add printf_tiny data dependent integer speed footnote
[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 sure 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 \begin_inset Foot
18847 status collapsed
18848
18849 \begin_layout Standard
18850 printf_tiny integer speed is data dependent, worst case is 0.33 ms
18851 \end_layout
18852
18853 \end_inset
18854
18855
18856 \end_layout
18857
18858 \end_inset
18859 </cell>
18860 </row>
18861 <row bottomline="true">
18862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18863 \begin_inset Text
18864
18865 \begin_layout Standard
18866 long speed
18867 \begin_inset Foot
18868 status collapsed
18869
18870 \begin_layout Standard
18871 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
18872  empty putchar()
18873 \end_layout
18874
18875 \end_inset
18876
18877 ,
18878 \end_layout
18879
18880 \begin_layout Standard
18881 small / large
18882 \end_layout
18883
18884 \end_inset
18885 </cell>
18886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18887 \begin_inset Text
18888
18889 \begin_layout Standard
18890 5.37 / 6.31 ms
18891 \end_layout
18892
18893 \end_inset
18894 </cell>
18895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18896 \begin_inset Text
18897
18898 \begin_layout Standard
18899 5.37 / 6.31 ms
18900 \end_layout
18901
18902 \end_inset
18903 </cell>
18904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18905 \begin_inset Text
18906
18907 \begin_layout Standard
18908 8.71 / 40.65 ms
18909 \end_layout
18910
18911 \end_inset
18912 </cell>
18913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18914 \begin_inset Text
18915
18916 \begin_layout Standard
18917 0.40 / 0.40 ms
18918 \end_layout
18919
18920 \end_inset
18921 </cell>
18922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18923 \begin_inset Text
18924
18925 \begin_layout Standard
18926 0.40 / 0.40 ms
18927 \end_layout
18928
18929 \end_inset
18930 </cell>
18931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18932 \begin_inset Text
18933
18934 \begin_layout Standard
18935 -
18936 \end_layout
18937
18938 \end_inset
18939 </cell>
18940 </row>
18941 <row bottomline="true">
18942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18943 \begin_inset Text
18944
18945 \begin_layout Standard
18946 float speed
18947 \begin_inset Foot
18948 status collapsed
18949
18950 \begin_layout Standard
18951 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18952  empty putchar()
18953 \end_layout
18954
18955 \end_inset
18956
18957 ,
18958 \end_layout
18959
18960 \begin_layout Standard
18961 small / large
18962 \end_layout
18963
18964 \end_inset
18965 </cell>
18966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18967 \begin_inset Text
18968
18969 \begin_layout Standard
18970 -
18971 \end_layout
18972
18973 \end_inset
18974 </cell>
18975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18976 \begin_inset Text
18977
18978 \begin_layout Standard
18979 7.49 / 22.47 ms
18980 \end_layout
18981
18982 \end_inset
18983 </cell>
18984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18985 \begin_inset Text
18986
18987 \begin_layout Standard
18988 -
18989 \end_layout
18990
18991 \end_inset
18992 </cell>
18993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18994 \begin_inset Text
18995
18996 \begin_layout Standard
18997 -
18998 \end_layout
18999
19000 \end_inset
19001 </cell>
19002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19003 \begin_inset Text
19004
19005 \begin_layout Standard
19006 1.04 / 1.04 ms
19007 \end_layout
19008
19009 \end_inset
19010 </cell>
19011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19012 \begin_inset Text
19013
19014 \begin_layout Standard
19015 -
19016 \end_layout
19017
19018 \end_inset
19019 </cell>
19020 </row>
19021 </lyxtabular>
19022
19023 \end_inset
19024
19025
19026 \end_layout
19027
19028 \begin_layout Subsubsection
19029 <malloc.h>
19030 \begin_inset LatexCommand \index{malloc.h}
19031
19032 \end_inset
19033
19034
19035 \end_layout
19036
19037 \begin_layout Standard
19038 As of SDCC 2.6.2 you no longer need to call an initialization routine before
19039  using dynamic memory allocation
19040 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
19041
19042 \end_inset
19043
19044  and a default heap
19045 \begin_inset LatexCommand \index{heap (malloc)}
19046
19047 \end_inset
19048
19049  space of 1024 bytes is provided for malloc to allocate memory from.
19050  If you need a different heap size you need to recompile _heap.c with the
19051  required size defined in HEAP_SIZE.
19052  It is recommended to make a copy of this file into your project directory
19053  and compile it there with:
19054 \end_layout
19055
19056 \begin_layout Verse
19057
19058 \family typewriter
19059 sdcc -c _heap.c -D HEAD_SIZE=2048
19060 \end_layout
19061
19062 \begin_layout Standard
19063 And then link it with:
19064 \end_layout
19065
19066 \begin_layout Verse
19067
19068 \family typewriter
19069 sdcc main.rel _heap.rel
19070 \end_layout
19071
19072 \begin_layout Subsection
19073 Math functions (sinf, powf, sqrtf etc.)
19074 \end_layout
19075
19076 \begin_layout Subsubsection
19077 <math.h>
19078 \end_layout
19079
19080 \begin_layout Standard
19081 See definitions in file <math.h>.
19082 \end_layout
19083
19084 \begin_layout Subsection
19085 Other libraries
19086 \end_layout
19087
19088 \begin_layout Standard
19089 Libraries
19090 \begin_inset LatexCommand \index{Libraries}
19091
19092 \end_inset
19093
19094  included in SDCC should have a license at least as liberal as the GNU Lesser
19095  General Public License
19096 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
19097
19098 \end_inset
19099
19100  
19101 \emph on
19102 LGPL
19103 \emph default
19104 .
19105 \end_layout
19106
19107 \begin_layout Standard
19108 \begin_inset Note Comment
19109 status collapsed
19110
19111 \begin_layout Standard
19112 license statements for the libraries are missing.
19113  sdcc/device/lib/ser_ir.c
19114 \end_layout
19115
19116 \begin_layout Standard
19117 or _decdptr f.e.
19118  come with a GPL (as opposed to LGPL) License - this will not be liberal
19119  enough for many embedded programmers.
19120 \end_layout
19121
19122 \end_inset
19123
19124
19125 \end_layout
19126
19127 \begin_layout Standard
19128 If you have ported some library or want to share experience about some code
19129  which f.e.
19130  falls into any of these categories Busses (I
19131 \begin_inset Formula $^{\textrm{2}}$
19132 \end_inset
19133
19134 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
19135  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
19136  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
19137 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
19138
19139 \end_inset
19140
19141 \InsetSpace ~
19142 would certainly like to hear about it.
19143 \end_layout
19144
19145 \begin_layout Standard
19146 Programmers coding for embedded systems are not especially famous for being
19147  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
19148 e these references are very valuable.
19149  Let's help to create a climate where information is shared.
19150 \begin_inset VSpace bigskip
19151 \end_inset
19152
19153
19154 \end_layout
19155
19156 \begin_layout Section
19157 Memory Models
19158 \end_layout
19159
19160 \begin_layout Subsection
19161 MCS51 Memory Models
19162 \begin_inset LatexCommand \index{Memory model}
19163
19164 \end_inset
19165
19166
19167 \begin_inset LatexCommand \index{MCS51 memory model}
19168
19169 \end_inset
19170
19171
19172 \end_layout
19173
19174 \begin_layout Subsubsection
19175 Small, Medium and Large
19176 \end_layout
19177
19178 \begin_layout Standard
19179 SDCC allows three memory models for MCS51 code, 
19180 \shape slanted
19181 small, medium
19182 \shape default
19183  and 
19184 \shape slanted
19185 large
19186 \shape default
19187 .
19188  Modules compiled with different memory models should 
19189 \emph on
19190 never
19191 \emph default
19192  be combined together or the results would be unpredictable.
19193  The library routines supplied with the compiler are compiled as small,
19194  medium and large.
19195  The compiled library modules are contained in separate directories as small,
19196  medium and large so that you can link to the appropriate set.
19197 \end_layout
19198
19199 \begin_layout Standard
19200 When the medium or large model is used all variables declared without a
19201  storage class will be allocated into the external ram, this includes all
19202  parameters and local variables (for non-reentrant
19203 \begin_inset LatexCommand \index{reentrant}
19204
19205 \end_inset
19206
19207  functions).
19208  When the small model is used variables without storage class are allocated
19209  in the internal ram.
19210 \end_layout
19211
19212 \begin_layout Standard
19213 Judicious usage of the processor specific storage classes
19214 \begin_inset LatexCommand \index{Storage class}
19215
19216 \end_inset
19217
19218  and the 'reentrant' function type will yield much more efficient code,
19219  than using the large model.
19220  Several optimizations are disabled when the program is compiled using the
19221  large model, it is therefore recommended that the small model be used unless
19222  absolutely required.
19223 \end_layout
19224
19225 \begin_layout Subsubsection
19226 External Stack
19227 \begin_inset LatexCommand \label{sub:External-Stack}
19228
19229 \end_inset
19230
19231
19232 \begin_inset LatexCommand \index{stack}
19233
19234 \end_inset
19235
19236
19237 \begin_inset LatexCommand \index{External stack (mcs51)}
19238
19239 \end_inset
19240
19241
19242 \end_layout
19243
19244 \begin_layout Standard
19245 The external stack (-
19246 \begin_inset ERT
19247 status collapsed
19248
19249 \begin_layout Standard
19250
19251
19252 \backslash
19253 /
19254 \end_layout
19255
19256 \end_inset
19257
19258 -xstack option
19259 \begin_inset LatexCommand \index{-\/-xstack}
19260
19261 \end_inset
19262
19263 ) is located in pdata
19264 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19265
19266 \end_inset
19267
19268  memory (usually at the start of the external ram segment) and uses all
19269  unused space in pdata (max.
19270  256 bytes).
19271  When -
19272 \begin_inset ERT
19273 status collapsed
19274
19275 \begin_layout Standard
19276
19277
19278 \backslash
19279 /
19280 \end_layout
19281
19282 \end_inset
19283
19284 -xstack option is used to compile the program, the parameters and local
19285  variables
19286 \begin_inset LatexCommand \index{local variables}
19287
19288 \end_inset
19289
19290  of all reentrant functions are allocated in this area.
19291  This option is provided for programs with large stack space requirements.
19292  When used with the -
19293 \begin_inset ERT
19294 status collapsed
19295
19296 \begin_layout Standard
19297
19298
19299 \backslash
19300 /
19301 \end_layout
19302
19303 \end_inset
19304
19305 -stack-auto
19306 \begin_inset LatexCommand \index{-\/-stack-auto}
19307
19308 \end_inset
19309
19310  option, all parameters and local variables are allocated on the external
19311  stack (note: support libraries will need to be recompiled with the same
19312  options.
19313  There is a predefined target in the library makefile).
19314 \end_layout
19315
19316 \begin_layout Standard
19317 The compiler outputs the higher order address byte of the external ram segment
19318  into port P2
19319 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19320
19321 \end_inset
19322
19323  (see also section 
19324 \begin_inset LatexCommand \ref{sub:MCS51-variants}
19325
19326 \end_inset
19327
19328 ), therefore when using the External Stack option, this port 
19329 \emph on
19330 may not
19331 \emph default
19332  be used by the application program.
19333 \end_layout
19334
19335 \begin_layout Subsection
19336 DS390 Memory Model
19337 \begin_inset LatexCommand \index{Memory model}
19338
19339 \end_inset
19340
19341
19342 \begin_inset LatexCommand \index{DS390 memory model}
19343
19344 \end_inset
19345
19346
19347 \end_layout
19348
19349 \begin_layout Standard
19350 The only model supported is Flat 24
19351 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
19352
19353 \end_inset
19354
19355 .
19356  This generates code for the 24 bit contiguous addressing mode of the Dallas
19357  DS80C390 part.
19358  In this mode, up to four meg of external RAM or code space can be directly
19359  addressed.
19360  See the data sheets at www.dalsemi.com for further information on this part.
19361 \newline
19362
19363 \newline
19364 Note
19365  that the compiler does not generate any code to place the processor into
19366  24 bitmode (although 
19367 \emph on
19368 tinibios
19369 \emph default
19370  in the ds390 libraries will do that for you).
19371  If you don't use 
19372 \emph on
19373 tinibios
19374 \emph default
19375
19376 \begin_inset LatexCommand \index{Tinibios (DS390)}
19377
19378 \end_inset
19379
19380 , the boot loader or similar code must ensure that the processor is in 24
19381  bit contiguous addressing mode before calling the SDCC startup code.
19382 \newline
19383
19384 \newline
19385 Like
19386  the 
19387 \emph on
19388 -
19389 \begin_inset ERT
19390 status collapsed
19391
19392 \begin_layout Standard
19393
19394
19395 \backslash
19396 /
19397 \end_layout
19398
19399 \end_inset
19400
19401 -model-large
19402 \emph default
19403  option, variables will by default be placed into the XDATA segment.
19404  
19405 \newline
19406
19407 \newline
19408 Segments may be placed anywhere in the 4 meg address space using the usual
19409  -
19410 \begin_inset ERT
19411 status collapsed
19412
19413 \begin_layout Standard
19414
19415
19416 \backslash
19417 /
19418 \end_layout
19419
19420 \end_inset
19421
19422 -*-loc options.
19423  Note that if any segments are located above 64K, the -r flag must be passed
19424  to the linker to generate the proper segment relocations, and the Intel
19425  HEX output format must be used.
19426  The -r flag can be passed to the linker by using the option 
19427 \emph on
19428 -Wl-r
19429 \emph default
19430  on the SDCC command line.
19431  However, currently the linker can not handle code segments > 64k.
19432 \end_layout
19433
19434 \begin_layout Section
19435 Pragmas
19436 \begin_inset LatexCommand \label{sec:Pragmas}
19437
19438 \end_inset
19439
19440
19441 \begin_inset LatexCommand \index{Pragmas}
19442
19443 \end_inset
19444
19445
19446 \end_layout
19447
19448 \begin_layout Standard
19449 SDCC supports the following #pragma directives:
19450 \end_layout
19451
19452 \begin_layout Itemize
19453
19454 \series bold
19455 save
19456 \series default
19457
19458 \begin_inset LatexCommand \index{\#pragma save}
19459
19460 \end_inset
19461
19462  - this will save most current options to the save/restore stack.
19463  See #pragma\InsetSpace ~
19464 restore.
19465 \end_layout
19466
19467 \begin_layout Itemize
19468
19469 \series bold
19470 restore
19471 \series default
19472
19473 \begin_inset LatexCommand \index{\#pragma restore}
19474
19475 \end_inset
19476
19477  - will restore saved options from the last save.
19478  saves & restores can be nested.
19479  SDCC uses a save/restore stack: save pushes current options to the stack,
19480  restore pulls current options from the stack.
19481  See #pragma\InsetSpace ~
19482 save.
19483 \newline
19484
19485 \end_layout
19486
19487 \begin_layout Itemize
19488
19489 \series bold
19490 callee_saves
19491 \series default
19492
19493 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19494
19495 \end_inset
19496
19497
19498 \begin_inset LatexCommand \index{function prologue}
19499
19500 \end_inset
19501
19502  function1[,function2[,function3...]] - The compiler by default uses a caller
19503  saves convention for register saving across function calls, however this
19504  can cause unnecessary register pushing & popping
19505 \begin_inset LatexCommand \index{push/pop}
19506
19507 \end_inset
19508
19509  when calling small functions from larger functions.
19510  This option can be used to switch off the register saving convention for
19511  the function names specified.
19512  The compiler will not save registers when calling these functions, extra
19513  code need to be manually inserted at the entry & exit for these functions
19514  to save & restore the registers used by these functions, this can SUBSTANTIALLY
19515  reduce code & improve run time performance of the generated code.
19516  In the future the compiler (with inter procedural analysis) may be able
19517  to determine the appropriate scheme to use for each function call.
19518  If -
19519 \begin_inset ERT
19520 status collapsed
19521
19522 \begin_layout Standard
19523
19524
19525 \backslash
19526 /
19527 \end_layout
19528
19529 \end_inset
19530
19531 -callee-saves command line option is used, the function names specified
19532  in #pragma\InsetSpace ~
19533 callee_saves
19534 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19535
19536 \end_inset
19537
19538  is appended to the list of functions specified in the command line.
19539 \end_layout
19540
19541 \begin_layout Itemize
19542
19543 \series bold
19544 exclude
19545 \series default
19546
19547 \begin_inset LatexCommand \index{\#pragma exclude}
19548
19549 \end_inset
19550
19551  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
19552  of pairs of push/pop
19553 \begin_inset LatexCommand \index{push/pop}
19554
19555 \end_inset
19556
19557  instructions in 
19558 \emph on
19559 I
19560 \emph default
19561 nterrupt
19562 \begin_inset LatexCommand \index{interrupt}
19563
19564 \end_inset
19565
19566  
19567 \emph on
19568 S
19569 \emph default
19570 ervice 
19571 \emph on
19572 R
19573 \emph default
19574 outines.
19575  The directive should be placed immediately before the ISR function definition
19576  and it affects ALL ISR functions following it.
19577  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
19578 exclude\InsetSpace ~
19579 none
19580 \begin_inset LatexCommand \index{\#pragma exclude}
19581
19582 \end_inset
19583
19584 .
19585  See also the related keyword _naked
19586 \begin_inset LatexCommand \index{\_naked}
19587
19588 \end_inset
19589
19590
19591 \begin_inset LatexCommand \index{\_\_naked}
19592
19593 \end_inset
19594
19595 .
19596 \end_layout
19597
19598 \begin_layout Itemize
19599
19600 \series bold
19601 less_pedantic
19602 \series default
19603
19604 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
19605
19606 \end_inset
19607
19608  - the compiler will not warn you anymore for obvious mistakes, you'r on
19609  your own now ;-(
19610 \end_layout
19611
19612 \begin_layout Itemize
19613
19614 \series bold
19615 disable_warning
19616 \series default
19617  <nnnn>
19618 \begin_inset LatexCommand \index{\#pragma disable\_warning}
19619
19620 \end_inset
19621
19622  - the compiler will not warn you anymore about warning number <nnnn>.
19623 \end_layout
19624
19625 \begin_layout Itemize
19626
19627 \series bold
19628 nogcse
19629 \series default
19630
19631 \begin_inset LatexCommand \index{\#pragma nogcse}
19632
19633 \end_inset
19634
19635  - will stop global common subexpression elimination.
19636 \end_layout
19637
19638 \begin_layout Itemize
19639
19640 \series bold
19641 noinduction
19642 \series default
19643
19644 \begin_inset LatexCommand \index{\#pragma noinduction}
19645
19646 \end_inset
19647
19648  - will stop loop induction optimizations.
19649 \end_layout
19650
19651 \begin_layout Itemize
19652
19653 \series bold
19654 noinvariant
19655 \series default
19656
19657 \begin_inset LatexCommand \index{\#pragma noinvariant}
19658
19659 \end_inset
19660
19661  - will not do loop invariant optimizations.
19662  For more details see Loop Invariants in section
19663 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
19664
19665 \end_inset
19666
19667 .
19668 \end_layout
19669
19670 \begin_layout Itemize
19671
19672 \series bold
19673 noiv
19674 \series default
19675
19676 \begin_inset LatexCommand \index{\#pragma noiv}
19677
19678 \end_inset
19679
19680  - Do not generate interrupt
19681 \begin_inset LatexCommand \index{interrupt}
19682
19683 \end_inset
19684
19685  vector table
19686 \begin_inset LatexCommand \index{interrupt vector table}
19687
19688 \end_inset
19689
19690  entries for all ISR functions defined after the pragma.
19691  This is useful in cases where the interrupt vector table must be defined
19692  manually, or when there is a secondary, manually defined interrupt vector
19693  table (e.g.
19694  for the autovector feature of the Cypress EZ-USB FX2).
19695  More elegantly this can be achieved by obmitting the optional interrupt
19696  number after the interrupt keyword, see section 
19697 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
19698
19699 \end_inset
19700
19701 \InsetSpace ~
19702 about interrupts.
19703 \end_layout
19704
19705 \begin_layout Itemize
19706
19707 \series bold
19708 nojtbound
19709 \series default
19710
19711 \begin_inset LatexCommand \index{\#pragma nojtbound}
19712
19713 \end_inset
19714
19715  - will not generate code for boundary value checking, when switch statements
19716  are turned into jump-tables (dangerous).
19717  For more details see section 
19718 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
19719
19720 \end_inset
19721
19722 .
19723 \end_layout
19724
19725 \begin_layout Itemize
19726
19727 \series bold
19728 noloopreverse
19729 \series default
19730
19731 \begin_inset LatexCommand \index{\#pragma noloopreverse}
19732
19733 \end_inset
19734
19735  - Will not do loop reversal optimization
19736 \end_layout
19737
19738 \begin_layout Itemize
19739
19740 \series bold
19741 nooverlay
19742 \series default
19743
19744 \begin_inset LatexCommand \index{\#pragma nooverlay}
19745
19746 \end_inset
19747
19748  - the compiler will not overlay the parameters and local variables of a
19749  function.
19750 \end_layout
19751
19752 \begin_layout Itemize
19753
19754 \series bold
19755 stackauto
19756 \series default
19757
19758 \begin_inset LatexCommand \index{\#pragma stackauto}
19759
19760 \end_inset
19761
19762 - See option -
19763 \begin_inset ERT
19764 status collapsed
19765
19766 \begin_layout Standard
19767
19768
19769 \backslash
19770 /
19771 \end_layout
19772
19773 \end_inset
19774
19775 -stack-auto
19776 \begin_inset LatexCommand \index{-\/-stack-auto}
19777
19778 \end_inset
19779
19780  and section 
19781 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
19782
19783 \end_inset
19784
19785  Parameters and Local Variables.
19786 \end_layout
19787
19788 \begin_layout Itemize
19789
19790 \series bold
19791 opt_code_speed
19792 \series default
19793  
19794 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
19795
19796 \end_inset
19797
19798 - The compiler will optimize code generation towards fast code, possibly
19799  at the expense of code size.
19800  Currently this has little effect.
19801 \end_layout
19802
19803 \begin_layout Itemize
19804
19805 \series bold
19806 opt_code_size
19807 \series default
19808  
19809 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
19810
19811 \end_inset
19812
19813 - The compiler will optimize code generation towards compact code, possibly
19814  at the expense of code speed.
19815  Currently this has little effect.
19816 \end_layout
19817
19818 \begin_layout Itemize
19819
19820 \series bold
19821 opt_code_balanced
19822 \series default
19823  
19824 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
19825
19826 \end_inset
19827
19828 - The compiler will attempt to generate code that is both compact and fast,
19829  as long as meeting one goal is not a detriment to the other (this is the
19830  default).
19831  
19832 \end_layout
19833
19834 \begin_layout Itemize
19835
19836 \series bold
19837 std_sdcc89
19838 \series default
19839  
19840 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
19841
19842 \end_inset
19843
19844 - Generally follow the C89 standard, but allow SDCC features that conflict
19845  with the standard (default).
19846 \end_layout
19847
19848 \begin_layout Itemize
19849
19850 \series bold
19851 std_c89
19852 \series default
19853  
19854 \begin_inset LatexCommand \index{\#pragma std\_c89}
19855
19856 \end_inset
19857
19858 - Follow the C89 standard and disable SDCC features that conflict with the
19859  standard.
19860 \end_layout
19861
19862 \begin_layout Itemize
19863
19864 \series bold
19865 std_sdcc99
19866 \series default
19867  
19868 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
19869
19870 \end_inset
19871
19872 - Generally follow the C99 standard, but allow SDCC features that conflict
19873  with the standard (incomplete support).
19874 \end_layout
19875
19876 \begin_layout Itemize
19877
19878 \series bold
19879 std_c99
19880 \series default
19881  
19882 \begin_inset LatexCommand \index{\#pragma std\_c99}
19883
19884 \end_inset
19885
19886 - Follow the C99 standard and disable SDCC features that conflict with the
19887  standard (incomplete support).
19888 \end_layout
19889
19890 \begin_layout Itemize
19891
19892 \series bold
19893 codeseg
19894 \series default
19895  <name>
19896 \begin_inset LatexCommand \index{\#pragma codeseg}
19897
19898 \end_inset
19899
19900 - Use this name (max.
19901  8 characters) for the code segment.
19902  See option -
19903 \begin_inset ERT
19904 status collapsed
19905
19906 \begin_layout Standard
19907
19908
19909 \backslash
19910 /
19911 \end_layout
19912
19913 \end_inset
19914
19915 -codeseg.
19916 \end_layout
19917
19918 \begin_layout Itemize
19919
19920 \series bold
19921 constseg
19922 \series default
19923  <name>
19924 \begin_inset LatexCommand \index{\#pragma constseg}
19925
19926 \end_inset
19927
19928 - Use this name (max.
19929  8 characters) for the const segment.
19930  See option -
19931 \begin_inset ERT
19932 status collapsed
19933
19934 \begin_layout Standard
19935
19936
19937 \backslash
19938 /
19939 \end_layout
19940
19941 \end_inset
19942
19943 -constseg.
19944 \end_layout
19945
19946 \begin_layout Standard
19947 The preprocessor SDCPP
19948 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
19949
19950 \end_inset
19951
19952  supports the following #pragma directives:
19953 \end_layout
19954
19955 \begin_layout Itemize
19956
19957 \series bold
19958 pedantic_parse_number
19959 \series default
19960
19961 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19962
19963 \end_inset
19964
19965  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
19966  parsed properly and the macro LO_B(3) gets expanded.
19967  Default is off.
19968  Below is an example on how to use this pragma.
19969
19970 \emph on
19971  Note: this functionality is not in conformance with standard!
19972 \end_layout
19973
19974 \begin_layout Verse
19975
19976 \family typewriter
19977 #pragma pedantic_parse_number +
19978 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19979
19980 \end_inset
19981
19982
19983 \newline
19984
19985 \newline
19986 #define LO_B(x) ((x) & 0xff)
19987 \newline
19988
19989 \newline
19990 unsigned char foo(void)
19991 \newline
19992 {
19993 \newline
19994 \InsetSpace ~
19995 \InsetSpace ~
19996 \InsetSpace ~
19997 unsigned char c=0xfe-LO_B(3)
19998 ;
19999 \newline
20000
20001 \newline
20002 \InsetSpace ~
20003 \InsetSpace ~
20004 \InsetSpace ~
20005 return c;
20006 \newline
20007 }
20008 \newline
20009
20010 \end_layout
20011
20012 \begin_layout Itemize
20013
20014 \series bold
20015 preproc_asm
20016 \series default
20017
20018 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20019
20020 \end_inset
20021
20022  (+ | -) - switch _asm _endasm block preprocessing on / off.
20023  Default is on.
20024  You use this prama to define multilines of assembly code.
20025  This will prevent the preprocessor from changing the formating required
20026  by assembly code.
20027  Below is an example on how to use this pragma.
20028 \end_layout
20029
20030 \begin_layout Verse
20031
20032 \family typewriter
20033 #pragma preproc_asm -
20034 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20035
20036 \end_inset
20037
20038
20039 \newline
20040 #define MYDELAY _asm
20041 \newline
20042 \InsetSpace ~
20043 \InsetSpace ~
20044 \InsetSpace ~
20045 nop ;my assembly comment...
20046 \newline
20047 \InsetSpace ~
20048 \InsetSpace ~
20049 \InsetSpace ~
20050 nop
20051 \newline
20052 \InsetSpace ~
20053 \InsetSpace ~
20054 \InsetSpace ~
20055 nop
20056 \newline
20057 _endasm
20058 \newline
20059 #pragma preproc_asm
20060  +
20061 \newline
20062
20063 \newline
20064 void foo (void) 
20065 \newline
20066
20067 \newline
20068 \InsetSpace ~
20069 \InsetSpace ~
20070 \InsetSpace ~
20071  ...
20072  
20073 \newline
20074 \InsetSpace ~
20075 \InsetSpace ~
20076 \InsetSpace ~
20077  MYDELAY;
20078 \newline
20079 \InsetSpace ~
20080 \InsetSpace ~
20081 \InsetSpace ~
20082  ...
20083  
20084 \newline
20085
20086 \newline
20087
20088 \end_layout
20089
20090 \begin_layout Itemize
20091
20092 \series bold
20093 sdcc_hash
20094 \series default
20095
20096 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
20097
20098 \end_inset
20099
20100  (+ | -) - Allow "naked" hash in macro definition, for example:
20101 \newline
20102
20103 \family typewriter
20104 #define DIR_LO(x) #(x & 0xff)
20105 \family default
20106
20107 \newline
20108 Default is off.
20109  Below is an example on how to use this pragma.
20110 \end_layout
20111
20112 \begin_layout Verse
20113
20114 \family typewriter
20115 #pragma preproc_asm +
20116 \newline
20117 #pragma sdcc_hash +
20118 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
20119
20120 \end_inset
20121
20122
20123 \newline
20124
20125 \newline
20126 #define ROMCALL(x) 
20127 \backslash
20128
20129 \newline
20130 \InsetSpace ~
20131 \InsetSpace ~
20132 \InsetSpace ~
20133 mov R6_B3, #(x & 0xff) 
20134 \backslash
20135
20136 \newline
20137 \InsetSpace ~
20138 \InsetSpace ~
20139 \InsetSpace ~
20140 mov R7_B3, #((x >> 8) & 0xff) 
20141 \backslash
20142
20143 \newline
20144 \InsetSpace ~
20145 \InsetSpace ~
20146 \InsetSpace ~
20147 lcall __romcall
20148 \newline
20149
20150 \newline
20151 ...
20152 \newline
20153 _asm
20154 \newline
20155 ROMCALL(72)
20156 \newline
20157 _endasm;
20158 \newline
20159 ...
20160 \newline
20161
20162 \end_layout
20163
20164 \begin_layout Standard
20165 The pragma's are intended to be used to turn-on or off certain optimizations
20166  which might cause the compiler to generate extra stack / data space to
20167  store compiler generated temporary variables.
20168  This usually happens in large functions.
20169  Pragma directives should be used as shown in the following example, they
20170  are used to control options & optimizations for a given function; pragmas
20171  should be placed before and/or after a function, placing pragma's inside
20172  a function body could have unpredictable results.
20173 \end_layout
20174
20175 \begin_layout Verse
20176
20177 \family typewriter
20178 #pragma save
20179 \begin_inset LatexCommand \index{\#pragma save}
20180
20181 \end_inset
20182
20183  \InsetSpace ~
20184 \InsetSpace ~
20185 \InsetSpace ~
20186 \InsetSpace ~
20187 \InsetSpace ~
20188 \InsetSpace ~
20189 \InsetSpace ~
20190 /* save the current settings */ 
20191 \newline
20192 #pragma nogcse
20193 \begin_inset LatexCommand \index{\#pragma nogcse}
20194
20195 \end_inset
20196
20197  \InsetSpace ~
20198 \InsetSpace ~
20199 \InsetSpace ~
20200 \InsetSpace ~
20201 \InsetSpace ~
20202 /* turnoff global subexpression elimination */ 
20203 \newline
20204 #pragma noinduction
20205 \begin_inset LatexCommand \index{\#pragma noinduction}
20206
20207 \end_inset
20208
20209  /* turn off induction optimizations */ 
20210 \newline
20211 int foo () 
20212 \newline
20213
20214 \newline
20215 \InsetSpace ~
20216  \InsetSpace ~
20217  ...
20218  
20219 \newline
20220 \InsetSpace ~
20221  \InsetSpace ~
20222  /* large code */ 
20223 \newline
20224 \InsetSpace ~
20225  \InsetSpace ~
20226  ...
20227  
20228 \newline
20229
20230 \newline
20231 #pragma restore
20232 \begin_inset LatexCommand \index{\#pragma restore}
20233
20234 \end_inset
20235
20236  /* turn the optimizations back on */
20237 \end_layout
20238
20239 \begin_layout Standard
20240 The compiler will generate a warning message when extra space is allocated.
20241  It is strongly recommended that the save and restore pragma's be used when
20242  changing options for a function.
20243 \newline
20244
20245 \newline
20246
20247 \newline
20248
20249 \end_layout
20250
20251 \begin_layout Section
20252 Defines Created by the Compiler
20253 \end_layout
20254
20255 \begin_layout Standard
20256 The compiler creates the following #defines
20257 \begin_inset LatexCommand \index{\#defines}
20258
20259 \end_inset
20260
20261
20262 \begin_inset LatexCommand \index{Defines created by the compiler}
20263
20264 \end_inset
20265
20266 :
20267 \newline
20268
20269 \end_layout
20270
20271 \begin_layout Standard
20272 \begin_inset Tabular
20273 <lyxtabular version="3" rows="11" columns="2">
20274 <features>
20275 <column alignment="left" valignment="top" leftline="true" width="3in">
20276 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
20277 <row topline="true" bottomline="true">
20278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20279 \begin_inset Text
20280
20281 \begin_layout Standard
20282
20283 \series bold
20284 #define
20285 \end_layout
20286
20287 \end_inset
20288 </cell>
20289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20290 \begin_inset Text
20291
20292 \begin_layout Standard
20293
20294 \series bold
20295 Description
20296 \end_layout
20297
20298 \end_inset
20299 </cell>
20300 </row>
20301 <row topline="true">
20302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20303 \begin_inset Text
20304
20305 \begin_layout Standard
20306 SDCC
20307 \begin_inset LatexCommand \index{SDCC}
20308
20309 \end_inset
20310
20311  
20312 \end_layout
20313
20314 \end_inset
20315 </cell>
20316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20317 \begin_inset Text
20318
20319 \begin_layout Standard
20320 Always defined.
20321  Since version 2.5.6 the version number as an int (ex.
20322  256)
20323 \end_layout
20324
20325 \end_inset
20326 </cell>
20327 </row>
20328 <row topline="true">
20329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20330 \begin_inset Text
20331
20332 \begin_layout Standard
20333 SDCC_mcs51
20334 \begin_inset LatexCommand \index{SDCC\_mcs51}
20335
20336 \end_inset
20337
20338  or SDCC_ds390
20339 \begin_inset LatexCommand \index{SDCC\_ds390}
20340
20341 \end_inset
20342
20343  or SDCC_z80
20344 \begin_inset LatexCommand \index{SDCC\_z80}
20345
20346 \end_inset
20347
20348 , etc.
20349 \end_layout
20350
20351 \end_inset
20352 </cell>
20353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20354 \begin_inset Text
20355
20356 \begin_layout Standard
20357 depending on the model used (e.g.: -mds390)
20358 \end_layout
20359
20360 \end_inset
20361 </cell>
20362 </row>
20363 <row topline="true">
20364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20365 \begin_inset Text
20366
20367 \begin_layout Standard
20368 __mcs51
20369 \begin_inset LatexCommand \index{\_\_mcs51}
20370
20371 \end_inset
20372
20373 , __ds390
20374 \begin_inset LatexCommand \index{\_\_ds390}
20375
20376 \end_inset
20377
20378 , __hc08
20379 \begin_inset LatexCommand \index{\_\_hc08}
20380
20381 \end_inset
20382
20383 , __z80
20384 \begin_inset LatexCommand \index{\_\_z80}
20385
20386 \end_inset
20387
20388 , etc
20389 \end_layout
20390
20391 \end_inset
20392 </cell>
20393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20394 \begin_inset Text
20395
20396 \begin_layout Standard
20397 depending on the model used (e.g.
20398  -mz80)
20399 \end_layout
20400
20401 \end_inset
20402 </cell>
20403 </row>
20404 <row topline="true">
20405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20406 \begin_inset Text
20407
20408 \begin_layout Standard
20409 SDCC_STACK_AUTO
20410 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
20411
20412 \end_inset
20413
20414
20415 \end_layout
20416
20417 \end_inset
20418 </cell>
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20420 \begin_inset Text
20421
20422 \begin_layout Standard
20423 when 
20424 \emph on
20425 -
20426 \begin_inset ERT
20427 status collapsed
20428
20429 \begin_layout Standard
20430
20431
20432 \backslash
20433 /
20434 \end_layout
20435
20436 \end_inset
20437
20438 -stack-auto
20439 \emph default
20440  option is used
20441 \end_layout
20442
20443 \end_inset
20444 </cell>
20445 </row>
20446 <row topline="true">
20447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20448 \begin_inset Text
20449
20450 \begin_layout Standard
20451 SDCC_MODEL_SMALL
20452 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
20453
20454 \end_inset
20455
20456
20457 \end_layout
20458
20459 \end_inset
20460 </cell>
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20462 \begin_inset Text
20463
20464 \begin_layout Standard
20465 when 
20466 \emph on
20467 -
20468 \begin_inset ERT
20469 status collapsed
20470
20471 \begin_layout Standard
20472
20473
20474 \backslash
20475 /
20476 \end_layout
20477
20478 \end_inset
20479
20480 -model-small
20481 \emph default
20482  is used
20483 \end_layout
20484
20485 \end_inset
20486 </cell>
20487 </row>
20488 <row topline="true">
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20490 \begin_inset Text
20491
20492 \begin_layout Standard
20493 SDCC_MODEL_MEDIUM
20494 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
20495
20496 \end_inset
20497
20498
20499 \end_layout
20500
20501 \end_inset
20502 </cell>
20503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20504 \begin_inset Text
20505
20506 \begin_layout Standard
20507 when 
20508 \emph on
20509 -
20510 \begin_inset ERT
20511 status collapsed
20512
20513 \begin_layout Standard
20514
20515
20516 \backslash
20517 /
20518 \end_layout
20519
20520 \end_inset
20521
20522 -model-medium
20523 \emph default
20524  is used
20525 \end_layout
20526
20527 \end_inset
20528 </cell>
20529 </row>
20530 <row topline="true">
20531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20532 \begin_inset Text
20533
20534 \begin_layout Standard
20535 SDCC_MODEL_LARGE
20536 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
20537
20538 \end_inset
20539
20540
20541 \end_layout
20542
20543 \end_inset
20544 </cell>
20545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20546 \begin_inset Text
20547
20548 \begin_layout Standard
20549 when 
20550 \emph on
20551 -
20552 \begin_inset ERT
20553 status collapsed
20554
20555 \begin_layout Standard
20556
20557
20558 \backslash
20559 /
20560 \end_layout
20561
20562 \end_inset
20563
20564 -model-large
20565 \emph default
20566  is used
20567 \end_layout
20568
20569 \end_inset
20570 </cell>
20571 </row>
20572 <row topline="true">
20573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20574 \begin_inset Text
20575
20576 \begin_layout Standard
20577 SDCC_USE_XSTACK
20578 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
20579
20580 \end_inset
20581
20582
20583 \end_layout
20584
20585 \end_inset
20586 </cell>
20587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20588 \begin_inset Text
20589
20590 \begin_layout Standard
20591 when 
20592 \emph on
20593 -
20594 \begin_inset ERT
20595 status collapsed
20596
20597 \begin_layout Standard
20598
20599
20600 \backslash
20601 /
20602 \end_layout
20603
20604 \end_inset
20605
20606 -xstack
20607 \emph default
20608  option is used
20609 \end_layout
20610
20611 \end_inset
20612 </cell>
20613 </row>
20614 <row topline="true">
20615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20616 \begin_inset Text
20617
20618 \begin_layout Standard
20619 SDCC_STACK_TENBIT
20620 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
20621
20622 \end_inset
20623
20624  
20625 \end_layout
20626
20627 \end_inset
20628 </cell>
20629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20630 \begin_inset Text
20631
20632 \begin_layout Standard
20633 when 
20634 \emph on
20635 -mds390
20636 \emph default
20637  is used
20638 \end_layout
20639
20640 \end_inset
20641 </cell>
20642 </row>
20643 <row topline="true" bottomline="true">
20644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20645 \begin_inset Text
20646
20647 \begin_layout Standard
20648 SDCC_MODEL_FLAT24
20649 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
20650
20651 \end_inset
20652
20653
20654 \end_layout
20655
20656 \end_inset
20657 </cell>
20658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20659 \begin_inset Text
20660
20661 \begin_layout Standard
20662 when 
20663 \emph on
20664 -mds390
20665 \emph default
20666  is used
20667 \end_layout
20668
20669 \end_inset
20670 </cell>
20671 </row>
20672 </lyxtabular>
20673
20674 \end_inset
20675
20676
20677 \end_layout
20678
20679 \begin_layout Chapter
20680 Notes on supported Processors
20681 \end_layout
20682
20683 \begin_layout Section
20684 MCS51 variants
20685 \begin_inset LatexCommand \label{sub:MCS51-variants}
20686
20687 \end_inset
20688
20689
20690 \begin_inset LatexCommand \index{MCS51 variants}
20691
20692 \end_inset
20693
20694
20695 \end_layout
20696
20697 \begin_layout Standard
20698 MCS51 processors are available from many vendors and come in many different
20699  flavours.
20700  While they might differ considerably in respect to Special Function Registers
20701  the core MCS51 is usually not modified or is kept compatible.
20702  
20703 \end_layout
20704
20705 \begin_layout Subsection
20706 pdata access by SFR 
20707 \end_layout
20708
20709 \begin_layout Standard
20710 With the upcome of devices with internal xdata and flash memory devices
20711  using port P2
20712 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20713
20714 \end_inset
20715
20716  as dedicated I/O port is becoming more popular.
20717  Switching the high byte for pdata
20718 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20719
20720 \end_inset
20721
20722  access which was formerly done by port P2 is then achieved by a Special
20723  Function Register
20724 \begin_inset LatexCommand \index{sfr}
20725
20726 \end_inset
20727
20728 .
20729  In well-established MCS51 tradition the address of this 
20730 \emph on
20731 sfr
20732 \emph default
20733  is where the chip designers decided to put it.
20734  Needless to say that they didn't agree on a common name either.
20735  So that the startup code can correctly initialize xdata variables, you
20736  should define an sfr with the name _XPAGE
20737 \family typewriter
20738
20739 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
20740
20741 \end_inset
20742
20743
20744 \family default
20745  at the appropriate location if the default, port P2, is not used for this.
20746  Some examples are:
20747 \end_layout
20748
20749 \begin_layout Verse
20750
20751 \family typewriter
20752 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
20753 \end_layout
20754
20755 \begin_layout Verse
20756
20757 \family typewriter
20758 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
20759 \end_layout
20760
20761 \begin_layout Verse
20762
20763 \family typewriter
20764 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
20765 \end_layout
20766
20767 \begin_layout Standard
20768 For more exotic implementations further customizations may be needed.
20769  See section 
20770 \begin_inset LatexCommand \ref{sub:Startup-Code}
20771
20772 \end_inset
20773
20774  for other possibilities.
20775 \end_layout
20776
20777 \begin_layout Subsection
20778 Other Features available by SFR
20779 \end_layout
20780
20781 \begin_layout Standard
20782 Some MCS51 variants offer features like Double DPTR
20783 \begin_inset LatexCommand \index{DPTR}
20784
20785 \end_inset
20786
20787 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
20788  These are currently not used for the MCS51 port.
20789  If you absolutely need them you can fall back to inline assembly or submit
20790  a patch to SDCC.
20791 \begin_inset VSpace bigskip
20792 \end_inset
20793
20794
20795 \end_layout
20796
20797 \begin_layout Section
20798 DS400 port
20799 \end_layout
20800
20801 \begin_layout Standard
20802 The DS80C400
20803 \begin_inset LatexCommand \index{DS80C400}
20804
20805 \end_inset
20806
20807
20808 \begin_inset LatexCommand \index{DS400}
20809
20810 \end_inset
20811
20812  microcontroller has a rich set of peripherals.
20813  In its built-in ROM library it includes functions to access some of the
20814  features, among them is a TCP stack with IP4 and IP6 support.
20815  Library headers (currently in beta status) and other files are provided
20816  at 
20817 \size footnotesize
20818
20819 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
20820
20821 \end_inset
20822
20823 .
20824  
20825 \begin_inset VSpace bigskip
20826 \end_inset
20827
20828
20829 \end_layout
20830
20831 \begin_layout Section
20832 The Z80 and gbz80 port
20833 \end_layout
20834
20835 \begin_layout Standard
20836 SDCC can target both the Zilog Z80
20837 \begin_inset LatexCommand \index{Z80}
20838
20839 \end_inset
20840
20841  and the Nintendo Gameboy's Z80-like gbz80
20842 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
20843
20844 \end_inset
20845
20846 .
20847  The Z80 port is passed through the same 
20848 \emph on
20849 regressions tests
20850 \begin_inset LatexCommand \index{Regression test}
20851
20852 \end_inset
20853
20854
20855 \emph default
20856  (see section 
20857 \begin_inset LatexCommand \ref{sec:Quality-control}
20858
20859 \end_inset
20860
20861 ) as the MCS51 and DS390 ports, so floating point support, support for long
20862  variables and bitfield support is fine.
20863  See mailing lists and forums about interrupt routines.
20864 \end_layout
20865
20866 \begin_layout Standard
20867 As always, the code is the authoritative reference - see z80/ralloc.c and
20868  z80/gen.c.
20869  The stack
20870 \begin_inset LatexCommand \index{Z80!stack}
20871
20872 \end_inset
20873
20874  frame is similar to that generated by the IAR Z80 compiler.
20875  IX is used as the base pointer, HL and IY are used as a temporary registers,
20876  and BC and DE are available for holding variables.
20877  Return values
20878 \begin_inset LatexCommand \index{Z80!return value}
20879
20880 \end_inset
20881
20882  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
20883  bytes).
20884  The gbz80 port use the same set of registers for the return values, but
20885  in a different order of significance: E (one byte), DE (two bytes), or
20886  HLDE (four bytes).
20887 \begin_inset VSpace bigskip
20888 \end_inset
20889
20890
20891 \end_layout
20892
20893 \begin_layout Section
20894 The HC08 port
20895 \end_layout
20896
20897 \begin_layout Standard
20898 The port to the Freescale/Motorola HC08
20899 \begin_inset LatexCommand \index{HC08}
20900
20901 \end_inset
20902
20903  family has been added in October 2003, and is still undergoing some basic
20904  development.
20905  The code generator is complete, but the register allocation is still quite
20906  unoptimized.
20907  Some of the SDCC's standard C library functions have embedded non-HC08
20908  inline assembly and so are not yet usable.
20909 \end_layout
20910
20911 \begin_layout Standard
20912 The HC08 port passes the regression test suite (see section 
20913 \begin_inset LatexCommand \ref{sec:Quality-control}
20914
20915 \end_inset
20916
20917 ).
20918 \begin_inset VSpace bigskip
20919 \end_inset
20920
20921
20922 \end_layout
20923
20924 \begin_layout Standard
20925
20926 \newpage
20927
20928 \end_layout
20929
20930 \begin_layout Section
20931 The PIC14 port
20932 \end_layout
20933
20934 \begin_layout Standard
20935 The 14bit PIC
20936 \begin_inset LatexCommand \index{PIC14}
20937
20938 \end_inset
20939
20940  port still requires a major effort from the development community.
20941  However it can work for simple code.
20942  It passes its (smaller set of) regression tests
20943 \begin_inset LatexCommand \index{Regression test (PIC14)}
20944
20945 \end_inset
20946
20947  in the directory 
20948 \shape italic
20949 sdcc/src/regression
20950 \shape default
20951 .
20952 \end_layout
20953
20954 \begin_layout Subsection
20955 C code and 14bit PIC code page
20956 \begin_inset LatexCommand \index{code page (pic14)}
20957
20958 \end_inset
20959
20960  and RAM banks
20961 \begin_inset LatexCommand \index{RAM bank (pic14)}
20962
20963 \end_inset
20964
20965
20966 \end_layout
20967
20968 \begin_layout Standard
20969 The linker organizes allocation for the code page and RAM banks.
20970  It does not have intimate knowledge of the code flow.
20971  It will put all the code section of a single asm file into a single code
20972  page.
20973  In order to make use of multiple code pages, separate asm files must be
20974  used.
20975  The compiler treats all functions of a single C file as being in the same
20976  code page unless it is non static.
20977 \newline
20978
20979 \newline
20980 To get the best follow these guide lines:
20981 \end_layout
20982
20983 \begin_layout Enumerate
20984 Make local functions static, as non static functions require code page selection
20985  overhead.
20986 \end_layout
20987
20988 \begin_layout Enumerate
20989 For devices that have multiple code pages it is more efficient to use the
20990  same number of files as pages, i.e.
20991  for the 16F877 use 4 separate files and i.e.
20992  for the 16F874 use 2 separate files.
20993  This way the linker can put the code for each file into different code
20994  pages and there's less page selection overhead.
20995 \end_layout
20996
20997 \begin_layout Enumerate
20998  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
20999  instruction set), use 'unsigned char' whereever possible instead of 'int'.
21000 \end_layout
21001
21002 \begin_layout Subsection
21003 Creating a device include file 
21004 \end_layout
21005
21006 \begin_layout Standard
21007 For generating a device include file
21008 \begin_inset LatexCommand \index{PIC14!Header files}
21009
21010 \end_inset
21011
21012  use the support perl script inc2h.pl kept in directory support/script.
21013 \end_layout
21014
21015 \begin_layout Subsection
21016 Interrupt code
21017 \end_layout
21018
21019 \begin_layout Standard
21020 For the interrupt function, use the keyword '__interrupt'
21021 \begin_inset LatexCommand \index{PIC14!interrupt}
21022
21023 \end_inset
21024
21025  with level number of 0 (PIC14 only has 1 interrupt so this number is only
21026  there to avoid a syntax error - it ought to be fixed).
21027  E.g.:
21028 \end_layout
21029
21030 \begin_layout Verse
21031
21032 \family typewriter
21033 void Intr(void) __interrupt 0
21034 \newline
21035 {
21036 \newline
21037 \InsetSpace ~
21038 \InsetSpace ~
21039 T0IF = 0; /* Clear timer interrupt */
21040 \newline
21041 }
21042 \end_layout
21043
21044 \begin_layout Subsection
21045 Linking and assembling
21046 \end_layout
21047
21048 \begin_layout Standard
21049 For assembling you can use either GPUTILS'
21050 \begin_inset LatexCommand \index{gputils (pic tools)}
21051
21052 \end_inset
21053
21054  gpasm.exe or MPLAB's mpasmwin.exe.
21055  GPUTILS is available from 
21056 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21057
21058 \end_inset
21059
21060 .
21061  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
21062  If you use MPLAB and an interrupt function then the linker script file
21063  vectors section will need to be enlarged to link with mplink.
21064 \newline
21065
21066 \newline
21067 Here is a 
21068 \family typewriter
21069 Makefile
21070 \family default
21071  using GPUTILS:
21072 \end_layout
21073
21074 \begin_layout Verse
21075
21076 \family typewriter
21077 .c.o:
21078 \newline
21079 \InsetSpace ~
21080 \InsetSpace ~
21081 \InsetSpace ~
21082 \InsetSpace ~
21083 \InsetSpace ~
21084 \InsetSpace ~
21085 \InsetSpace ~
21086 \InsetSpace ~
21087 sdcc -S -V -mpic14 -p16F877 $< 
21088 \newline
21089 \InsetSpace ~
21090 \InsetSpace ~
21091 \InsetSpace ~
21092 \InsetSpace ~
21093 \InsetSpace ~
21094 \InsetSpace ~
21095 \InsetSpace ~
21096 \InsetSpace ~
21097 gpasm -c $*.asm
21098 \newline
21099
21100 \newline
21101 $(PRJ).hex: $(OBJS) 
21102 \newline
21103 \InsetSpace ~
21104 \InsetSpace ~
21105 \InsetSpace ~
21106 \InsetSpace ~
21107 \InsetSpace ~
21108 \InsetSpace ~
21109 \InsetSpace ~
21110 \InsetSpace ~
21111 gplink
21112  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
21113 \end_layout
21114
21115 \begin_layout Standard
21116 Here is a 
21117 \family typewriter
21118 Makefile
21119 \family default
21120  using MPLAB:
21121 \end_layout
21122
21123 \begin_layout Verse
21124
21125 \family typewriter
21126 .c.o: 
21127 \newline
21128 \InsetSpace ~
21129 \InsetSpace ~
21130 \InsetSpace ~
21131 \InsetSpace ~
21132 \InsetSpace ~
21133 \InsetSpace ~
21134 \InsetSpace ~
21135 \InsetSpace ~
21136 sdcc -S -V -mpic14 -p16F877 $< 
21137 \newline
21138 \InsetSpace ~
21139 \InsetSpace ~
21140 \InsetSpace ~
21141 \InsetSpace ~
21142 \InsetSpace ~
21143 \InsetSpace ~
21144 \InsetSpace ~
21145 \InsetSpace ~
21146 mpasmwin /q /o $*.asm
21147 \newline
21148
21149 \newline
21150 $(PRJ).hex: $(OBJS)
21151  
21152 \newline
21153 \InsetSpace ~
21154 \InsetSpace ~
21155 \InsetSpace ~
21156 \InsetSpace ~
21157 \InsetSpace ~
21158 \InsetSpace ~
21159 \InsetSpace ~
21160 \InsetSpace ~
21161 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
21162 \end_layout
21163
21164 \begin_layout Standard
21165 Please note that indentations within a
21166 \family typewriter
21167  Makefile
21168 \family default
21169  have to be done with a tabulator character.
21170 \end_layout
21171
21172 \begin_layout Subsection
21173 Command-line options
21174 \end_layout
21175
21176 \begin_layout Standard
21177 Besides the switches common to all SDCC backends, the PIC14 port accepts
21178  the following options (for an updated list see sdcc -
21179 \begin_inset ERT
21180 status collapsed
21181
21182 \begin_layout Standard
21183
21184
21185 \backslash
21186 /
21187 \end_layout
21188
21189 \end_inset
21190
21191 -help):
21192 \end_layout
21193
21194 \begin_layout List
21195 \labelwidthstring 00.00.0000
21196 -
21197 \begin_inset ERT
21198 status collapsed
21199
21200 \begin_layout Standard
21201
21202
21203 \backslash
21204 /
21205 \end_layout
21206
21207 \end_inset
21208
21209 -debug-extra
21210 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
21211
21212 \end_inset
21213
21214  emit debug info in assembly output
21215 \end_layout
21216
21217 \begin_layout List
21218 \labelwidthstring 00.00.0000
21219 -
21220 \begin_inset ERT
21221 status collapsed
21222
21223 \begin_layout Standard
21224
21225
21226 \backslash
21227 /
21228 \end_layout
21229
21230 \end_inset
21231
21232 -no-pcode-opt
21233 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
21234
21235 \end_inset
21236
21237  disable (slightly faulty) optimization on pCode
21238 \end_layout
21239
21240 \begin_layout List
21241 \labelwidthstring 00.00.0000
21242 -
21243 \begin_inset ERT
21244 status collapsed
21245
21246 \begin_layout Standard
21247
21248
21249 \backslash
21250 /
21251 \end_layout
21252
21253 \end_inset
21254
21255 -stack-loc
21256 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
21257
21258 \end_inset
21259
21260  sets the lowest address of the argument passing stack (defaults to a suitably
21261  large shared databank to reduce BANKSEL overhead)
21262 \end_layout
21263
21264 \begin_layout List
21265 \labelwidthstring 00.00.0000
21266 -
21267 \begin_inset ERT
21268 status collapsed
21269
21270 \begin_layout Standard
21271
21272
21273 \backslash
21274 /
21275 \end_layout
21276
21277 \end_inset
21278
21279 -stack-size
21280 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
21281
21282 \end_inset
21283
21284  sets the size if the argument passing stack (default: 16, minimum: 4)
21285 \end_layout
21286
21287 \begin_layout Subsection
21288 The library
21289 \end_layout
21290
21291 \begin_layout Subsubsection
21292 error: missing definition for symbol 
21293 \begin_inset Quotes sld
21294 \end_inset
21295
21296 __gptrget1
21297 \begin_inset Quotes srd
21298 \end_inset
21299
21300
21301 \end_layout
21302
21303 \begin_layout Standard
21304 The PIC14 port uses library routines to provide more complex operations
21305  like multiplication, division/modulus and (generic) pointer dereferencing.
21306  In order to add these routines to your project, you must link with PIC14's
21307  
21308 \family typewriter
21309 libsdcc.lib
21310 \family default
21311 .
21312  For single source file projects this is done automatically, more complex
21313  projects must add 
21314 \family typewriter
21315 libsdcc.lib
21316 \family default
21317  to the linker's arguments.
21318  Make sure you also add an include path for the library (using the -I switch
21319  to the linker)!
21320 \end_layout
21321
21322 \begin_layout Subsubsection
21323 Processor mismatch in file 
21324 \begin_inset Quotes sld
21325 \end_inset
21326
21327 XXX
21328 \begin_inset Quotes srd
21329 \end_inset
21330
21331 .
21332 \end_layout
21333
21334 \begin_layout Standard
21335 This warning can usually be ignored due to the very good compatibility amongst
21336  14 bit PIC
21337 \begin_inset LatexCommand \index{PIC14}
21338
21339 \end_inset
21340
21341  devices.
21342 \end_layout
21343
21344 \begin_layout Standard
21345 You might also consider recompiling the library for your specific device
21346  by changing the ARCH=p16f877 (default target) entry in 
21347 \family typewriter
21348 device/lib/pic/Makefile.in
21349 \family default
21350  and 
21351 \family typewriter
21352 device/lib/pic/Makefile
21353 \family default
21354  to reflect your device.
21355  This might even improve performance for smaller devices as unneccesary
21356  BANKSELs migth be removed.
21357 \end_layout
21358
21359 \begin_layout Subsection
21360 Known bugs
21361 \end_layout
21362
21363 \begin_layout Subsubsection
21364 initialized data
21365 \end_layout
21366
21367 \begin_layout Standard
21368 Currently, data can only be initialized if it resides in the source file
21369  together with 
21370 \emph on
21371 main()
21372 \emph default
21373 .
21374  Data in other source files will silently 
21375 \series bold
21376 not
21377 \series default
21378  be initialized.
21379 \family typewriter
21380 \size footnotesize
21381
21382 \begin_inset Marginal
21383 status collapsed
21384
21385 \begin_layout Standard
21386
21387 \series bold
21388 \InsetSpace ~
21389 !
21390 \end_layout
21391
21392 \end_inset
21393
21394
21395 \end_layout
21396
21397 \begin_layout Standard
21398
21399 \newpage
21400
21401 \end_layout
21402
21403 \begin_layout Section
21404 The PIC16
21405 \begin_inset LatexCommand \index{PIC16}
21406
21407 \end_inset
21408
21409  port
21410 \end_layout
21411
21412 \begin_layout Standard
21413 The PIC16
21414 \begin_inset LatexCommand \index{PIC16}
21415
21416 \end_inset
21417
21418  port is the portion of SDCC that is responsible to produce code for the
21419  Microchip
21420 \begin_inset LatexCommand \index{Microchip}
21421
21422 \end_inset
21423
21424 (TM) microcontrollers with 16 bit core.
21425  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
21426  Currently supported devices are:
21427 \end_layout
21428
21429 \begin_layout Standard
21430 \align center
21431 \begin_inset Tabular
21432 <lyxtabular version="3" rows="4" columns="6">
21433 <features>
21434 <column alignment="center" valignment="top" leftline="true" width="0">
21435 <column alignment="center" valignment="top" leftline="true" width="0">
21436 <column alignment="center" valignment="top" leftline="true" width="0">
21437 <column alignment="center" valignment="top" leftline="true" width="0">
21438 <column alignment="center" valignment="top" leftline="true" width="0">
21439 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21440 <row topline="true">
21441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21442 \begin_inset Text
21443
21444 \begin_layout Standard
21445 18F242
21446 \end_layout
21447
21448 \end_inset
21449 </cell>
21450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21451 \begin_inset Text
21452
21453 \begin_layout Standard
21454 18F248
21455 \end_layout
21456
21457 \end_inset
21458 </cell>
21459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21460 \begin_inset Text
21461
21462 \begin_layout Standard
21463 18F252
21464 \end_layout
21465
21466 \end_inset
21467 </cell>
21468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21469 \begin_inset Text
21470
21471 \begin_layout Standard
21472 18F258
21473 \end_layout
21474
21475 \end_inset
21476 </cell>
21477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21478 \begin_inset Text
21479
21480 \begin_layout Standard
21481 18F442
21482 \end_layout
21483
21484 \end_inset
21485 </cell>
21486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21487 \begin_inset Text
21488
21489 \begin_layout Standard
21490 18F448
21491 \end_layout
21492
21493 \end_inset
21494 </cell>
21495 </row>
21496 <row topline="true">
21497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21498 \begin_inset Text
21499
21500 \begin_layout Standard
21501 18F452
21502 \end_layout
21503
21504 \end_inset
21505 </cell>
21506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21507 \begin_inset Text
21508
21509 \begin_layout Standard
21510 18F458
21511 \end_layout
21512
21513 \end_inset
21514 </cell>
21515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21516 \begin_inset Text
21517
21518 \begin_layout Standard
21519 18F1220
21520 \end_layout
21521
21522 \end_inset
21523 </cell>
21524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21525 \begin_inset Text
21526
21527 \begin_layout Standard
21528 18F2220
21529 \end_layout
21530
21531 \end_inset
21532 </cell>
21533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21534 \begin_inset Text
21535
21536 \begin_layout Standard
21537 18F2550
21538 \end_layout
21539
21540 \end_inset
21541 </cell>
21542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21543 \begin_inset Text
21544
21545 \begin_layout Standard
21546 18F4331
21547 \end_layout
21548
21549 \end_inset
21550 </cell>
21551 </row>
21552 <row topline="true">
21553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21554 \begin_inset Text
21555
21556 \begin_layout Standard
21557 18F4455
21558 \end_layout
21559
21560 \end_inset
21561 </cell>
21562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21563 \begin_inset Text
21564
21565 \begin_layout Standard
21566 18F6520
21567 \end_layout
21568
21569 \end_inset
21570 </cell>
21571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21572 \begin_inset Text
21573
21574 \begin_layout Standard
21575 18F6620
21576 \end_layout
21577
21578 \end_inset
21579 </cell>
21580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21581 \begin_inset Text
21582
21583 \begin_layout Standard
21584 18F6680
21585 \end_layout
21586
21587 \end_inset
21588 </cell>
21589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21590 \begin_inset Text
21591
21592 \begin_layout Standard
21593 18F6720
21594 \end_layout
21595
21596 \end_inset
21597 </cell>
21598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21599 \begin_inset Text
21600
21601 \begin_layout Standard
21602 18F8520
21603 \end_layout
21604
21605 \end_inset
21606 </cell>
21607 </row>
21608 <row topline="true" bottomline="true">
21609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21610 \begin_inset Text
21611
21612 \begin_layout Standard
21613 18F8620
21614 \end_layout
21615
21616 \end_inset
21617 </cell>
21618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21619 \begin_inset Text
21620
21621 \begin_layout Standard
21622 18F8680
21623 \end_layout
21624
21625 \end_inset
21626 </cell>
21627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21628 \begin_inset Text
21629
21630 \begin_layout Standard
21631 18F8720
21632 \end_layout
21633
21634 \end_inset
21635 </cell>
21636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21637 \begin_inset Text
21638
21639 \begin_layout Standard
21640
21641 \end_layout
21642
21643 \end_inset
21644 </cell>
21645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21646 \begin_inset Text
21647
21648 \begin_layout Standard
21649
21650 \end_layout
21651
21652 \end_inset
21653 </cell>
21654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21655 \begin_inset Text
21656
21657 \begin_layout Standard
21658
21659 \end_layout
21660
21661 \end_inset
21662 </cell>
21663 </row>
21664 </lyxtabular>
21665
21666 \end_inset
21667
21668
21669 \end_layout
21670
21671 \begin_layout Subsection
21672 Global Options
21673 \end_layout
21674
21675 \begin_layout Standard
21676 PIC16 port supports the standard command line arguments as supposed, with
21677  the exception of certain cases that will be mentioned in the following
21678  list:
21679 \end_layout
21680
21681 \begin_layout List
21682 \labelwidthstring 00.00.0000
21683 -
21684 \begin_inset ERT
21685 status collapsed
21686
21687 \begin_layout Standard
21688
21689
21690 \backslash
21691 /
21692 \end_layout
21693
21694 \end_inset
21695
21696 -callee-saves
21697 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
21698
21699 \end_inset
21700
21701  See -
21702 \begin_inset ERT
21703 status collapsed
21704
21705 \begin_layout Standard
21706
21707
21708 \backslash
21709 /
21710 \end_layout
21711
21712 \end_inset
21713
21714 -all-callee-saves
21715 \end_layout
21716
21717 \begin_layout List
21718 \labelwidthstring 00.00.0000
21719 -
21720 \begin_inset ERT
21721 status collapsed
21722
21723 \begin_layout Standard
21724
21725
21726 \backslash
21727 /
21728 \end_layout
21729
21730 \end_inset
21731
21732 -all-callee-saves
21733 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
21734
21735 \end_inset
21736
21737  All function arguments are passed on stack by default.
21738  
21739 \emph on
21740 There is no need to specify this in the command line.
21741 \end_layout
21742
21743 \begin_layout List
21744 \labelwidthstring 00.00.0000
21745 -
21746 \begin_inset ERT
21747 status collapsed
21748
21749 \begin_layout Standard
21750
21751
21752 \backslash
21753 /
21754 \end_layout
21755
21756 \end_inset
21757
21758 -fommit-frame-pointer
21759 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
21760
21761 \end_inset
21762
21763  Frame pointer will be omitted when the function uses no local variables.
21764 \end_layout
21765
21766 \begin_layout Subsection
21767 Port Specific Options
21768 \begin_inset LatexCommand \index{Options PIC16}
21769
21770 \end_inset
21771
21772
21773 \end_layout
21774
21775 \begin_layout Standard
21776 The port specific options appear after the global options in the sdcc --help
21777  output.
21778 \end_layout
21779
21780 \begin_layout Subsubsection
21781 General Options
21782 \end_layout
21783
21784 \begin_layout Standard
21785 General options enable certain port features and optimizations.
21786 \end_layout
21787
21788 \begin_layout List
21789 \labelwidthstring 00.00.0000
21790 -
21791 \begin_inset ERT
21792 status collapsed
21793
21794 \begin_layout Standard
21795
21796
21797 \backslash
21798 /
21799 \end_layout
21800
21801 \end_inset
21802
21803 -pstack-model=[model] Used in conjuction with the command above.
21804  Defines the stack model to be used, valid stack models are : 
21805 \end_layout
21806
21807 \begin_deeper
21808 \begin_layout List
21809 \labelwidthstring 00.00.0000
21810
21811 \emph on
21812 small
21813 \emph default
21814  Selects small stack model.
21815  8 bit stack and frame pointers.
21816  Supports 256 bytes stack size.
21817 \end_layout
21818
21819 \begin_layout List
21820 \labelwidthstring 00.00.0000
21821
21822 \emph on
21823 large
21824 \emph default
21825  Selects large stack model.
21826  16 bit stack and frame pointers.
21827  Supports 65536 bytes stack size.
21828 \end_layout
21829
21830 \end_deeper
21831 \begin_layout List
21832 \labelwidthstring 00.00.0000
21833 -
21834 \begin_inset ERT
21835 status collapsed
21836
21837 \begin_layout Standard
21838
21839
21840 \backslash
21841 /
21842 \end_layout
21843
21844 \end_inset
21845
21846 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
21847  unitialized data variables with [kword].
21848  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
21849 \end_layout
21850
21851 \begin_layout List
21852 \labelwidthstring 00.00.0000
21853 -
21854 \begin_inset ERT
21855 status collapsed
21856
21857 \begin_layout Standard
21858
21859
21860 \backslash
21861 /
21862 \end_layout
21863
21864 \end_inset
21865
21866 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
21867  Useful for bootloaders.
21868 \end_layout
21869
21870 \begin_layout List
21871 \labelwidthstring 00.00.0000
21872 -
21873 \begin_inset ERT
21874 status collapsed
21875
21876 \begin_layout Standard
21877
21878
21879 \backslash
21880 /
21881 \end_layout
21882
21883 \end_inset
21884
21885 -asm= sets the full path and name of an external assembler to call.
21886 \end_layout
21887
21888 \begin_layout List
21889 \labelwidthstring 00.00.0000
21890 -
21891 \begin_inset ERT
21892 status collapsed
21893
21894 \begin_layout Standard
21895
21896
21897 \backslash
21898 /
21899 \end_layout
21900
21901 \end_inset
21902
21903 -link= sets the full path and name of an external linker to call.
21904 \end_layout
21905
21906 \begin_layout List
21907 \labelwidthstring 00.00.0000
21908 -
21909 \begin_inset ERT
21910 status collapsed
21911
21912 \begin_layout Standard
21913
21914
21915 \backslash
21916 /
21917 \end_layout
21918
21919 \end_inset
21920
21921 -mplab-comp MPLAB
21922 \begin_inset LatexCommand \index{PIC16!MPLAB}
21923
21924 \end_inset
21925
21926  compatibility option.
21927  Currently only suppresses special gpasm directives.
21928 \end_layout
21929
21930 \begin_layout Subsubsection
21931 Optimization Options
21932 \end_layout
21933
21934 \begin_layout List
21935 \labelwidthstring 00.00.0000
21936 -
21937 \begin_inset ERT
21938 status collapsed
21939
21940 \begin_layout Standard
21941
21942
21943 \backslash
21944 /
21945 \end_layout
21946
21947 \end_inset
21948
21949 -optimize-goto Try to use (conditional) BRA instead of GOTO
21950 \end_layout
21951
21952 \begin_layout List
21953 \labelwidthstring 00.00.0000
21954 -
21955 \begin_inset ERT
21956 status collapsed
21957
21958 \begin_layout Standard
21959
21960
21961 \backslash
21962 /
21963 \end_layout
21964
21965 \end_inset
21966
21967 -optimize-cmp Try to optimize some compares.
21968 \end_layout
21969
21970 \begin_layout List
21971 \labelwidthstring 00.00.0000
21972 -
21973 \begin_inset ERT
21974 status collapsed
21975
21976 \begin_layout Standard
21977
21978
21979 \backslash
21980 /
21981 \end_layout
21982
21983 \end_inset
21984
21985 -optimize-df Analyze the dataflow of the generated code and improve it.
21986 \end_layout
21987
21988 \begin_layout List
21989 \labelwidthstring 00.00.0000
21990 -
21991 \begin_inset ERT
21992 status collapsed
21993
21994 \begin_layout Standard
21995
21996
21997 \backslash
21998 /
21999 \end_layout
22000
22001 \end_inset
22002
22003 -obanksel=nn Set optimization level for inserting BANKSELs.
22004 \newline
22005
22006 \end_layout
22007
22008 \begin_deeper
22009 \begin_layout List
22010 \labelwidthstring 00.00.0000
22011 0 no optimization
22012 \end_layout
22013
22014 \begin_layout List
22015 \labelwidthstring 00.00.0000
22016 1 checks previous used register and if it is the same then does not emit
22017  BANKSEL, accounts only for labels.
22018 \end_layout
22019
22020 \begin_layout List
22021 \labelwidthstring 00.00.0000
22022 2 tries to check the location of (even different) symbols and removes BANKSELs
22023  if they are in the same bank.
22024  
22025 \newline
22026
22027 \emph on
22028 Important: There might be problems if the linker script has data sections
22029  across bank borders!
22030 \end_layout
22031
22032 \end_deeper
22033 \begin_layout Subsubsection
22034 Linking Options
22035 \end_layout
22036
22037 \begin_layout List
22038 \labelwidthstring 00.00.0000
22039 -
22040 \begin_inset ERT
22041 status collapsed
22042
22043 \begin_layout Standard
22044
22045
22046 \backslash
22047 /
22048 \end_layout
22049
22050 \end_inset
22051
22052 -nodefaultlibs do not link default libraries when linking
22053 \end_layout
22054
22055 \begin_layout List
22056 \labelwidthstring 00.00.0000
22057 -
22058 \begin_inset ERT
22059 status collapsed
22060
22061 \begin_layout Standard
22062
22063
22064 \backslash
22065 /
22066 \end_layout
22067
22068 \end_inset
22069
22070 -no-crt Don't link the default run-time modules
22071 \end_layout
22072
22073 \begin_layout List
22074 \labelwidthstring 00.00.0000
22075 -
22076 \begin_inset ERT
22077 status collapsed
22078
22079 \begin_layout Standard
22080
22081
22082 \backslash
22083 /
22084 \end_layout
22085
22086 \end_inset
22087
22088 -use-crt= Use a custom run-time module instead of the defaults.
22089 \end_layout
22090
22091 \begin_layout Subsubsection
22092 Debugging Options
22093 \end_layout
22094
22095 \begin_layout Standard
22096 Debugging options enable extra debugging information in the output files.
22097 \end_layout
22098
22099 \begin_layout List
22100 \labelwidthstring 00.00.0000
22101 -
22102 \begin_inset ERT
22103 status collapsed
22104
22105 \begin_layout Standard
22106
22107
22108 \backslash
22109 /
22110 \end_layout
22111
22112 \end_inset
22113
22114 -debug-xtra Similar to -
22115 \begin_inset ERT
22116 status collapsed
22117
22118 \begin_layout Standard
22119
22120
22121 \backslash
22122 /
22123 \end_layout
22124
22125 \end_inset
22126
22127 -debug
22128 \begin_inset LatexCommand \index{-\/-debug}
22129
22130 \end_inset
22131
22132 , but dumps more information.
22133 \end_layout
22134
22135 \begin_layout List
22136 \labelwidthstring 00.00.0000
22137 -
22138 \begin_inset ERT
22139 status collapsed
22140
22141 \begin_layout Standard
22142
22143
22144 \backslash
22145 /
22146 \end_layout
22147
22148 \end_inset
22149
22150 -debug-ralloc Force register allocator to dump <source>.d file with debugging
22151  information.
22152  <source> is the name of the file compiled.
22153 \end_layout
22154
22155 \begin_layout List
22156 \labelwidthstring 00.00.0000
22157 -
22158 \begin_inset ERT
22159 status collapsed
22160
22161 \begin_layout Standard
22162
22163
22164 \backslash
22165 /
22166 \end_layout
22167
22168 \end_inset
22169
22170 -pcode-verbose Enable pcode debugging information in translation.
22171 \end_layout
22172
22173 \begin_layout List
22174 \labelwidthstring 00.00.0000
22175 -
22176 \begin_inset ERT
22177 status collapsed
22178
22179 \begin_layout Standard
22180
22181
22182 \backslash
22183 /
22184 \end_layout
22185
22186 \end_inset
22187
22188 -denable-peeps Force the usage of peepholes.
22189  Use with care.
22190 \end_layout
22191
22192 \begin_layout List
22193 \labelwidthstring 00.00.0000
22194 -
22195 \begin_inset ERT
22196 status collapsed
22197
22198 \begin_layout Standard
22199
22200
22201 \backslash
22202 /
22203 \end_layout
22204
22205 \end_inset
22206
22207 -gstack Trace push/pops for stack pointer overflow
22208 \end_layout
22209
22210 \begin_layout List
22211 \labelwidthstring 00.00.0000
22212 -
22213 \begin_inset ERT
22214 status collapsed
22215
22216 \begin_layout Standard
22217
22218
22219 \backslash
22220 /
22221 \end_layout
22222
22223 \end_inset
22224
22225 -call-tree dump call tree in .calltree file
22226 \end_layout
22227
22228 \begin_layout Subsection
22229 Enviromental Variables
22230 \end_layout
22231
22232 \begin_layout Standard
22233 There is a number of enviromental variables that can be used when running
22234  SDCC to enable certain optimizations or force a specific program behaviour.
22235  these variables are primarily for debugging purposes so they can be enabled/dis
22236 abled at will.
22237 \end_layout
22238
22239 \begin_layout Standard
22240 Currently there is only two such variables available:
22241 \end_layout
22242
22243 \begin_layout List
22244 \labelwidthstring 00.00.0000
22245 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
22246  bitfields is optimized by directly loading FSR0 with the address of the
22247  bitfield structure.
22248  Normally SDCC will cast the bitfield structure to a bitfield pointer and
22249  then load FSR0.
22250  This step saves data ram and code space for functions that perform heavy
22251  use of bitfields.
22252  (ie.
22253  80 bytes of code space are saved when compiling malloc.c with this option).
22254  
22255 \end_layout
22256
22257 \begin_layout List
22258 \labelwidthstring 00.00.0000
22259 NO_REG_OPT do not perform pCode registers optimization.
22260  This should be used for debugging purposes.
22261  In some where bugs in the pcode optimizer are found, users can benefit
22262  from temporarily disabling the optimizer until the bug is fixed.
22263 \end_layout
22264
22265 \begin_layout Subsection
22266 Preprocessor Macros
22267 \end_layout
22268
22269 \begin_layout Standard
22270 PIC16
22271 \begin_inset LatexCommand \index{PIC16}
22272
22273 \end_inset
22274
22275  port defines the following preprocessor macros while translating a source.
22276 \end_layout
22277
22278 \begin_layout Standard
22279 \align center
22280 \begin_inset Tabular
22281 <lyxtabular version="3" rows="6" columns="2">
22282 <features>
22283 <column alignment="center" valignment="top" leftline="true" width="0">
22284 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22285 <row topline="true" bottomline="true">
22286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22287 \begin_inset Text
22288
22289 \begin_layout Standard
22290 Macro
22291 \end_layout
22292
22293 \end_inset
22294 </cell>
22295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22296 \begin_inset Text
22297
22298 \begin_layout Standard
22299 Description
22300 \end_layout
22301
22302 \end_inset
22303 </cell>
22304 </row>
22305 <row topline="true">
22306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22307 \begin_inset Text
22308
22309 \begin_layout Standard
22310 SDCC_pic16
22311 \end_layout
22312
22313 \end_inset
22314 </cell>
22315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22316 \begin_inset Text
22317
22318 \begin_layout Standard
22319 Port identification
22320 \end_layout
22321
22322 \end_inset
22323 </cell>
22324 </row>
22325 <row topline="true">
22326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22327 \begin_inset Text
22328
22329 \begin_layout Standard
22330 _
22331 \begin_inset ERT
22332 status collapsed
22333
22334 \begin_layout Standard
22335
22336
22337 \backslash
22338 /
22339 \end_layout
22340
22341 \end_inset
22342
22343 _pic16
22344 \end_layout
22345
22346 \end_inset
22347 </cell>
22348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22349 \begin_inset Text
22350
22351 \begin_layout Standard
22352 Port identification (same as above)
22353 \end_layout
22354
22355 \end_inset
22356 </cell>
22357 </row>
22358 <row topline="true">
22359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22360 \begin_inset Text
22361
22362 \begin_layout Standard
22363 pic18fxxxx
22364 \end_layout
22365
22366 \end_inset
22367 </cell>
22368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22369 \begin_inset Text
22370
22371 \begin_layout Standard
22372 MCU Identification.
22373  
22374 \emph on
22375 xxxx
22376 \emph default
22377  is the microcontrol identification number, i.e.
22378  452, 6620, etc
22379 \end_layout
22380
22381 \end_inset
22382 </cell>
22383 </row>
22384 <row topline="true">
22385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22386 \begin_inset Text
22387
22388 \begin_layout Standard
22389 _
22390 \begin_inset ERT
22391 status collapsed
22392
22393 \begin_layout Standard
22394
22395
22396 \backslash
22397 /
22398 \end_layout
22399
22400 \end_inset
22401
22402 _18Fxxxx
22403 \end_layout
22404
22405 \end_inset
22406 </cell>
22407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22408 \begin_inset Text
22409
22410 \begin_layout Standard
22411 MCU Identification (same as above)
22412 \end_layout
22413
22414 \end_inset
22415 </cell>
22416 </row>
22417 <row topline="true" bottomline="true">
22418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22419 \begin_inset Text
22420
22421 \begin_layout Standard
22422 STACK_MODEL_nnn
22423 \end_layout
22424
22425 \end_inset
22426 </cell>
22427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22428 \begin_inset Text
22429
22430 \begin_layout Standard
22431 nnn = SMALL or LARGE respectively according to the stack model used
22432 \end_layout
22433
22434 \end_inset
22435 </cell>
22436 </row>
22437 </lyxtabular>
22438
22439 \end_inset
22440
22441
22442 \end_layout
22443
22444 \begin_layout Standard
22445 In addition the following macros are defined when calling assembler:
22446 \end_layout
22447
22448 \begin_layout Standard
22449 \align center
22450 \begin_inset Tabular
22451 <lyxtabular version="3" rows="4" columns="2">
22452 <features>
22453 <column alignment="center" valignment="top" leftline="true" width="0">
22454 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22455 <row topline="true" bottomline="true">
22456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22457 \begin_inset Text
22458
22459 \begin_layout Standard
22460 Macro
22461 \end_layout
22462
22463 \end_inset
22464 </cell>
22465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22466 \begin_inset Text
22467
22468 \begin_layout Standard
22469 Description
22470 \end_layout
22471
22472 \end_inset
22473 </cell>
22474 </row>
22475 <row topline="true">
22476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22477 \begin_inset Text
22478
22479 \begin_layout Standard
22480 __18Fxxxx
22481 \end_layout
22482
22483 \end_inset
22484 </cell>
22485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22486 \begin_inset Text
22487
22488 \begin_layout Standard
22489 MCU Identification.
22490  
22491 \emph on
22492 xxxx
22493 \emph default
22494  is the microcontrol identification number, i.e.
22495  452, 6620, etc
22496 \end_layout
22497
22498 \end_inset
22499 </cell>
22500 </row>
22501 <row topline="true">
22502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22503 \begin_inset Text
22504
22505 \begin_layout Standard
22506 SDCC_MODEL_nnn
22507 \end_layout
22508
22509 \end_inset
22510 </cell>
22511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22512 \begin_inset Text
22513
22514 \begin_layout Standard
22515 nnn = SMALL or LARGE respectively according to the memory model used for
22516  SDCC
22517 \end_layout
22518
22519 \end_inset
22520 </cell>
22521 </row>
22522 <row topline="true" bottomline="true">
22523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22524 \begin_inset Text
22525
22526 \begin_layout Standard
22527 STACK_MODEL_nnn
22528 \end_layout
22529
22530 \end_inset
22531 </cell>
22532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22533 \begin_inset Text
22534
22535 \begin_layout Standard
22536 nnn = SMALL or LARGE respectively according to the stack model used
22537 \end_layout
22538
22539 \end_inset
22540 </cell>
22541 </row>
22542 </lyxtabular>
22543
22544 \end_inset
22545
22546
22547 \end_layout
22548
22549 \begin_layout Subsection
22550 Directories
22551 \end_layout
22552
22553 \begin_layout Standard
22554 PIC16
22555 \begin_inset LatexCommand \index{PIC16}
22556
22557 \end_inset
22558
22559  port uses the following directories for searching header files and libraries.
22560 \end_layout
22561
22562 \begin_layout Standard
22563 \align center
22564 \begin_inset Tabular
22565 <lyxtabular version="3" rows="3" columns="4">
22566 <features>
22567 <column alignment="center" valignment="top" leftline="true" width="0">
22568 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22569 <column alignment="center" valignment="top" width="0">
22570 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22571 <row topline="true" bottomline="true">
22572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22573 \begin_inset Text
22574
22575 \begin_layout Standard
22576 Directory
22577 \end_layout
22578
22579 \end_inset
22580 </cell>
22581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22582 \begin_inset Text
22583
22584 \begin_layout Standard
22585 Description
22586 \end_layout
22587
22588 \end_inset
22589 </cell>
22590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22591 \begin_inset Text
22592
22593 \begin_layout Standard
22594 Target
22595 \end_layout
22596
22597 \end_inset
22598 </cell>
22599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22600 \begin_inset Text
22601
22602 \begin_layout Standard
22603 Command prefix
22604 \end_layout
22605
22606 \end_inset
22607 </cell>
22608 </row>
22609 <row topline="true">
22610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22611 \begin_inset Text
22612
22613 \begin_layout Standard
22614 PREFIX/sdcc/include/pic16
22615 \end_layout
22616
22617 \end_inset
22618 </cell>
22619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22620 \begin_inset Text
22621
22622 \begin_layout Standard
22623 PIC16 specific headers
22624 \end_layout
22625
22626 \end_inset
22627 </cell>
22628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22629 \begin_inset Text
22630
22631 \begin_layout Standard
22632 Compiler
22633 \end_layout
22634
22635 \end_inset
22636 </cell>
22637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22638 \begin_inset Text
22639
22640 \begin_layout Standard
22641 -I
22642 \end_layout
22643
22644 \end_inset
22645 </cell>
22646 </row>
22647 <row topline="true" bottomline="true">
22648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22649 \begin_inset Text
22650
22651 \begin_layout Standard
22652 PREFIX/sdcc/lib/pic16
22653 \end_layout
22654
22655 \end_inset
22656 </cell>
22657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22658 \begin_inset Text
22659
22660 \begin_layout Standard
22661 PIC16 specific libraries
22662 \end_layout
22663
22664 \end_inset
22665 </cell>
22666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22667 \begin_inset Text
22668
22669 \begin_layout Standard
22670 Linker
22671 \end_layout
22672
22673 \end_inset
22674 </cell>
22675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22676 \begin_inset Text
22677
22678 \begin_layout Standard
22679 -L
22680 \end_layout
22681
22682 \end_inset
22683 </cell>
22684 </row>
22685 </lyxtabular>
22686
22687 \end_inset
22688
22689
22690 \end_layout
22691
22692 \begin_layout Subsection
22693 Pragmas
22694 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
22695
22696 \end_inset
22697
22698
22699 \end_layout
22700
22701 \begin_layout Standard
22702 PIC16
22703 \begin_inset LatexCommand \index{PIC16}
22704
22705 \end_inset
22706
22707  port currently supports the following pragmas:
22708 \end_layout
22709
22710 \begin_layout List
22711 \labelwidthstring 00.00.0000
22712 stack
22713 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
22714
22715 \end_inset
22716
22717  pragma stack
22718 \begin_inset LatexCommand \index{PIC16!stack}
22719
22720 \end_inset
22721
22722  forces the code generator to initialize the stack & frame pointers at a
22723  specific address.
22724  This is an adhoc solution for cases where no STACK directive is available
22725  in the linker script or gplink is not instructed to create a stack section.
22726 \newline
22727 The
22728  stack pragma should be used only once in a project.
22729  Multiple pragmas may result in indeterminate behaviour of the program.
22730 \begin_inset Foot
22731 status open
22732
22733 \begin_layout Standard
22734 The old format (ie.
22735  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
22736  cross page boundaries (or even exceed the available data RAM) and crash
22737  the program.
22738  Make sure that stack does not cross page boundaries when using the SMALL
22739  stack model.
22740 \end_layout
22741
22742 \end_inset
22743
22744
22745 \newline
22746 The format is as follows:
22747 \end_layout
22748
22749 \begin_layout LyX-Code
22750 #pragma stack bottom_address [stack_size]
22751 \end_layout
22752
22753 \begin_layout Standard
22754
22755 \emph on
22756 bottom_address
22757 \emph default
22758  is the lower bound of the stack section.
22759  The stack pointer initially will point at address (bottom_address+stack_size-1).
22760 \end_layout
22761
22762 \begin_layout LyX-Code
22763 Example:
22764 \end_layout
22765
22766 \begin_layout LyX-Code
22767
22768 \end_layout
22769
22770 \begin_layout LyX-Code
22771 /* initializes stack of 100 bytes at RAM address 0x200 */
22772 \end_layout
22773
22774 \begin_layout LyX-Code
22775 #pragma stack 0x200 100
22776 \end_layout
22777
22778 \begin_layout Standard
22779 If the stack_size field is omitted then a stack is created with the default
22780  size of 64.
22781  This size might be enough for most programs, but its not enough for operations
22782  with deep function nesting or excessive stack usage.
22783 \end_layout
22784
22785 \begin_layout List
22786 \labelwidthstring 00.00.0000
22787 code
22788 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
22789
22790 \end_inset
22791
22792  place a function symbol at static FLASH address
22793 \end_layout
22794
22795 \begin_layout LyX-Code
22796 Example:
22797 \end_layout
22798
22799 \begin_layout LyX-Code
22800
22801 \end_layout
22802
22803 \begin_layout LyX-Code
22804 /* place function test_func at 0x4000 */
22805 \end_layout
22806
22807 \begin_layout LyX-Code
22808 #pragma code test_func 0x4000
22809 \end_layout
22810
22811 \begin_layout LyX-Code
22812
22813 \end_layout
22814
22815 \begin_layout List
22816 \labelwidthstring 00.00.0000
22817 library instructs the linker to use a library module.
22818 \newline
22819 Usage:
22820 \end_layout
22821
22822 \begin_layout LyX-Code
22823 #pragma library module_name
22824 \end_layout
22825
22826 \begin_layout Standard
22827
22828 \emph on
22829 module_name
22830 \emph default
22831  can be any library or object file (including its path).
22832  Note that there are four reserved keywords which have special meaning.
22833  These are:
22834 \end_layout
22835
22836 \begin_layout Standard
22837 \align center
22838 \begin_inset Tabular
22839 <lyxtabular version="3" rows="6" columns="3">
22840 <features>
22841 <column alignment="center" valignment="top" leftline="true" width="0">
22842 <column alignment="block" valignment="top" leftline="true" width="20page%">
22843 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
22844 <row topline="true" bottomline="true">
22845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22846 \begin_inset Text
22847
22848 \begin_layout Standard
22849 Keyword
22850 \end_layout
22851
22852 \end_inset
22853 </cell>
22854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22855 \begin_inset Text
22856
22857 \begin_layout Standard
22858 Description
22859 \end_layout
22860
22861 \end_inset
22862 </cell>
22863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22864 \begin_inset Text
22865
22866 \begin_layout Standard
22867 Module to link
22868 \end_layout
22869
22870 \end_inset
22871 </cell>
22872 </row>
22873 <row topline="true">
22874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22875 \begin_inset Text
22876
22877 \begin_layout Standard
22878
22879 \series bold
22880 ignore
22881 \end_layout
22882
22883 \end_inset
22884 </cell>
22885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22886 \begin_inset Text
22887
22888 \begin_layout Standard
22889 ignore all library pragmas
22890 \end_layout
22891
22892 \end_inset
22893 </cell>
22894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22895 \begin_inset Text
22896
22897 \begin_layout Standard
22898
22899 \emph on
22900 (none)
22901 \end_layout
22902
22903 \end_inset
22904 </cell>
22905 </row>
22906 <row topline="true">
22907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22908 \begin_inset Text
22909
22910 \begin_layout Standard
22911
22912 \series bold
22913 c
22914 \end_layout
22915
22916 \end_inset
22917 </cell>
22918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22919 \begin_inset Text
22920
22921 \begin_layout Standard
22922 link the C library
22923 \end_layout
22924
22925 \end_inset
22926 </cell>
22927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22928 \begin_inset Text
22929
22930 \begin_layout Standard
22931
22932 \emph on
22933 libc18f
22934 \emph default
22935 .lib
22936 \end_layout
22937
22938 \end_inset
22939 </cell>
22940 </row>
22941 <row topline="true">
22942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22943 \begin_inset Text
22944
22945 \begin_layout Standard
22946
22947 \series bold
22948 math
22949 \end_layout
22950
22951 \end_inset
22952 </cell>
22953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22954 \begin_inset Text
22955
22956 \begin_layout Standard
22957 link the Math libarary
22958 \end_layout
22959
22960 \end_inset
22961 </cell>
22962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22963 \begin_inset Text
22964
22965 \begin_layout Standard
22966
22967 \emph on
22968 libm18f
22969 \emph default
22970 .lib
22971 \end_layout
22972
22973 \end_inset
22974 </cell>
22975 </row>
22976 <row topline="true">
22977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22978 \begin_inset Text
22979
22980 \begin_layout Standard
22981
22982 \series bold
22983 io
22984 \end_layout
22985
22986 \end_inset
22987 </cell>
22988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22989 \begin_inset Text
22990
22991 \begin_layout Standard
22992 link the I/O library
22993 \end_layout
22994
22995 \end_inset
22996 </cell>
22997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22998 \begin_inset Text
22999
23000 \begin_layout Standard
23001
23002 \emph on
23003 libio18f*
23004 \emph default
23005 .lib
23006 \end_layout
23007
23008 \end_inset
23009 </cell>
23010 </row>
23011 <row topline="true" bottomline="true">
23012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23013 \begin_inset Text
23014
23015 \begin_layout Standard
23016
23017 \series bold
23018 debug
23019 \end_layout
23020
23021 \end_inset
23022 </cell>
23023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23024 \begin_inset Text
23025
23026 \begin_layout Standard
23027 link the debug library
23028 \end_layout
23029
23030 \end_inset
23031 </cell>
23032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23033 \begin_inset Text
23034
23035 \begin_layout Standard
23036
23037 \emph on
23038 libdebug
23039 \emph default
23040 .lib
23041 \end_layout
23042
23043 \end_inset
23044 </cell>
23045 </row>
23046 </lyxtabular>
23047
23048 \end_inset
23049
23050
23051 \newline
23052 * is the device number, i.e.
23053  452 for PIC18F452 MCU.
23054 \end_layout
23055
23056 \begin_layout Standard
23057 This feature allows for linking with specific libraries withoug having to
23058  explicit name them in the command line.
23059  Note that the 
23060 \noun on
23061 ignore
23062 \noun default
23063  keyword will reject all modules specified by the library pragma.
23064 \end_layout
23065
23066 \begin_layout List
23067 \labelwidthstring 00.00.0000
23068 udata pragma udata instructs the compiler to emit code so that linker will
23069  place a variable at a specific memory bank
23070 \end_layout
23071
23072 \begin_layout LyX-Code
23073 Example:
23074 \end_layout
23075
23076 \begin_layout LyX-Code
23077
23078 \end_layout
23079
23080 \begin_layout LyX-Code
23081 /* places variable foo at bank2 */
23082 \end_layout
23083
23084 \begin_layout LyX-Code
23085 #pragma udata bank2 foo
23086 \end_layout
23087
23088 \begin_layout LyX-Code
23089 char foo;
23090 \end_layout
23091
23092 \begin_layout Standard
23093 In order for this pragma to work extra SECTION directives should be added
23094  in the .lkr script.
23095  In the following example a sample .lkr file is shown:
23096 \end_layout
23097
23098 \begin_layout LyX-Code
23099
23100 \end_layout
23101
23102 \begin_layout LyX-Code
23103 // Sample linker script for the PIC18F452 processor
23104 \end_layout
23105
23106 \begin_layout LyX-Code
23107 LIBPATH .
23108 \end_layout
23109
23110 \begin_layout LyX-Code
23111 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
23112 \end_layout
23113
23114 \begin_layout LyX-Code
23115 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
23116 \end_layout
23117
23118 \begin_layout LyX-Code
23119 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
23120 \end_layout
23121
23122 \begin_layout LyX-Code
23123 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
23124 \end_layout
23125
23126 \begin_layout LyX-Code
23127 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
23128 \end_layout
23129
23130 \begin_layout LyX-Code
23131 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
23132 \end_layout
23133
23134 \begin_layout LyX-Code
23135 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
23136 \end_layout
23137
23138 \begin_layout LyX-Code
23139
23140 \end_layout
23141
23142 \begin_layout LyX-Code
23143 DATABANK   NAME=gpr0       START=0x80           END=0xFF
23144 \end_layout
23145
23146 \begin_layout LyX-Code
23147 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
23148 \end_layout
23149
23150 \begin_layout LyX-Code
23151 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
23152 \end_layout
23153
23154 \begin_layout LyX-Code
23155 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
23156 \end_layout
23157
23158 \begin_layout LyX-Code
23159 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
23160 \end_layout
23161
23162 \begin_layout LyX-Code
23163 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
23164 \end_layout
23165
23166 \begin_layout LyX-Code
23167 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
23168 \end_layout
23169
23170 \begin_layout LyX-Code
23171
23172 \end_layout
23173
23174 \begin_layout LyX-Code
23175 SECTION    NAME=CONFIG     ROM=config
23176 \end_layout
23177
23178 \begin_layout LyX-Code
23179
23180 \end_layout
23181
23182 \begin_layout LyX-Code
23183 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
23184 \end_layout
23185
23186 \begin_layout LyX-Code
23187 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
23188 \end_layout
23189
23190 \begin_layout LyX-Code
23191 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
23192 \end_layout
23193
23194 \begin_layout LyX-Code
23195 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
23196 \end_layout
23197
23198 \begin_layout LyX-Code
23199 SECTION    NAME=bank4      RAM=gpr4
23200 \end_layout
23201
23202 \begin_layout LyX-Code
23203 SECTION    NAME=bank5      RAM=gpr5
23204 \end_layout
23205
23206 \begin_layout Standard
23207 The linker will recognise the section name set in the pragma statement and
23208  will position the variable at the memory bank set with the RAM field at
23209  the SECTION line in the linker script file.
23210 \end_layout
23211
23212 \begin_layout Subsection
23213 Header Files
23214 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
23215
23216 \end_inset
23217
23218
23219 \end_layout
23220
23221 \begin_layout Standard
23222 There is one main header file
23223 \begin_inset LatexCommand \index{PIC16!Header files}
23224
23225 \end_inset
23226
23227  that can be included to the source files using the pic16
23228 \begin_inset LatexCommand \index{PIC16}
23229
23230 \end_inset
23231
23232  port.
23233  That file is the 
23234 \series bold
23235 pic18fregs.h
23236 \series default
23237 .
23238  This header file contains the definitions for the processor special registers,
23239  so it is necessary if the source accesses them.
23240  It can be included by adding the following line in the beginning of the
23241  file:
23242 \end_layout
23243
23244 \begin_layout LyX-Code
23245 #include <pic18fregs.h>
23246 \end_layout
23247
23248 \begin_layout Standard
23249 The specific microcontroller is selected within the pic18fregs.h automatically,
23250  so the same source can be used with a variety of devices.
23251 \end_layout
23252
23253 \begin_layout Subsection
23254 Libraries
23255 \end_layout
23256
23257 \begin_layout Standard
23258 The libraries
23259 \begin_inset LatexCommand \index{PIC16!Libraries}
23260
23261 \end_inset
23262
23263  that PIC16
23264 \begin_inset LatexCommand \index{PIC16}
23265
23266 \end_inset
23267
23268  port depends on are the microcontroller device libraries which contain
23269  the symbol definitions for the microcontroller special function registers.
23270  These libraries have the format pic18fxxxx.lib, where 
23271 \emph on
23272 xxxx
23273 \emph default
23274  is the microcontroller identification number.
23275  The specific library is selected automatically by the compiler at link
23276  stage according to the selected device.
23277 \end_layout
23278
23279 \begin_layout Standard
23280 Libraries are created with gplib which is part of the gputils package 
23281 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23282
23283 \end_inset
23284
23285 .
23286 \end_layout
23287
23288 \begin_layout Subsubsection*
23289 Building the libraries
23290 \end_layout
23291
23292 \begin_layout Standard
23293 Before using SDCC/pic16 there are some libraries that need to be compiled.
23294  This process is not done automatically by SDCC since not all users use
23295  SDCC for pic16 projects.
23296  So each user should compile the libraries separately.
23297 \end_layout
23298
23299 \begin_layout Standard
23300 The steps to compile the pic16 libraries under Linux are:
23301 \end_layout
23302
23303 \begin_layout LyX-Code
23304 cd device/lib/pic16
23305 \end_layout
23306
23307 \begin_layout LyX-Code
23308 ./configure
23309 \end_layout
23310
23311 \begin_layout LyX-Code
23312 make
23313 \end_layout
23314
23315 \begin_layout LyX-Code
23316 cd ..
23317 \end_layout
23318
23319 \begin_layout LyX-Code
23320 make model-pic16
23321 \end_layout
23322
23323 \begin_layout LyX-Code
23324 su -c 'make install'     # install the libraries, you need the root password
23325 \end_layout
23326
23327 \begin_layout Standard
23328 If you need to install the headers too, do:
23329 \end_layout
23330
23331 \begin_layout LyX-Code
23332 cd device/include
23333 \end_layout
23334
23335 \begin_layout LyX-Code
23336 su -c 'make install'     # install the headers, you need the root password
23337 \end_layout
23338
23339 \begin_layout Standard
23340 There exist a special target to build the I/O libraries.
23341  This target is not automatically build because it will build the I/O library
23342  for 
23343 \emph on
23344 every
23345 \emph default
23346  supported device.
23347  This way building will take quite a lot of time.
23348  Users are advised to edit the 
23349 \series bold
23350 device/lib/pic16/pics.build
23351 \series default
23352  file and then execute:
23353 \end_layout
23354
23355 \begin_layout LyX-Code
23356 make lib-io
23357 \end_layout
23358
23359 \begin_layout Subsection
23360 Memory Models
23361 \end_layout
23362
23363 \begin_layout Standard
23364 The following memory models are supported by the PIC16 port:
23365 \end_layout
23366
23367 \begin_layout Itemize
23368 small model
23369 \end_layout
23370
23371 \begin_layout Itemize
23372 large model
23373 \end_layout
23374
23375 \begin_layout Standard
23376 Memory model affects the default size of pointers within the source.
23377  The sizes are shown in the next table:
23378 \end_layout
23379
23380 \begin_layout Standard
23381 \align center
23382 \begin_inset Tabular
23383 <lyxtabular version="3" rows="3" columns="3">
23384 <features>
23385 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23386 <column alignment="center" valignment="top" leftline="true" width="0">
23387 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23388 <row topline="true" bottomline="true">
23389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23390 \begin_inset Text
23391
23392 \begin_layout Standard
23393 Pointer sizes according to memory model
23394 \end_layout
23395
23396 \end_inset
23397 </cell>
23398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23399 \begin_inset Text
23400
23401 \begin_layout Standard
23402 small model
23403 \end_layout
23404
23405 \end_inset
23406 </cell>
23407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23408 \begin_inset Text
23409
23410 \begin_layout Standard
23411 large model
23412 \end_layout
23413
23414 \end_inset
23415 </cell>
23416 </row>
23417 <row topline="true" bottomline="true">
23418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23419 \begin_inset Text
23420
23421 \begin_layout Standard
23422 code pointers
23423 \end_layout
23424
23425 \end_inset
23426 </cell>
23427 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23428 \begin_inset Text
23429
23430 \begin_layout Standard
23431 16-bits
23432 \end_layout
23433
23434 \end_inset
23435 </cell>
23436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23437 \begin_inset Text
23438
23439 \begin_layout Standard
23440 24-bits
23441 \end_layout
23442
23443 \end_inset
23444 </cell>
23445 </row>
23446 <row topline="true" bottomline="true">
23447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23448 \begin_inset Text
23449
23450 \begin_layout Standard
23451 data pointers
23452 \end_layout
23453
23454 \end_inset
23455 </cell>
23456 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
23457 \begin_inset Text
23458
23459 \begin_layout Standard
23460 16-bits
23461 \end_layout
23462
23463 \end_inset
23464 </cell>
23465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23466 \begin_inset Text
23467
23468 \begin_layout Standard
23469 16-bits
23470 \end_layout
23471
23472 \end_inset
23473 </cell>
23474 </row>
23475 </lyxtabular>
23476
23477 \end_inset
23478
23479
23480 \end_layout
23481
23482 \begin_layout Standard
23483 It is advisable that all sources within a project are compiled with the
23484  same memory model.
23485  If one wants to override the default memory model, this can be done by
23486  declaring a pointer as 
23487 \series bold
23488 far
23489 \series default
23490  or 
23491 \series bold
23492 near
23493 \series default
23494 .
23495  Far selects large memory model's pointers, while near selects small memory
23496  model's pointers.
23497 \end_layout
23498
23499 \begin_layout Standard
23500 The standard device libraries (see 
23501 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
23502
23503 \end_inset
23504
23505 ) contain no reference to pointers, so they can be used with both memory
23506  models.
23507 \end_layout
23508
23509 \begin_layout Subsection
23510 Stack
23511 \end_layout
23512
23513 \begin_layout Standard
23514 The stack
23515 \begin_inset LatexCommand \index{PIC16!stack}
23516
23517 \end_inset
23518
23519  implementation for the PIC16 port uses two indirect registers, FSR1 and
23520  FSR2.
23521 \end_layout
23522
23523 \begin_layout List
23524 \labelwidthstring 00.00.0000
23525 FSR1 is assigned as stack pointer
23526 \end_layout
23527
23528 \begin_layout List
23529 \labelwidthstring 00.00.0000
23530 FSR2 is assigned as frame pointer
23531 \end_layout
23532
23533 \begin_layout Standard
23534 The following stack models are supported by the PIC16 port
23535 \end_layout
23536
23537 \begin_layout Itemize
23538
23539 \noun on
23540 small
23541 \noun default
23542  model
23543 \end_layout
23544
23545 \begin_layout Itemize
23546
23547 \noun on
23548 large
23549 \noun default
23550  model
23551 \end_layout
23552
23553 \begin_layout Standard
23554
23555 \noun on
23556 Small
23557 \noun default
23558  model means that only the FSRxL byte is used to access stack and frame,
23559  while 
23560 \emph on
23561 \noun on
23562 large
23563 \emph default
23564 \noun default
23565  uses both FSRxL and FSRxH registers.
23566  The following table shows the stack/frame pointers sizes according to stack
23567  model and the maximum space they can address:
23568 \end_layout
23569
23570 \begin_layout Standard
23571 \align center
23572 \begin_inset Tabular
23573 <lyxtabular version="3" rows="3" columns="3">
23574 <features>
23575 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23576 <column alignment="center" valignment="top" leftline="true" width="0">
23577 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23578 <row topline="true" bottomline="true">
23579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23580 \begin_inset Text
23581
23582 \begin_layout Standard
23583 Stack & Frame pointer sizes according to stack model
23584 \end_layout
23585
23586 \end_inset
23587 </cell>
23588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23589 \begin_inset Text
23590
23591 \begin_layout Standard
23592 small
23593 \end_layout
23594
23595 \end_inset
23596 </cell>
23597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23598 \begin_inset Text
23599
23600 \begin_layout Standard
23601 large
23602 \end_layout
23603
23604 \end_inset
23605 </cell>
23606 </row>
23607 <row topline="true">
23608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23609 \begin_inset Text
23610
23611 \begin_layout Standard
23612 Stack pointer FSR1
23613 \end_layout
23614
23615 \end_inset
23616 </cell>
23617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23618 \begin_inset Text
23619
23620 \begin_layout Standard
23621 8-bits
23622 \end_layout
23623
23624 \end_inset
23625 </cell>
23626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23627 \begin_inset Text
23628
23629 \begin_layout Standard
23630 16-bits
23631 \end_layout
23632
23633 \end_inset
23634 </cell>
23635 </row>
23636 <row topline="true" bottomline="true">
23637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23638 \begin_inset Text
23639
23640 \begin_layout Standard
23641 Frame pointer FSR2
23642 \end_layout
23643
23644 \end_inset
23645 </cell>
23646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23647 \begin_inset Text
23648
23649 \begin_layout Standard
23650 8-bits
23651 \end_layout
23652
23653 \end_inset
23654 </cell>
23655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23656 \begin_inset Text
23657
23658 \begin_layout Standard
23659 16-bits
23660 \end_layout
23661
23662 \end_inset
23663 </cell>
23664 </row>
23665 </lyxtabular>
23666
23667 \end_inset
23668
23669
23670 \end_layout
23671
23672 \begin_layout Standard
23673
23674 \noun on
23675 Large 
23676 \noun default
23677 stack model is currently not working properly throughout the code generator.
23678  So its use is not advised.
23679  Also there are some other points that need special care:
23680 \newline
23681
23682 \end_layout
23683
23684 \begin_layout Enumerate
23685 Do not create stack sections with size more than one physical bank (that
23686  is 256 bytes)
23687 \end_layout
23688
23689 \begin_layout Enumerate
23690 Stack sections should no cross physical bank limits (i.e.
23691  #pragma stack 0x50 0x100)
23692 \end_layout
23693
23694 \begin_layout Standard
23695 These limitations are caused by the fact that only FSRxL is modified when
23696  using SMALL stack model, so no more than 256 bytes of stack can be used.
23697  This problem will disappear after LARGE model is fully implemented.
23698 \end_layout
23699
23700 \begin_layout Subsection
23701 Functions
23702 \end_layout
23703
23704 \begin_layout Standard
23705 In addition to the standard SDCC function keywords, PIC16
23706 \begin_inset LatexCommand \index{PIC16}
23707
23708 \end_inset
23709
23710  port makes available two more:
23711 \end_layout
23712
23713 \begin_layout List
23714 \labelwidthstring 00.00.0000
23715 wparam
23716 \begin_inset LatexCommand \index{PIC16!wparam}
23717
23718 \end_inset
23719
23720  Use the WREG to pass one byte of the first function argument.
23721  This improves speed but you may not use this for functions with arguments
23722  that are called via function pointers, otherwise the first byte of the
23723  first parameter will get lost.
23724  Usage:
23725 \end_layout
23726
23727 \begin_layout LyX-Code
23728 void func_wparam(int a) wparam
23729 \end_layout
23730
23731 \begin_layout LyX-Code
23732 {
23733 \end_layout
23734
23735 \begin_layout LyX-Code
23736     /* WREG hold the lower part of a */
23737 \end_layout
23738
23739 \begin_layout LyX-Code
23740     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
23741  */
23742 \end_layout
23743
23744 \begin_layout LyX-Code
23745 ...
23746 \end_layout
23747
23748 \begin_layout LyX-Code
23749 }
23750 \end_layout
23751
23752 \begin_layout List
23753 \labelwidthstring 00.00.0000
23754 shadowregs
23755 \begin_inset LatexCommand \index{PIC16!shadowregs}
23756
23757 \end_inset
23758
23759  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
23760  hardware shadow registers which hold the values of WREG, STATUS and BSR
23761  registers.
23762  This can be done by adding the keyword 
23763 \emph on
23764 shadowregs
23765 \emph default
23766  before the 
23767 \emph on
23768 interrupt
23769 \emph default
23770  keyword in the function's header.
23771 \end_layout
23772
23773 \begin_layout LyX-Code
23774 void isr_shadow(void) shadowregs interrupt 1
23775 \end_layout
23776
23777 \begin_layout LyX-Code
23778 {
23779 \end_layout
23780
23781 \begin_layout LyX-Code
23782 ...
23783 \end_layout
23784
23785 \begin_layout LyX-Code
23786 }
23787 \end_layout
23788
23789 \begin_layout Standard
23790
23791 \emph on
23792 shadowregs
23793 \emph default
23794  instructs the code generator not to store/restore WREG, STATUS, BSR when
23795  entering/exiting the ISR.
23796 \end_layout
23797
23798 \begin_layout Subsection
23799 Function return values
23800 \end_layout
23801
23802 \begin_layout Standard
23803 Return values from functions are placed to the appropriate registers following
23804  a modified Microchip policy optimized for SDCC.
23805  The following table shows these registers:
23806 \end_layout
23807
23808 \begin_layout Standard
23809 \align center
23810 \begin_inset Tabular
23811 <lyxtabular version="3" rows="6" columns="2">
23812 <features>
23813 <column alignment="center" valignment="top" leftline="true" width="0">
23814 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23815 <row topline="true" bottomline="true">
23816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23817 \begin_inset Text
23818
23819 \begin_layout Standard
23820 size
23821 \end_layout
23822
23823 \end_inset
23824 </cell>
23825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23826 \begin_inset Text
23827
23828 \begin_layout Standard
23829 destination register
23830 \end_layout
23831
23832 \end_inset
23833 </cell>
23834 </row>
23835 <row topline="true">
23836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23837 \begin_inset Text
23838
23839 \begin_layout Standard
23840 8 bits
23841 \end_layout
23842
23843 \end_inset
23844 </cell>
23845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23846 \begin_inset Text
23847
23848 \begin_layout Standard
23849 WREG
23850 \end_layout
23851
23852 \end_inset
23853 </cell>
23854 </row>
23855 <row topline="true">
23856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23857 \begin_inset Text
23858
23859 \begin_layout Standard
23860 16 bits
23861 \end_layout
23862
23863 \end_inset
23864 </cell>
23865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23866 \begin_inset Text
23867
23868 \begin_layout Standard
23869 PRODL:WREG
23870 \end_layout
23871
23872 \end_inset
23873 </cell>
23874 </row>
23875 <row topline="true">
23876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23877 \begin_inset Text
23878
23879 \begin_layout Standard
23880 24 bits
23881 \end_layout
23882
23883 \end_inset
23884 </cell>
23885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23886 \begin_inset Text
23887
23888 \begin_layout Standard
23889 PRODH:PRODL:WREG
23890 \end_layout
23891
23892 \end_inset
23893 </cell>
23894 </row>
23895 <row topline="true">
23896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23897 \begin_inset Text
23898
23899 \begin_layout Standard
23900 32 bits
23901 \end_layout
23902
23903 \end_inset
23904 </cell>
23905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23906 \begin_inset Text
23907
23908 \begin_layout Standard
23909 FSR0L:PRODH:PRODL:WREG
23910 \end_layout
23911
23912 \end_inset
23913 </cell>
23914 </row>
23915 <row topline="true" bottomline="true">
23916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23917 \begin_inset Text
23918
23919 \begin_layout Standard
23920 >32 bits
23921 \end_layout
23922
23923 \end_inset
23924 </cell>
23925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23926 \begin_inset Text
23927
23928 \begin_layout Standard
23929 on stack, FSR0 points to the beginning
23930 \end_layout
23931
23932 \end_inset
23933 </cell>
23934 </row>
23935 </lyxtabular>
23936
23937 \end_inset
23938
23939
23940 \end_layout
23941
23942 \begin_layout Subsection
23943 Interrupts
23944 \end_layout
23945
23946 \begin_layout Standard
23947 An interrupt
23948 \begin_inset LatexCommand \index{PIC16!interrupt}
23949
23950 \end_inset
23951
23952  service routine (ISR) is declared using the 
23953 \emph on
23954 interrupt
23955 \emph default
23956  keyword.
23957 \end_layout
23958
23959 \begin_layout LyX-Code
23960 void isr(void) interrupt 
23961 \emph on
23962 n
23963 \end_layout
23964
23965 \begin_layout LyX-Code
23966 {
23967 \end_layout
23968
23969 \begin_layout LyX-Code
23970 ...
23971 \end_layout
23972
23973 \begin_layout LyX-Code
23974 }
23975 \end_layout
23976
23977 \begin_layout Standard
23978
23979 \emph on
23980 n
23981 \emph default
23982  is the interrupt number, which for PIC18F devices can be:
23983 \end_layout
23984
23985 \begin_layout Standard
23986 \align center
23987 \begin_inset Tabular
23988 <lyxtabular version="3" rows="4" columns="3">
23989 <features>
23990 <column alignment="center" valignment="top" leftline="true" width="0">
23991 <column alignment="center" valignment="top" leftline="true" width="0">
23992 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23993 <row topline="true" bottomline="true">
23994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23995 \begin_inset Text
23996
23997 \begin_layout Standard
23998
23999 \emph on
24000 n
24001 \end_layout
24002
24003 \end_inset
24004 </cell>
24005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24006 \begin_inset Text
24007
24008 \begin_layout Standard
24009 Interrupt Vector
24010 \end_layout
24011
24012 \end_inset
24013 </cell>
24014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24015 \begin_inset Text
24016
24017 \begin_layout Standard
24018 Interrupt Vector Address
24019 \end_layout
24020
24021 \end_inset
24022 </cell>
24023 </row>
24024 <row topline="true">
24025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24026 \begin_inset Text
24027
24028 \begin_layout Standard
24029 0
24030 \end_layout
24031
24032 \end_inset
24033 </cell>
24034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24035 \begin_inset Text
24036
24037 \begin_layout Standard
24038 RESET vector
24039 \end_layout
24040
24041 \end_inset
24042 </cell>
24043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24044 \begin_inset Text
24045
24046 \begin_layout Standard
24047 0x000000
24048 \end_layout
24049
24050 \end_inset
24051 </cell>
24052 </row>
24053 <row topline="true">
24054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24055 \begin_inset Text
24056
24057 \begin_layout Standard
24058
24059 \family roman
24060 \series medium
24061 \shape up
24062 \size normal
24063 \emph off
24064 \bar no
24065 \noun off
24066 \color none
24067 1
24068 \end_layout
24069
24070 \end_inset
24071 </cell>
24072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24073 \begin_inset Text
24074
24075 \begin_layout Standard
24076
24077 \family roman
24078 \series medium
24079 \shape up
24080 \size normal
24081 \emph off
24082 \bar no
24083 \noun off
24084 \color none
24085 HIGH priority interrupts
24086 \end_layout
24087
24088 \end_inset
24089 </cell>
24090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24091 \begin_inset Text
24092
24093 \begin_layout Standard
24094 0x000008
24095 \end_layout
24096
24097 \end_inset
24098 </cell>
24099 </row>
24100 <row topline="true" bottomline="true">
24101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24102 \begin_inset Text
24103
24104 \begin_layout Standard
24105 2
24106 \end_layout
24107
24108 \end_inset
24109 </cell>
24110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24111 \begin_inset Text
24112
24113 \begin_layout Standard
24114 LOW priority interrupts
24115 \end_layout
24116
24117 \end_inset
24118 </cell>
24119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24120 \begin_inset Text
24121
24122 \begin_layout Standard
24123 0x000018
24124 \end_layout
24125
24126 \end_inset
24127 </cell>
24128 </row>
24129 </lyxtabular>
24130
24131 \end_inset
24132
24133
24134 \end_layout
24135
24136 \begin_layout Standard
24137 When generating assembly code for ISR the code generator places a 
24138 \noun on
24139 goto 
24140 \noun default
24141 instruction at the 
24142 \emph on
24143 Interrupt Vector Address
24144 \emph default
24145  which points at the genetated ISR.
24146  This single GOTO instruction is part of an automatically generated 
24147 \emph on
24148 interrupt entry point
24149 \emph default
24150  function.
24151  The actuall ISR code is placed as normally would in the code space.
24152  Upon interrupt request, the GOTO instruction is executed which jumps to
24153  the ISR code.
24154  When declaring interrupt functions as _naked this GOTO instruction is 
24155 \series bold
24156 not
24157 \series default
24158  generated.
24159  The whole interrupt functions is therefore placed at the Interrupt Vector
24160  Address of the specific interrupt.
24161  This is not a problem for the LOW priority interrupts, but it is a problem
24162  for the RESET and the HIGH priority interrupts because code may be written
24163  at the next interrupt´s vector address and cause undeterminate program
24164  behaviour if that interrupt is raised.
24165 \begin_inset Foot
24166 status open
24167
24168 \begin_layout Standard
24169 This is not a problem when
24170 \end_layout
24171
24172 \begin_layout Enumerate
24173 this is a HIGH interrupt ISR and LOW interrupts are 
24174 \emph on
24175 disabled
24176 \emph default
24177  or not used.
24178 \end_layout
24179
24180 \begin_layout Enumerate
24181 when the ISR is small enough not to reach the next interrupt´s vector address.
24182 \end_layout
24183
24184 \end_inset
24185
24186
24187 \end_layout
24188
24189 \begin_layout Standard
24190
24191 \emph on
24192 n
24193 \emph default
24194  is possible to be omitted.
24195  This way a function is generated similar to an ISR, but it is not assigned
24196  to any interrupt.
24197 \end_layout
24198
24199 \begin_layout Standard
24200 When entering an interrupt, currently the PIC16
24201 \begin_inset LatexCommand \index{PIC16}
24202
24203 \end_inset
24204
24205  port automatically saves the following registers:
24206 \end_layout
24207
24208 \begin_layout Itemize
24209 WREG
24210 \end_layout
24211
24212 \begin_layout Itemize
24213 STATUS
24214 \end_layout
24215
24216 \begin_layout Itemize
24217 BSR
24218 \end_layout
24219
24220 \begin_layout Itemize
24221 PROD (PRODL and PRODH)
24222 \end_layout
24223
24224 \begin_layout Itemize
24225 FSR0 (FSR0L and FSR0H)
24226 \end_layout
24227
24228 \begin_layout Standard
24229 These registers are restored upon return from the interrupt routine.
24230 \begin_inset Foot
24231 status open
24232
24233 \begin_layout Standard
24234 NOTE that when the _naked attribute is specified for an interrupt routine,
24235  then NO registers are stored or restored.
24236 \end_layout
24237
24238 \end_inset
24239
24240
24241 \end_layout
24242
24243 \begin_layout Subsection
24244 Generic Pointers
24245 \end_layout
24246
24247 \begin_layout Standard
24248 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
24249  There are 3 types of generic pointers currently implemented data, code
24250  and eeprom pointers.
24251  They are differentiated by the value of the 7th and 6th bits of the upper
24252  byte:
24253 \end_layout
24254
24255 \begin_layout Standard
24256 \align center
24257 \begin_inset Tabular
24258 <lyxtabular version="3" rows="5" columns="5">
24259 <features>
24260 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24261 <column alignment="center" valignment="top" width="0">
24262 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24263 <column alignment="center" valignment="top" width="0">
24264 <column alignment="left" valignment="top" rightline="true" width="0">
24265 <row topline="true" bottomline="true">
24266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24267 \begin_inset Text
24268
24269 \begin_layout Standard
24270 pointer type
24271 \end_layout
24272
24273 \end_inset
24274 </cell>
24275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24276 \begin_inset Text
24277
24278 \begin_layout Standard
24279 7th bit
24280 \end_layout
24281
24282 \end_inset
24283 </cell>
24284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24285 \begin_inset Text
24286
24287 \begin_layout Standard
24288 6th bit
24289 \end_layout
24290
24291 \end_inset
24292 </cell>
24293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24294 \begin_inset Text
24295
24296 \begin_layout Standard
24297 rest of the pointer
24298 \end_layout
24299
24300 \end_inset
24301 </cell>
24302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24303 \begin_inset Text
24304
24305 \begin_layout Standard
24306 description
24307 \end_layout
24308
24309 \end_inset
24310 </cell>
24311 </row>
24312 <row topline="true" bottomline="true">
24313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24314 \begin_inset Text
24315
24316 \begin_layout Standard
24317 data 
24318 \end_layout
24319
24320 \end_inset
24321 </cell>
24322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24323 \begin_inset Text
24324
24325 \begin_layout Standard
24326 1
24327 \end_layout
24328
24329 \end_inset
24330 </cell>
24331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24332 \begin_inset Text
24333
24334 \begin_layout Standard
24335 0
24336 \end_layout
24337
24338 \end_inset
24339 </cell>
24340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24341 \begin_inset Text
24342
24343 \begin_layout Standard
24344
24345 \family typewriter
24346 \shape slanted
24347 \emph on
24348 uuuuuu uuuuxxxx xxxxxxxx
24349 \end_layout
24350
24351 \end_inset
24352 </cell>
24353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24354 \begin_inset Text
24355
24356 \begin_layout Standard
24357 a 12-bit data pointer in data RAM memory
24358 \end_layout
24359
24360 \end_inset
24361 </cell>
24362 </row>
24363 <row bottomline="true">
24364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24365 \begin_inset Text
24366
24367 \begin_layout Standard
24368 code
24369 \end_layout
24370
24371 \end_inset
24372 </cell>
24373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24374 \begin_inset Text
24375
24376 \begin_layout Standard
24377 0
24378 \end_layout
24379
24380 \end_inset
24381 </cell>
24382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24383 \begin_inset Text
24384
24385 \begin_layout Standard
24386 0
24387 \end_layout
24388
24389 \end_inset
24390 </cell>
24391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24392 \begin_inset Text
24393
24394 \begin_layout Standard
24395
24396 \family typewriter
24397 \shape slanted
24398 \emph on
24399 uxxxxx xxxxxxxx xxxxxxxx
24400 \end_layout
24401
24402 \end_inset
24403 </cell>
24404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24405 \begin_inset Text
24406
24407 \begin_layout Standard
24408 a 21-bit code pointer in FLASH memory
24409 \end_layout
24410
24411 \end_inset
24412 </cell>
24413 </row>
24414 <row bottomline="true">
24415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24416 \begin_inset Text
24417
24418 \begin_layout Standard
24419 eeprom
24420 \end_layout
24421
24422 \end_inset
24423 </cell>
24424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24425 \begin_inset Text
24426
24427 \begin_layout Standard
24428 0
24429 \end_layout
24430
24431 \end_inset
24432 </cell>
24433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24434 \begin_inset Text
24435
24436 \begin_layout Standard
24437 1
24438 \end_layout
24439
24440 \end_inset
24441 </cell>
24442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24443 \begin_inset Text
24444
24445 \begin_layout Standard
24446
24447 \family typewriter
24448 \shape slanted
24449 \emph on
24450 uuuuuu uuuuuuxx xxxxxxxx
24451 \end_layout
24452
24453 \end_inset
24454 </cell>
24455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24456 \begin_inset Text
24457
24458 \begin_layout Standard
24459 a 10-bit eeprom pointer in EEPROM memory
24460 \end_layout
24461
24462 \end_inset
24463 </cell>
24464 </row>
24465 <row bottomline="true">
24466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24467 \begin_inset Text
24468
24469 \begin_layout Standard
24470 (unimplemented)
24471 \end_layout
24472
24473 \end_inset
24474 </cell>
24475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24476 \begin_inset Text
24477
24478 \begin_layout Standard
24479 1
24480 \end_layout
24481
24482 \end_inset
24483 </cell>
24484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24485 \begin_inset Text
24486
24487 \begin_layout Standard
24488 1
24489 \end_layout
24490
24491 \end_inset
24492 </cell>
24493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24494 \begin_inset Text
24495
24496 \begin_layout Standard
24497
24498 \family typewriter
24499 \shape slanted
24500 \emph on
24501 xxxxxx xxxxxxxx xxxxxxxx
24502 \end_layout
24503
24504 \end_inset
24505 </cell>
24506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24507 \begin_inset Text
24508
24509 \begin_layout Standard
24510 unimplemented pointer type
24511 \end_layout
24512
24513 \end_inset
24514 </cell>
24515 </row>
24516 </lyxtabular>
24517
24518 \end_inset
24519
24520
24521 \end_layout
24522
24523 \begin_layout Standard
24524 Generic pointer are read and written with a set of library functions which
24525  read/write 1, 2, 3, 4 bytes.
24526 \end_layout
24527
24528 \begin_layout Subsection
24529 PIC16 C Libraries
24530 \end_layout
24531
24532 \begin_layout Subsubsection
24533 Standard I/O Streams
24534 \end_layout
24535
24536 \begin_layout Standard
24537 In the 
24538 \emph on
24539 stdio.h
24540 \emph default
24541  the type FILE is defined as:
24542 \end_layout
24543
24544 \begin_layout LyX-Code
24545 typedef char * FILE;
24546 \end_layout
24547
24548 \begin_layout Standard
24549 This type is the stream type implemented I/O in the PIC18F devices.
24550  Also the standard input and output streams are declared in stdio.h:
24551 \end_layout
24552
24553 \begin_layout LyX-Code
24554 extern FILE * stdin;
24555 \end_layout
24556
24557 \begin_layout LyX-Code
24558 extern FILE * stdout;
24559 \end_layout
24560
24561 \begin_layout Standard
24562 The FILE type is actually a generic pointer which defines one more type
24563  of generic pointers, the 
24564 \emph on
24565 stream 
24566 \emph default
24567 pointer.
24568  This new type has the format:
24569 \end_layout
24570
24571 \begin_layout Standard
24572 \align center
24573 \begin_inset Tabular
24574 <lyxtabular version="3" rows="2" columns="7">
24575 <features>
24576 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24577 <column alignment="center" valignment="top" width="0">
24578 <column alignment="center" valignment="top" leftline="true" width="0">
24579 <column alignment="center" valignment="top" leftline="true" width="0">
24580 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24581 <column alignment="center" valignment="top" width="0">
24582 <column alignment="left" valignment="top" rightline="true" width="0">
24583 <row topline="true" bottomline="true">
24584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24585 \begin_inset Text
24586
24587 \begin_layout Standard
24588 pointer type
24589 \end_layout
24590
24591 \end_inset
24592 </cell>
24593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24594 \begin_inset Text
24595
24596 \begin_layout Standard
24597 <7:6>
24598 \end_layout
24599
24600 \end_inset
24601 </cell>
24602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24603 \begin_inset Text
24604
24605 \begin_layout Standard
24606 <5>
24607 \end_layout
24608
24609 \end_inset
24610 </cell>
24611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24612 \begin_inset Text
24613
24614 \begin_layout Standard
24615 <4>
24616 \end_layout
24617
24618 \end_inset
24619 </cell>
24620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24621 \begin_inset Text
24622
24623 \begin_layout Standard
24624 <3:0>
24625 \end_layout
24626
24627 \end_inset
24628 </cell>
24629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24630 \begin_inset Text
24631
24632 \begin_layout Standard
24633 rest of the pointer
24634 \end_layout
24635
24636 \end_inset
24637 </cell>
24638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24639 \begin_inset Text
24640
24641 \begin_layout Standard
24642 descrption
24643 \end_layout
24644
24645 \end_inset
24646 </cell>
24647 </row>
24648 <row topline="true" bottomline="true">
24649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24650 \begin_inset Text
24651
24652 \begin_layout Standard
24653 stream
24654 \end_layout
24655
24656 \end_inset
24657 </cell>
24658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24659 \begin_inset Text
24660
24661 \begin_layout Standard
24662 00
24663 \end_layout
24664
24665 \end_inset
24666 </cell>
24667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24668 \begin_inset Text
24669
24670 \begin_layout Standard
24671 1
24672 \end_layout
24673
24674 \end_inset
24675 </cell>
24676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24677 \begin_inset Text
24678
24679 \begin_layout Standard
24680 0
24681 \end_layout
24682
24683 \end_inset
24684 </cell>
24685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24686 \begin_inset Text
24687
24688 \begin_layout Standard
24689 nnnn
24690 \end_layout
24691
24692 \end_inset
24693 </cell>
24694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24695 \begin_inset Text
24696
24697 \begin_layout Standard
24698
24699 \family typewriter
24700 \shape slanted
24701 \emph on
24702 uuuuuuuu uuuuuuuu
24703 \end_layout
24704
24705 \end_inset
24706 </cell>
24707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24708 \begin_inset Text
24709
24710 \begin_layout Standard
24711 upper byte high nubble is 0x2n, the rest are zeroes
24712 \end_layout
24713
24714 \end_inset
24715 </cell>
24716 </row>
24717 </lyxtabular>
24718
24719 \end_inset
24720
24721
24722 \end_layout
24723
24724 \begin_layout Standard
24725 Currently implemented there are 3 types of streams defined:
24726 \end_layout
24727
24728 \begin_layout Standard
24729 \align center
24730 \begin_inset Tabular
24731 <lyxtabular version="3" rows="4" columns="4">
24732 <features>
24733 <column alignment="center" valignment="top" leftline="true" width="0">
24734 <column alignment="center" valignment="top" leftline="true" width="0">
24735 <column alignment="center" valignment="top" leftline="true" width="0">
24736 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24737 <row topline="true" bottomline="true">
24738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24739 \begin_inset Text
24740
24741 \begin_layout Standard
24742 stream type
24743 \end_layout
24744
24745 \end_inset
24746 </cell>
24747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24748 \begin_inset Text
24749
24750 \begin_layout Standard
24751 value
24752 \end_layout
24753
24754 \end_inset
24755 </cell>
24756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24757 \begin_inset Text
24758
24759 \begin_layout Standard
24760 module
24761 \end_layout
24762
24763 \end_inset
24764 </cell>
24765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24766 \begin_inset Text
24767
24768 \begin_layout Standard
24769 description
24770 \end_layout
24771
24772 \end_inset
24773 </cell>
24774 </row>
24775 <row topline="true">
24776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24777 \begin_inset Text
24778
24779 \begin_layout Standard
24780 STREAM_USART
24781 \end_layout
24782
24783 \end_inset
24784 </cell>
24785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24786 \begin_inset Text
24787
24788 \begin_layout Standard
24789
24790 \family typewriter
24791 0x200000UL
24792 \end_layout
24793
24794 \end_inset
24795 </cell>
24796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24797 \begin_inset Text
24798
24799 \begin_layout Standard
24800 USART
24801 \end_layout
24802
24803 \end_inset
24804 </cell>
24805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24806 \begin_inset Text
24807
24808 \begin_layout Standard
24809 Writes/Reads characters via the USART peripheral
24810 \end_layout
24811
24812 \end_inset
24813 </cell>
24814 </row>
24815 <row topline="true">
24816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24817 \begin_inset Text
24818
24819 \begin_layout Standard
24820 STREAM_MSSP
24821 \end_layout
24822
24823 \end_inset
24824 </cell>
24825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24826 \begin_inset Text
24827
24828 \begin_layout Standard
24829
24830 \family typewriter
24831 0x210000UL
24832 \end_layout
24833
24834 \end_inset
24835 </cell>
24836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24837 \begin_inset Text
24838
24839 \begin_layout Standard
24840 MSSP
24841 \end_layout
24842
24843 \end_inset
24844 </cell>
24845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24846 \begin_inset Text
24847
24848 \begin_layout Standard
24849 Writes/Reads characters via the MSSP peripheral
24850 \end_layout
24851
24852 \end_inset
24853 </cell>
24854 </row>
24855 <row topline="true" bottomline="true">
24856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24857 \begin_inset Text
24858
24859 \begin_layout Standard
24860 STREAM_USER
24861 \end_layout
24862
24863 \end_inset
24864 </cell>
24865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24866 \begin_inset Text
24867
24868 \begin_layout Standard
24869
24870 \family typewriter
24871 0x2f0000UL
24872 \end_layout
24873
24874 \end_inset
24875 </cell>
24876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24877 \begin_inset Text
24878
24879 \begin_layout Standard
24880 (none)
24881 \end_layout
24882
24883 \end_inset
24884 </cell>
24885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24886 \begin_inset Text
24887
24888 \begin_layout Standard
24889 Writes/Reads characters via used defined functions
24890 \end_layout
24891
24892 \end_inset
24893 </cell>
24894 </row>
24895 </lyxtabular>
24896
24897 \end_inset
24898
24899
24900 \end_layout
24901
24902 \begin_layout Standard
24903 The stream identifiers are declared as macros in the stdio.h header.
24904 \end_layout
24905
24906 \begin_layout Standard
24907 In the libc library there exist the functions that are used to write to
24908  each of the above streams.
24909  These are
24910 \end_layout
24911
24912 \begin_layout List
24913 \labelwidthstring 00.00.0000
24914 _
24915 \begin_inset ERT
24916 status collapsed
24917
24918 \begin_layout Standard
24919
24920
24921 \backslash
24922 /
24923 \end_layout
24924
24925 \end_inset
24926
24927 _stream_usart_putchar writes a character at the USART stream
24928 \end_layout
24929
24930 \begin_layout List
24931 \labelwidthstring 00.00.0000
24932 _
24933 \begin_inset ERT
24934 status collapsed
24935
24936 \begin_layout Standard
24937
24938
24939 \backslash
24940 /
24941 \end_layout
24942
24943 \end_inset
24944
24945 _stream_mssp_putchar writes a character at the MSSP stream
24946 \end_layout
24947
24948 \begin_layout List
24949 \labelwidthstring 00.00.0000
24950 putchar dummy function.
24951  This writes a character to a user specified manner.
24952 \end_layout
24953
24954 \begin_layout Standard
24955 In order to increase performance 
24956 \emph on
24957 putchar 
24958 \emph default
24959 is declared in stdio.h as having its parameter in WREG (it has the wparam
24960  keyword).
24961  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
24962  in a user-friendly way.
24963  
24964 \emph on
24965 arg
24966 \emph default
24967  is the name of the variable that holds the character to print.
24968  An example follows:
24969 \end_layout
24970
24971 \begin_layout LyX-Code
24972 #include <pic18fregs.h>
24973 \newline
24974 #include <stdio.h>
24975 \newline
24976
24977 \newline
24978 PUTCHAR( c )
24979 \end_layout
24980
24981 \begin_layout LyX-Code
24982 {
24983 \end_layout
24984
24985 \begin_layout LyX-Code
24986     PORTA = c;    /* dump character c to PORTA */
24987 \end_layout
24988
24989 \begin_layout LyX-Code
24990
24991 \newline
24992
24993 \newline
24994 void main(void)
24995 \end_layout
24996
24997 \begin_layout LyX-Code
24998 {
24999 \end_layout
25000
25001 \begin_layout LyX-Code
25002     stdout = STREAM_USER;    /* this is not necessary, since stdout points
25003 \end_layout
25004
25005 \begin_layout LyX-Code
25006                               * by default to STREAM_USER */
25007 \end_layout
25008
25009 \begin_layout LyX-Code
25010     printf (¨This is a printf test
25011 \backslash
25012 n¨);
25013 \end_layout
25014
25015 \begin_layout LyX-Code
25016 }
25017 \end_layout
25018
25019 \begin_layout LyX-Code
25020
25021 \end_layout
25022
25023 \begin_layout Subsubsection
25024 Printing functions
25025 \end_layout
25026
25027 \begin_layout Standard
25028 PIC16 contains an implementation of the printf-family of functions.
25029  There exist the following functions:
25030 \end_layout
25031
25032 \begin_layout LyX-Code
25033 extern unsigned int sprintf(char *buf, char *fmt, ...);
25034 \end_layout
25035
25036 \begin_layout LyX-Code
25037 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
25038 \end_layout
25039
25040 \begin_layout LyX-Code
25041
25042 \end_layout
25043
25044 \begin_layout LyX-Code
25045 extern unsigned int printf(char *fmt, ...);
25046 \end_layout
25047
25048 \begin_layout LyX-Code
25049 extern unsigned int vprintf(char *fmt, va_lista ap);
25050 \end_layout
25051
25052 \begin_layout LyX-Code
25053
25054 \end_layout
25055
25056 \begin_layout LyX-Code
25057 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
25058 \end_layout
25059
25060 \begin_layout LyX-Code
25061 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
25062 \end_layout
25063
25064 \begin_layout Standard
25065 For sprintf and vsprintf 
25066 \emph on
25067 buf 
25068 \emph default
25069 should normally be a data pointer where the resulting string will be placed.
25070  No range checking is done so the user should allocate the necessery buffer.
25071  For fprintf and vfprintf 
25072 \emph on
25073 fp
25074 \emph default
25075  should be a stream pointer (i.e.
25076  stdout, STREAM_MSSP, etc...).
25077 \end_layout
25078
25079 \begin_layout Subsubsection
25080 Signals
25081 \end_layout
25082
25083 \begin_layout Standard
25084 The PIC18F family of microcontrollers supports a number of interrupt sources.
25085  A list of these interrupts is shown in the following table:
25086 \end_layout
25087
25088 \begin_layout Standard
25089 \align center
25090 \begin_inset Tabular
25091 <lyxtabular version="3" rows="11" columns="4">
25092 <features>
25093 <column alignment="left" valignment="top" leftline="true" width="0">
25094 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25095 <column alignment="left" valignment="top" leftline="true" width="0">
25096 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25097 <row topline="true" bottomline="true">
25098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25099 \begin_inset Text
25100
25101 \begin_layout Standard
25102 signal name
25103 \end_layout
25104
25105 \end_inset
25106 </cell>
25107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25108 \begin_inset Text
25109
25110 \begin_layout Standard
25111 description
25112 \end_layout
25113
25114 \end_inset
25115 </cell>
25116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25117 \begin_inset Text
25118
25119 \begin_layout Standard
25120 signal name
25121 \end_layout
25122
25123 \end_inset
25124 </cell>
25125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25126 \begin_inset Text
25127
25128 \begin_layout Standard
25129 descritpion
25130 \end_layout
25131
25132 \end_inset
25133 </cell>
25134 </row>
25135 <row topline="true">
25136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25137 \begin_inset Text
25138
25139 \begin_layout Standard
25140 SIG_RB
25141 \end_layout
25142
25143 \end_inset
25144 </cell>
25145 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25146 \begin_inset Text
25147
25148 \begin_layout Standard
25149 PORTB change interrupt
25150 \end_layout
25151
25152 \end_inset
25153 </cell>
25154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25155 \begin_inset Text
25156
25157 \begin_layout Standard
25158 SIG_EE
25159 \end_layout
25160
25161 \end_inset
25162 </cell>
25163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25164 \begin_inset Text
25165
25166 \begin_layout Standard
25167 EEPROM/FLASH write complete interrupt
25168 \end_layout
25169
25170 \end_inset
25171 </cell>
25172 </row>
25173 <row topline="true">
25174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25175 \begin_inset Text
25176
25177 \begin_layout Standard
25178 SIG_INT0
25179 \end_layout
25180
25181 \end_inset
25182 </cell>
25183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25184 \begin_inset Text
25185
25186 \begin_layout Standard
25187 INT0 external interrupt
25188 \end_layout
25189
25190 \end_inset
25191 </cell>
25192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25193 \begin_inset Text
25194
25195 \begin_layout Standard
25196 SIG_BCOL
25197 \end_layout
25198
25199 \end_inset
25200 </cell>
25201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25202 \begin_inset Text
25203
25204 \begin_layout Standard
25205 Bus collision interrupt
25206 \end_layout
25207
25208 \end_inset
25209 </cell>
25210 </row>
25211 <row topline="true">
25212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25213 \begin_inset Text
25214
25215 \begin_layout Standard
25216 SIG_INT1
25217 \end_layout
25218
25219 \end_inset
25220 </cell>
25221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25222 \begin_inset Text
25223
25224 \begin_layout Standard
25225 INT1 external interrupt
25226 \end_layout
25227
25228 \end_inset
25229 </cell>
25230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25231 \begin_inset Text
25232
25233 \begin_layout Standard
25234 SIG_LVD
25235 \end_layout
25236
25237 \end_inset
25238 </cell>
25239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25240 \begin_inset Text
25241
25242 \begin_layout Standard
25243 Low voltage detect interrupt
25244 \end_layout
25245
25246 \end_inset
25247 </cell>
25248 </row>
25249 <row topline="true">
25250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25251 \begin_inset Text
25252
25253 \begin_layout Standard
25254 SIG_INT2
25255 \end_layout
25256
25257 \end_inset
25258 </cell>
25259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25260 \begin_inset Text
25261
25262 \begin_layout Standard
25263 INT2 external interrupt
25264 \end_layout
25265
25266 \end_inset
25267 </cell>
25268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25269 \begin_inset Text
25270
25271 \begin_layout Standard
25272 SIG_PSP
25273 \end_layout
25274
25275 \end_inset
25276 </cell>
25277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25278 \begin_inset Text
25279
25280 \begin_layout Standard
25281 Parallel slave port interrupt
25282 \end_layout
25283
25284 \end_inset
25285 </cell>
25286 </row>
25287 <row topline="true">
25288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25289 \begin_inset Text
25290
25291 \begin_layout Standard
25292 SIG_CCP1
25293 \end_layout
25294
25295 \end_inset
25296 </cell>
25297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25298 \begin_inset Text
25299
25300 \begin_layout Standard
25301 CCP1 module interrupt
25302 \end_layout
25303
25304 \end_inset
25305 </cell>
25306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25307 \begin_inset Text
25308
25309 \begin_layout Standard
25310 SIG_AD
25311 \end_layout
25312
25313 \end_inset
25314 </cell>
25315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25316 \begin_inset Text
25317
25318 \begin_layout Standard
25319 AD convertion complete interrupt
25320 \end_layout
25321
25322 \end_inset
25323 </cell>
25324 </row>
25325 <row topline="true">
25326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25327 \begin_inset Text
25328
25329 \begin_layout Standard
25330 SIG_CCP2
25331 \end_layout
25332
25333 \end_inset
25334 </cell>
25335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25336 \begin_inset Text
25337
25338 \begin_layout Standard
25339 CCP2 module interrupt
25340 \end_layout
25341
25342 \end_inset
25343 </cell>
25344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25345 \begin_inset Text
25346
25347 \begin_layout Standard
25348 SIG_RC
25349 \end_layout
25350
25351 \end_inset
25352 </cell>
25353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25354 \begin_inset Text
25355
25356 \begin_layout Standard
25357 USART receive interrupt
25358 \end_layout
25359
25360 \end_inset
25361 </cell>
25362 </row>
25363 <row topline="true">
25364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25365 \begin_inset Text
25366
25367 \begin_layout Standard
25368 SIG_TMR0
25369 \end_layout
25370
25371 \end_inset
25372 </cell>
25373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25374 \begin_inset Text
25375
25376 \begin_layout Standard
25377 TMR0 overflow interrupt
25378 \end_layout
25379
25380 \end_inset
25381 </cell>
25382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25383 \begin_inset Text
25384
25385 \begin_layout Standard
25386 SIG_TX
25387 \end_layout
25388
25389 \end_inset
25390 </cell>
25391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25392 \begin_inset Text
25393
25394 \begin_layout Standard
25395 USART transmit interrupt
25396 \end_layout
25397
25398 \end_inset
25399 </cell>
25400 </row>
25401 <row topline="true">
25402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25403 \begin_inset Text
25404
25405 \begin_layout Standard
25406 SIG_TMR1
25407 \end_layout
25408
25409 \end_inset
25410 </cell>
25411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25412 \begin_inset Text
25413
25414 \begin_layout Standard
25415 TMR1 overflow interrupt
25416 \end_layout
25417
25418 \end_inset
25419 </cell>
25420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25421 \begin_inset Text
25422
25423 \begin_layout Standard
25424 SIG_MSSP
25425 \end_layout
25426
25427 \end_inset
25428 </cell>
25429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25430 \begin_inset Text
25431
25432 \begin_layout Standard
25433 SSP receive/transmit interrupt
25434 \end_layout
25435
25436 \end_inset
25437 </cell>
25438 </row>
25439 <row topline="true">
25440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25441 \begin_inset Text
25442
25443 \begin_layout Standard
25444 SIG_TMR2
25445 \end_layout
25446
25447 \end_inset
25448 </cell>
25449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25450 \begin_inset Text
25451
25452 \begin_layout Standard
25453 TMR2 matches PR2 interrupt
25454 \end_layout
25455
25456 \end_inset
25457 </cell>
25458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25459 \begin_inset Text
25460
25461 \begin_layout Standard
25462
25463 \end_layout
25464
25465 \end_inset
25466 </cell>
25467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25468 \begin_inset Text
25469
25470 \begin_layout Standard
25471
25472 \end_layout
25473
25474 \end_inset
25475 </cell>
25476 </row>
25477 <row topline="true" bottomline="true">
25478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25479 \begin_inset Text
25480
25481 \begin_layout Standard
25482 SIG_TMR3
25483 \end_layout
25484
25485 \end_inset
25486 </cell>
25487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25488 \begin_inset Text
25489
25490 \begin_layout Standard
25491 TMR3 overflow interrupt
25492 \end_layout
25493
25494 \end_inset
25495 </cell>
25496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25497 \begin_inset Text
25498
25499 \begin_layout Standard
25500
25501 \end_layout
25502
25503 \end_inset
25504 </cell>
25505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25506 \begin_inset Text
25507
25508 \begin_layout Standard
25509
25510 \end_layout
25511
25512 \end_inset
25513 </cell>
25514 </row>
25515 </lyxtabular>
25516
25517 \end_inset
25518
25519
25520 \end_layout
25521
25522 \begin_layout Standard
25523 The prototypes for these names are defined in the header file 
25524 \emph on
25525 signal.h
25526 \emph default
25527  .
25528 \end_layout
25529
25530 \begin_layout Standard
25531 In order to simplify signal handling, a number of macros is provided:
25532 \end_layout
25533
25534 \begin_layout List
25535 \labelwidthstring 00.00.0000
25536 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
25537  high priority interrupts.
25538  
25539 \emph on
25540 name
25541 \emph default
25542  is the function name to use.
25543 \end_layout
25544
25545 \begin_layout List
25546 \labelwidthstring 00.00.0000
25547 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
25548  low priority interrupt.
25549  
25550 \emph on
25551 name
25552 \emph default
25553  is the function name to use.
25554 \end_layout
25555
25556 \begin_layout List
25557 \labelwidthstring 00.00.0000
25558 DEF_HANDLER(sig,handler) define a handler for signal 
25559 \emph on
25560 sig.
25561 \end_layout
25562
25563 \begin_layout List
25564 \labelwidthstring 00.00.0000
25565 END_DEF end the declaration of the dispatch table.
25566 \end_layout
25567
25568 \begin_layout Standard
25569 Additionally there are two more macros to simplify the declaration of the
25570  signal handler:
25571 \end_layout
25572
25573 \begin_layout List
25574 \labelwidthstring 00.00.0000
25575
25576 \series medium
25577 SIGHANDLER(handler) 
25578 \series default
25579 this declares the function prototype for the 
25580 \emph on
25581 handler
25582 \emph default
25583  function.
25584 \end_layout
25585
25586 \begin_layout List
25587 \labelwidthstring 00.00.0000
25588 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
25589 \end_layout
25590
25591 \begin_layout Standard
25592 An example of using the macros above is shown below:
25593 \end_layout
25594
25595 \begin_layout LyX-Code
25596 #include <pic18fregs.h>
25597 \end_layout
25598
25599 \begin_layout LyX-Code
25600 #include <signal.h>
25601 \newline
25602
25603 \newline
25604 DEF_INTHIGH(high_int)
25605 \end_layout
25606
25607 \begin_layout LyX-Code
25608 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
25609 \end_layout
25610
25611 \begin_layout LyX-Code
25612 DEF_HANDLER(SIG_BCOL, _bcol_handler)
25613 \end_layout
25614
25615 \begin_layout LyX-Code
25616 END_DEF
25617 \newline
25618
25619 \newline
25620 SIGHANDLER(_tmr0_handler)
25621 \end_layout
25622
25623 \begin_layout LyX-Code
25624 {
25625 \end_layout
25626
25627 \begin_layout LyX-Code
25628   /* action to be taken when timer 0 overflows */
25629 \end_layout
25630
25631 \begin_layout LyX-Code
25632 }
25633 \newline
25634
25635 \newline
25636 SIGHANDLERNAKED(_bcol_handler)
25637 \end_layout
25638
25639 \begin_layout LyX-Code
25640 {
25641 \end_layout
25642
25643 \begin_layout LyX-Code
25644   _asm
25645 \end_layout
25646
25647 \begin_layout LyX-Code
25648     /* action to be taken when bus collision occurs */
25649 \end_layout
25650
25651 \begin_layout LyX-Code
25652     retfie
25653 \end_layout
25654
25655 \begin_layout LyX-Code
25656  _endasm;
25657 \end_layout
25658
25659 \begin_layout LyX-Code
25660 }
25661 \end_layout
25662
25663 \begin_layout Standard
25664
25665 \series bold
25666 NOTES:
25667 \series default
25668  Special care should be taken when using the above scheme:
25669 \end_layout
25670
25671 \begin_layout Itemize
25672 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
25673 \end_layout
25674
25675 \begin_layout Itemize
25676 when declaring SIGHANDLERNAKED handler never forget to use 
25677 \emph on
25678 retfie
25679 \emph default
25680  for proper returning.
25681 \end_layout
25682
25683 \begin_layout Subsection
25684 PIC16 Port -- Tips
25685 \end_layout
25686
25687 \begin_layout Standard
25688 Here you can find some general tips for compiling programs with SDCC/pic16.
25689 \end_layout
25690
25691 \begin_layout Subsubsection
25692 Stack size
25693 \end_layout
25694
25695 \begin_layout Standard
25696 The default stack
25697 \begin_inset LatexCommand \index{PIC16!stack}
25698
25699 \end_inset
25700
25701  size (that is 64 bytes) probably is enough for many programs.
25702  One must take care that when there are many levels of function nesting,
25703  or there is excessive usage of stack, its size should be extended.
25704  An example of such a case is the printf/sprintf family of functions.
25705  If you encounter problems like not being able to print integers, then you
25706  need to set the stack size around the maximum (256 for small stack model).
25707  The following diagram shows what happens when calling printf to print an
25708  integer:
25709 \end_layout
25710
25711 \begin_layout LyX-Code
25712 printf () --> ltoa () --> ultoa () --> divschar ()
25713 \end_layout
25714
25715 \begin_layout Standard
25716 It is should be understood that stack is easily consumed when calling complicate
25717 d functions.
25718  Using command line arguments like -
25719 \begin_inset ERT
25720 status collapsed
25721
25722 \begin_layout Standard
25723
25724
25725 \backslash
25726 /
25727 \end_layout
25728
25729 \end_inset
25730
25731 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
25732  stack frames.
25733  Other ways to reduce stack usage may exist.
25734 \end_layout
25735
25736 \begin_layout Subsection
25737 Known bugs
25738 \end_layout
25739
25740 \begin_layout Standard
25741 The PIC16 Port currently does not pass SDCC's regression test
25742 \begin_inset LatexCommand \index{Regression test (PIC16)}
25743
25744 \end_inset
25745
25746  suite (see section 
25747 \begin_inset LatexCommand \ref{sec:Quality-control}
25748
25749 \end_inset
25750
25751 ) and thus the nightly regression tests for the PIC16 target are currently
25752  disabled for all hosts except for 
25753 \emph on
25754 Linux on Opteron.
25755
25756 \emph default
25757  This means you can see the result of the PIC16 regression tests f.e.
25758  by checking the log files in 
25759 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
25760
25761 \end_inset
25762
25763  (pick the most up to date file there, scroll down, lend a hand).
25764 \end_layout
25765
25766 \begin_layout Chapter
25767 Debugging
25768 \end_layout
25769
25770 \begin_layout Standard
25771 There are several approaches to debugging your code.
25772  This chapter is meant to show your options and to give detail on some of
25773  them:
25774 \newline
25775
25776 \newline
25777 When writing your code:
25778 \end_layout
25779
25780 \begin_layout Itemize
25781 write your code with debugging in mind (avoid duplicating code, put conceptually
25782  similar variables into structs, use structured code, have strategic points
25783  within your code where all variables are consistent, ...)
25784 \end_layout
25785
25786 \begin_layout Itemize
25787 run a syntax-checking tool like splint
25788 \begin_inset LatexCommand \index{splint (syntax checking tool)}
25789
25790 \end_inset
25791
25792
25793 \begin_inset LatexCommand \index{lint (syntax checking tool)}
25794
25795 \end_inset
25796
25797  (see -
25798 \begin_inset ERT
25799 status collapsed
25800
25801 \begin_layout Standard
25802
25803
25804 \backslash
25805 /
25806 \end_layout
25807
25808 \end_inset
25809
25810 -more-pedantic 
25811 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25812
25813 \end_inset
25814
25815 ) over the code.
25816 \end_layout
25817
25818 \begin_layout Itemize
25819 for the high level code use a C-compiler (like f.e.
25820  GCC) to compile run and debug the code on your host.
25821  See (see -
25822 \begin_inset ERT
25823 status collapsed
25824
25825 \begin_layout Standard
25826
25827
25828 \backslash
25829 /
25830 \end_layout
25831
25832 \end_inset
25833
25834 -more-pedantic 
25835 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
25836
25837 \end_inset
25838
25839  ) on howto handle syntax extensions like __xdata, __at(), ...
25840  
25841 \end_layout
25842
25843 \begin_layout Itemize
25844 use another C-compiler to compile code for your target.
25845  Always an option but not recommended:) And not very likely to help you.
25846  If you seriously consider walking this path you should at least occasionally
25847  check portability of your code.
25848  Most commercial compiler vendors will offer an evaluation version so you
25849  can test compile your code or snippets of your code.
25850 \end_layout
25851
25852 \begin_layout Standard
25853 Debugging on a simulator:
25854 \end_layout
25855
25856 \begin_layout Itemize
25857 there is a separate section about SDCDB (section 
25858 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
25859
25860 \end_inset
25861
25862 ) below.
25863 \end_layout
25864
25865 \begin_layout Itemize
25866 or (8051 specific) use a freeware/commercial simulator which interfaces
25867  to the AOMF
25868 \begin_inset LatexCommand \index{AOMF, AOMF51}
25869
25870 \end_inset
25871
25872  file (see 
25873 \begin_inset LatexCommand \ref{OMF file}
25874
25875 \end_inset
25876
25877 ) optionally generated by SDCC.
25878 \end_layout
25879
25880 \begin_layout Standard
25881 Debugging On-target: 
25882 \end_layout
25883
25884 \begin_layout Itemize
25885 use a MCU port pin to serially output debug data to the RS232 port of your
25886  host.
25887  You'll probably want some level shifting device typically involving a MAX232
25888  or similar IC.
25889  If the hardware serial port of the MCU is not available search for 'Software
25890  UART' in your favourite search machine.
25891 \end_layout
25892
25893 \begin_layout Itemize
25894 use an on-target monitor.
25895  In this context a monitor is a small program which usually accepts commands
25896  via a serial line and allows to set program counter, to single step through
25897  a program and read/write memory locations.
25898  For the 8051 good examples of monitors are paulmon and cmon51 (see section
25899  
25900 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
25901
25902 \end_inset
25903
25904 ).
25905 \end_layout
25906
25907 \begin_layout Itemize
25908 toggle MCU port pins at strategic points within your code and use an oscilloscop
25909 e.
25910  A 
25911 \emph on
25912 digital oscilloscope
25913 \emph default
25914
25915 \begin_inset LatexCommand \index{Oscilloscope}
25916
25917 \end_inset
25918
25919  with deep trace memory is really helpful especially if you have to debug
25920  a realtime application.
25921  If you need to monitor more pins than your oscilloscope provides you can
25922  sometimes get away with a small R-2R network.
25923  On a single channel oscilloscope you could f.e.
25924  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
25925 k
25926 \begin_inset Formula $\Omega$
25927 \end_inset
25928
25929  resistor and the other one by a 5\InsetSpace ~
25930 k
25931 \begin_inset Formula $\Omega$
25932 \end_inset
25933
25934  resistor to the oscilloscope probe (check output drive capability of the
25935  pins you want to monitor).
25936  If you need to monitor many more pins a 
25937 \emph on
25938 logic analyzer
25939 \emph default
25940  will be handy.
25941 \end_layout
25942
25943 \begin_layout Itemize
25944 use an ICE (
25945 \emph on
25946 i
25947 \emph default
25948
25949 \emph on
25950 c
25951 \emph default
25952 ircuit 
25953 \emph on
25954 e
25955 \emph default
25956 mulator
25957 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
25958
25959 \end_inset
25960
25961 ).
25962  Usually very expensive.
25963  And very nice to have too.
25964  And usually locks you (for years...) to the devices the ICE can emulate.
25965  
25966 \end_layout
25967
25968 \begin_layout Itemize
25969 use a remote debugger.
25970  In most 8-bit systems the symbol information is not available on the target,
25971  and a complete debugger is too bulky for the target system.
25972  Therefore usually a debugger on the host system connects to an on-target
25973  debugging stub which accepts only primitive commands.
25974  
25975 \newline
25976 Terms to enter into your favourite search engine could be 'remote debugging',
25977  'gdb stub' or 'inferior debugger'.
25978  (is there one?)
25979 \end_layout
25980
25981 \begin_layout Itemize
25982 use an on target hardware debugger.
25983  Some of the more modern MCUs include hardware support for setting break
25984  points and monitoring/changing variables by using dedicated hardware pins.
25985  This facility doesn't require additional code to run on the target and
25986  
25987 \emph on
25988 usually
25989 \emph default
25990  doesn't affect runtime behaviour until a breakpoint is hit.
25991  For the mcs51 most hardware debuggers use the AOMF
25992 \begin_inset LatexCommand \index{AOMF, AOMF51}
25993
25994 \end_inset
25995
25996  file (see 
25997 \begin_inset LatexCommand \ref{OMF file}
25998
25999 \end_inset
26000
26001 ) as input file.
26002  
26003 \end_layout
26004
26005 \begin_layout Standard
26006 Last not least:
26007 \end_layout
26008
26009 \begin_layout Itemize
26010 if you are not familiar with any of the following terms you're likely to
26011  run into problems rather sooner than later: 
26012 \emph on
26013 volatile
26014 \emph default
26015
26016 \emph on
26017 atomic
26018 \emph default
26019
26020 \emph on
26021 memory map
26022 \emph default
26023
26024 \emph on
26025 overlay
26026 \emph default
26027 .
26028  As an embedded programmer you 
26029 \emph on
26030 have
26031 \emph default
26032  to know them so why not look them up 
26033 \emph on
26034 before
26035 \emph default
26036  you have problems?)
26037 \end_layout
26038
26039 \begin_layout Itemize
26040 tell someone else about your problem (actually this is a surprisingly effective
26041  means to hunt down the bug even if the listener is not familiar with your
26042  environment).
26043  As 'failure to communicate' is probably one of the job-induced deformations
26044  of an embedded programmer this is highly encouraged.
26045 \end_layout
26046
26047 \begin_layout Section
26048 Debugging with SDCDB
26049 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
26050
26051 \end_inset
26052
26053
26054 \begin_inset LatexCommand \index{SDCDB (debugger)}
26055
26056 \end_inset
26057
26058  
26059 \end_layout
26060
26061 \begin_layout Standard
26062 SDCC is distributed with a source level debugger
26063 \begin_inset LatexCommand \index{Debugger}
26064
26065 \end_inset
26066
26067 .
26068  The debugger uses a command line interface, the command repertoire of the
26069  debugger has been kept as close to gdb
26070 \begin_inset LatexCommand \index{gdb}
26071
26072 \end_inset
26073
26074  (the GNU debugger) as possible.
26075  The configuration and build process is part of the standard compiler installati
26076 on, which also builds and installs the debugger in the target directory
26077  specified during configuration.
26078  The debugger allows you debug BOTH at the C source and at the ASM source
26079  level.
26080 \end_layout
26081
26082 \begin_layout Subsection
26083 Compiling for Debugging
26084 \end_layout
26085
26086 \begin_layout Standard
26087 The -
26088 \begin_inset ERT
26089 status collapsed
26090
26091 \begin_layout Standard
26092
26093
26094 \backslash
26095 /
26096 \end_layout
26097
26098 \end_inset
26099
26100 -debug
26101 \begin_inset LatexCommand \index{-\/-debug}
26102
26103 \end_inset
26104
26105  option must be specified for all files for which debug information is to
26106  be generated.
26107  The compiler generates a .adb file for each of these files.
26108  The linker creates the .cdb
26109 \begin_inset LatexCommand \index{<file>.cdb}
26110
26111 \end_inset
26112
26113  file from the .adb
26114 \begin_inset LatexCommand \index{<file>.adb}
26115
26116 \end_inset
26117
26118  files and the address information.
26119  This .cdb is used by the debugger.
26120 \end_layout
26121
26122 \begin_layout Subsection
26123 How the Debugger Works
26124 \end_layout
26125
26126 \begin_layout Standard
26127 When the -
26128 \begin_inset ERT
26129 status collapsed
26130
26131 \begin_layout Standard
26132
26133
26134 \backslash
26135 /
26136 \end_layout
26137
26138 \end_inset
26139
26140 -debug option is specified the compiler generates extra symbol information
26141  some of which are put into the assembler source and some are put into the
26142  .adb file.
26143  Then the linker creates the .cdb file from the individual .adb files with
26144  the address information for the symbols.
26145  The debugger reads the symbolic information generated by the compiler &
26146  the address information generated by the linker.
26147  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
26148  execution is controlled by the debugger.
26149  When a command is issued for the debugger, it translates it into appropriate
26150  commands for the simulator.
26151  (Currently SDCDM only connects to the simulator but 
26152 \emph on
26153 newcdb
26154 \emph default
26155  at 
26156 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
26157
26158 \end_inset
26159
26160  is an effort to connect directly to the hardware.) 
26161 \end_layout
26162
26163 \begin_layout Subsection
26164 Starting the Debugger SDCDB
26165 \end_layout
26166
26167 \begin_layout Standard
26168 The debugger can be started using the following command line.
26169  (Assume the file you are debugging has the file name foo).
26170 \newline
26171
26172 \newline
26173
26174 \family sans
26175 \series bold
26176 sdcdb foo
26177 \newline
26178
26179 \family default
26180 \series default
26181
26182 \newline
26183 The debugger will look for the following files.
26184 \end_layout
26185
26186 \begin_layout Itemize
26187 foo.c - the source file.
26188 \end_layout
26189
26190 \begin_layout Itemize
26191 foo.cdb - the debugger symbol information file.
26192 \end_layout
26193
26194 \begin_layout Itemize
26195 foo.ihx - the Intel hex format
26196 \begin_inset LatexCommand \index{Intel hex format}
26197
26198 \end_inset
26199
26200  object file.
26201 \end_layout
26202
26203 \begin_layout Subsection
26204 SDCDB Command Line Options
26205 \end_layout
26206
26207 \begin_layout Itemize
26208 -
26209 \begin_inset ERT
26210 status collapsed
26211
26212 \begin_layout Standard
26213
26214
26215 \backslash
26216 /
26217 \end_layout
26218
26219 \end_inset
26220
26221 -directory=<source file directory> this option can used to specify the directory
26222  search list.
26223  The debugger will look into the directory list specified for source, cdb
26224  & ihx files.
26225  The items in the directory list must be separated by ':', e.g.
26226  if the source files can be in the directories /home/src1 and /home/src2,
26227  the -
26228 \begin_inset ERT
26229 status collapsed
26230
26231 \begin_layout Standard
26232
26233
26234 \backslash
26235 /
26236 \end_layout
26237
26238 \end_inset
26239
26240 -directory option should be -
26241 \begin_inset ERT
26242 status collapsed
26243
26244 \begin_layout Standard
26245
26246
26247 \backslash
26248 /
26249 \end_layout
26250
26251 \end_inset
26252
26253 -directory=/home/src1:/home/src2.
26254  Note there can be no spaces in the option.
26255  
26256 \end_layout
26257
26258 \begin_layout Itemize
26259 -cd <directory> - change to the <directory>.
26260 \end_layout
26261
26262 \begin_layout Itemize
26263 -fullname - used by GUI front ends.
26264 \end_layout
26265
26266 \begin_layout Itemize
26267 -cpu <cpu-type> - this argument is passed to the simulator please see the
26268  simulator docs for details.
26269 \end_layout
26270
26271 \begin_layout Itemize
26272 -X <Clock frequency > this options is passed to the simulator please see
26273  the simulator docs for details.
26274 \end_layout
26275
26276 \begin_layout Itemize
26277 -s <serial port file> passed to simulator see the simulator docs for details.
26278 \end_layout
26279
26280 \begin_layout Itemize
26281 -S <serial in,out> passed to simulator see the simulator docs for details.
26282 \end_layout
26283
26284 \begin_layout Itemize
26285 -k <port number> passed to simulator see the simulator docs for details.
26286 \end_layout
26287
26288 \begin_layout Subsection
26289 SDCDB Debugger Commands
26290 \end_layout
26291
26292 \begin_layout Standard
26293 As mentioned earlier the command interface for the debugger has been deliberatel
26294 y kept as close the GNU debugger gdb, as possible.
26295  This will help the integration with existing graphical user interfaces
26296  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
26297  If you use a graphical user interface for the debugger you can skip this
26298  section.
26299 \end_layout
26300
26301 \begin_layout Subsubsection*
26302 break [line | file:line | function | file:function]
26303 \end_layout
26304
26305 \begin_layout Standard
26306 Set breakpoint at specified line or function:
26307 \newline
26308
26309 \newline
26310
26311 \family sans
26312 \series bold
26313 sdcdb>break 100 
26314 \newline
26315 sdcdb>break foo.c:100
26316 \newline
26317 sdcdb>break funcfoo
26318 \newline
26319 sdcdb>break foo.c:funcfoo
26320 \end_layout
26321
26322 \begin_layout Subsubsection*
26323 clear [line | file:line | function | file:function ]
26324 \end_layout
26325
26326 \begin_layout Standard
26327 Clear breakpoint at specified line or function:
26328 \newline
26329
26330 \newline
26331
26332 \family sans
26333 \series bold
26334 sdcdb>clear 100
26335 \newline
26336 sdcdb>clear foo.c:100
26337 \newline
26338 sdcdb>clear funcfoo
26339 \newline
26340 sdcdb>clear foo.c:funcfoo
26341 \end_layout
26342
26343 \begin_layout Subsubsection*
26344 continue
26345 \end_layout
26346
26347 \begin_layout Standard
26348 Continue program being debugged, after breakpoint.
26349 \end_layout
26350
26351 \begin_layout Subsubsection*
26352 finish
26353 \end_layout
26354
26355 \begin_layout Standard
26356 Execute till the end of the current function.
26357 \end_layout
26358
26359 \begin_layout Subsubsection*
26360 delete [n]
26361 \end_layout
26362
26363 \begin_layout Standard
26364 Delete breakpoint number 'n'.
26365  If used without any option clear ALL user defined break points.
26366 \end_layout
26367
26368 \begin_layout Subsubsection*
26369 info [break | stack | frame | registers ]
26370 \end_layout
26371
26372 \begin_layout Itemize
26373 info break - list all breakpoints
26374 \end_layout
26375
26376 \begin_layout Itemize
26377 info stack - show the function call stack.
26378 \end_layout
26379
26380 \begin_layout Itemize
26381 info frame - show information about the current execution frame.
26382 \end_layout
26383
26384 \begin_layout Itemize
26385 info registers - show content of all registers.
26386 \end_layout
26387
26388 \begin_layout Subsubsection*
26389 step
26390 \end_layout
26391
26392 \begin_layout Standard
26393 Step program until it reaches a different source line.
26394  Note: pressing <return> repeats the last command.
26395 \end_layout
26396
26397 \begin_layout Subsubsection*
26398 next
26399 \end_layout
26400
26401 \begin_layout Standard
26402 Step program, proceeding through subroutine calls.
26403 \end_layout
26404
26405 \begin_layout Subsubsection*
26406 run
26407 \end_layout
26408
26409 \begin_layout Standard
26410 Start debugged program.
26411 \end_layout
26412
26413 \begin_layout Subsubsection*
26414 ptype variable 
26415 \end_layout
26416
26417 \begin_layout Standard
26418 Print type information of the variable.
26419 \end_layout
26420
26421 \begin_layout Subsubsection*
26422 print variable
26423 \end_layout
26424
26425 \begin_layout Standard
26426 print value of variable.
26427 \end_layout
26428
26429 \begin_layout Subsubsection*
26430 file filename
26431 \end_layout
26432
26433 \begin_layout Standard
26434 load the given file name.
26435  Note this is an alternate method of loading file for debugging.
26436 \end_layout
26437
26438 \begin_layout Subsubsection*
26439 frame
26440 \end_layout
26441
26442 \begin_layout Standard
26443 print information about current frame.
26444 \end_layout
26445
26446 \begin_layout Subsubsection*
26447 set srcmode
26448 \end_layout
26449
26450 \begin_layout Standard
26451 Toggle between C source & assembly source.
26452 \end_layout
26453
26454 \begin_layout Subsubsection*
26455 ! simulator command
26456 \end_layout
26457
26458 \begin_layout Standard
26459 Send the string following '!' to the simulator, the simulator response is
26460  displayed.
26461  Note the debugger does not interpret the command being sent to the simulator,
26462  so if a command like 'go' is sent the debugger can loose its execution
26463  context and may display incorrect values.
26464 \end_layout
26465
26466 \begin_layout Subsubsection*
26467 quit
26468 \end_layout
26469
26470 \begin_layout Standard
26471 "Watch me now.
26472  Iam going Down.
26473  My name is Bobby Brown"
26474 \end_layout
26475
26476 \begin_layout Subsection
26477 Interfacing SDCDB with DDD
26478 \end_layout
26479
26480 \begin_layout Standard
26481 \begin_inset Note Comment
26482 status collapsed
26483
26484 \begin_layout Standard
26485 The screenshot was converted from png to eps with: 
26486 \begin_inset Quotes sld
26487 \end_inset
26488
26489 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
26490 \begin_inset Quotes srd
26491 \end_inset
26492
26493  which produces a pretty compact eps file which is free from compression
26494  artifacts.
26495 \end_layout
26496
26497 \begin_layout Standard
26498 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
26499  as this broke the build system on Sourceforge (pdf-file was broken.
26500  pdflatex does not accept eps files).
26501 \end_layout
26502
26503 \end_inset
26504
26505
26506 \end_layout
26507
26508 \begin_layout Standard
26509 The 
26510 \emph on
26511 p
26512 \emph default
26513 ortable 
26514 \emph on
26515 n
26516 \emph default
26517 etwork 
26518 \emph on
26519 g
26520 \emph default
26521 raphics File 
26522 \size footnotesize
26523
26524 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
26525
26526 \end_inset
26527
26528
26529 \size default
26530  shows a screenshot of a debugging session with DDD
26531 \begin_inset LatexCommand \index{DDD (debugger)}
26532
26533 \end_inset
26534
26535  (Unix only) on a simulated 8032.
26536  The debugging session might not run as smoothly as the screenshot suggests.
26537  The debugger allows setting of breakpoints, displaying and changing variables,
26538  single stepping through C and assembler code.
26539  
26540 \newline
26541 The source was compiled with 
26542 \family sans
26543 \series bold
26544
26545 \newline
26546
26547 \newline
26548 sdcc -
26549 \family default
26550 \series default
26551
26552 \begin_inset ERT
26553 status collapsed
26554
26555 \begin_layout Standard
26556
26557
26558 \backslash
26559 /
26560 \end_layout
26561
26562 \end_inset
26563
26564
26565 \family sans
26566 \series bold
26567 -debug ddd_example.c
26568 \family default
26569 \series default
26570  
26571 \family sans
26572 \series bold
26573
26574 \newline
26575
26576 \family default
26577 \series default
26578
26579 \newline
26580 and DDD was invoked with 
26581 \family sans
26582 \series bold
26583
26584 \newline
26585
26586 \newline
26587 ddd -debugger "sdcdb -cpu 8032 ddd_example"
26588 \end_layout
26589
26590 \begin_layout Standard
26591 \begin_inset Note Note
26592 status open
26593
26594 \begin_layout Standard
26595 Check that the double quotes or an apostroph within the command line survive
26596  the LyX tool chain.
26597  Previously the apostrophs got slanted in the PDF output so a cut and paste
26598  did not work.
26599 \end_layout
26600
26601 \end_inset
26602
26603
26604 \end_layout
26605
26606 \begin_layout Subsection
26607 Interfacing SDCDB with XEmacs
26608 \begin_inset LatexCommand \index{XEmacs}
26609
26610 \end_inset
26611
26612
26613 \begin_inset LatexCommand \index{Emacs}
26614
26615 \end_inset
26616
26617
26618 \end_layout
26619
26620 \begin_layout Standard
26621 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
26622  sdcdb.el and sdcdbsrc.el.
26623  These two files can be found in the $(prefix)/bin directory after the installat
26624 ion is complete.
26625  These files need to be loaded into XEmacs for the interface to work.
26626  This can be done at XEmacs startup time by inserting the following into
26627  your '.xemacs' file (which can be found in your HOME directory): 
26628 \newline
26629
26630 \newline
26631
26632 \family typewriter
26633 (load-file sdcdbsrc.el) 
26634 \family default
26635
26636 \newline
26637
26638 \newline
26639 .xemacs is a lisp file so the () around the command is REQUIRED.
26640  The files can also be loaded dynamically while XEmacs is running, set the
26641  environment variable 'EMACSLOADPATH' to the installation bin directory
26642  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
26643  To start the interface enter the following command: 
26644 \newline
26645
26646 \newline
26647
26648 \family sans
26649 \series bold
26650 ESC-x sdcdbsrc
26651 \family default
26652 \series default
26653
26654 \newline
26655
26656 \newline
26657 You will prompted to enter the file name to be debugged.
26658  
26659 \newline
26660
26661 \newline
26662 The command line options that are passed to the simulator directly are
26663  bound to default values in the file sdcdbsrc.el.
26664  The variables are listed below, these values maybe changed as required.
26665 \end_layout
26666
26667 \begin_layout Itemize
26668 sdcdbsrc-cpu-type '51
26669 \end_layout
26670
26671 \begin_layout Itemize
26672 sdcdbsrc-frequency '11059200
26673 \end_layout
26674
26675 \begin_layout Itemize
26676 sdcdbsrc-serial nil
26677 \end_layout
26678
26679 \begin_layout Standard
26680 The following is a list of key mapping for the debugger interface.
26681 \end_layout
26682
26683 \begin_layout Standard
26684 \InsetSpace ~
26685
26686 \family typewriter
26687
26688 \newline
26689 ;;\InsetSpace ~
26690 Current Listing :: 
26691 \newline
26692 ;;key\InsetSpace ~
26693 \InsetSpace ~
26694 \InsetSpace ~
26695 \InsetSpace ~
26696 \InsetSpace ~
26697 \InsetSpace ~
26698 \InsetSpace ~
26699 \InsetSpace ~
26700 \InsetSpace ~
26701 \InsetSpace ~
26702 \InsetSpace ~
26703 \InsetSpace ~
26704 \InsetSpace ~
26705 \InsetSpace ~
26706 binding\InsetSpace ~
26707 \InsetSpace ~
26708 \InsetSpace ~
26709 \InsetSpace ~
26710 \InsetSpace ~
26711 \InsetSpace ~
26712 \InsetSpace ~
26713 \InsetSpace ~
26714 \InsetSpace ~
26715 \InsetSpace ~
26716 \InsetSpace ~
26717 \InsetSpace ~
26718 \InsetSpace ~
26719 \InsetSpace ~
26720 \InsetSpace ~
26721 \InsetSpace ~
26722 \InsetSpace ~
26723 \InsetSpace ~
26724 \InsetSpace ~
26725 \InsetSpace ~
26726 \InsetSpace ~
26727 \InsetSpace ~
26728 Comment 
26729 \newline
26730 ;;---\InsetSpace ~
26731 \InsetSpace ~
26732 \InsetSpace ~
26733 \InsetSpace ~
26734 \InsetSpace ~
26735 \InsetSpace ~
26736 \InsetSpace ~
26737 \InsetSpace ~
26738 \InsetSpace ~
26739 \InsetSpace ~
26740 \InsetSpace ~
26741 \InsetSpace ~
26742 \InsetSpace ~
26743 \InsetSpace ~
26744 -------\InsetSpace ~
26745 \InsetSpace ~
26746 \InsetSpace ~
26747 \InsetSpace ~
26748 \InsetSpace ~
26749 \InsetSpace ~
26750 \InsetSpace ~
26751 \InsetSpace ~
26752 \InsetSpace ~
26753 \InsetSpace ~
26754 \InsetSpace ~
26755 \InsetSpace ~
26756 \InsetSpace ~
26757 \InsetSpace ~
26758 \InsetSpace ~
26759 \InsetSpace ~
26760 \InsetSpace ~
26761 \InsetSpace ~
26762 \InsetSpace ~
26763 \InsetSpace ~
26764 \InsetSpace ~
26765 \InsetSpace ~
26766 -------
26767 \newline
26768 ;; 
26769 \newline
26770 ;;\InsetSpace ~
26771 n\InsetSpace ~
26772 \InsetSpace ~
26773 \InsetSpace ~
26774 \InsetSpace ~
26775 \InsetSpace ~
26776 \InsetSpace ~
26777 \InsetSpace ~
26778 \InsetSpace ~
26779 \InsetSpace ~
26780 \InsetSpace ~
26781 \InsetSpace ~
26782 \InsetSpace ~
26783 \InsetSpace ~
26784 \InsetSpace ~
26785 \InsetSpace ~
26786 sdcdb-next-fro
26787 m-src\InsetSpace ~
26788 \InsetSpace ~
26789 \InsetSpace ~
26790 \InsetSpace ~
26791 \InsetSpace ~
26792 \InsetSpace ~
26793 \InsetSpace ~
26794 \InsetSpace ~
26795 \InsetSpace ~
26796 \InsetSpace ~
26797 SDCDB next command 
26798 \newline
26799 ;;\InsetSpace ~
26800 b\InsetSpace ~
26801 \InsetSpace ~
26802 \InsetSpace ~
26803 \InsetSpace ~
26804 \InsetSpace ~
26805 \InsetSpace ~
26806 \InsetSpace ~
26807 \InsetSpace ~
26808 \InsetSpace ~
26809 \InsetSpace ~
26810 \InsetSpace ~
26811 \InsetSpace ~
26812 \InsetSpace ~
26813 \InsetSpace ~
26814 \InsetSpace ~
26815 sdcdb-back-from-src\InsetSpace ~
26816 \InsetSpace ~
26817 \InsetSpace ~
26818 \InsetSpace ~
26819 \InsetSpace ~
26820 \InsetSpace ~
26821 \InsetSpace ~
26822 \InsetSpace ~
26823 \InsetSpace ~
26824 \InsetSpace ~
26825 SDCDB back command 
26826 \newline
26827 ;;\InsetSpace ~
26828 c\InsetSpace ~
26829 \InsetSpace ~
26830 \InsetSpace ~
26831 \InsetSpace ~
26832 \InsetSpace ~
26833 \InsetSpace ~
26834 \InsetSpace ~
26835 \InsetSpace ~
26836 \InsetSpace ~
26837 \InsetSpace ~
26838 \InsetSpace ~
26839 \InsetSpace ~
26840 \InsetSpace ~
26841 \InsetSpace ~
26842 \InsetSpace ~
26843 sdcdb-cont-f
26844 rom-src\InsetSpace ~
26845 \InsetSpace ~
26846 \InsetSpace ~
26847 \InsetSpace ~
26848 \InsetSpace ~
26849 \InsetSpace ~
26850 \InsetSpace ~
26851 \InsetSpace ~
26852 \InsetSpace ~
26853 \InsetSpace ~
26854 SDCDB continue command
26855 \newline
26856 ;;\InsetSpace ~
26857 s\InsetSpace ~
26858 \InsetSpace ~
26859 \InsetSpace ~
26860 \InsetSpace ~
26861 \InsetSpace ~
26862 \InsetSpace ~
26863 \InsetSpace ~
26864 \InsetSpace ~
26865 \InsetSpace ~
26866 \InsetSpace ~
26867 \InsetSpace ~
26868 \InsetSpace ~
26869 \InsetSpace ~
26870 \InsetSpace ~
26871 \InsetSpace ~
26872 sdcdb-step-from-src\InsetSpace ~
26873 \InsetSpace ~
26874 \InsetSpace ~
26875 \InsetSpace ~
26876 \InsetSpace ~
26877 \InsetSpace ~
26878 \InsetSpace ~
26879 \InsetSpace ~
26880 \InsetSpace ~
26881 \InsetSpace ~
26882 SDCDB step command 
26883 \newline
26884 ;;\InsetSpace ~
26885 ?\InsetSpace ~
26886 \InsetSpace ~
26887 \InsetSpace ~
26888 \InsetSpace ~
26889 \InsetSpace ~
26890 \InsetSpace ~
26891 \InsetSpace ~
26892 \InsetSpace ~
26893 \InsetSpace ~
26894 \InsetSpace ~
26895 \InsetSpace ~
26896 \InsetSpace ~
26897 \InsetSpace ~
26898 \InsetSpace ~
26899 \InsetSpace ~
26900 sdcdb-w
26901 hatis-c-sexp\InsetSpace ~
26902 \InsetSpace ~
26903 \InsetSpace ~
26904 \InsetSpace ~
26905 \InsetSpace ~
26906 \InsetSpace ~
26907 \InsetSpace ~
26908 \InsetSpace ~
26909 \InsetSpace ~
26910 \InsetSpace ~
26911 SDCDB ptypecommand for data at 
26912 \newline
26913 ;;\InsetSpace ~
26914 \InsetSpace ~
26915 \InsetSpace ~
26916 \InsetSpace ~
26917 \InsetSpace ~
26918 \InsetSpace ~
26919 \InsetSpace ~
26920 \InsetSpace ~
26921 \InsetSpace ~
26922 \InsetSpace ~
26923 \InsetSpace ~
26924 \InsetSpace ~
26925 \InsetSpace ~
26926 \InsetSpace ~
26927 \InsetSpace ~
26928 \InsetSpace ~
26929 \InsetSpace ~
26930 \InsetSpace ~
26931 \InsetSpace ~
26932 \InsetSpace ~
26933 \InsetSpace ~
26934 \InsetSpace ~
26935 \InsetSpace ~
26936 \InsetSpace ~
26937 \InsetSpace ~
26938 \InsetSpace ~
26939 \InsetSpace ~
26940 \InsetSpace ~
26941 \InsetSpace ~
26942 \InsetSpace ~
26943 \InsetSpace ~
26944 \InsetSpace ~
26945 \InsetSpace ~
26946 \InsetSpace ~
26947 \InsetSpace ~
26948 \InsetSpace ~
26949 \InsetSpace ~
26950 \InsetSpace ~
26951 \InsetSpace ~
26952 \InsetSpace ~
26953 \InsetSpace ~
26954 \InsetSpace ~
26955 \InsetSpace ~
26956 \InsetSpace ~
26957 \InsetSpace ~
26958 \InsetSpace ~
26959 \InsetSpace ~
26960 buffer point 
26961 \newline
26962 ;;\InsetSpace ~
26963 x\InsetSpace ~
26964 \InsetSpace ~
26965 \InsetSpace ~
26966 \InsetSpace ~
26967 \InsetSpace ~
26968 \InsetSpace ~
26969 \InsetSpace ~
26970 \InsetSpace ~
26971 \InsetSpace ~
26972 \InsetSpace ~
26973 \InsetSpace ~
26974 \InsetSpace ~
26975 \InsetSpace ~
26976 \InsetSpace ~
26977 \InsetSpace ~
26978 sdcdbsrc-delete\InsetSpace ~
26979 \InsetSpace ~
26980 \InsetSpace ~
26981 \InsetSpace ~
26982 \InsetSpace ~
26983 \InsetSpace ~
26984 \InsetSpace ~
26985 \InsetSpace ~
26986 \InsetSpace ~
26987 \InsetSpace ~
26988 \InsetSpace ~
26989 \InsetSpace ~
26990 \InsetSpace ~
26991 \InsetSpace ~
26992 SDCD
26993 B Delete all breakpoints if no arg 
26994 \newline
26995 ;;\InsetSpace ~
26996 \InsetSpace ~
26997 \InsetSpace ~
26998 \InsetSpace ~
26999 \InsetSpace ~
27000 \InsetSpace ~
27001 \InsetSpace ~
27002 \InsetSpace ~
27003 \InsetSpace ~
27004 \InsetSpace ~
27005 \InsetSpace ~
27006 \InsetSpace ~
27007 \InsetSpace ~
27008 \InsetSpace ~
27009 \InsetSpace ~
27010 \InsetSpace ~
27011 \InsetSpace ~
27012 \InsetSpace ~
27013 \InsetSpace ~
27014 \InsetSpace ~
27015 \InsetSpace ~
27016 \InsetSpace ~
27017 \InsetSpace ~
27018 \InsetSpace ~
27019 \InsetSpace ~
27020 \InsetSpace ~
27021 \InsetSpace ~
27022 \InsetSpace ~
27023 \InsetSpace ~
27024 \InsetSpace ~
27025 \InsetSpace ~
27026 \InsetSpace ~
27027 \InsetSpace ~
27028 \InsetSpace ~
27029 \InsetSpace ~
27030 \InsetSpace ~
27031 \InsetSpace ~
27032 \InsetSpace ~
27033 \InsetSpace ~
27034 \InsetSpace ~
27035 \InsetSpace ~
27036 \InsetSpace ~
27037 \InsetSpace ~
27038 \InsetSpace ~
27039 \InsetSpace ~
27040 \InsetSpace ~
27041 \InsetSpace ~
27042 given or delete arg (C-u arg x) 
27043 \newline
27044 ;;\InsetSpace ~
27045 m\InsetSpace ~
27046 \InsetSpace ~
27047 \InsetSpace ~
27048 \InsetSpace ~
27049 \InsetSpace ~
27050 \InsetSpace ~
27051 \InsetSpace ~
27052 \InsetSpace ~
27053 \InsetSpace ~
27054 \InsetSpace ~
27055 \InsetSpace ~
27056 \InsetSpace ~
27057 \InsetSpace ~
27058 \InsetSpace ~
27059 \InsetSpace ~
27060 sdcdbsrc
27061 -frame\InsetSpace ~
27062 \InsetSpace ~
27063 \InsetSpace ~
27064 \InsetSpace ~
27065 \InsetSpace ~
27066 \InsetSpace ~
27067 \InsetSpace ~
27068 \InsetSpace ~
27069 \InsetSpace ~
27070 \InsetSpace ~
27071 \InsetSpace ~
27072 \InsetSpace ~
27073 \InsetSpace ~
27074 \InsetSpace ~
27075 \InsetSpace ~
27076 SDCDB Display current frame if no arg, 
27077 \newline
27078 ;;\InsetSpace ~
27079 \InsetSpace ~
27080 \InsetSpace ~
27081 \InsetSpace ~
27082 \InsetSpace ~
27083 \InsetSpace ~
27084 \InsetSpace ~
27085 \InsetSpace ~
27086 \InsetSpace ~
27087 \InsetSpace ~
27088 \InsetSpace ~
27089 \InsetSpace ~
27090 \InsetSpace ~
27091 \InsetSpace ~
27092 \InsetSpace ~
27093 \InsetSpace ~
27094 \InsetSpace ~
27095 \InsetSpace ~
27096 \InsetSpace ~
27097 \InsetSpace ~
27098 \InsetSpace ~
27099 \InsetSpace ~
27100 \InsetSpace ~
27101 \InsetSpace ~
27102 \InsetSpace ~
27103 \InsetSpace ~
27104 \InsetSpace ~
27105 \InsetSpace ~
27106 \InsetSpace ~
27107 \InsetSpace ~
27108 \InsetSpace ~
27109 \InsetSpace ~
27110 \InsetSpace ~
27111 \InsetSpace ~
27112 \InsetSpace ~
27113 \InsetSpace ~
27114 \InsetSpace ~
27115 \InsetSpace ~
27116 \InsetSpace ~
27117 \InsetSpace ~
27118 \InsetSpace ~
27119 \InsetSpace ~
27120 \InsetSpace ~
27121 \InsetSpace ~
27122 \InsetSpace ~
27123 \InsetSpace ~
27124 \InsetSpace ~
27125 given or display frame arg
27126  
27127 \newline
27128 ;;\InsetSpace ~
27129 \InsetSpace ~
27130 \InsetSpace ~
27131 \InsetSpace ~
27132 \InsetSpace ~
27133 \InsetSpace ~
27134 \InsetSpace ~
27135 \InsetSpace ~
27136 \InsetSpace ~
27137 \InsetSpace ~
27138 \InsetSpace ~
27139 \InsetSpace ~
27140 \InsetSpace ~
27141 \InsetSpace ~
27142 \InsetSpace ~
27143 \InsetSpace ~
27144 \InsetSpace ~
27145 \InsetSpace ~
27146 \InsetSpace ~
27147 \InsetSpace ~
27148 \InsetSpace ~
27149 \InsetSpace ~
27150 \InsetSpace ~
27151 \InsetSpace ~
27152 \InsetSpace ~
27153 \InsetSpace ~
27154 \InsetSpace ~
27155 \InsetSpace ~
27156 \InsetSpace ~
27157 \InsetSpace ~
27158 \InsetSpace ~
27159 \InsetSpace ~
27160 \InsetSpace ~
27161 \InsetSpace ~
27162 \InsetSpace ~
27163 \InsetSpace ~
27164 \InsetSpace ~
27165 \InsetSpace ~
27166 \InsetSpace ~
27167 \InsetSpace ~
27168 \InsetSpace ~
27169 \InsetSpace ~
27170 \InsetSpace ~
27171 \InsetSpace ~
27172 \InsetSpace ~
27173 \InsetSpace ~
27174 \InsetSpace ~
27175 buffer point 
27176 \newline
27177 ;;\InsetSpace ~
27178 !\InsetSpace ~
27179 \InsetSpace ~
27180 \InsetSpace ~
27181 \InsetSpace ~
27182 \InsetSpace ~
27183 \InsetSpace ~
27184 \InsetSpace ~
27185 \InsetSpace ~
27186 \InsetSpace ~
27187 \InsetSpace ~
27188 \InsetSpace ~
27189 \InsetSpace ~
27190 \InsetSpace ~
27191 \InsetSpace ~
27192 \InsetSpace ~
27193 sdcdbsrc-goto-sdcdb\InsetSpace ~
27194 \InsetSpace ~
27195 \InsetSpace ~
27196 \InsetSpace ~
27197 \InsetSpace ~
27198 \InsetSpace ~
27199 \InsetSpace ~
27200 \InsetSpace ~
27201 \InsetSpace ~
27202 \InsetSpace ~
27203 Goto the SDCDB output buffer 
27204 \newline
27205 ;;\InsetSpace ~
27206 p\InsetSpace ~
27207 \InsetSpace ~
27208 \InsetSpace ~
27209 \InsetSpace ~
27210 \InsetSpace ~
27211 \InsetSpace ~
27212 \InsetSpace ~
27213 \InsetSpace ~
27214 \InsetSpace ~
27215 \InsetSpace ~
27216 \InsetSpace ~
27217 \InsetSpace ~
27218 \InsetSpace ~
27219 \InsetSpace ~
27220 \InsetSpace ~
27221 sdcdb-prin
27222 t-c-sexp\InsetSpace ~
27223 \InsetSpace ~
27224 \InsetSpace ~
27225 \InsetSpace ~
27226 \InsetSpace ~
27227 \InsetSpace ~
27228 \InsetSpace ~
27229 \InsetSpace ~
27230 \InsetSpace ~
27231 \InsetSpace ~
27232 \InsetSpace ~
27233 SDCDB print command for data at 
27234 \newline
27235 ;;\InsetSpace ~
27236 \InsetSpace ~
27237 \InsetSpace ~
27238 \InsetSpace ~
27239 \InsetSpace ~
27240 \InsetSpace ~
27241 \InsetSpace ~
27242 \InsetSpace ~
27243 \InsetSpace ~
27244 \InsetSpace ~
27245 \InsetSpace ~
27246 \InsetSpace ~
27247 \InsetSpace ~
27248 \InsetSpace ~
27249 \InsetSpace ~
27250 \InsetSpace ~
27251 \InsetSpace ~
27252 \InsetSpace ~
27253 \InsetSpace ~
27254 \InsetSpace ~
27255 \InsetSpace ~
27256 \InsetSpace ~
27257 \InsetSpace ~
27258 \InsetSpace ~
27259 \InsetSpace ~
27260 \InsetSpace ~
27261 \InsetSpace ~
27262 \InsetSpace ~
27263 \InsetSpace ~
27264 \InsetSpace ~
27265 \InsetSpace ~
27266 \InsetSpace ~
27267 \InsetSpace ~
27268 \InsetSpace ~
27269 \InsetSpace ~
27270 \InsetSpace ~
27271 \InsetSpace ~
27272 \InsetSpace ~
27273 \InsetSpace ~
27274 \InsetSpace ~
27275 \InsetSpace ~
27276 \InsetSpace ~
27277 \InsetSpace ~
27278 \InsetSpace ~
27279 \InsetSpace ~
27280 \InsetSpace ~
27281 \InsetSpace ~
27282 buffer point 
27283 \newline
27284 ;;\InsetSpace ~
27285 g\InsetSpace ~
27286 \InsetSpace ~
27287 \InsetSpace ~
27288 \InsetSpace ~
27289 \InsetSpace ~
27290 \InsetSpace ~
27291 \InsetSpace ~
27292 \InsetSpace ~
27293 \InsetSpace ~
27294 \InsetSpace ~
27295 \InsetSpace ~
27296 \InsetSpace ~
27297 \InsetSpace ~
27298 \InsetSpace ~
27299 \InsetSpace ~
27300 sdcdbsrc-goto-sdcdb\InsetSpace ~
27301 \InsetSpace ~
27302 \InsetSpace ~
27303 \InsetSpace ~
27304 \InsetSpace ~
27305 \InsetSpace ~
27306 \InsetSpace ~
27307 \InsetSpace ~
27308 \InsetSpace ~
27309 \InsetSpace ~
27310 Got
27311 o the SDCDB output buffer 
27312 \newline
27313 ;;\InsetSpace ~
27314 t\InsetSpace ~
27315 \InsetSpace ~
27316 \InsetSpace ~
27317 \InsetSpace ~
27318 \InsetSpace ~
27319 \InsetSpace ~
27320 \InsetSpace ~
27321 \InsetSpace ~
27322 \InsetSpace ~
27323 \InsetSpace ~
27324 \InsetSpace ~
27325 \InsetSpace ~
27326 \InsetSpace ~
27327 \InsetSpace ~
27328 \InsetSpace ~
27329 sdcdbsrc-mode\InsetSpace ~
27330 \InsetSpace ~
27331 \InsetSpace ~
27332 \InsetSpace ~
27333 \InsetSpace ~
27334 \InsetSpace ~
27335 \InsetSpace ~
27336 \InsetSpace ~
27337 \InsetSpace ~
27338 \InsetSpace ~
27339 \InsetSpace ~
27340 \InsetSpace ~
27341 \InsetSpace ~
27342 \InsetSpace ~
27343 \InsetSpace ~
27344 \InsetSpace ~
27345 Toggles Sdcdbsrc mode (turns it
27346  off) 
27347 \newline
27348 ;; 
27349 \newline
27350 ;;\InsetSpace ~
27351 C-c\InsetSpace ~
27352 C-f\InsetSpace ~
27353 \InsetSpace ~
27354 \InsetSpace ~
27355 \InsetSpace ~
27356 \InsetSpace ~
27357 \InsetSpace ~
27358 \InsetSpace ~
27359 \InsetSpace ~
27360 \InsetSpace ~
27361 sdcdb-finish-from-src\InsetSpace ~
27362 \InsetSpace ~
27363 \InsetSpace ~
27364 \InsetSpace ~
27365 \InsetSpace ~
27366 \InsetSpace ~
27367 \InsetSpace ~
27368 \InsetSpace ~
27369 SDCDB finish command 
27370 \newline
27371 ;; 
27372 \newline
27373 ;;\InsetSpace ~
27374 C-x\InsetSpace ~
27375 SPC\InsetSpace ~
27376 \InsetSpace ~
27377 \InsetSpace ~
27378 \InsetSpace ~
27379 \InsetSpace ~
27380 \InsetSpace ~
27381 \InsetSpace ~
27382 \InsetSpace ~
27383 \InsetSpace ~
27384 sdcdb-brea
27385 k\InsetSpace ~
27386 \InsetSpace ~
27387 \InsetSpace ~
27388 \InsetSpace ~
27389 \InsetSpace ~
27390 \InsetSpace ~
27391 \InsetSpace ~
27392 \InsetSpace ~
27393 \InsetSpace ~
27394 \InsetSpace ~
27395 \InsetSpace ~
27396 \InsetSpace ~
27397 \InsetSpace ~
27398 \InsetSpace ~
27399 \InsetSpace ~
27400 \InsetSpace ~
27401 \InsetSpace ~
27402 \InsetSpace ~
27403 Set break for line with point 
27404 \newline
27405 ;;\InsetSpace ~
27406 ESC\InsetSpace ~
27407 t\InsetSpace ~
27408 \InsetSpace ~
27409 \InsetSpace ~
27410 \InsetSpace ~
27411 \InsetSpace ~
27412 \InsetSpace ~
27413 \InsetSpace ~
27414 \InsetSpace ~
27415 \InsetSpace ~
27416 \InsetSpace ~
27417 \InsetSpace ~
27418 sdcdbsrc-mode\InsetSpace ~
27419 \InsetSpace ~
27420 \InsetSpace ~
27421 \InsetSpace ~
27422 \InsetSpace ~
27423 \InsetSpace ~
27424 \InsetSpace ~
27425 \InsetSpace ~
27426 \InsetSpace ~
27427 \InsetSpace ~
27428 \InsetSpace ~
27429 \InsetSpace ~
27430 \InsetSpace ~
27431 \InsetSpace ~
27432 \InsetSpace ~
27433 \InsetSpace ~
27434 Toggle Sdcdbsrc mode 
27435 \newline
27436 ;;\InsetSpace ~
27437 ESC\InsetSpace ~
27438 m\InsetSpace ~
27439 \InsetSpace ~
27440 \InsetSpace ~
27441 \InsetSpace ~
27442 \InsetSpace ~
27443 \InsetSpace ~
27444 \InsetSpace ~
27445 \InsetSpace ~
27446 \InsetSpace ~
27447 \InsetSpace ~
27448 \InsetSpace ~
27449 sdc
27450 dbsrc-srcmode\InsetSpace ~
27451 \InsetSpace ~
27452 \InsetSpace ~
27453 \InsetSpace ~
27454 \InsetSpace ~
27455 \InsetSpace ~
27456 \InsetSpace ~
27457 \InsetSpace ~
27458 \InsetSpace ~
27459 \InsetSpace ~
27460 \InsetSpace ~
27461 \InsetSpace ~
27462 \InsetSpace ~
27463 Toggle list mode 
27464 \newline
27465 ;; 
27466 \newline
27467
27468 \end_layout
27469
27470 \begin_layout Standard
27471
27472 \newpage
27473
27474 \end_layout
27475
27476 \begin_layout Chapter
27477 TIPS
27478 \end_layout
27479
27480 \begin_layout Standard
27481 Here are a few guidelines that will help the compiler generate more efficient
27482  code, some of the tips are specific to this compiler others are generally
27483  good programming practice.
27484 \end_layout
27485
27486 \begin_layout Itemize
27487 Use the smallest data type to represent your data-value.
27488  If it is known in advance that the value is going to be less than 256 then
27489  use an 'unsigned char' instead of a 'short' or 'int'.
27490  Please note, that ANSI C requires both signed and unsigned chars to be
27491  promoted to 'signed int'
27492 \begin_inset LatexCommand \index{promotion to signed int}
27493
27494 \end_inset
27495
27496
27497 \begin_inset Marginal
27498 status collapsed
27499
27500 \begin_layout Standard
27501
27502 \series bold
27503 \InsetSpace ~
27504 !
27505 \end_layout
27506
27507 \end_inset
27508
27509  before doing any operation.
27510  This promotion
27511 \begin_inset LatexCommand \index{type promotion}
27512
27513 \end_inset
27514
27515
27516 \begin_inset LatexCommand \label{type promotion}
27517
27518 \end_inset
27519
27520  can be omitted, if the result is the same.
27521  The effect of the promotion rules together with the sign-extension is often
27522  surprising:
27523 \end_layout
27524
27525 \begin_deeper
27526 \begin_layout Verse
27527
27528 \family typewriter
27529 unsigned char uc = 0xfe;
27530 \newline
27531 if (uc * uc < 0) /* this is true! */
27532 \newline
27533 {
27534 \newline
27535 \InsetSpace ~
27536 \InsetSpace ~
27537 \InsetSpace ~
27538 \InsetSpace ~
27539 ....
27540 \newline
27541 }
27542 \end_layout
27543
27544 \begin_layout Standard
27545
27546 \family typewriter
27547 uc * uc
27548 \family default
27549  is evaluated as 
27550 \family typewriter
27551 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
27552 \family default
27553 .
27554  
27555 \newline
27556 Another one:
27557 \end_layout
27558
27559 \begin_layout Verse
27560
27561 \family typewriter
27562 (unsigned char) -12 / (signed char) -3 = ...
27563 \end_layout
27564
27565 \begin_layout Standard
27566 No, the result is not 4:
27567 \end_layout
27568
27569 \begin_layout Verse
27570
27571 \family typewriter
27572 (int) (unsigned char) -12 / (int) (signed char) -3 =
27573 \newline
27574 (int) (unsigned char)
27575  0xf4 / (int) (signed char) 0xfd =
27576 \newline
27577 (int) 0x00f4 / (int) 0xfffd =
27578 \newline
27579 (int) 0x00f4
27580  / (int) 0xfffd =
27581 \newline
27582 (int) 244 / (int) -3 =
27583 \newline
27584 (int) -81 = (int) 0xffaf;
27585 \end_layout
27586
27587 \begin_layout Standard
27588 Don't complain, that gcc gives you a different result.
27589  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
27590  Therefore the results are different.
27591 \newline
27592 From 
27593 \begin_inset Quotes sld
27594 \end_inset
27595
27596 comp.lang.c FAQ
27597 \begin_inset Quotes srd
27598 \end_inset
27599
27600 :
27601 \end_layout
27602
27603 \begin_layout Quote
27604
27605 \emph on
27606 If well-defined overflow characteristics are important and negative values
27607  are not, or if you want to steer clear of sign-extension problems when
27608  manipulating bits or bytes, use one of the corresponding unsigned types.
27609  (Beware when mixing signed and unsigned values in expressions, though.)
27610 \newline
27611 Although
27612  character types (especially unsigned char) can be used as "tiny" integers,
27613  doing so is sometimes more trouble than it's worth, due to unpredictable
27614  sign extension and increased code size.
27615 \end_layout
27616
27617 \end_deeper
27618 \begin_layout Itemize
27619 Use unsigned when it is known in advance that the value is not going to
27620  be negative.
27621  This helps especially if you are doing division or multiplication, bit-shifting
27622  or are using an array index.
27623 \end_layout
27624
27625 \begin_layout Itemize
27626 NEVER jump into a LOOP.
27627 \end_layout
27628
27629 \begin_layout Itemize
27630 Declare the variables to be local
27631 \begin_inset LatexCommand \index{local variables}
27632
27633 \end_inset
27634
27635  whenever possible, especially loop control variables (induction).
27636 \end_layout
27637
27638 \begin_layout Itemize
27639 Have a look at the assembly listing to get a 
27640 \begin_inset Quotes sld
27641 \end_inset
27642
27643 feeling
27644 \begin_inset Quotes srd
27645 \end_inset
27646
27647  for the code generation.
27648 \end_layout
27649
27650 \begin_layout Section
27651 Porting code from or to other compilers
27652 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
27653
27654 \end_inset
27655
27656
27657 \end_layout
27658
27659 \begin_layout Itemize
27660 check whether endianness of the compilers differs and adapt where needed.
27661 \end_layout
27662
27663 \begin_layout Itemize
27664 check the device specific header files
27665 \begin_inset LatexCommand \index{Header files}
27666
27667 \end_inset
27668
27669
27670 \begin_inset LatexCommand \index{Include files}
27671
27672 \end_inset
27673
27674  for compiler specific syntax.
27675  Eventually include the file <compiler.h
27676 \begin_inset LatexCommand \index{compiler.h (include file)}
27677
27678 \end_inset
27679
27680
27681 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
27682
27683 \end_inset
27684
27685  to allow using common header files.
27686  (see f.e.
27687  cc2510fx.h 
27688 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
27689
27690 \end_inset
27691
27692 ).
27693 \end_layout
27694
27695 \begin_layout Itemize
27696 check whether the startup code contains the correct initialization (watchdog,
27697  peripherals).
27698 \end_layout
27699
27700 \begin_layout Itemize
27701 check whether the sizes of short, int, long match.
27702 \end_layout
27703
27704 \begin_layout Itemize
27705 check if some 16 or 32 bit hardware registers require a specific addressing
27706  order (least significant or most significant byte first) and adapt if needed
27707  (
27708 \emph on
27709 first
27710 \emph default
27711  and 
27712 \emph on
27713 last
27714 \emph default
27715  relate to time and not to lower/upper memory location here, so this is
27716  
27717 \emph on
27718 not
27719 \emph default
27720  the same as endianness).
27721 \end_layout
27722
27723 \begin_layout Itemize
27724 check whether the keyword 
27725 \emph on
27726 volatile
27727 \emph default
27728  is used where needed.
27729  The compilers might differ in their optimization characteristics (as different
27730  versions of the same compiler might also use more clever optimizations
27731  this is good idea anyway).
27732  See section 
27733 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
27734
27735 \end_inset
27736
27737 .
27738 \end_layout
27739
27740 \begin_layout Itemize
27741 check that the compilers are not told to supress warnings.
27742 \end_layout
27743
27744 \begin_layout Itemize
27745 check and convert compiler specific extensions (interrupts, memory areas,
27746  pragmas etc.).
27747 \end_layout
27748
27749 \begin_layout Itemize
27750 check for differences in type promotion.
27751  Especially check for math operations on 
27752 \family typewriter
27753 char
27754 \family default
27755  or 
27756 \family typewriter
27757 unsigned char
27758 \family default
27759  variables.
27760  For the sake of C99 compatibility SDCC will probably promote these to 
27761 \family typewriter
27762 int
27763 \family default
27764  more often than other compilers.
27765  Eventually insert explicit casts to 
27766 \family typewriter
27767 (char) 
27768 \family default
27769 or
27770 \family typewriter
27771  (unsigned char)
27772 \family default
27773 .
27774  Also check that the ~\InsetSpace ~
27775 operator
27776 \begin_inset LatexCommand \index{\~\/ Operator}
27777
27778 \end_inset
27779
27780  is not used on 
27781 \family typewriter
27782 bit
27783 \begin_inset LatexCommand \index{bit}
27784
27785 \end_inset
27786
27787
27788 \family default
27789  variables, use the !\InsetSpace ~
27790 operator instead.
27791  See sections 
27792 \begin_inset LatexCommand \ref{type promotion}
27793
27794 \end_inset
27795
27796  and 
27797 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
27798
27799 \end_inset
27800
27801 .
27802 \end_layout
27803
27804 \begin_layout Itemize
27805 check the assembly code generated for interrupt routines (f.e.
27806  for calls to possibly non-reentrant library functions).
27807 \end_layout
27808
27809 \begin_layout Itemize
27810 check whether timing loops result in proper timing (or preferably consider
27811  a rewrite of the code with timer based delays instead).
27812 \end_layout
27813
27814 \begin_layout Itemize
27815 check for differences in printf parameters (some compilers push (va_arg
27816 \begin_inset LatexCommand \index{vararg, va\_arg}
27817
27818 \end_inset
27819
27820 ) char variables as 
27821 \family typewriter
27822 int
27823 \family default
27824  others push them as 
27825 \family typewriter
27826 char
27827 \family default
27828 .
27829  See section 
27830 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
27831
27832 \end_inset
27833
27834 ).
27835 \end_layout
27836
27837 \begin_layout Itemize
27838 check the resulting memory map
27839 \begin_inset LatexCommand \index{Memory map}
27840
27841 \end_inset
27842
27843 .
27844  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
27845 ly idata, pdata, xdata).
27846  Eventually check if unexpected library functions are included.
27847 \end_layout
27848
27849 \begin_layout Section
27850 Tools
27851 \begin_inset LatexCommand \index{Tools}
27852
27853 \end_inset
27854
27855  included in the distribution
27856 \end_layout
27857
27858 \begin_layout Standard
27859 \align left
27860 \begin_inset Tabular
27861 <lyxtabular version="3" rows="12" columns="3">
27862 <features>
27863 <column alignment="left" valignment="top" leftline="true" width="0pt">
27864 <column alignment="left" valignment="top" leftline="true" width="0pt">
27865 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27866 <row topline="true" bottomline="true">
27867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27868 \begin_inset Text
27869
27870 \begin_layout Standard
27871
27872 \series bold
27873 Name
27874 \end_layout
27875
27876 \end_inset
27877 </cell>
27878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27879 \begin_inset Text
27880
27881 \begin_layout Standard
27882
27883 \series bold
27884 Purpose
27885 \end_layout
27886
27887 \end_inset
27888 </cell>
27889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27890 \begin_inset Text
27891
27892 \begin_layout Standard
27893
27894 \series bold
27895 Directory
27896 \end_layout
27897
27898 \end_inset
27899 </cell>
27900 </row>
27901 <row topline="true">
27902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27903 \begin_inset Text
27904
27905 \begin_layout Standard
27906 uCsim
27907 \begin_inset LatexCommand \index{uCsim}
27908
27909 \end_inset
27910
27911
27912 \end_layout
27913
27914 \end_inset
27915 </cell>
27916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27917 \begin_inset Text
27918
27919 \begin_layout Standard
27920 Simulator for various architectures
27921 \end_layout
27922
27923 \end_inset
27924 </cell>
27925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27926 \begin_inset Text
27927
27928 \begin_layout Standard
27929 sdcc/sim/ucsim
27930 \end_layout
27931
27932 \end_inset
27933 </cell>
27934 </row>
27935 <row topline="true">
27936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27937 \begin_inset Text
27938
27939 \begin_layout Standard
27940 keil2sdcc.pl
27941 \end_layout
27942
27943 \end_inset
27944 </cell>
27945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27946 \begin_inset Text
27947
27948 \begin_layout Standard
27949 header file
27950 \begin_inset LatexCommand \index{Header files}
27951
27952 \end_inset
27953
27954
27955 \begin_inset LatexCommand \index{Include files}
27956
27957 \end_inset
27958
27959  conversion
27960 \end_layout
27961
27962 \end_inset
27963 </cell>
27964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27965 \begin_inset Text
27966
27967 \begin_layout Standard
27968 sdcc/support/scripts
27969 \end_layout
27970
27971 \end_inset
27972 </cell>
27973 </row>
27974 <row topline="true">
27975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27976 \begin_inset Text
27977
27978 \begin_layout Standard
27979 mh2h.c
27980 \end_layout
27981
27982 \end_inset
27983 </cell>
27984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27985 \begin_inset Text
27986
27987 \begin_layout Standard
27988 header file conversion
27989 \end_layout
27990
27991 \end_inset
27992 </cell>
27993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27994 \begin_inset Text
27995
27996 \begin_layout Standard
27997 sdcc/support/scripts
27998 \end_layout
27999
28000 \end_inset
28001 </cell>
28002 </row>
28003 <row topline="true">
28004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28005 \begin_inset Text
28006
28007 \begin_layout Standard
28008 as-gbz80
28009 \end_layout
28010
28011 \end_inset
28012 </cell>
28013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28014 \begin_inset Text
28015
28016 \begin_layout Standard
28017 Assembler
28018 \end_layout
28019
28020 \end_inset
28021 </cell>
28022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28023 \begin_inset Text
28024
28025 \begin_layout Standard
28026
28027 \family roman
28028 \series medium
28029 \shape up
28030 \size normal
28031 \emph off
28032 \bar no
28033 \noun off
28034 \color none
28035 sdcc/bin
28036 \end_layout
28037
28038 \end_inset
28039 </cell>
28040 </row>
28041 <row topline="true">
28042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28043 \begin_inset Text
28044
28045 \begin_layout Standard
28046 as-z80
28047 \end_layout
28048
28049 \end_inset
28050 </cell>
28051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28052 \begin_inset Text
28053
28054 \begin_layout Standard
28055 Assembler
28056 \end_layout
28057
28058 \end_inset
28059 </cell>
28060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28061 \begin_inset Text
28062
28063 \begin_layout Standard
28064
28065 \family roman
28066 \series medium
28067 \shape up
28068 \size normal
28069 \emph off
28070 \bar no
28071 \noun off
28072 \color none
28073 sdcc/bin
28074 \end_layout
28075
28076 \end_inset
28077 </cell>
28078 </row>
28079 <row topline="true">
28080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28081 \begin_inset Text
28082
28083 \begin_layout Standard
28084 asx8051
28085 \end_layout
28086
28087 \end_inset
28088 </cell>
28089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28090 \begin_inset Text
28091
28092 \begin_layout Standard
28093 Assembler
28094 \end_layout
28095
28096 \end_inset
28097 </cell>
28098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28099 \begin_inset Text
28100
28101 \begin_layout Standard
28102
28103 \family roman
28104 \series medium
28105 \shape up
28106 \size normal
28107 \emph off
28108 \bar no
28109 \noun off
28110 \color none
28111 sdcc/bin
28112 \end_layout
28113
28114 \end_inset
28115 </cell>
28116 </row>
28117 <row topline="true">
28118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28119 \begin_inset Text
28120
28121 \begin_layout Standard
28122 SDCDB
28123 \end_layout
28124
28125 \end_inset
28126 </cell>
28127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28128 \begin_inset Text
28129
28130 \begin_layout Standard
28131 Simulator
28132 \end_layout
28133
28134 \end_inset
28135 </cell>
28136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28137 \begin_inset Text
28138
28139 \begin_layout Standard
28140
28141 \family roman
28142 \series medium
28143 \shape up
28144 \size normal
28145 \emph off
28146 \bar no
28147 \noun off
28148 \color none
28149 sdcc/bin
28150 \end_layout
28151
28152 \end_inset
28153 </cell>
28154 </row>
28155 <row topline="true">
28156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28157 \begin_inset Text
28158
28159 \begin_layout Standard
28160 aslink
28161 \end_layout
28162
28163 \end_inset
28164 </cell>
28165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28166 \begin_inset Text
28167
28168 \begin_layout Standard
28169 Linker
28170 \end_layout
28171
28172 \end_inset
28173 </cell>
28174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28175 \begin_inset Text
28176
28177 \begin_layout Standard
28178
28179 \family roman
28180 \series medium
28181 \shape up
28182 \size normal
28183 \emph off
28184 \bar no
28185 \noun off
28186 \color none
28187 sdcc/bin
28188 \end_layout
28189
28190 \end_inset
28191 </cell>
28192 </row>
28193 <row topline="true">
28194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28195 \begin_inset Text
28196
28197 \begin_layout Standard
28198 link-z80
28199 \end_layout
28200
28201 \end_inset
28202 </cell>
28203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28204 \begin_inset Text
28205
28206 \begin_layout Standard
28207 Linker
28208 \end_layout
28209
28210 \end_inset
28211 </cell>
28212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28213 \begin_inset Text
28214
28215 \begin_layout Standard
28216
28217 \family roman
28218 \series medium
28219 \shape up
28220 \size normal
28221 \emph off
28222 \bar no
28223 \noun off
28224 \color none
28225 sdcc/bin
28226 \end_layout
28227
28228 \end_inset
28229 </cell>
28230 </row>
28231 <row topline="true">
28232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28233 \begin_inset Text
28234
28235 \begin_layout Standard
28236 link-gbz80
28237 \end_layout
28238
28239 \end_inset
28240 </cell>
28241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28242 \begin_inset Text
28243
28244 \begin_layout Standard
28245 Linker
28246 \end_layout
28247
28248 \end_inset
28249 </cell>
28250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28251 \begin_inset Text
28252
28253 \begin_layout Standard
28254
28255 \family roman
28256 \series medium
28257 \shape up
28258 \size normal
28259 \emph off
28260 \bar no
28261 \noun off
28262 \color none
28263 sdcc/bin
28264 \end_layout
28265
28266 \end_inset
28267 </cell>
28268 </row>
28269 <row topline="true" bottomline="true">
28270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28271 \begin_inset Text
28272
28273 \begin_layout Standard
28274 packihx
28275 \end_layout
28276
28277 \end_inset
28278 </cell>
28279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28280 \begin_inset Text
28281
28282 \begin_layout Standard
28283 Intel Hex packer 
28284 \begin_inset LatexCommand \index{packihx (tool)}
28285
28286 \end_inset
28287
28288
28289 \end_layout
28290
28291 \end_inset
28292 </cell>
28293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28294 \begin_inset Text
28295
28296 \begin_layout Standard
28297
28298 \family roman
28299 \series medium
28300 \shape up
28301 \size normal
28302 \emph off
28303 \bar no
28304 \noun off
28305 \color none
28306 sdcc/bin
28307 \end_layout
28308
28309 \end_inset
28310 </cell>
28311 </row>
28312 </lyxtabular>
28313
28314 \end_inset
28315
28316
28317 \newline
28318
28319 \end_layout
28320
28321 \begin_layout Section
28322 Documentation
28323 \begin_inset LatexCommand \index{Documentation}
28324
28325 \end_inset
28326
28327  included in the distribution
28328 \end_layout
28329
28330 \begin_layout Standard
28331 \align left
28332 \begin_inset Tabular
28333 <lyxtabular version="3" rows="10" columns="2">
28334 <features>
28335 <column alignment="block" valignment="top" leftline="true" width="40col%">
28336 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
28337 <row topline="true" bottomline="true" endhead="true">
28338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28339 \begin_inset Text
28340
28341 \begin_layout Standard
28342
28343 \series bold
28344 Subject / Title
28345 \end_layout
28346
28347 \end_inset
28348 </cell>
28349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28350 \begin_inset Text
28351
28352 \begin_layout Standard
28353
28354 \series bold
28355 Filename / Where to get
28356 \end_layout
28357
28358 \end_inset
28359 </cell>
28360 </row>
28361 <row topline="true">
28362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28363 \begin_inset Text
28364
28365 \begin_layout Standard
28366 SDCC Compiler User Guide
28367 \end_layout
28368
28369 \end_inset
28370 </cell>
28371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28372 \begin_inset Text
28373
28374 \begin_layout Standard
28375 You're reading it right now
28376 \emph on
28377  \InsetSpace ~
28378 \InsetSpace ~
28379 \InsetSpace ~
28380
28381 \hfill
28382 online at:
28383 \emph default
28384
28385 \newline
28386
28387 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
28388
28389 \end_inset
28390
28391
28392 \end_layout
28393
28394 \end_inset
28395 </cell>
28396 </row>
28397 <row topline="true">
28398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28399 \begin_inset Text
28400
28401 \begin_layout Standard
28402 Changelog of SDCC
28403 \end_layout
28404
28405 \end_inset
28406 </cell>
28407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28408 \begin_inset Text
28409
28410 \begin_layout Standard
28411 sdcc/Changelog
28412 \emph on
28413  \InsetSpace ~
28414 \InsetSpace ~
28415 \InsetSpace ~
28416
28417 \hfill
28418 online at:
28419 \emph default
28420
28421 \newline
28422
28423 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28424
28425 \end_inset
28426
28427
28428 \end_layout
28429
28430 \end_inset
28431 </cell>
28432 </row>
28433 <row topline="true">
28434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28435 \begin_inset Text
28436
28437 \begin_layout Standard
28438 ASXXXX
28439 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
28440
28441 \end_inset
28442
28443
28444 \begin_inset LatexCommand \index{Assembler documentation}
28445
28446 \end_inset
28447
28448  Assemblers and
28449 \newline
28450 ASLINK
28451 \begin_inset LatexCommand \index{aslink}
28452
28453 \end_inset
28454
28455
28456 \begin_inset LatexCommand \index{Linker documentation}
28457
28458 \end_inset
28459
28460  Relocating Linker
28461 \end_layout
28462
28463 \end_inset
28464 </cell>
28465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28466 \begin_inset Text
28467
28468 \begin_layout Standard
28469 sdcc/as/doc/asxhtm.html 
28470 \emph on
28471 \InsetSpace ~
28472 \InsetSpace ~
28473 \InsetSpace ~
28474
28475 \hfill
28476 online at:
28477 \emph default
28478
28479 \newline
28480
28481 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
28482
28483 \end_inset
28484
28485
28486 \end_layout
28487
28488 \end_inset
28489 </cell>
28490 </row>
28491 <row topline="true">
28492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28493 \begin_inset Text
28494
28495 \begin_layout Standard
28496 SDCC regression test
28497 \begin_inset LatexCommand \index{Regression test}
28498
28499 \end_inset
28500
28501
28502 \end_layout
28503
28504 \end_inset
28505 </cell>
28506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28507 \begin_inset Text
28508
28509 \begin_layout Standard
28510 sdcc/doc/test_suite_spec.pdf 
28511 \emph on
28512 \InsetSpace ~
28513 \InsetSpace ~
28514 \InsetSpace ~
28515
28516 \hfill
28517 online at:
28518 \emph default
28519
28520 \newline
28521
28522 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28523
28524 \end_inset
28525
28526
28527 \end_layout
28528
28529 \end_inset
28530 </cell>
28531 </row>
28532 <row topline="true">
28533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28534 \begin_inset Text
28535
28536 \begin_layout Standard
28537 Various notes
28538 \end_layout
28539
28540 \end_inset
28541 </cell>
28542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28543 \begin_inset Text
28544
28545 \begin_layout Standard
28546 sdcc/doc/* 
28547 \emph on
28548 \InsetSpace ~
28549 \InsetSpace ~
28550 \InsetSpace ~
28551
28552 \hfill
28553 online at:
28554 \emph default
28555
28556 \newline
28557
28558 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
28559
28560 \end_inset
28561
28562
28563 \end_layout
28564
28565 \end_inset
28566 </cell>
28567 </row>
28568 <row topline="true">
28569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28570 \begin_inset Text
28571
28572 \begin_layout Standard
28573 Notes on debugging with SDCDB
28574 \begin_inset LatexCommand \index{SDCDB (debugger)}
28575
28576 \end_inset
28577
28578
28579 \end_layout
28580
28581 \end_inset
28582 </cell>
28583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28584 \begin_inset Text
28585
28586 \begin_layout Standard
28587 sdcc/debugger/README 
28588 \emph on
28589 \InsetSpace ~
28590 \InsetSpace ~
28591 \InsetSpace ~
28592
28593 \hfill
28594 online at
28595 \emph default
28596 :
28597 \newline
28598
28599 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
28600
28601 \end_inset
28602
28603
28604 \end_layout
28605
28606 \end_inset
28607 </cell>
28608 </row>
28609 <row topline="true">
28610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28611 \begin_inset Text
28612
28613 \begin_layout Standard
28614 uCsim
28615 \begin_inset LatexCommand \index{uCsim}
28616
28617 \end_inset
28618
28619  Software simulator for microcontrollers
28620 \end_layout
28621
28622 \end_inset
28623 </cell>
28624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28625 \begin_inset Text
28626
28627 \begin_layout Standard
28628
28629 \family roman
28630 \series medium
28631 \shape up
28632 \size normal
28633 \emph off
28634 \bar no
28635 \noun off
28636 \color none
28637 sdcc/sim/ucsim/doc
28638 \family default
28639 \series default
28640 \shape default
28641 \size default
28642 \emph default
28643 \bar default
28644 \noun default
28645 /index.html 
28646 \emph on
28647 \InsetSpace ~
28648 \InsetSpace ~
28649 \InsetSpace ~
28650
28651 \hfill
28652 online at:
28653 \emph default
28654
28655 \newline
28656
28657 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
28658
28659 \end_inset
28660
28661
28662 \end_layout
28663
28664 \end_inset
28665 </cell>
28666 </row>
28667 <row topline="true">
28668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28669 \begin_inset Text
28670
28671 \begin_layout Standard
28672 Temporary notes on the pic16
28673 \begin_inset LatexCommand \index{PIC16}
28674
28675 \end_inset
28676
28677  port
28678 \end_layout
28679
28680 \end_inset
28681 </cell>
28682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28683 \begin_inset Text
28684
28685 \begin_layout Standard
28686 sdcc/src/pic16/NOTES 
28687 \emph on
28688 \InsetSpace ~
28689 \InsetSpace ~
28690 \InsetSpace ~
28691
28692 \hfill
28693 online at:
28694 \newline
28695
28696 \emph default
28697
28698 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
28699
28700 \end_inset
28701
28702
28703 \end_layout
28704
28705 \end_inset
28706 </cell>
28707 </row>
28708 <row topline="true" bottomline="true">
28709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28710 \begin_inset Text
28711
28712 \begin_layout Standard
28713 SDCC internal documentation (debugging file format)
28714 \end_layout
28715
28716 \end_inset
28717 </cell>
28718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28719 \begin_inset Text
28720
28721 \begin_layout Standard
28722 sdcc/doc/
28723 \family roman
28724 \series medium
28725 \shape up
28726 \size normal
28727 \emph off
28728 \bar no
28729 \noun off
28730 \color none
28731 cdbfileformat.pd
28732 \family default
28733 \series default
28734 \shape default
28735 \size default
28736 \emph default
28737 \bar default
28738 \noun default
28739 f
28740 \emph on
28741  \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744
28745 \hfill
28746 online at:
28747 \emph default
28748
28749 \newline
28750
28751 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
28752
28753 \end_inset
28754
28755
28756 \end_layout
28757
28758 \end_inset
28759 </cell>
28760 </row>
28761 </lyxtabular>
28762
28763 \end_inset
28764
28765
28766 \newline
28767
28768 \end_layout
28769
28770 \begin_layout Section
28771 Related open source tools
28772 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
28773
28774 \end_inset
28775
28776
28777 \begin_inset LatexCommand \index{Related tools}
28778
28779 \end_inset
28780
28781
28782 \end_layout
28783
28784 \begin_layout Standard
28785 \align left
28786 \begin_inset Tabular
28787 <lyxtabular version="3" rows="14" columns="3">
28788 <features>
28789 <column alignment="left" valignment="top" leftline="true" width="0pt">
28790 <column alignment="block" valignment="top" leftline="true" width="30line%">
28791 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28792 <row topline="true" bottomline="true">
28793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28794 \begin_inset Text
28795
28796 \begin_layout Standard
28797
28798 \series bold
28799 Name
28800 \end_layout
28801
28802 \end_inset
28803 </cell>
28804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28805 \begin_inset Text
28806
28807 \begin_layout Standard
28808
28809 \series bold
28810 Purpose
28811 \end_layout
28812
28813 \end_inset
28814 </cell>
28815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28816 \begin_inset Text
28817
28818 \begin_layout Standard
28819
28820 \series bold
28821 Where to get
28822 \end_layout
28823
28824 \end_inset
28825 </cell>
28826 </row>
28827 <row topline="true">
28828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28829 \begin_inset Text
28830
28831 \begin_layout Standard
28832 gpsim
28833 \begin_inset LatexCommand \index{gpsim (pic simulator)}
28834
28835 \end_inset
28836
28837
28838 \end_layout
28839
28840 \end_inset
28841 </cell>
28842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28843 \begin_inset Text
28844
28845 \begin_layout Standard
28846 PIC simulator
28847 \end_layout
28848
28849 \end_inset
28850 </cell>
28851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28852 \begin_inset Text
28853
28854 \begin_layout Standard
28855 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
28856
28857 \end_inset
28858
28859
28860 \end_layout
28861
28862 \end_inset
28863 </cell>
28864 </row>
28865 <row topline="true">
28866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28867 \begin_inset Text
28868
28869 \begin_layout Standard
28870 gputils
28871 \begin_inset LatexCommand \index{gputils (pic tools)}
28872
28873 \end_inset
28874
28875
28876 \end_layout
28877
28878 \end_inset
28879 </cell>
28880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28881 \begin_inset Text
28882
28883 \begin_layout Standard
28884 GNU PIC utilities
28885 \end_layout
28886
28887 \end_inset
28888 </cell>
28889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28890 \begin_inset Text
28891
28892 \begin_layout Standard
28893 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
28894
28895 \end_inset
28896
28897
28898 \end_layout
28899
28900 \end_inset
28901 </cell>
28902 </row>
28903 <row topline="true">
28904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28905 \begin_inset Text
28906
28907 \begin_layout Standard
28908 flP5
28909 \end_layout
28910
28911 \end_inset
28912 </cell>
28913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28914 \begin_inset Text
28915
28916 \begin_layout Standard
28917 PIC programmer
28918 \end_layout
28919
28920 \end_inset
28921 </cell>
28922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28923 \begin_inset Text
28924
28925 \begin_layout Standard
28926 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
28927
28928 \end_inset
28929
28930
28931 \end_layout
28932
28933 \end_inset
28934 </cell>
28935 </row>
28936 <row topline="true">
28937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28938 \begin_inset Text
28939
28940 \begin_layout Standard
28941 ec2drv/newcdb
28942 \end_layout
28943
28944 \end_inset
28945 </cell>
28946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28947 \begin_inset Text
28948
28949 \begin_layout Standard
28950 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
28951  (Unix only)
28952 \end_layout
28953
28954 \end_inset
28955 </cell>
28956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28957 \begin_inset Text
28958
28959 \begin_layout Standard
28960 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
28961
28962 \end_inset
28963
28964
28965 \end_layout
28966
28967 \end_inset
28968 </cell>
28969 </row>
28970 <row topline="true">
28971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28972 \begin_inset Text
28973
28974 \begin_layout Standard
28975 indent
28976 \begin_inset LatexCommand \index{indent (source formatting tool)}
28977
28978 \end_inset
28979
28980
28981 \end_layout
28982
28983 \end_inset
28984 </cell>
28985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28986 \begin_inset Text
28987
28988 \begin_layout Standard
28989 Formats C source - Master of the white spaces
28990 \end_layout
28991
28992 \end_inset
28993 </cell>
28994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28995 \begin_inset Text
28996
28997 \begin_layout Standard
28998 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
28999
29000 \end_inset
29001
29002
29003 \end_layout
29004
29005 \end_inset
29006 </cell>
29007 </row>
29008 <row topline="true">
29009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29010 \begin_inset Text
29011
29012 \begin_layout Standard
29013 srecord
29014 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
29015
29016 \end_inset
29017
29018
29019 \end_layout
29020
29021 \end_inset
29022 </cell>
29023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29024 \begin_inset Text
29025
29026 \begin_layout Standard
29027 Object file conversion, checksumming, ...
29028 \end_layout
29029
29030 \end_inset
29031 </cell>
29032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29033 \begin_inset Text
29034
29035 \begin_layout Standard
29036 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
29037
29038 \end_inset
29039
29040
29041 \end_layout
29042
29043 \end_inset
29044 </cell>
29045 </row>
29046 <row topline="true">
29047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29048 \begin_inset Text
29049
29050 \begin_layout Standard
29051 objdump
29052 \begin_inset LatexCommand \index{objdump (tool)}
29053
29054 \end_inset
29055
29056
29057 \end_layout
29058
29059 \end_inset
29060 </cell>
29061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29062 \begin_inset Text
29063
29064 \begin_layout Standard
29065 Object file conversion, ...
29066 \end_layout
29067
29068 \end_inset
29069 </cell>
29070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29071 \begin_inset Text
29072
29073 \begin_layout Standard
29074 Part of binutils (should be there anyway)
29075 \end_layout
29076
29077 \end_inset
29078 </cell>
29079 </row>
29080 <row topline="true">
29081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29082 \begin_inset Text
29083
29084 \begin_layout Standard
29085 cmon51
29086 \end_layout
29087
29088 \end_inset
29089 </cell>
29090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29091 \begin_inset Text
29092
29093 \begin_layout Standard
29094 8051 monitor (hex up-/download, single step, disassemble)
29095 \end_layout
29096
29097 \end_inset
29098 </cell>
29099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29100 \begin_inset Text
29101
29102 \begin_layout Standard
29103 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
29104
29105 \end_inset
29106
29107
29108 \end_layout
29109
29110 \end_inset
29111 </cell>
29112 </row>
29113 <row topline="true">
29114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29115 \begin_inset Text
29116
29117 \begin_layout Standard
29118 doxygen
29119 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
29120
29121 \end_inset
29122
29123
29124 \end_layout
29125
29126 \end_inset
29127 </cell>
29128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29129 \begin_inset Text
29130
29131 \begin_layout Standard
29132 Source code documentation system
29133 \end_layout
29134
29135 \end_inset
29136 </cell>
29137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29138 \begin_inset Text
29139
29140 \begin_layout Standard
29141 \begin_inset LatexCommand \url{http://www.doxygen.org}
29142
29143 \end_inset
29144
29145
29146 \end_layout
29147
29148 \end_inset
29149 </cell>
29150 </row>
29151 <row topline="true">
29152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29153 \begin_inset Text
29154
29155 \begin_layout Standard
29156 kdevelop
29157 \end_layout
29158
29159 \end_inset
29160 </cell>
29161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29162 \begin_inset Text
29163
29164 \begin_layout Standard
29165 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
29166 \end_layout
29167
29168 \end_inset
29169 </cell>
29170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29171 \begin_inset Text
29172
29173 \begin_layout Standard
29174 \begin_inset LatexCommand \url{http://www.kdevelop.org}
29175
29176 \end_inset
29177
29178
29179 \end_layout
29180
29181 \end_inset
29182 </cell>
29183 </row>
29184 <row topline="true">
29185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29186 \begin_inset Text
29187
29188 \begin_layout Standard
29189 paulmon
29190 \end_layout
29191
29192 \end_inset
29193 </cell>
29194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29195 \begin_inset Text
29196
29197 \begin_layout Standard
29198 8051 monitor (hex up-/download, single step, disassemble)
29199 \end_layout
29200
29201 \end_inset
29202 </cell>
29203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29204 \begin_inset Text
29205
29206 \begin_layout Standard
29207 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
29208
29209 \end_inset
29210
29211
29212 \end_layout
29213
29214 \end_inset
29215 </cell>
29216 </row>
29217 <row topline="true">
29218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29219 \begin_inset Text
29220
29221 \begin_layout Standard
29222 splint
29223 \begin_inset LatexCommand \index{splint (syntax checking tool)}
29224
29225 \end_inset
29226
29227
29228 \end_layout
29229
29230 \end_inset
29231 </cell>
29232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29233 \begin_inset Text
29234
29235 \begin_layout Standard
29236 Statically checks c sources (see 
29237 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
29238
29239 \end_inset
29240
29241 )
29242 \end_layout
29243
29244 \end_inset
29245 </cell>
29246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29247 \begin_inset Text
29248
29249 \begin_layout Standard
29250 \begin_inset LatexCommand \url{http://www.splint.org}
29251
29252 \end_inset
29253
29254
29255 \end_layout
29256
29257 \end_inset
29258 </cell>
29259 </row>
29260 <row topline="true" bottomline="true">
29261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29262 \begin_inset Text
29263
29264 \begin_layout Standard
29265 ddd
29266 \begin_inset LatexCommand \index{DDD (debugger)}
29267
29268 \end_inset
29269
29270
29271 \end_layout
29272
29273 \end_inset
29274 </cell>
29275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29276 \begin_inset Text
29277
29278 \begin_layout Standard
29279 Debugger, serves nicely as GUI to SDCDB
29280 \begin_inset LatexCommand \index{SDCDB (debugger)}
29281
29282 \end_inset
29283
29284  (Unix only)
29285 \end_layout
29286
29287 \end_inset
29288 </cell>
29289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29290 \begin_inset Text
29291
29292 \begin_layout Standard
29293 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
29294
29295 \end_inset
29296
29297
29298 \end_layout
29299
29300 \end_inset
29301 </cell>
29302 </row>
29303 </lyxtabular>
29304
29305 \end_inset
29306
29307
29308 \newline
29309
29310 \end_layout
29311
29312 \begin_layout Section
29313 Related documentation / recommended reading
29314 \end_layout
29315
29316 \begin_layout Standard
29317 \align left
29318 \begin_inset Tabular
29319 <lyxtabular version="3" rows="7" columns="3">
29320 <features>
29321 <column alignment="left" valignment="top" leftline="true" width="0pt">
29322 <column alignment="left" valignment="top" leftline="true" width="0">
29323 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29324 <row topline="true" bottomline="true">
29325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29326 \begin_inset Text
29327
29328 \begin_layout Standard
29329
29330 \series bold
29331 Name
29332 \end_layout
29333
29334 \end_inset
29335 </cell>
29336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29337 \begin_inset Text
29338
29339 \begin_layout Standard
29340
29341 \series bold
29342 Subject / Title
29343 \end_layout
29344
29345 \end_inset
29346 </cell>
29347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29348 \begin_inset Text
29349
29350 \begin_layout Standard
29351
29352 \series bold
29353 Where to get
29354 \end_layout
29355
29356 \end_inset
29357 </cell>
29358 </row>
29359 <row topline="true">
29360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29361 \begin_inset Text
29362
29363 \begin_layout Standard
29364
29365 \family roman
29366 \series medium
29367 \shape up
29368 \size normal
29369 \emph off
29370 \bar no
29371 \noun off
29372 \color none
29373 c-refcard.pdf
29374 \end_layout
29375
29376 \end_inset
29377 </cell>
29378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29379 \begin_inset Text
29380
29381 \begin_layout Standard
29382 C Reference Card
29383 \begin_inset LatexCommand \index{C Reference card}
29384
29385 \end_inset
29386
29387 , 2 pages
29388 \end_layout
29389
29390 \end_inset
29391 </cell>
29392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29393 \begin_inset Text
29394
29395 \begin_layout Standard
29396 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
29397
29398 \end_inset
29399
29400
29401 \end_layout
29402
29403 \end_inset
29404 </cell>
29405 </row>
29406 <row topline="true">
29407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29408 \begin_inset Text
29409
29410 \begin_layout Standard
29411 c-faq
29412 \end_layout
29413
29414 \end_inset
29415 </cell>
29416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29417 \begin_inset Text
29418
29419 \begin_layout Standard
29420 C-FAQ
29421 \begin_inset LatexCommand \index{C FAQ}
29422
29423 \end_inset
29424
29425
29426 \end_layout
29427
29428 \end_inset
29429 </cell>
29430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29431 \begin_inset Text
29432
29433 \begin_layout Standard
29434 \begin_inset LatexCommand \url{http://www.c-faq.com}
29435
29436 \end_inset
29437
29438
29439 \end_layout
29440
29441 \end_inset
29442 </cell>
29443 </row>
29444 <row topline="true">
29445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29446 \begin_inset Text
29447
29448 \begin_layout Standard
29449 ISO/IEC 9899:TC2
29450 \end_layout
29451
29452 \end_inset
29453 </cell>
29454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29455 \begin_inset Text
29456
29457 \begin_layout Standard
29458 \begin_inset Quotes sld
29459 \end_inset
29460
29461 C-Standard
29462 \begin_inset Quotes srd
29463 \end_inset
29464
29465
29466 \end_layout
29467
29468 \end_inset
29469 </cell>
29470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29471 \begin_inset Text
29472
29473 \begin_layout Standard
29474
29475 \size footnotesize
29476 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29477
29478 \end_inset
29479
29480
29481 \end_layout
29482
29483 \end_inset
29484 </cell>
29485 </row>
29486 <row topline="true">
29487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29488 \begin_inset Text
29489
29490 \begin_layout Standard
29491 ISO/IEC DTR 18037
29492 \end_layout
29493
29494 \end_inset
29495 </cell>
29496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29497 \begin_inset Text
29498
29499 \begin_layout Standard
29500 \begin_inset Quotes sld
29501 \end_inset
29502
29503 Extensions for Embedded C
29504 \begin_inset Quotes srd
29505 \end_inset
29506
29507
29508 \end_layout
29509
29510 \end_inset
29511 </cell>
29512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29513 \begin_inset Text
29514
29515 \begin_layout Standard
29516
29517 \size footnotesize
29518 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
29519
29520 \end_inset
29521
29522
29523 \end_layout
29524
29525 \end_inset
29526 </cell>
29527 </row>
29528 <row topline="true">
29529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29530 \begin_inset Text
29531
29532 \begin_layout Standard
29533
29534 \end_layout
29535
29536 \end_inset
29537 </cell>
29538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29539 \begin_inset Text
29540
29541 \begin_layout Standard
29542 Latest datasheet of target CPU
29543 \end_layout
29544
29545 \end_inset
29546 </cell>
29547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29548 \begin_inset Text
29549
29550 \begin_layout Standard
29551 vendor
29552 \end_layout
29553
29554 \end_inset
29555 </cell>
29556 </row>
29557 <row topline="true" bottomline="true">
29558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29559 \begin_inset Text
29560
29561 \begin_layout Standard
29562
29563 \end_layout
29564
29565 \end_inset
29566 </cell>
29567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29568 \begin_inset Text
29569
29570 \begin_layout Standard
29571 Revision history of datasheet
29572 \end_layout
29573
29574 \end_inset
29575 </cell>
29576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29577 \begin_inset Text
29578
29579 \begin_layout Standard
29580 vendor
29581 \end_layout
29582
29583 \end_inset
29584 </cell>
29585 </row>
29586 </lyxtabular>
29587
29588 \end_inset
29589
29590
29591 \newline
29592
29593 \end_layout
29594
29595 \begin_layout Section
29596 Application notes specifically for SDCC
29597 \end_layout
29598
29599 \begin_layout Standard
29600 SDCC makes no claims about the completeness of this list and about up-to-datenes
29601 s or correctness of the application notes
29602 \begin_inset LatexCommand \index{Application notes}
29603
29604 \end_inset
29605
29606 .
29607 \end_layout
29608
29609 \begin_layout Standard
29610 \align left
29611
29612 \size footnotesize
29613 \begin_inset Tabular
29614 <lyxtabular version="3" rows="7" columns="3">
29615 <features>
29616 <column alignment="block" valignment="top" leftline="true" width="17col%">
29617 <column alignment="block" valignment="top" leftline="true" width="27col%">
29618 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
29619 <row topline="true" bottomline="true">
29620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29621 \begin_inset Text
29622
29623 \begin_layout Standard
29624
29625 \series bold
29626 \size footnotesize
29627 Vendor
29628 \end_layout
29629
29630 \end_inset
29631 </cell>
29632 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
29633 \begin_inset Text
29634
29635 \begin_layout Standard
29636
29637 \series bold
29638 \size footnotesize
29639 Subject / Title
29640 \end_layout
29641
29642 \end_inset
29643 </cell>
29644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29645 \begin_inset Text
29646
29647 \begin_layout Standard
29648
29649 \series bold
29650 \size footnotesize
29651 Where to get
29652 \end_layout
29653
29654 \end_inset
29655 </cell>
29656 </row>
29657 <row topline="true">
29658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29659 \begin_inset Text
29660
29661 \begin_layout Standard
29662
29663 \size footnotesize
29664 Maxim / Dallas
29665 \end_layout
29666
29667 \end_inset
29668 </cell>
29669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29670 \begin_inset Text
29671
29672 \begin_layout Standard
29673
29674 \size footnotesize
29675 Using the SDCC Compiler for the DS80C400
29676 \begin_inset LatexCommand \index{DS80C400}
29677
29678 \end_inset
29679
29680
29681 \end_layout
29682
29683 \end_inset
29684 </cell>
29685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29686 \begin_inset Text
29687
29688 \begin_layout Standard
29689
29690 \size footnotesize
29691 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
29692
29693 \end_inset
29694
29695
29696 \end_layout
29697
29698 \end_inset
29699 </cell>
29700 </row>
29701 <row topline="true">
29702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29703 \begin_inset Text
29704
29705 \begin_layout Standard
29706
29707 \size footnotesize
29708 Maxim / Dallas
29709 \end_layout
29710
29711 \end_inset
29712 </cell>
29713 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
29714 \begin_inset Text
29715
29716 \begin_layout Standard
29717
29718 \size footnotesize
29719 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
29720 \begin_inset LatexCommand \index{DS89C4x0}
29721
29722 \end_inset
29723
29724  Family of Microcontrollers
29725 \end_layout
29726
29727 \end_inset
29728 </cell>
29729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29730 \begin_inset Text
29731
29732 \begin_layout Standard
29733
29734 \size footnotesize
29735 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
29736
29737 \end_inset
29738
29739
29740 \end_layout
29741
29742 \end_inset
29743 </cell>
29744 </row>
29745 <row topline="true">
29746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29747 \begin_inset Text
29748
29749 \begin_layout Standard
29750
29751 \size footnotesize
29752 Silicon Laboratories / Cygnal
29753 \end_layout
29754
29755 \end_inset
29756 </cell>
29757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29758 \begin_inset Text
29759
29760 \begin_layout Standard
29761
29762 \size footnotesize
29763 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
29764 \begin_inset LatexCommand \index{IDE}
29765
29766 \end_inset
29767
29768
29769 \end_layout
29770
29771 \end_inset
29772 </cell>
29773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29774 \begin_inset Text
29775
29776 \begin_layout Standard
29777
29778 \size footnotesize
29779 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
29780
29781 \end_inset
29782
29783
29784 \end_layout
29785
29786 \end_inset
29787 </cell>
29788 </row>
29789 <row topline="true">
29790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29791 \begin_inset Text
29792
29793 \begin_layout Standard
29794
29795 \size footnotesize
29796 Ramtron / Goal Semiconductor
29797 \end_layout
29798
29799 \end_inset
29800 </cell>
29801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29802 \begin_inset Text
29803
29804 \begin_layout Standard
29805
29806 \size footnotesize
29807 Interfacing SDCC to Syn and Textpad
29808 \end_layout
29809
29810 \end_inset
29811 </cell>
29812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29813 \begin_inset Text
29814
29815 \begin_layout Standard
29816
29817 \size footnotesize
29818 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
29819
29820 \end_inset
29821
29822
29823 \end_layout
29824
29825 \end_inset
29826 </cell>
29827 </row>
29828 <row topline="true">
29829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29830 \begin_inset Text
29831
29832 \begin_layout Standard
29833
29834 \size footnotesize
29835 Ramtron / Goal Semiconductor
29836 \end_layout
29837
29838 \end_inset
29839 </cell>
29840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29841 \begin_inset Text
29842
29843 \begin_layout Standard
29844
29845 \size footnotesize
29846 Installing and Configuring SDCC and Crimson Editor 
29847 \end_layout
29848
29849 \end_inset
29850 </cell>
29851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29852 \begin_inset Text
29853
29854 \begin_layout Standard
29855
29856 \size footnotesize
29857 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
29858
29859 \end_inset
29860
29861
29862 \end_layout
29863
29864 \end_inset
29865 </cell>
29866 </row>
29867 <row topline="true" bottomline="true">
29868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29869 \begin_inset Text
29870
29871 \begin_layout Standard
29872
29873 \size footnotesize
29874 Texas Instruments
29875 \end_layout
29876
29877 \end_inset
29878 </cell>
29879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29880 \begin_inset Text
29881
29882 \begin_layout Standard
29883
29884 \size footnotesize
29885 MSC12xx Programming with SDCC
29886 \end_layout
29887
29888 \end_inset
29889 </cell>
29890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29891 \begin_inset Text
29892
29893 \begin_layout Standard
29894
29895 \size footnotesize
29896 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
29897
29898 \end_inset
29899
29900
29901 \end_layout
29902
29903 \end_inset
29904 </cell>
29905 </row>
29906 </lyxtabular>
29907
29908 \end_inset
29909
29910
29911 \end_layout
29912
29913 \begin_layout Section
29914 Some Questions
29915 \end_layout
29916
29917 \begin_layout Standard
29918 Some questions answered, some pointers given - it might be time to in turn
29919  ask 
29920 \emph on
29921 you
29922 \emph default
29923  some questions: 
29924 \end_layout
29925
29926 \begin_layout Itemize
29927 can you solve your project with the selected microcontroller? Would you
29928  find out early or rather late that your target is too small/slow/whatever?
29929  Can you switch to a slightly better device if it doesn't fit?
29930 \end_layout
29931
29932 \begin_layout Itemize
29933 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
29934  and/or another programming language be more adequate? Would an operating
29935  system on the target device help?
29936 \end_layout
29937
29938 \begin_layout Itemize
29939 if you solved the problem, will the marketing department be happy?
29940 \end_layout
29941
29942 \begin_layout Itemize
29943 if the marketing department is happy, will customers be happy?
29944 \end_layout
29945
29946 \begin_layout Itemize
29947 if you're the project manager, marketing department and maybe even the customer
29948  in one person, have you tried to see the project from the outside?
29949 \end_layout
29950
29951 \begin_layout Itemize
29952 is the project done if you think it is done? Or is just that other interface/pro
29953 tocol/feature/configuration/option missing? How about website, manual(s),
29954  internationali(z|s)ation, packaging, labels, 2nd source for components,
29955  electromagnetic compatability/interference, documentation for production,
29956  production test software, update mechanism, patent issues?
29957 \end_layout
29958
29959 \begin_layout Itemize
29960 is your project adequately positioned in that magic triangle: fame, fortune,
29961  fun?
29962 \end_layout
29963
29964 \begin_layout Standard
29965 Maybe not all answers to these questions are known and some answers may
29966  even be 
29967 \emph on
29968 no
29969 \emph default
29970 , nevertheless knowing these questions may help you to avoid burnout
29971 \begin_inset Foot
29972 status open
29973
29974 \begin_layout Standard
29975 burnout is bad for electronic devices, programmers and motorcycle tyres
29976 \end_layout
29977
29978 \end_inset
29979
29980 .
29981  Chances are you didn't want to hear some of them...
29982 \end_layout
29983
29984 \begin_layout Chapter
29985 Support
29986 \begin_inset LatexCommand \index{Support}
29987
29988 \end_inset
29989
29990
29991 \end_layout
29992
29993 \begin_layout Standard
29994 SDCC has grown to be a large project.
29995  The compiler alone (without the preprocessor, assembler and linker) is
29996  well over 150,000 lines of code (blank stripped).
29997  The open source nature of this project is a key to its continued growth
29998  and support.
29999  You gain the benefit and support of many active software developers and
30000  end users.
30001  Is SDCC perfect? No, that's why we need your help.
30002  The developers take pride in fixing reported bugs.
30003  You can help by reporting the bugs and helping other SDCC users.
30004  There are lots of ways to contribute, and we encourage you to take part
30005  in making SDCC a great software package.
30006  
30007 \end_layout
30008
30009 \begin_layout Standard
30010 The SDCC project is hosted on the SDCC sourceforge site at 
30011 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
30012
30013 \end_inset
30014
30015 .
30016  You'll find the complete set of mailing lists
30017 \begin_inset LatexCommand \index{Mailing list(s)}
30018
30019 \end_inset
30020
30021 , forums, bug reporting system, patch submission
30022 \begin_inset LatexCommand \index{Patch submission}
30023
30024 \end_inset
30025
30026  system, download
30027 \begin_inset LatexCommand \index{download}
30028
30029 \end_inset
30030
30031  area and Subversion code repository
30032 \begin_inset LatexCommand \index{Subversion code repository}
30033
30034 \end_inset
30035
30036  there.
30037 \end_layout
30038
30039 \begin_layout Section
30040 Reporting Bugs
30041 \begin_inset LatexCommand \index{Bug reporting}
30042
30043 \end_inset
30044
30045
30046 \begin_inset LatexCommand \index{Reporting bugs}
30047
30048 \end_inset
30049
30050
30051 \end_layout
30052
30053 \begin_layout Standard
30054 The recommended way of reporting bugs is using the infrastructure of the
30055  sourceforge site.
30056  You can follow the status of bug reports there and have an overview about
30057  the known bugs.
30058 \end_layout
30059
30060 \begin_layout Standard
30061 Bug reports are automatically forwarded to the developer mailing list and
30062  will be fixed ASAP.
30063  When reporting a bug, it is very useful to include a small test program
30064  (the smaller the better) which reproduces the problem.
30065  If you can isolate the problem by looking at the generated assembly code,
30066  this can be very helpful.
30067  Compiling your program with the -
30068 \begin_inset ERT
30069 status collapsed
30070
30071 \begin_layout Standard
30072
30073
30074 \backslash
30075 /
30076 \end_layout
30077
30078 \end_inset
30079
30080 -dumpall
30081 \begin_inset LatexCommand \index{-\/-dumpall}
30082
30083 \end_inset
30084
30085  option can sometimes be useful in locating optimization problems.
30086  When reporting a bug please make sure you:
30087 \end_layout
30088
30089 \begin_layout Enumerate
30090 Attach the code you are compiling with SDCC.
30091  
30092 \end_layout
30093
30094 \begin_layout Enumerate
30095 Specify the exact command you use to run SDCC, or attach your Makefile.
30096  
30097 \end_layout
30098
30099 \begin_layout Enumerate
30100 Specify the SDCC version (type "
30101 \family sans
30102 \series bold
30103 sdcc -v
30104 \family default
30105 \series default
30106 "), your platform, and operating system.
30107  
30108 \end_layout
30109
30110 \begin_layout Enumerate
30111 Provide an exact copy of any error message or incorrect output.
30112  
30113 \end_layout
30114
30115 \begin_layout Enumerate
30116 Put something meaningful in the subject of your message.
30117 \end_layout
30118
30119 \begin_layout Standard
30120 Please attempt to include these 5 important parts, as applicable, in all
30121  requests for support or when reporting any problems or bugs with SDCC.
30122  Though this will make your message lengthy, it will greatly improve your
30123  chance that SDCC users and developers will be able to help you.
30124  Some SDCC developers are frustrated by bug reports without code provided
30125  that they can use to reproduce and ultimately fix the problem, so please
30126  be sure to provide sample code if you are reporting a bug! 
30127 \end_layout
30128
30129 \begin_layout Standard
30130 Please have a short check that you are using a recent version of SDCC and
30131  the bug is not yet known.
30132  This is the link for reporting bugs: 
30133 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
30134
30135 \end_inset
30136
30137 .
30138  With SDCC on average having more than 200 downloads
30139 \begin_inset LatexCommand \index{download}
30140
30141 \end_inset
30142
30143  on sourceforge per day
30144 \begin_inset Foot
30145 status open
30146
30147 \begin_layout Standard
30148 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
30149  between 2002 and 2005.
30150  This does not include other methods of distribution.
30151 \end_layout
30152
30153 \end_inset
30154
30155  there must be some users.
30156  So it's not exactly easy to find a new bug.
30157  If you find one we need it: 
30158 \emph on
30159 reporting bugs is good
30160 \emph default
30161 .
30162 \end_layout
30163
30164 \begin_layout Section
30165 Requesting Features
30166 \begin_inset LatexCommand \label{sub:Requesting-Features}
30167
30168 \end_inset
30169
30170
30171 \begin_inset LatexCommand \index{Feature request}
30172
30173 \end_inset
30174
30175
30176 \begin_inset LatexCommand \index{Requesting features}
30177
30178 \end_inset
30179
30180
30181 \end_layout
30182
30183 \begin_layout Standard
30184 Like bug reports feature requests are forwarded to the developer mailing
30185  list.
30186  This is the link for requesting features: 
30187 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
30188
30189 \end_inset
30190
30191 .
30192 \end_layout
30193
30194 \begin_layout Section
30195 Submitting patches
30196 \end_layout
30197
30198 \begin_layout Standard
30199 Like bug reports contributed patches are forwarded to the developer mailing
30200  list.
30201  This is the link for submitting patches
30202 \begin_inset LatexCommand \index{Patch submission}
30203
30204 \end_inset
30205
30206
30207 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
30208
30209 \end_inset
30210
30211 .
30212 \end_layout
30213
30214 \begin_layout Standard
30215 You need to specify some parameters to the 
30216 \family typewriter
30217 diff
30218 \family default
30219  command for the patches to be useful.
30220  If you modified more than one file a patch created f.e.
30221  with 
30222 \family sans
30223 \series bold
30224
30225 \begin_inset Quotes sld
30226 \end_inset
30227
30228 diff -Naur unmodified_directory modified_directory >my_changes.patch
30229 \begin_inset Quotes srd
30230 \end_inset
30231
30232
30233 \family default
30234 \series default
30235  will be fine, otherwise 
30236 \family sans
30237 \series bold
30238
30239 \begin_inset Quotes sld
30240 \end_inset
30241
30242 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
30243 \begin_inset Quotes srd
30244 \end_inset
30245
30246
30247 \series default
30248  
30249 \family default
30250 will do.
30251 \end_layout
30252
30253 \begin_layout Section
30254 Getting Help
30255 \end_layout
30256
30257 \begin_layout Standard
30258 These links should take you directly to the 
30259 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
30260
30261 \end_inset
30262
30263
30264 \begin_inset Foot
30265 status open
30266
30267 \begin_layout Standard
30268 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
30269  automated messages (mid 2003)
30270 \end_layout
30271
30272 \end_inset
30273
30274  and the 
30275 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
30276
30277 \end_inset
30278
30279 , lists
30280 \begin_inset LatexCommand \index{Mailing list(s)}
30281
30282 \end_inset
30283
30284  and forums are archived and searchable so if you are lucky someone already
30285  had a similar problem.
30286  While mails to the lists themselves are delivered promptly their web front
30287  end on sourceforge sometimes shows a severe time lag (up to several weeks),
30288  if you're seriously using SDCC please consider subscribing to the lists.
30289 \end_layout
30290
30291 \begin_layout Section
30292 ChangeLog
30293 \end_layout
30294
30295 \begin_layout Standard
30296 You can follow the status of the Subversion version
30297 \begin_inset LatexCommand \index{version}
30298
30299 \end_inset
30300
30301  of SDCC by watching the Changelog
30302 \begin_inset LatexCommand \index{Changelog}
30303
30304 \end_inset
30305
30306  in the Subversion repository
30307 \size footnotesize
30308  
30309 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30310
30311 \end_inset
30312
30313 .
30314 \end_layout
30315
30316 \begin_layout Section
30317 Subversion Source Code Repository
30318 \end_layout
30319
30320 \begin_layout Standard
30321 The output of 
30322 \family sans
30323 \series bold
30324 sdcc --version
30325 \family default
30326 \series default
30327  or the filenames of the snapshot versions of SDCC include date and its
30328  Subversion
30329 \begin_inset LatexCommand \index{Subversion code repository}
30330
30331 \end_inset
30332
30333  number.
30334  Subversion allows to download the source of recent or previous versions
30335  
30336 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
30337
30338 \end_inset
30339
30340  (by number or by date).
30341  An on-line source code browser and detailled instructions are also available
30342  there.
30343  SDCC versions starting from 1999 up to now are available (currently the
30344  versions prior to the conversion from cvs
30345 \begin_inset LatexCommand \index{cvs|see{Subversion}}
30346
30347 \end_inset
30348
30349  to Subversion (April 2006) are either by accessible by Subversion or by
30350  cvs).
30351 \end_layout
30352
30353 \begin_layout Section
30354 Release policy
30355 \begin_inset LatexCommand \index{Release policy}
30356
30357 \end_inset
30358
30359
30360 \end_layout
30361
30362 \begin_layout Standard
30363 Historically there often were long delays between official releases and
30364  the sourceforge download area tends to get not updated at all.
30365  Excuses in the past might have referred to problems with live range analysis,
30366  but as this was fixed a while ago, the current problem is that another
30367  excuse has to be found.
30368  Kidding aside, we have to get better there! On the other hand there are
30369  daily snapshots available at 
30370 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
30371
30372 \end_inset
30373
30374 , and you can always build the very last version (hopefully with many bugs
30375  fixed, and features added) from the source code available at 
30376 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
30377
30378 \end_inset
30379
30380 .
30381  A release wiki
30382 \begin_inset LatexCommand \index{wiki}
30383
30384 \end_inset
30385
30386
30387 \begin_inset LatexCommand \index{Release wiki}
30388
30389 \end_inset
30390
30391  at 
30392 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
30393
30394 \end_inset
30395
30396  also holds some information about past and future releases.
30397 \end_layout
30398
30399 \begin_layout Section
30400 Examples
30401 \begin_inset LatexCommand \index{Examples}
30402
30403 \end_inset
30404
30405
30406 \end_layout
30407
30408 \begin_layout Standard
30409 You'll find some small examples in the directory 
30410 \emph on
30411 sdcc/device/examples/.
30412  
30413 \emph default
30414 More examples and libraries are available at
30415 \emph on
30416  The SDCC Open Knowledge Resource 
30417 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
30418
30419 \end_inset
30420
30421  
30422 \emph default
30423 web site or at 
30424 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
30425
30426 \end_inset
30427
30428 .
30429 \end_layout
30430
30431 \begin_layout Standard
30432 \begin_inset Note Comment
30433 status collapsed
30434
30435 \begin_layout Standard
30436 I did insert a reference to Paul's web site here although it seems rather
30437  dedicated to a specific 8032 board (I think it's okay because it f.e.
30438  shows LCD/Harddisc interface and has a free 8051 monitor.
30439  Independent 8032 board vendors face hard competition of heavily subsidized
30440  development boards anyway).
30441 \end_layout
30442
30443 \begin_layout Standard
30444 Maybe we should include some links to real world applications.
30445  Preferably pointer to pointers (one for each architecture) so this stays
30446  manageable here?
30447 \end_layout
30448
30449 \end_inset
30450
30451
30452 \end_layout
30453
30454 \begin_layout Section
30455 Quality control
30456 \begin_inset LatexCommand \label{sec:Quality-control}
30457
30458 \end_inset
30459
30460
30461 \begin_inset LatexCommand \index{Quality control}
30462
30463 \end_inset
30464
30465
30466 \end_layout
30467
30468 \begin_layout Standard
30469 The compiler is passed through nightly compile and build checks.
30470  The so called 
30471 \shape italic
30472 regression tests
30473 \shape default
30474
30475 \begin_inset LatexCommand \index{Regression test}
30476
30477 \end_inset
30478
30479  check that SDCC itself compiles flawlessly on several host platforms (i386,
30480  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
30481  the quality of the code generated by SDCC by running the code for several
30482  target platforms through simulators.
30483  The regression test suite comprises more than 100 files which expand to
30484  more than 500 test cases which include more than 4500 tests.
30485  The results of these tests are published daily on SDCC's snapshot page
30486  (click on the red or green symbols on the right side of 
30487 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
30488
30489 \end_inset
30490
30491 ).
30492 \end_layout
30493
30494 \begin_layout Standard
30495 There is a separate document 
30496 \shape italic
30497 test_suite.pdf 
30498 \begin_inset LatexCommand \index{Test suite}
30499
30500 \end_inset
30501
30502
30503 \shape default
30504  
30505 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30506
30507 \end_inset
30508
30509  about the regression test suite.
30510 \end_layout
30511
30512 \begin_layout Standard
30513 You'll find the test code in the directory 
30514 \shape italic
30515 sdcc/support/regression
30516 \shape default
30517 .
30518  You can run these tests manually by running 
30519 \family sans
30520 make
30521 \family default
30522  in this directory (or f.e.
30523  
30524 \family sans
30525 \series bold
30526
30527 \begin_inset Quotes sld
30528 \end_inset
30529
30530 make test-mcs51
30531 \begin_inset Quotes srd
30532 \end_inset
30533
30534
30535 \family default
30536 \series default
30537  if you don't want to run the complete tests).
30538  The test code might also be interesting if you want to look for examples
30539 \begin_inset LatexCommand \index{Examples}
30540
30541 \end_inset
30542
30543  checking corner cases of SDCC or if you plan to submit patches
30544 \begin_inset LatexCommand \index{Patch submission}
30545
30546 \end_inset
30547
30548 .
30549 \end_layout
30550
30551 \begin_layout Standard
30552 The 14bit pic port uses a different set of regression tests 
30553 \begin_inset LatexCommand \index{Regression test (PIC14)}
30554
30555 \end_inset
30556
30557 , you'll find them in the directory 
30558 \shape italic
30559 sdcc/src/regression
30560 \shape default
30561 .
30562 \end_layout
30563
30564 \begin_layout Section
30565 Use of SDCC in Education
30566 \end_layout
30567
30568 \begin_layout Standard
30569 In short: 
30570 \emph on
30571 highly
30572 \emph default
30573  encouraged
30574 \begin_inset Foot
30575 status open
30576
30577 \begin_layout Standard
30578 the phrase "use in education" might evoke the association "
30579 \emph on
30580 only
30581 \emph default
30582  fit for use in education".
30583  This connotation is not intended but nevertheless risked as the licensing
30584  of SDCC makes it difficult to offer educational discounts
30585 \end_layout
30586
30587 \end_inset
30588
30589 .
30590  If your rationales are to:
30591 \end_layout
30592
30593 \begin_layout Enumerate
30594 give students a chance to understand the 
30595 \emph on
30596 complete
30597 \emph default
30598  steps of code generation
30599 \end_layout
30600
30601 \begin_layout Enumerate
30602 have a curriculum that can be extended for years.
30603  Then you could use an fpga board as target and your curriculum will seamlessly
30604  extend from logic synthesis (
30605 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
30606
30607 \end_inset
30608
30609
30610 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
30611
30612 \end_inset
30613
30614 ), over assembly programming, to C to FPGA compilers (
30615 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
30616
30617 \end_inset
30618
30619 ) and to C.
30620 \end_layout
30621
30622 \begin_layout Enumerate
30623 be able to insert excursions about skills like using a revision control
30624  system, submitting/applying patches, using a type-setting (as opposed to
30625  word-processing) engine LyX/LaTeX, using 
30626 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
30627
30628 \end_inset
30629
30630 , following some 
30631 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
30632
30633 \end_inset
30634
30635 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
30636  Source Software, CPU simulation, compiler regression tests
30637 \begin_inset LatexCommand \index{Regression test}
30638
30639 \end_inset
30640
30641 .
30642  
30643 \newline
30644 And if there should be a shortage of ideas then you can always point students
30645  to the ever-growing feature request list 
30646 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
30647
30648 \end_inset
30649
30650 .
30651 \end_layout
30652
30653 \begin_layout Enumerate
30654 not tie students to a specific host platform and instead allow them to use
30655  a host platform of 
30656 \emph on
30657 their
30658 \emph default
30659  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
30660  eventually 
30661 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
30662
30663 \end_inset
30664
30665 )
30666 \end_layout
30667
30668 \begin_layout Enumerate
30669 not encourage students to use illegal copies of educational software
30670 \end_layout
30671
30672 \begin_layout Enumerate
30673 be immune to licensing/availability/price changes of the chosen tool chain
30674 \end_layout
30675
30676 \begin_layout Enumerate
30677 be able to change to a new target platform without having to adopt a new
30678  tool chain
30679 \end_layout
30680
30681 \begin_layout Enumerate
30682 have complete control over and insight into the tool chain
30683 \end_layout
30684
30685 \begin_layout Enumerate
30686 make your students aware about the pros and cons of open source software
30687  development
30688 \end_layout
30689
30690 \begin_layout Enumerate
30691 give back to the public as you are probably at least partially publically
30692  funded
30693 \end_layout
30694
30695 \begin_layout Enumerate
30696 give students a chance to publically prove their skills and to possibly
30697  see a world wide impact
30698 \end_layout
30699
30700 \begin_layout Standard
30701 then SDCC is probably among the first choices.
30702  Well, probably SDCC might be the only choice.
30703 \end_layout
30704
30705 \begin_layout Standard
30706
30707 \newpage
30708
30709 \end_layout
30710
30711 \begin_layout Chapter
30712 SDCC Technical Data
30713 \end_layout
30714
30715 \begin_layout Section
30716 Optimizations
30717 \begin_inset LatexCommand \index{Optimizations}
30718
30719 \end_inset
30720
30721
30722 \end_layout
30723
30724 \begin_layout Standard
30725 SDCC performs a host of standard optimizations in addition to some MCU specific
30726  optimizations.
30727  
30728 \end_layout
30729
30730 \begin_layout Subsection
30731 Sub-expression Elimination
30732 \begin_inset LatexCommand \index{Subexpression elimination}
30733
30734 \end_inset
30735
30736
30737 \end_layout
30738
30739 \begin_layout Standard
30740 The compiler does local and 
30741 \emph on
30742 g
30743 \emph default
30744 lobal 
30745 \emph on
30746 c
30747 \emph default
30748 ommon 
30749 \emph on
30750 s
30751 \emph default
30752 ubexpression 
30753 \emph on
30754 e
30755 \emph default
30756 limination, e.g.: 
30757 \end_layout
30758
30759 \begin_layout Verse
30760
30761 \family typewriter
30762 i = x + y + 1; 
30763 \newline
30764 j = x + y;
30765 \end_layout
30766
30767 \begin_layout Standard
30768 will be translated to
30769 \end_layout
30770
30771 \begin_layout Verse
30772
30773 \family typewriter
30774 iTemp = x + y; 
30775 \newline
30776 i = iTemp + 1; 
30777 \newline
30778 j = iTemp;
30779 \end_layout
30780
30781 \begin_layout Standard
30782 Some subexpressions are not as obvious as the above example, e.g.:
30783 \end_layout
30784
30785 \begin_layout Verse
30786
30787 \family typewriter
30788 a->b[i].c = 10; 
30789 \newline
30790 a->b[i].d = 11;
30791 \end_layout
30792
30793 \begin_layout Standard
30794 In this case the address arithmetic a->b[i] will be computed only once;
30795  the equivalent code in C would be.
30796 \end_layout
30797
30798 \begin_layout Verse
30799
30800 \family typewriter
30801 iTemp = a->b[i]; 
30802 \newline
30803 iTemp.c = 10; 
30804 \newline
30805 iTemp.d = 11;
30806 \end_layout
30807
30808 \begin_layout Standard
30809 The compiler will try to keep these temporary variables in registers.
30810 \end_layout
30811
30812 \begin_layout Subsection
30813 Dead-Code Elimination
30814 \begin_inset LatexCommand \index{Dead-code elimination}
30815
30816 \end_inset
30817
30818
30819 \end_layout
30820
30821 \begin_layout Verse
30822
30823 \family typewriter
30824 int global;
30825 \newline
30826
30827 \newline
30828 void f () { 
30829 \newline
30830 \InsetSpace ~
30831 \InsetSpace ~
30832 int i; 
30833 \newline
30834 \InsetSpace ~
30835 \InsetSpace ~
30836 i = 1; \InsetSpace ~
30837 \InsetSpace ~
30838 \InsetSpace ~
30839 \InsetSpace ~
30840 \InsetSpace ~
30841 /* dead store */ 
30842 \newline
30843 \InsetSpace ~
30844 \InsetSpace ~
30845 global = 1;\InsetSpace ~
30846 /* dead
30847  store */ 
30848 \newline
30849 \InsetSpace ~
30850 \InsetSpace ~
30851 global = 2; 
30852 \newline
30853 \InsetSpace ~
30854 \InsetSpace ~
30855 return; 
30856 \newline
30857 \InsetSpace ~
30858 \InsetSpace ~
30859 global = 3;\InsetSpace ~
30860 /* unreachable */ 
30861 \newline
30862 }
30863 \end_layout
30864
30865 \begin_layout Standard
30866 will be changed to
30867 \end_layout
30868
30869 \begin_layout Verse
30870
30871 \family typewriter
30872 int global;
30873 \newline
30874
30875 \newline
30876 void f () {
30877 \newline
30878 \InsetSpace ~
30879 \InsetSpace ~
30880 global = 2; 
30881 \newline
30882 }
30883 \end_layout
30884
30885 \begin_layout Subsection
30886 Copy-Propagation
30887 \begin_inset LatexCommand \index{Copy propagation}
30888
30889 \end_inset
30890
30891
30892 \end_layout
30893
30894 \begin_layout Verse
30895
30896 \family typewriter
30897 int f() { 
30898 \newline
30899 \InsetSpace ~
30900 \InsetSpace ~
30901 int i, j; 
30902 \newline
30903 \InsetSpace ~
30904 \InsetSpace ~
30905 i = 10; 
30906 \newline
30907 \InsetSpace ~
30908 \InsetSpace ~
30909 j = i; 
30910 \newline
30911 \InsetSpace ~
30912 \InsetSpace ~
30913 return j; 
30914 \newline
30915 }
30916 \end_layout
30917
30918 \begin_layout Standard
30919 will be changed to 
30920 \end_layout
30921
30922 \begin_layout Verse
30923
30924 \family typewriter
30925 int f() { 
30926 \newline
30927 \InsetSpace ~
30928 \InsetSpace ~
30929 int i, j; 
30930 \newline
30931 \InsetSpace ~
30932 \InsetSpace ~
30933 i = 10; 
30934 \newline
30935 \InsetSpace ~
30936 \InsetSpace ~
30937 j = 10; 
30938 \newline
30939 \InsetSpace ~
30940 \InsetSpace ~
30941 return 10; 
30942 \newline
30943 }
30944 \end_layout
30945
30946 \begin_layout Standard
30947 Note: the dead stores created by this copy propagation will be eliminated
30948  by dead-code elimination.
30949 \end_layout
30950
30951 \begin_layout Subsection
30952 Loop Optimizations
30953 \begin_inset LatexCommand \index{Loop optimization}
30954
30955 \end_inset
30956
30957
30958 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
30959
30960 \end_inset
30961
30962
30963 \end_layout
30964
30965 \begin_layout Standard
30966 Two types of loop optimizations are done by SDCC 
30967 \emph on
30968 loop invariant
30969 \emph default
30970  lifting and
30971 \emph on
30972  strength reduction
30973 \emph default
30974  of loop induction variables.
30975  In addition to the strength reduction the optimizer marks the induction
30976  variables and the register allocator tries to keep the induction variables
30977  in registers for the duration of the loop.
30978  Because of this preference of the register allocator
30979 \begin_inset LatexCommand \index{Register allocation}
30980
30981 \end_inset
30982
30983 , loop induction optimization causes an increase in register pressure, which
30984  may cause unwanted spilling of other temporary variables into the stack
30985 \begin_inset LatexCommand \index{stack}
30986
30987 \end_inset
30988
30989  / data space.
30990  The compiler will generate a warning message when it is forced to allocate
30991  extra space either on the stack or data space.
30992  If this extra space allocation is undesirable then induction optimization
30993  can be eliminated either for the entire source file (with -
30994 \begin_inset ERT
30995 status collapsed
30996
30997 \begin_layout Standard
30998
30999
31000 \backslash
31001 /
31002 \end_layout
31003
31004 \end_inset
31005
31006 -noinduction option) or for a given function only using #pragma\InsetSpace ~
31007 noinduction
31008 \begin_inset LatexCommand \index{\#pragma noinduction}
31009
31010 \end_inset
31011
31012 .
31013 \newline
31014
31015 \newline
31016 Loop Invariant:
31017 \end_layout
31018
31019 \begin_layout Verse
31020
31021 \family typewriter
31022 for (i = 0 ; i < 100 ; i ++) 
31023 \newline
31024 \InsetSpace ~
31025 \InsetSpace ~
31026 \InsetSpace ~
31027 \InsetSpace ~
31028 f += k + l;
31029 \end_layout
31030
31031 \begin_layout Standard
31032 changed to
31033 \end_layout
31034
31035 \begin_layout Verse
31036
31037 \family typewriter
31038 itemp = k + l; 
31039 \newline
31040 for (i = 0; i < 100; i++) 
31041 \newline
31042 \InsetSpace ~
31043 \InsetSpace ~
31044 \InsetSpace ~
31045 \InsetSpace ~
31046 f += itemp;
31047 \end_layout
31048
31049 \begin_layout Standard
31050 As mentioned previously some loop invariants are not as apparent, all static
31051  address computations are also moved out of the loop.
31052 \newline
31053
31054 \newline
31055 Strength Reduction
31056 \begin_inset LatexCommand \index{Strength reduction}
31057
31058 \end_inset
31059
31060 , this optimization substitutes an expression by a cheaper expression:
31061 \end_layout
31062
31063 \begin_layout Verse
31064
31065 \family typewriter
31066 for (i=0;i < 100; i++)
31067 \newline
31068 \InsetSpace ~
31069 \InsetSpace ~
31070 \InsetSpace ~
31071 \InsetSpace ~
31072 ar[i*5] = i*3;
31073 \end_layout
31074
31075 \begin_layout Standard
31076 changed to
31077 \end_layout
31078
31079 \begin_layout Verse
31080
31081 \family typewriter
31082 itemp1 = 0; 
31083 \newline
31084 itemp2 = 0; 
31085 \newline
31086 for (i=0;i< 100;i++) { 
31087 \newline
31088 \InsetSpace ~
31089 \InsetSpace ~
31090 \InsetSpace ~
31091 \InsetSpace ~
31092 ar[itemp1] = itemp2; 
31093 \newline
31094 \InsetSpace ~
31095 \InsetSpace ~
31096 \InsetSpace ~
31097 \InsetSpace ~
31098 itemp1
31099  += 5; 
31100 \newline
31101 \InsetSpace ~
31102 \InsetSpace ~
31103 \InsetSpace ~
31104 \InsetSpace ~
31105 itemp2 += 3; 
31106 \newline
31107 }
31108 \end_layout
31109
31110 \begin_layout Standard
31111 The more expensive multiplication
31112 \begin_inset LatexCommand \index{Multiplication}
31113
31114 \end_inset
31115
31116  is changed to a less expensive addition.
31117 \end_layout
31118
31119 \begin_layout Subsection
31120 Loop Reversing
31121 \begin_inset LatexCommand \index{Loop reversing}
31122
31123 \end_inset
31124
31125
31126 \end_layout
31127
31128 \begin_layout Standard
31129 This optimization is done to reduce the overhead of checking loop boundaries
31130  for every iteration.
31131  Some simple loops can be reversed and implemented using a 
31132 \begin_inset Quotes eld
31133 \end_inset
31134
31135 decrement and jump if not zero
31136 \begin_inset Quotes erd
31137 \end_inset
31138
31139  instruction.
31140  SDCC checks for the following criterion to determine if a loop is reversible
31141  (note: more sophisticated compilers use data-dependency analysis to make
31142  this determination, SDCC uses a more simple minded analysis).
31143 \end_layout
31144
31145 \begin_layout Itemize
31146 The 'for' loop is of the form 
31147 \newline
31148
31149 \newline
31150
31151 \family typewriter
31152 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
31153  += 1])
31154 \newline
31155 \InsetSpace ~
31156 \InsetSpace ~
31157 \InsetSpace ~
31158 \InsetSpace ~
31159 <for body>
31160 \end_layout
31161
31162 \begin_layout Itemize
31163 The <for body> does not contain 
31164 \begin_inset Quotes eld
31165 \end_inset
31166
31167 continue
31168 \begin_inset Quotes erd
31169 \end_inset
31170
31171  or 'break
31172 \begin_inset Quotes erd
31173 \end_inset
31174
31175 .
31176 \end_layout
31177
31178 \begin_layout Itemize
31179 All goto's are contained within the loop.
31180 \end_layout
31181
31182 \begin_layout Itemize
31183 No function calls within the loop.
31184 \end_layout
31185
31186 \begin_layout Itemize
31187 The loop control variable <sym> is not assigned any value within the loop
31188 \end_layout
31189
31190 \begin_layout Itemize
31191 The loop control variable does NOT participate in any arithmetic operation
31192  within the loop.
31193 \end_layout
31194
31195 \begin_layout Itemize
31196 There are NO switch statements in the loop.
31197 \end_layout
31198
31199 \begin_layout Subsection
31200 Algebraic Simplifications
31201 \end_layout
31202
31203 \begin_layout Standard
31204 SDCC does numerous algebraic simplifications, the following is a small sub-set
31205  of these optimizations.
31206 \end_layout
31207
31208 \begin_layout Verse
31209
31210 \family typewriter
31211 i = j + 0;\InsetSpace ~
31212 \InsetSpace ~
31213 \InsetSpace ~
31214 \InsetSpace ~
31215  /* changed to: */\InsetSpace ~
31216 \InsetSpace ~
31217 \InsetSpace ~
31218 \InsetSpace ~
31219  i = j; 
31220 \newline
31221 i /= 2;\InsetSpace ~
31222 \InsetSpace ~
31223 \InsetSpace ~
31224 \InsetSpace ~
31225 \InsetSpace ~
31226 \InsetSpace ~
31227 \InsetSpace ~
31228  /* changed to: */\InsetSpace ~
31229 \InsetSpace ~
31230 \InsetSpace ~
31231 \InsetSpace ~
31232  i >>= 1; 
31233 \newline
31234 i
31235  = j - j;\InsetSpace ~
31236 \InsetSpace ~
31237 \InsetSpace ~
31238 \InsetSpace ~
31239  /* changed to: */\InsetSpace ~
31240 \InsetSpace ~
31241 \InsetSpace ~
31242 \InsetSpace ~
31243  i = 0; 
31244 \newline
31245 i = j / 1;\InsetSpace ~
31246 \InsetSpace ~
31247 \InsetSpace ~
31248 \InsetSpace ~
31249  /* changed to: */\InsetSpace ~
31250 \InsetSpace ~
31251 \InsetSpace ~
31252 \InsetSpace ~
31253  i = j;
31254 \end_layout
31255
31256 \begin_layout Standard
31257 Note the subexpressions
31258 \begin_inset LatexCommand \index{Subexpression}
31259
31260 \end_inset
31261
31262  given above are generally introduced by macro expansions or as a result
31263  of copy/constant propagation.
31264 \end_layout
31265
31266 \begin_layout Subsection
31267 'switch' Statements
31268 \begin_inset LatexCommand \label{sub:'switch'-Statements}
31269
31270 \end_inset
31271
31272
31273 \begin_inset LatexCommand \index{switch statement}
31274
31275 \end_inset
31276
31277
31278 \end_layout
31279
31280 \begin_layout Standard
31281 SDCC can optimize switch statements to jump tables
31282 \begin_inset LatexCommand \index{jump tables}
31283
31284 \end_inset
31285
31286 .
31287  It makes the decision based on an estimate of the generated code size.
31288  SDCC is quite liberal in the requirements for jump table generation: 
31289 \end_layout
31290
31291 \begin_layout Itemize
31292 The labels need not be in order, and the starting number need not be one
31293  or zero, the case labels are in numerical sequence or not too many case
31294  labels are missing.
31295 \end_layout
31296
31297 \begin_deeper
31298 \begin_layout Verse
31299
31300 \family typewriter
31301 switch(i) {\InsetSpace ~
31302 \InsetSpace ~
31303 \InsetSpace ~
31304 \InsetSpace ~
31305 \InsetSpace ~
31306 \InsetSpace ~
31307 \InsetSpace ~
31308 \InsetSpace ~
31309 \InsetSpace ~
31310 \InsetSpace ~
31311 \InsetSpace ~
31312 \InsetSpace ~
31313 \InsetSpace ~
31314 \InsetSpace ~
31315 \InsetSpace ~
31316 \InsetSpace ~
31317 \InsetSpace ~
31318 \InsetSpace ~
31319 \InsetSpace ~
31320 \InsetSpace ~
31321 \InsetSpace ~
31322 \InsetSpace ~
31323 \InsetSpace ~
31324 \InsetSpace ~
31325 \InsetSpace ~
31326 \InsetSpace ~
31327 switch (i) { 
31328 \newline
31329 \InsetSpace ~
31330 \InsetSpace ~
31331 \InsetSpace ~
31332 case 4: ...\InsetSpace ~
31333 \InsetSpace ~
31334 \InsetSpace ~
31335 \InsetSpace ~
31336 \InsetSpace ~
31337 \InsetSpace ~
31338 \InsetSpace ~
31339 \InsetSpace ~
31340 \InsetSpace ~
31341 \InsetSpace ~
31342 \InsetSpace ~
31343 \InsetSpace ~
31344 \InsetSpace ~
31345 \InsetSpace ~
31346 \InsetSpace ~
31347 \InsetSpace ~
31348 \InsetSpace ~
31349 \InsetSpace ~
31350 \InsetSpace ~
31351 \InsetSpace ~
31352 \InsetSpace ~
31353 \InsetSpace ~
31354 \InsetSpace ~
31355 \InsetSpace ~
31356 \InsetSpace ~
31357 \InsetSpace ~
31358 case 0: ...
31359  
31360 \newline
31361 \InsetSpace ~
31362 \InsetSpace ~
31363 \InsetSpace ~
31364 case 5: ...\InsetSpace ~
31365 \InsetSpace ~
31366 \InsetSpace ~
31367 \InsetSpace ~
31368 \InsetSpace ~
31369 \InsetSpace ~
31370 \InsetSpace ~
31371 \InsetSpace ~
31372 \InsetSpace ~
31373 \InsetSpace ~
31374 \InsetSpace ~
31375 \InsetSpace ~
31376 \InsetSpace ~
31377 \InsetSpace ~
31378 \InsetSpace ~
31379 \InsetSpace ~
31380 \InsetSpace ~
31381 \InsetSpace ~
31382 \InsetSpace ~
31383 \InsetSpace ~
31384 \InsetSpace ~
31385 \InsetSpace ~
31386 \InsetSpace ~
31387 \InsetSpace ~
31388 \InsetSpace ~
31389 \InsetSpace ~
31390 case 1: ...
31391  
31392 \newline
31393 \InsetSpace ~
31394 \InsetSpace ~
31395 \InsetSpace ~
31396 case 3: ...\InsetSpace ~
31397 \InsetSpace ~
31398 \InsetSpace ~
31399 \InsetSpace ~
31400 \InsetSpace ~
31401 \InsetSpace ~
31402 \InsetSpace ~
31403 \InsetSpace ~
31404 \InsetSpace ~
31405 \InsetSpace ~
31406 \InsetSpace ~
31407 \InsetSpace ~
31408 \InsetSpace ~
31409 \InsetSpace ~
31410 \InsetSpace ~
31411 \InsetSpace ~
31412 \InsetSpace ~
31413 \InsetSpace ~
31414 \InsetSpace ~
31415 \InsetSpace ~
31416 \InsetSpace ~
31417 \InsetSpace ~
31418 \InsetSpace ~
31419 \InsetSpace ~
31420 \InsetSpace ~
31421 \InsetSpace ~
31422
31423 \newline
31424 \InsetSpace ~
31425 \InsetSpace ~
31426 \InsetSpace ~
31427 case 6: ...\InsetSpace ~
31428 \InsetSpace ~
31429 \InsetSpace ~
31430 \InsetSpace ~
31431 \InsetSpace ~
31432 \InsetSpace ~
31433 \InsetSpace ~
31434 \InsetSpace ~
31435 \InsetSpace ~
31436 \InsetSpace ~
31437 \InsetSpace ~
31438 \InsetSpace ~
31439 \InsetSpace ~
31440 \InsetSpace ~
31441 \InsetSpace ~
31442 \InsetSpace ~
31443 \InsetSpace ~
31444 \InsetSpace ~
31445 \InsetSpace ~
31446 \InsetSpace ~
31447 \InsetSpace ~
31448 \InsetSpace ~
31449 \InsetSpace ~
31450 \InsetSpace ~
31451 \InsetSpace ~
31452 \InsetSpace ~
31453 case 3: ...
31454  
31455 \newline
31456 \InsetSpace ~
31457 \InsetSpace ~
31458 \InsetSpace ~
31459 case 7: ...\InsetSpace ~
31460 \InsetSpace ~
31461 \InsetSpace ~
31462 \InsetSpace ~
31463 \InsetSpace ~
31464 \InsetSpace ~
31465 \InsetSpace ~
31466 \InsetSpace ~
31467 \InsetSpace ~
31468 \InsetSpace ~
31469 \InsetSpace ~
31470 \InsetSpace ~
31471 \InsetSpace ~
31472 \InsetSpace ~
31473 \InsetSpace ~
31474 \InsetSpace ~
31475 \InsetSpace ~
31476 \InsetSpace ~
31477 \InsetSpace ~
31478 \InsetSpace ~
31479 \InsetSpace ~
31480 \InsetSpace ~
31481 \InsetSpace ~
31482 \InsetSpace ~
31483 \InsetSpace ~
31484 \InsetSpace ~
31485 case 4: ...
31486  
31487 \newline
31488 \InsetSpace ~
31489 \InsetSpace ~
31490 \InsetSpace ~
31491 case 8: ...\InsetSpace ~
31492 \InsetSpace ~
31493 \InsetSpace ~
31494 \InsetSpace ~
31495 \InsetSpace ~
31496 \InsetSpace ~
31497 \InsetSpace ~
31498 \InsetSpace ~
31499 \InsetSpace ~
31500 \InsetSpace ~
31501 \InsetSpace ~
31502 \InsetSpace ~
31503 \InsetSpace ~
31504 \InsetSpace ~
31505 \InsetSpace ~
31506 \InsetSpace ~
31507 \InsetSpace ~
31508 \InsetSpace ~
31509 \InsetSpace ~
31510 \InsetSpace ~
31511 \InsetSpace ~
31512 \InsetSpace ~
31513 \InsetSpace ~
31514 \InsetSpace ~
31515 \InsetSpace ~
31516 \InsetSpace ~
31517 case 5: ...
31518  
31519 \newline
31520 \InsetSpace ~
31521 \InsetSpace ~
31522 \InsetSpace ~
31523 case 9: ...\InsetSpace ~
31524 \InsetSpace ~
31525 \InsetSpace ~
31526 \InsetSpace ~
31527 \InsetSpace ~
31528 \InsetSpace ~
31529 \InsetSpace ~
31530 \InsetSpace ~
31531 \InsetSpace ~
31532 \InsetSpace ~
31533 \InsetSpace ~
31534 \InsetSpace ~
31535 \InsetSpace ~
31536 \InsetSpace ~
31537 \InsetSpace ~
31538 \InsetSpace ~
31539 \InsetSpace ~
31540 \InsetSpace ~
31541 \InsetSpace ~
31542 \InsetSpace ~
31543 \InsetSpace ~
31544 \InsetSpace ~
31545 \InsetSpace ~
31546 \InsetSpace ~
31547 \InsetSpace ~
31548 \InsetSpace ~
31549 case 6: ...
31550  
31551 \newline
31552 \InsetSpace ~
31553 \InsetSpace ~
31554 \InsetSpace ~
31555 case 10: ...\InsetSpace ~
31556 \InsetSpace ~
31557 \InsetSpace ~
31558 \InsetSpace ~
31559 \InsetSpace ~
31560 \InsetSpace ~
31561 \InsetSpace ~
31562 \InsetSpace ~
31563 \InsetSpace ~
31564 \InsetSpace ~
31565 \InsetSpace ~
31566 \InsetSpace ~
31567 \InsetSpace ~
31568 \InsetSpace ~
31569 \InsetSpace ~
31570 \InsetSpace ~
31571 \InsetSpace ~
31572 \InsetSpace ~
31573 \InsetSpace ~
31574 \InsetSpace ~
31575 \InsetSpace ~
31576 \InsetSpace ~
31577 \InsetSpace ~
31578 \InsetSpace ~
31579 \InsetSpace ~
31580 case 7: ...
31581  
31582 \newline
31583 \InsetSpace ~
31584 \InsetSpace ~
31585 \InsetSpace ~
31586 case 11: ...\InsetSpace ~
31587 \InsetSpace ~
31588 \InsetSpace ~
31589 \InsetSpace ~
31590 \InsetSpace ~
31591 \InsetSpace ~
31592 \InsetSpace ~
31593 \InsetSpace ~
31594 \InsetSpace ~
31595 \InsetSpace ~
31596 \InsetSpace ~
31597 \InsetSpace ~
31598 \InsetSpace ~
31599 \InsetSpace ~
31600 \InsetSpace ~
31601 \InsetSpace ~
31602 \InsetSpace ~
31603 \InsetSpace ~
31604 \InsetSpace ~
31605 \InsetSpace ~
31606 \InsetSpace ~
31607 \InsetSpace ~
31608 \InsetSpace ~
31609 \InsetSpace ~
31610 \InsetSpace ~
31611 case 8: ...
31612  
31613 \newline
31614 }\InsetSpace ~
31615 \InsetSpace ~
31616 \InsetSpace ~
31617 \InsetSpace ~
31618 \InsetSpace ~
31619 \InsetSpace ~
31620 \InsetSpace ~
31621 \InsetSpace ~
31622 \InsetSpace ~
31623 \InsetSpace ~
31624 \InsetSpace ~
31625 \InsetSpace ~
31626 \InsetSpace ~
31627 \InsetSpace ~
31628 \InsetSpace ~
31629 \InsetSpace ~
31630 \InsetSpace ~
31631 \InsetSpace ~
31632 \InsetSpace ~
31633 \InsetSpace ~
31634 \InsetSpace ~
31635 \InsetSpace ~
31636 \InsetSpace ~
31637 \InsetSpace ~
31638 \InsetSpace ~
31639 \InsetSpace ~
31640 \InsetSpace ~
31641 \InsetSpace ~
31642 \InsetSpace ~
31643 \InsetSpace ~
31644 \InsetSpace ~
31645 \InsetSpace ~
31646 \InsetSpace ~
31647 \InsetSpace ~
31648 \InsetSpace ~
31649 \InsetSpace ~
31650 }
31651 \end_layout
31652
31653 \begin_layout Standard
31654 Both the above switch statements will be implemented using a jump-table.
31655  The example to the right side is slightly more efficient as the check for
31656  the lower boundary of the jump-table is not needed.
31657 \end_layout
31658
31659 \end_deeper
31660 \begin_layout Itemize
31661 The number of case labels is not larger than supported by the target architectur
31662 e.
31663 \end_layout
31664
31665 \begin_layout Itemize
31666 If the case labels are not in numerical sequence ('gaps' between cases)
31667  SDCC checks whether a jump table with additionally inserted dummy cases
31668  is still attractive.
31669  
31670 \end_layout
31671
31672 \begin_layout Itemize
31673 If the starting number is not zero and a check for the lower boundary of
31674  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
31675  ...
31676  .
31677 \end_layout
31678
31679 \begin_layout Standard
31680 Switch statements which have large gaps in the numeric sequence or those
31681  that have too many case labels can be split into more than one switch statement
31682  for efficient code generation, e.g.:
31683 \end_layout
31684
31685 \begin_layout Verse
31686
31687 \family typewriter
31688 switch (i) { 
31689 \newline
31690 \InsetSpace ~
31691 \InsetSpace ~
31692 case 1: ...
31693  
31694 \newline
31695 \InsetSpace ~
31696 \InsetSpace ~
31697 case 2: ...
31698  
31699 \newline
31700 \InsetSpace ~
31701 \InsetSpace ~
31702 case 3: ...
31703  
31704 \newline
31705 \InsetSpace ~
31706 \InsetSpace ~
31707 case 4: ...
31708  
31709 \newline
31710 \InsetSpace ~
31711 \InsetSpace ~
31712 case 5: ...
31713  
31714 \newline
31715 \InsetSpace ~
31716 \InsetSpace ~
31717 case 6: ...
31718  
31719 \newline
31720 \InsetSpace ~
31721 \InsetSpace ~
31722 case 7: ...
31723  
31724 \newline
31725 \InsetSpace ~
31726 \InsetSpace ~
31727 case 101: ...
31728  
31729 \newline
31730 \InsetSpace ~
31731 \InsetSpace ~
31732 case 102: ...
31733  
31734 \newline
31735 \InsetSpace ~
31736 \InsetSpace ~
31737 case 103: ...
31738  
31739 \newline
31740 \InsetSpace ~
31741 \InsetSpace ~
31742 case 104: ...
31743  
31744 \newline
31745 \InsetSpace ~
31746 \InsetSpace ~
31747 case 105: ...
31748  
31749 \newline
31750 \InsetSpace ~
31751 \InsetSpace ~
31752 case 106: ...
31753  
31754 \newline
31755 \InsetSpace ~
31756 \InsetSpace ~
31757 case 107: ...
31758  
31759 \newline
31760 }
31761 \end_layout
31762
31763 \begin_layout Standard
31764 If the above switch statement is broken down into two switch statements
31765 \end_layout
31766
31767 \begin_layout Verse
31768
31769 \family typewriter
31770 switch (i) { 
31771 \newline
31772 \InsetSpace ~
31773 \InsetSpace ~
31774 case 1: ...
31775  
31776 \newline
31777 \InsetSpace ~
31778 \InsetSpace ~
31779 case 2: ...
31780  
31781 \newline
31782 \InsetSpace ~
31783 \InsetSpace ~
31784 case 3: ...
31785  
31786 \newline
31787 \InsetSpace ~
31788 \InsetSpace ~
31789 case 4: ...
31790  
31791 \newline
31792 \InsetSpace ~
31793 \InsetSpace ~
31794 case 5: ...
31795  
31796 \newline
31797 \InsetSpace ~
31798 \InsetSpace ~
31799 case 6: ...
31800  
31801 \newline
31802 \InsetSpace ~
31803 \InsetSpace ~
31804 case 7: ...
31805  
31806 \newline
31807 }
31808 \end_layout
31809
31810 \begin_layout Standard
31811 and
31812 \end_layout
31813
31814 \begin_layout Verse
31815
31816 \family typewriter
31817 switch (i) { 
31818 \newline
31819 \InsetSpace ~
31820 \InsetSpace ~
31821 case 101: ...
31822  
31823 \newline
31824 \InsetSpace ~
31825 \InsetSpace ~
31826 case 102: ...
31827  
31828 \newline
31829 \InsetSpace ~
31830 \InsetSpace ~
31831 case 103: ...
31832  
31833 \newline
31834 \InsetSpace ~
31835 \InsetSpace ~
31836 case 104: ...
31837  
31838 \newline
31839 \InsetSpace ~
31840 \InsetSpace ~
31841 case 105: ...
31842  
31843 \newline
31844 \InsetSpace ~
31845 \InsetSpace ~
31846 case 106: ...
31847  
31848 \newline
31849 \InsetSpace ~
31850 \InsetSpace ~
31851 case 107: ...
31852  
31853 \newline
31854 }
31855 \end_layout
31856
31857 \begin_layout Standard
31858 then both the switch statements will be implemented using jump-tables whereas
31859  the unmodified switch statement will not be.
31860 \end_layout
31861
31862 \begin_layout Standard
31863 \begin_inset Note Comment
31864 status collapsed
31865
31866 \begin_layout Standard
31867 There might be reasons which SDCC cannot know about to either favour or
31868  not favour jump tables.
31869  If the target system has to be as quick for the last switch case as for
31870  the first (pro jump table), or if the switch argument is known to be zero
31871  in the majority of the cases (contra jump table).
31872 \end_layout
31873
31874 \end_inset
31875
31876
31877 \end_layout
31878
31879 \begin_layout Standard
31880 The pragma nojtbound
31881 \begin_inset LatexCommand \index{\#pragma nojtbound}
31882
31883 \end_inset
31884
31885  can be used to turn off checking the 
31886 \emph on
31887 j
31888 \emph default
31889 ump 
31890 \emph on
31891 t
31892 \emph default
31893 able 
31894 \emph on
31895 bound
31896 \emph default
31897 aries.
31898  It has no effect if a default label is supplied.
31899  Use of this pragma is dangerous: if the switch
31900 \begin_inset LatexCommand \index{switch statement}
31901
31902 \end_inset
31903
31904  argument is not matched by a case statement the processor will happily
31905  jump into Nirvana.
31906 \end_layout
31907
31908 \begin_layout Subsection
31909 Bit-shifting Operations
31910 \begin_inset LatexCommand \index{Bit shifting}
31911
31912 \end_inset
31913
31914 .
31915 \end_layout
31916
31917 \begin_layout Standard
31918 Bit shifting is one of the most frequently used operation in embedded programmin
31919 g.
31920  SDCC tries to implement bit-shift operations in the most efficient way
31921  possible, e.g.:
31922 \end_layout
31923
31924 \begin_layout Verse
31925
31926 \family typewriter
31927 unsigned char i;
31928 \newline
31929 ...
31930  
31931 \newline
31932 i >>= 4; 
31933 \newline
31934 ...
31935 \end_layout
31936
31937 \begin_layout Standard
31938 generates the following code:
31939 \end_layout
31940
31941 \begin_layout Verse
31942
31943 \family typewriter
31944 mov\InsetSpace ~
31945  a,_i 
31946 \newline
31947 swap a 
31948 \newline
31949 anl\InsetSpace ~
31950  a,#0x0f 
31951 \newline
31952 mov\InsetSpace ~
31953  _i,a
31954 \end_layout
31955
31956 \begin_layout Standard
31957 In general SDCC will never setup a loop if the shift count is known.
31958  Another example:
31959 \end_layout
31960
31961 \begin_layout Verse
31962
31963 \family typewriter
31964 unsigned int i; 
31965 \newline
31966 ...
31967  
31968 \newline
31969 i >>= 9; 
31970 \newline
31971 ...
31972 \end_layout
31973
31974 \begin_layout Standard
31975 will generate:
31976 \end_layout
31977
31978 \begin_layout Verse
31979
31980 \family typewriter
31981 mov\InsetSpace ~
31982 \InsetSpace ~
31983 a,(_i + 1) 
31984 \newline
31985 mov\InsetSpace ~
31986 \InsetSpace ~
31987 (_i + 1),#0x00 
31988 \newline
31989 clr\InsetSpace ~
31990 \InsetSpace ~
31991
31992 \newline
31993 rrc\InsetSpace ~
31994 \InsetSpace ~
31995
31996 \newline
31997 mov\InsetSpace ~
31998 \InsetSpace ~
31999 _i,a
32000 \end_layout
32001
32002 \begin_layout Subsection
32003 Bit-rotation
32004 \begin_inset LatexCommand \index{Bit rotation}
32005
32006 \end_inset
32007
32008
32009 \end_layout
32010
32011 \begin_layout Standard
32012 A special case of the bit-shift operation is bit rotation
32013 \begin_inset LatexCommand \index{rotating bits}
32014
32015 \end_inset
32016
32017 , SDCC recognizes the following expression to be a left bit-rotation:
32018 \end_layout
32019
32020 \begin_layout Verse
32021
32022 \family typewriter
32023 \series bold
32024 unsigned
32025 \series default
32026 \InsetSpace ~
32027 \InsetSpace ~
32028 char i;\InsetSpace ~
32029 \InsetSpace ~
32030 \InsetSpace ~
32031 \InsetSpace ~
32032 \InsetSpace ~
32033 \InsetSpace ~
32034 \InsetSpace ~
32035 \InsetSpace ~
32036 \InsetSpace ~
32037 \InsetSpace ~
32038 \InsetSpace ~
32039 /* unsigned is needed for rotation */ 
32040 \newline
32041 ...
32042  
32043 \newline
32044 i = ((i << 1) | (i >> 7)); 
32045 \family default
32046
32047 \newline
32048
32049 \family typewriter
32050 ...
32051 \end_layout
32052
32053 \begin_layout Standard
32054 will generate the following code:
32055 \end_layout
32056
32057 \begin_layout Verse
32058
32059 \family typewriter
32060 mov\InsetSpace ~
32061 \InsetSpace ~
32062 a,_i 
32063 \newline
32064 rl\InsetSpace ~
32065 \InsetSpace ~
32066 \InsetSpace ~
32067
32068 \newline
32069 mov\InsetSpace ~
32070 \InsetSpace ~
32071 _i,a
32072 \end_layout
32073
32074 \begin_layout Standard
32075 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
32076 ns of this case will also be recognized as bit-rotation, i.e.: 
32077 \end_layout
32078
32079 \begin_layout Verse
32080
32081 \family typewriter
32082 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
32083 \end_layout
32084
32085 \begin_layout Subsection
32086 Nibble and Byte Swapping
32087 \end_layout
32088
32089 \begin_layout Standard
32090 Other special cases of the bit-shift operations are nibble or byte swapping
32091 \begin_inset LatexCommand \index{swapping nibbles/bytes}
32092
32093 \end_inset
32094
32095 , SDCC recognizes the following expressions:
32096 \end_layout
32097
32098 \begin_layout Verse
32099
32100 \family typewriter
32101 \series bold
32102 unsigned
32103 \series default
32104 \InsetSpace ~
32105 \InsetSpace ~
32106 char i; 
32107 \newline
32108
32109 \series bold
32110 unsigned
32111 \series default
32112 \InsetSpace ~
32113 \InsetSpace ~
32114 int j; 
32115 \newline
32116 ...
32117  
32118 \newline
32119 i = ((i << 4) | (i >> 4)); 
32120 \family default
32121
32122 \newline
32123
32124 \family typewriter
32125 j = ((j << 8) | (j >> 8)); 
32126 \end_layout
32127
32128 \begin_layout Standard
32129 and generates a swap instruction for the nibble swapping
32130 \begin_inset LatexCommand \index{Nibble swapping}
32131
32132 \end_inset
32133
32134  or move instructions for the byte swapping
32135 \begin_inset LatexCommand \index{Byte swapping}
32136
32137 \end_inset
32138
32139 .
32140  The 
32141 \begin_inset Quotes sld
32142 \end_inset
32143
32144 j
32145 \begin_inset Quotes srd
32146 \end_inset
32147
32148  example can be used to convert from little to big-endian or vice versa.
32149  If you want to change the endianness of a 
32150 \emph on
32151 signed
32152 \emph default
32153  integer you have to cast to 
32154 \family typewriter
32155 (unsigned int)
32156 \family default
32157  first.
32158 \end_layout
32159
32160 \begin_layout Standard
32161 Note that SDCC stores numbers in little-endian
32162 \begin_inset Foot
32163 status open
32164
32165 \begin_layout Standard
32166 Usually 8-bit processors don't care much about endianness.
32167  This is not the case for the standard 8051 which only has an instruction
32168  to increment its 
32169 \emph on
32170 dptr
32171 \emph default
32172
32173 \begin_inset LatexCommand \index{DPTR}
32174
32175 \end_inset
32176
32177 -datapointer
32178 \emph on
32179  
32180 \emph default
32181 so little-endian is the more efficient byte order.
32182 \end_layout
32183
32184 \end_inset
32185
32186
32187 \begin_inset LatexCommand \index{little-endian}
32188
32189 \end_inset
32190
32191
32192 \begin_inset LatexCommand \index{Endianness}
32193
32194 \end_inset
32195
32196  format (i.e.
32197  lowest order first).
32198 \end_layout
32199
32200 \begin_layout Subsection
32201 Highest Order Bit
32202 \begin_inset LatexCommand \index{Highest Order Bit}
32203
32204 \end_inset
32205
32206  / Any Order Bit
32207 \begin_inset LatexCommand \index{Any Order Bit}
32208
32209 \end_inset
32210
32211
32212 \end_layout
32213
32214 \begin_layout Standard
32215 It is frequently required to obtain the highest order bit of an integral
32216  type (long, int, short or char types).
32217  Also obtaining any other order bit is not uncommon.
32218  SDCC recognizes the following expressions to yield the highest order bit
32219  and generates optimized code for it, e.g.:
32220 \end_layout
32221
32222 \begin_layout Verse
32223
32224 \family typewriter
32225 unsigned int gint; 
32226 \newline
32227
32228 \newline
32229 foo () { 
32230 \newline
32231 \InsetSpace ~
32232 \InsetSpace ~
32233 unsigned char hob1, aob1; 
32234 \newline
32235 \InsetSpace ~
32236 \InsetSpace ~
32237 bit hob2, hob3, aob2,
32238  aob3; 
32239 \newline
32240 \InsetSpace ~
32241 \InsetSpace ~
32242 ...
32243  
32244 \newline
32245 \InsetSpace ~
32246 \InsetSpace ~
32247 hob1 = (gint >> 15) & 1; 
32248 \newline
32249 \InsetSpace ~
32250 \InsetSpace ~
32251 hob2 = (gint >> 15) & 1; 
32252 \newline
32253 \InsetSpace ~
32254 \InsetSpace ~
32255 hob3 = gint & 0x8000;
32256  
32257 \newline
32258 \InsetSpace ~
32259 \InsetSpace ~
32260 aob1 = (gint >> 9) & 1; 
32261 \newline
32262 \InsetSpace ~
32263 \InsetSpace ~
32264 aob2 = (gint >> 8) & 1; 
32265 \newline
32266 \InsetSpace ~
32267 \InsetSpace ~
32268 aob3 = gint & 0x0800; 
32269 \newline
32270 \InsetSpace ~
32271 \InsetSpace ~
32272 ..
32273  
32274 \newline
32275 }
32276 \end_layout
32277
32278 \begin_layout Standard
32279 will generate the following code:
32280 \end_layout
32281
32282 \begin_layout Verse
32283
32284 \family typewriter
32285 \InsetSpace ~
32286 \InsetSpace ~
32287 \InsetSpace ~
32288 \InsetSpace ~
32289 \InsetSpace ~
32290 \InsetSpace ~
32291 \InsetSpace ~
32292 \InsetSpace ~
32293 \InsetSpace ~
32294 \InsetSpace ~
32295 \InsetSpace ~
32296 \InsetSpace ~
32297 \InsetSpace ~
32298 \InsetSpace ~
32299 \InsetSpace ~
32300 \InsetSpace ~
32301 \InsetSpace ~
32302 \InsetSpace ~
32303 \InsetSpace ~
32304 \InsetSpace ~
32305 \InsetSpace ~
32306 \InsetSpace ~
32307 \InsetSpace ~
32308 \InsetSpace ~
32309 \InsetSpace ~
32310  61 ;\InsetSpace ~
32311  hob.c 7 
32312 \newline
32313 000A E5*01\InsetSpace ~
32314 \InsetSpace ~
32315 \InsetSpace ~
32316 \InsetSpace ~
32317 \InsetSpace ~
32318 \InsetSpace ~
32319 \InsetSpace ~
32320 \InsetSpace ~
32321 \InsetSpace ~
32322 \InsetSpace ~
32323 \InsetSpace ~
32324 \InsetSpace ~
32325 \InsetSpace ~
32326 \InsetSpace ~
32327 \InsetSpace ~
32328  62\InsetSpace ~
32329 \InsetSpace ~
32330 \InsetSpace ~
32331 \InsetSpace ~
32332 \InsetSpace ~
32333 \InsetSpace ~
32334 \InsetSpace ~
32335 \InsetSpace ~
32336  mov\InsetSpace ~
32337 \InsetSpace ~
32338  a,(_gint + 1) 
32339 \newline
32340 000C 23\InsetSpace ~
32341 \InsetSpace ~
32342 \InsetSpace ~
32343 \InsetSpace ~
32344 \InsetSpace ~
32345 \InsetSpace ~
32346 \InsetSpace ~
32347 \InsetSpace ~
32348 \InsetSpace ~
32349 \InsetSpace ~
32350 \InsetSpace ~
32351 \InsetSpace ~
32352 \InsetSpace ~
32353 \InsetSpace ~
32354 \InsetSpace ~
32355 \InsetSpace ~
32356 \InsetSpace ~
32357 \InsetSpace ~
32358  63\InsetSpace ~
32359 \InsetSpace ~
32360 \InsetSpace ~
32361 \InsetSpace ~
32362 \InsetSpace ~
32363 \InsetSpace ~
32364 \InsetSpace ~
32365 \InsetSpace ~
32366  rl\InsetSpace ~
32367 \InsetSpace ~
32368 \InsetSpace ~
32369  a 
32370 \newline
32371 000D 54 01\InsetSpace ~
32372 \InsetSpace ~
32373 \InsetSpace ~
32374 \InsetSpace ~
32375 \InsetSpace ~
32376 \InsetSpace ~
32377 \InsetSpace ~
32378 \InsetSpace ~
32379 \InsetSpace ~
32380 \InsetSpace ~
32381 \InsetSpace ~
32382 \InsetSpace ~
32383 \InsetSpace ~
32384 \InsetSpace ~
32385 \InsetSpace ~
32386
32387  64\InsetSpace ~
32388 \InsetSpace ~
32389 \InsetSpace ~
32390 \InsetSpace ~
32391 \InsetSpace ~
32392 \InsetSpace ~
32393 \InsetSpace ~
32394 \InsetSpace ~
32395  anl\InsetSpace ~
32396 \InsetSpace ~
32397  a,#0x01 
32398 \newline
32399 000F F5*02\InsetSpace ~
32400 \InsetSpace ~
32401 \InsetSpace ~
32402 \InsetSpace ~
32403 \InsetSpace ~
32404 \InsetSpace ~
32405 \InsetSpace ~
32406 \InsetSpace ~
32407 \InsetSpace ~
32408 \InsetSpace ~
32409 \InsetSpace ~
32410 \InsetSpace ~
32411 \InsetSpace ~
32412 \InsetSpace ~
32413 \InsetSpace ~
32414  65\InsetSpace ~
32415 \InsetSpace ~
32416 \InsetSpace ~
32417 \InsetSpace ~
32418 \InsetSpace ~
32419 \InsetSpace ~
32420 \InsetSpace ~
32421 \InsetSpace ~
32422  mov\InsetSpace ~
32423 \InsetSpace ~
32424  _foo_hob1_1_1,a 
32425 \newline
32426 \InsetSpace ~
32427 \InsetSpace ~
32428 \InsetSpace ~
32429 \InsetSpace ~
32430 \InsetSpace ~
32431 \InsetSpace ~
32432 \InsetSpace ~
32433 \InsetSpace ~
32434 \InsetSpace ~
32435 \InsetSpace ~
32436 \InsetSpace ~
32437 \InsetSpace ~
32438 \InsetSpace ~
32439 \InsetSpace ~
32440 \InsetSpace ~
32441 \InsetSpace ~
32442 \InsetSpace ~
32443 \InsetSpace ~
32444 \InsetSpace ~
32445 \InsetSpace ~
32446 \InsetSpace ~
32447 \InsetSpace ~
32448 \InsetSpace ~
32449 \InsetSpace ~
32450 \InsetSpace ~
32451  66 ;\InsetSpace ~
32452  hob.c 8 
32453 \newline
32454 0011 E5*01\InsetSpace ~
32455 \InsetSpace ~
32456 \InsetSpace ~
32457 \InsetSpace ~
32458 \InsetSpace ~
32459 \InsetSpace ~
32460 \InsetSpace ~
32461 \InsetSpace ~
32462 \InsetSpace ~
32463 \InsetSpace ~
32464 \InsetSpace ~
32465 \InsetSpace ~
32466 \InsetSpace ~
32467 \InsetSpace ~
32468 \InsetSpace ~
32469
32470  67\InsetSpace ~
32471 \InsetSpace ~
32472 \InsetSpace ~
32473 \InsetSpace ~
32474 \InsetSpace ~
32475 \InsetSpace ~
32476 \InsetSpace ~
32477 \InsetSpace ~
32478  mov\InsetSpace ~
32479 \InsetSpace ~
32480  a,(_gint + 1) 
32481 \newline
32482 0013 33\InsetSpace ~
32483 \InsetSpace ~
32484 \InsetSpace ~
32485 \InsetSpace ~
32486 \InsetSpace ~
32487 \InsetSpace ~
32488 \InsetSpace ~
32489 \InsetSpace ~
32490 \InsetSpace ~
32491 \InsetSpace ~
32492 \InsetSpace ~
32493 \InsetSpace ~
32494 \InsetSpace ~
32495 \InsetSpace ~
32496 \InsetSpace ~
32497 \InsetSpace ~
32498 \InsetSpace ~
32499 \InsetSpace ~
32500  68\InsetSpace ~
32501 \InsetSpace ~
32502 \InsetSpace ~
32503 \InsetSpace ~
32504 \InsetSpace ~
32505 \InsetSpace ~
32506 \InsetSpace ~
32507 \InsetSpace ~
32508  rlc\InsetSpace ~
32509 \InsetSpace ~
32510  a 
32511 \newline
32512 0014 92*00\InsetSpace ~
32513 \InsetSpace ~
32514 \InsetSpace ~
32515 \InsetSpace ~
32516 \InsetSpace ~
32517 \InsetSpace ~
32518 \InsetSpace ~
32519 \InsetSpace ~
32520 \InsetSpace ~
32521 \InsetSpace ~
32522 \InsetSpace ~
32523 \InsetSpace ~
32524 \InsetSpace ~
32525 \InsetSpace ~
32526 \InsetSpace ~
32527  69\InsetSpace ~
32528 \InsetSpace ~
32529 \InsetSpace ~
32530 \InsetSpace ~
32531 \InsetSpace ~
32532 \InsetSpace ~
32533 \InsetSpace ~
32534 \InsetSpace ~
32535  mov\InsetSpace ~
32536 \InsetSpace ~
32537  _foo_hob2_1_1,c
32538  
32539 \newline
32540 \InsetSpace ~
32541 \InsetSpace ~
32542 \InsetSpace ~
32543 \InsetSpace ~
32544 \InsetSpace ~
32545 \InsetSpace ~
32546 \InsetSpace ~
32547 \InsetSpace ~
32548 \InsetSpace ~
32549 \InsetSpace ~
32550 \InsetSpace ~
32551 \InsetSpace ~
32552 \InsetSpace ~
32553 \InsetSpace ~
32554 \InsetSpace ~
32555 \InsetSpace ~
32556 \InsetSpace ~
32557 \InsetSpace ~
32558 \InsetSpace ~
32559 \InsetSpace ~
32560 \InsetSpace ~
32561 \InsetSpace ~
32562 \InsetSpace ~
32563 \InsetSpace ~
32564 \InsetSpace ~
32565  66 ;\InsetSpace ~
32566  hob.c 9 
32567 \newline
32568 0016 E5*01\InsetSpace ~
32569 \InsetSpace ~
32570 \InsetSpace ~
32571 \InsetSpace ~
32572 \InsetSpace ~
32573 \InsetSpace ~
32574 \InsetSpace ~
32575 \InsetSpace ~
32576 \InsetSpace ~
32577 \InsetSpace ~
32578 \InsetSpace ~
32579 \InsetSpace ~
32580 \InsetSpace ~
32581 \InsetSpace ~
32582 \InsetSpace ~
32583  67\InsetSpace ~
32584 \InsetSpace ~
32585 \InsetSpace ~
32586 \InsetSpace ~
32587 \InsetSpace ~
32588 \InsetSpace ~
32589 \InsetSpace ~
32590 \InsetSpace ~
32591  mov\InsetSpace ~
32592 \InsetSpace ~
32593  a,(_gint + 1) 
32594 \newline
32595 0018 33\InsetSpace ~
32596 \InsetSpace ~
32597 \InsetSpace ~
32598 \InsetSpace ~
32599 \InsetSpace ~
32600 \InsetSpace ~
32601 \InsetSpace ~
32602 \InsetSpace ~
32603 \InsetSpace ~
32604 \InsetSpace ~
32605 \InsetSpace ~
32606 \InsetSpace ~
32607 \InsetSpace ~
32608 \InsetSpace ~
32609 \InsetSpace ~
32610 \InsetSpace ~
32611 \InsetSpace ~
32612 \InsetSpace ~
32613  68\InsetSpace ~
32614 \InsetSpace ~
32615 \InsetSpace ~
32616 \InsetSpace ~
32617 \InsetSpace ~
32618 \InsetSpace ~
32619 \InsetSpace ~
32620 \InsetSpace ~
32621  rlc\InsetSpace ~
32622 \InsetSpace ~
32623  a 
32624 \newline
32625 0019 92*01\InsetSpace ~
32626 \InsetSpace ~
32627 \InsetSpace ~
32628 \InsetSpace ~
32629 \InsetSpace ~
32630 \InsetSpace ~
32631 \InsetSpace ~
32632 \InsetSpace ~
32633 \InsetSpace ~
32634 \InsetSpace ~
32635 \InsetSpace ~
32636 \InsetSpace ~
32637 \InsetSpace ~
32638 \InsetSpace ~
32639 \InsetSpace ~
32640
32641  69\InsetSpace ~
32642 \InsetSpace ~
32643 \InsetSpace ~
32644 \InsetSpace ~
32645 \InsetSpace ~
32646 \InsetSpace ~
32647 \InsetSpace ~
32648 \InsetSpace ~
32649  mov\InsetSpace ~
32650 \InsetSpace ~
32651  _foo_hob3_1_1,c 
32652 \newline
32653 \InsetSpace ~
32654 \InsetSpace ~
32655 \InsetSpace ~
32656 \InsetSpace ~
32657 \InsetSpace ~
32658 \InsetSpace ~
32659 \InsetSpace ~
32660 \InsetSpace ~
32661 \InsetSpace ~
32662 \InsetSpace ~
32663 \InsetSpace ~
32664 \InsetSpace ~
32665 \InsetSpace ~
32666 \InsetSpace ~
32667 \InsetSpace ~
32668 \InsetSpace ~
32669 \InsetSpace ~
32670 \InsetSpace ~
32671 \InsetSpace ~
32672 \InsetSpace ~
32673 \InsetSpace ~
32674 \InsetSpace ~
32675 \InsetSpace ~
32676 \InsetSpace ~
32677 \InsetSpace ~
32678  70 ;\InsetSpace ~
32679  hob.c 10 
32680 \newline
32681 001B E5*01\InsetSpace ~
32682 \InsetSpace ~
32683 \InsetSpace ~
32684 \InsetSpace ~
32685 \InsetSpace ~
32686 \InsetSpace ~
32687 \InsetSpace ~
32688 \InsetSpace ~
32689 \InsetSpace ~
32690 \InsetSpace ~
32691 \InsetSpace ~
32692 \InsetSpace ~
32693 \InsetSpace ~
32694 \InsetSpace ~
32695 \InsetSpace ~
32696  71\InsetSpace ~
32697 \InsetSpace ~
32698 \InsetSpace ~
32699 \InsetSpace ~
32700 \InsetSpace ~
32701 \InsetSpace ~
32702 \InsetSpace ~
32703 \InsetSpace ~
32704  mov\InsetSpace ~
32705 \InsetSpace ~
32706  a,(_gint + 1) 
32707 \newline
32708 001D
32709  03\InsetSpace ~
32710 \InsetSpace ~
32711 \InsetSpace ~
32712 \InsetSpace ~
32713 \InsetSpace ~
32714 \InsetSpace ~
32715 \InsetSpace ~
32716 \InsetSpace ~
32717 \InsetSpace ~
32718 \InsetSpace ~
32719 \InsetSpace ~
32720 \InsetSpace ~
32721 \InsetSpace ~
32722 \InsetSpace ~
32723 \InsetSpace ~
32724 \InsetSpace ~
32725 \InsetSpace ~
32726 \InsetSpace ~
32727  72\InsetSpace ~
32728 \InsetSpace ~
32729 \InsetSpace ~
32730 \InsetSpace ~
32731 \InsetSpace ~
32732 \InsetSpace ~
32733 \InsetSpace ~
32734 \InsetSpace ~
32735  rr\InsetSpace ~
32736 \InsetSpace ~
32737 \InsetSpace ~
32738  a 
32739 \newline
32740 001E 54 01\InsetSpace ~
32741 \InsetSpace ~
32742 \InsetSpace ~
32743 \InsetSpace ~
32744 \InsetSpace ~
32745 \InsetSpace ~
32746 \InsetSpace ~
32747 \InsetSpace ~
32748 \InsetSpace ~
32749 \InsetSpace ~
32750 \InsetSpace ~
32751 \InsetSpace ~
32752 \InsetSpace ~
32753 \InsetSpace ~
32754 \InsetSpace ~
32755  73\InsetSpace ~
32756 \InsetSpace ~
32757 \InsetSpace ~
32758 \InsetSpace ~
32759 \InsetSpace ~
32760 \InsetSpace ~
32761 \InsetSpace ~
32762 \InsetSpace ~
32763  anl\InsetSpace ~
32764 \InsetSpace ~
32765  a,#0x01 
32766 \newline
32767 0020 F5*03\InsetSpace ~
32768 \InsetSpace ~
32769 \InsetSpace ~
32770 \InsetSpace ~
32771 \InsetSpace ~
32772 \InsetSpace ~
32773 \InsetSpace ~
32774 \InsetSpace ~
32775 \InsetSpace ~
32776 \InsetSpace ~
32777 \InsetSpace ~
32778 \InsetSpace ~
32779 \InsetSpace ~
32780 \InsetSpace ~
32781 \InsetSpace ~
32782  74\InsetSpace ~
32783 \InsetSpace ~
32784 \InsetSpace ~
32785 \InsetSpace ~
32786 \InsetSpace ~
32787 \InsetSpace ~
32788 \InsetSpace ~
32789 \InsetSpace ~
32790  mov\InsetSpace ~
32791 \InsetSpace ~
32792  _foo_aob1_1_1,a
32793  
32794 \newline
32795 \InsetSpace ~
32796 \InsetSpace ~
32797 \InsetSpace ~
32798 \InsetSpace ~
32799 \InsetSpace ~
32800 \InsetSpace ~
32801 \InsetSpace ~
32802 \InsetSpace ~
32803 \InsetSpace ~
32804 \InsetSpace ~
32805 \InsetSpace ~
32806 \InsetSpace ~
32807 \InsetSpace ~
32808 \InsetSpace ~
32809 \InsetSpace ~
32810 \InsetSpace ~
32811 \InsetSpace ~
32812 \InsetSpace ~
32813 \InsetSpace ~
32814 \InsetSpace ~
32815 \InsetSpace ~
32816 \InsetSpace ~
32817 \InsetSpace ~
32818 \InsetSpace ~
32819 \InsetSpace ~
32820  75 ;\InsetSpace ~
32821  hob.c 11 
32822 \newline
32823 0022 E5*01\InsetSpace ~
32824 \InsetSpace ~
32825 \InsetSpace ~
32826 \InsetSpace ~
32827 \InsetSpace ~
32828 \InsetSpace ~
32829 \InsetSpace ~
32830 \InsetSpace ~
32831 \InsetSpace ~
32832 \InsetSpace ~
32833 \InsetSpace ~
32834 \InsetSpace ~
32835 \InsetSpace ~
32836 \InsetSpace ~
32837 \InsetSpace ~
32838  76\InsetSpace ~
32839 \InsetSpace ~
32840 \InsetSpace ~
32841 \InsetSpace ~
32842 \InsetSpace ~
32843 \InsetSpace ~
32844 \InsetSpace ~
32845 \InsetSpace ~
32846  mov\InsetSpace ~
32847 \InsetSpace ~
32848  a,(_gint + 1) 
32849 \newline
32850 0024 13\InsetSpace ~
32851 \InsetSpace ~
32852 \InsetSpace ~
32853 \InsetSpace ~
32854 \InsetSpace ~
32855 \InsetSpace ~
32856 \InsetSpace ~
32857 \InsetSpace ~
32858 \InsetSpace ~
32859 \InsetSpace ~
32860 \InsetSpace ~
32861 \InsetSpace ~
32862 \InsetSpace ~
32863 \InsetSpace ~
32864 \InsetSpace ~
32865 \InsetSpace ~
32866 \InsetSpace ~
32867 \InsetSpace ~
32868  77\InsetSpace ~
32869 \InsetSpace ~
32870 \InsetSpace ~
32871 \InsetSpace ~
32872 \InsetSpace ~
32873 \InsetSpace ~
32874 \InsetSpace ~
32875 \InsetSpace ~
32876  rrc\InsetSpace ~
32877 \InsetSpace ~
32878  a 
32879 \newline
32880 0025 92*02\InsetSpace ~
32881 \InsetSpace ~
32882 \InsetSpace ~
32883 \InsetSpace ~
32884 \InsetSpace ~
32885 \InsetSpace ~
32886 \InsetSpace ~
32887 \InsetSpace ~
32888 \InsetSpace ~
32889 \InsetSpace ~
32890 \InsetSpace ~
32891 \InsetSpace ~
32892 \InsetSpace ~
32893 \InsetSpace ~
32894 \InsetSpace ~
32895
32896  78\InsetSpace ~
32897 \InsetSpace ~
32898 \InsetSpace ~
32899 \InsetSpace ~
32900 \InsetSpace ~
32901 \InsetSpace ~
32902 \InsetSpace ~
32903 \InsetSpace ~
32904  mov\InsetSpace ~
32905 \InsetSpace ~
32906  _foo_aob2_1_1,c 
32907 \newline
32908 \InsetSpace ~
32909 \InsetSpace ~
32910 \InsetSpace ~
32911 \InsetSpace ~
32912 \InsetSpace ~
32913 \InsetSpace ~
32914 \InsetSpace ~
32915 \InsetSpace ~
32916 \InsetSpace ~
32917 \InsetSpace ~
32918 \InsetSpace ~
32919 \InsetSpace ~
32920 \InsetSpace ~
32921 \InsetSpace ~
32922 \InsetSpace ~
32923 \InsetSpace ~
32924 \InsetSpace ~
32925 \InsetSpace ~
32926 \InsetSpace ~
32927 \InsetSpace ~
32928 \InsetSpace ~
32929 \InsetSpace ~
32930 \InsetSpace ~
32931 \InsetSpace ~
32932 \InsetSpace ~
32933  79 ;\InsetSpace ~
32934  hob.c 12 
32935 \newline
32936 0027 E5*01\InsetSpace ~
32937 \InsetSpace ~
32938 \InsetSpace ~
32939 \InsetSpace ~
32940 \InsetSpace ~
32941 \InsetSpace ~
32942 \InsetSpace ~
32943 \InsetSpace ~
32944 \InsetSpace ~
32945 \InsetSpace ~
32946 \InsetSpace ~
32947 \InsetSpace ~
32948 \InsetSpace ~
32949 \InsetSpace ~
32950 \InsetSpace ~
32951  80\InsetSpace ~
32952 \InsetSpace ~
32953 \InsetSpace ~
32954 \InsetSpace ~
32955 \InsetSpace ~
32956 \InsetSpace ~
32957 \InsetSpace ~
32958 \InsetSpace ~
32959  mov\InsetSpace ~
32960 \InsetSpace ~
32961  a,(_gint + 1) 
32962 \newline
32963 0029
32964  A2 E3\InsetSpace ~
32965 \InsetSpace ~
32966 \InsetSpace ~
32967 \InsetSpace ~
32968 \InsetSpace ~
32969 \InsetSpace ~
32970 \InsetSpace ~
32971 \InsetSpace ~
32972 \InsetSpace ~
32973 \InsetSpace ~
32974 \InsetSpace ~
32975 \InsetSpace ~
32976 \InsetSpace ~
32977 \InsetSpace ~
32978 \InsetSpace ~
32979  81\InsetSpace ~
32980 \InsetSpace ~
32981 \InsetSpace ~
32982 \InsetSpace ~
32983 \InsetSpace ~
32984 \InsetSpace ~
32985 \InsetSpace ~
32986 \InsetSpace ~
32987  mov\InsetSpace ~
32988 \InsetSpace ~
32989  c,acc[3] 
32990 \newline
32991 002B 92*03\InsetSpace ~
32992 \InsetSpace ~
32993 \InsetSpace ~
32994 \InsetSpace ~
32995 \InsetSpace ~
32996 \InsetSpace ~
32997 \InsetSpace ~
32998 \InsetSpace ~
32999 \InsetSpace ~
33000 \InsetSpace ~
33001 \InsetSpace ~
33002 \InsetSpace ~
33003 \InsetSpace ~
33004 \InsetSpace ~
33005 \InsetSpace ~
33006  82\InsetSpace ~
33007 \InsetSpace ~
33008 \InsetSpace ~
33009 \InsetSpace ~
33010 \InsetSpace ~
33011 \InsetSpace ~
33012 \InsetSpace ~
33013 \InsetSpace ~
33014  mov\InsetSpace ~
33015 \InsetSpace ~
33016  _foo_aob3_1_1,c 
33017 \end_layout
33018
33019 \begin_layout Standard
33020 Other variations of these cases however will 
33021 \emph on
33022 not
33023 \emph default
33024  be recognized.
33025  They are standard C expressions, so I heartily recommend these be the only
33026  way to get the highest order bit, (it is portable).
33027  Of course it will be recognized even if it is embedded in other expressions,
33028  e.g.:
33029 \end_layout
33030
33031 \begin_layout Verse
33032
33033 \family typewriter
33034 xyz = gint + ((gint >> 15) & 1);
33035 \end_layout
33036
33037 \begin_layout Standard
33038 will still be recognized.
33039 \end_layout
33040
33041 \begin_layout Subsection
33042 Higher Order Byte
33043 \begin_inset LatexCommand \index{Higher Order Byte}
33044
33045 \end_inset
33046
33047  / Higher Order Word
33048 \begin_inset LatexCommand \index{Higher Order Word}
33049
33050 \end_inset
33051
33052
33053 \end_layout
33054
33055 \begin_layout Standard
33056 It is also frequently required to obtain a higher order byte or word of
33057  a larger integral type (long, int or short types).
33058  SDCC recognizes the following expressions to yield the higher order byte
33059  or word and generates optimized code for it, e.g.:
33060 \end_layout
33061
33062 \begin_layout Verse
33063
33064 \family typewriter
33065 unsigned int gint; 
33066 \newline
33067 unsigned long int glong; 
33068 \newline
33069
33070 \newline
33071 foo () { 
33072 \newline
33073 \InsetSpace ~
33074 \InsetSpace ~
33075 unsigned char hob1,
33076  hob2; 
33077 \newline
33078 \InsetSpace ~
33079 \InsetSpace ~
33080 unsigned int how1, how2; 
33081 \newline
33082 \InsetSpace ~
33083 \InsetSpace ~
33084 ...
33085  
33086 \newline
33087 \InsetSpace ~
33088 \InsetSpace ~
33089 hob1 = (gint >> 8) & 0xFF; 
33090 \newline
33091 \InsetSpace ~
33092 \InsetSpace ~
33093 hob2 = glong >> 24; 
33094 \newline
33095 \InsetSpace ~
33096 \InsetSpace ~
33097 how1 = (glong >> 16) & 0xFFFF;
33098  
33099 \newline
33100 \InsetSpace ~
33101 \InsetSpace ~
33102 how2 = glong >> 8; 
33103 \newline
33104 \InsetSpace ~
33105 \InsetSpace ~
33106 ..
33107  
33108 \newline
33109 }
33110 \end_layout
33111
33112 \begin_layout Standard
33113 will generate the following code:
33114 \end_layout
33115
33116 \begin_layout Verse
33117
33118 \family typewriter
33119 \InsetSpace ~
33120 \InsetSpace ~
33121 \InsetSpace ~
33122 \InsetSpace ~
33123 \InsetSpace ~
33124 \InsetSpace ~
33125 \InsetSpace ~
33126 \InsetSpace ~
33127 \InsetSpace ~
33128 \InsetSpace ~
33129 \InsetSpace ~
33130 \InsetSpace ~
33131 \InsetSpace ~
33132 \InsetSpace ~
33133 \InsetSpace ~
33134 \InsetSpace ~
33135 \InsetSpace ~
33136 \InsetSpace ~
33137 \InsetSpace ~
33138 \InsetSpace ~
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 \InsetSpace ~
33142 \InsetSpace ~
33143 \InsetSpace ~
33144  91 ;\InsetSpace ~
33145  hob.c 15 
33146 \newline
33147 0037 85*01*06\InsetSpace ~
33148 \InsetSpace ~
33149 \InsetSpace ~
33150 \InsetSpace ~
33151 \InsetSpace ~
33152 \InsetSpace ~
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 \InsetSpace ~
33156 \InsetSpace ~
33157 \InsetSpace ~
33158 \InsetSpace ~
33159  92\InsetSpace ~
33160 \InsetSpace ~
33161 \InsetSpace ~
33162 \InsetSpace ~
33163 \InsetSpace ~
33164 \InsetSpace ~
33165 \InsetSpace ~
33166 \InsetSpace ~
33167  mov\InsetSpace ~
33168 \InsetSpace ~
33169  _foo_hob1_1_1,(_gint + 1) 
33170 \newline
33171 \InsetSpace ~
33172 \InsetSpace ~
33173 \InsetSpace ~
33174 \InsetSpace ~
33175 \InsetSpace ~
33176 \InsetSpace ~
33177 \InsetSpace ~
33178 \InsetSpace ~
33179 \InsetSpace ~
33180 \InsetSpace ~
33181 \InsetSpace ~
33182 \InsetSpace ~
33183 \InsetSpace ~
33184 \InsetSpace ~
33185 \InsetSpace ~
33186 \InsetSpace ~
33187 \InsetSpace ~
33188 \InsetSpace ~
33189 \InsetSpace ~
33190 \InsetSpace ~
33191 \InsetSpace ~
33192 \InsetSpace ~
33193 \InsetSpace ~
33194 \InsetSpace ~
33195 \InsetSpace ~
33196  93 ;\InsetSpace ~
33197  hob.c
33198  16 
33199 \newline
33200 003A 85*05*07\InsetSpace ~
33201 \InsetSpace ~
33202 \InsetSpace ~
33203 \InsetSpace ~
33204 \InsetSpace ~
33205 \InsetSpace ~
33206 \InsetSpace ~
33207 \InsetSpace ~
33208 \InsetSpace ~
33209 \InsetSpace ~
33210 \InsetSpace ~
33211 \InsetSpace ~
33212  94\InsetSpace ~
33213 \InsetSpace ~
33214 \InsetSpace ~
33215 \InsetSpace ~
33216 \InsetSpace ~
33217 \InsetSpace ~
33218 \InsetSpace ~
33219 \InsetSpace ~
33220  mov\InsetSpace ~
33221 \InsetSpace ~
33222  _foo_hob2_1_1,(_glong + 3) 
33223 \newline
33224 \InsetSpace ~
33225 \InsetSpace ~
33226 \InsetSpace ~
33227 \InsetSpace ~
33228 \InsetSpace ~
33229 \InsetSpace ~
33230 \InsetSpace ~
33231 \InsetSpace ~
33232 \InsetSpace ~
33233 \InsetSpace ~
33234 \InsetSpace ~
33235 \InsetSpace ~
33236 \InsetSpace ~
33237 \InsetSpace ~
33238 \InsetSpace ~
33239 \InsetSpace ~
33240 \InsetSpace ~
33241 \InsetSpace ~
33242 \InsetSpace ~
33243 \InsetSpace ~
33244 \InsetSpace ~
33245 \InsetSpace ~
33246 \InsetSpace ~
33247 \InsetSpace ~
33248 \InsetSpace ~
33249  95 ;\InsetSpace ~
33250  hob.c 17 
33251 \newline
33252 003D 85*04*08\InsetSpace ~
33253 \InsetSpace ~
33254 \InsetSpace ~
33255 \InsetSpace ~
33256 \InsetSpace ~
33257 \InsetSpace ~
33258 \InsetSpace ~
33259 \InsetSpace ~
33260 \InsetSpace ~
33261 \InsetSpace ~
33262 \InsetSpace ~
33263 \InsetSpace ~
33264
33265  96\InsetSpace ~
33266 \InsetSpace ~
33267 \InsetSpace ~
33268 \InsetSpace ~
33269 \InsetSpace ~
33270 \InsetSpace ~
33271 \InsetSpace ~
33272 \InsetSpace ~
33273  mov\InsetSpace ~
33274 \InsetSpace ~
33275  _foo_how1_1_1,(_glong + 2) 
33276 \newline
33277 0040 85*05*09\InsetSpace ~
33278 \InsetSpace ~
33279 \InsetSpace ~
33280 \InsetSpace ~
33281 \InsetSpace ~
33282 \InsetSpace ~
33283 \InsetSpace ~
33284 \InsetSpace ~
33285 \InsetSpace ~
33286 \InsetSpace ~
33287 \InsetSpace ~
33288 \InsetSpace ~
33289  97\InsetSpace ~
33290 \InsetSpace ~
33291 \InsetSpace ~
33292 \InsetSpace ~
33293 \InsetSpace ~
33294 \InsetSpace ~
33295 \InsetSpace ~
33296 \InsetSpace ~
33297  mov\InsetSpace ~
33298 \InsetSpace ~
33299  (_foo_how1_1_1 +
33300  1),(_glong + 3) 
33301 \newline
33302 0043 85*03*0A\InsetSpace ~
33303 \InsetSpace ~
33304 \InsetSpace ~
33305 \InsetSpace ~
33306 \InsetSpace ~
33307 \InsetSpace ~
33308 \InsetSpace ~
33309 \InsetSpace ~
33310 \InsetSpace ~
33311 \InsetSpace ~
33312 \InsetSpace ~
33313 \InsetSpace ~
33314  98\InsetSpace ~
33315 \InsetSpace ~
33316 \InsetSpace ~
33317 \InsetSpace ~
33318 \InsetSpace ~
33319 \InsetSpace ~
33320 \InsetSpace ~
33321 \InsetSpace ~
33322  mov\InsetSpace ~
33323 \InsetSpace ~
33324  _foo_how2_1_1,(_glong + 1) 
33325 \newline
33326 0046 85*04*0B\InsetSpace ~
33327 \InsetSpace ~
33328 \InsetSpace ~
33329 \InsetSpace ~
33330 \InsetSpace ~
33331 \InsetSpace ~
33332 \InsetSpace ~
33333 \InsetSpace ~
33334 \InsetSpace ~
33335 \InsetSpace ~
33336 \InsetSpace ~
33337 \InsetSpace ~
33338
33339  99\InsetSpace ~
33340 \InsetSpace ~
33341 \InsetSpace ~
33342 \InsetSpace ~
33343 \InsetSpace ~
33344 \InsetSpace ~
33345 \InsetSpace ~
33346 \InsetSpace ~
33347  mov\InsetSpace ~
33348 \InsetSpace ~
33349  (_foo_how2_1_1 + 1),(_glong + 2) 
33350 \end_layout
33351
33352 \begin_layout Standard
33353 Again, variations of these cases may 
33354 \emph on
33355 not
33356 \emph default
33357  be recognized.
33358  They are standard C expressions, so I heartily recommend these be the only
33359  way to get the higher order byte/word, (it is portable).
33360  Of course it will be recognized even if it is embedded in other expressions,
33361  e.g.:
33362 \end_layout
33363
33364 \begin_layout Verse
33365
33366 \family typewriter
33367 xyz = gint + ((gint >> 8) & 0xFF);
33368 \end_layout
33369
33370 \begin_layout Standard
33371 will still be recognized.
33372 \end_layout
33373
33374 \begin_layout Subsection
33375 Peephole Optimizer
33376 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
33377
33378 \end_inset
33379
33380
33381 \begin_inset LatexCommand \index{Peephole optimizer}
33382
33383 \end_inset
33384
33385
33386 \end_layout
33387
33388 \begin_layout Standard
33389 The compiler uses a rule based, pattern matching and re-writing mechanism
33390  for peep-hole optimization.
33391  It is inspired by 
33392 \emph on
33393 copt
33394 \emph default
33395  a peep-hole optimizer by Christopher W.
33396  Fraser (cwfraser\InsetSpace ~
33397 @\InsetSpace ~
33398 microsoft.com).
33399  A default set of rules are compiled into the compiler, additional rules
33400  may be added with the 
33401 \emph on
33402 -
33403 \begin_inset ERT
33404 status collapsed
33405
33406 \begin_layout Standard
33407
33408
33409 \backslash
33410 /
33411 \end_layout
33412
33413 \end_inset
33414
33415 -peep-file
33416 \begin_inset LatexCommand \index{-\/-peep-file}
33417
33418 \end_inset
33419
33420  <filename>
33421 \emph default
33422  option.
33423  The rule language is best illustrated with examples.
33424 \end_layout
33425
33426 \begin_layout Verse
33427
33428 \family typewriter
33429 replace { 
33430 \newline
33431 \InsetSpace ~
33432 \InsetSpace ~
33433 mov %1,a 
33434 \newline
33435 \InsetSpace ~
33436 \InsetSpace ~
33437 mov a,%1
33438 \newline
33439 } by {
33440 \newline
33441 \InsetSpace ~
33442 \InsetSpace ~
33443 mov %1,a
33444 \newline
33445 }
33446 \end_layout
33447
33448 \begin_layout Standard
33449 The above rule will change the following assembly
33450 \begin_inset LatexCommand \index{Assembler routines}
33451
33452 \end_inset
33453
33454  sequence:
33455 \end_layout
33456
33457 \begin_layout Verse
33458
33459 \family typewriter
33460 mov r1,a 
33461 \newline
33462 mov a,r1
33463 \end_layout
33464
33465 \begin_layout Standard
33466 to
33467 \end_layout
33468
33469 \begin_layout Verse
33470
33471 \family typewriter
33472 mov r1,a
33473 \end_layout
33474
33475 \begin_layout Standard
33476 Note: All occurrences of a 
33477 \emph on
33478 %n
33479 \emph default
33480  (pattern variable) must denote the same string.
33481  With the above rule, the assembly sequence:
33482 \end_layout
33483
33484 \begin_layout Verse
33485
33486 \family typewriter
33487 mov r1,a 
33488 \newline
33489 mov a,r2
33490 \end_layout
33491
33492 \begin_layout Standard
33493 will remain unmodified.
33494 \newline
33495
33496 \newline
33497 Other special case optimizations may be added by the
33498  user (via 
33499 \emph on
33500 -
33501 \begin_inset ERT
33502 status collapsed
33503
33504 \begin_layout Standard
33505
33506
33507 \backslash
33508 /
33509 \end_layout
33510
33511 \end_inset
33512
33513 -peep-file option
33514 \emph default
33515 ).
33516  E.g.
33517  some variants of the 8051 MCU
33518 \begin_inset LatexCommand \index{MCS51 variants}
33519
33520 \end_inset
33521
33522  allow only 
33523 \family typewriter
33524 ajmp
33525 \family default
33526  and 
33527 \family typewriter
33528 acall
33529 \family default
33530 .
33531  The following two rules will change all 
33532 \family typewriter
33533 ljmp
33534 \family default
33535  and 
33536 \family typewriter
33537 lcall
33538 \family default
33539  to 
33540 \family typewriter
33541 ajmp
33542 \family default
33543  and 
33544 \family typewriter
33545 acall
33546 \end_layout
33547
33548 \begin_layout Verse
33549
33550 \family typewriter
33551 replace { lcall %1 } by { acall %1 } 
33552 \newline
33553 replace { ljmp %1 } by { ajmp %1 }
33554 \end_layout
33555
33556 \begin_layout Standard
33557 The 
33558 \emph on
33559 inline-assembler code
33560 \emph default
33561  is also passed through the peep hole optimizer, thus the peephole optimizer
33562  can also be used as an assembly level macro expander.
33563  The rules themselves are MCU dependent whereas the rule language infra-structur
33564 e is MCU independent.
33565  Peephole optimization rules for other MCU can be easily programmed using
33566  the rule language.
33567 \newline
33568
33569 \newline
33570 The syntax for a rule is as follows:
33571 \end_layout
33572
33573 \begin_layout Verse
33574
33575 \family typewriter
33576 rule := replace [ restart ] '{' <assembly sequence> '
33577 \backslash
33578 n' 
33579 \newline
33580 \InsetSpace ~
33581  \InsetSpace ~
33582  \InsetSpace ~
33583  \InsetSpace ~
33584  \InsetSpace ~
33585  \InsetSpace ~
33586  \InsetSpace ~
33587  \InsetSpace ~
33588  \InsetSpace ~
33589  \InsetSpace ~
33590  \InsetSpace ~
33591  \InsetSpace ~
33592  \InsetSpace ~
33593  \InsetSpace ~
33594  '}' by '{' '
33595 \backslash
33596 n' 
33597 \newline
33598 \InsetSpace ~
33599  \InsetSpace ~
33600  \InsetSpace ~
33601  \InsetSpace ~
33602  \InsetSpace ~
33603  \InsetSpace ~
33604  \InsetSpace ~
33605  \InsetSpace ~
33606  \InsetSpace ~
33607  \InsetSpace ~
33608  \InsetSpace ~
33609  \InsetSpace ~
33610  \InsetSpace ~
33611  \InsetSpace ~
33612  \InsetSpace ~
33613  \InsetSpace ~
33614  <assembly sequence> '
33615 \backslash
33616 n' 
33617 \newline
33618 \InsetSpace ~
33619  \InsetSpace ~
33620  \InsetSpace ~
33621  \InsetSpace ~
33622  \InsetSpace ~
33623  \InsetSpace ~
33624  \InsetSpace ~
33625  \InsetSpace ~
33626  \InsetSpace ~
33627  \InsetSpace ~
33628  \InsetSpace ~
33629  \InsetSpace ~
33630  \InsetSpace ~
33631  \InsetSpace ~
33632  '}' [if <functionName> ] '
33633 \backslash
33634 n' 
33635 \end_layout
33636
33637 \begin_layout Standard
33638 <assembly sequence> := assembly instruction (each instruction including
33639  labels must be on a separate line).
33640 \newline
33641
33642 \newline
33643 The optimizer will apply to the rules
33644  one by one from the top in the sequence of their appearance, it will terminate
33645  when all rules are exhausted.
33646  If the 'restart' option is specified, then the optimizer will start matching
33647  the rules again from the top, this option for a rule is expensive (performance)
33648 , it is intended to be used in situations where a transformation will trigger
33649  the same rule again.
33650  An example of this (not a good one, it has side effects) is the following
33651  rule:
33652 \end_layout
33653
33654 \begin_layout Verse
33655
33656 \family typewriter
33657 replace restart { 
33658 \newline
33659 \InsetSpace ~
33660 \InsetSpace ~
33661 pop %1 
33662 \newline
33663 \InsetSpace ~
33664 \InsetSpace ~
33665 push %1 } by { 
33666 \newline
33667 \InsetSpace ~
33668 \InsetSpace ~
33669 ; nop 
33670 \newline
33671 }
33672 \end_layout
33673
33674 \begin_layout Standard
33675 Note that the replace pattern cannot be a blank, but can be a comment line.
33676  Without the 'restart' option only the innermost 'pop' 'push' pair would
33677  be eliminated, i.e.:
33678 \end_layout
33679
33680 \begin_layout Verse
33681
33682 \family typewriter
33683 pop ar1 
33684 \newline
33685 pop ar2 
33686 \newline
33687 push ar2 
33688 \newline
33689 push ar1
33690 \end_layout
33691
33692 \begin_layout Standard
33693 would result in:
33694 \end_layout
33695
33696 \begin_layout Verse
33697
33698 \family typewriter
33699 pop ar1 
33700 \newline
33701 ; nop 
33702 \newline
33703 push ar1
33704 \end_layout
33705
33706 \begin_layout Standard
33707
33708 \emph on
33709 with
33710 \emph default
33711  the restart option the rule will be applied again to the resulting code
33712  and then all the pop-push pairs will be eliminated to yield:
33713 \end_layout
33714
33715 \begin_layout Verse
33716
33717 \family typewriter
33718 ; nop 
33719 \newline
33720 ; nop
33721 \end_layout
33722
33723 \begin_layout Standard
33724 A conditional function can be attached to a rule.
33725  Attaching rules are somewhat more involved, let me illustrate this with
33726  an example.
33727 \end_layout
33728
33729 \begin_layout Verse
33730
33731 \family typewriter
33732 replace { 
33733 \newline
33734 \InsetSpace ~
33735  \InsetSpace ~
33736  \InsetSpace ~
33737 ljmp %5 
33738 \newline
33739 %2:
33740 \newline
33741 } by { 
33742 \newline
33743 \InsetSpace ~
33744  \InsetSpace ~
33745  \InsetSpace ~
33746 sjmp %5 
33747 \newline
33748 %2:
33749 \newline
33750 } if labelInRange
33751 \end_layout
33752
33753 \begin_layout Standard
33754 The optimizer does a look-up of a function name table defined in function
33755  
33756 \emph on
33757 callFuncByName
33758 \emph default
33759  in the source file SDCCpeeph.c, with the name 
33760 \emph on
33761 labelInRange
33762 \emph default
33763 .
33764  If it finds a corresponding entry the function is called.
33765  Note there can be no parameters specified for these functions, in this
33766  case the use of 
33767 \emph on
33768 %5
33769 \emph default
33770  is crucial, since the function 
33771 \emph on
33772 labelInRange
33773 \emph default
33774  expects to find the label in that particular variable (the hash table containin
33775 g the variable bindings is passed as a parameter).
33776  If you want to code more such functions, take a close look at the function
33777  labelInRange and the calling mechanism in source file SDCCpeeph.c.
33778  Currently implemented are 
33779 \emph on
33780 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
33781  24bitMode, portIsDS390, 24bitModeAndPortDS390 
33782 \emph default
33783 and
33784 \emph on
33785  notVolatile
33786 \emph default
33787 .
33788 \end_layout
33789
33790 \begin_layout Standard
33791 I know this whole thing is a little kludgey, but maybe some day we will
33792  have some better means.
33793  If you are looking at this file, you will see the default rules that are
33794  compiled into the compiler, you can add your own rules in the default set
33795  there if you get tired of specifying the -
33796 \begin_inset ERT
33797 status collapsed
33798
33799 \begin_layout Standard
33800
33801
33802 \backslash
33803 /
33804 \end_layout
33805
33806 \end_inset
33807
33808 -peep-file option.
33809 \end_layout
33810
33811 \begin_layout Section
33812 ANSI-Compliance
33813 \begin_inset LatexCommand \index{ANSI-compliance}
33814
33815 \end_inset
33816
33817
33818 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
33819
33820 \end_inset
33821
33822
33823 \end_layout
33824
33825 \begin_layout Standard
33826 The latest publically available version of the standard 
33827 \emph on
33828 ISO/IEC 9899 - Programming languages - C
33829 \emph default
33830  should be available at: 
33831 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
33832
33833 \end_inset
33834
33835 .
33836 \newline
33837
33838 \end_layout
33839
33840 \begin_layout Standard
33841 Deviations from the compliance:
33842 \end_layout
33843
33844 \begin_layout Itemize
33845 functions are not reentrant
33846 \begin_inset LatexCommand \index{reentrant}
33847
33848 \end_inset
33849
33850  unless explicitly declared as such or the 
33851 \series bold
33852 -
33853 \begin_inset ERT
33854 status collapsed
33855
33856 \begin_layout Standard
33857
33858
33859 \backslash
33860 /
33861 \end_layout
33862
33863 \end_inset
33864
33865 -stack-auto
33866 \begin_inset LatexCommand \index{-\/-stack-auto}
33867
33868 \end_inset
33869
33870
33871 \series default
33872  command line option is specified.
33873 \end_layout
33874
33875 \begin_layout Itemize
33876 structures
33877 \begin_inset LatexCommand \index{struct}
33878
33879 \end_inset
33880
33881  and unions
33882 \begin_inset LatexCommand \index{union}
33883
33884 \end_inset
33885
33886  cannot be assigned values directly, cannot be passed as function parameters
33887  or assigned to each other and cannot be a return value
33888 \begin_inset LatexCommand \index{return value}
33889
33890 \end_inset
33891
33892  from a function, e.g.:
33893 \end_layout
33894
33895 \begin_deeper
33896 \begin_layout Verse
33897
33898 \family typewriter
33899 struct s { ...
33900  }; 
33901 \newline
33902 struct s s1, s2; 
33903 \newline
33904 foo() 
33905 \newline
33906
33907 \newline
33908 \InsetSpace ~
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 \InsetSpace ~
33912 ...
33913  
33914 \newline
33915 \InsetSpace ~
33916 \InsetSpace ~
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
33920 \newline
33921 \InsetSpace ~
33922 \InsetSpace ~
33923 \InsetSpace ~
33924 \InsetSpace ~
33925 ...
33926  
33927 \newline
33928 }
33929 \newline
33930
33931 \series bold
33932 struct
33933 \series default
33934  s foo1 (
33935 \series bold
33936 struct
33937 \series default
33938  s parms) /* invalid in SDCC although allowed in ANSI */
33939 \newline
33940
33941 \newline
33942 \InsetSpace ~
33943 \InsetSpace ~
33944 \InsetSpace ~
33945 \InsetSpace ~
33946 struct s rets;
33947  
33948 \newline
33949 \InsetSpace ~
33950 \InsetSpace ~
33951 \InsetSpace ~
33952 \InsetSpace ~
33953 ...
33954  
33955 \newline
33956 \InsetSpace ~
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 \InsetSpace ~
33960 return rets; /* is invalid in SDCC although allowed in ANSI */ 
33961 \newline
33962 }
33963 \end_layout
33964
33965 \end_deeper
33966 \begin_layout Itemize
33967 initialization of structure arrays must be fully braced.
33968 \end_layout
33969
33970 \begin_deeper
33971 \begin_layout Verse
33972
33973 \family typewriter
33974 struct s { char x } a[] = {1, 2};\InsetSpace ~
33975 \InsetSpace ~
33976 \InsetSpace ~
33977 \InsetSpace ~
33978 \InsetSpace ~
33979 /* invalid in SDCC */
33980 \newline
33981 struct s { char x
33982  } a[] = {{1}, {2}}; /* OK */
33983 \end_layout
33984
33985 \end_deeper
33986 \begin_layout Itemize
33987 'long long
33988 \begin_inset LatexCommand \index{long long (not supported)}
33989
33990 \end_inset
33991
33992 ' (64 bit integers
33993 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
33994
33995 \end_inset
33996
33997 ) not supported.
33998 \end_layout
33999
34000 \begin_layout Itemize
34001 'double
34002 \begin_inset LatexCommand \index{double (not supported)}
34003
34004 \end_inset
34005
34006 ' precision floating point 
34007 \begin_inset LatexCommand \index{Floating point support}
34008
34009 \end_inset
34010
34011 not supported.
34012 \end_layout
34013
34014 \begin_layout Itemize
34015 Old K&R style
34016 \begin_inset LatexCommand \index{K\&R style}
34017
34018 \end_inset
34019
34020  function declarations are NOT allowed.
34021 \end_layout
34022
34023 \begin_deeper
34024 \begin_layout Verse
34025
34026 \family typewriter
34027 foo(i,j) /* this old style of function declarations */ 
34028 \newline
34029 int i,j; /* are valid
34030  in ANSI but not valid in SDCC */ 
34031 \newline
34032
34033 \newline
34034 \InsetSpace ~
34035 \InsetSpace ~
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 ...
34039  
34040 \newline
34041 }
34042 \end_layout
34043
34044 \end_deeper
34045 \begin_layout Itemize
34046 Most enhancements in C99 are not supported, f.e.:
34047 \end_layout
34048
34049 \begin_deeper
34050 \begin_layout Verse
34051
34052 \family typewriter
34053 \series bold
34054 inline
34055 \begin_inset LatexCommand \index{inline (not supported)}
34056
34057 \end_inset
34058
34059
34060 \series default
34061  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
34062  in C99.
34063  An empty define 
34064 \emph on
34065 #define inline
34066 \emph default
34067  can be used as a work around */
34068 \newline
34069
34070 \newline
34071 for (
34072 \series bold
34073 int
34074 \series default
34075  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
34076 \end_layout
34077
34078 \end_deeper
34079 \begin_layout Itemize
34080 Certain words that are valid identifiers in the standard may be reserved
34081  words in SDCC unless the 
34082 \series bold
34083 -
34084 \begin_inset ERT
34085 status collapsed
34086
34087 \begin_layout Standard
34088
34089
34090 \backslash
34091 /
34092 \end_layout
34093
34094 \end_inset
34095
34096 -std-c89
34097 \begin_inset LatexCommand \index{-\/-std-c89}
34098
34099 \end_inset
34100
34101  or -
34102 \begin_inset ERT
34103 status collapsed
34104
34105 \begin_layout Standard
34106
34107
34108 \backslash
34109 /
34110 \end_layout
34111
34112 \end_inset
34113
34114 -std-c99
34115 \begin_inset LatexCommand \index{-\/-std-c99}
34116
34117 \end_inset
34118
34119
34120 \series default
34121  command line options are used.
34122  These may include (depending on the selected processor): 'at', 'banked',
34123  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
34124 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
34125  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
34126  '_naked'.
34127  Compliant equivalents of these keywords are always available in a form
34128  that begin with two underscores
34129 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
34130
34131 \end_inset
34132
34133 , f.e.
34134  '__data' instead of 'data'.
34135 \end_layout
34136
34137 \begin_layout Section
34138 Cyclomatic Complexity
34139 \begin_inset LatexCommand \index{Cyclomatic complexity}
34140
34141 \end_inset
34142
34143
34144 \end_layout
34145
34146 \begin_layout Standard
34147 Cyclomatic complexity of a function is defined as the number of independent
34148  paths the program can take during execution of the function.
34149  This is an important number since it defines the number test cases you
34150  have to generate to validate the function.
34151  The accepted industry standard for complexity number is 10, if the cyclomatic
34152  complexity reported by SDCC exceeds 10 you should think about simplification
34153  of the function logic.
34154  Note that the complexity level is not related to the number of lines of
34155  code in a function.
34156  Large functions can have low complexity, and small functions can have large
34157  complexity levels.
34158  
34159 \newline
34160
34161 \newline
34162 SDCC uses the following formula to compute the complexity:
34163 \newline
34164
34165 \end_layout
34166
34167 \begin_layout Standard
34168 complexity = (number of edges in control flow graph) - (number of nodes
34169  in control flow graph) + 2;
34170 \newline
34171
34172 \newline
34173 Having said that the industry standard is 10,
34174  you should be aware that in some cases it be may unavoidable to have a
34175  complexity level of less than 10.
34176  For example if you have switch statement with more than 10 case labels,
34177  each case label adds one to the complexity level.
34178  The complexity level is by no means an absolute measure of the algorithmic
34179  complexity of the function, it does however provide a good starting point
34180  for which functions you might look at for further optimization.
34181 \end_layout
34182
34183 \begin_layout Section
34184 Retargetting for other Processors
34185 \end_layout
34186
34187 \begin_layout Standard
34188 The issues for retargetting the compiler are far too numerous to be covered
34189  by this document.
34190  What follows is a brief description of each of the seven phases of the
34191  compiler and its MCU dependency.
34192 \end_layout
34193
34194 \begin_layout Itemize
34195 Parsing the source and building the annotated parse tree.
34196  This phase is largely MCU independent (except for the language extensions).
34197  Syntax & semantic checks are also done in this phase, along with some initial
34198  optimizations like back patching labels and the pattern matching optimizations
34199  like bit-rotation etc.
34200 \end_layout
34201
34202 \begin_layout Itemize
34203 The second phase involves generating an intermediate code which can be easy
34204  manipulated during the later phases.
34205  This phase is entirely MCU independent.
34206  The intermediate code generation assumes the target machine has unlimited
34207  number of registers, and designates them with the name iTemp.
34208  The compiler can be made to dump a human readable form of the code generated
34209  by using the -
34210 \begin_inset ERT
34211 status collapsed
34212
34213 \begin_layout Standard
34214
34215
34216 \backslash
34217 /
34218 \end_layout
34219
34220 \end_inset
34221
34222 -dumpraw option.
34223 \end_layout
34224
34225 \begin_layout Itemize
34226 This phase does the bulk of the standard optimizations and is also MCU independe
34227 nt.
34228  This phase can be broken down into several sub-phases:
34229 \newline
34230
34231 \newline
34232 Break down intermediate
34233  code (iCode) into basic blocks.
34234 \newline
34235 Do control flow & data flow analysis on the
34236  basic blocks.
34237 \newline
34238 Do local common subexpression elimination, then global subexpressio
34239 n elimination
34240 \newline
34241 Dead code elimination
34242 \newline
34243 Loop optimizations
34244 \newline
34245 If loop optimizations
34246  caused any changes then do 'global subexpression elimination' and 'dead
34247  code elimination' again.
34248 \end_layout
34249
34250 \begin_layout Itemize
34251 This phase determines the live-ranges; by live range I mean those iTemp
34252  variables defined by the compiler that still survive after all the optimization
34253 s.
34254  Live range analysis
34255 \begin_inset LatexCommand \index{Live range analysis}
34256
34257 \end_inset
34258
34259  is essential for register allocation, since these computation determines
34260  which of these iTemps will be assigned to registers, and for how long.
34261 \end_layout
34262
34263 \begin_layout Itemize
34264 Phase five is register allocation.
34265  There are two parts to this process.
34266 \newline
34267
34268 \newline
34269 The first part I call 'register packing'
34270  (for lack of a better term).
34271  In this case several MCU specific expression folding is done to reduce
34272  register pressure.
34273 \newline
34274
34275 \newline
34276 The second part is more MCU independent and deals with
34277  allocating registers to the remaining live ranges.
34278  A lot of MCU specific code does creep into this phase because of the limited
34279  number of index registers available in the 8051.
34280 \end_layout
34281
34282 \begin_layout Itemize
34283 The Code generation phase is (unhappily), entirely MCU dependent and very
34284  little (if any at all) of this code can be reused for other MCU.
34285  However the scheme for allocating a homogenized assembler operand for each
34286  iCode operand may be reused.
34287 \end_layout
34288
34289 \begin_layout Itemize
34290 As mentioned in the optimization section the peep-hole optimizer is rule
34291  based system, which can reprogrammed for other MCUs.
34292 \end_layout
34293
34294 \begin_layout Standard
34295 More information is available in a wiki
34296 \begin_inset LatexCommand \index{wiki}
34297
34298 \end_inset
34299
34300  (preliminary link 
34301 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
34302
34303 \end_inset
34304
34305 ) and in the thread 
34306 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
34307
34308 \end_inset
34309
34310  .
34311 \end_layout
34312
34313 \begin_layout Chapter
34314 Compiler internals
34315 \begin_inset LatexCommand \index{Compiler internals}
34316
34317 \end_inset
34318
34319
34320 \end_layout
34321
34322 \begin_layout Section
34323 The anatomy of the compiler
34324 \begin_inset LatexCommand \label{sub:The-anatomy-of}
34325
34326 \end_inset
34327
34328
34329 \end_layout
34330
34331 \begin_layout Standard
34332
34333 \shape italic
34334 This is an excerpt from an article published in Circuit Cellar Magazine
34335  in 
34336 \series bold
34337 August 2000
34338 \series default
34339 .
34340  It's a little outdated (the compiler is much more efficient now and user/develo
34341 per friendly), but pretty well exposes the guts of it all.
34342 \shape default
34343
34344 \newline
34345
34346 \newline
34347 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
34348  It is fairly easy to retarget for other 8-bit MCU.
34349  Here we take a look at some of the internals of the compiler.
34350  
34351 \end_layout
34352
34353 \begin_layout Paragraph*
34354 Parsing
34355 \begin_inset LatexCommand \index{Parsing}
34356
34357 \end_inset
34358
34359  
34360 \end_layout
34361
34362 \begin_layout Standard
34363 Parsing the input source file and creating an AST (Annotated Syntax Tree
34364 \begin_inset LatexCommand \index{Annotated syntax tree}
34365
34366 \end_inset
34367
34368 ).
34369  This phase also involves propagating types (annotating each node of the
34370  parse tree with type information) and semantic analysis.
34371  There are some MCU specific parsing rules.
34372  For example the storage classes, the extended storage classes are MCU specific
34373  while there may be a xdata storage class for 8051 there is no such storage
34374  class for z80 or Atmel AVR.
34375  SDCC allows MCU specific storage class extensions, i.e.
34376  xdata will be treated as a storage class specifier when parsing 8051 C
34377  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
34378  C code.
34379 \end_layout
34380
34381 \begin_layout Paragraph*
34382 Generating iCode
34383 \begin_inset LatexCommand \index{iCode}
34384
34385 \end_inset
34386
34387
34388 \end_layout
34389
34390 \begin_layout Standard
34391 Intermediate code generation.
34392  In this phase the AST is broken down into three-operand form (iCode).
34393  These three operand forms are represented as doubly linked lists.
34394  ICode is the term given to the intermediate form generated by the compiler.
34395  ICode example section shows some examples of iCode generated for some simple
34396  C source functions.
34397 \end_layout
34398
34399 \begin_layout Paragraph*
34400 Optimizations
34401 \begin_inset LatexCommand \index{Optimizations}
34402
34403 \end_inset
34404
34405 .
34406 \end_layout
34407
34408 \begin_layout Standard
34409 Bulk of the target independent optimizations is performed in this phase.
34410  The optimizations include constant propagation, common sub-expression eliminati
34411 on, loop invariant code movement, strength reduction of loop induction variables
34412  and dead-code elimination.
34413 \end_layout
34414
34415 \begin_layout Paragraph*
34416 Live range analysis
34417 \begin_inset LatexCommand \index{Live range analysis}
34418
34419 \end_inset
34420
34421
34422 \end_layout
34423
34424 \begin_layout Standard
34425 During intermediate code generation phase, the compiler assumes the target
34426  machine has infinite number of registers and generates a lot of temporary
34427  variables.
34428  The live range computation determines the lifetime of each of these compiler-ge
34429 nerated temporaries.
34430  A picture speaks a thousand words.
34431  ICode example sections show the live range annotations for each of the
34432  operand.
34433  It is important to note here, each iCode is assigned a number in the order
34434  of its execution in the function.
34435  The live ranges are computed in terms of these numbers.
34436  The from number is the number of the iCode which first defines the operand
34437  and the to number signifies the iCode which uses this operand last.
34438 \end_layout
34439
34440 \begin_layout Paragraph*
34441 Register Allocation
34442 \begin_inset LatexCommand \index{Register allocation}
34443
34444 \end_inset
34445
34446
34447 \end_layout
34448
34449 \begin_layout Standard
34450 The register allocation determines the type and number of registers needed
34451  by each operand.
34452  In most MCUs only a few registers can be used for indirect addressing.
34453  In case of 8051 for example the registers R0 & R1 can be used to indirectly
34454  address the internal ram and DPTR to indirectly address the external ram.
34455  The compiler will try to allocate the appropriate register to pointer variables
34456  if it can.
34457  ICode example section shows the operands annotated with the registers assigned
34458  to them.
34459  The compiler will try to keep operands in registers as much as possible;
34460  there are several schemes the compiler uses to do achieve this.
34461  When the compiler runs out of registers the compiler will check to see
34462  if there are any live operands which is not used or defined in the current
34463  basic block being processed, if there are any found then it will push that
34464  operand and use the registers in this block, the operand will then be popped
34465  at the end of the basic block.
34466  
34467 \end_layout
34468
34469 \begin_layout Standard
34470 There are other MCU specific considerations in this phase.
34471  Some MCUs have an accumulator; very short-lived operands could be assigned
34472  to the accumulator instead of a general-purpose register.
34473 \end_layout
34474
34475 \begin_layout Paragraph*
34476 Code generation
34477 \end_layout
34478
34479 \begin_layout Standard
34480 Figure II gives a table of iCode
34481 \begin_inset LatexCommand \index{iCode}
34482
34483 \end_inset
34484
34485  operations supported by the compiler.
34486  The code generation involves translating these operations into corresponding
34487  assembly code for the processor.
34488  This sounds overly simple but that is the essence of code generation.
34489  Some of the iCode operations are generated on a MCU specific manner for
34490  example, the z80 port does not use registers to pass parameters so the
34491  SEND and RECV iCode operations will not be generated, and it also does
34492  not support JUMPTABLES.
34493  
34494 \newline
34495
34496 \end_layout
34497
34498 \begin_layout Standard
34499
34500 \size footnotesize
34501 Figure II 
34502 \begin_inset Tabular
34503 <lyxtabular version="3" rows="39" columns="4">
34504 <features islongtable="true" headBottomDL="true">
34505 <column alignment="block" valignment="top" leftline="true" width="13col%">
34506 <column alignment="left" valignment="top" leftline="true" width="13col%">
34507 <column alignment="block" valignment="top" leftline="true" width="22col%">
34508 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
34509 <row topline="true" bottomline="true" endhead="true">
34510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34511 \begin_inset Text
34512
34513 \begin_layout Standard
34514
34515 \series bold
34516 iCode
34517 \series default
34518
34519 \begin_inset LatexCommand \index{iCode}
34520
34521 \end_inset
34522
34523
34524 \end_layout
34525
34526 \end_inset
34527 </cell>
34528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34529 \begin_inset Text
34530
34531 \begin_layout Standard
34532
34533 \series bold
34534 Operands
34535 \end_layout
34536
34537 \end_inset
34538 </cell>
34539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34540 \begin_inset Text
34541
34542 \begin_layout Standard
34543
34544 \series bold
34545 Description
34546 \end_layout
34547
34548 \end_inset
34549 </cell>
34550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34551 \begin_inset Text
34552
34553 \begin_layout Standard
34554
34555 \series bold
34556 C Equivalent
34557 \end_layout
34558
34559 \end_inset
34560 </cell>
34561 </row>
34562 <row topline="true">
34563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34564 \begin_inset Text
34565
34566 \begin_layout Standard
34567
34568 \size footnotesize
34569 '!'
34570 \end_layout
34571
34572 \end_inset
34573 </cell>
34574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34575 \begin_inset Text
34576
34577 \begin_layout Standard
34578
34579 \size footnotesize
34580 IC_LEFT() IC_RESULT()
34581 \end_layout
34582
34583 \end_inset
34584 </cell>
34585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34586 \begin_inset Text
34587
34588 \begin_layout Standard
34589
34590 \size footnotesize
34591 NOT operation 
34592 \end_layout
34593
34594 \end_inset
34595 </cell>
34596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34597 \begin_inset Text
34598
34599 \begin_layout Standard
34600
34601 \size footnotesize
34602 IC_RESULT = ! IC_LEFT;
34603 \end_layout
34604
34605 \end_inset
34606 </cell>
34607 </row>
34608 <row topline="true">
34609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34610 \begin_inset Text
34611
34612 \begin_layout Standard
34613
34614 \size footnotesize
34615 '~'
34616 \end_layout
34617
34618 \end_inset
34619 </cell>
34620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34621 \begin_inset Text
34622
34623 \begin_layout Standard
34624
34625 \size footnotesize
34626 IC_LEFT() IC_RESULT()
34627 \end_layout
34628
34629 \end_inset
34630 </cell>
34631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34632 \begin_inset Text
34633
34634 \begin_layout Standard
34635
34636 \size footnotesize
34637 Bitwise complement of 
34638 \end_layout
34639
34640 \end_inset
34641 </cell>
34642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34643 \begin_inset Text
34644
34645 \begin_layout Standard
34646
34647 \size footnotesize
34648 IC_RESULT = ~IC_LEFT;
34649 \end_layout
34650
34651 \end_inset
34652 </cell>
34653 </row>
34654 <row topline="true">
34655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34656 \begin_inset Text
34657
34658 \begin_layout Standard
34659
34660 \size footnotesize
34661 RRC
34662 \end_layout
34663
34664 \end_inset
34665 </cell>
34666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34667 \begin_inset Text
34668
34669 \begin_layout Standard
34670
34671 \size footnotesize
34672 IC_LEFT() IC_RESULT()
34673 \end_layout
34674
34675 \end_inset
34676 </cell>
34677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34678 \begin_inset Text
34679
34680 \begin_layout Standard
34681
34682 \size footnotesize
34683 Rotate right with carry
34684 \end_layout
34685
34686 \end_inset
34687 </cell>
34688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34689 \begin_inset Text
34690
34691 \begin_layout Standard
34692
34693 \size footnotesize
34694 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
34695 \end_layout
34696
34697 \end_inset
34698 </cell>
34699 </row>
34700 <row topline="true">
34701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34702 \begin_inset Text
34703
34704 \begin_layout Standard
34705
34706 \size footnotesize
34707 RLC
34708 \end_layout
34709
34710 \end_inset
34711 </cell>
34712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34713 \begin_inset Text
34714
34715 \begin_layout Standard
34716
34717 \size footnotesize
34718 IC_LEFT() IC_RESULT()
34719 \end_layout
34720
34721 \end_inset
34722 </cell>
34723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34724 \begin_inset Text
34725
34726 \begin_layout Standard
34727
34728 \size footnotesize
34729 Rotate left with carry
34730 \end_layout
34731
34732 \end_inset
34733 </cell>
34734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34735 \begin_inset Text
34736
34737 \begin_layout Standard
34738
34739 \size footnotesize
34740 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
34741 \end_layout
34742
34743 \end_inset
34744 </cell>
34745 </row>
34746 <row topline="true">
34747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34748 \begin_inset Text
34749
34750 \begin_layout Standard
34751
34752 \size footnotesize
34753 GETHBIT
34754 \end_layout
34755
34756 \end_inset
34757 </cell>
34758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34759 \begin_inset Text
34760
34761 \begin_layout Standard
34762
34763 \size footnotesize
34764 IC_LEFT() IC_RESULT()
34765 \end_layout
34766
34767 \end_inset
34768 </cell>
34769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34770 \begin_inset Text
34771
34772 \begin_layout Standard
34773
34774 \size footnotesize
34775 Get the highest order bit of IC_LEFT
34776 \end_layout
34777
34778 \end_inset
34779 </cell>
34780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34781 \begin_inset Text
34782
34783 \begin_layout Standard
34784
34785 \size footnotesize
34786 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
34787 \end_layout
34788
34789 \end_inset
34790 </cell>
34791 </row>
34792 <row topline="true">
34793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34794 \begin_inset Text
34795
34796 \begin_layout Standard
34797
34798 \size footnotesize
34799 UNARYMINUS
34800 \end_layout
34801
34802 \end_inset
34803 </cell>
34804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34805 \begin_inset Text
34806
34807 \begin_layout Standard
34808
34809 \size footnotesize
34810 IC_LEFT() IC_RESULT()
34811 \end_layout
34812
34813 \end_inset
34814 </cell>
34815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34816 \begin_inset Text
34817
34818 \begin_layout Standard
34819
34820 \size footnotesize
34821 Unary minus
34822 \end_layout
34823
34824 \end_inset
34825 </cell>
34826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34827 \begin_inset Text
34828
34829 \begin_layout Standard
34830
34831 \size footnotesize
34832 IC_RESULT = - IC_LEFT;
34833 \end_layout
34834
34835 \end_inset
34836 </cell>
34837 </row>
34838 <row topline="true">
34839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34840 \begin_inset Text
34841
34842 \begin_layout Standard
34843
34844 \size footnotesize
34845 IPUSH
34846 \end_layout
34847
34848 \end_inset
34849 </cell>
34850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34851 \begin_inset Text
34852
34853 \begin_layout Standard
34854
34855 \size footnotesize
34856 IC_LEFT()
34857 \end_layout
34858
34859 \end_inset
34860 </cell>
34861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34862 \begin_inset Text
34863
34864 \begin_layout Standard
34865
34866 \size footnotesize
34867 Push the operand into stack
34868 \end_layout
34869
34870 \end_inset
34871 </cell>
34872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34873 \begin_inset Text
34874
34875 \begin_layout Standard
34876
34877 \size footnotesize
34878 NONE
34879 \end_layout
34880
34881 \end_inset
34882 </cell>
34883 </row>
34884 <row topline="true">
34885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34886 \begin_inset Text
34887
34888 \begin_layout Standard
34889
34890 \size footnotesize
34891 IPOP
34892 \end_layout
34893
34894 \end_inset
34895 </cell>
34896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34897 \begin_inset Text
34898
34899 \begin_layout Standard
34900
34901 \size footnotesize
34902 IC_LEFT()
34903 \end_layout
34904
34905 \end_inset
34906 </cell>
34907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34908 \begin_inset Text
34909
34910 \begin_layout Standard
34911
34912 \size footnotesize
34913 Pop the operand from the stack 
34914 \end_layout
34915
34916 \end_inset
34917 </cell>
34918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34919 \begin_inset Text
34920
34921 \begin_layout Standard
34922
34923 \size footnotesize
34924 NONE
34925 \end_layout
34926
34927 \end_inset
34928 </cell>
34929 </row>
34930 <row topline="true">
34931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34932 \begin_inset Text
34933
34934 \begin_layout Standard
34935
34936 \size footnotesize
34937 CALL
34938 \end_layout
34939
34940 \end_inset
34941 </cell>
34942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34943 \begin_inset Text
34944
34945 \begin_layout Standard
34946
34947 \size footnotesize
34948 IC_LEFT() IC_RESULT()
34949 \end_layout
34950
34951 \end_inset
34952 </cell>
34953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34954 \begin_inset Text
34955
34956 \begin_layout Standard
34957
34958 \size footnotesize
34959 Call the function represented by IC_LEFT 
34960 \end_layout
34961
34962 \end_inset
34963 </cell>
34964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34965 \begin_inset Text
34966
34967 \begin_layout Standard
34968
34969 \size footnotesize
34970 IC_RESULT = IC_LEFT();
34971 \end_layout
34972
34973 \end_inset
34974 </cell>
34975 </row>
34976 <row topline="true">
34977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34978 \begin_inset Text
34979
34980 \begin_layout Standard
34981
34982 \size footnotesize
34983 PCALL
34984 \end_layout
34985
34986 \end_inset
34987 </cell>
34988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34989 \begin_inset Text
34990
34991 \begin_layout Standard
34992
34993 \size footnotesize
34994 IC_LEFT() IC_RESULT()
34995 \end_layout
34996
34997 \end_inset
34998 </cell>
34999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35000 \begin_inset Text
35001
35002 \begin_layout Standard
35003
35004 \size footnotesize
35005 Call via function pointer
35006 \end_layout
35007
35008 \end_inset
35009 </cell>
35010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35011 \begin_inset Text
35012
35013 \begin_layout Standard
35014
35015 \size footnotesize
35016 IC_RESULT = (*IC_LEFT)();
35017 \end_layout
35018
35019 \end_inset
35020 </cell>
35021 </row>
35022 <row topline="true">
35023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35024 \begin_inset Text
35025
35026 \begin_layout Standard
35027
35028 \size footnotesize
35029 RETURN
35030 \end_layout
35031
35032 \end_inset
35033 </cell>
35034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35035 \begin_inset Text
35036
35037 \begin_layout Standard
35038
35039 \size footnotesize
35040 IC_LEFT()
35041 \end_layout
35042
35043 \end_inset
35044 </cell>
35045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35046 \begin_inset Text
35047
35048 \begin_layout Standard
35049
35050 \size footnotesize
35051 Return the value in operand IC_LEFT 
35052 \end_layout
35053
35054 \end_inset
35055 </cell>
35056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35057 \begin_inset Text
35058
35059 \begin_layout Standard
35060
35061 \size footnotesize
35062 return IC_LEFT;
35063 \end_layout
35064
35065 \end_inset
35066 </cell>
35067 </row>
35068 <row topline="true">
35069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35070 \begin_inset Text
35071
35072 \begin_layout Standard
35073
35074 \size footnotesize
35075 LABEL
35076 \end_layout
35077
35078 \end_inset
35079 </cell>
35080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35081 \begin_inset Text
35082
35083 \begin_layout Standard
35084
35085 \size footnotesize
35086 IC_LABEL() 
35087 \end_layout
35088
35089 \end_inset
35090 </cell>
35091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35092 \begin_inset Text
35093
35094 \begin_layout Standard
35095
35096 \size footnotesize
35097 Label
35098 \end_layout
35099
35100 \end_inset
35101 </cell>
35102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35103 \begin_inset Text
35104
35105 \begin_layout Standard
35106
35107 \size footnotesize
35108 IC_LABEL:
35109 \end_layout
35110
35111 \end_inset
35112 </cell>
35113 </row>
35114 <row topline="true">
35115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35116 \begin_inset Text
35117
35118 \begin_layout Standard
35119
35120 \size footnotesize
35121 GOTO
35122 \end_layout
35123
35124 \end_inset
35125 </cell>
35126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35127 \begin_inset Text
35128
35129 \begin_layout Standard
35130
35131 \size footnotesize
35132 IC_LABEL() 
35133 \end_layout
35134
35135 \end_inset
35136 </cell>
35137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35138 \begin_inset Text
35139
35140 \begin_layout Standard
35141
35142 \size footnotesize
35143 Goto label
35144 \end_layout
35145
35146 \end_inset
35147 </cell>
35148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35149 \begin_inset Text
35150
35151 \begin_layout Standard
35152
35153 \size footnotesize
35154 goto IC_LABEL();
35155 \end_layout
35156
35157 \end_inset
35158 </cell>
35159 </row>
35160 <row topline="true">
35161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35162 \begin_inset Text
35163
35164 \begin_layout Standard
35165
35166 \size footnotesize
35167 '+'
35168 \end_layout
35169
35170 \end_inset
35171 </cell>
35172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35173 \begin_inset Text
35174
35175 \begin_layout Standard
35176
35177 \size footnotesize
35178 IC_LEFT() IC_RIGHT() IC_RESULT()
35179 \end_layout
35180
35181 \end_inset
35182 </cell>
35183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35184 \begin_inset Text
35185
35186 \begin_layout Standard
35187
35188 \size footnotesize
35189 Addition
35190 \end_layout
35191
35192 \end_inset
35193 </cell>
35194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35195 \begin_inset Text
35196
35197 \begin_layout Standard
35198
35199 \size footnotesize
35200 IC_RESULT = IC_LEFT + IC_RIGHT
35201 \end_layout
35202
35203 \end_inset
35204 </cell>
35205 </row>
35206 <row topline="true">
35207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35208 \begin_inset Text
35209
35210 \begin_layout Standard
35211
35212 \size footnotesize
35213 '-'
35214 \end_layout
35215
35216 \end_inset
35217 </cell>
35218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35219 \begin_inset Text
35220
35221 \begin_layout Standard
35222
35223 \size footnotesize
35224 IC_LEFT() IC_RIGHT() IC_RESULT()
35225 \end_layout
35226
35227 \end_inset
35228 </cell>
35229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35230 \begin_inset Text
35231
35232 \begin_layout Standard
35233
35234 \size footnotesize
35235 Subtraction
35236 \end_layout
35237
35238 \end_inset
35239 </cell>
35240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35241 \begin_inset Text
35242
35243 \begin_layout Standard
35244
35245 \size footnotesize
35246 IC_RESULT = IC_LEFT - IC_RIGHT 
35247 \end_layout
35248
35249 \end_inset
35250 </cell>
35251 </row>
35252 <row topline="true">
35253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35254 \begin_inset Text
35255
35256 \begin_layout Standard
35257
35258 \size footnotesize
35259 '*'
35260 \end_layout
35261
35262 \end_inset
35263 </cell>
35264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35265 \begin_inset Text
35266
35267 \begin_layout Standard
35268
35269 \size footnotesize
35270 IC_LEFT() IC_RIGHT() IC_RESULT()
35271 \end_layout
35272
35273 \end_inset
35274 </cell>
35275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35276 \begin_inset Text
35277
35278 \begin_layout Standard
35279
35280 \size footnotesize
35281 Multiplication 
35282 \end_layout
35283
35284 \end_inset
35285 </cell>
35286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35287 \begin_inset Text
35288
35289 \begin_layout Standard
35290
35291 \size footnotesize
35292 IC_RESULT = IC_LEFT * IC_RIGHT;
35293 \end_layout
35294
35295 \end_inset
35296 </cell>
35297 </row>
35298 <row topline="true">
35299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35300 \begin_inset Text
35301
35302 \begin_layout Standard
35303
35304 \size footnotesize
35305 '/'
35306 \end_layout
35307
35308 \end_inset
35309 </cell>
35310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35311 \begin_inset Text
35312
35313 \begin_layout Standard
35314
35315 \size footnotesize
35316 IC_LEFT() IC_RIGHT() IC_RESULT()
35317 \end_layout
35318
35319 \end_inset
35320 </cell>
35321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35322 \begin_inset Text
35323
35324 \begin_layout Standard
35325
35326 \size footnotesize
35327 Division
35328 \end_layout
35329
35330 \end_inset
35331 </cell>
35332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35333 \begin_inset Text
35334
35335 \begin_layout Standard
35336
35337 \size footnotesize
35338 IC_RESULT = IC_LEFT / IC_RIGHT;
35339 \end_layout
35340
35341 \end_inset
35342 </cell>
35343 </row>
35344 <row topline="true">
35345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35346 \begin_inset Text
35347
35348 \begin_layout Standard
35349
35350 \size footnotesize
35351 '%'
35352 \end_layout
35353
35354 \end_inset
35355 </cell>
35356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35357 \begin_inset Text
35358
35359 \begin_layout Standard
35360
35361 \size footnotesize
35362 IC_LEFT() IC_RIGHT() IC_RESULT()
35363 \end_layout
35364
35365 \end_inset
35366 </cell>
35367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35368 \begin_inset Text
35369
35370 \begin_layout Standard
35371
35372 \size footnotesize
35373 Modulus
35374 \end_layout
35375
35376 \end_inset
35377 </cell>
35378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35379 \begin_inset Text
35380
35381 \begin_layout Standard
35382
35383 \size footnotesize
35384 IC_RESULT = IC_LEFT % IC_RIGHT;
35385 \end_layout
35386
35387 \end_inset
35388 </cell>
35389 </row>
35390 <row topline="true">
35391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35392 \begin_inset Text
35393
35394 \begin_layout Standard
35395
35396 \size footnotesize
35397 '<'
35398 \end_layout
35399
35400 \end_inset
35401 </cell>
35402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35403 \begin_inset Text
35404
35405 \begin_layout Standard
35406
35407 \size footnotesize
35408 IC_LEFT() IC_RIGHT() IC_RESULT()
35409 \end_layout
35410
35411 \end_inset
35412 </cell>
35413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35414 \begin_inset Text
35415
35416 \begin_layout Standard
35417
35418 \size footnotesize
35419 Less than
35420 \end_layout
35421
35422 \end_inset
35423 </cell>
35424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35425 \begin_inset Text
35426
35427 \begin_layout Standard
35428
35429 \size footnotesize
35430 IC_RESULT = IC_LEFT < IC_RIGHT;
35431 \end_layout
35432
35433 \end_inset
35434 </cell>
35435 </row>
35436 <row topline="true">
35437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35438 \begin_inset Text
35439
35440 \begin_layout Standard
35441
35442 \size footnotesize
35443 '>'
35444 \end_layout
35445
35446 \end_inset
35447 </cell>
35448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35449 \begin_inset Text
35450
35451 \begin_layout Standard
35452
35453 \size footnotesize
35454 IC_LEFT() IC_RIGHT() IC_RESULT()
35455 \end_layout
35456
35457 \end_inset
35458 </cell>
35459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35460 \begin_inset Text
35461
35462 \begin_layout Standard
35463
35464 \size footnotesize
35465 Greater than 
35466 \end_layout
35467
35468 \end_inset
35469 </cell>
35470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35471 \begin_inset Text
35472
35473 \begin_layout Standard
35474
35475 \size footnotesize
35476 IC_RESULT = IC_LEFT > IC_RIGHT;
35477 \end_layout
35478
35479 \end_inset
35480 </cell>
35481 </row>
35482 <row topline="true">
35483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35484 \begin_inset Text
35485
35486 \begin_layout Standard
35487
35488 \size footnotesize
35489 EQ_OP
35490 \end_layout
35491
35492 \end_inset
35493 </cell>
35494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35495 \begin_inset Text
35496
35497 \begin_layout Standard
35498
35499 \size footnotesize
35500 IC_LEFT() IC_RIGHT() IC_RESULT()
35501 \end_layout
35502
35503 \end_inset
35504 </cell>
35505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35506 \begin_inset Text
35507
35508 \begin_layout Standard
35509
35510 \size footnotesize
35511 Equal to 
35512 \end_layout
35513
35514 \end_inset
35515 </cell>
35516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35517 \begin_inset Text
35518
35519 \begin_layout Standard
35520
35521 \size footnotesize
35522 IC_RESULT = IC_LEFT == IC_RIGHT;
35523 \end_layout
35524
35525 \end_inset
35526 </cell>
35527 </row>
35528 <row topline="true">
35529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35530 \begin_inset Text
35531
35532 \begin_layout Standard
35533
35534 \size footnotesize
35535 AND_OP
35536 \end_layout
35537
35538 \end_inset
35539 </cell>
35540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35541 \begin_inset Text
35542
35543 \begin_layout Standard
35544
35545 \size footnotesize
35546 IC_LEFT() IC_RIGHT() IC_RESULT() 
35547 \end_layout
35548
35549 \end_inset
35550 </cell>
35551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35552 \begin_inset Text
35553
35554 \begin_layout Standard
35555
35556 \size footnotesize
35557 Logical and operation
35558 \end_layout
35559
35560 \end_inset
35561 </cell>
35562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35563 \begin_inset Text
35564
35565 \begin_layout Standard
35566
35567 \size footnotesize
35568 IC_RESULT = IC_LEFT && IC_RIGHT; 
35569 \end_layout
35570
35571 \end_inset
35572 </cell>
35573 </row>
35574 <row topline="true">
35575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35576 \begin_inset Text
35577
35578 \begin_layout Standard
35579
35580 \size footnotesize
35581 OR_OP
35582 \end_layout
35583
35584 \end_inset
35585 </cell>
35586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35587 \begin_inset Text
35588
35589 \begin_layout Standard
35590
35591 \size footnotesize
35592 IC_LEFT() IC_RIGHT() IC_RESULT() 
35593 \end_layout
35594
35595 \end_inset
35596 </cell>
35597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35598 \begin_inset Text
35599
35600 \begin_layout Standard
35601
35602 \size footnotesize
35603 Logical or operation 
35604 \end_layout
35605
35606 \end_inset
35607 </cell>
35608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35609 \begin_inset Text
35610
35611 \begin_layout Standard
35612
35613 \size footnotesize
35614 IC_RESULT = IC_LEFT || IC_RIGHT; 
35615 \end_layout
35616
35617 \end_inset
35618 </cell>
35619 </row>
35620 <row topline="true">
35621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35622 \begin_inset Text
35623
35624 \begin_layout Standard
35625
35626 \size footnotesize
35627 '^'
35628 \end_layout
35629
35630 \end_inset
35631 </cell>
35632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35633 \begin_inset Text
35634
35635 \begin_layout Standard
35636
35637 \size footnotesize
35638 IC_LEFT() IC_RIGHT() IC_RESULT() 
35639 \end_layout
35640
35641 \end_inset
35642 </cell>
35643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35644 \begin_inset Text
35645
35646 \begin_layout Standard
35647
35648 \size footnotesize
35649 Exclusive OR
35650 \end_layout
35651
35652 \end_inset
35653 </cell>
35654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35655 \begin_inset Text
35656
35657 \begin_layout Standard
35658
35659 \size footnotesize
35660 IC_RESULT = IC_LEFT ^ IC_RIGHT;
35661 \end_layout
35662
35663 \end_inset
35664 </cell>
35665 </row>
35666 <row topline="true">
35667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35668 \begin_inset Text
35669
35670 \begin_layout Standard
35671
35672 \size footnotesize
35673 '|'
35674 \end_layout
35675
35676 \end_inset
35677 </cell>
35678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35679 \begin_inset Text
35680
35681 \begin_layout Standard
35682
35683 \size footnotesize
35684 IC_LEFT() IC_RIGHT() IC_RESULT() 
35685 \end_layout
35686
35687 \end_inset
35688 </cell>
35689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35690 \begin_inset Text
35691
35692 \begin_layout Standard
35693
35694 \size footnotesize
35695 Bitwise OR 
35696 \end_layout
35697
35698 \end_inset
35699 </cell>
35700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35701 \begin_inset Text
35702
35703 \begin_layout Standard
35704
35705 \size footnotesize
35706 IC_RESULT = IC_LEFT | IC_RIGHT;
35707 \end_layout
35708
35709 \end_inset
35710 </cell>
35711 </row>
35712 <row topline="true">
35713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35714 \begin_inset Text
35715
35716 \begin_layout Standard
35717
35718 \size footnotesize
35719 BITWISEAND
35720 \end_layout
35721
35722 \end_inset
35723 </cell>
35724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35725 \begin_inset Text
35726
35727 \begin_layout Standard
35728
35729 \size footnotesize
35730 IC_LEFT() IC_RIGHT() IC_RESULT()
35731 \end_layout
35732
35733 \end_inset
35734 </cell>
35735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35736 \begin_inset Text
35737
35738 \begin_layout Standard
35739
35740 \size footnotesize
35741 Bitwise AND 
35742 \end_layout
35743
35744 \end_inset
35745 </cell>
35746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35747 \begin_inset Text
35748
35749 \begin_layout Standard
35750
35751 \size footnotesize
35752 IC_RESULT = IC_LEFT & IC_RIGHT;
35753 \end_layout
35754
35755 \end_inset
35756 </cell>
35757 </row>
35758 <row topline="true">
35759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35760 \begin_inset Text
35761
35762 \begin_layout Standard
35763
35764 \size footnotesize
35765 LEFT_OP
35766 \end_layout
35767
35768 \end_inset
35769 </cell>
35770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35771 \begin_inset Text
35772
35773 \begin_layout Standard
35774
35775 \size footnotesize
35776 IC_LEFT() IC_RIGHT() IC_RESULT()
35777 \end_layout
35778
35779 \end_inset
35780 </cell>
35781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35782 \begin_inset Text
35783
35784 \begin_layout Standard
35785
35786 \size footnotesize
35787 Left shift 
35788 \end_layout
35789
35790 \end_inset
35791 </cell>
35792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35793 \begin_inset Text
35794
35795 \begin_layout Standard
35796
35797 \size footnotesize
35798 IC_RESULT = IC_LEFT << IC_RIGHT 
35799 \end_layout
35800
35801 \end_inset
35802 </cell>
35803 </row>
35804 <row topline="true">
35805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35806 \begin_inset Text
35807
35808 \begin_layout Standard
35809
35810 \size footnotesize
35811 RIGHT_OP
35812 \end_layout
35813
35814 \end_inset
35815 </cell>
35816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35817 \begin_inset Text
35818
35819 \begin_layout Standard
35820
35821 \size footnotesize
35822 IC_LEFT() IC_RIGHT() IC_RESULT()
35823 \end_layout
35824
35825 \end_inset
35826 </cell>
35827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35828 \begin_inset Text
35829
35830 \begin_layout Standard
35831
35832 \size footnotesize
35833 Right shift
35834 \end_layout
35835
35836 \end_inset
35837 </cell>
35838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35839 \begin_inset Text
35840
35841 \begin_layout Standard
35842
35843 \size footnotesize
35844 IC_RESULT = IC_LEFT >> IC_RIGHT 
35845 \end_layout
35846
35847 \end_inset
35848 </cell>
35849 </row>
35850 <row topline="true">
35851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35852 \begin_inset Text
35853
35854 \begin_layout Standard
35855
35856 \size footnotesize
35857 GET_VALUE_
35858 \newline
35859 AT_ ADDRESS
35860 \end_layout
35861
35862 \end_inset
35863 </cell>
35864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35865 \begin_inset Text
35866
35867 \begin_layout Standard
35868
35869 \size footnotesize
35870 IC_LEFT() IC_RESULT()
35871 \end_layout
35872
35873 \end_inset
35874 </cell>
35875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35876 \begin_inset Text
35877
35878 \begin_layout Standard
35879
35880 \size footnotesize
35881 Indirect fetch 
35882 \end_layout
35883
35884 \end_inset
35885 </cell>
35886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35887 \begin_inset Text
35888
35889 \begin_layout Standard
35890
35891 \size footnotesize
35892 IC_RESULT = (*IC_LEFT);
35893 \end_layout
35894
35895 \end_inset
35896 </cell>
35897 </row>
35898 <row topline="true">
35899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35900 \begin_inset Text
35901
35902 \begin_layout Standard
35903
35904 \size footnotesize
35905 POINTER_SET
35906 \end_layout
35907
35908 \end_inset
35909 </cell>
35910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35911 \begin_inset Text
35912
35913 \begin_layout Standard
35914
35915 \size footnotesize
35916 IC_RIGHT() IC_RESULT() 
35917 \end_layout
35918
35919 \end_inset
35920 </cell>
35921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35922 \begin_inset Text
35923
35924 \begin_layout Standard
35925
35926 \size footnotesize
35927 Indirect set
35928 \end_layout
35929
35930 \end_inset
35931 </cell>
35932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35933 \begin_inset Text
35934
35935 \begin_layout Standard
35936
35937 \size footnotesize
35938 (*IC_RESULT) = IC_RIGHT;
35939 \end_layout
35940
35941 \end_inset
35942 </cell>
35943 </row>
35944 <row topline="true">
35945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35946 \begin_inset Text
35947
35948 \begin_layout Standard
35949
35950 \size footnotesize
35951 '='
35952 \end_layout
35953
35954 \end_inset
35955 </cell>
35956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35957 \begin_inset Text
35958
35959 \begin_layout Standard
35960
35961 \size footnotesize
35962 IC_RIGHT() IC_RESULT()
35963 \end_layout
35964
35965 \end_inset
35966 </cell>
35967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35968 \begin_inset Text
35969
35970 \begin_layout Standard
35971
35972 \size footnotesize
35973 Assignment
35974 \end_layout
35975
35976 \end_inset
35977 </cell>
35978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35979 \begin_inset Text
35980
35981 \begin_layout Standard
35982
35983 \size footnotesize
35984 IC_RESULT = IC_RIGHT;
35985 \end_layout
35986
35987 \end_inset
35988 </cell>
35989 </row>
35990 <row topline="true">
35991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35992 \begin_inset Text
35993
35994 \begin_layout Standard
35995
35996 \size footnotesize
35997 IFX
35998 \end_layout
35999
36000 \end_inset
36001 </cell>
36002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36003 \begin_inset Text
36004
36005 \begin_layout Standard
36006
36007 \size footnotesize
36008 IC_COND IC_TRUE IC_LABEL
36009 \end_layout
36010
36011 \end_inset
36012 </cell>
36013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36014 \begin_inset Text
36015
36016 \begin_layout Standard
36017
36018 \size footnotesize
36019 Conditional jump.
36020  If true label is present then jump to true label if condition is true else
36021  jump to false label if condition is false 
36022 \end_layout
36023
36024 \end_inset
36025 </cell>
36026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36027 \begin_inset Text
36028
36029 \begin_layout Standard
36030
36031 \size footnotesize
36032 if (IC_COND) goto IC_TRUE; 
36033 \newline
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 Or 
36037 \newline
36038 If (!IC_COND) goto IC_FALSE;
36039 \end_layout
36040
36041 \end_inset
36042 </cell>
36043 </row>
36044 <row topline="true">
36045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36046 \begin_inset Text
36047
36048 \begin_layout Standard
36049
36050 \size footnotesize
36051 ADDRESS_OF
36052 \end_layout
36053
36054 \end_inset
36055 </cell>
36056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36057 \begin_inset Text
36058
36059 \begin_layout Standard
36060
36061 \size footnotesize
36062 IC_LEFT() IC_RESULT()
36063 \end_layout
36064
36065 \end_inset
36066 </cell>
36067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36068 \begin_inset Text
36069
36070 \begin_layout Standard
36071
36072 \size footnotesize
36073 Address of 
36074 \end_layout
36075
36076 \end_inset
36077 </cell>
36078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36079 \begin_inset Text
36080
36081 \begin_layout Standard
36082
36083 \size footnotesize
36084 IC_RESULT = &IC_LEFT();
36085 \end_layout
36086
36087 \end_inset
36088 </cell>
36089 </row>
36090 <row topline="true">
36091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36092 \begin_inset Text
36093
36094 \begin_layout Standard
36095
36096 \size footnotesize
36097 JUMPTABLE
36098 \end_layout
36099
36100 \end_inset
36101 </cell>
36102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36103 \begin_inset Text
36104
36105 \begin_layout Standard
36106
36107 \size footnotesize
36108 IC_JTCOND IC_JTLABELS
36109 \end_layout
36110
36111 \end_inset
36112 </cell>
36113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36114 \begin_inset Text
36115
36116 \begin_layout Standard
36117
36118 \size footnotesize
36119 Jump to list of labels depending on the value of JTCOND
36120 \end_layout
36121
36122 \end_inset
36123 </cell>
36124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36125 \begin_inset Text
36126
36127 \begin_layout Standard
36128
36129 \size footnotesize
36130 Switch statement
36131 \end_layout
36132
36133 \end_inset
36134 </cell>
36135 </row>
36136 <row topline="true">
36137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36138 \begin_inset Text
36139
36140 \begin_layout Standard
36141
36142 \size footnotesize
36143 CAST
36144 \end_layout
36145
36146 \end_inset
36147 </cell>
36148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36149 \begin_inset Text
36150
36151 \begin_layout Standard
36152
36153 \size footnotesize
36154 IC_RIGHT() IC_LEFT() IC_RESULT()
36155 \end_layout
36156
36157 \end_inset
36158 </cell>
36159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36160 \begin_inset Text
36161
36162 \begin_layout Standard
36163
36164 \size footnotesize
36165 Cast types 
36166 \end_layout
36167
36168 \end_inset
36169 </cell>
36170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36171 \begin_inset Text
36172
36173 \begin_layout Standard
36174
36175 \size footnotesize
36176 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
36177 \end_layout
36178
36179 \end_inset
36180 </cell>
36181 </row>
36182 <row topline="true">
36183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36184 \begin_inset Text
36185
36186 \begin_layout Standard
36187
36188 \size footnotesize
36189 SEND
36190 \end_layout
36191
36192 \end_inset
36193 </cell>
36194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36195 \begin_inset Text
36196
36197 \begin_layout Standard
36198
36199 \size footnotesize
36200 IC_LEFT()
36201 \end_layout
36202
36203 \end_inset
36204 </cell>
36205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36206 \begin_inset Text
36207
36208 \begin_layout Standard
36209
36210 \size footnotesize
36211 This is used for passing parameters in registers; 
36212 \newline
36213 move IC_LEFT to the next
36214  available parameter register.
36215 \end_layout
36216
36217 \end_inset
36218 </cell>
36219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36220 \begin_inset Text
36221
36222 \begin_layout Standard
36223
36224 \size footnotesize
36225 None
36226 \end_layout
36227
36228 \end_inset
36229 </cell>
36230 </row>
36231 <row topline="true">
36232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36233 \begin_inset Text
36234
36235 \begin_layout Standard
36236
36237 \size footnotesize
36238 RECV
36239 \end_layout
36240
36241 \end_inset
36242 </cell>
36243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36244 \begin_inset Text
36245
36246 \begin_layout Standard
36247
36248 \size footnotesize
36249 IC_RESULT()
36250 \end_layout
36251
36252 \end_inset
36253 </cell>
36254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36255 \begin_inset Text
36256
36257 \begin_layout Standard
36258
36259 \size footnotesize
36260 This is used for receiving parameters passed in registers;
36261 \newline
36262 Move the values
36263  in the next parameter register to IC_RESULT 
36264 \end_layout
36265
36266 \end_inset
36267 </cell>
36268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36269 \begin_inset Text
36270
36271 \begin_layout Standard
36272
36273 \size footnotesize
36274 None
36275 \end_layout
36276
36277 \end_inset
36278 </cell>
36279 </row>
36280 <row topline="true" bottomline="true">
36281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36282 \begin_inset Text
36283
36284 \begin_layout Standard
36285
36286 \shape slanted
36287 \size footnotesize
36288 (some more have been added)
36289 \end_layout
36290
36291 \end_inset
36292 </cell>
36293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36294 \begin_inset Text
36295
36296 \begin_layout Standard
36297
36298 \end_layout
36299
36300 \end_inset
36301 </cell>
36302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36303 \begin_inset Text
36304
36305 \begin_layout Standard
36306
36307 \end_layout
36308
36309 \end_inset
36310 </cell>
36311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36312 \begin_inset Text
36313
36314 \begin_layout Standard
36315
36316 \shape slanted
36317 \size footnotesize
36318 see f.e.
36319  
36320 \family typewriter
36321 gen51Code()
36322 \family default
36323  in 
36324 \family typewriter
36325 src/mcs51/gen.c
36326 \end_layout
36327
36328 \end_inset
36329 </cell>
36330 </row>
36331 </lyxtabular>
36332
36333 \end_inset
36334
36335
36336 \end_layout
36337
36338 \begin_layout Standard
36339 \begin_inset Note Comment
36340 status collapsed
36341
36342 \begin_layout Standard
36343 In the original article Figure II was announced to be downloadable on 
36344 \shape italic
36345 Circuit Cellar
36346 \shape default
36347 's web site.
36348  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
36349 \end_layout
36350
36351 \end_inset
36352
36353
36354 \end_layout
36355
36356 \begin_layout Paragraph*
36357 ICode Example
36358 \begin_inset LatexCommand \index{iCode}
36359
36360 \end_inset
36361
36362
36363 \end_layout
36364
36365 \begin_layout Standard
36366 This section shows some details of iCode.
36367  The example C code does not do anything useful; it is used as an example
36368  to illustrate the intermediate code generated by the compiler.
36369 \end_layout
36370
36371 \begin_layout Verse
36372
36373 \family typewriter
36374 1.\InsetSpace ~
36375 xdata int * p;
36376 \newline
36377 2.\InsetSpace ~
36378 int gint;
36379 \newline
36380 3.\InsetSpace ~
36381 /* This function does nothing useful.
36382  It is used
36383 \newline
36384 4.\InsetSpace ~
36385 \InsetSpace ~
36386 \InsetSpace ~
36387 \InsetSpace ~
36388 for the purpose of explaining iCode */
36389 \newline
36390 5.\InsetSpace ~
36391 short function (data
36392  int *x)
36393 \newline
36394 6.\InsetSpace ~
36395 {
36396 \newline
36397 7.\InsetSpace ~
36398 \InsetSpace ~
36399 \InsetSpace ~
36400 short i=10; \InsetSpace ~
36401 \InsetSpace ~
36402 /* dead initialization eliminated */
36403 \newline
36404 8.\InsetSpace ~
36405 \InsetSpace ~
36406 \InsetSpace ~
36407 short sum=10;
36408  /* dead initialization eliminated */
36409 \newline
36410 9.\InsetSpace ~
36411 \InsetSpace ~
36412 \InsetSpace ~
36413 short mul;
36414 \newline
36415 10.\InsetSpace ~
36416 \InsetSpace ~
36417 int j ;
36418 \newline
36419 11.\InsetSpace ~
36420 \InsetSpace ~
36421 while (*x) *x++
36422  = *p++; 
36423 \newline
36424 12.\InsetSpace ~
36425 \InsetSpace ~
36426 \InsetSpace ~
36427 \InsetSpace ~
36428 sum = 0 ; 
36429 \newline
36430 13.\InsetSpace ~
36431 \InsetSpace ~
36432 mul = 0;
36433 \newline
36434 14.\InsetSpace ~
36435 \InsetSpace ~
36436 /* compiler detects i,j to be induction
36437  variables */
36438 \newline
36439 15.\InsetSpace ~
36440 \InsetSpace ~
36441 for (i = 0, j = 10 ; i < 10 ; i++, j
36442 \family default
36443 -
36444 \begin_inset ERT
36445 status collapsed
36446
36447 \begin_layout Standard
36448
36449
36450 \backslash
36451 /
36452 \end_layout
36453
36454 \end_inset
36455
36456 -
36457 \family typewriter
36458 ) {
36459 \newline
36460 16.\InsetSpace ~
36461 \InsetSpace ~
36462 \InsetSpace ~
36463 \InsetSpace ~
36464 sum += i;
36465 \newline
36466 17.\InsetSpace ~
36467 \InsetSpace ~
36468 \InsetSpace ~
36469 \InsetSpace ~
36470 mul += i * 3; \InsetSpace ~
36471 \InsetSpace ~
36472 /* this multiplication remains */
36473 \newline
36474 18.\InsetSpace ~
36475 \InsetSpace ~
36476 \InsetSpace ~
36477 \InsetSpace ~
36478 gint +=
36479  j * 3;\InsetSpace ~
36480 \InsetSpace ~
36481 /* this multiplication changed to addition */
36482 \newline
36483 19.\InsetSpace ~
36484 \InsetSpace ~
36485 }
36486 \newline
36487 20.\InsetSpace ~
36488 \InsetSpace ~
36489 return sum+mul;
36490 \newline
36491 21.\InsetSpace ~
36492 }
36493 \end_layout
36494
36495 \begin_layout Standard
36496 In addition to the operands each iCode contains information about the filename
36497  and line it corresponds to in the source file.
36498  The first field in the listing should be interpreted as follows:
36499 \newline
36500
36501 \shape italic
36502 \size footnotesize
36503 Filename(linenumber: iCode Execution sequence number : ICode hash table
36504  key : loop depth of the iCode).
36505 \shape default
36506 \size default
36507
36508 \newline
36509 Then follows the human readable form of the ICode operation.
36510  Each operand of this triplet form can be of three basic types a) compiler
36511  generated temporary b) user defined variable c) a constant value.
36512  Note that local variables and parameters are replaced by compiler generated
36513  temporaries.
36514  Live ranges
36515 \begin_inset LatexCommand \index{Live range analysis}
36516
36517 \end_inset
36518
36519  are computed only for temporaries (i.e.
36520  live ranges are not computed for global variables).
36521  Registers
36522 \begin_inset LatexCommand \index{Register allocation}
36523
36524 \end_inset
36525
36526  are allocated for temporaries only.
36527  Operands are formatted in the following manner:
36528 \newline
36529
36530 \shape italic
36531 \size footnotesize
36532 Operand Name [lr live-from : live-to ] { type information } [ registers
36533  allocated ].
36534 \shape default
36535 \size default
36536
36537 \newline
36538 As mentioned earlier the live ranges are computed in terms of the execution
36539  sequence number of the iCodes, for example 
36540 \newline
36541 the iTemp0 is live from (i.e.
36542  first defined in iCode with execution sequence number 3, and is last used
36543  in the iCode with sequence number 5).
36544  For induction variables such as iTemp21 the live range computation extends
36545  the lifetime from the start to the end of the loop.
36546 \newline
36547 The register allocator
36548  used the live range information to allocate registers, the same registers
36549  may be used for different temporaries if their live ranges do not overlap,
36550  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
36551  ranges do not overlap.
36552  In addition the allocator also takes into consideration the type and usage
36553  of a temporary, for example itemp6 is a pointer to near space and is used
36554  as to fetch data from (i.e.
36555  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
36556  Some short lived temporaries are allocated to special registers which have
36557  meaning to the code generator e.g.
36558  iTemp13 is allocated to a pseudo register CC which tells the back end that
36559  the temporary is used only for a conditional jump the code generation makes
36560  use of this information to optimize a compare and jump ICode.
36561 \newline
36562 There are several
36563  loop optimizations
36564 \begin_inset LatexCommand \index{Loop optimization}
36565
36566 \end_inset
36567
36568  performed by the compiler.
36569  It can detect induction variables iTemp21(i) and iTemp23(j).
36570  Also note the compiler does selective strength reduction
36571 \begin_inset LatexCommand \index{Strength reduction}
36572
36573 \end_inset
36574
36575 , i.e.
36576  the multiplication of an induction variable in line 18 (gint = j * 3) is
36577  changed to addition, a new temporary iTemp17 is allocated and assigned
36578  a initial value, a constant 3 is then added for each iteration of the loop.
36579  The compiler does not change the multiplication
36580 \begin_inset LatexCommand \index{Multiplication}
36581
36582 \end_inset
36583
36584  in line 17 however since the processor does support an 8 * 8 bit multiplication.
36585 \newline
36586
36587 Note the dead code elimination
36588 \begin_inset LatexCommand \index{Dead-code elimination}
36589
36590 \end_inset
36591
36592  optimization eliminated the dead assignments in line 7 & 8 to I and sum
36593  respectively.
36594 \newline
36595
36596 \end_layout
36597
36598 \begin_layout Standard
36599
36600 \size footnotesize
36601 Sample.c (5:1:0:0) _entry($9) :
36602 \end_layout
36603
36604 \begin_layout Standard
36605
36606 \size footnotesize
36607 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
36608 \end_layout
36609
36610 \begin_layout Standard
36611
36612 \size footnotesize
36613 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
36614 \end_layout
36615
36616 \begin_layout Standard
36617
36618 \size footnotesize
36619 Sample.c(11:4:53:0) preHeaderLbl0($11) :
36620 \end_layout
36621
36622 \begin_layout Standard
36623
36624 \size footnotesize
36625 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
36626  * int}[r2]
36627 \end_layout
36628
36629 \begin_layout Standard
36630
36631 \size footnotesize
36632 Sample.c(11:6:5:1) _whilecontinue_0($1) :
36633 \end_layout
36634
36635 \begin_layout Standard
36636
36637 \size footnotesize
36638 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
36639  int}[r0]]
36640 \end_layout
36641
36642 \begin_layout Standard
36643
36644 \size footnotesize
36645 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
36646 \end_layout
36647
36648 \begin_layout Standard
36649
36650 \size footnotesize
36651 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
36652  * int}
36653 \end_layout
36654
36655 \begin_layout Standard
36656
36657 \size footnotesize
36658 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
36659  {short}
36660 \end_layout
36661
36662 \begin_layout Standard
36663
36664 \size footnotesize
36665 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
36666  * int}[DPTR]]
36667 \end_layout
36668
36669 \begin_layout Standard
36670
36671 \size footnotesize
36672 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
36673 }[r2 r3]
36674 \end_layout
36675
36676 \begin_layout Standard
36677
36678 \size footnotesize
36679 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
36680  * int}[r0] + 0x2 {short}
36681 \end_layout
36682
36683 \begin_layout Standard
36684
36685 \size footnotesize
36686 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
36687 \end_layout
36688
36689 \begin_layout Standard
36690
36691 \size footnotesize
36692 Sample.c(11:17:21:0)_whilebreak_0($3) :
36693 \end_layout
36694
36695 \begin_layout Standard
36696
36697 \size footnotesize
36698 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
36699 \end_layout
36700
36701 \begin_layout Standard
36702
36703 \size footnotesize
36704 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
36705 \end_layout
36706
36707 \begin_layout Standard
36708
36709 \size footnotesize
36710 Sample.c(15:20:54:0)preHeaderLbl1($13) :
36711 \end_layout
36712
36713 \begin_layout Standard
36714
36715 \size footnotesize
36716 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
36717 \end_layout
36718
36719 \begin_layout Standard
36720
36721 \size footnotesize
36722 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
36723 \end_layout
36724
36725 \begin_layout Standard
36726
36727 \size footnotesize
36728 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
36729 \end_layout
36730
36731 \begin_layout Standard
36732
36733 \size footnotesize
36734 Sample.c(15:24:26:1)_forcond_0($4) :
36735 \end_layout
36736
36737 \begin_layout Standard
36738
36739 \size footnotesize
36740 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
36741  < 0xa {short}
36742 \end_layout
36743
36744 \begin_layout Standard
36745
36746 \size footnotesize
36747 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
36748 \end_layout
36749
36750 \begin_layout Standard
36751
36752 \size footnotesize
36753 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
36754  + ITemp21 [lr21:38]{short}[r4]
36755 \end_layout
36756
36757 \begin_layout Standard
36758
36759 \size footnotesize
36760 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
36761  * 0x3 {short}
36762 \end_layout
36763
36764 \begin_layout Standard
36765
36766 \size footnotesize
36767 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
36768  + iTemp15 [lr29:30]{short}[r1]
36769 \end_layout
36770
36771 \begin_layout Standard
36772
36773 \size footnotesize
36774 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
36775  r0]- 0x3 {short}
36776 \end_layout
36777
36778 \begin_layout Standard
36779
36780 \size footnotesize
36781 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
36782 int}[r7 r0]
36783 \end_layout
36784
36785 \begin_layout Standard
36786
36787 \size footnotesize
36788 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
36789  + 0x1 {short}
36790 \end_layout
36791
36792 \begin_layout Standard
36793
36794 \size footnotesize
36795 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
36796  r6]- 0x1 {short}
36797 \end_layout
36798
36799 \begin_layout Standard
36800
36801 \size footnotesize
36802 Sample.c(19:38:47:1) goto _forcond_0($4)
36803 \end_layout
36804
36805 \begin_layout Standard
36806
36807 \size footnotesize
36808 Sample.c(19:39:48:0)_forbreak_0($7) :
36809 \end_layout
36810
36811 \begin_layout Standard
36812
36813 \size footnotesize
36814 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
36815  + ITemp11 [lr19:40]{short}[r3]
36816 \end_layout
36817
36818 \begin_layout Standard
36819
36820 \size footnotesize
36821 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
36822 \end_layout
36823
36824 \begin_layout Standard
36825
36826 \size footnotesize
36827 Sample.c(20:42:51:0)_return($8) :
36828 \end_layout
36829
36830 \begin_layout Standard
36831
36832 \size footnotesize
36833 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
36834 \size default
36835
36836 \newline
36837
36838 \newline
36839 Finally the code generated for this function:
36840 \newline
36841
36842 \end_layout
36843
36844 \begin_layout Standard
36845
36846 \size footnotesize
36847 .area DSEG (DATA)
36848 \end_layout
36849
36850 \begin_layout Standard
36851
36852 \size footnotesize
36853 _p::
36854 \end_layout
36855
36856 \begin_layout Standard
36857
36858 \size footnotesize
36859 \InsetSpace ~
36860 \InsetSpace ~
36861 .ds 2
36862 \end_layout
36863
36864 \begin_layout Standard
36865
36866 \size footnotesize
36867 _gint::
36868 \end_layout
36869
36870 \begin_layout Standard
36871
36872 \size footnotesize
36873 \InsetSpace ~
36874 \InsetSpace ~
36875 .ds 2
36876 \end_layout
36877
36878 \begin_layout Standard
36879
36880 \size footnotesize
36881 ; sample.c 5
36882 \end_layout
36883
36884 \begin_layout Standard
36885
36886 \size footnotesize
36887 ; ----------------------------------------------
36888 \end_layout
36889
36890 \begin_layout Standard
36891
36892 \size footnotesize
36893 ; function function
36894 \end_layout
36895
36896 \begin_layout Standard
36897
36898 \size footnotesize
36899 ; ----------------------------------------------
36900 \end_layout
36901
36902 \begin_layout Standard
36903
36904 \size footnotesize
36905 _function:
36906 \end_layout
36907
36908 \begin_layout Standard
36909
36910 \size footnotesize
36911 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
36912 \end_layout
36913
36914 \begin_layout Standard
36915
36916 \size footnotesize
36917 \InsetSpace ~
36918 \InsetSpace ~
36919 mov r2,dpl
36920 \end_layout
36921
36922 \begin_layout Standard
36923
36924 \size footnotesize
36925 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
36926 \end_layout
36927
36928 \begin_layout Standard
36929
36930 \size footnotesize
36931 \InsetSpace ~
36932 \InsetSpace ~
36933 mov ar0,r2
36934 \end_layout
36935
36936 \begin_layout Standard
36937
36938 \size footnotesize
36939 ;_whilecontinue_0($1) :
36940 \end_layout
36941
36942 \begin_layout Standard
36943
36944 \size footnotesize
36945 00101$:
36946 \end_layout
36947
36948 \begin_layout Standard
36949
36950 \size footnotesize
36951 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
36952 \end_layout
36953
36954 \begin_layout Standard
36955
36956 \size footnotesize
36957 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
36958 \end_layout
36959
36960 \begin_layout Standard
36961
36962 \size footnotesize
36963 \InsetSpace ~
36964 \InsetSpace ~
36965 mov ar2,@r0
36966 \end_layout
36967
36968 \begin_layout Standard
36969
36970 \size footnotesize
36971 \InsetSpace ~
36972 \InsetSpace ~
36973 inc r0
36974 \end_layout
36975
36976 \begin_layout Standard
36977
36978 \size footnotesize
36979 \InsetSpace ~
36980 \InsetSpace ~
36981 mov ar3,@r0
36982 \end_layout
36983
36984 \begin_layout Standard
36985
36986 \size footnotesize
36987 \InsetSpace ~
36988 \InsetSpace ~
36989 dec r0
36990 \end_layout
36991
36992 \begin_layout Standard
36993
36994 \size footnotesize
36995 \InsetSpace ~
36996 \InsetSpace ~
36997 mov a,r2
36998 \end_layout
36999
37000 \begin_layout Standard
37001
37002 \size footnotesize
37003 \InsetSpace ~
37004 \InsetSpace ~
37005 orl a,r3
37006 \end_layout
37007
37008 \begin_layout Standard
37009
37010 \size footnotesize
37011 \InsetSpace ~
37012 \InsetSpace ~
37013 jz 00103$
37014 \end_layout
37015
37016 \begin_layout Standard
37017
37018 \size footnotesize
37019 00114$:
37020 \end_layout
37021
37022 \begin_layout Standard
37023
37024 \size footnotesize
37025 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
37026 \end_layout
37027
37028 \begin_layout Standard
37029
37030 \size footnotesize
37031 \InsetSpace ~
37032 \InsetSpace ~
37033 mov dpl,_p
37034 \end_layout
37035
37036 \begin_layout Standard
37037
37038 \size footnotesize
37039 \InsetSpace ~
37040 \InsetSpace ~
37041 mov dph,(_p + 1)
37042 \end_layout
37043
37044 \begin_layout Standard
37045
37046 \size footnotesize
37047 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
37048 \end_layout
37049
37050 \begin_layout Standard
37051
37052 \size footnotesize
37053 \InsetSpace ~
37054 \InsetSpace ~
37055 mov a,#0x02
37056 \end_layout
37057
37058 \begin_layout Standard
37059
37060 \size footnotesize
37061 \InsetSpace ~
37062 \InsetSpace ~
37063 add a,_p
37064 \end_layout
37065
37066 \begin_layout Standard
37067
37068 \size footnotesize
37069 \InsetSpace ~
37070 \InsetSpace ~
37071 mov _p,a
37072 \end_layout
37073
37074 \begin_layout Standard
37075
37076 \size footnotesize
37077 \InsetSpace ~
37078 \InsetSpace ~
37079 clr a
37080 \end_layout
37081
37082 \begin_layout Standard
37083
37084 \size footnotesize
37085 \InsetSpace ~
37086 \InsetSpace ~
37087 addc a,(_p + 1)
37088 \end_layout
37089
37090 \begin_layout Standard
37091
37092 \size footnotesize
37093 \InsetSpace ~
37094 \InsetSpace ~
37095 mov (_p + 1),a
37096 \end_layout
37097
37098 \begin_layout Standard
37099
37100 \size footnotesize
37101 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
37102 \end_layout
37103
37104 \begin_layout Standard
37105
37106 \size footnotesize
37107 \InsetSpace ~
37108 \InsetSpace ~
37109 movx a,@dptr
37110 \end_layout
37111
37112 \begin_layout Standard
37113
37114 \size footnotesize
37115 \InsetSpace ~
37116 \InsetSpace ~
37117 mov r2,a
37118 \end_layout
37119
37120 \begin_layout Standard
37121
37122 \size footnotesize
37123 \InsetSpace ~
37124 \InsetSpace ~
37125 inc dptr
37126 \end_layout
37127
37128 \begin_layout Standard
37129
37130 \size footnotesize
37131 \InsetSpace ~
37132 \InsetSpace ~
37133 movx a,@dptr
37134 \end_layout
37135
37136 \begin_layout Standard
37137
37138 \size footnotesize
37139 \InsetSpace ~
37140 \InsetSpace ~
37141 mov r3,a
37142 \end_layout
37143
37144 \begin_layout Standard
37145
37146 \size footnotesize
37147 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
37148 \end_layout
37149
37150 \begin_layout Standard
37151
37152 \size footnotesize
37153 \InsetSpace ~
37154 \InsetSpace ~
37155 mov @r0,ar2
37156 \end_layout
37157
37158 \begin_layout Standard
37159
37160 \size footnotesize
37161 \InsetSpace ~
37162 \InsetSpace ~
37163 inc r0
37164 \end_layout
37165
37166 \begin_layout Standard
37167
37168 \size footnotesize
37169 \InsetSpace ~
37170 \InsetSpace ~
37171 mov @r0,ar3
37172 \end_layout
37173
37174 \begin_layout Standard
37175
37176 \size footnotesize
37177 ; iTemp6 [lr5:16]{_near * int}[r0] = 
37178 \end_layout
37179
37180 \begin_layout Standard
37181
37182 \size footnotesize
37183 ; iTemp6 [lr5:16]{_near * int}[r0] + 
37184 \end_layout
37185
37186 \begin_layout Standard
37187
37188 \size footnotesize
37189 ; 0x2 {short}
37190 \end_layout
37191
37192 \begin_layout Standard
37193
37194 \size footnotesize
37195 \InsetSpace ~
37196 \InsetSpace ~
37197 inc r0
37198 \end_layout
37199
37200 \begin_layout Standard
37201
37202 \size footnotesize
37203 ; goto _whilecontinue_0($1)
37204 \end_layout
37205
37206 \begin_layout Standard
37207
37208 \size footnotesize
37209 \InsetSpace ~
37210 \InsetSpace ~
37211 sjmp 00101$
37212 \end_layout
37213
37214 \begin_layout Standard
37215
37216 \size footnotesize
37217 ; _whilebreak_0($3) :
37218 \end_layout
37219
37220 \begin_layout Standard
37221
37222 \size footnotesize
37223 00103$:
37224 \end_layout
37225
37226 \begin_layout Standard
37227
37228 \size footnotesize
37229 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
37230 \end_layout
37231
37232 \begin_layout Standard
37233
37234 \size footnotesize
37235 \InsetSpace ~
37236 \InsetSpace ~
37237 mov r2,#0x00
37238 \end_layout
37239
37240 \begin_layout Standard
37241
37242 \size footnotesize
37243 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
37244 \end_layout
37245
37246 \begin_layout Standard
37247
37248 \size footnotesize
37249 \InsetSpace ~
37250 \InsetSpace ~
37251 mov r3,#0x00
37252 \end_layout
37253
37254 \begin_layout Standard
37255
37256 \size footnotesize
37257 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
37258 \end_layout
37259
37260 \begin_layout Standard
37261
37262 \size footnotesize
37263 \InsetSpace ~
37264 \InsetSpace ~
37265 mov r4,#0x00
37266 \end_layout
37267
37268 \begin_layout Standard
37269
37270 \size footnotesize
37271 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
37272 \end_layout
37273
37274 \begin_layout Standard
37275
37276 \size footnotesize
37277 \InsetSpace ~
37278 \InsetSpace ~
37279 mov r5,#0x0A
37280 \end_layout
37281
37282 \begin_layout Standard
37283
37284 \size footnotesize
37285 \InsetSpace ~
37286 \InsetSpace ~
37287 mov r6,#0x00
37288 \end_layout
37289
37290 \begin_layout Standard
37291
37292 \size footnotesize
37293 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
37294 \end_layout
37295
37296 \begin_layout Standard
37297
37298 \size footnotesize
37299 \InsetSpace ~
37300 \InsetSpace ~
37301 mov r7,#0x1E
37302 \end_layout
37303
37304 \begin_layout Standard
37305
37306 \size footnotesize
37307 \InsetSpace ~
37308 \InsetSpace ~
37309 mov r0,#0x00
37310 \end_layout
37311
37312 \begin_layout Standard
37313
37314 \size footnotesize
37315 ; _forcond_0($4) :
37316 \end_layout
37317
37318 \begin_layout Standard
37319
37320 \size footnotesize
37321 00104$:
37322 \end_layout
37323
37324 \begin_layout Standard
37325
37326 \size footnotesize
37327 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
37328 \end_layout
37329
37330 \begin_layout Standard
37331
37332 \size footnotesize
37333 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
37334 \end_layout
37335
37336 \begin_layout Standard
37337
37338 \size footnotesize
37339 \InsetSpace ~
37340 \InsetSpace ~
37341 clr c
37342 \end_layout
37343
37344 \begin_layout Standard
37345
37346 \size footnotesize
37347 \InsetSpace ~
37348 \InsetSpace ~
37349 mov a,r4
37350 \end_layout
37351
37352 \begin_layout Standard
37353
37354 \size footnotesize
37355 \InsetSpace ~
37356 \InsetSpace ~
37357 xrl a,#0x80
37358 \end_layout
37359
37360 \begin_layout Standard
37361
37362 \size footnotesize
37363 \InsetSpace ~
37364 \InsetSpace ~
37365 subb a,#0x8a
37366 \end_layout
37367
37368 \begin_layout Standard
37369
37370 \size footnotesize
37371 \InsetSpace ~
37372 \InsetSpace ~
37373 jnc 00107$
37374 \end_layout
37375
37376 \begin_layout Standard
37377
37378 \size footnotesize
37379 00115$:
37380 \end_layout
37381
37382 \begin_layout Standard
37383
37384 \size footnotesize
37385 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
37386 \end_layout
37387
37388 \begin_layout Standard
37389
37390 \size footnotesize
37391 ; iTemp21 [lr21:38]{short}[r4]
37392 \end_layout
37393
37394 \begin_layout Standard
37395
37396 \size footnotesize
37397 \InsetSpace ~
37398 \InsetSpace ~
37399 mov a,r4
37400 \end_layout
37401
37402 \begin_layout Standard
37403
37404 \size footnotesize
37405 \InsetSpace ~
37406 \InsetSpace ~
37407 add a,r2
37408 \end_layout
37409
37410 \begin_layout Standard
37411
37412 \size footnotesize
37413 \InsetSpace ~
37414 \InsetSpace ~
37415 mov r2,a
37416 \end_layout
37417
37418 \begin_layout Standard
37419
37420 \size footnotesize
37421 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
37422 \end_layout
37423
37424 \begin_layout Standard
37425
37426 \size footnotesize
37427 \InsetSpace ~
37428 \InsetSpace ~
37429 mov b,#0x03
37430 \end_layout
37431
37432 \begin_layout Standard
37433
37434 \size footnotesize
37435 \InsetSpace ~
37436 \InsetSpace ~
37437 mov a,r4
37438 \end_layout
37439
37440 \begin_layout Standard
37441
37442 \size footnotesize
37443 \InsetSpace ~
37444 \InsetSpace ~
37445 mul ab
37446 \end_layout
37447
37448 \begin_layout Standard
37449
37450 \size footnotesize
37451 \InsetSpace ~
37452 \InsetSpace ~
37453 mov r1,a
37454 \end_layout
37455
37456 \begin_layout Standard
37457
37458 \size footnotesize
37459 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
37460 \end_layout
37461
37462 \begin_layout Standard
37463
37464 \size footnotesize
37465 ; iTemp15 [lr29:30]{short}[r1]
37466 \end_layout
37467
37468 \begin_layout Standard
37469
37470 \size footnotesize
37471 \InsetSpace ~
37472 \InsetSpace ~
37473 add a,r3
37474 \end_layout
37475
37476 \begin_layout Standard
37477
37478 \size footnotesize
37479 \InsetSpace ~
37480 \InsetSpace ~
37481 mov r3,a
37482 \end_layout
37483
37484 \begin_layout Standard
37485
37486 \size footnotesize
37487 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
37488 \end_layout
37489
37490 \begin_layout Standard
37491
37492 \size footnotesize
37493 \InsetSpace ~
37494 \InsetSpace ~
37495 mov a,r7
37496 \end_layout
37497
37498 \begin_layout Standard
37499
37500 \size footnotesize
37501 \InsetSpace ~
37502 \InsetSpace ~
37503 add a,#0xfd
37504 \end_layout
37505
37506 \begin_layout Standard
37507
37508 \size footnotesize
37509 \InsetSpace ~
37510 \InsetSpace ~
37511 mov r7,a
37512 \end_layout
37513
37514 \begin_layout Standard
37515
37516 \size footnotesize
37517 \InsetSpace ~
37518 \InsetSpace ~
37519 mov a,r0
37520 \end_layout
37521
37522 \begin_layout Standard
37523
37524 \size footnotesize
37525 \InsetSpace ~
37526 \InsetSpace ~
37527 addc a,#0xff
37528 \end_layout
37529
37530 \begin_layout Standard
37531
37532 \size footnotesize
37533 \InsetSpace ~
37534 \InsetSpace ~
37535 mov r0,a
37536 \end_layout
37537
37538 \begin_layout Standard
37539
37540 \size footnotesize
37541 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
37542 \end_layout
37543
37544 \begin_layout Standard
37545
37546 \size footnotesize
37547 \InsetSpace ~
37548 \InsetSpace ~
37549 mov a,r7
37550 \end_layout
37551
37552 \begin_layout Standard
37553
37554 \size footnotesize
37555 \InsetSpace ~
37556 \InsetSpace ~
37557 add a,_gint
37558 \end_layout
37559
37560 \begin_layout Standard
37561
37562 \size footnotesize
37563 \InsetSpace ~
37564 \InsetSpace ~
37565 mov _gint,a
37566 \end_layout
37567
37568 \begin_layout Standard
37569
37570 \size footnotesize
37571 \InsetSpace ~
37572 \InsetSpace ~
37573 mov a,r0
37574 \end_layout
37575
37576 \begin_layout Standard
37577
37578 \size footnotesize
37579 \InsetSpace ~
37580 \InsetSpace ~
37581 addc a,(_gint + 1)
37582 \end_layout
37583
37584 \begin_layout Standard
37585
37586 \size footnotesize
37587 \InsetSpace ~
37588 \InsetSpace ~
37589 mov (_gint + 1),a
37590 \end_layout
37591
37592 \begin_layout Standard
37593
37594 \size footnotesize
37595 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
37596 \end_layout
37597
37598 \begin_layout Standard
37599
37600 \size footnotesize
37601 \InsetSpace ~
37602 \InsetSpace ~
37603 inc r4
37604 \end_layout
37605
37606 \begin_layout Standard
37607
37608 \size footnotesize
37609 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
37610 \end_layout
37611
37612 \begin_layout Standard
37613
37614 \size footnotesize
37615 \InsetSpace ~
37616 \InsetSpace ~
37617 dec r5
37618 \end_layout
37619
37620 \begin_layout Standard
37621
37622 \size footnotesize
37623 \InsetSpace ~
37624 \InsetSpace ~
37625 cjne r5,#0xff,00104$
37626 \end_layout
37627
37628 \begin_layout Standard
37629
37630 \size footnotesize
37631 \InsetSpace ~
37632 \InsetSpace ~
37633 dec r6
37634 \end_layout
37635
37636 \begin_layout Standard
37637
37638 \size footnotesize
37639 ; goto _forcond_0($4)
37640 \end_layout
37641
37642 \begin_layout Standard
37643
37644 \size footnotesize
37645 \InsetSpace ~
37646 \InsetSpace ~
37647 sjmp 00104$
37648 \end_layout
37649
37650 \begin_layout Standard
37651
37652 \size footnotesize
37653 ; _forbreak_0($7) :
37654 \end_layout
37655
37656 \begin_layout Standard
37657
37658 \size footnotesize
37659 00107$:
37660 \end_layout
37661
37662 \begin_layout Standard
37663
37664 \size footnotesize
37665 ; ret iTemp24 [lr40:41]{short}
37666 \end_layout
37667
37668 \begin_layout Standard
37669
37670 \size footnotesize
37671 \InsetSpace ~
37672 \InsetSpace ~
37673 mov a,r3
37674 \end_layout
37675
37676 \begin_layout Standard
37677
37678 \size footnotesize
37679 \InsetSpace ~
37680 \InsetSpace ~
37681 add a,r2
37682 \end_layout
37683
37684 \begin_layout Standard
37685
37686 \size footnotesize
37687 \InsetSpace ~
37688 \InsetSpace ~
37689 mov dpl,a
37690 \end_layout
37691
37692 \begin_layout Standard
37693
37694 \size footnotesize
37695 ; _return($8) :
37696 \end_layout
37697
37698 \begin_layout Standard
37699
37700 \size footnotesize
37701 00108$:
37702 \end_layout
37703
37704 \begin_layout Standard
37705
37706 \size footnotesize
37707 \InsetSpace ~
37708 \InsetSpace ~
37709 ret
37710 \newline
37711
37712 \end_layout
37713
37714 \begin_layout Section
37715 A few words about basic block successors, predecessors and dominators
37716 \end_layout
37717
37718 \begin_layout Standard
37719 Successors are basic blocks
37720 \begin_inset LatexCommand \index{Basic blocks}
37721
37722 \end_inset
37723
37724  that might execute after this basic block.
37725 \newline
37726 Predecessors are basic blocks
37727  that might execute before reaching this basic block.
37728 \newline
37729 Dominators are basic
37730  blocks that WILL execute before reaching this basic block.
37731 \newline
37732
37733 \end_layout
37734
37735 \begin_layout Standard
37736 [basic block 1]
37737 \end_layout
37738
37739 \begin_layout Standard
37740 if (something)
37741 \end_layout
37742
37743 \begin_layout Standard
37744 \InsetSpace ~
37745 \InsetSpace ~
37746 \InsetSpace ~
37747 \InsetSpace ~
37748 [basic block 2]
37749 \end_layout
37750
37751 \begin_layout Standard
37752 else
37753 \end_layout
37754
37755 \begin_layout Standard
37756 \InsetSpace ~
37757 \InsetSpace ~
37758 \InsetSpace ~
37759 \InsetSpace ~
37760 [basic block 3]
37761 \end_layout
37762
37763 \begin_layout Standard
37764 [basic block 4]
37765 \newline
37766
37767 \end_layout
37768
37769 \begin_layout Standard
37770 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
37771 \end_layout
37772
37773 \begin_layout Standard
37774 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
37775 \end_layout
37776
37777 \begin_layout Standard
37778 c) domVect of [BB4] = BB1 ...
37779  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
37780  was executed.
37781 \end_layout
37782
37783 \begin_layout Chapter
37784 Acknowledgments
37785 \end_layout
37786
37787 \begin_layout Standard
37788 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
37789
37790 \end_inset
37791
37792
37793 \newline
37794
37795 \newline
37796
37797 \emph on
37798 Thanks to all the other volunteer developers who have helped with coding,
37799  testing, web-page creation, distribution sets, etc.
37800  You know who you are :-)
37801 \emph default
37802
37803 \newline
37804
37805 \newline
37806
37807 \emph on
37808 Also thanks to Sourceforge 
37809 \begin_inset LatexCommand \url{http://www.sf.net}
37810
37811 \end_inset
37812
37813  which has hosted the project since 1999 and donates significant download
37814  bandwidth and probably more than 
37815 \begin_inset ERT
37816 status collapsed
37817
37818 \begin_layout Standard
37819
37820 $10^{13}$
37821 \end_layout
37822
37823 \end_inset
37824
37825 CPU cycles per day.
37826 \newline
37827  
37828 \begin_inset Note Note
37829 status open
37830
37831 \begin_layout Standard
37832 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
37833  minutes for (configure+make+regression test), and there is (i386, amd64,
37834  alpha, ppc64, (mingw32), sparc, macosx).
37835  
37836 \end_layout
37837
37838 \end_inset
37839
37840
37841 \end_layout
37842
37843 \begin_layout Standard
37844 This document was initially written by Sandeep Dutta
37845 \end_layout
37846
37847 \begin_layout Standard
37848 All product names mentioned herein may be trademarks
37849 \begin_inset LatexCommand \index{Trademarks}
37850
37851 \end_inset
37852
37853  of their respective companies.
37854  
37855 \end_layout
37856
37857 \begin_layout Section*
37858 Alphabetical index
37859 \end_layout
37860
37861 \begin_layout Standard
37862 To avoid confusion, the installation and building options for SDCC itself
37863  (chapter 2) are not part of the index.
37864 \end_layout
37865
37866 \begin_layout Standard
37867 \begin_inset LatexCommand \printindex{}
37868
37869 \end_inset
37870
37871
37872 \end_layout
37873
37874 \end_body
37875 \end_document