* .version,
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.5 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 would otherwise 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.8.2
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 free open source, retargettable, optimizing ANSI-C compiler
167  by 
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.
680  The debugger currently uses ucSim, a free open source simulator for 8051
681  and other micro-controllers.
682 \newline
683
684 \newline
685 The latest SDCC version can be downloaded from
686  
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
688
689 \end_inset
690
691 .
692
693 \series bold
694  
695 \series default
696 \emph on
697 Please note: the compiler will probably always be some steps ahead of this
698  documentation
699 \series bold
700 \emph default
701
702 \begin_inset LatexCommand \index{Status of documentation}
703
704 \end_inset
705
706
707 \begin_inset Foot
708 status open
709
710 \begin_layout Standard
711 Obviously this has pros and cons
712 \end_layout
713
714 \end_inset
715
716 .
717 \end_layout
718
719 \begin_layout Section
720 Open Source
721 \end_layout
722
723 \begin_layout Standard
724 All packages used in this compiler system are 
725 \emph on
726 open source
727 \emph default
728  and 
729 \emph on
730 freeware
731 \emph default
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733  etc.) is distributed with the package.
734  This documentation is maintained using a free open source word processor
735  (LyX).
736 \newline
737 This program is free software; you can redistribute it and/or modify
738  it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
740
741 \end_inset
742
743  as published by the Free Software Foundation; either version 2, or (at
744  your option) any later version.
745  This program is distributed in the hope that it will be useful, but WITHOUT
746  ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
748
749 \end_inset
750
751  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752  See the GNU General Public License for more details.
753  You should have received a copy of the GNU General Public License along
754  with this program; if not, write to the Free Software Foundation, 59 Temple
755  Place - Suite 330, Boston, MA 02111-1307, USA.
756  In other words, you are welcome to use, share and improve this program.
757  You are forbidden to forbid anyone else to use, share and improve what
758  you give them.
759  Help stamp out software-hoarding! 
760 \end_layout
761
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
765
766 \end_inset
767
768
769 \end_layout
770
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773  Commands you have to type in are printed in 
774 \family sans
775 \series bold
776 "sans serif"
777 \series default
778 .
779
780 \family default
781  Code samples are printed in 
782 \family typewriter
783 typewriter font.
784
785 \family default
786  Interesting items and new terms are printed in 
787 \emph on
788 italic.
789 \end_layout
790
791 \begin_layout Section
792 Compatibility
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
794
795 \end_inset
796
797  with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
799
800 \end_inset
801
802
803 \end_layout
804
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
807  version.
808  But we also sometimes introduce some incompatibilities with older versions.
809  Not just for the fun of it, but to make the compiler more stable, efficient
810  and ANSI compliant
811 \begin_inset LatexCommand \index{ANSI-compliance}
812
813 \end_inset
814
815  (see section 
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
817
818 \end_inset
819
820  for ANSI-Compliance).
821  
822 \begin_inset Note Note
823 status collapsed
824
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
827 \end_layout
828
829 \end_inset
830
831
832 \newline
833
834 \end_layout
835
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838  (8 bits) which is not ANSI compliant.
839  To maintain compatibility, old programs may be compiled using the -
840 \begin_inset ERT
841 status collapsed
842
843 \begin_layout Standard
844
845
846 \backslash
847 /
848 \end_layout
849
850 \end_inset
851
852 -short-is-8bits commandline option (see 
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
854
855 \end_inset
856
857 ).
858 \end_layout
859
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862  files are stored is now in /usr/local/share.
863 \end_layout
864
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
868
869 \end_inset
870
871  functions are casted to int unless explicitly casted and 
872 \series bold
873 -
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 -std-c89
887 \begin_inset LatexCommand \index{-\/-std-c89}
888
889 \end_inset
890
891  
892 \series default
893 and
894 \series bold
895  -
896 \begin_inset ERT
897 status collapsed
898
899 \begin_layout Standard
900
901
902 \backslash
903 /
904 \end_layout
905
906 \end_inset
907
908 -std-c99
909 \begin_inset LatexCommand \index{-\/-std-c99}
910
911 \end_inset
912
913
914 \series default
915  command line option are not defined 
916 \begin_inset Marginal
917 status collapsed
918
919 \begin_layout Standard
920
921 \series bold
922 \InsetSpace ~
923 !
924 \end_layout
925
926 \end_inset
927
928 , e.g.: 
929 \newline
930
931 \family typewriter
932 \InsetSpace ~
933 \InsetSpace ~
934 char a=3;
935 \newline
936 \InsetSpace ~
937 \InsetSpace ~
938 printf ("%d %c
939 \backslash
940 n", a, (char)a);
941 \family default
942
943 \newline
944  will push a as an int and as a char resp if
945 \series bold
946  -
947 \begin_inset ERT
948 status collapsed
949
950 \begin_layout Standard
951
952
953 \backslash
954 /
955 \end_layout
956
957 \end_inset
958
959 -std-c89
960 \begin_inset LatexCommand \index{-\/-std-c89}
961
962 \end_inset
963
964  
965 \series default
966 and
967 \series bold
968  -
969 \begin_inset ERT
970 status collapsed
971
972 \begin_layout Standard
973
974
975 \backslash
976 /
977 \end_layout
978
979 \end_inset
980
981 -std-c99
982 \begin_inset LatexCommand \index{-\/-std-c99}
983
984 \end_inset
985
986
987 \series default
988  command line options are not defined,
989 \newline
990  will push a as two ints if
991 \series bold
992  -
993 \begin_inset ERT
994 status collapsed
995
996 \begin_layout Standard
997
998
999 \backslash
1000 /
1001 \end_layout
1002
1003 \end_inset
1004
1005 -std-c89
1006 \begin_inset LatexCommand \index{-\/-std-c89}
1007
1008 \end_inset
1009
1010  
1011 \series default
1012 or
1013 \series bold
1014  -
1015 \begin_inset ERT
1016 status collapsed
1017
1018 \begin_layout Standard
1019
1020
1021 \backslash
1022 /
1023 \end_layout
1024
1025 \end_inset
1026
1027 -std-c99
1028 \begin_inset LatexCommand \index{-\/-std-c99}
1029
1030 \end_inset
1031
1032
1033 \series default
1034  command line option is defined.
1035 \end_layout
1036
1037 \begin_layout Itemize
1038 option -
1039 \begin_inset ERT
1040 status collapsed
1041
1042 \begin_layout Standard
1043
1044
1045 \backslash
1046 /
1047 \end_layout
1048
1049 \end_inset
1050
1051 -regextend has been removed.
1052 \end_layout
1053
1054 \begin_layout Itemize
1055 option -
1056 \begin_inset ERT
1057 status collapsed
1058
1059 \begin_layout Standard
1060
1061
1062 \backslash
1063 /
1064 \end_layout
1065
1066 \end_inset
1067
1068 -noregparms has been removed.
1069 \end_layout
1070
1071 \begin_layout Itemize
1072 option -
1073 \begin_inset ERT
1074 status collapsed
1075
1076 \begin_layout Standard
1077
1078
1079 \backslash
1080 /
1081 \end_layout
1082
1083 \end_inset
1084
1085 -stack-after-data has been removed.
1086 \end_layout
1087
1088 \begin_layout Itemize
1089 bit
1090 \begin_inset LatexCommand \index{bit}
1091
1092 \end_inset
1093
1094  and sbit
1095 \begin_inset LatexCommand \index{sbit}
1096
1097 \end_inset
1098
1099
1100 \begin_inset LatexCommand \index{\_\_sbit}
1101
1102 \end_inset
1103
1104  types now consistently behave like the C99 _Bool type with respect to type
1105  conversion
1106 \begin_inset LatexCommand \index{type conversion}
1107
1108 \end_inset
1109
1110
1111 \begin_inset LatexCommand \index{type promotion}
1112
1113 \end_inset
1114
1115 .
1116  The most common incompatibility resulting from this change is related to
1117  bit toggling
1118 \begin_inset LatexCommand \index{Bit toggling}
1119
1120 \end_inset
1121
1122  idioms, e.g.:
1123 \newline
1124
1125 \family typewriter
1126 \InsetSpace ~
1127 \InsetSpace ~
1128 bit b;
1129 \newline
1130 \InsetSpace ~
1131 \InsetSpace ~
1132 b = ~
1133 \begin_inset LatexCommand \index{\~\/ Operator}
1134
1135 \end_inset
1136
1137 b; /* equivalent to b=1 instead of toggling b */
1138 \begin_inset Marginal
1139 status collapsed
1140
1141 \begin_layout Standard
1142
1143 \series bold
1144 \InsetSpace ~
1145 !
1146 \end_layout
1147
1148 \end_inset
1149
1150
1151 \newline
1152 \InsetSpace ~
1153 \InsetSpace ~
1154 b = !b; /* toggles b */
1155 \newline
1156
1157 \family default
1158 In previous versions, both forms would have toggled the bit.
1159 \end_layout
1160
1161 \begin_layout Standard
1162
1163 \emph on
1164 <pending: more incompatibilities?>
1165 \end_layout
1166
1167 \begin_layout Section
1168 System Requirements
1169 \end_layout
1170
1171 \begin_layout Standard
1172 What do you need before you start installation of SDCC? A computer, and
1173  a desire to compute.
1174  The preferred method of installation is to compile SDCC from source using
1175  GNU gcc and make.
1176  For Windows some pre-compiled binary distributions are available for your
1177  convenience.
1178  You should have some experience with command line tools and compiler use.
1179 \end_layout
1180
1181 \begin_layout Section
1182 Other Resources
1183 \end_layout
1184
1185 \begin_layout Standard
1186 The SDCC home page at 
1187 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1188
1189 \end_inset
1190
1191  is a great place to find distribution sets.
1192  You can also find links to the user mailing lists that offer help or discuss
1193  SDCC with other SDCC users.
1194  Web links to other SDCC related sites can also be found here.
1195  This document can be found in the DOC directory of the source package as
1196  a text or HTML file.
1197  A pdf version of this document is available at 
1198 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1199
1200 \end_inset
1201
1202 .
1203  Some of the other tools (simulator and assembler) included with SDCC contain
1204  their own documentation and can be found in the source distribution.
1205  If you want the latest unreleased software, the complete source package
1206  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1207 sdcc/trunk/sdcc.
1208 \end_layout
1209
1210 \begin_layout Section
1211 Wishes for the future
1212 \end_layout
1213
1214 \begin_layout Standard
1215 There are (and always will be) some things that could be done.
1216  Here are some I can think of:
1217 \newline
1218
1219 \end_layout
1220
1221 \begin_layout Standard
1222
1223 \family typewriter
1224 char KernelFunction3(char p) at 0x340;
1225 \newline
1226
1227 \end_layout
1228
1229 \begin_layout Standard
1230
1231 \family typewriter
1232 better code banking
1233 \begin_inset LatexCommand \index{code banking (limited support)}
1234
1235 \end_inset
1236
1237  support for mcs51
1238 \newline
1239
1240 \newline
1241
1242 \family default
1243 If you can think of some more, please see the section 
1244 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1245
1246 \end_inset
1247
1248  about filing feature requests
1249 \begin_inset LatexCommand \index{Requesting features}
1250
1251 \end_inset
1252
1253
1254 \begin_inset LatexCommand \index{Feature request}
1255
1256 \end_inset
1257
1258 .
1259 \newline
1260
1261 \end_layout
1262
1263 \begin_layout Chapter
1264 Installing SDCC
1265 \begin_inset LatexCommand \index{Installation}
1266
1267 \end_inset
1268
1269
1270 \end_layout
1271
1272 \begin_layout Standard
1273 For most users it is sufficient to skip to either section 
1274 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1275
1276 \end_inset
1277
1278  (Unix) or section 
1279 \begin_inset LatexCommand \ref{sub:Windows-Install}
1280
1281 \end_inset
1282
1283  (Windows).
1284  More detailed instructions follow below.
1285 \end_layout
1286
1287 \begin_layout Section
1288 Configure Options
1289 \begin_inset LatexCommand \index{Options SDCC configuration}
1290
1291 \end_inset
1292
1293
1294 \end_layout
1295
1296 \begin_layout Standard
1297 The install paths, search paths and other options are defined when running
1298  'configure'.
1299  The defaults can be overridden by:
1300 \end_layout
1301
1302 \begin_layout List
1303 \labelwidthstring 00.00.0000
1304 -
1305 \begin_inset ERT
1306 status collapsed
1307
1308 \begin_layout Standard
1309
1310
1311 \backslash
1312 /
1313 \end_layout
1314
1315 \end_inset
1316
1317 -prefix see table below
1318 \end_layout
1319
1320 \begin_layout List
1321 \labelwidthstring 00.00.0000
1322 -
1323 \begin_inset ERT
1324 status collapsed
1325
1326 \begin_layout Standard
1327
1328
1329 \backslash
1330 /
1331 \end_layout
1332
1333 \end_inset
1334
1335 -exec_prefix see table below
1336 \end_layout
1337
1338 \begin_layout List
1339 \labelwidthstring 00.00.0000
1340 -
1341 \begin_inset ERT
1342 status collapsed
1343
1344 \begin_layout Standard
1345
1346
1347 \backslash
1348 /
1349 \end_layout
1350
1351 \end_inset
1352
1353 -bindir see table below
1354 \end_layout
1355
1356 \begin_layout List
1357 \labelwidthstring 00.00.0000
1358 -
1359 \begin_inset ERT
1360 status collapsed
1361
1362 \begin_layout Standard
1363
1364
1365 \backslash
1366 /
1367 \end_layout
1368
1369 \end_inset
1370
1371 -datadir see table below
1372 \end_layout
1373
1374 \begin_layout List
1375 \labelwidthstring 00.00.0000
1376 -
1377 \begin_inset ERT
1378 status collapsed
1379
1380 \begin_layout Standard
1381
1382
1383 \backslash
1384 /
1385 \end_layout
1386
1387 \end_inset
1388
1389 -datarootdir see table below
1390 \newline
1391
1392 \end_layout
1393
1394 \begin_layout List
1395 \labelwidthstring 00.00.0000
1396 \InsetSpace ~
1397 \InsetSpace ~
1398 docdir environment variable, see table below
1399 \end_layout
1400
1401 \begin_layout List
1402 \labelwidthstring 00.00.0000
1403 \InsetSpace ~
1404 \InsetSpace ~
1405 include_dir_suffix environment variable, see table below
1406 \end_layout
1407
1408 \begin_layout List
1409 \labelwidthstring 00.00.0000
1410 \InsetSpace ~
1411 \InsetSpace ~
1412 lib_dir_suffix environment variable, see table below
1413 \end_layout
1414
1415 \begin_layout List
1416 \labelwidthstring 00.00.0000
1417 \InsetSpace ~
1418 \InsetSpace ~
1419 sdccconf_h_dir_separator environment variable, either / or 
1420 \backslash
1421
1422 \backslash
1423  makes sense here.
1424  This character will only be used in sdccconf.h; don't forget it's a C-header,
1425  therefore a double-backslash is needed there.
1426 \newline
1427
1428 \end_layout
1429
1430 \begin_layout List
1431 \labelwidthstring 00.00.0000
1432 -
1433 \begin_inset ERT
1434 status collapsed
1435
1436 \begin_layout Standard
1437
1438
1439 \backslash
1440 /
1441 \end_layout
1442
1443 \end_inset
1444
1445 -disable-mcs51-port Excludes the Intel mcs51 port
1446 \end_layout
1447
1448 \begin_layout List
1449 \labelwidthstring 00.00.0000
1450 -
1451 \begin_inset ERT
1452 status collapsed
1453
1454 \begin_layout Standard
1455
1456
1457 \backslash
1458 /
1459 \end_layout
1460
1461 \end_inset
1462
1463 -disable-gbz80-port Excludes the Gameboy gbz80 port
1464 \end_layout
1465
1466 \begin_layout List
1467 \labelwidthstring 00.00.0000
1468 -
1469 \begin_inset ERT
1470 status collapsed
1471
1472 \begin_layout Standard
1473
1474
1475 \backslash
1476 /
1477 \end_layout
1478
1479 \end_inset
1480
1481 -disable-z80-port Excludes the z80 port
1482 \end_layout
1483
1484 \begin_layout List
1485 \labelwidthstring 00.00.0000
1486 -
1487 \begin_inset ERT
1488 status collapsed
1489
1490 \begin_layout Standard
1491
1492
1493 \backslash
1494 /
1495 \end_layout
1496
1497 \end_inset
1498
1499 -disable-avr-port Excludes the AVR port
1500 \end_layout
1501
1502 \begin_layout List
1503 \labelwidthstring 00.00.0000
1504 -
1505 \begin_inset ERT
1506 status collapsed
1507
1508 \begin_layout Standard
1509
1510
1511 \backslash
1512 /
1513 \end_layout
1514
1515 \end_inset
1516
1517 -disable-ds390-port Excludes the DS390 port
1518 \end_layout
1519
1520 \begin_layout List
1521 \labelwidthstring 00.00.0000
1522 -
1523 \begin_inset ERT
1524 status collapsed
1525
1526 \begin_layout Standard
1527
1528
1529 \backslash
1530 /
1531 \end_layout
1532
1533 \end_inset
1534
1535 -disable-hc08-port Excludes the HC08 port
1536 \end_layout
1537
1538 \begin_layout List
1539 \labelwidthstring 00.00.0000
1540 -
1541 \begin_inset ERT
1542 status collapsed
1543
1544 \begin_layout Standard
1545
1546
1547 \backslash
1548 /
1549 \end_layout
1550
1551 \end_inset
1552
1553 -disable-pic-port Excludes the PIC14 port
1554 \end_layout
1555
1556 \begin_layout List
1557 \labelwidthstring 00.00.0000
1558 -
1559 \begin_inset ERT
1560 status collapsed
1561
1562 \begin_layout Standard
1563
1564
1565 \backslash
1566 /
1567 \end_layout
1568
1569 \end_inset
1570
1571 -disable-pic16-port Excludes the PIC16 port
1572 \end_layout
1573
1574 \begin_layout List
1575 \labelwidthstring 00.00.0000
1576 -
1577 \begin_inset ERT
1578 status collapsed
1579
1580 \begin_layout Standard
1581
1582
1583 \backslash
1584 /
1585 \end_layout
1586
1587 \end_inset
1588
1589 -disable-xa51-port Excludes the XA51 port
1590 \end_layout
1591
1592 \begin_layout List
1593 \labelwidthstring 00.00.0000
1594 -
1595 \begin_inset ERT
1596 status collapsed
1597
1598 \begin_layout Standard
1599
1600
1601 \backslash
1602 /
1603 \end_layout
1604
1605 \end_inset
1606
1607 -disable-ucsim Disables configuring and building of ucsim
1608 \end_layout
1609
1610 \begin_layout List
1611 \labelwidthstring 00.00.0000
1612 -
1613 \begin_inset ERT
1614 status collapsed
1615
1616 \begin_layout Standard
1617
1618
1619 \backslash
1620 /
1621 \end_layout
1622
1623 \end_inset
1624
1625 -disable-device-lib Disables automatically building device libraries
1626 \end_layout
1627
1628 \begin_layout List
1629 \labelwidthstring 00.00.0000
1630 -
1631 \begin_inset ERT
1632 status collapsed
1633
1634 \begin_layout Standard
1635
1636
1637 \backslash
1638 /
1639 \end_layout
1640
1641 \end_inset
1642
1643 -disable-packihx Disables building packihx
1644 \newline
1645
1646 \end_layout
1647
1648 \begin_layout List
1649 \labelwidthstring 00.00.0000
1650 -
1651 \begin_inset ERT
1652 status collapsed
1653
1654 \begin_layout Standard
1655
1656
1657 \backslash
1658 /
1659 \end_layout
1660
1661 \end_inset
1662
1663 -enable-doc Build pdf, html and txt files from the lyx sources
1664 \end_layout
1665
1666 \begin_layout List
1667 \labelwidthstring 00.00.0000
1668 -
1669 \begin_inset ERT
1670 status collapsed
1671
1672 \begin_layout Standard
1673
1674
1675 \backslash
1676 /
1677 \end_layout
1678
1679 \end_inset
1680
1681 -enable-libgc Use the Bohem memory allocator.
1682  Lower runtime footprint.
1683 \end_layout
1684
1685 \begin_layout Standard
1686 Furthermore the environment variables CC, CFLAGS, ...
1687  the tools and their arguments can be influenced.
1688  Please see `configure -
1689 \begin_inset ERT
1690 status collapsed
1691
1692 \begin_layout Standard
1693
1694
1695 \backslash
1696 /
1697 \end_layout
1698
1699 \end_inset
1700
1701 -help' and the man/info pages of `configure' for details.
1702 \newline
1703
1704 \newline
1705 The names of the
1706  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1707 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1708  SDCC_LIB_NAME are defined by `configure' too.
1709  At the moment it's not possible to change the default settings (it was
1710  simply never required).
1711 \newline
1712
1713 \newline
1714 These configure options are compiled into the binaries,
1715  and can only be changed by rerunning 'configure' and recompiling SDCC.
1716  The configure options are written in 
1717 \emph on
1718 italics
1719 \emph default
1720  to distinguish them from run time environment variables (see section search
1721  paths).
1722 \newline
1723
1724 \newline
1725 The settings for 
1726 \begin_inset Quotes sld
1727 \end_inset
1728
1729 Win32 builds
1730 \begin_inset Quotes srd
1731 \end_inset
1732
1733  are used by the SDCC team to build the official Win32 binaries.
1734  The SDCC team uses Mingw32 to build the official Windows binaries, because
1735  it's
1736 \end_layout
1737
1738 \begin_layout Enumerate
1739 open source, 
1740 \end_layout
1741
1742 \begin_layout Enumerate
1743 a gcc compiler and last but not least
1744 \end_layout
1745
1746 \begin_layout Enumerate
1747 the binaries can be built by cross compiling on SDCC Distributed Compile
1748  Farm.
1749 \end_layout
1750
1751 \begin_layout Standard
1752 See the examples, how to pass the Win32 settings to 'configure'.
1753  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1754  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1755  for Win32.
1756 \newline
1757
1758 \newline
1759 These defaults are:
1760 \newline
1761
1762 \end_layout
1763
1764 \begin_layout Standard
1765 \align center
1766 \begin_inset Tabular
1767 <lyxtabular version="3" rows="9" columns="3">
1768 <features>
1769 <column alignment="block" valignment="top" leftline="true" width="0in">
1770 <column alignment="block" valignment="top" leftline="true" width="0in">
1771 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1772 <row topline="true" bottomline="true">
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1774 \begin_inset Text
1775
1776 \begin_layout Standard
1777 Variable
1778 \end_layout
1779
1780 \end_inset
1781 </cell>
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 \begin_inset Text
1784
1785 \begin_layout Standard
1786 default
1787 \end_layout
1788
1789 \end_inset
1790 </cell>
1791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1792 \begin_inset Text
1793
1794 \begin_layout Standard
1795 Win32 builds
1796 \end_layout
1797
1798 \end_inset
1799 </cell>
1800 </row>
1801 <row topline="true">
1802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1803 \begin_inset Text
1804
1805 \begin_layout Standard
1806
1807 \emph on
1808 PREFIX
1809 \end_layout
1810
1811 \end_inset
1812 </cell>
1813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 \begin_inset Text
1815
1816 \begin_layout Standard
1817 /usr/local
1818 \end_layout
1819
1820 \end_inset
1821 </cell>
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1823 \begin_inset Text
1824
1825 \begin_layout Standard
1826
1827 \backslash
1828 sdcc
1829 \end_layout
1830
1831 \end_inset
1832 </cell>
1833 </row>
1834 <row topline="true">
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1836 \begin_inset Text
1837
1838 \begin_layout Standard
1839
1840 \emph on
1841 EXEC_PREFIX
1842 \end_layout
1843
1844 \end_inset
1845 </cell>
1846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1847 \begin_inset Text
1848
1849 \begin_layout Standard
1850
1851 \emph on
1852 $PREFIX
1853 \end_layout
1854
1855 \end_inset
1856 </cell>
1857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1858 \begin_inset Text
1859
1860 \begin_layout Standard
1861
1862 \emph on
1863 $PREFIX
1864 \end_layout
1865
1866 \end_inset
1867 </cell>
1868 </row>
1869 <row topline="true">
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1871 \begin_inset Text
1872
1873 \begin_layout Standard
1874
1875 \emph on
1876 BINDIR
1877 \end_layout
1878
1879 \end_inset
1880 </cell>
1881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1882 \begin_inset Text
1883
1884 \begin_layout Standard
1885
1886 \emph on
1887 $EXEC_PREFIX
1888 \emph default
1889 /bin
1890 \end_layout
1891
1892 \end_inset
1893 </cell>
1894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1895 \begin_inset Text
1896
1897 \begin_layout Standard
1898
1899 \emph on
1900 $EXEC_PREFIX
1901 \emph default
1902
1903 \backslash
1904 bin
1905 \end_layout
1906
1907 \end_inset
1908 </cell>
1909 </row>
1910 <row topline="true">
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1912 \begin_inset Text
1913
1914 \begin_layout Standard
1915
1916 \emph on
1917 DATADIR
1918 \end_layout
1919
1920 \end_inset
1921 </cell>
1922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1923 \begin_inset Text
1924
1925 \begin_layout Standard
1926
1927 \emph on
1928 $DATAROOTDIR
1929 \end_layout
1930
1931 \end_inset
1932 </cell>
1933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1934 \begin_inset Text
1935
1936 \begin_layout Standard
1937
1938 \emph on
1939 $DATAROOTDIR
1940 \end_layout
1941
1942 \end_inset
1943 </cell>
1944 </row>
1945 <row topline="true">
1946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1947 \begin_inset Text
1948
1949 \begin_layout Standard
1950
1951 \emph on
1952 DATAROOTDIR
1953 \end_layout
1954
1955 \end_inset
1956 </cell>
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1958 \begin_inset Text
1959
1960 \begin_layout Standard
1961
1962 \emph on
1963 $PREFIX
1964 \emph default
1965 /share
1966 \end_layout
1967
1968 \end_inset
1969 </cell>
1970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1971 \begin_inset Text
1972
1973 \begin_layout Standard
1974
1975 \emph on
1976 $PREFIX
1977 \end_layout
1978
1979 \end_inset
1980 </cell>
1981 </row>
1982 <row topline="true">
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1984 \begin_inset Text
1985
1986 \begin_layout Standard
1987
1988 \emph on
1989 DOCDIR
1990 \end_layout
1991
1992 \end_inset
1993 </cell>
1994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1995 \begin_inset Text
1996
1997 \begin_layout Standard
1998
1999 \emph on
2000 $DATAROOTDIR
2001 \emph default
2002 /sdcc/doc
2003 \end_layout
2004
2005 \end_inset
2006 </cell>
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2008 \begin_inset Text
2009
2010 \begin_layout Standard
2011
2012 \emph on
2013 $DATAROOTDIR
2014 \emph default
2015
2016 \backslash
2017 doc
2018 \end_layout
2019
2020 \end_inset
2021 </cell>
2022 </row>
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2025 \begin_inset Text
2026
2027 \begin_layout Standard
2028
2029 \emph on
2030 INCLUDE_DIR_SUFFIX
2031 \end_layout
2032
2033 \end_inset
2034 </cell>
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2036 \begin_inset Text
2037
2038 \begin_layout Standard
2039 sdcc/include
2040 \end_layout
2041
2042 \end_inset
2043 </cell>
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2045 \begin_inset Text
2046
2047 \begin_layout Standard
2048 include
2049 \end_layout
2050
2051 \end_inset
2052 </cell>
2053 </row>
2054 <row topline="true" bottomline="true">
2055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2056 \begin_inset Text
2057
2058 \begin_layout Standard
2059
2060 \emph on
2061 LIB_DIR_SUFFIX
2062 \end_layout
2063
2064 \end_inset
2065 </cell>
2066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2067 \begin_inset Text
2068
2069 \begin_layout Standard
2070 sdcc/lib
2071 \end_layout
2072
2073 \end_inset
2074 </cell>
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2076 \begin_inset Text
2077
2078 \begin_layout Standard
2079 lib
2080 \end_layout
2081
2082 \end_inset
2083 </cell>
2084 </row>
2085 </lyxtabular>
2086
2087 \end_inset
2088
2089
2090 \newline
2091
2092 \end_layout
2093
2094 \begin_layout Standard
2095 \noindent
2096 'configure' also computes relative paths.
2097  This is needed for full relocatability of a binary package and to complete
2098  search paths (see section search paths below):
2099 \newline
2100  
2101 \end_layout
2102
2103 \begin_layout Standard
2104 \align center
2105 \begin_inset Tabular
2106 <lyxtabular version="3" rows="4" columns="3">
2107 <features>
2108 <column alignment="block" valignment="top" leftline="true" width="0in">
2109 <column alignment="block" valignment="top" leftline="true" width="0in">
2110 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2111 <row topline="true" bottomline="true">
2112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2113 \begin_inset Text
2114
2115 \begin_layout Standard
2116 Variable (computed)
2117 \end_layout
2118
2119 \end_inset
2120 </cell>
2121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2122 \begin_inset Text
2123
2124 \begin_layout Standard
2125 default
2126 \end_layout
2127
2128 \end_inset
2129 </cell>
2130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2131 \begin_inset Text
2132
2133 \begin_layout Standard
2134 Win32 builds
2135 \end_layout
2136
2137 \end_inset
2138 </cell>
2139 </row>
2140 <row topline="true" bottomline="true">
2141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2142 \begin_inset Text
2143
2144 \begin_layout Standard
2145
2146 \emph on
2147 BIN2DATA_DIR
2148 \end_layout
2149
2150 \end_inset
2151 </cell>
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \begin_layout Standard
2156 ../share
2157 \end_layout
2158
2159 \end_inset
2160 </cell>
2161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2162 \begin_inset Text
2163
2164 \begin_layout Standard
2165 ..
2166 \end_layout
2167
2168 \end_inset
2169 </cell>
2170 </row>
2171 <row bottomline="true">
2172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2173 \begin_inset Text
2174
2175 \begin_layout Standard
2176
2177 \emph on
2178 PREFIX2BIN_DIR
2179 \end_layout
2180
2181 \end_inset
2182 </cell>
2183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2184 \begin_inset Text
2185
2186 \begin_layout Standard
2187 bin
2188 \end_layout
2189
2190 \end_inset
2191 </cell>
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2193 \begin_inset Text
2194
2195 \begin_layout Standard
2196 bin
2197 \end_layout
2198
2199 \end_inset
2200 </cell>
2201 </row>
2202 <row bottomline="true">
2203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2204 \begin_inset Text
2205
2206 \begin_layout Standard
2207
2208 \emph on
2209 PREFIX2DATA_DIR
2210 \end_layout
2211
2212 \end_inset
2213 </cell>
2214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2215 \begin_inset Text
2216
2217 \begin_layout Standard
2218 share/sdcc
2219 \end_layout
2220
2221 \end_inset
2222 </cell>
2223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2224 \begin_inset Text
2225
2226 \begin_layout Standard
2227
2228 \end_layout
2229
2230 \end_inset
2231 </cell>
2232 </row>
2233 </lyxtabular>
2234
2235 \end_inset
2236
2237
2238 \newline
2239
2240 \end_layout
2241
2242 \begin_layout Standard
2243 \noindent
2244 Examples:
2245 \end_layout
2246
2247 \begin_layout LyX-Code
2248 ./configure
2249 \newline
2250 ./configure -
2251 \begin_inset ERT
2252 status collapsed
2253
2254 \begin_layout Standard
2255
2256
2257 \backslash
2258 /
2259 \end_layout
2260
2261 \end_inset
2262
2263 -prefix=
2264 \begin_inset Quotes srd
2265 \end_inset
2266
2267 /usr/bin
2268 \begin_inset Quotes srd
2269 \end_inset
2270
2271  -
2272 \begin_inset ERT
2273 status collapsed
2274
2275 \begin_layout Standard
2276
2277
2278 \backslash
2279 /
2280 \end_layout
2281
2282 \end_inset
2283
2284 -datarootdir=
2285 \begin_inset Quotes srd
2286 \end_inset
2287
2288 /usr/share
2289 \begin_inset Quotes srd
2290 \end_inset
2291
2292
2293 \newline
2294 ./configure -
2295 \begin_inset ERT
2296 status collapsed
2297
2298 \begin_layout Standard
2299
2300
2301 \backslash
2302 /
2303 \end_layout
2304
2305 \end_inset
2306
2307 -disable-avr-port -
2308 \begin_inset ERT
2309 status collapsed
2310
2311 \begin_layout Standard
2312
2313
2314 \backslash
2315 /
2316 \end_layout
2317
2318 \end_inset
2319
2320 -disable-xa51-port
2321 \end_layout
2322
2323 \begin_layout Standard
2324 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2325 32'):
2326 \end_layout
2327
2328 \begin_layout LyX-Code
2329 ./configure 
2330 \backslash
2331
2332 \newline
2333 CC=
2334 \begin_inset Quotes srd
2335 \end_inset
2336
2337 i586-mingw32msvc-gcc
2338 \begin_inset Quotes srd
2339 \end_inset
2340
2341  CXX=
2342 \begin_inset Quotes srd
2343 \end_inset
2344
2345 i586-mingw32msvc-g++
2346 \begin_inset Quotes srd
2347 \end_inset
2348
2349  
2350 \backslash
2351  
2352 \newline
2353 RANLIB=
2354 \begin_inset Quotes srd
2355 \end_inset
2356
2357 i586-mingw32msvc-ranlib
2358 \begin_inset Quotes srd
2359 \end_inset
2360
2361  
2362 \backslash
2363
2364 \newline
2365 STRIP=
2366 \begin_inset Quotes srd
2367 \end_inset
2368
2369 i586-mingw32msvc-strip
2370 \begin_inset Quotes srd
2371 \end_inset
2372
2373  
2374 \backslash
2375
2376 \newline
2377 -
2378 \begin_inset ERT
2379 status collapsed
2380
2381 \begin_layout Standard
2382
2383
2384 \backslash
2385 /
2386 \end_layout
2387
2388 \end_inset
2389
2390 -prefix=
2391 \begin_inset Quotes srd
2392 \end_inset
2393
2394 /sdcc
2395 \begin_inset Quotes srd
2396 \end_inset
2397
2398  
2399 \backslash
2400
2401 \newline
2402 -
2403 \begin_inset ERT
2404 status collapsed
2405
2406 \begin_layout Standard
2407
2408
2409 \backslash
2410 /
2411 \end_layout
2412
2413 \end_inset
2414
2415 -datarootdir=
2416 \begin_inset Quotes srd
2417 \end_inset
2418
2419 /sdcc
2420 \begin_inset Quotes srd
2421 \end_inset
2422
2423  
2424 \backslash
2425
2426 \newline
2427 docdir=
2428 \begin_inset Quotes srd
2429 \end_inset
2430
2431
2432 \backslash
2433 ${datarootdir}/doc
2434 \begin_inset Quotes srd
2435 \end_inset
2436
2437  
2438 \backslash
2439
2440 \newline
2441 include_dir_suffix=
2442 \begin_inset Quotes srd
2443 \end_inset
2444
2445 include
2446 \begin_inset Quotes srd
2447 \end_inset
2448
2449  
2450 \backslash
2451
2452 \newline
2453 lib_dir_suffix=
2454 \begin_inset Quotes srd
2455 \end_inset
2456
2457 lib
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461  
2462 \backslash
2463
2464 \newline
2465 sdccconf_h_dir_separator=
2466 \begin_inset Quotes srd
2467 \end_inset
2468
2469
2470 \backslash
2471
2472 \backslash
2473
2474 \backslash
2475
2476 \backslash
2477
2478 \begin_inset Quotes srd
2479 \end_inset
2480
2481  
2482 \backslash
2483
2484 \newline
2485 -
2486 \begin_inset ERT
2487 status collapsed
2488
2489 \begin_layout Standard
2490
2491
2492 \backslash
2493 /
2494 \end_layout
2495
2496 \end_inset
2497
2498 -disable-device-lib
2499 \backslash
2500
2501 \newline
2502 -
2503 \begin_inset ERT
2504 status collapsed
2505
2506 \begin_layout Standard
2507
2508
2509 \backslash
2510 /
2511 \end_layout
2512
2513 \end_inset
2514
2515 -host=i586-mingw32msvc
2516 \backslash
2517
2518 \newline
2519 -
2520 \begin_inset ERT
2521 status collapsed
2522
2523 \begin_layout Standard
2524
2525
2526 \backslash
2527 /
2528 \end_layout
2529
2530 \end_inset
2531
2532 -build=unknown-unknown-linux-gnu
2533 \end_layout
2534
2535 \begin_layout Standard
2536 To 
2537 \begin_inset Quotes sld
2538 \end_inset
2539
2540 cross
2541 \begin_inset Quotes srd
2542 \end_inset
2543
2544 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2545 ):
2546 \end_layout
2547
2548 \begin_layout LyX-Code
2549 ./configure -C 
2550 \backslash
2551
2552 \newline
2553 -
2554 \begin_inset ERT
2555 status collapsed
2556
2557 \begin_layout Standard
2558
2559
2560 \backslash
2561 /
2562 \end_layout
2563
2564 \end_inset
2565
2566 -prefix=
2567 \begin_inset Quotes srd
2568 \end_inset
2569
2570 /sdcc
2571 \begin_inset Quotes srd
2572 \end_inset
2573
2574  
2575 \backslash
2576
2577 \newline
2578 -
2579 \begin_inset ERT
2580 status collapsed
2581
2582 \begin_layout Standard
2583
2584
2585 \backslash
2586 /
2587 \end_layout
2588
2589 \end_inset
2590
2591 -datarootdir=
2592 \begin_inset Quotes srd
2593 \end_inset
2594
2595 /sdcc
2596 \begin_inset Quotes srd
2597 \end_inset
2598
2599  
2600 \backslash
2601
2602 \newline
2603 docdir=
2604 \begin_inset Quotes srd
2605 \end_inset
2606
2607
2608 \backslash
2609 ${datarootdir}/doc
2610 \begin_inset Quotes srd
2611 \end_inset
2612
2613  
2614 \backslash
2615  
2616 \newline
2617 include_dir_suffix=
2618 \begin_inset Quotes srd
2619 \end_inset
2620
2621 include
2622 \begin_inset Quotes srd
2623 \end_inset
2624
2625  
2626 \backslash
2627
2628 \newline
2629 lib_dir_suffix=
2630 \begin_inset Quotes srd
2631 \end_inset
2632
2633 lib
2634 \begin_inset Quotes srd
2635 \end_inset
2636
2637  
2638 \backslash
2639
2640 \newline
2641 sdccconf_h_dir_separator=
2642 \begin_inset Quotes srd
2643 \end_inset
2644
2645
2646 \backslash
2647
2648 \backslash
2649
2650 \backslash
2651
2652 \backslash
2653
2654 \begin_inset Quotes srd
2655 \end_inset
2656
2657  
2658 \backslash
2659
2660 \newline
2661 CC=
2662 \begin_inset Quotes srd
2663 \end_inset
2664
2665 gcc -mno-cygwin
2666 \begin_inset Quotes srd
2667 \end_inset
2668
2669  
2670 \backslash
2671
2672 \newline
2673 CXX=
2674 \begin_inset Quotes srd
2675 \end_inset
2676
2677 g++ -mno-cygwin
2678 \begin_inset Quotes srd
2679 \end_inset
2680
2681  
2682 \end_layout
2683
2684 \begin_layout Standard
2685 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2686  The option '-
2687 \begin_inset ERT
2688 status collapsed
2689
2690 \begin_layout Standard
2691
2692
2693 \backslash
2694 /
2695 \end_layout
2696
2697 \end_inset
2698
2699 -C' turns on caching, which gives a little bit extra speed.
2700  However if options are changed, it can be necessary to delete the config.cache
2701  file.
2702 \end_layout
2703
2704 \begin_layout Section
2705 Install paths
2706 \begin_inset LatexCommand \label{sub:Install-paths}
2707
2708 \end_inset
2709
2710
2711 \begin_inset LatexCommand \index{Install paths}
2712
2713 \end_inset
2714
2715
2716 \end_layout
2717
2718 \begin_layout Standard
2719 \begin_inset VSpace medskip
2720 \end_inset
2721
2722
2723 \end_layout
2724
2725 \begin_layout Standard
2726 \align center
2727 \begin_inset Tabular
2728 <lyxtabular version="3" rows="5" columns="4">
2729 <features>
2730 <column alignment="left" valignment="top" leftline="true" width="0">
2731 <column alignment="left" valignment="top" leftline="true" width="0">
2732 <column alignment="left" valignment="top" leftline="true" width="0">
2733 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2734 <row topline="true" bottomline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2736 \begin_inset Text
2737
2738 \begin_layout Standard
2739
2740 \series bold
2741 Description
2742 \end_layout
2743
2744 \end_inset
2745 </cell>
2746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 \begin_inset Text
2748
2749 \begin_layout Standard
2750
2751 \series bold
2752 Path
2753 \end_layout
2754
2755 \end_inset
2756 </cell>
2757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_inset Text
2759
2760 \begin_layout Standard
2761
2762 \series bold
2763 Default
2764 \end_layout
2765
2766 \end_inset
2767 </cell>
2768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2769 \begin_inset Text
2770
2771 \begin_layout Standard
2772
2773 \series bold
2774 Win32 builds
2775 \end_layout
2776
2777 \end_inset
2778 </cell>
2779 </row>
2780 <row topline="true">
2781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_inset Text
2783
2784 \begin_layout Standard
2785 Binary files*
2786 \end_layout
2787
2788 \end_inset
2789 </cell>
2790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2791 \begin_inset Text
2792
2793 \begin_layout Standard
2794
2795 \emph on
2796 $EXEC_PREFIX
2797 \end_layout
2798
2799 \end_inset
2800 </cell>
2801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_inset Text
2803
2804 \begin_layout Standard
2805 /usr/local/bin
2806 \end_layout
2807
2808 \end_inset
2809 </cell>
2810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2811 \begin_inset Text
2812
2813 \begin_layout Standard
2814
2815 \backslash
2816 sdcc
2817 \backslash
2818 bin
2819 \end_layout
2820
2821 \end_inset
2822 </cell>
2823 </row>
2824 <row topline="true">
2825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2826 \begin_inset Text
2827
2828 \begin_layout Standard
2829 Include files
2830 \end_layout
2831
2832 \end_inset
2833 </cell>
2834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2835 \begin_inset Text
2836
2837 \begin_layout Standard
2838
2839 \emph on
2840 $DATADIR/ $INCLUDE_DIR_SUFFIX
2841 \end_layout
2842
2843 \end_inset
2844 </cell>
2845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2846 \begin_inset Text
2847
2848 \begin_layout Standard
2849 /usr/local/share/sdcc/include
2850 \end_layout
2851
2852 \end_inset
2853 </cell>
2854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2855 \begin_inset Text
2856
2857 \begin_layout Standard
2858
2859 \backslash
2860 sdcc
2861 \backslash
2862 include
2863 \end_layout
2864
2865 \end_inset
2866 </cell>
2867 </row>
2868 <row topline="true">
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2870 \begin_inset Text
2871
2872 \begin_layout Standard
2873 Library file**
2874 \end_layout
2875
2876 \end_inset
2877 </cell>
2878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2879 \begin_inset Text
2880
2881 \begin_layout Standard
2882
2883 \emph on
2884 $DATADIR/$LIB_DIR_SUFFIX
2885 \end_layout
2886
2887 \end_inset
2888 </cell>
2889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2890 \begin_inset Text
2891
2892 \begin_layout Standard
2893 /usr/local/share/sdcc/lib
2894 \end_layout
2895
2896 \end_inset
2897 </cell>
2898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2899 \begin_inset Text
2900
2901 \begin_layout Standard
2902
2903 \backslash
2904 sdcc
2905 \backslash
2906 lib
2907 \end_layout
2908
2909 \end_inset
2910 </cell>
2911 </row>
2912 <row topline="true" bottomline="true">
2913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2914 \begin_inset Text
2915
2916 \begin_layout Standard
2917 Documentation
2918 \end_layout
2919
2920 \end_inset
2921 </cell>
2922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2923 \begin_inset Text
2924
2925 \begin_layout Standard
2926
2927 \emph on
2928 $DOCDIR
2929 \end_layout
2930
2931 \end_inset
2932 </cell>
2933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2934 \begin_inset Text
2935
2936 \begin_layout Standard
2937 /usr/local/share/sdcc/doc
2938 \end_layout
2939
2940 \end_inset
2941 </cell>
2942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2943 \begin_inset Text
2944
2945 \begin_layout Standard
2946
2947 \backslash
2948 sdcc
2949 \backslash
2950 doc
2951 \end_layout
2952
2953 \end_inset
2954 </cell>
2955 </row>
2956 </lyxtabular>
2957
2958 \end_inset
2959
2960
2961 \end_layout
2962
2963 \begin_layout Verse
2964
2965 \size footnotesize
2966 *compiler, preprocessor, assembler, and linker
2967 \newline
2968 **the 
2969 \shape italic
2970 model
2971 \shape default
2972  is auto-appended by the compiler, e.g.
2973  small, large, z80, ds390 etc
2974 \end_layout
2975
2976 \begin_layout Standard
2977 \noindent
2978 The install paths can still be changed during `make install' with e.g.:
2979 \end_layout
2980
2981 \begin_layout LyX-Code
2982 make install prefix=$(HOME)/local/sdcc
2983 \end_layout
2984
2985 \begin_layout Standard
2986 Of course this doesn't change the search paths compiled into the binaries.
2987 \newline
2988
2989 \newline
2990 Moreove
2991 r the install path can be changed by defining DESTDIR
2992 \begin_inset LatexCommand \index{DESTDIR}
2993
2994 \end_inset
2995
2996 :
2997 \end_layout
2998
2999 \begin_layout LyX-Code
3000 make install DESTDIR=$(HOME)/sdcc.rpm/
3001 \end_layout
3002
3003 \begin_layout Standard
3004 Please note that DESTDIR must have a trailing slash!
3005 \end_layout
3006
3007 \begin_layout Section
3008 Search Paths
3009 \begin_inset LatexCommand \label{sub:Search-Paths}
3010
3011 \end_inset
3012
3013
3014 \begin_inset LatexCommand \index{Search path}
3015
3016 \end_inset
3017
3018
3019 \end_layout
3020
3021 \begin_layout Standard
3022 Some search paths or parts of them are determined by configure variables
3023  (in 
3024 \emph on
3025 italics
3026 \emph default
3027 , see section above).
3028  Further search paths are determined by environment variables during runtime.
3029  
3030 \newline
3031 The paths searched when running the compiler are as follows (the first
3032  catch wins):
3033 \newline
3034
3035 \newline
3036 1.
3037  Binary files (preprocessor, assembler and linker)
3038 \newline
3039
3040 \end_layout
3041
3042 \begin_layout Standard
3043 \align center
3044 \begin_inset Tabular
3045 <lyxtabular version="3" rows="4" columns="3">
3046 <features>
3047 <column alignment="block" valignment="top" leftline="true" width="0in">
3048 <column alignment="block" valignment="top" leftline="true" width="0in">
3049 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3050 <row topline="true" bottomline="true">
3051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_inset Text
3053
3054 \begin_layout Standard
3055 Search path
3056 \end_layout
3057
3058 \end_inset
3059 </cell>
3060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_inset Text
3062
3063 \begin_layout Standard
3064 default
3065 \end_layout
3066
3067 \end_inset
3068 </cell>
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3070 \begin_inset Text
3071
3072 \begin_layout Standard
3073 Win32 builds
3074 \end_layout
3075
3076 \end_inset
3077 </cell>
3078 </row>
3079 <row topline="true">
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3081 \begin_inset Text
3082
3083 \begin_layout Standard
3084 $SDCC_HOME/
3085 \emph on
3086 $PPREFIX2BIN_DIR
3087 \end_layout
3088
3089 \end_inset
3090 </cell>
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3092 \begin_inset Text
3093
3094 \begin_layout Standard
3095 $SDCC_HOME/bin
3096 \end_layout
3097
3098 \end_inset
3099 </cell>
3100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3101 \begin_inset Text
3102
3103 \begin_layout Standard
3104 $SDCC_HOME
3105 \backslash
3106 bin
3107 \end_layout
3108
3109 \end_inset
3110 </cell>
3111 </row>
3112 <row topline="true">
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3114 \begin_inset Text
3115
3116 \begin_layout Standard
3117 Path of argv[0] (if available)
3118 \end_layout
3119
3120 \end_inset
3121 </cell>
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3123 \begin_inset Text
3124
3125 \begin_layout Standard
3126 Path of argv[0]
3127 \end_layout
3128
3129 \end_inset
3130 </cell>
3131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3132 \begin_inset Text
3133
3134 \begin_layout Standard
3135 Path of argv[0]
3136 \end_layout
3137
3138 \end_inset
3139 </cell>
3140 </row>
3141 <row topline="true" bottomline="true">
3142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3143 \begin_inset Text
3144
3145 \begin_layout Standard
3146 $PATH
3147 \end_layout
3148
3149 \end_inset
3150 </cell>
3151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3152 \begin_inset Text
3153
3154 \begin_layout Standard
3155 $PATH
3156 \end_layout
3157
3158 \end_inset
3159 </cell>
3160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3161 \begin_inset Text
3162
3163 \begin_layout Standard
3164 $PATH
3165 \end_layout
3166
3167 \end_inset
3168 </cell>
3169 </row>
3170 </lyxtabular>
3171
3172 \end_inset
3173
3174  
3175 \newline
3176
3177 \end_layout
3178
3179 \begin_layout Standard
3180 \noindent
3181 2.
3182  Include files
3183 \newline
3184
3185 \end_layout
3186
3187 \begin_layout Standard
3188 \align center
3189 \begin_inset Tabular
3190 <lyxtabular version="3" rows="6" columns="3">
3191 <features>
3192 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3193 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3194 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3195 <row topline="true" bottomline="true">
3196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3197 \begin_inset Text
3198
3199 \begin_layout Standard
3200 Search path
3201 \end_layout
3202
3203 \end_inset
3204 </cell>
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3206 \begin_inset Text
3207
3208 \begin_layout Standard
3209 default
3210 \end_layout
3211
3212 \end_inset
3213 </cell>
3214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3215 \begin_inset Text
3216
3217 \begin_layout Standard
3218 Win32 builds
3219 \end_layout
3220
3221 \end_inset
3222 </cell>
3223 </row>
3224 <row topline="true">
3225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3226 \begin_inset Text
3227
3228 \begin_layout Standard
3229 -
3230 \begin_inset ERT
3231 status collapsed
3232
3233 \begin_layout Standard
3234
3235
3236 \backslash
3237 /
3238 \end_layout
3239
3240 \end_inset
3241
3242 -I dir
3243 \end_layout
3244
3245 \end_inset
3246 </cell>
3247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3248 \begin_inset Text
3249
3250 \begin_layout Standard
3251 -
3252 \begin_inset ERT
3253 status collapsed
3254
3255 \begin_layout Standard
3256
3257
3258 \backslash
3259 /
3260 \end_layout
3261
3262 \end_inset
3263
3264 -I dir
3265 \end_layout
3266
3267 \end_inset
3268 </cell>
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3270 \begin_inset Text
3271
3272 \begin_layout Standard
3273 -
3274 \begin_inset ERT
3275 status collapsed
3276
3277 \begin_layout Standard
3278
3279
3280 \backslash
3281 /
3282 \end_layout
3283
3284 \end_inset
3285
3286 -I dir
3287 \end_layout
3288
3289 \end_inset
3290 </cell>
3291 </row>
3292 <row topline="true">
3293 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3294 \begin_inset Text
3295
3296 \begin_layout Standard
3297 $SDCC_INCLUDE
3298 \end_layout
3299
3300 \end_inset
3301 </cell>
3302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3303 \begin_inset Text
3304
3305 \begin_layout Standard
3306 $SDCC_INCLUDE
3307 \end_layout
3308
3309 \end_inset
3310 </cell>
3311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3312 \begin_inset Text
3313
3314 \begin_layout Standard
3315 $SDCC_INCLUDE
3316 \end_layout
3317
3318 \end_inset
3319 </cell>
3320 </row>
3321 <row topline="true">
3322 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3323 \begin_inset Text
3324
3325 \begin_layout Standard
3326 $SDCC_HOME/
3327 \newline
3328
3329 \emph on
3330 $PREFIX2DATA_DIR/
3331 \newline
3332 $INCLUDE_DIR_SUFFIX
3333 \end_layout
3334
3335 \end_inset
3336 </cell>
3337 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3338 \begin_inset Text
3339
3340 \begin_layout Standard
3341 $SDCC_ HOME/
3342 \newline
3343 share/sdcc/
3344 \newline
3345 include
3346 \end_layout
3347
3348 \end_inset
3349 </cell>
3350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3351 \begin_inset Text
3352
3353 \begin_layout Standard
3354 $SDCC_HOME
3355 \backslash
3356 include
3357 \end_layout
3358
3359 \end_inset
3360 </cell>
3361 </row>
3362 <row topline="true">
3363 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3364 \begin_inset Text
3365
3366 \begin_layout Standard
3367 path(argv[0])/
3368 \newline
3369
3370 \emph on
3371 $BIN2DATADIR/
3372 \emph default
3373
3374 \newline
3375
3376 \emph on
3377 $INCLUDE_DIR_SUFFIX
3378 \end_layout
3379
3380 \end_inset
3381 </cell>
3382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3383 \begin_inset Text
3384
3385 \begin_layout Standard
3386 path(argv[0])/
3387 \newline
3388 ../sdcc/include
3389 \newline
3390 \InsetSpace ~
3391 \InsetSpace ~
3392 \InsetSpace ~
3393 \InsetSpace ~
3394 \InsetSpace ~
3395 \InsetSpace ~
3396 \InsetSpace ~
3397 \InsetSpace ~
3398 \InsetSpace ~
3399 \InsetSpace ~
3400 \InsetSpace ~
3401 \InsetSpace ~
3402 \InsetSpace ~
3403 \InsetSpace ~
3404 \InsetSpace ~
3405 \InsetSpace ~
3406 \InsetSpace ~
3407 \InsetSpace ~
3408 \InsetSpace ~
3409 \InsetSpace ~
3410 \InsetSpace ~
3411 \InsetSpace ~
3412 \InsetSpace ~
3413 \InsetSpace ~
3414 \InsetSpace ~
3415 \InsetSpace ~
3416 \InsetSpace ~
3417 \InsetSpace ~
3418 \InsetSpace ~
3419 \InsetSpace ~
3420 \InsetSpace ~
3421 \InsetSpace ~
3422 \InsetSpace ~
3423 \InsetSpace ~
3424 \InsetSpace ~
3425 \InsetSpace ~
3426 \InsetSpace ~
3427 \InsetSpace ~
3428
3429 \end_layout
3430
3431 \end_inset
3432 </cell>
3433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3434 \begin_inset Text
3435
3436 \begin_layout Standard
3437 path(argv[0])
3438 \backslash
3439 ..
3440 \backslash
3441 include
3442 \end_layout
3443
3444 \end_inset
3445 </cell>
3446 </row>
3447 <row topline="true" bottomline="true">
3448 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3449 \begin_inset Text
3450
3451 \begin_layout Standard
3452
3453 \emph on
3454 $DATADIR/
3455 \emph default
3456
3457 \newline
3458
3459 \emph on
3460 $INCLUDE_DIR_SUFFIX
3461 \end_layout
3462
3463 \end_inset
3464 </cell>
3465 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3466 \begin_inset Text
3467
3468 \begin_layout Standard
3469 /usr/local/share/sdcc/
3470 \newline
3471 include
3472 \end_layout
3473
3474 \end_inset
3475 </cell>
3476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3477 \begin_inset Text
3478
3479 \begin_layout Standard
3480 (not on Win32)
3481 \end_layout
3482
3483 \end_inset
3484 </cell>
3485 </row>
3486 </lyxtabular>
3487
3488 \end_inset
3489
3490  
3491 \newline
3492
3493 \end_layout
3494
3495 \begin_layout Standard
3496 \noindent
3497 The option -
3498 \begin_inset ERT
3499 status collapsed
3500
3501 \begin_layout Standard
3502
3503
3504 \backslash
3505 /
3506 \end_layout
3507
3508 \end_inset
3509
3510 -nostdinc disables the last two search paths.
3511 \newline
3512
3513 \newline
3514 3.
3515  Library files 
3516 \newline
3517
3518 \end_layout
3519
3520 \begin_layout Standard
3521 With the exception of 
3522 \begin_inset Quotes sld
3523 \end_inset
3524
3525 -
3526 \begin_inset ERT
3527 status collapsed
3528
3529 \begin_layout Standard
3530
3531
3532 \backslash
3533 /
3534 \end_layout
3535
3536 \end_inset
3537
3538 -L dir
3539 \begin_inset Quotes srd
3540 \end_inset
3541
3542  the 
3543 \shape italic
3544 model
3545 \shape default
3546  is auto-appended by the compiler (e.g.
3547  small, large, z80, ds390 etc.).
3548  
3549 \newline
3550
3551 \end_layout
3552
3553 \begin_layout Standard
3554 \align center
3555 \begin_inset Tabular
3556 <lyxtabular version="3" rows="6" columns="3">
3557 <features>
3558 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3559 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3560 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3561 <row topline="true" bottomline="true">
3562 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3563 \begin_inset Text
3564
3565 \begin_layout Standard
3566 Search path
3567 \end_layout
3568
3569 \end_inset
3570 </cell>
3571 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3572 \begin_inset Text
3573
3574 \begin_layout Standard
3575 default
3576 \end_layout
3577
3578 \end_inset
3579 </cell>
3580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3581 \begin_inset Text
3582
3583 \begin_layout Standard
3584 Win32 builds
3585 \end_layout
3586
3587 \end_inset
3588 </cell>
3589 </row>
3590 <row topline="true">
3591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3592 \begin_inset Text
3593
3594 \begin_layout Standard
3595 -
3596 \begin_inset ERT
3597 status collapsed
3598
3599 \begin_layout Standard
3600
3601
3602 \backslash
3603 /
3604 \end_layout
3605
3606 \end_inset
3607
3608 -L dir
3609 \end_layout
3610
3611 \end_inset
3612 </cell>
3613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3614 \begin_inset Text
3615
3616 \begin_layout Standard
3617 -
3618 \begin_inset ERT
3619 status collapsed
3620
3621 \begin_layout Standard
3622
3623
3624 \backslash
3625 /
3626 \end_layout
3627
3628 \end_inset
3629
3630 -L dir
3631 \end_layout
3632
3633 \end_inset
3634 </cell>
3635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3636 \begin_inset Text
3637
3638 \begin_layout Standard
3639 -
3640 \begin_inset ERT
3641 status collapsed
3642
3643 \begin_layout Standard
3644
3645
3646 \backslash
3647 /
3648 \end_layout
3649
3650 \end_inset
3651
3652 -L dir
3653 \end_layout
3654
3655 \end_inset
3656 </cell>
3657 </row>
3658 <row topline="true">
3659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3660 \begin_inset Text
3661
3662 \begin_layout Standard
3663 $SDCC_LIB/
3664 \newline
3665
3666 \emph on
3667 <model>
3668 \end_layout
3669
3670 \end_inset
3671 </cell>
3672 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3673 \begin_inset Text
3674
3675 \begin_layout Standard
3676 $SDCC_LIB/
3677 \newline
3678
3679 \emph on
3680 <model>
3681 \end_layout
3682
3683 \end_inset
3684 </cell>
3685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3686 \begin_inset Text
3687
3688 \begin_layout Standard
3689 $SDCC_LIB
3690 \backslash
3691
3692 \newline
3693
3694 \emph on
3695 <model>
3696 \end_layout
3697
3698 \end_inset
3699 </cell>
3700 </row>
3701 <row topline="true">
3702 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3703 \begin_inset Text
3704
3705 \begin_layout Standard
3706 $SDCC_HOME/
3707 \newline
3708
3709 \emph on
3710 $PREFIX2DATA_DIR/
3711 \newline
3712 $LIB_DIR_SUFFIX/<model>
3713 \end_layout
3714
3715 \end_inset
3716 </cell>
3717 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3718 \begin_inset Text
3719
3720 \begin_layout Standard
3721 $SDCC_HOME/
3722 \newline
3723 share/sdcc/
3724 \newline
3725 lib/
3726 \emph on
3727 <model>
3728 \end_layout
3729
3730 \end_inset
3731 </cell>
3732 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3733 \begin_inset Text
3734
3735 \begin_layout Standard
3736 $SDCC_HOME
3737 \backslash
3738 lib
3739 \backslash
3740
3741 \emph on
3742
3743 \newline
3744 <model>
3745 \end_layout
3746
3747 \end_inset
3748 </cell>
3749 </row>
3750 <row topline="true">
3751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3752 \begin_inset Text
3753
3754 \begin_layout Standard
3755 path(argv[0])/
3756 \newline
3757
3758 \emph on
3759 $BIN2DATADIR/
3760 \emph default
3761
3762 \newline
3763
3764 \emph on
3765 $LIB_DIR_SUFFIX/<model>
3766 \end_layout
3767
3768 \end_inset
3769 </cell>
3770 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3771 \begin_inset Text
3772
3773 \begin_layout Standard
3774 path(argv[0])/
3775 \newline
3776 ../sdcc/lib/
3777 \emph on
3778 <model>
3779 \newline
3780 \InsetSpace ~
3781 \InsetSpace ~
3782 \InsetSpace ~
3783 \InsetSpace ~
3784 \InsetSpace ~
3785 \InsetSpace ~
3786 \InsetSpace ~
3787 \InsetSpace ~
3788 \InsetSpace ~
3789 \InsetSpace ~
3790 \InsetSpace ~
3791 \InsetSpace ~
3792 \InsetSpace ~
3793 \InsetSpace ~
3794 \InsetSpace ~
3795 \InsetSpace ~
3796 \InsetSpace ~
3797 \InsetSpace ~
3798 \InsetSpace ~
3799 \InsetSpace ~
3800 \InsetSpace ~
3801 \InsetSpace ~
3802 \InsetSpace ~
3803 \InsetSpace ~
3804 \InsetSpace ~
3805 \InsetSpace ~
3806 \InsetSpace ~
3807 \InsetSpace ~
3808 \InsetSpace ~
3809 \InsetSpace ~
3810 \InsetSpace ~
3811 \InsetSpace ~
3812 \InsetSpace ~
3813 \InsetSpace ~
3814 \InsetSpace ~
3815 \InsetSpace ~
3816 \InsetSpace ~
3817 \InsetSpace ~
3818 \InsetSpace ~
3819
3820 \end_layout
3821
3822 \end_inset
3823 </cell>
3824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3825 \begin_inset Text
3826
3827 \begin_layout Standard
3828 path(argv[0])
3829 \backslash
3830
3831 \newline
3832 ..
3833 \backslash
3834 lib
3835 \backslash
3836
3837 \emph on
3838 <model>
3839 \newline
3840 \InsetSpace ~
3841 \InsetSpace ~
3842 \InsetSpace ~
3843 \InsetSpace ~
3844 \InsetSpace ~
3845 \InsetSpace ~
3846 \InsetSpace ~
3847 \InsetSpace ~
3848 \InsetSpace ~
3849 \InsetSpace ~
3850 \InsetSpace ~
3851 \InsetSpace ~
3852 \InsetSpace ~
3853 \InsetSpace ~
3854 \InsetSpace ~
3855 \InsetSpace ~
3856 \InsetSpace ~
3857 \InsetSpace ~
3858 \InsetSpace ~
3859 \InsetSpace ~
3860 \InsetSpace ~
3861 \InsetSpace ~
3862 \InsetSpace ~
3863 \InsetSpace ~
3864 \InsetSpace ~
3865 \InsetSpace ~
3866 \InsetSpace ~
3867 \InsetSpace ~
3868 \InsetSpace ~
3869 \InsetSpace ~
3870 \InsetSpace ~
3871 \InsetSpace ~
3872 \InsetSpace ~
3873 \InsetSpace ~
3874 \InsetSpace ~
3875
3876 \end_layout
3877
3878 \end_inset
3879 </cell>
3880 </row>
3881 <row topline="true" bottomline="true">
3882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3883 \begin_inset Text
3884
3885 \begin_layout Standard
3886
3887 \emph on
3888 $DATADIR/
3889 \newline
3890 $LIB_DIR_SUFFIX/<model>
3891 \end_layout
3892
3893 \end_inset
3894 </cell>
3895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3896 \begin_inset Text
3897
3898 \begin_layout Standard
3899 /usr/local/share/sdcc/
3900 \newline
3901 lib/
3902 \emph on
3903 <model>
3904 \end_layout
3905
3906 \end_inset
3907 </cell>
3908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3909 \begin_inset Text
3910
3911 \begin_layout Standard
3912 (not on Win32)
3913 \end_layout
3914
3915 \end_inset
3916 </cell>
3917 </row>
3918 </lyxtabular>
3919
3920 \end_inset
3921
3922
3923 \newline
3924
3925 \end_layout
3926
3927 \begin_layout Standard
3928 \begin_inset Note Note
3929 status collapsed
3930
3931 \begin_layout Standard
3932 Don't delete any of the stray spaces in the table above without checking
3933  the HTML output (last line)!
3934 \end_layout
3935
3936 \end_inset
3937
3938
3939 \end_layout
3940
3941 \begin_layout Standard
3942 \InsetSpace ~
3943
3944 \newline
3945 The option -
3946 \begin_inset ERT
3947 status collapsed
3948
3949 \begin_layout Standard
3950
3951
3952 \backslash
3953 /
3954 \end_layout
3955
3956 \end_inset
3957
3958 -nostdlib disables the last two search paths.
3959 \end_layout
3960
3961 \begin_layout Section
3962 Building SDCC
3963 \begin_inset LatexCommand \index{Building SDCC}
3964
3965 \end_inset
3966
3967
3968 \end_layout
3969
3970 \begin_layout Subsection
3971 Building SDCC on Linux
3972 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3973
3974 \end_inset
3975
3976
3977 \end_layout
3978
3979 \begin_layout Enumerate
3980
3981 \series medium
3982 Download the source package
3983 \series default
3984  either from the SDCC Subversion repository or from snapshot builds
3985 \series medium
3986 , it will be named something like sdcc
3987 \series default
3988 -src
3989 \series medium
3990 -yyyymmdd-rrrr.t
3991 \series default
3992 ar.
3993 \series medium
3994 bz2
3995 \series default
3996  
3997 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3998
3999 \end_inset
4000
4001 .
4002 \end_layout
4003
4004 \begin_layout Enumerate
4005
4006 \series medium
4007 Bring up a command line terminal, such as xterm.
4008 \end_layout
4009
4010 \begin_layout Enumerate
4011
4012 \series medium
4013 Unpack the file using a command like: 
4014 \family sans
4015 \series bold
4016 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4017 \begin_inset Quotes srd
4018 \end_inset
4019
4020
4021 \family default
4022 \series medium
4023 , this will create a sub-directory called sdcc with all of the sources.
4024 \end_layout
4025
4026 \begin_layout Enumerate
4027 Change directory into the main SDCC directory, for example type: 
4028 \family sans
4029 \series bold
4030 "cd sdcc
4031 \series default
4032 ".
4033 \end_layout
4034
4035 \begin_layout Enumerate
4036
4037 \series medium
4038 Type 
4039 \family sans
4040 \series bold
4041 "./configure
4042 \family default
4043 \series default
4044 ".
4045  This configures the package for compilation on your system.
4046 \end_layout
4047
4048 \begin_layout Enumerate
4049
4050 \series medium
4051 Type 
4052 \family sans
4053 \series bold
4054 "make
4055 \family default
4056 \series default
4057 "
4058 \series medium
4059 .
4060
4061 \series default
4062  All of the source packages will compile, this can take a while.
4063 \end_layout
4064
4065 \begin_layout Enumerate
4066
4067 \series medium
4068 Type 
4069 \family sans
4070 \series bold
4071 "make install"
4072 \family default
4073 \series default
4074  as root
4075 \series medium
4076 .
4077
4078 \series default
4079  This copies the binary executables, the include files, the libraries and
4080  the documentation to the install directories.
4081  Proceed with section 
4082 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4083
4084 \end_inset
4085
4086 .
4087 \end_layout
4088
4089 \begin_layout Subsection
4090 Building SDCC on Mac OS X
4091 \end_layout
4092
4093 \begin_layout Standard
4094 Follow the instruction for Linux.
4095 \newline
4096
4097 \newline
4098 On Mac OS X 10.2.x it was reported, that the
4099  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4100  Fortunately there's also gcc 2.9.x installed, which works fine.
4101  This compiler can be selected by running 'configure' with:
4102 \end_layout
4103
4104 \begin_layout LyX-Code
4105 ./configure CC=gcc2 CXX=g++2
4106 \end_layout
4107
4108 \begin_layout Standard
4109 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4110  Xcode.
4111  Run 'configure' with:
4112 \end_layout
4113
4114 \begin_layout LyX-Code
4115 ./configure 
4116 \backslash
4117
4118 \end_layout
4119
4120 \begin_layout LyX-Code
4121 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4122  ppc" 
4123 \backslash
4124
4125 \end_layout
4126
4127 \begin_layout LyX-Code
4128 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4129  ppc" 
4130 \backslash
4131
4132 \end_layout
4133
4134 \begin_layout LyX-Code
4135 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4136 \end_layout
4137
4138 \begin_layout Subsection
4139 Cross compiling SDCC on Linux for Windows
4140 \end_layout
4141
4142 \begin_layout Standard
4143 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4144  See section 'Configure Options'.
4145 \end_layout
4146
4147 \begin_layout Subsection
4148 Building SDCC using Cygwin and Mingw32
4149 \end_layout
4150
4151 \begin_layout Standard
4152 For building and installing a Cygwin executable follow the instructions
4153  for Linux.
4154 \newline
4155
4156 \newline
4157 On Cygwin a 
4158 \begin_inset Quotes sld
4159 \end_inset
4160
4161 native
4162 \begin_inset Quotes srd
4163 \end_inset
4164
4165  Win32-binary can be built, which will not need the Cygwin-DLL.
4166  For the necessary 'configure' options see section 'configure options' or
4167  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4168 \newline
4169
4170 \newline
4171 In order to install
4172  Cygwin on Windows download setup.exe from 
4173 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4174
4175 \end_inset
4176
4177 .
4178  Run it, set the 
4179 \begin_inset Quotes sld
4180 \end_inset
4181
4182 default text file type
4183 \begin_inset Quotes srd
4184 \end_inset
4185
4186  to 
4187 \begin_inset Quotes sld
4188 \end_inset
4189
4190 unix
4191 \begin_inset Quotes srd
4192 \end_inset
4193
4194  and download/install at least the following packages.
4195  Some packages are selected by default, others will be automatically selected
4196  because of dependencies with the manually selected packages.
4197  Never deselect these packages!
4198 \end_layout
4199
4200 \begin_layout Itemize
4201 flex
4202 \end_layout
4203
4204 \begin_layout Itemize
4205 bison
4206 \end_layout
4207
4208 \begin_layout Itemize
4209 gcc ; version 3.x is fine, no need to use the old 2.9x
4210 \end_layout
4211
4212 \begin_layout Itemize
4213 binutils ; selected with gcc
4214 \end_layout
4215
4216 \begin_layout Itemize
4217 make
4218 \end_layout
4219
4220 \begin_layout Itemize
4221 rxvt ; a nice console, which makes life much easier under windoze (see below)
4222 \end_layout
4223
4224 \begin_layout Itemize
4225 man ; not really needed for building SDCC, but you'll miss it sooner or
4226  later
4227 \end_layout
4228
4229 \begin_layout Itemize
4230 less ; not really needed for building SDCC, but you'll miss it sooner or
4231  later
4232 \end_layout
4233
4234 \begin_layout Itemize
4235 svn ; only if you use Subversion access
4236 \end_layout
4237
4238 \begin_layout Standard
4239 If you want to develop something you'll need:
4240 \end_layout
4241
4242 \begin_layout Itemize
4243 python ; for the regression tests
4244 \end_layout
4245
4246 \begin_layout Itemize
4247 gdb ; the gnu debugger, together with the nice GUI 
4248 \begin_inset Quotes sld
4249 \end_inset
4250
4251 insight
4252 \begin_inset Quotes srd
4253 \end_inset
4254
4255
4256 \end_layout
4257
4258 \begin_layout Itemize
4259 openssh ; to access the CF or commit changes
4260 \end_layout
4261
4262 \begin_layout Itemize
4263 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4264  use autoconf-stable!
4265 \end_layout
4266
4267 \begin_layout Standard
4268 rxvt is a nice console with history.
4269  Replace in your cygwin.bat the line
4270 \end_layout
4271
4272 \begin_layout LyX-Code
4273 bash -
4274 \begin_inset ERT
4275 status collapsed
4276
4277 \begin_layout Standard
4278
4279
4280 \backslash
4281 /
4282 \end_layout
4283
4284 \end_inset
4285
4286 -login -i 
4287 \end_layout
4288
4289 \begin_layout Standard
4290 with (one line):
4291 \end_layout
4292
4293 \begin_layout LyX-Code
4294 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4295 \end_layout
4296
4297 \begin_layout LyX-Code
4298      -bg black -fg white -geometry 100x65 -e bash -
4299 \begin_inset ERT
4300 status collapsed
4301
4302 \begin_layout Standard
4303
4304
4305 \backslash
4306 /
4307 \end_layout
4308
4309 \end_inset
4310
4311 -login
4312 \end_layout
4313
4314 \begin_layout Standard
4315 Text selected with the mouse is automatically copied to the clipboard, pasting
4316  works with shift-insert.
4317 \newline
4318
4319 \newline
4320 The other good tip is to make sure you have no //c/-styl
4321 e paths anywhere, use /cygdrive/c/ instead.
4322  Using // invokes a network lookup which is very slow.
4323  If you think 
4324 \begin_inset Quotes sld
4325 \end_inset
4326
4327 cygdrive
4328 \begin_inset Quotes srd
4329 \end_inset
4330
4331  is too long, you can change it with e.g.
4332 \end_layout
4333
4334 \begin_layout LyX-Code
4335 mount -s -u -c /mnt
4336 \end_layout
4337
4338 \begin_layout Standard
4339 SDCC sources use the unix line ending LF.
4340  Life is much easier, if you store the source tree on a drive which is mounted
4341  in binary mode.
4342  And use an editor which can handle LF-only line endings.
4343  Make sure not to commit files with windows line endings.
4344  The tabulator spacing
4345 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4346
4347 \end_inset
4348
4349  used in the project is 8.
4350  Although a tabulator spacing of 8 is a sensible choice for programmers
4351  (it's a power of 2 and allows to display 8/16 bit signed variables without
4352  loosing columns) the plan is to move towards using only spaces in the source.
4353 \end_layout
4354
4355 \begin_layout Subsection
4356 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4357 \end_layout
4358
4359 \begin_layout Standard
4360
4361 \series medium
4362 Download the source package
4363 \series default
4364  either from the SDCC Subversion repository or from the 
4365 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4366
4367 \end_inset
4368
4369
4370 \series medium
4371 , it will be named something like sdcc
4372 \series default
4373 -src
4374 \series medium
4375 -yyyymmdd-rrrr.tar.bz2.
4376
4377 \series default
4378  SDCC is distributed with all the projects, workspaces, and files you need
4379  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4380  The workspace name is 'sdcc.dsw'.
4381  Please note that as it is now, all the executables are created in a folder
4382  called sdcc
4383 \backslash
4384 bin_vc.
4385  Once built you need to copy the executables from sdcc
4386 \backslash
4387 bin_vc to sdcc
4388 \backslash
4389 bin before running SDCC.
4390  
4391 \newline
4392
4393 \newline
4394 WARNING: Visual studio is very picky with line terminations; it expects
4395  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4396  When using the Subversion repository it's easiest to configure the svn
4397  client to convert automatically for you.
4398  If however you are getting a message such as "This makefile was not generated
4399  by Developer Studio etc.
4400  etc.
4401 \begin_inset Quotes srd
4402 \end_inset
4403
4404  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4405  need to convert the Unix style line endings to DOS style line endings.
4406  To do so you can use the 
4407 \begin_inset Quotes sld
4408 \end_inset
4409
4410 unix2dos
4411 \begin_inset Quotes srd
4412 \end_inset
4413
4414  utility freely available on the internet.
4415  Doug Hawkins reported in the sdcc-user list that this works:
4416 \newline
4417
4418 \newline
4419 C:
4420 \backslash
4421 Programming
4422 \backslash
4423 SDCC> unix2dos sdcc.dsw
4424 \newline
4425 C:
4426 \backslash
4427 Programming
4428 \backslash
4429 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4430 \newline
4431
4432 \newline
4433 In order to build SDCC with MSVC
4434  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4435  One good place to get them is 
4436 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4437
4438 \end_inset
4439
4440
4441 \newline
4442
4443 \newline
4444 Download the file UnxUtils
4445 \begin_inset LatexCommand \index{UnxUtils}
4446
4447 \end_inset
4448
4449 .zip.
4450  Now you have to install the utilities and setup MSVC so it can locate the
4451  required programs.
4452  Here there are two alternatives (choose one!):
4453 \end_layout
4454
4455 \begin_layout Enumerate
4456 The easy way:
4457 \newline
4458
4459 \newline
4460 a) Extract UnxUtils.zip to your C:
4461 \backslash
4462  hard disk PRESERVING the original paths, otherwise bison won't work.
4463  (If you are using WinZip make certain that 'Use folder names' is selected)
4464 \newline
4465
4466 \newline
4467 b)
4468  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4469  'Show directories for:' select 'Executable files', and in the directories
4470  window add a new path: 'C:
4471 \backslash
4472 user
4473 \backslash
4474 local
4475 \backslash
4476 wbin', click ok.
4477 \newline
4478
4479 \newline
4480 (As a side effect, you get a bunch of Unix utilities that
4481  could be useful, such as diff and patch.)
4482 \end_layout
4483
4484 \begin_layout Enumerate
4485 A more compact way:
4486 \newline
4487
4488 \newline
4489 This one avoids extracting a bunch of files you may not
4490  use, but requires some extra work:
4491 \newline
4492
4493 \newline
4494 a) Create a directory were to put the
4495  tools needed, or use a directory already present.
4496  Say for example 'C:
4497 \backslash
4498 util'.
4499 \newline
4500
4501 \newline
4502 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4503  gawk.exe to such directory WITHOUT preserving the original paths.
4504  (If you are using WinZip make certain that 'Use folder names' is not selected)
4505 \newline
4506
4507 \newline
4508 c
4509 ) Rename bison.exe to '_bison.exe'.
4510 \newline
4511
4512 \newline
4513 d) Create a batch file 'bison.bat' in 'C:
4514 \backslash
4515 util
4516 \backslash
4517 ' and add these lines: 
4518 \newline
4519 \InsetSpace ~
4520 \InsetSpace ~
4521 set BISON_SIMPLE=C:
4522 \backslash
4523 util
4524 \backslash
4525 bison.simple 
4526 \newline
4527 \InsetSpace ~
4528 \InsetSpace ~
4529 set BISON_HAIRY=C:
4530 \backslash
4531 util
4532 \backslash
4533 bison.hairy
4534 \newline
4535 \InsetSpace ~
4536 \InsetSpace ~
4537 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4538 \newline
4539
4540 \newline
4541 Steps 'c' and 'd' are needed
4542  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4543  reside in some weird Unix directory, '/usr/local/share/' I think.
4544  So it is necessary to tell bison where those files are located if they
4545  are not in such directory.
4546  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4547 \newline
4548
4549 \newline
4550 e
4551 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4552  in 'Show directories for:' select 'Executable files', and in the directories
4553  window add a new path: 'c:
4554 \backslash
4555 util', click ok.
4556  Note that you can use any other path instead of 'c:
4557 \backslash
4558 util', even the path where the Visual C++ tools are, probably: 'C:
4559 \backslash
4560 Program Files
4561 \backslash
4562 Microsoft Visual Studio
4563 \backslash
4564 Common
4565 \backslash
4566 Tools'.
4567  So you don't have to execute step 'e' :)
4568 \end_layout
4569
4570 \begin_layout Standard
4571 That is it.
4572  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4573  the executables from sdcc
4574 \backslash
4575 bin_vc to sdcc
4576 \backslash
4577 bin, and you can compile using SDCC.
4578 \end_layout
4579
4580 \begin_layout Subsection
4581 Building SDCC Using Borland
4582 \end_layout
4583
4584 \begin_layout Enumerate
4585 From the sdcc directory, run the command "make -f Makefile.bcc".
4586  This should regenerate all the .exe files in the bin directory except for
4587  SDCDB and ucSim.
4588 \end_layout
4589
4590 \begin_layout Enumerate
4591 If you modify any source files and need to rebuild, be aware that the dependenci
4592 es may not be correctly calculated.
4593  The safest option is to delete all .obj files and run the build again.
4594  From a Cygwin BASH prompt, this can easily be done with the command (be
4595  sure you are in the sdcc directory):
4596 \newline
4597
4598 \newline
4599
4600 \family sans
4601 \series bold
4602 find .
4603  
4604 \backslash
4605 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4606 \backslash
4607 ) -print -exec rm {} 
4608 \backslash
4609 ;
4610 \family default
4611 \series default
4612
4613 \newline
4614
4615 \newline
4616 or on Windows NT/2000/XP from the command prompt with the command:
4617 \newline
4618
4619 \family sans
4620 \series bold
4621
4622 \newline
4623 del /s *.obj *.lib *.rul
4624 \family default
4625 \series default
4626  from the sdcc directory.
4627 \end_layout
4628
4629 \begin_layout Subsection
4630 Windows Install Using a ZIP Package
4631 \end_layout
4632
4633 \begin_layout Enumerate
4634 Download the binary zip package from 
4635 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4636
4637 \end_inset
4638
4639  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4640  This should unpack to a group of sub-directories.
4641  An example directory structure after unpacking the mingw32 package is:
4642  c:
4643 \backslash
4644 sdcc
4645 \backslash
4646 bin for the executables, c:
4647 \backslash
4648 sdcc
4649 \backslash
4650 include and c:
4651 \backslash
4652 sdcc
4653 \backslash
4654 lib for the include and libraries.
4655 \end_layout
4656
4657 \begin_layout Enumerate
4658 Adjust your environment variable PATH to include the location of the bin
4659  directory or start sdcc using the full path.
4660 \end_layout
4661
4662 \begin_layout Subsection
4663 Windows Install Using the Setup Program
4664 \begin_inset LatexCommand \label{sub:Windows-Install}
4665
4666 \end_inset
4667
4668
4669 \end_layout
4670
4671 \begin_layout Standard
4672 Download the setup program 
4673 \emph on
4674 sdcc-x.y.z-setup.exe
4675 \emph default
4676  for an official release from 
4677 \newline
4678
4679 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4680
4681 \end_inset
4682
4683  or a setup program for one of the snapshots 
4684 \emph on
4685 sdcc-yyyymmdd-xxxx-setup.exe
4686 \emph default
4687  from 
4688 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4689
4690 \end_inset
4691
4692  and execute it.
4693  A windows typical installer will guide you through the installation process.
4694 \end_layout
4695
4696 \begin_layout Subsection
4697 VPATH
4698 \begin_inset LatexCommand \index{VPATH}
4699
4700 \end_inset
4701
4702  feature
4703 \end_layout
4704
4705 \begin_layout Standard
4706 SDCC supports the VPATH feature provided by configure and make.
4707  It allows to separate the source and build trees.
4708  Here's an example:
4709 \end_layout
4710
4711 \begin_layout Standard
4712
4713 \family typewriter
4714 cd ~\InsetSpace ~
4715 \InsetSpace ~
4716 \InsetSpace ~
4717 \InsetSpace ~
4718 \InsetSpace ~
4719 \InsetSpace ~
4720 \InsetSpace ~
4721 \InsetSpace ~
4722 \InsetSpace ~
4723 \InsetSpace ~
4724 \InsetSpace ~
4725 \InsetSpace ~
4726 \InsetSpace ~
4727 \InsetSpace ~
4728 \InsetSpace ~
4729 \InsetSpace ~
4730 \InsetSpace ~
4731 \InsetSpace ~
4732 \InsetSpace ~
4733 \InsetSpace ~
4734 \InsetSpace ~
4735 # cd $HOME
4736 \end_layout
4737
4738 \begin_layout Standard
4739
4740 \family typewriter
4741 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4742 # extract source to directory sdcc
4743 \end_layout
4744
4745 \begin_layout Standard
4746
4747 \family typewriter
4748 mkdir sdcc.build\InsetSpace ~
4749 \InsetSpace ~
4750 \InsetSpace ~
4751 \InsetSpace ~
4752 \InsetSpace ~
4753 \InsetSpace ~
4754 \InsetSpace ~
4755 \InsetSpace ~
4756 \InsetSpace ~
4757 # put output in sdcc.build
4758 \end_layout
4759
4760 \begin_layout Standard
4761
4762 \family typewriter
4763 cd sdcc.build
4764 \end_layout
4765
4766 \begin_layout Standard
4767
4768 \family typewriter
4769 ../sdcc/configure\InsetSpace ~
4770 \InsetSpace ~
4771 \InsetSpace ~
4772 \InsetSpace ~
4773 \InsetSpace ~
4774 \InsetSpace ~
4775 \InsetSpace ~
4776 \InsetSpace ~
4777 # configure is doing all the magic!
4778 \end_layout
4779
4780 \begin_layout Standard
4781
4782 \family typewriter
4783 make
4784 \end_layout
4785
4786 \begin_layout Standard
4787 \noindent
4788 That's it! 
4789 \series bold
4790 configure
4791 \series default
4792  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4793  It automagically computes the variables srcdir, top_srcdir and top_buildir
4794  for each directory.
4795  After running 
4796 \series bold
4797 make
4798 \series default
4799  the generated files will be in ~/sdcc.build, while the source files stay
4800  in ~/sdcc.
4801 \newline
4802 This is not only usefull for building different binaries, e.g.
4803  when cross compiling.
4804  It also gives you a much better overview in the source tree when all the
4805  generated files are not scattered between the source files.
4806  And the best thing is: if you want to change a file you can leave the original
4807  file untouched in the source directory.
4808  Simply copy it to the build directory, edit it, enter `make clean', `rm
4809  Makefile.dep' and `make'.
4810  
4811 \series bold
4812 make
4813 \series default
4814  will do the rest for you!
4815 \end_layout
4816
4817 \begin_layout Section
4818 Building the Documentation
4819 \end_layout
4820
4821 \begin_layout Standard
4822 Add -
4823 \begin_inset ERT
4824 status collapsed
4825
4826 \begin_layout Standard
4827
4828
4829 \backslash
4830 /
4831 \end_layout
4832
4833 \end_inset
4834
4835 -enable-doc to the configure arguments to build the documentation together
4836  with all the other stuff.
4837  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4838  dvips and makeindex) to get the job done.
4839  Another possibility is to change to the doc directory and to type 
4840 \family sans
4841 \series bold
4842
4843 \begin_inset Quotes srd
4844 \end_inset
4845
4846 make
4847 \begin_inset Quotes srd
4848 \end_inset
4849
4850
4851 \family default
4852 \series default
4853  there.
4854  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4855 x).
4856  Using LyX 
4857 \begin_inset LatexCommand \url{http://www.lyx.org}
4858
4859 \end_inset
4860
4861  as editor is straightforward.
4862  Prebuilt documentation in html and pdf format is available from 
4863 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4864
4865 \end_inset
4866
4867 .
4868 \end_layout
4869
4870 \begin_layout Section
4871 Reading the Documentation
4872 \begin_inset LatexCommand \index{Documentation}
4873
4874 \end_inset
4875
4876
4877 \end_layout
4878
4879 \begin_layout Standard
4880 Currently reading the document in pdf format is recommended, as for unknown
4881  reason the hyperlinks are working there whereas in the html version they
4882  are not
4883 \begin_inset Foot
4884 status open
4885
4886 \begin_layout Standard
4887 If you should know why please drop us a note
4888 \end_layout
4889
4890 \end_inset
4891
4892 .
4893  
4894 \newline
4895 You'll find the pdf version
4896 \begin_inset LatexCommand \index{PDF version of this document}
4897
4898 \end_inset
4899
4900  at 
4901 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4902
4903 \end_inset
4904
4905 .
4906  
4907 \newline
4908 A html version
4909 \begin_inset LatexCommand \index{HTML version of this document}
4910
4911 \end_inset
4912
4913  should be online at 
4914 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4915
4916 \end_inset
4917
4918 .
4919 \newline
4920 This documentation is in some aspects different from a commercial documentation:
4921  
4922 \end_layout
4923
4924 \begin_layout Itemize
4925 It tries to document SDCC for several processor architectures in one document
4926  (commercially these probably would be separate documents/products).
4927  This document
4928 \begin_inset LatexCommand \index{Status of documentation}
4929
4930 \end_inset
4931
4932  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4933 on about f.e.
4934  Z80, PIC14, PIC16 and HC08.
4935 \end_layout
4936
4937 \begin_layout Itemize
4938 There are many references pointing away from this documentation.
4939  Don't let this distract you.
4940  If there f.e.
4941  was a reference like 
4942 \begin_inset LatexCommand \url{http://www.opencores.org}
4943
4944 \end_inset
4945
4946  together with a statement 
4947 \begin_inset Quotes sld
4948 \end_inset
4949
4950 some processors which are targetted by SDCC can be implemented in a 
4951 \emph on
4952 f
4953 \emph default
4954 ield 
4955 \emph on
4956 p
4957 \emph default
4958 rogrammable 
4959 \emph on
4960 g
4961 \emph default
4962 ate 
4963 \emph on
4964 a
4965 \emph default
4966 rray
4967 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4968
4969 \end_inset
4970
4971
4972 \begin_inset Quotes srd
4973 \end_inset
4974
4975  or 
4976 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4977
4978 \end_inset
4979
4980
4981 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4982
4983 \end_inset
4984
4985  
4986 \begin_inset Quotes sld
4987 \end_inset
4988
4989 have you ever heard of an open source compiler that compiles a subset of
4990  C for an FPGA?
4991 \begin_inset Quotes srd
4992 \end_inset
4993
4994  we expect you to have a quick look there and come back.
4995  If you read this you are on the right track.
4996 \end_layout
4997
4998 \begin_layout Itemize
4999 Some sections attribute more space to problems, restrictions and warnings
5000  than to the solution.
5001 \end_layout
5002
5003 \begin_layout Itemize
5004 The installation section and the section about the debugger is intimidating.
5005 \end_layout
5006
5007 \begin_layout Itemize
5008 There are still lots of typos and there are more different writing styles
5009  than pictures.
5010 \end_layout
5011
5012 \begin_layout Section
5013 Testing the SDCC Compiler
5014 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5015
5016 \end_inset
5017
5018
5019 \end_layout
5020
5021 \begin_layout Standard
5022 The first thing you should do after installing your SDCC compiler is to
5023  see if it runs.
5024  Type 
5025 \family sans
5026 \series bold
5027 "sdcc -
5028 \begin_inset ERT
5029 status collapsed
5030
5031 \begin_layout Standard
5032
5033
5034 \backslash
5035 /
5036 \end_layout
5037
5038 \end_inset
5039
5040 -version"
5041 \begin_inset LatexCommand \index{version}
5042
5043 \end_inset
5044
5045
5046 \family default
5047 \series default
5048  at the prompt, and the program should run and output its version like:
5049  
5050 \newline
5051
5052 \family typewriter
5053 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5054  (UNIX)
5055 \end_layout
5056
5057 \begin_layout Standard
5058 If it doesn't run, or gives a message about not finding sdcc program, then
5059  you need to check over your installation.
5060  Make sure that the sdcc bin directory is in your executable search path
5061  defined by the PATH environment setting (
5062 \series medium
5063 see 
5064 \series default
5065 section 
5066 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5067
5068 \end_inset
5069
5070 \InsetSpace ~
5071
5072 \series medium
5073 Install trouble-shooting for suggestions
5074 \series default
5075 ).
5076  Make sure that the sdcc program is in the bin folder, if not perhaps something
5077  did not install correctly.
5078 \newline
5079
5080 \newline
5081
5082 \series medium
5083 SDCC 
5084 \series default
5085 is commonly installed as described in section 
5086 \begin_inset Quotes sld
5087 \end_inset
5088
5089 Install and search paths
5090 \begin_inset Quotes srd
5091 \end_inset
5092
5093 .
5094 \newline
5095
5096 \newline
5097
5098 \series medium
5099 Make sure the compiler works on a very simple example.
5100  Type in the following test.c program using your favorite 
5101 \series default
5102 ASCII 
5103 \series medium
5104 editor:
5105 \end_layout
5106
5107 \begin_layout Verse
5108
5109 \family typewriter
5110 char test;
5111 \newline
5112
5113 \newline
5114 void main(void) {
5115 \newline
5116 \InsetSpace ~
5117 \InsetSpace ~
5118 \InsetSpace ~
5119 \InsetSpace ~
5120 test=0;
5121 \newline
5122 }
5123 \end_layout
5124
5125 \begin_layout Standard
5126
5127 \series medium
5128 Compile this using the following command: 
5129 \family sans
5130 \series bold
5131 "sdcc -c test.c".
5132
5133 \family default
5134 \series default
5135  
5136 \series medium
5137 If all goes well, the compiler will generate a test.asm and test.rel file.
5138  Congratulations, you've just compiled your first program with SDCC.
5139  We used the -c option to tell SDCC not to link the generated code, just
5140  to keep things simple for this step.
5141 \series default
5142
5143 \newline
5144
5145 \newline
5146
5147 \series medium
5148 The next step is to try it with the linker.
5149  Type in 
5150 \family sans
5151 \series bold
5152 "sdcc test.c
5153 \family default
5154 \series default
5155 "
5156 \series medium
5157 .
5158  If all goes well the compiler will link with the libraries and produce
5159  a test.ihx output file.
5160  If this step fails
5161 \series default
5162  
5163 \series medium
5164 (no test.ihx, and the linker generates warnings), then the problem is most
5165  likely that 
5166 \series default
5167 SDCC
5168 \series medium
5169  cannot find the 
5170 \series default
5171 /
5172 \series medium
5173 usr/local/share/sdcc/lib directory
5174 \series default
5175  
5176 \series medium
5177 (see 
5178 \series default
5179 section 
5180 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5181
5182 \end_inset
5183
5184 \InsetSpace ~
5185
5186 \series medium
5187 Install trouble-shooting for suggestions).
5188 \series default
5189
5190 \newline
5191
5192 \newline
5193
5194 \series medium
5195 The final test is to ensure 
5196 \series default
5197 SDCC
5198 \series medium
5199  can use the 
5200 \series default
5201 standard
5202 \series medium
5203  header files and libraries.
5204  Edit test.c and change it to the following:
5205 \end_layout
5206
5207 \begin_layout Verse
5208
5209 \family typewriter
5210 #include <string.h>
5211 \newline
5212
5213 \newline
5214 char str1[10];
5215 \newline
5216
5217 \newline
5218 void main(void) {
5219 \newline
5220 \InsetSpace ~
5221 \InsetSpace ~
5222 strcpy(str1, "testing");
5223 \newline
5224 }
5225 \end_layout
5226
5227 \begin_layout Standard
5228
5229 \series medium
5230 Compile this by typing 
5231 \family sans
5232 \series bold
5233 "sdcc test.c"
5234 \family default
5235 \series medium
5236 .
5237  This should generate a test.ihx output file, and it should give no warnings
5238  such as not finding the string.h file.
5239  If it cannot find the string.h file, then the problem is that 
5240 \series default
5241 SDCC
5242 \series medium
5243  cannot find the /usr/local/share/sdcc/include directory
5244 \series default
5245  
5246 \series medium
5247 (see the 
5248 \series default
5249 section 
5250 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5251
5252 \end_inset
5253
5254 \InsetSpace ~
5255
5256 \series medium
5257 Install trouble-shooting section for suggestions).
5258
5259 \series default
5260  Use option 
5261 \series bold
5262 -
5263 \begin_inset ERT
5264 status collapsed
5265
5266 \begin_layout Standard
5267
5268
5269 \backslash
5270 /
5271 \end_layout
5272
5273 \end_inset
5274
5275 -print-search-dirs
5276 \series default
5277
5278 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5279
5280 \end_inset
5281
5282  to find exactly where SDCC is looking for the include and lib files.
5283 \end_layout
5284
5285 \begin_layout Section
5286 Install Trouble-shooting
5287 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5288
5289 \end_inset
5290
5291
5292 \begin_inset LatexCommand \index{Install trouble-shooting}
5293
5294 \end_inset
5295
5296
5297 \end_layout
5298
5299 \begin_layout Subsection
5300 If SDCC does not build correctly
5301 \end_layout
5302
5303 \begin_layout Standard
5304 A thing to try is starting from scratch by unpacking the .tgz source package
5305  again in an empty directory.
5306  Configure it like:
5307 \newline
5308
5309 \newline
5310
5311 \family sans
5312 \series bold
5313 ./configure 2>&1 | tee configure.log
5314 \family default
5315 \series default
5316
5317 \newline
5318
5319 \newline
5320 and build it like:
5321 \newline
5322
5323 \newline
5324
5325 \family sans
5326 \series bold
5327 make 2>&1 | tee make.log
5328 \family default
5329 \series default
5330
5331 \newline
5332
5333 \newline
5334 If anything goes wrong, you can review the log files to locate the problem.
5335  Or a relevant part of this can be attached to an email that could be helpful
5336  when requesting help from the mailing list.
5337 \end_layout
5338
5339 \begin_layout Subsection
5340 What the 
5341 \begin_inset Quotes sld
5342 \end_inset
5343
5344 ./configure
5345 \begin_inset Quotes srd
5346 \end_inset
5347
5348  does
5349 \end_layout
5350
5351 \begin_layout Standard
5352 The 
5353 \begin_inset Quotes sld
5354 \end_inset
5355
5356 ./configure
5357 \begin_inset Quotes srd
5358 \end_inset
5359
5360  command is a script that analyzes your system and performs some configuration
5361  to ensure the source package compiles on your system.
5362  It will take a few minutes to run, and will compile a few tests to determine
5363  what compiler features are installed.
5364 \end_layout
5365
5366 \begin_layout Subsection
5367 What the 
5368 \begin_inset Quotes sld
5369 \end_inset
5370
5371 make
5372 \begin_inset Quotes srd
5373 \end_inset
5374
5375  does
5376 \end_layout
5377
5378 \begin_layout Standard
5379 This runs the GNU make tool, which automatically compiles all the source
5380  packages into the final installed binary executables.
5381 \end_layout
5382
5383 \begin_layout Subsection
5384 What the 
5385 \begin_inset Quotes sld
5386 \end_inset
5387
5388 make install
5389 \begin_inset Quotes erd
5390 \end_inset
5391
5392  command does.
5393 \end_layout
5394
5395 \begin_layout Standard
5396 This will install the compiler, other executables libraries and include
5397  files into the appropriate directories.
5398  See sections 
5399 \begin_inset LatexCommand \ref{sub:Install-paths}
5400
5401 \end_inset
5402
5403 ,\InsetSpace ~
5404
5405 \begin_inset LatexCommand \ref{sub:Search-Paths}
5406
5407 \end_inset
5408
5409 \InsetSpace ~
5410 about install and search paths.
5411 \newline
5412 On most systems you will need super-user privilege
5413 s to do this.
5414 \end_layout
5415
5416 \begin_layout Section
5417 Components of SDCC
5418 \end_layout
5419
5420 \begin_layout Standard
5421 SDCC is not just a compiler, but a collection of tools by various developers.
5422  These include linkers, assemblers, simulators and other components.
5423  Here is a summary of some of the components.
5424  Note that the included simulator and assembler have separate documentation
5425  which you can find in the source package in their respective directories.
5426  As SDCC grows to include support for other processors, other packages from
5427  various developers are included and may have their own sets of documentation.
5428 \newline
5429
5430 \newline
5431 You
5432  might want to look at the files which are installed in <installdir>.
5433  At the time of this writing, we find the following programs for gcc-builds:
5434 \newline
5435
5436  
5437 \newline
5438 In <installdir>/bin:
5439 \end_layout
5440
5441 \begin_layout Itemize
5442 sdcc - The compiler.
5443 \end_layout
5444
5445 \begin_layout Itemize
5446 sdcpp - The C preprocessor.
5447 \end_layout
5448
5449 \begin_layout Itemize
5450 asx8051 - The assembler for 8051 type processors.
5451 \end_layout
5452
5453 \begin_layout Itemize
5454 as-z80
5455 \series bold
5456
5457 \series default
5458 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5459 \end_layout
5460
5461 \begin_layout Itemize
5462 aslink -The linker for 8051 type processors.
5463 \end_layout
5464
5465 \begin_layout Itemize
5466 link-z80
5467 \series bold
5468
5469 \series default
5470 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5471 \end_layout
5472
5473 \begin_layout Itemize
5474 s51 - The ucSim 8051 simulator.
5475 \end_layout
5476
5477 \begin_layout Itemize
5478 sdcdb - The source debugger.
5479 \end_layout
5480
5481 \begin_layout Itemize
5482 packihx - A tool to pack (compress) Intel hex files.
5483 \end_layout
5484
5485 \begin_layout Standard
5486 In <installdir>/share/sdcc/include
5487 \end_layout
5488
5489 \begin_layout Itemize
5490 the include files
5491 \end_layout
5492
5493 \begin_layout Standard
5494 In <installdir>/share/sdcc/lib
5495 \end_layout
5496
5497 \begin_layout Itemize
5498 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5499  relocatables.
5500 \end_layout
5501
5502 \begin_layout Standard
5503 In <installdir>/share/sdcc/doc
5504 \end_layout
5505
5506 \begin_layout Itemize
5507 the documentation
5508 \end_layout
5509
5510 \begin_layout Standard
5511 As development for other processors proceeds, this list will expand to include
5512  executables to support processors like AVR, PIC, etc.
5513 \end_layout
5514
5515 \begin_layout Subsection
5516 sdcc - The Compiler
5517 \end_layout
5518
5519 \begin_layout Standard
5520 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5521  the assembler and linkage editor.
5522 \end_layout
5523
5524 \begin_layout Subsection
5525 sdcpp - The C-Preprocessor
5526 \end_layout
5527
5528 \begin_layout Standard
5529 The preprocessor
5530 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5531
5532 \end_inset
5533
5534  is a modified version of the GNU cpp
5535 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5536
5537 \end_inset
5538
5539  preprocessor 
5540 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5541
5542 \end_inset
5543
5544 .
5545  The C preprocessor is used to pull in #include sources, process #ifdef
5546  statements, #defines and so on.
5547 \end_layout
5548
5549 \begin_layout Subsection
5550 as
5551 \emph on
5552 xxxx
5553 \emph default
5554 , aslink, link-
5555 \emph on
5556 xxx
5557 \emph default
5558  - The Assemblers and Linkage Editors
5559 \end_layout
5560
5561 \begin_layout Standard
5562 This is retargettable assembler & linkage editor, it was developed by Alan
5563  Baldwin.
5564  John Hartman created the version for 8051, and I (Sandeep) have made some
5565  enhancements and bug fixes for it to work properly with SDCC.
5566 \end_layout
5567
5568 \begin_layout Subsection
5569 s51 - The Simulator
5570 \end_layout
5571
5572 \begin_layout Standard
5573 S51
5574 \begin_inset LatexCommand \index{s51}
5575
5576 \end_inset
5577
5578  is a free open source simulator developed by Daniel Drotos.
5579  The simulator is built as part of the build process.
5580  For more information visit Daniel's web site at: 
5581 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5582
5583 \end_inset
5584
5585 .
5586  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5587  XA51 family.
5588 \end_layout
5589
5590 \begin_layout Subsection
5591 sdcdb - Source Level Debugger
5592 \end_layout
5593
5594 \begin_layout Standard
5595 SDCDB
5596 \begin_inset LatexCommand \index{SDCDB (debugger)}
5597
5598 \end_inset
5599
5600  is the companion source level debugger.
5601  More about SDCDB in section 
5602 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5603
5604 \end_inset
5605
5606 .
5607  The current version of the debugger uses Daniel's Simulator S51
5608 \begin_inset LatexCommand \index{s51}
5609
5610 \end_inset
5611
5612 , but can be easily changed to use other simulators.
5613 \end_layout
5614
5615 \begin_layout Chapter
5616 Using SDCC
5617 \end_layout
5618
5619 \begin_layout Section
5620 Compiling
5621 \end_layout
5622
5623 \begin_layout Subsection
5624 Single Source File Projects
5625 \end_layout
5626
5627 \begin_layout Standard
5628 For single source file 8051 projects the process is very simple.
5629  Compile your programs with the following command 
5630 \family sans
5631 \series bold
5632 "sdcc sourcefile.c".
5633
5634 \family default
5635 \series default
5636  This will compile, assemble and link your source file.
5637  Output files are as follows:
5638 \end_layout
5639
5640 \begin_layout Itemize
5641 sourcefile.asm
5642 \begin_inset LatexCommand \index{<file>.asm}
5643
5644 \end_inset
5645
5646  - Assembler source
5647 \begin_inset LatexCommand \index{Assembler source}
5648
5649 \end_inset
5650
5651  file created by the compiler
5652 \end_layout
5653
5654 \begin_layout Itemize
5655 sourcefile.lst
5656 \begin_inset LatexCommand \index{<file>.lst}
5657
5658 \end_inset
5659
5660  - Assembler listing
5661 \begin_inset LatexCommand \index{Assembler listing}
5662
5663 \end_inset
5664
5665  file created by the Assembler
5666 \end_layout
5667
5668 \begin_layout Itemize
5669 sourcefile.rst
5670 \begin_inset LatexCommand \index{<file>.rst}
5671
5672 \end_inset
5673
5674  - Assembler listing
5675 \begin_inset LatexCommand \index{Assembler listing}
5676
5677 \end_inset
5678
5679  file updated with linkedit information, created by linkage editor
5680 \end_layout
5681
5682 \begin_layout Itemize
5683 sourcefile.sym
5684 \begin_inset LatexCommand \index{<file>.sym}
5685
5686 \end_inset
5687
5688  - symbol listing
5689 \begin_inset LatexCommand \index{Symbol listing}
5690
5691 \end_inset
5692
5693  for the sourcefile, created by the assembler
5694 \end_layout
5695
5696 \begin_layout Itemize
5697 sourcefile.rel
5698 \begin_inset LatexCommand \index{<file>.rel}
5699
5700 \end_inset
5701
5702  or sourcefile.o
5703 \begin_inset LatexCommand \index{<file>.o}
5704
5705 \end_inset
5706
5707  - Object file
5708 \begin_inset LatexCommand \index{Object file}
5709
5710 \end_inset
5711
5712  created by the assembler, input to Linkage editor
5713 \end_layout
5714
5715 \begin_layout Itemize
5716 sourcefile.map
5717 \begin_inset LatexCommand \index{<file>.map}
5718
5719 \end_inset
5720
5721  - The memory map
5722 \begin_inset LatexCommand \index{Memory map}
5723
5724 \end_inset
5725
5726  for the load module, created by the Linker
5727 \end_layout
5728
5729 \begin_layout Itemize
5730 sourcefile.mem
5731 \begin_inset LatexCommand \index{<file>.mem}
5732
5733 \end_inset
5734
5735  - A file with a summary of the memory usage
5736 \end_layout
5737
5738 \begin_layout Itemize
5739 sourcefile.ihx
5740 \begin_inset LatexCommand \index{<file>.ihx}
5741
5742 \end_inset
5743
5744  - The load module in Intel hex format
5745 \begin_inset LatexCommand \index{Intel hex format}
5746
5747 \end_inset
5748
5749  (you can select the Motorola S19 format
5750 \begin_inset LatexCommand \index{Motorola S19 format}
5751
5752 \end_inset
5753
5754  with -
5755 \begin_inset ERT
5756 status collapsed
5757
5758 \begin_layout Standard
5759
5760
5761 \backslash
5762 /
5763 \end_layout
5764
5765 \end_inset
5766
5767 -out-fmt-s19
5768 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5769
5770 \end_inset
5771
5772 .
5773  If you need another format you might want to use 
5774 \family sans
5775 \shape italic
5776 objdump
5777 \family default
5778 \shape default
5779
5780 \begin_inset LatexCommand \index{objdump (tool)}
5781
5782 \end_inset
5783
5784  or
5785 \family sans
5786 \shape italic
5787  srecord
5788 \family default
5789 \shape default
5790
5791 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5792
5793 \end_inset
5794
5795
5796 \begin_inset Note Note
5797 status collapsed
5798
5799 \begin_layout Standard
5800 hyperlinks needed
5801 \end_layout
5802
5803 \end_inset
5804
5805  - see also section 
5806 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5807
5808 \end_inset
5809
5810 ).
5811  Both formats are documented in the documentation of srecord
5812 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5813
5814 \end_inset
5815
5816
5817 \end_layout
5818
5819 \begin_layout Itemize
5820 sourcefile.adb
5821 \begin_inset LatexCommand \index{<file>.adb}
5822
5823 \end_inset
5824
5825  - An intermediate file containing debug information needed to create the
5826  .cdb file (with -
5827 \begin_inset ERT
5828 status collapsed
5829
5830 \begin_layout Standard
5831
5832
5833 \backslash
5834 /
5835 \end_layout
5836
5837 \end_inset
5838
5839 -debug
5840 \begin_inset LatexCommand \index{-\/-debug}
5841
5842 \end_inset
5843
5844
5845 \end_layout
5846
5847 \begin_layout Itemize
5848 sourcefile.cdb
5849 \begin_inset LatexCommand \index{<file>.cdb}
5850
5851 \end_inset
5852
5853  - An optional file (with -
5854 \begin_inset ERT
5855 status collapsed
5856
5857 \begin_layout Standard
5858
5859
5860 \backslash
5861 /
5862 \end_layout
5863
5864 \end_inset
5865
5866 -debug) containing debug information.
5867  The format is documented in cdbfileformat.pdf
5868 \end_layout
5869
5870 \begin_layout Itemize
5871 sourcefile.
5872  - (no extension)
5873 \begin_inset LatexCommand \index{<file> (no extension)}
5874
5875 \end_inset
5876
5877  An optional AOMF or AOMF51
5878 \begin_inset LatexCommand \index{AOMF, AOMF51}
5879
5880 \end_inset
5881
5882  
5883 \begin_inset LatexCommand \label{OMF file}
5884
5885 \end_inset
5886
5887 file containing debug information (generated with option -
5888 \begin_inset ERT
5889 status collapsed
5890
5891 \begin_layout Standard
5892
5893
5894 \backslash
5895 /
5896 \end_layout
5897
5898 \end_inset
5899
5900 -debug).
5901  The (Intel)
5902 \emph on
5903  a
5904 \emph default
5905 bsolute 
5906 \emph on
5907 o
5908 \emph default
5909 bject 
5910 \emph on
5911 m
5912 \emph default
5913 odule 
5914 \emph on
5915 f
5916 \emph default
5917 ormat is a subformat of the OMF51 format and is commonly used by third party
5918  tools (debuggers
5919 \begin_inset LatexCommand \index{Debugger}
5920
5921 \end_inset
5922
5923 , simulators, emulators).
5924 \end_layout
5925
5926 \begin_layout Itemize
5927 sourcefile.dump*
5928 \begin_inset LatexCommand \index{<file>.dump*}
5929
5930 \end_inset
5931
5932  - Dump file to debug the compiler it self (generated with option -
5933 \begin_inset ERT
5934 status collapsed
5935
5936 \begin_layout Standard
5937
5938
5939 \backslash
5940 /
5941 \end_layout
5942
5943 \end_inset
5944
5945 -dumpall) (see section 
5946 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5947
5948 \end_inset
5949
5950 \InsetSpace ~
5951  and section 
5952 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5953
5954 \end_inset
5955
5956 \InsetSpace ~
5957
5958 \begin_inset Quotes sld
5959 \end_inset
5960
5961 Anatomy of the compiler
5962 \begin_inset Quotes srd
5963 \end_inset
5964
5965 ).
5966 \end_layout
5967
5968 \begin_layout Subsection
5969 Postprocessing the Intel Hex
5970 \begin_inset LatexCommand \index{Intel hex format}
5971
5972 \end_inset
5973
5974  file
5975 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5976
5977 \end_inset
5978
5979
5980 \end_layout
5981
5982 \begin_layout Standard
5983 In most cases this won't be needed but the Intel Hex file
5984 \begin_inset LatexCommand \index{<file>.ihx}
5985
5986 \end_inset
5987
5988  which is generated by SDCC might include lines of varying length and the
5989  addresses within the file are not guaranteed to be strictly ascending.
5990  If your toolchain or a bootloader does not like this you can use the tool
5991  
5992 \family typewriter
5993 packihx
5994 \family default
5995
5996 \begin_inset LatexCommand \index{packihx (tool)}
5997
5998 \end_inset
5999
6000  which is part of the SDCC distribution: 
6001 \newline
6002
6003 \newline
6004
6005 \family sans
6006 \series bold
6007  packihx sourcefile.ihx >sourcefile.hex
6008 \family default
6009 \series default
6010
6011 \newline
6012
6013 \newline
6014 The separately available
6015 \emph on
6016  srecord
6017 \emph default
6018
6019 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6020
6021 \end_inset
6022
6023  package additionally allows to set undefined locations to a predefined
6024  value, to insert checksums
6025 \begin_inset LatexCommand \index{checksum}
6026
6027 \end_inset
6028
6029  of various flavours (crc, add, xor) and to perform other manipulations
6030  (convert, split, crop, offset, ...).
6031  
6032 \newline
6033
6034 \newline
6035
6036 \family sans
6037 \series bold
6038 srec_cat\InsetSpace ~
6039 \InsetSpace ~
6040 sourcefile.ihx -intel\InsetSpace ~
6041 \InsetSpace ~
6042 -o sourcefile.hex -intel
6043 \newline
6044
6045 \newline
6046
6047 \family default
6048 \series default
6049 An example for a more complex command line
6050 \begin_inset Foot
6051 status open
6052
6053 \begin_layout Standard
6054 the command backfills
6055 \begin_inset LatexCommand \index{backfill unused memory}
6056
6057 \end_inset
6058
6059  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6060  block is zero.
6061  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6062  will be interpreted as an 
6063 \family typewriter
6064 lcall
6065 \family default
6066  to address 
6067 \family typewriter
6068 0x1212
6069 \family default
6070  (where an emergency routine could sit).
6071 \end_layout
6072
6073 \end_inset
6074
6075  could look like:
6076 \newline
6077
6078 \newline
6079
6080 \family sans
6081 \series bold
6082 \size footnotesize
6083 srec_cat\InsetSpace ~
6084 sourcefile.ihx -intel\InsetSpace ~
6085 \InsetSpace ~
6086 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6087 -little-endian-checksum-nega
6088 tive 0xfffe 0x02 0x02\InsetSpace ~
6089 \InsetSpace ~
6090 -o sourcefile.hex -intel
6091 \size default
6092
6093 \newline
6094
6095 \newline
6096
6097 \family default
6098 \series default
6099 The srecord package is available at 
6100 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6101
6102 \end_inset
6103
6104  .
6105 \end_layout
6106
6107 \begin_layout Subsection
6108 Projects with Multiple Source Files
6109 \end_layout
6110
6111 \begin_layout Standard
6112 SDCC can compile only ONE file at a time.
6113  Let us for example assume that you have a project containing the following
6114  files:
6115 \newline
6116
6117 \newline
6118 foo1.c (contains some functions)
6119 \newline
6120 foo2.c (contains some more functions)
6121 \newline
6122 foomai
6123 n.c (contains more functions and the function main)
6124 \newline
6125
6126 \size footnotesize
6127
6128 \newline
6129
6130 \size default
6131 The first two files will need to be compiled separately with the commands:
6132 \size footnotesize
6133  
6134 \size default
6135
6136 \newline
6137
6138 \newline
6139
6140 \family sans
6141 \series bold
6142 sdcc\InsetSpace ~
6143 -c\InsetSpace ~
6144 foo1.c
6145 \family default
6146 \series default
6147 \size footnotesize
6148
6149 \newline
6150
6151 \family sans
6152 \series bold
6153 \size default
6154 sdcc\InsetSpace ~
6155 -c\InsetSpace ~
6156 foo2.c
6157 \family default
6158 \series default
6159
6160 \newline
6161
6162 \newline
6163 Then compile the source file containing the 
6164 \emph on
6165 main()
6166 \emph default
6167  function and link
6168 \begin_inset LatexCommand \index{Linker}
6169
6170 \end_inset
6171
6172  the files together with the following command: 
6173 \newline
6174
6175 \newline
6176
6177 \family sans
6178 \series bold
6179 sdcc\InsetSpace ~
6180 foomain.c\InsetSpace ~
6181 foo1.rel\InsetSpace ~
6182 foo2.rel
6183 \family default
6184 \series default
6185
6186 \begin_inset LatexCommand \index{<file>.rel}
6187
6188 \end_inset
6189
6190
6191 \newline
6192
6193 \newline
6194 Alternatively, 
6195 \emph on
6196 foomain.c 
6197 \emph default
6198 can be separately compiled as well: 
6199 \family sans
6200 \series bold
6201
6202 \newline
6203
6204 \newline
6205 sdcc\InsetSpace ~
6206 -c\InsetSpace ~
6207 foomain.c
6208 \newline
6209 sdcc foomain.rel foo1.rel foo2.rel
6210 \newline
6211
6212 \newline
6213
6214 \family default
6215 \series default
6216 The file containing the 
6217 \emph on
6218 main()
6219 \emph default
6220  function
6221 \emph on
6222  
6223 \emph default
6224 \noun on
6225 must
6226 \noun default
6227  be the 
6228 \noun on
6229 first
6230 \noun default
6231  file specified in the command line, since the linkage editor processes
6232  file in the order they are presented to it.
6233  The linker is invoked from SDCC using a script file with extension .lnk
6234 \begin_inset LatexCommand \index{<file>.lnk}
6235
6236 \end_inset
6237
6238 .
6239  You can view this file to troubleshoot linking problems such as those arising
6240  from missing libraries.
6241 \end_layout
6242
6243 \begin_layout Subsection
6244 Projects with Additional Libraries
6245 \begin_inset LatexCommand \index{Libraries}
6246
6247 \end_inset
6248
6249
6250 \end_layout
6251
6252 \begin_layout Standard
6253 Some reusable routines may be compiled into a library, see the documentation
6254  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6255  for how to create a 
6256 \emph on
6257 .lib
6258 \begin_inset LatexCommand \index{<file>.lib}
6259
6260 \end_inset
6261
6262
6263 \emph default
6264  library file.
6265  Libraries created in this manner can be included in the command line.
6266  Make sure you include the -L <library-path> option to tell the linker where
6267  to look for these files if they are not in the current directory.
6268  Here is an example, assuming you have the source file 
6269 \emph on
6270 foomain.c
6271 \emph default
6272  and a library
6273 \emph on
6274  foolib.lib
6275 \emph default
6276  in the directory 
6277 \emph on
6278 mylib
6279 \emph default
6280  (if that is not the same as your current project):
6281 \newline
6282
6283 \newline
6284
6285 \family sans
6286 \series bold
6287 sdcc foomain.c foolib.lib -L mylib
6288 \newline
6289
6290 \newline
6291
6292 \family default
6293 \series default
6294 Note here that
6295 \emph on
6296  mylib
6297 \emph default
6298  must be an absolute path name.
6299 \newline
6300
6301 \newline
6302 The most efficient way to use libraries is
6303  to keep separate modules in separate source files.
6304  The lib file now should name all the modules.rel
6305 \begin_inset LatexCommand \index{<file>.rel}
6306
6307 \end_inset
6308
6309  files.
6310  For an example see the standard library file 
6311 \emph on
6312 libsdcc.lib
6313 \emph default
6314  in the directory <installdir>/share/lib/small.
6315 \end_layout
6316
6317 \begin_layout Subsection
6318 Using sdcclib to Create and Manage Libraries
6319 \begin_inset LatexCommand \index{sdcclib}
6320
6321 \end_inset
6322
6323
6324 \end_layout
6325
6326 \begin_layout Standard
6327 Alternatively, instead of having a .rel file for each entry on the library
6328  file as described in the preceding section, sdcclib can be used to embed
6329  all the modules belonging to such library in the library file itself.
6330  This results in a larger library file, but it greatly reduces the number
6331  of disk files accessed by the linker.
6332   Additionally, the packed library file contains an index of all include
6333  modules and symbols that significantly speeds up the linking process.
6334  To display a list of options supported by sdcclib type:
6335 \newline
6336
6337 \end_layout
6338
6339 \begin_layout Standard
6340
6341 \family sans
6342 \series bold
6343 sdcclib -?
6344 \begin_inset LatexCommand \index{sdcclib}
6345
6346 \end_inset
6347
6348
6349 \newline
6350
6351 \newline
6352
6353 \family default
6354 \series default
6355 To create a new library file, start by compiling all the required modules.
6356  For example:
6357 \newline
6358
6359 \end_layout
6360
6361 \begin_layout Standard
6362
6363 \family sans
6364 \series bold
6365 sdcc -c _divsint.c
6366 \end_layout
6367
6368 \begin_layout Standard
6369
6370 \family sans
6371 \series bold
6372 sdcc -c _divuint.c
6373 \end_layout
6374
6375 \begin_layout Standard
6376
6377 \family sans
6378 \series bold
6379 sdcc -c _modsint.c
6380 \end_layout
6381
6382 \begin_layout Standard
6383
6384 \family sans
6385 \series bold
6386 sdcc -c _moduint.c
6387 \end_layout
6388
6389 \begin_layout Standard
6390
6391 \family sans
6392 \series bold
6393 sdcc -c _mulint.c
6394 \newline
6395
6396 \end_layout
6397
6398 \begin_layout Standard
6399 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6400  and _mulint.rel.
6401  The next step is to add the .rel files to the library file:
6402 \newline
6403
6404 \end_layout
6405
6406 \begin_layout Standard
6407
6408 \family sans
6409 \series bold
6410 sdcclib libint.lib _divsint.rel
6411 \family default
6412
6413 \begin_inset LatexCommand \index{sdcclib}
6414
6415 \end_inset
6416
6417
6418 \end_layout
6419
6420 \begin_layout Standard
6421
6422 \family sans
6423 \series bold
6424 sdcclib libint.lib _divuint.rel
6425 \end_layout
6426
6427 \begin_layout Standard
6428
6429 \family sans
6430 \series bold
6431 sdcclib libint.lib _modsint.rel
6432 \end_layout
6433
6434 \begin_layout Standard
6435
6436 \family sans
6437 \series bold
6438 sdcclib libint.lib _moduint.rel
6439 \end_layout
6440
6441 \begin_layout Standard
6442
6443 \family sans
6444 \series bold
6445 sdcclib libint.lib _mulint.rel
6446 \family default
6447 \series default
6448
6449 \newline
6450
6451 \end_layout
6452
6453 \begin_layout Standard
6454 Or, if you preffer:
6455 \family sans
6456 \series bold
6457
6458 \newline
6459
6460 \end_layout
6461
6462 \begin_layout Standard
6463
6464 \family sans
6465 \series bold
6466 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6467 \family default
6468 \series default
6469
6470 \newline
6471
6472 \end_layout
6473
6474 \begin_layout Standard
6475 If the file already exists in the library, it will be replaced.
6476  If a list of .rel files is available, you can tell sdcclib to add those
6477  files to a library.
6478  For example, if the file 'myliblist.txt' contains
6479 \family sans
6480 \series bold
6481
6482 \newline
6483
6484 \end_layout
6485
6486 \begin_layout Standard
6487
6488 \family sans
6489 \series bold
6490 _divsint.rel
6491 \end_layout
6492
6493 \begin_layout Standard
6494
6495 \family sans
6496 \series bold
6497 _divuint.rel
6498 \end_layout
6499
6500 \begin_layout Standard
6501
6502 \family sans
6503 \series bold
6504 _modsint.rel
6505 \end_layout
6506
6507 \begin_layout Standard
6508
6509 \family sans
6510 \series bold
6511 _moduint.rel
6512 \end_layout
6513
6514 \begin_layout Standard
6515
6516 \family sans
6517 \series bold
6518 _mulint.rel
6519 \family default
6520 \series default
6521
6522 \newline
6523
6524 \end_layout
6525
6526 \begin_layout Standard
6527 Use
6528 \family sans
6529 \series bold
6530
6531 \newline
6532
6533 \end_layout
6534
6535 \begin_layout Standard
6536
6537 \family sans
6538 \series bold
6539 sdcclib -l libint.lib myliblist.txt
6540 \family default
6541 \series default
6542
6543 \newline
6544
6545 \end_layout
6546
6547 \begin_layout Standard
6548 Additionally, you can instruct sdcclib to compiles the files before adding
6549  them to the library.
6550  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6551  For example:
6552 \family sans
6553 \series bold
6554
6555 \newline
6556
6557 \end_layout
6558
6559 \begin_layout Standard
6560
6561 \family sans
6562 \series bold
6563 set SDCCLIB_CC=sdcc -c
6564 \end_layout
6565
6566 \begin_layout Standard
6567
6568 \family sans
6569 \series bold
6570 sdcclib -l libint.lib myliblist.txt
6571 \family default
6572 \series default
6573
6574 \newline
6575
6576 \end_layout
6577
6578 \begin_layout Standard
6579 To see what modules and symbols are included in the library, options -s
6580  and -m are available.
6581  For example:
6582 \newline
6583
6584 \newline
6585
6586 \family sans
6587 \series bold
6588 sdcclib -s libint.lib
6589 \family default
6590
6591 \begin_inset LatexCommand \index{sdcclib}
6592
6593 \end_inset
6594
6595
6596 \newline
6597
6598 \family typewriter
6599 \series default
6600 _divsint.rel:
6601 \end_layout
6602
6603 \begin_layout Standard
6604
6605 \family typewriter
6606 __divsint_a_1_1
6607 \end_layout
6608
6609 \begin_layout Standard
6610
6611 \family typewriter
6612 __divsint_PARM_2
6613 \end_layout
6614
6615 \begin_layout Standard
6616
6617 \family typewriter
6618 __divsint
6619 \newline
6620 _divuint.rel:
6621 \end_layout
6622
6623 \begin_layout Standard
6624
6625 \family typewriter
6626 __divuint_a_1_1
6627 \end_layout
6628
6629 \begin_layout Standard
6630
6631 \family typewriter
6632 __divuint_PARM_2
6633 \end_layout
6634
6635 \begin_layout Standard
6636
6637 \family typewriter
6638 __divuint_reste_1_1
6639 \end_layout
6640
6641 \begin_layout Standard
6642
6643 \family typewriter
6644 __divuint_count_1_1
6645 \end_layout
6646
6647 \begin_layout Standard
6648
6649 \family typewriter
6650 __divuint
6651 \newline
6652 _modsint.rel:
6653 \end_layout
6654
6655 \begin_layout Standard
6656
6657 \family typewriter
6658 __modsint_a_1_1
6659 \end_layout
6660
6661 \begin_layout Standard
6662
6663 \family typewriter
6664 __modsint_PARM_2
6665 \end_layout
6666
6667 \begin_layout Standard
6668
6669 \family typewriter
6670 __modsint
6671 \newline
6672 _moduint.rel:
6673 \end_layout
6674
6675 \begin_layout Standard
6676
6677 \family typewriter
6678 __moduint_a_1_1
6679 \end_layout
6680
6681 \begin_layout Standard
6682
6683 \family typewriter
6684 __moduint_PARM_2
6685 \end_layout
6686
6687 \begin_layout Standard
6688
6689 \family typewriter
6690 __moduint_count_1_1
6691 \end_layout
6692
6693 \begin_layout Standard
6694
6695 \family typewriter
6696 __moduint
6697 \newline
6698 _mulint.rel:
6699 \end_layout
6700
6701 \begin_layout Standard
6702
6703 \family typewriter
6704 __mulint_PARM_2
6705 \end_layout
6706
6707 \begin_layout Standard
6708
6709 \family typewriter
6710 __mulint
6711 \family default
6712 \series bold
6713
6714 \newline
6715
6716 \end_layout
6717
6718 \begin_layout Standard
6719 If the source files are compiled using -
6720 \begin_inset ERT
6721 status collapsed
6722
6723 \begin_layout Standard
6724
6725
6726 \backslash
6727 /
6728 \end_layout
6729
6730 \end_inset
6731
6732 -debug
6733 \begin_inset LatexCommand \index{-\/-debug}
6734
6735 \end_inset
6736
6737 , the corresponding debug information file .adb will be include in the library
6738  file as well.
6739  The library files created with sdcclib are plain text files, so they can
6740  be viewed with a text editor.
6741  It is not recomended to modify a library file created with sdcclib using
6742  a text editor, as there are file indexes numbers located accross the file
6743  used by the linker to quickly locate the required module to link.
6744  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6745  it can be safely deleted, since all the information required for linking
6746  is embedded in the library file itself.
6747  Library files created using sdcclib are used as described in the preceding
6748  sections.
6749 \begin_inset VSpace bigskip
6750 \end_inset
6751
6752
6753 \end_layout
6754
6755 \begin_layout Section
6756 Command Line Options
6757 \begin_inset LatexCommand \index{Command Line Options}
6758
6759 \end_inset
6760
6761
6762 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6763
6764 \end_inset
6765
6766
6767 \end_layout
6768
6769 \begin_layout Subsection
6770 Processor Selection Options
6771 \begin_inset LatexCommand \index{Options processor selection}
6772
6773 \end_inset
6774
6775
6776 \begin_inset LatexCommand \index{Processor selection options}
6777
6778 \end_inset
6779
6780
6781 \end_layout
6782
6783 \begin_layout List
6784 \labelwidthstring 00.00.0000
6785
6786 \series bold
6787 -mmcs51
6788 \begin_inset LatexCommand \index{-mmcs51}
6789
6790 \end_inset
6791
6792
6793 \series default
6794  Generate code for the Intel MCS51
6795 \begin_inset LatexCommand \index{MCS51}
6796
6797 \end_inset
6798
6799  family of processors.
6800  This is the default processor target.
6801 \end_layout
6802
6803 \begin_layout List
6804 \labelwidthstring 00.00.0000
6805
6806 \series bold
6807 -mds390
6808 \begin_inset LatexCommand \index{-mds390}
6809
6810 \end_inset
6811
6812
6813 \series default
6814  Generate code for the Dallas DS80C390
6815 \begin_inset LatexCommand \index{DS80C390}
6816
6817 \end_inset
6818
6819  processor.
6820 \end_layout
6821
6822 \begin_layout List
6823 \labelwidthstring 00.00.0000
6824
6825 \series bold
6826 -mds400
6827 \begin_inset LatexCommand \index{-mds400}
6828
6829 \end_inset
6830
6831
6832 \series default
6833  Generate code for the Dallas DS80C400
6834 \begin_inset LatexCommand \index{DS80C400}
6835
6836 \end_inset
6837
6838  processor.
6839 \end_layout
6840
6841 \begin_layout List
6842 \labelwidthstring 00.00.0000
6843
6844 \series bold
6845 -mhc08
6846 \begin_inset LatexCommand \index{-mhc08}
6847
6848 \end_inset
6849
6850
6851 \series default
6852  Generate code for the Freescale/Motorola HC08
6853 \begin_inset LatexCommand \index{HC08}
6854
6855 \end_inset
6856
6857  family of processors.
6858 \end_layout
6859
6860 \begin_layout List
6861 \labelwidthstring 00.00.0000
6862
6863 \series bold
6864 -mz80
6865 \begin_inset LatexCommand \index{-mz80}
6866
6867 \end_inset
6868
6869
6870 \series default
6871  Generate code for the Zilog Z80
6872 \begin_inset LatexCommand \index{Z80}
6873
6874 \end_inset
6875
6876  family of processors.
6877 \end_layout
6878
6879 \begin_layout List
6880 \labelwidthstring 00.00.0000
6881
6882 \series bold
6883 -mgbz80
6884 \begin_inset LatexCommand \index{-mgbz80}
6885
6886 \end_inset
6887
6888
6889 \series default
6890  Generate code for the GameBoy Z80
6891 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6892
6893 \end_inset
6894
6895  processor (Not actively maintained).
6896 \end_layout
6897
6898 \begin_layout List
6899 \labelwidthstring 00.00.0000
6900
6901 \series bold
6902 -mavr
6903 \begin_inset LatexCommand \index{-mavr}
6904
6905 \end_inset
6906
6907
6908 \series default
6909  Generate code for the Atmel AVR
6910 \begin_inset LatexCommand \index{AVR}
6911
6912 \end_inset
6913
6914  processor (Not maintained, not complete).
6915  AVR users should probably have a look at winavr 
6916 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6917
6918 \end_inset
6919
6920  or 
6921 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6922
6923 \end_inset
6924
6925 , which is based on AVR-port of the gcc compiler.
6926 \end_layout
6927
6928 \begin_layout Standard
6929 \begin_inset Note Note
6930 status collapsed
6931
6932 \begin_layout Standard
6933 I think it is fair to direct users there for now.
6934  Open source is also about avoiding unnecessary work .
6935  But I didn't find the 'official' link.
6936 \end_layout
6937
6938 \end_inset
6939
6940
6941 \end_layout
6942
6943 \begin_layout List
6944 \labelwidthstring 00.00.0000
6945
6946 \series bold
6947 -mpic14
6948 \begin_inset LatexCommand \index{-mpic14}
6949
6950 \end_inset
6951
6952
6953 \series default
6954  Generate code for the Microchip PIC 14
6955 \begin_inset LatexCommand \index{PIC14}
6956
6957 \end_inset
6958
6959 -bit processors (p16f84 and variants.
6960  In development, not complete).
6961 \end_layout
6962
6963 \begin_layout Standard
6964 \begin_inset Note Note
6965 status collapsed
6966
6967 \begin_layout Standard
6968 p16f627 p16f628 p16f84 p16f873 p16f877?
6969 \end_layout
6970
6971 \end_inset
6972
6973
6974 \end_layout
6975
6976 \begin_layout List
6977 \labelwidthstring 00.00.0000
6978
6979 \series bold
6980 -mpic16
6981 \begin_inset LatexCommand \index{-mpic16}
6982
6983 \end_inset
6984
6985
6986 \series default
6987  Generate code for the Microchip PIC 16
6988 \begin_inset LatexCommand \index{PIC16}
6989
6990 \end_inset
6991
6992 -bit processors (p18f452 and variants.
6993  In development, not complete).
6994 \end_layout
6995
6996 \begin_layout List
6997 \labelwidthstring 00.00.0000
6998
6999 \series bold
7000 -mtlcs900h
7001 \series default
7002  Generate code for the Toshiba TLCS-900H
7003 \begin_inset LatexCommand \index{TLCS-900H}
7004
7005 \end_inset
7006
7007  processor (Not maintained, not complete).
7008 \end_layout
7009
7010 \begin_layout List
7011 \labelwidthstring 00.00.0000
7012
7013 \series bold
7014 -mxa51
7015 \begin_inset LatexCommand \index{-mxa51}
7016
7017 \end_inset
7018
7019
7020 \series default
7021  Generate code for the Phillips XA51
7022 \begin_inset LatexCommand \index{XA51}
7023
7024 \end_inset
7025
7026  processor (Not maintained, not complete).
7027 \end_layout
7028
7029 \begin_layout Standard
7030 \begin_inset VSpace bigskip
7031 \end_inset
7032
7033
7034 \end_layout
7035
7036 \begin_layout Subsection
7037 Preprocessor Options
7038 \begin_inset LatexCommand \index{Options preprocessor}
7039
7040 \end_inset
7041
7042
7043 \begin_inset LatexCommand \index{Preprocessor options}
7044
7045 \end_inset
7046
7047
7048 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7049
7050 \end_inset
7051
7052
7053 \end_layout
7054
7055 \begin_layout List
7056 \labelwidthstring 00.00.0000
7057
7058 \series bold
7059 -I<path>
7060 \begin_inset LatexCommand \index{-I<path>}
7061
7062 \end_inset
7063
7064
7065 \series default
7066  The additional location where the preprocessor will look for <..h> or 
7067 \begin_inset Quotes eld
7068 \end_inset
7069
7070 ..h
7071 \begin_inset Quotes erd
7072 \end_inset
7073
7074  files.
7075 \end_layout
7076
7077 \begin_layout List
7078 \labelwidthstring 00.00.0000
7079
7080 \series bold
7081 -D<macro[=value]>
7082 \begin_inset LatexCommand \index{-D<macro[=value]>}
7083
7084 \end_inset
7085
7086
7087 \series default
7088  Command line definition of macros.
7089  Passed to the preprocessor.
7090 \end_layout
7091
7092 \begin_layout List
7093 \labelwidthstring 00.00.0000
7094
7095 \series bold
7096 -M
7097 \begin_inset LatexCommand \index{-M}
7098
7099 \end_inset
7100
7101
7102 \series default
7103  Tell the preprocessor to output a rule suitable for make describing the
7104  dependencies of each object file.
7105  For each source file, the preprocessor outputs one make-rule whose target
7106  is the object file name for that source file and whose dependencies are
7107  all the files `#include'd in it.
7108  This rule may be a single line or may be continued with `
7109 \backslash
7110 '-newline if it is long.
7111  The list of rules is printed on standard output instead of the preprocessed
7112  C program.
7113  `-M' implies `-E
7114 \begin_inset LatexCommand \index{-E}
7115
7116 \end_inset
7117
7118 '.
7119 \end_layout
7120
7121 \begin_layout List
7122 \labelwidthstring 00.00.0000
7123
7124 \series bold
7125 -C
7126 \begin_inset LatexCommand \index{-C}
7127
7128 \end_inset
7129
7130
7131 \series default
7132  Tell the preprocessor not to discard comments.
7133  Used with the `-E' option.
7134 \end_layout
7135
7136 \begin_layout List
7137 \labelwidthstring 00.00.0000
7138
7139 \series bold
7140 -MM
7141 \begin_inset LatexCommand \index{-MM}
7142
7143 \end_inset
7144
7145
7146 \size large
7147 \bar under
7148  
7149 \series default
7150 \size default
7151 \bar default
7152 Like `-M' but the output mentions only the user header files included with
7153  `#include 
7154 \begin_inset Quotes eld
7155 \end_inset
7156
7157 file"'.
7158  System header files included with `#include <file>' are omitted.
7159 \end_layout
7160
7161 \begin_layout List
7162 \labelwidthstring 00.00.0000
7163
7164 \series bold
7165 -Aquestion(answer)
7166 \begin_inset LatexCommand \index{-Aquestion(answer)}
7167
7168 \end_inset
7169
7170
7171 \series default
7172  Assert the answer answer for question, in case it is tested with a preprocessor
7173  conditional such as `#if #question(answer)'.
7174  `-A-' disables the standard assertions that normally describe the target
7175  machine.
7176 \end_layout
7177
7178 \begin_layout List
7179 \labelwidthstring 00.00.0000
7180
7181 \series bold
7182 -Umacro
7183 \begin_inset LatexCommand \index{-Umacro}
7184
7185 \end_inset
7186
7187
7188 \series default
7189  Undefine macro macro.
7190  `-U' options are evaluated after all `-D' options, but before any `-include'
7191  and `-imacros' options.
7192 \end_layout
7193
7194 \begin_layout List
7195 \labelwidthstring 00.00.0000
7196
7197 \series bold
7198 -dM
7199 \begin_inset LatexCommand \index{-dM}
7200
7201 \end_inset
7202
7203
7204 \series default
7205  Tell the preprocessor to output only a list of the macro definitions that
7206  are in effect at the end of preprocessing.
7207  Used with the `-E' option.
7208 \end_layout
7209
7210 \begin_layout List
7211 \labelwidthstring 00.00.0000
7212
7213 \series bold
7214 -dD
7215 \begin_inset LatexCommand \index{-dD}
7216
7217 \end_inset
7218
7219
7220 \series default
7221  Tell the preprocessor to pass all macro definitions into the output, in
7222  their proper sequence in the rest of the output.
7223 \end_layout
7224
7225 \begin_layout List
7226 \labelwidthstring 00.00.0000
7227
7228 \series bold
7229 -dN
7230 \begin_inset LatexCommand \index{-dN}
7231
7232 \end_inset
7233
7234
7235 \size large
7236 \bar under
7237  
7238 \series default
7239 \size default
7240 \bar default
7241 Like `-dD' except that the macro arguments and contents are omitted.
7242  Only `#define name' is included in the output.
7243 \end_layout
7244
7245 \begin_layout List
7246 \labelwidthstring 00.00.0000
7247
7248 \series bold
7249 -pedantic-parse-number
7250 \begin_inset LatexCommand \index{pedantic}
7251
7252 \end_inset
7253
7254
7255 \begin_inset LatexCommand \index{-pedantic-parse-number}
7256
7257 \end_inset
7258
7259
7260 \size large
7261 \bar under
7262
7263 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7264
7265 \end_inset
7266
7267  
7268 \series default
7269 \size default
7270 \bar default
7271 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7272  and the macro LO_B(3) gets expanded.
7273  See also #pragma pedantic_parse_number 
7274 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7275
7276 \end_inset
7277
7278  in section
7279 \begin_inset LatexCommand \ref{sec:Pragmas}
7280
7281 \end_inset
7282
7283  
7284 \emph on
7285 Note: this functionality is not in conformance with C99 standard!
7286 \end_layout
7287
7288 \begin_layout List
7289 \labelwidthstring 00.00.0000
7290
7291 \series bold
7292 -Wp\InsetSpace ~
7293 preprocessorOption[,preprocessorOption]
7294 \series default
7295
7296 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7297
7298 \end_inset
7299
7300 ...
7301  Pass the preprocessorOption to the preprocessor 
7302 \family typewriter
7303 sdcpp
7304 \family default
7305
7306 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7307
7308 \end_inset
7309
7310 .
7311  SDCC uses an adapted version of the preprocessor 
7312 \emph on
7313 cpp
7314 \emph default
7315  of the GNU Compiler Collection
7316 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7317
7318 \end_inset
7319
7320  (
7321 \emph on
7322 gcc
7323 \emph default
7324  
7325 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7326
7327 \end_inset
7328
7329 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7330 4.1.1\InsetSpace ~
7331 CPP\InsetSpace ~
7332 Manual
7333  at 
7334 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7335
7336 \end_inset
7337
7338 .
7339 \end_layout
7340
7341 \begin_layout Standard
7342 \begin_inset VSpace bigskip
7343 \end_inset
7344
7345
7346 \end_layout
7347
7348 \begin_layout Subsection
7349 Linker Options
7350 \begin_inset LatexCommand \index{Options linker}
7351
7352 \end_inset
7353
7354
7355 \begin_inset LatexCommand \index{Linker options}
7356
7357 \end_inset
7358
7359
7360 \end_layout
7361
7362 \begin_layout List
7363 \labelwidthstring 00.00.0000
7364
7365 \series bold
7366 -L\InsetSpace ~
7367 -
7368 \series default
7369
7370 \begin_inset ERT
7371 status collapsed
7372
7373 \begin_layout Standard
7374
7375
7376 \backslash
7377 /
7378 \end_layout
7379
7380 \end_inset
7381
7382
7383 \series bold
7384 -lib-path
7385 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7386
7387 \end_inset
7388
7389
7390 \begin_inset LatexCommand \index{-L -\/-lib-path}
7391
7392 \end_inset
7393
7394
7395 \series default
7396 \InsetSpace ~
7397 <absolute path to additional libraries> This option is passed to the linkage
7398  editor's additional libraries
7399 \begin_inset LatexCommand \index{Libraries}
7400
7401 \end_inset
7402
7403  search path.
7404  The path name must be absolute.
7405  Additional library files may be specified in the command line.
7406  See section Compiling programs for more details.
7407 \end_layout
7408
7409 \begin_layout List
7410 \labelwidthstring 00.00.0000
7411
7412 \series bold
7413 -
7414 \begin_inset ERT
7415 status collapsed
7416
7417 \begin_layout Standard
7418
7419
7420 \backslash
7421 /
7422 \end_layout
7423
7424 \end_inset
7425
7426 -xram-loc
7427 \series default
7428
7429 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7430
7431 \end_inset
7432
7433 \InsetSpace ~
7434 <Value> The start location of the external ram
7435 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7436
7437 \end_inset
7438
7439 , default value is 0.
7440  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7441 \begin_inset ERT
7442 status collapsed
7443
7444 \begin_layout Standard
7445
7446
7447 \backslash
7448 /
7449 \end_layout
7450
7451 \end_inset
7452
7453 -xram-loc 0x8000 or -
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 -xram-loc 32768.
7467 \end_layout
7468
7469 \begin_layout List
7470 \labelwidthstring 00.00.0000
7471
7472 \series bold
7473 -
7474 \begin_inset ERT
7475 status collapsed
7476
7477 \begin_layout Standard
7478
7479
7480 \backslash
7481 /
7482 \end_layout
7483
7484 \end_inset
7485
7486 -code-loc
7487 \series default
7488
7489 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7490
7491 \end_inset
7492
7493 \InsetSpace ~
7494 <Value> The start location of the code
7495 \begin_inset LatexCommand \index{code}
7496
7497 \end_inset
7498
7499  segment, default value 0.
7500  Note when this option is used the interrupt vector table
7501 \begin_inset LatexCommand \index{interrupt vector table}
7502
7503 \end_inset
7504
7505  is also relocated to the given address.
7506  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7507 \begin_inset ERT
7508 status collapsed
7509
7510 \begin_layout Standard
7511
7512
7513 \backslash
7514 /
7515 \end_layout
7516
7517 \end_inset
7518
7519 -code-loc 0x8000 or -
7520 \begin_inset ERT
7521 status collapsed
7522
7523 \begin_layout Standard
7524
7525
7526 \backslash
7527 /
7528 \end_layout
7529
7530 \end_inset
7531
7532 -code-loc 32768.
7533 \end_layout
7534
7535 \begin_layout List
7536 \labelwidthstring 00.00.0000
7537
7538 \series bold
7539 -
7540 \begin_inset ERT
7541 status collapsed
7542
7543 \begin_layout Standard
7544
7545
7546 \backslash
7547 /
7548 \end_layout
7549
7550 \end_inset
7551
7552 -stack-loc
7553 \series default
7554
7555 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7556
7557 \end_inset
7558
7559 \InsetSpace ~
7560 <Value> By default the stack
7561 \begin_inset LatexCommand \index{stack}
7562
7563 \end_inset
7564
7565  is placed after the data segment.
7566  Using this option the stack can be placed anywhere in the internal memory
7567  space of the 8051.
7568  The value entered can be in Hexadecimal or Decimal format, e.g.
7569  -
7570 \begin_inset ERT
7571 status collapsed
7572
7573 \begin_layout Standard
7574
7575
7576 \backslash
7577 /
7578 \end_layout
7579
7580 \end_inset
7581
7582 -stack-loc 0x20 or -
7583 \begin_inset ERT
7584 status collapsed
7585
7586 \begin_layout Standard
7587
7588
7589 \backslash
7590 /
7591 \end_layout
7592
7593 \end_inset
7594
7595 -stack-loc 32.
7596  Since the sp register is incremented before a push or call, the initial
7597  sp will be set to one byte prior the provided value.
7598  The provided value should not overlap any other memory areas such as used
7599  register banks or the data segment and with enough space for the current
7600  application.
7601  The 
7602 \series bold
7603 -
7604 \begin_inset ERT
7605 status collapsed
7606
7607 \begin_layout Standard
7608
7609
7610 \backslash
7611 /
7612 \end_layout
7613
7614 \end_inset
7615
7616 -pack-iram
7617 \series default
7618 \InsetSpace ~
7619
7620 \begin_inset LatexCommand \index{-\/-pack-iram}
7621
7622 \end_inset
7623
7624  option (which is now a default setting) will override this setting, so
7625  you should also specify the 
7626 \series bold
7627 -
7628 \begin_inset ERT
7629 status collapsed
7630
7631 \begin_layout Standard
7632
7633
7634 \backslash
7635 /
7636 \end_layout
7637
7638 \end_inset
7639
7640 -no-pack-iram
7641 \series default
7642 \InsetSpace ~
7643
7644 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7645
7646 \end_inset
7647
7648  option if you need to manually place the stack.
7649 \end_layout
7650
7651 \begin_layout List
7652 \labelwidthstring 00.00.0000
7653
7654 \series bold
7655 -
7656 \begin_inset ERT
7657 status collapsed
7658
7659 \begin_layout Standard
7660
7661
7662 \backslash
7663 /
7664 \end_layout
7665
7666 \end_inset
7667
7668 -xstack-loc
7669 \series default
7670
7671 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7672
7673 \end_inset
7674
7675 \InsetSpace ~
7676 <Value> By default the external stack
7677 \begin_inset LatexCommand \index{xstack}
7678
7679 \end_inset
7680
7681  is placed after the pdata
7682 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7683
7684 \end_inset
7685
7686  segment.
7687  Using this option the xstack can be placed anywhere in the external memory
7688  space of the 8051.
7689  The value entered can be in Hexadecimal or Decimal format, e.g.
7690  -
7691 \begin_inset ERT
7692 status collapsed
7693
7694 \begin_layout Standard
7695
7696
7697 \backslash
7698 /
7699 \end_layout
7700
7701 \end_inset
7702
7703 -xstack-loc 0x8000 or -
7704 \begin_inset ERT
7705 status collapsed
7706
7707 \begin_layout Standard
7708
7709
7710 \backslash
7711 /
7712 \end_layout
7713
7714 \end_inset
7715
7716 -stack-loc 32768.
7717  The provided value should not overlap any other memory areas such as the
7718  pdata or xdata segment and with enough space for the current application.
7719 \end_layout
7720
7721 \begin_layout List
7722 \labelwidthstring 00.00.0000
7723
7724 \series bold
7725 -
7726 \begin_inset ERT
7727 status collapsed
7728
7729 \begin_layout Standard
7730
7731
7732 \backslash
7733 /
7734 \end_layout
7735
7736 \end_inset
7737
7738 -data-loc
7739 \series default
7740
7741 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7742
7743 \end_inset
7744
7745 \InsetSpace ~
7746 <Value> The start location of the internal ram data
7747 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7748
7749 \end_inset
7750
7751  segment.
7752  The value entered can be in Hexadecimal or Decimal format, eg.
7753  -
7754 \begin_inset ERT
7755 status collapsed
7756
7757 \begin_layout Standard
7758
7759
7760 \backslash
7761 /
7762 \end_layout
7763
7764 \end_inset
7765
7766 -data-loc 0x20 or -
7767 \begin_inset ERT
7768 status collapsed
7769
7770 \begin_layout Standard
7771
7772
7773 \backslash
7774 /
7775 \end_layout
7776
7777 \end_inset
7778
7779 -data-loc 32.
7780  (By default, the start location of the internal ram data segment  is set
7781  as low as possible in memory, taking into account the used register banks
7782  and the bit segment at address 0x20.
7783  For example if register banks 0 and 1 are used without bit variables, the
7784  data segment will be set, if -
7785 \begin_inset ERT
7786 status collapsed
7787
7788 \begin_layout Standard
7789
7790
7791 \backslash
7792 /
7793 \end_layout
7794
7795 \end_inset
7796
7797 -data-loc is not used, to location 0x10.)
7798 \end_layout
7799
7800 \begin_layout List
7801 \labelwidthstring 00.00.0000
7802
7803 \series bold
7804 -
7805 \begin_inset ERT
7806 status collapsed
7807
7808 \begin_layout Standard
7809
7810
7811 \backslash
7812 /
7813 \end_layout
7814
7815 \end_inset
7816
7817 -idata-loc
7818 \series default
7819
7820 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7821
7822 \end_inset
7823
7824 \InsetSpace ~
7825 <Value> The start location of the indirectly addressable internal ram
7826 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7827
7828 \end_inset
7829
7830  of the 8051, default value is 0x80.
7831  The value entered can be in Hexadecimal or Decimal format, eg.
7832  -
7833 \begin_inset ERT
7834 status collapsed
7835
7836 \begin_layout Standard
7837
7838
7839 \backslash
7840 /
7841 \end_layout
7842
7843 \end_inset
7844
7845 -idata-loc 0x88 or -
7846 \begin_inset ERT
7847 status collapsed
7848
7849 \begin_layout Standard
7850
7851
7852 \backslash
7853 /
7854 \end_layout
7855
7856 \end_inset
7857
7858 -idata-loc 136.
7859 \end_layout
7860
7861 \begin_layout List
7862 \labelwidthstring 00.00.0000
7863
7864 \series bold
7865 -
7866 \begin_inset ERT
7867 status collapsed
7868
7869 \begin_layout Standard
7870
7871
7872 \backslash
7873 /
7874 \end_layout
7875
7876 \end_inset
7877
7878 -bit-loc
7879 \series default
7880 \InsetSpace ~
7881 <Value> The start location of the bit
7882 \begin_inset LatexCommand \index{bit}
7883
7884 \end_inset
7885
7886  addressable internal ram of the 8051.
7887  This is 
7888 \emph on
7889 not
7890 \emph default
7891  implemented yet.
7892  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7893 -bBSEG=<Value>.
7894 \end_layout
7895
7896 \begin_layout List
7897 \labelwidthstring 00.00.0000
7898
7899 \series bold
7900 -
7901 \begin_inset ERT
7902 status collapsed
7903
7904 \begin_layout Standard
7905
7906
7907 \backslash
7908 /
7909 \end_layout
7910
7911 \end_inset
7912
7913 -out-fmt-ihx
7914 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7915
7916 \end_inset
7917
7918
7919 \bar under
7920  
7921 \series default
7922 \bar default
7923 The linker output (final object code) is in Intel Hex format.
7924 \begin_inset LatexCommand \index{Intel hex format}
7925
7926 \end_inset
7927
7928  This is the default option.
7929  The format itself is documented in the documentation of srecord
7930 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7931
7932 \end_inset
7933
7934 .
7935 \end_layout
7936
7937 \begin_layout List
7938 \labelwidthstring 00.00.0000
7939
7940 \series bold
7941 -
7942 \begin_inset ERT
7943 status collapsed
7944
7945 \begin_layout Standard
7946
7947
7948 \backslash
7949 /
7950 \end_layout
7951
7952 \end_inset
7953
7954 -out-fmt-s19
7955 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7956
7957 \end_inset
7958
7959
7960 \bar under
7961  
7962 \series default
7963 \bar default
7964 The linker output (final object code) is in Motorola S19 format
7965 \begin_inset LatexCommand \index{Motorola S19 format}
7966
7967 \end_inset
7968
7969 .
7970  The format itself is documented in the documentation of srecord.
7971 \end_layout
7972
7973 \begin_layout List
7974 \labelwidthstring 00.00.0000
7975
7976 \series bold
7977 -
7978 \begin_inset ERT
7979 status collapsed
7980
7981 \begin_layout Standard
7982
7983
7984 \backslash
7985 /
7986 \end_layout
7987
7988 \end_inset
7989
7990 -out-fmt-elf
7991 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7992
7993 \end_inset
7994
7995
7996 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7997
7998 \end_inset
7999
8000
8001 \bar under
8002  
8003 \series default
8004 \bar default
8005 The linker output (final object code) is in ELF format
8006 \begin_inset LatexCommand \index{ELF format}
8007
8008 \end_inset
8009
8010 .
8011  (Currently only supported for the HC08
8012 \begin_inset LatexCommand \index{HC08}
8013
8014 \end_inset
8015
8016  processors)
8017 \end_layout
8018
8019 \begin_layout List
8020 \labelwidthstring 00.00.0000
8021
8022 \series bold
8023 -Wl\InsetSpace ~
8024 linkOption[,linkOption]
8025 \series default
8026
8027 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8028
8029 \end_inset
8030
8031 \begin_inset LatexCommand \label{lyx:-Wl option}
8032
8033 \end_inset
8034
8035 ...
8036  Pass the linkOption to the linker.
8037  If a bootloader is used an option like 
8038 \begin_inset Quotes sld
8039 \end_inset
8040
8041 -Wl\InsetSpace ~
8042 -bCSEG=0x1000
8043 \begin_inset Quotes srd
8044 \end_inset
8045
8046  would be typical to set the start of the code segment.
8047  Either use the double quotes around this option or use no space (e.g.
8048  -Wl-bCSEG=0x1000).
8049  See also #pragma constseg and #pragma codeseg in section 
8050 \begin_inset LatexCommand \ref{sec:Pragmas}
8051
8052 \end_inset
8053
8054  .
8055  File sdcc/as/doc/asxhtm.html has more on linker options.
8056 \end_layout
8057
8058 \begin_layout Standard
8059 \begin_inset VSpace bigskip
8060 \end_inset
8061
8062
8063 \end_layout
8064
8065 \begin_layout Subsection
8066 MCS51 Options
8067 \begin_inset LatexCommand \index{Options MCS51}
8068
8069 \end_inset
8070
8071
8072 \begin_inset LatexCommand \index{MCS51 options}
8073
8074 \end_inset
8075
8076
8077 \end_layout
8078
8079 \begin_layout List
8080 \labelwidthstring 00.00.0000
8081
8082 \series bold
8083 -
8084 \begin_inset ERT
8085 status collapsed
8086
8087 \begin_layout Standard
8088
8089
8090 \backslash
8091 /
8092 \end_layout
8093
8094 \end_inset
8095
8096 -model-small
8097 \begin_inset LatexCommand \index{-\/-model-small}
8098
8099 \end_inset
8100
8101
8102 \series default
8103 \size large
8104 \emph on
8105  
8106 \size default
8107 \emph default
8108 Generate code for Small Model programs, see section Memory Models for more
8109  details.
8110  This is the default model.
8111 \end_layout
8112
8113 \begin_layout List
8114 \labelwidthstring 00.00.0000
8115
8116 \series bold
8117 -
8118 \begin_inset ERT
8119 status collapsed
8120
8121 \begin_layout Standard
8122
8123
8124 \backslash
8125 /
8126 \end_layout
8127
8128 \end_inset
8129
8130 -model-medium
8131 \begin_inset LatexCommand \index{-\/-model-medium}
8132
8133 \end_inset
8134
8135
8136 \series default
8137  Generate code for Medium model programs, see section Memory Models for
8138  more details.
8139  If this option is used all source files in the project have to be compiled
8140  with this option.
8141  It must also be used when invoking the linker.
8142 \end_layout
8143
8144 \begin_layout List
8145 \labelwidthstring 00.00.0000
8146
8147 \series bold
8148 -
8149 \begin_inset ERT
8150 status collapsed
8151
8152 \begin_layout Standard
8153
8154
8155 \backslash
8156 /
8157 \end_layout
8158
8159 \end_inset
8160
8161 -model-large
8162 \begin_inset LatexCommand \index{-\/-model-large}
8163
8164 \end_inset
8165
8166
8167 \series default
8168  Generate code for Large model programs, see section Memory Models for more
8169  details.
8170  If this option is used all source files in the project have to be compiled
8171  with this option.
8172  It must also be used when invoking the linker.
8173 \end_layout
8174
8175 \begin_layout List
8176 \labelwidthstring 00.00.0000
8177
8178 \series bold
8179 -
8180 \begin_inset ERT
8181 status collapsed
8182
8183 \begin_layout Standard
8184
8185
8186 \backslash
8187 /
8188 \end_layout
8189
8190 \end_inset
8191
8192 -xstack
8193 \begin_inset LatexCommand \index{-\/-xstack}
8194
8195 \end_inset
8196
8197
8198 \series default
8199  Uses a pseudo stack in the pdata
8200 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8201
8202 \end_inset
8203
8204  area (usually the first 256 bytes in the external ram) for allocating variables
8205  and passing parameters.
8206  See section 
8207 \begin_inset LatexCommand \ref{sub:External-Stack}
8208
8209 \end_inset
8210
8211 \InsetSpace ~
8212  External Stack for more details.
8213 \end_layout
8214
8215 \begin_layout List
8216 \labelwidthstring 00.00.0000
8217
8218 \series bold
8219 -
8220 \begin_inset ERT
8221 status collapsed
8222
8223 \begin_layout Standard
8224
8225
8226 \backslash
8227 /
8228 \end_layout
8229
8230 \end_inset
8231
8232 -iram-size
8233 \series default
8234 \InsetSpace ~
8235 <Value>
8236 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8237
8238 \end_inset
8239
8240  Causes the linker to check if the internal ram usage is within limits of
8241  the given value.
8242 \end_layout
8243
8244 \begin_layout List
8245 \labelwidthstring 00.00.0000
8246
8247 \series bold
8248 -
8249 \begin_inset ERT
8250 status collapsed
8251
8252 \begin_layout Standard
8253
8254
8255 \backslash
8256 /
8257 \end_layout
8258
8259 \end_inset
8260
8261 -xram-size
8262 \series default
8263 \InsetSpace ~
8264 <Value>
8265 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8266
8267 \end_inset
8268
8269  Causes the linker to check if the external ram usage is within limits of
8270  the given value.
8271 \end_layout
8272
8273 \begin_layout List
8274 \labelwidthstring 00.00.0000
8275
8276 \series bold
8277 -
8278 \begin_inset ERT
8279 status collapsed
8280
8281 \begin_layout Standard
8282
8283
8284 \backslash
8285 /
8286 \end_layout
8287
8288 \end_inset
8289
8290 -code-size
8291 \series default
8292 \InsetSpace ~
8293 <Value>
8294 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8295
8296 \end_inset
8297
8298  Causes the linker to check if the code memory usage is within limits of
8299  the given value.
8300 \end_layout
8301
8302 \begin_layout List
8303 \labelwidthstring 00.00.0000
8304
8305 \series bold
8306 -
8307 \begin_inset ERT
8308 status collapsed
8309
8310 \begin_layout Standard
8311
8312
8313 \backslash
8314 /
8315 \end_layout
8316
8317 \end_inset
8318
8319 -stack-size
8320 \series default
8321 \InsetSpace ~
8322 <Value>
8323 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8324
8325 \end_inset
8326
8327  Causes the linker to check if there is at minimum <Value> bytes for stack.
8328 \end_layout
8329
8330 \begin_layout List
8331 \labelwidthstring 00.00.0000
8332
8333 \series bold
8334 -
8335 \begin_inset ERT
8336 status collapsed
8337
8338 \begin_layout Standard
8339
8340
8341 \backslash
8342 /
8343 \end_layout
8344
8345 \end_inset
8346
8347 -pack-iram
8348 \series default
8349 \InsetSpace ~
8350
8351 \begin_inset LatexCommand \index{-\/-pack-iram}
8352
8353 \end_inset
8354
8355  Causes the linker to use unused register banks for data variables and pack
8356  data, idata and stack together.
8357  This is the default now.
8358 \end_layout
8359
8360 \begin_layout List
8361 \labelwidthstring 00.00.0000
8362
8363 \series bold
8364 -
8365 \begin_inset ERT
8366 status collapsed
8367
8368 \begin_layout Standard
8369
8370
8371 \backslash
8372 /
8373 \end_layout
8374
8375 \end_inset
8376
8377 -no-pack-iram
8378 \series default
8379 \InsetSpace ~
8380
8381 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8382
8383 \end_inset
8384
8385  Causes the linker to use old style for allocating memory areas.
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 -acall-ajmp
8406 \series default
8407 \InsetSpace ~
8408
8409 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8410
8411 \end_inset
8412
8413  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8414  acall/ajmp.
8415  Only use this option if your code is in the same 2k block of memory.
8416  You may need to use this option for some 8051 derivatives which lack the
8417  lcall/ljmp instructions..
8418 \end_layout
8419
8420 \begin_layout Standard
8421 \begin_inset VSpace bigskip
8422 \end_inset
8423
8424
8425 \end_layout
8426
8427 \begin_layout Subsection
8428 DS390 / DS400 Options
8429 \begin_inset LatexCommand \index{Options DS390}
8430
8431 \end_inset
8432
8433
8434 \begin_inset LatexCommand \index{DS390}
8435
8436 \end_inset
8437
8438
8439 \end_layout
8440
8441 \begin_layout List
8442 \labelwidthstring 00.00.0000
8443
8444 \series bold
8445 -
8446 \begin_inset ERT
8447 status collapsed
8448
8449 \begin_layout Standard
8450
8451
8452 \backslash
8453 /
8454 \end_layout
8455
8456 \end_inset
8457
8458 -model-flat24
8459 \series default
8460
8461 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8462
8463 \end_inset
8464
8465
8466 \size large
8467 \emph on
8468  
8469 \size default
8470 \emph default
8471 Generate 24-bit flat mode code.
8472  This is the one and only that the ds390 code generator supports right now
8473  and is default when using 
8474 \emph on
8475 -mds390
8476 \emph default
8477 .
8478  See section Memory Models for more details.
8479 \end_layout
8480
8481 \begin_layout List
8482 \labelwidthstring 00.00.0000
8483
8484 \series bold
8485 -
8486 \begin_inset ERT
8487 status collapsed
8488
8489 \begin_layout Standard
8490
8491
8492 \backslash
8493 /
8494 \end_layout
8495
8496 \end_inset
8497
8498 -protect-sp-update
8499 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8500
8501 \end_inset
8502
8503
8504 \series default
8505  disable interrupts during ESP:SP updates.
8506 \end_layout
8507
8508 \begin_layout List
8509 \labelwidthstring 00.00.0000
8510
8511 \series bold
8512 -
8513 \begin_inset ERT
8514 status collapsed
8515
8516 \begin_layout Standard
8517
8518
8519 \backslash
8520 /
8521 \end_layout
8522
8523 \end_inset
8524
8525 -stack-10bit
8526 \series default
8527
8528 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8529
8530 \end_inset
8531
8532  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8533  This is the one and only that the ds390 code generator supports right now
8534  and is default when using 
8535 \emph on
8536 -mds390
8537 \emph default
8538 .
8539  In this mode, the stack is located in the lower 1K of the internal RAM,
8540  which is mapped to 0x400000.
8541  Note that the support is incomplete, since it still uses a single byte
8542  as the stack pointer.
8543  This means that only the lower 256 bytes of the potential 1K stack space
8544  will actually be used.
8545  However, this does allow you to reclaim the precious 256 bytes of low RAM
8546  for use for the DATA and IDATA segments.
8547  The compiler will not generate any code to put the processor into 10 bit
8548  stack mode.
8549  It is important to ensure that the processor is in this mode before calling
8550  any re-entrant functions compiled with this option.
8551  In principle, this should work with the 
8552 \emph on
8553 -
8554 \begin_inset ERT
8555 status collapsed
8556
8557 \begin_layout Standard
8558
8559
8560 \backslash
8561 /
8562 \end_layout
8563
8564 \end_inset
8565
8566 -stack-auto
8567 \begin_inset LatexCommand \index{-\/-stack-auto}
8568
8569 \end_inset
8570
8571
8572 \emph default
8573  option, but that has not been tested.
8574  It is incompatible with the 
8575 \emph on
8576 -
8577 \begin_inset ERT
8578 status collapsed
8579
8580 \begin_layout Standard
8581
8582
8583 \backslash
8584 /
8585 \end_layout
8586
8587 \end_inset
8588
8589 -xstack
8590 \begin_inset LatexCommand \index{-\/-xstack}
8591
8592 \end_inset
8593
8594
8595 \emph default
8596  option.
8597  It also only makes sense if the processor is in 24 bit contiguous addressing
8598  mode (see the 
8599 \emph on
8600 -
8601 \begin_inset ERT
8602 status collapsed
8603
8604 \begin_layout Standard
8605
8606
8607 \backslash
8608 /
8609 \end_layout
8610
8611 \end_inset
8612
8613 -model-flat24 option
8614 \emph default
8615 ).
8616 \series bold
8617
8618 \begin_inset Note Note
8619 status collapsed
8620
8621 \begin_layout List
8622 \labelwidthstring 00.00.0000
8623
8624 \series bold
8625 -
8626 \begin_inset ERT
8627 status open
8628
8629 \begin_layout Standard
8630
8631
8632 \backslash
8633 /
8634 \end_layout
8635
8636 \end_inset
8637
8638 -stack-8-bit - switches off the 10-bit mode
8639 \end_layout
8640
8641 \end_inset
8642
8643
8644 \end_layout
8645
8646 \begin_layout List
8647 \labelwidthstring 00.00.0000
8648
8649 \series bold
8650 -
8651 \begin_inset ERT
8652 status collapsed
8653
8654 \begin_layout Standard
8655
8656
8657 \backslash
8658 /
8659 \end_layout
8660
8661 \end_inset
8662
8663 -stack-probe
8664 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8665
8666 \end_inset
8667
8668
8669 \series default
8670  insert call to function __stack_probe at each function prologue.
8671 \end_layout
8672
8673 \begin_layout List
8674 \labelwidthstring 00.00.0000
8675
8676 \series bold
8677 -
8678 \begin_inset ERT
8679 status open
8680
8681 \begin_layout Standard
8682
8683
8684 \backslash
8685 /
8686 \end_layout
8687
8688 \end_inset
8689
8690 -tini-libid
8691 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8692
8693 \end_inset
8694
8695
8696 \series default
8697  <nnnn> LibraryID used in -mTININative.
8698  
8699 \end_layout
8700
8701 \begin_layout List
8702 \labelwidthstring 00.00.0000
8703
8704 \series bold
8705 -
8706 \begin_inset ERT
8707 status collapsed
8708
8709 \begin_layout Standard
8710
8711
8712 \backslash
8713 /
8714 \end_layout
8715
8716 \end_inset
8717
8718 -use-accelerator
8719 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8720
8721 \end_inset
8722
8723
8724 \series default
8725  generate code for DS390 Arithmetic Accelerator.
8726  
8727 \end_layout
8728
8729 \begin_layout Standard
8730 \begin_inset VSpace bigskip
8731 \end_inset
8732
8733
8734 \end_layout
8735
8736 \begin_layout Subsection
8737 Z80 Options
8738 \begin_inset LatexCommand \index{Options Z80}
8739
8740 \end_inset
8741
8742
8743 \begin_inset LatexCommand \index{Z80}
8744
8745 \end_inset
8746
8747
8748 \end_layout
8749
8750 \begin_layout List
8751 \labelwidthstring 00.00.0000
8752
8753 \series bold
8754 -
8755 \begin_inset ERT
8756 status collapsed
8757
8758 \begin_layout Standard
8759
8760
8761 \backslash
8762 /
8763 \end_layout
8764
8765 \end_inset
8766
8767 -callee-saves-bc
8768 \series default
8769
8770 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8771
8772 \end_inset
8773
8774
8775 \size large
8776 \emph on
8777  
8778 \size default
8779 \emph default
8780 Force a called function to always save BC.
8781 \end_layout
8782
8783 \begin_layout List
8784 \labelwidthstring 00.00.0000
8785
8786 \series bold
8787 -
8788 \begin_inset ERT
8789 status collapsed
8790
8791 \begin_layout Standard
8792
8793
8794 \backslash
8795 /
8796 \end_layout
8797
8798 \end_inset
8799
8800 -no-std-crt0
8801 \series default
8802
8803 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8804
8805 \end_inset
8806
8807  When linking, skip the standard crt0.o object file.
8808  You must provide your own crt0.o for your system when linking.
8809 \end_layout
8810
8811 \begin_layout List
8812 \labelwidthstring 00.00.0000
8813
8814 \series bold
8815 -
8816 \begin_inset ERT
8817 status collapsed
8818
8819 \begin_layout Standard
8820
8821
8822 \backslash
8823 /
8824 \end_layout
8825
8826 \end_inset
8827
8828 -portmode=
8829 \series default
8830 <Value>
8831 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8832
8833 \end_inset
8834
8835  Determinate PORT I/O mode (<Value> is z80 or z180).
8836 \end_layout
8837
8838 \begin_layout List
8839 \labelwidthstring 00.00.0000
8840
8841 \series bold
8842 -
8843 \begin_inset ERT
8844 status collapsed
8845
8846 \begin_layout Standard
8847
8848
8849 \backslash
8850 /
8851 \end_layout
8852
8853 \end_inset
8854
8855 -asm=
8856 \series default
8857 <Value>
8858 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8859
8860 \end_inset
8861
8862  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8863 \end_layout
8864
8865 \begin_layout List
8866 \labelwidthstring 00.00.0000
8867
8868 \series bold
8869 -
8870 \begin_inset ERT
8871 status collapsed
8872
8873 \begin_layout Standard
8874
8875
8876 \backslash
8877 /
8878 \end_layout
8879
8880 \end_inset
8881
8882 -codeseg
8883 \series default
8884 \InsetSpace ~
8885 <Value>
8886 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8887
8888 \end_inset
8889
8890  Use <Value> for the code segment name.
8891 \end_layout
8892
8893 \begin_layout List
8894 \labelwidthstring 00.00.0000
8895
8896 \series bold
8897 -
8898 \begin_inset ERT
8899 status collapsed
8900
8901 \begin_layout Standard
8902
8903
8904 \backslash
8905 /
8906 \end_layout
8907
8908 \end_inset
8909
8910 -constseg
8911 \series default
8912 \InsetSpace ~
8913 <Value>
8914 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8915
8916 \end_inset
8917
8918  Use <Value> for the const segment name.
8919 \end_layout
8920
8921 \begin_layout List
8922 \labelwidthstring 00.00.0000
8923 \begin_inset VSpace bigskip
8924 \end_inset
8925
8926
8927 \end_layout
8928
8929 \begin_layout Subsection
8930 GBZ80 Options
8931 \begin_inset LatexCommand \index{Options GBZ80}
8932
8933 \end_inset
8934
8935
8936 \begin_inset LatexCommand \index{GBZ80}
8937
8938 \end_inset
8939
8940
8941 \end_layout
8942
8943 \begin_layout List
8944 \labelwidthstring 00.00.0000
8945
8946 \series bold
8947 -
8948 \begin_inset ERT
8949 status collapsed
8950
8951 \begin_layout Standard
8952
8953
8954 \backslash
8955 /
8956 \end_layout
8957
8958 \end_inset
8959
8960 -callee-saves-bc
8961 \series default
8962
8963 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8964
8965 \end_inset
8966
8967
8968 \size large
8969 \emph on
8970  
8971 \size default
8972 \emph default
8973 Force a called function to always save BC.
8974 \end_layout
8975
8976 \begin_layout List
8977 \labelwidthstring 00.00.0000
8978
8979 \series bold
8980 -
8981 \begin_inset ERT
8982 status collapsed
8983
8984 \begin_layout Standard
8985
8986
8987 \backslash
8988 /
8989 \end_layout
8990
8991 \end_inset
8992
8993 -no-std-crt0
8994 \series default
8995
8996 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8997
8998 \end_inset
8999
9000  When linking, skip the standard crt0.o object file.
9001  You must provide your own crt0.o for your system when linking.
9002 \end_layout
9003
9004 \begin_layout List
9005 \labelwidthstring 00.00.0000
9006
9007 \series bold
9008 -bo
9009 \series default
9010 \InsetSpace ~
9011 <Num>
9012 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9013
9014 \end_inset
9015
9016  Use code bank <Num>.
9017 \end_layout
9018
9019 \begin_layout List
9020 \labelwidthstring 00.00.0000
9021
9022 \series bold
9023 -ba
9024 \series default
9025 \InsetSpace ~
9026 <Num>
9027 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9028
9029 \end_inset
9030
9031  Use data bank <Num>.
9032 \end_layout
9033
9034 \begin_layout List
9035 \labelwidthstring 00.00.0000
9036
9037 \series bold
9038 -
9039 \begin_inset ERT
9040 status collapsed
9041
9042 \begin_layout Standard
9043
9044
9045 \backslash
9046 /
9047 \end_layout
9048
9049 \end_inset
9050
9051 -codeseg
9052 \series default
9053 \InsetSpace ~
9054 <Value>
9055 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9056
9057 \end_inset
9058
9059  Use <Value> for the code segment name.
9060 \end_layout
9061
9062 \begin_layout List
9063 \labelwidthstring 00.00.0000
9064
9065 \series bold
9066 -
9067 \begin_inset ERT
9068 status collapsed
9069
9070 \begin_layout Standard
9071
9072
9073 \backslash
9074 /
9075 \end_layout
9076
9077 \end_inset
9078
9079 -constseg
9080 \series default
9081 \InsetSpace ~
9082 <Value>
9083 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9084
9085 \end_inset
9086
9087  Use <Value> for the const segment name.
9088 \end_layout
9089
9090 \begin_layout Standard
9091 \begin_inset VSpace bigskip
9092 \end_inset
9093
9094
9095 \end_layout
9096
9097 \begin_layout Subsection
9098 Optimization Options
9099 \begin_inset LatexCommand \index{Options optimization}
9100
9101 \end_inset
9102
9103
9104 \begin_inset LatexCommand \index{Optimization options}
9105
9106 \end_inset
9107
9108
9109 \end_layout
9110
9111 \begin_layout List
9112 \labelwidthstring 00.00.0000
9113
9114 \series bold
9115 -
9116 \begin_inset ERT
9117 status collapsed
9118
9119 \begin_layout Standard
9120
9121
9122 \backslash
9123 /
9124 \end_layout
9125
9126 \end_inset
9127
9128 -nogcse
9129 \begin_inset LatexCommand \index{-\/-nogcse}
9130
9131 \end_inset
9132
9133
9134 \series default
9135  Will not do global subexpression elimination, this option may be used when
9136  the compiler creates undesirably large stack/data spaces to store compiler
9137  temporaries (
9138 \emph on
9139 s
9140 \emph default
9141 pill 
9142 \emph on
9143 loc
9144 \emph default
9145 ations, sloc
9146 \begin_inset LatexCommand \index{sloc (spill location)}
9147
9148 \end_inset
9149
9150 ).
9151  A warning message will be generated when this happens and the compiler
9152  will indicate the number of extra bytes it allocated.
9153  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9154 nogcse
9155 \begin_inset LatexCommand \index{\#pragma nogcse}
9156
9157 \end_inset
9158
9159  can be used to turn off global subexpression elimination
9160 \begin_inset LatexCommand \index{Subexpression elimination}
9161
9162 \end_inset
9163
9164  for a given function only.
9165 \end_layout
9166
9167 \begin_layout List
9168 \labelwidthstring 00.00.0000
9169
9170 \series bold
9171 -
9172 \begin_inset ERT
9173 status collapsed
9174
9175 \begin_layout Standard
9176
9177
9178 \backslash
9179 /
9180 \end_layout
9181
9182 \end_inset
9183
9184 -noinvariant
9185 \begin_inset LatexCommand \index{-\/-noinvariant}
9186
9187 \end_inset
9188
9189
9190 \series default
9191  Will not do loop invariant optimizations, this may be turned off for reasons
9192  explained for the previous option.
9193  For more details of loop optimizations performed see Loop Invariants in
9194  section 
9195 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9196
9197 \end_inset
9198
9199 .
9200  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9201 noinvariant
9202 \begin_inset LatexCommand \index{\#pragma noinvariant}
9203
9204 \end_inset
9205
9206  can be used to turn off invariant optimizations for a given function only.
9207 \end_layout
9208
9209 \begin_layout List
9210 \labelwidthstring 00.00.0000
9211
9212 \series bold
9213 -
9214 \begin_inset ERT
9215 status collapsed
9216
9217 \begin_layout Standard
9218
9219
9220 \backslash
9221 /
9222 \end_layout
9223
9224 \end_inset
9225
9226 -noinduction
9227 \begin_inset LatexCommand \index{-\/-noinduction}
9228
9229 \end_inset
9230
9231
9232 \series default
9233  Will not do loop induction optimizations, see section strength reduction
9234  for more details.
9235  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9236 noinduction
9237 \begin_inset LatexCommand \index{\#pragma noinduction}
9238
9239 \end_inset
9240
9241  can be used to turn off induction optimizations for a given function only.
9242 \end_layout
9243
9244 \begin_layout List
9245 \labelwidthstring 00.00.0000
9246
9247 \series bold
9248 -
9249 \begin_inset ERT
9250 status collapsed
9251
9252 \begin_layout Standard
9253
9254
9255 \backslash
9256 /
9257 \end_layout
9258
9259 \end_inset
9260
9261 -nojtbound
9262 \begin_inset LatexCommand \index{-\/-nojtbound}
9263
9264 \end_inset
9265
9266
9267 \size large
9268 \bar under
9269  
9270 \series default
9271 \size default
9272 \bar default
9273  Will not generate boundary condition check when switch statements
9274 \begin_inset LatexCommand \index{switch statement}
9275
9276 \end_inset
9277
9278  are implemented using jump-tables.
9279  See section 
9280 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9281
9282 \end_inset
9283
9284 \InsetSpace ~
9285 Switch Statements for more details.
9286  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9287 nojtbound
9288 \begin_inset LatexCommand \index{\#pragma nojtbound}
9289
9290 \end_inset
9291
9292  can be used to turn off boundary checking for jump tables for a given function
9293  only.
9294 \end_layout
9295
9296 \begin_layout List
9297 \labelwidthstring 00.00.0000
9298
9299 \series bold
9300 -
9301 \begin_inset ERT
9302 status collapsed
9303
9304 \begin_layout Standard
9305
9306
9307 \backslash
9308 /
9309 \end_layout
9310
9311 \end_inset
9312
9313 -noloopreverse
9314 \begin_inset LatexCommand \index{-\/-noloopreverse}
9315
9316 \end_inset
9317
9318
9319 \series default
9320 \size large
9321  
9322 \size default
9323 Will not do loop reversal 
9324 \begin_inset LatexCommand \index{Loop reversing}
9325
9326 \end_inset
9327
9328 optimization.
9329 \end_layout
9330
9331 \begin_layout List
9332 \labelwidthstring 00.00.0000
9333 -
9334 \begin_inset ERT
9335 status collapsed
9336
9337 \begin_layout Standard
9338
9339
9340 \backslash
9341 /
9342 \end_layout
9343
9344 \end_inset
9345
9346 -
9347 \series bold
9348 nolabelopt
9349 \series default
9350  
9351 \begin_inset LatexCommand \index{-\/-nolabelopt }
9352
9353 \end_inset
9354
9355 Will not optimize labels (makes the dumpfiles more readable).
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 -no-xinit-opt
9376 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9377
9378 \end_inset
9379
9380
9381 \series default
9382  Will not memcpy initialized data from code space into xdata space.
9383  This saves a few bytes in code space if you don't have initialized data
9384 \begin_inset LatexCommand \index{Variable initialization}
9385
9386 \end_inset
9387
9388 .
9389 \end_layout
9390
9391 \begin_layout List
9392 \labelwidthstring 00.00.0000
9393
9394 \series bold
9395 -
9396 \begin_inset ERT
9397 status collapsed
9398
9399 \begin_layout Standard
9400
9401
9402 \backslash
9403 /
9404 \end_layout
9405
9406 \end_inset
9407
9408 -nooverlay
9409 \begin_inset LatexCommand \index{-\/-nooverlay}
9410
9411 \end_inset
9412
9413
9414 \series default
9415   The compiler will not overlay parameters and local variables of any function,
9416  see section Parameters and local variables for more details.
9417 \end_layout
9418
9419 \begin_layout List
9420 \labelwidthstring 00.00.0000
9421
9422 \series bold
9423 -
9424 \begin_inset ERT
9425 status collapsed
9426
9427 \begin_layout Standard
9428
9429
9430 \backslash
9431 /
9432 \end_layout
9433
9434 \end_inset
9435
9436 -no-peep
9437 \begin_inset LatexCommand \index{-\/-no-peep}
9438
9439 \end_inset
9440
9441
9442 \series default
9443  Disable peep-hole optimization with built-in rules.
9444 \end_layout
9445
9446 \begin_layout List
9447 \labelwidthstring 00.00.0000
9448
9449 \series bold
9450 -
9451 \begin_inset ERT
9452 status collapsed
9453
9454 \begin_layout Standard
9455
9456
9457 \backslash
9458 /
9459 \end_layout
9460
9461 \end_inset
9462
9463 -peep-file
9464 \series default
9465
9466 \begin_inset LatexCommand \index{-\/-peep-file}
9467
9468 \end_inset
9469
9470 \InsetSpace ~
9471 <filename> This option can be used to use additional rules to be used by
9472  the peep hole optimizer.
9473  See section 
9474 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9475
9476 \end_inset
9477
9478 \InsetSpace ~
9479 Peep Hole optimizations for details on how to write these rules.
9480 \end_layout
9481
9482 \begin_layout List
9483 \labelwidthstring 00.00.0000
9484
9485 \series bold
9486 -
9487 \begin_inset ERT
9488 status collapsed
9489
9490 \begin_layout Standard
9491
9492
9493 \backslash
9494 /
9495 \end_layout
9496
9497 \end_inset
9498
9499 -peep-asm
9500 \begin_inset LatexCommand \index{-\/-peep-asm}
9501
9502 \end_inset
9503
9504
9505 \series default
9506  Pass the inline assembler code through the peep hole optimizer.
9507  This can cause unexpected changes to inline assembler code, please go through
9508  the peephole optimizer
9509 \begin_inset LatexCommand \index{Peephole optimizer}
9510
9511 \end_inset
9512
9513  rules defined in the source file tree '<target>/peeph.def' before using
9514  this option.
9515 \end_layout
9516
9517 \begin_layout List
9518 \labelwidthstring 00.00.0000
9519
9520 \series bold
9521 -
9522 \begin_inset ERT
9523 status collapsed
9524
9525 \begin_layout Standard
9526
9527
9528 \backslash
9529 /
9530 \end_layout
9531
9532 \end_inset
9533
9534 -opt-code-speed
9535 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9536
9537 \end_inset
9538
9539
9540 \series default
9541  The compiler will optimize code generation towards fast code, possibly
9542  at the expense of code size.
9543 \end_layout
9544
9545 \begin_layout List
9546 \labelwidthstring 00.00.0000
9547
9548 \series bold
9549 -
9550 \begin_inset ERT
9551 status collapsed
9552
9553 \begin_layout Standard
9554
9555
9556 \backslash
9557 /
9558 \end_layout
9559
9560 \end_inset
9561
9562 -opt-code-size
9563 \begin_inset LatexCommand \index{-\/-opt-code-size}
9564
9565 \end_inset
9566
9567
9568 \series default
9569  The compiler will optimize code generation towards compact code, possibly
9570  at the expense of code speed.
9571 \end_layout
9572
9573 \begin_layout Standard
9574 \begin_inset VSpace bigskip
9575 \end_inset
9576
9577
9578 \end_layout
9579
9580 \begin_layout Subsection
9581 Other Options
9582 \begin_inset LatexCommand \index{Options other}
9583
9584 \end_inset
9585
9586
9587 \end_layout
9588
9589 \begin_layout List
9590 \labelwidthstring 00.00.0000
9591
9592 \series bold
9593 -c\InsetSpace ~
9594 -
9595 \begin_inset ERT
9596 status collapsed
9597
9598 \begin_layout Standard
9599
9600
9601 \backslash
9602 /
9603 \end_layout
9604
9605 \end_inset
9606
9607 -compile-only
9608 \begin_inset LatexCommand \index{-\/-compile-only}
9609
9610 \end_inset
9611
9612
9613 \begin_inset LatexCommand \index{-c -\/-compile-only}
9614
9615 \end_inset
9616
9617
9618 \series default
9619  will compile and assemble the source, but will not call the linkage editor.
9620 \end_layout
9621
9622 \begin_layout List
9623 \labelwidthstring 00.00.0000
9624
9625 \series bold
9626 -
9627 \series default
9628
9629 \begin_inset ERT
9630 status collapsed
9631
9632 \begin_layout Standard
9633
9634
9635 \backslash
9636 /
9637 \end_layout
9638
9639 \end_inset
9640
9641
9642 \series bold
9643 -c1mode
9644 \begin_inset LatexCommand \index{-\/-c1mode}
9645
9646 \end_inset
9647
9648
9649 \series default
9650  reads the preprocessed source from standard input and compiles it.
9651  The file name for the assembler output must be specified using the -o option.
9652 \end_layout
9653
9654 \begin_layout List
9655 \labelwidthstring 00.00.0000
9656
9657 \series bold
9658 -E
9659 \begin_inset LatexCommand \index{-E}
9660
9661 \end_inset
9662
9663
9664 \series default
9665  Run only the C preprocessor.
9666  Preprocess all the C source files specified and output the results to standard
9667  output.
9668 \end_layout
9669
9670 \begin_layout List
9671 \labelwidthstring 00.00.0000
9672
9673 \series bold
9674 -o\InsetSpace ~
9675 <path/file>
9676 \begin_inset LatexCommand \index{-o <path/file>}
9677
9678 \end_inset
9679
9680  
9681 \series default
9682 The output path where everything will be placed or the file name used for
9683  all generated output files.
9684  If the parameter is a path, it must have a trailing slash (or backslash
9685  for the Windows binaries) to be recognized as a path.
9686
9687 \emph on
9688  
9689 \emph default
9690 Note for Windows users: if the path contains spaces, it should be surrounded
9691  by quotes.
9692  The trailing backslash should be doubled in order to prevent escaping the
9693  final quote, for example: 
9694 \emph on
9695 -o 
9696 \begin_inset Quotes sld
9697 \end_inset
9698
9699 F:
9700 \backslash
9701 Projects
9702 \backslash
9703 test3
9704 \backslash
9705 output 1
9706 \backslash
9707
9708 \backslash
9709
9710 \begin_inset Quotes srd
9711 \end_inset
9712
9713
9714 \emph default
9715  or put after the final quote, for example: 
9716 \emph on
9717 -o 
9718 \begin_inset Quotes sld
9719 \end_inset
9720
9721 F:
9722 \backslash
9723 Projects
9724 \backslash
9725 test3
9726 \backslash
9727 output 1
9728 \begin_inset Quotes srd
9729 \end_inset
9730
9731
9732 \backslash
9733
9734 \emph default
9735 .
9736  The path using slashes for directory delimiters can be used too, for example:
9737  
9738 \emph on
9739 -o 
9740 \begin_inset Quotes sld
9741 \end_inset
9742
9743 F:/Projects/test3/output 1/
9744 \begin_inset Quotes srd
9745 \end_inset
9746
9747
9748 \emph default
9749 .
9750 \end_layout
9751
9752 \begin_layout List
9753 \labelwidthstring 00.00.0000
9754
9755 \series bold
9756 -
9757 \begin_inset ERT
9758 status collapsed
9759
9760 \begin_layout Standard
9761
9762
9763 \backslash
9764 /
9765 \end_layout
9766
9767 \end_inset
9768
9769 -stack-auto
9770 \begin_inset LatexCommand \index{-\/-stack-auto}
9771
9772 \end_inset
9773
9774
9775 \series default
9776 \size large
9777 \emph on
9778  
9779 \size default
9780 \emph default
9781 All functions in the source file will be compiled as 
9782 \emph on
9783 reentrant
9784 \emph default
9785
9786 \begin_inset LatexCommand \index{reentrant}
9787
9788 \end_inset
9789
9790 , i.e.
9791  the parameters and local variables will be allocated on the stack
9792 \begin_inset LatexCommand \index{stack}
9793
9794 \end_inset
9795
9796 .
9797  See section 
9798 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9799
9800 \end_inset
9801
9802  Parameters and Local Variables for more details.
9803  If this option is used all source files in the project should be compiled
9804  with this option.
9805  It automatically implies -
9806 \series bold
9807
9808 \begin_inset ERT
9809 status open
9810
9811 \begin_layout Standard
9812
9813
9814 \backslash
9815 /
9816 \end_layout
9817
9818 \end_inset
9819
9820
9821 \series default
9822 -int-long-reent and -
9823 \series bold
9824
9825 \begin_inset ERT
9826 status open
9827
9828 \begin_layout Standard
9829
9830
9831 \backslash
9832 /
9833 \end_layout
9834
9835 \end_inset
9836
9837
9838 \series default
9839 -float-reent.
9840  
9841 \end_layout
9842
9843 \begin_layout List
9844 \labelwidthstring 00.00.0000
9845
9846 \series bold
9847 -
9848 \begin_inset ERT
9849 status collapsed
9850
9851 \begin_layout Standard
9852
9853
9854 \backslash
9855 /
9856 \end_layout
9857
9858 \end_inset
9859
9860 -callee-saves
9861 \begin_inset LatexCommand \index{-\/-callee-saves}
9862
9863 \end_inset
9864
9865  
9866 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9867
9868 \end_inset
9869
9870 function1[,function2][,function3]....
9871
9872 \series default
9873  The compiler by default uses a caller saves convention for register saving
9874  across function calls, however this can cause unnecessary register pushing
9875  and popping when calling small functions from larger functions.
9876  This option can be used to switch the register saving convention for the
9877  function names specified.
9878  The compiler will not save registers when calling these functions, no extra
9879  code will be generated at the entry and exit (function prologue
9880 \series bold
9881
9882 \begin_inset LatexCommand \index{function prologue}
9883
9884 \end_inset
9885
9886
9887 \series default
9888  and epilogue
9889 \series bold
9890
9891 \begin_inset LatexCommand \index{function epilogue}
9892
9893 \end_inset
9894
9895
9896 \series default
9897 ) for these functions to save and restore the registers used by these functions,
9898  this can SUBSTANTIALLY reduce code and improve run time performance of
9899  the generated code.
9900  In the future the compiler (with inter procedural analysis) will be able
9901  to determine the appropriate scheme to use for each function call.
9902  DO NOT use this option for built-in functions such as _mulint..., if this
9903  option is used for a library function the appropriate library function
9904  needs to be recompiled with the same option.
9905  If the project consists of multiple source files then all the source file
9906  should be compiled with the same -
9907 \begin_inset ERT
9908 status collapsed
9909
9910 \begin_layout Standard
9911
9912
9913 \backslash
9914 /
9915 \end_layout
9916
9917 \end_inset
9918
9919 -callee-saves option string.
9920  Also see #pragma\InsetSpace ~
9921 callee_saves 
9922 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9923
9924 \end_inset
9925
9926  
9927 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9928
9929 \end_inset
9930
9931 .
9932 \end_layout
9933
9934 \begin_layout List
9935 \labelwidthstring 00.00.0000
9936
9937 \series bold
9938 -
9939 \begin_inset ERT
9940 status collapsed
9941
9942 \begin_layout Standard
9943
9944
9945 \backslash
9946 /
9947 \end_layout
9948
9949 \end_inset
9950
9951 -all-callee-saves
9952 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9953
9954 \end_inset
9955
9956  
9957 \series default
9958 Function of
9959 \series bold
9960  
9961 \series default
9962 -
9963 \begin_inset ERT
9964 status collapsed
9965
9966 \begin_layout Standard
9967
9968
9969 \backslash
9970 /
9971 \end_layout
9972
9973 \end_inset
9974
9975 -callee-saves will be applied to all functions by default.
9976 \end_layout
9977
9978 \begin_layout List
9979 \labelwidthstring 00.00.0000
9980
9981 \series bold
9982 -
9983 \begin_inset ERT
9984 status collapsed
9985
9986 \begin_layout Standard
9987
9988
9989 \backslash
9990 /
9991 \end_layout
9992
9993 \end_inset
9994
9995 -debug
9996 \begin_inset LatexCommand \index{-\/-debug}
9997
9998 \end_inset
9999
10000
10001 \bar under
10002  
10003 \series default
10004 \bar default
10005 When this option is used the compiler will generate debug information.
10006  The debug information collected in a file with .cdb extension can be used
10007  with the SDCDB.
10008  For more information see documentation for SDCDB.
10009  Another file with no extension contains debug information in AOMF or AOMF51
10010 \begin_inset LatexCommand \index{AOMF, AOMF51}
10011
10012 \end_inset
10013
10014  format which is commonly used by third party tools.
10015 \end_layout
10016
10017 \begin_layout List
10018 \labelwidthstring 00.00.0000
10019
10020 \series bold
10021 -S
10022 \begin_inset LatexCommand \index{-S}
10023
10024 \end_inset
10025
10026
10027 \size large
10028 \bar under
10029  
10030 \series default
10031 \size default
10032 \bar default
10033 Stop after the stage of compilation proper; do not assemble.
10034  The output is an assembler code file for the input file specified.
10035 \end_layout
10036
10037 \begin_layout List
10038 \labelwidthstring 00.00.0000
10039
10040 \series bold
10041 -
10042 \begin_inset ERT
10043 status collapsed
10044
10045 \begin_layout Standard
10046
10047
10048 \backslash
10049 /
10050 \end_layout
10051
10052 \end_inset
10053
10054 -int-long-reent
10055 \begin_inset LatexCommand \index{-\/-int-long-reent}
10056
10057 \end_inset
10058
10059
10060 \series default
10061  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10062  Note by default these libraries are compiled as non-reentrant.
10063  See section Installation for more details.
10064 \end_layout
10065
10066 \begin_layout List
10067 \labelwidthstring 00.00.0000
10068
10069 \series bold
10070 -
10071 \begin_inset ERT
10072 status collapsed
10073
10074 \begin_layout Standard
10075
10076
10077 \backslash
10078 /
10079 \end_layout
10080
10081 \end_inset
10082
10083 -cyclomatic
10084 \begin_inset LatexCommand \index{-\/-cyclomatic}
10085
10086 \end_inset
10087
10088
10089 \bar under
10090  
10091 \series default
10092 \bar default
10093 This option will cause the compiler to generate an information message for
10094  each function in the source file.
10095  The message contains some 
10096 \emph on
10097 important
10098 \emph default
10099  information about the function.
10100  The number of edges and nodes the compiler detected in the control flow
10101  graph of the function, and most importantly the 
10102 \emph on
10103 cyclomatic complexity
10104 \begin_inset LatexCommand \index{Cyclomatic complexity}
10105
10106 \end_inset
10107
10108
10109 \emph default
10110  see section on Cyclomatic Complexity for more details.
10111 \end_layout
10112
10113 \begin_layout List
10114 \labelwidthstring 00.00.0000
10115
10116 \series bold
10117 -
10118 \begin_inset ERT
10119 status collapsed
10120
10121 \begin_layout Standard
10122
10123
10124 \backslash
10125 /
10126 \end_layout
10127
10128 \end_inset
10129
10130 -float-reent
10131 \begin_inset LatexCommand \index{-\/-float-reent}
10132
10133 \end_inset
10134
10135
10136 \series default
10137  Floating point library is compiled as reentrant
10138 \begin_inset LatexCommand \index{reentrant}
10139
10140 \end_inset
10141
10142 .
10143  See section Installation for more details.
10144 \end_layout
10145
10146 \begin_layout List
10147 \labelwidthstring 00.00.0000
10148
10149 \series bold
10150 -
10151 \begin_inset ERT
10152 status collapsed
10153
10154 \begin_layout Standard
10155
10156
10157 \backslash
10158 /
10159 \end_layout
10160
10161 \end_inset
10162
10163 -funsigned-char
10164 \begin_inset LatexCommand \index{-\/-funsigned-char}
10165
10166 \end_inset
10167
10168
10169 \series default
10170  The default signedness for every type is
10171 \family typewriter
10172  signed
10173 \family default
10174 .
10175  In some embedded environments the default signedness of
10176 \family typewriter
10177  char
10178 \family default
10179  is
10180 \family typewriter
10181  unsigned
10182 \family default
10183 .
10184  To set the signess for characters to unsigned, use the option -
10185 \series bold
10186
10187 \begin_inset ERT
10188 status open
10189
10190 \begin_layout Standard
10191
10192
10193 \backslash
10194 /
10195 \end_layout
10196
10197 \end_inset
10198
10199
10200 \series default
10201 -funsigned-char.
10202  If this option is set and no signedness keyword (unsigned/signed) is given,
10203  a char will be signed.
10204  All other types are unaffected.
10205 \end_layout
10206
10207 \begin_layout List
10208 \labelwidthstring 00.00.0000
10209
10210 \series bold
10211 -
10212 \begin_inset ERT
10213 status collapsed
10214
10215 \begin_layout Standard
10216
10217
10218 \backslash
10219 /
10220 \end_layout
10221
10222 \end_inset
10223
10224 -main-return
10225 \begin_inset LatexCommand \index{-\/-main-return}
10226
10227 \end_inset
10228
10229
10230 \series default
10231  This option can be used if the code generated is called by a monitor program
10232  or if the main routine includes an endless loop.
10233  This option results in slightly smaller code and saves two bytes of stack
10234  space.
10235  The return from the 'main'
10236 \begin_inset LatexCommand \index{main return}
10237
10238 \end_inset
10239
10240  function will return to the function calling main.
10241  The default setting is to lock up i.e.
10242  generate a '
10243 \family typewriter
10244 sjmp .
10245 \family default
10246 '.
10247 \end_layout
10248
10249 \begin_layout List
10250 \labelwidthstring 00.00.0000
10251
10252 \series bold
10253 -
10254 \begin_inset ERT
10255 status collapsed
10256
10257 \begin_layout Standard
10258
10259
10260 \backslash
10261 /
10262 \end_layout
10263
10264 \end_inset
10265
10266 -nostdinc
10267 \begin_inset LatexCommand \index{-\/-nostdinc}
10268
10269 \end_inset
10270
10271
10272 \series default
10273  This will prevent the compiler from passing on the default include path
10274  to the preprocessor.
10275 \end_layout
10276
10277 \begin_layout List
10278 \labelwidthstring 00.00.0000
10279
10280 \series bold
10281 -
10282 \begin_inset ERT
10283 status collapsed
10284
10285 \begin_layout Standard
10286
10287
10288 \backslash
10289 /
10290 \end_layout
10291
10292 \end_inset
10293
10294 -nostdlib
10295 \begin_inset LatexCommand \index{-\/-nostdlib}
10296
10297 \end_inset
10298
10299
10300 \series default
10301  This will prevent the compiler from passing on the default library
10302 \begin_inset LatexCommand \index{Libraries}
10303
10304 \end_inset
10305
10306  path to the linker.
10307 \end_layout
10308
10309 \begin_layout List
10310 \labelwidthstring 00.00.0000
10311
10312 \series bold
10313 -
10314 \begin_inset ERT
10315 status collapsed
10316
10317 \begin_layout Standard
10318
10319
10320 \backslash
10321 /
10322 \end_layout
10323
10324 \end_inset
10325
10326 -verbose
10327 \begin_inset LatexCommand \index{-\/-verbose}
10328
10329 \end_inset
10330
10331
10332 \series default
10333  Shows the various actions the compiler is performing.
10334 \end_layout
10335
10336 \begin_layout List
10337 \labelwidthstring 00.00.0000
10338
10339 \series bold
10340 -V
10341 \begin_inset LatexCommand \index{-V}
10342
10343 \end_inset
10344
10345
10346 \series default
10347  Shows the actual commands the compiler is executing.
10348 \end_layout
10349
10350 \begin_layout List
10351 \labelwidthstring 00.00.0000
10352
10353 \series bold
10354 -
10355 \begin_inset ERT
10356 status collapsed
10357
10358 \begin_layout Standard
10359
10360
10361 \backslash
10362 /
10363 \end_layout
10364
10365 \end_inset
10366
10367 -no-c-code-in-asm
10368 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10369
10370 \end_inset
10371
10372
10373 \series default
10374  Hides your ugly and inefficient c-code from the asm file, so you can always
10375  blame the compiler :)
10376 \end_layout
10377
10378 \begin_layout List
10379 \labelwidthstring 00.00.0000
10380
10381 \series bold
10382 -
10383 \begin_inset ERT
10384 status collapsed
10385
10386 \begin_layout Standard
10387
10388
10389 \backslash
10390 /
10391 \end_layout
10392
10393 \end_inset
10394
10395 -fverbose-asm
10396 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10397
10398 \end_inset
10399
10400
10401 \series default
10402  Include code generator and peep-hole comments in the generated asm files.
10403 \end_layout
10404
10405 \begin_layout List
10406 \labelwidthstring 00.00.0000
10407
10408 \series bold
10409 -
10410 \begin_inset ERT
10411 status collapsed
10412
10413 \begin_layout Standard
10414
10415
10416 \backslash
10417 /
10418 \end_layout
10419
10420 \end_inset
10421
10422 -no-peep-comments
10423 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10424
10425 \end_inset
10426
10427
10428 \series default
10429  Don't include peep-hole comments in the generated asm files even if -
10430 \series bold
10431
10432 \begin_inset ERT
10433 status open
10434
10435 \begin_layout Standard
10436
10437
10438 \backslash
10439 /
10440 \end_layout
10441
10442 \end_inset
10443
10444
10445 \series default
10446 -fverbose-asm option is specified.
10447 \end_layout
10448
10449 \begin_layout List
10450 \labelwidthstring 00.00.0000
10451
10452 \series bold
10453 -
10454 \begin_inset ERT
10455 status collapsed
10456
10457 \begin_layout Standard
10458
10459
10460 \backslash
10461 /
10462 \end_layout
10463
10464 \end_inset
10465
10466 -i-code-in-asm
10467 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10468
10469 \end_inset
10470
10471
10472 \series default
10473  Include i-codes in the asm file.
10474  Sounds like noise but is most helpful for debugging the compiler itself.
10475 \end_layout
10476
10477 \begin_layout List
10478 \labelwidthstring 00.00.0000
10479
10480 \series bold
10481 -
10482 \begin_inset ERT
10483 status collapsed
10484
10485 \begin_layout Standard
10486
10487
10488 \backslash
10489 /
10490 \end_layout
10491
10492 \end_inset
10493
10494 -less-pedantic
10495 \begin_inset LatexCommand \index{pedantic}
10496
10497 \end_inset
10498
10499
10500 \begin_inset LatexCommand \index{-\/-less-pedantic}
10501
10502 \end_inset
10503
10504
10505 \series default
10506
10507 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10508
10509 \end_inset
10510
10511  Disable some of the more pedantic warnings
10512 \begin_inset LatexCommand \index{Warnings}
10513
10514 \end_inset
10515
10516 .
10517  For more details, see the less_pedantic pragma 
10518 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10519
10520 \end_inset
10521
10522 .
10523 \end_layout
10524
10525 \begin_layout List
10526 \labelwidthstring 00.00.0000
10527
10528 \series bold
10529 -
10530 \begin_inset ERT
10531 status collapsed
10532
10533 \begin_layout Standard
10534
10535
10536 \backslash
10537 /
10538 \end_layout
10539
10540 \end_inset
10541
10542 -disable-warning\InsetSpace ~
10543 <nnnn>
10544 \begin_inset LatexCommand \index{-\/-disable-warning}
10545
10546 \end_inset
10547
10548
10549 \series default
10550  Disable specific warning with number <nnnn>.
10551 \end_layout
10552
10553 \begin_layout List
10554 \labelwidthstring 00.00.0000
10555
10556 \series bold
10557 -
10558 \begin_inset ERT
10559 status collapsed
10560
10561 \begin_layout Standard
10562
10563
10564 \backslash
10565 /
10566 \end_layout
10567
10568 \end_inset
10569
10570 -Werror
10571 \begin_inset LatexCommand \index{-\/-Werror}
10572
10573 \end_inset
10574
10575
10576 \series default
10577  Treat all warnings as errors.
10578 \end_layout
10579
10580 \begin_layout List
10581 \labelwidthstring 00.00.0000
10582
10583 \series bold
10584 -
10585 \begin_inset ERT
10586 status collapsed
10587
10588 \begin_layout Standard
10589
10590
10591 \backslash
10592 /
10593 \end_layout
10594
10595 \end_inset
10596
10597 -print-search-dirs
10598 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10599
10600 \end_inset
10601
10602
10603 \series default
10604  Display the directories in the compiler's search path
10605 \end_layout
10606
10607 \begin_layout List
10608 \labelwidthstring 00.00.0000
10609
10610 \series bold
10611 -
10612 \begin_inset ERT
10613 status collapsed
10614
10615 \begin_layout Standard
10616
10617
10618 \backslash
10619 /
10620 \end_layout
10621
10622 \end_inset
10623
10624 -vc
10625 \begin_inset LatexCommand \index{-\/-vc}
10626
10627 \end_inset
10628
10629
10630 \series default
10631  Display errors and warnings using MSVC style, so you can use SDCC with
10632  the visual studio IDE
10633 \begin_inset LatexCommand \index{IDE}
10634
10635 \end_inset
10636
10637 .
10638  With SDCC both offering a GCC-like (the default) and a MSVC-like
10639 \begin_inset LatexCommand \index{MSVC output style}
10640
10641 \end_inset
10642
10643  output style, integration into most programming editors should be straightforwa
10644 rd.
10645 \end_layout
10646
10647 \begin_layout List
10648 \labelwidthstring 00.00.0000
10649
10650 \series bold
10651 -
10652 \begin_inset ERT
10653 status collapsed
10654
10655 \begin_layout Standard
10656
10657
10658 \backslash
10659 /
10660 \end_layout
10661
10662 \end_inset
10663
10664 -use-stdout
10665 \begin_inset LatexCommand \index{-\/-use-stdout}
10666
10667 \end_inset
10668
10669
10670 \series default
10671  Send errors and warnings to stdout instead of stderr.
10672 \end_layout
10673
10674 \begin_layout List
10675 \labelwidthstring 00.00.0000
10676
10677 \series bold
10678 -Wa\InsetSpace ~
10679 asmOption[,asmOption]
10680 \series default
10681
10682 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10683
10684 \end_inset
10685
10686 ...
10687  Pass the asmOption to the assembler
10688 \begin_inset LatexCommand \index{Options assembler}
10689
10690 \end_inset
10691
10692
10693 \begin_inset LatexCommand \index{Assembler options}
10694
10695 \end_inset
10696
10697 .
10698  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10699 \end_layout
10700
10701 \begin_layout List
10702 \labelwidthstring 00.00.0000
10703
10704 \series bold
10705 -
10706 \begin_inset ERT
10707 status collapsed
10708
10709 \begin_layout Standard
10710
10711
10712 \backslash
10713 /
10714 \end_layout
10715
10716 \end_inset
10717
10718 -std-sdcc89
10719 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10720
10721 \end_inset
10722
10723
10724 \series default
10725  Generally follow the C89 standard, but allow SDCC features that conflict
10726  with the standard (default).
10727 \end_layout
10728
10729 \begin_layout List
10730 \labelwidthstring 00.00.0000
10731
10732 \series bold
10733 -
10734 \begin_inset ERT
10735 status collapsed
10736
10737 \begin_layout Standard
10738
10739
10740 \backslash
10741 /
10742 \end_layout
10743
10744 \end_inset
10745
10746 -std-c89
10747 \begin_inset LatexCommand \index{-\/-std-c89}
10748
10749 \end_inset
10750
10751
10752 \series default
10753  Follow the C89 standard and disable SDCC features that conflict with the
10754  standard.
10755 \end_layout
10756
10757 \begin_layout List
10758 \labelwidthstring 00.00.0000
10759
10760 \series bold
10761 -
10762 \begin_inset ERT
10763 status collapsed
10764
10765 \begin_layout Standard
10766
10767
10768 \backslash
10769 /
10770 \end_layout
10771
10772 \end_inset
10773
10774 -std-sdcc99
10775 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10776
10777 \end_inset
10778
10779
10780 \series default
10781  Generally follow the C99 standard, but allow SDCC features that conflict
10782  with the standard (incomplete support).
10783 \end_layout
10784
10785 \begin_layout List
10786 \labelwidthstring 00.00.0000
10787
10788 \series bold
10789 -
10790 \begin_inset ERT
10791 status collapsed
10792
10793 \begin_layout Standard
10794
10795
10796 \backslash
10797 /
10798 \end_layout
10799
10800 \end_inset
10801
10802 -std-c99
10803 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10804
10805 \end_inset
10806
10807
10808 \series default
10809  Follow the C99 standard and disable SDCC features that conflict with the
10810  standard (incomplete support).
10811 \end_layout
10812
10813 \begin_layout List
10814 \labelwidthstring 00.00.0000
10815
10816 \series bold
10817 -
10818 \begin_inset ERT
10819 status collapsed
10820
10821 \begin_layout Standard
10822
10823
10824 \backslash
10825 /
10826 \end_layout
10827
10828 \end_inset
10829
10830 -codeseg
10831 \series default
10832
10833 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10834
10835 \end_inset
10836
10837 \begin_inset LatexCommand \label{lyx:-codeseg}
10838
10839 \end_inset
10840
10841 \InsetSpace ~
10842 <Name> The name to be used for the code
10843 \begin_inset LatexCommand \index{code}
10844
10845 \end_inset
10846
10847  segment, default CSEG.
10848  This is useful if you need to tell the compiler to put the code in a special
10849  segment so you can later on tell the linker to put this segment in a special
10850  place in memory.
10851  Can be used for instance when using bank switching to put the code in a
10852  bank.
10853 \end_layout
10854
10855 \begin_layout List
10856 \labelwidthstring 00.00.0000
10857
10858 \series bold
10859 -
10860 \begin_inset ERT
10861 status collapsed
10862
10863 \begin_layout Standard
10864
10865
10866 \backslash
10867 /
10868 \end_layout
10869
10870 \end_inset
10871
10872 -constseg
10873 \series default
10874
10875 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10876
10877 \end_inset
10878
10879 \InsetSpace ~
10880 <Name> The name to be used for the const
10881 \begin_inset LatexCommand \index{const}
10882
10883 \end_inset
10884
10885  segment, default CONST.
10886  This is useful if you need to tell the compiler to put the const data in
10887  a special segment so you can later on tell the linker to put this segment
10888  in a special place in memory.
10889  Can be used for instance when using bank switching to put the const data
10890  in a bank.
10891 \end_layout
10892
10893 \begin_layout List
10894 \labelwidthstring 00.00.0000
10895
10896 \series bold
10897 -
10898 \begin_inset ERT
10899 status collapsed
10900
10901 \begin_layout Standard
10902
10903
10904 \backslash
10905 /
10906 \end_layout
10907
10908 \end_inset
10909
10910 -fdollars-in-identifiers
10911 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10912
10913 \end_inset
10914
10915
10916 \series default
10917  Permit '$' as an identifier character.
10918 \end_layout
10919
10920 \begin_layout List
10921 \labelwidthstring 00.00.0000
10922
10923 \series bold
10924 -
10925 \begin_inset ERT
10926 status collapsed
10927
10928 \begin_layout Standard
10929
10930
10931 \backslash
10932 /
10933 \end_layout
10934
10935 \end_inset
10936
10937 -more-pedantic
10938 \series default
10939
10940 \begin_inset LatexCommand \index{-\/-more-pedantic}
10941
10942 \end_inset
10943
10944
10945 \begin_inset LatexCommand \index{pedantic}
10946
10947 \end_inset
10948
10949  Actually this is 
10950 \series bold
10951 \emph on
10952 not
10953 \series default
10954 \emph default
10955  a SDCC compiler option but if you want 
10956 \emph on
10957 more
10958 \emph default
10959  warnings you can use a separate tool dedicated to syntax checking like
10960  splint
10961 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10962
10963 \end_inset
10964
10965
10966 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10967
10968 \end_inset
10969
10970  
10971 \begin_inset LatexCommand \url{http://www.splint.org}
10972
10973 \end_inset
10974
10975 .
10976  To make your source files parseable by splint you will have to include
10977  
10978 \family sans
10979 lint.h
10980 \family default
10981
10982 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10983
10984 \end_inset
10985
10986  in your source file and add brackets around extended keywords (like 
10987 \family sans
10988
10989 \begin_inset Quotes sld
10990 \end_inset
10991
10992 __at\InsetSpace ~
10993
10994 \series bold
10995 (
10996 \series default
10997 0xab
10998 \series bold
10999 )
11000 \series default
11001
11002 \begin_inset Quotes srd
11003 \end_inset
11004
11005
11006 \family default
11007  and 
11008 \family sans
11009
11010 \begin_inset Quotes sld
11011 \end_inset
11012
11013 __interrupt\InsetSpace ~
11014 (2)
11015 \begin_inset Quotes srd
11016 \end_inset
11017
11018
11019 \family default
11020 ).
11021  
11022 \newline
11023 Splint has an excellent on line manual at 
11024 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11025
11026 \end_inset
11027
11028  and it's capabilities go beyond pure syntax checking.
11029  You'll need to tell splint the location of SDCC's include files so a typical
11030  command line could look like this: 
11031 \newline
11032
11033 \family sans
11034 splint\InsetSpace ~
11035 -I\InsetSpace ~
11036 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11037 \InsetSpace ~
11038 myprogram.c
11039 \end_layout
11040
11041 \begin_layout List
11042 \labelwidthstring 00.00.0000
11043
11044 \series bold
11045 -
11046 \begin_inset ERT
11047 status collapsed
11048
11049 \begin_layout Standard
11050
11051
11052 \backslash
11053 /
11054 \end_layout
11055
11056 \end_inset
11057
11058 -short-is-8bits
11059 \series default
11060
11061 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11062
11063 \end_inset
11064
11065
11066 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11067
11068 \end_inset
11069
11070  Treat short as 8-bit (for backward compatibility with older versions of
11071  compiler - see section 
11072 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11073
11074 \end_inset
11075
11076 )
11077 \end_layout
11078
11079 \begin_layout Standard
11080 \begin_inset VSpace bigskip
11081 \end_inset
11082
11083
11084 \end_layout
11085
11086 \begin_layout Subsection
11087 Intermediate Dump Options
11088 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11089
11090 \end_inset
11091
11092
11093 \begin_inset LatexCommand \index{Options intermediate dump}
11094
11095 \end_inset
11096
11097
11098 \begin_inset LatexCommand \index{Intermediate dump options}
11099
11100 \end_inset
11101
11102
11103 \end_layout
11104
11105 \begin_layout Standard
11106 The following options are provided for the purpose of retargetting and debugging
11107  the compiler.
11108  They provide a means to dump the intermediate code (iCode
11109 \begin_inset LatexCommand \index{iCode}
11110
11111 \end_inset
11112
11113 ) generated by the compiler in human readable form at various stages of
11114  the compilation process.
11115  More on iCodes see chapter 
11116 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11117
11118 \end_inset
11119
11120  
11121 \begin_inset Quotes srd
11122 \end_inset
11123
11124 The anatomy of the compiler
11125 \begin_inset Quotes srd
11126 \end_inset
11127
11128 .
11129 \end_layout
11130
11131 \begin_layout List
11132 \labelwidthstring 00.00.0000
11133
11134 \series bold
11135 -
11136 \begin_inset ERT
11137 status collapsed
11138
11139 \begin_layout Standard
11140
11141
11142 \backslash
11143 /
11144 \end_layout
11145
11146 \end_inset
11147
11148 -dumpraw
11149 \begin_inset LatexCommand \index{-\/-dumpraw}
11150
11151 \end_inset
11152
11153
11154 \series default
11155  This option will cause the compiler to dump the intermediate code into
11156  a file of named 
11157 \emph on
11158 <source filename>.dumpraw
11159 \emph default
11160  just after the intermediate code has been generated for a function, i.e.
11161  before any optimizations are done.
11162  The basic blocks
11163 \begin_inset LatexCommand \index{Basic blocks}
11164
11165 \end_inset
11166
11167  at this stage ordered in the depth first number, so they may not be in
11168  sequence of execution.
11169 \end_layout
11170
11171 \begin_layout List
11172 \labelwidthstring 00.00.0000
11173
11174 \series bold
11175 -
11176 \begin_inset ERT
11177 status collapsed
11178
11179 \begin_layout Standard
11180
11181
11182 \backslash
11183 /
11184 \end_layout
11185
11186 \end_inset
11187
11188 -dumpgcse
11189 \begin_inset LatexCommand \index{-\/-dumpgcse}
11190
11191 \end_inset
11192
11193
11194 \series default
11195  Will create a dump of iCodes, after global subexpression elimination
11196 \begin_inset LatexCommand \index{Global subexpression elimination}
11197
11198 \end_inset
11199
11200 , into a file named 
11201 \emph on
11202 <source filename>.dumpgcse.
11203 \end_layout
11204
11205 \begin_layout List
11206 \labelwidthstring 00.00.0000
11207
11208 \series bold
11209 -
11210 \begin_inset ERT
11211 status collapsed
11212
11213 \begin_layout Standard
11214
11215
11216 \backslash
11217 /
11218 \end_layout
11219
11220 \end_inset
11221
11222 -dumpdeadcode
11223 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11224
11225 \end_inset
11226
11227
11228 \series default
11229  Will create a dump of iCodes, after deadcode elimination
11230 \begin_inset LatexCommand \index{Dead-code elimination}
11231
11232 \end_inset
11233
11234 , into a file named 
11235 \emph on
11236 <source filename>.dumpdeadcode.
11237 \end_layout
11238
11239 \begin_layout List
11240 \labelwidthstring 00.00.0000
11241
11242 \series bold
11243 -
11244 \begin_inset ERT
11245 status collapsed
11246
11247 \begin_layout Standard
11248
11249
11250 \backslash
11251 /
11252 \end_layout
11253
11254 \end_inset
11255
11256 -dumploop
11257 \begin_inset LatexCommand \index{-\/-dumploop}
11258
11259 \end_inset
11260
11261
11262 \series default
11263 \size large
11264  
11265 \size default
11266 Will create a dump of iCodes, after loop optimizations
11267 \begin_inset LatexCommand \index{Loop optimization}
11268
11269 \end_inset
11270
11271 , into a file named 
11272 \emph on
11273 <source filename>.dumploop.
11274 \end_layout
11275
11276 \begin_layout List
11277 \labelwidthstring 00.00.0000
11278
11279 \series bold
11280 -
11281 \begin_inset ERT
11282 status collapsed
11283
11284 \begin_layout Standard
11285
11286
11287 \backslash
11288 /
11289 \end_layout
11290
11291 \end_inset
11292
11293 -dumprange
11294 \begin_inset LatexCommand \index{-\/-dumprange}
11295
11296 \end_inset
11297
11298
11299 \series default
11300 \size large
11301  
11302 \size default
11303 Will create a dump of iCodes, after live range analysis
11304 \begin_inset LatexCommand \index{Live range analysis}
11305
11306 \end_inset
11307
11308 , into a file named 
11309 \emph on
11310 <source filename>.dumprange.
11311 \end_layout
11312
11313 \begin_layout List
11314 \labelwidthstring 00.00.0000
11315
11316 \series bold
11317 -
11318 \begin_inset ERT
11319 status collapsed
11320
11321 \begin_layout Standard
11322
11323
11324 \backslash
11325 /
11326 \end_layout
11327
11328 \end_inset
11329
11330 -dumlrange
11331 \begin_inset LatexCommand \index{-\/-dumlrange}
11332
11333 \end_inset
11334
11335
11336 \series default
11337  Will dump the life ranges
11338 \begin_inset LatexCommand \index{Live range analysis}
11339
11340 \end_inset
11341
11342  for all symbols.
11343 \end_layout
11344
11345 \begin_layout List
11346 \labelwidthstring 00.00.0000
11347
11348 \series bold
11349 -
11350 \begin_inset ERT
11351 status collapsed
11352
11353 \begin_layout Standard
11354
11355
11356 \backslash
11357 /
11358 \end_layout
11359
11360 \end_inset
11361
11362 -dumpregassign
11363 \begin_inset LatexCommand \index{-\/-dumpregassign}
11364
11365 \end_inset
11366
11367
11368 \bar under
11369  
11370 \series default
11371 \bar default
11372 Will create a dump of iCodes, after register assignment
11373 \begin_inset LatexCommand \index{Register assignment}
11374
11375 \end_inset
11376
11377 , into a file named 
11378 \emph on
11379 <source filename>.dumprassgn.
11380 \end_layout
11381
11382 \begin_layout List
11383 \labelwidthstring 00.00.0000
11384
11385 \series bold
11386 -
11387 \begin_inset ERT
11388 status collapsed
11389
11390 \begin_layout Standard
11391
11392
11393 \backslash
11394 /
11395 \end_layout
11396
11397 \end_inset
11398
11399 -dumplrange
11400 \begin_inset LatexCommand \index{-\/-dumplrange}
11401
11402 \end_inset
11403
11404
11405 \series default
11406  Will create a dump of the live ranges of iTemp's
11407 \end_layout
11408
11409 \begin_layout List
11410 \labelwidthstring 00.00.0000
11411
11412 \series bold
11413 -
11414 \begin_inset ERT
11415 status collapsed
11416
11417 \begin_layout Standard
11418
11419
11420 \backslash
11421 /
11422 \end_layout
11423
11424 \end_inset
11425
11426 -dumpall
11427 \begin_inset LatexCommand \index{-\/-dumpall}
11428
11429 \end_inset
11430
11431
11432 \size large
11433 \bar under
11434  
11435 \series default
11436 \size default
11437 \bar default
11438 Will cause all the above mentioned dumps to be created.
11439 \end_layout
11440
11441 \begin_layout Standard
11442 \begin_inset VSpace bigskip
11443 \end_inset
11444
11445
11446 \end_layout
11447
11448 \begin_layout Subsection
11449 Redirecting output on Windows Shells
11450 \end_layout
11451
11452 \begin_layout Standard
11453 By default SDCC writes its error messages to 
11454 \begin_inset Quotes sld
11455 \end_inset
11456
11457 standard error
11458 \begin_inset Quotes srd
11459 \end_inset
11460
11461 .
11462  To force all messages to 
11463 \begin_inset Quotes sld
11464 \end_inset
11465
11466 standard output
11467 \begin_inset Quotes srd
11468 \end_inset
11469
11470  use 
11471 \series bold
11472 -
11473 \series default
11474 \emph on
11475
11476 \begin_inset ERT
11477 status collapsed
11478
11479 \begin_layout Standard
11480
11481
11482 \backslash
11483 /
11484 \end_layout
11485
11486 \end_inset
11487
11488
11489 \series bold
11490 \emph default
11491 -
11492 \series default
11493 use-stdout
11494 \begin_inset LatexCommand \index{-\/-use-stdout}
11495
11496 \end_inset
11497
11498 .
11499  Additionally, if you happen to have visual studio installed in your windows
11500  machine, you can use it to compile your sources using a custom build and
11501  the SDCC -
11502 \emph on
11503
11504 \begin_inset ERT
11505 status collapsed
11506
11507 \begin_layout Standard
11508
11509
11510 \backslash
11511 /
11512 \end_layout
11513
11514 \end_inset
11515
11516
11517 \emph default
11518 -vc
11519 \begin_inset LatexCommand \index{-\/-vc}
11520
11521 \end_inset
11522
11523  option.
11524  Something like this should work:
11525 \newline
11526
11527 \newline
11528
11529 \series bold
11530 c:
11531 \backslash
11532 sdcc
11533 \backslash
11534 bin
11535 \backslash
11536 sdcc.exe -
11537 \series default
11538 \emph on
11539
11540 \begin_inset ERT
11541 status collapsed
11542
11543 \begin_layout Standard
11544
11545
11546 \backslash
11547 /
11548 \end_layout
11549
11550 \end_inset
11551
11552
11553 \series bold
11554 \emph default
11555 -vc -
11556 \series default
11557 \emph on
11558
11559 \begin_inset ERT
11560 status collapsed
11561
11562 \begin_layout Standard
11563
11564
11565 \backslash
11566 /
11567 \end_layout
11568
11569 \end_inset
11570
11571
11572 \series bold
11573 \emph default
11574 -model-large -c $(InputPath)
11575 \series default
11576
11577 \begin_inset VSpace bigskip
11578 \end_inset
11579
11580
11581 \end_layout
11582
11583 \begin_layout Section
11584 Environment variables
11585 \begin_inset LatexCommand \index{Environment variables}
11586
11587 \end_inset
11588
11589
11590 \end_layout
11591
11592 \begin_layout Standard
11593 SDCC recognizes the following environment variables:
11594 \end_layout
11595
11596 \begin_layout List
11597 \labelwidthstring 00.00.0000
11598
11599 \series bold
11600 SDCC_LEAVE_SIGNALS
11601 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11602
11603 \end_inset
11604
11605
11606 \series default
11607  SDCC installs a signal handler
11608 \begin_inset LatexCommand \index{signal handler}
11609
11610 \end_inset
11611
11612  to be able to delete temporary files after an user break (^C) or an exception.
11613  If this environment variable is set, SDCC won't install the signal handler
11614  in order to be able to debug SDCC.
11615 \end_layout
11616
11617 \begin_layout List
11618 \labelwidthstring 00.00.0000
11619
11620 \series bold
11621 TMP,\InsetSpace ~
11622 TEMP,\InsetSpace ~
11623 TMPDIR
11624 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11625
11626 \end_inset
11627
11628
11629 \series default
11630  Path, where temporary files will be created.
11631  The order of the variables is the search order.
11632  In a standard *nix environment these variables are not set, and there's
11633  no need to set them.
11634  On Windows it's recommended to set one of them.
11635 \end_layout
11636
11637 \begin_layout List
11638 \labelwidthstring 00.00.0000
11639
11640 \series bold
11641 SDCC_HOME
11642 \begin_inset LatexCommand \index{SDCC\_HOME}
11643
11644 \end_inset
11645
11646
11647 \series default
11648  Path, see section 
11649 \begin_inset LatexCommand \ref{sub:Install-paths}
11650
11651 \end_inset
11652
11653 \InsetSpace ~
11654
11655 \begin_inset Quotes sld
11656 \end_inset
11657
11658  Install Paths
11659 \begin_inset Quotes srd
11660 \end_inset
11661
11662 .
11663 \end_layout
11664
11665 \begin_layout List
11666 \labelwidthstring 00.00.0000
11667
11668 \series bold
11669 SDCC_INCLUDE
11670 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11671
11672 \end_inset
11673
11674
11675 \series default
11676  Path, see section 
11677 \begin_inset LatexCommand \ref{sub:Search-Paths}
11678
11679 \end_inset
11680
11681 \InsetSpace ~
11682
11683 \begin_inset Quotes sld
11684 \end_inset
11685
11686 Search Paths
11687 \begin_inset Quotes srd
11688 \end_inset
11689
11690 .
11691 \end_layout
11692
11693 \begin_layout List
11694 \labelwidthstring 00.00.0000
11695
11696 \series bold
11697 SDCC_LIB
11698 \begin_inset LatexCommand \index{SDCC\_LIB}
11699
11700 \end_inset
11701
11702
11703 \series default
11704  Path, see section 
11705 \begin_inset LatexCommand \ref{sub:Search-Paths}
11706
11707 \end_inset
11708
11709 \InsetSpace ~
11710
11711 \begin_inset Quotes sld
11712 \end_inset
11713
11714 Search Paths
11715 \begin_inset Quotes srd
11716 \end_inset
11717
11718 ..
11719 \end_layout
11720
11721 \begin_layout Standard
11722 There are some more environment variables recognized by SDCC, but these
11723  are solely used for debugging purposes.
11724  They can change or disappear very quickly, and will never be documented.
11725 \begin_inset VSpace bigskip
11726 \end_inset
11727
11728
11729 \end_layout
11730
11731 \begin_layout Section
11732 Storage Class Language Extensions
11733 \end_layout
11734
11735 \begin_layout Subsection
11736 MCS51/DS390 Storage Class
11737 \begin_inset LatexCommand \index{Storage class}
11738
11739 \end_inset
11740
11741  Language Extensions
11742 \end_layout
11743
11744 \begin_layout Standard
11745 In addition to the ANSI storage classes SDCC allows the following MCS51
11746  specific storage classes:
11747 \end_layout
11748
11749 \begin_layout Subsubsection
11750 data
11751 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11752
11753 \end_inset
11754
11755
11756 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11757
11758 \end_inset
11759
11760  / near
11761 \begin_inset LatexCommand \index{near (storage class)}
11762
11763 \end_inset
11764
11765
11766 \begin_inset LatexCommand \index{\_\_near (storage class)}
11767
11768 \end_inset
11769
11770
11771 \end_layout
11772
11773 \begin_layout Standard
11774 This is the 
11775 \series bold
11776 default
11777 \series default
11778  storage class for the Small Memory model (
11779 \emph on
11780 data
11781 \emph default
11782  and 
11783 \emph on
11784 near
11785 \emph default
11786  or the more ANSI-C compliant forms 
11787 \emph on
11788 __data
11789 \emph default
11790  and 
11791 \emph on
11792 __near
11793 \emph default
11794  can be used synonymously).
11795  Variables declared with this storage class will be allocated in the directly
11796  addressable portion of the internal RAM of a 8051, e.g.:
11797 \end_layout
11798
11799 \begin_layout Verse
11800
11801 \family typewriter
11802 __data unsigned char test_data;
11803 \end_layout
11804
11805 \begin_layout Standard
11806 Writing 0x01 to this variable generates the assembly code:
11807 \end_layout
11808
11809 \begin_layout Verse
11810
11811 \family typewriter
11812 75*00 01\InsetSpace ~
11813 \InsetSpace ~
11814 \InsetSpace ~
11815 mov\InsetSpace ~
11816 \InsetSpace ~
11817 _test_data,#0x01
11818 \end_layout
11819
11820 \begin_layout Subsubsection
11821 xdata
11822 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11823
11824 \end_inset
11825
11826
11827 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11828
11829 \end_inset
11830
11831  / far
11832 \begin_inset LatexCommand \index{far (storage class)}
11833
11834 \end_inset
11835
11836
11837 \begin_inset LatexCommand \index{\_\_far (storage class)}
11838
11839 \end_inset
11840
11841
11842 \end_layout
11843
11844 \begin_layout Standard
11845 Variables declared with this storage class will be placed in the external
11846  RAM.
11847  This is the 
11848 \series bold
11849 default
11850 \series default
11851  storage class for the Large Memory model, e.g.:
11852 \end_layout
11853
11854 \begin_layout Verse
11855
11856 \family typewriter
11857 __xdata unsigned char test_xdata;
11858 \end_layout
11859
11860 \begin_layout Standard
11861 Writing 0x01 to this variable generates the assembly code:
11862 \end_layout
11863
11864 \begin_layout Verse
11865
11866 \family typewriter
11867 90s00r00\InsetSpace ~
11868 \InsetSpace ~
11869 \InsetSpace ~
11870 mov\InsetSpace ~
11871 \InsetSpace ~
11872 dptr,#_test_xdata 
11873 \newline
11874 74\InsetSpace ~
11875 01\InsetSpace ~
11876 \InsetSpace ~
11877 \InsetSpace ~
11878 \InsetSpace ~
11879 \InsetSpace ~
11880 \InsetSpace ~
11881 mov\InsetSpace ~
11882 \InsetSpace ~
11883 a,#0x01 
11884 \newline
11885 F0\InsetSpace ~
11886 \InsetSpace ~
11887 \InsetSpace ~
11888 \InsetSpace ~
11889 \InsetSpace ~
11890 \InsetSpace ~
11891 \InsetSpace ~
11892 \InsetSpace ~
11893 \InsetSpace ~
11894 movx\InsetSpace ~
11895 @dptr,a 
11896 \end_layout
11897
11898 \begin_layout Subsubsection
11899 idata
11900 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11901
11902 \end_inset
11903
11904
11905 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11906
11907 \end_inset
11908
11909
11910 \end_layout
11911
11912 \begin_layout Standard
11913 Variables declared with this storage class will be allocated into the indirectly
11914  addressable portion of the internal ram of a 8051, e.g.:
11915 \end_layout
11916
11917 \begin_layout Verse
11918
11919 \family typewriter
11920 __idata unsigned char test_idata;
11921 \end_layout
11922
11923 \begin_layout Standard
11924 Writing 0x01 to this variable generates the assembly code:
11925 \end_layout
11926
11927 \begin_layout Verse
11928
11929 \family typewriter
11930 78r00\InsetSpace ~
11931 \InsetSpace ~
11932 \InsetSpace ~
11933 \InsetSpace ~
11934 \InsetSpace ~
11935 \InsetSpace ~
11936 \InsetSpace ~
11937 mov\InsetSpace ~
11938 \InsetSpace ~
11939 r0,#_test_idata
11940 \newline
11941 76\InsetSpace ~
11942 01\InsetSpace ~
11943 \InsetSpace ~
11944 \InsetSpace ~
11945 \InsetSpace ~
11946 \InsetSpace ~
11947 \InsetSpace ~
11948 \InsetSpace ~
11949 mov\InsetSpace ~
11950 \InsetSpace ~
11951 @r0,#0x01
11952 \end_layout
11953
11954 \begin_layout Standard
11955 Please note, the first 128 byte of idata physically access the same RAM
11956  as the data memory.
11957  The original 8051 had 128 byte idata memory, nowadays most devices have
11958  256 byte idata memory.
11959  The stack
11960 \begin_inset LatexCommand \index{stack}
11961
11962 \end_inset
11963
11964  is located in idata memory.
11965 \end_layout
11966
11967 \begin_layout Subsubsection
11968 pdata
11969 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11970
11971 \end_inset
11972
11973
11974 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11975
11976 \end_inset
11977
11978
11979 \end_layout
11980
11981 \begin_layout Standard
11982 Paged xdata access is just as straightforward as using the other addressing
11983  modes of a 8051.
11984  It is typically located at the start of xdata and has a maximum size of
11985  256 bytes.
11986  The following example writes 0x01 to the pdata variable.
11987  Please note, pdata access physically accesses xdata memory.
11988  The high byte of the address is determined by port P2 
11989 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11990
11991 \end_inset
11992
11993 (or in case of some 8051 variants by a separate Special Function Register,
11994  see section 
11995 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11996
11997 \end_inset
11998
11999 ).
12000  This is the 
12001 \series bold
12002 default
12003 \series default
12004  storage class for the Medium Memory model, e.g.:
12005 \end_layout
12006
12007 \begin_layout Verse
12008
12009 \family typewriter
12010 __pdata unsigned char test_pdata;
12011 \end_layout
12012
12013 \begin_layout Standard
12014 Writing 0x01 to this variable generates the assembly code:
12015 \end_layout
12016
12017 \begin_layout Verse
12018
12019 \family typewriter
12020 78r00\InsetSpace ~
12021 \InsetSpace ~
12022 \InsetSpace ~
12023 \InsetSpace ~
12024 \InsetSpace ~
12025 \InsetSpace ~
12026 mov r0,#_test_pdata
12027 \newline
12028 74 01\InsetSpace ~
12029 \InsetSpace ~
12030 \InsetSpace ~
12031 \InsetSpace ~
12032 \InsetSpace ~
12033 \InsetSpace ~
12034 mov a,#0x01 
12035 \newline
12036 F2\InsetSpace ~
12037 \InsetSpace ~
12038 \InsetSpace ~
12039 \InsetSpace ~
12040 \InsetSpace ~
12041 \InsetSpace ~
12042 \InsetSpace ~
12043 \InsetSpace ~
12044 \InsetSpace ~
12045 movx @r0,a
12046 \end_layout
12047
12048 \begin_layout Standard
12049 If the -
12050 \begin_inset ERT
12051 status collapsed
12052
12053 \begin_layout Standard
12054
12055
12056 \backslash
12057 /
12058 \end_layout
12059
12060 \end_inset
12061
12062 -xstack
12063 \begin_inset LatexCommand \index{-\/-xstack}
12064
12065 \end_inset
12066
12067  option is used the pdata memory area is followed by the xstack memory area
12068  and the sum of their sizes is limited to 256 bytes.
12069 \end_layout
12070
12071 \begin_layout Subsubsection
12072 code
12073 \begin_inset LatexCommand \index{code}
12074
12075 \end_inset
12076
12077
12078 \begin_inset LatexCommand \index{\_\_code}
12079
12080 \end_inset
12081
12082
12083 \end_layout
12084
12085 \begin_layout Standard
12086 'Variables' declared with this storage class will be placed in the code
12087  memory:
12088 \end_layout
12089
12090 \begin_layout Verse
12091
12092 \family typewriter
12093 __code unsigned char test_code;
12094 \end_layout
12095
12096 \begin_layout Standard
12097 Read access to this variable generates the assembly code:
12098 \end_layout
12099
12100 \begin_layout Verse
12101
12102 \family typewriter
12103 90s00r6F\InsetSpace ~
12104 \InsetSpace ~
12105 \InsetSpace ~
12106 mov dptr,#_test_code
12107 \newline
12108 E4\InsetSpace ~
12109 \InsetSpace ~
12110 \InsetSpace ~
12111 \InsetSpace ~
12112 \InsetSpace ~
12113 \InsetSpace ~
12114 \InsetSpace ~
12115 \InsetSpace ~
12116 \InsetSpace ~
12117 clr a
12118 \newline
12119 93\InsetSpace ~
12120 \InsetSpace ~
12121 \InsetSpace ~
12122 \InsetSpace ~
12123 \InsetSpace ~
12124 \InsetSpace ~
12125 \InsetSpace ~
12126 \InsetSpace ~
12127 \InsetSpace ~
12128 movc a,@a+dptr 
12129 \end_layout
12130
12131 \begin_layout Standard
12132
12133 \family typewriter
12134 char
12135 \family default
12136  indexed arrays of characters in code memory can be accessed efficiently:
12137 \end_layout
12138
12139 \begin_layout Verse
12140
12141 \family typewriter
12142 __code char test_array[] = {'c','h','e','a','p'}; 
12143 \end_layout
12144
12145 \begin_layout Standard
12146 Read access to this array using an 8-bit unsigned index generates the assembly
12147  code:
12148 \end_layout
12149
12150 \begin_layout Verse
12151
12152 \family typewriter
12153 E5*00\InsetSpace ~
12154 \InsetSpace ~
12155 \InsetSpace ~
12156 \InsetSpace ~
12157 \InsetSpace ~
12158 \InsetSpace ~
12159 mov a,_index 
12160 \end_layout
12161
12162 \begin_layout Verse
12163
12164 \family typewriter
12165 90s00r41\InsetSpace ~
12166 \InsetSpace ~
12167 \InsetSpace ~
12168 mov dptr,#_test_array
12169 \end_layout
12170
12171 \begin_layout Verse
12172
12173 \family typewriter
12174 93\InsetSpace ~
12175 \InsetSpace ~
12176 \InsetSpace ~
12177 \InsetSpace ~
12178 \InsetSpace ~
12179 \InsetSpace ~
12180 \InsetSpace ~
12181 \InsetSpace ~
12182 \InsetSpace ~
12183 movc a,@a+dptr 
12184 \end_layout
12185
12186 \begin_layout Subsubsection
12187 bit
12188 \begin_inset LatexCommand \index{bit}
12189
12190 \end_inset
12191
12192
12193 \begin_inset LatexCommand \index{\_\_bit}
12194
12195 \end_inset
12196
12197
12198 \end_layout
12199
12200 \begin_layout Standard
12201 This is a data-type and a storage class specifier.
12202  When a variable is declared as a bit, it is allocated into the bit addressable
12203  memory of 8051, e.g.:
12204 \end_layout
12205
12206 \begin_layout Verse
12207
12208 \family typewriter
12209 __bit test_bit;
12210 \end_layout
12211
12212 \begin_layout Standard
12213 Writing 1 to this variable generates the assembly code:
12214 \end_layout
12215
12216 \begin_layout Verse
12217
12218 \family typewriter
12219 D2*00\InsetSpace ~
12220 \InsetSpace ~
12221 \InsetSpace ~
12222 \InsetSpace ~
12223 \InsetSpace ~
12224 \InsetSpace ~
12225 \InsetSpace ~
12226 setb\InsetSpace ~
12227 _test_bit
12228 \end_layout
12229
12230 \begin_layout Standard
12231 The bit addressable memory consists of 128 bits which are located from 0x20
12232  to 0x2f in data memory.
12233  
12234 \newline
12235 Apart from this 8051 specific storage class most architectures support
12236  ANSI-C bitfields
12237 \begin_inset LatexCommand \index{bitfields}
12238
12239 \end_inset
12240
12241
12242 \begin_inset Foot
12243 status open
12244
12245 \begin_layout Standard
12246 Not really meant as examples, but nevertheless showing what bitfields are
12247  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12248 \end_layout
12249
12250 \end_inset
12251
12252 .
12253  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12254  signed modifier are implemented as unsigned.
12255 \end_layout
12256
12257 \begin_layout Subsubsection
12258 sfr
12259 \begin_inset LatexCommand \index{sfr}
12260
12261 \end_inset
12262
12263
12264 \begin_inset LatexCommand \index{\_\_sfr}
12265
12266 \end_inset
12267
12268  / sfr16
12269 \begin_inset LatexCommand \index{sfr16}
12270
12271 \end_inset
12272
12273
12274 \begin_inset LatexCommand \index{\_\_sfr16}
12275
12276 \end_inset
12277
12278  / sfr32
12279 \begin_inset LatexCommand \index{sfr32}
12280
12281 \end_inset
12282
12283
12284 \begin_inset LatexCommand \index{\_\_sfr32}
12285
12286 \end_inset
12287
12288  / sbit
12289 \begin_inset LatexCommand \index{\_\_sbit}
12290
12291 \end_inset
12292
12293
12294 \begin_inset LatexCommand \index{sbit}
12295
12296 \end_inset
12297
12298
12299 \end_layout
12300
12301 \begin_layout Standard
12302 Like the bit keyword, 
12303 \emph on
12304 sfr / sfr16 / sfr32 / sbit 
12305 \emph default
12306 signify both a data-type and storage class, they are used to describe the
12307  
12308 \emph on
12309 s
12310 \emph default
12311 pecial 
12312 \emph on
12313 f
12314 \emph default
12315 unction 
12316 \emph on
12317 r
12318 \emph default
12319 egisters and 
12320 \emph on
12321 s
12322 \emph default
12323 pecial 
12324 \emph on
12325 bit
12326 \emph default
12327  variables of a 8051, eg:
12328 \end_layout
12329
12330 \begin_layout Verse
12331
12332 \family typewriter
12333 __sfr __at
12334 \begin_inset LatexCommand \index{at}
12335
12336 \end_inset
12337
12338
12339 \begin_inset LatexCommand \index{\_\_at}
12340
12341 \end_inset
12342
12343  (0x80) P0;\InsetSpace ~
12344  /* special function register P0 at location 0x80 */
12345 \newline
12346
12347 \newline
12348 /* 16 bit
12349  special function register combination for timer 0
12350 \newline
12351 \InsetSpace ~
12352 \InsetSpace ~
12353  with the high byte at
12354  location 0x8C and the low byte at location 0x8A */
12355 \newline
12356 __sfr16 __at (0x8C8A)
12357  TMR0;
12358 \newline
12359
12360 \newline
12361 __sbit __at
12362 \begin_inset LatexCommand \index{at}
12363
12364 \end_inset
12365
12366
12367 \begin_inset LatexCommand \index{\_\_at}
12368
12369 \end_inset
12370
12371  (0xd7) CY;\InsetSpace ~
12372  /* CY (Carry Flag
12373 \begin_inset LatexCommand \index{Flags}
12374
12375 \end_inset
12376
12377
12378 \begin_inset LatexCommand \index{Carry flag}
12379
12380 \end_inset
12381
12382 ) */
12383 \end_layout
12384
12385 \begin_layout Standard
12386 Special function registers which are located on an address dividable by
12387  8 are bit-addressable, an
12388 \emph on
12389  sbit
12390 \emph default
12391  addresses a specific bit within these sfr.
12392 \newline
12393 16 Bit and 32 bit special function
12394  register combinations which require a certain access order are better not
12395  declared using 
12396 \emph on
12397 sfr16
12398 \emph default
12399  or 
12400 \emph on
12401 sfr32.
12402
12403 \emph default
12404  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12405  this is not guaranteed.
12406 \newline
12407
12408 \end_layout
12409
12410 \begin_layout Standard
12411 Please note, if you use a header file which was written for another compiler
12412  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12413  likely be 
12414 \emph on
12415 not 
12416 \emph default
12417 compatible.
12418  Specifically the syntax 
12419 \family typewriter
12420 \InsetSpace ~
12421 sfr P0 = 0x80;\InsetSpace ~
12422
12423 \family default
12424  is compiled 
12425 \emph on
12426 without warning
12427 \emph default
12428  by SDCC to an assignment of 0x80 to a variable called P0 
12429 \family typewriter
12430
12431 \begin_inset Marginal
12432 status collapsed
12433
12434 \begin_layout Standard
12435
12436 \series bold
12437 \InsetSpace ~
12438 !
12439 \end_layout
12440
12441 \end_inset
12442
12443 .
12444  
12445 \family default
12446 Nevertheless it is possible to write header files
12447 \begin_inset LatexCommand \index{Header files}
12448
12449 \end_inset
12450
12451
12452 \begin_inset LatexCommand \index{Include files}
12453
12454 \end_inset
12455
12456  which can be shared among different compilers (see section 
12457 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12458
12459 \end_inset
12460
12461 ).
12462  
12463 \end_layout
12464
12465 \begin_layout Subsubsection
12466 Pointers
12467 \begin_inset LatexCommand \index{Pointer}
12468
12469 \end_inset
12470
12471  to MCS51/DS390 specific memory spaces
12472 \end_layout
12473
12474 \begin_layout Standard
12475 SDCC allows (via language extensions) pointers to explicitly point to any
12476  of the memory spaces
12477 \begin_inset LatexCommand \index{Memory model}
12478
12479 \end_inset
12480
12481  of the 8051.
12482  In addition to the explicit pointers, the compiler uses (by default) generic
12483  pointers which can be used to point to any of the memory spaces.
12484 \newline
12485
12486 \newline
12487 Pointer
12488  declaration examples:
12489 \end_layout
12490
12491 \begin_layout Verse
12492
12493 \family typewriter
12494 /* pointer physically in internal ram pointing to object in external ram
12495  */ 
12496 \newline
12497 __xdata unsigned char * __data p;
12498 \newline
12499
12500 \newline
12501 /* pointer physically in external ram
12502  pointing to object in internal ram */ 
12503 \newline
12504 __data unsigned char * __xdata p;
12505 \newline
12506
12507 \newline
12508 /*
12509  pointer physically in code rom pointing to data in xdata space */ 
12510 \newline
12511 __xdata
12512  unsigned char * __code p;
12513 \newline
12514
12515 \newline
12516 /* pointer physically in code space pointing to
12517  data in code space */ 
12518 \newline
12519 __code unsigned char * __code p;
12520 \newline
12521
12522 \newline
12523 /* generic pointer
12524  physically located in xdata space */
12525 \newline
12526 unsigned char * __xdata p;
12527 \newline
12528
12529 \newline
12530 /* generic
12531  pointer physically located in default memory space */
12532 \newline
12533 unsigned char * p;
12534 \newline
12535
12536 \newline
12537 /*
12538  the following is a function pointer
12539 \begin_inset LatexCommand \index{function pointer}
12540
12541 \end_inset
12542
12543  physically located in data space */
12544 \newline
12545 char (* __data fp)(void);
12546 \end_layout
12547
12548 \begin_layout Standard
12549 Well you get the idea.
12550  
12551 \newline
12552
12553 \newline
12554 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12555 \emph on
12556 generic
12557 \emph default
12558  pointers.
12559  
12560 \size small
12561
12562 \newline
12563
12564 \newline
12565
12566 \size default
12567 The highest order byte of the 
12568 \emph on
12569 generic
12570 \emph default
12571  pointers contains the data space information.
12572  Assembler support routines are called whenever data is stored or retrieved
12573  using 
12574 \emph on
12575 generic
12576 \emph default
12577  pointers.
12578  These are useful for developing reusable library
12579 \begin_inset LatexCommand \index{Libraries}
12580
12581 \end_inset
12582
12583  routines.
12584  Explicitly specifying the pointer
12585 \begin_inset LatexCommand \index{pointer}
12586
12587 \end_inset
12588
12589  type will generate the most efficient code.
12590 \end_layout
12591
12592 \begin_layout Subsubsection
12593 Notes on MCS51 memory
12594 \begin_inset LatexCommand \index{MCS51 memory}
12595
12596 \end_inset
12597
12598  layout
12599 \end_layout
12600
12601 \begin_layout Standard
12602 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12603  RAM memory which is structured as follows:
12604 \newline
12605
12606 \newline
12607 - Bytes 00-1F - 32 bytes to hold
12608  up to 4 banks of the registers R0 to R7, 
12609 \newline
12610 - Bytes 20-2F - 16 bytes to hold
12611  128 bit
12612 \begin_inset LatexCommand \index{bit}
12613
12614 \end_inset
12615
12616  variables and, 
12617 \newline
12618 - Bytes 30-7F - 80 bytes for general purpose use.
12619 \newline
12620
12621 \end_layout
12622
12623 \begin_layout Standard
12624 Additionally some members of the MCS51 family may have up to 128 bytes of
12625  additional, indirectly addressable, internal RAM memory (
12626 \emph on
12627 idata
12628 \emph default
12629
12630 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12631
12632 \end_inset
12633
12634
12635 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12636
12637 \end_inset
12638
12639 ).
12640  Furthermore, some chips may have some built in external memory (
12641 \emph on
12642 xdata
12643 \emph default
12644
12645 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12646
12647 \end_inset
12648
12649
12650 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12651
12652 \end_inset
12653
12654 ) which should not be confused with the internal, directly addressable RAM
12655  memory (
12656 \emph on
12657 data
12658 \emph default
12659
12660 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12661
12662 \end_inset
12663
12664
12665 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12666
12667 \end_inset
12668
12669 ).
12670  Sometimes this built in 
12671 \emph on
12672 xdata
12673 \emph default
12674  memory has to be activated before using it (you can probably find this
12675  information on the datasheet of the microcontroller your are using, see
12676  also section 
12677 \begin_inset LatexCommand \ref{sub:Startup-Code}
12678
12679 \end_inset
12680
12681 \InsetSpace ~
12682 Startup-Code).
12683 \end_layout
12684
12685 \begin_layout Standard
12686 Normally SDCC will only use the first bank
12687 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12688
12689 \end_inset
12690
12691  of registers (register bank 0), but it is possible to specify that other
12692  banks of registers (keyword 
12693 \emph on
12694 using
12695 \emph default
12696  
12697 \emph on
12698
12699 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12700
12701 \end_inset
12702
12703
12704 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12705
12706 \end_inset
12707
12708
12709 \emph default
12710 ) should be used for example in interrupt
12711 \begin_inset LatexCommand \index{interrupt}
12712
12713 \end_inset
12714
12715
12716 \begin_inset LatexCommand \index{\_\_interrupt}
12717
12718 \end_inset
12719
12720  routines.
12721  By default, the compiler will place the stack after the last byte of allocated
12722  memory for variables.
12723  For example, if the first 2 banks of registers are used, and only four
12724  bytes are used for 
12725 \emph on
12726 data
12727 \emph default
12728  variables, it will position the base of the internal stack at address 20
12729  (0x14).
12730  This implies that as the stack
12731 \begin_inset LatexCommand \index{stack}
12732
12733 \end_inset
12734
12735  grows, it will use up the remaining register banks, and the 16 bytes used
12736  by the 128 bit variables, and 80 bytes for general purpose use.
12737  If any bit variables are used, the data variables will be placed in unused
12738  register banks and after the byte holding the last bit variable.
12739  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12740  (two bytes used), 
12741 \emph on
12742 data
12743 \emph default
12744  variables will be placed starting from address 0x10 to 0x20 and continue
12745  at address 0x22.
12746  You can also use -
12747 \begin_inset ERT
12748 status collapsed
12749
12750 \begin_layout Standard
12751
12752
12753 \backslash
12754 /
12755 \end_layout
12756
12757 \end_inset
12758
12759 -data-loc
12760 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12761
12762 \end_inset
12763
12764  to specify the start address of the 
12765 \emph on
12766 data
12767 \emph default
12768  and -
12769 \begin_inset ERT
12770 status collapsed
12771
12772 \begin_layout Standard
12773
12774
12775 \backslash
12776 /
12777 \end_layout
12778
12779 \end_inset
12780
12781 -iram-size
12782 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12783
12784 \end_inset
12785
12786  to specify the size of the total internal RAM (
12787 \emph on
12788 data
12789 \emph default
12790 +
12791 \emph on
12792 idata
12793 \emph default
12794 ).
12795  
12796 \newline
12797
12798 \end_layout
12799
12800 \begin_layout Standard
12801 By default the 8051 linker will place the stack after the last byte of (i)data
12802  variables.
12803  Option -
12804 \begin_inset ERT
12805 status collapsed
12806
12807 \begin_layout Standard
12808
12809
12810 \backslash
12811 /
12812 \end_layout
12813
12814 \end_inset
12815
12816 -stack-loc
12817 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12818
12819 \end_inset
12820
12821  allows you to specify the start of the stack, i.e.
12822  you could start it after any data in the general purpose area.
12823  If your microcontroller has additional indirectly addressable internal
12824  RAM (
12825 \emph on
12826 idata
12827 \emph default
12828 ) you can place the stack on it.
12829  You may also need to use -
12830 \begin_inset ERT
12831 status collapsed
12832
12833 \begin_layout Standard
12834
12835
12836 \backslash
12837 /
12838 \end_layout
12839
12840 \end_inset
12841
12842 -xdata-loc
12843 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12844
12845 \end_inset
12846
12847  to set the start address of the external RAM (
12848 \emph on
12849 xdata
12850 \emph default
12851 ) and -
12852 \begin_inset ERT
12853 status collapsed
12854
12855 \begin_layout Standard
12856
12857
12858 \backslash
12859 /
12860 \end_layout
12861
12862 \end_inset
12863
12864 -xram-size
12865 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12866
12867 \end_inset
12868
12869  to specify its size.
12870  Same goes for the code memory, using -
12871 \begin_inset ERT
12872 status collapsed
12873
12874 \begin_layout Standard
12875
12876
12877 \backslash
12878 /
12879 \end_layout
12880
12881 \end_inset
12882
12883 -code-loc
12884 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12885
12886 \end_inset
12887
12888  and -
12889 \begin_inset ERT
12890 status collapsed
12891
12892 \begin_layout Standard
12893
12894
12895 \backslash
12896 /
12897 \end_layout
12898
12899 \end_inset
12900
12901 -code-size
12902 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12903
12904 \end_inset
12905
12906 .
12907  If in doubt, don't specify any options and see if the resulting memory
12908  layout is appropriate, then you can adjust it.
12909 \end_layout
12910
12911 \begin_layout Standard
12912 The linker generates two files with memory allocation information.
12913  The first, with extension .map
12914 \begin_inset LatexCommand \index{<file>.map}
12915
12916 \end_inset
12917
12918  shows all the variables and segments.
12919  The second with extension .mem
12920 \begin_inset LatexCommand \index{<file>.mem}
12921
12922 \end_inset
12923
12924  shows the final memory layout.
12925  The linker will complain either if memory segments overlap, there is not
12926  enough memory, or there is not enough space for stack.
12927  If you get any linking warnings and/or errors related to stack or segments
12928  allocation, take a look at either the .map or .mem files to find out what
12929  the problem is.
12930  The .mem file may even suggest a solution to the problem.
12931 \begin_inset VSpace bigskip
12932 \end_inset
12933
12934
12935 \end_layout
12936
12937 \begin_layout Subsection
12938 Z80/Z180 Storage Class
12939 \begin_inset LatexCommand \index{Z80!Storage class}
12940
12941 \end_inset
12942
12943  Language Extensions
12944 \end_layout
12945
12946 \begin_layout Subsubsection
12947 sfr
12948 \begin_inset LatexCommand \index{sfr}
12949
12950 \end_inset
12951
12952
12953 \begin_inset LatexCommand \index{\_\_sfr}
12954
12955 \end_inset
12956
12957  (in/out to 8-bit addresses)
12958 \end_layout
12959
12960 \begin_layout Standard
12961 The Z80
12962 \begin_inset LatexCommand \index{Z80}
12963
12964 \end_inset
12965
12966  family has separate address spaces for memory and 
12967 \emph on
12968 i
12969 \emph default
12970 nput/
12971 \emph on
12972 o
12973 \emph default
12974 utput memory.
12975  I/O memory
12976 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12977
12978 \end_inset
12979
12980
12981 \begin_inset LatexCommand \index{Z80!I/O memory}
12982
12983 \end_inset
12984
12985
12986 \begin_inset LatexCommand \index{Z180!I/O memory}
12987
12988 \end_inset
12989
12990  is accessed with special instructions, e.g.:
12991 \end_layout
12992
12993 \begin_layout Verse
12994
12995 \family typewriter
12996 sfr at 0x78 IoPort;\InsetSpace ~
12997 \InsetSpace ~
12998 /* define a var in I/O space at 78h called IoPort */
12999  
13000 \end_layout
13001
13002 \begin_layout Standard
13003 Writing 0x01 to this variable generates the assembly code:
13004 \end_layout
13005
13006 \begin_layout Verse
13007
13008 \family typewriter
13009 3E 01\InsetSpace ~
13010 \InsetSpace ~
13011 \InsetSpace ~
13012 \InsetSpace ~
13013 \InsetSpace ~
13014 \InsetSpace ~
13015 ld a,#0x01
13016 \newline
13017 D3 78\InsetSpace ~
13018 \InsetSpace ~
13019 \InsetSpace ~
13020 \InsetSpace ~
13021 \InsetSpace ~
13022 \InsetSpace ~
13023 out (_IoPort),a 
13024 \end_layout
13025
13026 \begin_layout Subsubsection
13027 banked sfr
13028 \begin_inset LatexCommand \index{sfr}
13029
13030 \end_inset
13031
13032
13033 \begin_inset LatexCommand \index{\_\_sfr}
13034
13035 \end_inset
13036
13037  (in/out to 16-bit addresses)
13038 \end_layout
13039
13040 \begin_layout Standard
13041 The keyword 
13042 \emph on
13043 banked
13044 \emph default
13045  is used to support 16 bit addresses in I/O memory e.g.:
13046 \end_layout
13047
13048 \begin_layout Verse
13049
13050 \family typewriter
13051 sfr banked at
13052 \begin_inset LatexCommand \index{at}
13053
13054 \end_inset
13055
13056
13057 \begin_inset LatexCommand \index{\_\_at}
13058
13059 \end_inset
13060
13061  0x123 IoPort; 
13062 \end_layout
13063
13064 \begin_layout Standard
13065 Writing 0x01 to this variable generates the assembly code:
13066 \end_layout
13067
13068 \begin_layout Verse
13069
13070 \family typewriter
13071 01 23 01\InsetSpace ~
13072 \InsetSpace ~
13073 \InsetSpace ~
13074 ld bc,#_IoPort
13075 \newline
13076 3E 01\InsetSpace ~
13077 \InsetSpace ~
13078 \InsetSpace ~
13079 \InsetSpace ~
13080 \InsetSpace ~
13081 \InsetSpace ~
13082 ld a,#0x01 
13083 \newline
13084 ED 79\InsetSpace ~
13085 \InsetSpace ~
13086 \InsetSpace ~
13087 \InsetSpace ~
13088 \InsetSpace ~
13089 \InsetSpace ~
13090 out (c),a 
13091 \end_layout
13092
13093 \begin_layout Subsubsection
13094 sfr
13095 \begin_inset LatexCommand \index{sfr}
13096
13097 \end_inset
13098
13099
13100 \begin_inset LatexCommand \index{\_\_sfr}
13101
13102 \end_inset
13103
13104  (in0/out0 to 8 bit addresses on Z180
13105 \begin_inset LatexCommand \index{Z180}
13106
13107 \end_inset
13108
13109 /HD64180
13110 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13111
13112 \end_inset
13113
13114 )
13115 \end_layout
13116
13117 \begin_layout Standard
13118 The compiler option -
13119 \begin_inset ERT
13120 status collapsed
13121
13122 \begin_layout Standard
13123
13124
13125 \backslash
13126 /
13127 \end_layout
13128
13129 \end_inset
13130
13131 -portmode
13132 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13133
13134 \end_inset
13135
13136 =180 (80) and a compiler #pragma\InsetSpace ~
13137 portmode
13138 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13139
13140 \end_inset
13141
13142  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13143 ns 
13144 \family typewriter
13145 in0/out0
13146 \family default
13147  instead of 
13148 \family typewriter
13149 in/out
13150 \family default
13151 .
13152  If you include the file z180.h this will be set automatically.
13153 \begin_inset VSpace bigskip
13154 \end_inset
13155
13156
13157 \end_layout
13158
13159 \begin_layout Subsection
13160 HC08 Storage Class
13161 \begin_inset LatexCommand \index{HC08!Storage class}
13162
13163 \end_inset
13164
13165  Language Extensions
13166 \end_layout
13167
13168 \begin_layout Subsubsection
13169 data
13170 \begin_inset LatexCommand \index{data (hc08 storage class)}
13171
13172 \end_inset
13173
13174
13175 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13176
13177 \end_inset
13178
13179  
13180 \end_layout
13181
13182 \begin_layout Standard
13183 The data storage class declares a variable that resides in the first 256
13184  bytes of memory (the direct page).
13185  The HC08
13186 \begin_inset LatexCommand \index{HC08}
13187
13188 \end_inset
13189
13190  is most efficient at accessing variables (especially pointers) stored here.
13191 \end_layout
13192
13193 \begin_layout Subsubsection
13194 xdata
13195 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13196
13197 \end_inset
13198
13199
13200 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13201
13202 \end_inset
13203
13204  
13205 \end_layout
13206
13207 \begin_layout Standard
13208 The xdata storage class declares a variable that can reside anywhere in
13209  memory.
13210  This is the default if no storage class is specified.
13211  
13212 \begin_inset VSpace bigskip
13213 \end_inset
13214
13215
13216 \end_layout
13217
13218 \begin_layout Section
13219 Absolute Addressing
13220 \begin_inset LatexCommand \index{Absolute addressing}
13221
13222 \end_inset
13223
13224
13225 \end_layout
13226
13227 \begin_layout Standard
13228 Data items can be assigned an absolute address with the 
13229 \emph on
13230 at
13231 \begin_inset LatexCommand \index{at}
13232
13233 \end_inset
13234
13235
13236 \begin_inset LatexCommand \index{\_\_at}
13237
13238 \end_inset
13239
13240  <address>
13241 \emph default
13242  keyword, in addition to a storage class, e.g.:
13243 \end_layout
13244
13245 \begin_layout Verse
13246
13247 \family typewriter
13248 xdata
13249 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13250
13251 \end_inset
13252
13253
13254 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13255
13256 \end_inset
13257
13258  at
13259 \begin_inset LatexCommand \index{at}
13260
13261 \end_inset
13262
13263
13264 \begin_inset LatexCommand \index{\_\_at}
13265
13266 \end_inset
13267
13268  0x7ffe unsigned int chksum;
13269 \end_layout
13270
13271 \begin_layout Standard
13272 or, better conforming to ISO/IEC 9899 C:
13273 \end_layout
13274
13275 \begin_layout Verse
13276
13277 \family typewriter
13278 __xdata __at (0x7ffe) unsigned int chksum;
13279 \end_layout
13280
13281 \begin_layout Standard
13282 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13283  of the external ram.
13284  The compiler does 
13285 \emph on
13286 not
13287 \emph default
13288  reserve any space for variables declared in this way
13289 \begin_inset Marginal
13290 status collapsed
13291
13292 \begin_layout Standard
13293
13294 \series bold
13295 \InsetSpace ~
13296 !
13297 \end_layout
13298
13299 \end_inset
13300
13301  (they are implemented with an equate in the assembler).
13302  Thus it is left to the programmer to make sure there are no overlaps with
13303  other variables that are declared without the absolute address.
13304  The assembler listing file (.lst
13305 \begin_inset LatexCommand \index{<file>.lst}
13306
13307 \end_inset
13308
13309 ) and the linker output files (.rst
13310 \begin_inset LatexCommand \index{<file>.rst}
13311
13312 \end_inset
13313
13314 ) and (.map
13315 \begin_inset LatexCommand \index{<file>.map}
13316
13317 \end_inset
13318
13319 ) are good places to look for such overlaps.
13320 \end_layout
13321
13322 \begin_layout Standard
13323 If however you provide an initializer
13324 \begin_inset LatexCommand \index{Variable initialization}
13325
13326 \end_inset
13327
13328  actual memory allocation will take place and overlaps will be detected
13329  by the linker.
13330  E.g.:
13331 \end_layout
13332
13333 \begin_layout Verse
13334
13335 \family typewriter
13336 __code __at (0x7ff0) char Id[5] = 
13337 \begin_inset Quotes sld
13338 \end_inset
13339
13340 SDCC
13341 \begin_inset Quotes srd
13342 \end_inset
13343
13344 ;
13345 \end_layout
13346
13347 \begin_layout Standard
13348 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13349  in code memory.
13350 \end_layout
13351
13352 \begin_layout Standard
13353 In case of memory mapped I/O devices the keyword 
13354 \emph on
13355 volatile
13356 \emph default
13357  has to be used to tell the compiler that accesses might not be removed:
13358 \end_layout
13359
13360 \begin_layout Verse
13361
13362 \family typewriter
13363 volatile
13364 \begin_inset LatexCommand \index{volatile}
13365
13366 \end_inset
13367
13368  __xdata
13369 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13370
13371 \end_inset
13372
13373  __at
13374 \begin_inset LatexCommand \index{at}
13375
13376 \end_inset
13377
13378  (0x8000) unsigned char PORTA_8255;
13379 \end_layout
13380
13381 \begin_layout Standard
13382 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13383 r) array
13384 \family typewriter
13385 \size footnotesize
13386
13387 \begin_inset LatexCommand \index{Aligned array}
13388
13389 \end_inset
13390
13391
13392 \family default
13393 \size default
13394  starts at a block (256 byte) boundary
13395 \begin_inset LatexCommand \index{block boundary}
13396
13397 \end_inset
13398
13399  (section 
13400 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13401
13402 \end_inset
13403
13404  has an example).
13405 \newline
13406 Absolute addresses can be specified for variables in all
13407  storage classes, e.g.:
13408 \end_layout
13409
13410 \begin_layout Verse
13411
13412 \family typewriter
13413 __bit
13414 \begin_inset LatexCommand \index{bit}
13415
13416 \end_inset
13417
13418  __at
13419 \begin_inset LatexCommand \index{at}
13420
13421 \end_inset
13422
13423  (0x02) bvar;
13424 \end_layout
13425
13426 \begin_layout Standard
13427 The above example will allocate the variable at offset 0x02 in the bit-addressab
13428 le space.
13429  There is no real advantage to assigning absolute addresses to variables
13430  in this manner, unless you want strict control over all the variables allocated.
13431  One possible use would be to write hardware portable code.
13432  For example, if you have a routine that uses one or more of the microcontroller
13433  I/O pins, and such pins are different for two different hardwares, you
13434  can declare the I/O pins in your routine using:
13435 \end_layout
13436
13437 \begin_layout Verse
13438
13439 \family typewriter
13440 extern volatile
13441 \begin_inset LatexCommand \index{volatile}
13442
13443 \end_inset
13444
13445  __bit MOSI;\InsetSpace ~
13446 \InsetSpace ~
13447 \InsetSpace ~
13448 \InsetSpace ~
13449 /* master out, slave in */
13450 \newline
13451 extern volatile __bit MISO;\InsetSpace ~
13452 \InsetSpace ~
13453 \InsetSpace ~
13454 \InsetSpace ~
13455 /* master
13456  in, slave out */
13457 \newline
13458 extern volatile __bit MCLK;\InsetSpace ~
13459 \InsetSpace ~
13460 \InsetSpace ~
13461 \InsetSpace ~
13462 /* master clock */
13463 \newline
13464
13465 \newline
13466 /* Input and
13467  Output of a byte on a 3-wire serial bus.
13468 \newline
13469 \InsetSpace ~
13470 \InsetSpace ~
13471 \InsetSpace ~
13472 If needed adapt polarity of clock,
13473  polarity of data and bit order
13474 \newline
13475 \InsetSpace ~
13476 */
13477 \newline
13478 unsigned char spi_io(unsigned char out_byte)
13479  
13480 \newline
13481
13482 \newline
13483 \InsetSpace ~
13484 \InsetSpace ~
13485 \InsetSpace ~
13486 \InsetSpace ~
13487 unsigned char i=8;
13488 \newline
13489 \InsetSpace ~
13490 \InsetSpace ~
13491 \InsetSpace ~
13492 \InsetSpace ~
13493 do { 
13494 \newline
13495 \InsetSpace ~
13496 \InsetSpace ~
13497 \InsetSpace ~
13498 \InsetSpace ~
13499 \InsetSpace ~
13500 \InsetSpace ~
13501 \InsetSpace ~
13502 \InsetSpace ~
13503 MOSI = out_byte & 0x80; 
13504 \newline
13505 \InsetSpace ~
13506 \InsetSpace ~
13507 \InsetSpace ~
13508 \InsetSpace ~
13509 \InsetSpace ~
13510 \InsetSpace ~
13511 \InsetSpace ~
13512 \InsetSpace ~
13513 out_byte <<= 1;
13514 \newline
13515 \InsetSpace ~
13516 \InsetSpace ~
13517 \InsetSpace ~
13518 \InsetSpace ~
13519 \InsetSpace ~
13520 \InsetSpace ~
13521 \InsetSpace ~
13522 \InsetSpace ~
13523 MCLK =
13524  1; 
13525 \newline
13526 \InsetSpace ~
13527 \InsetSpace ~
13528 \InsetSpace ~
13529 \InsetSpace ~
13530 \InsetSpace ~
13531 \InsetSpace ~
13532 \InsetSpace ~
13533 \InsetSpace ~
13534 /* _asm nop _endasm; */\InsetSpace ~
13535 \InsetSpace ~
13536 \InsetSpace ~
13537 \InsetSpace ~
13538 \InsetSpace ~
13539 \InsetSpace ~
13540 \InsetSpace ~
13541 \InsetSpace ~
13542 /* for slow peripherals */
13543 \newline
13544 \InsetSpace ~
13545 \InsetSpace ~
13546 \InsetSpace ~
13547 \InsetSpace ~
13548 \InsetSpace ~
13549 \InsetSpace ~
13550 \InsetSpace ~
13551 \InsetSpace ~
13552 if(MISO) 
13553 \newline
13554 \InsetSpace ~
13555 \InsetSpace ~
13556 \InsetSpace ~
13557 \InsetSpace ~
13558 \InsetSpace ~
13559 \InsetSpace ~
13560 \InsetSpace ~
13561 \InsetSpace ~
13562 \InsetSpace ~
13563 \InsetSpace ~
13564 \InsetSpace ~
13565 \InsetSpace ~
13566 out_byte +=
13567  1; 
13568 \newline
13569 \InsetSpace ~
13570 \InsetSpace ~
13571 \InsetSpace ~
13572 \InsetSpace ~
13573 \InsetSpace ~
13574 \InsetSpace ~
13575 \InsetSpace ~
13576 \InsetSpace ~
13577 MCLK = 0; 
13578 \newline
13579 \InsetSpace ~
13580 \InsetSpace ~
13581 \InsetSpace ~
13582 \InsetSpace ~
13583 } while(--i);
13584 \newline
13585 \InsetSpace ~
13586 \InsetSpace ~
13587 \InsetSpace ~
13588 \InsetSpace ~
13589 return out_byte; 
13590 \newline
13591 }
13592 \end_layout
13593
13594 \begin_layout Standard
13595 Then, someplace in the code for the first hardware you would use
13596 \end_layout
13597
13598 \begin_layout Verse
13599
13600 \family typewriter
13601 __bit __at
13602 \begin_inset LatexCommand \index{at}
13603
13604 \end_inset
13605
13606
13607 \begin_inset LatexCommand \index{\_\_at}
13608
13609 \end_inset
13610
13611  (0x80) MOSI;\InsetSpace ~
13612 \InsetSpace ~
13613 \InsetSpace ~
13614 \InsetSpace ~
13615 /* I/O port 0, bit 0 */
13616 \newline
13617 __bit __at (0x81) MISO;\InsetSpace ~
13618 \InsetSpace ~
13619 \InsetSpace ~
13620 \InsetSpace ~
13621 /* I/O port 0,
13622  bit 1 */
13623 \newline
13624 __bit __at (0x82) MCLK;\InsetSpace ~
13625 \InsetSpace ~
13626 \InsetSpace ~
13627 \InsetSpace ~
13628 /* I/O port 0, bit 2 */
13629 \end_layout
13630
13631 \begin_layout Standard
13632 Similarly, for the second hardware you would use
13633 \end_layout
13634
13635 \begin_layout Verse
13636
13637 \family typewriter
13638 __bit __at (0x83) MOSI;\InsetSpace ~
13639 \InsetSpace ~
13640 \InsetSpace ~
13641 \InsetSpace ~
13642 /* I/O port 0, bit 3 */
13643 \newline
13644 __bit __at (0x91) MISO;\InsetSpace ~
13645 \InsetSpace ~
13646 \InsetSpace ~
13647 \InsetSpace ~
13648 /*
13649  I/O port 1, bit 1 */
13650 \newline
13651 __bit
13652 \begin_inset LatexCommand \index{bit}
13653
13654 \end_inset
13655
13656  __at (0x92) MCLK;\InsetSpace ~
13657 \InsetSpace ~
13658 \InsetSpace ~
13659 \InsetSpace ~
13660 /* I/O port 1, bit 2 */
13661 \end_layout
13662
13663 \begin_layout Standard
13664 and you can use the same hardware dependent routine without changes, as
13665  for example in a library.
13666  This is somehow similar to sbit, but only one absolute address has to be
13667  specified in the whole project.
13668 \begin_inset VSpace bigskip
13669 \end_inset
13670
13671
13672 \end_layout
13673
13674 \begin_layout Section
13675 Parameters
13676 \begin_inset LatexCommand \index{Parameters}
13677
13678 \end_inset
13679
13680
13681 \begin_inset LatexCommand \index{function parameter}
13682
13683 \end_inset
13684
13685  & Local Variables
13686 \begin_inset LatexCommand \index{local variables}
13687
13688 \end_inset
13689
13690
13691 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13692
13693 \end_inset
13694
13695
13696 \end_layout
13697
13698 \begin_layout Standard
13699 Automatic (local) variables and parameters to functions can either be placed
13700  on the stack or in data-space.
13701  The default action of the compiler is to place these variables in the internal
13702  RAM (for small model) or external RAM (for medium or large model).
13703  This in fact makes them similar to 
13704 \emph on
13705 static
13706 \begin_inset LatexCommand \index{static}
13707
13708 \end_inset
13709
13710
13711 \emph default
13712  so by default functions are non-reentrant
13713 \begin_inset LatexCommand \index{reentrant}
13714
13715 \end_inset
13716
13717 .
13718  
13719 \newline
13720
13721 \newline
13722 They can be placed on the stack
13723 \begin_inset LatexCommand \index{stack}
13724
13725 \end_inset
13726
13727  by using the
13728 \emph on
13729  -
13730 \begin_inset ERT
13731 status collapsed
13732
13733 \begin_layout Standard
13734
13735
13736 \backslash
13737 /
13738 \end_layout
13739
13740 \end_inset
13741
13742 -stack-auto
13743 \begin_inset LatexCommand \index{-\/-stack-auto}
13744
13745 \end_inset
13746
13747
13748 \emph default
13749  option, by using 
13750 \emph on
13751 #pragma\InsetSpace ~
13752 stackauto
13753 \emph default
13754
13755 \begin_inset LatexCommand \index{\#pragma stackauto}
13756
13757 \end_inset
13758
13759  or by using the 
13760 \emph on
13761 reentrant
13762 \begin_inset LatexCommand \index{reentrant}
13763
13764 \end_inset
13765
13766
13767 \emph default
13768  keyword in the function declaration, e.g.:
13769 \end_layout
13770
13771 \begin_layout Verse
13772
13773 \family typewriter
13774 unsigned char foo(char i) __reentrant 
13775 \newline
13776
13777 \newline
13778 \InsetSpace ~
13779 \InsetSpace ~
13780 \InsetSpace ~
13781 \InsetSpace ~
13782 ...
13783  
13784 \newline
13785 }
13786 \end_layout
13787
13788 \begin_layout Standard
13789 Since stack space on 8051 is limited, the 
13790 \emph on
13791 reentrant 
13792 \emph default
13793 keyword or the
13794 \emph on
13795  -
13796 \begin_inset ERT
13797 status collapsed
13798
13799 \begin_layout Standard
13800
13801
13802 \backslash
13803 /
13804 \end_layout
13805
13806 \end_inset
13807
13808 -stack-auto
13809 \emph default
13810  option should be used sparingly.
13811  Note that the reentrant keyword just means that the parameters & local
13812  variables will be allocated to the stack, it 
13813 \emph on
13814 does not
13815 \emph default
13816  mean that the function is register bank
13817 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13818
13819 \end_inset
13820
13821  independent.
13822 \newline
13823
13824 \newline
13825 Local variables
13826 \begin_inset LatexCommand \index{local variables}
13827
13828 \end_inset
13829
13830  can be assigned storage classes and absolute
13831 \begin_inset LatexCommand \index{Absolute addressing}
13832
13833 \end_inset
13834
13835  addresses, e.g.: 
13836 \end_layout
13837
13838 \begin_layout Verse
13839
13840 \family typewriter
13841 unsigned char foo() 
13842 \newline
13843 {
13844 \newline
13845 \InsetSpace ~
13846 \InsetSpace ~
13847 \InsetSpace ~
13848 \InsetSpace ~
13849 __xdata unsigned char i;
13850 \newline
13851 \InsetSpace ~
13852 \InsetSpace ~
13853 \InsetSpace ~
13854 \InsetSpace ~
13855 __bit bvar;
13856 \newline
13857 \InsetSpace ~
13858 \InsetSpace ~
13859 \InsetSpace ~
13860 \InsetSpace ~
13861 __data __at
13862 \begin_inset LatexCommand \index{at}
13863
13864 \end_inset
13865
13866  (0x31) unsigned char j;
13867 \newline
13868 \InsetSpace ~
13869 \InsetSpace ~
13870 \InsetSpace ~
13871 \InsetSpace ~
13872 ...
13873  
13874 \newline
13875 }
13876 \end_layout
13877
13878 \begin_layout Standard
13879 In the above example the variable 
13880 \emph on
13881 i
13882 \emph default
13883  will be allocated in the external ram, 
13884 \emph on
13885 bvar
13886 \emph default
13887  in bit addressable space and
13888 \emph on
13889  j
13890 \emph default
13891  in internal ram.
13892  When compiled with 
13893 \emph on
13894 -
13895 \begin_inset ERT
13896 status collapsed
13897
13898 \begin_layout Standard
13899
13900
13901 \backslash
13902 /
13903 \end_layout
13904
13905 \end_inset
13906
13907 -stack-auto
13908 \emph default
13909  or when a function is declared as 
13910 \emph on
13911 reentrant
13912 \emph default
13913  this should only be done for static variables.
13914 \end_layout
13915
13916 \begin_layout Standard
13917 Parameters
13918 \begin_inset LatexCommand \index{function parameter}
13919
13920 \end_inset
13921
13922  however are not allowed any storage class
13923 \begin_inset LatexCommand \index{Storage class}
13924
13925 \end_inset
13926
13927 , (storage classes for parameters will be ignored), their allocation is
13928  governed by the memory model in use, and the reentrancy options.
13929 \end_layout
13930
13931 \begin_layout Standard
13932 It is however allowed to use bit parameters in reentrant functions and also
13933  non-static local bit variables are supported.
13934  Efficient use is limited to 8 semi-bitregisters in bit space.
13935  They are pushed and popped to stack
13936 \begin_inset LatexCommand \index{stack}
13937
13938 \end_inset
13939
13940  as a single byte just like the normal registers.
13941 \end_layout
13942
13943 \begin_layout Section
13944 Overlaying
13945 \begin_inset LatexCommand \label{sub:Overlaying}
13946
13947 \end_inset
13948
13949
13950 \begin_inset LatexCommand \index{Overlaying}
13951
13952 \end_inset
13953
13954
13955 \end_layout
13956
13957 \begin_layout Standard
13958 For non-reentrant
13959 \begin_inset LatexCommand \index{reentrant}
13960
13961 \end_inset
13962
13963  functions SDCC will try to reduce internal ram space usage by overlaying
13964  parameters and local variables of a function (if possible).
13965  Parameters and local variables
13966 \begin_inset LatexCommand \index{local variables}
13967
13968 \end_inset
13969
13970  of a function will be allocated to an overlayable segment if the function
13971  has 
13972 \emph on
13973 no other function calls and the function is non-reentrant and the memory
13974  model
13975 \begin_inset LatexCommand \index{Memory model}
13976
13977 \end_inset
13978
13979  is small.
13980
13981 \emph default
13982  If an explicit storage class
13983 \begin_inset LatexCommand \index{Storage class}
13984
13985 \end_inset
13986
13987  is specified for a local variable, it will NOT be overlayed.
13988 \end_layout
13989
13990 \begin_layout Standard
13991 Note that the compiler (not the linkage editor) makes the decision for overlayin
13992 g the data items.
13993  Functions that are called from an interrupt service routine
13994 \begin_inset Marginal
13995 status collapsed
13996
13997 \begin_layout Standard
13998
13999 \series bold
14000 !
14001 \end_layout
14002
14003 \end_inset
14004
14005  should be preceded by a #pragma\InsetSpace ~
14006 nooverlay
14007 \begin_inset LatexCommand \index{\#pragma nooverlay}
14008
14009 \end_inset
14010
14011  if they are not reentrant.
14012 \end_layout
14013
14014 \begin_layout Standard
14015 Also note that the compiler does not do any processing of inline assembler
14016  code, so the compiler might incorrectly assign local variables and parameters
14017  of a function into the overlay segment if the inline assembler code calls
14018  other c-functions that might use the overlay.
14019  In that case the #pragma\InsetSpace ~
14020 nooverlay should be used.
14021 \end_layout
14022
14023 \begin_layout Standard
14024 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14025 tion
14026 \begin_inset LatexCommand \index{Multiplication}
14027
14028 \end_inset
14029
14030  or division
14031 \begin_inset LatexCommand \index{Division}
14032
14033 \end_inset
14034
14035  will NOT be overlayed since these are implemented using external functions,
14036  e.g.:
14037 \end_layout
14038
14039 \begin_layout Verse
14040
14041 \family typewriter
14042 #pragma save 
14043 \newline
14044 #pragma nooverlay
14045 \begin_inset LatexCommand \index{\#pragma nooverlay}
14046
14047 \end_inset
14048
14049  
14050 \newline
14051 void set_error(unsigned char errcd) 
14052 \newline
14053 {
14054 \newline
14055 \InsetSpace ~
14056 \InsetSpace ~
14057 \InsetSpace ~
14058 \InsetSpace ~
14059 P3 = errcd;
14060 \newline
14061
14062 \newline
14063 #pragma restore 
14064 \newline
14065
14066 \newline
14067 void
14068  some_isr () __interrupt
14069 \begin_inset LatexCommand \index{interrupt}
14070
14071 \end_inset
14072
14073  (2)
14074 \newline
14075 {
14076 \newline
14077 \InsetSpace ~
14078 \InsetSpace ~
14079 \InsetSpace ~
14080 \InsetSpace ~
14081 ...
14082 \newline
14083 \InsetSpace ~
14084 \InsetSpace ~
14085 \InsetSpace ~
14086 \InsetSpace ~
14087 set_error(10);
14088 \newline
14089 \InsetSpace ~
14090 \InsetSpace ~
14091 \InsetSpace ~
14092 \InsetSpace ~
14093 ...
14094  
14095 \newline
14096 }
14097 \end_layout
14098
14099 \begin_layout Standard
14100 In the above example the parameter 
14101 \emph on
14102 errcd
14103 \emph default
14104  for the function 
14105 \emph on
14106 set_error
14107 \emph default
14108  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14109 nooverlay was
14110  not present, this could cause unpredictable runtime behavior when called
14111  from an interrupt service routine.
14112  The #pragma\InsetSpace ~
14113 nooverlay ensures that the parameters and local variables for
14114  the function are NOT overlayed.
14115 \begin_inset VSpace bigskip
14116 \end_inset
14117
14118
14119 \end_layout
14120
14121 \begin_layout Section
14122 Interrupt Service Routines
14123 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14124
14125 \end_inset
14126
14127
14128 \end_layout
14129
14130 \begin_layout Subsection
14131 General Information
14132 \end_layout
14133
14134 \begin_layout Standard
14135 SDCC allows 
14136 \emph on
14137 i
14138 \emph default
14139 nterrupt 
14140 \emph on
14141 s
14142 \emph default
14143 ervice 
14144 \emph on
14145 r
14146 \emph default
14147 outines to be coded in C, with some extended keywords.
14148 \end_layout
14149
14150 \begin_layout Verse
14151
14152 \family typewriter
14153 void timer_isr (void) __interrupt (1) __using (1) 
14154 \newline
14155
14156 \newline
14157 \InsetSpace ~
14158 \InsetSpace ~
14159 \InsetSpace ~
14160 \InsetSpace ~
14161 ...
14162  
14163 \newline
14164 }
14165 \end_layout
14166
14167 \begin_layout Standard
14168 The optional number following the 
14169 \emph on
14170 interrupt
14171 \begin_inset LatexCommand \index{interrupt}
14172
14173 \end_inset
14174
14175
14176 \begin_inset LatexCommand \index{\_\_interrupt}
14177
14178 \end_inset
14179
14180
14181 \emph default
14182  keyword is the interrupt number this routine will service.
14183  When present, the compiler will insert a call to this routine in the interrupt
14184  vector table
14185 \begin_inset LatexCommand \index{interrupt vector table}
14186
14187 \end_inset
14188
14189  for the interrupt number specified.
14190  If you have multiple source files in your project, interrupt service routines
14191  can be present in any of them, but a prototype of the isr MUST be present
14192  or included in the file that contains the function 
14193 \emph on
14194 main
14195 \emph default
14196 .
14197  The optional (8051 specific) keyword 
14198 \emph on
14199 using
14200 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14201
14202 \end_inset
14203
14204
14205 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14206
14207 \end_inset
14208
14209
14210 \emph default
14211  can be used to tell the compiler to use the specified register bank when
14212  generating code for this function.
14213  
14214 \newline
14215 Interrupt service routines open the door for some very interesting bugs:
14216 \end_layout
14217
14218 \begin_layout Subsubsection
14219 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14220
14221 \end_inset
14222
14223 Common interrupt pitfall: variable not declared 
14224 \emph on
14225 volatile
14226 \end_layout
14227
14228 \begin_layout Standard
14229 If an interrupt service routine changes variables which are accessed by
14230  other functions these variables have to be declared 
14231 \emph on
14232 volatile
14233 \emph default
14234
14235 \begin_inset LatexCommand \index{volatile}
14236
14237 \end_inset
14238
14239 .
14240  See 
14241 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14242
14243 \end_inset
14244
14245  .
14246 \end_layout
14247
14248 \begin_layout Subsubsection
14249 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14250
14251 \end_inset
14252
14253 Common interrupt pitfall: 
14254 \emph on
14255 non-atomic access
14256 \end_layout
14257
14258 \begin_layout Standard
14259 If the access to these variables is not 
14260 \emph on
14261 atomic
14262 \begin_inset LatexCommand \index{atomic}
14263
14264 \end_inset
14265
14266
14267 \emph default
14268  (i.e.
14269  the processor needs more than one instruction for the access and could
14270  be interrupted while accessing the variable) the interrupt must be disabled
14271  during the access to avoid inconsistent data.
14272  
14273 \newline
14274 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14275  and should be protected by disabling interrupts.
14276  You're not automatically on the safe side if you use 8 bit variables though.
14277  We need an example here: f.e.
14278  on the 8051 the harmless looking 
14279 \begin_inset Quotes srd
14280 \end_inset
14281
14282
14283 \family typewriter
14284 flags\InsetSpace ~
14285 |=\InsetSpace ~
14286 0x80;
14287 \family default
14288
14289 \begin_inset Quotes sld
14290 \end_inset
14291
14292  is not atomic if 
14293 \family typewriter
14294 flags
14295 \family default
14296  resides in xdata.
14297  Setting 
14298 \begin_inset Quotes srd
14299 \end_inset
14300
14301
14302 \family typewriter
14303 flags\InsetSpace ~
14304 |=\InsetSpace ~
14305 0x40;
14306 \family default
14307
14308 \begin_inset Quotes sld
14309 \end_inset
14310
14311  from within an interrupt routine might get lost if the interrupt occurs
14312  at the wrong time.
14313  
14314 \begin_inset Quotes sld
14315 \end_inset
14316
14317
14318 \family typewriter
14319 counter\InsetSpace ~
14320 +=\InsetSpace ~
14321 8;
14322 \family default
14323
14324 \begin_inset Quotes srd
14325 \end_inset
14326
14327  is not atomic on the 8051 even if 
14328 \family typewriter
14329 counter
14330 \family default
14331  is located in data memory.
14332 \newline
14333 Bugs like these are hard to reproduce and can
14334  cause a lot of trouble.
14335  
14336 \end_layout
14337
14338 \begin_layout Subsubsection
14339 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14340
14341 \end_inset
14342
14343 Common interrupt pitfall: 
14344 \emph on
14345 stack overflow
14346 \end_layout
14347
14348 \begin_layout Standard
14349 The return address and the registers used in the interrupt service routine
14350  are saved on the stack
14351 \begin_inset LatexCommand \index{stack}
14352
14353 \end_inset
14354
14355  so there must be sufficient stack space.
14356  If there isn't variables or registers (or even the return address itself)
14357  will be corrupted.
14358  This 
14359 \emph on
14360 stack overflow
14361 \emph default
14362
14363 \begin_inset LatexCommand \index{stack overflow}
14364
14365 \end_inset
14366
14367  is most likely to happen if the interrupt occurs during the 
14368 \begin_inset Quotes sld
14369 \end_inset
14370
14371 deepest
14372 \begin_inset Quotes srd
14373 \end_inset
14374
14375  subroutine when the stack is already in use for f.e.
14376  many return addresses.
14377 \end_layout
14378
14379 \begin_layout Subsubsection
14380 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14381
14382 \end_inset
14383
14384 Common interrupt pitfall: 
14385 \emph on
14386 use of non-reentrant functions
14387 \end_layout
14388
14389 \begin_layout Standard
14390 A special note here, int (16 bit) and long (32 bit) integer division
14391 \begin_inset LatexCommand \index{Division}
14392
14393 \end_inset
14394
14395 , multiplication
14396 \begin_inset LatexCommand \index{Multiplication}
14397
14398 \end_inset
14399
14400  & modulus
14401 \begin_inset LatexCommand \index{Modulus}
14402
14403 \end_inset
14404
14405  and floating-point
14406 \begin_inset LatexCommand \index{Floating point support}
14407
14408 \end_inset
14409
14410  operations are implemented using external support routines.
14411  If an interrupt service routine needs to do any of these operations then
14412  the support routines (as mentioned in a following section) will have to
14413  be recompiled using the
14414 \emph on
14415  -
14416 \begin_inset ERT
14417 status collapsed
14418
14419 \begin_layout Standard
14420
14421
14422 \backslash
14423 /
14424 \end_layout
14425
14426 \end_inset
14427
14428 -stack-auto
14429 \begin_inset LatexCommand \index{-\/-stack-auto}
14430
14431 \end_inset
14432
14433
14434 \emph default
14435  option and the source file will need to be compiled using the 
14436 \emph on
14437 -
14438 \begin_inset ERT
14439 status collapsed
14440
14441 \begin_layout Standard
14442
14443
14444 \backslash
14445 /
14446 \end_layout
14447
14448 \end_inset
14449
14450 -int-long-reent
14451 \emph default
14452
14453 \begin_inset LatexCommand \index{-\/-int-long-reent}
14454
14455 \end_inset
14456
14457  compiler option.
14458  
14459 \newline
14460 Note, the type promotion
14461 \begin_inset LatexCommand \index{type promotion}
14462
14463 \end_inset
14464
14465  required by ANSI C can cause 16 bit routines to be used
14466 \begin_inset Marginal
14467 status collapsed
14468
14469 \begin_layout Standard
14470
14471 \series bold
14472 \InsetSpace ~
14473 !
14474 \end_layout
14475
14476 \end_inset
14477
14478  without the programmer being aware of it.
14479  See f.e.
14480  the cast 
14481 \family typewriter
14482 (unsigned char)(tail-1)
14483 \family default
14484  within the if clause in section 
14485 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14486
14487 \end_inset
14488
14489 .
14490 \end_layout
14491
14492 \begin_layout Standard
14493 Calling other functions from an interrupt service routine is not recommended,
14494  avoid it if possible.
14495  Note that when some function is called from an interrupt service routine
14496  it should be preceded by a #pragma\InsetSpace ~
14497 nooverlay
14498 \begin_inset LatexCommand \index{\#pragma nooverlay}
14499
14500 \end_inset
14501
14502  if it is not reentrant.
14503  Furthermore nonreentrant functions should not be called from the main program
14504  while the interrupt service routine might be active.
14505  They also must not be called from low priority interrupt service routines
14506  while a high priority interrupt service routine might be active.
14507  You could use semaphores or make the function
14508 \emph on
14509  critical
14510 \emph default
14511  if all parameters are passed in registers.
14512 \newline
14513  Also see section 
14514 \begin_inset LatexCommand \ref{sub:Overlaying}
14515
14516 \end_inset
14517
14518 \InsetSpace ~
14519 about Overlaying and section 
14520 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14521
14522 \end_inset
14523
14524 \InsetSpace ~
14525 about Functions using private register banks.
14526 \begin_inset VSpace bigskip
14527 \end_inset
14528
14529
14530 \end_layout
14531
14532 \begin_layout Subsection
14533 MCS51/DS390 Interrupt Service Routines
14534 \end_layout
14535
14536 \begin_layout Standard
14537 Interrupt
14538 \begin_inset LatexCommand \index{interrupt}
14539
14540 \end_inset
14541
14542  numbers and the corresponding address & descriptions for the Standard 8051/8052
14543  are listed below.
14544  SDCC will automatically adjust the 
14545 \begin_inset LatexCommand \index{interrupt vector table}
14546
14547 \end_inset
14548
14549  to the maximum interrupt number specified.
14550 \newline
14551
14552 \end_layout
14553
14554 \begin_layout Standard
14555 \align center
14556 \begin_inset Tabular
14557 <lyxtabular version="3" rows="9" columns="3">
14558 <features>
14559 <column alignment="center" valignment="top" leftline="true" width="0in">
14560 <column alignment="left" valignment="top" leftline="true" width="0in">
14561 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14562 <row topline="true" bottomline="true">
14563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14564 \begin_inset Text
14565
14566 \begin_layout Standard
14567 Interrupt #
14568 \end_layout
14569
14570 \end_inset
14571 </cell>
14572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14573 \begin_inset Text
14574
14575 \begin_layout Standard
14576 Description
14577 \end_layout
14578
14579 \end_inset
14580 </cell>
14581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14582 \begin_inset Text
14583
14584 \begin_layout Standard
14585 Vector Address
14586 \end_layout
14587
14588 \end_inset
14589 </cell>
14590 </row>
14591 <row topline="true">
14592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14593 \begin_inset Text
14594
14595 \begin_layout Standard
14596 0
14597 \end_layout
14598
14599 \end_inset
14600 </cell>
14601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14602 \begin_inset Text
14603
14604 \begin_layout Standard
14605 External 0
14606 \end_layout
14607
14608 \end_inset
14609 </cell>
14610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14611 \begin_inset Text
14612
14613 \begin_layout Standard
14614 0x0003
14615 \end_layout
14616
14617 \end_inset
14618 </cell>
14619 </row>
14620 <row topline="true">
14621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14622 \begin_inset Text
14623
14624 \begin_layout Standard
14625 1
14626 \end_layout
14627
14628 \end_inset
14629 </cell>
14630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14631 \begin_inset Text
14632
14633 \begin_layout Standard
14634 Timer 0
14635 \end_layout
14636
14637 \end_inset
14638 </cell>
14639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14640 \begin_inset Text
14641
14642 \begin_layout Standard
14643 0x000b
14644 \end_layout
14645
14646 \end_inset
14647 </cell>
14648 </row>
14649 <row topline="true">
14650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14651 \begin_inset Text
14652
14653 \begin_layout Standard
14654 2
14655 \end_layout
14656
14657 \end_inset
14658 </cell>
14659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14660 \begin_inset Text
14661
14662 \begin_layout Standard
14663 External 1
14664 \end_layout
14665
14666 \end_inset
14667 </cell>
14668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14669 \begin_inset Text
14670
14671 \begin_layout Standard
14672 0x0013
14673 \end_layout
14674
14675 \end_inset
14676 </cell>
14677 </row>
14678 <row topline="true">
14679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14680 \begin_inset Text
14681
14682 \begin_layout Standard
14683 3
14684 \end_layout
14685
14686 \end_inset
14687 </cell>
14688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14689 \begin_inset Text
14690
14691 \begin_layout Standard
14692 Timer 1
14693 \end_layout
14694
14695 \end_inset
14696 </cell>
14697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14698 \begin_inset Text
14699
14700 \begin_layout Standard
14701 0x001b
14702 \end_layout
14703
14704 \end_inset
14705 </cell>
14706 </row>
14707 <row topline="true">
14708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14709 \begin_inset Text
14710
14711 \begin_layout Standard
14712 4
14713 \end_layout
14714
14715 \end_inset
14716 </cell>
14717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14718 \begin_inset Text
14719
14720 \begin_layout Standard
14721 Serial
14722 \end_layout
14723
14724 \end_inset
14725 </cell>
14726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14727 \begin_inset Text
14728
14729 \begin_layout Standard
14730 0x0023
14731 \end_layout
14732
14733 \end_inset
14734 </cell>
14735 </row>
14736 <row topline="true">
14737 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14738 \begin_inset Text
14739
14740 \begin_layout Standard
14741 5
14742 \end_layout
14743
14744 \end_inset
14745 </cell>
14746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14747 \begin_inset Text
14748
14749 \begin_layout Standard
14750 Timer 2 (8052)
14751 \end_layout
14752
14753 \end_inset
14754 </cell>
14755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14756 \begin_inset Text
14757
14758 \begin_layout Standard
14759 0x002b
14760 \end_layout
14761
14762 \end_inset
14763 </cell>
14764 </row>
14765 <row topline="true">
14766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14767 \begin_inset Text
14768
14769 \begin_layout Standard
14770 ...
14771 \end_layout
14772
14773 \end_inset
14774 </cell>
14775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14776 \begin_inset Text
14777
14778 \begin_layout Standard
14779
14780 \end_layout
14781
14782 \end_inset
14783 </cell>
14784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14785 \begin_inset Text
14786
14787 \begin_layout Standard
14788 ...
14789 \end_layout
14790
14791 \end_inset
14792 </cell>
14793 </row>
14794 <row topline="true" bottomline="true">
14795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14796 \begin_inset Text
14797
14798 \begin_layout Standard
14799 n
14800 \end_layout
14801
14802 \end_inset
14803 </cell>
14804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14805 \begin_inset Text
14806
14807 \begin_layout Standard
14808
14809 \end_layout
14810
14811 \end_inset
14812 </cell>
14813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14814 \begin_inset Text
14815
14816 \begin_layout Standard
14817 0x0003 + 8*n
14818 \end_layout
14819
14820 \end_inset
14821 </cell>
14822 </row>
14823 </lyxtabular>
14824
14825 \end_inset
14826
14827
14828 \newline
14829
14830 \end_layout
14831
14832 \begin_layout Standard
14833 If the interrupt service routine is defined without 
14834 \emph on
14835 using
14836 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14837
14838 \end_inset
14839
14840
14841 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14842
14843 \end_inset
14844
14845
14846 \emph default
14847  a register bank or with register bank 0 (
14848 \emph on
14849 using
14850 \emph default
14851  0), the compiler will save the registers used by itself on the stack upon
14852  entry and restore them at exit, however if such an interrupt service routine
14853  calls another function then the entire register bank will be saved on the
14854  stack.
14855  This scheme may be advantageous for small interrupt service routines which
14856  have low register usage.
14857 \end_layout
14858
14859 \begin_layout Standard
14860 If the interrupt service routine is defined to be using a specific register
14861  bank then only 
14862 \emph on
14863 a, b, dptr
14864 \emph default
14865  & psw are saved and restored, if such an interrupt service routine calls
14866  another function (using another register bank) then the entire register
14867  bank of the called function will be saved on the stack
14868 \begin_inset LatexCommand \index{stack}
14869
14870 \end_inset
14871
14872 .
14873  This scheme is recommended for larger interrupt service routines.
14874 \begin_inset VSpace bigskip
14875 \end_inset
14876
14877
14878 \end_layout
14879
14880 \begin_layout Subsection
14881 HC08
14882 \begin_inset LatexCommand \index{HC08}
14883
14884 \end_inset
14885
14886  Interrupt Service Routines
14887 \end_layout
14888
14889 \begin_layout Standard
14890 Since the number of interrupts
14891 \begin_inset LatexCommand \index{HC08!interrupt}
14892
14893 \end_inset
14894
14895  available is chip specific and the interrupt vector table always ends at
14896  the last byte of memory, the interrupt numbers corresponds to the interrupt
14897  vectors in reverse order of address.
14898  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14899  2 will use the interrupt vector at 0xfffa, and so on.
14900  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14901  this way; instead see section 
14902 \begin_inset LatexCommand \ref{sub:Startup-Code}
14903
14904 \end_inset
14905
14906  for details on customizing startup.
14907 \begin_inset VSpace bigskip
14908 \end_inset
14909
14910
14911 \end_layout
14912
14913 \begin_layout Subsection
14914 Z80 Interrupt Service Routines
14915 \end_layout
14916
14917 \begin_layout Standard
14918 The Z80
14919 \begin_inset LatexCommand \index{Z80}
14920
14921 \end_inset
14922
14923  uses several different methods for determining the correct interrupt
14924 \begin_inset LatexCommand \index{Z80!interrupt}
14925
14926 \end_inset
14927
14928  vector depending on the hardware implementation.
14929  Therefore, SDCC ignores the optional interrupt number and does not attempt
14930  to generate an interrupt vector table.
14931 \end_layout
14932
14933 \begin_layout Standard
14934 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14935  instruction to return from the interrupt.
14936  To write an interrupt handler for the non-maskable interrupt, which needs
14937  a RETN instruction instead, add the 
14938 \emph on
14939 critical
14940 \emph default
14941  keyword:
14942 \end_layout
14943
14944 \begin_layout Verse
14945
14946 \family typewriter
14947 void nmi_isr (void) critical interrupt
14948 \newline
14949
14950 \newline
14951 \InsetSpace ~
14952 \InsetSpace ~
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 ...
14956  
14957 \newline
14958 }
14959 \end_layout
14960
14961 \begin_layout Standard
14962 However if you need to create a non-interruptable interrupt service routine
14963  you would also require the 
14964 \emph on
14965 critical
14966 \emph default
14967  keyword.
14968  To distinguish between this and an nmi_isr you must provide an interrupt
14969  number.
14970 \begin_inset VSpace bigskip
14971 \end_inset
14972
14973
14974 \end_layout
14975
14976 \begin_layout Section
14977 Enabling and Disabling Interrupts
14978 \end_layout
14979
14980 \begin_layout Subsection
14981 Critical Functions and Critical Statements
14982 \end_layout
14983
14984 \begin_layout Standard
14985 A special keyword may be associated with a block or a function declaring
14986  it as 
14987 \emph on
14988 critical
14989 \emph default
14990 .
14991  SDCC will generate code to disable all interrupts
14992 \begin_inset LatexCommand \index{interrupt}
14993
14994 \end_inset
14995
14996  upon entry to a critical function and restore the interrupt enable to the
14997  previous state before returning.
14998  Nesting critical functions will need one additional byte on the stack
14999 \begin_inset LatexCommand \index{stack}
15000
15001 \end_inset
15002
15003  for each call.
15004 \end_layout
15005
15006 \begin_layout Verse
15007
15008 \family typewriter
15009 int foo () __critical
15010 \begin_inset LatexCommand \index{critical}
15011
15012 \end_inset
15013
15014
15015 \begin_inset LatexCommand \index{\_\_critical}
15016
15017 \end_inset
15018
15019  
15020 \newline
15021
15022 \newline
15023 \InsetSpace ~
15024 \InsetSpace ~
15025 \InsetSpace ~
15026 \InsetSpace ~
15027 ...
15028  
15029 \newline
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 \InsetSpace ~
15034 ...
15035  
15036 \newline
15037 }
15038 \end_layout
15039
15040 \begin_layout Standard
15041 The critical attribute maybe used with other attributes like 
15042 \emph on
15043 reentrant.
15044 \emph default
15045
15046 \newline
15047 The keyword 
15048 \emph on
15049 critical
15050 \emph default
15051  may also be used to disable interrupts more locally:
15052 \end_layout
15053
15054 \begin_layout Verse
15055
15056 \family typewriter
15057 __critical{ i++; }
15058 \end_layout
15059
15060 \begin_layout Standard
15061 More than one statement could have been included in the block.
15062 \end_layout
15063
15064 \begin_layout Subsection
15065 Enabling and Disabling Interrupts directly
15066 \end_layout
15067
15068 \begin_layout Standard
15069 Interrupts
15070 \begin_inset LatexCommand \index{interrupt}
15071
15072 \end_inset
15073
15074  can also be disabled and enabled directly (8051):
15075 \end_layout
15076
15077 \begin_layout Verse
15078
15079 \family typewriter
15080 EA = 0;\InsetSpace ~
15081 \InsetSpace ~
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 \InsetSpace ~
15091 \InsetSpace ~
15092 or:\InsetSpace ~
15093 \InsetSpace ~
15094 \InsetSpace ~
15095 \InsetSpace ~
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 \InsetSpace ~
15103 EA_SAVE = EA;
15104 \end_layout
15105
15106 \begin_layout Verse
15107
15108 \family typewriter
15109 ...\InsetSpace ~
15110 \InsetSpace ~
15111 \InsetSpace ~
15112 \InsetSpace ~
15113 \InsetSpace ~
15114 \InsetSpace ~
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 \InsetSpace ~
15123 \InsetSpace ~
15124 \InsetSpace ~
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 \InsetSpace ~
15134 \InsetSpace ~
15135 \InsetSpace ~
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 EA = 0;
15140 \end_layout
15141
15142 \begin_layout Verse
15143
15144 \family typewriter
15145 EA = 1;\InsetSpace ~
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 \InsetSpace ~
15155 \InsetSpace ~
15156 \InsetSpace ~
15157 \InsetSpace ~
15158 \InsetSpace ~
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 \InsetSpace ~
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 ...
15172 \end_layout
15173
15174 \begin_layout Verse
15175
15176 \family typewriter
15177 \InsetSpace ~
15178 \InsetSpace ~
15179 \InsetSpace ~
15180 \InsetSpace ~
15181 \InsetSpace ~
15182 \InsetSpace ~
15183 \InsetSpace ~
15184 \InsetSpace ~
15185 \InsetSpace ~
15186 \InsetSpace ~
15187 \InsetSpace ~
15188 \InsetSpace ~
15189 \InsetSpace ~
15190 \InsetSpace ~
15191 \InsetSpace ~
15192 \InsetSpace ~
15193 \InsetSpace ~
15194 \InsetSpace ~
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 \InsetSpace ~
15201 \InsetSpace ~
15202 \InsetSpace ~
15203 \InsetSpace ~
15204 \InsetSpace ~
15205 \InsetSpace ~
15206 \InsetSpace ~
15207 \InsetSpace ~
15208 \InsetSpace ~
15209 \InsetSpace ~
15210 EA = EA_SAVE;
15211 \end_layout
15212
15213 \begin_layout Standard
15214 On other architectures which have seperate opcodes for enabling and disabling
15215  interrupts you might want to make use of defines with inline assembly
15216 \begin_inset LatexCommand \index{Assembler routines}
15217
15218 \end_inset
15219
15220  (HC08
15221 \begin_inset LatexCommand \index{HC08!interrupt}
15222
15223 \end_inset
15224
15225 ):
15226 \end_layout
15227
15228 \begin_layout Verse
15229
15230 \family typewriter
15231 #define CLI _asm
15232 \begin_inset LatexCommand \index{\_asm}
15233
15234 \end_inset
15235
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 cli\InsetSpace ~
15239 \InsetSpace ~
15240 _endasm
15241 \begin_inset LatexCommand \index{\_endasm}
15242
15243 \end_inset
15244
15245
15246 \end_layout
15247
15248 \begin_layout Verse
15249
15250 \family typewriter
15251 #define SEI _asm\InsetSpace ~
15252 \InsetSpace ~
15253 sei\InsetSpace ~
15254 \InsetSpace ~
15255 _endasm; 
15256 \end_layout
15257
15258 \begin_layout Verse
15259
15260 \family typewriter
15261 ...
15262 \end_layout
15263
15264 \begin_layout Standard
15265 Note: it is sometimes sufficient to disable only a specific interrupt source
15266  like f.e.
15267  a timer or serial interrupt by manipulating an 
15268 \emph on
15269 interrupt mask
15270 \begin_inset LatexCommand \index{interrupt mask}
15271
15272 \end_inset
15273
15274
15275 \emph default
15276  register.
15277  
15278 \end_layout
15279
15280 \begin_layout Standard
15281 Usually the time during which interrupts are disabled should be kept as
15282  short as possible.
15283  This minimizes both 
15284 \emph on
15285 interrupt latency
15286 \emph default
15287
15288 \begin_inset LatexCommand \index{interrupt latency}
15289
15290 \end_inset
15291
15292  (the time between the occurrence of the interrupt and the execution of
15293  the first code in the interrupt routine) and 
15294 \emph on
15295 interrupt jitter
15296 \emph default
15297
15298 \begin_inset LatexCommand \index{interrupt jitter}
15299
15300 \end_inset
15301
15302  (the difference between the shortest and the longest interrupt latency).
15303  These really are something different, f.e.
15304  a serial interrupt has to be served before its buffer overruns so it cares
15305  for the maximum interrupt latency, whereas it does not care about jitter.
15306  On a loudspeaker driven via a digital to analog converter which is fed
15307  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15308  a much smaller jitter will be very audible.
15309 \end_layout
15310
15311 \begin_layout Standard
15312 You can reenable interrupts within an interrupt routine and on some architecture
15313 s you can make use of two (or more) levels of 
15314 \emph on
15315 interrupt priorities
15316 \emph default
15317
15318 \begin_inset LatexCommand \index{interrupt priority}
15319
15320 \end_inset
15321
15322 .
15323  On some architectures which don't support interrupt priorities these can
15324  be implemented by manipulating the interrupt mask and reenabling interrupts
15325  within the interrupt routine.
15326  Check there is sufficient space on the stack
15327 \begin_inset LatexCommand \index{stack}
15328
15329 \end_inset
15330
15331  and don't add complexity unless you have to.
15332  
15333 \end_layout
15334
15335 \begin_layout Subsection
15336 Semaphore
15337 \begin_inset LatexCommand \index{semaphore}
15338
15339 \end_inset
15340
15341  locking (mcs51/ds390)
15342 \end_layout
15343
15344 \begin_layout Standard
15345 Some architectures (mcs51/ds390) have an atomic
15346 \begin_inset LatexCommand \index{atomic}
15347
15348 \end_inset
15349
15350  bit test and
15351 \emph on
15352  
15353 \emph default
15354 clear
15355 \emph on
15356  
15357 \emph default
15358 instruction.
15359  These type of instructions are typically used in preemptive multitasking
15360  systems, where a routine f.e.
15361  claims the use of a data structure ('acquires a lock
15362 \begin_inset LatexCommand \index{lock}
15363
15364 \end_inset
15365
15366  on it'), makes some modifications and then releases the lock when the data
15367  structure is consistent again.
15368  The instruction may also be used if interrupt and non-interrupt code have
15369  to compete for a resource.
15370  With the atomic bit test and clear instruction interrupts
15371 \begin_inset LatexCommand \index{interrupt}
15372
15373 \end_inset
15374
15375  don't have to be disabled for the locking operation.
15376  
15377 \end_layout
15378
15379 \begin_layout Standard
15380 SDCC generates this instruction if the source follows this pattern:
15381 \end_layout
15382
15383 \begin_layout Verse
15384
15385 \family typewriter
15386 volatile
15387 \begin_inset LatexCommand \index{volatile}
15388
15389 \end_inset
15390
15391  bit resource_is_free; 
15392 \newline
15393
15394 \newline
15395 if (resource_is_free) 
15396 \newline
15397 \InsetSpace ~
15398 \InsetSpace ~
15399
15400 \newline
15401 \InsetSpace ~
15402 \InsetSpace ~
15403 \InsetSpace ~
15404 \InsetSpace ~
15405 resource_is_free=0; 
15406 \newline
15407 \InsetSpace ~
15408 \InsetSpace ~
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 ...
15412  
15413 \newline
15414 \InsetSpace ~
15415 \InsetSpace ~
15416 \InsetSpace ~
15417 \InsetSpace ~
15418 resource_is_free=1;
15419 \newline
15420 \InsetSpace ~
15421 \InsetSpace ~
15422
15423 \end_layout
15424
15425 \begin_layout Standard
15426 Note, mcs51 and ds390 support only an atomic
15427 \begin_inset LatexCommand \index{atomic}
15428
15429 \end_inset
15430
15431  bit test and 
15432 \emph on
15433 clear
15434 \emph default
15435  instruction (as opposed to atomic bit test and 
15436 \emph on
15437 set).
15438 \end_layout
15439
15440 \begin_layout Section
15441 Functions using private register banks
15442 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15443
15444 \end_inset
15445
15446  (mcs51/ds390)
15447 \end_layout
15448
15449 \begin_layout Standard
15450 Some architectures have support for quickly changing register sets.
15451  SDCC supports this feature with the 
15452 \emph on
15453 using
15454 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15455
15456 \end_inset
15457
15458
15459 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15460
15461 \end_inset
15462
15463
15464 \emph default
15465  attribute (which tells the compiler to use a register bank
15466 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15467
15468 \end_inset
15469
15470  other than the default bank zero).
15471  It should only be applied to 
15472 \emph on
15473 interrupt
15474 \begin_inset LatexCommand \index{interrupt}
15475
15476 \end_inset
15477
15478
15479 \emph default
15480  functions (see footnote below).
15481  This will in most circumstances make the generated ISR code more efficient
15482  since it will not have to save registers on the stack.
15483 \end_layout
15484
15485 \begin_layout Standard
15486 The 
15487 \emph on
15488 using
15489 \emph default
15490  attribute will have no effect on the generated code for a 
15491 \emph on
15492 non-interrupt
15493 \emph default
15494  function (but may occasionally be useful anyway
15495 \begin_inset Foot
15496 status open
15497
15498 \begin_layout Standard
15499 possible exception: if a function is called ONLY from 'interrupt' functions
15500  using a particular bank, it can be declared with the same 'using' attribute
15501  as the calling 'interrupt' functions.
15502  For instance, if you have several ISRs using bank one, and all of them
15503  call memcpy(), it might make sense to create a specialized version of memcpy()
15504  'using 1', since this would prevent the ISR from having to save bank zero
15505  to the stack on entry and switch to bank zero before calling the function
15506 \end_layout
15507
15508 \end_inset
15509
15510 ).
15511 \newline
15512
15513 \emph on
15514 (pending: Note, nowadays the 
15515 \emph default
15516 using
15517 \emph on
15518  attribute has an effect on
15519 \emph default
15520  
15521 \emph on
15522 the generated code for a 
15523 \emph default
15524 non-interrupt
15525 \emph on
15526  function
15527 \emph default
15528 .
15529 \emph on
15530 )
15531 \end_layout
15532
15533 \begin_layout Standard
15534 An 
15535 \emph on
15536 interrupt
15537 \emph default
15538  function using a non-zero bank will assume that it can trash that register
15539  bank, and will not save it.
15540  Since high-priority interrupts
15541 \begin_inset LatexCommand \index{interrupts}
15542
15543 \end_inset
15544
15545
15546 \begin_inset LatexCommand \index{interrupt priority}
15547
15548 \end_inset
15549
15550  can interrupt low-priority ones on the 8051 and friends, this means that
15551  if a high-priority ISR 
15552 \emph on
15553 using
15554 \emph default
15555  a particular bank occurs while processing a low-priority ISR 
15556 \emph on
15557 using
15558 \emph default
15559  the same bank, terrible and bad things can happen.
15560  To prevent this, no single register bank should be 
15561 \emph on
15562 used
15563 \emph default
15564  by both a high priority and a low priority ISR.
15565  This is probably most easily done by having all high priority ISRs use
15566  one bank and all low priority ISRs use another.
15567  If you have an ISR which can change priority at runtime, you're on your
15568  own: I suggest using the default bank zero and taking the small performance
15569  hit.
15570 \end_layout
15571
15572 \begin_layout Standard
15573 It is most efficient if your ISR calls no other functions.
15574  If your ISR must call other functions, it is most efficient if those functions
15575  use the same bank as the ISR (see note 1 below); the next best is if the
15576  called functions use bank zero.
15577  It is very inefficient to call a function using a different, non-zero bank
15578  from an ISR.
15579  
15580 \begin_inset VSpace bigskip
15581 \end_inset
15582
15583
15584 \end_layout
15585
15586 \begin_layout Section
15587 Startup Code
15588 \begin_inset LatexCommand \label{sub:Startup-Code}
15589
15590 \end_inset
15591
15592
15593 \begin_inset LatexCommand \index{Startup code}
15594
15595 \end_inset
15596
15597
15598 \end_layout
15599
15600 \begin_layout Subsection
15601 MCS51/DS390 Startup Code
15602 \end_layout
15603
15604 \begin_layout Standard
15605 The compiler triggers the linker to link certain initialization modules
15606  from the runtime library
15607 \begin_inset LatexCommand \index{Runtime library}
15608
15609 \end_inset
15610
15611  called crt<something>.
15612  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15613  GSINIT5) is not linked unless the -
15614 \series bold
15615
15616 \begin_inset ERT
15617 status open
15618
15619 \begin_layout Standard
15620
15621
15622 \backslash
15623 /
15624 \end_layout
15625
15626 \end_inset
15627
15628
15629 \series default
15630 -xstack option is used.
15631  These modules are highly entangled by the use of special segments/areas,
15632  but a common layout is shown below:
15633 \end_layout
15634
15635 \begin_layout Verse
15636
15637 \family typewriter
15638 \series bold
15639 \size footnotesize
15640 (main.asm)
15641 \end_layout
15642
15643 \begin_layout Verse
15644
15645 \family typewriter
15646 \size footnotesize
15647 \InsetSpace ~
15648 \InsetSpace ~
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 \InsetSpace ~
15654 \InsetSpace ~
15655 .area HOME (CODE)
15656 \newline
15657 __interrupt_vect:
15658 \newline
15659 \InsetSpace ~
15660 \InsetSpace ~
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 \InsetSpace ~
15664 \InsetSpace ~
15665 \InsetSpace ~
15666 \InsetSpace ~
15667 ljmp __sdcc_gsinit_startup
15668 \end_layout
15669
15670 \begin_layout Verse
15671
15672 \family typewriter
15673 \series bold
15674 \size footnotesize
15675 (crtstart.asm)
15676 \end_layout
15677
15678 \begin_layout Verse
15679
15680 \family typewriter
15681 \size footnotesize
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 \InsetSpace ~
15688 \InsetSpace ~
15689 \InsetSpace ~
15690 .area GSINIT0 (CODE)
15691 \newline
15692 __sdcc_gsinit_startup::
15693 \newline
15694 \InsetSpace ~
15695 \InsetSpace ~
15696 \InsetSpace ~
15697 \InsetSpace ~
15698 \InsetSpace ~
15699 \InsetSpace ~
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 mov sp,#__start__stack - 1
15703 \end_layout
15704
15705 \begin_layout Verse
15706
15707 \family typewriter
15708 \series bold
15709 \size footnotesize
15710 (crtxstack.asm)
15711 \end_layout
15712
15713 \begin_layout Verse
15714
15715 \family typewriter
15716 \size footnotesize
15717 \InsetSpace ~
15718 \InsetSpace ~
15719 \InsetSpace ~
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 .area GSINIT1 (CODE)
15726 \newline
15727 __sdcc_init_xstack::
15728 \newline
15729 ; Need to initialize in GSINIT1 in
15730  case the user's __sdcc_external_startup uses the xstack.
15731 \newline
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 mov __XPAGE,#(__start__x
15741 stack >> 8)
15742 \newline
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 \InsetSpace ~
15747 \InsetSpace ~
15748 \InsetSpace ~
15749 \InsetSpace ~
15750 \InsetSpace ~
15751 mov _spx,#__start__xstack
15752 \end_layout
15753
15754 \begin_layout Verse
15755
15756 \family typewriter
15757 \series bold
15758 \size footnotesize
15759 (crtstart.asm)
15760 \end_layout
15761
15762 \begin_layout Verse
15763
15764 \family typewriter
15765 \size footnotesize
15766 \InsetSpace ~
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 \InsetSpace ~
15773 \InsetSpace ~
15774 .area GSINIT2 (CODE)
15775 \newline
15776 \InsetSpace ~
15777 \InsetSpace ~
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 \InsetSpace ~
15783 \InsetSpace ~
15784 lcall __sdcc_external_startup
15785 \newline
15786 \InsetSpace ~
15787 \InsetSpace ~
15788 \InsetSpace ~
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 mov a,dpl
15795 \newline
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 jz __sdcc_init_data
15805 \newline
15806 \InsetSpace ~
15807 \InsetSpace ~
15808 \InsetSpace ~
15809 \InsetSpace ~
15810 \InsetSpace ~
15811 \InsetSpace ~
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 ljmp
15815  __sdcc_program_startup
15816 \newline
15817 __sdcc_init_data:
15818 \end_layout
15819
15820 \begin_layout Verse
15821
15822 \family typewriter
15823 \series bold
15824 \size footnotesize
15825 (crtxinit.asm)
15826 \end_layout
15827
15828 \begin_layout Verse
15829
15830 \family typewriter
15831 \size footnotesize
15832 \InsetSpace ~
15833 \InsetSpace ~
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 .area GSINIT3 (CODE)
15841 \newline
15842 __mcs51_genXINIT::
15843 \newline
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 mov r1,#l_XINIT
15853 \newline
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 \InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 mov a,r1
15863 \newline
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 orl a,#(l_XINIT
15873  >> 8)
15874 \newline
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 jz 00003$
15884 \newline
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 mov r2,#((l_XINIT+255) >> 8)
15894 \newline
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 mov dptr,#s_XINIT
15904 \newline
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 mov r0,#s_XISEG
15914 \newline
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 mov
15924  __XPAGE,#(s_XISEG >> 8)
15925 \newline
15926 00001$:\InsetSpace ~
15927 clr a
15928 \newline
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 movc a,@a+dptr
15938 \newline
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 movx @r0,a
15948 \newline
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 inc dptr
15958 \newline
15959 \InsetSpace ~
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 inc
15968  r0
15969 \newline
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 cjne r0,#0,00002$
15979 \newline
15980 \InsetSpace ~
15981 \InsetSpace ~
15982 \InsetSpace ~
15983 \InsetSpace ~
15984 \InsetSpace ~
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 inc __XPAGE
15989 \newline
15990 00002$:\InsetSpace ~
15991 djnz r1,00001$
15992 \newline
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 djnz r2,00001$
16002 \newline
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 mov __XPAGE,#0
16012 xFF
16013 \newline
16014 00003$:
16015 \end_layout
16016
16017 \begin_layout Verse
16018
16019 \family typewriter
16020 \series bold
16021 \size footnotesize
16022 (crtclear.asm)
16023 \end_layout
16024
16025 \begin_layout Verse
16026
16027 \family typewriter
16028 \size footnotesize
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 \InsetSpace ~
16036 \InsetSpace ~
16037 .area GSINIT4 (CODE)
16038 \newline
16039 __mcs51_genRAMCLEAR::
16040 \newline
16041 \InsetSpace ~
16042 \InsetSpace ~
16043 \InsetSpace ~
16044 \InsetSpace ~
16045 \InsetSpace ~
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 clr a
16050 \newline
16051 \InsetSpace ~
16052 \InsetSpace ~
16053 \InsetSpace ~
16054 \InsetSpace ~
16055 \InsetSpace ~
16056 \InsetSpace ~
16057 \InsetSpace ~
16058 \InsetSpace ~
16059 mov r0,#(l_IRAM-1)
16060 \newline
16061 00004$:\InsetSpace ~
16062 mov
16063  @r0,a
16064 \newline
16065 \InsetSpace ~
16066 \InsetSpace ~
16067 \InsetSpace ~
16068 \InsetSpace ~
16069 \InsetSpace ~
16070 \InsetSpace ~
16071 \InsetSpace ~
16072 \InsetSpace ~
16073 djnz r0,00004$
16074 \newline
16075 ; _mcs51_genRAMCLEAR() end
16076 \end_layout
16077
16078 \begin_layout Verse
16079
16080 \family typewriter
16081 \series bold
16082 \size footnotesize
16083 (crtxclear.asm)
16084 \end_layout
16085
16086 \begin_layout Verse
16087
16088 \family typewriter
16089 \size footnotesize
16090 \InsetSpace ~
16091 \InsetSpace ~
16092 \InsetSpace ~
16093 \InsetSpace ~
16094 \InsetSpace ~
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 .area GSINIT4 (CODE)
16099 \newline
16100 __mcs51_genXRAMCLEAR::
16101 \newline
16102 \InsetSpace ~
16103 \InsetSpace ~
16104 \InsetSpace ~
16105 \InsetSpace ~
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 \InsetSpace ~
16109 \InsetSpace ~
16110 mov r0,#l_PSEG
16111 \newline
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 \InsetSpace ~
16116 \InsetSpace ~
16117 \InsetSpace ~
16118 \InsetSpace ~
16119 \InsetSpace ~
16120 mov a,r0
16121 \newline
16122 \InsetSpace ~
16123 \InsetSpace ~
16124 \InsetSpace ~
16125 \InsetSpace ~
16126 \InsetSpace ~
16127 \InsetSpace ~
16128 \InsetSpace ~
16129 \InsetSpace ~
16130 orl a,#(l_PSEG
16131  >> 8)
16132 \newline
16133 \InsetSpace ~
16134 \InsetSpace ~
16135 \InsetSpace ~
16136 \InsetSpace ~
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 \InsetSpace ~
16140 \InsetSpace ~
16141 jz 00006$
16142 \newline
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 mov r1,#s_PSEG
16152 \newline
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 \InsetSpace ~
16158 \InsetSpace ~
16159 \InsetSpace ~
16160 \InsetSpace ~
16161 mov __XPAGE,#(s_PSEG >> 8)
16162 \newline
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 \InsetSpace ~
16166 \InsetSpace ~
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 clr a
16172 \newline
16173 00005$:\InsetSpace ~
16174 movx
16175  @r1,a
16176 \newline
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 \InsetSpace ~
16185 inc r1
16186 \newline
16187 \InsetSpace ~
16188 \InsetSpace ~
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 djnz r0,00005$
16196 \newline
16197 00006$:
16198 \newline
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 mov r0,#l_XSEG
16208 \newline
16209 \InsetSpace ~
16210 \InsetSpace ~
16211 \InsetSpace ~
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 mov a,r0
16218 \newline
16219 \InsetSpace ~
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 orl a,#(l_XSEG >>
16228  8)
16229 \newline
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 \InsetSpace ~
16237 \InsetSpace ~
16238 jz 00008$
16239 \newline
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 \InsetSpace ~
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 mov r1,#((l_XSEG + 255) >> 8)
16249 \newline
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 mov dptr,#s_XSEG
16259 \newline
16260 \InsetSpace ~
16261 \InsetSpace ~
16262 \InsetSpace ~
16263 \InsetSpace ~
16264 \InsetSpace ~
16265 \InsetSpace ~
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 clr a
16269 \newline
16270 00007$:\InsetSpace ~
16271 movx
16272  @dptr,a
16273 \newline
16274 \InsetSpace ~
16275 \InsetSpace ~
16276 \InsetSpace ~
16277 \InsetSpace ~
16278 \InsetSpace ~
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 inc dptr
16283 \newline
16284 \InsetSpace ~
16285 \InsetSpace ~
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 \InsetSpace ~
16290 \InsetSpace ~
16291 \InsetSpace ~
16292 djnz r0,00007$
16293 \newline
16294 \InsetSpace ~
16295 \InsetSpace ~
16296 \InsetSpace ~
16297 \InsetSpace ~
16298 \InsetSpace ~
16299 \InsetSpace ~
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 djnz r1,00007$
16303 \newline
16304 00008$:
16305 \end_layout
16306
16307 \begin_layout Verse
16308
16309 \family typewriter
16310 \series bold
16311 \size footnotesize
16312 (crtxstack.asm)
16313 \end_layout
16314
16315 \begin_layout Verse
16316
16317 \family typewriter
16318 \size footnotesize
16319 \InsetSpace ~
16320 \InsetSpace ~
16321 \InsetSpace ~
16322 \InsetSpace ~
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 .area GSINIT5 (CODE)
16328 \newline
16329 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16330  modifies __XPAGE
16331 \newline
16332 ; and __mcs51_genRAMCLEAR modifies _spx.
16333 \newline
16334 \InsetSpace ~
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 \InsetSpace ~
16339 \InsetSpace ~
16340 \InsetSpace ~
16341 \InsetSpace ~
16342 mov __XPAGE,#(__start__x
16343 stack >> 8)
16344 \newline
16345 \InsetSpace ~
16346 \InsetSpace ~
16347 \InsetSpace ~
16348 \InsetSpace ~
16349 \InsetSpace ~
16350 \InsetSpace ~
16351 \InsetSpace ~
16352 \InsetSpace ~
16353 mov _spx,#__start__xstack
16354 \end_layout
16355
16356 \begin_layout Verse
16357
16358 \family typewriter
16359 \series bold
16360 \size footnotesize
16361 (application modules)
16362 \end_layout
16363
16364 \begin_layout Verse
16365
16366 \family typewriter
16367 \size footnotesize
16368 \InsetSpace ~
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 \InsetSpace ~
16372 \InsetSpace ~
16373 \InsetSpace ~
16374 \InsetSpace ~
16375 \InsetSpace ~
16376 .area GSINIT (CODE)
16377 \end_layout
16378
16379 \begin_layout Verse
16380
16381 \family typewriter
16382 \series bold
16383 \size footnotesize
16384 (main.asm)
16385 \end_layout
16386
16387 \begin_layout Verse
16388
16389 \family typewriter
16390 \size footnotesize
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 \InsetSpace ~
16398 \InsetSpace ~
16399 .area GSFINAL (CODE)
16400 \newline
16401 \InsetSpace ~
16402 \InsetSpace ~
16403 \InsetSpace ~
16404 \InsetSpace ~
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 \InsetSpace ~
16408 \InsetSpace ~
16409 ljmp __sdcc_program_startup
16410 \newline
16411 ;---------------------------------
16412 -----------------------
16413 \newline
16414 ; Home
16415 \newline
16416 ;--------------------------------------------------
16417 ------
16418 \newline
16419 \InsetSpace ~
16420 \InsetSpace ~
16421 \InsetSpace ~
16422 \InsetSpace ~
16423 \InsetSpace ~
16424 \InsetSpace ~
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 .area HOME (CODE)
16428 \newline
16429 \InsetSpace ~
16430 \InsetSpace ~
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 \InsetSpace ~
16437 .area CSEG (CODE)
16438 \newline
16439 __sdcc_program_startup:
16440 \newline
16441 \InsetSpace ~
16442 \InsetSpace ~
16443 \InsetSpace ~
16444 \InsetSpace ~
16445 \InsetSpace ~
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 lcall _main
16450 \newline
16451 ;
16452  return from main will lock up
16453 \newline
16454 \InsetSpace ~
16455 \InsetSpace ~
16456 \InsetSpace ~
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 sjmp .
16463 \end_layout
16464
16465 \begin_layout Standard
16466 One of these modules (crtstart.asm) contains a call to the C routine 
16467 \emph on
16468 _sdcc_external_startup()
16469 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16470
16471 \end_inset
16472
16473
16474 \series bold
16475 \emph default
16476  
16477 \series default
16478 at the start of the CODE area.
16479  This routine is also in the runtime library
16480 \begin_inset LatexCommand \index{Runtime library}
16481
16482 \end_inset
16483
16484  and returns 0 by default.
16485  If this routine returns a non-zero value, the static & global variable
16486  initialization will be skipped and the function main will be invoked.
16487  Otherwise static & global variables will be initialized before the function
16488  main is invoked.
16489  You could add an 
16490 \emph on
16491 _sdcc_external_startup()
16492 \emph default
16493  routine to your program to override the default if you need to setup hardware
16494  or perform some other critical operation prior to static & global variable
16495  initialization
16496 \begin_inset LatexCommand \index{Variable initialization}
16497
16498 \end_inset
16499
16500 .
16501  On some mcs51 variants xdata
16502 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16503
16504 \end_inset
16505
16506  memory has to be explicitly enabled before it can be accessed or if the
16507  watchdog
16508 \begin_inset LatexCommand \index{watchdog}
16509
16510 \end_inset
16511
16512  needs to be disabled, this is the place to do it.
16513  The startup code clears all internal data memory, 256 bytes by default,
16514  but from 0 to n-1 if 
16515 \emph on
16516 -
16517 \begin_inset ERT
16518 status collapsed
16519
16520 \begin_layout Standard
16521
16522
16523 \backslash
16524 /
16525 \end_layout
16526
16527 \end_inset
16528
16529 -iram-size
16530 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16531
16532 \end_inset
16533
16534 n
16535 \emph default
16536  is used.
16537  (recommended for Chipcon CC1010).
16538 \end_layout
16539
16540 \begin_layout Standard
16541 See also the compiler options 
16542 \emph on
16543 -
16544 \begin_inset ERT
16545 status collapsed
16546
16547 \begin_layout Standard
16548
16549
16550 \backslash
16551 /
16552 \end_layout
16553
16554 \end_inset
16555
16556 -no-xinit
16557 \emph default
16558 -
16559 \emph on
16560 opt
16561 \emph default
16562
16563 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16564
16565 \end_inset
16566
16567
16568 \emph on
16569 -
16570 \begin_inset ERT
16571 status collapsed
16572
16573 \begin_layout Standard
16574
16575
16576 \backslash
16577 /
16578 \end_layout
16579
16580 \end_inset
16581
16582 -main-return
16583 \emph default
16584
16585 \begin_inset LatexCommand \index{-\/-main-return}
16586
16587 \end_inset
16588
16589  and section 
16590 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16591
16592 \end_inset
16593
16594  about MCS51-variants.
16595 \newline
16596
16597 \end_layout
16598
16599 \begin_layout Standard
16600 While these initialization modules are meant as generic startup code there
16601  might be the need for customization.
16602  Let's assume the return value of 
16603 \emph on
16604 _sdcc_external_startup()
16605 \emph default
16606  in 
16607 \emph on
16608 crtstart.asm
16609 \emph default
16610  should not be checked (or 
16611 \emph on
16612 _sdcc_external_startup()
16613 \emph default
16614  should not be called at all).
16615  The recommended way would be to copy 
16616 \emph on
16617 crtstart.asm
16618 \emph default
16619  (f.e.
16620  from 
16621 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16622
16623 \end_inset
16624
16625 ) into the source directory, adapt it there, then assemble it with 
16626 \emph on
16627 asx8051 -plosgff
16628 \begin_inset Foot
16629 status open
16630
16631 \begin_layout Standard
16632 \begin_inset Quotes sld
16633 \end_inset
16634
16635 -plosgff
16636 \begin_inset Quotes srd
16637 \end_inset
16638
16639  are the assembler options used in 
16640 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16641
16642 \end_inset
16643
16644
16645 \end_layout
16646
16647 \end_inset
16648
16649  crtstart.asm
16650 \emph default
16651  and when linking your project explicitely specify 
16652 \emph on
16653 crtstart.rel
16654 \emph default
16655 .
16656  As a bonus a listing of the relocated object file 
16657 \emph on
16658 crtstart.rst
16659 \emph default
16660  is generated.
16661 \end_layout
16662
16663 \begin_layout Standard
16664 \begin_inset VSpace bigskip
16665 \end_inset
16666
16667
16668 \end_layout
16669
16670 \begin_layout Subsection
16671 HC08 Startup Code
16672 \end_layout
16673
16674 \begin_layout Standard
16675 The HC08
16676 \begin_inset LatexCommand \index{HC08}
16677
16678 \end_inset
16679
16680  startup code follows the same scheme as the MCS51 startup code.
16681 \begin_inset VSpace bigskip
16682 \end_inset
16683
16684
16685 \end_layout
16686
16687 \begin_layout Subsection
16688 Z80 Startup Code
16689 \end_layout
16690
16691 \begin_layout Standard
16692 On the Z80
16693 \begin_inset LatexCommand \index{Z80}
16694
16695 \end_inset
16696
16697  the startup code is inserted by linking with crt0.o which is generated from
16698  sdcc/device/lib/z80/crt0.s.
16699  If you need a different startup code you can use the compiler option 
16700 \emph on
16701 -
16702 \series bold
16703 \emph default
16704
16705 \begin_inset ERT
16706 status collapsed
16707
16708 \begin_layout Standard
16709
16710
16711 \backslash
16712 /
16713 \end_layout
16714
16715 \end_inset
16716
16717
16718 \series default
16719 \emph on
16720 -no-std-crt0
16721 \emph default
16722
16723 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16724
16725 \end_inset
16726
16727  and provide your own crt0.o.
16728  
16729 \begin_inset VSpace bigskip
16730 \end_inset
16731
16732
16733 \end_layout
16734
16735 \begin_layout Section
16736 Inline Assembler Code
16737 \begin_inset LatexCommand \index{Assembler routines}
16738
16739 \end_inset
16740
16741
16742 \end_layout
16743
16744 \begin_layout Subsection
16745 A Step by Step Introduction
16746 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16747
16748 \end_inset
16749
16750
16751 \end_layout
16752
16753 \begin_layout Standard
16754 Starting from a small snippet of c-code this example shows for the MCS51
16755  how to use inline assembly, access variables, a function parameter and
16756  an array in xdata memory.
16757  The example uses an MCS51 here but is easily adapted for other architectures.
16758  This is a buffer routine which should be optimized:
16759 \end_layout
16760
16761 \begin_layout Verse
16762
16763 \family typewriter
16764 \size footnotesize
16765 unsigned char __far
16766 \begin_inset LatexCommand \index{far (storage class)}
16767
16768 \end_inset
16769
16770
16771 \begin_inset LatexCommand \index{\_\_far (storage class)}
16772
16773 \end_inset
16774
16775  __at
16776 \begin_inset LatexCommand \index{at}
16777
16778 \end_inset
16779
16780
16781 \begin_inset LatexCommand \index{\_\_at}
16782
16783 \end_inset
16784
16785 (0x7f00) buf[0x100];
16786 \begin_inset LatexCommand \index{Aligned array}
16787
16788 \end_inset
16789
16790
16791 \newline
16792 unsigned char head, tail;\InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 \InsetSpace ~
16800 \InsetSpace ~
16801 \InsetSpace ~
16802 \InsetSpace ~
16803 \InsetSpace ~
16804 \InsetSpace ~
16805 \InsetSpace ~
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 /* if interrupts
16810 \begin_inset LatexCommand \index{interrupt}
16811
16812 \end_inset
16813
16814  are involved see
16815 \newline
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 \InsetSpace ~
16824 \InsetSpace ~
16825 \InsetSpace ~
16826 \InsetSpace ~
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 \InsetSpace ~
16834 \InsetSpace ~
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 \InsetSpace ~
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 \InsetSpace ~
16859 \InsetSpace ~
16860 \InsetSpace ~
16861 section 
16862 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16863
16864 \end_inset
16865
16866  about
16867 \series bold
16868  volatile
16869 \series default
16870  */
16871 \newline
16872
16873 \newline
16874 void to_buffer( unsigned char c ) 
16875 \newline
16876 {
16877 \newline
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 \InsetSpace ~
16881 \InsetSpace ~
16882 if( head != (unsigned char)(tail-1)
16883  )\InsetSpace ~
16884 /* cast 
16885 \series bold
16886 needed
16887 \series default
16888  to avoid promotion
16889 \begin_inset LatexCommand \index{promotion to signed int}
16890
16891 \end_inset
16892
16893
16894 \begin_inset LatexCommand \index{type promotion}
16895
16896 \end_inset
16897
16898  to integer */
16899 \begin_inset Marginal
16900 status collapsed
16901
16902 \begin_layout Standard
16903
16904 \series bold
16905 \InsetSpace ~
16906 !
16907 \end_layout
16908
16909 \end_inset
16910
16911
16912 \newline
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 buf[ head++ ] = c;\InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 \InsetSpace ~
16926 \InsetSpace ~
16927 \InsetSpace ~
16928 \InsetSpace ~
16929 \InsetSpace ~
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 \InsetSpace ~
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 /* access to a 256 byte aligned array */
16938 \newline
16939
16940 \end_layout
16941
16942 \begin_layout Standard
16943 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16944  then a corresponding buffer.asm file is generated.
16945  We define a new function 
16946 \family typewriter
16947 to_buffer_asm()
16948 \family default
16949  in file buffer.c in which we cut and paste the generated code, removing
16950  unwanted comments and some ':'.
16951  Then add 
16952 \begin_inset Quotes sld
16953 \end_inset
16954
16955
16956 \series bold
16957 _asm
16958 \series default
16959
16960 \begin_inset Quotes srd
16961 \end_inset
16962
16963  and 
16964 \begin_inset Quotes sld
16965 \end_inset
16966
16967
16968 \series bold
16969 _endasm;
16970 \series default
16971
16972 \begin_inset Quotes srd
16973 \end_inset
16974
16975
16976 \begin_inset Foot
16977 status open
16978
16979 \begin_layout Standard
16980 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16981  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16982  has to be used.
16983  The latter is also used in the library functions.
16984 \end_layout
16985
16986 \end_inset
16987
16988  to the beginning and the end of the function body:
16989 \end_layout
16990
16991 \begin_layout Verse
16992
16993 \family typewriter
16994 \size footnotesize
16995 /* With a cut and paste from the .asm file, we have something to start with.
16996 \newline
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 The
17001  function is not yet OK! (registers aren't saved) */ 
17002 \newline
17003 void to_buffer_asm(
17004  unsigned char c ) 
17005 \newline
17006
17007 \newline
17008 \InsetSpace ~
17009 \InsetSpace ~
17010 \InsetSpace ~
17011 \InsetSpace ~
17012 _asm
17013 \begin_inset LatexCommand \index{\_asm}
17014
17015 \end_inset
17016
17017
17018 \begin_inset LatexCommand \index{\_\_asm}
17019
17020 \end_inset
17021
17022
17023 \newline
17024 \InsetSpace ~
17025 \InsetSpace ~
17026 \InsetSpace ~
17027 \InsetSpace ~
17028 mov\InsetSpace ~
17029 \InsetSpace ~
17030 r2,dpl 
17031 \newline
17032 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17033 /* cast 
17034 \series bold
17035 needed
17036 \series default
17037  to avoid promotion
17038 \begin_inset LatexCommand \index{promotion to signed int}
17039
17040 \end_inset
17041
17042
17043 \begin_inset LatexCommand \index{type promotion}
17044
17045 \end_inset
17046
17047  to integer */
17048 \newline
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 \InsetSpace ~
17052 \InsetSpace ~
17053 mov\InsetSpace ~
17054 \InsetSpace ~
17055 a,_tail 
17056 \newline
17057 \InsetSpace ~
17058 \InsetSpace ~
17059 \InsetSpace ~
17060 \InsetSpace ~
17061 dec\InsetSpace ~
17062 \InsetSpace ~
17063
17064 \newline
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 \InsetSpace ~
17068 \InsetSpace ~
17069 mov\InsetSpace ~
17070 \InsetSpace ~
17071 r3,a 
17072 \newline
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 \InsetSpace ~
17076 \InsetSpace ~
17077 mov\InsetSpace ~
17078 \InsetSpace ~
17079 a,_head 
17080 \newline
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 cjne a,ar3,00106$ 
17086 \newline
17087 \InsetSpace ~
17088 \InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 ret
17092 \newline
17093 00106$:
17094  
17095 \newline
17096 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17097 \begin_inset LatexCommand \index{Aligned array}
17098
17099 \end_inset
17100
17101
17102 \newline
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 \InsetSpace ~
17106 \InsetSpace ~
17107 mov\InsetSpace ~
17108 \InsetSpace ~
17109 r3,_head 
17110 \newline
17111 \InsetSpace ~
17112 \InsetSpace ~
17113 \InsetSpace ~
17114 \InsetSpace ~
17115 inc\InsetSpace ~
17116 \InsetSpace ~
17117 _head 
17118 \newline
17119 \InsetSpace ~
17120 \InsetSpace ~
17121 \InsetSpace ~
17122 \InsetSpace ~
17123 mov\InsetSpace ~
17124 \InsetSpace ~
17125 dpl,r3 
17126 \newline
17127 \InsetSpace ~
17128 \InsetSpace ~
17129 \InsetSpace ~
17130 \InsetSpace ~
17131 mov\InsetSpace ~
17132 \InsetSpace ~
17133 dph,#(_buf >> 8) 
17134 \newline
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 mov\InsetSpace ~
17140 \InsetSpace ~
17141 a,r2 
17142 \newline
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 \InsetSpace ~
17147 movx @dptr,a
17148  
17149 \newline
17150 00103$: 
17151 \newline
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 ret
17157 \newline
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 \InsetSpace ~
17162 _endasm
17163 \begin_inset LatexCommand \index{\_endasm}
17164
17165 \end_inset
17166
17167
17168 \begin_inset LatexCommand \index{\_\_endasm}
17169
17170 \end_inset
17171
17172 ;
17173 \newline
17174
17175 \end_layout
17176
17177 \begin_layout Standard
17178 The new file buffer.c should compile with only one warning about the unreferenced
17179  function argument 'c'.
17180  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17181  (1) and finally have:
17182 \end_layout
17183
17184 \begin_layout Verse
17185
17186 \family typewriter
17187 \size footnotesize
17188 unsigned char __far __at(0x7f00) buf[0x100];
17189 \newline
17190 unsigned char head, tail;
17191 \newline
17192 #define
17193  USE_ASSEMBLY (1)
17194 \newline
17195
17196 \newline
17197 #if !USE_ASSEMBLY
17198 \newline
17199
17200 \newline
17201 void to_buffer( unsigned char c )
17202 \newline
17203 {
17204 \newline
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 if(
17210  head != (unsigned char)(tail-1) )
17211 \newline
17212 \InsetSpace ~
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 buf[ head++ ] = c;
17221 \newline
17222 }
17223 \newline
17224
17225 \newline
17226 #else
17227 \newline
17228
17229 \newline
17230 void to_buffer(
17231  unsigned char c )
17232 \newline
17233 {
17234 \newline
17235 \InsetSpace ~
17236 \InsetSpace ~
17237 \InsetSpace ~
17238 \InsetSpace ~
17239 c; // to avoid warning: unreferenced function argument
17240 \newline
17241 \InsetSpace ~
17242 \InsetSpace ~
17243 \InsetSpace ~
17244 \InsetSpace ~
17245 _asm
17246 \begin_inset LatexCommand \index{\_asm}
17247
17248 \end_inset
17249
17250
17251 \begin_inset LatexCommand \index{\_\_asm}
17252
17253 \end_inset
17254
17255
17256 \newline
17257 \InsetSpace ~
17258 \InsetSpace ~
17259 \InsetSpace ~
17260 \InsetSpace ~
17261 \InsetSpace ~
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 ; save used registers here.
17266  
17267 \newline
17268 \InsetSpace ~
17269 \InsetSpace ~
17270 \InsetSpace ~
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 \InsetSpace ~
17274 \InsetSpace ~
17275 \InsetSpace ~
17276 ; If we were still using r2,r3 we would have to push them here.
17277  
17278 \newline
17279 ; if( head != (unsigned char)(tail-1) )
17280 \newline
17281 \InsetSpace ~
17282 \InsetSpace ~
17283 \InsetSpace ~
17284 \InsetSpace ~
17285 \InsetSpace ~
17286 \InsetSpace ~
17287 \InsetSpace ~
17288 \InsetSpace ~
17289 mov\InsetSpace ~
17290  a,_tail
17291 \newline
17292 \InsetSpace ~
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 \InsetSpace ~
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 dec\InsetSpace ~
17301  a
17302 \newline
17303 \InsetSpace ~
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 \InsetSpace ~
17308 \InsetSpace ~
17309 \InsetSpace ~
17310 \InsetSpace ~
17311 xrl\InsetSpace ~
17312  a,_head
17313 \newline
17314 \InsetSpace ~
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 ; we
17323  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17324 \newline
17325 \InsetSpace ~
17326 \InsetSpace ~
17327 \InsetSpace ~
17328 \InsetSpace ~
17329 \InsetSpace ~
17330 \InsetSpace ~
17331 \InsetSpace ~
17332 \InsetSpace ~
17333 jz\InsetSpace ~
17334 \InsetSpace ~
17335  t_b_end$
17336 \newline
17337 \InsetSpace ~
17338 \InsetSpace ~
17339 \InsetSpace ~
17340 \InsetSpace ~
17341 \InsetSpace ~
17342 \InsetSpace ~
17343 \InsetSpace ~
17344 \InsetSpace ~
17345 ;
17346 \newline
17347 ;
17348  buf[ head++ ] = c;
17349 \newline
17350 \InsetSpace ~
17351 \InsetSpace ~
17352 \InsetSpace ~
17353 \InsetSpace ~
17354 \InsetSpace ~
17355 \InsetSpace ~
17356 \InsetSpace ~
17357 \InsetSpace ~
17358 mov\InsetSpace ~
17359  a,dpl \InsetSpace ~
17360 \InsetSpace ~
17361 \InsetSpace ~
17362 \InsetSpace ~
17363 \InsetSpace ~
17364 \InsetSpace ~
17365 \InsetSpace ~
17366 ; dpl holds lower byte of function argument
17367 \newline
17368 \InsetSpace ~
17369 \InsetSpace ~
17370 \InsetSpace ~
17371 \InsetSpace ~
17372 \InsetSpace ~
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 mov\InsetSpace ~
17377
17378  dpl,_head \InsetSpace ~
17379 \InsetSpace ~
17380 \InsetSpace ~
17381 ; buf is 0x100 byte aligned so head can be used directly
17382 \newline
17383 \InsetSpace ~
17384 \InsetSpace ~
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 \InsetSpace ~
17388 \InsetSpace ~
17389 \InsetSpace ~
17390 \InsetSpace ~
17391 mov\InsetSpace ~
17392  dph,#(_bu
17393 f>>8)
17394 \newline
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 \InsetSpace ~
17398 \InsetSpace ~
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 \InsetSpace ~
17402 \InsetSpace ~
17403 movx @dptr,a
17404 \newline
17405 \InsetSpace ~
17406 \InsetSpace ~
17407 \InsetSpace ~
17408 \InsetSpace ~
17409 \InsetSpace ~
17410 \InsetSpace ~
17411 \InsetSpace ~
17412 \InsetSpace ~
17413 inc \InsetSpace ~
17414 _head
17415 \newline
17416 \InsetSpace ~
17417 \InsetSpace ~
17418 \InsetSpace ~
17419 \InsetSpace ~
17420 \InsetSpace ~
17421 \InsetSpace ~
17422 \InsetSpace ~
17423 \InsetSpace ~
17424 ; we could do an ANL _head,#0x0f here to use a
17425  smaller buffer (see above)
17426 \newline
17427 t_b_end$:
17428 \newline
17429 \InsetSpace ~
17430 \InsetSpace ~
17431 \InsetSpace ~
17432 \InsetSpace ~
17433 \InsetSpace ~
17434 \InsetSpace ~
17435 \InsetSpace ~
17436 \InsetSpace ~
17437 ; restore used registers here 
17438 \newline
17439 \InsetSpace ~
17440 \InsetSpace ~
17441 \InsetSpace ~
17442 \InsetSpace ~
17443 _endasm
17444 \begin_inset LatexCommand \index{\_endasm}
17445
17446 \end_inset
17447
17448
17449 \begin_inset LatexCommand \index{\_\_endasm}
17450
17451 \end_inset
17452
17453 ;
17454 \newline
17455 }
17456 \newline
17457 #endif
17458 \end_layout
17459
17460 \begin_layout Standard
17461 The inline assembler code can contain any valid code understood by the assembler
17462 , this includes any assembler directives and comment lines.
17463  The assembler does not like some characters like ':' or ''' in comments.
17464  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17465 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17466
17467 \end_inset
17468
17469
17470 \begin_inset LatexCommand \index{Assembler documentation}
17471
17472 \end_inset
17473
17474  or online at 
17475 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17476
17477 \end_inset
17478
17479 \InsetSpace ~
17480 .
17481 \end_layout
17482
17483 \begin_layout Standard
17484 The compiler does not do any validation of the code within the 
17485 \family typewriter
17486 _asm
17487 \begin_inset LatexCommand \index{\_asm}
17488
17489 \end_inset
17490
17491
17492 \begin_inset LatexCommand \index{\_\_asm}
17493
17494 \end_inset
17495
17496  ...
17497  _endasm
17498 \size footnotesize
17499
17500 \begin_inset LatexCommand \index{\_endasm}
17501
17502 \end_inset
17503
17504
17505 \begin_inset LatexCommand \index{\_\_endasm}
17506
17507 \end_inset
17508
17509
17510 \size default
17511 ;
17512 \family default
17513  keyword pair.
17514  Specifically it will not know which registers are used and thus register
17515  pushing/popping
17516 \begin_inset LatexCommand \index{push/pop}
17517
17518 \end_inset
17519
17520  has to be done manually.
17521  
17522 \end_layout
17523
17524 \begin_layout Standard
17525 It is recommended that each assembly instruction (including labels) be placed
17526  in a separate line (as the example shows).
17527  When the -
17528 \begin_inset ERT
17529 status collapsed
17530
17531 \begin_layout Standard
17532
17533
17534 \backslash
17535 /
17536 \end_layout
17537
17538 \end_inset
17539
17540 -
17541 \emph on
17542 peep-asm
17543 \begin_inset LatexCommand \index{-\/-peep-asm}
17544
17545 \end_inset
17546
17547
17548 \emph default
17549  command line option is used, the inline assembler code will be passed through
17550  the peephole optimizer
17551 \begin_inset LatexCommand \index{Peephole optimizer}
17552
17553 \end_inset
17554
17555 .
17556  There are only a few (if any) cases where this option makes sense, it might
17557  cause some unexpected changes in the inline assembler code.
17558  Please go through the peephole optimizer rules defined in file 
17559 \emph on
17560 SDCCpeeph.def
17561 \emph default
17562  before using this option.
17563 \end_layout
17564
17565 \begin_layout Subsection
17566 Naked Functions
17567 \begin_inset LatexCommand \label{sub:Naked-Functions}
17568
17569 \end_inset
17570
17571
17572 \begin_inset LatexCommand \index{Naked functions}
17573
17574 \end_inset
17575
17576
17577 \end_layout
17578
17579 \begin_layout Standard
17580 A special keyword may be associated with a function declaring it as 
17581 \emph on
17582 _naked
17583 \begin_inset LatexCommand \index{\_naked}
17584
17585 \end_inset
17586
17587
17588 \begin_inset LatexCommand \index{\_\_naked}
17589
17590 \end_inset
17591
17592 .
17593  
17594 \emph default
17595 The 
17596 \emph on
17597 _naked
17598 \emph default
17599  function modifier attribute prevents the compiler from generating prologue
17600 \begin_inset LatexCommand \index{function prologue}
17601
17602 \end_inset
17603
17604  and epilogue
17605 \begin_inset LatexCommand \index{function epilogue}
17606
17607 \end_inset
17608
17609  code for that function.
17610  This means that the user is entirely responsible for such things as saving
17611  any registers that may need to be preserved, selecting the proper register
17612  bank, generating the 
17613 \emph on
17614 return
17615 \emph default
17616  instruction at the end, etc.
17617  Practically, this means that the contents of the function must be written
17618  in inline assembler.
17619  This is particularly useful for interrupt functions, which can have a large
17620  (and often unnecessary) prologue/epilogue.
17621  For example, compare the code generated by these two functions:
17622 \end_layout
17623
17624 \begin_layout Verse
17625
17626 \family typewriter
17627 volatile
17628 \begin_inset LatexCommand \index{volatile}
17629
17630 \end_inset
17631
17632  data unsigned char counter;
17633 \newline
17634
17635 \newline
17636 void simpleInterrupt(void) __interrupt
17637 \begin_inset LatexCommand \index{interrupt}
17638
17639 \end_inset
17640
17641
17642 \begin_inset LatexCommand \index{\_\_interrupt}
17643
17644 \end_inset
17645
17646  (1)
17647 \newline
17648 {
17649 \newline
17650 \InsetSpace ~
17651 \InsetSpace ~
17652 \InsetSpace ~
17653 \InsetSpace ~
17654 counter++;
17655 \newline
17656 }
17657 \newline
17658
17659 \newline
17660 void nakedInterrupt(void) __interrupt (2) __naked
17661 \newline
17662 {
17663 \newline
17664 \InsetSpace ~
17665 \InsetSpace ~
17666 \InsetSpace ~
17667 \InsetSpace ~
17668 _asm
17669 \begin_inset LatexCommand \index{\_asm}
17670
17671 \end_inset
17672
17673
17674 \begin_inset LatexCommand \index{\_\_asm}
17675
17676 \end_inset
17677
17678
17679 \newline
17680 \InsetSpace ~
17681 \InsetSpace ~
17682 \InsetSpace ~
17683 \InsetSpace ~
17684 \InsetSpace ~
17685 \InsetSpace ~
17686 inc\InsetSpace ~
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 \InsetSpace ~
17690 \InsetSpace ~
17691 _counter ; does not change flags, no need to save psw
17692 \newline
17693 \InsetSpace ~
17694 \InsetSpace ~
17695 \InsetSpace ~
17696 \InsetSpace ~
17697 \InsetSpace ~
17698 \InsetSpace ~
17699 reti\InsetSpace ~
17700 \InsetSpace ~
17701 \InsetSpace ~
17702 \InsetSpace ~
17703 ; MUST explicitly
17704  include ret or reti in _naked function.
17705 \newline
17706 \InsetSpace ~
17707 \InsetSpace ~
17708 \InsetSpace ~
17709 \InsetSpace ~
17710 _endasm
17711 \begin_inset LatexCommand \index{\_endasm}
17712
17713 \end_inset
17714
17715
17716 \begin_inset LatexCommand \index{\_\_endasm}
17717
17718 \end_inset
17719
17720 ;
17721 \newline
17722 }
17723 \end_layout
17724
17725 \begin_layout Standard
17726 For an 8051 target, the generated simpleInterrupt looks like:
17727 \end_layout
17728
17729 \begin_layout Verse
17730
17731 \family typewriter
17732 Note, this is an 
17733 \emph on
17734 outdated
17735 \emph default
17736  example, recent versions of SDCC generate
17737 \newline
17738 the 
17739 \emph on
17740 same
17741 \emph default
17742  code for simpleInterrupt() and nakedInterrupt()!
17743 \newline
17744
17745 \newline
17746 _simpleInterrupt:
17747 \newline
17748 \InsetSpace ~
17749 \InsetSpace ~
17750 \InsetSpace ~
17751 \InsetSpace ~
17752 push\InsetSpace ~
17753 \InsetSpace ~
17754 \InsetSpace ~
17755 \InsetSpace ~
17756 acc
17757 \newline
17758 \InsetSpace ~
17759 \InsetSpace ~
17760 \InsetSpace ~
17761 \InsetSpace ~
17762 push\InsetSpace ~
17763 \InsetSpace ~
17764 \InsetSpace ~
17765 \InsetSpace ~
17766 b
17767 \newline
17768 \InsetSpace ~
17769 \InsetSpace ~
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 pu
17773 sh\InsetSpace ~
17774 \InsetSpace ~
17775 \InsetSpace ~
17776 \InsetSpace ~
17777 dpl
17778 \newline
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 \InsetSpace ~
17782 \InsetSpace ~
17783 push\InsetSpace ~
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 dph
17788 \newline
17789 \InsetSpace ~
17790 \InsetSpace ~
17791 \InsetSpace ~
17792 \InsetSpace ~
17793 push\InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 \InsetSpace ~
17797 psw
17798 \newline
17799 \InsetSpace ~
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 mov\InsetSpace ~
17804 \InsetSpace ~
17805 \InsetSpace ~
17806 \InsetSpace ~
17807 \InsetSpace ~
17808 psw,#0x00
17809 \newline
17810 \InsetSpace ~
17811 \InsetSpace ~
17812 \InsetSpace ~
17813 \InsetSpace ~
17814 inc\InsetSpace ~
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 _counter
17820 \newline
17821 \InsetSpace ~
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 pop\InsetSpace ~
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 psw
17831 \newline
17832 \InsetSpace ~
17833 \InsetSpace ~
17834 \InsetSpace ~
17835 \InsetSpace ~
17836 pop\InsetSpace ~
17837 \InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 dph
17842 \newline
17843 \InsetSpace ~
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 pop\InsetSpace ~
17848 \InsetSpace ~
17849 \InsetSpace ~
17850 \InsetSpace ~
17851 \InsetSpace ~
17852 dpl
17853 \newline
17854 \InsetSpace ~
17855 \InsetSpace ~
17856 \InsetSpace ~
17857 \InsetSpace ~
17858 pop\InsetSpace ~
17859 \InsetSpace ~
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 b
17864 \newline
17865 \InsetSpace ~
17866 \InsetSpace ~
17867 \InsetSpace ~
17868 \InsetSpace ~
17869 pop\InsetSpace ~
17870 \InsetSpace ~
17871 \InsetSpace ~
17872 \InsetSpace ~
17873 \InsetSpace ~
17874 acc
17875 \newline
17876 \InsetSpace ~
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 reti
17881 \end_layout
17882
17883 \begin_layout Standard
17884 whereas nakedInterrupt looks like:
17885 \end_layout
17886
17887 \begin_layout Verse
17888
17889 \family typewriter
17890 _nakedInterrupt:
17891 \newline
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 inc\InsetSpace ~
17897 \InsetSpace ~
17898 \InsetSpace ~
17899 \InsetSpace ~
17900 _counter ; does not change flags, no need to save psw
17901 \newline
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 reti\InsetSpace ~
17907 \InsetSpace ~
17908 \InsetSpace ~
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 \InsetSpace ~
17914 \InsetSpace ~
17915 \InsetSpace ~
17916 \InsetSpace ~
17917 \InsetSpace ~
17918 ;
17919  MUST explicitly include ret or reti in _naked function
17920 \end_layout
17921
17922 \begin_layout Standard
17923 The related directive #pragma exclude
17924 \begin_inset LatexCommand \index{\#pragma exclude}
17925
17926 \end_inset
17927
17928  allows a more fine grained control over pushing & popping
17929 \begin_inset LatexCommand \index{push/pop}
17930
17931 \end_inset
17932
17933  the registers.
17934 \end_layout
17935
17936 \begin_layout Standard
17937 While there is nothing preventing you from writing C code inside a 
17938 \family typewriter
17939 _naked
17940 \family default
17941  function, there are many ways to shoot yourself in the foot doing this,
17942  and it is recommended that you stick to inline assembler.
17943 \end_layout
17944
17945 \begin_layout Subsection
17946 Use of Labels within Inline Assembler
17947 \end_layout
17948
17949 \begin_layout Standard
17950 SDCC allows the use of in-line assembler with a few restrictions regarding
17951  labels.
17952  All labels defined within inline assembler code have to be of the form
17953  
17954 \emph on
17955 nnnnn$
17956 \emph default
17957  where nnnnn is a number less than 100 (which implies a limit of utmost
17958  100 inline assembler labels 
17959 \emph on
17960 per function
17961 \emph default
17962 \noun on
17963 )
17964 \noun default
17965 .
17966 \begin_inset Foot
17967 status open
17968
17969 \begin_layout Standard
17970 This is a slightly more stringent rule than absolutely necessary, but stays
17971  always on the safe side.
17972  Labels in the form of nnnnn$ are local labels in the assembler, locality
17973  of which is confined within two labels of the standard form.
17974  The compiler uses the same form for labels within a function (but starting
17975  from nnnnn=00100); and places always a standard label at the beginning
17976  of a function, thus limiting the locality of labels within the scope of
17977  the function.
17978  So, if the inline assembler part would be embedded into C-code, an improperly
17979  placed non-local label in the assembler would break up the reference space
17980  for labels created by the compiler for the C-code, leading to an assembling
17981  error.
17982 \end_layout
17983
17984 \begin_layout Standard
17985 The numeric part of local labels does not need to have 5 digits (although
17986  this is the form of labels output by the compiler), any valid integer will
17987  do.
17988  Please refer to the assemblers documentation for further details.
17989 \end_layout
17990
17991 \end_inset
17992
17993  
17994 \end_layout
17995
17996 \begin_layout Verse
17997
17998 \family typewriter
17999 _asm
18000 \begin_inset LatexCommand \index{\_asm}
18001
18002 \end_inset
18003
18004
18005 \begin_inset LatexCommand \index{\_\_asm}
18006
18007 \end_inset
18008
18009  
18010 \newline
18011 \InsetSpace ~
18012 \InsetSpace ~
18013 \InsetSpace ~
18014 \InsetSpace ~
18015 mov\InsetSpace ~
18016 \InsetSpace ~
18017 \InsetSpace ~
18018 \InsetSpace ~
18019 \InsetSpace ~
18020 b,#10 
18021 \newline
18022 00001$: 
18023 \newline
18024 \InsetSpace ~
18025 \InsetSpace ~
18026 \InsetSpace ~
18027 \InsetSpace ~
18028 djnz\InsetSpace ~
18029 \InsetSpace ~
18030 \InsetSpace ~
18031 \InsetSpace ~
18032 b,00001$ 
18033 \newline
18034 _endasm
18035 \begin_inset LatexCommand \index{\_endasm}
18036
18037 \end_inset
18038
18039
18040 \begin_inset LatexCommand \index{\_\_endasm}
18041
18042 \end_inset
18043
18044  ;
18045 \end_layout
18046
18047 \begin_layout Standard
18048 Inline assembler code cannot reference any C-labels, however it can reference
18049  labels
18050 \begin_inset LatexCommand \index{Labels}
18051
18052 \end_inset
18053
18054  defined by the inline assembler, e.g.:
18055 \end_layout
18056
18057 \begin_layout Verse
18058
18059 \family typewriter
18060 foo() { 
18061 \newline
18062 \InsetSpace ~
18063 \InsetSpace ~
18064 \InsetSpace ~
18065 \InsetSpace ~
18066 /* some c code */ 
18067 \newline
18068 \InsetSpace ~
18069 \InsetSpace ~
18070 \InsetSpace ~
18071 \InsetSpace ~
18072 _asm 
18073 \newline
18074 \InsetSpace ~
18075 \InsetSpace ~
18076 \InsetSpace ~
18077 \InsetSpace ~
18078 \InsetSpace ~
18079 \InsetSpace ~
18080 ; some assembler code 
18081 \newline
18082 \InsetSpace ~
18083 \InsetSpace ~
18084 \InsetSpace ~
18085 \InsetSpace ~
18086 \InsetSpace ~
18087 \InsetSpace ~
18088 ljmp 0003$ 
18089 \newline
18090 \InsetSpace ~
18091 \InsetSpace ~
18092 \InsetSpace ~
18093 \InsetSpace ~
18094 _endasm;
18095  
18096 \newline
18097 \InsetSpace ~
18098 \InsetSpace ~
18099 \InsetSpace ~
18100 \InsetSpace ~
18101 /* some more c code */ 
18102 \newline
18103 clabel:\InsetSpace ~
18104 \InsetSpace ~
18105 /* inline assembler cannot reference this
18106  label */ 
18107 \begin_inset Foot
18108 status open
18109
18110 \begin_layout Standard
18111 Here, the C-label 
18112 \family typewriter
18113 clabel
18114 \family default
18115  is translated by the compiler into a local label, so the locality of labels
18116  within the function is not broken.
18117 \end_layout
18118
18119 \end_inset
18120
18121
18122 \newline
18123 \InsetSpace ~
18124 \InsetSpace ~
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 _asm
18128 \newline
18129 \InsetSpace ~
18130 \InsetSpace ~
18131 \InsetSpace ~
18132 \InsetSpace ~
18133 0003$: ;label (can be referenced by inline assembler only) 
18134 \newline
18135 \InsetSpace ~
18136 \InsetSpace ~
18137 \InsetSpace ~
18138 \InsetSpace ~
18139 _endasm
18140 \begin_inset LatexCommand \index{\_endasm}
18141
18142 \end_inset
18143
18144
18145 \begin_inset LatexCommand \index{\_\_endasm}
18146
18147 \end_inset
18148
18149  ; 
18150 \newline
18151 \InsetSpace ~
18152 \InsetSpace ~
18153 \InsetSpace ~
18154 \InsetSpace ~
18155 /* some more c code */
18156 \newline
18157 }
18158 \end_layout
18159
18160 \begin_layout Standard
18161 In other words inline assembly code can access labels defined in inline
18162  assembly within the scope of the function.
18163  The same goes the other way, i.e.
18164  labels defines in inline assembly can not be accessed by C statements.
18165 \end_layout
18166
18167 \begin_layout Section
18168 Interfacing with Assembler Code
18169 \begin_inset LatexCommand \index{Assembler routines}
18170
18171 \end_inset
18172
18173
18174 \end_layout
18175
18176 \begin_layout Subsection
18177 Global Registers used for Parameter Passing
18178 \begin_inset LatexCommand \index{Parameter passing}
18179
18180 \end_inset
18181
18182
18183 \end_layout
18184
18185 \begin_layout Standard
18186 The compiler always uses the global registers 
18187 \emph on
18188 DPL, DPH
18189 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18190
18191 \end_inset
18192
18193
18194 \begin_inset LatexCommand \index{DPTR}
18195
18196 \end_inset
18197
18198 , B
18199 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18200
18201 \end_inset
18202
18203  
18204 \emph default
18205 and
18206 \emph on
18207  ACC
18208 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18209
18210 \end_inset
18211
18212
18213 \emph default
18214  to pass the first (non-bit) parameter to a function, and also to pass the
18215  return value 
18216 \begin_inset LatexCommand \index{return value}
18217
18218 \end_inset
18219
18220 of function; according to the following scheme: one byte return value in
18221  
18222 \emph on
18223 DPL
18224 \emph default
18225 , two byte value in 
18226 \emph on
18227 DPL
18228 \emph default
18229  (LSB) and 
18230 \emph on
18231 DPH
18232 \emph default
18233  (MSB).
18234  three byte values (generic pointers) in 
18235 \emph on
18236 DPH
18237 \emph default
18238
18239 \emph on
18240 DPL
18241 \emph default
18242  and 
18243 \emph on
18244 B
18245 \emph default
18246 , and four byte values in 
18247 \emph on
18248 DPH
18249 \emph default
18250
18251 \emph on
18252 DPL
18253 \emph default
18254 ,
18255 \emph on
18256  B
18257 \emph default
18258  and 
18259 \emph on
18260 ACC
18261 \emph default
18262 .
18263  Generic pointers
18264 \begin_inset LatexCommand \index{generic pointer}
18265
18266 \end_inset
18267
18268  contain type of accessed memory in 
18269 \emph on
18270 B
18271 \emph default
18272
18273 \series bold
18274 0x00
18275 \series default
18276  -- xdata/far, 
18277 \series bold
18278 0x40
18279 \series default
18280  -- idata/near -- , 
18281 \series bold
18282 0x60
18283 \series default
18284  -- pdata, 
18285 \series bold
18286 0x80
18287 \series default
18288  -- code
18289 \begin_inset Note Note
18290 status collapsed
18291
18292 \begin_layout Standard
18293 This might not be the case of certain memory models (medium???)
18294 \end_layout
18295
18296 \end_inset
18297
18298 .
18299 \end_layout
18300
18301 \begin_layout Standard
18302 The second parameter onwards is either allocated on the stack (for reentrant
18303  routines or if -
18304 \begin_inset ERT
18305 status collapsed
18306
18307 \begin_layout Standard
18308
18309
18310 \backslash
18311 /
18312 \end_layout
18313
18314 \end_inset
18315
18316 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18317 \end_layout
18318
18319 \begin_layout Standard
18320 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18321  space for reentrant functions or allocated directly in bit memory otherwise.
18322 \end_layout
18323
18324 \begin_layout Standard
18325 Functions (with two or more parameters or bit parameters) that are called
18326  through function pointers
18327 \begin_inset LatexCommand \index{function pointers}
18328
18329 \end_inset
18330
18331  must therefor be reentrant so the compiler knows how to pass the parameters.
18332 \end_layout
18333
18334 \begin_layout Subsection
18335 Registers usage
18336 \end_layout
18337
18338 \begin_layout Standard
18339 Unless the called function is declared as 
18340 \family typewriter
18341 _naked
18342 \family default
18343
18344 \begin_inset LatexCommand \index{naked}
18345
18346 \end_inset
18347
18348 , or the -
18349 \begin_inset ERT
18350 status collapsed
18351
18352 \begin_layout Standard
18353
18354
18355 \backslash
18356 /
18357 \end_layout
18358
18359 \end_inset
18360
18361 -callee-saves
18362 \begin_inset LatexCommand \index{-\/-callee-saves}
18363
18364 \end_inset
18365
18366 /-
18367 \begin_inset ERT
18368 status collapsed
18369
18370 \begin_layout Standard
18371
18372
18373 \backslash
18374 /
18375 \end_layout
18376
18377 \end_inset
18378
18379 -all-callee-saves command line option or the corresponding callee_saves
18380  pragma are used, the caller will save the registers (
18381 \emph on
18382 R0-R7
18383 \emph default
18384 ) around the call, so the called function can destroy they content freely.
18385 \end_layout
18386
18387 \begin_layout Standard
18388 If the called function is not declared as 
18389 \family typewriter
18390 _naked
18391 \family default
18392 , the caller will swap register banks around the call, if caller and callee
18393  use different register banks (having them defined by the 
18394 \family typewriter
18395 _using
18396 \family default
18397  modifier).
18398  
18399 \end_layout
18400
18401 \begin_layout Standard
18402 The called function can also use 
18403 \emph on
18404 DPL
18405 \emph default
18406
18407 \emph on
18408 DPH
18409 \emph default
18410
18411 \emph on
18412 B
18413 \emph default
18414  and 
18415 \emph on
18416 ACC
18417 \emph default
18418  observing that they are used for parameter/return value passing.
18419 \end_layout
18420
18421 \begin_layout Subsection
18422 Assembler Routine (non-reentrant)
18423 \end_layout
18424
18425 \begin_layout Standard
18426 In the following example
18427 \begin_inset LatexCommand \index{reentrant}
18428
18429 \end_inset
18430
18431
18432 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18433
18434 \end_inset
18435
18436  the function c_func calls an assembler routine asm_func, which takes two
18437  parameters
18438 \begin_inset LatexCommand \index{function parameter}
18439
18440 \end_inset
18441
18442 .
18443 \end_layout
18444
18445 \begin_layout Verse
18446
18447 \family typewriter
18448 extern int asm_func(unsigned char, unsigned char);
18449 \newline
18450
18451 \newline
18452 int c_func (unsigned char
18453  i, unsigned char j)
18454 \newline
18455 {
18456 \newline
18457 \InsetSpace ~
18458 \InsetSpace ~
18459 \InsetSpace ~
18460 \InsetSpace ~
18461 return asm_func(i,j);
18462 \newline
18463 }
18464 \newline
18465
18466 \newline
18467 int main()
18468 \newline
18469 {
18470 \newline
18471 \InsetSpace ~
18472 \InsetSpace ~
18473 \InsetSpace ~
18474 \InsetSpace ~
18475 return c_func(10,9);
18476 \newline
18477 }
18478 \end_layout
18479
18480 \begin_layout Standard
18481 The corresponding assembler function is:
18482 \end_layout
18483
18484 \begin_layout Verse
18485
18486 \family typewriter
18487 .globl _asm_func_PARM_2 
18488 \newline
18489 \InsetSpace ~
18490 \InsetSpace ~
18491 \InsetSpace ~
18492 \InsetSpace ~
18493 \InsetSpace ~
18494 \InsetSpace ~
18495 \InsetSpace ~
18496 \InsetSpace ~
18497 .globl _asm_func 
18498 \newline
18499 \InsetSpace ~
18500 \InsetSpace ~
18501 \InsetSpace ~
18502 \InsetSpace ~
18503 \InsetSpace ~
18504 \InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 .area OSEG 
18508 \newline
18509 _asm_func_PARM_2:
18510 \newline
18511 \InsetSpace ~
18512 \InsetSpace ~
18513 \InsetSpace ~
18514 \InsetSpace ~
18515 \InsetSpace ~
18516 \InsetSpace ~
18517 \InsetSpace ~
18518 \InsetSpace ~
18519 .ds   
18520  1 
18521 \newline
18522 \InsetSpace ~
18523 \InsetSpace ~
18524 \InsetSpace ~
18525 \InsetSpace ~
18526 \InsetSpace ~
18527 \InsetSpace ~
18528 \InsetSpace ~
18529 \InsetSpace ~
18530 .area CSEG 
18531 \newline
18532 _asm_func: 
18533 \newline
18534 \InsetSpace ~
18535 \InsetSpace ~
18536 \InsetSpace ~
18537 \InsetSpace ~
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 mov\InsetSpace ~
18543 \InsetSpace ~
18544 \InsetSpace ~
18545 \InsetSpace ~
18546 a,dpl 
18547 \newline
18548 \InsetSpace ~
18549 \InsetSpace ~
18550 \InsetSpace ~
18551 \InsetSpace ~
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 \InsetSpace ~
18555 \InsetSpace ~
18556 add\InsetSpace ~
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 \InsetSpace ~
18560 a,_asm_func_PARM_2 
18561 \newline
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 \InsetSpace ~
18565 \InsetSpace ~
18566 \InsetSpace ~
18567 \InsetSpace ~
18568 \InsetSpace ~
18569 \InsetSpace ~
18570 mov\InsetSpace ~
18571 \InsetSpace ~
18572 \InsetSpace ~
18573 \InsetSpace ~
18574 dpl,a 
18575 \newline
18576 \InsetSpace ~
18577 \InsetSpace ~
18578 \InsetSpace ~
18579 \InsetSpace ~
18580 \InsetSpace ~
18581 \InsetSpace ~
18582 \InsetSpace ~
18583 \InsetSpace ~
18584 mov\InsetSpace ~
18585 \InsetSpace ~
18586 \InsetSpace ~
18587 \InsetSpace ~
18588 dph
18589 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18590
18591 \end_inset
18592
18593 ,#0x00 
18594 \newline
18595 \InsetSpace ~
18596 \InsetSpace ~
18597 \InsetSpace ~
18598 \InsetSpace ~
18599 \InsetSpace ~
18600 \InsetSpace ~
18601 \InsetSpace ~
18602 \InsetSpace ~
18603 ret
18604 \end_layout
18605
18606 \begin_layout Standard
18607 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18608  the parameter number starting from 1, and counting from the left.
18609  The first parameter is passed in 
18610 \emph on
18611 DPH
18612 \emph default
18613
18614 \emph on
18615 DPL
18616 \emph default
18617
18618 \emph on
18619 B
18620 \emph default
18621  and 
18622 \emph on
18623 ACC
18624 \emph default
18625  according to the description above.
18626  The variable name for the second parameter will be _<function_name>_PARM_2.
18627 \newline
18628
18629 \newline
18630 Assem
18631 ble the assembler routine with the following command:
18632 \newline
18633
18634 \newline
18635
18636 \family sans
18637 \series bold
18638 asx8051 -losg asmfunc.asm
18639 \newline
18640
18641 \newline
18642
18643 \family default
18644 \series default
18645 Then compile and link the assembler routine to the C source file with the
18646  following command:
18647 \newline
18648
18649 \newline
18650
18651 \family sans
18652 \series bold
18653 sdcc cfunc.c asmfunc.rel
18654 \end_layout
18655
18656 \begin_layout Subsection
18657 Assembler Routine (reentrant)
18658 \end_layout
18659
18660 \begin_layout Standard
18661 In this case
18662 \begin_inset LatexCommand \index{reentrant}
18663
18664 \end_inset
18665
18666
18667 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18668
18669 \end_inset
18670
18671  the second parameter
18672 \begin_inset LatexCommand \index{function parameter}
18673
18674 \end_inset
18675
18676  onwards will be passed on the stack, the parameters are pushed from right
18677  to left i.e.
18678  before the call the second leftmost parameter will be on the top of the
18679  stack (the leftmost parameter is passed in registers).
18680  Here is an example:
18681 \end_layout
18682
18683 \begin_layout Verse
18684
18685 \family typewriter
18686 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18687 \newline
18688
18689 \newline
18690 int
18691  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18692 \newline
18693 {
18694  
18695 \newline
18696 \InsetSpace ~
18697 \InsetSpace ~
18698 \InsetSpace ~
18699 \InsetSpace ~
18700 return asm_func(i,j,k); 
18701 \newline
18702
18703 \newline
18704
18705 \newline
18706 int main() 
18707 \newline
18708
18709 \newline
18710 \InsetSpace ~
18711 \InsetSpace ~
18712 \InsetSpace ~
18713 \InsetSpace ~
18714 return c_func(10,9,8); 
18715 \newline
18716 }
18717 \end_layout
18718
18719 \begin_layout Standard
18720 The corresponding (unoptimized) assembler routine is:
18721 \end_layout
18722
18723 \begin_layout Verse
18724
18725 \family typewriter
18726 .globl _asm_func 
18727 \newline
18728 _asm_func: 
18729 \newline
18730 \InsetSpace ~
18731 \InsetSpace ~
18732 \InsetSpace ~
18733 \InsetSpace ~
18734 push\InsetSpace ~
18735 _bp 
18736 \newline
18737 \InsetSpace ~
18738 \InsetSpace ~
18739 \InsetSpace ~
18740 \InsetSpace ~
18741 mov\InsetSpace ~
18742 \InsetSpace ~
18743 _bp,sp\InsetSpace ~
18744 \InsetSpace ~
18745 \InsetSpace ~
18746 \InsetSpace ~
18747 \InsetSpace ~
18748 \InsetSpace ~
18749 ;stack contains: _bp, return
18750  address, second parameter, third parameter
18751 \newline
18752 \InsetSpace ~
18753 \InsetSpace ~
18754 \InsetSpace ~
18755 \InsetSpace ~
18756 mov\InsetSpace ~
18757 \InsetSpace ~
18758 r2,dpl
18759 \newline
18760 \InsetSpace ~
18761 \InsetSpace ~
18762 \InsetSpace ~
18763 \InsetSpace ~
18764 mov\InsetSpace ~
18765 \InsetSpace ~
18766 a,_bp
18767 \newline
18768 \InsetSpace ~
18769 \InsetSpace ~
18770 \InsetSpace ~
18771 \InsetSpace ~
18772 add\InsetSpace ~
18773 \InsetSpace ~
18774 a,#0xfd\InsetSpace ~
18775 \InsetSpace ~
18776 \InsetSpace ~
18777 \InsetSpace ~
18778 \InsetSpace ~
18779 ;calculate
18780  pointer to the second parameter
18781 \newline
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 \InsetSpace ~
18785 \InsetSpace ~
18786 mov\InsetSpace ~
18787 \InsetSpace ~
18788 r0,a 
18789 \newline
18790 \InsetSpace ~
18791 \InsetSpace ~
18792 \InsetSpace ~
18793 \InsetSpace ~
18794 mov\InsetSpace ~
18795 \InsetSpace ~
18796 a,_bp 
18797 \newline
18798 \InsetSpace ~
18799 \InsetSpace ~
18800 \InsetSpace ~
18801 \InsetSpace ~
18802 add\InsetSpace ~
18803 \InsetSpace ~
18804 a,#0xfc\InsetSpace ~
18805 \InsetSpace ~
18806 \InsetSpace ~
18807 \InsetSpace ~
18808 \InsetSpace ~
18809 ;calculate pointer
18810  to the rightmost parameter
18811 \newline
18812 \InsetSpace ~
18813 \InsetSpace ~
18814 \InsetSpace ~
18815 \InsetSpace ~
18816 mov\InsetSpace ~
18817 \InsetSpace ~
18818 r1,a 
18819 \newline
18820 \InsetSpace ~
18821 \InsetSpace ~
18822 \InsetSpace ~
18823 \InsetSpace ~
18824 mov\InsetSpace ~
18825 \InsetSpace ~
18826 a,@r0
18827 \newline
18828 \InsetSpace ~
18829 \InsetSpace ~
18830 \InsetSpace ~
18831 \InsetSpace ~
18832 add\InsetSpace ~
18833 \InsetSpace ~
18834 a,@r1
18835 \newline
18836 \InsetSpace ~
18837 \InsetSpace ~
18838 \InsetSpace ~
18839 \InsetSpace ~
18840 add\InsetSpace ~
18841 \InsetSpace ~
18842 a,r2\InsetSpace ~
18843 \InsetSpace ~
18844 \InsetSpace ~
18845 \InsetSpace ~
18846 \InsetSpace ~
18847 \InsetSpace ~
18848 \InsetSpace ~
18849 \InsetSpace ~
18850 ;calculate the
18851  result (= sum of all three parameters)
18852 \newline
18853 \InsetSpace ~
18854 \InsetSpace ~
18855 \InsetSpace ~
18856 \InsetSpace ~
18857 mov\InsetSpace ~
18858 \InsetSpace ~
18859 dpl,a\InsetSpace ~
18860 \InsetSpace ~
18861 \InsetSpace ~
18862 \InsetSpace ~
18863 \InsetSpace ~
18864 \InsetSpace ~
18865 \InsetSpace ~
18866 ;return value goes into dptr
18867  (cast into int)
18868 \newline
18869 \InsetSpace ~
18870 \InsetSpace ~
18871 \InsetSpace ~
18872 \InsetSpace ~
18873 mov\InsetSpace ~
18874 \InsetSpace ~
18875 dph,#0x00 
18876 \newline
18877 \InsetSpace ~
18878 \InsetSpace ~
18879 \InsetSpace ~
18880 \InsetSpace ~
18881 mov\InsetSpace ~
18882 \InsetSpace ~
18883 sp,_bp 
18884 \newline
18885 \InsetSpace ~
18886 \InsetSpace ~
18887 \InsetSpace ~
18888 \InsetSpace ~
18889 pop\InsetSpace ~
18890 \InsetSpace ~
18891 _bp 
18892 \newline
18893 \InsetSpace ~
18894 \InsetSpace ~
18895 \InsetSpace ~
18896 \InsetSpace ~
18897 ret
18898 \end_layout
18899
18900 \begin_layout Standard
18901 The compiling and linking procedure remains the same, however note the extra
18902  entry & exit linkage required for the assembler code, _bp is the stack
18903  frame pointer and is used to compute the offset into the stack for parameters
18904  and local variables.
18905 \begin_inset VSpace bigskip
18906 \end_inset
18907
18908
18909 \end_layout
18910
18911 \begin_layout Section
18912 int (16 bit)
18913 \begin_inset LatexCommand \index{int (16 bit)}
18914
18915 \end_inset
18916
18917  and long (32 bit)
18918 \begin_inset LatexCommand \index{long (32 bit)}
18919
18920 \end_inset
18921
18922  Support
18923 \end_layout
18924
18925 \begin_layout Standard
18926 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18927  multiplication and modulus operations are implemented by support routines.
18928  These support routines are all developed in ANSI-C to facilitate porting
18929  to other MCUs, although some model specific assembler optimizations are
18930  used.
18931  The following files contain the described routines, all of them can be
18932  found in <installdir>/share/sdcc/lib.
18933 \newline
18934
18935 \end_layout
18936
18937 \begin_layout Standard
18938 \align center
18939 \begin_inset Tabular
18940 <lyxtabular version="3" rows="11" columns="2">
18941 <features>
18942 <column alignment="left" valignment="top" leftline="true" width="0">
18943 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18944 <row topline="true" bottomline="true">
18945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18946 \begin_inset Text
18947
18948 \begin_layout Standard
18949
18950 \series bold
18951 Function
18952 \end_layout
18953
18954 \end_inset
18955 </cell>
18956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18957 \begin_inset Text
18958
18959 \begin_layout Standard
18960
18961 \series bold
18962 Description
18963 \end_layout
18964
18965 \end_inset
18966 </cell>
18967 </row>
18968 <row topline="true">
18969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18970 \begin_inset Text
18971
18972 \begin_layout Standard
18973 _mulint.c 
18974 \end_layout
18975
18976 \end_inset
18977 </cell>
18978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18979 \begin_inset Text
18980
18981 \begin_layout Standard
18982 16 bit multiplication
18983 \end_layout
18984
18985 \end_inset
18986 </cell>
18987 </row>
18988 <row topline="true">
18989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18990 \begin_inset Text
18991
18992 \begin_layout Standard
18993 _divsint.c 
18994 \end_layout
18995
18996 \end_inset
18997 </cell>
18998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18999 \begin_inset Text
19000
19001 \begin_layout Standard
19002  signed 16 bit division (calls _divuint)
19003 \end_layout
19004
19005 \end_inset
19006 </cell>
19007 </row>
19008 <row topline="true">
19009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19010 \begin_inset Text
19011
19012 \begin_layout Standard
19013 _divuint.c 
19014 \end_layout
19015
19016 \end_inset
19017 </cell>
19018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19019 \begin_inset Text
19020
19021 \begin_layout Standard
19022  unsigned 16 bit division
19023 \end_layout
19024
19025 \end_inset
19026 </cell>
19027 </row>
19028 <row topline="true">
19029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19030 \begin_inset Text
19031
19032 \begin_layout Standard
19033 _modsint.c
19034 \end_layout
19035
19036 \end_inset
19037 </cell>
19038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19039 \begin_inset Text
19040
19041 \begin_layout Standard
19042 signed 16 bit modulus (calls _moduint)
19043 \end_layout
19044
19045 \end_inset
19046 </cell>
19047 </row>
19048 <row topline="true">
19049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19050 \begin_inset Text
19051
19052 \begin_layout Standard
19053 _moduint.c
19054 \end_layout
19055
19056 \end_inset
19057 </cell>
19058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19059 \begin_inset Text
19060
19061 \begin_layout Standard
19062 unsigned 16 bit modulus
19063 \end_layout
19064
19065 \end_inset
19066 </cell>
19067 </row>
19068 <row topline="true">
19069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19070 \begin_inset Text
19071
19072 \begin_layout Standard
19073 _mullong.c
19074 \end_layout
19075
19076 \end_inset
19077 </cell>
19078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19079 \begin_inset Text
19080
19081 \begin_layout Standard
19082 32 bit multiplication
19083 \end_layout
19084
19085 \end_inset
19086 </cell>
19087 </row>
19088 <row topline="true">
19089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19090 \begin_inset Text
19091
19092 \begin_layout Standard
19093 _divslong.c 
19094 \end_layout
19095
19096 \end_inset
19097 </cell>
19098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19099 \begin_inset Text
19100
19101 \begin_layout Standard
19102  signed 32 division (calls _divulong)
19103 \end_layout
19104
19105 \end_inset
19106 </cell>
19107 </row>
19108 <row topline="true">
19109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19110 \begin_inset Text
19111
19112 \begin_layout Standard
19113 _divulong.c 
19114 \end_layout
19115
19116 \end_inset
19117 </cell>
19118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19119 \begin_inset Text
19120
19121 \begin_layout Standard
19122 unsigned 32 division
19123 \end_layout
19124
19125 \end_inset
19126 </cell>
19127 </row>
19128 <row topline="true">
19129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19130 \begin_inset Text
19131
19132 \begin_layout Standard
19133 _modslong.c
19134 \end_layout
19135
19136 \end_inset
19137 </cell>
19138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19139 \begin_inset Text
19140
19141 \begin_layout Standard
19142  signed 32 bit modulus (calls _modulong)
19143 \end_layout
19144
19145 \end_inset
19146 </cell>
19147 </row>
19148 <row topline="true" bottomline="true">
19149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19150 \begin_inset Text
19151
19152 \begin_layout Standard
19153 _modulong.c
19154 \end_layout
19155
19156 \end_inset
19157 </cell>
19158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19159 \begin_inset Text
19160
19161 \begin_layout Standard
19162 unsigned 32 bit modulus
19163 \end_layout
19164
19165 \end_inset
19166 </cell>
19167 </row>
19168 </lyxtabular>
19169
19170 \end_inset
19171
19172
19173 \newline
19174
19175 \end_layout
19176
19177 \begin_layout Standard
19178 Since they are compiled as 
19179 \emph on
19180 non-reentrant
19181 \emph default
19182
19183 \begin_inset LatexCommand \index{reentrant}
19184
19185 \end_inset
19186
19187 , interrupt
19188 \begin_inset LatexCommand \index{interrupt}
19189
19190 \end_inset
19191
19192  service routines should not do any of the above operations.
19193  If this is unavoidable then the above routines will need to be compiled
19194  with the 
19195 \emph on
19196 -
19197 \begin_inset ERT
19198 status collapsed
19199
19200 \begin_layout Standard
19201
19202
19203 \backslash
19204 /
19205 \end_layout
19206
19207 \end_inset
19208
19209 -stack-auto
19210 \begin_inset LatexCommand \index{-\/-stack-auto}
19211
19212 \end_inset
19213
19214
19215 \emph default
19216  option, after which the source program will have to be compiled with 
19217 \emph on
19218 -
19219 \begin_inset ERT
19220 status collapsed
19221
19222 \begin_layout Standard
19223
19224
19225 \backslash
19226 /
19227 \end_layout
19228
19229 \end_inset
19230
19231 -int-long-reent
19232 \begin_inset LatexCommand \index{-\/-int-long-reent}
19233
19234 \end_inset
19235
19236
19237 \emph default
19238  option.
19239  Notice that you don't have to call these routines directly.
19240  The compiler will use them automatically every time an integer operation
19241  is required.
19242 \end_layout
19243
19244 \begin_layout Section
19245 Floating Point Support
19246 \begin_inset LatexCommand \index{Floating point support}
19247
19248 \end_inset
19249
19250
19251 \end_layout
19252
19253 \begin_layout Standard
19254 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19255  The floating point support routines are derived from gcc's floatlib.c and
19256  consist of the following routines:
19257 \newline
19258
19259 \end_layout
19260
19261 \begin_layout Standard
19262 \align center
19263
19264 \size footnotesize
19265 \begin_inset Tabular
19266 <lyxtabular version="3" rows="17" columns="2">
19267 <features>
19268 <column alignment="left" valignment="top" leftline="true" width="0">
19269 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19270 <row topline="true" bottomline="true">
19271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19272 \begin_inset Text
19273
19274 \begin_layout Standard
19275
19276 \family roman
19277 \series medium
19278 \shape up
19279 \size normal
19280 \emph off
19281 \bar no
19282 \noun off
19283 \color none
19284 Function 
19285 \end_layout
19286
19287 \end_inset
19288 </cell>
19289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19290 \begin_inset Text
19291
19292 \begin_layout Standard
19293 Description
19294 \end_layout
19295
19296 \end_inset
19297 </cell>
19298 </row>
19299 <row topline="true">
19300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19301 \begin_inset Text
19302
19303 \begin_layout Standard
19304
19305 \family roman
19306 \series medium
19307 \shape up
19308 \size normal
19309 \emph off
19310 \bar no
19311 \noun off
19312 \color none
19313 _fsadd.c
19314 \end_layout
19315
19316 \end_inset
19317 </cell>
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19319 \begin_inset Text
19320
19321 \begin_layout Standard
19322
19323 \family roman
19324 \series medium
19325 \shape up
19326 \size normal
19327 \emph off
19328 \bar no
19329 \noun off
19330 \color none
19331 add floating point numbers
19332 \end_layout
19333
19334 \end_inset
19335 </cell>
19336 </row>
19337 <row topline="true">
19338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19339 \begin_inset Text
19340
19341 \begin_layout Standard
19342
19343 \family roman
19344 \series medium
19345 \shape up
19346 \size normal
19347 \emph off
19348 \bar no
19349 \noun off
19350 \color none
19351 _fssub.c 
19352 \end_layout
19353
19354 \end_inset
19355 </cell>
19356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19357 \begin_inset Text
19358
19359 \begin_layout Standard
19360
19361 \family roman
19362 \series medium
19363 \shape up
19364 \size normal
19365 \emph off
19366 \bar no
19367 \noun off
19368 \color none
19369 subtract floating point numbers 
19370 \end_layout
19371
19372 \end_inset
19373 </cell>
19374 </row>
19375 <row topline="true">
19376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19377 \begin_inset Text
19378
19379 \begin_layout Standard
19380
19381 \family roman
19382 \series medium
19383 \shape up
19384 \size normal
19385 \emph off
19386 \bar no
19387 \noun off
19388 \color none
19389 _fsdiv.c 
19390 \end_layout
19391
19392 \end_inset
19393 </cell>
19394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19395 \begin_inset Text
19396
19397 \begin_layout Standard
19398
19399 \family roman
19400 \series medium
19401 \shape up
19402 \size normal
19403 \emph off
19404 \bar no
19405 \noun off
19406 \color none
19407 divide floating point numbers 
19408 \end_layout
19409
19410 \end_inset
19411 </cell>
19412 </row>
19413 <row topline="true">
19414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19415 \begin_inset Text
19416
19417 \begin_layout Standard
19418
19419 \family roman
19420 \series medium
19421 \shape up
19422 \size normal
19423 \emph off
19424 \bar no
19425 \noun off
19426 \color none
19427 _fsmul.c 
19428 \end_layout
19429
19430 \end_inset
19431 </cell>
19432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19433 \begin_inset Text
19434
19435 \begin_layout Standard
19436
19437 \family roman
19438 \series medium
19439 \shape up
19440 \size normal
19441 \emph off
19442 \bar no
19443 \noun off
19444 \color none
19445 multiply floating point numbers 
19446 \end_layout
19447
19448 \end_inset
19449 </cell>
19450 </row>
19451 <row topline="true">
19452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19453 \begin_inset Text
19454
19455 \begin_layout Standard
19456
19457 \family roman
19458 \series medium
19459 \shape up
19460 \size normal
19461 \emph off
19462 \bar no
19463 \noun off
19464 \color none
19465 _fs2uchar.c
19466 \end_layout
19467
19468 \end_inset
19469 </cell>
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19471 \begin_inset Text
19472
19473 \begin_layout Standard
19474
19475 \family roman
19476 \series medium
19477 \shape up
19478 \size normal
19479 \emph off
19480 \bar no
19481 \noun off
19482 \color none
19483 convert floating point to unsigned char
19484 \end_layout
19485
19486 \end_inset
19487 </cell>
19488 </row>
19489 <row topline="true">
19490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19491 \begin_inset Text
19492
19493 \begin_layout Standard
19494
19495 \family roman
19496 \series medium
19497 \shape up
19498 \size normal
19499 \emph off
19500 \bar no
19501 \noun off
19502 \color none
19503 _fs2char.c
19504 \end_layout
19505
19506 \end_inset
19507 </cell>
19508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19509 \begin_inset Text
19510
19511 \begin_layout Standard
19512
19513 \family roman
19514 \series medium
19515 \shape up
19516 \size normal
19517 \emph off
19518 \bar no
19519 \noun off
19520 \color none
19521 convert floating point to signed char
19522 \end_layout
19523
19524 \end_inset
19525 </cell>
19526 </row>
19527 <row topline="true">
19528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19529 \begin_inset Text
19530
19531 \begin_layout Standard
19532
19533 \family roman
19534 \series medium
19535 \shape up
19536 \size normal
19537 \emph off
19538 \bar no
19539 \noun off
19540 \color none
19541 _fs2uint.c
19542 \end_layout
19543
19544 \end_inset
19545 </cell>
19546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19547 \begin_inset Text
19548
19549 \begin_layout Standard
19550
19551 \family roman
19552 \series medium
19553 \shape up
19554 \size normal
19555 \emph off
19556 \bar no
19557 \noun off
19558 \color none
19559 convert floating point to unsigned int
19560 \end_layout
19561
19562 \end_inset
19563 </cell>
19564 </row>
19565 <row topline="true">
19566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19567 \begin_inset Text
19568
19569 \begin_layout Standard
19570
19571 \family roman
19572 \series medium
19573 \shape up
19574 \size normal
19575 \emph off
19576 \bar no
19577 \noun off
19578 \color none
19579 _fs2int.c
19580 \end_layout
19581
19582 \end_inset
19583 </cell>
19584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19585 \begin_inset Text
19586
19587 \begin_layout Standard
19588
19589 \family roman
19590 \series medium
19591 \shape up
19592 \size normal
19593 \emph off
19594 \bar no
19595 \noun off
19596 \color none
19597 convert floating point to signed int
19598 \end_layout
19599
19600 \end_inset
19601 </cell>
19602 </row>
19603 <row topline="true">
19604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19605 \begin_inset Text
19606
19607 \begin_layout Standard
19608
19609 \family roman
19610 \series medium
19611 \shape up
19612 \size normal
19613 \emph off
19614 \bar no
19615 \noun off
19616 \color none
19617 _fs2ulong.
19618 \family default
19619 \series default
19620 \shape default
19621 \size default
19622 \emph default
19623 \bar default
19624 \noun default
19625 c
19626 \end_layout
19627
19628 \end_inset
19629 </cell>
19630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19631 \begin_inset Text
19632
19633 \begin_layout Standard
19634
19635 \family roman
19636 \series medium
19637 \shape up
19638 \size normal
19639 \emph off
19640 \bar no
19641 \noun off
19642 \color none
19643 convert floating point to unsigned long
19644 \end_layout
19645
19646 \end_inset
19647 </cell>
19648 </row>
19649 <row topline="true">
19650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19651 \begin_inset Text
19652
19653 \begin_layout Standard
19654
19655 \family roman
19656 \series medium
19657 \shape up
19658 \size normal
19659 \emph off
19660 \bar no
19661 \noun off
19662 \color none
19663 _fs2long.c
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
19673 \family roman
19674 \series medium
19675 \shape up
19676 \size normal
19677 \emph off
19678 \bar no
19679 \noun off
19680 \color none
19681 convert floating point to signed long
19682 \end_layout
19683
19684 \end_inset
19685 </cell>
19686 </row>
19687 <row topline="true">
19688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19689 \begin_inset Text
19690
19691 \begin_layout Standard
19692
19693 \family roman
19694 \series medium
19695 \shape up
19696 \size normal
19697 \emph off
19698 \bar no
19699 \noun off
19700 \color none
19701 _uchar2fs.c
19702 \end_layout
19703
19704 \end_inset
19705 </cell>
19706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19707 \begin_inset Text
19708
19709 \begin_layout Standard
19710
19711 \family roman
19712 \series medium
19713 \shape up
19714 \size normal
19715 \emph off
19716 \bar no
19717 \noun off
19718 \color none
19719 convert unsigned char to floating point
19720 \end_layout
19721
19722 \end_inset
19723 </cell>
19724 </row>
19725 <row topline="true">
19726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19727 \begin_inset Text
19728
19729 \begin_layout Standard
19730
19731 \family roman
19732 \series medium
19733 \shape up
19734 \size normal
19735 \emph off
19736 \bar no
19737 \noun off
19738 \color none
19739 _char2fs.c
19740 \end_layout
19741
19742 \end_inset
19743 </cell>
19744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19745 \begin_inset Text
19746
19747 \begin_layout Standard
19748
19749 \family roman
19750 \series medium
19751 \shape up
19752 \size normal
19753 \emph off
19754 \bar no
19755 \noun off
19756 \color none
19757 convert char to floating point number
19758 \end_layout
19759
19760 \end_inset
19761 </cell>
19762 </row>
19763 <row topline="true">
19764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19765 \begin_inset Text
19766
19767 \begin_layout Standard
19768
19769 \family roman
19770 \series medium
19771 \shape up
19772 \size normal
19773 \emph off
19774 \bar no
19775 \noun off
19776 \color none
19777 _uint2fs.c
19778 \end_layout
19779
19780 \end_inset
19781 </cell>
19782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19783 \begin_inset Text
19784
19785 \begin_layout Standard
19786
19787 \family roman
19788 \series medium
19789 \shape up
19790 \size normal
19791 \emph off
19792 \bar no
19793 \noun off
19794 \color none
19795 convert unsigned int to floating point
19796 \end_layout
19797
19798 \end_inset
19799 </cell>
19800 </row>
19801 <row topline="true">
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19803 \begin_inset Text
19804
19805 \begin_layout Standard
19806
19807 \family roman
19808 \series medium
19809 \shape up
19810 \size normal
19811 \emph off
19812 \bar no
19813 \noun off
19814 \color none
19815 _int2fs.c
19816 \end_layout
19817
19818 \end_inset
19819 </cell>
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19821 \begin_inset Text
19822
19823 \begin_layout Standard
19824
19825 \family roman
19826 \series medium
19827 \shape up
19828 \size normal
19829 \emph off
19830 \bar no
19831 \noun off
19832 \color none
19833 convert int to floating point numbers
19834 \end_layout
19835
19836 \end_inset
19837 </cell>
19838 </row>
19839 <row topline="true">
19840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19841 \begin_inset Text
19842
19843 \begin_layout Standard
19844
19845 \family roman
19846 \series medium
19847 \shape up
19848 \size normal
19849 \emph off
19850 \bar no
19851 \noun off
19852 \color none
19853 _ulong2fs.c
19854 \end_layout
19855
19856 \end_inset
19857 </cell>
19858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19859 \begin_inset Text
19860
19861 \begin_layout Standard
19862
19863 \family roman
19864 \series medium
19865 \shape up
19866 \size normal
19867 \emph off
19868 \bar no
19869 \noun off
19870 \color none
19871 convert unsigned long to floating point number
19872 \end_layout
19873
19874 \end_inset
19875 </cell>
19876 </row>
19877 <row topline="true" bottomline="true">
19878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19879 \begin_inset Text
19880
19881 \begin_layout Standard
19882
19883 \family roman
19884 \series medium
19885 \shape up
19886 \size normal
19887 \emph off
19888 \bar no
19889 \noun off
19890 \color none
19891 _long2fs.c
19892 \end_layout
19893
19894 \end_inset
19895 </cell>
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19897 \begin_inset Text
19898
19899 \begin_layout Standard
19900
19901 \family roman
19902 \series medium
19903 \shape up
19904 \size normal
19905 \emph off
19906 \bar no
19907 \noun off
19908 \color none
19909 convert long to floating point number
19910 \end_layout
19911
19912 \end_inset
19913 </cell>
19914 </row>
19915 </lyxtabular>
19916
19917 \end_inset
19918
19919
19920 \newline
19921
19922 \end_layout
19923
19924 \begin_layout Standard
19925 These support routines are developed in ANSI-C so there is room for space
19926  and speed improvement
19927 \begin_inset Foot
19928 status open
19929
19930 \begin_layout Standard
19931 These floating point routines (
19932 \emph on
19933 not
19934 \emph default
19935  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19936  
19937 \end_layout
19938
19939 \end_inset
19940
19941 .
19942  Note if all these routines are used simultaneously the data space might
19943  overflow.
19944  For serious floating point usage the large model might be needed.
19945  Also notice that you don't have to call this routines directly.
19946  The compiler will use them automatically every time a floating point operation
19947  is required.
19948 \begin_inset VSpace bigskip
19949 \end_inset
19950
19951
19952 \end_layout
19953
19954 \begin_layout Section
19955 Library Routines
19956 \begin_inset LatexCommand \index{Libraries}
19957
19958 \end_inset
19959
19960
19961 \end_layout
19962
19963 \begin_layout Standard
19964
19965 \emph on
19966 <pending: this is messy and incomplete - a little more information is in
19967  sdcc/doc/libdoc.txt
19968 \emph default
19969  >
19970 \end_layout
19971
19972 \begin_layout Subsection
19973 Compiler support routines (_gptrget, _mulint etc.)
19974 \end_layout
19975
19976 \begin_layout Subsection
19977 Stdclib functions (puts, printf, strcat etc.)
19978 \end_layout
19979
19980 \begin_layout Subsubsection
19981 <stdio.h>
19982 \end_layout
19983
19984 \begin_layout Paragraph
19985 getchar(), putchar()
19986 \end_layout
19987
19988 \begin_layout Standard
19989 \begin_inset LatexCommand \index{<stdio.h>}
19990
19991 \end_inset
19992
19993 As usual on embedded systems you have to provide your own 
19994 \family typewriter
19995 getchar()
19996 \begin_inset LatexCommand \index{getchar()}
19997
19998 \end_inset
19999
20000  
20001 \family default
20002 and 
20003 \family typewriter
20004 putchar()
20005 \begin_inset LatexCommand \index{putchar()}
20006
20007 \end_inset
20008
20009
20010 \family default
20011  routines.
20012  SDCC does not know whether the system connects to a serial line with or
20013  without handshake, LCD, keyboard or other device.
20014  And whether a 
20015 \family typewriter
20016 lf
20017 \family default
20018  to 
20019 \family typewriter
20020 crlf
20021 \family default
20022  conversion within 
20023 \family typewriter
20024 putchar()
20025 \family default
20026  is intended.
20027  You'll find examples for serial routines f.e.
20028  in sdcc/device/lib.
20029  For the mcs51 this minimalistic polling 
20030 \family typewriter
20031 putchar()
20032 \family default
20033  routine might be a start:
20034 \end_layout
20035
20036 \begin_layout Verse
20037
20038 \family typewriter
20039 void putchar (char c) { 
20040 \newline
20041 \InsetSpace ~
20042 \InsetSpace ~
20043 \InsetSpace ~
20044 \InsetSpace ~
20045 while (!TI)\InsetSpace ~
20046 \InsetSpace ~
20047 \InsetSpace ~
20048  /* assumes UART is initialized */
20049 \newline
20050 \InsetSpace ~
20051 \InsetSpace ~
20052 \InsetSpace ~
20053 \InsetSpace ~
20054 \InsetSpace ~
20055 \InsetSpace ~
20056 \InsetSpace ~
20057 \InsetSpace ~
20058 ;
20059 \newline
20060 \InsetSpace ~
20061 \InsetSpace ~
20062 \InsetSpace ~
20063 \InsetSpace ~
20064 TI
20065  = 0;
20066 \newline
20067 \InsetSpace ~
20068 \InsetSpace ~
20069 \InsetSpace ~
20070 \InsetSpace ~
20071 SBUF = c;
20072 \newline
20073 }
20074 \end_layout
20075
20076 \begin_layout Paragraph
20077 printf()
20078 \end_layout
20079
20080 \begin_layout Standard
20081 The default
20082 \family typewriter
20083  printf()
20084 \begin_inset LatexCommand \index{printf()}
20085
20086 \end_inset
20087
20088
20089 \family default
20090  implementation in
20091 \family typewriter
20092  printf_large.c
20093 \family default
20094  does not support float (except on ds390).
20095  To enable this recompile it with the option 
20096 \emph on
20097 -
20098 \begin_inset ERT
20099 status collapsed
20100
20101 \begin_layout Standard
20102
20103
20104 \backslash
20105 /
20106 \end_layout
20107
20108 \end_inset
20109
20110 DUSE_FLOATS=1
20111 \begin_inset LatexCommand \index{USE\_FLOATS}
20112
20113 \end_inset
20114
20115
20116 \emph default
20117  on the command line.
20118  Use
20119 \emph on
20120  -
20121 \begin_inset ERT
20122 status collapsed
20123
20124 \begin_layout Standard
20125
20126
20127 \backslash
20128 /
20129 \end_layout
20130
20131 \end_inset
20132
20133 -model-large
20134 \begin_inset LatexCommand \index{-\/-model-large}
20135
20136 \end_inset
20137
20138
20139 \emph default
20140  for the mcs51 port, since this uses a lot of memory.
20141 \end_layout
20142
20143 \begin_layout Standard
20144 If you're short on code memory you might want to use 
20145 \family typewriter
20146 printf_small()
20147 \begin_inset LatexCommand \index{printf\_small()}
20148
20149 \end_inset
20150
20151
20152 \family default
20153  
20154 \emph on
20155 instead
20156 \emph default
20157  of
20158 \family typewriter
20159  printf().
20160
20161 \family default
20162  For the mcs51 there additionally are assembly versions 
20163 \family typewriter
20164 printf_tiny()
20165 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20166
20167 \end_inset
20168
20169
20170 \family default
20171  (subset of printf using less than 270 bytes) and 
20172 \family typewriter
20173 printf_fast()
20174 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20175
20176 \end_inset
20177
20178  
20179 \family default
20180 and
20181 \family typewriter
20182  printf_fast_f()
20183 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20184
20185 \end_inset
20186
20187
20188 \family default
20189  (floating-point aware version of printf_fast) which should fit the requirements
20190  of many embedded systems (printf_fast() can be customized by unsetting
20191  #defines to 
20192 \emph on
20193 not
20194 \emph default
20195  support long variables and field widths).
20196  Be sure to use only one of these printf options within a project.
20197 \newline
20198
20199 \end_layout
20200
20201 \begin_layout Standard
20202 Feature matrix of different 
20203 \emph on
20204 printf
20205 \emph default
20206  options on mcs51.
20207 \end_layout
20208
20209 \begin_layout Standard
20210 \begin_inset Tabular
20211 <lyxtabular version="3" rows="14" columns="7">
20212 <features islongtable="true">
20213 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20214 <column alignment="center" valignment="top" leftline="true" width="0">
20215 <column alignment="center" valignment="top" leftline="true" width="12col%">
20216 <column alignment="center" valignment="top" leftline="true" width="10col%">
20217 <column alignment="center" valignment="top" leftline="true" width="0">
20218 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20219 <column alignment="center" valignment="top" rightline="true" width="0">
20220 <row topline="true" bottomline="true" endhead="true">
20221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20222 \begin_inset Text
20223
20224 \begin_layout Standard
20225
20226 \series bold
20227 \size large
20228 mcs51
20229 \end_layout
20230
20231 \end_inset
20232 </cell>
20233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20234 \begin_inset Text
20235
20236 \begin_layout Standard
20237 printf
20238 \begin_inset LatexCommand \index{printf}
20239
20240 \end_inset
20241
20242
20243 \end_layout
20244
20245 \end_inset
20246 </cell>
20247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20248 \begin_inset Text
20249
20250 \begin_layout Standard
20251 printf 
20252 \size scriptsize
20253 USE_FLOATS=1
20254 \end_layout
20255
20256 \end_inset
20257 </cell>
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20259 \begin_inset Text
20260
20261 \begin_layout Standard
20262 printf_small
20263 \end_layout
20264
20265 \end_inset
20266 </cell>
20267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20268 \begin_inset Text
20269
20270 \begin_layout Standard
20271 printf_fast
20272 \end_layout
20273
20274 \end_inset
20275 </cell>
20276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20277 \begin_inset Text
20278
20279 \begin_layout Standard
20280 printf_fast_f
20281 \end_layout
20282
20283 \end_inset
20284 </cell>
20285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20286 \begin_inset Text
20287
20288 \begin_layout Standard
20289 printf_tiny
20290 \end_layout
20291
20292 \end_inset
20293 </cell>
20294 </row>
20295 <row topline="true" endhead="true">
20296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20297 \begin_inset Text
20298
20299 \begin_layout Standard
20300 filename
20301 \end_layout
20302
20303 \end_inset
20304 </cell>
20305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20306 \begin_inset Text
20307
20308 \begin_layout Standard
20309
20310 \size scriptsize
20311 printf_large.c
20312 \end_layout
20313
20314 \end_inset
20315 </cell>
20316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20317 \begin_inset Text
20318
20319 \begin_layout Standard
20320
20321 \size scriptsize
20322 printf_large.c
20323 \end_layout
20324
20325 \end_inset
20326 </cell>
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20328 \begin_inset Text
20329
20330 \begin_layout Standard
20331
20332 \size scriptsize
20333 printfl.c
20334 \end_layout
20335
20336 \end_inset
20337 </cell>
20338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20339 \begin_inset Text
20340
20341 \begin_layout Standard
20342
20343 \size scriptsize
20344 printf_fast.c
20345 \end_layout
20346
20347 \end_inset
20348 </cell>
20349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20350 \begin_inset Text
20351
20352 \begin_layout Standard
20353
20354 \size scriptsize
20355 printf_fast_f.c
20356 \end_layout
20357
20358 \end_inset
20359 </cell>
20360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20361 \begin_inset Text
20362
20363 \begin_layout Standard
20364
20365 \size scriptsize
20366 printf_tiny.c
20367 \end_layout
20368
20369 \end_inset
20370 </cell>
20371 </row>
20372 <row topline="true" endhead="true">
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20374 \begin_inset Text
20375
20376 \begin_layout Standard
20377 \begin_inset Quotes sld
20378 \end_inset
20379
20380 Hello World
20381 \begin_inset Quotes srd
20382 \end_inset
20383
20384  size
20385 \end_layout
20386
20387 \begin_layout Standard
20388 small / large
20389 \end_layout
20390
20391 \end_inset
20392 </cell>
20393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20394 \begin_inset Text
20395
20396 \begin_layout Standard
20397 1.7k / 2.4k
20398 \end_layout
20399
20400 \end_inset
20401 </cell>
20402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20403 \begin_inset Text
20404
20405 \begin_layout Standard
20406 4.3k / 5.6k
20407 \end_layout
20408
20409 \end_inset
20410 </cell>
20411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20412 \begin_inset Text
20413
20414 \begin_layout Standard
20415 1.2k / 1.8k
20416 \end_layout
20417
20418 \end_inset
20419 </cell>
20420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20421 \begin_inset Text
20422
20423 \begin_layout Standard
20424 1.3k / 1.3k
20425 \end_layout
20426
20427 \end_inset
20428 </cell>
20429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20430 \begin_inset Text
20431
20432 \begin_layout Standard
20433 1.9k / 1.9k
20434 \end_layout
20435
20436 \end_inset
20437 </cell>
20438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20439 \begin_inset Text
20440
20441 \begin_layout Standard
20442 0.44k / 0.44k
20443 \end_layout
20444
20445 \end_inset
20446 </cell>
20447 </row>
20448 <row topline="true" endhead="true">
20449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20450 \begin_inset Text
20451
20452 \begin_layout Standard
20453 code size
20454 \end_layout
20455
20456 \begin_layout Standard
20457 small / large
20458 \end_layout
20459
20460 \end_inset
20461 </cell>
20462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20463 \begin_inset Text
20464
20465 \begin_layout Standard
20466 1.4k / 2.0k
20467 \end_layout
20468
20469 \end_inset
20470 </cell>
20471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20472 \begin_inset Text
20473
20474 \begin_layout Standard
20475 2.8k / 3.7k
20476 \end_layout
20477
20478 \end_inset
20479 </cell>
20480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20481 \begin_inset Text
20482
20483 \begin_layout Standard
20484 0.45k / 0.47k (+ _ltoa)
20485 \end_layout
20486
20487 \end_inset
20488 </cell>
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20490 \begin_inset Text
20491
20492 \begin_layout Standard
20493 1.2k / 1.2k
20494 \end_layout
20495
20496 \end_inset
20497 </cell>
20498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20499 \begin_inset Text
20500
20501 \begin_layout Standard
20502 1.6k / 1.6k
20503 \end_layout
20504
20505 \end_inset
20506 </cell>
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20508 \begin_inset Text
20509
20510 \begin_layout Standard
20511 0.26k / 0.26k
20512 \end_layout
20513
20514 \end_inset
20515 </cell>
20516 </row>
20517 <row topline="true">
20518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20519 \begin_inset Text
20520
20521 \begin_layout Standard
20522 formats
20523 \end_layout
20524
20525 \end_inset
20526 </cell>
20527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20528 \begin_inset Text
20529
20530 \begin_layout Standard
20531 cdi
20532 \emph on
20533 o
20534 \emph default
20535 psux
20536 \end_layout
20537
20538 \end_inset
20539 </cell>
20540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20541 \begin_inset Text
20542
20543 \begin_layout Standard
20544
20545 \family roman
20546 \series medium
20547 \shape up
20548 \size normal
20549 \emph off
20550 \bar no
20551 \noun off
20552 \color none
20553 cd
20554 \family default
20555 \series default
20556 \shape default
20557 \size default
20558 \emph default
20559 \bar default
20560 \noun default
20561 f
20562 \family roman
20563 \series medium
20564 \shape up
20565 \size normal
20566 \emph off
20567 \bar no
20568 \noun off
20569 i
20570 \family default
20571 \series default
20572 \shape default
20573 \size default
20574 \emph on
20575 \bar default
20576 \noun default
20577 o
20578 \family roman
20579 \series medium
20580 \shape up
20581 \size normal
20582 \emph off
20583 \bar no
20584 \noun off
20585 psux
20586 \end_layout
20587
20588 \end_inset
20589 </cell>
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20591 \begin_inset Text
20592
20593 \begin_layout Standard
20594 c
20595 \family roman
20596 \series medium
20597 \shape up
20598 \size normal
20599 \emph off
20600 \bar no
20601 \noun off
20602 \color none
20603 d
20604 \family default
20605 \series default
20606 \shape default
20607 \size default
20608 \emph on
20609 \bar default
20610 \noun default
20611 o
20612 \family roman
20613 \series medium
20614 \shape up
20615 \size normal
20616 \emph off
20617 \bar no
20618 \noun off
20619 s
20620 \family default
20621 \series default
20622 \shape default
20623 \size default
20624 \emph default
20625 \bar default
20626 \noun default
20627 x
20628 \end_layout
20629
20630 \end_inset
20631 </cell>
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20633 \begin_inset Text
20634
20635 \begin_layout Standard
20636 cdsux
20637 \end_layout
20638
20639 \end_inset
20640 </cell>
20641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20642 \begin_inset Text
20643
20644 \begin_layout Standard
20645 cdfsux
20646 \end_layout
20647
20648 \end_inset
20649 </cell>
20650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20651 \begin_inset Text
20652
20653 \begin_layout Standard
20654 cdsux
20655 \end_layout
20656
20657 \end_inset
20658 </cell>
20659 </row>
20660 <row topline="true">
20661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20662 \begin_inset Text
20663
20664 \begin_layout Standard
20665 long (32 bit) support
20666 \end_layout
20667
20668 \end_inset
20669 </cell>
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20671 \begin_inset Text
20672
20673 \begin_layout Standard
20674 x
20675 \end_layout
20676
20677 \end_inset
20678 </cell>
20679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20680 \begin_inset Text
20681
20682 \begin_layout Standard
20683 x
20684 \end_layout
20685
20686 \end_inset
20687 </cell>
20688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20689 \begin_inset Text
20690
20691 \begin_layout Standard
20692 x
20693 \end_layout
20694
20695 \end_inset
20696 </cell>
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20698 \begin_inset Text
20699
20700 \begin_layout Standard
20701 x
20702 \end_layout
20703
20704 \end_inset
20705 </cell>
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20707 \begin_inset Text
20708
20709 \begin_layout Standard
20710
20711 \family roman
20712 \series medium
20713 \shape up
20714 \size normal
20715 \emph off
20716 \bar no
20717 \noun off
20718 \color none
20719 x
20720 \end_layout
20721
20722 \end_inset
20723 </cell>
20724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20725 \begin_inset Text
20726
20727 \begin_layout Standard
20728 -
20729 \end_layout
20730
20731 \end_inset
20732 </cell>
20733 </row>
20734 <row topline="true">
20735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20736 \begin_inset Text
20737
20738 \begin_layout Standard
20739 byte arguments on stack
20740 \end_layout
20741
20742 \end_inset
20743 </cell>
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20745 \begin_inset Text
20746
20747 \begin_layout Standard
20748 b
20749 \end_layout
20750
20751 \end_inset
20752 </cell>
20753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20754 \begin_inset Text
20755
20756 \begin_layout Standard
20757 b
20758 \end_layout
20759
20760 \end_inset
20761 </cell>
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20763 \begin_inset Text
20764
20765 \begin_layout Standard
20766 -
20767 \end_layout
20768
20769 \end_inset
20770 </cell>
20771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20772 \begin_inset Text
20773
20774 \begin_layout Standard
20775 -
20776 \end_layout
20777
20778 \end_inset
20779 </cell>
20780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20781 \begin_inset Text
20782
20783 \begin_layout Standard
20784 -
20785 \end_layout
20786
20787 \end_inset
20788 </cell>
20789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20790 \begin_inset Text
20791
20792 \begin_layout Standard
20793 -
20794 \end_layout
20795
20796 \end_inset
20797 </cell>
20798 </row>
20799 <row topline="true">
20800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20801 \begin_inset Text
20802
20803 \begin_layout Standard
20804 float format
20805 \begin_inset LatexCommand \index{Floating point support}
20806
20807 \end_inset
20808
20809
20810 \end_layout
20811
20812 \end_inset
20813 </cell>
20814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20815 \begin_inset Text
20816
20817 \begin_layout Standard
20818 -
20819 \end_layout
20820
20821 \end_inset
20822 </cell>
20823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20824 \begin_inset Text
20825
20826 \begin_layout Standard
20827 %f
20828 \end_layout
20829
20830 \end_inset
20831 </cell>
20832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20833 \begin_inset Text
20834
20835 \begin_layout Standard
20836 -
20837 \end_layout
20838
20839 \end_inset
20840 </cell>
20841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20842 \begin_inset Text
20843
20844 \begin_layout Standard
20845 -
20846 \end_layout
20847
20848 \end_inset
20849 </cell>
20850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20851 \begin_inset Text
20852
20853 \begin_layout Standard
20854 %f
20855 \begin_inset Foot
20856 status collapsed
20857
20858 \begin_layout Standard
20859 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20860 \end_layout
20861
20862 \end_inset
20863
20864
20865 \end_layout
20866
20867 \end_inset
20868 </cell>
20869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20870 \begin_inset Text
20871
20872 \begin_layout Standard
20873 -
20874 \end_layout
20875
20876 \end_inset
20877 </cell>
20878 </row>
20879 <row topline="true">
20880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20881 \begin_inset Text
20882
20883 \begin_layout Standard
20884 float formats %e %g
20885 \end_layout
20886
20887 \end_inset
20888 </cell>
20889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20890 \begin_inset Text
20891
20892 \begin_layout Standard
20893 -
20894 \end_layout
20895
20896 \end_inset
20897 </cell>
20898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20899 \begin_inset Text
20900
20901 \begin_layout Standard
20902 -
20903 \end_layout
20904
20905 \end_inset
20906 </cell>
20907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20908 \begin_inset Text
20909
20910 \begin_layout Standard
20911 -
20912 \end_layout
20913
20914 \end_inset
20915 </cell>
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20917 \begin_inset Text
20918
20919 \begin_layout Standard
20920 -
20921 \end_layout
20922
20923 \end_inset
20924 </cell>
20925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20926 \begin_inset Text
20927
20928 \begin_layout Standard
20929 -
20930 \end_layout
20931
20932 \end_inset
20933 </cell>
20934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20935 \begin_inset Text
20936
20937 \begin_layout Standard
20938 -
20939 \end_layout
20940
20941 \end_inset
20942 </cell>
20943 </row>
20944 <row topline="true" bottomline="true">
20945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20946 \begin_inset Text
20947
20948 \begin_layout Standard
20949 field width
20950 \end_layout
20951
20952 \end_inset
20953 </cell>
20954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20955 \begin_inset Text
20956
20957 \begin_layout Standard
20958 x
20959 \end_layout
20960
20961 \end_inset
20962 </cell>
20963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20964 \begin_inset Text
20965
20966 \begin_layout Standard
20967 x
20968 \end_layout
20969
20970 \end_inset
20971 </cell>
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20973 \begin_inset Text
20974
20975 \begin_layout Standard
20976 -
20977 \end_layout
20978
20979 \end_inset
20980 </cell>
20981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20982 \begin_inset Text
20983
20984 \begin_layout Standard
20985 x
20986 \end_layout
20987
20988 \end_inset
20989 </cell>
20990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20991 \begin_inset Text
20992
20993 \begin_layout Standard
20994 x
20995 \end_layout
20996
20997 \end_inset
20998 </cell>
20999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21000 \begin_inset Text
21001
21002 \begin_layout Standard
21003 -
21004 \end_layout
21005
21006 \end_inset
21007 </cell>
21008 </row>
21009 <row bottomline="true">
21010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21011 \begin_inset Text
21012
21013 \begin_layout Standard
21014 string speed
21015 \begin_inset Foot
21016 status collapsed
21017
21018 \begin_layout Standard
21019 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21020 \backslash
21021 r', '
21022 \backslash
21023 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21024 \end_layout
21025
21026 \end_inset
21027
21028 ,
21029 \end_layout
21030
21031 \begin_layout Standard
21032 small / large
21033 \end_layout
21034
21035 \end_inset
21036 </cell>
21037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21038 \begin_inset Text
21039
21040 \begin_layout Standard
21041 1.52 / 2.59 ms
21042 \end_layout
21043
21044 \end_inset
21045 </cell>
21046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21047 \begin_inset Text
21048
21049 \begin_layout Standard
21050 1.53 / 2.62 ms
21051 \end_layout
21052
21053 \end_inset
21054 </cell>
21055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21056 \begin_inset Text
21057
21058 \begin_layout Standard
21059 0.92 / 0.93 ms
21060 \end_layout
21061
21062 \end_inset
21063 </cell>
21064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21065 \begin_inset Text
21066
21067 \begin_layout Standard
21068 0.45 / 0.45 ms
21069 \end_layout
21070
21071 \end_inset
21072 </cell>
21073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21074 \begin_inset Text
21075
21076 \begin_layout Standard
21077 0.46 / 0.46 ms
21078 \end_layout
21079
21080 \end_inset
21081 </cell>
21082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21083 \begin_inset Text
21084
21085 \begin_layout Standard
21086 0.45 / 0.45 ms
21087 \end_layout
21088
21089 \end_inset
21090 </cell>
21091 </row>
21092 <row bottomline="true">
21093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21094 \begin_inset Text
21095
21096 \begin_layout Standard
21097 int speed
21098 \begin_inset Foot
21099 status collapsed
21100
21101 \begin_layout Standard
21102 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21103  putchar()
21104 \end_layout
21105
21106 \end_inset
21107
21108 ,
21109 \end_layout
21110
21111 \begin_layout Standard
21112 small / large
21113 \end_layout
21114
21115 \end_inset
21116 </cell>
21117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21118 \begin_inset Text
21119
21120 \begin_layout Standard
21121 3.01 / 3.61 ms
21122 \end_layout
21123
21124 \end_inset
21125 </cell>
21126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21127 \begin_inset Text
21128
21129 \begin_layout Standard
21130 3.01 / 3.61 ms
21131 \end_layout
21132
21133 \end_inset
21134 </cell>
21135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21136 \begin_inset Text
21137
21138 \begin_layout Standard
21139 3.51 / 18.13 ms
21140 \end_layout
21141
21142 \end_inset
21143 </cell>
21144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21145 \begin_inset Text
21146
21147 \begin_layout Standard
21148 0.22 / 0.22 ms
21149 \end_layout
21150
21151 \end_inset
21152 </cell>
21153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21154 \begin_inset Text
21155
21156 \begin_layout Standard
21157 0.23 / 0.23 ms
21158 \end_layout
21159
21160 \end_inset
21161 </cell>
21162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21163 \begin_inset Text
21164
21165 \begin_layout Standard
21166 0.25 / 0.25 ms
21167 \begin_inset Foot
21168 status collapsed
21169
21170 \begin_layout Standard
21171 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21172 \end_layout
21173
21174 \end_inset
21175
21176
21177 \end_layout
21178
21179 \end_inset
21180 </cell>
21181 </row>
21182 <row bottomline="true">
21183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21184 \begin_inset Text
21185
21186 \begin_layout Standard
21187 long speed
21188 \begin_inset Foot
21189 status collapsed
21190
21191 \begin_layout Standard
21192 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21193  empty putchar()
21194 \end_layout
21195
21196 \end_inset
21197
21198 ,
21199 \end_layout
21200
21201 \begin_layout Standard
21202 small / large
21203 \end_layout
21204
21205 \end_inset
21206 </cell>
21207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21208 \begin_inset Text
21209
21210 \begin_layout Standard
21211 5.37 / 6.31 ms
21212 \end_layout
21213
21214 \end_inset
21215 </cell>
21216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21217 \begin_inset Text
21218
21219 \begin_layout Standard
21220 5.37 / 6.31 ms
21221 \end_layout
21222
21223 \end_inset
21224 </cell>
21225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21226 \begin_inset Text
21227
21228 \begin_layout Standard
21229 8.71 / 40.65 ms
21230 \end_layout
21231
21232 \end_inset
21233 </cell>
21234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21235 \begin_inset Text
21236
21237 \begin_layout Standard
21238 0.40 / 0.40 ms
21239 \end_layout
21240
21241 \end_inset
21242 </cell>
21243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21244 \begin_inset Text
21245
21246 \begin_layout Standard
21247 0.40 / 0.40 ms
21248 \end_layout
21249
21250 \end_inset
21251 </cell>
21252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21253 \begin_inset Text
21254
21255 \begin_layout Standard
21256 -
21257 \end_layout
21258
21259 \end_inset
21260 </cell>
21261 </row>
21262 <row bottomline="true">
21263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21264 \begin_inset Text
21265
21266 \begin_layout Standard
21267 float speed
21268 \begin_inset Foot
21269 status collapsed
21270
21271 \begin_layout Standard
21272 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21273  empty putchar()
21274 \end_layout
21275
21276 \end_inset
21277
21278 ,
21279 \end_layout
21280
21281 \begin_layout Standard
21282 small / large
21283 \end_layout
21284
21285 \end_inset
21286 </cell>
21287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21288 \begin_inset Text
21289
21290 \begin_layout Standard
21291 -
21292 \end_layout
21293
21294 \end_inset
21295 </cell>
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21297 \begin_inset Text
21298
21299 \begin_layout Standard
21300 7.49 / 22.47 ms
21301 \end_layout
21302
21303 \end_inset
21304 </cell>
21305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21306 \begin_inset Text
21307
21308 \begin_layout Standard
21309 -
21310 \end_layout
21311
21312 \end_inset
21313 </cell>
21314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21315 \begin_inset Text
21316
21317 \begin_layout Standard
21318 -
21319 \end_layout
21320
21321 \end_inset
21322 </cell>
21323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21324 \begin_inset Text
21325
21326 \begin_layout Standard
21327 1.04 / 1.04 ms
21328 \end_layout
21329
21330 \end_inset
21331 </cell>
21332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21333 \begin_inset Text
21334
21335 \begin_layout Standard
21336 -
21337 \end_layout
21338
21339 \end_inset
21340 </cell>
21341 </row>
21342 </lyxtabular>
21343
21344 \end_inset
21345
21346
21347 \end_layout
21348
21349 \begin_layout Subsubsection
21350 <malloc.h>
21351 \begin_inset LatexCommand \index{malloc.h}
21352
21353 \end_inset
21354
21355
21356 \end_layout
21357
21358 \begin_layout Standard
21359 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21360  using dynamic memory allocation
21361 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21362
21363 \end_inset
21364
21365  and a default heap
21366 \begin_inset LatexCommand \index{heap (malloc)}
21367
21368 \end_inset
21369
21370  space of 1024 bytes is provided for malloc to allocate memory from.
21371  If you need a different heap size you need to recompile _heap.c with the
21372  required size defined in HEAP_SIZE.
21373  It is recommended to make a copy of this file into your project directory
21374  and compile it there with:
21375 \end_layout
21376
21377 \begin_layout Verse
21378
21379 \family typewriter
21380 sdcc -c _heap.c -D HEAD_SIZE=2048
21381 \end_layout
21382
21383 \begin_layout Standard
21384 And then link it with:
21385 \end_layout
21386
21387 \begin_layout Verse
21388
21389 \family typewriter
21390 sdcc main.rel _heap.rel
21391 \end_layout
21392
21393 \begin_layout Subsection
21394 Math functions (sinf, powf, sqrtf etc.)
21395 \end_layout
21396
21397 \begin_layout Subsubsection
21398 <math.h>
21399 \end_layout
21400
21401 \begin_layout Standard
21402 See definitions in file <math.h>.
21403 \end_layout
21404
21405 \begin_layout Subsection
21406 Other libraries
21407 \end_layout
21408
21409 \begin_layout Standard
21410 Libraries
21411 \begin_inset LatexCommand \index{Libraries}
21412
21413 \end_inset
21414
21415  included in SDCC should have a license at least as liberal as the GNU Lesser
21416  General Public License
21417 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21418
21419 \end_inset
21420
21421  
21422 \emph on
21423 LGPL
21424 \emph default
21425 .
21426 \end_layout
21427
21428 \begin_layout Standard
21429 \begin_inset Note Note
21430 status collapsed
21431
21432 \begin_layout Standard
21433 license statements for the libraries are missing.
21434  sdcc/device/lib/ser_ir.c
21435 \end_layout
21436
21437 \begin_layout Standard
21438 or _decdptr f.e.
21439  come with a GPL (as opposed to LGPL) License - this will not be liberal
21440  enough for many embedded programmers.
21441 \end_layout
21442
21443 \end_inset
21444
21445
21446 \end_layout
21447
21448 \begin_layout Standard
21449 If you have ported some library or want to share experience about some code
21450  which f.e.
21451  falls into any of these categories Busses (I
21452 \begin_inset Formula $^{\textrm{2}}$
21453 \end_inset
21454
21455 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21456  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21457  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21458 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21459
21460 \end_inset
21461
21462 \InsetSpace ~
21463 would certainly like to hear about it.
21464 \end_layout
21465
21466 \begin_layout Standard
21467 Programmers coding for embedded systems are not especially famous for being
21468  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21469 e these references are very valuable.
21470  Let's help to create a climate where information is shared.
21471 \begin_inset VSpace bigskip
21472 \end_inset
21473
21474
21475 \end_layout
21476
21477 \begin_layout Section
21478 Memory Models
21479 \end_layout
21480
21481 \begin_layout Subsection
21482 MCS51 Memory Models
21483 \begin_inset LatexCommand \index{Memory model}
21484
21485 \end_inset
21486
21487
21488 \begin_inset LatexCommand \index{MCS51 memory model}
21489
21490 \end_inset
21491
21492
21493 \end_layout
21494
21495 \begin_layout Subsubsection
21496 Small, Medium and Large
21497 \end_layout
21498
21499 \begin_layout Standard
21500 SDCC allows three memory models for MCS51 code, 
21501 \shape slanted
21502 small, medium
21503 \shape default
21504  and 
21505 \shape slanted
21506 large
21507 \shape default
21508 .
21509  Modules compiled with different memory models should 
21510 \emph on
21511 never
21512 \emph default
21513  be combined together or the results would be unpredictable.
21514  The library routines supplied with the compiler are compiled as small,
21515  medium and large.
21516  The compiled library modules are contained in separate directories as small,
21517  medium and large so that you can link to the appropriate set.
21518 \end_layout
21519
21520 \begin_layout Standard
21521 When the medium or large model is used all variables declared without a
21522  storage class will be allocated into the external ram, this includes all
21523  parameters and local variables (for non-reentrant
21524 \begin_inset LatexCommand \index{reentrant}
21525
21526 \end_inset
21527
21528  functions).
21529  When the small model is used variables without storage class are allocated
21530  in the internal ram.
21531 \end_layout
21532
21533 \begin_layout Standard
21534 Judicious usage of the processor specific storage classes
21535 \begin_inset LatexCommand \index{Storage class}
21536
21537 \end_inset
21538
21539  and the 'reentrant' function type will yield much more efficient code,
21540  than using the large model.
21541  Several optimizations are disabled when the program is compiled using the
21542  large model, it is therefore recommended that the small model be used unless
21543  absolutely required.
21544 \end_layout
21545
21546 \begin_layout Subsubsection
21547 External Stack
21548 \begin_inset LatexCommand \label{sub:External-Stack}
21549
21550 \end_inset
21551
21552
21553 \begin_inset LatexCommand \index{stack}
21554
21555 \end_inset
21556
21557
21558 \begin_inset LatexCommand \index{External stack (mcs51)}
21559
21560 \end_inset
21561
21562
21563 \end_layout
21564
21565 \begin_layout Standard
21566 The external stack (-
21567 \begin_inset ERT
21568 status collapsed
21569
21570 \begin_layout Standard
21571
21572
21573 \backslash
21574 /
21575 \end_layout
21576
21577 \end_inset
21578
21579 -xstack option
21580 \begin_inset LatexCommand \index{-\/-xstack}
21581
21582 \end_inset
21583
21584 ) is located in pdata
21585 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21586
21587 \end_inset
21588
21589  memory (usually at the start of the external ram segment) and uses all
21590  unused space in pdata (max.
21591  256 bytes).
21592  When -
21593 \begin_inset ERT
21594 status collapsed
21595
21596 \begin_layout Standard
21597
21598
21599 \backslash
21600 /
21601 \end_layout
21602
21603 \end_inset
21604
21605 -xstack option is used to compile the program, the parameters and local
21606  variables
21607 \begin_inset LatexCommand \index{local variables}
21608
21609 \end_inset
21610
21611  of all reentrant functions are allocated in this area.
21612  This option is provided for programs with large stack space requirements.
21613  When used with the -
21614 \begin_inset ERT
21615 status collapsed
21616
21617 \begin_layout Standard
21618
21619
21620 \backslash
21621 /
21622 \end_layout
21623
21624 \end_inset
21625
21626 -stack-auto
21627 \begin_inset LatexCommand \index{-\/-stack-auto}
21628
21629 \end_inset
21630
21631  option, all parameters and local variables are allocated on the external
21632  stack (note: support libraries will need to be recompiled with the same
21633  options.
21634  There is a predefined target in the library makefile).
21635 \end_layout
21636
21637 \begin_layout Standard
21638 The compiler outputs the higher order address byte of the external ram segment
21639  into port P2
21640 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21641
21642 \end_inset
21643
21644  (see also section 
21645 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21646
21647 \end_inset
21648
21649 ), therefore when using the External Stack option, this port 
21650 \emph on
21651 may not
21652 \emph default
21653  be used by the application program.
21654 \end_layout
21655
21656 \begin_layout Subsection
21657 DS390 Memory Model
21658 \begin_inset LatexCommand \index{Memory model}
21659
21660 \end_inset
21661
21662
21663 \begin_inset LatexCommand \index{DS390 memory model}
21664
21665 \end_inset
21666
21667
21668 \end_layout
21669
21670 \begin_layout Standard
21671 The only model supported is Flat 24
21672 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21673
21674 \end_inset
21675
21676 .
21677  This generates code for the 24 bit contiguous addressing mode of the Dallas
21678  DS80C390 part.
21679  In this mode, up to four meg of external RAM or code space can be directly
21680  addressed.
21681  See the data sheets at www.dalsemi.com for further information on this part.
21682 \newline
21683
21684 \newline
21685 Note
21686  that the compiler does not generate any code to place the processor into
21687  24 bitmode (although 
21688 \emph on
21689 tinibios
21690 \emph default
21691  in the ds390 libraries will do that for you).
21692  If you don't use 
21693 \emph on
21694 tinibios
21695 \emph default
21696
21697 \begin_inset LatexCommand \index{Tinibios (DS390)}
21698
21699 \end_inset
21700
21701 , the boot loader or similar code must ensure that the processor is in 24
21702  bit contiguous addressing mode before calling the SDCC startup code.
21703 \newline
21704
21705 \newline
21706 Like
21707  the 
21708 \emph on
21709 -
21710 \begin_inset ERT
21711 status collapsed
21712
21713 \begin_layout Standard
21714
21715
21716 \backslash
21717 /
21718 \end_layout
21719
21720 \end_inset
21721
21722 -model-large
21723 \emph default
21724  option, variables will by default be placed into the XDATA segment.
21725  
21726 \newline
21727
21728 \newline
21729 Segments may be placed anywhere in the 4 meg address space using the usual
21730  -
21731 \begin_inset ERT
21732 status collapsed
21733
21734 \begin_layout Standard
21735
21736
21737 \backslash
21738 /
21739 \end_layout
21740
21741 \end_inset
21742
21743 -*-loc options.
21744  Note that if any segments are located above 64K, the -r flag must be passed
21745  to the linker to generate the proper segment relocations, and the Intel
21746  HEX output format must be used.
21747  The -r flag can be passed to the linker by using the option 
21748 \emph on
21749 -Wl-r
21750 \emph default
21751  on the SDCC command line.
21752  However, currently the linker can not handle code segments > 64k.
21753 \end_layout
21754
21755 \begin_layout Section
21756 Pragmas
21757 \begin_inset LatexCommand \label{sec:Pragmas}
21758
21759 \end_inset
21760
21761
21762 \begin_inset LatexCommand \index{Pragmas}
21763
21764 \end_inset
21765
21766
21767 \end_layout
21768
21769 \begin_layout Standard
21770 Pragmas are used to turn on and/or off certain compiler options.
21771  Some of them are closely related to corresponding command-line options
21772  (see section 
21773 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21774
21775 \end_inset
21776
21777 ).
21778 \newline
21779 Pragmas should be placed before and/or after a function, placing pragmas
21780  inside a function body could have unpredictable results.
21781 \newline
21782
21783 \newline
21784 SDCC supports the
21785  following #pragma directives:
21786 \end_layout
21787
21788 \begin_layout Itemize
21789
21790 \series bold
21791 save
21792 \series default
21793
21794 \begin_inset LatexCommand \index{\#pragma save}
21795
21796 \end_inset
21797
21798  - this will save most current options to the save/restore stack.
21799  See #pragma\InsetSpace ~
21800 restore.
21801 \end_layout
21802
21803 \begin_layout Itemize
21804
21805 \series bold
21806 restore
21807 \series default
21808
21809 \begin_inset LatexCommand \index{\#pragma restore}
21810
21811 \end_inset
21812
21813  - will restore saved options from the last save.
21814  saves & restores can be nested.
21815  SDCC uses a save/restore stack: save pushes current options to the stack,
21816  restore pulls current options from the stack.
21817  See #pragma\InsetSpace ~
21818 save.
21819 \newline
21820
21821 \end_layout
21822
21823 \begin_layout Itemize
21824
21825 \series bold
21826 callee_saves
21827 \series default
21828
21829 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21830
21831 \end_inset
21832
21833
21834 \begin_inset LatexCommand \index{function prologue}
21835
21836 \end_inset
21837
21838  function1[,function2[,function3...]] 
21839 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21840
21841 \end_inset
21842
21843 - The compiler by default uses a caller saves convention for register saving
21844  across function calls, however this can cause unnecessary register pushing
21845  and popping
21846 \begin_inset LatexCommand \index{push/pop}
21847
21848 \end_inset
21849
21850  when calling small functions from larger functions.
21851  This option can be used to switch off the register saving convention for
21852  the function names specified.
21853  The compiler will not save registers when calling these functions, extra
21854  code need to be manually inserted at the entry and exit for these functions
21855  to save and restore the registers used by these functions, this can SUBSTANTIAL
21856 LY reduce code and improve run time performance of the generated code.
21857  In the future the compiler (with inter procedural analysis) may be able
21858  to determine the appropriate scheme to use for each function call.
21859  If -
21860 \begin_inset ERT
21861 status collapsed
21862
21863 \begin_layout Standard
21864
21865
21866 \backslash
21867 /
21868 \end_layout
21869
21870 \end_inset
21871
21872 -callee-saves command line option is used (see page 
21873 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21874
21875 \end_inset
21876
21877 ), the function names specified in #pragma\InsetSpace ~
21878 callee_saves
21879 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21880
21881 \end_inset
21882
21883  is appended to the list of functions specified in the command line.
21884 \end_layout
21885
21886 \begin_layout Itemize
21887
21888 \series bold
21889 exclude
21890 \series default
21891
21892 \begin_inset LatexCommand \index{\#pragma exclude}
21893
21894 \end_inset
21895
21896  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21897  of pairs of push/pop
21898 \begin_inset LatexCommand \index{push/pop}
21899
21900 \end_inset
21901
21902  instructions in 
21903 \emph on
21904 I
21905 \emph default
21906 nterrupt
21907 \begin_inset LatexCommand \index{interrupt}
21908
21909 \end_inset
21910
21911  
21912 \emph on
21913 S
21914 \emph default
21915 ervice 
21916 \emph on
21917 R
21918 \emph default
21919 outines.
21920  The directive should be placed immediately before the ISR function definition
21921  and it affects ALL ISR functions following it.
21922  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21923 exclude\InsetSpace ~
21924 none
21925 \begin_inset LatexCommand \index{\#pragma exclude}
21926
21927 \end_inset
21928
21929 .
21930  See also the related keyword _naked
21931 \begin_inset LatexCommand \index{\_naked}
21932
21933 \end_inset
21934
21935
21936 \begin_inset LatexCommand \index{\_\_naked}
21937
21938 \end_inset
21939
21940 .
21941 \end_layout
21942
21943 \begin_layout Itemize
21944
21945 \series bold
21946 less_pedantic
21947 \series default
21948
21949 \begin_inset LatexCommand \index{pedantic}
21950
21951 \end_inset
21952
21953
21954 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21955
21956 \end_inset
21957
21958  
21959 \begin_inset LatexCommand \label{ite:less_pedantic}
21960
21961 \end_inset
21962
21963 - the compiler will not warn you anymore for obvious mistakes, you're on
21964  your own now ;-( .
21965  See also the command line option -
21966 \begin_inset ERT
21967 status collapsed
21968
21969 \begin_layout Standard
21970
21971
21972 \backslash
21973 /
21974 \end_layout
21975
21976 \end_inset
21977
21978 -less-pedantic 
21979 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21980
21981 \end_inset
21982
21983 .
21984  
21985 \newline
21986 More specifically, the following warnings will be disabled: 
21987 \shape italic
21988 comparison is always [true/false] due to limited range of data type
21989 \shape default
21990  (94); 
21991 \shape italic
21992 overflow in implicit constant conversion
21993 \shape default
21994  (158); [the (in)famous] 
21995 \shape italic
21996 conditional flow changed by optimizer: so said EVELYN the modified DOG
21997 \shape default
21998  (110); 
21999 \shape italic
22000 function '[function name]' must return value
22001 \shape default
22002  (59).
22003  
22004 \newline
22005 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22006  level) are disabled, too, namely: 
22007 \shape italic
22008 constant value '[
22009 \begin_inset Note Note
22010 status collapsed
22011
22012 \begin_layout Standard
22013 dunno what comes here - this warning appears to be unused altogether
22014 \end_layout
22015
22016 \end_inset
22017
22018 ]', out of range
22019 \shape default
22020  (81); 
22021 \shape italic
22022 [left/right] shifting more than size of object changed to zero
22023 \shape default
22024  (116); 
22025 \shape italic
22026 unreachable code
22027 \shape default
22028  (126); 
22029 \shape italic
22030 integer overflow in expression
22031 \shape default
22032  (165); 
22033 \shape italic
22034 unmatched #pragma save and #pragma restore
22035 \shape default
22036  (170); 
22037 \shape italic
22038 comparison of 'signed char' with 'unsigned char' requires promotion to int
22039 \shape default
22040  (185); 
22041 \shape italic
22042 ISO C90 does not support flexible array members
22043 \shape default
22044  (187); 
22045 \shape italic
22046 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22047 nam
22048 e]':\InsetSpace ~
22049 [
22050 \begin_inset Note Note
22051 status collapsed
22052
22053 \begin_layout Standard
22054 appears to be always blank - what was supposed to be here?
22055 \end_layout
22056
22057 \end_inset
22058
22059 ]
22060 \shape default
22061  (114); 
22062 \shape italic
22063 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22064  complexity [number]
22065 \shape default
22066  (121).
22067 \end_layout
22068
22069 \begin_layout Itemize
22070
22071 \series bold
22072 disable_warning
22073 \series default
22074  <nnnn>
22075 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22076
22077 \end_inset
22078
22079  - the compiler will not warn you anymore about warning number <nnnn>.
22080 \end_layout
22081
22082 \begin_layout Itemize
22083
22084 \series bold
22085 nogcse
22086 \series default
22087
22088 \begin_inset LatexCommand \index{\#pragma nogcse}
22089
22090 \end_inset
22091
22092  - will stop global common subexpression elimination.
22093 \end_layout
22094
22095 \begin_layout Itemize
22096
22097 \series bold
22098 noinduction
22099 \series default
22100
22101 \begin_inset LatexCommand \index{\#pragma noinduction}
22102
22103 \end_inset
22104
22105  - will stop loop induction optimizations.
22106 \end_layout
22107
22108 \begin_layout Itemize
22109
22110 \series bold
22111 noinvariant
22112 \series default
22113
22114 \begin_inset LatexCommand \index{\#pragma noinvariant}
22115
22116 \end_inset
22117
22118  - will not do loop invariant optimizations.
22119  For more details see Loop Invariants in section
22120 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22121
22122 \end_inset
22123
22124 .
22125 \end_layout
22126
22127 \begin_layout Itemize
22128
22129 \series bold
22130 noiv
22131 \series default
22132
22133 \begin_inset LatexCommand \index{\#pragma noiv}
22134
22135 \end_inset
22136
22137  - Do not generate interrupt
22138 \begin_inset LatexCommand \index{interrupt}
22139
22140 \end_inset
22141
22142  vector table
22143 \begin_inset LatexCommand \index{interrupt vector table}
22144
22145 \end_inset
22146
22147  entries for all ISR functions defined after the pragma.
22148  This is useful in cases where the interrupt vector table must be defined
22149  manually, or when there is a secondary, manually defined interrupt vector
22150  table (e.g.
22151  for the autovector feature of the Cypress EZ-USB FX2).
22152  More elegantly this can be achieved by obmitting the optional interrupt
22153  number after the interrupt keyword, see section 
22154 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22155
22156 \end_inset
22157
22158 \InsetSpace ~
22159 about interrupts.
22160 \end_layout
22161
22162 \begin_layout Itemize
22163
22164 \series bold
22165 nojtbound
22166 \series default
22167
22168 \begin_inset LatexCommand \index{\#pragma nojtbound}
22169
22170 \end_inset
22171
22172  - will not generate code for boundary value checking, when switch statements
22173  are turned into jump-tables (dangerous).
22174  For more details see section 
22175 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22176
22177 \end_inset
22178
22179 .
22180 \end_layout
22181
22182 \begin_layout Itemize
22183
22184 \series bold
22185 noloopreverse
22186 \series default
22187
22188 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22189
22190 \end_inset
22191
22192  - Will not do loop reversal optimization
22193 \end_layout
22194
22195 \begin_layout Itemize
22196
22197 \series bold
22198 nooverlay
22199 \series default
22200
22201 \begin_inset LatexCommand \index{\#pragma nooverlay}
22202
22203 \end_inset
22204
22205  - the compiler will not overlay the parameters and local variables of a
22206  function.
22207 \end_layout
22208
22209 \begin_layout Itemize
22210
22211 \series bold
22212 stackauto
22213 \series default
22214
22215 \begin_inset LatexCommand \index{\#pragma stackauto}
22216
22217 \end_inset
22218
22219 - See option -
22220 \begin_inset ERT
22221 status collapsed
22222
22223 \begin_layout Standard
22224
22225
22226 \backslash
22227 /
22228 \end_layout
22229
22230 \end_inset
22231
22232 -stack-auto
22233 \begin_inset LatexCommand \index{-\/-stack-auto}
22234
22235 \end_inset
22236
22237  and section 
22238 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22239
22240 \end_inset
22241
22242  Parameters and Local Variables.
22243 \end_layout
22244
22245 \begin_layout Itemize
22246
22247 \series bold
22248 opt_code_speed
22249 \series default
22250  
22251 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22252
22253 \end_inset
22254
22255 - The compiler will optimize code generation towards fast code, possibly
22256  at the expense of code size.
22257  Currently this has little effect.
22258 \end_layout
22259
22260 \begin_layout Itemize
22261
22262 \series bold
22263 opt_code_size
22264 \series default
22265  
22266 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22267
22268 \end_inset
22269
22270 - The compiler will optimize code generation towards compact code, possibly
22271  at the expense of code speed.
22272  Currently this has little effect.
22273 \end_layout
22274
22275 \begin_layout Itemize
22276
22277 \series bold
22278 opt_code_balanced
22279 \series default
22280  
22281 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22282
22283 \end_inset
22284
22285 - The compiler will attempt to generate code that is both compact and fast,
22286  as long as meeting one goal is not a detriment to the other (this is the
22287  default).
22288  
22289 \end_layout
22290
22291 \begin_layout Itemize
22292
22293 \series bold
22294 std_sdcc89
22295 \series default
22296  
22297 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22298
22299 \end_inset
22300
22301 - Generally follow the C89 standard, but allow SDCC features that conflict
22302  with the standard (default).
22303 \end_layout
22304
22305 \begin_layout Itemize
22306
22307 \series bold
22308 std_c89
22309 \series default
22310  
22311 \begin_inset LatexCommand \index{\#pragma std\_c89}
22312
22313 \end_inset
22314
22315 - Follow the C89 standard and disable SDCC features that conflict with the
22316  standard.
22317 \end_layout
22318
22319 \begin_layout Itemize
22320
22321 \series bold
22322 std_sdcc99
22323 \series default
22324  
22325 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22326
22327 \end_inset
22328
22329 - Generally follow the C99 standard, but allow SDCC features that conflict
22330  with the standard (incomplete support).
22331 \end_layout
22332
22333 \begin_layout Itemize
22334
22335 \series bold
22336 std_c99
22337 \series default
22338  
22339 \begin_inset LatexCommand \index{\#pragma std\_c99}
22340
22341 \end_inset
22342
22343 - Follow the C99 standard and disable SDCC features that conflict with the
22344  standard (incomplete support).
22345 \end_layout
22346
22347 \begin_layout Itemize
22348
22349 \series bold
22350 codeseg
22351 \series default
22352  <name>
22353 \begin_inset LatexCommand \index{\#pragma codeseg}
22354
22355 \end_inset
22356
22357 - Use this name (max.
22358  8 characters) for the code segment.
22359  See option -
22360 \begin_inset ERT
22361 status collapsed
22362
22363 \begin_layout Standard
22364
22365
22366 \backslash
22367 /
22368 \end_layout
22369
22370 \end_inset
22371
22372 -codeseg.
22373 \end_layout
22374
22375 \begin_layout Itemize
22376
22377 \series bold
22378 constseg
22379 \series default
22380  <name>
22381 \begin_inset LatexCommand \index{\#pragma constseg}
22382
22383 \end_inset
22384
22385 - Use this name (max.
22386  8 characters) for the const segment.
22387  See option -
22388 \begin_inset ERT
22389 status collapsed
22390
22391 \begin_layout Standard
22392
22393
22394 \backslash
22395 /
22396 \end_layout
22397
22398 \end_inset
22399
22400 -constseg.
22401 \end_layout
22402
22403 \begin_layout Standard
22404 The preprocessor SDCPP
22405 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22406
22407 \end_inset
22408
22409  supports the following #pragma directives:
22410 \end_layout
22411
22412 \begin_layout Itemize
22413
22414 \series bold
22415 pedantic_parse_number
22416 \series default
22417
22418 \begin_inset LatexCommand \index{pedantic}
22419
22420 \end_inset
22421
22422
22423 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22424
22425 \end_inset
22426
22427  (+ | -) 
22428 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22429
22430 \end_inset
22431
22432 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22433  properly and the macro LO_B(3) gets expanded.
22434  Default is off.
22435  See also the -
22436 \begin_inset ERT
22437 status collapsed
22438
22439 \begin_layout Standard
22440
22441
22442 \backslash
22443 /
22444 \end_layout
22445
22446 \end_inset
22447
22448 -pedantic-parse-number command line option 
22449 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22450
22451 \end_inset
22452
22453 .
22454  
22455 \newline
22456 Below is an example on how to use this pragma.
22457
22458 \emph on
22459  Note: this functionality is not in conformance with standard!
22460 \end_layout
22461
22462 \begin_layout Verse
22463
22464 \family typewriter
22465 #pragma pedantic_parse_number +
22466 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22467
22468 \end_inset
22469
22470
22471 \newline
22472
22473 \newline
22474 #define LO_B(x) ((x) & 0xff)
22475 \newline
22476
22477 \newline
22478 unsigned char foo(void)
22479 \newline
22480 {
22481 \newline
22482 \InsetSpace ~
22483 \InsetSpace ~
22484 \InsetSpace ~
22485 unsigned char c=0xfe-LO_B(3)
22486 ;
22487 \newline
22488
22489 \newline
22490 \InsetSpace ~
22491 \InsetSpace ~
22492 \InsetSpace ~
22493 return c;
22494 \newline
22495 }
22496 \newline
22497
22498 \end_layout
22499
22500 \begin_layout Itemize
22501
22502 \series bold
22503 preproc_asm
22504 \series default
22505
22506 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22507
22508 \end_inset
22509
22510  (+ | -) - switch _asm _endasm block preprocessing on / off.
22511  Default is on.
22512  You use this prama to define multilines of assembly code.
22513  This will prevent the preprocessor from changing the formating required
22514  by assembly code.
22515  Below is an example on how to use this pragma.
22516 \end_layout
22517
22518 \begin_layout Verse
22519
22520 \family typewriter
22521 #pragma preproc_asm -
22522 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22523
22524 \end_inset
22525
22526
22527 \newline
22528 #define MYDELAY _asm
22529 \newline
22530 \InsetSpace ~
22531 \InsetSpace ~
22532 \InsetSpace ~
22533 nop ;my assembly comment...
22534 \newline
22535 \InsetSpace ~
22536 \InsetSpace ~
22537 \InsetSpace ~
22538 nop
22539 \newline
22540 \InsetSpace ~
22541 \InsetSpace ~
22542 \InsetSpace ~
22543 nop
22544 \newline
22545 _endasm
22546 \newline
22547 #pragma preproc_asm
22548  +
22549 \newline
22550
22551 \newline
22552 void foo (void) 
22553 \newline
22554
22555 \newline
22556 \InsetSpace ~
22557 \InsetSpace ~
22558 \InsetSpace ~
22559  ...
22560  
22561 \newline
22562 \InsetSpace ~
22563 \InsetSpace ~
22564 \InsetSpace ~
22565  MYDELAY;
22566 \newline
22567 \InsetSpace ~
22568 \InsetSpace ~
22569 \InsetSpace ~
22570  ...
22571  
22572 \newline
22573
22574 \newline
22575
22576 \end_layout
22577
22578 \begin_layout Itemize
22579
22580 \series bold
22581 sdcc_hash
22582 \series default
22583
22584 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22585
22586 \end_inset
22587
22588  (+ | -) - Allow "naked" hash in macro definition, for example:
22589 \newline
22590
22591 \family typewriter
22592 #define DIR_LO(x) #(x & 0xff)
22593 \family default
22594
22595 \newline
22596 Default is off.
22597  Below is an example on how to use this pragma.
22598 \end_layout
22599
22600 \begin_layout Verse
22601
22602 \family typewriter
22603 #pragma preproc_asm +
22604 \newline
22605 #pragma sdcc_hash +
22606 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22607
22608 \end_inset
22609
22610
22611 \newline
22612
22613 \newline
22614 #define ROMCALL(x) 
22615 \backslash
22616
22617 \newline
22618 \InsetSpace ~
22619 \InsetSpace ~
22620 \InsetSpace ~
22621 mov R6_B3, #(x & 0xff) 
22622 \backslash
22623
22624 \newline
22625 \InsetSpace ~
22626 \InsetSpace ~
22627 \InsetSpace ~
22628 mov R7_B3, #((x >> 8) & 0xff) 
22629 \backslash
22630
22631 \newline
22632 \InsetSpace ~
22633 \InsetSpace ~
22634 \InsetSpace ~
22635 lcall __romcall
22636 \newline
22637
22638 \newline
22639 ...
22640 \newline
22641 _asm
22642 \newline
22643 ROMCALL(72)
22644 \newline
22645 _endasm;
22646 \newline
22647 ...
22648 \newline
22649
22650 \end_layout
22651
22652 \begin_layout Standard
22653 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22654 ons which might cause the compiler to generate extra stack and/or data space
22655  to store compiler generated temporary variables.
22656  This usually happens in large functions.
22657  Pragma directives should be used as shown in the following example, they
22658  are used to control options and optimizations for a given function.
22659  
22660 \end_layout
22661
22662 \begin_layout Verse
22663
22664 \family typewriter
22665 #pragma save
22666 \begin_inset LatexCommand \index{\#pragma save}
22667
22668 \end_inset
22669
22670  \InsetSpace ~
22671 \InsetSpace ~
22672 \InsetSpace ~
22673 \InsetSpace ~
22674 \InsetSpace ~
22675 \InsetSpace ~
22676 \InsetSpace ~
22677 /* save the current settings */ 
22678 \newline
22679 #pragma nogcse
22680 \begin_inset LatexCommand \index{\#pragma nogcse}
22681
22682 \end_inset
22683
22684  \InsetSpace ~
22685 \InsetSpace ~
22686 \InsetSpace ~
22687 \InsetSpace ~
22688 \InsetSpace ~
22689 /* turnoff global subexpression elimination */ 
22690 \newline
22691 #pragma noinduction
22692 \begin_inset LatexCommand \index{\#pragma noinduction}
22693
22694 \end_inset
22695
22696  /* turn off induction optimizations */ 
22697 \newline
22698 int foo () 
22699 \newline
22700
22701 \newline
22702 \InsetSpace ~
22703  \InsetSpace ~
22704  ...
22705  
22706 \newline
22707 \InsetSpace ~
22708  \InsetSpace ~
22709  /* large code */ 
22710 \newline
22711 \InsetSpace ~
22712  \InsetSpace ~
22713  ...
22714  
22715 \newline
22716
22717 \newline
22718 #pragma restore
22719 \begin_inset LatexCommand \index{\#pragma restore}
22720
22721 \end_inset
22722
22723  /* turn the optimizations back on */
22724 \end_layout
22725
22726 \begin_layout Standard
22727 The compiler will generate a warning message when extra space is allocated.
22728  It is strongly recommended that the save and restore pragmas be used when
22729  changing options for a function.
22730 \newline
22731
22732 \newline
22733
22734 \newline
22735
22736 \end_layout
22737
22738 \begin_layout Section
22739 Defines Created by the Compiler
22740 \end_layout
22741
22742 \begin_layout Standard
22743 The compiler creates the following #defines
22744 \begin_inset LatexCommand \index{\#defines}
22745
22746 \end_inset
22747
22748
22749 \begin_inset LatexCommand \index{Defines created by the compiler}
22750
22751 \end_inset
22752
22753 :
22754 \newline
22755
22756 \end_layout
22757
22758 \begin_layout Standard
22759 \begin_inset Tabular
22760 <lyxtabular version="3" rows="15" columns="2">
22761 <features>
22762 <column alignment="left" valignment="top" leftline="true" width="3in">
22763 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22764 <row topline="true" bottomline="true">
22765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22766 \begin_inset Text
22767
22768 \begin_layout Standard
22769
22770 \series bold
22771 #define
22772 \end_layout
22773
22774 \end_inset
22775 </cell>
22776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22777 \begin_inset Text
22778
22779 \begin_layout Standard
22780
22781 \series bold
22782 Description
22783 \end_layout
22784
22785 \end_inset
22786 </cell>
22787 </row>
22788 <row topline="true">
22789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22790 \begin_inset Text
22791
22792 \begin_layout Standard
22793 SDCC
22794 \begin_inset LatexCommand \index{SDCC}
22795
22796 \end_inset
22797
22798  
22799 \end_layout
22800
22801 \end_inset
22802 </cell>
22803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22804 \begin_inset Text
22805
22806 \begin_layout Standard
22807 Always defined.
22808  Since version 2.5.6 the version number as an int (ex.
22809  256)
22810 \end_layout
22811
22812 \end_inset
22813 </cell>
22814 </row>
22815 <row topline="true">
22816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22817 \begin_inset Text
22818
22819 \begin_layout Standard
22820 SDCC_mcs51
22821 \begin_inset LatexCommand \index{SDCC\_mcs51}
22822
22823 \end_inset
22824
22825  or SDCC_ds390
22826 \begin_inset LatexCommand \index{SDCC\_ds390}
22827
22828 \end_inset
22829
22830  or SDCC_z80
22831 \begin_inset LatexCommand \index{SDCC\_z80}
22832
22833 \end_inset
22834
22835 , etc.
22836 \end_layout
22837
22838 \end_inset
22839 </cell>
22840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22841 \begin_inset Text
22842
22843 \begin_layout Standard
22844 depending on the model used (e.g.: -mds390)
22845 \end_layout
22846
22847 \end_inset
22848 </cell>
22849 </row>
22850 <row topline="true">
22851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22852 \begin_inset Text
22853
22854 \begin_layout Standard
22855 __mcs51
22856 \begin_inset LatexCommand \index{\_\_mcs51}
22857
22858 \end_inset
22859
22860 , __ds390
22861 \begin_inset LatexCommand \index{\_\_ds390}
22862
22863 \end_inset
22864
22865 , __hc08
22866 \begin_inset LatexCommand \index{\_\_hc08}
22867
22868 \end_inset
22869
22870 , __z80
22871 \begin_inset LatexCommand \index{\_\_z80}
22872
22873 \end_inset
22874
22875 , etc
22876 \end_layout
22877
22878 \end_inset
22879 </cell>
22880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22881 \begin_inset Text
22882
22883 \begin_layout Standard
22884 depending on the model used (e.g.
22885  -mz80)
22886 \end_layout
22887
22888 \end_inset
22889 </cell>
22890 </row>
22891 <row topline="true">
22892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22893 \begin_inset Text
22894
22895 \begin_layout Standard
22896 SDCC_STACK_AUTO
22897 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22898
22899 \end_inset
22900
22901
22902 \end_layout
22903
22904 \end_inset
22905 </cell>
22906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22907 \begin_inset Text
22908
22909 \begin_layout Standard
22910 when 
22911 \emph on
22912 -
22913 \begin_inset ERT
22914 status collapsed
22915
22916 \begin_layout Standard
22917
22918
22919 \backslash
22920 /
22921 \end_layout
22922
22923 \end_inset
22924
22925 -stack-auto
22926 \emph default
22927  option is used
22928 \end_layout
22929
22930 \end_inset
22931 </cell>
22932 </row>
22933 <row topline="true">
22934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22935 \begin_inset Text
22936
22937 \begin_layout Standard
22938 SDCC_MODEL_SMALL
22939 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22940
22941 \end_inset
22942
22943
22944 \end_layout
22945
22946 \end_inset
22947 </cell>
22948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22949 \begin_inset Text
22950
22951 \begin_layout Standard
22952 when 
22953 \emph on
22954 -
22955 \begin_inset ERT
22956 status collapsed
22957
22958 \begin_layout Standard
22959
22960
22961 \backslash
22962 /
22963 \end_layout
22964
22965 \end_inset
22966
22967 -model-small
22968 \emph default
22969  is used
22970 \end_layout
22971
22972 \end_inset
22973 </cell>
22974 </row>
22975 <row topline="true">
22976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22977 \begin_inset Text
22978
22979 \begin_layout Standard
22980 SDCC_MODEL_MEDIUM
22981 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22982
22983 \end_inset
22984
22985
22986 \end_layout
22987
22988 \end_inset
22989 </cell>
22990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22991 \begin_inset Text
22992
22993 \begin_layout Standard
22994 when 
22995 \emph on
22996 -
22997 \begin_inset ERT
22998 status collapsed
22999
23000 \begin_layout Standard
23001
23002
23003 \backslash
23004 /
23005 \end_layout
23006
23007 \end_inset
23008
23009 -model-medium
23010 \emph default
23011  is used
23012 \end_layout
23013
23014 \end_inset
23015 </cell>
23016 </row>
23017 <row topline="true">
23018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23019 \begin_inset Text
23020
23021 \begin_layout Standard
23022 SDCC_MODEL_LARGE
23023 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23024
23025 \end_inset
23026
23027
23028 \end_layout
23029
23030 \end_inset
23031 </cell>
23032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23033 \begin_inset Text
23034
23035 \begin_layout Standard
23036 when 
23037 \emph on
23038 -
23039 \begin_inset ERT
23040 status collapsed
23041
23042 \begin_layout Standard
23043
23044
23045 \backslash
23046 /
23047 \end_layout
23048
23049 \end_inset
23050
23051 -model-large
23052 \emph default
23053  is used
23054 \end_layout
23055
23056 \end_inset
23057 </cell>
23058 </row>
23059 <row topline="true">
23060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23061 \begin_inset Text
23062
23063 \begin_layout Standard
23064 SDCC_USE_XSTACK
23065 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23066
23067 \end_inset
23068
23069
23070 \end_layout
23071
23072 \end_inset
23073 </cell>
23074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23075 \begin_inset Text
23076
23077 \begin_layout Standard
23078 when 
23079 \emph on
23080 -
23081 \begin_inset ERT
23082 status collapsed
23083
23084 \begin_layout Standard
23085
23086
23087 \backslash
23088 /
23089 \end_layout
23090
23091 \end_inset
23092
23093 -xstack
23094 \emph default
23095  option is used
23096 \end_layout
23097
23098 \end_inset
23099 </cell>
23100 </row>
23101 <row topline="true">
23102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23103 \begin_inset Text
23104
23105 \begin_layout Standard
23106 SDCC_STACK_TENBIT
23107 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23108
23109 \end_inset
23110
23111  
23112 \end_layout
23113
23114 \end_inset
23115 </cell>
23116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23117 \begin_inset Text
23118
23119 \begin_layout Standard
23120 when 
23121 \emph on
23122 -mds390
23123 \emph default
23124  is used
23125 \end_layout
23126
23127 \end_inset
23128 </cell>
23129 </row>
23130 <row topline="true">
23131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23132 \begin_inset Text
23133
23134 \begin_layout Standard
23135 SDCC_MODEL_FLAT24
23136 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23137
23138 \end_inset
23139
23140
23141 \end_layout
23142
23143 \end_inset
23144 </cell>
23145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23146 \begin_inset Text
23147
23148 \begin_layout Standard
23149 when 
23150 \emph on
23151 -mds390
23152 \emph default
23153  is used
23154 \end_layout
23155
23156 \end_inset
23157 </cell>
23158 </row>
23159 <row topline="true">
23160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23161 \begin_inset Text
23162
23163 \begin_layout Standard
23164 SDCC_REVISION
23165 \begin_inset LatexCommand \index{SDCC\_REVISION}
23166
23167 \end_inset
23168
23169
23170 \end_layout
23171
23172 \end_inset
23173 </cell>
23174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23175 \begin_inset Text
23176
23177 \begin_layout Standard
23178 Always defined.
23179  SDCC svn revision number
23180 \end_layout
23181
23182 \end_inset
23183 </cell>
23184 </row>
23185 <row topline="true">
23186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23187 \begin_inset Text
23188
23189 \begin_layout Standard
23190 SDCC_PARMS_IN_BANK1
23191 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23192
23193 \end_inset
23194
23195
23196 \end_layout
23197
23198 \end_inset
23199 </cell>
23200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23201 \begin_inset Text
23202
23203 \begin_layout Standard
23204 when 
23205 \emph on
23206 -
23207 \begin_inset ERT
23208 status collapsed
23209
23210 \begin_layout Standard
23211
23212
23213 \backslash
23214 /
23215 \end_layout
23216
23217 \end_inset
23218
23219 -parms-in-bank1
23220 \emph default
23221  is used
23222 \end_layout
23223
23224 \end_inset
23225 </cell>
23226 </row>
23227 <row topline="true">
23228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23229 \begin_inset Text
23230
23231 \begin_layout Standard
23232 SDCC_FLOAT_REENT
23233 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23234
23235 \end_inset
23236
23237
23238 \end_layout
23239
23240 \end_inset
23241 </cell>
23242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23243 \begin_inset Text
23244
23245 \begin_layout Standard
23246 when 
23247 \emph on
23248 -
23249 \begin_inset ERT
23250 status collapsed
23251
23252 \begin_layout Standard
23253
23254
23255 \backslash
23256 /
23257 \end_layout
23258
23259 \end_inset
23260
23261 -float-reent
23262 \emph default
23263  is used
23264 \end_layout
23265
23266 \end_inset
23267 </cell>
23268 </row>
23269 <row topline="true" bottomline="true">
23270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23271 \begin_inset Text
23272
23273 \begin_layout Standard
23274 SDCC_INT_LONG_REENT
23275 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23276
23277 \end_inset
23278
23279
23280 \end_layout
23281
23282 \end_inset
23283 </cell>
23284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23285 \begin_inset Text
23286
23287 \begin_layout Standard
23288 when 
23289 \emph on
23290 -
23291 \begin_inset ERT
23292 status collapsed
23293
23294 \begin_layout Standard
23295
23296
23297 \backslash
23298 /
23299 \end_layout
23300
23301 \end_inset
23302
23303 -int-long-reent
23304 \emph default
23305  is used
23306 \end_layout
23307
23308 \end_inset
23309 </cell>
23310 </row>
23311 </lyxtabular>
23312
23313 \end_inset
23314
23315
23316 \end_layout
23317
23318 \begin_layout Chapter
23319 Notes on supported Processors
23320 \end_layout
23321
23322 \begin_layout Section
23323 MCS51 variants
23324 \begin_inset LatexCommand \label{sub:MCS51-variants}
23325
23326 \end_inset
23327
23328
23329 \begin_inset LatexCommand \index{MCS51 variants}
23330
23331 \end_inset
23332
23333
23334 \end_layout
23335
23336 \begin_layout Standard
23337 MCS51 processors are available from many vendors and come in many different
23338  flavours.
23339  While they might differ considerably in respect to Special Function Registers
23340  the core MCS51 is usually not modified or is kept compatible.
23341  
23342 \end_layout
23343
23344 \begin_layout Subsection
23345 pdata access by SFR 
23346 \end_layout
23347
23348 \begin_layout Standard
23349 With the upcome of devices with internal xdata and flash memory devices
23350  using port P2
23351 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23352
23353 \end_inset
23354
23355  as dedicated I/O port is becoming more popular.
23356  Switching the high byte for pdata
23357 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23358
23359 \end_inset
23360
23361  access which was formerly done by port P2 is then achieved by a Special
23362  Function Register
23363 \begin_inset LatexCommand \index{sfr}
23364
23365 \end_inset
23366
23367 .
23368  In well-established MCS51 tradition the address of this 
23369 \emph on
23370 sfr
23371 \emph default
23372  is where the chip designers decided to put it.
23373  Needless to say that they didn't agree on a common name either.
23374  So that the startup code can correctly initialize xdata variables, you
23375  should define an sfr with the name _XPAGE
23376 \family typewriter
23377
23378 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23379
23380 \end_inset
23381
23382
23383 \family default
23384  at the appropriate location if the default, port P2, is not used for this.
23385  Some examples are:
23386 \end_layout
23387
23388 \begin_layout Verse
23389
23390 \family typewriter
23391 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23392  MPAGE */
23393 \end_layout
23394
23395 \begin_layout Verse
23396
23397 \family typewriter
23398 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23399  a.k.a.
23400  MPAGE */
23401 \end_layout
23402
23403 \begin_layout Verse
23404
23405 \family typewriter
23406 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23407  XPAGE */
23408 \end_layout
23409
23410 \begin_layout Verse
23411
23412 \family typewriter
23413 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23414  EMI0CN */
23415 \end_layout
23416
23417 \begin_layout Verse
23418
23419 \family typewriter
23420 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23421  EMI0CN */
23422 \end_layout
23423
23424 \begin_layout Standard
23425 For more exotic implementations further customizations may be needed.
23426  See section 
23427 \begin_inset LatexCommand \ref{sub:Startup-Code}
23428
23429 \end_inset
23430
23431  for other possibilities.
23432 \end_layout
23433
23434 \begin_layout Subsection
23435 Other Features available by SFR
23436 \end_layout
23437
23438 \begin_layout Standard
23439 Some MCS51 variants offer features like Double DPTR
23440 \begin_inset LatexCommand \index{DPTR}
23441
23442 \end_inset
23443
23444 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23445  These are currently not used for the MCS51 port.
23446  If you absolutely need them you can fall back to inline assembly or submit
23447  a patch to SDCC.
23448 \end_layout
23449
23450 \begin_layout Subsection
23451 Bankswitching
23452 \end_layout
23453
23454 \begin_layout Standard
23455 Bankswitching
23456 \begin_inset LatexCommand \index{Bankswitching}
23457
23458 \end_inset
23459
23460  (a.k.a.
23461  code banking
23462 \begin_inset LatexCommand \index{code banking}
23463
23464 \end_inset
23465
23466 ) is a technique to increase the code space above the 64k limit of the 8051.
23467 \end_layout
23468
23469 \begin_layout Subsubsection
23470 Hardware
23471 \end_layout
23472
23473 \begin_layout Standard
23474 \begin_inset Tabular
23475 <lyxtabular version="3" rows="3" columns="4">
23476 <features>
23477 <column alignment="center" valignment="top" width="0">
23478 <column alignment="center" valignment="top" leftline="true" width="0">
23479 <column alignment="center" valignment="top" leftline="true" width="0">
23480 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23481 <row topline="true" bottomline="true">
23482 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23483 \begin_inset Text
23484
23485 \begin_layout Standard
23486 8000-FFFF
23487 \end_layout
23488
23489 \end_inset
23490 </cell>
23491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23492 \begin_inset Text
23493
23494 \begin_layout Standard
23495 bank1
23496 \end_layout
23497
23498 \end_inset
23499 </cell>
23500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23501 \begin_inset Text
23502
23503 \begin_layout Standard
23504 bank2
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 bank3
23514 \end_layout
23515
23516 \end_inset
23517 </cell>
23518 </row>
23519 <row topline="true" bottomline="true">
23520 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23521 \begin_inset Text
23522
23523 \begin_layout Standard
23524 0000-7FFF
23525 \end_layout
23526
23527 \end_inset
23528 </cell>
23529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23530 \begin_inset Text
23531
23532 \begin_layout Standard
23533 common
23534 \end_layout
23535
23536 \end_inset
23537 </cell>
23538 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23539 \begin_inset Text
23540
23541 \begin_layout Standard
23542
23543 \end_layout
23544
23545 \end_inset
23546 </cell>
23547 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23548 \begin_inset Text
23549
23550 \begin_layout Standard
23551
23552 \end_layout
23553
23554 \end_inset
23555 </cell>
23556 </row>
23557 <row>
23558 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23559 \begin_inset Text
23560
23561 \begin_layout Standard
23562 SiLabs C8051F120 example
23563 \end_layout
23564
23565 \end_inset
23566 </cell>
23567 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23568 \begin_inset Text
23569
23570 \begin_layout Standard
23571
23572 \end_layout
23573
23574 \end_inset
23575 </cell>
23576 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23577 \begin_inset Text
23578
23579 \begin_layout Standard
23580
23581 \end_layout
23582
23583 \end_inset
23584 </cell>
23585 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23586 \begin_inset Text
23587
23588 \begin_layout Standard
23589
23590 \end_layout
23591
23592 \end_inset
23593 </cell>
23594 </row>
23595 </lyxtabular>
23596
23597 \end_inset
23598
23599
23600 \newline
23601
23602 \newline
23603 Usually the hardware uses some sfr (an output port or an internal sfr) to
23604  select a bank and put it in the banked area of the memory map.
23605  The selected bank usually becomes active immediately upon assignment to
23606  this sfr and when running inside a bank it will switch out this code it
23607  is currently running.
23608  Therefor you cannot jump or call directly from one bank to another and
23609  need to use a so-called trampoline in the common area.
23610  For SDCC an example trampoline is in crtbank.asm and you may need to change
23611  it to your 8051 derivative or schematic.
23612  The presented code is written for the C8051F120.
23613 \newline
23614
23615 \newline
23616 When calling a banked function
23617  SDCC will put the LSB of the functions address in register R0, the MSB
23618  in R1 and the bank in R2 and then call this trampoline 
23619 \emph on
23620 __sdcc_banked_call
23621 \emph default
23622 .
23623  The current selected bank is saved on the stack, the new bank is selected
23624  and an indirect jump is made.
23625  When the banked function returns it jumps to 
23626 \emph on
23627 __sdcc_banked_ret
23628 \emph default
23629  which restores the previous bank and returns to the caller.
23630 \end_layout
23631
23632 \begin_layout Subsubsection
23633 Software
23634 \end_layout
23635
23636 \begin_layout Standard
23637 When writing banked software using SDCC you need to use some special keywords
23638  and options.
23639  You also need to take over a bit of work from the linker.
23640 \newline
23641
23642 \newline
23643 To create a function
23644  that can be called from another bank it requires the keyword 
23645 \emph on
23646 banked
23647 \emph default
23648
23649 \begin_inset LatexCommand \index{banked}
23650
23651 \end_inset
23652
23653 .
23654  The caller must see this in the prototype of the callee and the callee
23655  needs it for a proper return.
23656  Called functions within the same bank as the caller do not need the 
23657 \emph on
23658 banked
23659 \emph default
23660  keyword nor do functions in the common area.
23661  Beware: SDCC does not know or check if functions are in the same bank.
23662  This is your responsibility!
23663 \newline
23664
23665 \newline
23666 Normally all functions you write end up in
23667  the segment CSEG.
23668  If you want a function explicitly to reside in the common area put it in
23669  segment HOME.
23670  This applies for instance to interrupt service routines as they should
23671  not be banked.
23672 \end_layout
23673
23674 \begin_layout Standard
23675 Functions that need to be in a switched bank must be put in a named segment.
23676  The name can be mostly anything upto eight characters (e.g.
23677  BANK1).
23678  To do this you either use -
23679 \begin_inset ERT
23680 status collapsed
23681
23682 \begin_layout Standard
23683
23684
23685 \backslash
23686 /
23687 \end_layout
23688
23689 \end_inset
23690
23691 -codeseg BANK1 (See 
23692 \begin_inset LatexCommand \ref{lyx:-codeseg}
23693
23694 \end_inset
23695
23696 ) on the command line when compiling or #pragma codeseg BANK1 (See 
23697 \begin_inset LatexCommand \ref{sec:Pragmas}
23698
23699 \end_inset
23700
23701 ) at the top of the C source file.
23702  The segment name always applies to the whole source file and generated
23703  object so functions for different banks need to be defined in different
23704  source files.
23705 \newline
23706
23707 \newline
23708 When linking your objects you need to tell the linker where
23709  to put your segments.
23710  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23711 00 (See 
23712 \begin_inset LatexCommand \ref{lyx:-Wl option}
23713
23714 \end_inset
23715
23716 ).
23717  This sets the virtual start address of this segment.
23718  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23719  The linker will not check for overflows, again this is your responsibility.
23720 \end_layout
23721
23722 \begin_layout Standard
23723 \begin_inset VSpace bigskip
23724 \end_inset
23725
23726
23727 \end_layout
23728
23729 \begin_layout Section
23730 DS400 port
23731 \end_layout
23732
23733 \begin_layout Standard
23734 The DS80C400
23735 \begin_inset LatexCommand \index{DS80C400}
23736
23737 \end_inset
23738
23739
23740 \begin_inset LatexCommand \index{DS400}
23741
23742 \end_inset
23743
23744  microcontroller has a rich set of peripherals.
23745  In its built-in ROM library it includes functions to access some of the
23746  features, among them is a TCP stack with IP4 and IP6 support.
23747  Library headers (currently in beta status) and other files are provided
23748  at 
23749 \size footnotesize
23750
23751 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23752
23753 \end_inset
23754
23755 .
23756  
23757 \begin_inset VSpace bigskip
23758 \end_inset
23759
23760
23761 \end_layout
23762
23763 \begin_layout Section
23764 The Z80 and gbz80 port
23765 \end_layout
23766
23767 \begin_layout Standard
23768 SDCC can target both the Zilog Z80
23769 \begin_inset LatexCommand \index{Z80}
23770
23771 \end_inset
23772
23773  and the Nintendo Gameboy's Z80-like gbz80
23774 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23775
23776 \end_inset
23777
23778 .
23779  The Z80 port is passed through the same 
23780 \emph on
23781 regressions tests
23782 \begin_inset LatexCommand \index{Regression test}
23783
23784 \end_inset
23785
23786
23787 \emph default
23788  (see section 
23789 \begin_inset LatexCommand \ref{sec:Quality-control}
23790
23791 \end_inset
23792
23793 ) as the MCS51 and DS390 ports, so floating point support, support for long
23794  variables and bitfield support is fine.
23795  See mailing lists and forums about interrupt routines.
23796 \end_layout
23797
23798 \begin_layout Standard
23799 As always, the code is the authoritative reference - see z80/ralloc.c and
23800  z80/gen.c.
23801  The stack
23802 \begin_inset LatexCommand \index{Z80!stack}
23803
23804 \end_inset
23805
23806  frame is similar to that generated by the IAR Z80 compiler.
23807  IX is used as the base pointer, HL and IY are used as a temporary registers,
23808  and BC and DE are available for holding variables.
23809  Return values
23810 \begin_inset LatexCommand \index{Z80!return value}
23811
23812 \end_inset
23813
23814  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23815  bytes).
23816  The gbz80 port use the same set of registers for the return values, but
23817  in a different order of significance: E (one byte), DE (two bytes), or
23818  HLDE (four bytes).
23819 \begin_inset VSpace bigskip
23820 \end_inset
23821
23822
23823 \end_layout
23824
23825 \begin_layout Section
23826 The HC08 port
23827 \end_layout
23828
23829 \begin_layout Standard
23830 The port to the Freescale/Motorola HC08
23831 \begin_inset LatexCommand \index{HC08}
23832
23833 \end_inset
23834
23835  family has been added in October 2003, and is still undergoing some basic
23836  development.
23837  The code generator is complete, but the register allocation is still quite
23838  unoptimized.
23839  Some of the SDCC's standard C library functions have embedded non-HC08
23840  inline assembly and so are not yet usable.
23841 \end_layout
23842
23843 \begin_layout Standard
23844 The HC08 port passes the regression test suite (see section 
23845 \begin_inset LatexCommand \ref{sec:Quality-control}
23846
23847 \end_inset
23848
23849 ).
23850 \begin_inset VSpace bigskip
23851 \end_inset
23852
23853
23854 \end_layout
23855
23856 \begin_layout Section
23857 The PIC14
23858 \begin_inset LatexCommand \index{PIC14}
23859
23860 \end_inset
23861
23862  port
23863 \end_layout
23864
23865 \begin_layout Standard
23866 The PIC14 port adds support for Microchip
23867 \begin_inset LatexCommand \index{Microchip}
23868
23869 \end_inset
23870
23871
23872 \begin_inset Formula $^{\text{TM}}$
23873 \end_inset
23874
23875  PIC
23876 \begin_inset LatexCommand \index{PIC14}
23877
23878 \end_inset
23879
23880
23881 \begin_inset Formula $^{\text{TM}}$
23882 \end_inset
23883
23884  MCUs with 14 bit wide instructions.
23885  This port is not yet mature and still lacks many features.
23886  However, it can work for simple code.
23887 \end_layout
23888
23889 \begin_layout Standard
23890 Currently supported devices include:
23891 \end_layout
23892
23893 \begin_layout Standard
23894 12F: 629, 635, 675, 683
23895 \end_layout
23896
23897 \begin_layout Standard
23898 16C: 432, 433
23899 \end_layout
23900
23901 \begin_layout Standard
23902 16C: 554, 557, 558
23903 \end_layout
23904
23905 \begin_layout Standard
23906 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23907 \end_layout
23908
23909 \begin_layout Standard
23910 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23911  781, 782
23912 \end_layout
23913
23914 \begin_layout Standard
23915 16C: 925, 926
23916 \end_layout
23917
23918 \begin_layout Standard
23919 16CR: 620a, 73, 74, 76, 77
23920 \end_layout
23921
23922 \begin_layout Standard
23923 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
23924  687, 688, 689, 690
23925 \end_layout
23926
23927 \begin_layout Standard
23928 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
23929 \end_layout
23930
23931 \begin_layout Standard
23932 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23933  877, 877a, 88, 886, 887
23934 \end_layout
23935
23936 \begin_layout Standard
23937 16F: 913, 914, 916, 917, 946
23938 \end_layout
23939
23940 \begin_layout Standard
23941 26HV: 626, 785
23942 \end_layout
23943
23944 \begin_layout Standard
23945 An up-to-date list of currently supported devices can be obtained via 
23946 \family typewriter
23947 sdcc -mpic14 -phelp foo.c
23948 \family default
23949  (foo.c must exist...).
23950 \end_layout
23951
23952 \begin_layout Subsection
23953 PIC Code Pages
23954 \begin_inset LatexCommand \index{code page (pic14)}
23955
23956 \end_inset
23957
23958  and Memory Banks
23959 \begin_inset LatexCommand \index{Memory bank (pic14)}
23960
23961 \end_inset
23962
23963
23964 \end_layout
23965
23966 \begin_layout Standard
23967 The linker organizes allocation for the code page and RAM banks.
23968  It does not have intimate knowledge of the code flow.
23969  It will put all the code section of a single .asm file into a single code
23970  page.
23971  In order to make use of multiple code pages, separate asm files must be
23972  used.
23973  The compiler assigns all 
23974 \emph on
23975 static
23976 \emph default
23977  functions of a single .c file into the same code page.
23978 \newline
23979
23980 \newline
23981 To get the best results,
23982  follow these guidelines:
23983 \end_layout
23984
23985 \begin_layout Enumerate
23986 Make local functions static, as non static functions require code page selection
23987  overhead.
23988 \newline
23989 Due to the way sdcc handles functions, place called functions prior
23990  to calling functions in the file wherever possible: Otherwise sdcc will
23991  insert unneccessary pagesel directives around the call, believing that
23992  the called function is externally defined.
23993 \end_layout
23994
23995 \begin_layout Enumerate
23996 For devices that have multiple code pages it is more efficient to use the
23997  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23998  but only 2 files for the 16F874.
23999  This way the linker can put the code for each file into different code
24000  pages and there will be less page selection overhead.
24001 \end_layout
24002
24003 \begin_layout Enumerate
24004 And as for any 8 bit micro (especially for PIC14 as they have a very simple
24005  instruction set), use `unsigned char' wherever possible instead of `int'.
24006 \end_layout
24007
24008 \begin_layout Subsection
24009 Adding New Devices to the Port 
24010 \end_layout
24011
24012 \begin_layout Standard
24013 Adding support for a new 14
24014 \begin_inset ERT
24015 status open
24016
24017 \begin_layout Standard
24018
24019
24020 \backslash
24021 ,
24022 \end_layout
24023
24024 \end_inset
24025
24026 bit PIC MCU requires the following steps:
24027 \end_layout
24028
24029 \begin_layout Enumerate
24030 Create a new device description.
24031 \newline
24032 Each device is described in two files: pic16f*.h
24033  and pic16f*.c.
24034  These files primarily define SFRs, structs to access their bits, and symbolic
24035  configuration options.
24036  Both files can be generated from gputils' .inc files using the perl script
24037  
24038 \family typewriter
24039 support/scripts/inc2h.pl
24040 \family default
24041 .
24042  This file also contains further instructions on how to proceed.
24043 \end_layout
24044
24045 \begin_layout Enumerate
24046 Copy the .h file into SDCC's include path and either add the .c file to your
24047  project or copy it to 
24048 \family typewriter
24049 device/lib/pic/libdev
24050 \family default
24051 .
24052  Afterwards, rebuild and install the libraries.
24053 \end_layout
24054
24055 \begin_layout Enumerate
24056 Edit pic14devices.txt in SDCC's include path (
24057 \family typewriter
24058 device/include/pic/
24059 \family default
24060  in the source tree or 
24061 \family typewriter
24062 /usr/local/share/sdcc/include/pic
24063 \family default
24064  after installation).
24065 \newline
24066 You need to add a device specification here to make
24067  the memory layout (code banks, RAM, aliased memory regions, ...) known to
24068  the compiler.
24069  Probably you can copy and modify an existing entry.
24070  The file format is documented at the top of the file.
24071 \end_layout
24072
24073 \begin_layout Subsection
24074 Interrupt Code
24075 \end_layout
24076
24077 \begin_layout Standard
24078 For the interrupt function, use the keyword `__interrupt'
24079 \begin_inset LatexCommand \index{PIC14!interrupt}
24080
24081 \end_inset
24082
24083  with level number of 0 (PIC14 only has 1 interrupt so this number is only
24084  there to avoid a syntax error - it ought to be fixed).
24085  E.g.:
24086 \end_layout
24087
24088 \begin_layout Verse
24089
24090 \family typewriter
24091 void Intr(void) __interrupt 0
24092 \newline
24093 {
24094 \newline
24095 \InsetSpace ~
24096 \InsetSpace ~
24097 T0IF = 0; /* Clear timer interrupt */
24098 \newline
24099 }
24100 \end_layout
24101
24102 \begin_layout Subsection
24103 Linking and Assembling
24104 \end_layout
24105
24106 \begin_layout Standard
24107 For assembling you can use either GPUTILS'
24108 \begin_inset LatexCommand \index{gputils (pic tools)}
24109
24110 \end_inset
24111
24112  gpasm.exe or MPLAB's mpasmwin.exe.
24113  GPUTILS are available from 
24114 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24115
24116 \end_inset
24117
24118 .
24119  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24120  If you use MPLAB and an interrupt function then the linker script file
24121  vectors section will need to be enlarged to link with mplink.
24122 \newline
24123
24124 \newline
24125 Here is a 
24126 \family typewriter
24127 Makefile
24128 \family default
24129  using GPUTILS:
24130 \end_layout
24131
24132 \begin_layout Verse
24133
24134 \family typewriter
24135 .c.o:
24136 \newline
24137 \InsetSpace ~
24138 \InsetSpace ~
24139 \InsetSpace ~
24140 \InsetSpace ~
24141 \InsetSpace ~
24142 \InsetSpace ~
24143 \InsetSpace ~
24144 \InsetSpace ~
24145 sdcc -V -mpic14 -p16f877 -c $< 
24146 \newline
24147
24148 \newline
24149 $(PRJ).hex: $(OBJS) 
24150 \newline
24151 \InsetSpace ~
24152 \InsetSpace ~
24153 \InsetSpace ~
24154 \InsetSpace ~
24155 \InsetSpace ~
24156 \InsetSpace ~
24157 \InsetSpace ~
24158 \InsetSpace ~
24159 gplink -m -s $(PRJ).lkr
24160  -o $(PRJ).hex $(OBJS) libsdcc.lib
24161 \end_layout
24162
24163 \begin_layout Standard
24164 Here is a 
24165 \family typewriter
24166 Makefile
24167 \family default
24168  using MPLAB:
24169 \end_layout
24170
24171 \begin_layout Verse
24172
24173 \family typewriter
24174 .c.o: 
24175 \newline
24176 \InsetSpace ~
24177 \InsetSpace ~
24178 \InsetSpace ~
24179 \InsetSpace ~
24180 \InsetSpace ~
24181 \InsetSpace ~
24182 \InsetSpace ~
24183 \InsetSpace ~
24184 sdcc -S -V -mpic14 -p16f877 $< 
24185 \newline
24186 \InsetSpace ~
24187 \InsetSpace ~
24188 \InsetSpace ~
24189 \InsetSpace ~
24190 \InsetSpace ~
24191 \InsetSpace ~
24192 \InsetSpace ~
24193 \InsetSpace ~
24194 mpasmwin /q /o $*.asm
24195 \newline
24196
24197 \newline
24198 $(PRJ).hex: $(OBJS)
24199  
24200 \newline
24201 \InsetSpace ~
24202 \InsetSpace ~
24203 \InsetSpace ~
24204 \InsetSpace ~
24205 \InsetSpace ~
24206 \InsetSpace ~
24207 \InsetSpace ~
24208 \InsetSpace ~
24209 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24210 \end_layout
24211
24212 \begin_layout Standard
24213 Please note that indentations within a
24214 \family typewriter
24215  Makefile
24216 \family default
24217  have to be done with a tabulator character.
24218 \end_layout
24219
24220 \begin_layout Subsection
24221 Command-Line Options
24222 \end_layout
24223
24224 \begin_layout Standard
24225 Besides the switches common to all SDCC backends, the PIC14 port accepts
24226  the following options (for an updated list see sdcc -
24227 \begin_inset ERT
24228 status collapsed
24229
24230 \begin_layout Standard
24231
24232
24233 \backslash
24234 /
24235 \end_layout
24236
24237 \end_inset
24238
24239 -help):
24240 \end_layout
24241
24242 \begin_layout Description
24243 -
24244 \begin_inset ERT
24245 status collapsed
24246
24247 \begin_layout Standard
24248
24249
24250 \backslash
24251 /
24252 \end_layout
24253
24254 \end_inset
24255
24256 -debug-xtra
24257 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24258
24259 \end_inset
24260
24261  emit debug info in assembly output
24262 \end_layout
24263
24264 \begin_layout Description
24265 -
24266 \begin_inset ERT
24267 status collapsed
24268
24269 \begin_layout Standard
24270
24271
24272 \backslash
24273 /
24274 \end_layout
24275
24276 \end_inset
24277
24278 -no-pcode-opt
24279 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24280
24281 \end_inset
24282
24283  disable (slightly faulty) optimization on pCode
24284 \end_layout
24285
24286 \begin_layout Description
24287 -
24288 \begin_inset ERT
24289 status collapsed
24290
24291 \begin_layout Standard
24292
24293
24294 \backslash
24295 /
24296 \end_layout
24297
24298 \end_inset
24299
24300 -stack-loc
24301 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24302
24303 \end_inset
24304
24305  sets the lowest address of the argument passing stack (defaults to a suitably
24306  large shared databank to reduce BANKSEL overhead)
24307 \end_layout
24308
24309 \begin_layout Description
24310 -
24311 \begin_inset ERT
24312 status collapsed
24313
24314 \begin_layout Standard
24315
24316
24317 \backslash
24318 /
24319 \end_layout
24320
24321 \end_inset
24322
24323 -stack-size
24324 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24325
24326 \end_inset
24327
24328  sets the size if the argument passing stack (default: 16, minimum: 4)
24329 \end_layout
24330
24331 \begin_layout Subsection
24332 Environment Variables
24333 \end_layout
24334
24335 \begin_layout Standard
24336 The PIC14 port recognizes the following environment variables:
24337 \end_layout
24338
24339 \begin_layout Description
24340 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24341  register (the ones called r0xNNNN) in a section of its own.
24342  By default (if this variable is unset), sdcc tries to cluster registers
24343  in sections in order to reduce the BANKSEL overhead when accessing them.
24344 \end_layout
24345
24346 \begin_layout Subsection
24347 The Library
24348 \end_layout
24349
24350 \begin_layout Standard
24351 The PIC14 library currently only contains support routines required by the
24352  compiler to implement multiplication, division, and floating point support.
24353  No libc-like replacement is available at the moment, though many of the
24354  common sdcc library sources (in 
24355 \family typewriter
24356 device/lib
24357 \family default
24358 ) should also compile with the PIC14 port.
24359 \end_layout
24360
24361 \begin_layout Subsubsection
24362 error: missing definition for symbol ``__gptrget1''
24363 \end_layout
24364
24365 \begin_layout Standard
24366 The PIC14 port uses library routines to provide more complex operations
24367  like multiplication, division/modulus and (generic) pointer dereferencing.
24368  In order to add these routines to your project, you must link with PIC14's
24369  
24370 \family typewriter
24371 libsdcc.lib
24372 \family default
24373 .
24374  For single source file projects this is done automatically, more complex
24375  projects must add 
24376 \family typewriter
24377 libsdcc.lib
24378 \family default
24379  to the linker's arguments.
24380  Make sure you also add an include path for the library (using the -I switch
24381  to the linker)!
24382 \end_layout
24383
24384 \begin_layout Subsubsection
24385 Processor mismatch in file ``XXX''.
24386 \end_layout
24387
24388 \begin_layout Standard
24389 This warning can usually be ignored due to the very good compatibility amongst
24390  14
24391 \begin_inset ERT
24392 status open
24393
24394 \begin_layout Standard
24395
24396
24397 \backslash
24398 ,
24399 \end_layout
24400
24401 \end_inset
24402
24403 bit PIC
24404 \begin_inset LatexCommand \index{PIC14}
24405
24406 \end_inset
24407
24408  devices.
24409 \end_layout
24410
24411 \begin_layout Standard
24412 You might also consider recompiling the library for your specific device
24413  by changing the ARCH=p16f877 (default target) entry in 
24414 \family typewriter
24415 device/lib/pic/Makefile.in
24416 \family default
24417  and 
24418 \family typewriter
24419 device/lib/pic/Makefile
24420 \family default
24421  to reflect your device.
24422  This might even improve performance for smaller devices as unneccesary
24423  BANKSELs might be removed.
24424 \end_layout
24425
24426 \begin_layout Subsection
24427 Known Bugs
24428 \end_layout
24429
24430 \begin_layout Subsubsection
24431 Function arguments
24432 \end_layout
24433
24434 \begin_layout Standard
24435 Functions with variable argument lists (like printf) are not yet supported.
24436  Similarly, taking the address of the first argument passed into a function
24437  does not work: It is currently passed in WREG and has no address...
24438 \end_layout
24439
24440 \begin_layout Subsubsection
24441 Regression tests fail
24442 \end_layout
24443
24444 \begin_layout Standard
24445 Though the small subset of regression tests in src/regression passes, SDCC
24446  regression test suite does not, indicating that there are still major bugs
24447  in the port.
24448  However, many smaller projects have successfully used SDCC in the past...
24449 \end_layout
24450
24451 \begin_layout Standard
24452
24453 \size footnotesize
24454
24455 \newpage
24456
24457 \end_layout
24458
24459 \begin_layout Section
24460 The PIC16
24461 \begin_inset LatexCommand \index{PIC16}
24462
24463 \end_inset
24464
24465  port
24466 \end_layout
24467
24468 \begin_layout Standard
24469 The PIC16 port adds support for Microchip
24470 \begin_inset LatexCommand \index{Microchip}
24471
24472 \end_inset
24473
24474
24475 \begin_inset Formula $^{\text{TM}}$
24476 \end_inset
24477
24478  PIC
24479 \begin_inset LatexCommand \index{PIC}
24480
24481 \end_inset
24482
24483
24484 \begin_inset Formula $^{\text{TM}}$
24485 \end_inset
24486
24487  MCUs with 16 bit wide instructions.
24488  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24489 ; devices supported by the port include:
24490 \end_layout
24491
24492 \begin_layout Standard
24493 18F: 242, 248, 252, 258, 442, 448, 452, 458
24494 \end_layout
24495
24496 \begin_layout Standard
24497 18F: 1220, 1320
24498 \end_layout
24499
24500 \begin_layout Standard
24501 18F: 2220, 2221, 2320, 2321, 2331, 2420, 2423, 2431, 2455, 2480, 24j10
24502 \end_layout
24503
24504 \begin_layout Standard
24505 18F: 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2620, 2680, 2682, 2685
24506 \end_layout
24507
24508 \begin_layout Standard
24509 18F: 4220, 4221, 4320, 4321, 4331, 4420, 4423, 4431, 4455, 4480, 44j10
24510 \end_layout
24511
24512 \begin_layout Standard
24513 18F: 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4620, 4680, 4682, 4685
24514 \end_layout
24515
24516 \begin_layout Standard
24517 18F: 6520, 6585, 6620, 6680, 6720
24518 \end_layout
24519
24520 \begin_layout Standard
24521 18F: 8520, 8585, 8620, 8680, 8720
24522 \end_layout
24523
24524 \begin_layout Standard
24525 A list of supported devices is also available via '
24526 \family typewriter
24527 sdcc -mpic16 -plist
24528 \family default
24529 '.
24530 \end_layout
24531
24532 \begin_layout Subsection
24533 Global Options
24534 \end_layout
24535
24536 \begin_layout Standard
24537 PIC16 port supports the standard command line arguments as supposed, with
24538  the exception of certain cases that will be mentioned in the following
24539  list:
24540 \end_layout
24541
24542 \begin_layout Description
24543 -
24544 \begin_inset ERT
24545 status collapsed
24546
24547 \begin_layout Standard
24548
24549
24550 \backslash
24551 /
24552 \end_layout
24553
24554 \end_inset
24555
24556 -callee-saves
24557 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24558
24559 \end_inset
24560
24561  See -
24562 \begin_inset ERT
24563 status collapsed
24564
24565 \begin_layout Standard
24566
24567
24568 \backslash
24569 /
24570 \end_layout
24571
24572 \end_inset
24573
24574 -all-callee-saves
24575 \end_layout
24576
24577 \begin_layout Description
24578 -
24579 \begin_inset ERT
24580 status collapsed
24581
24582 \begin_layout Standard
24583
24584
24585 \backslash
24586 /
24587 \end_layout
24588
24589 \end_inset
24590
24591 -fommit-frame-pointer
24592 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24593
24594 \end_inset
24595
24596  Frame pointer will be omitted when the function uses no local variables.
24597 \end_layout
24598
24599 \begin_layout Subsection
24600 Port Specific Options
24601 \begin_inset LatexCommand \index{Options PIC16}
24602
24603 \end_inset
24604
24605
24606 \end_layout
24607
24608 \begin_layout Standard
24609 The port specific options appear after the global options in the sdcc -
24610 \begin_inset ERT
24611 status collapsed
24612
24613 \begin_layout Standard
24614
24615
24616 \backslash
24617 /
24618 \end_layout
24619
24620 \end_inset
24621
24622 -help output.
24623 \end_layout
24624
24625 \begin_layout Subsubsection
24626 Code Generation Options
24627 \end_layout
24628
24629 \begin_layout Standard
24630 These options influence the generated assembler code.
24631 \end_layout
24632
24633 \begin_layout Description
24634 -
24635 \begin_inset ERT
24636 status collapsed
24637
24638 \begin_layout Standard
24639
24640
24641 \backslash
24642 /
24643 \end_layout
24644
24645 \end_inset
24646
24647 -pstack-model=[model] Used in conjuction with the command above.
24648  Defines the stack model to be used, valid stack models are:
24649 \end_layout
24650
24651 \begin_deeper
24652 \begin_layout List
24653 \labelwidthstring 00.00.0000
24654
24655 \emph on
24656 small
24657 \emph default
24658  Selects small stack model.
24659  8 bit stack and frame pointers.
24660  Supports 256 bytes stack size.
24661 \end_layout
24662
24663 \begin_layout List
24664 \labelwidthstring 00.00.0000
24665
24666 \emph on
24667 large
24668 \emph default
24669  Selects large stack model.
24670  16 bit stack and frame pointers.
24671  Supports 65536 bytes stack size.
24672 \end_layout
24673
24674 \end_deeper
24675 \begin_layout Description
24676 -
24677 \begin_inset ERT
24678 status collapsed
24679
24680 \begin_layout Standard
24681
24682
24683 \backslash
24684 /
24685 \end_layout
24686
24687 \end_inset
24688
24689 -pno-banksel Do not generate BANKSEL assembler directives.
24690 \end_layout
24691
24692 \begin_layout Description
24693 -
24694 \begin_inset ERT
24695 status collapsed
24696
24697 \begin_layout Standard
24698
24699
24700 \backslash
24701 /
24702 \end_layout
24703
24704 \end_inset
24705
24706 -extended Enable extended instruction set/literal offset addressing mode.
24707  Use with care!
24708 \end_layout
24709
24710 \begin_layout Subsubsection
24711 Optimization Options
24712 \end_layout
24713
24714 \begin_layout Description
24715 -
24716 \begin_inset ERT
24717 status collapsed
24718
24719 \begin_layout Standard
24720
24721
24722 \backslash
24723 /
24724 \end_layout
24725
24726 \end_inset
24727
24728 -obanksel=n Set optimization level for inserting BANKSELs.
24729 \newline
24730
24731 \end_layout
24732
24733 \begin_deeper
24734 \begin_layout List
24735 \labelwidthstring 00.00.0000
24736 0 no optimization
24737 \end_layout
24738
24739 \begin_layout List
24740 \labelwidthstring 00.00.0000
24741 1 checks previous used register and if it is the same then does not emit
24742  BANKSEL, accounts only for labels.
24743 \end_layout
24744
24745 \begin_layout List
24746 \labelwidthstring 00.00.0000
24747 2 tries to check the location of (even different) symbols and removes BANKSELs
24748  if they are in the same bank.
24749  
24750 \newline
24751
24752 \emph on
24753 Important: There might be problems if the linker script has data sections
24754  across bank borders!
24755 \end_layout
24756
24757 \end_deeper
24758 \begin_layout Description
24759 -
24760 \begin_inset ERT
24761 status collapsed
24762
24763 \begin_layout Standard
24764
24765
24766 \backslash
24767 /
24768 \end_layout
24769
24770 \end_inset
24771
24772 -denable-peeps Force the usage of peepholes.
24773  Use with care.
24774 \end_layout
24775
24776 \begin_layout Description
24777 -
24778 \begin_inset ERT
24779 status collapsed
24780
24781 \begin_layout Standard
24782
24783
24784 \backslash
24785 /
24786 \end_layout
24787
24788 \end_inset
24789
24790 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24791 \end_layout
24792
24793 \begin_layout Description
24794 -
24795 \begin_inset ERT
24796 status collapsed
24797
24798 \begin_layout Standard
24799
24800
24801 \backslash
24802 /
24803 \end_layout
24804
24805 \end_inset
24806
24807 -optimize-cmp Try to optimize some compares.
24808 \end_layout
24809
24810 \begin_layout Description
24811 -
24812 \begin_inset ERT
24813 status collapsed
24814
24815 \begin_layout Standard
24816
24817
24818 \backslash
24819 /
24820 \end_layout
24821
24822 \end_inset
24823
24824 -optimize-df Analyze the dataflow of the generated code and improve it.
24825 \end_layout
24826
24827 \begin_layout Subsubsection
24828 Assembling Options
24829 \end_layout
24830
24831 \begin_layout Description
24832 -
24833 \begin_inset ERT
24834 status collapsed
24835
24836 \begin_layout Standard
24837
24838
24839 \backslash
24840 /
24841 \end_layout
24842
24843 \end_inset
24844
24845 -asm= Sets the full path and name of an external assembler to call.
24846 \end_layout
24847
24848 \begin_layout Description
24849 -
24850 \begin_inset ERT
24851 status collapsed
24852
24853 \begin_layout Standard
24854
24855
24856 \backslash
24857 /
24858 \end_layout
24859
24860 \end_inset
24861
24862 -mplab-comp MPLAB
24863 \begin_inset LatexCommand \index{PIC16!MPLAB}
24864
24865 \end_inset
24866
24867  compatibility option.
24868  Currently only suppresses special gpasm directives.
24869 \end_layout
24870
24871 \begin_layout Subsubsection
24872 Linking Options
24873 \end_layout
24874
24875 \begin_layout Description
24876 -
24877 \begin_inset ERT
24878 status collapsed
24879
24880 \begin_layout Standard
24881
24882
24883 \backslash
24884 /
24885 \end_layout
24886
24887 \end_inset
24888
24889 -link= Sets the full path and name of an external linker to call.
24890 \end_layout
24891
24892 \begin_layout Description
24893 -
24894 \begin_inset ERT
24895 status collapsed
24896
24897 \begin_layout Standard
24898
24899
24900 \backslash
24901 /
24902 \end_layout
24903
24904 \end_inset
24905
24906 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24907  unitialized data variables with [kword].
24908  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24909 \end_layout
24910
24911 \begin_layout Description
24912 -
24913 \begin_inset ERT
24914 status collapsed
24915
24916 \begin_layout Standard
24917
24918
24919 \backslash
24920 /
24921 \end_layout
24922
24923 \end_inset
24924
24925 -ivt-loc=n Place the interrupt vector table at address 
24926 \emph on
24927 n
24928 \emph default
24929 .
24930  Useful for bootloaders.
24931 \end_layout
24932
24933 \begin_layout Description
24934 -
24935 \begin_inset ERT
24936 status collapsed
24937
24938 \begin_layout Standard
24939
24940
24941 \backslash
24942 /
24943 \end_layout
24944
24945 \end_inset
24946
24947 -nodefaultlibs Do not link default libraries when linking.
24948 \end_layout
24949
24950 \begin_layout Description
24951 -
24952 \begin_inset ERT
24953 status collapsed
24954
24955 \begin_layout Standard
24956
24957
24958 \backslash
24959 /
24960 \end_layout
24961
24962 \end_inset
24963
24964 -use-crt= Use a custom run-time module instead of the defaults.
24965 \end_layout
24966
24967 \begin_layout Description
24968 -
24969 \begin_inset ERT
24970 status collapsed
24971
24972 \begin_layout Standard
24973
24974
24975 \backslash
24976 /
24977 \end_layout
24978
24979 \end_inset
24980
24981 -no-crt Don't link the default run-time modules
24982 \end_layout
24983
24984 \begin_layout Subsubsection
24985 Debugging Options
24986 \end_layout
24987
24988 \begin_layout Standard
24989 Debugging options enable extra debugging information in the output files.
24990 \end_layout
24991
24992 \begin_layout Description
24993 -
24994 \begin_inset ERT
24995 status collapsed
24996
24997 \begin_layout Standard
24998
24999
25000 \backslash
25001 /
25002 \end_layout
25003
25004 \end_inset
25005
25006 -debug-xtra Similar to -
25007 \begin_inset ERT
25008 status collapsed
25009
25010 \begin_layout Standard
25011
25012
25013 \backslash
25014 /
25015 \end_layout
25016
25017 \end_inset
25018
25019 -debug
25020 \begin_inset LatexCommand \index{-\/-debug}
25021
25022 \end_inset
25023
25024 , but dumps more information.
25025 \end_layout
25026
25027 \begin_layout Description
25028 -
25029 \begin_inset ERT
25030 status collapsed
25031
25032 \begin_layout Standard
25033
25034
25035 \backslash
25036 /
25037 \end_layout
25038
25039 \end_inset
25040
25041 -debug-ralloc Force register allocator to dump <source>.d file with debugging
25042  information.
25043  <source> is the name of the file being compiled.
25044 \end_layout
25045
25046 \begin_layout Description
25047 -
25048 \begin_inset ERT
25049 status collapsed
25050
25051 \begin_layout Standard
25052
25053
25054 \backslash
25055 /
25056 \end_layout
25057
25058 \end_inset
25059
25060 -pcode-verbose Enable pcode debugging information in translation.
25061 \end_layout
25062
25063 \begin_layout Description
25064 -
25065 \begin_inset ERT
25066 status collapsed
25067
25068 \begin_layout Standard
25069
25070
25071 \backslash
25072 /
25073 \end_layout
25074
25075 \end_inset
25076
25077 -calltree Dump call tree in .calltree file.
25078 \end_layout
25079
25080 \begin_layout Description
25081 -
25082 \begin_inset ERT
25083 status collapsed
25084
25085 \begin_layout Standard
25086
25087
25088 \backslash
25089 /
25090 \end_layout
25091
25092 \end_inset
25093
25094 -gstack Trace push/pops for stack pointer overflow.
25095 \end_layout
25096
25097 \begin_layout Subsection
25098 Enviroment Variables
25099 \end_layout
25100
25101 \begin_layout Standard
25102 There is a number of enviromental variables that can be used when running
25103  SDCC to enable certain optimizations or force a specific program behaviour.
25104  these variables are primarily for debugging purposes so they can be enabled/dis
25105 abled at will.
25106 \end_layout
25107
25108 \begin_layout Standard
25109 Currently there is only two such variables available:
25110 \end_layout
25111
25112 \begin_layout Description
25113 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25114  bitfields is optimized by directly loading FSR0 with the address of the
25115  bitfield structure.
25116  Normally SDCC will cast the bitfield structure to a bitfield pointer and
25117  then load FSR0.
25118  This step saves data ram and code space for functions that make heavy use
25119  of bitfields.
25120  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25121  option).
25122  
25123 \end_layout
25124
25125 \begin_layout Description
25126 NO_REG_OPT Do not perform pCode registers optimization.
25127  This should be used for debugging purposes.
25128  If bugs in the pcode optimizer are found, users can benefit from temporarily
25129  disabling the optimizer until the bug is fixed.
25130 \end_layout
25131
25132 \begin_layout Subsection
25133 Preprocessor Macros
25134 \end_layout
25135
25136 \begin_layout Standard
25137 PIC16
25138 \begin_inset LatexCommand \index{PIC16}
25139
25140 \end_inset
25141
25142  port defines the following preprocessor macros while translating a source.
25143 \end_layout
25144
25145 \begin_layout Standard
25146 \align center
25147 \begin_inset Tabular
25148 <lyxtabular version="3" rows="6" columns="2">
25149 <features>
25150 <column alignment="center" valignment="top" leftline="true" width="0">
25151 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25152 <row topline="true" bottomline="true">
25153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25154 \begin_inset Text
25155
25156 \begin_layout Standard
25157 Macro
25158 \end_layout
25159
25160 \end_inset
25161 </cell>
25162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25163 \begin_inset Text
25164
25165 \begin_layout Standard
25166 Description
25167 \end_layout
25168
25169 \end_inset
25170 </cell>
25171 </row>
25172 <row topline="true">
25173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25174 \begin_inset Text
25175
25176 \begin_layout Standard
25177 SDCC_pic16
25178 \end_layout
25179
25180 \end_inset
25181 </cell>
25182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25183 \begin_inset Text
25184
25185 \begin_layout Standard
25186 Port identification
25187 \end_layout
25188
25189 \end_inset
25190 </cell>
25191 </row>
25192 <row topline="true">
25193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25194 \begin_inset Text
25195
25196 \begin_layout Standard
25197 _
25198 \begin_inset ERT
25199 status collapsed
25200
25201 \begin_layout Standard
25202
25203
25204 \backslash
25205 /
25206 \end_layout
25207
25208 \end_inset
25209
25210 _pic16
25211 \end_layout
25212
25213 \end_inset
25214 </cell>
25215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25216 \begin_inset Text
25217
25218 \begin_layout Standard
25219 Port identification (same as above)
25220 \end_layout
25221
25222 \end_inset
25223 </cell>
25224 </row>
25225 <row topline="true">
25226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25227 \begin_inset Text
25228
25229 \begin_layout Standard
25230 pic18fxxxx
25231 \end_layout
25232
25233 \end_inset
25234 </cell>
25235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25236 \begin_inset Text
25237
25238 \begin_layout Standard
25239 MCU Identification.
25240  
25241 \emph on
25242 xxxx
25243 \emph default
25244  is the microcontrol identification number, i.e.
25245  452, 6620, etc
25246 \end_layout
25247
25248 \end_inset
25249 </cell>
25250 </row>
25251 <row topline="true">
25252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25253 \begin_inset Text
25254
25255 \begin_layout Standard
25256 _
25257 \begin_inset ERT
25258 status collapsed
25259
25260 \begin_layout Standard
25261
25262
25263 \backslash
25264 /
25265 \end_layout
25266
25267 \end_inset
25268
25269 _18Fxxxx
25270 \end_layout
25271
25272 \end_inset
25273 </cell>
25274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25275 \begin_inset Text
25276
25277 \begin_layout Standard
25278 MCU Identification (same as above)
25279 \end_layout
25280
25281 \end_inset
25282 </cell>
25283 </row>
25284 <row topline="true" bottomline="true">
25285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25286 \begin_inset Text
25287
25288 \begin_layout Standard
25289 STACK_MODEL_nnn
25290 \end_layout
25291
25292 \end_inset
25293 </cell>
25294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25295 \begin_inset Text
25296
25297 \begin_layout Standard
25298 nnn = SMALL or LARGE respectively according to the stack model used
25299 \end_layout
25300
25301 \end_inset
25302 </cell>
25303 </row>
25304 </lyxtabular>
25305
25306 \end_inset
25307
25308
25309 \end_layout
25310
25311 \begin_layout Standard
25312 In addition the following macros are defined when calling assembler:
25313 \end_layout
25314
25315 \begin_layout Standard
25316 \align center
25317 \begin_inset Tabular
25318 <lyxtabular version="3" rows="4" columns="2">
25319 <features>
25320 <column alignment="center" valignment="top" leftline="true" width="0">
25321 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25322 <row topline="true" bottomline="true">
25323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25324 \begin_inset Text
25325
25326 \begin_layout Standard
25327 Macro
25328 \end_layout
25329
25330 \end_inset
25331 </cell>
25332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25333 \begin_inset Text
25334
25335 \begin_layout Standard
25336 Description
25337 \end_layout
25338
25339 \end_inset
25340 </cell>
25341 </row>
25342 <row topline="true">
25343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25344 \begin_inset Text
25345
25346 \begin_layout Standard
25347 __18Fxxxx
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 MCU Identification.
25357  
25358 \emph on
25359 xxxx
25360 \emph default
25361  is the microcontrol identification number, i.e.
25362  452, 6620, etc
25363 \end_layout
25364
25365 \end_inset
25366 </cell>
25367 </row>
25368 <row topline="true">
25369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25370 \begin_inset Text
25371
25372 \begin_layout Standard
25373 SDCC_MODEL_nnn
25374 \end_layout
25375
25376 \end_inset
25377 </cell>
25378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25379 \begin_inset Text
25380
25381 \begin_layout Standard
25382 nnn = SMALL or LARGE respectively according to the memory model used for
25383  SDCC
25384 \end_layout
25385
25386 \end_inset
25387 </cell>
25388 </row>
25389 <row topline="true" bottomline="true">
25390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25391 \begin_inset Text
25392
25393 \begin_layout Standard
25394 STACK_MODEL_nnn
25395 \end_layout
25396
25397 \end_inset
25398 </cell>
25399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25400 \begin_inset Text
25401
25402 \begin_layout Standard
25403 nnn = SMALL or LARGE respectively according to the stack model used
25404 \end_layout
25405
25406 \end_inset
25407 </cell>
25408 </row>
25409 </lyxtabular>
25410
25411 \end_inset
25412
25413
25414 \end_layout
25415
25416 \begin_layout Subsection
25417 Directories
25418 \end_layout
25419
25420 \begin_layout Standard
25421 PIC16
25422 \begin_inset LatexCommand \index{PIC16}
25423
25424 \end_inset
25425
25426  port uses the following directories for searching header files and libraries.
25427 \end_layout
25428
25429 \begin_layout Standard
25430 \align center
25431 \begin_inset Tabular
25432 <lyxtabular version="3" rows="3" columns="4">
25433 <features>
25434 <column alignment="center" valignment="top" leftline="true" width="0">
25435 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25436 <column alignment="center" valignment="top" width="0">
25437 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25438 <row topline="true" bottomline="true">
25439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25440 \begin_inset Text
25441
25442 \begin_layout Standard
25443 Directory
25444 \end_layout
25445
25446 \end_inset
25447 </cell>
25448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25449 \begin_inset Text
25450
25451 \begin_layout Standard
25452 Description
25453 \end_layout
25454
25455 \end_inset
25456 </cell>
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25458 \begin_inset Text
25459
25460 \begin_layout Standard
25461 Target
25462 \end_layout
25463
25464 \end_inset
25465 </cell>
25466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25467 \begin_inset Text
25468
25469 \begin_layout Standard
25470 Command prefix
25471 \end_layout
25472
25473 \end_inset
25474 </cell>
25475 </row>
25476 <row topline="true">
25477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25478 \begin_inset Text
25479
25480 \begin_layout Standard
25481 PREFIX/sdcc/include/pic16
25482 \end_layout
25483
25484 \end_inset
25485 </cell>
25486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25487 \begin_inset Text
25488
25489 \begin_layout Standard
25490 PIC16 specific headers
25491 \end_layout
25492
25493 \end_inset
25494 </cell>
25495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25496 \begin_inset Text
25497
25498 \begin_layout Standard
25499 Compiler
25500 \end_layout
25501
25502 \end_inset
25503 </cell>
25504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25505 \begin_inset Text
25506
25507 \begin_layout Standard
25508 -I
25509 \end_layout
25510
25511 \end_inset
25512 </cell>
25513 </row>
25514 <row topline="true" bottomline="true">
25515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25516 \begin_inset Text
25517
25518 \begin_layout Standard
25519 PREFIX/sdcc/lib/pic16
25520 \end_layout
25521
25522 \end_inset
25523 </cell>
25524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25525 \begin_inset Text
25526
25527 \begin_layout Standard
25528 PIC16 specific libraries
25529 \end_layout
25530
25531 \end_inset
25532 </cell>
25533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25534 \begin_inset Text
25535
25536 \begin_layout Standard
25537 Linker
25538 \end_layout
25539
25540 \end_inset
25541 </cell>
25542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25543 \begin_inset Text
25544
25545 \begin_layout Standard
25546 -L
25547 \end_layout
25548
25549 \end_inset
25550 </cell>
25551 </row>
25552 </lyxtabular>
25553
25554 \end_inset
25555
25556
25557 \end_layout
25558
25559 \begin_layout Subsection
25560 Pragmas
25561 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25562
25563 \end_inset
25564
25565
25566 \end_layout
25567
25568 \begin_layout Standard
25569 The PIC16
25570 \begin_inset LatexCommand \index{PIC16}
25571
25572 \end_inset
25573
25574  port currently supports the following pragmas:
25575 \end_layout
25576
25577 \begin_layout Description
25578 stack
25579 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25580
25581 \end_inset
25582
25583  This forces the code generator to initialize the stack & frame pointers
25584  at a specific address.
25585  This is an ad hoc solution for cases where no STACK directive is available
25586  in the linker script or gplink is not instructed to create a stack section.
25587 \newline
25588 The
25589  stack pragma should be used only once in a project.
25590  Multiple pragmas may result in indeterminate behaviour of the program.
25591 \begin_inset Foot
25592 status open
25593
25594 \begin_layout Standard
25595 The old format (ie.
25596  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25597  cross page boundaries (or even exceed the available data RAM) and crash
25598  the program.
25599  Make sure that stack does not cross page boundaries when using the SMALL
25600  stack model.
25601 \end_layout
25602
25603 \end_inset
25604
25605
25606 \newline
25607 The format is as follows:
25608 \newline
25609
25610 \end_layout
25611
25612 \begin_layout LyX-Code
25613 #pragma stack bottom_address [stack_size]
25614 \newline
25615
25616 \end_layout
25617
25618 \begin_layout Standard
25619
25620 \emph on
25621 bottom_address
25622 \emph default
25623  is the lower bound of the stack section.
25624  The stack pointer initially will point at address (bottom_address+stack_size-1).
25625 \end_layout
25626
25627 \begin_layout LyX-Code
25628 Example:
25629 \end_layout
25630
25631 \begin_layout LyX-Code
25632
25633 \end_layout
25634
25635 \begin_layout LyX-Code
25636 /* initializes stack of 100 bytes at RAM address 0x200 */
25637 \end_layout
25638
25639 \begin_layout LyX-Code
25640 #pragma stack 0x200 100
25641 \end_layout
25642
25643 \begin_layout Standard
25644 If the stack_size field is omitted then a stack is created with the default
25645  size of 64.
25646  This size might be enough for most programs, but its not enough for operations
25647  with deep function nesting or excessive stack usage.
25648 \end_layout
25649
25650 \begin_layout Description
25651 code
25652 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25653
25654 \end_inset
25655
25656  Force a function to a static FLASH address.
25657 \end_layout
25658
25659 \begin_layout LyX-Code
25660 Example:
25661 \end_layout
25662
25663 \begin_layout LyX-Code
25664
25665 \end_layout
25666
25667 \begin_layout LyX-Code
25668 /* place function test_func at 0x4000 */
25669 \end_layout
25670
25671 \begin_layout LyX-Code
25672 #pragma code test_func 0x4000
25673 \end_layout
25674
25675 \begin_layout LyX-Code
25676
25677 \end_layout
25678
25679 \begin_layout Description
25680 library instructs the linker to use a library module.
25681 \newline
25682 Usage:
25683 \end_layout
25684
25685 \begin_layout LyX-Code
25686 #pragma library module_name
25687 \end_layout
25688
25689 \begin_layout Standard
25690
25691 \emph on
25692 module_name
25693 \emph default
25694  can be any library or object file (including its path).
25695  Note that there are four reserved keywords which have special meaning.
25696  These are:
25697 \end_layout
25698
25699 \begin_layout Standard
25700 \align center
25701 \begin_inset Tabular
25702 <lyxtabular version="3" rows="6" columns="3">
25703 <features>
25704 <column alignment="center" valignment="top" leftline="true" width="0">
25705 <column alignment="block" valignment="top" leftline="true" width="20page%">
25706 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25707 <row topline="true" bottomline="true">
25708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25709 \begin_inset Text
25710
25711 \begin_layout Standard
25712 Keyword
25713 \end_layout
25714
25715 \end_inset
25716 </cell>
25717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25718 \begin_inset Text
25719
25720 \begin_layout Standard
25721 Description
25722 \end_layout
25723
25724 \end_inset
25725 </cell>
25726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25727 \begin_inset Text
25728
25729 \begin_layout Standard
25730 Module to link
25731 \end_layout
25732
25733 \end_inset
25734 </cell>
25735 </row>
25736 <row topline="true">
25737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25738 \begin_inset Text
25739
25740 \begin_layout Standard
25741
25742 \series bold
25743 ignore
25744 \end_layout
25745
25746 \end_inset
25747 </cell>
25748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25749 \begin_inset Text
25750
25751 \begin_layout Standard
25752 ignore all library pragmas
25753 \end_layout
25754
25755 \end_inset
25756 </cell>
25757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25758 \begin_inset Text
25759
25760 \begin_layout Standard
25761
25762 \emph on
25763 (none)
25764 \end_layout
25765
25766 \end_inset
25767 </cell>
25768 </row>
25769 <row topline="true">
25770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25771 \begin_inset Text
25772
25773 \begin_layout Standard
25774
25775 \series bold
25776 c
25777 \end_layout
25778
25779 \end_inset
25780 </cell>
25781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25782 \begin_inset Text
25783
25784 \begin_layout Standard
25785 link the C library
25786 \end_layout
25787
25788 \end_inset
25789 </cell>
25790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25791 \begin_inset Text
25792
25793 \begin_layout Standard
25794
25795 \emph on
25796 libc18f
25797 \emph default
25798 .lib
25799 \end_layout
25800
25801 \end_inset
25802 </cell>
25803 </row>
25804 <row topline="true">
25805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25806 \begin_inset Text
25807
25808 \begin_layout Standard
25809
25810 \series bold
25811 math
25812 \end_layout
25813
25814 \end_inset
25815 </cell>
25816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25817 \begin_inset Text
25818
25819 \begin_layout Standard
25820 link the Math libarary
25821 \end_layout
25822
25823 \end_inset
25824 </cell>
25825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25826 \begin_inset Text
25827
25828 \begin_layout Standard
25829
25830 \emph on
25831 libm18f
25832 \emph default
25833 .lib
25834 \end_layout
25835
25836 \end_inset
25837 </cell>
25838 </row>
25839 <row topline="true">
25840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25841 \begin_inset Text
25842
25843 \begin_layout Standard
25844
25845 \series bold
25846 io
25847 \end_layout
25848
25849 \end_inset
25850 </cell>
25851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25852 \begin_inset Text
25853
25854 \begin_layout Standard
25855 link the I/O library
25856 \end_layout
25857
25858 \end_inset
25859 </cell>
25860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25861 \begin_inset Text
25862
25863 \begin_layout Standard
25864
25865 \emph on
25866 libio18f*
25867 \emph default
25868 .lib
25869 \end_layout
25870
25871 \end_inset
25872 </cell>
25873 </row>
25874 <row topline="true" bottomline="true">
25875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25876 \begin_inset Text
25877
25878 \begin_layout Standard
25879
25880 \series bold
25881 debug
25882 \end_layout
25883
25884 \end_inset
25885 </cell>
25886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25887 \begin_inset Text
25888
25889 \begin_layout Standard
25890 link the debug library
25891 \end_layout
25892
25893 \end_inset
25894 </cell>
25895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25896 \begin_inset Text
25897
25898 \begin_layout Standard
25899
25900 \emph on
25901 libdebug
25902 \emph default
25903 .lib
25904 \end_layout
25905
25906 \end_inset
25907 </cell>
25908 </row>
25909 </lyxtabular>
25910
25911 \end_inset
25912
25913
25914 \newline
25915 * is the device number, i.e.
25916  452 for PIC18F452 MCU.
25917 \end_layout
25918
25919 \begin_layout Standard
25920 This feature allows for linking with specific libraries withoug having to
25921  explicit name them in the command line.
25922  Note that the 
25923 \noun on
25924 ignore
25925 \noun default
25926  keyword will reject all modules specified by the library pragma.
25927 \end_layout
25928
25929 \begin_layout Description
25930 udata The pragma udata instructs the compiler to emit code so that linker
25931  will place a variable at a specific memory bank.
25932 \end_layout
25933
25934 \begin_layout LyX-Code
25935 Example:
25936 \end_layout
25937
25938 \begin_layout LyX-Code
25939
25940 \end_layout
25941
25942 \begin_layout LyX-Code
25943 /* places variable foo at bank2 */
25944 \end_layout
25945
25946 \begin_layout LyX-Code
25947 #pragma udata bank2 foo
25948 \end_layout
25949
25950 \begin_layout LyX-Code
25951 char foo;
25952 \end_layout
25953
25954 \begin_layout Standard
25955 In order for this pragma to work extra SECTION directives should be added
25956  in the .lkr script.
25957  In the following example a sample .lkr file is shown:
25958 \end_layout
25959
25960 \begin_layout LyX-Code
25961
25962 \end_layout
25963
25964 \begin_layout LyX-Code
25965 // Sample linker script for the PIC18F452 processor
25966 \end_layout
25967
25968 \begin_layout LyX-Code
25969 LIBPATH .
25970 \end_layout
25971
25972 \begin_layout LyX-Code
25973 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25974 \end_layout
25975
25976 \begin_layout LyX-Code
25977 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25978 \end_layout
25979
25980 \begin_layout LyX-Code
25981 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25982 \end_layout
25983
25984 \begin_layout LyX-Code
25985 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25986 \end_layout
25987
25988 \begin_layout LyX-Code
25989 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25990 \end_layout
25991
25992 \begin_layout LyX-Code
25993 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25994 \end_layout
25995
25996 \begin_layout LyX-Code
25997 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25998 \end_layout
25999
26000 \begin_layout LyX-Code
26001
26002 \end_layout
26003
26004 \begin_layout LyX-Code
26005 DATABANK   NAME=gpr0       START=0x80           END=0xFF
26006 \end_layout
26007
26008 \begin_layout LyX-Code
26009 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
26010 \end_layout
26011
26012 \begin_layout LyX-Code
26013 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
26014 \end_layout
26015
26016 \begin_layout LyX-Code
26017 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
26018 \end_layout
26019
26020 \begin_layout LyX-Code
26021 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
26022 \end_layout
26023
26024 \begin_layout LyX-Code
26025 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
26026 \end_layout
26027
26028 \begin_layout LyX-Code
26029 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
26030 \end_layout
26031
26032 \begin_layout LyX-Code
26033
26034 \end_layout
26035
26036 \begin_layout LyX-Code
26037 SECTION    NAME=CONFIG     ROM=config
26038 \end_layout
26039
26040 \begin_layout LyX-Code
26041
26042 \end_layout
26043
26044 \begin_layout LyX-Code
26045 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
26046 \end_layout
26047
26048 \begin_layout LyX-Code
26049 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
26050 \end_layout
26051
26052 \begin_layout LyX-Code
26053 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
26054 \end_layout
26055
26056 \begin_layout LyX-Code
26057 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
26058 \end_layout
26059
26060 \begin_layout LyX-Code
26061 SECTION    NAME=bank4      RAM=gpr4
26062 \end_layout
26063
26064 \begin_layout LyX-Code
26065 SECTION    NAME=bank5      RAM=gpr5
26066 \end_layout
26067
26068 \begin_layout Standard
26069 The linker will recognise the section name set in the pragma statement and
26070  will position the variable at the memory bank set with the RAM field at
26071  the SECTION line in the linker script file.
26072 \end_layout
26073
26074 \begin_layout Subsection
26075 Header Files
26076 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26077
26078 \end_inset
26079
26080
26081 \end_layout
26082
26083 \begin_layout Standard
26084 There is one main header file
26085 \begin_inset LatexCommand \index{PIC16!Header files}
26086
26087 \end_inset
26088
26089  that can be included to the source files using the pic16
26090 \begin_inset LatexCommand \index{PIC16}
26091
26092 \end_inset
26093
26094  port.
26095  That file is the 
26096 \series bold
26097 pic18fregs.h
26098 \series default
26099 .
26100  This header file contains the definitions for the processor special registers,
26101  so it is necessary if the source accesses them.
26102  It can be included by adding the following line in the beginning of the
26103  file:
26104 \end_layout
26105
26106 \begin_layout LyX-Code
26107 #include <pic18fregs.h>
26108 \end_layout
26109
26110 \begin_layout Standard
26111 The specific microcontroller is selected within the pic18fregs.h automatically,
26112  so the same source can be used with a variety of devices.
26113 \end_layout
26114
26115 \begin_layout Subsection
26116 Libraries
26117 \end_layout
26118
26119 \begin_layout Standard
26120 The libraries
26121 \begin_inset LatexCommand \index{PIC16!Libraries}
26122
26123 \end_inset
26124
26125  that PIC16
26126 \begin_inset LatexCommand \index{PIC16}
26127
26128 \end_inset
26129
26130  port depends on are the microcontroller device libraries which contain
26131  the symbol definitions for the microcontroller special function registers.
26132  These libraries have the format pic18fxxxx.lib, where 
26133 \emph on
26134 xxxx
26135 \emph default
26136  is the microcontroller identification number.
26137  The specific library is selected automatically by the compiler at link
26138  stage according to the selected device.
26139 \end_layout
26140
26141 \begin_layout Standard
26142 Libraries are created with gplib which is part of the gputils package 
26143 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26144
26145 \end_inset
26146
26147 .
26148 \end_layout
26149
26150 \begin_layout Subsubsection*
26151 Building the libraries
26152 \end_layout
26153
26154 \begin_layout Standard
26155 Before using SDCC/pic16 there are some libraries that need to be compiled.
26156  This process is not done automatically by SDCC since not all users use
26157  SDCC for pic16 projects.
26158  So each user should compile the libraries separately.
26159 \end_layout
26160
26161 \begin_layout Standard
26162 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26163 \end_layout
26164
26165 \begin_layout LyX-Code
26166 cd device/lib/pic16
26167 \end_layout
26168
26169 \begin_layout LyX-Code
26170 ./configure
26171 \end_layout
26172
26173 \begin_layout LyX-Code
26174 make
26175 \end_layout
26176
26177 \begin_layout LyX-Code
26178 cd ..
26179 \end_layout
26180
26181 \begin_layout LyX-Code
26182 make model-pic16
26183 \end_layout
26184
26185 \begin_layout LyX-Code
26186 su -c 'make install'     # install the libraries, you need the root password
26187 \end_layout
26188
26189 \begin_layout Standard
26190 If you need to install the headers too, do:
26191 \end_layout
26192
26193 \begin_layout LyX-Code
26194 cd device/include
26195 \end_layout
26196
26197 \begin_layout LyX-Code
26198 su -c 'make install'     # install the headers, you need the root password
26199 \end_layout
26200
26201 \begin_layout Standard
26202 There exist a special target to build the I/O libraries.
26203  This target is not automatically build because it will build the I/O library
26204  for 
26205 \emph on
26206 every
26207 \emph default
26208  supported device.
26209  This way building will take quite a lot of time.
26210  Users are advised to edit the 
26211 \series bold
26212 device/lib/pic16/pics.build
26213 \series default
26214  file and then execute:
26215 \end_layout
26216
26217 \begin_layout LyX-Code
26218 make lib-io
26219 \end_layout
26220
26221 \begin_layout Subsection
26222 Adding New Devices to the Port
26223 \end_layout
26224
26225 \begin_layout Standard
26226 Adding support for a new 16
26227 \begin_inset ERT
26228 status open
26229
26230 \begin_layout Standard
26231
26232
26233 \backslash
26234 ,
26235 \end_layout
26236
26237 \end_inset
26238
26239 bit PIC MCU requires the following steps:
26240 \end_layout
26241
26242 \begin_layout Enumerate
26243 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26244 \newline
26245
26246 \family typewriter
26247 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26248 inc
26249 \end_layout
26250
26251 \begin_layout Enumerate
26252
26253 \family typewriter
26254 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26255 \end_layout
26256
26257 \begin_layout Enumerate
26258
26259 \family typewriter
26260 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26261 \end_layout
26262
26263 \begin_layout Enumerate
26264 Add DEVICE to 
26265 \family typewriter
26266 /path/to/sdcc/device/lib/pic16/pics.all
26267 \family default
26268  (and 
26269 \family typewriter
26270 .build
26271 \family default
26272 ).
26273 \newline
26274 Note: No 18f prefix here!
26275 \end_layout
26276
26277 \begin_layout Enumerate
26278 Set up the I/O library by doing 
26279 \series bold
26280 one
26281 \series default
26282  of the following:
26283 \end_layout
26284
26285 \begin_deeper
26286 \begin_layout Enumerate
26287 Adjust 
26288 \family typewriter
26289 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26290 \family default
26291
26292 \newline
26293 Add your DEVICE if it does not compile in 
26294 \family typewriter
26295 adc
26296 \family default
26297
26298 \family typewriter
26299 i2c
26300 \family default
26301 , or 
26302 \family typewriter
26303 usart
26304 \family default
26305 .
26306 \end_layout
26307
26308 \begin_layout Enumerate
26309 Adjust 
26310 \family typewriter
26311 /path/to/sdcc/device/include/pic16/adc.h
26312 \newline
26313
26314 \family default
26315 Add the new devices to the correct ADC style class.
26316 \end_layout
26317
26318 \end_deeper
26319 \begin_layout Enumerate
26320 Edit 
26321 \family typewriter
26322 /path/to/sdcc/device/include/pic16/pic18fregs.h
26323 \family default
26324 .
26325  The file format is self-explanatory, just add
26326 \newline
26327
26328 \family typewriter
26329 #elif defined(picDEVICE)
26330 \newline
26331 # include <picDEVICE.h>
26332 \family default
26333
26334 \newline
26335 at the right place (keep it sorted).
26336 \end_layout
26337
26338 \begin_layout Enumerate
26339 Edit 
26340 \family typewriter
26341 /path/to/sdcc/device/include/pic16devices.txt
26342 \newline
26343
26344 \family default
26345 Copy and modify an existing entry or create a new one and insert it at the
26346  correct place (keep the file sorted).
26347 \end_layout
26348
26349 \begin_layout Enumerate
26350 Recompile the pic16 libraries.
26351 \end_layout
26352
26353 \begin_layout Subsection
26354 Memory Models
26355 \end_layout
26356
26357 \begin_layout Standard
26358 The following memory models are supported by the PIC16 port:
26359 \end_layout
26360
26361 \begin_layout Itemize
26362 small model
26363 \end_layout
26364
26365 \begin_layout Itemize
26366 large model
26367 \end_layout
26368
26369 \begin_layout Standard
26370 Memory model affects the default size of pointers within the source.
26371  The sizes are shown in the next table:
26372 \end_layout
26373
26374 \begin_layout Standard
26375 \align center
26376 \begin_inset Tabular
26377 <lyxtabular version="3" rows="3" columns="3">
26378 <features>
26379 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26380 <column alignment="center" valignment="top" leftline="true" width="0">
26381 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26382 <row topline="true" bottomline="true">
26383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26384 \begin_inset Text
26385
26386 \begin_layout Standard
26387 Pointer sizes according to memory model
26388 \end_layout
26389
26390 \end_inset
26391 </cell>
26392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26393 \begin_inset Text
26394
26395 \begin_layout Standard
26396 small model
26397 \end_layout
26398
26399 \end_inset
26400 </cell>
26401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26402 \begin_inset Text
26403
26404 \begin_layout Standard
26405 large model
26406 \end_layout
26407
26408 \end_inset
26409 </cell>
26410 </row>
26411 <row topline="true" bottomline="true">
26412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26413 \begin_inset Text
26414
26415 \begin_layout Standard
26416 code pointers
26417 \end_layout
26418
26419 \end_inset
26420 </cell>
26421 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26422 \begin_inset Text
26423
26424 \begin_layout Standard
26425 16-bits
26426 \end_layout
26427
26428 \end_inset
26429 </cell>
26430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26431 \begin_inset Text
26432
26433 \begin_layout Standard
26434 24-bits
26435 \end_layout
26436
26437 \end_inset
26438 </cell>
26439 </row>
26440 <row topline="true" bottomline="true">
26441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26442 \begin_inset Text
26443
26444 \begin_layout Standard
26445 data pointers
26446 \end_layout
26447
26448 \end_inset
26449 </cell>
26450 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26451 \begin_inset Text
26452
26453 \begin_layout Standard
26454 16-bits
26455 \end_layout
26456
26457 \end_inset
26458 </cell>
26459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26460 \begin_inset Text
26461
26462 \begin_layout Standard
26463 16-bits
26464 \end_layout
26465
26466 \end_inset
26467 </cell>
26468 </row>
26469 </lyxtabular>
26470
26471 \end_inset
26472
26473
26474 \end_layout
26475
26476 \begin_layout Standard
26477 It is advisable that all sources within a project are compiled with the
26478  same memory model.
26479  If one wants to override the default memory model, this can be done by
26480  declaring a pointer as 
26481 \series bold
26482 far
26483 \series default
26484  or 
26485 \series bold
26486 near
26487 \series default
26488 .
26489  Far selects large memory model's pointers, while near selects small memory
26490  model's pointers.
26491 \end_layout
26492
26493 \begin_layout Standard
26494 The standard device libraries (see 
26495 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26496
26497 \end_inset
26498
26499 ) contain no reference to pointers, so they can be used with both memory
26500  models.
26501 \end_layout
26502
26503 \begin_layout Subsection
26504 Stack
26505 \end_layout
26506
26507 \begin_layout Standard
26508 The stack
26509 \begin_inset LatexCommand \index{PIC16!stack}
26510
26511 \end_inset
26512
26513  implementation for the PIC16 port uses two indirect registers, FSR1 and
26514  FSR2.
26515 \end_layout
26516
26517 \begin_layout Description
26518 FSR1 is assigned as stack pointer
26519 \end_layout
26520
26521 \begin_layout Description
26522 FSR2 is assigned as frame pointer
26523 \end_layout
26524
26525 \begin_layout Standard
26526 The following stack models are supported by the PIC16 port
26527 \end_layout
26528
26529 \begin_layout Itemize
26530
26531 \noun on
26532 small
26533 \noun default
26534  model
26535 \end_layout
26536
26537 \begin_layout Itemize
26538
26539 \noun on
26540 large
26541 \noun default
26542  model
26543 \end_layout
26544
26545 \begin_layout Standard
26546
26547 \noun on
26548 Small
26549 \noun default
26550  model means that only the FSRxL byte is used to access stack and frame,
26551  while 
26552 \emph on
26553 \noun on
26554 large
26555 \emph default
26556 \noun default
26557  uses both FSRxL and FSRxH registers.
26558  The following table shows the stack/frame pointers sizes according to stack
26559  model and the maximum space they can address:
26560 \end_layout
26561
26562 \begin_layout Standard
26563 \align center
26564 \begin_inset Tabular
26565 <lyxtabular version="3" rows="3" columns="3">
26566 <features>
26567 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26568 <column alignment="center" valignment="top" leftline="true" width="0">
26569 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26570 <row topline="true" bottomline="true">
26571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26572 \begin_inset Text
26573
26574 \begin_layout Standard
26575 Stack & Frame pointer sizes according to stack model
26576 \end_layout
26577
26578 \end_inset
26579 </cell>
26580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26581 \begin_inset Text
26582
26583 \begin_layout Standard
26584 small
26585 \end_layout
26586
26587 \end_inset
26588 </cell>
26589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26590 \begin_inset Text
26591
26592 \begin_layout Standard
26593 large
26594 \end_layout
26595
26596 \end_inset
26597 </cell>
26598 </row>
26599 <row topline="true">
26600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26601 \begin_inset Text
26602
26603 \begin_layout Standard
26604 Stack pointer FSR1
26605 \end_layout
26606
26607 \end_inset
26608 </cell>
26609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26610 \begin_inset Text
26611
26612 \begin_layout Standard
26613 8-bits
26614 \end_layout
26615
26616 \end_inset
26617 </cell>
26618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26619 \begin_inset Text
26620
26621 \begin_layout Standard
26622 16-bits
26623 \end_layout
26624
26625 \end_inset
26626 </cell>
26627 </row>
26628 <row topline="true" bottomline="true">
26629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26630 \begin_inset Text
26631
26632 \begin_layout Standard
26633 Frame pointer FSR2
26634 \end_layout
26635
26636 \end_inset
26637 </cell>
26638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26639 \begin_inset Text
26640
26641 \begin_layout Standard
26642 8-bits
26643 \end_layout
26644
26645 \end_inset
26646 </cell>
26647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26648 \begin_inset Text
26649
26650 \begin_layout Standard
26651 16-bits
26652 \end_layout
26653
26654 \end_inset
26655 </cell>
26656 </row>
26657 </lyxtabular>
26658
26659 \end_inset
26660
26661
26662 \end_layout
26663
26664 \begin_layout Standard
26665
26666 \noun on
26667 Large 
26668 \noun default
26669 stack model is currently not working properly throughout the code generator.
26670  So its use is not advised.
26671  Also there are some other points that need special care:
26672 \newline
26673
26674 \end_layout
26675
26676 \begin_layout Enumerate
26677 Do not create stack sections with size more than one physical bank (that
26678  is 256 bytes)
26679 \end_layout
26680
26681 \begin_layout Enumerate
26682 Stack sections should no cross physical bank limits (i.e.
26683  #pragma stack 0x50 0x100)
26684 \end_layout
26685
26686 \begin_layout Standard
26687 These limitations are caused by the fact that only FSRxL is modified when
26688  using SMALL stack model, so no more than 256 bytes of stack can be used.
26689  This problem will disappear after LARGE model is fully implemented.
26690 \end_layout
26691
26692 \begin_layout Subsection
26693 Functions
26694 \end_layout
26695
26696 \begin_layout Standard
26697 In addition to the standard SDCC function keywords, PIC16
26698 \begin_inset LatexCommand \index{PIC16}
26699
26700 \end_inset
26701
26702  port makes available two more:
26703 \end_layout
26704
26705 \begin_layout Description
26706 wparam
26707 \begin_inset LatexCommand \index{PIC16!wparam}
26708
26709 \end_inset
26710
26711  Use the WREG to pass one byte of the first function argument.
26712  This improves speed but you may not use this for functions with arguments
26713  that are called via function pointers, otherwise the first byte of the
26714  first parameter will get lost.
26715  Usage:
26716 \end_layout
26717
26718 \begin_layout LyX-Code
26719 void func_wparam(int a) wparam
26720 \end_layout
26721
26722 \begin_layout LyX-Code
26723 {
26724 \end_layout
26725
26726 \begin_layout LyX-Code
26727     /* WREG hold the lower part of a */
26728 \end_layout
26729
26730 \begin_layout LyX-Code
26731     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26732  */
26733 \end_layout
26734
26735 \begin_layout LyX-Code
26736 ...
26737 \end_layout
26738
26739 \begin_layout LyX-Code
26740 }
26741 \end_layout
26742
26743 \begin_layout Description
26744 shadowregs
26745 \begin_inset LatexCommand \index{PIC16!shadowregs}
26746
26747 \end_inset
26748
26749  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26750  hardware shadow registers which hold the values of WREG, STATUS and BSR
26751  registers.
26752  This can be done by adding the keyword 
26753 \emph on
26754 shadowregs
26755 \emph default
26756  before the 
26757 \emph on
26758 interrupt
26759 \emph default
26760  keyword in the function's header.
26761 \end_layout
26762
26763 \begin_layout LyX-Code
26764 void isr_shadow(void) shadowregs interrupt 1
26765 \end_layout
26766
26767 \begin_layout LyX-Code
26768 {
26769 \end_layout
26770
26771 \begin_layout LyX-Code
26772 ...
26773 \end_layout
26774
26775 \begin_layout LyX-Code
26776 }
26777 \end_layout
26778
26779 \begin_layout Standard
26780
26781 \emph on
26782 shadowregs
26783 \emph default
26784  instructs the code generator not to store/restore WREG, STATUS, BSR when
26785  entering/exiting the ISR.
26786 \end_layout
26787
26788 \begin_layout Subsection
26789 Function return values
26790 \end_layout
26791
26792 \begin_layout Standard
26793 Return values from functions are placed to the appropriate registers following
26794  a modified Microchip policy optimized for SDCC.
26795  The following table shows these registers:
26796 \end_layout
26797
26798 \begin_layout Standard
26799 \align center
26800 \begin_inset Tabular
26801 <lyxtabular version="3" rows="6" columns="2">
26802 <features>
26803 <column alignment="center" valignment="top" leftline="true" width="0">
26804 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26805 <row topline="true" bottomline="true">
26806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26807 \begin_inset Text
26808
26809 \begin_layout Standard
26810 size
26811 \end_layout
26812
26813 \end_inset
26814 </cell>
26815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26816 \begin_inset Text
26817
26818 \begin_layout Standard
26819 destination register
26820 \end_layout
26821
26822 \end_inset
26823 </cell>
26824 </row>
26825 <row topline="true">
26826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26827 \begin_inset Text
26828
26829 \begin_layout Standard
26830 8 bits
26831 \end_layout
26832
26833 \end_inset
26834 </cell>
26835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26836 \begin_inset Text
26837
26838 \begin_layout Standard
26839 WREG
26840 \end_layout
26841
26842 \end_inset
26843 </cell>
26844 </row>
26845 <row topline="true">
26846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26847 \begin_inset Text
26848
26849 \begin_layout Standard
26850 16 bits
26851 \end_layout
26852
26853 \end_inset
26854 </cell>
26855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26856 \begin_inset Text
26857
26858 \begin_layout Standard
26859 PRODL:WREG
26860 \end_layout
26861
26862 \end_inset
26863 </cell>
26864 </row>
26865 <row topline="true">
26866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26867 \begin_inset Text
26868
26869 \begin_layout Standard
26870 24 bits
26871 \end_layout
26872
26873 \end_inset
26874 </cell>
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26876 \begin_inset Text
26877
26878 \begin_layout Standard
26879 PRODH:PRODL:WREG
26880 \end_layout
26881
26882 \end_inset
26883 </cell>
26884 </row>
26885 <row topline="true">
26886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26887 \begin_inset Text
26888
26889 \begin_layout Standard
26890 32 bits
26891 \end_layout
26892
26893 \end_inset
26894 </cell>
26895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26896 \begin_inset Text
26897
26898 \begin_layout Standard
26899 FSR0L:PRODH:PRODL:WREG
26900 \end_layout
26901
26902 \end_inset
26903 </cell>
26904 </row>
26905 <row topline="true" bottomline="true">
26906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26907 \begin_inset Text
26908
26909 \begin_layout Standard
26910 >32 bits
26911 \end_layout
26912
26913 \end_inset
26914 </cell>
26915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26916 \begin_inset Text
26917
26918 \begin_layout Standard
26919 on stack, FSR0 points to the beginning
26920 \end_layout
26921
26922 \end_inset
26923 </cell>
26924 </row>
26925 </lyxtabular>
26926
26927 \end_inset
26928
26929
26930 \end_layout
26931
26932 \begin_layout Subsection
26933 Interrupts
26934 \end_layout
26935
26936 \begin_layout Standard
26937 An interrupt
26938 \begin_inset LatexCommand \index{PIC16!interrupt}
26939
26940 \end_inset
26941
26942  service routine (ISR) is declared using the 
26943 \emph on
26944 interrupt
26945 \emph default
26946  keyword.
26947 \end_layout
26948
26949 \begin_layout LyX-Code
26950 void isr(void) interrupt 
26951 \emph on
26952 n
26953 \end_layout
26954
26955 \begin_layout LyX-Code
26956 {
26957 \end_layout
26958
26959 \begin_layout LyX-Code
26960 ...
26961 \end_layout
26962
26963 \begin_layout LyX-Code
26964 }
26965 \end_layout
26966
26967 \begin_layout Standard
26968
26969 \emph on
26970 n
26971 \emph default
26972  is the interrupt number, which for PIC18F devices can be:
26973 \end_layout
26974
26975 \begin_layout Standard
26976 \align center
26977 \begin_inset Tabular
26978 <lyxtabular version="3" rows="4" columns="3">
26979 <features>
26980 <column alignment="center" valignment="top" leftline="true" width="0">
26981 <column alignment="center" valignment="top" leftline="true" width="0">
26982 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26983 <row topline="true" bottomline="true">
26984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26985 \begin_inset Text
26986
26987 \begin_layout Standard
26988
26989 \emph on
26990 n
26991 \end_layout
26992
26993 \end_inset
26994 </cell>
26995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26996 \begin_inset Text
26997
26998 \begin_layout Standard
26999 Interrupt Vector
27000 \end_layout
27001
27002 \end_inset
27003 </cell>
27004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27005 \begin_inset Text
27006
27007 \begin_layout Standard
27008 Interrupt Vector Address
27009 \end_layout
27010
27011 \end_inset
27012 </cell>
27013 </row>
27014 <row topline="true">
27015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27016 \begin_inset Text
27017
27018 \begin_layout Standard
27019 0
27020 \end_layout
27021
27022 \end_inset
27023 </cell>
27024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27025 \begin_inset Text
27026
27027 \begin_layout Standard
27028 RESET vector
27029 \end_layout
27030
27031 \end_inset
27032 </cell>
27033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27034 \begin_inset Text
27035
27036 \begin_layout Standard
27037 0x000000
27038 \end_layout
27039
27040 \end_inset
27041 </cell>
27042 </row>
27043 <row topline="true">
27044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27045 \begin_inset Text
27046
27047 \begin_layout Standard
27048
27049 \family roman
27050 \series medium
27051 \shape up
27052 \size normal
27053 \emph off
27054 \bar no
27055 \noun off
27056 \color none
27057 1
27058 \end_layout
27059
27060 \end_inset
27061 </cell>
27062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27063 \begin_inset Text
27064
27065 \begin_layout Standard
27066
27067 \family roman
27068 \series medium
27069 \shape up
27070 \size normal
27071 \emph off
27072 \bar no
27073 \noun off
27074 \color none
27075 HIGH priority interrupts
27076 \end_layout
27077
27078 \end_inset
27079 </cell>
27080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27081 \begin_inset Text
27082
27083 \begin_layout Standard
27084 0x000008
27085 \end_layout
27086
27087 \end_inset
27088 </cell>
27089 </row>
27090 <row topline="true" bottomline="true">
27091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27092 \begin_inset Text
27093
27094 \begin_layout Standard
27095 2
27096 \end_layout
27097
27098 \end_inset
27099 </cell>
27100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27101 \begin_inset Text
27102
27103 \begin_layout Standard
27104 LOW priority interrupts
27105 \end_layout
27106
27107 \end_inset
27108 </cell>
27109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27110 \begin_inset Text
27111
27112 \begin_layout Standard
27113 0x000018
27114 \end_layout
27115
27116 \end_inset
27117 </cell>
27118 </row>
27119 </lyxtabular>
27120
27121 \end_inset
27122
27123
27124 \end_layout
27125
27126 \begin_layout Standard
27127 When generating assembly code for ISR the code generator places a 
27128 \noun on
27129 goto 
27130 \noun default
27131 instruction at the 
27132 \emph on
27133 Interrupt Vector Address
27134 \emph default
27135  which points at the genetated ISR.
27136  This single GOTO instruction is part of an automatically generated 
27137 \emph on
27138 interrupt entry point
27139 \emph default
27140  function.
27141  The actuall ISR code is placed as normally would in the code space.
27142  Upon interrupt request, the GOTO instruction is executed which jumps to
27143  the ISR code.
27144  When declaring interrupt functions as _naked this GOTO instruction is 
27145 \series bold
27146 not
27147 \series default
27148  generated.
27149  The whole interrupt functions is therefore placed at the Interrupt Vector
27150  Address of the specific interrupt.
27151  This is not a problem for the LOW priority interrupts, but it is a problem
27152  for the RESET and the HIGH priority interrupts because code may be written
27153  at the next interrupt's vector address and cause undeterminate program
27154  behaviour if that interrupt is raised.
27155 \begin_inset Foot
27156 status open
27157
27158 \begin_layout Standard
27159 This is not a problem when
27160 \end_layout
27161
27162 \begin_layout Enumerate
27163 this is a HIGH interrupt ISR and LOW interrupts are 
27164 \emph on
27165 disabled
27166 \emph default
27167  or not used.
27168 \end_layout
27169
27170 \begin_layout Enumerate
27171 when the ISR is small enough not to reach the next interrupt's vector address.
27172 \end_layout
27173
27174 \end_inset
27175
27176
27177 \end_layout
27178
27179 \begin_layout Standard
27180
27181 \emph on
27182 n
27183 \emph default
27184  may be omitted.
27185  This way a function is generated similar to an ISR, but it is not assigned
27186  to any interrupt.
27187 \end_layout
27188
27189 \begin_layout Standard
27190 When entering an interrupt, currently the PIC16
27191 \begin_inset LatexCommand \index{PIC16}
27192
27193 \end_inset
27194
27195  port automatically saves the following registers:
27196 \end_layout
27197
27198 \begin_layout Itemize
27199 WREG
27200 \end_layout
27201
27202 \begin_layout Itemize
27203 STATUS
27204 \end_layout
27205
27206 \begin_layout Itemize
27207 BSR
27208 \end_layout
27209
27210 \begin_layout Itemize
27211 PROD (PRODL and PRODH)
27212 \end_layout
27213
27214 \begin_layout Itemize
27215 FSR0 (FSR0L and FSR0H)
27216 \end_layout
27217
27218 \begin_layout Standard
27219 These registers are restored upon return from the interrupt routine.
27220 \begin_inset Foot
27221 status open
27222
27223 \begin_layout Standard
27224 NOTE that when the _naked attribute is specified for an interrupt routine,
27225  then NO registers are stored or restored.
27226 \end_layout
27227
27228 \end_inset
27229
27230
27231 \end_layout
27232
27233 \begin_layout Subsection
27234 Generic Pointers
27235 \end_layout
27236
27237 \begin_layout Standard
27238 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27239  There are 3 types of generic pointers currently implemented data, code
27240  and eeprom pointers.
27241  They are differentiated by the value of the 7th and 6th bits of the upper
27242  byte:
27243 \end_layout
27244
27245 \begin_layout Standard
27246 \align center
27247 \begin_inset Tabular
27248 <lyxtabular version="3" rows="5" columns="5">
27249 <features>
27250 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27251 <column alignment="center" valignment="top" width="0">
27252 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27253 <column alignment="center" valignment="top" width="0">
27254 <column alignment="left" valignment="top" rightline="true" width="0">
27255 <row topline="true" bottomline="true">
27256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27257 \begin_inset Text
27258
27259 \begin_layout Standard
27260 pointer type
27261 \end_layout
27262
27263 \end_inset
27264 </cell>
27265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27266 \begin_inset Text
27267
27268 \begin_layout Standard
27269 7th bit
27270 \end_layout
27271
27272 \end_inset
27273 </cell>
27274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27275 \begin_inset Text
27276
27277 \begin_layout Standard
27278 6th bit
27279 \end_layout
27280
27281 \end_inset
27282 </cell>
27283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27284 \begin_inset Text
27285
27286 \begin_layout Standard
27287 rest of the pointer
27288 \end_layout
27289
27290 \end_inset
27291 </cell>
27292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27293 \begin_inset Text
27294
27295 \begin_layout Standard
27296 description
27297 \end_layout
27298
27299 \end_inset
27300 </cell>
27301 </row>
27302 <row topline="true" bottomline="true">
27303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27304 \begin_inset Text
27305
27306 \begin_layout Standard
27307 data 
27308 \end_layout
27309
27310 \end_inset
27311 </cell>
27312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27313 \begin_inset Text
27314
27315 \begin_layout Standard
27316 1
27317 \end_layout
27318
27319 \end_inset
27320 </cell>
27321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27322 \begin_inset Text
27323
27324 \begin_layout Standard
27325 0
27326 \end_layout
27327
27328 \end_inset
27329 </cell>
27330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27331 \begin_inset Text
27332
27333 \begin_layout Standard
27334
27335 \family typewriter
27336 \shape slanted
27337 \emph on
27338 uuuuuu uuuuxxxx xxxxxxxx
27339 \end_layout
27340
27341 \end_inset
27342 </cell>
27343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27344 \begin_inset Text
27345
27346 \begin_layout Standard
27347 a 12-bit data pointer in data RAM memory
27348 \end_layout
27349
27350 \end_inset
27351 </cell>
27352 </row>
27353 <row bottomline="true">
27354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27355 \begin_inset Text
27356
27357 \begin_layout Standard
27358 code
27359 \end_layout
27360
27361 \end_inset
27362 </cell>
27363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27364 \begin_inset Text
27365
27366 \begin_layout Standard
27367 0
27368 \end_layout
27369
27370 \end_inset
27371 </cell>
27372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27373 \begin_inset Text
27374
27375 \begin_layout Standard
27376 0
27377 \end_layout
27378
27379 \end_inset
27380 </cell>
27381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27382 \begin_inset Text
27383
27384 \begin_layout Standard
27385
27386 \family typewriter
27387 \shape slanted
27388 \emph on
27389 uxxxxx xxxxxxxx xxxxxxxx
27390 \end_layout
27391
27392 \end_inset
27393 </cell>
27394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27395 \begin_inset Text
27396
27397 \begin_layout Standard
27398 a 21-bit code pointer in FLASH memory
27399 \end_layout
27400
27401 \end_inset
27402 </cell>
27403 </row>
27404 <row bottomline="true">
27405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27406 \begin_inset Text
27407
27408 \begin_layout Standard
27409 eeprom
27410 \end_layout
27411
27412 \end_inset
27413 </cell>
27414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27415 \begin_inset Text
27416
27417 \begin_layout Standard
27418 0
27419 \end_layout
27420
27421 \end_inset
27422 </cell>
27423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27424 \begin_inset Text
27425
27426 \begin_layout Standard
27427 1
27428 \end_layout
27429
27430 \end_inset
27431 </cell>
27432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27433 \begin_inset Text
27434
27435 \begin_layout Standard
27436
27437 \family typewriter
27438 \shape slanted
27439 \emph on
27440 uuuuuu uuuuuuxx xxxxxxxx
27441 \end_layout
27442
27443 \end_inset
27444 </cell>
27445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27446 \begin_inset Text
27447
27448 \begin_layout Standard
27449 a 10-bit eeprom pointer in EEPROM memory
27450 \end_layout
27451
27452 \end_inset
27453 </cell>
27454 </row>
27455 <row bottomline="true">
27456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27457 \begin_inset Text
27458
27459 \begin_layout Standard
27460 (unimplemented)
27461 \end_layout
27462
27463 \end_inset
27464 </cell>
27465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27466 \begin_inset Text
27467
27468 \begin_layout Standard
27469 1
27470 \end_layout
27471
27472 \end_inset
27473 </cell>
27474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27475 \begin_inset Text
27476
27477 \begin_layout Standard
27478 1
27479 \end_layout
27480
27481 \end_inset
27482 </cell>
27483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27484 \begin_inset Text
27485
27486 \begin_layout Standard
27487
27488 \family typewriter
27489 \shape slanted
27490 \emph on
27491 xxxxxx xxxxxxxx xxxxxxxx
27492 \end_layout
27493
27494 \end_inset
27495 </cell>
27496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27497 \begin_inset Text
27498
27499 \begin_layout Standard
27500 unimplemented pointer type
27501 \end_layout
27502
27503 \end_inset
27504 </cell>
27505 </row>
27506 </lyxtabular>
27507
27508 \end_inset
27509
27510
27511 \end_layout
27512
27513 \begin_layout Standard
27514 Generic pointer are read and written with a set of library functions which
27515  read/write 1, 2, 3, 4 bytes.
27516 \end_layout
27517
27518 \begin_layout Subsection
27519 PIC16 C Libraries
27520 \end_layout
27521
27522 \begin_layout Subsubsection
27523 Standard I/O Streams
27524 \end_layout
27525
27526 \begin_layout Standard
27527 In the 
27528 \emph on
27529 stdio.h
27530 \emph default
27531  the type FILE is defined as:
27532 \end_layout
27533
27534 \begin_layout LyX-Code
27535 typedef char * FILE;
27536 \end_layout
27537
27538 \begin_layout Standard
27539 This type is the stream type implemented I/O in the PIC18F devices.
27540  Also the standard input and output streams are declared in stdio.h:
27541 \end_layout
27542
27543 \begin_layout LyX-Code
27544 extern FILE * stdin;
27545 \end_layout
27546
27547 \begin_layout LyX-Code
27548 extern FILE * stdout;
27549 \end_layout
27550
27551 \begin_layout Standard
27552 The FILE type is actually a generic pointer which defines one more type
27553  of generic pointers, the 
27554 \emph on
27555 stream 
27556 \emph default
27557 pointer.
27558  This new type has the format:
27559 \end_layout
27560
27561 \begin_layout Standard
27562 \align center
27563 \begin_inset Tabular
27564 <lyxtabular version="3" rows="2" columns="7">
27565 <features>
27566 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27567 <column alignment="center" valignment="top" width="0">
27568 <column alignment="center" valignment="top" leftline="true" width="0">
27569 <column alignment="center" valignment="top" leftline="true" width="0">
27570 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27571 <column alignment="center" valignment="top" width="0">
27572 <column alignment="left" valignment="top" rightline="true" width="0">
27573 <row topline="true" bottomline="true">
27574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27575 \begin_inset Text
27576
27577 \begin_layout Standard
27578 pointer type
27579 \end_layout
27580
27581 \end_inset
27582 </cell>
27583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27584 \begin_inset Text
27585
27586 \begin_layout Standard
27587 <7:6>
27588 \end_layout
27589
27590 \end_inset
27591 </cell>
27592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27593 \begin_inset Text
27594
27595 \begin_layout Standard
27596 <5>
27597 \end_layout
27598
27599 \end_inset
27600 </cell>
27601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27602 \begin_inset Text
27603
27604 \begin_layout Standard
27605 <4>
27606 \end_layout
27607
27608 \end_inset
27609 </cell>
27610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27611 \begin_inset Text
27612
27613 \begin_layout Standard
27614 <3:0>
27615 \end_layout
27616
27617 \end_inset
27618 </cell>
27619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27620 \begin_inset Text
27621
27622 \begin_layout Standard
27623 rest of the pointer
27624 \end_layout
27625
27626 \end_inset
27627 </cell>
27628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27629 \begin_inset Text
27630
27631 \begin_layout Standard
27632 descrption
27633 \end_layout
27634
27635 \end_inset
27636 </cell>
27637 </row>
27638 <row topline="true" bottomline="true">
27639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27640 \begin_inset Text
27641
27642 \begin_layout Standard
27643 stream
27644 \end_layout
27645
27646 \end_inset
27647 </cell>
27648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27649 \begin_inset Text
27650
27651 \begin_layout Standard
27652 00
27653 \end_layout
27654
27655 \end_inset
27656 </cell>
27657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27658 \begin_inset Text
27659
27660 \begin_layout Standard
27661 1
27662 \end_layout
27663
27664 \end_inset
27665 </cell>
27666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27667 \begin_inset Text
27668
27669 \begin_layout Standard
27670 0
27671 \end_layout
27672
27673 \end_inset
27674 </cell>
27675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27676 \begin_inset Text
27677
27678 \begin_layout Standard
27679 nnnn
27680 \end_layout
27681
27682 \end_inset
27683 </cell>
27684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27685 \begin_inset Text
27686
27687 \begin_layout Standard
27688
27689 \family typewriter
27690 \shape slanted
27691 \emph on
27692 uuuuuuuu uuuuuuuu
27693 \end_layout
27694
27695 \end_inset
27696 </cell>
27697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27698 \begin_inset Text
27699
27700 \begin_layout Standard
27701 upper byte high nubble is 0x2n, the rest are zeroes
27702 \end_layout
27703
27704 \end_inset
27705 </cell>
27706 </row>
27707 </lyxtabular>
27708
27709 \end_inset
27710
27711
27712 \end_layout
27713
27714 \begin_layout Standard
27715 Currently implemented there are 3 types of streams defined:
27716 \end_layout
27717
27718 \begin_layout Standard
27719 \align center
27720 \begin_inset Tabular
27721 <lyxtabular version="3" rows="4" columns="4">
27722 <features>
27723 <column alignment="center" valignment="top" leftline="true" width="0">
27724 <column alignment="center" valignment="top" leftline="true" width="0">
27725 <column alignment="center" valignment="top" leftline="true" width="0">
27726 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27727 <row topline="true" bottomline="true">
27728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27729 \begin_inset Text
27730
27731 \begin_layout Standard
27732 stream type
27733 \end_layout
27734
27735 \end_inset
27736 </cell>
27737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27738 \begin_inset Text
27739
27740 \begin_layout Standard
27741 value
27742 \end_layout
27743
27744 \end_inset
27745 </cell>
27746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27747 \begin_inset Text
27748
27749 \begin_layout Standard
27750 module
27751 \end_layout
27752
27753 \end_inset
27754 </cell>
27755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27756 \begin_inset Text
27757
27758 \begin_layout Standard
27759 description
27760 \end_layout
27761
27762 \end_inset
27763 </cell>
27764 </row>
27765 <row topline="true">
27766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27767 \begin_inset Text
27768
27769 \begin_layout Standard
27770 STREAM_USART
27771 \end_layout
27772
27773 \end_inset
27774 </cell>
27775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27776 \begin_inset Text
27777
27778 \begin_layout Standard
27779
27780 \family typewriter
27781 0x200000UL
27782 \end_layout
27783
27784 \end_inset
27785 </cell>
27786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27787 \begin_inset Text
27788
27789 \begin_layout Standard
27790 USART
27791 \end_layout
27792
27793 \end_inset
27794 </cell>
27795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27796 \begin_inset Text
27797
27798 \begin_layout Standard
27799 Writes/Reads characters via the USART peripheral
27800 \end_layout
27801
27802 \end_inset
27803 </cell>
27804 </row>
27805 <row topline="true">
27806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27807 \begin_inset Text
27808
27809 \begin_layout Standard
27810 STREAM_MSSP
27811 \end_layout
27812
27813 \end_inset
27814 </cell>
27815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27816 \begin_inset Text
27817
27818 \begin_layout Standard
27819
27820 \family typewriter
27821 0x210000UL
27822 \end_layout
27823
27824 \end_inset
27825 </cell>
27826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27827 \begin_inset Text
27828
27829 \begin_layout Standard
27830 MSSP
27831 \end_layout
27832
27833 \end_inset
27834 </cell>
27835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27836 \begin_inset Text
27837
27838 \begin_layout Standard
27839 Writes/Reads characters via the MSSP peripheral
27840 \end_layout
27841
27842 \end_inset
27843 </cell>
27844 </row>
27845 <row topline="true" bottomline="true">
27846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27847 \begin_inset Text
27848
27849 \begin_layout Standard
27850 STREAM_USER
27851 \end_layout
27852
27853 \end_inset
27854 </cell>
27855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27856 \begin_inset Text
27857
27858 \begin_layout Standard
27859
27860 \family typewriter
27861 0x2f0000UL
27862 \end_layout
27863
27864 \end_inset
27865 </cell>
27866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27867 \begin_inset Text
27868
27869 \begin_layout Standard
27870 (none)
27871 \end_layout
27872
27873 \end_inset
27874 </cell>
27875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27876 \begin_inset Text
27877
27878 \begin_layout Standard
27879 Writes/Reads characters via used defined functions
27880 \end_layout
27881
27882 \end_inset
27883 </cell>
27884 </row>
27885 </lyxtabular>
27886
27887 \end_inset
27888
27889
27890 \end_layout
27891
27892 \begin_layout Standard
27893 The stream identifiers are declared as macros in the stdio.h header.
27894 \end_layout
27895
27896 \begin_layout Standard
27897 In the libc library there exist the functions that are used to write to
27898  each of the above streams.
27899  These are
27900 \end_layout
27901
27902 \begin_layout Description
27903 _
27904 \begin_inset ERT
27905 status collapsed
27906
27907 \begin_layout Standard
27908
27909
27910 \backslash
27911 /
27912 \end_layout
27913
27914 \end_inset
27915
27916 _stream_usart_putchar writes a character at the USART stream
27917 \end_layout
27918
27919 \begin_layout Description
27920 _
27921 \begin_inset ERT
27922 status collapsed
27923
27924 \begin_layout Standard
27925
27926
27927 \backslash
27928 /
27929 \end_layout
27930
27931 \end_inset
27932
27933 _stream_mssp_putchar writes a character at the MSSP stream
27934 \end_layout
27935
27936 \begin_layout Description
27937 putchar dummy function.
27938  This writes a character to a user specified manner.
27939 \end_layout
27940
27941 \begin_layout Standard
27942 In order to increase performance 
27943 \emph on
27944 putchar 
27945 \emph default
27946 is declared in stdio.h as having its parameter in WREG (it has the wparam
27947  keyword).
27948  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27949  in a user-friendly way.
27950  
27951 \emph on
27952 arg
27953 \emph default
27954  is the name of the variable that holds the character to print.
27955  An example follows:
27956 \end_layout
27957
27958 \begin_layout LyX-Code
27959 #include <pic18fregs.h>
27960 \newline
27961 #include <stdio.h>
27962 \newline
27963
27964 \newline
27965 PUTCHAR( c )
27966 \end_layout
27967
27968 \begin_layout LyX-Code
27969 {
27970 \end_layout
27971
27972 \begin_layout LyX-Code
27973     PORTA = c;    /* dump character c to PORTA */
27974 \end_layout
27975
27976 \begin_layout LyX-Code
27977
27978 \newline
27979
27980 \newline
27981 void main(void)
27982 \end_layout
27983
27984 \begin_layout LyX-Code
27985 {
27986 \end_layout
27987
27988 \begin_layout LyX-Code
27989     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27990 \end_layout
27991
27992 \begin_layout LyX-Code
27993                               * by default to STREAM_USER */
27994 \end_layout
27995
27996 \begin_layout LyX-Code
27997     printf (
27998 \begin_inset Quotes sld
27999 \end_inset
28000
28001 This is a printf test
28002 \backslash
28003 n
28004 \begin_inset Quotes srd
28005 \end_inset
28006
28007 );
28008 \end_layout
28009
28010 \begin_layout LyX-Code
28011 }
28012 \end_layout
28013
28014 \begin_layout LyX-Code
28015
28016 \end_layout
28017
28018 \begin_layout Subsubsection
28019 Printing functions
28020 \end_layout
28021
28022 \begin_layout Standard
28023 PIC16 contains an implementation of the printf-family of functions.
28024  There exist the following functions:
28025 \end_layout
28026
28027 \begin_layout LyX-Code
28028 extern unsigned int sprintf(char *buf, char *fmt, ...);
28029 \end_layout
28030
28031 \begin_layout LyX-Code
28032 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
28033 \end_layout
28034
28035 \begin_layout LyX-Code
28036
28037 \end_layout
28038
28039 \begin_layout LyX-Code
28040 extern unsigned int printf(char *fmt, ...);
28041 \end_layout
28042
28043 \begin_layout LyX-Code
28044 extern unsigned int vprintf(char *fmt, va_lista ap);
28045 \end_layout
28046
28047 \begin_layout LyX-Code
28048
28049 \end_layout
28050
28051 \begin_layout LyX-Code
28052 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
28053 \end_layout
28054
28055 \begin_layout LyX-Code
28056 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
28057 \end_layout
28058
28059 \begin_layout Standard
28060 For sprintf and vsprintf 
28061 \emph on
28062 buf 
28063 \emph default
28064 should normally be a data pointer where the resulting string will be placed.
28065  No range checking is done so the user should allocate the necessery buffer.
28066  For fprintf and vfprintf 
28067 \emph on
28068 fp
28069 \emph default
28070  should be a stream pointer (i.e.
28071  stdout, STREAM_MSSP, etc...).
28072 \end_layout
28073
28074 \begin_layout Subsubsection
28075 Signals
28076 \end_layout
28077
28078 \begin_layout Standard
28079 The PIC18F family of microcontrollers supports a number of interrupt sources.
28080  A list of these interrupts is shown in the following table:
28081 \end_layout
28082
28083 \begin_layout Standard
28084 \align center
28085 \begin_inset Tabular
28086 <lyxtabular version="3" rows="11" columns="4">
28087 <features>
28088 <column alignment="left" valignment="top" leftline="true" width="0">
28089 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28090 <column alignment="left" valignment="top" leftline="true" width="0">
28091 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28092 <row topline="true" bottomline="true">
28093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28094 \begin_inset Text
28095
28096 \begin_layout Standard
28097 signal name
28098 \end_layout
28099
28100 \end_inset
28101 </cell>
28102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28103 \begin_inset Text
28104
28105 \begin_layout Standard
28106 description
28107 \end_layout
28108
28109 \end_inset
28110 </cell>
28111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28112 \begin_inset Text
28113
28114 \begin_layout Standard
28115 signal name
28116 \end_layout
28117
28118 \end_inset
28119 </cell>
28120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28121 \begin_inset Text
28122
28123 \begin_layout Standard
28124 descritpion
28125 \end_layout
28126
28127 \end_inset
28128 </cell>
28129 </row>
28130 <row topline="true">
28131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28132 \begin_inset Text
28133
28134 \begin_layout Standard
28135 SIG_RB
28136 \end_layout
28137
28138 \end_inset
28139 </cell>
28140 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28141 \begin_inset Text
28142
28143 \begin_layout Standard
28144 PORTB change interrupt
28145 \end_layout
28146
28147 \end_inset
28148 </cell>
28149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28150 \begin_inset Text
28151
28152 \begin_layout Standard
28153 SIG_EE
28154 \end_layout
28155
28156 \end_inset
28157 </cell>
28158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28159 \begin_inset Text
28160
28161 \begin_layout Standard
28162 EEPROM/FLASH write complete interrupt
28163 \end_layout
28164
28165 \end_inset
28166 </cell>
28167 </row>
28168 <row topline="true">
28169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28170 \begin_inset Text
28171
28172 \begin_layout Standard
28173 SIG_INT0
28174 \end_layout
28175
28176 \end_inset
28177 </cell>
28178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28179 \begin_inset Text
28180
28181 \begin_layout Standard
28182 INT0 external interrupt
28183 \end_layout
28184
28185 \end_inset
28186 </cell>
28187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28188 \begin_inset Text
28189
28190 \begin_layout Standard
28191 SIG_BCOL
28192 \end_layout
28193
28194 \end_inset
28195 </cell>
28196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28197 \begin_inset Text
28198
28199 \begin_layout Standard
28200 Bus collision interrupt
28201 \end_layout
28202
28203 \end_inset
28204 </cell>
28205 </row>
28206 <row topline="true">
28207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28208 \begin_inset Text
28209
28210 \begin_layout Standard
28211 SIG_INT1
28212 \end_layout
28213
28214 \end_inset
28215 </cell>
28216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28217 \begin_inset Text
28218
28219 \begin_layout Standard
28220 INT1 external interrupt
28221 \end_layout
28222
28223 \end_inset
28224 </cell>
28225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28226 \begin_inset Text
28227
28228 \begin_layout Standard
28229 SIG_LVD
28230 \end_layout
28231
28232 \end_inset
28233 </cell>
28234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28235 \begin_inset Text
28236
28237 \begin_layout Standard
28238 Low voltage detect interrupt
28239 \end_layout
28240
28241 \end_inset
28242 </cell>
28243 </row>
28244 <row topline="true">
28245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28246 \begin_inset Text
28247
28248 \begin_layout Standard
28249 SIG_INT2
28250 \end_layout
28251
28252 \end_inset
28253 </cell>
28254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28255 \begin_inset Text
28256
28257 \begin_layout Standard
28258 INT2 external interrupt
28259 \end_layout
28260
28261 \end_inset
28262 </cell>
28263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28264 \begin_inset Text
28265
28266 \begin_layout Standard
28267 SIG_PSP
28268 \end_layout
28269
28270 \end_inset
28271 </cell>
28272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28273 \begin_inset Text
28274
28275 \begin_layout Standard
28276 Parallel slave port interrupt
28277 \end_layout
28278
28279 \end_inset
28280 </cell>
28281 </row>
28282 <row topline="true">
28283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28284 \begin_inset Text
28285
28286 \begin_layout Standard
28287 SIG_CCP1
28288 \end_layout
28289
28290 \end_inset
28291 </cell>
28292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28293 \begin_inset Text
28294
28295 \begin_layout Standard
28296 CCP1 module interrupt
28297 \end_layout
28298
28299 \end_inset
28300 </cell>
28301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28302 \begin_inset Text
28303
28304 \begin_layout Standard
28305 SIG_AD
28306 \end_layout
28307
28308 \end_inset
28309 </cell>
28310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28311 \begin_inset Text
28312
28313 \begin_layout Standard
28314 AD convertion complete interrupt
28315 \end_layout
28316
28317 \end_inset
28318 </cell>
28319 </row>
28320 <row topline="true">
28321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28322 \begin_inset Text
28323
28324 \begin_layout Standard
28325 SIG_CCP2
28326 \end_layout
28327
28328 \end_inset
28329 </cell>
28330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28331 \begin_inset Text
28332
28333 \begin_layout Standard
28334 CCP2 module interrupt
28335 \end_layout
28336
28337 \end_inset
28338 </cell>
28339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28340 \begin_inset Text
28341
28342 \begin_layout Standard
28343 SIG_RC
28344 \end_layout
28345
28346 \end_inset
28347 </cell>
28348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28349 \begin_inset Text
28350
28351 \begin_layout Standard
28352 USART receive interrupt
28353 \end_layout
28354
28355 \end_inset
28356 </cell>
28357 </row>
28358 <row topline="true">
28359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28360 \begin_inset Text
28361
28362 \begin_layout Standard
28363 SIG_TMR0
28364 \end_layout
28365
28366 \end_inset
28367 </cell>
28368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28369 \begin_inset Text
28370
28371 \begin_layout Standard
28372 TMR0 overflow interrupt
28373 \end_layout
28374
28375 \end_inset
28376 </cell>
28377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28378 \begin_inset Text
28379
28380 \begin_layout Standard
28381 SIG_TX
28382 \end_layout
28383
28384 \end_inset
28385 </cell>
28386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28387 \begin_inset Text
28388
28389 \begin_layout Standard
28390 USART transmit interrupt
28391 \end_layout
28392
28393 \end_inset
28394 </cell>
28395 </row>
28396 <row topline="true">
28397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28398 \begin_inset Text
28399
28400 \begin_layout Standard
28401 SIG_TMR1
28402 \end_layout
28403
28404 \end_inset
28405 </cell>
28406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28407 \begin_inset Text
28408
28409 \begin_layout Standard
28410 TMR1 overflow interrupt
28411 \end_layout
28412
28413 \end_inset
28414 </cell>
28415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28416 \begin_inset Text
28417
28418 \begin_layout Standard
28419 SIG_MSSP
28420 \end_layout
28421
28422 \end_inset
28423 </cell>
28424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28425 \begin_inset Text
28426
28427 \begin_layout Standard
28428 SSP receive/transmit interrupt
28429 \end_layout
28430
28431 \end_inset
28432 </cell>
28433 </row>
28434 <row topline="true">
28435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28436 \begin_inset Text
28437
28438 \begin_layout Standard
28439 SIG_TMR2
28440 \end_layout
28441
28442 \end_inset
28443 </cell>
28444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28445 \begin_inset Text
28446
28447 \begin_layout Standard
28448 TMR2 matches PR2 interrupt
28449 \end_layout
28450
28451 \end_inset
28452 </cell>
28453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28454 \begin_inset Text
28455
28456 \begin_layout Standard
28457
28458 \end_layout
28459
28460 \end_inset
28461 </cell>
28462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28463 \begin_inset Text
28464
28465 \begin_layout Standard
28466
28467 \end_layout
28468
28469 \end_inset
28470 </cell>
28471 </row>
28472 <row topline="true" bottomline="true">
28473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28474 \begin_inset Text
28475
28476 \begin_layout Standard
28477 SIG_TMR3
28478 \end_layout
28479
28480 \end_inset
28481 </cell>
28482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28483 \begin_inset Text
28484
28485 \begin_layout Standard
28486 TMR3 overflow interrupt
28487 \end_layout
28488
28489 \end_inset
28490 </cell>
28491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28492 \begin_inset Text
28493
28494 \begin_layout Standard
28495
28496 \end_layout
28497
28498 \end_inset
28499 </cell>
28500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28501 \begin_inset Text
28502
28503 \begin_layout Standard
28504
28505 \end_layout
28506
28507 \end_inset
28508 </cell>
28509 </row>
28510 </lyxtabular>
28511
28512 \end_inset
28513
28514
28515 \end_layout
28516
28517 \begin_layout Standard
28518 The prototypes for these names are defined in the header file 
28519 \emph on
28520 signal.h
28521 \emph default
28522  .
28523 \end_layout
28524
28525 \begin_layout Standard
28526 In order to simplify signal handling, a number of macros is provided:
28527 \end_layout
28528
28529 \begin_layout List
28530 \labelwidthstring 00.00.0000
28531 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28532  high priority interrupts.
28533  
28534 \emph on
28535 name
28536 \emph default
28537  is the function name to use.
28538 \end_layout
28539
28540 \begin_layout List
28541 \labelwidthstring 00.00.0000
28542 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28543  low priority interrupt.
28544  
28545 \emph on
28546 name
28547 \emph default
28548  is the function name to use.
28549 \end_layout
28550
28551 \begin_layout List
28552 \labelwidthstring 00.00.0000
28553 DEF_HANDLER(sig,handler) define a handler for signal 
28554 \emph on
28555 sig.
28556 \end_layout
28557
28558 \begin_layout List
28559 \labelwidthstring 00.00.0000
28560 END_DEF end the declaration of the dispatch table.
28561 \end_layout
28562
28563 \begin_layout Standard
28564 Additionally there are two more macros to simplify the declaration of the
28565  signal handler:
28566 \end_layout
28567
28568 \begin_layout List
28569 \labelwidthstring 00.00.0000
28570
28571 \series medium
28572 SIGHANDLER(handler) 
28573 \series default
28574 this declares the function prototype for the 
28575 \emph on
28576 handler
28577 \emph default
28578  function.
28579 \end_layout
28580
28581 \begin_layout List
28582 \labelwidthstring 00.00.0000
28583 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28584 \end_layout
28585
28586 \begin_layout Standard
28587 An example of using the macros above is shown below:
28588 \end_layout
28589
28590 \begin_layout LyX-Code
28591 #include <pic18fregs.h>
28592 \end_layout
28593
28594 \begin_layout LyX-Code
28595 #include <signal.h>
28596 \newline
28597
28598 \newline
28599 DEF_INTHIGH(high_int)
28600 \end_layout
28601
28602 \begin_layout LyX-Code
28603 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28604 \end_layout
28605
28606 \begin_layout LyX-Code
28607 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28608 \end_layout
28609
28610 \begin_layout LyX-Code
28611 END_DEF
28612 \newline
28613
28614 \newline
28615 SIGHANDLER(_tmr0_handler)
28616 \end_layout
28617
28618 \begin_layout LyX-Code
28619 {
28620 \end_layout
28621
28622 \begin_layout LyX-Code
28623   /* action to be taken when timer 0 overflows */
28624 \end_layout
28625
28626 \begin_layout LyX-Code
28627 }
28628 \newline
28629
28630 \newline
28631 SIGHANDLERNAKED(_bcol_handler)
28632 \end_layout
28633
28634 \begin_layout LyX-Code
28635 {
28636 \end_layout
28637
28638 \begin_layout LyX-Code
28639   _asm
28640 \end_layout
28641
28642 \begin_layout LyX-Code
28643     /* action to be taken when bus collision occurs */
28644 \end_layout
28645
28646 \begin_layout LyX-Code
28647     retfie
28648 \end_layout
28649
28650 \begin_layout LyX-Code
28651  _endasm;
28652 \end_layout
28653
28654 \begin_layout LyX-Code
28655 }
28656 \end_layout
28657
28658 \begin_layout Standard
28659
28660 \series bold
28661 NOTES:
28662 \series default
28663  Special care should be taken when using the above scheme:
28664 \end_layout
28665
28666 \begin_layout Itemize
28667 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28668 \end_layout
28669
28670 \begin_layout Itemize
28671 when declaring SIGHANDLERNAKED handler never forget to use 
28672 \emph on
28673 retfie
28674 \emph default
28675  for proper returning.
28676 \end_layout
28677
28678 \begin_layout Subsection
28679 PIC16 Port -- Tips
28680 \end_layout
28681
28682 \begin_layout Standard
28683 Here you can find some general tips for compiling programs with SDCC/pic16.
28684 \end_layout
28685
28686 \begin_layout Subsubsection
28687 Stack size
28688 \end_layout
28689
28690 \begin_layout Standard
28691 The default stack
28692 \begin_inset LatexCommand \index{PIC16!stack}
28693
28694 \end_inset
28695
28696  size (that is 64 bytes) probably is enough for many programs.
28697  One must take care that when there are many levels of function nesting,
28698  or there is excessive usage of stack, its size should be extended.
28699  An example of such a case is the printf/sprintf family of functions.
28700  If you encounter problems like not being able to print integers, then you
28701  need to set the stack size around the maximum (256 for small stack model).
28702  The following diagram shows what happens when calling printf to print an
28703  integer:
28704 \end_layout
28705
28706 \begin_layout LyX-Code
28707 printf () --> ltoa () --> ultoa () --> divschar ()
28708 \end_layout
28709
28710 \begin_layout Standard
28711 It is should be understood that stack is easily consumed when calling complicate
28712 d functions.
28713  Using command line arguments like -
28714 \begin_inset ERT
28715 status collapsed
28716
28717 \begin_layout Standard
28718
28719
28720 \backslash
28721 /
28722 \end_layout
28723
28724 \end_inset
28725
28726 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28727  stack frames.
28728  Other ways to reduce stack usage may exist.
28729 \end_layout
28730
28731 \begin_layout Subsection
28732 Known Bugs
28733 \end_layout
28734
28735 \begin_layout Standard
28736 The PIC16 Port currently does not pass SDCC's regression test
28737 \begin_inset LatexCommand \index{Regression test (PIC16)}
28738
28739 \end_inset
28740
28741  suite (see section 
28742 \begin_inset LatexCommand \ref{sec:Quality-control}
28743
28744 \end_inset
28745
28746 ) and thus the snapshot build regression tests for the PIC16 target are
28747  currently disabled for all hosts
28748 \emph on
28749 .
28750 \end_layout
28751
28752 \begin_layout Chapter
28753 Debugging
28754 \end_layout
28755
28756 \begin_layout Standard
28757 There are several approaches to debugging your code.
28758  This chapter is meant to show your options and to give detail on some of
28759  them:
28760 \newline
28761
28762 \newline
28763 When writing your code:
28764 \end_layout
28765
28766 \begin_layout Itemize
28767 write your code with debugging in mind (avoid duplicating code, put conceptually
28768  similar variables into structs, use structured code, have strategic points
28769  within your code where all variables are consistent, ...)
28770 \end_layout
28771
28772 \begin_layout Itemize
28773 run a syntax-checking tool like splint
28774 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28775
28776 \end_inset
28777
28778
28779 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28780
28781 \end_inset
28782
28783  (see -
28784 \begin_inset ERT
28785 status collapsed
28786
28787 \begin_layout Standard
28788
28789
28790 \backslash
28791 /
28792 \end_layout
28793
28794 \end_inset
28795
28796 -more-pedantic 
28797 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28798
28799 \end_inset
28800
28801 ) over the code.
28802 \end_layout
28803
28804 \begin_layout Itemize
28805 for the high level code use a C-compiler (like f.e.
28806  GCC) to compile run and debug the code on your host.
28807  See (see -
28808 \begin_inset ERT
28809 status collapsed
28810
28811 \begin_layout Standard
28812
28813
28814 \backslash
28815 /
28816 \end_layout
28817
28818 \end_inset
28819
28820 -more-pedantic 
28821 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28822
28823 \end_inset
28824
28825 ) on how to handle syntax extensions like __xdata, __at(), ...
28826  
28827 \end_layout
28828
28829 \begin_layout Itemize
28830 use another C-compiler to compile code for your target.
28831  Always an option but not recommended:) And not very likely to help you.
28832  If you seriously consider walking this path you should at least occasionally
28833  check portability of your code.
28834  Most commercial compiler vendors will offer an evaluation version so you
28835  can test compile your code or snippets of your code.
28836 \end_layout
28837
28838 \begin_layout Standard
28839 Debugging on a simulator:
28840 \end_layout
28841
28842 \begin_layout Itemize
28843 there is a separate section about SDCDB (section 
28844 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28845
28846 \end_inset
28847
28848 ) below.
28849 \end_layout
28850
28851 \begin_layout Itemize
28852 or (8051 specific) use a freeware/commercial simulator which interfaces
28853  to the AOMF
28854 \begin_inset LatexCommand \index{AOMF, AOMF51}
28855
28856 \end_inset
28857
28858  file (see 
28859 \begin_inset LatexCommand \ref{OMF file}
28860
28861 \end_inset
28862
28863 ) optionally generated by SDCC.
28864 \end_layout
28865
28866 \begin_layout Standard
28867 Debugging On-target: 
28868 \end_layout
28869
28870 \begin_layout Itemize
28871 use a MCU port pin to serially output debug data to the RS232 port of your
28872  host.
28873  You'll probably want some level shifting device typically involving a MAX232
28874  or similar IC.
28875  If the hardware serial port of the MCU is not available search for 'Software
28876  UART' in your favourite search machine.
28877 \end_layout
28878
28879 \begin_layout Itemize
28880 use an on-target monitor.
28881  In this context a monitor is a small program which usually accepts commands
28882  via a serial line and allows to set program counter, to single step through
28883  a program and read/write memory locations.
28884  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28885  
28886 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28887
28888 \end_inset
28889
28890 ).
28891 \end_layout
28892
28893 \begin_layout Itemize
28894 toggle MCU port pins at strategic points within your code and use an oscilloscop
28895 e.
28896  A 
28897 \emph on
28898 digital oscilloscope
28899 \emph default
28900
28901 \begin_inset LatexCommand \index{Oscilloscope}
28902
28903 \end_inset
28904
28905  with deep trace memory is really helpful especially if you have to debug
28906  a realtime application.
28907  If you need to monitor more pins than your oscilloscope provides you can
28908  sometimes get away with a small R-2R network.
28909  On a single channel oscilloscope you could f.e.
28910  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28911 k
28912 \begin_inset Formula $\Omega$
28913 \end_inset
28914
28915  resistor and the other one by a 5\InsetSpace ~
28916 k
28917 \begin_inset Formula $\Omega$
28918 \end_inset
28919
28920  resistor to the oscilloscope probe (check output drive capability of the
28921  pins you want to monitor).
28922  If you need to monitor many more pins a 
28923 \emph on
28924 logic analyzer
28925 \emph default
28926  will be handy.
28927 \end_layout
28928
28929 \begin_layout Itemize
28930 use an ICE (
28931 \emph on
28932 i
28933 \emph default
28934
28935 \emph on
28936 c
28937 \emph default
28938 ircuit 
28939 \emph on
28940 e
28941 \emph default
28942 mulator
28943 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28944
28945 \end_inset
28946
28947 ).
28948  Usually very expensive.
28949  And very nice to have too.
28950  And usually locks you (for years...) to the devices the ICE can emulate.
28951  
28952 \end_layout
28953
28954 \begin_layout Itemize
28955 use a remote debugger.
28956  In most 8-bit systems the symbol information is not available on the target,
28957  and a complete debugger is too bulky for the target system.
28958  Therefore usually a debugger on the host system connects to an on-target
28959  debugging stub which accepts only primitive commands.
28960  
28961 \newline
28962 Terms to enter into your favourite search engine could be 'remote debugging',
28963  'gdb stub' or 'inferior debugger'.
28964  (is there one?)
28965 \end_layout
28966
28967 \begin_layout Itemize
28968 use an on target hardware debugger.
28969  Some of the more modern MCUs include hardware support for setting break
28970  points and monitoring/changing variables by using dedicated hardware pins.
28971  This facility doesn't require additional code to run on the target and
28972  
28973 \emph on
28974 usually
28975 \emph default
28976  doesn't affect runtime behaviour until a breakpoint is hit.
28977  For the mcs51 most hardware debuggers use the AOMF
28978 \begin_inset LatexCommand \index{AOMF, AOMF51}
28979
28980 \end_inset
28981
28982  file (see 
28983 \begin_inset LatexCommand \ref{OMF file}
28984
28985 \end_inset
28986
28987 ) as input file.
28988  
28989 \end_layout
28990
28991 \begin_layout Standard
28992 Last not least:
28993 \end_layout
28994
28995 \begin_layout Itemize
28996 if you are not familiar with any of the following terms you're likely to
28997  run into problems rather sooner than later: 
28998 \emph on
28999 volatile
29000 \emph default
29001
29002 \emph on
29003 atomic
29004 \emph default
29005
29006 \emph on
29007 memory map
29008 \emph default
29009
29010 \emph on
29011 overlay
29012 \emph default
29013 .
29014  As an embedded programmer you 
29015 \emph on
29016 have
29017 \emph default
29018  to know them so why not look them up 
29019 \emph on
29020 before
29021 \emph default
29022  you have problems?)
29023 \end_layout
29024
29025 \begin_layout Itemize
29026 tell someone else about your problem (actually this is a surprisingly effective
29027  means to hunt down the bug even if the listener is not familiar with your
29028  environment).
29029  As 'failure to communicate' is probably one of the job-induced deformations
29030  of an embedded programmer this is highly encouraged.
29031 \end_layout
29032
29033 \begin_layout Section
29034 Debugging with SDCDB
29035 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
29036
29037 \end_inset
29038
29039
29040 \begin_inset LatexCommand \index{SDCDB (debugger)}
29041
29042 \end_inset
29043
29044  
29045 \end_layout
29046
29047 \begin_layout Standard
29048 SDCC is distributed with a source level debugger
29049 \begin_inset LatexCommand \index{Debugger}
29050
29051 \end_inset
29052
29053 .
29054  The debugger uses a command line interface, the command repertoire of the
29055  debugger has been kept as close to gdb
29056 \begin_inset LatexCommand \index{gdb}
29057
29058 \end_inset
29059
29060  (the GNU debugger) as possible.
29061  The configuration and build process is part of the standard compiler installati
29062 on, which also builds and installs the debugger in the target directory
29063  specified during configuration.
29064  The debugger allows you debug BOTH at the C source and at the ASM source
29065  level.
29066 \end_layout
29067
29068 \begin_layout Subsection
29069 Compiling for Debugging
29070 \end_layout
29071
29072 \begin_layout Standard
29073 The -
29074 \begin_inset ERT
29075 status collapsed
29076
29077 \begin_layout Standard
29078
29079
29080 \backslash
29081 /
29082 \end_layout
29083
29084 \end_inset
29085
29086 -debug
29087 \begin_inset LatexCommand \index{-\/-debug}
29088
29089 \end_inset
29090
29091  option must be specified for all files for which debug information is to
29092  be generated.
29093  The compiler generates a .adb file for each of these files.
29094  The linker creates the .cdb
29095 \begin_inset LatexCommand \index{<file>.cdb}
29096
29097 \end_inset
29098
29099  file from the .adb
29100 \begin_inset LatexCommand \index{<file>.adb}
29101
29102 \end_inset
29103
29104  files and the address information.
29105  This .cdb is used by the debugger.
29106 \end_layout
29107
29108 \begin_layout Subsection
29109 How the Debugger Works
29110 \end_layout
29111
29112 \begin_layout Standard
29113 When the -
29114 \begin_inset ERT
29115 status collapsed
29116
29117 \begin_layout Standard
29118
29119
29120 \backslash
29121 /
29122 \end_layout
29123
29124 \end_inset
29125
29126 -debug option is specified the compiler generates extra symbol information
29127  some of which are put into the assembler source and some are put into the
29128  .adb file.
29129  Then the linker creates the .cdb file from the individual .adb files with
29130  the address information for the symbols.
29131  The debugger reads the symbolic information generated by the compiler &
29132  the address information generated by the linker.
29133  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29134  execution is controlled by the debugger.
29135  When a command is issued for the debugger, it translates it into appropriate
29136  commands for the simulator.
29137  (Currently SDCDM only connects to the simulator but 
29138 \emph on
29139 newcdb
29140 \emph default
29141  at 
29142 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29143
29144 \end_inset
29145
29146  is an effort to connect directly to the hardware.) 
29147 \end_layout
29148
29149 \begin_layout Subsection
29150 Starting the Debugger SDCDB
29151 \end_layout
29152
29153 \begin_layout Standard
29154 The debugger can be started using the following command line.
29155  (Assume the file you are debugging has the file name foo).
29156 \newline
29157
29158 \newline
29159
29160 \family sans
29161 \series bold
29162 sdcdb foo
29163 \newline
29164
29165 \family default
29166 \series default
29167
29168 \newline
29169 The debugger will look for the following files.
29170 \end_layout
29171
29172 \begin_layout Itemize
29173 foo.c - the source file.
29174 \end_layout
29175
29176 \begin_layout Itemize
29177 foo.cdb - the debugger symbol information file.
29178 \end_layout
29179
29180 \begin_layout Itemize
29181 foo.ihx - the Intel hex format
29182 \begin_inset LatexCommand \index{Intel hex format}
29183
29184 \end_inset
29185
29186  object file.
29187 \end_layout
29188
29189 \begin_layout Subsection
29190 SDCDB Command Line Options
29191 \end_layout
29192
29193 \begin_layout Itemize
29194 -
29195 \begin_inset ERT
29196 status collapsed
29197
29198 \begin_layout Standard
29199
29200
29201 \backslash
29202 /
29203 \end_layout
29204
29205 \end_inset
29206
29207 -directory=<source file directory> this option can used to specify the directory
29208  search list.
29209  The debugger will look into the directory list specified for source, cdb
29210  & ihx files.
29211  The items in the directory list must be separated by ':', e.g.
29212  if the source files can be in the directories /home/src1 and /home/src2,
29213  the -
29214 \begin_inset ERT
29215 status collapsed
29216
29217 \begin_layout Standard
29218
29219
29220 \backslash
29221 /
29222 \end_layout
29223
29224 \end_inset
29225
29226 -directory option should be -
29227 \begin_inset ERT
29228 status collapsed
29229
29230 \begin_layout Standard
29231
29232
29233 \backslash
29234 /
29235 \end_layout
29236
29237 \end_inset
29238
29239 -directory=/home/src1:/home/src2.
29240  Note there can be no spaces in the option.
29241  
29242 \end_layout
29243
29244 \begin_layout Itemize
29245 -cd <directory> - change to the <directory>.
29246 \end_layout
29247
29248 \begin_layout Itemize
29249 -fullname - used by GUI front ends.
29250 \end_layout
29251
29252 \begin_layout Itemize
29253 -cpu <cpu-type> - this argument is passed to the simulator please see the
29254  simulator docs for details.
29255 \end_layout
29256
29257 \begin_layout Itemize
29258 -X <Clock frequency > this options is passed to the simulator please see
29259  the simulator docs for details.
29260 \end_layout
29261
29262 \begin_layout Itemize
29263 -s <serial port file> passed to simulator see the simulator docs for details.
29264 \end_layout
29265
29266 \begin_layout Itemize
29267 -S <serial in,out> passed to simulator see the simulator docs for details.
29268 \end_layout
29269
29270 \begin_layout Itemize
29271 -k <port number> passed to simulator see the simulator docs for details.
29272 \end_layout
29273
29274 \begin_layout Subsection
29275 SDCDB Debugger Commands
29276 \end_layout
29277
29278 \begin_layout Standard
29279 As mentioned earlier the command interface for the debugger has been deliberatel
29280 y kept as close the GNU debugger gdb, as possible.
29281  This will help the integration with existing graphical user interfaces
29282  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29283  If you use a graphical user interface for the debugger you can skip this
29284  section.
29285 \end_layout
29286
29287 \begin_layout Subsubsection*
29288 break [line | file:line | function | file:function]
29289 \end_layout
29290
29291 \begin_layout Standard
29292 Set breakpoint at specified line or function:
29293 \newline
29294
29295 \newline
29296
29297 \family sans
29298 \series bold
29299 sdcdb>break 100 
29300 \newline
29301 sdcdb>break foo.c:100
29302 \newline
29303 sdcdb>break funcfoo
29304 \newline
29305 sdcdb>break foo.c:funcfoo
29306 \end_layout
29307
29308 \begin_layout Subsubsection*
29309 clear [line | file:line | function | file:function ]
29310 \end_layout
29311
29312 \begin_layout Standard
29313 Clear breakpoint at specified line or function:
29314 \newline
29315
29316 \newline
29317
29318 \family sans
29319 \series bold
29320 sdcdb>clear 100
29321 \newline
29322 sdcdb>clear foo.c:100
29323 \newline
29324 sdcdb>clear funcfoo
29325 \newline
29326 sdcdb>clear foo.c:funcfoo
29327 \end_layout
29328
29329 \begin_layout Subsubsection*
29330 continue
29331 \end_layout
29332
29333 \begin_layout Standard
29334 Continue program being debugged, after breakpoint.
29335 \end_layout
29336
29337 \begin_layout Subsubsection*
29338 finish
29339 \end_layout
29340
29341 \begin_layout Standard
29342 Execute till the end of the current function.
29343 \end_layout
29344
29345 \begin_layout Subsubsection*
29346 delete [n]
29347 \end_layout
29348
29349 \begin_layout Standard
29350 Delete breakpoint number 'n'.
29351  If used without any option clear ALL user defined break points.
29352 \end_layout
29353
29354 \begin_layout Subsubsection*
29355 info [break | stack | frame | registers ]
29356 \end_layout
29357
29358 \begin_layout Itemize
29359 info break - list all breakpoints
29360 \end_layout
29361
29362 \begin_layout Itemize
29363 info stack - show the function call stack.
29364 \end_layout
29365
29366 \begin_layout Itemize
29367 info frame - show information about the current execution frame.
29368 \end_layout
29369
29370 \begin_layout Itemize
29371 info registers - show content of all registers.
29372 \end_layout
29373
29374 \begin_layout Subsubsection*
29375 step
29376 \end_layout
29377
29378 \begin_layout Standard
29379 Step program until it reaches a different source line.
29380  Note: pressing <return> repeats the last command.
29381 \end_layout
29382
29383 \begin_layout Subsubsection*
29384 next
29385 \end_layout
29386
29387 \begin_layout Standard
29388 Step program, proceeding through subroutine calls.
29389 \end_layout
29390
29391 \begin_layout Subsubsection*
29392 run
29393 \end_layout
29394
29395 \begin_layout Standard
29396 Start debugged program.
29397 \end_layout
29398
29399 \begin_layout Subsubsection*
29400 ptype variable 
29401 \end_layout
29402
29403 \begin_layout Standard
29404 Print type information of the variable.
29405 \end_layout
29406
29407 \begin_layout Subsubsection*
29408 print variable
29409 \end_layout
29410
29411 \begin_layout Standard
29412 print value of variable.
29413 \end_layout
29414
29415 \begin_layout Subsubsection*
29416 file filename
29417 \end_layout
29418
29419 \begin_layout Standard
29420 load the given file name.
29421  Note this is an alternate method of loading file for debugging.
29422 \end_layout
29423
29424 \begin_layout Subsubsection*
29425 frame
29426 \end_layout
29427
29428 \begin_layout Standard
29429 print information about current frame.
29430 \end_layout
29431
29432 \begin_layout Subsubsection*
29433 set srcmode
29434 \end_layout
29435
29436 \begin_layout Standard
29437 Toggle between C source & assembly source.
29438 \end_layout
29439
29440 \begin_layout Subsubsection*
29441 ! simulator command
29442 \end_layout
29443
29444 \begin_layout Standard
29445 Send the string following '!' to the simulator, the simulator response is
29446  displayed.
29447  Note the debugger does not interpret the command being sent to the simulator,
29448  so if a command like 'go' is sent the debugger can loose its execution
29449  context and may display incorrect values.
29450 \end_layout
29451
29452 \begin_layout Subsubsection*
29453 quit
29454 \end_layout
29455
29456 \begin_layout Standard
29457 "Watch me now.
29458  Iam going Down.
29459  My name is Bobby Brown"
29460 \end_layout
29461
29462 \begin_layout Subsection
29463 Interfacing SDCDB with DDD
29464 \end_layout
29465
29466 \begin_layout Standard
29467 \begin_inset Note Note
29468 status collapsed
29469
29470 \begin_layout Standard
29471 The screenshot was converted from png to eps with: 
29472 \begin_inset Quotes sld
29473 \end_inset
29474
29475 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29476 \begin_inset Quotes srd
29477 \end_inset
29478
29479  which produces a pretty compact eps file which is free from compression
29480  artifacts.
29481 \end_layout
29482
29483 \begin_layout Standard
29484 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29485  as this broke the build system on Sourceforge (pdf-file was broken.
29486  pdflatex does not accept eps files).
29487 \end_layout
29488
29489 \end_inset
29490
29491
29492 \end_layout
29493
29494 \begin_layout Standard
29495 The 
29496 \emph on
29497 p
29498 \emph default
29499 ortable 
29500 \emph on
29501 n
29502 \emph default
29503 etwork 
29504 \emph on
29505 g
29506 \emph default
29507 raphics File 
29508 \size footnotesize
29509
29510 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29511
29512 \end_inset
29513
29514
29515 \size default
29516  shows a screenshot of a debugging session with DDD
29517 \begin_inset LatexCommand \index{DDD (debugger)}
29518
29519 \end_inset
29520
29521  (Unix only) on a simulated 8032.
29522  The debugging session might not run as smoothly as the screenshot suggests.
29523  The debugger allows setting of breakpoints, displaying and changing variables,
29524  single stepping through C and assembler code.
29525  
29526 \newline
29527 The source was compiled with 
29528 \family sans
29529 \series bold
29530
29531 \newline
29532
29533 \newline
29534 sdcc -
29535 \family default
29536 \series default
29537
29538 \begin_inset ERT
29539 status collapsed
29540
29541 \begin_layout Standard
29542
29543
29544 \backslash
29545 /
29546 \end_layout
29547
29548 \end_inset
29549
29550
29551 \family sans
29552 \series bold
29553 -debug ddd_example.c
29554 \family default
29555 \series default
29556  
29557 \family sans
29558 \series bold
29559
29560 \newline
29561
29562 \family default
29563 \series default
29564
29565 \newline
29566 and DDD was invoked with 
29567 \family sans
29568 \series bold
29569
29570 \newline
29571
29572 \newline
29573 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29574 \end_layout
29575
29576 \begin_layout Standard
29577 \begin_inset Note Note
29578 status open
29579
29580 \begin_layout Standard
29581 Check that the double quotes or an apostroph within the command line survive
29582  the LyX tool chain.
29583  Previously the apostrophs got slanted in the PDF output so a cut and paste
29584  did not work.
29585 \end_layout
29586
29587 \end_inset
29588
29589
29590 \end_layout
29591
29592 \begin_layout Subsection
29593 Interfacing SDCDB with XEmacs
29594 \begin_inset LatexCommand \index{XEmacs}
29595
29596 \end_inset
29597
29598
29599 \begin_inset LatexCommand \index{Emacs}
29600
29601 \end_inset
29602
29603
29604 \end_layout
29605
29606 \begin_layout Standard
29607 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29608  sdcdb.el and sdcdbsrc.el.
29609  These two files can be found in the $(prefix)/bin directory after the installat
29610 ion is complete.
29611  These files need to be loaded into XEmacs for the interface to work.
29612  This can be done at XEmacs startup time by inserting the following into
29613  your '.xemacs' file (which can be found in your HOME directory): 
29614 \newline
29615
29616 \newline
29617
29618 \family typewriter
29619 (load-file sdcdbsrc.el) 
29620 \family default
29621
29622 \newline
29623
29624 \newline
29625 .xemacs is a lisp file so the () around the command is REQUIRED.
29626  The files can also be loaded dynamically while XEmacs is running, set the
29627  environment variable 'EMACSLOADPATH' to the installation bin directory
29628  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29629  To start the interface enter the following command: 
29630 \newline
29631
29632 \newline
29633
29634 \family sans
29635 \series bold
29636 ESC-x sdcdbsrc
29637 \family default
29638 \series default
29639
29640 \newline
29641
29642 \newline
29643 You will prompted to enter the file name to be debugged.
29644  
29645 \newline
29646
29647 \newline
29648 The command line options that are passed to the simulator directly are
29649  bound to default values in the file sdcdbsrc.el.
29650  The variables are listed below, these values maybe changed as required.
29651 \end_layout
29652
29653 \begin_layout Itemize
29654 sdcdbsrc-cpu-type '51
29655 \end_layout
29656
29657 \begin_layout Itemize
29658 sdcdbsrc-frequency '11059200
29659 \end_layout
29660
29661 \begin_layout Itemize
29662 sdcdbsrc-serial nil
29663 \end_layout
29664
29665 \begin_layout Standard
29666 The following is a list of key mapping for the debugger interface.
29667 \end_layout
29668
29669 \begin_layout Standard
29670 \InsetSpace ~
29671
29672 \family typewriter
29673
29674 \newline
29675 ;;\InsetSpace ~
29676 Current Listing :: 
29677 \newline
29678 ;;key\InsetSpace ~
29679 \InsetSpace ~
29680 \InsetSpace ~
29681 \InsetSpace ~
29682 \InsetSpace ~
29683 \InsetSpace ~
29684 \InsetSpace ~
29685 \InsetSpace ~
29686 \InsetSpace ~
29687 \InsetSpace ~
29688 \InsetSpace ~
29689 \InsetSpace ~
29690 \InsetSpace ~
29691 \InsetSpace ~
29692 binding\InsetSpace ~
29693 \InsetSpace ~
29694 \InsetSpace ~
29695 \InsetSpace ~
29696 \InsetSpace ~
29697 \InsetSpace ~
29698 \InsetSpace ~
29699 \InsetSpace ~
29700 \InsetSpace ~
29701 \InsetSpace ~
29702 \InsetSpace ~
29703 \InsetSpace ~
29704 \InsetSpace ~
29705 \InsetSpace ~
29706 \InsetSpace ~
29707 \InsetSpace ~
29708 \InsetSpace ~
29709 \InsetSpace ~
29710 \InsetSpace ~
29711 \InsetSpace ~
29712 \InsetSpace ~
29713 \InsetSpace ~
29714 Comment 
29715 \newline
29716 ;;---\InsetSpace ~
29717 \InsetSpace ~
29718 \InsetSpace ~
29719 \InsetSpace ~
29720 \InsetSpace ~
29721 \InsetSpace ~
29722 \InsetSpace ~
29723 \InsetSpace ~
29724 \InsetSpace ~
29725 \InsetSpace ~
29726 \InsetSpace ~
29727 \InsetSpace ~
29728 \InsetSpace ~
29729 \InsetSpace ~
29730 -------\InsetSpace ~
29731 \InsetSpace ~
29732 \InsetSpace ~
29733 \InsetSpace ~
29734 \InsetSpace ~
29735 \InsetSpace ~
29736 \InsetSpace ~
29737 \InsetSpace ~
29738 \InsetSpace ~
29739 \InsetSpace ~
29740 \InsetSpace ~
29741 \InsetSpace ~
29742 \InsetSpace ~
29743 \InsetSpace ~
29744 \InsetSpace ~
29745 \InsetSpace ~
29746 \InsetSpace ~
29747 \InsetSpace ~
29748 \InsetSpace ~
29749 \InsetSpace ~
29750 \InsetSpace ~
29751 \InsetSpace ~
29752 -------
29753 \newline
29754 ;; 
29755 \newline
29756 ;;\InsetSpace ~
29757 n\InsetSpace ~
29758 \InsetSpace ~
29759 \InsetSpace ~
29760 \InsetSpace ~
29761 \InsetSpace ~
29762 \InsetSpace ~
29763 \InsetSpace ~
29764 \InsetSpace ~
29765 \InsetSpace ~
29766 \InsetSpace ~
29767 \InsetSpace ~
29768 \InsetSpace ~
29769 \InsetSpace ~
29770 \InsetSpace ~
29771 \InsetSpace ~
29772 sdcdb-next-fro
29773 m-src\InsetSpace ~
29774 \InsetSpace ~
29775 \InsetSpace ~
29776 \InsetSpace ~
29777 \InsetSpace ~
29778 \InsetSpace ~
29779 \InsetSpace ~
29780 \InsetSpace ~
29781 \InsetSpace ~
29782 \InsetSpace ~
29783 SDCDB next command 
29784 \newline
29785 ;;\InsetSpace ~
29786 b\InsetSpace ~
29787 \InsetSpace ~
29788 \InsetSpace ~
29789 \InsetSpace ~
29790 \InsetSpace ~
29791 \InsetSpace ~
29792 \InsetSpace ~
29793 \InsetSpace ~
29794 \InsetSpace ~
29795 \InsetSpace ~
29796 \InsetSpace ~
29797 \InsetSpace ~
29798 \InsetSpace ~
29799 \InsetSpace ~
29800 \InsetSpace ~
29801 sdcdb-back-from-src\InsetSpace ~
29802 \InsetSpace ~
29803 \InsetSpace ~
29804 \InsetSpace ~
29805 \InsetSpace ~
29806 \InsetSpace ~
29807 \InsetSpace ~
29808 \InsetSpace ~
29809 \InsetSpace ~
29810 \InsetSpace ~
29811 SDCDB back command 
29812 \newline
29813 ;;\InsetSpace ~
29814 c\InsetSpace ~
29815 \InsetSpace ~
29816 \InsetSpace ~
29817 \InsetSpace ~
29818 \InsetSpace ~
29819 \InsetSpace ~
29820 \InsetSpace ~
29821 \InsetSpace ~
29822 \InsetSpace ~
29823 \InsetSpace ~
29824 \InsetSpace ~
29825 \InsetSpace ~
29826 \InsetSpace ~
29827 \InsetSpace ~
29828 \InsetSpace ~
29829 sdcdb-cont-f
29830 rom-src\InsetSpace ~
29831 \InsetSpace ~
29832 \InsetSpace ~
29833 \InsetSpace ~
29834 \InsetSpace ~
29835 \InsetSpace ~
29836 \InsetSpace ~
29837 \InsetSpace ~
29838 \InsetSpace ~
29839 \InsetSpace ~
29840 SDCDB continue command
29841 \newline
29842 ;;\InsetSpace ~
29843 s\InsetSpace ~
29844 \InsetSpace ~
29845 \InsetSpace ~
29846 \InsetSpace ~
29847 \InsetSpace ~
29848 \InsetSpace ~
29849 \InsetSpace ~
29850 \InsetSpace ~
29851 \InsetSpace ~
29852 \InsetSpace ~
29853 \InsetSpace ~
29854 \InsetSpace ~
29855 \InsetSpace ~
29856 \InsetSpace ~
29857 \InsetSpace ~
29858 sdcdb-step-from-src\InsetSpace ~
29859 \InsetSpace ~
29860 \InsetSpace ~
29861 \InsetSpace ~
29862 \InsetSpace ~
29863 \InsetSpace ~
29864 \InsetSpace ~
29865 \InsetSpace ~
29866 \InsetSpace ~
29867 \InsetSpace ~
29868 SDCDB step command 
29869 \newline
29870 ;;\InsetSpace ~
29871 ?\InsetSpace ~
29872 \InsetSpace ~
29873 \InsetSpace ~
29874 \InsetSpace ~
29875 \InsetSpace ~
29876 \InsetSpace ~
29877 \InsetSpace ~
29878 \InsetSpace ~
29879 \InsetSpace ~
29880 \InsetSpace ~
29881 \InsetSpace ~
29882 \InsetSpace ~
29883 \InsetSpace ~
29884 \InsetSpace ~
29885 \InsetSpace ~
29886 sdcdb-w
29887 hatis-c-sexp\InsetSpace ~
29888 \InsetSpace ~
29889 \InsetSpace ~
29890 \InsetSpace ~
29891 \InsetSpace ~
29892 \InsetSpace ~
29893 \InsetSpace ~
29894 \InsetSpace ~
29895 \InsetSpace ~
29896 \InsetSpace ~
29897 SDCDB ptypecommand for data at 
29898 \newline
29899 ;;\InsetSpace ~
29900 \InsetSpace ~
29901 \InsetSpace ~
29902 \InsetSpace ~
29903 \InsetSpace ~
29904 \InsetSpace ~
29905 \InsetSpace ~
29906 \InsetSpace ~
29907 \InsetSpace ~
29908 \InsetSpace ~
29909 \InsetSpace ~
29910 \InsetSpace ~
29911 \InsetSpace ~
29912 \InsetSpace ~
29913 \InsetSpace ~
29914 \InsetSpace ~
29915 \InsetSpace ~
29916 \InsetSpace ~
29917 \InsetSpace ~
29918 \InsetSpace ~
29919 \InsetSpace ~
29920 \InsetSpace ~
29921 \InsetSpace ~
29922 \InsetSpace ~
29923 \InsetSpace ~
29924 \InsetSpace ~
29925 \InsetSpace ~
29926 \InsetSpace ~
29927 \InsetSpace ~
29928 \InsetSpace ~
29929 \InsetSpace ~
29930 \InsetSpace ~
29931 \InsetSpace ~
29932 \InsetSpace ~
29933 \InsetSpace ~
29934 \InsetSpace ~
29935 \InsetSpace ~
29936 \InsetSpace ~
29937 \InsetSpace ~
29938 \InsetSpace ~
29939 \InsetSpace ~
29940 \InsetSpace ~
29941 \InsetSpace ~
29942 \InsetSpace ~
29943 \InsetSpace ~
29944 \InsetSpace ~
29945 \InsetSpace ~
29946 buffer point 
29947 \newline
29948 ;;\InsetSpace ~
29949 x\InsetSpace ~
29950 \InsetSpace ~
29951 \InsetSpace ~
29952 \InsetSpace ~
29953 \InsetSpace ~
29954 \InsetSpace ~
29955 \InsetSpace ~
29956 \InsetSpace ~
29957 \InsetSpace ~
29958 \InsetSpace ~
29959 \InsetSpace ~
29960 \InsetSpace ~
29961 \InsetSpace ~
29962 \InsetSpace ~
29963 \InsetSpace ~
29964 sdcdbsrc-delete\InsetSpace ~
29965 \InsetSpace ~
29966 \InsetSpace ~
29967 \InsetSpace ~
29968 \InsetSpace ~
29969 \InsetSpace ~
29970 \InsetSpace ~
29971 \InsetSpace ~
29972 \InsetSpace ~
29973 \InsetSpace ~
29974 \InsetSpace ~
29975 \InsetSpace ~
29976 \InsetSpace ~
29977 \InsetSpace ~
29978 SDCD
29979 B Delete all breakpoints if no arg 
29980 \newline
29981 ;;\InsetSpace ~
29982 \InsetSpace ~
29983 \InsetSpace ~
29984 \InsetSpace ~
29985 \InsetSpace ~
29986 \InsetSpace ~
29987 \InsetSpace ~
29988 \InsetSpace ~
29989 \InsetSpace ~
29990 \InsetSpace ~
29991 \InsetSpace ~
29992 \InsetSpace ~
29993 \InsetSpace ~
29994 \InsetSpace ~
29995 \InsetSpace ~
29996 \InsetSpace ~
29997 \InsetSpace ~
29998 \InsetSpace ~
29999 \InsetSpace ~
30000 \InsetSpace ~
30001 \InsetSpace ~
30002 \InsetSpace ~
30003 \InsetSpace ~
30004 \InsetSpace ~
30005 \InsetSpace ~
30006 \InsetSpace ~
30007 \InsetSpace ~
30008 \InsetSpace ~
30009 \InsetSpace ~
30010 \InsetSpace ~
30011 \InsetSpace ~
30012 \InsetSpace ~
30013 \InsetSpace ~
30014 \InsetSpace ~
30015 \InsetSpace ~
30016 \InsetSpace ~
30017 \InsetSpace ~
30018 \InsetSpace ~
30019 \InsetSpace ~
30020 \InsetSpace ~
30021 \InsetSpace ~
30022 \InsetSpace ~
30023 \InsetSpace ~
30024 \InsetSpace ~
30025 \InsetSpace ~
30026 \InsetSpace ~
30027 \InsetSpace ~
30028 given or delete arg (C-u arg x) 
30029 \newline
30030 ;;\InsetSpace ~
30031 m\InsetSpace ~
30032 \InsetSpace ~
30033 \InsetSpace ~
30034 \InsetSpace ~
30035 \InsetSpace ~
30036 \InsetSpace ~
30037 \InsetSpace ~
30038 \InsetSpace ~
30039 \InsetSpace ~
30040 \InsetSpace ~
30041 \InsetSpace ~
30042 \InsetSpace ~
30043 \InsetSpace ~
30044 \InsetSpace ~
30045 \InsetSpace ~
30046 sdcdbsrc
30047 -frame\InsetSpace ~
30048 \InsetSpace ~
30049 \InsetSpace ~
30050 \InsetSpace ~
30051 \InsetSpace ~
30052 \InsetSpace ~
30053 \InsetSpace ~
30054 \InsetSpace ~
30055 \InsetSpace ~
30056 \InsetSpace ~
30057 \InsetSpace ~
30058 \InsetSpace ~
30059 \InsetSpace ~
30060 \InsetSpace ~
30061 \InsetSpace ~
30062 SDCDB Display current frame if no arg, 
30063 \newline
30064 ;;\InsetSpace ~
30065 \InsetSpace ~
30066 \InsetSpace ~
30067 \InsetSpace ~
30068 \InsetSpace ~
30069 \InsetSpace ~
30070 \InsetSpace ~
30071 \InsetSpace ~
30072 \InsetSpace ~
30073 \InsetSpace ~
30074 \InsetSpace ~
30075 \InsetSpace ~
30076 \InsetSpace ~
30077 \InsetSpace ~
30078 \InsetSpace ~
30079 \InsetSpace ~
30080 \InsetSpace ~
30081 \InsetSpace ~
30082 \InsetSpace ~
30083 \InsetSpace ~
30084 \InsetSpace ~
30085 \InsetSpace ~
30086 \InsetSpace ~
30087 \InsetSpace ~
30088 \InsetSpace ~
30089 \InsetSpace ~
30090 \InsetSpace ~
30091 \InsetSpace ~
30092 \InsetSpace ~
30093 \InsetSpace ~
30094 \InsetSpace ~
30095 \InsetSpace ~
30096 \InsetSpace ~
30097 \InsetSpace ~
30098 \InsetSpace ~
30099 \InsetSpace ~
30100 \InsetSpace ~
30101 \InsetSpace ~
30102 \InsetSpace ~
30103 \InsetSpace ~
30104 \InsetSpace ~
30105 \InsetSpace ~
30106 \InsetSpace ~
30107 \InsetSpace ~
30108 \InsetSpace ~
30109 \InsetSpace ~
30110 \InsetSpace ~
30111 given or display frame arg
30112  
30113 \newline
30114 ;;\InsetSpace ~
30115 \InsetSpace ~
30116 \InsetSpace ~
30117 \InsetSpace ~
30118 \InsetSpace ~
30119 \InsetSpace ~
30120 \InsetSpace ~
30121 \InsetSpace ~
30122 \InsetSpace ~
30123 \InsetSpace ~
30124 \InsetSpace ~
30125 \InsetSpace ~
30126 \InsetSpace ~
30127 \InsetSpace ~
30128 \InsetSpace ~
30129 \InsetSpace ~
30130 \InsetSpace ~
30131 \InsetSpace ~
30132 \InsetSpace ~
30133 \InsetSpace ~
30134 \InsetSpace ~
30135 \InsetSpace ~
30136 \InsetSpace ~
30137 \InsetSpace ~
30138 \InsetSpace ~
30139 \InsetSpace ~
30140 \InsetSpace ~
30141 \InsetSpace ~
30142 \InsetSpace ~
30143 \InsetSpace ~
30144 \InsetSpace ~
30145 \InsetSpace ~
30146 \InsetSpace ~
30147 \InsetSpace ~
30148 \InsetSpace ~
30149 \InsetSpace ~
30150 \InsetSpace ~
30151 \InsetSpace ~
30152 \InsetSpace ~
30153 \InsetSpace ~
30154 \InsetSpace ~
30155 \InsetSpace ~
30156 \InsetSpace ~
30157 \InsetSpace ~
30158 \InsetSpace ~
30159 \InsetSpace ~
30160 \InsetSpace ~
30161 buffer point 
30162 \newline
30163 ;;\InsetSpace ~
30164 !\InsetSpace ~
30165 \InsetSpace ~
30166 \InsetSpace ~
30167 \InsetSpace ~
30168 \InsetSpace ~
30169 \InsetSpace ~
30170 \InsetSpace ~
30171 \InsetSpace ~
30172 \InsetSpace ~
30173 \InsetSpace ~
30174 \InsetSpace ~
30175 \InsetSpace ~
30176 \InsetSpace ~
30177 \InsetSpace ~
30178 \InsetSpace ~
30179 sdcdbsrc-goto-sdcdb\InsetSpace ~
30180 \InsetSpace ~
30181 \InsetSpace ~
30182 \InsetSpace ~
30183 \InsetSpace ~
30184 \InsetSpace ~
30185 \InsetSpace ~
30186 \InsetSpace ~
30187 \InsetSpace ~
30188 \InsetSpace ~
30189 Goto the SDCDB output buffer 
30190 \newline
30191 ;;\InsetSpace ~
30192 p\InsetSpace ~
30193 \InsetSpace ~
30194 \InsetSpace ~
30195 \InsetSpace ~
30196 \InsetSpace ~
30197 \InsetSpace ~
30198 \InsetSpace ~
30199 \InsetSpace ~
30200 \InsetSpace ~
30201 \InsetSpace ~
30202 \InsetSpace ~
30203 \InsetSpace ~
30204 \InsetSpace ~
30205 \InsetSpace ~
30206 \InsetSpace ~
30207 sdcdb-prin
30208 t-c-sexp\InsetSpace ~
30209 \InsetSpace ~
30210 \InsetSpace ~
30211 \InsetSpace ~
30212 \InsetSpace ~
30213 \InsetSpace ~
30214 \InsetSpace ~
30215 \InsetSpace ~
30216 \InsetSpace ~
30217 \InsetSpace ~
30218 \InsetSpace ~
30219 SDCDB print command for data at 
30220 \newline
30221 ;;\InsetSpace ~
30222 \InsetSpace ~
30223 \InsetSpace ~
30224 \InsetSpace ~
30225 \InsetSpace ~
30226 \InsetSpace ~
30227 \InsetSpace ~
30228 \InsetSpace ~
30229 \InsetSpace ~
30230 \InsetSpace ~
30231 \InsetSpace ~
30232 \InsetSpace ~
30233 \InsetSpace ~
30234 \InsetSpace ~
30235 \InsetSpace ~
30236 \InsetSpace ~
30237 \InsetSpace ~
30238 \InsetSpace ~
30239 \InsetSpace ~
30240 \InsetSpace ~
30241 \InsetSpace ~
30242 \InsetSpace ~
30243 \InsetSpace ~
30244 \InsetSpace ~
30245 \InsetSpace ~
30246 \InsetSpace ~
30247 \InsetSpace ~
30248 \InsetSpace ~
30249 \InsetSpace ~
30250 \InsetSpace ~
30251 \InsetSpace ~
30252 \InsetSpace ~
30253 \InsetSpace ~
30254 \InsetSpace ~
30255 \InsetSpace ~
30256 \InsetSpace ~
30257 \InsetSpace ~
30258 \InsetSpace ~
30259 \InsetSpace ~
30260 \InsetSpace ~
30261 \InsetSpace ~
30262 \InsetSpace ~
30263 \InsetSpace ~
30264 \InsetSpace ~
30265 \InsetSpace ~
30266 \InsetSpace ~
30267 \InsetSpace ~
30268 buffer point 
30269 \newline
30270 ;;\InsetSpace ~
30271 g\InsetSpace ~
30272 \InsetSpace ~
30273 \InsetSpace ~
30274 \InsetSpace ~
30275 \InsetSpace ~
30276 \InsetSpace ~
30277 \InsetSpace ~
30278 \InsetSpace ~
30279 \InsetSpace ~
30280 \InsetSpace ~
30281 \InsetSpace ~
30282 \InsetSpace ~
30283 \InsetSpace ~
30284 \InsetSpace ~
30285 \InsetSpace ~
30286 sdcdbsrc-goto-sdcdb\InsetSpace ~
30287 \InsetSpace ~
30288 \InsetSpace ~
30289 \InsetSpace ~
30290 \InsetSpace ~
30291 \InsetSpace ~
30292 \InsetSpace ~
30293 \InsetSpace ~
30294 \InsetSpace ~
30295 \InsetSpace ~
30296 Got
30297 o the SDCDB output buffer 
30298 \newline
30299 ;;\InsetSpace ~
30300 t\InsetSpace ~
30301 \InsetSpace ~
30302 \InsetSpace ~
30303 \InsetSpace ~
30304 \InsetSpace ~
30305 \InsetSpace ~
30306 \InsetSpace ~
30307 \InsetSpace ~
30308 \InsetSpace ~
30309 \InsetSpace ~
30310 \InsetSpace ~
30311 \InsetSpace ~
30312 \InsetSpace ~
30313 \InsetSpace ~
30314 \InsetSpace ~
30315 sdcdbsrc-mode\InsetSpace ~
30316 \InsetSpace ~
30317 \InsetSpace ~
30318 \InsetSpace ~
30319 \InsetSpace ~
30320 \InsetSpace ~
30321 \InsetSpace ~
30322 \InsetSpace ~
30323 \InsetSpace ~
30324 \InsetSpace ~
30325 \InsetSpace ~
30326 \InsetSpace ~
30327 \InsetSpace ~
30328 \InsetSpace ~
30329 \InsetSpace ~
30330 \InsetSpace ~
30331 Toggles Sdcdbsrc mode (turns it
30332  off) 
30333 \newline
30334 ;; 
30335 \newline
30336 ;;\InsetSpace ~
30337 C-c\InsetSpace ~
30338 C-f\InsetSpace ~
30339 \InsetSpace ~
30340 \InsetSpace ~
30341 \InsetSpace ~
30342 \InsetSpace ~
30343 \InsetSpace ~
30344 \InsetSpace ~
30345 \InsetSpace ~
30346 \InsetSpace ~
30347 sdcdb-finish-from-src\InsetSpace ~
30348 \InsetSpace ~
30349 \InsetSpace ~
30350 \InsetSpace ~
30351 \InsetSpace ~
30352 \InsetSpace ~
30353 \InsetSpace ~
30354 \InsetSpace ~
30355 SDCDB finish command 
30356 \newline
30357 ;; 
30358 \newline
30359 ;;\InsetSpace ~
30360 C-x\InsetSpace ~
30361 SPC\InsetSpace ~
30362 \InsetSpace ~
30363 \InsetSpace ~
30364 \InsetSpace ~
30365 \InsetSpace ~
30366 \InsetSpace ~
30367 \InsetSpace ~
30368 \InsetSpace ~
30369 \InsetSpace ~
30370 sdcdb-brea
30371 k\InsetSpace ~
30372 \InsetSpace ~
30373 \InsetSpace ~
30374 \InsetSpace ~
30375 \InsetSpace ~
30376 \InsetSpace ~
30377 \InsetSpace ~
30378 \InsetSpace ~
30379 \InsetSpace ~
30380 \InsetSpace ~
30381 \InsetSpace ~
30382 \InsetSpace ~
30383 \InsetSpace ~
30384 \InsetSpace ~
30385 \InsetSpace ~
30386 \InsetSpace ~
30387 \InsetSpace ~
30388 \InsetSpace ~
30389 Set break for line with point 
30390 \newline
30391 ;;\InsetSpace ~
30392 ESC\InsetSpace ~
30393 t\InsetSpace ~
30394 \InsetSpace ~
30395 \InsetSpace ~
30396 \InsetSpace ~
30397 \InsetSpace ~
30398 \InsetSpace ~
30399 \InsetSpace ~
30400 \InsetSpace ~
30401 \InsetSpace ~
30402 \InsetSpace ~
30403 \InsetSpace ~
30404 sdcdbsrc-mode\InsetSpace ~
30405 \InsetSpace ~
30406 \InsetSpace ~
30407 \InsetSpace ~
30408 \InsetSpace ~
30409 \InsetSpace ~
30410 \InsetSpace ~
30411 \InsetSpace ~
30412 \InsetSpace ~
30413 \InsetSpace ~
30414 \InsetSpace ~
30415 \InsetSpace ~
30416 \InsetSpace ~
30417 \InsetSpace ~
30418 \InsetSpace ~
30419 \InsetSpace ~
30420 Toggle Sdcdbsrc mode 
30421 \newline
30422 ;;\InsetSpace ~
30423 ESC\InsetSpace ~
30424 m\InsetSpace ~
30425 \InsetSpace ~
30426 \InsetSpace ~
30427 \InsetSpace ~
30428 \InsetSpace ~
30429 \InsetSpace ~
30430 \InsetSpace ~
30431 \InsetSpace ~
30432 \InsetSpace ~
30433 \InsetSpace ~
30434 \InsetSpace ~
30435 sdc
30436 dbsrc-srcmode\InsetSpace ~
30437 \InsetSpace ~
30438 \InsetSpace ~
30439 \InsetSpace ~
30440 \InsetSpace ~
30441 \InsetSpace ~
30442 \InsetSpace ~
30443 \InsetSpace ~
30444 \InsetSpace ~
30445 \InsetSpace ~
30446 \InsetSpace ~
30447 \InsetSpace ~
30448 \InsetSpace ~
30449 Toggle list mode 
30450 \newline
30451 ;; 
30452 \newline
30453
30454 \family default
30455
30456 \newpage
30457
30458 \end_layout
30459
30460 \begin_layout Chapter
30461 TIPS
30462 \end_layout
30463
30464 \begin_layout Standard
30465 Here are a few guidelines that will help the compiler generate more efficient
30466  code, some of the tips are specific to this compiler others are generally
30467  good programming practice.
30468 \end_layout
30469
30470 \begin_layout Itemize
30471 Use the smallest data type to represent your data-value.
30472  If it is known in advance that the value is going to be less than 256 then
30473  use an 'unsigned char' instead of a 'short' or 'int'.
30474  Please note, that ANSI C requires both signed and unsigned chars to be
30475  promoted to 'signed int'
30476 \begin_inset LatexCommand \index{promotion to signed int}
30477
30478 \end_inset
30479
30480
30481 \begin_inset Marginal
30482 status collapsed
30483
30484 \begin_layout Standard
30485
30486 \series bold
30487 \InsetSpace ~
30488 !
30489 \end_layout
30490
30491 \end_inset
30492
30493  before doing any operation.
30494  This promotion
30495 \begin_inset LatexCommand \index{type promotion}
30496
30497 \end_inset
30498
30499
30500 \begin_inset LatexCommand \label{type promotion}
30501
30502 \end_inset
30503
30504  can be omitted, if the result is the same.
30505  The effect of the promotion rules together with the sign-extension is often
30506  surprising:
30507 \end_layout
30508
30509 \begin_deeper
30510 \begin_layout Verse
30511
30512 \family typewriter
30513 unsigned char uc = 0xfe;
30514 \newline
30515 if (uc * uc < 0) /* this is true! */
30516 \newline
30517 {
30518 \newline
30519 \InsetSpace ~
30520 \InsetSpace ~
30521 \InsetSpace ~
30522 \InsetSpace ~
30523 ....
30524 \newline
30525 }
30526 \end_layout
30527
30528 \begin_layout Standard
30529
30530 \family typewriter
30531 uc * uc
30532 \family default
30533  is evaluated as 
30534 \family typewriter
30535 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30536 \family default
30537 .
30538  
30539 \newline
30540 Another one:
30541 \end_layout
30542
30543 \begin_layout Verse
30544
30545 \family typewriter
30546 (unsigned char) -12 / (signed char) -3 = ...
30547 \end_layout
30548
30549 \begin_layout Standard
30550 No, the result is not 4:
30551 \end_layout
30552
30553 \begin_layout Verse
30554
30555 \family typewriter
30556 (int) (unsigned char) -12 / (int) (signed char) -3 =
30557 \newline
30558 (int) (unsigned char)
30559  0xf4 / (int) (signed char) 0xfd =
30560 \newline
30561 (int) 0x00f4 / (int) 0xfffd =
30562 \newline
30563 (int) 0x00f4
30564  / (int) 0xfffd =
30565 \newline
30566 (int) 244 / (int) -3 =
30567 \newline
30568 (int) -81 = (int) 0xffaf;
30569 \end_layout
30570
30571 \begin_layout Standard
30572 Don't complain, that gcc gives you a different result.
30573  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30574  Therefore the results are different.
30575 \newline
30576 From 
30577 \begin_inset Quotes sld
30578 \end_inset
30579
30580 comp.lang.c FAQ
30581 \begin_inset Quotes srd
30582 \end_inset
30583
30584 :
30585 \end_layout
30586
30587 \begin_layout Quote
30588
30589 \emph on
30590 If well-defined overflow characteristics are important and negative values
30591  are not, or if you want to steer clear of sign-extension problems when
30592  manipulating bits or bytes, use one of the corresponding unsigned types.
30593  (Beware when mixing signed and unsigned values in expressions, though.)
30594 \newline
30595 Although
30596  character types (especially unsigned char) can be used as "tiny" integers,
30597  doing so is sometimes more trouble than it's worth, due to unpredictable
30598  sign extension and increased code size.
30599 \end_layout
30600
30601 \end_deeper
30602 \begin_layout Itemize
30603 Use unsigned when it is known in advance that the value is not going to
30604  be negative.
30605  This helps especially if you are doing division or multiplication, bit-shifting
30606  or are using an array index.
30607 \end_layout
30608
30609 \begin_layout Itemize
30610 NEVER jump into a LOOP.
30611 \end_layout
30612
30613 \begin_layout Itemize
30614 Declare the variables to be local
30615 \begin_inset LatexCommand \index{local variables}
30616
30617 \end_inset
30618
30619  whenever possible, especially loop control variables (induction).
30620 \end_layout
30621
30622 \begin_layout Itemize
30623 Have a look at the assembly listing to get a 
30624 \begin_inset Quotes sld
30625 \end_inset
30626
30627 feeling
30628 \begin_inset Quotes srd
30629 \end_inset
30630
30631  for the code generation.
30632 \end_layout
30633
30634 \begin_layout Section
30635 Porting code from or to other compilers
30636 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30637
30638 \end_inset
30639
30640
30641 \end_layout
30642
30643 \begin_layout Itemize
30644 check whether endianness of the compilers differs and adapt where needed.
30645 \end_layout
30646
30647 \begin_layout Itemize
30648 check the device specific header files
30649 \begin_inset LatexCommand \index{Header files}
30650
30651 \end_inset
30652
30653
30654 \begin_inset LatexCommand \index{Include files}
30655
30656 \end_inset
30657
30658  for compiler specific syntax.
30659  Eventually include the file <compiler.h
30660 \begin_inset LatexCommand \index{compiler.h (include file)}
30661
30662 \end_inset
30663
30664
30665 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30666
30667 \end_inset
30668
30669  to allow using common header files.
30670  (see f.e.
30671  cc2510fx.h 
30672 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30673
30674 \end_inset
30675
30676 ).
30677 \end_layout
30678
30679 \begin_layout Itemize
30680 check whether the startup code contains the correct initialization (watchdog,
30681  peripherals).
30682 \end_layout
30683
30684 \begin_layout Itemize
30685 check whether the sizes of short, int, long match.
30686 \end_layout
30687
30688 \begin_layout Itemize
30689 check if some 16 or 32 bit hardware registers require a specific addressing
30690  order (least significant or most significant byte first) and adapt if needed
30691  (
30692 \emph on
30693 first
30694 \emph default
30695  and 
30696 \emph on
30697 last
30698 \emph default
30699  relate to time and not to lower/upper memory location here, so this is
30700  
30701 \emph on
30702 not
30703 \emph default
30704  the same as endianness).
30705 \end_layout
30706
30707 \begin_layout Itemize
30708 check whether the keyword 
30709 \emph on
30710 volatile
30711 \emph default
30712  is used where needed.
30713  The compilers might differ in their optimization characteristics (as different
30714  versions of the same compiler might also use more clever optimizations
30715  this is good idea anyway).
30716  See section 
30717 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30718
30719 \end_inset
30720
30721 .
30722 \end_layout
30723
30724 \begin_layout Itemize
30725 check that the compilers are not told to supress warnings.
30726 \end_layout
30727
30728 \begin_layout Itemize
30729 check and convert compiler specific extensions (interrupts, memory areas,
30730  pragmas etc.).
30731 \end_layout
30732
30733 \begin_layout Itemize
30734 check for differences in type promotion.
30735  Especially check for math operations on 
30736 \family typewriter
30737 char
30738 \family default
30739  or 
30740 \family typewriter
30741 unsigned char
30742 \family default
30743  variables.
30744  For the sake of C99 compatibility SDCC will probably promote these to 
30745 \family typewriter
30746 int
30747 \family default
30748  more often than other compilers.
30749  Eventually insert explicit casts to 
30750 \family typewriter
30751 (char) 
30752 \family default
30753 or
30754 \family typewriter
30755  (unsigned char)
30756 \family default
30757 .
30758  Also check that the ~\InsetSpace ~
30759 operator
30760 \begin_inset LatexCommand \index{\~\/ Operator}
30761
30762 \end_inset
30763
30764  is not used on 
30765 \family typewriter
30766 bit
30767 \begin_inset LatexCommand \index{bit}
30768
30769 \end_inset
30770
30771
30772 \family default
30773  variables, use the !\InsetSpace ~
30774 operator instead.
30775  See sections 
30776 \begin_inset LatexCommand \ref{type promotion}
30777
30778 \end_inset
30779
30780  and 
30781 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30782
30783 \end_inset
30784
30785 .
30786 \end_layout
30787
30788 \begin_layout Itemize
30789 check the assembly code generated for interrupt routines (f.e.
30790  for calls to possibly non-reentrant library functions).
30791 \end_layout
30792
30793 \begin_layout Itemize
30794 check whether timing loops result in proper timing (or preferably consider
30795  a rewrite of the code with timer based delays instead).
30796 \end_layout
30797
30798 \begin_layout Itemize
30799 check for differences in printf parameters (some compilers push (va_arg
30800 \begin_inset LatexCommand \index{vararg, va\_arg}
30801
30802 \end_inset
30803
30804 ) char variables as 
30805 \family typewriter
30806 int
30807 \family default
30808  others push them as 
30809 \family typewriter
30810 char
30811 \family default
30812 .
30813  See section 
30814 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30815
30816 \end_inset
30817
30818 ).
30819 \end_layout
30820
30821 \begin_layout Itemize
30822 check the resulting memory map
30823 \begin_inset LatexCommand \index{Memory map}
30824
30825 \end_inset
30826
30827 .
30828  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30829 ly idata, pdata, xdata).
30830  Eventually check if unexpected library functions are included.
30831 \end_layout
30832
30833 \begin_layout Section
30834 Tools
30835 \begin_inset LatexCommand \index{Tools}
30836
30837 \end_inset
30838
30839  included in the distribution
30840 \end_layout
30841
30842 \begin_layout Standard
30843 \align left
30844 \begin_inset Tabular
30845 <lyxtabular version="3" rows="12" columns="3">
30846 <features>
30847 <column alignment="left" valignment="top" leftline="true" width="0pt">
30848 <column alignment="left" valignment="top" leftline="true" width="0pt">
30849 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30850 <row topline="true" bottomline="true">
30851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30852 \begin_inset Text
30853
30854 \begin_layout Standard
30855
30856 \series bold
30857 Name
30858 \end_layout
30859
30860 \end_inset
30861 </cell>
30862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30863 \begin_inset Text
30864
30865 \begin_layout Standard
30866
30867 \series bold
30868 Purpose
30869 \end_layout
30870
30871 \end_inset
30872 </cell>
30873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30874 \begin_inset Text
30875
30876 \begin_layout Standard
30877
30878 \series bold
30879 Directory
30880 \end_layout
30881
30882 \end_inset
30883 </cell>
30884 </row>
30885 <row topline="true">
30886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30887 \begin_inset Text
30888
30889 \begin_layout Standard
30890 uCsim
30891 \begin_inset LatexCommand \index{uCsim}
30892
30893 \end_inset
30894
30895
30896 \end_layout
30897
30898 \end_inset
30899 </cell>
30900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30901 \begin_inset Text
30902
30903 \begin_layout Standard
30904 Simulator for various architectures
30905 \end_layout
30906
30907 \end_inset
30908 </cell>
30909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30910 \begin_inset Text
30911
30912 \begin_layout Standard
30913 sdcc/sim/ucsim
30914 \end_layout
30915
30916 \end_inset
30917 </cell>
30918 </row>
30919 <row topline="true">
30920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30921 \begin_inset Text
30922
30923 \begin_layout Standard
30924 keil2sdcc.pl
30925 \end_layout
30926
30927 \end_inset
30928 </cell>
30929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30930 \begin_inset Text
30931
30932 \begin_layout Standard
30933 header file
30934 \begin_inset LatexCommand \index{Header files}
30935
30936 \end_inset
30937
30938
30939 \begin_inset LatexCommand \index{Include files}
30940
30941 \end_inset
30942
30943  conversion
30944 \end_layout
30945
30946 \end_inset
30947 </cell>
30948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30949 \begin_inset Text
30950
30951 \begin_layout Standard
30952 sdcc/support/scripts
30953 \end_layout
30954
30955 \end_inset
30956 </cell>
30957 </row>
30958 <row topline="true">
30959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30960 \begin_inset Text
30961
30962 \begin_layout Standard
30963 mh2h.c
30964 \end_layout
30965
30966 \end_inset
30967 </cell>
30968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30969 \begin_inset Text
30970
30971 \begin_layout Standard
30972 header file conversion
30973 \end_layout
30974
30975 \end_inset
30976 </cell>
30977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30978 \begin_inset Text
30979
30980 \begin_layout Standard
30981 sdcc/support/scripts
30982 \end_layout
30983
30984 \end_inset
30985 </cell>
30986 </row>
30987 <row topline="true">
30988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30989 \begin_inset Text
30990
30991 \begin_layout Standard
30992 as-gbz80
30993 \end_layout
30994
30995 \end_inset
30996 </cell>
30997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30998 \begin_inset Text
30999
31000 \begin_layout Standard
31001 Assembler
31002 \end_layout
31003
31004 \end_inset
31005 </cell>
31006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31007 \begin_inset Text
31008
31009 \begin_layout Standard
31010
31011 \family roman
31012 \series medium
31013 \shape up
31014 \size normal
31015 \emph off
31016 \bar no
31017 \noun off
31018 \color none
31019 sdcc/bin
31020 \end_layout
31021
31022 \end_inset
31023 </cell>
31024 </row>
31025 <row topline="true">
31026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31027 \begin_inset Text
31028
31029 \begin_layout Standard
31030 as-z80
31031 \end_layout
31032
31033 \end_inset
31034 </cell>
31035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31036 \begin_inset Text
31037
31038 \begin_layout Standard
31039 Assembler
31040 \end_layout
31041
31042 \end_inset
31043 </cell>
31044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31045 \begin_inset Text
31046
31047 \begin_layout Standard
31048
31049 \family roman
31050 \series medium
31051 \shape up
31052 \size normal
31053 \emph off
31054 \bar no
31055 \noun off
31056 \color none
31057 sdcc/bin
31058 \end_layout
31059
31060 \end_inset
31061 </cell>
31062 </row>
31063 <row topline="true">
31064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31065 \begin_inset Text
31066
31067 \begin_layout Standard
31068 asx8051
31069 \end_layout
31070
31071 \end_inset
31072 </cell>
31073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31074 \begin_inset Text
31075
31076 \begin_layout Standard
31077 Assembler
31078 \end_layout
31079
31080 \end_inset
31081 </cell>
31082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31083 \begin_inset Text
31084
31085 \begin_layout Standard
31086
31087 \family roman
31088 \series medium
31089 \shape up
31090 \size normal
31091 \emph off
31092 \bar no
31093 \noun off
31094 \color none
31095 sdcc/bin
31096 \end_layout
31097
31098 \end_inset
31099 </cell>
31100 </row>
31101 <row topline="true">
31102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31103 \begin_inset Text
31104
31105 \begin_layout Standard
31106 SDCDB
31107 \end_layout
31108
31109 \end_inset
31110 </cell>
31111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31112 \begin_inset Text
31113
31114 \begin_layout Standard
31115 Simulator
31116 \end_layout
31117
31118 \end_inset
31119 </cell>
31120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31121 \begin_inset Text
31122
31123 \begin_layout Standard
31124
31125 \family roman
31126 \series medium
31127 \shape up
31128 \size normal
31129 \emph off
31130 \bar no
31131 \noun off
31132 \color none
31133 sdcc/bin
31134 \end_layout
31135
31136 \end_inset
31137 </cell>
31138 </row>
31139 <row topline="true">
31140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31141 \begin_inset Text
31142
31143 \begin_layout Standard
31144 aslink
31145 \end_layout
31146
31147 \end_inset
31148 </cell>
31149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31150 \begin_inset Text
31151
31152 \begin_layout Standard
31153 Linker
31154 \end_layout
31155
31156 \end_inset
31157 </cell>
31158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31159 \begin_inset Text
31160
31161 \begin_layout Standard
31162
31163 \family roman
31164 \series medium
31165 \shape up
31166 \size normal
31167 \emph off
31168 \bar no
31169 \noun off
31170 \color none
31171 sdcc/bin
31172 \end_layout
31173
31174 \end_inset
31175 </cell>
31176 </row>
31177 <row topline="true">
31178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31179 \begin_inset Text
31180
31181 \begin_layout Standard
31182 link-z80
31183 \end_layout
31184
31185 \end_inset
31186 </cell>
31187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31188 \begin_inset Text
31189
31190 \begin_layout Standard
31191 Linker
31192 \end_layout
31193
31194 \end_inset
31195 </cell>
31196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31197 \begin_inset Text
31198
31199 \begin_layout Standard
31200
31201 \family roman
31202 \series medium
31203 \shape up
31204 \size normal
31205 \emph off
31206 \bar no
31207 \noun off
31208 \color none
31209 sdcc/bin
31210 \end_layout
31211
31212 \end_inset
31213 </cell>
31214 </row>
31215 <row topline="true">
31216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31217 \begin_inset Text
31218
31219 \begin_layout Standard
31220 link-gbz80
31221 \end_layout
31222
31223 \end_inset
31224 </cell>
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31226 \begin_inset Text
31227
31228 \begin_layout Standard
31229 Linker
31230 \end_layout
31231
31232 \end_inset
31233 </cell>
31234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31235 \begin_inset Text
31236
31237 \begin_layout Standard
31238
31239 \family roman
31240 \series medium
31241 \shape up
31242 \size normal
31243 \emph off
31244 \bar no
31245 \noun off
31246 \color none
31247 sdcc/bin
31248 \end_layout
31249
31250 \end_inset
31251 </cell>
31252 </row>
31253 <row topline="true" bottomline="true">
31254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31255 \begin_inset Text
31256
31257 \begin_layout Standard
31258 packihx
31259 \end_layout
31260
31261 \end_inset
31262 </cell>
31263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31264 \begin_inset Text
31265
31266 \begin_layout Standard
31267 Intel Hex packer 
31268 \begin_inset LatexCommand \index{packihx (tool)}
31269
31270 \end_inset
31271
31272
31273 \end_layout
31274
31275 \end_inset
31276 </cell>
31277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31278 \begin_inset Text
31279
31280 \begin_layout Standard
31281
31282 \family roman
31283 \series medium
31284 \shape up
31285 \size normal
31286 \emph off
31287 \bar no
31288 \noun off
31289 \color none
31290 sdcc/bin
31291 \end_layout
31292
31293 \end_inset
31294 </cell>
31295 </row>
31296 </lyxtabular>
31297
31298 \end_inset
31299
31300
31301 \newline
31302
31303 \end_layout
31304
31305 \begin_layout Section
31306 Documentation
31307 \begin_inset LatexCommand \index{Documentation}
31308
31309 \end_inset
31310
31311  included in the distribution
31312 \end_layout
31313
31314 \begin_layout Standard
31315 \align left
31316 \begin_inset Tabular
31317 <lyxtabular version="3" rows="10" columns="2">
31318 <features>
31319 <column alignment="block" valignment="top" leftline="true" width="40col%">
31320 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31321 <row topline="true" bottomline="true" endhead="true">
31322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31323 \begin_inset Text
31324
31325 \begin_layout Standard
31326
31327 \series bold
31328 Subject / Title
31329 \end_layout
31330
31331 \end_inset
31332 </cell>
31333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31334 \begin_inset Text
31335
31336 \begin_layout Standard
31337
31338 \series bold
31339 Filename / Where to get
31340 \end_layout
31341
31342 \end_inset
31343 </cell>
31344 </row>
31345 <row topline="true">
31346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31347 \begin_inset Text
31348
31349 \begin_layout Standard
31350 SDCC Compiler User Guide
31351 \end_layout
31352
31353 \end_inset
31354 </cell>
31355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31356 \begin_inset Text
31357
31358 \begin_layout Standard
31359 You're reading it right now
31360 \emph on
31361  \InsetSpace ~
31362 \InsetSpace ~
31363 \InsetSpace ~
31364
31365 \hfill
31366 online at:
31367 \emph default
31368
31369 \newline
31370
31371 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31372
31373 \end_inset
31374
31375
31376 \end_layout
31377
31378 \end_inset
31379 </cell>
31380 </row>
31381 <row topline="true">
31382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31383 \begin_inset Text
31384
31385 \begin_layout Standard
31386 Changelog of SDCC
31387 \end_layout
31388
31389 \end_inset
31390 </cell>
31391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31392 \begin_inset Text
31393
31394 \begin_layout Standard
31395 sdcc/Changelog
31396 \emph on
31397  \InsetSpace ~
31398 \InsetSpace ~
31399 \InsetSpace ~
31400
31401 \hfill
31402 online at:
31403 \emph default
31404
31405 \newline
31406
31407 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31408
31409 \end_inset
31410
31411
31412 \end_layout
31413
31414 \end_inset
31415 </cell>
31416 </row>
31417 <row topline="true">
31418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31419 \begin_inset Text
31420
31421 \begin_layout Standard
31422 ASXXXX
31423 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31424
31425 \end_inset
31426
31427
31428 \begin_inset LatexCommand \index{Assembler documentation}
31429
31430 \end_inset
31431
31432  Assemblers and
31433 \newline
31434 ASLINK
31435 \begin_inset LatexCommand \index{aslink}
31436
31437 \end_inset
31438
31439
31440 \begin_inset LatexCommand \index{Linker documentation}
31441
31442 \end_inset
31443
31444  Relocating Linker
31445 \end_layout
31446
31447 \end_inset
31448 </cell>
31449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31450 \begin_inset Text
31451
31452 \begin_layout Standard
31453 sdcc/as/doc/asxhtm.html 
31454 \emph on
31455 \InsetSpace ~
31456 \InsetSpace ~
31457 \InsetSpace ~
31458
31459 \hfill
31460 online at:
31461 \emph default
31462
31463 \newline
31464
31465 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31466
31467 \end_inset
31468
31469
31470 \end_layout
31471
31472 \end_inset
31473 </cell>
31474 </row>
31475 <row topline="true">
31476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31477 \begin_inset Text
31478
31479 \begin_layout Standard
31480 SDCC regression test
31481 \begin_inset LatexCommand \index{Regression test}
31482
31483 \end_inset
31484
31485
31486 \end_layout
31487
31488 \end_inset
31489 </cell>
31490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31491 \begin_inset Text
31492
31493 \begin_layout Standard
31494 sdcc/doc/test_suite_spec.pdf 
31495 \emph on
31496 \InsetSpace ~
31497 \InsetSpace ~
31498 \InsetSpace ~
31499
31500 \hfill
31501 online at:
31502 \emph default
31503
31504 \newline
31505
31506 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31507
31508 \end_inset
31509
31510
31511 \end_layout
31512
31513 \end_inset
31514 </cell>
31515 </row>
31516 <row topline="true">
31517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31518 \begin_inset Text
31519
31520 \begin_layout Standard
31521 Various notes
31522 \end_layout
31523
31524 \end_inset
31525 </cell>
31526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31527 \begin_inset Text
31528
31529 \begin_layout Standard
31530 sdcc/doc/* 
31531 \emph on
31532 \InsetSpace ~
31533 \InsetSpace ~
31534 \InsetSpace ~
31535
31536 \hfill
31537 online at:
31538 \emph default
31539
31540 \newline
31541
31542 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31543
31544 \end_inset
31545
31546
31547 \end_layout
31548
31549 \end_inset
31550 </cell>
31551 </row>
31552 <row topline="true">
31553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31554 \begin_inset Text
31555
31556 \begin_layout Standard
31557 Notes on debugging with SDCDB
31558 \begin_inset LatexCommand \index{SDCDB (debugger)}
31559
31560 \end_inset
31561
31562
31563 \end_layout
31564
31565 \end_inset
31566 </cell>
31567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31568 \begin_inset Text
31569
31570 \begin_layout Standard
31571 sdcc/debugger/README 
31572 \emph on
31573 \InsetSpace ~
31574 \InsetSpace ~
31575 \InsetSpace ~
31576
31577 \hfill
31578 online at
31579 \emph default
31580 :
31581 \newline
31582
31583 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31584
31585 \end_inset
31586
31587
31588 \end_layout
31589
31590 \end_inset
31591 </cell>
31592 </row>
31593 <row topline="true">
31594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31595 \begin_inset Text
31596
31597 \begin_layout Standard
31598 uCsim
31599 \begin_inset LatexCommand \index{uCsim}
31600
31601 \end_inset
31602
31603  Software simulator for microcontrollers
31604 \end_layout
31605
31606 \end_inset
31607 </cell>
31608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31609 \begin_inset Text
31610
31611 \begin_layout Standard
31612
31613 \family roman
31614 \series medium
31615 \shape up
31616 \size normal
31617 \emph off
31618 \bar no
31619 \noun off
31620 \color none
31621 sdcc/sim/ucsim/doc
31622 \family default
31623 \series default
31624 \shape default
31625 \size default
31626 \emph default
31627 \bar default
31628 \noun default
31629 /index.html 
31630 \emph on
31631 \InsetSpace ~
31632 \InsetSpace ~
31633 \InsetSpace ~
31634
31635 \hfill
31636 online at:
31637 \emph default
31638
31639 \newline
31640
31641 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31642
31643 \end_inset
31644
31645
31646 \end_layout
31647
31648 \end_inset
31649 </cell>
31650 </row>
31651 <row topline="true">
31652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31653 \begin_inset Text
31654
31655 \begin_layout Standard
31656 Temporary notes on the pic16
31657 \begin_inset LatexCommand \index{PIC16}
31658
31659 \end_inset
31660
31661  port
31662 \end_layout
31663
31664 \end_inset
31665 </cell>
31666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31667 \begin_inset Text
31668
31669 \begin_layout Standard
31670 sdcc/src/pic16/NOTES 
31671 \emph on
31672 \InsetSpace ~
31673 \InsetSpace ~
31674 \InsetSpace ~
31675
31676 \hfill
31677 online at:
31678 \newline
31679
31680 \emph default
31681
31682 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31683
31684 \end_inset
31685
31686
31687 \end_layout
31688
31689 \end_inset
31690 </cell>
31691 </row>
31692 <row topline="true" bottomline="true">
31693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31694 \begin_inset Text
31695
31696 \begin_layout Standard
31697 SDCC internal documentation (debugging file format)
31698 \end_layout
31699
31700 \end_inset
31701 </cell>
31702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31703 \begin_inset Text
31704
31705 \begin_layout Standard
31706 sdcc/doc/
31707 \family roman
31708 \series medium
31709 \shape up
31710 \size normal
31711 \emph off
31712 \bar no
31713 \noun off
31714 \color none
31715 cdbfileformat.pd
31716 \family default
31717 \series default
31718 \shape default
31719 \size default
31720 \emph default
31721 \bar default
31722 \noun default
31723 f
31724 \emph on
31725  \InsetSpace ~
31726 \InsetSpace ~
31727 \InsetSpace ~
31728
31729 \hfill
31730 online at:
31731 \emph default
31732
31733 \newline
31734
31735 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31736
31737 \end_inset
31738
31739
31740 \end_layout
31741
31742 \end_inset
31743 </cell>
31744 </row>
31745 </lyxtabular>
31746
31747 \end_inset
31748
31749
31750 \newline
31751
31752 \end_layout
31753
31754 \begin_layout Section
31755 Related open source tools
31756 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31757
31758 \end_inset
31759
31760
31761 \begin_inset LatexCommand \index{Related tools}
31762
31763 \end_inset
31764
31765
31766 \end_layout
31767
31768 \begin_layout Standard
31769 \align left
31770 \begin_inset Tabular
31771 <lyxtabular version="3" rows="16" columns="3">
31772 <features>
31773 <column alignment="left" valignment="top" leftline="true" width="0pt">
31774 <column alignment="block" valignment="top" leftline="true" width="30line%">
31775 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31776 <row topline="true" bottomline="true">
31777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31778 \begin_inset Text
31779
31780 \begin_layout Standard
31781
31782 \series bold
31783 Name
31784 \end_layout
31785
31786 \end_inset
31787 </cell>
31788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31789 \begin_inset Text
31790
31791 \begin_layout Standard
31792
31793 \series bold
31794 Purpose
31795 \end_layout
31796
31797 \end_inset
31798 </cell>
31799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31800 \begin_inset Text
31801
31802 \begin_layout Standard
31803
31804 \series bold
31805 Where to get
31806 \end_layout
31807
31808 \end_inset
31809 </cell>
31810 </row>
31811 <row topline="true">
31812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31813 \begin_inset Text
31814
31815 \begin_layout Standard
31816 gpsim
31817 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31818
31819 \end_inset
31820
31821
31822 \end_layout
31823
31824 \end_inset
31825 </cell>
31826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31827 \begin_inset Text
31828
31829 \begin_layout Standard
31830 PIC simulator
31831 \end_layout
31832
31833 \end_inset
31834 </cell>
31835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31836 \begin_inset Text
31837
31838 \begin_layout Standard
31839 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31840
31841 \end_inset
31842
31843
31844 \end_layout
31845
31846 \end_inset
31847 </cell>
31848 </row>
31849 <row topline="true">
31850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31851 \begin_inset Text
31852
31853 \begin_layout Standard
31854 gputils
31855 \begin_inset LatexCommand \index{gputils (pic tools)}
31856
31857 \end_inset
31858
31859
31860 \end_layout
31861
31862 \end_inset
31863 </cell>
31864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31865 \begin_inset Text
31866
31867 \begin_layout Standard
31868 GNU PIC utilities
31869 \end_layout
31870
31871 \end_inset
31872 </cell>
31873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31874 \begin_inset Text
31875
31876 \begin_layout Standard
31877 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31878
31879 \end_inset
31880
31881
31882 \end_layout
31883
31884 \end_inset
31885 </cell>
31886 </row>
31887 <row topline="true">
31888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31889 \begin_inset Text
31890
31891 \begin_layout Standard
31892 flP5
31893 \end_layout
31894
31895 \end_inset
31896 </cell>
31897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31898 \begin_inset Text
31899
31900 \begin_layout Standard
31901 PIC programmer
31902 \end_layout
31903
31904 \end_inset
31905 </cell>
31906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31907 \begin_inset Text
31908
31909 \begin_layout Standard
31910 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31911
31912 \end_inset
31913
31914
31915 \end_layout
31916
31917 \end_inset
31918 </cell>
31919 </row>
31920 <row topline="true">
31921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31922 \begin_inset Text
31923
31924 \begin_layout Standard
31925 ec2drv/newcdb
31926 \end_layout
31927
31928 \end_inset
31929 </cell>
31930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31931 \begin_inset Text
31932
31933 \begin_layout Standard
31934 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31935  (Unix only)
31936 \end_layout
31937
31938 \end_inset
31939 </cell>
31940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31941 \begin_inset Text
31942
31943 \begin_layout Standard
31944 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31945
31946 \end_inset
31947
31948
31949 \end_layout
31950
31951 \end_inset
31952 </cell>
31953 </row>
31954 <row topline="true">
31955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31956 \begin_inset Text
31957
31958 \begin_layout Standard
31959 indent
31960 \begin_inset LatexCommand \index{indent (source formatting tool)}
31961
31962 \end_inset
31963
31964
31965 \end_layout
31966
31967 \end_inset
31968 </cell>
31969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31970 \begin_inset Text
31971
31972 \begin_layout Standard
31973 Formats C source - Master of the white spaces
31974 \end_layout
31975
31976 \end_inset
31977 </cell>
31978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31979 \begin_inset Text
31980
31981 \begin_layout Standard
31982 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31983
31984 \end_inset
31985
31986
31987 \end_layout
31988
31989 \end_inset
31990 </cell>
31991 </row>
31992 <row topline="true">
31993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31994 \begin_inset Text
31995
31996 \begin_layout Standard
31997 srecord
31998 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31999
32000 \end_inset
32001
32002
32003 \end_layout
32004
32005 \end_inset
32006 </cell>
32007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32008 \begin_inset Text
32009
32010 \begin_layout Standard
32011 Object file conversion, checksumming, ...
32012 \end_layout
32013
32014 \end_inset
32015 </cell>
32016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32017 \begin_inset Text
32018
32019 \begin_layout Standard
32020 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
32021
32022 \end_inset
32023
32024
32025 \end_layout
32026
32027 \end_inset
32028 </cell>
32029 </row>
32030 <row topline="true">
32031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32032 \begin_inset Text
32033
32034 \begin_layout Standard
32035 objdump
32036 \begin_inset LatexCommand \index{objdump (tool)}
32037
32038 \end_inset
32039
32040
32041 \end_layout
32042
32043 \end_inset
32044 </cell>
32045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32046 \begin_inset Text
32047
32048 \begin_layout Standard
32049 Object file conversion, ...
32050 \end_layout
32051
32052 \end_inset
32053 </cell>
32054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32055 \begin_inset Text
32056
32057 \begin_layout Standard
32058 Part of binutils (should be there anyway)
32059 \end_layout
32060
32061 \end_inset
32062 </cell>
32063 </row>
32064 <row topline="true">
32065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32066 \begin_inset Text
32067
32068 \begin_layout Standard
32069 cmon51
32070 \end_layout
32071
32072 \end_inset
32073 </cell>
32074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32075 \begin_inset Text
32076
32077 \begin_layout Standard
32078 8051 monitor (hex up-/download, single step, disassemble)
32079 \end_layout
32080
32081 \end_inset
32082 </cell>
32083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32084 \begin_inset Text
32085
32086 \begin_layout Standard
32087 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32088
32089 \end_inset
32090
32091
32092 \end_layout
32093
32094 \end_inset
32095 </cell>
32096 </row>
32097 <row topline="true">
32098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32099 \begin_inset Text
32100
32101 \begin_layout Standard
32102 doxygen
32103 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32104
32105 \end_inset
32106
32107
32108 \end_layout
32109
32110 \end_inset
32111 </cell>
32112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32113 \begin_inset Text
32114
32115 \begin_layout Standard
32116 Source code documentation system
32117 \end_layout
32118
32119 \end_inset
32120 </cell>
32121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32122 \begin_inset Text
32123
32124 \begin_layout Standard
32125 \begin_inset LatexCommand \url{http://www.doxygen.org}
32126
32127 \end_inset
32128
32129
32130 \end_layout
32131
32132 \end_inset
32133 </cell>
32134 </row>
32135 <row topline="true">
32136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32137 \begin_inset Text
32138
32139 \begin_layout Standard
32140 kdevelop
32141 \end_layout
32142
32143 \end_inset
32144 </cell>
32145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32146 \begin_inset Text
32147
32148 \begin_layout Standard
32149 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32150 \end_layout
32151
32152 \end_inset
32153 </cell>
32154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32155 \begin_inset Text
32156
32157 \begin_layout Standard
32158 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32159
32160 \end_inset
32161
32162
32163 \end_layout
32164
32165 \end_inset
32166 </cell>
32167 </row>
32168 <row topline="true">
32169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32170 \begin_inset Text
32171
32172 \begin_layout Standard
32173 paulmon
32174 \end_layout
32175
32176 \end_inset
32177 </cell>
32178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32179 \begin_inset Text
32180
32181 \begin_layout Standard
32182 8051 monitor (hex up-/download, single step, disassemble)
32183 \end_layout
32184
32185 \end_inset
32186 </cell>
32187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32188 \begin_inset Text
32189
32190 \begin_layout Standard
32191 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32192
32193 \end_inset
32194
32195
32196 \end_layout
32197
32198 \end_inset
32199 </cell>
32200 </row>
32201 <row topline="true">
32202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32203 \begin_inset Text
32204
32205 \begin_layout Standard
32206 splint
32207 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32208
32209 \end_inset
32210
32211
32212 \end_layout
32213
32214 \end_inset
32215 </cell>
32216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32217 \begin_inset Text
32218
32219 \begin_layout Standard
32220 Statically checks c sources (see 
32221 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32222
32223 \end_inset
32224
32225 )
32226 \end_layout
32227
32228 \end_inset
32229 </cell>
32230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32231 \begin_inset Text
32232
32233 \begin_layout Standard
32234 \begin_inset LatexCommand \url{http://www.splint.org}
32235
32236 \end_inset
32237
32238
32239 \end_layout
32240
32241 \end_inset
32242 </cell>
32243 </row>
32244 <row topline="true" bottomline="true">
32245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32246 \begin_inset Text
32247
32248 \begin_layout Standard
32249 ddd
32250 \begin_inset LatexCommand \index{DDD (debugger)}
32251
32252 \end_inset
32253
32254
32255 \end_layout
32256
32257 \end_inset
32258 </cell>
32259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32260 \begin_inset Text
32261
32262 \begin_layout Standard
32263 Debugger, serves nicely as GUI to SDCDB
32264 \begin_inset LatexCommand \index{SDCDB (debugger)}
32265
32266 \end_inset
32267
32268  (Unix only)
32269 \end_layout
32270
32271 \end_inset
32272 </cell>
32273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32274 \begin_inset Text
32275
32276 \begin_layout Standard
32277 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32278
32279 \end_inset
32280
32281
32282 \end_layout
32283
32284 \end_inset
32285 </cell>
32286 </row>
32287 <row bottomline="true">
32288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32289 \begin_inset Text
32290
32291 \begin_layout Standard
32292 d52
32293 \begin_inset LatexCommand \index{d52}
32294
32295 \end_inset
32296
32297
32298 \begin_inset LatexCommand \index{d52 (disassembler)}
32299
32300 \end_inset
32301
32302
32303 \end_layout
32304
32305 \end_inset
32306 </cell>
32307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32308 \begin_inset Text
32309
32310 \begin_layout Standard
32311 Disassembler, can count instruction cycles
32312 \begin_inset LatexCommand \index{instruction cycles (count)}
32313
32314 \end_inset
32315
32316 , use with options -pnd
32317 \end_layout
32318
32319 \end_inset
32320 </cell>
32321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32322 \begin_inset Text
32323
32324 \begin_layout Standard
32325 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32326
32327 \end_inset
32328
32329
32330 \end_layout
32331
32332 \end_inset
32333 </cell>
32334 </row>
32335 <row bottomline="true">
32336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32337 \begin_inset Text
32338
32339 \begin_layout Standard
32340 cmake
32341 \begin_inset LatexCommand \index{cmake}
32342
32343 \end_inset
32344
32345
32346 \end_layout
32347
32348 \end_inset
32349 </cell>
32350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32351 \begin_inset Text
32352
32353 \begin_layout Standard
32354 Cross platform build system, generates Makefiles
32355 \begin_inset LatexCommand \index{Makefile}
32356
32357 \end_inset
32358
32359  and project workspaces
32360 \begin_inset LatexCommand \index{project workspace}
32361
32362 \end_inset
32363
32364
32365 \end_layout
32366
32367 \end_inset
32368 </cell>
32369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32370 \begin_inset Text
32371
32372 \begin_layout Standard
32373 \begin_inset LatexCommand \url{http://www.cmake.org}
32374
32375 \end_inset
32376
32377  \InsetSpace ~
32378 \InsetSpace ~
32379 \InsetSpace ~
32380 \InsetSpace ~
32381 and a dedicated wiki entry: 
32382 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32383
32384 \end_inset
32385
32386
32387 \end_layout
32388
32389 \end_inset
32390 </cell>
32391 </row>
32392 </lyxtabular>
32393
32394 \end_inset
32395
32396
32397 \newline
32398
32399 \end_layout
32400
32401 \begin_layout Section
32402 Related documentation / recommended reading
32403 \end_layout
32404
32405 \begin_layout Standard
32406 \align left
32407 \begin_inset Tabular
32408 <lyxtabular version="3" rows="7" columns="3">
32409 <features>
32410 <column alignment="left" valignment="top" leftline="true" width="0pt">
32411 <column alignment="left" valignment="top" leftline="true" width="0">
32412 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32413 <row topline="true" bottomline="true">
32414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32415 \begin_inset Text
32416
32417 \begin_layout Standard
32418
32419 \series bold
32420 Name
32421 \end_layout
32422
32423 \end_inset
32424 </cell>
32425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32426 \begin_inset Text
32427
32428 \begin_layout Standard
32429
32430 \series bold
32431 Subject / Title
32432 \end_layout
32433
32434 \end_inset
32435 </cell>
32436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32437 \begin_inset Text
32438
32439 \begin_layout Standard
32440
32441 \series bold
32442 Where to get
32443 \end_layout
32444
32445 \end_inset
32446 </cell>
32447 </row>
32448 <row topline="true">
32449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32450 \begin_inset Text
32451
32452 \begin_layout Standard
32453
32454 \family roman
32455 \series medium
32456 \shape up
32457 \size normal
32458 \emph off
32459 \bar no
32460 \noun off
32461 \color none
32462 c-refcard.pdf
32463 \end_layout
32464
32465 \end_inset
32466 </cell>
32467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32468 \begin_inset Text
32469
32470 \begin_layout Standard
32471 C Reference Card
32472 \begin_inset LatexCommand \index{C Reference card}
32473
32474 \end_inset
32475
32476 , 2 pages
32477 \end_layout
32478
32479 \end_inset
32480 </cell>
32481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32482 \begin_inset Text
32483
32484 \begin_layout Standard
32485 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32486
32487 \end_inset
32488
32489
32490 \end_layout
32491
32492 \end_inset
32493 </cell>
32494 </row>
32495 <row topline="true">
32496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32497 \begin_inset Text
32498
32499 \begin_layout Standard
32500 c-faq
32501 \end_layout
32502
32503 \end_inset
32504 </cell>
32505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32506 \begin_inset Text
32507
32508 \begin_layout Standard
32509 C-FAQ
32510 \begin_inset LatexCommand \index{C FAQ}
32511
32512 \end_inset
32513
32514
32515 \end_layout
32516
32517 \end_inset
32518 </cell>
32519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32520 \begin_inset Text
32521
32522 \begin_layout Standard
32523 \begin_inset LatexCommand \url{http://www.c-faq.com}
32524
32525 \end_inset
32526
32527
32528 \end_layout
32529
32530 \end_inset
32531 </cell>
32532 </row>
32533 <row topline="true">
32534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32535 \begin_inset Text
32536
32537 \begin_layout Standard
32538 ISO/IEC 9899:TC2
32539 \end_layout
32540
32541 \end_inset
32542 </cell>
32543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32544 \begin_inset Text
32545
32546 \begin_layout Standard
32547 \begin_inset Quotes sld
32548 \end_inset
32549
32550 C-Standard
32551 \begin_inset Quotes srd
32552 \end_inset
32553
32554
32555 \end_layout
32556
32557 \end_inset
32558 </cell>
32559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32560 \begin_inset Text
32561
32562 \begin_layout Standard
32563
32564 \size footnotesize
32565 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32566
32567 \end_inset
32568
32569
32570 \end_layout
32571
32572 \end_inset
32573 </cell>
32574 </row>
32575 <row topline="true">
32576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32577 \begin_inset Text
32578
32579 \begin_layout Standard
32580 ISO/IEC DTR 18037
32581 \end_layout
32582
32583 \end_inset
32584 </cell>
32585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32586 \begin_inset Text
32587
32588 \begin_layout Standard
32589 \begin_inset Quotes sld
32590 \end_inset
32591
32592 Extensions for Embedded C
32593 \begin_inset Quotes srd
32594 \end_inset
32595
32596
32597 \end_layout
32598
32599 \end_inset
32600 </cell>
32601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32602 \begin_inset Text
32603
32604 \begin_layout Standard
32605
32606 \size footnotesize
32607 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32608
32609 \end_inset
32610
32611
32612 \end_layout
32613
32614 \end_inset
32615 </cell>
32616 </row>
32617 <row topline="true">
32618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32619 \begin_inset Text
32620
32621 \begin_layout Standard
32622
32623 \end_layout
32624
32625 \end_inset
32626 </cell>
32627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32628 \begin_inset Text
32629
32630 \begin_layout Standard
32631 Latest datasheet of target CPU
32632 \end_layout
32633
32634 \end_inset
32635 </cell>
32636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32637 \begin_inset Text
32638
32639 \begin_layout Standard
32640 vendor
32641 \end_layout
32642
32643 \end_inset
32644 </cell>
32645 </row>
32646 <row topline="true" bottomline="true">
32647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32648 \begin_inset Text
32649
32650 \begin_layout Standard
32651
32652 \end_layout
32653
32654 \end_inset
32655 </cell>
32656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32657 \begin_inset Text
32658
32659 \begin_layout Standard
32660 Revision history of datasheet
32661 \end_layout
32662
32663 \end_inset
32664 </cell>
32665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32666 \begin_inset Text
32667
32668 \begin_layout Standard
32669 vendor
32670 \end_layout
32671
32672 \end_inset
32673 </cell>
32674 </row>
32675 </lyxtabular>
32676
32677 \end_inset
32678
32679
32680 \newline
32681
32682 \end_layout
32683
32684 \begin_layout Section
32685 Application notes specifically for SDCC
32686 \end_layout
32687
32688 \begin_layout Standard
32689 SDCC makes no claims about the completeness of this list and about up-to-datenes
32690 s or correctness of the application notes
32691 \begin_inset LatexCommand \index{Application notes}
32692
32693 \end_inset
32694
32695 .
32696 \end_layout
32697
32698 \begin_layout Standard
32699 \align left
32700
32701 \size footnotesize
32702 \begin_inset Tabular
32703 <lyxtabular version="3" rows="7" columns="3">
32704 <features>
32705 <column alignment="block" valignment="top" leftline="true" width="17col%">
32706 <column alignment="block" valignment="top" leftline="true" width="27col%">
32707 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32708 <row topline="true" bottomline="true">
32709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32710 \begin_inset Text
32711
32712 \begin_layout Standard
32713
32714 \series bold
32715 \size footnotesize
32716 Vendor
32717 \end_layout
32718
32719 \end_inset
32720 </cell>
32721 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32722 \begin_inset Text
32723
32724 \begin_layout Standard
32725
32726 \series bold
32727 \size footnotesize
32728 Subject / Title
32729 \end_layout
32730
32731 \end_inset
32732 </cell>
32733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32734 \begin_inset Text
32735
32736 \begin_layout Standard
32737
32738 \series bold
32739 \size footnotesize
32740 Where to get
32741 \end_layout
32742
32743 \end_inset
32744 </cell>
32745 </row>
32746 <row topline="true">
32747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32748 \begin_inset Text
32749
32750 \begin_layout Standard
32751
32752 \size footnotesize
32753 Maxim / Dallas
32754 \end_layout
32755
32756 \end_inset
32757 </cell>
32758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32759 \begin_inset Text
32760
32761 \begin_layout Standard
32762
32763 \size footnotesize
32764 Using the SDCC Compiler for the DS80C400
32765 \begin_inset LatexCommand \index{DS80C400}
32766
32767 \end_inset
32768
32769
32770 \end_layout
32771
32772 \end_inset
32773 </cell>
32774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32775 \begin_inset Text
32776
32777 \begin_layout Standard
32778
32779 \size footnotesize
32780 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32781
32782 \end_inset
32783
32784
32785 \end_layout
32786
32787 \end_inset
32788 </cell>
32789 </row>
32790 <row topline="true">
32791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32792 \begin_inset Text
32793
32794 \begin_layout Standard
32795
32796 \size footnotesize
32797 Maxim / Dallas
32798 \end_layout
32799
32800 \end_inset
32801 </cell>
32802 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32803 \begin_inset Text
32804
32805 \begin_layout Standard
32806
32807 \size footnotesize
32808 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32809 \begin_inset LatexCommand \index{DS89C4x0}
32810
32811 \end_inset
32812
32813  Family of Microcontrollers
32814 \end_layout
32815
32816 \end_inset
32817 </cell>
32818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32819 \begin_inset Text
32820
32821 \begin_layout Standard
32822
32823 \size footnotesize
32824 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32825
32826 \end_inset
32827
32828
32829 \end_layout
32830
32831 \end_inset
32832 </cell>
32833 </row>
32834 <row topline="true">
32835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32836 \begin_inset Text
32837
32838 \begin_layout Standard
32839
32840 \size footnotesize
32841 Silicon Laboratories / Cygnal
32842 \end_layout
32843
32844 \end_inset
32845 </cell>
32846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32847 \begin_inset Text
32848
32849 \begin_layout Standard
32850
32851 \size footnotesize
32852 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32853 \begin_inset LatexCommand \index{IDE}
32854
32855 \end_inset
32856
32857
32858 \end_layout
32859
32860 \end_inset
32861 </cell>
32862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32863 \begin_inset Text
32864
32865 \begin_layout Standard
32866
32867 \size footnotesize
32868 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32869
32870 \end_inset
32871
32872
32873 \end_layout
32874
32875 \end_inset
32876 </cell>
32877 </row>
32878 <row topline="true">
32879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32880 \begin_inset Text
32881
32882 \begin_layout Standard
32883
32884 \size footnotesize
32885 Ramtron / Goal Semiconductor
32886 \end_layout
32887
32888 \end_inset
32889 </cell>
32890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32891 \begin_inset Text
32892
32893 \begin_layout Standard
32894
32895 \size footnotesize
32896 Interfacing SDCC to Syn and Textpad
32897 \end_layout
32898
32899 \end_inset
32900 </cell>
32901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32902 \begin_inset Text
32903
32904 \begin_layout Standard
32905
32906 \size footnotesize
32907 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32908
32909 \end_inset
32910
32911
32912 \end_layout
32913
32914 \end_inset
32915 </cell>
32916 </row>
32917 <row topline="true">
32918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32919 \begin_inset Text
32920
32921 \begin_layout Standard
32922
32923 \size footnotesize
32924 Ramtron / Goal Semiconductor
32925 \end_layout
32926
32927 \end_inset
32928 </cell>
32929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32930 \begin_inset Text
32931
32932 \begin_layout Standard
32933
32934 \size footnotesize
32935 Installing and Configuring SDCC and Crimson Editor 
32936 \end_layout
32937
32938 \end_inset
32939 </cell>
32940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32941 \begin_inset Text
32942
32943 \begin_layout Standard
32944
32945 \size footnotesize
32946 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32947
32948 \end_inset
32949
32950
32951 \end_layout
32952
32953 \end_inset
32954 </cell>
32955 </row>
32956 <row topline="true" bottomline="true">
32957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32958 \begin_inset Text
32959
32960 \begin_layout Standard
32961
32962 \size footnotesize
32963 Texas Instruments
32964 \end_layout
32965
32966 \end_inset
32967 </cell>
32968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32969 \begin_inset Text
32970
32971 \begin_layout Standard
32972
32973 \size footnotesize
32974 MSC12xx Programming with SDCC
32975 \end_layout
32976
32977 \end_inset
32978 </cell>
32979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32980 \begin_inset Text
32981
32982 \begin_layout Standard
32983
32984 \size footnotesize
32985 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32986
32987 \end_inset
32988
32989
32990 \end_layout
32991
32992 \end_inset
32993 </cell>
32994 </row>
32995 </lyxtabular>
32996
32997 \end_inset
32998
32999
33000 \end_layout
33001
33002 \begin_layout Section
33003 Some Questions
33004 \end_layout
33005
33006 \begin_layout Standard
33007 Some questions answered, some pointers given - it might be time to in turn
33008  ask 
33009 \emph on
33010 you
33011 \emph default
33012  some questions: 
33013 \end_layout
33014
33015 \begin_layout Itemize
33016 can you solve your project with the selected microcontroller? Would you
33017  find out early or rather late that your target is too small/slow/whatever?
33018  Can you switch to a slightly better device if it doesn't fit?
33019 \end_layout
33020
33021 \begin_layout Itemize
33022 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
33023  and/or another programming language be more adequate? Would an operating
33024  system on the target device help?
33025 \end_layout
33026
33027 \begin_layout Itemize
33028 if you solved the problem, will the marketing department be happy?
33029 \end_layout
33030
33031 \begin_layout Itemize
33032 if the marketing department is happy, will customers be happy?
33033 \end_layout
33034
33035 \begin_layout Itemize
33036 if you're the project manager, marketing department and maybe even the customer
33037  in one person, have you tried to see the project from the outside?
33038 \end_layout
33039
33040 \begin_layout Itemize
33041 is the project done if you think it is done? Or is just that other interface/pro
33042 tocol/feature/configuration/option missing? How about website, manual(s),
33043  internationali(z|s)ation, packaging, labels, 2nd source for components,
33044  electromagnetic compatability/interference, documentation for production,
33045  production test software, update mechanism, patent issues?
33046 \end_layout
33047
33048 \begin_layout Itemize
33049 is your project adequately positioned in that magic triangle: fame, fortune,
33050  fun?
33051 \end_layout
33052
33053 \begin_layout Standard
33054 Maybe not all answers to these questions are known and some answers may
33055  even be 
33056 \emph on
33057 no
33058 \emph default
33059 , nevertheless knowing these questions may help you to avoid burnout
33060 \begin_inset Foot
33061 status open
33062
33063 \begin_layout Standard
33064 burnout is bad for electronic devices, programmers and motorcycle tyres
33065 \end_layout
33066
33067 \end_inset
33068
33069 .
33070  Chances are you didn't want to hear some of them...
33071 \end_layout
33072
33073 \begin_layout Chapter
33074 Support
33075 \begin_inset LatexCommand \index{Support}
33076
33077 \end_inset
33078
33079
33080 \end_layout
33081
33082 \begin_layout Standard
33083 SDCC has grown to be a large project.
33084  The compiler alone (without the preprocessor, assembler and linker) is
33085  well over 150,000 lines of code (blank stripped).
33086  The open source nature of this project is a key to its continued growth
33087  and support.
33088  You gain the benefit and support of many active software developers and
33089  end users.
33090  Is SDCC perfect? No, that's why we need your help.
33091  The developers take pride in fixing reported bugs.
33092  You can help by reporting the bugs and helping other SDCC users.
33093  There are lots of ways to contribute, and we encourage you to take part
33094  in making SDCC a great software package.
33095  
33096 \end_layout
33097
33098 \begin_layout Standard
33099 The SDCC project is hosted on the SDCC sourceforge site at 
33100 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33101
33102 \end_inset
33103
33104 .
33105  You'll find the complete set of mailing lists
33106 \begin_inset LatexCommand \index{Mailing list(s)}
33107
33108 \end_inset
33109
33110 , forums, bug reporting system, patch submission
33111 \begin_inset LatexCommand \index{Patch submission}
33112
33113 \end_inset
33114
33115  system, download
33116 \begin_inset LatexCommand \index{download}
33117
33118 \end_inset
33119
33120  area and Subversion code repository
33121 \begin_inset LatexCommand \index{Subversion code repository}
33122
33123 \end_inset
33124
33125  there.
33126 \end_layout
33127
33128 \begin_layout Section
33129 Reporting Bugs
33130 \begin_inset LatexCommand \index{Bug reporting}
33131
33132 \end_inset
33133
33134
33135 \begin_inset LatexCommand \index{Reporting bugs}
33136
33137 \end_inset
33138
33139
33140 \end_layout
33141
33142 \begin_layout Standard
33143 The recommended way of reporting bugs is using the infrastructure of the
33144  sourceforge site.
33145  You can follow the status of bug reports there and have an overview about
33146  the known bugs.
33147 \end_layout
33148
33149 \begin_layout Standard
33150 Bug reports are automatically forwarded to the developer mailing list and
33151  will be fixed ASAP.
33152  When reporting a bug, it is very useful to include a small test program
33153  (the smaller the better) which reproduces the problem.
33154  If you can isolate the problem by looking at the generated assembly code,
33155  this can be very helpful.
33156  Compiling your program with the -
33157 \begin_inset ERT
33158 status collapsed
33159
33160 \begin_layout Standard
33161
33162
33163 \backslash
33164 /
33165 \end_layout
33166
33167 \end_inset
33168
33169 -dumpall
33170 \begin_inset LatexCommand \index{-\/-dumpall}
33171
33172 \end_inset
33173
33174  option can sometimes be useful in locating optimization problems.
33175  When reporting a bug please make sure you:
33176 \end_layout
33177
33178 \begin_layout Enumerate
33179 Attach the code you are compiling with SDCC.
33180  
33181 \end_layout
33182
33183 \begin_layout Enumerate
33184 Specify the exact command you use to run SDCC, or attach your Makefile.
33185  
33186 \end_layout
33187
33188 \begin_layout Enumerate
33189 Specify the SDCC version (type "
33190 \family sans
33191 \series bold
33192 sdcc -v
33193 \family default
33194 \series default
33195 "), your platform, and operating system.
33196  
33197 \end_layout
33198
33199 \begin_layout Enumerate
33200 Provide an exact copy of any error message or incorrect output.
33201  
33202 \end_layout
33203
33204 \begin_layout Enumerate
33205 Put something meaningful in the subject of your message.
33206 \end_layout
33207
33208 \begin_layout Standard
33209 Please attempt to include these 5 important parts, as applicable, in all
33210  requests for support or when reporting any problems or bugs with SDCC.
33211  Though this will make your message lengthy, it will greatly improve your
33212  chance that SDCC users and developers will be able to help you.
33213  Some SDCC developers are frustrated by bug reports without code provided
33214  that they can use to reproduce and ultimately fix the problem, so please
33215  be sure to provide sample code if you are reporting a bug! 
33216 \end_layout
33217
33218 \begin_layout Standard
33219 Please have a short check that you are using a recent version of SDCC and
33220  the bug is not yet known.
33221  This is the link for reporting bugs: 
33222 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33223
33224 \end_inset
33225
33226 .
33227  With SDCC on average having more than 200 downloads
33228 \begin_inset LatexCommand \index{download}
33229
33230 \end_inset
33231
33232  on sourceforge per day
33233 \begin_inset Foot
33234 status open
33235
33236 \begin_layout Standard
33237 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33238  between 2002 and 2005.
33239  This does not include other methods of distribution.
33240 \end_layout
33241
33242 \end_inset
33243
33244  there must be some users.
33245  So it's not exactly easy to find a new bug.
33246  If you find one we need it: 
33247 \emph on
33248 reporting bugs is good
33249 \emph default
33250 .
33251 \end_layout
33252
33253 \begin_layout Section
33254 Requesting Features
33255 \begin_inset LatexCommand \label{sub:Requesting-Features}
33256
33257 \end_inset
33258
33259
33260 \begin_inset LatexCommand \index{Feature request}
33261
33262 \end_inset
33263
33264
33265 \begin_inset LatexCommand \index{Requesting features}
33266
33267 \end_inset
33268
33269
33270 \end_layout
33271
33272 \begin_layout Standard
33273 Like bug reports feature requests are forwarded to the developer mailing
33274  list.
33275  This is the link for requesting features: 
33276 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33277
33278 \end_inset
33279
33280 .
33281 \end_layout
33282
33283 \begin_layout Section
33284 Submitting patches
33285 \end_layout
33286
33287 \begin_layout Standard
33288 Like bug reports contributed patches are forwarded to the developer mailing
33289  list.
33290  This is the link for submitting patches
33291 \begin_inset LatexCommand \index{Patch submission}
33292
33293 \end_inset
33294
33295
33296 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33297
33298 \end_inset
33299
33300 .
33301 \end_layout
33302
33303 \begin_layout Standard
33304 You need to specify some parameters to the 
33305 \family typewriter
33306 diff
33307 \family default
33308  command for the patches to be useful.
33309  If you modified more than one file a patch created f.e.
33310  with 
33311 \family sans
33312 \series bold
33313
33314 \begin_inset Quotes sld
33315 \end_inset
33316
33317 diff -Naur unmodified_directory modified_directory >my_changes.patch
33318 \begin_inset Quotes srd
33319 \end_inset
33320
33321
33322 \family default
33323 \series default
33324  will be fine, otherwise 
33325 \family sans
33326 \series bold
33327
33328 \begin_inset Quotes sld
33329 \end_inset
33330
33331 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33332 \begin_inset Quotes srd
33333 \end_inset
33334
33335
33336 \series default
33337  
33338 \family default
33339 will do.
33340 \end_layout
33341
33342 \begin_layout Section
33343 Getting Help
33344 \end_layout
33345
33346 \begin_layout Standard
33347 These links should take you directly to the 
33348 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33349
33350 \end_inset
33351
33352
33353 \begin_inset Foot
33354 status open
33355
33356 \begin_layout Standard
33357 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33358  automated messages (mid 2003)
33359 \end_layout
33360
33361 \end_inset
33362
33363  and the 
33364 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33365
33366 \end_inset
33367
33368 , lists
33369 \begin_inset LatexCommand \index{Mailing list(s)}
33370
33371 \end_inset
33372
33373  and forums are archived and searchable so if you are lucky someone already
33374  had a similar problem.
33375  While mails to the lists themselves are delivered promptly their web front
33376  end on sourceforge sometimes shows a severe time lag (up to several weeks),
33377  if you're seriously using SDCC please consider subscribing to the lists.
33378 \end_layout
33379
33380 \begin_layout Section
33381 ChangeLog
33382 \end_layout
33383
33384 \begin_layout Standard
33385 You can follow the status of the Subversion version
33386 \begin_inset LatexCommand \index{version}
33387
33388 \end_inset
33389
33390  of SDCC by watching the Changelog
33391 \begin_inset LatexCommand \index{Changelog}
33392
33393 \end_inset
33394
33395  in the Subversion repository
33396 \size footnotesize
33397  
33398 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33399
33400 \end_inset
33401
33402 .
33403 \end_layout
33404
33405 \begin_layout Section
33406 Subversion Source Code Repository
33407 \end_layout
33408
33409 \begin_layout Standard
33410 The output of 
33411 \family sans
33412 \series bold
33413 sdcc -
33414 \family default
33415
33416 \begin_inset ERT
33417 status open
33418
33419 \begin_layout Standard
33420
33421
33422 \backslash
33423 /
33424 \end_layout
33425
33426 \end_inset
33427
33428
33429 \family sans
33430 -version
33431 \family default
33432 \series default
33433  or the filenames of the snapshot versions of SDCC include date and its
33434  Subversion
33435 \begin_inset LatexCommand \index{Subversion code repository}
33436
33437 \end_inset
33438
33439  number.
33440  Subversion allows to download the source of recent or previous versions
33441  
33442 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33443
33444 \end_inset
33445
33446  (by number or by date).
33447  An on-line source code browser and detailled instructions are also available
33448  there.
33449  SDCC versions starting from 1999 up to now are available (currently the
33450  versions prior to the conversion from cvs
33451 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33452
33453 \end_inset
33454
33455  to Subversion (April 2006) are either by accessible by Subversion or by
33456  cvs).
33457 \end_layout
33458
33459 \begin_layout Section
33460 Release policy
33461 \begin_inset LatexCommand \index{Release policy}
33462
33463 \end_inset
33464
33465
33466 \end_layout
33467
33468 \begin_layout Standard
33469 Historically there often were long delays between official releases and
33470  the sourceforge download area tends to get not updated at all.
33471  Excuses in the past might have referred to problems with live range analysis,
33472  but as this was fixed a while ago, the current problem is that another
33473  excuse has to be found.
33474  Kidding aside, we have to get better there! On the other hand there are
33475  daily snapshots available at 
33476 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33477
33478 \end_inset
33479
33480 , and you can always build the very last version (hopefully with many bugs
33481  fixed, and features added) from the source code available at 
33482 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33483
33484 \end_inset
33485
33486 .
33487  The SDCC Wiki
33488 \begin_inset LatexCommand \index{wiki}
33489
33490 \end_inset
33491
33492
33493 \begin_inset LatexCommand \index{SDCC Wiki}
33494
33495 \end_inset
33496
33497  at 
33498 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33499
33500 \end_inset
33501
33502  also holds some information about past and future releases.
33503 \end_layout
33504
33505 \begin_layout Section
33506 Examples
33507 \begin_inset LatexCommand \index{Examples}
33508
33509 \end_inset
33510
33511
33512 \end_layout
33513
33514 \begin_layout Standard
33515 You'll find some small examples in the directory 
33516 \emph on
33517 sdcc/device/examples/.
33518  
33519 \emph default
33520 More examples and libraries are available at
33521 \emph on
33522  The SDCC Open Knowledge Resource 
33523 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33524
33525 \end_inset
33526
33527  
33528 \emph default
33529 web site or at 
33530 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33531
33532 \end_inset
33533
33534 .
33535 \end_layout
33536
33537 \begin_layout Standard
33538 \begin_inset Note Note
33539 status collapsed
33540
33541 \begin_layout Standard
33542 I did insert a reference to Paul's web site here although it seems rather
33543  dedicated to a specific 8032 board (I think it's okay because it f.e.
33544  shows LCD/Harddisc interface and has a free 8051 monitor.
33545  Independent 8032 board vendors face hard competition of heavily subsidized
33546  development boards anyway).
33547 \end_layout
33548
33549 \begin_layout Standard
33550 Maybe we should include some links to real world applications.
33551  Preferably pointer to pointers (one for each architecture) so this stays
33552  manageable here?
33553 \end_layout
33554
33555 \end_inset
33556
33557
33558 \end_layout
33559
33560 \begin_layout Section
33561 Quality control
33562 \begin_inset LatexCommand \label{sec:Quality-control}
33563
33564 \end_inset
33565
33566
33567 \begin_inset LatexCommand \index{Quality control}
33568
33569 \end_inset
33570
33571
33572 \end_layout
33573
33574 \begin_layout Standard
33575 The compiler is passed through snaphot build compile and build checks.
33576  The so called 
33577 \shape italic
33578 regression tests
33579 \shape default
33580
33581 \begin_inset LatexCommand \index{Regression test}
33582
33583 \end_inset
33584
33585  check that SDCC itself compiles flawlessly on several host platforms (i386,
33586  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33587  and checks the quality of the code generated by SDCC by running the code
33588  for several target platforms through simulators.
33589  The regression test suite comprises more than 100 files which expand to
33590  more than 500 test cases which include more than 4500 tests.
33591  The results of these tests are published daily on SDCC's snapshot page
33592  (click on the red or green symbols on the right side of 
33593 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33594
33595 \end_inset
33596
33597 ).
33598 \end_layout
33599
33600 \begin_layout Standard
33601 There is a separate document 
33602 \shape italic
33603 test_suite.pdf 
33604 \begin_inset LatexCommand \index{Test suite}
33605
33606 \end_inset
33607
33608
33609 \shape default
33610  
33611 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33612
33613 \end_inset
33614
33615  about the regression test suite.
33616 \end_layout
33617
33618 \begin_layout Standard
33619 You'll find the test code in the directory 
33620 \shape italic
33621 sdcc/support/regression
33622 \shape default
33623 .
33624  You can run these tests manually by running 
33625 \family sans
33626 make
33627 \family default
33628  in this directory (or f.e.
33629  
33630 \family sans
33631 \series bold
33632
33633 \begin_inset Quotes sld
33634 \end_inset
33635
33636 make test-mcs51
33637 \begin_inset Quotes srd
33638 \end_inset
33639
33640
33641 \family default
33642 \series default
33643  if you don't want to run the complete tests).
33644  The test code might also be interesting if you want to look for examples
33645 \begin_inset LatexCommand \index{Examples}
33646
33647 \end_inset
33648
33649  checking corner cases of SDCC or if you plan to submit patches
33650 \begin_inset LatexCommand \index{Patch submission}
33651
33652 \end_inset
33653
33654 .
33655 \end_layout
33656
33657 \begin_layout Standard
33658 The PIC14 port uses a different set of regression tests 
33659 \begin_inset LatexCommand \index{Regression test (PIC14)}
33660
33661 \end_inset
33662
33663 , you'll find them in the directory 
33664 \shape italic
33665 sdcc/src/regression
33666 \shape default
33667 .
33668 \end_layout
33669
33670 \begin_layout Section
33671 Use of SDCC in Education
33672 \end_layout
33673
33674 \begin_layout Standard
33675 In short: 
33676 \emph on
33677 highly
33678 \emph default
33679  encouraged
33680 \begin_inset Foot
33681 status open
33682
33683 \begin_layout Standard
33684 the phrase "use in education" might evoke the association "
33685 \emph on
33686 only
33687 \emph default
33688  fit for use in education".
33689  This connotation is not intended but nevertheless risked as the licensing
33690  of SDCC makes it difficult to offer educational discounts
33691 \end_layout
33692
33693 \end_inset
33694
33695 .
33696  If your rationales are to:
33697 \end_layout
33698
33699 \begin_layout Enumerate
33700 give students a chance to understand the 
33701 \emph on
33702 complete
33703 \emph default
33704  steps of code generation
33705 \end_layout
33706
33707 \begin_layout Enumerate
33708 have a curriculum that can be extended for years.
33709  Then you could use an fpga board as target and your curriculum will seamlessly
33710  extend from logic synthesis (
33711 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33712
33713 \end_inset
33714
33715
33716 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33717
33718 \end_inset
33719
33720 ), over assembly programming, to C to FPGA compilers (
33721 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33722
33723 \end_inset
33724
33725 ) and to C.
33726 \end_layout
33727
33728 \begin_layout Enumerate
33729 be able to insert excursions about skills like using a revision control
33730  system, submitting/applying patches, using a type-setting (as opposed to
33731  word-processing) engine LyX/LaTeX, using 
33732 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33733
33734 \end_inset
33735
33736 , following some 
33737 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33738
33739 \end_inset
33740
33741 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33742  Source Software, CPU simulation, compiler regression tests
33743 \begin_inset LatexCommand \index{Regression test}
33744
33745 \end_inset
33746
33747 .
33748  
33749 \newline
33750 And if there should be a shortage of ideas then you can always point students
33751  to the ever-growing feature request list 
33752 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33753
33754 \end_inset
33755
33756 .
33757 \end_layout
33758
33759 \begin_layout Enumerate
33760 not tie students to a specific host platform and instead allow them to use
33761  a host platform of 
33762 \emph on
33763 their
33764 \emph default
33765  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33766  and eventually 
33767 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33768
33769 \end_inset
33770
33771 )
33772 \end_layout
33773
33774 \begin_layout Enumerate
33775 not encourage students to use illegal copies of educational software
33776 \end_layout
33777
33778 \begin_layout Enumerate
33779 be immune to licensing/availability/price changes of the chosen tool chain
33780 \end_layout
33781
33782 \begin_layout Enumerate
33783 be able to change to a new target platform without having to adopt a new
33784  tool chain
33785 \end_layout
33786
33787 \begin_layout Enumerate
33788 have complete control over and insight into the tool chain
33789 \end_layout
33790
33791 \begin_layout Enumerate
33792 make your students aware about the pros and cons of open source software
33793  development
33794 \end_layout
33795
33796 \begin_layout Enumerate
33797 give back to the public as you are probably at least partially publically
33798  funded
33799 \end_layout
33800
33801 \begin_layout Enumerate
33802 give students a chance to publically prove their skills and to possibly
33803  see a world wide impact
33804 \end_layout
33805
33806 \begin_layout Standard
33807 then SDCC is probably among the first choices.
33808  Well, probably SDCC might be the only choice.
33809 \newpage
33810
33811 \end_layout
33812
33813 \begin_layout Chapter
33814 SDCC Technical Data
33815 \end_layout
33816
33817 \begin_layout Section
33818 Optimizations
33819 \begin_inset LatexCommand \index{Optimizations}
33820
33821 \end_inset
33822
33823
33824 \end_layout
33825
33826 \begin_layout Standard
33827 SDCC performs a host of standard optimizations in addition to some MCU specific
33828  optimizations.
33829  
33830 \end_layout
33831
33832 \begin_layout Subsection
33833 Sub-expression Elimination
33834 \begin_inset LatexCommand \index{Subexpression elimination}
33835
33836 \end_inset
33837
33838
33839 \end_layout
33840
33841 \begin_layout Standard
33842 The compiler does local and 
33843 \emph on
33844 g
33845 \emph default
33846 lobal 
33847 \emph on
33848 c
33849 \emph default
33850 ommon 
33851 \emph on
33852 s
33853 \emph default
33854 ubexpression 
33855 \emph on
33856 e
33857 \emph default
33858 limination, e.g.: 
33859 \end_layout
33860
33861 \begin_layout Verse
33862
33863 \family typewriter
33864 i = x + y + 1; 
33865 \newline
33866 j = x + y;
33867 \end_layout
33868
33869 \begin_layout Standard
33870 will be translated to
33871 \end_layout
33872
33873 \begin_layout Verse
33874
33875 \family typewriter
33876 iTemp = x + y; 
33877 \newline
33878 i = iTemp + 1; 
33879 \newline
33880 j = iTemp;
33881 \end_layout
33882
33883 \begin_layout Standard
33884 Some subexpressions are not as obvious as the above example, e.g.:
33885 \end_layout
33886
33887 \begin_layout Verse
33888
33889 \family typewriter
33890 a->b[i].c = 10; 
33891 \newline
33892 a->b[i].d = 11;
33893 \end_layout
33894
33895 \begin_layout Standard
33896 In this case the address arithmetic a->b[i] will be computed only once;
33897  the equivalent code in C would be.
33898 \end_layout
33899
33900 \begin_layout Verse
33901
33902 \family typewriter
33903 iTemp = a->b[i]; 
33904 \newline
33905 iTemp.c = 10; 
33906 \newline
33907 iTemp.d = 11;
33908 \end_layout
33909
33910 \begin_layout Standard
33911 The compiler will try to keep these temporary variables in registers.
33912 \end_layout
33913
33914 \begin_layout Subsection
33915 Dead-Code Elimination
33916 \begin_inset LatexCommand \index{Dead-code elimination}
33917
33918 \end_inset
33919
33920
33921 \end_layout
33922
33923 \begin_layout Verse
33924
33925 \family typewriter
33926 int global;
33927 \newline
33928
33929 \newline
33930 void f () { 
33931 \newline
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 int i; 
33935 \newline
33936 \InsetSpace ~
33937 \InsetSpace ~
33938 i = 1; \InsetSpace ~
33939 \InsetSpace ~
33940 \InsetSpace ~
33941 \InsetSpace ~
33942 \InsetSpace ~
33943 /* dead store */ 
33944 \newline
33945 \InsetSpace ~
33946 \InsetSpace ~
33947 global = 1;\InsetSpace ~
33948 /* dead
33949  store */ 
33950 \newline
33951 \InsetSpace ~
33952 \InsetSpace ~
33953 global = 2; 
33954 \newline
33955 \InsetSpace ~
33956 \InsetSpace ~
33957 return; 
33958 \newline
33959 \InsetSpace ~
33960 \InsetSpace ~
33961 global = 3;\InsetSpace ~
33962 /* unreachable */ 
33963 \newline
33964 }
33965 \end_layout
33966
33967 \begin_layout Standard
33968 will be changed to
33969 \end_layout
33970
33971 \begin_layout Verse
33972
33973 \family typewriter
33974 int global;
33975 \newline
33976
33977 \newline
33978 void f () {
33979 \newline
33980 \InsetSpace ~
33981 \InsetSpace ~
33982 global = 2; 
33983 \newline
33984 }
33985 \end_layout
33986
33987 \begin_layout Subsection
33988 Copy-Propagation
33989 \begin_inset LatexCommand \index{Copy propagation}
33990
33991 \end_inset
33992
33993
33994 \end_layout
33995
33996 \begin_layout Verse
33997
33998 \family typewriter
33999 int f() { 
34000 \newline
34001 \InsetSpace ~
34002 \InsetSpace ~
34003 int i, j; 
34004 \newline
34005 \InsetSpace ~
34006 \InsetSpace ~
34007 i = 10; 
34008 \newline
34009 \InsetSpace ~
34010 \InsetSpace ~
34011 j = i; 
34012 \newline
34013 \InsetSpace ~
34014 \InsetSpace ~
34015 return j; 
34016 \newline
34017 }
34018 \end_layout
34019
34020 \begin_layout Standard
34021 will be changed to 
34022 \end_layout
34023
34024 \begin_layout Verse
34025
34026 \family typewriter
34027 int f() { 
34028 \newline
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 int i, j; 
34032 \newline
34033 \InsetSpace ~
34034 \InsetSpace ~
34035 i = 10; 
34036 \newline
34037 \InsetSpace ~
34038 \InsetSpace ~
34039 j = 10; 
34040 \newline
34041 \InsetSpace ~
34042 \InsetSpace ~
34043 return 10; 
34044 \newline
34045 }
34046 \end_layout
34047
34048 \begin_layout Standard
34049 Note: the dead stores created by this copy propagation will be eliminated
34050  by dead-code elimination.
34051 \end_layout
34052
34053 \begin_layout Subsection
34054 Loop Optimizations
34055 \begin_inset LatexCommand \index{Loop optimization}
34056
34057 \end_inset
34058
34059
34060 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
34061
34062 \end_inset
34063
34064
34065 \end_layout
34066
34067 \begin_layout Standard
34068 Two types of loop optimizations are done by SDCC 
34069 \emph on
34070 loop invariant
34071 \emph default
34072  lifting and
34073 \emph on
34074  strength reduction
34075 \emph default
34076  of loop induction variables.
34077  In addition to the strength reduction the optimizer marks the induction
34078  variables and the register allocator tries to keep the induction variables
34079  in registers for the duration of the loop.
34080  Because of this preference of the register allocator
34081 \begin_inset LatexCommand \index{Register allocation}
34082
34083 \end_inset
34084
34085 , loop induction optimization causes an increase in register pressure, which
34086  may cause unwanted spilling of other temporary variables into the stack
34087 \begin_inset LatexCommand \index{stack}
34088
34089 \end_inset
34090
34091  / data space.
34092  The compiler will generate a warning message when it is forced to allocate
34093  extra space either on the stack or data space.
34094  If this extra space allocation is undesirable then induction optimization
34095  can be eliminated either for the entire source file (with -
34096 \begin_inset ERT
34097 status collapsed
34098
34099 \begin_layout Standard
34100
34101
34102 \backslash
34103 /
34104 \end_layout
34105
34106 \end_inset
34107
34108 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34109 noinduction
34110 \begin_inset LatexCommand \index{\#pragma noinduction}
34111
34112 \end_inset
34113
34114 .
34115 \newline
34116
34117 \newline
34118 Loop Invariant:
34119 \end_layout
34120
34121 \begin_layout Verse
34122
34123 \family typewriter
34124 for (i = 0 ; i < 100 ; i ++) 
34125 \newline
34126 \InsetSpace ~
34127 \InsetSpace ~
34128 \InsetSpace ~
34129 \InsetSpace ~
34130 f += k + l;
34131 \end_layout
34132
34133 \begin_layout Standard
34134 changed to
34135 \end_layout
34136
34137 \begin_layout Verse
34138
34139 \family typewriter
34140 itemp = k + l; 
34141 \newline
34142 for (i = 0; i < 100; i++) 
34143 \newline
34144 \InsetSpace ~
34145 \InsetSpace ~
34146 \InsetSpace ~
34147 \InsetSpace ~
34148 f += itemp;
34149 \end_layout
34150
34151 \begin_layout Standard
34152 As mentioned previously some loop invariants are not as apparent, all static
34153  address computations are also moved out of the loop.
34154 \newline
34155
34156 \newline
34157 Strength Reduction
34158 \begin_inset LatexCommand \index{Strength reduction}
34159
34160 \end_inset
34161
34162 , this optimization substitutes an expression by a cheaper expression:
34163 \end_layout
34164
34165 \begin_layout Verse
34166
34167 \family typewriter
34168 for (i=0;i < 100; i++)
34169 \newline
34170 \InsetSpace ~
34171 \InsetSpace ~
34172 \InsetSpace ~
34173 \InsetSpace ~
34174 ar[i*5] = i*3;
34175 \end_layout
34176
34177 \begin_layout Standard
34178 changed to
34179 \end_layout
34180
34181 \begin_layout Verse
34182
34183 \family typewriter
34184 itemp1 = 0; 
34185 \newline
34186 itemp2 = 0; 
34187 \newline
34188 for (i=0;i< 100;i++) { 
34189 \newline
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194 ar[itemp1] = itemp2; 
34195 \newline
34196 \InsetSpace ~
34197 \InsetSpace ~
34198 \InsetSpace ~
34199 \InsetSpace ~
34200 itemp1
34201  += 5; 
34202 \newline
34203 \InsetSpace ~
34204 \InsetSpace ~
34205 \InsetSpace ~
34206 \InsetSpace ~
34207 itemp2 += 3; 
34208 \newline
34209 }
34210 \end_layout
34211
34212 \begin_layout Standard
34213 The more expensive multiplication
34214 \begin_inset LatexCommand \index{Multiplication}
34215
34216 \end_inset
34217
34218  is changed to a less expensive addition.
34219 \end_layout
34220
34221 \begin_layout Subsection
34222 Loop Reversing
34223 \begin_inset LatexCommand \index{Loop reversing}
34224
34225 \end_inset
34226
34227
34228 \end_layout
34229
34230 \begin_layout Standard
34231 This optimization is done to reduce the overhead of checking loop boundaries
34232  for every iteration.
34233  Some simple loops can be reversed and implemented using a 
34234 \begin_inset Quotes eld
34235 \end_inset
34236
34237 decrement and jump if not zero
34238 \begin_inset Quotes erd
34239 \end_inset
34240
34241  instruction.
34242  SDCC checks for the following criterion to determine if a loop is reversible
34243  (note: more sophisticated compilers use data-dependency analysis to make
34244  this determination, SDCC uses a more simple minded analysis).
34245 \end_layout
34246
34247 \begin_layout Itemize
34248 The 'for' loop is of the form 
34249 \newline
34250
34251 \newline
34252
34253 \family typewriter
34254 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34255  += 1])
34256 \newline
34257 \InsetSpace ~
34258 \InsetSpace ~
34259 \InsetSpace ~
34260 \InsetSpace ~
34261 <for body>
34262 \end_layout
34263
34264 \begin_layout Itemize
34265 The <for body> does not contain 
34266 \begin_inset Quotes eld
34267 \end_inset
34268
34269 continue
34270 \begin_inset Quotes erd
34271 \end_inset
34272
34273  or 'break
34274 \begin_inset Quotes erd
34275 \end_inset
34276
34277 .
34278 \end_layout
34279
34280 \begin_layout Itemize
34281 All goto's are contained within the loop.
34282 \end_layout
34283
34284 \begin_layout Itemize
34285 No function calls within the loop.
34286 \end_layout
34287
34288 \begin_layout Itemize
34289 The loop control variable <sym> is not assigned any value within the loop
34290 \end_layout
34291
34292 \begin_layout Itemize
34293 The loop control variable does NOT participate in any arithmetic operation
34294  within the loop.
34295 \end_layout
34296
34297 \begin_layout Itemize
34298 There are NO switch statements in the loop.
34299 \end_layout
34300
34301 \begin_layout Subsection
34302 Algebraic Simplifications
34303 \end_layout
34304
34305 \begin_layout Standard
34306 SDCC does numerous algebraic simplifications, the following is a small sub-set
34307  of these optimizations.
34308 \end_layout
34309
34310 \begin_layout Verse
34311
34312 \family typewriter
34313 i = j + 0;\InsetSpace ~
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 \InsetSpace ~
34317  /* changed to: */\InsetSpace ~
34318 \InsetSpace ~
34319 \InsetSpace ~
34320 \InsetSpace ~
34321  i = j; 
34322 \newline
34323 i /= 2;\InsetSpace ~
34324 \InsetSpace ~
34325 \InsetSpace ~
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 \InsetSpace ~
34330  /* changed to: */\InsetSpace ~
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334  i >>= 1; 
34335 \newline
34336 i
34337  = j - j;\InsetSpace ~
34338 \InsetSpace ~
34339 \InsetSpace ~
34340 \InsetSpace ~
34341  /* changed to: */\InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345  i = 0; 
34346 \newline
34347 i = j / 1;\InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351  /* changed to: */\InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355  i = j;
34356 \end_layout
34357
34358 \begin_layout Standard
34359 Note the subexpressions
34360 \begin_inset LatexCommand \index{Subexpression}
34361
34362 \end_inset
34363
34364  given above are generally introduced by macro expansions or as a result
34365  of copy/constant propagation.
34366 \end_layout
34367
34368 \begin_layout Subsection
34369 'switch' Statements
34370 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34371
34372 \end_inset
34373
34374
34375 \begin_inset LatexCommand \index{switch statement}
34376
34377 \end_inset
34378
34379
34380 \end_layout
34381
34382 \begin_layout Standard
34383 SDCC can optimize switch statements to jump tables
34384 \begin_inset LatexCommand \index{jump tables}
34385
34386 \end_inset
34387
34388 .
34389  It makes the decision based on an estimate of the generated code size.
34390  SDCC is quite liberal in the requirements for jump table generation: 
34391 \end_layout
34392
34393 \begin_layout Itemize
34394 The labels need not be in order, and the starting number need not be one
34395  or zero, the case labels are in numerical sequence or not too many case
34396  labels are missing.
34397 \end_layout
34398
34399 \begin_deeper
34400 \begin_layout Verse
34401
34402 \family typewriter
34403 switch(i) {\InsetSpace ~
34404 \InsetSpace ~
34405 \InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411 \InsetSpace ~
34412 \InsetSpace ~
34413 \InsetSpace ~
34414 \InsetSpace ~
34415 \InsetSpace ~
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421 \InsetSpace ~
34422 \InsetSpace ~
34423 \InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426 \InsetSpace ~
34427 \InsetSpace ~
34428 \InsetSpace ~
34429 switch (i) { 
34430 \newline
34431 \InsetSpace ~
34432 \InsetSpace ~
34433 \InsetSpace ~
34434 case 4: ...\InsetSpace ~
34435 \InsetSpace ~
34436 \InsetSpace ~
34437 \InsetSpace ~
34438 \InsetSpace ~
34439 \InsetSpace ~
34440 \InsetSpace ~
34441 \InsetSpace ~
34442 \InsetSpace ~
34443 \InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450 \InsetSpace ~
34451 \InsetSpace ~
34452 \InsetSpace ~
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457 \InsetSpace ~
34458 \InsetSpace ~
34459 \InsetSpace ~
34460 case 0: ...
34461  
34462 \newline
34463 \InsetSpace ~
34464 \InsetSpace ~
34465 \InsetSpace ~
34466 case 5: ...\InsetSpace ~
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 \InsetSpace ~
34470 \InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 \InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 \InsetSpace ~
34487 \InsetSpace ~
34488 \InsetSpace ~
34489 \InsetSpace ~
34490 \InsetSpace ~
34491 \InsetSpace ~
34492 case 1: ...
34493  
34494 \newline
34495 \InsetSpace ~
34496 \InsetSpace ~
34497 \InsetSpace ~
34498 case 3: ...\InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
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 \InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521 \InsetSpace ~
34522 \InsetSpace ~
34523 \InsetSpace ~
34524
34525 \newline
34526 \InsetSpace ~
34527 \InsetSpace ~
34528 \InsetSpace ~
34529 case 6: ...\InsetSpace ~
34530 \InsetSpace ~
34531 \InsetSpace ~
34532 \InsetSpace ~
34533 \InsetSpace ~
34534 \InsetSpace ~
34535 \InsetSpace ~
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539 \InsetSpace ~
34540 \InsetSpace ~
34541 \InsetSpace ~
34542 \InsetSpace ~
34543 \InsetSpace ~
34544 \InsetSpace ~
34545 \InsetSpace ~
34546 \InsetSpace ~
34547 \InsetSpace ~
34548 \InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 \InsetSpace ~
34554 \InsetSpace ~
34555 case 3: ...
34556  
34557 \newline
34558 \InsetSpace ~
34559 \InsetSpace ~
34560 \InsetSpace ~
34561 case 7: ...\InsetSpace ~
34562 \InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 \InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 \InsetSpace ~
34570 \InsetSpace ~
34571 \InsetSpace ~
34572 \InsetSpace ~
34573 \InsetSpace ~
34574 \InsetSpace ~
34575 \InsetSpace ~
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 case 4: ...
34588  
34589 \newline
34590 \InsetSpace ~
34591 \InsetSpace ~
34592 \InsetSpace ~
34593 case 8: ...\InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 \InsetSpace ~
34598 \InsetSpace ~
34599 \InsetSpace ~
34600 \InsetSpace ~
34601 \InsetSpace ~
34602 \InsetSpace ~
34603 \InsetSpace ~
34604 \InsetSpace ~
34605 \InsetSpace ~
34606 \InsetSpace ~
34607 \InsetSpace ~
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 \InsetSpace ~
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617 \InsetSpace ~
34618 \InsetSpace ~
34619 case 5: ...
34620  
34621 \newline
34622 \InsetSpace ~
34623 \InsetSpace ~
34624 \InsetSpace ~
34625 case 9: ...\InsetSpace ~
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 \InsetSpace ~
34630 \InsetSpace ~
34631 \InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 case 6: ...
34652  
34653 \newline
34654 \InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657 case 10: ...\InsetSpace ~
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 \InsetSpace ~
34661 \InsetSpace ~
34662 \InsetSpace ~
34663 \InsetSpace ~
34664 \InsetSpace ~
34665 \InsetSpace ~
34666 \InsetSpace ~
34667 \InsetSpace ~
34668 \InsetSpace ~
34669 \InsetSpace ~
34670 \InsetSpace ~
34671 \InsetSpace ~
34672 \InsetSpace ~
34673 \InsetSpace ~
34674 \InsetSpace ~
34675 \InsetSpace ~
34676 \InsetSpace ~
34677 \InsetSpace ~
34678 \InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 case 7: ...
34683  
34684 \newline
34685 \InsetSpace ~
34686 \InsetSpace ~
34687 \InsetSpace ~
34688 case 11: ...\InsetSpace ~
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 \InsetSpace ~
34703 \InsetSpace ~
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713 case 8: ...
34714  
34715 \newline
34716 }\InsetSpace ~
34717 \InsetSpace ~
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729 \InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739 \InsetSpace ~
34740 \InsetSpace ~
34741 \InsetSpace ~
34742 \InsetSpace ~
34743 \InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 }
34753 \end_layout
34754
34755 \begin_layout Standard
34756 Both the above switch statements will be implemented using a jump-table.
34757  The example to the right side is slightly more efficient as the check for
34758  the lower boundary of the jump-table is not needed.
34759 \end_layout
34760
34761 \end_deeper
34762 \begin_layout Itemize
34763 The number of case labels is not larger than supported by the target architectur
34764 e.
34765 \end_layout
34766
34767 \begin_layout Itemize
34768 If the case labels are not in numerical sequence ('gaps' between cases)
34769  SDCC checks whether a jump table with additionally inserted dummy cases
34770  is still attractive.
34771  
34772 \end_layout
34773
34774 \begin_layout Itemize
34775 If the starting number is not zero and a check for the lower boundary of
34776  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34777  ...
34778  .
34779 \end_layout
34780
34781 \begin_layout Standard
34782 Switch statements which have large gaps in the numeric sequence or those
34783  that have too many case labels can be split into more than one switch statement
34784  for efficient code generation, e.g.:
34785 \end_layout
34786
34787 \begin_layout Verse
34788
34789 \family typewriter
34790 switch (i) { 
34791 \newline
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 case 1: ...
34795  
34796 \newline
34797 \InsetSpace ~
34798 \InsetSpace ~
34799 case 2: ...
34800  
34801 \newline
34802 \InsetSpace ~
34803 \InsetSpace ~
34804 case 3: ...
34805  
34806 \newline
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 case 4: ...
34810  
34811 \newline
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 case 5: ...
34815  
34816 \newline
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 case 6: ...
34820  
34821 \newline
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 case 7: ...
34825  
34826 \newline
34827 \InsetSpace ~
34828 \InsetSpace ~
34829 case 101: ...
34830  
34831 \newline
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 case 102: ...
34835  
34836 \newline
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 case 103: ...
34840  
34841 \newline
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 case 104: ...
34845  
34846 \newline
34847 \InsetSpace ~
34848 \InsetSpace ~
34849 case 105: ...
34850  
34851 \newline
34852 \InsetSpace ~
34853 \InsetSpace ~
34854 case 106: ...
34855  
34856 \newline
34857 \InsetSpace ~
34858 \InsetSpace ~
34859 case 107: ...
34860  
34861 \newline
34862 }
34863 \end_layout
34864
34865 \begin_layout Standard
34866 If the above switch statement is broken down into two switch statements
34867 \end_layout
34868
34869 \begin_layout Verse
34870
34871 \family typewriter
34872 switch (i) { 
34873 \newline
34874 \InsetSpace ~
34875 \InsetSpace ~
34876 case 1: ...
34877  
34878 \newline
34879 \InsetSpace ~
34880 \InsetSpace ~
34881 case 2: ...
34882  
34883 \newline
34884 \InsetSpace ~
34885 \InsetSpace ~
34886 case 3: ...
34887  
34888 \newline
34889 \InsetSpace ~
34890 \InsetSpace ~
34891 case 4: ...
34892  
34893 \newline
34894 \InsetSpace ~
34895 \InsetSpace ~
34896 case 5: ...
34897  
34898 \newline
34899 \InsetSpace ~
34900 \InsetSpace ~
34901 case 6: ...
34902  
34903 \newline
34904 \InsetSpace ~
34905 \InsetSpace ~
34906 case 7: ...
34907  
34908 \newline
34909 }
34910 \end_layout
34911
34912 \begin_layout Standard
34913 and
34914 \end_layout
34915
34916 \begin_layout Verse
34917
34918 \family typewriter
34919 switch (i) { 
34920 \newline
34921 \InsetSpace ~
34922 \InsetSpace ~
34923 case 101: ...
34924  
34925 \newline
34926 \InsetSpace ~
34927 \InsetSpace ~
34928 case 102: ...
34929  
34930 \newline
34931 \InsetSpace ~
34932 \InsetSpace ~
34933 case 103: ...
34934  
34935 \newline
34936 \InsetSpace ~
34937 \InsetSpace ~
34938 case 104: ...
34939  
34940 \newline
34941 \InsetSpace ~
34942 \InsetSpace ~
34943 case 105: ...
34944  
34945 \newline
34946 \InsetSpace ~
34947 \InsetSpace ~
34948 case 106: ...
34949  
34950 \newline
34951 \InsetSpace ~
34952 \InsetSpace ~
34953 case 107: ...
34954  
34955 \newline
34956 }
34957 \end_layout
34958
34959 \begin_layout Standard
34960 then both the switch statements will be implemented using jump-tables whereas
34961  the unmodified switch statement will not be.
34962 \end_layout
34963
34964 \begin_layout Standard
34965 \begin_inset Note Note
34966 status collapsed
34967
34968 \begin_layout Standard
34969 There might be reasons which SDCC cannot know about to either favour or
34970  not favour jump tables.
34971  If the target system has to be as quick for the last switch case as for
34972  the first (pro jump table), or if the switch argument is known to be zero
34973  in the majority of the cases (contra jump table).
34974 \end_layout
34975
34976 \end_inset
34977
34978
34979 \end_layout
34980
34981 \begin_layout Standard
34982 The pragma nojtbound
34983 \begin_inset LatexCommand \index{\#pragma nojtbound}
34984
34985 \end_inset
34986
34987  can be used to turn off checking the 
34988 \emph on
34989 j
34990 \emph default
34991 ump 
34992 \emph on
34993 t
34994 \emph default
34995 able 
34996 \emph on
34997 bound
34998 \emph default
34999 aries.
35000  It has no effect if a default label is supplied.
35001  Use of this pragma is dangerous: if the switch
35002 \begin_inset LatexCommand \index{switch statement}
35003
35004 \end_inset
35005
35006  argument is not matched by a case statement the processor will happily
35007  jump into Nirvana.
35008 \end_layout
35009
35010 \begin_layout Subsection
35011 Bit-shifting Operations
35012 \begin_inset LatexCommand \index{Bit shifting}
35013
35014 \end_inset
35015
35016 .
35017 \end_layout
35018
35019 \begin_layout Standard
35020 Bit shifting is one of the most frequently used operation in embedded programmin
35021 g.
35022  SDCC tries to implement bit-shift operations in the most efficient way
35023  possible, e.g.:
35024 \end_layout
35025
35026 \begin_layout Verse
35027
35028 \family typewriter
35029 unsigned char i;
35030 \newline
35031 ...
35032  
35033 \newline
35034 i >>= 4; 
35035 \newline
35036 ...
35037 \end_layout
35038
35039 \begin_layout Standard
35040 generates the following code:
35041 \end_layout
35042
35043 \begin_layout Verse
35044
35045 \family typewriter
35046 mov\InsetSpace ~
35047  a,_i 
35048 \newline
35049 swap a 
35050 \newline
35051 anl\InsetSpace ~
35052  a,#0x0f 
35053 \newline
35054 mov\InsetSpace ~
35055  _i,a
35056 \end_layout
35057
35058 \begin_layout Standard
35059 In general SDCC will never setup a loop if the shift count is known.
35060  Another example:
35061 \end_layout
35062
35063 \begin_layout Verse
35064
35065 \family typewriter
35066 unsigned int i; 
35067 \newline
35068 ...
35069  
35070 \newline
35071 i >>= 9; 
35072 \newline
35073 ...
35074 \end_layout
35075
35076 \begin_layout Standard
35077 will generate:
35078 \end_layout
35079
35080 \begin_layout Verse
35081
35082 \family typewriter
35083 mov\InsetSpace ~
35084 \InsetSpace ~
35085 a,(_i + 1) 
35086 \newline
35087 mov\InsetSpace ~
35088 \InsetSpace ~
35089 (_i + 1),#0x00 
35090 \newline
35091 clr\InsetSpace ~
35092 \InsetSpace ~
35093
35094 \newline
35095 rrc\InsetSpace ~
35096 \InsetSpace ~
35097
35098 \newline
35099 mov\InsetSpace ~
35100 \InsetSpace ~
35101 _i,a
35102 \end_layout
35103
35104 \begin_layout Subsection
35105 Bit-rotation
35106 \begin_inset LatexCommand \index{Bit rotation}
35107
35108 \end_inset
35109
35110
35111 \end_layout
35112
35113 \begin_layout Standard
35114 A special case of the bit-shift operation is bit rotation
35115 \begin_inset LatexCommand \index{rotating bits}
35116
35117 \end_inset
35118
35119 , SDCC recognizes the following expression to be a left bit-rotation:
35120 \end_layout
35121
35122 \begin_layout Verse
35123
35124 \family typewriter
35125 \series bold
35126 unsigned
35127 \series default
35128 \InsetSpace ~
35129 \InsetSpace ~
35130 char i;\InsetSpace ~
35131 \InsetSpace ~
35132 \InsetSpace ~
35133 \InsetSpace ~
35134 \InsetSpace ~
35135 \InsetSpace ~
35136 \InsetSpace ~
35137 \InsetSpace ~
35138 \InsetSpace ~
35139 \InsetSpace ~
35140 \InsetSpace ~
35141 /* unsigned is needed for rotation */ 
35142 \newline
35143 ...
35144  
35145 \newline
35146 i = ((i << 1) | (i >> 7)); 
35147 \family default
35148
35149 \newline
35150
35151 \family typewriter
35152 ...
35153 \end_layout
35154
35155 \begin_layout Standard
35156 will generate the following code:
35157 \end_layout
35158
35159 \begin_layout Verse
35160
35161 \family typewriter
35162 mov\InsetSpace ~
35163 \InsetSpace ~
35164 a,_i 
35165 \newline
35166 rl\InsetSpace ~
35167 \InsetSpace ~
35168 \InsetSpace ~
35169
35170 \newline
35171 mov\InsetSpace ~
35172 \InsetSpace ~
35173 _i,a
35174 \end_layout
35175
35176 \begin_layout Standard
35177 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35178 ns of this case will also be recognized as bit-rotation, i.e.: 
35179 \end_layout
35180
35181 \begin_layout Verse
35182
35183 \family typewriter
35184 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35185 \end_layout
35186
35187 \begin_layout Subsection
35188 Nibble and Byte Swapping
35189 \end_layout
35190
35191 \begin_layout Standard
35192 Other special cases of the bit-shift operations are nibble or byte swapping
35193 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35194
35195 \end_inset
35196
35197 , SDCC recognizes the following expressions:
35198 \end_layout
35199
35200 \begin_layout Verse
35201
35202 \family typewriter
35203 \series bold
35204 unsigned
35205 \series default
35206 \InsetSpace ~
35207 \InsetSpace ~
35208 char i; 
35209 \newline
35210
35211 \series bold
35212 unsigned
35213 \series default
35214 \InsetSpace ~
35215 \InsetSpace ~
35216 int j; 
35217 \newline
35218 ...
35219  
35220 \newline
35221 i = ((i << 4) | (i >> 4)); 
35222 \family default
35223
35224 \newline
35225
35226 \family typewriter
35227 j = ((j << 8) | (j >> 8)); 
35228 \end_layout
35229
35230 \begin_layout Standard
35231 and generates a swap instruction for the nibble swapping
35232 \begin_inset LatexCommand \index{Nibble swapping}
35233
35234 \end_inset
35235
35236  or move instructions for the byte swapping
35237 \begin_inset LatexCommand \index{Byte swapping}
35238
35239 \end_inset
35240
35241 .
35242  The 
35243 \begin_inset Quotes sld
35244 \end_inset
35245
35246 j
35247 \begin_inset Quotes srd
35248 \end_inset
35249
35250  example can be used to convert from little to big-endian or vice versa.
35251  If you want to change the endianness of a 
35252 \emph on
35253 signed
35254 \emph default
35255  integer you have to cast to 
35256 \family typewriter
35257 (unsigned int)
35258 \family default
35259  first.
35260 \end_layout
35261
35262 \begin_layout Standard
35263 Note that SDCC stores numbers in little-endian
35264 \begin_inset Foot
35265 status open
35266
35267 \begin_layout Standard
35268 Usually 8-bit processors don't care much about endianness.
35269  This is not the case for the standard 8051 which only has an instruction
35270  to increment its 
35271 \emph on
35272 dptr
35273 \emph default
35274
35275 \begin_inset LatexCommand \index{DPTR}
35276
35277 \end_inset
35278
35279 -datapointer
35280 \emph on
35281  
35282 \emph default
35283 so little-endian is the more efficient byte order.
35284 \end_layout
35285
35286 \end_inset
35287
35288
35289 \begin_inset LatexCommand \index{little-endian}
35290
35291 \end_inset
35292
35293
35294 \begin_inset LatexCommand \index{Endianness}
35295
35296 \end_inset
35297
35298  format (i.e.
35299  lowest order first).
35300 \end_layout
35301
35302 \begin_layout Subsection
35303 Highest Order Bit
35304 \begin_inset LatexCommand \index{Highest Order Bit}
35305
35306 \end_inset
35307
35308  / Any Order Bit
35309 \begin_inset LatexCommand \index{Any Order Bit}
35310
35311 \end_inset
35312
35313
35314 \end_layout
35315
35316 \begin_layout Standard
35317 It is frequently required to obtain the highest order bit of an integral
35318  type (long, int, short or char types).
35319  Also obtaining any other order bit is not uncommon.
35320  SDCC recognizes the following expressions to yield the highest order bit
35321  and generates optimized code for it, e.g.:
35322 \end_layout
35323
35324 \begin_layout Verse
35325
35326 \family typewriter
35327 unsigned int gint; 
35328 \newline
35329
35330 \newline
35331 foo () { 
35332 \newline
35333 \InsetSpace ~
35334 \InsetSpace ~
35335 unsigned char hob1, aob1; 
35336 \newline
35337 \InsetSpace ~
35338 \InsetSpace ~
35339 bit hob2, hob3, aob2,
35340  aob3; 
35341 \newline
35342 \InsetSpace ~
35343 \InsetSpace ~
35344 ...
35345  
35346 \newline
35347 \InsetSpace ~
35348 \InsetSpace ~
35349 hob1 = (gint >> 15) & 1; 
35350 \newline
35351 \InsetSpace ~
35352 \InsetSpace ~
35353 hob2 = (gint >> 15) & 1; 
35354 \newline
35355 \InsetSpace ~
35356 \InsetSpace ~
35357 hob3 = gint & 0x8000;
35358  
35359 \newline
35360 \InsetSpace ~
35361 \InsetSpace ~
35362 aob1 = (gint >> 9) & 1; 
35363 \newline
35364 \InsetSpace ~
35365 \InsetSpace ~
35366 aob2 = (gint >> 8) & 1; 
35367 \newline
35368 \InsetSpace ~
35369 \InsetSpace ~
35370 aob3 = gint & 0x0800; 
35371 \newline
35372 \InsetSpace ~
35373 \InsetSpace ~
35374 ..
35375  
35376 \newline
35377 }
35378 \end_layout
35379
35380 \begin_layout Standard
35381 will generate the following code:
35382 \end_layout
35383
35384 \begin_layout Verse
35385
35386 \family typewriter
35387 \InsetSpace ~
35388 \InsetSpace ~
35389 \InsetSpace ~
35390 \InsetSpace ~
35391 \InsetSpace ~
35392 \InsetSpace ~
35393 \InsetSpace ~
35394 \InsetSpace ~
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 \InsetSpace ~
35398 \InsetSpace ~
35399 \InsetSpace ~
35400 \InsetSpace ~
35401 \InsetSpace ~
35402 \InsetSpace ~
35403 \InsetSpace ~
35404 \InsetSpace ~
35405 \InsetSpace ~
35406 \InsetSpace ~
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 \InsetSpace ~
35410 \InsetSpace ~
35411 \InsetSpace ~
35412  61 ;\InsetSpace ~
35413  hob.c 7 
35414 \newline
35415 000A E5*01\InsetSpace ~
35416 \InsetSpace ~
35417 \InsetSpace ~
35418 \InsetSpace ~
35419 \InsetSpace ~
35420 \InsetSpace ~
35421 \InsetSpace ~
35422 \InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426 \InsetSpace ~
35427 \InsetSpace ~
35428 \InsetSpace ~
35429 \InsetSpace ~
35430  62\InsetSpace ~
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 \InsetSpace ~
35438  mov\InsetSpace ~
35439 \InsetSpace ~
35440  a,(_gint + 1) 
35441 \newline
35442 000C 23\InsetSpace ~
35443 \InsetSpace ~
35444 \InsetSpace ~
35445 \InsetSpace ~
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 \InsetSpace ~
35454 \InsetSpace ~
35455 \InsetSpace ~
35456 \InsetSpace ~
35457 \InsetSpace ~
35458 \InsetSpace ~
35459 \InsetSpace ~
35460  63\InsetSpace ~
35461 \InsetSpace ~
35462 \InsetSpace ~
35463 \InsetSpace ~
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468  rl\InsetSpace ~
35469 \InsetSpace ~
35470 \InsetSpace ~
35471  a 
35472 \newline
35473 000D 54 01\InsetSpace ~
35474 \InsetSpace ~
35475 \InsetSpace ~
35476 \InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 \InsetSpace ~
35481 \InsetSpace ~
35482 \InsetSpace ~
35483 \InsetSpace ~
35484 \InsetSpace ~
35485 \InsetSpace ~
35486 \InsetSpace ~
35487 \InsetSpace ~
35488
35489  64\InsetSpace ~
35490 \InsetSpace ~
35491 \InsetSpace ~
35492 \InsetSpace ~
35493 \InsetSpace ~
35494 \InsetSpace ~
35495 \InsetSpace ~
35496 \InsetSpace ~
35497  anl\InsetSpace ~
35498 \InsetSpace ~
35499  a,#0x01 
35500 \newline
35501 000F F5*02\InsetSpace ~
35502 \InsetSpace ~
35503 \InsetSpace ~
35504 \InsetSpace ~
35505 \InsetSpace ~
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510 \InsetSpace ~
35511 \InsetSpace ~
35512 \InsetSpace ~
35513 \InsetSpace ~
35514 \InsetSpace ~
35515 \InsetSpace ~
35516  65\InsetSpace ~
35517 \InsetSpace ~
35518 \InsetSpace ~
35519 \InsetSpace ~
35520 \InsetSpace ~
35521 \InsetSpace ~
35522 \InsetSpace ~
35523 \InsetSpace ~
35524  mov\InsetSpace ~
35525 \InsetSpace ~
35526  _foo_hob1_1_1,a 
35527 \newline
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 \InsetSpace ~
35531 \InsetSpace ~
35532 \InsetSpace ~
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 \InsetSpace ~
35539 \InsetSpace ~
35540 \InsetSpace ~
35541 \InsetSpace ~
35542 \InsetSpace ~
35543 \InsetSpace ~
35544 \InsetSpace ~
35545 \InsetSpace ~
35546 \InsetSpace ~
35547 \InsetSpace ~
35548 \InsetSpace ~
35549 \InsetSpace ~
35550 \InsetSpace ~
35551 \InsetSpace ~
35552 \InsetSpace ~
35553  66 ;\InsetSpace ~
35554  hob.c 8 
35555 \newline
35556 0011 E5*01\InsetSpace ~
35557 \InsetSpace ~
35558 \InsetSpace ~
35559 \InsetSpace ~
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 \InsetSpace ~
35569 \InsetSpace ~
35570 \InsetSpace ~
35571
35572  67\InsetSpace ~
35573 \InsetSpace ~
35574 \InsetSpace ~
35575 \InsetSpace ~
35576 \InsetSpace ~
35577 \InsetSpace ~
35578 \InsetSpace ~
35579 \InsetSpace ~
35580  mov\InsetSpace ~
35581 \InsetSpace ~
35582  a,(_gint + 1) 
35583 \newline
35584 0013 33\InsetSpace ~
35585 \InsetSpace ~
35586 \InsetSpace ~
35587 \InsetSpace ~
35588 \InsetSpace ~
35589 \InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 \InsetSpace ~
35593 \InsetSpace ~
35594 \InsetSpace ~
35595 \InsetSpace ~
35596 \InsetSpace ~
35597 \InsetSpace ~
35598 \InsetSpace ~
35599 \InsetSpace ~
35600 \InsetSpace ~
35601 \InsetSpace ~
35602  68\InsetSpace ~
35603 \InsetSpace ~
35604 \InsetSpace ~
35605 \InsetSpace ~
35606 \InsetSpace ~
35607 \InsetSpace ~
35608 \InsetSpace ~
35609 \InsetSpace ~
35610  rlc\InsetSpace ~
35611 \InsetSpace ~
35612  a 
35613 \newline
35614 0014 92*00\InsetSpace ~
35615 \InsetSpace ~
35616 \InsetSpace ~
35617 \InsetSpace ~
35618 \InsetSpace ~
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623 \InsetSpace ~
35624 \InsetSpace ~
35625 \InsetSpace ~
35626 \InsetSpace ~
35627 \InsetSpace ~
35628 \InsetSpace ~
35629  69\InsetSpace ~
35630 \InsetSpace ~
35631 \InsetSpace ~
35632 \InsetSpace ~
35633 \InsetSpace ~
35634 \InsetSpace ~
35635 \InsetSpace ~
35636 \InsetSpace ~
35637  mov\InsetSpace ~
35638 \InsetSpace ~
35639  _foo_hob2_1_1,c
35640  
35641 \newline
35642 \InsetSpace ~
35643 \InsetSpace ~
35644 \InsetSpace ~
35645 \InsetSpace ~
35646 \InsetSpace ~
35647 \InsetSpace ~
35648 \InsetSpace ~
35649 \InsetSpace ~
35650 \InsetSpace ~
35651 \InsetSpace ~
35652 \InsetSpace ~
35653 \InsetSpace ~
35654 \InsetSpace ~
35655 \InsetSpace ~
35656 \InsetSpace ~
35657 \InsetSpace ~
35658 \InsetSpace ~
35659 \InsetSpace ~
35660 \InsetSpace ~
35661 \InsetSpace ~
35662 \InsetSpace ~
35663 \InsetSpace ~
35664 \InsetSpace ~
35665 \InsetSpace ~
35666 \InsetSpace ~
35667  66 ;\InsetSpace ~
35668  hob.c 9 
35669 \newline
35670 0016 E5*01\InsetSpace ~
35671 \InsetSpace ~
35672 \InsetSpace ~
35673 \InsetSpace ~
35674 \InsetSpace ~
35675 \InsetSpace ~
35676 \InsetSpace ~
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681 \InsetSpace ~
35682 \InsetSpace ~
35683 \InsetSpace ~
35684 \InsetSpace ~
35685  67\InsetSpace ~
35686 \InsetSpace ~
35687 \InsetSpace ~
35688 \InsetSpace ~
35689 \InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 \InsetSpace ~
35693  mov\InsetSpace ~
35694 \InsetSpace ~
35695  a,(_gint + 1) 
35696 \newline
35697 0018 33\InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700 \InsetSpace ~
35701 \InsetSpace ~
35702 \InsetSpace ~
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707 \InsetSpace ~
35708 \InsetSpace ~
35709 \InsetSpace ~
35710 \InsetSpace ~
35711 \InsetSpace ~
35712 \InsetSpace ~
35713 \InsetSpace ~
35714 \InsetSpace ~
35715  68\InsetSpace ~
35716 \InsetSpace ~
35717 \InsetSpace ~
35718 \InsetSpace ~
35719 \InsetSpace ~
35720 \InsetSpace ~
35721 \InsetSpace ~
35722 \InsetSpace ~
35723  rlc\InsetSpace ~
35724 \InsetSpace ~
35725  a 
35726 \newline
35727 0019 92*01\InsetSpace ~
35728 \InsetSpace ~
35729 \InsetSpace ~
35730 \InsetSpace ~
35731 \InsetSpace ~
35732 \InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736 \InsetSpace ~
35737 \InsetSpace ~
35738 \InsetSpace ~
35739 \InsetSpace ~
35740 \InsetSpace ~
35741 \InsetSpace ~
35742
35743  69\InsetSpace ~
35744 \InsetSpace ~
35745 \InsetSpace ~
35746 \InsetSpace ~
35747 \InsetSpace ~
35748 \InsetSpace ~
35749 \InsetSpace ~
35750 \InsetSpace ~
35751  mov\InsetSpace ~
35752 \InsetSpace ~
35753  _foo_hob3_1_1,c 
35754 \newline
35755 \InsetSpace ~
35756 \InsetSpace ~
35757 \InsetSpace ~
35758 \InsetSpace ~
35759 \InsetSpace ~
35760 \InsetSpace ~
35761 \InsetSpace ~
35762 \InsetSpace ~
35763 \InsetSpace ~
35764 \InsetSpace ~
35765 \InsetSpace ~
35766 \InsetSpace ~
35767 \InsetSpace ~
35768 \InsetSpace ~
35769 \InsetSpace ~
35770 \InsetSpace ~
35771 \InsetSpace ~
35772 \InsetSpace ~
35773 \InsetSpace ~
35774 \InsetSpace ~
35775 \InsetSpace ~
35776 \InsetSpace ~
35777 \InsetSpace ~
35778 \InsetSpace ~
35779 \InsetSpace ~
35780  70 ;\InsetSpace ~
35781  hob.c 10 
35782 \newline
35783 001B E5*01\InsetSpace ~
35784 \InsetSpace ~
35785 \InsetSpace ~
35786 \InsetSpace ~
35787 \InsetSpace ~
35788 \InsetSpace ~
35789 \InsetSpace ~
35790 \InsetSpace ~
35791 \InsetSpace ~
35792 \InsetSpace ~
35793 \InsetSpace ~
35794 \InsetSpace ~
35795 \InsetSpace ~
35796 \InsetSpace ~
35797 \InsetSpace ~
35798  71\InsetSpace ~
35799 \InsetSpace ~
35800 \InsetSpace ~
35801 \InsetSpace ~
35802 \InsetSpace ~
35803 \InsetSpace ~
35804 \InsetSpace ~
35805 \InsetSpace ~
35806  mov\InsetSpace ~
35807 \InsetSpace ~
35808  a,(_gint + 1) 
35809 \newline
35810 001D
35811  03\InsetSpace ~
35812 \InsetSpace ~
35813 \InsetSpace ~
35814 \InsetSpace ~
35815 \InsetSpace ~
35816 \InsetSpace ~
35817 \InsetSpace ~
35818 \InsetSpace ~
35819 \InsetSpace ~
35820 \InsetSpace ~
35821 \InsetSpace ~
35822 \InsetSpace ~
35823 \InsetSpace ~
35824 \InsetSpace ~
35825 \InsetSpace ~
35826 \InsetSpace ~
35827 \InsetSpace ~
35828 \InsetSpace ~
35829  72\InsetSpace ~
35830 \InsetSpace ~
35831 \InsetSpace ~
35832 \InsetSpace ~
35833 \InsetSpace ~
35834 \InsetSpace ~
35835 \InsetSpace ~
35836 \InsetSpace ~
35837  rr\InsetSpace ~
35838 \InsetSpace ~
35839 \InsetSpace ~
35840  a 
35841 \newline
35842 001E 54 01\InsetSpace ~
35843 \InsetSpace ~
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 \InsetSpace ~
35850 \InsetSpace ~
35851 \InsetSpace ~
35852 \InsetSpace ~
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 \InsetSpace ~
35856 \InsetSpace ~
35857  73\InsetSpace ~
35858 \InsetSpace ~
35859 \InsetSpace ~
35860 \InsetSpace ~
35861 \InsetSpace ~
35862 \InsetSpace ~
35863 \InsetSpace ~
35864 \InsetSpace ~
35865  anl\InsetSpace ~
35866 \InsetSpace ~
35867  a,#0x01 
35868 \newline
35869 0020 F5*03\InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872 \InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884  74\InsetSpace ~
35885 \InsetSpace ~
35886 \InsetSpace ~
35887 \InsetSpace ~
35888 \InsetSpace ~
35889 \InsetSpace ~
35890 \InsetSpace ~
35891 \InsetSpace ~
35892  mov\InsetSpace ~
35893 \InsetSpace ~
35894  _foo_aob1_1_1,a
35895  
35896 \newline
35897 \InsetSpace ~
35898 \InsetSpace ~
35899 \InsetSpace ~
35900 \InsetSpace ~
35901 \InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 \InsetSpace ~
35907 \InsetSpace ~
35908 \InsetSpace ~
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 \InsetSpace ~
35912 \InsetSpace ~
35913 \InsetSpace ~
35914 \InsetSpace ~
35915 \InsetSpace ~
35916 \InsetSpace ~
35917 \InsetSpace ~
35918 \InsetSpace ~
35919 \InsetSpace ~
35920 \InsetSpace ~
35921 \InsetSpace ~
35922  75 ;\InsetSpace ~
35923  hob.c 11 
35924 \newline
35925 0022 E5*01\InsetSpace ~
35926 \InsetSpace ~
35927 \InsetSpace ~
35928 \InsetSpace ~
35929 \InsetSpace ~
35930 \InsetSpace ~
35931 \InsetSpace ~
35932 \InsetSpace ~
35933 \InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936 \InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940  76\InsetSpace ~
35941 \InsetSpace ~
35942 \InsetSpace ~
35943 \InsetSpace ~
35944 \InsetSpace ~
35945 \InsetSpace ~
35946 \InsetSpace ~
35947 \InsetSpace ~
35948  mov\InsetSpace ~
35949 \InsetSpace ~
35950  a,(_gint + 1) 
35951 \newline
35952 0024 13\InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956 \InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \InsetSpace ~
35960 \InsetSpace ~
35961 \InsetSpace ~
35962 \InsetSpace ~
35963 \InsetSpace ~
35964 \InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969 \InsetSpace ~
35970  77\InsetSpace ~
35971 \InsetSpace ~
35972 \InsetSpace ~
35973 \InsetSpace ~
35974 \InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 \InsetSpace ~
35978  rrc\InsetSpace ~
35979 \InsetSpace ~
35980  a 
35981 \newline
35982 0025 92*02\InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 \InsetSpace ~
35991 \InsetSpace ~
35992 \InsetSpace ~
35993 \InsetSpace ~
35994 \InsetSpace ~
35995 \InsetSpace ~
35996 \InsetSpace ~
35997
35998  78\InsetSpace ~
35999 \InsetSpace ~
36000 \InsetSpace ~
36001 \InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 \InsetSpace ~
36006  mov\InsetSpace ~
36007 \InsetSpace ~
36008  _foo_aob2_1_1,c 
36009 \newline
36010 \InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019 \InsetSpace ~
36020 \InsetSpace ~
36021 \InsetSpace ~
36022 \InsetSpace ~
36023 \InsetSpace ~
36024 \InsetSpace ~
36025 \InsetSpace ~
36026 \InsetSpace ~
36027 \InsetSpace ~
36028 \InsetSpace ~
36029 \InsetSpace ~
36030 \InsetSpace ~
36031 \InsetSpace ~
36032 \InsetSpace ~
36033 \InsetSpace ~
36034 \InsetSpace ~
36035  79 ;\InsetSpace ~
36036  hob.c 12 
36037 \newline
36038 0027 E5*01\InsetSpace ~
36039 \InsetSpace ~
36040 \InsetSpace ~
36041 \InsetSpace ~
36042 \InsetSpace ~
36043 \InsetSpace ~
36044 \InsetSpace ~
36045 \InsetSpace ~
36046 \InsetSpace ~
36047 \InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050 \InsetSpace ~
36051 \InsetSpace ~
36052 \InsetSpace ~
36053  80\InsetSpace ~
36054 \InsetSpace ~
36055 \InsetSpace ~
36056 \InsetSpace ~
36057 \InsetSpace ~
36058 \InsetSpace ~
36059 \InsetSpace ~
36060 \InsetSpace ~
36061  mov\InsetSpace ~
36062 \InsetSpace ~
36063  a,(_gint + 1) 
36064 \newline
36065 0029
36066  A2 E3\InsetSpace ~
36067 \InsetSpace ~
36068 \InsetSpace ~
36069 \InsetSpace ~
36070 \InsetSpace ~
36071 \InsetSpace ~
36072 \InsetSpace ~
36073 \InsetSpace ~
36074 \InsetSpace ~
36075 \InsetSpace ~
36076 \InsetSpace ~
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 \InsetSpace ~
36081  81\InsetSpace ~
36082 \InsetSpace ~
36083 \InsetSpace ~
36084 \InsetSpace ~
36085 \InsetSpace ~
36086 \InsetSpace ~
36087 \InsetSpace ~
36088 \InsetSpace ~
36089  mov\InsetSpace ~
36090 \InsetSpace ~
36091  c,acc[3] 
36092 \newline
36093 002B 92*03\InsetSpace ~
36094 \InsetSpace ~
36095 \InsetSpace ~
36096 \InsetSpace ~
36097 \InsetSpace ~
36098 \InsetSpace ~
36099 \InsetSpace ~
36100 \InsetSpace ~
36101 \InsetSpace ~
36102 \InsetSpace ~
36103 \InsetSpace ~
36104 \InsetSpace ~
36105 \InsetSpace ~
36106 \InsetSpace ~
36107 \InsetSpace ~
36108  82\InsetSpace ~
36109 \InsetSpace ~
36110 \InsetSpace ~
36111 \InsetSpace ~
36112 \InsetSpace ~
36113 \InsetSpace ~
36114 \InsetSpace ~
36115 \InsetSpace ~
36116  mov\InsetSpace ~
36117 \InsetSpace ~
36118  _foo_aob3_1_1,c 
36119 \end_layout
36120
36121 \begin_layout Standard
36122 Other variations of these cases however will 
36123 \emph on
36124 not
36125 \emph default
36126  be recognized.
36127  They are standard C expressions, so I heartily recommend these be the only
36128  way to get the highest order bit, (it is portable).
36129  Of course it will be recognized even if it is embedded in other expressions,
36130  e.g.:
36131 \end_layout
36132
36133 \begin_layout Verse
36134
36135 \family typewriter
36136 xyz = gint + ((gint >> 15) & 1);
36137 \end_layout
36138
36139 \begin_layout Standard
36140 will still be recognized.
36141 \end_layout
36142
36143 \begin_layout Subsection
36144 Higher Order Byte
36145 \begin_inset LatexCommand \index{Higher Order Byte}
36146
36147 \end_inset
36148
36149  / Higher Order Word
36150 \begin_inset LatexCommand \index{Higher Order Word}
36151
36152 \end_inset
36153
36154
36155 \end_layout
36156
36157 \begin_layout Standard
36158 It is also frequently required to obtain a higher order byte or word of
36159  a larger integral type (long, int or short types).
36160  SDCC recognizes the following expressions to yield the higher order byte
36161  or word and generates optimized code for it, e.g.:
36162 \end_layout
36163
36164 \begin_layout Verse
36165
36166 \family typewriter
36167 unsigned int gint; 
36168 \newline
36169 unsigned long int glong; 
36170 \newline
36171
36172 \newline
36173 foo () { 
36174 \newline
36175 \InsetSpace ~
36176 \InsetSpace ~
36177 unsigned char hob1,
36178  hob2; 
36179 \newline
36180 \InsetSpace ~
36181 \InsetSpace ~
36182 unsigned int how1, how2; 
36183 \newline
36184 \InsetSpace ~
36185 \InsetSpace ~
36186 ...
36187  
36188 \newline
36189 \InsetSpace ~
36190 \InsetSpace ~
36191 hob1 = (gint >> 8) & 0xFF; 
36192 \newline
36193 \InsetSpace ~
36194 \InsetSpace ~
36195 hob2 = glong >> 24; 
36196 \newline
36197 \InsetSpace ~
36198 \InsetSpace ~
36199 how1 = (glong >> 16) & 0xFFFF;
36200  
36201 \newline
36202 \InsetSpace ~
36203 \InsetSpace ~
36204 how2 = glong >> 8; 
36205 \newline
36206 \InsetSpace ~
36207 \InsetSpace ~
36208 ..
36209  
36210 \newline
36211 }
36212 \end_layout
36213
36214 \begin_layout Standard
36215 will generate the following code:
36216 \end_layout
36217
36218 \begin_layout Verse
36219
36220 \family typewriter
36221 \InsetSpace ~
36222 \InsetSpace ~
36223 \InsetSpace ~
36224 \InsetSpace ~
36225 \InsetSpace ~
36226 \InsetSpace ~
36227 \InsetSpace ~
36228 \InsetSpace ~
36229 \InsetSpace ~
36230 \InsetSpace ~
36231 \InsetSpace ~
36232 \InsetSpace ~
36233 \InsetSpace ~
36234 \InsetSpace ~
36235 \InsetSpace ~
36236 \InsetSpace ~
36237 \InsetSpace ~
36238 \InsetSpace ~
36239 \InsetSpace ~
36240 \InsetSpace ~
36241 \InsetSpace ~
36242 \InsetSpace ~
36243 \InsetSpace ~
36244 \InsetSpace ~
36245 \InsetSpace ~
36246  91 ;\InsetSpace ~
36247  hob.c 15 
36248 \newline
36249 0037 85*01*06\InsetSpace ~
36250 \InsetSpace ~
36251 \InsetSpace ~
36252 \InsetSpace ~
36253 \InsetSpace ~
36254 \InsetSpace ~
36255 \InsetSpace ~
36256 \InsetSpace ~
36257 \InsetSpace ~
36258 \InsetSpace ~
36259 \InsetSpace ~
36260 \InsetSpace ~
36261  92\InsetSpace ~
36262 \InsetSpace ~
36263 \InsetSpace ~
36264 \InsetSpace ~
36265 \InsetSpace ~
36266 \InsetSpace ~
36267 \InsetSpace ~
36268 \InsetSpace ~
36269  mov\InsetSpace ~
36270 \InsetSpace ~
36271  _foo_hob1_1_1,(_gint + 1) 
36272 \newline
36273 \InsetSpace ~
36274 \InsetSpace ~
36275 \InsetSpace ~
36276 \InsetSpace ~
36277 \InsetSpace ~
36278 \InsetSpace ~
36279 \InsetSpace ~
36280 \InsetSpace ~
36281 \InsetSpace ~
36282 \InsetSpace ~
36283 \InsetSpace ~
36284 \InsetSpace ~
36285 \InsetSpace ~
36286 \InsetSpace ~
36287 \InsetSpace ~
36288 \InsetSpace ~
36289 \InsetSpace ~
36290 \InsetSpace ~
36291 \InsetSpace ~
36292 \InsetSpace ~
36293 \InsetSpace ~
36294 \InsetSpace ~
36295 \InsetSpace ~
36296 \InsetSpace ~
36297 \InsetSpace ~
36298  93 ;\InsetSpace ~
36299  hob.c
36300  16 
36301 \newline
36302 003A 85*05*07\InsetSpace ~
36303 \InsetSpace ~
36304 \InsetSpace ~
36305 \InsetSpace ~
36306 \InsetSpace ~
36307 \InsetSpace ~
36308 \InsetSpace ~
36309 \InsetSpace ~
36310 \InsetSpace ~
36311 \InsetSpace ~
36312 \InsetSpace ~
36313 \InsetSpace ~
36314  94\InsetSpace ~
36315 \InsetSpace ~
36316 \InsetSpace ~
36317 \InsetSpace ~
36318 \InsetSpace ~
36319 \InsetSpace ~
36320 \InsetSpace ~
36321 \InsetSpace ~
36322  mov\InsetSpace ~
36323 \InsetSpace ~
36324  _foo_hob2_1_1,(_glong + 3) 
36325 \newline
36326 \InsetSpace ~
36327 \InsetSpace ~
36328 \InsetSpace ~
36329 \InsetSpace ~
36330 \InsetSpace ~
36331 \InsetSpace ~
36332 \InsetSpace ~
36333 \InsetSpace ~
36334 \InsetSpace ~
36335 \InsetSpace ~
36336 \InsetSpace ~
36337 \InsetSpace ~
36338 \InsetSpace ~
36339 \InsetSpace ~
36340 \InsetSpace ~
36341 \InsetSpace ~
36342 \InsetSpace ~
36343 \InsetSpace ~
36344 \InsetSpace ~
36345 \InsetSpace ~
36346 \InsetSpace ~
36347 \InsetSpace ~
36348 \InsetSpace ~
36349 \InsetSpace ~
36350 \InsetSpace ~
36351  95 ;\InsetSpace ~
36352  hob.c 17 
36353 \newline
36354 003D 85*04*08\InsetSpace ~
36355 \InsetSpace ~
36356 \InsetSpace ~
36357 \InsetSpace ~
36358 \InsetSpace ~
36359 \InsetSpace ~
36360 \InsetSpace ~
36361 \InsetSpace ~
36362 \InsetSpace ~
36363 \InsetSpace ~
36364 \InsetSpace ~
36365 \InsetSpace ~
36366
36367  96\InsetSpace ~
36368 \InsetSpace ~
36369 \InsetSpace ~
36370 \InsetSpace ~
36371 \InsetSpace ~
36372 \InsetSpace ~
36373 \InsetSpace ~
36374 \InsetSpace ~
36375  mov\InsetSpace ~
36376 \InsetSpace ~
36377  _foo_how1_1_1,(_glong + 2) 
36378 \newline
36379 0040 85*05*09\InsetSpace ~
36380 \InsetSpace ~
36381 \InsetSpace ~
36382 \InsetSpace ~
36383 \InsetSpace ~
36384 \InsetSpace ~
36385 \InsetSpace ~
36386 \InsetSpace ~
36387 \InsetSpace ~
36388 \InsetSpace ~
36389 \InsetSpace ~
36390 \InsetSpace ~
36391  97\InsetSpace ~
36392 \InsetSpace ~
36393 \InsetSpace ~
36394 \InsetSpace ~
36395 \InsetSpace ~
36396 \InsetSpace ~
36397 \InsetSpace ~
36398 \InsetSpace ~
36399  mov\InsetSpace ~
36400 \InsetSpace ~
36401  (_foo_how1_1_1 +
36402  1),(_glong + 3) 
36403 \newline
36404 0043 85*03*0A\InsetSpace ~
36405 \InsetSpace ~
36406 \InsetSpace ~
36407 \InsetSpace ~
36408 \InsetSpace ~
36409 \InsetSpace ~
36410 \InsetSpace ~
36411 \InsetSpace ~
36412 \InsetSpace ~
36413 \InsetSpace ~
36414 \InsetSpace ~
36415 \InsetSpace ~
36416  98\InsetSpace ~
36417 \InsetSpace ~
36418 \InsetSpace ~
36419 \InsetSpace ~
36420 \InsetSpace ~
36421 \InsetSpace ~
36422 \InsetSpace ~
36423 \InsetSpace ~
36424  mov\InsetSpace ~
36425 \InsetSpace ~
36426  _foo_how2_1_1,(_glong + 1) 
36427 \newline
36428 0046 85*04*0B\InsetSpace ~
36429 \InsetSpace ~
36430 \InsetSpace ~
36431 \InsetSpace ~
36432 \InsetSpace ~
36433 \InsetSpace ~
36434 \InsetSpace ~
36435 \InsetSpace ~
36436 \InsetSpace ~
36437 \InsetSpace ~
36438 \InsetSpace ~
36439 \InsetSpace ~
36440
36441  99\InsetSpace ~
36442 \InsetSpace ~
36443 \InsetSpace ~
36444 \InsetSpace ~
36445 \InsetSpace ~
36446 \InsetSpace ~
36447 \InsetSpace ~
36448 \InsetSpace ~
36449  mov\InsetSpace ~
36450 \InsetSpace ~
36451  (_foo_how2_1_1 + 1),(_glong + 2) 
36452 \end_layout
36453
36454 \begin_layout Standard
36455 Again, variations of these cases may 
36456 \emph on
36457 not
36458 \emph default
36459  be recognized.
36460  They are standard C expressions, so I heartily recommend these be the only
36461  way to get the higher order byte/word, (it is portable).
36462  Of course it will be recognized even if it is embedded in other expressions,
36463  e.g.:
36464 \end_layout
36465
36466 \begin_layout Verse
36467
36468 \family typewriter
36469 xyz = gint + ((gint >> 8) & 0xFF);
36470 \end_layout
36471
36472 \begin_layout Standard
36473 will still be recognized.
36474 \end_layout
36475
36476 \begin_layout Subsection
36477 Peephole Optimizer
36478 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36479
36480 \end_inset
36481
36482
36483 \begin_inset LatexCommand \index{Peephole optimizer}
36484
36485 \end_inset
36486
36487
36488 \end_layout
36489
36490 \begin_layout Standard
36491 The compiler uses a rule based, pattern matching and re-writing mechanism
36492  for peep-hole optimization.
36493  It is inspired by 
36494 \emph on
36495 copt
36496 \emph default
36497  a peep-hole optimizer by Christopher W.
36498  Fraser (cwfraser\InsetSpace ~
36499 @\InsetSpace ~
36500 microsoft.com).
36501  A default set of rules are compiled into the compiler, additional rules
36502  may be added with the 
36503 \emph on
36504 -
36505 \begin_inset ERT
36506 status collapsed
36507
36508 \begin_layout Standard
36509
36510
36511 \backslash
36512 /
36513 \end_layout
36514
36515 \end_inset
36516
36517 -peep-file
36518 \begin_inset LatexCommand \index{-\/-peep-file}
36519
36520 \end_inset
36521
36522  <filename>
36523 \emph default
36524  option.
36525  The rule language is best illustrated with examples.
36526 \end_layout
36527
36528 \begin_layout Verse
36529
36530 \family typewriter
36531 replace { 
36532 \newline
36533 \InsetSpace ~
36534 \InsetSpace ~
36535 mov %1,a 
36536 \newline
36537 \InsetSpace ~
36538 \InsetSpace ~
36539 mov a,%1
36540 \newline
36541 } by {
36542 \newline
36543 \InsetSpace ~
36544 \InsetSpace ~
36545 mov %1,a
36546 \newline
36547 }
36548 \end_layout
36549
36550 \begin_layout Standard
36551 The above rule will change the following assembly
36552 \begin_inset LatexCommand \index{Assembler routines}
36553
36554 \end_inset
36555
36556  sequence:
36557 \end_layout
36558
36559 \begin_layout Verse
36560
36561 \family typewriter
36562 mov r1,a 
36563 \newline
36564 mov a,r1
36565 \end_layout
36566
36567 \begin_layout Standard
36568 to
36569 \end_layout
36570
36571 \begin_layout Verse
36572
36573 \family typewriter
36574 mov r1,a
36575 \end_layout
36576
36577 \begin_layout Standard
36578 Note: All occurrences of a 
36579 \emph on
36580 %n
36581 \emph default
36582  (pattern variable) must denote the same string.
36583  With the above rule, the assembly sequence:
36584 \end_layout
36585
36586 \begin_layout Verse
36587
36588 \family typewriter
36589 mov r1,a 
36590 \newline
36591 mov a,r2
36592 \end_layout
36593
36594 \begin_layout Standard
36595 will remain unmodified.
36596 \newline
36597
36598 \newline
36599 Other special case optimizations may be added by the
36600  user (via 
36601 \emph on
36602 -
36603 \begin_inset ERT
36604 status collapsed
36605
36606 \begin_layout Standard
36607
36608
36609 \backslash
36610 /
36611 \end_layout
36612
36613 \end_inset
36614
36615 -peep-file option
36616 \emph default
36617 ).
36618  E.g.
36619  some variants of the 8051 MCU
36620 \begin_inset LatexCommand \index{MCS51 variants}
36621
36622 \end_inset
36623
36624  allow only 
36625 \family typewriter
36626 ajmp
36627 \family default
36628  and 
36629 \family typewriter
36630 acall
36631 \family default
36632 .
36633  The following two rules will change all 
36634 \family typewriter
36635 ljmp
36636 \family default
36637  and 
36638 \family typewriter
36639 lcall
36640 \family default
36641  to 
36642 \family typewriter
36643 ajmp
36644 \family default
36645  and 
36646 \family typewriter
36647 acall
36648 \end_layout
36649
36650 \begin_layout Verse
36651
36652 \family typewriter
36653 replace { lcall %1 } by { acall %1 } 
36654 \newline
36655 replace { ljmp %1 } by { ajmp %1 }
36656 \end_layout
36657
36658 \begin_layout Standard
36659 (NOTE: from version 2.7.3 on, you can use option -
36660 \emph on
36661
36662 \begin_inset ERT
36663 status collapsed
36664
36665 \begin_layout Standard
36666
36667
36668 \backslash
36669 /
36670 \end_layout
36671
36672 \end_inset
36673
36674
36675 \emph default
36676 -acall-ajmp
36677 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36678
36679 \end_inset
36680
36681 , which also takes care of aligning the interrupt vectors properly.)
36682 \newline
36683
36684 \end_layout
36685
36686 \begin_layout Standard
36687 The 
36688 \emph on
36689 inline-assembler code
36690 \emph default
36691  is also passed through the peep hole optimizer, thus the peephole optimizer
36692  can also be used as an assembly level macro expander.
36693  The rules themselves are MCU dependent whereas the rule language infra-structur
36694 e is MCU independent.
36695  Peephole optimization rules for other MCU can be easily programmed using
36696  the rule language.
36697 \newline
36698
36699 \newline
36700 The syntax for a rule is as follows:
36701 \end_layout
36702
36703 \begin_layout Verse
36704
36705 \family typewriter
36706 rule := replace [ restart ] '{' <assembly sequence> '
36707 \backslash
36708 n' 
36709 \newline
36710 \InsetSpace ~
36711  \InsetSpace ~
36712  \InsetSpace ~
36713  \InsetSpace ~
36714  \InsetSpace ~
36715  \InsetSpace ~
36716  \InsetSpace ~
36717  \InsetSpace ~
36718  \InsetSpace ~
36719  \InsetSpace ~
36720  \InsetSpace ~
36721  \InsetSpace ~
36722  \InsetSpace ~
36723  \InsetSpace ~
36724  '}' by '{' '
36725 \backslash
36726 n' 
36727 \newline
36728 \InsetSpace ~
36729  \InsetSpace ~
36730  \InsetSpace ~
36731  \InsetSpace ~
36732  \InsetSpace ~
36733  \InsetSpace ~
36734  \InsetSpace ~
36735  \InsetSpace ~
36736  \InsetSpace ~
36737  \InsetSpace ~
36738  \InsetSpace ~
36739  \InsetSpace ~
36740  \InsetSpace ~
36741  \InsetSpace ~
36742  \InsetSpace ~
36743  \InsetSpace ~
36744  <assembly sequence> '
36745 \backslash
36746 n' 
36747 \newline
36748 \InsetSpace ~
36749  \InsetSpace ~
36750  \InsetSpace ~
36751  \InsetSpace ~
36752  \InsetSpace ~
36753  \InsetSpace ~
36754  \InsetSpace ~
36755  \InsetSpace ~
36756  \InsetSpace ~
36757  \InsetSpace ~
36758  \InsetSpace ~
36759  \InsetSpace ~
36760  \InsetSpace ~
36761  \InsetSpace ~
36762  '}' [if <functionName> ] '
36763 \backslash
36764 n' 
36765 \end_layout
36766
36767 \begin_layout Standard
36768 <assembly sequence> := assembly instruction (each instruction including
36769  labels must be on a separate line).
36770 \newline
36771
36772 \newline
36773 The optimizer will apply to the rules
36774  one by one from the top in the sequence of their appearance, it will terminate
36775  when all rules are exhausted.
36776  If the 'restart' option is specified, then the optimizer will start matching
36777  the rules again from the top, this option for a rule is expensive (performance)
36778 , it is intended to be used in situations where a transformation will trigger
36779  the same rule again.
36780  An example of this (not a good one, it has side effects) is the following
36781  rule:
36782 \end_layout
36783
36784 \begin_layout Verse
36785
36786 \family typewriter
36787 replace restart { 
36788 \newline
36789 \InsetSpace ~
36790 \InsetSpace ~
36791 pop %1 
36792 \newline
36793 \InsetSpace ~
36794 \InsetSpace ~
36795 push %1 } by { 
36796 \newline
36797 \InsetSpace ~
36798 \InsetSpace ~
36799 ; nop 
36800 \newline
36801 }
36802 \end_layout
36803
36804 \begin_layout Standard
36805 Note that the replace pattern cannot be a blank, but can be a comment line.
36806  Without the 'restart' option only the innermost 'pop' 'push' pair would
36807  be eliminated, i.e.:
36808 \end_layout
36809
36810 \begin_layout Verse
36811
36812 \family typewriter
36813 pop ar1 
36814 \newline
36815 pop ar2 
36816 \newline
36817 push ar2 
36818 \newline
36819 push ar1
36820 \end_layout
36821
36822 \begin_layout Standard
36823 would result in:
36824 \end_layout
36825
36826 \begin_layout Verse
36827
36828 \family typewriter
36829 pop ar1 
36830 \newline
36831 ; nop 
36832 \newline
36833 push ar1
36834 \end_layout
36835
36836 \begin_layout Standard
36837
36838 \emph on
36839 with
36840 \emph default
36841  the restart option the rule will be applied again to the resulting code
36842  and then all the pop-push pairs will be eliminated to yield:
36843 \end_layout
36844
36845 \begin_layout Verse
36846
36847 \family typewriter
36848 ; nop 
36849 \newline
36850 ; nop
36851 \end_layout
36852
36853 \begin_layout Standard
36854 A conditional function can be attached to a rule.
36855  Attaching rules are somewhat more involved, let me illustrate this with
36856  an example.
36857 \end_layout
36858
36859 \begin_layout Verse
36860
36861 \family typewriter
36862 replace { 
36863 \newline
36864 \InsetSpace ~
36865  \InsetSpace ~
36866  \InsetSpace ~
36867 ljmp %5 
36868 \newline
36869 %2:
36870 \newline
36871 } by { 
36872 \newline
36873 \InsetSpace ~
36874  \InsetSpace ~
36875  \InsetSpace ~
36876 sjmp %5 
36877 \newline
36878 %2:
36879 \newline
36880 } if labelInRange
36881 \end_layout
36882
36883 \begin_layout Standard
36884 The optimizer does a look-up of a function name table defined in function
36885  
36886 \emph on
36887 callFuncByName
36888 \emph default
36889  in the source file SDCCpeeph.c, with the name 
36890 \emph on
36891 labelInRange
36892 \emph default
36893 .
36894  If it finds a corresponding entry the function is called.
36895  Note there can be no parameters specified for these functions, in this
36896  case the use of 
36897 \emph on
36898 %5
36899 \emph default
36900  is crucial, since the function 
36901 \emph on
36902 labelInRange
36903 \emph default
36904  expects to find the label in that particular variable (the hash table containin
36905 g the variable bindings is passed as a parameter).
36906  If you want to code more such functions, take a close look at the function
36907  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36908  Currently implemented are 
36909 \emph on
36910 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36911  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36912 \emph default
36913 and
36914 \emph on
36915  notVolatile
36916 \emph default
36917 .
36918 \end_layout
36919
36920 \begin_layout Standard
36921 I know this whole thing is a little kludgey, but maybe some day we will
36922  have some better means.
36923  If you are looking at this file, you will see the default rules that are
36924  compiled into the compiler, you can add your own rules in the default set
36925  there if you get tired of specifying the -
36926 \begin_inset ERT
36927 status collapsed
36928
36929 \begin_layout Standard
36930
36931
36932 \backslash
36933 /
36934 \end_layout
36935
36936 \end_inset
36937
36938 -peep-file option.
36939 \end_layout
36940
36941 \begin_layout Section
36942 ANSI-Compliance
36943 \begin_inset LatexCommand \index{ANSI-compliance}
36944
36945 \end_inset
36946
36947
36948 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36949
36950 \end_inset
36951
36952
36953 \end_layout
36954
36955 \begin_layout Standard
36956 The latest publically available version of the standard 
36957 \emph on
36958 ISO/IEC 9899 - Programming languages - C
36959 \emph default
36960  should be available at: 
36961 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36962
36963 \end_inset
36964
36965 .
36966 \newline
36967
36968 \end_layout
36969
36970 \begin_layout Standard
36971 Deviations from the compliance:
36972 \end_layout
36973
36974 \begin_layout Itemize
36975 functions are not reentrant
36976 \begin_inset LatexCommand \index{reentrant}
36977
36978 \end_inset
36979
36980  unless explicitly declared as such or the 
36981 \series bold
36982 -
36983 \begin_inset ERT
36984 status collapsed
36985
36986 \begin_layout Standard
36987
36988
36989 \backslash
36990 /
36991 \end_layout
36992
36993 \end_inset
36994
36995 -stack-auto
36996 \begin_inset LatexCommand \index{-\/-stack-auto}
36997
36998 \end_inset
36999
37000
37001 \series default
37002  command line option is specified.
37003 \end_layout
37004
37005 \begin_layout Itemize
37006 structures
37007 \begin_inset LatexCommand \index{struct}
37008
37009 \end_inset
37010
37011  and unions
37012 \begin_inset LatexCommand \index{union}
37013
37014 \end_inset
37015
37016  cannot be assigned values directly, cannot be passed as function parameters
37017  or assigned to each other and cannot be a return value
37018 \begin_inset LatexCommand \index{return value}
37019
37020 \end_inset
37021
37022  from a function, e.g.:
37023 \end_layout
37024
37025 \begin_deeper
37026 \begin_layout Verse
37027
37028 \family typewriter
37029 struct s { ...
37030  }; 
37031 \newline
37032 struct s s1, s2; 
37033 \newline
37034 foo() 
37035 \newline
37036
37037 \newline
37038 \InsetSpace ~
37039 \InsetSpace ~
37040 \InsetSpace ~
37041 \InsetSpace ~
37042 ...
37043  
37044 \newline
37045 \InsetSpace ~
37046 \InsetSpace ~
37047 \InsetSpace ~
37048 \InsetSpace ~
37049 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
37050 \newline
37051 \InsetSpace ~
37052 \InsetSpace ~
37053 \InsetSpace ~
37054 \InsetSpace ~
37055 ...
37056  
37057 \newline
37058 }
37059 \newline
37060
37061 \series bold
37062 struct
37063 \series default
37064  s foo1 (
37065 \series bold
37066 struct
37067 \series default
37068  s parms) /* invalid in SDCC although allowed in ANSI */
37069 \newline
37070
37071 \newline
37072 \InsetSpace ~
37073 \InsetSpace ~
37074 \InsetSpace ~
37075 \InsetSpace ~
37076 struct s rets;
37077  
37078 \newline
37079 \InsetSpace ~
37080 \InsetSpace ~
37081 \InsetSpace ~
37082 \InsetSpace ~
37083 ...
37084  
37085 \newline
37086 \InsetSpace ~
37087 \InsetSpace ~
37088 \InsetSpace ~
37089 \InsetSpace ~
37090 return rets; /* is invalid in SDCC although allowed in ANSI */ 
37091 \newline
37092 }
37093 \end_layout
37094
37095 \end_deeper
37096 \begin_layout Itemize
37097 initialization of structure arrays must be fully braced.
37098 \end_layout
37099
37100 \begin_deeper
37101 \begin_layout Verse
37102
37103 \family typewriter
37104 struct s { char x } a[] = {1, 2};\InsetSpace ~
37105 \InsetSpace ~
37106 \InsetSpace ~
37107 \InsetSpace ~
37108 \InsetSpace ~
37109 /* invalid in SDCC */
37110 \newline
37111 struct s { char x
37112  } a[] = {{1}, {2}}; /* OK */
37113 \end_layout
37114
37115 \end_deeper
37116 \begin_layout Itemize
37117 'long long
37118 \begin_inset LatexCommand \index{long long (not supported)}
37119
37120 \end_inset
37121
37122 ' (64 bit integers
37123 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37124
37125 \end_inset
37126
37127 ) not supported.
37128 \end_layout
37129
37130 \begin_layout Itemize
37131 'double
37132 \begin_inset LatexCommand \index{double (not supported)}
37133
37134 \end_inset
37135
37136 ' precision floating point 
37137 \begin_inset LatexCommand \index{Floating point support}
37138
37139 \end_inset
37140
37141 not supported.
37142 \end_layout
37143
37144 \begin_layout Itemize
37145 Old K&R style
37146 \begin_inset LatexCommand \index{K\&R style}
37147
37148 \end_inset
37149
37150  function declarations are NOT allowed.
37151 \end_layout
37152
37153 \begin_deeper
37154 \begin_layout Verse
37155
37156 \family typewriter
37157 foo(i,j) /* this old style of function declarations */ 
37158 \newline
37159 int i,j; /* is valid
37160  in ANSI but not valid in SDCC */ 
37161 \newline
37162
37163 \newline
37164 \InsetSpace ~
37165 \InsetSpace ~
37166 \InsetSpace ~
37167 \InsetSpace ~
37168 ...
37169  
37170 \newline
37171 }
37172 \end_layout
37173
37174 \end_deeper
37175 \begin_layout Itemize
37176 Most enhancements in C99 are not supported, e.g.:
37177 \end_layout
37178
37179 \begin_deeper
37180 \begin_layout Verse
37181
37182 \family typewriter
37183 for (
37184 \series bold
37185 int
37186 \series default
37187  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37188 \end_layout
37189
37190 \end_deeper
37191 \begin_layout Itemize
37192 But some have been added recently in SDCC 2.7.0.
37193  They must be considered alpha quality however.
37194 \end_layout
37195
37196 \begin_deeper
37197 \begin_layout Verse
37198
37199 \family typewriter
37200 \series bold
37201 inline
37202 \begin_inset LatexCommand \index{inline (not supported)}
37203
37204 \end_inset
37205
37206
37207 \series default
37208  int increment (int a) { return a+1; } /* inlines the increment without
37209  function call overhead */
37210 \newline
37211 int * 
37212 \series bold
37213 restrict
37214 \begin_inset LatexCommand \index{inline (not supported)}
37215
37216 \end_inset
37217
37218
37219 \series default
37220  p; /* accepted but ignored */
37221 \end_layout
37222
37223 \end_deeper
37224 \begin_layout Itemize
37225 Certain words that are valid identifiers in the standard may be reserved
37226  words in SDCC unless the 
37227 \series bold
37228 -
37229 \begin_inset ERT
37230 status collapsed
37231
37232 \begin_layout Standard
37233
37234
37235 \backslash
37236 /
37237 \end_layout
37238
37239 \end_inset
37240
37241 -std-c89
37242 \begin_inset LatexCommand \index{-\/-std-c89}
37243
37244 \end_inset
37245
37246  
37247 \series default
37248 or
37249 \series bold
37250  -
37251 \begin_inset ERT
37252 status collapsed
37253
37254 \begin_layout Standard
37255
37256
37257 \backslash
37258 /
37259 \end_layout
37260
37261 \end_inset
37262
37263 -std-c99
37264 \begin_inset LatexCommand \index{-\/-std-c99}
37265
37266 \end_inset
37267
37268
37269 \series default
37270  command line options are used.
37271  These may include (depending on the selected processor): 'at', 'banked',
37272  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37273 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37274  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37275  '_naked'.
37276  Compliant equivalents of these keywords are always available in a form
37277  that begin with two underscores
37278 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37279
37280 \end_inset
37281
37282 , f.e.
37283  '__data' instead of 'data'.
37284 \end_layout
37285
37286 \begin_layout Itemize
37287 Integer promotion of variable arguments is not performed if the argument
37288  is explicitly taypecasted unless the
37289 \series bold
37290  -
37291 \begin_inset ERT
37292 status collapsed
37293
37294 \begin_layout Standard
37295
37296
37297 \backslash
37298 /
37299 \end_layout
37300
37301 \end_inset
37302
37303 -std-c89
37304 \begin_inset LatexCommand \index{-\/-std-c89}
37305
37306 \end_inset
37307
37308  
37309 \series default
37310 or
37311 \series bold
37312  -
37313 \begin_inset ERT
37314 status collapsed
37315
37316 \begin_layout Standard
37317
37318
37319 \backslash
37320 /
37321 \end_layout
37322
37323 \end_inset
37324
37325 -std-c99
37326 \begin_inset LatexCommand \index{-\/-std-c99}
37327
37328 \end_inset
37329
37330
37331 \series default
37332  command line options are used.
37333 \end_layout
37334
37335 \begin_deeper
37336 \begin_layout Verse
37337
37338 \family typewriter
37339 void vararg_func (char *str, ...) { str; }
37340 \newline
37341
37342 \newline
37343 void main (void)
37344 \newline
37345 {
37346 \newline
37347 \InsetSpace ~
37348 \InsetSpace ~
37349 char c = 10;
37350 \newline
37351
37352 \newline
37353 \InsetSpace ~
37354 \InsetSpace ~
37355 /* argument
37356  u is promoted to int before
37357 \newline
37358 \InsetSpace ~
37359 \InsetSpace ~
37360 \InsetSpace ~
37361 * passing to function */
37362 \newline
37363 \InsetSpace ~
37364 \InsetSpace ~
37365 vararg_func ("%c", c);
37366 \newline
37367
37368 \newline
37369 \InsetSpace ~
37370 \InsetSpace ~
37371 /*
37372  argument u is not promoted to int,
37373 \newline
37374 \InsetSpace ~
37375 \InsetSpace ~
37376 \InsetSpace ~
37377 * it is passed as char to function
37378 \newline
37379 \InsetSpace ~
37380 \InsetSpace ~
37381 \InsetSpace ~
37382 * if
37383  --std-cXX is not defined;
37384 \newline
37385 \InsetSpace ~
37386 \InsetSpace ~
37387 \InsetSpace ~
37388 * is promoted to int before passing
37389 \newline
37390 \InsetSpace ~
37391 \InsetSpace ~
37392 \InsetSpace ~
37393 * to function
37394  if --std-cXX is defined */
37395 \newline
37396 \InsetSpace ~
37397 \InsetSpace ~
37398 vararg_func ("%bc", (char)u);
37399 \newline
37400 }
37401 \end_layout
37402
37403 \end_deeper
37404 \begin_layout Section
37405 Cyclomatic Complexity
37406 \begin_inset LatexCommand \index{Cyclomatic complexity}
37407
37408 \end_inset
37409
37410
37411 \end_layout
37412
37413 \begin_layout Standard
37414 Cyclomatic complexity of a function is defined as the number of independent
37415  paths the program can take during execution of the function.
37416  This is an important number since it defines the number test cases you
37417  have to generate to validate the function.
37418  The accepted industry standard for complexity number is 10, if the cyclomatic
37419  complexity reported by SDCC exceeds 10 you should think about simplification
37420  of the function logic.
37421  Note that the complexity level is not related to the number of lines of
37422  code in a function.
37423  Large functions can have low complexity, and small functions can have large
37424  complexity levels.
37425  
37426 \newline
37427
37428 \newline
37429 SDCC uses the following formula to compute the complexity:
37430 \newline
37431
37432 \end_layout
37433
37434 \begin_layout Standard
37435 complexity = (number of edges in control flow graph) - (number of nodes
37436  in control flow graph) + 2;
37437 \newline
37438
37439 \newline
37440 Having said that the industry standard is 10,
37441  you should be aware that in some cases it be may unavoidable to have a
37442  complexity level of less than 10.
37443  For example if you have switch statement with more than 10 case labels,
37444  each case label adds one to the complexity level.
37445  The complexity level is by no means an absolute measure of the algorithmic
37446  complexity of the function, it does however provide a good starting point
37447  for which functions you might look at for further optimization.
37448 \end_layout
37449
37450 \begin_layout Section
37451 Retargetting for other Processors
37452 \end_layout
37453
37454 \begin_layout Standard
37455 The issues for retargetting the compiler are far too numerous to be covered
37456  by this document.
37457  What follows is a brief description of each of the seven phases of the
37458  compiler and its MCU dependency.
37459 \end_layout
37460
37461 \begin_layout Itemize
37462 Parsing the source and building the annotated parse tree.
37463  This phase is largely MCU independent (except for the language extensions).
37464  Syntax & semantic checks are also done in this phase, along with some initial
37465  optimizations like back patching labels and the pattern matching optimizations
37466  like bit-rotation etc.
37467 \end_layout
37468
37469 \begin_layout Itemize
37470 The second phase involves generating an intermediate code which can be easy
37471  manipulated during the later phases.
37472  This phase is entirely MCU independent.
37473  The intermediate code generation assumes the target machine has unlimited
37474  number of registers, and designates them with the name iTemp.
37475  The compiler can be made to dump a human readable form of the code generated
37476  by using the -
37477 \begin_inset ERT
37478 status collapsed
37479
37480 \begin_layout Standard
37481
37482
37483 \backslash
37484 /
37485 \end_layout
37486
37487 \end_inset
37488
37489 -dumpraw option.
37490 \end_layout
37491
37492 \begin_layout Itemize
37493 This phase does the bulk of the standard optimizations and is also MCU independe
37494 nt.
37495  This phase can be broken down into several sub-phases:
37496 \newline
37497
37498 \newline
37499 Break down intermediate
37500  code (iCode) into basic blocks.
37501 \newline
37502 Do control flow & data flow analysis on the
37503  basic blocks.
37504 \newline
37505 Do local common subexpression elimination, then global subexpressio
37506 n elimination
37507 \newline
37508 Dead code elimination
37509 \newline
37510 Loop optimizations
37511 \newline
37512 If loop optimizations
37513  caused any changes then do 'global subexpression elimination' and 'dead
37514  code elimination' again.
37515 \end_layout
37516
37517 \begin_layout Itemize
37518 This phase determines the live-ranges; by live range I mean those iTemp
37519  variables defined by the compiler that still survive after all the optimization
37520 s.
37521  Live range analysis
37522 \begin_inset LatexCommand \index{Live range analysis}
37523
37524 \end_inset
37525
37526  is essential for register allocation, since these computation determines
37527  which of these iTemps will be assigned to registers, and for how long.
37528 \end_layout
37529
37530 \begin_layout Itemize
37531 Phase five is register allocation.
37532  There are two parts to this process.
37533 \newline
37534
37535 \newline
37536 The first part I call 'register packing'
37537  (for lack of a better term).
37538  In this case several MCU specific expression folding is done to reduce
37539  register pressure.
37540 \newline
37541
37542 \newline
37543 The second part is more MCU independent and deals with
37544  allocating registers to the remaining live ranges.
37545  A lot of MCU specific code does creep into this phase because of the limited
37546  number of index registers available in the 8051.
37547 \end_layout
37548
37549 \begin_layout Itemize
37550 The Code generation phase is (unhappily), entirely MCU dependent and very
37551  little (if any at all) of this code can be reused for other MCU.
37552  However the scheme for allocating a homogenized assembler operand for each
37553  iCode operand may be reused.
37554 \end_layout
37555
37556 \begin_layout Itemize
37557 As mentioned in the optimization section the peep-hole optimizer is rule
37558  based system, which can reprogrammed for other MCUs.
37559 \end_layout
37560
37561 \begin_layout Standard
37562 More information is available on SDCC Wiki
37563 \begin_inset LatexCommand \index{wiki}
37564
37565 \end_inset
37566
37567  (preliminary link 
37568 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37569
37570 \end_inset
37571
37572 ) and in the thread 
37573 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37574
37575 \end_inset
37576
37577  .
37578 \end_layout
37579
37580 \begin_layout Chapter
37581 Compiler internals
37582 \begin_inset LatexCommand \index{Compiler internals}
37583
37584 \end_inset
37585
37586
37587 \end_layout
37588
37589 \begin_layout Section
37590 The anatomy of the compiler
37591 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37592
37593 \end_inset
37594
37595
37596 \end_layout
37597
37598 \begin_layout Standard
37599
37600 \shape italic
37601 This is an excerpt from an article published in Circuit Cellar Magazine
37602  in 
37603 \series bold
37604 August 2000
37605 \series default
37606 .
37607  It's a little outdated (the compiler is much more efficient now and user/develo
37608 per friendly), but pretty well exposes the guts of it all.
37609 \shape default
37610
37611 \newline
37612
37613 \newline
37614 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37615  It is fairly easy to retarget for other 8-bit MCU.
37616  Here we take a look at some of the internals of the compiler.
37617  
37618 \end_layout
37619
37620 \begin_layout Paragraph*
37621 Parsing
37622 \begin_inset LatexCommand \index{Parsing}
37623
37624 \end_inset
37625
37626  
37627 \end_layout
37628
37629 \begin_layout Standard
37630 Parsing the input source file and creating an AST (Annotated Syntax Tree
37631 \begin_inset LatexCommand \index{Annotated syntax tree}
37632
37633 \end_inset
37634
37635 ).
37636  This phase also involves propagating types (annotating each node of the
37637  parse tree with type information) and semantic analysis.
37638  There are some MCU specific parsing rules.
37639  For example the storage classes, the extended storage classes are MCU specific
37640  while there may be a xdata storage class for 8051 there is no such storage
37641  class for z80 or Atmel AVR.
37642  SDCC allows MCU specific storage class extensions, i.e.
37643  xdata will be treated as a storage class specifier when parsing 8051 C
37644  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37645  C code.
37646 \end_layout
37647
37648 \begin_layout Paragraph*
37649 Generating iCode
37650 \begin_inset LatexCommand \index{iCode}
37651
37652 \end_inset
37653
37654
37655 \end_layout
37656
37657 \begin_layout Standard
37658 Intermediate code generation.
37659  In this phase the AST is broken down into three-operand form (iCode).
37660  These three operand forms are represented as doubly linked lists.
37661  ICode is the term given to the intermediate form generated by the compiler.
37662  ICode example section shows some examples of iCode generated for some simple
37663  C source functions.
37664 \end_layout
37665
37666 \begin_layout Paragraph*
37667 Optimizations
37668 \begin_inset LatexCommand \index{Optimizations}
37669
37670 \end_inset
37671
37672 .
37673 \end_layout
37674
37675 \begin_layout Standard
37676 Bulk of the target independent optimizations is performed in this phase.
37677  The optimizations include constant propagation, common sub-expression eliminati
37678 on, loop invariant code movement, strength reduction of loop induction variables
37679  and dead-code elimination.
37680 \end_layout
37681
37682 \begin_layout Paragraph*
37683 Live range analysis
37684 \begin_inset LatexCommand \index{Live range analysis}
37685
37686 \end_inset
37687
37688
37689 \end_layout
37690
37691 \begin_layout Standard
37692 During intermediate code generation phase, the compiler assumes the target
37693  machine has infinite number of registers and generates a lot of temporary
37694  variables.
37695  The live range computation determines the lifetime of each of these compiler-ge
37696 nerated temporaries.
37697  A picture speaks a thousand words.
37698  ICode example sections show the live range annotations for each of the
37699  operand.
37700  It is important to note here, each iCode is assigned a number in the order
37701  of its execution in the function.
37702  The live ranges are computed in terms of these numbers.
37703  The from number is the number of the iCode which first defines the operand
37704  and the to number signifies the iCode which uses this operand last.
37705 \end_layout
37706
37707 \begin_layout Paragraph*
37708 Register Allocation
37709 \begin_inset LatexCommand \index{Register allocation}
37710
37711 \end_inset
37712
37713
37714 \end_layout
37715
37716 \begin_layout Standard
37717 The register allocation determines the type and number of registers needed
37718  by each operand.
37719  In most MCUs only a few registers can be used for indirect addressing.
37720  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37721  address the internal ram and DPTR to indirectly address the external ram.
37722  The compiler will try to allocate the appropriate register to pointer variables
37723  if it can.
37724  ICode example section shows the operands annotated with the registers assigned
37725  to them.
37726  The compiler will try to keep operands in registers as much as possible;
37727  there are several schemes the compiler uses to do achieve this.
37728  When the compiler runs out of registers the compiler will check to see
37729  if there are any live operands which is not used or defined in the current
37730  basic block being processed, if there are any found then it will push that
37731  operand and use the registers in this block, the operand will then be popped
37732  at the end of the basic block.
37733  
37734 \end_layout
37735
37736 \begin_layout Standard
37737 There are other MCU specific considerations in this phase.
37738  Some MCUs have an accumulator; very short-lived operands could be assigned
37739  to the accumulator instead of a general-purpose register.
37740 \end_layout
37741
37742 \begin_layout Paragraph*
37743 Code generation
37744 \end_layout
37745
37746 \begin_layout Standard
37747 Figure II gives a table of iCode
37748 \begin_inset LatexCommand \index{iCode}
37749
37750 \end_inset
37751
37752  operations supported by the compiler.
37753  The code generation involves translating these operations into corresponding
37754  assembly code for the processor.
37755  This sounds overly simple but that is the essence of code generation.
37756  Some of the iCode operations are generated on a MCU specific manner for
37757  example, the z80 port does not use registers to pass parameters so the
37758  SEND and RECV iCode operations will not be generated, and it also does
37759  not support JUMPTABLES.
37760  
37761 \newline
37762
37763 \end_layout
37764
37765 \begin_layout Standard
37766
37767 \size footnotesize
37768 Figure II 
37769 \begin_inset Tabular
37770 <lyxtabular version="3" rows="39" columns="4">
37771 <features islongtable="true" headBottomDL="true">
37772 <column alignment="block" valignment="top" leftline="true" width="13col%">
37773 <column alignment="left" valignment="top" leftline="true" width="13col%">
37774 <column alignment="block" valignment="top" leftline="true" width="22col%">
37775 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37776 <row topline="true" bottomline="true" endhead="true">
37777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37778 \begin_inset Text
37779
37780 \begin_layout Standard
37781
37782 \series bold
37783 iCode
37784 \series default
37785
37786 \begin_inset LatexCommand \index{iCode}
37787
37788 \end_inset
37789
37790
37791 \end_layout
37792
37793 \end_inset
37794 </cell>
37795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37796 \begin_inset Text
37797
37798 \begin_layout Standard
37799
37800 \series bold
37801 Operands
37802 \end_layout
37803
37804 \end_inset
37805 </cell>
37806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37807 \begin_inset Text
37808
37809 \begin_layout Standard
37810
37811 \series bold
37812 Description
37813 \end_layout
37814
37815 \end_inset
37816 </cell>
37817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37818 \begin_inset Text
37819
37820 \begin_layout Standard
37821
37822 \series bold
37823 C Equivalent
37824 \end_layout
37825
37826 \end_inset
37827 </cell>
37828 </row>
37829 <row topline="true">
37830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37831 \begin_inset Text
37832
37833 \begin_layout Standard
37834
37835 \size footnotesize
37836 '!'
37837 \end_layout
37838
37839 \end_inset
37840 </cell>
37841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37842 \begin_inset Text
37843
37844 \begin_layout Standard
37845
37846 \size footnotesize
37847 IC_LEFT() IC_RESULT()
37848 \end_layout
37849
37850 \end_inset
37851 </cell>
37852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37853 \begin_inset Text
37854
37855 \begin_layout Standard
37856
37857 \size footnotesize
37858 NOT operation 
37859 \end_layout
37860
37861 \end_inset
37862 </cell>
37863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37864 \begin_inset Text
37865
37866 \begin_layout Standard
37867
37868 \size footnotesize
37869 IC_RESULT = ! IC_LEFT;
37870 \end_layout
37871
37872 \end_inset
37873 </cell>
37874 </row>
37875 <row topline="true">
37876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37877 \begin_inset Text
37878
37879 \begin_layout Standard
37880
37881 \size footnotesize
37882 '~'
37883 \end_layout
37884
37885 \end_inset
37886 </cell>
37887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37888 \begin_inset Text
37889
37890 \begin_layout Standard
37891
37892 \size footnotesize
37893 IC_LEFT() IC_RESULT()
37894 \end_layout
37895
37896 \end_inset
37897 </cell>
37898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37899 \begin_inset Text
37900
37901 \begin_layout Standard
37902
37903 \size footnotesize
37904 Bitwise complement of 
37905 \end_layout
37906
37907 \end_inset
37908 </cell>
37909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37910 \begin_inset Text
37911
37912 \begin_layout Standard
37913
37914 \size footnotesize
37915 IC_RESULT = ~IC_LEFT;
37916 \end_layout
37917
37918 \end_inset
37919 </cell>
37920 </row>
37921 <row topline="true">
37922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37923 \begin_inset Text
37924
37925 \begin_layout Standard
37926
37927 \size footnotesize
37928 RRC
37929 \end_layout
37930
37931 \end_inset
37932 </cell>
37933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37934 \begin_inset Text
37935
37936 \begin_layout Standard
37937
37938 \size footnotesize
37939 IC_LEFT() IC_RESULT()
37940 \end_layout
37941
37942 \end_inset
37943 </cell>
37944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37945 \begin_inset Text
37946
37947 \begin_layout Standard
37948
37949 \size footnotesize
37950 Rotate right with carry
37951 \end_layout
37952
37953 \end_inset
37954 </cell>
37955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37956 \begin_inset Text
37957
37958 \begin_layout Standard
37959
37960 \size footnotesize
37961 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37962 \end_layout
37963
37964 \end_inset
37965 </cell>
37966 </row>
37967 <row topline="true">
37968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37969 \begin_inset Text
37970
37971 \begin_layout Standard
37972
37973 \size footnotesize
37974 RLC
37975 \end_layout
37976
37977 \end_inset
37978 </cell>
37979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37980 \begin_inset Text
37981
37982 \begin_layout Standard
37983
37984 \size footnotesize
37985 IC_LEFT() IC_RESULT()
37986 \end_layout
37987
37988 \end_inset
37989 </cell>
37990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37991 \begin_inset Text
37992
37993 \begin_layout Standard
37994
37995 \size footnotesize
37996 Rotate left with carry
37997 \end_layout
37998
37999 \end_inset
38000 </cell>
38001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38002 \begin_inset Text
38003
38004 \begin_layout Standard
38005
38006 \size footnotesize
38007 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
38008 \end_layout
38009
38010 \end_inset
38011 </cell>
38012 </row>
38013 <row topline="true">
38014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38015 \begin_inset Text
38016
38017 \begin_layout Standard
38018
38019 \size footnotesize
38020 GETHBIT
38021 \end_layout
38022
38023 \end_inset
38024 </cell>
38025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38026 \begin_inset Text
38027
38028 \begin_layout Standard
38029
38030 \size footnotesize
38031 IC_LEFT() IC_RESULT()
38032 \end_layout
38033
38034 \end_inset
38035 </cell>
38036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38037 \begin_inset Text
38038
38039 \begin_layout Standard
38040
38041 \size footnotesize
38042 Get the highest order bit of IC_LEFT
38043 \end_layout
38044
38045 \end_inset
38046 </cell>
38047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38048 \begin_inset Text
38049
38050 \begin_layout Standard
38051
38052 \size footnotesize
38053 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
38054 \end_layout
38055
38056 \end_inset
38057 </cell>
38058 </row>
38059 <row topline="true">
38060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38061 \begin_inset Text
38062
38063 \begin_layout Standard
38064
38065 \size footnotesize
38066 UNARYMINUS
38067 \end_layout
38068
38069 \end_inset
38070 </cell>
38071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38072 \begin_inset Text
38073
38074 \begin_layout Standard
38075
38076 \size footnotesize
38077 IC_LEFT() IC_RESULT()
38078 \end_layout
38079
38080 \end_inset
38081 </cell>
38082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38083 \begin_inset Text
38084
38085 \begin_layout Standard
38086
38087 \size footnotesize
38088 Unary minus
38089 \end_layout
38090
38091 \end_inset
38092 </cell>
38093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38094 \begin_inset Text
38095
38096 \begin_layout Standard
38097
38098 \size footnotesize
38099 IC_RESULT = - IC_LEFT;
38100 \end_layout
38101
38102 \end_inset
38103 </cell>
38104 </row>
38105 <row topline="true">
38106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38107 \begin_inset Text
38108
38109 \begin_layout Standard
38110
38111 \size footnotesize
38112 IPUSH
38113 \end_layout
38114
38115 \end_inset
38116 </cell>
38117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38118 \begin_inset Text
38119
38120 \begin_layout Standard
38121
38122 \size footnotesize
38123 IC_LEFT()
38124 \end_layout
38125
38126 \end_inset
38127 </cell>
38128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38129 \begin_inset Text
38130
38131 \begin_layout Standard
38132
38133 \size footnotesize
38134 Push the operand into stack
38135 \end_layout
38136
38137 \end_inset
38138 </cell>
38139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38140 \begin_inset Text
38141
38142 \begin_layout Standard
38143
38144 \size footnotesize
38145 NONE
38146 \end_layout
38147
38148 \end_inset
38149 </cell>
38150 </row>
38151 <row topline="true">
38152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38153 \begin_inset Text
38154
38155 \begin_layout Standard
38156
38157 \size footnotesize
38158 IPOP
38159 \end_layout
38160
38161 \end_inset
38162 </cell>
38163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38164 \begin_inset Text
38165
38166 \begin_layout Standard
38167
38168 \size footnotesize
38169 IC_LEFT()
38170 \end_layout
38171
38172 \end_inset
38173 </cell>
38174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38175 \begin_inset Text
38176
38177 \begin_layout Standard
38178
38179 \size footnotesize
38180 Pop the operand from the stack 
38181 \end_layout
38182
38183 \end_inset
38184 </cell>
38185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38186 \begin_inset Text
38187
38188 \begin_layout Standard
38189
38190 \size footnotesize
38191 NONE
38192 \end_layout
38193
38194 \end_inset
38195 </cell>
38196 </row>
38197 <row topline="true">
38198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38199 \begin_inset Text
38200
38201 \begin_layout Standard
38202
38203 \size footnotesize
38204 CALL
38205 \end_layout
38206
38207 \end_inset
38208 </cell>
38209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38210 \begin_inset Text
38211
38212 \begin_layout Standard
38213
38214 \size footnotesize
38215 IC_LEFT() IC_RESULT()
38216 \end_layout
38217
38218 \end_inset
38219 </cell>
38220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38221 \begin_inset Text
38222
38223 \begin_layout Standard
38224
38225 \size footnotesize
38226 Call the function represented by IC_LEFT 
38227 \end_layout
38228
38229 \end_inset
38230 </cell>
38231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38232 \begin_inset Text
38233
38234 \begin_layout Standard
38235
38236 \size footnotesize
38237 IC_RESULT = IC_LEFT();
38238 \end_layout
38239
38240 \end_inset
38241 </cell>
38242 </row>
38243 <row topline="true">
38244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38245 \begin_inset Text
38246
38247 \begin_layout Standard
38248
38249 \size footnotesize
38250 PCALL
38251 \end_layout
38252
38253 \end_inset
38254 </cell>
38255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38256 \begin_inset Text
38257
38258 \begin_layout Standard
38259
38260 \size footnotesize
38261 IC_LEFT() IC_RESULT()
38262 \end_layout
38263
38264 \end_inset
38265 </cell>
38266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38267 \begin_inset Text
38268
38269 \begin_layout Standard
38270
38271 \size footnotesize
38272 Call via function pointer
38273 \end_layout
38274
38275 \end_inset
38276 </cell>
38277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38278 \begin_inset Text
38279
38280 \begin_layout Standard
38281
38282 \size footnotesize
38283 IC_RESULT = (*IC_LEFT)();
38284 \end_layout
38285
38286 \end_inset
38287 </cell>
38288 </row>
38289 <row topline="true">
38290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38291 \begin_inset Text
38292
38293 \begin_layout Standard
38294
38295 \size footnotesize
38296 RETURN
38297 \end_layout
38298
38299 \end_inset
38300 </cell>
38301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38302 \begin_inset Text
38303
38304 \begin_layout Standard
38305
38306 \size footnotesize
38307 IC_LEFT()
38308 \end_layout
38309
38310 \end_inset
38311 </cell>
38312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38313 \begin_inset Text
38314
38315 \begin_layout Standard
38316
38317 \size footnotesize
38318 Return the value in operand IC_LEFT 
38319 \end_layout
38320
38321 \end_inset
38322 </cell>
38323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38324 \begin_inset Text
38325
38326 \begin_layout Standard
38327
38328 \size footnotesize
38329 return IC_LEFT;
38330 \end_layout
38331
38332 \end_inset
38333 </cell>
38334 </row>
38335 <row topline="true">
38336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38337 \begin_inset Text
38338
38339 \begin_layout Standard
38340
38341 \size footnotesize
38342 LABEL
38343 \end_layout
38344
38345 \end_inset
38346 </cell>
38347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38348 \begin_inset Text
38349
38350 \begin_layout Standard
38351
38352 \size footnotesize
38353 IC_LABEL() 
38354 \end_layout
38355
38356 \end_inset
38357 </cell>
38358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38359 \begin_inset Text
38360
38361 \begin_layout Standard
38362
38363 \size footnotesize
38364 Label
38365 \end_layout
38366
38367 \end_inset
38368 </cell>
38369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38370 \begin_inset Text
38371
38372 \begin_layout Standard
38373
38374 \size footnotesize
38375 IC_LABEL:
38376 \end_layout
38377
38378 \end_inset
38379 </cell>
38380 </row>
38381 <row topline="true">
38382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38383 \begin_inset Text
38384
38385 \begin_layout Standard
38386
38387 \size footnotesize
38388 GOTO
38389 \end_layout
38390
38391 \end_inset
38392 </cell>
38393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38394 \begin_inset Text
38395
38396 \begin_layout Standard
38397
38398 \size footnotesize
38399 IC_LABEL() 
38400 \end_layout
38401
38402 \end_inset
38403 </cell>
38404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38405 \begin_inset Text
38406
38407 \begin_layout Standard
38408
38409 \size footnotesize
38410 Goto label
38411 \end_layout
38412
38413 \end_inset
38414 </cell>
38415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38416 \begin_inset Text
38417
38418 \begin_layout Standard
38419
38420 \size footnotesize
38421 goto IC_LABEL();
38422 \end_layout
38423
38424 \end_inset
38425 </cell>
38426 </row>
38427 <row topline="true">
38428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38429 \begin_inset Text
38430
38431 \begin_layout Standard
38432
38433 \size footnotesize
38434 '+'
38435 \end_layout
38436
38437 \end_inset
38438 </cell>
38439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38440 \begin_inset Text
38441
38442 \begin_layout Standard
38443
38444 \size footnotesize
38445 IC_LEFT() IC_RIGHT() IC_RESULT()
38446 \end_layout
38447
38448 \end_inset
38449 </cell>
38450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38451 \begin_inset Text
38452
38453 \begin_layout Standard
38454
38455 \size footnotesize
38456 Addition
38457 \end_layout
38458
38459 \end_inset
38460 </cell>
38461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38462 \begin_inset Text
38463
38464 \begin_layout Standard
38465
38466 \size footnotesize
38467 IC_RESULT = IC_LEFT + IC_RIGHT
38468 \end_layout
38469
38470 \end_inset
38471 </cell>
38472 </row>
38473 <row topline="true">
38474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38475 \begin_inset Text
38476
38477 \begin_layout Standard
38478
38479 \size footnotesize
38480 '-'
38481 \end_layout
38482
38483 \end_inset
38484 </cell>
38485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38486 \begin_inset Text
38487
38488 \begin_layout Standard
38489
38490 \size footnotesize
38491 IC_LEFT() IC_RIGHT() IC_RESULT()
38492 \end_layout
38493
38494 \end_inset
38495 </cell>
38496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38497 \begin_inset Text
38498
38499 \begin_layout Standard
38500
38501 \size footnotesize
38502 Subtraction
38503 \end_layout
38504
38505 \end_inset
38506 </cell>
38507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38508 \begin_inset Text
38509
38510 \begin_layout Standard
38511
38512 \size footnotesize
38513 IC_RESULT = IC_LEFT - IC_RIGHT 
38514 \end_layout
38515
38516 \end_inset
38517 </cell>
38518 </row>
38519 <row topline="true">
38520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38521 \begin_inset Text
38522
38523 \begin_layout Standard
38524
38525 \size footnotesize
38526 '*'
38527 \end_layout
38528
38529 \end_inset
38530 </cell>
38531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38532 \begin_inset Text
38533
38534 \begin_layout Standard
38535
38536 \size footnotesize
38537 IC_LEFT() IC_RIGHT() IC_RESULT()
38538 \end_layout
38539
38540 \end_inset
38541 </cell>
38542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38543 \begin_inset Text
38544
38545 \begin_layout Standard
38546
38547 \size footnotesize
38548 Multiplication 
38549 \end_layout
38550
38551 \end_inset
38552 </cell>
38553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38554 \begin_inset Text
38555
38556 \begin_layout Standard
38557
38558 \size footnotesize
38559 IC_RESULT = IC_LEFT * IC_RIGHT;
38560 \end_layout
38561
38562 \end_inset
38563 </cell>
38564 </row>
38565 <row topline="true">
38566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38567 \begin_inset Text
38568
38569 \begin_layout Standard
38570
38571 \size footnotesize
38572 '/'
38573 \end_layout
38574
38575 \end_inset
38576 </cell>
38577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38578 \begin_inset Text
38579
38580 \begin_layout Standard
38581
38582 \size footnotesize
38583 IC_LEFT() IC_RIGHT() IC_RESULT()
38584 \end_layout
38585
38586 \end_inset
38587 </cell>
38588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38589 \begin_inset Text
38590
38591 \begin_layout Standard
38592
38593 \size footnotesize
38594 Division
38595 \end_layout
38596
38597 \end_inset
38598 </cell>
38599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38600 \begin_inset Text
38601
38602 \begin_layout Standard
38603
38604 \size footnotesize
38605 IC_RESULT = IC_LEFT / IC_RIGHT;
38606 \end_layout
38607
38608 \end_inset
38609 </cell>
38610 </row>
38611 <row topline="true">
38612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38613 \begin_inset Text
38614
38615 \begin_layout Standard
38616
38617 \size footnotesize
38618 '%'
38619 \end_layout
38620
38621 \end_inset
38622 </cell>
38623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38624 \begin_inset Text
38625
38626 \begin_layout Standard
38627
38628 \size footnotesize
38629 IC_LEFT() IC_RIGHT() IC_RESULT()
38630 \end_layout
38631
38632 \end_inset
38633 </cell>
38634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38635 \begin_inset Text
38636
38637 \begin_layout Standard
38638
38639 \size footnotesize
38640 Modulus
38641 \end_layout
38642
38643 \end_inset
38644 </cell>
38645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38646 \begin_inset Text
38647
38648 \begin_layout Standard
38649
38650 \size footnotesize
38651 IC_RESULT = IC_LEFT % IC_RIGHT;
38652 \end_layout
38653
38654 \end_inset
38655 </cell>
38656 </row>
38657 <row topline="true">
38658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38659 \begin_inset Text
38660
38661 \begin_layout Standard
38662
38663 \size footnotesize
38664 '<'
38665 \end_layout
38666
38667 \end_inset
38668 </cell>
38669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38670 \begin_inset Text
38671
38672 \begin_layout Standard
38673
38674 \size footnotesize
38675 IC_LEFT() IC_RIGHT() IC_RESULT()
38676 \end_layout
38677
38678 \end_inset
38679 </cell>
38680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38681 \begin_inset Text
38682
38683 \begin_layout Standard
38684
38685 \size footnotesize
38686 Less than
38687 \end_layout
38688
38689 \end_inset
38690 </cell>
38691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38692 \begin_inset Text
38693
38694 \begin_layout Standard
38695
38696 \size footnotesize
38697 IC_RESULT = IC_LEFT < IC_RIGHT;
38698 \end_layout
38699
38700 \end_inset
38701 </cell>
38702 </row>
38703 <row topline="true">
38704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38705 \begin_inset Text
38706
38707 \begin_layout Standard
38708
38709 \size footnotesize
38710 '>'
38711 \end_layout
38712
38713 \end_inset
38714 </cell>
38715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38716 \begin_inset Text
38717
38718 \begin_layout Standard
38719
38720 \size footnotesize
38721 IC_LEFT() IC_RIGHT() IC_RESULT()
38722 \end_layout
38723
38724 \end_inset
38725 </cell>
38726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38727 \begin_inset Text
38728
38729 \begin_layout Standard
38730
38731 \size footnotesize
38732 Greater than 
38733 \end_layout
38734
38735 \end_inset
38736 </cell>
38737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38738 \begin_inset Text
38739
38740 \begin_layout Standard
38741
38742 \size footnotesize
38743 IC_RESULT = IC_LEFT > IC_RIGHT;
38744 \end_layout
38745
38746 \end_inset
38747 </cell>
38748 </row>
38749 <row topline="true">
38750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38751 \begin_inset Text
38752
38753 \begin_layout Standard
38754
38755 \size footnotesize
38756 EQ_OP
38757 \end_layout
38758
38759 \end_inset
38760 </cell>
38761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38762 \begin_inset Text
38763
38764 \begin_layout Standard
38765
38766 \size footnotesize
38767 IC_LEFT() IC_RIGHT() IC_RESULT()
38768 \end_layout
38769
38770 \end_inset
38771 </cell>
38772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38773 \begin_inset Text
38774
38775 \begin_layout Standard
38776
38777 \size footnotesize
38778 Equal to 
38779 \end_layout
38780
38781 \end_inset
38782 </cell>
38783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38784 \begin_inset Text
38785
38786 \begin_layout Standard
38787
38788 \size footnotesize
38789 IC_RESULT = IC_LEFT == IC_RIGHT;
38790 \end_layout
38791
38792 \end_inset
38793 </cell>
38794 </row>
38795 <row topline="true">
38796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38797 \begin_inset Text
38798
38799 \begin_layout Standard
38800
38801 \size footnotesize
38802 AND_OP
38803 \end_layout
38804
38805 \end_inset
38806 </cell>
38807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38808 \begin_inset Text
38809
38810 \begin_layout Standard
38811
38812 \size footnotesize
38813 IC_LEFT() IC_RIGHT() IC_RESULT() 
38814 \end_layout
38815
38816 \end_inset
38817 </cell>
38818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38819 \begin_inset Text
38820
38821 \begin_layout Standard
38822
38823 \size footnotesize
38824 Logical and operation
38825 \end_layout
38826
38827 \end_inset
38828 </cell>
38829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38830 \begin_inset Text
38831
38832 \begin_layout Standard
38833
38834 \size footnotesize
38835 IC_RESULT = IC_LEFT && IC_RIGHT; 
38836 \end_layout
38837
38838 \end_inset
38839 </cell>
38840 </row>
38841 <row topline="true">
38842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38843 \begin_inset Text
38844
38845 \begin_layout Standard
38846
38847 \size footnotesize
38848 OR_OP
38849 \end_layout
38850
38851 \end_inset
38852 </cell>
38853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38854 \begin_inset Text
38855
38856 \begin_layout Standard
38857
38858 \size footnotesize
38859 IC_LEFT() IC_RIGHT() IC_RESULT() 
38860 \end_layout
38861
38862 \end_inset
38863 </cell>
38864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38865 \begin_inset Text
38866
38867 \begin_layout Standard
38868
38869 \size footnotesize
38870 Logical or operation 
38871 \end_layout
38872
38873 \end_inset
38874 </cell>
38875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38876 \begin_inset Text
38877
38878 \begin_layout Standard
38879
38880 \size footnotesize
38881 IC_RESULT = IC_LEFT || IC_RIGHT; 
38882 \end_layout
38883
38884 \end_inset
38885 </cell>
38886 </row>
38887 <row topline="true">
38888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38889 \begin_inset Text
38890
38891 \begin_layout Standard
38892
38893 \size footnotesize
38894 '^'
38895 \end_layout
38896
38897 \end_inset
38898 </cell>
38899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38900 \begin_inset Text
38901
38902 \begin_layout Standard
38903
38904 \size footnotesize
38905 IC_LEFT() IC_RIGHT() IC_RESULT() 
38906 \end_layout
38907
38908 \end_inset
38909 </cell>
38910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38911 \begin_inset Text
38912
38913 \begin_layout Standard
38914
38915 \size footnotesize
38916 Exclusive OR
38917 \end_layout
38918
38919 \end_inset
38920 </cell>
38921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38922 \begin_inset Text
38923
38924 \begin_layout Standard
38925
38926 \size footnotesize
38927 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38928 \end_layout
38929
38930 \end_inset
38931 </cell>
38932 </row>
38933 <row topline="true">
38934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38935 \begin_inset Text
38936
38937 \begin_layout Standard
38938
38939 \size footnotesize
38940 '|'
38941 \end_layout
38942
38943 \end_inset
38944 </cell>
38945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38946 \begin_inset Text
38947
38948 \begin_layout Standard
38949
38950 \size footnotesize
38951 IC_LEFT() IC_RIGHT() IC_RESULT() 
38952 \end_layout
38953
38954 \end_inset
38955 </cell>
38956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38957 \begin_inset Text
38958
38959 \begin_layout Standard
38960
38961 \size footnotesize
38962 Bitwise OR 
38963 \end_layout
38964
38965 \end_inset
38966 </cell>
38967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38968 \begin_inset Text
38969
38970 \begin_layout Standard
38971
38972 \size footnotesize
38973 IC_RESULT = IC_LEFT | IC_RIGHT;
38974 \end_layout
38975
38976 \end_inset
38977 </cell>
38978 </row>
38979 <row topline="true">
38980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38981 \begin_inset Text
38982
38983 \begin_layout Standard
38984
38985 \size footnotesize
38986 BITWISEAND
38987 \end_layout
38988
38989 \end_inset
38990 </cell>
38991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38992 \begin_inset Text
38993
38994 \begin_layout Standard
38995
38996 \size footnotesize
38997 IC_LEFT() IC_RIGHT() IC_RESULT()
38998 \end_layout
38999
39000 \end_inset
39001 </cell>
39002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39003 \begin_inset Text
39004
39005 \begin_layout Standard
39006
39007 \size footnotesize
39008 Bitwise AND 
39009 \end_layout
39010
39011 \end_inset
39012 </cell>
39013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39014 \begin_inset Text
39015
39016 \begin_layout Standard
39017
39018 \size footnotesize
39019 IC_RESULT = IC_LEFT & IC_RIGHT;
39020 \end_layout
39021
39022 \end_inset
39023 </cell>
39024 </row>
39025 <row topline="true">
39026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39027 \begin_inset Text
39028
39029 \begin_layout Standard
39030
39031 \size footnotesize
39032 LEFT_OP
39033 \end_layout
39034
39035 \end_inset
39036 </cell>
39037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39038 \begin_inset Text
39039
39040 \begin_layout Standard
39041
39042 \size footnotesize
39043 IC_LEFT() IC_RIGHT() IC_RESULT()
39044 \end_layout
39045
39046 \end_inset
39047 </cell>
39048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39049 \begin_inset Text
39050
39051 \begin_layout Standard
39052
39053 \size footnotesize
39054 Left shift 
39055 \end_layout
39056
39057 \end_inset
39058 </cell>
39059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39060 \begin_inset Text
39061
39062 \begin_layout Standard
39063
39064 \size footnotesize
39065 IC_RESULT = IC_LEFT << IC_RIGHT 
39066 \end_layout
39067
39068 \end_inset
39069 </cell>
39070 </row>
39071 <row topline="true">
39072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39073 \begin_inset Text
39074
39075 \begin_layout Standard
39076
39077 \size footnotesize
39078 RIGHT_OP
39079 \end_layout
39080
39081 \end_inset
39082 </cell>
39083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39084 \begin_inset Text
39085
39086 \begin_layout Standard
39087
39088 \size footnotesize
39089 IC_LEFT() IC_RIGHT() IC_RESULT()
39090 \end_layout
39091
39092 \end_inset
39093 </cell>
39094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39095 \begin_inset Text
39096
39097 \begin_layout Standard
39098
39099 \size footnotesize
39100 Right shift
39101 \end_layout
39102
39103 \end_inset
39104 </cell>
39105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39106 \begin_inset Text
39107
39108 \begin_layout Standard
39109
39110 \size footnotesize
39111 IC_RESULT = IC_LEFT >> IC_RIGHT 
39112 \end_layout
39113
39114 \end_inset
39115 </cell>
39116 </row>
39117 <row topline="true">
39118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39119 \begin_inset Text
39120
39121 \begin_layout Standard
39122
39123 \size footnotesize
39124 GET_VALUE_
39125 \newline
39126 AT_ ADDRESS
39127 \end_layout
39128
39129 \end_inset
39130 </cell>
39131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39132 \begin_inset Text
39133
39134 \begin_layout Standard
39135
39136 \size footnotesize
39137 IC_LEFT() IC_RESULT()
39138 \end_layout
39139
39140 \end_inset
39141 </cell>
39142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39143 \begin_inset Text
39144
39145 \begin_layout Standard
39146
39147 \size footnotesize
39148 Indirect fetch 
39149 \end_layout
39150
39151 \end_inset
39152 </cell>
39153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39154 \begin_inset Text
39155
39156 \begin_layout Standard
39157
39158 \size footnotesize
39159 IC_RESULT = (*IC_LEFT);
39160 \end_layout
39161
39162 \end_inset
39163 </cell>
39164 </row>
39165 <row topline="true">
39166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39167 \begin_inset Text
39168
39169 \begin_layout Standard
39170
39171 \size footnotesize
39172 POINTER_SET
39173 \end_layout
39174
39175 \end_inset
39176 </cell>
39177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39178 \begin_inset Text
39179
39180 \begin_layout Standard
39181
39182 \size footnotesize
39183 IC_RIGHT() IC_RESULT() 
39184 \end_layout
39185
39186 \end_inset
39187 </cell>
39188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39189 \begin_inset Text
39190
39191 \begin_layout Standard
39192
39193 \size footnotesize
39194 Indirect set
39195 \end_layout
39196
39197 \end_inset
39198 </cell>
39199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39200 \begin_inset Text
39201
39202 \begin_layout Standard
39203
39204 \size footnotesize
39205 (*IC_RESULT) = IC_RIGHT;
39206 \end_layout
39207
39208 \end_inset
39209 </cell>
39210 </row>
39211 <row topline="true">
39212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39213 \begin_inset Text
39214
39215 \begin_layout Standard
39216
39217 \size footnotesize
39218 '='
39219 \end_layout
39220
39221 \end_inset
39222 </cell>
39223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39224 \begin_inset Text
39225
39226 \begin_layout Standard
39227
39228 \size footnotesize
39229 IC_RIGHT() IC_RESULT()
39230 \end_layout
39231
39232 \end_inset
39233 </cell>
39234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39235 \begin_inset Text
39236
39237 \begin_layout Standard
39238
39239 \size footnotesize
39240 Assignment
39241 \end_layout
39242
39243 \end_inset
39244 </cell>
39245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39246 \begin_inset Text
39247
39248 \begin_layout Standard
39249
39250 \size footnotesize
39251 IC_RESULT = IC_RIGHT;
39252 \end_layout
39253
39254 \end_inset
39255 </cell>
39256 </row>
39257 <row topline="true">
39258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39259 \begin_inset Text
39260
39261 \begin_layout Standard
39262
39263 \size footnotesize
39264 IFX
39265 \end_layout
39266
39267 \end_inset
39268 </cell>
39269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39270 \begin_inset Text
39271
39272 \begin_layout Standard
39273
39274 \size footnotesize
39275 IC_COND IC_TRUE IC_LABEL
39276 \end_layout
39277
39278 \end_inset
39279 </cell>
39280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39281 \begin_inset Text
39282
39283 \begin_layout Standard
39284
39285 \size footnotesize
39286 Conditional jump.
39287  If true label is present then jump to true label if condition is true else
39288  jump to false label if condition is false 
39289 \end_layout
39290
39291 \end_inset
39292 </cell>
39293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39294 \begin_inset Text
39295
39296 \begin_layout Standard
39297
39298 \size footnotesize
39299 if (IC_COND) goto IC_TRUE; 
39300 \newline
39301 \InsetSpace ~
39302 \InsetSpace ~
39303 Or 
39304 \newline
39305 If (!IC_COND) goto IC_FALSE;
39306 \end_layout
39307
39308 \end_inset
39309 </cell>
39310 </row>
39311 <row topline="true">
39312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39313 \begin_inset Text
39314
39315 \begin_layout Standard
39316
39317 \size footnotesize
39318 ADDRESS_OF
39319 \end_layout
39320
39321 \end_inset
39322 </cell>
39323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39324 \begin_inset Text
39325
39326 \begin_layout Standard
39327
39328 \size footnotesize
39329 IC_LEFT() IC_RESULT()
39330 \end_layout
39331
39332 \end_inset
39333 </cell>
39334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39335 \begin_inset Text
39336
39337 \begin_layout Standard
39338
39339 \size footnotesize
39340 Address of 
39341 \end_layout
39342
39343 \end_inset
39344 </cell>
39345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39346 \begin_inset Text
39347
39348 \begin_layout Standard
39349
39350 \size footnotesize
39351 IC_RESULT = &IC_LEFT();
39352 \end_layout
39353
39354 \end_inset
39355 </cell>
39356 </row>
39357 <row topline="true">
39358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39359 \begin_inset Text
39360
39361 \begin_layout Standard
39362
39363 \size footnotesize
39364 JUMPTABLE
39365 \end_layout
39366
39367 \end_inset
39368 </cell>
39369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39370 \begin_inset Text
39371
39372 \begin_layout Standard
39373
39374 \size footnotesize
39375 IC_JTCOND IC_JTLABELS
39376 \end_layout
39377
39378 \end_inset
39379 </cell>
39380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39381 \begin_inset Text
39382
39383 \begin_layout Standard
39384
39385 \size footnotesize
39386 Jump to list of labels depending on the value of JTCOND
39387 \end_layout
39388
39389 \end_inset
39390 </cell>
39391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39392 \begin_inset Text
39393
39394 \begin_layout Standard
39395
39396 \size footnotesize
39397 Switch statement
39398 \end_layout
39399
39400 \end_inset
39401 </cell>
39402 </row>
39403 <row topline="true">
39404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39405 \begin_inset Text
39406
39407 \begin_layout Standard
39408
39409 \size footnotesize
39410 CAST
39411 \end_layout
39412
39413 \end_inset
39414 </cell>
39415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39416 \begin_inset Text
39417
39418 \begin_layout Standard
39419
39420 \size footnotesize
39421 IC_RIGHT() IC_LEFT() IC_RESULT()
39422 \end_layout
39423
39424 \end_inset
39425 </cell>
39426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39427 \begin_inset Text
39428
39429 \begin_layout Standard
39430
39431 \size footnotesize
39432 Cast types 
39433 \end_layout
39434
39435 \end_inset
39436 </cell>
39437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39438 \begin_inset Text
39439
39440 \begin_layout Standard
39441
39442 \size footnotesize
39443 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39444 \end_layout
39445
39446 \end_inset
39447 </cell>
39448 </row>
39449 <row topline="true">
39450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39451 \begin_inset Text
39452
39453 \begin_layout Standard
39454
39455 \size footnotesize
39456 SEND
39457 \end_layout
39458
39459 \end_inset
39460 </cell>
39461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39462 \begin_inset Text
39463
39464 \begin_layout Standard
39465
39466 \size footnotesize
39467 IC_LEFT()
39468 \end_layout
39469
39470 \end_inset
39471 </cell>
39472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39473 \begin_inset Text
39474
39475 \begin_layout Standard
39476
39477 \size footnotesize
39478 This is used for passing parameters in registers; 
39479 \newline
39480 move IC_LEFT to the next
39481  available parameter register.
39482 \end_layout
39483
39484 \end_inset
39485 </cell>
39486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39487 \begin_inset Text
39488
39489 \begin_layout Standard
39490
39491 \size footnotesize
39492 None
39493 \end_layout
39494
39495 \end_inset
39496 </cell>
39497 </row>
39498 <row topline="true">
39499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39500 \begin_inset Text
39501
39502 \begin_layout Standard
39503
39504 \size footnotesize
39505 RECV
39506 \end_layout
39507
39508 \end_inset
39509 </cell>
39510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39511 \begin_inset Text
39512
39513 \begin_layout Standard
39514
39515 \size footnotesize
39516 IC_RESULT()
39517 \end_layout
39518
39519 \end_inset
39520 </cell>
39521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39522 \begin_inset Text
39523
39524 \begin_layout Standard
39525
39526 \size footnotesize
39527 This is used for receiving parameters passed in registers;
39528 \newline
39529 Move the values
39530  in the next parameter register to IC_RESULT 
39531 \end_layout
39532
39533 \end_inset
39534 </cell>
39535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39536 \begin_inset Text
39537
39538 \begin_layout Standard
39539
39540 \size footnotesize
39541 None
39542 \end_layout
39543
39544 \end_inset
39545 </cell>
39546 </row>
39547 <row topline="true" bottomline="true">
39548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39549 \begin_inset Text
39550
39551 \begin_layout Standard
39552
39553 \shape slanted
39554 \size footnotesize
39555 (some more have been added)
39556 \end_layout
39557
39558 \end_inset
39559 </cell>
39560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39561 \begin_inset Text
39562
39563 \begin_layout Standard
39564
39565 \end_layout
39566
39567 \end_inset
39568 </cell>
39569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39570 \begin_inset Text
39571
39572 \begin_layout Standard
39573
39574 \end_layout
39575
39576 \end_inset
39577 </cell>
39578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39579 \begin_inset Text
39580
39581 \begin_layout Standard
39582
39583 \shape slanted
39584 \size footnotesize
39585 see f.e.
39586  
39587 \family typewriter
39588 gen51Code()
39589 \family default
39590  in 
39591 \family typewriter
39592 src/mcs51/gen.c
39593 \end_layout
39594
39595 \end_inset
39596 </cell>
39597 </row>
39598 </lyxtabular>
39599
39600 \end_inset
39601
39602
39603 \end_layout
39604
39605 \begin_layout Standard
39606 \begin_inset Note Note
39607 status collapsed
39608
39609 \begin_layout Standard
39610 In the original article Figure II was announced to be downloadable on 
39611 \shape italic
39612 Circuit Cellar
39613 \shape default
39614 's web site.
39615  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39616 \end_layout
39617
39618 \end_inset
39619
39620
39621 \end_layout
39622
39623 \begin_layout Paragraph*
39624 ICode Example
39625 \begin_inset LatexCommand \index{iCode}
39626
39627 \end_inset
39628
39629
39630 \end_layout
39631
39632 \begin_layout Standard
39633 This section shows some details of iCode.
39634  The example C code does not do anything useful; it is used as an example
39635  to illustrate the intermediate code generated by the compiler.
39636 \end_layout
39637
39638 \begin_layout Verse
39639
39640 \family typewriter
39641 1.\InsetSpace ~
39642 xdata int * p;
39643 \newline
39644 2.\InsetSpace ~
39645 int gint;
39646 \newline
39647 3.\InsetSpace ~
39648 /* This function does nothing useful.
39649  It is used
39650 \newline
39651 4.\InsetSpace ~
39652 \InsetSpace ~
39653 \InsetSpace ~
39654 \InsetSpace ~
39655 for the purpose of explaining iCode */
39656 \newline
39657 5.\InsetSpace ~
39658 short function (data
39659  int *x)
39660 \newline
39661 6.\InsetSpace ~
39662 {
39663 \newline
39664 7.\InsetSpace ~
39665 \InsetSpace ~
39666 \InsetSpace ~
39667 short i=10; \InsetSpace ~
39668 \InsetSpace ~
39669 /* dead initialization eliminated */
39670 \newline
39671 8.\InsetSpace ~
39672 \InsetSpace ~
39673 \InsetSpace ~
39674 short sum=10;
39675  /* dead initialization eliminated */
39676 \newline
39677 9.\InsetSpace ~
39678 \InsetSpace ~
39679 \InsetSpace ~
39680 short mul;
39681 \newline
39682 10.\InsetSpace ~
39683 \InsetSpace ~
39684 int j ;
39685 \newline
39686 11.\InsetSpace ~
39687 \InsetSpace ~
39688 while (*x) *x++
39689  = *p++; 
39690 \newline
39691 12.\InsetSpace ~
39692 \InsetSpace ~
39693 \InsetSpace ~
39694 \InsetSpace ~
39695 sum = 0 ; 
39696 \newline
39697 13.\InsetSpace ~
39698 \InsetSpace ~
39699 mul = 0;
39700 \newline
39701 14.\InsetSpace ~
39702 \InsetSpace ~
39703 /* compiler detects i,j to be induction
39704  variables */
39705 \newline
39706 15.\InsetSpace ~
39707 \InsetSpace ~
39708 for (i = 0, j = 10 ; i < 10 ; i++, j
39709 \family default
39710 -
39711 \begin_inset ERT
39712 status collapsed
39713
39714 \begin_layout Standard
39715
39716
39717 \backslash
39718 /
39719 \end_layout
39720
39721 \end_inset
39722
39723 -
39724 \family typewriter
39725 ) {
39726 \newline
39727 16.\InsetSpace ~
39728 \InsetSpace ~
39729 \InsetSpace ~
39730 \InsetSpace ~
39731 sum += i;
39732 \newline
39733 17.\InsetSpace ~
39734 \InsetSpace ~
39735 \InsetSpace ~
39736 \InsetSpace ~
39737 mul += i * 3; \InsetSpace ~
39738 \InsetSpace ~
39739 /* this multiplication remains */
39740 \newline
39741 18.\InsetSpace ~
39742 \InsetSpace ~
39743 \InsetSpace ~
39744 \InsetSpace ~
39745 gint +=
39746  j * 3;\InsetSpace ~
39747 \InsetSpace ~
39748 /* this multiplication changed to addition */
39749 \newline
39750 19.\InsetSpace ~
39751 \InsetSpace ~
39752 }
39753 \newline
39754 20.\InsetSpace ~
39755 \InsetSpace ~
39756 return sum+mul;
39757 \newline
39758 21.\InsetSpace ~
39759 }
39760 \end_layout
39761
39762 \begin_layout Standard
39763 In addition to the operands each iCode contains information about the filename
39764  and line it corresponds to in the source file.
39765  The first field in the listing should be interpreted as follows:
39766 \newline
39767
39768 \shape italic
39769 \size footnotesize
39770 Filename(linenumber: iCode Execution sequence number : ICode hash table
39771  key : loop depth of the iCode).
39772 \shape default
39773 \size default
39774
39775 \newline
39776 Then follows the human readable form of the ICode operation.
39777  Each operand of this triplet form can be of three basic types a) compiler
39778  generated temporary b) user defined variable c) a constant value.
39779  Note that local variables and parameters are replaced by compiler generated
39780  temporaries.
39781  Live ranges
39782 \begin_inset LatexCommand \index{Live range analysis}
39783
39784 \end_inset
39785
39786  are computed only for temporaries (i.e.
39787  live ranges are not computed for global variables).
39788  Registers
39789 \begin_inset LatexCommand \index{Register allocation}
39790
39791 \end_inset
39792
39793  are allocated for temporaries only.
39794  Operands are formatted in the following manner:
39795 \newline
39796
39797 \shape italic
39798 \size footnotesize
39799 Operand Name [lr live-from : live-to ] { type information } [ registers
39800  allocated ].
39801 \shape default
39802 \size default
39803
39804 \newline
39805 As mentioned earlier the live ranges are computed in terms of the execution
39806  sequence number of the iCodes, for example 
39807 \newline
39808 the iTemp0 is live from (i.e.
39809  first defined in iCode with execution sequence number 3, and is last used
39810  in the iCode with sequence number 5).
39811  For induction variables such as iTemp21 the live range computation extends
39812  the lifetime from the start to the end of the loop.
39813 \newline
39814 The register allocator
39815  used the live range information to allocate registers, the same registers
39816  may be used for different temporaries if their live ranges do not overlap,
39817  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39818  ranges do not overlap.
39819  In addition the allocator also takes into consideration the type and usage
39820  of a temporary, for example itemp6 is a pointer to near space and is used
39821  as to fetch data from (i.e.
39822  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39823  Some short lived temporaries are allocated to special registers which have
39824  meaning to the code generator e.g.
39825  iTemp13 is allocated to a pseudo register CC which tells the back end that
39826  the temporary is used only for a conditional jump the code generation makes
39827  use of this information to optimize a compare and jump ICode.
39828 \newline
39829 There are several
39830  loop optimizations
39831 \begin_inset LatexCommand \index{Loop optimization}
39832
39833 \end_inset
39834
39835  performed by the compiler.
39836  It can detect induction variables iTemp21(i) and iTemp23(j).
39837  Also note the compiler does selective strength reduction
39838 \begin_inset LatexCommand \index{Strength reduction}
39839
39840 \end_inset
39841
39842 , i.e.
39843  the multiplication of an induction variable in line 18 (gint = j * 3) is
39844  changed to addition, a new temporary iTemp17 is allocated and assigned
39845  a initial value, a constant 3 is then added for each iteration of the loop.
39846  The compiler does not change the multiplication
39847 \begin_inset LatexCommand \index{Multiplication}
39848
39849 \end_inset
39850
39851  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39852 \newline
39853
39854 Note the dead code elimination
39855 \begin_inset LatexCommand \index{Dead-code elimination}
39856
39857 \end_inset
39858
39859  optimization eliminated the dead assignments in line 7 & 8 to I and sum
39860  respectively.
39861 \newline
39862
39863 \end_layout
39864
39865 \begin_layout Standard
39866
39867 \size footnotesize
39868 Sample.c (5:1:0:0) _entry($9) :
39869 \end_layout
39870
39871 \begin_layout Standard
39872
39873 \size footnotesize
39874 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39875 \end_layout
39876
39877 \begin_layout Standard
39878
39879 \size footnotesize
39880 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
39881 \end_layout
39882
39883 \begin_layout Standard
39884
39885 \size footnotesize
39886 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39887 \end_layout
39888
39889 \begin_layout Standard
39890
39891 \size footnotesize
39892 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39893  * int}[r2]
39894 \end_layout
39895
39896 \begin_layout Standard
39897
39898 \size footnotesize
39899 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39900 \end_layout
39901
39902 \begin_layout Standard
39903
39904 \size footnotesize
39905 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39906  int}[r0]]
39907 \end_layout
39908
39909 \begin_layout Standard
39910
39911 \size footnotesize
39912 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39913 \end_layout
39914
39915 \begin_layout Standard
39916
39917 \size footnotesize
39918 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39919  * int}
39920 \end_layout
39921
39922 \begin_layout Standard
39923
39924 \size footnotesize
39925 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39926  {short}
39927 \end_layout
39928
39929 \begin_layout Standard
39930
39931 \size footnotesize
39932 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39933  * int}[DPTR]]
39934 \end_layout
39935
39936 \begin_layout Standard
39937
39938 \size footnotesize
39939 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39940 }[r2 r3]
39941 \end_layout
39942
39943 \begin_layout Standard
39944
39945 \size footnotesize
39946 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39947  * int}[r0] + 0x2 {short}
39948 \end_layout
39949
39950 \begin_layout Standard
39951
39952 \size footnotesize
39953 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39954 \end_layout
39955
39956 \begin_layout Standard
39957
39958 \size footnotesize
39959 Sample.c(11:17:21:0)_whilebreak_0($3) :
39960 \end_layout
39961
39962 \begin_layout Standard
39963
39964 \size footnotesize
39965 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39966 \end_layout
39967
39968 \begin_layout Standard
39969
39970 \size footnotesize
39971 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39972 \end_layout
39973
39974 \begin_layout Standard
39975
39976 \size footnotesize
39977 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39978 \end_layout
39979
39980 \begin_layout Standard
39981
39982 \size footnotesize
39983 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39984 \end_layout
39985
39986 \begin_layout Standard
39987
39988 \size footnotesize
39989 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39990 \end_layout
39991
39992 \begin_layout Standard
39993
39994 \size footnotesize
39995 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39996 \end_layout
39997
39998 \begin_layout Standard
39999
40000 \size footnotesize
40001 Sample.c(15:24:26:1)_forcond_0($4) :
40002 \end_layout
40003
40004 \begin_layout Standard
40005
40006 \size footnotesize
40007 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
40008  < 0xa {short}
40009 \end_layout
40010
40011 \begin_layout Standard
40012
40013 \size footnotesize
40014 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40015 \end_layout
40016
40017 \begin_layout Standard
40018
40019 \size footnotesize
40020 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
40021  + ITemp21 [lr21:38]{short}[r4]
40022 \end_layout
40023
40024 \begin_layout Standard
40025
40026 \size footnotesize
40027 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
40028  * 0x3 {short}
40029 \end_layout
40030
40031 \begin_layout Standard
40032
40033 \size footnotesize
40034 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
40035  + iTemp15 [lr29:30]{short}[r1]
40036 \end_layout
40037
40038 \begin_layout Standard
40039
40040 \size footnotesize
40041 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
40042  r0]- 0x3 {short}
40043 \end_layout
40044
40045 \begin_layout Standard
40046
40047 \size footnotesize
40048 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
40049 int}[r7 r0]
40050 \end_layout
40051
40052 \begin_layout Standard
40053
40054 \size footnotesize
40055 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
40056  + 0x1 {short}
40057 \end_layout
40058
40059 \begin_layout Standard
40060
40061 \size footnotesize
40062 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
40063  r6]- 0x1 {short}
40064 \end_layout
40065
40066 \begin_layout Standard
40067
40068 \size footnotesize
40069 Sample.c(19:38:47:1) goto _forcond_0($4)
40070 \end_layout
40071
40072 \begin_layout Standard
40073
40074 \size footnotesize
40075 Sample.c(19:39:48:0)_forbreak_0($7) :
40076 \end_layout
40077
40078 \begin_layout Standard
40079
40080 \size footnotesize
40081 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
40082  + ITemp11 [lr19:40]{short}[r3]
40083 \end_layout
40084
40085 \begin_layout Standard
40086
40087 \size footnotesize
40088 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
40089 \end_layout
40090
40091 \begin_layout Standard
40092
40093 \size footnotesize
40094 Sample.c(20:42:51:0)_return($8) :
40095 \end_layout
40096
40097 \begin_layout Standard
40098
40099 \size footnotesize
40100 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40101 \size default
40102
40103 \newline
40104
40105 \newline
40106 Finally the code generated for this function:
40107 \newline
40108
40109 \end_layout
40110
40111 \begin_layout Standard
40112
40113 \size footnotesize
40114 .area DSEG (DATA)
40115 \end_layout
40116
40117 \begin_layout Standard
40118
40119 \size footnotesize
40120 _p::
40121 \end_layout
40122
40123 \begin_layout Standard
40124
40125 \size footnotesize
40126 \InsetSpace ~
40127 \InsetSpace ~
40128 .ds 2
40129 \end_layout
40130
40131 \begin_layout Standard
40132
40133 \size footnotesize
40134 _gint::
40135 \end_layout
40136
40137 \begin_layout Standard
40138
40139 \size footnotesize
40140 \InsetSpace ~
40141 \InsetSpace ~
40142 .ds 2
40143 \end_layout
40144
40145 \begin_layout Standard
40146
40147 \size footnotesize
40148 ; sample.c 5
40149 \end_layout
40150
40151 \begin_layout Standard
40152
40153 \size footnotesize
40154 ; ----------------------------------------------
40155 \end_layout
40156
40157 \begin_layout Standard
40158
40159 \size footnotesize
40160 ; function function
40161 \end_layout
40162
40163 \begin_layout Standard
40164
40165 \size footnotesize
40166 ; ----------------------------------------------
40167 \end_layout
40168
40169 \begin_layout Standard
40170
40171 \size footnotesize
40172 _function:
40173 \end_layout
40174
40175 \begin_layout Standard
40176
40177 \size footnotesize
40178 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
40179 \end_layout
40180
40181 \begin_layout Standard
40182
40183 \size footnotesize
40184 \InsetSpace ~
40185 \InsetSpace ~
40186 mov r2,dpl
40187 \end_layout
40188
40189 \begin_layout Standard
40190
40191 \size footnotesize
40192 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40193 \end_layout
40194
40195 \begin_layout Standard
40196
40197 \size footnotesize
40198 \InsetSpace ~
40199 \InsetSpace ~
40200 mov ar0,r2
40201 \end_layout
40202
40203 \begin_layout Standard
40204
40205 \size footnotesize
40206 ;_whilecontinue_0($1) :
40207 \end_layout
40208
40209 \begin_layout Standard
40210
40211 \size footnotesize
40212 00101$:
40213 \end_layout
40214
40215 \begin_layout Standard
40216
40217 \size footnotesize
40218 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40219 \end_layout
40220
40221 \begin_layout Standard
40222
40223 \size footnotesize
40224 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40225 \end_layout
40226
40227 \begin_layout Standard
40228
40229 \size footnotesize
40230 \InsetSpace ~
40231 \InsetSpace ~
40232 mov ar2,@r0
40233 \end_layout
40234
40235 \begin_layout Standard
40236
40237 \size footnotesize
40238 \InsetSpace ~
40239 \InsetSpace ~
40240 inc r0
40241 \end_layout
40242
40243 \begin_layout Standard
40244
40245 \size footnotesize
40246 \InsetSpace ~
40247 \InsetSpace ~
40248 mov ar3,@r0
40249 \end_layout
40250
40251 \begin_layout Standard
40252
40253 \size footnotesize
40254 \InsetSpace ~
40255 \InsetSpace ~
40256 dec r0
40257 \end_layout
40258
40259 \begin_layout Standard
40260
40261 \size footnotesize
40262 \InsetSpace ~
40263 \InsetSpace ~
40264 mov a,r2
40265 \end_layout
40266
40267 \begin_layout Standard
40268
40269 \size footnotesize
40270 \InsetSpace ~
40271 \InsetSpace ~
40272 orl a,r3
40273 \end_layout
40274
40275 \begin_layout Standard
40276
40277 \size footnotesize
40278 \InsetSpace ~
40279 \InsetSpace ~
40280 jz 00103$
40281 \end_layout
40282
40283 \begin_layout Standard
40284
40285 \size footnotesize
40286 00114$:
40287 \end_layout
40288
40289 \begin_layout Standard
40290
40291 \size footnotesize
40292 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40293 \end_layout
40294
40295 \begin_layout Standard
40296
40297 \size footnotesize
40298 \InsetSpace ~
40299 \InsetSpace ~
40300 mov dpl,_p
40301 \end_layout
40302
40303 \begin_layout Standard
40304
40305 \size footnotesize
40306 \InsetSpace ~
40307 \InsetSpace ~
40308 mov dph,(_p + 1)
40309 \end_layout
40310
40311 \begin_layout Standard
40312
40313 \size footnotesize
40314 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40315 \end_layout
40316
40317 \begin_layout Standard
40318
40319 \size footnotesize
40320 \InsetSpace ~
40321 \InsetSpace ~
40322 mov a,#0x02
40323 \end_layout
40324
40325 \begin_layout Standard
40326
40327 \size footnotesize
40328 \InsetSpace ~
40329 \InsetSpace ~
40330 add a,_p
40331 \end_layout
40332
40333 \begin_layout Standard
40334
40335 \size footnotesize
40336 \InsetSpace ~
40337 \InsetSpace ~
40338 mov _p,a
40339 \end_layout
40340
40341 \begin_layout Standard
40342
40343 \size footnotesize
40344 \InsetSpace ~
40345 \InsetSpace ~
40346 clr a
40347 \end_layout
40348
40349 \begin_layout Standard
40350
40351 \size footnotesize
40352 \InsetSpace ~
40353 \InsetSpace ~
40354 addc a,(_p + 1)
40355 \end_layout
40356
40357 \begin_layout Standard
40358
40359 \size footnotesize
40360 \InsetSpace ~
40361 \InsetSpace ~
40362 mov (_p + 1),a
40363 \end_layout
40364
40365 \begin_layout Standard
40366
40367 \size footnotesize
40368 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40369 \end_layout
40370
40371 \begin_layout Standard
40372
40373 \size footnotesize
40374 \InsetSpace ~
40375 \InsetSpace ~
40376 movx a,@dptr
40377 \end_layout
40378
40379 \begin_layout Standard
40380
40381 \size footnotesize
40382 \InsetSpace ~
40383 \InsetSpace ~
40384 mov r2,a
40385 \end_layout
40386
40387 \begin_layout Standard
40388
40389 \size footnotesize
40390 \InsetSpace ~
40391 \InsetSpace ~
40392 inc dptr
40393 \end_layout
40394
40395 \begin_layout Standard
40396
40397 \size footnotesize
40398 \InsetSpace ~
40399 \InsetSpace ~
40400 movx a,@dptr
40401 \end_layout
40402
40403 \begin_layout Standard
40404
40405 \size footnotesize
40406 \InsetSpace ~
40407 \InsetSpace ~
40408 mov r3,a
40409 \end_layout
40410
40411 \begin_layout Standard
40412
40413 \size footnotesize
40414 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40415 \end_layout
40416
40417 \begin_layout Standard
40418
40419 \size footnotesize
40420 \InsetSpace ~
40421 \InsetSpace ~
40422 mov @r0,ar2
40423 \end_layout
40424
40425 \begin_layout Standard
40426
40427 \size footnotesize
40428 \InsetSpace ~
40429 \InsetSpace ~
40430 inc r0
40431 \end_layout
40432
40433 \begin_layout Standard
40434
40435 \size footnotesize
40436 \InsetSpace ~
40437 \InsetSpace ~
40438 mov @r0,ar3
40439 \end_layout
40440
40441 \begin_layout Standard
40442
40443 \size footnotesize
40444 ; iTemp6 [lr5:16]{_near * int}[r0] = 
40445 \end_layout
40446
40447 \begin_layout Standard
40448
40449 \size footnotesize
40450 ; iTemp6 [lr5:16]{_near * int}[r0] + 
40451 \end_layout
40452
40453 \begin_layout Standard
40454
40455 \size footnotesize
40456 ; 0x2 {short}
40457 \end_layout
40458
40459 \begin_layout Standard
40460
40461 \size footnotesize
40462 \InsetSpace ~
40463 \InsetSpace ~
40464 inc r0
40465 \end_layout
40466
40467 \begin_layout Standard
40468
40469 \size footnotesize
40470 ; goto _whilecontinue_0($1)
40471 \end_layout
40472
40473 \begin_layout Standard
40474
40475 \size footnotesize
40476 \InsetSpace ~
40477 \InsetSpace ~
40478 sjmp 00101$
40479 \end_layout
40480
40481 \begin_layout Standard
40482
40483 \size footnotesize
40484 ; _whilebreak_0($3) :
40485 \end_layout
40486
40487 \begin_layout Standard
40488
40489 \size footnotesize
40490 00103$:
40491 \end_layout
40492
40493 \begin_layout Standard
40494
40495 \size footnotesize
40496 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40497 \end_layout
40498
40499 \begin_layout Standard
40500
40501 \size footnotesize
40502 \InsetSpace ~
40503 \InsetSpace ~
40504 mov r2,#0x00
40505 \end_layout
40506
40507 \begin_layout Standard
40508
40509 \size footnotesize
40510 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40511 \end_layout
40512
40513 \begin_layout Standard
40514
40515 \size footnotesize
40516 \InsetSpace ~
40517 \InsetSpace ~
40518 mov r3,#0x00
40519 \end_layout
40520
40521 \begin_layout Standard
40522
40523 \size footnotesize
40524 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40525 \end_layout
40526
40527 \begin_layout Standard
40528
40529 \size footnotesize
40530 \InsetSpace ~
40531 \InsetSpace ~
40532 mov r4,#0x00
40533 \end_layout
40534
40535 \begin_layout Standard
40536
40537 \size footnotesize
40538 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40539 \end_layout
40540
40541 \begin_layout Standard
40542
40543 \size footnotesize
40544 \InsetSpace ~
40545 \InsetSpace ~
40546 mov r5,#0x0A
40547 \end_layout
40548
40549 \begin_layout Standard
40550
40551 \size footnotesize
40552 \InsetSpace ~
40553 \InsetSpace ~
40554 mov r6,#0x00
40555 \end_layout
40556
40557 \begin_layout Standard
40558
40559 \size footnotesize
40560 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40561 \end_layout
40562
40563 \begin_layout Standard
40564
40565 \size footnotesize
40566 \InsetSpace ~
40567 \InsetSpace ~
40568 mov r7,#0x1E
40569 \end_layout
40570
40571 \begin_layout Standard
40572
40573 \size footnotesize
40574 \InsetSpace ~
40575 \InsetSpace ~
40576 mov r0,#0x00
40577 \end_layout
40578
40579 \begin_layout Standard
40580
40581 \size footnotesize
40582 ; _forcond_0($4) :
40583 \end_layout
40584
40585 \begin_layout Standard
40586
40587 \size footnotesize
40588 00104$:
40589 \end_layout
40590
40591 \begin_layout Standard
40592
40593 \size footnotesize
40594 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40595 \end_layout
40596
40597 \begin_layout Standard
40598
40599 \size footnotesize
40600 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40601 \end_layout
40602
40603 \begin_layout Standard
40604
40605 \size footnotesize
40606 \InsetSpace ~
40607 \InsetSpace ~
40608 clr c
40609 \end_layout
40610
40611 \begin_layout Standard
40612
40613 \size footnotesize
40614 \InsetSpace ~
40615 \InsetSpace ~
40616 mov a,r4
40617 \end_layout
40618
40619 \begin_layout Standard
40620
40621 \size footnotesize
40622 \InsetSpace ~
40623 \InsetSpace ~
40624 xrl a,#0x80
40625 \end_layout
40626
40627 \begin_layout Standard
40628
40629 \size footnotesize
40630 \InsetSpace ~
40631 \InsetSpace ~
40632 subb a,#0x8a
40633 \end_layout
40634
40635 \begin_layout Standard
40636
40637 \size footnotesize
40638 \InsetSpace ~
40639 \InsetSpace ~
40640 jnc 00107$
40641 \end_layout
40642
40643 \begin_layout Standard
40644
40645 \size footnotesize
40646 00115$:
40647 \end_layout
40648
40649 \begin_layout Standard
40650
40651 \size footnotesize
40652 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40653 \end_layout
40654
40655 \begin_layout Standard
40656
40657 \size footnotesize
40658 ; iTemp21 [lr21:38]{short}[r4]
40659 \end_layout
40660
40661 \begin_layout Standard
40662
40663 \size footnotesize
40664 \InsetSpace ~
40665 \InsetSpace ~
40666 mov a,r4
40667 \end_layout
40668
40669 \begin_layout Standard
40670
40671 \size footnotesize
40672 \InsetSpace ~
40673 \InsetSpace ~
40674 add a,r2
40675 \end_layout
40676
40677 \begin_layout Standard
40678
40679 \size footnotesize
40680 \InsetSpace ~
40681 \InsetSpace ~
40682 mov r2,a
40683 \end_layout
40684
40685 \begin_layout Standard
40686
40687 \size footnotesize
40688 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40689 \end_layout
40690
40691 \begin_layout Standard
40692
40693 \size footnotesize
40694 \InsetSpace ~
40695 \InsetSpace ~
40696 mov b,#0x03
40697 \end_layout
40698
40699 \begin_layout Standard
40700
40701 \size footnotesize
40702 \InsetSpace ~
40703 \InsetSpace ~
40704 mov a,r4
40705 \end_layout
40706
40707 \begin_layout Standard
40708
40709 \size footnotesize
40710 \InsetSpace ~
40711 \InsetSpace ~
40712 mul ab
40713 \end_layout
40714
40715 \begin_layout Standard
40716
40717 \size footnotesize
40718 \InsetSpace ~
40719 \InsetSpace ~
40720 mov r1,a
40721 \end_layout
40722
40723 \begin_layout Standard
40724
40725 \size footnotesize
40726 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40727 \end_layout
40728
40729 \begin_layout Standard
40730
40731 \size footnotesize
40732 ; iTemp15 [lr29:30]{short}[r1]
40733 \end_layout
40734
40735 \begin_layout Standard
40736
40737 \size footnotesize
40738 \InsetSpace ~
40739 \InsetSpace ~
40740 add a,r3
40741 \end_layout
40742
40743 \begin_layout Standard
40744
40745 \size footnotesize
40746 \InsetSpace ~
40747 \InsetSpace ~
40748 mov r3,a
40749 \end_layout
40750
40751 \begin_layout Standard
40752
40753 \size footnotesize
40754 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40755 \end_layout
40756
40757 \begin_layout Standard
40758
40759 \size footnotesize
40760 \InsetSpace ~
40761 \InsetSpace ~
40762 mov a,r7
40763 \end_layout
40764
40765 \begin_layout Standard
40766
40767 \size footnotesize
40768 \InsetSpace ~
40769 \InsetSpace ~
40770 add a,#0xfd
40771 \end_layout
40772
40773 \begin_layout Standard
40774
40775 \size footnotesize
40776 \InsetSpace ~
40777 \InsetSpace ~
40778 mov r7,a
40779 \end_layout
40780
40781 \begin_layout Standard
40782
40783 \size footnotesize
40784 \InsetSpace ~
40785 \InsetSpace ~
40786 mov a,r0
40787 \end_layout
40788
40789 \begin_layout Standard
40790
40791 \size footnotesize
40792 \InsetSpace ~
40793 \InsetSpace ~
40794 addc a,#0xff
40795 \end_layout
40796
40797 \begin_layout Standard
40798
40799 \size footnotesize
40800 \InsetSpace ~
40801 \InsetSpace ~
40802 mov r0,a
40803 \end_layout
40804
40805 \begin_layout Standard
40806
40807 \size footnotesize
40808 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40809 \end_layout
40810
40811 \begin_layout Standard
40812
40813 \size footnotesize
40814 \InsetSpace ~
40815 \InsetSpace ~
40816 mov a,r7
40817 \end_layout
40818
40819 \begin_layout Standard
40820
40821 \size footnotesize
40822 \InsetSpace ~
40823 \InsetSpace ~
40824 add a,_gint
40825 \end_layout
40826
40827 \begin_layout Standard
40828
40829 \size footnotesize
40830 \InsetSpace ~
40831 \InsetSpace ~
40832 mov _gint,a
40833 \end_layout
40834
40835 \begin_layout Standard
40836
40837 \size footnotesize
40838 \InsetSpace ~
40839 \InsetSpace ~
40840 mov a,r0
40841 \end_layout
40842
40843 \begin_layout Standard
40844
40845 \size footnotesize
40846 \InsetSpace ~
40847 \InsetSpace ~
40848 addc a,(_gint + 1)
40849 \end_layout
40850
40851 \begin_layout Standard
40852
40853 \size footnotesize
40854 \InsetSpace ~
40855 \InsetSpace ~
40856 mov (_gint + 1),a
40857 \end_layout
40858
40859 \begin_layout Standard
40860
40861 \size footnotesize
40862 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40863 \end_layout
40864
40865 \begin_layout Standard
40866
40867 \size footnotesize
40868 \InsetSpace ~
40869 \InsetSpace ~
40870 inc r4
40871 \end_layout
40872
40873 \begin_layout Standard
40874
40875 \size footnotesize
40876 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40877 \end_layout
40878
40879 \begin_layout Standard
40880
40881 \size footnotesize
40882 \InsetSpace ~
40883 \InsetSpace ~
40884 dec r5
40885 \end_layout
40886
40887 \begin_layout Standard
40888
40889 \size footnotesize
40890 \InsetSpace ~
40891 \InsetSpace ~
40892 cjne r5,#0xff,00104$
40893 \end_layout
40894
40895 \begin_layout Standard
40896
40897 \size footnotesize
40898 \InsetSpace ~
40899 \InsetSpace ~
40900 dec r6
40901 \end_layout
40902
40903 \begin_layout Standard
40904
40905 \size footnotesize
40906 ; goto _forcond_0($4)
40907 \end_layout
40908
40909 \begin_layout Standard
40910
40911 \size footnotesize
40912 \InsetSpace ~
40913 \InsetSpace ~
40914 sjmp 00104$
40915 \end_layout
40916
40917 \begin_layout Standard
40918
40919 \size footnotesize
40920 ; _forbreak_0($7) :
40921 \end_layout
40922
40923 \begin_layout Standard
40924
40925 \size footnotesize
40926 00107$:
40927 \end_layout
40928
40929 \begin_layout Standard
40930
40931 \size footnotesize
40932 ; ret iTemp24 [lr40:41]{short}
40933 \end_layout
40934
40935 \begin_layout Standard
40936
40937 \size footnotesize
40938 \InsetSpace ~
40939 \InsetSpace ~
40940 mov a,r3
40941 \end_layout
40942
40943 \begin_layout Standard
40944
40945 \size footnotesize
40946 \InsetSpace ~
40947 \InsetSpace ~
40948 add a,r2
40949 \end_layout
40950
40951 \begin_layout Standard
40952
40953 \size footnotesize
40954 \InsetSpace ~
40955 \InsetSpace ~
40956 mov dpl,a
40957 \end_layout
40958
40959 \begin_layout Standard
40960
40961 \size footnotesize
40962 ; _return($8) :
40963 \end_layout
40964
40965 \begin_layout Standard
40966
40967 \size footnotesize
40968 00108$:
40969 \end_layout
40970
40971 \begin_layout Standard
40972
40973 \size footnotesize
40974 \InsetSpace ~
40975 \InsetSpace ~
40976 ret
40977 \newline
40978
40979 \end_layout
40980
40981 \begin_layout Section
40982 A few words about basic block successors, predecessors and dominators
40983 \end_layout
40984
40985 \begin_layout Standard
40986 Successors are basic blocks
40987 \begin_inset LatexCommand \index{Basic blocks}
40988
40989 \end_inset
40990
40991  that might execute after this basic block.
40992 \newline
40993 Predecessors are basic blocks
40994  that might execute before reaching this basic block.
40995 \newline
40996 Dominators are basic
40997  blocks that WILL execute before reaching this basic block.
40998 \newline
40999
41000 \end_layout
41001
41002 \begin_layout Standard
41003 [basic block 1]
41004 \end_layout
41005
41006 \begin_layout Standard
41007 if (something)
41008 \end_layout
41009
41010 \begin_layout Standard
41011 \InsetSpace ~
41012 \InsetSpace ~
41013 \InsetSpace ~
41014 \InsetSpace ~
41015 [basic block 2]
41016 \end_layout
41017
41018 \begin_layout Standard
41019 else
41020 \end_layout
41021
41022 \begin_layout Standard
41023 \InsetSpace ~
41024 \InsetSpace ~
41025 \InsetSpace ~
41026 \InsetSpace ~
41027 [basic block 3]
41028 \end_layout
41029
41030 \begin_layout Standard
41031 [basic block 4]
41032 \newline
41033
41034 \end_layout
41035
41036 \begin_layout Standard
41037 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
41038 \end_layout
41039
41040 \begin_layout Standard
41041 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
41042 \end_layout
41043
41044 \begin_layout Standard
41045 c) domVect of [BB4] = BB1 ...
41046  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
41047  was executed.
41048 \end_layout
41049
41050 \begin_layout Chapter
41051 Acknowledgments
41052 \end_layout
41053
41054 \begin_layout Standard
41055 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
41056
41057 \end_inset
41058
41059
41060 \newline
41061
41062 \newline
41063
41064 \emph on
41065 Thanks to all the other volunteer developers who have helped with coding,
41066  testing, web-page creation, distribution sets, etc.
41067  You know who you are :-)
41068 \emph default
41069
41070 \newline
41071
41072 \newline
41073
41074 \emph on
41075 Thanks to Sourceforge 
41076 \begin_inset LatexCommand \url{http://www.sf.net}
41077
41078 \end_inset
41079
41080  which has hosted the project since 1999 and donates significant download
41081  bandwidth.
41082 \emph default
41083
41084 \newline
41085
41086 \newline
41087
41088 \emph on
41089 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
41090  cycles and bandwidth for snapshot builds.
41091 \newline
41092
41093 \end_layout
41094
41095 \begin_layout Standard
41096 This document was initially written by Sandeep Dutta
41097 \end_layout
41098
41099 \begin_layout Standard
41100 All product names mentioned herein may be trademarks
41101 \begin_inset LatexCommand \index{Trademarks}
41102
41103 \end_inset
41104
41105  of their respective companies.
41106  
41107 \end_layout
41108
41109 \begin_layout Section*
41110 Alphabetical index
41111 \end_layout
41112
41113 \begin_layout Standard
41114 To avoid confusion, the installation and building options for SDCC itself
41115  (chapter 2) are not part of the index.
41116 \end_layout
41117
41118 \begin_layout Standard
41119 \begin_inset LatexCommand \printindex{}
41120
41121 \end_inset
41122
41123
41124 \end_layout
41125
41126 \end_body
41127 \end_document