* doc/cdbfileformat.lyx, doc/sdccman.lyx, doc/test_suite_spec.lyx:
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.4 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 Note
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.5
108 \size footnotesize
109
110 \newline
111 $Date$ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Note
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://sdcc.svn.sourceforge.net/svnroot/
1042 sdcc/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 SDCC Distributed Compile
1565  Farm.
1566 \end_layout
1567
1568 \begin_layout Standard
1569 See the examples, how to pass the Win32 settings to 'configure'.
1570  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1571  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1572  for Win32.
1573 \newline
1574
1575 \newline
1576 These defaults are:
1577 \newline
1578
1579 \end_layout
1580
1581 \begin_layout Standard
1582 \align center
1583 \begin_inset Tabular
1584 <lyxtabular version="3" rows="9" columns="3">
1585 <features>
1586 <column alignment="block" valignment="top" leftline="true" width="0in">
1587 <column alignment="block" valignment="top" leftline="true" width="0in">
1588 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1589 <row topline="true" bottomline="true">
1590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1591 \begin_inset Text
1592
1593 \begin_layout Standard
1594 Variable
1595 \end_layout
1596
1597 \end_inset
1598 </cell>
1599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1600 \begin_inset Text
1601
1602 \begin_layout Standard
1603 default
1604 \end_layout
1605
1606 \end_inset
1607 </cell>
1608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1609 \begin_inset Text
1610
1611 \begin_layout Standard
1612 Win32 builds
1613 \end_layout
1614
1615 \end_inset
1616 </cell>
1617 </row>
1618 <row topline="true">
1619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1620 \begin_inset Text
1621
1622 \begin_layout Standard
1623
1624 \emph on
1625 PREFIX
1626 \end_layout
1627
1628 \end_inset
1629 </cell>
1630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1631 \begin_inset Text
1632
1633 \begin_layout Standard
1634 /usr/local
1635 \end_layout
1636
1637 \end_inset
1638 </cell>
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1640 \begin_inset Text
1641
1642 \begin_layout Standard
1643
1644 \backslash
1645 sdcc
1646 \end_layout
1647
1648 \end_inset
1649 </cell>
1650 </row>
1651 <row topline="true">
1652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1653 \begin_inset Text
1654
1655 \begin_layout Standard
1656
1657 \emph on
1658 EXEC_PREFIX
1659 \end_layout
1660
1661 \end_inset
1662 </cell>
1663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1664 \begin_inset Text
1665
1666 \begin_layout Standard
1667
1668 \emph on
1669 $PREFIX
1670 \end_layout
1671
1672 \end_inset
1673 </cell>
1674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1675 \begin_inset Text
1676
1677 \begin_layout Standard
1678
1679 \emph on
1680 $PREFIX
1681 \end_layout
1682
1683 \end_inset
1684 </cell>
1685 </row>
1686 <row topline="true">
1687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1688 \begin_inset Text
1689
1690 \begin_layout Standard
1691
1692 \emph on
1693 BINDIR
1694 \end_layout
1695
1696 \end_inset
1697 </cell>
1698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1699 \begin_inset Text
1700
1701 \begin_layout Standard
1702
1703 \emph on
1704 $EXEC_PREFIX
1705 \emph default
1706 /bin
1707 \end_layout
1708
1709 \end_inset
1710 </cell>
1711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1712 \begin_inset Text
1713
1714 \begin_layout Standard
1715
1716 \emph on
1717 $EXEC_PREFIX
1718 \emph default
1719
1720 \backslash
1721 bin
1722 \end_layout
1723
1724 \end_inset
1725 </cell>
1726 </row>
1727 <row topline="true">
1728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1729 \begin_inset Text
1730
1731 \begin_layout Standard
1732
1733 \emph on
1734 DATADIR
1735 \end_layout
1736
1737 \end_inset
1738 </cell>
1739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1740 \begin_inset Text
1741
1742 \begin_layout Standard
1743
1744 \emph on
1745 $DATAROOTDIR
1746 \end_layout
1747
1748 \end_inset
1749 </cell>
1750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1751 \begin_inset Text
1752
1753 \begin_layout Standard
1754
1755 \emph on
1756 $DATAROOTDIR
1757 \end_layout
1758
1759 \end_inset
1760 </cell>
1761 </row>
1762 <row topline="true">
1763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1764 \begin_inset Text
1765
1766 \begin_layout Standard
1767
1768 \emph on
1769 DATAROOTDIR
1770 \end_layout
1771
1772 \end_inset
1773 </cell>
1774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1775 \begin_inset Text
1776
1777 \begin_layout Standard
1778
1779 \emph on
1780 $PREFIX
1781 \emph default
1782 /share
1783 \end_layout
1784
1785 \end_inset
1786 </cell>
1787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1788 \begin_inset Text
1789
1790 \begin_layout Standard
1791
1792 \emph on
1793 $PREFIX
1794 \end_layout
1795
1796 \end_inset
1797 </cell>
1798 </row>
1799 <row topline="true">
1800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1801 \begin_inset Text
1802
1803 \begin_layout Standard
1804
1805 \emph on
1806 DOCDIR
1807 \end_layout
1808
1809 \end_inset
1810 </cell>
1811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1812 \begin_inset Text
1813
1814 \begin_layout Standard
1815
1816 \emph on
1817 $DATAROOTDIR
1818 \emph default
1819 /sdcc/doc
1820 \end_layout
1821
1822 \end_inset
1823 </cell>
1824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1825 \begin_inset Text
1826
1827 \begin_layout Standard
1828
1829 \emph on
1830 $DATAROOTDIR
1831 \emph default
1832
1833 \backslash
1834 doc
1835 \end_layout
1836
1837 \end_inset
1838 </cell>
1839 </row>
1840 <row topline="true">
1841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1842 \begin_inset Text
1843
1844 \begin_layout Standard
1845
1846 \emph on
1847 INCLUDE_DIR_SUFFIX
1848 \end_layout
1849
1850 \end_inset
1851 </cell>
1852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1853 \begin_inset Text
1854
1855 \begin_layout Standard
1856 sdcc/include
1857 \end_layout
1858
1859 \end_inset
1860 </cell>
1861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1862 \begin_inset Text
1863
1864 \begin_layout Standard
1865 include
1866 \end_layout
1867
1868 \end_inset
1869 </cell>
1870 </row>
1871 <row topline="true" bottomline="true">
1872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1873 \begin_inset Text
1874
1875 \begin_layout Standard
1876
1877 \emph on
1878 LIB_DIR_SUFFIX
1879 \end_layout
1880
1881 \end_inset
1882 </cell>
1883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1884 \begin_inset Text
1885
1886 \begin_layout Standard
1887 sdcc/lib
1888 \end_layout
1889
1890 \end_inset
1891 </cell>
1892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1893 \begin_inset Text
1894
1895 \begin_layout Standard
1896 lib
1897 \end_layout
1898
1899 \end_inset
1900 </cell>
1901 </row>
1902 </lyxtabular>
1903
1904 \end_inset
1905
1906
1907 \newline
1908
1909 \end_layout
1910
1911 \begin_layout Standard
1912 \noindent
1913 'configure' also computes relative paths.
1914  This is needed for full relocatability of a binary package and to complete
1915  search paths (see section search paths below):
1916 \newline
1917  
1918 \end_layout
1919
1920 \begin_layout Standard
1921 \align center
1922 \begin_inset Tabular
1923 <lyxtabular version="3" rows="4" columns="3">
1924 <features>
1925 <column alignment="block" valignment="top" leftline="true" width="0in">
1926 <column alignment="block" valignment="top" leftline="true" width="0in">
1927 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1928 <row topline="true" bottomline="true">
1929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1930 \begin_inset Text
1931
1932 \begin_layout Standard
1933 Variable (computed)
1934 \end_layout
1935
1936 \end_inset
1937 </cell>
1938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1939 \begin_inset Text
1940
1941 \begin_layout Standard
1942 default
1943 \end_layout
1944
1945 \end_inset
1946 </cell>
1947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1948 \begin_inset Text
1949
1950 \begin_layout Standard
1951 Win32 builds
1952 \end_layout
1953
1954 \end_inset
1955 </cell>
1956 </row>
1957 <row topline="true" bottomline="true">
1958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1959 \begin_inset Text
1960
1961 \begin_layout Standard
1962
1963 \emph on
1964 BIN2DATA_DIR
1965 \end_layout
1966
1967 \end_inset
1968 </cell>
1969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1970 \begin_inset Text
1971
1972 \begin_layout Standard
1973 ../share
1974 \end_layout
1975
1976 \end_inset
1977 </cell>
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1979 \begin_inset Text
1980
1981 \begin_layout Standard
1982 ..
1983 \end_layout
1984
1985 \end_inset
1986 </cell>
1987 </row>
1988 <row bottomline="true">
1989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 \begin_inset Text
1991
1992 \begin_layout Standard
1993
1994 \emph on
1995 PREFIX2BIN_DIR
1996 \end_layout
1997
1998 \end_inset
1999 </cell>
2000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2001 \begin_inset Text
2002
2003 \begin_layout Standard
2004 bin
2005 \end_layout
2006
2007 \end_inset
2008 </cell>
2009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2010 \begin_inset Text
2011
2012 \begin_layout Standard
2013 bin
2014 \end_layout
2015
2016 \end_inset
2017 </cell>
2018 </row>
2019 <row bottomline="true">
2020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2021 \begin_inset Text
2022
2023 \begin_layout Standard
2024
2025 \emph on
2026 PREFIX2DATA_DIR
2027 \end_layout
2028
2029 \end_inset
2030 </cell>
2031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2032 \begin_inset Text
2033
2034 \begin_layout Standard
2035 share/sdcc
2036 \end_layout
2037
2038 \end_inset
2039 </cell>
2040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2041 \begin_inset Text
2042
2043 \begin_layout Standard
2044
2045 \end_layout
2046
2047 \end_inset
2048 </cell>
2049 </row>
2050 </lyxtabular>
2051
2052 \end_inset
2053
2054
2055 \newline
2056
2057 \end_layout
2058
2059 \begin_layout Standard
2060 \noindent
2061 Examples:
2062 \end_layout
2063
2064 \begin_layout LyX-Code
2065 ./configure
2066 \newline
2067 ./configure -
2068 \begin_inset ERT
2069 status collapsed
2070
2071 \begin_layout Standard
2072
2073
2074 \backslash
2075 /
2076 \end_layout
2077
2078 \end_inset
2079
2080 -prefix=
2081 \begin_inset Quotes srd
2082 \end_inset
2083
2084 /usr/bin
2085 \begin_inset Quotes srd
2086 \end_inset
2087
2088  -
2089 \begin_inset ERT
2090 status collapsed
2091
2092 \begin_layout Standard
2093
2094
2095 \backslash
2096 /
2097 \end_layout
2098
2099 \end_inset
2100
2101 -datarootdir=
2102 \begin_inset Quotes srd
2103 \end_inset
2104
2105 /usr/share
2106 \begin_inset Quotes srd
2107 \end_inset
2108
2109
2110 \newline
2111 ./configure -
2112 \begin_inset ERT
2113 status collapsed
2114
2115 \begin_layout Standard
2116
2117
2118 \backslash
2119 /
2120 \end_layout
2121
2122 \end_inset
2123
2124 -disable-avr-port -
2125 \begin_inset ERT
2126 status collapsed
2127
2128 \begin_layout Standard
2129
2130
2131 \backslash
2132 /
2133 \end_layout
2134
2135 \end_inset
2136
2137 -disable-xa51-port
2138 \end_layout
2139
2140 \begin_layout Standard
2141 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2142 32'):
2143 \end_layout
2144
2145 \begin_layout LyX-Code
2146 ./configure 
2147 \backslash
2148
2149 \newline
2150 CC=
2151 \begin_inset Quotes srd
2152 \end_inset
2153
2154 i586-mingw32msvc-gcc
2155 \begin_inset Quotes srd
2156 \end_inset
2157
2158  CXX=
2159 \begin_inset Quotes srd
2160 \end_inset
2161
2162 i586-mingw32msvc-g++
2163 \begin_inset Quotes srd
2164 \end_inset
2165
2166  
2167 \backslash
2168  
2169 \newline
2170 RANLIB=
2171 \begin_inset Quotes srd
2172 \end_inset
2173
2174 i586-mingw32msvc-ranlib
2175 \begin_inset Quotes srd
2176 \end_inset
2177
2178  
2179 \backslash
2180
2181 \newline
2182 STRIP=
2183 \begin_inset Quotes srd
2184 \end_inset
2185
2186 i586-mingw32msvc-strip
2187 \begin_inset Quotes srd
2188 \end_inset
2189
2190  
2191 \backslash
2192
2193 \newline
2194 -
2195 \begin_inset ERT
2196 status collapsed
2197
2198 \begin_layout Standard
2199
2200
2201 \backslash
2202 /
2203 \end_layout
2204
2205 \end_inset
2206
2207 -prefix=
2208 \begin_inset Quotes srd
2209 \end_inset
2210
2211 /sdcc
2212 \begin_inset Quotes srd
2213 \end_inset
2214
2215  
2216 \backslash
2217
2218 \newline
2219 -
2220 \begin_inset ERT
2221 status collapsed
2222
2223 \begin_layout Standard
2224
2225
2226 \backslash
2227 /
2228 \end_layout
2229
2230 \end_inset
2231
2232 -datarootdir=
2233 \begin_inset Quotes srd
2234 \end_inset
2235
2236 /sdcc
2237 \begin_inset Quotes srd
2238 \end_inset
2239
2240  
2241 \backslash
2242
2243 \newline
2244 docdir=
2245 \begin_inset Quotes srd
2246 \end_inset
2247
2248
2249 \backslash
2250 ${datarootdir}/doc
2251 \begin_inset Quotes srd
2252 \end_inset
2253
2254  
2255 \backslash
2256
2257 \newline
2258 include_dir_suffix=
2259 \begin_inset Quotes srd
2260 \end_inset
2261
2262 include
2263 \begin_inset Quotes srd
2264 \end_inset
2265
2266  
2267 \backslash
2268
2269 \newline
2270 lib_dir_suffix=
2271 \begin_inset Quotes srd
2272 \end_inset
2273
2274 lib
2275 \begin_inset Quotes srd
2276 \end_inset
2277
2278  
2279 \backslash
2280
2281 \newline
2282 sdccconf_h_dir_separator=
2283 \begin_inset Quotes srd
2284 \end_inset
2285
2286
2287 \backslash
2288
2289 \backslash
2290
2291 \backslash
2292
2293 \backslash
2294
2295 \begin_inset Quotes srd
2296 \end_inset
2297
2298  
2299 \backslash
2300
2301 \newline
2302 -
2303 \begin_inset ERT
2304 status collapsed
2305
2306 \begin_layout Standard
2307
2308
2309 \backslash
2310 /
2311 \end_layout
2312
2313 \end_inset
2314
2315 -disable-device-lib
2316 \backslash
2317
2318 \newline
2319 -
2320 \begin_inset ERT
2321 status collapsed
2322
2323 \begin_layout Standard
2324
2325
2326 \backslash
2327 /
2328 \end_layout
2329
2330 \end_inset
2331
2332 -host=i586-mingw32msvc
2333 \backslash
2334
2335 \newline
2336 -
2337 \begin_inset ERT
2338 status collapsed
2339
2340 \begin_layout Standard
2341
2342
2343 \backslash
2344 /
2345 \end_layout
2346
2347 \end_inset
2348
2349 -build=unknown-unknown-linux-gnu
2350 \end_layout
2351
2352 \begin_layout Standard
2353 To 
2354 \begin_inset Quotes sld
2355 \end_inset
2356
2357 cross
2358 \begin_inset Quotes srd
2359 \end_inset
2360
2361 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2362 ):
2363 \end_layout
2364
2365 \begin_layout LyX-Code
2366 ./configure -C 
2367 \backslash
2368
2369 \newline
2370 -
2371 \begin_inset ERT
2372 status collapsed
2373
2374 \begin_layout Standard
2375
2376
2377 \backslash
2378 /
2379 \end_layout
2380
2381 \end_inset
2382
2383 -prefix=
2384 \begin_inset Quotes srd
2385 \end_inset
2386
2387 /sdcc
2388 \begin_inset Quotes srd
2389 \end_inset
2390
2391  
2392 \backslash
2393
2394 \newline
2395 -
2396 \begin_inset ERT
2397 status collapsed
2398
2399 \begin_layout Standard
2400
2401
2402 \backslash
2403 /
2404 \end_layout
2405
2406 \end_inset
2407
2408 -datarootdir=
2409 \begin_inset Quotes srd
2410 \end_inset
2411
2412 /sdcc
2413 \begin_inset Quotes srd
2414 \end_inset
2415
2416  
2417 \backslash
2418
2419 \newline
2420 docdir=
2421 \begin_inset Quotes srd
2422 \end_inset
2423
2424
2425 \backslash
2426 ${datarootdir}/doc
2427 \begin_inset Quotes srd
2428 \end_inset
2429
2430  
2431 \backslash
2432  
2433 \newline
2434 include_dir_suffix=
2435 \begin_inset Quotes srd
2436 \end_inset
2437
2438 include
2439 \begin_inset Quotes srd
2440 \end_inset
2441
2442  
2443 \backslash
2444
2445 \newline
2446 lib_dir_suffix=
2447 \begin_inset Quotes srd
2448 \end_inset
2449
2450 lib
2451 \begin_inset Quotes srd
2452 \end_inset
2453
2454  
2455 \backslash
2456
2457 \newline
2458 sdccconf_h_dir_separator=
2459 \begin_inset Quotes srd
2460 \end_inset
2461
2462
2463 \backslash
2464
2465 \backslash
2466
2467 \backslash
2468
2469 \backslash
2470
2471 \begin_inset Quotes srd
2472 \end_inset
2473
2474  
2475 \backslash
2476
2477 \newline
2478 CC=
2479 \begin_inset Quotes srd
2480 \end_inset
2481
2482 gcc -mno-cygwin
2483 \begin_inset Quotes srd
2484 \end_inset
2485
2486  
2487 \backslash
2488
2489 \newline
2490 CXX=
2491 \begin_inset Quotes srd
2492 \end_inset
2493
2494 g++ -mno-cygwin
2495 \begin_inset Quotes srd
2496 \end_inset
2497
2498  
2499 \end_layout
2500
2501 \begin_layout Standard
2502 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2503  The option '-
2504 \begin_inset ERT
2505 status collapsed
2506
2507 \begin_layout Standard
2508
2509
2510 \backslash
2511 /
2512 \end_layout
2513
2514 \end_inset
2515
2516 -C' turns on caching, which gives a little bit extra speed.
2517  However if options are changed, it can be necessary to delete the config.cache
2518  file.
2519 \end_layout
2520
2521 \begin_layout Section
2522 Install paths
2523 \begin_inset LatexCommand \label{sub:Install-paths}
2524
2525 \end_inset
2526
2527
2528 \begin_inset LatexCommand \index{Install paths}
2529
2530 \end_inset
2531
2532
2533 \end_layout
2534
2535 \begin_layout Standard
2536 \begin_inset VSpace medskip
2537 \end_inset
2538
2539
2540 \end_layout
2541
2542 \begin_layout Standard
2543 \align center
2544 \begin_inset Tabular
2545 <lyxtabular version="3" rows="5" columns="4">
2546 <features>
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" width="0">
2550 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2551 <row topline="true" bottomline="true">
2552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2553 \begin_inset Text
2554
2555 \begin_layout Standard
2556
2557 \series bold
2558 Description
2559 \end_layout
2560
2561 \end_inset
2562 </cell>
2563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2564 \begin_inset Text
2565
2566 \begin_layout Standard
2567
2568 \series bold
2569 Path
2570 \end_layout
2571
2572 \end_inset
2573 </cell>
2574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2575 \begin_inset Text
2576
2577 \begin_layout Standard
2578
2579 \series bold
2580 Default
2581 \end_layout
2582
2583 \end_inset
2584 </cell>
2585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2586 \begin_inset Text
2587
2588 \begin_layout Standard
2589
2590 \series bold
2591 Win32 builds
2592 \end_layout
2593
2594 \end_inset
2595 </cell>
2596 </row>
2597 <row topline="true">
2598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2599 \begin_inset Text
2600
2601 \begin_layout Standard
2602 Binary files*
2603 \end_layout
2604
2605 \end_inset
2606 </cell>
2607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2608 \begin_inset Text
2609
2610 \begin_layout Standard
2611
2612 \emph on
2613 $EXEC_PREFIX
2614 \end_layout
2615
2616 \end_inset
2617 </cell>
2618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2619 \begin_inset Text
2620
2621 \begin_layout Standard
2622 /usr/local/bin
2623 \end_layout
2624
2625 \end_inset
2626 </cell>
2627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2628 \begin_inset Text
2629
2630 \begin_layout Standard
2631
2632 \backslash
2633 sdcc
2634 \backslash
2635 bin
2636 \end_layout
2637
2638 \end_inset
2639 </cell>
2640 </row>
2641 <row topline="true">
2642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2643 \begin_inset Text
2644
2645 \begin_layout Standard
2646 Include files
2647 \end_layout
2648
2649 \end_inset
2650 </cell>
2651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2652 \begin_inset Text
2653
2654 \begin_layout Standard
2655
2656 \emph on
2657 $DATADIR/ $INCLUDE_DIR_SUFFIX
2658 \end_layout
2659
2660 \end_inset
2661 </cell>
2662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2663 \begin_inset Text
2664
2665 \begin_layout Standard
2666 /usr/local/share/sdcc/include
2667 \end_layout
2668
2669 \end_inset
2670 </cell>
2671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2672 \begin_inset Text
2673
2674 \begin_layout Standard
2675
2676 \backslash
2677 sdcc
2678 \backslash
2679 include
2680 \end_layout
2681
2682 \end_inset
2683 </cell>
2684 </row>
2685 <row topline="true">
2686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2687 \begin_inset Text
2688
2689 \begin_layout Standard
2690 Library file**
2691 \end_layout
2692
2693 \end_inset
2694 </cell>
2695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2696 \begin_inset Text
2697
2698 \begin_layout Standard
2699
2700 \emph on
2701 $DATADIR/$LIB_DIR_SUFFIX
2702 \end_layout
2703
2704 \end_inset
2705 </cell>
2706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2707 \begin_inset Text
2708
2709 \begin_layout Standard
2710 /usr/local/share/sdcc/lib
2711 \end_layout
2712
2713 \end_inset
2714 </cell>
2715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2716 \begin_inset Text
2717
2718 \begin_layout Standard
2719
2720 \backslash
2721 sdcc
2722 \backslash
2723 lib
2724 \end_layout
2725
2726 \end_inset
2727 </cell>
2728 </row>
2729 <row topline="true" bottomline="true">
2730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2731 \begin_inset Text
2732
2733 \begin_layout Standard
2734 Documentation
2735 \end_layout
2736
2737 \end_inset
2738 </cell>
2739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2740 \begin_inset Text
2741
2742 \begin_layout Standard
2743
2744 \emph on
2745 $DOCDIR
2746 \end_layout
2747
2748 \end_inset
2749 </cell>
2750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2751 \begin_inset Text
2752
2753 \begin_layout Standard
2754 /usr/local/share/sdcc/doc
2755 \end_layout
2756
2757 \end_inset
2758 </cell>
2759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2760 \begin_inset Text
2761
2762 \begin_layout Standard
2763
2764 \backslash
2765 sdcc
2766 \backslash
2767 doc
2768 \end_layout
2769
2770 \end_inset
2771 </cell>
2772 </row>
2773 </lyxtabular>
2774
2775 \end_inset
2776
2777
2778 \end_layout
2779
2780 \begin_layout Verse
2781
2782 \size footnotesize
2783 *compiler, preprocessor, assembler, and linker
2784 \newline
2785 **the 
2786 \shape italic
2787 model
2788 \shape default
2789  is auto-appended by the compiler, e.g.
2790  small, large, z80, ds390 etc
2791 \end_layout
2792
2793 \begin_layout Standard
2794 \noindent
2795 The install paths can still be changed during `make install` with e.g.:
2796 \end_layout
2797
2798 \begin_layout LyX-Code
2799 make install prefix=$(HOME)/local/sdcc
2800 \end_layout
2801
2802 \begin_layout Standard
2803 Of course this doesn't change the search paths compiled into the binaries.
2804 \newline
2805
2806 \newline
2807 Moreove
2808 r the install path can be changed by defining DESTDIR
2809 \begin_inset LatexCommand \index{DESTDIR}
2810
2811 \end_inset
2812
2813 :
2814 \end_layout
2815
2816 \begin_layout LyX-Code
2817 make install DESTDIR=$(HOME)/sdcc.rpm/
2818 \end_layout
2819
2820 \begin_layout Standard
2821 Please note that DESTDIR must have a trailing slash!
2822 \end_layout
2823
2824 \begin_layout Section
2825 Search Paths
2826 \begin_inset LatexCommand \label{sub:Search-Paths}
2827
2828 \end_inset
2829
2830
2831 \begin_inset LatexCommand \index{Search path}
2832
2833 \end_inset
2834
2835
2836 \end_layout
2837
2838 \begin_layout Standard
2839 Some search paths or parts of them are determined by configure variables
2840  (in 
2841 \emph on
2842 italics
2843 \emph default
2844 , see section above).
2845  Further search paths are determined by environment variables during runtime.
2846  
2847 \newline
2848 The paths searched when running the compiler are as follows (the first
2849  catch wins):
2850 \newline
2851
2852 \newline
2853 1.
2854  Binary files (preprocessor, assembler and linker)
2855 \newline
2856
2857 \end_layout
2858
2859 \begin_layout Standard
2860 \align center
2861 \begin_inset Tabular
2862 <lyxtabular version="3" rows="4" columns="3">
2863 <features>
2864 <column alignment="block" valignment="top" leftline="true" width="0in">
2865 <column alignment="block" valignment="top" leftline="true" width="0in">
2866 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2867 <row topline="true" bottomline="true">
2868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2869 \begin_inset Text
2870
2871 \begin_layout Standard
2872 Search path
2873 \end_layout
2874
2875 \end_inset
2876 </cell>
2877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2878 \begin_inset Text
2879
2880 \begin_layout Standard
2881 default
2882 \end_layout
2883
2884 \end_inset
2885 </cell>
2886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2887 \begin_inset Text
2888
2889 \begin_layout Standard
2890 Win32 builds
2891 \end_layout
2892
2893 \end_inset
2894 </cell>
2895 </row>
2896 <row topline="true">
2897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2898 \begin_inset Text
2899
2900 \begin_layout Standard
2901 $SDCC_HOME/
2902 \emph on
2903 $PPREFIX2BIN_DIR
2904 \end_layout
2905
2906 \end_inset
2907 </cell>
2908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2909 \begin_inset Text
2910
2911 \begin_layout Standard
2912 $SDCC_HOME/bin
2913 \end_layout
2914
2915 \end_inset
2916 </cell>
2917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2918 \begin_inset Text
2919
2920 \begin_layout Standard
2921 $SDCC_HOME
2922 \backslash
2923 bin
2924 \end_layout
2925
2926 \end_inset
2927 </cell>
2928 </row>
2929 <row topline="true">
2930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2931 \begin_inset Text
2932
2933 \begin_layout Standard
2934 Path of argv[0] (if available)
2935 \end_layout
2936
2937 \end_inset
2938 </cell>
2939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2940 \begin_inset Text
2941
2942 \begin_layout Standard
2943 Path of argv[0]
2944 \end_layout
2945
2946 \end_inset
2947 </cell>
2948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2949 \begin_inset Text
2950
2951 \begin_layout Standard
2952 Path of argv[0]
2953 \end_layout
2954
2955 \end_inset
2956 </cell>
2957 </row>
2958 <row topline="true" bottomline="true">
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_inset Text
2961
2962 \begin_layout Standard
2963 $PATH
2964 \end_layout
2965
2966 \end_inset
2967 </cell>
2968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2969 \begin_inset Text
2970
2971 \begin_layout Standard
2972 $PATH
2973 \end_layout
2974
2975 \end_inset
2976 </cell>
2977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2978 \begin_inset Text
2979
2980 \begin_layout Standard
2981 $PATH
2982 \end_layout
2983
2984 \end_inset
2985 </cell>
2986 </row>
2987 </lyxtabular>
2988
2989 \end_inset
2990
2991  
2992 \newline
2993
2994 \end_layout
2995
2996 \begin_layout Standard
2997 \noindent
2998 2.
2999  Include files
3000 \newline
3001
3002 \end_layout
3003
3004 \begin_layout Standard
3005 \align center
3006 \begin_inset Tabular
3007 <lyxtabular version="3" rows="6" columns="3">
3008 <features>
3009 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3010 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3011 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3012 <row topline="true" bottomline="true">
3013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3014 \begin_inset Text
3015
3016 \begin_layout Standard
3017 Search path
3018 \end_layout
3019
3020 \end_inset
3021 </cell>
3022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3023 \begin_inset Text
3024
3025 \begin_layout Standard
3026 default
3027 \end_layout
3028
3029 \end_inset
3030 </cell>
3031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3032 \begin_inset Text
3033
3034 \begin_layout Standard
3035 Win32 builds
3036 \end_layout
3037
3038 \end_inset
3039 </cell>
3040 </row>
3041 <row topline="true">
3042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3043 \begin_inset Text
3044
3045 \begin_layout Standard
3046 -
3047 \begin_inset ERT
3048 status collapsed
3049
3050 \begin_layout Standard
3051
3052
3053 \backslash
3054 /
3055 \end_layout
3056
3057 \end_inset
3058
3059 -I dir
3060 \end_layout
3061
3062 \end_inset
3063 </cell>
3064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3065 \begin_inset Text
3066
3067 \begin_layout Standard
3068 -
3069 \begin_inset ERT
3070 status collapsed
3071
3072 \begin_layout Standard
3073
3074
3075 \backslash
3076 /
3077 \end_layout
3078
3079 \end_inset
3080
3081 -I dir
3082 \end_layout
3083
3084 \end_inset
3085 </cell>
3086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3087 \begin_inset Text
3088
3089 \begin_layout Standard
3090 -
3091 \begin_inset ERT
3092 status collapsed
3093
3094 \begin_layout Standard
3095
3096
3097 \backslash
3098 /
3099 \end_layout
3100
3101 \end_inset
3102
3103 -I dir
3104 \end_layout
3105
3106 \end_inset
3107 </cell>
3108 </row>
3109 <row topline="true">
3110 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3111 \begin_inset Text
3112
3113 \begin_layout Standard
3114 $SDCC_INCLUDE
3115 \end_layout
3116
3117 \end_inset
3118 </cell>
3119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3120 \begin_inset Text
3121
3122 \begin_layout Standard
3123 $SDCC_INCLUDE
3124 \end_layout
3125
3126 \end_inset
3127 </cell>
3128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3129 \begin_inset Text
3130
3131 \begin_layout Standard
3132 $SDCC_INCLUDE
3133 \end_layout
3134
3135 \end_inset
3136 </cell>
3137 </row>
3138 <row topline="true">
3139 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3140 \begin_inset Text
3141
3142 \begin_layout Standard
3143 $SDCC_HOME/
3144 \newline
3145
3146 \emph on
3147 $PREFIX2DATA_DIR/
3148 \newline
3149 $INCLUDE_DIR_SUFFIX
3150 \end_layout
3151
3152 \end_inset
3153 </cell>
3154 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3155 \begin_inset Text
3156
3157 \begin_layout Standard
3158 $SDCC_ HOME/
3159 \newline
3160 share/sdcc/
3161 \newline
3162 include
3163 \end_layout
3164
3165 \end_inset
3166 </cell>
3167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3168 \begin_inset Text
3169
3170 \begin_layout Standard
3171 $SDCC_HOME
3172 \backslash
3173 include
3174 \end_layout
3175
3176 \end_inset
3177 </cell>
3178 </row>
3179 <row topline="true">
3180 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3181 \begin_inset Text
3182
3183 \begin_layout Standard
3184 path(argv[0])/
3185 \newline
3186
3187 \emph on
3188 $BIN2DATADIR/
3189 \emph default
3190
3191 \newline
3192
3193 \emph on
3194 $INCLUDE_DIR_SUFFIX
3195 \end_layout
3196
3197 \end_inset
3198 </cell>
3199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3200 \begin_inset Text
3201
3202 \begin_layout Standard
3203 path(argv[0])/
3204 \newline
3205 ../sdcc/include
3206 \newline
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 \InsetSpace ~
3245
3246 \end_layout
3247
3248 \end_inset
3249 </cell>
3250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3251 \begin_inset Text
3252
3253 \begin_layout Standard
3254 path(argv[0])
3255 \backslash
3256 ..
3257 \backslash
3258 include
3259 \end_layout
3260
3261 \end_inset
3262 </cell>
3263 </row>
3264 <row topline="true" bottomline="true">
3265 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3266 \begin_inset Text
3267
3268 \begin_layout Standard
3269
3270 \emph on
3271 $DATADIR/
3272 \emph default
3273
3274 \newline
3275
3276 \emph on
3277 $INCLUDE_DIR_SUFFIX
3278 \end_layout
3279
3280 \end_inset
3281 </cell>
3282 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3283 \begin_inset Text
3284
3285 \begin_layout Standard
3286 /usr/local/share/sdcc/
3287 \newline
3288 include
3289 \end_layout
3290
3291 \end_inset
3292 </cell>
3293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3294 \begin_inset Text
3295
3296 \begin_layout Standard
3297 (not on Win32)
3298 \end_layout
3299
3300 \end_inset
3301 </cell>
3302 </row>
3303 </lyxtabular>
3304
3305 \end_inset
3306
3307  
3308 \newline
3309
3310 \end_layout
3311
3312 \begin_layout Standard
3313 \noindent
3314 The option -
3315 \begin_inset ERT
3316 status collapsed
3317
3318 \begin_layout Standard
3319
3320
3321 \backslash
3322 /
3323 \end_layout
3324
3325 \end_inset
3326
3327 -nostdinc disables the last two search paths.
3328 \newline
3329
3330 \newline
3331 3.
3332  Library files 
3333 \newline
3334
3335 \end_layout
3336
3337 \begin_layout Standard
3338 With the exception of 
3339 \begin_inset Quotes sld
3340 \end_inset
3341
3342 -
3343 \begin_inset ERT
3344 status collapsed
3345
3346 \begin_layout Standard
3347
3348
3349 \backslash
3350 /
3351 \end_layout
3352
3353 \end_inset
3354
3355 -L dir
3356 \begin_inset Quotes srd
3357 \end_inset
3358
3359  the 
3360 \shape italic
3361 model
3362 \shape default
3363  is auto-appended by the compiler (e.g.
3364  small, large, z80, ds390 etc.).
3365  
3366 \newline
3367
3368 \end_layout
3369
3370 \begin_layout Standard
3371 \align center
3372 \begin_inset Tabular
3373 <lyxtabular version="3" rows="6" columns="3">
3374 <features>
3375 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3376 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3377 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3378 <row topline="true" bottomline="true">
3379 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3380 \begin_inset Text
3381
3382 \begin_layout Standard
3383 Search path
3384 \end_layout
3385
3386 \end_inset
3387 </cell>
3388 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3389 \begin_inset Text
3390
3391 \begin_layout Standard
3392 default
3393 \end_layout
3394
3395 \end_inset
3396 </cell>
3397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3398 \begin_inset Text
3399
3400 \begin_layout Standard
3401 Win32 builds
3402 \end_layout
3403
3404 \end_inset
3405 </cell>
3406 </row>
3407 <row topline="true">
3408 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3409 \begin_inset Text
3410
3411 \begin_layout Standard
3412 -
3413 \begin_inset ERT
3414 status collapsed
3415
3416 \begin_layout Standard
3417
3418
3419 \backslash
3420 /
3421 \end_layout
3422
3423 \end_inset
3424
3425 -L dir
3426 \end_layout
3427
3428 \end_inset
3429 </cell>
3430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3431 \begin_inset Text
3432
3433 \begin_layout Standard
3434 -
3435 \begin_inset ERT
3436 status collapsed
3437
3438 \begin_layout Standard
3439
3440
3441 \backslash
3442 /
3443 \end_layout
3444
3445 \end_inset
3446
3447 -L dir
3448 \end_layout
3449
3450 \end_inset
3451 </cell>
3452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3453 \begin_inset Text
3454
3455 \begin_layout Standard
3456 -
3457 \begin_inset ERT
3458 status collapsed
3459
3460 \begin_layout Standard
3461
3462
3463 \backslash
3464 /
3465 \end_layout
3466
3467 \end_inset
3468
3469 -L dir
3470 \end_layout
3471
3472 \end_inset
3473 </cell>
3474 </row>
3475 <row topline="true">
3476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3477 \begin_inset Text
3478
3479 \begin_layout Standard
3480 $SDCC_LIB/
3481 \newline
3482
3483 \emph on
3484 <model>
3485 \end_layout
3486
3487 \end_inset
3488 </cell>
3489 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3490 \begin_inset Text
3491
3492 \begin_layout Standard
3493 $SDCC_LIB/
3494 \newline
3495
3496 \emph on
3497 <model>
3498 \end_layout
3499
3500 \end_inset
3501 </cell>
3502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3503 \begin_inset Text
3504
3505 \begin_layout Standard
3506 $SDCC_LIB
3507 \backslash
3508
3509 \newline
3510
3511 \emph on
3512 <model>
3513 \end_layout
3514
3515 \end_inset
3516 </cell>
3517 </row>
3518 <row topline="true">
3519 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3520 \begin_inset Text
3521
3522 \begin_layout Standard
3523 $SDCC_HOME/
3524 \newline
3525
3526 \emph on
3527 $PREFIX2DATA_DIR/
3528 \newline
3529 $LIB_DIR_SUFFIX/<model>
3530 \end_layout
3531
3532 \end_inset
3533 </cell>
3534 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3535 \begin_inset Text
3536
3537 \begin_layout Standard
3538 $SDCC_HOME/
3539 \newline
3540 share/sdcc/
3541 \newline
3542 lib/
3543 \emph on
3544 <model>
3545 \end_layout
3546
3547 \end_inset
3548 </cell>
3549 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3550 \begin_inset Text
3551
3552 \begin_layout Standard
3553 $SDCC_HOME
3554 \backslash
3555 lib
3556 \backslash
3557
3558 \emph on
3559
3560 \newline
3561 <model>
3562 \end_layout
3563
3564 \end_inset
3565 </cell>
3566 </row>
3567 <row topline="true">
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3569 \begin_inset Text
3570
3571 \begin_layout Standard
3572 path(argv[0])/
3573 \newline
3574
3575 \emph on
3576 $BIN2DATADIR/
3577 \emph default
3578
3579 \newline
3580
3581 \emph on
3582 $LIB_DIR_SUFFIX/<model>
3583 \end_layout
3584
3585 \end_inset
3586 </cell>
3587 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3588 \begin_inset Text
3589
3590 \begin_layout Standard
3591 path(argv[0])/
3592 \newline
3593 ../sdcc/lib/
3594 \emph on
3595 <model>
3596 \newline
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 \InsetSpace ~
3636
3637 \end_layout
3638
3639 \end_inset
3640 </cell>
3641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3642 \begin_inset Text
3643
3644 \begin_layout Standard
3645 path(argv[0])
3646 \backslash
3647
3648 \newline
3649 ..
3650 \backslash
3651 lib
3652 \backslash
3653
3654 \emph on
3655 <model>
3656 \newline
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 \InsetSpace ~
3692
3693 \end_layout
3694
3695 \end_inset
3696 </cell>
3697 </row>
3698 <row topline="true" bottomline="true">
3699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3700 \begin_inset Text
3701
3702 \begin_layout Standard
3703
3704 \emph on
3705 $DATADIR/
3706 \newline
3707 $LIB_DIR_SUFFIX/<model>
3708 \end_layout
3709
3710 \end_inset
3711 </cell>
3712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3713 \begin_inset Text
3714
3715 \begin_layout Standard
3716 /usr/local/share/sdcc/
3717 \newline
3718 lib/
3719 \emph on
3720 <model>
3721 \end_layout
3722
3723 \end_inset
3724 </cell>
3725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3726 \begin_inset Text
3727
3728 \begin_layout Standard
3729 (not on Win32)
3730 \end_layout
3731
3732 \end_inset
3733 </cell>
3734 </row>
3735 </lyxtabular>
3736
3737 \end_inset
3738
3739
3740 \newline
3741
3742 \end_layout
3743
3744 \begin_layout Standard
3745 \begin_inset Note Note
3746 status collapsed
3747
3748 \begin_layout Standard
3749 Don't delete any of the stray spaces in the table above without checking
3750  the HTML output (last line)!
3751 \end_layout
3752
3753 \end_inset
3754
3755
3756 \end_layout
3757
3758 \begin_layout Standard
3759 \InsetSpace ~
3760
3761 \newline
3762 The option -
3763 \begin_inset ERT
3764 status collapsed
3765
3766 \begin_layout Standard
3767
3768
3769 \backslash
3770 /
3771 \end_layout
3772
3773 \end_inset
3774
3775 -nostdlib disables the last two search paths.
3776 \end_layout
3777
3778 \begin_layout Section
3779 Building SDCC
3780 \begin_inset LatexCommand \index{Building SDCC}
3781
3782 \end_inset
3783
3784
3785 \end_layout
3786
3787 \begin_layout Subsection
3788 Building SDCC on Linux
3789 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3790
3791 \end_inset
3792
3793
3794 \end_layout
3795
3796 \begin_layout Enumerate
3797
3798 \series medium
3799 Download the source package
3800 \series default
3801  either from the SDCC Subversion repository or from snapshot builds
3802 \series medium
3803 , it will be named something like sdcc
3804 \series default
3805 -src
3806 \series medium
3807 -yyyymmdd-rrrr.t
3808 \series default
3809 ar.
3810 \series medium
3811 bz2
3812 \series default
3813  
3814 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3815
3816 \end_inset
3817
3818 .
3819 \end_layout
3820
3821 \begin_layout Enumerate
3822
3823 \series medium
3824 Bring up a command line terminal, such as xterm.
3825 \end_layout
3826
3827 \begin_layout Enumerate
3828
3829 \series medium
3830 Unpack the file using a command like: 
3831 \family sans
3832 \series bold
3833 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3834 \begin_inset Quotes srd
3835 \end_inset
3836
3837
3838 \family default
3839 \series medium
3840 , this will create a sub-directory called sdcc with all of the sources.
3841 \end_layout
3842
3843 \begin_layout Enumerate
3844 Change directory into the main SDCC directory, for example type: 
3845 \family sans
3846 \series bold
3847 "cd sdcc
3848 \series default
3849 ".
3850 \end_layout
3851
3852 \begin_layout Enumerate
3853
3854 \series medium
3855 Type 
3856 \family sans
3857 \series bold
3858 "./configure
3859 \family default
3860 \series default
3861 ".
3862  This configures the package for compilation on your system.
3863 \end_layout
3864
3865 \begin_layout Enumerate
3866
3867 \series medium
3868 Type 
3869 \family sans
3870 \series bold
3871 "make
3872 \family default
3873 \series default
3874 "
3875 \series medium
3876 .
3877
3878 \series default
3879  All of the source packages will compile, this can take a while.
3880 \end_layout
3881
3882 \begin_layout Enumerate
3883
3884 \series medium
3885 Type 
3886 \family sans
3887 \series bold
3888 "make install"
3889 \family default
3890 \series default
3891  as root
3892 \series medium
3893 .
3894
3895 \series default
3896  This copies the binary executables, the include files, the libraries and
3897  the documentation to the install directories.
3898  Proceed with section 
3899 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3900
3901 \end_inset
3902
3903 .
3904 \end_layout
3905
3906 \begin_layout Subsection
3907 Building SDCC on OSX 2.x
3908 \end_layout
3909
3910 \begin_layout Standard
3911 Follow the instruction for Linux.
3912 \newline
3913
3914 \newline
3915 On OSX 2.x it was reported, that the default
3916  gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3917  Fortunately there's also gcc 2.9.x installed, which works fine.
3918  This compiler can be selected by running 'configure' with:
3919 \end_layout
3920
3921 \begin_layout LyX-Code
3922 ./configure CC=gcc2 CXX=g++2
3923 \end_layout
3924
3925 \begin_layout Subsection
3926 Cross compiling SDCC on Linux for Windows
3927 \end_layout
3928
3929 \begin_layout Standard
3930 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3931  See section 'Configure Options'.
3932 \end_layout
3933
3934 \begin_layout Subsection
3935 Building SDCC using Cygwin and Mingw32
3936 \end_layout
3937
3938 \begin_layout Standard
3939 For building and installing a Cygwin executable follow the instructions
3940  for Linux.
3941 \newline
3942
3943 \newline
3944 On Cygwin a 
3945 \begin_inset Quotes sld
3946 \end_inset
3947
3948 native
3949 \begin_inset Quotes srd
3950 \end_inset
3951
3952  Win32-binary can be built, which will not need the Cygwin-DLL.
3953  For the necessary 'configure' options see section 'configure options' or
3954  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3955 \newline
3956
3957 \newline
3958 In order to install
3959  Cygwin on Windows download setup.exe from 
3960 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3961
3962 \end_inset
3963
3964 .
3965  Run it, set the 
3966 \begin_inset Quotes sld
3967 \end_inset
3968
3969 default text file type
3970 \begin_inset Quotes srd
3971 \end_inset
3972
3973  to 
3974 \begin_inset Quotes sld
3975 \end_inset
3976
3977 unix
3978 \begin_inset Quotes srd
3979 \end_inset
3980
3981  and download/install at least the following packages.
3982  Some packages are selected by default, others will be automatically selected
3983  because of dependencies with the manually selected packages.
3984  Never deselect these packages!
3985 \end_layout
3986
3987 \begin_layout Itemize
3988 flex
3989 \end_layout
3990
3991 \begin_layout Itemize
3992 bison
3993 \end_layout
3994
3995 \begin_layout Itemize
3996 gcc ; version 3.x is fine, no need to use the old 2.9x
3997 \end_layout
3998
3999 \begin_layout Itemize
4000 binutils ; selected with gcc
4001 \end_layout
4002
4003 \begin_layout Itemize
4004 make
4005 \end_layout
4006
4007 \begin_layout Itemize
4008 rxvt ; a nice console, which makes life much easier under windoze (see below)
4009 \end_layout
4010
4011 \begin_layout Itemize
4012 man ; not really needed for building SDCC, but you'll miss it sooner or
4013  later
4014 \end_layout
4015
4016 \begin_layout Itemize
4017 less ; not really needed for building SDCC, but you'll miss it sooner or
4018  later
4019 \end_layout
4020
4021 \begin_layout Itemize
4022 svn ; only if you use Subversion access
4023 \end_layout
4024
4025 \begin_layout Standard
4026 If you want to develop something you'll need:
4027 \end_layout
4028
4029 \begin_layout Itemize
4030 python ; for the regression tests
4031 \end_layout
4032
4033 \begin_layout Itemize
4034 gdb ; the gnu debugger, together with the nice GUI 
4035 \begin_inset Quotes sld
4036 \end_inset
4037
4038 insight
4039 \begin_inset Quotes srd
4040 \end_inset
4041
4042
4043 \end_layout
4044
4045 \begin_layout Itemize
4046 openssh ; to access the CF or commit changes
4047 \end_layout
4048
4049 \begin_layout Itemize
4050 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4051  use autoconf-stable!
4052 \end_layout
4053
4054 \begin_layout Standard
4055 rxvt is a nice console with history.
4056  Replace in your cygwin.bat the line
4057 \end_layout
4058
4059 \begin_layout LyX-Code
4060 bash -
4061 \begin_inset ERT
4062 status collapsed
4063
4064 \begin_layout Standard
4065
4066
4067 \backslash
4068 /
4069 \end_layout
4070
4071 \end_inset
4072
4073 -login -i 
4074 \end_layout
4075
4076 \begin_layout Standard
4077 with (one line):
4078 \end_layout
4079
4080 \begin_layout LyX-Code
4081 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4082 \end_layout
4083
4084 \begin_layout LyX-Code
4085      -bg black -fg white -geometry 100x65 -e bash -
4086 \begin_inset ERT
4087 status collapsed
4088
4089 \begin_layout Standard
4090
4091
4092 \backslash
4093 /
4094 \end_layout
4095
4096 \end_inset
4097
4098 -login
4099 \end_layout
4100
4101 \begin_layout Standard
4102 Text selected with the mouse is automatically copied to the clipboard, pasting
4103  works with shift-insert.
4104 \newline
4105
4106 \newline
4107 The other good tip is to make sure you have no //c/-styl
4108 e paths anywhere, use /cygdrive/c/ instead.
4109  Using // invokes a network lookup which is very slow.
4110  If you think 
4111 \begin_inset Quotes sld
4112 \end_inset
4113
4114 cygdrive
4115 \begin_inset Quotes srd
4116 \end_inset
4117
4118  is too long, you can change it with e.g.
4119 \end_layout
4120
4121 \begin_layout LyX-Code
4122 mount -s -u -c /mnt
4123 \end_layout
4124
4125 \begin_layout Standard
4126 SDCC sources use the unix line ending LF.
4127  Life is much easier, if you store the source tree on a drive which is mounted
4128  in binary mode.
4129  And use an editor which can handle LF-only line endings.
4130  Make sure not to commit files with windows line endings.
4131  The tabulator spacing
4132 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4133
4134 \end_inset
4135
4136  used in the project is 8.
4137  Although a tabulator spacing of 8 is a sensible choice for programmers
4138  (it's a power of 2 and allows to display 8/16 bit signed variables without
4139  loosing columns) the plan is to move towards using only spaces in the source.
4140 \end_layout
4141
4142 \begin_layout Subsection
4143 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4144 \end_layout
4145
4146 \begin_layout Standard
4147
4148 \series medium
4149 Download the source package
4150 \series default
4151  either from the SDCC Subversion repository or from the 
4152 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4153
4154 \end_inset
4155
4156
4157 \series medium
4158 , it will be named something like sdcc
4159 \series default
4160 -src
4161 \series medium
4162 -yyyymmdd-rrrr.tar.bz2.
4163
4164 \series default
4165  SDCC is distributed with all the projects, workspaces, and files you need
4166  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4167  The workspace name is 'sdcc.dsw'.
4168  Please note that as it is now, all the executables are created in a folder
4169  called sdcc
4170 \backslash
4171 bin_vc.
4172  Once built you need to copy the executables from sdcc
4173 \backslash
4174 bin_vc to sdcc
4175 \backslash
4176 bin before running SDCC.
4177  
4178 \newline
4179
4180 \newline
4181 WARNING: Visual studio is very picky with line terminations; it expects
4182  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4183  When using the Subversion repository it's easiest to configure the svn
4184  client to convert automatically for you.
4185  If however you are getting a message such as "This makefile was not generated
4186  by Developer Studio etc.
4187  etc.
4188 \begin_inset Quotes srd
4189 \end_inset
4190
4191  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4192  need to convert the Unix style line endings to DOS style line endings.
4193  To do so you can use the 
4194 \begin_inset Quotes sld
4195 \end_inset
4196
4197 unix2dos
4198 \begin_inset Quotes srd
4199 \end_inset
4200
4201  utility freely available on the internet.
4202  Doug Hawkins reported in the sdcc-user list that this works:
4203 \newline
4204
4205 \newline
4206 C:
4207 \backslash
4208 Programming
4209 \backslash
4210 SDCC> unix2dos sdcc.dsw
4211 \newline
4212 C:
4213 \backslash
4214 Programming
4215 \backslash
4216 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4217 \newline
4218
4219 \newline
4220 In order to build SDCC with MSVC
4221  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4222  One good place to get them is 
4223 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4224
4225 \end_inset
4226
4227
4228 \newline
4229
4230 \newline
4231 Download the file UnxUtils
4232 \begin_inset LatexCommand \index{UnxUtils}
4233
4234 \end_inset
4235
4236 .zip.
4237  Now you have to install the utilities and setup MSVC so it can locate the
4238  required programs.
4239  Here there are two alternatives (choose one!):
4240 \end_layout
4241
4242 \begin_layout Enumerate
4243 The easy way:
4244 \newline
4245
4246 \newline
4247 a) Extract UnxUtils.zip to your C:
4248 \backslash
4249  hard disk PRESERVING the original paths, otherwise bison won't work.
4250  (If you are using WinZip make certain that 'Use folder names' is selected)
4251 \newline
4252
4253 \newline
4254 b)
4255  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4256  'Show directories for:' select 'Executable files', and in the directories
4257  window add a new path: 'C:
4258 \backslash
4259 user
4260 \backslash
4261 local
4262 \backslash
4263 wbin', click ok.
4264 \newline
4265
4266 \newline
4267 (As a side effect, you get a bunch of Unix utilities that
4268  could be useful, such as diff and patch.)
4269 \end_layout
4270
4271 \begin_layout Enumerate
4272 A more compact way:
4273 \newline
4274
4275 \newline
4276 This one avoids extracting a bunch of files you may not
4277  use, but requires some extra work:
4278 \newline
4279
4280 \newline
4281 a) Create a directory were to put the
4282  tools needed, or use a directory already present.
4283  Say for example 'C:
4284 \backslash
4285 util'.
4286 \newline
4287
4288 \newline
4289 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4290  gawk.exe to such directory WITHOUT preserving the original paths.
4291  (If you are using WinZip make certain that 'Use folder names' is not selected)
4292 \newline
4293
4294 \newline
4295 c
4296 ) Rename bison.exe to '_bison.exe'.
4297 \newline
4298
4299 \newline
4300 d) Create a batch file 'bison.bat' in 'C:
4301 \backslash
4302 util
4303 \backslash
4304 ' and add these lines: 
4305 \newline
4306 \InsetSpace ~
4307 \InsetSpace ~
4308 set BISON_SIMPLE=C:
4309 \backslash
4310 util
4311 \backslash
4312 bison.simple 
4313 \newline
4314 \InsetSpace ~
4315 \InsetSpace ~
4316 set BISON_HAIRY=C:
4317 \backslash
4318 util
4319 \backslash
4320 bison.hairy
4321 \newline
4322 \InsetSpace ~
4323 \InsetSpace ~
4324 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4325 \newline
4326
4327 \newline
4328 Steps 'c' and 'd' are needed
4329  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4330  reside in some weird Unix directory, '/usr/local/share/' I think.
4331  So it is necessary to tell bison where those files are located if they
4332  are not in such directory.
4333  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4334 \newline
4335
4336 \newline
4337 e
4338 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4339  in 'Show directories for:' select 'Executable files', and in the directories
4340  window add a new path: 'c:
4341 \backslash
4342 util', click ok.
4343  Note that you can use any other path instead of 'c:
4344 \backslash
4345 util', even the path where the Visual C++ tools are, probably: 'C:
4346 \backslash
4347 Program Files
4348 \backslash
4349 Microsoft Visual Studio
4350 \backslash
4351 Common
4352 \backslash
4353 Tools'.
4354  So you don't have to execute step 'e' :)
4355 \end_layout
4356
4357 \begin_layout Standard
4358 That is it.
4359  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4360  the executables from sdcc
4361 \backslash
4362 bin_vc to sdcc
4363 \backslash
4364 bin, and you can compile using SDCC.
4365 \end_layout
4366
4367 \begin_layout Subsection
4368 Building SDCC Using Borland
4369 \end_layout
4370
4371 \begin_layout Enumerate
4372 From the sdcc directory, run the command "make -f Makefile.bcc".
4373  This should regenerate all the .exe files in the bin directory except for
4374  SDCDB and ucSim.
4375 \end_layout
4376
4377 \begin_layout Enumerate
4378 If you modify any source files and need to rebuild, be aware that the dependenci
4379 es may not be correctly calculated.
4380  The safest option is to delete all .obj files and run the build again.
4381  From a Cygwin BASH prompt, this can easily be done with the command (be
4382  sure you are in the sdcc directory):
4383 \newline
4384
4385 \newline
4386
4387 \family sans
4388 \series bold
4389 find .
4390  
4391 \backslash
4392 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4393 \backslash
4394 ) -print -exec rm {} 
4395 \backslash
4396 ;
4397 \family default
4398 \series default
4399
4400 \newline
4401
4402 \newline
4403 or on Windows NT/2000/XP from the command prompt with the command:
4404 \newline
4405
4406 \family sans
4407 \series bold
4408
4409 \newline
4410 del /s *.obj *.lib *.rul
4411 \family default
4412 \series default
4413  from the sdcc directory.
4414 \end_layout
4415
4416 \begin_layout Subsection
4417 Windows Install Using a ZIP Package
4418 \end_layout
4419
4420 \begin_layout Enumerate
4421 Download the binary zip package from 
4422 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4423
4424 \end_inset
4425
4426  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4427  This should unpack to a group of sub-directories.
4428  An example directory structure after unpacking the mingw32 package is:
4429  c:
4430 \backslash
4431 sdcc
4432 \backslash
4433 bin for the executables, c:
4434 \backslash
4435 sdcc
4436 \backslash
4437 include and c:
4438 \backslash
4439 sdcc
4440 \backslash
4441 lib for the include and libraries.
4442 \end_layout
4443
4444 \begin_layout Enumerate
4445 Adjust your environment variable PATH to include the location of the bin
4446  directory or start sdcc using the full path.
4447 \end_layout
4448
4449 \begin_layout Subsection
4450 Windows Install Using the Setup Program
4451 \begin_inset LatexCommand \label{sub:Windows-Install}
4452
4453 \end_inset
4454
4455
4456 \end_layout
4457
4458 \begin_layout Standard
4459 Download the setup program 
4460 \emph on
4461 sdcc-x.y.z-setup.exe
4462 \emph default
4463  for an official release from 
4464 \newline
4465
4466 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4467
4468 \end_inset
4469
4470  or a setup program for one of the snapshots 
4471 \emph on
4472 sdcc-yyyymmdd-xxxx-setup.exe
4473 \emph default
4474  from 
4475 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4476
4477 \end_inset
4478
4479  and execute it.
4480  A windows typical installer will guide you through the installation process.
4481 \end_layout
4482
4483 \begin_layout Subsection
4484 VPATH
4485 \begin_inset LatexCommand \index{VPATH}
4486
4487 \end_inset
4488
4489  feature
4490 \end_layout
4491
4492 \begin_layout Standard
4493 SDCC supports the VPATH feature provided by configure and make.
4494  It allows to separate the source and build trees.
4495  Here's an example:
4496 \end_layout
4497
4498 \begin_layout Standard
4499
4500 \family typewriter
4501 cd ~\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 \InsetSpace ~
4520 \InsetSpace ~
4521 \InsetSpace ~
4522 # cd $HOME
4523 \end_layout
4524
4525 \begin_layout Standard
4526
4527 \family typewriter
4528 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4529 # extract source to directory sdcc
4530 \end_layout
4531
4532 \begin_layout Standard
4533
4534 \family typewriter
4535 mkdir sdcc.build\InsetSpace ~
4536 \InsetSpace ~
4537 \InsetSpace ~
4538 \InsetSpace ~
4539 \InsetSpace ~
4540 \InsetSpace ~
4541 \InsetSpace ~
4542 \InsetSpace ~
4543 \InsetSpace ~
4544 # put output in sdcc.build
4545 \end_layout
4546
4547 \begin_layout Standard
4548
4549 \family typewriter
4550 cd sdcc.build
4551 \end_layout
4552
4553 \begin_layout Standard
4554
4555 \family typewriter
4556 ../sdcc/configure\InsetSpace ~
4557 \InsetSpace ~
4558 \InsetSpace ~
4559 \InsetSpace ~
4560 \InsetSpace ~
4561 \InsetSpace ~
4562 \InsetSpace ~
4563 \InsetSpace ~
4564 # configure is doing all the magic!
4565 \end_layout
4566
4567 \begin_layout Standard
4568
4569 \family typewriter
4570 make
4571 \end_layout
4572
4573 \begin_layout Standard
4574 \noindent
4575 That's it! 
4576 \series bold
4577 configure
4578 \series default
4579  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4580  It automagically computes the variables srcdir, top_srcdir and top_buildir
4581  for each directory.
4582  After running 
4583 \series bold
4584 make
4585 \series default
4586  the generated files will be in ~/sdcc.build, while the source files stay
4587  in ~/sdcc.
4588 \newline
4589 This is not only usefull for building different binaries, e.g.
4590  when cross compiling.
4591  It also gives you a much better overview in the source tree when all the
4592  generated files are not scattered between the source files.
4593  And the best thing is: if you want to change a file you can leave the original
4594  file untouched in the source directory.
4595  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4596  Makefile.dep` and `make`.
4597  
4598 \series bold
4599 make
4600 \series default
4601  will do the rest for you!
4602 \end_layout
4603
4604 \begin_layout Section
4605 Building the Documentation
4606 \end_layout
4607
4608 \begin_layout Standard
4609 Add -
4610 \begin_inset ERT
4611 status collapsed
4612
4613 \begin_layout Standard
4614
4615
4616 \backslash
4617 /
4618 \end_layout
4619
4620 \end_inset
4621
4622 -enable-doc to the configure arguments to build the documentation together
4623  with all the other stuff.
4624  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4625  dvips and makeindex) to get the job done.
4626  Another possibility is to change to the doc directory and to type 
4627 \family sans
4628 \series bold
4629
4630 \begin_inset Quotes srd
4631 \end_inset
4632
4633 make
4634 \begin_inset Quotes srd
4635 \end_inset
4636
4637
4638 \family default
4639 \series default
4640  there.
4641  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4642 x).
4643  Using LyX 
4644 \begin_inset LatexCommand \url{http://www.lyx.org}
4645
4646 \end_inset
4647
4648  as editor is straightforward.
4649  Prebuilt documentation in html and pdf format is available from 
4650 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4651
4652 \end_inset
4653
4654 .
4655 \end_layout
4656
4657 \begin_layout Section
4658 Reading the Documentation
4659 \begin_inset LatexCommand \index{Documentation}
4660
4661 \end_inset
4662
4663
4664 \end_layout
4665
4666 \begin_layout Standard
4667 Currently reading the document in pdf format is recommended, as for unknown
4668  reason the hyperlinks are working there whereas in the html version they
4669  are not
4670 \begin_inset Foot
4671 status open
4672
4673 \begin_layout Standard
4674 If you should know why please drop us a note
4675 \end_layout
4676
4677 \end_inset
4678
4679 .
4680  
4681 \newline
4682 You'll find the pdf version
4683 \begin_inset LatexCommand \index{PDF version of this document}
4684
4685 \end_inset
4686
4687  at 
4688 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4689
4690 \end_inset
4691
4692 .
4693  
4694 \newline
4695 A html version
4696 \begin_inset LatexCommand \index{HTML version of this document}
4697
4698 \end_inset
4699
4700  should be online at 
4701 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4702
4703 \end_inset
4704
4705 .
4706 \newline
4707 This documentation is in some aspects different from a commercial documentation:
4708  
4709 \end_layout
4710
4711 \begin_layout Itemize
4712 It tries to document SDCC for several processor architectures in one document
4713  (commercially these probably would be separate documents/products).
4714  This document
4715 \begin_inset LatexCommand \index{Status of documentation}
4716
4717 \end_inset
4718
4719  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4720 on about f.e.
4721  Z80, PIC14, PIC16 and HC08.
4722 \end_layout
4723
4724 \begin_layout Itemize
4725 There are many references pointing away from this documentation.
4726  Don't let this distract you.
4727  If there f.e.
4728  was a reference like 
4729 \begin_inset LatexCommand \url{http://www.opencores.org}
4730
4731 \end_inset
4732
4733  together with a statement 
4734 \begin_inset Quotes sld
4735 \end_inset
4736
4737 some processors which are targetted by SDCC can be implemented in a 
4738 \emph on
4739 f
4740 \emph default
4741 ield 
4742 \emph on
4743 p
4744 \emph default
4745 rogrammable 
4746 \emph on
4747 g
4748 \emph default
4749 ate 
4750 \emph on
4751 a
4752 \emph default
4753 rray
4754 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4755
4756 \end_inset
4757
4758
4759 \begin_inset Quotes srd
4760 \end_inset
4761
4762  or 
4763 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4764
4765 \end_inset
4766
4767
4768 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4769
4770 \end_inset
4771
4772  
4773 \begin_inset Quotes sld
4774 \end_inset
4775
4776 have you ever heard of an open source compiler that compiles a subset of
4777  C for an FPGA?
4778 \begin_inset Quotes srd
4779 \end_inset
4780
4781  we expect you to have a quick look there and come back.
4782  If you read this you are on the right track.
4783 \end_layout
4784
4785 \begin_layout Itemize
4786 Some sections attribute more space to problems, restrictions and warnings
4787  than to the solution.
4788 \end_layout
4789
4790 \begin_layout Itemize
4791 The installation section and the section about the debugger is intimidating.
4792 \end_layout
4793
4794 \begin_layout Itemize
4795 There are still lots of typos and there are more different writing styles
4796  than pictures.
4797 \end_layout
4798
4799 \begin_layout Section
4800 Testing the SDCC Compiler
4801 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4802
4803 \end_inset
4804
4805
4806 \end_layout
4807
4808 \begin_layout Standard
4809 The first thing you should do after installing your SDCC compiler is to
4810  see if it runs.
4811  Type 
4812 \family sans
4813 \series bold
4814 "sdcc -
4815 \begin_inset ERT
4816 status collapsed
4817
4818 \begin_layout Standard
4819
4820
4821 \backslash
4822 /
4823 \end_layout
4824
4825 \end_inset
4826
4827 -version"
4828 \begin_inset LatexCommand \index{version}
4829
4830 \end_inset
4831
4832
4833 \family default
4834 \series default
4835  at the prompt, and the program should run and output its version like:
4836  
4837 \newline
4838
4839 \family typewriter
4840 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4841  (UNIX)
4842 \end_layout
4843
4844 \begin_layout Standard
4845 If it doesn't run, or gives a message about not finding sdcc program, then
4846  you need to check over your installation.
4847  Make sure that the sdcc bin directory is in your executable search path
4848  defined by the PATH environment setting (
4849 \series medium
4850 see 
4851 \series default
4852 section 
4853 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4854
4855 \end_inset
4856
4857 \InsetSpace ~
4858
4859 \series medium
4860 Install trouble-shooting for suggestions
4861 \series default
4862 ).
4863  Make sure that the sdcc program is in the bin folder, if not perhaps something
4864  did not install correctly.
4865 \newline
4866
4867 \newline
4868
4869 \series medium
4870 SDCC 
4871 \series default
4872 is commonly installed as described in section 
4873 \begin_inset Quotes sld
4874 \end_inset
4875
4876 Install and search paths
4877 \begin_inset Quotes srd
4878 \end_inset
4879
4880 .
4881 \newline
4882
4883 \newline
4884
4885 \series medium
4886 Make sure the compiler works on a very simple example.
4887  Type in the following test.c program using your favorite 
4888 \series default
4889 ASCII 
4890 \series medium
4891 editor:
4892 \end_layout
4893
4894 \begin_layout Verse
4895
4896 \family typewriter
4897 char test;
4898 \newline
4899
4900 \newline
4901 void main(void) {
4902 \newline
4903 \InsetSpace ~
4904 \InsetSpace ~
4905 \InsetSpace ~
4906 \InsetSpace ~
4907 test=0;
4908 \newline
4909 }
4910 \end_layout
4911
4912 \begin_layout Standard
4913
4914 \series medium
4915 Compile this using the following command: 
4916 \family sans
4917 \series bold
4918 "sdcc -c test.c".
4919
4920 \family default
4921 \series default
4922  
4923 \series medium
4924 If all goes well, the compiler will generate a test.asm and test.rel file.
4925  Congratulations, you've just compiled your first program with SDCC.
4926  We used the -c option to tell SDCC not to link the generated code, just
4927  to keep things simple for this step.
4928 \series default
4929
4930 \newline
4931
4932 \newline
4933
4934 \series medium
4935 The next step is to try it with the linker.
4936  Type in 
4937 \family sans
4938 \series bold
4939 "sdcc test.c
4940 \family default
4941 \series default
4942 "
4943 \series medium
4944 .
4945  If all goes well the compiler will link with the libraries and produce
4946  a test.ihx output file.
4947  If this step fails
4948 \series default
4949  
4950 \series medium
4951 (no test.ihx, and the linker generates warnings), then the problem is most
4952  likely that 
4953 \series default
4954 SDCC
4955 \series medium
4956  cannot find the 
4957 \series default
4958 /
4959 \series medium
4960 usr/local/share/sdcc/lib directory
4961 \series default
4962  
4963 \series medium
4964 (see 
4965 \series default
4966 section 
4967 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4968
4969 \end_inset
4970
4971 \InsetSpace ~
4972
4973 \series medium
4974 Install trouble-shooting for suggestions).
4975 \series default
4976
4977 \newline
4978
4979 \newline
4980
4981 \series medium
4982 The final test is to ensure 
4983 \series default
4984 SDCC
4985 \series medium
4986  can use the 
4987 \series default
4988 standard
4989 \series medium
4990  header files and libraries.
4991  Edit test.c and change it to the following:
4992 \end_layout
4993
4994 \begin_layout Verse
4995
4996 \family typewriter
4997 #include <string.h>
4998 \newline
4999
5000 \newline
5001 char str1[10];
5002 \newline
5003
5004 \newline
5005 void main(void) {
5006 \newline
5007 \InsetSpace ~
5008 \InsetSpace ~
5009 strcpy(str1, "testing");
5010 \newline
5011 }
5012 \end_layout
5013
5014 \begin_layout Standard
5015
5016 \series medium
5017 Compile this by typing 
5018 \family sans
5019 \series bold
5020 "sdcc test.c"
5021 \family default
5022 \series medium
5023 .
5024  This should generate a test.ihx output file, and it should give no warnings
5025  such as not finding the string.h file.
5026  If it cannot find the string.h file, then the problem is that 
5027 \series default
5028 SDCC
5029 \series medium
5030  cannot find the /usr/local/share/sdcc/include directory
5031 \series default
5032  
5033 \series medium
5034 (see the 
5035 \series default
5036 section 
5037 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5038
5039 \end_inset
5040
5041 \InsetSpace ~
5042
5043 \series medium
5044 Install trouble-shooting section for suggestions).
5045
5046 \series default
5047  Use option 
5048 \series bold
5049 -
5050 \begin_inset ERT
5051 status collapsed
5052
5053 \begin_layout Standard
5054
5055
5056 \backslash
5057 /
5058 \end_layout
5059
5060 \end_inset
5061
5062 -print-search-dirs
5063 \series default
5064
5065 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5066
5067 \end_inset
5068
5069  to find exactly where SDCC is looking for the include and lib files.
5070 \end_layout
5071
5072 \begin_layout Section
5073 Install Trouble-shooting
5074 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5075
5076 \end_inset
5077
5078
5079 \begin_inset LatexCommand \index{Install trouble-shooting}
5080
5081 \end_inset
5082
5083
5084 \end_layout
5085
5086 \begin_layout Subsection
5087 If SDCC does not build correctly
5088 \end_layout
5089
5090 \begin_layout Standard
5091 A thing to try is starting from scratch by unpacking the .tgz source package
5092  again in an empty directory.
5093  Configure it like:
5094 \newline
5095
5096 \newline
5097
5098 \family sans
5099 \series bold
5100 ./configure 2>&1 | tee configure.log
5101 \family default
5102 \series default
5103
5104 \newline
5105
5106 \newline
5107 and build it like:
5108 \newline
5109
5110 \newline
5111
5112 \family sans
5113 \series bold
5114 make 2>&1 | tee make.log
5115 \family default
5116 \series default
5117
5118 \newline
5119
5120 \newline
5121 If anything goes wrong, you can review the log files to locate the problem.
5122  Or a relevant part of this can be attached to an email that could be helpful
5123  when requesting help from the mailing list.
5124 \end_layout
5125
5126 \begin_layout Subsection
5127 What the 
5128 \begin_inset Quotes sld
5129 \end_inset
5130
5131 ./configure
5132 \begin_inset Quotes srd
5133 \end_inset
5134
5135  does
5136 \end_layout
5137
5138 \begin_layout Standard
5139 The 
5140 \begin_inset Quotes sld
5141 \end_inset
5142
5143 ./configure
5144 \begin_inset Quotes srd
5145 \end_inset
5146
5147  command is a script that analyzes your system and performs some configuration
5148  to ensure the source package compiles on your system.
5149  It will take a few minutes to run, and will compile a few tests to determine
5150  what compiler features are installed.
5151 \end_layout
5152
5153 \begin_layout Subsection
5154 What the 
5155 \begin_inset Quotes sld
5156 \end_inset
5157
5158 make
5159 \begin_inset Quotes srd
5160 \end_inset
5161
5162  does
5163 \end_layout
5164
5165 \begin_layout Standard
5166 This runs the GNU make tool, which automatically compiles all the source
5167  packages into the final installed binary executables.
5168 \end_layout
5169
5170 \begin_layout Subsection
5171 What the 
5172 \begin_inset Quotes sld
5173 \end_inset
5174
5175 make install
5176 \begin_inset Quotes erd
5177 \end_inset
5178
5179  command does.
5180 \end_layout
5181
5182 \begin_layout Standard
5183 This will install the compiler, other executables libraries and include
5184  files into the appropriate directories.
5185  See sections 
5186 \begin_inset LatexCommand \ref{sub:Install-paths}
5187
5188 \end_inset
5189
5190 ,\InsetSpace ~
5191
5192 \begin_inset LatexCommand \ref{sub:Search-Paths}
5193
5194 \end_inset
5195
5196 \InsetSpace ~
5197 about install and search paths.
5198 \newline
5199 On most systems you will need super-user privilege
5200 s to do this.
5201 \end_layout
5202
5203 \begin_layout Section
5204 Components of SDCC
5205 \end_layout
5206
5207 \begin_layout Standard
5208 SDCC is not just a compiler, but a collection of tools by various developers.
5209  These include linkers, assemblers, simulators and other components.
5210  Here is a summary of some of the components.
5211  Note that the included simulator and assembler have separate documentation
5212  which you can find in the source package in their respective directories.
5213  As SDCC grows to include support for other processors, other packages from
5214  various developers are included and may have their own sets of documentation.
5215 \newline
5216
5217 \newline
5218 You
5219  might want to look at the files which are installed in <installdir>.
5220  At the time of this writing, we find the following programs for gcc-builds:
5221 \newline
5222
5223  
5224 \newline
5225 In <installdir>/bin:
5226 \end_layout
5227
5228 \begin_layout Itemize
5229 sdcc - The compiler.
5230 \end_layout
5231
5232 \begin_layout Itemize
5233 sdcpp - The C preprocessor.
5234 \end_layout
5235
5236 \begin_layout Itemize
5237 asx8051 - The assembler for 8051 type processors.
5238 \end_layout
5239
5240 \begin_layout Itemize
5241 as-z80
5242 \series bold
5243
5244 \series default
5245 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5246 \end_layout
5247
5248 \begin_layout Itemize
5249 aslink -The linker for 8051 type processors.
5250 \end_layout
5251
5252 \begin_layout Itemize
5253 link-z80
5254 \series bold
5255
5256 \series default
5257 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5258 \end_layout
5259
5260 \begin_layout Itemize
5261 s51 - The ucSim 8051 simulator.
5262 \end_layout
5263
5264 \begin_layout Itemize
5265 sdcdb - The source debugger.
5266 \end_layout
5267
5268 \begin_layout Itemize
5269 packihx - A tool to pack (compress) Intel hex files.
5270 \end_layout
5271
5272 \begin_layout Standard
5273 In <installdir>/share/sdcc/include
5274 \end_layout
5275
5276 \begin_layout Itemize
5277 the include files
5278 \end_layout
5279
5280 \begin_layout Standard
5281 In <installdir>/share/sdcc/lib
5282 \end_layout
5283
5284 \begin_layout Itemize
5285 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5286  relocatables.
5287 \end_layout
5288
5289 \begin_layout Standard
5290 In <installdir>/share/sdcc/doc
5291 \end_layout
5292
5293 \begin_layout Itemize
5294 the documentation
5295 \end_layout
5296
5297 \begin_layout Standard
5298 As development for other processors proceeds, this list will expand to include
5299  executables to support processors like AVR, PIC, etc.
5300 \end_layout
5301
5302 \begin_layout Subsection
5303 sdcc - The Compiler
5304 \end_layout
5305
5306 \begin_layout Standard
5307 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5308  the assembler and linkage editor.
5309 \end_layout
5310
5311 \begin_layout Subsection
5312 sdcpp - The C-Preprocessor
5313 \end_layout
5314
5315 \begin_layout Standard
5316 The preprocessor
5317 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5318
5319 \end_inset
5320
5321  is a modified version of the GNU cpp
5322 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5323
5324 \end_inset
5325
5326  preprocessor 
5327 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5328
5329 \end_inset
5330
5331 .
5332  The C preprocessor is used to pull in #include sources, process #ifdef
5333  statements, #defines and so on.
5334 \end_layout
5335
5336 \begin_layout Subsection
5337 as
5338 \emph on
5339 xxxx
5340 \emph default
5341 , aslink, link-
5342 \emph on
5343 xxx
5344 \emph default
5345  - The Assemblers and Linkage Editors
5346 \end_layout
5347
5348 \begin_layout Standard
5349 This is retargettable assembler & linkage editor, it was developed by Alan
5350  Baldwin.
5351  John Hartman created the version for 8051, and I (Sandeep) have made some
5352  enhancements and bug fixes for it to work properly with SDCC.
5353 \end_layout
5354
5355 \begin_layout Subsection
5356 s51 - The Simulator
5357 \end_layout
5358
5359 \begin_layout Standard
5360 S51
5361 \begin_inset LatexCommand \index{s51}
5362
5363 \end_inset
5364
5365  is a freeware, opensource simulator developed by Daniel Drotos.
5366  The simulator is built as part of the build process.
5367  For more information visit Daniel's web site at: 
5368 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5369
5370 \end_inset
5371
5372 .
5373  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5374  XA51 family.
5375 \end_layout
5376
5377 \begin_layout Subsection
5378 sdcdb - Source Level Debugger
5379 \end_layout
5380
5381 \begin_layout Standard
5382 SDCDB
5383 \begin_inset LatexCommand \index{SDCDB (debugger)}
5384
5385 \end_inset
5386
5387  is the companion source level debugger.
5388  More about SDCDB in section 
5389 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5390
5391 \end_inset
5392
5393 .
5394  The current version of the debugger uses Daniel's Simulator S51
5395 \begin_inset LatexCommand \index{s51}
5396
5397 \end_inset
5398
5399 , but can be easily changed to use other simulators.
5400 \end_layout
5401
5402 \begin_layout Chapter
5403 Using SDCC
5404 \end_layout
5405
5406 \begin_layout Section
5407 Compiling
5408 \end_layout
5409
5410 \begin_layout Subsection
5411 Single Source File Projects
5412 \end_layout
5413
5414 \begin_layout Standard
5415 For single source file 8051 projects the process is very simple.
5416  Compile your programs with the following command 
5417 \family sans
5418 \series bold
5419 "sdcc sourcefile.c".
5420
5421 \family default
5422 \series default
5423  This will compile, assemble and link your source file.
5424  Output files are as follows:
5425 \end_layout
5426
5427 \begin_layout Itemize
5428 sourcefile.asm
5429 \begin_inset LatexCommand \index{<file>.asm}
5430
5431 \end_inset
5432
5433  - Assembler source
5434 \begin_inset LatexCommand \index{Assembler source}
5435
5436 \end_inset
5437
5438  file created by the compiler
5439 \end_layout
5440
5441 \begin_layout Itemize
5442 sourcefile.lst
5443 \begin_inset LatexCommand \index{<file>.lst}
5444
5445 \end_inset
5446
5447  - Assembler listing
5448 \begin_inset LatexCommand \index{Assembler listing}
5449
5450 \end_inset
5451
5452  file created by the Assembler
5453 \end_layout
5454
5455 \begin_layout Itemize
5456 sourcefile.rst
5457 \begin_inset LatexCommand \index{<file>.rst}
5458
5459 \end_inset
5460
5461  - Assembler listing
5462 \begin_inset LatexCommand \index{Assembler listing}
5463
5464 \end_inset
5465
5466  file updated with linkedit information, created by linkage editor
5467 \end_layout
5468
5469 \begin_layout Itemize
5470 sourcefile.sym
5471 \begin_inset LatexCommand \index{<file>.sym}
5472
5473 \end_inset
5474
5475  - symbol listing
5476 \begin_inset LatexCommand \index{Symbol listing}
5477
5478 \end_inset
5479
5480  for the sourcefile, created by the assembler
5481 \end_layout
5482
5483 \begin_layout Itemize
5484 sourcefile.rel
5485 \begin_inset LatexCommand \index{<file>.rel}
5486
5487 \end_inset
5488
5489  or sourcefile.o
5490 \begin_inset LatexCommand \index{<file>.o}
5491
5492 \end_inset
5493
5494  - Object file
5495 \begin_inset LatexCommand \index{Object file}
5496
5497 \end_inset
5498
5499  created by the assembler, input to Linkage editor
5500 \end_layout
5501
5502 \begin_layout Itemize
5503 sourcefile.map
5504 \begin_inset LatexCommand \index{<file>.map}
5505
5506 \end_inset
5507
5508  - The memory map
5509 \begin_inset LatexCommand \index{Memory map}
5510
5511 \end_inset
5512
5513  for the load module, created by the Linker
5514 \end_layout
5515
5516 \begin_layout Itemize
5517 sourcefile.mem
5518 \begin_inset LatexCommand \index{<file>.mem}
5519
5520 \end_inset
5521
5522  - A file with a summary of the memory usage
5523 \end_layout
5524
5525 \begin_layout Itemize
5526 sourcefile.ihx
5527 \begin_inset LatexCommand \index{<file>.ihx}
5528
5529 \end_inset
5530
5531  - The load module in Intel hex format
5532 \begin_inset LatexCommand \index{Intel hex format}
5533
5534 \end_inset
5535
5536  (you can select the Motorola S19 format
5537 \begin_inset LatexCommand \index{Motorola S19 format}
5538
5539 \end_inset
5540
5541  with -
5542 \begin_inset ERT
5543 status collapsed
5544
5545 \begin_layout Standard
5546
5547
5548 \backslash
5549 /
5550 \end_layout
5551
5552 \end_inset
5553
5554 -out-fmt-s19
5555 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5556
5557 \end_inset
5558
5559 .
5560  If you need another format you might want to use 
5561 \family sans
5562 \shape italic
5563 objdump
5564 \family default
5565 \shape default
5566
5567 \begin_inset LatexCommand \index{objdump (tool)}
5568
5569 \end_inset
5570
5571  or
5572 \family sans
5573 \shape italic
5574  srecord
5575 \family default
5576 \shape default
5577
5578 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5579
5580 \end_inset
5581
5582 ).
5583  Both formats are documented in the documentation of srecord
5584 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5585
5586 \end_inset
5587
5588
5589 \end_layout
5590
5591 \begin_layout Itemize
5592 sourcefile.adb
5593 \begin_inset LatexCommand \index{<file>.adb}
5594
5595 \end_inset
5596
5597  - An intermediate file containing debug information needed to create the
5598  .cdb file (with -
5599 \begin_inset ERT
5600 status collapsed
5601
5602 \begin_layout Standard
5603
5604
5605 \backslash
5606 /
5607 \end_layout
5608
5609 \end_inset
5610
5611 -debug
5612 \begin_inset LatexCommand \index{-\/-debug}
5613
5614 \end_inset
5615
5616
5617 \end_layout
5618
5619 \begin_layout Itemize
5620 sourcefile.cdb
5621 \begin_inset LatexCommand \index{<file>.cdb}
5622
5623 \end_inset
5624
5625  - An optional file (with -
5626 \begin_inset ERT
5627 status collapsed
5628
5629 \begin_layout Standard
5630
5631
5632 \backslash
5633 /
5634 \end_layout
5635
5636 \end_inset
5637
5638 -debug) containing debug information.
5639  The format is documented in cdbfileformat.pdf
5640 \end_layout
5641
5642 \begin_layout Itemize
5643 sourcefile.
5644  - (no extension)
5645 \begin_inset LatexCommand \index{<file> (no extension)}
5646
5647 \end_inset
5648
5649  An optional AOMF or AOMF51
5650 \begin_inset LatexCommand \index{AOMF, AOMF51}
5651
5652 \end_inset
5653
5654  
5655 \begin_inset LatexCommand \label{OMF file}
5656
5657 \end_inset
5658
5659 file containing debug information (generated with option -
5660 \begin_inset ERT
5661 status collapsed
5662
5663 \begin_layout Standard
5664
5665
5666 \backslash
5667 /
5668 \end_layout
5669
5670 \end_inset
5671
5672 -debug).
5673  The (Intel)
5674 \emph on
5675  a
5676 \emph default
5677 bsolute 
5678 \emph on
5679 o
5680 \emph default
5681 bject 
5682 \emph on
5683 m
5684 \emph default
5685 odule 
5686 \emph on
5687 f
5688 \emph default
5689 ormat is commonly used by third party tools (debuggers
5690 \begin_inset LatexCommand \index{Debugger}
5691
5692 \end_inset
5693
5694 , simulators, emulators)
5695 \end_layout
5696
5697 \begin_layout Itemize
5698 sourcefile.dump*
5699 \begin_inset LatexCommand \index{<file>.dump*}
5700
5701 \end_inset
5702
5703  - Dump file to debug the compiler it self (generated with option -
5704 \begin_inset ERT
5705 status collapsed
5706
5707 \begin_layout Standard
5708
5709
5710 \backslash
5711 /
5712 \end_layout
5713
5714 \end_inset
5715
5716 -dumpall) (see section 
5717 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5718
5719 \end_inset
5720
5721 \InsetSpace ~
5722  and section 
5723 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5724
5725 \end_inset
5726
5727 \InsetSpace ~
5728
5729 \begin_inset Quotes sld
5730 \end_inset
5731
5732 Anatomy of the compiler
5733 \begin_inset Quotes srd
5734 \end_inset
5735
5736 ).
5737 \end_layout
5738
5739 \begin_layout Subsection
5740 Postprocessing the Intel Hex
5741 \begin_inset LatexCommand \index{Intel hex format}
5742
5743 \end_inset
5744
5745  file
5746 \end_layout
5747
5748 \begin_layout Standard
5749 In most cases this won't be needed but the Intel Hex file
5750 \begin_inset LatexCommand \index{<file>.ihx}
5751
5752 \end_inset
5753
5754  which is generated by SDCC might include lines of varying length and the
5755  addresses within the file are not guaranteed to be strictly ascending.
5756  If your toolchain or a bootloader does not like this you can use the tool
5757  
5758 \family typewriter
5759 packihx
5760 \family default
5761
5762 \begin_inset LatexCommand \index{packihx (tool)}
5763
5764 \end_inset
5765
5766  which is part of the SDCC distribution: 
5767 \newline
5768
5769 \newline
5770
5771 \family sans
5772 \series bold
5773  packihx sourcefile.ihx >sourcefile.hex
5774 \family default
5775 \series default
5776
5777 \newline
5778
5779 \newline
5780 The separately available
5781 \emph on
5782  srecord
5783 \emph default
5784
5785 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5786
5787 \end_inset
5788
5789  package additionally allows to set undefined locations to a predefined
5790  value, to insert checksums
5791 \begin_inset LatexCommand \index{checksum}
5792
5793 \end_inset
5794
5795  of various flavours (crc, add, xor) and to perform other manipulations
5796  (convert, split, crop, offset, ...).
5797  
5798 \newline
5799
5800 \newline
5801
5802 \family sans
5803 \series bold
5804 srec_cat\InsetSpace ~
5805 \InsetSpace ~
5806 sourcefile.ihx -intel\InsetSpace ~
5807 \InsetSpace ~
5808 -o sourcefile.hex -intel
5809 \newline
5810
5811 \newline
5812
5813 \family default
5814 \series default
5815 An example for a more complex command line
5816 \begin_inset Foot
5817 status open
5818
5819 \begin_layout Standard
5820 the command backfills
5821 \begin_inset LatexCommand \index{backfill unused memory}
5822
5823 \end_inset
5824
5825  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5826  block is zero.
5827  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5828  will be interpreted as an 
5829 \family typewriter
5830 lcall
5831 \family default
5832  to address 
5833 \family typewriter
5834 0x1212
5835 \family default
5836  (where an emergency routine could sit).
5837 \end_layout
5838
5839 \end_inset
5840
5841  could look like:
5842 \newline
5843
5844 \newline
5845
5846 \family sans
5847 \series bold
5848 \size footnotesize
5849 srec_cat\InsetSpace ~
5850 sourcefile.ihx -intel\InsetSpace ~
5851 \InsetSpace ~
5852 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5853 -little-endian-checksum-nega
5854 tive 0xfffe 0x02 0x02\InsetSpace ~
5855 \InsetSpace ~
5856 -o sourcefile.hex -intel
5857 \size default
5858
5859 \newline
5860
5861 \newline
5862
5863 \family default
5864 \series default
5865 The srecord package is available at 
5866 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5867
5868 \end_inset
5869
5870  .
5871 \end_layout
5872
5873 \begin_layout Subsection
5874 Projects with Multiple Source Files
5875 \end_layout
5876
5877 \begin_layout Standard
5878 SDCC can compile only ONE file at a time.
5879  Let us for example assume that you have a project containing the following
5880  files:
5881 \newline
5882
5883 \newline
5884 foo1.c (contains some functions)
5885 \newline
5886 foo2.c (contains some more functions)
5887 \newline
5888 foomai
5889 n.c (contains more functions and the function main)
5890 \newline
5891
5892 \size footnotesize
5893
5894 \newline
5895
5896 \size default
5897 The first two files will need to be compiled separately with the commands:
5898 \size footnotesize
5899  
5900 \size default
5901
5902 \newline
5903
5904 \newline
5905
5906 \family sans
5907 \series bold
5908 sdcc\InsetSpace ~
5909 -c\InsetSpace ~
5910 foo1.c
5911 \family default
5912 \series default
5913 \size footnotesize
5914
5915 \newline
5916
5917 \family sans
5918 \series bold
5919 \size default
5920 sdcc\InsetSpace ~
5921 -c\InsetSpace ~
5922 foo2.c
5923 \family default
5924 \series default
5925
5926 \newline
5927
5928 \newline
5929 Then compile the source file containing the 
5930 \emph on
5931 main()
5932 \emph default
5933  function and link
5934 \begin_inset LatexCommand \index{Linker}
5935
5936 \end_inset
5937
5938  the files together with the following command: 
5939 \newline
5940
5941 \newline
5942
5943 \family sans
5944 \series bold
5945 sdcc\InsetSpace ~
5946 foomain.c\InsetSpace ~
5947 foo1.rel\InsetSpace ~
5948 foo2.rel
5949 \family default
5950 \series default
5951
5952 \begin_inset LatexCommand \index{<file>.rel}
5953
5954 \end_inset
5955
5956
5957 \newline
5958
5959 \newline
5960 Alternatively, 
5961 \emph on
5962 foomain.c 
5963 \emph default
5964 can be separately compiled as well: 
5965 \family sans
5966 \series bold
5967
5968 \newline
5969
5970 \newline
5971 sdcc\InsetSpace ~
5972 -c\InsetSpace ~
5973 foomain.c
5974 \newline
5975 sdcc foomain.rel foo1.rel foo2.rel
5976 \newline
5977
5978 \newline
5979
5980 \family default
5981 \series default
5982 The file containing the 
5983 \emph on
5984 main()
5985 \emph default
5986  function
5987 \emph on
5988  
5989 \emph default
5990 \noun on
5991 must
5992 \noun default
5993  be the 
5994 \noun on
5995 first
5996 \noun default
5997  file specified in the command line, since the linkage editor processes
5998  file in the order they are presented to it.
5999  The linker is invoked from SDCC using a script file with extension .lnk
6000 \begin_inset LatexCommand \index{<file>.lnk}
6001
6002 \end_inset
6003
6004 .
6005  You can view this file to troubleshoot linking problems such as those arising
6006  from missing libraries.
6007 \end_layout
6008
6009 \begin_layout Subsection
6010 Projects with Additional Libraries
6011 \begin_inset LatexCommand \index{Libraries}
6012
6013 \end_inset
6014
6015
6016 \end_layout
6017
6018 \begin_layout Standard
6019 Some reusable routines may be compiled into a library, see the documentation
6020  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6021  for how to create a 
6022 \emph on
6023 .lib
6024 \begin_inset LatexCommand \index{<file>.lib}
6025
6026 \end_inset
6027
6028
6029 \emph default
6030  library file.
6031  Libraries created in this manner can be included in the command line.
6032  Make sure you include the -L <library-path> option to tell the linker where
6033  to look for these files if they are not in the current directory.
6034  Here is an example, assuming you have the source file 
6035 \emph on
6036 foomain.c
6037 \emph default
6038  and a library
6039 \emph on
6040  foolib.lib
6041 \emph default
6042  in the directory 
6043 \emph on
6044 mylib
6045 \emph default
6046  (if that is not the same as your current project):
6047 \newline
6048
6049 \newline
6050
6051 \family sans
6052 \series bold
6053 sdcc foomain.c foolib.lib -L mylib
6054 \newline
6055
6056 \newline
6057
6058 \family default
6059 \series default
6060 Note here that
6061 \emph on
6062  mylib
6063 \emph default
6064  must be an absolute path name.
6065 \newline
6066
6067 \newline
6068 The most efficient way to use libraries is
6069  to keep separate modules in separate source files.
6070  The lib file now should name all the modules.rel
6071 \begin_inset LatexCommand \index{<file>.rel}
6072
6073 \end_inset
6074
6075  files.
6076  For an example see the standard library file 
6077 \emph on
6078 libsdcc.lib
6079 \emph default
6080  in the directory <installdir>/share/lib/small.
6081 \end_layout
6082
6083 \begin_layout Subsection
6084 Using sdcclib to Create and Manage Libraries
6085 \begin_inset LatexCommand \index{sdcclib}
6086
6087 \end_inset
6088
6089
6090 \end_layout
6091
6092 \begin_layout Standard
6093 Alternatively, instead of having a .rel file for each entry on the library
6094  file as described in the preceding section, sdcclib can be used to embed
6095  all the modules belonging to such library in the library file itself.
6096  This results in a larger library file, but it greatly reduces the number
6097  of disk files accessed by the linker.
6098   Additionally, the packed library file contains an index of all include
6099  modules and symbols that significantly speeds up the linking process.
6100  To display a list of options supported by sdcclib type:
6101 \newline
6102
6103 \end_layout
6104
6105 \begin_layout Standard
6106
6107 \family sans
6108 \series bold
6109 sdcclib -?
6110 \begin_inset LatexCommand \index{sdcclib}
6111
6112 \end_inset
6113
6114
6115 \newline
6116
6117 \newline
6118
6119 \family default
6120 \series default
6121 To create a new library file, start by compiling all the required modules.
6122  For example:
6123 \newline
6124
6125 \end_layout
6126
6127 \begin_layout Standard
6128
6129 \family sans
6130 \series bold
6131 sdcc -c _divsint.c
6132 \end_layout
6133
6134 \begin_layout Standard
6135
6136 \family sans
6137 \series bold
6138 sdcc -c _divuint.c
6139 \end_layout
6140
6141 \begin_layout Standard
6142
6143 \family sans
6144 \series bold
6145 sdcc -c _modsint.c
6146 \end_layout
6147
6148 \begin_layout Standard
6149
6150 \family sans
6151 \series bold
6152 sdcc -c _moduint.c
6153 \end_layout
6154
6155 \begin_layout Standard
6156
6157 \family sans
6158 \series bold
6159 sdcc -c _mulint.c
6160 \newline
6161
6162 \end_layout
6163
6164 \begin_layout Standard
6165 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6166  and _mulint.rel.
6167  The next step is to add the .rel files to the library file:
6168 \newline
6169
6170 \end_layout
6171
6172 \begin_layout Standard
6173
6174 \family sans
6175 \series bold
6176 sdcclib libint.lib _divsint.rel
6177 \family default
6178
6179 \begin_inset LatexCommand \index{sdcclib}
6180
6181 \end_inset
6182
6183
6184 \end_layout
6185
6186 \begin_layout Standard
6187
6188 \family sans
6189 \series bold
6190 sdcclib libint.lib _divuint.rel
6191 \end_layout
6192
6193 \begin_layout Standard
6194
6195 \family sans
6196 \series bold
6197 sdcclib libint.lib _modsint.rel
6198 \end_layout
6199
6200 \begin_layout Standard
6201
6202 \family sans
6203 \series bold
6204 sdcclib libint.lib _moduint.rel
6205 \end_layout
6206
6207 \begin_layout Standard
6208
6209 \family sans
6210 \series bold
6211 sdcclib libint.lib _mulint.rel
6212 \series default
6213
6214 \newline
6215
6216 \end_layout
6217
6218 \begin_layout Standard
6219 If the file already exists in the library, it will be replaced.
6220  To see what modules and symbols are included in the library, options -s
6221  and -m are available.
6222  For example:
6223 \newline
6224
6225 \newline
6226
6227 \family sans
6228 \series bold
6229 sdcclib -s libint.lib
6230 \family default
6231
6232 \begin_inset LatexCommand \index{sdcclib}
6233
6234 \end_inset
6235
6236
6237 \newline
6238
6239 \family typewriter
6240 \series default
6241 _divsint.rel:
6242 \end_layout
6243
6244 \begin_layout Standard
6245
6246 \family typewriter
6247 __divsint_a_1_1
6248 \end_layout
6249
6250 \begin_layout Standard
6251
6252 \family typewriter
6253 __divsint_PARM_2
6254 \end_layout
6255
6256 \begin_layout Standard
6257
6258 \family typewriter
6259 __divsint
6260 \newline
6261 _divuint.rel:
6262 \end_layout
6263
6264 \begin_layout Standard
6265
6266 \family typewriter
6267 __divuint_a_1_1
6268 \end_layout
6269
6270 \begin_layout Standard
6271
6272 \family typewriter
6273 __divuint_PARM_2
6274 \end_layout
6275
6276 \begin_layout Standard
6277
6278 \family typewriter
6279 __divuint_reste_1_1
6280 \end_layout
6281
6282 \begin_layout Standard
6283
6284 \family typewriter
6285 __divuint_count_1_1
6286 \end_layout
6287
6288 \begin_layout Standard
6289
6290 \family typewriter
6291 __divuint
6292 \newline
6293 _modsint.rel:
6294 \end_layout
6295
6296 \begin_layout Standard
6297
6298 \family typewriter
6299 __modsint_a_1_1
6300 \end_layout
6301
6302 \begin_layout Standard
6303
6304 \family typewriter
6305 __modsint_PARM_2
6306 \end_layout
6307
6308 \begin_layout Standard
6309
6310 \family typewriter
6311 __modsint
6312 \newline
6313 _moduint.rel:
6314 \end_layout
6315
6316 \begin_layout Standard
6317
6318 \family typewriter
6319 __moduint_a_1_1
6320 \end_layout
6321
6322 \begin_layout Standard
6323
6324 \family typewriter
6325 __moduint_PARM_2
6326 \end_layout
6327
6328 \begin_layout Standard
6329
6330 \family typewriter
6331 __moduint_count_1_1
6332 \end_layout
6333
6334 \begin_layout Standard
6335
6336 \family typewriter
6337 __moduint
6338 \newline
6339 _mulint.rel:
6340 \end_layout
6341
6342 \begin_layout Standard
6343
6344 \family typewriter
6345 __mulint_PARM_2
6346 \end_layout
6347
6348 \begin_layout Standard
6349
6350 \family typewriter
6351 __mulint
6352 \family default
6353 \series bold
6354
6355 \newline
6356
6357 \end_layout
6358
6359 \begin_layout Standard
6360 If the source files are compiled using -
6361 \begin_inset ERT
6362 status collapsed
6363
6364 \begin_layout Standard
6365
6366
6367 \backslash
6368 /
6369 \end_layout
6370
6371 \end_inset
6372
6373 -debug
6374 \begin_inset LatexCommand \index{-\/-debug}
6375
6376 \end_inset
6377
6378 , the corresponding debug information file .adb will be include in the library
6379  file as well.
6380  The library files created with sdcclib are plain text files, so they can
6381  be viewed with a text editor.
6382  It is not recomended to modify a library file created with sdcclib using
6383  a text editor, as there are file indexes numbers located accross the file
6384  used by the linker to quickly locate the required module to link.
6385  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6386  it can be safely deleted, since all the information required for linking
6387  is embedded in the library file itself.
6388  Library files created using sdcclib are used as described in the preceding
6389  sections.
6390 \begin_inset VSpace bigskip
6391 \end_inset
6392
6393
6394 \end_layout
6395
6396 \begin_layout Section
6397 Command Line Options
6398 \begin_inset LatexCommand \index{Command Line Options}
6399
6400 \end_inset
6401
6402
6403 \end_layout
6404
6405 \begin_layout Subsection
6406 Processor Selection Options
6407 \begin_inset LatexCommand \index{Options processor selection}
6408
6409 \end_inset
6410
6411
6412 \begin_inset LatexCommand \index{Processor selection options}
6413
6414 \end_inset
6415
6416
6417 \end_layout
6418
6419 \begin_layout List
6420 \labelwidthstring 00.00.0000
6421
6422 \series bold
6423 -mmcs51
6424 \begin_inset LatexCommand \index{-mmcs51}
6425
6426 \end_inset
6427
6428
6429 \series default
6430  Generate code for the Intel MCS51
6431 \begin_inset LatexCommand \index{MCS51}
6432
6433 \end_inset
6434
6435  family of processors.
6436  This is the default processor target.
6437 \end_layout
6438
6439 \begin_layout List
6440 \labelwidthstring 00.00.0000
6441
6442 \series bold
6443 -mds390
6444 \begin_inset LatexCommand \index{-mds390}
6445
6446 \end_inset
6447
6448
6449 \series default
6450  Generate code for the Dallas DS80C390
6451 \begin_inset LatexCommand \index{DS80C390}
6452
6453 \end_inset
6454
6455  processor.
6456 \end_layout
6457
6458 \begin_layout List
6459 \labelwidthstring 00.00.0000
6460
6461 \series bold
6462 -mds400
6463 \begin_inset LatexCommand \index{-mds400}
6464
6465 \end_inset
6466
6467
6468 \series default
6469  Generate code for the Dallas DS80C400
6470 \begin_inset LatexCommand \index{DS80C400}
6471
6472 \end_inset
6473
6474  processor.
6475 \end_layout
6476
6477 \begin_layout List
6478 \labelwidthstring 00.00.0000
6479
6480 \series bold
6481 -mhc08
6482 \begin_inset LatexCommand \index{-mhc08}
6483
6484 \end_inset
6485
6486
6487 \series default
6488  Generate code for the Freescale/Motorola HC08
6489 \begin_inset LatexCommand \index{HC08}
6490
6491 \end_inset
6492
6493  family of processors.
6494 \end_layout
6495
6496 \begin_layout List
6497 \labelwidthstring 00.00.0000
6498
6499 \series bold
6500 -mz80
6501 \begin_inset LatexCommand \index{-mz80}
6502
6503 \end_inset
6504
6505
6506 \series default
6507  Generate code for the Zilog Z80
6508 \begin_inset LatexCommand \index{Z80}
6509
6510 \end_inset
6511
6512  family of processors.
6513 \end_layout
6514
6515 \begin_layout List
6516 \labelwidthstring 00.00.0000
6517
6518 \series bold
6519 -mgbz80
6520 \begin_inset LatexCommand \index{-mgbz80}
6521
6522 \end_inset
6523
6524
6525 \series default
6526  Generate code for the GameBoy Z80
6527 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6528
6529 \end_inset
6530
6531  processor (Not actively maintained).
6532 \end_layout
6533
6534 \begin_layout List
6535 \labelwidthstring 00.00.0000
6536
6537 \series bold
6538 -mavr
6539 \begin_inset LatexCommand \index{-mavr}
6540
6541 \end_inset
6542
6543
6544 \series default
6545  Generate code for the Atmel AVR
6546 \begin_inset LatexCommand \index{AVR}
6547
6548 \end_inset
6549
6550  processor (Not maintained, not complete).
6551  AVR users should probably have a look at winavr 
6552 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6553
6554 \end_inset
6555
6556  or 
6557 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6558
6559 \end_inset
6560
6561 .
6562 \end_layout
6563
6564 \begin_layout Standard
6565 \begin_inset Note Note
6566 status collapsed
6567
6568 \begin_layout Standard
6569 I think it is fair to direct users there for now.
6570  Open source is also about avoiding unnecessary work .
6571  But I didn't find the 'official' link.
6572 \end_layout
6573
6574 \end_inset
6575
6576
6577 \end_layout
6578
6579 \begin_layout List
6580 \labelwidthstring 00.00.0000
6581
6582 \series bold
6583 -mpic14
6584 \begin_inset LatexCommand \index{-mpic14}
6585
6586 \end_inset
6587
6588
6589 \series default
6590  Generate code for the Microchip PIC 14
6591 \begin_inset LatexCommand \index{PIC14}
6592
6593 \end_inset
6594
6595 -bit processors (p16f84 and variants.
6596  In development, not complete).
6597 \end_layout
6598
6599 \begin_layout Standard
6600 \begin_inset Note Note
6601 status collapsed
6602
6603 \begin_layout Standard
6604 p16f627 p16f628 p16f84 p16f873 p16f877?
6605 \end_layout
6606
6607 \end_inset
6608
6609
6610 \end_layout
6611
6612 \begin_layout List
6613 \labelwidthstring 00.00.0000
6614
6615 \series bold
6616 -mpic16
6617 \begin_inset LatexCommand \index{-mpic16}
6618
6619 \end_inset
6620
6621
6622 \series default
6623  Generate code for the Microchip PIC 16
6624 \begin_inset LatexCommand \index{PIC16}
6625
6626 \end_inset
6627
6628 -bit processors (p18f452 and variants.
6629  In development, not complete).
6630 \end_layout
6631
6632 \begin_layout List
6633 \labelwidthstring 00.00.0000
6634
6635 \series bold
6636 -mtlcs900h
6637 \series default
6638  Generate code for the Toshiba TLCS-900H
6639 \begin_inset LatexCommand \index{TLCS-900H}
6640
6641 \end_inset
6642
6643  processor (Not maintained, not complete).
6644 \end_layout
6645
6646 \begin_layout List
6647 \labelwidthstring 00.00.0000
6648
6649 \series bold
6650 -mxa51
6651 \begin_inset LatexCommand \index{-mxa51}
6652
6653 \end_inset
6654
6655
6656 \series default
6657  Generate code for the Phillips XA51
6658 \begin_inset LatexCommand \index{XA51}
6659
6660 \end_inset
6661
6662  processor (Not maintained, not complete).
6663 \end_layout
6664
6665 \begin_layout Standard
6666 \begin_inset VSpace bigskip
6667 \end_inset
6668
6669
6670 \end_layout
6671
6672 \begin_layout Subsection
6673 Preprocessor Options
6674 \begin_inset LatexCommand \index{Options preprocessor}
6675
6676 \end_inset
6677
6678
6679 \begin_inset LatexCommand \index{Preprocessor options}
6680
6681 \end_inset
6682
6683
6684 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6685
6686 \end_inset
6687
6688
6689 \end_layout
6690
6691 \begin_layout List
6692 \labelwidthstring 00.00.0000
6693
6694 \series bold
6695 -I<path>
6696 \begin_inset LatexCommand \index{-I<path>}
6697
6698 \end_inset
6699
6700
6701 \series default
6702  The additional location where the pre processor will look for <..h> or 
6703 \begin_inset Quotes eld
6704 \end_inset
6705
6706 ..h
6707 \begin_inset Quotes erd
6708 \end_inset
6709
6710  files.
6711 \end_layout
6712
6713 \begin_layout List
6714 \labelwidthstring 00.00.0000
6715
6716 \series bold
6717 -D<macro[=value]>
6718 \begin_inset LatexCommand \index{-D<macro[=value]>}
6719
6720 \end_inset
6721
6722
6723 \series default
6724  Command line definition of macros.
6725  Passed to the preprocessor.
6726 \end_layout
6727
6728 \begin_layout List
6729 \labelwidthstring 00.00.0000
6730
6731 \series bold
6732 -M
6733 \begin_inset LatexCommand \index{-M}
6734
6735 \end_inset
6736
6737
6738 \series default
6739  Tell the preprocessor to output a rule suitable for make describing the
6740  dependencies of each object file.
6741  For each source file, the preprocessor outputs one make-rule whose target
6742  is the object file name for that source file and whose dependencies are
6743  all the files `#include'd in it.
6744  This rule may be a single line or may be continued with `
6745 \backslash
6746 '-newline if it is long.
6747  The list of rules is printed on standard output instead of the preprocessed
6748  C program.
6749  `-M' implies `-E
6750 \begin_inset LatexCommand \index{-E}
6751
6752 \end_inset
6753
6754 '.
6755 \end_layout
6756
6757 \begin_layout List
6758 \labelwidthstring 00.00.0000
6759
6760 \series bold
6761 -C
6762 \begin_inset LatexCommand \index{-C}
6763
6764 \end_inset
6765
6766
6767 \series default
6768  Tell the preprocessor not to discard comments.
6769  Used with the `-E' option.
6770 \end_layout
6771
6772 \begin_layout List
6773 \labelwidthstring 00.00.0000
6774
6775 \series bold
6776 -MM
6777 \begin_inset LatexCommand \index{-MM}
6778
6779 \end_inset
6780
6781
6782 \size large
6783 \bar under
6784  
6785 \series default
6786 \size default
6787 \bar default
6788 Like `-M' but the output mentions only the user header files included with
6789  `#include 
6790 \begin_inset Quotes eld
6791 \end_inset
6792
6793 file"'.
6794  System header files included with `#include <file>' are omitted.
6795 \end_layout
6796
6797 \begin_layout List
6798 \labelwidthstring 00.00.0000
6799
6800 \series bold
6801 -Aquestion(answer)
6802 \begin_inset LatexCommand \index{-Aquestion(answer)}
6803
6804 \end_inset
6805
6806
6807 \series default
6808  Assert the answer answer for question, in case it is tested with a preprocessor
6809  conditional such as `#if #question(answer)'.
6810  `-A-' disables the standard assertions that normally describe the target
6811  machine.
6812 \end_layout
6813
6814 \begin_layout List
6815 \labelwidthstring 00.00.0000
6816
6817 \series bold
6818 -Umacro
6819 \begin_inset LatexCommand \index{-Umacro}
6820
6821 \end_inset
6822
6823
6824 \series default
6825  Undefine macro macro.
6826  `-U' options are evaluated after all `-D' options, but before any `-include'
6827  and `-imacros' options.
6828 \end_layout
6829
6830 \begin_layout List
6831 \labelwidthstring 00.00.0000
6832
6833 \series bold
6834 -dM
6835 \begin_inset LatexCommand \index{-dM}
6836
6837 \end_inset
6838
6839
6840 \series default
6841  Tell the preprocessor to output only a list of the macro definitions that
6842  are in effect at the end of preprocessing.
6843  Used with the `-E' option.
6844 \end_layout
6845
6846 \begin_layout List
6847 \labelwidthstring 00.00.0000
6848
6849 \series bold
6850 -dD
6851 \begin_inset LatexCommand \index{-dD}
6852
6853 \end_inset
6854
6855
6856 \series default
6857  Tell the preprocessor to pass all macro definitions into the output, in
6858  their proper sequence in the rest of the output.
6859 \end_layout
6860
6861 \begin_layout List
6862 \labelwidthstring 00.00.0000
6863
6864 \series bold
6865 -dN
6866 \begin_inset LatexCommand \index{-dN}
6867
6868 \end_inset
6869
6870
6871 \size large
6872 \bar under
6873  
6874 \series default
6875 \size default
6876 \bar default
6877 Like `-dD' except that the macro arguments and contents are omitted.
6878  Only `#define name' is included in the output.
6879 \end_layout
6880
6881 \begin_layout List
6882 \labelwidthstring 00.00.0000
6883
6884 \series bold
6885 -pedantic-parse-number
6886 \begin_inset LatexCommand \index{-pedantic-parse-number}
6887
6888 \end_inset
6889
6890
6891 \size large
6892 \bar under
6893  
6894 \series default
6895 \size default
6896 \bar default
6897 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6898  and the macro LO_B(3) gets expanded.
6899  See also #pragma pedantic_parse_number in section
6900 \begin_inset LatexCommand \ref{sec:Pragmas}
6901
6902 \end_inset
6903
6904  
6905 \emph on
6906 Note: this functionality is not in conformance with standard!
6907 \end_layout
6908
6909 \begin_layout List
6910 \labelwidthstring 00.00.0000
6911
6912 \series bold
6913 -Wp\InsetSpace ~
6914 preprocessorOption[,preprocessorOption]
6915 \series default
6916
6917 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6918
6919 \end_inset
6920
6921 ...
6922  Pass the preprocessorOption to the preprocessor 
6923 \family typewriter
6924 sdcpp
6925 \family default
6926
6927 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6928
6929 \end_inset
6930
6931 .
6932  SDCC uses an adapted version of the preprocessor 
6933 \emph on
6934 cpp
6935 \emph default
6936  of the GNU Compiler Collection
6937 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6938
6939 \end_inset
6940
6941  (
6942 \emph on
6943 gcc
6944 \emph default
6945  
6946 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6947
6948 \end_inset
6949
6950 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
6951 4.1.1\InsetSpace ~
6952 CPP\InsetSpace ~
6953 Manual
6954  at 
6955 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6956
6957 \end_inset
6958
6959 .
6960 \end_layout
6961
6962 \begin_layout Standard
6963 \begin_inset VSpace bigskip
6964 \end_inset
6965
6966
6967 \end_layout
6968
6969 \begin_layout Subsection
6970 Linker Options
6971 \begin_inset LatexCommand \index{Options linker}
6972
6973 \end_inset
6974
6975
6976 \begin_inset LatexCommand \index{Linker options}
6977
6978 \end_inset
6979
6980
6981 \end_layout
6982
6983 \begin_layout List
6984 \labelwidthstring 00.00.0000
6985
6986 \series bold
6987 -L\InsetSpace ~
6988 -
6989 \series default
6990
6991 \begin_inset ERT
6992 status collapsed
6993
6994 \begin_layout Standard
6995
6996
6997 \backslash
6998 /
6999 \end_layout
7000
7001 \end_inset
7002
7003
7004 \series bold
7005 -lib-path
7006 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7007
7008 \end_inset
7009
7010
7011 \begin_inset LatexCommand \index{-L -\/-lib-path}
7012
7013 \end_inset
7014
7015
7016 \series default
7017 \InsetSpace ~
7018 <absolute path to additional libraries> This option is passed to the linkage
7019  editor's additional libraries
7020 \begin_inset LatexCommand \index{Libraries}
7021
7022 \end_inset
7023
7024  search path.
7025  The path name must be absolute.
7026  Additional library files may be specified in the command line.
7027  See section Compiling programs for more details.
7028 \end_layout
7029
7030 \begin_layout List
7031 \labelwidthstring 00.00.0000
7032
7033 \series bold
7034 -
7035 \begin_inset ERT
7036 status collapsed
7037
7038 \begin_layout Standard
7039
7040
7041 \backslash
7042 /
7043 \end_layout
7044
7045 \end_inset
7046
7047 -xram-loc
7048 \series default
7049
7050 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7051
7052 \end_inset
7053
7054 \InsetSpace ~
7055 <Value> The start location of the external ram
7056 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7057
7058 \end_inset
7059
7060 , default value is 0.
7061  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7062 \begin_inset ERT
7063 status collapsed
7064
7065 \begin_layout Standard
7066
7067
7068 \backslash
7069 /
7070 \end_layout
7071
7072 \end_inset
7073
7074 -xram-loc 0x8000 or -
7075 \begin_inset ERT
7076 status collapsed
7077
7078 \begin_layout Standard
7079
7080
7081 \backslash
7082 /
7083 \end_layout
7084
7085 \end_inset
7086
7087 -xram-loc 32768.
7088 \end_layout
7089
7090 \begin_layout List
7091 \labelwidthstring 00.00.0000
7092
7093 \series bold
7094 -
7095 \begin_inset ERT
7096 status collapsed
7097
7098 \begin_layout Standard
7099
7100
7101 \backslash
7102 /
7103 \end_layout
7104
7105 \end_inset
7106
7107 -code-loc
7108 \series default
7109
7110 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7111
7112 \end_inset
7113
7114 \InsetSpace ~
7115 <Value> The start location of the code
7116 \begin_inset LatexCommand \index{code}
7117
7118 \end_inset
7119
7120  segment, default value 0.
7121  Note when this option is used the interrupt vector table
7122 \begin_inset LatexCommand \index{interrupt vector table}
7123
7124 \end_inset
7125
7126  is also relocated to the given address.
7127  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7128 \begin_inset ERT
7129 status collapsed
7130
7131 \begin_layout Standard
7132
7133
7134 \backslash
7135 /
7136 \end_layout
7137
7138 \end_inset
7139
7140 -code-loc 0x8000 or -
7141 \begin_inset ERT
7142 status collapsed
7143
7144 \begin_layout Standard
7145
7146
7147 \backslash
7148 /
7149 \end_layout
7150
7151 \end_inset
7152
7153 -code-loc 32768.
7154 \end_layout
7155
7156 \begin_layout List
7157 \labelwidthstring 00.00.0000
7158
7159 \series bold
7160 -
7161 \begin_inset ERT
7162 status collapsed
7163
7164 \begin_layout Standard
7165
7166
7167 \backslash
7168 /
7169 \end_layout
7170
7171 \end_inset
7172
7173 -stack-loc
7174 \series default
7175
7176 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7177
7178 \end_inset
7179
7180 \InsetSpace ~
7181 <Value> By default the stack
7182 \begin_inset LatexCommand \index{stack}
7183
7184 \end_inset
7185
7186  is placed after the data segment.
7187  Using this option the stack can be placed anywhere in the internal memory
7188  space of the 8051.
7189  The value entered can be in Hexadecimal or Decimal format, e.g.
7190  -
7191 \begin_inset ERT
7192 status collapsed
7193
7194 \begin_layout Standard
7195
7196
7197 \backslash
7198 /
7199 \end_layout
7200
7201 \end_inset
7202
7203 -stack-loc 0x20 or -
7204 \begin_inset ERT
7205 status collapsed
7206
7207 \begin_layout Standard
7208
7209
7210 \backslash
7211 /
7212 \end_layout
7213
7214 \end_inset
7215
7216 -stack-loc 32.
7217  Since the sp register is incremented before a push or call, the initial
7218  sp will be set to one byte prior the provided value.
7219  The provided value should not overlap any other memory areas such as used
7220  register banks or the data segment and with enough space for the current
7221  application.
7222  The 
7223 \series bold
7224 -
7225 \begin_inset ERT
7226 status collapsed
7227
7228 \begin_layout Standard
7229
7230
7231 \backslash
7232 /
7233 \end_layout
7234
7235 \end_inset
7236
7237 -pack-iram
7238 \series default
7239 \InsetSpace ~
7240
7241 \begin_inset LatexCommand \index{-\/-pack-iram}
7242
7243 \end_inset
7244
7245  option (which is now a default setting) will override this setting, so
7246  you should also specify the 
7247 \series bold
7248 -
7249 \begin_inset ERT
7250 status collapsed
7251
7252 \begin_layout Standard
7253
7254
7255 \backslash
7256 /
7257 \end_layout
7258
7259 \end_inset
7260
7261 -no-pack-iram
7262 \series default
7263 \InsetSpace ~
7264
7265 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7266
7267 \end_inset
7268
7269  option if you need to manually place the stack.
7270 \end_layout
7271
7272 \begin_layout List
7273 \labelwidthstring 00.00.0000
7274
7275 \series bold
7276 -
7277 \begin_inset ERT
7278 status collapsed
7279
7280 \begin_layout Standard
7281
7282
7283 \backslash
7284 /
7285 \end_layout
7286
7287 \end_inset
7288
7289 -xstack-loc
7290 \series default
7291
7292 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7293
7294 \end_inset
7295
7296 \InsetSpace ~
7297 <Value> By default the external stack
7298 \begin_inset LatexCommand \index{xstack}
7299
7300 \end_inset
7301
7302  is placed after the pdata
7303 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7304
7305 \end_inset
7306
7307  segment.
7308  Using this option the xstack can be placed anywhere in the external memory
7309  space of the 8051.
7310  The value entered can be in Hexadecimal or Decimal format, e.g.
7311  -
7312 \begin_inset ERT
7313 status collapsed
7314
7315 \begin_layout Standard
7316
7317
7318 \backslash
7319 /
7320 \end_layout
7321
7322 \end_inset
7323
7324 -xstack-loc 0x8000 or -
7325 \begin_inset ERT
7326 status collapsed
7327
7328 \begin_layout Standard
7329
7330
7331 \backslash
7332 /
7333 \end_layout
7334
7335 \end_inset
7336
7337 -stack-loc 32768.
7338  The provided value should not overlap any other memory areas such as the
7339  pdata or xdata segment and with enough space for the current application.
7340 \end_layout
7341
7342 \begin_layout List
7343 \labelwidthstring 00.00.0000
7344
7345 \series bold
7346 -
7347 \begin_inset ERT
7348 status collapsed
7349
7350 \begin_layout Standard
7351
7352
7353 \backslash
7354 /
7355 \end_layout
7356
7357 \end_inset
7358
7359 -data-loc
7360 \series default
7361
7362 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7363
7364 \end_inset
7365
7366 \InsetSpace ~
7367 <Value> The start location of the internal ram data
7368 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7369
7370 \end_inset
7371
7372  segment.
7373  The value entered can be in Hexadecimal or Decimal format, eg.
7374  -
7375 \begin_inset ERT
7376 status collapsed
7377
7378 \begin_layout Standard
7379
7380
7381 \backslash
7382 /
7383 \end_layout
7384
7385 \end_inset
7386
7387 -data-loc 0x20 or -
7388 \begin_inset ERT
7389 status collapsed
7390
7391 \begin_layout Standard
7392
7393
7394 \backslash
7395 /
7396 \end_layout
7397
7398 \end_inset
7399
7400 -data-loc 32.
7401  (By default, the start location of the internal ram data segment  is set
7402  as low as possible in memory, taking into account the used register banks
7403  and the bit segment at address 0x20.
7404  For example if register banks 0 and 1 are used without bit variables, the
7405  data segment will be set, if -
7406 \begin_inset ERT
7407 status collapsed
7408
7409 \begin_layout Standard
7410
7411
7412 \backslash
7413 /
7414 \end_layout
7415
7416 \end_inset
7417
7418 -data-loc is not used, to location 0x10.)
7419 \end_layout
7420
7421 \begin_layout List
7422 \labelwidthstring 00.00.0000
7423
7424 \series bold
7425 -
7426 \begin_inset ERT
7427 status collapsed
7428
7429 \begin_layout Standard
7430
7431
7432 \backslash
7433 /
7434 \end_layout
7435
7436 \end_inset
7437
7438 -idata-loc
7439 \series default
7440
7441 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7442
7443 \end_inset
7444
7445 \InsetSpace ~
7446 <Value> The start location of the indirectly addressable internal ram
7447 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7448
7449 \end_inset
7450
7451  of the 8051, default value is 0x80.
7452  The value entered can be in Hexadecimal or Decimal format, eg.
7453  -
7454 \begin_inset ERT
7455 status collapsed
7456
7457 \begin_layout Standard
7458
7459
7460 \backslash
7461 /
7462 \end_layout
7463
7464 \end_inset
7465
7466 -idata-loc 0x88 or -
7467 \begin_inset ERT
7468 status collapsed
7469
7470 \begin_layout Standard
7471
7472
7473 \backslash
7474 /
7475 \end_layout
7476
7477 \end_inset
7478
7479 -idata-loc 136.
7480 \end_layout
7481
7482 \begin_layout List
7483 \labelwidthstring 00.00.0000
7484
7485 \series bold
7486 -
7487 \begin_inset ERT
7488 status collapsed
7489
7490 \begin_layout Standard
7491
7492
7493 \backslash
7494 /
7495 \end_layout
7496
7497 \end_inset
7498
7499 -bit-loc
7500 \series default
7501 \InsetSpace ~
7502 <Value> The start location of the bit
7503 \begin_inset LatexCommand \index{bit}
7504
7505 \end_inset
7506
7507  addressable internal ram of the 8051.
7508  This is 
7509 \emph on
7510 not
7511 \emph default
7512  implemented yet.
7513  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7514 -bBSEG=<Value>.
7515 \end_layout
7516
7517 \begin_layout List
7518 \labelwidthstring 00.00.0000
7519
7520 \series bold
7521 -
7522 \begin_inset ERT
7523 status collapsed
7524
7525 \begin_layout Standard
7526
7527
7528 \backslash
7529 /
7530 \end_layout
7531
7532 \end_inset
7533
7534 -out-fmt-ihx
7535 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7536
7537 \end_inset
7538
7539
7540 \bar under
7541  
7542 \series default
7543 \bar default
7544 The linker output (final object code) is in Intel Hex format.
7545 \begin_inset LatexCommand \index{Intel hex format}
7546
7547 \end_inset
7548
7549  This is the default option.
7550  The format itself is documented in the documentation of srecord
7551 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7552
7553 \end_inset
7554
7555 .
7556 \end_layout
7557
7558 \begin_layout List
7559 \labelwidthstring 00.00.0000
7560
7561 \series bold
7562 -
7563 \begin_inset ERT
7564 status collapsed
7565
7566 \begin_layout Standard
7567
7568
7569 \backslash
7570 /
7571 \end_layout
7572
7573 \end_inset
7574
7575 -out-fmt-s19
7576 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7577
7578 \end_inset
7579
7580
7581 \bar under
7582  
7583 \series default
7584 \bar default
7585 The linker output (final object code) is in Motorola S19 format
7586 \begin_inset LatexCommand \index{Motorola S19 format}
7587
7588 \end_inset
7589
7590 .
7591  The format itself is documented in the documentation of srecord.
7592 \end_layout
7593
7594 \begin_layout List
7595 \labelwidthstring 00.00.0000
7596
7597 \series bold
7598 -
7599 \begin_inset ERT
7600 status collapsed
7601
7602 \begin_layout Standard
7603
7604
7605 \backslash
7606 /
7607 \end_layout
7608
7609 \end_inset
7610
7611 -out-fmt-elf
7612 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7613
7614 \end_inset
7615
7616
7617 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7618
7619 \end_inset
7620
7621
7622 \bar under
7623  
7624 \series default
7625 \bar default
7626 The linker output (final object code) is in ELF format
7627 \begin_inset LatexCommand \index{ELF format}
7628
7629 \end_inset
7630
7631 .
7632  (Currently only supported for the HC08
7633 \begin_inset LatexCommand \index{HC08}
7634
7635 \end_inset
7636
7637  processors)
7638 \end_layout
7639
7640 \begin_layout List
7641 \labelwidthstring 00.00.0000
7642
7643 \series bold
7644 -Wl\InsetSpace ~
7645 linkOption[,linkOption]
7646 \series default
7647
7648 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7649
7650 \end_inset
7651
7652 ...
7653  Pass the linkOption to the linker.
7654  If a bootloader is used an option like 
7655 \begin_inset Quotes sld
7656 \end_inset
7657
7658 -Wl\InsetSpace ~
7659 -bCSEG=0x1000
7660 \begin_inset Quotes srd
7661 \end_inset
7662
7663  would be typical to set the start of the code segment.
7664  See also #pragma constseg and #pragma codeseg in section 
7665 \begin_inset LatexCommand \ref{sec:Pragmas}
7666
7667 \end_inset
7668
7669  .
7670  File sdcc/as/doc/asxhtm.html has more on linker options.
7671 \end_layout
7672
7673 \begin_layout Standard
7674 \begin_inset VSpace bigskip
7675 \end_inset
7676
7677
7678 \end_layout
7679
7680 \begin_layout Subsection
7681 MCS51 Options
7682 \begin_inset LatexCommand \index{Options MCS51}
7683
7684 \end_inset
7685
7686
7687 \begin_inset LatexCommand \index{MCS51 options}
7688
7689 \end_inset
7690
7691
7692 \end_layout
7693
7694 \begin_layout List
7695 \labelwidthstring 00.00.0000
7696
7697 \series bold
7698 -
7699 \begin_inset ERT
7700 status collapsed
7701
7702 \begin_layout Standard
7703
7704
7705 \backslash
7706 /
7707 \end_layout
7708
7709 \end_inset
7710
7711 -model-small
7712 \begin_inset LatexCommand \index{-\/-model-small}
7713
7714 \end_inset
7715
7716
7717 \series default
7718 \size large
7719 \emph on
7720  
7721 \size default
7722 \emph default
7723 Generate code for Small Model programs, see section Memory Models for more
7724  details.
7725  This is the default model.
7726 \end_layout
7727
7728 \begin_layout List
7729 \labelwidthstring 00.00.0000
7730
7731 \series bold
7732 -
7733 \begin_inset ERT
7734 status collapsed
7735
7736 \begin_layout Standard
7737
7738
7739 \backslash
7740 /
7741 \end_layout
7742
7743 \end_inset
7744
7745 -model-medium
7746 \begin_inset LatexCommand \index{-\/-model-medium}
7747
7748 \end_inset
7749
7750
7751 \series default
7752  Generate code for Medium model programs, see section Memory Models for
7753  more details.
7754  If this option is used all source files in the project have to be compiled
7755  with this option.
7756  It must also be used when invoking the linker.
7757 \end_layout
7758
7759 \begin_layout List
7760 \labelwidthstring 00.00.0000
7761
7762 \series bold
7763 -
7764 \begin_inset ERT
7765 status collapsed
7766
7767 \begin_layout Standard
7768
7769
7770 \backslash
7771 /
7772 \end_layout
7773
7774 \end_inset
7775
7776 -model-large
7777 \begin_inset LatexCommand \index{-\/-model-large}
7778
7779 \end_inset
7780
7781
7782 \series default
7783  Generate code for Large model programs, see section Memory Models for more
7784  details.
7785  If this option is used all source files in the project have to be compiled
7786  with this option.
7787  It must also be used when invoking the linker.
7788 \end_layout
7789
7790 \begin_layout List
7791 \labelwidthstring 00.00.0000
7792
7793 \series bold
7794 -
7795 \begin_inset ERT
7796 status collapsed
7797
7798 \begin_layout Standard
7799
7800
7801 \backslash
7802 /
7803 \end_layout
7804
7805 \end_inset
7806
7807 -xstack
7808 \begin_inset LatexCommand \index{-\/-xstack}
7809
7810 \end_inset
7811
7812
7813 \series default
7814  Uses a pseudo stack in the pdata
7815 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7816
7817 \end_inset
7818
7819  area (usually the first 256 bytes in the external ram) for allocating variables
7820  and passing parameters.
7821  See section 
7822 \begin_inset LatexCommand \ref{sub:External-Stack}
7823
7824 \end_inset
7825
7826 \InsetSpace ~
7827  External Stack for more details.
7828 \end_layout
7829
7830 \begin_layout List
7831 \labelwidthstring 00.00.0000
7832
7833 \series bold
7834 -
7835 \begin_inset ERT
7836 status collapsed
7837
7838 \begin_layout Standard
7839
7840
7841 \backslash
7842 /
7843 \end_layout
7844
7845 \end_inset
7846
7847 -iram-size
7848 \series default
7849 \InsetSpace ~
7850 <Value>
7851 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7852
7853 \end_inset
7854
7855  Causes the linker to check if the internal ram usage is within limits of
7856  the given value.
7857 \end_layout
7858
7859 \begin_layout List
7860 \labelwidthstring 00.00.0000
7861
7862 \series bold
7863 -
7864 \begin_inset ERT
7865 status collapsed
7866
7867 \begin_layout Standard
7868
7869
7870 \backslash
7871 /
7872 \end_layout
7873
7874 \end_inset
7875
7876 -xram-size
7877 \series default
7878 \InsetSpace ~
7879 <Value>
7880 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7881
7882 \end_inset
7883
7884  Causes the linker to check if the external ram usage is within limits of
7885  the given value.
7886 \end_layout
7887
7888 \begin_layout List
7889 \labelwidthstring 00.00.0000
7890
7891 \series bold
7892 -
7893 \begin_inset ERT
7894 status collapsed
7895
7896 \begin_layout Standard
7897
7898
7899 \backslash
7900 /
7901 \end_layout
7902
7903 \end_inset
7904
7905 -code-size
7906 \series default
7907 \InsetSpace ~
7908 <Value>
7909 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7910
7911 \end_inset
7912
7913  Causes the linker to check if the code memory usage is within limits of
7914  the given value.
7915 \end_layout
7916
7917 \begin_layout List
7918 \labelwidthstring 00.00.0000
7919
7920 \series bold
7921 -
7922 \begin_inset ERT
7923 status collapsed
7924
7925 \begin_layout Standard
7926
7927
7928 \backslash
7929 /
7930 \end_layout
7931
7932 \end_inset
7933
7934 -stack-size
7935 \series default
7936 \InsetSpace ~
7937 <Value>
7938 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7939
7940 \end_inset
7941
7942  Causes the linker to check if there is at minimum <Value> bytes for stack.
7943 \end_layout
7944
7945 \begin_layout List
7946 \labelwidthstring 00.00.0000
7947
7948 \series bold
7949 -
7950 \begin_inset ERT
7951 status collapsed
7952
7953 \begin_layout Standard
7954
7955
7956 \backslash
7957 /
7958 \end_layout
7959
7960 \end_inset
7961
7962 -pack-iram
7963 \series default
7964 \InsetSpace ~
7965
7966 \begin_inset LatexCommand \index{-\/-pack-iram}
7967
7968 \end_inset
7969
7970  Causes the linker to use unused register banks for data variables and pack
7971  data, idata and stack together.
7972  This is the default now.
7973 \end_layout
7974
7975 \begin_layout List
7976 \labelwidthstring 00.00.0000
7977
7978 \series bold
7979 -
7980 \begin_inset ERT
7981 status collapsed
7982
7983 \begin_layout Standard
7984
7985
7986 \backslash
7987 /
7988 \end_layout
7989
7990 \end_inset
7991
7992 -no-pack-iram
7993 \series default
7994 \InsetSpace ~
7995
7996 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7997
7998 \end_inset
7999
8000  Causes the linker to use old style for allocating memory areas.
8001 \end_layout
8002
8003 \begin_layout Standard
8004 \begin_inset VSpace bigskip
8005 \end_inset
8006
8007
8008 \end_layout
8009
8010 \begin_layout Subsection
8011 DS390 / DS400 Options
8012 \begin_inset LatexCommand \index{Options DS390}
8013
8014 \end_inset
8015
8016
8017 \begin_inset LatexCommand \index{DS390}
8018
8019 \end_inset
8020
8021
8022 \end_layout
8023
8024 \begin_layout List
8025 \labelwidthstring 00.00.0000
8026
8027 \series bold
8028 -
8029 \begin_inset ERT
8030 status collapsed
8031
8032 \begin_layout Standard
8033
8034
8035 \backslash
8036 /
8037 \end_layout
8038
8039 \end_inset
8040
8041 -model-flat24
8042 \series default
8043
8044 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8045
8046 \end_inset
8047
8048
8049 \size large
8050 \emph on
8051  
8052 \size default
8053 \emph default
8054 Generate 24-bit flat mode code.
8055  This is the one and only that the ds390 code generator supports right now
8056  and is default when using 
8057 \emph on
8058 -mds390
8059 \emph default
8060 .
8061  See section Memory Models for more details.
8062 \end_layout
8063
8064 \begin_layout List
8065 \labelwidthstring 00.00.0000
8066
8067 \series bold
8068 -
8069 \begin_inset ERT
8070 status collapsed
8071
8072 \begin_layout Standard
8073
8074
8075 \backslash
8076 /
8077 \end_layout
8078
8079 \end_inset
8080
8081 -protect-sp-update
8082 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8083
8084 \end_inset
8085
8086
8087 \series default
8088  disable interrupts during ESP:SP updates.
8089 \end_layout
8090
8091 \begin_layout List
8092 \labelwidthstring 00.00.0000
8093
8094 \series bold
8095 -
8096 \begin_inset ERT
8097 status collapsed
8098
8099 \begin_layout Standard
8100
8101
8102 \backslash
8103 /
8104 \end_layout
8105
8106 \end_inset
8107
8108 -stack-10bit
8109 \series default
8110
8111 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8112
8113 \end_inset
8114
8115  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8116  This is the one and only that the ds390 code generator supports right now
8117  and is default when using 
8118 \emph on
8119 -mds390
8120 \emph default
8121 .
8122  In this mode, the stack is located in the lower 1K of the internal RAM,
8123  which is mapped to 0x400000.
8124  Note that the support is incomplete, since it still uses a single byte
8125  as the stack pointer.
8126  This means that only the lower 256 bytes of the potential 1K stack space
8127  will actually be used.
8128  However, this does allow you to reclaim the precious 256 bytes of low RAM
8129  for use for the DATA and IDATA segments.
8130  The compiler will not generate any code to put the processor into 10 bit
8131  stack mode.
8132  It is important to ensure that the processor is in this mode before calling
8133  any re-entrant functions compiled with this option.
8134  In principle, this should work with the 
8135 \emph on
8136 -
8137 \begin_inset ERT
8138 status collapsed
8139
8140 \begin_layout Standard
8141
8142
8143 \backslash
8144 /
8145 \end_layout
8146
8147 \end_inset
8148
8149 -stack-auto
8150 \begin_inset LatexCommand \index{-\/-stack-auto}
8151
8152 \end_inset
8153
8154
8155 \emph default
8156  option, but that has not been tested.
8157  It is incompatible with the 
8158 \emph on
8159 -
8160 \begin_inset ERT
8161 status collapsed
8162
8163 \begin_layout Standard
8164
8165
8166 \backslash
8167 /
8168 \end_layout
8169
8170 \end_inset
8171
8172 -xstack
8173 \begin_inset LatexCommand \index{-\/-xstack}
8174
8175 \end_inset
8176
8177
8178 \emph default
8179  option.
8180  It also only makes sense if the processor is in 24 bit contiguous addressing
8181  mode (see the 
8182 \emph on
8183 -
8184 \begin_inset ERT
8185 status collapsed
8186
8187 \begin_layout Standard
8188
8189
8190 \backslash
8191 /
8192 \end_layout
8193
8194 \end_inset
8195
8196 -model-flat24 option
8197 \emph default
8198 ).
8199 \end_layout
8200
8201 \begin_layout List
8202 \labelwidthstring 00.00.0000
8203
8204 \series bold
8205 -
8206 \begin_inset ERT
8207 status collapsed
8208
8209 \begin_layout Standard
8210
8211
8212 \backslash
8213 /
8214 \end_layout
8215
8216 \end_inset
8217
8218 -stack-probe
8219 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8220
8221 \end_inset
8222
8223
8224 \series default
8225  insert call to function __stack_probe at each function prologue.
8226 \end_layout
8227
8228 \begin_layout List
8229 \labelwidthstring 00.00.0000
8230
8231 \series bold
8232 -
8233 \begin_inset ERT
8234 status collapsed
8235
8236 \begin_layout Standard
8237
8238
8239 \backslash
8240 /
8241 \end_layout
8242
8243 \end_inset
8244
8245 -tini-libid
8246 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8247
8248 \end_inset
8249
8250
8251 \series default
8252  <nnnn> LibraryID used in -mTININative.
8253  
8254 \end_layout
8255
8256 \begin_layout List
8257 \labelwidthstring 00.00.0000
8258
8259 \series bold
8260 -
8261 \begin_inset ERT
8262 status collapsed
8263
8264 \begin_layout Standard
8265
8266
8267 \backslash
8268 /
8269 \end_layout
8270
8271 \end_inset
8272
8273 -use-accelerator
8274 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8275
8276 \end_inset
8277
8278
8279 \series default
8280  generate code for DS390 Arithmetic Accelerator.
8281  
8282 \end_layout
8283
8284 \begin_layout Standard
8285 \begin_inset VSpace bigskip
8286 \end_inset
8287
8288
8289 \end_layout
8290
8291 \begin_layout Subsection
8292 Z80 Options
8293 \begin_inset LatexCommand \index{Options Z80}
8294
8295 \end_inset
8296
8297
8298 \begin_inset LatexCommand \index{Z80}
8299
8300 \end_inset
8301
8302
8303 \end_layout
8304
8305 \begin_layout List
8306 \labelwidthstring 00.00.0000
8307
8308 \series bold
8309 -
8310 \begin_inset ERT
8311 status collapsed
8312
8313 \begin_layout Standard
8314
8315
8316 \backslash
8317 /
8318 \end_layout
8319
8320 \end_inset
8321
8322 -callee-saves-bc
8323 \series default
8324
8325 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8326
8327 \end_inset
8328
8329
8330 \size large
8331 \emph on
8332  
8333 \size default
8334 \emph default
8335 Force a called function to always save BC.
8336 \end_layout
8337
8338 \begin_layout List
8339 \labelwidthstring 00.00.0000
8340
8341 \series bold
8342 -
8343 \begin_inset ERT
8344 status collapsed
8345
8346 \begin_layout Standard
8347
8348
8349 \backslash
8350 /
8351 \end_layout
8352
8353 \end_inset
8354
8355 -no-std-crt0
8356 \series default
8357
8358 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8359
8360 \end_inset
8361
8362  When linking, skip the standard crt0.o object file.
8363  You must provide your own crt0.o for your system when linking.
8364  
8365 \end_layout
8366
8367 \begin_layout Standard
8368 \begin_inset VSpace bigskip
8369 \end_inset
8370
8371
8372 \end_layout
8373
8374 \begin_layout Subsection
8375 Optimization Options
8376 \begin_inset LatexCommand \index{Options optimization}
8377
8378 \end_inset
8379
8380
8381 \begin_inset LatexCommand \index{Optimization options}
8382
8383 \end_inset
8384
8385
8386 \end_layout
8387
8388 \begin_layout List
8389 \labelwidthstring 00.00.0000
8390
8391 \series bold
8392 -
8393 \begin_inset ERT
8394 status collapsed
8395
8396 \begin_layout Standard
8397
8398
8399 \backslash
8400 /
8401 \end_layout
8402
8403 \end_inset
8404
8405 -nogcse
8406 \begin_inset LatexCommand \index{-\/-nogcse}
8407
8408 \end_inset
8409
8410
8411 \series default
8412  Will not do global subexpression elimination, this option may be used when
8413  the compiler creates undesirably large stack/data spaces to store compiler
8414  temporaries (
8415 \emph on
8416 s
8417 \emph default
8418 pill 
8419 \emph on
8420 loc
8421 \emph default
8422 ations, sloc
8423 \begin_inset LatexCommand \index{sloc (spill location)}
8424
8425 \end_inset
8426
8427 ).
8428  A warning message will be generated when this happens and the compiler
8429  will indicate the number of extra bytes it allocated.
8430  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8431 nogcse
8432 \begin_inset LatexCommand \index{\#pragma nogcse}
8433
8434 \end_inset
8435
8436  can be used to turn off global subexpression elimination
8437 \begin_inset LatexCommand \index{Subexpression elimination}
8438
8439 \end_inset
8440
8441  for a given function only.
8442 \end_layout
8443
8444 \begin_layout List
8445 \labelwidthstring 00.00.0000
8446
8447 \series bold
8448 -
8449 \begin_inset ERT
8450 status collapsed
8451
8452 \begin_layout Standard
8453
8454
8455 \backslash
8456 /
8457 \end_layout
8458
8459 \end_inset
8460
8461 -noinvariant
8462 \begin_inset LatexCommand \index{-\/-noinvariant}
8463
8464 \end_inset
8465
8466
8467 \series default
8468  Will not do loop invariant optimizations, this may be turned off for reasons
8469  explained for the previous option.
8470  For more details of loop optimizations performed see Loop Invariants in
8471  section 
8472 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8473
8474 \end_inset
8475
8476 .
8477  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8478 noinvariant
8479 \begin_inset LatexCommand \index{\#pragma noinvariant}
8480
8481 \end_inset
8482
8483  can be used to turn off invariant optimizations for a given function only.
8484 \end_layout
8485
8486 \begin_layout List
8487 \labelwidthstring 00.00.0000
8488
8489 \series bold
8490 -
8491 \begin_inset ERT
8492 status collapsed
8493
8494 \begin_layout Standard
8495
8496
8497 \backslash
8498 /
8499 \end_layout
8500
8501 \end_inset
8502
8503 -noinduction
8504 \begin_inset LatexCommand \index{-\/-noinduction}
8505
8506 \end_inset
8507
8508
8509 \series default
8510  Will not do loop induction optimizations, see section strength reduction
8511  for more details.
8512  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8513 noinduction
8514 \begin_inset LatexCommand \index{\#pragma noinduction}
8515
8516 \end_inset
8517
8518  can be used to turn off induction optimizations for a given function only.
8519 \end_layout
8520
8521 \begin_layout List
8522 \labelwidthstring 00.00.0000
8523
8524 \series bold
8525 -
8526 \begin_inset ERT
8527 status collapsed
8528
8529 \begin_layout Standard
8530
8531
8532 \backslash
8533 /
8534 \end_layout
8535
8536 \end_inset
8537
8538 -nojtbound
8539 \begin_inset LatexCommand \index{-\/-nojtbound}
8540
8541 \end_inset
8542
8543
8544 \size large
8545 \bar under
8546  
8547 \series default
8548 \size default
8549 \bar default
8550  Will not generate boundary condition check when switch statements
8551 \begin_inset LatexCommand \index{switch statement}
8552
8553 \end_inset
8554
8555  are implemented using jump-tables.
8556  See section 
8557 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8558
8559 \end_inset
8560
8561 \InsetSpace ~
8562 Switch Statements for more details.
8563  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8564 nojtbound
8565 \begin_inset LatexCommand \index{\#pragma nojtbound}
8566
8567 \end_inset
8568
8569  can be used to turn off boundary checking for jump tables for a given function
8570  only.
8571 \end_layout
8572
8573 \begin_layout List
8574 \labelwidthstring 00.00.0000
8575
8576 \series bold
8577 -
8578 \begin_inset ERT
8579 status collapsed
8580
8581 \begin_layout Standard
8582
8583
8584 \backslash
8585 /
8586 \end_layout
8587
8588 \end_inset
8589
8590 -noloopreverse
8591 \begin_inset LatexCommand \index{-\/-noloopreverse}
8592
8593 \end_inset
8594
8595
8596 \series default
8597 \size large
8598  
8599 \size default
8600 Will not do loop reversal 
8601 \begin_inset LatexCommand \index{Loop reversing}
8602
8603 \end_inset
8604
8605 optimization.
8606 \end_layout
8607
8608 \begin_layout List
8609 \labelwidthstring 00.00.0000
8610 -
8611 \begin_inset ERT
8612 status collapsed
8613
8614 \begin_layout Standard
8615
8616
8617 \backslash
8618 /
8619 \end_layout
8620
8621 \end_inset
8622
8623 -
8624 \series bold
8625 nolabelopt
8626 \series default
8627  
8628 \begin_inset LatexCommand \index{-\/-nolabelopt }
8629
8630 \end_inset
8631
8632 Will not optimize labels (makes the dumpfiles more readable).
8633 \end_layout
8634
8635 \begin_layout List
8636 \labelwidthstring 00.00.0000
8637
8638 \series bold
8639 -
8640 \begin_inset ERT
8641 status collapsed
8642
8643 \begin_layout Standard
8644
8645
8646 \backslash
8647 /
8648 \end_layout
8649
8650 \end_inset
8651
8652 -no-xinit-opt
8653 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8654
8655 \end_inset
8656
8657
8658 \series default
8659  Will not memcpy initialized data from code space into xdata space.
8660  This saves a few bytes in code space if you don't have initialized data
8661 \begin_inset LatexCommand \index{Variable initialization}
8662
8663 \end_inset
8664
8665 .
8666 \end_layout
8667
8668 \begin_layout List
8669 \labelwidthstring 00.00.0000
8670
8671 \series bold
8672 -
8673 \begin_inset ERT
8674 status collapsed
8675
8676 \begin_layout Standard
8677
8678
8679 \backslash
8680 /
8681 \end_layout
8682
8683 \end_inset
8684
8685 -nooverlay
8686 \begin_inset LatexCommand \index{-\/-nooverlay}
8687
8688 \end_inset
8689
8690
8691 \series default
8692   The compiler will not overlay parameters and local variables of any function,
8693  see section Parameters and local variables for more details.
8694 \end_layout
8695
8696 \begin_layout List
8697 \labelwidthstring 00.00.0000
8698
8699 \series bold
8700 -
8701 \begin_inset ERT
8702 status collapsed
8703
8704 \begin_layout Standard
8705
8706
8707 \backslash
8708 /
8709 \end_layout
8710
8711 \end_inset
8712
8713 -no-peep
8714 \begin_inset LatexCommand \index{-\/-no-peep}
8715
8716 \end_inset
8717
8718
8719 \series default
8720  Disable peep-hole optimization with built-in rules.
8721 \end_layout
8722
8723 \begin_layout List
8724 \labelwidthstring 00.00.0000
8725
8726 \series bold
8727 -
8728 \begin_inset ERT
8729 status collapsed
8730
8731 \begin_layout Standard
8732
8733
8734 \backslash
8735 /
8736 \end_layout
8737
8738 \end_inset
8739
8740 -peep-file
8741 \series default
8742
8743 \begin_inset LatexCommand \index{-\/-peep-file}
8744
8745 \end_inset
8746
8747 \InsetSpace ~
8748 <filename> This option can be used to use additional rules to be used by
8749  the peep hole optimizer.
8750  See section 
8751 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8752
8753 \end_inset
8754
8755 \InsetSpace ~
8756 Peep Hole optimizations for details on how to write these rules.
8757 \end_layout
8758
8759 \begin_layout List
8760 \labelwidthstring 00.00.0000
8761
8762 \series bold
8763 -
8764 \begin_inset ERT
8765 status collapsed
8766
8767 \begin_layout Standard
8768
8769
8770 \backslash
8771 /
8772 \end_layout
8773
8774 \end_inset
8775
8776 -peep-asm
8777 \begin_inset LatexCommand \index{-\/-peep-asm}
8778
8779 \end_inset
8780
8781
8782 \series default
8783  Pass the inline assembler code through the peep hole optimizer.
8784  This can cause unexpected changes to inline assembler code, please go through
8785  the peephole optimizer
8786 \begin_inset LatexCommand \index{Peephole optimizer}
8787
8788 \end_inset
8789
8790  rules defined in the source file tree '<target>/peeph.def' before using
8791  this option.
8792 \end_layout
8793
8794 \begin_layout List
8795 \labelwidthstring 00.00.0000
8796
8797 \series bold
8798 -
8799 \begin_inset ERT
8800 status collapsed
8801
8802 \begin_layout Standard
8803
8804
8805 \backslash
8806 /
8807 \end_layout
8808
8809 \end_inset
8810
8811 -opt-code-speed
8812 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8813
8814 \end_inset
8815
8816
8817 \series default
8818  The compiler will optimize code generation towards fast code, possibly
8819  at the expense of code size.
8820 \end_layout
8821
8822 \begin_layout List
8823 \labelwidthstring 00.00.0000
8824
8825 \series bold
8826 -
8827 \begin_inset ERT
8828 status collapsed
8829
8830 \begin_layout Standard
8831
8832
8833 \backslash
8834 /
8835 \end_layout
8836
8837 \end_inset
8838
8839 -opt-code-size
8840 \begin_inset LatexCommand \index{-\/-opt-code-size}
8841
8842 \end_inset
8843
8844
8845 \series default
8846  The compiler will optimize code generation towards compact code, possibly
8847  at the expense of code speed.
8848 \end_layout
8849
8850 \begin_layout Standard
8851 \begin_inset VSpace bigskip
8852 \end_inset
8853
8854
8855 \end_layout
8856
8857 \begin_layout Subsection
8858 Other Options
8859 \begin_inset LatexCommand \index{Options other}
8860
8861 \end_inset
8862
8863
8864 \end_layout
8865
8866 \begin_layout List
8867 \labelwidthstring 00.00.0000
8868
8869 \series bold
8870 -c\InsetSpace ~
8871 -
8872 \begin_inset ERT
8873 status collapsed
8874
8875 \begin_layout Standard
8876
8877
8878 \backslash
8879 /
8880 \end_layout
8881
8882 \end_inset
8883
8884 -compile-only
8885 \begin_inset LatexCommand \index{-\/-compile-only}
8886
8887 \end_inset
8888
8889
8890 \begin_inset LatexCommand \index{-c -\/-compile-only}
8891
8892 \end_inset
8893
8894
8895 \series default
8896  will compile and assemble the source, but will not call the linkage editor.
8897 \end_layout
8898
8899 \begin_layout List
8900 \labelwidthstring 00.00.0000
8901
8902 \series bold
8903 -
8904 \series default
8905
8906 \begin_inset ERT
8907 status collapsed
8908
8909 \begin_layout Standard
8910
8911
8912 \backslash
8913 /
8914 \end_layout
8915
8916 \end_inset
8917
8918
8919 \series bold
8920 -c1mode
8921 \begin_inset LatexCommand \index{-\/-c1mode}
8922
8923 \end_inset
8924
8925
8926 \series default
8927  reads the preprocessed source from standard input and compiles it.
8928  The file name for the assembler output must be specified using the -o option.
8929 \end_layout
8930
8931 \begin_layout List
8932 \labelwidthstring 00.00.0000
8933
8934 \series bold
8935 -E
8936 \begin_inset LatexCommand \index{-E}
8937
8938 \end_inset
8939
8940
8941 \series default
8942  Run only the C preprocessor.
8943  Preprocess all the C source files specified and output the results to standard
8944  output.
8945 \end_layout
8946
8947 \begin_layout List
8948 \labelwidthstring 00.00.0000
8949
8950 \series bold
8951 -o\InsetSpace ~
8952 <path/file>
8953 \begin_inset LatexCommand \index{-o <path/file>}
8954
8955 \end_inset
8956
8957  
8958 \series default
8959 The output path resp.
8960  file where everything will be placed.
8961  If the parameter is a path, it must have a trailing slash (or backslash
8962  for the Windows binaries) to be recognized as a path.
8963  
8964 \end_layout
8965
8966 \begin_layout List
8967 \labelwidthstring 00.00.0000
8968
8969 \series bold
8970 -
8971 \begin_inset ERT
8972 status collapsed
8973
8974 \begin_layout Standard
8975
8976
8977 \backslash
8978 /
8979 \end_layout
8980
8981 \end_inset
8982
8983 -stack-auto
8984 \begin_inset LatexCommand \index{-\/-stack-auto}
8985
8986 \end_inset
8987
8988
8989 \series default
8990 \size large
8991 \emph on
8992  
8993 \size default
8994 \emph default
8995 All functions in the source file will be compiled as 
8996 \emph on
8997 reentrant
8998 \emph default
8999
9000 \begin_inset LatexCommand \index{reentrant}
9001
9002 \end_inset
9003
9004 , i.e.
9005  the parameters and local variables will be allocated on the stack
9006 \begin_inset LatexCommand \index{stack}
9007
9008 \end_inset
9009
9010 .
9011  See section 
9012 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9013
9014 \end_inset
9015
9016  Parameters and Local Variables for more details.
9017  If this option is used all source files in the project should be compiled
9018  with this option.
9019  It automatically implies --int-long-reent and --float-reent.
9020  
9021 \end_layout
9022
9023 \begin_layout List
9024 \labelwidthstring 00.00.0000
9025
9026 \series bold
9027 -
9028 \begin_inset ERT
9029 status collapsed
9030
9031 \begin_layout Standard
9032
9033
9034 \backslash
9035 /
9036 \end_layout
9037
9038 \end_inset
9039
9040 -callee-saves
9041 \begin_inset LatexCommand \index{-\/-callee-saves}
9042
9043 \end_inset
9044
9045  function1[,function2][,function3]....
9046
9047 \series default
9048  The compiler by default uses a caller saves convention for register saving
9049  across function calls, however this can cause unnecessary register pushing
9050  & popping when calling small functions from larger functions.
9051  This option can be used to switch the register saving convention for the
9052  function names specified.
9053  The compiler will not save registers when calling these functions, no extra
9054  code will be generated at the entry & exit (function prologue
9055 \series bold
9056
9057 \begin_inset LatexCommand \index{function prologue}
9058
9059 \end_inset
9060
9061
9062 \series default
9063  & epilogue
9064 \series bold
9065
9066 \begin_inset LatexCommand \index{function epilogue}
9067
9068 \end_inset
9069
9070
9071 \series default
9072 ) for these functions to save & restore the registers used by these functions,
9073  this can SUBSTANTIALLY reduce code & improve run time performance of the
9074  generated code.
9075  In the future the compiler (with inter procedural analysis) will be able
9076  to determine the appropriate scheme to use for each function call.
9077  DO NOT use this option for built-in functions such as _mulint..., if this
9078  option is used for a library function the appropriate library function
9079  needs to be recompiled with the same option.
9080  If the project consists of multiple source files then all the source file
9081  should be compiled with the same -
9082 \begin_inset ERT
9083 status collapsed
9084
9085 \begin_layout Standard
9086
9087
9088 \backslash
9089 /
9090 \end_layout
9091
9092 \end_inset
9093
9094 -callee-saves option string.
9095  Also see #pragma\InsetSpace ~
9096 callee_saves
9097 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9098
9099 \end_inset
9100
9101 .
9102 \end_layout
9103
9104 \begin_layout List
9105 \labelwidthstring 00.00.0000
9106
9107 \series bold
9108 -
9109 \begin_inset ERT
9110 status collapsed
9111
9112 \begin_layout Standard
9113
9114
9115 \backslash
9116 /
9117 \end_layout
9118
9119 \end_inset
9120
9121 -debug
9122 \begin_inset LatexCommand \index{-\/-debug}
9123
9124 \end_inset
9125
9126
9127 \bar under
9128  
9129 \series default
9130 \bar default
9131 When this option is used the compiler will generate debug information.
9132  The debug information collected in a file with .cdb extension can be used
9133  with the SDCDB.
9134  For more information see documentation for SDCDB.
9135  Another file with no extension contains debug information in AOMF or AOMF51
9136 \begin_inset LatexCommand \index{AOMF, AOMF51}
9137
9138 \end_inset
9139
9140  format which is commonly used by third party tools.
9141 \end_layout
9142
9143 \begin_layout List
9144 \labelwidthstring 00.00.0000
9145
9146 \series bold
9147 -S
9148 \begin_inset LatexCommand \index{-S}
9149
9150 \end_inset
9151
9152
9153 \size large
9154 \bar under
9155  
9156 \series default
9157 \size default
9158 \bar default
9159 Stop after the stage of compilation proper; do not assemble.
9160  The output is an assembler code file for the input file specified.
9161 \end_layout
9162
9163 \begin_layout List
9164 \labelwidthstring 00.00.0000
9165
9166 \series bold
9167 -
9168 \begin_inset ERT
9169 status collapsed
9170
9171 \begin_layout Standard
9172
9173
9174 \backslash
9175 /
9176 \end_layout
9177
9178 \end_inset
9179
9180 -int-long-reent
9181 \begin_inset LatexCommand \index{-\/-int-long-reent}
9182
9183 \end_inset
9184
9185
9186 \series default
9187  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9188  Note by default these libraries are compiled as non-reentrant.
9189  See section Installation for more details.
9190 \end_layout
9191
9192 \begin_layout List
9193 \labelwidthstring 00.00.0000
9194
9195 \series bold
9196 -
9197 \begin_inset ERT
9198 status collapsed
9199
9200 \begin_layout Standard
9201
9202
9203 \backslash
9204 /
9205 \end_layout
9206
9207 \end_inset
9208
9209 -cyclomatic
9210 \begin_inset LatexCommand \index{-\/-cyclomatic}
9211
9212 \end_inset
9213
9214
9215 \bar under
9216  
9217 \series default
9218 \bar default
9219 This option will cause the compiler to generate an information message for
9220  each function in the source file.
9221  The message contains some 
9222 \emph on
9223 important
9224 \emph default
9225  information about the function.
9226  The number of edges and nodes the compiler detected in the control flow
9227  graph of the function, and most importantly the 
9228 \emph on
9229 cyclomatic complexity
9230 \begin_inset LatexCommand \index{Cyclomatic complexity}
9231
9232 \end_inset
9233
9234
9235 \emph default
9236  see section on Cyclomatic Complexity for more details.
9237 \end_layout
9238
9239 \begin_layout List
9240 \labelwidthstring 00.00.0000
9241
9242 \series bold
9243 -
9244 \begin_inset ERT
9245 status collapsed
9246
9247 \begin_layout Standard
9248
9249
9250 \backslash
9251 /
9252 \end_layout
9253
9254 \end_inset
9255
9256 -float-reent
9257 \begin_inset LatexCommand \index{-\/-float-reent}
9258
9259 \end_inset
9260
9261
9262 \series default
9263  Floating point library is compiled as reentrant
9264 \begin_inset LatexCommand \index{reentrant}
9265
9266 \end_inset
9267
9268 .
9269  See section Installation for more details.
9270 \end_layout
9271
9272 \begin_layout List
9273 \labelwidthstring 00.00.0000
9274
9275 \series bold
9276 -
9277 \begin_inset ERT
9278 status collapsed
9279
9280 \begin_layout Standard
9281
9282
9283 \backslash
9284 /
9285 \end_layout
9286
9287 \end_inset
9288
9289 -funsigned-char
9290 \begin_inset LatexCommand \index{-\/-funsigned-char}
9291
9292 \end_inset
9293
9294
9295 \series default
9296  The default signedness for every type is
9297 \family typewriter
9298  signed
9299 \family default
9300 .
9301  In some embedded environments the default signedness of
9302 \family typewriter
9303  char
9304 \family default
9305  is
9306 \family typewriter
9307  unsigned
9308 \family default
9309 .
9310  To set the signess for characters to unsigned, use the option --funsigned-char.
9311  If this option is set and no signedness keyword (unsigned/signed) is given,
9312  a char will be signed.
9313  All other types are unaffected.
9314 \end_layout
9315
9316 \begin_layout List
9317 \labelwidthstring 00.00.0000
9318
9319 \series bold
9320 -
9321 \begin_inset ERT
9322 status collapsed
9323
9324 \begin_layout Standard
9325
9326
9327 \backslash
9328 /
9329 \end_layout
9330
9331 \end_inset
9332
9333 -main-return
9334 \begin_inset LatexCommand \index{-\/-main-return}
9335
9336 \end_inset
9337
9338
9339 \series default
9340  This option can be used if the code generated is called by a monitor program
9341  or if the main routine includes an endless loop.
9342  This option results in slightly smaller code and saves two bytes of stack
9343  space.
9344  The return from the 'main'
9345 \begin_inset LatexCommand \index{main return}
9346
9347 \end_inset
9348
9349  function will return to the function calling main.
9350  The default setting is to lock up i.e.
9351  generate a '
9352 \family typewriter
9353 sjmp .
9354 \family default
9355 '.
9356 \end_layout
9357
9358 \begin_layout List
9359 \labelwidthstring 00.00.0000
9360
9361 \series bold
9362 -
9363 \begin_inset ERT
9364 status collapsed
9365
9366 \begin_layout Standard
9367
9368
9369 \backslash
9370 /
9371 \end_layout
9372
9373 \end_inset
9374
9375 -nostdinc
9376 \begin_inset LatexCommand \index{-\/-nostdinc}
9377
9378 \end_inset
9379
9380
9381 \series default
9382  This will prevent the compiler from passing on the default include path
9383  to the preprocessor.
9384 \end_layout
9385
9386 \begin_layout List
9387 \labelwidthstring 00.00.0000
9388
9389 \series bold
9390 -
9391 \begin_inset ERT
9392 status collapsed
9393
9394 \begin_layout Standard
9395
9396
9397 \backslash
9398 /
9399 \end_layout
9400
9401 \end_inset
9402
9403 -nostdlib
9404 \begin_inset LatexCommand \index{-\/-nostdlib}
9405
9406 \end_inset
9407
9408
9409 \series default
9410  This will prevent the compiler from passing on the default library
9411 \begin_inset LatexCommand \index{Libraries}
9412
9413 \end_inset
9414
9415  path to the linker.
9416 \end_layout
9417
9418 \begin_layout List
9419 \labelwidthstring 00.00.0000
9420
9421 \series bold
9422 -
9423 \begin_inset ERT
9424 status collapsed
9425
9426 \begin_layout Standard
9427
9428
9429 \backslash
9430 /
9431 \end_layout
9432
9433 \end_inset
9434
9435 -verbose
9436 \begin_inset LatexCommand \index{-\/-verbose}
9437
9438 \end_inset
9439
9440
9441 \series default
9442  Shows the various actions the compiler is performing.
9443 \end_layout
9444
9445 \begin_layout List
9446 \labelwidthstring 00.00.0000
9447
9448 \series bold
9449 -V
9450 \begin_inset LatexCommand \index{-V}
9451
9452 \end_inset
9453
9454
9455 \series default
9456  Shows the actual commands the compiler is executing.
9457 \end_layout
9458
9459 \begin_layout List
9460 \labelwidthstring 00.00.0000
9461
9462 \series bold
9463 -
9464 \begin_inset ERT
9465 status collapsed
9466
9467 \begin_layout Standard
9468
9469
9470 \backslash
9471 /
9472 \end_layout
9473
9474 \end_inset
9475
9476 -no-c-code-in-asm
9477 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9478
9479 \end_inset
9480
9481
9482 \series default
9483  Hides your ugly and inefficient c-code from the asm file, so you can always
9484  blame the compiler :)
9485 \end_layout
9486
9487 \begin_layout List
9488 \labelwidthstring 00.00.0000
9489
9490 \series bold
9491 -
9492 \begin_inset ERT
9493 status collapsed
9494
9495 \begin_layout Standard
9496
9497
9498 \backslash
9499 /
9500 \end_layout
9501
9502 \end_inset
9503
9504 -no-peep-comments
9505 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9506
9507 \end_inset
9508
9509
9510 \series default
9511  Will not include peep-hole comments in the generated files.
9512 \end_layout
9513
9514 \begin_layout List
9515 \labelwidthstring 00.00.0000
9516
9517 \series bold
9518 -
9519 \begin_inset ERT
9520 status collapsed
9521
9522 \begin_layout Standard
9523
9524
9525 \backslash
9526 /
9527 \end_layout
9528
9529 \end_inset
9530
9531 -no-gen-comments
9532 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9533
9534 \end_inset
9535
9536
9537 \series default
9538  Will not include code generator comments in the generated files.
9539 \end_layout
9540
9541 \begin_layout List
9542 \labelwidthstring 00.00.0000
9543
9544 \series bold
9545 -
9546 \begin_inset ERT
9547 status collapsed
9548
9549 \begin_layout Standard
9550
9551
9552 \backslash
9553 /
9554 \end_layout
9555
9556 \end_inset
9557
9558 -i-code-in-asm
9559 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9560
9561 \end_inset
9562
9563
9564 \series default
9565  Include i-codes in the asm file.
9566  Sounds like noise but is most helpful for debugging the compiler itself.
9567 \end_layout
9568
9569 \begin_layout List
9570 \labelwidthstring 00.00.0000
9571
9572 \series bold
9573 -
9574 \begin_inset ERT
9575 status collapsed
9576
9577 \begin_layout Standard
9578
9579
9580 \backslash
9581 /
9582 \end_layout
9583
9584 \end_inset
9585
9586 -less-pedantic
9587 \begin_inset LatexCommand \index{-\/-less-pedantic}
9588
9589 \end_inset
9590
9591
9592 \series default
9593  Disable some of the more pedantic warnings
9594 \begin_inset LatexCommand \index{Warnings}
9595
9596 \end_inset
9597
9598  (jwk burps: please be more specific here, please!).
9599 \end_layout
9600
9601 \begin_layout List
9602 \labelwidthstring 00.00.0000
9603
9604 \series bold
9605 -
9606 \begin_inset ERT
9607 status collapsed
9608
9609 \begin_layout Standard
9610
9611
9612 \backslash
9613 /
9614 \end_layout
9615
9616 \end_inset
9617
9618 -disable-warning\InsetSpace ~
9619 <nnnn>
9620 \begin_inset LatexCommand \index{-\/-disable-warning}
9621
9622 \end_inset
9623
9624
9625 \series default
9626  Disable specific warning with number <nnnn>.
9627 \end_layout
9628
9629 \begin_layout List
9630 \labelwidthstring 00.00.0000
9631
9632 \series bold
9633 -
9634 \begin_inset ERT
9635 status collapsed
9636
9637 \begin_layout Standard
9638
9639
9640 \backslash
9641 /
9642 \end_layout
9643
9644 \end_inset
9645
9646 -print-search-dirs
9647 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9648
9649 \end_inset
9650
9651
9652 \series default
9653  Display the directories in the compiler's search path
9654 \end_layout
9655
9656 \begin_layout List
9657 \labelwidthstring 00.00.0000
9658
9659 \series bold
9660 -
9661 \begin_inset ERT
9662 status collapsed
9663
9664 \begin_layout Standard
9665
9666
9667 \backslash
9668 /
9669 \end_layout
9670
9671 \end_inset
9672
9673 -vc
9674 \begin_inset LatexCommand \index{-\/-vc}
9675
9676 \end_inset
9677
9678
9679 \series default
9680  Display errors and warnings using MSVC style, so you can use SDCC with
9681  the visual studio IDE
9682 \begin_inset LatexCommand \index{IDE}
9683
9684 \end_inset
9685
9686 .
9687  With SDCC both offering a GCC-like (the default) and a MSVC-like
9688 \begin_inset LatexCommand \index{MSVC output style}
9689
9690 \end_inset
9691
9692  output style, integration into most programming editors should be straightforwa
9693 rd.
9694 \end_layout
9695
9696 \begin_layout List
9697 \labelwidthstring 00.00.0000
9698
9699 \series bold
9700 -
9701 \begin_inset ERT
9702 status collapsed
9703
9704 \begin_layout Standard
9705
9706
9707 \backslash
9708 /
9709 \end_layout
9710
9711 \end_inset
9712
9713 -use-stdout
9714 \begin_inset LatexCommand \index{-\/-use-stdout}
9715
9716 \end_inset
9717
9718
9719 \series default
9720  Send errors and warnings to stdout instead of stderr.
9721 \end_layout
9722
9723 \begin_layout List
9724 \labelwidthstring 00.00.0000
9725
9726 \series bold
9727 -Wa\InsetSpace ~
9728 asmOption[,asmOption]
9729 \series default
9730
9731 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9732
9733 \end_inset
9734
9735 ...
9736  Pass the asmOption to the assembler
9737 \begin_inset LatexCommand \index{Options assembler}
9738
9739 \end_inset
9740
9741
9742 \begin_inset LatexCommand \index{Assembler options}
9743
9744 \end_inset
9745
9746 .
9747  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9748 \end_layout
9749
9750 \begin_layout List
9751 \labelwidthstring 00.00.0000
9752
9753 \series bold
9754 -
9755 \begin_inset ERT
9756 status collapsed
9757
9758 \begin_layout Standard
9759
9760
9761 \backslash
9762 /
9763 \end_layout
9764
9765 \end_inset
9766
9767 -std-sdcc89
9768 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9769
9770 \end_inset
9771
9772
9773 \series default
9774  Generally follow the C89 standard, but allow SDCC features that conflict
9775  with the standard (default).
9776 \end_layout
9777
9778 \begin_layout List
9779 \labelwidthstring 00.00.0000
9780
9781 \series bold
9782 -
9783 \begin_inset ERT
9784 status collapsed
9785
9786 \begin_layout Standard
9787
9788
9789 \backslash
9790 /
9791 \end_layout
9792
9793 \end_inset
9794
9795 -std-c89
9796 \begin_inset LatexCommand \index{-\/-std-c89}
9797
9798 \end_inset
9799
9800
9801 \series default
9802  Follow the C89 standard and disable SDCC features that conflict with the
9803  standard.
9804 \end_layout
9805
9806 \begin_layout List
9807 \labelwidthstring 00.00.0000
9808
9809 \series bold
9810 -
9811 \begin_inset ERT
9812 status collapsed
9813
9814 \begin_layout Standard
9815
9816
9817 \backslash
9818 /
9819 \end_layout
9820
9821 \end_inset
9822
9823 -std-sdcc99
9824 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9825
9826 \end_inset
9827
9828
9829 \series default
9830  Generally follow the C99 standard, but allow SDCC features that conflict
9831  with the standard (incomplete support).
9832 \end_layout
9833
9834 \begin_layout List
9835 \labelwidthstring 00.00.0000
9836
9837 \series bold
9838 -
9839 \begin_inset ERT
9840 status collapsed
9841
9842 \begin_layout Standard
9843
9844
9845 \backslash
9846 /
9847 \end_layout
9848
9849 \end_inset
9850
9851 -std-c99
9852 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9853
9854 \end_inset
9855
9856
9857 \series default
9858  Follow the C99 standard and disable SDCC features that conflict with the
9859  standard (incomplete support).
9860 \end_layout
9861
9862 \begin_layout List
9863 \labelwidthstring 00.00.0000
9864
9865 \series bold
9866 -
9867 \begin_inset ERT
9868 status collapsed
9869
9870 \begin_layout Standard
9871
9872
9873 \backslash
9874 /
9875 \end_layout
9876
9877 \end_inset
9878
9879 -codeseg
9880 \series default
9881
9882 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9883
9884 \end_inset
9885
9886 \InsetSpace ~
9887 <Name> The name to be used for the code
9888 \begin_inset LatexCommand \index{code}
9889
9890 \end_inset
9891
9892  segment, default CSEG.
9893  This is useful if you need to tell the compiler to put the code in a special
9894  segment so you can later on tell the linker to put this segment in a special
9895  place in memory.
9896  Can be used for instance when using bank switching to put the code in a
9897  bank.
9898 \end_layout
9899
9900 \begin_layout List
9901 \labelwidthstring 00.00.0000
9902
9903 \series bold
9904 -
9905 \begin_inset ERT
9906 status collapsed
9907
9908 \begin_layout Standard
9909
9910
9911 \backslash
9912 /
9913 \end_layout
9914
9915 \end_inset
9916
9917 -constseg
9918 \series default
9919
9920 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9921
9922 \end_inset
9923
9924 \InsetSpace ~
9925 <Name> The name to be used for the const
9926 \begin_inset LatexCommand \index{code}
9927
9928 \end_inset
9929
9930  segment, default CONST.
9931  This is useful if you need to tell the compiler to put the const data in
9932  a special segment so you can later on tell the linker to put this segment
9933  in a special place in memory.
9934  Can be used for instance when using bank switching to put the const data
9935  in a bank.
9936 \end_layout
9937
9938 \begin_layout List
9939 \labelwidthstring 00.00.0000
9940
9941 \series bold
9942 -
9943 \begin_inset ERT
9944 status collapsed
9945
9946 \begin_layout Standard
9947
9948
9949 \backslash
9950 /
9951 \end_layout
9952
9953 \end_inset
9954
9955 -fdollars-in-identifiers
9956 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9957
9958 \end_inset
9959
9960
9961 \series default
9962  Permit '$' as an identifier character
9963 \end_layout
9964
9965 \begin_layout List
9966 \labelwidthstring 00.00.0000
9967
9968 \series bold
9969 more-pedantic
9970 \series default
9971  Actually this is 
9972 \series bold
9973 \emph on
9974 not
9975 \series default
9976 \emph default
9977  a SDCC compiler option but if you want 
9978 \emph on
9979 more
9980 \emph default
9981  warnings you can use a separate tool dedicated to syntax checking like
9982  splint
9983 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9984
9985 \end_inset
9986
9987
9988 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9989
9990 \end_inset
9991
9992  
9993 \begin_inset LatexCommand \url{http://www.splint.org}
9994
9995 \end_inset
9996
9997 .
9998  To make your source files parseable by splint you will have to include
9999  
10000 \family sans
10001 lint.h
10002 \family default
10003
10004 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10005
10006 \end_inset
10007
10008  in your source file and add brackets around extended keywords (like 
10009 \family sans
10010
10011 \begin_inset Quotes sld
10012 \end_inset
10013
10014 __at\InsetSpace ~
10015
10016 \series bold
10017 (
10018 \series default
10019 0xab
10020 \series bold
10021 )
10022 \series default
10023
10024 \begin_inset Quotes srd
10025 \end_inset
10026
10027
10028 \family default
10029  and 
10030 \family sans
10031
10032 \begin_inset Quotes sld
10033 \end_inset
10034
10035 __interrupt\InsetSpace ~
10036 (2)
10037 \begin_inset Quotes srd
10038 \end_inset
10039
10040
10041 \family default
10042 ).
10043  
10044 \newline
10045 Splint has an excellent on line manual at 
10046 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10047
10048 \end_inset
10049
10050  and it's capabilities go beyond pure syntax checking.
10051  You'll need to tell splint the location of SDCC's include files so a typical
10052  command line could look like this: 
10053 \newline
10054
10055 \family sans
10056 splint\InsetSpace ~
10057 -I\InsetSpace ~
10058 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10059 \InsetSpace ~
10060 myprogram.c
10061 \end_layout
10062
10063 \begin_layout Standard
10064 \begin_inset VSpace bigskip
10065 \end_inset
10066
10067
10068 \end_layout
10069
10070 \begin_layout Subsection
10071 Intermediate Dump Options
10072 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10073
10074 \end_inset
10075
10076
10077 \begin_inset LatexCommand \index{Options intermediate dump}
10078
10079 \end_inset
10080
10081
10082 \begin_inset LatexCommand \index{Intermediate dump options}
10083
10084 \end_inset
10085
10086
10087 \end_layout
10088
10089 \begin_layout Standard
10090 The following options are provided for the purpose of retargetting and debugging
10091  the compiler.
10092  They provide a means to dump the intermediate code (iCode
10093 \begin_inset LatexCommand \index{iCode}
10094
10095 \end_inset
10096
10097 ) generated by the compiler in human readable form at various stages of
10098  the compilation process.
10099  More on iCodes see chapter 
10100 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10101
10102 \end_inset
10103
10104  
10105 \begin_inset Quotes srd
10106 \end_inset
10107
10108 The anatomy of the compiler
10109 \begin_inset Quotes srd
10110 \end_inset
10111
10112 .
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 -dumpraw
10133 \begin_inset LatexCommand \index{-\/-dumpraw}
10134
10135 \end_inset
10136
10137
10138 \series default
10139  This option will cause the compiler to dump the intermediate code into
10140  a file of named 
10141 \emph on
10142 <source filename>.dumpraw
10143 \emph default
10144  just after the intermediate code has been generated for a function, i.e.
10145  before any optimizations are done.
10146  The basic blocks
10147 \begin_inset LatexCommand \index{Basic blocks}
10148
10149 \end_inset
10150
10151  at this stage ordered in the depth first number, so they may not be in
10152  sequence of execution.
10153 \end_layout
10154
10155 \begin_layout List
10156 \labelwidthstring 00.00.0000
10157
10158 \series bold
10159 -
10160 \begin_inset ERT
10161 status collapsed
10162
10163 \begin_layout Standard
10164
10165
10166 \backslash
10167 /
10168 \end_layout
10169
10170 \end_inset
10171
10172 -dumpgcse
10173 \begin_inset LatexCommand \index{-\/-dumpgcse}
10174
10175 \end_inset
10176
10177
10178 \series default
10179  Will create a dump of iCode's, after global subexpression elimination
10180 \begin_inset LatexCommand \index{Global subexpression elimination}
10181
10182 \end_inset
10183
10184 , into a file named 
10185 \emph on
10186 <source filename>.dumpgcse.
10187 \end_layout
10188
10189 \begin_layout List
10190 \labelwidthstring 00.00.0000
10191
10192 \series bold
10193 -
10194 \begin_inset ERT
10195 status collapsed
10196
10197 \begin_layout Standard
10198
10199
10200 \backslash
10201 /
10202 \end_layout
10203
10204 \end_inset
10205
10206 -dumpdeadcode
10207 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10208
10209 \end_inset
10210
10211
10212 \series default
10213  Will create a dump of iCode's, after deadcode elimination
10214 \begin_inset LatexCommand \index{Dead-code elimination}
10215
10216 \end_inset
10217
10218 , into a file named 
10219 \emph on
10220 <source filename>.dumpdeadcode.
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 -dumploop
10241 \begin_inset LatexCommand \index{-\/-dumploop}
10242
10243 \end_inset
10244
10245
10246 \series default
10247 \size large
10248  
10249 \size default
10250 Will create a dump of iCode's, after loop optimizations
10251 \begin_inset LatexCommand \index{Loop optimization}
10252
10253 \end_inset
10254
10255 , into a file named 
10256 \emph on
10257 <source filename>.dumploop.
10258 \end_layout
10259
10260 \begin_layout List
10261 \labelwidthstring 00.00.0000
10262
10263 \series bold
10264 -
10265 \begin_inset ERT
10266 status collapsed
10267
10268 \begin_layout Standard
10269
10270
10271 \backslash
10272 /
10273 \end_layout
10274
10275 \end_inset
10276
10277 -dumprange
10278 \begin_inset LatexCommand \index{-\/-dumprange}
10279
10280 \end_inset
10281
10282
10283 \series default
10284 \size large
10285  
10286 \size default
10287 Will create a dump of iCode's, after live range analysis
10288 \begin_inset LatexCommand \index{Live range analysis}
10289
10290 \end_inset
10291
10292 , into a file named 
10293 \emph on
10294 <source filename>.dumprange.
10295 \end_layout
10296
10297 \begin_layout List
10298 \labelwidthstring 00.00.0000
10299
10300 \series bold
10301 -
10302 \begin_inset ERT
10303 status collapsed
10304
10305 \begin_layout Standard
10306
10307
10308 \backslash
10309 /
10310 \end_layout
10311
10312 \end_inset
10313
10314 -dumlrange
10315 \begin_inset LatexCommand \index{-\/-dumlrange}
10316
10317 \end_inset
10318
10319
10320 \series default
10321  Will dump the life ranges
10322 \begin_inset LatexCommand \index{Live range analysis}
10323
10324 \end_inset
10325
10326  for all symbols.
10327 \end_layout
10328
10329 \begin_layout List
10330 \labelwidthstring 00.00.0000
10331
10332 \series bold
10333 -
10334 \begin_inset ERT
10335 status collapsed
10336
10337 \begin_layout Standard
10338
10339
10340 \backslash
10341 /
10342 \end_layout
10343
10344 \end_inset
10345
10346 -dumpregassign
10347 \begin_inset LatexCommand \index{-\/-dumpregassign}
10348
10349 \end_inset
10350
10351
10352 \bar under
10353  
10354 \series default
10355 \bar default
10356 Will create a dump of iCode's, after register assignment
10357 \begin_inset LatexCommand \index{Register assignment}
10358
10359 \end_inset
10360
10361 , into a file named 
10362 \emph on
10363 <source filename>.dumprassgn.
10364 \end_layout
10365
10366 \begin_layout List
10367 \labelwidthstring 00.00.0000
10368
10369 \series bold
10370 -
10371 \begin_inset ERT
10372 status collapsed
10373
10374 \begin_layout Standard
10375
10376
10377 \backslash
10378 /
10379 \end_layout
10380
10381 \end_inset
10382
10383 -dumplrange
10384 \begin_inset LatexCommand \index{-\/-dumplrange}
10385
10386 \end_inset
10387
10388
10389 \series default
10390  Will create a dump of the live ranges of iTemp's
10391 \end_layout
10392
10393 \begin_layout List
10394 \labelwidthstring 00.00.0000
10395
10396 \series bold
10397 -
10398 \begin_inset ERT
10399 status collapsed
10400
10401 \begin_layout Standard
10402
10403
10404 \backslash
10405 /
10406 \end_layout
10407
10408 \end_inset
10409
10410 -dumpall
10411 \begin_inset LatexCommand \index{-\/-dumpall}
10412
10413 \end_inset
10414
10415
10416 \size large
10417 \bar under
10418  
10419 \series default
10420 \size default
10421 \bar default
10422 Will cause all the above mentioned dumps to be created.
10423 \end_layout
10424
10425 \begin_layout Standard
10426 \begin_inset VSpace bigskip
10427 \end_inset
10428
10429
10430 \end_layout
10431
10432 \begin_layout Subsection
10433 Redirecting output on Windows Shells
10434 \end_layout
10435
10436 \begin_layout Standard
10437 By default SDCC writes it's error messages to 
10438 \begin_inset Quotes sld
10439 \end_inset
10440
10441 standard error
10442 \begin_inset Quotes srd
10443 \end_inset
10444
10445 .
10446  To force all messages to 
10447 \begin_inset Quotes sld
10448 \end_inset
10449
10450 standard output
10451 \begin_inset Quotes srd
10452 \end_inset
10453
10454  use 
10455 \series bold
10456 -
10457 \series default
10458 \emph on
10459
10460 \begin_inset ERT
10461 status collapsed
10462
10463 \begin_layout Standard
10464
10465
10466 \backslash
10467 /
10468 \end_layout
10469
10470 \end_inset
10471
10472
10473 \series bold
10474 \emph default
10475 -
10476 \series default
10477 use-stdout
10478 \begin_inset LatexCommand \index{-\/-use-stdout}
10479
10480 \end_inset
10481
10482 .
10483  Additionally, if you happen to have visual studio installed in your windows
10484  machine, you can use it to compile your sources using a custom build and
10485  the SDCC -
10486 \emph on
10487
10488 \begin_inset ERT
10489 status collapsed
10490
10491 \begin_layout Standard
10492
10493
10494 \backslash
10495 /
10496 \end_layout
10497
10498 \end_inset
10499
10500
10501 \emph default
10502 -vc
10503 \begin_inset LatexCommand \index{-\/-vc}
10504
10505 \end_inset
10506
10507  option.
10508  Something like this should work:
10509 \newline
10510
10511 \newline
10512
10513 \series bold
10514 c:
10515 \backslash
10516 sdcc
10517 \backslash
10518 bin
10519 \backslash
10520 sdcc.exe -
10521 \series default
10522 \emph on
10523
10524 \begin_inset ERT
10525 status collapsed
10526
10527 \begin_layout Standard
10528
10529
10530 \backslash
10531 /
10532 \end_layout
10533
10534 \end_inset
10535
10536
10537 \series bold
10538 \emph default
10539 -vc -
10540 \series default
10541 \emph on
10542
10543 \begin_inset ERT
10544 status collapsed
10545
10546 \begin_layout Standard
10547
10548
10549 \backslash
10550 /
10551 \end_layout
10552
10553 \end_inset
10554
10555
10556 \series bold
10557 \emph default
10558 -model-large -c $(InputPath)
10559 \series default
10560
10561 \begin_inset VSpace bigskip
10562 \end_inset
10563
10564
10565 \end_layout
10566
10567 \begin_layout Section
10568 Environment variables
10569 \begin_inset LatexCommand \index{Environment variables}
10570
10571 \end_inset
10572
10573
10574 \end_layout
10575
10576 \begin_layout Standard
10577 SDCC recognizes the following environment variables:
10578 \end_layout
10579
10580 \begin_layout List
10581 \labelwidthstring 00.00.0000
10582
10583 \series bold
10584 SDCC_LEAVE_SIGNALS
10585 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10586
10587 \end_inset
10588
10589
10590 \series default
10591  SDCC installs a signal handler
10592 \begin_inset LatexCommand \index{signal handler}
10593
10594 \end_inset
10595
10596  to be able to delete temporary files after an user break (^C) or an exception.
10597  If this environment variable is set, SDCC won't install the signal handler
10598  in order to be able to debug SDCC.
10599 \end_layout
10600
10601 \begin_layout List
10602 \labelwidthstring 00.00.0000
10603
10604 \series bold
10605 TMP,\InsetSpace ~
10606 TEMP,\InsetSpace ~
10607 TMPDIR
10608 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10609
10610 \end_inset
10611
10612
10613 \series default
10614  Path, where temporary files will be created.
10615  The order of the variables is the search order.
10616  In a standard *nix environment these variables are not set, and there's
10617  no need to set them.
10618  On Windows it's recommended to set one of them.
10619 \end_layout
10620
10621 \begin_layout List
10622 \labelwidthstring 00.00.0000
10623
10624 \series bold
10625 SDCC_HOME
10626 \begin_inset LatexCommand \index{SDCC\_HOME}
10627
10628 \end_inset
10629
10630
10631 \series default
10632  Path, see section 
10633 \begin_inset LatexCommand \ref{sub:Install-paths}
10634
10635 \end_inset
10636
10637 \InsetSpace ~
10638
10639 \begin_inset Quotes sld
10640 \end_inset
10641
10642  Install Paths
10643 \begin_inset Quotes srd
10644 \end_inset
10645
10646 .
10647 \end_layout
10648
10649 \begin_layout List
10650 \labelwidthstring 00.00.0000
10651
10652 \series bold
10653 SDCC_INCLUDE
10654 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10655
10656 \end_inset
10657
10658
10659 \series default
10660  Path, see section 
10661 \begin_inset LatexCommand \ref{sub:Search-Paths}
10662
10663 \end_inset
10664
10665 \InsetSpace ~
10666
10667 \begin_inset Quotes sld
10668 \end_inset
10669
10670 Search Paths
10671 \begin_inset Quotes srd
10672 \end_inset
10673
10674 .
10675 \end_layout
10676
10677 \begin_layout List
10678 \labelwidthstring 00.00.0000
10679
10680 \series bold
10681 SDCC_LIB
10682 \begin_inset LatexCommand \index{SDCC\_LIB}
10683
10684 \end_inset
10685
10686
10687 \series default
10688  Path, see section 
10689 \begin_inset LatexCommand \ref{sub:Search-Paths}
10690
10691 \end_inset
10692
10693 \InsetSpace ~
10694
10695 \begin_inset Quotes sld
10696 \end_inset
10697
10698 Search Paths
10699 \begin_inset Quotes srd
10700 \end_inset
10701
10702 ..
10703 \end_layout
10704
10705 \begin_layout Standard
10706 There are some more environment variables recognized by SDCC, but these
10707  are solely used for debugging purposes.
10708  They can change or disappear very quickly, and will never be documented.
10709 \begin_inset VSpace bigskip
10710 \end_inset
10711
10712
10713 \end_layout
10714
10715 \begin_layout Section
10716 Storage Class Language Extensions
10717 \end_layout
10718
10719 \begin_layout Subsection
10720 MCS51/DS390 Storage Class
10721 \begin_inset LatexCommand \index{Storage class}
10722
10723 \end_inset
10724
10725  Language Extensions
10726 \end_layout
10727
10728 \begin_layout Standard
10729 In addition to the ANSI storage classes SDCC allows the following MCS51
10730  specific storage classes:
10731 \end_layout
10732
10733 \begin_layout Subsubsection
10734 data
10735 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10736
10737 \end_inset
10738
10739
10740 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10741
10742 \end_inset
10743
10744  / near
10745 \begin_inset LatexCommand \index{near (storage class)}
10746
10747 \end_inset
10748
10749
10750 \begin_inset LatexCommand \index{\_\_near (storage class)}
10751
10752 \end_inset
10753
10754
10755 \end_layout
10756
10757 \begin_layout Standard
10758 This is the 
10759 \series bold
10760 default
10761 \series default
10762  storage class for the Small Memory model (
10763 \emph on
10764 data
10765 \emph default
10766  and 
10767 \emph on
10768 near
10769 \emph default
10770  or the more ANSI-C compliant forms 
10771 \emph on
10772 __data
10773 \emph default
10774  and 
10775 \emph on
10776 __near
10777 \emph default
10778  can be used synonymously).
10779  Variables declared with this storage class will be allocated in the directly
10780  addressable portion of the internal RAM of a 8051, e.g.:
10781 \end_layout
10782
10783 \begin_layout Verse
10784
10785 \family typewriter
10786 __data unsigned char test_data;
10787 \end_layout
10788
10789 \begin_layout Standard
10790 Writing 0x01 to this variable generates the assembly code:
10791 \end_layout
10792
10793 \begin_layout Verse
10794
10795 \family typewriter
10796 75*00 01\InsetSpace ~
10797 \InsetSpace ~
10798 \InsetSpace ~
10799 mov\InsetSpace ~
10800 \InsetSpace ~
10801 _test_data,#0x01
10802 \end_layout
10803
10804 \begin_layout Subsubsection
10805 xdata
10806 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10807
10808 \end_inset
10809
10810
10811 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10812
10813 \end_inset
10814
10815  / far
10816 \begin_inset LatexCommand \index{far (storage class)}
10817
10818 \end_inset
10819
10820
10821 \begin_inset LatexCommand \index{\_\_far (storage class)}
10822
10823 \end_inset
10824
10825
10826 \end_layout
10827
10828 \begin_layout Standard
10829 Variables declared with this storage class will be placed in the external
10830  RAM.
10831  This is the 
10832 \series bold
10833 default
10834 \series default
10835  storage class for the Large Memory model, e.g.:
10836 \end_layout
10837
10838 \begin_layout Verse
10839
10840 \family typewriter
10841 __xdata unsigned char test_xdata;
10842 \end_layout
10843
10844 \begin_layout Standard
10845 Writing 0x01 to this variable generates the assembly code:
10846 \end_layout
10847
10848 \begin_layout Verse
10849
10850 \family typewriter
10851 90s00r00\InsetSpace ~
10852 \InsetSpace ~
10853 \InsetSpace ~
10854 mov\InsetSpace ~
10855 \InsetSpace ~
10856 dptr,#_test_xdata 
10857 \newline
10858 74\InsetSpace ~
10859 01\InsetSpace ~
10860 \InsetSpace ~
10861 \InsetSpace ~
10862 \InsetSpace ~
10863 \InsetSpace ~
10864 \InsetSpace ~
10865 mov\InsetSpace ~
10866 \InsetSpace ~
10867 a,#0x01 
10868 \newline
10869 F0\InsetSpace ~
10870 \InsetSpace ~
10871 \InsetSpace ~
10872 \InsetSpace ~
10873 \InsetSpace ~
10874 \InsetSpace ~
10875 \InsetSpace ~
10876 \InsetSpace ~
10877 \InsetSpace ~
10878 movx\InsetSpace ~
10879 @dptr,a 
10880 \end_layout
10881
10882 \begin_layout Subsubsection
10883 idata
10884 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10885
10886 \end_inset
10887
10888
10889 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10890
10891 \end_inset
10892
10893
10894 \end_layout
10895
10896 \begin_layout Standard
10897 Variables declared with this storage class will be allocated into the indirectly
10898  addressable portion of the internal ram of a 8051, e.g.:
10899 \end_layout
10900
10901 \begin_layout Verse
10902
10903 \family typewriter
10904 __idata unsigned char test_idata;
10905 \end_layout
10906
10907 \begin_layout Standard
10908 Writing 0x01 to this variable generates the assembly code:
10909 \end_layout
10910
10911 \begin_layout Verse
10912
10913 \family typewriter
10914 78r00\InsetSpace ~
10915 \InsetSpace ~
10916 \InsetSpace ~
10917 \InsetSpace ~
10918 \InsetSpace ~
10919 \InsetSpace ~
10920 \InsetSpace ~
10921 mov\InsetSpace ~
10922 \InsetSpace ~
10923 r0,#_test_idata
10924 \newline
10925 76\InsetSpace ~
10926 01\InsetSpace ~
10927 \InsetSpace ~
10928 \InsetSpace ~
10929 \InsetSpace ~
10930 \InsetSpace ~
10931 \InsetSpace ~
10932 \InsetSpace ~
10933 mov\InsetSpace ~
10934 \InsetSpace ~
10935 @r0,#0x01
10936 \end_layout
10937
10938 \begin_layout Standard
10939 Please note, the first 128 byte of idata physically access the same RAM
10940  as the data memory.
10941  The original 8051 had 128 byte idata memory, nowadays most devices have
10942  256 byte idata memory.
10943  The stack
10944 \begin_inset LatexCommand \index{stack}
10945
10946 \end_inset
10947
10948  is located in idata memory.
10949 \end_layout
10950
10951 \begin_layout Subsubsection
10952 pdata
10953 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10954
10955 \end_inset
10956
10957
10958 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10959
10960 \end_inset
10961
10962
10963 \end_layout
10964
10965 \begin_layout Standard
10966 Paged xdata access is just as straightforward as using the other addressing
10967  modes of a 8051.
10968  It is typically located at the start of xdata and has a maximum size of
10969  256 bytes.
10970  The following example writes 0x01 to the pdata variable.
10971  Please note, pdata access physically accesses xdata memory.
10972  The high byte of the address is determined by port P2 
10973 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10974
10975 \end_inset
10976
10977 (or in case of some 8051 variants by a separate Special Function Register,
10978  see section 
10979 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10980
10981 \end_inset
10982
10983 ).
10984  This is the 
10985 \series bold
10986 default
10987 \series default
10988  storage class for the Medium Memory model, e.g.:
10989 \end_layout
10990
10991 \begin_layout Verse
10992
10993 \family typewriter
10994 __pdata unsigned char test_pdata;
10995 \end_layout
10996
10997 \begin_layout Standard
10998 Writing 0x01 to this variable generates the assembly code:
10999 \end_layout
11000
11001 \begin_layout Verse
11002
11003 \family typewriter
11004 78r00\InsetSpace ~
11005 \InsetSpace ~
11006 \InsetSpace ~
11007 \InsetSpace ~
11008 \InsetSpace ~
11009 \InsetSpace ~
11010 mov r0,#_test_pdata
11011 \newline
11012 74 01\InsetSpace ~
11013 \InsetSpace ~
11014 \InsetSpace ~
11015 \InsetSpace ~
11016 \InsetSpace ~
11017 \InsetSpace ~
11018 mov a,#0x01 
11019 \newline
11020 F2\InsetSpace ~
11021 \InsetSpace ~
11022 \InsetSpace ~
11023 \InsetSpace ~
11024 \InsetSpace ~
11025 \InsetSpace ~
11026 \InsetSpace ~
11027 \InsetSpace ~
11028 \InsetSpace ~
11029 movx @r0,a
11030 \end_layout
11031
11032 \begin_layout Standard
11033 If the -
11034 \begin_inset ERT
11035 status collapsed
11036
11037 \begin_layout Standard
11038
11039
11040 \backslash
11041 /
11042 \end_layout
11043
11044 \end_inset
11045
11046 -xstack
11047 \begin_inset LatexCommand \index{-\/-xstack}
11048
11049 \end_inset
11050
11051  option is used the pdata memory area is followed by the xstack memory area
11052  and the sum of their sizes is limited to 256 bytes.
11053 \end_layout
11054
11055 \begin_layout Subsubsection
11056 code
11057 \begin_inset LatexCommand \index{code}
11058
11059 \end_inset
11060
11061
11062 \begin_inset LatexCommand \index{\_\_code}
11063
11064 \end_inset
11065
11066
11067 \end_layout
11068
11069 \begin_layout Standard
11070 'Variables' declared with this storage class will be placed in the code
11071  memory:
11072 \end_layout
11073
11074 \begin_layout Verse
11075
11076 \family typewriter
11077 __code unsigned char test_code;
11078 \end_layout
11079
11080 \begin_layout Standard
11081 Read access to this variable generates the assembly code:
11082 \end_layout
11083
11084 \begin_layout Verse
11085
11086 \family typewriter
11087 90s00r6F\InsetSpace ~
11088 \InsetSpace ~
11089 \InsetSpace ~
11090 mov dptr,#_test_code
11091 \newline
11092 E4\InsetSpace ~
11093 \InsetSpace ~
11094 \InsetSpace ~
11095 \InsetSpace ~
11096 \InsetSpace ~
11097 \InsetSpace ~
11098 \InsetSpace ~
11099 \InsetSpace ~
11100 \InsetSpace ~
11101 clr a
11102 \newline
11103 93\InsetSpace ~
11104 \InsetSpace ~
11105 \InsetSpace ~
11106 \InsetSpace ~
11107 \InsetSpace ~
11108 \InsetSpace ~
11109 \InsetSpace ~
11110 \InsetSpace ~
11111 \InsetSpace ~
11112 movc a,@a+dptr 
11113 \end_layout
11114
11115 \begin_layout Standard
11116
11117 \family typewriter
11118 char
11119 \family default
11120  indexed arrays of characters in code memory can be accessed efficiently:
11121 \end_layout
11122
11123 \begin_layout Verse
11124
11125 \family typewriter
11126 __code char test_array[] = {'c','h','e','a','p'}; 
11127 \end_layout
11128
11129 \begin_layout Standard
11130 Read access to this array using an 8-bit unsigned index generates the assembly
11131  code:
11132 \end_layout
11133
11134 \begin_layout Verse
11135
11136 \family typewriter
11137 E5*00\InsetSpace ~
11138 \InsetSpace ~
11139 \InsetSpace ~
11140 \InsetSpace ~
11141 \InsetSpace ~
11142 \InsetSpace ~
11143 mov a,_index 
11144 \end_layout
11145
11146 \begin_layout Verse
11147
11148 \family typewriter
11149 90s00r41\InsetSpace ~
11150 \InsetSpace ~
11151 \InsetSpace ~
11152 mov dptr,#_test_array
11153 \end_layout
11154
11155 \begin_layout Verse
11156
11157 \family typewriter
11158 93\InsetSpace ~
11159 \InsetSpace ~
11160 \InsetSpace ~
11161 \InsetSpace ~
11162 \InsetSpace ~
11163 \InsetSpace ~
11164 \InsetSpace ~
11165 \InsetSpace ~
11166 \InsetSpace ~
11167 movc a,@a+dptr 
11168 \end_layout
11169
11170 \begin_layout Subsubsection
11171 bit
11172 \begin_inset LatexCommand \index{bit}
11173
11174 \end_inset
11175
11176
11177 \begin_inset LatexCommand \index{\_\_bit}
11178
11179 \end_inset
11180
11181
11182 \end_layout
11183
11184 \begin_layout Standard
11185 This is a data-type and a storage class specifier.
11186  When a variable is declared as a bit, it is allocated into the bit addressable
11187  memory of 8051, e.g.:
11188 \end_layout
11189
11190 \begin_layout Verse
11191
11192 \family typewriter
11193 __bit test_bit;
11194 \end_layout
11195
11196 \begin_layout Standard
11197 Writing 1 to this variable generates the assembly code:
11198 \end_layout
11199
11200 \begin_layout Verse
11201
11202 \family typewriter
11203 D2*00\InsetSpace ~
11204 \InsetSpace ~
11205 \InsetSpace ~
11206 \InsetSpace ~
11207 \InsetSpace ~
11208 \InsetSpace ~
11209 \InsetSpace ~
11210 setb\InsetSpace ~
11211 _test_bit
11212 \end_layout
11213
11214 \begin_layout Standard
11215 The bit addressable memory consists of 128 bits which are located from 0x20
11216  to 0x2f in data memory.
11217  
11218 \newline
11219 Apart from this 8051 specific storage class most architectures support
11220  ANSI-C bitfields
11221 \begin_inset LatexCommand \index{bitfields}
11222
11223 \end_inset
11224
11225
11226 \begin_inset Foot
11227 status open
11228
11229 \begin_layout Standard
11230 Not really meant as examples, but nevertheless showing what bitfields are
11231  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11232 \end_layout
11233
11234 \end_inset
11235
11236 .
11237  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11238  signed modifier are implemented as unsigned.
11239 \end_layout
11240
11241 \begin_layout Subsubsection
11242 sfr
11243 \begin_inset LatexCommand \index{sfr}
11244
11245 \end_inset
11246
11247
11248 \begin_inset LatexCommand \index{\_\_sfr}
11249
11250 \end_inset
11251
11252  / sfr16
11253 \begin_inset LatexCommand \index{sfr16}
11254
11255 \end_inset
11256
11257
11258 \begin_inset LatexCommand \index{\_\_sfr16}
11259
11260 \end_inset
11261
11262  / sfr32
11263 \begin_inset LatexCommand \index{sfr32}
11264
11265 \end_inset
11266
11267
11268 \begin_inset LatexCommand \index{\_\_sfr32}
11269
11270 \end_inset
11271
11272  / sbit
11273 \begin_inset LatexCommand \index{\_\_sbit}
11274
11275 \end_inset
11276
11277
11278 \begin_inset LatexCommand \index{sbit}
11279
11280 \end_inset
11281
11282
11283 \end_layout
11284
11285 \begin_layout Standard
11286 Like the bit keyword, 
11287 \emph on
11288 sfr / sfr16 / sfr32 / sbit 
11289 \emph default
11290 signify both a data-type and storage class, they are used to describe the
11291  
11292 \emph on
11293 s
11294 \emph default
11295 pecial 
11296 \emph on
11297 f
11298 \emph default
11299 unction 
11300 \emph on
11301 r
11302 \emph default
11303 egisters and 
11304 \emph on
11305 s
11306 \emph default
11307 pecial 
11308 \emph on
11309 bit
11310 \emph default
11311  variables of a 8051, eg:
11312 \end_layout
11313
11314 \begin_layout Verse
11315
11316 \family typewriter
11317 __sfr __at
11318 \begin_inset LatexCommand \index{at}
11319
11320 \end_inset
11321
11322
11323 \begin_inset LatexCommand \index{\_\_at}
11324
11325 \end_inset
11326
11327  (0x80) P0;\InsetSpace ~
11328  /* special function register P0 at location 0x80 */
11329 \newline
11330
11331 \newline
11332 /* 16 bit
11333  special function register combination for timer 0
11334 \newline
11335 \InsetSpace ~
11336 \InsetSpace ~
11337  with the high byte at
11338  location 0x8C and the low byte at location 0x8A */
11339 \newline
11340 __sfr16 __at (0x8C8A)
11341  TMR0;
11342 \newline
11343
11344 \newline
11345 __sbit __at
11346 \begin_inset LatexCommand \index{at}
11347
11348 \end_inset
11349
11350
11351 \begin_inset LatexCommand \index{\_\_at}
11352
11353 \end_inset
11354
11355  (0xd7) CY;\InsetSpace ~
11356  /* CY (Carry Flag
11357 \begin_inset LatexCommand \index{Flags}
11358
11359 \end_inset
11360
11361
11362 \begin_inset LatexCommand \index{Carry flag}
11363
11364 \end_inset
11365
11366 ) */
11367 \end_layout
11368
11369 \begin_layout Standard
11370 Special function registers which are located on an address dividable by
11371  8 are bit-addressable, an
11372 \emph on
11373  sbit
11374 \emph default
11375  addresses a specific bit within these sfr.
11376 \newline
11377 16 Bit and 32 bit special function
11378  register combinations which require a certain access order are better not
11379  declared using 
11380 \emph on
11381 sfr16
11382 \emph default
11383  or 
11384 \emph on
11385 sfr32.
11386
11387 \emph default
11388  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11389  this is not guaranteed.
11390 \newline
11391
11392 \end_layout
11393
11394 \begin_layout Standard
11395 Please note, if you use a header file which was written for another compiler
11396  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11397  likely be 
11398 \emph on
11399 not 
11400 \emph default
11401 compatible.
11402  Specifically the syntax 
11403 \family typewriter
11404 \InsetSpace ~
11405 sfr P0 = 0x80;\InsetSpace ~
11406
11407 \family default
11408  is compiled 
11409 \emph on
11410 without warning
11411 \emph default
11412  by SDCC to an assignment of 0x80 to a variable called P0 
11413 \family typewriter
11414
11415 \begin_inset Marginal
11416 status collapsed
11417
11418 \begin_layout Standard
11419
11420 \series bold
11421 \InsetSpace ~
11422 !
11423 \end_layout
11424
11425 \end_inset
11426
11427 .
11428  
11429 \family default
11430 Nevertheless it is possible to write header files
11431 \begin_inset LatexCommand \index{Header files}
11432
11433 \end_inset
11434
11435
11436 \begin_inset LatexCommand \index{Include files}
11437
11438 \end_inset
11439
11440  which can be shared among different compilers (see section 
11441 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11442
11443 \end_inset
11444
11445 ).
11446  
11447 \end_layout
11448
11449 \begin_layout Subsubsection
11450 Pointers
11451 \begin_inset LatexCommand \index{Pointer}
11452
11453 \end_inset
11454
11455  to MCS51/DS390 specific memory spaces
11456 \end_layout
11457
11458 \begin_layout Standard
11459 SDCC allows (via language extensions) pointers to explicitly point to any
11460  of the memory spaces
11461 \begin_inset LatexCommand \index{Memory model}
11462
11463 \end_inset
11464
11465  of the 8051.
11466  In addition to the explicit pointers, the compiler uses (by default) generic
11467  pointers which can be used to point to any of the memory spaces.
11468 \newline
11469
11470 \newline
11471 Pointer
11472  declaration examples:
11473 \end_layout
11474
11475 \begin_layout Verse
11476
11477 \family typewriter
11478 /* pointer physically in internal ram pointing to object in external ram
11479  */ 
11480 \newline
11481 __xdata unsigned char * __data p;
11482 \newline
11483
11484 \newline
11485 /* pointer physically in external ram
11486  pointing to object in internal ram */ 
11487 \newline
11488 __data unsigned char * __xdata p;
11489 \newline
11490
11491 \newline
11492 /*
11493  pointer physically in code rom pointing to data in xdata space */ 
11494 \newline
11495 __xdata
11496  unsigned char * __code p;
11497 \newline
11498
11499 \newline
11500 /* pointer physically in code space pointing to
11501  data in code space */ 
11502 \newline
11503 __code unsigned char * __code p;
11504 \newline
11505
11506 \newline
11507 /* generic pointer
11508  physically located in xdata space */
11509 \newline
11510 unsigned char * __xdata p;
11511 \newline
11512
11513 \newline
11514 /* generic
11515  pointer physically located in default memory space */
11516 \newline
11517 unsigned char * p;
11518 \newline
11519
11520 \newline
11521 /*
11522  the following is a function pointer
11523 \begin_inset LatexCommand \index{function pointer}
11524
11525 \end_inset
11526
11527  physically located in data space */
11528 \newline
11529 char (* __data fp)(void);
11530 \end_layout
11531
11532 \begin_layout Standard
11533 Well you get the idea.
11534  
11535 \newline
11536
11537 \newline
11538 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
11539 \emph on
11540 generic
11541 \emph default
11542  pointers.
11543  
11544 \size small
11545
11546 \newline
11547
11548 \newline
11549
11550 \size default
11551 The highest order byte of the 
11552 \emph on
11553 generic
11554 \emph default
11555  pointers contains the data space information.
11556  Assembler support routines are called whenever data is stored or retrieved
11557  using 
11558 \emph on
11559 generic
11560 \emph default
11561  pointers.
11562  These are useful for developing reusable library
11563 \begin_inset LatexCommand \index{Libraries}
11564
11565 \end_inset
11566
11567  routines.
11568  Explicitly specifying the pointer
11569 \begin_inset LatexCommand \index{pointer}
11570
11571 \end_inset
11572
11573  type will generate the most efficient code.
11574 \end_layout
11575
11576 \begin_layout Subsubsection
11577 Notes on MCS51 memory
11578 \begin_inset LatexCommand \index{MCS51 memory}
11579
11580 \end_inset
11581
11582  layout
11583 \end_layout
11584
11585 \begin_layout Standard
11586 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11587  RAM memory which is structured as follows:
11588 \newline
11589
11590 \newline
11591 - Bytes 00-1F - 32 bytes to hold
11592  up to 4 banks of the registers R0 to R7, 
11593 \newline
11594 - Bytes 20-2F - 16 bytes to hold
11595  128 bit
11596 \begin_inset LatexCommand \index{bit}
11597
11598 \end_inset
11599
11600  variables and, 
11601 \newline
11602 - Bytes 30-7F - 80 bytes for general purpose use.
11603 \newline
11604
11605 \end_layout
11606
11607 \begin_layout Standard
11608 Additionally some members of the MCS51 family may have up to 128 bytes of
11609  additional, indirectly addressable, internal RAM memory (
11610 \emph on
11611 idata
11612 \emph default
11613
11614 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11615
11616 \end_inset
11617
11618
11619 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11620
11621 \end_inset
11622
11623 ).
11624  Furthermore, some chips may have some built in external memory (
11625 \emph on
11626 xdata
11627 \emph default
11628
11629 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11630
11631 \end_inset
11632
11633
11634 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11635
11636 \end_inset
11637
11638 ) which should not be confused with the internal, directly addressable RAM
11639  memory (
11640 \emph on
11641 data
11642 \emph default
11643
11644 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11645
11646 \end_inset
11647
11648
11649 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11650
11651 \end_inset
11652
11653 ).
11654  Sometimes this built in 
11655 \emph on
11656 xdata
11657 \emph default
11658  memory has to be activated before using it (you can probably find this
11659  information on the datasheet of the microcontroller your are using, see
11660  also section 
11661 \begin_inset LatexCommand \ref{sub:Startup-Code}
11662
11663 \end_inset
11664
11665 \InsetSpace ~
11666 Startup-Code).
11667 \end_layout
11668
11669 \begin_layout Standard
11670 Normally SDCC will only use the first bank
11671 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11672
11673 \end_inset
11674
11675  of registers (register bank 0), but it is possible to specify that other
11676  banks of registers (keyword 
11677 \emph on
11678 using
11679 \emph default
11680  
11681 \emph on
11682
11683 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11684
11685 \end_inset
11686
11687
11688 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11689
11690 \end_inset
11691
11692
11693 \emph default
11694 ) should be used in interrupt
11695 \begin_inset LatexCommand \index{interrupt}
11696
11697 \end_inset
11698
11699
11700 \begin_inset LatexCommand \index{\_\_interrupt}
11701
11702 \end_inset
11703
11704  routines.
11705  By default, the compiler will place the stack after the last byte of allocated
11706  memory for variables.
11707  For example, if the first 2 banks of registers are used, and only four
11708  bytes are used for 
11709 \emph on
11710 data
11711 \emph default
11712  variables, it will position the base of the internal stack at address 20
11713  (0x14).
11714  This implies that as the stack
11715 \begin_inset LatexCommand \index{stack}
11716
11717 \end_inset
11718
11719  grows, it will use up the remaining register banks, and the 16 bytes used
11720  by the 128 bit variables, and 80 bytes for general purpose use.
11721  If any bit variables are used, the data variables will be placed in unused
11722  register banks and after the byte holding the last bit variable.
11723  For example, if register banks 0 and 1 are used, and there are 9 bit variables
11724  (two bytes used), 
11725 \emph on
11726 data
11727 \emph default
11728  variables will be placed starting from address 0x10 to 0x20 and continue
11729  at address 0x22.
11730  You can also use -
11731 \begin_inset ERT
11732 status collapsed
11733
11734 \begin_layout Standard
11735
11736
11737 \backslash
11738 /
11739 \end_layout
11740
11741 \end_inset
11742
11743 -data-loc
11744 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11745
11746 \end_inset
11747
11748  to specify the start address of the 
11749 \emph on
11750 data
11751 \emph default
11752  and -
11753 \begin_inset ERT
11754 status collapsed
11755
11756 \begin_layout Standard
11757
11758
11759 \backslash
11760 /
11761 \end_layout
11762
11763 \end_inset
11764
11765 -iram-size
11766 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11767
11768 \end_inset
11769
11770  to specify the size of the total internal RAM (
11771 \emph on
11772 data
11773 \emph default
11774 +
11775 \emph on
11776 idata
11777 \emph default
11778 ).
11779  
11780 \newline
11781
11782 \end_layout
11783
11784 \begin_layout Standard
11785 By default the 8051 linker will place the stack after the last byte of (i)data
11786  variables.
11787  Option -
11788 \begin_inset ERT
11789 status collapsed
11790
11791 \begin_layout Standard
11792
11793
11794 \backslash
11795 /
11796 \end_layout
11797
11798 \end_inset
11799
11800 -stack-loc
11801 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
11802
11803 \end_inset
11804
11805  allows you to specify the start of the stack, i.e.
11806  you could start it after any data in the general purpose area.
11807  If your microcontroller has additional indirectly addressable internal
11808  RAM (
11809 \emph on
11810 idata
11811 \emph default
11812 ) you can place the stack on it.
11813  You may also need to use -
11814 \begin_inset ERT
11815 status collapsed
11816
11817 \begin_layout Standard
11818
11819
11820 \backslash
11821 /
11822 \end_layout
11823
11824 \end_inset
11825
11826 -xdata-loc
11827 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
11828
11829 \end_inset
11830
11831  to set the start address of the external RAM (
11832 \emph on
11833 xdata
11834 \emph default
11835 ) and -
11836 \begin_inset ERT
11837 status collapsed
11838
11839 \begin_layout Standard
11840
11841
11842 \backslash
11843 /
11844 \end_layout
11845
11846 \end_inset
11847
11848 -xram-size
11849 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
11850
11851 \end_inset
11852
11853  to specify its size.
11854  Same goes for the code memory, using -
11855 \begin_inset ERT
11856 status collapsed
11857
11858 \begin_layout Standard
11859
11860
11861 \backslash
11862 /
11863 \end_layout
11864
11865 \end_inset
11866
11867 -code-loc
11868 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
11869
11870 \end_inset
11871
11872  and -
11873 \begin_inset ERT
11874 status collapsed
11875
11876 \begin_layout Standard
11877
11878
11879 \backslash
11880 /
11881 \end_layout
11882
11883 \end_inset
11884
11885 -code-size
11886 \begin_inset LatexCommand \index{-\/-code-size <Value>}
11887
11888 \end_inset
11889
11890 .
11891  If in doubt, don't specify any options and see if the resulting memory
11892  layout is appropriate, then you can adjust it.
11893 \end_layout
11894
11895 \begin_layout Standard
11896 The linker generates two files with memory allocation information.
11897  The first, with extension .map
11898 \begin_inset LatexCommand \index{<file>.map}
11899
11900 \end_inset
11901
11902  shows all the variables and segments.
11903  The second with extension .mem
11904 \begin_inset LatexCommand \index{<file>.mem}
11905
11906 \end_inset
11907
11908  shows the final memory layout.
11909  The linker will complain either if memory segments overlap, there is not
11910  enough memory, or there is not enough space for stack.
11911  If you get any linking warnings and/or errors related to stack or segments
11912  allocation, take a look at either the .map or .mem files to find out what
11913  the problem is.
11914  The .mem file may even suggest a solution to the problem.
11915 \begin_inset VSpace bigskip
11916 \end_inset
11917
11918
11919 \end_layout
11920
11921 \begin_layout Subsection
11922 Z80/Z180 Storage Class
11923 \begin_inset LatexCommand \index{Z80!Storage class}
11924
11925 \end_inset
11926
11927  Language Extensions
11928 \end_layout
11929
11930 \begin_layout Subsubsection
11931 sfr
11932 \begin_inset LatexCommand \index{sfr}
11933
11934 \end_inset
11935
11936
11937 \begin_inset LatexCommand \index{\_\_sfr}
11938
11939 \end_inset
11940
11941  (in/out to 8-bit addresses)
11942 \end_layout
11943
11944 \begin_layout Standard
11945 The Z80
11946 \begin_inset LatexCommand \index{Z80}
11947
11948 \end_inset
11949
11950  family has separate address spaces for memory and 
11951 \emph on
11952 i
11953 \emph default
11954 nput/
11955 \emph on
11956 o
11957 \emph default
11958 utput memory.
11959  I/O memory
11960 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11961
11962 \end_inset
11963
11964
11965 \begin_inset LatexCommand \index{Z80!I/O memory}
11966
11967 \end_inset
11968
11969
11970 \begin_inset LatexCommand \index{Z180!I/O memory}
11971
11972 \end_inset
11973
11974  is accessed with special instructions, e.g.:
11975 \end_layout
11976
11977 \begin_layout Verse
11978
11979 \family typewriter
11980 sfr at 0x78 IoPort;\InsetSpace ~
11981 \InsetSpace ~
11982 /* define a var in I/O space at 78h called IoPort */
11983  
11984 \end_layout
11985
11986 \begin_layout Standard
11987 Writing 0x01 to this variable generates the assembly code:
11988 \end_layout
11989
11990 \begin_layout Verse
11991
11992 \family typewriter
11993 3E 01\InsetSpace ~
11994 \InsetSpace ~
11995 \InsetSpace ~
11996 \InsetSpace ~
11997 \InsetSpace ~
11998 \InsetSpace ~
11999 ld a,#0x01
12000 \newline
12001 D3 78\InsetSpace ~
12002 \InsetSpace ~
12003 \InsetSpace ~
12004 \InsetSpace ~
12005 \InsetSpace ~
12006 \InsetSpace ~
12007 out (_IoPort),a 
12008 \end_layout
12009
12010 \begin_layout Subsubsection
12011 banked sfr
12012 \begin_inset LatexCommand \index{sfr}
12013
12014 \end_inset
12015
12016
12017 \begin_inset LatexCommand \index{\_\_sfr}
12018
12019 \end_inset
12020
12021  (in/out to 16-bit addresses)
12022 \end_layout
12023
12024 \begin_layout Standard
12025 The keyword 
12026 \emph on
12027 banked
12028 \emph default
12029  is used to support 16 bit addresses in I/O memory e.g.:
12030 \end_layout
12031
12032 \begin_layout Verse
12033
12034 \family typewriter
12035 sfr banked at
12036 \begin_inset LatexCommand \index{at}
12037
12038 \end_inset
12039
12040
12041 \begin_inset LatexCommand \index{\_\_at}
12042
12043 \end_inset
12044
12045  0x123 IoPort; 
12046 \end_layout
12047
12048 \begin_layout Standard
12049 Writing 0x01 to this variable generates the assembly code:
12050 \end_layout
12051
12052 \begin_layout Verse
12053
12054 \family typewriter
12055 01 23 01\InsetSpace ~
12056 \InsetSpace ~
12057 \InsetSpace ~
12058 ld bc,#_IoPort
12059 \newline
12060 3E 01\InsetSpace ~
12061 \InsetSpace ~
12062 \InsetSpace ~
12063 \InsetSpace ~
12064 \InsetSpace ~
12065 \InsetSpace ~
12066 ld a,#0x01 
12067 \newline
12068 ED 79\InsetSpace ~
12069 \InsetSpace ~
12070 \InsetSpace ~
12071 \InsetSpace ~
12072 \InsetSpace ~
12073 \InsetSpace ~
12074 out (c),a 
12075 \end_layout
12076
12077 \begin_layout Subsubsection
12078 sfr
12079 \begin_inset LatexCommand \index{sfr}
12080
12081 \end_inset
12082
12083
12084 \begin_inset LatexCommand \index{\_\_sfr}
12085
12086 \end_inset
12087
12088  (in0/out0 to 8 bit addresses on Z180
12089 \begin_inset LatexCommand \index{Z180}
12090
12091 \end_inset
12092
12093 /HD64180
12094 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12095
12096 \end_inset
12097
12098 )
12099 \end_layout
12100
12101 \begin_layout Standard
12102 The compiler option -
12103 \begin_inset ERT
12104 status collapsed
12105
12106 \begin_layout Standard
12107
12108
12109 \backslash
12110 /
12111 \end_layout
12112
12113 \end_inset
12114
12115 -portmode
12116 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12117
12118 \end_inset
12119
12120 =180 (80) and a compiler #pragma\InsetSpace ~
12121 portmode
12122 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12123
12124 \end_inset
12125
12126  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12127 ns 
12128 \family typewriter
12129 in0/out0
12130 \family default
12131  instead of 
12132 \family typewriter
12133 in/out
12134 \family default
12135 .
12136  If you include the file z180.h this will be set automatically.
12137 \begin_inset VSpace bigskip
12138 \end_inset
12139
12140
12141 \end_layout
12142
12143 \begin_layout Subsection
12144 HC08 Storage Class
12145 \begin_inset LatexCommand \index{HC08!Storage class}
12146
12147 \end_inset
12148
12149  Language Extensions
12150 \end_layout
12151
12152 \begin_layout Subsubsection
12153 data
12154 \begin_inset LatexCommand \index{data (hc08 storage class)}
12155
12156 \end_inset
12157
12158
12159 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12160
12161 \end_inset
12162
12163  
12164 \end_layout
12165
12166 \begin_layout Standard
12167 The data storage class declares a variable that resides in the first 256
12168  bytes of memory (the direct page).
12169  The HC08
12170 \begin_inset LatexCommand \index{HC08}
12171
12172 \end_inset
12173
12174  is most efficient at accessing variables (especially pointers) stored here.
12175 \end_layout
12176
12177 \begin_layout Subsubsection
12178 xdata
12179 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12180
12181 \end_inset
12182
12183
12184 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12185
12186 \end_inset
12187
12188  
12189 \end_layout
12190
12191 \begin_layout Standard
12192 The xdata storage class declares a variable that can reside anywhere in
12193  memory.
12194  This is the default if no storage class is specified.
12195  
12196 \begin_inset VSpace bigskip
12197 \end_inset
12198
12199
12200 \end_layout
12201
12202 \begin_layout Section
12203 Absolute Addressing
12204 \begin_inset LatexCommand \index{Absolute addressing}
12205
12206 \end_inset
12207
12208
12209 \end_layout
12210
12211 \begin_layout Standard
12212 Data items can be assigned an absolute address with the 
12213 \emph on
12214 at
12215 \begin_inset LatexCommand \index{at}
12216
12217 \end_inset
12218
12219
12220 \begin_inset LatexCommand \index{\_\_at}
12221
12222 \end_inset
12223
12224  <address>
12225 \emph default
12226  keyword, in addition to a storage class, e.g.:
12227 \end_layout
12228
12229 \begin_layout Verse
12230
12231 \family typewriter
12232 xdata
12233 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12234
12235 \end_inset
12236
12237
12238 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12239
12240 \end_inset
12241
12242  at
12243 \begin_inset LatexCommand \index{at}
12244
12245 \end_inset
12246
12247
12248 \begin_inset LatexCommand \index{\_\_at}
12249
12250 \end_inset
12251
12252  0x7ffe unsigned int chksum;
12253 \end_layout
12254
12255 \begin_layout Standard
12256 or, better conforming to ISO/IEC 9899 C:
12257 \end_layout
12258
12259 \begin_layout Verse
12260
12261 \family typewriter
12262 __xdata __at (0x7ffe) unsigned int chksum;
12263 \end_layout
12264
12265 \begin_layout Standard
12266 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12267  of the external ram.
12268  The compiler does 
12269 \emph on
12270 not
12271 \emph default
12272  reserve any space for variables declared in this way
12273 \begin_inset Marginal
12274 status collapsed
12275
12276 \begin_layout Standard
12277
12278 \series bold
12279 \InsetSpace ~
12280 !
12281 \end_layout
12282
12283 \end_inset
12284
12285  (they are implemented with an equate in the assembler).
12286  Thus it is left to the programmer to make sure there are no overlaps with
12287  other variables that are declared without the absolute address.
12288  The assembler listing file (.lst
12289 \begin_inset LatexCommand \index{<file>.lst}
12290
12291 \end_inset
12292
12293 ) and the linker output files (.rst
12294 \begin_inset LatexCommand \index{<file>.rst}
12295
12296 \end_inset
12297
12298 ) and (.map
12299 \begin_inset LatexCommand \index{<file>.map}
12300
12301 \end_inset
12302
12303 ) are good places to look for such overlaps.
12304  Variables with an absolute address are 
12305 \emph on
12306 not
12307 \begin_inset Marginal
12308 status collapsed
12309
12310 \begin_layout Standard
12311
12312 \series bold
12313 \InsetSpace ~
12314 !
12315 \end_layout
12316
12317 \end_inset
12318
12319
12320 \emph default
12321  initialized
12322 \begin_inset LatexCommand \index{Variable initialization}
12323
12324 \end_inset
12325
12326 .
12327 \end_layout
12328
12329 \begin_layout Standard
12330 In case of memory mapped I/O devices the keyword 
12331 \emph on
12332 volatile
12333 \emph default
12334  has to be used to tell the compiler that accesses might not be removed:
12335 \end_layout
12336
12337 \begin_layout Verse
12338
12339 \family typewriter
12340 volatile
12341 \begin_inset LatexCommand \index{volatile}
12342
12343 \end_inset
12344
12345  __xdata
12346 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12347
12348 \end_inset
12349
12350  __at
12351 \begin_inset LatexCommand \index{at}
12352
12353 \end_inset
12354
12355  (0x8000) unsigned char PORTA_8255;
12356 \end_layout
12357
12358 \begin_layout Standard
12359 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12360 r) array
12361 \family typewriter
12362 \size footnotesize
12363
12364 \begin_inset LatexCommand \index{Aligned array}
12365
12366 \end_inset
12367
12368
12369 \family default
12370 \size default
12371  starts at a block (256 byte) boundary
12372 \begin_inset LatexCommand \index{block boundary}
12373
12374 \end_inset
12375
12376  (section 
12377 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12378
12379 \end_inset
12380
12381  has an example).
12382 \newline
12383 Absolute addresses can be specified for variables in all
12384  storage classes, e.g.:
12385 \end_layout
12386
12387 \begin_layout Verse
12388
12389 \family typewriter
12390 __bit
12391 \begin_inset LatexCommand \index{bit}
12392
12393 \end_inset
12394
12395  __at
12396 \begin_inset LatexCommand \index{at}
12397
12398 \end_inset
12399
12400  (0x02) bvar;
12401 \end_layout
12402
12403 \begin_layout Standard
12404 The above example will allocate the variable at offset 0x02 in the bit-addressab
12405 le space.
12406  There is no real advantage to assigning absolute addresses to variables
12407  in this manner, unless you want strict control over all the variables allocated.
12408  One possible use would be to write hardware portable code.
12409  For example, if you have a routine that uses one or more of the microcontroller
12410  I/O pins, and such pins are different for two different hardwares, you
12411  can declare the I/O pins in your routine using:
12412 \end_layout
12413
12414 \begin_layout Verse
12415
12416 \family typewriter
12417 extern volatile
12418 \begin_inset LatexCommand \index{volatile}
12419
12420 \end_inset
12421
12422  __bit MOSI;\InsetSpace ~
12423 \InsetSpace ~
12424 \InsetSpace ~
12425 \InsetSpace ~
12426 /* master out, slave in */
12427 \newline
12428 extern volatile __bit MISO;\InsetSpace ~
12429 \InsetSpace ~
12430 \InsetSpace ~
12431 \InsetSpace ~
12432 /* master
12433  in, slave out */
12434 \newline
12435 extern volatile __bit MCLK;\InsetSpace ~
12436 \InsetSpace ~
12437 \InsetSpace ~
12438 \InsetSpace ~
12439 /* master clock */
12440 \newline
12441
12442 \newline
12443 /* Input and
12444  Output of a byte on a 3-wire serial bus.
12445 \newline
12446 \InsetSpace ~
12447 \InsetSpace ~
12448 \InsetSpace ~
12449 If needed adapt polarity of clock,
12450  polarity of data and bit order
12451 \newline
12452 \InsetSpace ~
12453 */
12454 \newline
12455 unsigned char spi_io(unsigned char out_byte)
12456  
12457 \newline
12458
12459 \newline
12460 \InsetSpace ~
12461 \InsetSpace ~
12462 \InsetSpace ~
12463 \InsetSpace ~
12464 unsigned char i=8;
12465 \newline
12466 \InsetSpace ~
12467 \InsetSpace ~
12468 \InsetSpace ~
12469 \InsetSpace ~
12470 do { 
12471 \newline
12472 \InsetSpace ~
12473 \InsetSpace ~
12474 \InsetSpace ~
12475 \InsetSpace ~
12476 \InsetSpace ~
12477 \InsetSpace ~
12478 \InsetSpace ~
12479 \InsetSpace ~
12480 MOSI = out_byte & 0x80; 
12481 \newline
12482 \InsetSpace ~
12483 \InsetSpace ~
12484 \InsetSpace ~
12485 \InsetSpace ~
12486 \InsetSpace ~
12487 \InsetSpace ~
12488 \InsetSpace ~
12489 \InsetSpace ~
12490 out_byte <<= 1;
12491 \newline
12492 \InsetSpace ~
12493 \InsetSpace ~
12494 \InsetSpace ~
12495 \InsetSpace ~
12496 \InsetSpace ~
12497 \InsetSpace ~
12498 \InsetSpace ~
12499 \InsetSpace ~
12500 MCLK =
12501  1; 
12502 \newline
12503 \InsetSpace ~
12504 \InsetSpace ~
12505 \InsetSpace ~
12506 \InsetSpace ~
12507 \InsetSpace ~
12508 \InsetSpace ~
12509 \InsetSpace ~
12510 \InsetSpace ~
12511 /* _asm nop _endasm; */\InsetSpace ~
12512 \InsetSpace ~
12513 \InsetSpace ~
12514 \InsetSpace ~
12515 \InsetSpace ~
12516 \InsetSpace ~
12517 \InsetSpace ~
12518 \InsetSpace ~
12519 /* for slow peripherals */
12520 \newline
12521 \InsetSpace ~
12522 \InsetSpace ~
12523 \InsetSpace ~
12524 \InsetSpace ~
12525 \InsetSpace ~
12526 \InsetSpace ~
12527 \InsetSpace ~
12528 \InsetSpace ~
12529 if(MISO) 
12530 \newline
12531 \InsetSpace ~
12532 \InsetSpace ~
12533 \InsetSpace ~
12534 \InsetSpace ~
12535 \InsetSpace ~
12536 \InsetSpace ~
12537 \InsetSpace ~
12538 \InsetSpace ~
12539 \InsetSpace ~
12540 \InsetSpace ~
12541 \InsetSpace ~
12542 \InsetSpace ~
12543 out_byte +=
12544  1; 
12545 \newline
12546 \InsetSpace ~
12547 \InsetSpace ~
12548 \InsetSpace ~
12549 \InsetSpace ~
12550 \InsetSpace ~
12551 \InsetSpace ~
12552 \InsetSpace ~
12553 \InsetSpace ~
12554 MCLK = 0; 
12555 \newline
12556 \InsetSpace ~
12557 \InsetSpace ~
12558 \InsetSpace ~
12559 \InsetSpace ~
12560 } while(--i);
12561 \newline
12562 \InsetSpace ~
12563 \InsetSpace ~
12564 \InsetSpace ~
12565 \InsetSpace ~
12566 return out_byte; 
12567 \newline
12568 }
12569 \end_layout
12570
12571 \begin_layout Standard
12572 Then, someplace in the code for the first hardware you would use
12573 \end_layout
12574
12575 \begin_layout Verse
12576
12577 \family typewriter
12578 __bit __at
12579 \begin_inset LatexCommand \index{at}
12580
12581 \end_inset
12582
12583
12584 \begin_inset LatexCommand \index{\_\_at}
12585
12586 \end_inset
12587
12588  (0x80) MOSI;\InsetSpace ~
12589 \InsetSpace ~
12590 \InsetSpace ~
12591 \InsetSpace ~
12592 /* I/O port 0, bit 0 */
12593 \newline
12594 __bit __at (0x81) MISO;\InsetSpace ~
12595 \InsetSpace ~
12596 \InsetSpace ~
12597 \InsetSpace ~
12598 /* I/O port 0,
12599  bit 1 */
12600 \newline
12601 __bit __at (0x82) MCLK;\InsetSpace ~
12602 \InsetSpace ~
12603 \InsetSpace ~
12604 \InsetSpace ~
12605 /* I/O port 0, bit 2 */
12606 \end_layout
12607
12608 \begin_layout Standard
12609 Similarly, for the second hardware you would use
12610 \end_layout
12611
12612 \begin_layout Verse
12613
12614 \family typewriter
12615 __bit __at (0x83) MOSI;\InsetSpace ~
12616 \InsetSpace ~
12617 \InsetSpace ~
12618 \InsetSpace ~
12619 /* I/O port 0, bit 3 */
12620 \newline
12621 __bit __at (0x91) MISO;\InsetSpace ~
12622 \InsetSpace ~
12623 \InsetSpace ~
12624 \InsetSpace ~
12625 /*
12626  I/O port 1, bit 1 */
12627 \newline
12628 __bit
12629 \begin_inset LatexCommand \index{bit}
12630
12631 \end_inset
12632
12633  __at (0x92) MCLK;\InsetSpace ~
12634 \InsetSpace ~
12635 \InsetSpace ~
12636 \InsetSpace ~
12637 /* I/O port 1, bit 2 */
12638 \end_layout
12639
12640 \begin_layout Standard
12641 and you can use the same hardware dependent routine without changes, as
12642  for example in a library.
12643  This is somehow similar to sbit, but only one absolute address has to be
12644  specified in the whole project.
12645 \begin_inset VSpace bigskip
12646 \end_inset
12647
12648
12649 \end_layout
12650
12651 \begin_layout Section
12652 Parameters
12653 \begin_inset LatexCommand \index{Parameters}
12654
12655 \end_inset
12656
12657
12658 \begin_inset LatexCommand \index{function parameter}
12659
12660 \end_inset
12661
12662  & Local Variables
12663 \begin_inset LatexCommand \index{local variables}
12664
12665 \end_inset
12666
12667
12668 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12669
12670 \end_inset
12671
12672
12673 \end_layout
12674
12675 \begin_layout Standard
12676 Automatic (local) variables and parameters to functions can either be placed
12677  on the stack or in data-space.
12678  The default action of the compiler is to place these variables in the internal
12679  RAM (for small model) or external RAM (for large model).
12680  This in fact makes them similar to 
12681 \emph on
12682 static
12683 \begin_inset LatexCommand \index{static}
12684
12685 \end_inset
12686
12687
12688 \emph default
12689  so by default functions are non-reentrant
12690 \begin_inset LatexCommand \index{reentrant}
12691
12692 \end_inset
12693
12694 .
12695  
12696 \newline
12697
12698 \newline
12699 They can be placed on the stack
12700 \begin_inset LatexCommand \index{stack}
12701
12702 \end_inset
12703
12704  by using the
12705 \emph on
12706  -
12707 \begin_inset ERT
12708 status collapsed
12709
12710 \begin_layout Standard
12711
12712
12713 \backslash
12714 /
12715 \end_layout
12716
12717 \end_inset
12718
12719 -stack-auto
12720 \begin_inset LatexCommand \index{-\/-stack-auto}
12721
12722 \end_inset
12723
12724
12725 \emph default
12726  option, by using 
12727 \emph on
12728 #pragma\InsetSpace ~
12729 stackauto
12730 \emph default
12731
12732 \begin_inset LatexCommand \index{\#pragma stackauto}
12733
12734 \end_inset
12735
12736  or by using the 
12737 \emph on
12738 reentrant
12739 \begin_inset LatexCommand \index{reentrant}
12740
12741 \end_inset
12742
12743
12744 \emph default
12745  keyword in the function declaration, e.g.:
12746 \end_layout
12747
12748 \begin_layout Verse
12749
12750 \family typewriter
12751 unsigned char foo(char i) __reentrant 
12752 \newline
12753
12754 \newline
12755 \InsetSpace ~
12756 \InsetSpace ~
12757 \InsetSpace ~
12758 \InsetSpace ~
12759 ...
12760  
12761 \newline
12762 }
12763 \end_layout
12764
12765 \begin_layout Standard
12766 Since stack space on 8051 is limited, the 
12767 \emph on
12768 reentrant 
12769 \emph default
12770 keyword or the
12771 \emph on
12772  -
12773 \begin_inset ERT
12774 status collapsed
12775
12776 \begin_layout Standard
12777
12778
12779 \backslash
12780 /
12781 \end_layout
12782
12783 \end_inset
12784
12785 -stack-auto
12786 \emph default
12787  option should be used sparingly.
12788  Note that the reentrant keyword just means that the parameters & local
12789  variables will be allocated to the stack, it 
12790 \emph on
12791 does not
12792 \emph default
12793  mean that the function is register bank
12794 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12795
12796 \end_inset
12797
12798  independent.
12799 \newline
12800
12801 \newline
12802 Local variables
12803 \begin_inset LatexCommand \index{local variables}
12804
12805 \end_inset
12806
12807  can be assigned storage classes and absolute
12808 \begin_inset LatexCommand \index{Absolute addressing}
12809
12810 \end_inset
12811
12812  addresses, e.g.: 
12813 \end_layout
12814
12815 \begin_layout Verse
12816
12817 \family typewriter
12818 unsigned char foo() 
12819 \newline
12820 {
12821 \newline
12822 \InsetSpace ~
12823 \InsetSpace ~
12824 \InsetSpace ~
12825 \InsetSpace ~
12826 __xdata unsigned char i;
12827 \newline
12828 \InsetSpace ~
12829 \InsetSpace ~
12830 \InsetSpace ~
12831 \InsetSpace ~
12832 __bit bvar;
12833 \newline
12834 \InsetSpace ~
12835 \InsetSpace ~
12836 \InsetSpace ~
12837 \InsetSpace ~
12838 __data __at
12839 \begin_inset LatexCommand \index{at}
12840
12841 \end_inset
12842
12843  (0x31) unsigned char j;
12844 \newline
12845 \InsetSpace ~
12846 \InsetSpace ~
12847 \InsetSpace ~
12848 \InsetSpace ~
12849 ...
12850  
12851 \newline
12852 }
12853 \end_layout
12854
12855 \begin_layout Standard
12856 In the above example the variable 
12857 \emph on
12858 i
12859 \emph default
12860  will be allocated in the external ram, 
12861 \emph on
12862 bvar
12863 \emph default
12864  in bit addressable space and
12865 \emph on
12866  j
12867 \emph default
12868  in internal ram.
12869  When compiled with 
12870 \emph on
12871 -
12872 \begin_inset ERT
12873 status collapsed
12874
12875 \begin_layout Standard
12876
12877
12878 \backslash
12879 /
12880 \end_layout
12881
12882 \end_inset
12883
12884 -stack-auto
12885 \emph default
12886  or when a function is declared as 
12887 \emph on
12888 reentrant
12889 \emph default
12890  this should only be done for static variables.
12891 \end_layout
12892
12893 \begin_layout Standard
12894 Parameters
12895 \begin_inset LatexCommand \index{function parameter}
12896
12897 \end_inset
12898
12899  however are not allowed any storage class
12900 \begin_inset LatexCommand \index{Storage class}
12901
12902 \end_inset
12903
12904 , (storage classes for parameters will be ignored), their allocation is
12905  governed by the memory model in use, and the reentrancy options.
12906 \end_layout
12907
12908 \begin_layout Standard
12909 It is however allowed to use bit parameters in reentrant functions and also
12910  non-static local bit variables are supported.
12911  Efficient use is limited to 8 semi-bitregisters in bit space.
12912  They are pushed and popped to stack
12913 \begin_inset LatexCommand \index{stack}
12914
12915 \end_inset
12916
12917  as a single byte just like the normal registers.
12918 \end_layout
12919
12920 \begin_layout Section
12921 Overlaying
12922 \begin_inset LatexCommand \label{sub:Overlaying}
12923
12924 \end_inset
12925
12926
12927 \begin_inset LatexCommand \index{Overlaying}
12928
12929 \end_inset
12930
12931
12932 \end_layout
12933
12934 \begin_layout Standard
12935 For non-reentrant
12936 \begin_inset LatexCommand \index{reentrant}
12937
12938 \end_inset
12939
12940  functions SDCC will try to reduce internal ram space usage by overlaying
12941  parameters and local variables of a function (if possible).
12942  Parameters and local variables
12943 \begin_inset LatexCommand \index{local variables}
12944
12945 \end_inset
12946
12947  of a function will be allocated to an overlayable segment if the function
12948  has 
12949 \emph on
12950 no other function calls and the function is non-reentrant and the memory
12951  model
12952 \begin_inset LatexCommand \index{Memory model}
12953
12954 \end_inset
12955
12956  is small.
12957
12958 \emph default
12959  If an explicit storage class
12960 \begin_inset LatexCommand \index{Storage class}
12961
12962 \end_inset
12963
12964  is specified for a local variable, it will NOT be overlayed.
12965 \end_layout
12966
12967 \begin_layout Standard
12968 Note that the compiler (not the linkage editor) makes the decision for overlayin
12969 g the data items.
12970  Functions that are called from an interrupt service routine
12971 \begin_inset Marginal
12972 status collapsed
12973
12974 \begin_layout Standard
12975
12976 \series bold
12977 !
12978 \end_layout
12979
12980 \end_inset
12981
12982  should be preceded by a #pragma\InsetSpace ~
12983 nooverlay
12984 \begin_inset LatexCommand \index{\#pragma nooverlay}
12985
12986 \end_inset
12987
12988  if they are not reentrant.
12989 \end_layout
12990
12991 \begin_layout Standard
12992 Also note that the compiler does not do any processing of inline assembler
12993  code, so the compiler might incorrectly assign local variables and parameters
12994  of a function into the overlay segment if the inline assembler code calls
12995  other c-functions that might use the overlay.
12996  In that case the #pragma\InsetSpace ~
12997 nooverlay should be used.
12998 \end_layout
12999
13000 \begin_layout Standard
13001 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13002 tion
13003 \begin_inset LatexCommand \index{Multiplication}
13004
13005 \end_inset
13006
13007  or division
13008 \begin_inset LatexCommand \index{Division}
13009
13010 \end_inset
13011
13012  will NOT be overlayed since these are implemented using external functions,
13013  e.g.:
13014 \end_layout
13015
13016 \begin_layout Verse
13017
13018 \family typewriter
13019 #pragma save 
13020 \newline
13021 #pragma nooverlay
13022 \begin_inset LatexCommand \index{\#pragma nooverlay}
13023
13024 \end_inset
13025
13026  
13027 \newline
13028 void set_error(unsigned char errcd) 
13029 \newline
13030 {
13031 \newline
13032 \InsetSpace ~
13033 \InsetSpace ~
13034 \InsetSpace ~
13035 \InsetSpace ~
13036 P3 = errcd;
13037 \newline
13038
13039 \newline
13040 #pragma restore 
13041 \newline
13042
13043 \newline
13044 void
13045  some_isr () __interrupt
13046 \begin_inset LatexCommand \index{interrupt}
13047
13048 \end_inset
13049
13050  (2)
13051 \newline
13052 {
13053 \newline
13054 \InsetSpace ~
13055 \InsetSpace ~
13056 \InsetSpace ~
13057 \InsetSpace ~
13058 ...
13059 \newline
13060 \InsetSpace ~
13061 \InsetSpace ~
13062 \InsetSpace ~
13063 \InsetSpace ~
13064 set_error(10);
13065 \newline
13066 \InsetSpace ~
13067 \InsetSpace ~
13068 \InsetSpace ~
13069 \InsetSpace ~
13070 ...
13071  
13072 \newline
13073 }
13074 \end_layout
13075
13076 \begin_layout Standard
13077 In the above example the parameter 
13078 \emph on
13079 errcd
13080 \emph default
13081  for the function 
13082 \emph on
13083 set_error
13084 \emph default
13085  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13086 nooverlay was
13087  not present, this could cause unpredictable runtime behavior when called
13088  from an interrupt service routine.
13089  The #pragma\InsetSpace ~
13090 nooverlay ensures that the parameters and local variables for
13091  the function are NOT overlayed.
13092 \begin_inset VSpace bigskip
13093 \end_inset
13094
13095
13096 \end_layout
13097
13098 \begin_layout Section
13099 Interrupt Service Routines
13100 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13101
13102 \end_inset
13103
13104
13105 \end_layout
13106
13107 \begin_layout Subsection
13108 General Information
13109 \end_layout
13110
13111 \begin_layout Standard
13112 SDCC allows 
13113 \emph on
13114 i
13115 \emph default
13116 nterrupt 
13117 \emph on
13118 s
13119 \emph default
13120 ervice 
13121 \emph on
13122 r
13123 \emph default
13124 outines to be coded in C, with some extended keywords.
13125 \end_layout
13126
13127 \begin_layout Verse
13128
13129 \family typewriter
13130 void timer_isr (void) __interrupt (1) __using (1) 
13131 \newline
13132
13133 \newline
13134 \InsetSpace ~
13135 \InsetSpace ~
13136 \InsetSpace ~
13137 \InsetSpace ~
13138 ...
13139  
13140 \newline
13141 }
13142 \end_layout
13143
13144 \begin_layout Standard
13145 The optional number following the 
13146 \emph on
13147 interrupt
13148 \begin_inset LatexCommand \index{interrupt}
13149
13150 \end_inset
13151
13152
13153 \begin_inset LatexCommand \index{\_\_interrupt}
13154
13155 \end_inset
13156
13157
13158 \emph default
13159  keyword is the interrupt number this routine will service.
13160  When present, the compiler will insert a call to this routine in the interrupt
13161  vector table
13162 \begin_inset LatexCommand \index{interrupt vector table}
13163
13164 \end_inset
13165
13166  for the interrupt number specified.
13167  If you have multiple source files in your project, interrupt service routines
13168  can be present in any of them, but a prototype of the isr MUST be present
13169  or included in the file that contains the function 
13170 \emph on
13171 main
13172 \emph default
13173 .
13174  The optional (8051 specific) keyword 
13175 \emph on
13176 using
13177 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13178
13179 \end_inset
13180
13181
13182 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13183
13184 \end_inset
13185
13186
13187 \emph default
13188  can be used to tell the compiler to use the specified register bank when
13189  generating code for this function.
13190  
13191 \newline
13192 Interrupt service routines open the door for some very interesting bugs:
13193 \end_layout
13194
13195 \begin_layout Subsubsection
13196 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13197
13198 \end_inset
13199
13200 Common interrupt pitfall: variable not declared 
13201 \emph on
13202 volatile
13203 \end_layout
13204
13205 \begin_layout Standard
13206 If an interrupt service routine changes variables which are accessed by
13207  other functions these variables have to be declared 
13208 \emph on
13209 volatile
13210 \emph default
13211
13212 \begin_inset LatexCommand \index{volatile}
13213
13214 \end_inset
13215
13216 .
13217  See 
13218 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13219
13220 \end_inset
13221
13222  .
13223 \end_layout
13224
13225 \begin_layout Subsubsection
13226 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13227
13228 \end_inset
13229
13230 Common interrupt pitfall: 
13231 \emph on
13232 non-atomic access
13233 \end_layout
13234
13235 \begin_layout Standard
13236 If the access to these variables is not 
13237 \emph on
13238 atomic
13239 \begin_inset LatexCommand \index{atomic}
13240
13241 \end_inset
13242
13243
13244 \emph default
13245  (i.e.
13246  the processor needs more than one instruction for the access and could
13247  be interrupted while accessing the variable) the interrupt must be disabled
13248  during the access to avoid inconsistent data.
13249  
13250 \newline
13251 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13252  and should be protected by disabling interrupts.
13253  You're not automatically on the safe side if you use 8 bit variables though.
13254  We need an example here: f.e.
13255  on the 8051 the harmless looking 
13256 \begin_inset Quotes srd
13257 \end_inset
13258
13259
13260 \family typewriter
13261 flags\InsetSpace ~
13262 |=\InsetSpace ~
13263 0x80;
13264 \family default
13265
13266 \begin_inset Quotes sld
13267 \end_inset
13268
13269  is not atomic if 
13270 \family typewriter
13271 flags
13272 \family default
13273  resides in xdata.
13274  Setting 
13275 \begin_inset Quotes srd
13276 \end_inset
13277
13278
13279 \family typewriter
13280 flags\InsetSpace ~
13281 |=\InsetSpace ~
13282 0x40;
13283 \family default
13284
13285 \begin_inset Quotes sld
13286 \end_inset
13287
13288  from within an interrupt routine might get lost if the interrupt occurs
13289  at the wrong time.
13290  
13291 \begin_inset Quotes sld
13292 \end_inset
13293
13294
13295 \family typewriter
13296 counter\InsetSpace ~
13297 +=\InsetSpace ~
13298 8;
13299 \family default
13300
13301 \begin_inset Quotes srd
13302 \end_inset
13303
13304  is not atomic on the 8051 even if 
13305 \family typewriter
13306 counter
13307 \family default
13308  is located in data memory.
13309 \newline
13310 Bugs like these are hard to reproduce and can
13311  cause a lot of trouble.
13312  
13313 \end_layout
13314
13315 \begin_layout Subsubsection
13316 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13317
13318 \end_inset
13319
13320 Common interrupt pitfall: 
13321 \emph on
13322 stack overflow
13323 \end_layout
13324
13325 \begin_layout Standard
13326 The return address and the registers used in the interrupt service routine
13327  are saved on the stack
13328 \begin_inset LatexCommand \index{stack}
13329
13330 \end_inset
13331
13332  so there must be sufficient stack space.
13333  If there isn't variables or registers (or even the return address itself)
13334  will be corrupted.
13335  This 
13336 \emph on
13337 stack overflow
13338 \emph default
13339
13340 \begin_inset LatexCommand \index{stack overflow}
13341
13342 \end_inset
13343
13344  is most likely to happen if the interrupt occurs during the 
13345 \begin_inset Quotes sld
13346 \end_inset
13347
13348 deepest
13349 \begin_inset Quotes srd
13350 \end_inset
13351
13352  subroutine when the stack is already in use for f.e.
13353  many return addresses.
13354 \end_layout
13355
13356 \begin_layout Subsubsection
13357 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13358
13359 \end_inset
13360
13361 Common interrupt pitfall: 
13362 \emph on
13363 use of non-reentrant functions
13364 \end_layout
13365
13366 \begin_layout Standard
13367 A special note here, int (16 bit) and long (32 bit) integer division
13368 \begin_inset LatexCommand \index{Division}
13369
13370 \end_inset
13371
13372 , multiplication
13373 \begin_inset LatexCommand \index{Multiplication}
13374
13375 \end_inset
13376
13377  & modulus
13378 \begin_inset LatexCommand \index{Modulus}
13379
13380 \end_inset
13381
13382  and floating-point
13383 \begin_inset LatexCommand \index{Floating point support}
13384
13385 \end_inset
13386
13387  operations are implemented using external support routines.
13388  If an interrupt service routine needs to do any of these operations then
13389  the support routines (as mentioned in a following section) will have to
13390  be recompiled using the
13391 \emph on
13392  -
13393 \begin_inset ERT
13394 status collapsed
13395
13396 \begin_layout Standard
13397
13398
13399 \backslash
13400 /
13401 \end_layout
13402
13403 \end_inset
13404
13405 -stack-auto
13406 \begin_inset LatexCommand \index{-\/-stack-auto}
13407
13408 \end_inset
13409
13410
13411 \emph default
13412  option and the source file will need to be compiled using the 
13413 \emph on
13414 -
13415 \begin_inset ERT
13416 status collapsed
13417
13418 \begin_layout Standard
13419
13420
13421 \backslash
13422 /
13423 \end_layout
13424
13425 \end_inset
13426
13427 -int-long-reent
13428 \emph default
13429
13430 \begin_inset LatexCommand \index{-\/-int-long-reent}
13431
13432 \end_inset
13433
13434  compiler option.
13435  
13436 \newline
13437 Note, the type promotion
13438 \begin_inset LatexCommand \index{type promotion}
13439
13440 \end_inset
13441
13442  required by ANSI C can cause 16 bit routines to be used
13443 \begin_inset Marginal
13444 status collapsed
13445
13446 \begin_layout Standard
13447
13448 \series bold
13449 \InsetSpace ~
13450 !
13451 \end_layout
13452
13453 \end_inset
13454
13455  without the programmer being aware of it.
13456  See f.e.
13457  the cast 
13458 \family typewriter
13459 (unsigned char)(tail-1)
13460 \family default
13461  within the if clause in section 
13462 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13463
13464 \end_inset
13465
13466 .
13467 \end_layout
13468
13469 \begin_layout Standard
13470 Calling other functions from an interrupt service routine is not recommended,
13471  avoid it if possible.
13472  Note that when some function is called from an interrupt service routine
13473  it should be preceded by a #pragma\InsetSpace ~
13474 nooverlay
13475 \begin_inset LatexCommand \index{\#pragma nooverlay}
13476
13477 \end_inset
13478
13479  if it is not reentrant.
13480  Furthermore nonreentrant functions should not be called from the main program
13481  while the interrupt service routine might be active.
13482  They also must not be called from low priority interrupt service routines
13483  while a high priority interrupt service routine might be active.
13484  You could use semaphores or make the function
13485 \emph on
13486  critical
13487 \emph default
13488  if all parameters are passed in registers.
13489 \newline
13490  Also see section 
13491 \begin_inset LatexCommand \ref{sub:Overlaying}
13492
13493 \end_inset
13494
13495 \InsetSpace ~
13496 about Overlaying and section 
13497 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13498
13499 \end_inset
13500
13501 \InsetSpace ~
13502 about Functions using private register banks.
13503 \begin_inset VSpace bigskip
13504 \end_inset
13505
13506
13507 \end_layout
13508
13509 \begin_layout Subsection
13510 MCS51/DS390 Interrupt Service Routines
13511 \end_layout
13512
13513 \begin_layout Standard
13514 Interrupt
13515 \begin_inset LatexCommand \index{interrupt}
13516
13517 \end_inset
13518
13519  numbers and the corresponding address & descriptions for the Standard 8051/8052
13520  are listed below.
13521  SDCC will automatically adjust the 
13522 \begin_inset LatexCommand \index{interrupt vector table}
13523
13524 \end_inset
13525
13526  to the maximum interrupt number specified.
13527 \newline
13528
13529 \end_layout
13530
13531 \begin_layout Standard
13532 \align center
13533 \begin_inset Tabular
13534 <lyxtabular version="3" rows="9" columns="3">
13535 <features>
13536 <column alignment="center" valignment="top" leftline="true" width="0in">
13537 <column alignment="left" valignment="top" leftline="true" width="0in">
13538 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13539 <row topline="true" bottomline="true">
13540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13541 \begin_inset Text
13542
13543 \begin_layout Standard
13544 Interrupt #
13545 \end_layout
13546
13547 \end_inset
13548 </cell>
13549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13550 \begin_inset Text
13551
13552 \begin_layout Standard
13553 Description
13554 \end_layout
13555
13556 \end_inset
13557 </cell>
13558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13559 \begin_inset Text
13560
13561 \begin_layout Standard
13562 Vector Address
13563 \end_layout
13564
13565 \end_inset
13566 </cell>
13567 </row>
13568 <row topline="true">
13569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13570 \begin_inset Text
13571
13572 \begin_layout Standard
13573 0
13574 \end_layout
13575
13576 \end_inset
13577 </cell>
13578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13579 \begin_inset Text
13580
13581 \begin_layout Standard
13582 External 0
13583 \end_layout
13584
13585 \end_inset
13586 </cell>
13587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13588 \begin_inset Text
13589
13590 \begin_layout Standard
13591 0x0003
13592 \end_layout
13593
13594 \end_inset
13595 </cell>
13596 </row>
13597 <row topline="true">
13598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13599 \begin_inset Text
13600
13601 \begin_layout Standard
13602 1
13603 \end_layout
13604
13605 \end_inset
13606 </cell>
13607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13608 \begin_inset Text
13609
13610 \begin_layout Standard
13611 Timer 0
13612 \end_layout
13613
13614 \end_inset
13615 </cell>
13616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13617 \begin_inset Text
13618
13619 \begin_layout Standard
13620 0x000b
13621 \end_layout
13622
13623 \end_inset
13624 </cell>
13625 </row>
13626 <row topline="true">
13627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13628 \begin_inset Text
13629
13630 \begin_layout Standard
13631 2
13632 \end_layout
13633
13634 \end_inset
13635 </cell>
13636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13637 \begin_inset Text
13638
13639 \begin_layout Standard
13640 External 1
13641 \end_layout
13642
13643 \end_inset
13644 </cell>
13645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13646 \begin_inset Text
13647
13648 \begin_layout Standard
13649 0x0013
13650 \end_layout
13651
13652 \end_inset
13653 </cell>
13654 </row>
13655 <row topline="true">
13656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13657 \begin_inset Text
13658
13659 \begin_layout Standard
13660 3
13661 \end_layout
13662
13663 \end_inset
13664 </cell>
13665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13666 \begin_inset Text
13667
13668 \begin_layout Standard
13669 Timer 1
13670 \end_layout
13671
13672 \end_inset
13673 </cell>
13674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13675 \begin_inset Text
13676
13677 \begin_layout Standard
13678 0x001b
13679 \end_layout
13680
13681 \end_inset
13682 </cell>
13683 </row>
13684 <row topline="true">
13685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13686 \begin_inset Text
13687
13688 \begin_layout Standard
13689 4
13690 \end_layout
13691
13692 \end_inset
13693 </cell>
13694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13695 \begin_inset Text
13696
13697 \begin_layout Standard
13698 Serial
13699 \end_layout
13700
13701 \end_inset
13702 </cell>
13703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13704 \begin_inset Text
13705
13706 \begin_layout Standard
13707 0x0023
13708 \end_layout
13709
13710 \end_inset
13711 </cell>
13712 </row>
13713 <row topline="true">
13714 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13715 \begin_inset Text
13716
13717 \begin_layout Standard
13718 5
13719 \end_layout
13720
13721 \end_inset
13722 </cell>
13723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13724 \begin_inset Text
13725
13726 \begin_layout Standard
13727 Timer 2 (8052)
13728 \end_layout
13729
13730 \end_inset
13731 </cell>
13732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13733 \begin_inset Text
13734
13735 \begin_layout Standard
13736 0x002b
13737 \end_layout
13738
13739 \end_inset
13740 </cell>
13741 </row>
13742 <row topline="true">
13743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13744 \begin_inset Text
13745
13746 \begin_layout Standard
13747 ...
13748 \end_layout
13749
13750 \end_inset
13751 </cell>
13752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13753 \begin_inset Text
13754
13755 \begin_layout Standard
13756
13757 \end_layout
13758
13759 \end_inset
13760 </cell>
13761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13762 \begin_inset Text
13763
13764 \begin_layout Standard
13765 ...
13766 \end_layout
13767
13768 \end_inset
13769 </cell>
13770 </row>
13771 <row topline="true" bottomline="true">
13772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13773 \begin_inset Text
13774
13775 \begin_layout Standard
13776 n
13777 \end_layout
13778
13779 \end_inset
13780 </cell>
13781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13782 \begin_inset Text
13783
13784 \begin_layout Standard
13785
13786 \end_layout
13787
13788 \end_inset
13789 </cell>
13790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13791 \begin_inset Text
13792
13793 \begin_layout Standard
13794 0x0003 + 8*n
13795 \end_layout
13796
13797 \end_inset
13798 </cell>
13799 </row>
13800 </lyxtabular>
13801
13802 \end_inset
13803
13804
13805 \newline
13806
13807 \end_layout
13808
13809 \begin_layout Standard
13810 If the interrupt service routine is defined without 
13811 \emph on
13812 using
13813 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13814
13815 \end_inset
13816
13817
13818 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13819
13820 \end_inset
13821
13822
13823 \emph default
13824  a register bank or with register bank 0 (
13825 \emph on
13826 using
13827 \emph default
13828  0), the compiler will save the registers used by itself on the stack upon
13829  entry and restore them at exit, however if such an interrupt service routine
13830  calls another function then the entire register bank will be saved on the
13831  stack.
13832  This scheme may be advantageous for small interrupt service routines which
13833  have low register usage.
13834 \end_layout
13835
13836 \begin_layout Standard
13837 If the interrupt service routine is defined to be using a specific register
13838  bank then only 
13839 \emph on
13840 a, b, dptr
13841 \emph default
13842  & psw are saved and restored, if such an interrupt service routine calls
13843  another function (using another register bank) then the entire register
13844  bank of the called function will be saved on the stack
13845 \begin_inset LatexCommand \index{stack}
13846
13847 \end_inset
13848
13849 .
13850  This scheme is recommended for larger interrupt service routines.
13851 \begin_inset VSpace bigskip
13852 \end_inset
13853
13854
13855 \end_layout
13856
13857 \begin_layout Subsection
13858 HC08
13859 \begin_inset LatexCommand \index{HC08}
13860
13861 \end_inset
13862
13863  Interrupt Service Routines
13864 \end_layout
13865
13866 \begin_layout Standard
13867 Since the number of interrupts
13868 \begin_inset LatexCommand \index{HC08!interrupt}
13869
13870 \end_inset
13871
13872  available is chip specific and the interrupt vector table always ends at
13873  the last byte of memory, the interrupt numbers corresponds to the interrupt
13874  vectors in reverse order of address.
13875  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
13876  2 will use the interrupt vector at 0xfffa, and so on.
13877  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
13878  this way; instead see section 
13879 \begin_inset LatexCommand \ref{sub:Startup-Code}
13880
13881 \end_inset
13882
13883  for details on customizing startup.
13884 \begin_inset VSpace bigskip
13885 \end_inset
13886
13887
13888 \end_layout
13889
13890 \begin_layout Subsection
13891 Z80 Interrupt Service Routines
13892 \end_layout
13893
13894 \begin_layout Standard
13895 The Z80
13896 \begin_inset LatexCommand \index{Z80}
13897
13898 \end_inset
13899
13900  uses several different methods for determining the correct interrupt
13901 \begin_inset LatexCommand \index{Z80!interrupt}
13902
13903 \end_inset
13904
13905  vector depending on the hardware implementation.
13906  Therefore, SDCC ignores the optional interrupt number and does not attempt
13907  to generate an interrupt vector table.
13908 \end_layout
13909
13910 \begin_layout Standard
13911 By default, SDCC generates code for a maskable interrupt, which uses a RETI
13912  instruction to return from the interrupt.
13913  To write an interrupt handler for the non-maskable interrupt, which needs
13914  a RETN instruction instead, add the 
13915 \emph on
13916 critical
13917 \emph default
13918  keyword:
13919 \end_layout
13920
13921 \begin_layout Verse
13922
13923 \family typewriter
13924 void nmi_isr (void) critical interrupt
13925 \newline
13926
13927 \newline
13928 \InsetSpace ~
13929 \InsetSpace ~
13930 \InsetSpace ~
13931 \InsetSpace ~
13932 ...
13933  
13934 \newline
13935 }
13936 \end_layout
13937
13938 \begin_layout Standard
13939 However if you need to create a non-interruptable interrupt service routine
13940  you would also require the 
13941 \emph on
13942 critical
13943 \emph default
13944  keyword.
13945  To distinguish between this and an nmi_isr you must provide an interrupt
13946  number.
13947 \begin_inset VSpace bigskip
13948 \end_inset
13949
13950
13951 \end_layout
13952
13953 \begin_layout Section
13954 Enabling and Disabling Interrupts
13955 \end_layout
13956
13957 \begin_layout Subsection
13958 Critical Functions and Critical Statements
13959 \end_layout
13960
13961 \begin_layout Standard
13962 A special keyword may be associated with a block or a function declaring
13963  it as 
13964 \emph on
13965 critical
13966 \emph default
13967 .
13968  SDCC will generate code to disable all interrupts
13969 \begin_inset LatexCommand \index{interrupt}
13970
13971 \end_inset
13972
13973  upon entry to a critical function and restore the interrupt enable to the
13974  previous state before returning.
13975  Nesting critical functions will need one additional byte on the stack
13976 \begin_inset LatexCommand \index{stack}
13977
13978 \end_inset
13979
13980  for each call.
13981 \end_layout
13982
13983 \begin_layout Verse
13984
13985 \family typewriter
13986 int foo () __critical
13987 \begin_inset LatexCommand \index{critical}
13988
13989 \end_inset
13990
13991
13992 \begin_inset LatexCommand \index{\_\_critical}
13993
13994 \end_inset
13995
13996  
13997 \newline
13998
13999 \newline
14000 \InsetSpace ~
14001 \InsetSpace ~
14002 \InsetSpace ~
14003 \InsetSpace ~
14004 ...
14005  
14006 \newline
14007 \InsetSpace ~
14008 \InsetSpace ~
14009 \InsetSpace ~
14010 \InsetSpace ~
14011 ...
14012  
14013 \newline
14014 }
14015 \end_layout
14016
14017 \begin_layout Standard
14018 The critical attribute maybe used with other attributes like 
14019 \emph on
14020 reentrant.
14021 \emph default
14022
14023 \newline
14024 The keyword 
14025 \emph on
14026 critical
14027 \emph default
14028  may also be used to disable interrupts more locally:
14029 \end_layout
14030
14031 \begin_layout Verse
14032
14033 \family typewriter
14034 __critical{ i++; }
14035 \end_layout
14036
14037 \begin_layout Standard
14038 More than one statement could have been included in the block.
14039 \end_layout
14040
14041 \begin_layout Subsection
14042 Enabling and Disabling Interrupts directly
14043 \end_layout
14044
14045 \begin_layout Standard
14046 Interrupts
14047 \begin_inset LatexCommand \index{interrupt}
14048
14049 \end_inset
14050
14051  can also be disabled and enabled directly (8051):
14052 \end_layout
14053
14054 \begin_layout Verse
14055
14056 \family typewriter
14057 EA = 0;\InsetSpace ~
14058 \InsetSpace ~
14059 \InsetSpace ~
14060 \InsetSpace ~
14061 \InsetSpace ~
14062 \InsetSpace ~
14063 \InsetSpace ~
14064 \InsetSpace ~
14065 \InsetSpace ~
14066 \InsetSpace ~
14067 \InsetSpace ~
14068 \InsetSpace ~
14069 or:\InsetSpace ~
14070 \InsetSpace ~
14071 \InsetSpace ~
14072 \InsetSpace ~
14073 \InsetSpace ~
14074 \InsetSpace ~
14075 \InsetSpace ~
14076 \InsetSpace ~
14077 \InsetSpace ~
14078 \InsetSpace ~
14079 \InsetSpace ~
14080 EA_SAVE = EA;
14081 \end_layout
14082
14083 \begin_layout Verse
14084
14085 \family typewriter
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 \InsetSpace ~
14114 \InsetSpace ~
14115 \InsetSpace ~
14116 EA = 0;
14117 \end_layout
14118
14119 \begin_layout Verse
14120
14121 \family typewriter
14122 EA = 1;\InsetSpace ~
14123 \InsetSpace ~
14124 \InsetSpace ~
14125 \InsetSpace ~
14126 \InsetSpace ~
14127 \InsetSpace ~
14128 \InsetSpace ~
14129 \InsetSpace ~
14130 \InsetSpace ~
14131 \InsetSpace ~
14132 \InsetSpace ~
14133 \InsetSpace ~
14134 \InsetSpace ~
14135 \InsetSpace ~
14136 \InsetSpace ~
14137 \InsetSpace ~
14138 \InsetSpace ~
14139 \InsetSpace ~
14140 \InsetSpace ~
14141 \InsetSpace ~
14142 \InsetSpace ~
14143 \InsetSpace ~
14144 \InsetSpace ~
14145 \InsetSpace ~
14146 \InsetSpace ~
14147 \InsetSpace ~
14148 ...
14149 \end_layout
14150
14151 \begin_layout Verse
14152
14153 \family typewriter
14154 \InsetSpace ~
14155 \InsetSpace ~
14156 \InsetSpace ~
14157 \InsetSpace ~
14158 \InsetSpace ~
14159 \InsetSpace ~
14160 \InsetSpace ~
14161 \InsetSpace ~
14162 \InsetSpace ~
14163 \InsetSpace ~
14164 \InsetSpace ~
14165 \InsetSpace ~
14166 \InsetSpace ~
14167 \InsetSpace ~
14168 \InsetSpace ~
14169 \InsetSpace ~
14170 \InsetSpace ~
14171 \InsetSpace ~
14172 \InsetSpace ~
14173 \InsetSpace ~
14174 \InsetSpace ~
14175 \InsetSpace ~
14176 \InsetSpace ~
14177 \InsetSpace ~
14178 \InsetSpace ~
14179 \InsetSpace ~
14180 \InsetSpace ~
14181 \InsetSpace ~
14182 \InsetSpace ~
14183 \InsetSpace ~
14184 \InsetSpace ~
14185 \InsetSpace ~
14186 \InsetSpace ~
14187 EA = EA_SAVE;
14188 \end_layout
14189
14190 \begin_layout Standard
14191 On other architectures which have seperate opcodes for enabling and disabling
14192  interrupts you might want to make use of defines with inline assembly
14193 \begin_inset LatexCommand \index{Assembler routines}
14194
14195 \end_inset
14196
14197  (HC08
14198 \begin_inset LatexCommand \index{HC08!interrupt}
14199
14200 \end_inset
14201
14202 ):
14203 \end_layout
14204
14205 \begin_layout Verse
14206
14207 \family typewriter
14208 #define CLI _asm
14209 \begin_inset LatexCommand \index{\_asm}
14210
14211 \end_inset
14212
14213 \InsetSpace ~
14214 \InsetSpace ~
14215 cli\InsetSpace ~
14216 \InsetSpace ~
14217 _endasm
14218 \begin_inset LatexCommand \index{\_endasm}
14219
14220 \end_inset
14221
14222
14223 \end_layout
14224
14225 \begin_layout Verse
14226
14227 \family typewriter
14228 #define SEI _asm\InsetSpace ~
14229 \InsetSpace ~
14230 sei\InsetSpace ~
14231 \InsetSpace ~
14232 _endasm; 
14233 \end_layout
14234
14235 \begin_layout Verse
14236
14237 \family typewriter
14238 ...
14239 \end_layout
14240
14241 \begin_layout Standard
14242 Note: it is sometimes sufficient to disable only a specific interrupt source
14243  like f.e.
14244  a timer or serial interrupt by manipulating an 
14245 \emph on
14246 interrupt mask
14247 \begin_inset LatexCommand \index{interrupt mask}
14248
14249 \end_inset
14250
14251
14252 \emph default
14253  register.
14254  
14255 \end_layout
14256
14257 \begin_layout Standard
14258 Usually the time during which interrupts are disabled should be kept as
14259  short as possible.
14260  This minimizes both 
14261 \emph on
14262 interrupt latency
14263 \emph default
14264
14265 \begin_inset LatexCommand \index{interrupt latency}
14266
14267 \end_inset
14268
14269  (the time between the occurrence of the interrupt and the execution of
14270  the first code in the interrupt routine) and 
14271 \emph on
14272 interrupt jitter
14273 \emph default
14274
14275 \begin_inset LatexCommand \index{interrupt jitter}
14276
14277 \end_inset
14278
14279  (the difference between the shortest and the longest interrupt latency).
14280  These really are something different, f.e.
14281  a serial interrupt has to be served before its buffer overruns so it cares
14282  for the maximum interrupt latency, whereas it does not care about jitter.
14283  On a loudspeaker driven via a digital to analog converter which is fed
14284  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14285  a much smaller jitter will be very audible.
14286 \end_layout
14287
14288 \begin_layout Standard
14289 You can reenable interrupts within an interrupt routine and on some architecture
14290 s you can make use of two (or more) levels of 
14291 \emph on
14292 interrupt priorities
14293 \emph default
14294
14295 \begin_inset LatexCommand \index{interrupt priority}
14296
14297 \end_inset
14298
14299 .
14300  On some architectures which don't support interrupt priorities these can
14301  be implemented by manipulating the interrupt mask and reenabling interrupts
14302  within the interrupt routine.
14303  Check there is sufficient space on the stack
14304 \begin_inset LatexCommand \index{stack}
14305
14306 \end_inset
14307
14308  and don't add complexity unless you have to.
14309  
14310 \end_layout
14311
14312 \begin_layout Subsection
14313 Semaphore
14314 \begin_inset LatexCommand \index{semaphore}
14315
14316 \end_inset
14317
14318  locking (mcs51/ds390)
14319 \end_layout
14320
14321 \begin_layout Standard
14322 Some architectures (mcs51/ds390) have an atomic
14323 \begin_inset LatexCommand \index{atomic}
14324
14325 \end_inset
14326
14327  bit test and
14328 \emph on
14329  
14330 \emph default
14331 clear
14332 \emph on
14333  
14334 \emph default
14335 instruction.
14336  These type of instructions are typically used in preemptive multitasking
14337  systems, where a routine f.e.
14338  claims the use of a data structure ('acquires a lock
14339 \begin_inset LatexCommand \index{lock}
14340
14341 \end_inset
14342
14343  on it'), makes some modifications and then releases the lock when the data
14344  structure is consistent again.
14345  The instruction may also be used if interrupt and non-interrupt code have
14346  to compete for a resource.
14347  With the atomic bit test and clear instruction interrupts
14348 \begin_inset LatexCommand \index{interrupt}
14349
14350 \end_inset
14351
14352  don't have to be disabled for the locking operation.
14353  
14354 \end_layout
14355
14356 \begin_layout Standard
14357 SDCC generates this instruction if the source follows this pattern:
14358 \end_layout
14359
14360 \begin_layout Verse
14361
14362 \family typewriter
14363 volatile
14364 \begin_inset LatexCommand \index{volatile}
14365
14366 \end_inset
14367
14368  bit resource_is_free; 
14369 \newline
14370
14371 \newline
14372 if (resource_is_free) 
14373 \newline
14374 \InsetSpace ~
14375 \InsetSpace ~
14376
14377 \newline
14378 \InsetSpace ~
14379 \InsetSpace ~
14380 \InsetSpace ~
14381 \InsetSpace ~
14382 resource_is_free=0; 
14383 \newline
14384 \InsetSpace ~
14385 \InsetSpace ~
14386 \InsetSpace ~
14387 \InsetSpace ~
14388 ...
14389  
14390 \newline
14391 \InsetSpace ~
14392 \InsetSpace ~
14393 \InsetSpace ~
14394 \InsetSpace ~
14395 resource_is_free=1;
14396 \newline
14397 \InsetSpace ~
14398 \InsetSpace ~
14399
14400 \end_layout
14401
14402 \begin_layout Standard
14403 Note, mcs51 and ds390 support only an atomic
14404 \begin_inset LatexCommand \index{atomic}
14405
14406 \end_inset
14407
14408  bit test and 
14409 \emph on
14410 clear
14411 \emph default
14412  instruction (as opposed to atomic bit test and 
14413 \emph on
14414 set).
14415 \end_layout
14416
14417 \begin_layout Section
14418 Functions using private register banks
14419 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14420
14421 \end_inset
14422
14423  (mcs51/ds390)
14424 \end_layout
14425
14426 \begin_layout Standard
14427 Some architectures have support for quickly changing register sets.
14428  SDCC supports this feature with the 
14429 \emph on
14430 using
14431 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14432
14433 \end_inset
14434
14435
14436 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14437
14438 \end_inset
14439
14440
14441 \emph default
14442  attribute (which tells the compiler to use a register bank
14443 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14444
14445 \end_inset
14446
14447  other than the default bank zero).
14448  It should only be applied to 
14449 \emph on
14450 interrupt
14451 \begin_inset LatexCommand \index{interrupt}
14452
14453 \end_inset
14454
14455
14456 \emph default
14457  functions (see footnote below).
14458  This will in most circumstances make the generated ISR code more efficient
14459  since it will not have to save registers on the stack.
14460 \end_layout
14461
14462 \begin_layout Standard
14463 The 
14464 \emph on
14465 using
14466 \emph default
14467  attribute will have no effect on the generated code for a 
14468 \emph on
14469 non-interrupt
14470 \emph default
14471  function (but may occasionally be useful anyway
14472 \begin_inset Foot
14473 status open
14474
14475 \begin_layout Standard
14476 possible exception: if a function is called ONLY from 'interrupt' functions
14477  using a particular bank, it can be declared with the same 'using' attribute
14478  as the calling 'interrupt' functions.
14479  For instance, if you have several ISRs using bank one, and all of them
14480  call memcpy(), it might make sense to create a specialized version of memcpy()
14481  'using 1', since this would prevent the ISR from having to save bank zero
14482  to the stack on entry and switch to bank zero before calling the function
14483 \end_layout
14484
14485 \end_inset
14486
14487 ).
14488 \newline
14489
14490 \emph on
14491 (pending: Note, nowadays the 
14492 \emph default
14493 using
14494 \emph on
14495  attribute has an effect on
14496 \emph default
14497  
14498 \emph on
14499 the generated code for a 
14500 \emph default
14501 non-interrupt
14502 \emph on
14503  function
14504 \emph default
14505 .
14506 \emph on
14507 )
14508 \end_layout
14509
14510 \begin_layout Standard
14511 An 
14512 \emph on
14513 interrupt
14514 \emph default
14515  function using a non-zero bank will assume that it can trash that register
14516  bank, and will not save it.
14517  Since high-priority interrupts
14518 \begin_inset LatexCommand \index{interrupts}
14519
14520 \end_inset
14521
14522
14523 \begin_inset LatexCommand \index{interrupt priority}
14524
14525 \end_inset
14526
14527  can interrupt low-priority ones on the 8051 and friends, this means that
14528  if a high-priority ISR 
14529 \emph on
14530 using
14531 \emph default
14532  a particular bank occurs while processing a low-priority ISR 
14533 \emph on
14534 using
14535 \emph default
14536  the same bank, terrible and bad things can happen.
14537  To prevent this, no single register bank should be 
14538 \emph on
14539 used
14540 \emph default
14541  by both a high priority and a low priority ISR.
14542  This is probably most easily done by having all high priority ISRs use
14543  one bank and all low priority ISRs use another.
14544  If you have an ISR which can change priority at runtime, you're on your
14545  own: I suggest using the default bank zero and taking the small performance
14546  hit.
14547 \end_layout
14548
14549 \begin_layout Standard
14550 It is most efficient if your ISR calls no other functions.
14551  If your ISR must call other functions, it is most efficient if those functions
14552  use the same bank as the ISR (see note 1 below); the next best is if the
14553  called functions use bank zero.
14554  It is very inefficient to call a function using a different, non-zero bank
14555  from an ISR.
14556  
14557 \begin_inset VSpace bigskip
14558 \end_inset
14559
14560
14561 \end_layout
14562
14563 \begin_layout Section
14564 Startup Code
14565 \begin_inset LatexCommand \label{sub:Startup-Code}
14566
14567 \end_inset
14568
14569
14570 \begin_inset LatexCommand \index{Startup code}
14571
14572 \end_inset
14573
14574
14575 \end_layout
14576
14577 \begin_layout Subsection
14578 MCS51/DS390 Startup Code
14579 \end_layout
14580
14581 \begin_layout Standard
14582 The compiler triggers the linker to link certain initialization modules
14583  from the runtime library
14584 \begin_inset LatexCommand \index{Runtime library}
14585
14586 \end_inset
14587
14588  called crt<something>.
14589  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14590  GSINIT5) is not linked unless the --xstack option is used.
14591  These modules are highly entangled by the use of special segments/areas,
14592  but a common layout is shown below:
14593 \end_layout
14594
14595 \begin_layout Verse
14596
14597 \family typewriter
14598 \series bold
14599 \size footnotesize
14600 (main.asm)
14601 \end_layout
14602
14603 \begin_layout Verse
14604
14605 \family typewriter
14606 \size footnotesize
14607 \InsetSpace ~
14608 \InsetSpace ~
14609 \InsetSpace ~
14610 \InsetSpace ~
14611 \InsetSpace ~
14612 \InsetSpace ~
14613 \InsetSpace ~
14614 \InsetSpace ~
14615 .area HOME (CODE)
14616 \newline
14617 __interrupt_vect:
14618 \newline
14619 \InsetSpace ~
14620 \InsetSpace ~
14621 \InsetSpace ~
14622 \InsetSpace ~
14623 \InsetSpace ~
14624 \InsetSpace ~
14625 \InsetSpace ~
14626 \InsetSpace ~
14627 ljmp __sdcc_gsinit_startup
14628 \end_layout
14629
14630 \begin_layout Verse
14631
14632 \family typewriter
14633 \series bold
14634 \size footnotesize
14635 (crtstart.asm)
14636 \end_layout
14637
14638 \begin_layout Verse
14639
14640 \family typewriter
14641 \size footnotesize
14642 \InsetSpace ~
14643 \InsetSpace ~
14644 \InsetSpace ~
14645 \InsetSpace ~
14646 \InsetSpace ~
14647 \InsetSpace ~
14648 \InsetSpace ~
14649 \InsetSpace ~
14650 .area GSINIT0 (CODE)
14651 \newline
14652 __sdcc_gsinit_startup::
14653 \newline
14654 \InsetSpace ~
14655 \InsetSpace ~
14656 \InsetSpace ~
14657 \InsetSpace ~
14658 \InsetSpace ~
14659 \InsetSpace ~
14660 \InsetSpace ~
14661 \InsetSpace ~
14662 mov sp,#__start__stack - 1
14663 \end_layout
14664
14665 \begin_layout Verse
14666
14667 \family typewriter
14668 \series bold
14669 \size footnotesize
14670 (crtxstack.asm)
14671 \end_layout
14672
14673 \begin_layout Verse
14674
14675 \family typewriter
14676 \size footnotesize
14677 \InsetSpace ~
14678 \InsetSpace ~
14679 \InsetSpace ~
14680 \InsetSpace ~
14681 \InsetSpace ~
14682 \InsetSpace ~
14683 \InsetSpace ~
14684 \InsetSpace ~
14685 .area GSINIT1 (CODE)
14686 \newline
14687 __sdcc_init_xstack::
14688 \newline
14689 ; Need to initialize in GSINIT1 in
14690  case the user's __sdcc_external_startup uses the xstack.
14691 \newline
14692 \InsetSpace ~
14693 \InsetSpace ~
14694 \InsetSpace ~
14695 \InsetSpace ~
14696 \InsetSpace ~
14697 \InsetSpace ~
14698 \InsetSpace ~
14699 \InsetSpace ~
14700 mov __XPAGE,#(__start__x
14701 stack >> 8)
14702 \newline
14703 \InsetSpace ~
14704 \InsetSpace ~
14705 \InsetSpace ~
14706 \InsetSpace ~
14707 \InsetSpace ~
14708 \InsetSpace ~
14709 \InsetSpace ~
14710 \InsetSpace ~
14711 mov _spx,#__start__xstack
14712 \end_layout
14713
14714 \begin_layout Verse
14715
14716 \family typewriter
14717 \series bold
14718 \size footnotesize
14719 (crtstart.asm)
14720 \end_layout
14721
14722 \begin_layout Verse
14723
14724 \family typewriter
14725 \size footnotesize
14726 \InsetSpace ~
14727 \InsetSpace ~
14728 \InsetSpace ~
14729 \InsetSpace ~
14730 \InsetSpace ~
14731 \InsetSpace ~
14732 \InsetSpace ~
14733 \InsetSpace ~
14734 .area GSINIT2 (CODE)
14735 \newline
14736 \InsetSpace ~
14737 \InsetSpace ~
14738 \InsetSpace ~
14739 \InsetSpace ~
14740 \InsetSpace ~
14741 \InsetSpace ~
14742 \InsetSpace ~
14743 \InsetSpace ~
14744 lcall __sdcc_external_startup
14745 \newline
14746 \InsetSpace ~
14747 \InsetSpace ~
14748 \InsetSpace ~
14749 \InsetSpace ~
14750 \InsetSpace ~
14751 \InsetSpace ~
14752 \InsetSpace ~
14753 \InsetSpace ~
14754 mov a,dpl
14755 \newline
14756 \InsetSpace ~
14757 \InsetSpace ~
14758 \InsetSpace ~
14759 \InsetSpace ~
14760 \InsetSpace ~
14761 \InsetSpace ~
14762 \InsetSpace ~
14763 \InsetSpace ~
14764 jz __sdcc_init_data
14765 \newline
14766 \InsetSpace ~
14767 \InsetSpace ~
14768 \InsetSpace ~
14769 \InsetSpace ~
14770 \InsetSpace ~
14771 \InsetSpace ~
14772 \InsetSpace ~
14773 \InsetSpace ~
14774 ljmp
14775  __sdcc_program_startup
14776 \newline
14777 __sdcc_init_data:
14778 \end_layout
14779
14780 \begin_layout Verse
14781
14782 \family typewriter
14783 \series bold
14784 \size footnotesize
14785 (crtxinit.asm)
14786 \end_layout
14787
14788 \begin_layout Verse
14789
14790 \family typewriter
14791 \size footnotesize
14792 \InsetSpace ~
14793 \InsetSpace ~
14794 \InsetSpace ~
14795 \InsetSpace ~
14796 \InsetSpace ~
14797 \InsetSpace ~
14798 \InsetSpace ~
14799 \InsetSpace ~
14800 .area GSINIT3 (CODE)
14801 \newline
14802 __mcs51_genXINIT::
14803 \newline
14804 \InsetSpace ~
14805 \InsetSpace ~
14806 \InsetSpace ~
14807 \InsetSpace ~
14808 \InsetSpace ~
14809 \InsetSpace ~
14810 \InsetSpace ~
14811 \InsetSpace ~
14812 mov r1,#l_XINIT
14813 \newline
14814 \InsetSpace ~
14815 \InsetSpace ~
14816 \InsetSpace ~
14817 \InsetSpace ~
14818 \InsetSpace ~
14819 \InsetSpace ~
14820 \InsetSpace ~
14821 \InsetSpace ~
14822 mov a,r1
14823 \newline
14824 \InsetSpace ~
14825 \InsetSpace ~
14826 \InsetSpace ~
14827 \InsetSpace ~
14828 \InsetSpace ~
14829 \InsetSpace ~
14830 \InsetSpace ~
14831 \InsetSpace ~
14832 orl a,#(l_XINIT
14833  >> 8)
14834 \newline
14835 \InsetSpace ~
14836 \InsetSpace ~
14837 \InsetSpace ~
14838 \InsetSpace ~
14839 \InsetSpace ~
14840 \InsetSpace ~
14841 \InsetSpace ~
14842 \InsetSpace ~
14843 jz 00003$
14844 \newline
14845 \InsetSpace ~
14846 \InsetSpace ~
14847 \InsetSpace ~
14848 \InsetSpace ~
14849 \InsetSpace ~
14850 \InsetSpace ~
14851 \InsetSpace ~
14852 \InsetSpace ~
14853 mov r2,#((l_XINIT+255) >> 8)
14854 \newline
14855 \InsetSpace ~
14856 \InsetSpace ~
14857 \InsetSpace ~
14858 \InsetSpace ~
14859 \InsetSpace ~
14860 \InsetSpace ~
14861 \InsetSpace ~
14862 \InsetSpace ~
14863 mov dptr,#s_XINIT
14864 \newline
14865 \InsetSpace ~
14866 \InsetSpace ~
14867 \InsetSpace ~
14868 \InsetSpace ~
14869 \InsetSpace ~
14870 \InsetSpace ~
14871 \InsetSpace ~
14872 \InsetSpace ~
14873 mov r0,#s_XISEG
14874 \newline
14875 \InsetSpace ~
14876 \InsetSpace ~
14877 \InsetSpace ~
14878 \InsetSpace ~
14879 \InsetSpace ~
14880 \InsetSpace ~
14881 \InsetSpace ~
14882 \InsetSpace ~
14883 mov
14884  __XPAGE,#(s_XISEG >> 8)
14885 \newline
14886 00001$:\InsetSpace ~
14887 clr a
14888 \newline
14889 \InsetSpace ~
14890 \InsetSpace ~
14891 \InsetSpace ~
14892 \InsetSpace ~
14893 \InsetSpace ~
14894 \InsetSpace ~
14895 \InsetSpace ~
14896 \InsetSpace ~
14897 movc a,@a+dptr
14898 \newline
14899 \InsetSpace ~
14900 \InsetSpace ~
14901 \InsetSpace ~
14902 \InsetSpace ~
14903 \InsetSpace ~
14904 \InsetSpace ~
14905 \InsetSpace ~
14906 \InsetSpace ~
14907 movx @r0,a
14908 \newline
14909 \InsetSpace ~
14910 \InsetSpace ~
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 \InsetSpace ~
14916 \InsetSpace ~
14917 inc dptr
14918 \newline
14919 \InsetSpace ~
14920 \InsetSpace ~
14921 \InsetSpace ~
14922 \InsetSpace ~
14923 \InsetSpace ~
14924 \InsetSpace ~
14925 \InsetSpace ~
14926 \InsetSpace ~
14927 inc
14928  r0
14929 \newline
14930 \InsetSpace ~
14931 \InsetSpace ~
14932 \InsetSpace ~
14933 \InsetSpace ~
14934 \InsetSpace ~
14935 \InsetSpace ~
14936 \InsetSpace ~
14937 \InsetSpace ~
14938 cjne r0,#0,00002$
14939 \newline
14940 \InsetSpace ~
14941 \InsetSpace ~
14942 \InsetSpace ~
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 \InsetSpace ~
14946 \InsetSpace ~
14947 \InsetSpace ~
14948 inc __XPAGE
14949 \newline
14950 00002$:\InsetSpace ~
14951 djnz r1,00001$
14952 \newline
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 \InsetSpace ~
14956 \InsetSpace ~
14957 \InsetSpace ~
14958 \InsetSpace ~
14959 \InsetSpace ~
14960 \InsetSpace ~
14961 djnz r2,00001$
14962 \newline
14963 \InsetSpace ~
14964 \InsetSpace ~
14965 \InsetSpace ~
14966 \InsetSpace ~
14967 \InsetSpace ~
14968 \InsetSpace ~
14969 \InsetSpace ~
14970 \InsetSpace ~
14971 mov __XPAGE,#0
14972 xFF
14973 \newline
14974 00003$:
14975 \end_layout
14976
14977 \begin_layout Verse
14978
14979 \family typewriter
14980 \series bold
14981 \size footnotesize
14982 (crtclear.asm)
14983 \end_layout
14984
14985 \begin_layout Verse
14986
14987 \family typewriter
14988 \size footnotesize
14989 \InsetSpace ~
14990 \InsetSpace ~
14991 \InsetSpace ~
14992 \InsetSpace ~
14993 \InsetSpace ~
14994 \InsetSpace ~
14995 \InsetSpace ~
14996 \InsetSpace ~
14997 .area GSINIT4 (CODE)
14998 \newline
14999 __mcs51_genRAMCLEAR::
15000 \newline
15001 \InsetSpace ~
15002 \InsetSpace ~
15003 \InsetSpace ~
15004 \InsetSpace ~
15005 \InsetSpace ~
15006 \InsetSpace ~
15007 \InsetSpace ~
15008 \InsetSpace ~
15009 clr a
15010 \newline
15011 \InsetSpace ~
15012 \InsetSpace ~
15013 \InsetSpace ~
15014 \InsetSpace ~
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 \InsetSpace ~
15018 \InsetSpace ~
15019 mov r0,#(l_IRAM-1)
15020 \newline
15021 00004$:\InsetSpace ~
15022 mov
15023  @r0,a
15024 \newline
15025 \InsetSpace ~
15026 \InsetSpace ~
15027 \InsetSpace ~
15028 \InsetSpace ~
15029 \InsetSpace ~
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 djnz r0,00004$
15034 \newline
15035 ; _mcs51_genRAMCLEAR() end
15036 \end_layout
15037
15038 \begin_layout Verse
15039
15040 \family typewriter
15041 \series bold
15042 \size footnotesize
15043 (crtxclear.asm)
15044 \end_layout
15045
15046 \begin_layout Verse
15047
15048 \family typewriter
15049 \size footnotesize
15050 \InsetSpace ~
15051 \InsetSpace ~
15052 \InsetSpace ~
15053 \InsetSpace ~
15054 \InsetSpace ~
15055 \InsetSpace ~
15056 \InsetSpace ~
15057 \InsetSpace ~
15058 .area GSINIT4 (CODE)
15059 \newline
15060 __mcs51_genXRAMCLEAR::
15061 \newline
15062 \InsetSpace ~
15063 \InsetSpace ~
15064 \InsetSpace ~
15065 \InsetSpace ~
15066 \InsetSpace ~
15067 \InsetSpace ~
15068 \InsetSpace ~
15069 \InsetSpace ~
15070 mov r0,#l_PSEG
15071 \newline
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 \InsetSpace ~
15079 \InsetSpace ~
15080 mov a,r0
15081 \newline
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 jz 00006$
15091 \newline
15092 \InsetSpace ~
15093 \InsetSpace ~
15094 \InsetSpace ~
15095 \InsetSpace ~
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 mov
15101  r1,#s_PSEG
15102 \newline
15103 \InsetSpace ~
15104 \InsetSpace ~
15105 \InsetSpace ~
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
15109 \InsetSpace ~
15110 \InsetSpace ~
15111 mov __XPAGE,#(s_PSEG >> 8)
15112 \newline
15113 \InsetSpace ~
15114 \InsetSpace ~
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 clr a
15122 \newline
15123 00005$:\InsetSpace ~
15124 movx @r1,a
15125 \newline
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 \InsetSpace ~
15134 inc r1
15135 \newline
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 djnz r0,00005$
15145 \newline
15146 0
15147 0006$:
15148 \newline
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 \InsetSpace ~
15155 \InsetSpace ~
15156 \InsetSpace ~
15157 mov r0,#l_XSEG
15158 \newline
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 mov a,r0
15168 \newline
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
15177 orl a,#(l_XSEG >> 8)
15178 \newline
15179 \InsetSpace ~
15180 \InsetSpace ~
15181 \InsetSpace ~
15182 \InsetSpace ~
15183 \InsetSpace ~
15184 \InsetSpace ~
15185 \InsetSpace ~
15186 \InsetSpace ~
15187 jz 00008$
15188 \newline
15189 \InsetSpace ~
15190 \InsetSpace ~
15191 \InsetSpace ~
15192 \InsetSpace ~
15193 \InsetSpace ~
15194 \InsetSpace ~
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 mov r1,#((l_XSEG
15198  + 255) >> 8)
15199 \newline
15200 \InsetSpace ~
15201 \InsetSpace ~
15202 \InsetSpace ~
15203 \InsetSpace ~
15204 \InsetSpace ~
15205 \InsetSpace ~
15206 \InsetSpace ~
15207 \InsetSpace ~
15208 mov dptr,#s_XSEG
15209 \newline
15210 \InsetSpace ~
15211 \InsetSpace ~
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 \InsetSpace ~
15215 \InsetSpace ~
15216 \InsetSpace ~
15217 \InsetSpace ~
15218 clr a
15219 \newline
15220 00007$:\InsetSpace ~
15221 movx @dptr,a
15222 \newline
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 \InsetSpace ~
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 \InsetSpace ~
15229 \InsetSpace ~
15230 \InsetSpace ~
15231 inc dptr
15232 \newline
15233 \InsetSpace ~
15234 \InsetSpace ~
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 \InsetSpace ~
15239 \InsetSpace ~
15240 \InsetSpace ~
15241 djnz r0,00007$
15242 \newline
15243 \InsetSpace ~
15244 \InsetSpace ~
15245 \InsetSpace ~
15246 \InsetSpace ~
15247 \InsetSpace ~
15248 \InsetSpace ~
15249 \InsetSpace ~
15250 \InsetSpace ~
15251 djnz
15252  r1,00007$
15253 \newline
15254 00008$:
15255 \end_layout
15256
15257 \begin_layout Verse
15258
15259 \family typewriter
15260 \series bold
15261 \size footnotesize
15262 (crtxstack.asm)
15263 \end_layout
15264
15265 \begin_layout Verse
15266
15267 \family typewriter
15268 \size footnotesize
15269 \InsetSpace ~
15270 \InsetSpace ~
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 \InsetSpace ~
15274 \InsetSpace ~
15275 \InsetSpace ~
15276 \InsetSpace ~
15277 .area GSINIT5 (CODE)
15278 \newline
15279 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15280  modifies __XPAGE
15281 \newline
15282 ; and __mcs51_genRAMCLEAR modifies _spx.
15283 \newline
15284 \InsetSpace ~
15285 \InsetSpace ~
15286 \InsetSpace ~
15287 \InsetSpace ~
15288 \InsetSpace ~
15289 \InsetSpace ~
15290 \InsetSpace ~
15291 \InsetSpace ~
15292 mov __XPAGE,#(__start__x
15293 stack >> 8)
15294 \newline
15295 \InsetSpace ~
15296 \InsetSpace ~
15297 \InsetSpace ~
15298 \InsetSpace ~
15299 \InsetSpace ~
15300 \InsetSpace ~
15301 \InsetSpace ~
15302 \InsetSpace ~
15303 mov _spx,#__start__xstack
15304 \end_layout
15305
15306 \begin_layout Verse
15307
15308 \family typewriter
15309 \series bold
15310 \size footnotesize
15311 (application modules)
15312 \end_layout
15313
15314 \begin_layout Verse
15315
15316 \family typewriter
15317 \size footnotesize
15318 \InsetSpace ~
15319 \InsetSpace ~
15320 \InsetSpace ~
15321 \InsetSpace ~
15322 \InsetSpace ~
15323 \InsetSpace ~
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 .area GSINIT (CODE)
15327 \end_layout
15328
15329 \begin_layout Verse
15330
15331 \family typewriter
15332 \series bold
15333 \size footnotesize
15334 (main.asm)
15335 \end_layout
15336
15337 \begin_layout Verse
15338
15339 \family typewriter
15340 \size footnotesize
15341 \InsetSpace ~
15342 \InsetSpace ~
15343 \InsetSpace ~
15344 \InsetSpace ~
15345 \InsetSpace ~
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 .area GSFINAL (CODE)
15350 \newline
15351 \InsetSpace ~
15352 \InsetSpace ~
15353 \InsetSpace ~
15354 \InsetSpace ~
15355 \InsetSpace ~
15356 \InsetSpace ~
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 ljmp __sdcc_program_startup
15360 \newline
15361 ;---------------------------------
15362 -----------------------
15363 \newline
15364 ; Home
15365 \newline
15366 ;--------------------------------------------------
15367 ------
15368 \newline
15369 \InsetSpace ~
15370 \InsetSpace ~
15371 \InsetSpace ~
15372 \InsetSpace ~
15373 \InsetSpace ~
15374 \InsetSpace ~
15375 \InsetSpace ~
15376 \InsetSpace ~
15377 .area HOME (CODE)
15378 \newline
15379 \InsetSpace ~
15380 \InsetSpace ~
15381 \InsetSpace ~
15382 \InsetSpace ~
15383 \InsetSpace ~
15384 \InsetSpace ~
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 .area CSEG (CODE)
15388 \newline
15389 __sdcc_program_startup:
15390 \newline
15391 \InsetSpace ~
15392 \InsetSpace ~
15393 \InsetSpace ~
15394 \InsetSpace ~
15395 \InsetSpace ~
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 lcall _main
15400 \newline
15401 ;
15402  return from main will lock up
15403 \newline
15404 \InsetSpace ~
15405 \InsetSpace ~
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 \InsetSpace ~
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 \InsetSpace ~
15412 sjmp .
15413 \end_layout
15414
15415 \begin_layout Standard
15416 One of these modules (crtstart.asm) contains a call to the C routine 
15417 \emph on
15418 _sdcc_external_startup()
15419 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15420
15421 \end_inset
15422
15423
15424 \series bold
15425 \emph default
15426  
15427 \series default
15428 at the start of the CODE area.
15429  This routine is also in the runtime library
15430 \begin_inset LatexCommand \index{Runtime library}
15431
15432 \end_inset
15433
15434  and returns 0 by default.
15435  If this routine returns a non-zero value, the static & global variable
15436  initialization will be skipped and the function main will be invoked.
15437  Otherwise static & global variables will be initialized before the function
15438  main is invoked.
15439  You could add an 
15440 \emph on
15441 _sdcc_external_startup()
15442 \emph default
15443  routine to your program to override the default if you need to setup hardware
15444  or perform some other critical operation prior to static & global variable
15445  initialization
15446 \begin_inset LatexCommand \index{Variable initialization}
15447
15448 \end_inset
15449
15450 .
15451  On some mcs51 variants xdata
15452 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15453
15454 \end_inset
15455
15456  memory has to be explicitly enabled before it can be accessed or if the
15457  watchdog
15458 \begin_inset LatexCommand \index{watchdog}
15459
15460 \end_inset
15461
15462  needs to be disabled, this is the place to do it.
15463  The startup code clears all internal data memory, 256 bytes by default,
15464  but from 0 to n-1 if 
15465 \emph on
15466 -
15467 \begin_inset ERT
15468 status collapsed
15469
15470 \begin_layout Standard
15471
15472
15473 \backslash
15474 /
15475 \end_layout
15476
15477 \end_inset
15478
15479 -iram-size
15480 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15481
15482 \end_inset
15483
15484 n
15485 \emph default
15486  is used.
15487  (recommended for Chipcon CC1010).
15488 \end_layout
15489
15490 \begin_layout Standard
15491 See also the compiler options 
15492 \emph on
15493 -
15494 \begin_inset ERT
15495 status collapsed
15496
15497 \begin_layout Standard
15498
15499
15500 \backslash
15501 /
15502 \end_layout
15503
15504 \end_inset
15505
15506 -no-xinit
15507 \emph default
15508 -
15509 \emph on
15510 opt
15511 \emph default
15512
15513 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15514
15515 \end_inset
15516
15517
15518 \emph on
15519 -
15520 \begin_inset ERT
15521 status collapsed
15522
15523 \begin_layout Standard
15524
15525
15526 \backslash
15527 /
15528 \end_layout
15529
15530 \end_inset
15531
15532 -main-return
15533 \emph default
15534
15535 \begin_inset LatexCommand \index{-\/-main-return}
15536
15537 \end_inset
15538
15539  and section 
15540 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15541
15542 \end_inset
15543
15544  about MCS51-variants.
15545 \begin_inset VSpace bigskip
15546 \end_inset
15547
15548
15549 \end_layout
15550
15551 \begin_layout Subsection
15552 HC08 Startup Code
15553 \end_layout
15554
15555 \begin_layout Standard
15556 The HC08
15557 \begin_inset LatexCommand \index{HC08}
15558
15559 \end_inset
15560
15561  startup code follows the same scheme as the MCS51 startup code.
15562 \begin_inset VSpace bigskip
15563 \end_inset
15564
15565
15566 \end_layout
15567
15568 \begin_layout Subsection
15569 Z80 Startup Code
15570 \end_layout
15571
15572 \begin_layout Standard
15573 On the Z80
15574 \begin_inset LatexCommand \index{Z80}
15575
15576 \end_inset
15577
15578  the startup code is inserted by linking with crt0.o which is generated from
15579  sdcc/device/lib/z80/crt0.s.
15580  If you need a different startup code you can use the compiler option 
15581 \emph on
15582 -
15583 \series bold
15584 \emph default
15585
15586 \begin_inset ERT
15587 status collapsed
15588
15589 \begin_layout Standard
15590
15591
15592 \backslash
15593 /
15594 \end_layout
15595
15596 \end_inset
15597
15598
15599 \series default
15600 \emph on
15601 -no-std-crt0
15602 \emph default
15603
15604 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15605
15606 \end_inset
15607
15608  and provide your own crt0.o.
15609  
15610 \begin_inset VSpace bigskip
15611 \end_inset
15612
15613
15614 \end_layout
15615
15616 \begin_layout Section
15617 Inline Assembler Code
15618 \begin_inset LatexCommand \index{Assembler routines}
15619
15620 \end_inset
15621
15622
15623 \end_layout
15624
15625 \begin_layout Subsection
15626 A Step by Step Introduction
15627 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15628
15629 \end_inset
15630
15631
15632 \end_layout
15633
15634 \begin_layout Standard
15635 Starting from a small snippet of c-code this example shows for the MCS51
15636  how to use inline assembly, access variables, a function parameter and
15637  an array in xdata memory.
15638  The example uses an MCS51 here but is easily adapted for other architectures.
15639  This is a buffer routine which should be optimized:
15640 \end_layout
15641
15642 \begin_layout Verse
15643
15644 \family typewriter
15645 \size footnotesize
15646 unsigned char __far
15647 \begin_inset LatexCommand \index{far (storage class)}
15648
15649 \end_inset
15650
15651
15652 \begin_inset LatexCommand \index{\_\_far (storage class)}
15653
15654 \end_inset
15655
15656  __at
15657 \begin_inset LatexCommand \index{at}
15658
15659 \end_inset
15660
15661
15662 \begin_inset LatexCommand \index{\_\_at}
15663
15664 \end_inset
15665
15666 (0x7f00) buf[0x100];
15667 \begin_inset LatexCommand \index{Aligned array}
15668
15669 \end_inset
15670
15671
15672 \newline
15673 unsigned char head, tail;\InsetSpace ~
15674 \InsetSpace ~
15675 \InsetSpace ~
15676 \InsetSpace ~
15677 \InsetSpace ~
15678 \InsetSpace ~
15679 \InsetSpace ~
15680 \InsetSpace ~
15681 \InsetSpace ~
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 \InsetSpace ~
15688 \InsetSpace ~
15689 \InsetSpace ~
15690 /* if interrupts
15691 \begin_inset LatexCommand \index{interrupt}
15692
15693 \end_inset
15694
15695  are involved see
15696 \newline
15697 \InsetSpace ~
15698 \InsetSpace ~
15699 \InsetSpace ~
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 \InsetSpace ~
15703 \InsetSpace ~
15704 \InsetSpace ~
15705 \InsetSpace ~
15706 \InsetSpace ~
15707 \InsetSpace ~
15708 \InsetSpace ~
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 \InsetSpace ~
15716 \InsetSpace ~
15717 \InsetSpace ~
15718 \InsetSpace ~
15719 \InsetSpace ~
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 \InsetSpace ~
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 \InsetSpace ~
15729 \InsetSpace ~
15730 \InsetSpace ~
15731 \InsetSpace ~
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 \InsetSpace ~
15741 \InsetSpace ~
15742 section 
15743 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15744
15745 \end_inset
15746
15747  about
15748 \series bold
15749  volatile
15750 \series default
15751  */
15752 \newline
15753
15754 \newline
15755 void to_buffer( unsigned char c ) 
15756 \newline
15757 {
15758 \newline
15759 \InsetSpace ~
15760 \InsetSpace ~
15761 \InsetSpace ~
15762 \InsetSpace ~
15763 if( head != (unsigned char)(tail-1)
15764  )\InsetSpace ~
15765 /* cast 
15766 \series bold
15767 needed
15768 \series default
15769  to avoid promotion
15770 \begin_inset LatexCommand \index{promotion to signed int}
15771
15772 \end_inset
15773
15774
15775 \begin_inset LatexCommand \index{type promotion}
15776
15777 \end_inset
15778
15779  to integer */
15780 \begin_inset Marginal
15781 status collapsed
15782
15783 \begin_layout Standard
15784
15785 \series bold
15786 \InsetSpace ~
15787 !
15788 \end_layout
15789
15790 \end_inset
15791
15792
15793 \newline
15794 \InsetSpace ~
15795 \InsetSpace ~
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 buf[ head++ ] = c;\InsetSpace ~
15803 \InsetSpace ~
15804 \InsetSpace ~
15805 \InsetSpace ~
15806 \InsetSpace ~
15807 \InsetSpace ~
15808 \InsetSpace ~
15809 \InsetSpace ~
15810 \InsetSpace ~
15811 \InsetSpace ~
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 \InsetSpace ~
15815 \InsetSpace ~
15816 \InsetSpace ~
15817 \InsetSpace ~
15818 /* access to a 256 byte aligned array */
15819 \newline
15820
15821 \end_layout
15822
15823 \begin_layout Standard
15824 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
15825  then a corresponding buffer.asm file is generated.
15826  We define a new function 
15827 \family typewriter
15828 to_buffer_asm()
15829 \family default
15830  in file buffer.c in which we cut and paste the generated code, removing
15831  unwanted comments and some ':'.
15832  Then add 
15833 \begin_inset Quotes sld
15834 \end_inset
15835
15836 _asm
15837 \begin_inset Quotes srd
15838 \end_inset
15839
15840  and 
15841 \begin_inset Quotes sld
15842 \end_inset
15843
15844 _endasm;
15845 \begin_inset Quotes srd
15846 \end_inset
15847
15848  to the beginning and the end of the function body:
15849 \end_layout
15850
15851 \begin_layout Verse
15852
15853 \family typewriter
15854 \size footnotesize
15855 /* With a cut and paste from the .asm file, we have something to start with.
15856 \newline
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 \InsetSpace ~
15860 The
15861  function is not yet OK! (registers aren't saved) */ 
15862 \newline
15863 void to_buffer_asm(
15864  unsigned char c ) 
15865 \newline
15866
15867 \newline
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 _asm
15873 \begin_inset LatexCommand \index{\_asm}
15874
15875 \end_inset
15876
15877
15878 \begin_inset LatexCommand \index{\_\_asm}
15879
15880 \end_inset
15881
15882
15883 \newline
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 mov\InsetSpace ~
15889 \InsetSpace ~
15890 r2,dpl 
15891 \newline
15892 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
15893 /* cast 
15894 \series bold
15895 needed
15896 \series default
15897  to avoid promotion
15898 \begin_inset LatexCommand \index{promotion to signed int}
15899
15900 \end_inset
15901
15902
15903 \begin_inset LatexCommand \index{type promotion}
15904
15905 \end_inset
15906
15907  to integer */
15908 \newline
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 mov\InsetSpace ~
15914 \InsetSpace ~
15915 a,_tail 
15916 \newline
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 dec\InsetSpace ~
15922 \InsetSpace ~
15923
15924 \newline
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 mov\InsetSpace ~
15930 \InsetSpace ~
15931 r3,a 
15932 \newline
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 mov\InsetSpace ~
15938 \InsetSpace ~
15939 a,_head 
15940 \newline
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 cjne a,ar3,00106$ 
15946 \newline
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 ret
15952 \newline
15953 00106$:
15954  
15955 \newline
15956 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
15957 \begin_inset LatexCommand \index{Aligned array}
15958
15959 \end_inset
15960
15961
15962 \newline
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 mov\InsetSpace ~
15968 \InsetSpace ~
15969 r3,_head 
15970 \newline
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 inc\InsetSpace ~
15976 \InsetSpace ~
15977 _head 
15978 \newline
15979 \InsetSpace ~
15980 \InsetSpace ~
15981 \InsetSpace ~
15982 \InsetSpace ~
15983 mov\InsetSpace ~
15984 \InsetSpace ~
15985 dpl,r3 
15986 \newline
15987 \InsetSpace ~
15988 \InsetSpace ~
15989 \InsetSpace ~
15990 \InsetSpace ~
15991 mov\InsetSpace ~
15992 \InsetSpace ~
15993 dph,#(_buf >> 8) 
15994 \newline
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 mov\InsetSpace ~
16000 \InsetSpace ~
16001 a,r2 
16002 \newline
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 movx @dptr,a
16008  
16009 \newline
16010 00103$: 
16011 \newline
16012 \InsetSpace ~
16013 \InsetSpace ~
16014 \InsetSpace ~
16015 \InsetSpace ~
16016 ret
16017 \newline
16018 \InsetSpace ~
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 _endasm
16023 \begin_inset LatexCommand \index{\_endasm}
16024
16025 \end_inset
16026
16027
16028 \begin_inset LatexCommand \index{\_\_endasm}
16029
16030 \end_inset
16031
16032 ;
16033 \newline
16034
16035 \end_layout
16036
16037 \begin_layout Standard
16038 The new file buffer.c should compile with only one warning about the unreferenced
16039  function argument 'c'.
16040  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16041  (1) and finally have:
16042 \end_layout
16043
16044 \begin_layout Verse
16045
16046 \family typewriter
16047 \size footnotesize
16048 unsigned char __far __at(0x7f00) buf[0x100];
16049 \newline
16050 unsigned char head, tail;
16051 \newline
16052 #define
16053  USE_ASSEMBLY (1)
16054 \newline
16055
16056 \newline
16057 #if !USE_ASSEMBLY
16058 \newline
16059
16060 \newline
16061 void to_buffer( unsigned char c )
16062 \newline
16063 {
16064 \newline
16065 \InsetSpace ~
16066 \InsetSpace ~
16067 \InsetSpace ~
16068 \InsetSpace ~
16069 if(
16070  head != (unsigned char)(tail-1) )
16071 \newline
16072 \InsetSpace ~
16073 \InsetSpace ~
16074 \InsetSpace ~
16075 \InsetSpace ~
16076 \InsetSpace ~
16077 \InsetSpace ~
16078 \InsetSpace ~
16079 \InsetSpace ~
16080 buf[ head++ ] = c;
16081 \newline
16082 }
16083 \newline
16084
16085 \newline
16086 #else
16087 \newline
16088
16089 \newline
16090 void to_buffer(
16091  unsigned char c )
16092 \newline
16093 {
16094 \newline
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 \InsetSpace ~
16099 c; // to avoid warning: unreferenced function argument
16100 \newline
16101 \InsetSpace ~
16102 \InsetSpace ~
16103 \InsetSpace ~
16104 \InsetSpace ~
16105 _asm
16106 \begin_inset LatexCommand \index{\_asm}
16107
16108 \end_inset
16109
16110
16111 \begin_inset LatexCommand \index{\_\_asm}
16112
16113 \end_inset
16114
16115
16116 \newline
16117 \InsetSpace ~
16118 \InsetSpace ~
16119 \InsetSpace ~
16120 \InsetSpace ~
16121 \InsetSpace ~
16122 \InsetSpace ~
16123 \InsetSpace ~
16124 \InsetSpace ~
16125 ; save used registers here.
16126  
16127 \newline
16128 \InsetSpace ~
16129 \InsetSpace ~
16130 \InsetSpace ~
16131 \InsetSpace ~
16132 \InsetSpace ~
16133 \InsetSpace ~
16134 \InsetSpace ~
16135 \InsetSpace ~
16136 ; If we were still using r2,r3 we would have to push them here.
16137  
16138 \newline
16139 ; if( head != (unsigned char)(tail-1) )
16140 \newline
16141 \InsetSpace ~
16142 \InsetSpace ~
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 mov\InsetSpace ~
16150  a,_tail
16151 \newline
16152 \InsetSpace ~
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 \InsetSpace ~
16158 \InsetSpace ~
16159 \InsetSpace ~
16160 dec\InsetSpace ~
16161  a
16162 \newline
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 \InsetSpace ~
16166 \InsetSpace ~
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 xrl\InsetSpace ~
16172  a,_head
16173 \newline
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 ; we
16183  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16184 \newline
16185 \InsetSpace ~
16186 \InsetSpace ~
16187 \InsetSpace ~
16188 \InsetSpace ~
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 jz\InsetSpace ~
16194 \InsetSpace ~
16195  t_b_end$
16196 \newline
16197 \InsetSpace ~
16198 \InsetSpace ~
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 ;
16206 \newline
16207 ;
16208  buf[ head++ ] = c;
16209 \newline
16210 \InsetSpace ~
16211 \InsetSpace ~
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 mov\InsetSpace ~
16219  a,dpl \InsetSpace ~
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 ; dpl holds lower byte of function argument
16227 \newline
16228 \InsetSpace ~
16229 \InsetSpace ~
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 mov\InsetSpace ~
16237
16238  dpl,_head \InsetSpace ~
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 ; buf is 0x100 byte aligned so head can be used directly
16242 \newline
16243 \InsetSpace ~
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 \InsetSpace ~
16249 \InsetSpace ~
16250 \InsetSpace ~
16251 mov\InsetSpace ~
16252  dph,#(_bu
16253 f>>8)
16254 \newline
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 \InsetSpace ~
16259 \InsetSpace ~
16260 \InsetSpace ~
16261 \InsetSpace ~
16262 \InsetSpace ~
16263 movx @dptr,a
16264 \newline
16265 \InsetSpace ~
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 \InsetSpace ~
16269 \InsetSpace ~
16270 \InsetSpace ~
16271 \InsetSpace ~
16272 \InsetSpace ~
16273 inc \InsetSpace ~
16274 _head
16275 \newline
16276 \InsetSpace ~
16277 \InsetSpace ~
16278 \InsetSpace ~
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 \InsetSpace ~
16283 \InsetSpace ~
16284 ; we could do an ANL _head,#0x0f here to use a
16285  smaller buffer (see above)
16286 \newline
16287 t_b_end$:
16288 \newline
16289 \InsetSpace ~
16290 \InsetSpace ~
16291 \InsetSpace ~
16292 \InsetSpace ~
16293 \InsetSpace ~
16294 \InsetSpace ~
16295 \InsetSpace ~
16296 \InsetSpace ~
16297 ; restore used registers here 
16298 \newline
16299 \InsetSpace ~
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 \InsetSpace ~
16303 _endasm
16304 \begin_inset LatexCommand \index{\_endasm}
16305
16306 \end_inset
16307
16308
16309 \begin_inset LatexCommand \index{\_\_endasm}
16310
16311 \end_inset
16312
16313 ;
16314 \newline
16315 }
16316 \newline
16317 #endif
16318 \end_layout
16319
16320 \begin_layout Standard
16321 The inline assembler code can contain any valid code understood by the assembler
16322 , this includes any assembler directives and comment lines.
16323  The assembler does not like some characters like ':' or ''' in comments.
16324  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16325 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16326
16327 \end_inset
16328
16329
16330 \begin_inset LatexCommand \index{Assembler documentation}
16331
16332 \end_inset
16333
16334  or online at 
16335 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16336
16337 \end_inset
16338
16339 \InsetSpace ~
16340 .
16341 \end_layout
16342
16343 \begin_layout Standard
16344 The compiler does not do any validation of the code within the 
16345 \family typewriter
16346 _asm
16347 \begin_inset LatexCommand \index{\_asm}
16348
16349 \end_inset
16350
16351
16352 \begin_inset LatexCommand \index{\_\_asm}
16353
16354 \end_inset
16355
16356  ...
16357  _endasm
16358 \size footnotesize
16359
16360 \begin_inset LatexCommand \index{\_endasm}
16361
16362 \end_inset
16363
16364
16365 \begin_inset LatexCommand \index{\_\_endasm}
16366
16367 \end_inset
16368
16369
16370 \size default
16371 ;
16372 \family default
16373  keyword pair.
16374  Specifically it will not know which registers are used and thus register
16375  pushing/popping
16376 \begin_inset LatexCommand \index{push/pop}
16377
16378 \end_inset
16379
16380  has to be done manually.
16381  
16382 \end_layout
16383
16384 \begin_layout Standard
16385 It is recommended that each assembly instruction (including labels) be placed
16386  in a separate line (as the example shows).
16387  When the -
16388 \begin_inset ERT
16389 status collapsed
16390
16391 \begin_layout Standard
16392
16393
16394 \backslash
16395 /
16396 \end_layout
16397
16398 \end_inset
16399
16400 -
16401 \emph on
16402 peep-asm
16403 \begin_inset LatexCommand \index{-\/-peep-asm}
16404
16405 \end_inset
16406
16407
16408 \emph default
16409  command line option is used, the inline assembler code will be passed through
16410  the peephole optimizer
16411 \begin_inset LatexCommand \index{Peephole optimizer}
16412
16413 \end_inset
16414
16415 .
16416  There are only a few (if any) cases where this option makes sense, it might
16417  cause some unexpected changes in the inline assembler code.
16418  Please go through the peephole optimizer rules defined in file 
16419 \emph on
16420 SDCCpeeph.def
16421 \emph default
16422  before using this option.
16423 \end_layout
16424
16425 \begin_layout Subsection
16426 Naked Functions
16427 \begin_inset LatexCommand \label{sub:Naked-Functions}
16428
16429 \end_inset
16430
16431
16432 \begin_inset LatexCommand \index{Naked functions}
16433
16434 \end_inset
16435
16436
16437 \end_layout
16438
16439 \begin_layout Standard
16440 A special keyword may be associated with a function declaring it as 
16441 \emph on
16442 _naked
16443 \begin_inset LatexCommand \index{\_naked}
16444
16445 \end_inset
16446
16447
16448 \begin_inset LatexCommand \index{\_\_naked}
16449
16450 \end_inset
16451
16452 .
16453  
16454 \emph default
16455 The 
16456 \emph on
16457 _naked
16458 \emph default
16459  function modifier attribute prevents the compiler from generating prologue
16460 \begin_inset LatexCommand \index{function prologue}
16461
16462 \end_inset
16463
16464  and epilogue
16465 \begin_inset LatexCommand \index{function epilogue}
16466
16467 \end_inset
16468
16469  code for that function.
16470  This means that the user is entirely responsible for such things as saving
16471  any registers that may need to be preserved, selecting the proper register
16472  bank, generating the 
16473 \emph on
16474 return
16475 \emph default
16476  instruction at the end, etc.
16477  Practically, this means that the contents of the function must be written
16478  in inline assembler.
16479  This is particularly useful for interrupt functions, which can have a large
16480  (and often unnecessary) prologue/epilogue.
16481  For example, compare the code generated by these two functions:
16482 \end_layout
16483
16484 \begin_layout Verse
16485
16486 \family typewriter
16487 volatile
16488 \begin_inset LatexCommand \index{volatile}
16489
16490 \end_inset
16491
16492  data unsigned char counter;
16493 \newline
16494
16495 \newline
16496 void simpleInterrupt(void) __interrupt
16497 \begin_inset LatexCommand \index{interrupt}
16498
16499 \end_inset
16500
16501
16502 \begin_inset LatexCommand \index{\_\_interrupt}
16503
16504 \end_inset
16505
16506  (1)
16507 \newline
16508 {
16509 \newline
16510 \InsetSpace ~
16511 \InsetSpace ~
16512 \InsetSpace ~
16513 \InsetSpace ~
16514 counter++;
16515 \newline
16516 }
16517 \newline
16518
16519 \newline
16520 void nakedInterrupt(void) __interrupt (2) __naked
16521 \newline
16522 {
16523 \newline
16524 \InsetSpace ~
16525 \InsetSpace ~
16526 \InsetSpace ~
16527 \InsetSpace ~
16528 _asm
16529 \begin_inset LatexCommand \index{\_asm}
16530
16531 \end_inset
16532
16533
16534 \begin_inset LatexCommand \index{\_\_asm}
16535
16536 \end_inset
16537
16538
16539 \newline
16540 \InsetSpace ~
16541 \InsetSpace ~
16542 \InsetSpace ~
16543 \InsetSpace ~
16544 \InsetSpace ~
16545 \InsetSpace ~
16546 inc\InsetSpace ~
16547 \InsetSpace ~
16548 \InsetSpace ~
16549 \InsetSpace ~
16550 \InsetSpace ~
16551 _counter ; does not change flags, no need to save psw
16552 \newline
16553 \InsetSpace ~
16554 \InsetSpace ~
16555 \InsetSpace ~
16556 \InsetSpace ~
16557 \InsetSpace ~
16558 \InsetSpace ~
16559 reti\InsetSpace ~
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 ; MUST explicitly
16564  include ret or reti in _naked function.
16565 \newline
16566 \InsetSpace ~
16567 \InsetSpace ~
16568 \InsetSpace ~
16569 \InsetSpace ~
16570 _endasm
16571 \begin_inset LatexCommand \index{\_endasm}
16572
16573 \end_inset
16574
16575
16576 \begin_inset LatexCommand \index{\_\_endasm}
16577
16578 \end_inset
16579
16580 ;
16581 \newline
16582 }
16583 \end_layout
16584
16585 \begin_layout Standard
16586 For an 8051 target, the generated simpleInterrupt looks like:
16587 \end_layout
16588
16589 \begin_layout Verse
16590
16591 \family typewriter
16592 Note, this is an 
16593 \emph on
16594 outdated
16595 \emph default
16596  example, recent versions of SDCC generate
16597 \newline
16598 the 
16599 \emph on
16600 same
16601 \emph default
16602  code for simpleInterrupt() and nakedInterrupt()!
16603 \newline
16604
16605 \newline
16606 _simpleInterrupt:
16607 \newline
16608 \InsetSpace ~
16609 \InsetSpace ~
16610 \InsetSpace ~
16611 \InsetSpace ~
16612 push\InsetSpace ~
16613 \InsetSpace ~
16614 \InsetSpace ~
16615 \InsetSpace ~
16616 acc
16617 \newline
16618 \InsetSpace ~
16619 \InsetSpace ~
16620 \InsetSpace ~
16621 \InsetSpace ~
16622 push\InsetSpace ~
16623 \InsetSpace ~
16624 \InsetSpace ~
16625 \InsetSpace ~
16626 b
16627 \newline
16628 \InsetSpace ~
16629 \InsetSpace ~
16630 \InsetSpace ~
16631 \InsetSpace ~
16632 pu
16633 sh\InsetSpace ~
16634 \InsetSpace ~
16635 \InsetSpace ~
16636 \InsetSpace ~
16637 dpl
16638 \newline
16639 \InsetSpace ~
16640 \InsetSpace ~
16641 \InsetSpace ~
16642 \InsetSpace ~
16643 push\InsetSpace ~
16644 \InsetSpace ~
16645 \InsetSpace ~
16646 \InsetSpace ~
16647 dph
16648 \newline
16649 \InsetSpace ~
16650 \InsetSpace ~
16651 \InsetSpace ~
16652 \InsetSpace ~
16653 push\InsetSpace ~
16654 \InsetSpace ~
16655 \InsetSpace ~
16656 \InsetSpace ~
16657 psw
16658 \newline
16659 \InsetSpace ~
16660 \InsetSpace ~
16661 \InsetSpace ~
16662 \InsetSpace ~
16663 mov\InsetSpace ~
16664 \InsetSpace ~
16665 \InsetSpace ~
16666 \InsetSpace ~
16667 \InsetSpace ~
16668 psw,#0x00
16669 \newline
16670 \InsetSpace ~
16671 \InsetSpace ~
16672 \InsetSpace ~
16673 \InsetSpace ~
16674 inc\InsetSpace ~
16675 \InsetSpace ~
16676 \InsetSpace ~
16677 \InsetSpace ~
16678 \InsetSpace ~
16679 _counter
16680 \newline
16681 \InsetSpace ~
16682 \InsetSpace ~
16683 \InsetSpace ~
16684 \InsetSpace ~
16685 pop\InsetSpace ~
16686 \InsetSpace ~
16687 \InsetSpace ~
16688 \InsetSpace ~
16689 \InsetSpace ~
16690 psw
16691 \newline
16692 \InsetSpace ~
16693 \InsetSpace ~
16694 \InsetSpace ~
16695 \InsetSpace ~
16696 pop\InsetSpace ~
16697 \InsetSpace ~
16698 \InsetSpace ~
16699 \InsetSpace ~
16700 \InsetSpace ~
16701 dph
16702 \newline
16703 \InsetSpace ~
16704 \InsetSpace ~
16705 \InsetSpace ~
16706 \InsetSpace ~
16707 pop\InsetSpace ~
16708 \InsetSpace ~
16709 \InsetSpace ~
16710 \InsetSpace ~
16711 \InsetSpace ~
16712 dpl
16713 \newline
16714 \InsetSpace ~
16715 \InsetSpace ~
16716 \InsetSpace ~
16717 \InsetSpace ~
16718 pop\InsetSpace ~
16719 \InsetSpace ~
16720 \InsetSpace ~
16721 \InsetSpace ~
16722 \InsetSpace ~
16723 b
16724 \newline
16725 \InsetSpace ~
16726 \InsetSpace ~
16727 \InsetSpace ~
16728 \InsetSpace ~
16729 pop\InsetSpace ~
16730 \InsetSpace ~
16731 \InsetSpace ~
16732 \InsetSpace ~
16733 \InsetSpace ~
16734 acc
16735 \newline
16736 \InsetSpace ~
16737 \InsetSpace ~
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 reti
16741 \end_layout
16742
16743 \begin_layout Standard
16744 whereas nakedInterrupt looks like:
16745 \end_layout
16746
16747 \begin_layout Verse
16748
16749 \family typewriter
16750 _nakedInterrupt:
16751 \newline
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 \InsetSpace ~
16756 inc\InsetSpace ~
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 \InsetSpace ~
16760 _counter ; does not change flags, no need to save psw
16761 \newline
16762 \InsetSpace ~
16763 \InsetSpace ~
16764 \InsetSpace ~
16765 \InsetSpace ~
16766 reti\InsetSpace ~
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 \InsetSpace ~
16773 \InsetSpace ~
16774 \InsetSpace ~
16775 \InsetSpace ~
16776 \InsetSpace ~
16777 \InsetSpace ~
16778 ;
16779  MUST explicitly include ret or reti in _naked function
16780 \end_layout
16781
16782 \begin_layout Standard
16783 The related directive #pragma exclude
16784 \begin_inset LatexCommand \index{\#pragma exclude}
16785
16786 \end_inset
16787
16788  allows a more fine grained control over pushing & popping
16789 \begin_inset LatexCommand \index{push/pop}
16790
16791 \end_inset
16792
16793  the registers.
16794 \end_layout
16795
16796 \begin_layout Standard
16797 While there is nothing preventing you from writing C code inside a 
16798 \family typewriter
16799 _naked
16800 \family default
16801  function, there are many ways to shoot yourself in the foot doing this,
16802  and it is recommended that you stick to inline assembler.
16803 \end_layout
16804
16805 \begin_layout Subsection
16806 Use of Labels within Inline Assembler
16807 \end_layout
16808
16809 \begin_layout Standard
16810 SDCC allows the use of in-line assembler with a few restrictions regarding
16811  labels.
16812  In older versions of the compiler all labels defined within inline assembler
16813  code 
16814 \emph on
16815 had to be
16816 \emph default
16817  of the form 
16818 \emph on
16819 nnnnn$
16820 \emph default
16821  where nnnn is a number less than 100 (which implies a limit of utmost 100
16822  inline assembler labels 
16823 \emph on
16824 per function
16825 \emph default
16826 \noun on
16827 )
16828 \noun default
16829 .
16830  
16831 \end_layout
16832
16833 \begin_layout Verse
16834
16835 \family typewriter
16836 _asm
16837 \begin_inset LatexCommand \index{\_asm}
16838
16839 \end_inset
16840
16841
16842 \begin_inset LatexCommand \index{\_\_asm}
16843
16844 \end_inset
16845
16846  
16847 \newline
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 mov\InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 b,#10 
16858 \newline
16859 00001$: 
16860 \newline
16861 \InsetSpace ~
16862 \InsetSpace ~
16863 \InsetSpace ~
16864 \InsetSpace ~
16865 djnz\InsetSpace ~
16866 \InsetSpace ~
16867 \InsetSpace ~
16868 \InsetSpace ~
16869 b,00001$ 
16870 \newline
16871 _endasm
16872 \begin_inset LatexCommand \index{\_endasm}
16873
16874 \end_inset
16875
16876
16877 \begin_inset LatexCommand \index{\_\_endasm}
16878
16879 \end_inset
16880
16881  ;
16882 \end_layout
16883
16884 \begin_layout Standard
16885 Inline assembler code cannot reference any C-Labels, however it can reference
16886  labels
16887 \begin_inset LatexCommand \index{Labels}
16888
16889 \end_inset
16890
16891  defined by the inline assembler, e.g.:
16892 \end_layout
16893
16894 \begin_layout Verse
16895
16896 \family typewriter
16897 foo() { 
16898 \newline
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 \InsetSpace ~
16902 \InsetSpace ~
16903 /* some c code */ 
16904 \newline
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 _asm 
16910 \newline
16911 \InsetSpace ~
16912 \InsetSpace ~
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 ; some assembler code 
16918 \newline
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 ljmp $0003 
16926 \newline
16927 \InsetSpace ~
16928 \InsetSpace ~
16929 \InsetSpace ~
16930 \InsetSpace ~
16931 _endasm;
16932  
16933 \newline
16934 \InsetSpace ~
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 \InsetSpace ~
16938 /* some more c code */ 
16939 \newline
16940 clabel:\InsetSpace ~
16941 \InsetSpace ~
16942 /* inline assembler cannot reference this
16943  label */ 
16944 \newline
16945 \InsetSpace ~
16946 \InsetSpace ~
16947 \InsetSpace ~
16948 \InsetSpace ~
16949 _asm
16950 \newline
16951 \InsetSpace ~
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 $0003: ;label (can be referenced by inline assembler only)
16956  
16957 \newline
16958 \InsetSpace ~
16959 \InsetSpace ~
16960 \InsetSpace ~
16961 \InsetSpace ~
16962 _endasm
16963 \begin_inset LatexCommand \index{\_endasm}
16964
16965 \end_inset
16966
16967
16968 \begin_inset LatexCommand \index{\_\_endasm}
16969
16970 \end_inset
16971
16972  ; 
16973 \newline
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 \InsetSpace ~
16977 \InsetSpace ~
16978 /* some more c code */
16979 \newline
16980 }
16981 \end_layout
16982
16983 \begin_layout Standard
16984 In other words inline assembly code can access labels defined in inline
16985  assembly within the scope of the function.
16986  The same goes the other way, i.e.
16987  labels defines in inline assembly can not be accessed by C statements.
16988 \end_layout
16989
16990 \begin_layout Section
16991 Interfacing with Assembler Code
16992 \begin_inset LatexCommand \index{Assembler routines}
16993
16994 \end_inset
16995
16996
16997 \end_layout
16998
16999 \begin_layout Subsection
17000 Global Registers used for Parameter Passing
17001 \begin_inset LatexCommand \index{Parameter passing}
17002
17003 \end_inset
17004
17005
17006 \end_layout
17007
17008 \begin_layout Standard
17009 The compiler always uses the global registers 
17010 \emph on
17011 DPL, DPH
17012 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17013
17014 \end_inset
17015
17016
17017 \begin_inset LatexCommand \index{DPTR}
17018
17019 \end_inset
17020
17021 , B
17022 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17023
17024 \end_inset
17025
17026  
17027 \emph default
17028 and
17029 \emph on
17030  ACC
17031 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17032
17033 \end_inset
17034
17035
17036 \emph default
17037  to pass the first parameter to a routine.
17038  The second parameter onwards is either allocated on the stack (for reentrant
17039  routines or if -
17040 \begin_inset ERT
17041 status collapsed
17042
17043 \begin_layout Standard
17044
17045
17046 \backslash
17047 /
17048 \end_layout
17049
17050 \end_inset
17051
17052 -stack-auto is used) or in data / xdata memory (depending on the memory
17053  model).
17054  
17055 \end_layout
17056
17057 \begin_layout Subsection
17058 Assembler Routine (non-reentrant)
17059 \end_layout
17060
17061 \begin_layout Standard
17062 In the following example
17063 \begin_inset LatexCommand \index{reentrant}
17064
17065 \end_inset
17066
17067
17068 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17069
17070 \end_inset
17071
17072  the function c_func calls an assembler routine asm_func, which takes two
17073  parameters
17074 \begin_inset LatexCommand \index{function parameter}
17075
17076 \end_inset
17077
17078 .
17079 \end_layout
17080
17081 \begin_layout Verse
17082
17083 \family typewriter
17084 extern int asm_func(unsigned char, unsigned char);
17085 \newline
17086
17087 \newline
17088 int c_func (unsigned char
17089  i, unsigned char j)
17090 \newline
17091 {
17092 \newline
17093 \InsetSpace ~
17094 \InsetSpace ~
17095 \InsetSpace ~
17096 \InsetSpace ~
17097 return asm_func(i,j);
17098 \newline
17099 }
17100 \newline
17101
17102 \newline
17103 int main()
17104 \newline
17105 {
17106 \newline
17107 \InsetSpace ~
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 return c_func(10,9);
17112 \newline
17113 }
17114 \end_layout
17115
17116 \begin_layout Standard
17117 The corresponding assembler function is:
17118 \end_layout
17119
17120 \begin_layout Verse
17121
17122 \family typewriter
17123 .globl _asm_func_PARM_2 
17124 \newline
17125 \InsetSpace ~
17126 \InsetSpace ~
17127 \InsetSpace ~
17128 \InsetSpace ~
17129 \InsetSpace ~
17130 \InsetSpace ~
17131 \InsetSpace ~
17132 \InsetSpace ~
17133 .globl _asm_func 
17134 \newline
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 \InsetSpace ~
17140 \InsetSpace ~
17141 \InsetSpace ~
17142 \InsetSpace ~
17143 .area OSEG 
17144 \newline
17145 _asm_func_PARM_2:
17146 \newline
17147 \InsetSpace ~
17148 \InsetSpace ~
17149 \InsetSpace ~
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 \InsetSpace ~
17155 .ds   
17156  1 
17157 \newline
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 \InsetSpace ~
17162 \InsetSpace ~
17163 \InsetSpace ~
17164 \InsetSpace ~
17165 \InsetSpace ~
17166 .area CSEG 
17167 \newline
17168 _asm_func: 
17169 \newline
17170 \InsetSpace ~
17171 \InsetSpace ~
17172 \InsetSpace ~
17173 \InsetSpace ~
17174 \InsetSpace ~
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 mov\InsetSpace ~
17179 \InsetSpace ~
17180 \InsetSpace ~
17181 \InsetSpace ~
17182 a,dpl 
17183 \newline
17184 \InsetSpace ~
17185 \InsetSpace ~
17186 \InsetSpace ~
17187 \InsetSpace ~
17188 \InsetSpace ~
17189 \InsetSpace ~
17190 \InsetSpace ~
17191 \InsetSpace ~
17192 add\InsetSpace ~
17193 \InsetSpace ~
17194 \InsetSpace ~
17195 \InsetSpace ~
17196 a,_asm_func_PARM_2 
17197 \newline
17198 \InsetSpace ~
17199 \InsetSpace ~
17200 \InsetSpace ~
17201 \InsetSpace ~
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 \InsetSpace ~
17205 \InsetSpace ~
17206 mov\InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 dpl,a 
17211 \newline
17212 \InsetSpace ~
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 mov\InsetSpace ~
17221 \InsetSpace ~
17222 \InsetSpace ~
17223 \InsetSpace ~
17224 dph
17225 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17226
17227 \end_inset
17228
17229 ,#0x00 
17230 \newline
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 \InsetSpace ~
17234 \InsetSpace ~
17235 \InsetSpace ~
17236 \InsetSpace ~
17237 \InsetSpace ~
17238 \InsetSpace ~
17239 ret
17240 \end_layout
17241
17242 \begin_layout Standard
17243 Note here that the return values
17244 \begin_inset LatexCommand \index{return value}
17245
17246 \end_inset
17247
17248  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
17249  two byte values.
17250  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
17251 b' & 'acc' for four byte values.
17252 \end_layout
17253
17254 \begin_layout Standard
17255 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17256  the parameter number starting from 1, and counting from the left.
17257  The first parameter is passed in 
17258 \begin_inset Quotes eld
17259 \end_inset
17260
17261 dpl
17262 \begin_inset Quotes erd
17263 \end_inset
17264
17265  for a one byte parameter, 
17266 \begin_inset Quotes eld
17267 \end_inset
17268
17269 dptr
17270 \begin_inset Quotes erd
17271 \end_inset
17272
17273  for two bytes, 
17274 \begin_inset Quotes eld
17275 \end_inset
17276
17277 b,dptr
17278 \begin_inset Quotes erd
17279 \end_inset
17280
17281  for three bytes and 
17282 \begin_inset Quotes eld
17283 \end_inset
17284
17285 acc,b,dptr
17286 \begin_inset Quotes erd
17287 \end_inset
17288
17289  for a four bytes parameter.
17290  The variable name for the second parameter will be _<function_name>_PARM_2.
17291 \newline
17292
17293 \newline
17294 Assem
17295 ble the assembler routine with the following command:
17296 \newline
17297
17298 \newline
17299
17300 \family sans
17301 \series bold
17302 asx8051 -losg asmfunc.asm
17303 \newline
17304
17305 \newline
17306
17307 \family default
17308 \series default
17309 Then compile and link the assembler routine to the C source file with the
17310  following command:
17311 \newline
17312
17313 \newline
17314
17315 \family sans
17316 \series bold
17317 sdcc cfunc.c asmfunc.rel
17318 \end_layout
17319
17320 \begin_layout Subsection
17321 Assembler Routine (reentrant)
17322 \end_layout
17323
17324 \begin_layout Standard
17325 In this case
17326 \begin_inset LatexCommand \index{reentrant}
17327
17328 \end_inset
17329
17330
17331 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17332
17333 \end_inset
17334
17335  the second parameter
17336 \begin_inset LatexCommand \index{function parameter}
17337
17338 \end_inset
17339
17340  onwards will be passed on the stack, the parameters are pushed from right
17341  to left i.e.
17342  after the call the leftmost parameter will be on the top of the stack.
17343  Here is an example:
17344 \end_layout
17345
17346 \begin_layout Verse
17347
17348 \family typewriter
17349 extern int asm_func(unsigned char, unsigned char);
17350 \newline
17351
17352 \newline
17353 int c_func (unsigned char
17354  i, unsigned char j) reentrant 
17355 \newline
17356
17357 \newline
17358 \InsetSpace ~
17359 \InsetSpace ~
17360 \InsetSpace ~
17361 \InsetSpace ~
17362 return asm_func(i,j); 
17363 \newline
17364
17365 \newline
17366
17367 \newline
17368 int main() 
17369 \newline
17370
17371 \newline
17372 \InsetSpace ~
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 return
17377  c_func(10,9); 
17378 \newline
17379 }
17380 \end_layout
17381
17382 \begin_layout Standard
17383 The corresponding assembler routine is:
17384 \end_layout
17385
17386 \begin_layout Verse
17387
17388 \family typewriter
17389 .globl _asm_func 
17390 \newline
17391 _asm_func: 
17392 \newline
17393 \InsetSpace ~
17394 \InsetSpace ~
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 push  _bp 
17398 \newline
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 \InsetSpace ~
17402 \InsetSpace ~
17403 mov _bp,sp 
17404 \newline
17405 \InsetSpace ~
17406 \InsetSpace ~
17407 \InsetSpace ~
17408 \InsetSpace ~
17409 mov r2,dpl
17410 \newline
17411 \InsetSpace ~
17412 \InsetSpace ~
17413 \InsetSpace ~
17414 \InsetSpace ~
17415 mov a,_bp 
17416 \newline
17417 \InsetSpace ~
17418 \InsetSpace ~
17419 \InsetSpace ~
17420 \InsetSpace ~
17421 add
17422  a,#0xfd 
17423 \newline
17424 \InsetSpace ~
17425 \InsetSpace ~
17426 \InsetSpace ~
17427 \InsetSpace ~
17428 mov r0,a 
17429 \newline
17430 \InsetSpace ~
17431 \InsetSpace ~
17432 \InsetSpace ~
17433 \InsetSpace ~
17434 add  a,#0xfc ;?
17435 \newline
17436 \InsetSpace ~
17437 \InsetSpace ~
17438 \InsetSpace ~
17439 \InsetSpace ~
17440 mov  r1,a 
17441 \newline
17442 \InsetSpace ~
17443 \InsetSpace ~
17444 \InsetSpace ~
17445 \InsetSpace ~
17446 mov  a,@r0 
17447 \newline
17448 \InsetSpace ~
17449 \InsetSpace ~
17450 \InsetSpace ~
17451 \InsetSpace ~
17452 add  a,r2 ;?
17453 \newline
17454 \InsetSpace ~
17455 \InsetSpace ~
17456 \InsetSpace ~
17457 \InsetSpace ~
17458 mov  dpl,a
17459  
17460 \newline
17461 \InsetSpace ~
17462 \InsetSpace ~
17463 \InsetSpace ~
17464 \InsetSpace ~
17465 mov  dph,#0x00 
17466 \newline
17467 \InsetSpace ~
17468 \InsetSpace ~
17469 \InsetSpace ~
17470 \InsetSpace ~
17471 mov  sp,_bp 
17472 \newline
17473 \InsetSpace ~
17474 \InsetSpace ~
17475 \InsetSpace ~
17476 \InsetSpace ~
17477 pop  _bp 
17478 \newline
17479 \InsetSpace ~
17480 \InsetSpace ~
17481 \InsetSpace ~
17482 \InsetSpace ~
17483 ret
17484 \end_layout
17485
17486 \begin_layout Standard
17487 The compiling and linking procedure remains the same, however note the extra
17488  entry & exit linkage required for the assembler code, _bp is the stack
17489  frame pointer and is used to compute the offset into the stack for parameters
17490  and local variables.
17491 \begin_inset VSpace bigskip
17492 \end_inset
17493
17494
17495 \end_layout
17496
17497 \begin_layout Section
17498 int (16 bit)
17499 \begin_inset LatexCommand \index{int (16 bit)}
17500
17501 \end_inset
17502
17503  and long (32 bit)
17504 \begin_inset LatexCommand \index{long (32 bit)}
17505
17506 \end_inset
17507
17508  Support
17509 \end_layout
17510
17511 \begin_layout Standard
17512 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17513  multiplication and modulus operations are implemented by support routines.
17514  These support routines are all developed in ANSI-C to facilitate porting
17515  to other MCUs, although some model specific assembler optimizations are
17516  used.
17517  The following files contain the described routines, all of them can be
17518  found in <installdir>/share/sdcc/lib.
17519 \newline
17520
17521 \end_layout
17522
17523 \begin_layout Standard
17524 \align center
17525 \begin_inset Tabular
17526 <lyxtabular version="3" rows="11" columns="2">
17527 <features>
17528 <column alignment="left" valignment="top" leftline="true" width="0">
17529 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17530 <row topline="true" bottomline="true">
17531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17532 \begin_inset Text
17533
17534 \begin_layout Standard
17535
17536 \series bold
17537 Function
17538 \end_layout
17539
17540 \end_inset
17541 </cell>
17542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17543 \begin_inset Text
17544
17545 \begin_layout Standard
17546
17547 \series bold
17548 Description
17549 \end_layout
17550
17551 \end_inset
17552 </cell>
17553 </row>
17554 <row topline="true">
17555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17556 \begin_inset Text
17557
17558 \begin_layout Standard
17559 _mulint.c 
17560 \end_layout
17561
17562 \end_inset
17563 </cell>
17564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17565 \begin_inset Text
17566
17567 \begin_layout Standard
17568 16 bit multiplication
17569 \end_layout
17570
17571 \end_inset
17572 </cell>
17573 </row>
17574 <row topline="true">
17575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17576 \begin_inset Text
17577
17578 \begin_layout Standard
17579 _divsint.c 
17580 \end_layout
17581
17582 \end_inset
17583 </cell>
17584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17585 \begin_inset Text
17586
17587 \begin_layout Standard
17588  signed 16 bit division (calls _divuint)
17589 \end_layout
17590
17591 \end_inset
17592 </cell>
17593 </row>
17594 <row topline="true">
17595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17596 \begin_inset Text
17597
17598 \begin_layout Standard
17599 _divuint.c 
17600 \end_layout
17601
17602 \end_inset
17603 </cell>
17604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17605 \begin_inset Text
17606
17607 \begin_layout Standard
17608  unsigned 16 bit division
17609 \end_layout
17610
17611 \end_inset
17612 </cell>
17613 </row>
17614 <row topline="true">
17615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17616 \begin_inset Text
17617
17618 \begin_layout Standard
17619 _modsint.c
17620 \end_layout
17621
17622 \end_inset
17623 </cell>
17624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17625 \begin_inset Text
17626
17627 \begin_layout Standard
17628 signed 16 bit modulus (calls _moduint)
17629 \end_layout
17630
17631 \end_inset
17632 </cell>
17633 </row>
17634 <row topline="true">
17635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17636 \begin_inset Text
17637
17638 \begin_layout Standard
17639 _moduint.c
17640 \end_layout
17641
17642 \end_inset
17643 </cell>
17644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17645 \begin_inset Text
17646
17647 \begin_layout Standard
17648 unsigned 16 bit modulus
17649 \end_layout
17650
17651 \end_inset
17652 </cell>
17653 </row>
17654 <row topline="true">
17655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17656 \begin_inset Text
17657
17658 \begin_layout Standard
17659 _mullong.c
17660 \end_layout
17661
17662 \end_inset
17663 </cell>
17664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17665 \begin_inset Text
17666
17667 \begin_layout Standard
17668 32 bit multiplication
17669 \end_layout
17670
17671 \end_inset
17672 </cell>
17673 </row>
17674 <row topline="true">
17675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17676 \begin_inset Text
17677
17678 \begin_layout Standard
17679 _divslong.c 
17680 \end_layout
17681
17682 \end_inset
17683 </cell>
17684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17685 \begin_inset Text
17686
17687 \begin_layout Standard
17688  signed 32 division (calls _divulong)
17689 \end_layout
17690
17691 \end_inset
17692 </cell>
17693 </row>
17694 <row topline="true">
17695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17696 \begin_inset Text
17697
17698 \begin_layout Standard
17699 _divulong.c 
17700 \end_layout
17701
17702 \end_inset
17703 </cell>
17704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17705 \begin_inset Text
17706
17707 \begin_layout Standard
17708 unsigned 32 division
17709 \end_layout
17710
17711 \end_inset
17712 </cell>
17713 </row>
17714 <row topline="true">
17715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17716 \begin_inset Text
17717
17718 \begin_layout Standard
17719 _modslong.c
17720 \end_layout
17721
17722 \end_inset
17723 </cell>
17724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17725 \begin_inset Text
17726
17727 \begin_layout Standard
17728  signed 32 bit modulus (calls _modulong)
17729 \end_layout
17730
17731 \end_inset
17732 </cell>
17733 </row>
17734 <row topline="true" bottomline="true">
17735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17736 \begin_inset Text
17737
17738 \begin_layout Standard
17739 _modulong.c
17740 \end_layout
17741
17742 \end_inset
17743 </cell>
17744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17745 \begin_inset Text
17746
17747 \begin_layout Standard
17748 unsigned 32 bit modulus
17749 \end_layout
17750
17751 \end_inset
17752 </cell>
17753 </row>
17754 </lyxtabular>
17755
17756 \end_inset
17757
17758
17759 \newline
17760
17761 \end_layout
17762
17763 \begin_layout Standard
17764 Since they are compiled as 
17765 \emph on
17766 non-reentrant
17767 \emph default
17768
17769 \begin_inset LatexCommand \index{reentrant}
17770
17771 \end_inset
17772
17773 , interrupt
17774 \begin_inset LatexCommand \index{interrupt}
17775
17776 \end_inset
17777
17778  service routines should not do any of the above operations.
17779  If this is unavoidable then the above routines will need to be compiled
17780  with the 
17781 \emph on
17782 -
17783 \begin_inset ERT
17784 status collapsed
17785
17786 \begin_layout Standard
17787
17788
17789 \backslash
17790 /
17791 \end_layout
17792
17793 \end_inset
17794
17795 -stack-auto
17796 \begin_inset LatexCommand \index{-\/-stack-auto}
17797
17798 \end_inset
17799
17800
17801 \emph default
17802  option, after which the source program will have to be compiled with 
17803 \emph on
17804 -
17805 \begin_inset ERT
17806 status collapsed
17807
17808 \begin_layout Standard
17809
17810
17811 \backslash
17812 /
17813 \end_layout
17814
17815 \end_inset
17816
17817 -int-long-reent
17818 \begin_inset LatexCommand \index{-\/-int-long-reent}
17819
17820 \end_inset
17821
17822
17823 \emph default
17824  option.
17825  Notice that you don't have to call these routines directly.
17826  The compiler will use them automatically every time an integer operation
17827  is required.
17828 \end_layout
17829
17830 \begin_layout Section
17831 Floating Point Support
17832 \begin_inset LatexCommand \index{Floating point support}
17833
17834 \end_inset
17835
17836
17837 \end_layout
17838
17839 \begin_layout Standard
17840 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
17841  The floating point support routines are derived from gcc's floatlib.c and
17842  consist of the following routines:
17843 \newline
17844
17845 \end_layout
17846
17847 \begin_layout Standard
17848 \align center
17849
17850 \size footnotesize
17851 \begin_inset Tabular
17852 <lyxtabular version="3" rows="17" columns="2">
17853 <features>
17854 <column alignment="left" valignment="top" leftline="true" width="0">
17855 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17856 <row topline="true" bottomline="true">
17857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17858 \begin_inset Text
17859
17860 \begin_layout Standard
17861
17862 \family roman
17863 \series medium
17864 \shape up
17865 \size normal
17866 \emph off
17867 \bar no
17868 \noun off
17869 \color none
17870 Function 
17871 \end_layout
17872
17873 \end_inset
17874 </cell>
17875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17876 \begin_inset Text
17877
17878 \begin_layout Standard
17879 Description
17880 \end_layout
17881
17882 \end_inset
17883 </cell>
17884 </row>
17885 <row topline="true">
17886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17887 \begin_inset Text
17888
17889 \begin_layout Standard
17890
17891 \family roman
17892 \series medium
17893 \shape up
17894 \size normal
17895 \emph off
17896 \bar no
17897 \noun off
17898 \color none
17899 _fsadd.c
17900 \end_layout
17901
17902 \end_inset
17903 </cell>
17904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17905 \begin_inset Text
17906
17907 \begin_layout Standard
17908
17909 \family roman
17910 \series medium
17911 \shape up
17912 \size normal
17913 \emph off
17914 \bar no
17915 \noun off
17916 \color none
17917 add floating point numbers
17918 \end_layout
17919
17920 \end_inset
17921 </cell>
17922 </row>
17923 <row topline="true">
17924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17925 \begin_inset Text
17926
17927 \begin_layout Standard
17928
17929 \family roman
17930 \series medium
17931 \shape up
17932 \size normal
17933 \emph off
17934 \bar no
17935 \noun off
17936 \color none
17937 _fssub.c 
17938 \end_layout
17939
17940 \end_inset
17941 </cell>
17942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17943 \begin_inset Text
17944
17945 \begin_layout Standard
17946
17947 \family roman
17948 \series medium
17949 \shape up
17950 \size normal
17951 \emph off
17952 \bar no
17953 \noun off
17954 \color none
17955 subtract floating point numbers 
17956 \end_layout
17957
17958 \end_inset
17959 </cell>
17960 </row>
17961 <row topline="true">
17962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17963 \begin_inset Text
17964
17965 \begin_layout Standard
17966
17967 \family roman
17968 \series medium
17969 \shape up
17970 \size normal
17971 \emph off
17972 \bar no
17973 \noun off
17974 \color none
17975 _fsdiv.c 
17976 \end_layout
17977
17978 \end_inset
17979 </cell>
17980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17981 \begin_inset Text
17982
17983 \begin_layout Standard
17984
17985 \family roman
17986 \series medium
17987 \shape up
17988 \size normal
17989 \emph off
17990 \bar no
17991 \noun off
17992 \color none
17993 divide floating point numbers 
17994 \end_layout
17995
17996 \end_inset
17997 </cell>
17998 </row>
17999 <row topline="true">
18000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18001 \begin_inset Text
18002
18003 \begin_layout Standard
18004
18005 \family roman
18006 \series medium
18007 \shape up
18008 \size normal
18009 \emph off
18010 \bar no
18011 \noun off
18012 \color none
18013 _fsmul.c 
18014 \end_layout
18015
18016 \end_inset
18017 </cell>
18018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18019 \begin_inset Text
18020
18021 \begin_layout Standard
18022
18023 \family roman
18024 \series medium
18025 \shape up
18026 \size normal
18027 \emph off
18028 \bar no
18029 \noun off
18030 \color none
18031 multiply floating point numbers 
18032 \end_layout
18033
18034 \end_inset
18035 </cell>
18036 </row>
18037 <row topline="true">
18038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18039 \begin_inset Text
18040
18041 \begin_layout Standard
18042
18043 \family roman
18044 \series medium
18045 \shape up
18046 \size normal
18047 \emph off
18048 \bar no
18049 \noun off
18050 \color none
18051 _fs2uchar.c
18052 \end_layout
18053
18054 \end_inset
18055 </cell>
18056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18057 \begin_inset Text
18058
18059 \begin_layout Standard
18060
18061 \family roman
18062 \series medium
18063 \shape up
18064 \size normal
18065 \emph off
18066 \bar no
18067 \noun off
18068 \color none
18069 convert floating point to unsigned char
18070 \end_layout
18071
18072 \end_inset
18073 </cell>
18074 </row>
18075 <row topline="true">
18076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18077 \begin_inset Text
18078
18079 \begin_layout Standard
18080
18081 \family roman
18082 \series medium
18083 \shape up
18084 \size normal
18085 \emph off
18086 \bar no
18087 \noun off
18088 \color none
18089 _fs2char.c
18090 \end_layout
18091
18092 \end_inset
18093 </cell>
18094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18095 \begin_inset Text
18096
18097 \begin_layout Standard
18098
18099 \family roman
18100 \series medium
18101 \shape up
18102 \size normal
18103 \emph off
18104 \bar no
18105 \noun off
18106 \color none
18107 convert floating point to signed char
18108 \end_layout
18109
18110 \end_inset
18111 </cell>
18112 </row>
18113 <row topline="true">
18114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18115 \begin_inset Text
18116
18117 \begin_layout Standard
18118
18119 \family roman
18120 \series medium
18121 \shape up
18122 \size normal
18123 \emph off
18124 \bar no
18125 \noun off
18126 \color none
18127 _fs2uint.c
18128 \end_layout
18129
18130 \end_inset
18131 </cell>
18132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18133 \begin_inset Text
18134
18135 \begin_layout Standard
18136
18137 \family roman
18138 \series medium
18139 \shape up
18140 \size normal
18141 \emph off
18142 \bar no
18143 \noun off
18144 \color none
18145 convert floating point to unsigned int
18146 \end_layout
18147
18148 \end_inset
18149 </cell>
18150 </row>
18151 <row topline="true">
18152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18153 \begin_inset Text
18154
18155 \begin_layout Standard
18156
18157 \family roman
18158 \series medium
18159 \shape up
18160 \size normal
18161 \emph off
18162 \bar no
18163 \noun off
18164 \color none
18165 _fs2int.c
18166 \end_layout
18167
18168 \end_inset
18169 </cell>
18170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18171 \begin_inset Text
18172
18173 \begin_layout Standard
18174
18175 \family roman
18176 \series medium
18177 \shape up
18178 \size normal
18179 \emph off
18180 \bar no
18181 \noun off
18182 \color none
18183 convert floating point to signed int
18184 \end_layout
18185
18186 \end_inset
18187 </cell>
18188 </row>
18189 <row topline="true">
18190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18191 \begin_inset Text
18192
18193 \begin_layout Standard
18194
18195 \family roman
18196 \series medium
18197 \shape up
18198 \size normal
18199 \emph off
18200 \bar no
18201 \noun off
18202 \color none
18203 _fs2ulong.
18204 \family default
18205 \series default
18206 \shape default
18207 \size default
18208 \emph default
18209 \bar default
18210 \noun default
18211 c
18212 \end_layout
18213
18214 \end_inset
18215 </cell>
18216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18217 \begin_inset Text
18218
18219 \begin_layout Standard
18220
18221 \family roman
18222 \series medium
18223 \shape up
18224 \size normal
18225 \emph off
18226 \bar no
18227 \noun off
18228 \color none
18229 convert floating point to unsigned long
18230 \end_layout
18231
18232 \end_inset
18233 </cell>
18234 </row>
18235 <row topline="true">
18236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18237 \begin_inset Text
18238
18239 \begin_layout Standard
18240
18241 \family roman
18242 \series medium
18243 \shape up
18244 \size normal
18245 \emph off
18246 \bar no
18247 \noun off
18248 \color none
18249 _fs2long.c
18250 \end_layout
18251
18252 \end_inset
18253 </cell>
18254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18255 \begin_inset Text
18256
18257 \begin_layout Standard
18258
18259 \family roman
18260 \series medium
18261 \shape up
18262 \size normal
18263 \emph off
18264 \bar no
18265 \noun off
18266 \color none
18267 convert floating point to signed long
18268 \end_layout
18269
18270 \end_inset
18271 </cell>
18272 </row>
18273 <row topline="true">
18274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18275 \begin_inset Text
18276
18277 \begin_layout Standard
18278
18279 \family roman
18280 \series medium
18281 \shape up
18282 \size normal
18283 \emph off
18284 \bar no
18285 \noun off
18286 \color none
18287 _uchar2fs.c
18288 \end_layout
18289
18290 \end_inset
18291 </cell>
18292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18293 \begin_inset Text
18294
18295 \begin_layout Standard
18296
18297 \family roman
18298 \series medium
18299 \shape up
18300 \size normal
18301 \emph off
18302 \bar no
18303 \noun off
18304 \color none
18305 convert unsigned char to floating point
18306 \end_layout
18307
18308 \end_inset
18309 </cell>
18310 </row>
18311 <row topline="true">
18312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18313 \begin_inset Text
18314
18315 \begin_layout Standard
18316
18317 \family roman
18318 \series medium
18319 \shape up
18320 \size normal
18321 \emph off
18322 \bar no
18323 \noun off
18324 \color none
18325 _char2fs.c
18326 \end_layout
18327
18328 \end_inset
18329 </cell>
18330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18331 \begin_inset Text
18332
18333 \begin_layout Standard
18334
18335 \family roman
18336 \series medium
18337 \shape up
18338 \size normal
18339 \emph off
18340 \bar no
18341 \noun off
18342 \color none
18343 convert char to floating point number
18344 \end_layout
18345
18346 \end_inset
18347 </cell>
18348 </row>
18349 <row topline="true">
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18351 \begin_inset Text
18352
18353 \begin_layout Standard
18354
18355 \family roman
18356 \series medium
18357 \shape up
18358 \size normal
18359 \emph off
18360 \bar no
18361 \noun off
18362 \color none
18363 _uint2fs.c
18364 \end_layout
18365
18366 \end_inset
18367 </cell>
18368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18369 \begin_inset Text
18370
18371 \begin_layout Standard
18372
18373 \family roman
18374 \series medium
18375 \shape up
18376 \size normal
18377 \emph off
18378 \bar no
18379 \noun off
18380 \color none
18381 convert unsigned int to floating point
18382 \end_layout
18383
18384 \end_inset
18385 </cell>
18386 </row>
18387 <row topline="true">
18388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18389 \begin_inset Text
18390
18391 \begin_layout Standard
18392
18393 \family roman
18394 \series medium
18395 \shape up
18396 \size normal
18397 \emph off
18398 \bar no
18399 \noun off
18400 \color none
18401 _int2fs.c
18402 \end_layout
18403
18404 \end_inset
18405 </cell>
18406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18407 \begin_inset Text
18408
18409 \begin_layout Standard
18410
18411 \family roman
18412 \series medium
18413 \shape up
18414 \size normal
18415 \emph off
18416 \bar no
18417 \noun off
18418 \color none
18419 convert int to floating point numbers
18420 \end_layout
18421
18422 \end_inset
18423 </cell>
18424 </row>
18425 <row topline="true">
18426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18427 \begin_inset Text
18428
18429 \begin_layout Standard
18430
18431 \family roman
18432 \series medium
18433 \shape up
18434 \size normal
18435 \emph off
18436 \bar no
18437 \noun off
18438 \color none
18439 _ulong2fs.c
18440 \end_layout
18441
18442 \end_inset
18443 </cell>
18444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18445 \begin_inset Text
18446
18447 \begin_layout Standard
18448
18449 \family roman
18450 \series medium
18451 \shape up
18452 \size normal
18453 \emph off
18454 \bar no
18455 \noun off
18456 \color none
18457 convert unsigned long to floating point number
18458 \end_layout
18459
18460 \end_inset
18461 </cell>
18462 </row>
18463 <row topline="true" bottomline="true">
18464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18465 \begin_inset Text
18466
18467 \begin_layout Standard
18468
18469 \family roman
18470 \series medium
18471 \shape up
18472 \size normal
18473 \emph off
18474 \bar no
18475 \noun off
18476 \color none
18477 _long2fs.c
18478 \end_layout
18479
18480 \end_inset
18481 </cell>
18482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18483 \begin_inset Text
18484
18485 \begin_layout Standard
18486
18487 \family roman
18488 \series medium
18489 \shape up
18490 \size normal
18491 \emph off
18492 \bar no
18493 \noun off
18494 \color none
18495 convert long to floating point number
18496 \end_layout
18497
18498 \end_inset
18499 </cell>
18500 </row>
18501 </lyxtabular>
18502
18503 \end_inset
18504
18505
18506 \newline
18507
18508 \end_layout
18509
18510 \begin_layout Standard
18511 These support routines are developed in ANSI-C so there is room for space
18512  and speed improvement
18513 \begin_inset Foot
18514 status open
18515
18516 \begin_layout Standard
18517 These floating point routines (
18518 \emph on
18519 not
18520 \emph default
18521  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18522  
18523 \end_layout
18524
18525 \end_inset
18526
18527 .
18528  Note if all these routines are used simultaneously the data space might
18529  overflow.
18530  For serious floating point usage the large model might be needed.
18531  Also notice that you don't have to call this routines directly.
18532  The compiler will use them automatically every time a floating point operation
18533  is required.
18534 \begin_inset VSpace bigskip
18535 \end_inset
18536
18537
18538 \end_layout
18539
18540 \begin_layout Section
18541 Library Routines
18542 \begin_inset LatexCommand \index{Libraries}
18543
18544 \end_inset
18545
18546
18547 \end_layout
18548
18549 \begin_layout Standard
18550
18551 \emph on
18552 <pending: this is messy and incomplete - a little more information is in
18553  sdcc/doc/libdoc.txt
18554 \emph default
18555  >
18556 \end_layout
18557
18558 \begin_layout Subsection
18559 Compiler support routines (_gptrget, _mulint etc.)
18560 \end_layout
18561
18562 \begin_layout Subsection
18563 Stdclib functions (puts, printf, strcat etc.)
18564 \end_layout
18565
18566 \begin_layout Subsubsection
18567 <stdio.h>
18568 \end_layout
18569
18570 \begin_layout Paragraph
18571 getchar(), putchar()
18572 \end_layout
18573
18574 \begin_layout Standard
18575 \begin_inset LatexCommand \index{<stdio.h>}
18576
18577 \end_inset
18578
18579 As usual on embedded systems you have to provide your own 
18580 \family typewriter
18581 getchar()
18582 \begin_inset LatexCommand \index{getchar()}
18583
18584 \end_inset
18585
18586  
18587 \family default
18588 and 
18589 \family typewriter
18590 putchar()
18591 \begin_inset LatexCommand \index{putchar()}
18592
18593 \end_inset
18594
18595
18596 \family default
18597  routines.
18598  SDCC does not know whether the system connects to a serial line with or
18599  without handshake, LCD, keyboard or other device.
18600  And whether a 
18601 \family typewriter
18602 lf
18603 \family default
18604  to 
18605 \family typewriter
18606 crlf
18607 \family default
18608  conversion within 
18609 \family typewriter
18610 putchar()
18611 \family default
18612  is intended.
18613  You'll find examples for serial routines f.e.
18614  in sdcc/device/lib.
18615  For the mcs51 this minimalistic polling 
18616 \family typewriter
18617 putchar()
18618 \family default
18619  routine might be a start:
18620 \end_layout
18621
18622 \begin_layout Verse
18623
18624 \family typewriter
18625 void putchar (char c) { 
18626 \newline
18627 \InsetSpace ~
18628 \InsetSpace ~
18629 \InsetSpace ~
18630 \InsetSpace ~
18631 while (!TI)\InsetSpace ~
18632 \InsetSpace ~
18633 \InsetSpace ~
18634  /* assumes UART is initialized */
18635 \newline
18636 \InsetSpace ~
18637 \InsetSpace ~
18638 \InsetSpace ~
18639 \InsetSpace ~
18640 \InsetSpace ~
18641 \InsetSpace ~
18642 \InsetSpace ~
18643 \InsetSpace ~
18644 ;
18645 \newline
18646 \InsetSpace ~
18647 \InsetSpace ~
18648 \InsetSpace ~
18649 \InsetSpace ~
18650 TI
18651  = 0;
18652 \newline
18653 \InsetSpace ~
18654 \InsetSpace ~
18655 \InsetSpace ~
18656 \InsetSpace ~
18657 SBUF = c;
18658 \newline
18659 }
18660 \end_layout
18661
18662 \begin_layout Paragraph
18663 printf()
18664 \end_layout
18665
18666 \begin_layout Standard
18667 The default
18668 \family typewriter
18669  printf()
18670 \begin_inset LatexCommand \index{printf()}
18671
18672 \end_inset
18673
18674
18675 \family default
18676  implementation in
18677 \family typewriter
18678  printf_large.c
18679 \family default
18680  does not support float (except on ds390).
18681  To enable this recompile it with the option 
18682 \emph on
18683 -
18684 \begin_inset ERT
18685 status collapsed
18686
18687 \begin_layout Standard
18688
18689
18690 \backslash
18691 /
18692 \end_layout
18693
18694 \end_inset
18695
18696 DUSE_FLOATS=1
18697 \begin_inset LatexCommand \index{USE\_FLOATS}
18698
18699 \end_inset
18700
18701
18702 \emph default
18703  on the command line.
18704  Use
18705 \emph on
18706  -
18707 \begin_inset ERT
18708 status collapsed
18709
18710 \begin_layout Standard
18711
18712
18713 \backslash
18714 /
18715 \end_layout
18716
18717 \end_inset
18718
18719 -model-large
18720 \begin_inset LatexCommand \index{-\/-model-large}
18721
18722 \end_inset
18723
18724
18725 \emph default
18726  for the mcs51 port, since this uses a lot of memory.
18727 \end_layout
18728
18729 \begin_layout Standard
18730 If you're short on code memory you might want to use 
18731 \family typewriter
18732 printf_small()
18733 \begin_inset LatexCommand \index{printf\_small()}
18734
18735 \end_inset
18736
18737
18738 \family default
18739  
18740 \emph on
18741 instead
18742 \emph default
18743  of
18744 \family typewriter
18745  printf().
18746
18747 \family default
18748  For the mcs51 there additionally are assembly versions 
18749 \family typewriter
18750 printf_tiny()
18751 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
18752
18753 \end_inset
18754
18755
18756 \family default
18757  (subset of printf using less than 270 bytes) and 
18758 \family typewriter
18759 printf_fast()
18760 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
18761
18762 \end_inset
18763
18764  
18765 \family default
18766 and
18767 \family typewriter
18768  printf_fast_f()
18769 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
18770
18771 \end_inset
18772
18773
18774 \family default
18775  (floating-point aware version of printf_fast) which should fit the requirements
18776  of many embedded systems (printf_fast() can be customized by unsetting
18777  #defines to 
18778 \emph on
18779 not
18780 \emph default
18781  support long variables and field widths).
18782  Be sure to use only one of these printf options within a project.
18783 \newline
18784
18785 \end_layout
18786
18787 \begin_layout Standard
18788 Feature matrix of different 
18789 \emph on
18790 printf
18791 \emph default
18792  options on mcs51.
18793 \end_layout
18794
18795 \begin_layout Standard
18796 \begin_inset Tabular
18797 <lyxtabular version="3" rows="14" columns="7">
18798 <features islongtable="true">
18799 <column alignment="left" valignment="middle" leftline="true" width="14col%">
18800 <column alignment="center" valignment="top" leftline="true" width="0">
18801 <column alignment="center" valignment="top" leftline="true" width="12col%">
18802 <column alignment="center" valignment="top" leftline="true" width="10col%">
18803 <column alignment="center" valignment="top" leftline="true" width="0">
18804 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
18805 <column alignment="center" valignment="top" rightline="true" width="0">
18806 <row topline="true" bottomline="true" endhead="true">
18807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18808 \begin_inset Text
18809
18810 \begin_layout Standard
18811
18812 \series bold
18813 \size large
18814 mcs51
18815 \end_layout
18816
18817 \end_inset
18818 </cell>
18819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18820 \begin_inset Text
18821
18822 \begin_layout Standard
18823 printf
18824 \begin_inset LatexCommand \index{printf}
18825
18826 \end_inset
18827
18828
18829 \end_layout
18830
18831 \end_inset
18832 </cell>
18833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18834 \begin_inset Text
18835
18836 \begin_layout Standard
18837 printf 
18838 \size scriptsize
18839 USE_FLOATS=1
18840 \end_layout
18841
18842 \end_inset
18843 </cell>
18844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18845 \begin_inset Text
18846
18847 \begin_layout Standard
18848 printf_small
18849 \end_layout
18850
18851 \end_inset
18852 </cell>
18853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18854 \begin_inset Text
18855
18856 \begin_layout Standard
18857 printf_fast
18858 \end_layout
18859
18860 \end_inset
18861 </cell>
18862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18863 \begin_inset Text
18864
18865 \begin_layout Standard
18866 printf_fast_f
18867 \end_layout
18868
18869 \end_inset
18870 </cell>
18871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18872 \begin_inset Text
18873
18874 \begin_layout Standard
18875 printf_tiny
18876 \end_layout
18877
18878 \end_inset
18879 </cell>
18880 </row>
18881 <row topline="true" endhead="true">
18882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18883 \begin_inset Text
18884
18885 \begin_layout Standard
18886 filename
18887 \end_layout
18888
18889 \end_inset
18890 </cell>
18891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18892 \begin_inset Text
18893
18894 \begin_layout Standard
18895
18896 \size scriptsize
18897 printf_large.c
18898 \end_layout
18899
18900 \end_inset
18901 </cell>
18902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18903 \begin_inset Text
18904
18905 \begin_layout Standard
18906
18907 \size scriptsize
18908 printf_large.c
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
18918 \size scriptsize
18919 printfl.c
18920 \end_layout
18921
18922 \end_inset
18923 </cell>
18924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18925 \begin_inset Text
18926
18927 \begin_layout Standard
18928
18929 \size scriptsize
18930 printf_fast.c
18931 \end_layout
18932
18933 \end_inset
18934 </cell>
18935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18936 \begin_inset Text
18937
18938 \begin_layout Standard
18939
18940 \size scriptsize
18941 printf_fast_f.c
18942 \end_layout
18943
18944 \end_inset
18945 </cell>
18946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18947 \begin_inset Text
18948
18949 \begin_layout Standard
18950
18951 \size scriptsize
18952 printf_tiny.c
18953 \end_layout
18954
18955 \end_inset
18956 </cell>
18957 </row>
18958 <row topline="true" endhead="true">
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18960 \begin_inset Text
18961
18962 \begin_layout Standard
18963 \begin_inset Quotes sld
18964 \end_inset
18965
18966 Hello World
18967 \begin_inset Quotes srd
18968 \end_inset
18969
18970  size
18971 \end_layout
18972
18973 \begin_layout Standard
18974 small / large
18975 \end_layout
18976
18977 \end_inset
18978 </cell>
18979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18980 \begin_inset Text
18981
18982 \begin_layout Standard
18983 1.7k / 2.4k
18984 \end_layout
18985
18986 \end_inset
18987 </cell>
18988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18989 \begin_inset Text
18990
18991 \begin_layout Standard
18992 4.3k / 5.6k
18993 \end_layout
18994
18995 \end_inset
18996 </cell>
18997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18998 \begin_inset Text
18999
19000 \begin_layout Standard
19001 1.2k / 1.8k
19002 \end_layout
19003
19004 \end_inset
19005 </cell>
19006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19007 \begin_inset Text
19008
19009 \begin_layout Standard
19010 1.3k / 1.3k
19011 \end_layout
19012
19013 \end_inset
19014 </cell>
19015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19016 \begin_inset Text
19017
19018 \begin_layout Standard
19019 1.9k / 1.9k
19020 \end_layout
19021
19022 \end_inset
19023 </cell>
19024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19025 \begin_inset Text
19026
19027 \begin_layout Standard
19028 0.44k / 0.44k
19029 \end_layout
19030
19031 \end_inset
19032 </cell>
19033 </row>
19034 <row topline="true" endhead="true">
19035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19036 \begin_inset Text
19037
19038 \begin_layout Standard
19039 code size
19040 \end_layout
19041
19042 \begin_layout Standard
19043 small / large
19044 \end_layout
19045
19046 \end_inset
19047 </cell>
19048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19049 \begin_inset Text
19050
19051 \begin_layout Standard
19052 1.4k / 2.0k
19053 \end_layout
19054
19055 \end_inset
19056 </cell>
19057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19058 \begin_inset Text
19059
19060 \begin_layout Standard
19061 2.8k / 3.7k
19062 \end_layout
19063
19064 \end_inset
19065 </cell>
19066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19067 \begin_inset Text
19068
19069 \begin_layout Standard
19070 0.45k / 0.47k (+ _ltoa)
19071 \end_layout
19072
19073 \end_inset
19074 </cell>
19075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19076 \begin_inset Text
19077
19078 \begin_layout Standard
19079 1.2k / 1.2k
19080 \end_layout
19081
19082 \end_inset
19083 </cell>
19084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19085 \begin_inset Text
19086
19087 \begin_layout Standard
19088 1.6k / 1.6k
19089 \end_layout
19090
19091 \end_inset
19092 </cell>
19093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19094 \begin_inset Text
19095
19096 \begin_layout Standard
19097 0.26k / 0.26k
19098 \end_layout
19099
19100 \end_inset
19101 </cell>
19102 </row>
19103 <row topline="true">
19104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19105 \begin_inset Text
19106
19107 \begin_layout Standard
19108 formats
19109 \end_layout
19110
19111 \end_inset
19112 </cell>
19113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19114 \begin_inset Text
19115
19116 \begin_layout Standard
19117 cdi
19118 \emph on
19119 o
19120 \emph default
19121 psux
19122 \end_layout
19123
19124 \end_inset
19125 </cell>
19126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19127 \begin_inset Text
19128
19129 \begin_layout Standard
19130
19131 \family roman
19132 \series medium
19133 \shape up
19134 \size normal
19135 \emph off
19136 \bar no
19137 \noun off
19138 \color none
19139 cd
19140 \family default
19141 \series default
19142 \shape default
19143 \size default
19144 \emph default
19145 \bar default
19146 \noun default
19147 f
19148 \family roman
19149 \series medium
19150 \shape up
19151 \size normal
19152 \emph off
19153 \bar no
19154 \noun off
19155 i
19156 \family default
19157 \series default
19158 \shape default
19159 \size default
19160 \emph on
19161 \bar default
19162 \noun default
19163 o
19164 \family roman
19165 \series medium
19166 \shape up
19167 \size normal
19168 \emph off
19169 \bar no
19170 \noun off
19171 psux
19172 \end_layout
19173
19174 \end_inset
19175 </cell>
19176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19177 \begin_inset Text
19178
19179 \begin_layout Standard
19180 c
19181 \family roman
19182 \series medium
19183 \shape up
19184 \size normal
19185 \emph off
19186 \bar no
19187 \noun off
19188 \color none
19189 d
19190 \family default
19191 \series default
19192 \shape default
19193 \size default
19194 \emph on
19195 \bar default
19196 \noun default
19197 o
19198 \family roman
19199 \series medium
19200 \shape up
19201 \size normal
19202 \emph off
19203 \bar no
19204 \noun off
19205 s
19206 \family default
19207 \series default
19208 \shape default
19209 \size default
19210 \emph default
19211 \bar default
19212 \noun default
19213 x
19214 \end_layout
19215
19216 \end_inset
19217 </cell>
19218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19219 \begin_inset Text
19220
19221 \begin_layout Standard
19222 cdsux
19223 \end_layout
19224
19225 \end_inset
19226 </cell>
19227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19228 \begin_inset Text
19229
19230 \begin_layout Standard
19231 cdfsux
19232 \end_layout
19233
19234 \end_inset
19235 </cell>
19236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19237 \begin_inset Text
19238
19239 \begin_layout Standard
19240 cdsux
19241 \end_layout
19242
19243 \end_inset
19244 </cell>
19245 </row>
19246 <row topline="true">
19247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19248 \begin_inset Text
19249
19250 \begin_layout Standard
19251 long (32 bit) support
19252 \end_layout
19253
19254 \end_inset
19255 </cell>
19256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19257 \begin_inset Text
19258
19259 \begin_layout Standard
19260 x
19261 \end_layout
19262
19263 \end_inset
19264 </cell>
19265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19266 \begin_inset Text
19267
19268 \begin_layout Standard
19269 x
19270 \end_layout
19271
19272 \end_inset
19273 </cell>
19274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19275 \begin_inset Text
19276
19277 \begin_layout Standard
19278 x
19279 \end_layout
19280
19281 \end_inset
19282 </cell>
19283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19284 \begin_inset Text
19285
19286 \begin_layout Standard
19287 x
19288 \end_layout
19289
19290 \end_inset
19291 </cell>
19292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19293 \begin_inset Text
19294
19295 \begin_layout Standard
19296
19297 \family roman
19298 \series medium
19299 \shape up
19300 \size normal
19301 \emph off
19302 \bar no
19303 \noun off
19304 \color none
19305 x
19306 \end_layout
19307
19308 \end_inset
19309 </cell>
19310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19311 \begin_inset Text
19312
19313 \begin_layout Standard
19314 -
19315 \end_layout
19316
19317 \end_inset
19318 </cell>
19319 </row>
19320 <row topline="true">
19321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19322 \begin_inset Text
19323
19324 \begin_layout Standard
19325 byte arguments on stack
19326 \end_layout
19327
19328 \end_inset
19329 </cell>
19330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19331 \begin_inset Text
19332
19333 \begin_layout Standard
19334 b
19335 \end_layout
19336
19337 \end_inset
19338 </cell>
19339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19340 \begin_inset Text
19341
19342 \begin_layout Standard
19343 b
19344 \end_layout
19345
19346 \end_inset
19347 </cell>
19348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19349 \begin_inset Text
19350
19351 \begin_layout Standard
19352 -
19353 \end_layout
19354
19355 \end_inset
19356 </cell>
19357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19358 \begin_inset Text
19359
19360 \begin_layout Standard
19361 -
19362 \end_layout
19363
19364 \end_inset
19365 </cell>
19366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19367 \begin_inset Text
19368
19369 \begin_layout Standard
19370 -
19371 \end_layout
19372
19373 \end_inset
19374 </cell>
19375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19376 \begin_inset Text
19377
19378 \begin_layout Standard
19379 -
19380 \end_layout
19381
19382 \end_inset
19383 </cell>
19384 </row>
19385 <row topline="true">
19386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19387 \begin_inset Text
19388
19389 \begin_layout Standard
19390 float format
19391 \begin_inset LatexCommand \index{Floating point support}
19392
19393 \end_inset
19394
19395
19396 \end_layout
19397
19398 \end_inset
19399 </cell>
19400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19401 \begin_inset Text
19402
19403 \begin_layout Standard
19404 -
19405 \end_layout
19406
19407 \end_inset
19408 </cell>
19409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19410 \begin_inset Text
19411
19412 \begin_layout Standard
19413 %f
19414 \end_layout
19415
19416 \end_inset
19417 </cell>
19418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19419 \begin_inset Text
19420
19421 \begin_layout Standard
19422 -
19423 \end_layout
19424
19425 \end_inset
19426 </cell>
19427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19428 \begin_inset Text
19429
19430 \begin_layout Standard
19431 -
19432 \end_layout
19433
19434 \end_inset
19435 </cell>
19436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19437 \begin_inset Text
19438
19439 \begin_layout Standard
19440 %f
19441 \begin_inset Foot
19442 status collapsed
19443
19444 \begin_layout Standard
19445 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19446 \end_layout
19447
19448 \end_inset
19449
19450
19451 \end_layout
19452
19453 \end_inset
19454 </cell>
19455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19456 \begin_inset Text
19457
19458 \begin_layout Standard
19459 -
19460 \end_layout
19461
19462 \end_inset
19463 </cell>
19464 </row>
19465 <row topline="true">
19466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19467 \begin_inset Text
19468
19469 \begin_layout Standard
19470 float formats %e %g
19471 \end_layout
19472
19473 \end_inset
19474 </cell>
19475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19476 \begin_inset Text
19477
19478 \begin_layout Standard
19479 -
19480 \end_layout
19481
19482 \end_inset
19483 </cell>
19484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19485 \begin_inset Text
19486
19487 \begin_layout Standard
19488 -
19489 \end_layout
19490
19491 \end_inset
19492 </cell>
19493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19494 \begin_inset Text
19495
19496 \begin_layout Standard
19497 -
19498 \end_layout
19499
19500 \end_inset
19501 </cell>
19502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19503 \begin_inset Text
19504
19505 \begin_layout Standard
19506 -
19507 \end_layout
19508
19509 \end_inset
19510 </cell>
19511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19512 \begin_inset Text
19513
19514 \begin_layout Standard
19515 -
19516 \end_layout
19517
19518 \end_inset
19519 </cell>
19520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19521 \begin_inset Text
19522
19523 \begin_layout Standard
19524 -
19525 \end_layout
19526
19527 \end_inset
19528 </cell>
19529 </row>
19530 <row topline="true" bottomline="true">
19531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19532 \begin_inset Text
19533
19534 \begin_layout Standard
19535 field width
19536 \end_layout
19537
19538 \end_inset
19539 </cell>
19540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19541 \begin_inset Text
19542
19543 \begin_layout Standard
19544 x
19545 \end_layout
19546
19547 \end_inset
19548 </cell>
19549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19550 \begin_inset Text
19551
19552 \begin_layout Standard
19553 x
19554 \end_layout
19555
19556 \end_inset
19557 </cell>
19558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19559 \begin_inset Text
19560
19561 \begin_layout Standard
19562 -
19563 \end_layout
19564
19565 \end_inset
19566 </cell>
19567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19568 \begin_inset Text
19569
19570 \begin_layout Standard
19571 x
19572 \end_layout
19573
19574 \end_inset
19575 </cell>
19576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19577 \begin_inset Text
19578
19579 \begin_layout Standard
19580 x
19581 \end_layout
19582
19583 \end_inset
19584 </cell>
19585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19586 \begin_inset Text
19587
19588 \begin_layout Standard
19589 -
19590 \end_layout
19591
19592 \end_inset
19593 </cell>
19594 </row>
19595 <row bottomline="true">
19596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19597 \begin_inset Text
19598
19599 \begin_layout Standard
19600 string speed
19601 \begin_inset Foot
19602 status collapsed
19603
19604 \begin_layout Standard
19605 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
19606 \backslash
19607 r', '
19608 \backslash
19609 n'); standard 8051 @ 22.1184 MHz, empty putchar()
19610 \end_layout
19611
19612 \end_inset
19613
19614 ,
19615 \end_layout
19616
19617 \begin_layout Standard
19618 small / large
19619 \end_layout
19620
19621 \end_inset
19622 </cell>
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19624 \begin_inset Text
19625
19626 \begin_layout Standard
19627 1.52 / 2.59 ms
19628 \end_layout
19629
19630 \end_inset
19631 </cell>
19632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19633 \begin_inset Text
19634
19635 \begin_layout Standard
19636 1.53 / 2.62 ms
19637 \end_layout
19638
19639 \end_inset
19640 </cell>
19641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19642 \begin_inset Text
19643
19644 \begin_layout Standard
19645 0.92 / 0.93 ms
19646 \end_layout
19647
19648 \end_inset
19649 </cell>
19650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19651 \begin_inset Text
19652
19653 \begin_layout Standard
19654 0.45 / 0.45 ms
19655 \end_layout
19656
19657 \end_inset
19658 </cell>
19659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19660 \begin_inset Text
19661
19662 \begin_layout Standard
19663 0.46 / 0.46 ms
19664 \end_layout
19665
19666 \end_inset
19667 </cell>
19668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19669 \begin_inset Text
19670
19671 \begin_layout Standard
19672 0.45 / 0.45 ms
19673 \end_layout
19674
19675 \end_inset
19676 </cell>
19677 </row>
19678 <row bottomline="true">
19679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19680 \begin_inset Text
19681
19682 \begin_layout Standard
19683 int speed
19684 \begin_inset Foot
19685 status collapsed
19686
19687 \begin_layout Standard
19688 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
19689  putchar()
19690 \end_layout
19691
19692 \end_inset
19693
19694 ,
19695 \end_layout
19696
19697 \begin_layout Standard
19698 small / large
19699 \end_layout
19700
19701 \end_inset
19702 </cell>
19703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19704 \begin_inset Text
19705
19706 \begin_layout Standard
19707 3.01 / 3.61 ms
19708 \end_layout
19709
19710 \end_inset
19711 </cell>
19712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19713 \begin_inset Text
19714
19715 \begin_layout Standard
19716 3.01 / 3.61 ms
19717 \end_layout
19718
19719 \end_inset
19720 </cell>
19721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19722 \begin_inset Text
19723
19724 \begin_layout Standard
19725 3.51 / 18.13 ms
19726 \end_layout
19727
19728 \end_inset
19729 </cell>
19730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19731 \begin_inset Text
19732
19733 \begin_layout Standard
19734 0.22 / 0.22 ms
19735 \end_layout
19736
19737 \end_inset
19738 </cell>
19739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19740 \begin_inset Text
19741
19742 \begin_layout Standard
19743 0.23 / 0.23 ms
19744 \end_layout
19745
19746 \end_inset
19747 </cell>
19748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19749 \begin_inset Text
19750
19751 \begin_layout Standard
19752 0.25 / 0.25 ms
19753 \begin_inset Foot
19754 status collapsed
19755
19756 \begin_layout Standard
19757 printf_tiny integer speed is data dependent, worst case is 0.33 ms
19758 \end_layout
19759
19760 \end_inset
19761
19762
19763 \end_layout
19764
19765 \end_inset
19766 </cell>
19767 </row>
19768 <row bottomline="true">
19769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19770 \begin_inset Text
19771
19772 \begin_layout Standard
19773 long speed
19774 \begin_inset Foot
19775 status collapsed
19776
19777 \begin_layout Standard
19778 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
19779  empty putchar()
19780 \end_layout
19781
19782 \end_inset
19783
19784 ,
19785 \end_layout
19786
19787 \begin_layout Standard
19788 small / large
19789 \end_layout
19790
19791 \end_inset
19792 </cell>
19793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19794 \begin_inset Text
19795
19796 \begin_layout Standard
19797 5.37 / 6.31 ms
19798 \end_layout
19799
19800 \end_inset
19801 </cell>
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19803 \begin_inset Text
19804
19805 \begin_layout Standard
19806 5.37 / 6.31 ms
19807 \end_layout
19808
19809 \end_inset
19810 </cell>
19811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19812 \begin_inset Text
19813
19814 \begin_layout Standard
19815 8.71 / 40.65 ms
19816 \end_layout
19817
19818 \end_inset
19819 </cell>
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19821 \begin_inset Text
19822
19823 \begin_layout Standard
19824 0.40 / 0.40 ms
19825 \end_layout
19826
19827 \end_inset
19828 </cell>
19829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19830 \begin_inset Text
19831
19832 \begin_layout Standard
19833 0.40 / 0.40 ms
19834 \end_layout
19835
19836 \end_inset
19837 </cell>
19838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19839 \begin_inset Text
19840
19841 \begin_layout Standard
19842 -
19843 \end_layout
19844
19845 \end_inset
19846 </cell>
19847 </row>
19848 <row bottomline="true">
19849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19850 \begin_inset Text
19851
19852 \begin_layout Standard
19853 float speed
19854 \begin_inset Foot
19855 status collapsed
19856
19857 \begin_layout Standard
19858 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
19859  empty putchar()
19860 \end_layout
19861
19862 \end_inset
19863
19864 ,
19865 \end_layout
19866
19867 \begin_layout Standard
19868 small / large
19869 \end_layout
19870
19871 \end_inset
19872 </cell>
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19874 \begin_inset Text
19875
19876 \begin_layout Standard
19877 -
19878 \end_layout
19879
19880 \end_inset
19881 </cell>
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19883 \begin_inset Text
19884
19885 \begin_layout Standard
19886 7.49 / 22.47 ms
19887 \end_layout
19888
19889 \end_inset
19890 </cell>
19891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19892 \begin_inset Text
19893
19894 \begin_layout Standard
19895 -
19896 \end_layout
19897
19898 \end_inset
19899 </cell>
19900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19901 \begin_inset Text
19902
19903 \begin_layout Standard
19904 -
19905 \end_layout
19906
19907 \end_inset
19908 </cell>
19909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19910 \begin_inset Text
19911
19912 \begin_layout Standard
19913 1.04 / 1.04 ms
19914 \end_layout
19915
19916 \end_inset
19917 </cell>
19918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19919 \begin_inset Text
19920
19921 \begin_layout Standard
19922 -
19923 \end_layout
19924
19925 \end_inset
19926 </cell>
19927 </row>
19928 </lyxtabular>
19929
19930 \end_inset
19931
19932
19933 \end_layout
19934
19935 \begin_layout Subsubsection
19936 <malloc.h>
19937 \begin_inset LatexCommand \index{malloc.h}
19938
19939 \end_inset
19940
19941
19942 \end_layout
19943
19944 \begin_layout Standard
19945 As of SDCC 2.6.2 you no longer need to call an initialization routine before
19946  using dynamic memory allocation
19947 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
19948
19949 \end_inset
19950
19951  and a default heap
19952 \begin_inset LatexCommand \index{heap (malloc)}
19953
19954 \end_inset
19955
19956  space of 1024 bytes is provided for malloc to allocate memory from.
19957  If you need a different heap size you need to recompile _heap.c with the
19958  required size defined in HEAP_SIZE.
19959  It is recommended to make a copy of this file into your project directory
19960  and compile it there with:
19961 \end_layout
19962
19963 \begin_layout Verse
19964
19965 \family typewriter
19966 sdcc -c _heap.c -D HEAD_SIZE=2048
19967 \end_layout
19968
19969 \begin_layout Standard
19970 And then link it with:
19971 \end_layout
19972
19973 \begin_layout Verse
19974
19975 \family typewriter
19976 sdcc main.rel _heap.rel
19977 \end_layout
19978
19979 \begin_layout Subsection
19980 Math functions (sinf, powf, sqrtf etc.)
19981 \end_layout
19982
19983 \begin_layout Subsubsection
19984 <math.h>
19985 \end_layout
19986
19987 \begin_layout Standard
19988 See definitions in file <math.h>.
19989 \end_layout
19990
19991 \begin_layout Subsection
19992 Other libraries
19993 \end_layout
19994
19995 \begin_layout Standard
19996 Libraries
19997 \begin_inset LatexCommand \index{Libraries}
19998
19999 \end_inset
20000
20001  included in SDCC should have a license at least as liberal as the GNU Lesser
20002  General Public License
20003 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20004
20005 \end_inset
20006
20007  
20008 \emph on
20009 LGPL
20010 \emph default
20011 .
20012 \end_layout
20013
20014 \begin_layout Standard
20015 \begin_inset Note Note
20016 status collapsed
20017
20018 \begin_layout Standard
20019 license statements for the libraries are missing.
20020  sdcc/device/lib/ser_ir.c
20021 \end_layout
20022
20023 \begin_layout Standard
20024 or _decdptr f.e.
20025  come with a GPL (as opposed to LGPL) License - this will not be liberal
20026  enough for many embedded programmers.
20027 \end_layout
20028
20029 \end_inset
20030
20031
20032 \end_layout
20033
20034 \begin_layout Standard
20035 If you have ported some library or want to share experience about some code
20036  which f.e.
20037  falls into any of these categories Busses (I
20038 \begin_inset Formula $^{\textrm{2}}$
20039 \end_inset
20040
20041 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20042  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20043  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20044 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20045
20046 \end_inset
20047
20048 \InsetSpace ~
20049 would certainly like to hear about it.
20050 \end_layout
20051
20052 \begin_layout Standard
20053 Programmers coding for embedded systems are not especially famous for being
20054  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20055 e these references are very valuable.
20056  Let's help to create a climate where information is shared.
20057 \begin_inset VSpace bigskip
20058 \end_inset
20059
20060
20061 \end_layout
20062
20063 \begin_layout Section
20064 Memory Models
20065 \end_layout
20066
20067 \begin_layout Subsection
20068 MCS51 Memory Models
20069 \begin_inset LatexCommand \index{Memory model}
20070
20071 \end_inset
20072
20073
20074 \begin_inset LatexCommand \index{MCS51 memory model}
20075
20076 \end_inset
20077
20078
20079 \end_layout
20080
20081 \begin_layout Subsubsection
20082 Small, Medium and Large
20083 \end_layout
20084
20085 \begin_layout Standard
20086 SDCC allows three memory models for MCS51 code, 
20087 \shape slanted
20088 small, medium
20089 \shape default
20090  and 
20091 \shape slanted
20092 large
20093 \shape default
20094 .
20095  Modules compiled with different memory models should 
20096 \emph on
20097 never
20098 \emph default
20099  be combined together or the results would be unpredictable.
20100  The library routines supplied with the compiler are compiled as small,
20101  medium and large.
20102  The compiled library modules are contained in separate directories as small,
20103  medium and large so that you can link to the appropriate set.
20104 \end_layout
20105
20106 \begin_layout Standard
20107 When the medium or large model is used all variables declared without a
20108  storage class will be allocated into the external ram, this includes all
20109  parameters and local variables (for non-reentrant
20110 \begin_inset LatexCommand \index{reentrant}
20111
20112 \end_inset
20113
20114  functions).
20115  When the small model is used variables without storage class are allocated
20116  in the internal ram.
20117 \end_layout
20118
20119 \begin_layout Standard
20120 Judicious usage of the processor specific storage classes
20121 \begin_inset LatexCommand \index{Storage class}
20122
20123 \end_inset
20124
20125  and the 'reentrant' function type will yield much more efficient code,
20126  than using the large model.
20127  Several optimizations are disabled when the program is compiled using the
20128  large model, it is therefore recommended that the small model be used unless
20129  absolutely required.
20130 \end_layout
20131
20132 \begin_layout Subsubsection
20133 External Stack
20134 \begin_inset LatexCommand \label{sub:External-Stack}
20135
20136 \end_inset
20137
20138
20139 \begin_inset LatexCommand \index{stack}
20140
20141 \end_inset
20142
20143
20144 \begin_inset LatexCommand \index{External stack (mcs51)}
20145
20146 \end_inset
20147
20148
20149 \end_layout
20150
20151 \begin_layout Standard
20152 The external stack (-
20153 \begin_inset ERT
20154 status collapsed
20155
20156 \begin_layout Standard
20157
20158
20159 \backslash
20160 /
20161 \end_layout
20162
20163 \end_inset
20164
20165 -xstack option
20166 \begin_inset LatexCommand \index{-\/-xstack}
20167
20168 \end_inset
20169
20170 ) is located in pdata
20171 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20172
20173 \end_inset
20174
20175  memory (usually at the start of the external ram segment) and uses all
20176  unused space in pdata (max.
20177  256 bytes).
20178  When -
20179 \begin_inset ERT
20180 status collapsed
20181
20182 \begin_layout Standard
20183
20184
20185 \backslash
20186 /
20187 \end_layout
20188
20189 \end_inset
20190
20191 -xstack option is used to compile the program, the parameters and local
20192  variables
20193 \begin_inset LatexCommand \index{local variables}
20194
20195 \end_inset
20196
20197  of all reentrant functions are allocated in this area.
20198  This option is provided for programs with large stack space requirements.
20199  When used with the -
20200 \begin_inset ERT
20201 status collapsed
20202
20203 \begin_layout Standard
20204
20205
20206 \backslash
20207 /
20208 \end_layout
20209
20210 \end_inset
20211
20212 -stack-auto
20213 \begin_inset LatexCommand \index{-\/-stack-auto}
20214
20215 \end_inset
20216
20217  option, all parameters and local variables are allocated on the external
20218  stack (note: support libraries will need to be recompiled with the same
20219  options.
20220  There is a predefined target in the library makefile).
20221 \end_layout
20222
20223 \begin_layout Standard
20224 The compiler outputs the higher order address byte of the external ram segment
20225  into port P2
20226 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20227
20228 \end_inset
20229
20230  (see also section 
20231 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20232
20233 \end_inset
20234
20235 ), therefore when using the External Stack option, this port 
20236 \emph on
20237 may not
20238 \emph default
20239  be used by the application program.
20240 \end_layout
20241
20242 \begin_layout Subsection
20243 DS390 Memory Model
20244 \begin_inset LatexCommand \index{Memory model}
20245
20246 \end_inset
20247
20248
20249 \begin_inset LatexCommand \index{DS390 memory model}
20250
20251 \end_inset
20252
20253
20254 \end_layout
20255
20256 \begin_layout Standard
20257 The only model supported is Flat 24
20258 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20259
20260 \end_inset
20261
20262 .
20263  This generates code for the 24 bit contiguous addressing mode of the Dallas
20264  DS80C390 part.
20265  In this mode, up to four meg of external RAM or code space can be directly
20266  addressed.
20267  See the data sheets at www.dalsemi.com for further information on this part.
20268 \newline
20269
20270 \newline
20271 Note
20272  that the compiler does not generate any code to place the processor into
20273  24 bitmode (although 
20274 \emph on
20275 tinibios
20276 \emph default
20277  in the ds390 libraries will do that for you).
20278  If you don't use 
20279 \emph on
20280 tinibios
20281 \emph default
20282
20283 \begin_inset LatexCommand \index{Tinibios (DS390)}
20284
20285 \end_inset
20286
20287 , the boot loader or similar code must ensure that the processor is in 24
20288  bit contiguous addressing mode before calling the SDCC startup code.
20289 \newline
20290
20291 \newline
20292 Like
20293  the 
20294 \emph on
20295 -
20296 \begin_inset ERT
20297 status collapsed
20298
20299 \begin_layout Standard
20300
20301
20302 \backslash
20303 /
20304 \end_layout
20305
20306 \end_inset
20307
20308 -model-large
20309 \emph default
20310  option, variables will by default be placed into the XDATA segment.
20311  
20312 \newline
20313
20314 \newline
20315 Segments may be placed anywhere in the 4 meg address space using the usual
20316  -
20317 \begin_inset ERT
20318 status collapsed
20319
20320 \begin_layout Standard
20321
20322
20323 \backslash
20324 /
20325 \end_layout
20326
20327 \end_inset
20328
20329 -*-loc options.
20330  Note that if any segments are located above 64K, the -r flag must be passed
20331  to the linker to generate the proper segment relocations, and the Intel
20332  HEX output format must be used.
20333  The -r flag can be passed to the linker by using the option 
20334 \emph on
20335 -Wl-r
20336 \emph default
20337  on the SDCC command line.
20338  However, currently the linker can not handle code segments > 64k.
20339 \end_layout
20340
20341 \begin_layout Section
20342 Pragmas
20343 \begin_inset LatexCommand \label{sec:Pragmas}
20344
20345 \end_inset
20346
20347
20348 \begin_inset LatexCommand \index{Pragmas}
20349
20350 \end_inset
20351
20352
20353 \end_layout
20354
20355 \begin_layout Standard
20356 SDCC supports the following #pragma directives:
20357 \end_layout
20358
20359 \begin_layout Itemize
20360
20361 \series bold
20362 save
20363 \series default
20364
20365 \begin_inset LatexCommand \index{\#pragma save}
20366
20367 \end_inset
20368
20369  - this will save most current options to the save/restore stack.
20370  See #pragma\InsetSpace ~
20371 restore.
20372 \end_layout
20373
20374 \begin_layout Itemize
20375
20376 \series bold
20377 restore
20378 \series default
20379
20380 \begin_inset LatexCommand \index{\#pragma restore}
20381
20382 \end_inset
20383
20384  - will restore saved options from the last save.
20385  saves & restores can be nested.
20386  SDCC uses a save/restore stack: save pushes current options to the stack,
20387  restore pulls current options from the stack.
20388  See #pragma\InsetSpace ~
20389 save.
20390 \newline
20391
20392 \end_layout
20393
20394 \begin_layout Itemize
20395
20396 \series bold
20397 callee_saves
20398 \series default
20399
20400 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20401
20402 \end_inset
20403
20404
20405 \begin_inset LatexCommand \index{function prologue}
20406
20407 \end_inset
20408
20409  function1[,function2[,function3...]] - The compiler by default uses a caller
20410  saves convention for register saving across function calls, however this
20411  can cause unnecessary register pushing & popping
20412 \begin_inset LatexCommand \index{push/pop}
20413
20414 \end_inset
20415
20416  when calling small functions from larger functions.
20417  This option can be used to switch off the register saving convention for
20418  the function names specified.
20419  The compiler will not save registers when calling these functions, extra
20420  code need to be manually inserted at the entry & exit for these functions
20421  to save & restore the registers used by these functions, this can SUBSTANTIALLY
20422  reduce code & improve run time performance of the generated code.
20423  In the future the compiler (with inter procedural analysis) may be able
20424  to determine the appropriate scheme to use for each function call.
20425  If -
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 -callee-saves command line option is used, the function names specified
20439  in #pragma\InsetSpace ~
20440 callee_saves
20441 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20442
20443 \end_inset
20444
20445  is appended to the list of functions specified in the command line.
20446 \end_layout
20447
20448 \begin_layout Itemize
20449
20450 \series bold
20451 exclude
20452 \series default
20453
20454 \begin_inset LatexCommand \index{\#pragma exclude}
20455
20456 \end_inset
20457
20458  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20459  of pairs of push/pop
20460 \begin_inset LatexCommand \index{push/pop}
20461
20462 \end_inset
20463
20464  instructions in 
20465 \emph on
20466 I
20467 \emph default
20468 nterrupt
20469 \begin_inset LatexCommand \index{interrupt}
20470
20471 \end_inset
20472
20473  
20474 \emph on
20475 S
20476 \emph default
20477 ervice 
20478 \emph on
20479 R
20480 \emph default
20481 outines.
20482  The directive should be placed immediately before the ISR function definition
20483  and it affects ALL ISR functions following it.
20484  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20485 exclude\InsetSpace ~
20486 none
20487 \begin_inset LatexCommand \index{\#pragma exclude}
20488
20489 \end_inset
20490
20491 .
20492  See also the related keyword _naked
20493 \begin_inset LatexCommand \index{\_naked}
20494
20495 \end_inset
20496
20497
20498 \begin_inset LatexCommand \index{\_\_naked}
20499
20500 \end_inset
20501
20502 .
20503 \end_layout
20504
20505 \begin_layout Itemize
20506
20507 \series bold
20508 less_pedantic
20509 \series default
20510
20511 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
20512
20513 \end_inset
20514
20515  - the compiler will not warn you anymore for obvious mistakes, you'r on
20516  your own now ;-(
20517 \end_layout
20518
20519 \begin_layout Itemize
20520
20521 \series bold
20522 disable_warning
20523 \series default
20524  <nnnn>
20525 \begin_inset LatexCommand \index{\#pragma disable\_warning}
20526
20527 \end_inset
20528
20529  - the compiler will not warn you anymore about warning number <nnnn>.
20530 \end_layout
20531
20532 \begin_layout Itemize
20533
20534 \series bold
20535 nogcse
20536 \series default
20537
20538 \begin_inset LatexCommand \index{\#pragma nogcse}
20539
20540 \end_inset
20541
20542  - will stop global common subexpression elimination.
20543 \end_layout
20544
20545 \begin_layout Itemize
20546
20547 \series bold
20548 noinduction
20549 \series default
20550
20551 \begin_inset LatexCommand \index{\#pragma noinduction}
20552
20553 \end_inset
20554
20555  - will stop loop induction optimizations.
20556 \end_layout
20557
20558 \begin_layout Itemize
20559
20560 \series bold
20561 noinvariant
20562 \series default
20563
20564 \begin_inset LatexCommand \index{\#pragma noinvariant}
20565
20566 \end_inset
20567
20568  - will not do loop invariant optimizations.
20569  For more details see Loop Invariants in section
20570 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
20571
20572 \end_inset
20573
20574 .
20575 \end_layout
20576
20577 \begin_layout Itemize
20578
20579 \series bold
20580 noiv
20581 \series default
20582
20583 \begin_inset LatexCommand \index{\#pragma noiv}
20584
20585 \end_inset
20586
20587  - Do not generate interrupt
20588 \begin_inset LatexCommand \index{interrupt}
20589
20590 \end_inset
20591
20592  vector table
20593 \begin_inset LatexCommand \index{interrupt vector table}
20594
20595 \end_inset
20596
20597  entries for all ISR functions defined after the pragma.
20598  This is useful in cases where the interrupt vector table must be defined
20599  manually, or when there is a secondary, manually defined interrupt vector
20600  table (e.g.
20601  for the autovector feature of the Cypress EZ-USB FX2).
20602  More elegantly this can be achieved by obmitting the optional interrupt
20603  number after the interrupt keyword, see section 
20604 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
20605
20606 \end_inset
20607
20608 \InsetSpace ~
20609 about interrupts.
20610 \end_layout
20611
20612 \begin_layout Itemize
20613
20614 \series bold
20615 nojtbound
20616 \series default
20617
20618 \begin_inset LatexCommand \index{\#pragma nojtbound}
20619
20620 \end_inset
20621
20622  - will not generate code for boundary value checking, when switch statements
20623  are turned into jump-tables (dangerous).
20624  For more details see section 
20625 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
20626
20627 \end_inset
20628
20629 .
20630 \end_layout
20631
20632 \begin_layout Itemize
20633
20634 \series bold
20635 noloopreverse
20636 \series default
20637
20638 \begin_inset LatexCommand \index{\#pragma noloopreverse}
20639
20640 \end_inset
20641
20642  - Will not do loop reversal optimization
20643 \end_layout
20644
20645 \begin_layout Itemize
20646
20647 \series bold
20648 nooverlay
20649 \series default
20650
20651 \begin_inset LatexCommand \index{\#pragma nooverlay}
20652
20653 \end_inset
20654
20655  - the compiler will not overlay the parameters and local variables of a
20656  function.
20657 \end_layout
20658
20659 \begin_layout Itemize
20660
20661 \series bold
20662 stackauto
20663 \series default
20664
20665 \begin_inset LatexCommand \index{\#pragma stackauto}
20666
20667 \end_inset
20668
20669 - See option -
20670 \begin_inset ERT
20671 status collapsed
20672
20673 \begin_layout Standard
20674
20675
20676 \backslash
20677 /
20678 \end_layout
20679
20680 \end_inset
20681
20682 -stack-auto
20683 \begin_inset LatexCommand \index{-\/-stack-auto}
20684
20685 \end_inset
20686
20687  and section 
20688 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
20689
20690 \end_inset
20691
20692  Parameters and Local Variables.
20693 \end_layout
20694
20695 \begin_layout Itemize
20696
20697 \series bold
20698 opt_code_speed
20699 \series default
20700  
20701 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
20702
20703 \end_inset
20704
20705 - The compiler will optimize code generation towards fast code, possibly
20706  at the expense of code size.
20707  Currently this has little effect.
20708 \end_layout
20709
20710 \begin_layout Itemize
20711
20712 \series bold
20713 opt_code_size
20714 \series default
20715  
20716 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
20717
20718 \end_inset
20719
20720 - The compiler will optimize code generation towards compact code, possibly
20721  at the expense of code speed.
20722  Currently this has little effect.
20723 \end_layout
20724
20725 \begin_layout Itemize
20726
20727 \series bold
20728 opt_code_balanced
20729 \series default
20730  
20731 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
20732
20733 \end_inset
20734
20735 - The compiler will attempt to generate code that is both compact and fast,
20736  as long as meeting one goal is not a detriment to the other (this is the
20737  default).
20738  
20739 \end_layout
20740
20741 \begin_layout Itemize
20742
20743 \series bold
20744 std_sdcc89
20745 \series default
20746  
20747 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
20748
20749 \end_inset
20750
20751 - Generally follow the C89 standard, but allow SDCC features that conflict
20752  with the standard (default).
20753 \end_layout
20754
20755 \begin_layout Itemize
20756
20757 \series bold
20758 std_c89
20759 \series default
20760  
20761 \begin_inset LatexCommand \index{\#pragma std\_c89}
20762
20763 \end_inset
20764
20765 - Follow the C89 standard and disable SDCC features that conflict with the
20766  standard.
20767 \end_layout
20768
20769 \begin_layout Itemize
20770
20771 \series bold
20772 std_sdcc99
20773 \series default
20774  
20775 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
20776
20777 \end_inset
20778
20779 - Generally follow the C99 standard, but allow SDCC features that conflict
20780  with the standard (incomplete support).
20781 \end_layout
20782
20783 \begin_layout Itemize
20784
20785 \series bold
20786 std_c99
20787 \series default
20788  
20789 \begin_inset LatexCommand \index{\#pragma std\_c99}
20790
20791 \end_inset
20792
20793 - Follow the C99 standard and disable SDCC features that conflict with the
20794  standard (incomplete support).
20795 \end_layout
20796
20797 \begin_layout Itemize
20798
20799 \series bold
20800 codeseg
20801 \series default
20802  <name>
20803 \begin_inset LatexCommand \index{\#pragma codeseg}
20804
20805 \end_inset
20806
20807 - Use this name (max.
20808  8 characters) for the code segment.
20809  See option -
20810 \begin_inset ERT
20811 status collapsed
20812
20813 \begin_layout Standard
20814
20815
20816 \backslash
20817 /
20818 \end_layout
20819
20820 \end_inset
20821
20822 -codeseg.
20823 \end_layout
20824
20825 \begin_layout Itemize
20826
20827 \series bold
20828 constseg
20829 \series default
20830  <name>
20831 \begin_inset LatexCommand \index{\#pragma constseg}
20832
20833 \end_inset
20834
20835 - Use this name (max.
20836  8 characters) for the const segment.
20837  See option -
20838 \begin_inset ERT
20839 status collapsed
20840
20841 \begin_layout Standard
20842
20843
20844 \backslash
20845 /
20846 \end_layout
20847
20848 \end_inset
20849
20850 -constseg.
20851 \end_layout
20852
20853 \begin_layout Standard
20854 The preprocessor SDCPP
20855 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
20856
20857 \end_inset
20858
20859  supports the following #pragma directives:
20860 \end_layout
20861
20862 \begin_layout Itemize
20863
20864 \series bold
20865 pedantic_parse_number
20866 \series default
20867
20868 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
20869
20870 \end_inset
20871
20872  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
20873  parsed properly and the macro LO_B(3) gets expanded.
20874  Default is off.
20875  Below is an example on how to use this pragma.
20876
20877 \emph on
20878  Note: this functionality is not in conformance with standard!
20879 \end_layout
20880
20881 \begin_layout Verse
20882
20883 \family typewriter
20884 #pragma pedantic_parse_number +
20885 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
20886
20887 \end_inset
20888
20889
20890 \newline
20891
20892 \newline
20893 #define LO_B(x) ((x) & 0xff)
20894 \newline
20895
20896 \newline
20897 unsigned char foo(void)
20898 \newline
20899 {
20900 \newline
20901 \InsetSpace ~
20902 \InsetSpace ~
20903 \InsetSpace ~
20904 unsigned char c=0xfe-LO_B(3)
20905 ;
20906 \newline
20907
20908 \newline
20909 \InsetSpace ~
20910 \InsetSpace ~
20911 \InsetSpace ~
20912 return c;
20913 \newline
20914 }
20915 \newline
20916
20917 \end_layout
20918
20919 \begin_layout Itemize
20920
20921 \series bold
20922 preproc_asm
20923 \series default
20924
20925 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20926
20927 \end_inset
20928
20929  (+ | -) - switch _asm _endasm block preprocessing on / off.
20930  Default is on.
20931  You use this prama to define multilines of assembly code.
20932  This will prevent the preprocessor from changing the formating required
20933  by assembly code.
20934  Below is an example on how to use this pragma.
20935 \end_layout
20936
20937 \begin_layout Verse
20938
20939 \family typewriter
20940 #pragma preproc_asm -
20941 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
20942
20943 \end_inset
20944
20945
20946 \newline
20947 #define MYDELAY _asm
20948 \newline
20949 \InsetSpace ~
20950 \InsetSpace ~
20951 \InsetSpace ~
20952 nop ;my assembly comment...
20953 \newline
20954 \InsetSpace ~
20955 \InsetSpace ~
20956 \InsetSpace ~
20957 nop
20958 \newline
20959 \InsetSpace ~
20960 \InsetSpace ~
20961 \InsetSpace ~
20962 nop
20963 \newline
20964 _endasm
20965 \newline
20966 #pragma preproc_asm
20967  +
20968 \newline
20969
20970 \newline
20971 void foo (void) 
20972 \newline
20973
20974 \newline
20975 \InsetSpace ~
20976 \InsetSpace ~
20977 \InsetSpace ~
20978  ...
20979  
20980 \newline
20981 \InsetSpace ~
20982 \InsetSpace ~
20983 \InsetSpace ~
20984  MYDELAY;
20985 \newline
20986 \InsetSpace ~
20987 \InsetSpace ~
20988 \InsetSpace ~
20989  ...
20990  
20991 \newline
20992
20993 \newline
20994
20995 \end_layout
20996
20997 \begin_layout Itemize
20998
20999 \series bold
21000 sdcc_hash
21001 \series default
21002
21003 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21004
21005 \end_inset
21006
21007  (+ | -) - Allow "naked" hash in macro definition, for example:
21008 \newline
21009
21010 \family typewriter
21011 #define DIR_LO(x) #(x & 0xff)
21012 \family default
21013
21014 \newline
21015 Default is off.
21016  Below is an example on how to use this pragma.
21017 \end_layout
21018
21019 \begin_layout Verse
21020
21021 \family typewriter
21022 #pragma preproc_asm +
21023 \newline
21024 #pragma sdcc_hash +
21025 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21026
21027 \end_inset
21028
21029
21030 \newline
21031
21032 \newline
21033 #define ROMCALL(x) 
21034 \backslash
21035
21036 \newline
21037 \InsetSpace ~
21038 \InsetSpace ~
21039 \InsetSpace ~
21040 mov R6_B3, #(x & 0xff) 
21041 \backslash
21042
21043 \newline
21044 \InsetSpace ~
21045 \InsetSpace ~
21046 \InsetSpace ~
21047 mov R7_B3, #((x >> 8) & 0xff) 
21048 \backslash
21049
21050 \newline
21051 \InsetSpace ~
21052 \InsetSpace ~
21053 \InsetSpace ~
21054 lcall __romcall
21055 \newline
21056
21057 \newline
21058 ...
21059 \newline
21060 _asm
21061 \newline
21062 ROMCALL(72)
21063 \newline
21064 _endasm;
21065 \newline
21066 ...
21067 \newline
21068
21069 \end_layout
21070
21071 \begin_layout Standard
21072 The pragma's are intended to be used to turn-on or off certain optimizations
21073  which might cause the compiler to generate extra stack / data space to
21074  store compiler generated temporary variables.
21075  This usually happens in large functions.
21076  Pragma directives should be used as shown in the following example, they
21077  are used to control options & optimizations for a given function; pragmas
21078  should be placed before and/or after a function, placing pragma's inside
21079  a function body could have unpredictable results.
21080 \end_layout
21081
21082 \begin_layout Verse
21083
21084 \family typewriter
21085 #pragma save
21086 \begin_inset LatexCommand \index{\#pragma save}
21087
21088 \end_inset
21089
21090  \InsetSpace ~
21091 \InsetSpace ~
21092 \InsetSpace ~
21093 \InsetSpace ~
21094 \InsetSpace ~
21095 \InsetSpace ~
21096 \InsetSpace ~
21097 /* save the current settings */ 
21098 \newline
21099 #pragma nogcse
21100 \begin_inset LatexCommand \index{\#pragma nogcse}
21101
21102 \end_inset
21103
21104  \InsetSpace ~
21105 \InsetSpace ~
21106 \InsetSpace ~
21107 \InsetSpace ~
21108 \InsetSpace ~
21109 /* turnoff global subexpression elimination */ 
21110 \newline
21111 #pragma noinduction
21112 \begin_inset LatexCommand \index{\#pragma noinduction}
21113
21114 \end_inset
21115
21116  /* turn off induction optimizations */ 
21117 \newline
21118 int foo () 
21119 \newline
21120
21121 \newline
21122 \InsetSpace ~
21123  \InsetSpace ~
21124  ...
21125  
21126 \newline
21127 \InsetSpace ~
21128  \InsetSpace ~
21129  /* large code */ 
21130 \newline
21131 \InsetSpace ~
21132  \InsetSpace ~
21133  ...
21134  
21135 \newline
21136
21137 \newline
21138 #pragma restore
21139 \begin_inset LatexCommand \index{\#pragma restore}
21140
21141 \end_inset
21142
21143  /* turn the optimizations back on */
21144 \end_layout
21145
21146 \begin_layout Standard
21147 The compiler will generate a warning message when extra space is allocated.
21148  It is strongly recommended that the save and restore pragma's be used when
21149  changing options for a function.
21150 \newline
21151
21152 \newline
21153
21154 \newline
21155
21156 \end_layout
21157
21158 \begin_layout Section
21159 Defines Created by the Compiler
21160 \end_layout
21161
21162 \begin_layout Standard
21163 The compiler creates the following #defines
21164 \begin_inset LatexCommand \index{\#defines}
21165
21166 \end_inset
21167
21168
21169 \begin_inset LatexCommand \index{Defines created by the compiler}
21170
21171 \end_inset
21172
21173 :
21174 \newline
21175
21176 \end_layout
21177
21178 \begin_layout Standard
21179 \begin_inset Tabular
21180 <lyxtabular version="3" rows="11" columns="2">
21181 <features>
21182 <column alignment="left" valignment="top" leftline="true" width="3in">
21183 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21184 <row topline="true" bottomline="true">
21185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21186 \begin_inset Text
21187
21188 \begin_layout Standard
21189
21190 \series bold
21191 #define
21192 \end_layout
21193
21194 \end_inset
21195 </cell>
21196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21197 \begin_inset Text
21198
21199 \begin_layout Standard
21200
21201 \series bold
21202 Description
21203 \end_layout
21204
21205 \end_inset
21206 </cell>
21207 </row>
21208 <row topline="true">
21209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21210 \begin_inset Text
21211
21212 \begin_layout Standard
21213 SDCC
21214 \begin_inset LatexCommand \index{SDCC}
21215
21216 \end_inset
21217
21218  
21219 \end_layout
21220
21221 \end_inset
21222 </cell>
21223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21224 \begin_inset Text
21225
21226 \begin_layout Standard
21227 Always defined.
21228  Since version 2.5.6 the version number as an int (ex.
21229  256)
21230 \end_layout
21231
21232 \end_inset
21233 </cell>
21234 </row>
21235 <row topline="true">
21236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21237 \begin_inset Text
21238
21239 \begin_layout Standard
21240 SDCC_mcs51
21241 \begin_inset LatexCommand \index{SDCC\_mcs51}
21242
21243 \end_inset
21244
21245  or SDCC_ds390
21246 \begin_inset LatexCommand \index{SDCC\_ds390}
21247
21248 \end_inset
21249
21250  or SDCC_z80
21251 \begin_inset LatexCommand \index{SDCC\_z80}
21252
21253 \end_inset
21254
21255 , etc.
21256 \end_layout
21257
21258 \end_inset
21259 </cell>
21260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21261 \begin_inset Text
21262
21263 \begin_layout Standard
21264 depending on the model used (e.g.: -mds390)
21265 \end_layout
21266
21267 \end_inset
21268 </cell>
21269 </row>
21270 <row topline="true">
21271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21272 \begin_inset Text
21273
21274 \begin_layout Standard
21275 __mcs51
21276 \begin_inset LatexCommand \index{\_\_mcs51}
21277
21278 \end_inset
21279
21280 , __ds390
21281 \begin_inset LatexCommand \index{\_\_ds390}
21282
21283 \end_inset
21284
21285 , __hc08
21286 \begin_inset LatexCommand \index{\_\_hc08}
21287
21288 \end_inset
21289
21290 , __z80
21291 \begin_inset LatexCommand \index{\_\_z80}
21292
21293 \end_inset
21294
21295 , etc
21296 \end_layout
21297
21298 \end_inset
21299 </cell>
21300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21301 \begin_inset Text
21302
21303 \begin_layout Standard
21304 depending on the model used (e.g.
21305  -mz80)
21306 \end_layout
21307
21308 \end_inset
21309 </cell>
21310 </row>
21311 <row topline="true">
21312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21313 \begin_inset Text
21314
21315 \begin_layout Standard
21316 SDCC_STACK_AUTO
21317 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21318
21319 \end_inset
21320
21321
21322 \end_layout
21323
21324 \end_inset
21325 </cell>
21326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21327 \begin_inset Text
21328
21329 \begin_layout Standard
21330 when 
21331 \emph on
21332 -
21333 \begin_inset ERT
21334 status collapsed
21335
21336 \begin_layout Standard
21337
21338
21339 \backslash
21340 /
21341 \end_layout
21342
21343 \end_inset
21344
21345 -stack-auto
21346 \emph default
21347  option is used
21348 \end_layout
21349
21350 \end_inset
21351 </cell>
21352 </row>
21353 <row topline="true">
21354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21355 \begin_inset Text
21356
21357 \begin_layout Standard
21358 SDCC_MODEL_SMALL
21359 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
21360
21361 \end_inset
21362
21363
21364 \end_layout
21365
21366 \end_inset
21367 </cell>
21368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21369 \begin_inset Text
21370
21371 \begin_layout Standard
21372 when 
21373 \emph on
21374 -
21375 \begin_inset ERT
21376 status collapsed
21377
21378 \begin_layout Standard
21379
21380
21381 \backslash
21382 /
21383 \end_layout
21384
21385 \end_inset
21386
21387 -model-small
21388 \emph default
21389  is used
21390 \end_layout
21391
21392 \end_inset
21393 </cell>
21394 </row>
21395 <row topline="true">
21396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21397 \begin_inset Text
21398
21399 \begin_layout Standard
21400 SDCC_MODEL_MEDIUM
21401 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
21402
21403 \end_inset
21404
21405
21406 \end_layout
21407
21408 \end_inset
21409 </cell>
21410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21411 \begin_inset Text
21412
21413 \begin_layout Standard
21414 when 
21415 \emph on
21416 -
21417 \begin_inset ERT
21418 status collapsed
21419
21420 \begin_layout Standard
21421
21422
21423 \backslash
21424 /
21425 \end_layout
21426
21427 \end_inset
21428
21429 -model-medium
21430 \emph default
21431  is used
21432 \end_layout
21433
21434 \end_inset
21435 </cell>
21436 </row>
21437 <row topline="true">
21438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21439 \begin_inset Text
21440
21441 \begin_layout Standard
21442 SDCC_MODEL_LARGE
21443 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
21444
21445 \end_inset
21446
21447
21448 \end_layout
21449
21450 \end_inset
21451 </cell>
21452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21453 \begin_inset Text
21454
21455 \begin_layout Standard
21456 when 
21457 \emph on
21458 -
21459 \begin_inset ERT
21460 status collapsed
21461
21462 \begin_layout Standard
21463
21464
21465 \backslash
21466 /
21467 \end_layout
21468
21469 \end_inset
21470
21471 -model-large
21472 \emph default
21473  is used
21474 \end_layout
21475
21476 \end_inset
21477 </cell>
21478 </row>
21479 <row topline="true">
21480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21481 \begin_inset Text
21482
21483 \begin_layout Standard
21484 SDCC_USE_XSTACK
21485 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
21486
21487 \end_inset
21488
21489
21490 \end_layout
21491
21492 \end_inset
21493 </cell>
21494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21495 \begin_inset Text
21496
21497 \begin_layout Standard
21498 when 
21499 \emph on
21500 -
21501 \begin_inset ERT
21502 status collapsed
21503
21504 \begin_layout Standard
21505
21506
21507 \backslash
21508 /
21509 \end_layout
21510
21511 \end_inset
21512
21513 -xstack
21514 \emph default
21515  option is used
21516 \end_layout
21517
21518 \end_inset
21519 </cell>
21520 </row>
21521 <row topline="true">
21522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21523 \begin_inset Text
21524
21525 \begin_layout Standard
21526 SDCC_STACK_TENBIT
21527 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
21528
21529 \end_inset
21530
21531  
21532 \end_layout
21533
21534 \end_inset
21535 </cell>
21536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21537 \begin_inset Text
21538
21539 \begin_layout Standard
21540 when 
21541 \emph on
21542 -mds390
21543 \emph default
21544  is used
21545 \end_layout
21546
21547 \end_inset
21548 </cell>
21549 </row>
21550 <row topline="true" bottomline="true">
21551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21552 \begin_inset Text
21553
21554 \begin_layout Standard
21555 SDCC_MODEL_FLAT24
21556 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
21557
21558 \end_inset
21559
21560
21561 \end_layout
21562
21563 \end_inset
21564 </cell>
21565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21566 \begin_inset Text
21567
21568 \begin_layout Standard
21569 when 
21570 \emph on
21571 -mds390
21572 \emph default
21573  is used
21574 \end_layout
21575
21576 \end_inset
21577 </cell>
21578 </row>
21579 </lyxtabular>
21580
21581 \end_inset
21582
21583
21584 \end_layout
21585
21586 \begin_layout Chapter
21587 Notes on supported Processors
21588 \end_layout
21589
21590 \begin_layout Section
21591 MCS51 variants
21592 \begin_inset LatexCommand \label{sub:MCS51-variants}
21593
21594 \end_inset
21595
21596
21597 \begin_inset LatexCommand \index{MCS51 variants}
21598
21599 \end_inset
21600
21601
21602 \end_layout
21603
21604 \begin_layout Standard
21605 MCS51 processors are available from many vendors and come in many different
21606  flavours.
21607  While they might differ considerably in respect to Special Function Registers
21608  the core MCS51 is usually not modified or is kept compatible.
21609  
21610 \end_layout
21611
21612 \begin_layout Subsection
21613 pdata access by SFR 
21614 \end_layout
21615
21616 \begin_layout Standard
21617 With the upcome of devices with internal xdata and flash memory devices
21618  using port P2
21619 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21620
21621 \end_inset
21622
21623  as dedicated I/O port is becoming more popular.
21624  Switching the high byte for pdata
21625 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21626
21627 \end_inset
21628
21629  access which was formerly done by port P2 is then achieved by a Special
21630  Function Register
21631 \begin_inset LatexCommand \index{sfr}
21632
21633 \end_inset
21634
21635 .
21636  In well-established MCS51 tradition the address of this 
21637 \emph on
21638 sfr
21639 \emph default
21640  is where the chip designers decided to put it.
21641  Needless to say that they didn't agree on a common name either.
21642  So that the startup code can correctly initialize xdata variables, you
21643  should define an sfr with the name _XPAGE
21644 \family typewriter
21645
21646 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
21647
21648 \end_inset
21649
21650
21651 \family default
21652  at the appropriate location if the default, port P2, is not used for this.
21653  Some examples are:
21654 \end_layout
21655
21656 \begin_layout Verse
21657
21658 \family typewriter
21659 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
21660  MPAGE */
21661 \end_layout
21662
21663 \begin_layout Verse
21664
21665 \family typewriter
21666 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
21667  a.k.a.
21668  MPAGE */
21669 \end_layout
21670
21671 \begin_layout Verse
21672
21673 \family typewriter
21674 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
21675  XPAGE */
21676 \end_layout
21677
21678 \begin_layout Verse
21679
21680 \family typewriter
21681 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
21682  EMI0CN */
21683 \end_layout
21684
21685 \begin_layout Verse
21686
21687 \family typewriter
21688 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
21689  EMI0CN */
21690 \end_layout
21691
21692 \begin_layout Standard
21693 For more exotic implementations further customizations may be needed.
21694  See section 
21695 \begin_inset LatexCommand \ref{sub:Startup-Code}
21696
21697 \end_inset
21698
21699  for other possibilities.
21700 \end_layout
21701
21702 \begin_layout Subsection
21703 Other Features available by SFR
21704 \end_layout
21705
21706 \begin_layout Standard
21707 Some MCS51 variants offer features like Double DPTR
21708 \begin_inset LatexCommand \index{DPTR}
21709
21710 \end_inset
21711
21712 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
21713  These are currently not used for the MCS51 port.
21714  If you absolutely need them you can fall back to inline assembly or submit
21715  a patch to SDCC.
21716 \begin_inset VSpace bigskip
21717 \end_inset
21718
21719
21720 \end_layout
21721
21722 \begin_layout Section
21723 DS400 port
21724 \end_layout
21725
21726 \begin_layout Standard
21727 The DS80C400
21728 \begin_inset LatexCommand \index{DS80C400}
21729
21730 \end_inset
21731
21732
21733 \begin_inset LatexCommand \index{DS400}
21734
21735 \end_inset
21736
21737  microcontroller has a rich set of peripherals.
21738  In its built-in ROM library it includes functions to access some of the
21739  features, among them is a TCP stack with IP4 and IP6 support.
21740  Library headers (currently in beta status) and other files are provided
21741  at 
21742 \size footnotesize
21743
21744 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
21745
21746 \end_inset
21747
21748 .
21749  
21750 \begin_inset VSpace bigskip
21751 \end_inset
21752
21753
21754 \end_layout
21755
21756 \begin_layout Section
21757 The Z80 and gbz80 port
21758 \end_layout
21759
21760 \begin_layout Standard
21761 SDCC can target both the Zilog Z80
21762 \begin_inset LatexCommand \index{Z80}
21763
21764 \end_inset
21765
21766  and the Nintendo Gameboy's Z80-like gbz80
21767 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
21768
21769 \end_inset
21770
21771 .
21772  The Z80 port is passed through the same 
21773 \emph on
21774 regressions tests
21775 \begin_inset LatexCommand \index{Regression test}
21776
21777 \end_inset
21778
21779
21780 \emph default
21781  (see section 
21782 \begin_inset LatexCommand \ref{sec:Quality-control}
21783
21784 \end_inset
21785
21786 ) as the MCS51 and DS390 ports, so floating point support, support for long
21787  variables and bitfield support is fine.
21788  See mailing lists and forums about interrupt routines.
21789 \end_layout
21790
21791 \begin_layout Standard
21792 As always, the code is the authoritative reference - see z80/ralloc.c and
21793  z80/gen.c.
21794  The stack
21795 \begin_inset LatexCommand \index{Z80!stack}
21796
21797 \end_inset
21798
21799  frame is similar to that generated by the IAR Z80 compiler.
21800  IX is used as the base pointer, HL and IY are used as a temporary registers,
21801  and BC and DE are available for holding variables.
21802  Return values
21803 \begin_inset LatexCommand \index{Z80!return value}
21804
21805 \end_inset
21806
21807  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
21808  bytes).
21809  The gbz80 port use the same set of registers for the return values, but
21810  in a different order of significance: E (one byte), DE (two bytes), or
21811  HLDE (four bytes).
21812 \begin_inset VSpace bigskip
21813 \end_inset
21814
21815
21816 \end_layout
21817
21818 \begin_layout Section
21819 The HC08 port
21820 \end_layout
21821
21822 \begin_layout Standard
21823 The port to the Freescale/Motorola HC08
21824 \begin_inset LatexCommand \index{HC08}
21825
21826 \end_inset
21827
21828  family has been added in October 2003, and is still undergoing some basic
21829  development.
21830  The code generator is complete, but the register allocation is still quite
21831  unoptimized.
21832  Some of the SDCC's standard C library functions have embedded non-HC08
21833  inline assembly and so are not yet usable.
21834 \end_layout
21835
21836 \begin_layout Standard
21837 The HC08 port passes the regression test suite (see section 
21838 \begin_inset LatexCommand \ref{sec:Quality-control}
21839
21840 \end_inset
21841
21842 ).
21843 \begin_inset VSpace bigskip
21844 \end_inset
21845
21846
21847 \newpage
21848
21849 \end_layout
21850
21851 \begin_layout Section
21852 The PIC14 port
21853 \end_layout
21854
21855 \begin_layout Standard
21856 The 14bit PIC
21857 \begin_inset LatexCommand \index{PIC14}
21858
21859 \end_inset
21860
21861  port still requires a major effort from the development community.
21862  However it can work for simple code.
21863  It passes its (smaller set of) regression tests
21864 \begin_inset LatexCommand \index{Regression test (PIC14)}
21865
21866 \end_inset
21867
21868  in the directory 
21869 \shape italic
21870 sdcc/src/regression
21871 \shape default
21872 .
21873 \end_layout
21874
21875 \begin_layout Subsection
21876 C code and 14bit PIC code page
21877 \begin_inset LatexCommand \index{code page (pic14)}
21878
21879 \end_inset
21880
21881  and RAM banks
21882 \begin_inset LatexCommand \index{RAM bank (pic14)}
21883
21884 \end_inset
21885
21886
21887 \end_layout
21888
21889 \begin_layout Standard
21890 The linker organizes allocation for the code page and RAM banks.
21891  It does not have intimate knowledge of the code flow.
21892  It will put all the code section of a single asm file into a single code
21893  page.
21894  In order to make use of multiple code pages, separate asm files must be
21895  used.
21896  The compiler treats all functions of a single C file as being in the same
21897  code page unless it is non static.
21898 \newline
21899
21900 \newline
21901 To get the best follow these guide lines:
21902 \end_layout
21903
21904 \begin_layout Enumerate
21905 Make local functions static, as non static functions require code page selection
21906  overhead.
21907 \end_layout
21908
21909 \begin_layout Enumerate
21910 For devices that have multiple code pages it is more efficient to use the
21911  same number of files as pages, i.e.
21912  for the 16F877 use 4 separate files and i.e.
21913  for the 16F874 use 2 separate files.
21914  This way the linker can put the code for each file into different code
21915  pages and there's less page selection overhead.
21916 \end_layout
21917
21918 \begin_layout Enumerate
21919 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
21920  instruction set), use 'unsigned char' whereever possible instead of 'int'.
21921 \end_layout
21922
21923 \begin_layout Subsection
21924 Creating a device include file 
21925 \end_layout
21926
21927 \begin_layout Standard
21928 For generating a device include file
21929 \begin_inset LatexCommand \index{PIC14!Header files}
21930
21931 \end_inset
21932
21933  use the support perl script inc2h.pl kept in directory support/script.
21934 \end_layout
21935
21936 \begin_layout Subsection
21937 Interrupt code
21938 \end_layout
21939
21940 \begin_layout Standard
21941 For the interrupt function, use the keyword '__interrupt'
21942 \begin_inset LatexCommand \index{PIC14!interrupt}
21943
21944 \end_inset
21945
21946  with level number of 0 (PIC14 only has 1 interrupt so this number is only
21947  there to avoid a syntax error - it ought to be fixed).
21948  E.g.:
21949 \end_layout
21950
21951 \begin_layout Verse
21952
21953 \family typewriter
21954 void Intr(void) __interrupt 0
21955 \newline
21956 {
21957 \newline
21958 \InsetSpace ~
21959 \InsetSpace ~
21960 T0IF = 0; /* Clear timer interrupt */
21961 \newline
21962 }
21963 \end_layout
21964
21965 \begin_layout Subsection
21966 Linking and assembling
21967 \end_layout
21968
21969 \begin_layout Standard
21970 For assembling you can use either GPUTILS'
21971 \begin_inset LatexCommand \index{gputils (pic tools)}
21972
21973 \end_inset
21974
21975  gpasm.exe or MPLAB's mpasmwin.exe.
21976  GPUTILS is available from 
21977 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21978
21979 \end_inset
21980
21981 .
21982  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
21983  If you use MPLAB and an interrupt function then the linker script file
21984  vectors section will need to be enlarged to link with mplink.
21985 \newline
21986
21987 \newline
21988 Here is a 
21989 \family typewriter
21990 Makefile
21991 \family default
21992  using GPUTILS:
21993 \end_layout
21994
21995 \begin_layout Verse
21996
21997 \family typewriter
21998 .c.o:
21999 \newline
22000 \InsetSpace ~
22001 \InsetSpace ~
22002 \InsetSpace ~
22003 \InsetSpace ~
22004 \InsetSpace ~
22005 \InsetSpace ~
22006 \InsetSpace ~
22007 \InsetSpace ~
22008 sdcc -S -V -mpic14 -p16F877 $< 
22009 \newline
22010 \InsetSpace ~
22011 \InsetSpace ~
22012 \InsetSpace ~
22013 \InsetSpace ~
22014 \InsetSpace ~
22015 \InsetSpace ~
22016 \InsetSpace ~
22017 \InsetSpace ~
22018 gpasm -c $*.asm
22019 \newline
22020
22021 \newline
22022 $(PRJ).hex: $(OBJS) 
22023 \newline
22024 \InsetSpace ~
22025 \InsetSpace ~
22026 \InsetSpace ~
22027 \InsetSpace ~
22028 \InsetSpace ~
22029 \InsetSpace ~
22030 \InsetSpace ~
22031 \InsetSpace ~
22032 gplink
22033  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22034 \end_layout
22035
22036 \begin_layout Standard
22037 Here is a 
22038 \family typewriter
22039 Makefile
22040 \family default
22041  using MPLAB:
22042 \end_layout
22043
22044 \begin_layout Verse
22045
22046 \family typewriter
22047 .c.o: 
22048 \newline
22049 \InsetSpace ~
22050 \InsetSpace ~
22051 \InsetSpace ~
22052 \InsetSpace ~
22053 \InsetSpace ~
22054 \InsetSpace ~
22055 \InsetSpace ~
22056 \InsetSpace ~
22057 sdcc -S -V -mpic14 -p16F877 $< 
22058 \newline
22059 \InsetSpace ~
22060 \InsetSpace ~
22061 \InsetSpace ~
22062 \InsetSpace ~
22063 \InsetSpace ~
22064 \InsetSpace ~
22065 \InsetSpace ~
22066 \InsetSpace ~
22067 mpasmwin /q /o $*.asm
22068 \newline
22069
22070 \newline
22071 $(PRJ).hex: $(OBJS)
22072  
22073 \newline
22074 \InsetSpace ~
22075 \InsetSpace ~
22076 \InsetSpace ~
22077 \InsetSpace ~
22078 \InsetSpace ~
22079 \InsetSpace ~
22080 \InsetSpace ~
22081 \InsetSpace ~
22082 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22083 \end_layout
22084
22085 \begin_layout Standard
22086 Please note that indentations within a
22087 \family typewriter
22088  Makefile
22089 \family default
22090  have to be done with a tabulator character.
22091 \end_layout
22092
22093 \begin_layout Subsection
22094 Command-line options
22095 \end_layout
22096
22097 \begin_layout Standard
22098 Besides the switches common to all SDCC backends, the PIC14 port accepts
22099  the following options (for an updated list see sdcc -
22100 \begin_inset ERT
22101 status collapsed
22102
22103 \begin_layout Standard
22104
22105
22106 \backslash
22107 /
22108 \end_layout
22109
22110 \end_inset
22111
22112 -help):
22113 \end_layout
22114
22115 \begin_layout List
22116 \labelwidthstring 00.00.0000
22117 -
22118 \begin_inset ERT
22119 status collapsed
22120
22121 \begin_layout Standard
22122
22123
22124 \backslash
22125 /
22126 \end_layout
22127
22128 \end_inset
22129
22130 -debug-extra
22131 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22132
22133 \end_inset
22134
22135  emit debug info in assembly output
22136 \end_layout
22137
22138 \begin_layout List
22139 \labelwidthstring 00.00.0000
22140 -
22141 \begin_inset ERT
22142 status collapsed
22143
22144 \begin_layout Standard
22145
22146
22147 \backslash
22148 /
22149 \end_layout
22150
22151 \end_inset
22152
22153 -no-pcode-opt
22154 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22155
22156 \end_inset
22157
22158  disable (slightly faulty) optimization on pCode
22159 \end_layout
22160
22161 \begin_layout List
22162 \labelwidthstring 00.00.0000
22163 -
22164 \begin_inset ERT
22165 status collapsed
22166
22167 \begin_layout Standard
22168
22169
22170 \backslash
22171 /
22172 \end_layout
22173
22174 \end_inset
22175
22176 -stack-loc
22177 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22178
22179 \end_inset
22180
22181  sets the lowest address of the argument passing stack (defaults to a suitably
22182  large shared databank to reduce BANKSEL overhead)
22183 \end_layout
22184
22185 \begin_layout List
22186 \labelwidthstring 00.00.0000
22187 -
22188 \begin_inset ERT
22189 status collapsed
22190
22191 \begin_layout Standard
22192
22193
22194 \backslash
22195 /
22196 \end_layout
22197
22198 \end_inset
22199
22200 -stack-size
22201 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22202
22203 \end_inset
22204
22205  sets the size if the argument passing stack (default: 16, minimum: 4)
22206 \end_layout
22207
22208 \begin_layout Subsection
22209 The library
22210 \end_layout
22211
22212 \begin_layout Subsubsection
22213 error: missing definition for symbol 
22214 \begin_inset Quotes sld
22215 \end_inset
22216
22217 __gptrget1
22218 \begin_inset Quotes srd
22219 \end_inset
22220
22221
22222 \end_layout
22223
22224 \begin_layout Standard
22225 The PIC14 port uses library routines to provide more complex operations
22226  like multiplication, division/modulus and (generic) pointer dereferencing.
22227  In order to add these routines to your project, you must link with PIC14's
22228  
22229 \family typewriter
22230 libsdcc.lib
22231 \family default
22232 .
22233  For single source file projects this is done automatically, more complex
22234  projects must add 
22235 \family typewriter
22236 libsdcc.lib
22237 \family default
22238  to the linker's arguments.
22239  Make sure you also add an include path for the library (using the -I switch
22240  to the linker)!
22241 \end_layout
22242
22243 \begin_layout Subsubsection
22244 Processor mismatch in file 
22245 \begin_inset Quotes sld
22246 \end_inset
22247
22248 XXX
22249 \begin_inset Quotes srd
22250 \end_inset
22251
22252 .
22253 \end_layout
22254
22255 \begin_layout Standard
22256 This warning can usually be ignored due to the very good compatibility amongst
22257  14 bit PIC
22258 \begin_inset LatexCommand \index{PIC14}
22259
22260 \end_inset
22261
22262  devices.
22263 \end_layout
22264
22265 \begin_layout Standard
22266 You might also consider recompiling the library for your specific device
22267  by changing the ARCH=p16f877 (default target) entry in 
22268 \family typewriter
22269 device/lib/pic/Makefile.in
22270 \family default
22271  and 
22272 \family typewriter
22273 device/lib/pic/Makefile
22274 \family default
22275  to reflect your device.
22276  This might even improve performance for smaller devices as unneccesary
22277  BANKSELs migth be removed.
22278 \end_layout
22279
22280 \begin_layout Subsection
22281 Known bugs
22282 \end_layout
22283
22284 \begin_layout Subsubsection
22285 initialized data
22286 \end_layout
22287
22288 \begin_layout Standard
22289 Currently, data can only be initialized if it resides in the source file
22290  together with 
22291 \emph on
22292 main()
22293 \emph default
22294 .
22295  Data in other source files will silently 
22296 \series bold
22297 not
22298 \series default
22299  be initialized.
22300 \family typewriter
22301 \size footnotesize
22302
22303 \begin_inset Marginal
22304 status collapsed
22305
22306 \begin_layout Standard
22307
22308 \series bold
22309 \InsetSpace ~
22310 !
22311 \end_layout
22312
22313 \end_inset
22314
22315
22316 \family default
22317
22318 \newpage
22319
22320 \end_layout
22321
22322 \begin_layout Section
22323 The PIC16
22324 \begin_inset LatexCommand \index{PIC16}
22325
22326 \end_inset
22327
22328  port
22329 \end_layout
22330
22331 \begin_layout Standard
22332 The PIC16
22333 \begin_inset LatexCommand \index{PIC16}
22334
22335 \end_inset
22336
22337  port is the portion of SDCC that is responsible to produce code for the
22338  Microchip
22339 \begin_inset LatexCommand \index{Microchip}
22340
22341 \end_inset
22342
22343 (TM) microcontrollers with 16 bit core.
22344  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22345  Currently supported devices are:
22346 \end_layout
22347
22348 \begin_layout Standard
22349 \align center
22350 \begin_inset Tabular
22351 <lyxtabular version="3" rows="4" columns="6">
22352 <features>
22353 <column alignment="center" valignment="top" leftline="true" width="0">
22354 <column alignment="center" valignment="top" leftline="true" width="0">
22355 <column alignment="center" valignment="top" leftline="true" width="0">
22356 <column alignment="center" valignment="top" leftline="true" width="0">
22357 <column alignment="center" valignment="top" leftline="true" width="0">
22358 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22359 <row topline="true">
22360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22361 \begin_inset Text
22362
22363 \begin_layout Standard
22364 18F242
22365 \end_layout
22366
22367 \end_inset
22368 </cell>
22369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22370 \begin_inset Text
22371
22372 \begin_layout Standard
22373 18F248
22374 \end_layout
22375
22376 \end_inset
22377 </cell>
22378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22379 \begin_inset Text
22380
22381 \begin_layout Standard
22382 18F252
22383 \end_layout
22384
22385 \end_inset
22386 </cell>
22387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22388 \begin_inset Text
22389
22390 \begin_layout Standard
22391 18F258
22392 \end_layout
22393
22394 \end_inset
22395 </cell>
22396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22397 \begin_inset Text
22398
22399 \begin_layout Standard
22400 18F442
22401 \end_layout
22402
22403 \end_inset
22404 </cell>
22405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22406 \begin_inset Text
22407
22408 \begin_layout Standard
22409 18F448
22410 \end_layout
22411
22412 \end_inset
22413 </cell>
22414 </row>
22415 <row topline="true">
22416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22417 \begin_inset Text
22418
22419 \begin_layout Standard
22420 18F452
22421 \end_layout
22422
22423 \end_inset
22424 </cell>
22425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22426 \begin_inset Text
22427
22428 \begin_layout Standard
22429 18F458
22430 \end_layout
22431
22432 \end_inset
22433 </cell>
22434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22435 \begin_inset Text
22436
22437 \begin_layout Standard
22438 18F1220
22439 \end_layout
22440
22441 \end_inset
22442 </cell>
22443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22444 \begin_inset Text
22445
22446 \begin_layout Standard
22447 18F2220
22448 \end_layout
22449
22450 \end_inset
22451 </cell>
22452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22453 \begin_inset Text
22454
22455 \begin_layout Standard
22456 18F2550
22457 \end_layout
22458
22459 \end_inset
22460 </cell>
22461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22462 \begin_inset Text
22463
22464 \begin_layout Standard
22465 18F4331
22466 \end_layout
22467
22468 \end_inset
22469 </cell>
22470 </row>
22471 <row topline="true">
22472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22473 \begin_inset Text
22474
22475 \begin_layout Standard
22476 18F4455
22477 \end_layout
22478
22479 \end_inset
22480 </cell>
22481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22482 \begin_inset Text
22483
22484 \begin_layout Standard
22485 18F6520
22486 \end_layout
22487
22488 \end_inset
22489 </cell>
22490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22491 \begin_inset Text
22492
22493 \begin_layout Standard
22494 18F6620
22495 \end_layout
22496
22497 \end_inset
22498 </cell>
22499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22500 \begin_inset Text
22501
22502 \begin_layout Standard
22503 18F6680
22504 \end_layout
22505
22506 \end_inset
22507 </cell>
22508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22509 \begin_inset Text
22510
22511 \begin_layout Standard
22512 18F6720
22513 \end_layout
22514
22515 \end_inset
22516 </cell>
22517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22518 \begin_inset Text
22519
22520 \begin_layout Standard
22521 18F8520
22522 \end_layout
22523
22524 \end_inset
22525 </cell>
22526 </row>
22527 <row topline="true" bottomline="true">
22528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22529 \begin_inset Text
22530
22531 \begin_layout Standard
22532 18F8620
22533 \end_layout
22534
22535 \end_inset
22536 </cell>
22537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22538 \begin_inset Text
22539
22540 \begin_layout Standard
22541 18F8680
22542 \end_layout
22543
22544 \end_inset
22545 </cell>
22546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22547 \begin_inset Text
22548
22549 \begin_layout Standard
22550 18F8720
22551 \end_layout
22552
22553 \end_inset
22554 </cell>
22555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22556 \begin_inset Text
22557
22558 \begin_layout Standard
22559
22560 \end_layout
22561
22562 \end_inset
22563 </cell>
22564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22565 \begin_inset Text
22566
22567 \begin_layout Standard
22568
22569 \end_layout
22570
22571 \end_inset
22572 </cell>
22573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22574 \begin_inset Text
22575
22576 \begin_layout Standard
22577
22578 \end_layout
22579
22580 \end_inset
22581 </cell>
22582 </row>
22583 </lyxtabular>
22584
22585 \end_inset
22586
22587
22588 \end_layout
22589
22590 \begin_layout Subsection
22591 Global Options
22592 \end_layout
22593
22594 \begin_layout Standard
22595 PIC16 port supports the standard command line arguments as supposed, with
22596  the exception of certain cases that will be mentioned in the following
22597  list:
22598 \end_layout
22599
22600 \begin_layout List
22601 \labelwidthstring 00.00.0000
22602 -
22603 \begin_inset ERT
22604 status collapsed
22605
22606 \begin_layout Standard
22607
22608
22609 \backslash
22610 /
22611 \end_layout
22612
22613 \end_inset
22614
22615 -callee-saves
22616 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
22617
22618 \end_inset
22619
22620  See -
22621 \begin_inset ERT
22622 status collapsed
22623
22624 \begin_layout Standard
22625
22626
22627 \backslash
22628 /
22629 \end_layout
22630
22631 \end_inset
22632
22633 -all-callee-saves
22634 \end_layout
22635
22636 \begin_layout List
22637 \labelwidthstring 00.00.0000
22638 -
22639 \begin_inset ERT
22640 status collapsed
22641
22642 \begin_layout Standard
22643
22644
22645 \backslash
22646 /
22647 \end_layout
22648
22649 \end_inset
22650
22651 -all-callee-saves
22652 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
22653
22654 \end_inset
22655
22656  All function arguments are passed on stack by default.
22657  
22658 \emph on
22659 There is no need to specify this in the command line.
22660 \end_layout
22661
22662 \begin_layout List
22663 \labelwidthstring 00.00.0000
22664 -
22665 \begin_inset ERT
22666 status collapsed
22667
22668 \begin_layout Standard
22669
22670
22671 \backslash
22672 /
22673 \end_layout
22674
22675 \end_inset
22676
22677 -fommit-frame-pointer
22678 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
22679
22680 \end_inset
22681
22682  Frame pointer will be omitted when the function uses no local variables.
22683 \end_layout
22684
22685 \begin_layout Subsection
22686 Port Specific Options
22687 \begin_inset LatexCommand \index{Options PIC16}
22688
22689 \end_inset
22690
22691
22692 \end_layout
22693
22694 \begin_layout Standard
22695 The port specific options appear after the global options in the sdcc --help
22696  output.
22697 \end_layout
22698
22699 \begin_layout Subsubsection
22700 General Options
22701 \end_layout
22702
22703 \begin_layout Standard
22704 General options enable certain port features and optimizations.
22705 \end_layout
22706
22707 \begin_layout List
22708 \labelwidthstring 00.00.0000
22709 -
22710 \begin_inset ERT
22711 status collapsed
22712
22713 \begin_layout Standard
22714
22715
22716 \backslash
22717 /
22718 \end_layout
22719
22720 \end_inset
22721
22722 -pstack-model=[model] Used in conjuction with the command above.
22723  Defines the stack model to be used, valid stack models are : 
22724 \end_layout
22725
22726 \begin_deeper
22727 \begin_layout List
22728 \labelwidthstring 00.00.0000
22729
22730 \emph on
22731 small
22732 \emph default
22733  Selects small stack model.
22734  8 bit stack and frame pointers.
22735  Supports 256 bytes stack size.
22736 \end_layout
22737
22738 \begin_layout List
22739 \labelwidthstring 00.00.0000
22740
22741 \emph on
22742 large
22743 \emph default
22744  Selects large stack model.
22745  16 bit stack and frame pointers.
22746  Supports 65536 bytes stack size.
22747 \end_layout
22748
22749 \end_deeper
22750 \begin_layout List
22751 \labelwidthstring 00.00.0000
22752 -
22753 \begin_inset ERT
22754 status collapsed
22755
22756 \begin_layout Standard
22757
22758
22759 \backslash
22760 /
22761 \end_layout
22762
22763 \end_inset
22764
22765 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
22766  unitialized data variables with [kword].
22767  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
22768 \end_layout
22769
22770 \begin_layout List
22771 \labelwidthstring 00.00.0000
22772 -
22773 \begin_inset ERT
22774 status collapsed
22775
22776 \begin_layout Standard
22777
22778
22779 \backslash
22780 /
22781 \end_layout
22782
22783 \end_inset
22784
22785 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
22786  Useful for bootloaders.
22787 \end_layout
22788
22789 \begin_layout List
22790 \labelwidthstring 00.00.0000
22791 -
22792 \begin_inset ERT
22793 status collapsed
22794
22795 \begin_layout Standard
22796
22797
22798 \backslash
22799 /
22800 \end_layout
22801
22802 \end_inset
22803
22804 -asm= sets the full path and name of an external assembler to call.
22805 \end_layout
22806
22807 \begin_layout List
22808 \labelwidthstring 00.00.0000
22809 -
22810 \begin_inset ERT
22811 status collapsed
22812
22813 \begin_layout Standard
22814
22815
22816 \backslash
22817 /
22818 \end_layout
22819
22820 \end_inset
22821
22822 -link= sets the full path and name of an external linker to call.
22823 \end_layout
22824
22825 \begin_layout List
22826 \labelwidthstring 00.00.0000
22827 -
22828 \begin_inset ERT
22829 status collapsed
22830
22831 \begin_layout Standard
22832
22833
22834 \backslash
22835 /
22836 \end_layout
22837
22838 \end_inset
22839
22840 -mplab-comp MPLAB
22841 \begin_inset LatexCommand \index{PIC16!MPLAB}
22842
22843 \end_inset
22844
22845  compatibility option.
22846  Currently only suppresses special gpasm directives.
22847 \end_layout
22848
22849 \begin_layout Subsubsection
22850 Optimization Options
22851 \end_layout
22852
22853 \begin_layout List
22854 \labelwidthstring 00.00.0000
22855 -
22856 \begin_inset ERT
22857 status collapsed
22858
22859 \begin_layout Standard
22860
22861
22862 \backslash
22863 /
22864 \end_layout
22865
22866 \end_inset
22867
22868 -optimize-goto Try to use (conditional) BRA instead of GOTO
22869 \end_layout
22870
22871 \begin_layout List
22872 \labelwidthstring 00.00.0000
22873 -
22874 \begin_inset ERT
22875 status collapsed
22876
22877 \begin_layout Standard
22878
22879
22880 \backslash
22881 /
22882 \end_layout
22883
22884 \end_inset
22885
22886 -optimize-cmp Try to optimize some compares.
22887 \end_layout
22888
22889 \begin_layout List
22890 \labelwidthstring 00.00.0000
22891 -
22892 \begin_inset ERT
22893 status collapsed
22894
22895 \begin_layout Standard
22896
22897
22898 \backslash
22899 /
22900 \end_layout
22901
22902 \end_inset
22903
22904 -optimize-df Analyze the dataflow of the generated code and improve it.
22905 \end_layout
22906
22907 \begin_layout List
22908 \labelwidthstring 00.00.0000
22909 -
22910 \begin_inset ERT
22911 status collapsed
22912
22913 \begin_layout Standard
22914
22915
22916 \backslash
22917 /
22918 \end_layout
22919
22920 \end_inset
22921
22922 -obanksel=nn Set optimization level for inserting BANKSELs.
22923 \newline
22924
22925 \end_layout
22926
22927 \begin_deeper
22928 \begin_layout List
22929 \labelwidthstring 00.00.0000
22930 0 no optimization
22931 \end_layout
22932
22933 \begin_layout List
22934 \labelwidthstring 00.00.0000
22935 1 checks previous used register and if it is the same then does not emit
22936  BANKSEL, accounts only for labels.
22937 \end_layout
22938
22939 \begin_layout List
22940 \labelwidthstring 00.00.0000
22941 2 tries to check the location of (even different) symbols and removes BANKSELs
22942  if they are in the same bank.
22943  
22944 \newline
22945
22946 \emph on
22947 Important: There might be problems if the linker script has data sections
22948  across bank borders!
22949 \end_layout
22950
22951 \end_deeper
22952 \begin_layout Subsubsection
22953 Linking Options
22954 \end_layout
22955
22956 \begin_layout List
22957 \labelwidthstring 00.00.0000
22958 -
22959 \begin_inset ERT
22960 status collapsed
22961
22962 \begin_layout Standard
22963
22964
22965 \backslash
22966 /
22967 \end_layout
22968
22969 \end_inset
22970
22971 -nodefaultlibs do not link default libraries when linking
22972 \end_layout
22973
22974 \begin_layout List
22975 \labelwidthstring 00.00.0000
22976 -
22977 \begin_inset ERT
22978 status collapsed
22979
22980 \begin_layout Standard
22981
22982
22983 \backslash
22984 /
22985 \end_layout
22986
22987 \end_inset
22988
22989 -no-crt Don't link the default run-time modules
22990 \end_layout
22991
22992 \begin_layout List
22993 \labelwidthstring 00.00.0000
22994 -
22995 \begin_inset ERT
22996 status collapsed
22997
22998 \begin_layout Standard
22999
23000
23001 \backslash
23002 /
23003 \end_layout
23004
23005 \end_inset
23006
23007 -use-crt= Use a custom run-time module instead of the defaults.
23008 \end_layout
23009
23010 \begin_layout Subsubsection
23011 Debugging Options
23012 \end_layout
23013
23014 \begin_layout Standard
23015 Debugging options enable extra debugging information in the output files.
23016 \end_layout
23017
23018 \begin_layout List
23019 \labelwidthstring 00.00.0000
23020 -
23021 \begin_inset ERT
23022 status collapsed
23023
23024 \begin_layout Standard
23025
23026
23027 \backslash
23028 /
23029 \end_layout
23030
23031 \end_inset
23032
23033 -debug-xtra Similar to -
23034 \begin_inset ERT
23035 status collapsed
23036
23037 \begin_layout Standard
23038
23039
23040 \backslash
23041 /
23042 \end_layout
23043
23044 \end_inset
23045
23046 -debug
23047 \begin_inset LatexCommand \index{-\/-debug}
23048
23049 \end_inset
23050
23051 , but dumps more information.
23052 \end_layout
23053
23054 \begin_layout List
23055 \labelwidthstring 00.00.0000
23056 -
23057 \begin_inset ERT
23058 status collapsed
23059
23060 \begin_layout Standard
23061
23062
23063 \backslash
23064 /
23065 \end_layout
23066
23067 \end_inset
23068
23069 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23070  information.
23071  <source> is the name of the file compiled.
23072 \end_layout
23073
23074 \begin_layout List
23075 \labelwidthstring 00.00.0000
23076 -
23077 \begin_inset ERT
23078 status collapsed
23079
23080 \begin_layout Standard
23081
23082
23083 \backslash
23084 /
23085 \end_layout
23086
23087 \end_inset
23088
23089 -pcode-verbose Enable pcode debugging information in translation.
23090 \end_layout
23091
23092 \begin_layout List
23093 \labelwidthstring 00.00.0000
23094 -
23095 \begin_inset ERT
23096 status collapsed
23097
23098 \begin_layout Standard
23099
23100
23101 \backslash
23102 /
23103 \end_layout
23104
23105 \end_inset
23106
23107 -denable-peeps Force the usage of peepholes.
23108  Use with care.
23109 \end_layout
23110
23111 \begin_layout List
23112 \labelwidthstring 00.00.0000
23113 -
23114 \begin_inset ERT
23115 status collapsed
23116
23117 \begin_layout Standard
23118
23119
23120 \backslash
23121 /
23122 \end_layout
23123
23124 \end_inset
23125
23126 -gstack Trace push/pops for stack pointer overflow
23127 \end_layout
23128
23129 \begin_layout List
23130 \labelwidthstring 00.00.0000
23131 -
23132 \begin_inset ERT
23133 status collapsed
23134
23135 \begin_layout Standard
23136
23137
23138 \backslash
23139 /
23140 \end_layout
23141
23142 \end_inset
23143
23144 -call-tree dump call tree in .calltree file
23145 \end_layout
23146
23147 \begin_layout Subsection
23148 Enviromental Variables
23149 \end_layout
23150
23151 \begin_layout Standard
23152 There is a number of enviromental variables that can be used when running
23153  SDCC to enable certain optimizations or force a specific program behaviour.
23154  these variables are primarily for debugging purposes so they can be enabled/dis
23155 abled at will.
23156 \end_layout
23157
23158 \begin_layout Standard
23159 Currently there is only two such variables available:
23160 \end_layout
23161
23162 \begin_layout List
23163 \labelwidthstring 00.00.0000
23164 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23165  bitfields is optimized by directly loading FSR0 with the address of the
23166  bitfield structure.
23167  Normally SDCC will cast the bitfield structure to a bitfield pointer and
23168  then load FSR0.
23169  This step saves data ram and code space for functions that perform heavy
23170  use of bitfields.
23171  (ie.
23172  80 bytes of code space are saved when compiling malloc.c with this option).
23173  
23174 \end_layout
23175
23176 \begin_layout List
23177 \labelwidthstring 00.00.0000
23178 NO_REG_OPT do not perform pCode registers optimization.
23179  This should be used for debugging purposes.
23180  In some where bugs in the pcode optimizer are found, users can benefit
23181  from temporarily disabling the optimizer until the bug is fixed.
23182 \end_layout
23183
23184 \begin_layout Subsection
23185 Preprocessor Macros
23186 \end_layout
23187
23188 \begin_layout Standard
23189 PIC16
23190 \begin_inset LatexCommand \index{PIC16}
23191
23192 \end_inset
23193
23194  port defines the following preprocessor macros while translating a source.
23195 \end_layout
23196
23197 \begin_layout Standard
23198 \align center
23199 \begin_inset Tabular
23200 <lyxtabular version="3" rows="6" columns="2">
23201 <features>
23202 <column alignment="center" valignment="top" leftline="true" width="0">
23203 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23204 <row topline="true" bottomline="true">
23205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23206 \begin_inset Text
23207
23208 \begin_layout Standard
23209 Macro
23210 \end_layout
23211
23212 \end_inset
23213 </cell>
23214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23215 \begin_inset Text
23216
23217 \begin_layout Standard
23218 Description
23219 \end_layout
23220
23221 \end_inset
23222 </cell>
23223 </row>
23224 <row topline="true">
23225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23226 \begin_inset Text
23227
23228 \begin_layout Standard
23229 SDCC_pic16
23230 \end_layout
23231
23232 \end_inset
23233 </cell>
23234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23235 \begin_inset Text
23236
23237 \begin_layout Standard
23238 Port identification
23239 \end_layout
23240
23241 \end_inset
23242 </cell>
23243 </row>
23244 <row topline="true">
23245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23246 \begin_inset Text
23247
23248 \begin_layout Standard
23249 _
23250 \begin_inset ERT
23251 status collapsed
23252
23253 \begin_layout Standard
23254
23255
23256 \backslash
23257 /
23258 \end_layout
23259
23260 \end_inset
23261
23262 _pic16
23263 \end_layout
23264
23265 \end_inset
23266 </cell>
23267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23268 \begin_inset Text
23269
23270 \begin_layout Standard
23271 Port identification (same as above)
23272 \end_layout
23273
23274 \end_inset
23275 </cell>
23276 </row>
23277 <row topline="true">
23278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23279 \begin_inset Text
23280
23281 \begin_layout Standard
23282 pic18fxxxx
23283 \end_layout
23284
23285 \end_inset
23286 </cell>
23287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23288 \begin_inset Text
23289
23290 \begin_layout Standard
23291 MCU Identification.
23292  
23293 \emph on
23294 xxxx
23295 \emph default
23296  is the microcontrol identification number, i.e.
23297  452, 6620, etc
23298 \end_layout
23299
23300 \end_inset
23301 </cell>
23302 </row>
23303 <row topline="true">
23304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23305 \begin_inset Text
23306
23307 \begin_layout Standard
23308 _
23309 \begin_inset ERT
23310 status collapsed
23311
23312 \begin_layout Standard
23313
23314
23315 \backslash
23316 /
23317 \end_layout
23318
23319 \end_inset
23320
23321 _18Fxxxx
23322 \end_layout
23323
23324 \end_inset
23325 </cell>
23326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23327 \begin_inset Text
23328
23329 \begin_layout Standard
23330 MCU Identification (same as above)
23331 \end_layout
23332
23333 \end_inset
23334 </cell>
23335 </row>
23336 <row topline="true" bottomline="true">
23337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23338 \begin_inset Text
23339
23340 \begin_layout Standard
23341 STACK_MODEL_nnn
23342 \end_layout
23343
23344 \end_inset
23345 </cell>
23346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23347 \begin_inset Text
23348
23349 \begin_layout Standard
23350 nnn = SMALL or LARGE respectively according to the stack model used
23351 \end_layout
23352
23353 \end_inset
23354 </cell>
23355 </row>
23356 </lyxtabular>
23357
23358 \end_inset
23359
23360
23361 \end_layout
23362
23363 \begin_layout Standard
23364 In addition the following macros are defined when calling assembler:
23365 \end_layout
23366
23367 \begin_layout Standard
23368 \align center
23369 \begin_inset Tabular
23370 <lyxtabular version="3" rows="4" columns="2">
23371 <features>
23372 <column alignment="center" valignment="top" leftline="true" width="0">
23373 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23374 <row topline="true" bottomline="true">
23375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23376 \begin_inset Text
23377
23378 \begin_layout Standard
23379 Macro
23380 \end_layout
23381
23382 \end_inset
23383 </cell>
23384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23385 \begin_inset Text
23386
23387 \begin_layout Standard
23388 Description
23389 \end_layout
23390
23391 \end_inset
23392 </cell>
23393 </row>
23394 <row topline="true">
23395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23396 \begin_inset Text
23397
23398 \begin_layout Standard
23399 __18Fxxxx
23400 \end_layout
23401
23402 \end_inset
23403 </cell>
23404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23405 \begin_inset Text
23406
23407 \begin_layout Standard
23408 MCU Identification.
23409  
23410 \emph on
23411 xxxx
23412 \emph default
23413  is the microcontrol identification number, i.e.
23414  452, 6620, etc
23415 \end_layout
23416
23417 \end_inset
23418 </cell>
23419 </row>
23420 <row topline="true">
23421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23422 \begin_inset Text
23423
23424 \begin_layout Standard
23425 SDCC_MODEL_nnn
23426 \end_layout
23427
23428 \end_inset
23429 </cell>
23430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23431 \begin_inset Text
23432
23433 \begin_layout Standard
23434 nnn = SMALL or LARGE respectively according to the memory model used for
23435  SDCC
23436 \end_layout
23437
23438 \end_inset
23439 </cell>
23440 </row>
23441 <row topline="true" bottomline="true">
23442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23443 \begin_inset Text
23444
23445 \begin_layout Standard
23446 STACK_MODEL_nnn
23447 \end_layout
23448
23449 \end_inset
23450 </cell>
23451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23452 \begin_inset Text
23453
23454 \begin_layout Standard
23455 nnn = SMALL or LARGE respectively according to the stack model used
23456 \end_layout
23457
23458 \end_inset
23459 </cell>
23460 </row>
23461 </lyxtabular>
23462
23463 \end_inset
23464
23465
23466 \end_layout
23467
23468 \begin_layout Subsection
23469 Directories
23470 \end_layout
23471
23472 \begin_layout Standard
23473 PIC16
23474 \begin_inset LatexCommand \index{PIC16}
23475
23476 \end_inset
23477
23478  port uses the following directories for searching header files and libraries.
23479 \end_layout
23480
23481 \begin_layout Standard
23482 \align center
23483 \begin_inset Tabular
23484 <lyxtabular version="3" rows="3" columns="4">
23485 <features>
23486 <column alignment="center" valignment="top" leftline="true" width="0">
23487 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23488 <column alignment="center" valignment="top" width="0">
23489 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23490 <row topline="true" bottomline="true">
23491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23492 \begin_inset Text
23493
23494 \begin_layout Standard
23495 Directory
23496 \end_layout
23497
23498 \end_inset
23499 </cell>
23500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23501 \begin_inset Text
23502
23503 \begin_layout Standard
23504 Description
23505 \end_layout
23506
23507 \end_inset
23508 </cell>
23509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23510 \begin_inset Text
23511
23512 \begin_layout Standard
23513 Target
23514 \end_layout
23515
23516 \end_inset
23517 </cell>
23518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23519 \begin_inset Text
23520
23521 \begin_layout Standard
23522 Command prefix
23523 \end_layout
23524
23525 \end_inset
23526 </cell>
23527 </row>
23528 <row topline="true">
23529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23530 \begin_inset Text
23531
23532 \begin_layout Standard
23533 PREFIX/sdcc/include/pic16
23534 \end_layout
23535
23536 \end_inset
23537 </cell>
23538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23539 \begin_inset Text
23540
23541 \begin_layout Standard
23542 PIC16 specific headers
23543 \end_layout
23544
23545 \end_inset
23546 </cell>
23547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23548 \begin_inset Text
23549
23550 \begin_layout Standard
23551 Compiler
23552 \end_layout
23553
23554 \end_inset
23555 </cell>
23556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23557 \begin_inset Text
23558
23559 \begin_layout Standard
23560 -I
23561 \end_layout
23562
23563 \end_inset
23564 </cell>
23565 </row>
23566 <row topline="true" bottomline="true">
23567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23568 \begin_inset Text
23569
23570 \begin_layout Standard
23571 PREFIX/sdcc/lib/pic16
23572 \end_layout
23573
23574 \end_inset
23575 </cell>
23576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23577 \begin_inset Text
23578
23579 \begin_layout Standard
23580 PIC16 specific libraries
23581 \end_layout
23582
23583 \end_inset
23584 </cell>
23585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23586 \begin_inset Text
23587
23588 \begin_layout Standard
23589 Linker
23590 \end_layout
23591
23592 \end_inset
23593 </cell>
23594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23595 \begin_inset Text
23596
23597 \begin_layout Standard
23598 -L
23599 \end_layout
23600
23601 \end_inset
23602 </cell>
23603 </row>
23604 </lyxtabular>
23605
23606 \end_inset
23607
23608
23609 \end_layout
23610
23611 \begin_layout Subsection
23612 Pragmas
23613 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
23614
23615 \end_inset
23616
23617
23618 \end_layout
23619
23620 \begin_layout Standard
23621 PIC16
23622 \begin_inset LatexCommand \index{PIC16}
23623
23624 \end_inset
23625
23626  port currently supports the following pragmas:
23627 \end_layout
23628
23629 \begin_layout List
23630 \labelwidthstring 00.00.0000
23631 stack
23632 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
23633
23634 \end_inset
23635
23636  pragma stack
23637 \begin_inset LatexCommand \index{PIC16!stack}
23638
23639 \end_inset
23640
23641  forces the code generator to initialize the stack & frame pointers at a
23642  specific address.
23643  This is an adhoc solution for cases where no STACK directive is available
23644  in the linker script or gplink is not instructed to create a stack section.
23645 \newline
23646 The
23647  stack pragma should be used only once in a project.
23648  Multiple pragmas may result in indeterminate behaviour of the program.
23649 \begin_inset Foot
23650 status open
23651
23652 \begin_layout Standard
23653 The old format (ie.
23654  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
23655  cross page boundaries (or even exceed the available data RAM) and crash
23656  the program.
23657  Make sure that stack does not cross page boundaries when using the SMALL
23658  stack model.
23659 \end_layout
23660
23661 \end_inset
23662
23663
23664 \newline
23665 The format is as follows:
23666 \end_layout
23667
23668 \begin_layout LyX-Code
23669 #pragma stack bottom_address [stack_size]
23670 \end_layout
23671
23672 \begin_layout Standard
23673
23674 \emph on
23675 bottom_address
23676 \emph default
23677  is the lower bound of the stack section.
23678  The stack pointer initially will point at address (bottom_address+stack_size-1).
23679 \end_layout
23680
23681 \begin_layout LyX-Code
23682 Example:
23683 \end_layout
23684
23685 \begin_layout LyX-Code
23686
23687 \end_layout
23688
23689 \begin_layout LyX-Code
23690 /* initializes stack of 100 bytes at RAM address 0x200 */
23691 \end_layout
23692
23693 \begin_layout LyX-Code
23694 #pragma stack 0x200 100
23695 \end_layout
23696
23697 \begin_layout Standard
23698 If the stack_size field is omitted then a stack is created with the default
23699  size of 64.
23700  This size might be enough for most programs, but its not enough for operations
23701  with deep function nesting or excessive stack usage.
23702 \end_layout
23703
23704 \begin_layout List
23705 \labelwidthstring 00.00.0000
23706 code
23707 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
23708
23709 \end_inset
23710
23711  place a function symbol at static FLASH address
23712 \end_layout
23713
23714 \begin_layout LyX-Code
23715 Example:
23716 \end_layout
23717
23718 \begin_layout LyX-Code
23719
23720 \end_layout
23721
23722 \begin_layout LyX-Code
23723 /* place function test_func at 0x4000 */
23724 \end_layout
23725
23726 \begin_layout LyX-Code
23727 #pragma code test_func 0x4000
23728 \end_layout
23729
23730 \begin_layout LyX-Code
23731
23732 \end_layout
23733
23734 \begin_layout List
23735 \labelwidthstring 00.00.0000
23736 library instructs the linker to use a library module.
23737 \newline
23738 Usage:
23739 \end_layout
23740
23741 \begin_layout LyX-Code
23742 #pragma library module_name
23743 \end_layout
23744
23745 \begin_layout Standard
23746
23747 \emph on
23748 module_name
23749 \emph default
23750  can be any library or object file (including its path).
23751  Note that there are four reserved keywords which have special meaning.
23752  These are:
23753 \end_layout
23754
23755 \begin_layout Standard
23756 \align center
23757 \begin_inset Tabular
23758 <lyxtabular version="3" rows="6" columns="3">
23759 <features>
23760 <column alignment="center" valignment="top" leftline="true" width="0">
23761 <column alignment="block" valignment="top" leftline="true" width="20page%">
23762 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
23763 <row topline="true" bottomline="true">
23764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23765 \begin_inset Text
23766
23767 \begin_layout Standard
23768 Keyword
23769 \end_layout
23770
23771 \end_inset
23772 </cell>
23773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23774 \begin_inset Text
23775
23776 \begin_layout Standard
23777 Description
23778 \end_layout
23779
23780 \end_inset
23781 </cell>
23782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23783 \begin_inset Text
23784
23785 \begin_layout Standard
23786 Module to link
23787 \end_layout
23788
23789 \end_inset
23790 </cell>
23791 </row>
23792 <row topline="true">
23793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23794 \begin_inset Text
23795
23796 \begin_layout Standard
23797
23798 \series bold
23799 ignore
23800 \end_layout
23801
23802 \end_inset
23803 </cell>
23804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23805 \begin_inset Text
23806
23807 \begin_layout Standard
23808 ignore all library pragmas
23809 \end_layout
23810
23811 \end_inset
23812 </cell>
23813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23814 \begin_inset Text
23815
23816 \begin_layout Standard
23817
23818 \emph on
23819 (none)
23820 \end_layout
23821
23822 \end_inset
23823 </cell>
23824 </row>
23825 <row topline="true">
23826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23827 \begin_inset Text
23828
23829 \begin_layout Standard
23830
23831 \series bold
23832 c
23833 \end_layout
23834
23835 \end_inset
23836 </cell>
23837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23838 \begin_inset Text
23839
23840 \begin_layout Standard
23841 link the C library
23842 \end_layout
23843
23844 \end_inset
23845 </cell>
23846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23847 \begin_inset Text
23848
23849 \begin_layout Standard
23850
23851 \emph on
23852 libc18f
23853 \emph default
23854 .lib
23855 \end_layout
23856
23857 \end_inset
23858 </cell>
23859 </row>
23860 <row topline="true">
23861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23862 \begin_inset Text
23863
23864 \begin_layout Standard
23865
23866 \series bold
23867 math
23868 \end_layout
23869
23870 \end_inset
23871 </cell>
23872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23873 \begin_inset Text
23874
23875 \begin_layout Standard
23876 link the Math libarary
23877 \end_layout
23878
23879 \end_inset
23880 </cell>
23881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23882 \begin_inset Text
23883
23884 \begin_layout Standard
23885
23886 \emph on
23887 libm18f
23888 \emph default
23889 .lib
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
23901 \series bold
23902 io
23903 \end_layout
23904
23905 \end_inset
23906 </cell>
23907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23908 \begin_inset Text
23909
23910 \begin_layout Standard
23911 link the I/O library
23912 \end_layout
23913
23914 \end_inset
23915 </cell>
23916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23917 \begin_inset Text
23918
23919 \begin_layout Standard
23920
23921 \emph on
23922 libio18f*
23923 \emph default
23924 .lib
23925 \end_layout
23926
23927 \end_inset
23928 </cell>
23929 </row>
23930 <row topline="true" bottomline="true">
23931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23932 \begin_inset Text
23933
23934 \begin_layout Standard
23935
23936 \series bold
23937 debug
23938 \end_layout
23939
23940 \end_inset
23941 </cell>
23942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23943 \begin_inset Text
23944
23945 \begin_layout Standard
23946 link the debug library
23947 \end_layout
23948
23949 \end_inset
23950 </cell>
23951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23952 \begin_inset Text
23953
23954 \begin_layout Standard
23955
23956 \emph on
23957 libdebug
23958 \emph default
23959 .lib
23960 \end_layout
23961
23962 \end_inset
23963 </cell>
23964 </row>
23965 </lyxtabular>
23966
23967 \end_inset
23968
23969
23970 \newline
23971 * is the device number, i.e.
23972  452 for PIC18F452 MCU.
23973 \end_layout
23974
23975 \begin_layout Standard
23976 This feature allows for linking with specific libraries withoug having to
23977  explicit name them in the command line.
23978  Note that the 
23979 \noun on
23980 ignore
23981 \noun default
23982  keyword will reject all modules specified by the library pragma.
23983 \end_layout
23984
23985 \begin_layout List
23986 \labelwidthstring 00.00.0000
23987 udata pragma udata instructs the compiler to emit code so that linker will
23988  place a variable at a specific memory bank
23989 \end_layout
23990
23991 \begin_layout LyX-Code
23992 Example:
23993 \end_layout
23994
23995 \begin_layout LyX-Code
23996
23997 \end_layout
23998
23999 \begin_layout LyX-Code
24000 /* places variable foo at bank2 */
24001 \end_layout
24002
24003 \begin_layout LyX-Code
24004 #pragma udata bank2 foo
24005 \end_layout
24006
24007 \begin_layout LyX-Code
24008 char foo;
24009 \end_layout
24010
24011 \begin_layout Standard
24012 In order for this pragma to work extra SECTION directives should be added
24013  in the .lkr script.
24014  In the following example a sample .lkr file is shown:
24015 \end_layout
24016
24017 \begin_layout LyX-Code
24018
24019 \end_layout
24020
24021 \begin_layout LyX-Code
24022 // Sample linker script for the PIC18F452 processor
24023 \end_layout
24024
24025 \begin_layout LyX-Code
24026 LIBPATH .
24027 \end_layout
24028
24029 \begin_layout LyX-Code
24030 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24031 \end_layout
24032
24033 \begin_layout LyX-Code
24034 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24035 \end_layout
24036
24037 \begin_layout LyX-Code
24038 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24039 \end_layout
24040
24041 \begin_layout LyX-Code
24042 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24043 \end_layout
24044
24045 \begin_layout LyX-Code
24046 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24047 \end_layout
24048
24049 \begin_layout LyX-Code
24050 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24051 \end_layout
24052
24053 \begin_layout LyX-Code
24054 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24055 \end_layout
24056
24057 \begin_layout LyX-Code
24058
24059 \end_layout
24060
24061 \begin_layout LyX-Code
24062 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24063 \end_layout
24064
24065 \begin_layout LyX-Code
24066 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24067 \end_layout
24068
24069 \begin_layout LyX-Code
24070 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24071 \end_layout
24072
24073 \begin_layout LyX-Code
24074 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24075 \end_layout
24076
24077 \begin_layout LyX-Code
24078 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24079 \end_layout
24080
24081 \begin_layout LyX-Code
24082 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24083 \end_layout
24084
24085 \begin_layout LyX-Code
24086 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24087 \end_layout
24088
24089 \begin_layout LyX-Code
24090
24091 \end_layout
24092
24093 \begin_layout LyX-Code
24094 SECTION    NAME=CONFIG     ROM=config
24095 \end_layout
24096
24097 \begin_layout LyX-Code
24098
24099 \end_layout
24100
24101 \begin_layout LyX-Code
24102 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
24103 \end_layout
24104
24105 \begin_layout LyX-Code
24106 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
24107 \end_layout
24108
24109 \begin_layout LyX-Code
24110 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
24111 \end_layout
24112
24113 \begin_layout LyX-Code
24114 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
24115 \end_layout
24116
24117 \begin_layout LyX-Code
24118 SECTION    NAME=bank4      RAM=gpr4
24119 \end_layout
24120
24121 \begin_layout LyX-Code
24122 SECTION    NAME=bank5      RAM=gpr5
24123 \end_layout
24124
24125 \begin_layout Standard
24126 The linker will recognise the section name set in the pragma statement and
24127  will position the variable at the memory bank set with the RAM field at
24128  the SECTION line in the linker script file.
24129 \end_layout
24130
24131 \begin_layout Subsection
24132 Header Files
24133 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24134
24135 \end_inset
24136
24137
24138 \end_layout
24139
24140 \begin_layout Standard
24141 There is one main header file
24142 \begin_inset LatexCommand \index{PIC16!Header files}
24143
24144 \end_inset
24145
24146  that can be included to the source files using the pic16
24147 \begin_inset LatexCommand \index{PIC16}
24148
24149 \end_inset
24150
24151  port.
24152  That file is the 
24153 \series bold
24154 pic18fregs.h
24155 \series default
24156 .
24157  This header file contains the definitions for the processor special registers,
24158  so it is necessary if the source accesses them.
24159  It can be included by adding the following line in the beginning of the
24160  file:
24161 \end_layout
24162
24163 \begin_layout LyX-Code
24164 #include <pic18fregs.h>
24165 \end_layout
24166
24167 \begin_layout Standard
24168 The specific microcontroller is selected within the pic18fregs.h automatically,
24169  so the same source can be used with a variety of devices.
24170 \end_layout
24171
24172 \begin_layout Subsection
24173 Libraries
24174 \end_layout
24175
24176 \begin_layout Standard
24177 The libraries
24178 \begin_inset LatexCommand \index{PIC16!Libraries}
24179
24180 \end_inset
24181
24182  that PIC16
24183 \begin_inset LatexCommand \index{PIC16}
24184
24185 \end_inset
24186
24187  port depends on are the microcontroller device libraries which contain
24188  the symbol definitions for the microcontroller special function registers.
24189  These libraries have the format pic18fxxxx.lib, where 
24190 \emph on
24191 xxxx
24192 \emph default
24193  is the microcontroller identification number.
24194  The specific library is selected automatically by the compiler at link
24195  stage according to the selected device.
24196 \end_layout
24197
24198 \begin_layout Standard
24199 Libraries are created with gplib which is part of the gputils package 
24200 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24201
24202 \end_inset
24203
24204 .
24205 \end_layout
24206
24207 \begin_layout Subsubsection*
24208 Building the libraries
24209 \end_layout
24210
24211 \begin_layout Standard
24212 Before using SDCC/pic16 there are some libraries that need to be compiled.
24213  This process is not done automatically by SDCC since not all users use
24214  SDCC for pic16 projects.
24215  So each user should compile the libraries separately.
24216 \end_layout
24217
24218 \begin_layout Standard
24219 The steps to compile the pic16 libraries under Linux are:
24220 \end_layout
24221
24222 \begin_layout LyX-Code
24223 cd device/lib/pic16
24224 \end_layout
24225
24226 \begin_layout LyX-Code
24227 ./configure
24228 \end_layout
24229
24230 \begin_layout LyX-Code
24231 make
24232 \end_layout
24233
24234 \begin_layout LyX-Code
24235 cd ..
24236 \end_layout
24237
24238 \begin_layout LyX-Code
24239 make model-pic16
24240 \end_layout
24241
24242 \begin_layout LyX-Code
24243 su -c 'make install'     # install the libraries, you need the root password
24244 \end_layout
24245
24246 \begin_layout Standard
24247 If you need to install the headers too, do:
24248 \end_layout
24249
24250 \begin_layout LyX-Code
24251 cd device/include
24252 \end_layout
24253
24254 \begin_layout LyX-Code
24255 su -c 'make install'     # install the headers, you need the root password
24256 \end_layout
24257
24258 \begin_layout Standard
24259 There exist a special target to build the I/O libraries.
24260  This target is not automatically build because it will build the I/O library
24261  for 
24262 \emph on
24263 every
24264 \emph default
24265  supported device.
24266  This way building will take quite a lot of time.
24267  Users are advised to edit the 
24268 \series bold
24269 device/lib/pic16/pics.build
24270 \series default
24271  file and then execute:
24272 \end_layout
24273
24274 \begin_layout LyX-Code
24275 make lib-io
24276 \end_layout
24277
24278 \begin_layout Subsection
24279 Memory Models
24280 \end_layout
24281
24282 \begin_layout Standard
24283 The following memory models are supported by the PIC16 port:
24284 \end_layout
24285
24286 \begin_layout Itemize
24287 small model
24288 \end_layout
24289
24290 \begin_layout Itemize
24291 large model
24292 \end_layout
24293
24294 \begin_layout Standard
24295 Memory model affects the default size of pointers within the source.
24296  The sizes are shown in the next table:
24297 \end_layout
24298
24299 \begin_layout Standard
24300 \align center
24301 \begin_inset Tabular
24302 <lyxtabular version="3" rows="3" columns="3">
24303 <features>
24304 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24305 <column alignment="center" valignment="top" leftline="true" width="0">
24306 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24307 <row topline="true" bottomline="true">
24308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24309 \begin_inset Text
24310
24311 \begin_layout Standard
24312 Pointer sizes according to memory model
24313 \end_layout
24314
24315 \end_inset
24316 </cell>
24317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24318 \begin_inset Text
24319
24320 \begin_layout Standard
24321 small model
24322 \end_layout
24323
24324 \end_inset
24325 </cell>
24326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24327 \begin_inset Text
24328
24329 \begin_layout Standard
24330 large model
24331 \end_layout
24332
24333 \end_inset
24334 </cell>
24335 </row>
24336 <row topline="true" bottomline="true">
24337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24338 \begin_inset Text
24339
24340 \begin_layout Standard
24341 code pointers
24342 \end_layout
24343
24344 \end_inset
24345 </cell>
24346 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24347 \begin_inset Text
24348
24349 \begin_layout Standard
24350 16-bits
24351 \end_layout
24352
24353 \end_inset
24354 </cell>
24355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24356 \begin_inset Text
24357
24358 \begin_layout Standard
24359 24-bits
24360 \end_layout
24361
24362 \end_inset
24363 </cell>
24364 </row>
24365 <row topline="true" bottomline="true">
24366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24367 \begin_inset Text
24368
24369 \begin_layout Standard
24370 data pointers
24371 \end_layout
24372
24373 \end_inset
24374 </cell>
24375 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24376 \begin_inset Text
24377
24378 \begin_layout Standard
24379 16-bits
24380 \end_layout
24381
24382 \end_inset
24383 </cell>
24384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24385 \begin_inset Text
24386
24387 \begin_layout Standard
24388 16-bits
24389 \end_layout
24390
24391 \end_inset
24392 </cell>
24393 </row>
24394 </lyxtabular>
24395
24396 \end_inset
24397
24398
24399 \end_layout
24400
24401 \begin_layout Standard
24402 It is advisable that all sources within a project are compiled with the
24403  same memory model.
24404  If one wants to override the default memory model, this can be done by
24405  declaring a pointer as 
24406 \series bold
24407 far
24408 \series default
24409  or 
24410 \series bold
24411 near
24412 \series default
24413 .
24414  Far selects large memory model's pointers, while near selects small memory
24415  model's pointers.
24416 \end_layout
24417
24418 \begin_layout Standard
24419 The standard device libraries (see 
24420 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
24421
24422 \end_inset
24423
24424 ) contain no reference to pointers, so they can be used with both memory
24425  models.
24426 \end_layout
24427
24428 \begin_layout Subsection
24429 Stack
24430 \end_layout
24431
24432 \begin_layout Standard
24433 The stack
24434 \begin_inset LatexCommand \index{PIC16!stack}
24435
24436 \end_inset
24437
24438  implementation for the PIC16 port uses two indirect registers, FSR1 and
24439  FSR2.
24440 \end_layout
24441
24442 \begin_layout List
24443 \labelwidthstring 00.00.0000
24444 FSR1 is assigned as stack pointer
24445 \end_layout
24446
24447 \begin_layout List
24448 \labelwidthstring 00.00.0000
24449 FSR2 is assigned as frame pointer
24450 \end_layout
24451
24452 \begin_layout Standard
24453 The following stack models are supported by the PIC16 port
24454 \end_layout
24455
24456 \begin_layout Itemize
24457
24458 \noun on
24459 small
24460 \noun default
24461  model
24462 \end_layout
24463
24464 \begin_layout Itemize
24465
24466 \noun on
24467 large
24468 \noun default
24469  model
24470 \end_layout
24471
24472 \begin_layout Standard
24473
24474 \noun on
24475 Small
24476 \noun default
24477  model means that only the FSRxL byte is used to access stack and frame,
24478  while 
24479 \emph on
24480 \noun on
24481 large
24482 \emph default
24483 \noun default
24484  uses both FSRxL and FSRxH registers.
24485  The following table shows the stack/frame pointers sizes according to stack
24486  model and the maximum space they can address:
24487 \end_layout
24488
24489 \begin_layout Standard
24490 \align center
24491 \begin_inset Tabular
24492 <lyxtabular version="3" rows="3" columns="3">
24493 <features>
24494 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24495 <column alignment="center" valignment="top" leftline="true" width="0">
24496 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24497 <row topline="true" bottomline="true">
24498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24499 \begin_inset Text
24500
24501 \begin_layout Standard
24502 Stack & Frame pointer sizes according to stack model
24503 \end_layout
24504
24505 \end_inset
24506 </cell>
24507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24508 \begin_inset Text
24509
24510 \begin_layout Standard
24511 small
24512 \end_layout
24513
24514 \end_inset
24515 </cell>
24516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24517 \begin_inset Text
24518
24519 \begin_layout Standard
24520 large
24521 \end_layout
24522
24523 \end_inset
24524 </cell>
24525 </row>
24526 <row topline="true">
24527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24528 \begin_inset Text
24529
24530 \begin_layout Standard
24531 Stack pointer FSR1
24532 \end_layout
24533
24534 \end_inset
24535 </cell>
24536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24537 \begin_inset Text
24538
24539 \begin_layout Standard
24540 8-bits
24541 \end_layout
24542
24543 \end_inset
24544 </cell>
24545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24546 \begin_inset Text
24547
24548 \begin_layout Standard
24549 16-bits
24550 \end_layout
24551
24552 \end_inset
24553 </cell>
24554 </row>
24555 <row topline="true" bottomline="true">
24556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24557 \begin_inset Text
24558
24559 \begin_layout Standard
24560 Frame pointer FSR2
24561 \end_layout
24562
24563 \end_inset
24564 </cell>
24565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24566 \begin_inset Text
24567
24568 \begin_layout Standard
24569 8-bits
24570 \end_layout
24571
24572 \end_inset
24573 </cell>
24574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24575 \begin_inset Text
24576
24577 \begin_layout Standard
24578 16-bits
24579 \end_layout
24580
24581 \end_inset
24582 </cell>
24583 </row>
24584 </lyxtabular>
24585
24586 \end_inset
24587
24588
24589 \end_layout
24590
24591 \begin_layout Standard
24592
24593 \noun on
24594 Large 
24595 \noun default
24596 stack model is currently not working properly throughout the code generator.
24597  So its use is not advised.
24598  Also there are some other points that need special care:
24599 \newline
24600
24601 \end_layout
24602
24603 \begin_layout Enumerate
24604 Do not create stack sections with size more than one physical bank (that
24605  is 256 bytes)
24606 \end_layout
24607
24608 \begin_layout Enumerate
24609 Stack sections should no cross physical bank limits (i.e.
24610  #pragma stack 0x50 0x100)
24611 \end_layout
24612
24613 \begin_layout Standard
24614 These limitations are caused by the fact that only FSRxL is modified when
24615  using SMALL stack model, so no more than 256 bytes of stack can be used.
24616  This problem will disappear after LARGE model is fully implemented.
24617 \end_layout
24618
24619 \begin_layout Subsection
24620 Functions
24621 \end_layout
24622
24623 \begin_layout Standard
24624 In addition to the standard SDCC function keywords, PIC16
24625 \begin_inset LatexCommand \index{PIC16}
24626
24627 \end_inset
24628
24629  port makes available two more:
24630 \end_layout
24631
24632 \begin_layout List
24633 \labelwidthstring 00.00.0000
24634 wparam
24635 \begin_inset LatexCommand \index{PIC16!wparam}
24636
24637 \end_inset
24638
24639  Use the WREG to pass one byte of the first function argument.
24640  This improves speed but you may not use this for functions with arguments
24641  that are called via function pointers, otherwise the first byte of the
24642  first parameter will get lost.
24643  Usage:
24644 \end_layout
24645
24646 \begin_layout LyX-Code
24647 void func_wparam(int a) wparam
24648 \end_layout
24649
24650 \begin_layout LyX-Code
24651 {
24652 \end_layout
24653
24654 \begin_layout LyX-Code
24655     /* WREG hold the lower part of a */
24656 \end_layout
24657
24658 \begin_layout LyX-Code
24659     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
24660  */
24661 \end_layout
24662
24663 \begin_layout LyX-Code
24664 ...
24665 \end_layout
24666
24667 \begin_layout LyX-Code
24668 }
24669 \end_layout
24670
24671 \begin_layout List
24672 \labelwidthstring 00.00.0000
24673 shadowregs
24674 \begin_inset LatexCommand \index{PIC16!shadowregs}
24675
24676 \end_inset
24677
24678  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
24679  hardware shadow registers which hold the values of WREG, STATUS and BSR
24680  registers.
24681  This can be done by adding the keyword 
24682 \emph on
24683 shadowregs
24684 \emph default
24685  before the 
24686 \emph on
24687 interrupt
24688 \emph default
24689  keyword in the function's header.
24690 \end_layout
24691
24692 \begin_layout LyX-Code
24693 void isr_shadow(void) shadowregs interrupt 1
24694 \end_layout
24695
24696 \begin_layout LyX-Code
24697 {
24698 \end_layout
24699
24700 \begin_layout LyX-Code
24701 ...
24702 \end_layout
24703
24704 \begin_layout LyX-Code
24705 }
24706 \end_layout
24707
24708 \begin_layout Standard
24709
24710 \emph on
24711 shadowregs
24712 \emph default
24713  instructs the code generator not to store/restore WREG, STATUS, BSR when
24714  entering/exiting the ISR.
24715 \end_layout
24716
24717 \begin_layout Subsection
24718 Function return values
24719 \end_layout
24720
24721 \begin_layout Standard
24722 Return values from functions are placed to the appropriate registers following
24723  a modified Microchip policy optimized for SDCC.
24724  The following table shows these registers:
24725 \end_layout
24726
24727 \begin_layout Standard
24728 \align center
24729 \begin_inset Tabular
24730 <lyxtabular version="3" rows="6" columns="2">
24731 <features>
24732 <column alignment="center" valignment="top" leftline="true" width="0">
24733 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24734 <row topline="true" bottomline="true">
24735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24736 \begin_inset Text
24737
24738 \begin_layout Standard
24739 size
24740 \end_layout
24741
24742 \end_inset
24743 </cell>
24744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24745 \begin_inset Text
24746
24747 \begin_layout Standard
24748 destination register
24749 \end_layout
24750
24751 \end_inset
24752 </cell>
24753 </row>
24754 <row topline="true">
24755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24756 \begin_inset Text
24757
24758 \begin_layout Standard
24759 8 bits
24760 \end_layout
24761
24762 \end_inset
24763 </cell>
24764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24765 \begin_inset Text
24766
24767 \begin_layout Standard
24768 WREG
24769 \end_layout
24770
24771 \end_inset
24772 </cell>
24773 </row>
24774 <row topline="true">
24775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24776 \begin_inset Text
24777
24778 \begin_layout Standard
24779 16 bits
24780 \end_layout
24781
24782 \end_inset
24783 </cell>
24784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24785 \begin_inset Text
24786
24787 \begin_layout Standard
24788 PRODL:WREG
24789 \end_layout
24790
24791 \end_inset
24792 </cell>
24793 </row>
24794 <row topline="true">
24795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24796 \begin_inset Text
24797
24798 \begin_layout Standard
24799 24 bits
24800 \end_layout
24801
24802 \end_inset
24803 </cell>
24804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24805 \begin_inset Text
24806
24807 \begin_layout Standard
24808 PRODH:PRODL:WREG
24809 \end_layout
24810
24811 \end_inset
24812 </cell>
24813 </row>
24814 <row topline="true">
24815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24816 \begin_inset Text
24817
24818 \begin_layout Standard
24819 32 bits
24820 \end_layout
24821
24822 \end_inset
24823 </cell>
24824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24825 \begin_inset Text
24826
24827 \begin_layout Standard
24828 FSR0L:PRODH:PRODL:WREG
24829 \end_layout
24830
24831 \end_inset
24832 </cell>
24833 </row>
24834 <row topline="true" bottomline="true">
24835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24836 \begin_inset Text
24837
24838 \begin_layout Standard
24839 >32 bits
24840 \end_layout
24841
24842 \end_inset
24843 </cell>
24844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24845 \begin_inset Text
24846
24847 \begin_layout Standard
24848 on stack, FSR0 points to the beginning
24849 \end_layout
24850
24851 \end_inset
24852 </cell>
24853 </row>
24854 </lyxtabular>
24855
24856 \end_inset
24857
24858
24859 \end_layout
24860
24861 \begin_layout Subsection
24862 Interrupts
24863 \end_layout
24864
24865 \begin_layout Standard
24866 An interrupt
24867 \begin_inset LatexCommand \index{PIC16!interrupt}
24868
24869 \end_inset
24870
24871  service routine (ISR) is declared using the 
24872 \emph on
24873 interrupt
24874 \emph default
24875  keyword.
24876 \end_layout
24877
24878 \begin_layout LyX-Code
24879 void isr(void) interrupt 
24880 \emph on
24881 n
24882 \end_layout
24883
24884 \begin_layout LyX-Code
24885 {
24886 \end_layout
24887
24888 \begin_layout LyX-Code
24889 ...
24890 \end_layout
24891
24892 \begin_layout LyX-Code
24893 }
24894 \end_layout
24895
24896 \begin_layout Standard
24897
24898 \emph on
24899 n
24900 \emph default
24901  is the interrupt number, which for PIC18F devices can be:
24902 \end_layout
24903
24904 \begin_layout Standard
24905 \align center
24906 \begin_inset Tabular
24907 <lyxtabular version="3" rows="4" columns="3">
24908 <features>
24909 <column alignment="center" valignment="top" leftline="true" width="0">
24910 <column alignment="center" valignment="top" leftline="true" width="0">
24911 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24912 <row topline="true" bottomline="true">
24913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24914 \begin_inset Text
24915
24916 \begin_layout Standard
24917
24918 \emph on
24919 n
24920 \end_layout
24921
24922 \end_inset
24923 </cell>
24924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24925 \begin_inset Text
24926
24927 \begin_layout Standard
24928 Interrupt Vector
24929 \end_layout
24930
24931 \end_inset
24932 </cell>
24933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24934 \begin_inset Text
24935
24936 \begin_layout Standard
24937 Interrupt Vector Address
24938 \end_layout
24939
24940 \end_inset
24941 </cell>
24942 </row>
24943 <row topline="true">
24944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24945 \begin_inset Text
24946
24947 \begin_layout Standard
24948 0
24949 \end_layout
24950
24951 \end_inset
24952 </cell>
24953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24954 \begin_inset Text
24955
24956 \begin_layout Standard
24957 RESET vector
24958 \end_layout
24959
24960 \end_inset
24961 </cell>
24962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24963 \begin_inset Text
24964
24965 \begin_layout Standard
24966 0x000000
24967 \end_layout
24968
24969 \end_inset
24970 </cell>
24971 </row>
24972 <row topline="true">
24973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24974 \begin_inset Text
24975
24976 \begin_layout Standard
24977
24978 \family roman
24979 \series medium
24980 \shape up
24981 \size normal
24982 \emph off
24983 \bar no
24984 \noun off
24985 \color none
24986 1
24987 \end_layout
24988
24989 \end_inset
24990 </cell>
24991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24992 \begin_inset Text
24993
24994 \begin_layout Standard
24995
24996 \family roman
24997 \series medium
24998 \shape up
24999 \size normal
25000 \emph off
25001 \bar no
25002 \noun off
25003 \color none
25004 HIGH priority interrupts
25005 \end_layout
25006
25007 \end_inset
25008 </cell>
25009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25010 \begin_inset Text
25011
25012 \begin_layout Standard
25013 0x000008
25014 \end_layout
25015
25016 \end_inset
25017 </cell>
25018 </row>
25019 <row topline="true" bottomline="true">
25020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25021 \begin_inset Text
25022
25023 \begin_layout Standard
25024 2
25025 \end_layout
25026
25027 \end_inset
25028 </cell>
25029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25030 \begin_inset Text
25031
25032 \begin_layout Standard
25033 LOW priority interrupts
25034 \end_layout
25035
25036 \end_inset
25037 </cell>
25038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25039 \begin_inset Text
25040
25041 \begin_layout Standard
25042 0x000018
25043 \end_layout
25044
25045 \end_inset
25046 </cell>
25047 </row>
25048 </lyxtabular>
25049
25050 \end_inset
25051
25052
25053 \end_layout
25054
25055 \begin_layout Standard
25056 When generating assembly code for ISR the code generator places a 
25057 \noun on
25058 goto 
25059 \noun default
25060 instruction at the 
25061 \emph on
25062 Interrupt Vector Address
25063 \emph default
25064  which points at the genetated ISR.
25065  This single GOTO instruction is part of an automatically generated 
25066 \emph on
25067 interrupt entry point
25068 \emph default
25069  function.
25070  The actuall ISR code is placed as normally would in the code space.
25071  Upon interrupt request, the GOTO instruction is executed which jumps to
25072  the ISR code.
25073  When declaring interrupt functions as _naked this GOTO instruction is 
25074 \series bold
25075 not
25076 \series default
25077  generated.
25078  The whole interrupt functions is therefore placed at the Interrupt Vector
25079  Address of the specific interrupt.
25080  This is not a problem for the LOW priority interrupts, but it is a problem
25081  for the RESET and the HIGH priority interrupts because code may be written
25082  at the next interrupt´s vector address and cause undeterminate program
25083  behaviour if that interrupt is raised.
25084 \begin_inset Foot
25085 status open
25086
25087 \begin_layout Standard
25088 This is not a problem when
25089 \end_layout
25090
25091 \begin_layout Enumerate
25092 this is a HIGH interrupt ISR and LOW interrupts are 
25093 \emph on
25094 disabled
25095 \emph default
25096  or not used.
25097 \end_layout
25098
25099 \begin_layout Enumerate
25100 when the ISR is small enough not to reach the next interrupt´s vector address.
25101 \end_layout
25102
25103 \end_inset
25104
25105
25106 \end_layout
25107
25108 \begin_layout Standard
25109
25110 \emph on
25111 n
25112 \emph default
25113  is possible to be omitted.
25114  This way a function is generated similar to an ISR, but it is not assigned
25115  to any interrupt.
25116 \end_layout
25117
25118 \begin_layout Standard
25119 When entering an interrupt, currently the PIC16
25120 \begin_inset LatexCommand \index{PIC16}
25121
25122 \end_inset
25123
25124  port automatically saves the following registers:
25125 \end_layout
25126
25127 \begin_layout Itemize
25128 WREG
25129 \end_layout
25130
25131 \begin_layout Itemize
25132 STATUS
25133 \end_layout
25134
25135 \begin_layout Itemize
25136 BSR
25137 \end_layout
25138
25139 \begin_layout Itemize
25140 PROD (PRODL and PRODH)
25141 \end_layout
25142
25143 \begin_layout Itemize
25144 FSR0 (FSR0L and FSR0H)
25145 \end_layout
25146
25147 \begin_layout Standard
25148 These registers are restored upon return from the interrupt routine.
25149 \begin_inset Foot
25150 status open
25151
25152 \begin_layout Standard
25153 NOTE that when the _naked attribute is specified for an interrupt routine,
25154  then NO registers are stored or restored.
25155 \end_layout
25156
25157 \end_inset
25158
25159
25160 \end_layout
25161
25162 \begin_layout Subsection
25163 Generic Pointers
25164 \end_layout
25165
25166 \begin_layout Standard
25167 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25168  There are 3 types of generic pointers currently implemented data, code
25169  and eeprom pointers.
25170  They are differentiated by the value of the 7th and 6th bits of the upper
25171  byte:
25172 \end_layout
25173
25174 \begin_layout Standard
25175 \align center
25176 \begin_inset Tabular
25177 <lyxtabular version="3" rows="5" columns="5">
25178 <features>
25179 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25180 <column alignment="center" valignment="top" width="0">
25181 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25182 <column alignment="center" valignment="top" width="0">
25183 <column alignment="left" valignment="top" rightline="true" width="0">
25184 <row topline="true" bottomline="true">
25185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25186 \begin_inset Text
25187
25188 \begin_layout Standard
25189 pointer type
25190 \end_layout
25191
25192 \end_inset
25193 </cell>
25194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25195 \begin_inset Text
25196
25197 \begin_layout Standard
25198 7th bit
25199 \end_layout
25200
25201 \end_inset
25202 </cell>
25203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25204 \begin_inset Text
25205
25206 \begin_layout Standard
25207 6th bit
25208 \end_layout
25209
25210 \end_inset
25211 </cell>
25212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25213 \begin_inset Text
25214
25215 \begin_layout Standard
25216 rest of the pointer
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 description
25226 \end_layout
25227
25228 \end_inset
25229 </cell>
25230 </row>
25231 <row topline="true" bottomline="true">
25232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25233 \begin_inset Text
25234
25235 \begin_layout Standard
25236 data 
25237 \end_layout
25238
25239 \end_inset
25240 </cell>
25241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25242 \begin_inset Text
25243
25244 \begin_layout Standard
25245 1
25246 \end_layout
25247
25248 \end_inset
25249 </cell>
25250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25251 \begin_inset Text
25252
25253 \begin_layout Standard
25254 0
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
25264 \family typewriter
25265 \shape slanted
25266 \emph on
25267 uuuuuu uuuuxxxx xxxxxxxx
25268 \end_layout
25269
25270 \end_inset
25271 </cell>
25272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25273 \begin_inset Text
25274
25275 \begin_layout Standard
25276 a 12-bit data pointer in data RAM memory
25277 \end_layout
25278
25279 \end_inset
25280 </cell>
25281 </row>
25282 <row bottomline="true">
25283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25284 \begin_inset Text
25285
25286 \begin_layout Standard
25287 code
25288 \end_layout
25289
25290 \end_inset
25291 </cell>
25292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25293 \begin_inset Text
25294
25295 \begin_layout Standard
25296 0
25297 \end_layout
25298
25299 \end_inset
25300 </cell>
25301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25302 \begin_inset Text
25303
25304 \begin_layout Standard
25305 0
25306 \end_layout
25307
25308 \end_inset
25309 </cell>
25310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25311 \begin_inset Text
25312
25313 \begin_layout Standard
25314
25315 \family typewriter
25316 \shape slanted
25317 \emph on
25318 uxxxxx xxxxxxxx xxxxxxxx
25319 \end_layout
25320
25321 \end_inset
25322 </cell>
25323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25324 \begin_inset Text
25325
25326 \begin_layout Standard
25327 a 21-bit code pointer in FLASH memory
25328 \end_layout
25329
25330 \end_inset
25331 </cell>
25332 </row>
25333 <row bottomline="true">
25334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25335 \begin_inset Text
25336
25337 \begin_layout Standard
25338 eeprom
25339 \end_layout
25340
25341 \end_inset
25342 </cell>
25343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25344 \begin_inset Text
25345
25346 \begin_layout Standard
25347 0
25348 \end_layout
25349
25350 \end_inset
25351 </cell>
25352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25353 \begin_inset Text
25354
25355 \begin_layout Standard
25356 1
25357 \end_layout
25358
25359 \end_inset
25360 </cell>
25361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25362 \begin_inset Text
25363
25364 \begin_layout Standard
25365
25366 \family typewriter
25367 \shape slanted
25368 \emph on
25369 uuuuuu uuuuuuxx xxxxxxxx
25370 \end_layout
25371
25372 \end_inset
25373 </cell>
25374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25375 \begin_inset Text
25376
25377 \begin_layout Standard
25378 a 10-bit eeprom pointer in EEPROM memory
25379 \end_layout
25380
25381 \end_inset
25382 </cell>
25383 </row>
25384 <row bottomline="true">
25385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25386 \begin_inset Text
25387
25388 \begin_layout Standard
25389 (unimplemented)
25390 \end_layout
25391
25392 \end_inset
25393 </cell>
25394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25395 \begin_inset Text
25396
25397 \begin_layout Standard
25398 1
25399 \end_layout
25400
25401 \end_inset
25402 </cell>
25403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25404 \begin_inset Text
25405
25406 \begin_layout Standard
25407 1
25408 \end_layout
25409
25410 \end_inset
25411 </cell>
25412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25413 \begin_inset Text
25414
25415 \begin_layout Standard
25416
25417 \family typewriter
25418 \shape slanted
25419 \emph on
25420 xxxxxx xxxxxxxx xxxxxxxx
25421 \end_layout
25422
25423 \end_inset
25424 </cell>
25425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25426 \begin_inset Text
25427
25428 \begin_layout Standard
25429 unimplemented pointer type
25430 \end_layout
25431
25432 \end_inset
25433 </cell>
25434 </row>
25435 </lyxtabular>
25436
25437 \end_inset
25438
25439
25440 \end_layout
25441
25442 \begin_layout Standard
25443 Generic pointer are read and written with a set of library functions which
25444  read/write 1, 2, 3, 4 bytes.
25445 \end_layout
25446
25447 \begin_layout Subsection
25448 PIC16 C Libraries
25449 \end_layout
25450
25451 \begin_layout Subsubsection
25452 Standard I/O Streams
25453 \end_layout
25454
25455 \begin_layout Standard
25456 In the 
25457 \emph on
25458 stdio.h
25459 \emph default
25460  the type FILE is defined as:
25461 \end_layout
25462
25463 \begin_layout LyX-Code
25464 typedef char * FILE;
25465 \end_layout
25466
25467 \begin_layout Standard
25468 This type is the stream type implemented I/O in the PIC18F devices.
25469  Also the standard input and output streams are declared in stdio.h:
25470 \end_layout
25471
25472 \begin_layout LyX-Code
25473 extern FILE * stdin;
25474 \end_layout
25475
25476 \begin_layout LyX-Code
25477 extern FILE * stdout;
25478 \end_layout
25479
25480 \begin_layout Standard
25481 The FILE type is actually a generic pointer which defines one more type
25482  of generic pointers, the 
25483 \emph on
25484 stream 
25485 \emph default
25486 pointer.
25487  This new type has the format:
25488 \end_layout
25489
25490 \begin_layout Standard
25491 \align center
25492 \begin_inset Tabular
25493 <lyxtabular version="3" rows="2" columns="7">
25494 <features>
25495 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25496 <column alignment="center" valignment="top" width="0">
25497 <column alignment="center" valignment="top" leftline="true" width="0">
25498 <column alignment="center" valignment="top" leftline="true" width="0">
25499 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25500 <column alignment="center" valignment="top" width="0">
25501 <column alignment="left" valignment="top" rightline="true" width="0">
25502 <row topline="true" bottomline="true">
25503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25504 \begin_inset Text
25505
25506 \begin_layout Standard
25507 pointer type
25508 \end_layout
25509
25510 \end_inset
25511 </cell>
25512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25513 \begin_inset Text
25514
25515 \begin_layout Standard
25516 <7:6>
25517 \end_layout
25518
25519 \end_inset
25520 </cell>
25521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25522 \begin_inset Text
25523
25524 \begin_layout Standard
25525 <5>
25526 \end_layout
25527
25528 \end_inset
25529 </cell>
25530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25531 \begin_inset Text
25532
25533 \begin_layout Standard
25534 <4>
25535 \end_layout
25536
25537 \end_inset
25538 </cell>
25539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25540 \begin_inset Text
25541
25542 \begin_layout Standard
25543 <3:0>
25544 \end_layout
25545
25546 \end_inset
25547 </cell>
25548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25549 \begin_inset Text
25550
25551 \begin_layout Standard
25552 rest of the pointer
25553 \end_layout
25554
25555 \end_inset
25556 </cell>
25557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25558 \begin_inset Text
25559
25560 \begin_layout Standard
25561 descrption
25562 \end_layout
25563
25564 \end_inset
25565 </cell>
25566 </row>
25567 <row topline="true" bottomline="true">
25568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25569 \begin_inset Text
25570
25571 \begin_layout Standard
25572 stream
25573 \end_layout
25574
25575 \end_inset
25576 </cell>
25577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25578 \begin_inset Text
25579
25580 \begin_layout Standard
25581 00
25582 \end_layout
25583
25584 \end_inset
25585 </cell>
25586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25587 \begin_inset Text
25588
25589 \begin_layout Standard
25590 1
25591 \end_layout
25592
25593 \end_inset
25594 </cell>
25595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25596 \begin_inset Text
25597
25598 \begin_layout Standard
25599 0
25600 \end_layout
25601
25602 \end_inset
25603 </cell>
25604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25605 \begin_inset Text
25606
25607 \begin_layout Standard
25608 nnnn
25609 \end_layout
25610
25611 \end_inset
25612 </cell>
25613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25614 \begin_inset Text
25615
25616 \begin_layout Standard
25617
25618 \family typewriter
25619 \shape slanted
25620 \emph on
25621 uuuuuuuu uuuuuuuu
25622 \end_layout
25623
25624 \end_inset
25625 </cell>
25626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25627 \begin_inset Text
25628
25629 \begin_layout Standard
25630 upper byte high nubble is 0x2n, the rest are zeroes
25631 \end_layout
25632
25633 \end_inset
25634 </cell>
25635 </row>
25636 </lyxtabular>
25637
25638 \end_inset
25639
25640
25641 \end_layout
25642
25643 \begin_layout Standard
25644 Currently implemented there are 3 types of streams defined:
25645 \end_layout
25646
25647 \begin_layout Standard
25648 \align center
25649 \begin_inset Tabular
25650 <lyxtabular version="3" rows="4" columns="4">
25651 <features>
25652 <column alignment="center" valignment="top" leftline="true" width="0">
25653 <column alignment="center" valignment="top" leftline="true" width="0">
25654 <column alignment="center" valignment="top" leftline="true" width="0">
25655 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25656 <row topline="true" bottomline="true">
25657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25658 \begin_inset Text
25659
25660 \begin_layout Standard
25661 stream type
25662 \end_layout
25663
25664 \end_inset
25665 </cell>
25666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25667 \begin_inset Text
25668
25669 \begin_layout Standard
25670 value
25671 \end_layout
25672
25673 \end_inset
25674 </cell>
25675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25676 \begin_inset Text
25677
25678 \begin_layout Standard
25679 module
25680 \end_layout
25681
25682 \end_inset
25683 </cell>
25684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25685 \begin_inset Text
25686
25687 \begin_layout Standard
25688 description
25689 \end_layout
25690
25691 \end_inset
25692 </cell>
25693 </row>
25694 <row topline="true">
25695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25696 \begin_inset Text
25697
25698 \begin_layout Standard
25699 STREAM_USART
25700 \end_layout
25701
25702 \end_inset
25703 </cell>
25704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25705 \begin_inset Text
25706
25707 \begin_layout Standard
25708
25709 \family typewriter
25710 0x200000UL
25711 \end_layout
25712
25713 \end_inset
25714 </cell>
25715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25716 \begin_inset Text
25717
25718 \begin_layout Standard
25719 USART
25720 \end_layout
25721
25722 \end_inset
25723 </cell>
25724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25725 \begin_inset Text
25726
25727 \begin_layout Standard
25728 Writes/Reads characters via the USART peripheral
25729 \end_layout
25730
25731 \end_inset
25732 </cell>
25733 </row>
25734 <row topline="true">
25735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25736 \begin_inset Text
25737
25738 \begin_layout Standard
25739 STREAM_MSSP
25740 \end_layout
25741
25742 \end_inset
25743 </cell>
25744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25745 \begin_inset Text
25746
25747 \begin_layout Standard
25748
25749 \family typewriter
25750 0x210000UL
25751 \end_layout
25752
25753 \end_inset
25754 </cell>
25755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25756 \begin_inset Text
25757
25758 \begin_layout Standard
25759 MSSP
25760 \end_layout
25761
25762 \end_inset
25763 </cell>
25764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25765 \begin_inset Text
25766
25767 \begin_layout Standard
25768 Writes/Reads characters via the MSSP peripheral
25769 \end_layout
25770
25771 \end_inset
25772 </cell>
25773 </row>
25774 <row topline="true" bottomline="true">
25775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25776 \begin_inset Text
25777
25778 \begin_layout Standard
25779 STREAM_USER
25780 \end_layout
25781
25782 \end_inset
25783 </cell>
25784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25785 \begin_inset Text
25786
25787 \begin_layout Standard
25788
25789 \family typewriter
25790 0x2f0000UL
25791 \end_layout
25792
25793 \end_inset
25794 </cell>
25795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25796 \begin_inset Text
25797
25798 \begin_layout Standard
25799 (none)
25800 \end_layout
25801
25802 \end_inset
25803 </cell>
25804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25805 \begin_inset Text
25806
25807 \begin_layout Standard
25808 Writes/Reads characters via used defined functions
25809 \end_layout
25810
25811 \end_inset
25812 </cell>
25813 </row>
25814 </lyxtabular>
25815
25816 \end_inset
25817
25818
25819 \end_layout
25820
25821 \begin_layout Standard
25822 The stream identifiers are declared as macros in the stdio.h header.
25823 \end_layout
25824
25825 \begin_layout Standard
25826 In the libc library there exist the functions that are used to write to
25827  each of the above streams.
25828  These are
25829 \end_layout
25830
25831 \begin_layout List
25832 \labelwidthstring 00.00.0000
25833 _
25834 \begin_inset ERT
25835 status collapsed
25836
25837 \begin_layout Standard
25838
25839
25840 \backslash
25841 /
25842 \end_layout
25843
25844 \end_inset
25845
25846 _stream_usart_putchar writes a character at the USART stream
25847 \end_layout
25848
25849 \begin_layout List
25850 \labelwidthstring 00.00.0000
25851 _
25852 \begin_inset ERT
25853 status collapsed
25854
25855 \begin_layout Standard
25856
25857
25858 \backslash
25859 /
25860 \end_layout
25861
25862 \end_inset
25863
25864 _stream_mssp_putchar writes a character at the MSSP stream
25865 \end_layout
25866
25867 \begin_layout List
25868 \labelwidthstring 00.00.0000
25869 putchar dummy function.
25870  This writes a character to a user specified manner.
25871 \end_layout
25872
25873 \begin_layout Standard
25874 In order to increase performance 
25875 \emph on
25876 putchar 
25877 \emph default
25878 is declared in stdio.h as having its parameter in WREG (it has the wparam
25879  keyword).
25880  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
25881  in a user-friendly way.
25882  
25883 \emph on
25884 arg
25885 \emph default
25886  is the name of the variable that holds the character to print.
25887  An example follows:
25888 \end_layout
25889
25890 \begin_layout LyX-Code
25891 #include <pic18fregs.h>
25892 \newline
25893 #include <stdio.h>
25894 \newline
25895
25896 \newline
25897 PUTCHAR( c )
25898 \end_layout
25899
25900 \begin_layout LyX-Code
25901 {
25902 \end_layout
25903
25904 \begin_layout LyX-Code
25905     PORTA = c;    /* dump character c to PORTA */
25906 \end_layout
25907
25908 \begin_layout LyX-Code
25909
25910 \newline
25911
25912 \newline
25913 void main(void)
25914 \end_layout
25915
25916 \begin_layout LyX-Code
25917 {
25918 \end_layout
25919
25920 \begin_layout LyX-Code
25921     stdout = STREAM_USER;    /* this is not necessary, since stdout points
25922 \end_layout
25923
25924 \begin_layout LyX-Code
25925                               * by default to STREAM_USER */
25926 \end_layout
25927
25928 \begin_layout LyX-Code
25929     printf (¨This is a printf test
25930 \backslash
25931 n¨);
25932 \end_layout
25933
25934 \begin_layout LyX-Code
25935 }
25936 \end_layout
25937
25938 \begin_layout LyX-Code
25939
25940 \end_layout
25941
25942 \begin_layout Subsubsection
25943 Printing functions
25944 \end_layout
25945
25946 \begin_layout Standard
25947 PIC16 contains an implementation of the printf-family of functions.
25948  There exist the following functions:
25949 \end_layout
25950
25951 \begin_layout LyX-Code
25952 extern unsigned int sprintf(char *buf, char *fmt, ...);
25953 \end_layout
25954
25955 \begin_layout LyX-Code
25956 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
25957 \end_layout
25958
25959 \begin_layout LyX-Code
25960
25961 \end_layout
25962
25963 \begin_layout LyX-Code
25964 extern unsigned int printf(char *fmt, ...);
25965 \end_layout
25966
25967 \begin_layout LyX-Code
25968 extern unsigned int vprintf(char *fmt, va_lista ap);
25969 \end_layout
25970
25971 \begin_layout LyX-Code
25972
25973 \end_layout
25974
25975 \begin_layout LyX-Code
25976 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
25977 \end_layout
25978
25979 \begin_layout LyX-Code
25980 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
25981 \end_layout
25982
25983 \begin_layout Standard
25984 For sprintf and vsprintf 
25985 \emph on
25986 buf 
25987 \emph default
25988 should normally be a data pointer where the resulting string will be placed.
25989  No range checking is done so the user should allocate the necessery buffer.
25990  For fprintf and vfprintf 
25991 \emph on
25992 fp
25993 \emph default
25994  should be a stream pointer (i.e.
25995  stdout, STREAM_MSSP, etc...).
25996 \end_layout
25997
25998 \begin_layout Subsubsection
25999 Signals
26000 \end_layout
26001
26002 \begin_layout Standard
26003 The PIC18F family of microcontrollers supports a number of interrupt sources.
26004  A list of these interrupts is shown in the following table:
26005 \end_layout
26006
26007 \begin_layout Standard
26008 \align center
26009 \begin_inset Tabular
26010 <lyxtabular version="3" rows="11" columns="4">
26011 <features>
26012 <column alignment="left" valignment="top" leftline="true" width="0">
26013 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26014 <column alignment="left" valignment="top" leftline="true" width="0">
26015 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26016 <row topline="true" bottomline="true">
26017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26018 \begin_inset Text
26019
26020 \begin_layout Standard
26021 signal name
26022 \end_layout
26023
26024 \end_inset
26025 </cell>
26026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26027 \begin_inset Text
26028
26029 \begin_layout Standard
26030 description
26031 \end_layout
26032
26033 \end_inset
26034 </cell>
26035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26036 \begin_inset Text
26037
26038 \begin_layout Standard
26039 signal name
26040 \end_layout
26041
26042 \end_inset
26043 </cell>
26044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26045 \begin_inset Text
26046
26047 \begin_layout Standard
26048 descritpion
26049 \end_layout
26050
26051 \end_inset
26052 </cell>
26053 </row>
26054 <row topline="true">
26055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26056 \begin_inset Text
26057
26058 \begin_layout Standard
26059 SIG_RB
26060 \end_layout
26061
26062 \end_inset
26063 </cell>
26064 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26065 \begin_inset Text
26066
26067 \begin_layout Standard
26068 PORTB change interrupt
26069 \end_layout
26070
26071 \end_inset
26072 </cell>
26073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26074 \begin_inset Text
26075
26076 \begin_layout Standard
26077 SIG_EE
26078 \end_layout
26079
26080 \end_inset
26081 </cell>
26082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26083 \begin_inset Text
26084
26085 \begin_layout Standard
26086 EEPROM/FLASH write complete interrupt
26087 \end_layout
26088
26089 \end_inset
26090 </cell>
26091 </row>
26092 <row topline="true">
26093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26094 \begin_inset Text
26095
26096 \begin_layout Standard
26097 SIG_INT0
26098 \end_layout
26099
26100 \end_inset
26101 </cell>
26102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26103 \begin_inset Text
26104
26105 \begin_layout Standard
26106 INT0 external interrupt
26107 \end_layout
26108
26109 \end_inset
26110 </cell>
26111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26112 \begin_inset Text
26113
26114 \begin_layout Standard
26115 SIG_BCOL
26116 \end_layout
26117
26118 \end_inset
26119 </cell>
26120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26121 \begin_inset Text
26122
26123 \begin_layout Standard
26124 Bus collision interrupt
26125 \end_layout
26126
26127 \end_inset
26128 </cell>
26129 </row>
26130 <row topline="true">
26131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26132 \begin_inset Text
26133
26134 \begin_layout Standard
26135 SIG_INT1
26136 \end_layout
26137
26138 \end_inset
26139 </cell>
26140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26141 \begin_inset Text
26142
26143 \begin_layout Standard
26144 INT1 external interrupt
26145 \end_layout
26146
26147 \end_inset
26148 </cell>
26149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26150 \begin_inset Text
26151
26152 \begin_layout Standard
26153 SIG_LVD
26154 \end_layout
26155
26156 \end_inset
26157 </cell>
26158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26159 \begin_inset Text
26160
26161 \begin_layout Standard
26162 Low voltage detect interrupt
26163 \end_layout
26164
26165 \end_inset
26166 </cell>
26167 </row>
26168 <row topline="true">
26169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26170 \begin_inset Text
26171
26172 \begin_layout Standard
26173 SIG_INT2
26174 \end_layout
26175
26176 \end_inset
26177 </cell>
26178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26179 \begin_inset Text
26180
26181 \begin_layout Standard
26182 INT2 external interrupt
26183 \end_layout
26184
26185 \end_inset
26186 </cell>
26187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26188 \begin_inset Text
26189
26190 \begin_layout Standard
26191 SIG_PSP
26192 \end_layout
26193
26194 \end_inset
26195 </cell>
26196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26197 \begin_inset Text
26198
26199 \begin_layout Standard
26200 Parallel slave port interrupt
26201 \end_layout
26202
26203 \end_inset
26204 </cell>
26205 </row>
26206 <row topline="true">
26207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26208 \begin_inset Text
26209
26210 \begin_layout Standard
26211 SIG_CCP1
26212 \end_layout
26213
26214 \end_inset
26215 </cell>
26216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26217 \begin_inset Text
26218
26219 \begin_layout Standard
26220 CCP1 module interrupt
26221 \end_layout
26222
26223 \end_inset
26224 </cell>
26225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26226 \begin_inset Text
26227
26228 \begin_layout Standard
26229 SIG_AD
26230 \end_layout
26231
26232 \end_inset
26233 </cell>
26234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26235 \begin_inset Text
26236
26237 \begin_layout Standard
26238 AD convertion complete interrupt
26239 \end_layout
26240
26241 \end_inset
26242 </cell>
26243 </row>
26244 <row topline="true">
26245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26246 \begin_inset Text
26247
26248 \begin_layout Standard
26249 SIG_CCP2
26250 \end_layout
26251
26252 \end_inset
26253 </cell>
26254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26255 \begin_inset Text
26256
26257 \begin_layout Standard
26258 CCP2 module interrupt
26259 \end_layout
26260
26261 \end_inset
26262 </cell>
26263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26264 \begin_inset Text
26265
26266 \begin_layout Standard
26267 SIG_RC
26268 \end_layout
26269
26270 \end_inset
26271 </cell>
26272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26273 \begin_inset Text
26274
26275 \begin_layout Standard
26276 USART receive interrupt
26277 \end_layout
26278
26279 \end_inset
26280 </cell>
26281 </row>
26282 <row topline="true">
26283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26284 \begin_inset Text
26285
26286 \begin_layout Standard
26287 SIG_TMR0
26288 \end_layout
26289
26290 \end_inset
26291 </cell>
26292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26293 \begin_inset Text
26294
26295 \begin_layout Standard
26296 TMR0 overflow interrupt
26297 \end_layout
26298
26299 \end_inset
26300 </cell>
26301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26302 \begin_inset Text
26303
26304 \begin_layout Standard
26305 SIG_TX
26306 \end_layout
26307
26308 \end_inset
26309 </cell>
26310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26311 \begin_inset Text
26312
26313 \begin_layout Standard
26314 USART transmit interrupt
26315 \end_layout
26316
26317 \end_inset
26318 </cell>
26319 </row>
26320 <row topline="true">
26321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26322 \begin_inset Text
26323
26324 \begin_layout Standard
26325 SIG_TMR1
26326 \end_layout
26327
26328 \end_inset
26329 </cell>
26330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26331 \begin_inset Text
26332
26333 \begin_layout Standard
26334 TMR1 overflow interrupt
26335 \end_layout
26336
26337 \end_inset
26338 </cell>
26339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26340 \begin_inset Text
26341
26342 \begin_layout Standard
26343 SIG_MSSP
26344 \end_layout
26345
26346 \end_inset
26347 </cell>
26348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26349 \begin_inset Text
26350
26351 \begin_layout Standard
26352 SSP receive/transmit interrupt
26353 \end_layout
26354
26355 \end_inset
26356 </cell>
26357 </row>
26358 <row topline="true">
26359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26360 \begin_inset Text
26361
26362 \begin_layout Standard
26363 SIG_TMR2
26364 \end_layout
26365
26366 \end_inset
26367 </cell>
26368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26369 \begin_inset Text
26370
26371 \begin_layout Standard
26372 TMR2 matches PR2 interrupt
26373 \end_layout
26374
26375 \end_inset
26376 </cell>
26377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26378 \begin_inset Text
26379
26380 \begin_layout Standard
26381
26382 \end_layout
26383
26384 \end_inset
26385 </cell>
26386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26387 \begin_inset Text
26388
26389 \begin_layout Standard
26390
26391 \end_layout
26392
26393 \end_inset
26394 </cell>
26395 </row>
26396 <row topline="true" bottomline="true">
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26398 \begin_inset Text
26399
26400 \begin_layout Standard
26401 SIG_TMR3
26402 \end_layout
26403
26404 \end_inset
26405 </cell>
26406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26407 \begin_inset Text
26408
26409 \begin_layout Standard
26410 TMR3 overflow interrupt
26411 \end_layout
26412
26413 \end_inset
26414 </cell>
26415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26416 \begin_inset Text
26417
26418 \begin_layout Standard
26419
26420 \end_layout
26421
26422 \end_inset
26423 </cell>
26424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26425 \begin_inset Text
26426
26427 \begin_layout Standard
26428
26429 \end_layout
26430
26431 \end_inset
26432 </cell>
26433 </row>
26434 </lyxtabular>
26435
26436 \end_inset
26437
26438
26439 \end_layout
26440
26441 \begin_layout Standard
26442 The prototypes for these names are defined in the header file 
26443 \emph on
26444 signal.h
26445 \emph default
26446  .
26447 \end_layout
26448
26449 \begin_layout Standard
26450 In order to simplify signal handling, a number of macros is provided:
26451 \end_layout
26452
26453 \begin_layout List
26454 \labelwidthstring 00.00.0000
26455 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
26456  high priority interrupts.
26457  
26458 \emph on
26459 name
26460 \emph default
26461  is the function name to use.
26462 \end_layout
26463
26464 \begin_layout List
26465 \labelwidthstring 00.00.0000
26466 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
26467  low priority interrupt.
26468  
26469 \emph on
26470 name
26471 \emph default
26472  is the function name to use.
26473 \end_layout
26474
26475 \begin_layout List
26476 \labelwidthstring 00.00.0000
26477 DEF_HANDLER(sig,handler) define a handler for signal 
26478 \emph on
26479 sig.
26480 \end_layout
26481
26482 \begin_layout List
26483 \labelwidthstring 00.00.0000
26484 END_DEF end the declaration of the dispatch table.
26485 \end_layout
26486
26487 \begin_layout Standard
26488 Additionally there are two more macros to simplify the declaration of the
26489  signal handler:
26490 \end_layout
26491
26492 \begin_layout List
26493 \labelwidthstring 00.00.0000
26494
26495 \series medium
26496 SIGHANDLER(handler) 
26497 \series default
26498 this declares the function prototype for the 
26499 \emph on
26500 handler
26501 \emph default
26502  function.
26503 \end_layout
26504
26505 \begin_layout List
26506 \labelwidthstring 00.00.0000
26507 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
26508 \end_layout
26509
26510 \begin_layout Standard
26511 An example of using the macros above is shown below:
26512 \end_layout
26513
26514 \begin_layout LyX-Code
26515 #include <pic18fregs.h>
26516 \end_layout
26517
26518 \begin_layout LyX-Code
26519 #include <signal.h>
26520 \newline
26521
26522 \newline
26523 DEF_INTHIGH(high_int)
26524 \end_layout
26525
26526 \begin_layout LyX-Code
26527 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
26528 \end_layout
26529
26530 \begin_layout LyX-Code
26531 DEF_HANDLER(SIG_BCOL, _bcol_handler)
26532 \end_layout
26533
26534 \begin_layout LyX-Code
26535 END_DEF
26536 \newline
26537
26538 \newline
26539 SIGHANDLER(_tmr0_handler)
26540 \end_layout
26541
26542 \begin_layout LyX-Code
26543 {
26544 \end_layout
26545
26546 \begin_layout LyX-Code
26547   /* action to be taken when timer 0 overflows */
26548 \end_layout
26549
26550 \begin_layout LyX-Code
26551 }
26552 \newline
26553
26554 \newline
26555 SIGHANDLERNAKED(_bcol_handler)
26556 \end_layout
26557
26558 \begin_layout LyX-Code
26559 {
26560 \end_layout
26561
26562 \begin_layout LyX-Code
26563   _asm
26564 \end_layout
26565
26566 \begin_layout LyX-Code
26567     /* action to be taken when bus collision occurs */
26568 \end_layout
26569
26570 \begin_layout LyX-Code
26571     retfie
26572 \end_layout
26573
26574 \begin_layout LyX-Code
26575  _endasm;
26576 \end_layout
26577
26578 \begin_layout LyX-Code
26579 }
26580 \end_layout
26581
26582 \begin_layout Standard
26583
26584 \series bold
26585 NOTES:
26586 \series default
26587  Special care should be taken when using the above scheme:
26588 \end_layout
26589
26590 \begin_layout Itemize
26591 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
26592 \end_layout
26593
26594 \begin_layout Itemize
26595 when declaring SIGHANDLERNAKED handler never forget to use 
26596 \emph on
26597 retfie
26598 \emph default
26599  for proper returning.
26600 \end_layout
26601
26602 \begin_layout Subsection
26603 PIC16 Port -- Tips
26604 \end_layout
26605
26606 \begin_layout Standard
26607 Here you can find some general tips for compiling programs with SDCC/pic16.
26608 \end_layout
26609
26610 \begin_layout Subsubsection
26611 Stack size
26612 \end_layout
26613
26614 \begin_layout Standard
26615 The default stack
26616 \begin_inset LatexCommand \index{PIC16!stack}
26617
26618 \end_inset
26619
26620  size (that is 64 bytes) probably is enough for many programs.
26621  One must take care that when there are many levels of function nesting,
26622  or there is excessive usage of stack, its size should be extended.
26623  An example of such a case is the printf/sprintf family of functions.
26624  If you encounter problems like not being able to print integers, then you
26625  need to set the stack size around the maximum (256 for small stack model).
26626  The following diagram shows what happens when calling printf to print an
26627  integer:
26628 \end_layout
26629
26630 \begin_layout LyX-Code
26631 printf () --> ltoa () --> ultoa () --> divschar ()
26632 \end_layout
26633
26634 \begin_layout Standard
26635 It is should be understood that stack is easily consumed when calling complicate
26636 d functions.
26637  Using command line arguments like -
26638 \begin_inset ERT
26639 status collapsed
26640
26641 \begin_layout Standard
26642
26643
26644 \backslash
26645 /
26646 \end_layout
26647
26648 \end_inset
26649
26650 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
26651  stack frames.
26652  Other ways to reduce stack usage may exist.
26653 \end_layout
26654
26655 \begin_layout Subsection
26656 Known bugs
26657 \end_layout
26658
26659 \begin_layout Standard
26660 The PIC16 Port currently does not pass SDCC's regression test
26661 \begin_inset LatexCommand \index{Regression test (PIC16)}
26662
26663 \end_inset
26664
26665  suite (see section 
26666 \begin_inset LatexCommand \ref{sec:Quality-control}
26667
26668 \end_inset
26669
26670 ) and thus the snapshot build regression tests for the PIC16 target are
26671  currently disabled for all hosts
26672 \emph on
26673 .
26674 \end_layout
26675
26676 \begin_layout Chapter
26677 Debugging
26678 \end_layout
26679
26680 \begin_layout Standard
26681 There are several approaches to debugging your code.
26682  This chapter is meant to show your options and to give detail on some of
26683  them:
26684 \newline
26685
26686 \newline
26687 When writing your code:
26688 \end_layout
26689
26690 \begin_layout Itemize
26691 write your code with debugging in mind (avoid duplicating code, put conceptually
26692  similar variables into structs, use structured code, have strategic points
26693  within your code where all variables are consistent, ...)
26694 \end_layout
26695
26696 \begin_layout Itemize
26697 run a syntax-checking tool like splint
26698 \begin_inset LatexCommand \index{splint (syntax checking tool)}
26699
26700 \end_inset
26701
26702
26703 \begin_inset LatexCommand \index{lint (syntax checking tool)}
26704
26705 \end_inset
26706
26707  (see -
26708 \begin_inset ERT
26709 status collapsed
26710
26711 \begin_layout Standard
26712
26713
26714 \backslash
26715 /
26716 \end_layout
26717
26718 \end_inset
26719
26720 -more-pedantic 
26721 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
26722
26723 \end_inset
26724
26725 ) over the code.
26726 \end_layout
26727
26728 \begin_layout Itemize
26729 for the high level code use a C-compiler (like f.e.
26730  GCC) to compile run and debug the code on your host.
26731  See (see -
26732 \begin_inset ERT
26733 status collapsed
26734
26735 \begin_layout Standard
26736
26737
26738 \backslash
26739 /
26740 \end_layout
26741
26742 \end_inset
26743
26744 -more-pedantic 
26745 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
26746
26747 \end_inset
26748
26749  ) on howto handle syntax extensions like __xdata, __at(), ...
26750  
26751 \end_layout
26752
26753 \begin_layout Itemize
26754 use another C-compiler to compile code for your target.
26755  Always an option but not recommended:) And not very likely to help you.
26756  If you seriously consider walking this path you should at least occasionally
26757  check portability of your code.
26758  Most commercial compiler vendors will offer an evaluation version so you
26759  can test compile your code or snippets of your code.
26760 \end_layout
26761
26762 \begin_layout Standard
26763 Debugging on a simulator:
26764 \end_layout
26765
26766 \begin_layout Itemize
26767 there is a separate section about SDCDB (section 
26768 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
26769
26770 \end_inset
26771
26772 ) below.
26773 \end_layout
26774
26775 \begin_layout Itemize
26776 or (8051 specific) use a freeware/commercial simulator which interfaces
26777  to the AOMF
26778 \begin_inset LatexCommand \index{AOMF, AOMF51}
26779
26780 \end_inset
26781
26782  file (see 
26783 \begin_inset LatexCommand \ref{OMF file}
26784
26785 \end_inset
26786
26787 ) optionally generated by SDCC.
26788 \end_layout
26789
26790 \begin_layout Standard
26791 Debugging On-target: 
26792 \end_layout
26793
26794 \begin_layout Itemize
26795 use a MCU port pin to serially output debug data to the RS232 port of your
26796  host.
26797  You'll probably want some level shifting device typically involving a MAX232
26798  or similar IC.
26799  If the hardware serial port of the MCU is not available search for 'Software
26800  UART' in your favourite search machine.
26801 \end_layout
26802
26803 \begin_layout Itemize
26804 use an on-target monitor.
26805  In this context a monitor is a small program which usually accepts commands
26806  via a serial line and allows to set program counter, to single step through
26807  a program and read/write memory locations.
26808  For the 8051 good examples of monitors are paulmon and cmon51 (see section
26809  
26810 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
26811
26812 \end_inset
26813
26814 ).
26815 \end_layout
26816
26817 \begin_layout Itemize
26818 toggle MCU port pins at strategic points within your code and use an oscilloscop
26819 e.
26820  A 
26821 \emph on
26822 digital oscilloscope
26823 \emph default
26824
26825 \begin_inset LatexCommand \index{Oscilloscope}
26826
26827 \end_inset
26828
26829  with deep trace memory is really helpful especially if you have to debug
26830  a realtime application.
26831  If you need to monitor more pins than your oscilloscope provides you can
26832  sometimes get away with a small R-2R network.
26833  On a single channel oscilloscope you could f.e.
26834  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
26835 k
26836 \begin_inset Formula $\Omega$
26837 \end_inset
26838
26839  resistor and the other one by a 5\InsetSpace ~
26840 k
26841 \begin_inset Formula $\Omega$
26842 \end_inset
26843
26844  resistor to the oscilloscope probe (check output drive capability of the
26845  pins you want to monitor).
26846  If you need to monitor many more pins a 
26847 \emph on
26848 logic analyzer
26849 \emph default
26850  will be handy.
26851 \end_layout
26852
26853 \begin_layout Itemize
26854 use an ICE (
26855 \emph on
26856 i
26857 \emph default
26858
26859 \emph on
26860 c
26861 \emph default
26862 ircuit 
26863 \emph on
26864 e
26865 \emph default
26866 mulator
26867 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
26868
26869 \end_inset
26870
26871 ).
26872  Usually very expensive.
26873  And very nice to have too.
26874  And usually locks you (for years...) to the devices the ICE can emulate.
26875  
26876 \end_layout
26877
26878 \begin_layout Itemize
26879 use a remote debugger.
26880  In most 8-bit systems the symbol information is not available on the target,
26881  and a complete debugger is too bulky for the target system.
26882  Therefore usually a debugger on the host system connects to an on-target
26883  debugging stub which accepts only primitive commands.
26884  
26885 \newline
26886 Terms to enter into your favourite search engine could be 'remote debugging',
26887  'gdb stub' or 'inferior debugger'.
26888  (is there one?)
26889 \end_layout
26890
26891 \begin_layout Itemize
26892 use an on target hardware debugger.
26893  Some of the more modern MCUs include hardware support for setting break
26894  points and monitoring/changing variables by using dedicated hardware pins.
26895  This facility doesn't require additional code to run on the target and
26896  
26897 \emph on
26898 usually
26899 \emph default
26900  doesn't affect runtime behaviour until a breakpoint is hit.
26901  For the mcs51 most hardware debuggers use the AOMF
26902 \begin_inset LatexCommand \index{AOMF, AOMF51}
26903
26904 \end_inset
26905
26906  file (see 
26907 \begin_inset LatexCommand \ref{OMF file}
26908
26909 \end_inset
26910
26911 ) as input file.
26912  
26913 \end_layout
26914
26915 \begin_layout Standard
26916 Last not least:
26917 \end_layout
26918
26919 \begin_layout Itemize
26920 if you are not familiar with any of the following terms you're likely to
26921  run into problems rather sooner than later: 
26922 \emph on
26923 volatile
26924 \emph default
26925
26926 \emph on
26927 atomic
26928 \emph default
26929
26930 \emph on
26931 memory map
26932 \emph default
26933
26934 \emph on
26935 overlay
26936 \emph default
26937 .
26938  As an embedded programmer you 
26939 \emph on
26940 have
26941 \emph default
26942  to know them so why not look them up 
26943 \emph on
26944 before
26945 \emph default
26946  you have problems?)
26947 \end_layout
26948
26949 \begin_layout Itemize
26950 tell someone else about your problem (actually this is a surprisingly effective
26951  means to hunt down the bug even if the listener is not familiar with your
26952  environment).
26953  As 'failure to communicate' is probably one of the job-induced deformations
26954  of an embedded programmer this is highly encouraged.
26955 \end_layout
26956
26957 \begin_layout Section
26958 Debugging with SDCDB
26959 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
26960
26961 \end_inset
26962
26963
26964 \begin_inset LatexCommand \index{SDCDB (debugger)}
26965
26966 \end_inset
26967
26968  
26969 \end_layout
26970
26971 \begin_layout Standard
26972 SDCC is distributed with a source level debugger
26973 \begin_inset LatexCommand \index{Debugger}
26974
26975 \end_inset
26976
26977 .
26978  The debugger uses a command line interface, the command repertoire of the
26979  debugger has been kept as close to gdb
26980 \begin_inset LatexCommand \index{gdb}
26981
26982 \end_inset
26983
26984  (the GNU debugger) as possible.
26985  The configuration and build process is part of the standard compiler installati
26986 on, which also builds and installs the debugger in the target directory
26987  specified during configuration.
26988  The debugger allows you debug BOTH at the C source and at the ASM source
26989  level.
26990 \end_layout
26991
26992 \begin_layout Subsection
26993 Compiling for Debugging
26994 \end_layout
26995
26996 \begin_layout Standard
26997 The -
26998 \begin_inset ERT
26999 status collapsed
27000
27001 \begin_layout Standard
27002
27003
27004 \backslash
27005 /
27006 \end_layout
27007
27008 \end_inset
27009
27010 -debug
27011 \begin_inset LatexCommand \index{-\/-debug}
27012
27013 \end_inset
27014
27015  option must be specified for all files for which debug information is to
27016  be generated.
27017  The compiler generates a .adb file for each of these files.
27018  The linker creates the .cdb
27019 \begin_inset LatexCommand \index{<file>.cdb}
27020
27021 \end_inset
27022
27023  file from the .adb
27024 \begin_inset LatexCommand \index{<file>.adb}
27025
27026 \end_inset
27027
27028  files and the address information.
27029  This .cdb is used by the debugger.
27030 \end_layout
27031
27032 \begin_layout Subsection
27033 How the Debugger Works
27034 \end_layout
27035
27036 \begin_layout Standard
27037 When the -
27038 \begin_inset ERT
27039 status collapsed
27040
27041 \begin_layout Standard
27042
27043
27044 \backslash
27045 /
27046 \end_layout
27047
27048 \end_inset
27049
27050 -debug option is specified the compiler generates extra symbol information
27051  some of which are put into the assembler source and some are put into the
27052  .adb file.
27053  Then the linker creates the .cdb file from the individual .adb files with
27054  the address information for the symbols.
27055  The debugger reads the symbolic information generated by the compiler &
27056  the address information generated by the linker.
27057  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27058  execution is controlled by the debugger.
27059  When a command is issued for the debugger, it translates it into appropriate
27060  commands for the simulator.
27061  (Currently SDCDM only connects to the simulator but 
27062 \emph on
27063 newcdb
27064 \emph default
27065  at 
27066 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27067
27068 \end_inset
27069
27070  is an effort to connect directly to the hardware.) 
27071 \end_layout
27072
27073 \begin_layout Subsection
27074 Starting the Debugger SDCDB
27075 \end_layout
27076
27077 \begin_layout Standard
27078 The debugger can be started using the following command line.
27079  (Assume the file you are debugging has the file name foo).
27080 \newline
27081
27082 \newline
27083
27084 \family sans
27085 \series bold
27086 sdcdb foo
27087 \newline
27088
27089 \family default
27090 \series default
27091
27092 \newline
27093 The debugger will look for the following files.
27094 \end_layout
27095
27096 \begin_layout Itemize
27097 foo.c - the source file.
27098 \end_layout
27099
27100 \begin_layout Itemize
27101 foo.cdb - the debugger symbol information file.
27102 \end_layout
27103
27104 \begin_layout Itemize
27105 foo.ihx - the Intel hex format
27106 \begin_inset LatexCommand \index{Intel hex format}
27107
27108 \end_inset
27109
27110  object file.
27111 \end_layout
27112
27113 \begin_layout Subsection
27114 SDCDB Command Line Options
27115 \end_layout
27116
27117 \begin_layout Itemize
27118 -
27119 \begin_inset ERT
27120 status collapsed
27121
27122 \begin_layout Standard
27123
27124
27125 \backslash
27126 /
27127 \end_layout
27128
27129 \end_inset
27130
27131 -directory=<source file directory> this option can used to specify the directory
27132  search list.
27133  The debugger will look into the directory list specified for source, cdb
27134  & ihx files.
27135  The items in the directory list must be separated by ':', e.g.
27136  if the source files can be in the directories /home/src1 and /home/src2,
27137  the -
27138 \begin_inset ERT
27139 status collapsed
27140
27141 \begin_layout Standard
27142
27143
27144 \backslash
27145 /
27146 \end_layout
27147
27148 \end_inset
27149
27150 -directory option should be -
27151 \begin_inset ERT
27152 status collapsed
27153
27154 \begin_layout Standard
27155
27156
27157 \backslash
27158 /
27159 \end_layout
27160
27161 \end_inset
27162
27163 -directory=/home/src1:/home/src2.
27164  Note there can be no spaces in the option.
27165  
27166 \end_layout
27167
27168 \begin_layout Itemize
27169 -cd <directory> - change to the <directory>.
27170 \end_layout
27171
27172 \begin_layout Itemize
27173 -fullname - used by GUI front ends.
27174 \end_layout
27175
27176 \begin_layout Itemize
27177 -cpu <cpu-type> - this argument is passed to the simulator please see the
27178  simulator docs for details.
27179 \end_layout
27180
27181 \begin_layout Itemize
27182 -X <Clock frequency > this options is passed to the simulator please see
27183  the simulator docs for details.
27184 \end_layout
27185
27186 \begin_layout Itemize
27187 -s <serial port file> passed to simulator see the simulator docs for details.
27188 \end_layout
27189
27190 \begin_layout Itemize
27191 -S <serial in,out> passed to simulator see the simulator docs for details.
27192 \end_layout
27193
27194 \begin_layout Itemize
27195 -k <port number> passed to simulator see the simulator docs for details.
27196 \end_layout
27197
27198 \begin_layout Subsection
27199 SDCDB Debugger Commands
27200 \end_layout
27201
27202 \begin_layout Standard
27203 As mentioned earlier the command interface for the debugger has been deliberatel
27204 y kept as close the GNU debugger gdb, as possible.
27205  This will help the integration with existing graphical user interfaces
27206  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27207  If you use a graphical user interface for the debugger you can skip this
27208  section.
27209 \end_layout
27210
27211 \begin_layout Subsubsection*
27212 break [line | file:line | function | file:function]
27213 \end_layout
27214
27215 \begin_layout Standard
27216 Set breakpoint at specified line or function:
27217 \newline
27218
27219 \newline
27220
27221 \family sans
27222 \series bold
27223 sdcdb>break 100 
27224 \newline
27225 sdcdb>break foo.c:100
27226 \newline
27227 sdcdb>break funcfoo
27228 \newline
27229 sdcdb>break foo.c:funcfoo
27230 \end_layout
27231
27232 \begin_layout Subsubsection*
27233 clear [line | file:line | function | file:function ]
27234 \end_layout
27235
27236 \begin_layout Standard
27237 Clear breakpoint at specified line or function:
27238 \newline
27239
27240 \newline
27241
27242 \family sans
27243 \series bold
27244 sdcdb>clear 100
27245 \newline
27246 sdcdb>clear foo.c:100
27247 \newline
27248 sdcdb>clear funcfoo
27249 \newline
27250 sdcdb>clear foo.c:funcfoo
27251 \end_layout
27252
27253 \begin_layout Subsubsection*
27254 continue
27255 \end_layout
27256
27257 \begin_layout Standard
27258 Continue program being debugged, after breakpoint.
27259 \end_layout
27260
27261 \begin_layout Subsubsection*
27262 finish
27263 \end_layout
27264
27265 \begin_layout Standard
27266 Execute till the end of the current function.
27267 \end_layout
27268
27269 \begin_layout Subsubsection*
27270 delete [n]
27271 \end_layout
27272
27273 \begin_layout Standard
27274 Delete breakpoint number 'n'.
27275  If used without any option clear ALL user defined break points.
27276 \end_layout
27277
27278 \begin_layout Subsubsection*
27279 info [break | stack | frame | registers ]
27280 \end_layout
27281
27282 \begin_layout Itemize
27283 info break - list all breakpoints
27284 \end_layout
27285
27286 \begin_layout Itemize
27287 info stack - show the function call stack.
27288 \end_layout
27289
27290 \begin_layout Itemize
27291 info frame - show information about the current execution frame.
27292 \end_layout
27293
27294 \begin_layout Itemize
27295 info registers - show content of all registers.
27296 \end_layout
27297
27298 \begin_layout Subsubsection*
27299 step
27300 \end_layout
27301
27302 \begin_layout Standard
27303 Step program until it reaches a different source line.
27304  Note: pressing <return> repeats the last command.
27305 \end_layout
27306
27307 \begin_layout Subsubsection*
27308 next
27309 \end_layout
27310
27311 \begin_layout Standard
27312 Step program, proceeding through subroutine calls.
27313 \end_layout
27314
27315 \begin_layout Subsubsection*
27316 run
27317 \end_layout
27318
27319 \begin_layout Standard
27320 Start debugged program.
27321 \end_layout
27322
27323 \begin_layout Subsubsection*
27324 ptype variable 
27325 \end_layout
27326
27327 \begin_layout Standard
27328 Print type information of the variable.
27329 \end_layout
27330
27331 \begin_layout Subsubsection*
27332 print variable
27333 \end_layout
27334
27335 \begin_layout Standard
27336 print value of variable.
27337 \end_layout
27338
27339 \begin_layout Subsubsection*
27340 file filename
27341 \end_layout
27342
27343 \begin_layout Standard
27344 load the given file name.
27345  Note this is an alternate method of loading file for debugging.
27346 \end_layout
27347
27348 \begin_layout Subsubsection*
27349 frame
27350 \end_layout
27351
27352 \begin_layout Standard
27353 print information about current frame.
27354 \end_layout
27355
27356 \begin_layout Subsubsection*
27357 set srcmode
27358 \end_layout
27359
27360 \begin_layout Standard
27361 Toggle between C source & assembly source.
27362 \end_layout
27363
27364 \begin_layout Subsubsection*
27365 ! simulator command
27366 \end_layout
27367
27368 \begin_layout Standard
27369 Send the string following '!' to the simulator, the simulator response is
27370  displayed.
27371  Note the debugger does not interpret the command being sent to the simulator,
27372  so if a command like 'go' is sent the debugger can loose its execution
27373  context and may display incorrect values.
27374 \end_layout
27375
27376 \begin_layout Subsubsection*
27377 quit
27378 \end_layout
27379
27380 \begin_layout Standard
27381 "Watch me now.
27382  Iam going Down.
27383  My name is Bobby Brown"
27384 \end_layout
27385
27386 \begin_layout Subsection
27387 Interfacing SDCDB with DDD
27388 \end_layout
27389
27390 \begin_layout Standard
27391 \begin_inset Note Note
27392 status collapsed
27393
27394 \begin_layout Standard
27395 The screenshot was converted from png to eps with: 
27396 \begin_inset Quotes sld
27397 \end_inset
27398
27399 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
27400 \begin_inset Quotes srd
27401 \end_inset
27402
27403  which produces a pretty compact eps file which is free from compression
27404  artifacts.
27405 \end_layout
27406
27407 \begin_layout Standard
27408 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
27409  as this broke the build system on Sourceforge (pdf-file was broken.
27410  pdflatex does not accept eps files).
27411 \end_layout
27412
27413 \end_inset
27414
27415
27416 \end_layout
27417
27418 \begin_layout Standard
27419 The 
27420 \emph on
27421 p
27422 \emph default
27423 ortable 
27424 \emph on
27425 n
27426 \emph default
27427 etwork 
27428 \emph on
27429 g
27430 \emph default
27431 raphics File 
27432 \size footnotesize
27433
27434 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
27435
27436 \end_inset
27437
27438
27439 \size default
27440  shows a screenshot of a debugging session with DDD
27441 \begin_inset LatexCommand \index{DDD (debugger)}
27442
27443 \end_inset
27444
27445  (Unix only) on a simulated 8032.
27446  The debugging session might not run as smoothly as the screenshot suggests.
27447  The debugger allows setting of breakpoints, displaying and changing variables,
27448  single stepping through C and assembler code.
27449  
27450 \newline
27451 The source was compiled with 
27452 \family sans
27453 \series bold
27454
27455 \newline
27456
27457 \newline
27458 sdcc -
27459 \family default
27460 \series default
27461
27462 \begin_inset ERT
27463 status collapsed
27464
27465 \begin_layout Standard
27466
27467
27468 \backslash
27469 /
27470 \end_layout
27471
27472 \end_inset
27473
27474
27475 \family sans
27476 \series bold
27477 -debug ddd_example.c
27478 \family default
27479 \series default
27480  
27481 \family sans
27482 \series bold
27483
27484 \newline
27485
27486 \family default
27487 \series default
27488
27489 \newline
27490 and DDD was invoked with 
27491 \family sans
27492 \series bold
27493
27494 \newline
27495
27496 \newline
27497 ddd -debugger "sdcdb -cpu 8032 ddd_example"
27498 \end_layout
27499
27500 \begin_layout Standard
27501 \begin_inset Note Note
27502 status open
27503
27504 \begin_layout Standard
27505 Check that the double quotes or an apostroph within the command line survive
27506  the LyX tool chain.
27507  Previously the apostrophs got slanted in the PDF output so a cut and paste
27508  did not work.
27509 \end_layout
27510
27511 \end_inset
27512
27513
27514 \end_layout
27515
27516 \begin_layout Subsection
27517 Interfacing SDCDB with XEmacs
27518 \begin_inset LatexCommand \index{XEmacs}
27519
27520 \end_inset
27521
27522
27523 \begin_inset LatexCommand \index{Emacs}
27524
27525 \end_inset
27526
27527
27528 \end_layout
27529
27530 \begin_layout Standard
27531 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
27532  sdcdb.el and sdcdbsrc.el.
27533  These two files can be found in the $(prefix)/bin directory after the installat
27534 ion is complete.
27535  These files need to be loaded into XEmacs for the interface to work.
27536  This can be done at XEmacs startup time by inserting the following into
27537  your '.xemacs' file (which can be found in your HOME directory): 
27538 \newline
27539
27540 \newline
27541
27542 \family typewriter
27543 (load-file sdcdbsrc.el) 
27544 \family default
27545
27546 \newline
27547
27548 \newline
27549 .xemacs is a lisp file so the () around the command is REQUIRED.
27550  The files can also be loaded dynamically while XEmacs is running, set the
27551  environment variable 'EMACSLOADPATH' to the installation bin directory
27552  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
27553  To start the interface enter the following command: 
27554 \newline
27555
27556 \newline
27557
27558 \family sans
27559 \series bold
27560 ESC-x sdcdbsrc
27561 \family default
27562 \series default
27563
27564 \newline
27565
27566 \newline
27567 You will prompted to enter the file name to be debugged.
27568  
27569 \newline
27570
27571 \newline
27572 The command line options that are passed to the simulator directly are
27573  bound to default values in the file sdcdbsrc.el.
27574  The variables are listed below, these values maybe changed as required.
27575 \end_layout
27576
27577 \begin_layout Itemize
27578 sdcdbsrc-cpu-type '51
27579 \end_layout
27580
27581 \begin_layout Itemize
27582 sdcdbsrc-frequency '11059200
27583 \end_layout
27584
27585 \begin_layout Itemize
27586 sdcdbsrc-serial nil
27587 \end_layout
27588
27589 \begin_layout Standard
27590 The following is a list of key mapping for the debugger interface.
27591 \end_layout
27592
27593 \begin_layout Standard
27594 \InsetSpace ~
27595
27596 \family typewriter
27597
27598 \newline
27599 ;;\InsetSpace ~
27600 Current Listing :: 
27601 \newline
27602 ;;key\InsetSpace ~
27603 \InsetSpace ~
27604 \InsetSpace ~
27605 \InsetSpace ~
27606 \InsetSpace ~
27607 \InsetSpace ~
27608 \InsetSpace ~
27609 \InsetSpace ~
27610 \InsetSpace ~
27611 \InsetSpace ~
27612 \InsetSpace ~
27613 \InsetSpace ~
27614 \InsetSpace ~
27615 \InsetSpace ~
27616 binding\InsetSpace ~
27617 \InsetSpace ~
27618 \InsetSpace ~
27619 \InsetSpace ~
27620 \InsetSpace ~
27621 \InsetSpace ~
27622 \InsetSpace ~
27623 \InsetSpace ~
27624 \InsetSpace ~
27625 \InsetSpace ~
27626 \InsetSpace ~
27627 \InsetSpace ~
27628 \InsetSpace ~
27629 \InsetSpace ~
27630 \InsetSpace ~
27631 \InsetSpace ~
27632 \InsetSpace ~
27633 \InsetSpace ~
27634 \InsetSpace ~
27635 \InsetSpace ~
27636 \InsetSpace ~
27637 \InsetSpace ~
27638 Comment 
27639 \newline
27640 ;;---\InsetSpace ~
27641 \InsetSpace ~
27642 \InsetSpace ~
27643 \InsetSpace ~
27644 \InsetSpace ~
27645 \InsetSpace ~
27646 \InsetSpace ~
27647 \InsetSpace ~
27648 \InsetSpace ~
27649 \InsetSpace ~
27650 \InsetSpace ~
27651 \InsetSpace ~
27652 \InsetSpace ~
27653 \InsetSpace ~
27654 -------\InsetSpace ~
27655 \InsetSpace ~
27656 \InsetSpace ~
27657 \InsetSpace ~
27658 \InsetSpace ~
27659 \InsetSpace ~
27660 \InsetSpace ~
27661 \InsetSpace ~
27662 \InsetSpace ~
27663 \InsetSpace ~
27664 \InsetSpace ~
27665 \InsetSpace ~
27666 \InsetSpace ~
27667 \InsetSpace ~
27668 \InsetSpace ~
27669 \InsetSpace ~
27670 \InsetSpace ~
27671 \InsetSpace ~
27672 \InsetSpace ~
27673 \InsetSpace ~
27674 \InsetSpace ~
27675 \InsetSpace ~
27676 -------
27677 \newline
27678 ;; 
27679 \newline
27680 ;;\InsetSpace ~
27681 n\InsetSpace ~
27682 \InsetSpace ~
27683 \InsetSpace ~
27684 \InsetSpace ~
27685 \InsetSpace ~
27686 \InsetSpace ~
27687 \InsetSpace ~
27688 \InsetSpace ~
27689 \InsetSpace ~
27690 \InsetSpace ~
27691 \InsetSpace ~
27692 \InsetSpace ~
27693 \InsetSpace ~
27694 \InsetSpace ~
27695 \InsetSpace ~
27696 sdcdb-next-fro
27697 m-src\InsetSpace ~
27698 \InsetSpace ~
27699 \InsetSpace ~
27700 \InsetSpace ~
27701 \InsetSpace ~
27702 \InsetSpace ~
27703 \InsetSpace ~
27704 \InsetSpace ~
27705 \InsetSpace ~
27706 \InsetSpace ~
27707 SDCDB next command 
27708 \newline
27709 ;;\InsetSpace ~
27710 b\InsetSpace ~
27711 \InsetSpace ~
27712 \InsetSpace ~
27713 \InsetSpace ~
27714 \InsetSpace ~
27715 \InsetSpace ~
27716 \InsetSpace ~
27717 \InsetSpace ~
27718 \InsetSpace ~
27719 \InsetSpace ~
27720 \InsetSpace ~
27721 \InsetSpace ~
27722 \InsetSpace ~
27723 \InsetSpace ~
27724 \InsetSpace ~
27725 sdcdb-back-from-src\InsetSpace ~
27726 \InsetSpace ~
27727 \InsetSpace ~
27728 \InsetSpace ~
27729 \InsetSpace ~
27730 \InsetSpace ~
27731 \InsetSpace ~
27732 \InsetSpace ~
27733 \InsetSpace ~
27734 \InsetSpace ~
27735 SDCDB back command 
27736 \newline
27737 ;;\InsetSpace ~
27738 c\InsetSpace ~
27739 \InsetSpace ~
27740 \InsetSpace ~
27741 \InsetSpace ~
27742 \InsetSpace ~
27743 \InsetSpace ~
27744 \InsetSpace ~
27745 \InsetSpace ~
27746 \InsetSpace ~
27747 \InsetSpace ~
27748 \InsetSpace ~
27749 \InsetSpace ~
27750 \InsetSpace ~
27751 \InsetSpace ~
27752 \InsetSpace ~
27753 sdcdb-cont-f
27754 rom-src\InsetSpace ~
27755 \InsetSpace ~
27756 \InsetSpace ~
27757 \InsetSpace ~
27758 \InsetSpace ~
27759 \InsetSpace ~
27760 \InsetSpace ~
27761 \InsetSpace ~
27762 \InsetSpace ~
27763 \InsetSpace ~
27764 SDCDB continue command
27765 \newline
27766 ;;\InsetSpace ~
27767 s\InsetSpace ~
27768 \InsetSpace ~
27769 \InsetSpace ~
27770 \InsetSpace ~
27771 \InsetSpace ~
27772 \InsetSpace ~
27773 \InsetSpace ~
27774 \InsetSpace ~
27775 \InsetSpace ~
27776 \InsetSpace ~
27777 \InsetSpace ~
27778 \InsetSpace ~
27779 \InsetSpace ~
27780 \InsetSpace ~
27781 \InsetSpace ~
27782 sdcdb-step-from-src\InsetSpace ~
27783 \InsetSpace ~
27784 \InsetSpace ~
27785 \InsetSpace ~
27786 \InsetSpace ~
27787 \InsetSpace ~
27788 \InsetSpace ~
27789 \InsetSpace ~
27790 \InsetSpace ~
27791 \InsetSpace ~
27792 SDCDB step command 
27793 \newline
27794 ;;\InsetSpace ~
27795 ?\InsetSpace ~
27796 \InsetSpace ~
27797 \InsetSpace ~
27798 \InsetSpace ~
27799 \InsetSpace ~
27800 \InsetSpace ~
27801 \InsetSpace ~
27802 \InsetSpace ~
27803 \InsetSpace ~
27804 \InsetSpace ~
27805 \InsetSpace ~
27806 \InsetSpace ~
27807 \InsetSpace ~
27808 \InsetSpace ~
27809 \InsetSpace ~
27810 sdcdb-w
27811 hatis-c-sexp\InsetSpace ~
27812 \InsetSpace ~
27813 \InsetSpace ~
27814 \InsetSpace ~
27815 \InsetSpace ~
27816 \InsetSpace ~
27817 \InsetSpace ~
27818 \InsetSpace ~
27819 \InsetSpace ~
27820 \InsetSpace ~
27821 SDCDB ptypecommand for data at 
27822 \newline
27823 ;;\InsetSpace ~
27824 \InsetSpace ~
27825 \InsetSpace ~
27826 \InsetSpace ~
27827 \InsetSpace ~
27828 \InsetSpace ~
27829 \InsetSpace ~
27830 \InsetSpace ~
27831 \InsetSpace ~
27832 \InsetSpace ~
27833 \InsetSpace ~
27834 \InsetSpace ~
27835 \InsetSpace ~
27836 \InsetSpace ~
27837 \InsetSpace ~
27838 \InsetSpace ~
27839 \InsetSpace ~
27840 \InsetSpace ~
27841 \InsetSpace ~
27842 \InsetSpace ~
27843 \InsetSpace ~
27844 \InsetSpace ~
27845 \InsetSpace ~
27846 \InsetSpace ~
27847 \InsetSpace ~
27848 \InsetSpace ~
27849 \InsetSpace ~
27850 \InsetSpace ~
27851 \InsetSpace ~
27852 \InsetSpace ~
27853 \InsetSpace ~
27854 \InsetSpace ~
27855 \InsetSpace ~
27856 \InsetSpace ~
27857 \InsetSpace ~
27858 \InsetSpace ~
27859 \InsetSpace ~
27860 \InsetSpace ~
27861 \InsetSpace ~
27862 \InsetSpace ~
27863 \InsetSpace ~
27864 \InsetSpace ~
27865 \InsetSpace ~
27866 \InsetSpace ~
27867 \InsetSpace ~
27868 \InsetSpace ~
27869 \InsetSpace ~
27870 buffer point 
27871 \newline
27872 ;;\InsetSpace ~
27873 x\InsetSpace ~
27874 \InsetSpace ~
27875 \InsetSpace ~
27876 \InsetSpace ~
27877 \InsetSpace ~
27878 \InsetSpace ~
27879 \InsetSpace ~
27880 \InsetSpace ~
27881 \InsetSpace ~
27882 \InsetSpace ~
27883 \InsetSpace ~
27884 \InsetSpace ~
27885 \InsetSpace ~
27886 \InsetSpace ~
27887 \InsetSpace ~
27888 sdcdbsrc-delete\InsetSpace ~
27889 \InsetSpace ~
27890 \InsetSpace ~
27891 \InsetSpace ~
27892 \InsetSpace ~
27893 \InsetSpace ~
27894 \InsetSpace ~
27895 \InsetSpace ~
27896 \InsetSpace ~
27897 \InsetSpace ~
27898 \InsetSpace ~
27899 \InsetSpace ~
27900 \InsetSpace ~
27901 \InsetSpace ~
27902 SDCD
27903 B Delete all breakpoints if no arg 
27904 \newline
27905 ;;\InsetSpace ~
27906 \InsetSpace ~
27907 \InsetSpace ~
27908 \InsetSpace ~
27909 \InsetSpace ~
27910 \InsetSpace ~
27911 \InsetSpace ~
27912 \InsetSpace ~
27913 \InsetSpace ~
27914 \InsetSpace ~
27915 \InsetSpace ~
27916 \InsetSpace ~
27917 \InsetSpace ~
27918 \InsetSpace ~
27919 \InsetSpace ~
27920 \InsetSpace ~
27921 \InsetSpace ~
27922 \InsetSpace ~
27923 \InsetSpace ~
27924 \InsetSpace ~
27925 \InsetSpace ~
27926 \InsetSpace ~
27927 \InsetSpace ~
27928 \InsetSpace ~
27929 \InsetSpace ~
27930 \InsetSpace ~
27931 \InsetSpace ~
27932 \InsetSpace ~
27933 \InsetSpace ~
27934 \InsetSpace ~
27935 \InsetSpace ~
27936 \InsetSpace ~
27937 \InsetSpace ~
27938 \InsetSpace ~
27939 \InsetSpace ~
27940 \InsetSpace ~
27941 \InsetSpace ~
27942 \InsetSpace ~
27943 \InsetSpace ~
27944 \InsetSpace ~
27945 \InsetSpace ~
27946 \InsetSpace ~
27947 \InsetSpace ~
27948 \InsetSpace ~
27949 \InsetSpace ~
27950 \InsetSpace ~
27951 \InsetSpace ~
27952 given or delete arg (C-u arg x) 
27953 \newline
27954 ;;\InsetSpace ~
27955 m\InsetSpace ~
27956 \InsetSpace ~
27957 \InsetSpace ~
27958 \InsetSpace ~
27959 \InsetSpace ~
27960 \InsetSpace ~
27961 \InsetSpace ~
27962 \InsetSpace ~
27963 \InsetSpace ~
27964 \InsetSpace ~
27965 \InsetSpace ~
27966 \InsetSpace ~
27967 \InsetSpace ~
27968 \InsetSpace ~
27969 \InsetSpace ~
27970 sdcdbsrc
27971 -frame\InsetSpace ~
27972 \InsetSpace ~
27973 \InsetSpace ~
27974 \InsetSpace ~
27975 \InsetSpace ~
27976 \InsetSpace ~
27977 \InsetSpace ~
27978 \InsetSpace ~
27979 \InsetSpace ~
27980 \InsetSpace ~
27981 \InsetSpace ~
27982 \InsetSpace ~
27983 \InsetSpace ~
27984 \InsetSpace ~
27985 \InsetSpace ~
27986 SDCDB Display current frame if no arg, 
27987 \newline
27988 ;;\InsetSpace ~
27989 \InsetSpace ~
27990 \InsetSpace ~
27991 \InsetSpace ~
27992 \InsetSpace ~
27993 \InsetSpace ~
27994 \InsetSpace ~
27995 \InsetSpace ~
27996 \InsetSpace ~
27997 \InsetSpace ~
27998 \InsetSpace ~
27999 \InsetSpace ~
28000 \InsetSpace ~
28001 \InsetSpace ~
28002 \InsetSpace ~
28003 \InsetSpace ~
28004 \InsetSpace ~
28005 \InsetSpace ~
28006 \InsetSpace ~
28007 \InsetSpace ~
28008 \InsetSpace ~
28009 \InsetSpace ~
28010 \InsetSpace ~
28011 \InsetSpace ~
28012 \InsetSpace ~
28013 \InsetSpace ~
28014 \InsetSpace ~
28015 \InsetSpace ~
28016 \InsetSpace ~
28017 \InsetSpace ~
28018 \InsetSpace ~
28019 \InsetSpace ~
28020 \InsetSpace ~
28021 \InsetSpace ~
28022 \InsetSpace ~
28023 \InsetSpace ~
28024 \InsetSpace ~
28025 \InsetSpace ~
28026 \InsetSpace ~
28027 \InsetSpace ~
28028 \InsetSpace ~
28029 \InsetSpace ~
28030 \InsetSpace ~
28031 \InsetSpace ~
28032 \InsetSpace ~
28033 \InsetSpace ~
28034 \InsetSpace ~
28035 given or display frame arg
28036  
28037 \newline
28038 ;;\InsetSpace ~
28039 \InsetSpace ~
28040 \InsetSpace ~
28041 \InsetSpace ~
28042 \InsetSpace ~
28043 \InsetSpace ~
28044 \InsetSpace ~
28045 \InsetSpace ~
28046 \InsetSpace ~
28047 \InsetSpace ~
28048 \InsetSpace ~
28049 \InsetSpace ~
28050 \InsetSpace ~
28051 \InsetSpace ~
28052 \InsetSpace ~
28053 \InsetSpace ~
28054 \InsetSpace ~
28055 \InsetSpace ~
28056 \InsetSpace ~
28057 \InsetSpace ~
28058 \InsetSpace ~
28059 \InsetSpace ~
28060 \InsetSpace ~
28061 \InsetSpace ~
28062 \InsetSpace ~
28063 \InsetSpace ~
28064 \InsetSpace ~
28065 \InsetSpace ~
28066 \InsetSpace ~
28067 \InsetSpace ~
28068 \InsetSpace ~
28069 \InsetSpace ~
28070 \InsetSpace ~
28071 \InsetSpace ~
28072 \InsetSpace ~
28073 \InsetSpace ~
28074 \InsetSpace ~
28075 \InsetSpace ~
28076 \InsetSpace ~
28077 \InsetSpace ~
28078 \InsetSpace ~
28079 \InsetSpace ~
28080 \InsetSpace ~
28081 \InsetSpace ~
28082 \InsetSpace ~
28083 \InsetSpace ~
28084 \InsetSpace ~
28085 buffer point 
28086 \newline
28087 ;;\InsetSpace ~
28088 !\InsetSpace ~
28089 \InsetSpace ~
28090 \InsetSpace ~
28091 \InsetSpace ~
28092 \InsetSpace ~
28093 \InsetSpace ~
28094 \InsetSpace ~
28095 \InsetSpace ~
28096 \InsetSpace ~
28097 \InsetSpace ~
28098 \InsetSpace ~
28099 \InsetSpace ~
28100 \InsetSpace ~
28101 \InsetSpace ~
28102 \InsetSpace ~
28103 sdcdbsrc-goto-sdcdb\InsetSpace ~
28104 \InsetSpace ~
28105 \InsetSpace ~
28106 \InsetSpace ~
28107 \InsetSpace ~
28108 \InsetSpace ~
28109 \InsetSpace ~
28110 \InsetSpace ~
28111 \InsetSpace ~
28112 \InsetSpace ~
28113 Goto the SDCDB output buffer 
28114 \newline
28115 ;;\InsetSpace ~
28116 p\InsetSpace ~
28117 \InsetSpace ~
28118 \InsetSpace ~
28119 \InsetSpace ~
28120 \InsetSpace ~
28121 \InsetSpace ~
28122 \InsetSpace ~
28123 \InsetSpace ~
28124 \InsetSpace ~
28125 \InsetSpace ~
28126 \InsetSpace ~
28127 \InsetSpace ~
28128 \InsetSpace ~
28129 \InsetSpace ~
28130 \InsetSpace ~
28131 sdcdb-prin
28132 t-c-sexp\InsetSpace ~
28133 \InsetSpace ~
28134 \InsetSpace ~
28135 \InsetSpace ~
28136 \InsetSpace ~
28137 \InsetSpace ~
28138 \InsetSpace ~
28139 \InsetSpace ~
28140 \InsetSpace ~
28141 \InsetSpace ~
28142 \InsetSpace ~
28143 SDCDB print command for data at 
28144 \newline
28145 ;;\InsetSpace ~
28146 \InsetSpace ~
28147 \InsetSpace ~
28148 \InsetSpace ~
28149 \InsetSpace ~
28150 \InsetSpace ~
28151 \InsetSpace ~
28152 \InsetSpace ~
28153 \InsetSpace ~
28154 \InsetSpace ~
28155 \InsetSpace ~
28156 \InsetSpace ~
28157 \InsetSpace ~
28158 \InsetSpace ~
28159 \InsetSpace ~
28160 \InsetSpace ~
28161 \InsetSpace ~
28162 \InsetSpace ~
28163 \InsetSpace ~
28164 \InsetSpace ~
28165 \InsetSpace ~
28166 \InsetSpace ~
28167 \InsetSpace ~
28168 \InsetSpace ~
28169 \InsetSpace ~
28170 \InsetSpace ~
28171 \InsetSpace ~
28172 \InsetSpace ~
28173 \InsetSpace ~
28174 \InsetSpace ~
28175 \InsetSpace ~
28176 \InsetSpace ~
28177 \InsetSpace ~
28178 \InsetSpace ~
28179 \InsetSpace ~
28180 \InsetSpace ~
28181 \InsetSpace ~
28182 \InsetSpace ~
28183 \InsetSpace ~
28184 \InsetSpace ~
28185 \InsetSpace ~
28186 \InsetSpace ~
28187 \InsetSpace ~
28188 \InsetSpace ~
28189 \InsetSpace ~
28190 \InsetSpace ~
28191 \InsetSpace ~
28192 buffer point 
28193 \newline
28194 ;;\InsetSpace ~
28195 g\InsetSpace ~
28196 \InsetSpace ~
28197 \InsetSpace ~
28198 \InsetSpace ~
28199 \InsetSpace ~
28200 \InsetSpace ~
28201 \InsetSpace ~
28202 \InsetSpace ~
28203 \InsetSpace ~
28204 \InsetSpace ~
28205 \InsetSpace ~
28206 \InsetSpace ~
28207 \InsetSpace ~
28208 \InsetSpace ~
28209 \InsetSpace ~
28210 sdcdbsrc-goto-sdcdb\InsetSpace ~
28211 \InsetSpace ~
28212 \InsetSpace ~
28213 \InsetSpace ~
28214 \InsetSpace ~
28215 \InsetSpace ~
28216 \InsetSpace ~
28217 \InsetSpace ~
28218 \InsetSpace ~
28219 \InsetSpace ~
28220 Got
28221 o the SDCDB output buffer 
28222 \newline
28223 ;;\InsetSpace ~
28224 t\InsetSpace ~
28225 \InsetSpace ~
28226 \InsetSpace ~
28227 \InsetSpace ~
28228 \InsetSpace ~
28229 \InsetSpace ~
28230 \InsetSpace ~
28231 \InsetSpace ~
28232 \InsetSpace ~
28233 \InsetSpace ~
28234 \InsetSpace ~
28235 \InsetSpace ~
28236 \InsetSpace ~
28237 \InsetSpace ~
28238 \InsetSpace ~
28239 sdcdbsrc-mode\InsetSpace ~
28240 \InsetSpace ~
28241 \InsetSpace ~
28242 \InsetSpace ~
28243 \InsetSpace ~
28244 \InsetSpace ~
28245 \InsetSpace ~
28246 \InsetSpace ~
28247 \InsetSpace ~
28248 \InsetSpace ~
28249 \InsetSpace ~
28250 \InsetSpace ~
28251 \InsetSpace ~
28252 \InsetSpace ~
28253 \InsetSpace ~
28254 \InsetSpace ~
28255 Toggles Sdcdbsrc mode (turns it
28256  off) 
28257 \newline
28258 ;; 
28259 \newline
28260 ;;\InsetSpace ~
28261 C-c\InsetSpace ~
28262 C-f\InsetSpace ~
28263 \InsetSpace ~
28264 \InsetSpace ~
28265 \InsetSpace ~
28266 \InsetSpace ~
28267 \InsetSpace ~
28268 \InsetSpace ~
28269 \InsetSpace ~
28270 \InsetSpace ~
28271 sdcdb-finish-from-src\InsetSpace ~
28272 \InsetSpace ~
28273 \InsetSpace ~
28274 \InsetSpace ~
28275 \InsetSpace ~
28276 \InsetSpace ~
28277 \InsetSpace ~
28278 \InsetSpace ~
28279 SDCDB finish command 
28280 \newline
28281 ;; 
28282 \newline
28283 ;;\InsetSpace ~
28284 C-x\InsetSpace ~
28285 SPC\InsetSpace ~
28286 \InsetSpace ~
28287 \InsetSpace ~
28288 \InsetSpace ~
28289 \InsetSpace ~
28290 \InsetSpace ~
28291 \InsetSpace ~
28292 \InsetSpace ~
28293 \InsetSpace ~
28294 sdcdb-brea
28295 k\InsetSpace ~
28296 \InsetSpace ~
28297 \InsetSpace ~
28298 \InsetSpace ~
28299 \InsetSpace ~
28300 \InsetSpace ~
28301 \InsetSpace ~
28302 \InsetSpace ~
28303 \InsetSpace ~
28304 \InsetSpace ~
28305 \InsetSpace ~
28306 \InsetSpace ~
28307 \InsetSpace ~
28308 \InsetSpace ~
28309 \InsetSpace ~
28310 \InsetSpace ~
28311 \InsetSpace ~
28312 \InsetSpace ~
28313 Set break for line with point 
28314 \newline
28315 ;;\InsetSpace ~
28316 ESC\InsetSpace ~
28317 t\InsetSpace ~
28318 \InsetSpace ~
28319 \InsetSpace ~
28320 \InsetSpace ~
28321 \InsetSpace ~
28322 \InsetSpace ~
28323 \InsetSpace ~
28324 \InsetSpace ~
28325 \InsetSpace ~
28326 \InsetSpace ~
28327 \InsetSpace ~
28328 sdcdbsrc-mode\InsetSpace ~
28329 \InsetSpace ~
28330 \InsetSpace ~
28331 \InsetSpace ~
28332 \InsetSpace ~
28333 \InsetSpace ~
28334 \InsetSpace ~
28335 \InsetSpace ~
28336 \InsetSpace ~
28337 \InsetSpace ~
28338 \InsetSpace ~
28339 \InsetSpace ~
28340 \InsetSpace ~
28341 \InsetSpace ~
28342 \InsetSpace ~
28343 \InsetSpace ~
28344 Toggle Sdcdbsrc mode 
28345 \newline
28346 ;;\InsetSpace ~
28347 ESC\InsetSpace ~
28348 m\InsetSpace ~
28349 \InsetSpace ~
28350 \InsetSpace ~
28351 \InsetSpace ~
28352 \InsetSpace ~
28353 \InsetSpace ~
28354 \InsetSpace ~
28355 \InsetSpace ~
28356 \InsetSpace ~
28357 \InsetSpace ~
28358 \InsetSpace ~
28359 sdc
28360 dbsrc-srcmode\InsetSpace ~
28361 \InsetSpace ~
28362 \InsetSpace ~
28363 \InsetSpace ~
28364 \InsetSpace ~
28365 \InsetSpace ~
28366 \InsetSpace ~
28367 \InsetSpace ~
28368 \InsetSpace ~
28369 \InsetSpace ~
28370 \InsetSpace ~
28371 \InsetSpace ~
28372 \InsetSpace ~
28373 Toggle list mode 
28374 \newline
28375 ;; 
28376 \newline
28377
28378 \family default
28379
28380 \newpage
28381
28382 \end_layout
28383
28384 \begin_layout Chapter
28385 TIPS
28386 \end_layout
28387
28388 \begin_layout Standard
28389 Here are a few guidelines that will help the compiler generate more efficient
28390  code, some of the tips are specific to this compiler others are generally
28391  good programming practice.
28392 \end_layout
28393
28394 \begin_layout Itemize
28395 Use the smallest data type to represent your data-value.
28396  If it is known in advance that the value is going to be less than 256 then
28397  use an 'unsigned char' instead of a 'short' or 'int'.
28398  Please note, that ANSI C requires both signed and unsigned chars to be
28399  promoted to 'signed int'
28400 \begin_inset LatexCommand \index{promotion to signed int}
28401
28402 \end_inset
28403
28404
28405 \begin_inset Marginal
28406 status collapsed
28407
28408 \begin_layout Standard
28409
28410 \series bold
28411 \InsetSpace ~
28412 !
28413 \end_layout
28414
28415 \end_inset
28416
28417  before doing any operation.
28418  This promotion
28419 \begin_inset LatexCommand \index{type promotion}
28420
28421 \end_inset
28422
28423
28424 \begin_inset LatexCommand \label{type promotion}
28425
28426 \end_inset
28427
28428  can be omitted, if the result is the same.
28429  The effect of the promotion rules together with the sign-extension is often
28430  surprising:
28431 \end_layout
28432
28433 \begin_deeper
28434 \begin_layout Verse
28435
28436 \family typewriter
28437 unsigned char uc = 0xfe;
28438 \newline
28439 if (uc * uc < 0) /* this is true! */
28440 \newline
28441 {
28442 \newline
28443 \InsetSpace ~
28444 \InsetSpace ~
28445 \InsetSpace ~
28446 \InsetSpace ~
28447 ....
28448 \newline
28449 }
28450 \end_layout
28451
28452 \begin_layout Standard
28453
28454 \family typewriter
28455 uc * uc
28456 \family default
28457  is evaluated as 
28458 \family typewriter
28459 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
28460 \family default
28461 .
28462  
28463 \newline
28464 Another one:
28465 \end_layout
28466
28467 \begin_layout Verse
28468
28469 \family typewriter
28470 (unsigned char) -12 / (signed char) -3 = ...
28471 \end_layout
28472
28473 \begin_layout Standard
28474 No, the result is not 4:
28475 \end_layout
28476
28477 \begin_layout Verse
28478
28479 \family typewriter
28480 (int) (unsigned char) -12 / (int) (signed char) -3 =
28481 \newline
28482 (int) (unsigned char)
28483  0xf4 / (int) (signed char) 0xfd =
28484 \newline
28485 (int) 0x00f4 / (int) 0xfffd =
28486 \newline
28487 (int) 0x00f4
28488  / (int) 0xfffd =
28489 \newline
28490 (int) 244 / (int) -3 =
28491 \newline
28492 (int) -81 = (int) 0xffaf;
28493 \end_layout
28494
28495 \begin_layout Standard
28496 Don't complain, that gcc gives you a different result.
28497  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
28498  Therefore the results are different.
28499 \newline
28500 From 
28501 \begin_inset Quotes sld
28502 \end_inset
28503
28504 comp.lang.c FAQ
28505 \begin_inset Quotes srd
28506 \end_inset
28507
28508 :
28509 \end_layout
28510
28511 \begin_layout Quote
28512
28513 \emph on
28514 If well-defined overflow characteristics are important and negative values
28515  are not, or if you want to steer clear of sign-extension problems when
28516  manipulating bits or bytes, use one of the corresponding unsigned types.
28517  (Beware when mixing signed and unsigned values in expressions, though.)
28518 \newline
28519 Although
28520  character types (especially unsigned char) can be used as "tiny" integers,
28521  doing so is sometimes more trouble than it's worth, due to unpredictable
28522  sign extension and increased code size.
28523 \end_layout
28524
28525 \end_deeper
28526 \begin_layout Itemize
28527 Use unsigned when it is known in advance that the value is not going to
28528  be negative.
28529  This helps especially if you are doing division or multiplication, bit-shifting
28530  or are using an array index.
28531 \end_layout
28532
28533 \begin_layout Itemize
28534 NEVER jump into a LOOP.
28535 \end_layout
28536
28537 \begin_layout Itemize
28538 Declare the variables to be local
28539 \begin_inset LatexCommand \index{local variables}
28540
28541 \end_inset
28542
28543  whenever possible, especially loop control variables (induction).
28544 \end_layout
28545
28546 \begin_layout Itemize
28547 Have a look at the assembly listing to get a 
28548 \begin_inset Quotes sld
28549 \end_inset
28550
28551 feeling
28552 \begin_inset Quotes srd
28553 \end_inset
28554
28555  for the code generation.
28556 \end_layout
28557
28558 \begin_layout Section
28559 Porting code from or to other compilers
28560 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
28561
28562 \end_inset
28563
28564
28565 \end_layout
28566
28567 \begin_layout Itemize
28568 check whether endianness of the compilers differs and adapt where needed.
28569 \end_layout
28570
28571 \begin_layout Itemize
28572 check the device specific header files
28573 \begin_inset LatexCommand \index{Header files}
28574
28575 \end_inset
28576
28577
28578 \begin_inset LatexCommand \index{Include files}
28579
28580 \end_inset
28581
28582  for compiler specific syntax.
28583  Eventually include the file <compiler.h
28584 \begin_inset LatexCommand \index{compiler.h (include file)}
28585
28586 \end_inset
28587
28588
28589 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
28590
28591 \end_inset
28592
28593  to allow using common header files.
28594  (see f.e.
28595  cc2510fx.h 
28596 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
28597
28598 \end_inset
28599
28600 ).
28601 \end_layout
28602
28603 \begin_layout Itemize
28604 check whether the startup code contains the correct initialization (watchdog,
28605  peripherals).
28606 \end_layout
28607
28608 \begin_layout Itemize
28609 check whether the sizes of short, int, long match.
28610 \end_layout
28611
28612 \begin_layout Itemize
28613 check if some 16 or 32 bit hardware registers require a specific addressing
28614  order (least significant or most significant byte first) and adapt if needed
28615  (
28616 \emph on
28617 first
28618 \emph default
28619  and 
28620 \emph on
28621 last
28622 \emph default
28623  relate to time and not to lower/upper memory location here, so this is
28624  
28625 \emph on
28626 not
28627 \emph default
28628  the same as endianness).
28629 \end_layout
28630
28631 \begin_layout Itemize
28632 check whether the keyword 
28633 \emph on
28634 volatile
28635 \emph default
28636  is used where needed.
28637  The compilers might differ in their optimization characteristics (as different
28638  versions of the same compiler might also use more clever optimizations
28639  this is good idea anyway).
28640  See section 
28641 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
28642
28643 \end_inset
28644
28645 .
28646 \end_layout
28647
28648 \begin_layout Itemize
28649 check that the compilers are not told to supress warnings.
28650 \end_layout
28651
28652 \begin_layout Itemize
28653 check and convert compiler specific extensions (interrupts, memory areas,
28654  pragmas etc.).
28655 \end_layout
28656
28657 \begin_layout Itemize
28658 check for differences in type promotion.
28659  Especially check for math operations on 
28660 \family typewriter
28661 char
28662 \family default
28663  or 
28664 \family typewriter
28665 unsigned char
28666 \family default
28667  variables.
28668  For the sake of C99 compatibility SDCC will probably promote these to 
28669 \family typewriter
28670 int
28671 \family default
28672  more often than other compilers.
28673  Eventually insert explicit casts to 
28674 \family typewriter
28675 (char) 
28676 \family default
28677 or
28678 \family typewriter
28679  (unsigned char)
28680 \family default
28681 .
28682  Also check that the ~\InsetSpace ~
28683 operator
28684 \begin_inset LatexCommand \index{\~\/ Operator}
28685
28686 \end_inset
28687
28688  is not used on 
28689 \family typewriter
28690 bit
28691 \begin_inset LatexCommand \index{bit}
28692
28693 \end_inset
28694
28695
28696 \family default
28697  variables, use the !\InsetSpace ~
28698 operator instead.
28699  See sections 
28700 \begin_inset LatexCommand \ref{type promotion}
28701
28702 \end_inset
28703
28704  and 
28705 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
28706
28707 \end_inset
28708
28709 .
28710 \end_layout
28711
28712 \begin_layout Itemize
28713 check the assembly code generated for interrupt routines (f.e.
28714  for calls to possibly non-reentrant library functions).
28715 \end_layout
28716
28717 \begin_layout Itemize
28718 check whether timing loops result in proper timing (or preferably consider
28719  a rewrite of the code with timer based delays instead).
28720 \end_layout
28721
28722 \begin_layout Itemize
28723 check for differences in printf parameters (some compilers push (va_arg
28724 \begin_inset LatexCommand \index{vararg, va\_arg}
28725
28726 \end_inset
28727
28728 ) char variables as 
28729 \family typewriter
28730 int
28731 \family default
28732  others push them as 
28733 \family typewriter
28734 char
28735 \family default
28736 .
28737  See section 
28738 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
28739
28740 \end_inset
28741
28742 ).
28743 \end_layout
28744
28745 \begin_layout Itemize
28746 check the resulting memory map
28747 \begin_inset LatexCommand \index{Memory map}
28748
28749 \end_inset
28750
28751 .
28752  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
28753 ly idata, pdata, xdata).
28754  Eventually check if unexpected library functions are included.
28755 \end_layout
28756
28757 \begin_layout Section
28758 Tools
28759 \begin_inset LatexCommand \index{Tools}
28760
28761 \end_inset
28762
28763  included in the distribution
28764 \end_layout
28765
28766 \begin_layout Standard
28767 \align left
28768 \begin_inset Tabular
28769 <lyxtabular version="3" rows="12" columns="3">
28770 <features>
28771 <column alignment="left" valignment="top" leftline="true" width="0pt">
28772 <column alignment="left" valignment="top" leftline="true" width="0pt">
28773 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28774 <row topline="true" bottomline="true">
28775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28776 \begin_inset Text
28777
28778 \begin_layout Standard
28779
28780 \series bold
28781 Name
28782 \end_layout
28783
28784 \end_inset
28785 </cell>
28786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28787 \begin_inset Text
28788
28789 \begin_layout Standard
28790
28791 \series bold
28792 Purpose
28793 \end_layout
28794
28795 \end_inset
28796 </cell>
28797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28798 \begin_inset Text
28799
28800 \begin_layout Standard
28801
28802 \series bold
28803 Directory
28804 \end_layout
28805
28806 \end_inset
28807 </cell>
28808 </row>
28809 <row topline="true">
28810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28811 \begin_inset Text
28812
28813 \begin_layout Standard
28814 uCsim
28815 \begin_inset LatexCommand \index{uCsim}
28816
28817 \end_inset
28818
28819
28820 \end_layout
28821
28822 \end_inset
28823 </cell>
28824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28825 \begin_inset Text
28826
28827 \begin_layout Standard
28828 Simulator for various architectures
28829 \end_layout
28830
28831 \end_inset
28832 </cell>
28833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28834 \begin_inset Text
28835
28836 \begin_layout Standard
28837 sdcc/sim/ucsim
28838 \end_layout
28839
28840 \end_inset
28841 </cell>
28842 </row>
28843 <row topline="true">
28844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28845 \begin_inset Text
28846
28847 \begin_layout Standard
28848 keil2sdcc.pl
28849 \end_layout
28850
28851 \end_inset
28852 </cell>
28853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28854 \begin_inset Text
28855
28856 \begin_layout Standard
28857 header file
28858 \begin_inset LatexCommand \index{Header files}
28859
28860 \end_inset
28861
28862
28863 \begin_inset LatexCommand \index{Include files}
28864
28865 \end_inset
28866
28867  conversion
28868 \end_layout
28869
28870 \end_inset
28871 </cell>
28872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28873 \begin_inset Text
28874
28875 \begin_layout Standard
28876 sdcc/support/scripts
28877 \end_layout
28878
28879 \end_inset
28880 </cell>
28881 </row>
28882 <row topline="true">
28883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28884 \begin_inset Text
28885
28886 \begin_layout Standard
28887 mh2h.c
28888 \end_layout
28889
28890 \end_inset
28891 </cell>
28892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28893 \begin_inset Text
28894
28895 \begin_layout Standard
28896 header file conversion
28897 \end_layout
28898
28899 \end_inset
28900 </cell>
28901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28902 \begin_inset Text
28903
28904 \begin_layout Standard
28905 sdcc/support/scripts
28906 \end_layout
28907
28908 \end_inset
28909 </cell>
28910 </row>
28911 <row topline="true">
28912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28913 \begin_inset Text
28914
28915 \begin_layout Standard
28916 as-gbz80
28917 \end_layout
28918
28919 \end_inset
28920 </cell>
28921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28922 \begin_inset Text
28923
28924 \begin_layout Standard
28925 Assembler
28926 \end_layout
28927
28928 \end_inset
28929 </cell>
28930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28931 \begin_inset Text
28932
28933 \begin_layout Standard
28934
28935 \family roman
28936 \series medium
28937 \shape up
28938 \size normal
28939 \emph off
28940 \bar no
28941 \noun off
28942 \color none
28943 sdcc/bin
28944 \end_layout
28945
28946 \end_inset
28947 </cell>
28948 </row>
28949 <row topline="true">
28950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28951 \begin_inset Text
28952
28953 \begin_layout Standard
28954 as-z80
28955 \end_layout
28956
28957 \end_inset
28958 </cell>
28959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28960 \begin_inset Text
28961
28962 \begin_layout Standard
28963 Assembler
28964 \end_layout
28965
28966 \end_inset
28967 </cell>
28968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28969 \begin_inset Text
28970
28971 \begin_layout Standard
28972
28973 \family roman
28974 \series medium
28975 \shape up
28976 \size normal
28977 \emph off
28978 \bar no
28979 \noun off
28980 \color none
28981 sdcc/bin
28982 \end_layout
28983
28984 \end_inset
28985 </cell>
28986 </row>
28987 <row topline="true">
28988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28989 \begin_inset Text
28990
28991 \begin_layout Standard
28992 asx8051
28993 \end_layout
28994
28995 \end_inset
28996 </cell>
28997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28998 \begin_inset Text
28999
29000 \begin_layout Standard
29001 Assembler
29002 \end_layout
29003
29004 \end_inset
29005 </cell>
29006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29007 \begin_inset Text
29008
29009 \begin_layout Standard
29010
29011 \family roman
29012 \series medium
29013 \shape up
29014 \size normal
29015 \emph off
29016 \bar no
29017 \noun off
29018 \color none
29019 sdcc/bin
29020 \end_layout
29021
29022 \end_inset
29023 </cell>
29024 </row>
29025 <row topline="true">
29026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29027 \begin_inset Text
29028
29029 \begin_layout Standard
29030 SDCDB
29031 \end_layout
29032
29033 \end_inset
29034 </cell>
29035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29036 \begin_inset Text
29037
29038 \begin_layout Standard
29039 Simulator
29040 \end_layout
29041
29042 \end_inset
29043 </cell>
29044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29045 \begin_inset Text
29046
29047 \begin_layout Standard
29048
29049 \family roman
29050 \series medium
29051 \shape up
29052 \size normal
29053 \emph off
29054 \bar no
29055 \noun off
29056 \color none
29057 sdcc/bin
29058 \end_layout
29059
29060 \end_inset
29061 </cell>
29062 </row>
29063 <row topline="true">
29064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29065 \begin_inset Text
29066
29067 \begin_layout Standard
29068 aslink
29069 \end_layout
29070
29071 \end_inset
29072 </cell>
29073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29074 \begin_inset Text
29075
29076 \begin_layout Standard
29077 Linker
29078 \end_layout
29079
29080 \end_inset
29081 </cell>
29082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29083 \begin_inset Text
29084
29085 \begin_layout Standard
29086
29087 \family roman
29088 \series medium
29089 \shape up
29090 \size normal
29091 \emph off
29092 \bar no
29093 \noun off
29094 \color none
29095 sdcc/bin
29096 \end_layout
29097
29098 \end_inset
29099 </cell>
29100 </row>
29101 <row topline="true">
29102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29103 \begin_inset Text
29104
29105 \begin_layout Standard
29106 link-z80
29107 \end_layout
29108
29109 \end_inset
29110 </cell>
29111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29112 \begin_inset Text
29113
29114 \begin_layout Standard
29115 Linker
29116 \end_layout
29117
29118 \end_inset
29119 </cell>
29120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29121 \begin_inset Text
29122
29123 \begin_layout Standard
29124
29125 \family roman
29126 \series medium
29127 \shape up
29128 \size normal
29129 \emph off
29130 \bar no
29131 \noun off
29132 \color none
29133 sdcc/bin
29134 \end_layout
29135
29136 \end_inset
29137 </cell>
29138 </row>
29139 <row topline="true">
29140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29141 \begin_inset Text
29142
29143 \begin_layout Standard
29144 link-gbz80
29145 \end_layout
29146
29147 \end_inset
29148 </cell>
29149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29150 \begin_inset Text
29151
29152 \begin_layout Standard
29153 Linker
29154 \end_layout
29155
29156 \end_inset
29157 </cell>
29158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29159 \begin_inset Text
29160
29161 \begin_layout Standard
29162
29163 \family roman
29164 \series medium
29165 \shape up
29166 \size normal
29167 \emph off
29168 \bar no
29169 \noun off
29170 \color none
29171 sdcc/bin
29172 \end_layout
29173
29174 \end_inset
29175 </cell>
29176 </row>
29177 <row topline="true" bottomline="true">
29178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29179 \begin_inset Text
29180
29181 \begin_layout Standard
29182 packihx
29183 \end_layout
29184
29185 \end_inset
29186 </cell>
29187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29188 \begin_inset Text
29189
29190 \begin_layout Standard
29191 Intel Hex packer 
29192 \begin_inset LatexCommand \index{packihx (tool)}
29193
29194 \end_inset
29195
29196
29197 \end_layout
29198
29199 \end_inset
29200 </cell>
29201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29202 \begin_inset Text
29203
29204 \begin_layout Standard
29205
29206 \family roman
29207 \series medium
29208 \shape up
29209 \size normal
29210 \emph off
29211 \bar no
29212 \noun off
29213 \color none
29214 sdcc/bin
29215 \end_layout
29216
29217 \end_inset
29218 </cell>
29219 </row>
29220 </lyxtabular>
29221
29222 \end_inset
29223
29224
29225 \newline
29226
29227 \end_layout
29228
29229 \begin_layout Section
29230 Documentation
29231 \begin_inset LatexCommand \index{Documentation}
29232
29233 \end_inset
29234
29235  included in the distribution
29236 \end_layout
29237
29238 \begin_layout Standard
29239 \align left
29240 \begin_inset Tabular
29241 <lyxtabular version="3" rows="10" columns="2">
29242 <features>
29243 <column alignment="block" valignment="top" leftline="true" width="40col%">
29244 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29245 <row topline="true" bottomline="true" endhead="true">
29246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29247 \begin_inset Text
29248
29249 \begin_layout Standard
29250
29251 \series bold
29252 Subject / Title
29253 \end_layout
29254
29255 \end_inset
29256 </cell>
29257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29258 \begin_inset Text
29259
29260 \begin_layout Standard
29261
29262 \series bold
29263 Filename / Where to get
29264 \end_layout
29265
29266 \end_inset
29267 </cell>
29268 </row>
29269 <row topline="true">
29270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29271 \begin_inset Text
29272
29273 \begin_layout Standard
29274 SDCC Compiler User Guide
29275 \end_layout
29276
29277 \end_inset
29278 </cell>
29279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29280 \begin_inset Text
29281
29282 \begin_layout Standard
29283 You're reading it right now
29284 \emph on
29285  \InsetSpace ~
29286 \InsetSpace ~
29287 \InsetSpace ~
29288
29289 \hfill
29290 online at:
29291 \emph default
29292
29293 \newline
29294
29295 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29296
29297 \end_inset
29298
29299
29300 \end_layout
29301
29302 \end_inset
29303 </cell>
29304 </row>
29305 <row topline="true">
29306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29307 \begin_inset Text
29308
29309 \begin_layout Standard
29310 Changelog of SDCC
29311 \end_layout
29312
29313 \end_inset
29314 </cell>
29315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29316 \begin_inset Text
29317
29318 \begin_layout Standard
29319 sdcc/Changelog
29320 \emph on
29321  \InsetSpace ~
29322 \InsetSpace ~
29323 \InsetSpace ~
29324
29325 \hfill
29326 online at:
29327 \emph default
29328
29329 \newline
29330
29331 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29332
29333 \end_inset
29334
29335
29336 \end_layout
29337
29338 \end_inset
29339 </cell>
29340 </row>
29341 <row topline="true">
29342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29343 \begin_inset Text
29344
29345 \begin_layout Standard
29346 ASXXXX
29347 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29348
29349 \end_inset
29350
29351
29352 \begin_inset LatexCommand \index{Assembler documentation}
29353
29354 \end_inset
29355
29356  Assemblers and
29357 \newline
29358 ASLINK
29359 \begin_inset LatexCommand \index{aslink}
29360
29361 \end_inset
29362
29363
29364 \begin_inset LatexCommand \index{Linker documentation}
29365
29366 \end_inset
29367
29368  Relocating Linker
29369 \end_layout
29370
29371 \end_inset
29372 </cell>
29373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29374 \begin_inset Text
29375
29376 \begin_layout Standard
29377 sdcc/as/doc/asxhtm.html 
29378 \emph on
29379 \InsetSpace ~
29380 \InsetSpace ~
29381 \InsetSpace ~
29382
29383 \hfill
29384 online at:
29385 \emph default
29386
29387 \newline
29388
29389 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
29390
29391 \end_inset
29392
29393
29394 \end_layout
29395
29396 \end_inset
29397 </cell>
29398 </row>
29399 <row topline="true">
29400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29401 \begin_inset Text
29402
29403 \begin_layout Standard
29404 SDCC regression test
29405 \begin_inset LatexCommand \index{Regression test}
29406
29407 \end_inset
29408
29409
29410 \end_layout
29411
29412 \end_inset
29413 </cell>
29414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29415 \begin_inset Text
29416
29417 \begin_layout Standard
29418 sdcc/doc/test_suite_spec.pdf 
29419 \emph on
29420 \InsetSpace ~
29421 \InsetSpace ~
29422 \InsetSpace ~
29423
29424 \hfill
29425 online at:
29426 \emph default
29427
29428 \newline
29429
29430 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
29431
29432 \end_inset
29433
29434
29435 \end_layout
29436
29437 \end_inset
29438 </cell>
29439 </row>
29440 <row topline="true">
29441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29442 \begin_inset Text
29443
29444 \begin_layout Standard
29445 Various notes
29446 \end_layout
29447
29448 \end_inset
29449 </cell>
29450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29451 \begin_inset Text
29452
29453 \begin_layout Standard
29454 sdcc/doc/* 
29455 \emph on
29456 \InsetSpace ~
29457 \InsetSpace ~
29458 \InsetSpace ~
29459
29460 \hfill
29461 online at:
29462 \emph default
29463
29464 \newline
29465
29466 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
29467
29468 \end_inset
29469
29470
29471 \end_layout
29472
29473 \end_inset
29474 </cell>
29475 </row>
29476 <row topline="true">
29477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29478 \begin_inset Text
29479
29480 \begin_layout Standard
29481 Notes on debugging with SDCDB
29482 \begin_inset LatexCommand \index{SDCDB (debugger)}
29483
29484 \end_inset
29485
29486
29487 \end_layout
29488
29489 \end_inset
29490 </cell>
29491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29492 \begin_inset Text
29493
29494 \begin_layout Standard
29495 sdcc/debugger/README 
29496 \emph on
29497 \InsetSpace ~
29498 \InsetSpace ~
29499 \InsetSpace ~
29500
29501 \hfill
29502 online at
29503 \emph default
29504 :
29505 \newline
29506
29507 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
29508
29509 \end_inset
29510
29511
29512 \end_layout
29513
29514 \end_inset
29515 </cell>
29516 </row>
29517 <row topline="true">
29518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29519 \begin_inset Text
29520
29521 \begin_layout Standard
29522 uCsim
29523 \begin_inset LatexCommand \index{uCsim}
29524
29525 \end_inset
29526
29527  Software simulator for microcontrollers
29528 \end_layout
29529
29530 \end_inset
29531 </cell>
29532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29533 \begin_inset Text
29534
29535 \begin_layout Standard
29536
29537 \family roman
29538 \series medium
29539 \shape up
29540 \size normal
29541 \emph off
29542 \bar no
29543 \noun off
29544 \color none
29545 sdcc/sim/ucsim/doc
29546 \family default
29547 \series default
29548 \shape default
29549 \size default
29550 \emph default
29551 \bar default
29552 \noun default
29553 /index.html 
29554 \emph on
29555 \InsetSpace ~
29556 \InsetSpace ~
29557 \InsetSpace ~
29558
29559 \hfill
29560 online at:
29561 \emph default
29562
29563 \newline
29564
29565 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
29566
29567 \end_inset
29568
29569
29570 \end_layout
29571
29572 \end_inset
29573 </cell>
29574 </row>
29575 <row topline="true">
29576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29577 \begin_inset Text
29578
29579 \begin_layout Standard
29580 Temporary notes on the pic16
29581 \begin_inset LatexCommand \index{PIC16}
29582
29583 \end_inset
29584
29585  port
29586 \end_layout
29587
29588 \end_inset
29589 </cell>
29590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29591 \begin_inset Text
29592
29593 \begin_layout Standard
29594 sdcc/src/pic16/NOTES 
29595 \emph on
29596 \InsetSpace ~
29597 \InsetSpace ~
29598 \InsetSpace ~
29599
29600 \hfill
29601 online at:
29602 \newline
29603
29604 \emph default
29605
29606 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
29607
29608 \end_inset
29609
29610
29611 \end_layout
29612
29613 \end_inset
29614 </cell>
29615 </row>
29616 <row topline="true" bottomline="true">
29617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29618 \begin_inset Text
29619
29620 \begin_layout Standard
29621 SDCC internal documentation (debugging file format)
29622 \end_layout
29623
29624 \end_inset
29625 </cell>
29626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29627 \begin_inset Text
29628
29629 \begin_layout Standard
29630 sdcc/doc/
29631 \family roman
29632 \series medium
29633 \shape up
29634 \size normal
29635 \emph off
29636 \bar no
29637 \noun off
29638 \color none
29639 cdbfileformat.pd
29640 \family default
29641 \series default
29642 \shape default
29643 \size default
29644 \emph default
29645 \bar default
29646 \noun default
29647 f
29648 \emph on
29649  \InsetSpace ~
29650 \InsetSpace ~
29651 \InsetSpace ~
29652
29653 \hfill
29654 online at:
29655 \emph default
29656
29657 \newline
29658
29659 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
29660
29661 \end_inset
29662
29663
29664 \end_layout
29665
29666 \end_inset
29667 </cell>
29668 </row>
29669 </lyxtabular>
29670
29671 \end_inset
29672
29673
29674 \newline
29675
29676 \end_layout
29677
29678 \begin_layout Section
29679 Related open source tools
29680 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
29681
29682 \end_inset
29683
29684
29685 \begin_inset LatexCommand \index{Related tools}
29686
29687 \end_inset
29688
29689
29690 \end_layout
29691
29692 \begin_layout Standard
29693 \align left
29694 \begin_inset Tabular
29695 <lyxtabular version="3" rows="14" columns="3">
29696 <features>
29697 <column alignment="left" valignment="top" leftline="true" width="0pt">
29698 <column alignment="block" valignment="top" leftline="true" width="30line%">
29699 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29700 <row topline="true" bottomline="true">
29701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29702 \begin_inset Text
29703
29704 \begin_layout Standard
29705
29706 \series bold
29707 Name
29708 \end_layout
29709
29710 \end_inset
29711 </cell>
29712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29713 \begin_inset Text
29714
29715 \begin_layout Standard
29716
29717 \series bold
29718 Purpose
29719 \end_layout
29720
29721 \end_inset
29722 </cell>
29723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29724 \begin_inset Text
29725
29726 \begin_layout Standard
29727
29728 \series bold
29729 Where to get
29730 \end_layout
29731
29732 \end_inset
29733 </cell>
29734 </row>
29735 <row topline="true">
29736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29737 \begin_inset Text
29738
29739 \begin_layout Standard
29740 gpsim
29741 \begin_inset LatexCommand \index{gpsim (pic simulator)}
29742
29743 \end_inset
29744
29745
29746 \end_layout
29747
29748 \end_inset
29749 </cell>
29750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29751 \begin_inset Text
29752
29753 \begin_layout Standard
29754 PIC simulator
29755 \end_layout
29756
29757 \end_inset
29758 </cell>
29759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29760 \begin_inset Text
29761
29762 \begin_layout Standard
29763 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
29764
29765 \end_inset
29766
29767
29768 \end_layout
29769
29770 \end_inset
29771 </cell>
29772 </row>
29773 <row topline="true">
29774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29775 \begin_inset Text
29776
29777 \begin_layout Standard
29778 gputils
29779 \begin_inset LatexCommand \index{gputils (pic tools)}
29780
29781 \end_inset
29782
29783
29784 \end_layout
29785
29786 \end_inset
29787 </cell>
29788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29789 \begin_inset Text
29790
29791 \begin_layout Standard
29792 GNU PIC utilities
29793 \end_layout
29794
29795 \end_inset
29796 </cell>
29797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29798 \begin_inset Text
29799
29800 \begin_layout Standard
29801 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
29802
29803 \end_inset
29804
29805
29806 \end_layout
29807
29808 \end_inset
29809 </cell>
29810 </row>
29811 <row topline="true">
29812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29813 \begin_inset Text
29814
29815 \begin_layout Standard
29816 flP5
29817 \end_layout
29818
29819 \end_inset
29820 </cell>
29821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29822 \begin_inset Text
29823
29824 \begin_layout Standard
29825 PIC programmer
29826 \end_layout
29827
29828 \end_inset
29829 </cell>
29830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29831 \begin_inset Text
29832
29833 \begin_layout Standard
29834 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
29835
29836 \end_inset
29837
29838
29839 \end_layout
29840
29841 \end_inset
29842 </cell>
29843 </row>
29844 <row topline="true">
29845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29846 \begin_inset Text
29847
29848 \begin_layout Standard
29849 ec2drv/newcdb
29850 \end_layout
29851
29852 \end_inset
29853 </cell>
29854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29855 \begin_inset Text
29856
29857 \begin_layout Standard
29858 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
29859  (Unix only)
29860 \end_layout
29861
29862 \end_inset
29863 </cell>
29864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29865 \begin_inset Text
29866
29867 \begin_layout Standard
29868 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
29869
29870 \end_inset
29871
29872
29873 \end_layout
29874
29875 \end_inset
29876 </cell>
29877 </row>
29878 <row topline="true">
29879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29880 \begin_inset Text
29881
29882 \begin_layout Standard
29883 indent
29884 \begin_inset LatexCommand \index{indent (source formatting tool)}
29885
29886 \end_inset
29887
29888
29889 \end_layout
29890
29891 \end_inset
29892 </cell>
29893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29894 \begin_inset Text
29895
29896 \begin_layout Standard
29897 Formats C source - Master of the white spaces
29898 \end_layout
29899
29900 \end_inset
29901 </cell>
29902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29903 \begin_inset Text
29904
29905 \begin_layout Standard
29906 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
29907
29908 \end_inset
29909
29910
29911 \end_layout
29912
29913 \end_inset
29914 </cell>
29915 </row>
29916 <row topline="true">
29917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29918 \begin_inset Text
29919
29920 \begin_layout Standard
29921 srecord
29922 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
29923
29924 \end_inset
29925
29926
29927 \end_layout
29928
29929 \end_inset
29930 </cell>
29931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29932 \begin_inset Text
29933
29934 \begin_layout Standard
29935 Object file conversion, checksumming, ...
29936 \end_layout
29937
29938 \end_inset
29939 </cell>
29940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29941 \begin_inset Text
29942
29943 \begin_layout Standard
29944 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
29945
29946 \end_inset
29947
29948
29949 \end_layout
29950
29951 \end_inset
29952 </cell>
29953 </row>
29954 <row topline="true">
29955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29956 \begin_inset Text
29957
29958 \begin_layout Standard
29959 objdump
29960 \begin_inset LatexCommand \index{objdump (tool)}
29961
29962 \end_inset
29963
29964
29965 \end_layout
29966
29967 \end_inset
29968 </cell>
29969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29970 \begin_inset Text
29971
29972 \begin_layout Standard
29973 Object file conversion, ...
29974 \end_layout
29975
29976 \end_inset
29977 </cell>
29978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29979 \begin_inset Text
29980
29981 \begin_layout Standard
29982 Part of binutils (should be there anyway)
29983 \end_layout
29984
29985 \end_inset
29986 </cell>
29987 </row>
29988 <row topline="true">
29989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29990 \begin_inset Text
29991
29992 \begin_layout Standard
29993 cmon51
29994 \end_layout
29995
29996 \end_inset
29997 </cell>
29998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29999 \begin_inset Text
30000
30001 \begin_layout Standard
30002 8051 monitor (hex up-/download, single step, disassemble)
30003 \end_layout
30004
30005 \end_inset
30006 </cell>
30007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30008 \begin_inset Text
30009
30010 \begin_layout Standard
30011 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30012
30013 \end_inset
30014
30015
30016 \end_layout
30017
30018 \end_inset
30019 </cell>
30020 </row>
30021 <row topline="true">
30022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30023 \begin_inset Text
30024
30025 \begin_layout Standard
30026 doxygen
30027 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30028
30029 \end_inset
30030
30031
30032 \end_layout
30033
30034 \end_inset
30035 </cell>
30036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30037 \begin_inset Text
30038
30039 \begin_layout Standard
30040 Source code documentation system
30041 \end_layout
30042
30043 \end_inset
30044 </cell>
30045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30046 \begin_inset Text
30047
30048 \begin_layout Standard
30049 \begin_inset LatexCommand \url{http://www.doxygen.org}
30050
30051 \end_inset
30052
30053
30054 \end_layout
30055
30056 \end_inset
30057 </cell>
30058 </row>
30059 <row topline="true">
30060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30061 \begin_inset Text
30062
30063 \begin_layout Standard
30064 kdevelop
30065 \end_layout
30066
30067 \end_inset
30068 </cell>
30069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30070 \begin_inset Text
30071
30072 \begin_layout Standard
30073 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30074 \end_layout
30075
30076 \end_inset
30077 </cell>
30078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30079 \begin_inset Text
30080
30081 \begin_layout Standard
30082 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30083
30084 \end_inset
30085
30086
30087 \end_layout
30088
30089 \end_inset
30090 </cell>
30091 </row>
30092 <row topline="true">
30093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30094 \begin_inset Text
30095
30096 \begin_layout Standard
30097 paulmon
30098 \end_layout
30099
30100 \end_inset
30101 </cell>
30102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30103 \begin_inset Text
30104
30105 \begin_layout Standard
30106 8051 monitor (hex up-/download, single step, disassemble)
30107 \end_layout
30108
30109 \end_inset
30110 </cell>
30111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30112 \begin_inset Text
30113
30114 \begin_layout Standard
30115 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30116
30117 \end_inset
30118
30119
30120 \end_layout
30121
30122 \end_inset
30123 </cell>
30124 </row>
30125 <row topline="true">
30126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30127 \begin_inset Text
30128
30129 \begin_layout Standard
30130 splint
30131 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30132
30133 \end_inset
30134
30135
30136 \end_layout
30137
30138 \end_inset
30139 </cell>
30140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30141 \begin_inset Text
30142
30143 \begin_layout Standard
30144 Statically checks c sources (see 
30145 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30146
30147 \end_inset
30148
30149 )
30150 \end_layout
30151
30152 \end_inset
30153 </cell>
30154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30155 \begin_inset Text
30156
30157 \begin_layout Standard
30158 \begin_inset LatexCommand \url{http://www.splint.org}
30159
30160 \end_inset
30161
30162
30163 \end_layout
30164
30165 \end_inset
30166 </cell>
30167 </row>
30168 <row topline="true" bottomline="true">
30169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30170 \begin_inset Text
30171
30172 \begin_layout Standard
30173 ddd
30174 \begin_inset LatexCommand \index{DDD (debugger)}
30175
30176 \end_inset
30177
30178
30179 \end_layout
30180
30181 \end_inset
30182 </cell>
30183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30184 \begin_inset Text
30185
30186 \begin_layout Standard
30187 Debugger, serves nicely as GUI to SDCDB
30188 \begin_inset LatexCommand \index{SDCDB (debugger)}
30189
30190 \end_inset
30191
30192  (Unix only)
30193 \end_layout
30194
30195 \end_inset
30196 </cell>
30197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30198 \begin_inset Text
30199
30200 \begin_layout Standard
30201 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30202
30203 \end_inset
30204
30205
30206 \end_layout
30207
30208 \end_inset
30209 </cell>
30210 </row>
30211 </lyxtabular>
30212
30213 \end_inset
30214
30215
30216 \newline
30217
30218 \end_layout
30219
30220 \begin_layout Section
30221 Related documentation / recommended reading
30222 \end_layout
30223
30224 \begin_layout Standard
30225 \align left
30226 \begin_inset Tabular
30227 <lyxtabular version="3" rows="7" columns="3">
30228 <features>
30229 <column alignment="left" valignment="top" leftline="true" width="0pt">
30230 <column alignment="left" valignment="top" leftline="true" width="0">
30231 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30232 <row topline="true" bottomline="true">
30233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30234 \begin_inset Text
30235
30236 \begin_layout Standard
30237
30238 \series bold
30239 Name
30240 \end_layout
30241
30242 \end_inset
30243 </cell>
30244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30245 \begin_inset Text
30246
30247 \begin_layout Standard
30248
30249 \series bold
30250 Subject / Title
30251 \end_layout
30252
30253 \end_inset
30254 </cell>
30255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30256 \begin_inset Text
30257
30258 \begin_layout Standard
30259
30260 \series bold
30261 Where to get
30262 \end_layout
30263
30264 \end_inset
30265 </cell>
30266 </row>
30267 <row topline="true">
30268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30269 \begin_inset Text
30270
30271 \begin_layout Standard
30272
30273 \family roman
30274 \series medium
30275 \shape up
30276 \size normal
30277 \emph off
30278 \bar no
30279 \noun off
30280 \color none
30281 c-refcard.pdf
30282 \end_layout
30283
30284 \end_inset
30285 </cell>
30286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30287 \begin_inset Text
30288
30289 \begin_layout Standard
30290 C Reference Card
30291 \begin_inset LatexCommand \index{C Reference card}
30292
30293 \end_inset
30294
30295 , 2 pages
30296 \end_layout
30297
30298 \end_inset
30299 </cell>
30300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30301 \begin_inset Text
30302
30303 \begin_layout Standard
30304 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30305
30306 \end_inset
30307
30308
30309 \end_layout
30310
30311 \end_inset
30312 </cell>
30313 </row>
30314 <row topline="true">
30315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30316 \begin_inset Text
30317
30318 \begin_layout Standard
30319 c-faq
30320 \end_layout
30321
30322 \end_inset
30323 </cell>
30324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30325 \begin_inset Text
30326
30327 \begin_layout Standard
30328 C-FAQ
30329 \begin_inset LatexCommand \index{C FAQ}
30330
30331 \end_inset
30332
30333
30334 \end_layout
30335
30336 \end_inset
30337 </cell>
30338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30339 \begin_inset Text
30340
30341 \begin_layout Standard
30342 \begin_inset LatexCommand \url{http://www.c-faq.com}
30343
30344 \end_inset
30345
30346
30347 \end_layout
30348
30349 \end_inset
30350 </cell>
30351 </row>
30352 <row topline="true">
30353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30354 \begin_inset Text
30355
30356 \begin_layout Standard
30357 ISO/IEC 9899:TC2
30358 \end_layout
30359
30360 \end_inset
30361 </cell>
30362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30363 \begin_inset Text
30364
30365 \begin_layout Standard
30366 \begin_inset Quotes sld
30367 \end_inset
30368
30369 C-Standard
30370 \begin_inset Quotes srd
30371 \end_inset
30372
30373
30374 \end_layout
30375
30376 \end_inset
30377 </cell>
30378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30379 \begin_inset Text
30380
30381 \begin_layout Standard
30382
30383 \size footnotesize
30384 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30385
30386 \end_inset
30387
30388
30389 \end_layout
30390
30391 \end_inset
30392 </cell>
30393 </row>
30394 <row topline="true">
30395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30396 \begin_inset Text
30397
30398 \begin_layout Standard
30399 ISO/IEC DTR 18037
30400 \end_layout
30401
30402 \end_inset
30403 </cell>
30404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30405 \begin_inset Text
30406
30407 \begin_layout Standard
30408 \begin_inset Quotes sld
30409 \end_inset
30410
30411 Extensions for Embedded C
30412 \begin_inset Quotes srd
30413 \end_inset
30414
30415
30416 \end_layout
30417
30418 \end_inset
30419 </cell>
30420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30421 \begin_inset Text
30422
30423 \begin_layout Standard
30424
30425 \size footnotesize
30426 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
30427
30428 \end_inset
30429
30430
30431 \end_layout
30432
30433 \end_inset
30434 </cell>
30435 </row>
30436 <row topline="true">
30437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30438 \begin_inset Text
30439
30440 \begin_layout Standard
30441
30442 \end_layout
30443
30444 \end_inset
30445 </cell>
30446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30447 \begin_inset Text
30448
30449 \begin_layout Standard
30450 Latest datasheet of target CPU
30451 \end_layout
30452
30453 \end_inset
30454 </cell>
30455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30456 \begin_inset Text
30457
30458 \begin_layout Standard
30459 vendor
30460 \end_layout
30461
30462 \end_inset
30463 </cell>
30464 </row>
30465 <row topline="true" bottomline="true">
30466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30467 \begin_inset Text
30468
30469 \begin_layout Standard
30470
30471 \end_layout
30472
30473 \end_inset
30474 </cell>
30475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30476 \begin_inset Text
30477
30478 \begin_layout Standard
30479 Revision history of datasheet
30480 \end_layout
30481
30482 \end_inset
30483 </cell>
30484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30485 \begin_inset Text
30486
30487 \begin_layout Standard
30488 vendor
30489 \end_layout
30490
30491 \end_inset
30492 </cell>
30493 </row>
30494 </lyxtabular>
30495
30496 \end_inset
30497
30498
30499 \newline
30500
30501 \end_layout
30502
30503 \begin_layout Section
30504 Application notes specifically for SDCC
30505 \end_layout
30506
30507 \begin_layout Standard
30508 SDCC makes no claims about the completeness of this list and about up-to-datenes
30509 s or correctness of the application notes
30510 \begin_inset LatexCommand \index{Application notes}
30511
30512 \end_inset
30513
30514 .
30515 \end_layout
30516
30517 \begin_layout Standard
30518 \align left
30519
30520 \size footnotesize
30521 \begin_inset Tabular
30522 <lyxtabular version="3" rows="7" columns="3">
30523 <features>
30524 <column alignment="block" valignment="top" leftline="true" width="17col%">
30525 <column alignment="block" valignment="top" leftline="true" width="27col%">
30526 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
30527 <row topline="true" bottomline="true">
30528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30529 \begin_inset Text
30530
30531 \begin_layout Standard
30532
30533 \series bold
30534 \size footnotesize
30535 Vendor
30536 \end_layout
30537
30538 \end_inset
30539 </cell>
30540 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
30541 \begin_inset Text
30542
30543 \begin_layout Standard
30544
30545 \series bold
30546 \size footnotesize
30547 Subject / Title
30548 \end_layout
30549
30550 \end_inset
30551 </cell>
30552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30553 \begin_inset Text
30554
30555 \begin_layout Standard
30556
30557 \series bold
30558 \size footnotesize
30559 Where to get
30560 \end_layout
30561
30562 \end_inset
30563 </cell>
30564 </row>
30565 <row topline="true">
30566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30567 \begin_inset Text
30568
30569 \begin_layout Standard
30570
30571 \size footnotesize
30572 Maxim / Dallas
30573 \end_layout
30574
30575 \end_inset
30576 </cell>
30577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30578 \begin_inset Text
30579
30580 \begin_layout Standard
30581
30582 \size footnotesize
30583 Using the SDCC Compiler for the DS80C400
30584 \begin_inset LatexCommand \index{DS80C400}
30585
30586 \end_inset
30587
30588
30589 \end_layout
30590
30591 \end_inset
30592 </cell>
30593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30594 \begin_inset Text
30595
30596 \begin_layout Standard
30597
30598 \size footnotesize
30599 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
30600
30601 \end_inset
30602
30603
30604 \end_layout
30605
30606 \end_inset
30607 </cell>
30608 </row>
30609 <row topline="true">
30610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30611 \begin_inset Text
30612
30613 \begin_layout Standard
30614
30615 \size footnotesize
30616 Maxim / Dallas
30617 \end_layout
30618
30619 \end_inset
30620 </cell>
30621 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
30622 \begin_inset Text
30623
30624 \begin_layout Standard
30625
30626 \size footnotesize
30627 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
30628 \begin_inset LatexCommand \index{DS89C4x0}
30629
30630 \end_inset
30631
30632  Family of Microcontrollers
30633 \end_layout
30634
30635 \end_inset
30636 </cell>
30637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30638 \begin_inset Text
30639
30640 \begin_layout Standard
30641
30642 \size footnotesize
30643 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
30644
30645 \end_inset
30646
30647
30648 \end_layout
30649
30650 \end_inset
30651 </cell>
30652 </row>
30653 <row topline="true">
30654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30655 \begin_inset Text
30656
30657 \begin_layout Standard
30658
30659 \size footnotesize
30660 Silicon Laboratories / Cygnal
30661 \end_layout
30662
30663 \end_inset
30664 </cell>
30665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30666 \begin_inset Text
30667
30668 \begin_layout Standard
30669
30670 \size footnotesize
30671 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
30672 \begin_inset LatexCommand \index{IDE}
30673
30674 \end_inset
30675
30676
30677 \end_layout
30678
30679 \end_inset
30680 </cell>
30681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30682 \begin_inset Text
30683
30684 \begin_layout Standard
30685
30686 \size footnotesize
30687 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
30688
30689 \end_inset
30690
30691
30692 \end_layout
30693
30694 \end_inset
30695 </cell>
30696 </row>
30697 <row topline="true">
30698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30699 \begin_inset Text
30700
30701 \begin_layout Standard
30702
30703 \size footnotesize
30704 Ramtron / Goal Semiconductor
30705 \end_layout
30706
30707 \end_inset
30708 </cell>
30709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30710 \begin_inset Text
30711
30712 \begin_layout Standard
30713
30714 \size footnotesize
30715 Interfacing SDCC to Syn and Textpad
30716 \end_layout
30717
30718 \end_inset
30719 </cell>
30720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30721 \begin_inset Text
30722
30723 \begin_layout Standard
30724
30725 \size footnotesize
30726 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
30727
30728 \end_inset
30729
30730
30731 \end_layout
30732
30733 \end_inset
30734 </cell>
30735 </row>
30736 <row topline="true">
30737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30738 \begin_inset Text
30739
30740 \begin_layout Standard
30741
30742 \size footnotesize
30743 Ramtron / Goal Semiconductor
30744 \end_layout
30745
30746 \end_inset
30747 </cell>
30748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30749 \begin_inset Text
30750
30751 \begin_layout Standard
30752
30753 \size footnotesize
30754 Installing and Configuring SDCC and Crimson Editor 
30755 \end_layout
30756
30757 \end_inset
30758 </cell>
30759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30760 \begin_inset Text
30761
30762 \begin_layout Standard
30763
30764 \size footnotesize
30765 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
30766
30767 \end_inset
30768
30769
30770 \end_layout
30771
30772 \end_inset
30773 </cell>
30774 </row>
30775 <row topline="true" bottomline="true">
30776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30777 \begin_inset Text
30778
30779 \begin_layout Standard
30780
30781 \size footnotesize
30782 Texas Instruments
30783 \end_layout
30784
30785 \end_inset
30786 </cell>
30787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30788 \begin_inset Text
30789
30790 \begin_layout Standard
30791
30792 \size footnotesize
30793 MSC12xx Programming with SDCC
30794 \end_layout
30795
30796 \end_inset
30797 </cell>
30798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30799 \begin_inset Text
30800
30801 \begin_layout Standard
30802
30803 \size footnotesize
30804 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
30805
30806 \end_inset
30807
30808
30809 \end_layout
30810
30811 \end_inset
30812 </cell>
30813 </row>
30814 </lyxtabular>
30815
30816 \end_inset
30817
30818
30819 \end_layout
30820
30821 \begin_layout Section
30822 Some Questions
30823 \end_layout
30824
30825 \begin_layout Standard
30826 Some questions answered, some pointers given - it might be time to in turn
30827  ask 
30828 \emph on
30829 you
30830 \emph default
30831  some questions: 
30832 \end_layout
30833
30834 \begin_layout Itemize
30835 can you solve your project with the selected microcontroller? Would you
30836  find out early or rather late that your target is too small/slow/whatever?
30837  Can you switch to a slightly better device if it doesn't fit?
30838 \end_layout
30839
30840 \begin_layout Itemize
30841 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
30842  and/or another programming language be more adequate? Would an operating
30843  system on the target device help?
30844 \end_layout
30845
30846 \begin_layout Itemize
30847 if you solved the problem, will the marketing department be happy?
30848 \end_layout
30849
30850 \begin_layout Itemize
30851 if the marketing department is happy, will customers be happy?
30852 \end_layout
30853
30854 \begin_layout Itemize
30855 if you're the project manager, marketing department and maybe even the customer
30856  in one person, have you tried to see the project from the outside?
30857 \end_layout
30858
30859 \begin_layout Itemize
30860 is the project done if you think it is done? Or is just that other interface/pro
30861 tocol/feature/configuration/option missing? How about website, manual(s),
30862  internationali(z|s)ation, packaging, labels, 2nd source for components,
30863  electromagnetic compatability/interference, documentation for production,
30864  production test software, update mechanism, patent issues?
30865 \end_layout
30866
30867 \begin_layout Itemize
30868 is your project adequately positioned in that magic triangle: fame, fortune,
30869  fun?
30870 \end_layout
30871
30872 \begin_layout Standard
30873 Maybe not all answers to these questions are known and some answers may
30874  even be 
30875 \emph on
30876 no
30877 \emph default
30878 , nevertheless knowing these questions may help you to avoid burnout
30879 \begin_inset Foot
30880 status open
30881
30882 \begin_layout Standard
30883 burnout is bad for electronic devices, programmers and motorcycle tyres
30884 \end_layout
30885
30886 \end_inset
30887
30888 .
30889  Chances are you didn't want to hear some of them...
30890 \end_layout
30891
30892 \begin_layout Chapter
30893 Support
30894 \begin_inset LatexCommand \index{Support}
30895
30896 \end_inset
30897
30898
30899 \end_layout
30900
30901 \begin_layout Standard
30902 SDCC has grown to be a large project.
30903  The compiler alone (without the preprocessor, assembler and linker) is
30904  well over 150,000 lines of code (blank stripped).
30905  The open source nature of this project is a key to its continued growth
30906  and support.
30907  You gain the benefit and support of many active software developers and
30908  end users.
30909  Is SDCC perfect? No, that's why we need your help.
30910  The developers take pride in fixing reported bugs.
30911  You can help by reporting the bugs and helping other SDCC users.
30912  There are lots of ways to contribute, and we encourage you to take part
30913  in making SDCC a great software package.
30914  
30915 \end_layout
30916
30917 \begin_layout Standard
30918 The SDCC project is hosted on the SDCC sourceforge site at 
30919 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
30920
30921 \end_inset
30922
30923 .
30924  You'll find the complete set of mailing lists
30925 \begin_inset LatexCommand \index{Mailing list(s)}
30926
30927 \end_inset
30928
30929 , forums, bug reporting system, patch submission
30930 \begin_inset LatexCommand \index{Patch submission}
30931
30932 \end_inset
30933
30934  system, download
30935 \begin_inset LatexCommand \index{download}
30936
30937 \end_inset
30938
30939  area and Subversion code repository
30940 \begin_inset LatexCommand \index{Subversion code repository}
30941
30942 \end_inset
30943
30944  there.
30945 \end_layout
30946
30947 \begin_layout Section
30948 Reporting Bugs
30949 \begin_inset LatexCommand \index{Bug reporting}
30950
30951 \end_inset
30952
30953
30954 \begin_inset LatexCommand \index{Reporting bugs}
30955
30956 \end_inset
30957
30958
30959 \end_layout
30960
30961 \begin_layout Standard
30962 The recommended way of reporting bugs is using the infrastructure of the
30963  sourceforge site.
30964  You can follow the status of bug reports there and have an overview about
30965  the known bugs.
30966 \end_layout
30967
30968 \begin_layout Standard
30969 Bug reports are automatically forwarded to the developer mailing list and
30970  will be fixed ASAP.
30971  When reporting a bug, it is very useful to include a small test program
30972  (the smaller the better) which reproduces the problem.
30973  If you can isolate the problem by looking at the generated assembly code,
30974  this can be very helpful.
30975  Compiling your program with the -
30976 \begin_inset ERT
30977 status collapsed
30978
30979 \begin_layout Standard
30980
30981
30982 \backslash
30983 /
30984 \end_layout
30985
30986 \end_inset
30987
30988 -dumpall
30989 \begin_inset LatexCommand \index{-\/-dumpall}
30990
30991 \end_inset
30992
30993  option can sometimes be useful in locating optimization problems.
30994  When reporting a bug please make sure you:
30995 \end_layout
30996
30997 \begin_layout Enumerate
30998 Attach the code you are compiling with SDCC.
30999  
31000 \end_layout
31001
31002 \begin_layout Enumerate
31003 Specify the exact command you use to run SDCC, or attach your Makefile.
31004  
31005 \end_layout
31006
31007 \begin_layout Enumerate
31008 Specify the SDCC version (type "
31009 \family sans
31010 \series bold
31011 sdcc -v
31012 \family default
31013 \series default
31014 "), your platform, and operating system.
31015  
31016 \end_layout
31017
31018 \begin_layout Enumerate
31019 Provide an exact copy of any error message or incorrect output.
31020  
31021 \end_layout
31022
31023 \begin_layout Enumerate
31024 Put something meaningful in the subject of your message.
31025 \end_layout
31026
31027 \begin_layout Standard
31028 Please attempt to include these 5 important parts, as applicable, in all
31029  requests for support or when reporting any problems or bugs with SDCC.
31030  Though this will make your message lengthy, it will greatly improve your
31031  chance that SDCC users and developers will be able to help you.
31032  Some SDCC developers are frustrated by bug reports without code provided
31033  that they can use to reproduce and ultimately fix the problem, so please
31034  be sure to provide sample code if you are reporting a bug! 
31035 \end_layout
31036
31037 \begin_layout Standard
31038 Please have a short check that you are using a recent version of SDCC and
31039  the bug is not yet known.
31040  This is the link for reporting bugs: 
31041 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31042
31043 \end_inset
31044
31045 .
31046  With SDCC on average having more than 200 downloads
31047 \begin_inset LatexCommand \index{download}
31048
31049 \end_inset
31050
31051  on sourceforge per day
31052 \begin_inset Foot
31053 status open
31054
31055 \begin_layout Standard
31056 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31057  between 2002 and 2005.
31058  This does not include other methods of distribution.
31059 \end_layout
31060
31061 \end_inset
31062
31063  there must be some users.
31064  So it's not exactly easy to find a new bug.
31065  If you find one we need it: 
31066 \emph on
31067 reporting bugs is good
31068 \emph default
31069 .
31070 \end_layout
31071
31072 \begin_layout Section
31073 Requesting Features
31074 \begin_inset LatexCommand \label{sub:Requesting-Features}
31075
31076 \end_inset
31077
31078
31079 \begin_inset LatexCommand \index{Feature request}
31080
31081 \end_inset
31082
31083
31084 \begin_inset LatexCommand \index{Requesting features}
31085
31086 \end_inset
31087
31088
31089 \end_layout
31090
31091 \begin_layout Standard
31092 Like bug reports feature requests are forwarded to the developer mailing
31093  list.
31094  This is the link for requesting features: 
31095 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31096
31097 \end_inset
31098
31099 .
31100 \end_layout
31101
31102 \begin_layout Section
31103 Submitting patches
31104 \end_layout
31105
31106 \begin_layout Standard
31107 Like bug reports contributed patches are forwarded to the developer mailing
31108  list.
31109  This is the link for submitting patches
31110 \begin_inset LatexCommand \index{Patch submission}
31111
31112 \end_inset
31113
31114
31115 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31116
31117 \end_inset
31118
31119 .
31120 \end_layout
31121
31122 \begin_layout Standard
31123 You need to specify some parameters to the 
31124 \family typewriter
31125 diff
31126 \family default
31127  command for the patches to be useful.
31128  If you modified more than one file a patch created f.e.
31129  with 
31130 \family sans
31131 \series bold
31132
31133 \begin_inset Quotes sld
31134 \end_inset
31135
31136 diff -Naur unmodified_directory modified_directory >my_changes.patch
31137 \begin_inset Quotes srd
31138 \end_inset
31139
31140
31141 \family default
31142 \series default
31143  will be fine, otherwise 
31144 \family sans
31145 \series bold
31146
31147 \begin_inset Quotes sld
31148 \end_inset
31149
31150 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31151 \begin_inset Quotes srd
31152 \end_inset
31153
31154
31155 \series default
31156  
31157 \family default
31158 will do.
31159 \end_layout
31160
31161 \begin_layout Section
31162 Getting Help
31163 \end_layout
31164
31165 \begin_layout Standard
31166 These links should take you directly to the 
31167 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31168
31169 \end_inset
31170
31171
31172 \begin_inset Foot
31173 status open
31174
31175 \begin_layout Standard
31176 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31177  automated messages (mid 2003)
31178 \end_layout
31179
31180 \end_inset
31181
31182  and the 
31183 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31184
31185 \end_inset
31186
31187 , lists
31188 \begin_inset LatexCommand \index{Mailing list(s)}
31189
31190 \end_inset
31191
31192  and forums are archived and searchable so if you are lucky someone already
31193  had a similar problem.
31194  While mails to the lists themselves are delivered promptly their web front
31195  end on sourceforge sometimes shows a severe time lag (up to several weeks),
31196  if you're seriously using SDCC please consider subscribing to the lists.
31197 \end_layout
31198
31199 \begin_layout Section
31200 ChangeLog
31201 \end_layout
31202
31203 \begin_layout Standard
31204 You can follow the status of the Subversion version
31205 \begin_inset LatexCommand \index{version}
31206
31207 \end_inset
31208
31209  of SDCC by watching the Changelog
31210 \begin_inset LatexCommand \index{Changelog}
31211
31212 \end_inset
31213
31214  in the Subversion repository
31215 \size footnotesize
31216  
31217 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31218
31219 \end_inset
31220
31221 .
31222 \end_layout
31223
31224 \begin_layout Section
31225 Subversion Source Code Repository
31226 \end_layout
31227
31228 \begin_layout Standard
31229 The output of 
31230 \family sans
31231 \series bold
31232 sdcc --version
31233 \family default
31234 \series default
31235  or the filenames of the snapshot versions of SDCC include date and its
31236  Subversion
31237 \begin_inset LatexCommand \index{Subversion code repository}
31238
31239 \end_inset
31240
31241  number.
31242  Subversion allows to download the source of recent or previous versions
31243  
31244 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31245
31246 \end_inset
31247
31248  (by number or by date).
31249  An on-line source code browser and detailled instructions are also available
31250  there.
31251  SDCC versions starting from 1999 up to now are available (currently the
31252  versions prior to the conversion from cvs
31253 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31254
31255 \end_inset
31256
31257  to Subversion (April 2006) are either by accessible by Subversion or by
31258  cvs).
31259 \end_layout
31260
31261 \begin_layout Section
31262 Release policy
31263 \begin_inset LatexCommand \index{Release policy}
31264
31265 \end_inset
31266
31267
31268 \end_layout
31269
31270 \begin_layout Standard
31271 Historically there often were long delays between official releases and
31272  the sourceforge download area tends to get not updated at all.
31273  Excuses in the past might have referred to problems with live range analysis,
31274  but as this was fixed a while ago, the current problem is that another
31275  excuse has to be found.
31276  Kidding aside, we have to get better there! On the other hand there are
31277  daily snapshots available at 
31278 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31279
31280 \end_inset
31281
31282 , and you can always build the very last version (hopefully with many bugs
31283  fixed, and features added) from the source code available at 
31284 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31285
31286 \end_inset
31287
31288 .
31289  A release wiki
31290 \begin_inset LatexCommand \index{wiki}
31291
31292 \end_inset
31293
31294
31295 \begin_inset LatexCommand \index{Release wiki}
31296
31297 \end_inset
31298
31299  at 
31300 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31301
31302 \end_inset
31303
31304  also holds some information about past and future releases.
31305 \end_layout
31306
31307 \begin_layout Section
31308 Examples
31309 \begin_inset LatexCommand \index{Examples}
31310
31311 \end_inset
31312
31313
31314 \end_layout
31315
31316 \begin_layout Standard
31317 You'll find some small examples in the directory 
31318 \emph on
31319 sdcc/device/examples/.
31320  
31321 \emph default
31322 More examples and libraries are available at
31323 \emph on
31324  The SDCC Open Knowledge Resource 
31325 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31326
31327 \end_inset
31328
31329  
31330 \emph default
31331 web site or at 
31332 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31333
31334 \end_inset
31335
31336 .
31337 \end_layout
31338
31339 \begin_layout Standard
31340 \begin_inset Note Note
31341 status collapsed
31342
31343 \begin_layout Standard
31344 I did insert a reference to Paul's web site here although it seems rather
31345  dedicated to a specific 8032 board (I think it's okay because it f.e.
31346  shows LCD/Harddisc interface and has a free 8051 monitor.
31347  Independent 8032 board vendors face hard competition of heavily subsidized
31348  development boards anyway).
31349 \end_layout
31350
31351 \begin_layout Standard
31352 Maybe we should include some links to real world applications.
31353  Preferably pointer to pointers (one for each architecture) so this stays
31354  manageable here?
31355 \end_layout
31356
31357 \end_inset
31358
31359
31360 \end_layout
31361
31362 \begin_layout Section
31363 Quality control
31364 \begin_inset LatexCommand \label{sec:Quality-control}
31365
31366 \end_inset
31367
31368
31369 \begin_inset LatexCommand \index{Quality control}
31370
31371 \end_inset
31372
31373
31374 \end_layout
31375
31376 \begin_layout Standard
31377 The compiler is passed through snaphot build compile and build checks.
31378  The so called 
31379 \shape italic
31380 regression tests
31381 \shape default
31382
31383 \begin_inset LatexCommand \index{Regression test}
31384
31385 \end_inset
31386
31387  check that SDCC itself compiles flawlessly on several host platforms (i386,
31388  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
31389  the quality of the code generated by SDCC by running the code for several
31390  target platforms through simulators.
31391  The regression test suite comprises more than 100 files which expand to
31392  more than 500 test cases which include more than 4500 tests.
31393  The results of these tests are published daily on SDCC's snapshot page
31394  (click on the red or green symbols on the right side of 
31395 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
31396
31397 \end_inset
31398
31399 ).
31400 \end_layout
31401
31402 \begin_layout Standard
31403 There is a separate document 
31404 \shape italic
31405 test_suite.pdf 
31406 \begin_inset LatexCommand \index{Test suite}
31407
31408 \end_inset
31409
31410
31411 \shape default
31412  
31413 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31414
31415 \end_inset
31416
31417  about the regression test suite.
31418 \end_layout
31419
31420 \begin_layout Standard
31421 You'll find the test code in the directory 
31422 \shape italic
31423 sdcc/support/regression
31424 \shape default
31425 .
31426  You can run these tests manually by running 
31427 \family sans
31428 make
31429 \family default
31430  in this directory (or f.e.
31431  
31432 \family sans
31433 \series bold
31434
31435 \begin_inset Quotes sld
31436 \end_inset
31437
31438 make test-mcs51
31439 \begin_inset Quotes srd
31440 \end_inset
31441
31442
31443 \family default
31444 \series default
31445  if you don't want to run the complete tests).
31446  The test code might also be interesting if you want to look for examples
31447 \begin_inset LatexCommand \index{Examples}
31448
31449 \end_inset
31450
31451  checking corner cases of SDCC or if you plan to submit patches
31452 \begin_inset LatexCommand \index{Patch submission}
31453
31454 \end_inset
31455
31456 .
31457 \end_layout
31458
31459 \begin_layout Standard
31460 The 14bit pic port uses a different set of regression tests 
31461 \begin_inset LatexCommand \index{Regression test (PIC14)}
31462
31463 \end_inset
31464
31465 , you'll find them in the directory 
31466 \shape italic
31467 sdcc/src/regression
31468 \shape default
31469 .
31470 \end_layout
31471
31472 \begin_layout Section
31473 Use of SDCC in Education
31474 \end_layout
31475
31476 \begin_layout Standard
31477 In short: 
31478 \emph on
31479 highly
31480 \emph default
31481  encouraged
31482 \begin_inset Foot
31483 status open
31484
31485 \begin_layout Standard
31486 the phrase "use in education" might evoke the association "
31487 \emph on
31488 only
31489 \emph default
31490  fit for use in education".
31491  This connotation is not intended but nevertheless risked as the licensing
31492  of SDCC makes it difficult to offer educational discounts
31493 \end_layout
31494
31495 \end_inset
31496
31497 .
31498  If your rationales are to:
31499 \end_layout
31500
31501 \begin_layout Enumerate
31502 give students a chance to understand the 
31503 \emph on
31504 complete
31505 \emph default
31506  steps of code generation
31507 \end_layout
31508
31509 \begin_layout Enumerate
31510 have a curriculum that can be extended for years.
31511  Then you could use an fpga board as target and your curriculum will seamlessly
31512  extend from logic synthesis (
31513 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
31514
31515 \end_inset
31516
31517
31518 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
31519
31520 \end_inset
31521
31522 ), over assembly programming, to C to FPGA compilers (
31523 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
31524
31525 \end_inset
31526
31527 ) and to C.
31528 \end_layout
31529
31530 \begin_layout Enumerate
31531 be able to insert excursions about skills like using a revision control
31532  system, submitting/applying patches, using a type-setting (as opposed to
31533  word-processing) engine LyX/LaTeX, using 
31534 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
31535
31536 \end_inset
31537
31538 , following some 
31539 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
31540
31541 \end_inset
31542
31543 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
31544  Source Software, CPU simulation, compiler regression tests
31545 \begin_inset LatexCommand \index{Regression test}
31546
31547 \end_inset
31548
31549 .
31550  
31551 \newline
31552 And if there should be a shortage of ideas then you can always point students
31553  to the ever-growing feature request list 
31554 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31555
31556 \end_inset
31557
31558 .
31559 \end_layout
31560
31561 \begin_layout Enumerate
31562 not tie students to a specific host platform and instead allow them to use
31563  a host platform of 
31564 \emph on
31565 their
31566 \emph default
31567  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
31568  eventually 
31569 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
31570
31571 \end_inset
31572
31573 )
31574 \end_layout
31575
31576 \begin_layout Enumerate
31577 not encourage students to use illegal copies of educational software
31578 \end_layout
31579
31580 \begin_layout Enumerate
31581 be immune to licensing/availability/price changes of the chosen tool chain
31582 \end_layout
31583
31584 \begin_layout Enumerate
31585 be able to change to a new target platform without having to adopt a new
31586  tool chain
31587 \end_layout
31588
31589 \begin_layout Enumerate
31590 have complete control over and insight into the tool chain
31591 \end_layout
31592
31593 \begin_layout Enumerate
31594 make your students aware about the pros and cons of open source software
31595  development
31596 \end_layout
31597
31598 \begin_layout Enumerate
31599 give back to the public as you are probably at least partially publically
31600  funded
31601 \end_layout
31602
31603 \begin_layout Enumerate
31604 give students a chance to publically prove their skills and to possibly
31605  see a world wide impact
31606 \end_layout
31607
31608 \begin_layout Standard
31609 then SDCC is probably among the first choices.
31610  Well, probably SDCC might be the only choice.
31611 \newpage
31612
31613 \end_layout
31614
31615 \begin_layout Chapter
31616 SDCC Technical Data
31617 \end_layout
31618
31619 \begin_layout Section
31620 Optimizations
31621 \begin_inset LatexCommand \index{Optimizations}
31622
31623 \end_inset
31624
31625
31626 \end_layout
31627
31628 \begin_layout Standard
31629 SDCC performs a host of standard optimizations in addition to some MCU specific
31630  optimizations.
31631  
31632 \end_layout
31633
31634 \begin_layout Subsection
31635 Sub-expression Elimination
31636 \begin_inset LatexCommand \index{Subexpression elimination}
31637
31638 \end_inset
31639
31640
31641 \end_layout
31642
31643 \begin_layout Standard
31644 The compiler does local and 
31645 \emph on
31646 g
31647 \emph default
31648 lobal 
31649 \emph on
31650 c
31651 \emph default
31652 ommon 
31653 \emph on
31654 s
31655 \emph default
31656 ubexpression 
31657 \emph on
31658 e
31659 \emph default
31660 limination, e.g.: 
31661 \end_layout
31662
31663 \begin_layout Verse
31664
31665 \family typewriter
31666 i = x + y + 1; 
31667 \newline
31668 j = x + y;
31669 \end_layout
31670
31671 \begin_layout Standard
31672 will be translated to
31673 \end_layout
31674
31675 \begin_layout Verse
31676
31677 \family typewriter
31678 iTemp = x + y; 
31679 \newline
31680 i = iTemp + 1; 
31681 \newline
31682 j = iTemp;
31683 \end_layout
31684
31685 \begin_layout Standard
31686 Some subexpressions are not as obvious as the above example, e.g.:
31687 \end_layout
31688
31689 \begin_layout Verse
31690
31691 \family typewriter
31692 a->b[i].c = 10; 
31693 \newline
31694 a->b[i].d = 11;
31695 \end_layout
31696
31697 \begin_layout Standard
31698 In this case the address arithmetic a->b[i] will be computed only once;
31699  the equivalent code in C would be.
31700 \end_layout
31701
31702 \begin_layout Verse
31703
31704 \family typewriter
31705 iTemp = a->b[i]; 
31706 \newline
31707 iTemp.c = 10; 
31708 \newline
31709 iTemp.d = 11;
31710 \end_layout
31711
31712 \begin_layout Standard
31713 The compiler will try to keep these temporary variables in registers.
31714 \end_layout
31715
31716 \begin_layout Subsection
31717 Dead-Code Elimination
31718 \begin_inset LatexCommand \index{Dead-code elimination}
31719
31720 \end_inset
31721
31722
31723 \end_layout
31724
31725 \begin_layout Verse
31726
31727 \family typewriter
31728 int global;
31729 \newline
31730
31731 \newline
31732 void f () { 
31733 \newline
31734 \InsetSpace ~
31735 \InsetSpace ~
31736 int i; 
31737 \newline
31738 \InsetSpace ~
31739 \InsetSpace ~
31740 i = 1; \InsetSpace ~
31741 \InsetSpace ~
31742 \InsetSpace ~
31743 \InsetSpace ~
31744 \InsetSpace ~
31745 /* dead store */ 
31746 \newline
31747 \InsetSpace ~
31748 \InsetSpace ~
31749 global = 1;\InsetSpace ~
31750 /* dead
31751  store */ 
31752 \newline
31753 \InsetSpace ~
31754 \InsetSpace ~
31755 global = 2; 
31756 \newline
31757 \InsetSpace ~
31758 \InsetSpace ~
31759 return; 
31760 \newline
31761 \InsetSpace ~
31762 \InsetSpace ~
31763 global = 3;\InsetSpace ~
31764 /* unreachable */ 
31765 \newline
31766 }
31767 \end_layout
31768
31769 \begin_layout Standard
31770 will be changed to
31771 \end_layout
31772
31773 \begin_layout Verse
31774
31775 \family typewriter
31776 int global;
31777 \newline
31778
31779 \newline
31780 void f () {
31781 \newline
31782 \InsetSpace ~
31783 \InsetSpace ~
31784 global = 2; 
31785 \newline
31786 }
31787 \end_layout
31788
31789 \begin_layout Subsection
31790 Copy-Propagation
31791 \begin_inset LatexCommand \index{Copy propagation}
31792
31793 \end_inset
31794
31795
31796 \end_layout
31797
31798 \begin_layout Verse
31799
31800 \family typewriter
31801 int f() { 
31802 \newline
31803 \InsetSpace ~
31804 \InsetSpace ~
31805 int i, j; 
31806 \newline
31807 \InsetSpace ~
31808 \InsetSpace ~
31809 i = 10; 
31810 \newline
31811 \InsetSpace ~
31812 \InsetSpace ~
31813 j = i; 
31814 \newline
31815 \InsetSpace ~
31816 \InsetSpace ~
31817 return j; 
31818 \newline
31819 }
31820 \end_layout
31821
31822 \begin_layout Standard
31823 will be changed to 
31824 \end_layout
31825
31826 \begin_layout Verse
31827
31828 \family typewriter
31829 int f() { 
31830 \newline
31831 \InsetSpace ~
31832 \InsetSpace ~
31833 int i, j; 
31834 \newline
31835 \InsetSpace ~
31836 \InsetSpace ~
31837 i = 10; 
31838 \newline
31839 \InsetSpace ~
31840 \InsetSpace ~
31841 j = 10; 
31842 \newline
31843 \InsetSpace ~
31844 \InsetSpace ~
31845 return 10; 
31846 \newline
31847 }
31848 \end_layout
31849
31850 \begin_layout Standard
31851 Note: the dead stores created by this copy propagation will be eliminated
31852  by dead-code elimination.
31853 \end_layout
31854
31855 \begin_layout Subsection
31856 Loop Optimizations
31857 \begin_inset LatexCommand \index{Loop optimization}
31858
31859 \end_inset
31860
31861
31862 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
31863
31864 \end_inset
31865
31866
31867 \end_layout
31868
31869 \begin_layout Standard
31870 Two types of loop optimizations are done by SDCC 
31871 \emph on
31872 loop invariant
31873 \emph default
31874  lifting and
31875 \emph on
31876  strength reduction
31877 \emph default
31878  of loop induction variables.
31879  In addition to the strength reduction the optimizer marks the induction
31880  variables and the register allocator tries to keep the induction variables
31881  in registers for the duration of the loop.
31882  Because of this preference of the register allocator
31883 \begin_inset LatexCommand \index{Register allocation}
31884
31885 \end_inset
31886
31887 , loop induction optimization causes an increase in register pressure, which
31888  may cause unwanted spilling of other temporary variables into the stack
31889 \begin_inset LatexCommand \index{stack}
31890
31891 \end_inset
31892
31893  / data space.
31894  The compiler will generate a warning message when it is forced to allocate
31895  extra space either on the stack or data space.
31896  If this extra space allocation is undesirable then induction optimization
31897  can be eliminated either for the entire source file (with -
31898 \begin_inset ERT
31899 status collapsed
31900
31901 \begin_layout Standard
31902
31903
31904 \backslash
31905 /
31906 \end_layout
31907
31908 \end_inset
31909
31910 -noinduction option) or for a given function only using #pragma\InsetSpace ~
31911 noinduction
31912 \begin_inset LatexCommand \index{\#pragma noinduction}
31913
31914 \end_inset
31915
31916 .
31917 \newline
31918
31919 \newline
31920 Loop Invariant:
31921 \end_layout
31922
31923 \begin_layout Verse
31924
31925 \family typewriter
31926 for (i = 0 ; i < 100 ; i ++) 
31927 \newline
31928 \InsetSpace ~
31929 \InsetSpace ~
31930 \InsetSpace ~
31931 \InsetSpace ~
31932 f += k + l;
31933 \end_layout
31934
31935 \begin_layout Standard
31936 changed to
31937 \end_layout
31938
31939 \begin_layout Verse
31940
31941 \family typewriter
31942 itemp = k + l; 
31943 \newline
31944 for (i = 0; i < 100; i++) 
31945 \newline
31946 \InsetSpace ~
31947 \InsetSpace ~
31948 \InsetSpace ~
31949 \InsetSpace ~
31950 f += itemp;
31951 \end_layout
31952
31953 \begin_layout Standard
31954 As mentioned previously some loop invariants are not as apparent, all static
31955  address computations are also moved out of the loop.
31956 \newline
31957
31958 \newline
31959 Strength Reduction
31960 \begin_inset LatexCommand \index{Strength reduction}
31961
31962 \end_inset
31963
31964 , this optimization substitutes an expression by a cheaper expression:
31965 \end_layout
31966
31967 \begin_layout Verse
31968
31969 \family typewriter
31970 for (i=0;i < 100; i++)
31971 \newline
31972 \InsetSpace ~
31973 \InsetSpace ~
31974 \InsetSpace ~
31975 \InsetSpace ~
31976 ar[i*5] = i*3;
31977 \end_layout
31978
31979 \begin_layout Standard
31980 changed to
31981 \end_layout
31982
31983 \begin_layout Verse
31984
31985 \family typewriter
31986 itemp1 = 0; 
31987 \newline
31988 itemp2 = 0; 
31989 \newline
31990 for (i=0;i< 100;i++) { 
31991 \newline
31992 \InsetSpace ~
31993 \InsetSpace ~
31994 \InsetSpace ~
31995 \InsetSpace ~
31996 ar[itemp1] = itemp2; 
31997 \newline
31998 \InsetSpace ~
31999 \InsetSpace ~
32000 \InsetSpace ~
32001 \InsetSpace ~
32002 itemp1
32003  += 5; 
32004 \newline
32005 \InsetSpace ~
32006 \InsetSpace ~
32007 \InsetSpace ~
32008 \InsetSpace ~
32009 itemp2 += 3; 
32010 \newline
32011 }
32012 \end_layout
32013
32014 \begin_layout Standard
32015 The more expensive multiplication
32016 \begin_inset LatexCommand \index{Multiplication}
32017
32018 \end_inset
32019
32020  is changed to a less expensive addition.
32021 \end_layout
32022
32023 \begin_layout Subsection
32024 Loop Reversing
32025 \begin_inset LatexCommand \index{Loop reversing}
32026
32027 \end_inset
32028
32029
32030 \end_layout
32031
32032 \begin_layout Standard
32033 This optimization is done to reduce the overhead of checking loop boundaries
32034  for every iteration.
32035  Some simple loops can be reversed and implemented using a 
32036 \begin_inset Quotes eld
32037 \end_inset
32038
32039 decrement and jump if not zero
32040 \begin_inset Quotes erd
32041 \end_inset
32042
32043  instruction.
32044  SDCC checks for the following criterion to determine if a loop is reversible
32045  (note: more sophisticated compilers use data-dependency analysis to make
32046  this determination, SDCC uses a more simple minded analysis).
32047 \end_layout
32048
32049 \begin_layout Itemize
32050 The 'for' loop is of the form 
32051 \newline
32052
32053 \newline
32054
32055 \family typewriter
32056 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32057  += 1])
32058 \newline
32059 \InsetSpace ~
32060 \InsetSpace ~
32061 \InsetSpace ~
32062 \InsetSpace ~
32063 <for body>
32064 \end_layout
32065
32066 \begin_layout Itemize
32067 The <for body> does not contain 
32068 \begin_inset Quotes eld
32069 \end_inset
32070
32071 continue
32072 \begin_inset Quotes erd
32073 \end_inset
32074
32075  or 'break
32076 \begin_inset Quotes erd
32077 \end_inset
32078
32079 .
32080 \end_layout
32081
32082 \begin_layout Itemize
32083 All goto's are contained within the loop.
32084 \end_layout
32085
32086 \begin_layout Itemize
32087 No function calls within the loop.
32088 \end_layout
32089
32090 \begin_layout Itemize
32091 The loop control variable <sym> is not assigned any value within the loop
32092 \end_layout
32093
32094 \begin_layout Itemize
32095 The loop control variable does NOT participate in any arithmetic operation
32096  within the loop.
32097 \end_layout
32098
32099 \begin_layout Itemize
32100 There are NO switch statements in the loop.
32101 \end_layout
32102
32103 \begin_layout Subsection
32104 Algebraic Simplifications
32105 \end_layout
32106
32107 \begin_layout Standard
32108 SDCC does numerous algebraic simplifications, the following is a small sub-set
32109  of these optimizations.
32110 \end_layout
32111
32112 \begin_layout Verse
32113
32114 \family typewriter
32115 i = j + 0;\InsetSpace ~
32116 \InsetSpace ~
32117 \InsetSpace ~
32118 \InsetSpace ~
32119  /* changed to: */\InsetSpace ~
32120 \InsetSpace ~
32121 \InsetSpace ~
32122 \InsetSpace ~
32123  i = j; 
32124 \newline
32125 i /= 2;\InsetSpace ~
32126 \InsetSpace ~
32127 \InsetSpace ~
32128 \InsetSpace ~
32129 \InsetSpace ~
32130 \InsetSpace ~
32131 \InsetSpace ~
32132  /* changed to: */\InsetSpace ~
32133 \InsetSpace ~
32134 \InsetSpace ~
32135 \InsetSpace ~
32136  i >>= 1; 
32137 \newline
32138 i
32139  = j - j;\InsetSpace ~
32140 \InsetSpace ~
32141 \InsetSpace ~
32142 \InsetSpace ~
32143  /* changed to: */\InsetSpace ~
32144 \InsetSpace ~
32145 \InsetSpace ~
32146 \InsetSpace ~
32147  i = 0; 
32148 \newline
32149 i = j / 1;\InsetSpace ~
32150 \InsetSpace ~
32151 \InsetSpace ~
32152 \InsetSpace ~
32153  /* changed to: */\InsetSpace ~
32154 \InsetSpace ~
32155 \InsetSpace ~
32156 \InsetSpace ~
32157  i = j;
32158 \end_layout
32159
32160 \begin_layout Standard
32161 Note the subexpressions
32162 \begin_inset LatexCommand \index{Subexpression}
32163
32164 \end_inset
32165
32166  given above are generally introduced by macro expansions or as a result
32167  of copy/constant propagation.
32168 \end_layout
32169
32170 \begin_layout Subsection
32171 'switch' Statements
32172 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32173
32174 \end_inset
32175
32176
32177 \begin_inset LatexCommand \index{switch statement}
32178
32179 \end_inset
32180
32181
32182 \end_layout
32183
32184 \begin_layout Standard
32185 SDCC can optimize switch statements to jump tables
32186 \begin_inset LatexCommand \index{jump tables}
32187
32188 \end_inset
32189
32190 .
32191  It makes the decision based on an estimate of the generated code size.
32192  SDCC is quite liberal in the requirements for jump table generation: 
32193 \end_layout
32194
32195 \begin_layout Itemize
32196 The labels need not be in order, and the starting number need not be one
32197  or zero, the case labels are in numerical sequence or not too many case
32198  labels are missing.
32199 \end_layout
32200
32201 \begin_deeper
32202 \begin_layout Verse
32203
32204 \family typewriter
32205 switch(i) {\InsetSpace ~
32206 \InsetSpace ~
32207 \InsetSpace ~
32208 \InsetSpace ~
32209 \InsetSpace ~
32210 \InsetSpace ~
32211 \InsetSpace ~
32212 \InsetSpace ~
32213 \InsetSpace ~
32214 \InsetSpace ~
32215 \InsetSpace ~
32216 \InsetSpace ~
32217 \InsetSpace ~
32218 \InsetSpace ~
32219 \InsetSpace ~
32220 \InsetSpace ~
32221 \InsetSpace ~
32222 \InsetSpace ~
32223 \InsetSpace ~
32224 \InsetSpace ~
32225 \InsetSpace ~
32226 \InsetSpace ~
32227 \InsetSpace ~
32228 \InsetSpace ~
32229 \InsetSpace ~
32230 \InsetSpace ~
32231 switch (i) { 
32232 \newline
32233 \InsetSpace ~
32234 \InsetSpace ~
32235 \InsetSpace ~
32236 case 4: ...\InsetSpace ~
32237 \InsetSpace ~
32238 \InsetSpace ~
32239 \InsetSpace ~
32240 \InsetSpace ~
32241 \InsetSpace ~
32242 \InsetSpace ~
32243 \InsetSpace ~
32244 \InsetSpace ~
32245 \InsetSpace ~
32246 \InsetSpace ~
32247 \InsetSpace ~
32248 \InsetSpace ~
32249 \InsetSpace ~
32250 \InsetSpace ~
32251 \InsetSpace ~
32252 \InsetSpace ~
32253 \InsetSpace ~
32254 \InsetSpace ~
32255 \InsetSpace ~
32256 \InsetSpace ~
32257 \InsetSpace ~
32258 \InsetSpace ~
32259 \InsetSpace ~
32260 \InsetSpace ~
32261 \InsetSpace ~
32262 case 0: ...
32263  
32264 \newline
32265 \InsetSpace ~
32266 \InsetSpace ~
32267 \InsetSpace ~
32268 case 5: ...\InsetSpace ~
32269 \InsetSpace ~
32270 \InsetSpace ~
32271 \InsetSpace ~
32272 \InsetSpace ~
32273 \InsetSpace ~
32274 \InsetSpace ~
32275 \InsetSpace ~
32276 \InsetSpace ~
32277 \InsetSpace ~
32278 \InsetSpace ~
32279 \InsetSpace ~
32280 \InsetSpace ~
32281 \InsetSpace ~
32282 \InsetSpace ~
32283 \InsetSpace ~
32284 \InsetSpace ~
32285 \InsetSpace ~
32286 \InsetSpace ~
32287 \InsetSpace ~
32288 \InsetSpace ~
32289 \InsetSpace ~
32290 \InsetSpace ~
32291 \InsetSpace ~
32292 \InsetSpace ~
32293 \InsetSpace ~
32294 case 1: ...
32295  
32296 \newline
32297 \InsetSpace ~
32298 \InsetSpace ~
32299 \InsetSpace ~
32300 case 3: ...\InsetSpace ~
32301 \InsetSpace ~
32302 \InsetSpace ~
32303 \InsetSpace ~
32304 \InsetSpace ~
32305 \InsetSpace ~
32306 \InsetSpace ~
32307 \InsetSpace ~
32308 \InsetSpace ~
32309 \InsetSpace ~
32310 \InsetSpace ~
32311 \InsetSpace ~
32312 \InsetSpace ~
32313 \InsetSpace ~
32314 \InsetSpace ~
32315 \InsetSpace ~
32316 \InsetSpace ~
32317 \InsetSpace ~
32318 \InsetSpace ~
32319 \InsetSpace ~
32320 \InsetSpace ~
32321 \InsetSpace ~
32322 \InsetSpace ~
32323 \InsetSpace ~
32324 \InsetSpace ~
32325 \InsetSpace ~
32326
32327 \newline
32328 \InsetSpace ~
32329 \InsetSpace ~
32330 \InsetSpace ~
32331 case 6: ...\InsetSpace ~
32332 \InsetSpace ~
32333 \InsetSpace ~
32334 \InsetSpace ~
32335 \InsetSpace ~
32336 \InsetSpace ~
32337 \InsetSpace ~
32338 \InsetSpace ~
32339 \InsetSpace ~
32340 \InsetSpace ~
32341 \InsetSpace ~
32342 \InsetSpace ~
32343 \InsetSpace ~
32344 \InsetSpace ~
32345 \InsetSpace ~
32346 \InsetSpace ~
32347 \InsetSpace ~
32348 \InsetSpace ~
32349 \InsetSpace ~
32350 \InsetSpace ~
32351 \InsetSpace ~
32352 \InsetSpace ~
32353 \InsetSpace ~
32354 \InsetSpace ~
32355 \InsetSpace ~
32356 \InsetSpace ~
32357 case 3: ...
32358  
32359 \newline
32360 \InsetSpace ~
32361 \InsetSpace ~
32362 \InsetSpace ~
32363 case 7: ...\InsetSpace ~
32364 \InsetSpace ~
32365 \InsetSpace ~
32366 \InsetSpace ~
32367 \InsetSpace ~
32368 \InsetSpace ~
32369 \InsetSpace ~
32370 \InsetSpace ~
32371 \InsetSpace ~
32372 \InsetSpace ~
32373 \InsetSpace ~
32374 \InsetSpace ~
32375 \InsetSpace ~
32376 \InsetSpace ~
32377 \InsetSpace ~
32378 \InsetSpace ~
32379 \InsetSpace ~
32380 \InsetSpace ~
32381 \InsetSpace ~
32382 \InsetSpace ~
32383 \InsetSpace ~
32384 \InsetSpace ~
32385 \InsetSpace ~
32386 \InsetSpace ~
32387 \InsetSpace ~
32388 \InsetSpace ~
32389 case 4: ...
32390  
32391 \newline
32392 \InsetSpace ~
32393 \InsetSpace ~
32394 \InsetSpace ~
32395 case 8: ...\InsetSpace ~
32396 \InsetSpace ~
32397 \InsetSpace ~
32398 \InsetSpace ~
32399 \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 \InsetSpace ~
32415 \InsetSpace ~
32416 \InsetSpace ~
32417 \InsetSpace ~
32418 \InsetSpace ~
32419 \InsetSpace ~
32420 \InsetSpace ~
32421 case 5: ...
32422  
32423 \newline
32424 \InsetSpace ~
32425 \InsetSpace ~
32426 \InsetSpace ~
32427 case 9: ...\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 \InsetSpace ~
32452 \InsetSpace ~
32453 case 6: ...
32454  
32455 \newline
32456 \InsetSpace ~
32457 \InsetSpace ~
32458 \InsetSpace ~
32459 case 10: ...\InsetSpace ~
32460 \InsetSpace ~
32461 \InsetSpace ~
32462 \InsetSpace ~
32463 \InsetSpace ~
32464 \InsetSpace ~
32465 \InsetSpace ~
32466 \InsetSpace ~
32467 \InsetSpace ~
32468 \InsetSpace ~
32469 \InsetSpace ~
32470 \InsetSpace ~
32471 \InsetSpace ~
32472 \InsetSpace ~
32473 \InsetSpace ~
32474 \InsetSpace ~
32475 \InsetSpace ~
32476 \InsetSpace ~
32477 \InsetSpace ~
32478 \InsetSpace ~
32479 \InsetSpace ~
32480 \InsetSpace ~
32481 \InsetSpace ~
32482 \InsetSpace ~
32483 \InsetSpace ~
32484 case 7: ...
32485  
32486 \newline
32487 \InsetSpace ~
32488 \InsetSpace ~
32489 \InsetSpace ~
32490 case 11: ...\InsetSpace ~
32491 \InsetSpace ~
32492 \InsetSpace ~
32493 \InsetSpace ~
32494 \InsetSpace ~
32495 \InsetSpace ~
32496 \InsetSpace ~
32497 \InsetSpace ~
32498 \InsetSpace ~
32499 \InsetSpace ~
32500 \InsetSpace ~
32501 \InsetSpace ~
32502 \InsetSpace ~
32503 \InsetSpace ~
32504 \InsetSpace ~
32505 \InsetSpace ~
32506 \InsetSpace ~
32507 \InsetSpace ~
32508 \InsetSpace ~
32509 \InsetSpace ~
32510 \InsetSpace ~
32511 \InsetSpace ~
32512 \InsetSpace ~
32513 \InsetSpace ~
32514 \InsetSpace ~
32515 case 8: ...
32516  
32517 \newline
32518 }\InsetSpace ~
32519 \InsetSpace ~
32520 \InsetSpace ~
32521 \InsetSpace ~
32522 \InsetSpace ~
32523 \InsetSpace ~
32524 \InsetSpace ~
32525 \InsetSpace ~
32526 \InsetSpace ~
32527 \InsetSpace ~
32528 \InsetSpace ~
32529 \InsetSpace ~
32530 \InsetSpace ~
32531 \InsetSpace ~
32532 \InsetSpace ~
32533 \InsetSpace ~
32534 \InsetSpace ~
32535 \InsetSpace ~
32536 \InsetSpace ~
32537 \InsetSpace ~
32538 \InsetSpace ~
32539 \InsetSpace ~
32540 \InsetSpace ~
32541 \InsetSpace ~
32542 \InsetSpace ~
32543 \InsetSpace ~
32544 \InsetSpace ~
32545 \InsetSpace ~
32546 \InsetSpace ~
32547 \InsetSpace ~
32548 \InsetSpace ~
32549 \InsetSpace ~
32550 \InsetSpace ~
32551 \InsetSpace ~
32552 \InsetSpace ~
32553 \InsetSpace ~
32554 }
32555 \end_layout
32556
32557 \begin_layout Standard
32558 Both the above switch statements will be implemented using a jump-table.
32559  The example to the right side is slightly more efficient as the check for
32560  the lower boundary of the jump-table is not needed.
32561 \end_layout
32562
32563 \end_deeper
32564 \begin_layout Itemize
32565 The number of case labels is not larger than supported by the target architectur
32566 e.
32567 \end_layout
32568
32569 \begin_layout Itemize
32570 If the case labels are not in numerical sequence ('gaps' between cases)
32571  SDCC checks whether a jump table with additionally inserted dummy cases
32572  is still attractive.
32573  
32574 \end_layout
32575
32576 \begin_layout Itemize
32577 If the starting number is not zero and a check for the lower boundary of
32578  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
32579  ...
32580  .
32581 \end_layout
32582
32583 \begin_layout Standard
32584 Switch statements which have large gaps in the numeric sequence or those
32585  that have too many case labels can be split into more than one switch statement
32586  for efficient code generation, e.g.:
32587 \end_layout
32588
32589 \begin_layout Verse
32590
32591 \family typewriter
32592 switch (i) { 
32593 \newline
32594 \InsetSpace ~
32595 \InsetSpace ~
32596 case 1: ...
32597  
32598 \newline
32599 \InsetSpace ~
32600 \InsetSpace ~
32601 case 2: ...
32602  
32603 \newline
32604 \InsetSpace ~
32605 \InsetSpace ~
32606 case 3: ...
32607  
32608 \newline
32609 \InsetSpace ~
32610 \InsetSpace ~
32611 case 4: ...
32612  
32613 \newline
32614 \InsetSpace ~
32615 \InsetSpace ~
32616 case 5: ...
32617  
32618 \newline
32619 \InsetSpace ~
32620 \InsetSpace ~
32621 case 6: ...
32622  
32623 \newline
32624 \InsetSpace ~
32625 \InsetSpace ~
32626 case 7: ...
32627  
32628 \newline
32629 \InsetSpace ~
32630 \InsetSpace ~
32631 case 101: ...
32632  
32633 \newline
32634 \InsetSpace ~
32635 \InsetSpace ~
32636 case 102: ...
32637  
32638 \newline
32639 \InsetSpace ~
32640 \InsetSpace ~
32641 case 103: ...
32642  
32643 \newline
32644 \InsetSpace ~
32645 \InsetSpace ~
32646 case 104: ...
32647  
32648 \newline
32649 \InsetSpace ~
32650 \InsetSpace ~
32651 case 105: ...
32652  
32653 \newline
32654 \InsetSpace ~
32655 \InsetSpace ~
32656 case 106: ...
32657  
32658 \newline
32659 \InsetSpace ~
32660 \InsetSpace ~
32661 case 107: ...
32662  
32663 \newline
32664 }
32665 \end_layout
32666
32667 \begin_layout Standard
32668 If the above switch statement is broken down into two switch statements
32669 \end_layout
32670
32671 \begin_layout Verse
32672
32673 \family typewriter
32674 switch (i) { 
32675 \newline
32676 \InsetSpace ~
32677 \InsetSpace ~
32678 case 1: ...
32679  
32680 \newline
32681 \InsetSpace ~
32682 \InsetSpace ~
32683 case 2: ...
32684  
32685 \newline
32686 \InsetSpace ~
32687 \InsetSpace ~
32688 case 3: ...
32689  
32690 \newline
32691 \InsetSpace ~
32692 \InsetSpace ~
32693 case 4: ...
32694  
32695 \newline
32696 \InsetSpace ~
32697 \InsetSpace ~
32698 case 5: ...
32699  
32700 \newline
32701 \InsetSpace ~
32702 \InsetSpace ~
32703 case 6: ...
32704  
32705 \newline
32706 \InsetSpace ~
32707 \InsetSpace ~
32708 case 7: ...
32709  
32710 \newline
32711 }
32712 \end_layout
32713
32714 \begin_layout Standard
32715 and
32716 \end_layout
32717
32718 \begin_layout Verse
32719
32720 \family typewriter
32721 switch (i) { 
32722 \newline
32723 \InsetSpace ~
32724 \InsetSpace ~
32725 case 101: ...
32726  
32727 \newline
32728 \InsetSpace ~
32729 \InsetSpace ~
32730 case 102: ...
32731  
32732 \newline
32733 \InsetSpace ~
32734 \InsetSpace ~
32735 case 103: ...
32736  
32737 \newline
32738 \InsetSpace ~
32739 \InsetSpace ~
32740 case 104: ...
32741  
32742 \newline
32743 \InsetSpace ~
32744 \InsetSpace ~
32745 case 105: ...
32746  
32747 \newline
32748 \InsetSpace ~
32749 \InsetSpace ~
32750 case 106: ...
32751  
32752 \newline
32753 \InsetSpace ~
32754 \InsetSpace ~
32755 case 107: ...
32756  
32757 \newline
32758 }
32759 \end_layout
32760
32761 \begin_layout Standard
32762 then both the switch statements will be implemented using jump-tables whereas
32763  the unmodified switch statement will not be.
32764 \end_layout
32765
32766 \begin_layout Standard
32767 \begin_inset Note Note
32768 status collapsed
32769
32770 \begin_layout Standard
32771 There might be reasons which SDCC cannot know about to either favour or
32772  not favour jump tables.
32773  If the target system has to be as quick for the last switch case as for
32774  the first (pro jump table), or if the switch argument is known to be zero
32775  in the majority of the cases (contra jump table).
32776 \end_layout
32777
32778 \end_inset
32779
32780
32781 \end_layout
32782
32783 \begin_layout Standard
32784 The pragma nojtbound
32785 \begin_inset LatexCommand \index{\#pragma nojtbound}
32786
32787 \end_inset
32788
32789  can be used to turn off checking the 
32790 \emph on
32791 j
32792 \emph default
32793 ump 
32794 \emph on
32795 t
32796 \emph default
32797 able 
32798 \emph on
32799 bound
32800 \emph default
32801 aries.
32802  It has no effect if a default label is supplied.
32803  Use of this pragma is dangerous: if the switch
32804 \begin_inset LatexCommand \index{switch statement}
32805
32806 \end_inset
32807
32808  argument is not matched by a case statement the processor will happily
32809  jump into Nirvana.
32810 \end_layout
32811
32812 \begin_layout Subsection
32813 Bit-shifting Operations
32814 \begin_inset LatexCommand \index{Bit shifting}
32815
32816 \end_inset
32817
32818 .
32819 \end_layout
32820
32821 \begin_layout Standard
32822 Bit shifting is one of the most frequently used operation in embedded programmin
32823 g.
32824  SDCC tries to implement bit-shift operations in the most efficient way
32825  possible, e.g.:
32826 \end_layout
32827
32828 \begin_layout Verse
32829
32830 \family typewriter
32831 unsigned char i;
32832 \newline
32833 ...
32834  
32835 \newline
32836 i >>= 4; 
32837 \newline
32838 ...
32839 \end_layout
32840
32841 \begin_layout Standard
32842 generates the following code:
32843 \end_layout
32844
32845 \begin_layout Verse
32846
32847 \family typewriter
32848 mov\InsetSpace ~
32849  a,_i 
32850 \newline
32851 swap a 
32852 \newline
32853 anl\InsetSpace ~
32854  a,#0x0f 
32855 \newline
32856 mov\InsetSpace ~
32857  _i,a
32858 \end_layout
32859
32860 \begin_layout Standard
32861 In general SDCC will never setup a loop if the shift count is known.
32862  Another example:
32863 \end_layout
32864
32865 \begin_layout Verse
32866
32867 \family typewriter
32868 unsigned int i; 
32869 \newline
32870 ...
32871  
32872 \newline
32873 i >>= 9; 
32874 \newline
32875 ...
32876 \end_layout
32877
32878 \begin_layout Standard
32879 will generate:
32880 \end_layout
32881
32882 \begin_layout Verse
32883
32884 \family typewriter
32885 mov\InsetSpace ~
32886 \InsetSpace ~
32887 a,(_i + 1) 
32888 \newline
32889 mov\InsetSpace ~
32890 \InsetSpace ~
32891 (_i + 1),#0x00 
32892 \newline
32893 clr\InsetSpace ~
32894 \InsetSpace ~
32895
32896 \newline
32897 rrc\InsetSpace ~
32898 \InsetSpace ~
32899
32900 \newline
32901 mov\InsetSpace ~
32902 \InsetSpace ~
32903 _i,a
32904 \end_layout
32905
32906 \begin_layout Subsection
32907 Bit-rotation
32908 \begin_inset LatexCommand \index{Bit rotation}
32909
32910 \end_inset
32911
32912
32913 \end_layout
32914
32915 \begin_layout Standard
32916 A special case of the bit-shift operation is bit rotation
32917 \begin_inset LatexCommand \index{rotating bits}
32918
32919 \end_inset
32920
32921 , SDCC recognizes the following expression to be a left bit-rotation:
32922 \end_layout
32923
32924 \begin_layout Verse
32925
32926 \family typewriter
32927 \series bold
32928 unsigned
32929 \series default
32930 \InsetSpace ~
32931 \InsetSpace ~
32932 char i;\InsetSpace ~
32933 \InsetSpace ~
32934 \InsetSpace ~
32935 \InsetSpace ~
32936 \InsetSpace ~
32937 \InsetSpace ~
32938 \InsetSpace ~
32939 \InsetSpace ~
32940 \InsetSpace ~
32941 \InsetSpace ~
32942 \InsetSpace ~
32943 /* unsigned is needed for rotation */ 
32944 \newline
32945 ...
32946  
32947 \newline
32948 i = ((i << 1) | (i >> 7)); 
32949 \family default
32950
32951 \newline
32952
32953 \family typewriter
32954 ...
32955 \end_layout
32956
32957 \begin_layout Standard
32958 will generate the following code:
32959 \end_layout
32960
32961 \begin_layout Verse
32962
32963 \family typewriter
32964 mov\InsetSpace ~
32965 \InsetSpace ~
32966 a,_i 
32967 \newline
32968 rl\InsetSpace ~
32969 \InsetSpace ~
32970 \InsetSpace ~
32971
32972 \newline
32973 mov\InsetSpace ~
32974 \InsetSpace ~
32975 _i,a
32976 \end_layout
32977
32978 \begin_layout Standard
32979 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
32980 ns of this case will also be recognized as bit-rotation, i.e.: 
32981 \end_layout
32982
32983 \begin_layout Verse
32984
32985 \family typewriter
32986 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
32987 \end_layout
32988
32989 \begin_layout Subsection
32990 Nibble and Byte Swapping
32991 \end_layout
32992
32993 \begin_layout Standard
32994 Other special cases of the bit-shift operations are nibble or byte swapping
32995 \begin_inset LatexCommand \index{swapping nibbles/bytes}
32996
32997 \end_inset
32998
32999 , SDCC recognizes the following expressions:
33000 \end_layout
33001
33002 \begin_layout Verse
33003
33004 \family typewriter
33005 \series bold
33006 unsigned
33007 \series default
33008 \InsetSpace ~
33009 \InsetSpace ~
33010 char i; 
33011 \newline
33012
33013 \series bold
33014 unsigned
33015 \series default
33016 \InsetSpace ~
33017 \InsetSpace ~
33018 int j; 
33019 \newline
33020 ...
33021  
33022 \newline
33023 i = ((i << 4) | (i >> 4)); 
33024 \family default
33025
33026 \newline
33027
33028 \family typewriter
33029 j = ((j << 8) | (j >> 8)); 
33030 \end_layout
33031
33032 \begin_layout Standard
33033 and generates a swap instruction for the nibble swapping
33034 \begin_inset LatexCommand \index{Nibble swapping}
33035
33036 \end_inset
33037
33038  or move instructions for the byte swapping
33039 \begin_inset LatexCommand \index{Byte swapping}
33040
33041 \end_inset
33042
33043 .
33044  The 
33045 \begin_inset Quotes sld
33046 \end_inset
33047
33048 j
33049 \begin_inset Quotes srd
33050 \end_inset
33051
33052  example can be used to convert from little to big-endian or vice versa.
33053  If you want to change the endianness of a 
33054 \emph on
33055 signed
33056 \emph default
33057  integer you have to cast to 
33058 \family typewriter
33059 (unsigned int)
33060 \family default
33061  first.
33062 \end_layout
33063
33064 \begin_layout Standard
33065 Note that SDCC stores numbers in little-endian
33066 \begin_inset Foot
33067 status open
33068
33069 \begin_layout Standard
33070 Usually 8-bit processors don't care much about endianness.
33071  This is not the case for the standard 8051 which only has an instruction
33072  to increment its 
33073 \emph on
33074 dptr
33075 \emph default
33076
33077 \begin_inset LatexCommand \index{DPTR}
33078
33079 \end_inset
33080
33081 -datapointer
33082 \emph on
33083  
33084 \emph default
33085 so little-endian is the more efficient byte order.
33086 \end_layout
33087
33088 \end_inset
33089
33090
33091 \begin_inset LatexCommand \index{little-endian}
33092
33093 \end_inset
33094
33095
33096 \begin_inset LatexCommand \index{Endianness}
33097
33098 \end_inset
33099
33100  format (i.e.
33101  lowest order first).
33102 \end_layout
33103
33104 \begin_layout Subsection
33105 Highest Order Bit
33106 \begin_inset LatexCommand \index{Highest Order Bit}
33107
33108 \end_inset
33109
33110  / Any Order Bit
33111 \begin_inset LatexCommand \index{Any Order Bit}
33112
33113 \end_inset
33114
33115
33116 \end_layout
33117
33118 \begin_layout Standard
33119 It is frequently required to obtain the highest order bit of an integral
33120  type (long, int, short or char types).
33121  Also obtaining any other order bit is not uncommon.
33122  SDCC recognizes the following expressions to yield the highest order bit
33123  and generates optimized code for it, e.g.:
33124 \end_layout
33125
33126 \begin_layout Verse
33127
33128 \family typewriter
33129 unsigned int gint; 
33130 \newline
33131
33132 \newline
33133 foo () { 
33134 \newline
33135 \InsetSpace ~
33136 \InsetSpace ~
33137 unsigned char hob1, aob1; 
33138 \newline
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 bit hob2, hob3, aob2,
33142  aob3; 
33143 \newline
33144 \InsetSpace ~
33145 \InsetSpace ~
33146 ...
33147  
33148 \newline
33149 \InsetSpace ~
33150 \InsetSpace ~
33151 hob1 = (gint >> 15) & 1; 
33152 \newline
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 hob2 = (gint >> 15) & 1; 
33156 \newline
33157 \InsetSpace ~
33158 \InsetSpace ~
33159 hob3 = gint & 0x8000;
33160  
33161 \newline
33162 \InsetSpace ~
33163 \InsetSpace ~
33164 aob1 = (gint >> 9) & 1; 
33165 \newline
33166 \InsetSpace ~
33167 \InsetSpace ~
33168 aob2 = (gint >> 8) & 1; 
33169 \newline
33170 \InsetSpace ~
33171 \InsetSpace ~
33172 aob3 = gint & 0x0800; 
33173 \newline
33174 \InsetSpace ~
33175 \InsetSpace ~
33176 ..
33177  
33178 \newline
33179 }
33180 \end_layout
33181
33182 \begin_layout Standard
33183 will generate the following code:
33184 \end_layout
33185
33186 \begin_layout Verse
33187
33188 \family typewriter
33189 \InsetSpace ~
33190 \InsetSpace ~
33191 \InsetSpace ~
33192 \InsetSpace ~
33193 \InsetSpace ~
33194 \InsetSpace ~
33195 \InsetSpace ~
33196 \InsetSpace ~
33197 \InsetSpace ~
33198 \InsetSpace ~
33199 \InsetSpace ~
33200 \InsetSpace ~
33201 \InsetSpace ~
33202 \InsetSpace ~
33203 \InsetSpace ~
33204 \InsetSpace ~
33205 \InsetSpace ~
33206 \InsetSpace ~
33207 \InsetSpace ~
33208 \InsetSpace ~
33209 \InsetSpace ~
33210 \InsetSpace ~
33211 \InsetSpace ~
33212 \InsetSpace ~
33213 \InsetSpace ~
33214  61 ;\InsetSpace ~
33215  hob.c 7 
33216 \newline
33217 000A E5*01\InsetSpace ~
33218 \InsetSpace ~
33219 \InsetSpace ~
33220 \InsetSpace ~
33221 \InsetSpace ~
33222 \InsetSpace ~
33223 \InsetSpace ~
33224 \InsetSpace ~
33225 \InsetSpace ~
33226 \InsetSpace ~
33227 \InsetSpace ~
33228 \InsetSpace ~
33229 \InsetSpace ~
33230 \InsetSpace ~
33231 \InsetSpace ~
33232  62\InsetSpace ~
33233 \InsetSpace ~
33234 \InsetSpace ~
33235 \InsetSpace ~
33236 \InsetSpace ~
33237 \InsetSpace ~
33238 \InsetSpace ~
33239 \InsetSpace ~
33240  mov\InsetSpace ~
33241 \InsetSpace ~
33242  a,(_gint + 1) 
33243 \newline
33244 000C 23\InsetSpace ~
33245 \InsetSpace ~
33246 \InsetSpace ~
33247 \InsetSpace ~
33248 \InsetSpace ~
33249 \InsetSpace ~
33250 \InsetSpace ~
33251 \InsetSpace ~
33252 \InsetSpace ~
33253 \InsetSpace ~
33254 \InsetSpace ~
33255 \InsetSpace ~
33256 \InsetSpace ~
33257 \InsetSpace ~
33258 \InsetSpace ~
33259 \InsetSpace ~
33260 \InsetSpace ~
33261 \InsetSpace ~
33262  63\InsetSpace ~
33263 \InsetSpace ~
33264 \InsetSpace ~
33265 \InsetSpace ~
33266 \InsetSpace ~
33267 \InsetSpace ~
33268 \InsetSpace ~
33269 \InsetSpace ~
33270  rl\InsetSpace ~
33271 \InsetSpace ~
33272 \InsetSpace ~
33273  a 
33274 \newline
33275 000D 54 01\InsetSpace ~
33276 \InsetSpace ~
33277 \InsetSpace ~
33278 \InsetSpace ~
33279 \InsetSpace ~
33280 \InsetSpace ~
33281 \InsetSpace ~
33282 \InsetSpace ~
33283 \InsetSpace ~
33284 \InsetSpace ~
33285 \InsetSpace ~
33286 \InsetSpace ~
33287 \InsetSpace ~
33288 \InsetSpace ~
33289 \InsetSpace ~
33290
33291  64\InsetSpace ~
33292 \InsetSpace ~
33293 \InsetSpace ~
33294 \InsetSpace ~
33295 \InsetSpace ~
33296 \InsetSpace ~
33297 \InsetSpace ~
33298 \InsetSpace ~
33299  anl\InsetSpace ~
33300 \InsetSpace ~
33301  a,#0x01 
33302 \newline
33303 000F F5*02\InsetSpace ~
33304 \InsetSpace ~
33305 \InsetSpace ~
33306 \InsetSpace ~
33307 \InsetSpace ~
33308 \InsetSpace ~
33309 \InsetSpace ~
33310 \InsetSpace ~
33311 \InsetSpace ~
33312 \InsetSpace ~
33313 \InsetSpace ~
33314 \InsetSpace ~
33315 \InsetSpace ~
33316 \InsetSpace ~
33317 \InsetSpace ~
33318  65\InsetSpace ~
33319 \InsetSpace ~
33320 \InsetSpace ~
33321 \InsetSpace ~
33322 \InsetSpace ~
33323 \InsetSpace ~
33324 \InsetSpace ~
33325 \InsetSpace ~
33326  mov\InsetSpace ~
33327 \InsetSpace ~
33328  _foo_hob1_1_1,a 
33329 \newline
33330 \InsetSpace ~
33331 \InsetSpace ~
33332 \InsetSpace ~
33333 \InsetSpace ~
33334 \InsetSpace ~
33335 \InsetSpace ~
33336 \InsetSpace ~
33337 \InsetSpace ~
33338 \InsetSpace ~
33339 \InsetSpace ~
33340 \InsetSpace ~
33341 \InsetSpace ~
33342 \InsetSpace ~
33343 \InsetSpace ~
33344 \InsetSpace ~
33345 \InsetSpace ~
33346 \InsetSpace ~
33347 \InsetSpace ~
33348 \InsetSpace ~
33349 \InsetSpace ~
33350 \InsetSpace ~
33351 \InsetSpace ~
33352 \InsetSpace ~
33353 \InsetSpace ~
33354 \InsetSpace ~
33355  66 ;\InsetSpace ~
33356  hob.c 8 
33357 \newline
33358 0011 E5*01\InsetSpace ~
33359 \InsetSpace ~
33360 \InsetSpace ~
33361 \InsetSpace ~
33362 \InsetSpace ~
33363 \InsetSpace ~
33364 \InsetSpace ~
33365 \InsetSpace ~
33366 \InsetSpace ~
33367 \InsetSpace ~
33368 \InsetSpace ~
33369 \InsetSpace ~
33370 \InsetSpace ~
33371 \InsetSpace ~
33372 \InsetSpace ~
33373
33374  67\InsetSpace ~
33375 \InsetSpace ~
33376 \InsetSpace ~
33377 \InsetSpace ~
33378 \InsetSpace ~
33379 \InsetSpace ~
33380 \InsetSpace ~
33381 \InsetSpace ~
33382  mov\InsetSpace ~
33383 \InsetSpace ~
33384  a,(_gint + 1) 
33385 \newline
33386 0013 33\InsetSpace ~
33387 \InsetSpace ~
33388 \InsetSpace ~
33389 \InsetSpace ~
33390 \InsetSpace ~
33391 \InsetSpace ~
33392 \InsetSpace ~
33393 \InsetSpace ~
33394 \InsetSpace ~
33395 \InsetSpace ~
33396 \InsetSpace ~
33397 \InsetSpace ~
33398 \InsetSpace ~
33399 \InsetSpace ~
33400 \InsetSpace ~
33401 \InsetSpace ~
33402 \InsetSpace ~
33403 \InsetSpace ~
33404  68\InsetSpace ~
33405 \InsetSpace ~
33406 \InsetSpace ~
33407 \InsetSpace ~
33408 \InsetSpace ~
33409 \InsetSpace ~
33410 \InsetSpace ~
33411 \InsetSpace ~
33412  rlc\InsetSpace ~
33413 \InsetSpace ~
33414  a 
33415 \newline
33416 0014 92*00\InsetSpace ~
33417 \InsetSpace ~
33418 \InsetSpace ~
33419 \InsetSpace ~
33420 \InsetSpace ~
33421 \InsetSpace ~
33422 \InsetSpace ~
33423 \InsetSpace ~
33424 \InsetSpace ~
33425 \InsetSpace ~
33426 \InsetSpace ~
33427 \InsetSpace ~
33428 \InsetSpace ~
33429 \InsetSpace ~
33430 \InsetSpace ~
33431  69\InsetSpace ~
33432 \InsetSpace ~
33433 \InsetSpace ~
33434 \InsetSpace ~
33435 \InsetSpace ~
33436 \InsetSpace ~
33437 \InsetSpace ~
33438 \InsetSpace ~
33439  mov\InsetSpace ~
33440 \InsetSpace ~
33441  _foo_hob2_1_1,c
33442  
33443 \newline
33444 \InsetSpace ~
33445 \InsetSpace ~
33446 \InsetSpace ~
33447 \InsetSpace ~
33448 \InsetSpace ~
33449 \InsetSpace ~
33450 \InsetSpace ~
33451 \InsetSpace ~
33452 \InsetSpace ~
33453 \InsetSpace ~
33454 \InsetSpace ~
33455 \InsetSpace ~
33456 \InsetSpace ~
33457 \InsetSpace ~
33458 \InsetSpace ~
33459 \InsetSpace ~
33460 \InsetSpace ~
33461 \InsetSpace ~
33462 \InsetSpace ~
33463 \InsetSpace ~
33464 \InsetSpace ~
33465 \InsetSpace ~
33466 \InsetSpace ~
33467 \InsetSpace ~
33468 \InsetSpace ~
33469  66 ;\InsetSpace ~
33470  hob.c 9 
33471 \newline
33472 0016 E5*01\InsetSpace ~
33473 \InsetSpace ~
33474 \InsetSpace ~
33475 \InsetSpace ~
33476 \InsetSpace ~
33477 \InsetSpace ~
33478 \InsetSpace ~
33479 \InsetSpace ~
33480 \InsetSpace ~
33481 \InsetSpace ~
33482 \InsetSpace ~
33483 \InsetSpace ~
33484 \InsetSpace ~
33485 \InsetSpace ~
33486 \InsetSpace ~
33487  67\InsetSpace ~
33488 \InsetSpace ~
33489 \InsetSpace ~
33490 \InsetSpace ~
33491 \InsetSpace ~
33492 \InsetSpace ~
33493 \InsetSpace ~
33494 \InsetSpace ~
33495  mov\InsetSpace ~
33496 \InsetSpace ~
33497  a,(_gint + 1) 
33498 \newline
33499 0018 33\InsetSpace ~
33500 \InsetSpace ~
33501 \InsetSpace ~
33502 \InsetSpace ~
33503 \InsetSpace ~
33504 \InsetSpace ~
33505 \InsetSpace ~
33506 \InsetSpace ~
33507 \InsetSpace ~
33508 \InsetSpace ~
33509 \InsetSpace ~
33510 \InsetSpace ~
33511 \InsetSpace ~
33512 \InsetSpace ~
33513 \InsetSpace ~
33514 \InsetSpace ~
33515 \InsetSpace ~
33516 \InsetSpace ~
33517  68\InsetSpace ~
33518 \InsetSpace ~
33519 \InsetSpace ~
33520 \InsetSpace ~
33521 \InsetSpace ~
33522 \InsetSpace ~
33523 \InsetSpace ~
33524 \InsetSpace ~
33525  rlc\InsetSpace ~
33526 \InsetSpace ~
33527  a 
33528 \newline
33529 0019 92*01\InsetSpace ~
33530 \InsetSpace ~
33531 \InsetSpace ~
33532 \InsetSpace ~
33533 \InsetSpace ~
33534 \InsetSpace ~
33535 \InsetSpace ~
33536 \InsetSpace ~
33537 \InsetSpace ~
33538 \InsetSpace ~
33539 \InsetSpace ~
33540 \InsetSpace ~
33541 \InsetSpace ~
33542 \InsetSpace ~
33543 \InsetSpace ~
33544
33545  69\InsetSpace ~
33546 \InsetSpace ~
33547 \InsetSpace ~
33548 \InsetSpace ~
33549 \InsetSpace ~
33550 \InsetSpace ~
33551 \InsetSpace ~
33552 \InsetSpace ~
33553  mov\InsetSpace ~
33554 \InsetSpace ~
33555  _foo_hob3_1_1,c 
33556 \newline
33557 \InsetSpace ~
33558 \InsetSpace ~
33559 \InsetSpace ~
33560 \InsetSpace ~
33561 \InsetSpace ~
33562 \InsetSpace ~
33563 \InsetSpace ~
33564 \InsetSpace ~
33565 \InsetSpace ~
33566 \InsetSpace ~
33567 \InsetSpace ~
33568 \InsetSpace ~
33569 \InsetSpace ~
33570 \InsetSpace ~
33571 \InsetSpace ~
33572 \InsetSpace ~
33573 \InsetSpace ~
33574 \InsetSpace ~
33575 \InsetSpace ~
33576 \InsetSpace ~
33577 \InsetSpace ~
33578 \InsetSpace ~
33579 \InsetSpace ~
33580 \InsetSpace ~
33581 \InsetSpace ~
33582  70 ;\InsetSpace ~
33583  hob.c 10 
33584 \newline
33585 001B E5*01\InsetSpace ~
33586 \InsetSpace ~
33587 \InsetSpace ~
33588 \InsetSpace ~
33589 \InsetSpace ~
33590 \InsetSpace ~
33591 \InsetSpace ~
33592 \InsetSpace ~
33593 \InsetSpace ~
33594 \InsetSpace ~
33595 \InsetSpace ~
33596 \InsetSpace ~
33597 \InsetSpace ~
33598 \InsetSpace ~
33599 \InsetSpace ~
33600  71\InsetSpace ~
33601 \InsetSpace ~
33602 \InsetSpace ~
33603 \InsetSpace ~
33604 \InsetSpace ~
33605 \InsetSpace ~
33606 \InsetSpace ~
33607 \InsetSpace ~
33608  mov\InsetSpace ~
33609 \InsetSpace ~
33610  a,(_gint + 1) 
33611 \newline
33612 001D
33613  03\InsetSpace ~
33614 \InsetSpace ~
33615 \InsetSpace ~
33616 \InsetSpace ~
33617 \InsetSpace ~
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  72\InsetSpace ~
33632 \InsetSpace ~
33633 \InsetSpace ~
33634 \InsetSpace ~
33635 \InsetSpace ~
33636 \InsetSpace ~
33637 \InsetSpace ~
33638 \InsetSpace ~
33639  rr\InsetSpace ~
33640 \InsetSpace ~
33641 \InsetSpace ~
33642  a 
33643 \newline
33644 001E 54 01\InsetSpace ~
33645 \InsetSpace ~
33646 \InsetSpace ~
33647 \InsetSpace ~
33648 \InsetSpace ~
33649 \InsetSpace ~
33650 \InsetSpace ~
33651 \InsetSpace ~
33652 \InsetSpace ~
33653 \InsetSpace ~
33654 \InsetSpace ~
33655 \InsetSpace ~
33656 \InsetSpace ~
33657 \InsetSpace ~
33658 \InsetSpace ~
33659  73\InsetSpace ~
33660 \InsetSpace ~
33661 \InsetSpace ~
33662 \InsetSpace ~
33663 \InsetSpace ~
33664 \InsetSpace ~
33665 \InsetSpace ~
33666 \InsetSpace ~
33667  anl\InsetSpace ~
33668 \InsetSpace ~
33669  a,#0x01 
33670 \newline
33671 0020 F5*03\InsetSpace ~
33672 \InsetSpace ~
33673 \InsetSpace ~
33674 \InsetSpace ~
33675 \InsetSpace ~
33676 \InsetSpace ~
33677 \InsetSpace ~
33678 \InsetSpace ~
33679 \InsetSpace ~
33680 \InsetSpace ~
33681 \InsetSpace ~
33682 \InsetSpace ~
33683 \InsetSpace ~
33684 \InsetSpace ~
33685 \InsetSpace ~
33686  74\InsetSpace ~
33687 \InsetSpace ~
33688 \InsetSpace ~
33689 \InsetSpace ~
33690 \InsetSpace ~
33691 \InsetSpace ~
33692 \InsetSpace ~
33693 \InsetSpace ~
33694  mov\InsetSpace ~
33695 \InsetSpace ~
33696  _foo_aob1_1_1,a
33697  
33698 \newline
33699 \InsetSpace ~
33700 \InsetSpace ~
33701 \InsetSpace ~
33702 \InsetSpace ~
33703 \InsetSpace ~
33704 \InsetSpace ~
33705 \InsetSpace ~
33706 \InsetSpace ~
33707 \InsetSpace ~
33708 \InsetSpace ~
33709 \InsetSpace ~
33710 \InsetSpace ~
33711 \InsetSpace ~
33712 \InsetSpace ~
33713 \InsetSpace ~
33714 \InsetSpace ~
33715 \InsetSpace ~
33716 \InsetSpace ~
33717 \InsetSpace ~
33718 \InsetSpace ~
33719 \InsetSpace ~
33720 \InsetSpace ~
33721 \InsetSpace ~
33722 \InsetSpace ~
33723 \InsetSpace ~
33724  75 ;\InsetSpace ~
33725  hob.c 11 
33726 \newline
33727 0022 E5*01\InsetSpace ~
33728 \InsetSpace ~
33729 \InsetSpace ~
33730 \InsetSpace ~
33731 \InsetSpace ~
33732 \InsetSpace ~
33733 \InsetSpace ~
33734 \InsetSpace ~
33735 \InsetSpace ~
33736 \InsetSpace ~
33737 \InsetSpace ~
33738 \InsetSpace ~
33739 \InsetSpace ~
33740 \InsetSpace ~
33741 \InsetSpace ~
33742  76\InsetSpace ~
33743 \InsetSpace ~
33744 \InsetSpace ~
33745 \InsetSpace ~
33746 \InsetSpace ~
33747 \InsetSpace ~
33748 \InsetSpace ~
33749 \InsetSpace ~
33750  mov\InsetSpace ~
33751 \InsetSpace ~
33752  a,(_gint + 1) 
33753 \newline
33754 0024 13\InsetSpace ~
33755 \InsetSpace ~
33756 \InsetSpace ~
33757 \InsetSpace ~
33758 \InsetSpace ~
33759 \InsetSpace ~
33760 \InsetSpace ~
33761 \InsetSpace ~
33762 \InsetSpace ~
33763 \InsetSpace ~
33764 \InsetSpace ~
33765 \InsetSpace ~
33766 \InsetSpace ~
33767 \InsetSpace ~
33768 \InsetSpace ~
33769 \InsetSpace ~
33770 \InsetSpace ~
33771 \InsetSpace ~
33772  77\InsetSpace ~
33773 \InsetSpace ~
33774 \InsetSpace ~
33775 \InsetSpace ~
33776 \InsetSpace ~
33777 \InsetSpace ~
33778 \InsetSpace ~
33779 \InsetSpace ~
33780  rrc\InsetSpace ~
33781 \InsetSpace ~
33782  a 
33783 \newline
33784 0025 92*02\InsetSpace ~
33785 \InsetSpace ~
33786 \InsetSpace ~
33787 \InsetSpace ~
33788 \InsetSpace ~
33789 \InsetSpace ~
33790 \InsetSpace ~
33791 \InsetSpace ~
33792 \InsetSpace ~
33793 \InsetSpace ~
33794 \InsetSpace ~
33795 \InsetSpace ~
33796 \InsetSpace ~
33797 \InsetSpace ~
33798 \InsetSpace ~
33799
33800  78\InsetSpace ~
33801 \InsetSpace ~
33802 \InsetSpace ~
33803 \InsetSpace ~
33804 \InsetSpace ~
33805 \InsetSpace ~
33806 \InsetSpace ~
33807 \InsetSpace ~
33808  mov\InsetSpace ~
33809 \InsetSpace ~
33810  _foo_aob2_1_1,c 
33811 \newline
33812 \InsetSpace ~
33813 \InsetSpace ~
33814 \InsetSpace ~
33815 \InsetSpace ~
33816 \InsetSpace ~
33817 \InsetSpace ~
33818 \InsetSpace ~
33819 \InsetSpace ~
33820 \InsetSpace ~
33821 \InsetSpace ~
33822 \InsetSpace ~
33823 \InsetSpace ~
33824 \InsetSpace ~
33825 \InsetSpace ~
33826 \InsetSpace ~
33827 \InsetSpace ~
33828 \InsetSpace ~
33829 \InsetSpace ~
33830 \InsetSpace ~
33831 \InsetSpace ~
33832 \InsetSpace ~
33833 \InsetSpace ~
33834 \InsetSpace ~
33835 \InsetSpace ~
33836 \InsetSpace ~
33837  79 ;\InsetSpace ~
33838  hob.c 12 
33839 \newline
33840 0027 E5*01\InsetSpace ~
33841 \InsetSpace ~
33842 \InsetSpace ~
33843 \InsetSpace ~
33844 \InsetSpace ~
33845 \InsetSpace ~
33846 \InsetSpace ~
33847 \InsetSpace ~
33848 \InsetSpace ~
33849 \InsetSpace ~
33850 \InsetSpace ~
33851 \InsetSpace ~
33852 \InsetSpace ~
33853 \InsetSpace ~
33854 \InsetSpace ~
33855  80\InsetSpace ~
33856 \InsetSpace ~
33857 \InsetSpace ~
33858 \InsetSpace ~
33859 \InsetSpace ~
33860 \InsetSpace ~
33861 \InsetSpace ~
33862 \InsetSpace ~
33863  mov\InsetSpace ~
33864 \InsetSpace ~
33865  a,(_gint + 1) 
33866 \newline
33867 0029
33868  A2 E3\InsetSpace ~
33869 \InsetSpace ~
33870 \InsetSpace ~
33871 \InsetSpace ~
33872 \InsetSpace ~
33873 \InsetSpace ~
33874 \InsetSpace ~
33875 \InsetSpace ~
33876 \InsetSpace ~
33877 \InsetSpace ~
33878 \InsetSpace ~
33879 \InsetSpace ~
33880 \InsetSpace ~
33881 \InsetSpace ~
33882 \InsetSpace ~
33883  81\InsetSpace ~
33884 \InsetSpace ~
33885 \InsetSpace ~
33886 \InsetSpace ~
33887 \InsetSpace ~
33888 \InsetSpace ~
33889 \InsetSpace ~
33890 \InsetSpace ~
33891  mov\InsetSpace ~
33892 \InsetSpace ~
33893  c,acc[3] 
33894 \newline
33895 002B 92*03\InsetSpace ~
33896 \InsetSpace ~
33897 \InsetSpace ~
33898 \InsetSpace ~
33899 \InsetSpace ~
33900 \InsetSpace ~
33901 \InsetSpace ~
33902 \InsetSpace ~
33903 \InsetSpace ~
33904 \InsetSpace ~
33905 \InsetSpace ~
33906 \InsetSpace ~
33907 \InsetSpace ~
33908 \InsetSpace ~
33909 \InsetSpace ~
33910  82\InsetSpace ~
33911 \InsetSpace ~
33912 \InsetSpace ~
33913 \InsetSpace ~
33914 \InsetSpace ~
33915 \InsetSpace ~
33916 \InsetSpace ~
33917 \InsetSpace ~
33918  mov\InsetSpace ~
33919 \InsetSpace ~
33920  _foo_aob3_1_1,c 
33921 \end_layout
33922
33923 \begin_layout Standard
33924 Other variations of these cases however will 
33925 \emph on
33926 not
33927 \emph default
33928  be recognized.
33929  They are standard C expressions, so I heartily recommend these be the only
33930  way to get the highest order bit, (it is portable).
33931  Of course it will be recognized even if it is embedded in other expressions,
33932  e.g.:
33933 \end_layout
33934
33935 \begin_layout Verse
33936
33937 \family typewriter
33938 xyz = gint + ((gint >> 15) & 1);
33939 \end_layout
33940
33941 \begin_layout Standard
33942 will still be recognized.
33943 \end_layout
33944
33945 \begin_layout Subsection
33946 Higher Order Byte
33947 \begin_inset LatexCommand \index{Higher Order Byte}
33948
33949 \end_inset
33950
33951  / Higher Order Word
33952 \begin_inset LatexCommand \index{Higher Order Word}
33953
33954 \end_inset
33955
33956
33957 \end_layout
33958
33959 \begin_layout Standard
33960 It is also frequently required to obtain a higher order byte or word of
33961  a larger integral type (long, int or short types).
33962  SDCC recognizes the following expressions to yield the higher order byte
33963  or word and generates optimized code for it, e.g.:
33964 \end_layout
33965
33966 \begin_layout Verse
33967
33968 \family typewriter
33969 unsigned int gint; 
33970 \newline
33971 unsigned long int glong; 
33972 \newline
33973
33974 \newline
33975 foo () { 
33976 \newline
33977 \InsetSpace ~
33978 \InsetSpace ~
33979 unsigned char hob1,
33980  hob2; 
33981 \newline
33982 \InsetSpace ~
33983 \InsetSpace ~
33984 unsigned int how1, how2; 
33985 \newline
33986 \InsetSpace ~
33987 \InsetSpace ~
33988 ...
33989  
33990 \newline
33991 \InsetSpace ~
33992 \InsetSpace ~
33993 hob1 = (gint >> 8) & 0xFF; 
33994 \newline
33995 \InsetSpace ~
33996 \InsetSpace ~
33997 hob2 = glong >> 24; 
33998 \newline
33999 \InsetSpace ~
34000 \InsetSpace ~
34001 how1 = (glong >> 16) & 0xFFFF;
34002  
34003 \newline
34004 \InsetSpace ~
34005 \InsetSpace ~
34006 how2 = glong >> 8; 
34007 \newline
34008 \InsetSpace ~
34009 \InsetSpace ~
34010 ..
34011  
34012 \newline
34013 }
34014 \end_layout
34015
34016 \begin_layout Standard
34017 will generate the following code:
34018 \end_layout
34019
34020 \begin_layout Verse
34021
34022 \family typewriter
34023 \InsetSpace ~
34024 \InsetSpace ~
34025 \InsetSpace ~
34026 \InsetSpace ~
34027 \InsetSpace ~
34028 \InsetSpace ~
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 \InsetSpace ~
34032 \InsetSpace ~
34033 \InsetSpace ~
34034 \InsetSpace ~
34035 \InsetSpace ~
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 \InsetSpace ~
34039 \InsetSpace ~
34040 \InsetSpace ~
34041 \InsetSpace ~
34042 \InsetSpace ~
34043 \InsetSpace ~
34044 \InsetSpace ~
34045 \InsetSpace ~
34046 \InsetSpace ~
34047 \InsetSpace ~
34048  91 ;\InsetSpace ~
34049  hob.c 15 
34050 \newline
34051 0037 85*01*06\InsetSpace ~
34052 \InsetSpace ~
34053 \InsetSpace ~
34054 \InsetSpace ~
34055 \InsetSpace ~
34056 \InsetSpace ~
34057 \InsetSpace ~
34058 \InsetSpace ~
34059 \InsetSpace ~
34060 \InsetSpace ~
34061 \InsetSpace ~
34062 \InsetSpace ~
34063  92\InsetSpace ~
34064 \InsetSpace ~
34065 \InsetSpace ~
34066 \InsetSpace ~
34067 \InsetSpace ~
34068 \InsetSpace ~
34069 \InsetSpace ~
34070 \InsetSpace ~
34071  mov\InsetSpace ~
34072 \InsetSpace ~
34073  _foo_hob1_1_1,(_gint + 1) 
34074 \newline
34075 \InsetSpace ~
34076 \InsetSpace ~
34077 \InsetSpace ~
34078 \InsetSpace ~
34079 \InsetSpace ~
34080 \InsetSpace ~
34081 \InsetSpace ~
34082 \InsetSpace ~
34083 \InsetSpace ~
34084 \InsetSpace ~
34085 \InsetSpace ~
34086 \InsetSpace ~
34087 \InsetSpace ~
34088 \InsetSpace ~
34089 \InsetSpace ~
34090 \InsetSpace ~
34091 \InsetSpace ~
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 \InsetSpace ~
34099 \InsetSpace ~
34100  93 ;\InsetSpace ~
34101  hob.c
34102  16 
34103 \newline
34104 003A 85*05*07\InsetSpace ~
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 \InsetSpace ~
34109 \InsetSpace ~
34110 \InsetSpace ~
34111 \InsetSpace ~
34112 \InsetSpace ~
34113 \InsetSpace ~
34114 \InsetSpace ~
34115 \InsetSpace ~
34116  94\InsetSpace ~
34117 \InsetSpace ~
34118 \InsetSpace ~
34119 \InsetSpace ~
34120 \InsetSpace ~
34121 \InsetSpace ~
34122 \InsetSpace ~
34123 \InsetSpace ~
34124  mov\InsetSpace ~
34125 \InsetSpace ~
34126  _foo_hob2_1_1,(_glong + 3) 
34127 \newline
34128 \InsetSpace ~
34129 \InsetSpace ~
34130 \InsetSpace ~
34131 \InsetSpace ~
34132 \InsetSpace ~
34133 \InsetSpace ~
34134 \InsetSpace ~
34135 \InsetSpace ~
34136 \InsetSpace ~
34137 \InsetSpace ~
34138 \InsetSpace ~
34139 \InsetSpace ~
34140 \InsetSpace ~
34141 \InsetSpace ~
34142 \InsetSpace ~
34143 \InsetSpace ~
34144 \InsetSpace ~
34145 \InsetSpace ~
34146 \InsetSpace ~
34147 \InsetSpace ~
34148 \InsetSpace ~
34149 \InsetSpace ~
34150 \InsetSpace ~
34151 \InsetSpace ~
34152 \InsetSpace ~
34153  95 ;\InsetSpace ~
34154  hob.c 17 
34155 \newline
34156 003D 85*04*08\InsetSpace ~
34157 \InsetSpace ~
34158 \InsetSpace ~
34159 \InsetSpace ~
34160 \InsetSpace ~
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 \InsetSpace ~
34166 \InsetSpace ~
34167 \InsetSpace ~
34168
34169  96\InsetSpace ~
34170 \InsetSpace ~
34171 \InsetSpace ~
34172 \InsetSpace ~
34173 \InsetSpace ~
34174 \InsetSpace ~
34175 \InsetSpace ~
34176 \InsetSpace ~
34177  mov\InsetSpace ~
34178 \InsetSpace ~
34179  _foo_how1_1_1,(_glong + 2) 
34180 \newline
34181 0040 85*05*09\InsetSpace ~
34182 \InsetSpace ~
34183 \InsetSpace ~
34184 \InsetSpace ~
34185 \InsetSpace ~
34186 \InsetSpace ~
34187 \InsetSpace ~
34188 \InsetSpace ~
34189 \InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193  97\InsetSpace ~
34194 \InsetSpace ~
34195 \InsetSpace ~
34196 \InsetSpace ~
34197 \InsetSpace ~
34198 \InsetSpace ~
34199 \InsetSpace ~
34200 \InsetSpace ~
34201  mov\InsetSpace ~
34202 \InsetSpace ~
34203  (_foo_how1_1_1 +
34204  1),(_glong + 3) 
34205 \newline
34206 0043 85*03*0A\InsetSpace ~
34207 \InsetSpace ~
34208 \InsetSpace ~
34209 \InsetSpace ~
34210 \InsetSpace ~
34211 \InsetSpace ~
34212 \InsetSpace ~
34213 \InsetSpace ~
34214 \InsetSpace ~
34215 \InsetSpace ~
34216 \InsetSpace ~
34217 \InsetSpace ~
34218  98\InsetSpace ~
34219 \InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225 \InsetSpace ~
34226  mov\InsetSpace ~
34227 \InsetSpace ~
34228  _foo_how2_1_1,(_glong + 1) 
34229 \newline
34230 0046 85*04*0B\InsetSpace ~
34231 \InsetSpace ~
34232 \InsetSpace ~
34233 \InsetSpace ~
34234 \InsetSpace ~
34235 \InsetSpace ~
34236 \InsetSpace ~
34237 \InsetSpace ~
34238 \InsetSpace ~
34239 \InsetSpace ~
34240 \InsetSpace ~
34241 \InsetSpace ~
34242
34243  99\InsetSpace ~
34244 \InsetSpace ~
34245 \InsetSpace ~
34246 \InsetSpace ~
34247 \InsetSpace ~
34248 \InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251  mov\InsetSpace ~
34252 \InsetSpace ~
34253  (_foo_how2_1_1 + 1),(_glong + 2) 
34254 \end_layout
34255
34256 \begin_layout Standard
34257 Again, variations of these cases may 
34258 \emph on
34259 not
34260 \emph default
34261  be recognized.
34262  They are standard C expressions, so I heartily recommend these be the only
34263  way to get the higher order byte/word, (it is portable).
34264  Of course it will be recognized even if it is embedded in other expressions,
34265  e.g.:
34266 \end_layout
34267
34268 \begin_layout Verse
34269
34270 \family typewriter
34271 xyz = gint + ((gint >> 8) & 0xFF);
34272 \end_layout
34273
34274 \begin_layout Standard
34275 will still be recognized.
34276 \end_layout
34277
34278 \begin_layout Subsection
34279 Peephole Optimizer
34280 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34281
34282 \end_inset
34283
34284
34285 \begin_inset LatexCommand \index{Peephole optimizer}
34286
34287 \end_inset
34288
34289
34290 \end_layout
34291
34292 \begin_layout Standard
34293 The compiler uses a rule based, pattern matching and re-writing mechanism
34294  for peep-hole optimization.
34295  It is inspired by 
34296 \emph on
34297 copt
34298 \emph default
34299  a peep-hole optimizer by Christopher W.
34300  Fraser (cwfraser\InsetSpace ~
34301 @\InsetSpace ~
34302 microsoft.com).
34303  A default set of rules are compiled into the compiler, additional rules
34304  may be added with the 
34305 \emph on
34306 -
34307 \begin_inset ERT
34308 status collapsed
34309
34310 \begin_layout Standard
34311
34312
34313 \backslash
34314 /
34315 \end_layout
34316
34317 \end_inset
34318
34319 -peep-file
34320 \begin_inset LatexCommand \index{-\/-peep-file}
34321
34322 \end_inset
34323
34324  <filename>
34325 \emph default
34326  option.
34327  The rule language is best illustrated with examples.
34328 \end_layout
34329
34330 \begin_layout Verse
34331
34332 \family typewriter
34333 replace { 
34334 \newline
34335 \InsetSpace ~
34336 \InsetSpace ~
34337 mov %1,a 
34338 \newline
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 mov a,%1
34342 \newline
34343 } by {
34344 \newline
34345 \InsetSpace ~
34346 \InsetSpace ~
34347 mov %1,a
34348 \newline
34349 }
34350 \end_layout
34351
34352 \begin_layout Standard
34353 The above rule will change the following assembly
34354 \begin_inset LatexCommand \index{Assembler routines}
34355
34356 \end_inset
34357
34358  sequence:
34359 \end_layout
34360
34361 \begin_layout Verse
34362
34363 \family typewriter
34364 mov r1,a 
34365 \newline
34366 mov a,r1
34367 \end_layout
34368
34369 \begin_layout Standard
34370 to
34371 \end_layout
34372
34373 \begin_layout Verse
34374
34375 \family typewriter
34376 mov r1,a
34377 \end_layout
34378
34379 \begin_layout Standard
34380 Note: All occurrences of a 
34381 \emph on
34382 %n
34383 \emph default
34384  (pattern variable) must denote the same string.
34385  With the above rule, the assembly sequence:
34386 \end_layout
34387
34388 \begin_layout Verse
34389
34390 \family typewriter
34391 mov r1,a 
34392 \newline
34393 mov a,r2
34394 \end_layout
34395
34396 \begin_layout Standard
34397 will remain unmodified.
34398 \newline
34399
34400 \newline
34401 Other special case optimizations may be added by the
34402  user (via 
34403 \emph on
34404 -
34405 \begin_inset ERT
34406 status collapsed
34407
34408 \begin_layout Standard
34409
34410
34411 \backslash
34412 /
34413 \end_layout
34414
34415 \end_inset
34416
34417 -peep-file option
34418 \emph default
34419 ).
34420  E.g.
34421  some variants of the 8051 MCU
34422 \begin_inset LatexCommand \index{MCS51 variants}
34423
34424 \end_inset
34425
34426  allow only 
34427 \family typewriter
34428 ajmp
34429 \family default
34430  and 
34431 \family typewriter
34432 acall
34433 \family default
34434 .
34435  The following two rules will change all 
34436 \family typewriter
34437 ljmp
34438 \family default
34439  and 
34440 \family typewriter
34441 lcall
34442 \family default
34443  to 
34444 \family typewriter
34445 ajmp
34446 \family default
34447  and 
34448 \family typewriter
34449 acall
34450 \end_layout
34451
34452 \begin_layout Verse
34453
34454 \family typewriter
34455 replace { lcall %1 } by { acall %1 } 
34456 \newline
34457 replace { ljmp %1 } by { ajmp %1 }
34458 \end_layout
34459
34460 \begin_layout Standard
34461 The 
34462 \emph on
34463 inline-assembler code
34464 \emph default
34465  is also passed through the peep hole optimizer, thus the peephole optimizer
34466  can also be used as an assembly level macro expander.
34467  The rules themselves are MCU dependent whereas the rule language infra-structur
34468 e is MCU independent.
34469  Peephole optimization rules for other MCU can be easily programmed using
34470  the rule language.
34471 \newline
34472
34473 \newline
34474 The syntax for a rule is as follows:
34475 \end_layout
34476
34477 \begin_layout Verse
34478
34479 \family typewriter
34480 rule := replace [ restart ] '{' <assembly sequence> '
34481 \backslash
34482 n' 
34483 \newline
34484 \InsetSpace ~
34485  \InsetSpace ~
34486  \InsetSpace ~
34487  \InsetSpace ~
34488  \InsetSpace ~
34489  \InsetSpace ~
34490  \InsetSpace ~
34491  \InsetSpace ~
34492  \InsetSpace ~
34493  \InsetSpace ~
34494  \InsetSpace ~
34495  \InsetSpace ~
34496  \InsetSpace ~
34497  \InsetSpace ~
34498  '}' by '{' '
34499 \backslash
34500 n' 
34501 \newline
34502 \InsetSpace ~
34503  \InsetSpace ~
34504  \InsetSpace ~
34505  \InsetSpace ~
34506  \InsetSpace ~
34507  \InsetSpace ~
34508  \InsetSpace ~
34509  \InsetSpace ~
34510  \InsetSpace ~
34511  \InsetSpace ~
34512  \InsetSpace ~
34513  \InsetSpace ~
34514  \InsetSpace ~
34515  \InsetSpace ~
34516  \InsetSpace ~
34517  \InsetSpace ~
34518  <assembly sequence> '
34519 \backslash
34520 n' 
34521 \newline
34522 \InsetSpace ~
34523  \InsetSpace ~
34524  \InsetSpace ~
34525  \InsetSpace ~
34526  \InsetSpace ~
34527  \InsetSpace ~
34528  \InsetSpace ~
34529  \InsetSpace ~
34530  \InsetSpace ~
34531  \InsetSpace ~
34532  \InsetSpace ~
34533  \InsetSpace ~
34534  \InsetSpace ~
34535  \InsetSpace ~
34536  '}' [if <functionName> ] '
34537 \backslash
34538 n' 
34539 \end_layout
34540
34541 \begin_layout Standard
34542 <assembly sequence> := assembly instruction (each instruction including
34543  labels must be on a separate line).
34544 \newline
34545
34546 \newline
34547 The optimizer will apply to the rules
34548  one by one from the top in the sequence of their appearance, it will terminate
34549  when all rules are exhausted.
34550  If the 'restart' option is specified, then the optimizer will start matching
34551  the rules again from the top, this option for a rule is expensive (performance)
34552 , it is intended to be used in situations where a transformation will trigger
34553  the same rule again.
34554  An example of this (not a good one, it has side effects) is the following
34555  rule:
34556 \end_layout
34557
34558 \begin_layout Verse
34559
34560 \family typewriter
34561 replace restart { 
34562 \newline
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 pop %1 
34566 \newline
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 push %1 } by { 
34570 \newline
34571 \InsetSpace ~
34572 \InsetSpace ~
34573 ; nop 
34574 \newline
34575 }
34576 \end_layout
34577
34578 \begin_layout Standard
34579 Note that the replace pattern cannot be a blank, but can be a comment line.
34580  Without the 'restart' option only the innermost 'pop' 'push' pair would
34581  be eliminated, i.e.:
34582 \end_layout
34583
34584 \begin_layout Verse
34585
34586 \family typewriter
34587 pop ar1 
34588 \newline
34589 pop ar2 
34590 \newline
34591 push ar2 
34592 \newline
34593 push ar1
34594 \end_layout
34595
34596 \begin_layout Standard
34597 would result in:
34598 \end_layout
34599
34600 \begin_layout Verse
34601
34602 \family typewriter
34603 pop ar1 
34604 \newline
34605 ; nop 
34606 \newline
34607 push ar1
34608 \end_layout
34609
34610 \begin_layout Standard
34611
34612 \emph on
34613 with
34614 \emph default
34615  the restart option the rule will be applied again to the resulting code
34616  and then all the pop-push pairs will be eliminated to yield:
34617 \end_layout
34618
34619 \begin_layout Verse
34620
34621 \family typewriter
34622 ; nop 
34623 \newline
34624 ; nop
34625 \end_layout
34626
34627 \begin_layout Standard
34628 A conditional function can be attached to a rule.
34629  Attaching rules are somewhat more involved, let me illustrate this with
34630  an example.
34631 \end_layout
34632
34633 \begin_layout Verse
34634
34635 \family typewriter
34636 replace { 
34637 \newline
34638 \InsetSpace ~
34639  \InsetSpace ~
34640  \InsetSpace ~
34641 ljmp %5 
34642 \newline
34643 %2:
34644 \newline
34645 } by { 
34646 \newline
34647 \InsetSpace ~
34648  \InsetSpace ~
34649  \InsetSpace ~
34650 sjmp %5 
34651 \newline
34652 %2:
34653 \newline
34654 } if labelInRange
34655 \end_layout
34656
34657 \begin_layout Standard
34658 The optimizer does a look-up of a function name table defined in function
34659  
34660 \emph on
34661 callFuncByName
34662 \emph default
34663  in the source file SDCCpeeph.c, with the name 
34664 \emph on
34665 labelInRange
34666 \emph default
34667 .
34668  If it finds a corresponding entry the function is called.
34669  Note there can be no parameters specified for these functions, in this
34670  case the use of 
34671 \emph on
34672 %5
34673 \emph default
34674  is crucial, since the function 
34675 \emph on
34676 labelInRange
34677 \emph default
34678  expects to find the label in that particular variable (the hash table containin
34679 g the variable bindings is passed as a parameter).
34680  If you want to code more such functions, take a close look at the function
34681  labelInRange and the calling mechanism in source file SDCCpeeph.c.
34682  Currently implemented are 
34683 \emph on
34684 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
34685  24bitMode, portIsDS390, 24bitModeAndPortDS390 
34686 \emph default
34687 and
34688 \emph on
34689  notVolatile
34690 \emph default
34691 .
34692 \end_layout
34693
34694 \begin_layout Standard
34695 I know this whole thing is a little kludgey, but maybe some day we will
34696  have some better means.
34697  If you are looking at this file, you will see the default rules that are
34698  compiled into the compiler, you can add your own rules in the default set
34699  there if you get tired of specifying the -
34700 \begin_inset ERT
34701 status collapsed
34702
34703 \begin_layout Standard
34704
34705
34706 \backslash
34707 /
34708 \end_layout
34709
34710 \end_inset
34711
34712 -peep-file option.
34713 \end_layout
34714
34715 \begin_layout Section
34716 ANSI-Compliance
34717 \begin_inset LatexCommand \index{ANSI-compliance}
34718
34719 \end_inset
34720
34721
34722 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
34723
34724 \end_inset
34725
34726
34727 \end_layout
34728
34729 \begin_layout Standard
34730 The latest publically available version of the standard 
34731 \emph on
34732 ISO/IEC 9899 - Programming languages - C
34733 \emph default
34734  should be available at: 
34735 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
34736
34737 \end_inset
34738
34739 .
34740 \newline
34741
34742 \end_layout
34743
34744 \begin_layout Standard
34745 Deviations from the compliance:
34746 \end_layout
34747
34748 \begin_layout Itemize
34749 functions are not reentrant
34750 \begin_inset LatexCommand \index{reentrant}
34751
34752 \end_inset
34753
34754  unless explicitly declared as such or the 
34755 \series bold
34756 -
34757 \begin_inset ERT
34758 status collapsed
34759
34760 \begin_layout Standard
34761
34762
34763 \backslash
34764 /
34765 \end_layout
34766
34767 \end_inset
34768
34769 -stack-auto
34770 \begin_inset LatexCommand \index{-\/-stack-auto}
34771
34772 \end_inset
34773
34774
34775 \series default
34776  command line option is specified.
34777 \end_layout
34778
34779 \begin_layout Itemize
34780 structures
34781 \begin_inset LatexCommand \index{struct}
34782
34783 \end_inset
34784
34785  and unions
34786 \begin_inset LatexCommand \index{union}
34787
34788 \end_inset
34789
34790  cannot be assigned values directly, cannot be passed as function parameters
34791  or assigned to each other and cannot be a return value
34792 \begin_inset LatexCommand \index{return value}
34793
34794 \end_inset
34795
34796  from a function, e.g.:
34797 \end_layout
34798
34799 \begin_deeper
34800 \begin_layout Verse
34801
34802 \family typewriter
34803 struct s { ...
34804  }; 
34805 \newline
34806 struct s s1, s2; 
34807 \newline
34808 foo() 
34809 \newline
34810
34811 \newline
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 ...
34817  
34818 \newline
34819 \InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
34824 \newline
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828 \InsetSpace ~
34829 ...
34830  
34831 \newline
34832 }
34833 \newline
34834
34835 \series bold
34836 struct
34837 \series default
34838  s foo1 (
34839 \series bold
34840 struct
34841 \series default
34842  s parms) /* invalid in SDCC although allowed in ANSI */
34843 \newline
34844
34845 \newline
34846 \InsetSpace ~
34847 \InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 struct s rets;
34851  
34852 \newline
34853 \InsetSpace ~
34854 \InsetSpace ~
34855 \InsetSpace ~
34856 \InsetSpace ~
34857 ...
34858  
34859 \newline
34860 \InsetSpace ~
34861 \InsetSpace ~
34862 \InsetSpace ~
34863 \InsetSpace ~
34864 return rets; /* is invalid in SDCC although allowed in ANSI */ 
34865 \newline
34866 }
34867 \end_layout
34868
34869 \end_deeper
34870 \begin_layout Itemize
34871 initialization of structure arrays must be fully braced.
34872 \end_layout
34873
34874 \begin_deeper
34875 \begin_layout Verse
34876
34877 \family typewriter
34878 struct s { char x } a[] = {1, 2};\InsetSpace ~
34879 \InsetSpace ~
34880 \InsetSpace ~
34881 \InsetSpace ~
34882 \InsetSpace ~
34883 /* invalid in SDCC */
34884 \newline
34885 struct s { char x
34886  } a[] = {{1}, {2}}; /* OK */
34887 \end_layout
34888
34889 \end_deeper
34890 \begin_layout Itemize
34891 'long long
34892 \begin_inset LatexCommand \index{long long (not supported)}
34893
34894 \end_inset
34895
34896 ' (64 bit integers
34897 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
34898
34899 \end_inset
34900
34901 ) not supported.
34902 \end_layout
34903
34904 \begin_layout Itemize
34905 'double
34906 \begin_inset LatexCommand \index{double (not supported)}
34907
34908 \end_inset
34909
34910 ' precision floating point 
34911 \begin_inset LatexCommand \index{Floating point support}
34912
34913 \end_inset
34914
34915 not supported.
34916 \end_layout
34917
34918 \begin_layout Itemize
34919 Old K&R style
34920 \begin_inset LatexCommand \index{K\&R style}
34921
34922 \end_inset
34923
34924  function declarations are NOT allowed.
34925 \end_layout
34926
34927 \begin_deeper
34928 \begin_layout Verse
34929
34930 \family typewriter
34931 foo(i,j) /* this old style of function declarations */ 
34932 \newline
34933 int i,j; /* are valid
34934  in ANSI but not valid in SDCC */ 
34935 \newline
34936
34937 \newline
34938 \InsetSpace ~
34939 \InsetSpace ~
34940 \InsetSpace ~
34941 \InsetSpace ~
34942 ...
34943  
34944 \newline
34945 }
34946 \end_layout
34947
34948 \end_deeper
34949 \begin_layout Itemize
34950 Most enhancements in C99 are not supported, f.e.:
34951 \end_layout
34952
34953 \begin_deeper
34954 \begin_layout Verse
34955
34956 \family typewriter
34957 \series bold
34958 inline
34959 \begin_inset LatexCommand \index{inline (not supported)}
34960
34961 \end_inset
34962
34963
34964 \series default
34965  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
34966  in C99.
34967  An empty define 
34968 \emph on
34969 #define inline
34970 \emph default
34971  can be used as a work around */
34972 \newline
34973
34974 \newline
34975 for (
34976 \series bold
34977 int
34978 \series default
34979  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
34980 \end_layout
34981
34982 \end_deeper
34983 \begin_layout Itemize
34984 Certain words that are valid identifiers in the standard may be reserved
34985  words in SDCC unless the 
34986 \series bold
34987 -
34988 \begin_inset ERT
34989 status collapsed
34990
34991 \begin_layout Standard
34992
34993
34994 \backslash
34995 /
34996 \end_layout
34997
34998 \end_inset
34999
35000 -std-c89
35001 \begin_inset LatexCommand \index{-\/-std-c89}
35002
35003 \end_inset
35004
35005  or -
35006 \begin_inset ERT
35007 status collapsed
35008
35009 \begin_layout Standard
35010
35011
35012 \backslash
35013 /
35014 \end_layout
35015
35016 \end_inset
35017
35018 -std-c99
35019 \begin_inset LatexCommand \index{-\/-std-c99}
35020
35021 \end_inset
35022
35023
35024 \series default
35025  command line options are used.
35026  These may include (depending on the selected processor): 'at', 'banked',
35027  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35028 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35029  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35030  '_naked'.
35031  Compliant equivalents of these keywords are always available in a form
35032  that begin with two underscores
35033 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35034
35035 \end_inset
35036
35037 , f.e.
35038  '__data' instead of 'data'.
35039 \end_layout
35040
35041 \begin_layout Section
35042 Cyclomatic Complexity
35043 \begin_inset LatexCommand \index{Cyclomatic complexity}
35044
35045 \end_inset
35046
35047
35048 \end_layout
35049
35050 \begin_layout Standard
35051 Cyclomatic complexity of a function is defined as the number of independent
35052  paths the program can take during execution of the function.
35053  This is an important number since it defines the number test cases you
35054  have to generate to validate the function.
35055  The accepted industry standard for complexity number is 10, if the cyclomatic
35056  complexity reported by SDCC exceeds 10 you should think about simplification
35057  of the function logic.
35058  Note that the complexity level is not related to the number of lines of
35059  code in a function.
35060  Large functions can have low complexity, and small functions can have large
35061  complexity levels.
35062  
35063 \newline
35064
35065 \newline
35066 SDCC uses the following formula to compute the complexity:
35067 \newline
35068
35069 \end_layout
35070
35071 \begin_layout Standard
35072 complexity = (number of edges in control flow graph) - (number of nodes
35073  in control flow graph) + 2;
35074 \newline
35075
35076 \newline
35077 Having said that the industry standard is 10,
35078  you should be aware that in some cases it be may unavoidable to have a
35079  complexity level of less than 10.
35080  For example if you have switch statement with more than 10 case labels,
35081  each case label adds one to the complexity level.
35082  The complexity level is by no means an absolute measure of the algorithmic
35083  complexity of the function, it does however provide a good starting point
35084  for which functions you might look at for further optimization.
35085 \end_layout
35086
35087 \begin_layout Section
35088 Retargetting for other Processors
35089 \end_layout
35090
35091 \begin_layout Standard
35092 The issues for retargetting the compiler are far too numerous to be covered
35093  by this document.
35094  What follows is a brief description of each of the seven phases of the
35095  compiler and its MCU dependency.
35096 \end_layout
35097
35098 \begin_layout Itemize
35099 Parsing the source and building the annotated parse tree.
35100  This phase is largely MCU independent (except for the language extensions).
35101  Syntax & semantic checks are also done in this phase, along with some initial
35102  optimizations like back patching labels and the pattern matching optimizations
35103  like bit-rotation etc.
35104 \end_layout
35105
35106 \begin_layout Itemize
35107 The second phase involves generating an intermediate code which can be easy
35108  manipulated during the later phases.
35109  This phase is entirely MCU independent.
35110  The intermediate code generation assumes the target machine has unlimited
35111  number of registers, and designates them with the name iTemp.
35112  The compiler can be made to dump a human readable form of the code generated
35113  by using the -
35114 \begin_inset ERT
35115 status collapsed
35116
35117 \begin_layout Standard
35118
35119
35120 \backslash
35121 /
35122 \end_layout
35123
35124 \end_inset
35125
35126 -dumpraw option.
35127 \end_layout
35128
35129 \begin_layout Itemize
35130 This phase does the bulk of the standard optimizations and is also MCU independe
35131 nt.
35132  This phase can be broken down into several sub-phases:
35133 \newline
35134
35135 \newline
35136 Break down intermediate
35137  code (iCode) into basic blocks.
35138 \newline
35139 Do control flow & data flow analysis on the
35140  basic blocks.
35141 \newline
35142 Do local common subexpression elimination, then global subexpressio
35143 n elimination
35144 \newline
35145 Dead code elimination
35146 \newline
35147 Loop optimizations
35148 \newline
35149 If loop optimizations
35150  caused any changes then do 'global subexpression elimination' and 'dead
35151  code elimination' again.
35152 \end_layout
35153
35154 \begin_layout Itemize
35155 This phase determines the live-ranges; by live range I mean those iTemp
35156  variables defined by the compiler that still survive after all the optimization
35157 s.
35158  Live range analysis
35159 \begin_inset LatexCommand \index{Live range analysis}
35160
35161 \end_inset
35162
35163  is essential for register allocation, since these computation determines
35164  which of these iTemps will be assigned to registers, and for how long.
35165 \end_layout
35166
35167 \begin_layout Itemize
35168 Phase five is register allocation.
35169  There are two parts to this process.
35170 \newline
35171
35172 \newline
35173 The first part I call 'register packing'
35174  (for lack of a better term).
35175  In this case several MCU specific expression folding is done to reduce
35176  register pressure.
35177 \newline
35178
35179 \newline
35180 The second part is more MCU independent and deals with
35181  allocating registers to the remaining live ranges.
35182  A lot of MCU specific code does creep into this phase because of the limited
35183  number of index registers available in the 8051.
35184 \end_layout
35185
35186 \begin_layout Itemize
35187 The Code generation phase is (unhappily), entirely MCU dependent and very
35188  little (if any at all) of this code can be reused for other MCU.
35189  However the scheme for allocating a homogenized assembler operand for each
35190  iCode operand may be reused.
35191 \end_layout
35192
35193 \begin_layout Itemize
35194 As mentioned in the optimization section the peep-hole optimizer is rule
35195  based system, which can reprogrammed for other MCUs.
35196 \end_layout
35197
35198 \begin_layout Standard
35199 More information is available in a wiki
35200 \begin_inset LatexCommand \index{wiki}
35201
35202 \end_inset
35203
35204  (preliminary link 
35205 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35206
35207 \end_inset
35208
35209 ) and in the thread 
35210 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35211
35212 \end_inset
35213
35214  .
35215 \end_layout
35216
35217 \begin_layout Chapter
35218 Compiler internals
35219 \begin_inset LatexCommand \index{Compiler internals}
35220
35221 \end_inset
35222
35223
35224 \end_layout
35225
35226 \begin_layout Section
35227 The anatomy of the compiler
35228 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35229
35230 \end_inset
35231
35232
35233 \end_layout
35234
35235 \begin_layout Standard
35236
35237 \shape italic
35238 This is an excerpt from an article published in Circuit Cellar Magazine
35239  in 
35240 \series bold
35241 August 2000
35242 \series default
35243 .
35244  It's a little outdated (the compiler is much more efficient now and user/develo
35245 per friendly), but pretty well exposes the guts of it all.
35246 \shape default
35247
35248 \newline
35249
35250 \newline
35251 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35252  It is fairly easy to retarget for other 8-bit MCU.
35253  Here we take a look at some of the internals of the compiler.
35254  
35255 \end_layout
35256
35257 \begin_layout Paragraph*
35258 Parsing
35259 \begin_inset LatexCommand \index{Parsing}
35260
35261 \end_inset
35262
35263  
35264 \end_layout
35265
35266 \begin_layout Standard
35267 Parsing the input source file and creating an AST (Annotated Syntax Tree
35268 \begin_inset LatexCommand \index{Annotated syntax tree}
35269
35270 \end_inset
35271
35272 ).
35273  This phase also involves propagating types (annotating each node of the
35274  parse tree with type information) and semantic analysis.
35275  There are some MCU specific parsing rules.
35276  For example the storage classes, the extended storage classes are MCU specific
35277  while there may be a xdata storage class for 8051 there is no such storage
35278  class for z80 or Atmel AVR.
35279  SDCC allows MCU specific storage class extensions, i.e.
35280  xdata will be treated as a storage class specifier when parsing 8051 C
35281  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35282  C code.
35283 \end_layout
35284
35285 \begin_layout Paragraph*
35286 Generating iCode
35287 \begin_inset LatexCommand \index{iCode}
35288
35289 \end_inset
35290
35291
35292 \end_layout
35293
35294 \begin_layout Standard
35295 Intermediate code generation.
35296  In this phase the AST is broken down into three-operand form (iCode).
35297  These three operand forms are represented as doubly linked lists.
35298  ICode is the term given to the intermediate form generated by the compiler.
35299  ICode example section shows some examples of iCode generated for some simple
35300  C source functions.
35301 \end_layout
35302
35303 \begin_layout Paragraph*
35304 Optimizations
35305 \begin_inset LatexCommand \index{Optimizations}
35306
35307 \end_inset
35308
35309 .
35310 \end_layout
35311
35312 \begin_layout Standard
35313 Bulk of the target independent optimizations is performed in this phase.
35314  The optimizations include constant propagation, common sub-expression eliminati
35315 on, loop invariant code movement, strength reduction of loop induction variables
35316  and dead-code elimination.
35317 \end_layout
35318
35319 \begin_layout Paragraph*
35320 Live range analysis
35321 \begin_inset LatexCommand \index{Live range analysis}
35322
35323 \end_inset
35324
35325
35326 \end_layout
35327
35328 \begin_layout Standard
35329 During intermediate code generation phase, the compiler assumes the target
35330  machine has infinite number of registers and generates a lot of temporary
35331  variables.
35332  The live range computation determines the lifetime of each of these compiler-ge
35333 nerated temporaries.
35334  A picture speaks a thousand words.
35335  ICode example sections show the live range annotations for each of the
35336  operand.
35337  It is important to note here, each iCode is assigned a number in the order
35338  of its execution in the function.
35339  The live ranges are computed in terms of these numbers.
35340  The from number is the number of the iCode which first defines the operand
35341  and the to number signifies the iCode which uses this operand last.
35342 \end_layout
35343
35344 \begin_layout Paragraph*
35345 Register Allocation
35346 \begin_inset LatexCommand \index{Register allocation}
35347
35348 \end_inset
35349
35350
35351 \end_layout
35352
35353 \begin_layout Standard
35354 The register allocation determines the type and number of registers needed
35355  by each operand.
35356  In most MCUs only a few registers can be used for indirect addressing.
35357  In case of 8051 for example the registers R0 & R1 can be used to indirectly
35358  address the internal ram and DPTR to indirectly address the external ram.
35359  The compiler will try to allocate the appropriate register to pointer variables
35360  if it can.
35361  ICode example section shows the operands annotated with the registers assigned
35362  to them.
35363  The compiler will try to keep operands in registers as much as possible;
35364  there are several schemes the compiler uses to do achieve this.
35365  When the compiler runs out of registers the compiler will check to see
35366  if there are any live operands which is not used or defined in the current
35367  basic block being processed, if there are any found then it will push that
35368  operand and use the registers in this block, the operand will then be popped
35369  at the end of the basic block.
35370  
35371 \end_layout
35372
35373 \begin_layout Standard
35374 There are other MCU specific considerations in this phase.
35375  Some MCUs have an accumulator; very short-lived operands could be assigned
35376  to the accumulator instead of a general-purpose register.
35377 \end_layout
35378
35379 \begin_layout Paragraph*
35380 Code generation
35381 \end_layout
35382
35383 \begin_layout Standard
35384 Figure II gives a table of iCode
35385 \begin_inset LatexCommand \index{iCode}
35386
35387 \end_inset
35388
35389  operations supported by the compiler.
35390  The code generation involves translating these operations into corresponding
35391  assembly code for the processor.
35392  This sounds overly simple but that is the essence of code generation.
35393  Some of the iCode operations are generated on a MCU specific manner for
35394  example, the z80 port does not use registers to pass parameters so the
35395  SEND and RECV iCode operations will not be generated, and it also does
35396  not support JUMPTABLES.
35397  
35398 \newline
35399
35400 \end_layout
35401
35402 \begin_layout Standard
35403
35404 \size footnotesize
35405 Figure II 
35406 \begin_inset Tabular
35407 <lyxtabular version="3" rows="39" columns="4">
35408 <features islongtable="true" headBottomDL="true">
35409 <column alignment="block" valignment="top" leftline="true" width="13col%">
35410 <column alignment="left" valignment="top" leftline="true" width="13col%">
35411 <column alignment="block" valignment="top" leftline="true" width="22col%">
35412 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
35413 <row topline="true" bottomline="true" endhead="true">
35414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35415 \begin_inset Text
35416
35417 \begin_layout Standard
35418
35419 \series bold
35420 iCode
35421 \series default
35422
35423 \begin_inset LatexCommand \index{iCode}
35424
35425 \end_inset
35426
35427
35428 \end_layout
35429
35430 \end_inset
35431 </cell>
35432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35433 \begin_inset Text
35434
35435 \begin_layout Standard
35436
35437 \series bold
35438 Operands
35439 \end_layout
35440
35441 \end_inset
35442 </cell>
35443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35444 \begin_inset Text
35445
35446 \begin_layout Standard
35447
35448 \series bold
35449 Description
35450 \end_layout
35451
35452 \end_inset
35453 </cell>
35454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35455 \begin_inset Text
35456
35457 \begin_layout Standard
35458
35459 \series bold
35460 C Equivalent
35461 \end_layout
35462
35463 \end_inset
35464 </cell>
35465 </row>
35466 <row topline="true">
35467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35468 \begin_inset Text
35469
35470 \begin_layout Standard
35471
35472 \size footnotesize
35473 '!'
35474 \end_layout
35475
35476 \end_inset
35477 </cell>
35478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35479 \begin_inset Text
35480
35481 \begin_layout Standard
35482
35483 \size footnotesize
35484 IC_LEFT() IC_RESULT()
35485 \end_layout
35486
35487 \end_inset
35488 </cell>
35489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35490 \begin_inset Text
35491
35492 \begin_layout Standard
35493
35494 \size footnotesize
35495 NOT operation 
35496 \end_layout
35497
35498 \end_inset
35499 </cell>
35500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35501 \begin_inset Text
35502
35503 \begin_layout Standard
35504
35505 \size footnotesize
35506 IC_RESULT = ! IC_LEFT;
35507 \end_layout
35508
35509 \end_inset
35510 </cell>
35511 </row>
35512 <row topline="true">
35513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35514 \begin_inset Text
35515
35516 \begin_layout Standard
35517
35518 \size footnotesize
35519 '~'
35520 \end_layout
35521
35522 \end_inset
35523 </cell>
35524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35525 \begin_inset Text
35526
35527 \begin_layout Standard
35528
35529 \size footnotesize
35530 IC_LEFT() IC_RESULT()
35531 \end_layout
35532
35533 \end_inset
35534 </cell>
35535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35536 \begin_inset Text
35537
35538 \begin_layout Standard
35539
35540 \size footnotesize
35541 Bitwise complement of 
35542 \end_layout
35543
35544 \end_inset
35545 </cell>
35546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35547 \begin_inset Text
35548
35549 \begin_layout Standard
35550
35551 \size footnotesize
35552 IC_RESULT = ~IC_LEFT;
35553 \end_layout
35554
35555 \end_inset
35556 </cell>
35557 </row>
35558 <row topline="true">
35559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35560 \begin_inset Text
35561
35562 \begin_layout Standard
35563
35564 \size footnotesize
35565 RRC
35566 \end_layout
35567
35568 \end_inset
35569 </cell>
35570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35571 \begin_inset Text
35572
35573 \begin_layout Standard
35574
35575 \size footnotesize
35576 IC_LEFT() IC_RESULT()
35577 \end_layout
35578
35579 \end_inset
35580 </cell>
35581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35582 \begin_inset Text
35583
35584 \begin_layout Standard
35585
35586 \size footnotesize
35587 Rotate right with carry
35588 \end_layout
35589
35590 \end_inset
35591 </cell>
35592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35593 \begin_inset Text
35594
35595 \begin_layout Standard
35596
35597 \size footnotesize
35598 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
35599 \end_layout
35600
35601 \end_inset
35602 </cell>
35603 </row>
35604 <row topline="true">
35605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35606 \begin_inset Text
35607
35608 \begin_layout Standard
35609
35610 \size footnotesize
35611 RLC
35612 \end_layout
35613
35614 \end_inset
35615 </cell>
35616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35617 \begin_inset Text
35618
35619 \begin_layout Standard
35620
35621 \size footnotesize
35622 IC_LEFT() IC_RESULT()
35623 \end_layout
35624
35625 \end_inset
35626 </cell>
35627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35628 \begin_inset Text
35629
35630 \begin_layout Standard
35631
35632 \size footnotesize
35633 Rotate left with carry
35634 \end_layout
35635
35636 \end_inset
35637 </cell>
35638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35639 \begin_inset Text
35640
35641 \begin_layout Standard
35642
35643 \size footnotesize
35644 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
35645 \end_layout
35646
35647 \end_inset
35648 </cell>
35649 </row>
35650 <row topline="true">
35651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35652 \begin_inset Text
35653
35654 \begin_layout Standard
35655
35656 \size footnotesize
35657 GETHBIT
35658 \end_layout
35659
35660 \end_inset
35661 </cell>
35662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35663 \begin_inset Text
35664
35665 \begin_layout Standard
35666
35667 \size footnotesize
35668 IC_LEFT() IC_RESULT()
35669 \end_layout
35670
35671 \end_inset
35672 </cell>
35673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35674 \begin_inset Text
35675
35676 \begin_layout Standard
35677
35678 \size footnotesize
35679 Get the highest order bit of IC_LEFT
35680 \end_layout
35681
35682 \end_inset
35683 </cell>
35684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35685 \begin_inset Text
35686
35687 \begin_layout Standard
35688
35689 \size footnotesize
35690 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
35691 \end_layout
35692
35693 \end_inset
35694 </cell>
35695 </row>
35696 <row topline="true">
35697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35698 \begin_inset Text
35699
35700 \begin_layout Standard
35701
35702 \size footnotesize
35703 UNARYMINUS
35704 \end_layout
35705
35706 \end_inset
35707 </cell>
35708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35709 \begin_inset Text
35710
35711 \begin_layout Standard
35712
35713 \size footnotesize
35714 IC_LEFT() IC_RESULT()
35715 \end_layout
35716
35717 \end_inset
35718 </cell>
35719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35720 \begin_inset Text
35721
35722 \begin_layout Standard
35723
35724 \size footnotesize
35725 Unary minus
35726 \end_layout
35727
35728 \end_inset
35729 </cell>
35730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35731 \begin_inset Text
35732
35733 \begin_layout Standard
35734
35735 \size footnotesize
35736 IC_RESULT = - IC_LEFT;
35737 \end_layout
35738
35739 \end_inset
35740 </cell>
35741 </row>
35742 <row topline="true">
35743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35744 \begin_inset Text
35745
35746 \begin_layout Standard
35747
35748 \size footnotesize
35749 IPUSH
35750 \end_layout
35751
35752 \end_inset
35753 </cell>
35754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35755 \begin_inset Text
35756
35757 \begin_layout Standard
35758
35759 \size footnotesize
35760 IC_LEFT()
35761 \end_layout
35762
35763 \end_inset
35764 </cell>
35765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35766 \begin_inset Text
35767
35768 \begin_layout Standard
35769
35770 \size footnotesize
35771 Push the operand into stack
35772 \end_layout
35773
35774 \end_inset
35775 </cell>
35776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35777 \begin_inset Text
35778
35779 \begin_layout Standard
35780
35781 \size footnotesize
35782 NONE
35783 \end_layout
35784
35785 \end_inset
35786 </cell>
35787 </row>
35788 <row topline="true">
35789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35790 \begin_inset Text
35791
35792 \begin_layout Standard
35793
35794 \size footnotesize
35795 IPOP
35796 \end_layout
35797
35798 \end_inset
35799 </cell>
35800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35801 \begin_inset Text
35802
35803 \begin_layout Standard
35804
35805 \size footnotesize
35806 IC_LEFT()
35807 \end_layout
35808
35809 \end_inset
35810 </cell>
35811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35812 \begin_inset Text
35813
35814 \begin_layout Standard
35815
35816 \size footnotesize
35817 Pop the operand from the stack 
35818 \end_layout
35819
35820 \end_inset
35821 </cell>
35822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35823 \begin_inset Text
35824
35825 \begin_layout Standard
35826
35827 \size footnotesize
35828 NONE
35829 \end_layout
35830
35831 \end_inset
35832 </cell>
35833 </row>
35834 <row topline="true">
35835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35836 \begin_inset Text
35837
35838 \begin_layout Standard
35839
35840 \size footnotesize
35841 CALL
35842 \end_layout
35843
35844 \end_inset
35845 </cell>
35846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35847 \begin_inset Text
35848
35849 \begin_layout Standard
35850
35851 \size footnotesize
35852 IC_LEFT() IC_RESULT()
35853 \end_layout
35854
35855 \end_inset
35856 </cell>
35857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35858 \begin_inset Text
35859
35860 \begin_layout Standard
35861
35862 \size footnotesize
35863 Call the function represented by IC_LEFT 
35864 \end_layout
35865
35866 \end_inset
35867 </cell>
35868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35869 \begin_inset Text
35870
35871 \begin_layout Standard
35872
35873 \size footnotesize
35874 IC_RESULT = IC_LEFT();
35875 \end_layout
35876
35877 \end_inset
35878 </cell>
35879 </row>
35880 <row topline="true">
35881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35882 \begin_inset Text
35883
35884 \begin_layout Standard
35885
35886 \size footnotesize
35887 PCALL
35888 \end_layout
35889
35890 \end_inset
35891 </cell>
35892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35893 \begin_inset Text
35894
35895 \begin_layout Standard
35896
35897 \size footnotesize
35898 IC_LEFT() IC_RESULT()
35899 \end_layout
35900
35901 \end_inset
35902 </cell>
35903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35904 \begin_inset Text
35905
35906 \begin_layout Standard
35907
35908 \size footnotesize
35909 Call via function pointer
35910 \end_layout
35911
35912 \end_inset
35913 </cell>
35914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35915 \begin_inset Text
35916
35917 \begin_layout Standard
35918
35919 \size footnotesize
35920 IC_RESULT = (*IC_LEFT)();
35921 \end_layout
35922
35923 \end_inset
35924 </cell>
35925 </row>
35926 <row topline="true">
35927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35928 \begin_inset Text
35929
35930 \begin_layout Standard
35931
35932 \size footnotesize
35933 RETURN
35934 \end_layout
35935
35936 \end_inset
35937 </cell>
35938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35939 \begin_inset Text
35940
35941 \begin_layout Standard
35942
35943 \size footnotesize
35944 IC_LEFT()
35945 \end_layout
35946
35947 \end_inset
35948 </cell>
35949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35950 \begin_inset Text
35951
35952 \begin_layout Standard
35953
35954 \size footnotesize
35955 Return the value in operand IC_LEFT 
35956 \end_layout
35957
35958 \end_inset
35959 </cell>
35960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
35961 \begin_inset Text
35962
35963 \begin_layout Standard
35964
35965 \size footnotesize
35966 return IC_LEFT;
35967 \end_layout
35968
35969 \end_inset
35970 </cell>
35971 </row>
35972 <row topline="true">
35973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35974 \begin_inset Text
35975
35976 \begin_layout Standard
35977
35978 \size footnotesize
35979 LABEL
35980 \end_layout
35981
35982 \end_inset
35983 </cell>
35984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35985 \begin_inset Text
35986
35987 \begin_layout Standard
35988
35989 \size footnotesize
35990 IC_LABEL() 
35991 \end_layout
35992
35993 \end_inset
35994 </cell>
35995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
35996 \begin_inset Text
35997
35998 \begin_layout Standard
35999
36000 \size footnotesize
36001 Label
36002 \end_layout
36003
36004 \end_inset
36005 </cell>
36006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36007 \begin_inset Text
36008
36009 \begin_layout Standard
36010
36011 \size footnotesize
36012 IC_LABEL:
36013 \end_layout
36014
36015 \end_inset
36016 </cell>
36017 </row>
36018 <row topline="true">
36019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36020 \begin_inset Text
36021
36022 \begin_layout Standard
36023
36024 \size footnotesize
36025 GOTO
36026 \end_layout
36027
36028 \end_inset
36029 </cell>
36030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36031 \begin_inset Text
36032
36033 \begin_layout Standard
36034
36035 \size footnotesize
36036 IC_LABEL() 
36037 \end_layout
36038
36039 \end_inset
36040 </cell>
36041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36042 \begin_inset Text
36043
36044 \begin_layout Standard
36045
36046 \size footnotesize
36047 Goto label
36048 \end_layout
36049
36050 \end_inset
36051 </cell>
36052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36053 \begin_inset Text
36054
36055 \begin_layout Standard
36056
36057 \size footnotesize
36058 goto IC_LABEL();
36059 \end_layout
36060
36061 \end_inset
36062 </cell>
36063 </row>
36064 <row topline="true">
36065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36066 \begin_inset Text
36067
36068 \begin_layout Standard
36069
36070 \size footnotesize
36071 '+'
36072 \end_layout
36073
36074 \end_inset
36075 </cell>
36076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36077 \begin_inset Text
36078
36079 \begin_layout Standard
36080
36081 \size footnotesize
36082 IC_LEFT() IC_RIGHT() IC_RESULT()
36083 \end_layout
36084
36085 \end_inset
36086 </cell>
36087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36088 \begin_inset Text
36089
36090 \begin_layout Standard
36091
36092 \size footnotesize
36093 Addition
36094 \end_layout
36095
36096 \end_inset
36097 </cell>
36098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36099 \begin_inset Text
36100
36101 \begin_layout Standard
36102
36103 \size footnotesize
36104 IC_RESULT = IC_LEFT + IC_RIGHT
36105 \end_layout
36106
36107 \end_inset
36108 </cell>
36109 </row>
36110 <row topline="true">
36111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36112 \begin_inset Text
36113
36114 \begin_layout Standard
36115
36116 \size footnotesize
36117 '-'
36118 \end_layout
36119
36120 \end_inset
36121 </cell>
36122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36123 \begin_inset Text
36124
36125 \begin_layout Standard
36126
36127 \size footnotesize
36128 IC_LEFT() IC_RIGHT() IC_RESULT()
36129 \end_layout
36130
36131 \end_inset
36132 </cell>
36133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36134 \begin_inset Text
36135
36136 \begin_layout Standard
36137
36138 \size footnotesize
36139 Subtraction
36140 \end_layout
36141
36142 \end_inset
36143 </cell>
36144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36145 \begin_inset Text
36146
36147 \begin_layout Standard
36148
36149 \size footnotesize
36150 IC_RESULT = IC_LEFT - IC_RIGHT 
36151 \end_layout
36152
36153 \end_inset
36154 </cell>
36155 </row>
36156 <row topline="true">
36157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36158 \begin_inset Text
36159
36160 \begin_layout Standard
36161
36162 \size footnotesize
36163 '*'
36164 \end_layout
36165
36166 \end_inset
36167 </cell>
36168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36169 \begin_inset Text
36170
36171 \begin_layout Standard
36172
36173 \size footnotesize
36174 IC_LEFT() IC_RIGHT() IC_RESULT()
36175 \end_layout
36176
36177 \end_inset
36178 </cell>
36179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36180 \begin_inset Text
36181
36182 \begin_layout Standard
36183
36184 \size footnotesize
36185 Multiplication 
36186 \end_layout
36187
36188 \end_inset
36189 </cell>
36190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36191 \begin_inset Text
36192
36193 \begin_layout Standard
36194
36195 \size footnotesize
36196 IC_RESULT = IC_LEFT * IC_RIGHT;
36197 \end_layout
36198
36199 \end_inset
36200 </cell>
36201 </row>
36202 <row topline="true">
36203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36204 \begin_inset Text
36205
36206 \begin_layout Standard
36207
36208 \size footnotesize
36209 '/'
36210 \end_layout
36211
36212 \end_inset
36213 </cell>
36214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36215 \begin_inset Text
36216
36217 \begin_layout Standard
36218
36219 \size footnotesize
36220 IC_LEFT() IC_RIGHT() IC_RESULT()
36221 \end_layout
36222
36223 \end_inset
36224 </cell>
36225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36226 \begin_inset Text
36227
36228 \begin_layout Standard
36229
36230 \size footnotesize
36231 Division
36232 \end_layout
36233
36234 \end_inset
36235 </cell>
36236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36237 \begin_inset Text
36238
36239 \begin_layout Standard
36240
36241 \size footnotesize
36242 IC_RESULT = IC_LEFT / IC_RIGHT;
36243 \end_layout
36244
36245 \end_inset
36246 </cell>
36247 </row>
36248 <row topline="true">
36249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36250 \begin_inset Text
36251
36252 \begin_layout Standard
36253
36254 \size footnotesize
36255 '%'
36256 \end_layout
36257
36258 \end_inset
36259 </cell>
36260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36261 \begin_inset Text
36262
36263 \begin_layout Standard
36264
36265 \size footnotesize
36266 IC_LEFT() IC_RIGHT() IC_RESULT()
36267 \end_layout
36268
36269 \end_inset
36270 </cell>
36271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36272 \begin_inset Text
36273
36274 \begin_layout Standard
36275
36276 \size footnotesize
36277 Modulus
36278 \end_layout
36279
36280 \end_inset
36281 </cell>
36282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36283 \begin_inset Text
36284
36285 \begin_layout Standard
36286
36287 \size footnotesize
36288 IC_RESULT = IC_LEFT % IC_RIGHT;
36289 \end_layout
36290
36291 \end_inset
36292 </cell>
36293 </row>
36294 <row topline="true">
36295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36296 \begin_inset Text
36297
36298 \begin_layout Standard
36299
36300 \size footnotesize
36301 '<'
36302 \end_layout
36303
36304 \end_inset
36305 </cell>
36306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36307 \begin_inset Text
36308
36309 \begin_layout Standard
36310
36311 \size footnotesize
36312 IC_LEFT() IC_RIGHT() IC_RESULT()
36313 \end_layout
36314
36315 \end_inset
36316 </cell>
36317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36318 \begin_inset Text
36319
36320 \begin_layout Standard
36321
36322 \size footnotesize
36323 Less than
36324 \end_layout
36325
36326 \end_inset
36327 </cell>
36328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36329 \begin_inset Text
36330
36331 \begin_layout Standard
36332
36333 \size footnotesize
36334 IC_RESULT = IC_LEFT < IC_RIGHT;
36335 \end_layout
36336
36337 \end_inset
36338 </cell>
36339 </row>
36340 <row topline="true">
36341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36342 \begin_inset Text
36343
36344 \begin_layout Standard
36345
36346 \size footnotesize
36347 '>'
36348 \end_layout
36349
36350 \end_inset
36351 </cell>
36352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36353 \begin_inset Text
36354
36355 \begin_layout Standard
36356
36357 \size footnotesize
36358 IC_LEFT() IC_RIGHT() IC_RESULT()
36359 \end_layout
36360
36361 \end_inset
36362 </cell>
36363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36364 \begin_inset Text
36365
36366 \begin_layout Standard
36367
36368 \size footnotesize
36369 Greater than 
36370 \end_layout
36371
36372 \end_inset
36373 </cell>
36374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36375 \begin_inset Text
36376
36377 \begin_layout Standard
36378
36379 \size footnotesize
36380 IC_RESULT = IC_LEFT > IC_RIGHT;
36381 \end_layout
36382
36383 \end_inset
36384 </cell>
36385 </row>
36386 <row topline="true">
36387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36388 \begin_inset Text
36389
36390 \begin_layout Standard
36391
36392 \size footnotesize
36393 EQ_OP
36394 \end_layout
36395
36396 \end_inset
36397 </cell>
36398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36399 \begin_inset Text
36400
36401 \begin_layout Standard
36402
36403 \size footnotesize
36404 IC_LEFT() IC_RIGHT() IC_RESULT()
36405 \end_layout
36406
36407 \end_inset
36408 </cell>
36409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36410 \begin_inset Text
36411
36412 \begin_layout Standard
36413
36414 \size footnotesize
36415 Equal to 
36416 \end_layout
36417
36418 \end_inset
36419 </cell>
36420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36421 \begin_inset Text
36422
36423 \begin_layout Standard
36424
36425 \size footnotesize
36426 IC_RESULT = IC_LEFT == IC_RIGHT;
36427 \end_layout
36428
36429 \end_inset
36430 </cell>
36431 </row>
36432 <row topline="true">
36433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36434 \begin_inset Text
36435
36436 \begin_layout Standard
36437
36438 \size footnotesize
36439 AND_OP
36440 \end_layout
36441
36442 \end_inset
36443 </cell>
36444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36445 \begin_inset Text
36446
36447 \begin_layout Standard
36448
36449 \size footnotesize
36450 IC_LEFT() IC_RIGHT() IC_RESULT() 
36451 \end_layout
36452
36453 \end_inset
36454 </cell>
36455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36456 \begin_inset Text
36457
36458 \begin_layout Standard
36459
36460 \size footnotesize
36461 Logical and operation
36462 \end_layout
36463
36464 \end_inset
36465 </cell>
36466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36467 \begin_inset Text
36468
36469 \begin_layout Standard
36470
36471 \size footnotesize
36472 IC_RESULT = IC_LEFT && IC_RIGHT; 
36473 \end_layout
36474
36475 \end_inset
36476 </cell>
36477 </row>
36478 <row topline="true">
36479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36480 \begin_inset Text
36481
36482 \begin_layout Standard
36483
36484 \size footnotesize
36485 OR_OP
36486 \end_layout
36487
36488 \end_inset
36489 </cell>
36490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36491 \begin_inset Text
36492
36493 \begin_layout Standard
36494
36495 \size footnotesize
36496 IC_LEFT() IC_RIGHT() IC_RESULT() 
36497 \end_layout
36498
36499 \end_inset
36500 </cell>
36501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36502 \begin_inset Text
36503
36504 \begin_layout Standard
36505
36506 \size footnotesize
36507 Logical or operation 
36508 \end_layout
36509
36510 \end_inset
36511 </cell>
36512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36513 \begin_inset Text
36514
36515 \begin_layout Standard
36516
36517 \size footnotesize
36518 IC_RESULT = IC_LEFT || IC_RIGHT; 
36519 \end_layout
36520
36521 \end_inset
36522 </cell>
36523 </row>
36524 <row topline="true">
36525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36526 \begin_inset Text
36527
36528 \begin_layout Standard
36529
36530 \size footnotesize
36531 '^'
36532 \end_layout
36533
36534 \end_inset
36535 </cell>
36536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36537 \begin_inset Text
36538
36539 \begin_layout Standard
36540
36541 \size footnotesize
36542 IC_LEFT() IC_RIGHT() IC_RESULT() 
36543 \end_layout
36544
36545 \end_inset
36546 </cell>
36547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36548 \begin_inset Text
36549
36550 \begin_layout Standard
36551
36552 \size footnotesize
36553 Exclusive OR
36554 \end_layout
36555
36556 \end_inset
36557 </cell>
36558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36559 \begin_inset Text
36560
36561 \begin_layout Standard
36562
36563 \size footnotesize
36564 IC_RESULT = IC_LEFT ^ IC_RIGHT;
36565 \end_layout
36566
36567 \end_inset
36568 </cell>
36569 </row>
36570 <row topline="true">
36571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36572 \begin_inset Text
36573
36574 \begin_layout Standard
36575
36576 \size footnotesize
36577 '|'
36578 \end_layout
36579
36580 \end_inset
36581 </cell>
36582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36583 \begin_inset Text
36584
36585 \begin_layout Standard
36586
36587 \size footnotesize
36588 IC_LEFT() IC_RIGHT() IC_RESULT() 
36589 \end_layout
36590
36591 \end_inset
36592 </cell>
36593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36594 \begin_inset Text
36595
36596 \begin_layout Standard
36597
36598 \size footnotesize
36599 Bitwise OR 
36600 \end_layout
36601
36602 \end_inset
36603 </cell>
36604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36605 \begin_inset Text
36606
36607 \begin_layout Standard
36608
36609 \size footnotesize
36610 IC_RESULT = IC_LEFT | IC_RIGHT;
36611 \end_layout
36612
36613 \end_inset
36614 </cell>
36615 </row>
36616 <row topline="true">
36617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36618 \begin_inset Text
36619
36620 \begin_layout Standard
36621
36622 \size footnotesize
36623 BITWISEAND
36624 \end_layout
36625
36626 \end_inset
36627 </cell>
36628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36629 \begin_inset Text
36630
36631 \begin_layout Standard
36632
36633 \size footnotesize
36634 IC_LEFT() IC_RIGHT() IC_RESULT()
36635 \end_layout
36636
36637 \end_inset
36638 </cell>
36639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36640 \begin_inset Text
36641
36642 \begin_layout Standard
36643
36644 \size footnotesize
36645 Bitwise AND 
36646 \end_layout
36647
36648 \end_inset
36649 </cell>
36650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36651 \begin_inset Text
36652
36653 \begin_layout Standard
36654
36655 \size footnotesize
36656 IC_RESULT = IC_LEFT & IC_RIGHT;
36657 \end_layout
36658
36659 \end_inset
36660 </cell>
36661 </row>
36662 <row topline="true">
36663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36664 \begin_inset Text
36665
36666 \begin_layout Standard
36667
36668 \size footnotesize
36669 LEFT_OP
36670 \end_layout
36671
36672 \end_inset
36673 </cell>
36674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36675 \begin_inset Text
36676
36677 \begin_layout Standard
36678
36679 \size footnotesize
36680 IC_LEFT() IC_RIGHT() IC_RESULT()
36681 \end_layout
36682
36683 \end_inset
36684 </cell>
36685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36686 \begin_inset Text
36687
36688 \begin_layout Standard
36689
36690 \size footnotesize
36691 Left shift 
36692 \end_layout
36693
36694 \end_inset
36695 </cell>
36696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36697 \begin_inset Text
36698
36699 \begin_layout Standard
36700
36701 \size footnotesize
36702 IC_RESULT = IC_LEFT << IC_RIGHT 
36703 \end_layout
36704
36705 \end_inset
36706 </cell>
36707 </row>
36708 <row topline="true">
36709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36710 \begin_inset Text
36711
36712 \begin_layout Standard
36713
36714 \size footnotesize
36715 RIGHT_OP
36716 \end_layout
36717
36718 \end_inset
36719 </cell>
36720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36721 \begin_inset Text
36722
36723 \begin_layout Standard
36724
36725 \size footnotesize
36726 IC_LEFT() IC_RIGHT() IC_RESULT()
36727 \end_layout
36728
36729 \end_inset
36730 </cell>
36731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36732 \begin_inset Text
36733
36734 \begin_layout Standard
36735
36736 \size footnotesize
36737 Right shift
36738 \end_layout
36739
36740 \end_inset
36741 </cell>
36742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36743 \begin_inset Text
36744
36745 \begin_layout Standard
36746
36747 \size footnotesize
36748 IC_RESULT = IC_LEFT >> IC_RIGHT 
36749 \end_layout
36750
36751 \end_inset
36752 </cell>
36753 </row>
36754 <row topline="true">
36755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36756 \begin_inset Text
36757
36758 \begin_layout Standard
36759
36760 \size footnotesize
36761 GET_VALUE_
36762 \newline
36763 AT_ ADDRESS
36764 \end_layout
36765
36766 \end_inset
36767 </cell>
36768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36769 \begin_inset Text
36770
36771 \begin_layout Standard
36772
36773 \size footnotesize
36774 IC_LEFT() IC_RESULT()
36775 \end_layout
36776
36777 \end_inset
36778 </cell>
36779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36780 \begin_inset Text
36781
36782 \begin_layout Standard
36783
36784 \size footnotesize
36785 Indirect fetch 
36786 \end_layout
36787
36788 \end_inset
36789 </cell>
36790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36791 \begin_inset Text
36792
36793 \begin_layout Standard
36794
36795 \size footnotesize
36796 IC_RESULT = (*IC_LEFT);
36797 \end_layout
36798
36799 \end_inset
36800 </cell>
36801 </row>
36802 <row topline="true">
36803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36804 \begin_inset Text
36805
36806 \begin_layout Standard
36807
36808 \size footnotesize
36809 POINTER_SET
36810 \end_layout
36811
36812 \end_inset
36813 </cell>
36814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36815 \begin_inset Text
36816
36817 \begin_layout Standard
36818
36819 \size footnotesize
36820 IC_RIGHT() IC_RESULT() 
36821 \end_layout
36822
36823 \end_inset
36824 </cell>
36825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36826 \begin_inset Text
36827
36828 \begin_layout Standard
36829
36830 \size footnotesize
36831 Indirect set
36832 \end_layout
36833
36834 \end_inset
36835 </cell>
36836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36837 \begin_inset Text
36838
36839 \begin_layout Standard
36840
36841 \size footnotesize
36842 (*IC_RESULT) = IC_RIGHT;
36843 \end_layout
36844
36845 \end_inset
36846 </cell>
36847 </row>
36848 <row topline="true">
36849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36850 \begin_inset Text
36851
36852 \begin_layout Standard
36853
36854 \size footnotesize
36855 '='
36856 \end_layout
36857
36858 \end_inset
36859 </cell>
36860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36861 \begin_inset Text
36862
36863 \begin_layout Standard
36864
36865 \size footnotesize
36866 IC_RIGHT() IC_RESULT()
36867 \end_layout
36868
36869 \end_inset
36870 </cell>
36871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36872 \begin_inset Text
36873
36874 \begin_layout Standard
36875
36876 \size footnotesize
36877 Assignment
36878 \end_layout
36879
36880 \end_inset
36881 </cell>
36882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36883 \begin_inset Text
36884
36885 \begin_layout Standard
36886
36887 \size footnotesize
36888 IC_RESULT = IC_RIGHT;
36889 \end_layout
36890
36891 \end_inset
36892 </cell>
36893 </row>
36894 <row topline="true">
36895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36896 \begin_inset Text
36897
36898 \begin_layout Standard
36899
36900 \size footnotesize
36901 IFX
36902 \end_layout
36903
36904 \end_inset
36905 </cell>
36906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36907 \begin_inset Text
36908
36909 \begin_layout Standard
36910
36911 \size footnotesize
36912 IC_COND IC_TRUE IC_LABEL
36913 \end_layout
36914
36915 \end_inset
36916 </cell>
36917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36918 \begin_inset Text
36919
36920 \begin_layout Standard
36921
36922 \size footnotesize
36923 Conditional jump.
36924  If true label is present then jump to true label if condition is true else
36925  jump to false label if condition is false 
36926 \end_layout
36927
36928 \end_inset
36929 </cell>
36930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36931 \begin_inset Text
36932
36933 \begin_layout Standard
36934
36935 \size footnotesize
36936 if (IC_COND) goto IC_TRUE; 
36937 \newline
36938 \InsetSpace ~
36939 \InsetSpace ~
36940 Or 
36941 \newline
36942 If (!IC_COND) goto IC_FALSE;
36943 \end_layout
36944
36945 \end_inset
36946 </cell>
36947 </row>
36948 <row topline="true">
36949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36950 \begin_inset Text
36951
36952 \begin_layout Standard
36953
36954 \size footnotesize
36955 ADDRESS_OF
36956 \end_layout
36957
36958 \end_inset
36959 </cell>
36960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36961 \begin_inset Text
36962
36963 \begin_layout Standard
36964
36965 \size footnotesize
36966 IC_LEFT() IC_RESULT()
36967 \end_layout
36968
36969 \end_inset
36970 </cell>
36971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36972 \begin_inset Text
36973
36974 \begin_layout Standard
36975
36976 \size footnotesize
36977 Address of 
36978 \end_layout
36979
36980 \end_inset
36981 </cell>
36982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36983 \begin_inset Text
36984
36985 \begin_layout Standard
36986
36987 \size footnotesize
36988 IC_RESULT = &IC_LEFT();
36989 \end_layout
36990
36991 \end_inset
36992 </cell>
36993 </row>
36994 <row topline="true">
36995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36996 \begin_inset Text
36997
36998 \begin_layout Standard
36999
37000 \size footnotesize
37001 JUMPTABLE
37002 \end_layout
37003
37004 \end_inset
37005 </cell>
37006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37007 \begin_inset Text
37008
37009 \begin_layout Standard
37010
37011 \size footnotesize
37012 IC_JTCOND IC_JTLABELS
37013 \end_layout
37014
37015 \end_inset
37016 </cell>
37017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37018 \begin_inset Text
37019
37020 \begin_layout Standard
37021
37022 \size footnotesize
37023 Jump to list of labels depending on the value of JTCOND
37024 \end_layout
37025
37026 \end_inset
37027 </cell>
37028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37029 \begin_inset Text
37030
37031 \begin_layout Standard
37032
37033 \size footnotesize
37034 Switch statement
37035 \end_layout
37036
37037 \end_inset
37038 </cell>
37039 </row>
37040 <row topline="true">
37041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37042 \begin_inset Text
37043
37044 \begin_layout Standard
37045
37046 \size footnotesize
37047 CAST
37048 \end_layout
37049
37050 \end_inset
37051 </cell>
37052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37053 \begin_inset Text
37054
37055 \begin_layout Standard
37056
37057 \size footnotesize
37058 IC_RIGHT() IC_LEFT() IC_RESULT()
37059 \end_layout
37060
37061 \end_inset
37062 </cell>
37063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37064 \begin_inset Text
37065
37066 \begin_layout Standard
37067
37068 \size footnotesize
37069 Cast types 
37070 \end_layout
37071
37072 \end_inset
37073 </cell>
37074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37075 \begin_inset Text
37076
37077 \begin_layout Standard
37078
37079 \size footnotesize
37080 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37081 \end_layout
37082
37083 \end_inset
37084 </cell>
37085 </row>
37086 <row topline="true">
37087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37088 \begin_inset Text
37089
37090 \begin_layout Standard
37091
37092 \size footnotesize
37093 SEND
37094 \end_layout
37095
37096 \end_inset
37097 </cell>
37098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37099 \begin_inset Text
37100
37101 \begin_layout Standard
37102
37103 \size footnotesize
37104 IC_LEFT()
37105 \end_layout
37106
37107 \end_inset
37108 </cell>
37109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37110 \begin_inset Text
37111
37112 \begin_layout Standard
37113
37114 \size footnotesize
37115 This is used for passing parameters in registers; 
37116 \newline
37117 move IC_LEFT to the next
37118  available parameter register.
37119 \end_layout
37120
37121 \end_inset
37122 </cell>
37123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37124 \begin_inset Text
37125
37126 \begin_layout Standard
37127
37128 \size footnotesize
37129 None
37130 \end_layout
37131
37132 \end_inset
37133 </cell>
37134 </row>
37135 <row topline="true">
37136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37137 \begin_inset Text
37138
37139 \begin_layout Standard
37140
37141 \size footnotesize
37142 RECV
37143 \end_layout
37144
37145 \end_inset
37146 </cell>
37147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37148 \begin_inset Text
37149
37150 \begin_layout Standard
37151
37152 \size footnotesize
37153 IC_RESULT()
37154 \end_layout
37155
37156 \end_inset
37157 </cell>
37158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37159 \begin_inset Text
37160
37161 \begin_layout Standard
37162
37163 \size footnotesize
37164 This is used for receiving parameters passed in registers;
37165 \newline
37166 Move the values
37167  in the next parameter register to IC_RESULT 
37168 \end_layout
37169
37170 \end_inset
37171 </cell>
37172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37173 \begin_inset Text
37174
37175 \begin_layout Standard
37176
37177 \size footnotesize
37178 None
37179 \end_layout
37180
37181 \end_inset
37182 </cell>
37183 </row>
37184 <row topline="true" bottomline="true">
37185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37186 \begin_inset Text
37187
37188 \begin_layout Standard
37189
37190 \shape slanted
37191 \size footnotesize
37192 (some more have been added)
37193 \end_layout
37194
37195 \end_inset
37196 </cell>
37197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37198 \begin_inset Text
37199
37200 \begin_layout Standard
37201
37202 \end_layout
37203
37204 \end_inset
37205 </cell>
37206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37207 \begin_inset Text
37208
37209 \begin_layout Standard
37210
37211 \end_layout
37212
37213 \end_inset
37214 </cell>
37215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37216 \begin_inset Text
37217
37218 \begin_layout Standard
37219
37220 \shape slanted
37221 \size footnotesize
37222 see f.e.
37223  
37224 \family typewriter
37225 gen51Code()
37226 \family default
37227  in 
37228 \family typewriter
37229 src/mcs51/gen.c
37230 \end_layout
37231
37232 \end_inset
37233 </cell>
37234 </row>
37235 </lyxtabular>
37236
37237 \end_inset
37238
37239
37240 \end_layout
37241
37242 \begin_layout Standard
37243 \begin_inset Note Note
37244 status collapsed
37245
37246 \begin_layout Standard
37247 In the original article Figure II was announced to be downloadable on 
37248 \shape italic
37249 Circuit Cellar
37250 \shape default
37251 's web site.
37252  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37253 \end_layout
37254
37255 \end_inset
37256
37257
37258 \end_layout
37259
37260 \begin_layout Paragraph*
37261 ICode Example
37262 \begin_inset LatexCommand \index{iCode}
37263
37264 \end_inset
37265
37266
37267 \end_layout
37268
37269 \begin_layout Standard
37270 This section shows some details of iCode.
37271  The example C code does not do anything useful; it is used as an example
37272  to illustrate the intermediate code generated by the compiler.
37273 \end_layout
37274
37275 \begin_layout Verse
37276
37277 \family typewriter
37278 1.\InsetSpace ~
37279 xdata int * p;
37280 \newline
37281 2.\InsetSpace ~
37282 int gint;
37283 \newline
37284 3.\InsetSpace ~
37285 /* This function does nothing useful.
37286  It is used
37287 \newline
37288 4.\InsetSpace ~
37289 \InsetSpace ~
37290 \InsetSpace ~
37291 \InsetSpace ~
37292 for the purpose of explaining iCode */
37293 \newline
37294 5.\InsetSpace ~
37295 short function (data
37296  int *x)
37297 \newline
37298 6.\InsetSpace ~
37299 {
37300 \newline
37301 7.\InsetSpace ~
37302 \InsetSpace ~
37303 \InsetSpace ~
37304 short i=10; \InsetSpace ~
37305 \InsetSpace ~
37306 /* dead initialization eliminated */
37307 \newline
37308 8.\InsetSpace ~
37309 \InsetSpace ~
37310 \InsetSpace ~
37311 short sum=10;
37312  /* dead initialization eliminated */
37313 \newline
37314 9.\InsetSpace ~
37315 \InsetSpace ~
37316 \InsetSpace ~
37317 short mul;
37318 \newline
37319 10.\InsetSpace ~
37320 \InsetSpace ~
37321 int j ;
37322 \newline
37323 11.\InsetSpace ~
37324 \InsetSpace ~
37325 while (*x) *x++
37326  = *p++; 
37327 \newline
37328 12.\InsetSpace ~
37329 \InsetSpace ~
37330 \InsetSpace ~
37331 \InsetSpace ~
37332 sum = 0 ; 
37333 \newline
37334 13.\InsetSpace ~
37335 \InsetSpace ~
37336 mul = 0;
37337 \newline
37338 14.\InsetSpace ~
37339 \InsetSpace ~
37340 /* compiler detects i,j to be induction
37341  variables */
37342 \newline
37343 15.\InsetSpace ~
37344 \InsetSpace ~
37345 for (i = 0, j = 10 ; i < 10 ; i++, j
37346 \family default
37347 -
37348 \begin_inset ERT
37349 status collapsed
37350
37351 \begin_layout Standard
37352
37353
37354 \backslash
37355 /
37356 \end_layout
37357
37358 \end_inset
37359
37360 -
37361 \family typewriter
37362 ) {
37363 \newline
37364 16.\InsetSpace ~
37365 \InsetSpace ~
37366 \InsetSpace ~
37367 \InsetSpace ~
37368 sum += i;
37369 \newline
37370 17.\InsetSpace ~
37371 \InsetSpace ~
37372 \InsetSpace ~
37373 \InsetSpace ~
37374 mul += i * 3; \InsetSpace ~
37375 \InsetSpace ~
37376 /* this multiplication remains */
37377 \newline
37378 18.\InsetSpace ~
37379 \InsetSpace ~
37380 \InsetSpace ~
37381 \InsetSpace ~
37382 gint +=
37383  j * 3;\InsetSpace ~
37384 \InsetSpace ~
37385 /* this multiplication changed to addition */
37386 \newline
37387 19.\InsetSpace ~
37388 \InsetSpace ~
37389 }
37390 \newline
37391 20.\InsetSpace ~
37392 \InsetSpace ~
37393 return sum+mul;
37394 \newline
37395 21.\InsetSpace ~
37396 }
37397 \end_layout
37398
37399 \begin_layout Standard
37400 In addition to the operands each iCode contains information about the filename
37401  and line it corresponds to in the source file.
37402  The first field in the listing should be interpreted as follows:
37403 \newline
37404
37405 \shape italic
37406 \size footnotesize
37407 Filename(linenumber: iCode Execution sequence number : ICode hash table
37408  key : loop depth of the iCode).
37409 \shape default
37410 \size default
37411
37412 \newline
37413 Then follows the human readable form of the ICode operation.
37414  Each operand of this triplet form can be of three basic types a) compiler
37415  generated temporary b) user defined variable c) a constant value.
37416  Note that local variables and parameters are replaced by compiler generated
37417  temporaries.
37418  Live ranges
37419 \begin_inset LatexCommand \index{Live range analysis}
37420
37421 \end_inset
37422
37423  are computed only for temporaries (i.e.
37424  live ranges are not computed for global variables).
37425  Registers
37426 \begin_inset LatexCommand \index{Register allocation}
37427
37428 \end_inset
37429
37430  are allocated for temporaries only.
37431  Operands are formatted in the following manner:
37432 \newline
37433
37434 \shape italic
37435 \size footnotesize
37436 Operand Name [lr live-from : live-to ] { type information } [ registers
37437  allocated ].
37438 \shape default
37439 \size default
37440
37441 \newline
37442 As mentioned earlier the live ranges are computed in terms of the execution
37443  sequence number of the iCodes, for example 
37444 \newline
37445 the iTemp0 is live from (i.e.
37446  first defined in iCode with execution sequence number 3, and is last used
37447  in the iCode with sequence number 5).
37448  For induction variables such as iTemp21 the live range computation extends
37449  the lifetime from the start to the end of the loop.
37450 \newline
37451 The register allocator
37452  used the live range information to allocate registers, the same registers
37453  may be used for different temporaries if their live ranges do not overlap,
37454  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
37455  ranges do not overlap.
37456  In addition the allocator also takes into consideration the type and usage
37457  of a temporary, for example itemp6 is a pointer to near space and is used
37458  as to fetch data from (i.e.
37459  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
37460  Some short lived temporaries are allocated to special registers which have
37461  meaning to the code generator e.g.
37462  iTemp13 is allocated to a pseudo register CC which tells the back end that
37463  the temporary is used only for a conditional jump the code generation makes
37464  use of this information to optimize a compare and jump ICode.
37465 \newline
37466 There are several
37467  loop optimizations
37468 \begin_inset LatexCommand \index{Loop optimization}
37469
37470 \end_inset
37471
37472  performed by the compiler.
37473  It can detect induction variables iTemp21(i) and iTemp23(j).
37474  Also note the compiler does selective strength reduction
37475 \begin_inset LatexCommand \index{Strength reduction}
37476
37477 \end_inset
37478
37479 , i.e.
37480  the multiplication of an induction variable in line 18 (gint = j * 3) is
37481  changed to addition, a new temporary iTemp17 is allocated and assigned
37482  a initial value, a constant 3 is then added for each iteration of the loop.
37483  The compiler does not change the multiplication
37484 \begin_inset LatexCommand \index{Multiplication}
37485
37486 \end_inset
37487
37488  in line 17 however since the processor does support an 8 * 8 bit multiplication.
37489 \newline
37490
37491 Note the dead code elimination
37492 \begin_inset LatexCommand \index{Dead-code elimination}
37493
37494 \end_inset
37495
37496  optimization eliminated the dead assignments in line 7 & 8 to I and sum
37497  respectively.
37498 \newline
37499
37500 \end_layout
37501
37502 \begin_layout Standard
37503
37504 \size footnotesize
37505 Sample.c (5:1:0:0) _entry($9) :
37506 \end_layout
37507
37508 \begin_layout Standard
37509
37510 \size footnotesize
37511 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
37512 \end_layout
37513
37514 \begin_layout Standard
37515
37516 \size footnotesize
37517 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
37518 \end_layout
37519
37520 \begin_layout Standard
37521
37522 \size footnotesize
37523 Sample.c(11:4:53:0) preHeaderLbl0($11) :
37524 \end_layout
37525
37526 \begin_layout Standard
37527
37528 \size footnotesize
37529 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
37530  * int}[r2]
37531 \end_layout
37532
37533 \begin_layout Standard
37534
37535 \size footnotesize
37536 Sample.c(11:6:5:1) _whilecontinue_0($1) :
37537 \end_layout
37538
37539 \begin_layout Standard
37540
37541 \size footnotesize
37542 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
37543  int}[r0]]
37544 \end_layout
37545
37546 \begin_layout Standard
37547
37548 \size footnotesize
37549 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
37550 \end_layout
37551
37552 \begin_layout Standard
37553
37554 \size footnotesize
37555 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
37556  * int}
37557 \end_layout
37558
37559 \begin_layout Standard
37560
37561 \size footnotesize
37562 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
37563  {short}
37564 \end_layout
37565
37566 \begin_layout Standard
37567
37568 \size footnotesize
37569 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
37570  * int}[DPTR]]
37571 \end_layout
37572
37573 \begin_layout Standard
37574
37575 \size footnotesize
37576 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
37577 }[r2 r3]
37578 \end_layout
37579
37580 \begin_layout Standard
37581
37582 \size footnotesize
37583 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
37584  * int}[r0] + 0x2 {short}
37585 \end_layout
37586
37587 \begin_layout Standard
37588
37589 \size footnotesize
37590 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
37591 \end_layout
37592
37593 \begin_layout Standard
37594
37595 \size footnotesize
37596 Sample.c(11:17:21:0)_whilebreak_0($3) :
37597 \end_layout
37598
37599 \begin_layout Standard
37600
37601 \size footnotesize
37602 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
37603 \end_layout
37604
37605 \begin_layout Standard
37606
37607 \size footnotesize
37608 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
37609 \end_layout
37610
37611 \begin_layout Standard
37612
37613 \size footnotesize
37614 Sample.c(15:20:54:0)preHeaderLbl1($13) :
37615 \end_layout
37616
37617 \begin_layout Standard
37618
37619 \size footnotesize
37620 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
37621 \end_layout
37622
37623 \begin_layout Standard
37624
37625 \size footnotesize
37626 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
37627 \end_layout
37628
37629 \begin_layout Standard
37630
37631 \size footnotesize
37632 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
37633 \end_layout
37634
37635 \begin_layout Standard
37636
37637 \size footnotesize
37638 Sample.c(15:24:26:1)_forcond_0($4) :
37639 \end_layout
37640
37641 \begin_layout Standard
37642
37643 \size footnotesize
37644 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
37645  < 0xa {short}
37646 \end_layout
37647
37648 \begin_layout Standard
37649
37650 \size footnotesize
37651 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
37652 \end_layout
37653
37654 \begin_layout Standard
37655
37656 \size footnotesize
37657 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
37658  + ITemp21 [lr21:38]{short}[r4]
37659 \end_layout
37660
37661 \begin_layout Standard
37662
37663 \size footnotesize
37664 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
37665  * 0x3 {short}
37666 \end_layout
37667
37668 \begin_layout Standard
37669
37670 \size footnotesize
37671 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
37672  + iTemp15 [lr29:30]{short}[r1]
37673 \end_layout
37674
37675 \begin_layout Standard
37676
37677 \size footnotesize
37678 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
37679  r0]- 0x3 {short}
37680 \end_layout
37681
37682 \begin_layout Standard
37683
37684 \size footnotesize
37685 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
37686 int}[r7 r0]
37687 \end_layout
37688
37689 \begin_layout Standard
37690
37691 \size footnotesize
37692 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
37693  + 0x1 {short}
37694 \end_layout
37695
37696 \begin_layout Standard
37697
37698 \size footnotesize
37699 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
37700  r6]- 0x1 {short}
37701 \end_layout
37702
37703 \begin_layout Standard
37704
37705 \size footnotesize
37706 Sample.c(19:38:47:1) goto _forcond_0($4)
37707 \end_layout
37708
37709 \begin_layout Standard
37710
37711 \size footnotesize
37712 Sample.c(19:39:48:0)_forbreak_0($7) :
37713 \end_layout
37714
37715 \begin_layout Standard
37716
37717 \size footnotesize
37718 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
37719  + ITemp11 [lr19:40]{short}[r3]
37720 \end_layout
37721
37722 \begin_layout Standard
37723
37724 \size footnotesize
37725 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
37726 \end_layout
37727
37728 \begin_layout Standard
37729
37730 \size footnotesize
37731 Sample.c(20:42:51:0)_return($8) :
37732 \end_layout
37733
37734 \begin_layout Standard
37735
37736 \size footnotesize
37737 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
37738 \size default
37739
37740 \newline
37741
37742 \newline
37743 Finally the code generated for this function:
37744 \newline
37745
37746 \end_layout
37747
37748 \begin_layout Standard
37749
37750 \size footnotesize
37751 .area DSEG (DATA)
37752 \end_layout
37753
37754 \begin_layout Standard
37755
37756 \size footnotesize
37757 _p::
37758 \end_layout
37759
37760 \begin_layout Standard
37761
37762 \size footnotesize
37763 \InsetSpace ~
37764 \InsetSpace ~
37765 .ds 2
37766 \end_layout
37767
37768 \begin_layout Standard
37769
37770 \size footnotesize
37771 _gint::
37772 \end_layout
37773
37774 \begin_layout Standard
37775
37776 \size footnotesize
37777 \InsetSpace ~
37778 \InsetSpace ~
37779 .ds 2
37780 \end_layout
37781
37782 \begin_layout Standard
37783
37784 \size footnotesize
37785 ; sample.c 5
37786 \end_layout
37787
37788 \begin_layout Standard
37789
37790 \size footnotesize
37791 ; ----------------------------------------------
37792 \end_layout
37793
37794 \begin_layout Standard
37795
37796 \size footnotesize
37797 ; function function
37798 \end_layout
37799
37800 \begin_layout Standard
37801
37802 \size footnotesize
37803 ; ----------------------------------------------
37804 \end_layout
37805
37806 \begin_layout Standard
37807
37808 \size footnotesize
37809 _function:
37810 \end_layout
37811
37812 \begin_layout Standard
37813
37814 \size footnotesize
37815 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
37816 \end_layout
37817
37818 \begin_layout Standard
37819
37820 \size footnotesize
37821 \InsetSpace ~
37822 \InsetSpace ~
37823 mov r2,dpl
37824 \end_layout
37825
37826 \begin_layout Standard
37827
37828 \size footnotesize
37829 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
37830 \end_layout
37831
37832 \begin_layout Standard
37833
37834 \size footnotesize
37835 \InsetSpace ~
37836 \InsetSpace ~
37837 mov ar0,r2
37838 \end_layout
37839
37840 \begin_layout Standard
37841
37842 \size footnotesize
37843 ;_whilecontinue_0($1) :
37844 \end_layout
37845
37846 \begin_layout Standard
37847
37848 \size footnotesize
37849 00101$:
37850 \end_layout
37851
37852 \begin_layout Standard
37853
37854 \size footnotesize
37855 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
37856 \end_layout
37857
37858 \begin_layout Standard
37859
37860 \size footnotesize
37861 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
37862 \end_layout
37863
37864 \begin_layout Standard
37865
37866 \size footnotesize
37867 \InsetSpace ~
37868 \InsetSpace ~
37869 mov ar2,@r0
37870 \end_layout
37871
37872 \begin_layout Standard
37873
37874 \size footnotesize
37875 \InsetSpace ~
37876 \InsetSpace ~
37877 inc r0
37878 \end_layout
37879
37880 \begin_layout Standard
37881
37882 \size footnotesize
37883 \InsetSpace ~
37884 \InsetSpace ~
37885 mov ar3,@r0
37886 \end_layout
37887
37888 \begin_layout Standard
37889
37890 \size footnotesize
37891 \InsetSpace ~
37892 \InsetSpace ~
37893 dec r0
37894 \end_layout
37895
37896 \begin_layout Standard
37897
37898 \size footnotesize
37899 \InsetSpace ~
37900 \InsetSpace ~
37901 mov a,r2
37902 \end_layout
37903
37904 \begin_layout Standard
37905
37906 \size footnotesize
37907 \InsetSpace ~
37908 \InsetSpace ~
37909 orl a,r3
37910 \end_layout
37911
37912 \begin_layout Standard
37913
37914 \size footnotesize
37915 \InsetSpace ~
37916 \InsetSpace ~
37917 jz 00103$
37918 \end_layout
37919
37920 \begin_layout Standard
37921
37922 \size footnotesize
37923 00114$:
37924 \end_layout
37925
37926 \begin_layout Standard
37927
37928 \size footnotesize
37929 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
37930 \end_layout
37931
37932 \begin_layout Standard
37933
37934 \size footnotesize
37935 \InsetSpace ~
37936 \InsetSpace ~
37937 mov dpl,_p
37938 \end_layout
37939
37940 \begin_layout Standard
37941
37942 \size footnotesize
37943 \InsetSpace ~
37944 \InsetSpace ~
37945 mov dph,(_p + 1)
37946 \end_layout
37947
37948 \begin_layout Standard
37949
37950 \size footnotesize
37951 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
37952 \end_layout
37953
37954 \begin_layout Standard
37955
37956 \size footnotesize
37957 \InsetSpace ~
37958 \InsetSpace ~
37959 mov a,#0x02
37960 \end_layout
37961
37962 \begin_layout Standard
37963
37964 \size footnotesize
37965 \InsetSpace ~
37966 \InsetSpace ~
37967 add a,_p
37968 \end_layout
37969
37970 \begin_layout Standard
37971
37972 \size footnotesize
37973 \InsetSpace ~
37974 \InsetSpace ~
37975 mov _p,a
37976 \end_layout
37977
37978 \begin_layout Standard
37979
37980 \size footnotesize
37981 \InsetSpace ~
37982 \InsetSpace ~
37983 clr a
37984 \end_layout
37985
37986 \begin_layout Standard
37987
37988 \size footnotesize
37989 \InsetSpace ~
37990 \InsetSpace ~
37991 addc a,(_p + 1)
37992 \end_layout
37993
37994 \begin_layout Standard
37995
37996 \size footnotesize
37997 \InsetSpace ~
37998 \InsetSpace ~
37999 mov (_p + 1),a
38000 \end_layout
38001
38002 \begin_layout Standard
38003
38004 \size footnotesize
38005 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38006 \end_layout
38007
38008 \begin_layout Standard
38009
38010 \size footnotesize
38011 \InsetSpace ~
38012 \InsetSpace ~
38013 movx a,@dptr
38014 \end_layout
38015
38016 \begin_layout Standard
38017
38018 \size footnotesize
38019 \InsetSpace ~
38020 \InsetSpace ~
38021 mov r2,a
38022 \end_layout
38023
38024 \begin_layout Standard
38025
38026 \size footnotesize
38027 \InsetSpace ~
38028 \InsetSpace ~
38029 inc dptr
38030 \end_layout
38031
38032 \begin_layout Standard
38033
38034 \size footnotesize
38035 \InsetSpace ~
38036 \InsetSpace ~
38037 movx a,@dptr
38038 \end_layout
38039
38040 \begin_layout Standard
38041
38042 \size footnotesize
38043 \InsetSpace ~
38044 \InsetSpace ~
38045 mov r3,a
38046 \end_layout
38047
38048 \begin_layout Standard
38049
38050 \size footnotesize
38051 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38052 \end_layout
38053
38054 \begin_layout Standard
38055
38056 \size footnotesize
38057 \InsetSpace ~
38058 \InsetSpace ~
38059 mov @r0,ar2
38060 \end_layout
38061
38062 \begin_layout Standard
38063
38064 \size footnotesize
38065 \InsetSpace ~
38066 \InsetSpace ~
38067 inc r0
38068 \end_layout
38069
38070 \begin_layout Standard
38071
38072 \size footnotesize
38073 \InsetSpace ~
38074 \InsetSpace ~
38075 mov @r0,ar3
38076 \end_layout
38077
38078 \begin_layout Standard
38079
38080 \size footnotesize
38081 ; iTemp6 [lr5:16]{_near * int}[r0] = 
38082 \end_layout
38083
38084 \begin_layout Standard
38085
38086 \size footnotesize
38087 ; iTemp6 [lr5:16]{_near * int}[r0] + 
38088 \end_layout
38089
38090 \begin_layout Standard
38091
38092 \size footnotesize
38093 ; 0x2 {short}
38094 \end_layout
38095
38096 \begin_layout Standard
38097
38098 \size footnotesize
38099 \InsetSpace ~
38100 \InsetSpace ~
38101 inc r0
38102 \end_layout
38103
38104 \begin_layout Standard
38105
38106 \size footnotesize
38107 ; goto _whilecontinue_0($1)
38108 \end_layout
38109
38110 \begin_layout Standard
38111
38112 \size footnotesize
38113 \InsetSpace ~
38114 \InsetSpace ~
38115 sjmp 00101$
38116 \end_layout
38117
38118 \begin_layout Standard
38119
38120 \size footnotesize
38121 ; _whilebreak_0($3) :
38122 \end_layout
38123
38124 \begin_layout Standard
38125
38126 \size footnotesize
38127 00103$:
38128 \end_layout
38129
38130 \begin_layout Standard
38131
38132 \size footnotesize
38133 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38134 \end_layout
38135
38136 \begin_layout Standard
38137
38138 \size footnotesize
38139 \InsetSpace ~
38140 \InsetSpace ~
38141 mov r2,#0x00
38142 \end_layout
38143
38144 \begin_layout Standard
38145
38146 \size footnotesize
38147 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38148 \end_layout
38149
38150 \begin_layout Standard
38151
38152 \size footnotesize
38153 \InsetSpace ~
38154 \InsetSpace ~
38155 mov r3,#0x00
38156 \end_layout
38157
38158 \begin_layout Standard
38159
38160 \size footnotesize
38161 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38162 \end_layout
38163
38164 \begin_layout Standard
38165
38166 \size footnotesize
38167 \InsetSpace ~
38168 \InsetSpace ~
38169 mov r4,#0x00
38170 \end_layout
38171
38172 \begin_layout Standard
38173
38174 \size footnotesize
38175 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38176 \end_layout
38177
38178 \begin_layout Standard
38179
38180 \size footnotesize
38181 \InsetSpace ~
38182 \InsetSpace ~
38183 mov r5,#0x0A
38184 \end_layout
38185
38186 \begin_layout Standard
38187
38188 \size footnotesize
38189 \InsetSpace ~
38190 \InsetSpace ~
38191 mov r6,#0x00
38192 \end_layout
38193
38194 \begin_layout Standard
38195
38196 \size footnotesize
38197 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38198 \end_layout
38199
38200 \begin_layout Standard
38201
38202 \size footnotesize
38203 \InsetSpace ~
38204 \InsetSpace ~
38205 mov r7,#0x1E
38206 \end_layout
38207
38208 \begin_layout Standard
38209
38210 \size footnotesize
38211 \InsetSpace ~
38212 \InsetSpace ~
38213 mov r0,#0x00
38214 \end_layout
38215
38216 \begin_layout Standard
38217
38218 \size footnotesize
38219 ; _forcond_0($4) :
38220 \end_layout
38221
38222 \begin_layout Standard
38223
38224 \size footnotesize
38225 00104$:
38226 \end_layout
38227
38228 \begin_layout Standard
38229
38230 \size footnotesize
38231 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38232 \end_layout
38233
38234 \begin_layout Standard
38235
38236 \size footnotesize
38237 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38238 \end_layout
38239
38240 \begin_layout Standard
38241
38242 \size footnotesize
38243 \InsetSpace ~
38244 \InsetSpace ~
38245 clr c
38246 \end_layout
38247
38248 \begin_layout Standard
38249
38250 \size footnotesize
38251 \InsetSpace ~
38252 \InsetSpace ~
38253 mov a,r4
38254 \end_layout
38255
38256 \begin_layout Standard
38257
38258 \size footnotesize
38259 \InsetSpace ~
38260 \InsetSpace ~
38261 xrl a,#0x80
38262 \end_layout
38263
38264 \begin_layout Standard
38265
38266 \size footnotesize
38267 \InsetSpace ~
38268 \InsetSpace ~
38269 subb a,#0x8a
38270 \end_layout
38271
38272 \begin_layout Standard
38273
38274 \size footnotesize
38275 \InsetSpace ~
38276 \InsetSpace ~
38277 jnc 00107$
38278 \end_layout
38279
38280 \begin_layout Standard
38281
38282 \size footnotesize
38283 00115$:
38284 \end_layout
38285
38286 \begin_layout Standard
38287
38288 \size footnotesize
38289 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
38290 \end_layout
38291
38292 \begin_layout Standard
38293
38294 \size footnotesize
38295 ; iTemp21 [lr21:38]{short}[r4]
38296 \end_layout
38297
38298 \begin_layout Standard
38299
38300 \size footnotesize
38301 \InsetSpace ~
38302 \InsetSpace ~
38303 mov a,r4
38304 \end_layout
38305
38306 \begin_layout Standard
38307
38308 \size footnotesize
38309 \InsetSpace ~
38310 \InsetSpace ~
38311 add a,r2
38312 \end_layout
38313
38314 \begin_layout Standard
38315
38316 \size footnotesize
38317 \InsetSpace ~
38318 \InsetSpace ~
38319 mov r2,a
38320 \end_layout
38321
38322 \begin_layout Standard
38323
38324 \size footnotesize
38325 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38326 \end_layout
38327
38328 \begin_layout Standard
38329
38330 \size footnotesize
38331 \InsetSpace ~
38332 \InsetSpace ~
38333 mov b,#0x03
38334 \end_layout
38335
38336 \begin_layout Standard
38337
38338 \size footnotesize
38339 \InsetSpace ~
38340 \InsetSpace ~
38341 mov a,r4
38342 \end_layout
38343
38344 \begin_layout Standard
38345
38346 \size footnotesize
38347 \InsetSpace ~
38348 \InsetSpace ~
38349 mul ab
38350 \end_layout
38351
38352 \begin_layout Standard
38353
38354 \size footnotesize
38355 \InsetSpace ~
38356 \InsetSpace ~
38357 mov r1,a
38358 \end_layout
38359
38360 \begin_layout Standard
38361
38362 \size footnotesize
38363 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
38364 \end_layout
38365
38366 \begin_layout Standard
38367
38368 \size footnotesize
38369 ; iTemp15 [lr29:30]{short}[r1]
38370 \end_layout
38371
38372 \begin_layout Standard
38373
38374 \size footnotesize
38375 \InsetSpace ~
38376 \InsetSpace ~
38377 add a,r3
38378 \end_layout
38379
38380 \begin_layout Standard
38381
38382 \size footnotesize
38383 \InsetSpace ~
38384 \InsetSpace ~
38385 mov r3,a
38386 \end_layout
38387
38388 \begin_layout Standard
38389
38390 \size footnotesize
38391 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
38392 \end_layout
38393
38394 \begin_layout Standard
38395
38396 \size footnotesize
38397 \InsetSpace ~
38398 \InsetSpace ~
38399 mov a,r7
38400 \end_layout
38401
38402 \begin_layout Standard
38403
38404 \size footnotesize
38405 \InsetSpace ~
38406 \InsetSpace ~
38407 add a,#0xfd
38408 \end_layout
38409
38410 \begin_layout Standard
38411
38412 \size footnotesize
38413 \InsetSpace ~
38414 \InsetSpace ~
38415 mov r7,a
38416 \end_layout
38417
38418 \begin_layout Standard
38419
38420 \size footnotesize
38421 \InsetSpace ~
38422 \InsetSpace ~
38423 mov a,r0
38424 \end_layout
38425
38426 \begin_layout Standard
38427
38428 \size footnotesize
38429 \InsetSpace ~
38430 \InsetSpace ~
38431 addc a,#0xff
38432 \end_layout
38433
38434 \begin_layout Standard
38435
38436 \size footnotesize
38437 \InsetSpace ~
38438 \InsetSpace ~
38439 mov r0,a
38440 \end_layout
38441
38442 \begin_layout Standard
38443
38444 \size footnotesize
38445 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
38446 \end_layout
38447
38448 \begin_layout Standard
38449
38450 \size footnotesize
38451 \InsetSpace ~
38452 \InsetSpace ~
38453 mov a,r7
38454 \end_layout
38455
38456 \begin_layout Standard
38457
38458 \size footnotesize
38459 \InsetSpace ~
38460 \InsetSpace ~
38461 add a,_gint
38462 \end_layout
38463
38464 \begin_layout Standard
38465
38466 \size footnotesize
38467 \InsetSpace ~
38468 \InsetSpace ~
38469 mov _gint,a
38470 \end_layout
38471
38472 \begin_layout Standard
38473
38474 \size footnotesize
38475 \InsetSpace ~
38476 \InsetSpace ~
38477 mov a,r0
38478 \end_layout
38479
38480 \begin_layout Standard
38481
38482 \size footnotesize
38483 \InsetSpace ~
38484 \InsetSpace ~
38485 addc a,(_gint + 1)
38486 \end_layout
38487
38488 \begin_layout Standard
38489
38490 \size footnotesize
38491 \InsetSpace ~
38492 \InsetSpace ~
38493 mov (_gint + 1),a
38494 \end_layout
38495
38496 \begin_layout Standard
38497
38498 \size footnotesize
38499 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
38500 \end_layout
38501
38502 \begin_layout Standard
38503
38504 \size footnotesize
38505 \InsetSpace ~
38506 \InsetSpace ~
38507 inc r4
38508 \end_layout
38509
38510 \begin_layout Standard
38511
38512 \size footnotesize
38513 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
38514 \end_layout
38515
38516 \begin_layout Standard
38517
38518 \size footnotesize
38519 \InsetSpace ~
38520 \InsetSpace ~
38521 dec r5
38522 \end_layout
38523
38524 \begin_layout Standard
38525
38526 \size footnotesize
38527 \InsetSpace ~
38528 \InsetSpace ~
38529 cjne r5,#0xff,00104$
38530 \end_layout
38531
38532 \begin_layout Standard
38533
38534 \size footnotesize
38535 \InsetSpace ~
38536 \InsetSpace ~
38537 dec r6
38538 \end_layout
38539
38540 \begin_layout Standard
38541
38542 \size footnotesize
38543 ; goto _forcond_0($4)
38544 \end_layout
38545
38546 \begin_layout Standard
38547
38548 \size footnotesize
38549 \InsetSpace ~
38550 \InsetSpace ~
38551 sjmp 00104$
38552 \end_layout
38553
38554 \begin_layout Standard
38555
38556 \size footnotesize
38557 ; _forbreak_0($7) :
38558 \end_layout
38559
38560 \begin_layout Standard
38561
38562 \size footnotesize
38563 00107$:
38564 \end_layout
38565
38566 \begin_layout Standard
38567
38568 \size footnotesize
38569 ; ret iTemp24 [lr40:41]{short}
38570 \end_layout
38571
38572 \begin_layout Standard
38573
38574 \size footnotesize
38575 \InsetSpace ~
38576 \InsetSpace ~
38577 mov a,r3
38578 \end_layout
38579
38580 \begin_layout Standard
38581
38582 \size footnotesize
38583 \InsetSpace ~
38584 \InsetSpace ~
38585 add a,r2
38586 \end_layout
38587
38588 \begin_layout Standard
38589
38590 \size footnotesize
38591 \InsetSpace ~
38592 \InsetSpace ~
38593 mov dpl,a
38594 \end_layout
38595
38596 \begin_layout Standard
38597
38598 \size footnotesize
38599 ; _return($8) :
38600 \end_layout
38601
38602 \begin_layout Standard
38603
38604 \size footnotesize
38605 00108$:
38606 \end_layout
38607
38608 \begin_layout Standard
38609
38610 \size footnotesize
38611 \InsetSpace ~
38612 \InsetSpace ~
38613 ret
38614 \newline
38615
38616 \end_layout
38617
38618 \begin_layout Section
38619 A few words about basic block successors, predecessors and dominators
38620 \end_layout
38621
38622 \begin_layout Standard
38623 Successors are basic blocks
38624 \begin_inset LatexCommand \index{Basic blocks}
38625
38626 \end_inset
38627
38628  that might execute after this basic block.
38629 \newline
38630 Predecessors are basic blocks
38631  that might execute before reaching this basic block.
38632 \newline
38633 Dominators are basic
38634  blocks that WILL execute before reaching this basic block.
38635 \newline
38636
38637 \end_layout
38638
38639 \begin_layout Standard
38640 [basic block 1]
38641 \end_layout
38642
38643 \begin_layout Standard
38644 if (something)
38645 \end_layout
38646
38647 \begin_layout Standard
38648 \InsetSpace ~
38649 \InsetSpace ~
38650 \InsetSpace ~
38651 \InsetSpace ~
38652 [basic block 2]
38653 \end_layout
38654
38655 \begin_layout Standard
38656 else
38657 \end_layout
38658
38659 \begin_layout Standard
38660 \InsetSpace ~
38661 \InsetSpace ~
38662 \InsetSpace ~
38663 \InsetSpace ~
38664 [basic block 3]
38665 \end_layout
38666
38667 \begin_layout Standard
38668 [basic block 4]
38669 \newline
38670
38671 \end_layout
38672
38673 \begin_layout Standard
38674 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
38675 \end_layout
38676
38677 \begin_layout Standard
38678 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
38679 \end_layout
38680
38681 \begin_layout Standard
38682 c) domVect of [BB4] = BB1 ...
38683  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
38684  was executed.
38685 \end_layout
38686
38687 \begin_layout Chapter
38688 Acknowledgments
38689 \end_layout
38690
38691 \begin_layout Standard
38692 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
38693
38694 \end_inset
38695
38696
38697 \newline
38698
38699 \newline
38700
38701 \emph on
38702 Thanks to all the other volunteer developers who have helped with coding,
38703  testing, web-page creation, distribution sets, etc.
38704  You know who you are :-)
38705 \emph default
38706
38707 \newline
38708
38709 \newline
38710
38711 \emph on
38712 Also thanks to Sourceforge 
38713 \begin_inset LatexCommand \url{http://www.sf.net}
38714
38715 \end_inset
38716
38717  which has hosted the project since 1999 and donates significant download
38718  bandwidth and probably more than 
38719 \begin_inset ERT
38720 status collapsed
38721
38722 \begin_layout Standard
38723
38724 $10^{13}$
38725 \end_layout
38726
38727 \end_inset
38728
38729 CPU cycles per day.
38730 \newline
38731  
38732 \begin_inset Note Note
38733 status open
38734
38735 \begin_layout Standard
38736 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
38737  minutes for (configure+make+regression test), and there is (i386, amd64,
38738  alpha, ppc64, (mingw32), sparc, macosx).
38739  
38740 \end_layout
38741
38742 \end_inset
38743
38744
38745 \end_layout
38746
38747 \begin_layout Standard
38748 This document was initially written by Sandeep Dutta
38749 \end_layout
38750
38751 \begin_layout Standard
38752 All product names mentioned herein may be trademarks
38753 \begin_inset LatexCommand \index{Trademarks}
38754
38755 \end_inset
38756
38757  of their respective companies.
38758  
38759 \end_layout
38760
38761 \begin_layout Section*
38762 Alphabetical index
38763 \end_layout
38764
38765 \begin_layout Standard
38766 To avoid confusion, the installation and building options for SDCC itself
38767  (chapter 2) are not part of the index.
38768 \end_layout
38769
38770 \begin_layout Standard
38771 \begin_inset LatexCommand \printindex{}
38772
38773 \end_inset
38774
38775
38776 \end_layout
38777
38778 \end_body
38779 \end_document