add footnote regarding printf_fast_f precision limit
[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 c
17305 \end_layout
17306
17307 \end_inset
17308 </cell>
17309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17310 \begin_inset Text
17311
17312 \begin_layout Standard
17313
17314 \family roman
17315 \series medium
17316 \shape up
17317 \size normal
17318 \emph off
17319 \bar no
17320 \noun off
17321 \color none
17322 convert floating point to unsigned long
17323 \end_layout
17324
17325 \end_inset
17326 </cell>
17327 </row>
17328 <row topline="true">
17329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17330 \begin_inset Text
17331
17332 \begin_layout Standard
17333
17334 \family roman
17335 \series medium
17336 \shape up
17337 \size normal
17338 \emph off
17339 \bar no
17340 \noun off
17341 \color none
17342 _fs2long.c
17343 \end_layout
17344
17345 \end_inset
17346 </cell>
17347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17348 \begin_inset Text
17349
17350 \begin_layout Standard
17351
17352 \family roman
17353 \series medium
17354 \shape up
17355 \size normal
17356 \emph off
17357 \bar no
17358 \noun off
17359 \color none
17360 convert floating point to signed long
17361 \end_layout
17362
17363 \end_inset
17364 </cell>
17365 </row>
17366 <row topline="true">
17367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17368 \begin_inset Text
17369
17370 \begin_layout Standard
17371
17372 \family roman
17373 \series medium
17374 \shape up
17375 \size normal
17376 \emph off
17377 \bar no
17378 \noun off
17379 \color none
17380 _uchar2fs.c
17381 \end_layout
17382
17383 \end_inset
17384 </cell>
17385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17386 \begin_inset Text
17387
17388 \begin_layout Standard
17389
17390 \family roman
17391 \series medium
17392 \shape up
17393 \size normal
17394 \emph off
17395 \bar no
17396 \noun off
17397 \color none
17398 convert unsigned char to floating point
17399 \end_layout
17400
17401 \end_inset
17402 </cell>
17403 </row>
17404 <row topline="true">
17405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17406 \begin_inset Text
17407
17408 \begin_layout Standard
17409
17410 \family roman
17411 \series medium
17412 \shape up
17413 \size normal
17414 \emph off
17415 \bar no
17416 \noun off
17417 \color none
17418 _char2fs.c
17419 \end_layout
17420
17421 \end_inset
17422 </cell>
17423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17424 \begin_inset Text
17425
17426 \begin_layout Standard
17427
17428 \family roman
17429 \series medium
17430 \shape up
17431 \size normal
17432 \emph off
17433 \bar no
17434 \noun off
17435 \color none
17436 convert char to floating point number
17437 \end_layout
17438
17439 \end_inset
17440 </cell>
17441 </row>
17442 <row topline="true">
17443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17444 \begin_inset Text
17445
17446 \begin_layout Standard
17447
17448 \family roman
17449 \series medium
17450 \shape up
17451 \size normal
17452 \emph off
17453 \bar no
17454 \noun off
17455 \color none
17456 _uint2fs.c
17457 \end_layout
17458
17459 \end_inset
17460 </cell>
17461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17462 \begin_inset Text
17463
17464 \begin_layout Standard
17465
17466 \family roman
17467 \series medium
17468 \shape up
17469 \size normal
17470 \emph off
17471 \bar no
17472 \noun off
17473 \color none
17474 convert unsigned int to floating point
17475 \end_layout
17476
17477 \end_inset
17478 </cell>
17479 </row>
17480 <row topline="true">
17481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17482 \begin_inset Text
17483
17484 \begin_layout Standard
17485
17486 \family roman
17487 \series medium
17488 \shape up
17489 \size normal
17490 \emph off
17491 \bar no
17492 \noun off
17493 \color none
17494 _int2fs.c
17495 \end_layout
17496
17497 \end_inset
17498 </cell>
17499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17500 \begin_inset Text
17501
17502 \begin_layout Standard
17503
17504 \family roman
17505 \series medium
17506 \shape up
17507 \size normal
17508 \emph off
17509 \bar no
17510 \noun off
17511 \color none
17512 convert int to floating point numbers
17513 \end_layout
17514
17515 \end_inset
17516 </cell>
17517 </row>
17518 <row topline="true">
17519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17520 \begin_inset Text
17521
17522 \begin_layout Standard
17523
17524 \family roman
17525 \series medium
17526 \shape up
17527 \size normal
17528 \emph off
17529 \bar no
17530 \noun off
17531 \color none
17532 _ulong2fs.c
17533 \end_layout
17534
17535 \end_inset
17536 </cell>
17537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17538 \begin_inset Text
17539
17540 \begin_layout Standard
17541
17542 \family roman
17543 \series medium
17544 \shape up
17545 \size normal
17546 \emph off
17547 \bar no
17548 \noun off
17549 \color none
17550 convert unsigned long to floating point number
17551 \end_layout
17552
17553 \end_inset
17554 </cell>
17555 </row>
17556 <row topline="true" bottomline="true">
17557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17558 \begin_inset Text
17559
17560 \begin_layout Standard
17561
17562 \family roman
17563 \series medium
17564 \shape up
17565 \size normal
17566 \emph off
17567 \bar no
17568 \noun off
17569 \color none
17570 _long2fs.c
17571 \end_layout
17572
17573 \end_inset
17574 </cell>
17575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17576 \begin_inset Text
17577
17578 \begin_layout Standard
17579
17580 \family roman
17581 \series medium
17582 \shape up
17583 \size normal
17584 \emph off
17585 \bar no
17586 \noun off
17587 \color none
17588 convert long to floating point number
17589 \end_layout
17590
17591 \end_inset
17592 </cell>
17593 </row>
17594 </lyxtabular>
17595
17596 \end_inset
17597
17598
17599 \newline
17600
17601 \end_layout
17602
17603 \begin_layout Standard
17604 These support routines are developed in ANSI-C so there is room for space
17605  and speed improvement
17606 \begin_inset Foot
17607 status open
17608
17609 \begin_layout Standard
17610 These floating point routines (
17611 \emph on
17612 not
17613 \emph default
17614  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
17615  
17616 \end_layout
17617
17618 \end_inset
17619
17620 .
17621  Note if all these routines are used simultaneously the data space might
17622  overflow.
17623  For serious floating point usage the large model might be needed.
17624  Also notice that you don't have to call this routines directly.
17625  The compiler will use them automatically every time a floating point operation
17626  is required.
17627 \begin_inset VSpace bigskip
17628 \end_inset
17629
17630
17631 \end_layout
17632
17633 \begin_layout Section
17634 Library Routines
17635 \begin_inset LatexCommand \index{Libraries}
17636
17637 \end_inset
17638
17639
17640 \end_layout
17641
17642 \begin_layout Standard
17643
17644 \emph on
17645 <pending: this is messy and incomplete - a little more information is in
17646  sdcc/doc/libdoc.txt
17647 \emph default
17648  >
17649 \end_layout
17650
17651 \begin_layout Subsection
17652 Compiler support routines (_gptrget, _mulint etc.)
17653 \end_layout
17654
17655 \begin_layout Subsection
17656 Stdclib functions (puts, printf, strcat etc.)
17657 \end_layout
17658
17659 \begin_layout Subsubsection
17660 <stdio.h>
17661 \end_layout
17662
17663 \begin_layout Paragraph
17664 getchar(), putchar()
17665 \end_layout
17666
17667 \begin_layout Standard
17668 \begin_inset LatexCommand \index{<stdio.h>}
17669
17670 \end_inset
17671
17672 As usual on embedded systems you have to provide your own 
17673 \family typewriter
17674 getchar()
17675 \begin_inset LatexCommand \index{getchar()}
17676
17677 \end_inset
17678
17679  
17680 \family default
17681 and 
17682 \family typewriter
17683 putchar()
17684 \begin_inset LatexCommand \index{putchar()}
17685
17686 \end_inset
17687
17688
17689 \family default
17690  routines.
17691  SDCC does not know whether the system connects to a serial line with or
17692  without handshake, LCD, keyboard or other device.
17693  And whether a 
17694 \family typewriter
17695 lf
17696 \family default
17697  to 
17698 \family typewriter
17699 crlf
17700 \family default
17701  conversion within 
17702 \family typewriter
17703 putchar()
17704 \family default
17705  is intended.
17706  You'll find examples for serial routines f.e.
17707  in sdcc/device/lib.
17708  For the mcs51 this minimalistic polling 
17709 \family typewriter
17710 putchar()
17711 \family default
17712  routine might be a start:
17713 \end_layout
17714
17715 \begin_layout Verse
17716
17717 \family typewriter
17718 void putchar (char c) { 
17719 \newline
17720 \InsetSpace ~
17721 \InsetSpace ~
17722 \InsetSpace ~
17723 \InsetSpace ~
17724 while (!TI)\InsetSpace ~
17725 \InsetSpace ~
17726 \InsetSpace ~
17727  /* assumes UART is initialized */
17728 \newline
17729 \InsetSpace ~
17730 \InsetSpace ~
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 \InsetSpace ~
17734 \InsetSpace ~
17735 \InsetSpace ~
17736 \InsetSpace ~
17737 ;
17738 \newline
17739 \InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 \InsetSpace ~
17743 TI
17744  = 0;
17745 \newline
17746 \InsetSpace ~
17747 \InsetSpace ~
17748 \InsetSpace ~
17749 \InsetSpace ~
17750 SBUF = c;
17751 \newline
17752 }
17753 \end_layout
17754
17755 \begin_layout Paragraph
17756 printf()
17757 \end_layout
17758
17759 \begin_layout Standard
17760 The default
17761 \family typewriter
17762  printf()
17763 \begin_inset LatexCommand \index{printf()}
17764
17765 \end_inset
17766
17767
17768 \family default
17769  implementation in
17770 \family typewriter
17771  printf_large.c
17772 \family default
17773  does not support float (except on ds390).
17774  To enable this recompile it with the option 
17775 \emph on
17776 -
17777 \begin_inset ERT
17778 status collapsed
17779
17780 \begin_layout Standard
17781
17782
17783 \backslash
17784 /
17785 \end_layout
17786
17787 \end_inset
17788
17789 DUSE_FLOATS=1
17790 \begin_inset LatexCommand \index{USE\_FLOATS}
17791
17792 \end_inset
17793
17794
17795 \emph default
17796  on the command line.
17797  Use
17798 \emph on
17799  -
17800 \begin_inset ERT
17801 status collapsed
17802
17803 \begin_layout Standard
17804
17805
17806 \backslash
17807 /
17808 \end_layout
17809
17810 \end_inset
17811
17812 -model-large
17813 \begin_inset LatexCommand \index{-\/-model-large}
17814
17815 \end_inset
17816
17817
17818 \emph default
17819  for the mcs51 port, since this uses a lot of memory.
17820 \end_layout
17821
17822 \begin_layout Standard
17823 If you're short on code memory you might want to use 
17824 \family typewriter
17825 printf_small()
17826 \begin_inset LatexCommand \index{printf\_small()}
17827
17828 \end_inset
17829
17830
17831 \family default
17832  
17833 \emph on
17834 instead
17835 \emph default
17836  of
17837 \family typewriter
17838  printf().
17839
17840 \family default
17841  For the mcs51 there additionally are assembly versions 
17842 \family typewriter
17843 printf_tiny()
17844 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
17845
17846 \end_inset
17847
17848
17849 \family default
17850  (subset of printf using less than 270 bytes) and 
17851 \family typewriter
17852 printf_fast()
17853 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
17854
17855 \end_inset
17856
17857  
17858 \family default
17859 and
17860 \family typewriter
17861  printf_fast_f()
17862 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
17863
17864 \end_inset
17865
17866
17867 \family default
17868  (floating-point aware version of printf_fast) which should fit the requirements
17869  of many embedded systems (printf_fast() can be customized by unsetting
17870  #defines to 
17871 \emph on
17872 not
17873 \emph default
17874  support long variables and field widths).
17875  Be shure to only use only one of these printf options within a project.
17876 \newline
17877
17878 \end_layout
17879
17880 \begin_layout Standard
17881 Feature matrix of different 
17882 \emph on
17883 printf
17884 \emph default
17885  options on mcs51.
17886 \end_layout
17887
17888 \begin_layout Standard
17889 \begin_inset Tabular
17890 <lyxtabular version="3" rows="14" columns="7">
17891 <features islongtable="true">
17892 <column alignment="left" valignment="middle" leftline="true" width="14col%">
17893 <column alignment="center" valignment="top" leftline="true" width="0">
17894 <column alignment="center" valignment="top" leftline="true" width="12col%">
17895 <column alignment="center" valignment="top" leftline="true" width="10col%">
17896 <column alignment="center" valignment="top" leftline="true" width="0">
17897 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
17898 <column alignment="center" valignment="top" rightline="true" width="0">
17899 <row topline="true" bottomline="true" endhead="true">
17900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17901 \begin_inset Text
17902
17903 \begin_layout Standard
17904
17905 \series bold
17906 \size large
17907 mcs51
17908 \end_layout
17909
17910 \end_inset
17911 </cell>
17912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17913 \begin_inset Text
17914
17915 \begin_layout Standard
17916 printf
17917 \begin_inset LatexCommand \index{printf}
17918
17919 \end_inset
17920
17921
17922 \end_layout
17923
17924 \end_inset
17925 </cell>
17926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17927 \begin_inset Text
17928
17929 \begin_layout Standard
17930 printf 
17931 \size scriptsize
17932 USE_FLOATS=1
17933 \end_layout
17934
17935 \end_inset
17936 </cell>
17937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17938 \begin_inset Text
17939
17940 \begin_layout Standard
17941 printf_small
17942 \end_layout
17943
17944 \end_inset
17945 </cell>
17946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17947 \begin_inset Text
17948
17949 \begin_layout Standard
17950 printf_fast
17951 \end_layout
17952
17953 \end_inset
17954 </cell>
17955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17956 \begin_inset Text
17957
17958 \begin_layout Standard
17959 printf_fast_f
17960 \end_layout
17961
17962 \end_inset
17963 </cell>
17964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17965 \begin_inset Text
17966
17967 \begin_layout Standard
17968 printf_tiny
17969 \end_layout
17970
17971 \end_inset
17972 </cell>
17973 </row>
17974 <row topline="true" endhead="true">
17975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17976 \begin_inset Text
17977
17978 \begin_layout Standard
17979 filename
17980 \end_layout
17981
17982 \end_inset
17983 </cell>
17984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17985 \begin_inset Text
17986
17987 \begin_layout Standard
17988
17989 \size scriptsize
17990 printf_large.c
17991 \end_layout
17992
17993 \end_inset
17994 </cell>
17995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17996 \begin_inset Text
17997
17998 \begin_layout Standard
17999
18000 \size scriptsize
18001 printf_large.c
18002 \end_layout
18003
18004 \end_inset
18005 </cell>
18006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18007 \begin_inset Text
18008
18009 \begin_layout Standard
18010
18011 \size scriptsize
18012 printfl.c
18013 \end_layout
18014
18015 \end_inset
18016 </cell>
18017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18018 \begin_inset Text
18019
18020 \begin_layout Standard
18021
18022 \size scriptsize
18023 printf_fast.c
18024 \end_layout
18025
18026 \end_inset
18027 </cell>
18028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18029 \begin_inset Text
18030
18031 \begin_layout Standard
18032
18033 \size scriptsize
18034 printf_fast_f.c
18035 \end_layout
18036
18037 \end_inset
18038 </cell>
18039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18040 \begin_inset Text
18041
18042 \begin_layout Standard
18043
18044 \size scriptsize
18045 printf_tiny.c
18046 \end_layout
18047
18048 \end_inset
18049 </cell>
18050 </row>
18051 <row topline="true" endhead="true">
18052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18053 \begin_inset Text
18054
18055 \begin_layout Standard
18056 \begin_inset Quotes sld
18057 \end_inset
18058
18059 Hello World
18060 \begin_inset Quotes srd
18061 \end_inset
18062
18063  size
18064 \end_layout
18065
18066 \begin_layout Standard
18067 small / large
18068 \end_layout
18069
18070 \end_inset
18071 </cell>
18072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18073 \begin_inset Text
18074
18075 \begin_layout Standard
18076 1.7k / 2.4k
18077 \end_layout
18078
18079 \end_inset
18080 </cell>
18081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18082 \begin_inset Text
18083
18084 \begin_layout Standard
18085 4.3k / 5.6k
18086 \end_layout
18087
18088 \end_inset
18089 </cell>
18090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18091 \begin_inset Text
18092
18093 \begin_layout Standard
18094 1.2k / 1.8k
18095 \end_layout
18096
18097 \end_inset
18098 </cell>
18099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18100 \begin_inset Text
18101
18102 \begin_layout Standard
18103 1.3k / 1.3k
18104 \end_layout
18105
18106 \end_inset
18107 </cell>
18108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18109 \begin_inset Text
18110
18111 \begin_layout Standard
18112 1.9k / 1.9k
18113 \end_layout
18114
18115 \end_inset
18116 </cell>
18117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18118 \begin_inset Text
18119
18120 \begin_layout Standard
18121 0.44k / 0.44k
18122 \end_layout
18123
18124 \end_inset
18125 </cell>
18126 </row>
18127 <row topline="true" endhead="true">
18128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18129 \begin_inset Text
18130
18131 \begin_layout Standard
18132 code size
18133 \end_layout
18134
18135 \begin_layout Standard
18136 small / large
18137 \end_layout
18138
18139 \end_inset
18140 </cell>
18141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18142 \begin_inset Text
18143
18144 \begin_layout Standard
18145 1.4k / 2.0k
18146 \end_layout
18147
18148 \end_inset
18149 </cell>
18150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18151 \begin_inset Text
18152
18153 \begin_layout Standard
18154 2.8k / 3.7k
18155 \end_layout
18156
18157 \end_inset
18158 </cell>
18159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18160 \begin_inset Text
18161
18162 \begin_layout Standard
18163 0.45k / 0.47k (+ _ltoa)
18164 \end_layout
18165
18166 \end_inset
18167 </cell>
18168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18169 \begin_inset Text
18170
18171 \begin_layout Standard
18172 1.2k / 1.2k
18173 \end_layout
18174
18175 \end_inset
18176 </cell>
18177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18178 \begin_inset Text
18179
18180 \begin_layout Standard
18181 1.6k / 1.6k
18182 \end_layout
18183
18184 \end_inset
18185 </cell>
18186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18187 \begin_inset Text
18188
18189 \begin_layout Standard
18190 0.26k / 0.26k
18191 \end_layout
18192
18193 \end_inset
18194 </cell>
18195 </row>
18196 <row topline="true">
18197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18198 \begin_inset Text
18199
18200 \begin_layout Standard
18201 formats
18202 \end_layout
18203
18204 \end_inset
18205 </cell>
18206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18207 \begin_inset Text
18208
18209 \begin_layout Standard
18210 cdi
18211 \emph on
18212 o
18213 \emph default
18214 psux
18215 \end_layout
18216
18217 \end_inset
18218 </cell>
18219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18220 \begin_inset Text
18221
18222 \begin_layout Standard
18223
18224 \family roman
18225 \series medium
18226 \shape up
18227 \size normal
18228 \emph off
18229 \bar no
18230 \noun off
18231 \color none
18232 cd
18233 \family default
18234 \series default
18235 \shape default
18236 \size default
18237 \emph default
18238 \bar default
18239 \noun default
18240 f
18241 \family roman
18242 \series medium
18243 \shape up
18244 \size normal
18245 \emph off
18246 \bar no
18247 \noun off
18248 i
18249 \family default
18250 \series default
18251 \shape default
18252 \size default
18253 \emph on
18254 \bar default
18255 \noun default
18256 o
18257 \family roman
18258 \series medium
18259 \shape up
18260 \size normal
18261 \emph off
18262 \bar no
18263 \noun off
18264 psux
18265 \end_layout
18266
18267 \end_inset
18268 </cell>
18269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18270 \begin_inset Text
18271
18272 \begin_layout Standard
18273 c
18274 \family roman
18275 \series medium
18276 \shape up
18277 \size normal
18278 \emph off
18279 \bar no
18280 \noun off
18281 \color none
18282 d
18283 \family default
18284 \series default
18285 \shape default
18286 \size default
18287 \emph on
18288 \bar default
18289 \noun default
18290 o
18291 \family roman
18292 \series medium
18293 \shape up
18294 \size normal
18295 \emph off
18296 \bar no
18297 \noun off
18298 s
18299 \family default
18300 \series default
18301 \shape default
18302 \size default
18303 \emph default
18304 \bar default
18305 \noun default
18306 x
18307 \end_layout
18308
18309 \end_inset
18310 </cell>
18311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18312 \begin_inset Text
18313
18314 \begin_layout Standard
18315 cdsux
18316 \end_layout
18317
18318 \end_inset
18319 </cell>
18320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18321 \begin_inset Text
18322
18323 \begin_layout Standard
18324 cdfsux
18325 \end_layout
18326
18327 \end_inset
18328 </cell>
18329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18330 \begin_inset Text
18331
18332 \begin_layout Standard
18333 cdsux
18334 \end_layout
18335
18336 \end_inset
18337 </cell>
18338 </row>
18339 <row topline="true">
18340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18341 \begin_inset Text
18342
18343 \begin_layout Standard
18344 long (32 bit) support
18345 \end_layout
18346
18347 \end_inset
18348 </cell>
18349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18350 \begin_inset Text
18351
18352 \begin_layout Standard
18353 x
18354 \end_layout
18355
18356 \end_inset
18357 </cell>
18358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18359 \begin_inset Text
18360
18361 \begin_layout Standard
18362 x
18363 \end_layout
18364
18365 \end_inset
18366 </cell>
18367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18368 \begin_inset Text
18369
18370 \begin_layout Standard
18371 x
18372 \end_layout
18373
18374 \end_inset
18375 </cell>
18376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18377 \begin_inset Text
18378
18379 \begin_layout Standard
18380 x
18381 \end_layout
18382
18383 \end_inset
18384 </cell>
18385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18386 \begin_inset Text
18387
18388 \begin_layout Standard
18389
18390 \family roman
18391 \series medium
18392 \shape up
18393 \size normal
18394 \emph off
18395 \bar no
18396 \noun off
18397 \color none
18398 x
18399 \end_layout
18400
18401 \end_inset
18402 </cell>
18403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18404 \begin_inset Text
18405
18406 \begin_layout Standard
18407 -
18408 \end_layout
18409
18410 \end_inset
18411 </cell>
18412 </row>
18413 <row topline="true">
18414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18415 \begin_inset Text
18416
18417 \begin_layout Standard
18418 byte arguments on stack
18419 \end_layout
18420
18421 \end_inset
18422 </cell>
18423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18424 \begin_inset Text
18425
18426 \begin_layout Standard
18427 b
18428 \end_layout
18429
18430 \end_inset
18431 </cell>
18432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18433 \begin_inset Text
18434
18435 \begin_layout Standard
18436 b
18437 \end_layout
18438
18439 \end_inset
18440 </cell>
18441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18442 \begin_inset Text
18443
18444 \begin_layout Standard
18445 -
18446 \end_layout
18447
18448 \end_inset
18449 </cell>
18450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18451 \begin_inset Text
18452
18453 \begin_layout Standard
18454 -
18455 \end_layout
18456
18457 \end_inset
18458 </cell>
18459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18460 \begin_inset Text
18461
18462 \begin_layout Standard
18463 -
18464 \end_layout
18465
18466 \end_inset
18467 </cell>
18468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18469 \begin_inset Text
18470
18471 \begin_layout Standard
18472 -
18473 \end_layout
18474
18475 \end_inset
18476 </cell>
18477 </row>
18478 <row topline="true">
18479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18480 \begin_inset Text
18481
18482 \begin_layout Standard
18483 float format
18484 \begin_inset LatexCommand \index{Floating point support}
18485
18486 \end_inset
18487
18488
18489 \end_layout
18490
18491 \end_inset
18492 </cell>
18493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18494 \begin_inset Text
18495
18496 \begin_layout Standard
18497 -
18498 \end_layout
18499
18500 \end_inset
18501 </cell>
18502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18503 \begin_inset Text
18504
18505 \begin_layout Standard
18506 %f
18507 \end_layout
18508
18509 \end_inset
18510 </cell>
18511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18512 \begin_inset Text
18513
18514 \begin_layout Standard
18515 -
18516 \end_layout
18517
18518 \end_inset
18519 </cell>
18520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18521 \begin_inset Text
18522
18523 \begin_layout Standard
18524 -
18525 \end_layout
18526
18527 \end_inset
18528 </cell>
18529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18530 \begin_inset Text
18531
18532 \begin_layout Standard
18533 %f
18534 \begin_inset Foot
18535 status collapsed
18536
18537 \begin_layout Standard
18538 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
18539 \end_layout
18540
18541 \end_inset
18542
18543
18544 \end_layout
18545
18546 \end_inset
18547 </cell>
18548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18549 \begin_inset Text
18550
18551 \begin_layout Standard
18552 -
18553 \end_layout
18554
18555 \end_inset
18556 </cell>
18557 </row>
18558 <row topline="true">
18559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18560 \begin_inset Text
18561
18562 \begin_layout Standard
18563 float formats %e %g
18564 \end_layout
18565
18566 \end_inset
18567 </cell>
18568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18569 \begin_inset Text
18570
18571 \begin_layout Standard
18572 -
18573 \end_layout
18574
18575 \end_inset
18576 </cell>
18577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18578 \begin_inset Text
18579
18580 \begin_layout Standard
18581 -
18582 \end_layout
18583
18584 \end_inset
18585 </cell>
18586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18587 \begin_inset Text
18588
18589 \begin_layout Standard
18590 -
18591 \end_layout
18592
18593 \end_inset
18594 </cell>
18595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18596 \begin_inset Text
18597
18598 \begin_layout Standard
18599 -
18600 \end_layout
18601
18602 \end_inset
18603 </cell>
18604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18605 \begin_inset Text
18606
18607 \begin_layout Standard
18608 -
18609 \end_layout
18610
18611 \end_inset
18612 </cell>
18613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18614 \begin_inset Text
18615
18616 \begin_layout Standard
18617 -
18618 \end_layout
18619
18620 \end_inset
18621 </cell>
18622 </row>
18623 <row topline="true" bottomline="true">
18624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18625 \begin_inset Text
18626
18627 \begin_layout Standard
18628 field width
18629 \end_layout
18630
18631 \end_inset
18632 </cell>
18633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18634 \begin_inset Text
18635
18636 \begin_layout Standard
18637 x
18638 \end_layout
18639
18640 \end_inset
18641 </cell>
18642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18643 \begin_inset Text
18644
18645 \begin_layout Standard
18646 x
18647 \end_layout
18648
18649 \end_inset
18650 </cell>
18651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18652 \begin_inset Text
18653
18654 \begin_layout Standard
18655 -
18656 \end_layout
18657
18658 \end_inset
18659 </cell>
18660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18661 \begin_inset Text
18662
18663 \begin_layout Standard
18664 x
18665 \end_layout
18666
18667 \end_inset
18668 </cell>
18669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18670 \begin_inset Text
18671
18672 \begin_layout Standard
18673 x
18674 \end_layout
18675
18676 \end_inset
18677 </cell>
18678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18679 \begin_inset Text
18680
18681 \begin_layout Standard
18682 -
18683 \end_layout
18684
18685 \end_inset
18686 </cell>
18687 </row>
18688 <row bottomline="true">
18689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18690 \begin_inset Text
18691
18692 \begin_layout Standard
18693 string speed
18694 \begin_inset Foot
18695 status collapsed
18696
18697 \begin_layout Standard
18698 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
18699 \backslash
18700 r', '
18701 \backslash
18702 n'); standard 8051 @ 22.1184 MHz, empty putchar()
18703 \end_layout
18704
18705 \end_inset
18706
18707 ,
18708 \end_layout
18709
18710 \begin_layout Standard
18711 small / large
18712 \end_layout
18713
18714 \end_inset
18715 </cell>
18716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18717 \begin_inset Text
18718
18719 \begin_layout Standard
18720 1.52 / 2.59 ms
18721 \end_layout
18722
18723 \end_inset
18724 </cell>
18725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18726 \begin_inset Text
18727
18728 \begin_layout Standard
18729 1.53 / 2.62 ms
18730 \end_layout
18731
18732 \end_inset
18733 </cell>
18734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18735 \begin_inset Text
18736
18737 \begin_layout Standard
18738 0.92 / 0.93 ms
18739 \end_layout
18740
18741 \end_inset
18742 </cell>
18743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18744 \begin_inset Text
18745
18746 \begin_layout Standard
18747 0.45 / 0.45 ms
18748 \end_layout
18749
18750 \end_inset
18751 </cell>
18752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18753 \begin_inset Text
18754
18755 \begin_layout Standard
18756 0.46 / 0.46 ms
18757 \end_layout
18758
18759 \end_inset
18760 </cell>
18761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18762 \begin_inset Text
18763
18764 \begin_layout Standard
18765 0.45 / 0.45 ms
18766 \end_layout
18767
18768 \end_inset
18769 </cell>
18770 </row>
18771 <row bottomline="true">
18772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18773 \begin_inset Text
18774
18775 \begin_layout Standard
18776 int speed
18777 \begin_inset Foot
18778 status collapsed
18779
18780 \begin_layout Standard
18781 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
18782  putchar()
18783 \end_layout
18784
18785 \end_inset
18786
18787 ,
18788 \end_layout
18789
18790 \begin_layout Standard
18791 small / large
18792 \end_layout
18793
18794 \end_inset
18795 </cell>
18796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18797 \begin_inset Text
18798
18799 \begin_layout Standard
18800 3.01 / 3.61 ms
18801 \end_layout
18802
18803 \end_inset
18804 </cell>
18805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18806 \begin_inset Text
18807
18808 \begin_layout Standard
18809 3.01 / 3.61 ms
18810 \end_layout
18811
18812 \end_inset
18813 </cell>
18814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18815 \begin_inset Text
18816
18817 \begin_layout Standard
18818 3.51 / 18.13 ms
18819 \end_layout
18820
18821 \end_inset
18822 </cell>
18823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18824 \begin_inset Text
18825
18826 \begin_layout Standard
18827 0.22 / 0.22 ms
18828 \end_layout
18829
18830 \end_inset
18831 </cell>
18832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18833 \begin_inset Text
18834
18835 \begin_layout Standard
18836 0.23 / 0.23 ms
18837 \end_layout
18838
18839 \end_inset
18840 </cell>
18841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18842 \begin_inset Text
18843
18844 \begin_layout Standard
18845 0.25 / 0.25 ms
18846 \end_layout
18847
18848 \end_inset
18849 </cell>
18850 </row>
18851 <row bottomline="true">
18852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18853 \begin_inset Text
18854
18855 \begin_layout Standard
18856 long speed
18857 \begin_inset Foot
18858 status collapsed
18859
18860 \begin_layout Standard
18861 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
18862  empty putchar()
18863 \end_layout
18864
18865 \end_inset
18866
18867 ,
18868 \end_layout
18869
18870 \begin_layout Standard
18871 small / large
18872 \end_layout
18873
18874 \end_inset
18875 </cell>
18876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18877 \begin_inset Text
18878
18879 \begin_layout Standard
18880 5.37 / 6.31 ms
18881 \end_layout
18882
18883 \end_inset
18884 </cell>
18885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18886 \begin_inset Text
18887
18888 \begin_layout Standard
18889 5.37 / 6.31 ms
18890 \end_layout
18891
18892 \end_inset
18893 </cell>
18894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18895 \begin_inset Text
18896
18897 \begin_layout Standard
18898 8.71 / 40.65 ms
18899 \end_layout
18900
18901 \end_inset
18902 </cell>
18903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18904 \begin_inset Text
18905
18906 \begin_layout Standard
18907 0.40 / 0.40 ms
18908 \end_layout
18909
18910 \end_inset
18911 </cell>
18912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18913 \begin_inset Text
18914
18915 \begin_layout Standard
18916 0.40 / 0.40 ms
18917 \end_layout
18918
18919 \end_inset
18920 </cell>
18921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18922 \begin_inset Text
18923
18924 \begin_layout Standard
18925 -
18926 \end_layout
18927
18928 \end_inset
18929 </cell>
18930 </row>
18931 <row bottomline="true">
18932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18933 \begin_inset Text
18934
18935 \begin_layout Standard
18936 float speed
18937 \begin_inset Foot
18938 status collapsed
18939
18940 \begin_layout Standard
18941 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18942  empty putchar()
18943 \end_layout
18944
18945 \end_inset
18946
18947 ,
18948 \end_layout
18949
18950 \begin_layout Standard
18951 small / large
18952 \end_layout
18953
18954 \end_inset
18955 </cell>
18956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18957 \begin_inset Text
18958
18959 \begin_layout Standard
18960 -
18961 \end_layout
18962
18963 \end_inset
18964 </cell>
18965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18966 \begin_inset Text
18967
18968 \begin_layout Standard
18969 7.49 / 22.47 ms
18970 \end_layout
18971
18972 \end_inset
18973 </cell>
18974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18975 \begin_inset Text
18976
18977 \begin_layout Standard
18978 -
18979 \end_layout
18980
18981 \end_inset
18982 </cell>
18983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18984 \begin_inset Text
18985
18986 \begin_layout Standard
18987 -
18988 \end_layout
18989
18990 \end_inset
18991 </cell>
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18993 \begin_inset Text
18994
18995 \begin_layout Standard
18996 1.04 / 1.04 ms
18997 \end_layout
18998
18999 \end_inset
19000 </cell>
19001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19002 \begin_inset Text
19003
19004 \begin_layout Standard
19005 -
19006 \end_layout
19007
19008 \end_inset
19009 </cell>
19010 </row>
19011 </lyxtabular>
19012
19013 \end_inset
19014
19015
19016 \end_layout
19017
19018 \begin_layout Subsubsection
19019 <malloc.h>
19020 \begin_inset LatexCommand \index{malloc.h}
19021
19022 \end_inset
19023
19024
19025 \end_layout
19026
19027 \begin_layout Standard
19028 As of SDCC 2.6.2 you no longer need to call an initialization routine before
19029  using dynamic memory allocation
19030 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
19031
19032 \end_inset
19033
19034  and a default heap
19035 \begin_inset LatexCommand \index{heap (malloc)}
19036
19037 \end_inset
19038
19039  space of 1024 bytes is provided for malloc to allocate memory from.
19040  If you need a different heap size you need to recompile _heap.c with the
19041  required size defined in HEAP_SIZE.
19042  It is recommended to make a copy of this file into your project directory
19043  and compile it there with:
19044 \end_layout
19045
19046 \begin_layout Verse
19047
19048 \family typewriter
19049 sdcc -c _heap.c -D HEAD_SIZE=2048
19050 \end_layout
19051
19052 \begin_layout Standard
19053 And then link it with:
19054 \end_layout
19055
19056 \begin_layout Verse
19057
19058 \family typewriter
19059 sdcc main.rel _heap.rel
19060 \end_layout
19061
19062 \begin_layout Subsection
19063 Math functions (sinf, powf, sqrtf etc.)
19064 \end_layout
19065
19066 \begin_layout Subsubsection
19067 <math.h>
19068 \end_layout
19069
19070 \begin_layout Standard
19071 See definitions in file <math.h>.
19072 \end_layout
19073
19074 \begin_layout Subsection
19075 Other libraries
19076 \end_layout
19077
19078 \begin_layout Standard
19079 Libraries
19080 \begin_inset LatexCommand \index{Libraries}
19081
19082 \end_inset
19083
19084  included in SDCC should have a license at least as liberal as the GNU Lesser
19085  General Public License
19086 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
19087
19088 \end_inset
19089
19090  
19091 \emph on
19092 LGPL
19093 \emph default
19094 .
19095 \end_layout
19096
19097 \begin_layout Standard
19098 \begin_inset Note Comment
19099 status collapsed
19100
19101 \begin_layout Standard
19102 license statements for the libraries are missing.
19103  sdcc/device/lib/ser_ir.c
19104 \end_layout
19105
19106 \begin_layout Standard
19107 or _decdptr f.e.
19108  come with a GPL (as opposed to LGPL) License - this will not be liberal
19109  enough for many embedded programmers.
19110 \end_layout
19111
19112 \end_inset
19113
19114
19115 \end_layout
19116
19117 \begin_layout Standard
19118 If you have ported some library or want to share experience about some code
19119  which f.e.
19120  falls into any of these categories Busses (I
19121 \begin_inset Formula $^{\textrm{2}}$
19122 \end_inset
19123
19124 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
19125  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
19126  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
19127 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
19128
19129 \end_inset
19130
19131 \InsetSpace ~
19132 would certainly like to hear about it.
19133 \end_layout
19134
19135 \begin_layout Standard
19136 Programmers coding for embedded systems are not especially famous for being
19137  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
19138 e these references are very valuable.
19139  Let's help to create a climate where information is shared.
19140 \begin_inset VSpace bigskip
19141 \end_inset
19142
19143
19144 \end_layout
19145
19146 \begin_layout Section
19147 Memory Models
19148 \end_layout
19149
19150 \begin_layout Subsection
19151 MCS51 Memory Models
19152 \begin_inset LatexCommand \index{Memory model}
19153
19154 \end_inset
19155
19156
19157 \begin_inset LatexCommand \index{MCS51 memory model}
19158
19159 \end_inset
19160
19161
19162 \end_layout
19163
19164 \begin_layout Subsubsection
19165 Small, Medium and Large
19166 \end_layout
19167
19168 \begin_layout Standard
19169 SDCC allows three memory models for MCS51 code, 
19170 \shape slanted
19171 small, medium
19172 \shape default
19173  and 
19174 \shape slanted
19175 large
19176 \shape default
19177 .
19178  Modules compiled with different memory models should 
19179 \emph on
19180 never
19181 \emph default
19182  be combined together or the results would be unpredictable.
19183  The library routines supplied with the compiler are compiled as small,
19184  medium and large.
19185  The compiled library modules are contained in separate directories as small,
19186  medium and large so that you can link to the appropriate set.
19187 \end_layout
19188
19189 \begin_layout Standard
19190 When the medium or large model is used all variables declared without a
19191  storage class will be allocated into the external ram, this includes all
19192  parameters and local variables (for non-reentrant
19193 \begin_inset LatexCommand \index{reentrant}
19194
19195 \end_inset
19196
19197  functions).
19198  When the small model is used variables without storage class are allocated
19199  in the internal ram.
19200 \end_layout
19201
19202 \begin_layout Standard
19203 Judicious usage of the processor specific storage classes
19204 \begin_inset LatexCommand \index{Storage class}
19205
19206 \end_inset
19207
19208  and the 'reentrant' function type will yield much more efficient code,
19209  than using the large model.
19210  Several optimizations are disabled when the program is compiled using the
19211  large model, it is therefore recommended that the small model be used unless
19212  absolutely required.
19213 \end_layout
19214
19215 \begin_layout Subsubsection
19216 External Stack
19217 \begin_inset LatexCommand \label{sub:External-Stack}
19218
19219 \end_inset
19220
19221
19222 \begin_inset LatexCommand \index{stack}
19223
19224 \end_inset
19225
19226
19227 \begin_inset LatexCommand \index{External stack (mcs51)}
19228
19229 \end_inset
19230
19231
19232 \end_layout
19233
19234 \begin_layout Standard
19235 The external stack (-
19236 \begin_inset ERT
19237 status collapsed
19238
19239 \begin_layout Standard
19240
19241
19242 \backslash
19243 /
19244 \end_layout
19245
19246 \end_inset
19247
19248 -xstack option
19249 \begin_inset LatexCommand \index{-\/-xstack}
19250
19251 \end_inset
19252
19253 ) is located in pdata
19254 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19255
19256 \end_inset
19257
19258  memory (usually at the start of the external ram segment) and uses all
19259  unused space in pdata (max.
19260  256 bytes).
19261  When -
19262 \begin_inset ERT
19263 status collapsed
19264
19265 \begin_layout Standard
19266
19267
19268 \backslash
19269 /
19270 \end_layout
19271
19272 \end_inset
19273
19274 -xstack option is used to compile the program, the parameters and local
19275  variables
19276 \begin_inset LatexCommand \index{local variables}
19277
19278 \end_inset
19279
19280  of all reentrant functions are allocated in this area.
19281  This option is provided for programs with large stack space requirements.
19282  When used with the -
19283 \begin_inset ERT
19284 status collapsed
19285
19286 \begin_layout Standard
19287
19288
19289 \backslash
19290 /
19291 \end_layout
19292
19293 \end_inset
19294
19295 -stack-auto
19296 \begin_inset LatexCommand \index{-\/-stack-auto}
19297
19298 \end_inset
19299
19300  option, all parameters and local variables are allocated on the external
19301  stack (note: support libraries will need to be recompiled with the same
19302  options.
19303  There is a predefined target in the library makefile).
19304 \end_layout
19305
19306 \begin_layout Standard
19307 The compiler outputs the higher order address byte of the external ram segment
19308  into port P2
19309 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19310
19311 \end_inset
19312
19313  (see also section 
19314 \begin_inset LatexCommand \ref{sub:MCS51-variants}
19315
19316 \end_inset
19317
19318 ), therefore when using the External Stack option, this port 
19319 \emph on
19320 may not
19321 \emph default
19322  be used by the application program.
19323 \end_layout
19324
19325 \begin_layout Subsection
19326 DS390 Memory Model
19327 \begin_inset LatexCommand \index{Memory model}
19328
19329 \end_inset
19330
19331
19332 \begin_inset LatexCommand \index{DS390 memory model}
19333
19334 \end_inset
19335
19336
19337 \end_layout
19338
19339 \begin_layout Standard
19340 The only model supported is Flat 24
19341 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
19342
19343 \end_inset
19344
19345 .
19346  This generates code for the 24 bit contiguous addressing mode of the Dallas
19347  DS80C390 part.
19348  In this mode, up to four meg of external RAM or code space can be directly
19349  addressed.
19350  See the data sheets at www.dalsemi.com for further information on this part.
19351 \newline
19352
19353 \newline
19354 Note
19355  that the compiler does not generate any code to place the processor into
19356  24 bitmode (although 
19357 \emph on
19358 tinibios
19359 \emph default
19360  in the ds390 libraries will do that for you).
19361  If you don't use 
19362 \emph on
19363 tinibios
19364 \emph default
19365
19366 \begin_inset LatexCommand \index{Tinibios (DS390)}
19367
19368 \end_inset
19369
19370 , the boot loader or similar code must ensure that the processor is in 24
19371  bit contiguous addressing mode before calling the SDCC startup code.
19372 \newline
19373
19374 \newline
19375 Like
19376  the 
19377 \emph on
19378 -
19379 \begin_inset ERT
19380 status collapsed
19381
19382 \begin_layout Standard
19383
19384
19385 \backslash
19386 /
19387 \end_layout
19388
19389 \end_inset
19390
19391 -model-large
19392 \emph default
19393  option, variables will by default be placed into the XDATA segment.
19394  
19395 \newline
19396
19397 \newline
19398 Segments may be placed anywhere in the 4 meg address space using the usual
19399  -
19400 \begin_inset ERT
19401 status collapsed
19402
19403 \begin_layout Standard
19404
19405
19406 \backslash
19407 /
19408 \end_layout
19409
19410 \end_inset
19411
19412 -*-loc options.
19413  Note that if any segments are located above 64K, the -r flag must be passed
19414  to the linker to generate the proper segment relocations, and the Intel
19415  HEX output format must be used.
19416  The -r flag can be passed to the linker by using the option 
19417 \emph on
19418 -Wl-r
19419 \emph default
19420  on the SDCC command line.
19421  However, currently the linker can not handle code segments > 64k.
19422 \end_layout
19423
19424 \begin_layout Section
19425 Pragmas
19426 \begin_inset LatexCommand \label{sec:Pragmas}
19427
19428 \end_inset
19429
19430
19431 \begin_inset LatexCommand \index{Pragmas}
19432
19433 \end_inset
19434
19435
19436 \end_layout
19437
19438 \begin_layout Standard
19439 SDCC supports the following #pragma directives:
19440 \end_layout
19441
19442 \begin_layout Itemize
19443
19444 \series bold
19445 save
19446 \series default
19447
19448 \begin_inset LatexCommand \index{\#pragma save}
19449
19450 \end_inset
19451
19452  - this will save most current options to the save/restore stack.
19453  See #pragma\InsetSpace ~
19454 restore.
19455 \end_layout
19456
19457 \begin_layout Itemize
19458
19459 \series bold
19460 restore
19461 \series default
19462
19463 \begin_inset LatexCommand \index{\#pragma restore}
19464
19465 \end_inset
19466
19467  - will restore saved options from the last save.
19468  saves & restores can be nested.
19469  SDCC uses a save/restore stack: save pushes current options to the stack,
19470  restore pulls current options from the stack.
19471  See #pragma\InsetSpace ~
19472 save.
19473 \newline
19474
19475 \end_layout
19476
19477 \begin_layout Itemize
19478
19479 \series bold
19480 callee_saves
19481 \series default
19482
19483 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19484
19485 \end_inset
19486
19487
19488 \begin_inset LatexCommand \index{function prologue}
19489
19490 \end_inset
19491
19492  function1[,function2[,function3...]] - The compiler by default uses a caller
19493  saves convention for register saving across function calls, however this
19494  can cause unnecessary register pushing & popping
19495 \begin_inset LatexCommand \index{push/pop}
19496
19497 \end_inset
19498
19499  when calling small functions from larger functions.
19500  This option can be used to switch off the register saving convention for
19501  the function names specified.
19502  The compiler will not save registers when calling these functions, extra
19503  code need to be manually inserted at the entry & exit for these functions
19504  to save & restore the registers used by these functions, this can SUBSTANTIALLY
19505  reduce code & improve run time performance of the generated code.
19506  In the future the compiler (with inter procedural analysis) may be able
19507  to determine the appropriate scheme to use for each function call.
19508  If -
19509 \begin_inset ERT
19510 status collapsed
19511
19512 \begin_layout Standard
19513
19514
19515 \backslash
19516 /
19517 \end_layout
19518
19519 \end_inset
19520
19521 -callee-saves command line option is used, the function names specified
19522  in #pragma\InsetSpace ~
19523 callee_saves
19524 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19525
19526 \end_inset
19527
19528  is appended to the list of functions specified in the command line.
19529 \end_layout
19530
19531 \begin_layout Itemize
19532
19533 \series bold
19534 exclude
19535 \series default
19536
19537 \begin_inset LatexCommand \index{\#pragma exclude}
19538
19539 \end_inset
19540
19541  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
19542  of pairs of push/pop
19543 \begin_inset LatexCommand \index{push/pop}
19544
19545 \end_inset
19546
19547  instructions in 
19548 \emph on
19549 I
19550 \emph default
19551 nterrupt
19552 \begin_inset LatexCommand \index{interrupt}
19553
19554 \end_inset
19555
19556  
19557 \emph on
19558 S
19559 \emph default
19560 ervice 
19561 \emph on
19562 R
19563 \emph default
19564 outines.
19565  The directive should be placed immediately before the ISR function definition
19566  and it affects ALL ISR functions following it.
19567  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
19568 exclude\InsetSpace ~
19569 none
19570 \begin_inset LatexCommand \index{\#pragma exclude}
19571
19572 \end_inset
19573
19574 .
19575  See also the related keyword _naked
19576 \begin_inset LatexCommand \index{\_naked}
19577
19578 \end_inset
19579
19580
19581 \begin_inset LatexCommand \index{\_\_naked}
19582
19583 \end_inset
19584
19585 .
19586 \end_layout
19587
19588 \begin_layout Itemize
19589
19590 \series bold
19591 less_pedantic
19592 \series default
19593
19594 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
19595
19596 \end_inset
19597
19598  - the compiler will not warn you anymore for obvious mistakes, you'r on
19599  your own now ;-(
19600 \end_layout
19601
19602 \begin_layout Itemize
19603
19604 \series bold
19605 disable_warning
19606 \series default
19607  <nnnn>
19608 \begin_inset LatexCommand \index{\#pragma disable\_warning}
19609
19610 \end_inset
19611
19612  - the compiler will not warn you anymore about warning number <nnnn>.
19613 \end_layout
19614
19615 \begin_layout Itemize
19616
19617 \series bold
19618 nogcse
19619 \series default
19620
19621 \begin_inset LatexCommand \index{\#pragma nogcse}
19622
19623 \end_inset
19624
19625  - will stop global common subexpression elimination.
19626 \end_layout
19627
19628 \begin_layout Itemize
19629
19630 \series bold
19631 noinduction
19632 \series default
19633
19634 \begin_inset LatexCommand \index{\#pragma noinduction}
19635
19636 \end_inset
19637
19638  - will stop loop induction optimizations.
19639 \end_layout
19640
19641 \begin_layout Itemize
19642
19643 \series bold
19644 noinvariant
19645 \series default
19646
19647 \begin_inset LatexCommand \index{\#pragma noinvariant}
19648
19649 \end_inset
19650
19651  - will not do loop invariant optimizations.
19652  For more details see Loop Invariants in section
19653 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
19654
19655 \end_inset
19656
19657 .
19658 \end_layout
19659
19660 \begin_layout Itemize
19661
19662 \series bold
19663 noiv
19664 \series default
19665
19666 \begin_inset LatexCommand \index{\#pragma noiv}
19667
19668 \end_inset
19669
19670  - Do not generate interrupt
19671 \begin_inset LatexCommand \index{interrupt}
19672
19673 \end_inset
19674
19675  vector table
19676 \begin_inset LatexCommand \index{interrupt vector table}
19677
19678 \end_inset
19679
19680  entries for all ISR functions defined after the pragma.
19681  This is useful in cases where the interrupt vector table must be defined
19682  manually, or when there is a secondary, manually defined interrupt vector
19683  table (e.g.
19684  for the autovector feature of the Cypress EZ-USB FX2).
19685  More elegantly this can be achieved by obmitting the optional interrupt
19686  number after the interrupt keyword, see section 
19687 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
19688
19689 \end_inset
19690
19691 \InsetSpace ~
19692 about interrupts.
19693 \end_layout
19694
19695 \begin_layout Itemize
19696
19697 \series bold
19698 nojtbound
19699 \series default
19700
19701 \begin_inset LatexCommand \index{\#pragma nojtbound}
19702
19703 \end_inset
19704
19705  - will not generate code for boundary value checking, when switch statements
19706  are turned into jump-tables (dangerous).
19707  For more details see section 
19708 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
19709
19710 \end_inset
19711
19712 .
19713 \end_layout
19714
19715 \begin_layout Itemize
19716
19717 \series bold
19718 noloopreverse
19719 \series default
19720
19721 \begin_inset LatexCommand \index{\#pragma noloopreverse}
19722
19723 \end_inset
19724
19725  - Will not do loop reversal optimization
19726 \end_layout
19727
19728 \begin_layout Itemize
19729
19730 \series bold
19731 nooverlay
19732 \series default
19733
19734 \begin_inset LatexCommand \index{\#pragma nooverlay}
19735
19736 \end_inset
19737
19738  - the compiler will not overlay the parameters and local variables of a
19739  function.
19740 \end_layout
19741
19742 \begin_layout Itemize
19743
19744 \series bold
19745 stackauto
19746 \series default
19747
19748 \begin_inset LatexCommand \index{\#pragma stackauto}
19749
19750 \end_inset
19751
19752 - See option -
19753 \begin_inset ERT
19754 status collapsed
19755
19756 \begin_layout Standard
19757
19758
19759 \backslash
19760 /
19761 \end_layout
19762
19763 \end_inset
19764
19765 -stack-auto
19766 \begin_inset LatexCommand \index{-\/-stack-auto}
19767
19768 \end_inset
19769
19770  and section 
19771 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
19772
19773 \end_inset
19774
19775  Parameters and Local Variables.
19776 \end_layout
19777
19778 \begin_layout Itemize
19779
19780 \series bold
19781 opt_code_speed
19782 \series default
19783  
19784 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
19785
19786 \end_inset
19787
19788 - The compiler will optimize code generation towards fast code, possibly
19789  at the expense of code size.
19790  Currently this has little effect.
19791 \end_layout
19792
19793 \begin_layout Itemize
19794
19795 \series bold
19796 opt_code_size
19797 \series default
19798  
19799 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
19800
19801 \end_inset
19802
19803 - The compiler will optimize code generation towards compact code, possibly
19804  at the expense of code speed.
19805  Currently this has little effect.
19806 \end_layout
19807
19808 \begin_layout Itemize
19809
19810 \series bold
19811 opt_code_balanced
19812 \series default
19813  
19814 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
19815
19816 \end_inset
19817
19818 - The compiler will attempt to generate code that is both compact and fast,
19819  as long as meeting one goal is not a detriment to the other (this is the
19820  default).
19821  
19822 \end_layout
19823
19824 \begin_layout Itemize
19825
19826 \series bold
19827 std_sdcc89
19828 \series default
19829  
19830 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
19831
19832 \end_inset
19833
19834 - Generally follow the C89 standard, but allow SDCC features that conflict
19835  with the standard (default).
19836 \end_layout
19837
19838 \begin_layout Itemize
19839
19840 \series bold
19841 std_c89
19842 \series default
19843  
19844 \begin_inset LatexCommand \index{\#pragma std\_c89}
19845
19846 \end_inset
19847
19848 - Follow the C89 standard and disable SDCC features that conflict with the
19849  standard.
19850 \end_layout
19851
19852 \begin_layout Itemize
19853
19854 \series bold
19855 std_sdcc99
19856 \series default
19857  
19858 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
19859
19860 \end_inset
19861
19862 - Generally follow the C99 standard, but allow SDCC features that conflict
19863  with the standard (incomplete support).
19864 \end_layout
19865
19866 \begin_layout Itemize
19867
19868 \series bold
19869 std_c99
19870 \series default
19871  
19872 \begin_inset LatexCommand \index{\#pragma std\_c99}
19873
19874 \end_inset
19875
19876 - Follow the C99 standard and disable SDCC features that conflict with the
19877  standard (incomplete support).
19878 \end_layout
19879
19880 \begin_layout Itemize
19881
19882 \series bold
19883 codeseg
19884 \series default
19885  <name>
19886 \begin_inset LatexCommand \index{\#pragma codeseg}
19887
19888 \end_inset
19889
19890 - Use this name (max.
19891  8 characters) for the code segment.
19892  See option -
19893 \begin_inset ERT
19894 status collapsed
19895
19896 \begin_layout Standard
19897
19898
19899 \backslash
19900 /
19901 \end_layout
19902
19903 \end_inset
19904
19905 -codeseg.
19906 \end_layout
19907
19908 \begin_layout Itemize
19909
19910 \series bold
19911 constseg
19912 \series default
19913  <name>
19914 \begin_inset LatexCommand \index{\#pragma constseg}
19915
19916 \end_inset
19917
19918 - Use this name (max.
19919  8 characters) for the const segment.
19920  See option -
19921 \begin_inset ERT
19922 status collapsed
19923
19924 \begin_layout Standard
19925
19926
19927 \backslash
19928 /
19929 \end_layout
19930
19931 \end_inset
19932
19933 -constseg.
19934 \end_layout
19935
19936 \begin_layout Standard
19937 The preprocessor SDCPP
19938 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
19939
19940 \end_inset
19941
19942  supports the following #pragma directives:
19943 \end_layout
19944
19945 \begin_layout Itemize
19946
19947 \series bold
19948 pedantic_parse_number
19949 \series default
19950
19951 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19952
19953 \end_inset
19954
19955  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
19956  parsed properly and the macro LO_B(3) gets expanded.
19957  Default is off.
19958  Below is an example on how to use this pragma.
19959
19960 \emph on
19961  Note: this functionality is not in conformance with standard!
19962 \end_layout
19963
19964 \begin_layout Verse
19965
19966 \family typewriter
19967 #pragma pedantic_parse_number +
19968 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19969
19970 \end_inset
19971
19972
19973 \newline
19974
19975 \newline
19976 #define LO_B(x) ((x) & 0xff)
19977 \newline
19978
19979 \newline
19980 unsigned char foo(void)
19981 \newline
19982 {
19983 \newline
19984 \InsetSpace ~
19985 \InsetSpace ~
19986 \InsetSpace ~
19987 unsigned char c=0xfe-LO_B(3)
19988 ;
19989 \newline
19990
19991 \newline
19992 \InsetSpace ~
19993 \InsetSpace ~
19994 \InsetSpace ~
19995 return c;
19996 \newline
19997 }
19998 \newline
19999
20000 \end_layout
20001
20002 \begin_layout Itemize
20003
20004 \series bold
20005 preproc_asm
20006 \series default
20007
20008 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20009
20010 \end_inset
20011
20012  (+ | -) - switch _asm _endasm block preprocessing on / off.
20013  Default is on.
20014  You use this prama to define multilines of assembly code.
20015  This will prevent the preprocessor from changing the formating required
20016  by assembly code.
20017  Below is an example on how to use this pragma.
20018 \end_layout
20019
20020 \begin_layout Verse
20021
20022 \family typewriter
20023 #pragma preproc_asm -
20024 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20025
20026 \end_inset
20027
20028
20029 \newline
20030 #define MYDELAY _asm
20031 \newline
20032 \InsetSpace ~
20033 \InsetSpace ~
20034 \InsetSpace ~
20035 nop ;my assembly comment...
20036 \newline
20037 \InsetSpace ~
20038 \InsetSpace ~
20039 \InsetSpace ~
20040 nop
20041 \newline
20042 \InsetSpace ~
20043 \InsetSpace ~
20044 \InsetSpace ~
20045 nop
20046 \newline
20047 _endasm
20048 \newline
20049 #pragma preproc_asm
20050  +
20051 \newline
20052
20053 \newline
20054 void foo (void) 
20055 \newline
20056
20057 \newline
20058 \InsetSpace ~
20059 \InsetSpace ~
20060 \InsetSpace ~
20061  ...
20062  
20063 \newline
20064 \InsetSpace ~
20065 \InsetSpace ~
20066 \InsetSpace ~
20067  MYDELAY;
20068 \newline
20069 \InsetSpace ~
20070 \InsetSpace ~
20071 \InsetSpace ~
20072  ...
20073  
20074 \newline
20075
20076 \newline
20077
20078 \end_layout
20079
20080 \begin_layout Itemize
20081
20082 \series bold
20083 sdcc_hash
20084 \series default
20085
20086 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
20087
20088 \end_inset
20089
20090  (+ | -) - Allow "naked" hash in macro definition, for example:
20091 \newline
20092
20093 \family typewriter
20094 #define DIR_LO(x) #(x & 0xff)
20095 \family default
20096
20097 \newline
20098 Default is off.
20099  Below is an example on how to use this pragma.
20100 \end_layout
20101
20102 \begin_layout Verse
20103
20104 \family typewriter
20105 #pragma preproc_asm +
20106 \newline
20107 #pragma sdcc_hash +
20108 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
20109
20110 \end_inset
20111
20112
20113 \newline
20114
20115 \newline
20116 #define ROMCALL(x) 
20117 \backslash
20118
20119 \newline
20120 \InsetSpace ~
20121 \InsetSpace ~
20122 \InsetSpace ~
20123 mov R6_B3, #(x & 0xff) 
20124 \backslash
20125
20126 \newline
20127 \InsetSpace ~
20128 \InsetSpace ~
20129 \InsetSpace ~
20130 mov R7_B3, #((x >> 8) & 0xff) 
20131 \backslash
20132
20133 \newline
20134 \InsetSpace ~
20135 \InsetSpace ~
20136 \InsetSpace ~
20137 lcall __romcall
20138 \newline
20139
20140 \newline
20141 ...
20142 \newline
20143 _asm
20144 \newline
20145 ROMCALL(72)
20146 \newline
20147 _endasm;
20148 \newline
20149 ...
20150 \newline
20151
20152 \end_layout
20153
20154 \begin_layout Standard
20155 The pragma's are intended to be used to turn-on or off certain optimizations
20156  which might cause the compiler to generate extra stack / data space to
20157  store compiler generated temporary variables.
20158  This usually happens in large functions.
20159  Pragma directives should be used as shown in the following example, they
20160  are used to control options & optimizations for a given function; pragmas
20161  should be placed before and/or after a function, placing pragma's inside
20162  a function body could have unpredictable results.
20163 \end_layout
20164
20165 \begin_layout Verse
20166
20167 \family typewriter
20168 #pragma save
20169 \begin_inset LatexCommand \index{\#pragma save}
20170
20171 \end_inset
20172
20173  \InsetSpace ~
20174 \InsetSpace ~
20175 \InsetSpace ~
20176 \InsetSpace ~
20177 \InsetSpace ~
20178 \InsetSpace ~
20179 \InsetSpace ~
20180 /* save the current settings */ 
20181 \newline
20182 #pragma nogcse
20183 \begin_inset LatexCommand \index{\#pragma nogcse}
20184
20185 \end_inset
20186
20187  \InsetSpace ~
20188 \InsetSpace ~
20189 \InsetSpace ~
20190 \InsetSpace ~
20191 \InsetSpace ~
20192 /* turnoff global subexpression elimination */ 
20193 \newline
20194 #pragma noinduction
20195 \begin_inset LatexCommand \index{\#pragma noinduction}
20196
20197 \end_inset
20198
20199  /* turn off induction optimizations */ 
20200 \newline
20201 int foo () 
20202 \newline
20203
20204 \newline
20205 \InsetSpace ~
20206  \InsetSpace ~
20207  ...
20208  
20209 \newline
20210 \InsetSpace ~
20211  \InsetSpace ~
20212  /* large code */ 
20213 \newline
20214 \InsetSpace ~
20215  \InsetSpace ~
20216  ...
20217  
20218 \newline
20219
20220 \newline
20221 #pragma restore
20222 \begin_inset LatexCommand \index{\#pragma restore}
20223
20224 \end_inset
20225
20226  /* turn the optimizations back on */
20227 \end_layout
20228
20229 \begin_layout Standard
20230 The compiler will generate a warning message when extra space is allocated.
20231  It is strongly recommended that the save and restore pragma's be used when
20232  changing options for a function.
20233 \newline
20234
20235 \newline
20236
20237 \newline
20238
20239 \end_layout
20240
20241 \begin_layout Section
20242 Defines Created by the Compiler
20243 \end_layout
20244
20245 \begin_layout Standard
20246 The compiler creates the following #defines
20247 \begin_inset LatexCommand \index{\#defines}
20248
20249 \end_inset
20250
20251
20252 \begin_inset LatexCommand \index{Defines created by the compiler}
20253
20254 \end_inset
20255
20256 :
20257 \newline
20258
20259 \end_layout
20260
20261 \begin_layout Standard
20262 \begin_inset Tabular
20263 <lyxtabular version="3" rows="11" columns="2">
20264 <features>
20265 <column alignment="left" valignment="top" leftline="true" width="3in">
20266 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
20267 <row topline="true" bottomline="true">
20268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20269 \begin_inset Text
20270
20271 \begin_layout Standard
20272
20273 \series bold
20274 #define
20275 \end_layout
20276
20277 \end_inset
20278 </cell>
20279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20280 \begin_inset Text
20281
20282 \begin_layout Standard
20283
20284 \series bold
20285 Description
20286 \end_layout
20287
20288 \end_inset
20289 </cell>
20290 </row>
20291 <row topline="true">
20292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20293 \begin_inset Text
20294
20295 \begin_layout Standard
20296 SDCC
20297 \begin_inset LatexCommand \index{SDCC}
20298
20299 \end_inset
20300
20301  
20302 \end_layout
20303
20304 \end_inset
20305 </cell>
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20307 \begin_inset Text
20308
20309 \begin_layout Standard
20310 Always defined.
20311  Since version 2.5.6 the version number as an int (ex.
20312  256)
20313 \end_layout
20314
20315 \end_inset
20316 </cell>
20317 </row>
20318 <row topline="true">
20319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20320 \begin_inset Text
20321
20322 \begin_layout Standard
20323 SDCC_mcs51
20324 \begin_inset LatexCommand \index{SDCC\_mcs51}
20325
20326 \end_inset
20327
20328  or SDCC_ds390
20329 \begin_inset LatexCommand \index{SDCC\_ds390}
20330
20331 \end_inset
20332
20333  or SDCC_z80
20334 \begin_inset LatexCommand \index{SDCC\_z80}
20335
20336 \end_inset
20337
20338 , etc.
20339 \end_layout
20340
20341 \end_inset
20342 </cell>
20343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20344 \begin_inset Text
20345
20346 \begin_layout Standard
20347 depending on the model used (e.g.: -mds390)
20348 \end_layout
20349
20350 \end_inset
20351 </cell>
20352 </row>
20353 <row topline="true">
20354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20355 \begin_inset Text
20356
20357 \begin_layout Standard
20358 __mcs51
20359 \begin_inset LatexCommand \index{\_\_mcs51}
20360
20361 \end_inset
20362
20363 , __ds390
20364 \begin_inset LatexCommand \index{\_\_ds390}
20365
20366 \end_inset
20367
20368 , __hc08
20369 \begin_inset LatexCommand \index{\_\_hc08}
20370
20371 \end_inset
20372
20373 , __z80
20374 \begin_inset LatexCommand \index{\_\_z80}
20375
20376 \end_inset
20377
20378 , etc
20379 \end_layout
20380
20381 \end_inset
20382 </cell>
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20384 \begin_inset Text
20385
20386 \begin_layout Standard
20387 depending on the model used (e.g.
20388  -mz80)
20389 \end_layout
20390
20391 \end_inset
20392 </cell>
20393 </row>
20394 <row topline="true">
20395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20396 \begin_inset Text
20397
20398 \begin_layout Standard
20399 SDCC_STACK_AUTO
20400 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
20401
20402 \end_inset
20403
20404
20405 \end_layout
20406
20407 \end_inset
20408 </cell>
20409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20410 \begin_inset Text
20411
20412 \begin_layout Standard
20413 when 
20414 \emph on
20415 -
20416 \begin_inset ERT
20417 status collapsed
20418
20419 \begin_layout Standard
20420
20421
20422 \backslash
20423 /
20424 \end_layout
20425
20426 \end_inset
20427
20428 -stack-auto
20429 \emph default
20430  option is used
20431 \end_layout
20432
20433 \end_inset
20434 </cell>
20435 </row>
20436 <row topline="true">
20437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20438 \begin_inset Text
20439
20440 \begin_layout Standard
20441 SDCC_MODEL_SMALL
20442 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
20443
20444 \end_inset
20445
20446
20447 \end_layout
20448
20449 \end_inset
20450 </cell>
20451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20452 \begin_inset Text
20453
20454 \begin_layout Standard
20455 when 
20456 \emph on
20457 -
20458 \begin_inset ERT
20459 status collapsed
20460
20461 \begin_layout Standard
20462
20463
20464 \backslash
20465 /
20466 \end_layout
20467
20468 \end_inset
20469
20470 -model-small
20471 \emph default
20472  is used
20473 \end_layout
20474
20475 \end_inset
20476 </cell>
20477 </row>
20478 <row topline="true">
20479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20480 \begin_inset Text
20481
20482 \begin_layout Standard
20483 SDCC_MODEL_MEDIUM
20484 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
20485
20486 \end_inset
20487
20488
20489 \end_layout
20490
20491 \end_inset
20492 </cell>
20493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20494 \begin_inset Text
20495
20496 \begin_layout Standard
20497 when 
20498 \emph on
20499 -
20500 \begin_inset ERT
20501 status collapsed
20502
20503 \begin_layout Standard
20504
20505
20506 \backslash
20507 /
20508 \end_layout
20509
20510 \end_inset
20511
20512 -model-medium
20513 \emph default
20514  is used
20515 \end_layout
20516
20517 \end_inset
20518 </cell>
20519 </row>
20520 <row topline="true">
20521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20522 \begin_inset Text
20523
20524 \begin_layout Standard
20525 SDCC_MODEL_LARGE
20526 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
20527
20528 \end_inset
20529
20530
20531 \end_layout
20532
20533 \end_inset
20534 </cell>
20535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20536 \begin_inset Text
20537
20538 \begin_layout Standard
20539 when 
20540 \emph on
20541 -
20542 \begin_inset ERT
20543 status collapsed
20544
20545 \begin_layout Standard
20546
20547
20548 \backslash
20549 /
20550 \end_layout
20551
20552 \end_inset
20553
20554 -model-large
20555 \emph default
20556  is used
20557 \end_layout
20558
20559 \end_inset
20560 </cell>
20561 </row>
20562 <row topline="true">
20563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20564 \begin_inset Text
20565
20566 \begin_layout Standard
20567 SDCC_USE_XSTACK
20568 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
20569
20570 \end_inset
20571
20572
20573 \end_layout
20574
20575 \end_inset
20576 </cell>
20577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20578 \begin_inset Text
20579
20580 \begin_layout Standard
20581 when 
20582 \emph on
20583 -
20584 \begin_inset ERT
20585 status collapsed
20586
20587 \begin_layout Standard
20588
20589
20590 \backslash
20591 /
20592 \end_layout
20593
20594 \end_inset
20595
20596 -xstack
20597 \emph default
20598  option is used
20599 \end_layout
20600
20601 \end_inset
20602 </cell>
20603 </row>
20604 <row topline="true">
20605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20606 \begin_inset Text
20607
20608 \begin_layout Standard
20609 SDCC_STACK_TENBIT
20610 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
20611
20612 \end_inset
20613
20614  
20615 \end_layout
20616
20617 \end_inset
20618 </cell>
20619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20620 \begin_inset Text
20621
20622 \begin_layout Standard
20623 when 
20624 \emph on
20625 -mds390
20626 \emph default
20627  is used
20628 \end_layout
20629
20630 \end_inset
20631 </cell>
20632 </row>
20633 <row topline="true" bottomline="true">
20634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20635 \begin_inset Text
20636
20637 \begin_layout Standard
20638 SDCC_MODEL_FLAT24
20639 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
20640
20641 \end_inset
20642
20643
20644 \end_layout
20645
20646 \end_inset
20647 </cell>
20648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20649 \begin_inset Text
20650
20651 \begin_layout Standard
20652 when 
20653 \emph on
20654 -mds390
20655 \emph default
20656  is used
20657 \end_layout
20658
20659 \end_inset
20660 </cell>
20661 </row>
20662 </lyxtabular>
20663
20664 \end_inset
20665
20666
20667 \end_layout
20668
20669 \begin_layout Chapter
20670 Notes on supported Processors
20671 \end_layout
20672
20673 \begin_layout Section
20674 MCS51 variants
20675 \begin_inset LatexCommand \label{sub:MCS51-variants}
20676
20677 \end_inset
20678
20679
20680 \begin_inset LatexCommand \index{MCS51 variants}
20681
20682 \end_inset
20683
20684
20685 \end_layout
20686
20687 \begin_layout Standard
20688 MCS51 processors are available from many vendors and come in many different
20689  flavours.
20690  While they might differ considerably in respect to Special Function Registers
20691  the core MCS51 is usually not modified or is kept compatible.
20692  
20693 \end_layout
20694
20695 \begin_layout Subsection
20696 pdata access by SFR 
20697 \end_layout
20698
20699 \begin_layout Standard
20700 With the upcome of devices with internal xdata and flash memory devices
20701  using port P2
20702 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20703
20704 \end_inset
20705
20706  as dedicated I/O port is becoming more popular.
20707  Switching the high byte for pdata
20708 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20709
20710 \end_inset
20711
20712  access which was formerly done by port P2 is then achieved by a Special
20713  Function Register
20714 \begin_inset LatexCommand \index{sfr}
20715
20716 \end_inset
20717
20718 .
20719  In well-established MCS51 tradition the address of this 
20720 \emph on
20721 sfr
20722 \emph default
20723  is where the chip designers decided to put it.
20724  Needless to say that they didn't agree on a common name either.
20725  So that the startup code can correctly initialize xdata variables, you
20726  should define an sfr with the name _XPAGE
20727 \family typewriter
20728
20729 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
20730
20731 \end_inset
20732
20733
20734 \family default
20735  at the appropriate location if the default, port P2, is not used for this.
20736  Some examples are:
20737 \end_layout
20738
20739 \begin_layout Verse
20740
20741 \family typewriter
20742 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
20743 \end_layout
20744
20745 \begin_layout Verse
20746
20747 \family typewriter
20748 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
20749 \end_layout
20750
20751 \begin_layout Verse
20752
20753 \family typewriter
20754 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
20755 \end_layout
20756
20757 \begin_layout Standard
20758 For more exotic implementations further customizations may be needed.
20759  See section 
20760 \begin_inset LatexCommand \ref{sub:Startup-Code}
20761
20762 \end_inset
20763
20764  for other possibilities.
20765 \end_layout
20766
20767 \begin_layout Subsection
20768 Other Features available by SFR
20769 \end_layout
20770
20771 \begin_layout Standard
20772 Some MCS51 variants offer features like Double DPTR
20773 \begin_inset LatexCommand \index{DPTR}
20774
20775 \end_inset
20776
20777 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
20778  These are currently not used for the MCS51 port.
20779  If you absolutely need them you can fall back to inline assembly or submit
20780  a patch to SDCC.
20781 \begin_inset VSpace bigskip
20782 \end_inset
20783
20784
20785 \end_layout
20786
20787 \begin_layout Section
20788 DS400 port
20789 \end_layout
20790
20791 \begin_layout Standard
20792 The DS80C400
20793 \begin_inset LatexCommand \index{DS80C400}
20794
20795 \end_inset
20796
20797
20798 \begin_inset LatexCommand \index{DS400}
20799
20800 \end_inset
20801
20802  microcontroller has a rich set of peripherals.
20803  In its built-in ROM library it includes functions to access some of the
20804  features, among them is a TCP stack with IP4 and IP6 support.
20805  Library headers (currently in beta status) and other files are provided
20806  at 
20807 \size footnotesize
20808
20809 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
20810
20811 \end_inset
20812
20813 .
20814  
20815 \begin_inset VSpace bigskip
20816 \end_inset
20817
20818
20819 \end_layout
20820
20821 \begin_layout Section
20822 The Z80 and gbz80 port
20823 \end_layout
20824
20825 \begin_layout Standard
20826 SDCC can target both the Zilog Z80
20827 \begin_inset LatexCommand \index{Z80}
20828
20829 \end_inset
20830
20831  and the Nintendo Gameboy's Z80-like gbz80
20832 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
20833
20834 \end_inset
20835
20836 .
20837  The Z80 port is passed through the same 
20838 \emph on
20839 regressions tests
20840 \begin_inset LatexCommand \index{Regression test}
20841
20842 \end_inset
20843
20844
20845 \emph default
20846  (see section 
20847 \begin_inset LatexCommand \ref{sec:Quality-control}
20848
20849 \end_inset
20850
20851 ) as the MCS51 and DS390 ports, so floating point support, support for long
20852  variables and bitfield support is fine.
20853  See mailing lists and forums about interrupt routines.
20854 \end_layout
20855
20856 \begin_layout Standard
20857 As always, the code is the authoritative reference - see z80/ralloc.c and
20858  z80/gen.c.
20859  The stack
20860 \begin_inset LatexCommand \index{Z80!stack}
20861
20862 \end_inset
20863
20864  frame is similar to that generated by the IAR Z80 compiler.
20865  IX is used as the base pointer, HL and IY are used as a temporary registers,
20866  and BC and DE are available for holding variables.
20867  Return values
20868 \begin_inset LatexCommand \index{Z80!return value}
20869
20870 \end_inset
20871
20872  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
20873  bytes).
20874  The gbz80 port use the same set of registers for the return values, but
20875  in a different order of significance: E (one byte), DE (two bytes), or
20876  HLDE (four bytes).
20877 \begin_inset VSpace bigskip
20878 \end_inset
20879
20880
20881 \end_layout
20882
20883 \begin_layout Section
20884 The HC08 port
20885 \end_layout
20886
20887 \begin_layout Standard
20888 The port to the Freescale/Motorola HC08
20889 \begin_inset LatexCommand \index{HC08}
20890
20891 \end_inset
20892
20893  family has been added in October 2003, and is still undergoing some basic
20894  development.
20895  The code generator is complete, but the register allocation is still quite
20896  unoptimized.
20897  Some of the SDCC's standard C library functions have embedded non-HC08
20898  inline assembly and so are not yet usable.
20899 \end_layout
20900
20901 \begin_layout Standard
20902 The HC08 port passes the regression test suite (see section 
20903 \begin_inset LatexCommand \ref{sec:Quality-control}
20904
20905 \end_inset
20906
20907 ).
20908 \begin_inset VSpace bigskip
20909 \end_inset
20910
20911
20912 \end_layout
20913
20914 \begin_layout Standard
20915
20916 \newpage
20917
20918 \end_layout
20919
20920 \begin_layout Section
20921 The PIC14 port
20922 \end_layout
20923
20924 \begin_layout Standard
20925 The 14bit PIC
20926 \begin_inset LatexCommand \index{PIC14}
20927
20928 \end_inset
20929
20930  port still requires a major effort from the development community.
20931  However it can work for simple code.
20932  It passes its (smaller set of) regression tests
20933 \begin_inset LatexCommand \index{Regression test (PIC14)}
20934
20935 \end_inset
20936
20937  in the directory 
20938 \shape italic
20939 sdcc/src/regression
20940 \shape default
20941 .
20942 \end_layout
20943
20944 \begin_layout Subsection
20945 C code and 14bit PIC code page
20946 \begin_inset LatexCommand \index{code page (pic14)}
20947
20948 \end_inset
20949
20950  and RAM banks
20951 \begin_inset LatexCommand \index{RAM bank (pic14)}
20952
20953 \end_inset
20954
20955
20956 \end_layout
20957
20958 \begin_layout Standard
20959 The linker organizes allocation for the code page and RAM banks.
20960  It does not have intimate knowledge of the code flow.
20961  It will put all the code section of a single asm file into a single code
20962  page.
20963  In order to make use of multiple code pages, separate asm files must be
20964  used.
20965  The compiler treats all functions of a single C file as being in the same
20966  code page unless it is non static.
20967 \newline
20968
20969 \newline
20970 To get the best follow these guide lines:
20971 \end_layout
20972
20973 \begin_layout Enumerate
20974 Make local functions static, as non static functions require code page selection
20975  overhead.
20976 \end_layout
20977
20978 \begin_layout Enumerate
20979 For devices that have multiple code pages it is more efficient to use the
20980  same number of files as pages, i.e.
20981  for the 16F877 use 4 separate files and i.e.
20982  for the 16F874 use 2 separate files.
20983  This way the linker can put the code for each file into different code
20984  pages and there's less page selection overhead.
20985 \end_layout
20986
20987 \begin_layout Enumerate
20988  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
20989  instruction set), use 'unsigned char' whereever possible instead of 'int'.
20990 \end_layout
20991
20992 \begin_layout Subsection
20993 Creating a device include file 
20994 \end_layout
20995
20996 \begin_layout Standard
20997 For generating a device include file
20998 \begin_inset LatexCommand \index{PIC14!Header files}
20999
21000 \end_inset
21001
21002  use the support perl script inc2h.pl kept in directory support/script.
21003 \end_layout
21004
21005 \begin_layout Subsection
21006 Interrupt code
21007 \end_layout
21008
21009 \begin_layout Standard
21010 For the interrupt function, use the keyword '__interrupt'
21011 \begin_inset LatexCommand \index{PIC14!interrupt}
21012
21013 \end_inset
21014
21015  with level number of 0 (PIC14 only has 1 interrupt so this number is only
21016  there to avoid a syntax error - it ought to be fixed).
21017  E.g.:
21018 \end_layout
21019
21020 \begin_layout Verse
21021
21022 \family typewriter
21023 void Intr(void) __interrupt 0
21024 \newline
21025 {
21026 \newline
21027 \InsetSpace ~
21028 \InsetSpace ~
21029 T0IF = 0; /* Clear timer interrupt */
21030 \newline
21031 }
21032 \end_layout
21033
21034 \begin_layout Subsection
21035 Linking and assembling
21036 \end_layout
21037
21038 \begin_layout Standard
21039 For assembling you can use either GPUTILS'
21040 \begin_inset LatexCommand \index{gputils (pic tools)}
21041
21042 \end_inset
21043
21044  gpasm.exe or MPLAB's mpasmwin.exe.
21045  GPUTILS is available from 
21046 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21047
21048 \end_inset
21049
21050 .
21051  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
21052  If you use MPLAB and an interrupt function then the linker script file
21053  vectors section will need to be enlarged to link with mplink.
21054 \newline
21055
21056 \newline
21057 Here is a 
21058 \family typewriter
21059 Makefile
21060 \family default
21061  using GPUTILS:
21062 \end_layout
21063
21064 \begin_layout Verse
21065
21066 \family typewriter
21067 .c.o:
21068 \newline
21069 \InsetSpace ~
21070 \InsetSpace ~
21071 \InsetSpace ~
21072 \InsetSpace ~
21073 \InsetSpace ~
21074 \InsetSpace ~
21075 \InsetSpace ~
21076 \InsetSpace ~
21077 sdcc -S -V -mpic14 -p16F877 $< 
21078 \newline
21079 \InsetSpace ~
21080 \InsetSpace ~
21081 \InsetSpace ~
21082 \InsetSpace ~
21083 \InsetSpace ~
21084 \InsetSpace ~
21085 \InsetSpace ~
21086 \InsetSpace ~
21087 gpasm -c $*.asm
21088 \newline
21089
21090 \newline
21091 $(PRJ).hex: $(OBJS) 
21092 \newline
21093 \InsetSpace ~
21094 \InsetSpace ~
21095 \InsetSpace ~
21096 \InsetSpace ~
21097 \InsetSpace ~
21098 \InsetSpace ~
21099 \InsetSpace ~
21100 \InsetSpace ~
21101 gplink
21102  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
21103 \end_layout
21104
21105 \begin_layout Standard
21106 Here is a 
21107 \family typewriter
21108 Makefile
21109 \family default
21110  using MPLAB:
21111 \end_layout
21112
21113 \begin_layout Verse
21114
21115 \family typewriter
21116 .c.o: 
21117 \newline
21118 \InsetSpace ~
21119 \InsetSpace ~
21120 \InsetSpace ~
21121 \InsetSpace ~
21122 \InsetSpace ~
21123 \InsetSpace ~
21124 \InsetSpace ~
21125 \InsetSpace ~
21126 sdcc -S -V -mpic14 -p16F877 $< 
21127 \newline
21128 \InsetSpace ~
21129 \InsetSpace ~
21130 \InsetSpace ~
21131 \InsetSpace ~
21132 \InsetSpace ~
21133 \InsetSpace ~
21134 \InsetSpace ~
21135 \InsetSpace ~
21136 mpasmwin /q /o $*.asm
21137 \newline
21138
21139 \newline
21140 $(PRJ).hex: $(OBJS)
21141  
21142 \newline
21143 \InsetSpace ~
21144 \InsetSpace ~
21145 \InsetSpace ~
21146 \InsetSpace ~
21147 \InsetSpace ~
21148 \InsetSpace ~
21149 \InsetSpace ~
21150 \InsetSpace ~
21151 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
21152 \end_layout
21153
21154 \begin_layout Standard
21155 Please note that indentations within a
21156 \family typewriter
21157  Makefile
21158 \family default
21159  have to be done with a tabulator character.
21160 \end_layout
21161
21162 \begin_layout Subsection
21163 Command-line options
21164 \end_layout
21165
21166 \begin_layout Standard
21167 Besides the switches common to all SDCC backends, the PIC14 port accepts
21168  the following options (for an updated list see sdcc -
21169 \begin_inset ERT
21170 status collapsed
21171
21172 \begin_layout Standard
21173
21174
21175 \backslash
21176 /
21177 \end_layout
21178
21179 \end_inset
21180
21181 -help):
21182 \end_layout
21183
21184 \begin_layout List
21185 \labelwidthstring 00.00.0000
21186 -
21187 \begin_inset ERT
21188 status collapsed
21189
21190 \begin_layout Standard
21191
21192
21193 \backslash
21194 /
21195 \end_layout
21196
21197 \end_inset
21198
21199 -debug-extra
21200 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
21201
21202 \end_inset
21203
21204  emit debug info in assembly output
21205 \end_layout
21206
21207 \begin_layout List
21208 \labelwidthstring 00.00.0000
21209 -
21210 \begin_inset ERT
21211 status collapsed
21212
21213 \begin_layout Standard
21214
21215
21216 \backslash
21217 /
21218 \end_layout
21219
21220 \end_inset
21221
21222 -no-pcode-opt
21223 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
21224
21225 \end_inset
21226
21227  disable (slightly faulty) optimization on pCode
21228 \end_layout
21229
21230 \begin_layout List
21231 \labelwidthstring 00.00.0000
21232 -
21233 \begin_inset ERT
21234 status collapsed
21235
21236 \begin_layout Standard
21237
21238
21239 \backslash
21240 /
21241 \end_layout
21242
21243 \end_inset
21244
21245 -stack-loc
21246 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
21247
21248 \end_inset
21249
21250  sets the lowest address of the argument passing stack (defaults to a suitably
21251  large shared databank to reduce BANKSEL overhead)
21252 \end_layout
21253
21254 \begin_layout List
21255 \labelwidthstring 00.00.0000
21256 -
21257 \begin_inset ERT
21258 status collapsed
21259
21260 \begin_layout Standard
21261
21262
21263 \backslash
21264 /
21265 \end_layout
21266
21267 \end_inset
21268
21269 -stack-size
21270 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
21271
21272 \end_inset
21273
21274  sets the size if the argument passing stack (default: 16, minimum: 4)
21275 \end_layout
21276
21277 \begin_layout Subsection
21278 The library
21279 \end_layout
21280
21281 \begin_layout Subsubsection
21282 error: missing definition for symbol 
21283 \begin_inset Quotes sld
21284 \end_inset
21285
21286 __gptrget1
21287 \begin_inset Quotes srd
21288 \end_inset
21289
21290
21291 \end_layout
21292
21293 \begin_layout Standard
21294 The PIC14 port uses library routines to provide more complex operations
21295  like multiplication, division/modulus and (generic) pointer dereferencing.
21296  In order to add these routines to your project, you must link with PIC14's
21297  
21298 \family typewriter
21299 libsdcc.lib
21300 \family default
21301 .
21302  For single source file projects this is done automatically, more complex
21303  projects must add 
21304 \family typewriter
21305 libsdcc.lib
21306 \family default
21307  to the linker's arguments.
21308  Make sure you also add an include path for the library (using the -I switch
21309  to the linker)!
21310 \end_layout
21311
21312 \begin_layout Subsubsection
21313 Processor mismatch in file 
21314 \begin_inset Quotes sld
21315 \end_inset
21316
21317 XXX
21318 \begin_inset Quotes srd
21319 \end_inset
21320
21321 .
21322 \end_layout
21323
21324 \begin_layout Standard
21325 This warning can usually be ignored due to the very good compatibility amongst
21326  14 bit PIC
21327 \begin_inset LatexCommand \index{PIC14}
21328
21329 \end_inset
21330
21331  devices.
21332 \end_layout
21333
21334 \begin_layout Standard
21335 You might also consider recompiling the library for your specific device
21336  by changing the ARCH=p16f877 (default target) entry in 
21337 \family typewriter
21338 device/lib/pic/Makefile.in
21339 \family default
21340  and 
21341 \family typewriter
21342 device/lib/pic/Makefile
21343 \family default
21344  to reflect your device.
21345  This might even improve performance for smaller devices as unneccesary
21346  BANKSELs migth be removed.
21347 \end_layout
21348
21349 \begin_layout Subsection
21350 Known bugs
21351 \end_layout
21352
21353 \begin_layout Subsubsection
21354 initialized data
21355 \end_layout
21356
21357 \begin_layout Standard
21358 Currently, data can only be initialized if it resides in the source file
21359  together with 
21360 \emph on
21361 main()
21362 \emph default
21363 .
21364  Data in other source files will silently 
21365 \series bold
21366 not
21367 \series default
21368  be initialized.
21369 \family typewriter
21370 \size footnotesize
21371
21372 \begin_inset Marginal
21373 status collapsed
21374
21375 \begin_layout Standard
21376
21377 \series bold
21378 \InsetSpace ~
21379 !
21380 \end_layout
21381
21382 \end_inset
21383
21384
21385 \end_layout
21386
21387 \begin_layout Standard
21388
21389 \newpage
21390
21391 \end_layout
21392
21393 \begin_layout Section
21394 The PIC16
21395 \begin_inset LatexCommand \index{PIC16}
21396
21397 \end_inset
21398
21399  port
21400 \end_layout
21401
21402 \begin_layout Standard
21403 The PIC16
21404 \begin_inset LatexCommand \index{PIC16}
21405
21406 \end_inset
21407
21408  port is the portion of SDCC that is responsible to produce code for the
21409  Microchip
21410 \begin_inset LatexCommand \index{Microchip}
21411
21412 \end_inset
21413
21414 (TM) microcontrollers with 16 bit core.
21415  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
21416  Currently supported devices are:
21417 \end_layout
21418
21419 \begin_layout Standard
21420 \align center
21421 \begin_inset Tabular
21422 <lyxtabular version="3" rows="4" columns="6">
21423 <features>
21424 <column alignment="center" valignment="top" leftline="true" width="0">
21425 <column alignment="center" valignment="top" leftline="true" width="0">
21426 <column alignment="center" valignment="top" leftline="true" width="0">
21427 <column alignment="center" valignment="top" leftline="true" width="0">
21428 <column alignment="center" valignment="top" leftline="true" width="0">
21429 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21430 <row topline="true">
21431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21432 \begin_inset Text
21433
21434 \begin_layout Standard
21435 18F242
21436 \end_layout
21437
21438 \end_inset
21439 </cell>
21440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21441 \begin_inset Text
21442
21443 \begin_layout Standard
21444 18F248
21445 \end_layout
21446
21447 \end_inset
21448 </cell>
21449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21450 \begin_inset Text
21451
21452 \begin_layout Standard
21453 18F252
21454 \end_layout
21455
21456 \end_inset
21457 </cell>
21458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21459 \begin_inset Text
21460
21461 \begin_layout Standard
21462 18F258
21463 \end_layout
21464
21465 \end_inset
21466 </cell>
21467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21468 \begin_inset Text
21469
21470 \begin_layout Standard
21471 18F442
21472 \end_layout
21473
21474 \end_inset
21475 </cell>
21476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21477 \begin_inset Text
21478
21479 \begin_layout Standard
21480 18F448
21481 \end_layout
21482
21483 \end_inset
21484 </cell>
21485 </row>
21486 <row topline="true">
21487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21488 \begin_inset Text
21489
21490 \begin_layout Standard
21491 18F452
21492 \end_layout
21493
21494 \end_inset
21495 </cell>
21496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21497 \begin_inset Text
21498
21499 \begin_layout Standard
21500 18F458
21501 \end_layout
21502
21503 \end_inset
21504 </cell>
21505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21506 \begin_inset Text
21507
21508 \begin_layout Standard
21509 18F1220
21510 \end_layout
21511
21512 \end_inset
21513 </cell>
21514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21515 \begin_inset Text
21516
21517 \begin_layout Standard
21518 18F2220
21519 \end_layout
21520
21521 \end_inset
21522 </cell>
21523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21524 \begin_inset Text
21525
21526 \begin_layout Standard
21527 18F2550
21528 \end_layout
21529
21530 \end_inset
21531 </cell>
21532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21533 \begin_inset Text
21534
21535 \begin_layout Standard
21536 18F4331
21537 \end_layout
21538
21539 \end_inset
21540 </cell>
21541 </row>
21542 <row topline="true">
21543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21544 \begin_inset Text
21545
21546 \begin_layout Standard
21547 18F4455
21548 \end_layout
21549
21550 \end_inset
21551 </cell>
21552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21553 \begin_inset Text
21554
21555 \begin_layout Standard
21556 18F6520
21557 \end_layout
21558
21559 \end_inset
21560 </cell>
21561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21562 \begin_inset Text
21563
21564 \begin_layout Standard
21565 18F6620
21566 \end_layout
21567
21568 \end_inset
21569 </cell>
21570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21571 \begin_inset Text
21572
21573 \begin_layout Standard
21574 18F6680
21575 \end_layout
21576
21577 \end_inset
21578 </cell>
21579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21580 \begin_inset Text
21581
21582 \begin_layout Standard
21583 18F6720
21584 \end_layout
21585
21586 \end_inset
21587 </cell>
21588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21589 \begin_inset Text
21590
21591 \begin_layout Standard
21592 18F8520
21593 \end_layout
21594
21595 \end_inset
21596 </cell>
21597 </row>
21598 <row topline="true" bottomline="true">
21599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21600 \begin_inset Text
21601
21602 \begin_layout Standard
21603 18F8620
21604 \end_layout
21605
21606 \end_inset
21607 </cell>
21608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21609 \begin_inset Text
21610
21611 \begin_layout Standard
21612 18F8680
21613 \end_layout
21614
21615 \end_inset
21616 </cell>
21617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21618 \begin_inset Text
21619
21620 \begin_layout Standard
21621 18F8720
21622 \end_layout
21623
21624 \end_inset
21625 </cell>
21626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21627 \begin_inset Text
21628
21629 \begin_layout Standard
21630
21631 \end_layout
21632
21633 \end_inset
21634 </cell>
21635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21636 \begin_inset Text
21637
21638 \begin_layout Standard
21639
21640 \end_layout
21641
21642 \end_inset
21643 </cell>
21644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21645 \begin_inset Text
21646
21647 \begin_layout Standard
21648
21649 \end_layout
21650
21651 \end_inset
21652 </cell>
21653 </row>
21654 </lyxtabular>
21655
21656 \end_inset
21657
21658
21659 \end_layout
21660
21661 \begin_layout Subsection
21662 Global Options
21663 \end_layout
21664
21665 \begin_layout Standard
21666 PIC16 port supports the standard command line arguments as supposed, with
21667  the exception of certain cases that will be mentioned in the following
21668  list:
21669 \end_layout
21670
21671 \begin_layout List
21672 \labelwidthstring 00.00.0000
21673 -
21674 \begin_inset ERT
21675 status collapsed
21676
21677 \begin_layout Standard
21678
21679
21680 \backslash
21681 /
21682 \end_layout
21683
21684 \end_inset
21685
21686 -callee-saves
21687 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
21688
21689 \end_inset
21690
21691  See -
21692 \begin_inset ERT
21693 status collapsed
21694
21695 \begin_layout Standard
21696
21697
21698 \backslash
21699 /
21700 \end_layout
21701
21702 \end_inset
21703
21704 -all-callee-saves
21705 \end_layout
21706
21707 \begin_layout List
21708 \labelwidthstring 00.00.0000
21709 -
21710 \begin_inset ERT
21711 status collapsed
21712
21713 \begin_layout Standard
21714
21715
21716 \backslash
21717 /
21718 \end_layout
21719
21720 \end_inset
21721
21722 -all-callee-saves
21723 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
21724
21725 \end_inset
21726
21727  All function arguments are passed on stack by default.
21728  
21729 \emph on
21730 There is no need to specify this in the command line.
21731 \end_layout
21732
21733 \begin_layout List
21734 \labelwidthstring 00.00.0000
21735 -
21736 \begin_inset ERT
21737 status collapsed
21738
21739 \begin_layout Standard
21740
21741
21742 \backslash
21743 /
21744 \end_layout
21745
21746 \end_inset
21747
21748 -fommit-frame-pointer
21749 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
21750
21751 \end_inset
21752
21753  Frame pointer will be omitted when the function uses no local variables.
21754 \end_layout
21755
21756 \begin_layout Subsection
21757 Port Specific Options
21758 \begin_inset LatexCommand \index{Options PIC16}
21759
21760 \end_inset
21761
21762
21763 \end_layout
21764
21765 \begin_layout Standard
21766 The port specific options appear after the global options in the sdcc --help
21767  output.
21768 \end_layout
21769
21770 \begin_layout Subsubsection
21771 General Options
21772 \end_layout
21773
21774 \begin_layout Standard
21775 General options enable certain port features and optimizations.
21776 \end_layout
21777
21778 \begin_layout List
21779 \labelwidthstring 00.00.0000
21780 -
21781 \begin_inset ERT
21782 status collapsed
21783
21784 \begin_layout Standard
21785
21786
21787 \backslash
21788 /
21789 \end_layout
21790
21791 \end_inset
21792
21793 -pstack-model=[model] Used in conjuction with the command above.
21794  Defines the stack model to be used, valid stack models are : 
21795 \end_layout
21796
21797 \begin_deeper
21798 \begin_layout List
21799 \labelwidthstring 00.00.0000
21800
21801 \emph on
21802 small
21803 \emph default
21804  Selects small stack model.
21805  8 bit stack and frame pointers.
21806  Supports 256 bytes stack size.
21807 \end_layout
21808
21809 \begin_layout List
21810 \labelwidthstring 00.00.0000
21811
21812 \emph on
21813 large
21814 \emph default
21815  Selects large stack model.
21816  16 bit stack and frame pointers.
21817  Supports 65536 bytes stack size.
21818 \end_layout
21819
21820 \end_deeper
21821 \begin_layout List
21822 \labelwidthstring 00.00.0000
21823 -
21824 \begin_inset ERT
21825 status collapsed
21826
21827 \begin_layout Standard
21828
21829
21830 \backslash
21831 /
21832 \end_layout
21833
21834 \end_inset
21835
21836 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
21837  unitialized data variables with [kword].
21838  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
21839 \end_layout
21840
21841 \begin_layout List
21842 \labelwidthstring 00.00.0000
21843 -
21844 \begin_inset ERT
21845 status collapsed
21846
21847 \begin_layout Standard
21848
21849
21850 \backslash
21851 /
21852 \end_layout
21853
21854 \end_inset
21855
21856 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
21857  Useful for bootloaders.
21858 \end_layout
21859
21860 \begin_layout List
21861 \labelwidthstring 00.00.0000
21862 -
21863 \begin_inset ERT
21864 status collapsed
21865
21866 \begin_layout Standard
21867
21868
21869 \backslash
21870 /
21871 \end_layout
21872
21873 \end_inset
21874
21875 -asm= sets the full path and name of an external assembler to call.
21876 \end_layout
21877
21878 \begin_layout List
21879 \labelwidthstring 00.00.0000
21880 -
21881 \begin_inset ERT
21882 status collapsed
21883
21884 \begin_layout Standard
21885
21886
21887 \backslash
21888 /
21889 \end_layout
21890
21891 \end_inset
21892
21893 -link= sets the full path and name of an external linker to call.
21894 \end_layout
21895
21896 \begin_layout List
21897 \labelwidthstring 00.00.0000
21898 -
21899 \begin_inset ERT
21900 status collapsed
21901
21902 \begin_layout Standard
21903
21904
21905 \backslash
21906 /
21907 \end_layout
21908
21909 \end_inset
21910
21911 -mplab-comp MPLAB
21912 \begin_inset LatexCommand \index{PIC16!MPLAB}
21913
21914 \end_inset
21915
21916  compatibility option.
21917  Currently only suppresses special gpasm directives.
21918 \end_layout
21919
21920 \begin_layout Subsubsection
21921 Optimization Options
21922 \end_layout
21923
21924 \begin_layout List
21925 \labelwidthstring 00.00.0000
21926 -
21927 \begin_inset ERT
21928 status collapsed
21929
21930 \begin_layout Standard
21931
21932
21933 \backslash
21934 /
21935 \end_layout
21936
21937 \end_inset
21938
21939 -optimize-goto Try to use (conditional) BRA instead of GOTO
21940 \end_layout
21941
21942 \begin_layout List
21943 \labelwidthstring 00.00.0000
21944 -
21945 \begin_inset ERT
21946 status collapsed
21947
21948 \begin_layout Standard
21949
21950
21951 \backslash
21952 /
21953 \end_layout
21954
21955 \end_inset
21956
21957 -optimize-cmp Try to optimize some compares.
21958 \end_layout
21959
21960 \begin_layout List
21961 \labelwidthstring 00.00.0000
21962 -
21963 \begin_inset ERT
21964 status collapsed
21965
21966 \begin_layout Standard
21967
21968
21969 \backslash
21970 /
21971 \end_layout
21972
21973 \end_inset
21974
21975 -optimize-df Analyze the dataflow of the generated code and improve it.
21976 \end_layout
21977
21978 \begin_layout List
21979 \labelwidthstring 00.00.0000
21980 -
21981 \begin_inset ERT
21982 status collapsed
21983
21984 \begin_layout Standard
21985
21986
21987 \backslash
21988 /
21989 \end_layout
21990
21991 \end_inset
21992
21993 -obanksel=nn Set optimization level for inserting BANKSELs.
21994 \newline
21995
21996 \end_layout
21997
21998 \begin_deeper
21999 \begin_layout List
22000 \labelwidthstring 00.00.0000
22001 0 no optimization
22002 \end_layout
22003
22004 \begin_layout List
22005 \labelwidthstring 00.00.0000
22006 1 checks previous used register and if it is the same then does not emit
22007  BANKSEL, accounts only for labels.
22008 \end_layout
22009
22010 \begin_layout List
22011 \labelwidthstring 00.00.0000
22012 2 tries to check the location of (even different) symbols and removes BANKSELs
22013  if they are in the same bank.
22014  
22015 \newline
22016
22017 \emph on
22018 Important: There might be problems if the linker script has data sections
22019  across bank borders!
22020 \end_layout
22021
22022 \end_deeper
22023 \begin_layout Subsubsection
22024 Linking Options
22025 \end_layout
22026
22027 \begin_layout List
22028 \labelwidthstring 00.00.0000
22029 -
22030 \begin_inset ERT
22031 status collapsed
22032
22033 \begin_layout Standard
22034
22035
22036 \backslash
22037 /
22038 \end_layout
22039
22040 \end_inset
22041
22042 -nodefaultlibs do not link default libraries when linking
22043 \end_layout
22044
22045 \begin_layout List
22046 \labelwidthstring 00.00.0000
22047 -
22048 \begin_inset ERT
22049 status collapsed
22050
22051 \begin_layout Standard
22052
22053
22054 \backslash
22055 /
22056 \end_layout
22057
22058 \end_inset
22059
22060 -no-crt Don't link the default run-time modules
22061 \end_layout
22062
22063 \begin_layout List
22064 \labelwidthstring 00.00.0000
22065 -
22066 \begin_inset ERT
22067 status collapsed
22068
22069 \begin_layout Standard
22070
22071
22072 \backslash
22073 /
22074 \end_layout
22075
22076 \end_inset
22077
22078 -use-crt= Use a custom run-time module instead of the defaults.
22079 \end_layout
22080
22081 \begin_layout Subsubsection
22082 Debugging Options
22083 \end_layout
22084
22085 \begin_layout Standard
22086 Debugging options enable extra debugging information in the output files.
22087 \end_layout
22088
22089 \begin_layout List
22090 \labelwidthstring 00.00.0000
22091 -
22092 \begin_inset ERT
22093 status collapsed
22094
22095 \begin_layout Standard
22096
22097
22098 \backslash
22099 /
22100 \end_layout
22101
22102 \end_inset
22103
22104 -debug-xtra Similar to -
22105 \begin_inset ERT
22106 status collapsed
22107
22108 \begin_layout Standard
22109
22110
22111 \backslash
22112 /
22113 \end_layout
22114
22115 \end_inset
22116
22117 -debug
22118 \begin_inset LatexCommand \index{-\/-debug}
22119
22120 \end_inset
22121
22122 , but dumps more information.
22123 \end_layout
22124
22125 \begin_layout List
22126 \labelwidthstring 00.00.0000
22127 -
22128 \begin_inset ERT
22129 status collapsed
22130
22131 \begin_layout Standard
22132
22133
22134 \backslash
22135 /
22136 \end_layout
22137
22138 \end_inset
22139
22140 -debug-ralloc Force register allocator to dump <source>.d file with debugging
22141  information.
22142  <source> is the name of the file compiled.
22143 \end_layout
22144
22145 \begin_layout List
22146 \labelwidthstring 00.00.0000
22147 -
22148 \begin_inset ERT
22149 status collapsed
22150
22151 \begin_layout Standard
22152
22153
22154 \backslash
22155 /
22156 \end_layout
22157
22158 \end_inset
22159
22160 -pcode-verbose Enable pcode debugging information in translation.
22161 \end_layout
22162
22163 \begin_layout List
22164 \labelwidthstring 00.00.0000
22165 -
22166 \begin_inset ERT
22167 status collapsed
22168
22169 \begin_layout Standard
22170
22171
22172 \backslash
22173 /
22174 \end_layout
22175
22176 \end_inset
22177
22178 -denable-peeps Force the usage of peepholes.
22179  Use with care.
22180 \end_layout
22181
22182 \begin_layout List
22183 \labelwidthstring 00.00.0000
22184 -
22185 \begin_inset ERT
22186 status collapsed
22187
22188 \begin_layout Standard
22189
22190
22191 \backslash
22192 /
22193 \end_layout
22194
22195 \end_inset
22196
22197 -gstack Trace push/pops for stack pointer overflow
22198 \end_layout
22199
22200 \begin_layout List
22201 \labelwidthstring 00.00.0000
22202 -
22203 \begin_inset ERT
22204 status collapsed
22205
22206 \begin_layout Standard
22207
22208
22209 \backslash
22210 /
22211 \end_layout
22212
22213 \end_inset
22214
22215 -call-tree dump call tree in .calltree file
22216 \end_layout
22217
22218 \begin_layout Subsection
22219 Enviromental Variables
22220 \end_layout
22221
22222 \begin_layout Standard
22223 There is a number of enviromental variables that can be used when running
22224  SDCC to enable certain optimizations or force a specific program behaviour.
22225  these variables are primarily for debugging purposes so they can be enabled/dis
22226 abled at will.
22227 \end_layout
22228
22229 \begin_layout Standard
22230 Currently there is only two such variables available:
22231 \end_layout
22232
22233 \begin_layout List
22234 \labelwidthstring 00.00.0000
22235 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
22236  bitfields is optimized by directly loading FSR0 with the address of the
22237  bitfield structure.
22238  Normally SDCC will cast the bitfield structure to a bitfield pointer and
22239  then load FSR0.
22240  This step saves data ram and code space for functions that perform heavy
22241  use of bitfields.
22242  (ie.
22243  80 bytes of code space are saved when compiling malloc.c with this option).
22244  
22245 \end_layout
22246
22247 \begin_layout List
22248 \labelwidthstring 00.00.0000
22249 NO_REG_OPT do not perform pCode registers optimization.
22250  This should be used for debugging purposes.
22251  In some where bugs in the pcode optimizer are found, users can benefit
22252  from temporarily disabling the optimizer until the bug is fixed.
22253 \end_layout
22254
22255 \begin_layout Subsection
22256 Preprocessor Macros
22257 \end_layout
22258
22259 \begin_layout Standard
22260 PIC16
22261 \begin_inset LatexCommand \index{PIC16}
22262
22263 \end_inset
22264
22265  port defines the following preprocessor macros while translating a source.
22266 \end_layout
22267
22268 \begin_layout Standard
22269 \align center
22270 \begin_inset Tabular
22271 <lyxtabular version="3" rows="6" columns="2">
22272 <features>
22273 <column alignment="center" valignment="top" leftline="true" width="0">
22274 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22275 <row topline="true" bottomline="true">
22276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22277 \begin_inset Text
22278
22279 \begin_layout Standard
22280 Macro
22281 \end_layout
22282
22283 \end_inset
22284 </cell>
22285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22286 \begin_inset Text
22287
22288 \begin_layout Standard
22289 Description
22290 \end_layout
22291
22292 \end_inset
22293 </cell>
22294 </row>
22295 <row topline="true">
22296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22297 \begin_inset Text
22298
22299 \begin_layout Standard
22300 SDCC_pic16
22301 \end_layout
22302
22303 \end_inset
22304 </cell>
22305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22306 \begin_inset Text
22307
22308 \begin_layout Standard
22309 Port identification
22310 \end_layout
22311
22312 \end_inset
22313 </cell>
22314 </row>
22315 <row topline="true">
22316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22317 \begin_inset Text
22318
22319 \begin_layout Standard
22320 _
22321 \begin_inset ERT
22322 status collapsed
22323
22324 \begin_layout Standard
22325
22326
22327 \backslash
22328 /
22329 \end_layout
22330
22331 \end_inset
22332
22333 _pic16
22334 \end_layout
22335
22336 \end_inset
22337 </cell>
22338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22339 \begin_inset Text
22340
22341 \begin_layout Standard
22342 Port identification (same as above)
22343 \end_layout
22344
22345 \end_inset
22346 </cell>
22347 </row>
22348 <row topline="true">
22349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22350 \begin_inset Text
22351
22352 \begin_layout Standard
22353 pic18fxxxx
22354 \end_layout
22355
22356 \end_inset
22357 </cell>
22358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22359 \begin_inset Text
22360
22361 \begin_layout Standard
22362 MCU Identification.
22363  
22364 \emph on
22365 xxxx
22366 \emph default
22367  is the microcontrol identification number, i.e.
22368  452, 6620, etc
22369 \end_layout
22370
22371 \end_inset
22372 </cell>
22373 </row>
22374 <row topline="true">
22375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22376 \begin_inset Text
22377
22378 \begin_layout Standard
22379 _
22380 \begin_inset ERT
22381 status collapsed
22382
22383 \begin_layout Standard
22384
22385
22386 \backslash
22387 /
22388 \end_layout
22389
22390 \end_inset
22391
22392 _18Fxxxx
22393 \end_layout
22394
22395 \end_inset
22396 </cell>
22397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22398 \begin_inset Text
22399
22400 \begin_layout Standard
22401 MCU Identification (same as above)
22402 \end_layout
22403
22404 \end_inset
22405 </cell>
22406 </row>
22407 <row topline="true" bottomline="true">
22408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22409 \begin_inset Text
22410
22411 \begin_layout Standard
22412 STACK_MODEL_nnn
22413 \end_layout
22414
22415 \end_inset
22416 </cell>
22417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22418 \begin_inset Text
22419
22420 \begin_layout Standard
22421 nnn = SMALL or LARGE respectively according to the stack model used
22422 \end_layout
22423
22424 \end_inset
22425 </cell>
22426 </row>
22427 </lyxtabular>
22428
22429 \end_inset
22430
22431
22432 \end_layout
22433
22434 \begin_layout Standard
22435 In addition the following macros are defined when calling assembler:
22436 \end_layout
22437
22438 \begin_layout Standard
22439 \align center
22440 \begin_inset Tabular
22441 <lyxtabular version="3" rows="4" columns="2">
22442 <features>
22443 <column alignment="center" valignment="top" leftline="true" width="0">
22444 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22445 <row topline="true" bottomline="true">
22446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22447 \begin_inset Text
22448
22449 \begin_layout Standard
22450 Macro
22451 \end_layout
22452
22453 \end_inset
22454 </cell>
22455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22456 \begin_inset Text
22457
22458 \begin_layout Standard
22459 Description
22460 \end_layout
22461
22462 \end_inset
22463 </cell>
22464 </row>
22465 <row topline="true">
22466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22467 \begin_inset Text
22468
22469 \begin_layout Standard
22470 __18Fxxxx
22471 \end_layout
22472
22473 \end_inset
22474 </cell>
22475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22476 \begin_inset Text
22477
22478 \begin_layout Standard
22479 MCU Identification.
22480  
22481 \emph on
22482 xxxx
22483 \emph default
22484  is the microcontrol identification number, i.e.
22485  452, 6620, etc
22486 \end_layout
22487
22488 \end_inset
22489 </cell>
22490 </row>
22491 <row topline="true">
22492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22493 \begin_inset Text
22494
22495 \begin_layout Standard
22496 SDCC_MODEL_nnn
22497 \end_layout
22498
22499 \end_inset
22500 </cell>
22501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22502 \begin_inset Text
22503
22504 \begin_layout Standard
22505 nnn = SMALL or LARGE respectively according to the memory model used for
22506  SDCC
22507 \end_layout
22508
22509 \end_inset
22510 </cell>
22511 </row>
22512 <row topline="true" bottomline="true">
22513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22514 \begin_inset Text
22515
22516 \begin_layout Standard
22517 STACK_MODEL_nnn
22518 \end_layout
22519
22520 \end_inset
22521 </cell>
22522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22523 \begin_inset Text
22524
22525 \begin_layout Standard
22526 nnn = SMALL or LARGE respectively according to the stack model used
22527 \end_layout
22528
22529 \end_inset
22530 </cell>
22531 </row>
22532 </lyxtabular>
22533
22534 \end_inset
22535
22536
22537 \end_layout
22538
22539 \begin_layout Subsection
22540 Directories
22541 \end_layout
22542
22543 \begin_layout Standard
22544 PIC16
22545 \begin_inset LatexCommand \index{PIC16}
22546
22547 \end_inset
22548
22549  port uses the following directories for searching header files and libraries.
22550 \end_layout
22551
22552 \begin_layout Standard
22553 \align center
22554 \begin_inset Tabular
22555 <lyxtabular version="3" rows="3" columns="4">
22556 <features>
22557 <column alignment="center" valignment="top" leftline="true" width="0">
22558 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22559 <column alignment="center" valignment="top" width="0">
22560 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22561 <row topline="true" bottomline="true">
22562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22563 \begin_inset Text
22564
22565 \begin_layout Standard
22566 Directory
22567 \end_layout
22568
22569 \end_inset
22570 </cell>
22571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22572 \begin_inset Text
22573
22574 \begin_layout Standard
22575 Description
22576 \end_layout
22577
22578 \end_inset
22579 </cell>
22580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22581 \begin_inset Text
22582
22583 \begin_layout Standard
22584 Target
22585 \end_layout
22586
22587 \end_inset
22588 </cell>
22589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22590 \begin_inset Text
22591
22592 \begin_layout Standard
22593 Command prefix
22594 \end_layout
22595
22596 \end_inset
22597 </cell>
22598 </row>
22599 <row topline="true">
22600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22601 \begin_inset Text
22602
22603 \begin_layout Standard
22604 PREFIX/sdcc/include/pic16
22605 \end_layout
22606
22607 \end_inset
22608 </cell>
22609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22610 \begin_inset Text
22611
22612 \begin_layout Standard
22613 PIC16 specific headers
22614 \end_layout
22615
22616 \end_inset
22617 </cell>
22618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22619 \begin_inset Text
22620
22621 \begin_layout Standard
22622 Compiler
22623 \end_layout
22624
22625 \end_inset
22626 </cell>
22627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22628 \begin_inset Text
22629
22630 \begin_layout Standard
22631 -I
22632 \end_layout
22633
22634 \end_inset
22635 </cell>
22636 </row>
22637 <row topline="true" bottomline="true">
22638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22639 \begin_inset Text
22640
22641 \begin_layout Standard
22642 PREFIX/sdcc/lib/pic16
22643 \end_layout
22644
22645 \end_inset
22646 </cell>
22647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22648 \begin_inset Text
22649
22650 \begin_layout Standard
22651 PIC16 specific libraries
22652 \end_layout
22653
22654 \end_inset
22655 </cell>
22656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22657 \begin_inset Text
22658
22659 \begin_layout Standard
22660 Linker
22661 \end_layout
22662
22663 \end_inset
22664 </cell>
22665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22666 \begin_inset Text
22667
22668 \begin_layout Standard
22669 -L
22670 \end_layout
22671
22672 \end_inset
22673 </cell>
22674 </row>
22675 </lyxtabular>
22676
22677 \end_inset
22678
22679
22680 \end_layout
22681
22682 \begin_layout Subsection
22683 Pragmas
22684 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
22685
22686 \end_inset
22687
22688
22689 \end_layout
22690
22691 \begin_layout Standard
22692 PIC16
22693 \begin_inset LatexCommand \index{PIC16}
22694
22695 \end_inset
22696
22697  port currently supports the following pragmas:
22698 \end_layout
22699
22700 \begin_layout List
22701 \labelwidthstring 00.00.0000
22702 stack
22703 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
22704
22705 \end_inset
22706
22707  pragma stack
22708 \begin_inset LatexCommand \index{PIC16!stack}
22709
22710 \end_inset
22711
22712  forces the code generator to initialize the stack & frame pointers at a
22713  specific address.
22714  This is an adhoc solution for cases where no STACK directive is available
22715  in the linker script or gplink is not instructed to create a stack section.
22716 \newline
22717 The
22718  stack pragma should be used only once in a project.
22719  Multiple pragmas may result in indeterminate behaviour of the program.
22720 \begin_inset Foot
22721 status open
22722
22723 \begin_layout Standard
22724 The old format (ie.
22725  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
22726  cross page boundaries (or even exceed the available data RAM) and crash
22727  the program.
22728  Make sure that stack does not cross page boundaries when using the SMALL
22729  stack model.
22730 \end_layout
22731
22732 \end_inset
22733
22734
22735 \newline
22736 The format is as follows:
22737 \end_layout
22738
22739 \begin_layout LyX-Code
22740 #pragma stack bottom_address [stack_size]
22741 \end_layout
22742
22743 \begin_layout Standard
22744
22745 \emph on
22746 bottom_address
22747 \emph default
22748  is the lower bound of the stack section.
22749  The stack pointer initially will point at address (bottom_address+stack_size-1).
22750 \end_layout
22751
22752 \begin_layout LyX-Code
22753 Example:
22754 \end_layout
22755
22756 \begin_layout LyX-Code
22757
22758 \end_layout
22759
22760 \begin_layout LyX-Code
22761 /* initializes stack of 100 bytes at RAM address 0x200 */
22762 \end_layout
22763
22764 \begin_layout LyX-Code
22765 #pragma stack 0x200 100
22766 \end_layout
22767
22768 \begin_layout Standard
22769 If the stack_size field is omitted then a stack is created with the default
22770  size of 64.
22771  This size might be enough for most programs, but its not enough for operations
22772  with deep function nesting or excessive stack usage.
22773 \end_layout
22774
22775 \begin_layout List
22776 \labelwidthstring 00.00.0000
22777 code
22778 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
22779
22780 \end_inset
22781
22782  place a function symbol at static FLASH address
22783 \end_layout
22784
22785 \begin_layout LyX-Code
22786 Example:
22787 \end_layout
22788
22789 \begin_layout LyX-Code
22790
22791 \end_layout
22792
22793 \begin_layout LyX-Code
22794 /* place function test_func at 0x4000 */
22795 \end_layout
22796
22797 \begin_layout LyX-Code
22798 #pragma code test_func 0x4000
22799 \end_layout
22800
22801 \begin_layout LyX-Code
22802
22803 \end_layout
22804
22805 \begin_layout List
22806 \labelwidthstring 00.00.0000
22807 library instructs the linker to use a library module.
22808 \newline
22809 Usage:
22810 \end_layout
22811
22812 \begin_layout LyX-Code
22813 #pragma library module_name
22814 \end_layout
22815
22816 \begin_layout Standard
22817
22818 \emph on
22819 module_name
22820 \emph default
22821  can be any library or object file (including its path).
22822  Note that there are four reserved keywords which have special meaning.
22823  These are:
22824 \end_layout
22825
22826 \begin_layout Standard
22827 \align center
22828 \begin_inset Tabular
22829 <lyxtabular version="3" rows="6" columns="3">
22830 <features>
22831 <column alignment="center" valignment="top" leftline="true" width="0">
22832 <column alignment="block" valignment="top" leftline="true" width="20page%">
22833 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
22834 <row topline="true" bottomline="true">
22835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22836 \begin_inset Text
22837
22838 \begin_layout Standard
22839 Keyword
22840 \end_layout
22841
22842 \end_inset
22843 </cell>
22844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22845 \begin_inset Text
22846
22847 \begin_layout Standard
22848 Description
22849 \end_layout
22850
22851 \end_inset
22852 </cell>
22853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22854 \begin_inset Text
22855
22856 \begin_layout Standard
22857 Module to link
22858 \end_layout
22859
22860 \end_inset
22861 </cell>
22862 </row>
22863 <row topline="true">
22864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22865 \begin_inset Text
22866
22867 \begin_layout Standard
22868
22869 \series bold
22870 ignore
22871 \end_layout
22872
22873 \end_inset
22874 </cell>
22875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22876 \begin_inset Text
22877
22878 \begin_layout Standard
22879 ignore all library pragmas
22880 \end_layout
22881
22882 \end_inset
22883 </cell>
22884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22885 \begin_inset Text
22886
22887 \begin_layout Standard
22888
22889 \emph on
22890 (none)
22891 \end_layout
22892
22893 \end_inset
22894 </cell>
22895 </row>
22896 <row topline="true">
22897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22898 \begin_inset Text
22899
22900 \begin_layout Standard
22901
22902 \series bold
22903 c
22904 \end_layout
22905
22906 \end_inset
22907 </cell>
22908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22909 \begin_inset Text
22910
22911 \begin_layout Standard
22912 link the C library
22913 \end_layout
22914
22915 \end_inset
22916 </cell>
22917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22918 \begin_inset Text
22919
22920 \begin_layout Standard
22921
22922 \emph on
22923 libc18f
22924 \emph default
22925 .lib
22926 \end_layout
22927
22928 \end_inset
22929 </cell>
22930 </row>
22931 <row topline="true">
22932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22933 \begin_inset Text
22934
22935 \begin_layout Standard
22936
22937 \series bold
22938 math
22939 \end_layout
22940
22941 \end_inset
22942 </cell>
22943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22944 \begin_inset Text
22945
22946 \begin_layout Standard
22947 link the Math libarary
22948 \end_layout
22949
22950 \end_inset
22951 </cell>
22952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22953 \begin_inset Text
22954
22955 \begin_layout Standard
22956
22957 \emph on
22958 libm18f
22959 \emph default
22960 .lib
22961 \end_layout
22962
22963 \end_inset
22964 </cell>
22965 </row>
22966 <row topline="true">
22967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22968 \begin_inset Text
22969
22970 \begin_layout Standard
22971
22972 \series bold
22973 io
22974 \end_layout
22975
22976 \end_inset
22977 </cell>
22978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22979 \begin_inset Text
22980
22981 \begin_layout Standard
22982 link the I/O library
22983 \end_layout
22984
22985 \end_inset
22986 </cell>
22987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22988 \begin_inset Text
22989
22990 \begin_layout Standard
22991
22992 \emph on
22993 libio18f*
22994 \emph default
22995 .lib
22996 \end_layout
22997
22998 \end_inset
22999 </cell>
23000 </row>
23001 <row topline="true" bottomline="true">
23002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23003 \begin_inset Text
23004
23005 \begin_layout Standard
23006
23007 \series bold
23008 debug
23009 \end_layout
23010
23011 \end_inset
23012 </cell>
23013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23014 \begin_inset Text
23015
23016 \begin_layout Standard
23017 link the debug library
23018 \end_layout
23019
23020 \end_inset
23021 </cell>
23022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23023 \begin_inset Text
23024
23025 \begin_layout Standard
23026
23027 \emph on
23028 libdebug
23029 \emph default
23030 .lib
23031 \end_layout
23032
23033 \end_inset
23034 </cell>
23035 </row>
23036 </lyxtabular>
23037
23038 \end_inset
23039
23040
23041 \newline
23042 * is the device number, i.e.
23043  452 for PIC18F452 MCU.
23044 \end_layout
23045
23046 \begin_layout Standard
23047 This feature allows for linking with specific libraries withoug having to
23048  explicit name them in the command line.
23049  Note that the 
23050 \noun on
23051 ignore
23052 \noun default
23053  keyword will reject all modules specified by the library pragma.
23054 \end_layout
23055
23056 \begin_layout List
23057 \labelwidthstring 00.00.0000
23058 udata pragma udata instructs the compiler to emit code so that linker will
23059  place a variable at a specific memory bank
23060 \end_layout
23061
23062 \begin_layout LyX-Code
23063 Example:
23064 \end_layout
23065
23066 \begin_layout LyX-Code
23067
23068 \end_layout
23069
23070 \begin_layout LyX-Code
23071 /* places variable foo at bank2 */
23072 \end_layout
23073
23074 \begin_layout LyX-Code
23075 #pragma udata bank2 foo
23076 \end_layout
23077
23078 \begin_layout LyX-Code
23079 char foo;
23080 \end_layout
23081
23082 \begin_layout Standard
23083 In order for this pragma to work extra SECTION directives should be added
23084  in the .lkr script.
23085  In the following example a sample .lkr file is shown:
23086 \end_layout
23087
23088 \begin_layout LyX-Code
23089
23090 \end_layout
23091
23092 \begin_layout LyX-Code
23093 // Sample linker script for the PIC18F452 processor
23094 \end_layout
23095
23096 \begin_layout LyX-Code
23097 LIBPATH .
23098 \end_layout
23099
23100 \begin_layout LyX-Code
23101 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
23102 \end_layout
23103
23104 \begin_layout LyX-Code
23105 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
23106 \end_layout
23107
23108 \begin_layout LyX-Code
23109 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
23110 \end_layout
23111
23112 \begin_layout LyX-Code
23113 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
23114 \end_layout
23115
23116 \begin_layout LyX-Code
23117 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
23118 \end_layout
23119
23120 \begin_layout LyX-Code
23121 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
23122 \end_layout
23123
23124 \begin_layout LyX-Code
23125 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
23126 \end_layout
23127
23128 \begin_layout LyX-Code
23129
23130 \end_layout
23131
23132 \begin_layout LyX-Code
23133 DATABANK   NAME=gpr0       START=0x80           END=0xFF
23134 \end_layout
23135
23136 \begin_layout LyX-Code
23137 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
23138 \end_layout
23139
23140 \begin_layout LyX-Code
23141 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
23142 \end_layout
23143
23144 \begin_layout LyX-Code
23145 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
23146 \end_layout
23147
23148 \begin_layout LyX-Code
23149 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
23150 \end_layout
23151
23152 \begin_layout LyX-Code
23153 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
23154 \end_layout
23155
23156 \begin_layout LyX-Code
23157 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
23158 \end_layout
23159
23160 \begin_layout LyX-Code
23161
23162 \end_layout
23163
23164 \begin_layout LyX-Code
23165 SECTION    NAME=CONFIG     ROM=config
23166 \end_layout
23167
23168 \begin_layout LyX-Code
23169
23170 \end_layout
23171
23172 \begin_layout LyX-Code
23173 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
23174 \end_layout
23175
23176 \begin_layout LyX-Code
23177 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
23178 \end_layout
23179
23180 \begin_layout LyX-Code
23181 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
23182 \end_layout
23183
23184 \begin_layout LyX-Code
23185 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
23186 \end_layout
23187
23188 \begin_layout LyX-Code
23189 SECTION    NAME=bank4      RAM=gpr4
23190 \end_layout
23191
23192 \begin_layout LyX-Code
23193 SECTION    NAME=bank5      RAM=gpr5
23194 \end_layout
23195
23196 \begin_layout Standard
23197 The linker will recognise the section name set in the pragma statement and
23198  will position the variable at the memory bank set with the RAM field at
23199  the SECTION line in the linker script file.
23200 \end_layout
23201
23202 \begin_layout Subsection
23203 Header Files
23204 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
23205
23206 \end_inset
23207
23208
23209 \end_layout
23210
23211 \begin_layout Standard
23212 There is one main header file
23213 \begin_inset LatexCommand \index{PIC16!Header files}
23214
23215 \end_inset
23216
23217  that can be included to the source files using the pic16
23218 \begin_inset LatexCommand \index{PIC16}
23219
23220 \end_inset
23221
23222  port.
23223  That file is the 
23224 \series bold
23225 pic18fregs.h
23226 \series default
23227 .
23228  This header file contains the definitions for the processor special registers,
23229  so it is necessary if the source accesses them.
23230  It can be included by adding the following line in the beginning of the
23231  file:
23232 \end_layout
23233
23234 \begin_layout LyX-Code
23235 #include <pic18fregs.h>
23236 \end_layout
23237
23238 \begin_layout Standard
23239 The specific microcontroller is selected within the pic18fregs.h automatically,
23240  so the same source can be used with a variety of devices.
23241 \end_layout
23242
23243 \begin_layout Subsection
23244 Libraries
23245 \end_layout
23246
23247 \begin_layout Standard
23248 The libraries
23249 \begin_inset LatexCommand \index{PIC16!Libraries}
23250
23251 \end_inset
23252
23253  that PIC16
23254 \begin_inset LatexCommand \index{PIC16}
23255
23256 \end_inset
23257
23258  port depends on are the microcontroller device libraries which contain
23259  the symbol definitions for the microcontroller special function registers.
23260  These libraries have the format pic18fxxxx.lib, where 
23261 \emph on
23262 xxxx
23263 \emph default
23264  is the microcontroller identification number.
23265  The specific library is selected automatically by the compiler at link
23266  stage according to the selected device.
23267 \end_layout
23268
23269 \begin_layout Standard
23270 Libraries are created with gplib which is part of the gputils package 
23271 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23272
23273 \end_inset
23274
23275 .
23276 \end_layout
23277
23278 \begin_layout Subsubsection*
23279 Building the libraries
23280 \end_layout
23281
23282 \begin_layout Standard
23283 Before using SDCC/pic16 there are some libraries that need to be compiled.
23284  This process is not done automatically by SDCC since not all users use
23285  SDCC for pic16 projects.
23286  So each user should compile the libraries separately.
23287 \end_layout
23288
23289 \begin_layout Standard
23290 The steps to compile the pic16 libraries under Linux are:
23291 \end_layout
23292
23293 \begin_layout LyX-Code
23294 cd device/lib/pic16
23295 \end_layout
23296
23297 \begin_layout LyX-Code
23298 ./configure
23299 \end_layout
23300
23301 \begin_layout LyX-Code
23302 make
23303 \end_layout
23304
23305 \begin_layout LyX-Code
23306 cd ..
23307 \end_layout
23308
23309 \begin_layout LyX-Code
23310 make model-pic16
23311 \end_layout
23312
23313 \begin_layout LyX-Code
23314 su -c 'make install'     # install the libraries, you need the root password
23315 \end_layout
23316
23317 \begin_layout Standard
23318 If you need to install the headers too, do:
23319 \end_layout
23320
23321 \begin_layout LyX-Code
23322 cd device/include
23323 \end_layout
23324
23325 \begin_layout LyX-Code
23326 su -c 'make install'     # install the headers, you need the root password
23327 \end_layout
23328
23329 \begin_layout Standard
23330 There exist a special target to build the I/O libraries.
23331  This target is not automatically build because it will build the I/O library
23332  for 
23333 \emph on
23334 every
23335 \emph default
23336  supported device.
23337  This way building will take quite a lot of time.
23338  Users are advised to edit the 
23339 \series bold
23340 device/lib/pic16/pics.build
23341 \series default
23342  file and then execute:
23343 \end_layout
23344
23345 \begin_layout LyX-Code
23346 make lib-io
23347 \end_layout
23348
23349 \begin_layout Subsection
23350 Memory Models
23351 \end_layout
23352
23353 \begin_layout Standard
23354 The following memory models are supported by the PIC16 port:
23355 \end_layout
23356
23357 \begin_layout Itemize
23358 small model
23359 \end_layout
23360
23361 \begin_layout Itemize
23362 large model
23363 \end_layout
23364
23365 \begin_layout Standard
23366 Memory model affects the default size of pointers within the source.
23367  The sizes are shown in the next table:
23368 \end_layout
23369
23370 \begin_layout Standard
23371 \align center
23372 \begin_inset Tabular
23373 <lyxtabular version="3" rows="3" columns="3">
23374 <features>
23375 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23376 <column alignment="center" valignment="top" leftline="true" width="0">
23377 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23378 <row topline="true" bottomline="true">
23379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23380 \begin_inset Text
23381
23382 \begin_layout Standard
23383 Pointer sizes according to memory model
23384 \end_layout
23385
23386 \end_inset
23387 </cell>
23388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23389 \begin_inset Text
23390
23391 \begin_layout Standard
23392 small model
23393 \end_layout
23394
23395 \end_inset
23396 </cell>
23397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23398 \begin_inset Text
23399
23400 \begin_layout Standard
23401 large model
23402 \end_layout
23403
23404 \end_inset
23405 </cell>
23406 </row>
23407 <row topline="true" bottomline="true">
23408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23409 \begin_inset Text
23410
23411 \begin_layout Standard
23412 code pointers
23413 \end_layout
23414
23415 \end_inset
23416 </cell>
23417 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23418 \begin_inset Text
23419
23420 \begin_layout Standard
23421 16-bits
23422 \end_layout
23423
23424 \end_inset
23425 </cell>
23426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23427 \begin_inset Text
23428
23429 \begin_layout Standard
23430 24-bits
23431 \end_layout
23432
23433 \end_inset
23434 </cell>
23435 </row>
23436 <row topline="true" bottomline="true">
23437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23438 \begin_inset Text
23439
23440 \begin_layout Standard
23441 data pointers
23442 \end_layout
23443
23444 \end_inset
23445 </cell>
23446 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
23447 \begin_inset Text
23448
23449 \begin_layout Standard
23450 16-bits
23451 \end_layout
23452
23453 \end_inset
23454 </cell>
23455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23456 \begin_inset Text
23457
23458 \begin_layout Standard
23459 16-bits
23460 \end_layout
23461
23462 \end_inset
23463 </cell>
23464 </row>
23465 </lyxtabular>
23466
23467 \end_inset
23468
23469
23470 \end_layout
23471
23472 \begin_layout Standard
23473 It is advisable that all sources within a project are compiled with the
23474  same memory model.
23475  If one wants to override the default memory model, this can be done by
23476  declaring a pointer as 
23477 \series bold
23478 far
23479 \series default
23480  or 
23481 \series bold
23482 near
23483 \series default
23484 .
23485  Far selects large memory model's pointers, while near selects small memory
23486  model's pointers.
23487 \end_layout
23488
23489 \begin_layout Standard
23490 The standard device libraries (see 
23491 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
23492
23493 \end_inset
23494
23495 ) contain no reference to pointers, so they can be used with both memory
23496  models.
23497 \end_layout
23498
23499 \begin_layout Subsection
23500 Stack
23501 \end_layout
23502
23503 \begin_layout Standard
23504 The stack
23505 \begin_inset LatexCommand \index{PIC16!stack}
23506
23507 \end_inset
23508
23509  implementation for the PIC16 port uses two indirect registers, FSR1 and
23510  FSR2.
23511 \end_layout
23512
23513 \begin_layout List
23514 \labelwidthstring 00.00.0000
23515 FSR1 is assigned as stack pointer
23516 \end_layout
23517
23518 \begin_layout List
23519 \labelwidthstring 00.00.0000
23520 FSR2 is assigned as frame pointer
23521 \end_layout
23522
23523 \begin_layout Standard
23524 The following stack models are supported by the PIC16 port
23525 \end_layout
23526
23527 \begin_layout Itemize
23528
23529 \noun on
23530 small
23531 \noun default
23532  model
23533 \end_layout
23534
23535 \begin_layout Itemize
23536
23537 \noun on
23538 large
23539 \noun default
23540  model
23541 \end_layout
23542
23543 \begin_layout Standard
23544
23545 \noun on
23546 Small
23547 \noun default
23548  model means that only the FSRxL byte is used to access stack and frame,
23549  while 
23550 \emph on
23551 \noun on
23552 large
23553 \emph default
23554 \noun default
23555  uses both FSRxL and FSRxH registers.
23556  The following table shows the stack/frame pointers sizes according to stack
23557  model and the maximum space they can address:
23558 \end_layout
23559
23560 \begin_layout Standard
23561 \align center
23562 \begin_inset Tabular
23563 <lyxtabular version="3" rows="3" columns="3">
23564 <features>
23565 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23566 <column alignment="center" valignment="top" leftline="true" width="0">
23567 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23568 <row topline="true" bottomline="true">
23569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23570 \begin_inset Text
23571
23572 \begin_layout Standard
23573 Stack & Frame pointer sizes according to stack model
23574 \end_layout
23575
23576 \end_inset
23577 </cell>
23578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23579 \begin_inset Text
23580
23581 \begin_layout Standard
23582 small
23583 \end_layout
23584
23585 \end_inset
23586 </cell>
23587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23588 \begin_inset Text
23589
23590 \begin_layout Standard
23591 large
23592 \end_layout
23593
23594 \end_inset
23595 </cell>
23596 </row>
23597 <row topline="true">
23598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23599 \begin_inset Text
23600
23601 \begin_layout Standard
23602 Stack pointer FSR1
23603 \end_layout
23604
23605 \end_inset
23606 </cell>
23607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23608 \begin_inset Text
23609
23610 \begin_layout Standard
23611 8-bits
23612 \end_layout
23613
23614 \end_inset
23615 </cell>
23616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23617 \begin_inset Text
23618
23619 \begin_layout Standard
23620 16-bits
23621 \end_layout
23622
23623 \end_inset
23624 </cell>
23625 </row>
23626 <row topline="true" bottomline="true">
23627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23628 \begin_inset Text
23629
23630 \begin_layout Standard
23631 Frame pointer FSR2
23632 \end_layout
23633
23634 \end_inset
23635 </cell>
23636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23637 \begin_inset Text
23638
23639 \begin_layout Standard
23640 8-bits
23641 \end_layout
23642
23643 \end_inset
23644 </cell>
23645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23646 \begin_inset Text
23647
23648 \begin_layout Standard
23649 16-bits
23650 \end_layout
23651
23652 \end_inset
23653 </cell>
23654 </row>
23655 </lyxtabular>
23656
23657 \end_inset
23658
23659
23660 \end_layout
23661
23662 \begin_layout Standard
23663
23664 \noun on
23665 Large 
23666 \noun default
23667 stack model is currently not working properly throughout the code generator.
23668  So its use is not advised.
23669  Also there are some other points that need special care:
23670 \newline
23671
23672 \end_layout
23673
23674 \begin_layout Enumerate
23675 Do not create stack sections with size more than one physical bank (that
23676  is 256 bytes)
23677 \end_layout
23678
23679 \begin_layout Enumerate
23680 Stack sections should no cross physical bank limits (i.e.
23681  #pragma stack 0x50 0x100)
23682 \end_layout
23683
23684 \begin_layout Standard
23685 These limitations are caused by the fact that only FSRxL is modified when
23686  using SMALL stack model, so no more than 256 bytes of stack can be used.
23687  This problem will disappear after LARGE model is fully implemented.
23688 \end_layout
23689
23690 \begin_layout Subsection
23691 Functions
23692 \end_layout
23693
23694 \begin_layout Standard
23695 In addition to the standard SDCC function keywords, PIC16
23696 \begin_inset LatexCommand \index{PIC16}
23697
23698 \end_inset
23699
23700  port makes available two more:
23701 \end_layout
23702
23703 \begin_layout List
23704 \labelwidthstring 00.00.0000
23705 wparam
23706 \begin_inset LatexCommand \index{PIC16!wparam}
23707
23708 \end_inset
23709
23710  Use the WREG to pass one byte of the first function argument.
23711  This improves speed but you may not use this for functions with arguments
23712  that are called via function pointers, otherwise the first byte of the
23713  first parameter will get lost.
23714  Usage:
23715 \end_layout
23716
23717 \begin_layout LyX-Code
23718 void func_wparam(int a) wparam
23719 \end_layout
23720
23721 \begin_layout LyX-Code
23722 {
23723 \end_layout
23724
23725 \begin_layout LyX-Code
23726     /* WREG hold the lower part of a */
23727 \end_layout
23728
23729 \begin_layout LyX-Code
23730     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
23731  */
23732 \end_layout
23733
23734 \begin_layout LyX-Code
23735 ...
23736 \end_layout
23737
23738 \begin_layout LyX-Code
23739 }
23740 \end_layout
23741
23742 \begin_layout List
23743 \labelwidthstring 00.00.0000
23744 shadowregs
23745 \begin_inset LatexCommand \index{PIC16!shadowregs}
23746
23747 \end_inset
23748
23749  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
23750  hardware shadow registers which hold the values of WREG, STATUS and BSR
23751  registers.
23752  This can be done by adding the keyword 
23753 \emph on
23754 shadowregs
23755 \emph default
23756  before the 
23757 \emph on
23758 interrupt
23759 \emph default
23760  keyword in the function's header.
23761 \end_layout
23762
23763 \begin_layout LyX-Code
23764 void isr_shadow(void) shadowregs interrupt 1
23765 \end_layout
23766
23767 \begin_layout LyX-Code
23768 {
23769 \end_layout
23770
23771 \begin_layout LyX-Code
23772 ...
23773 \end_layout
23774
23775 \begin_layout LyX-Code
23776 }
23777 \end_layout
23778
23779 \begin_layout Standard
23780
23781 \emph on
23782 shadowregs
23783 \emph default
23784  instructs the code generator not to store/restore WREG, STATUS, BSR when
23785  entering/exiting the ISR.
23786 \end_layout
23787
23788 \begin_layout Subsection
23789 Function return values
23790 \end_layout
23791
23792 \begin_layout Standard
23793 Return values from functions are placed to the appropriate registers following
23794  a modified Microchip policy optimized for SDCC.
23795  The following table shows these registers:
23796 \end_layout
23797
23798 \begin_layout Standard
23799 \align center
23800 \begin_inset Tabular
23801 <lyxtabular version="3" rows="6" columns="2">
23802 <features>
23803 <column alignment="center" valignment="top" leftline="true" width="0">
23804 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23805 <row topline="true" bottomline="true">
23806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23807 \begin_inset Text
23808
23809 \begin_layout Standard
23810 size
23811 \end_layout
23812
23813 \end_inset
23814 </cell>
23815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23816 \begin_inset Text
23817
23818 \begin_layout Standard
23819 destination register
23820 \end_layout
23821
23822 \end_inset
23823 </cell>
23824 </row>
23825 <row topline="true">
23826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23827 \begin_inset Text
23828
23829 \begin_layout Standard
23830 8 bits
23831 \end_layout
23832
23833 \end_inset
23834 </cell>
23835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23836 \begin_inset Text
23837
23838 \begin_layout Standard
23839 WREG
23840 \end_layout
23841
23842 \end_inset
23843 </cell>
23844 </row>
23845 <row topline="true">
23846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23847 \begin_inset Text
23848
23849 \begin_layout Standard
23850 16 bits
23851 \end_layout
23852
23853 \end_inset
23854 </cell>
23855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23856 \begin_inset Text
23857
23858 \begin_layout Standard
23859 PRODL:WREG
23860 \end_layout
23861
23862 \end_inset
23863 </cell>
23864 </row>
23865 <row topline="true">
23866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23867 \begin_inset Text
23868
23869 \begin_layout Standard
23870 24 bits
23871 \end_layout
23872
23873 \end_inset
23874 </cell>
23875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23876 \begin_inset Text
23877
23878 \begin_layout Standard
23879 PRODH:PRODL:WREG
23880 \end_layout
23881
23882 \end_inset
23883 </cell>
23884 </row>
23885 <row topline="true">
23886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23887 \begin_inset Text
23888
23889 \begin_layout Standard
23890 32 bits
23891 \end_layout
23892
23893 \end_inset
23894 </cell>
23895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23896 \begin_inset Text
23897
23898 \begin_layout Standard
23899 FSR0L:PRODH:PRODL:WREG
23900 \end_layout
23901
23902 \end_inset
23903 </cell>
23904 </row>
23905 <row topline="true" bottomline="true">
23906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23907 \begin_inset Text
23908
23909 \begin_layout Standard
23910 >32 bits
23911 \end_layout
23912
23913 \end_inset
23914 </cell>
23915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23916 \begin_inset Text
23917
23918 \begin_layout Standard
23919 on stack, FSR0 points to the beginning
23920 \end_layout
23921
23922 \end_inset
23923 </cell>
23924 </row>
23925 </lyxtabular>
23926
23927 \end_inset
23928
23929
23930 \end_layout
23931
23932 \begin_layout Subsection
23933 Interrupts
23934 \end_layout
23935
23936 \begin_layout Standard
23937 An interrupt
23938 \begin_inset LatexCommand \index{PIC16!interrupt}
23939
23940 \end_inset
23941
23942  service routine (ISR) is declared using the 
23943 \emph on
23944 interrupt
23945 \emph default
23946  keyword.
23947 \end_layout
23948
23949 \begin_layout LyX-Code
23950 void isr(void) interrupt 
23951 \emph on
23952 n
23953 \end_layout
23954
23955 \begin_layout LyX-Code
23956 {
23957 \end_layout
23958
23959 \begin_layout LyX-Code
23960 ...
23961 \end_layout
23962
23963 \begin_layout LyX-Code
23964 }
23965 \end_layout
23966
23967 \begin_layout Standard
23968
23969 \emph on
23970 n
23971 \emph default
23972  is the interrupt number, which for PIC18F devices can be:
23973 \end_layout
23974
23975 \begin_layout Standard
23976 \align center
23977 \begin_inset Tabular
23978 <lyxtabular version="3" rows="4" columns="3">
23979 <features>
23980 <column alignment="center" valignment="top" leftline="true" width="0">
23981 <column alignment="center" valignment="top" leftline="true" width="0">
23982 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23983 <row topline="true" bottomline="true">
23984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23985 \begin_inset Text
23986
23987 \begin_layout Standard
23988
23989 \emph on
23990 n
23991 \end_layout
23992
23993 \end_inset
23994 </cell>
23995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23996 \begin_inset Text
23997
23998 \begin_layout Standard
23999 Interrupt Vector
24000 \end_layout
24001
24002 \end_inset
24003 </cell>
24004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24005 \begin_inset Text
24006
24007 \begin_layout Standard
24008 Interrupt Vector Address
24009 \end_layout
24010
24011 \end_inset
24012 </cell>
24013 </row>
24014 <row topline="true">
24015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24016 \begin_inset Text
24017
24018 \begin_layout Standard
24019 0
24020 \end_layout
24021
24022 \end_inset
24023 </cell>
24024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24025 \begin_inset Text
24026
24027 \begin_layout Standard
24028 RESET vector
24029 \end_layout
24030
24031 \end_inset
24032 </cell>
24033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24034 \begin_inset Text
24035
24036 \begin_layout Standard
24037 0x000000
24038 \end_layout
24039
24040 \end_inset
24041 </cell>
24042 </row>
24043 <row topline="true">
24044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24045 \begin_inset Text
24046
24047 \begin_layout Standard
24048
24049 \family roman
24050 \series medium
24051 \shape up
24052 \size normal
24053 \emph off
24054 \bar no
24055 \noun off
24056 \color none
24057 1
24058 \end_layout
24059
24060 \end_inset
24061 </cell>
24062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24063 \begin_inset Text
24064
24065 \begin_layout Standard
24066
24067 \family roman
24068 \series medium
24069 \shape up
24070 \size normal
24071 \emph off
24072 \bar no
24073 \noun off
24074 \color none
24075 HIGH priority interrupts
24076 \end_layout
24077
24078 \end_inset
24079 </cell>
24080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24081 \begin_inset Text
24082
24083 \begin_layout Standard
24084 0x000008
24085 \end_layout
24086
24087 \end_inset
24088 </cell>
24089 </row>
24090 <row topline="true" bottomline="true">
24091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24092 \begin_inset Text
24093
24094 \begin_layout Standard
24095 2
24096 \end_layout
24097
24098 \end_inset
24099 </cell>
24100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24101 \begin_inset Text
24102
24103 \begin_layout Standard
24104 LOW priority interrupts
24105 \end_layout
24106
24107 \end_inset
24108 </cell>
24109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24110 \begin_inset Text
24111
24112 \begin_layout Standard
24113 0x000018
24114 \end_layout
24115
24116 \end_inset
24117 </cell>
24118 </row>
24119 </lyxtabular>
24120
24121 \end_inset
24122
24123
24124 \end_layout
24125
24126 \begin_layout Standard
24127 When generating assembly code for ISR the code generator places a 
24128 \noun on
24129 goto 
24130 \noun default
24131 instruction at the 
24132 \emph on
24133 Interrupt Vector Address
24134 \emph default
24135  which points at the genetated ISR.
24136  This single GOTO instruction is part of an automatically generated 
24137 \emph on
24138 interrupt entry point
24139 \emph default
24140  function.
24141  The actuall ISR code is placed as normally would in the code space.
24142  Upon interrupt request, the GOTO instruction is executed which jumps to
24143  the ISR code.
24144  When declaring interrupt functions as _naked this GOTO instruction is 
24145 \series bold
24146 not
24147 \series default
24148  generated.
24149  The whole interrupt functions is therefore placed at the Interrupt Vector
24150  Address of the specific interrupt.
24151  This is not a problem for the LOW priority interrupts, but it is a problem
24152  for the RESET and the HIGH priority interrupts because code may be written
24153  at the next interrupt´s vector address and cause undeterminate program
24154  behaviour if that interrupt is raised.
24155 \begin_inset Foot
24156 status open
24157
24158 \begin_layout Standard
24159 This is not a problem when
24160 \end_layout
24161
24162 \begin_layout Enumerate
24163 this is a HIGH interrupt ISR and LOW interrupts are 
24164 \emph on
24165 disabled
24166 \emph default
24167  or not used.
24168 \end_layout
24169
24170 \begin_layout Enumerate
24171 when the ISR is small enough not to reach the next interrupt´s vector address.
24172 \end_layout
24173
24174 \end_inset
24175
24176
24177 \end_layout
24178
24179 \begin_layout Standard
24180
24181 \emph on
24182 n
24183 \emph default
24184  is possible to be omitted.
24185  This way a function is generated similar to an ISR, but it is not assigned
24186  to any interrupt.
24187 \end_layout
24188
24189 \begin_layout Standard
24190 When entering an interrupt, currently the PIC16
24191 \begin_inset LatexCommand \index{PIC16}
24192
24193 \end_inset
24194
24195  port automatically saves the following registers:
24196 \end_layout
24197
24198 \begin_layout Itemize
24199 WREG
24200 \end_layout
24201
24202 \begin_layout Itemize
24203 STATUS
24204 \end_layout
24205
24206 \begin_layout Itemize
24207 BSR
24208 \end_layout
24209
24210 \begin_layout Itemize
24211 PROD (PRODL and PRODH)
24212 \end_layout
24213
24214 \begin_layout Itemize
24215 FSR0 (FSR0L and FSR0H)
24216 \end_layout
24217
24218 \begin_layout Standard
24219 These registers are restored upon return from the interrupt routine.
24220 \begin_inset Foot
24221 status open
24222
24223 \begin_layout Standard
24224 NOTE that when the _naked attribute is specified for an interrupt routine,
24225  then NO registers are stored or restored.
24226 \end_layout
24227
24228 \end_inset
24229
24230
24231 \end_layout
24232
24233 \begin_layout Subsection
24234 Generic Pointers
24235 \end_layout
24236
24237 \begin_layout Standard
24238 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
24239  There are 3 types of generic pointers currently implemented data, code
24240  and eeprom pointers.
24241  They are differentiated by the value of the 7th and 6th bits of the upper
24242  byte:
24243 \end_layout
24244
24245 \begin_layout Standard
24246 \align center
24247 \begin_inset Tabular
24248 <lyxtabular version="3" rows="5" columns="5">
24249 <features>
24250 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24251 <column alignment="center" valignment="top" width="0">
24252 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24253 <column alignment="center" valignment="top" width="0">
24254 <column alignment="left" valignment="top" rightline="true" width="0">
24255 <row topline="true" bottomline="true">
24256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24257 \begin_inset Text
24258
24259 \begin_layout Standard
24260 pointer type
24261 \end_layout
24262
24263 \end_inset
24264 </cell>
24265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24266 \begin_inset Text
24267
24268 \begin_layout Standard
24269 7th bit
24270 \end_layout
24271
24272 \end_inset
24273 </cell>
24274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24275 \begin_inset Text
24276
24277 \begin_layout Standard
24278 6th bit
24279 \end_layout
24280
24281 \end_inset
24282 </cell>
24283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24284 \begin_inset Text
24285
24286 \begin_layout Standard
24287 rest of the pointer
24288 \end_layout
24289
24290 \end_inset
24291 </cell>
24292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24293 \begin_inset Text
24294
24295 \begin_layout Standard
24296 description
24297 \end_layout
24298
24299 \end_inset
24300 </cell>
24301 </row>
24302 <row topline="true" bottomline="true">
24303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24304 \begin_inset Text
24305
24306 \begin_layout Standard
24307 data 
24308 \end_layout
24309
24310 \end_inset
24311 </cell>
24312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24313 \begin_inset Text
24314
24315 \begin_layout Standard
24316 1
24317 \end_layout
24318
24319 \end_inset
24320 </cell>
24321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24322 \begin_inset Text
24323
24324 \begin_layout Standard
24325 0
24326 \end_layout
24327
24328 \end_inset
24329 </cell>
24330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24331 \begin_inset Text
24332
24333 \begin_layout Standard
24334
24335 \family typewriter
24336 \shape slanted
24337 \emph on
24338 uuuuuu uuuuxxxx xxxxxxxx
24339 \end_layout
24340
24341 \end_inset
24342 </cell>
24343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24344 \begin_inset Text
24345
24346 \begin_layout Standard
24347 a 12-bit data pointer in data RAM memory
24348 \end_layout
24349
24350 \end_inset
24351 </cell>
24352 </row>
24353 <row bottomline="true">
24354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24355 \begin_inset Text
24356
24357 \begin_layout Standard
24358 code
24359 \end_layout
24360
24361 \end_inset
24362 </cell>
24363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24364 \begin_inset Text
24365
24366 \begin_layout Standard
24367 0
24368 \end_layout
24369
24370 \end_inset
24371 </cell>
24372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24373 \begin_inset Text
24374
24375 \begin_layout Standard
24376 0
24377 \end_layout
24378
24379 \end_inset
24380 </cell>
24381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24382 \begin_inset Text
24383
24384 \begin_layout Standard
24385
24386 \family typewriter
24387 \shape slanted
24388 \emph on
24389 uxxxxx xxxxxxxx xxxxxxxx
24390 \end_layout
24391
24392 \end_inset
24393 </cell>
24394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24395 \begin_inset Text
24396
24397 \begin_layout Standard
24398 a 21-bit code pointer in FLASH memory
24399 \end_layout
24400
24401 \end_inset
24402 </cell>
24403 </row>
24404 <row bottomline="true">
24405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24406 \begin_inset Text
24407
24408 \begin_layout Standard
24409 eeprom
24410 \end_layout
24411
24412 \end_inset
24413 </cell>
24414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24415 \begin_inset Text
24416
24417 \begin_layout Standard
24418 0
24419 \end_layout
24420
24421 \end_inset
24422 </cell>
24423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24424 \begin_inset Text
24425
24426 \begin_layout Standard
24427 1
24428 \end_layout
24429
24430 \end_inset
24431 </cell>
24432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24433 \begin_inset Text
24434
24435 \begin_layout Standard
24436
24437 \family typewriter
24438 \shape slanted
24439 \emph on
24440 uuuuuu uuuuuuxx xxxxxxxx
24441 \end_layout
24442
24443 \end_inset
24444 </cell>
24445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24446 \begin_inset Text
24447
24448 \begin_layout Standard
24449 a 10-bit eeprom pointer in EEPROM memory
24450 \end_layout
24451
24452 \end_inset
24453 </cell>
24454 </row>
24455 <row bottomline="true">
24456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24457 \begin_inset Text
24458
24459 \begin_layout Standard
24460 (unimplemented)
24461 \end_layout
24462
24463 \end_inset
24464 </cell>
24465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24466 \begin_inset Text
24467
24468 \begin_layout Standard
24469 1
24470 \end_layout
24471
24472 \end_inset
24473 </cell>
24474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24475 \begin_inset Text
24476
24477 \begin_layout Standard
24478 1
24479 \end_layout
24480
24481 \end_inset
24482 </cell>
24483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24484 \begin_inset Text
24485
24486 \begin_layout Standard
24487
24488 \family typewriter
24489 \shape slanted
24490 \emph on
24491 xxxxxx xxxxxxxx xxxxxxxx
24492 \end_layout
24493
24494 \end_inset
24495 </cell>
24496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24497 \begin_inset Text
24498
24499 \begin_layout Standard
24500 unimplemented pointer type
24501 \end_layout
24502
24503 \end_inset
24504 </cell>
24505 </row>
24506 </lyxtabular>
24507
24508 \end_inset
24509
24510
24511 \end_layout
24512
24513 \begin_layout Standard
24514 Generic pointer are read and written with a set of library functions which
24515  read/write 1, 2, 3, 4 bytes.
24516 \end_layout
24517
24518 \begin_layout Subsection
24519 PIC16 C Libraries
24520 \end_layout
24521
24522 \begin_layout Subsubsection
24523 Standard I/O Streams
24524 \end_layout
24525
24526 \begin_layout Standard
24527 In the 
24528 \emph on
24529 stdio.h
24530 \emph default
24531  the type FILE is defined as:
24532 \end_layout
24533
24534 \begin_layout LyX-Code
24535 typedef char * FILE;
24536 \end_layout
24537
24538 \begin_layout Standard
24539 This type is the stream type implemented I/O in the PIC18F devices.
24540  Also the standard input and output streams are declared in stdio.h:
24541 \end_layout
24542
24543 \begin_layout LyX-Code
24544 extern FILE * stdin;
24545 \end_layout
24546
24547 \begin_layout LyX-Code
24548 extern FILE * stdout;
24549 \end_layout
24550
24551 \begin_layout Standard
24552 The FILE type is actually a generic pointer which defines one more type
24553  of generic pointers, the 
24554 \emph on
24555 stream 
24556 \emph default
24557 pointer.
24558  This new type has the format:
24559 \end_layout
24560
24561 \begin_layout Standard
24562 \align center
24563 \begin_inset Tabular
24564 <lyxtabular version="3" rows="2" columns="7">
24565 <features>
24566 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24567 <column alignment="center" valignment="top" width="0">
24568 <column alignment="center" valignment="top" leftline="true" width="0">
24569 <column alignment="center" valignment="top" leftline="true" width="0">
24570 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24571 <column alignment="center" valignment="top" width="0">
24572 <column alignment="left" valignment="top" rightline="true" width="0">
24573 <row topline="true" bottomline="true">
24574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24575 \begin_inset Text
24576
24577 \begin_layout Standard
24578 pointer type
24579 \end_layout
24580
24581 \end_inset
24582 </cell>
24583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24584 \begin_inset Text
24585
24586 \begin_layout Standard
24587 <7:6>
24588 \end_layout
24589
24590 \end_inset
24591 </cell>
24592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24593 \begin_inset Text
24594
24595 \begin_layout Standard
24596 <5>
24597 \end_layout
24598
24599 \end_inset
24600 </cell>
24601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24602 \begin_inset Text
24603
24604 \begin_layout Standard
24605 <4>
24606 \end_layout
24607
24608 \end_inset
24609 </cell>
24610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24611 \begin_inset Text
24612
24613 \begin_layout Standard
24614 <3:0>
24615 \end_layout
24616
24617 \end_inset
24618 </cell>
24619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24620 \begin_inset Text
24621
24622 \begin_layout Standard
24623 rest of the pointer
24624 \end_layout
24625
24626 \end_inset
24627 </cell>
24628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24629 \begin_inset Text
24630
24631 \begin_layout Standard
24632 descrption
24633 \end_layout
24634
24635 \end_inset
24636 </cell>
24637 </row>
24638 <row topline="true" bottomline="true">
24639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24640 \begin_inset Text
24641
24642 \begin_layout Standard
24643 stream
24644 \end_layout
24645
24646 \end_inset
24647 </cell>
24648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24649 \begin_inset Text
24650
24651 \begin_layout Standard
24652 00
24653 \end_layout
24654
24655 \end_inset
24656 </cell>
24657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24658 \begin_inset Text
24659
24660 \begin_layout Standard
24661 1
24662 \end_layout
24663
24664 \end_inset
24665 </cell>
24666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24667 \begin_inset Text
24668
24669 \begin_layout Standard
24670 0
24671 \end_layout
24672
24673 \end_inset
24674 </cell>
24675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24676 \begin_inset Text
24677
24678 \begin_layout Standard
24679 nnnn
24680 \end_layout
24681
24682 \end_inset
24683 </cell>
24684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24685 \begin_inset Text
24686
24687 \begin_layout Standard
24688
24689 \family typewriter
24690 \shape slanted
24691 \emph on
24692 uuuuuuuu uuuuuuuu
24693 \end_layout
24694
24695 \end_inset
24696 </cell>
24697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24698 \begin_inset Text
24699
24700 \begin_layout Standard
24701 upper byte high nubble is 0x2n, the rest are zeroes
24702 \end_layout
24703
24704 \end_inset
24705 </cell>
24706 </row>
24707 </lyxtabular>
24708
24709 \end_inset
24710
24711
24712 \end_layout
24713
24714 \begin_layout Standard
24715 Currently implemented there are 3 types of streams defined:
24716 \end_layout
24717
24718 \begin_layout Standard
24719 \align center
24720 \begin_inset Tabular
24721 <lyxtabular version="3" rows="4" columns="4">
24722 <features>
24723 <column alignment="center" valignment="top" leftline="true" width="0">
24724 <column alignment="center" valignment="top" leftline="true" width="0">
24725 <column alignment="center" valignment="top" leftline="true" width="0">
24726 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24727 <row topline="true" bottomline="true">
24728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24729 \begin_inset Text
24730
24731 \begin_layout Standard
24732 stream type
24733 \end_layout
24734
24735 \end_inset
24736 </cell>
24737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24738 \begin_inset Text
24739
24740 \begin_layout Standard
24741 value
24742 \end_layout
24743
24744 \end_inset
24745 </cell>
24746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24747 \begin_inset Text
24748
24749 \begin_layout Standard
24750 module
24751 \end_layout
24752
24753 \end_inset
24754 </cell>
24755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24756 \begin_inset Text
24757
24758 \begin_layout Standard
24759 description
24760 \end_layout
24761
24762 \end_inset
24763 </cell>
24764 </row>
24765 <row topline="true">
24766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24767 \begin_inset Text
24768
24769 \begin_layout Standard
24770 STREAM_USART
24771 \end_layout
24772
24773 \end_inset
24774 </cell>
24775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24776 \begin_inset Text
24777
24778 \begin_layout Standard
24779
24780 \family typewriter
24781 0x200000UL
24782 \end_layout
24783
24784 \end_inset
24785 </cell>
24786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24787 \begin_inset Text
24788
24789 \begin_layout Standard
24790 USART
24791 \end_layout
24792
24793 \end_inset
24794 </cell>
24795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24796 \begin_inset Text
24797
24798 \begin_layout Standard
24799 Writes/Reads characters via the USART peripheral
24800 \end_layout
24801
24802 \end_inset
24803 </cell>
24804 </row>
24805 <row topline="true">
24806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24807 \begin_inset Text
24808
24809 \begin_layout Standard
24810 STREAM_MSSP
24811 \end_layout
24812
24813 \end_inset
24814 </cell>
24815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24816 \begin_inset Text
24817
24818 \begin_layout Standard
24819
24820 \family typewriter
24821 0x210000UL
24822 \end_layout
24823
24824 \end_inset
24825 </cell>
24826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24827 \begin_inset Text
24828
24829 \begin_layout Standard
24830 MSSP
24831 \end_layout
24832
24833 \end_inset
24834 </cell>
24835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24836 \begin_inset Text
24837
24838 \begin_layout Standard
24839 Writes/Reads characters via the MSSP peripheral
24840 \end_layout
24841
24842 \end_inset
24843 </cell>
24844 </row>
24845 <row topline="true" bottomline="true">
24846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24847 \begin_inset Text
24848
24849 \begin_layout Standard
24850 STREAM_USER
24851 \end_layout
24852
24853 \end_inset
24854 </cell>
24855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24856 \begin_inset Text
24857
24858 \begin_layout Standard
24859
24860 \family typewriter
24861 0x2f0000UL
24862 \end_layout
24863
24864 \end_inset
24865 </cell>
24866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24867 \begin_inset Text
24868
24869 \begin_layout Standard
24870 (none)
24871 \end_layout
24872
24873 \end_inset
24874 </cell>
24875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24876 \begin_inset Text
24877
24878 \begin_layout Standard
24879 Writes/Reads characters via used defined functions
24880 \end_layout
24881
24882 \end_inset
24883 </cell>
24884 </row>
24885 </lyxtabular>
24886
24887 \end_inset
24888
24889
24890 \end_layout
24891
24892 \begin_layout Standard
24893 The stream identifiers are declared as macros in the stdio.h header.
24894 \end_layout
24895
24896 \begin_layout Standard
24897 In the libc library there exist the functions that are used to write to
24898  each of the above streams.
24899  These are
24900 \end_layout
24901
24902 \begin_layout List
24903 \labelwidthstring 00.00.0000
24904 _
24905 \begin_inset ERT
24906 status collapsed
24907
24908 \begin_layout Standard
24909
24910
24911 \backslash
24912 /
24913 \end_layout
24914
24915 \end_inset
24916
24917 _stream_usart_putchar writes a character at the USART stream
24918 \end_layout
24919
24920 \begin_layout List
24921 \labelwidthstring 00.00.0000
24922 _
24923 \begin_inset ERT
24924 status collapsed
24925
24926 \begin_layout Standard
24927
24928
24929 \backslash
24930 /
24931 \end_layout
24932
24933 \end_inset
24934
24935 _stream_mssp_putchar writes a character at the MSSP stream
24936 \end_layout
24937
24938 \begin_layout List
24939 \labelwidthstring 00.00.0000
24940 putchar dummy function.
24941  This writes a character to a user specified manner.
24942 \end_layout
24943
24944 \begin_layout Standard
24945 In order to increase performance 
24946 \emph on
24947 putchar 
24948 \emph default
24949 is declared in stdio.h as having its parameter in WREG (it has the wparam
24950  keyword).
24951  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
24952  in a user-friendly way.
24953  
24954 \emph on
24955 arg
24956 \emph default
24957  is the name of the variable that holds the character to print.
24958  An example follows:
24959 \end_layout
24960
24961 \begin_layout LyX-Code
24962 #include <pic18fregs.h>
24963 \newline
24964 #include <stdio.h>
24965 \newline
24966
24967 \newline
24968 PUTCHAR( c )
24969 \end_layout
24970
24971 \begin_layout LyX-Code
24972 {
24973 \end_layout
24974
24975 \begin_layout LyX-Code
24976     PORTA = c;    /* dump character c to PORTA */
24977 \end_layout
24978
24979 \begin_layout LyX-Code
24980
24981 \newline
24982
24983 \newline
24984 void main(void)
24985 \end_layout
24986
24987 \begin_layout LyX-Code
24988 {
24989 \end_layout
24990
24991 \begin_layout LyX-Code
24992     stdout = STREAM_USER;    /* this is not necessary, since stdout points
24993 \end_layout
24994
24995 \begin_layout LyX-Code
24996                               * by default to STREAM_USER */
24997 \end_layout
24998
24999 \begin_layout LyX-Code
25000     printf (¨This is a printf test
25001 \backslash
25002 n¨);
25003 \end_layout
25004
25005 \begin_layout LyX-Code
25006 }
25007 \end_layout
25008
25009 \begin_layout LyX-Code
25010
25011 \end_layout
25012
25013 \begin_layout Subsubsection
25014 Printing functions
25015 \end_layout
25016
25017 \begin_layout Standard
25018 PIC16 contains an implementation of the printf-family of functions.
25019  There exist the following functions:
25020 \end_layout
25021
25022 \begin_layout LyX-Code
25023 extern unsigned int sprintf(char *buf, char *fmt, ...);
25024 \end_layout
25025
25026 \begin_layout LyX-Code
25027 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
25028 \end_layout
25029
25030 \begin_layout LyX-Code
25031
25032 \end_layout
25033
25034 \begin_layout LyX-Code
25035 extern unsigned int printf(char *fmt, ...);
25036 \end_layout
25037
25038 \begin_layout LyX-Code
25039 extern unsigned int vprintf(char *fmt, va_lista ap);
25040 \end_layout
25041
25042 \begin_layout LyX-Code
25043
25044 \end_layout
25045
25046 \begin_layout LyX-Code
25047 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
25048 \end_layout
25049
25050 \begin_layout LyX-Code
25051 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
25052 \end_layout
25053
25054 \begin_layout Standard
25055 For sprintf and vsprintf 
25056 \emph on
25057 buf 
25058 \emph default
25059 should normally be a data pointer where the resulting string will be placed.
25060  No range checking is done so the user should allocate the necessery buffer.
25061  For fprintf and vfprintf 
25062 \emph on
25063 fp
25064 \emph default
25065  should be a stream pointer (i.e.
25066  stdout, STREAM_MSSP, etc...).
25067 \end_layout
25068
25069 \begin_layout Subsubsection
25070 Signals
25071 \end_layout
25072
25073 \begin_layout Standard
25074 The PIC18F family of microcontrollers supports a number of interrupt sources.
25075  A list of these interrupts is shown in the following table:
25076 \end_layout
25077
25078 \begin_layout Standard
25079 \align center
25080 \begin_inset Tabular
25081 <lyxtabular version="3" rows="11" columns="4">
25082 <features>
25083 <column alignment="left" valignment="top" leftline="true" width="0">
25084 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25085 <column alignment="left" valignment="top" leftline="true" width="0">
25086 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25087 <row topline="true" bottomline="true">
25088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25089 \begin_inset Text
25090
25091 \begin_layout Standard
25092 signal name
25093 \end_layout
25094
25095 \end_inset
25096 </cell>
25097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25098 \begin_inset Text
25099
25100 \begin_layout Standard
25101 description
25102 \end_layout
25103
25104 \end_inset
25105 </cell>
25106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25107 \begin_inset Text
25108
25109 \begin_layout Standard
25110 signal name
25111 \end_layout
25112
25113 \end_inset
25114 </cell>
25115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25116 \begin_inset Text
25117
25118 \begin_layout Standard
25119 descritpion
25120 \end_layout
25121
25122 \end_inset
25123 </cell>
25124 </row>
25125 <row topline="true">
25126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25127 \begin_inset Text
25128
25129 \begin_layout Standard
25130 SIG_RB
25131 \end_layout
25132
25133 \end_inset
25134 </cell>
25135 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25136 \begin_inset Text
25137
25138 \begin_layout Standard
25139 PORTB change interrupt
25140 \end_layout
25141
25142 \end_inset
25143 </cell>
25144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25145 \begin_inset Text
25146
25147 \begin_layout Standard
25148 SIG_EE
25149 \end_layout
25150
25151 \end_inset
25152 </cell>
25153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25154 \begin_inset Text
25155
25156 \begin_layout Standard
25157 EEPROM/FLASH write complete interrupt
25158 \end_layout
25159
25160 \end_inset
25161 </cell>
25162 </row>
25163 <row topline="true">
25164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25165 \begin_inset Text
25166
25167 \begin_layout Standard
25168 SIG_INT0
25169 \end_layout
25170
25171 \end_inset
25172 </cell>
25173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25174 \begin_inset Text
25175
25176 \begin_layout Standard
25177 INT0 external interrupt
25178 \end_layout
25179
25180 \end_inset
25181 </cell>
25182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25183 \begin_inset Text
25184
25185 \begin_layout Standard
25186 SIG_BCOL
25187 \end_layout
25188
25189 \end_inset
25190 </cell>
25191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25192 \begin_inset Text
25193
25194 \begin_layout Standard
25195 Bus collision interrupt
25196 \end_layout
25197
25198 \end_inset
25199 </cell>
25200 </row>
25201 <row topline="true">
25202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25203 \begin_inset Text
25204
25205 \begin_layout Standard
25206 SIG_INT1
25207 \end_layout
25208
25209 \end_inset
25210 </cell>
25211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25212 \begin_inset Text
25213
25214 \begin_layout Standard
25215 INT1 external interrupt
25216 \end_layout
25217
25218 \end_inset
25219 </cell>
25220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25221 \begin_inset Text
25222
25223 \begin_layout Standard
25224 SIG_LVD
25225 \end_layout
25226
25227 \end_inset
25228 </cell>
25229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25230 \begin_inset Text
25231
25232 \begin_layout Standard
25233 Low voltage detect interrupt
25234 \end_layout
25235
25236 \end_inset
25237 </cell>
25238 </row>
25239 <row topline="true">
25240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25241 \begin_inset Text
25242
25243 \begin_layout Standard
25244 SIG_INT2
25245 \end_layout
25246
25247 \end_inset
25248 </cell>
25249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25250 \begin_inset Text
25251
25252 \begin_layout Standard
25253 INT2 external interrupt
25254 \end_layout
25255
25256 \end_inset
25257 </cell>
25258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25259 \begin_inset Text
25260
25261 \begin_layout Standard
25262 SIG_PSP
25263 \end_layout
25264
25265 \end_inset
25266 </cell>
25267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25268 \begin_inset Text
25269
25270 \begin_layout Standard
25271 Parallel slave port interrupt
25272 \end_layout
25273
25274 \end_inset
25275 </cell>
25276 </row>
25277 <row topline="true">
25278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25279 \begin_inset Text
25280
25281 \begin_layout Standard
25282 SIG_CCP1
25283 \end_layout
25284
25285 \end_inset
25286 </cell>
25287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25288 \begin_inset Text
25289
25290 \begin_layout Standard
25291 CCP1 module interrupt
25292 \end_layout
25293
25294 \end_inset
25295 </cell>
25296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25297 \begin_inset Text
25298
25299 \begin_layout Standard
25300 SIG_AD
25301 \end_layout
25302
25303 \end_inset
25304 </cell>
25305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25306 \begin_inset Text
25307
25308 \begin_layout Standard
25309 AD convertion complete interrupt
25310 \end_layout
25311
25312 \end_inset
25313 </cell>
25314 </row>
25315 <row topline="true">
25316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25317 \begin_inset Text
25318
25319 \begin_layout Standard
25320 SIG_CCP2
25321 \end_layout
25322
25323 \end_inset
25324 </cell>
25325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25326 \begin_inset Text
25327
25328 \begin_layout Standard
25329 CCP2 module interrupt
25330 \end_layout
25331
25332 \end_inset
25333 </cell>
25334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25335 \begin_inset Text
25336
25337 \begin_layout Standard
25338 SIG_RC
25339 \end_layout
25340
25341 \end_inset
25342 </cell>
25343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25344 \begin_inset Text
25345
25346 \begin_layout Standard
25347 USART receive interrupt
25348 \end_layout
25349
25350 \end_inset
25351 </cell>
25352 </row>
25353 <row topline="true">
25354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25355 \begin_inset Text
25356
25357 \begin_layout Standard
25358 SIG_TMR0
25359 \end_layout
25360
25361 \end_inset
25362 </cell>
25363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25364 \begin_inset Text
25365
25366 \begin_layout Standard
25367 TMR0 overflow interrupt
25368 \end_layout
25369
25370 \end_inset
25371 </cell>
25372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25373 \begin_inset Text
25374
25375 \begin_layout Standard
25376 SIG_TX
25377 \end_layout
25378
25379 \end_inset
25380 </cell>
25381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25382 \begin_inset Text
25383
25384 \begin_layout Standard
25385 USART transmit interrupt
25386 \end_layout
25387
25388 \end_inset
25389 </cell>
25390 </row>
25391 <row topline="true">
25392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25393 \begin_inset Text
25394
25395 \begin_layout Standard
25396 SIG_TMR1
25397 \end_layout
25398
25399 \end_inset
25400 </cell>
25401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25402 \begin_inset Text
25403
25404 \begin_layout Standard
25405 TMR1 overflow interrupt
25406 \end_layout
25407
25408 \end_inset
25409 </cell>
25410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25411 \begin_inset Text
25412
25413 \begin_layout Standard
25414 SIG_MSSP
25415 \end_layout
25416
25417 \end_inset
25418 </cell>
25419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25420 \begin_inset Text
25421
25422 \begin_layout Standard
25423 SSP receive/transmit interrupt
25424 \end_layout
25425
25426 \end_inset
25427 </cell>
25428 </row>
25429 <row topline="true">
25430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25431 \begin_inset Text
25432
25433 \begin_layout Standard
25434 SIG_TMR2
25435 \end_layout
25436
25437 \end_inset
25438 </cell>
25439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25440 \begin_inset Text
25441
25442 \begin_layout Standard
25443 TMR2 matches PR2 interrupt
25444 \end_layout
25445
25446 \end_inset
25447 </cell>
25448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25449 \begin_inset Text
25450
25451 \begin_layout Standard
25452
25453 \end_layout
25454
25455 \end_inset
25456 </cell>
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25458 \begin_inset Text
25459
25460 \begin_layout Standard
25461
25462 \end_layout
25463
25464 \end_inset
25465 </cell>
25466 </row>
25467 <row topline="true" bottomline="true">
25468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25469 \begin_inset Text
25470
25471 \begin_layout Standard
25472 SIG_TMR3
25473 \end_layout
25474
25475 \end_inset
25476 </cell>
25477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25478 \begin_inset Text
25479
25480 \begin_layout Standard
25481 TMR3 overflow interrupt
25482 \end_layout
25483
25484 \end_inset
25485 </cell>
25486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25487 \begin_inset Text
25488
25489 \begin_layout Standard
25490
25491 \end_layout
25492
25493 \end_inset
25494 </cell>
25495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25496 \begin_inset Text
25497
25498 \begin_layout Standard
25499
25500 \end_layout
25501
25502 \end_inset
25503 </cell>
25504 </row>
25505 </lyxtabular>
25506
25507 \end_inset
25508
25509
25510 \end_layout
25511
25512 \begin_layout Standard
25513 The prototypes for these names are defined in the header file 
25514 \emph on
25515 signal.h
25516 \emph default
25517  .
25518 \end_layout
25519
25520 \begin_layout Standard
25521 In order to simplify signal handling, a number of macros is provided:
25522 \end_layout
25523
25524 \begin_layout List
25525 \labelwidthstring 00.00.0000
25526 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
25527  high priority interrupts.
25528  
25529 \emph on
25530 name
25531 \emph default
25532  is the function name to use.
25533 \end_layout
25534
25535 \begin_layout List
25536 \labelwidthstring 00.00.0000
25537 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
25538  low priority interrupt.
25539  
25540 \emph on
25541 name
25542 \emph default
25543  is the function name to use.
25544 \end_layout
25545
25546 \begin_layout List
25547 \labelwidthstring 00.00.0000
25548 DEF_HANDLER(sig,handler) define a handler for signal 
25549 \emph on
25550 sig.
25551 \end_layout
25552
25553 \begin_layout List
25554 \labelwidthstring 00.00.0000
25555 END_DEF end the declaration of the dispatch table.
25556 \end_layout
25557
25558 \begin_layout Standard
25559 Additionally there are two more macros to simplify the declaration of the
25560  signal handler:
25561 \end_layout
25562
25563 \begin_layout List
25564 \labelwidthstring 00.00.0000
25565
25566 \series medium
25567 SIGHANDLER(handler) 
25568 \series default
25569 this declares the function prototype for the 
25570 \emph on
25571 handler
25572 \emph default
25573  function.
25574 \end_layout
25575
25576 \begin_layout List
25577 \labelwidthstring 00.00.0000
25578 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
25579 \end_layout
25580
25581 \begin_layout Standard
25582 An example of using the macros above is shown below:
25583 \end_layout
25584
25585 \begin_layout LyX-Code
25586 #include <pic18fregs.h>
25587 \end_layout
25588
25589 \begin_layout LyX-Code
25590 #include <signal.h>
25591 \newline
25592
25593 \newline
25594 DEF_INTHIGH(high_int)
25595 \end_layout
25596
25597 \begin_layout LyX-Code
25598 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
25599 \end_layout
25600
25601 \begin_layout LyX-Code
25602 DEF_HANDLER(SIG_BCOL, _bcol_handler)
25603 \end_layout
25604
25605 \begin_layout LyX-Code
25606 END_DEF
25607 \newline
25608
25609 \newline
25610 SIGHANDLER(_tmr0_handler)
25611 \end_layout
25612
25613 \begin_layout LyX-Code
25614 {
25615 \end_layout
25616
25617 \begin_layout LyX-Code
25618   /* action to be taken when timer 0 overflows */
25619 \end_layout
25620
25621 \begin_layout LyX-Code
25622 }
25623 \newline
25624
25625 \newline
25626 SIGHANDLERNAKED(_bcol_handler)
25627 \end_layout
25628
25629 \begin_layout LyX-Code
25630 {
25631 \end_layout
25632
25633 \begin_layout LyX-Code
25634   _asm
25635 \end_layout
25636
25637 \begin_layout LyX-Code
25638     /* action to be taken when bus collision occurs */
25639 \end_layout
25640
25641 \begin_layout LyX-Code
25642     retfie
25643 \end_layout
25644
25645 \begin_layout LyX-Code
25646  _endasm;
25647 \end_layout
25648
25649 \begin_layout LyX-Code
25650 }
25651 \end_layout
25652
25653 \begin_layout Standard
25654
25655 \series bold
25656 NOTES:
25657 \series default
25658  Special care should be taken when using the above scheme:
25659 \end_layout
25660
25661 \begin_layout Itemize
25662 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
25663 \end_layout
25664
25665 \begin_layout Itemize
25666 when declaring SIGHANDLERNAKED handler never forget to use 
25667 \emph on
25668 retfie
25669 \emph default
25670  for proper returning.
25671 \end_layout
25672
25673 \begin_layout Subsection
25674 PIC16 Port -- Tips
25675 \end_layout
25676
25677 \begin_layout Standard
25678 Here you can find some general tips for compiling programs with SDCC/pic16.
25679 \end_layout
25680
25681 \begin_layout Subsubsection
25682 Stack size
25683 \end_layout
25684
25685 \begin_layout Standard
25686 The default stack
25687 \begin_inset LatexCommand \index{PIC16!stack}
25688
25689 \end_inset
25690
25691  size (that is 64 bytes) probably is enough for many programs.
25692  One must take care that when there are many levels of function nesting,
25693  or there is excessive usage of stack, its size should be extended.
25694  An example of such a case is the printf/sprintf family of functions.
25695  If you encounter problems like not being able to print integers, then you
25696  need to set the stack size around the maximum (256 for small stack model).
25697  The following diagram shows what happens when calling printf to print an
25698  integer:
25699 \end_layout
25700
25701 \begin_layout LyX-Code
25702 printf () --> ltoa () --> ultoa () --> divschar ()
25703 \end_layout
25704
25705 \begin_layout Standard
25706 It is should be understood that stack is easily consumed when calling complicate
25707 d functions.
25708  Using command line arguments like -
25709 \begin_inset ERT
25710 status collapsed
25711
25712 \begin_layout Standard
25713
25714
25715 \backslash
25716 /
25717 \end_layout
25718
25719 \end_inset
25720
25721 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
25722  stack frames.
25723  Other ways to reduce stack usage may exist.
25724 \end_layout
25725
25726 \begin_layout Subsection
25727 Known bugs
25728 \end_layout
25729
25730 \begin_layout Standard
25731 The PIC16 Port currently does not pass SDCC's regression test
25732 \begin_inset LatexCommand \index{Regression test (PIC16)}
25733
25734 \end_inset
25735
25736  suite (see section 
25737 \begin_inset LatexCommand \ref{sec:Quality-control}
25738
25739 \end_inset
25740
25741 ) and thus the nightly regression tests for the PIC16 target are currently
25742  disabled for all hosts except for 
25743 \emph on
25744 Linux on Opteron.
25745
25746 \emph default
25747  This means you can see the result of the PIC16 regression tests f.e.
25748  by checking the log files in 
25749 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
25750
25751 \end_inset
25752
25753  (pick the most up to date file there, scroll down, lend a hand).
25754 \end_layout
25755
25756 \begin_layout Chapter
25757 Debugging
25758 \end_layout
25759
25760 \begin_layout Standard
25761 There are several approaches to debugging your code.
25762  This chapter is meant to show your options and to give detail on some of
25763  them:
25764 \newline
25765
25766 \newline
25767 When writing your code:
25768 \end_layout
25769
25770 \begin_layout Itemize
25771 write your code with debugging in mind (avoid duplicating code, put conceptually
25772  similar variables into structs, use structured code, have strategic points
25773  within your code where all variables are consistent, ...)
25774 \end_layout
25775
25776 \begin_layout Itemize
25777 run a syntax-checking tool like splint
25778 \begin_inset LatexCommand \index{splint (syntax checking tool)}
25779
25780 \end_inset
25781
25782
25783 \begin_inset LatexCommand \index{lint (syntax checking tool)}
25784
25785 \end_inset
25786
25787  (see -
25788 \begin_inset ERT
25789 status collapsed
25790
25791 \begin_layout Standard
25792
25793
25794 \backslash
25795 /
25796 \end_layout
25797
25798 \end_inset
25799
25800 -more-pedantic 
25801 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25802
25803 \end_inset
25804
25805 ) over the code.
25806 \end_layout
25807
25808 \begin_layout Itemize
25809 for the high level code use a C-compiler (like f.e.
25810  GCC) to compile run and debug the code on your host.
25811  See (see -
25812 \begin_inset ERT
25813 status collapsed
25814
25815 \begin_layout Standard
25816
25817
25818 \backslash
25819 /
25820 \end_layout
25821
25822 \end_inset
25823
25824 -more-pedantic 
25825 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25826
25827 \end_inset
25828
25829  ) on howto handle syntax extensions like __xdata, __at(), ...
25830  
25831 \end_layout
25832
25833 \begin_layout Itemize
25834 use another C-compiler to compile code for your target.
25835  Always an option but not recommended:) And not very likely to help you.
25836  If you seriously consider walking this path you should at least occasionally
25837  check portability of your code.
25838  Most commercial compiler vendors will offer an evaluation version so you
25839  can test compile your code or snippets of your code.
25840 \end_layout
25841
25842 \begin_layout Standard
25843 Debugging on a simulator:
25844 \end_layout
25845
25846 \begin_layout Itemize
25847 there is a separate section about SDCDB (section 
25848 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
25849
25850 \end_inset
25851
25852 ) below.
25853 \end_layout
25854
25855 \begin_layout Itemize
25856 or (8051 specific) use a freeware/commercial simulator which interfaces
25857  to the AOMF
25858 \begin_inset LatexCommand \index{AOMF, AOMF51}
25859
25860 \end_inset
25861
25862  file (see 
25863 \begin_inset LatexCommand \ref{OMF file}
25864
25865 \end_inset
25866
25867 ) optionally generated by SDCC.
25868 \end_layout
25869
25870 \begin_layout Standard
25871 Debugging On-target: 
25872 \end_layout
25873
25874 \begin_layout Itemize
25875 use a MCU port pin to serially output debug data to the RS232 port of your
25876  host.
25877  You'll probably want some level shifting device typically involving a MAX232
25878  or similar IC.
25879  If the hardware serial port of the MCU is not available search for 'Software
25880  UART' in your favourite search machine.
25881 \end_layout
25882
25883 \begin_layout Itemize
25884 use an on-target monitor.
25885  In this context a monitor is a small program which usually accepts commands
25886  via a serial line and allows to set program counter, to single step through
25887  a program and read/write memory locations.
25888  For the 8051 good examples of monitors are paulmon and cmon51 (see section
25889  
25890 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
25891
25892 \end_inset
25893
25894 ).
25895 \end_layout
25896
25897 \begin_layout Itemize
25898 toggle MCU port pins at strategic points within your code and use an oscilloscop
25899 e.
25900  A 
25901 \emph on
25902 digital oscilloscope
25903 \emph default
25904
25905 \begin_inset LatexCommand \index{Oscilloscope}
25906
25907 \end_inset
25908
25909  with deep trace memory is really helpful especially if you have to debug
25910  a realtime application.
25911  If you need to monitor more pins than your oscilloscope provides you can
25912  sometimes get away with a small R-2R network.
25913  On a single channel oscilloscope you could f.e.
25914  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
25915 k
25916 \begin_inset Formula $\Omega$
25917 \end_inset
25918
25919  resistor and the other one by a 5\InsetSpace ~
25920 k
25921 \begin_inset Formula $\Omega$
25922 \end_inset
25923
25924  resistor to the oscilloscope probe (check output drive capability of the
25925  pins you want to monitor).
25926  If you need to monitor many more pins a 
25927 \emph on
25928 logic analyzer
25929 \emph default
25930  will be handy.
25931 \end_layout
25932
25933 \begin_layout Itemize
25934 use an ICE (
25935 \emph on
25936 i
25937 \emph default
25938
25939 \emph on
25940 c
25941 \emph default
25942 ircuit 
25943 \emph on
25944 e
25945 \emph default
25946 mulator
25947 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
25948
25949 \end_inset
25950
25951 ).
25952  Usually very expensive.
25953  And very nice to have too.
25954  And usually locks you (for years...) to the devices the ICE can emulate.
25955  
25956 \end_layout
25957
25958 \begin_layout Itemize
25959 use a remote debugger.
25960  In most 8-bit systems the symbol information is not available on the target,
25961  and a complete debugger is too bulky for the target system.
25962  Therefore usually a debugger on the host system connects to an on-target
25963  debugging stub which accepts only primitive commands.
25964  
25965 \newline
25966 Terms to enter into your favourite search engine could be 'remote debugging',
25967  'gdb stub' or 'inferior debugger'.
25968  (is there one?)
25969 \end_layout
25970
25971 \begin_layout Itemize
25972 use an on target hardware debugger.
25973  Some of the more modern MCUs include hardware support for setting break
25974  points and monitoring/changing variables by using dedicated hardware pins.
25975  This facility doesn't require additional code to run on the target and
25976  
25977 \emph on
25978 usually
25979 \emph default
25980  doesn't affect runtime behaviour until a breakpoint is hit.
25981  For the mcs51 most hardware debuggers use the AOMF
25982 \begin_inset LatexCommand \index{AOMF, AOMF51}
25983
25984 \end_inset
25985
25986  file (see 
25987 \begin_inset LatexCommand \ref{OMF file}
25988
25989 \end_inset
25990
25991 ) as input file.
25992  
25993 \end_layout
25994
25995 \begin_layout Standard
25996 Last not least:
25997 \end_layout
25998
25999 \begin_layout Itemize
26000 if you are not familiar with any of the following terms you're likely to
26001  run into problems rather sooner than later: 
26002 \emph on
26003 volatile
26004 \emph default
26005
26006 \emph on
26007 atomic
26008 \emph default
26009
26010 \emph on
26011 memory map
26012 \emph default
26013
26014 \emph on
26015 overlay
26016 \emph default
26017 .
26018  As an embedded programmer you 
26019 \emph on
26020 have
26021 \emph default
26022  to know them so why not look them up 
26023 \emph on
26024 before
26025 \emph default
26026  you have problems?)
26027 \end_layout
26028
26029 \begin_layout Itemize
26030 tell someone else about your problem (actually this is a surprisingly effective
26031  means to hunt down the bug even if the listener is not familiar with your
26032  environment).
26033  As 'failure to communicate' is probably one of the job-induced deformations
26034  of an embedded programmer this is highly encouraged.
26035 \end_layout
26036
26037 \begin_layout Section
26038 Debugging with SDCDB
26039 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
26040
26041 \end_inset
26042
26043
26044 \begin_inset LatexCommand \index{SDCDB (debugger)}
26045
26046 \end_inset
26047
26048  
26049 \end_layout
26050
26051 \begin_layout Standard
26052 SDCC is distributed with a source level debugger
26053 \begin_inset LatexCommand \index{Debugger}
26054
26055 \end_inset
26056
26057 .
26058  The debugger uses a command line interface, the command repertoire of the
26059  debugger has been kept as close to gdb
26060 \begin_inset LatexCommand \index{gdb}
26061
26062 \end_inset
26063
26064  (the GNU debugger) as possible.
26065  The configuration and build process is part of the standard compiler installati
26066 on, which also builds and installs the debugger in the target directory
26067  specified during configuration.
26068  The debugger allows you debug BOTH at the C source and at the ASM source
26069  level.
26070 \end_layout
26071
26072 \begin_layout Subsection
26073 Compiling for Debugging
26074 \end_layout
26075
26076 \begin_layout Standard
26077 The -
26078 \begin_inset ERT
26079 status collapsed
26080
26081 \begin_layout Standard
26082
26083
26084 \backslash
26085 /
26086 \end_layout
26087
26088 \end_inset
26089
26090 -debug
26091 \begin_inset LatexCommand \index{-\/-debug}
26092
26093 \end_inset
26094
26095  option must be specified for all files for which debug information is to
26096  be generated.
26097  The compiler generates a .adb file for each of these files.
26098  The linker creates the .cdb
26099 \begin_inset LatexCommand \index{<file>.cdb}
26100
26101 \end_inset
26102
26103  file from the .adb
26104 \begin_inset LatexCommand \index{<file>.adb}
26105
26106 \end_inset
26107
26108  files and the address information.
26109  This .cdb is used by the debugger.
26110 \end_layout
26111
26112 \begin_layout Subsection
26113 How the Debugger Works
26114 \end_layout
26115
26116 \begin_layout Standard
26117 When the -
26118 \begin_inset ERT
26119 status collapsed
26120
26121 \begin_layout Standard
26122
26123
26124 \backslash
26125 /
26126 \end_layout
26127
26128 \end_inset
26129
26130 -debug option is specified the compiler generates extra symbol information
26131  some of which are put into the assembler source and some are put into the
26132  .adb file.
26133  Then the linker creates the .cdb file from the individual .adb files with
26134  the address information for the symbols.
26135  The debugger reads the symbolic information generated by the compiler &
26136  the address information generated by the linker.
26137  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
26138  execution is controlled by the debugger.
26139  When a command is issued for the debugger, it translates it into appropriate
26140  commands for the simulator.
26141  (Currently SDCDM only connects to the simulator but 
26142 \emph on
26143 newcdb
26144 \emph default
26145  at 
26146 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
26147
26148 \end_inset
26149
26150  is an effort to connect directly to the hardware.) 
26151 \end_layout
26152
26153 \begin_layout Subsection
26154 Starting the Debugger SDCDB
26155 \end_layout
26156
26157 \begin_layout Standard
26158 The debugger can be started using the following command line.
26159  (Assume the file you are debugging has the file name foo).
26160 \newline
26161
26162 \newline
26163
26164 \family sans
26165 \series bold
26166 sdcdb foo
26167 \newline
26168
26169 \family default
26170 \series default
26171
26172 \newline
26173 The debugger will look for the following files.
26174 \end_layout
26175
26176 \begin_layout Itemize
26177 foo.c - the source file.
26178 \end_layout
26179
26180 \begin_layout Itemize
26181 foo.cdb - the debugger symbol information file.
26182 \end_layout
26183
26184 \begin_layout Itemize
26185 foo.ihx - the Intel hex format
26186 \begin_inset LatexCommand \index{Intel hex format}
26187
26188 \end_inset
26189
26190  object file.
26191 \end_layout
26192
26193 \begin_layout Subsection
26194 SDCDB Command Line Options
26195 \end_layout
26196
26197 \begin_layout Itemize
26198 -
26199 \begin_inset ERT
26200 status collapsed
26201
26202 \begin_layout Standard
26203
26204
26205 \backslash
26206 /
26207 \end_layout
26208
26209 \end_inset
26210
26211 -directory=<source file directory> this option can used to specify the directory
26212  search list.
26213  The debugger will look into the directory list specified for source, cdb
26214  & ihx files.
26215  The items in the directory list must be separated by ':', e.g.
26216  if the source files can be in the directories /home/src1 and /home/src2,
26217  the -
26218 \begin_inset ERT
26219 status collapsed
26220
26221 \begin_layout Standard
26222
26223
26224 \backslash
26225 /
26226 \end_layout
26227
26228 \end_inset
26229
26230 -directory option should be -
26231 \begin_inset ERT
26232 status collapsed
26233
26234 \begin_layout Standard
26235
26236
26237 \backslash
26238 /
26239 \end_layout
26240
26241 \end_inset
26242
26243 -directory=/home/src1:/home/src2.
26244  Note there can be no spaces in the option.
26245  
26246 \end_layout
26247
26248 \begin_layout Itemize
26249 -cd <directory> - change to the <directory>.
26250 \end_layout
26251
26252 \begin_layout Itemize
26253 -fullname - used by GUI front ends.
26254 \end_layout
26255
26256 \begin_layout Itemize
26257 -cpu <cpu-type> - this argument is passed to the simulator please see the
26258  simulator docs for details.
26259 \end_layout
26260
26261 \begin_layout Itemize
26262 -X <Clock frequency > this options is passed to the simulator please see
26263  the simulator docs for details.
26264 \end_layout
26265
26266 \begin_layout Itemize
26267 -s <serial port file> passed to simulator see the simulator docs for details.
26268 \end_layout
26269
26270 \begin_layout Itemize
26271 -S <serial in,out> passed to simulator see the simulator docs for details.
26272 \end_layout
26273
26274 \begin_layout Itemize
26275 -k <port number> passed to simulator see the simulator docs for details.
26276 \end_layout
26277
26278 \begin_layout Subsection
26279 SDCDB Debugger Commands
26280 \end_layout
26281
26282 \begin_layout Standard
26283 As mentioned earlier the command interface for the debugger has been deliberatel
26284 y kept as close the GNU debugger gdb, as possible.
26285  This will help the integration with existing graphical user interfaces
26286  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
26287  If you use a graphical user interface for the debugger you can skip this
26288  section.
26289 \end_layout
26290
26291 \begin_layout Subsubsection*
26292 break [line | file:line | function | file:function]
26293 \end_layout
26294
26295 \begin_layout Standard
26296 Set breakpoint at specified line or function:
26297 \newline
26298
26299 \newline
26300
26301 \family sans
26302 \series bold
26303 sdcdb>break 100 
26304 \newline
26305 sdcdb>break foo.c:100
26306 \newline
26307 sdcdb>break funcfoo
26308 \newline
26309 sdcdb>break foo.c:funcfoo
26310 \end_layout
26311
26312 \begin_layout Subsubsection*
26313 clear [line | file:line | function | file:function ]
26314 \end_layout
26315
26316 \begin_layout Standard
26317 Clear breakpoint at specified line or function:
26318 \newline
26319
26320 \newline
26321
26322 \family sans
26323 \series bold
26324 sdcdb>clear 100
26325 \newline
26326 sdcdb>clear foo.c:100
26327 \newline
26328 sdcdb>clear funcfoo
26329 \newline
26330 sdcdb>clear foo.c:funcfoo
26331 \end_layout
26332
26333 \begin_layout Subsubsection*
26334 continue
26335 \end_layout
26336
26337 \begin_layout Standard
26338 Continue program being debugged, after breakpoint.
26339 \end_layout
26340
26341 \begin_layout Subsubsection*
26342 finish
26343 \end_layout
26344
26345 \begin_layout Standard
26346 Execute till the end of the current function.
26347 \end_layout
26348
26349 \begin_layout Subsubsection*
26350 delete [n]
26351 \end_layout
26352
26353 \begin_layout Standard
26354 Delete breakpoint number 'n'.
26355  If used without any option clear ALL user defined break points.
26356 \end_layout
26357
26358 \begin_layout Subsubsection*
26359 info [break | stack | frame | registers ]
26360 \end_layout
26361
26362 \begin_layout Itemize
26363 info break - list all breakpoints
26364 \end_layout
26365
26366 \begin_layout Itemize
26367 info stack - show the function call stack.
26368 \end_layout
26369
26370 \begin_layout Itemize
26371 info frame - show information about the current execution frame.
26372 \end_layout
26373
26374 \begin_layout Itemize
26375 info registers - show content of all registers.
26376 \end_layout
26377
26378 \begin_layout Subsubsection*
26379 step
26380 \end_layout
26381
26382 \begin_layout Standard
26383 Step program until it reaches a different source line.
26384  Note: pressing <return> repeats the last command.
26385 \end_layout
26386
26387 \begin_layout Subsubsection*
26388 next
26389 \end_layout
26390
26391 \begin_layout Standard
26392 Step program, proceeding through subroutine calls.
26393 \end_layout
26394
26395 \begin_layout Subsubsection*
26396 run
26397 \end_layout
26398
26399 \begin_layout Standard
26400 Start debugged program.
26401 \end_layout
26402
26403 \begin_layout Subsubsection*
26404 ptype variable 
26405 \end_layout
26406
26407 \begin_layout Standard
26408 Print type information of the variable.
26409 \end_layout
26410
26411 \begin_layout Subsubsection*
26412 print variable
26413 \end_layout
26414
26415 \begin_layout Standard
26416 print value of variable.
26417 \end_layout
26418
26419 \begin_layout Subsubsection*
26420 file filename
26421 \end_layout
26422
26423 \begin_layout Standard
26424 load the given file name.
26425  Note this is an alternate method of loading file for debugging.
26426 \end_layout
26427
26428 \begin_layout Subsubsection*
26429 frame
26430 \end_layout
26431
26432 \begin_layout Standard
26433 print information about current frame.
26434 \end_layout
26435
26436 \begin_layout Subsubsection*
26437 set srcmode
26438 \end_layout
26439
26440 \begin_layout Standard
26441 Toggle between C source & assembly source.
26442 \end_layout
26443
26444 \begin_layout Subsubsection*
26445 ! simulator command
26446 \end_layout
26447
26448 \begin_layout Standard
26449 Send the string following '!' to the simulator, the simulator response is
26450  displayed.
26451  Note the debugger does not interpret the command being sent to the simulator,
26452  so if a command like 'go' is sent the debugger can loose its execution
26453  context and may display incorrect values.
26454 \end_layout
26455
26456 \begin_layout Subsubsection*
26457 quit
26458 \end_layout
26459
26460 \begin_layout Standard
26461 "Watch me now.
26462  Iam going Down.
26463  My name is Bobby Brown"
26464 \end_layout
26465
26466 \begin_layout Subsection
26467 Interfacing SDCDB with DDD
26468 \end_layout
26469
26470 \begin_layout Standard
26471 \begin_inset Note Comment
26472 status collapsed
26473
26474 \begin_layout Standard
26475 The screenshot was converted from png to eps with: 
26476 \begin_inset Quotes sld
26477 \end_inset
26478
26479 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
26480 \begin_inset Quotes srd
26481 \end_inset
26482
26483  which produces a pretty compact eps file which is free from compression
26484  artifacts.
26485 \end_layout
26486
26487 \begin_layout Standard
26488 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
26489  as this broke the build system on Sourceforge (pdf-file was broken.
26490  pdflatex does not accept eps files).
26491 \end_layout
26492
26493 \end_inset
26494
26495
26496 \end_layout
26497
26498 \begin_layout Standard
26499 The 
26500 \emph on
26501 p
26502 \emph default
26503 ortable 
26504 \emph on
26505 n
26506 \emph default
26507 etwork 
26508 \emph on
26509 g
26510 \emph default
26511 raphics File 
26512 \size footnotesize
26513
26514 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
26515
26516 \end_inset
26517
26518
26519 \size default
26520  shows a screenshot of a debugging session with DDD
26521 \begin_inset LatexCommand \index{DDD (debugger)}
26522
26523 \end_inset
26524
26525  (Unix only) on a simulated 8032.
26526  The debugging session might not run as smoothly as the screenshot suggests.
26527  The debugger allows setting of breakpoints, displaying and changing variables,
26528  single stepping through C and assembler code.
26529  
26530 \newline
26531 The source was compiled with 
26532 \family sans
26533 \series bold
26534
26535 \newline
26536
26537 \newline
26538 sdcc -
26539 \family default
26540 \series default
26541
26542 \begin_inset ERT
26543 status collapsed
26544
26545 \begin_layout Standard
26546
26547
26548 \backslash
26549 /
26550 \end_layout
26551
26552 \end_inset
26553
26554
26555 \family sans
26556 \series bold
26557 -debug ddd_example.c
26558 \family default
26559 \series default
26560  
26561 \family sans
26562 \series bold
26563
26564 \newline
26565
26566 \family default
26567 \series default
26568
26569 \newline
26570 and DDD was invoked with 
26571 \family sans
26572 \series bold
26573
26574 \newline
26575
26576 \newline
26577 ddd -debugger "sdcdb -cpu 8032 ddd_example"
26578 \end_layout
26579
26580 \begin_layout Standard
26581 \begin_inset Note Note
26582 status open
26583
26584 \begin_layout Standard
26585 Check that the double quotes or an apostroph within the command line survive
26586  the LyX tool chain.
26587  Previously the apostrophs got slanted in the PDF output so a cut and paste
26588  did not work.
26589 \end_layout
26590
26591 \end_inset
26592
26593
26594 \end_layout
26595
26596 \begin_layout Subsection
26597 Interfacing SDCDB with XEmacs
26598 \begin_inset LatexCommand \index{XEmacs}
26599
26600 \end_inset
26601
26602
26603 \begin_inset LatexCommand \index{Emacs}
26604
26605 \end_inset
26606
26607
26608 \end_layout
26609
26610 \begin_layout Standard
26611 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
26612  sdcdb.el and sdcdbsrc.el.
26613  These two files can be found in the $(prefix)/bin directory after the installat
26614 ion is complete.
26615  These files need to be loaded into XEmacs for the interface to work.
26616  This can be done at XEmacs startup time by inserting the following into
26617  your '.xemacs' file (which can be found in your HOME directory): 
26618 \newline
26619
26620 \newline
26621
26622 \family typewriter
26623 (load-file sdcdbsrc.el) 
26624 \family default
26625
26626 \newline
26627
26628 \newline
26629 .xemacs is a lisp file so the () around the command is REQUIRED.
26630  The files can also be loaded dynamically while XEmacs is running, set the
26631  environment variable 'EMACSLOADPATH' to the installation bin directory
26632  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
26633  To start the interface enter the following command: 
26634 \newline
26635
26636 \newline
26637
26638 \family sans
26639 \series bold
26640 ESC-x sdcdbsrc
26641 \family default
26642 \series default
26643
26644 \newline
26645
26646 \newline
26647 You will prompted to enter the file name to be debugged.
26648  
26649 \newline
26650
26651 \newline
26652 The command line options that are passed to the simulator directly are
26653  bound to default values in the file sdcdbsrc.el.
26654  The variables are listed below, these values maybe changed as required.
26655 \end_layout
26656
26657 \begin_layout Itemize
26658 sdcdbsrc-cpu-type '51
26659 \end_layout
26660
26661 \begin_layout Itemize
26662 sdcdbsrc-frequency '11059200
26663 \end_layout
26664
26665 \begin_layout Itemize
26666 sdcdbsrc-serial nil
26667 \end_layout
26668
26669 \begin_layout Standard
26670 The following is a list of key mapping for the debugger interface.
26671 \end_layout
26672
26673 \begin_layout Standard
26674 \InsetSpace ~
26675
26676 \family typewriter
26677
26678 \newline
26679 ;;\InsetSpace ~
26680 Current Listing :: 
26681 \newline
26682 ;;key\InsetSpace ~
26683 \InsetSpace ~
26684 \InsetSpace ~
26685 \InsetSpace ~
26686 \InsetSpace ~
26687 \InsetSpace ~
26688 \InsetSpace ~
26689 \InsetSpace ~
26690 \InsetSpace ~
26691 \InsetSpace ~
26692 \InsetSpace ~
26693 \InsetSpace ~
26694 \InsetSpace ~
26695 \InsetSpace ~
26696 binding\InsetSpace ~
26697 \InsetSpace ~
26698 \InsetSpace ~
26699 \InsetSpace ~
26700 \InsetSpace ~
26701 \InsetSpace ~
26702 \InsetSpace ~
26703 \InsetSpace ~
26704 \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 Comment 
26719 \newline
26720 ;;---\InsetSpace ~
26721 \InsetSpace ~
26722 \InsetSpace ~
26723 \InsetSpace ~
26724 \InsetSpace ~
26725 \InsetSpace ~
26726 \InsetSpace ~
26727 \InsetSpace ~
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 -------
26757 \newline
26758 ;; 
26759 \newline
26760 ;;\InsetSpace ~
26761 n\InsetSpace ~
26762 \InsetSpace ~
26763 \InsetSpace ~
26764 \InsetSpace ~
26765 \InsetSpace ~
26766 \InsetSpace ~
26767 \InsetSpace ~
26768 \InsetSpace ~
26769 \InsetSpace ~
26770 \InsetSpace ~
26771 \InsetSpace ~
26772 \InsetSpace ~
26773 \InsetSpace ~
26774 \InsetSpace ~
26775 \InsetSpace ~
26776 sdcdb-next-fro
26777 m-src\InsetSpace ~
26778 \InsetSpace ~
26779 \InsetSpace ~
26780 \InsetSpace ~
26781 \InsetSpace ~
26782 \InsetSpace ~
26783 \InsetSpace ~
26784 \InsetSpace ~
26785 \InsetSpace ~
26786 \InsetSpace ~
26787 SDCDB next command 
26788 \newline
26789 ;;\InsetSpace ~
26790 b\InsetSpace ~
26791 \InsetSpace ~
26792 \InsetSpace ~
26793 \InsetSpace ~
26794 \InsetSpace ~
26795 \InsetSpace ~
26796 \InsetSpace ~
26797 \InsetSpace ~
26798 \InsetSpace ~
26799 \InsetSpace ~
26800 \InsetSpace ~
26801 \InsetSpace ~
26802 \InsetSpace ~
26803 \InsetSpace ~
26804 \InsetSpace ~
26805 sdcdb-back-from-src\InsetSpace ~
26806 \InsetSpace ~
26807 \InsetSpace ~
26808 \InsetSpace ~
26809 \InsetSpace ~
26810 \InsetSpace ~
26811 \InsetSpace ~
26812 \InsetSpace ~
26813 \InsetSpace ~
26814 \InsetSpace ~
26815 SDCDB back command 
26816 \newline
26817 ;;\InsetSpace ~
26818 c\InsetSpace ~
26819 \InsetSpace ~
26820 \InsetSpace ~
26821 \InsetSpace ~
26822 \InsetSpace ~
26823 \InsetSpace ~
26824 \InsetSpace ~
26825 \InsetSpace ~
26826 \InsetSpace ~
26827 \InsetSpace ~
26828 \InsetSpace ~
26829 \InsetSpace ~
26830 \InsetSpace ~
26831 \InsetSpace ~
26832 \InsetSpace ~
26833 sdcdb-cont-f
26834 rom-src\InsetSpace ~
26835 \InsetSpace ~
26836 \InsetSpace ~
26837 \InsetSpace ~
26838 \InsetSpace ~
26839 \InsetSpace ~
26840 \InsetSpace ~
26841 \InsetSpace ~
26842 \InsetSpace ~
26843 \InsetSpace ~
26844 SDCDB continue command
26845 \newline
26846 ;;\InsetSpace ~
26847 s\InsetSpace ~
26848 \InsetSpace ~
26849 \InsetSpace ~
26850 \InsetSpace ~
26851 \InsetSpace ~
26852 \InsetSpace ~
26853 \InsetSpace ~
26854 \InsetSpace ~
26855 \InsetSpace ~
26856 \InsetSpace ~
26857 \InsetSpace ~
26858 \InsetSpace ~
26859 \InsetSpace ~
26860 \InsetSpace ~
26861 \InsetSpace ~
26862 sdcdb-step-from-src\InsetSpace ~
26863 \InsetSpace ~
26864 \InsetSpace ~
26865 \InsetSpace ~
26866 \InsetSpace ~
26867 \InsetSpace ~
26868 \InsetSpace ~
26869 \InsetSpace ~
26870 \InsetSpace ~
26871 \InsetSpace ~
26872 SDCDB step command 
26873 \newline
26874 ;;\InsetSpace ~
26875 ?\InsetSpace ~
26876 \InsetSpace ~
26877 \InsetSpace ~
26878 \InsetSpace ~
26879 \InsetSpace ~
26880 \InsetSpace ~
26881 \InsetSpace ~
26882 \InsetSpace ~
26883 \InsetSpace ~
26884 \InsetSpace ~
26885 \InsetSpace ~
26886 \InsetSpace ~
26887 \InsetSpace ~
26888 \InsetSpace ~
26889 \InsetSpace ~
26890 sdcdb-w
26891 hatis-c-sexp\InsetSpace ~
26892 \InsetSpace ~
26893 \InsetSpace ~
26894 \InsetSpace ~
26895 \InsetSpace ~
26896 \InsetSpace ~
26897 \InsetSpace ~
26898 \InsetSpace ~
26899 \InsetSpace ~
26900 \InsetSpace ~
26901 SDCDB ptypecommand for data at 
26902 \newline
26903 ;;\InsetSpace ~
26904 \InsetSpace ~
26905 \InsetSpace ~
26906 \InsetSpace ~
26907 \InsetSpace ~
26908 \InsetSpace ~
26909 \InsetSpace ~
26910 \InsetSpace ~
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 buffer point 
26951 \newline
26952 ;;\InsetSpace ~
26953 x\InsetSpace ~
26954 \InsetSpace ~
26955 \InsetSpace ~
26956 \InsetSpace ~
26957 \InsetSpace ~
26958 \InsetSpace ~
26959 \InsetSpace ~
26960 \InsetSpace ~
26961 \InsetSpace ~
26962 \InsetSpace ~
26963 \InsetSpace ~
26964 \InsetSpace ~
26965 \InsetSpace ~
26966 \InsetSpace ~
26967 \InsetSpace ~
26968 sdcdbsrc-delete\InsetSpace ~
26969 \InsetSpace ~
26970 \InsetSpace ~
26971 \InsetSpace ~
26972 \InsetSpace ~
26973 \InsetSpace ~
26974 \InsetSpace ~
26975 \InsetSpace ~
26976 \InsetSpace ~
26977 \InsetSpace ~
26978 \InsetSpace ~
26979 \InsetSpace ~
26980 \InsetSpace ~
26981 \InsetSpace ~
26982 SDCD
26983 B Delete all breakpoints if no arg 
26984 \newline
26985 ;;\InsetSpace ~
26986 \InsetSpace ~
26987 \InsetSpace ~
26988 \InsetSpace ~
26989 \InsetSpace ~
26990 \InsetSpace ~
26991 \InsetSpace ~
26992 \InsetSpace ~
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 given or delete arg (C-u arg x) 
27033 \newline
27034 ;;\InsetSpace ~
27035 m\InsetSpace ~
27036 \InsetSpace ~
27037 \InsetSpace ~
27038 \InsetSpace ~
27039 \InsetSpace ~
27040 \InsetSpace ~
27041 \InsetSpace ~
27042 \InsetSpace ~
27043 \InsetSpace ~
27044 \InsetSpace ~
27045 \InsetSpace ~
27046 \InsetSpace ~
27047 \InsetSpace ~
27048 \InsetSpace ~
27049 \InsetSpace ~
27050 sdcdbsrc
27051 -frame\InsetSpace ~
27052 \InsetSpace ~
27053 \InsetSpace ~
27054 \InsetSpace ~
27055 \InsetSpace ~
27056 \InsetSpace ~
27057 \InsetSpace ~
27058 \InsetSpace ~
27059 \InsetSpace ~
27060 \InsetSpace ~
27061 \InsetSpace ~
27062 \InsetSpace ~
27063 \InsetSpace ~
27064 \InsetSpace ~
27065 \InsetSpace ~
27066 SDCDB Display current frame if no arg, 
27067 \newline
27068 ;;\InsetSpace ~
27069 \InsetSpace ~
27070 \InsetSpace ~
27071 \InsetSpace ~
27072 \InsetSpace ~
27073 \InsetSpace ~
27074 \InsetSpace ~
27075 \InsetSpace ~
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 given or display frame arg
27116  
27117 \newline
27118 ;;\InsetSpace ~
27119 \InsetSpace ~
27120 \InsetSpace ~
27121 \InsetSpace ~
27122 \InsetSpace ~
27123 \InsetSpace ~
27124 \InsetSpace ~
27125 \InsetSpace ~
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 buffer point 
27166 \newline
27167 ;;\InsetSpace ~
27168 !\InsetSpace ~
27169 \InsetSpace ~
27170 \InsetSpace ~
27171 \InsetSpace ~
27172 \InsetSpace ~
27173 \InsetSpace ~
27174 \InsetSpace ~
27175 \InsetSpace ~
27176 \InsetSpace ~
27177 \InsetSpace ~
27178 \InsetSpace ~
27179 \InsetSpace ~
27180 \InsetSpace ~
27181 \InsetSpace ~
27182 \InsetSpace ~
27183 sdcdbsrc-goto-sdcdb\InsetSpace ~
27184 \InsetSpace ~
27185 \InsetSpace ~
27186 \InsetSpace ~
27187 \InsetSpace ~
27188 \InsetSpace ~
27189 \InsetSpace ~
27190 \InsetSpace ~
27191 \InsetSpace ~
27192 \InsetSpace ~
27193 Goto the SDCDB output buffer 
27194 \newline
27195 ;;\InsetSpace ~
27196 p\InsetSpace ~
27197 \InsetSpace ~
27198 \InsetSpace ~
27199 \InsetSpace ~
27200 \InsetSpace ~
27201 \InsetSpace ~
27202 \InsetSpace ~
27203 \InsetSpace ~
27204 \InsetSpace ~
27205 \InsetSpace ~
27206 \InsetSpace ~
27207 \InsetSpace ~
27208 \InsetSpace ~
27209 \InsetSpace ~
27210 \InsetSpace ~
27211 sdcdb-prin
27212 t-c-sexp\InsetSpace ~
27213 \InsetSpace ~
27214 \InsetSpace ~
27215 \InsetSpace ~
27216 \InsetSpace ~
27217 \InsetSpace ~
27218 \InsetSpace ~
27219 \InsetSpace ~
27220 \InsetSpace ~
27221 \InsetSpace ~
27222 \InsetSpace ~
27223 SDCDB print command for data at 
27224 \newline
27225 ;;\InsetSpace ~
27226 \InsetSpace ~
27227 \InsetSpace ~
27228 \InsetSpace ~
27229 \InsetSpace ~
27230 \InsetSpace ~
27231 \InsetSpace ~
27232 \InsetSpace ~
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 buffer point 
27273 \newline
27274 ;;\InsetSpace ~
27275 g\InsetSpace ~
27276 \InsetSpace ~
27277 \InsetSpace ~
27278 \InsetSpace ~
27279 \InsetSpace ~
27280 \InsetSpace ~
27281 \InsetSpace ~
27282 \InsetSpace ~
27283 \InsetSpace ~
27284 \InsetSpace ~
27285 \InsetSpace ~
27286 \InsetSpace ~
27287 \InsetSpace ~
27288 \InsetSpace ~
27289 \InsetSpace ~
27290 sdcdbsrc-goto-sdcdb\InsetSpace ~
27291 \InsetSpace ~
27292 \InsetSpace ~
27293 \InsetSpace ~
27294 \InsetSpace ~
27295 \InsetSpace ~
27296 \InsetSpace ~
27297 \InsetSpace ~
27298 \InsetSpace ~
27299 \InsetSpace ~
27300 Got
27301 o the SDCDB output buffer 
27302 \newline
27303 ;;\InsetSpace ~
27304 t\InsetSpace ~
27305 \InsetSpace ~
27306 \InsetSpace ~
27307 \InsetSpace ~
27308 \InsetSpace ~
27309 \InsetSpace ~
27310 \InsetSpace ~
27311 \InsetSpace ~
27312 \InsetSpace ~
27313 \InsetSpace ~
27314 \InsetSpace ~
27315 \InsetSpace ~
27316 \InsetSpace ~
27317 \InsetSpace ~
27318 \InsetSpace ~
27319 sdcdbsrc-mode\InsetSpace ~
27320 \InsetSpace ~
27321 \InsetSpace ~
27322 \InsetSpace ~
27323 \InsetSpace ~
27324 \InsetSpace ~
27325 \InsetSpace ~
27326 \InsetSpace ~
27327 \InsetSpace ~
27328 \InsetSpace ~
27329 \InsetSpace ~
27330 \InsetSpace ~
27331 \InsetSpace ~
27332 \InsetSpace ~
27333 \InsetSpace ~
27334 \InsetSpace ~
27335 Toggles Sdcdbsrc mode (turns it
27336  off) 
27337 \newline
27338 ;; 
27339 \newline
27340 ;;\InsetSpace ~
27341 C-c\InsetSpace ~
27342 C-f\InsetSpace ~
27343 \InsetSpace ~
27344 \InsetSpace ~
27345 \InsetSpace ~
27346 \InsetSpace ~
27347 \InsetSpace ~
27348 \InsetSpace ~
27349 \InsetSpace ~
27350 \InsetSpace ~
27351 sdcdb-finish-from-src\InsetSpace ~
27352 \InsetSpace ~
27353 \InsetSpace ~
27354 \InsetSpace ~
27355 \InsetSpace ~
27356 \InsetSpace ~
27357 \InsetSpace ~
27358 \InsetSpace ~
27359 SDCDB finish command 
27360 \newline
27361 ;; 
27362 \newline
27363 ;;\InsetSpace ~
27364 C-x\InsetSpace ~
27365 SPC\InsetSpace ~
27366 \InsetSpace ~
27367 \InsetSpace ~
27368 \InsetSpace ~
27369 \InsetSpace ~
27370 \InsetSpace ~
27371 \InsetSpace ~
27372 \InsetSpace ~
27373 \InsetSpace ~
27374 sdcdb-brea
27375 k\InsetSpace ~
27376 \InsetSpace ~
27377 \InsetSpace ~
27378 \InsetSpace ~
27379 \InsetSpace ~
27380 \InsetSpace ~
27381 \InsetSpace ~
27382 \InsetSpace ~
27383 \InsetSpace ~
27384 \InsetSpace ~
27385 \InsetSpace ~
27386 \InsetSpace ~
27387 \InsetSpace ~
27388 \InsetSpace ~
27389 \InsetSpace ~
27390 \InsetSpace ~
27391 \InsetSpace ~
27392 \InsetSpace ~
27393 Set break for line with point 
27394 \newline
27395 ;;\InsetSpace ~
27396 ESC\InsetSpace ~
27397 t\InsetSpace ~
27398 \InsetSpace ~
27399 \InsetSpace ~
27400 \InsetSpace ~
27401 \InsetSpace ~
27402 \InsetSpace ~
27403 \InsetSpace ~
27404 \InsetSpace ~
27405 \InsetSpace ~
27406 \InsetSpace ~
27407 \InsetSpace ~
27408 sdcdbsrc-mode\InsetSpace ~
27409 \InsetSpace ~
27410 \InsetSpace ~
27411 \InsetSpace ~
27412 \InsetSpace ~
27413 \InsetSpace ~
27414 \InsetSpace ~
27415 \InsetSpace ~
27416 \InsetSpace ~
27417 \InsetSpace ~
27418 \InsetSpace ~
27419 \InsetSpace ~
27420 \InsetSpace ~
27421 \InsetSpace ~
27422 \InsetSpace ~
27423 \InsetSpace ~
27424 Toggle Sdcdbsrc mode 
27425 \newline
27426 ;;\InsetSpace ~
27427 ESC\InsetSpace ~
27428 m\InsetSpace ~
27429 \InsetSpace ~
27430 \InsetSpace ~
27431 \InsetSpace ~
27432 \InsetSpace ~
27433 \InsetSpace ~
27434 \InsetSpace ~
27435 \InsetSpace ~
27436 \InsetSpace ~
27437 \InsetSpace ~
27438 \InsetSpace ~
27439 sdc
27440 dbsrc-srcmode\InsetSpace ~
27441 \InsetSpace ~
27442 \InsetSpace ~
27443 \InsetSpace ~
27444 \InsetSpace ~
27445 \InsetSpace ~
27446 \InsetSpace ~
27447 \InsetSpace ~
27448 \InsetSpace ~
27449 \InsetSpace ~
27450 \InsetSpace ~
27451 \InsetSpace ~
27452 \InsetSpace ~
27453 Toggle list mode 
27454 \newline
27455 ;; 
27456 \newline
27457
27458 \end_layout
27459
27460 \begin_layout Standard
27461
27462 \newpage
27463
27464 \end_layout
27465
27466 \begin_layout Chapter
27467 TIPS
27468 \end_layout
27469
27470 \begin_layout Standard
27471 Here are a few guidelines that will help the compiler generate more efficient
27472  code, some of the tips are specific to this compiler others are generally
27473  good programming practice.
27474 \end_layout
27475
27476 \begin_layout Itemize
27477 Use the smallest data type to represent your data-value.
27478  If it is known in advance that the value is going to be less than 256 then
27479  use an 'unsigned char' instead of a 'short' or 'int'.
27480  Please note, that ANSI C requires both signed and unsigned chars to be
27481  promoted to 'signed int'
27482 \begin_inset LatexCommand \index{promotion to signed int}
27483
27484 \end_inset
27485
27486
27487 \begin_inset Marginal
27488 status collapsed
27489
27490 \begin_layout Standard
27491
27492 \series bold
27493 \InsetSpace ~
27494 !
27495 \end_layout
27496
27497 \end_inset
27498
27499  before doing any operation.
27500  This promotion
27501 \begin_inset LatexCommand \index{type promotion}
27502
27503 \end_inset
27504
27505
27506 \begin_inset LatexCommand \label{type promotion}
27507
27508 \end_inset
27509
27510  can be omitted, if the result is the same.
27511  The effect of the promotion rules together with the sign-extension is often
27512  surprising:
27513 \end_layout
27514
27515 \begin_deeper
27516 \begin_layout Verse
27517
27518 \family typewriter
27519 unsigned char uc = 0xfe;
27520 \newline
27521 if (uc * uc < 0) /* this is true! */
27522 \newline
27523 {
27524 \newline
27525 \InsetSpace ~
27526 \InsetSpace ~
27527 \InsetSpace ~
27528 \InsetSpace ~
27529 ....
27530 \newline
27531 }
27532 \end_layout
27533
27534 \begin_layout Standard
27535
27536 \family typewriter
27537 uc * uc
27538 \family default
27539  is evaluated as 
27540 \family typewriter
27541 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
27542 \family default
27543 .
27544  
27545 \newline
27546 Another one:
27547 \end_layout
27548
27549 \begin_layout Verse
27550
27551 \family typewriter
27552 (unsigned char) -12 / (signed char) -3 = ...
27553 \end_layout
27554
27555 \begin_layout Standard
27556 No, the result is not 4:
27557 \end_layout
27558
27559 \begin_layout Verse
27560
27561 \family typewriter
27562 (int) (unsigned char) -12 / (int) (signed char) -3 =
27563 \newline
27564 (int) (unsigned char)
27565  0xf4 / (int) (signed char) 0xfd =
27566 \newline
27567 (int) 0x00f4 / (int) 0xfffd =
27568 \newline
27569 (int) 0x00f4
27570  / (int) 0xfffd =
27571 \newline
27572 (int) 244 / (int) -3 =
27573 \newline
27574 (int) -81 = (int) 0xffaf;
27575 \end_layout
27576
27577 \begin_layout Standard
27578 Don't complain, that gcc gives you a different result.
27579  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
27580  Therefore the results are different.
27581 \newline
27582 From 
27583 \begin_inset Quotes sld
27584 \end_inset
27585
27586 comp.lang.c FAQ
27587 \begin_inset Quotes srd
27588 \end_inset
27589
27590 :
27591 \end_layout
27592
27593 \begin_layout Quote
27594
27595 \emph on
27596 If well-defined overflow characteristics are important and negative values
27597  are not, or if you want to steer clear of sign-extension problems when
27598  manipulating bits or bytes, use one of the corresponding unsigned types.
27599  (Beware when mixing signed and unsigned values in expressions, though.)
27600 \newline
27601 Although
27602  character types (especially unsigned char) can be used as "tiny" integers,
27603  doing so is sometimes more trouble than it's worth, due to unpredictable
27604  sign extension and increased code size.
27605 \end_layout
27606
27607 \end_deeper
27608 \begin_layout Itemize
27609 Use unsigned when it is known in advance that the value is not going to
27610  be negative.
27611  This helps especially if you are doing division or multiplication, bit-shifting
27612  or are using an array index.
27613 \end_layout
27614
27615 \begin_layout Itemize
27616 NEVER jump into a LOOP.
27617 \end_layout
27618
27619 \begin_layout Itemize
27620 Declare the variables to be local
27621 \begin_inset LatexCommand \index{local variables}
27622
27623 \end_inset
27624
27625  whenever possible, especially loop control variables (induction).
27626 \end_layout
27627
27628 \begin_layout Itemize
27629 Have a look at the assembly listing to get a 
27630 \begin_inset Quotes sld
27631 \end_inset
27632
27633 feeling
27634 \begin_inset Quotes srd
27635 \end_inset
27636
27637  for the code generation.
27638 \end_layout
27639
27640 \begin_layout Section
27641 Porting code from or to other compilers
27642 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
27643
27644 \end_inset
27645
27646
27647 \end_layout
27648
27649 \begin_layout Itemize
27650 check whether endianness of the compilers differs and adapt where needed.
27651 \end_layout
27652
27653 \begin_layout Itemize
27654 check the device specific header files
27655 \begin_inset LatexCommand \index{Header files}
27656
27657 \end_inset
27658
27659
27660 \begin_inset LatexCommand \index{Include files}
27661
27662 \end_inset
27663
27664  for compiler specific syntax.
27665  Eventually include the file <compiler.h
27666 \begin_inset LatexCommand \index{compiler.h (include file)}
27667
27668 \end_inset
27669
27670
27671 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
27672
27673 \end_inset
27674
27675  to allow using common header files.
27676  (see f.e.
27677  cc2510fx.h 
27678 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
27679
27680 \end_inset
27681
27682 ).
27683 \end_layout
27684
27685 \begin_layout Itemize
27686 check whether the startup code contains the correct initialization (watchdog,
27687  peripherals).
27688 \end_layout
27689
27690 \begin_layout Itemize
27691 check whether the sizes of short, int, long match.
27692 \end_layout
27693
27694 \begin_layout Itemize
27695 check if some 16 or 32 bit hardware registers require a specific addressing
27696  order (least significant or most significant byte first) and adapt if needed
27697  (
27698 \emph on
27699 first
27700 \emph default
27701  and 
27702 \emph on
27703 last
27704 \emph default
27705  relate to time and not to lower/upper memory location here, so this is
27706  
27707 \emph on
27708 not
27709 \emph default
27710  the same as endianness).
27711 \end_layout
27712
27713 \begin_layout Itemize
27714 check whether the keyword 
27715 \emph on
27716 volatile
27717 \emph default
27718  is used where needed.
27719  The compilers might differ in their optimization characteristics (as different
27720  versions of the same compiler might also use more clever optimizations
27721  this is good idea anyway).
27722  See section 
27723 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
27724
27725 \end_inset
27726
27727 .
27728 \end_layout
27729
27730 \begin_layout Itemize
27731 check that the compilers are not told to supress warnings.
27732 \end_layout
27733
27734 \begin_layout Itemize
27735 check and convert compiler specific extensions (interrupts, memory areas,
27736  pragmas etc.).
27737 \end_layout
27738
27739 \begin_layout Itemize
27740 check for differences in type promotion.
27741  Especially check for math operations on 
27742 \family typewriter
27743 char
27744 \family default
27745  or 
27746 \family typewriter
27747 unsigned char
27748 \family default
27749  variables.
27750  For the sake of C99 compatibility SDCC will probably promote these to 
27751 \family typewriter
27752 int
27753 \family default
27754  more often than other compilers.
27755  Eventually insert explicit casts to 
27756 \family typewriter
27757 (char) 
27758 \family default
27759 or
27760 \family typewriter
27761  (unsigned char)
27762 \family default
27763 .
27764  Also check that the ~\InsetSpace ~
27765 operator
27766 \begin_inset LatexCommand \index{\~\/ Operator}
27767
27768 \end_inset
27769
27770  is not used on 
27771 \family typewriter
27772 bit
27773 \begin_inset LatexCommand \index{bit}
27774
27775 \end_inset
27776
27777
27778 \family default
27779  variables, use the !\InsetSpace ~
27780 operator instead.
27781  See sections 
27782 \begin_inset LatexCommand \ref{type promotion}
27783
27784 \end_inset
27785
27786  and 
27787 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
27788
27789 \end_inset
27790
27791 .
27792 \end_layout
27793
27794 \begin_layout Itemize
27795 check the assembly code generated for interrupt routines (f.e.
27796  for calls to possibly non-reentrant library functions).
27797 \end_layout
27798
27799 \begin_layout Itemize
27800 check whether timing loops result in proper timing (or preferably consider
27801  a rewrite of the code with timer based delays instead).
27802 \end_layout
27803
27804 \begin_layout Itemize
27805 check for differences in printf parameters (some compilers push (va_arg
27806 \begin_inset LatexCommand \index{vararg, va\_arg}
27807
27808 \end_inset
27809
27810 ) char variables as 
27811 \family typewriter
27812 int
27813 \family default
27814  others push them as 
27815 \family typewriter
27816 char
27817 \family default
27818 .
27819  See section 
27820 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
27821
27822 \end_inset
27823
27824 ).
27825 \end_layout
27826
27827 \begin_layout Itemize
27828 check the resulting memory map
27829 \begin_inset LatexCommand \index{Memory map}
27830
27831 \end_inset
27832
27833 .
27834  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
27835 ly idata, pdata, xdata).
27836  Eventually check if unexpected library functions are included.
27837 \end_layout
27838
27839 \begin_layout Section
27840 Tools
27841 \begin_inset LatexCommand \index{Tools}
27842
27843 \end_inset
27844
27845  included in the distribution
27846 \end_layout
27847
27848 \begin_layout Standard
27849 \align left
27850 \begin_inset Tabular
27851 <lyxtabular version="3" rows="12" columns="3">
27852 <features>
27853 <column alignment="left" valignment="top" leftline="true" width="0pt">
27854 <column alignment="left" valignment="top" leftline="true" width="0pt">
27855 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27856 <row topline="true" bottomline="true">
27857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27858 \begin_inset Text
27859
27860 \begin_layout Standard
27861
27862 \series bold
27863 Name
27864 \end_layout
27865
27866 \end_inset
27867 </cell>
27868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27869 \begin_inset Text
27870
27871 \begin_layout Standard
27872
27873 \series bold
27874 Purpose
27875 \end_layout
27876
27877 \end_inset
27878 </cell>
27879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27880 \begin_inset Text
27881
27882 \begin_layout Standard
27883
27884 \series bold
27885 Directory
27886 \end_layout
27887
27888 \end_inset
27889 </cell>
27890 </row>
27891 <row topline="true">
27892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27893 \begin_inset Text
27894
27895 \begin_layout Standard
27896 uCsim
27897 \begin_inset LatexCommand \index{uCsim}
27898
27899 \end_inset
27900
27901
27902 \end_layout
27903
27904 \end_inset
27905 </cell>
27906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27907 \begin_inset Text
27908
27909 \begin_layout Standard
27910 Simulator for various architectures
27911 \end_layout
27912
27913 \end_inset
27914 </cell>
27915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27916 \begin_inset Text
27917
27918 \begin_layout Standard
27919 sdcc/sim/ucsim
27920 \end_layout
27921
27922 \end_inset
27923 </cell>
27924 </row>
27925 <row topline="true">
27926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27927 \begin_inset Text
27928
27929 \begin_layout Standard
27930 keil2sdcc.pl
27931 \end_layout
27932
27933 \end_inset
27934 </cell>
27935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27936 \begin_inset Text
27937
27938 \begin_layout Standard
27939 header file
27940 \begin_inset LatexCommand \index{Header files}
27941
27942 \end_inset
27943
27944
27945 \begin_inset LatexCommand \index{Include files}
27946
27947 \end_inset
27948
27949  conversion
27950 \end_layout
27951
27952 \end_inset
27953 </cell>
27954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27955 \begin_inset Text
27956
27957 \begin_layout Standard
27958 sdcc/support/scripts
27959 \end_layout
27960
27961 \end_inset
27962 </cell>
27963 </row>
27964 <row topline="true">
27965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27966 \begin_inset Text
27967
27968 \begin_layout Standard
27969 mh2h.c
27970 \end_layout
27971
27972 \end_inset
27973 </cell>
27974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27975 \begin_inset Text
27976
27977 \begin_layout Standard
27978 header file conversion
27979 \end_layout
27980
27981 \end_inset
27982 </cell>
27983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27984 \begin_inset Text
27985
27986 \begin_layout Standard
27987 sdcc/support/scripts
27988 \end_layout
27989
27990 \end_inset
27991 </cell>
27992 </row>
27993 <row topline="true">
27994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27995 \begin_inset Text
27996
27997 \begin_layout Standard
27998 as-gbz80
27999 \end_layout
28000
28001 \end_inset
28002 </cell>
28003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28004 \begin_inset Text
28005
28006 \begin_layout Standard
28007 Assembler
28008 \end_layout
28009
28010 \end_inset
28011 </cell>
28012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28013 \begin_inset Text
28014
28015 \begin_layout Standard
28016
28017 \family roman
28018 \series medium
28019 \shape up
28020 \size normal
28021 \emph off
28022 \bar no
28023 \noun off
28024 \color none
28025 sdcc/bin
28026 \end_layout
28027
28028 \end_inset
28029 </cell>
28030 </row>
28031 <row topline="true">
28032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28033 \begin_inset Text
28034
28035 \begin_layout Standard
28036 as-z80
28037 \end_layout
28038
28039 \end_inset
28040 </cell>
28041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28042 \begin_inset Text
28043
28044 \begin_layout Standard
28045 Assembler
28046 \end_layout
28047
28048 \end_inset
28049 </cell>
28050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28051 \begin_inset Text
28052
28053 \begin_layout Standard
28054
28055 \family roman
28056 \series medium
28057 \shape up
28058 \size normal
28059 \emph off
28060 \bar no
28061 \noun off
28062 \color none
28063 sdcc/bin
28064 \end_layout
28065
28066 \end_inset
28067 </cell>
28068 </row>
28069 <row topline="true">
28070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28071 \begin_inset Text
28072
28073 \begin_layout Standard
28074 asx8051
28075 \end_layout
28076
28077 \end_inset
28078 </cell>
28079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28080 \begin_inset Text
28081
28082 \begin_layout Standard
28083 Assembler
28084 \end_layout
28085
28086 \end_inset
28087 </cell>
28088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28089 \begin_inset Text
28090
28091 \begin_layout Standard
28092
28093 \family roman
28094 \series medium
28095 \shape up
28096 \size normal
28097 \emph off
28098 \bar no
28099 \noun off
28100 \color none
28101 sdcc/bin
28102 \end_layout
28103
28104 \end_inset
28105 </cell>
28106 </row>
28107 <row topline="true">
28108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28109 \begin_inset Text
28110
28111 \begin_layout Standard
28112 SDCDB
28113 \end_layout
28114
28115 \end_inset
28116 </cell>
28117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28118 \begin_inset Text
28119
28120 \begin_layout Standard
28121 Simulator
28122 \end_layout
28123
28124 \end_inset
28125 </cell>
28126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28127 \begin_inset Text
28128
28129 \begin_layout Standard
28130
28131 \family roman
28132 \series medium
28133 \shape up
28134 \size normal
28135 \emph off
28136 \bar no
28137 \noun off
28138 \color none
28139 sdcc/bin
28140 \end_layout
28141
28142 \end_inset
28143 </cell>
28144 </row>
28145 <row topline="true">
28146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28147 \begin_inset Text
28148
28149 \begin_layout Standard
28150 aslink
28151 \end_layout
28152
28153 \end_inset
28154 </cell>
28155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28156 \begin_inset Text
28157
28158 \begin_layout Standard
28159 Linker
28160 \end_layout
28161
28162 \end_inset
28163 </cell>
28164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28165 \begin_inset Text
28166
28167 \begin_layout Standard
28168
28169 \family roman
28170 \series medium
28171 \shape up
28172 \size normal
28173 \emph off
28174 \bar no
28175 \noun off
28176 \color none
28177 sdcc/bin
28178 \end_layout
28179
28180 \end_inset
28181 </cell>
28182 </row>
28183 <row topline="true">
28184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28185 \begin_inset Text
28186
28187 \begin_layout Standard
28188 link-z80
28189 \end_layout
28190
28191 \end_inset
28192 </cell>
28193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28194 \begin_inset Text
28195
28196 \begin_layout Standard
28197 Linker
28198 \end_layout
28199
28200 \end_inset
28201 </cell>
28202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28203 \begin_inset Text
28204
28205 \begin_layout Standard
28206
28207 \family roman
28208 \series medium
28209 \shape up
28210 \size normal
28211 \emph off
28212 \bar no
28213 \noun off
28214 \color none
28215 sdcc/bin
28216 \end_layout
28217
28218 \end_inset
28219 </cell>
28220 </row>
28221 <row topline="true">
28222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28223 \begin_inset Text
28224
28225 \begin_layout Standard
28226 link-gbz80
28227 \end_layout
28228
28229 \end_inset
28230 </cell>
28231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28232 \begin_inset Text
28233
28234 \begin_layout Standard
28235 Linker
28236 \end_layout
28237
28238 \end_inset
28239 </cell>
28240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28241 \begin_inset Text
28242
28243 \begin_layout Standard
28244
28245 \family roman
28246 \series medium
28247 \shape up
28248 \size normal
28249 \emph off
28250 \bar no
28251 \noun off
28252 \color none
28253 sdcc/bin
28254 \end_layout
28255
28256 \end_inset
28257 </cell>
28258 </row>
28259 <row topline="true" bottomline="true">
28260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28261 \begin_inset Text
28262
28263 \begin_layout Standard
28264 packihx
28265 \end_layout
28266
28267 \end_inset
28268 </cell>
28269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28270 \begin_inset Text
28271
28272 \begin_layout Standard
28273 Intel Hex packer 
28274 \begin_inset LatexCommand \index{packihx (tool)}
28275
28276 \end_inset
28277
28278
28279 \end_layout
28280
28281 \end_inset
28282 </cell>
28283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28284 \begin_inset Text
28285
28286 \begin_layout Standard
28287
28288 \family roman
28289 \series medium
28290 \shape up
28291 \size normal
28292 \emph off
28293 \bar no
28294 \noun off
28295 \color none
28296 sdcc/bin
28297 \end_layout
28298
28299 \end_inset
28300 </cell>
28301 </row>
28302 </lyxtabular>
28303
28304 \end_inset
28305
28306
28307 \newline
28308
28309 \end_layout
28310
28311 \begin_layout Section
28312 Documentation
28313 \begin_inset LatexCommand \index{Documentation}
28314
28315 \end_inset
28316
28317  included in the distribution
28318 \end_layout
28319
28320 \begin_layout Standard
28321 \align left
28322 \begin_inset Tabular
28323 <lyxtabular version="3" rows="10" columns="2">
28324 <features>
28325 <column alignment="block" valignment="top" leftline="true" width="40col%">
28326 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
28327 <row topline="true" bottomline="true" endhead="true">
28328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28329 \begin_inset Text
28330
28331 \begin_layout Standard
28332
28333 \series bold
28334 Subject / Title
28335 \end_layout
28336
28337 \end_inset
28338 </cell>
28339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28340 \begin_inset Text
28341
28342 \begin_layout Standard
28343
28344 \series bold
28345 Filename / Where to get
28346 \end_layout
28347
28348 \end_inset
28349 </cell>
28350 </row>
28351 <row topline="true">
28352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28353 \begin_inset Text
28354
28355 \begin_layout Standard
28356 SDCC Compiler User Guide
28357 \end_layout
28358
28359 \end_inset
28360 </cell>
28361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28362 \begin_inset Text
28363
28364 \begin_layout Standard
28365 You're reading it right now
28366 \emph on
28367  \InsetSpace ~
28368 \InsetSpace ~
28369 \InsetSpace ~
28370
28371 \hfill
28372 online at:
28373 \emph default
28374
28375 \newline
28376
28377 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
28378
28379 \end_inset
28380
28381
28382 \end_layout
28383
28384 \end_inset
28385 </cell>
28386 </row>
28387 <row topline="true">
28388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28389 \begin_inset Text
28390
28391 \begin_layout Standard
28392 Changelog of SDCC
28393 \end_layout
28394
28395 \end_inset
28396 </cell>
28397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28398 \begin_inset Text
28399
28400 \begin_layout Standard
28401 sdcc/Changelog
28402 \emph on
28403  \InsetSpace ~
28404 \InsetSpace ~
28405 \InsetSpace ~
28406
28407 \hfill
28408 online at:
28409 \emph default
28410
28411 \newline
28412
28413 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28414
28415 \end_inset
28416
28417
28418 \end_layout
28419
28420 \end_inset
28421 </cell>
28422 </row>
28423 <row topline="true">
28424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28425 \begin_inset Text
28426
28427 \begin_layout Standard
28428 ASXXXX
28429 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
28430
28431 \end_inset
28432
28433
28434 \begin_inset LatexCommand \index{Assembler documentation}
28435
28436 \end_inset
28437
28438  Assemblers and
28439 \newline
28440 ASLINK
28441 \begin_inset LatexCommand \index{aslink}
28442
28443 \end_inset
28444
28445
28446 \begin_inset LatexCommand \index{Linker documentation}
28447
28448 \end_inset
28449
28450  Relocating Linker
28451 \end_layout
28452
28453 \end_inset
28454 </cell>
28455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28456 \begin_inset Text
28457
28458 \begin_layout Standard
28459 sdcc/as/doc/asxhtm.html 
28460 \emph on
28461 \InsetSpace ~
28462 \InsetSpace ~
28463 \InsetSpace ~
28464
28465 \hfill
28466 online at:
28467 \emph default
28468
28469 \newline
28470
28471 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
28472
28473 \end_inset
28474
28475
28476 \end_layout
28477
28478 \end_inset
28479 </cell>
28480 </row>
28481 <row topline="true">
28482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28483 \begin_inset Text
28484
28485 \begin_layout Standard
28486 SDCC regression test
28487 \begin_inset LatexCommand \index{Regression test}
28488
28489 \end_inset
28490
28491
28492 \end_layout
28493
28494 \end_inset
28495 </cell>
28496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28497 \begin_inset Text
28498
28499 \begin_layout Standard
28500 sdcc/doc/test_suite_spec.pdf 
28501 \emph on
28502 \InsetSpace ~
28503 \InsetSpace ~
28504 \InsetSpace ~
28505
28506 \hfill
28507 online at:
28508 \emph default
28509
28510 \newline
28511
28512 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28513
28514 \end_inset
28515
28516
28517 \end_layout
28518
28519 \end_inset
28520 </cell>
28521 </row>
28522 <row topline="true">
28523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28524 \begin_inset Text
28525
28526 \begin_layout Standard
28527 Various notes
28528 \end_layout
28529
28530 \end_inset
28531 </cell>
28532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28533 \begin_inset Text
28534
28535 \begin_layout Standard
28536 sdcc/doc/* 
28537 \emph on
28538 \InsetSpace ~
28539 \InsetSpace ~
28540 \InsetSpace ~
28541
28542 \hfill
28543 online at:
28544 \emph default
28545
28546 \newline
28547
28548 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
28549
28550 \end_inset
28551
28552
28553 \end_layout
28554
28555 \end_inset
28556 </cell>
28557 </row>
28558 <row topline="true">
28559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28560 \begin_inset Text
28561
28562 \begin_layout Standard
28563 Notes on debugging with SDCDB
28564 \begin_inset LatexCommand \index{SDCDB (debugger)}
28565
28566 \end_inset
28567
28568
28569 \end_layout
28570
28571 \end_inset
28572 </cell>
28573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28574 \begin_inset Text
28575
28576 \begin_layout Standard
28577 sdcc/debugger/README 
28578 \emph on
28579 \InsetSpace ~
28580 \InsetSpace ~
28581 \InsetSpace ~
28582
28583 \hfill
28584 online at
28585 \emph default
28586 :
28587 \newline
28588
28589 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
28590
28591 \end_inset
28592
28593
28594 \end_layout
28595
28596 \end_inset
28597 </cell>
28598 </row>
28599 <row topline="true">
28600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28601 \begin_inset Text
28602
28603 \begin_layout Standard
28604 uCsim
28605 \begin_inset LatexCommand \index{uCsim}
28606
28607 \end_inset
28608
28609  Software simulator for microcontrollers
28610 \end_layout
28611
28612 \end_inset
28613 </cell>
28614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28615 \begin_inset Text
28616
28617 \begin_layout Standard
28618
28619 \family roman
28620 \series medium
28621 \shape up
28622 \size normal
28623 \emph off
28624 \bar no
28625 \noun off
28626 \color none
28627 sdcc/sim/ucsim/doc
28628 \family default
28629 \series default
28630 \shape default
28631 \size default
28632 \emph default
28633 \bar default
28634 \noun default
28635 /index.html 
28636 \emph on
28637 \InsetSpace ~
28638 \InsetSpace ~
28639 \InsetSpace ~
28640
28641 \hfill
28642 online at:
28643 \emph default
28644
28645 \newline
28646
28647 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
28648
28649 \end_inset
28650
28651
28652 \end_layout
28653
28654 \end_inset
28655 </cell>
28656 </row>
28657 <row topline="true">
28658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28659 \begin_inset Text
28660
28661 \begin_layout Standard
28662 Temporary notes on the pic16
28663 \begin_inset LatexCommand \index{PIC16}
28664
28665 \end_inset
28666
28667  port
28668 \end_layout
28669
28670 \end_inset
28671 </cell>
28672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28673 \begin_inset Text
28674
28675 \begin_layout Standard
28676 sdcc/src/pic16/NOTES 
28677 \emph on
28678 \InsetSpace ~
28679 \InsetSpace ~
28680 \InsetSpace ~
28681
28682 \hfill
28683 online at:
28684 \newline
28685
28686 \emph default
28687
28688 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
28689
28690 \end_inset
28691
28692
28693 \end_layout
28694
28695 \end_inset
28696 </cell>
28697 </row>
28698 <row topline="true" bottomline="true">
28699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28700 \begin_inset Text
28701
28702 \begin_layout Standard
28703 SDCC internal documentation (debugging file format)
28704 \end_layout
28705
28706 \end_inset
28707 </cell>
28708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28709 \begin_inset Text
28710
28711 \begin_layout Standard
28712 sdcc/doc/
28713 \family roman
28714 \series medium
28715 \shape up
28716 \size normal
28717 \emph off
28718 \bar no
28719 \noun off
28720 \color none
28721 cdbfileformat.pd
28722 \family default
28723 \series default
28724 \shape default
28725 \size default
28726 \emph default
28727 \bar default
28728 \noun default
28729 f
28730 \emph on
28731  \InsetSpace ~
28732 \InsetSpace ~
28733 \InsetSpace ~
28734
28735 \hfill
28736 online at:
28737 \emph default
28738
28739 \newline
28740
28741 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
28742
28743 \end_inset
28744
28745
28746 \end_layout
28747
28748 \end_inset
28749 </cell>
28750 </row>
28751 </lyxtabular>
28752
28753 \end_inset
28754
28755
28756 \newline
28757
28758 \end_layout
28759
28760 \begin_layout Section
28761 Related open source tools
28762 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
28763
28764 \end_inset
28765
28766
28767 \begin_inset LatexCommand \index{Related tools}
28768
28769 \end_inset
28770
28771
28772 \end_layout
28773
28774 \begin_layout Standard
28775 \align left
28776 \begin_inset Tabular
28777 <lyxtabular version="3" rows="14" columns="3">
28778 <features>
28779 <column alignment="left" valignment="top" leftline="true" width="0pt">
28780 <column alignment="block" valignment="top" leftline="true" width="30line%">
28781 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28782 <row topline="true" bottomline="true">
28783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28784 \begin_inset Text
28785
28786 \begin_layout Standard
28787
28788 \series bold
28789 Name
28790 \end_layout
28791
28792 \end_inset
28793 </cell>
28794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28795 \begin_inset Text
28796
28797 \begin_layout Standard
28798
28799 \series bold
28800 Purpose
28801 \end_layout
28802
28803 \end_inset
28804 </cell>
28805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28806 \begin_inset Text
28807
28808 \begin_layout Standard
28809
28810 \series bold
28811 Where to get
28812 \end_layout
28813
28814 \end_inset
28815 </cell>
28816 </row>
28817 <row topline="true">
28818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28819 \begin_inset Text
28820
28821 \begin_layout Standard
28822 gpsim
28823 \begin_inset LatexCommand \index{gpsim (pic simulator)}
28824
28825 \end_inset
28826
28827
28828 \end_layout
28829
28830 \end_inset
28831 </cell>
28832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28833 \begin_inset Text
28834
28835 \begin_layout Standard
28836 PIC simulator
28837 \end_layout
28838
28839 \end_inset
28840 </cell>
28841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28842 \begin_inset Text
28843
28844 \begin_layout Standard
28845 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
28846
28847 \end_inset
28848
28849
28850 \end_layout
28851
28852 \end_inset
28853 </cell>
28854 </row>
28855 <row topline="true">
28856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28857 \begin_inset Text
28858
28859 \begin_layout Standard
28860 gputils
28861 \begin_inset LatexCommand \index{gputils (pic tools)}
28862
28863 \end_inset
28864
28865
28866 \end_layout
28867
28868 \end_inset
28869 </cell>
28870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28871 \begin_inset Text
28872
28873 \begin_layout Standard
28874 GNU PIC utilities
28875 \end_layout
28876
28877 \end_inset
28878 </cell>
28879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28880 \begin_inset Text
28881
28882 \begin_layout Standard
28883 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
28884
28885 \end_inset
28886
28887
28888 \end_layout
28889
28890 \end_inset
28891 </cell>
28892 </row>
28893 <row topline="true">
28894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28895 \begin_inset Text
28896
28897 \begin_layout Standard
28898 flP5
28899 \end_layout
28900
28901 \end_inset
28902 </cell>
28903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28904 \begin_inset Text
28905
28906 \begin_layout Standard
28907 PIC programmer
28908 \end_layout
28909
28910 \end_inset
28911 </cell>
28912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28913 \begin_inset Text
28914
28915 \begin_layout Standard
28916 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
28917
28918 \end_inset
28919
28920
28921 \end_layout
28922
28923 \end_inset
28924 </cell>
28925 </row>
28926 <row topline="true">
28927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28928 \begin_inset Text
28929
28930 \begin_layout Standard
28931 ec2drv/newcdb
28932 \end_layout
28933
28934 \end_inset
28935 </cell>
28936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28937 \begin_inset Text
28938
28939 \begin_layout Standard
28940 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
28941  (Unix only)
28942 \end_layout
28943
28944 \end_inset
28945 </cell>
28946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28947 \begin_inset Text
28948
28949 \begin_layout Standard
28950 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
28951
28952 \end_inset
28953
28954
28955 \end_layout
28956
28957 \end_inset
28958 </cell>
28959 </row>
28960 <row topline="true">
28961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28962 \begin_inset Text
28963
28964 \begin_layout Standard
28965 indent
28966 \begin_inset LatexCommand \index{indent (source formatting tool)}
28967
28968 \end_inset
28969
28970
28971 \end_layout
28972
28973 \end_inset
28974 </cell>
28975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28976 \begin_inset Text
28977
28978 \begin_layout Standard
28979 Formats C source - Master of the white spaces
28980 \end_layout
28981
28982 \end_inset
28983 </cell>
28984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28985 \begin_inset Text
28986
28987 \begin_layout Standard
28988 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
28989
28990 \end_inset
28991
28992
28993 \end_layout
28994
28995 \end_inset
28996 </cell>
28997 </row>
28998 <row topline="true">
28999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29000 \begin_inset Text
29001
29002 \begin_layout Standard
29003 srecord
29004 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
29005
29006 \end_inset
29007
29008
29009 \end_layout
29010
29011 \end_inset
29012 </cell>
29013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29014 \begin_inset Text
29015
29016 \begin_layout Standard
29017 Object file conversion, checksumming, ...
29018 \end_layout
29019
29020 \end_inset
29021 </cell>
29022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29023 \begin_inset Text
29024
29025 \begin_layout Standard
29026 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
29027
29028 \end_inset
29029
29030
29031 \end_layout
29032
29033 \end_inset
29034 </cell>
29035 </row>
29036 <row topline="true">
29037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29038 \begin_inset Text
29039
29040 \begin_layout Standard
29041 objdump
29042 \begin_inset LatexCommand \index{objdump (tool)}
29043
29044 \end_inset
29045
29046
29047 \end_layout
29048
29049 \end_inset
29050 </cell>
29051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29052 \begin_inset Text
29053
29054 \begin_layout Standard
29055 Object file conversion, ...
29056 \end_layout
29057
29058 \end_inset
29059 </cell>
29060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29061 \begin_inset Text
29062
29063 \begin_layout Standard
29064 Part of binutils (should be there anyway)
29065 \end_layout
29066
29067 \end_inset
29068 </cell>
29069 </row>
29070 <row topline="true">
29071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29072 \begin_inset Text
29073
29074 \begin_layout Standard
29075 cmon51
29076 \end_layout
29077
29078 \end_inset
29079 </cell>
29080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29081 \begin_inset Text
29082
29083 \begin_layout Standard
29084 8051 monitor (hex up-/download, single step, disassemble)
29085 \end_layout
29086
29087 \end_inset
29088 </cell>
29089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29090 \begin_inset Text
29091
29092 \begin_layout Standard
29093 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
29094
29095 \end_inset
29096
29097
29098 \end_layout
29099
29100 \end_inset
29101 </cell>
29102 </row>
29103 <row topline="true">
29104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29105 \begin_inset Text
29106
29107 \begin_layout Standard
29108 doxygen
29109 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
29110
29111 \end_inset
29112
29113
29114 \end_layout
29115
29116 \end_inset
29117 </cell>
29118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29119 \begin_inset Text
29120
29121 \begin_layout Standard
29122 Source code documentation system
29123 \end_layout
29124
29125 \end_inset
29126 </cell>
29127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29128 \begin_inset Text
29129
29130 \begin_layout Standard
29131 \begin_inset LatexCommand \url{http://www.doxygen.org}
29132
29133 \end_inset
29134
29135
29136 \end_layout
29137
29138 \end_inset
29139 </cell>
29140 </row>
29141 <row topline="true">
29142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29143 \begin_inset Text
29144
29145 \begin_layout Standard
29146 kdevelop
29147 \end_layout
29148
29149 \end_inset
29150 </cell>
29151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29152 \begin_inset Text
29153
29154 \begin_layout Standard
29155 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
29156 \end_layout
29157
29158 \end_inset
29159 </cell>
29160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29161 \begin_inset Text
29162
29163 \begin_layout Standard
29164 \begin_inset LatexCommand \url{http://www.kdevelop.org}
29165
29166 \end_inset
29167
29168
29169 \end_layout
29170
29171 \end_inset
29172 </cell>
29173 </row>
29174 <row topline="true">
29175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29176 \begin_inset Text
29177
29178 \begin_layout Standard
29179 paulmon
29180 \end_layout
29181
29182 \end_inset
29183 </cell>
29184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29185 \begin_inset Text
29186
29187 \begin_layout Standard
29188 8051 monitor (hex up-/download, single step, disassemble)
29189 \end_layout
29190
29191 \end_inset
29192 </cell>
29193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29194 \begin_inset Text
29195
29196 \begin_layout Standard
29197 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
29198
29199 \end_inset
29200
29201
29202 \end_layout
29203
29204 \end_inset
29205 </cell>
29206 </row>
29207 <row topline="true">
29208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29209 \begin_inset Text
29210
29211 \begin_layout Standard
29212 splint
29213 \begin_inset LatexCommand \index{splint (syntax checking tool)}
29214
29215 \end_inset
29216
29217
29218 \end_layout
29219
29220 \end_inset
29221 </cell>
29222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29223 \begin_inset Text
29224
29225 \begin_layout Standard
29226 Statically checks c sources (see 
29227 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
29228
29229 \end_inset
29230
29231 )
29232 \end_layout
29233
29234 \end_inset
29235 </cell>
29236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29237 \begin_inset Text
29238
29239 \begin_layout Standard
29240 \begin_inset LatexCommand \url{http://www.splint.org}
29241
29242 \end_inset
29243
29244
29245 \end_layout
29246
29247 \end_inset
29248 </cell>
29249 </row>
29250 <row topline="true" bottomline="true">
29251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29252 \begin_inset Text
29253
29254 \begin_layout Standard
29255 ddd
29256 \begin_inset LatexCommand \index{DDD (debugger)}
29257
29258 \end_inset
29259
29260
29261 \end_layout
29262
29263 \end_inset
29264 </cell>
29265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29266 \begin_inset Text
29267
29268 \begin_layout Standard
29269 Debugger, serves nicely as GUI to SDCDB
29270 \begin_inset LatexCommand \index{SDCDB (debugger)}
29271
29272 \end_inset
29273
29274  (Unix only)
29275 \end_layout
29276
29277 \end_inset
29278 </cell>
29279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29280 \begin_inset Text
29281
29282 \begin_layout Standard
29283 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
29284
29285 \end_inset
29286
29287
29288 \end_layout
29289
29290 \end_inset
29291 </cell>
29292 </row>
29293 </lyxtabular>
29294
29295 \end_inset
29296
29297
29298 \newline
29299
29300 \end_layout
29301
29302 \begin_layout Section
29303 Related documentation / recommended reading
29304 \end_layout
29305
29306 \begin_layout Standard
29307 \align left
29308 \begin_inset Tabular
29309 <lyxtabular version="3" rows="7" columns="3">
29310 <features>
29311 <column alignment="left" valignment="top" leftline="true" width="0pt">
29312 <column alignment="left" valignment="top" leftline="true" width="0">
29313 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29314 <row topline="true" bottomline="true">
29315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29316 \begin_inset Text
29317
29318 \begin_layout Standard
29319
29320 \series bold
29321 Name
29322 \end_layout
29323
29324 \end_inset
29325 </cell>
29326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29327 \begin_inset Text
29328
29329 \begin_layout Standard
29330
29331 \series bold
29332 Subject / Title
29333 \end_layout
29334
29335 \end_inset
29336 </cell>
29337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29338 \begin_inset Text
29339
29340 \begin_layout Standard
29341
29342 \series bold
29343 Where to get
29344 \end_layout
29345
29346 \end_inset
29347 </cell>
29348 </row>
29349 <row topline="true">
29350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29351 \begin_inset Text
29352
29353 \begin_layout Standard
29354
29355 \family roman
29356 \series medium
29357 \shape up
29358 \size normal
29359 \emph off
29360 \bar no
29361 \noun off
29362 \color none
29363 c-refcard.pdf
29364 \end_layout
29365
29366 \end_inset
29367 </cell>
29368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29369 \begin_inset Text
29370
29371 \begin_layout Standard
29372 C Reference Card
29373 \begin_inset LatexCommand \index{C Reference card}
29374
29375 \end_inset
29376
29377 , 2 pages
29378 \end_layout
29379
29380 \end_inset
29381 </cell>
29382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29383 \begin_inset Text
29384
29385 \begin_layout Standard
29386 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
29387
29388 \end_inset
29389
29390
29391 \end_layout
29392
29393 \end_inset
29394 </cell>
29395 </row>
29396 <row topline="true">
29397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29398 \begin_inset Text
29399
29400 \begin_layout Standard
29401 c-faq
29402 \end_layout
29403
29404 \end_inset
29405 </cell>
29406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29407 \begin_inset Text
29408
29409 \begin_layout Standard
29410 C-FAQ
29411 \begin_inset LatexCommand \index{C FAQ}
29412
29413 \end_inset
29414
29415
29416 \end_layout
29417
29418 \end_inset
29419 </cell>
29420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29421 \begin_inset Text
29422
29423 \begin_layout Standard
29424 \begin_inset LatexCommand \url{http://www.c-faq.com}
29425
29426 \end_inset
29427
29428
29429 \end_layout
29430
29431 \end_inset
29432 </cell>
29433 </row>
29434 <row topline="true">
29435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29436 \begin_inset Text
29437
29438 \begin_layout Standard
29439 ISO/IEC 9899:TC2
29440 \end_layout
29441
29442 \end_inset
29443 </cell>
29444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29445 \begin_inset Text
29446
29447 \begin_layout Standard
29448 \begin_inset Quotes sld
29449 \end_inset
29450
29451 C-Standard
29452 \begin_inset Quotes srd
29453 \end_inset
29454
29455
29456 \end_layout
29457
29458 \end_inset
29459 </cell>
29460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29461 \begin_inset Text
29462
29463 \begin_layout Standard
29464
29465 \size footnotesize
29466 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29467
29468 \end_inset
29469
29470
29471 \end_layout
29472
29473 \end_inset
29474 </cell>
29475 </row>
29476 <row topline="true">
29477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29478 \begin_inset Text
29479
29480 \begin_layout Standard
29481 ISO/IEC DTR 18037
29482 \end_layout
29483
29484 \end_inset
29485 </cell>
29486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29487 \begin_inset Text
29488
29489 \begin_layout Standard
29490 \begin_inset Quotes sld
29491 \end_inset
29492
29493 Extensions for Embedded C
29494 \begin_inset Quotes srd
29495 \end_inset
29496
29497
29498 \end_layout
29499
29500 \end_inset
29501 </cell>
29502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29503 \begin_inset Text
29504
29505 \begin_layout Standard
29506
29507 \size footnotesize
29508 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
29509
29510 \end_inset
29511
29512
29513 \end_layout
29514
29515 \end_inset
29516 </cell>
29517 </row>
29518 <row topline="true">
29519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29520 \begin_inset Text
29521
29522 \begin_layout Standard
29523
29524 \end_layout
29525
29526 \end_inset
29527 </cell>
29528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29529 \begin_inset Text
29530
29531 \begin_layout Standard
29532 Latest datasheet of target CPU
29533 \end_layout
29534
29535 \end_inset
29536 </cell>
29537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29538 \begin_inset Text
29539
29540 \begin_layout Standard
29541 vendor
29542 \end_layout
29543
29544 \end_inset
29545 </cell>
29546 </row>
29547 <row topline="true" bottomline="true">
29548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29549 \begin_inset Text
29550
29551 \begin_layout Standard
29552
29553 \end_layout
29554
29555 \end_inset
29556 </cell>
29557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29558 \begin_inset Text
29559
29560 \begin_layout Standard
29561 Revision history of datasheet
29562 \end_layout
29563
29564 \end_inset
29565 </cell>
29566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29567 \begin_inset Text
29568
29569 \begin_layout Standard
29570 vendor
29571 \end_layout
29572
29573 \end_inset
29574 </cell>
29575 </row>
29576 </lyxtabular>
29577
29578 \end_inset
29579
29580
29581 \newline
29582
29583 \end_layout
29584
29585 \begin_layout Section
29586 Application notes specifically for SDCC
29587 \end_layout
29588
29589 \begin_layout Standard
29590 SDCC makes no claims about the completeness of this list and about up-to-datenes
29591 s or correctness of the application notes
29592 \begin_inset LatexCommand \index{Application notes}
29593
29594 \end_inset
29595
29596 .
29597 \end_layout
29598
29599 \begin_layout Standard
29600 \align left
29601
29602 \size footnotesize
29603 \begin_inset Tabular
29604 <lyxtabular version="3" rows="7" columns="3">
29605 <features>
29606 <column alignment="block" valignment="top" leftline="true" width="17col%">
29607 <column alignment="block" valignment="top" leftline="true" width="27col%">
29608 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
29609 <row topline="true" bottomline="true">
29610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29611 \begin_inset Text
29612
29613 \begin_layout Standard
29614
29615 \series bold
29616 \size footnotesize
29617 Vendor
29618 \end_layout
29619
29620 \end_inset
29621 </cell>
29622 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
29623 \begin_inset Text
29624
29625 \begin_layout Standard
29626
29627 \series bold
29628 \size footnotesize
29629 Subject / Title
29630 \end_layout
29631
29632 \end_inset
29633 </cell>
29634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29635 \begin_inset Text
29636
29637 \begin_layout Standard
29638
29639 \series bold
29640 \size footnotesize
29641 Where to get
29642 \end_layout
29643
29644 \end_inset
29645 </cell>
29646 </row>
29647 <row topline="true">
29648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29649 \begin_inset Text
29650
29651 \begin_layout Standard
29652
29653 \size footnotesize
29654 Maxim / Dallas
29655 \end_layout
29656
29657 \end_inset
29658 </cell>
29659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29660 \begin_inset Text
29661
29662 \begin_layout Standard
29663
29664 \size footnotesize
29665 Using the SDCC Compiler for the DS80C400
29666 \begin_inset LatexCommand \index{DS80C400}
29667
29668 \end_inset
29669
29670
29671 \end_layout
29672
29673 \end_inset
29674 </cell>
29675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29676 \begin_inset Text
29677
29678 \begin_layout Standard
29679
29680 \size footnotesize
29681 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
29682
29683 \end_inset
29684
29685
29686 \end_layout
29687
29688 \end_inset
29689 </cell>
29690 </row>
29691 <row topline="true">
29692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29693 \begin_inset Text
29694
29695 \begin_layout Standard
29696
29697 \size footnotesize
29698 Maxim / Dallas
29699 \end_layout
29700
29701 \end_inset
29702 </cell>
29703 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
29704 \begin_inset Text
29705
29706 \begin_layout Standard
29707
29708 \size footnotesize
29709 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
29710 \begin_inset LatexCommand \index{DS89C4x0}
29711
29712 \end_inset
29713
29714  Family of Microcontrollers
29715 \end_layout
29716
29717 \end_inset
29718 </cell>
29719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29720 \begin_inset Text
29721
29722 \begin_layout Standard
29723
29724 \size footnotesize
29725 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
29726
29727 \end_inset
29728
29729
29730 \end_layout
29731
29732 \end_inset
29733 </cell>
29734 </row>
29735 <row topline="true">
29736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29737 \begin_inset Text
29738
29739 \begin_layout Standard
29740
29741 \size footnotesize
29742 Silicon Laboratories / Cygnal
29743 \end_layout
29744
29745 \end_inset
29746 </cell>
29747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29748 \begin_inset Text
29749
29750 \begin_layout Standard
29751
29752 \size footnotesize
29753 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
29754 \begin_inset LatexCommand \index{IDE}
29755
29756 \end_inset
29757
29758
29759 \end_layout
29760
29761 \end_inset
29762 </cell>
29763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29764 \begin_inset Text
29765
29766 \begin_layout Standard
29767
29768 \size footnotesize
29769 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
29770
29771 \end_inset
29772
29773
29774 \end_layout
29775
29776 \end_inset
29777 </cell>
29778 </row>
29779 <row topline="true">
29780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29781 \begin_inset Text
29782
29783 \begin_layout Standard
29784
29785 \size footnotesize
29786 Ramtron / Goal Semiconductor
29787 \end_layout
29788
29789 \end_inset
29790 </cell>
29791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29792 \begin_inset Text
29793
29794 \begin_layout Standard
29795
29796 \size footnotesize
29797 Interfacing SDCC to Syn and Textpad
29798 \end_layout
29799
29800 \end_inset
29801 </cell>
29802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29803 \begin_inset Text
29804
29805 \begin_layout Standard
29806
29807 \size footnotesize
29808 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
29809
29810 \end_inset
29811
29812
29813 \end_layout
29814
29815 \end_inset
29816 </cell>
29817 </row>
29818 <row topline="true">
29819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29820 \begin_inset Text
29821
29822 \begin_layout Standard
29823
29824 \size footnotesize
29825 Ramtron / Goal Semiconductor
29826 \end_layout
29827
29828 \end_inset
29829 </cell>
29830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29831 \begin_inset Text
29832
29833 \begin_layout Standard
29834
29835 \size footnotesize
29836 Installing and Configuring SDCC and Crimson Editor 
29837 \end_layout
29838
29839 \end_inset
29840 </cell>
29841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29842 \begin_inset Text
29843
29844 \begin_layout Standard
29845
29846 \size footnotesize
29847 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
29848
29849 \end_inset
29850
29851
29852 \end_layout
29853
29854 \end_inset
29855 </cell>
29856 </row>
29857 <row topline="true" bottomline="true">
29858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29859 \begin_inset Text
29860
29861 \begin_layout Standard
29862
29863 \size footnotesize
29864 Texas Instruments
29865 \end_layout
29866
29867 \end_inset
29868 </cell>
29869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29870 \begin_inset Text
29871
29872 \begin_layout Standard
29873
29874 \size footnotesize
29875 MSC12xx Programming with SDCC
29876 \end_layout
29877
29878 \end_inset
29879 </cell>
29880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29881 \begin_inset Text
29882
29883 \begin_layout Standard
29884
29885 \size footnotesize
29886 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
29887
29888 \end_inset
29889
29890
29891 \end_layout
29892
29893 \end_inset
29894 </cell>
29895 </row>
29896 </lyxtabular>
29897
29898 \end_inset
29899
29900
29901 \end_layout
29902
29903 \begin_layout Section
29904 Some Questions
29905 \end_layout
29906
29907 \begin_layout Standard
29908 Some questions answered, some pointers given - it might be time to in turn
29909  ask 
29910 \emph on
29911 you
29912 \emph default
29913  some questions: 
29914 \end_layout
29915
29916 \begin_layout Itemize
29917 can you solve your project with the selected microcontroller? Would you
29918  find out early or rather late that your target is too small/slow/whatever?
29919  Can you switch to a slightly better device if it doesn't fit?
29920 \end_layout
29921
29922 \begin_layout Itemize
29923 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
29924  and/or another programming language be more adequate? Would an operating
29925  system on the target device help?
29926 \end_layout
29927
29928 \begin_layout Itemize
29929 if you solved the problem, will the marketing department be happy?
29930 \end_layout
29931
29932 \begin_layout Itemize
29933 if the marketing department is happy, will customers be happy?
29934 \end_layout
29935
29936 \begin_layout Itemize
29937 if you're the project manager, marketing department and maybe even the customer
29938  in one person, have you tried to see the project from the outside?
29939 \end_layout
29940
29941 \begin_layout Itemize
29942 is the project done if you think it is done? Or is just that other interface/pro
29943 tocol/feature/configuration/option missing? How about website, manual(s),
29944  internationali(z|s)ation, packaging, labels, 2nd source for components,
29945  electromagnetic compatability/interference, documentation for production,
29946  production test software, update mechanism, patent issues?
29947 \end_layout
29948
29949 \begin_layout Itemize
29950 is your project adequately positioned in that magic triangle: fame, fortune,
29951  fun?
29952 \end_layout
29953
29954 \begin_layout Standard
29955 Maybe not all answers to these questions are known and some answers may
29956  even be 
29957 \emph on
29958 no
29959 \emph default
29960 , nevertheless knowing these questions may help you to avoid burnout
29961 \begin_inset Foot
29962 status open
29963
29964 \begin_layout Standard
29965 burnout is bad for electronic devices, programmers and motorcycle tyres
29966 \end_layout
29967
29968 \end_inset
29969
29970 .
29971  Chances are you didn't want to hear some of them...
29972 \end_layout
29973
29974 \begin_layout Chapter
29975 Support
29976 \begin_inset LatexCommand \index{Support}
29977
29978 \end_inset
29979
29980
29981 \end_layout
29982
29983 \begin_layout Standard
29984 SDCC has grown to be a large project.
29985  The compiler alone (without the preprocessor, assembler and linker) is
29986  well over 150,000 lines of code (blank stripped).
29987  The open source nature of this project is a key to its continued growth
29988  and support.
29989  You gain the benefit and support of many active software developers and
29990  end users.
29991  Is SDCC perfect? No, that's why we need your help.
29992  The developers take pride in fixing reported bugs.
29993  You can help by reporting the bugs and helping other SDCC users.
29994  There are lots of ways to contribute, and we encourage you to take part
29995  in making SDCC a great software package.
29996  
29997 \end_layout
29998
29999 \begin_layout Standard
30000 The SDCC project is hosted on the SDCC sourceforge site at 
30001 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
30002
30003 \end_inset
30004
30005 .
30006  You'll find the complete set of mailing lists
30007 \begin_inset LatexCommand \index{Mailing list(s)}
30008
30009 \end_inset
30010
30011 , forums, bug reporting system, patch submission
30012 \begin_inset LatexCommand \index{Patch submission}
30013
30014 \end_inset
30015
30016  system, download
30017 \begin_inset LatexCommand \index{download}
30018
30019 \end_inset
30020
30021  area and Subversion code repository
30022 \begin_inset LatexCommand \index{Subversion code repository}
30023
30024 \end_inset
30025
30026  there.
30027 \end_layout
30028
30029 \begin_layout Section
30030 Reporting Bugs
30031 \begin_inset LatexCommand \index{Bug reporting}
30032
30033 \end_inset
30034
30035
30036 \begin_inset LatexCommand \index{Reporting bugs}
30037
30038 \end_inset
30039
30040
30041 \end_layout
30042
30043 \begin_layout Standard
30044 The recommended way of reporting bugs is using the infrastructure of the
30045  sourceforge site.
30046  You can follow the status of bug reports there and have an overview about
30047  the known bugs.
30048 \end_layout
30049
30050 \begin_layout Standard
30051 Bug reports are automatically forwarded to the developer mailing list and
30052  will be fixed ASAP.
30053  When reporting a bug, it is very useful to include a small test program
30054  (the smaller the better) which reproduces the problem.
30055  If you can isolate the problem by looking at the generated assembly code,
30056  this can be very helpful.
30057  Compiling your program with the -
30058 \begin_inset ERT
30059 status collapsed
30060
30061 \begin_layout Standard
30062
30063
30064 \backslash
30065 /
30066 \end_layout
30067
30068 \end_inset
30069
30070 -dumpall
30071 \begin_inset LatexCommand \index{-\/-dumpall}
30072
30073 \end_inset
30074
30075  option can sometimes be useful in locating optimization problems.
30076  When reporting a bug please make sure you:
30077 \end_layout
30078
30079 \begin_layout Enumerate
30080 Attach the code you are compiling with SDCC.
30081  
30082 \end_layout
30083
30084 \begin_layout Enumerate
30085 Specify the exact command you use to run SDCC, or attach your Makefile.
30086  
30087 \end_layout
30088
30089 \begin_layout Enumerate
30090 Specify the SDCC version (type "
30091 \family sans
30092 \series bold
30093 sdcc -v
30094 \family default
30095 \series default
30096 "), your platform, and operating system.
30097  
30098 \end_layout
30099
30100 \begin_layout Enumerate
30101 Provide an exact copy of any error message or incorrect output.
30102  
30103 \end_layout
30104
30105 \begin_layout Enumerate
30106 Put something meaningful in the subject of your message.
30107 \end_layout
30108
30109 \begin_layout Standard
30110 Please attempt to include these 5 important parts, as applicable, in all
30111  requests for support or when reporting any problems or bugs with SDCC.
30112  Though this will make your message lengthy, it will greatly improve your
30113  chance that SDCC users and developers will be able to help you.
30114  Some SDCC developers are frustrated by bug reports without code provided
30115  that they can use to reproduce and ultimately fix the problem, so please
30116  be sure to provide sample code if you are reporting a bug! 
30117 \end_layout
30118
30119 \begin_layout Standard
30120 Please have a short check that you are using a recent version of SDCC and
30121  the bug is not yet known.
30122  This is the link for reporting bugs: 
30123 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
30124
30125 \end_inset
30126
30127 .
30128  With SDCC on average having more than 200 downloads
30129 \begin_inset LatexCommand \index{download}
30130
30131 \end_inset
30132
30133  on sourceforge per day
30134 \begin_inset Foot
30135 status open
30136
30137 \begin_layout Standard
30138 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
30139  between 2002 and 2005.
30140  This does not include other methods of distribution.
30141 \end_layout
30142
30143 \end_inset
30144
30145  there must be some users.
30146  So it's not exactly easy to find a new bug.
30147  If you find one we need it: 
30148 \emph on
30149 reporting bugs is good
30150 \emph default
30151 .
30152 \end_layout
30153
30154 \begin_layout Section
30155 Requesting Features
30156 \begin_inset LatexCommand \label{sub:Requesting-Features}
30157
30158 \end_inset
30159
30160
30161 \begin_inset LatexCommand \index{Feature request}
30162
30163 \end_inset
30164
30165
30166 \begin_inset LatexCommand \index{Requesting features}
30167
30168 \end_inset
30169
30170
30171 \end_layout
30172
30173 \begin_layout Standard
30174 Like bug reports feature requests are forwarded to the developer mailing
30175  list.
30176  This is the link for requesting features: 
30177 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
30178
30179 \end_inset
30180
30181 .
30182 \end_layout
30183
30184 \begin_layout Section
30185 Submitting patches
30186 \end_layout
30187
30188 \begin_layout Standard
30189 Like bug reports contributed patches are forwarded to the developer mailing
30190  list.
30191  This is the link for submitting patches
30192 \begin_inset LatexCommand \index{Patch submission}
30193
30194 \end_inset
30195
30196
30197 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
30198
30199 \end_inset
30200
30201 .
30202 \end_layout
30203
30204 \begin_layout Standard
30205 You need to specify some parameters to the 
30206 \family typewriter
30207 diff
30208 \family default
30209  command for the patches to be useful.
30210  If you modified more than one file a patch created f.e.
30211  with 
30212 \family sans
30213 \series bold
30214
30215 \begin_inset Quotes sld
30216 \end_inset
30217
30218 diff -Naur unmodified_directory modified_directory >my_changes.patch
30219 \begin_inset Quotes srd
30220 \end_inset
30221
30222
30223 \family default
30224 \series default
30225  will be fine, otherwise 
30226 \family sans
30227 \series bold
30228
30229 \begin_inset Quotes sld
30230 \end_inset
30231
30232 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
30233 \begin_inset Quotes srd
30234 \end_inset
30235
30236
30237 \series default
30238  
30239 \family default
30240 will do.
30241 \end_layout
30242
30243 \begin_layout Section
30244 Getting Help
30245 \end_layout
30246
30247 \begin_layout Standard
30248 These links should take you directly to the 
30249 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
30250
30251 \end_inset
30252
30253
30254 \begin_inset Foot
30255 status open
30256
30257 \begin_layout Standard
30258 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
30259  automated messages (mid 2003)
30260 \end_layout
30261
30262 \end_inset
30263
30264  and the 
30265 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
30266
30267 \end_inset
30268
30269 , lists
30270 \begin_inset LatexCommand \index{Mailing list(s)}
30271
30272 \end_inset
30273
30274  and forums are archived and searchable so if you are lucky someone already
30275  had a similar problem.
30276  While mails to the lists themselves are delivered promptly their web front
30277  end on sourceforge sometimes shows a severe time lag (up to several weeks),
30278  if you're seriously using SDCC please consider subscribing to the lists.
30279 \end_layout
30280
30281 \begin_layout Section
30282 ChangeLog
30283 \end_layout
30284
30285 \begin_layout Standard
30286 You can follow the status of the Subversion version
30287 \begin_inset LatexCommand \index{version}
30288
30289 \end_inset
30290
30291  of SDCC by watching the Changelog
30292 \begin_inset LatexCommand \index{Changelog}
30293
30294 \end_inset
30295
30296  in the Subversion repository
30297 \size footnotesize
30298  
30299 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30300
30301 \end_inset
30302
30303 .
30304 \end_layout
30305
30306 \begin_layout Section
30307 Subversion Source Code Repository
30308 \end_layout
30309
30310 \begin_layout Standard
30311 The output of 
30312 \family sans
30313 \series bold
30314 sdcc --version
30315 \family default
30316 \series default
30317  or the filenames of the snapshot versions of SDCC include date and its
30318  Subversion
30319 \begin_inset LatexCommand \index{Subversion code repository}
30320
30321 \end_inset
30322
30323  number.
30324  Subversion allows to download the source of recent or previous versions
30325  
30326 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
30327
30328 \end_inset
30329
30330  (by number or by date).
30331  An on-line source code browser and detailled instructions are also available
30332  there.
30333  SDCC versions starting from 1999 up to now are available (currently the
30334  versions prior to the conversion from cvs
30335 \begin_inset LatexCommand \index{cvs|see{Subversion}}
30336
30337 \end_inset
30338
30339  to Subversion (April 2006) are either by accessible by Subversion or by
30340  cvs).
30341 \end_layout
30342
30343 \begin_layout Section
30344 Release policy
30345 \begin_inset LatexCommand \index{Release policy}
30346
30347 \end_inset
30348
30349
30350 \end_layout
30351
30352 \begin_layout Standard
30353 Historically there often were long delays between official releases and
30354  the sourceforge download area tends to get not updated at all.
30355  Excuses in the past might have referred to problems with live range analysis,
30356  but as this was fixed a while ago, the current problem is that another
30357  excuse has to be found.
30358  Kidding aside, we have to get better there! On the other hand there are
30359  daily snapshots available at 
30360 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
30361
30362 \end_inset
30363
30364 , and you can always build the very last version (hopefully with many bugs
30365  fixed, and features added) from the source code available at 
30366 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
30367
30368 \end_inset
30369
30370 .
30371  A release wiki
30372 \begin_inset LatexCommand \index{wiki}
30373
30374 \end_inset
30375
30376
30377 \begin_inset LatexCommand \index{Release wiki}
30378
30379 \end_inset
30380
30381  at 
30382 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
30383
30384 \end_inset
30385
30386  also holds some information about past and future releases.
30387 \end_layout
30388
30389 \begin_layout Section
30390 Examples
30391 \begin_inset LatexCommand \index{Examples}
30392
30393 \end_inset
30394
30395
30396 \end_layout
30397
30398 \begin_layout Standard
30399 You'll find some small examples in the directory 
30400 \emph on
30401 sdcc/device/examples/.
30402  
30403 \emph default
30404 More examples and libraries are available at
30405 \emph on
30406  The SDCC Open Knowledge Resource 
30407 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
30408
30409 \end_inset
30410
30411  
30412 \emph default
30413 web site or at 
30414 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
30415
30416 \end_inset
30417
30418 .
30419 \end_layout
30420
30421 \begin_layout Standard
30422 \begin_inset Note Comment
30423 status collapsed
30424
30425 \begin_layout Standard
30426 I did insert a reference to Paul's web site here although it seems rather
30427  dedicated to a specific 8032 board (I think it's okay because it f.e.
30428  shows LCD/Harddisc interface and has a free 8051 monitor.
30429  Independent 8032 board vendors face hard competition of heavily subsidized
30430  development boards anyway).
30431 \end_layout
30432
30433 \begin_layout Standard
30434 Maybe we should include some links to real world applications.
30435  Preferably pointer to pointers (one for each architecture) so this stays
30436  manageable here?
30437 \end_layout
30438
30439 \end_inset
30440
30441
30442 \end_layout
30443
30444 \begin_layout Section
30445 Quality control
30446 \begin_inset LatexCommand \label{sec:Quality-control}
30447
30448 \end_inset
30449
30450
30451 \begin_inset LatexCommand \index{Quality control}
30452
30453 \end_inset
30454
30455
30456 \end_layout
30457
30458 \begin_layout Standard
30459 The compiler is passed through nightly compile and build checks.
30460  The so called 
30461 \shape italic
30462 regression tests
30463 \shape default
30464
30465 \begin_inset LatexCommand \index{Regression test}
30466
30467 \end_inset
30468
30469  check that SDCC itself compiles flawlessly on several host platforms (i386,
30470  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
30471  the quality of the code generated by SDCC by running the code for several
30472  target platforms through simulators.
30473  The regression test suite comprises more than 100 files which expand to
30474  more than 500 test cases which include more than 4500 tests.
30475  The results of these tests are published daily on SDCC's snapshot page
30476  (click on the red or green symbols on the right side of 
30477 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
30478
30479 \end_inset
30480
30481 ).
30482 \end_layout
30483
30484 \begin_layout Standard
30485 There is a separate document 
30486 \shape italic
30487 test_suite.pdf 
30488 \begin_inset LatexCommand \index{Test suite}
30489
30490 \end_inset
30491
30492
30493 \shape default
30494  
30495 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30496
30497 \end_inset
30498
30499  about the regression test suite.
30500 \end_layout
30501
30502 \begin_layout Standard
30503 You'll find the test code in the directory 
30504 \shape italic
30505 sdcc/support/regression
30506 \shape default
30507 .
30508  You can run these tests manually by running 
30509 \family sans
30510 make
30511 \family default
30512  in this directory (or f.e.
30513  
30514 \family sans
30515 \series bold
30516
30517 \begin_inset Quotes sld
30518 \end_inset
30519
30520 make test-mcs51
30521 \begin_inset Quotes srd
30522 \end_inset
30523
30524
30525 \family default
30526 \series default
30527  if you don't want to run the complete tests).
30528  The test code might also be interesting if you want to look for examples
30529 \begin_inset LatexCommand \index{Examples}
30530
30531 \end_inset
30532
30533  checking corner cases of SDCC or if you plan to submit patches
30534 \begin_inset LatexCommand \index{Patch submission}
30535
30536 \end_inset
30537
30538 .
30539 \end_layout
30540
30541 \begin_layout Standard
30542 The 14bit pic port uses a different set of regression tests 
30543 \begin_inset LatexCommand \index{Regression test (PIC14)}
30544
30545 \end_inset
30546
30547 , you'll find them in the directory 
30548 \shape italic
30549 sdcc/src/regression
30550 \shape default
30551 .
30552 \end_layout
30553
30554 \begin_layout Section
30555 Use of SDCC in Education
30556 \end_layout
30557
30558 \begin_layout Standard
30559 In short: 
30560 \emph on
30561 highly
30562 \emph default
30563  encouraged
30564 \begin_inset Foot
30565 status open
30566
30567 \begin_layout Standard
30568 the phrase "use in education" might evoke the association "
30569 \emph on
30570 only
30571 \emph default
30572  fit for use in education".
30573  This connotation is not intended but nevertheless risked as the licensing
30574  of SDCC makes it difficult to offer educational discounts
30575 \end_layout
30576
30577 \end_inset
30578
30579 .
30580  If your rationales are to:
30581 \end_layout
30582
30583 \begin_layout Enumerate
30584 give students a chance to understand the 
30585 \emph on
30586 complete
30587 \emph default
30588  steps of code generation
30589 \end_layout
30590
30591 \begin_layout Enumerate
30592 have a curriculum that can be extended for years.
30593  Then you could use an fpga board as target and your curriculum will seamlessly
30594  extend from logic synthesis (
30595 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
30596
30597 \end_inset
30598
30599
30600 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
30601
30602 \end_inset
30603
30604 ), over assembly programming, to C to FPGA compilers (
30605 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
30606
30607 \end_inset
30608
30609 ) and to C.
30610 \end_layout
30611
30612 \begin_layout Enumerate
30613 be able to insert excursions about skills like using a revision control
30614  system, submitting/applying patches, using a type-setting (as opposed to
30615  word-processing) engine LyX/LaTeX, using 
30616 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
30617
30618 \end_inset
30619
30620 , following some 
30621 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
30622
30623 \end_inset
30624
30625 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
30626  Source Software, CPU simulation, compiler regression tests
30627 \begin_inset LatexCommand \index{Regression test}
30628
30629 \end_inset
30630
30631 .
30632  
30633 \newline
30634 And if there should be a shortage of ideas then you can always point students
30635  to the ever-growing feature request list 
30636 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
30637
30638 \end_inset
30639
30640 .
30641 \end_layout
30642
30643 \begin_layout Enumerate
30644 not tie students to a specific host platform and instead allow them to use
30645  a host platform of 
30646 \emph on
30647 their
30648 \emph default
30649  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
30650  eventually 
30651 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
30652
30653 \end_inset
30654
30655 )
30656 \end_layout
30657
30658 \begin_layout Enumerate
30659 not encourage students to use illegal copies of educational software
30660 \end_layout
30661
30662 \begin_layout Enumerate
30663 be immune to licensing/availability/price changes of the chosen tool chain
30664 \end_layout
30665
30666 \begin_layout Enumerate
30667 be able to change to a new target platform without having to adopt a new
30668  tool chain
30669 \end_layout
30670
30671 \begin_layout Enumerate
30672 have complete control over and insight into the tool chain
30673 \end_layout
30674
30675 \begin_layout Enumerate
30676 make your students aware about the pros and cons of open source software
30677  development
30678 \end_layout
30679
30680 \begin_layout Enumerate
30681 give back to the public as you are probably at least partially publically
30682  funded
30683 \end_layout
30684
30685 \begin_layout Enumerate
30686 give students a chance to publically prove their skills and to possibly
30687  see a world wide impact
30688 \end_layout
30689
30690 \begin_layout Standard
30691 then SDCC is probably among the first choices.
30692  Well, probably SDCC might be the only choice.
30693 \end_layout
30694
30695 \begin_layout Standard
30696
30697 \newpage
30698
30699 \end_layout
30700
30701 \begin_layout Chapter
30702 SDCC Technical Data
30703 \end_layout
30704
30705 \begin_layout Section
30706 Optimizations
30707 \begin_inset LatexCommand \index{Optimizations}
30708
30709 \end_inset
30710
30711
30712 \end_layout
30713
30714 \begin_layout Standard
30715 SDCC performs a host of standard optimizations in addition to some MCU specific
30716  optimizations.
30717  
30718 \end_layout
30719
30720 \begin_layout Subsection
30721 Sub-expression Elimination
30722 \begin_inset LatexCommand \index{Subexpression elimination}
30723
30724 \end_inset
30725
30726
30727 \end_layout
30728
30729 \begin_layout Standard
30730 The compiler does local and 
30731 \emph on
30732 g
30733 \emph default
30734 lobal 
30735 \emph on
30736 c
30737 \emph default
30738 ommon 
30739 \emph on
30740 s
30741 \emph default
30742 ubexpression 
30743 \emph on
30744 e
30745 \emph default
30746 limination, e.g.: 
30747 \end_layout
30748
30749 \begin_layout Verse
30750
30751 \family typewriter
30752 i = x + y + 1; 
30753 \newline
30754 j = x + y;
30755 \end_layout
30756
30757 \begin_layout Standard
30758 will be translated to
30759 \end_layout
30760
30761 \begin_layout Verse
30762
30763 \family typewriter
30764 iTemp = x + y; 
30765 \newline
30766 i = iTemp + 1; 
30767 \newline
30768 j = iTemp;
30769 \end_layout
30770
30771 \begin_layout Standard
30772 Some subexpressions are not as obvious as the above example, e.g.:
30773 \end_layout
30774
30775 \begin_layout Verse
30776
30777 \family typewriter
30778 a->b[i].c = 10; 
30779 \newline
30780 a->b[i].d = 11;
30781 \end_layout
30782
30783 \begin_layout Standard
30784 In this case the address arithmetic a->b[i] will be computed only once;
30785  the equivalent code in C would be.
30786 \end_layout
30787
30788 \begin_layout Verse
30789
30790 \family typewriter
30791 iTemp = a->b[i]; 
30792 \newline
30793 iTemp.c = 10; 
30794 \newline
30795 iTemp.d = 11;
30796 \end_layout
30797
30798 \begin_layout Standard
30799 The compiler will try to keep these temporary variables in registers.
30800 \end_layout
30801
30802 \begin_layout Subsection
30803 Dead-Code Elimination
30804 \begin_inset LatexCommand \index{Dead-code elimination}
30805
30806 \end_inset
30807
30808
30809 \end_layout
30810
30811 \begin_layout Verse
30812
30813 \family typewriter
30814 int global;
30815 \newline
30816
30817 \newline
30818 void f () { 
30819 \newline
30820 \InsetSpace ~
30821 \InsetSpace ~
30822 int i; 
30823 \newline
30824 \InsetSpace ~
30825 \InsetSpace ~
30826 i = 1; \InsetSpace ~
30827 \InsetSpace ~
30828 \InsetSpace ~
30829 \InsetSpace ~
30830 \InsetSpace ~
30831 /* dead store */ 
30832 \newline
30833 \InsetSpace ~
30834 \InsetSpace ~
30835 global = 1;\InsetSpace ~
30836 /* dead
30837  store */ 
30838 \newline
30839 \InsetSpace ~
30840 \InsetSpace ~
30841 global = 2; 
30842 \newline
30843 \InsetSpace ~
30844 \InsetSpace ~
30845 return; 
30846 \newline
30847 \InsetSpace ~
30848 \InsetSpace ~
30849 global = 3;\InsetSpace ~
30850 /* unreachable */ 
30851 \newline
30852 }
30853 \end_layout
30854
30855 \begin_layout Standard
30856 will be changed to
30857 \end_layout
30858
30859 \begin_layout Verse
30860
30861 \family typewriter
30862 int global;
30863 \newline
30864
30865 \newline
30866 void f () {
30867 \newline
30868 \InsetSpace ~
30869 \InsetSpace ~
30870 global = 2; 
30871 \newline
30872 }
30873 \end_layout
30874
30875 \begin_layout Subsection
30876 Copy-Propagation
30877 \begin_inset LatexCommand \index{Copy propagation}
30878
30879 \end_inset
30880
30881
30882 \end_layout
30883
30884 \begin_layout Verse
30885
30886 \family typewriter
30887 int f() { 
30888 \newline
30889 \InsetSpace ~
30890 \InsetSpace ~
30891 int i, j; 
30892 \newline
30893 \InsetSpace ~
30894 \InsetSpace ~
30895 i = 10; 
30896 \newline
30897 \InsetSpace ~
30898 \InsetSpace ~
30899 j = i; 
30900 \newline
30901 \InsetSpace ~
30902 \InsetSpace ~
30903 return j; 
30904 \newline
30905 }
30906 \end_layout
30907
30908 \begin_layout Standard
30909 will be changed to 
30910 \end_layout
30911
30912 \begin_layout Verse
30913
30914 \family typewriter
30915 int f() { 
30916 \newline
30917 \InsetSpace ~
30918 \InsetSpace ~
30919 int i, j; 
30920 \newline
30921 \InsetSpace ~
30922 \InsetSpace ~
30923 i = 10; 
30924 \newline
30925 \InsetSpace ~
30926 \InsetSpace ~
30927 j = 10; 
30928 \newline
30929 \InsetSpace ~
30930 \InsetSpace ~
30931 return 10; 
30932 \newline
30933 }
30934 \end_layout
30935
30936 \begin_layout Standard
30937 Note: the dead stores created by this copy propagation will be eliminated
30938  by dead-code elimination.
30939 \end_layout
30940
30941 \begin_layout Subsection
30942 Loop Optimizations
30943 \begin_inset LatexCommand \index{Loop optimization}
30944
30945 \end_inset
30946
30947
30948 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
30949
30950 \end_inset
30951
30952
30953 \end_layout
30954
30955 \begin_layout Standard
30956 Two types of loop optimizations are done by SDCC 
30957 \emph on
30958 loop invariant
30959 \emph default
30960  lifting and
30961 \emph on
30962  strength reduction
30963 \emph default
30964  of loop induction variables.
30965  In addition to the strength reduction the optimizer marks the induction
30966  variables and the register allocator tries to keep the induction variables
30967  in registers for the duration of the loop.
30968  Because of this preference of the register allocator
30969 \begin_inset LatexCommand \index{Register allocation}
30970
30971 \end_inset
30972
30973 , loop induction optimization causes an increase in register pressure, which
30974  may cause unwanted spilling of other temporary variables into the stack
30975 \begin_inset LatexCommand \index{stack}
30976
30977 \end_inset
30978
30979  / data space.
30980  The compiler will generate a warning message when it is forced to allocate
30981  extra space either on the stack or data space.
30982  If this extra space allocation is undesirable then induction optimization
30983  can be eliminated either for the entire source file (with -
30984 \begin_inset ERT
30985 status collapsed
30986
30987 \begin_layout Standard
30988
30989
30990 \backslash
30991 /
30992 \end_layout
30993
30994 \end_inset
30995
30996 -noinduction option) or for a given function only using #pragma\InsetSpace ~
30997 noinduction
30998 \begin_inset LatexCommand \index{\#pragma noinduction}
30999
31000 \end_inset
31001
31002 .
31003 \newline
31004
31005 \newline
31006 Loop Invariant:
31007 \end_layout
31008
31009 \begin_layout Verse
31010
31011 \family typewriter
31012 for (i = 0 ; i < 100 ; i ++) 
31013 \newline
31014 \InsetSpace ~
31015 \InsetSpace ~
31016 \InsetSpace ~
31017 \InsetSpace ~
31018 f += k + l;
31019 \end_layout
31020
31021 \begin_layout Standard
31022 changed to
31023 \end_layout
31024
31025 \begin_layout Verse
31026
31027 \family typewriter
31028 itemp = k + l; 
31029 \newline
31030 for (i = 0; i < 100; i++) 
31031 \newline
31032 \InsetSpace ~
31033 \InsetSpace ~
31034 \InsetSpace ~
31035 \InsetSpace ~
31036 f += itemp;
31037 \end_layout
31038
31039 \begin_layout Standard
31040 As mentioned previously some loop invariants are not as apparent, all static
31041  address computations are also moved out of the loop.
31042 \newline
31043
31044 \newline
31045 Strength Reduction
31046 \begin_inset LatexCommand \index{Strength reduction}
31047
31048 \end_inset
31049
31050 , this optimization substitutes an expression by a cheaper expression:
31051 \end_layout
31052
31053 \begin_layout Verse
31054
31055 \family typewriter
31056 for (i=0;i < 100; i++)
31057 \newline
31058 \InsetSpace ~
31059 \InsetSpace ~
31060 \InsetSpace ~
31061 \InsetSpace ~
31062 ar[i*5] = i*3;
31063 \end_layout
31064
31065 \begin_layout Standard
31066 changed to
31067 \end_layout
31068
31069 \begin_layout Verse
31070
31071 \family typewriter
31072 itemp1 = 0; 
31073 \newline
31074 itemp2 = 0; 
31075 \newline
31076 for (i=0;i< 100;i++) { 
31077 \newline
31078 \InsetSpace ~
31079 \InsetSpace ~
31080 \InsetSpace ~
31081 \InsetSpace ~
31082 ar[itemp1] = itemp2; 
31083 \newline
31084 \InsetSpace ~
31085 \InsetSpace ~
31086 \InsetSpace ~
31087 \InsetSpace ~
31088 itemp1
31089  += 5; 
31090 \newline
31091 \InsetSpace ~
31092 \InsetSpace ~
31093 \InsetSpace ~
31094 \InsetSpace ~
31095 itemp2 += 3; 
31096 \newline
31097 }
31098 \end_layout
31099
31100 \begin_layout Standard
31101 The more expensive multiplication
31102 \begin_inset LatexCommand \index{Multiplication}
31103
31104 \end_inset
31105
31106  is changed to a less expensive addition.
31107 \end_layout
31108
31109 \begin_layout Subsection
31110 Loop Reversing
31111 \begin_inset LatexCommand \index{Loop reversing}
31112
31113 \end_inset
31114
31115
31116 \end_layout
31117
31118 \begin_layout Standard
31119 This optimization is done to reduce the overhead of checking loop boundaries
31120  for every iteration.
31121  Some simple loops can be reversed and implemented using a 
31122 \begin_inset Quotes eld
31123 \end_inset
31124
31125 decrement and jump if not zero
31126 \begin_inset Quotes erd
31127 \end_inset
31128
31129  instruction.
31130  SDCC checks for the following criterion to determine if a loop is reversible
31131  (note: more sophisticated compilers use data-dependency analysis to make
31132  this determination, SDCC uses a more simple minded analysis).
31133 \end_layout
31134
31135 \begin_layout Itemize
31136 The 'for' loop is of the form 
31137 \newline
31138
31139 \newline
31140
31141 \family typewriter
31142 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
31143  += 1])
31144 \newline
31145 \InsetSpace ~
31146 \InsetSpace ~
31147 \InsetSpace ~
31148 \InsetSpace ~
31149 <for body>
31150 \end_layout
31151
31152 \begin_layout Itemize
31153 The <for body> does not contain 
31154 \begin_inset Quotes eld
31155 \end_inset
31156
31157 continue
31158 \begin_inset Quotes erd
31159 \end_inset
31160
31161  or 'break
31162 \begin_inset Quotes erd
31163 \end_inset
31164
31165 .
31166 \end_layout
31167
31168 \begin_layout Itemize
31169 All goto's are contained within the loop.
31170 \end_layout
31171
31172 \begin_layout Itemize
31173 No function calls within the loop.
31174 \end_layout
31175
31176 \begin_layout Itemize
31177 The loop control variable <sym> is not assigned any value within the loop
31178 \end_layout
31179
31180 \begin_layout Itemize
31181 The loop control variable does NOT participate in any arithmetic operation
31182  within the loop.
31183 \end_layout
31184
31185 \begin_layout Itemize
31186 There are NO switch statements in the loop.
31187 \end_layout
31188
31189 \begin_layout Subsection
31190 Algebraic Simplifications
31191 \end_layout
31192
31193 \begin_layout Standard
31194 SDCC does numerous algebraic simplifications, the following is a small sub-set
31195  of these optimizations.
31196 \end_layout
31197
31198 \begin_layout Verse
31199
31200 \family typewriter
31201 i = j + 0;\InsetSpace ~
31202 \InsetSpace ~
31203 \InsetSpace ~
31204 \InsetSpace ~
31205  /* changed to: */\InsetSpace ~
31206 \InsetSpace ~
31207 \InsetSpace ~
31208 \InsetSpace ~
31209  i = j; 
31210 \newline
31211 i /= 2;\InsetSpace ~
31212 \InsetSpace ~
31213 \InsetSpace ~
31214 \InsetSpace ~
31215 \InsetSpace ~
31216 \InsetSpace ~
31217 \InsetSpace ~
31218  /* changed to: */\InsetSpace ~
31219 \InsetSpace ~
31220 \InsetSpace ~
31221 \InsetSpace ~
31222  i >>= 1; 
31223 \newline
31224 i
31225  = j - j;\InsetSpace ~
31226 \InsetSpace ~
31227 \InsetSpace ~
31228 \InsetSpace ~
31229  /* changed to: */\InsetSpace ~
31230 \InsetSpace ~
31231 \InsetSpace ~
31232 \InsetSpace ~
31233  i = 0; 
31234 \newline
31235 i = j / 1;\InsetSpace ~
31236 \InsetSpace ~
31237 \InsetSpace ~
31238 \InsetSpace ~
31239  /* changed to: */\InsetSpace ~
31240 \InsetSpace ~
31241 \InsetSpace ~
31242 \InsetSpace ~
31243  i = j;
31244 \end_layout
31245
31246 \begin_layout Standard
31247 Note the subexpressions
31248 \begin_inset LatexCommand \index{Subexpression}
31249
31250 \end_inset
31251
31252  given above are generally introduced by macro expansions or as a result
31253  of copy/constant propagation.
31254 \end_layout
31255
31256 \begin_layout Subsection
31257 'switch' Statements
31258 \begin_inset LatexCommand \label{sub:'switch'-Statements}
31259
31260 \end_inset
31261
31262
31263 \begin_inset LatexCommand \index{switch statement}
31264
31265 \end_inset
31266
31267
31268 \end_layout
31269
31270 \begin_layout Standard
31271 SDCC can optimize switch statements to jump tables
31272 \begin_inset LatexCommand \index{jump tables}
31273
31274 \end_inset
31275
31276 .
31277  It makes the decision based on an estimate of the generated code size.
31278  SDCC is quite liberal in the requirements for jump table generation: 
31279 \end_layout
31280
31281 \begin_layout Itemize
31282 The labels need not be in order, and the starting number need not be one
31283  or zero, the case labels are in numerical sequence or not too many case
31284  labels are missing.
31285 \end_layout
31286
31287 \begin_deeper
31288 \begin_layout Verse
31289
31290 \family typewriter
31291 switch(i) {\InsetSpace ~
31292 \InsetSpace ~
31293 \InsetSpace ~
31294 \InsetSpace ~
31295 \InsetSpace ~
31296 \InsetSpace ~
31297 \InsetSpace ~
31298 \InsetSpace ~
31299 \InsetSpace ~
31300 \InsetSpace ~
31301 \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 switch (i) { 
31318 \newline
31319 \InsetSpace ~
31320 \InsetSpace ~
31321 \InsetSpace ~
31322 case 4: ...\InsetSpace ~
31323 \InsetSpace ~
31324 \InsetSpace ~
31325 \InsetSpace ~
31326 \InsetSpace ~
31327 \InsetSpace ~
31328 \InsetSpace ~
31329 \InsetSpace ~
31330 \InsetSpace ~
31331 \InsetSpace ~
31332 \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 case 0: ...
31349  
31350 \newline
31351 \InsetSpace ~
31352 \InsetSpace ~
31353 \InsetSpace ~
31354 case 5: ...\InsetSpace ~
31355 \InsetSpace ~
31356 \InsetSpace ~
31357 \InsetSpace ~
31358 \InsetSpace ~
31359 \InsetSpace ~
31360 \InsetSpace ~
31361 \InsetSpace ~
31362 \InsetSpace ~
31363 \InsetSpace ~
31364 \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 case 1: ...
31381  
31382 \newline
31383 \InsetSpace ~
31384 \InsetSpace ~
31385 \InsetSpace ~
31386 case 3: ...\InsetSpace ~
31387 \InsetSpace ~
31388 \InsetSpace ~
31389 \InsetSpace ~
31390 \InsetSpace ~
31391 \InsetSpace ~
31392 \InsetSpace ~
31393 \InsetSpace ~
31394 \InsetSpace ~
31395 \InsetSpace ~
31396 \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
31413 \newline
31414 \InsetSpace ~
31415 \InsetSpace ~
31416 \InsetSpace ~
31417 case 6: ...\InsetSpace ~
31418 \InsetSpace ~
31419 \InsetSpace ~
31420 \InsetSpace ~
31421 \InsetSpace ~
31422 \InsetSpace ~
31423 \InsetSpace ~
31424 \InsetSpace ~
31425 \InsetSpace ~
31426 \InsetSpace ~
31427 \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 case 3: ...
31444  
31445 \newline
31446 \InsetSpace ~
31447 \InsetSpace ~
31448 \InsetSpace ~
31449 case 7: ...\InsetSpace ~
31450 \InsetSpace ~
31451 \InsetSpace ~
31452 \InsetSpace ~
31453 \InsetSpace ~
31454 \InsetSpace ~
31455 \InsetSpace ~
31456 \InsetSpace ~
31457 \InsetSpace ~
31458 \InsetSpace ~
31459 \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 case 4: ...
31476  
31477 \newline
31478 \InsetSpace ~
31479 \InsetSpace ~
31480 \InsetSpace ~
31481 case 8: ...\InsetSpace ~
31482 \InsetSpace ~
31483 \InsetSpace ~
31484 \InsetSpace ~
31485 \InsetSpace ~
31486 \InsetSpace ~
31487 \InsetSpace ~
31488 \InsetSpace ~
31489 \InsetSpace ~
31490 \InsetSpace ~
31491 \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 case 5: ...
31508  
31509 \newline
31510 \InsetSpace ~
31511 \InsetSpace ~
31512 \InsetSpace ~
31513 case 9: ...\InsetSpace ~
31514 \InsetSpace ~
31515 \InsetSpace ~
31516 \InsetSpace ~
31517 \InsetSpace ~
31518 \InsetSpace ~
31519 \InsetSpace ~
31520 \InsetSpace ~
31521 \InsetSpace ~
31522 \InsetSpace ~
31523 \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 case 6: ...
31540  
31541 \newline
31542 \InsetSpace ~
31543 \InsetSpace ~
31544 \InsetSpace ~
31545 case 10: ...\InsetSpace ~
31546 \InsetSpace ~
31547 \InsetSpace ~
31548 \InsetSpace ~
31549 \InsetSpace ~
31550 \InsetSpace ~
31551 \InsetSpace ~
31552 \InsetSpace ~
31553 \InsetSpace ~
31554 \InsetSpace ~
31555 \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 case 7: ...
31571  
31572 \newline
31573 \InsetSpace ~
31574 \InsetSpace ~
31575 \InsetSpace ~
31576 case 11: ...\InsetSpace ~
31577 \InsetSpace ~
31578 \InsetSpace ~
31579 \InsetSpace ~
31580 \InsetSpace ~
31581 \InsetSpace ~
31582 \InsetSpace ~
31583 \InsetSpace ~
31584 \InsetSpace ~
31585 \InsetSpace ~
31586 \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 case 8: ...
31602  
31603 \newline
31604 }\InsetSpace ~
31605 \InsetSpace ~
31606 \InsetSpace ~
31607 \InsetSpace ~
31608 \InsetSpace ~
31609 \InsetSpace ~
31610 \InsetSpace ~
31611 \InsetSpace ~
31612 \InsetSpace ~
31613 \InsetSpace ~
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 }
31641 \end_layout
31642
31643 \begin_layout Standard
31644 Both the above switch statements will be implemented using a jump-table.
31645  The example to the right side is slightly more efficient as the check for
31646  the lower boundary of the jump-table is not needed.
31647 \end_layout
31648
31649 \end_deeper
31650 \begin_layout Itemize
31651 The number of case labels is not larger than supported by the target architectur
31652 e.
31653 \end_layout
31654
31655 \begin_layout Itemize
31656 If the case labels are not in numerical sequence ('gaps' between cases)
31657  SDCC checks whether a jump table with additionally inserted dummy cases
31658  is still attractive.
31659  
31660 \end_layout
31661
31662 \begin_layout Itemize
31663 If the starting number is not zero and a check for the lower boundary of
31664  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
31665  ...
31666  .
31667 \end_layout
31668
31669 \begin_layout Standard
31670 Switch statements which have large gaps in the numeric sequence or those
31671  that have too many case labels can be split into more than one switch statement
31672  for efficient code generation, e.g.:
31673 \end_layout
31674
31675 \begin_layout Verse
31676
31677 \family typewriter
31678 switch (i) { 
31679 \newline
31680 \InsetSpace ~
31681 \InsetSpace ~
31682 case 1: ...
31683  
31684 \newline
31685 \InsetSpace ~
31686 \InsetSpace ~
31687 case 2: ...
31688  
31689 \newline
31690 \InsetSpace ~
31691 \InsetSpace ~
31692 case 3: ...
31693  
31694 \newline
31695 \InsetSpace ~
31696 \InsetSpace ~
31697 case 4: ...
31698  
31699 \newline
31700 \InsetSpace ~
31701 \InsetSpace ~
31702 case 5: ...
31703  
31704 \newline
31705 \InsetSpace ~
31706 \InsetSpace ~
31707 case 6: ...
31708  
31709 \newline
31710 \InsetSpace ~
31711 \InsetSpace ~
31712 case 7: ...
31713  
31714 \newline
31715 \InsetSpace ~
31716 \InsetSpace ~
31717 case 101: ...
31718  
31719 \newline
31720 \InsetSpace ~
31721 \InsetSpace ~
31722 case 102: ...
31723  
31724 \newline
31725 \InsetSpace ~
31726 \InsetSpace ~
31727 case 103: ...
31728  
31729 \newline
31730 \InsetSpace ~
31731 \InsetSpace ~
31732 case 104: ...
31733  
31734 \newline
31735 \InsetSpace ~
31736 \InsetSpace ~
31737 case 105: ...
31738  
31739 \newline
31740 \InsetSpace ~
31741 \InsetSpace ~
31742 case 106: ...
31743  
31744 \newline
31745 \InsetSpace ~
31746 \InsetSpace ~
31747 case 107: ...
31748  
31749 \newline
31750 }
31751 \end_layout
31752
31753 \begin_layout Standard
31754 If the above switch statement is broken down into two switch statements
31755 \end_layout
31756
31757 \begin_layout Verse
31758
31759 \family typewriter
31760 switch (i) { 
31761 \newline
31762 \InsetSpace ~
31763 \InsetSpace ~
31764 case 1: ...
31765  
31766 \newline
31767 \InsetSpace ~
31768 \InsetSpace ~
31769 case 2: ...
31770  
31771 \newline
31772 \InsetSpace ~
31773 \InsetSpace ~
31774 case 3: ...
31775  
31776 \newline
31777 \InsetSpace ~
31778 \InsetSpace ~
31779 case 4: ...
31780  
31781 \newline
31782 \InsetSpace ~
31783 \InsetSpace ~
31784 case 5: ...
31785  
31786 \newline
31787 \InsetSpace ~
31788 \InsetSpace ~
31789 case 6: ...
31790  
31791 \newline
31792 \InsetSpace ~
31793 \InsetSpace ~
31794 case 7: ...
31795  
31796 \newline
31797 }
31798 \end_layout
31799
31800 \begin_layout Standard
31801 and
31802 \end_layout
31803
31804 \begin_layout Verse
31805
31806 \family typewriter
31807 switch (i) { 
31808 \newline
31809 \InsetSpace ~
31810 \InsetSpace ~
31811 case 101: ...
31812  
31813 \newline
31814 \InsetSpace ~
31815 \InsetSpace ~
31816 case 102: ...
31817  
31818 \newline
31819 \InsetSpace ~
31820 \InsetSpace ~
31821 case 103: ...
31822  
31823 \newline
31824 \InsetSpace ~
31825 \InsetSpace ~
31826 case 104: ...
31827  
31828 \newline
31829 \InsetSpace ~
31830 \InsetSpace ~
31831 case 105: ...
31832  
31833 \newline
31834 \InsetSpace ~
31835 \InsetSpace ~
31836 case 106: ...
31837  
31838 \newline
31839 \InsetSpace ~
31840 \InsetSpace ~
31841 case 107: ...
31842  
31843 \newline
31844 }
31845 \end_layout
31846
31847 \begin_layout Standard
31848 then both the switch statements will be implemented using jump-tables whereas
31849  the unmodified switch statement will not be.
31850 \end_layout
31851
31852 \begin_layout Standard
31853 \begin_inset Note Comment
31854 status collapsed
31855
31856 \begin_layout Standard
31857 There might be reasons which SDCC cannot know about to either favour or
31858  not favour jump tables.
31859  If the target system has to be as quick for the last switch case as for
31860  the first (pro jump table), or if the switch argument is known to be zero
31861  in the majority of the cases (contra jump table).
31862 \end_layout
31863
31864 \end_inset
31865
31866
31867 \end_layout
31868
31869 \begin_layout Standard
31870 The pragma nojtbound
31871 \begin_inset LatexCommand \index{\#pragma nojtbound}
31872
31873 \end_inset
31874
31875  can be used to turn off checking the 
31876 \emph on
31877 j
31878 \emph default
31879 ump 
31880 \emph on
31881 t
31882 \emph default
31883 able 
31884 \emph on
31885 bound
31886 \emph default
31887 aries.
31888  It has no effect if a default label is supplied.
31889  Use of this pragma is dangerous: if the switch
31890 \begin_inset LatexCommand \index{switch statement}
31891
31892 \end_inset
31893
31894  argument is not matched by a case statement the processor will happily
31895  jump into Nirvana.
31896 \end_layout
31897
31898 \begin_layout Subsection
31899 Bit-shifting Operations
31900 \begin_inset LatexCommand \index{Bit shifting}
31901
31902 \end_inset
31903
31904 .
31905 \end_layout
31906
31907 \begin_layout Standard
31908 Bit shifting is one of the most frequently used operation in embedded programmin
31909 g.
31910  SDCC tries to implement bit-shift operations in the most efficient way
31911  possible, e.g.:
31912 \end_layout
31913
31914 \begin_layout Verse
31915
31916 \family typewriter
31917 unsigned char i;
31918 \newline
31919 ...
31920  
31921 \newline
31922 i >>= 4; 
31923 \newline
31924 ...
31925 \end_layout
31926
31927 \begin_layout Standard
31928 generates the following code:
31929 \end_layout
31930
31931 \begin_layout Verse
31932
31933 \family typewriter
31934 mov\InsetSpace ~
31935  a,_i 
31936 \newline
31937 swap a 
31938 \newline
31939 anl\InsetSpace ~
31940  a,#0x0f 
31941 \newline
31942 mov\InsetSpace ~
31943  _i,a
31944 \end_layout
31945
31946 \begin_layout Standard
31947 In general SDCC will never setup a loop if the shift count is known.
31948  Another example:
31949 \end_layout
31950
31951 \begin_layout Verse
31952
31953 \family typewriter
31954 unsigned int i; 
31955 \newline
31956 ...
31957  
31958 \newline
31959 i >>= 9; 
31960 \newline
31961 ...
31962 \end_layout
31963
31964 \begin_layout Standard
31965 will generate:
31966 \end_layout
31967
31968 \begin_layout Verse
31969
31970 \family typewriter
31971 mov\InsetSpace ~
31972 \InsetSpace ~
31973 a,(_i + 1) 
31974 \newline
31975 mov\InsetSpace ~
31976 \InsetSpace ~
31977 (_i + 1),#0x00 
31978 \newline
31979 clr\InsetSpace ~
31980 \InsetSpace ~
31981
31982 \newline
31983 rrc\InsetSpace ~
31984 \InsetSpace ~
31985
31986 \newline
31987 mov\InsetSpace ~
31988 \InsetSpace ~
31989 _i,a
31990 \end_layout
31991
31992 \begin_layout Subsection
31993 Bit-rotation
31994 \begin_inset LatexCommand \index{Bit rotation}
31995
31996 \end_inset
31997
31998
31999 \end_layout
32000
32001 \begin_layout Standard
32002 A special case of the bit-shift operation is bit rotation
32003 \begin_inset LatexCommand \index{rotating bits}
32004
32005 \end_inset
32006
32007 , SDCC recognizes the following expression to be a left bit-rotation:
32008 \end_layout
32009
32010 \begin_layout Verse
32011
32012 \family typewriter
32013 \series bold
32014 unsigned
32015 \series default
32016 \InsetSpace ~
32017 \InsetSpace ~
32018 char i;\InsetSpace ~
32019 \InsetSpace ~
32020 \InsetSpace ~
32021 \InsetSpace ~
32022 \InsetSpace ~
32023 \InsetSpace ~
32024 \InsetSpace ~
32025 \InsetSpace ~
32026 \InsetSpace ~
32027 \InsetSpace ~
32028 \InsetSpace ~
32029 /* unsigned is needed for rotation */ 
32030 \newline
32031 ...
32032  
32033 \newline
32034 i = ((i << 1) | (i >> 7)); 
32035 \family default
32036
32037 \newline
32038
32039 \family typewriter
32040 ...
32041 \end_layout
32042
32043 \begin_layout Standard
32044 will generate the following code:
32045 \end_layout
32046
32047 \begin_layout Verse
32048
32049 \family typewriter
32050 mov\InsetSpace ~
32051 \InsetSpace ~
32052 a,_i 
32053 \newline
32054 rl\InsetSpace ~
32055 \InsetSpace ~
32056 \InsetSpace ~
32057
32058 \newline
32059 mov\InsetSpace ~
32060 \InsetSpace ~
32061 _i,a
32062 \end_layout
32063
32064 \begin_layout Standard
32065 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
32066 ns of this case will also be recognized as bit-rotation, i.e.: 
32067 \end_layout
32068
32069 \begin_layout Verse
32070
32071 \family typewriter
32072 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
32073 \end_layout
32074
32075 \begin_layout Subsection
32076 Nibble and Byte Swapping
32077 \end_layout
32078
32079 \begin_layout Standard
32080 Other special cases of the bit-shift operations are nibble or byte swapping
32081 \begin_inset LatexCommand \index{swapping nibbles/bytes}
32082
32083 \end_inset
32084
32085 , SDCC recognizes the following expressions:
32086 \end_layout
32087
32088 \begin_layout Verse
32089
32090 \family typewriter
32091 \series bold
32092 unsigned
32093 \series default
32094 \InsetSpace ~
32095 \InsetSpace ~
32096 char i; 
32097 \newline
32098
32099 \series bold
32100 unsigned
32101 \series default
32102 \InsetSpace ~
32103 \InsetSpace ~
32104 int j; 
32105 \newline
32106 ...
32107  
32108 \newline
32109 i = ((i << 4) | (i >> 4)); 
32110 \family default
32111
32112 \newline
32113
32114 \family typewriter
32115 j = ((j << 8) | (j >> 8)); 
32116 \end_layout
32117
32118 \begin_layout Standard
32119 and generates a swap instruction for the nibble swapping
32120 \begin_inset LatexCommand \index{Nibble swapping}
32121
32122 \end_inset
32123
32124  or move instructions for the byte swapping
32125 \begin_inset LatexCommand \index{Byte swapping}
32126
32127 \end_inset
32128
32129 .
32130  The 
32131 \begin_inset Quotes sld
32132 \end_inset
32133
32134 j
32135 \begin_inset Quotes srd
32136 \end_inset
32137
32138  example can be used to convert from little to big-endian or vice versa.
32139  If you want to change the endianness of a 
32140 \emph on
32141 signed
32142 \emph default
32143  integer you have to cast to 
32144 \family typewriter
32145 (unsigned int)
32146 \family default
32147  first.
32148 \end_layout
32149
32150 \begin_layout Standard
32151 Note that SDCC stores numbers in little-endian
32152 \begin_inset Foot
32153 status open
32154
32155 \begin_layout Standard
32156 Usually 8-bit processors don't care much about endianness.
32157  This is not the case for the standard 8051 which only has an instruction
32158  to increment its 
32159 \emph on
32160 dptr
32161 \emph default
32162
32163 \begin_inset LatexCommand \index{DPTR}
32164
32165 \end_inset
32166
32167 -datapointer
32168 \emph on
32169  
32170 \emph default
32171 so little-endian is the more efficient byte order.
32172 \end_layout
32173
32174 \end_inset
32175
32176
32177 \begin_inset LatexCommand \index{little-endian}
32178
32179 \end_inset
32180
32181
32182 \begin_inset LatexCommand \index{Endianness}
32183
32184 \end_inset
32185
32186  format (i.e.
32187  lowest order first).
32188 \end_layout
32189
32190 \begin_layout Subsection
32191 Highest Order Bit
32192 \begin_inset LatexCommand \index{Highest Order Bit}
32193
32194 \end_inset
32195
32196  / Any Order Bit
32197 \begin_inset LatexCommand \index{Any Order Bit}
32198
32199 \end_inset
32200
32201
32202 \end_layout
32203
32204 \begin_layout Standard
32205 It is frequently required to obtain the highest order bit of an integral
32206  type (long, int, short or char types).
32207  Also obtaining any other order bit is not uncommon.
32208  SDCC recognizes the following expressions to yield the highest order bit
32209  and generates optimized code for it, e.g.:
32210 \end_layout
32211
32212 \begin_layout Verse
32213
32214 \family typewriter
32215 unsigned int gint; 
32216 \newline
32217
32218 \newline
32219 foo () { 
32220 \newline
32221 \InsetSpace ~
32222 \InsetSpace ~
32223 unsigned char hob1, aob1; 
32224 \newline
32225 \InsetSpace ~
32226 \InsetSpace ~
32227 bit hob2, hob3, aob2,
32228  aob3; 
32229 \newline
32230 \InsetSpace ~
32231 \InsetSpace ~
32232 ...
32233  
32234 \newline
32235 \InsetSpace ~
32236 \InsetSpace ~
32237 hob1 = (gint >> 15) & 1; 
32238 \newline
32239 \InsetSpace ~
32240 \InsetSpace ~
32241 hob2 = (gint >> 15) & 1; 
32242 \newline
32243 \InsetSpace ~
32244 \InsetSpace ~
32245 hob3 = gint & 0x8000;
32246  
32247 \newline
32248 \InsetSpace ~
32249 \InsetSpace ~
32250 aob1 = (gint >> 9) & 1; 
32251 \newline
32252 \InsetSpace ~
32253 \InsetSpace ~
32254 aob2 = (gint >> 8) & 1; 
32255 \newline
32256 \InsetSpace ~
32257 \InsetSpace ~
32258 aob3 = gint & 0x0800; 
32259 \newline
32260 \InsetSpace ~
32261 \InsetSpace ~
32262 ..
32263  
32264 \newline
32265 }
32266 \end_layout
32267
32268 \begin_layout Standard
32269 will generate the following code:
32270 \end_layout
32271
32272 \begin_layout Verse
32273
32274 \family typewriter
32275 \InsetSpace ~
32276 \InsetSpace ~
32277 \InsetSpace ~
32278 \InsetSpace ~
32279 \InsetSpace ~
32280 \InsetSpace ~
32281 \InsetSpace ~
32282 \InsetSpace ~
32283 \InsetSpace ~
32284 \InsetSpace ~
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  61 ;\InsetSpace ~
32301  hob.c 7 
32302 \newline
32303 000A E5*01\InsetSpace ~
32304 \InsetSpace ~
32305 \InsetSpace ~
32306 \InsetSpace ~
32307 \InsetSpace ~
32308 \InsetSpace ~
32309 \InsetSpace ~
32310 \InsetSpace ~
32311 \InsetSpace ~
32312 \InsetSpace ~
32313 \InsetSpace ~
32314 \InsetSpace ~
32315 \InsetSpace ~
32316 \InsetSpace ~
32317 \InsetSpace ~
32318  62\InsetSpace ~
32319 \InsetSpace ~
32320 \InsetSpace ~
32321 \InsetSpace ~
32322 \InsetSpace ~
32323 \InsetSpace ~
32324 \InsetSpace ~
32325 \InsetSpace ~
32326  mov\InsetSpace ~
32327 \InsetSpace ~
32328  a,(_gint + 1) 
32329 \newline
32330 000C 23\InsetSpace ~
32331 \InsetSpace ~
32332 \InsetSpace ~
32333 \InsetSpace ~
32334 \InsetSpace ~
32335 \InsetSpace ~
32336 \InsetSpace ~
32337 \InsetSpace ~
32338 \InsetSpace ~
32339 \InsetSpace ~
32340 \InsetSpace ~
32341 \InsetSpace ~
32342 \InsetSpace ~
32343 \InsetSpace ~
32344 \InsetSpace ~
32345 \InsetSpace ~
32346 \InsetSpace ~
32347 \InsetSpace ~
32348  63\InsetSpace ~
32349 \InsetSpace ~
32350 \InsetSpace ~
32351 \InsetSpace ~
32352 \InsetSpace ~
32353 \InsetSpace ~
32354 \InsetSpace ~
32355 \InsetSpace ~
32356  rl\InsetSpace ~
32357 \InsetSpace ~
32358 \InsetSpace ~
32359  a 
32360 \newline
32361 000D 54 01\InsetSpace ~
32362 \InsetSpace ~
32363 \InsetSpace ~
32364 \InsetSpace ~
32365 \InsetSpace ~
32366 \InsetSpace ~
32367 \InsetSpace ~
32368 \InsetSpace ~
32369 \InsetSpace ~
32370 \InsetSpace ~
32371 \InsetSpace ~
32372 \InsetSpace ~
32373 \InsetSpace ~
32374 \InsetSpace ~
32375 \InsetSpace ~
32376
32377  64\InsetSpace ~
32378 \InsetSpace ~
32379 \InsetSpace ~
32380 \InsetSpace ~
32381 \InsetSpace ~
32382 \InsetSpace ~
32383 \InsetSpace ~
32384 \InsetSpace ~
32385  anl\InsetSpace ~
32386 \InsetSpace ~
32387  a,#0x01 
32388 \newline
32389 000F F5*02\InsetSpace ~
32390 \InsetSpace ~
32391 \InsetSpace ~
32392 \InsetSpace ~
32393 \InsetSpace ~
32394 \InsetSpace ~
32395 \InsetSpace ~
32396 \InsetSpace ~
32397 \InsetSpace ~
32398 \InsetSpace ~
32399 \InsetSpace ~
32400 \InsetSpace ~
32401 \InsetSpace ~
32402 \InsetSpace ~
32403 \InsetSpace ~
32404  65\InsetSpace ~
32405 \InsetSpace ~
32406 \InsetSpace ~
32407 \InsetSpace ~
32408 \InsetSpace ~
32409 \InsetSpace ~
32410 \InsetSpace ~
32411 \InsetSpace ~
32412  mov\InsetSpace ~
32413 \InsetSpace ~
32414  _foo_hob1_1_1,a 
32415 \newline
32416 \InsetSpace ~
32417 \InsetSpace ~
32418 \InsetSpace ~
32419 \InsetSpace ~
32420 \InsetSpace ~
32421 \InsetSpace ~
32422 \InsetSpace ~
32423 \InsetSpace ~
32424 \InsetSpace ~
32425 \InsetSpace ~
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  66 ;\InsetSpace ~
32442  hob.c 8 
32443 \newline
32444 0011 E5*01\InsetSpace ~
32445 \InsetSpace ~
32446 \InsetSpace ~
32447 \InsetSpace ~
32448 \InsetSpace ~
32449 \InsetSpace ~
32450 \InsetSpace ~
32451 \InsetSpace ~
32452 \InsetSpace ~
32453 \InsetSpace ~
32454 \InsetSpace ~
32455 \InsetSpace ~
32456 \InsetSpace ~
32457 \InsetSpace ~
32458 \InsetSpace ~
32459
32460  67\InsetSpace ~
32461 \InsetSpace ~
32462 \InsetSpace ~
32463 \InsetSpace ~
32464 \InsetSpace ~
32465 \InsetSpace ~
32466 \InsetSpace ~
32467 \InsetSpace ~
32468  mov\InsetSpace ~
32469 \InsetSpace ~
32470  a,(_gint + 1) 
32471 \newline
32472 0013 33\InsetSpace ~
32473 \InsetSpace ~
32474 \InsetSpace ~
32475 \InsetSpace ~
32476 \InsetSpace ~
32477 \InsetSpace ~
32478 \InsetSpace ~
32479 \InsetSpace ~
32480 \InsetSpace ~
32481 \InsetSpace ~
32482 \InsetSpace ~
32483 \InsetSpace ~
32484 \InsetSpace ~
32485 \InsetSpace ~
32486 \InsetSpace ~
32487 \InsetSpace ~
32488 \InsetSpace ~
32489 \InsetSpace ~
32490  68\InsetSpace ~
32491 \InsetSpace ~
32492 \InsetSpace ~
32493 \InsetSpace ~
32494 \InsetSpace ~
32495 \InsetSpace ~
32496 \InsetSpace ~
32497 \InsetSpace ~
32498  rlc\InsetSpace ~
32499 \InsetSpace ~
32500  a 
32501 \newline
32502 0014 92*00\InsetSpace ~
32503 \InsetSpace ~
32504 \InsetSpace ~
32505 \InsetSpace ~
32506 \InsetSpace ~
32507 \InsetSpace ~
32508 \InsetSpace ~
32509 \InsetSpace ~
32510 \InsetSpace ~
32511 \InsetSpace ~
32512 \InsetSpace ~
32513 \InsetSpace ~
32514 \InsetSpace ~
32515 \InsetSpace ~
32516 \InsetSpace ~
32517  69\InsetSpace ~
32518 \InsetSpace ~
32519 \InsetSpace ~
32520 \InsetSpace ~
32521 \InsetSpace ~
32522 \InsetSpace ~
32523 \InsetSpace ~
32524 \InsetSpace ~
32525  mov\InsetSpace ~
32526 \InsetSpace ~
32527  _foo_hob2_1_1,c
32528  
32529 \newline
32530 \InsetSpace ~
32531 \InsetSpace ~
32532 \InsetSpace ~
32533 \InsetSpace ~
32534 \InsetSpace ~
32535 \InsetSpace ~
32536 \InsetSpace ~
32537 \InsetSpace ~
32538 \InsetSpace ~
32539 \InsetSpace ~
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  66 ;\InsetSpace ~
32556  hob.c 9 
32557 \newline
32558 0016 E5*01\InsetSpace ~
32559 \InsetSpace ~
32560 \InsetSpace ~
32561 \InsetSpace ~
32562 \InsetSpace ~
32563 \InsetSpace ~
32564 \InsetSpace ~
32565 \InsetSpace ~
32566 \InsetSpace ~
32567 \InsetSpace ~
32568 \InsetSpace ~
32569 \InsetSpace ~
32570 \InsetSpace ~
32571 \InsetSpace ~
32572 \InsetSpace ~
32573  67\InsetSpace ~
32574 \InsetSpace ~
32575 \InsetSpace ~
32576 \InsetSpace ~
32577 \InsetSpace ~
32578 \InsetSpace ~
32579 \InsetSpace ~
32580 \InsetSpace ~
32581  mov\InsetSpace ~
32582 \InsetSpace ~
32583  a,(_gint + 1) 
32584 \newline
32585 0018 33\InsetSpace ~
32586 \InsetSpace ~
32587 \InsetSpace ~
32588 \InsetSpace ~
32589 \InsetSpace ~
32590 \InsetSpace ~
32591 \InsetSpace ~
32592 \InsetSpace ~
32593 \InsetSpace ~
32594 \InsetSpace ~
32595 \InsetSpace ~
32596 \InsetSpace ~
32597 \InsetSpace ~
32598 \InsetSpace ~
32599 \InsetSpace ~
32600 \InsetSpace ~
32601 \InsetSpace ~
32602 \InsetSpace ~
32603  68\InsetSpace ~
32604 \InsetSpace ~
32605 \InsetSpace ~
32606 \InsetSpace ~
32607 \InsetSpace ~
32608 \InsetSpace ~
32609 \InsetSpace ~
32610 \InsetSpace ~
32611  rlc\InsetSpace ~
32612 \InsetSpace ~
32613  a 
32614 \newline
32615 0019 92*01\InsetSpace ~
32616 \InsetSpace ~
32617 \InsetSpace ~
32618 \InsetSpace ~
32619 \InsetSpace ~
32620 \InsetSpace ~
32621 \InsetSpace ~
32622 \InsetSpace ~
32623 \InsetSpace ~
32624 \InsetSpace ~
32625 \InsetSpace ~
32626 \InsetSpace ~
32627 \InsetSpace ~
32628 \InsetSpace ~
32629 \InsetSpace ~
32630
32631  69\InsetSpace ~
32632 \InsetSpace ~
32633 \InsetSpace ~
32634 \InsetSpace ~
32635 \InsetSpace ~
32636 \InsetSpace ~
32637 \InsetSpace ~
32638 \InsetSpace ~
32639  mov\InsetSpace ~
32640 \InsetSpace ~
32641  _foo_hob3_1_1,c 
32642 \newline
32643 \InsetSpace ~
32644 \InsetSpace ~
32645 \InsetSpace ~
32646 \InsetSpace ~
32647 \InsetSpace ~
32648 \InsetSpace ~
32649 \InsetSpace ~
32650 \InsetSpace ~
32651 \InsetSpace ~
32652 \InsetSpace ~
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  70 ;\InsetSpace ~
32669  hob.c 10 
32670 \newline
32671 001B E5*01\InsetSpace ~
32672 \InsetSpace ~
32673 \InsetSpace ~
32674 \InsetSpace ~
32675 \InsetSpace ~
32676 \InsetSpace ~
32677 \InsetSpace ~
32678 \InsetSpace ~
32679 \InsetSpace ~
32680 \InsetSpace ~
32681 \InsetSpace ~
32682 \InsetSpace ~
32683 \InsetSpace ~
32684 \InsetSpace ~
32685 \InsetSpace ~
32686  71\InsetSpace ~
32687 \InsetSpace ~
32688 \InsetSpace ~
32689 \InsetSpace ~
32690 \InsetSpace ~
32691 \InsetSpace ~
32692 \InsetSpace ~
32693 \InsetSpace ~
32694  mov\InsetSpace ~
32695 \InsetSpace ~
32696  a,(_gint + 1) 
32697 \newline
32698 001D
32699  03\InsetSpace ~
32700 \InsetSpace ~
32701 \InsetSpace ~
32702 \InsetSpace ~
32703 \InsetSpace ~
32704 \InsetSpace ~
32705 \InsetSpace ~
32706 \InsetSpace ~
32707 \InsetSpace ~
32708 \InsetSpace ~
32709 \InsetSpace ~
32710 \InsetSpace ~
32711 \InsetSpace ~
32712 \InsetSpace ~
32713 \InsetSpace ~
32714 \InsetSpace ~
32715 \InsetSpace ~
32716 \InsetSpace ~
32717  72\InsetSpace ~
32718 \InsetSpace ~
32719 \InsetSpace ~
32720 \InsetSpace ~
32721 \InsetSpace ~
32722 \InsetSpace ~
32723 \InsetSpace ~
32724 \InsetSpace ~
32725  rr\InsetSpace ~
32726 \InsetSpace ~
32727 \InsetSpace ~
32728  a 
32729 \newline
32730 001E 54 01\InsetSpace ~
32731 \InsetSpace ~
32732 \InsetSpace ~
32733 \InsetSpace ~
32734 \InsetSpace ~
32735 \InsetSpace ~
32736 \InsetSpace ~
32737 \InsetSpace ~
32738 \InsetSpace ~
32739 \InsetSpace ~
32740 \InsetSpace ~
32741 \InsetSpace ~
32742 \InsetSpace ~
32743 \InsetSpace ~
32744 \InsetSpace ~
32745  73\InsetSpace ~
32746 \InsetSpace ~
32747 \InsetSpace ~
32748 \InsetSpace ~
32749 \InsetSpace ~
32750 \InsetSpace ~
32751 \InsetSpace ~
32752 \InsetSpace ~
32753  anl\InsetSpace ~
32754 \InsetSpace ~
32755  a,#0x01 
32756 \newline
32757 0020 F5*03\InsetSpace ~
32758 \InsetSpace ~
32759 \InsetSpace ~
32760 \InsetSpace ~
32761 \InsetSpace ~
32762 \InsetSpace ~
32763 \InsetSpace ~
32764 \InsetSpace ~
32765 \InsetSpace ~
32766 \InsetSpace ~
32767 \InsetSpace ~
32768 \InsetSpace ~
32769 \InsetSpace ~
32770 \InsetSpace ~
32771 \InsetSpace ~
32772  74\InsetSpace ~
32773 \InsetSpace ~
32774 \InsetSpace ~
32775 \InsetSpace ~
32776 \InsetSpace ~
32777 \InsetSpace ~
32778 \InsetSpace ~
32779 \InsetSpace ~
32780  mov\InsetSpace ~
32781 \InsetSpace ~
32782  _foo_aob1_1_1,a
32783  
32784 \newline
32785 \InsetSpace ~
32786 \InsetSpace ~
32787 \InsetSpace ~
32788 \InsetSpace ~
32789 \InsetSpace ~
32790 \InsetSpace ~
32791 \InsetSpace ~
32792 \InsetSpace ~
32793 \InsetSpace ~
32794 \InsetSpace ~
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  75 ;\InsetSpace ~
32811  hob.c 11 
32812 \newline
32813 0022 E5*01\InsetSpace ~
32814 \InsetSpace ~
32815 \InsetSpace ~
32816 \InsetSpace ~
32817 \InsetSpace ~
32818 \InsetSpace ~
32819 \InsetSpace ~
32820 \InsetSpace ~
32821 \InsetSpace ~
32822 \InsetSpace ~
32823 \InsetSpace ~
32824 \InsetSpace ~
32825 \InsetSpace ~
32826 \InsetSpace ~
32827 \InsetSpace ~
32828  76\InsetSpace ~
32829 \InsetSpace ~
32830 \InsetSpace ~
32831 \InsetSpace ~
32832 \InsetSpace ~
32833 \InsetSpace ~
32834 \InsetSpace ~
32835 \InsetSpace ~
32836  mov\InsetSpace ~
32837 \InsetSpace ~
32838  a,(_gint + 1) 
32839 \newline
32840 0024 13\InsetSpace ~
32841 \InsetSpace ~
32842 \InsetSpace ~
32843 \InsetSpace ~
32844 \InsetSpace ~
32845 \InsetSpace ~
32846 \InsetSpace ~
32847 \InsetSpace ~
32848 \InsetSpace ~
32849 \InsetSpace ~
32850 \InsetSpace ~
32851 \InsetSpace ~
32852 \InsetSpace ~
32853 \InsetSpace ~
32854 \InsetSpace ~
32855 \InsetSpace ~
32856 \InsetSpace ~
32857 \InsetSpace ~
32858  77\InsetSpace ~
32859 \InsetSpace ~
32860 \InsetSpace ~
32861 \InsetSpace ~
32862 \InsetSpace ~
32863 \InsetSpace ~
32864 \InsetSpace ~
32865 \InsetSpace ~
32866  rrc\InsetSpace ~
32867 \InsetSpace ~
32868  a 
32869 \newline
32870 0025 92*02\InsetSpace ~
32871 \InsetSpace ~
32872 \InsetSpace ~
32873 \InsetSpace ~
32874 \InsetSpace ~
32875 \InsetSpace ~
32876 \InsetSpace ~
32877 \InsetSpace ~
32878 \InsetSpace ~
32879 \InsetSpace ~
32880 \InsetSpace ~
32881 \InsetSpace ~
32882 \InsetSpace ~
32883 \InsetSpace ~
32884 \InsetSpace ~
32885
32886  78\InsetSpace ~
32887 \InsetSpace ~
32888 \InsetSpace ~
32889 \InsetSpace ~
32890 \InsetSpace ~
32891 \InsetSpace ~
32892 \InsetSpace ~
32893 \InsetSpace ~
32894  mov\InsetSpace ~
32895 \InsetSpace ~
32896  _foo_aob2_1_1,c 
32897 \newline
32898 \InsetSpace ~
32899 \InsetSpace ~
32900 \InsetSpace ~
32901 \InsetSpace ~
32902 \InsetSpace ~
32903 \InsetSpace ~
32904 \InsetSpace ~
32905 \InsetSpace ~
32906 \InsetSpace ~
32907 \InsetSpace ~
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  79 ;\InsetSpace ~
32924  hob.c 12 
32925 \newline
32926 0027 E5*01\InsetSpace ~
32927 \InsetSpace ~
32928 \InsetSpace ~
32929 \InsetSpace ~
32930 \InsetSpace ~
32931 \InsetSpace ~
32932 \InsetSpace ~
32933 \InsetSpace ~
32934 \InsetSpace ~
32935 \InsetSpace ~
32936 \InsetSpace ~
32937 \InsetSpace ~
32938 \InsetSpace ~
32939 \InsetSpace ~
32940 \InsetSpace ~
32941  80\InsetSpace ~
32942 \InsetSpace ~
32943 \InsetSpace ~
32944 \InsetSpace ~
32945 \InsetSpace ~
32946 \InsetSpace ~
32947 \InsetSpace ~
32948 \InsetSpace ~
32949  mov\InsetSpace ~
32950 \InsetSpace ~
32951  a,(_gint + 1) 
32952 \newline
32953 0029
32954  A2 E3\InsetSpace ~
32955 \InsetSpace ~
32956 \InsetSpace ~
32957 \InsetSpace ~
32958 \InsetSpace ~
32959 \InsetSpace ~
32960 \InsetSpace ~
32961 \InsetSpace ~
32962 \InsetSpace ~
32963 \InsetSpace ~
32964 \InsetSpace ~
32965 \InsetSpace ~
32966 \InsetSpace ~
32967 \InsetSpace ~
32968 \InsetSpace ~
32969  81\InsetSpace ~
32970 \InsetSpace ~
32971 \InsetSpace ~
32972 \InsetSpace ~
32973 \InsetSpace ~
32974 \InsetSpace ~
32975 \InsetSpace ~
32976 \InsetSpace ~
32977  mov\InsetSpace ~
32978 \InsetSpace ~
32979  c,acc[3] 
32980 \newline
32981 002B 92*03\InsetSpace ~
32982 \InsetSpace ~
32983 \InsetSpace ~
32984 \InsetSpace ~
32985 \InsetSpace ~
32986 \InsetSpace ~
32987 \InsetSpace ~
32988 \InsetSpace ~
32989 \InsetSpace ~
32990 \InsetSpace ~
32991 \InsetSpace ~
32992 \InsetSpace ~
32993 \InsetSpace ~
32994 \InsetSpace ~
32995 \InsetSpace ~
32996  82\InsetSpace ~
32997 \InsetSpace ~
32998 \InsetSpace ~
32999 \InsetSpace ~
33000 \InsetSpace ~
33001 \InsetSpace ~
33002 \InsetSpace ~
33003 \InsetSpace ~
33004  mov\InsetSpace ~
33005 \InsetSpace ~
33006  _foo_aob3_1_1,c 
33007 \end_layout
33008
33009 \begin_layout Standard
33010 Other variations of these cases however will 
33011 \emph on
33012 not
33013 \emph default
33014  be recognized.
33015  They are standard C expressions, so I heartily recommend these be the only
33016  way to get the highest order bit, (it is portable).
33017  Of course it will be recognized even if it is embedded in other expressions,
33018  e.g.:
33019 \end_layout
33020
33021 \begin_layout Verse
33022
33023 \family typewriter
33024 xyz = gint + ((gint >> 15) & 1);
33025 \end_layout
33026
33027 \begin_layout Standard
33028 will still be recognized.
33029 \end_layout
33030
33031 \begin_layout Subsection
33032 Higher Order Byte
33033 \begin_inset LatexCommand \index{Higher Order Byte}
33034
33035 \end_inset
33036
33037  / Higher Order Word
33038 \begin_inset LatexCommand \index{Higher Order Word}
33039
33040 \end_inset
33041
33042
33043 \end_layout
33044
33045 \begin_layout Standard
33046 It is also frequently required to obtain a higher order byte or word of
33047  a larger integral type (long, int or short types).
33048  SDCC recognizes the following expressions to yield the higher order byte
33049  or word and generates optimized code for it, e.g.:
33050 \end_layout
33051
33052 \begin_layout Verse
33053
33054 \family typewriter
33055 unsigned int gint; 
33056 \newline
33057 unsigned long int glong; 
33058 \newline
33059
33060 \newline
33061 foo () { 
33062 \newline
33063 \InsetSpace ~
33064 \InsetSpace ~
33065 unsigned char hob1,
33066  hob2; 
33067 \newline
33068 \InsetSpace ~
33069 \InsetSpace ~
33070 unsigned int how1, how2; 
33071 \newline
33072 \InsetSpace ~
33073 \InsetSpace ~
33074 ...
33075  
33076 \newline
33077 \InsetSpace ~
33078 \InsetSpace ~
33079 hob1 = (gint >> 8) & 0xFF; 
33080 \newline
33081 \InsetSpace ~
33082 \InsetSpace ~
33083 hob2 = glong >> 24; 
33084 \newline
33085 \InsetSpace ~
33086 \InsetSpace ~
33087 how1 = (glong >> 16) & 0xFFFF;
33088  
33089 \newline
33090 \InsetSpace ~
33091 \InsetSpace ~
33092 how2 = glong >> 8; 
33093 \newline
33094 \InsetSpace ~
33095 \InsetSpace ~
33096 ..
33097  
33098 \newline
33099 }
33100 \end_layout
33101
33102 \begin_layout Standard
33103 will generate the following code:
33104 \end_layout
33105
33106 \begin_layout Verse
33107
33108 \family typewriter
33109 \InsetSpace ~
33110 \InsetSpace ~
33111 \InsetSpace ~
33112 \InsetSpace ~
33113 \InsetSpace ~
33114 \InsetSpace ~
33115 \InsetSpace ~
33116 \InsetSpace ~
33117 \InsetSpace ~
33118 \InsetSpace ~
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  91 ;\InsetSpace ~
33135  hob.c 15 
33136 \newline
33137 0037 85*01*06\InsetSpace ~
33138 \InsetSpace ~
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 \InsetSpace ~
33142 \InsetSpace ~
33143 \InsetSpace ~
33144 \InsetSpace ~
33145 \InsetSpace ~
33146 \InsetSpace ~
33147 \InsetSpace ~
33148 \InsetSpace ~
33149  92\InsetSpace ~
33150 \InsetSpace ~
33151 \InsetSpace ~
33152 \InsetSpace ~
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 \InsetSpace ~
33156 \InsetSpace ~
33157  mov\InsetSpace ~
33158 \InsetSpace ~
33159  _foo_hob1_1_1,(_gint + 1) 
33160 \newline
33161 \InsetSpace ~
33162 \InsetSpace ~
33163 \InsetSpace ~
33164 \InsetSpace ~
33165 \InsetSpace ~
33166 \InsetSpace ~
33167 \InsetSpace ~
33168 \InsetSpace ~
33169 \InsetSpace ~
33170 \InsetSpace ~
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  93 ;\InsetSpace ~
33187  hob.c
33188  16 
33189 \newline
33190 003A 85*05*07\InsetSpace ~
33191 \InsetSpace ~
33192 \InsetSpace ~
33193 \InsetSpace ~
33194 \InsetSpace ~
33195 \InsetSpace ~
33196 \InsetSpace ~
33197 \InsetSpace ~
33198 \InsetSpace ~
33199 \InsetSpace ~
33200 \InsetSpace ~
33201 \InsetSpace ~
33202  94\InsetSpace ~
33203 \InsetSpace ~
33204 \InsetSpace ~
33205 \InsetSpace ~
33206 \InsetSpace ~
33207 \InsetSpace ~
33208 \InsetSpace ~
33209 \InsetSpace ~
33210  mov\InsetSpace ~
33211 \InsetSpace ~
33212  _foo_hob2_1_1,(_glong + 3) 
33213 \newline
33214 \InsetSpace ~
33215 \InsetSpace ~
33216 \InsetSpace ~
33217 \InsetSpace ~
33218 \InsetSpace ~
33219 \InsetSpace ~
33220 \InsetSpace ~
33221 \InsetSpace ~
33222 \InsetSpace ~
33223 \InsetSpace ~
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  95 ;\InsetSpace ~
33240  hob.c 17 
33241 \newline
33242 003D 85*04*08\InsetSpace ~
33243 \InsetSpace ~
33244 \InsetSpace ~
33245 \InsetSpace ~
33246 \InsetSpace ~
33247 \InsetSpace ~
33248 \InsetSpace ~
33249 \InsetSpace ~
33250 \InsetSpace ~
33251 \InsetSpace ~
33252 \InsetSpace ~
33253 \InsetSpace ~
33254
33255  96\InsetSpace ~
33256 \InsetSpace ~
33257 \InsetSpace ~
33258 \InsetSpace ~
33259 \InsetSpace ~
33260 \InsetSpace ~
33261 \InsetSpace ~
33262 \InsetSpace ~
33263  mov\InsetSpace ~
33264 \InsetSpace ~
33265  _foo_how1_1_1,(_glong + 2) 
33266 \newline
33267 0040 85*05*09\InsetSpace ~
33268 \InsetSpace ~
33269 \InsetSpace ~
33270 \InsetSpace ~
33271 \InsetSpace ~
33272 \InsetSpace ~
33273 \InsetSpace ~
33274 \InsetSpace ~
33275 \InsetSpace ~
33276 \InsetSpace ~
33277 \InsetSpace ~
33278 \InsetSpace ~
33279  97\InsetSpace ~
33280 \InsetSpace ~
33281 \InsetSpace ~
33282 \InsetSpace ~
33283 \InsetSpace ~
33284 \InsetSpace ~
33285 \InsetSpace ~
33286 \InsetSpace ~
33287  mov\InsetSpace ~
33288 \InsetSpace ~
33289  (_foo_how1_1_1 +
33290  1),(_glong + 3) 
33291 \newline
33292 0043 85*03*0A\InsetSpace ~
33293 \InsetSpace ~
33294 \InsetSpace ~
33295 \InsetSpace ~
33296 \InsetSpace ~
33297 \InsetSpace ~
33298 \InsetSpace ~
33299 \InsetSpace ~
33300 \InsetSpace ~
33301 \InsetSpace ~
33302 \InsetSpace ~
33303 \InsetSpace ~
33304  98\InsetSpace ~
33305 \InsetSpace ~
33306 \InsetSpace ~
33307 \InsetSpace ~
33308 \InsetSpace ~
33309 \InsetSpace ~
33310 \InsetSpace ~
33311 \InsetSpace ~
33312  mov\InsetSpace ~
33313 \InsetSpace ~
33314  _foo_how2_1_1,(_glong + 1) 
33315 \newline
33316 0046 85*04*0B\InsetSpace ~
33317 \InsetSpace ~
33318 \InsetSpace ~
33319 \InsetSpace ~
33320 \InsetSpace ~
33321 \InsetSpace ~
33322 \InsetSpace ~
33323 \InsetSpace ~
33324 \InsetSpace ~
33325 \InsetSpace ~
33326 \InsetSpace ~
33327 \InsetSpace ~
33328
33329  99\InsetSpace ~
33330 \InsetSpace ~
33331 \InsetSpace ~
33332 \InsetSpace ~
33333 \InsetSpace ~
33334 \InsetSpace ~
33335 \InsetSpace ~
33336 \InsetSpace ~
33337  mov\InsetSpace ~
33338 \InsetSpace ~
33339  (_foo_how2_1_1 + 1),(_glong + 2) 
33340 \end_layout
33341
33342 \begin_layout Standard
33343 Again, variations of these cases may 
33344 \emph on
33345 not
33346 \emph default
33347  be recognized.
33348  They are standard C expressions, so I heartily recommend these be the only
33349  way to get the higher order byte/word, (it is portable).
33350  Of course it will be recognized even if it is embedded in other expressions,
33351  e.g.:
33352 \end_layout
33353
33354 \begin_layout Verse
33355
33356 \family typewriter
33357 xyz = gint + ((gint >> 8) & 0xFF);
33358 \end_layout
33359
33360 \begin_layout Standard
33361 will still be recognized.
33362 \end_layout
33363
33364 \begin_layout Subsection
33365 Peephole Optimizer
33366 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
33367
33368 \end_inset
33369
33370
33371 \begin_inset LatexCommand \index{Peephole optimizer}
33372
33373 \end_inset
33374
33375
33376 \end_layout
33377
33378 \begin_layout Standard
33379 The compiler uses a rule based, pattern matching and re-writing mechanism
33380  for peep-hole optimization.
33381  It is inspired by 
33382 \emph on
33383 copt
33384 \emph default
33385  a peep-hole optimizer by Christopher W.
33386  Fraser (cwfraser\InsetSpace ~
33387 @\InsetSpace ~
33388 microsoft.com).
33389  A default set of rules are compiled into the compiler, additional rules
33390  may be added with the 
33391 \emph on
33392 -
33393 \begin_inset ERT
33394 status collapsed
33395
33396 \begin_layout Standard
33397
33398
33399 \backslash
33400 /
33401 \end_layout
33402
33403 \end_inset
33404
33405 -peep-file
33406 \begin_inset LatexCommand \index{-\/-peep-file}
33407
33408 \end_inset
33409
33410  <filename>
33411 \emph default
33412  option.
33413  The rule language is best illustrated with examples.
33414 \end_layout
33415
33416 \begin_layout Verse
33417
33418 \family typewriter
33419 replace { 
33420 \newline
33421 \InsetSpace ~
33422 \InsetSpace ~
33423 mov %1,a 
33424 \newline
33425 \InsetSpace ~
33426 \InsetSpace ~
33427 mov a,%1
33428 \newline
33429 } by {
33430 \newline
33431 \InsetSpace ~
33432 \InsetSpace ~
33433 mov %1,a
33434 \newline
33435 }
33436 \end_layout
33437
33438 \begin_layout Standard
33439 The above rule will change the following assembly
33440 \begin_inset LatexCommand \index{Assembler routines}
33441
33442 \end_inset
33443
33444  sequence:
33445 \end_layout
33446
33447 \begin_layout Verse
33448
33449 \family typewriter
33450 mov r1,a 
33451 \newline
33452 mov a,r1
33453 \end_layout
33454
33455 \begin_layout Standard
33456 to
33457 \end_layout
33458
33459 \begin_layout Verse
33460
33461 \family typewriter
33462 mov r1,a
33463 \end_layout
33464
33465 \begin_layout Standard
33466 Note: All occurrences of a 
33467 \emph on
33468 %n
33469 \emph default
33470  (pattern variable) must denote the same string.
33471  With the above rule, the assembly sequence:
33472 \end_layout
33473
33474 \begin_layout Verse
33475
33476 \family typewriter
33477 mov r1,a 
33478 \newline
33479 mov a,r2
33480 \end_layout
33481
33482 \begin_layout Standard
33483 will remain unmodified.
33484 \newline
33485
33486 \newline
33487 Other special case optimizations may be added by the
33488  user (via 
33489 \emph on
33490 -
33491 \begin_inset ERT
33492 status collapsed
33493
33494 \begin_layout Standard
33495
33496
33497 \backslash
33498 /
33499 \end_layout
33500
33501 \end_inset
33502
33503 -peep-file option
33504 \emph default
33505 ).
33506  E.g.
33507  some variants of the 8051 MCU
33508 \begin_inset LatexCommand \index{MCS51 variants}
33509
33510 \end_inset
33511
33512  allow only 
33513 \family typewriter
33514 ajmp
33515 \family default
33516  and 
33517 \family typewriter
33518 acall
33519 \family default
33520 .
33521  The following two rules will change all 
33522 \family typewriter
33523 ljmp
33524 \family default
33525  and 
33526 \family typewriter
33527 lcall
33528 \family default
33529  to 
33530 \family typewriter
33531 ajmp
33532 \family default
33533  and 
33534 \family typewriter
33535 acall
33536 \end_layout
33537
33538 \begin_layout Verse
33539
33540 \family typewriter
33541 replace { lcall %1 } by { acall %1 } 
33542 \newline
33543 replace { ljmp %1 } by { ajmp %1 }
33544 \end_layout
33545
33546 \begin_layout Standard
33547 The 
33548 \emph on
33549 inline-assembler code
33550 \emph default
33551  is also passed through the peep hole optimizer, thus the peephole optimizer
33552  can also be used as an assembly level macro expander.
33553  The rules themselves are MCU dependent whereas the rule language infra-structur
33554 e is MCU independent.
33555  Peephole optimization rules for other MCU can be easily programmed using
33556  the rule language.
33557 \newline
33558
33559 \newline
33560 The syntax for a rule is as follows:
33561 \end_layout
33562
33563 \begin_layout Verse
33564
33565 \family typewriter
33566 rule := replace [ restart ] '{' <assembly sequence> '
33567 \backslash
33568 n' 
33569 \newline
33570 \InsetSpace ~
33571  \InsetSpace ~
33572  \InsetSpace ~
33573  \InsetSpace ~
33574  \InsetSpace ~
33575  \InsetSpace ~
33576  \InsetSpace ~
33577  \InsetSpace ~
33578  \InsetSpace ~
33579  \InsetSpace ~
33580  \InsetSpace ~
33581  \InsetSpace ~
33582  \InsetSpace ~
33583  \InsetSpace ~
33584  '}' by '{' '
33585 \backslash
33586 n' 
33587 \newline
33588 \InsetSpace ~
33589  \InsetSpace ~
33590  \InsetSpace ~
33591  \InsetSpace ~
33592  \InsetSpace ~
33593  \InsetSpace ~
33594  \InsetSpace ~
33595  \InsetSpace ~
33596  \InsetSpace ~
33597  \InsetSpace ~
33598  \InsetSpace ~
33599  \InsetSpace ~
33600  \InsetSpace ~
33601  \InsetSpace ~
33602  \InsetSpace ~
33603  \InsetSpace ~
33604  <assembly sequence> '
33605 \backslash
33606 n' 
33607 \newline
33608 \InsetSpace ~
33609  \InsetSpace ~
33610  \InsetSpace ~
33611  \InsetSpace ~
33612  \InsetSpace ~
33613  \InsetSpace ~
33614  \InsetSpace ~
33615  \InsetSpace ~
33616  \InsetSpace ~
33617  \InsetSpace ~
33618  \InsetSpace ~
33619  \InsetSpace ~
33620  \InsetSpace ~
33621  \InsetSpace ~
33622  '}' [if <functionName> ] '
33623 \backslash
33624 n' 
33625 \end_layout
33626
33627 \begin_layout Standard
33628 <assembly sequence> := assembly instruction (each instruction including
33629  labels must be on a separate line).
33630 \newline
33631
33632 \newline
33633 The optimizer will apply to the rules
33634  one by one from the top in the sequence of their appearance, it will terminate
33635  when all rules are exhausted.
33636  If the 'restart' option is specified, then the optimizer will start matching
33637  the rules again from the top, this option for a rule is expensive (performance)
33638 , it is intended to be used in situations where a transformation will trigger
33639  the same rule again.
33640  An example of this (not a good one, it has side effects) is the following
33641  rule:
33642 \end_layout
33643
33644 \begin_layout Verse
33645
33646 \family typewriter
33647 replace restart { 
33648 \newline
33649 \InsetSpace ~
33650 \InsetSpace ~
33651 pop %1 
33652 \newline
33653 \InsetSpace ~
33654 \InsetSpace ~
33655 push %1 } by { 
33656 \newline
33657 \InsetSpace ~
33658 \InsetSpace ~
33659 ; nop 
33660 \newline
33661 }
33662 \end_layout
33663
33664 \begin_layout Standard
33665 Note that the replace pattern cannot be a blank, but can be a comment line.
33666  Without the 'restart' option only the innermost 'pop' 'push' pair would
33667  be eliminated, i.e.:
33668 \end_layout
33669
33670 \begin_layout Verse
33671
33672 \family typewriter
33673 pop ar1 
33674 \newline
33675 pop ar2 
33676 \newline
33677 push ar2 
33678 \newline
33679 push ar1
33680 \end_layout
33681
33682 \begin_layout Standard
33683 would result in:
33684 \end_layout
33685
33686 \begin_layout Verse
33687
33688 \family typewriter
33689 pop ar1 
33690 \newline
33691 ; nop 
33692 \newline
33693 push ar1
33694 \end_layout
33695
33696 \begin_layout Standard
33697
33698 \emph on
33699 with
33700 \emph default
33701  the restart option the rule will be applied again to the resulting code
33702  and then all the pop-push pairs will be eliminated to yield:
33703 \end_layout
33704
33705 \begin_layout Verse
33706
33707 \family typewriter
33708 ; nop 
33709 \newline
33710 ; nop
33711 \end_layout
33712
33713 \begin_layout Standard
33714 A conditional function can be attached to a rule.
33715  Attaching rules are somewhat more involved, let me illustrate this with
33716  an example.
33717 \end_layout
33718
33719 \begin_layout Verse
33720
33721 \family typewriter
33722 replace { 
33723 \newline
33724 \InsetSpace ~
33725  \InsetSpace ~
33726  \InsetSpace ~
33727 ljmp %5 
33728 \newline
33729 %2:
33730 \newline
33731 } by { 
33732 \newline
33733 \InsetSpace ~
33734  \InsetSpace ~
33735  \InsetSpace ~
33736 sjmp %5 
33737 \newline
33738 %2:
33739 \newline
33740 } if labelInRange
33741 \end_layout
33742
33743 \begin_layout Standard
33744 The optimizer does a look-up of a function name table defined in function
33745  
33746 \emph on
33747 callFuncByName
33748 \emph default
33749  in the source file SDCCpeeph.c, with the name 
33750 \emph on
33751 labelInRange
33752 \emph default
33753 .
33754  If it finds a corresponding entry the function is called.
33755  Note there can be no parameters specified for these functions, in this
33756  case the use of 
33757 \emph on
33758 %5
33759 \emph default
33760  is crucial, since the function 
33761 \emph on
33762 labelInRange
33763 \emph default
33764  expects to find the label in that particular variable (the hash table containin
33765 g the variable bindings is passed as a parameter).
33766  If you want to code more such functions, take a close look at the function
33767  labelInRange and the calling mechanism in source file SDCCpeeph.c.
33768  Currently implemented are 
33769 \emph on
33770 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
33771  24bitMode, portIsDS390, 24bitModeAndPortDS390 
33772 \emph default
33773 and
33774 \emph on
33775  notVolatile
33776 \emph default
33777 .
33778 \end_layout
33779
33780 \begin_layout Standard
33781 I know this whole thing is a little kludgey, but maybe some day we will
33782  have some better means.
33783  If you are looking at this file, you will see the default rules that are
33784  compiled into the compiler, you can add your own rules in the default set
33785  there if you get tired of specifying the -
33786 \begin_inset ERT
33787 status collapsed
33788
33789 \begin_layout Standard
33790
33791
33792 \backslash
33793 /
33794 \end_layout
33795
33796 \end_inset
33797
33798 -peep-file option.
33799 \end_layout
33800
33801 \begin_layout Section
33802 ANSI-Compliance
33803 \begin_inset LatexCommand \index{ANSI-compliance}
33804
33805 \end_inset
33806
33807
33808 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
33809
33810 \end_inset
33811
33812
33813 \end_layout
33814
33815 \begin_layout Standard
33816 The latest publically available version of the standard 
33817 \emph on
33818 ISO/IEC 9899 - Programming languages - C
33819 \emph default
33820  should be available at: 
33821 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
33822
33823 \end_inset
33824
33825 .
33826 \newline
33827
33828 \end_layout
33829
33830 \begin_layout Standard
33831 Deviations from the compliance:
33832 \end_layout
33833
33834 \begin_layout Itemize
33835 functions are not reentrant
33836 \begin_inset LatexCommand \index{reentrant}
33837
33838 \end_inset
33839
33840  unless explicitly declared as such or the 
33841 \series bold
33842 -
33843 \begin_inset ERT
33844 status collapsed
33845
33846 \begin_layout Standard
33847
33848
33849 \backslash
33850 /
33851 \end_layout
33852
33853 \end_inset
33854
33855 -stack-auto
33856 \begin_inset LatexCommand \index{-\/-stack-auto}
33857
33858 \end_inset
33859
33860
33861 \series default
33862  command line option is specified.
33863 \end_layout
33864
33865 \begin_layout Itemize
33866 structures
33867 \begin_inset LatexCommand \index{struct}
33868
33869 \end_inset
33870
33871  and unions
33872 \begin_inset LatexCommand \index{union}
33873
33874 \end_inset
33875
33876  cannot be assigned values directly, cannot be passed as function parameters
33877  or assigned to each other and cannot be a return value
33878 \begin_inset LatexCommand \index{return value}
33879
33880 \end_inset
33881
33882  from a function, e.g.:
33883 \end_layout
33884
33885 \begin_deeper
33886 \begin_layout Verse
33887
33888 \family typewriter
33889 struct s { ...
33890  }; 
33891 \newline
33892 struct s s1, s2; 
33893 \newline
33894 foo() 
33895 \newline
33896
33897 \newline
33898 \InsetSpace ~
33899 \InsetSpace ~
33900 \InsetSpace ~
33901 \InsetSpace ~
33902 ...
33903  
33904 \newline
33905 \InsetSpace ~
33906 \InsetSpace ~
33907 \InsetSpace ~
33908 \InsetSpace ~
33909 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
33910 \newline
33911 \InsetSpace ~
33912 \InsetSpace ~
33913 \InsetSpace ~
33914 \InsetSpace ~
33915 ...
33916  
33917 \newline
33918 }
33919 \newline
33920
33921 \series bold
33922 struct
33923 \series default
33924  s foo1 (
33925 \series bold
33926 struct
33927 \series default
33928  s parms) /* invalid in SDCC although allowed in ANSI */
33929 \newline
33930
33931 \newline
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 \InsetSpace ~
33935 \InsetSpace ~
33936 struct s rets;
33937  
33938 \newline
33939 \InsetSpace ~
33940 \InsetSpace ~
33941 \InsetSpace ~
33942 \InsetSpace ~
33943 ...
33944  
33945 \newline
33946 \InsetSpace ~
33947 \InsetSpace ~
33948 \InsetSpace ~
33949 \InsetSpace ~
33950 return rets; /* is invalid in SDCC although allowed in ANSI */ 
33951 \newline
33952 }
33953 \end_layout
33954
33955 \end_deeper
33956 \begin_layout Itemize
33957 initialization of structure arrays must be fully braced.
33958 \end_layout
33959
33960 \begin_deeper
33961 \begin_layout Verse
33962
33963 \family typewriter
33964 struct s { char x } a[] = {1, 2};\InsetSpace ~
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 \InsetSpace ~
33968 \InsetSpace ~
33969 /* invalid in SDCC */
33970 \newline
33971 struct s { char x
33972  } a[] = {{1}, {2}}; /* OK */
33973 \end_layout
33974
33975 \end_deeper
33976 \begin_layout Itemize
33977 'long long
33978 \begin_inset LatexCommand \index{long long (not supported)}
33979
33980 \end_inset
33981
33982 ' (64 bit integers
33983 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
33984
33985 \end_inset
33986
33987 ) not supported.
33988 \end_layout
33989
33990 \begin_layout Itemize
33991 'double
33992 \begin_inset LatexCommand \index{double (not supported)}
33993
33994 \end_inset
33995
33996 ' precision floating point 
33997 \begin_inset LatexCommand \index{Floating point support}
33998
33999 \end_inset
34000
34001 not supported.
34002 \end_layout
34003
34004 \begin_layout Itemize
34005 Old K&R style
34006 \begin_inset LatexCommand \index{K\&R style}
34007
34008 \end_inset
34009
34010  function declarations are NOT allowed.
34011 \end_layout
34012
34013 \begin_deeper
34014 \begin_layout Verse
34015
34016 \family typewriter
34017 foo(i,j) /* this old style of function declarations */ 
34018 \newline
34019 int i,j; /* are valid
34020  in ANSI but not valid in SDCC */ 
34021 \newline
34022
34023 \newline
34024 \InsetSpace ~
34025 \InsetSpace ~
34026 \InsetSpace ~
34027 \InsetSpace ~
34028 ...
34029  
34030 \newline
34031 }
34032 \end_layout
34033
34034 \end_deeper
34035 \begin_layout Itemize
34036 Most enhancements in C99 are not supported, f.e.:
34037 \end_layout
34038
34039 \begin_deeper
34040 \begin_layout Verse
34041
34042 \family typewriter
34043 \series bold
34044 inline
34045 \begin_inset LatexCommand \index{inline (not supported)}
34046
34047 \end_inset
34048
34049
34050 \series default
34051  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
34052  in C99.
34053  An empty define 
34054 \emph on
34055 #define inline
34056 \emph default
34057  can be used as a work around */
34058 \newline
34059
34060 \newline
34061 for (
34062 \series bold
34063 int
34064 \series default
34065  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
34066 \end_layout
34067
34068 \end_deeper
34069 \begin_layout Itemize
34070 Certain words that are valid identifiers in the standard may be reserved
34071  words in SDCC unless the 
34072 \series bold
34073 -
34074 \begin_inset ERT
34075 status collapsed
34076
34077 \begin_layout Standard
34078
34079
34080 \backslash
34081 /
34082 \end_layout
34083
34084 \end_inset
34085
34086 -std-c89
34087 \begin_inset LatexCommand \index{-\/-std-c89}
34088
34089 \end_inset
34090
34091  or -
34092 \begin_inset ERT
34093 status collapsed
34094
34095 \begin_layout Standard
34096
34097
34098 \backslash
34099 /
34100 \end_layout
34101
34102 \end_inset
34103
34104 -std-c99
34105 \begin_inset LatexCommand \index{-\/-std-c99}
34106
34107 \end_inset
34108
34109
34110 \series default
34111  command line options are used.
34112  These may include (depending on the selected processor): 'at', 'banked',
34113  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
34114 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
34115  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
34116  '_naked'.
34117  Compliant equivalents of these keywords are always available in a form
34118  that begin with two underscores
34119 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
34120
34121 \end_inset
34122
34123 , f.e.
34124  '__data' instead of 'data'.
34125 \end_layout
34126
34127 \begin_layout Section
34128 Cyclomatic Complexity
34129 \begin_inset LatexCommand \index{Cyclomatic complexity}
34130
34131 \end_inset
34132
34133
34134 \end_layout
34135
34136 \begin_layout Standard
34137 Cyclomatic complexity of a function is defined as the number of independent
34138  paths the program can take during execution of the function.
34139  This is an important number since it defines the number test cases you
34140  have to generate to validate the function.
34141  The accepted industry standard for complexity number is 10, if the cyclomatic
34142  complexity reported by SDCC exceeds 10 you should think about simplification
34143  of the function logic.
34144  Note that the complexity level is not related to the number of lines of
34145  code in a function.
34146  Large functions can have low complexity, and small functions can have large
34147  complexity levels.
34148  
34149 \newline
34150
34151 \newline
34152 SDCC uses the following formula to compute the complexity:
34153 \newline
34154
34155 \end_layout
34156
34157 \begin_layout Standard
34158 complexity = (number of edges in control flow graph) - (number of nodes
34159  in control flow graph) + 2;
34160 \newline
34161
34162 \newline
34163 Having said that the industry standard is 10,
34164  you should be aware that in some cases it be may unavoidable to have a
34165  complexity level of less than 10.
34166  For example if you have switch statement with more than 10 case labels,
34167  each case label adds one to the complexity level.
34168  The complexity level is by no means an absolute measure of the algorithmic
34169  complexity of the function, it does however provide a good starting point
34170  for which functions you might look at for further optimization.
34171 \end_layout
34172
34173 \begin_layout Section
34174 Retargetting for other Processors
34175 \end_layout
34176
34177 \begin_layout Standard
34178 The issues for retargetting the compiler are far too numerous to be covered
34179  by this document.
34180  What follows is a brief description of each of the seven phases of the
34181  compiler and its MCU dependency.
34182 \end_layout
34183
34184 \begin_layout Itemize
34185 Parsing the source and building the annotated parse tree.
34186  This phase is largely MCU independent (except for the language extensions).
34187  Syntax & semantic checks are also done in this phase, along with some initial
34188  optimizations like back patching labels and the pattern matching optimizations
34189  like bit-rotation etc.
34190 \end_layout
34191
34192 \begin_layout Itemize
34193 The second phase involves generating an intermediate code which can be easy
34194  manipulated during the later phases.
34195  This phase is entirely MCU independent.
34196  The intermediate code generation assumes the target machine has unlimited
34197  number of registers, and designates them with the name iTemp.
34198  The compiler can be made to dump a human readable form of the code generated
34199  by using the -
34200 \begin_inset ERT
34201 status collapsed
34202
34203 \begin_layout Standard
34204
34205
34206 \backslash
34207 /
34208 \end_layout
34209
34210 \end_inset
34211
34212 -dumpraw option.
34213 \end_layout
34214
34215 \begin_layout Itemize
34216 This phase does the bulk of the standard optimizations and is also MCU independe
34217 nt.
34218  This phase can be broken down into several sub-phases:
34219 \newline
34220
34221 \newline
34222 Break down intermediate
34223  code (iCode) into basic blocks.
34224 \newline
34225 Do control flow & data flow analysis on the
34226  basic blocks.
34227 \newline
34228 Do local common subexpression elimination, then global subexpressio
34229 n elimination
34230 \newline
34231 Dead code elimination
34232 \newline
34233 Loop optimizations
34234 \newline
34235 If loop optimizations
34236  caused any changes then do 'global subexpression elimination' and 'dead
34237  code elimination' again.
34238 \end_layout
34239
34240 \begin_layout Itemize
34241 This phase determines the live-ranges; by live range I mean those iTemp
34242  variables defined by the compiler that still survive after all the optimization
34243 s.
34244  Live range analysis
34245 \begin_inset LatexCommand \index{Live range analysis}
34246
34247 \end_inset
34248
34249  is essential for register allocation, since these computation determines
34250  which of these iTemps will be assigned to registers, and for how long.
34251 \end_layout
34252
34253 \begin_layout Itemize
34254 Phase five is register allocation.
34255  There are two parts to this process.
34256 \newline
34257
34258 \newline
34259 The first part I call 'register packing'
34260  (for lack of a better term).
34261  In this case several MCU specific expression folding is done to reduce
34262  register pressure.
34263 \newline
34264
34265 \newline
34266 The second part is more MCU independent and deals with
34267  allocating registers to the remaining live ranges.
34268  A lot of MCU specific code does creep into this phase because of the limited
34269  number of index registers available in the 8051.
34270 \end_layout
34271
34272 \begin_layout Itemize
34273 The Code generation phase is (unhappily), entirely MCU dependent and very
34274  little (if any at all) of this code can be reused for other MCU.
34275  However the scheme for allocating a homogenized assembler operand for each
34276  iCode operand may be reused.
34277 \end_layout
34278
34279 \begin_layout Itemize
34280 As mentioned in the optimization section the peep-hole optimizer is rule
34281  based system, which can reprogrammed for other MCUs.
34282 \end_layout
34283
34284 \begin_layout Standard
34285 More information is available in a wiki
34286 \begin_inset LatexCommand \index{wiki}
34287
34288 \end_inset
34289
34290  (preliminary link 
34291 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
34292
34293 \end_inset
34294
34295 ) and in the thread 
34296 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
34297
34298 \end_inset
34299
34300  .
34301 \end_layout
34302
34303 \begin_layout Chapter
34304 Compiler internals
34305 \begin_inset LatexCommand \index{Compiler internals}
34306
34307 \end_inset
34308
34309
34310 \end_layout
34311
34312 \begin_layout Section
34313 The anatomy of the compiler
34314 \begin_inset LatexCommand \label{sub:The-anatomy-of}
34315
34316 \end_inset
34317
34318
34319 \end_layout
34320
34321 \begin_layout Standard
34322
34323 \shape italic
34324 This is an excerpt from an article published in Circuit Cellar Magazine
34325  in 
34326 \series bold
34327 August 2000
34328 \series default
34329 .
34330  It's a little outdated (the compiler is much more efficient now and user/develo
34331 per friendly), but pretty well exposes the guts of it all.
34332 \shape default
34333
34334 \newline
34335
34336 \newline
34337 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
34338  It is fairly easy to retarget for other 8-bit MCU.
34339  Here we take a look at some of the internals of the compiler.
34340  
34341 \end_layout
34342
34343 \begin_layout Paragraph*
34344 Parsing
34345 \begin_inset LatexCommand \index{Parsing}
34346
34347 \end_inset
34348
34349  
34350 \end_layout
34351
34352 \begin_layout Standard
34353 Parsing the input source file and creating an AST (Annotated Syntax Tree
34354 \begin_inset LatexCommand \index{Annotated syntax tree}
34355
34356 \end_inset
34357
34358 ).
34359  This phase also involves propagating types (annotating each node of the
34360  parse tree with type information) and semantic analysis.
34361  There are some MCU specific parsing rules.
34362  For example the storage classes, the extended storage classes are MCU specific
34363  while there may be a xdata storage class for 8051 there is no such storage
34364  class for z80 or Atmel AVR.
34365  SDCC allows MCU specific storage class extensions, i.e.
34366  xdata will be treated as a storage class specifier when parsing 8051 C
34367  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
34368  C code.
34369 \end_layout
34370
34371 \begin_layout Paragraph*
34372 Generating iCode
34373 \begin_inset LatexCommand \index{iCode}
34374
34375 \end_inset
34376
34377
34378 \end_layout
34379
34380 \begin_layout Standard
34381 Intermediate code generation.
34382  In this phase the AST is broken down into three-operand form (iCode).
34383  These three operand forms are represented as doubly linked lists.
34384  ICode is the term given to the intermediate form generated by the compiler.
34385  ICode example section shows some examples of iCode generated for some simple
34386  C source functions.
34387 \end_layout
34388
34389 \begin_layout Paragraph*
34390 Optimizations
34391 \begin_inset LatexCommand \index{Optimizations}
34392
34393 \end_inset
34394
34395 .
34396 \end_layout
34397
34398 \begin_layout Standard
34399 Bulk of the target independent optimizations is performed in this phase.
34400  The optimizations include constant propagation, common sub-expression eliminati
34401 on, loop invariant code movement, strength reduction of loop induction variables
34402  and dead-code elimination.
34403 \end_layout
34404
34405 \begin_layout Paragraph*
34406 Live range analysis
34407 \begin_inset LatexCommand \index{Live range analysis}
34408
34409 \end_inset
34410
34411
34412 \end_layout
34413
34414 \begin_layout Standard
34415 During intermediate code generation phase, the compiler assumes the target
34416  machine has infinite number of registers and generates a lot of temporary
34417  variables.
34418  The live range computation determines the lifetime of each of these compiler-ge
34419 nerated temporaries.
34420  A picture speaks a thousand words.
34421  ICode example sections show the live range annotations for each of the
34422  operand.
34423  It is important to note here, each iCode is assigned a number in the order
34424  of its execution in the function.
34425  The live ranges are computed in terms of these numbers.
34426  The from number is the number of the iCode which first defines the operand
34427  and the to number signifies the iCode which uses this operand last.
34428 \end_layout
34429
34430 \begin_layout Paragraph*
34431 Register Allocation
34432 \begin_inset LatexCommand \index{Register allocation}
34433
34434 \end_inset
34435
34436
34437 \end_layout
34438
34439 \begin_layout Standard
34440 The register allocation determines the type and number of registers needed
34441  by each operand.
34442  In most MCUs only a few registers can be used for indirect addressing.
34443  In case of 8051 for example the registers R0 & R1 can be used to indirectly
34444  address the internal ram and DPTR to indirectly address the external ram.
34445  The compiler will try to allocate the appropriate register to pointer variables
34446  if it can.
34447  ICode example section shows the operands annotated with the registers assigned
34448  to them.
34449  The compiler will try to keep operands in registers as much as possible;
34450  there are several schemes the compiler uses to do achieve this.
34451  When the compiler runs out of registers the compiler will check to see
34452  if there are any live operands which is not used or defined in the current
34453  basic block being processed, if there are any found then it will push that
34454  operand and use the registers in this block, the operand will then be popped
34455  at the end of the basic block.
34456  
34457 \end_layout
34458
34459 \begin_layout Standard
34460 There are other MCU specific considerations in this phase.
34461  Some MCUs have an accumulator; very short-lived operands could be assigned
34462  to the accumulator instead of a general-purpose register.
34463 \end_layout
34464
34465 \begin_layout Paragraph*
34466 Code generation
34467 \end_layout
34468
34469 \begin_layout Standard
34470 Figure II gives a table of iCode
34471 \begin_inset LatexCommand \index{iCode}
34472
34473 \end_inset
34474
34475  operations supported by the compiler.
34476  The code generation involves translating these operations into corresponding
34477  assembly code for the processor.
34478  This sounds overly simple but that is the essence of code generation.
34479  Some of the iCode operations are generated on a MCU specific manner for
34480  example, the z80 port does not use registers to pass parameters so the
34481  SEND and RECV iCode operations will not be generated, and it also does
34482  not support JUMPTABLES.
34483  
34484 \newline
34485
34486 \end_layout
34487
34488 \begin_layout Standard
34489
34490 \size footnotesize
34491 Figure II 
34492 \begin_inset Tabular
34493 <lyxtabular version="3" rows="39" columns="4">
34494 <features islongtable="true" headBottomDL="true">
34495 <column alignment="block" valignment="top" leftline="true" width="13col%">
34496 <column alignment="left" valignment="top" leftline="true" width="13col%">
34497 <column alignment="block" valignment="top" leftline="true" width="22col%">
34498 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
34499 <row topline="true" bottomline="true" endhead="true">
34500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34501 \begin_inset Text
34502
34503 \begin_layout Standard
34504
34505 \series bold
34506 iCode
34507 \series default
34508
34509 \begin_inset LatexCommand \index{iCode}
34510
34511 \end_inset
34512
34513
34514 \end_layout
34515
34516 \end_inset
34517 </cell>
34518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34519 \begin_inset Text
34520
34521 \begin_layout Standard
34522
34523 \series bold
34524 Operands
34525 \end_layout
34526
34527 \end_inset
34528 </cell>
34529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34530 \begin_inset Text
34531
34532 \begin_layout Standard
34533
34534 \series bold
34535 Description
34536 \end_layout
34537
34538 \end_inset
34539 </cell>
34540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34541 \begin_inset Text
34542
34543 \begin_layout Standard
34544
34545 \series bold
34546 C Equivalent
34547 \end_layout
34548
34549 \end_inset
34550 </cell>
34551 </row>
34552 <row topline="true">
34553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34554 \begin_inset Text
34555
34556 \begin_layout Standard
34557
34558 \size footnotesize
34559 '!'
34560 \end_layout
34561
34562 \end_inset
34563 </cell>
34564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34565 \begin_inset Text
34566
34567 \begin_layout Standard
34568
34569 \size footnotesize
34570 IC_LEFT() IC_RESULT()
34571 \end_layout
34572
34573 \end_inset
34574 </cell>
34575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34576 \begin_inset Text
34577
34578 \begin_layout Standard
34579
34580 \size footnotesize
34581 NOT operation 
34582 \end_layout
34583
34584 \end_inset
34585 </cell>
34586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34587 \begin_inset Text
34588
34589 \begin_layout Standard
34590
34591 \size footnotesize
34592 IC_RESULT = ! IC_LEFT;
34593 \end_layout
34594
34595 \end_inset
34596 </cell>
34597 </row>
34598 <row topline="true">
34599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34600 \begin_inset Text
34601
34602 \begin_layout Standard
34603
34604 \size footnotesize
34605 '~'
34606 \end_layout
34607
34608 \end_inset
34609 </cell>
34610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34611 \begin_inset Text
34612
34613 \begin_layout Standard
34614
34615 \size footnotesize
34616 IC_LEFT() IC_RESULT()
34617 \end_layout
34618
34619 \end_inset
34620 </cell>
34621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34622 \begin_inset Text
34623
34624 \begin_layout Standard
34625
34626 \size footnotesize
34627 Bitwise complement of 
34628 \end_layout
34629
34630 \end_inset
34631 </cell>
34632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34633 \begin_inset Text
34634
34635 \begin_layout Standard
34636
34637 \size footnotesize
34638 IC_RESULT = ~IC_LEFT;
34639 \end_layout
34640
34641 \end_inset
34642 </cell>
34643 </row>
34644 <row topline="true">
34645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34646 \begin_inset Text
34647
34648 \begin_layout Standard
34649
34650 \size footnotesize
34651 RRC
34652 \end_layout
34653
34654 \end_inset
34655 </cell>
34656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34657 \begin_inset Text
34658
34659 \begin_layout Standard
34660
34661 \size footnotesize
34662 IC_LEFT() IC_RESULT()
34663 \end_layout
34664
34665 \end_inset
34666 </cell>
34667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34668 \begin_inset Text
34669
34670 \begin_layout Standard
34671
34672 \size footnotesize
34673 Rotate right with carry
34674 \end_layout
34675
34676 \end_inset
34677 </cell>
34678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34679 \begin_inset Text
34680
34681 \begin_layout Standard
34682
34683 \size footnotesize
34684 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
34685 \end_layout
34686
34687 \end_inset
34688 </cell>
34689 </row>
34690 <row topline="true">
34691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34692 \begin_inset Text
34693
34694 \begin_layout Standard
34695
34696 \size footnotesize
34697 RLC
34698 \end_layout
34699
34700 \end_inset
34701 </cell>
34702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34703 \begin_inset Text
34704
34705 \begin_layout Standard
34706
34707 \size footnotesize
34708 IC_LEFT() IC_RESULT()
34709 \end_layout
34710
34711 \end_inset
34712 </cell>
34713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34714 \begin_inset Text
34715
34716 \begin_layout Standard
34717
34718 \size footnotesize
34719 Rotate left with carry
34720 \end_layout
34721
34722 \end_inset
34723 </cell>
34724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34725 \begin_inset Text
34726
34727 \begin_layout Standard
34728
34729 \size footnotesize
34730 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
34731 \end_layout
34732
34733 \end_inset
34734 </cell>
34735 </row>
34736 <row topline="true">
34737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34738 \begin_inset Text
34739
34740 \begin_layout Standard
34741
34742 \size footnotesize
34743 GETHBIT
34744 \end_layout
34745
34746 \end_inset
34747 </cell>
34748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34749 \begin_inset Text
34750
34751 \begin_layout Standard
34752
34753 \size footnotesize
34754 IC_LEFT() IC_RESULT()
34755 \end_layout
34756
34757 \end_inset
34758 </cell>
34759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34760 \begin_inset Text
34761
34762 \begin_layout Standard
34763
34764 \size footnotesize
34765 Get the highest order bit of IC_LEFT
34766 \end_layout
34767
34768 \end_inset
34769 </cell>
34770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34771 \begin_inset Text
34772
34773 \begin_layout Standard
34774
34775 \size footnotesize
34776 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
34777 \end_layout
34778
34779 \end_inset
34780 </cell>
34781 </row>
34782 <row topline="true">
34783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34784 \begin_inset Text
34785
34786 \begin_layout Standard
34787
34788 \size footnotesize
34789 UNARYMINUS
34790 \end_layout
34791
34792 \end_inset
34793 </cell>
34794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34795 \begin_inset Text
34796
34797 \begin_layout Standard
34798
34799 \size footnotesize
34800 IC_LEFT() IC_RESULT()
34801 \end_layout
34802
34803 \end_inset
34804 </cell>
34805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34806 \begin_inset Text
34807
34808 \begin_layout Standard
34809
34810 \size footnotesize
34811 Unary minus
34812 \end_layout
34813
34814 \end_inset
34815 </cell>
34816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34817 \begin_inset Text
34818
34819 \begin_layout Standard
34820
34821 \size footnotesize
34822 IC_RESULT = - IC_LEFT;
34823 \end_layout
34824
34825 \end_inset
34826 </cell>
34827 </row>
34828 <row topline="true">
34829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34830 \begin_inset Text
34831
34832 \begin_layout Standard
34833
34834 \size footnotesize
34835 IPUSH
34836 \end_layout
34837
34838 \end_inset
34839 </cell>
34840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34841 \begin_inset Text
34842
34843 \begin_layout Standard
34844
34845 \size footnotesize
34846 IC_LEFT()
34847 \end_layout
34848
34849 \end_inset
34850 </cell>
34851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34852 \begin_inset Text
34853
34854 \begin_layout Standard
34855
34856 \size footnotesize
34857 Push the operand into stack
34858 \end_layout
34859
34860 \end_inset
34861 </cell>
34862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34863 \begin_inset Text
34864
34865 \begin_layout Standard
34866
34867 \size footnotesize
34868 NONE
34869 \end_layout
34870
34871 \end_inset
34872 </cell>
34873 </row>
34874 <row topline="true">
34875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34876 \begin_inset Text
34877
34878 \begin_layout Standard
34879
34880 \size footnotesize
34881 IPOP
34882 \end_layout
34883
34884 \end_inset
34885 </cell>
34886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34887 \begin_inset Text
34888
34889 \begin_layout Standard
34890
34891 \size footnotesize
34892 IC_LEFT()
34893 \end_layout
34894
34895 \end_inset
34896 </cell>
34897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34898 \begin_inset Text
34899
34900 \begin_layout Standard
34901
34902 \size footnotesize
34903 Pop the operand from the stack 
34904 \end_layout
34905
34906 \end_inset
34907 </cell>
34908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34909 \begin_inset Text
34910
34911 \begin_layout Standard
34912
34913 \size footnotesize
34914 NONE
34915 \end_layout
34916
34917 \end_inset
34918 </cell>
34919 </row>
34920 <row topline="true">
34921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34922 \begin_inset Text
34923
34924 \begin_layout Standard
34925
34926 \size footnotesize
34927 CALL
34928 \end_layout
34929
34930 \end_inset
34931 </cell>
34932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34933 \begin_inset Text
34934
34935 \begin_layout Standard
34936
34937 \size footnotesize
34938 IC_LEFT() IC_RESULT()
34939 \end_layout
34940
34941 \end_inset
34942 </cell>
34943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34944 \begin_inset Text
34945
34946 \begin_layout Standard
34947
34948 \size footnotesize
34949 Call the function represented by IC_LEFT 
34950 \end_layout
34951
34952 \end_inset
34953 </cell>
34954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34955 \begin_inset Text
34956
34957 \begin_layout Standard
34958
34959 \size footnotesize
34960 IC_RESULT = IC_LEFT();
34961 \end_layout
34962
34963 \end_inset
34964 </cell>
34965 </row>
34966 <row topline="true">
34967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34968 \begin_inset Text
34969
34970 \begin_layout Standard
34971
34972 \size footnotesize
34973 PCALL
34974 \end_layout
34975
34976 \end_inset
34977 </cell>
34978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34979 \begin_inset Text
34980
34981 \begin_layout Standard
34982
34983 \size footnotesize
34984 IC_LEFT() IC_RESULT()
34985 \end_layout
34986
34987 \end_inset
34988 </cell>
34989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34990 \begin_inset Text
34991
34992 \begin_layout Standard
34993
34994 \size footnotesize
34995 Call via function pointer
34996 \end_layout
34997
34998 \end_inset
34999 </cell>
35000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35001 \begin_inset Text
35002
35003 \begin_layout Standard
35004
35005 \size footnotesize
35006 IC_RESULT = (*IC_LEFT)();
35007 \end_layout
35008
35009 \end_inset
35010 </cell>
35011 </row>
35012 <row topline="true">
35013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35014 \begin_inset Text
35015
35016 \begin_layout Standard
35017
35018 \size footnotesize
35019 RETURN
35020 \end_layout
35021
35022 \end_inset
35023 </cell>
35024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35025 \begin_inset Text
35026
35027 \begin_layout Standard
35028
35029 \size footnotesize
35030 IC_LEFT()
35031 \end_layout
35032
35033 \end_inset
35034 </cell>
35035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35036 \begin_inset Text
35037
35038 \begin_layout Standard
35039
35040 \size footnotesize
35041 Return the value in operand IC_LEFT 
35042 \end_layout
35043
35044 \end_inset
35045 </cell>
35046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35047 \begin_inset Text
35048
35049 \begin_layout Standard
35050
35051 \size footnotesize
35052 return IC_LEFT;
35053 \end_layout
35054
35055 \end_inset
35056 </cell>
35057 </row>
35058 <row topline="true">
35059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35060 \begin_inset Text
35061
35062 \begin_layout Standard
35063
35064 \size footnotesize
35065 LABEL
35066 \end_layout
35067
35068 \end_inset
35069 </cell>
35070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35071 \begin_inset Text
35072
35073 \begin_layout Standard
35074
35075 \size footnotesize
35076 IC_LABEL() 
35077 \end_layout
35078
35079 \end_inset
35080 </cell>
35081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35082 \begin_inset Text
35083
35084 \begin_layout Standard
35085
35086 \size footnotesize
35087 Label
35088 \end_layout
35089
35090 \end_inset
35091 </cell>
35092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35093 \begin_inset Text
35094
35095 \begin_layout Standard
35096
35097 \size footnotesize
35098 IC_LABEL:
35099 \end_layout
35100
35101 \end_inset
35102 </cell>
35103 </row>
35104 <row topline="true">
35105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35106 \begin_inset Text
35107
35108 \begin_layout Standard
35109
35110 \size footnotesize
35111 GOTO
35112 \end_layout
35113
35114 \end_inset
35115 </cell>
35116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35117 \begin_inset Text
35118
35119 \begin_layout Standard
35120
35121 \size footnotesize
35122 IC_LABEL() 
35123 \end_layout
35124
35125 \end_inset
35126 </cell>
35127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35128 \begin_inset Text
35129
35130 \begin_layout Standard
35131
35132 \size footnotesize
35133 Goto label
35134 \end_layout
35135
35136 \end_inset
35137 </cell>
35138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35139 \begin_inset Text
35140
35141 \begin_layout Standard
35142
35143 \size footnotesize
35144 goto IC_LABEL();
35145 \end_layout
35146
35147 \end_inset
35148 </cell>
35149 </row>
35150 <row topline="true">
35151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35152 \begin_inset Text
35153
35154 \begin_layout Standard
35155
35156 \size footnotesize
35157 '+'
35158 \end_layout
35159
35160 \end_inset
35161 </cell>
35162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35163 \begin_inset Text
35164
35165 \begin_layout Standard
35166
35167 \size footnotesize
35168 IC_LEFT() IC_RIGHT() IC_RESULT()
35169 \end_layout
35170
35171 \end_inset
35172 </cell>
35173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35174 \begin_inset Text
35175
35176 \begin_layout Standard
35177
35178 \size footnotesize
35179 Addition
35180 \end_layout
35181
35182 \end_inset
35183 </cell>
35184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35185 \begin_inset Text
35186
35187 \begin_layout Standard
35188
35189 \size footnotesize
35190 IC_RESULT = IC_LEFT + IC_RIGHT
35191 \end_layout
35192
35193 \end_inset
35194 </cell>
35195 </row>
35196 <row topline="true">
35197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35198 \begin_inset Text
35199
35200 \begin_layout Standard
35201
35202 \size footnotesize
35203 '-'
35204 \end_layout
35205
35206 \end_inset
35207 </cell>
35208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35209 \begin_inset Text
35210
35211 \begin_layout Standard
35212
35213 \size footnotesize
35214 IC_LEFT() IC_RIGHT() IC_RESULT()
35215 \end_layout
35216
35217 \end_inset
35218 </cell>
35219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35220 \begin_inset Text
35221
35222 \begin_layout Standard
35223
35224 \size footnotesize
35225 Subtraction
35226 \end_layout
35227
35228 \end_inset
35229 </cell>
35230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35231 \begin_inset Text
35232
35233 \begin_layout Standard
35234
35235 \size footnotesize
35236 IC_RESULT = IC_LEFT - IC_RIGHT 
35237 \end_layout
35238
35239 \end_inset
35240 </cell>
35241 </row>
35242 <row topline="true">
35243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35244 \begin_inset Text
35245
35246 \begin_layout Standard
35247
35248 \size footnotesize
35249 '*'
35250 \end_layout
35251
35252 \end_inset
35253 </cell>
35254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35255 \begin_inset Text
35256
35257 \begin_layout Standard
35258
35259 \size footnotesize
35260 IC_LEFT() IC_RIGHT() IC_RESULT()
35261 \end_layout
35262
35263 \end_inset
35264 </cell>
35265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35266 \begin_inset Text
35267
35268 \begin_layout Standard
35269
35270 \size footnotesize
35271 Multiplication 
35272 \end_layout
35273
35274 \end_inset
35275 </cell>
35276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35277 \begin_inset Text
35278
35279 \begin_layout Standard
35280
35281 \size footnotesize
35282 IC_RESULT = IC_LEFT * IC_RIGHT;
35283 \end_layout
35284
35285 \end_inset
35286 </cell>
35287 </row>
35288 <row topline="true">
35289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35290 \begin_inset Text
35291
35292 \begin_layout Standard
35293
35294 \size footnotesize
35295 '/'
35296 \end_layout
35297
35298 \end_inset
35299 </cell>
35300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35301 \begin_inset Text
35302
35303 \begin_layout Standard
35304
35305 \size footnotesize
35306 IC_LEFT() IC_RIGHT() IC_RESULT()
35307 \end_layout
35308
35309 \end_inset
35310 </cell>
35311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35312 \begin_inset Text
35313
35314 \begin_layout Standard
35315
35316 \size footnotesize
35317 Division
35318 \end_layout
35319
35320 \end_inset
35321 </cell>
35322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35323 \begin_inset Text
35324
35325 \begin_layout Standard
35326
35327 \size footnotesize
35328 IC_RESULT = IC_LEFT / IC_RIGHT;
35329 \end_layout
35330
35331 \end_inset
35332 </cell>
35333 </row>
35334 <row topline="true">
35335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35336 \begin_inset Text
35337
35338 \begin_layout Standard
35339
35340 \size footnotesize
35341 '%'
35342 \end_layout
35343
35344 \end_inset
35345 </cell>
35346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35347 \begin_inset Text
35348
35349 \begin_layout Standard
35350
35351 \size footnotesize
35352 IC_LEFT() IC_RIGHT() IC_RESULT()
35353 \end_layout
35354
35355 \end_inset
35356 </cell>
35357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35358 \begin_inset Text
35359
35360 \begin_layout Standard
35361
35362 \size footnotesize
35363 Modulus
35364 \end_layout
35365
35366 \end_inset
35367 </cell>
35368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35369 \begin_inset Text
35370
35371 \begin_layout Standard
35372
35373 \size footnotesize
35374 IC_RESULT = IC_LEFT % IC_RIGHT;
35375 \end_layout
35376
35377 \end_inset
35378 </cell>
35379 </row>
35380 <row topline="true">
35381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35382 \begin_inset Text
35383
35384 \begin_layout Standard
35385
35386 \size footnotesize
35387 '<'
35388 \end_layout
35389
35390 \end_inset
35391 </cell>
35392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35393 \begin_inset Text
35394
35395 \begin_layout Standard
35396
35397 \size footnotesize
35398 IC_LEFT() IC_RIGHT() IC_RESULT()
35399 \end_layout
35400
35401 \end_inset
35402 </cell>
35403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35404 \begin_inset Text
35405
35406 \begin_layout Standard
35407
35408 \size footnotesize
35409 Less than
35410 \end_layout
35411
35412 \end_inset
35413 </cell>
35414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35415 \begin_inset Text
35416
35417 \begin_layout Standard
35418
35419 \size footnotesize
35420 IC_RESULT = IC_LEFT < IC_RIGHT;
35421 \end_layout
35422
35423 \end_inset
35424 </cell>
35425 </row>
35426 <row topline="true">
35427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35428 \begin_inset Text
35429
35430 \begin_layout Standard
35431
35432 \size footnotesize
35433 '>'
35434 \end_layout
35435
35436 \end_inset
35437 </cell>
35438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35439 \begin_inset Text
35440
35441 \begin_layout Standard
35442
35443 \size footnotesize
35444 IC_LEFT() IC_RIGHT() IC_RESULT()
35445 \end_layout
35446
35447 \end_inset
35448 </cell>
35449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35450 \begin_inset Text
35451
35452 \begin_layout Standard
35453
35454 \size footnotesize
35455 Greater than 
35456 \end_layout
35457
35458 \end_inset
35459 </cell>
35460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35461 \begin_inset Text
35462
35463 \begin_layout Standard
35464
35465 \size footnotesize
35466 IC_RESULT = IC_LEFT > IC_RIGHT;
35467 \end_layout
35468
35469 \end_inset
35470 </cell>
35471 </row>
35472 <row topline="true">
35473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35474 \begin_inset Text
35475
35476 \begin_layout Standard
35477
35478 \size footnotesize
35479 EQ_OP
35480 \end_layout
35481
35482 \end_inset
35483 </cell>
35484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35485 \begin_inset Text
35486
35487 \begin_layout Standard
35488
35489 \size footnotesize
35490 IC_LEFT() IC_RIGHT() IC_RESULT()
35491 \end_layout
35492
35493 \end_inset
35494 </cell>
35495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35496 \begin_inset Text
35497
35498 \begin_layout Standard
35499
35500 \size footnotesize
35501 Equal to 
35502 \end_layout
35503
35504 \end_inset
35505 </cell>
35506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35507 \begin_inset Text
35508
35509 \begin_layout Standard
35510
35511 \size footnotesize
35512 IC_RESULT = IC_LEFT == IC_RIGHT;
35513 \end_layout
35514
35515 \end_inset
35516 </cell>
35517 </row>
35518 <row topline="true">
35519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35520 \begin_inset Text
35521
35522 \begin_layout Standard
35523
35524 \size footnotesize
35525 AND_OP
35526 \end_layout
35527
35528 \end_inset
35529 </cell>
35530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35531 \begin_inset Text
35532
35533 \begin_layout Standard
35534
35535 \size footnotesize
35536 IC_LEFT() IC_RIGHT() IC_RESULT() 
35537 \end_layout
35538
35539 \end_inset
35540 </cell>
35541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35542 \begin_inset Text
35543
35544 \begin_layout Standard
35545
35546 \size footnotesize
35547 Logical and operation
35548 \end_layout
35549
35550 \end_inset
35551 </cell>
35552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35553 \begin_inset Text
35554
35555 \begin_layout Standard
35556
35557 \size footnotesize
35558 IC_RESULT = IC_LEFT && IC_RIGHT; 
35559 \end_layout
35560
35561 \end_inset
35562 </cell>
35563 </row>
35564 <row topline="true">
35565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35566 \begin_inset Text
35567
35568 \begin_layout Standard
35569
35570 \size footnotesize
35571 OR_OP
35572 \end_layout
35573
35574 \end_inset
35575 </cell>
35576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35577 \begin_inset Text
35578
35579 \begin_layout Standard
35580
35581 \size footnotesize
35582 IC_LEFT() IC_RIGHT() IC_RESULT() 
35583 \end_layout
35584
35585 \end_inset
35586 </cell>
35587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35588 \begin_inset Text
35589
35590 \begin_layout Standard
35591
35592 \size footnotesize
35593 Logical or operation 
35594 \end_layout
35595
35596 \end_inset
35597 </cell>
35598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35599 \begin_inset Text
35600
35601 \begin_layout Standard
35602
35603 \size footnotesize
35604 IC_RESULT = IC_LEFT || IC_RIGHT; 
35605 \end_layout
35606
35607 \end_inset
35608 </cell>
35609 </row>
35610 <row topline="true">
35611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35612 \begin_inset Text
35613
35614 \begin_layout Standard
35615
35616 \size footnotesize
35617 '^'
35618 \end_layout
35619
35620 \end_inset
35621 </cell>
35622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35623 \begin_inset Text
35624
35625 \begin_layout Standard
35626
35627 \size footnotesize
35628 IC_LEFT() IC_RIGHT() IC_RESULT() 
35629 \end_layout
35630
35631 \end_inset
35632 </cell>
35633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35634 \begin_inset Text
35635
35636 \begin_layout Standard
35637
35638 \size footnotesize
35639 Exclusive OR
35640 \end_layout
35641
35642 \end_inset
35643 </cell>
35644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35645 \begin_inset Text
35646
35647 \begin_layout Standard
35648
35649 \size footnotesize
35650 IC_RESULT = IC_LEFT ^ IC_RIGHT;
35651 \end_layout
35652
35653 \end_inset
35654 </cell>
35655 </row>
35656 <row topline="true">
35657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35658 \begin_inset Text
35659
35660 \begin_layout Standard
35661
35662 \size footnotesize
35663 '|'
35664 \end_layout
35665
35666 \end_inset
35667 </cell>
35668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35669 \begin_inset Text
35670
35671 \begin_layout Standard
35672
35673 \size footnotesize
35674 IC_LEFT() IC_RIGHT() IC_RESULT() 
35675 \end_layout
35676
35677 \end_inset
35678 </cell>
35679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35680 \begin_inset Text
35681
35682 \begin_layout Standard
35683
35684 \size footnotesize
35685 Bitwise OR 
35686 \end_layout
35687
35688 \end_inset
35689 </cell>
35690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35691 \begin_inset Text
35692
35693 \begin_layout Standard
35694
35695 \size footnotesize
35696 IC_RESULT = IC_LEFT | IC_RIGHT;
35697 \end_layout
35698
35699 \end_inset
35700 </cell>
35701 </row>
35702 <row topline="true">
35703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35704 \begin_inset Text
35705
35706 \begin_layout Standard
35707
35708 \size footnotesize
35709 BITWISEAND
35710 \end_layout
35711
35712 \end_inset
35713 </cell>
35714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35715 \begin_inset Text
35716
35717 \begin_layout Standard
35718
35719 \size footnotesize
35720 IC_LEFT() IC_RIGHT() IC_RESULT()
35721 \end_layout
35722
35723 \end_inset
35724 </cell>
35725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35726 \begin_inset Text
35727
35728 \begin_layout Standard
35729
35730 \size footnotesize
35731 Bitwise AND 
35732 \end_layout
35733
35734 \end_inset
35735 </cell>
35736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35737 \begin_inset Text
35738
35739 \begin_layout Standard
35740
35741 \size footnotesize
35742 IC_RESULT = IC_LEFT & IC_RIGHT;
35743 \end_layout
35744
35745 \end_inset
35746 </cell>
35747 </row>
35748 <row topline="true">
35749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35750 \begin_inset Text
35751
35752 \begin_layout Standard
35753
35754 \size footnotesize
35755 LEFT_OP
35756 \end_layout
35757
35758 \end_inset
35759 </cell>
35760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35761 \begin_inset Text
35762
35763 \begin_layout Standard
35764
35765 \size footnotesize
35766 IC_LEFT() IC_RIGHT() IC_RESULT()
35767 \end_layout
35768
35769 \end_inset
35770 </cell>
35771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35772 \begin_inset Text
35773
35774 \begin_layout Standard
35775
35776 \size footnotesize
35777 Left shift 
35778 \end_layout
35779
35780 \end_inset
35781 </cell>
35782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35783 \begin_inset Text
35784
35785 \begin_layout Standard
35786
35787 \size footnotesize
35788 IC_RESULT = IC_LEFT << IC_RIGHT 
35789 \end_layout
35790
35791 \end_inset
35792 </cell>
35793 </row>
35794 <row topline="true">
35795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35796 \begin_inset Text
35797
35798 \begin_layout Standard
35799
35800 \size footnotesize
35801 RIGHT_OP
35802 \end_layout
35803
35804 \end_inset
35805 </cell>
35806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35807 \begin_inset Text
35808
35809 \begin_layout Standard
35810
35811 \size footnotesize
35812 IC_LEFT() IC_RIGHT() IC_RESULT()
35813 \end_layout
35814
35815 \end_inset
35816 </cell>
35817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35818 \begin_inset Text
35819
35820 \begin_layout Standard
35821
35822 \size footnotesize
35823 Right shift
35824 \end_layout
35825
35826 \end_inset
35827 </cell>
35828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35829 \begin_inset Text
35830
35831 \begin_layout Standard
35832
35833 \size footnotesize
35834 IC_RESULT = IC_LEFT >> IC_RIGHT 
35835 \end_layout
35836
35837 \end_inset
35838 </cell>
35839 </row>
35840 <row topline="true">
35841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35842 \begin_inset Text
35843
35844 \begin_layout Standard
35845
35846 \size footnotesize
35847 GET_VALUE_
35848 \newline
35849 AT_ ADDRESS
35850 \end_layout
35851
35852 \end_inset
35853 </cell>
35854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35855 \begin_inset Text
35856
35857 \begin_layout Standard
35858
35859 \size footnotesize
35860 IC_LEFT() IC_RESULT()
35861 \end_layout
35862
35863 \end_inset
35864 </cell>
35865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35866 \begin_inset Text
35867
35868 \begin_layout Standard
35869
35870 \size footnotesize
35871 Indirect fetch 
35872 \end_layout
35873
35874 \end_inset
35875 </cell>
35876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35877 \begin_inset Text
35878
35879 \begin_layout Standard
35880
35881 \size footnotesize
35882 IC_RESULT = (*IC_LEFT);
35883 \end_layout
35884
35885 \end_inset
35886 </cell>
35887 </row>
35888 <row topline="true">
35889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35890 \begin_inset Text
35891
35892 \begin_layout Standard
35893
35894 \size footnotesize
35895 POINTER_SET
35896 \end_layout
35897
35898 \end_inset
35899 </cell>
35900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35901 \begin_inset Text
35902
35903 \begin_layout Standard
35904
35905 \size footnotesize
35906 IC_RIGHT() IC_RESULT() 
35907 \end_layout
35908
35909 \end_inset
35910 </cell>
35911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35912 \begin_inset Text
35913
35914 \begin_layout Standard
35915
35916 \size footnotesize
35917 Indirect set
35918 \end_layout
35919
35920 \end_inset
35921 </cell>
35922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35923 \begin_inset Text
35924
35925 \begin_layout Standard
35926
35927 \size footnotesize
35928 (*IC_RESULT) = IC_RIGHT;
35929 \end_layout
35930
35931 \end_inset
35932 </cell>
35933 </row>
35934 <row topline="true">
35935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35936 \begin_inset Text
35937
35938 \begin_layout Standard
35939
35940 \size footnotesize
35941 '='
35942 \end_layout
35943
35944 \end_inset
35945 </cell>
35946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35947 \begin_inset Text
35948
35949 \begin_layout Standard
35950
35951 \size footnotesize
35952 IC_RIGHT() IC_RESULT()
35953 \end_layout
35954
35955 \end_inset
35956 </cell>
35957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35958 \begin_inset Text
35959
35960 \begin_layout Standard
35961
35962 \size footnotesize
35963 Assignment
35964 \end_layout
35965
35966 \end_inset
35967 </cell>
35968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35969 \begin_inset Text
35970
35971 \begin_layout Standard
35972
35973 \size footnotesize
35974 IC_RESULT = IC_RIGHT;
35975 \end_layout
35976
35977 \end_inset
35978 </cell>
35979 </row>
35980 <row topline="true">
35981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35982 \begin_inset Text
35983
35984 \begin_layout Standard
35985
35986 \size footnotesize
35987 IFX
35988 \end_layout
35989
35990 \end_inset
35991 </cell>
35992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35993 \begin_inset Text
35994
35995 \begin_layout Standard
35996
35997 \size footnotesize
35998 IC_COND IC_TRUE IC_LABEL
35999 \end_layout
36000
36001 \end_inset
36002 </cell>
36003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36004 \begin_inset Text
36005
36006 \begin_layout Standard
36007
36008 \size footnotesize
36009 Conditional jump.
36010  If true label is present then jump to true label if condition is true else
36011  jump to false label if condition is false 
36012 \end_layout
36013
36014 \end_inset
36015 </cell>
36016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36017 \begin_inset Text
36018
36019 \begin_layout Standard
36020
36021 \size footnotesize
36022 if (IC_COND) goto IC_TRUE; 
36023 \newline
36024 \InsetSpace ~
36025 \InsetSpace ~
36026 Or 
36027 \newline
36028 If (!IC_COND) goto IC_FALSE;
36029 \end_layout
36030
36031 \end_inset
36032 </cell>
36033 </row>
36034 <row topline="true">
36035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36036 \begin_inset Text
36037
36038 \begin_layout Standard
36039
36040 \size footnotesize
36041 ADDRESS_OF
36042 \end_layout
36043
36044 \end_inset
36045 </cell>
36046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36047 \begin_inset Text
36048
36049 \begin_layout Standard
36050
36051 \size footnotesize
36052 IC_LEFT() IC_RESULT()
36053 \end_layout
36054
36055 \end_inset
36056 </cell>
36057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36058 \begin_inset Text
36059
36060 \begin_layout Standard
36061
36062 \size footnotesize
36063 Address of 
36064 \end_layout
36065
36066 \end_inset
36067 </cell>
36068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36069 \begin_inset Text
36070
36071 \begin_layout Standard
36072
36073 \size footnotesize
36074 IC_RESULT = &IC_LEFT();
36075 \end_layout
36076
36077 \end_inset
36078 </cell>
36079 </row>
36080 <row topline="true">
36081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36082 \begin_inset Text
36083
36084 \begin_layout Standard
36085
36086 \size footnotesize
36087 JUMPTABLE
36088 \end_layout
36089
36090 \end_inset
36091 </cell>
36092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36093 \begin_inset Text
36094
36095 \begin_layout Standard
36096
36097 \size footnotesize
36098 IC_JTCOND IC_JTLABELS
36099 \end_layout
36100
36101 \end_inset
36102 </cell>
36103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36104 \begin_inset Text
36105
36106 \begin_layout Standard
36107
36108 \size footnotesize
36109 Jump to list of labels depending on the value of JTCOND
36110 \end_layout
36111
36112 \end_inset
36113 </cell>
36114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36115 \begin_inset Text
36116
36117 \begin_layout Standard
36118
36119 \size footnotesize
36120 Switch statement
36121 \end_layout
36122
36123 \end_inset
36124 </cell>
36125 </row>
36126 <row topline="true">
36127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36128 \begin_inset Text
36129
36130 \begin_layout Standard
36131
36132 \size footnotesize
36133 CAST
36134 \end_layout
36135
36136 \end_inset
36137 </cell>
36138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36139 \begin_inset Text
36140
36141 \begin_layout Standard
36142
36143 \size footnotesize
36144 IC_RIGHT() IC_LEFT() IC_RESULT()
36145 \end_layout
36146
36147 \end_inset
36148 </cell>
36149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36150 \begin_inset Text
36151
36152 \begin_layout Standard
36153
36154 \size footnotesize
36155 Cast types 
36156 \end_layout
36157
36158 \end_inset
36159 </cell>
36160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36161 \begin_inset Text
36162
36163 \begin_layout Standard
36164
36165 \size footnotesize
36166 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
36167 \end_layout
36168
36169 \end_inset
36170 </cell>
36171 </row>
36172 <row topline="true">
36173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36174 \begin_inset Text
36175
36176 \begin_layout Standard
36177
36178 \size footnotesize
36179 SEND
36180 \end_layout
36181
36182 \end_inset
36183 </cell>
36184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36185 \begin_inset Text
36186
36187 \begin_layout Standard
36188
36189 \size footnotesize
36190 IC_LEFT()
36191 \end_layout
36192
36193 \end_inset
36194 </cell>
36195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36196 \begin_inset Text
36197
36198 \begin_layout Standard
36199
36200 \size footnotesize
36201 This is used for passing parameters in registers; 
36202 \newline
36203 move IC_LEFT to the next
36204  available parameter register.
36205 \end_layout
36206
36207 \end_inset
36208 </cell>
36209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36210 \begin_inset Text
36211
36212 \begin_layout Standard
36213
36214 \size footnotesize
36215 None
36216 \end_layout
36217
36218 \end_inset
36219 </cell>
36220 </row>
36221 <row topline="true">
36222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36223 \begin_inset Text
36224
36225 \begin_layout Standard
36226
36227 \size footnotesize
36228 RECV
36229 \end_layout
36230
36231 \end_inset
36232 </cell>
36233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36234 \begin_inset Text
36235
36236 \begin_layout Standard
36237
36238 \size footnotesize
36239 IC_RESULT()
36240 \end_layout
36241
36242 \end_inset
36243 </cell>
36244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36245 \begin_inset Text
36246
36247 \begin_layout Standard
36248
36249 \size footnotesize
36250 This is used for receiving parameters passed in registers;
36251 \newline
36252 Move the values
36253  in the next parameter register to IC_RESULT 
36254 \end_layout
36255
36256 \end_inset
36257 </cell>
36258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36259 \begin_inset Text
36260
36261 \begin_layout Standard
36262
36263 \size footnotesize
36264 None
36265 \end_layout
36266
36267 \end_inset
36268 </cell>
36269 </row>
36270 <row topline="true" bottomline="true">
36271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36272 \begin_inset Text
36273
36274 \begin_layout Standard
36275
36276 \shape slanted
36277 \size footnotesize
36278 (some more have been added)
36279 \end_layout
36280
36281 \end_inset
36282 </cell>
36283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36284 \begin_inset Text
36285
36286 \begin_layout Standard
36287
36288 \end_layout
36289
36290 \end_inset
36291 </cell>
36292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36293 \begin_inset Text
36294
36295 \begin_layout Standard
36296
36297 \end_layout
36298
36299 \end_inset
36300 </cell>
36301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36302 \begin_inset Text
36303
36304 \begin_layout Standard
36305
36306 \shape slanted
36307 \size footnotesize
36308 see f.e.
36309  
36310 \family typewriter
36311 gen51Code()
36312 \family default
36313  in 
36314 \family typewriter
36315 src/mcs51/gen.c
36316 \end_layout
36317
36318 \end_inset
36319 </cell>
36320 </row>
36321 </lyxtabular>
36322
36323 \end_inset
36324
36325
36326 \end_layout
36327
36328 \begin_layout Standard
36329 \begin_inset Note Comment
36330 status collapsed
36331
36332 \begin_layout Standard
36333 In the original article Figure II was announced to be downloadable on 
36334 \shape italic
36335 Circuit Cellar
36336 \shape default
36337 's web site.
36338  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
36339 \end_layout
36340
36341 \end_inset
36342
36343
36344 \end_layout
36345
36346 \begin_layout Paragraph*
36347 ICode Example
36348 \begin_inset LatexCommand \index{iCode}
36349
36350 \end_inset
36351
36352
36353 \end_layout
36354
36355 \begin_layout Standard
36356 This section shows some details of iCode.
36357  The example C code does not do anything useful; it is used as an example
36358  to illustrate the intermediate code generated by the compiler.
36359 \end_layout
36360
36361 \begin_layout Verse
36362
36363 \family typewriter
36364 1.\InsetSpace ~
36365 xdata int * p;
36366 \newline
36367 2.\InsetSpace ~
36368 int gint;
36369 \newline
36370 3.\InsetSpace ~
36371 /* This function does nothing useful.
36372  It is used
36373 \newline
36374 4.\InsetSpace ~
36375 \InsetSpace ~
36376 \InsetSpace ~
36377 \InsetSpace ~
36378 for the purpose of explaining iCode */
36379 \newline
36380 5.\InsetSpace ~
36381 short function (data
36382  int *x)
36383 \newline
36384 6.\InsetSpace ~
36385 {
36386 \newline
36387 7.\InsetSpace ~
36388 \InsetSpace ~
36389 \InsetSpace ~
36390 short i=10; \InsetSpace ~
36391 \InsetSpace ~
36392 /* dead initialization eliminated */
36393 \newline
36394 8.\InsetSpace ~
36395 \InsetSpace ~
36396 \InsetSpace ~
36397 short sum=10;
36398  /* dead initialization eliminated */
36399 \newline
36400 9.\InsetSpace ~
36401 \InsetSpace ~
36402 \InsetSpace ~
36403 short mul;
36404 \newline
36405 10.\InsetSpace ~
36406 \InsetSpace ~
36407 int j ;
36408 \newline
36409 11.\InsetSpace ~
36410 \InsetSpace ~
36411 while (*x) *x++
36412  = *p++; 
36413 \newline
36414 12.\InsetSpace ~
36415 \InsetSpace ~
36416 \InsetSpace ~
36417 \InsetSpace ~
36418 sum = 0 ; 
36419 \newline
36420 13.\InsetSpace ~
36421 \InsetSpace ~
36422 mul = 0;
36423 \newline
36424 14.\InsetSpace ~
36425 \InsetSpace ~
36426 /* compiler detects i,j to be induction
36427  variables */
36428 \newline
36429 15.\InsetSpace ~
36430 \InsetSpace ~
36431 for (i = 0, j = 10 ; i < 10 ; i++, j
36432 \family default
36433 -
36434 \begin_inset ERT
36435 status collapsed
36436
36437 \begin_layout Standard
36438
36439
36440 \backslash
36441 /
36442 \end_layout
36443
36444 \end_inset
36445
36446 -
36447 \family typewriter
36448 ) {
36449 \newline
36450 16.\InsetSpace ~
36451 \InsetSpace ~
36452 \InsetSpace ~
36453 \InsetSpace ~
36454 sum += i;
36455 \newline
36456 17.\InsetSpace ~
36457 \InsetSpace ~
36458 \InsetSpace ~
36459 \InsetSpace ~
36460 mul += i * 3; \InsetSpace ~
36461 \InsetSpace ~
36462 /* this multiplication remains */
36463 \newline
36464 18.\InsetSpace ~
36465 \InsetSpace ~
36466 \InsetSpace ~
36467 \InsetSpace ~
36468 gint +=
36469  j * 3;\InsetSpace ~
36470 \InsetSpace ~
36471 /* this multiplication changed to addition */
36472 \newline
36473 19.\InsetSpace ~
36474 \InsetSpace ~
36475 }
36476 \newline
36477 20.\InsetSpace ~
36478 \InsetSpace ~
36479 return sum+mul;
36480 \newline
36481 21.\InsetSpace ~
36482 }
36483 \end_layout
36484
36485 \begin_layout Standard
36486 In addition to the operands each iCode contains information about the filename
36487  and line it corresponds to in the source file.
36488  The first field in the listing should be interpreted as follows:
36489 \newline
36490
36491 \shape italic
36492 \size footnotesize
36493 Filename(linenumber: iCode Execution sequence number : ICode hash table
36494  key : loop depth of the iCode).
36495 \shape default
36496 \size default
36497
36498 \newline
36499 Then follows the human readable form of the ICode operation.
36500  Each operand of this triplet form can be of three basic types a) compiler
36501  generated temporary b) user defined variable c) a constant value.
36502  Note that local variables and parameters are replaced by compiler generated
36503  temporaries.
36504  Live ranges
36505 \begin_inset LatexCommand \index{Live range analysis}
36506
36507 \end_inset
36508
36509  are computed only for temporaries (i.e.
36510  live ranges are not computed for global variables).
36511  Registers
36512 \begin_inset LatexCommand \index{Register allocation}
36513
36514 \end_inset
36515
36516  are allocated for temporaries only.
36517  Operands are formatted in the following manner:
36518 \newline
36519
36520 \shape italic
36521 \size footnotesize
36522 Operand Name [lr live-from : live-to ] { type information } [ registers
36523  allocated ].
36524 \shape default
36525 \size default
36526
36527 \newline
36528 As mentioned earlier the live ranges are computed in terms of the execution
36529  sequence number of the iCodes, for example 
36530 \newline
36531 the iTemp0 is live from (i.e.
36532  first defined in iCode with execution sequence number 3, and is last used
36533  in the iCode with sequence number 5).
36534  For induction variables such as iTemp21 the live range computation extends
36535  the lifetime from the start to the end of the loop.
36536 \newline
36537 The register allocator
36538  used the live range information to allocate registers, the same registers
36539  may be used for different temporaries if their live ranges do not overlap,
36540  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
36541  ranges do not overlap.
36542  In addition the allocator also takes into consideration the type and usage
36543  of a temporary, for example itemp6 is a pointer to near space and is used
36544  as to fetch data from (i.e.
36545  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
36546  Some short lived temporaries are allocated to special registers which have
36547  meaning to the code generator e.g.
36548  iTemp13 is allocated to a pseudo register CC which tells the back end that
36549  the temporary is used only for a conditional jump the code generation makes
36550  use of this information to optimize a compare and jump ICode.
36551 \newline
36552 There are several
36553  loop optimizations
36554 \begin_inset LatexCommand \index{Loop optimization}
36555
36556 \end_inset
36557
36558  performed by the compiler.
36559  It can detect induction variables iTemp21(i) and iTemp23(j).
36560  Also note the compiler does selective strength reduction
36561 \begin_inset LatexCommand \index{Strength reduction}
36562
36563 \end_inset
36564
36565 , i.e.
36566  the multiplication of an induction variable in line 18 (gint = j * 3) is
36567  changed to addition, a new temporary iTemp17 is allocated and assigned
36568  a initial value, a constant 3 is then added for each iteration of the loop.
36569  The compiler does not change the multiplication
36570 \begin_inset LatexCommand \index{Multiplication}
36571
36572 \end_inset
36573
36574  in line 17 however since the processor does support an 8 * 8 bit multiplication.
36575 \newline
36576
36577 Note the dead code elimination
36578 \begin_inset LatexCommand \index{Dead-code elimination}
36579
36580 \end_inset
36581
36582  optimization eliminated the dead assignments in line 7 & 8 to I and sum
36583  respectively.
36584 \newline
36585
36586 \end_layout
36587
36588 \begin_layout Standard
36589
36590 \size footnotesize
36591 Sample.c (5:1:0:0) _entry($9) :
36592 \end_layout
36593
36594 \begin_layout Standard
36595
36596 \size footnotesize
36597 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
36598 \end_layout
36599
36600 \begin_layout Standard
36601
36602 \size footnotesize
36603 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
36604 \end_layout
36605
36606 \begin_layout Standard
36607
36608 \size footnotesize
36609 Sample.c(11:4:53:0) preHeaderLbl0($11) :
36610 \end_layout
36611
36612 \begin_layout Standard
36613
36614 \size footnotesize
36615 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
36616  * int}[r2]
36617 \end_layout
36618
36619 \begin_layout Standard
36620
36621 \size footnotesize
36622 Sample.c(11:6:5:1) _whilecontinue_0($1) :
36623 \end_layout
36624
36625 \begin_layout Standard
36626
36627 \size footnotesize
36628 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
36629  int}[r0]]
36630 \end_layout
36631
36632 \begin_layout Standard
36633
36634 \size footnotesize
36635 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
36636 \end_layout
36637
36638 \begin_layout Standard
36639
36640 \size footnotesize
36641 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
36642  * int}
36643 \end_layout
36644
36645 \begin_layout Standard
36646
36647 \size footnotesize
36648 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
36649  {short}
36650 \end_layout
36651
36652 \begin_layout Standard
36653
36654 \size footnotesize
36655 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
36656  * int}[DPTR]]
36657 \end_layout
36658
36659 \begin_layout Standard
36660
36661 \size footnotesize
36662 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
36663 }[r2 r3]
36664 \end_layout
36665
36666 \begin_layout Standard
36667
36668 \size footnotesize
36669 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
36670  * int}[r0] + 0x2 {short}
36671 \end_layout
36672
36673 \begin_layout Standard
36674
36675 \size footnotesize
36676 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
36677 \end_layout
36678
36679 \begin_layout Standard
36680
36681 \size footnotesize
36682 Sample.c(11:17:21:0)_whilebreak_0($3) :
36683 \end_layout
36684
36685 \begin_layout Standard
36686
36687 \size footnotesize
36688 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
36689 \end_layout
36690
36691 \begin_layout Standard
36692
36693 \size footnotesize
36694 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
36695 \end_layout
36696
36697 \begin_layout Standard
36698
36699 \size footnotesize
36700 Sample.c(15:20:54:0)preHeaderLbl1($13) :
36701 \end_layout
36702
36703 \begin_layout Standard
36704
36705 \size footnotesize
36706 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
36707 \end_layout
36708
36709 \begin_layout Standard
36710
36711 \size footnotesize
36712 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
36713 \end_layout
36714
36715 \begin_layout Standard
36716
36717 \size footnotesize
36718 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
36719 \end_layout
36720
36721 \begin_layout Standard
36722
36723 \size footnotesize
36724 Sample.c(15:24:26:1)_forcond_0($4) :
36725 \end_layout
36726
36727 \begin_layout Standard
36728
36729 \size footnotesize
36730 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
36731  < 0xa {short}
36732 \end_layout
36733
36734 \begin_layout Standard
36735
36736 \size footnotesize
36737 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
36738 \end_layout
36739
36740 \begin_layout Standard
36741
36742 \size footnotesize
36743 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
36744  + ITemp21 [lr21:38]{short}[r4]
36745 \end_layout
36746
36747 \begin_layout Standard
36748
36749 \size footnotesize
36750 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
36751  * 0x3 {short}
36752 \end_layout
36753
36754 \begin_layout Standard
36755
36756 \size footnotesize
36757 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
36758  + iTemp15 [lr29:30]{short}[r1]
36759 \end_layout
36760
36761 \begin_layout Standard
36762
36763 \size footnotesize
36764 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
36765  r0]- 0x3 {short}
36766 \end_layout
36767
36768 \begin_layout Standard
36769
36770 \size footnotesize
36771 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
36772 int}[r7 r0]
36773 \end_layout
36774
36775 \begin_layout Standard
36776
36777 \size footnotesize
36778 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
36779  + 0x1 {short}
36780 \end_layout
36781
36782 \begin_layout Standard
36783
36784 \size footnotesize
36785 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
36786  r6]- 0x1 {short}
36787 \end_layout
36788
36789 \begin_layout Standard
36790
36791 \size footnotesize
36792 Sample.c(19:38:47:1) goto _forcond_0($4)
36793 \end_layout
36794
36795 \begin_layout Standard
36796
36797 \size footnotesize
36798 Sample.c(19:39:48:0)_forbreak_0($7) :
36799 \end_layout
36800
36801 \begin_layout Standard
36802
36803 \size footnotesize
36804 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
36805  + ITemp11 [lr19:40]{short}[r3]
36806 \end_layout
36807
36808 \begin_layout Standard
36809
36810 \size footnotesize
36811 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
36812 \end_layout
36813
36814 \begin_layout Standard
36815
36816 \size footnotesize
36817 Sample.c(20:42:51:0)_return($8) :
36818 \end_layout
36819
36820 \begin_layout Standard
36821
36822 \size footnotesize
36823 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
36824 \size default
36825
36826 \newline
36827
36828 \newline
36829 Finally the code generated for this function:
36830 \newline
36831
36832 \end_layout
36833
36834 \begin_layout Standard
36835
36836 \size footnotesize
36837 .area DSEG (DATA)
36838 \end_layout
36839
36840 \begin_layout Standard
36841
36842 \size footnotesize
36843 _p::
36844 \end_layout
36845
36846 \begin_layout Standard
36847
36848 \size footnotesize
36849 \InsetSpace ~
36850 \InsetSpace ~
36851 .ds 2
36852 \end_layout
36853
36854 \begin_layout Standard
36855
36856 \size footnotesize
36857 _gint::
36858 \end_layout
36859
36860 \begin_layout Standard
36861
36862 \size footnotesize
36863 \InsetSpace ~
36864 \InsetSpace ~
36865 .ds 2
36866 \end_layout
36867
36868 \begin_layout Standard
36869
36870 \size footnotesize
36871 ; sample.c 5
36872 \end_layout
36873
36874 \begin_layout Standard
36875
36876 \size footnotesize
36877 ; ----------------------------------------------
36878 \end_layout
36879
36880 \begin_layout Standard
36881
36882 \size footnotesize
36883 ; function function
36884 \end_layout
36885
36886 \begin_layout Standard
36887
36888 \size footnotesize
36889 ; ----------------------------------------------
36890 \end_layout
36891
36892 \begin_layout Standard
36893
36894 \size footnotesize
36895 _function:
36896 \end_layout
36897
36898 \begin_layout Standard
36899
36900 \size footnotesize
36901 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
36902 \end_layout
36903
36904 \begin_layout Standard
36905
36906 \size footnotesize
36907 \InsetSpace ~
36908 \InsetSpace ~
36909 mov r2,dpl
36910 \end_layout
36911
36912 \begin_layout Standard
36913
36914 \size footnotesize
36915 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
36916 \end_layout
36917
36918 \begin_layout Standard
36919
36920 \size footnotesize
36921 \InsetSpace ~
36922 \InsetSpace ~
36923 mov ar0,r2
36924 \end_layout
36925
36926 \begin_layout Standard
36927
36928 \size footnotesize
36929 ;_whilecontinue_0($1) :
36930 \end_layout
36931
36932 \begin_layout Standard
36933
36934 \size footnotesize
36935 00101$:
36936 \end_layout
36937
36938 \begin_layout Standard
36939
36940 \size footnotesize
36941 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
36942 \end_layout
36943
36944 \begin_layout Standard
36945
36946 \size footnotesize
36947 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
36948 \end_layout
36949
36950 \begin_layout Standard
36951
36952 \size footnotesize
36953 \InsetSpace ~
36954 \InsetSpace ~
36955 mov ar2,@r0
36956 \end_layout
36957
36958 \begin_layout Standard
36959
36960 \size footnotesize
36961 \InsetSpace ~
36962 \InsetSpace ~
36963 inc r0
36964 \end_layout
36965
36966 \begin_layout Standard
36967
36968 \size footnotesize
36969 \InsetSpace ~
36970 \InsetSpace ~
36971 mov ar3,@r0
36972 \end_layout
36973
36974 \begin_layout Standard
36975
36976 \size footnotesize
36977 \InsetSpace ~
36978 \InsetSpace ~
36979 dec r0
36980 \end_layout
36981
36982 \begin_layout Standard
36983
36984 \size footnotesize
36985 \InsetSpace ~
36986 \InsetSpace ~
36987 mov a,r2
36988 \end_layout
36989
36990 \begin_layout Standard
36991
36992 \size footnotesize
36993 \InsetSpace ~
36994 \InsetSpace ~
36995 orl a,r3
36996 \end_layout
36997
36998 \begin_layout Standard
36999
37000 \size footnotesize
37001 \InsetSpace ~
37002 \InsetSpace ~
37003 jz 00103$
37004 \end_layout
37005
37006 \begin_layout Standard
37007
37008 \size footnotesize
37009 00114$:
37010 \end_layout
37011
37012 \begin_layout Standard
37013
37014 \size footnotesize
37015 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
37016 \end_layout
37017
37018 \begin_layout Standard
37019
37020 \size footnotesize
37021 \InsetSpace ~
37022 \InsetSpace ~
37023 mov dpl,_p
37024 \end_layout
37025
37026 \begin_layout Standard
37027
37028 \size footnotesize
37029 \InsetSpace ~
37030 \InsetSpace ~
37031 mov dph,(_p + 1)
37032 \end_layout
37033
37034 \begin_layout Standard
37035
37036 \size footnotesize
37037 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
37038 \end_layout
37039
37040 \begin_layout Standard
37041
37042 \size footnotesize
37043 \InsetSpace ~
37044 \InsetSpace ~
37045 mov a,#0x02
37046 \end_layout
37047
37048 \begin_layout Standard
37049
37050 \size footnotesize
37051 \InsetSpace ~
37052 \InsetSpace ~
37053 add a,_p
37054 \end_layout
37055
37056 \begin_layout Standard
37057
37058 \size footnotesize
37059 \InsetSpace ~
37060 \InsetSpace ~
37061 mov _p,a
37062 \end_layout
37063
37064 \begin_layout Standard
37065
37066 \size footnotesize
37067 \InsetSpace ~
37068 \InsetSpace ~
37069 clr a
37070 \end_layout
37071
37072 \begin_layout Standard
37073
37074 \size footnotesize
37075 \InsetSpace ~
37076 \InsetSpace ~
37077 addc a,(_p + 1)
37078 \end_layout
37079
37080 \begin_layout Standard
37081
37082 \size footnotesize
37083 \InsetSpace ~
37084 \InsetSpace ~
37085 mov (_p + 1),a
37086 \end_layout
37087
37088 \begin_layout Standard
37089
37090 \size footnotesize
37091 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
37092 \end_layout
37093
37094 \begin_layout Standard
37095
37096 \size footnotesize
37097 \InsetSpace ~
37098 \InsetSpace ~
37099 movx a,@dptr
37100 \end_layout
37101
37102 \begin_layout Standard
37103
37104 \size footnotesize
37105 \InsetSpace ~
37106 \InsetSpace ~
37107 mov r2,a
37108 \end_layout
37109
37110 \begin_layout Standard
37111
37112 \size footnotesize
37113 \InsetSpace ~
37114 \InsetSpace ~
37115 inc dptr
37116 \end_layout
37117
37118 \begin_layout Standard
37119
37120 \size footnotesize
37121 \InsetSpace ~
37122 \InsetSpace ~
37123 movx a,@dptr
37124 \end_layout
37125
37126 \begin_layout Standard
37127
37128 \size footnotesize
37129 \InsetSpace ~
37130 \InsetSpace ~
37131 mov r3,a
37132 \end_layout
37133
37134 \begin_layout Standard
37135
37136 \size footnotesize
37137 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
37138 \end_layout
37139
37140 \begin_layout Standard
37141
37142 \size footnotesize
37143 \InsetSpace ~
37144 \InsetSpace ~
37145 mov @r0,ar2
37146 \end_layout
37147
37148 \begin_layout Standard
37149
37150 \size footnotesize
37151 \InsetSpace ~
37152 \InsetSpace ~
37153 inc r0
37154 \end_layout
37155
37156 \begin_layout Standard
37157
37158 \size footnotesize
37159 \InsetSpace ~
37160 \InsetSpace ~
37161 mov @r0,ar3
37162 \end_layout
37163
37164 \begin_layout Standard
37165
37166 \size footnotesize
37167 ; iTemp6 [lr5:16]{_near * int}[r0] = 
37168 \end_layout
37169
37170 \begin_layout Standard
37171
37172 \size footnotesize
37173 ; iTemp6 [lr5:16]{_near * int}[r0] + 
37174 \end_layout
37175
37176 \begin_layout Standard
37177
37178 \size footnotesize
37179 ; 0x2 {short}
37180 \end_layout
37181
37182 \begin_layout Standard
37183
37184 \size footnotesize
37185 \InsetSpace ~
37186 \InsetSpace ~
37187 inc r0
37188 \end_layout
37189
37190 \begin_layout Standard
37191
37192 \size footnotesize
37193 ; goto _whilecontinue_0($1)
37194 \end_layout
37195
37196 \begin_layout Standard
37197
37198 \size footnotesize
37199 \InsetSpace ~
37200 \InsetSpace ~
37201 sjmp 00101$
37202 \end_layout
37203
37204 \begin_layout Standard
37205
37206 \size footnotesize
37207 ; _whilebreak_0($3) :
37208 \end_layout
37209
37210 \begin_layout Standard
37211
37212 \size footnotesize
37213 00103$:
37214 \end_layout
37215
37216 \begin_layout Standard
37217
37218 \size footnotesize
37219 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
37220 \end_layout
37221
37222 \begin_layout Standard
37223
37224 \size footnotesize
37225 \InsetSpace ~
37226 \InsetSpace ~
37227 mov r2,#0x00
37228 \end_layout
37229
37230 \begin_layout Standard
37231
37232 \size footnotesize
37233 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
37234 \end_layout
37235
37236 \begin_layout Standard
37237
37238 \size footnotesize
37239 \InsetSpace ~
37240 \InsetSpace ~
37241 mov r3,#0x00
37242 \end_layout
37243
37244 \begin_layout Standard
37245
37246 \size footnotesize
37247 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
37248 \end_layout
37249
37250 \begin_layout Standard
37251
37252 \size footnotesize
37253 \InsetSpace ~
37254 \InsetSpace ~
37255 mov r4,#0x00
37256 \end_layout
37257
37258 \begin_layout Standard
37259
37260 \size footnotesize
37261 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
37262 \end_layout
37263
37264 \begin_layout Standard
37265
37266 \size footnotesize
37267 \InsetSpace ~
37268 \InsetSpace ~
37269 mov r5,#0x0A
37270 \end_layout
37271
37272 \begin_layout Standard
37273
37274 \size footnotesize
37275 \InsetSpace ~
37276 \InsetSpace ~
37277 mov r6,#0x00
37278 \end_layout
37279
37280 \begin_layout Standard
37281
37282 \size footnotesize
37283 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
37284 \end_layout
37285
37286 \begin_layout Standard
37287
37288 \size footnotesize
37289 \InsetSpace ~
37290 \InsetSpace ~
37291 mov r7,#0x1E
37292 \end_layout
37293
37294 \begin_layout Standard
37295
37296 \size footnotesize
37297 \InsetSpace ~
37298 \InsetSpace ~
37299 mov r0,#0x00
37300 \end_layout
37301
37302 \begin_layout Standard
37303
37304 \size footnotesize
37305 ; _forcond_0($4) :
37306 \end_layout
37307
37308 \begin_layout Standard
37309
37310 \size footnotesize
37311 00104$:
37312 \end_layout
37313
37314 \begin_layout Standard
37315
37316 \size footnotesize
37317 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
37318 \end_layout
37319
37320 \begin_layout Standard
37321
37322 \size footnotesize
37323 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
37324 \end_layout
37325
37326 \begin_layout Standard
37327
37328 \size footnotesize
37329 \InsetSpace ~
37330 \InsetSpace ~
37331 clr c
37332 \end_layout
37333
37334 \begin_layout Standard
37335
37336 \size footnotesize
37337 \InsetSpace ~
37338 \InsetSpace ~
37339 mov a,r4
37340 \end_layout
37341
37342 \begin_layout Standard
37343
37344 \size footnotesize
37345 \InsetSpace ~
37346 \InsetSpace ~
37347 xrl a,#0x80
37348 \end_layout
37349
37350 \begin_layout Standard
37351
37352 \size footnotesize
37353 \InsetSpace ~
37354 \InsetSpace ~
37355 subb a,#0x8a
37356 \end_layout
37357
37358 \begin_layout Standard
37359
37360 \size footnotesize
37361 \InsetSpace ~
37362 \InsetSpace ~
37363 jnc 00107$
37364 \end_layout
37365
37366 \begin_layout Standard
37367
37368 \size footnotesize
37369 00115$:
37370 \end_layout
37371
37372 \begin_layout Standard
37373
37374 \size footnotesize
37375 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
37376 \end_layout
37377
37378 \begin_layout Standard
37379
37380 \size footnotesize
37381 ; iTemp21 [lr21:38]{short}[r4]
37382 \end_layout
37383
37384 \begin_layout Standard
37385
37386 \size footnotesize
37387 \InsetSpace ~
37388 \InsetSpace ~
37389 mov a,r4
37390 \end_layout
37391
37392 \begin_layout Standard
37393
37394 \size footnotesize
37395 \InsetSpace ~
37396 \InsetSpace ~
37397 add a,r2
37398 \end_layout
37399
37400 \begin_layout Standard
37401
37402 \size footnotesize
37403 \InsetSpace ~
37404 \InsetSpace ~
37405 mov r2,a
37406 \end_layout
37407
37408 \begin_layout Standard
37409
37410 \size footnotesize
37411 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
37412 \end_layout
37413
37414 \begin_layout Standard
37415
37416 \size footnotesize
37417 \InsetSpace ~
37418 \InsetSpace ~
37419 mov b,#0x03
37420 \end_layout
37421
37422 \begin_layout Standard
37423
37424 \size footnotesize
37425 \InsetSpace ~
37426 \InsetSpace ~
37427 mov a,r4
37428 \end_layout
37429
37430 \begin_layout Standard
37431
37432 \size footnotesize
37433 \InsetSpace ~
37434 \InsetSpace ~
37435 mul ab
37436 \end_layout
37437
37438 \begin_layout Standard
37439
37440 \size footnotesize
37441 \InsetSpace ~
37442 \InsetSpace ~
37443 mov r1,a
37444 \end_layout
37445
37446 \begin_layout Standard
37447
37448 \size footnotesize
37449 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
37450 \end_layout
37451
37452 \begin_layout Standard
37453
37454 \size footnotesize
37455 ; iTemp15 [lr29:30]{short}[r1]
37456 \end_layout
37457
37458 \begin_layout Standard
37459
37460 \size footnotesize
37461 \InsetSpace ~
37462 \InsetSpace ~
37463 add a,r3
37464 \end_layout
37465
37466 \begin_layout Standard
37467
37468 \size footnotesize
37469 \InsetSpace ~
37470 \InsetSpace ~
37471 mov r3,a
37472 \end_layout
37473
37474 \begin_layout Standard
37475
37476 \size footnotesize
37477 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
37478 \end_layout
37479
37480 \begin_layout Standard
37481
37482 \size footnotesize
37483 \InsetSpace ~
37484 \InsetSpace ~
37485 mov a,r7
37486 \end_layout
37487
37488 \begin_layout Standard
37489
37490 \size footnotesize
37491 \InsetSpace ~
37492 \InsetSpace ~
37493 add a,#0xfd
37494 \end_layout
37495
37496 \begin_layout Standard
37497
37498 \size footnotesize
37499 \InsetSpace ~
37500 \InsetSpace ~
37501 mov r7,a
37502 \end_layout
37503
37504 \begin_layout Standard
37505
37506 \size footnotesize
37507 \InsetSpace ~
37508 \InsetSpace ~
37509 mov a,r0
37510 \end_layout
37511
37512 \begin_layout Standard
37513
37514 \size footnotesize
37515 \InsetSpace ~
37516 \InsetSpace ~
37517 addc a,#0xff
37518 \end_layout
37519
37520 \begin_layout Standard
37521
37522 \size footnotesize
37523 \InsetSpace ~
37524 \InsetSpace ~
37525 mov r0,a
37526 \end_layout
37527
37528 \begin_layout Standard
37529
37530 \size footnotesize
37531 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
37532 \end_layout
37533
37534 \begin_layout Standard
37535
37536 \size footnotesize
37537 \InsetSpace ~
37538 \InsetSpace ~
37539 mov a,r7
37540 \end_layout
37541
37542 \begin_layout Standard
37543
37544 \size footnotesize
37545 \InsetSpace ~
37546 \InsetSpace ~
37547 add a,_gint
37548 \end_layout
37549
37550 \begin_layout Standard
37551
37552 \size footnotesize
37553 \InsetSpace ~
37554 \InsetSpace ~
37555 mov _gint,a
37556 \end_layout
37557
37558 \begin_layout Standard
37559
37560 \size footnotesize
37561 \InsetSpace ~
37562 \InsetSpace ~
37563 mov a,r0
37564 \end_layout
37565
37566 \begin_layout Standard
37567
37568 \size footnotesize
37569 \InsetSpace ~
37570 \InsetSpace ~
37571 addc a,(_gint + 1)
37572 \end_layout
37573
37574 \begin_layout Standard
37575
37576 \size footnotesize
37577 \InsetSpace ~
37578 \InsetSpace ~
37579 mov (_gint + 1),a
37580 \end_layout
37581
37582 \begin_layout Standard
37583
37584 \size footnotesize
37585 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
37586 \end_layout
37587
37588 \begin_layout Standard
37589
37590 \size footnotesize
37591 \InsetSpace ~
37592 \InsetSpace ~
37593 inc r4
37594 \end_layout
37595
37596 \begin_layout Standard
37597
37598 \size footnotesize
37599 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
37600 \end_layout
37601
37602 \begin_layout Standard
37603
37604 \size footnotesize
37605 \InsetSpace ~
37606 \InsetSpace ~
37607 dec r5
37608 \end_layout
37609
37610 \begin_layout Standard
37611
37612 \size footnotesize
37613 \InsetSpace ~
37614 \InsetSpace ~
37615 cjne r5,#0xff,00104$
37616 \end_layout
37617
37618 \begin_layout Standard
37619
37620 \size footnotesize
37621 \InsetSpace ~
37622 \InsetSpace ~
37623 dec r6
37624 \end_layout
37625
37626 \begin_layout Standard
37627
37628 \size footnotesize
37629 ; goto _forcond_0($4)
37630 \end_layout
37631
37632 \begin_layout Standard
37633
37634 \size footnotesize
37635 \InsetSpace ~
37636 \InsetSpace ~
37637 sjmp 00104$
37638 \end_layout
37639
37640 \begin_layout Standard
37641
37642 \size footnotesize
37643 ; _forbreak_0($7) :
37644 \end_layout
37645
37646 \begin_layout Standard
37647
37648 \size footnotesize
37649 00107$:
37650 \end_layout
37651
37652 \begin_layout Standard
37653
37654 \size footnotesize
37655 ; ret iTemp24 [lr40:41]{short}
37656 \end_layout
37657
37658 \begin_layout Standard
37659
37660 \size footnotesize
37661 \InsetSpace ~
37662 \InsetSpace ~
37663 mov a,r3
37664 \end_layout
37665
37666 \begin_layout Standard
37667
37668 \size footnotesize
37669 \InsetSpace ~
37670 \InsetSpace ~
37671 add a,r2
37672 \end_layout
37673
37674 \begin_layout Standard
37675
37676 \size footnotesize
37677 \InsetSpace ~
37678 \InsetSpace ~
37679 mov dpl,a
37680 \end_layout
37681
37682 \begin_layout Standard
37683
37684 \size footnotesize
37685 ; _return($8) :
37686 \end_layout
37687
37688 \begin_layout Standard
37689
37690 \size footnotesize
37691 00108$:
37692 \end_layout
37693
37694 \begin_layout Standard
37695
37696 \size footnotesize
37697 \InsetSpace ~
37698 \InsetSpace ~
37699 ret
37700 \newline
37701
37702 \end_layout
37703
37704 \begin_layout Section
37705 A few words about basic block successors, predecessors and dominators
37706 \end_layout
37707
37708 \begin_layout Standard
37709 Successors are basic blocks
37710 \begin_inset LatexCommand \index{Basic blocks}
37711
37712 \end_inset
37713
37714  that might execute after this basic block.
37715 \newline
37716 Predecessors are basic blocks
37717  that might execute before reaching this basic block.
37718 \newline
37719 Dominators are basic
37720  blocks that WILL execute before reaching this basic block.
37721 \newline
37722
37723 \end_layout
37724
37725 \begin_layout Standard
37726 [basic block 1]
37727 \end_layout
37728
37729 \begin_layout Standard
37730 if (something)
37731 \end_layout
37732
37733 \begin_layout Standard
37734 \InsetSpace ~
37735 \InsetSpace ~
37736 \InsetSpace ~
37737 \InsetSpace ~
37738 [basic block 2]
37739 \end_layout
37740
37741 \begin_layout Standard
37742 else
37743 \end_layout
37744
37745 \begin_layout Standard
37746 \InsetSpace ~
37747 \InsetSpace ~
37748 \InsetSpace ~
37749 \InsetSpace ~
37750 [basic block 3]
37751 \end_layout
37752
37753 \begin_layout Standard
37754 [basic block 4]
37755 \newline
37756
37757 \end_layout
37758
37759 \begin_layout Standard
37760 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
37761 \end_layout
37762
37763 \begin_layout Standard
37764 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
37765 \end_layout
37766
37767 \begin_layout Standard
37768 c) domVect of [BB4] = BB1 ...
37769  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
37770  was executed.
37771 \end_layout
37772
37773 \begin_layout Chapter
37774 Acknowledgments
37775 \end_layout
37776
37777 \begin_layout Standard
37778 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
37779
37780 \end_inset
37781
37782
37783 \newline
37784
37785 \newline
37786
37787 \emph on
37788 Thanks to all the other volunteer developers who have helped with coding,
37789  testing, web-page creation, distribution sets, etc.
37790  You know who you are :-)
37791 \emph default
37792
37793 \newline
37794
37795 \newline
37796
37797 \emph on
37798 Also thanks to Sourceforge 
37799 \begin_inset LatexCommand \url{http://www.sf.net}
37800
37801 \end_inset
37802
37803  which has hosted the project since 1999 and donates significant download
37804  bandwidth and probably more than 
37805 \begin_inset ERT
37806 status collapsed
37807
37808 \begin_layout Standard
37809
37810 $10^{13}$
37811 \end_layout
37812
37813 \end_inset
37814
37815 CPU cycles per day.
37816 \newline
37817  
37818 \begin_inset Note Note
37819 status open
37820
37821 \begin_layout Standard
37822 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
37823  minutes for (configure+make+regression test), and there is (i386, amd64,
37824  alpha, ppc64, (mingw32), sparc, macosx).
37825  
37826 \end_layout
37827
37828 \end_inset
37829
37830
37831 \end_layout
37832
37833 \begin_layout Standard
37834 This document was initially written by Sandeep Dutta
37835 \end_layout
37836
37837 \begin_layout Standard
37838 All product names mentioned herein may be trademarks
37839 \begin_inset LatexCommand \index{Trademarks}
37840
37841 \end_inset
37842
37843  of their respective companies.
37844  
37845 \end_layout
37846
37847 \begin_layout Section*
37848 Alphabetical index
37849 \end_layout
37850
37851 \begin_layout Standard
37852 To avoid confusion, the installation and building options for SDCC itself
37853  (chapter 2) are not part of the index.
37854 \end_layout
37855
37856 \begin_layout Standard
37857 \begin_inset LatexCommand \printindex{}
37858
37859 \end_inset
37860
37861
37862 \end_layout
37863
37864 \end_body
37865 \end_document