* .version, doc/sdccman.lyx: bumped sdcc version to 2.8.3
[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.3
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 Itemize
1162 in older versions, the preprocessor was always called with -std=c99 regardless
1163  of the --std-xxx setting.
1164  This is no longer true, and can cause compilation failures on code built
1165  with --std-c89 but using c99 preprocessor features, such as one-line (//)
1166  comments
1167 \end_layout
1168
1169 \begin_layout Standard
1170
1171 \emph on
1172 <pending: more incompatibilities?>
1173 \end_layout
1174
1175 \begin_layout Section
1176 System Requirements
1177 \end_layout
1178
1179 \begin_layout Standard
1180 What do you need before you start installation of SDCC? A computer, and
1181  a desire to compute.
1182  The preferred method of installation is to compile SDCC from source using
1183  GNU gcc and make.
1184  For Windows some pre-compiled binary distributions are available for your
1185  convenience.
1186  You should have some experience with command line tools and compiler use.
1187 \end_layout
1188
1189 \begin_layout Section
1190 Other Resources
1191 \end_layout
1192
1193 \begin_layout Standard
1194 The SDCC home page at 
1195 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1196
1197 \end_inset
1198
1199  is a great place to find distribution sets.
1200  You can also find links to the user mailing lists that offer help or discuss
1201  SDCC with other SDCC users.
1202  Web links to other SDCC related sites can also be found here.
1203  This document can be found in the DOC directory of the source package as
1204  a text or HTML file.
1205  A pdf version of this document is available at 
1206 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1207
1208 \end_inset
1209
1210 .
1211  Some of the other tools (simulator and assembler) included with SDCC contain
1212  their own documentation and can be found in the source distribution.
1213  If you want the latest unreleased software, the complete source package
1214  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1215 sdcc/trunk/sdcc.
1216 \end_layout
1217
1218 \begin_layout Section
1219 Wishes for the future
1220 \end_layout
1221
1222 \begin_layout Standard
1223 There are (and always will be) some things that could be done.
1224  Here are some I can think of:
1225 \newline
1226
1227 \end_layout
1228
1229 \begin_layout Standard
1230
1231 \family typewriter
1232 char KernelFunction3(char p) at 0x340;
1233 \newline
1234
1235 \end_layout
1236
1237 \begin_layout Standard
1238
1239 \family typewriter
1240 better code banking
1241 \begin_inset LatexCommand \index{code banking (limited support)}
1242
1243 \end_inset
1244
1245  support for mcs51
1246 \newline
1247
1248 \newline
1249
1250 \family default
1251 If you can think of some more, please see the section 
1252 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1253
1254 \end_inset
1255
1256  about filing feature requests
1257 \begin_inset LatexCommand \index{Requesting features}
1258
1259 \end_inset
1260
1261
1262 \begin_inset LatexCommand \index{Feature request}
1263
1264 \end_inset
1265
1266 .
1267 \newline
1268
1269 \end_layout
1270
1271 \begin_layout Chapter
1272 Installing SDCC
1273 \begin_inset LatexCommand \index{Installation}
1274
1275 \end_inset
1276
1277
1278 \end_layout
1279
1280 \begin_layout Standard
1281 For most users it is sufficient to skip to either section 
1282 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1283
1284 \end_inset
1285
1286  (Unix) or section 
1287 \begin_inset LatexCommand \ref{sub:Windows-Install}
1288
1289 \end_inset
1290
1291  (Windows).
1292  More detailed instructions follow below.
1293 \end_layout
1294
1295 \begin_layout Section
1296 Configure Options
1297 \begin_inset LatexCommand \index{Options SDCC configuration}
1298
1299 \end_inset
1300
1301
1302 \end_layout
1303
1304 \begin_layout Standard
1305 The install paths, search paths and other options are defined when running
1306  'configure'.
1307  The defaults can be overridden by:
1308 \end_layout
1309
1310 \begin_layout List
1311 \labelwidthstring 00.00.0000
1312 -
1313 \begin_inset ERT
1314 status collapsed
1315
1316 \begin_layout Standard
1317
1318
1319 \backslash
1320 /
1321 \end_layout
1322
1323 \end_inset
1324
1325 -prefix see table below
1326 \end_layout
1327
1328 \begin_layout List
1329 \labelwidthstring 00.00.0000
1330 -
1331 \begin_inset ERT
1332 status collapsed
1333
1334 \begin_layout Standard
1335
1336
1337 \backslash
1338 /
1339 \end_layout
1340
1341 \end_inset
1342
1343 -exec_prefix see table below
1344 \end_layout
1345
1346 \begin_layout List
1347 \labelwidthstring 00.00.0000
1348 -
1349 \begin_inset ERT
1350 status collapsed
1351
1352 \begin_layout Standard
1353
1354
1355 \backslash
1356 /
1357 \end_layout
1358
1359 \end_inset
1360
1361 -bindir see table below
1362 \end_layout
1363
1364 \begin_layout List
1365 \labelwidthstring 00.00.0000
1366 -
1367 \begin_inset ERT
1368 status collapsed
1369
1370 \begin_layout Standard
1371
1372
1373 \backslash
1374 /
1375 \end_layout
1376
1377 \end_inset
1378
1379 -datadir see table below
1380 \end_layout
1381
1382 \begin_layout List
1383 \labelwidthstring 00.00.0000
1384 -
1385 \begin_inset ERT
1386 status collapsed
1387
1388 \begin_layout Standard
1389
1390
1391 \backslash
1392 /
1393 \end_layout
1394
1395 \end_inset
1396
1397 -datarootdir see table below
1398 \newline
1399
1400 \end_layout
1401
1402 \begin_layout List
1403 \labelwidthstring 00.00.0000
1404 \InsetSpace ~
1405 \InsetSpace ~
1406 docdir environment variable, see table below
1407 \end_layout
1408
1409 \begin_layout List
1410 \labelwidthstring 00.00.0000
1411 \InsetSpace ~
1412 \InsetSpace ~
1413 include_dir_suffix environment variable, see table below
1414 \end_layout
1415
1416 \begin_layout List
1417 \labelwidthstring 00.00.0000
1418 \InsetSpace ~
1419 \InsetSpace ~
1420 lib_dir_suffix environment variable, see table below
1421 \end_layout
1422
1423 \begin_layout List
1424 \labelwidthstring 00.00.0000
1425 \InsetSpace ~
1426 \InsetSpace ~
1427 sdccconf_h_dir_separator environment variable, either / or 
1428 \backslash
1429
1430 \backslash
1431  makes sense here.
1432  This character will only be used in sdccconf.h; don't forget it's a C-header,
1433  therefore a double-backslash is needed there.
1434 \newline
1435
1436 \end_layout
1437
1438 \begin_layout List
1439 \labelwidthstring 00.00.0000
1440 -
1441 \begin_inset ERT
1442 status collapsed
1443
1444 \begin_layout Standard
1445
1446
1447 \backslash
1448 /
1449 \end_layout
1450
1451 \end_inset
1452
1453 -disable-mcs51-port Excludes the Intel mcs51 port
1454 \end_layout
1455
1456 \begin_layout List
1457 \labelwidthstring 00.00.0000
1458 -
1459 \begin_inset ERT
1460 status collapsed
1461
1462 \begin_layout Standard
1463
1464
1465 \backslash
1466 /
1467 \end_layout
1468
1469 \end_inset
1470
1471 -disable-gbz80-port Excludes the Gameboy gbz80 port
1472 \end_layout
1473
1474 \begin_layout List
1475 \labelwidthstring 00.00.0000
1476 -
1477 \begin_inset ERT
1478 status collapsed
1479
1480 \begin_layout Standard
1481
1482
1483 \backslash
1484 /
1485 \end_layout
1486
1487 \end_inset
1488
1489 -disable-z80-port Excludes the z80 port
1490 \end_layout
1491
1492 \begin_layout List
1493 \labelwidthstring 00.00.0000
1494 -
1495 \begin_inset ERT
1496 status collapsed
1497
1498 \begin_layout Standard
1499
1500
1501 \backslash
1502 /
1503 \end_layout
1504
1505 \end_inset
1506
1507 -disable-avr-port Excludes the AVR port
1508 \end_layout
1509
1510 \begin_layout List
1511 \labelwidthstring 00.00.0000
1512 -
1513 \begin_inset ERT
1514 status collapsed
1515
1516 \begin_layout Standard
1517
1518
1519 \backslash
1520 /
1521 \end_layout
1522
1523 \end_inset
1524
1525 -disable-ds390-port Excludes the DS390 port
1526 \end_layout
1527
1528 \begin_layout List
1529 \labelwidthstring 00.00.0000
1530 -
1531 \begin_inset ERT
1532 status collapsed
1533
1534 \begin_layout Standard
1535
1536
1537 \backslash
1538 /
1539 \end_layout
1540
1541 \end_inset
1542
1543 -disable-hc08-port Excludes the HC08 port
1544 \end_layout
1545
1546 \begin_layout List
1547 \labelwidthstring 00.00.0000
1548 -
1549 \begin_inset ERT
1550 status collapsed
1551
1552 \begin_layout Standard
1553
1554
1555 \backslash
1556 /
1557 \end_layout
1558
1559 \end_inset
1560
1561 -disable-pic-port Excludes the PIC14 port
1562 \end_layout
1563
1564 \begin_layout List
1565 \labelwidthstring 00.00.0000
1566 -
1567 \begin_inset ERT
1568 status collapsed
1569
1570 \begin_layout Standard
1571
1572
1573 \backslash
1574 /
1575 \end_layout
1576
1577 \end_inset
1578
1579 -disable-pic16-port Excludes the PIC16 port
1580 \end_layout
1581
1582 \begin_layout List
1583 \labelwidthstring 00.00.0000
1584 -
1585 \begin_inset ERT
1586 status collapsed
1587
1588 \begin_layout Standard
1589
1590
1591 \backslash
1592 /
1593 \end_layout
1594
1595 \end_inset
1596
1597 -disable-xa51-port Excludes the XA51 port
1598 \end_layout
1599
1600 \begin_layout List
1601 \labelwidthstring 00.00.0000
1602 -
1603 \begin_inset ERT
1604 status collapsed
1605
1606 \begin_layout Standard
1607
1608
1609 \backslash
1610 /
1611 \end_layout
1612
1613 \end_inset
1614
1615 -disable-ucsim Disables configuring and building of ucsim
1616 \end_layout
1617
1618 \begin_layout List
1619 \labelwidthstring 00.00.0000
1620 -
1621 \begin_inset ERT
1622 status collapsed
1623
1624 \begin_layout Standard
1625
1626
1627 \backslash
1628 /
1629 \end_layout
1630
1631 \end_inset
1632
1633 -disable-device-lib Disables automatically building device libraries
1634 \end_layout
1635
1636 \begin_layout List
1637 \labelwidthstring 00.00.0000
1638 -
1639 \begin_inset ERT
1640 status collapsed
1641
1642 \begin_layout Standard
1643
1644
1645 \backslash
1646 /
1647 \end_layout
1648
1649 \end_inset
1650
1651 -disable-packihx Disables building packihx
1652 \newline
1653
1654 \end_layout
1655
1656 \begin_layout List
1657 \labelwidthstring 00.00.0000
1658 -
1659 \begin_inset ERT
1660 status collapsed
1661
1662 \begin_layout Standard
1663
1664
1665 \backslash
1666 /
1667 \end_layout
1668
1669 \end_inset
1670
1671 -enable-doc Build pdf, html and txt files from the lyx sources
1672 \end_layout
1673
1674 \begin_layout List
1675 \labelwidthstring 00.00.0000
1676 -
1677 \begin_inset ERT
1678 status collapsed
1679
1680 \begin_layout Standard
1681
1682
1683 \backslash
1684 /
1685 \end_layout
1686
1687 \end_inset
1688
1689 -enable-libgc Use the Bohem memory allocator.
1690  Lower runtime footprint.
1691 \end_layout
1692
1693 \begin_layout Standard
1694 Furthermore the environment variables CC, CFLAGS, ...
1695  the tools and their arguments can be influenced.
1696  Please see `configure -
1697 \begin_inset ERT
1698 status collapsed
1699
1700 \begin_layout Standard
1701
1702
1703 \backslash
1704 /
1705 \end_layout
1706
1707 \end_inset
1708
1709 -help' and the man/info pages of `configure' for details.
1710 \newline
1711
1712 \newline
1713 The names of the
1714  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1715 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1716  SDCC_LIB_NAME are defined by `configure' too.
1717  At the moment it's not possible to change the default settings (it was
1718  simply never required).
1719 \newline
1720
1721 \newline
1722 These configure options are compiled into the binaries,
1723  and can only be changed by rerunning 'configure' and recompiling SDCC.
1724  The configure options are written in 
1725 \emph on
1726 italics
1727 \emph default
1728  to distinguish them from run time environment variables (see section search
1729  paths).
1730 \newline
1731
1732 \newline
1733 The settings for 
1734 \begin_inset Quotes sld
1735 \end_inset
1736
1737 Win32 builds
1738 \begin_inset Quotes srd
1739 \end_inset
1740
1741  are used by the SDCC team to build the official Win32 binaries.
1742  The SDCC team uses Mingw32 to build the official Windows binaries, because
1743  it's
1744 \end_layout
1745
1746 \begin_layout Enumerate
1747 open source, 
1748 \end_layout
1749
1750 \begin_layout Enumerate
1751 a gcc compiler and last but not least
1752 \end_layout
1753
1754 \begin_layout Enumerate
1755 the binaries can be built by cross compiling on SDCC Distributed Compile
1756  Farm.
1757 \end_layout
1758
1759 \begin_layout Standard
1760 See the examples, how to pass the Win32 settings to 'configure'.
1761  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1762  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1763  for Win32.
1764 \newline
1765
1766 \newline
1767 These defaults are:
1768 \newline
1769
1770 \end_layout
1771
1772 \begin_layout Standard
1773 \align center
1774 \begin_inset Tabular
1775 <lyxtabular version="3" rows="9" columns="3">
1776 <features>
1777 <column alignment="block" valignment="top" leftline="true" width="0in">
1778 <column alignment="block" valignment="top" leftline="true" width="0in">
1779 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1780 <row topline="true" bottomline="true">
1781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1782 \begin_inset Text
1783
1784 \begin_layout Standard
1785 Variable
1786 \end_layout
1787
1788 \end_inset
1789 </cell>
1790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1791 \begin_inset Text
1792
1793 \begin_layout Standard
1794 default
1795 \end_layout
1796
1797 \end_inset
1798 </cell>
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1800 \begin_inset Text
1801
1802 \begin_layout Standard
1803 Win32 builds
1804 \end_layout
1805
1806 \end_inset
1807 </cell>
1808 </row>
1809 <row topline="true">
1810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1811 \begin_inset Text
1812
1813 \begin_layout Standard
1814
1815 \emph on
1816 PREFIX
1817 \end_layout
1818
1819 \end_inset
1820 </cell>
1821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1822 \begin_inset Text
1823
1824 \begin_layout Standard
1825 /usr/local
1826 \end_layout
1827
1828 \end_inset
1829 </cell>
1830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1831 \begin_inset Text
1832
1833 \begin_layout Standard
1834
1835 \backslash
1836 sdcc
1837 \end_layout
1838
1839 \end_inset
1840 </cell>
1841 </row>
1842 <row topline="true">
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1844 \begin_inset Text
1845
1846 \begin_layout Standard
1847
1848 \emph on
1849 EXEC_PREFIX
1850 \end_layout
1851
1852 \end_inset
1853 </cell>
1854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1855 \begin_inset Text
1856
1857 \begin_layout Standard
1858
1859 \emph on
1860 $PREFIX
1861 \end_layout
1862
1863 \end_inset
1864 </cell>
1865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1866 \begin_inset Text
1867
1868 \begin_layout Standard
1869
1870 \emph on
1871 $PREFIX
1872 \end_layout
1873
1874 \end_inset
1875 </cell>
1876 </row>
1877 <row topline="true">
1878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1879 \begin_inset Text
1880
1881 \begin_layout Standard
1882
1883 \emph on
1884 BINDIR
1885 \end_layout
1886
1887 \end_inset
1888 </cell>
1889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1890 \begin_inset Text
1891
1892 \begin_layout Standard
1893
1894 \emph on
1895 $EXEC_PREFIX
1896 \emph default
1897 /bin
1898 \end_layout
1899
1900 \end_inset
1901 </cell>
1902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1903 \begin_inset Text
1904
1905 \begin_layout Standard
1906
1907 \emph on
1908 $EXEC_PREFIX
1909 \emph default
1910
1911 \backslash
1912 bin
1913 \end_layout
1914
1915 \end_inset
1916 </cell>
1917 </row>
1918 <row topline="true">
1919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1920 \begin_inset Text
1921
1922 \begin_layout Standard
1923
1924 \emph on
1925 DATADIR
1926 \end_layout
1927
1928 \end_inset
1929 </cell>
1930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1931 \begin_inset Text
1932
1933 \begin_layout Standard
1934
1935 \emph on
1936 $DATAROOTDIR
1937 \end_layout
1938
1939 \end_inset
1940 </cell>
1941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1942 \begin_inset Text
1943
1944 \begin_layout Standard
1945
1946 \emph on
1947 $DATAROOTDIR
1948 \end_layout
1949
1950 \end_inset
1951 </cell>
1952 </row>
1953 <row topline="true">
1954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1955 \begin_inset Text
1956
1957 \begin_layout Standard
1958
1959 \emph on
1960 DATAROOTDIR
1961 \end_layout
1962
1963 \end_inset
1964 </cell>
1965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1966 \begin_inset Text
1967
1968 \begin_layout Standard
1969
1970 \emph on
1971 $PREFIX
1972 \emph default
1973 /share
1974 \end_layout
1975
1976 \end_inset
1977 </cell>
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1979 \begin_inset Text
1980
1981 \begin_layout Standard
1982
1983 \emph on
1984 $PREFIX
1985 \end_layout
1986
1987 \end_inset
1988 </cell>
1989 </row>
1990 <row topline="true">
1991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1992 \begin_inset Text
1993
1994 \begin_layout Standard
1995
1996 \emph on
1997 DOCDIR
1998 \end_layout
1999
2000 \end_inset
2001 </cell>
2002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2003 \begin_inset Text
2004
2005 \begin_layout Standard
2006
2007 \emph on
2008 $DATAROOTDIR
2009 \emph default
2010 /sdcc/doc
2011 \end_layout
2012
2013 \end_inset
2014 </cell>
2015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2016 \begin_inset Text
2017
2018 \begin_layout Standard
2019
2020 \emph on
2021 $DATAROOTDIR
2022 \emph default
2023
2024 \backslash
2025 doc
2026 \end_layout
2027
2028 \end_inset
2029 </cell>
2030 </row>
2031 <row topline="true">
2032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2033 \begin_inset Text
2034
2035 \begin_layout Standard
2036
2037 \emph on
2038 INCLUDE_DIR_SUFFIX
2039 \end_layout
2040
2041 \end_inset
2042 </cell>
2043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2044 \begin_inset Text
2045
2046 \begin_layout Standard
2047 sdcc/include
2048 \end_layout
2049
2050 \end_inset
2051 </cell>
2052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2053 \begin_inset Text
2054
2055 \begin_layout Standard
2056 include
2057 \end_layout
2058
2059 \end_inset
2060 </cell>
2061 </row>
2062 <row topline="true" bottomline="true">
2063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2064 \begin_inset Text
2065
2066 \begin_layout Standard
2067
2068 \emph on
2069 LIB_DIR_SUFFIX
2070 \end_layout
2071
2072 \end_inset
2073 </cell>
2074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2075 \begin_inset Text
2076
2077 \begin_layout Standard
2078 sdcc/lib
2079 \end_layout
2080
2081 \end_inset
2082 </cell>
2083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2084 \begin_inset Text
2085
2086 \begin_layout Standard
2087 lib
2088 \end_layout
2089
2090 \end_inset
2091 </cell>
2092 </row>
2093 </lyxtabular>
2094
2095 \end_inset
2096
2097
2098 \newline
2099
2100 \end_layout
2101
2102 \begin_layout Standard
2103 \noindent
2104 'configure' also computes relative paths.
2105  This is needed for full relocatability of a binary package and to complete
2106  search paths (see section search paths below):
2107 \newline
2108  
2109 \end_layout
2110
2111 \begin_layout Standard
2112 \align center
2113 \begin_inset Tabular
2114 <lyxtabular version="3" rows="4" columns="3">
2115 <features>
2116 <column alignment="block" valignment="top" leftline="true" width="0in">
2117 <column alignment="block" valignment="top" leftline="true" width="0in">
2118 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2119 <row topline="true" bottomline="true">
2120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2121 \begin_inset Text
2122
2123 \begin_layout Standard
2124 Variable (computed)
2125 \end_layout
2126
2127 \end_inset
2128 </cell>
2129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2130 \begin_inset Text
2131
2132 \begin_layout Standard
2133 default
2134 \end_layout
2135
2136 \end_inset
2137 </cell>
2138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2139 \begin_inset Text
2140
2141 \begin_layout Standard
2142 Win32 builds
2143 \end_layout
2144
2145 \end_inset
2146 </cell>
2147 </row>
2148 <row topline="true" bottomline="true">
2149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2150 \begin_inset Text
2151
2152 \begin_layout Standard
2153
2154 \emph on
2155 BIN2DATA_DIR
2156 \end_layout
2157
2158 \end_inset
2159 </cell>
2160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2161 \begin_inset Text
2162
2163 \begin_layout Standard
2164 ../share
2165 \end_layout
2166
2167 \end_inset
2168 </cell>
2169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2170 \begin_inset Text
2171
2172 \begin_layout Standard
2173 ..
2174 \end_layout
2175
2176 \end_inset
2177 </cell>
2178 </row>
2179 <row bottomline="true">
2180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2181 \begin_inset Text
2182
2183 \begin_layout Standard
2184
2185 \emph on
2186 PREFIX2BIN_DIR
2187 \end_layout
2188
2189 \end_inset
2190 </cell>
2191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2192 \begin_inset Text
2193
2194 \begin_layout Standard
2195 bin
2196 \end_layout
2197
2198 \end_inset
2199 </cell>
2200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2201 \begin_inset Text
2202
2203 \begin_layout Standard
2204 bin
2205 \end_layout
2206
2207 \end_inset
2208 </cell>
2209 </row>
2210 <row bottomline="true">
2211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2212 \begin_inset Text
2213
2214 \begin_layout Standard
2215
2216 \emph on
2217 PREFIX2DATA_DIR
2218 \end_layout
2219
2220 \end_inset
2221 </cell>
2222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2223 \begin_inset Text
2224
2225 \begin_layout Standard
2226 share/sdcc
2227 \end_layout
2228
2229 \end_inset
2230 </cell>
2231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2232 \begin_inset Text
2233
2234 \begin_layout Standard
2235
2236 \end_layout
2237
2238 \end_inset
2239 </cell>
2240 </row>
2241 </lyxtabular>
2242
2243 \end_inset
2244
2245
2246 \newline
2247
2248 \end_layout
2249
2250 \begin_layout Standard
2251 \noindent
2252 Examples:
2253 \end_layout
2254
2255 \begin_layout LyX-Code
2256 ./configure
2257 \newline
2258 ./configure -
2259 \begin_inset ERT
2260 status collapsed
2261
2262 \begin_layout Standard
2263
2264
2265 \backslash
2266 /
2267 \end_layout
2268
2269 \end_inset
2270
2271 -prefix=
2272 \begin_inset Quotes srd
2273 \end_inset
2274
2275 /usr/bin
2276 \begin_inset Quotes srd
2277 \end_inset
2278
2279  -
2280 \begin_inset ERT
2281 status collapsed
2282
2283 \begin_layout Standard
2284
2285
2286 \backslash
2287 /
2288 \end_layout
2289
2290 \end_inset
2291
2292 -datarootdir=
2293 \begin_inset Quotes srd
2294 \end_inset
2295
2296 /usr/share
2297 \begin_inset Quotes srd
2298 \end_inset
2299
2300
2301 \newline
2302 ./configure -
2303 \begin_inset ERT
2304 status collapsed
2305
2306 \begin_layout Standard
2307
2308
2309 \backslash
2310 /
2311 \end_layout
2312
2313 \end_inset
2314
2315 -disable-avr-port -
2316 \begin_inset ERT
2317 status collapsed
2318
2319 \begin_layout Standard
2320
2321
2322 \backslash
2323 /
2324 \end_layout
2325
2326 \end_inset
2327
2328 -disable-xa51-port
2329 \end_layout
2330
2331 \begin_layout Standard
2332 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2333 32'):
2334 \end_layout
2335
2336 \begin_layout LyX-Code
2337 ./configure 
2338 \backslash
2339
2340 \newline
2341 CC=
2342 \begin_inset Quotes srd
2343 \end_inset
2344
2345 i586-mingw32msvc-gcc
2346 \begin_inset Quotes srd
2347 \end_inset
2348
2349  CXX=
2350 \begin_inset Quotes srd
2351 \end_inset
2352
2353 i586-mingw32msvc-g++
2354 \begin_inset Quotes srd
2355 \end_inset
2356
2357  
2358 \backslash
2359  
2360 \newline
2361 RANLIB=
2362 \begin_inset Quotes srd
2363 \end_inset
2364
2365 i586-mingw32msvc-ranlib
2366 \begin_inset Quotes srd
2367 \end_inset
2368
2369  
2370 \backslash
2371
2372 \newline
2373 STRIP=
2374 \begin_inset Quotes srd
2375 \end_inset
2376
2377 i586-mingw32msvc-strip
2378 \begin_inset Quotes srd
2379 \end_inset
2380
2381  
2382 \backslash
2383
2384 \newline
2385 -
2386 \begin_inset ERT
2387 status collapsed
2388
2389 \begin_layout Standard
2390
2391
2392 \backslash
2393 /
2394 \end_layout
2395
2396 \end_inset
2397
2398 -prefix=
2399 \begin_inset Quotes srd
2400 \end_inset
2401
2402 /sdcc
2403 \begin_inset Quotes srd
2404 \end_inset
2405
2406  
2407 \backslash
2408
2409 \newline
2410 -
2411 \begin_inset ERT
2412 status collapsed
2413
2414 \begin_layout Standard
2415
2416
2417 \backslash
2418 /
2419 \end_layout
2420
2421 \end_inset
2422
2423 -datarootdir=
2424 \begin_inset Quotes srd
2425 \end_inset
2426
2427 /sdcc
2428 \begin_inset Quotes srd
2429 \end_inset
2430
2431  
2432 \backslash
2433
2434 \newline
2435 docdir=
2436 \begin_inset Quotes srd
2437 \end_inset
2438
2439
2440 \backslash
2441 ${datarootdir}/doc
2442 \begin_inset Quotes srd
2443 \end_inset
2444
2445  
2446 \backslash
2447
2448 \newline
2449 include_dir_suffix=
2450 \begin_inset Quotes srd
2451 \end_inset
2452
2453 include
2454 \begin_inset Quotes srd
2455 \end_inset
2456
2457  
2458 \backslash
2459
2460 \newline
2461 lib_dir_suffix=
2462 \begin_inset Quotes srd
2463 \end_inset
2464
2465 lib
2466 \begin_inset Quotes srd
2467 \end_inset
2468
2469  
2470 \backslash
2471
2472 \newline
2473 sdccconf_h_dir_separator=
2474 \begin_inset Quotes srd
2475 \end_inset
2476
2477
2478 \backslash
2479
2480 \backslash
2481
2482 \backslash
2483
2484 \backslash
2485
2486 \begin_inset Quotes srd
2487 \end_inset
2488
2489  
2490 \backslash
2491
2492 \newline
2493 -
2494 \begin_inset ERT
2495 status collapsed
2496
2497 \begin_layout Standard
2498
2499
2500 \backslash
2501 /
2502 \end_layout
2503
2504 \end_inset
2505
2506 -disable-device-lib
2507 \backslash
2508
2509 \newline
2510 -
2511 \begin_inset ERT
2512 status collapsed
2513
2514 \begin_layout Standard
2515
2516
2517 \backslash
2518 /
2519 \end_layout
2520
2521 \end_inset
2522
2523 -host=i586-mingw32msvc
2524 \backslash
2525
2526 \newline
2527 -
2528 \begin_inset ERT
2529 status collapsed
2530
2531 \begin_layout Standard
2532
2533
2534 \backslash
2535 /
2536 \end_layout
2537
2538 \end_inset
2539
2540 -build=unknown-unknown-linux-gnu
2541 \end_layout
2542
2543 \begin_layout Standard
2544 To 
2545 \begin_inset Quotes sld
2546 \end_inset
2547
2548 cross
2549 \begin_inset Quotes srd
2550 \end_inset
2551
2552 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2553 ):
2554 \end_layout
2555
2556 \begin_layout LyX-Code
2557 ./configure -C 
2558 \backslash
2559
2560 \newline
2561 -
2562 \begin_inset ERT
2563 status collapsed
2564
2565 \begin_layout Standard
2566
2567
2568 \backslash
2569 /
2570 \end_layout
2571
2572 \end_inset
2573
2574 -prefix=
2575 \begin_inset Quotes srd
2576 \end_inset
2577
2578 /sdcc
2579 \begin_inset Quotes srd
2580 \end_inset
2581
2582  
2583 \backslash
2584
2585 \newline
2586 -
2587 \begin_inset ERT
2588 status collapsed
2589
2590 \begin_layout Standard
2591
2592
2593 \backslash
2594 /
2595 \end_layout
2596
2597 \end_inset
2598
2599 -datarootdir=
2600 \begin_inset Quotes srd
2601 \end_inset
2602
2603 /sdcc
2604 \begin_inset Quotes srd
2605 \end_inset
2606
2607  
2608 \backslash
2609
2610 \newline
2611 docdir=
2612 \begin_inset Quotes srd
2613 \end_inset
2614
2615
2616 \backslash
2617 ${datarootdir}/doc
2618 \begin_inset Quotes srd
2619 \end_inset
2620
2621  
2622 \backslash
2623  
2624 \newline
2625 include_dir_suffix=
2626 \begin_inset Quotes srd
2627 \end_inset
2628
2629 include
2630 \begin_inset Quotes srd
2631 \end_inset
2632
2633  
2634 \backslash
2635
2636 \newline
2637 lib_dir_suffix=
2638 \begin_inset Quotes srd
2639 \end_inset
2640
2641 lib
2642 \begin_inset Quotes srd
2643 \end_inset
2644
2645  
2646 \backslash
2647
2648 \newline
2649 sdccconf_h_dir_separator=
2650 \begin_inset Quotes srd
2651 \end_inset
2652
2653
2654 \backslash
2655
2656 \backslash
2657
2658 \backslash
2659
2660 \backslash
2661
2662 \begin_inset Quotes srd
2663 \end_inset
2664
2665  
2666 \backslash
2667
2668 \newline
2669 CC=
2670 \begin_inset Quotes srd
2671 \end_inset
2672
2673 gcc -mno-cygwin
2674 \begin_inset Quotes srd
2675 \end_inset
2676
2677  
2678 \backslash
2679
2680 \newline
2681 CXX=
2682 \begin_inset Quotes srd
2683 \end_inset
2684
2685 g++ -mno-cygwin
2686 \begin_inset Quotes srd
2687 \end_inset
2688
2689  
2690 \end_layout
2691
2692 \begin_layout Standard
2693 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2694  The option '-
2695 \begin_inset ERT
2696 status collapsed
2697
2698 \begin_layout Standard
2699
2700
2701 \backslash
2702 /
2703 \end_layout
2704
2705 \end_inset
2706
2707 -C' turns on caching, which gives a little bit extra speed.
2708  However if options are changed, it can be necessary to delete the config.cache
2709  file.
2710 \end_layout
2711
2712 \begin_layout Section
2713 Install paths
2714 \begin_inset LatexCommand \label{sub:Install-paths}
2715
2716 \end_inset
2717
2718
2719 \begin_inset LatexCommand \index{Install paths}
2720
2721 \end_inset
2722
2723
2724 \end_layout
2725
2726 \begin_layout Standard
2727 \begin_inset VSpace medskip
2728 \end_inset
2729
2730
2731 \end_layout
2732
2733 \begin_layout Standard
2734 \align center
2735 \begin_inset Tabular
2736 <lyxtabular version="3" rows="5" columns="4">
2737 <features>
2738 <column alignment="left" valignment="top" leftline="true" width="0">
2739 <column alignment="left" valignment="top" leftline="true" width="0">
2740 <column alignment="left" valignment="top" leftline="true" width="0">
2741 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2742 <row topline="true" bottomline="true">
2743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2744 \begin_inset Text
2745
2746 \begin_layout Standard
2747
2748 \series bold
2749 Description
2750 \end_layout
2751
2752 \end_inset
2753 </cell>
2754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2755 \begin_inset Text
2756
2757 \begin_layout Standard
2758
2759 \series bold
2760 Path
2761 \end_layout
2762
2763 \end_inset
2764 </cell>
2765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2766 \begin_inset Text
2767
2768 \begin_layout Standard
2769
2770 \series bold
2771 Default
2772 \end_layout
2773
2774 \end_inset
2775 </cell>
2776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2777 \begin_inset Text
2778
2779 \begin_layout Standard
2780
2781 \series bold
2782 Win32 builds
2783 \end_layout
2784
2785 \end_inset
2786 </cell>
2787 </row>
2788 <row topline="true">
2789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2790 \begin_inset Text
2791
2792 \begin_layout Standard
2793 Binary files*
2794 \end_layout
2795
2796 \end_inset
2797 </cell>
2798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2799 \begin_inset Text
2800
2801 \begin_layout Standard
2802
2803 \emph on
2804 $EXEC_PREFIX
2805 \end_layout
2806
2807 \end_inset
2808 </cell>
2809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2810 \begin_inset Text
2811
2812 \begin_layout Standard
2813 /usr/local/bin
2814 \end_layout
2815
2816 \end_inset
2817 </cell>
2818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2819 \begin_inset Text
2820
2821 \begin_layout Standard
2822
2823 \backslash
2824 sdcc
2825 \backslash
2826 bin
2827 \end_layout
2828
2829 \end_inset
2830 </cell>
2831 </row>
2832 <row topline="true">
2833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2834 \begin_inset Text
2835
2836 \begin_layout Standard
2837 Include files
2838 \end_layout
2839
2840 \end_inset
2841 </cell>
2842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2843 \begin_inset Text
2844
2845 \begin_layout Standard
2846
2847 \emph on
2848 $DATADIR/ $INCLUDE_DIR_SUFFIX
2849 \end_layout
2850
2851 \end_inset
2852 </cell>
2853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2854 \begin_inset Text
2855
2856 \begin_layout Standard
2857 /usr/local/share/sdcc/include
2858 \end_layout
2859
2860 \end_inset
2861 </cell>
2862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2863 \begin_inset Text
2864
2865 \begin_layout Standard
2866
2867 \backslash
2868 sdcc
2869 \backslash
2870 include
2871 \end_layout
2872
2873 \end_inset
2874 </cell>
2875 </row>
2876 <row topline="true">
2877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2878 \begin_inset Text
2879
2880 \begin_layout Standard
2881 Library file**
2882 \end_layout
2883
2884 \end_inset
2885 </cell>
2886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2887 \begin_inset Text
2888
2889 \begin_layout Standard
2890
2891 \emph on
2892 $DATADIR/$LIB_DIR_SUFFIX
2893 \end_layout
2894
2895 \end_inset
2896 </cell>
2897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2898 \begin_inset Text
2899
2900 \begin_layout Standard
2901 /usr/local/share/sdcc/lib
2902 \end_layout
2903
2904 \end_inset
2905 </cell>
2906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2907 \begin_inset Text
2908
2909 \begin_layout Standard
2910
2911 \backslash
2912 sdcc
2913 \backslash
2914 lib
2915 \end_layout
2916
2917 \end_inset
2918 </cell>
2919 </row>
2920 <row topline="true" bottomline="true">
2921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2922 \begin_inset Text
2923
2924 \begin_layout Standard
2925 Documentation
2926 \end_layout
2927
2928 \end_inset
2929 </cell>
2930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2931 \begin_inset Text
2932
2933 \begin_layout Standard
2934
2935 \emph on
2936 $DOCDIR
2937 \end_layout
2938
2939 \end_inset
2940 </cell>
2941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2942 \begin_inset Text
2943
2944 \begin_layout Standard
2945 /usr/local/share/sdcc/doc
2946 \end_layout
2947
2948 \end_inset
2949 </cell>
2950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2951 \begin_inset Text
2952
2953 \begin_layout Standard
2954
2955 \backslash
2956 sdcc
2957 \backslash
2958 doc
2959 \end_layout
2960
2961 \end_inset
2962 </cell>
2963 </row>
2964 </lyxtabular>
2965
2966 \end_inset
2967
2968
2969 \end_layout
2970
2971 \begin_layout Verse
2972
2973 \size footnotesize
2974 *compiler, preprocessor, assembler, and linker
2975 \newline
2976 **the 
2977 \shape italic
2978 model
2979 \shape default
2980  is auto-appended by the compiler, e.g.
2981  small, large, z80, ds390 etc
2982 \end_layout
2983
2984 \begin_layout Standard
2985 \noindent
2986 The install paths can still be changed during `make install' with e.g.:
2987 \end_layout
2988
2989 \begin_layout LyX-Code
2990 make install prefix=$(HOME)/local/sdcc
2991 \end_layout
2992
2993 \begin_layout Standard
2994 Of course this doesn't change the search paths compiled into the binaries.
2995 \newline
2996
2997 \newline
2998 Moreove
2999 r the install path can be changed by defining DESTDIR
3000 \begin_inset LatexCommand \index{DESTDIR}
3001
3002 \end_inset
3003
3004 :
3005 \end_layout
3006
3007 \begin_layout LyX-Code
3008 make install DESTDIR=$(HOME)/sdcc.rpm/
3009 \end_layout
3010
3011 \begin_layout Standard
3012 Please note that DESTDIR must have a trailing slash!
3013 \end_layout
3014
3015 \begin_layout Section
3016 Search Paths
3017 \begin_inset LatexCommand \label{sub:Search-Paths}
3018
3019 \end_inset
3020
3021
3022 \begin_inset LatexCommand \index{Search path}
3023
3024 \end_inset
3025
3026
3027 \end_layout
3028
3029 \begin_layout Standard
3030 Some search paths or parts of them are determined by configure variables
3031  (in 
3032 \emph on
3033 italics
3034 \emph default
3035 , see section above).
3036  Further search paths are determined by environment variables during runtime.
3037  
3038 \newline
3039 The paths searched when running the compiler are as follows (the first
3040  catch wins):
3041 \newline
3042
3043 \newline
3044 1.
3045  Binary files (preprocessor, assembler and linker)
3046 \newline
3047
3048 \end_layout
3049
3050 \begin_layout Standard
3051 \align center
3052 \begin_inset Tabular
3053 <lyxtabular version="3" rows="4" columns="3">
3054 <features>
3055 <column alignment="block" valignment="top" leftline="true" width="0in">
3056 <column alignment="block" valignment="top" leftline="true" width="0in">
3057 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3058 <row topline="true" bottomline="true">
3059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3060 \begin_inset Text
3061
3062 \begin_layout Standard
3063 Search path
3064 \end_layout
3065
3066 \end_inset
3067 </cell>
3068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3069 \begin_inset Text
3070
3071 \begin_layout Standard
3072 default
3073 \end_layout
3074
3075 \end_inset
3076 </cell>
3077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3078 \begin_inset Text
3079
3080 \begin_layout Standard
3081 Win32 builds
3082 \end_layout
3083
3084 \end_inset
3085 </cell>
3086 </row>
3087 <row topline="true">
3088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3089 \begin_inset Text
3090
3091 \begin_layout Standard
3092 $SDCC_HOME/
3093 \emph on
3094 $PPREFIX2BIN_DIR
3095 \end_layout
3096
3097 \end_inset
3098 </cell>
3099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3100 \begin_inset Text
3101
3102 \begin_layout Standard
3103 $SDCC_HOME/bin
3104 \end_layout
3105
3106 \end_inset
3107 </cell>
3108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3109 \begin_inset Text
3110
3111 \begin_layout Standard
3112 $SDCC_HOME
3113 \backslash
3114 bin
3115 \end_layout
3116
3117 \end_inset
3118 </cell>
3119 </row>
3120 <row topline="true">
3121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3122 \begin_inset Text
3123
3124 \begin_layout Standard
3125 Path of argv[0] (if available)
3126 \end_layout
3127
3128 \end_inset
3129 </cell>
3130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3131 \begin_inset Text
3132
3133 \begin_layout Standard
3134 Path of argv[0]
3135 \end_layout
3136
3137 \end_inset
3138 </cell>
3139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3140 \begin_inset Text
3141
3142 \begin_layout Standard
3143 Path of argv[0]
3144 \end_layout
3145
3146 \end_inset
3147 </cell>
3148 </row>
3149 <row topline="true" bottomline="true">
3150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3151 \begin_inset Text
3152
3153 \begin_layout Standard
3154 $PATH
3155 \end_layout
3156
3157 \end_inset
3158 </cell>
3159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3160 \begin_inset Text
3161
3162 \begin_layout Standard
3163 $PATH
3164 \end_layout
3165
3166 \end_inset
3167 </cell>
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3169 \begin_inset Text
3170
3171 \begin_layout Standard
3172 $PATH
3173 \end_layout
3174
3175 \end_inset
3176 </cell>
3177 </row>
3178 </lyxtabular>
3179
3180 \end_inset
3181
3182  
3183 \newline
3184
3185 \end_layout
3186
3187 \begin_layout Standard
3188 \noindent
3189 2.
3190  Include files
3191 \newline
3192
3193 \end_layout
3194
3195 \begin_layout Standard
3196 \align center
3197 \begin_inset Tabular
3198 <lyxtabular version="3" rows="6" columns="3">
3199 <features>
3200 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3201 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3202 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3203 <row topline="true" bottomline="true">
3204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3205 \begin_inset Text
3206
3207 \begin_layout Standard
3208 Search path
3209 \end_layout
3210
3211 \end_inset
3212 </cell>
3213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3214 \begin_inset Text
3215
3216 \begin_layout Standard
3217 default
3218 \end_layout
3219
3220 \end_inset
3221 </cell>
3222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3223 \begin_inset Text
3224
3225 \begin_layout Standard
3226 Win32 builds
3227 \end_layout
3228
3229 \end_inset
3230 </cell>
3231 </row>
3232 <row topline="true">
3233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3234 \begin_inset Text
3235
3236 \begin_layout Standard
3237 -
3238 \begin_inset ERT
3239 status collapsed
3240
3241 \begin_layout Standard
3242
3243
3244 \backslash
3245 /
3246 \end_layout
3247
3248 \end_inset
3249
3250 -I dir
3251 \end_layout
3252
3253 \end_inset
3254 </cell>
3255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3256 \begin_inset Text
3257
3258 \begin_layout Standard
3259 -
3260 \begin_inset ERT
3261 status collapsed
3262
3263 \begin_layout Standard
3264
3265
3266 \backslash
3267 /
3268 \end_layout
3269
3270 \end_inset
3271
3272 -I dir
3273 \end_layout
3274
3275 \end_inset
3276 </cell>
3277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3278 \begin_inset Text
3279
3280 \begin_layout Standard
3281 -
3282 \begin_inset ERT
3283 status collapsed
3284
3285 \begin_layout Standard
3286
3287
3288 \backslash
3289 /
3290 \end_layout
3291
3292 \end_inset
3293
3294 -I dir
3295 \end_layout
3296
3297 \end_inset
3298 </cell>
3299 </row>
3300 <row topline="true">
3301 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3302 \begin_inset Text
3303
3304 \begin_layout Standard
3305 $SDCC_INCLUDE
3306 \end_layout
3307
3308 \end_inset
3309 </cell>
3310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3311 \begin_inset Text
3312
3313 \begin_layout Standard
3314 $SDCC_INCLUDE
3315 \end_layout
3316
3317 \end_inset
3318 </cell>
3319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3320 \begin_inset Text
3321
3322 \begin_layout Standard
3323 $SDCC_INCLUDE
3324 \end_layout
3325
3326 \end_inset
3327 </cell>
3328 </row>
3329 <row topline="true">
3330 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3331 \begin_inset Text
3332
3333 \begin_layout Standard
3334 $SDCC_HOME/
3335 \newline
3336
3337 \emph on
3338 $PREFIX2DATA_DIR/
3339 \newline
3340 $INCLUDE_DIR_SUFFIX
3341 \end_layout
3342
3343 \end_inset
3344 </cell>
3345 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3346 \begin_inset Text
3347
3348 \begin_layout Standard
3349 $SDCC_ HOME/
3350 \newline
3351 share/sdcc/
3352 \newline
3353 include
3354 \end_layout
3355
3356 \end_inset
3357 </cell>
3358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3359 \begin_inset Text
3360
3361 \begin_layout Standard
3362 $SDCC_HOME
3363 \backslash
3364 include
3365 \end_layout
3366
3367 \end_inset
3368 </cell>
3369 </row>
3370 <row topline="true">
3371 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3372 \begin_inset Text
3373
3374 \begin_layout Standard
3375 path(argv[0])/
3376 \newline
3377
3378 \emph on
3379 $BIN2DATADIR/
3380 \emph default
3381
3382 \newline
3383
3384 \emph on
3385 $INCLUDE_DIR_SUFFIX
3386 \end_layout
3387
3388 \end_inset
3389 </cell>
3390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3391 \begin_inset Text
3392
3393 \begin_layout Standard
3394 path(argv[0])/
3395 \newline
3396 ../sdcc/include
3397 \newline
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 \InsetSpace ~
3429 \InsetSpace ~
3430 \InsetSpace ~
3431 \InsetSpace ~
3432 \InsetSpace ~
3433 \InsetSpace ~
3434 \InsetSpace ~
3435 \InsetSpace ~
3436
3437 \end_layout
3438
3439 \end_inset
3440 </cell>
3441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3442 \begin_inset Text
3443
3444 \begin_layout Standard
3445 path(argv[0])
3446 \backslash
3447 ..
3448 \backslash
3449 include
3450 \end_layout
3451
3452 \end_inset
3453 </cell>
3454 </row>
3455 <row topline="true" bottomline="true">
3456 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3457 \begin_inset Text
3458
3459 \begin_layout Standard
3460
3461 \emph on
3462 $DATADIR/
3463 \emph default
3464
3465 \newline
3466
3467 \emph on
3468 $INCLUDE_DIR_SUFFIX
3469 \end_layout
3470
3471 \end_inset
3472 </cell>
3473 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3474 \begin_inset Text
3475
3476 \begin_layout Standard
3477 /usr/local/share/sdcc/
3478 \newline
3479 include
3480 \end_layout
3481
3482 \end_inset
3483 </cell>
3484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3485 \begin_inset Text
3486
3487 \begin_layout Standard
3488 (not on Win32)
3489 \end_layout
3490
3491 \end_inset
3492 </cell>
3493 </row>
3494 </lyxtabular>
3495
3496 \end_inset
3497
3498  
3499 \newline
3500
3501 \end_layout
3502
3503 \begin_layout Standard
3504 \noindent
3505 The option -
3506 \begin_inset ERT
3507 status collapsed
3508
3509 \begin_layout Standard
3510
3511
3512 \backslash
3513 /
3514 \end_layout
3515
3516 \end_inset
3517
3518 -nostdinc disables the last two search paths.
3519 \newline
3520
3521 \newline
3522 3.
3523  Library files 
3524 \newline
3525
3526 \end_layout
3527
3528 \begin_layout Standard
3529 With the exception of 
3530 \begin_inset Quotes sld
3531 \end_inset
3532
3533 -
3534 \begin_inset ERT
3535 status collapsed
3536
3537 \begin_layout Standard
3538
3539
3540 \backslash
3541 /
3542 \end_layout
3543
3544 \end_inset
3545
3546 -L dir
3547 \begin_inset Quotes srd
3548 \end_inset
3549
3550  the 
3551 \shape italic
3552 model
3553 \shape default
3554  is auto-appended by the compiler (e.g.
3555  small, large, z80, ds390 etc.).
3556  
3557 \newline
3558
3559 \end_layout
3560
3561 \begin_layout Standard
3562 \align center
3563 \begin_inset Tabular
3564 <lyxtabular version="3" rows="6" columns="3">
3565 <features>
3566 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3567 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3568 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3569 <row topline="true" bottomline="true">
3570 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3571 \begin_inset Text
3572
3573 \begin_layout Standard
3574 Search path
3575 \end_layout
3576
3577 \end_inset
3578 </cell>
3579 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3580 \begin_inset Text
3581
3582 \begin_layout Standard
3583 default
3584 \end_layout
3585
3586 \end_inset
3587 </cell>
3588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3589 \begin_inset Text
3590
3591 \begin_layout Standard
3592 Win32 builds
3593 \end_layout
3594
3595 \end_inset
3596 </cell>
3597 </row>
3598 <row topline="true">
3599 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3600 \begin_inset Text
3601
3602 \begin_layout Standard
3603 -
3604 \begin_inset ERT
3605 status collapsed
3606
3607 \begin_layout Standard
3608
3609
3610 \backslash
3611 /
3612 \end_layout
3613
3614 \end_inset
3615
3616 -L dir
3617 \end_layout
3618
3619 \end_inset
3620 </cell>
3621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3622 \begin_inset Text
3623
3624 \begin_layout Standard
3625 -
3626 \begin_inset ERT
3627 status collapsed
3628
3629 \begin_layout Standard
3630
3631
3632 \backslash
3633 /
3634 \end_layout
3635
3636 \end_inset
3637
3638 -L dir
3639 \end_layout
3640
3641 \end_inset
3642 </cell>
3643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3644 \begin_inset Text
3645
3646 \begin_layout Standard
3647 -
3648 \begin_inset ERT
3649 status collapsed
3650
3651 \begin_layout Standard
3652
3653
3654 \backslash
3655 /
3656 \end_layout
3657
3658 \end_inset
3659
3660 -L dir
3661 \end_layout
3662
3663 \end_inset
3664 </cell>
3665 </row>
3666 <row topline="true">
3667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3668 \begin_inset Text
3669
3670 \begin_layout Standard
3671 $SDCC_LIB/
3672 \newline
3673
3674 \emph on
3675 <model>
3676 \end_layout
3677
3678 \end_inset
3679 </cell>
3680 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3681 \begin_inset Text
3682
3683 \begin_layout Standard
3684 $SDCC_LIB/
3685 \newline
3686
3687 \emph on
3688 <model>
3689 \end_layout
3690
3691 \end_inset
3692 </cell>
3693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3694 \begin_inset Text
3695
3696 \begin_layout Standard
3697 $SDCC_LIB
3698 \backslash
3699
3700 \newline
3701
3702 \emph on
3703 <model>
3704 \end_layout
3705
3706 \end_inset
3707 </cell>
3708 </row>
3709 <row topline="true">
3710 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3711 \begin_inset Text
3712
3713 \begin_layout Standard
3714 $SDCC_HOME/
3715 \newline
3716
3717 \emph on
3718 $PREFIX2DATA_DIR/
3719 \newline
3720 $LIB_DIR_SUFFIX/<model>
3721 \end_layout
3722
3723 \end_inset
3724 </cell>
3725 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3726 \begin_inset Text
3727
3728 \begin_layout Standard
3729 $SDCC_HOME/
3730 \newline
3731 share/sdcc/
3732 \newline
3733 lib/
3734 \emph on
3735 <model>
3736 \end_layout
3737
3738 \end_inset
3739 </cell>
3740 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3741 \begin_inset Text
3742
3743 \begin_layout Standard
3744 $SDCC_HOME
3745 \backslash
3746 lib
3747 \backslash
3748
3749 \emph on
3750
3751 \newline
3752 <model>
3753 \end_layout
3754
3755 \end_inset
3756 </cell>
3757 </row>
3758 <row topline="true">
3759 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3760 \begin_inset Text
3761
3762 \begin_layout Standard
3763 path(argv[0])/
3764 \newline
3765
3766 \emph on
3767 $BIN2DATADIR/
3768 \emph default
3769
3770 \newline
3771
3772 \emph on
3773 $LIB_DIR_SUFFIX/<model>
3774 \end_layout
3775
3776 \end_inset
3777 </cell>
3778 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3779 \begin_inset Text
3780
3781 \begin_layout Standard
3782 path(argv[0])/
3783 \newline
3784 ../sdcc/lib/
3785 \emph on
3786 <model>
3787 \newline
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 \InsetSpace ~
3820 \InsetSpace ~
3821 \InsetSpace ~
3822 \InsetSpace ~
3823 \InsetSpace ~
3824 \InsetSpace ~
3825 \InsetSpace ~
3826 \InsetSpace ~
3827
3828 \end_layout
3829
3830 \end_inset
3831 </cell>
3832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3833 \begin_inset Text
3834
3835 \begin_layout Standard
3836 path(argv[0])
3837 \backslash
3838
3839 \newline
3840 ..
3841 \backslash
3842 lib
3843 \backslash
3844
3845 \emph on
3846 <model>
3847 \newline
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 \InsetSpace ~
3876 \InsetSpace ~
3877 \InsetSpace ~
3878 \InsetSpace ~
3879 \InsetSpace ~
3880 \InsetSpace ~
3881 \InsetSpace ~
3882 \InsetSpace ~
3883
3884 \end_layout
3885
3886 \end_inset
3887 </cell>
3888 </row>
3889 <row topline="true" bottomline="true">
3890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3891 \begin_inset Text
3892
3893 \begin_layout Standard
3894
3895 \emph on
3896 $DATADIR/
3897 \newline
3898 $LIB_DIR_SUFFIX/<model>
3899 \end_layout
3900
3901 \end_inset
3902 </cell>
3903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3904 \begin_inset Text
3905
3906 \begin_layout Standard
3907 /usr/local/share/sdcc/
3908 \newline
3909 lib/
3910 \emph on
3911 <model>
3912 \end_layout
3913
3914 \end_inset
3915 </cell>
3916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3917 \begin_inset Text
3918
3919 \begin_layout Standard
3920 (not on Win32)
3921 \end_layout
3922
3923 \end_inset
3924 </cell>
3925 </row>
3926 </lyxtabular>
3927
3928 \end_inset
3929
3930
3931 \newline
3932
3933 \end_layout
3934
3935 \begin_layout Standard
3936 \begin_inset Note Note
3937 status collapsed
3938
3939 \begin_layout Standard
3940 Don't delete any of the stray spaces in the table above without checking
3941  the HTML output (last line)!
3942 \end_layout
3943
3944 \end_inset
3945
3946
3947 \end_layout
3948
3949 \begin_layout Standard
3950 \InsetSpace ~
3951
3952 \newline
3953 The option -
3954 \begin_inset ERT
3955 status collapsed
3956
3957 \begin_layout Standard
3958
3959
3960 \backslash
3961 /
3962 \end_layout
3963
3964 \end_inset
3965
3966 -nostdlib disables the last two search paths.
3967 \end_layout
3968
3969 \begin_layout Section
3970 Building SDCC
3971 \begin_inset LatexCommand \index{Building SDCC}
3972
3973 \end_inset
3974
3975
3976 \end_layout
3977
3978 \begin_layout Subsection
3979 Building SDCC on Linux
3980 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3981
3982 \end_inset
3983
3984
3985 \end_layout
3986
3987 \begin_layout Enumerate
3988
3989 \series medium
3990 Download the source package
3991 \series default
3992  either from the SDCC Subversion repository or from snapshot builds
3993 \series medium
3994 , it will be named something like sdcc
3995 \series default
3996 -src
3997 \series medium
3998 -yyyymmdd-rrrr.t
3999 \series default
4000 ar.
4001 \series medium
4002 bz2
4003 \series default
4004  
4005 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
4006
4007 \end_inset
4008
4009 .
4010 \end_layout
4011
4012 \begin_layout Enumerate
4013
4014 \series medium
4015 Bring up a command line terminal, such as xterm.
4016 \end_layout
4017
4018 \begin_layout Enumerate
4019
4020 \series medium
4021 Unpack the file using a command like: 
4022 \family sans
4023 \series bold
4024 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4025 \begin_inset Quotes srd
4026 \end_inset
4027
4028
4029 \family default
4030 \series medium
4031 , this will create a sub-directory called sdcc with all of the sources.
4032 \end_layout
4033
4034 \begin_layout Enumerate
4035 Change directory into the main SDCC directory, for example type: 
4036 \family sans
4037 \series bold
4038 "cd sdcc
4039 \series default
4040 ".
4041 \end_layout
4042
4043 \begin_layout Enumerate
4044
4045 \series medium
4046 Type 
4047 \family sans
4048 \series bold
4049 "./configure
4050 \family default
4051 \series default
4052 ".
4053  This configures the package for compilation on your system.
4054 \end_layout
4055
4056 \begin_layout Enumerate
4057
4058 \series medium
4059 Type 
4060 \family sans
4061 \series bold
4062 "make
4063 \family default
4064 \series default
4065 "
4066 \series medium
4067 .
4068
4069 \series default
4070  All of the source packages will compile, this can take a while.
4071 \end_layout
4072
4073 \begin_layout Enumerate
4074
4075 \series medium
4076 Type 
4077 \family sans
4078 \series bold
4079 "make install"
4080 \family default
4081 \series default
4082  as root
4083 \series medium
4084 .
4085
4086 \series default
4087  This copies the binary executables, the include files, the libraries and
4088  the documentation to the install directories.
4089  Proceed with section 
4090 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4091
4092 \end_inset
4093
4094 .
4095 \end_layout
4096
4097 \begin_layout Subsection
4098 Building SDCC on Mac OS X
4099 \end_layout
4100
4101 \begin_layout Standard
4102 Follow the instruction for Linux.
4103 \newline
4104
4105 \newline
4106 On Mac OS X 10.2.x it was reported, that the
4107  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4108  Fortunately there's also gcc 2.9.x installed, which works fine.
4109  This compiler can be selected by running 'configure' with:
4110 \end_layout
4111
4112 \begin_layout LyX-Code
4113 ./configure CC=gcc2 CXX=g++2
4114 \end_layout
4115
4116 \begin_layout Standard
4117 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4118  Xcode.
4119  Run 'configure' with:
4120 \end_layout
4121
4122 \begin_layout LyX-Code
4123 ./configure 
4124 \backslash
4125
4126 \end_layout
4127
4128 \begin_layout LyX-Code
4129 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4130  ppc" 
4131 \backslash
4132
4133 \end_layout
4134
4135 \begin_layout LyX-Code
4136 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4137  ppc" 
4138 \backslash
4139
4140 \end_layout
4141
4142 \begin_layout LyX-Code
4143 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4144 \end_layout
4145
4146 \begin_layout Subsection
4147 Cross compiling SDCC on Linux for Windows
4148 \end_layout
4149
4150 \begin_layout Standard
4151 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4152  See section 'Configure Options'.
4153 \end_layout
4154
4155 \begin_layout Subsection
4156 Building SDCC using Cygwin and Mingw32
4157 \end_layout
4158
4159 \begin_layout Standard
4160 For building and installing a Cygwin executable follow the instructions
4161  for Linux.
4162 \newline
4163
4164 \newline
4165 On Cygwin a 
4166 \begin_inset Quotes sld
4167 \end_inset
4168
4169 native
4170 \begin_inset Quotes srd
4171 \end_inset
4172
4173  Win32-binary can be built, which will not need the Cygwin-DLL.
4174  For the necessary 'configure' options see section 'configure options' or
4175  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4176 \newline
4177
4178 \newline
4179 In order to install
4180  Cygwin on Windows download setup.exe from 
4181 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4182
4183 \end_inset
4184
4185 .
4186  Run it, set the 
4187 \begin_inset Quotes sld
4188 \end_inset
4189
4190 default text file type
4191 \begin_inset Quotes srd
4192 \end_inset
4193
4194  to 
4195 \begin_inset Quotes sld
4196 \end_inset
4197
4198 unix
4199 \begin_inset Quotes srd
4200 \end_inset
4201
4202  and download/install at least the following packages.
4203  Some packages are selected by default, others will be automatically selected
4204  because of dependencies with the manually selected packages.
4205  Never deselect these packages!
4206 \end_layout
4207
4208 \begin_layout Itemize
4209 flex
4210 \end_layout
4211
4212 \begin_layout Itemize
4213 bison
4214 \end_layout
4215
4216 \begin_layout Itemize
4217 gcc ; version 3.x is fine, no need to use the old 2.9x
4218 \end_layout
4219
4220 \begin_layout Itemize
4221 binutils ; selected with gcc
4222 \end_layout
4223
4224 \begin_layout Itemize
4225 make
4226 \end_layout
4227
4228 \begin_layout Itemize
4229 rxvt ; a nice console, which makes life much easier under windoze (see below)
4230 \end_layout
4231
4232 \begin_layout Itemize
4233 man ; not really needed for building SDCC, but you'll miss it sooner or
4234  later
4235 \end_layout
4236
4237 \begin_layout Itemize
4238 less ; not really needed for building SDCC, but you'll miss it sooner or
4239  later
4240 \end_layout
4241
4242 \begin_layout Itemize
4243 svn ; only if you use Subversion access
4244 \end_layout
4245
4246 \begin_layout Standard
4247 If you want to develop something you'll need:
4248 \end_layout
4249
4250 \begin_layout Itemize
4251 python ; for the regression tests
4252 \end_layout
4253
4254 \begin_layout Itemize
4255 gdb ; the gnu debugger, together with the nice GUI 
4256 \begin_inset Quotes sld
4257 \end_inset
4258
4259 insight
4260 \begin_inset Quotes srd
4261 \end_inset
4262
4263
4264 \end_layout
4265
4266 \begin_layout Itemize
4267 openssh ; to access the CF or commit changes
4268 \end_layout
4269
4270 \begin_layout Itemize
4271 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4272  use autoconf-stable!
4273 \end_layout
4274
4275 \begin_layout Standard
4276 rxvt is a nice console with history.
4277  Replace in your cygwin.bat the line
4278 \end_layout
4279
4280 \begin_layout LyX-Code
4281 bash -
4282 \begin_inset ERT
4283 status collapsed
4284
4285 \begin_layout Standard
4286
4287
4288 \backslash
4289 /
4290 \end_layout
4291
4292 \end_inset
4293
4294 -login -i 
4295 \end_layout
4296
4297 \begin_layout Standard
4298 with (one line):
4299 \end_layout
4300
4301 \begin_layout LyX-Code
4302 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4303 \end_layout
4304
4305 \begin_layout LyX-Code
4306      -bg black -fg white -geometry 100x65 -e bash -
4307 \begin_inset ERT
4308 status collapsed
4309
4310 \begin_layout Standard
4311
4312
4313 \backslash
4314 /
4315 \end_layout
4316
4317 \end_inset
4318
4319 -login
4320 \end_layout
4321
4322 \begin_layout Standard
4323 Text selected with the mouse is automatically copied to the clipboard, pasting
4324  works with shift-insert.
4325 \newline
4326
4327 \newline
4328 The other good tip is to make sure you have no //c/-styl
4329 e paths anywhere, use /cygdrive/c/ instead.
4330  Using // invokes a network lookup which is very slow.
4331  If you think 
4332 \begin_inset Quotes sld
4333 \end_inset
4334
4335 cygdrive
4336 \begin_inset Quotes srd
4337 \end_inset
4338
4339  is too long, you can change it with e.g.
4340 \end_layout
4341
4342 \begin_layout LyX-Code
4343 mount -s -u -c /mnt
4344 \end_layout
4345
4346 \begin_layout Standard
4347 SDCC sources use the unix line ending LF.
4348  Life is much easier, if you store the source tree on a drive which is mounted
4349  in binary mode.
4350  And use an editor which can handle LF-only line endings.
4351  Make sure not to commit files with windows line endings.
4352  The tabulator spacing
4353 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4354
4355 \end_inset
4356
4357  used in the project is 8.
4358  Although a tabulator spacing of 8 is a sensible choice for programmers
4359  (it's a power of 2 and allows to display 8/16 bit signed variables without
4360  loosing columns) the plan is to move towards using only spaces in the source.
4361 \end_layout
4362
4363 \begin_layout Subsection
4364 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4365 \end_layout
4366
4367 \begin_layout Standard
4368
4369 \series medium
4370 Download the source package
4371 \series default
4372  either from the SDCC Subversion repository or from the 
4373 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4374
4375 \end_inset
4376
4377
4378 \series medium
4379 , it will be named something like sdcc
4380 \series default
4381 -src
4382 \series medium
4383 -yyyymmdd-rrrr.tar.bz2.
4384
4385 \series default
4386  SDCC is distributed with all the projects, workspaces, and files you need
4387  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4388  The workspace name is 'sdcc.dsw'.
4389  Please note that as it is now, all the executables are created in a folder
4390  called sdcc
4391 \backslash
4392 bin_vc.
4393  Once built you need to copy the executables from sdcc
4394 \backslash
4395 bin_vc to sdcc
4396 \backslash
4397 bin before running SDCC.
4398  
4399 \newline
4400
4401 \newline
4402 WARNING: Visual studio is very picky with line terminations; it expects
4403  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4404  When using the Subversion repository it's easiest to configure the svn
4405  client to convert automatically for you.
4406  If however you are getting a message such as "This makefile was not generated
4407  by Developer Studio etc.
4408  etc.
4409 \begin_inset Quotes srd
4410 \end_inset
4411
4412  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4413  need to convert the Unix style line endings to DOS style line endings.
4414  To do so you can use the 
4415 \begin_inset Quotes sld
4416 \end_inset
4417
4418 unix2dos
4419 \begin_inset Quotes srd
4420 \end_inset
4421
4422  utility freely available on the internet.
4423  Doug Hawkins reported in the sdcc-user list that this works:
4424 \newline
4425
4426 \newline
4427 C:
4428 \backslash
4429 Programming
4430 \backslash
4431 SDCC> unix2dos sdcc.dsw
4432 \newline
4433 C:
4434 \backslash
4435 Programming
4436 \backslash
4437 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4438 \newline
4439
4440 \newline
4441 In order to build SDCC with MSVC
4442  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4443  One good place to get them is 
4444 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4445
4446 \end_inset
4447
4448
4449 \newline
4450
4451 \newline
4452 Download the file UnxUtils
4453 \begin_inset LatexCommand \index{UnxUtils}
4454
4455 \end_inset
4456
4457 .zip.
4458  Now you have to install the utilities and setup MSVC so it can locate the
4459  required programs.
4460  Here there are two alternatives (choose one!):
4461 \end_layout
4462
4463 \begin_layout Enumerate
4464 The easy way:
4465 \newline
4466
4467 \newline
4468 a) Extract UnxUtils.zip to your C:
4469 \backslash
4470  hard disk PRESERVING the original paths, otherwise bison won't work.
4471  (If you are using WinZip make certain that 'Use folder names' is selected)
4472 \newline
4473
4474 \newline
4475 b)
4476  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4477  'Show directories for:' select 'Executable files', and in the directories
4478  window add a new path: 'C:
4479 \backslash
4480 user
4481 \backslash
4482 local
4483 \backslash
4484 wbin', click ok.
4485 \newline
4486
4487 \newline
4488 (As a side effect, you get a bunch of Unix utilities that
4489  could be useful, such as diff and patch.)
4490 \end_layout
4491
4492 \begin_layout Enumerate
4493 A more compact way:
4494 \newline
4495
4496 \newline
4497 This one avoids extracting a bunch of files you may not
4498  use, but requires some extra work:
4499 \newline
4500
4501 \newline
4502 a) Create a directory were to put the
4503  tools needed, or use a directory already present.
4504  Say for example 'C:
4505 \backslash
4506 util'.
4507 \newline
4508
4509 \newline
4510 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4511  gawk.exe to such directory WITHOUT preserving the original paths.
4512  (If you are using WinZip make certain that 'Use folder names' is not selected)
4513 \newline
4514
4515 \newline
4516 c
4517 ) Rename bison.exe to '_bison.exe'.
4518 \newline
4519
4520 \newline
4521 d) Create a batch file 'bison.bat' in 'C:
4522 \backslash
4523 util
4524 \backslash
4525 ' and add these lines: 
4526 \newline
4527 \InsetSpace ~
4528 \InsetSpace ~
4529 set BISON_SIMPLE=C:
4530 \backslash
4531 util
4532 \backslash
4533 bison.simple 
4534 \newline
4535 \InsetSpace ~
4536 \InsetSpace ~
4537 set BISON_HAIRY=C:
4538 \backslash
4539 util
4540 \backslash
4541 bison.hairy
4542 \newline
4543 \InsetSpace ~
4544 \InsetSpace ~
4545 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4546 \newline
4547
4548 \newline
4549 Steps 'c' and 'd' are needed
4550  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4551  reside in some weird Unix directory, '/usr/local/share/' I think.
4552  So it is necessary to tell bison where those files are located if they
4553  are not in such directory.
4554  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4555 \newline
4556
4557 \newline
4558 e
4559 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4560  in 'Show directories for:' select 'Executable files', and in the directories
4561  window add a new path: 'c:
4562 \backslash
4563 util', click ok.
4564  Note that you can use any other path instead of 'c:
4565 \backslash
4566 util', even the path where the Visual C++ tools are, probably: 'C:
4567 \backslash
4568 Program Files
4569 \backslash
4570 Microsoft Visual Studio
4571 \backslash
4572 Common
4573 \backslash
4574 Tools'.
4575  So you don't have to execute step 'e' :)
4576 \end_layout
4577
4578 \begin_layout Standard
4579 That is it.
4580  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4581  the executables from sdcc
4582 \backslash
4583 bin_vc to sdcc
4584 \backslash
4585 bin, and you can compile using SDCC.
4586 \end_layout
4587
4588 \begin_layout Subsection
4589 Building SDCC Using Borland
4590 \end_layout
4591
4592 \begin_layout Enumerate
4593 From the sdcc directory, run the command "make -f Makefile.bcc".
4594  This should regenerate all the .exe files in the bin directory except for
4595  SDCDB and ucSim.
4596 \end_layout
4597
4598 \begin_layout Enumerate
4599 If you modify any source files and need to rebuild, be aware that the dependenci
4600 es may not be correctly calculated.
4601  The safest option is to delete all .obj files and run the build again.
4602  From a Cygwin BASH prompt, this can easily be done with the command (be
4603  sure you are in the sdcc directory):
4604 \newline
4605
4606 \newline
4607
4608 \family sans
4609 \series bold
4610 find .
4611  
4612 \backslash
4613 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4614 \backslash
4615 ) -print -exec rm {} 
4616 \backslash
4617 ;
4618 \family default
4619 \series default
4620
4621 \newline
4622
4623 \newline
4624 or on Windows NT/2000/XP from the command prompt with the command:
4625 \newline
4626
4627 \family sans
4628 \series bold
4629
4630 \newline
4631 del /s *.obj *.lib *.rul
4632 \family default
4633 \series default
4634  from the sdcc directory.
4635 \end_layout
4636
4637 \begin_layout Subsection
4638 Windows Install Using a ZIP Package
4639 \end_layout
4640
4641 \begin_layout Enumerate
4642 Download the binary zip package from 
4643 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4644
4645 \end_inset
4646
4647  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4648  This should unpack to a group of sub-directories.
4649  An example directory structure after unpacking the mingw32 package is:
4650  c:
4651 \backslash
4652 sdcc
4653 \backslash
4654 bin for the executables, c:
4655 \backslash
4656 sdcc
4657 \backslash
4658 include and c:
4659 \backslash
4660 sdcc
4661 \backslash
4662 lib for the include and libraries.
4663 \end_layout
4664
4665 \begin_layout Enumerate
4666 Adjust your environment variable PATH to include the location of the bin
4667  directory or start sdcc using the full path.
4668 \end_layout
4669
4670 \begin_layout Subsection
4671 Windows Install Using the Setup Program
4672 \begin_inset LatexCommand \label{sub:Windows-Install}
4673
4674 \end_inset
4675
4676
4677 \end_layout
4678
4679 \begin_layout Standard
4680 Download the setup program 
4681 \emph on
4682 sdcc-x.y.z-setup.exe
4683 \emph default
4684  for an official release from 
4685 \newline
4686
4687 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4688
4689 \end_inset
4690
4691  or a setup program for one of the snapshots 
4692 \emph on
4693 sdcc-yyyymmdd-xxxx-setup.exe
4694 \emph default
4695  from 
4696 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4697
4698 \end_inset
4699
4700  and execute it.
4701  A windows typical installer will guide you through the installation process.
4702 \end_layout
4703
4704 \begin_layout Subsection
4705 VPATH
4706 \begin_inset LatexCommand \index{VPATH}
4707
4708 \end_inset
4709
4710  feature
4711 \end_layout
4712
4713 \begin_layout Standard
4714 SDCC supports the VPATH feature provided by configure and make.
4715  It allows to separate the source and build trees.
4716  Here's an example:
4717 \end_layout
4718
4719 \begin_layout Standard
4720
4721 \family typewriter
4722 cd ~\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 \InsetSpace ~
4736 \InsetSpace ~
4737 \InsetSpace ~
4738 \InsetSpace ~
4739 \InsetSpace ~
4740 \InsetSpace ~
4741 \InsetSpace ~
4742 \InsetSpace ~
4743 # cd $HOME
4744 \end_layout
4745
4746 \begin_layout Standard
4747
4748 \family typewriter
4749 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4750 # extract source to directory sdcc
4751 \end_layout
4752
4753 \begin_layout Standard
4754
4755 \family typewriter
4756 mkdir sdcc.build\InsetSpace ~
4757 \InsetSpace ~
4758 \InsetSpace ~
4759 \InsetSpace ~
4760 \InsetSpace ~
4761 \InsetSpace ~
4762 \InsetSpace ~
4763 \InsetSpace ~
4764 \InsetSpace ~
4765 # put output in sdcc.build
4766 \end_layout
4767
4768 \begin_layout Standard
4769
4770 \family typewriter
4771 cd sdcc.build
4772 \end_layout
4773
4774 \begin_layout Standard
4775
4776 \family typewriter
4777 ../sdcc/configure\InsetSpace ~
4778 \InsetSpace ~
4779 \InsetSpace ~
4780 \InsetSpace ~
4781 \InsetSpace ~
4782 \InsetSpace ~
4783 \InsetSpace ~
4784 \InsetSpace ~
4785 # configure is doing all the magic!
4786 \end_layout
4787
4788 \begin_layout Standard
4789
4790 \family typewriter
4791 make
4792 \end_layout
4793
4794 \begin_layout Standard
4795 \noindent
4796 That's it! 
4797 \series bold
4798 configure
4799 \series default
4800  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4801  It automagically computes the variables srcdir, top_srcdir and top_buildir
4802  for each directory.
4803  After running 
4804 \series bold
4805 make
4806 \series default
4807  the generated files will be in ~/sdcc.build, while the source files stay
4808  in ~/sdcc.
4809 \newline
4810 This is not only usefull for building different binaries, e.g.
4811  when cross compiling.
4812  It also gives you a much better overview in the source tree when all the
4813  generated files are not scattered between the source files.
4814  And the best thing is: if you want to change a file you can leave the original
4815  file untouched in the source directory.
4816  Simply copy it to the build directory, edit it, enter `make clean', `rm
4817  Makefile.dep' and `make'.
4818  
4819 \series bold
4820 make
4821 \series default
4822  will do the rest for you!
4823 \end_layout
4824
4825 \begin_layout Section
4826 Building the Documentation
4827 \end_layout
4828
4829 \begin_layout Standard
4830 Add -
4831 \begin_inset ERT
4832 status collapsed
4833
4834 \begin_layout Standard
4835
4836
4837 \backslash
4838 /
4839 \end_layout
4840
4841 \end_inset
4842
4843 -enable-doc to the configure arguments to build the documentation together
4844  with all the other stuff.
4845  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4846  dvips and makeindex) to get the job done.
4847  Another possibility is to change to the doc directory and to type 
4848 \family sans
4849 \series bold
4850
4851 \begin_inset Quotes srd
4852 \end_inset
4853
4854 make
4855 \begin_inset Quotes srd
4856 \end_inset
4857
4858
4859 \family default
4860 \series default
4861  there.
4862  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4863 x).
4864  Using LyX 
4865 \begin_inset LatexCommand \url{http://www.lyx.org}
4866
4867 \end_inset
4868
4869  as editor is straightforward.
4870  Prebuilt documentation in html and pdf format is available from 
4871 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4872
4873 \end_inset
4874
4875 .
4876 \end_layout
4877
4878 \begin_layout Section
4879 Reading the Documentation
4880 \begin_inset LatexCommand \index{Documentation}
4881
4882 \end_inset
4883
4884
4885 \end_layout
4886
4887 \begin_layout Standard
4888 Currently reading the document in pdf format is recommended, as for unknown
4889  reason the hyperlinks are working there whereas in the html version they
4890  are not
4891 \begin_inset Foot
4892 status open
4893
4894 \begin_layout Standard
4895 If you should know why please drop us a note
4896 \end_layout
4897
4898 \end_inset
4899
4900 .
4901  
4902 \newline
4903 You'll find the pdf version
4904 \begin_inset LatexCommand \index{PDF version of this document}
4905
4906 \end_inset
4907
4908  at 
4909 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4910
4911 \end_inset
4912
4913 .
4914  
4915 \newline
4916 A html version
4917 \begin_inset LatexCommand \index{HTML version of this document}
4918
4919 \end_inset
4920
4921  should be online at 
4922 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4923
4924 \end_inset
4925
4926 .
4927 \newline
4928 This documentation is in some aspects different from a commercial documentation:
4929  
4930 \end_layout
4931
4932 \begin_layout Itemize
4933 It tries to document SDCC for several processor architectures in one document
4934  (commercially these probably would be separate documents/products).
4935  This document
4936 \begin_inset LatexCommand \index{Status of documentation}
4937
4938 \end_inset
4939
4940  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4941 on about f.e.
4942  Z80, PIC14, PIC16 and HC08.
4943 \end_layout
4944
4945 \begin_layout Itemize
4946 There are many references pointing away from this documentation.
4947  Don't let this distract you.
4948  If there f.e.
4949  was a reference like 
4950 \begin_inset LatexCommand \url{http://www.opencores.org}
4951
4952 \end_inset
4953
4954  together with a statement 
4955 \begin_inset Quotes sld
4956 \end_inset
4957
4958 some processors which are targetted by SDCC can be implemented in a 
4959 \emph on
4960 f
4961 \emph default
4962 ield 
4963 \emph on
4964 p
4965 \emph default
4966 rogrammable 
4967 \emph on
4968 g
4969 \emph default
4970 ate 
4971 \emph on
4972 a
4973 \emph default
4974 rray
4975 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4976
4977 \end_inset
4978
4979
4980 \begin_inset Quotes srd
4981 \end_inset
4982
4983  or 
4984 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4985
4986 \end_inset
4987
4988
4989 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4990
4991 \end_inset
4992
4993  
4994 \begin_inset Quotes sld
4995 \end_inset
4996
4997 have you ever heard of an open source compiler that compiles a subset of
4998  C for an FPGA?
4999 \begin_inset Quotes srd
5000 \end_inset
5001
5002  we expect you to have a quick look there and come back.
5003  If you read this you are on the right track.
5004 \end_layout
5005
5006 \begin_layout Itemize
5007 Some sections attribute more space to problems, restrictions and warnings
5008  than to the solution.
5009 \end_layout
5010
5011 \begin_layout Itemize
5012 The installation section and the section about the debugger is intimidating.
5013 \end_layout
5014
5015 \begin_layout Itemize
5016 There are still lots of typos and there are more different writing styles
5017  than pictures.
5018 \end_layout
5019
5020 \begin_layout Section
5021 Testing the SDCC Compiler
5022 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5023
5024 \end_inset
5025
5026
5027 \end_layout
5028
5029 \begin_layout Standard
5030 The first thing you should do after installing your SDCC compiler is to
5031  see if it runs.
5032  Type 
5033 \family sans
5034 \series bold
5035 "sdcc -
5036 \begin_inset ERT
5037 status collapsed
5038
5039 \begin_layout Standard
5040
5041
5042 \backslash
5043 /
5044 \end_layout
5045
5046 \end_inset
5047
5048 -version"
5049 \begin_inset LatexCommand \index{version}
5050
5051 \end_inset
5052
5053
5054 \family default
5055 \series default
5056  at the prompt, and the program should run and output its version like:
5057  
5058 \newline
5059
5060 \family typewriter
5061 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5062  (UNIX)
5063 \end_layout
5064
5065 \begin_layout Standard
5066 If it doesn't run, or gives a message about not finding sdcc program, then
5067  you need to check over your installation.
5068  Make sure that the sdcc bin directory is in your executable search path
5069  defined by the PATH environment setting (
5070 \series medium
5071 see 
5072 \series default
5073 section 
5074 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5075
5076 \end_inset
5077
5078 \InsetSpace ~
5079
5080 \series medium
5081 Install trouble-shooting for suggestions
5082 \series default
5083 ).
5084  Make sure that the sdcc program is in the bin folder, if not perhaps something
5085  did not install correctly.
5086 \newline
5087
5088 \newline
5089
5090 \series medium
5091 SDCC 
5092 \series default
5093 is commonly installed as described in section 
5094 \begin_inset Quotes sld
5095 \end_inset
5096
5097 Install and search paths
5098 \begin_inset Quotes srd
5099 \end_inset
5100
5101 .
5102 \newline
5103
5104 \newline
5105
5106 \series medium
5107 Make sure the compiler works on a very simple example.
5108  Type in the following test.c program using your favorite 
5109 \series default
5110 ASCII 
5111 \series medium
5112 editor:
5113 \end_layout
5114
5115 \begin_layout Verse
5116
5117 \family typewriter
5118 char test;
5119 \newline
5120
5121 \newline
5122 void main(void) {
5123 \newline
5124 \InsetSpace ~
5125 \InsetSpace ~
5126 \InsetSpace ~
5127 \InsetSpace ~
5128 test=0;
5129 \newline
5130 }
5131 \end_layout
5132
5133 \begin_layout Standard
5134
5135 \series medium
5136 Compile this using the following command: 
5137 \family sans
5138 \series bold
5139 "sdcc -c test.c".
5140
5141 \family default
5142 \series default
5143  
5144 \series medium
5145 If all goes well, the compiler will generate a test.asm and test.rel file.
5146  Congratulations, you've just compiled your first program with SDCC.
5147  We used the -c option to tell SDCC not to link the generated code, just
5148  to keep things simple for this step.
5149 \series default
5150
5151 \newline
5152
5153 \newline
5154
5155 \series medium
5156 The next step is to try it with the linker.
5157  Type in 
5158 \family sans
5159 \series bold
5160 "sdcc test.c
5161 \family default
5162 \series default
5163 "
5164 \series medium
5165 .
5166  If all goes well the compiler will link with the libraries and produce
5167  a test.ihx output file.
5168  If this step fails
5169 \series default
5170  
5171 \series medium
5172 (no test.ihx, and the linker generates warnings), then the problem is most
5173  likely that 
5174 \series default
5175 SDCC
5176 \series medium
5177  cannot find the 
5178 \series default
5179 /
5180 \series medium
5181 usr/local/share/sdcc/lib directory
5182 \series default
5183  
5184 \series medium
5185 (see 
5186 \series default
5187 section 
5188 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5189
5190 \end_inset
5191
5192 \InsetSpace ~
5193
5194 \series medium
5195 Install trouble-shooting for suggestions).
5196 \series default
5197
5198 \newline
5199
5200 \newline
5201
5202 \series medium
5203 The final test is to ensure 
5204 \series default
5205 SDCC
5206 \series medium
5207  can use the 
5208 \series default
5209 standard
5210 \series medium
5211  header files and libraries.
5212  Edit test.c and change it to the following:
5213 \end_layout
5214
5215 \begin_layout Verse
5216
5217 \family typewriter
5218 #include <string.h>
5219 \newline
5220
5221 \newline
5222 char str1[10];
5223 \newline
5224
5225 \newline
5226 void main(void) {
5227 \newline
5228 \InsetSpace ~
5229 \InsetSpace ~
5230 strcpy(str1, "testing");
5231 \newline
5232 }
5233 \end_layout
5234
5235 \begin_layout Standard
5236
5237 \series medium
5238 Compile this by typing 
5239 \family sans
5240 \series bold
5241 "sdcc test.c"
5242 \family default
5243 \series medium
5244 .
5245  This should generate a test.ihx output file, and it should give no warnings
5246  such as not finding the string.h file.
5247  If it cannot find the string.h file, then the problem is that 
5248 \series default
5249 SDCC
5250 \series medium
5251  cannot find the /usr/local/share/sdcc/include directory
5252 \series default
5253  
5254 \series medium
5255 (see the 
5256 \series default
5257 section 
5258 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5259
5260 \end_inset
5261
5262 \InsetSpace ~
5263
5264 \series medium
5265 Install trouble-shooting section for suggestions).
5266
5267 \series default
5268  Use option 
5269 \series bold
5270 -
5271 \begin_inset ERT
5272 status collapsed
5273
5274 \begin_layout Standard
5275
5276
5277 \backslash
5278 /
5279 \end_layout
5280
5281 \end_inset
5282
5283 -print-search-dirs
5284 \series default
5285
5286 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5287
5288 \end_inset
5289
5290  to find exactly where SDCC is looking for the include and lib files.
5291 \end_layout
5292
5293 \begin_layout Section
5294 Install Trouble-shooting
5295 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5296
5297 \end_inset
5298
5299
5300 \begin_inset LatexCommand \index{Install trouble-shooting}
5301
5302 \end_inset
5303
5304
5305 \end_layout
5306
5307 \begin_layout Subsection
5308 If SDCC does not build correctly
5309 \end_layout
5310
5311 \begin_layout Standard
5312 A thing to try is starting from scratch by unpacking the .tgz source package
5313  again in an empty directory.
5314  Configure it like:
5315 \newline
5316
5317 \newline
5318
5319 \family sans
5320 \series bold
5321 ./configure 2>&1 | tee configure.log
5322 \family default
5323 \series default
5324
5325 \newline
5326
5327 \newline
5328 and build it like:
5329 \newline
5330
5331 \newline
5332
5333 \family sans
5334 \series bold
5335 make 2>&1 | tee make.log
5336 \family default
5337 \series default
5338
5339 \newline
5340
5341 \newline
5342 If anything goes wrong, you can review the log files to locate the problem.
5343  Or a relevant part of this can be attached to an email that could be helpful
5344  when requesting help from the mailing list.
5345 \end_layout
5346
5347 \begin_layout Subsection
5348 What the 
5349 \begin_inset Quotes sld
5350 \end_inset
5351
5352 ./configure
5353 \begin_inset Quotes srd
5354 \end_inset
5355
5356  does
5357 \end_layout
5358
5359 \begin_layout Standard
5360 The 
5361 \begin_inset Quotes sld
5362 \end_inset
5363
5364 ./configure
5365 \begin_inset Quotes srd
5366 \end_inset
5367
5368  command is a script that analyzes your system and performs some configuration
5369  to ensure the source package compiles on your system.
5370  It will take a few minutes to run, and will compile a few tests to determine
5371  what compiler features are installed.
5372 \end_layout
5373
5374 \begin_layout Subsection
5375 What the 
5376 \begin_inset Quotes sld
5377 \end_inset
5378
5379 make
5380 \begin_inset Quotes srd
5381 \end_inset
5382
5383  does
5384 \end_layout
5385
5386 \begin_layout Standard
5387 This runs the GNU make tool, which automatically compiles all the source
5388  packages into the final installed binary executables.
5389 \end_layout
5390
5391 \begin_layout Subsection
5392 What the 
5393 \begin_inset Quotes sld
5394 \end_inset
5395
5396 make install
5397 \begin_inset Quotes erd
5398 \end_inset
5399
5400  command does.
5401 \end_layout
5402
5403 \begin_layout Standard
5404 This will install the compiler, other executables libraries and include
5405  files into the appropriate directories.
5406  See sections 
5407 \begin_inset LatexCommand \ref{sub:Install-paths}
5408
5409 \end_inset
5410
5411 ,\InsetSpace ~
5412
5413 \begin_inset LatexCommand \ref{sub:Search-Paths}
5414
5415 \end_inset
5416
5417 \InsetSpace ~
5418 about install and search paths.
5419 \newline
5420 On most systems you will need super-user privilege
5421 s to do this.
5422 \end_layout
5423
5424 \begin_layout Section
5425 Components of SDCC
5426 \end_layout
5427
5428 \begin_layout Standard
5429 SDCC is not just a compiler, but a collection of tools by various developers.
5430  These include linkers, assemblers, simulators and other components.
5431  Here is a summary of some of the components.
5432  Note that the included simulator and assembler have separate documentation
5433  which you can find in the source package in their respective directories.
5434  As SDCC grows to include support for other processors, other packages from
5435  various developers are included and may have their own sets of documentation.
5436 \newline
5437
5438 \newline
5439 You
5440  might want to look at the files which are installed in <installdir>.
5441  At the time of this writing, we find the following programs for gcc-builds:
5442 \newline
5443
5444  
5445 \newline
5446 In <installdir>/bin:
5447 \end_layout
5448
5449 \begin_layout Itemize
5450 sdcc - The compiler.
5451 \end_layout
5452
5453 \begin_layout Itemize
5454 sdcpp - The C preprocessor.
5455 \end_layout
5456
5457 \begin_layout Itemize
5458 asx8051 - The assembler for 8051 type processors.
5459 \end_layout
5460
5461 \begin_layout Itemize
5462 as-z80
5463 \series bold
5464
5465 \series default
5466 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5467 \end_layout
5468
5469 \begin_layout Itemize
5470 aslink -The linker for 8051 type processors.
5471 \end_layout
5472
5473 \begin_layout Itemize
5474 link-z80
5475 \series bold
5476
5477 \series default
5478 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5479 \end_layout
5480
5481 \begin_layout Itemize
5482 s51 - The ucSim 8051 simulator.
5483 \end_layout
5484
5485 \begin_layout Itemize
5486 sdcdb - The source debugger.
5487 \end_layout
5488
5489 \begin_layout Itemize
5490 packihx - A tool to pack (compress) Intel hex files.
5491 \end_layout
5492
5493 \begin_layout Standard
5494 In <installdir>/share/sdcc/include
5495 \end_layout
5496
5497 \begin_layout Itemize
5498 the include files
5499 \end_layout
5500
5501 \begin_layout Standard
5502 In <installdir>/share/sdcc/lib
5503 \end_layout
5504
5505 \begin_layout Itemize
5506 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5507  relocatables.
5508 \end_layout
5509
5510 \begin_layout Standard
5511 In <installdir>/share/sdcc/doc
5512 \end_layout
5513
5514 \begin_layout Itemize
5515 the documentation
5516 \end_layout
5517
5518 \begin_layout Standard
5519 As development for other processors proceeds, this list will expand to include
5520  executables to support processors like AVR, PIC, etc.
5521 \end_layout
5522
5523 \begin_layout Subsection
5524 sdcc - The Compiler
5525 \end_layout
5526
5527 \begin_layout Standard
5528 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5529  the assembler and linkage editor.
5530 \end_layout
5531
5532 \begin_layout Subsection
5533 sdcpp - The C-Preprocessor
5534 \end_layout
5535
5536 \begin_layout Standard
5537 The preprocessor
5538 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5539
5540 \end_inset
5541
5542  is a modified version of the GNU cpp
5543 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5544
5545 \end_inset
5546
5547  preprocessor 
5548 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5549
5550 \end_inset
5551
5552 .
5553  The C preprocessor is used to pull in #include sources, process #ifdef
5554  statements, #defines and so on.
5555 \end_layout
5556
5557 \begin_layout Subsection
5558 as
5559 \emph on
5560 xxxx
5561 \emph default
5562 , aslink, link-
5563 \emph on
5564 xxx
5565 \emph default
5566  - The Assemblers and Linkage Editors
5567 \end_layout
5568
5569 \begin_layout Standard
5570 This is retargettable assembler & linkage editor, it was developed by Alan
5571  Baldwin.
5572  John Hartman created the version for 8051, and I (Sandeep) have made some
5573  enhancements and bug fixes for it to work properly with SDCC.
5574 \end_layout
5575
5576 \begin_layout Subsection
5577 s51 - The Simulator
5578 \end_layout
5579
5580 \begin_layout Standard
5581 S51
5582 \begin_inset LatexCommand \index{s51}
5583
5584 \end_inset
5585
5586  is a free open source simulator developed by Daniel Drotos.
5587  The simulator is built as part of the build process.
5588  For more information visit Daniel's web site at: 
5589 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5590
5591 \end_inset
5592
5593 .
5594  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5595  XA51 family.
5596 \end_layout
5597
5598 \begin_layout Subsection
5599 sdcdb - Source Level Debugger
5600 \end_layout
5601
5602 \begin_layout Standard
5603 SDCDB
5604 \begin_inset LatexCommand \index{SDCDB (debugger)}
5605
5606 \end_inset
5607
5608  is the companion source level debugger.
5609  More about SDCDB in section 
5610 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5611
5612 \end_inset
5613
5614 .
5615  The current version of the debugger uses Daniel's Simulator S51
5616 \begin_inset LatexCommand \index{s51}
5617
5618 \end_inset
5619
5620 , but can be easily changed to use other simulators.
5621 \end_layout
5622
5623 \begin_layout Chapter
5624 Using SDCC
5625 \end_layout
5626
5627 \begin_layout Section
5628 Compiling
5629 \end_layout
5630
5631 \begin_layout Subsection
5632 Single Source File Projects
5633 \end_layout
5634
5635 \begin_layout Standard
5636 For single source file 8051 projects the process is very simple.
5637  Compile your programs with the following command 
5638 \family sans
5639 \series bold
5640 "sdcc sourcefile.c".
5641
5642 \family default
5643 \series default
5644  This will compile, assemble and link your source file.
5645  Output files are as follows:
5646 \end_layout
5647
5648 \begin_layout Itemize
5649 sourcefile.asm
5650 \begin_inset LatexCommand \index{<file>.asm}
5651
5652 \end_inset
5653
5654  - Assembler source
5655 \begin_inset LatexCommand \index{Assembler source}
5656
5657 \end_inset
5658
5659  file created by the compiler
5660 \end_layout
5661
5662 \begin_layout Itemize
5663 sourcefile.lst
5664 \begin_inset LatexCommand \index{<file>.lst}
5665
5666 \end_inset
5667
5668  - Assembler listing
5669 \begin_inset LatexCommand \index{Assembler listing}
5670
5671 \end_inset
5672
5673  file created by the Assembler
5674 \end_layout
5675
5676 \begin_layout Itemize
5677 sourcefile.rst
5678 \begin_inset LatexCommand \index{<file>.rst}
5679
5680 \end_inset
5681
5682  - Assembler listing
5683 \begin_inset LatexCommand \index{Assembler listing}
5684
5685 \end_inset
5686
5687  file updated with linkedit information, created by linkage editor
5688 \end_layout
5689
5690 \begin_layout Itemize
5691 sourcefile.sym
5692 \begin_inset LatexCommand \index{<file>.sym}
5693
5694 \end_inset
5695
5696  - symbol listing
5697 \begin_inset LatexCommand \index{Symbol listing}
5698
5699 \end_inset
5700
5701  for the sourcefile, created by the assembler
5702 \end_layout
5703
5704 \begin_layout Itemize
5705 sourcefile.rel
5706 \begin_inset LatexCommand \index{<file>.rel}
5707
5708 \end_inset
5709
5710  or sourcefile.o
5711 \begin_inset LatexCommand \index{<file>.o}
5712
5713 \end_inset
5714
5715  - Object file
5716 \begin_inset LatexCommand \index{Object file}
5717
5718 \end_inset
5719
5720  created by the assembler, input to Linkage editor
5721 \end_layout
5722
5723 \begin_layout Itemize
5724 sourcefile.map
5725 \begin_inset LatexCommand \index{<file>.map}
5726
5727 \end_inset
5728
5729  - The memory map
5730 \begin_inset LatexCommand \index{Memory map}
5731
5732 \end_inset
5733
5734  for the load module, created by the Linker
5735 \end_layout
5736
5737 \begin_layout Itemize
5738 sourcefile.mem
5739 \begin_inset LatexCommand \index{<file>.mem}
5740
5741 \end_inset
5742
5743  - A file with a summary of the memory usage
5744 \end_layout
5745
5746 \begin_layout Itemize
5747 sourcefile.ihx
5748 \begin_inset LatexCommand \index{<file>.ihx}
5749
5750 \end_inset
5751
5752  - The load module in Intel hex format
5753 \begin_inset LatexCommand \index{Intel hex format}
5754
5755 \end_inset
5756
5757  (you can select the Motorola S19 format
5758 \begin_inset LatexCommand \index{Motorola S19 format}
5759
5760 \end_inset
5761
5762  with -
5763 \begin_inset ERT
5764 status collapsed
5765
5766 \begin_layout Standard
5767
5768
5769 \backslash
5770 /
5771 \end_layout
5772
5773 \end_inset
5774
5775 -out-fmt-s19
5776 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5777
5778 \end_inset
5779
5780 .
5781  If you need another format you might want to use 
5782 \family sans
5783 \shape italic
5784 objdump
5785 \family default
5786 \shape default
5787
5788 \begin_inset LatexCommand \index{objdump (tool)}
5789
5790 \end_inset
5791
5792  or
5793 \family sans
5794 \shape italic
5795  srecord
5796 \family default
5797 \shape default
5798
5799 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5800
5801 \end_inset
5802
5803
5804 \begin_inset Note Note
5805 status collapsed
5806
5807 \begin_layout Standard
5808 hyperlinks needed
5809 \end_layout
5810
5811 \end_inset
5812
5813  - see also section 
5814 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5815
5816 \end_inset
5817
5818 ).
5819  Both formats are documented in the documentation of srecord
5820 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5821
5822 \end_inset
5823
5824
5825 \end_layout
5826
5827 \begin_layout Itemize
5828 sourcefile.adb
5829 \begin_inset LatexCommand \index{<file>.adb}
5830
5831 \end_inset
5832
5833  - An intermediate file containing debug information needed to create the
5834  .cdb file (with -
5835 \begin_inset ERT
5836 status collapsed
5837
5838 \begin_layout Standard
5839
5840
5841 \backslash
5842 /
5843 \end_layout
5844
5845 \end_inset
5846
5847 -debug
5848 \begin_inset LatexCommand \index{-\/-debug}
5849
5850 \end_inset
5851
5852
5853 \end_layout
5854
5855 \begin_layout Itemize
5856 sourcefile.cdb
5857 \begin_inset LatexCommand \index{<file>.cdb}
5858
5859 \end_inset
5860
5861  - An optional file (with -
5862 \begin_inset ERT
5863 status collapsed
5864
5865 \begin_layout Standard
5866
5867
5868 \backslash
5869 /
5870 \end_layout
5871
5872 \end_inset
5873
5874 -debug) containing debug information.
5875  The format is documented in cdbfileformat.pdf
5876 \end_layout
5877
5878 \begin_layout Itemize
5879 sourcefile.
5880  - (no extension)
5881 \begin_inset LatexCommand \index{<file> (no extension)}
5882
5883 \end_inset
5884
5885  An optional AOMF or AOMF51
5886 \begin_inset LatexCommand \index{AOMF, AOMF51}
5887
5888 \end_inset
5889
5890  
5891 \begin_inset LatexCommand \label{OMF file}
5892
5893 \end_inset
5894
5895 file containing debug information (generated with option -
5896 \begin_inset ERT
5897 status collapsed
5898
5899 \begin_layout Standard
5900
5901
5902 \backslash
5903 /
5904 \end_layout
5905
5906 \end_inset
5907
5908 -debug).
5909  The (Intel)
5910 \emph on
5911  a
5912 \emph default
5913 bsolute 
5914 \emph on
5915 o
5916 \emph default
5917 bject 
5918 \emph on
5919 m
5920 \emph default
5921 odule 
5922 \emph on
5923 f
5924 \emph default
5925 ormat is a subformat of the OMF51 format and is commonly used by third party
5926  tools (debuggers
5927 \begin_inset LatexCommand \index{Debugger}
5928
5929 \end_inset
5930
5931 , simulators, emulators).
5932 \end_layout
5933
5934 \begin_layout Itemize
5935 sourcefile.dump*
5936 \begin_inset LatexCommand \index{<file>.dump*}
5937
5938 \end_inset
5939
5940  - Dump file to debug the compiler it self (generated with option -
5941 \begin_inset ERT
5942 status collapsed
5943
5944 \begin_layout Standard
5945
5946
5947 \backslash
5948 /
5949 \end_layout
5950
5951 \end_inset
5952
5953 -dumpall) (see section 
5954 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5955
5956 \end_inset
5957
5958 \InsetSpace ~
5959  and section 
5960 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5961
5962 \end_inset
5963
5964 \InsetSpace ~
5965
5966 \begin_inset Quotes sld
5967 \end_inset
5968
5969 Anatomy of the compiler
5970 \begin_inset Quotes srd
5971 \end_inset
5972
5973 ).
5974 \end_layout
5975
5976 \begin_layout Subsection
5977 Postprocessing the Intel Hex
5978 \begin_inset LatexCommand \index{Intel hex format}
5979
5980 \end_inset
5981
5982  file
5983 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5984
5985 \end_inset
5986
5987
5988 \end_layout
5989
5990 \begin_layout Standard
5991 In most cases this won't be needed but the Intel Hex file
5992 \begin_inset LatexCommand \index{<file>.ihx}
5993
5994 \end_inset
5995
5996  which is generated by SDCC might include lines of varying length and the
5997  addresses within the file are not guaranteed to be strictly ascending.
5998  If your toolchain or a bootloader does not like this you can use the tool
5999  
6000 \family typewriter
6001 packihx
6002 \family default
6003
6004 \begin_inset LatexCommand \index{packihx (tool)}
6005
6006 \end_inset
6007
6008  which is part of the SDCC distribution: 
6009 \newline
6010
6011 \newline
6012
6013 \family sans
6014 \series bold
6015  packihx sourcefile.ihx >sourcefile.hex
6016 \family default
6017 \series default
6018
6019 \newline
6020
6021 \newline
6022 The separately available
6023 \emph on
6024  srecord
6025 \emph default
6026
6027 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6028
6029 \end_inset
6030
6031  package additionally allows to set undefined locations to a predefined
6032  value, to insert checksums
6033 \begin_inset LatexCommand \index{checksum}
6034
6035 \end_inset
6036
6037  of various flavours (crc, add, xor) and to perform other manipulations
6038  (convert, split, crop, offset, ...).
6039  
6040 \newline
6041
6042 \newline
6043
6044 \family sans
6045 \series bold
6046 srec_cat\InsetSpace ~
6047 \InsetSpace ~
6048 sourcefile.ihx -intel\InsetSpace ~
6049 \InsetSpace ~
6050 -o sourcefile.hex -intel
6051 \newline
6052
6053 \newline
6054
6055 \family default
6056 \series default
6057 An example for a more complex command line
6058 \begin_inset Foot
6059 status open
6060
6061 \begin_layout Standard
6062 the command backfills
6063 \begin_inset LatexCommand \index{backfill unused memory}
6064
6065 \end_inset
6066
6067  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6068  block is zero.
6069  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6070  will be interpreted as an 
6071 \family typewriter
6072 lcall
6073 \family default
6074  to address 
6075 \family typewriter
6076 0x1212
6077 \family default
6078  (where an emergency routine could sit).
6079 \end_layout
6080
6081 \end_inset
6082
6083  could look like:
6084 \newline
6085
6086 \newline
6087
6088 \family sans
6089 \series bold
6090 \size footnotesize
6091 srec_cat\InsetSpace ~
6092 sourcefile.ihx -intel\InsetSpace ~
6093 \InsetSpace ~
6094 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6095 -little-endian-checksum-nega
6096 tive 0xfffe 0x02 0x02\InsetSpace ~
6097 \InsetSpace ~
6098 -o sourcefile.hex -intel
6099 \size default
6100
6101 \newline
6102
6103 \newline
6104
6105 \family default
6106 \series default
6107 The srecord package is available at 
6108 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6109
6110 \end_inset
6111
6112  .
6113 \end_layout
6114
6115 \begin_layout Subsection
6116 Projects with Multiple Source Files
6117 \end_layout
6118
6119 \begin_layout Standard
6120 SDCC can compile only ONE file at a time.
6121  Let us for example assume that you have a project containing the following
6122  files:
6123 \newline
6124
6125 \newline
6126 foo1.c (contains some functions)
6127 \newline
6128 foo2.c (contains some more functions)
6129 \newline
6130 foomai
6131 n.c (contains more functions and the function main)
6132 \newline
6133
6134 \size footnotesize
6135
6136 \newline
6137
6138 \size default
6139 The first two files will need to be compiled separately with the commands:
6140 \size footnotesize
6141  
6142 \size default
6143
6144 \newline
6145
6146 \newline
6147
6148 \family sans
6149 \series bold
6150 sdcc\InsetSpace ~
6151 -c\InsetSpace ~
6152 foo1.c
6153 \family default
6154 \series default
6155 \size footnotesize
6156
6157 \newline
6158
6159 \family sans
6160 \series bold
6161 \size default
6162 sdcc\InsetSpace ~
6163 -c\InsetSpace ~
6164 foo2.c
6165 \family default
6166 \series default
6167
6168 \newline
6169
6170 \newline
6171 Then compile the source file containing the 
6172 \emph on
6173 main()
6174 \emph default
6175  function and link
6176 \begin_inset LatexCommand \index{Linker}
6177
6178 \end_inset
6179
6180  the files together with the following command: 
6181 \newline
6182
6183 \newline
6184
6185 \family sans
6186 \series bold
6187 sdcc\InsetSpace ~
6188 foomain.c\InsetSpace ~
6189 foo1.rel\InsetSpace ~
6190 foo2.rel
6191 \family default
6192 \series default
6193
6194 \begin_inset LatexCommand \index{<file>.rel}
6195
6196 \end_inset
6197
6198
6199 \newline
6200
6201 \newline
6202 Alternatively, 
6203 \emph on
6204 foomain.c 
6205 \emph default
6206 can be separately compiled as well: 
6207 \family sans
6208 \series bold
6209
6210 \newline
6211
6212 \newline
6213 sdcc\InsetSpace ~
6214 -c\InsetSpace ~
6215 foomain.c
6216 \newline
6217 sdcc foomain.rel foo1.rel foo2.rel
6218 \newline
6219
6220 \newline
6221
6222 \family default
6223 \series default
6224 The file containing the 
6225 \emph on
6226 main()
6227 \emph default
6228  function
6229 \emph on
6230  
6231 \emph default
6232 \noun on
6233 must
6234 \noun default
6235  be the 
6236 \noun on
6237 first
6238 \noun default
6239  file specified in the command line, since the linkage editor processes
6240  file in the order they are presented to it.
6241  The linker is invoked from SDCC using a script file with extension .lnk
6242 \begin_inset LatexCommand \index{<file>.lnk}
6243
6244 \end_inset
6245
6246 .
6247  You can view this file to troubleshoot linking problems such as those arising
6248  from missing libraries.
6249 \end_layout
6250
6251 \begin_layout Subsection
6252 Projects with Additional Libraries
6253 \begin_inset LatexCommand \index{Libraries}
6254
6255 \end_inset
6256
6257
6258 \end_layout
6259
6260 \begin_layout Standard
6261 Some reusable routines may be compiled into a library, see the documentation
6262  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6263  for how to create a 
6264 \emph on
6265 .lib
6266 \begin_inset LatexCommand \index{<file>.lib}
6267
6268 \end_inset
6269
6270
6271 \emph default
6272  library file.
6273  Libraries created in this manner can be included in the command line.
6274  Make sure you include the -L <library-path> option to tell the linker where
6275  to look for these files if they are not in the current directory.
6276  Here is an example, assuming you have the source file 
6277 \emph on
6278 foomain.c
6279 \emph default
6280  and a library
6281 \emph on
6282  foolib.lib
6283 \emph default
6284  in the directory 
6285 \emph on
6286 mylib
6287 \emph default
6288  (if that is not the same as your current project):
6289 \newline
6290
6291 \newline
6292
6293 \family sans
6294 \series bold
6295 sdcc foomain.c foolib.lib -L mylib
6296 \newline
6297
6298 \newline
6299
6300 \family default
6301 \series default
6302 Note here that
6303 \emph on
6304  mylib
6305 \emph default
6306  must be an absolute path name.
6307 \newline
6308
6309 \newline
6310 The most efficient way to use libraries is
6311  to keep separate modules in separate source files.
6312  The lib file now should name all the modules.rel
6313 \begin_inset LatexCommand \index{<file>.rel}
6314
6315 \end_inset
6316
6317  files.
6318  For an example see the standard library file 
6319 \emph on
6320 libsdcc.lib
6321 \emph default
6322  in the directory <installdir>/share/lib/small.
6323 \end_layout
6324
6325 \begin_layout Subsection
6326 Using sdcclib to Create and Manage Libraries
6327 \begin_inset LatexCommand \index{sdcclib}
6328
6329 \end_inset
6330
6331
6332 \end_layout
6333
6334 \begin_layout Standard
6335 Alternatively, instead of having a .rel file for each entry on the library
6336  file as described in the preceding section, sdcclib can be used to embed
6337  all the modules belonging to such library in the library file itself.
6338  This results in a larger library file, but it greatly reduces the number
6339  of disk files accessed by the linker.
6340   Additionally, the packed library file contains an index of all include
6341  modules and symbols that significantly speeds up the linking process.
6342  To display a list of options supported by sdcclib type:
6343 \newline
6344
6345 \end_layout
6346
6347 \begin_layout Standard
6348
6349 \family sans
6350 \series bold
6351 sdcclib -?
6352 \begin_inset LatexCommand \index{sdcclib}
6353
6354 \end_inset
6355
6356
6357 \newline
6358
6359 \newline
6360
6361 \family default
6362 \series default
6363 To create a new library file, start by compiling all the required modules.
6364  For example:
6365 \newline
6366
6367 \end_layout
6368
6369 \begin_layout Standard
6370
6371 \family sans
6372 \series bold
6373 sdcc -c _divsint.c
6374 \end_layout
6375
6376 \begin_layout Standard
6377
6378 \family sans
6379 \series bold
6380 sdcc -c _divuint.c
6381 \end_layout
6382
6383 \begin_layout Standard
6384
6385 \family sans
6386 \series bold
6387 sdcc -c _modsint.c
6388 \end_layout
6389
6390 \begin_layout Standard
6391
6392 \family sans
6393 \series bold
6394 sdcc -c _moduint.c
6395 \end_layout
6396
6397 \begin_layout Standard
6398
6399 \family sans
6400 \series bold
6401 sdcc -c _mulint.c
6402 \newline
6403
6404 \end_layout
6405
6406 \begin_layout Standard
6407 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6408  and _mulint.rel.
6409  The next step is to add the .rel files to the library file:
6410 \newline
6411
6412 \end_layout
6413
6414 \begin_layout Standard
6415
6416 \family sans
6417 \series bold
6418 sdcclib libint.lib _divsint.rel
6419 \family default
6420
6421 \begin_inset LatexCommand \index{sdcclib}
6422
6423 \end_inset
6424
6425
6426 \end_layout
6427
6428 \begin_layout Standard
6429
6430 \family sans
6431 \series bold
6432 sdcclib libint.lib _divuint.rel
6433 \end_layout
6434
6435 \begin_layout Standard
6436
6437 \family sans
6438 \series bold
6439 sdcclib libint.lib _modsint.rel
6440 \end_layout
6441
6442 \begin_layout Standard
6443
6444 \family sans
6445 \series bold
6446 sdcclib libint.lib _moduint.rel
6447 \end_layout
6448
6449 \begin_layout Standard
6450
6451 \family sans
6452 \series bold
6453 sdcclib libint.lib _mulint.rel
6454 \family default
6455 \series default
6456
6457 \newline
6458
6459 \end_layout
6460
6461 \begin_layout Standard
6462 Or, if you preffer:
6463 \family sans
6464 \series bold
6465
6466 \newline
6467
6468 \end_layout
6469
6470 \begin_layout Standard
6471
6472 \family sans
6473 \series bold
6474 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6475 \family default
6476 \series default
6477
6478 \newline
6479
6480 \end_layout
6481
6482 \begin_layout Standard
6483 If the file already exists in the library, it will be replaced.
6484  If a list of .rel files is available, you can tell sdcclib to add those
6485  files to a library.
6486  For example, if the file 'myliblist.txt' contains
6487 \family sans
6488 \series bold
6489
6490 \newline
6491
6492 \end_layout
6493
6494 \begin_layout Standard
6495
6496 \family sans
6497 \series bold
6498 _divsint.rel
6499 \end_layout
6500
6501 \begin_layout Standard
6502
6503 \family sans
6504 \series bold
6505 _divuint.rel
6506 \end_layout
6507
6508 \begin_layout Standard
6509
6510 \family sans
6511 \series bold
6512 _modsint.rel
6513 \end_layout
6514
6515 \begin_layout Standard
6516
6517 \family sans
6518 \series bold
6519 _moduint.rel
6520 \end_layout
6521
6522 \begin_layout Standard
6523
6524 \family sans
6525 \series bold
6526 _mulint.rel
6527 \family default
6528 \series default
6529
6530 \newline
6531
6532 \end_layout
6533
6534 \begin_layout Standard
6535 Use
6536 \family sans
6537 \series bold
6538
6539 \newline
6540
6541 \end_layout
6542
6543 \begin_layout Standard
6544
6545 \family sans
6546 \series bold
6547 sdcclib -l libint.lib myliblist.txt
6548 \family default
6549 \series default
6550
6551 \newline
6552
6553 \end_layout
6554
6555 \begin_layout Standard
6556 Additionally, you can instruct sdcclib to compiles the files before adding
6557  them to the library.
6558  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6559  For example:
6560 \family sans
6561 \series bold
6562
6563 \newline
6564
6565 \end_layout
6566
6567 \begin_layout Standard
6568
6569 \family sans
6570 \series bold
6571 set SDCCLIB_CC=sdcc -c
6572 \end_layout
6573
6574 \begin_layout Standard
6575
6576 \family sans
6577 \series bold
6578 sdcclib -l libint.lib myliblist.txt
6579 \family default
6580 \series default
6581
6582 \newline
6583
6584 \end_layout
6585
6586 \begin_layout Standard
6587 To see what modules and symbols are included in the library, options -s
6588  and -m are available.
6589  For example:
6590 \newline
6591
6592 \newline
6593
6594 \family sans
6595 \series bold
6596 sdcclib -s libint.lib
6597 \family default
6598
6599 \begin_inset LatexCommand \index{sdcclib}
6600
6601 \end_inset
6602
6603
6604 \newline
6605
6606 \family typewriter
6607 \series default
6608 _divsint.rel:
6609 \end_layout
6610
6611 \begin_layout Standard
6612
6613 \family typewriter
6614 __divsint_a_1_1
6615 \end_layout
6616
6617 \begin_layout Standard
6618
6619 \family typewriter
6620 __divsint_PARM_2
6621 \end_layout
6622
6623 \begin_layout Standard
6624
6625 \family typewriter
6626 __divsint
6627 \newline
6628 _divuint.rel:
6629 \end_layout
6630
6631 \begin_layout Standard
6632
6633 \family typewriter
6634 __divuint_a_1_1
6635 \end_layout
6636
6637 \begin_layout Standard
6638
6639 \family typewriter
6640 __divuint_PARM_2
6641 \end_layout
6642
6643 \begin_layout Standard
6644
6645 \family typewriter
6646 __divuint_reste_1_1
6647 \end_layout
6648
6649 \begin_layout Standard
6650
6651 \family typewriter
6652 __divuint_count_1_1
6653 \end_layout
6654
6655 \begin_layout Standard
6656
6657 \family typewriter
6658 __divuint
6659 \newline
6660 _modsint.rel:
6661 \end_layout
6662
6663 \begin_layout Standard
6664
6665 \family typewriter
6666 __modsint_a_1_1
6667 \end_layout
6668
6669 \begin_layout Standard
6670
6671 \family typewriter
6672 __modsint_PARM_2
6673 \end_layout
6674
6675 \begin_layout Standard
6676
6677 \family typewriter
6678 __modsint
6679 \newline
6680 _moduint.rel:
6681 \end_layout
6682
6683 \begin_layout Standard
6684
6685 \family typewriter
6686 __moduint_a_1_1
6687 \end_layout
6688
6689 \begin_layout Standard
6690
6691 \family typewriter
6692 __moduint_PARM_2
6693 \end_layout
6694
6695 \begin_layout Standard
6696
6697 \family typewriter
6698 __moduint_count_1_1
6699 \end_layout
6700
6701 \begin_layout Standard
6702
6703 \family typewriter
6704 __moduint
6705 \newline
6706 _mulint.rel:
6707 \end_layout
6708
6709 \begin_layout Standard
6710
6711 \family typewriter
6712 __mulint_PARM_2
6713 \end_layout
6714
6715 \begin_layout Standard
6716
6717 \family typewriter
6718 __mulint
6719 \family default
6720 \series bold
6721
6722 \newline
6723
6724 \end_layout
6725
6726 \begin_layout Standard
6727 If the source files are compiled using -
6728 \begin_inset ERT
6729 status collapsed
6730
6731 \begin_layout Standard
6732
6733
6734 \backslash
6735 /
6736 \end_layout
6737
6738 \end_inset
6739
6740 -debug
6741 \begin_inset LatexCommand \index{-\/-debug}
6742
6743 \end_inset
6744
6745 , the corresponding debug information file .adb will be include in the library
6746  file as well.
6747  The library files created with sdcclib are plain text files, so they can
6748  be viewed with a text editor.
6749  It is not recomended to modify a library file created with sdcclib using
6750  a text editor, as there are file indexes numbers located accross the file
6751  used by the linker to quickly locate the required module to link.
6752  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6753  it can be safely deleted, since all the information required for linking
6754  is embedded in the library file itself.
6755  Library files created using sdcclib are used as described in the preceding
6756  sections.
6757 \begin_inset VSpace bigskip
6758 \end_inset
6759
6760
6761 \end_layout
6762
6763 \begin_layout Section
6764 Command Line Options
6765 \begin_inset LatexCommand \index{Command Line Options}
6766
6767 \end_inset
6768
6769
6770 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6771
6772 \end_inset
6773
6774
6775 \end_layout
6776
6777 \begin_layout Subsection
6778 Processor Selection Options
6779 \begin_inset LatexCommand \index{Options processor selection}
6780
6781 \end_inset
6782
6783
6784 \begin_inset LatexCommand \index{Processor selection options}
6785
6786 \end_inset
6787
6788
6789 \end_layout
6790
6791 \begin_layout List
6792 \labelwidthstring 00.00.0000
6793
6794 \series bold
6795 -mmcs51
6796 \begin_inset LatexCommand \index{-mmcs51}
6797
6798 \end_inset
6799
6800
6801 \series default
6802  Generate code for the Intel MCS51
6803 \begin_inset LatexCommand \index{MCS51}
6804
6805 \end_inset
6806
6807  family of processors.
6808  This is the default processor target.
6809 \end_layout
6810
6811 \begin_layout List
6812 \labelwidthstring 00.00.0000
6813
6814 \series bold
6815 -mds390
6816 \begin_inset LatexCommand \index{-mds390}
6817
6818 \end_inset
6819
6820
6821 \series default
6822  Generate code for the Dallas DS80C390
6823 \begin_inset LatexCommand \index{DS80C390}
6824
6825 \end_inset
6826
6827  processor.
6828 \end_layout
6829
6830 \begin_layout List
6831 \labelwidthstring 00.00.0000
6832
6833 \series bold
6834 -mds400
6835 \begin_inset LatexCommand \index{-mds400}
6836
6837 \end_inset
6838
6839
6840 \series default
6841  Generate code for the Dallas DS80C400
6842 \begin_inset LatexCommand \index{DS80C400}
6843
6844 \end_inset
6845
6846  processor.
6847 \end_layout
6848
6849 \begin_layout List
6850 \labelwidthstring 00.00.0000
6851
6852 \series bold
6853 -mhc08
6854 \begin_inset LatexCommand \index{-mhc08}
6855
6856 \end_inset
6857
6858
6859 \series default
6860  Generate code for the Freescale/Motorola HC08
6861 \begin_inset LatexCommand \index{HC08}
6862
6863 \end_inset
6864
6865  family of processors.
6866 \end_layout
6867
6868 \begin_layout List
6869 \labelwidthstring 00.00.0000
6870
6871 \series bold
6872 -mz80
6873 \begin_inset LatexCommand \index{-mz80}
6874
6875 \end_inset
6876
6877
6878 \series default
6879  Generate code for the Zilog Z80
6880 \begin_inset LatexCommand \index{Z80}
6881
6882 \end_inset
6883
6884  family of processors.
6885 \end_layout
6886
6887 \begin_layout List
6888 \labelwidthstring 00.00.0000
6889
6890 \series bold
6891 -mgbz80
6892 \begin_inset LatexCommand \index{-mgbz80}
6893
6894 \end_inset
6895
6896
6897 \series default
6898  Generate code for the GameBoy Z80
6899 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6900
6901 \end_inset
6902
6903  processor (Not actively maintained).
6904 \end_layout
6905
6906 \begin_layout List
6907 \labelwidthstring 00.00.0000
6908
6909 \series bold
6910 -mavr
6911 \begin_inset LatexCommand \index{-mavr}
6912
6913 \end_inset
6914
6915
6916 \series default
6917  Generate code for the Atmel AVR
6918 \begin_inset LatexCommand \index{AVR}
6919
6920 \end_inset
6921
6922  processor (Not maintained, not complete).
6923  AVR users should probably have a look at winavr 
6924 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6925
6926 \end_inset
6927
6928  or 
6929 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6930
6931 \end_inset
6932
6933 , which is based on AVR-port of the gcc compiler.
6934 \end_layout
6935
6936 \begin_layout Standard
6937 \begin_inset Note Note
6938 status collapsed
6939
6940 \begin_layout Standard
6941 I think it is fair to direct users there for now.
6942  Open source is also about avoiding unnecessary work .
6943  But I didn't find the 'official' link.
6944 \end_layout
6945
6946 \end_inset
6947
6948
6949 \end_layout
6950
6951 \begin_layout List
6952 \labelwidthstring 00.00.0000
6953
6954 \series bold
6955 -mpic14
6956 \begin_inset LatexCommand \index{-mpic14}
6957
6958 \end_inset
6959
6960
6961 \series default
6962  Generate code for the Microchip PIC 14
6963 \begin_inset LatexCommand \index{PIC14}
6964
6965 \end_inset
6966
6967 -bit processors (p16f84 and variants.
6968  In development, not complete).
6969 \end_layout
6970
6971 \begin_layout Standard
6972 \begin_inset Note Note
6973 status collapsed
6974
6975 \begin_layout Standard
6976 p16f627 p16f628 p16f84 p16f873 p16f877?
6977 \end_layout
6978
6979 \end_inset
6980
6981
6982 \end_layout
6983
6984 \begin_layout List
6985 \labelwidthstring 00.00.0000
6986
6987 \series bold
6988 -mpic16
6989 \begin_inset LatexCommand \index{-mpic16}
6990
6991 \end_inset
6992
6993
6994 \series default
6995  Generate code for the Microchip PIC 16
6996 \begin_inset LatexCommand \index{PIC16}
6997
6998 \end_inset
6999
7000 -bit processors (p18f452 and variants.
7001  In development, not complete).
7002 \end_layout
7003
7004 \begin_layout List
7005 \labelwidthstring 00.00.0000
7006
7007 \series bold
7008 -mtlcs900h
7009 \series default
7010  Generate code for the Toshiba TLCS-900H
7011 \begin_inset LatexCommand \index{TLCS-900H}
7012
7013 \end_inset
7014
7015  processor (Not maintained, not complete).
7016 \end_layout
7017
7018 \begin_layout List
7019 \labelwidthstring 00.00.0000
7020
7021 \series bold
7022 -mxa51
7023 \begin_inset LatexCommand \index{-mxa51}
7024
7025 \end_inset
7026
7027
7028 \series default
7029  Generate code for the Phillips XA51
7030 \begin_inset LatexCommand \index{XA51}
7031
7032 \end_inset
7033
7034  processor (Not maintained, not complete).
7035 \end_layout
7036
7037 \begin_layout Standard
7038 \begin_inset VSpace bigskip
7039 \end_inset
7040
7041
7042 \end_layout
7043
7044 \begin_layout Subsection
7045 Preprocessor Options
7046 \begin_inset LatexCommand \index{Options preprocessor}
7047
7048 \end_inset
7049
7050
7051 \begin_inset LatexCommand \index{Preprocessor options}
7052
7053 \end_inset
7054
7055
7056 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7057
7058 \end_inset
7059
7060
7061 \end_layout
7062
7063 \begin_layout List
7064 \labelwidthstring 00.00.0000
7065
7066 \series bold
7067 -I<path>
7068 \begin_inset LatexCommand \index{-I<path>}
7069
7070 \end_inset
7071
7072
7073 \series default
7074  The additional location where the preprocessor will look for <..h> or 
7075 \begin_inset Quotes eld
7076 \end_inset
7077
7078 ..h
7079 \begin_inset Quotes erd
7080 \end_inset
7081
7082  files.
7083 \end_layout
7084
7085 \begin_layout List
7086 \labelwidthstring 00.00.0000
7087
7088 \series bold
7089 -D<macro[=value]>
7090 \begin_inset LatexCommand \index{-D<macro[=value]>}
7091
7092 \end_inset
7093
7094
7095 \series default
7096  Command line definition of macros.
7097  Passed to the preprocessor.
7098 \end_layout
7099
7100 \begin_layout List
7101 \labelwidthstring 00.00.0000
7102
7103 \series bold
7104 -M
7105 \begin_inset LatexCommand \index{-M}
7106
7107 \end_inset
7108
7109
7110 \series default
7111  Tell the preprocessor to output a rule suitable for make describing the
7112  dependencies of each object file.
7113  For each source file, the preprocessor outputs one make-rule whose target
7114  is the object file name for that source file and whose dependencies are
7115  all the files `#include'd in it.
7116  This rule may be a single line or may be continued with `
7117 \backslash
7118 '-newline if it is long.
7119  The list of rules is printed on standard output instead of the preprocessed
7120  C program.
7121  `-M' implies `-E
7122 \begin_inset LatexCommand \index{-E}
7123
7124 \end_inset
7125
7126 '.
7127 \end_layout
7128
7129 \begin_layout List
7130 \labelwidthstring 00.00.0000
7131
7132 \series bold
7133 -C
7134 \begin_inset LatexCommand \index{-C}
7135
7136 \end_inset
7137
7138
7139 \series default
7140  Tell the preprocessor not to discard comments.
7141  Used with the `-E' option.
7142 \end_layout
7143
7144 \begin_layout List
7145 \labelwidthstring 00.00.0000
7146
7147 \series bold
7148 -MM
7149 \begin_inset LatexCommand \index{-MM}
7150
7151 \end_inset
7152
7153
7154 \size large
7155 \bar under
7156  
7157 \series default
7158 \size default
7159 \bar default
7160 Like `-M' but the output mentions only the user header files included with
7161  `#include 
7162 \begin_inset Quotes eld
7163 \end_inset
7164
7165 file"'.
7166  System header files included with `#include <file>' are omitted.
7167 \end_layout
7168
7169 \begin_layout List
7170 \labelwidthstring 00.00.0000
7171
7172 \series bold
7173 -Aquestion(answer)
7174 \begin_inset LatexCommand \index{-Aquestion(answer)}
7175
7176 \end_inset
7177
7178
7179 \series default
7180  Assert the answer answer for question, in case it is tested with a preprocessor
7181  conditional such as `#if #question(answer)'.
7182  `-A-' disables the standard assertions that normally describe the target
7183  machine.
7184 \end_layout
7185
7186 \begin_layout List
7187 \labelwidthstring 00.00.0000
7188
7189 \series bold
7190 -Umacro
7191 \begin_inset LatexCommand \index{-Umacro}
7192
7193 \end_inset
7194
7195
7196 \series default
7197  Undefine macro macro.
7198  `-U' options are evaluated after all `-D' options, but before any `-include'
7199  and `-imacros' options.
7200 \end_layout
7201
7202 \begin_layout List
7203 \labelwidthstring 00.00.0000
7204
7205 \series bold
7206 -dM
7207 \begin_inset LatexCommand \index{-dM}
7208
7209 \end_inset
7210
7211
7212 \series default
7213  Tell the preprocessor to output only a list of the macro definitions that
7214  are in effect at the end of preprocessing.
7215  Used with the `-E' option.
7216 \end_layout
7217
7218 \begin_layout List
7219 \labelwidthstring 00.00.0000
7220
7221 \series bold
7222 -dD
7223 \begin_inset LatexCommand \index{-dD}
7224
7225 \end_inset
7226
7227
7228 \series default
7229  Tell the preprocessor to pass all macro definitions into the output, in
7230  their proper sequence in the rest of the output.
7231 \end_layout
7232
7233 \begin_layout List
7234 \labelwidthstring 00.00.0000
7235
7236 \series bold
7237 -dN
7238 \begin_inset LatexCommand \index{-dN}
7239
7240 \end_inset
7241
7242
7243 \size large
7244 \bar under
7245  
7246 \series default
7247 \size default
7248 \bar default
7249 Like `-dD' except that the macro arguments and contents are omitted.
7250  Only `#define name' is included in the output.
7251 \end_layout
7252
7253 \begin_layout List
7254 \labelwidthstring 00.00.0000
7255
7256 \series bold
7257 -pedantic-parse-number
7258 \begin_inset LatexCommand \index{pedantic}
7259
7260 \end_inset
7261
7262
7263 \begin_inset LatexCommand \index{-pedantic-parse-number}
7264
7265 \end_inset
7266
7267
7268 \size large
7269 \bar under
7270
7271 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7272
7273 \end_inset
7274
7275  
7276 \series default
7277 \size default
7278 \bar default
7279 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7280  and the macro LO_B(3) gets expanded.
7281  See also #pragma pedantic_parse_number 
7282 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7283
7284 \end_inset
7285
7286  in section
7287 \begin_inset LatexCommand \ref{sec:Pragmas}
7288
7289 \end_inset
7290
7291  
7292 \emph on
7293 Note: this functionality is not in conformance with C99 standard!
7294 \end_layout
7295
7296 \begin_layout List
7297 \labelwidthstring 00.00.0000
7298
7299 \series bold
7300 -Wp\InsetSpace ~
7301 preprocessorOption[,preprocessorOption]
7302 \series default
7303
7304 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7305
7306 \end_inset
7307
7308 ...
7309  Pass the preprocessorOption to the preprocessor 
7310 \family typewriter
7311 sdcpp
7312 \family default
7313
7314 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7315
7316 \end_inset
7317
7318 .
7319  SDCC uses an adapted version of the preprocessor 
7320 \emph on
7321 cpp
7322 \emph default
7323  of the GNU Compiler Collection
7324 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7325
7326 \end_inset
7327
7328  (
7329 \emph on
7330 gcc
7331 \emph default
7332  
7333 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7334
7335 \end_inset
7336
7337 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7338 4.1.1\InsetSpace ~
7339 CPP\InsetSpace ~
7340 Manual
7341  at 
7342 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7343
7344 \end_inset
7345
7346 .
7347 \end_layout
7348
7349 \begin_layout Standard
7350 \begin_inset VSpace bigskip
7351 \end_inset
7352
7353
7354 \end_layout
7355
7356 \begin_layout Subsection
7357 Linker Options
7358 \begin_inset LatexCommand \index{Options linker}
7359
7360 \end_inset
7361
7362
7363 \begin_inset LatexCommand \index{Linker options}
7364
7365 \end_inset
7366
7367
7368 \end_layout
7369
7370 \begin_layout List
7371 \labelwidthstring 00.00.0000
7372
7373 \series bold
7374 -L\InsetSpace ~
7375 -
7376 \series default
7377
7378 \begin_inset ERT
7379 status collapsed
7380
7381 \begin_layout Standard
7382
7383
7384 \backslash
7385 /
7386 \end_layout
7387
7388 \end_inset
7389
7390
7391 \series bold
7392 -lib-path
7393 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7394
7395 \end_inset
7396
7397
7398 \begin_inset LatexCommand \index{-L -\/-lib-path}
7399
7400 \end_inset
7401
7402
7403 \series default
7404 \InsetSpace ~
7405 <absolute path to additional libraries> This option is passed to the linkage
7406  editor's additional libraries
7407 \begin_inset LatexCommand \index{Libraries}
7408
7409 \end_inset
7410
7411  search path.
7412  The path name must be absolute.
7413  Additional library files may be specified in the command line.
7414  See section Compiling programs for more details.
7415 \end_layout
7416
7417 \begin_layout List
7418 \labelwidthstring 00.00.0000
7419
7420 \series bold
7421 -
7422 \begin_inset ERT
7423 status collapsed
7424
7425 \begin_layout Standard
7426
7427
7428 \backslash
7429 /
7430 \end_layout
7431
7432 \end_inset
7433
7434 -xram-loc
7435 \series default
7436
7437 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7438
7439 \end_inset
7440
7441 \InsetSpace ~
7442 <Value> The start location of the external ram
7443 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7444
7445 \end_inset
7446
7447 , default value is 0.
7448  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7449 \begin_inset ERT
7450 status collapsed
7451
7452 \begin_layout Standard
7453
7454
7455 \backslash
7456 /
7457 \end_layout
7458
7459 \end_inset
7460
7461 -xram-loc 0x8000 or -
7462 \begin_inset ERT
7463 status collapsed
7464
7465 \begin_layout Standard
7466
7467
7468 \backslash
7469 /
7470 \end_layout
7471
7472 \end_inset
7473
7474 -xram-loc 32768.
7475 \end_layout
7476
7477 \begin_layout List
7478 \labelwidthstring 00.00.0000
7479
7480 \series bold
7481 -
7482 \begin_inset ERT
7483 status collapsed
7484
7485 \begin_layout Standard
7486
7487
7488 \backslash
7489 /
7490 \end_layout
7491
7492 \end_inset
7493
7494 -code-loc
7495 \series default
7496
7497 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7498
7499 \end_inset
7500
7501 \InsetSpace ~
7502 <Value> The start location of the code
7503 \begin_inset LatexCommand \index{code}
7504
7505 \end_inset
7506
7507  segment, default value 0.
7508  Note when this option is used the interrupt vector table
7509 \begin_inset LatexCommand \index{interrupt vector table}
7510
7511 \end_inset
7512
7513  is also relocated to the given address.
7514  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7515 \begin_inset ERT
7516 status collapsed
7517
7518 \begin_layout Standard
7519
7520
7521 \backslash
7522 /
7523 \end_layout
7524
7525 \end_inset
7526
7527 -code-loc 0x8000 or -
7528 \begin_inset ERT
7529 status collapsed
7530
7531 \begin_layout Standard
7532
7533
7534 \backslash
7535 /
7536 \end_layout
7537
7538 \end_inset
7539
7540 -code-loc 32768.
7541 \end_layout
7542
7543 \begin_layout List
7544 \labelwidthstring 00.00.0000
7545
7546 \series bold
7547 -
7548 \begin_inset ERT
7549 status collapsed
7550
7551 \begin_layout Standard
7552
7553
7554 \backslash
7555 /
7556 \end_layout
7557
7558 \end_inset
7559
7560 -stack-loc
7561 \series default
7562
7563 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7564
7565 \end_inset
7566
7567 \InsetSpace ~
7568 <Value> By default the stack
7569 \begin_inset LatexCommand \index{stack}
7570
7571 \end_inset
7572
7573  is placed after the data segment.
7574  Using this option the stack can be placed anywhere in the internal memory
7575  space of the 8051.
7576  The value entered can be in Hexadecimal or Decimal format, e.g.
7577  -
7578 \begin_inset ERT
7579 status collapsed
7580
7581 \begin_layout Standard
7582
7583
7584 \backslash
7585 /
7586 \end_layout
7587
7588 \end_inset
7589
7590 -stack-loc 0x20 or -
7591 \begin_inset ERT
7592 status collapsed
7593
7594 \begin_layout Standard
7595
7596
7597 \backslash
7598 /
7599 \end_layout
7600
7601 \end_inset
7602
7603 -stack-loc 32.
7604  Since the sp register is incremented before a push or call, the initial
7605  sp will be set to one byte prior the provided value.
7606  The provided value should not overlap any other memory areas such as used
7607  register banks or the data segment and with enough space for the current
7608  application.
7609  The 
7610 \series bold
7611 -
7612 \begin_inset ERT
7613 status collapsed
7614
7615 \begin_layout Standard
7616
7617
7618 \backslash
7619 /
7620 \end_layout
7621
7622 \end_inset
7623
7624 -pack-iram
7625 \series default
7626 \InsetSpace ~
7627
7628 \begin_inset LatexCommand \index{-\/-pack-iram}
7629
7630 \end_inset
7631
7632  option (which is now a default setting) will override this setting, so
7633  you should also specify the 
7634 \series bold
7635 -
7636 \begin_inset ERT
7637 status collapsed
7638
7639 \begin_layout Standard
7640
7641
7642 \backslash
7643 /
7644 \end_layout
7645
7646 \end_inset
7647
7648 -no-pack-iram
7649 \series default
7650 \InsetSpace ~
7651
7652 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7653
7654 \end_inset
7655
7656  option if you need to manually place the stack.
7657 \end_layout
7658
7659 \begin_layout List
7660 \labelwidthstring 00.00.0000
7661
7662 \series bold
7663 -
7664 \begin_inset ERT
7665 status collapsed
7666
7667 \begin_layout Standard
7668
7669
7670 \backslash
7671 /
7672 \end_layout
7673
7674 \end_inset
7675
7676 -xstack-loc
7677 \series default
7678
7679 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7680
7681 \end_inset
7682
7683 \InsetSpace ~
7684 <Value> By default the external stack
7685 \begin_inset LatexCommand \index{xstack}
7686
7687 \end_inset
7688
7689  is placed after the pdata
7690 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7691
7692 \end_inset
7693
7694  segment.
7695  Using this option the xstack can be placed anywhere in the external memory
7696  space of the 8051.
7697  The value entered can be in Hexadecimal or Decimal format, e.g.
7698  -
7699 \begin_inset ERT
7700 status collapsed
7701
7702 \begin_layout Standard
7703
7704
7705 \backslash
7706 /
7707 \end_layout
7708
7709 \end_inset
7710
7711 -xstack-loc 0x8000 or -
7712 \begin_inset ERT
7713 status collapsed
7714
7715 \begin_layout Standard
7716
7717
7718 \backslash
7719 /
7720 \end_layout
7721
7722 \end_inset
7723
7724 -stack-loc 32768.
7725  The provided value should not overlap any other memory areas such as the
7726  pdata or xdata segment and with enough space for the current application.
7727 \end_layout
7728
7729 \begin_layout List
7730 \labelwidthstring 00.00.0000
7731
7732 \series bold
7733 -
7734 \begin_inset ERT
7735 status collapsed
7736
7737 \begin_layout Standard
7738
7739
7740 \backslash
7741 /
7742 \end_layout
7743
7744 \end_inset
7745
7746 -data-loc
7747 \series default
7748
7749 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7750
7751 \end_inset
7752
7753 \InsetSpace ~
7754 <Value> The start location of the internal ram data
7755 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7756
7757 \end_inset
7758
7759  segment.
7760  The value entered can be in Hexadecimal or Decimal format, eg.
7761  -
7762 \begin_inset ERT
7763 status collapsed
7764
7765 \begin_layout Standard
7766
7767
7768 \backslash
7769 /
7770 \end_layout
7771
7772 \end_inset
7773
7774 -data-loc 0x20 or -
7775 \begin_inset ERT
7776 status collapsed
7777
7778 \begin_layout Standard
7779
7780
7781 \backslash
7782 /
7783 \end_layout
7784
7785 \end_inset
7786
7787 -data-loc 32.
7788  (By default, the start location of the internal ram data segment  is set
7789  as low as possible in memory, taking into account the used register banks
7790  and the bit segment at address 0x20.
7791  For example if register banks 0 and 1 are used without bit variables, the
7792  data segment will be set, if -
7793 \begin_inset ERT
7794 status collapsed
7795
7796 \begin_layout Standard
7797
7798
7799 \backslash
7800 /
7801 \end_layout
7802
7803 \end_inset
7804
7805 -data-loc is not used, to location 0x10.)
7806 \end_layout
7807
7808 \begin_layout List
7809 \labelwidthstring 00.00.0000
7810
7811 \series bold
7812 -
7813 \begin_inset ERT
7814 status collapsed
7815
7816 \begin_layout Standard
7817
7818
7819 \backslash
7820 /
7821 \end_layout
7822
7823 \end_inset
7824
7825 -idata-loc
7826 \series default
7827
7828 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7829
7830 \end_inset
7831
7832 \InsetSpace ~
7833 <Value> The start location of the indirectly addressable internal ram
7834 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7835
7836 \end_inset
7837
7838  of the 8051, default value is 0x80.
7839  The value entered can be in Hexadecimal or Decimal format, eg.
7840  -
7841 \begin_inset ERT
7842 status collapsed
7843
7844 \begin_layout Standard
7845
7846
7847 \backslash
7848 /
7849 \end_layout
7850
7851 \end_inset
7852
7853 -idata-loc 0x88 or -
7854 \begin_inset ERT
7855 status collapsed
7856
7857 \begin_layout Standard
7858
7859
7860 \backslash
7861 /
7862 \end_layout
7863
7864 \end_inset
7865
7866 -idata-loc 136.
7867 \end_layout
7868
7869 \begin_layout List
7870 \labelwidthstring 00.00.0000
7871
7872 \series bold
7873 -
7874 \begin_inset ERT
7875 status collapsed
7876
7877 \begin_layout Standard
7878
7879
7880 \backslash
7881 /
7882 \end_layout
7883
7884 \end_inset
7885
7886 -bit-loc
7887 \series default
7888 \InsetSpace ~
7889 <Value> The start location of the bit
7890 \begin_inset LatexCommand \index{bit}
7891
7892 \end_inset
7893
7894  addressable internal ram of the 8051.
7895  This is 
7896 \emph on
7897 not
7898 \emph default
7899  implemented yet.
7900  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7901 -bBSEG=<Value>.
7902 \end_layout
7903
7904 \begin_layout List
7905 \labelwidthstring 00.00.0000
7906
7907 \series bold
7908 -
7909 \begin_inset ERT
7910 status collapsed
7911
7912 \begin_layout Standard
7913
7914
7915 \backslash
7916 /
7917 \end_layout
7918
7919 \end_inset
7920
7921 -out-fmt-ihx
7922 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7923
7924 \end_inset
7925
7926
7927 \bar under
7928  
7929 \series default
7930 \bar default
7931 The linker output (final object code) is in Intel Hex format.
7932 \begin_inset LatexCommand \index{Intel hex format}
7933
7934 \end_inset
7935
7936  This is the default option.
7937  The format itself is documented in the documentation of srecord
7938 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7939
7940 \end_inset
7941
7942 .
7943 \end_layout
7944
7945 \begin_layout List
7946 \labelwidthstring 00.00.0000
7947
7948 \series bold
7949 -
7950 \begin_inset ERT
7951 status collapsed
7952
7953 \begin_layout Standard
7954
7955
7956 \backslash
7957 /
7958 \end_layout
7959
7960 \end_inset
7961
7962 -out-fmt-s19
7963 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7964
7965 \end_inset
7966
7967
7968 \bar under
7969  
7970 \series default
7971 \bar default
7972 The linker output (final object code) is in Motorola S19 format
7973 \begin_inset LatexCommand \index{Motorola S19 format}
7974
7975 \end_inset
7976
7977 .
7978  The format itself is documented in the documentation of srecord.
7979 \end_layout
7980
7981 \begin_layout List
7982 \labelwidthstring 00.00.0000
7983
7984 \series bold
7985 -
7986 \begin_inset ERT
7987 status collapsed
7988
7989 \begin_layout Standard
7990
7991
7992 \backslash
7993 /
7994 \end_layout
7995
7996 \end_inset
7997
7998 -out-fmt-elf
7999 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
8000
8001 \end_inset
8002
8003
8004 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
8005
8006 \end_inset
8007
8008
8009 \bar under
8010  
8011 \series default
8012 \bar default
8013 The linker output (final object code) is in ELF format
8014 \begin_inset LatexCommand \index{ELF format}
8015
8016 \end_inset
8017
8018 .
8019  (Currently only supported for the HC08
8020 \begin_inset LatexCommand \index{HC08}
8021
8022 \end_inset
8023
8024  processors)
8025 \end_layout
8026
8027 \begin_layout List
8028 \labelwidthstring 00.00.0000
8029
8030 \series bold
8031 -Wl\InsetSpace ~
8032 linkOption[,linkOption]
8033 \series default
8034
8035 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8036
8037 \end_inset
8038
8039
8040 \begin_inset LatexCommand \label{lyx:-Wl option}
8041
8042 \end_inset
8043
8044 ...
8045  Pass the linkOption to the linker.
8046  If a bootloader is used an option like 
8047 \begin_inset Quotes sld
8048 \end_inset
8049
8050 -Wl\InsetSpace ~
8051 -bCSEG=0x1000
8052 \begin_inset Quotes srd
8053 \end_inset
8054
8055  would be typical to set the start of the code segment.
8056  Either use the double quotes around this option or use no space (e.g.
8057  -Wl-bCSEG=0x1000).
8058  See also #pragma constseg and #pragma codeseg in section 
8059 \begin_inset LatexCommand \ref{sec:Pragmas}
8060
8061 \end_inset
8062
8063  .
8064  File sdcc/as/doc/asxhtm.html has more on linker options.
8065 \end_layout
8066
8067 \begin_layout Standard
8068 \begin_inset VSpace bigskip
8069 \end_inset
8070
8071
8072 \end_layout
8073
8074 \begin_layout Subsection
8075 MCS51 Options
8076 \begin_inset LatexCommand \index{Options MCS51}
8077
8078 \end_inset
8079
8080
8081 \begin_inset LatexCommand \index{MCS51 options}
8082
8083 \end_inset
8084
8085
8086 \end_layout
8087
8088 \begin_layout List
8089 \labelwidthstring 00.00.0000
8090
8091 \series bold
8092 -
8093 \begin_inset ERT
8094 status collapsed
8095
8096 \begin_layout Standard
8097
8098
8099 \backslash
8100 /
8101 \end_layout
8102
8103 \end_inset
8104
8105 -model-small
8106 \begin_inset LatexCommand \index{-\/-model-small}
8107
8108 \end_inset
8109
8110
8111 \series default
8112 \size large
8113 \emph on
8114  
8115 \size default
8116 \emph default
8117 Generate code for Small Model programs, see section Memory Models for more
8118  details.
8119  This is the default model.
8120 \end_layout
8121
8122 \begin_layout List
8123 \labelwidthstring 00.00.0000
8124
8125 \series bold
8126 -
8127 \begin_inset ERT
8128 status collapsed
8129
8130 \begin_layout Standard
8131
8132
8133 \backslash
8134 /
8135 \end_layout
8136
8137 \end_inset
8138
8139 -model-medium
8140 \begin_inset LatexCommand \index{-\/-model-medium}
8141
8142 \end_inset
8143
8144
8145 \series default
8146  Generate code for Medium model programs, see section Memory Models for
8147  more details.
8148  If this option is used all source files in the project have to be compiled
8149  with this option.
8150  It must also be used when invoking the linker.
8151 \end_layout
8152
8153 \begin_layout List
8154 \labelwidthstring 00.00.0000
8155
8156 \series bold
8157 -
8158 \begin_inset ERT
8159 status collapsed
8160
8161 \begin_layout Standard
8162
8163
8164 \backslash
8165 /
8166 \end_layout
8167
8168 \end_inset
8169
8170 -model-large
8171 \begin_inset LatexCommand \index{-\/-model-large}
8172
8173 \end_inset
8174
8175
8176 \series default
8177  Generate code for Large model programs, see section Memory Models for more
8178  details.
8179  If this option is used all source files in the project have to be compiled
8180  with this option.
8181  It must also be used when invoking the linker.
8182 \end_layout
8183
8184 \begin_layout List
8185 \labelwidthstring 00.00.0000
8186
8187 \series bold
8188 -
8189 \begin_inset ERT
8190 status collapsed
8191
8192 \begin_layout Standard
8193
8194
8195 \backslash
8196 /
8197 \end_layout
8198
8199 \end_inset
8200
8201 -xstack
8202 \begin_inset LatexCommand \index{-\/-xstack}
8203
8204 \end_inset
8205
8206
8207 \series default
8208  Uses a pseudo stack in the pdata
8209 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8210
8211 \end_inset
8212
8213  area (usually the first 256 bytes in the external ram) for allocating variables
8214  and passing parameters.
8215  See section 
8216 \begin_inset LatexCommand \ref{sub:External-Stack}
8217
8218 \end_inset
8219
8220 \InsetSpace ~
8221  External Stack for more details.
8222 \end_layout
8223
8224 \begin_layout List
8225 \labelwidthstring 00.00.0000
8226
8227 \series bold
8228 -
8229 \begin_inset ERT
8230 status collapsed
8231
8232 \begin_layout Standard
8233
8234
8235 \backslash
8236 /
8237 \end_layout
8238
8239 \end_inset
8240
8241 -iram-size
8242 \series default
8243 \InsetSpace ~
8244 <Value>
8245 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8246
8247 \end_inset
8248
8249  Causes the linker to check if the internal ram usage is within limits of
8250  the given value.
8251 \end_layout
8252
8253 \begin_layout List
8254 \labelwidthstring 00.00.0000
8255
8256 \series bold
8257 -
8258 \begin_inset ERT
8259 status collapsed
8260
8261 \begin_layout Standard
8262
8263
8264 \backslash
8265 /
8266 \end_layout
8267
8268 \end_inset
8269
8270 -xram-size
8271 \series default
8272 \InsetSpace ~
8273 <Value>
8274 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8275
8276 \end_inset
8277
8278  Causes the linker to check if the external ram usage is within limits of
8279  the given value.
8280 \end_layout
8281
8282 \begin_layout List
8283 \labelwidthstring 00.00.0000
8284
8285 \series bold
8286 -
8287 \begin_inset ERT
8288 status collapsed
8289
8290 \begin_layout Standard
8291
8292
8293 \backslash
8294 /
8295 \end_layout
8296
8297 \end_inset
8298
8299 -code-size
8300 \series default
8301 \InsetSpace ~
8302 <Value>
8303 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8304
8305 \end_inset
8306
8307  Causes the linker to check if the code memory usage is within limits of
8308  the given value.
8309 \end_layout
8310
8311 \begin_layout List
8312 \labelwidthstring 00.00.0000
8313
8314 \series bold
8315 -
8316 \begin_inset ERT
8317 status collapsed
8318
8319 \begin_layout Standard
8320
8321
8322 \backslash
8323 /
8324 \end_layout
8325
8326 \end_inset
8327
8328 -stack-size
8329 \series default
8330 \InsetSpace ~
8331 <Value>
8332 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8333
8334 \end_inset
8335
8336  Causes the linker to check if there is at minimum <Value> bytes for stack.
8337 \end_layout
8338
8339 \begin_layout List
8340 \labelwidthstring 00.00.0000
8341
8342 \series bold
8343 -
8344 \begin_inset ERT
8345 status collapsed
8346
8347 \begin_layout Standard
8348
8349
8350 \backslash
8351 /
8352 \end_layout
8353
8354 \end_inset
8355
8356 -pack-iram
8357 \series default
8358 \InsetSpace ~
8359
8360 \begin_inset LatexCommand \index{-\/-pack-iram}
8361
8362 \end_inset
8363
8364  Causes the linker to use unused register banks for data variables and pack
8365  data, idata and stack together.
8366  This is the default now.
8367 \end_layout
8368
8369 \begin_layout List
8370 \labelwidthstring 00.00.0000
8371
8372 \series bold
8373 -
8374 \begin_inset ERT
8375 status collapsed
8376
8377 \begin_layout Standard
8378
8379
8380 \backslash
8381 /
8382 \end_layout
8383
8384 \end_inset
8385
8386 -no-pack-iram
8387 \series default
8388 \InsetSpace ~
8389
8390 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8391
8392 \end_inset
8393
8394  Causes the linker to use old style for allocating memory areas.
8395 \end_layout
8396
8397 \begin_layout List
8398 \labelwidthstring 00.00.0000
8399
8400 \series bold
8401 -
8402 \begin_inset ERT
8403 status collapsed
8404
8405 \begin_layout Standard
8406
8407
8408 \backslash
8409 /
8410 \end_layout
8411
8412 \end_inset
8413
8414 -acall-ajmp
8415 \series default
8416 \InsetSpace ~
8417
8418 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8419
8420 \end_inset
8421
8422  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8423  acall/ajmp.
8424  Only use this option if your code is in the same 2k block of memory.
8425  You may need to use this option for some 8051 derivatives which lack the
8426  lcall/ljmp instructions..
8427 \end_layout
8428
8429 \begin_layout Standard
8430 \begin_inset VSpace bigskip
8431 \end_inset
8432
8433
8434 \end_layout
8435
8436 \begin_layout Subsection
8437 DS390 / DS400 Options
8438 \begin_inset LatexCommand \index{Options DS390}
8439
8440 \end_inset
8441
8442
8443 \begin_inset LatexCommand \index{DS390}
8444
8445 \end_inset
8446
8447
8448 \end_layout
8449
8450 \begin_layout List
8451 \labelwidthstring 00.00.0000
8452
8453 \series bold
8454 -
8455 \begin_inset ERT
8456 status collapsed
8457
8458 \begin_layout Standard
8459
8460
8461 \backslash
8462 /
8463 \end_layout
8464
8465 \end_inset
8466
8467 -model-flat24
8468 \series default
8469
8470 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8471
8472 \end_inset
8473
8474
8475 \size large
8476 \emph on
8477  
8478 \size default
8479 \emph default
8480 Generate 24-bit flat mode code.
8481  This is the one and only that the ds390 code generator supports right now
8482  and is default when using 
8483 \emph on
8484 -mds390
8485 \emph default
8486 .
8487  See section Memory Models for more details.
8488 \end_layout
8489
8490 \begin_layout List
8491 \labelwidthstring 00.00.0000
8492
8493 \series bold
8494 -
8495 \begin_inset ERT
8496 status collapsed
8497
8498 \begin_layout Standard
8499
8500
8501 \backslash
8502 /
8503 \end_layout
8504
8505 \end_inset
8506
8507 -protect-sp-update
8508 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8509
8510 \end_inset
8511
8512
8513 \series default
8514  disable interrupts during ESP:SP updates.
8515 \end_layout
8516
8517 \begin_layout List
8518 \labelwidthstring 00.00.0000
8519
8520 \series bold
8521 -
8522 \begin_inset ERT
8523 status collapsed
8524
8525 \begin_layout Standard
8526
8527
8528 \backslash
8529 /
8530 \end_layout
8531
8532 \end_inset
8533
8534 -stack-10bit
8535 \series default
8536
8537 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8538
8539 \end_inset
8540
8541  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8542  This is the one and only that the ds390 code generator supports right now
8543  and is default when using 
8544 \emph on
8545 -mds390
8546 \emph default
8547 .
8548  In this mode, the stack is located in the lower 1K of the internal RAM,
8549  which is mapped to 0x400000.
8550  Note that the support is incomplete, since it still uses a single byte
8551  as the stack pointer.
8552  This means that only the lower 256 bytes of the potential 1K stack space
8553  will actually be used.
8554  However, this does allow you to reclaim the precious 256 bytes of low RAM
8555  for use for the DATA and IDATA segments.
8556  The compiler will not generate any code to put the processor into 10 bit
8557  stack mode.
8558  It is important to ensure that the processor is in this mode before calling
8559  any re-entrant functions compiled with this option.
8560  In principle, this should work with the 
8561 \emph on
8562 -
8563 \begin_inset ERT
8564 status collapsed
8565
8566 \begin_layout Standard
8567
8568
8569 \backslash
8570 /
8571 \end_layout
8572
8573 \end_inset
8574
8575 -stack-auto
8576 \begin_inset LatexCommand \index{-\/-stack-auto}
8577
8578 \end_inset
8579
8580
8581 \emph default
8582  option, but that has not been tested.
8583  It is incompatible with the 
8584 \emph on
8585 -
8586 \begin_inset ERT
8587 status collapsed
8588
8589 \begin_layout Standard
8590
8591
8592 \backslash
8593 /
8594 \end_layout
8595
8596 \end_inset
8597
8598 -xstack
8599 \begin_inset LatexCommand \index{-\/-xstack}
8600
8601 \end_inset
8602
8603
8604 \emph default
8605  option.
8606  It also only makes sense if the processor is in 24 bit contiguous addressing
8607  mode (see the 
8608 \emph on
8609 -
8610 \begin_inset ERT
8611 status collapsed
8612
8613 \begin_layout Standard
8614
8615
8616 \backslash
8617 /
8618 \end_layout
8619
8620 \end_inset
8621
8622 -model-flat24 option
8623 \emph default
8624 ).
8625 \series bold
8626
8627 \begin_inset Note Note
8628 status collapsed
8629
8630 \begin_layout List
8631 \labelwidthstring 00.00.0000
8632
8633 \series bold
8634 -
8635 \begin_inset ERT
8636 status open
8637
8638 \begin_layout Standard
8639
8640
8641 \backslash
8642 /
8643 \end_layout
8644
8645 \end_inset
8646
8647 -stack-8-bit - switches off the 10-bit mode
8648 \end_layout
8649
8650 \end_inset
8651
8652
8653 \end_layout
8654
8655 \begin_layout List
8656 \labelwidthstring 00.00.0000
8657
8658 \series bold
8659 -
8660 \begin_inset ERT
8661 status collapsed
8662
8663 \begin_layout Standard
8664
8665
8666 \backslash
8667 /
8668 \end_layout
8669
8670 \end_inset
8671
8672 -stack-probe
8673 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8674
8675 \end_inset
8676
8677
8678 \series default
8679  insert call to function __stack_probe at each function prologue.
8680 \end_layout
8681
8682 \begin_layout List
8683 \labelwidthstring 00.00.0000
8684
8685 \series bold
8686 -
8687 \begin_inset ERT
8688 status open
8689
8690 \begin_layout Standard
8691
8692
8693 \backslash
8694 /
8695 \end_layout
8696
8697 \end_inset
8698
8699 -tini-libid
8700 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8701
8702 \end_inset
8703
8704
8705 \series default
8706  <nnnn> LibraryID used in -mTININative.
8707  
8708 \end_layout
8709
8710 \begin_layout List
8711 \labelwidthstring 00.00.0000
8712
8713 \series bold
8714 -
8715 \begin_inset ERT
8716 status collapsed
8717
8718 \begin_layout Standard
8719
8720
8721 \backslash
8722 /
8723 \end_layout
8724
8725 \end_inset
8726
8727 -use-accelerator
8728 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8729
8730 \end_inset
8731
8732
8733 \series default
8734  generate code for DS390 Arithmetic Accelerator.
8735  
8736 \end_layout
8737
8738 \begin_layout Standard
8739 \begin_inset VSpace bigskip
8740 \end_inset
8741
8742
8743 \end_layout
8744
8745 \begin_layout Subsection
8746 Z80 Options
8747 \begin_inset LatexCommand \index{Options Z80}
8748
8749 \end_inset
8750
8751
8752 \begin_inset LatexCommand \index{Z80}
8753
8754 \end_inset
8755
8756
8757 \end_layout
8758
8759 \begin_layout List
8760 \labelwidthstring 00.00.0000
8761
8762 \series bold
8763 -
8764 \begin_inset ERT
8765 status collapsed
8766
8767 \begin_layout Standard
8768
8769
8770 \backslash
8771 /
8772 \end_layout
8773
8774 \end_inset
8775
8776 -callee-saves-bc
8777 \series default
8778
8779 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8780
8781 \end_inset
8782
8783
8784 \size large
8785 \emph on
8786  
8787 \size default
8788 \emph default
8789 Force a called function to always save BC.
8790 \end_layout
8791
8792 \begin_layout List
8793 \labelwidthstring 00.00.0000
8794
8795 \series bold
8796 -
8797 \begin_inset ERT
8798 status collapsed
8799
8800 \begin_layout Standard
8801
8802
8803 \backslash
8804 /
8805 \end_layout
8806
8807 \end_inset
8808
8809 -no-std-crt0
8810 \series default
8811
8812 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8813
8814 \end_inset
8815
8816  When linking, skip the standard crt0.o object file.
8817  You must provide your own crt0.o for your system when linking.
8818 \end_layout
8819
8820 \begin_layout List
8821 \labelwidthstring 00.00.0000
8822
8823 \series bold
8824 -
8825 \begin_inset ERT
8826 status collapsed
8827
8828 \begin_layout Standard
8829
8830
8831 \backslash
8832 /
8833 \end_layout
8834
8835 \end_inset
8836
8837 -portmode=
8838 \series default
8839 <Value>
8840 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8841
8842 \end_inset
8843
8844  Determinate PORT I/O mode (<Value> is z80 or z180).
8845 \end_layout
8846
8847 \begin_layout List
8848 \labelwidthstring 00.00.0000
8849
8850 \series bold
8851 -
8852 \begin_inset ERT
8853 status collapsed
8854
8855 \begin_layout Standard
8856
8857
8858 \backslash
8859 /
8860 \end_layout
8861
8862 \end_inset
8863
8864 -asm=
8865 \series default
8866 <Value>
8867 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8868
8869 \end_inset
8870
8871  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8872 \end_layout
8873
8874 \begin_layout List
8875 \labelwidthstring 00.00.0000
8876
8877 \series bold
8878 -
8879 \begin_inset ERT
8880 status collapsed
8881
8882 \begin_layout Standard
8883
8884
8885 \backslash
8886 /
8887 \end_layout
8888
8889 \end_inset
8890
8891 -codeseg
8892 \series default
8893 \InsetSpace ~
8894 <Value>
8895 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8896
8897 \end_inset
8898
8899  Use <Value> for the code segment name.
8900 \end_layout
8901
8902 \begin_layout List
8903 \labelwidthstring 00.00.0000
8904
8905 \series bold
8906 -
8907 \begin_inset ERT
8908 status collapsed
8909
8910 \begin_layout Standard
8911
8912
8913 \backslash
8914 /
8915 \end_layout
8916
8917 \end_inset
8918
8919 -constseg
8920 \series default
8921 \InsetSpace ~
8922 <Value>
8923 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8924
8925 \end_inset
8926
8927  Use <Value> for the const segment name.
8928 \end_layout
8929
8930 \begin_layout List
8931 \labelwidthstring 00.00.0000
8932 \begin_inset VSpace bigskip
8933 \end_inset
8934
8935
8936 \end_layout
8937
8938 \begin_layout Subsection
8939 GBZ80 Options
8940 \begin_inset LatexCommand \index{Options GBZ80}
8941
8942 \end_inset
8943
8944
8945 \begin_inset LatexCommand \index{GBZ80}
8946
8947 \end_inset
8948
8949
8950 \end_layout
8951
8952 \begin_layout List
8953 \labelwidthstring 00.00.0000
8954
8955 \series bold
8956 -
8957 \begin_inset ERT
8958 status collapsed
8959
8960 \begin_layout Standard
8961
8962
8963 \backslash
8964 /
8965 \end_layout
8966
8967 \end_inset
8968
8969 -callee-saves-bc
8970 \series default
8971
8972 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8973
8974 \end_inset
8975
8976
8977 \size large
8978 \emph on
8979  
8980 \size default
8981 \emph default
8982 Force a called function to always save BC.
8983 \end_layout
8984
8985 \begin_layout List
8986 \labelwidthstring 00.00.0000
8987
8988 \series bold
8989 -
8990 \begin_inset ERT
8991 status collapsed
8992
8993 \begin_layout Standard
8994
8995
8996 \backslash
8997 /
8998 \end_layout
8999
9000 \end_inset
9001
9002 -no-std-crt0
9003 \series default
9004
9005 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
9006
9007 \end_inset
9008
9009  When linking, skip the standard crt0.o object file.
9010  You must provide your own crt0.o for your system when linking.
9011 \end_layout
9012
9013 \begin_layout List
9014 \labelwidthstring 00.00.0000
9015
9016 \series bold
9017 -bo
9018 \series default
9019 \InsetSpace ~
9020 <Num>
9021 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9022
9023 \end_inset
9024
9025  Use code bank <Num>.
9026 \end_layout
9027
9028 \begin_layout List
9029 \labelwidthstring 00.00.0000
9030
9031 \series bold
9032 -ba
9033 \series default
9034 \InsetSpace ~
9035 <Num>
9036 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9037
9038 \end_inset
9039
9040  Use data bank <Num>.
9041 \end_layout
9042
9043 \begin_layout List
9044 \labelwidthstring 00.00.0000
9045
9046 \series bold
9047 -
9048 \begin_inset ERT
9049 status collapsed
9050
9051 \begin_layout Standard
9052
9053
9054 \backslash
9055 /
9056 \end_layout
9057
9058 \end_inset
9059
9060 -codeseg
9061 \series default
9062 \InsetSpace ~
9063 <Value>
9064 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9065
9066 \end_inset
9067
9068  Use <Value> for the code segment name.
9069 \end_layout
9070
9071 \begin_layout List
9072 \labelwidthstring 00.00.0000
9073
9074 \series bold
9075 -
9076 \begin_inset ERT
9077 status collapsed
9078
9079 \begin_layout Standard
9080
9081
9082 \backslash
9083 /
9084 \end_layout
9085
9086 \end_inset
9087
9088 -constseg
9089 \series default
9090 \InsetSpace ~
9091 <Value>
9092 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9093
9094 \end_inset
9095
9096  Use <Value> for the const segment name.
9097 \end_layout
9098
9099 \begin_layout Standard
9100 \begin_inset VSpace bigskip
9101 \end_inset
9102
9103
9104 \end_layout
9105
9106 \begin_layout Subsection
9107 Optimization Options
9108 \begin_inset LatexCommand \index{Options optimization}
9109
9110 \end_inset
9111
9112
9113 \begin_inset LatexCommand \index{Optimization options}
9114
9115 \end_inset
9116
9117
9118 \end_layout
9119
9120 \begin_layout List
9121 \labelwidthstring 00.00.0000
9122
9123 \series bold
9124 -
9125 \begin_inset ERT
9126 status collapsed
9127
9128 \begin_layout Standard
9129
9130
9131 \backslash
9132 /
9133 \end_layout
9134
9135 \end_inset
9136
9137 -nogcse
9138 \begin_inset LatexCommand \index{-\/-nogcse}
9139
9140 \end_inset
9141
9142
9143 \series default
9144  Will not do global subexpression elimination, this option may be used when
9145  the compiler creates undesirably large stack/data spaces to store compiler
9146  temporaries (
9147 \emph on
9148 s
9149 \emph default
9150 pill 
9151 \emph on
9152 loc
9153 \emph default
9154 ations, sloc
9155 \begin_inset LatexCommand \index{sloc (spill location)}
9156
9157 \end_inset
9158
9159 ).
9160  A warning message will be generated when this happens and the compiler
9161  will indicate the number of extra bytes it allocated.
9162  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9163 nogcse
9164 \begin_inset LatexCommand \index{\#pragma nogcse}
9165
9166 \end_inset
9167
9168  can be used to turn off global subexpression elimination
9169 \begin_inset LatexCommand \index{Subexpression elimination}
9170
9171 \end_inset
9172
9173  for a given function only.
9174 \end_layout
9175
9176 \begin_layout List
9177 \labelwidthstring 00.00.0000
9178
9179 \series bold
9180 -
9181 \begin_inset ERT
9182 status collapsed
9183
9184 \begin_layout Standard
9185
9186
9187 \backslash
9188 /
9189 \end_layout
9190
9191 \end_inset
9192
9193 -noinvariant
9194 \begin_inset LatexCommand \index{-\/-noinvariant}
9195
9196 \end_inset
9197
9198
9199 \series default
9200  Will not do loop invariant optimizations, this may be turned off for reasons
9201  explained for the previous option.
9202  For more details of loop optimizations performed see Loop Invariants in
9203  section 
9204 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9205
9206 \end_inset
9207
9208 .
9209  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9210 noinvariant
9211 \begin_inset LatexCommand \index{\#pragma noinvariant}
9212
9213 \end_inset
9214
9215  can be used to turn off invariant optimizations for a given function only.
9216 \end_layout
9217
9218 \begin_layout List
9219 \labelwidthstring 00.00.0000
9220
9221 \series bold
9222 -
9223 \begin_inset ERT
9224 status collapsed
9225
9226 \begin_layout Standard
9227
9228
9229 \backslash
9230 /
9231 \end_layout
9232
9233 \end_inset
9234
9235 -noinduction
9236 \begin_inset LatexCommand \index{-\/-noinduction}
9237
9238 \end_inset
9239
9240
9241 \series default
9242  Will not do loop induction optimizations, see section strength reduction
9243  for more details.
9244  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9245 noinduction
9246 \begin_inset LatexCommand \index{\#pragma noinduction}
9247
9248 \end_inset
9249
9250  can be used to turn off induction optimizations for a given function only.
9251 \end_layout
9252
9253 \begin_layout List
9254 \labelwidthstring 00.00.0000
9255
9256 \series bold
9257 -
9258 \begin_inset ERT
9259 status collapsed
9260
9261 \begin_layout Standard
9262
9263
9264 \backslash
9265 /
9266 \end_layout
9267
9268 \end_inset
9269
9270 -nojtbound
9271 \begin_inset LatexCommand \index{-\/-nojtbound}
9272
9273 \end_inset
9274
9275
9276 \size large
9277 \bar under
9278  
9279 \series default
9280 \size default
9281 \bar default
9282  Will not generate boundary condition check when switch statements
9283 \begin_inset LatexCommand \index{switch statement}
9284
9285 \end_inset
9286
9287  are implemented using jump-tables.
9288  See section 
9289 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9290
9291 \end_inset
9292
9293 \InsetSpace ~
9294 Switch Statements for more details.
9295  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9296 nojtbound
9297 \begin_inset LatexCommand \index{\#pragma nojtbound}
9298
9299 \end_inset
9300
9301  can be used to turn off boundary checking for jump tables for a given function
9302  only.
9303 \end_layout
9304
9305 \begin_layout List
9306 \labelwidthstring 00.00.0000
9307
9308 \series bold
9309 -
9310 \begin_inset ERT
9311 status collapsed
9312
9313 \begin_layout Standard
9314
9315
9316 \backslash
9317 /
9318 \end_layout
9319
9320 \end_inset
9321
9322 -noloopreverse
9323 \begin_inset LatexCommand \index{-\/-noloopreverse}
9324
9325 \end_inset
9326
9327
9328 \series default
9329 \size large
9330  
9331 \size default
9332 Will not do loop reversal 
9333 \begin_inset LatexCommand \index{Loop reversing}
9334
9335 \end_inset
9336
9337 optimization.
9338 \end_layout
9339
9340 \begin_layout List
9341 \labelwidthstring 00.00.0000
9342 -
9343 \begin_inset ERT
9344 status collapsed
9345
9346 \begin_layout Standard
9347
9348
9349 \backslash
9350 /
9351 \end_layout
9352
9353 \end_inset
9354
9355 -
9356 \series bold
9357 nolabelopt
9358 \series default
9359  
9360 \begin_inset LatexCommand \index{-\/-nolabelopt }
9361
9362 \end_inset
9363
9364 Will not optimize labels (makes the dumpfiles more readable).
9365 \end_layout
9366
9367 \begin_layout List
9368 \labelwidthstring 00.00.0000
9369
9370 \series bold
9371 -
9372 \begin_inset ERT
9373 status collapsed
9374
9375 \begin_layout Standard
9376
9377
9378 \backslash
9379 /
9380 \end_layout
9381
9382 \end_inset
9383
9384 -no-xinit-opt
9385 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9386
9387 \end_inset
9388
9389
9390 \series default
9391  Will not memcpy initialized data from code space into xdata space.
9392  This saves a few bytes in code space if you don't have initialized data
9393 \begin_inset LatexCommand \index{Variable initialization}
9394
9395 \end_inset
9396
9397 .
9398 \end_layout
9399
9400 \begin_layout List
9401 \labelwidthstring 00.00.0000
9402
9403 \series bold
9404 -
9405 \begin_inset ERT
9406 status collapsed
9407
9408 \begin_layout Standard
9409
9410
9411 \backslash
9412 /
9413 \end_layout
9414
9415 \end_inset
9416
9417 -nooverlay
9418 \begin_inset LatexCommand \index{-\/-nooverlay}
9419
9420 \end_inset
9421
9422
9423 \series default
9424   The compiler will not overlay parameters and local variables of any function,
9425  see section Parameters and local variables for more details.
9426 \end_layout
9427
9428 \begin_layout List
9429 \labelwidthstring 00.00.0000
9430
9431 \series bold
9432 -
9433 \begin_inset ERT
9434 status collapsed
9435
9436 \begin_layout Standard
9437
9438
9439 \backslash
9440 /
9441 \end_layout
9442
9443 \end_inset
9444
9445 -no-peep
9446 \begin_inset LatexCommand \index{-\/-no-peep}
9447
9448 \end_inset
9449
9450
9451 \series default
9452  Disable peep-hole optimization with built-in rules.
9453 \end_layout
9454
9455 \begin_layout List
9456 \labelwidthstring 00.00.0000
9457
9458 \series bold
9459 -
9460 \begin_inset ERT
9461 status collapsed
9462
9463 \begin_layout Standard
9464
9465
9466 \backslash
9467 /
9468 \end_layout
9469
9470 \end_inset
9471
9472 -peep-file
9473 \series default
9474
9475 \begin_inset LatexCommand \index{-\/-peep-file}
9476
9477 \end_inset
9478
9479 \InsetSpace ~
9480 <filename> This option can be used to use additional rules to be used by
9481  the peep hole optimizer.
9482  See section 
9483 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9484
9485 \end_inset
9486
9487 \InsetSpace ~
9488 Peep Hole optimizations for details on how to write these rules.
9489 \end_layout
9490
9491 \begin_layout List
9492 \labelwidthstring 00.00.0000
9493
9494 \series bold
9495 -
9496 \begin_inset ERT
9497 status collapsed
9498
9499 \begin_layout Standard
9500
9501
9502 \backslash
9503 /
9504 \end_layout
9505
9506 \end_inset
9507
9508 -peep-asm
9509 \begin_inset LatexCommand \index{-\/-peep-asm}
9510
9511 \end_inset
9512
9513
9514 \series default
9515  Pass the inline assembler code through the peep hole optimizer.
9516  This can cause unexpected changes to inline assembler code, please go through
9517  the peephole optimizer
9518 \begin_inset LatexCommand \index{Peephole optimizer}
9519
9520 \end_inset
9521
9522  rules defined in the source file tree '<target>/peeph.def' before using
9523  this option.
9524 \end_layout
9525
9526 \begin_layout List
9527 \labelwidthstring 00.00.0000
9528
9529 \series bold
9530 -
9531 \begin_inset ERT
9532 status collapsed
9533
9534 \begin_layout Standard
9535
9536
9537 \backslash
9538 /
9539 \end_layout
9540
9541 \end_inset
9542
9543 -opt-code-speed
9544 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9545
9546 \end_inset
9547
9548
9549 \series default
9550  The compiler will optimize code generation towards fast code, possibly
9551  at the expense of code size.
9552 \end_layout
9553
9554 \begin_layout List
9555 \labelwidthstring 00.00.0000
9556
9557 \series bold
9558 -
9559 \begin_inset ERT
9560 status collapsed
9561
9562 \begin_layout Standard
9563
9564
9565 \backslash
9566 /
9567 \end_layout
9568
9569 \end_inset
9570
9571 -opt-code-size
9572 \begin_inset LatexCommand \index{-\/-opt-code-size}
9573
9574 \end_inset
9575
9576
9577 \series default
9578  The compiler will optimize code generation towards compact code, possibly
9579  at the expense of code speed.
9580 \end_layout
9581
9582 \begin_layout Standard
9583 \begin_inset VSpace bigskip
9584 \end_inset
9585
9586
9587 \end_layout
9588
9589 \begin_layout Subsection
9590 Other Options
9591 \begin_inset LatexCommand \index{Options other}
9592
9593 \end_inset
9594
9595
9596 \end_layout
9597
9598 \begin_layout List
9599 \labelwidthstring 00.00.0000
9600
9601 \series bold
9602 -c\InsetSpace ~
9603 -
9604 \begin_inset ERT
9605 status collapsed
9606
9607 \begin_layout Standard
9608
9609
9610 \backslash
9611 /
9612 \end_layout
9613
9614 \end_inset
9615
9616 -compile-only
9617 \begin_inset LatexCommand \index{-\/-compile-only}
9618
9619 \end_inset
9620
9621
9622 \begin_inset LatexCommand \index{-c -\/-compile-only}
9623
9624 \end_inset
9625
9626
9627 \series default
9628  will compile and assemble the source, but will not call the linkage editor.
9629 \end_layout
9630
9631 \begin_layout List
9632 \labelwidthstring 00.00.0000
9633
9634 \series bold
9635 -
9636 \series default
9637
9638 \begin_inset ERT
9639 status collapsed
9640
9641 \begin_layout Standard
9642
9643
9644 \backslash
9645 /
9646 \end_layout
9647
9648 \end_inset
9649
9650
9651 \series bold
9652 -c1mode
9653 \begin_inset LatexCommand \index{-\/-c1mode}
9654
9655 \end_inset
9656
9657
9658 \series default
9659  reads the preprocessed source from standard input and compiles it.
9660  The file name for the assembler output must be specified using the -o option.
9661 \end_layout
9662
9663 \begin_layout List
9664 \labelwidthstring 00.00.0000
9665
9666 \series bold
9667 -E
9668 \begin_inset LatexCommand \index{-E}
9669
9670 \end_inset
9671
9672
9673 \series default
9674  Run only the C preprocessor.
9675  Preprocess all the C source files specified and output the results to standard
9676  output.
9677 \end_layout
9678
9679 \begin_layout List
9680 \labelwidthstring 00.00.0000
9681
9682 \series bold
9683 -o\InsetSpace ~
9684 <path/file>
9685 \begin_inset LatexCommand \index{-o <path/file>}
9686
9687 \end_inset
9688
9689  
9690 \series default
9691 The output path where everything will be placed or the file name used for
9692  all generated output files.
9693  If the parameter is a path, it must have a trailing slash (or backslash
9694  for the Windows binaries) to be recognized as a path.
9695
9696 \emph on
9697  
9698 \emph default
9699 Note for Windows users: if the path contains spaces, it should be surrounded
9700  by quotes.
9701  The trailing backslash should be doubled in order to prevent escaping the
9702  final quote, for example: 
9703 \emph on
9704 -o 
9705 \begin_inset Quotes sld
9706 \end_inset
9707
9708 F:
9709 \backslash
9710 Projects
9711 \backslash
9712 test3
9713 \backslash
9714 output 1
9715 \backslash
9716
9717 \backslash
9718
9719 \begin_inset Quotes srd
9720 \end_inset
9721
9722
9723 \emph default
9724  or put after the final quote, for example: 
9725 \emph on
9726 -o 
9727 \begin_inset Quotes sld
9728 \end_inset
9729
9730 F:
9731 \backslash
9732 Projects
9733 \backslash
9734 test3
9735 \backslash
9736 output 1
9737 \begin_inset Quotes srd
9738 \end_inset
9739
9740
9741 \backslash
9742
9743 \emph default
9744 .
9745  The path using slashes for directory delimiters can be used too, for example:
9746  
9747 \emph on
9748 -o 
9749 \begin_inset Quotes sld
9750 \end_inset
9751
9752 F:/Projects/test3/output 1/
9753 \begin_inset Quotes srd
9754 \end_inset
9755
9756
9757 \emph default
9758 .
9759 \end_layout
9760
9761 \begin_layout List
9762 \labelwidthstring 00.00.0000
9763
9764 \series bold
9765 -
9766 \begin_inset ERT
9767 status collapsed
9768
9769 \begin_layout Standard
9770
9771
9772 \backslash
9773 /
9774 \end_layout
9775
9776 \end_inset
9777
9778 -stack-auto
9779 \begin_inset LatexCommand \index{-\/-stack-auto}
9780
9781 \end_inset
9782
9783
9784 \series default
9785 \size large
9786 \emph on
9787  
9788 \size default
9789 \emph default
9790 All functions in the source file will be compiled as 
9791 \emph on
9792 reentrant
9793 \emph default
9794
9795 \begin_inset LatexCommand \index{reentrant}
9796
9797 \end_inset
9798
9799 , i.e.
9800  the parameters and local variables will be allocated on the stack
9801 \begin_inset LatexCommand \index{stack}
9802
9803 \end_inset
9804
9805 .
9806  See section 
9807 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9808
9809 \end_inset
9810
9811  Parameters and Local Variables for more details.
9812  If this option is used all source files in the project should be compiled
9813  with this option.
9814  It automatically implies -
9815 \series bold
9816
9817 \begin_inset ERT
9818 status open
9819
9820 \begin_layout Standard
9821
9822
9823 \backslash
9824 /
9825 \end_layout
9826
9827 \end_inset
9828
9829
9830 \series default
9831 -int-long-reent and -
9832 \series bold
9833
9834 \begin_inset ERT
9835 status open
9836
9837 \begin_layout Standard
9838
9839
9840 \backslash
9841 /
9842 \end_layout
9843
9844 \end_inset
9845
9846
9847 \series default
9848 -float-reent.
9849  
9850 \end_layout
9851
9852 \begin_layout List
9853 \labelwidthstring 00.00.0000
9854
9855 \series bold
9856 -
9857 \begin_inset ERT
9858 status collapsed
9859
9860 \begin_layout Standard
9861
9862
9863 \backslash
9864 /
9865 \end_layout
9866
9867 \end_inset
9868
9869 -callee-saves
9870 \begin_inset LatexCommand \index{-\/-callee-saves}
9871
9872 \end_inset
9873
9874  
9875 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9876
9877 \end_inset
9878
9879 function1[,function2][,function3]....
9880
9881 \series default
9882  The compiler by default uses a caller saves convention for register saving
9883  across function calls, however this can cause unnecessary register pushing
9884  and popping when calling small functions from larger functions.
9885  This option can be used to switch the register saving convention for the
9886  function names specified.
9887  The compiler will not save registers when calling these functions, no extra
9888  code will be generated at the entry and exit (function prologue
9889 \series bold
9890
9891 \begin_inset LatexCommand \index{function prologue}
9892
9893 \end_inset
9894
9895
9896 \series default
9897  and epilogue
9898 \series bold
9899
9900 \begin_inset LatexCommand \index{function epilogue}
9901
9902 \end_inset
9903
9904
9905 \series default
9906 ) for these functions to save and restore the registers used by these functions,
9907  this can SUBSTANTIALLY reduce code and improve run time performance of
9908  the generated code.
9909  In the future the compiler (with inter procedural analysis) will be able
9910  to determine the appropriate scheme to use for each function call.
9911  DO NOT use this option for built-in functions such as _mulint..., if this
9912  option is used for a library function the appropriate library function
9913  needs to be recompiled with the same option.
9914  If the project consists of multiple source files then all the source file
9915  should be compiled with the same -
9916 \begin_inset ERT
9917 status collapsed
9918
9919 \begin_layout Standard
9920
9921
9922 \backslash
9923 /
9924 \end_layout
9925
9926 \end_inset
9927
9928 -callee-saves option string.
9929  Also see #pragma\InsetSpace ~
9930 callee_saves 
9931 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9932
9933 \end_inset
9934
9935  
9936 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9937
9938 \end_inset
9939
9940 .
9941 \end_layout
9942
9943 \begin_layout List
9944 \labelwidthstring 00.00.0000
9945
9946 \series bold
9947 -
9948 \begin_inset ERT
9949 status collapsed
9950
9951 \begin_layout Standard
9952
9953
9954 \backslash
9955 /
9956 \end_layout
9957
9958 \end_inset
9959
9960 -all-callee-saves
9961 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9962
9963 \end_inset
9964
9965  
9966 \series default
9967 Function of
9968 \series bold
9969  
9970 \series default
9971 -
9972 \begin_inset ERT
9973 status collapsed
9974
9975 \begin_layout Standard
9976
9977
9978 \backslash
9979 /
9980 \end_layout
9981
9982 \end_inset
9983
9984 -callee-saves will be applied to all functions by default.
9985 \end_layout
9986
9987 \begin_layout List
9988 \labelwidthstring 00.00.0000
9989
9990 \series bold
9991 -
9992 \begin_inset ERT
9993 status collapsed
9994
9995 \begin_layout Standard
9996
9997
9998 \backslash
9999 /
10000 \end_layout
10001
10002 \end_inset
10003
10004 -debug
10005 \begin_inset LatexCommand \index{-\/-debug}
10006
10007 \end_inset
10008
10009
10010 \bar under
10011  
10012 \series default
10013 \bar default
10014 When this option is used the compiler will generate debug information.
10015  The debug information collected in a file with .cdb extension can be used
10016  with the SDCDB.
10017  For more information see documentation for SDCDB.
10018  Another file with no extension contains debug information in AOMF or AOMF51
10019 \begin_inset LatexCommand \index{AOMF, AOMF51}
10020
10021 \end_inset
10022
10023  format which is commonly used by third party tools.
10024 \end_layout
10025
10026 \begin_layout List
10027 \labelwidthstring 00.00.0000
10028
10029 \series bold
10030 -S
10031 \begin_inset LatexCommand \index{-S}
10032
10033 \end_inset
10034
10035
10036 \size large
10037 \bar under
10038  
10039 \series default
10040 \size default
10041 \bar default
10042 Stop after the stage of compilation proper; do not assemble.
10043  The output is an assembler code file for the input file specified.
10044 \end_layout
10045
10046 \begin_layout List
10047 \labelwidthstring 00.00.0000
10048
10049 \series bold
10050 -
10051 \begin_inset ERT
10052 status collapsed
10053
10054 \begin_layout Standard
10055
10056
10057 \backslash
10058 /
10059 \end_layout
10060
10061 \end_inset
10062
10063 -int-long-reent
10064 \begin_inset LatexCommand \index{-\/-int-long-reent}
10065
10066 \end_inset
10067
10068
10069 \series default
10070  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10071  Note by default these libraries are compiled as non-reentrant.
10072  See section Installation for more details.
10073 \end_layout
10074
10075 \begin_layout List
10076 \labelwidthstring 00.00.0000
10077
10078 \series bold
10079 -
10080 \begin_inset ERT
10081 status collapsed
10082
10083 \begin_layout Standard
10084
10085
10086 \backslash
10087 /
10088 \end_layout
10089
10090 \end_inset
10091
10092 -cyclomatic
10093 \begin_inset LatexCommand \index{-\/-cyclomatic}
10094
10095 \end_inset
10096
10097
10098 \bar under
10099  
10100 \series default
10101 \bar default
10102 This option will cause the compiler to generate an information message for
10103  each function in the source file.
10104  The message contains some 
10105 \emph on
10106 important
10107 \emph default
10108  information about the function.
10109  The number of edges and nodes the compiler detected in the control flow
10110  graph of the function, and most importantly the 
10111 \emph on
10112 cyclomatic complexity
10113 \begin_inset LatexCommand \index{Cyclomatic complexity}
10114
10115 \end_inset
10116
10117
10118 \emph default
10119  see section on Cyclomatic Complexity for more details.
10120 \end_layout
10121
10122 \begin_layout List
10123 \labelwidthstring 00.00.0000
10124
10125 \series bold
10126 -
10127 \begin_inset ERT
10128 status collapsed
10129
10130 \begin_layout Standard
10131
10132
10133 \backslash
10134 /
10135 \end_layout
10136
10137 \end_inset
10138
10139 -float-reent
10140 \begin_inset LatexCommand \index{-\/-float-reent}
10141
10142 \end_inset
10143
10144
10145 \series default
10146  Floating point library is compiled as reentrant
10147 \begin_inset LatexCommand \index{reentrant}
10148
10149 \end_inset
10150
10151 .
10152  See section Installation for more details.
10153 \end_layout
10154
10155 \begin_layout List
10156 \labelwidthstring 00.00.0000
10157
10158 \series bold
10159 -
10160 \begin_inset ERT
10161 status collapsed
10162
10163 \begin_layout Standard
10164
10165
10166 \backslash
10167 /
10168 \end_layout
10169
10170 \end_inset
10171
10172 -funsigned-char
10173 \begin_inset LatexCommand \index{-\/-funsigned-char}
10174
10175 \end_inset
10176
10177
10178 \series default
10179  The default signedness for every type is
10180 \family typewriter
10181  signed
10182 \family default
10183 .
10184  In some embedded environments the default signedness of
10185 \family typewriter
10186  char
10187 \family default
10188  is
10189 \family typewriter
10190  unsigned
10191 \family default
10192 .
10193  To set the signess for characters to unsigned, use the option -
10194 \series bold
10195
10196 \begin_inset ERT
10197 status open
10198
10199 \begin_layout Standard
10200
10201
10202 \backslash
10203 /
10204 \end_layout
10205
10206 \end_inset
10207
10208
10209 \series default
10210 -funsigned-char.
10211  If this option is set and no signedness keyword (unsigned/signed) is given,
10212  a char will be signed.
10213  All other types are unaffected.
10214 \end_layout
10215
10216 \begin_layout List
10217 \labelwidthstring 00.00.0000
10218
10219 \series bold
10220 -
10221 \begin_inset ERT
10222 status collapsed
10223
10224 \begin_layout Standard
10225
10226
10227 \backslash
10228 /
10229 \end_layout
10230
10231 \end_inset
10232
10233 -main-return
10234 \begin_inset LatexCommand \index{-\/-main-return}
10235
10236 \end_inset
10237
10238
10239 \series default
10240  This option can be used if the code generated is called by a monitor program
10241  or if the main routine includes an endless loop.
10242  This option results in slightly smaller code and saves two bytes of stack
10243  space.
10244  The return from the 'main'
10245 \begin_inset LatexCommand \index{main return}
10246
10247 \end_inset
10248
10249  function will return to the function calling main.
10250  The default setting is to lock up i.e.
10251  generate a '
10252 \family typewriter
10253 sjmp .
10254 \family default
10255 '.
10256 \end_layout
10257
10258 \begin_layout List
10259 \labelwidthstring 00.00.0000
10260
10261 \series bold
10262 -
10263 \begin_inset ERT
10264 status collapsed
10265
10266 \begin_layout Standard
10267
10268
10269 \backslash
10270 /
10271 \end_layout
10272
10273 \end_inset
10274
10275 -nostdinc
10276 \begin_inset LatexCommand \index{-\/-nostdinc}
10277
10278 \end_inset
10279
10280
10281 \series default
10282  This will prevent the compiler from passing on the default include path
10283  to the preprocessor.
10284 \end_layout
10285
10286 \begin_layout List
10287 \labelwidthstring 00.00.0000
10288
10289 \series bold
10290 -
10291 \begin_inset ERT
10292 status collapsed
10293
10294 \begin_layout Standard
10295
10296
10297 \backslash
10298 /
10299 \end_layout
10300
10301 \end_inset
10302
10303 -nostdlib
10304 \begin_inset LatexCommand \index{-\/-nostdlib}
10305
10306 \end_inset
10307
10308
10309 \series default
10310  This will prevent the compiler from passing on the default library
10311 \begin_inset LatexCommand \index{Libraries}
10312
10313 \end_inset
10314
10315  path to the linker.
10316 \end_layout
10317
10318 \begin_layout List
10319 \labelwidthstring 00.00.0000
10320
10321 \series bold
10322 -
10323 \begin_inset ERT
10324 status collapsed
10325
10326 \begin_layout Standard
10327
10328
10329 \backslash
10330 /
10331 \end_layout
10332
10333 \end_inset
10334
10335 -verbose
10336 \begin_inset LatexCommand \index{-\/-verbose}
10337
10338 \end_inset
10339
10340
10341 \series default
10342  Shows the various actions the compiler is performing.
10343 \end_layout
10344
10345 \begin_layout List
10346 \labelwidthstring 00.00.0000
10347
10348 \series bold
10349 -V
10350 \begin_inset LatexCommand \index{-V}
10351
10352 \end_inset
10353
10354
10355 \series default
10356  Shows the actual commands the compiler is executing.
10357 \end_layout
10358
10359 \begin_layout List
10360 \labelwidthstring 00.00.0000
10361
10362 \series bold
10363 -
10364 \begin_inset ERT
10365 status collapsed
10366
10367 \begin_layout Standard
10368
10369
10370 \backslash
10371 /
10372 \end_layout
10373
10374 \end_inset
10375
10376 -no-c-code-in-asm
10377 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10378
10379 \end_inset
10380
10381
10382 \series default
10383  Hides your ugly and inefficient c-code from the asm file, so you can always
10384  blame the compiler :)
10385 \end_layout
10386
10387 \begin_layout List
10388 \labelwidthstring 00.00.0000
10389
10390 \series bold
10391 -
10392 \begin_inset ERT
10393 status collapsed
10394
10395 \begin_layout Standard
10396
10397
10398 \backslash
10399 /
10400 \end_layout
10401
10402 \end_inset
10403
10404 -fverbose-asm
10405 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10406
10407 \end_inset
10408
10409
10410 \series default
10411  Include code generator and peep-hole comments in the generated asm files.
10412 \end_layout
10413
10414 \begin_layout List
10415 \labelwidthstring 00.00.0000
10416
10417 \series bold
10418 -
10419 \begin_inset ERT
10420 status collapsed
10421
10422 \begin_layout Standard
10423
10424
10425 \backslash
10426 /
10427 \end_layout
10428
10429 \end_inset
10430
10431 -no-peep-comments
10432 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10433
10434 \end_inset
10435
10436
10437 \series default
10438  Don't include peep-hole comments in the generated asm files even if -
10439 \series bold
10440
10441 \begin_inset ERT
10442 status open
10443
10444 \begin_layout Standard
10445
10446
10447 \backslash
10448 /
10449 \end_layout
10450
10451 \end_inset
10452
10453
10454 \series default
10455 -fverbose-asm option is specified.
10456 \end_layout
10457
10458 \begin_layout List
10459 \labelwidthstring 00.00.0000
10460
10461 \series bold
10462 -
10463 \begin_inset ERT
10464 status collapsed
10465
10466 \begin_layout Standard
10467
10468
10469 \backslash
10470 /
10471 \end_layout
10472
10473 \end_inset
10474
10475 -i-code-in-asm
10476 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10477
10478 \end_inset
10479
10480
10481 \series default
10482  Include i-codes in the asm file.
10483  Sounds like noise but is most helpful for debugging the compiler itself.
10484 \end_layout
10485
10486 \begin_layout List
10487 \labelwidthstring 00.00.0000
10488
10489 \series bold
10490 -
10491 \begin_inset ERT
10492 status collapsed
10493
10494 \begin_layout Standard
10495
10496
10497 \backslash
10498 /
10499 \end_layout
10500
10501 \end_inset
10502
10503 -less-pedantic
10504 \begin_inset LatexCommand \index{pedantic}
10505
10506 \end_inset
10507
10508
10509 \begin_inset LatexCommand \index{-\/-less-pedantic}
10510
10511 \end_inset
10512
10513
10514 \series default
10515
10516 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10517
10518 \end_inset
10519
10520  Disable some of the more pedantic warnings
10521 \begin_inset LatexCommand \index{Warnings}
10522
10523 \end_inset
10524
10525 .
10526  For more details, see the less_pedantic pragma 
10527 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10528
10529 \end_inset
10530
10531 .
10532 \end_layout
10533
10534 \begin_layout List
10535 \labelwidthstring 00.00.0000
10536
10537 \series bold
10538 -
10539 \begin_inset ERT
10540 status collapsed
10541
10542 \begin_layout Standard
10543
10544
10545 \backslash
10546 /
10547 \end_layout
10548
10549 \end_inset
10550
10551 -disable-warning\InsetSpace ~
10552 <nnnn>
10553 \begin_inset LatexCommand \index{-\/-disable-warning}
10554
10555 \end_inset
10556
10557
10558 \series default
10559  Disable specific warning with number <nnnn>.
10560 \end_layout
10561
10562 \begin_layout List
10563 \labelwidthstring 00.00.0000
10564
10565 \series bold
10566 -
10567 \begin_inset ERT
10568 status collapsed
10569
10570 \begin_layout Standard
10571
10572
10573 \backslash
10574 /
10575 \end_layout
10576
10577 \end_inset
10578
10579 -Werror
10580 \begin_inset LatexCommand \index{-\/-Werror}
10581
10582 \end_inset
10583
10584
10585 \series default
10586  Treat all warnings as errors.
10587 \end_layout
10588
10589 \begin_layout List
10590 \labelwidthstring 00.00.0000
10591
10592 \series bold
10593 -
10594 \begin_inset ERT
10595 status collapsed
10596
10597 \begin_layout Standard
10598
10599
10600 \backslash
10601 /
10602 \end_layout
10603
10604 \end_inset
10605
10606 -print-search-dirs
10607 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10608
10609 \end_inset
10610
10611
10612 \series default
10613  Display the directories in the compiler's search path
10614 \end_layout
10615
10616 \begin_layout List
10617 \labelwidthstring 00.00.0000
10618
10619 \series bold
10620 -
10621 \begin_inset ERT
10622 status collapsed
10623
10624 \begin_layout Standard
10625
10626
10627 \backslash
10628 /
10629 \end_layout
10630
10631 \end_inset
10632
10633 -vc
10634 \begin_inset LatexCommand \index{-\/-vc}
10635
10636 \end_inset
10637
10638
10639 \series default
10640  Display errors and warnings using MSVC style, so you can use SDCC with
10641  the visual studio IDE
10642 \begin_inset LatexCommand \index{IDE}
10643
10644 \end_inset
10645
10646 .
10647  With SDCC both offering a GCC-like (the default) and a MSVC-like
10648 \begin_inset LatexCommand \index{MSVC output style}
10649
10650 \end_inset
10651
10652  output style, integration into most programming editors should be straightforwa
10653 rd.
10654 \end_layout
10655
10656 \begin_layout List
10657 \labelwidthstring 00.00.0000
10658
10659 \series bold
10660 -
10661 \begin_inset ERT
10662 status collapsed
10663
10664 \begin_layout Standard
10665
10666
10667 \backslash
10668 /
10669 \end_layout
10670
10671 \end_inset
10672
10673 -use-stdout
10674 \begin_inset LatexCommand \index{-\/-use-stdout}
10675
10676 \end_inset
10677
10678
10679 \series default
10680  Send errors and warnings to stdout instead of stderr.
10681 \end_layout
10682
10683 \begin_layout List
10684 \labelwidthstring 00.00.0000
10685
10686 \series bold
10687 -Wa\InsetSpace ~
10688 asmOption[,asmOption]
10689 \series default
10690
10691 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10692
10693 \end_inset
10694
10695 ...
10696  Pass the asmOption to the assembler
10697 \begin_inset LatexCommand \index{Options assembler}
10698
10699 \end_inset
10700
10701
10702 \begin_inset LatexCommand \index{Assembler options}
10703
10704 \end_inset
10705
10706 .
10707  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10708 \end_layout
10709
10710 \begin_layout List
10711 \labelwidthstring 00.00.0000
10712
10713 \series bold
10714 -
10715 \begin_inset ERT
10716 status collapsed
10717
10718 \begin_layout Standard
10719
10720
10721 \backslash
10722 /
10723 \end_layout
10724
10725 \end_inset
10726
10727 -std-sdcc89
10728 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10729
10730 \end_inset
10731
10732
10733 \series default
10734  Generally follow the C89 standard, but allow SDCC features that conflict
10735  with the standard (default).
10736 \end_layout
10737
10738 \begin_layout List
10739 \labelwidthstring 00.00.0000
10740
10741 \series bold
10742 -
10743 \begin_inset ERT
10744 status collapsed
10745
10746 \begin_layout Standard
10747
10748
10749 \backslash
10750 /
10751 \end_layout
10752
10753 \end_inset
10754
10755 -std-c89
10756 \begin_inset LatexCommand \index{-\/-std-c89}
10757
10758 \end_inset
10759
10760
10761 \series default
10762  Follow the C89 standard and disable SDCC features that conflict with the
10763  standard.
10764 \end_layout
10765
10766 \begin_layout List
10767 \labelwidthstring 00.00.0000
10768
10769 \series bold
10770 -
10771 \begin_inset ERT
10772 status collapsed
10773
10774 \begin_layout Standard
10775
10776
10777 \backslash
10778 /
10779 \end_layout
10780
10781 \end_inset
10782
10783 -std-sdcc99
10784 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10785
10786 \end_inset
10787
10788
10789 \series default
10790  Generally follow the C99 standard, but allow SDCC features that conflict
10791  with the standard (incomplete support).
10792 \end_layout
10793
10794 \begin_layout List
10795 \labelwidthstring 00.00.0000
10796
10797 \series bold
10798 -
10799 \begin_inset ERT
10800 status collapsed
10801
10802 \begin_layout Standard
10803
10804
10805 \backslash
10806 /
10807 \end_layout
10808
10809 \end_inset
10810
10811 -std-c99
10812 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10813
10814 \end_inset
10815
10816
10817 \series default
10818  Follow the C99 standard and disable SDCC features that conflict with the
10819  standard (incomplete support).
10820 \end_layout
10821
10822 \begin_layout List
10823 \labelwidthstring 00.00.0000
10824
10825 \series bold
10826 -
10827 \begin_inset ERT
10828 status collapsed
10829
10830 \begin_layout Standard
10831
10832
10833 \backslash
10834 /
10835 \end_layout
10836
10837 \end_inset
10838
10839 -codeseg
10840 \series default
10841
10842 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10843
10844 \end_inset
10845
10846
10847 \begin_inset LatexCommand \label{lyx:-codeseg}
10848
10849 \end_inset
10850
10851 \InsetSpace ~
10852 <Name> The name to be used for the code
10853 \begin_inset LatexCommand \index{code}
10854
10855 \end_inset
10856
10857  segment, default CSEG.
10858  This is useful if you need to tell the compiler to put the code in a special
10859  segment so you can later on tell the linker to put this segment in a special
10860  place in memory.
10861  Can be used for instance when using bank switching to put the code in a
10862  bank.
10863 \end_layout
10864
10865 \begin_layout List
10866 \labelwidthstring 00.00.0000
10867
10868 \series bold
10869 -
10870 \begin_inset ERT
10871 status collapsed
10872
10873 \begin_layout Standard
10874
10875
10876 \backslash
10877 /
10878 \end_layout
10879
10880 \end_inset
10881
10882 -constseg
10883 \series default
10884
10885 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10886
10887 \end_inset
10888
10889 \InsetSpace ~
10890 <Name> The name to be used for the const
10891 \begin_inset LatexCommand \index{const}
10892
10893 \end_inset
10894
10895  segment, default CONST.
10896  This is useful if you need to tell the compiler to put the const data in
10897  a special segment so you can later on tell the linker to put this segment
10898  in a special place in memory.
10899  Can be used for instance when using bank switching to put the const data
10900  in a bank.
10901 \end_layout
10902
10903 \begin_layout List
10904 \labelwidthstring 00.00.0000
10905
10906 \series bold
10907 -
10908 \begin_inset ERT
10909 status collapsed
10910
10911 \begin_layout Standard
10912
10913
10914 \backslash
10915 /
10916 \end_layout
10917
10918 \end_inset
10919
10920 -fdollars-in-identifiers
10921 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10922
10923 \end_inset
10924
10925
10926 \series default
10927  Permit '$' as an identifier character.
10928 \end_layout
10929
10930 \begin_layout List
10931 \labelwidthstring 00.00.0000
10932
10933 \series bold
10934 -
10935 \begin_inset ERT
10936 status collapsed
10937
10938 \begin_layout Standard
10939
10940
10941 \backslash
10942 /
10943 \end_layout
10944
10945 \end_inset
10946
10947 -more-pedantic
10948 \series default
10949
10950 \begin_inset LatexCommand \index{-\/-more-pedantic}
10951
10952 \end_inset
10953
10954
10955 \begin_inset LatexCommand \index{pedantic}
10956
10957 \end_inset
10958
10959  Actually this is 
10960 \series bold
10961 \emph on
10962 not
10963 \series default
10964 \emph default
10965  a SDCC compiler option but if you want 
10966 \emph on
10967 more
10968 \emph default
10969  warnings you can use a separate tool dedicated to syntax checking like
10970  splint
10971 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10972
10973 \end_inset
10974
10975
10976 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10977
10978 \end_inset
10979
10980  
10981 \begin_inset LatexCommand \url{http://www.splint.org}
10982
10983 \end_inset
10984
10985 .
10986  To make your source files parseable by splint you will have to include
10987  
10988 \family sans
10989 lint.h
10990 \family default
10991
10992 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10993
10994 \end_inset
10995
10996  in your source file and add brackets around extended keywords (like 
10997 \family sans
10998
10999 \begin_inset Quotes sld
11000 \end_inset
11001
11002 __at\InsetSpace ~
11003
11004 \series bold
11005 (
11006 \series default
11007 0xab
11008 \series bold
11009 )
11010 \series default
11011
11012 \begin_inset Quotes srd
11013 \end_inset
11014
11015
11016 \family default
11017  and 
11018 \family sans
11019
11020 \begin_inset Quotes sld
11021 \end_inset
11022
11023 __interrupt\InsetSpace ~
11024 (2)
11025 \begin_inset Quotes srd
11026 \end_inset
11027
11028
11029 \family default
11030 ).
11031  
11032 \newline
11033 Splint has an excellent on line manual at 
11034 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11035
11036 \end_inset
11037
11038  and it's capabilities go beyond pure syntax checking.
11039  You'll need to tell splint the location of SDCC's include files so a typical
11040  command line could look like this: 
11041 \newline
11042
11043 \family sans
11044 splint\InsetSpace ~
11045 -I\InsetSpace ~
11046 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11047 \InsetSpace ~
11048 myprogram.c
11049 \end_layout
11050
11051 \begin_layout List
11052 \labelwidthstring 00.00.0000
11053
11054 \series bold
11055 -
11056 \begin_inset ERT
11057 status collapsed
11058
11059 \begin_layout Standard
11060
11061
11062 \backslash
11063 /
11064 \end_layout
11065
11066 \end_inset
11067
11068 -short-is-8bits
11069 \series default
11070
11071 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11072
11073 \end_inset
11074
11075
11076 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11077
11078 \end_inset
11079
11080  Treat short as 8-bit (for backward compatibility with older versions of
11081  compiler - see section 
11082 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11083
11084 \end_inset
11085
11086 )
11087 \end_layout
11088
11089 \begin_layout Standard
11090 \begin_inset VSpace bigskip
11091 \end_inset
11092
11093
11094 \end_layout
11095
11096 \begin_layout Subsection
11097 Intermediate Dump Options
11098 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11099
11100 \end_inset
11101
11102
11103 \begin_inset LatexCommand \index{Options intermediate dump}
11104
11105 \end_inset
11106
11107
11108 \begin_inset LatexCommand \index{Intermediate dump options}
11109
11110 \end_inset
11111
11112
11113 \end_layout
11114
11115 \begin_layout Standard
11116 The following options are provided for the purpose of retargetting and debugging
11117  the compiler.
11118  They provide a means to dump the intermediate code (iCode
11119 \begin_inset LatexCommand \index{iCode}
11120
11121 \end_inset
11122
11123 ) generated by the compiler in human readable form at various stages of
11124  the compilation process.
11125  More on iCodes see chapter 
11126 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11127
11128 \end_inset
11129
11130  
11131 \begin_inset Quotes srd
11132 \end_inset
11133
11134 The anatomy of the compiler
11135 \begin_inset Quotes srd
11136 \end_inset
11137
11138 .
11139 \end_layout
11140
11141 \begin_layout List
11142 \labelwidthstring 00.00.0000
11143
11144 \series bold
11145 -
11146 \begin_inset ERT
11147 status collapsed
11148
11149 \begin_layout Standard
11150
11151
11152 \backslash
11153 /
11154 \end_layout
11155
11156 \end_inset
11157
11158 -dumpraw
11159 \begin_inset LatexCommand \index{-\/-dumpraw}
11160
11161 \end_inset
11162
11163
11164 \series default
11165  This option will cause the compiler to dump the intermediate code into
11166  a file of named 
11167 \emph on
11168 <source filename>.dumpraw
11169 \emph default
11170  just after the intermediate code has been generated for a function, i.e.
11171  before any optimizations are done.
11172  The basic blocks
11173 \begin_inset LatexCommand \index{Basic blocks}
11174
11175 \end_inset
11176
11177  at this stage ordered in the depth first number, so they may not be in
11178  sequence of execution.
11179 \end_layout
11180
11181 \begin_layout List
11182 \labelwidthstring 00.00.0000
11183
11184 \series bold
11185 -
11186 \begin_inset ERT
11187 status collapsed
11188
11189 \begin_layout Standard
11190
11191
11192 \backslash
11193 /
11194 \end_layout
11195
11196 \end_inset
11197
11198 -dumpgcse
11199 \begin_inset LatexCommand \index{-\/-dumpgcse}
11200
11201 \end_inset
11202
11203
11204 \series default
11205  Will create a dump of iCodes, after global subexpression elimination
11206 \begin_inset LatexCommand \index{Global subexpression elimination}
11207
11208 \end_inset
11209
11210 , into a file named 
11211 \emph on
11212 <source filename>.dumpgcse.
11213 \end_layout
11214
11215 \begin_layout List
11216 \labelwidthstring 00.00.0000
11217
11218 \series bold
11219 -
11220 \begin_inset ERT
11221 status collapsed
11222
11223 \begin_layout Standard
11224
11225
11226 \backslash
11227 /
11228 \end_layout
11229
11230 \end_inset
11231
11232 -dumpdeadcode
11233 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11234
11235 \end_inset
11236
11237
11238 \series default
11239  Will create a dump of iCodes, after deadcode elimination
11240 \begin_inset LatexCommand \index{Dead-code elimination}
11241
11242 \end_inset
11243
11244 , into a file named 
11245 \emph on
11246 <source filename>.dumpdeadcode.
11247 \end_layout
11248
11249 \begin_layout List
11250 \labelwidthstring 00.00.0000
11251
11252 \series bold
11253 -
11254 \begin_inset ERT
11255 status collapsed
11256
11257 \begin_layout Standard
11258
11259
11260 \backslash
11261 /
11262 \end_layout
11263
11264 \end_inset
11265
11266 -dumploop
11267 \begin_inset LatexCommand \index{-\/-dumploop}
11268
11269 \end_inset
11270
11271
11272 \series default
11273 \size large
11274  
11275 \size default
11276 Will create a dump of iCodes, after loop optimizations
11277 \begin_inset LatexCommand \index{Loop optimization}
11278
11279 \end_inset
11280
11281 , into a file named 
11282 \emph on
11283 <source filename>.dumploop.
11284 \end_layout
11285
11286 \begin_layout List
11287 \labelwidthstring 00.00.0000
11288
11289 \series bold
11290 -
11291 \begin_inset ERT
11292 status collapsed
11293
11294 \begin_layout Standard
11295
11296
11297 \backslash
11298 /
11299 \end_layout
11300
11301 \end_inset
11302
11303 -dumprange
11304 \begin_inset LatexCommand \index{-\/-dumprange}
11305
11306 \end_inset
11307
11308
11309 \series default
11310 \size large
11311  
11312 \size default
11313 Will create a dump of iCodes, after live range analysis
11314 \begin_inset LatexCommand \index{Live range analysis}
11315
11316 \end_inset
11317
11318 , into a file named 
11319 \emph on
11320 <source filename>.dumprange.
11321 \end_layout
11322
11323 \begin_layout List
11324 \labelwidthstring 00.00.0000
11325
11326 \series bold
11327 -
11328 \begin_inset ERT
11329 status collapsed
11330
11331 \begin_layout Standard
11332
11333
11334 \backslash
11335 /
11336 \end_layout
11337
11338 \end_inset
11339
11340 -dumlrange
11341 \begin_inset LatexCommand \index{-\/-dumlrange}
11342
11343 \end_inset
11344
11345
11346 \series default
11347  Will dump the life ranges
11348 \begin_inset LatexCommand \index{Live range analysis}
11349
11350 \end_inset
11351
11352  for all symbols.
11353 \end_layout
11354
11355 \begin_layout List
11356 \labelwidthstring 00.00.0000
11357
11358 \series bold
11359 -
11360 \begin_inset ERT
11361 status collapsed
11362
11363 \begin_layout Standard
11364
11365
11366 \backslash
11367 /
11368 \end_layout
11369
11370 \end_inset
11371
11372 -dumpregassign
11373 \begin_inset LatexCommand \index{-\/-dumpregassign}
11374
11375 \end_inset
11376
11377
11378 \bar under
11379  
11380 \series default
11381 \bar default
11382 Will create a dump of iCodes, after register assignment
11383 \begin_inset LatexCommand \index{Register assignment}
11384
11385 \end_inset
11386
11387 , into a file named 
11388 \emph on
11389 <source filename>.dumprassgn.
11390 \end_layout
11391
11392 \begin_layout List
11393 \labelwidthstring 00.00.0000
11394
11395 \series bold
11396 -
11397 \begin_inset ERT
11398 status collapsed
11399
11400 \begin_layout Standard
11401
11402
11403 \backslash
11404 /
11405 \end_layout
11406
11407 \end_inset
11408
11409 -dumplrange
11410 \begin_inset LatexCommand \index{-\/-dumplrange}
11411
11412 \end_inset
11413
11414
11415 \series default
11416  Will create a dump of the live ranges of iTemp's
11417 \end_layout
11418
11419 \begin_layout List
11420 \labelwidthstring 00.00.0000
11421
11422 \series bold
11423 -
11424 \begin_inset ERT
11425 status collapsed
11426
11427 \begin_layout Standard
11428
11429
11430 \backslash
11431 /
11432 \end_layout
11433
11434 \end_inset
11435
11436 -dumpall
11437 \begin_inset LatexCommand \index{-\/-dumpall}
11438
11439 \end_inset
11440
11441
11442 \size large
11443 \bar under
11444  
11445 \series default
11446 \size default
11447 \bar default
11448 Will cause all the above mentioned dumps to be created.
11449 \end_layout
11450
11451 \begin_layout Standard
11452 \begin_inset VSpace bigskip
11453 \end_inset
11454
11455
11456 \end_layout
11457
11458 \begin_layout Subsection
11459 Redirecting output on Windows Shells
11460 \end_layout
11461
11462 \begin_layout Standard
11463 By default SDCC writes its error messages to 
11464 \begin_inset Quotes sld
11465 \end_inset
11466
11467 standard error
11468 \begin_inset Quotes srd
11469 \end_inset
11470
11471 .
11472  To force all messages to 
11473 \begin_inset Quotes sld
11474 \end_inset
11475
11476 standard output
11477 \begin_inset Quotes srd
11478 \end_inset
11479
11480  use 
11481 \series bold
11482 -
11483 \series default
11484 \emph on
11485
11486 \begin_inset ERT
11487 status collapsed
11488
11489 \begin_layout Standard
11490
11491
11492 \backslash
11493 /
11494 \end_layout
11495
11496 \end_inset
11497
11498
11499 \series bold
11500 \emph default
11501 -
11502 \series default
11503 use-stdout
11504 \begin_inset LatexCommand \index{-\/-use-stdout}
11505
11506 \end_inset
11507
11508 .
11509  Additionally, if you happen to have visual studio installed in your windows
11510  machine, you can use it to compile your sources using a custom build and
11511  the SDCC -
11512 \emph on
11513
11514 \begin_inset ERT
11515 status collapsed
11516
11517 \begin_layout Standard
11518
11519
11520 \backslash
11521 /
11522 \end_layout
11523
11524 \end_inset
11525
11526
11527 \emph default
11528 -vc
11529 \begin_inset LatexCommand \index{-\/-vc}
11530
11531 \end_inset
11532
11533  option.
11534  Something like this should work:
11535 \newline
11536
11537 \newline
11538
11539 \series bold
11540 c:
11541 \backslash
11542 sdcc
11543 \backslash
11544 bin
11545 \backslash
11546 sdcc.exe -
11547 \series default
11548 \emph on
11549
11550 \begin_inset ERT
11551 status collapsed
11552
11553 \begin_layout Standard
11554
11555
11556 \backslash
11557 /
11558 \end_layout
11559
11560 \end_inset
11561
11562
11563 \series bold
11564 \emph default
11565 -vc -
11566 \series default
11567 \emph on
11568
11569 \begin_inset ERT
11570 status collapsed
11571
11572 \begin_layout Standard
11573
11574
11575 \backslash
11576 /
11577 \end_layout
11578
11579 \end_inset
11580
11581
11582 \series bold
11583 \emph default
11584 -model-large -c $(InputPath)
11585 \series default
11586
11587 \begin_inset VSpace bigskip
11588 \end_inset
11589
11590
11591 \end_layout
11592
11593 \begin_layout Section
11594 Environment variables
11595 \begin_inset LatexCommand \index{Environment variables}
11596
11597 \end_inset
11598
11599
11600 \end_layout
11601
11602 \begin_layout Standard
11603 SDCC recognizes the following environment variables:
11604 \end_layout
11605
11606 \begin_layout List
11607 \labelwidthstring 00.00.0000
11608
11609 \series bold
11610 SDCC_LEAVE_SIGNALS
11611 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11612
11613 \end_inset
11614
11615
11616 \series default
11617  SDCC installs a signal handler
11618 \begin_inset LatexCommand \index{signal handler}
11619
11620 \end_inset
11621
11622  to be able to delete temporary files after an user break (^C) or an exception.
11623  If this environment variable is set, SDCC won't install the signal handler
11624  in order to be able to debug SDCC.
11625 \end_layout
11626
11627 \begin_layout List
11628 \labelwidthstring 00.00.0000
11629
11630 \series bold
11631 TMP,\InsetSpace ~
11632 TEMP,\InsetSpace ~
11633 TMPDIR
11634 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11635
11636 \end_inset
11637
11638
11639 \series default
11640  Path, where temporary files will be created.
11641  The order of the variables is the search order.
11642  In a standard *nix environment these variables are not set, and there's
11643  no need to set them.
11644  On Windows it's recommended to set one of them.
11645 \end_layout
11646
11647 \begin_layout List
11648 \labelwidthstring 00.00.0000
11649
11650 \series bold
11651 SDCC_HOME
11652 \begin_inset LatexCommand \index{SDCC\_HOME}
11653
11654 \end_inset
11655
11656
11657 \series default
11658  Path, see section 
11659 \begin_inset LatexCommand \ref{sub:Install-paths}
11660
11661 \end_inset
11662
11663 \InsetSpace ~
11664
11665 \begin_inset Quotes sld
11666 \end_inset
11667
11668  Install Paths
11669 \begin_inset Quotes srd
11670 \end_inset
11671
11672 .
11673 \end_layout
11674
11675 \begin_layout List
11676 \labelwidthstring 00.00.0000
11677
11678 \series bold
11679 SDCC_INCLUDE
11680 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11681
11682 \end_inset
11683
11684
11685 \series default
11686  Path, see section 
11687 \begin_inset LatexCommand \ref{sub:Search-Paths}
11688
11689 \end_inset
11690
11691 \InsetSpace ~
11692
11693 \begin_inset Quotes sld
11694 \end_inset
11695
11696 Search Paths
11697 \begin_inset Quotes srd
11698 \end_inset
11699
11700 .
11701 \end_layout
11702
11703 \begin_layout List
11704 \labelwidthstring 00.00.0000
11705
11706 \series bold
11707 SDCC_LIB
11708 \begin_inset LatexCommand \index{SDCC\_LIB}
11709
11710 \end_inset
11711
11712
11713 \series default
11714  Path, see section 
11715 \begin_inset LatexCommand \ref{sub:Search-Paths}
11716
11717 \end_inset
11718
11719 \InsetSpace ~
11720
11721 \begin_inset Quotes sld
11722 \end_inset
11723
11724 Search Paths
11725 \begin_inset Quotes srd
11726 \end_inset
11727
11728 ..
11729 \end_layout
11730
11731 \begin_layout Standard
11732 There are some more environment variables recognized by SDCC, but these
11733  are solely used for debugging purposes.
11734  They can change or disappear very quickly, and will never be documented.
11735 \begin_inset VSpace bigskip
11736 \end_inset
11737
11738
11739 \end_layout
11740
11741 \begin_layout Section
11742 Storage Class Language Extensions
11743 \end_layout
11744
11745 \begin_layout Subsection
11746 MCS51/DS390 Storage Class
11747 \begin_inset LatexCommand \index{Storage class}
11748
11749 \end_inset
11750
11751  Language Extensions
11752 \end_layout
11753
11754 \begin_layout Standard
11755 In addition to the ANSI storage classes SDCC allows the following MCS51
11756  specific storage classes:
11757 \end_layout
11758
11759 \begin_layout Subsubsection
11760 data
11761 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11762
11763 \end_inset
11764
11765
11766 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11767
11768 \end_inset
11769
11770  / near
11771 \begin_inset LatexCommand \index{near (storage class)}
11772
11773 \end_inset
11774
11775
11776 \begin_inset LatexCommand \index{\_\_near (storage class)}
11777
11778 \end_inset
11779
11780
11781 \end_layout
11782
11783 \begin_layout Standard
11784 This is the 
11785 \series bold
11786 default
11787 \series default
11788  storage class for the Small Memory model (
11789 \emph on
11790 data
11791 \emph default
11792  and 
11793 \emph on
11794 near
11795 \emph default
11796  or the more ANSI-C compliant forms 
11797 \emph on
11798 __data
11799 \emph default
11800  and 
11801 \emph on
11802 __near
11803 \emph default
11804  can be used synonymously).
11805  Variables declared with this storage class will be allocated in the directly
11806  addressable portion of the internal RAM of a 8051, e.g.:
11807 \end_layout
11808
11809 \begin_layout Verse
11810
11811 \family typewriter
11812 __data unsigned char test_data;
11813 \end_layout
11814
11815 \begin_layout Standard
11816 Writing 0x01 to this variable generates the assembly code:
11817 \end_layout
11818
11819 \begin_layout Verse
11820
11821 \family typewriter
11822 75*00 01\InsetSpace ~
11823 \InsetSpace ~
11824 \InsetSpace ~
11825 mov\InsetSpace ~
11826 \InsetSpace ~
11827 _test_data,#0x01
11828 \end_layout
11829
11830 \begin_layout Subsubsection
11831 xdata
11832 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11833
11834 \end_inset
11835
11836
11837 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11838
11839 \end_inset
11840
11841  / far
11842 \begin_inset LatexCommand \index{far (storage class)}
11843
11844 \end_inset
11845
11846
11847 \begin_inset LatexCommand \index{\_\_far (storage class)}
11848
11849 \end_inset
11850
11851
11852 \end_layout
11853
11854 \begin_layout Standard
11855 Variables declared with this storage class will be placed in the external
11856  RAM.
11857  This is the 
11858 \series bold
11859 default
11860 \series default
11861  storage class for the Large Memory model, e.g.:
11862 \end_layout
11863
11864 \begin_layout Verse
11865
11866 \family typewriter
11867 __xdata unsigned char test_xdata;
11868 \end_layout
11869
11870 \begin_layout Standard
11871 Writing 0x01 to this variable generates the assembly code:
11872 \end_layout
11873
11874 \begin_layout Verse
11875
11876 \family typewriter
11877 90s00r00\InsetSpace ~
11878 \InsetSpace ~
11879 \InsetSpace ~
11880 mov\InsetSpace ~
11881 \InsetSpace ~
11882 dptr,#_test_xdata 
11883 \newline
11884 74\InsetSpace ~
11885 01\InsetSpace ~
11886 \InsetSpace ~
11887 \InsetSpace ~
11888 \InsetSpace ~
11889 \InsetSpace ~
11890 \InsetSpace ~
11891 mov\InsetSpace ~
11892 \InsetSpace ~
11893 a,#0x01 
11894 \newline
11895 F0\InsetSpace ~
11896 \InsetSpace ~
11897 \InsetSpace ~
11898 \InsetSpace ~
11899 \InsetSpace ~
11900 \InsetSpace ~
11901 \InsetSpace ~
11902 \InsetSpace ~
11903 \InsetSpace ~
11904 movx\InsetSpace ~
11905 @dptr,a 
11906 \end_layout
11907
11908 \begin_layout Subsubsection
11909 idata
11910 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11911
11912 \end_inset
11913
11914
11915 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11916
11917 \end_inset
11918
11919
11920 \end_layout
11921
11922 \begin_layout Standard
11923 Variables declared with this storage class will be allocated into the indirectly
11924  addressable portion of the internal ram of a 8051, e.g.:
11925 \end_layout
11926
11927 \begin_layout Verse
11928
11929 \family typewriter
11930 __idata unsigned char test_idata;
11931 \end_layout
11932
11933 \begin_layout Standard
11934 Writing 0x01 to this variable generates the assembly code:
11935 \end_layout
11936
11937 \begin_layout Verse
11938
11939 \family typewriter
11940 78r00\InsetSpace ~
11941 \InsetSpace ~
11942 \InsetSpace ~
11943 \InsetSpace ~
11944 \InsetSpace ~
11945 \InsetSpace ~
11946 \InsetSpace ~
11947 mov\InsetSpace ~
11948 \InsetSpace ~
11949 r0,#_test_idata
11950 \newline
11951 76\InsetSpace ~
11952 01\InsetSpace ~
11953 \InsetSpace ~
11954 \InsetSpace ~
11955 \InsetSpace ~
11956 \InsetSpace ~
11957 \InsetSpace ~
11958 \InsetSpace ~
11959 mov\InsetSpace ~
11960 \InsetSpace ~
11961 @r0,#0x01
11962 \end_layout
11963
11964 \begin_layout Standard
11965 Please note, the first 128 byte of idata physically access the same RAM
11966  as the data memory.
11967  The original 8051 had 128 byte idata memory, nowadays most devices have
11968  256 byte idata memory.
11969  The stack
11970 \begin_inset LatexCommand \index{stack}
11971
11972 \end_inset
11973
11974  is located in idata memory.
11975 \end_layout
11976
11977 \begin_layout Subsubsection
11978 pdata
11979 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11980
11981 \end_inset
11982
11983
11984 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11985
11986 \end_inset
11987
11988
11989 \end_layout
11990
11991 \begin_layout Standard
11992 Paged xdata access is just as straightforward as using the other addressing
11993  modes of a 8051.
11994  It is typically located at the start of xdata and has a maximum size of
11995  256 bytes.
11996  The following example writes 0x01 to the pdata variable.
11997  Please note, pdata access physically accesses xdata memory.
11998  The high byte of the address is determined by port P2 
11999 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
12000
12001 \end_inset
12002
12003 (or in case of some 8051 variants by a separate Special Function Register,
12004  see section 
12005 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12006
12007 \end_inset
12008
12009 ).
12010  This is the 
12011 \series bold
12012 default
12013 \series default
12014  storage class for the Medium Memory model, e.g.:
12015 \end_layout
12016
12017 \begin_layout Verse
12018
12019 \family typewriter
12020 __pdata unsigned char test_pdata;
12021 \end_layout
12022
12023 \begin_layout Standard
12024 Writing 0x01 to this variable generates the assembly code:
12025 \end_layout
12026
12027 \begin_layout Verse
12028
12029 \family typewriter
12030 78r00\InsetSpace ~
12031 \InsetSpace ~
12032 \InsetSpace ~
12033 \InsetSpace ~
12034 \InsetSpace ~
12035 \InsetSpace ~
12036 mov r0,#_test_pdata
12037 \newline
12038 74 01\InsetSpace ~
12039 \InsetSpace ~
12040 \InsetSpace ~
12041 \InsetSpace ~
12042 \InsetSpace ~
12043 \InsetSpace ~
12044 mov a,#0x01 
12045 \newline
12046 F2\InsetSpace ~
12047 \InsetSpace ~
12048 \InsetSpace ~
12049 \InsetSpace ~
12050 \InsetSpace ~
12051 \InsetSpace ~
12052 \InsetSpace ~
12053 \InsetSpace ~
12054 \InsetSpace ~
12055 movx @r0,a
12056 \end_layout
12057
12058 \begin_layout Standard
12059 If the -
12060 \begin_inset ERT
12061 status collapsed
12062
12063 \begin_layout Standard
12064
12065
12066 \backslash
12067 /
12068 \end_layout
12069
12070 \end_inset
12071
12072 -xstack
12073 \begin_inset LatexCommand \index{-\/-xstack}
12074
12075 \end_inset
12076
12077  option is used the pdata memory area is followed by the xstack memory area
12078  and the sum of their sizes is limited to 256 bytes.
12079 \end_layout
12080
12081 \begin_layout Subsubsection
12082 code
12083 \begin_inset LatexCommand \index{code}
12084
12085 \end_inset
12086
12087
12088 \begin_inset LatexCommand \index{\_\_code}
12089
12090 \end_inset
12091
12092
12093 \end_layout
12094
12095 \begin_layout Standard
12096 'Variables' declared with this storage class will be placed in the code
12097  memory:
12098 \end_layout
12099
12100 \begin_layout Verse
12101
12102 \family typewriter
12103 __code unsigned char test_code;
12104 \end_layout
12105
12106 \begin_layout Standard
12107 Read access to this variable generates the assembly code:
12108 \end_layout
12109
12110 \begin_layout Verse
12111
12112 \family typewriter
12113 90s00r6F\InsetSpace ~
12114 \InsetSpace ~
12115 \InsetSpace ~
12116 mov dptr,#_test_code
12117 \newline
12118 E4\InsetSpace ~
12119 \InsetSpace ~
12120 \InsetSpace ~
12121 \InsetSpace ~
12122 \InsetSpace ~
12123 \InsetSpace ~
12124 \InsetSpace ~
12125 \InsetSpace ~
12126 \InsetSpace ~
12127 clr a
12128 \newline
12129 93\InsetSpace ~
12130 \InsetSpace ~
12131 \InsetSpace ~
12132 \InsetSpace ~
12133 \InsetSpace ~
12134 \InsetSpace ~
12135 \InsetSpace ~
12136 \InsetSpace ~
12137 \InsetSpace ~
12138 movc a,@a+dptr 
12139 \end_layout
12140
12141 \begin_layout Standard
12142
12143 \family typewriter
12144 char
12145 \family default
12146  indexed arrays of characters in code memory can be accessed efficiently:
12147 \end_layout
12148
12149 \begin_layout Verse
12150
12151 \family typewriter
12152 __code char test_array[] = {'c','h','e','a','p'}; 
12153 \end_layout
12154
12155 \begin_layout Standard
12156 Read access to this array using an 8-bit unsigned index generates the assembly
12157  code:
12158 \end_layout
12159
12160 \begin_layout Verse
12161
12162 \family typewriter
12163 E5*00\InsetSpace ~
12164 \InsetSpace ~
12165 \InsetSpace ~
12166 \InsetSpace ~
12167 \InsetSpace ~
12168 \InsetSpace ~
12169 mov a,_index 
12170 \end_layout
12171
12172 \begin_layout Verse
12173
12174 \family typewriter
12175 90s00r41\InsetSpace ~
12176 \InsetSpace ~
12177 \InsetSpace ~
12178 mov dptr,#_test_array
12179 \end_layout
12180
12181 \begin_layout Verse
12182
12183 \family typewriter
12184 93\InsetSpace ~
12185 \InsetSpace ~
12186 \InsetSpace ~
12187 \InsetSpace ~
12188 \InsetSpace ~
12189 \InsetSpace ~
12190 \InsetSpace ~
12191 \InsetSpace ~
12192 \InsetSpace ~
12193 movc a,@a+dptr 
12194 \end_layout
12195
12196 \begin_layout Subsubsection
12197 bit
12198 \begin_inset LatexCommand \index{bit}
12199
12200 \end_inset
12201
12202
12203 \begin_inset LatexCommand \index{\_\_bit}
12204
12205 \end_inset
12206
12207
12208 \end_layout
12209
12210 \begin_layout Standard
12211 This is a data-type and a storage class specifier.
12212  When a variable is declared as a bit, it is allocated into the bit addressable
12213  memory of 8051, e.g.:
12214 \end_layout
12215
12216 \begin_layout Verse
12217
12218 \family typewriter
12219 __bit test_bit;
12220 \end_layout
12221
12222 \begin_layout Standard
12223 Writing 1 to this variable generates the assembly code:
12224 \end_layout
12225
12226 \begin_layout Verse
12227
12228 \family typewriter
12229 D2*00\InsetSpace ~
12230 \InsetSpace ~
12231 \InsetSpace ~
12232 \InsetSpace ~
12233 \InsetSpace ~
12234 \InsetSpace ~
12235 \InsetSpace ~
12236 setb\InsetSpace ~
12237 _test_bit
12238 \end_layout
12239
12240 \begin_layout Standard
12241 The bit addressable memory consists of 128 bits which are located from 0x20
12242  to 0x2f in data memory.
12243  
12244 \newline
12245 Apart from this 8051 specific storage class most architectures support
12246  ANSI-C bitfields
12247 \begin_inset LatexCommand \index{bitfields}
12248
12249 \end_inset
12250
12251
12252 \begin_inset Foot
12253 status open
12254
12255 \begin_layout Standard
12256 Not really meant as examples, but nevertheless showing what bitfields are
12257  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12258 \end_layout
12259
12260 \end_inset
12261
12262 .
12263  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12264  signed modifier are implemented as unsigned.
12265 \end_layout
12266
12267 \begin_layout Subsubsection
12268 sfr
12269 \begin_inset LatexCommand \index{sfr}
12270
12271 \end_inset
12272
12273
12274 \begin_inset LatexCommand \index{\_\_sfr}
12275
12276 \end_inset
12277
12278  / sfr16
12279 \begin_inset LatexCommand \index{sfr16}
12280
12281 \end_inset
12282
12283
12284 \begin_inset LatexCommand \index{\_\_sfr16}
12285
12286 \end_inset
12287
12288  / sfr32
12289 \begin_inset LatexCommand \index{sfr32}
12290
12291 \end_inset
12292
12293
12294 \begin_inset LatexCommand \index{\_\_sfr32}
12295
12296 \end_inset
12297
12298  / sbit
12299 \begin_inset LatexCommand \index{\_\_sbit}
12300
12301 \end_inset
12302
12303
12304 \begin_inset LatexCommand \index{sbit}
12305
12306 \end_inset
12307
12308
12309 \end_layout
12310
12311 \begin_layout Standard
12312 Like the bit keyword, 
12313 \emph on
12314 sfr / sfr16 / sfr32 / sbit 
12315 \emph default
12316 signify both a data-type and storage class, they are used to describe the
12317  
12318 \emph on
12319 s
12320 \emph default
12321 pecial 
12322 \emph on
12323 f
12324 \emph default
12325 unction 
12326 \emph on
12327 r
12328 \emph default
12329 egisters and 
12330 \emph on
12331 s
12332 \emph default
12333 pecial 
12334 \emph on
12335 bit
12336 \emph default
12337  variables of a 8051, eg:
12338 \end_layout
12339
12340 \begin_layout Verse
12341
12342 \family typewriter
12343 __sfr __at
12344 \begin_inset LatexCommand \index{at}
12345
12346 \end_inset
12347
12348
12349 \begin_inset LatexCommand \index{\_\_at}
12350
12351 \end_inset
12352
12353  (0x80) P0;\InsetSpace ~
12354  /* special function register P0 at location 0x80 */
12355 \newline
12356
12357 \newline
12358 /* 16 bit
12359  special function register combination for timer 0
12360 \newline
12361 \InsetSpace ~
12362 \InsetSpace ~
12363  with the high byte at
12364  location 0x8C and the low byte at location 0x8A */
12365 \newline
12366 __sfr16 __at (0x8C8A)
12367  TMR0;
12368 \newline
12369
12370 \newline
12371 __sbit __at
12372 \begin_inset LatexCommand \index{at}
12373
12374 \end_inset
12375
12376
12377 \begin_inset LatexCommand \index{\_\_at}
12378
12379 \end_inset
12380
12381  (0xd7) CY;\InsetSpace ~
12382  /* CY (Carry Flag
12383 \begin_inset LatexCommand \index{Flags}
12384
12385 \end_inset
12386
12387
12388 \begin_inset LatexCommand \index{Carry flag}
12389
12390 \end_inset
12391
12392 ) */
12393 \end_layout
12394
12395 \begin_layout Standard
12396 Special function registers which are located on an address dividable by
12397  8 are bit-addressable, an
12398 \emph on
12399  sbit
12400 \emph default
12401  addresses a specific bit within these sfr.
12402 \newline
12403 16 Bit and 32 bit special function
12404  register combinations which require a certain access order are better not
12405  declared using 
12406 \emph on
12407 sfr16
12408 \emph default
12409  or 
12410 \emph on
12411 sfr32.
12412
12413 \emph default
12414  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12415  this is not guaranteed.
12416 \newline
12417
12418 \end_layout
12419
12420 \begin_layout Standard
12421 Please note, if you use a header file which was written for another compiler
12422  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12423  likely be 
12424 \emph on
12425 not 
12426 \emph default
12427 compatible.
12428  Specifically the syntax 
12429 \family typewriter
12430 \InsetSpace ~
12431 sfr P0 = 0x80;\InsetSpace ~
12432
12433 \family default
12434  is compiled 
12435 \emph on
12436 without warning
12437 \emph default
12438  by SDCC to an assignment of 0x80 to a variable called P0 
12439 \family typewriter
12440
12441 \begin_inset Marginal
12442 status collapsed
12443
12444 \begin_layout Standard
12445
12446 \series bold
12447 \InsetSpace ~
12448 !
12449 \end_layout
12450
12451 \end_inset
12452
12453 .
12454  
12455 \family default
12456 Nevertheless it is possible to write header files
12457 \begin_inset LatexCommand \index{Header files}
12458
12459 \end_inset
12460
12461
12462 \begin_inset LatexCommand \index{Include files}
12463
12464 \end_inset
12465
12466  which can be shared among different compilers (see section 
12467 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12468
12469 \end_inset
12470
12471 ).
12472  
12473 \end_layout
12474
12475 \begin_layout Subsubsection
12476 Pointers
12477 \begin_inset LatexCommand \index{Pointer}
12478
12479 \end_inset
12480
12481  to MCS51/DS390 specific memory spaces
12482 \end_layout
12483
12484 \begin_layout Standard
12485 SDCC allows (via language extensions) pointers to explicitly point to any
12486  of the memory spaces
12487 \begin_inset LatexCommand \index{Memory model}
12488
12489 \end_inset
12490
12491  of the 8051.
12492  In addition to the explicit pointers, the compiler uses (by default) generic
12493  pointers which can be used to point to any of the memory spaces.
12494 \newline
12495
12496 \newline
12497 Pointer
12498  declaration examples:
12499 \end_layout
12500
12501 \begin_layout Verse
12502
12503 \family typewriter
12504 /* pointer physically in internal ram pointing to object in external ram
12505  */ 
12506 \newline
12507 __xdata unsigned char * __data p;
12508 \newline
12509
12510 \newline
12511 /* pointer physically in external ram
12512  pointing to object in internal ram */ 
12513 \newline
12514 __data unsigned char * __xdata p;
12515 \newline
12516
12517 \newline
12518 /*
12519  pointer physically in code rom pointing to data in xdata space */ 
12520 \newline
12521 __xdata
12522  unsigned char * __code p;
12523 \newline
12524
12525 \newline
12526 /* pointer physically in code space pointing to
12527  data in code space */ 
12528 \newline
12529 __code unsigned char * __code p;
12530 \newline
12531
12532 \newline
12533 /* generic pointer
12534  physically located in xdata space */
12535 \newline
12536 unsigned char * __xdata p;
12537 \newline
12538
12539 \newline
12540 /* generic
12541  pointer physically located in default memory space */
12542 \newline
12543 unsigned char * p;
12544 \newline
12545
12546 \newline
12547 /*
12548  the following is a function pointer
12549 \begin_inset LatexCommand \index{function pointer}
12550
12551 \end_inset
12552
12553  physically located in data space */
12554 \newline
12555 char (* __data fp)(void);
12556 \end_layout
12557
12558 \begin_layout Standard
12559 Well you get the idea.
12560  
12561 \newline
12562
12563 \newline
12564 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12565 \emph on
12566 generic
12567 \emph default
12568  pointers.
12569  
12570 \size small
12571
12572 \newline
12573
12574 \newline
12575
12576 \size default
12577 The highest order byte of the 
12578 \emph on
12579 generic
12580 \emph default
12581  pointers contains the data space information.
12582  Assembler support routines are called whenever data is stored or retrieved
12583  using 
12584 \emph on
12585 generic
12586 \emph default
12587  pointers.
12588  These are useful for developing reusable library
12589 \begin_inset LatexCommand \index{Libraries}
12590
12591 \end_inset
12592
12593  routines.
12594  Explicitly specifying the pointer
12595 \begin_inset LatexCommand \index{pointer}
12596
12597 \end_inset
12598
12599  type will generate the most efficient code.
12600 \end_layout
12601
12602 \begin_layout Subsubsection
12603 Notes on MCS51 memory
12604 \begin_inset LatexCommand \index{MCS51 memory}
12605
12606 \end_inset
12607
12608  layout
12609 \end_layout
12610
12611 \begin_layout Standard
12612 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12613  RAM memory which is structured as follows:
12614 \newline
12615
12616 \newline
12617 - Bytes 00-1F - 32 bytes to hold
12618  up to 4 banks of the registers R0 to R7, 
12619 \newline
12620 - Bytes 20-2F - 16 bytes to hold
12621  128 bit
12622 \begin_inset LatexCommand \index{bit}
12623
12624 \end_inset
12625
12626  variables and, 
12627 \newline
12628 - Bytes 30-7F - 80 bytes for general purpose use.
12629 \newline
12630
12631 \end_layout
12632
12633 \begin_layout Standard
12634 Additionally some members of the MCS51 family may have up to 128 bytes of
12635  additional, indirectly addressable, internal RAM memory (
12636 \emph on
12637 idata
12638 \emph default
12639
12640 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12641
12642 \end_inset
12643
12644
12645 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12646
12647 \end_inset
12648
12649 ).
12650  Furthermore, some chips may have some built in external memory (
12651 \emph on
12652 xdata
12653 \emph default
12654
12655 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12656
12657 \end_inset
12658
12659
12660 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12661
12662 \end_inset
12663
12664 ) which should not be confused with the internal, directly addressable RAM
12665  memory (
12666 \emph on
12667 data
12668 \emph default
12669
12670 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12671
12672 \end_inset
12673
12674
12675 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12676
12677 \end_inset
12678
12679 ).
12680  Sometimes this built in 
12681 \emph on
12682 xdata
12683 \emph default
12684  memory has to be activated before using it (you can probably find this
12685  information on the datasheet of the microcontroller your are using, see
12686  also section 
12687 \begin_inset LatexCommand \ref{sub:Startup-Code}
12688
12689 \end_inset
12690
12691 \InsetSpace ~
12692 Startup-Code).
12693 \end_layout
12694
12695 \begin_layout Standard
12696 Normally SDCC will only use the first bank
12697 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12698
12699 \end_inset
12700
12701  of registers (register bank 0), but it is possible to specify that other
12702  banks of registers (keyword 
12703 \emph on
12704 using
12705 \emph default
12706  
12707 \emph on
12708
12709 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12710
12711 \end_inset
12712
12713
12714 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12715
12716 \end_inset
12717
12718
12719 \emph default
12720 ) should be used for example in interrupt
12721 \begin_inset LatexCommand \index{interrupt}
12722
12723 \end_inset
12724
12725
12726 \begin_inset LatexCommand \index{\_\_interrupt}
12727
12728 \end_inset
12729
12730  routines.
12731  By default, the compiler will place the stack after the last byte of allocated
12732  memory for variables.
12733  For example, if the first 2 banks of registers are used, and only four
12734  bytes are used for 
12735 \emph on
12736 data
12737 \emph default
12738  variables, it will position the base of the internal stack at address 20
12739  (0x14).
12740  This implies that as the stack
12741 \begin_inset LatexCommand \index{stack}
12742
12743 \end_inset
12744
12745  grows, it will use up the remaining register banks, and the 16 bytes used
12746  by the 128 bit variables, and 80 bytes for general purpose use.
12747  If any bit variables are used, the data variables will be placed in unused
12748  register banks and after the byte holding the last bit variable.
12749  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12750  (two bytes used), 
12751 \emph on
12752 data
12753 \emph default
12754  variables will be placed starting from address 0x10 to 0x20 and continue
12755  at address 0x22.
12756  You can also use -
12757 \begin_inset ERT
12758 status collapsed
12759
12760 \begin_layout Standard
12761
12762
12763 \backslash
12764 /
12765 \end_layout
12766
12767 \end_inset
12768
12769 -data-loc
12770 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12771
12772 \end_inset
12773
12774  to specify the start address of the 
12775 \emph on
12776 data
12777 \emph default
12778  and -
12779 \begin_inset ERT
12780 status collapsed
12781
12782 \begin_layout Standard
12783
12784
12785 \backslash
12786 /
12787 \end_layout
12788
12789 \end_inset
12790
12791 -iram-size
12792 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12793
12794 \end_inset
12795
12796  to specify the size of the total internal RAM (
12797 \emph on
12798 data
12799 \emph default
12800 +
12801 \emph on
12802 idata
12803 \emph default
12804 ).
12805  
12806 \newline
12807
12808 \end_layout
12809
12810 \begin_layout Standard
12811 By default the 8051 linker will place the stack after the last byte of (i)data
12812  variables.
12813  Option -
12814 \begin_inset ERT
12815 status collapsed
12816
12817 \begin_layout Standard
12818
12819
12820 \backslash
12821 /
12822 \end_layout
12823
12824 \end_inset
12825
12826 -stack-loc
12827 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12828
12829 \end_inset
12830
12831  allows you to specify the start of the stack, i.e.
12832  you could start it after any data in the general purpose area.
12833  If your microcontroller has additional indirectly addressable internal
12834  RAM (
12835 \emph on
12836 idata
12837 \emph default
12838 ) you can place the stack on it.
12839  You may also need to use -
12840 \begin_inset ERT
12841 status collapsed
12842
12843 \begin_layout Standard
12844
12845
12846 \backslash
12847 /
12848 \end_layout
12849
12850 \end_inset
12851
12852 -xdata-loc
12853 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12854
12855 \end_inset
12856
12857  to set the start address of the external RAM (
12858 \emph on
12859 xdata
12860 \emph default
12861 ) and -
12862 \begin_inset ERT
12863 status collapsed
12864
12865 \begin_layout Standard
12866
12867
12868 \backslash
12869 /
12870 \end_layout
12871
12872 \end_inset
12873
12874 -xram-size
12875 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12876
12877 \end_inset
12878
12879  to specify its size.
12880  Same goes for the code memory, using -
12881 \begin_inset ERT
12882 status collapsed
12883
12884 \begin_layout Standard
12885
12886
12887 \backslash
12888 /
12889 \end_layout
12890
12891 \end_inset
12892
12893 -code-loc
12894 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12895
12896 \end_inset
12897
12898  and -
12899 \begin_inset ERT
12900 status collapsed
12901
12902 \begin_layout Standard
12903
12904
12905 \backslash
12906 /
12907 \end_layout
12908
12909 \end_inset
12910
12911 -code-size
12912 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12913
12914 \end_inset
12915
12916 .
12917  If in doubt, don't specify any options and see if the resulting memory
12918  layout is appropriate, then you can adjust it.
12919 \end_layout
12920
12921 \begin_layout Standard
12922 The linker generates two files with memory allocation information.
12923  The first, with extension .map
12924 \begin_inset LatexCommand \index{<file>.map}
12925
12926 \end_inset
12927
12928  shows all the variables and segments.
12929  The second with extension .mem
12930 \begin_inset LatexCommand \index{<file>.mem}
12931
12932 \end_inset
12933
12934  shows the final memory layout.
12935  The linker will complain either if memory segments overlap, there is not
12936  enough memory, or there is not enough space for stack.
12937  If you get any linking warnings and/or errors related to stack or segments
12938  allocation, take a look at either the .map or .mem files to find out what
12939  the problem is.
12940  The .mem file may even suggest a solution to the problem.
12941 \begin_inset VSpace bigskip
12942 \end_inset
12943
12944
12945 \end_layout
12946
12947 \begin_layout Subsection
12948 Z80/Z180 Storage Class
12949 \begin_inset LatexCommand \index{Z80!Storage class}
12950
12951 \end_inset
12952
12953  Language Extensions
12954 \end_layout
12955
12956 \begin_layout Subsubsection
12957 sfr
12958 \begin_inset LatexCommand \index{sfr}
12959
12960 \end_inset
12961
12962
12963 \begin_inset LatexCommand \index{\_\_sfr}
12964
12965 \end_inset
12966
12967  (in/out to 8-bit addresses)
12968 \end_layout
12969
12970 \begin_layout Standard
12971 The Z80
12972 \begin_inset LatexCommand \index{Z80}
12973
12974 \end_inset
12975
12976  family has separate address spaces for memory and 
12977 \emph on
12978 i
12979 \emph default
12980 nput/
12981 \emph on
12982 o
12983 \emph default
12984 utput memory.
12985  I/O memory
12986 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12987
12988 \end_inset
12989
12990
12991 \begin_inset LatexCommand \index{Z80!I/O memory}
12992
12993 \end_inset
12994
12995
12996 \begin_inset LatexCommand \index{Z180!I/O memory}
12997
12998 \end_inset
12999
13000  is accessed with special instructions, e.g.:
13001 \end_layout
13002
13003 \begin_layout Verse
13004
13005 \family typewriter
13006 sfr at 0x78 IoPort;\InsetSpace ~
13007 \InsetSpace ~
13008 /* define a var in I/O space at 78h called IoPort */
13009  
13010 \end_layout
13011
13012 \begin_layout Standard
13013 Writing 0x01 to this variable generates the assembly code:
13014 \end_layout
13015
13016 \begin_layout Verse
13017
13018 \family typewriter
13019 3E 01\InsetSpace ~
13020 \InsetSpace ~
13021 \InsetSpace ~
13022 \InsetSpace ~
13023 \InsetSpace ~
13024 \InsetSpace ~
13025 ld a,#0x01
13026 \newline
13027 D3 78\InsetSpace ~
13028 \InsetSpace ~
13029 \InsetSpace ~
13030 \InsetSpace ~
13031 \InsetSpace ~
13032 \InsetSpace ~
13033 out (_IoPort),a 
13034 \end_layout
13035
13036 \begin_layout Subsubsection
13037 banked sfr
13038 \begin_inset LatexCommand \index{sfr}
13039
13040 \end_inset
13041
13042
13043 \begin_inset LatexCommand \index{\_\_sfr}
13044
13045 \end_inset
13046
13047  (in/out to 16-bit addresses)
13048 \end_layout
13049
13050 \begin_layout Standard
13051 The keyword 
13052 \emph on
13053 banked
13054 \emph default
13055  is used to support 16 bit addresses in I/O memory e.g.:
13056 \end_layout
13057
13058 \begin_layout Verse
13059
13060 \family typewriter
13061 sfr banked at
13062 \begin_inset LatexCommand \index{at}
13063
13064 \end_inset
13065
13066
13067 \begin_inset LatexCommand \index{\_\_at}
13068
13069 \end_inset
13070
13071  0x123 IoPort; 
13072 \end_layout
13073
13074 \begin_layout Standard
13075 Writing 0x01 to this variable generates the assembly code:
13076 \end_layout
13077
13078 \begin_layout Verse
13079
13080 \family typewriter
13081 01 23 01\InsetSpace ~
13082 \InsetSpace ~
13083 \InsetSpace ~
13084 ld bc,#_IoPort
13085 \newline
13086 3E 01\InsetSpace ~
13087 \InsetSpace ~
13088 \InsetSpace ~
13089 \InsetSpace ~
13090 \InsetSpace ~
13091 \InsetSpace ~
13092 ld a,#0x01 
13093 \newline
13094 ED 79\InsetSpace ~
13095 \InsetSpace ~
13096 \InsetSpace ~
13097 \InsetSpace ~
13098 \InsetSpace ~
13099 \InsetSpace ~
13100 out (c),a 
13101 \end_layout
13102
13103 \begin_layout Subsubsection
13104 sfr
13105 \begin_inset LatexCommand \index{sfr}
13106
13107 \end_inset
13108
13109
13110 \begin_inset LatexCommand \index{\_\_sfr}
13111
13112 \end_inset
13113
13114  (in0/out0 to 8 bit addresses on Z180
13115 \begin_inset LatexCommand \index{Z180}
13116
13117 \end_inset
13118
13119 /HD64180
13120 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13121
13122 \end_inset
13123
13124 )
13125 \end_layout
13126
13127 \begin_layout Standard
13128 The compiler option -
13129 \begin_inset ERT
13130 status collapsed
13131
13132 \begin_layout Standard
13133
13134
13135 \backslash
13136 /
13137 \end_layout
13138
13139 \end_inset
13140
13141 -portmode
13142 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13143
13144 \end_inset
13145
13146 =180 (80) and a compiler #pragma\InsetSpace ~
13147 portmode
13148 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13149
13150 \end_inset
13151
13152  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13153 ns 
13154 \family typewriter
13155 in0/out0
13156 \family default
13157  instead of 
13158 \family typewriter
13159 in/out
13160 \family default
13161 .
13162  If you include the file z180.h this will be set automatically.
13163 \begin_inset VSpace bigskip
13164 \end_inset
13165
13166
13167 \end_layout
13168
13169 \begin_layout Subsection
13170 HC08 Storage Class
13171 \begin_inset LatexCommand \index{HC08!Storage class}
13172
13173 \end_inset
13174
13175  Language Extensions
13176 \end_layout
13177
13178 \begin_layout Subsubsection
13179 data
13180 \begin_inset LatexCommand \index{data (hc08 storage class)}
13181
13182 \end_inset
13183
13184
13185 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13186
13187 \end_inset
13188
13189  
13190 \end_layout
13191
13192 \begin_layout Standard
13193 The data storage class declares a variable that resides in the first 256
13194  bytes of memory (the direct page).
13195  The HC08
13196 \begin_inset LatexCommand \index{HC08}
13197
13198 \end_inset
13199
13200  is most efficient at accessing variables (especially pointers) stored here.
13201 \end_layout
13202
13203 \begin_layout Subsubsection
13204 xdata
13205 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13206
13207 \end_inset
13208
13209
13210 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13211
13212 \end_inset
13213
13214  
13215 \end_layout
13216
13217 \begin_layout Standard
13218 The xdata storage class declares a variable that can reside anywhere in
13219  memory.
13220  This is the default if no storage class is specified.
13221  
13222 \begin_inset VSpace bigskip
13223 \end_inset
13224
13225
13226 \end_layout
13227
13228 \begin_layout Section
13229 Other SDCC language extensions
13230 \begin_inset LatexCommand \index{Other SDCC language extensions}
13231
13232 \end_inset
13233
13234
13235 \end_layout
13236
13237 \begin_layout Subsection
13238 Binary constants
13239 \end_layout
13240
13241 \begin_layout Standard
13242 SDCC supports the use of binary constants, such as 0b01100010.
13243  This feature is only enabled when the compiler is invoked using --std-sdccxx.
13244 \end_layout
13245
13246 \begin_layout Standard
13247 \begin_inset VSpace bigskip
13248 \end_inset
13249
13250
13251 \end_layout
13252
13253 \begin_layout Section
13254 Absolute Addressing
13255 \begin_inset LatexCommand \index{Absolute addressing}
13256
13257 \end_inset
13258
13259
13260 \end_layout
13261
13262 \begin_layout Standard
13263 Data items can be assigned an absolute address with the 
13264 \emph on
13265 at
13266 \begin_inset LatexCommand \index{at}
13267
13268 \end_inset
13269
13270
13271 \begin_inset LatexCommand \index{\_\_at}
13272
13273 \end_inset
13274
13275  <address>
13276 \emph default
13277  keyword, in addition to a storage class, e.g.:
13278 \end_layout
13279
13280 \begin_layout Verse
13281
13282 \family typewriter
13283 xdata
13284 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13285
13286 \end_inset
13287
13288
13289 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13290
13291 \end_inset
13292
13293  at
13294 \begin_inset LatexCommand \index{at}
13295
13296 \end_inset
13297
13298
13299 \begin_inset LatexCommand \index{\_\_at}
13300
13301 \end_inset
13302
13303  0x7ffe unsigned int chksum;
13304 \end_layout
13305
13306 \begin_layout Standard
13307 or, better conforming to ISO/IEC 9899 C:
13308 \end_layout
13309
13310 \begin_layout Verse
13311
13312 \family typewriter
13313 __xdata __at (0x7ffe) unsigned int chksum;
13314 \end_layout
13315
13316 \begin_layout Standard
13317 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13318  of the external ram.
13319  The compiler does 
13320 \emph on
13321 not
13322 \emph default
13323  reserve any space for variables declared in this way
13324 \begin_inset Marginal
13325 status collapsed
13326
13327 \begin_layout Standard
13328
13329 \series bold
13330 \InsetSpace ~
13331 !
13332 \end_layout
13333
13334 \end_inset
13335
13336  (they are implemented with an equate in the assembler).
13337  Thus it is left to the programmer to make sure there are no overlaps with
13338  other variables that are declared without the absolute address.
13339  The assembler listing file (.lst
13340 \begin_inset LatexCommand \index{<file>.lst}
13341
13342 \end_inset
13343
13344 ) and the linker output files (.rst
13345 \begin_inset LatexCommand \index{<file>.rst}
13346
13347 \end_inset
13348
13349 ) and (.map
13350 \begin_inset LatexCommand \index{<file>.map}
13351
13352 \end_inset
13353
13354 ) are good places to look for such overlaps.
13355 \end_layout
13356
13357 \begin_layout Standard
13358 If however you provide an initializer
13359 \begin_inset LatexCommand \index{Variable initialization}
13360
13361 \end_inset
13362
13363  actual memory allocation will take place and overlaps will be detected
13364  by the linker.
13365  E.g.:
13366 \end_layout
13367
13368 \begin_layout Verse
13369
13370 \family typewriter
13371 __code __at (0x7ff0) char Id[5] = 
13372 \begin_inset Quotes sld
13373 \end_inset
13374
13375 SDCC
13376 \begin_inset Quotes srd
13377 \end_inset
13378
13379 ;
13380 \end_layout
13381
13382 \begin_layout Standard
13383 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13384  in code memory.
13385 \end_layout
13386
13387 \begin_layout Standard
13388 In case of memory mapped I/O devices the keyword 
13389 \emph on
13390 volatile
13391 \emph default
13392  has to be used to tell the compiler that accesses might not be removed:
13393 \end_layout
13394
13395 \begin_layout Verse
13396
13397 \family typewriter
13398 volatile
13399 \begin_inset LatexCommand \index{volatile}
13400
13401 \end_inset
13402
13403  __xdata
13404 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13405
13406 \end_inset
13407
13408  __at
13409 \begin_inset LatexCommand \index{at}
13410
13411 \end_inset
13412
13413  (0x8000) unsigned char PORTA_8255;
13414 \end_layout
13415
13416 \begin_layout Standard
13417 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13418 r) array
13419 \family typewriter
13420 \size footnotesize
13421
13422 \begin_inset LatexCommand \index{Aligned array}
13423
13424 \end_inset
13425
13426
13427 \family default
13428 \size default
13429  starts at a block (256 byte) boundary
13430 \begin_inset LatexCommand \index{block boundary}
13431
13432 \end_inset
13433
13434  (section 
13435 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13436
13437 \end_inset
13438
13439  has an example).
13440 \newline
13441 Absolute addresses can be specified for variables in all
13442  storage classes, e.g.:
13443 \end_layout
13444
13445 \begin_layout Verse
13446
13447 \family typewriter
13448 __bit
13449 \begin_inset LatexCommand \index{bit}
13450
13451 \end_inset
13452
13453  __at
13454 \begin_inset LatexCommand \index{at}
13455
13456 \end_inset
13457
13458  (0x02) bvar;
13459 \end_layout
13460
13461 \begin_layout Standard
13462 The above example will allocate the variable at offset 0x02 in the bit-addressab
13463 le space.
13464  There is no real advantage to assigning absolute addresses to variables
13465  in this manner, unless you want strict control over all the variables allocated.
13466  One possible use would be to write hardware portable code.
13467  For example, if you have a routine that uses one or more of the microcontroller
13468  I/O pins, and such pins are different for two different hardwares, you
13469  can declare the I/O pins in your routine using:
13470 \end_layout
13471
13472 \begin_layout Verse
13473
13474 \family typewriter
13475 extern volatile
13476 \begin_inset LatexCommand \index{volatile}
13477
13478 \end_inset
13479
13480  __bit MOSI;\InsetSpace ~
13481 \InsetSpace ~
13482 \InsetSpace ~
13483 \InsetSpace ~
13484 /* master out, slave in */
13485 \newline
13486 extern volatile __bit MISO;\InsetSpace ~
13487 \InsetSpace ~
13488 \InsetSpace ~
13489 \InsetSpace ~
13490 /* master
13491  in, slave out */
13492 \newline
13493 extern volatile __bit MCLK;\InsetSpace ~
13494 \InsetSpace ~
13495 \InsetSpace ~
13496 \InsetSpace ~
13497 /* master clock */
13498 \newline
13499
13500 \newline
13501 /* Input and
13502  Output of a byte on a 3-wire serial bus.
13503 \newline
13504 \InsetSpace ~
13505 \InsetSpace ~
13506 \InsetSpace ~
13507 If needed adapt polarity of clock,
13508  polarity of data and bit order
13509 \newline
13510 \InsetSpace ~
13511 */
13512 \newline
13513 unsigned char spi_io(unsigned char out_byte)
13514  
13515 \newline
13516
13517 \newline
13518 \InsetSpace ~
13519 \InsetSpace ~
13520 \InsetSpace ~
13521 \InsetSpace ~
13522 unsigned char i=8;
13523 \newline
13524 \InsetSpace ~
13525 \InsetSpace ~
13526 \InsetSpace ~
13527 \InsetSpace ~
13528 do { 
13529 \newline
13530 \InsetSpace ~
13531 \InsetSpace ~
13532 \InsetSpace ~
13533 \InsetSpace ~
13534 \InsetSpace ~
13535 \InsetSpace ~
13536 \InsetSpace ~
13537 \InsetSpace ~
13538 MOSI = out_byte & 0x80; 
13539 \newline
13540 \InsetSpace ~
13541 \InsetSpace ~
13542 \InsetSpace ~
13543 \InsetSpace ~
13544 \InsetSpace ~
13545 \InsetSpace ~
13546 \InsetSpace ~
13547 \InsetSpace ~
13548 out_byte <<= 1;
13549 \newline
13550 \InsetSpace ~
13551 \InsetSpace ~
13552 \InsetSpace ~
13553 \InsetSpace ~
13554 \InsetSpace ~
13555 \InsetSpace ~
13556 \InsetSpace ~
13557 \InsetSpace ~
13558 MCLK =
13559  1; 
13560 \newline
13561 \InsetSpace ~
13562 \InsetSpace ~
13563 \InsetSpace ~
13564 \InsetSpace ~
13565 \InsetSpace ~
13566 \InsetSpace ~
13567 \InsetSpace ~
13568 \InsetSpace ~
13569 /* _asm nop _endasm; */\InsetSpace ~
13570 \InsetSpace ~
13571 \InsetSpace ~
13572 \InsetSpace ~
13573 \InsetSpace ~
13574 \InsetSpace ~
13575 \InsetSpace ~
13576 \InsetSpace ~
13577 /* for slow peripherals */
13578 \newline
13579 \InsetSpace ~
13580 \InsetSpace ~
13581 \InsetSpace ~
13582 \InsetSpace ~
13583 \InsetSpace ~
13584 \InsetSpace ~
13585 \InsetSpace ~
13586 \InsetSpace ~
13587 if(MISO) 
13588 \newline
13589 \InsetSpace ~
13590 \InsetSpace ~
13591 \InsetSpace ~
13592 \InsetSpace ~
13593 \InsetSpace ~
13594 \InsetSpace ~
13595 \InsetSpace ~
13596 \InsetSpace ~
13597 \InsetSpace ~
13598 \InsetSpace ~
13599 \InsetSpace ~
13600 \InsetSpace ~
13601 out_byte +=
13602  1; 
13603 \newline
13604 \InsetSpace ~
13605 \InsetSpace ~
13606 \InsetSpace ~
13607 \InsetSpace ~
13608 \InsetSpace ~
13609 \InsetSpace ~
13610 \InsetSpace ~
13611 \InsetSpace ~
13612 MCLK = 0; 
13613 \newline
13614 \InsetSpace ~
13615 \InsetSpace ~
13616 \InsetSpace ~
13617 \InsetSpace ~
13618 } while(--i);
13619 \newline
13620 \InsetSpace ~
13621 \InsetSpace ~
13622 \InsetSpace ~
13623 \InsetSpace ~
13624 return out_byte; 
13625 \newline
13626 }
13627 \end_layout
13628
13629 \begin_layout Standard
13630 Then, someplace in the code for the first hardware you would use
13631 \end_layout
13632
13633 \begin_layout Verse
13634
13635 \family typewriter
13636 __bit __at
13637 \begin_inset LatexCommand \index{at}
13638
13639 \end_inset
13640
13641
13642 \begin_inset LatexCommand \index{\_\_at}
13643
13644 \end_inset
13645
13646  (0x80) MOSI;\InsetSpace ~
13647 \InsetSpace ~
13648 \InsetSpace ~
13649 \InsetSpace ~
13650 /* I/O port 0, bit 0 */
13651 \newline
13652 __bit __at (0x81) MISO;\InsetSpace ~
13653 \InsetSpace ~
13654 \InsetSpace ~
13655 \InsetSpace ~
13656 /* I/O port 0,
13657  bit 1 */
13658 \newline
13659 __bit __at (0x82) MCLK;\InsetSpace ~
13660 \InsetSpace ~
13661 \InsetSpace ~
13662 \InsetSpace ~
13663 /* I/O port 0, bit 2 */
13664 \end_layout
13665
13666 \begin_layout Standard
13667 Similarly, for the second hardware you would use
13668 \end_layout
13669
13670 \begin_layout Verse
13671
13672 \family typewriter
13673 __bit __at (0x83) MOSI;\InsetSpace ~
13674 \InsetSpace ~
13675 \InsetSpace ~
13676 \InsetSpace ~
13677 /* I/O port 0, bit 3 */
13678 \newline
13679 __bit __at (0x91) MISO;\InsetSpace ~
13680 \InsetSpace ~
13681 \InsetSpace ~
13682 \InsetSpace ~
13683 /*
13684  I/O port 1, bit 1 */
13685 \newline
13686 __bit
13687 \begin_inset LatexCommand \index{bit}
13688
13689 \end_inset
13690
13691  __at (0x92) MCLK;\InsetSpace ~
13692 \InsetSpace ~
13693 \InsetSpace ~
13694 \InsetSpace ~
13695 /* I/O port 1, bit 2 */
13696 \end_layout
13697
13698 \begin_layout Standard
13699 and you can use the same hardware dependent routine without changes, as
13700  for example in a library.
13701  This is somehow similar to sbit, but only one absolute address has to be
13702  specified in the whole project.
13703 \begin_inset VSpace bigskip
13704 \end_inset
13705
13706
13707 \end_layout
13708
13709 \begin_layout Section
13710 Parameters
13711 \begin_inset LatexCommand \index{Parameters}
13712
13713 \end_inset
13714
13715
13716 \begin_inset LatexCommand \index{function parameter}
13717
13718 \end_inset
13719
13720  & Local Variables
13721 \begin_inset LatexCommand \index{local variables}
13722
13723 \end_inset
13724
13725
13726 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13727
13728 \end_inset
13729
13730
13731 \end_layout
13732
13733 \begin_layout Standard
13734 Automatic (local) variables and parameters to functions can either be placed
13735  on the stack or in data-space.
13736  The default action of the compiler is to place these variables in the internal
13737  RAM (for small model) or external RAM (for medium or large model).
13738  This in fact makes them similar to 
13739 \emph on
13740 static
13741 \begin_inset LatexCommand \index{static}
13742
13743 \end_inset
13744
13745
13746 \emph default
13747  so by default functions are non-reentrant
13748 \begin_inset LatexCommand \index{reentrant}
13749
13750 \end_inset
13751
13752 .
13753  
13754 \newline
13755
13756 \newline
13757 They can be placed on the stack
13758 \begin_inset LatexCommand \index{stack}
13759
13760 \end_inset
13761
13762  by using the
13763 \emph on
13764  -
13765 \begin_inset ERT
13766 status collapsed
13767
13768 \begin_layout Standard
13769
13770
13771 \backslash
13772 /
13773 \end_layout
13774
13775 \end_inset
13776
13777 -stack-auto
13778 \begin_inset LatexCommand \index{-\/-stack-auto}
13779
13780 \end_inset
13781
13782
13783 \emph default
13784  option, by using 
13785 \emph on
13786 #pragma\InsetSpace ~
13787 stackauto
13788 \emph default
13789
13790 \begin_inset LatexCommand \index{\#pragma stackauto}
13791
13792 \end_inset
13793
13794  or by using the 
13795 \emph on
13796 reentrant
13797 \begin_inset LatexCommand \index{reentrant}
13798
13799 \end_inset
13800
13801
13802 \emph default
13803  keyword in the function declaration, e.g.:
13804 \end_layout
13805
13806 \begin_layout Verse
13807
13808 \family typewriter
13809 unsigned char foo(char i) __reentrant 
13810 \newline
13811
13812 \newline
13813 \InsetSpace ~
13814 \InsetSpace ~
13815 \InsetSpace ~
13816 \InsetSpace ~
13817 ...
13818  
13819 \newline
13820 }
13821 \end_layout
13822
13823 \begin_layout Standard
13824 Since stack space on 8051 is limited, the 
13825 \emph on
13826 reentrant 
13827 \emph default
13828 keyword or the
13829 \emph on
13830  -
13831 \begin_inset ERT
13832 status collapsed
13833
13834 \begin_layout Standard
13835
13836
13837 \backslash
13838 /
13839 \end_layout
13840
13841 \end_inset
13842
13843 -stack-auto
13844 \emph default
13845  option should be used sparingly.
13846  Note that the reentrant keyword just means that the parameters & local
13847  variables will be allocated to the stack, it 
13848 \emph on
13849 does not
13850 \emph default
13851  mean that the function is register bank
13852 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13853
13854 \end_inset
13855
13856  independent.
13857 \newline
13858
13859 \newline
13860 Local variables
13861 \begin_inset LatexCommand \index{local variables}
13862
13863 \end_inset
13864
13865  can be assigned storage classes and absolute
13866 \begin_inset LatexCommand \index{Absolute addressing}
13867
13868 \end_inset
13869
13870  addresses, e.g.: 
13871 \end_layout
13872
13873 \begin_layout Verse
13874
13875 \family typewriter
13876 unsigned char foo() 
13877 \newline
13878 {
13879 \newline
13880 \InsetSpace ~
13881 \InsetSpace ~
13882 \InsetSpace ~
13883 \InsetSpace ~
13884 __xdata unsigned char i;
13885 \newline
13886 \InsetSpace ~
13887 \InsetSpace ~
13888 \InsetSpace ~
13889 \InsetSpace ~
13890 __bit bvar;
13891 \newline
13892 \InsetSpace ~
13893 \InsetSpace ~
13894 \InsetSpace ~
13895 \InsetSpace ~
13896 __data __at
13897 \begin_inset LatexCommand \index{at}
13898
13899 \end_inset
13900
13901  (0x31) unsigned char j;
13902 \newline
13903 \InsetSpace ~
13904 \InsetSpace ~
13905 \InsetSpace ~
13906 \InsetSpace ~
13907 ...
13908  
13909 \newline
13910 }
13911 \end_layout
13912
13913 \begin_layout Standard
13914 In the above example the variable 
13915 \emph on
13916 i
13917 \emph default
13918  will be allocated in the external ram, 
13919 \emph on
13920 bvar
13921 \emph default
13922  in bit addressable space and
13923 \emph on
13924  j
13925 \emph default
13926  in internal ram.
13927  When compiled with 
13928 \emph on
13929 -
13930 \begin_inset ERT
13931 status collapsed
13932
13933 \begin_layout Standard
13934
13935
13936 \backslash
13937 /
13938 \end_layout
13939
13940 \end_inset
13941
13942 -stack-auto
13943 \emph default
13944  or when a function is declared as 
13945 \emph on
13946 reentrant
13947 \emph default
13948  this should only be done for static variables.
13949 \end_layout
13950
13951 \begin_layout Standard
13952 Parameters
13953 \begin_inset LatexCommand \index{function parameter}
13954
13955 \end_inset
13956
13957  however are not allowed any storage class
13958 \begin_inset LatexCommand \index{Storage class}
13959
13960 \end_inset
13961
13962 , (storage classes for parameters will be ignored), their allocation is
13963  governed by the memory model in use, and the reentrancy options.
13964 \end_layout
13965
13966 \begin_layout Standard
13967 It is however allowed to use bit parameters in reentrant functions and also
13968  non-static local bit variables are supported.
13969  Efficient use is limited to 8 semi-bitregisters in bit space.
13970  They are pushed and popped to stack
13971 \begin_inset LatexCommand \index{stack}
13972
13973 \end_inset
13974
13975  as a single byte just like the normal registers.
13976 \end_layout
13977
13978 \begin_layout Section
13979 Overlaying
13980 \begin_inset LatexCommand \label{sub:Overlaying}
13981
13982 \end_inset
13983
13984
13985 \begin_inset LatexCommand \index{Overlaying}
13986
13987 \end_inset
13988
13989
13990 \end_layout
13991
13992 \begin_layout Standard
13993 For non-reentrant
13994 \begin_inset LatexCommand \index{reentrant}
13995
13996 \end_inset
13997
13998  functions SDCC will try to reduce internal ram space usage by overlaying
13999  parameters and local variables of a function (if possible).
14000  Parameters and local variables
14001 \begin_inset LatexCommand \index{local variables}
14002
14003 \end_inset
14004
14005  of a function will be allocated to an overlayable segment if the function
14006  has 
14007 \emph on
14008 no other function calls and the function is non-reentrant and the memory
14009  model
14010 \begin_inset LatexCommand \index{Memory model}
14011
14012 \end_inset
14013
14014  is small.
14015
14016 \emph default
14017  If an explicit storage class
14018 \begin_inset LatexCommand \index{Storage class}
14019
14020 \end_inset
14021
14022  is specified for a local variable, it will NOT be overlayed.
14023 \end_layout
14024
14025 \begin_layout Standard
14026 Note that the compiler (not the linkage editor) makes the decision for overlayin
14027 g the data items.
14028  Functions that are called from an interrupt service routine
14029 \begin_inset Marginal
14030 status collapsed
14031
14032 \begin_layout Standard
14033
14034 \series bold
14035 !
14036 \end_layout
14037
14038 \end_inset
14039
14040  should be preceded by a #pragma\InsetSpace ~
14041 nooverlay
14042 \begin_inset LatexCommand \index{\#pragma nooverlay}
14043
14044 \end_inset
14045
14046  if they are not reentrant.
14047 \end_layout
14048
14049 \begin_layout Standard
14050 Also note that the compiler does not do any processing of inline assembler
14051  code, so the compiler might incorrectly assign local variables and parameters
14052  of a function into the overlay segment if the inline assembler code calls
14053  other c-functions that might use the overlay.
14054  In that case the #pragma\InsetSpace ~
14055 nooverlay should be used.
14056 \end_layout
14057
14058 \begin_layout Standard
14059 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14060 tion
14061 \begin_inset LatexCommand \index{Multiplication}
14062
14063 \end_inset
14064
14065  or division
14066 \begin_inset LatexCommand \index{Division}
14067
14068 \end_inset
14069
14070  will NOT be overlayed since these are implemented using external functions,
14071  e.g.:
14072 \end_layout
14073
14074 \begin_layout Verse
14075
14076 \family typewriter
14077 #pragma save 
14078 \newline
14079 #pragma nooverlay
14080 \begin_inset LatexCommand \index{\#pragma nooverlay}
14081
14082 \end_inset
14083
14084  
14085 \newline
14086 void set_error(unsigned char errcd) 
14087 \newline
14088 {
14089 \newline
14090 \InsetSpace ~
14091 \InsetSpace ~
14092 \InsetSpace ~
14093 \InsetSpace ~
14094 P3 = errcd;
14095 \newline
14096
14097 \newline
14098 #pragma restore 
14099 \newline
14100
14101 \newline
14102 void
14103  some_isr () __interrupt
14104 \begin_inset LatexCommand \index{interrupt}
14105
14106 \end_inset
14107
14108  (2)
14109 \newline
14110 {
14111 \newline
14112 \InsetSpace ~
14113 \InsetSpace ~
14114 \InsetSpace ~
14115 \InsetSpace ~
14116 ...
14117 \newline
14118 \InsetSpace ~
14119 \InsetSpace ~
14120 \InsetSpace ~
14121 \InsetSpace ~
14122 set_error(10);
14123 \newline
14124 \InsetSpace ~
14125 \InsetSpace ~
14126 \InsetSpace ~
14127 \InsetSpace ~
14128 ...
14129  
14130 \newline
14131 }
14132 \end_layout
14133
14134 \begin_layout Standard
14135 In the above example the parameter 
14136 \emph on
14137 errcd
14138 \emph default
14139  for the function 
14140 \emph on
14141 set_error
14142 \emph default
14143  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14144 nooverlay was
14145  not present, this could cause unpredictable runtime behavior when called
14146  from an interrupt service routine.
14147  The #pragma\InsetSpace ~
14148 nooverlay ensures that the parameters and local variables for
14149  the function are NOT overlayed.
14150 \begin_inset VSpace bigskip
14151 \end_inset
14152
14153
14154 \end_layout
14155
14156 \begin_layout Section
14157 Interrupt Service Routines
14158 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14159
14160 \end_inset
14161
14162
14163 \end_layout
14164
14165 \begin_layout Subsection
14166 General Information
14167 \end_layout
14168
14169 \begin_layout Standard
14170 SDCC allows 
14171 \emph on
14172 i
14173 \emph default
14174 nterrupt 
14175 \emph on
14176 s
14177 \emph default
14178 ervice 
14179 \emph on
14180 r
14181 \emph default
14182 outines to be coded in C, with some extended keywords.
14183 \end_layout
14184
14185 \begin_layout Verse
14186
14187 \family typewriter
14188 void timer_isr (void) __interrupt (1) __using (1) 
14189 \newline
14190
14191 \newline
14192 \InsetSpace ~
14193 \InsetSpace ~
14194 \InsetSpace ~
14195 \InsetSpace ~
14196 ...
14197  
14198 \newline
14199 }
14200 \end_layout
14201
14202 \begin_layout Standard
14203 The optional number following the 
14204 \emph on
14205 interrupt
14206 \begin_inset LatexCommand \index{interrupt}
14207
14208 \end_inset
14209
14210
14211 \begin_inset LatexCommand \index{\_\_interrupt}
14212
14213 \end_inset
14214
14215
14216 \emph default
14217  keyword is the interrupt number this routine will service.
14218  When present, the compiler will insert a call to this routine in the interrupt
14219  vector table
14220 \begin_inset LatexCommand \index{interrupt vector table}
14221
14222 \end_inset
14223
14224  for the interrupt number specified.
14225  If you have multiple source files in your project, interrupt service routines
14226  can be present in any of them, but a prototype of the isr MUST be present
14227  or included in the file that contains the function 
14228 \emph on
14229 main
14230 \emph default
14231 .
14232  The optional (8051 specific) keyword 
14233 \emph on
14234 using
14235 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14236
14237 \end_inset
14238
14239
14240 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14241
14242 \end_inset
14243
14244
14245 \emph default
14246  can be used to tell the compiler to use the specified register bank when
14247  generating code for this function.
14248  
14249 \newline
14250 Interrupt service routines open the door for some very interesting bugs:
14251 \end_layout
14252
14253 \begin_layout Subsubsection
14254 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14255
14256 \end_inset
14257
14258 Common interrupt pitfall: variable not declared 
14259 \emph on
14260 volatile
14261 \end_layout
14262
14263 \begin_layout Standard
14264 If an interrupt service routine changes variables which are accessed by
14265  other functions these variables have to be declared 
14266 \emph on
14267 volatile
14268 \emph default
14269
14270 \begin_inset LatexCommand \index{volatile}
14271
14272 \end_inset
14273
14274 .
14275  See 
14276 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14277
14278 \end_inset
14279
14280  .
14281 \end_layout
14282
14283 \begin_layout Subsubsection
14284 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14285
14286 \end_inset
14287
14288 Common interrupt pitfall: 
14289 \emph on
14290 non-atomic access
14291 \end_layout
14292
14293 \begin_layout Standard
14294 If the access to these variables is not 
14295 \emph on
14296 atomic
14297 \begin_inset LatexCommand \index{atomic}
14298
14299 \end_inset
14300
14301
14302 \emph default
14303  (i.e.
14304  the processor needs more than one instruction for the access and could
14305  be interrupted while accessing the variable) the interrupt must be disabled
14306  during the access to avoid inconsistent data.
14307  
14308 \newline
14309 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14310  and should be protected by disabling interrupts.
14311  You're not automatically on the safe side if you use 8 bit variables though.
14312  We need an example here: f.e.
14313  on the 8051 the harmless looking 
14314 \begin_inset Quotes srd
14315 \end_inset
14316
14317
14318 \family typewriter
14319 flags\InsetSpace ~
14320 |=\InsetSpace ~
14321 0x80;
14322 \family default
14323
14324 \begin_inset Quotes sld
14325 \end_inset
14326
14327  is not atomic if 
14328 \family typewriter
14329 flags
14330 \family default
14331  resides in xdata.
14332  Setting 
14333 \begin_inset Quotes srd
14334 \end_inset
14335
14336
14337 \family typewriter
14338 flags\InsetSpace ~
14339 |=\InsetSpace ~
14340 0x40;
14341 \family default
14342
14343 \begin_inset Quotes sld
14344 \end_inset
14345
14346  from within an interrupt routine might get lost if the interrupt occurs
14347  at the wrong time.
14348  
14349 \begin_inset Quotes sld
14350 \end_inset
14351
14352
14353 \family typewriter
14354 counter\InsetSpace ~
14355 +=\InsetSpace ~
14356 8;
14357 \family default
14358
14359 \begin_inset Quotes srd
14360 \end_inset
14361
14362  is not atomic on the 8051 even if 
14363 \family typewriter
14364 counter
14365 \family default
14366  is located in data memory.
14367 \newline
14368 Bugs like these are hard to reproduce and can
14369  cause a lot of trouble.
14370  
14371 \end_layout
14372
14373 \begin_layout Subsubsection
14374 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14375
14376 \end_inset
14377
14378 Common interrupt pitfall: 
14379 \emph on
14380 stack overflow
14381 \end_layout
14382
14383 \begin_layout Standard
14384 The return address and the registers used in the interrupt service routine
14385  are saved on the stack
14386 \begin_inset LatexCommand \index{stack}
14387
14388 \end_inset
14389
14390  so there must be sufficient stack space.
14391  If there isn't variables or registers (or even the return address itself)
14392  will be corrupted.
14393  This 
14394 \emph on
14395 stack overflow
14396 \emph default
14397
14398 \begin_inset LatexCommand \index{stack overflow}
14399
14400 \end_inset
14401
14402  is most likely to happen if the interrupt occurs during the 
14403 \begin_inset Quotes sld
14404 \end_inset
14405
14406 deepest
14407 \begin_inset Quotes srd
14408 \end_inset
14409
14410  subroutine when the stack is already in use for f.e.
14411  many return addresses.
14412 \end_layout
14413
14414 \begin_layout Subsubsection
14415 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14416
14417 \end_inset
14418
14419 Common interrupt pitfall: 
14420 \emph on
14421 use of non-reentrant functions
14422 \end_layout
14423
14424 \begin_layout Standard
14425 A special note here, int (16 bit) and long (32 bit) integer division
14426 \begin_inset LatexCommand \index{Division}
14427
14428 \end_inset
14429
14430 , multiplication
14431 \begin_inset LatexCommand \index{Multiplication}
14432
14433 \end_inset
14434
14435  & modulus
14436 \begin_inset LatexCommand \index{Modulus}
14437
14438 \end_inset
14439
14440  and floating-point
14441 \begin_inset LatexCommand \index{Floating point support}
14442
14443 \end_inset
14444
14445  operations are implemented using external support routines.
14446  If an interrupt service routine needs to do any of these operations then
14447  the support routines (as mentioned in a following section) will have to
14448  be recompiled using the
14449 \emph on
14450  -
14451 \begin_inset ERT
14452 status collapsed
14453
14454 \begin_layout Standard
14455
14456
14457 \backslash
14458 /
14459 \end_layout
14460
14461 \end_inset
14462
14463 -stack-auto
14464 \begin_inset LatexCommand \index{-\/-stack-auto}
14465
14466 \end_inset
14467
14468
14469 \emph default
14470  option and the source file will need to be compiled using the 
14471 \emph on
14472 -
14473 \begin_inset ERT
14474 status collapsed
14475
14476 \begin_layout Standard
14477
14478
14479 \backslash
14480 /
14481 \end_layout
14482
14483 \end_inset
14484
14485 -int-long-reent
14486 \emph default
14487
14488 \begin_inset LatexCommand \index{-\/-int-long-reent}
14489
14490 \end_inset
14491
14492  compiler option.
14493  
14494 \newline
14495 Note, the type promotion
14496 \begin_inset LatexCommand \index{type promotion}
14497
14498 \end_inset
14499
14500  required by ANSI C can cause 16 bit routines to be used
14501 \begin_inset Marginal
14502 status collapsed
14503
14504 \begin_layout Standard
14505
14506 \series bold
14507 \InsetSpace ~
14508 !
14509 \end_layout
14510
14511 \end_inset
14512
14513  without the programmer being aware of it.
14514  See f.e.
14515  the cast 
14516 \family typewriter
14517 (unsigned char)(tail-1)
14518 \family default
14519  within the if clause in section 
14520 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14521
14522 \end_inset
14523
14524 .
14525 \end_layout
14526
14527 \begin_layout Standard
14528 Calling other functions from an interrupt service routine is not recommended,
14529  avoid it if possible.
14530  Note that when some function is called from an interrupt service routine
14531  it should be preceded by a #pragma\InsetSpace ~
14532 nooverlay
14533 \begin_inset LatexCommand \index{\#pragma nooverlay}
14534
14535 \end_inset
14536
14537  if it is not reentrant.
14538  Furthermore nonreentrant functions should not be called from the main program
14539  while the interrupt service routine might be active.
14540  They also must not be called from low priority interrupt service routines
14541  while a high priority interrupt service routine might be active.
14542  You could use semaphores or make the function
14543 \emph on
14544  critical
14545 \emph default
14546  if all parameters are passed in registers.
14547 \newline
14548  Also see section 
14549 \begin_inset LatexCommand \ref{sub:Overlaying}
14550
14551 \end_inset
14552
14553 \InsetSpace ~
14554 about Overlaying and section 
14555 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14556
14557 \end_inset
14558
14559 \InsetSpace ~
14560 about Functions using private register banks.
14561 \begin_inset VSpace bigskip
14562 \end_inset
14563
14564
14565 \end_layout
14566
14567 \begin_layout Subsection
14568 MCS51/DS390 Interrupt Service Routines
14569 \end_layout
14570
14571 \begin_layout Standard
14572 Interrupt
14573 \begin_inset LatexCommand \index{interrupt}
14574
14575 \end_inset
14576
14577  numbers and the corresponding address & descriptions for the Standard 8051/8052
14578  are listed below.
14579  SDCC will automatically adjust the 
14580 \begin_inset LatexCommand \index{interrupt vector table}
14581
14582 \end_inset
14583
14584  to the maximum interrupt number specified.
14585 \newline
14586
14587 \end_layout
14588
14589 \begin_layout Standard
14590 \align center
14591 \begin_inset Tabular
14592 <lyxtabular version="3" rows="9" columns="3">
14593 <features>
14594 <column alignment="center" valignment="top" leftline="true" width="0in">
14595 <column alignment="left" valignment="top" leftline="true" width="0in">
14596 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14597 <row topline="true" bottomline="true">
14598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14599 \begin_inset Text
14600
14601 \begin_layout Standard
14602 Interrupt #
14603 \end_layout
14604
14605 \end_inset
14606 </cell>
14607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14608 \begin_inset Text
14609
14610 \begin_layout Standard
14611 Description
14612 \end_layout
14613
14614 \end_inset
14615 </cell>
14616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14617 \begin_inset Text
14618
14619 \begin_layout Standard
14620 Vector Address
14621 \end_layout
14622
14623 \end_inset
14624 </cell>
14625 </row>
14626 <row topline="true">
14627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14628 \begin_inset Text
14629
14630 \begin_layout Standard
14631 0
14632 \end_layout
14633
14634 \end_inset
14635 </cell>
14636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14637 \begin_inset Text
14638
14639 \begin_layout Standard
14640 External 0
14641 \end_layout
14642
14643 \end_inset
14644 </cell>
14645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14646 \begin_inset Text
14647
14648 \begin_layout Standard
14649 0x0003
14650 \end_layout
14651
14652 \end_inset
14653 </cell>
14654 </row>
14655 <row topline="true">
14656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14657 \begin_inset Text
14658
14659 \begin_layout Standard
14660 1
14661 \end_layout
14662
14663 \end_inset
14664 </cell>
14665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14666 \begin_inset Text
14667
14668 \begin_layout Standard
14669 Timer 0
14670 \end_layout
14671
14672 \end_inset
14673 </cell>
14674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14675 \begin_inset Text
14676
14677 \begin_layout Standard
14678 0x000b
14679 \end_layout
14680
14681 \end_inset
14682 </cell>
14683 </row>
14684 <row topline="true">
14685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14686 \begin_inset Text
14687
14688 \begin_layout Standard
14689 2
14690 \end_layout
14691
14692 \end_inset
14693 </cell>
14694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14695 \begin_inset Text
14696
14697 \begin_layout Standard
14698 External 1
14699 \end_layout
14700
14701 \end_inset
14702 </cell>
14703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14704 \begin_inset Text
14705
14706 \begin_layout Standard
14707 0x0013
14708 \end_layout
14709
14710 \end_inset
14711 </cell>
14712 </row>
14713 <row topline="true">
14714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14715 \begin_inset Text
14716
14717 \begin_layout Standard
14718 3
14719 \end_layout
14720
14721 \end_inset
14722 </cell>
14723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14724 \begin_inset Text
14725
14726 \begin_layout Standard
14727 Timer 1
14728 \end_layout
14729
14730 \end_inset
14731 </cell>
14732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14733 \begin_inset Text
14734
14735 \begin_layout Standard
14736 0x001b
14737 \end_layout
14738
14739 \end_inset
14740 </cell>
14741 </row>
14742 <row topline="true">
14743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14744 \begin_inset Text
14745
14746 \begin_layout Standard
14747 4
14748 \end_layout
14749
14750 \end_inset
14751 </cell>
14752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14753 \begin_inset Text
14754
14755 \begin_layout Standard
14756 Serial
14757 \end_layout
14758
14759 \end_inset
14760 </cell>
14761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14762 \begin_inset Text
14763
14764 \begin_layout Standard
14765 0x0023
14766 \end_layout
14767
14768 \end_inset
14769 </cell>
14770 </row>
14771 <row topline="true">
14772 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14773 \begin_inset Text
14774
14775 \begin_layout Standard
14776 5
14777 \end_layout
14778
14779 \end_inset
14780 </cell>
14781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14782 \begin_inset Text
14783
14784 \begin_layout Standard
14785 Timer 2 (8052)
14786 \end_layout
14787
14788 \end_inset
14789 </cell>
14790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14791 \begin_inset Text
14792
14793 \begin_layout Standard
14794 0x002b
14795 \end_layout
14796
14797 \end_inset
14798 </cell>
14799 </row>
14800 <row topline="true">
14801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14802 \begin_inset Text
14803
14804 \begin_layout Standard
14805 ...
14806 \end_layout
14807
14808 \end_inset
14809 </cell>
14810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14811 \begin_inset Text
14812
14813 \begin_layout Standard
14814
14815 \end_layout
14816
14817 \end_inset
14818 </cell>
14819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14820 \begin_inset Text
14821
14822 \begin_layout Standard
14823 ...
14824 \end_layout
14825
14826 \end_inset
14827 </cell>
14828 </row>
14829 <row topline="true" bottomline="true">
14830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14831 \begin_inset Text
14832
14833 \begin_layout Standard
14834 n
14835 \end_layout
14836
14837 \end_inset
14838 </cell>
14839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14840 \begin_inset Text
14841
14842 \begin_layout Standard
14843
14844 \end_layout
14845
14846 \end_inset
14847 </cell>
14848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14849 \begin_inset Text
14850
14851 \begin_layout Standard
14852 0x0003 + 8*n
14853 \end_layout
14854
14855 \end_inset
14856 </cell>
14857 </row>
14858 </lyxtabular>
14859
14860 \end_inset
14861
14862
14863 \newline
14864
14865 \end_layout
14866
14867 \begin_layout Standard
14868 If the interrupt service routine is defined without 
14869 \emph on
14870 using
14871 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14872
14873 \end_inset
14874
14875
14876 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14877
14878 \end_inset
14879
14880
14881 \emph default
14882  a register bank or with register bank 0 (
14883 \emph on
14884 using
14885 \emph default
14886  0), the compiler will save the registers used by itself on the stack upon
14887  entry and restore them at exit, however if such an interrupt service routine
14888  calls another function then the entire register bank will be saved on the
14889  stack.
14890  This scheme may be advantageous for small interrupt service routines which
14891  have low register usage.
14892 \end_layout
14893
14894 \begin_layout Standard
14895 If the interrupt service routine is defined to be using a specific register
14896  bank then only 
14897 \emph on
14898 a, b, dptr
14899 \emph default
14900  & psw are saved and restored, if such an interrupt service routine calls
14901  another function (using another register bank) then the entire register
14902  bank of the called function will be saved on the stack
14903 \begin_inset LatexCommand \index{stack}
14904
14905 \end_inset
14906
14907 .
14908  This scheme is recommended for larger interrupt service routines.
14909 \begin_inset VSpace bigskip
14910 \end_inset
14911
14912
14913 \end_layout
14914
14915 \begin_layout Subsection
14916 HC08
14917 \begin_inset LatexCommand \index{HC08}
14918
14919 \end_inset
14920
14921  Interrupt Service Routines
14922 \end_layout
14923
14924 \begin_layout Standard
14925 Since the number of interrupts
14926 \begin_inset LatexCommand \index{HC08!interrupt}
14927
14928 \end_inset
14929
14930  available is chip specific and the interrupt vector table always ends at
14931  the last byte of memory, the interrupt numbers corresponds to the interrupt
14932  vectors in reverse order of address.
14933  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14934  2 will use the interrupt vector at 0xfffa, and so on.
14935  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14936  this way; instead see section 
14937 \begin_inset LatexCommand \ref{sub:Startup-Code}
14938
14939 \end_inset
14940
14941  for details on customizing startup.
14942 \begin_inset VSpace bigskip
14943 \end_inset
14944
14945
14946 \end_layout
14947
14948 \begin_layout Subsection
14949 Z80 Interrupt Service Routines
14950 \end_layout
14951
14952 \begin_layout Standard
14953 The Z80
14954 \begin_inset LatexCommand \index{Z80}
14955
14956 \end_inset
14957
14958  uses several different methods for determining the correct interrupt
14959 \begin_inset LatexCommand \index{Z80!interrupt}
14960
14961 \end_inset
14962
14963  vector depending on the hardware implementation.
14964  Therefore, SDCC ignores the optional interrupt number and does not attempt
14965  to generate an interrupt vector table.
14966 \end_layout
14967
14968 \begin_layout Standard
14969 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14970  instruction to return from the interrupt.
14971  To write an interrupt handler for the non-maskable interrupt, which needs
14972  a RETN instruction instead, add the 
14973 \emph on
14974 critical
14975 \emph default
14976  keyword:
14977 \end_layout
14978
14979 \begin_layout Verse
14980
14981 \family typewriter
14982 void nmi_isr (void) critical interrupt
14983 \newline
14984
14985 \newline
14986 \InsetSpace ~
14987 \InsetSpace ~
14988 \InsetSpace ~
14989 \InsetSpace ~
14990 ...
14991  
14992 \newline
14993 }
14994 \end_layout
14995
14996 \begin_layout Standard
14997 However if you need to create a non-interruptable interrupt service routine
14998  you would also require the 
14999 \emph on
15000 critical
15001 \emph default
15002  keyword.
15003  To distinguish between this and an nmi_isr you must provide an interrupt
15004  number.
15005 \begin_inset VSpace bigskip
15006 \end_inset
15007
15008
15009 \end_layout
15010
15011 \begin_layout Section
15012 Enabling and Disabling Interrupts
15013 \end_layout
15014
15015 \begin_layout Subsection
15016 Critical Functions and Critical Statements
15017 \end_layout
15018
15019 \begin_layout Standard
15020 A special keyword may be associated with a block or a function declaring
15021  it as 
15022 \emph on
15023 critical
15024 \emph default
15025 .
15026  SDCC will generate code to disable all interrupts
15027 \begin_inset LatexCommand \index{interrupt}
15028
15029 \end_inset
15030
15031  upon entry to a critical function and restore the interrupt enable to the
15032  previous state before returning.
15033  Nesting critical functions will need one additional byte on the stack
15034 \begin_inset LatexCommand \index{stack}
15035
15036 \end_inset
15037
15038  for each call.
15039 \end_layout
15040
15041 \begin_layout Verse
15042
15043 \family typewriter
15044 int foo () __critical
15045 \begin_inset LatexCommand \index{critical}
15046
15047 \end_inset
15048
15049
15050 \begin_inset LatexCommand \index{\_\_critical}
15051
15052 \end_inset
15053
15054  
15055 \newline
15056
15057 \newline
15058 \InsetSpace ~
15059 \InsetSpace ~
15060 \InsetSpace ~
15061 \InsetSpace ~
15062 ...
15063  
15064 \newline
15065 \InsetSpace ~
15066 \InsetSpace ~
15067 \InsetSpace ~
15068 \InsetSpace ~
15069 ...
15070  
15071 \newline
15072 }
15073 \end_layout
15074
15075 \begin_layout Standard
15076 The critical attribute maybe used with other attributes like 
15077 \emph on
15078 reentrant.
15079 \emph default
15080
15081 \newline
15082 The keyword 
15083 \emph on
15084 critical
15085 \emph default
15086  may also be used to disable interrupts more locally:
15087 \end_layout
15088
15089 \begin_layout Verse
15090
15091 \family typewriter
15092 __critical{ i++; }
15093 \end_layout
15094
15095 \begin_layout Standard
15096 More than one statement could have been included in the block.
15097 \end_layout
15098
15099 \begin_layout Subsection
15100 Enabling and Disabling Interrupts directly
15101 \end_layout
15102
15103 \begin_layout Standard
15104 Interrupts
15105 \begin_inset LatexCommand \index{interrupt}
15106
15107 \end_inset
15108
15109  can also be disabled and enabled directly (8051):
15110 \end_layout
15111
15112 \begin_layout Verse
15113
15114 \family typewriter
15115 EA = 0;\InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 \InsetSpace ~
15123 \InsetSpace ~
15124 \InsetSpace ~
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 or:\InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 \InsetSpace ~
15134 \InsetSpace ~
15135 \InsetSpace ~
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 EA_SAVE = EA;
15139 \end_layout
15140
15141 \begin_layout Verse
15142
15143 \family typewriter
15144 ...\InsetSpace ~
15145 \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 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 EA = 0;
15175 \end_layout
15176
15177 \begin_layout Verse
15178
15179 \family typewriter
15180 EA = 1;\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 ...
15207 \end_layout
15208
15209 \begin_layout Verse
15210
15211 \family typewriter
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 \InsetSpace ~
15215 \InsetSpace ~
15216 \InsetSpace ~
15217 \InsetSpace ~
15218 \InsetSpace ~
15219 \InsetSpace ~
15220 \InsetSpace ~
15221 \InsetSpace ~
15222 \InsetSpace ~
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 \InsetSpace ~
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 \InsetSpace ~
15229 \InsetSpace ~
15230 \InsetSpace ~
15231 \InsetSpace ~
15232 \InsetSpace ~
15233 \InsetSpace ~
15234 \InsetSpace ~
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 \InsetSpace ~
15239 \InsetSpace ~
15240 \InsetSpace ~
15241 \InsetSpace ~
15242 \InsetSpace ~
15243 \InsetSpace ~
15244 \InsetSpace ~
15245 EA = EA_SAVE;
15246 \end_layout
15247
15248 \begin_layout Standard
15249 On other architectures which have seperate opcodes for enabling and disabling
15250  interrupts you might want to make use of defines with inline assembly
15251 \begin_inset LatexCommand \index{Assembler routines}
15252
15253 \end_inset
15254
15255  (HC08
15256 \begin_inset LatexCommand \index{HC08!interrupt}
15257
15258 \end_inset
15259
15260 ):
15261 \end_layout
15262
15263 \begin_layout Verse
15264
15265 \family typewriter
15266 #define CLI _asm
15267 \begin_inset LatexCommand \index{\_asm}
15268
15269 \end_inset
15270
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 cli\InsetSpace ~
15274 \InsetSpace ~
15275 _endasm
15276 \begin_inset LatexCommand \index{\_endasm}
15277
15278 \end_inset
15279
15280
15281 \end_layout
15282
15283 \begin_layout Verse
15284
15285 \family typewriter
15286 #define SEI _asm\InsetSpace ~
15287 \InsetSpace ~
15288 sei\InsetSpace ~
15289 \InsetSpace ~
15290 _endasm; 
15291 \end_layout
15292
15293 \begin_layout Verse
15294
15295 \family typewriter
15296 ...
15297 \end_layout
15298
15299 \begin_layout Standard
15300 Note: it is sometimes sufficient to disable only a specific interrupt source
15301  like f.e.
15302  a timer or serial interrupt by manipulating an 
15303 \emph on
15304 interrupt mask
15305 \begin_inset LatexCommand \index{interrupt mask}
15306
15307 \end_inset
15308
15309
15310 \emph default
15311  register.
15312  
15313 \end_layout
15314
15315 \begin_layout Standard
15316 Usually the time during which interrupts are disabled should be kept as
15317  short as possible.
15318  This minimizes both 
15319 \emph on
15320 interrupt latency
15321 \emph default
15322
15323 \begin_inset LatexCommand \index{interrupt latency}
15324
15325 \end_inset
15326
15327  (the time between the occurrence of the interrupt and the execution of
15328  the first code in the interrupt routine) and 
15329 \emph on
15330 interrupt jitter
15331 \emph default
15332
15333 \begin_inset LatexCommand \index{interrupt jitter}
15334
15335 \end_inset
15336
15337  (the difference between the shortest and the longest interrupt latency).
15338  These really are something different, f.e.
15339  a serial interrupt has to be served before its buffer overruns so it cares
15340  for the maximum interrupt latency, whereas it does not care about jitter.
15341  On a loudspeaker driven via a digital to analog converter which is fed
15342  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15343  a much smaller jitter will be very audible.
15344 \end_layout
15345
15346 \begin_layout Standard
15347 You can reenable interrupts within an interrupt routine and on some architecture
15348 s you can make use of two (or more) levels of 
15349 \emph on
15350 interrupt priorities
15351 \emph default
15352
15353 \begin_inset LatexCommand \index{interrupt priority}
15354
15355 \end_inset
15356
15357 .
15358  On some architectures which don't support interrupt priorities these can
15359  be implemented by manipulating the interrupt mask and reenabling interrupts
15360  within the interrupt routine.
15361  Check there is sufficient space on the stack
15362 \begin_inset LatexCommand \index{stack}
15363
15364 \end_inset
15365
15366  and don't add complexity unless you have to.
15367  
15368 \end_layout
15369
15370 \begin_layout Subsection
15371 Semaphore
15372 \begin_inset LatexCommand \index{semaphore}
15373
15374 \end_inset
15375
15376  locking (mcs51/ds390)
15377 \end_layout
15378
15379 \begin_layout Standard
15380 Some architectures (mcs51/ds390) have an atomic
15381 \begin_inset LatexCommand \index{atomic}
15382
15383 \end_inset
15384
15385  bit test and
15386 \emph on
15387  
15388 \emph default
15389 clear
15390 \emph on
15391  
15392 \emph default
15393 instruction.
15394  These type of instructions are typically used in preemptive multitasking
15395  systems, where a routine f.e.
15396  claims the use of a data structure ('acquires a lock
15397 \begin_inset LatexCommand \index{lock}
15398
15399 \end_inset
15400
15401  on it'), makes some modifications and then releases the lock when the data
15402  structure is consistent again.
15403  The instruction may also be used if interrupt and non-interrupt code have
15404  to compete for a resource.
15405  With the atomic bit test and clear instruction interrupts
15406 \begin_inset LatexCommand \index{interrupt}
15407
15408 \end_inset
15409
15410  don't have to be disabled for the locking operation.
15411  
15412 \end_layout
15413
15414 \begin_layout Standard
15415 SDCC generates this instruction if the source follows this pattern:
15416 \end_layout
15417
15418 \begin_layout Verse
15419
15420 \family typewriter
15421 volatile
15422 \begin_inset LatexCommand \index{volatile}
15423
15424 \end_inset
15425
15426  bit resource_is_free; 
15427 \newline
15428
15429 \newline
15430 if (resource_is_free) 
15431 \newline
15432 \InsetSpace ~
15433 \InsetSpace ~
15434
15435 \newline
15436 \InsetSpace ~
15437 \InsetSpace ~
15438 \InsetSpace ~
15439 \InsetSpace ~
15440 resource_is_free=0; 
15441 \newline
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 \InsetSpace ~
15445 \InsetSpace ~
15446 ...
15447  
15448 \newline
15449 \InsetSpace ~
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 resource_is_free=1;
15454 \newline
15455 \InsetSpace ~
15456 \InsetSpace ~
15457
15458 \end_layout
15459
15460 \begin_layout Standard
15461 Note, mcs51 and ds390 support only an atomic
15462 \begin_inset LatexCommand \index{atomic}
15463
15464 \end_inset
15465
15466  bit test and 
15467 \emph on
15468 clear
15469 \emph default
15470  instruction (as opposed to atomic bit test and 
15471 \emph on
15472 set).
15473 \end_layout
15474
15475 \begin_layout Section
15476 Functions using private register banks
15477 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15478
15479 \end_inset
15480
15481  (mcs51/ds390)
15482 \end_layout
15483
15484 \begin_layout Standard
15485 Some architectures have support for quickly changing register sets.
15486  SDCC supports this feature with the 
15487 \emph on
15488 using
15489 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15490
15491 \end_inset
15492
15493
15494 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15495
15496 \end_inset
15497
15498
15499 \emph default
15500  attribute (which tells the compiler to use a register bank
15501 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15502
15503 \end_inset
15504
15505  other than the default bank zero).
15506  It should only be applied to 
15507 \emph on
15508 interrupt
15509 \begin_inset LatexCommand \index{interrupt}
15510
15511 \end_inset
15512
15513
15514 \emph default
15515  functions (see footnote below).
15516  This will in most circumstances make the generated ISR code more efficient
15517  since it will not have to save registers on the stack.
15518 \end_layout
15519
15520 \begin_layout Standard
15521 The 
15522 \emph on
15523 using
15524 \emph default
15525  attribute will have no effect on the generated code for a 
15526 \emph on
15527 non-interrupt
15528 \emph default
15529  function (but may occasionally be useful anyway
15530 \begin_inset Foot
15531 status open
15532
15533 \begin_layout Standard
15534 possible exception: if a function is called ONLY from 'interrupt' functions
15535  using a particular bank, it can be declared with the same 'using' attribute
15536  as the calling 'interrupt' functions.
15537  For instance, if you have several ISRs using bank one, and all of them
15538  call memcpy(), it might make sense to create a specialized version of memcpy()
15539  'using 1', since this would prevent the ISR from having to save bank zero
15540  to the stack on entry and switch to bank zero before calling the function
15541 \end_layout
15542
15543 \end_inset
15544
15545 ).
15546 \newline
15547
15548 \emph on
15549 (pending: Note, nowadays the 
15550 \emph default
15551 using
15552 \emph on
15553  attribute has an effect on
15554 \emph default
15555  
15556 \emph on
15557 the generated code for a 
15558 \emph default
15559 non-interrupt
15560 \emph on
15561  function
15562 \emph default
15563 .
15564 \emph on
15565 )
15566 \end_layout
15567
15568 \begin_layout Standard
15569 An 
15570 \emph on
15571 interrupt
15572 \emph default
15573  function using a non-zero bank will assume that it can trash that register
15574  bank, and will not save it.
15575  Since high-priority interrupts
15576 \begin_inset LatexCommand \index{interrupts}
15577
15578 \end_inset
15579
15580
15581 \begin_inset LatexCommand \index{interrupt priority}
15582
15583 \end_inset
15584
15585  can interrupt low-priority ones on the 8051 and friends, this means that
15586  if a high-priority ISR 
15587 \emph on
15588 using
15589 \emph default
15590  a particular bank occurs while processing a low-priority ISR 
15591 \emph on
15592 using
15593 \emph default
15594  the same bank, terrible and bad things can happen.
15595  To prevent this, no single register bank should be 
15596 \emph on
15597 used
15598 \emph default
15599  by both a high priority and a low priority ISR.
15600  This is probably most easily done by having all high priority ISRs use
15601  one bank and all low priority ISRs use another.
15602  If you have an ISR which can change priority at runtime, you're on your
15603  own: I suggest using the default bank zero and taking the small performance
15604  hit.
15605 \end_layout
15606
15607 \begin_layout Standard
15608 It is most efficient if your ISR calls no other functions.
15609  If your ISR must call other functions, it is most efficient if those functions
15610  use the same bank as the ISR (see note 1 below); the next best is if the
15611  called functions use bank zero.
15612  It is very inefficient to call a function using a different, non-zero bank
15613  from an ISR.
15614  
15615 \begin_inset VSpace bigskip
15616 \end_inset
15617
15618
15619 \end_layout
15620
15621 \begin_layout Section
15622 Startup Code
15623 \begin_inset LatexCommand \label{sub:Startup-Code}
15624
15625 \end_inset
15626
15627
15628 \begin_inset LatexCommand \index{Startup code}
15629
15630 \end_inset
15631
15632
15633 \end_layout
15634
15635 \begin_layout Subsection
15636 MCS51/DS390 Startup Code
15637 \end_layout
15638
15639 \begin_layout Standard
15640 The compiler triggers the linker to link certain initialization modules
15641  from the runtime library
15642 \begin_inset LatexCommand \index{Runtime library}
15643
15644 \end_inset
15645
15646  called crt<something>.
15647  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15648  GSINIT5) is not linked unless the -
15649 \series bold
15650
15651 \begin_inset ERT
15652 status open
15653
15654 \begin_layout Standard
15655
15656
15657 \backslash
15658 /
15659 \end_layout
15660
15661 \end_inset
15662
15663
15664 \series default
15665 -xstack option is used.
15666  These modules are highly entangled by the use of special segments/areas,
15667  but a common layout is shown below:
15668 \end_layout
15669
15670 \begin_layout Verse
15671
15672 \family typewriter
15673 \series bold
15674 \size footnotesize
15675 (main.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 HOME (CODE)
15691 \newline
15692 __interrupt_vect:
15693 \newline
15694 \InsetSpace ~
15695 \InsetSpace ~
15696 \InsetSpace ~
15697 \InsetSpace ~
15698 \InsetSpace ~
15699 \InsetSpace ~
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 ljmp __sdcc_gsinit_startup
15703 \end_layout
15704
15705 \begin_layout Verse
15706
15707 \family typewriter
15708 \series bold
15709 \size footnotesize
15710 (crtstart.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 GSINIT0 (CODE)
15726 \newline
15727 __sdcc_gsinit_startup::
15728 \newline
15729 \InsetSpace ~
15730 \InsetSpace ~
15731 \InsetSpace ~
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 mov sp,#__start__stack - 1
15738 \end_layout
15739
15740 \begin_layout Verse
15741
15742 \family typewriter
15743 \series bold
15744 \size footnotesize
15745 (crtxstack.asm)
15746 \end_layout
15747
15748 \begin_layout Verse
15749
15750 \family typewriter
15751 \size footnotesize
15752 \InsetSpace ~
15753 \InsetSpace ~
15754 \InsetSpace ~
15755 \InsetSpace ~
15756 \InsetSpace ~
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 \InsetSpace ~
15760 .area GSINIT1 (CODE)
15761 \newline
15762 __sdcc_init_xstack::
15763 \newline
15764 ; Need to initialize in GSINIT1 in
15765  case the user's __sdcc_external_startup uses the xstack.
15766 \newline
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 \InsetSpace ~
15773 \InsetSpace ~
15774 \InsetSpace ~
15775 mov __XPAGE,#(__start__x
15776 stack >> 8)
15777 \newline
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 \InsetSpace ~
15783 \InsetSpace ~
15784 \InsetSpace ~
15785 \InsetSpace ~
15786 mov _spx,#__start__xstack
15787 \end_layout
15788
15789 \begin_layout Verse
15790
15791 \family typewriter
15792 \series bold
15793 \size footnotesize
15794 (crtstart.asm)
15795 \end_layout
15796
15797 \begin_layout Verse
15798
15799 \family typewriter
15800 \size footnotesize
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 \InsetSpace ~
15805 \InsetSpace ~
15806 \InsetSpace ~
15807 \InsetSpace ~
15808 \InsetSpace ~
15809 .area GSINIT2 (CODE)
15810 \newline
15811 \InsetSpace ~
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 \InsetSpace ~
15815 \InsetSpace ~
15816 \InsetSpace ~
15817 \InsetSpace ~
15818 \InsetSpace ~
15819 lcall __sdcc_external_startup
15820 \newline
15821 \InsetSpace ~
15822 \InsetSpace ~
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 mov a,dpl
15830 \newline
15831 \InsetSpace ~
15832 \InsetSpace ~
15833 \InsetSpace ~
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 jz __sdcc_init_data
15840 \newline
15841 \InsetSpace ~
15842 \InsetSpace ~
15843 \InsetSpace ~
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 ljmp
15850  __sdcc_program_startup
15851 \newline
15852 __sdcc_init_data:
15853 \end_layout
15854
15855 \begin_layout Verse
15856
15857 \family typewriter
15858 \series bold
15859 \size footnotesize
15860 (crtxinit.asm)
15861 \end_layout
15862
15863 \begin_layout Verse
15864
15865 \family typewriter
15866 \size footnotesize
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 \InsetSpace ~
15873 \InsetSpace ~
15874 \InsetSpace ~
15875 .area GSINIT3 (CODE)
15876 \newline
15877 __mcs51_genXINIT::
15878 \newline
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 mov r1,#l_XINIT
15888 \newline
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 mov a,r1
15898 \newline
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 orl a,#(l_XINIT
15908  >> 8)
15909 \newline
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 jz 00003$
15919 \newline
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 mov r2,#((l_XINIT+255) >> 8)
15929 \newline
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 \InsetSpace ~
15938 mov dptr,#s_XINIT
15939 \newline
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 mov r0,#s_XISEG
15949 \newline
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 \InsetSpace ~
15958 mov
15959  __XPAGE,#(s_XISEG >> 8)
15960 \newline
15961 00001$:\InsetSpace ~
15962 clr a
15963 \newline
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 \InsetSpace ~
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 movc a,@a+dptr
15973 \newline
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 \InsetSpace ~
15979 \InsetSpace ~
15980 \InsetSpace ~
15981 \InsetSpace ~
15982 movx @r0,a
15983 \newline
15984 \InsetSpace ~
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 \InsetSpace ~
15989 \InsetSpace ~
15990 \InsetSpace ~
15991 \InsetSpace ~
15992 inc dptr
15993 \newline
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 inc
16003  r0
16004 \newline
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 cjne r0,#0,00002$
16014 \newline
16015 \InsetSpace ~
16016 \InsetSpace ~
16017 \InsetSpace ~
16018 \InsetSpace ~
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 inc __XPAGE
16024 \newline
16025 00002$:\InsetSpace ~
16026 djnz r1,00001$
16027 \newline
16028 \InsetSpace ~
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 \InsetSpace ~
16036 djnz r2,00001$
16037 \newline
16038 \InsetSpace ~
16039 \InsetSpace ~
16040 \InsetSpace ~
16041 \InsetSpace ~
16042 \InsetSpace ~
16043 \InsetSpace ~
16044 \InsetSpace ~
16045 \InsetSpace ~
16046 mov __XPAGE,#0
16047 xFF
16048 \newline
16049 00003$:
16050 \end_layout
16051
16052 \begin_layout Verse
16053
16054 \family typewriter
16055 \series bold
16056 \size footnotesize
16057 (crtclear.asm)
16058 \end_layout
16059
16060 \begin_layout Verse
16061
16062 \family typewriter
16063 \size footnotesize
16064 \InsetSpace ~
16065 \InsetSpace ~
16066 \InsetSpace ~
16067 \InsetSpace ~
16068 \InsetSpace ~
16069 \InsetSpace ~
16070 \InsetSpace ~
16071 \InsetSpace ~
16072 .area GSINIT4 (CODE)
16073 \newline
16074 __mcs51_genRAMCLEAR::
16075 \newline
16076 \InsetSpace ~
16077 \InsetSpace ~
16078 \InsetSpace ~
16079 \InsetSpace ~
16080 \InsetSpace ~
16081 \InsetSpace ~
16082 \InsetSpace ~
16083 \InsetSpace ~
16084 clr a
16085 \newline
16086 \InsetSpace ~
16087 \InsetSpace ~
16088 \InsetSpace ~
16089 \InsetSpace ~
16090 \InsetSpace ~
16091 \InsetSpace ~
16092 \InsetSpace ~
16093 \InsetSpace ~
16094 mov r0,#(l_IRAM-1)
16095 \newline
16096 00004$:\InsetSpace ~
16097 mov
16098  @r0,a
16099 \newline
16100 \InsetSpace ~
16101 \InsetSpace ~
16102 \InsetSpace ~
16103 \InsetSpace ~
16104 \InsetSpace ~
16105 \InsetSpace ~
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 djnz r0,00004$
16109 \newline
16110 ; _mcs51_genRAMCLEAR() end
16111 \end_layout
16112
16113 \begin_layout Verse
16114
16115 \family typewriter
16116 \series bold
16117 \size footnotesize
16118 (crtxclear.asm)
16119 \end_layout
16120
16121 \begin_layout Verse
16122
16123 \family typewriter
16124 \size footnotesize
16125 \InsetSpace ~
16126 \InsetSpace ~
16127 \InsetSpace ~
16128 \InsetSpace ~
16129 \InsetSpace ~
16130 \InsetSpace ~
16131 \InsetSpace ~
16132 \InsetSpace ~
16133 .area GSINIT4 (CODE)
16134 \newline
16135 __mcs51_genXRAMCLEAR::
16136 \newline
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 \InsetSpace ~
16140 \InsetSpace ~
16141 \InsetSpace ~
16142 \InsetSpace ~
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 mov r0,#l_PSEG
16146 \newline
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 \InsetSpace ~
16152 \InsetSpace ~
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 mov a,r0
16156 \newline
16157 \InsetSpace ~
16158 \InsetSpace ~
16159 \InsetSpace ~
16160 \InsetSpace ~
16161 \InsetSpace ~
16162 \InsetSpace ~
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 orl a,#(l_PSEG
16166  >> 8)
16167 \newline
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 \InsetSpace ~
16172 \InsetSpace ~
16173 \InsetSpace ~
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 jz 00006$
16177 \newline
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 \InsetSpace ~
16185 \InsetSpace ~
16186 mov r1,#s_PSEG
16187 \newline
16188 \InsetSpace ~
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 mov __XPAGE,#(s_PSEG >> 8)
16197 \newline
16198 \InsetSpace ~
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 clr a
16207 \newline
16208 00005$:\InsetSpace ~
16209 movx
16210  @r1,a
16211 \newline
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 \InsetSpace ~
16219 \InsetSpace ~
16220 inc r1
16221 \newline
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 \InsetSpace ~
16228 \InsetSpace ~
16229 \InsetSpace ~
16230 djnz r0,00005$
16231 \newline
16232 00006$:
16233 \newline
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 \InsetSpace ~
16237 \InsetSpace ~
16238 \InsetSpace ~
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 mov r0,#l_XSEG
16243 \newline
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 \InsetSpace ~
16249 \InsetSpace ~
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 mov a,r0
16253 \newline
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 \InsetSpace ~
16259 \InsetSpace ~
16260 \InsetSpace ~
16261 \InsetSpace ~
16262 orl a,#(l_XSEG >>
16263  8)
16264 \newline
16265 \InsetSpace ~
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 \InsetSpace ~
16269 \InsetSpace ~
16270 \InsetSpace ~
16271 \InsetSpace ~
16272 \InsetSpace ~
16273 jz 00008$
16274 \newline
16275 \InsetSpace ~
16276 \InsetSpace ~
16277 \InsetSpace ~
16278 \InsetSpace ~
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 \InsetSpace ~
16283 mov r1,#((l_XSEG + 255) >> 8)
16284 \newline
16285 \InsetSpace ~
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 \InsetSpace ~
16290 \InsetSpace ~
16291 \InsetSpace ~
16292 \InsetSpace ~
16293 mov dptr,#s_XSEG
16294 \newline
16295 \InsetSpace ~
16296 \InsetSpace ~
16297 \InsetSpace ~
16298 \InsetSpace ~
16299 \InsetSpace ~
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 \InsetSpace ~
16303 clr a
16304 \newline
16305 00007$:\InsetSpace ~
16306 movx
16307  @dptr,a
16308 \newline
16309 \InsetSpace ~
16310 \InsetSpace ~
16311 \InsetSpace ~
16312 \InsetSpace ~
16313 \InsetSpace ~
16314 \InsetSpace ~
16315 \InsetSpace ~
16316 \InsetSpace ~
16317 inc dptr
16318 \newline
16319 \InsetSpace ~
16320 \InsetSpace ~
16321 \InsetSpace ~
16322 \InsetSpace ~
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 djnz r0,00007$
16328 \newline
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 \InsetSpace ~
16333 \InsetSpace ~
16334 \InsetSpace ~
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 djnz r1,00007$
16338 \newline
16339 00008$:
16340 \end_layout
16341
16342 \begin_layout Verse
16343
16344 \family typewriter
16345 \series bold
16346 \size footnotesize
16347 (crtxstack.asm)
16348 \end_layout
16349
16350 \begin_layout Verse
16351
16352 \family typewriter
16353 \size footnotesize
16354 \InsetSpace ~
16355 \InsetSpace ~
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 \InsetSpace ~
16362 .area GSINIT5 (CODE)
16363 \newline
16364 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16365  modifies __XPAGE
16366 \newline
16367 ; and __mcs51_genRAMCLEAR modifies _spx.
16368 \newline
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 \InsetSpace ~
16372 \InsetSpace ~
16373 \InsetSpace ~
16374 \InsetSpace ~
16375 \InsetSpace ~
16376 \InsetSpace ~
16377 mov __XPAGE,#(__start__x
16378 stack >> 8)
16379 \newline
16380 \InsetSpace ~
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 \InsetSpace ~
16386 \InsetSpace ~
16387 \InsetSpace ~
16388 mov _spx,#__start__xstack
16389 \end_layout
16390
16391 \begin_layout Verse
16392
16393 \family typewriter
16394 \series bold
16395 \size footnotesize
16396 (application modules)
16397 \end_layout
16398
16399 \begin_layout Verse
16400
16401 \family typewriter
16402 \size footnotesize
16403 \InsetSpace ~
16404 \InsetSpace ~
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 \InsetSpace ~
16408 \InsetSpace ~
16409 \InsetSpace ~
16410 \InsetSpace ~
16411 .area GSINIT (CODE)
16412 \end_layout
16413
16414 \begin_layout Verse
16415
16416 \family typewriter
16417 \series bold
16418 \size footnotesize
16419 (main.asm)
16420 \end_layout
16421
16422 \begin_layout Verse
16423
16424 \family typewriter
16425 \size footnotesize
16426 \InsetSpace ~
16427 \InsetSpace ~
16428 \InsetSpace ~
16429 \InsetSpace ~
16430 \InsetSpace ~
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 .area GSFINAL (CODE)
16435 \newline
16436 \InsetSpace ~
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 \InsetSpace ~
16440 \InsetSpace ~
16441 \InsetSpace ~
16442 \InsetSpace ~
16443 \InsetSpace ~
16444 ljmp __sdcc_program_startup
16445 \newline
16446 ;---------------------------------
16447 -----------------------
16448 \newline
16449 ; Home
16450 \newline
16451 ;--------------------------------------------------
16452 ------
16453 \newline
16454 \InsetSpace ~
16455 \InsetSpace ~
16456 \InsetSpace ~
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 .area HOME (CODE)
16463 \newline
16464 \InsetSpace ~
16465 \InsetSpace ~
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 \InsetSpace ~
16470 \InsetSpace ~
16471 \InsetSpace ~
16472 .area CSEG (CODE)
16473 \newline
16474 __sdcc_program_startup:
16475 \newline
16476 \InsetSpace ~
16477 \InsetSpace ~
16478 \InsetSpace ~
16479 \InsetSpace ~
16480 \InsetSpace ~
16481 \InsetSpace ~
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 lcall _main
16485 \newline
16486 ;
16487  return from main will lock up
16488 \newline
16489 \InsetSpace ~
16490 \InsetSpace ~
16491 \InsetSpace ~
16492 \InsetSpace ~
16493 \InsetSpace ~
16494 \InsetSpace ~
16495 \InsetSpace ~
16496 \InsetSpace ~
16497 sjmp .
16498 \end_layout
16499
16500 \begin_layout Standard
16501 One of these modules (crtstart.asm) contains a call to the C routine 
16502 \emph on
16503 _sdcc_external_startup()
16504 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16505
16506 \end_inset
16507
16508
16509 \series bold
16510 \emph default
16511  
16512 \series default
16513 at the start of the CODE area.
16514  This routine is also in the runtime library
16515 \begin_inset LatexCommand \index{Runtime library}
16516
16517 \end_inset
16518
16519  and returns 0 by default.
16520  If this routine returns a non-zero value, the static & global variable
16521  initialization will be skipped and the function main will be invoked.
16522  Otherwise static & global variables will be initialized before the function
16523  main is invoked.
16524  You could add an 
16525 \emph on
16526 _sdcc_external_startup()
16527 \emph default
16528  routine to your program to override the default if you need to setup hardware
16529  or perform some other critical operation prior to static & global variable
16530  initialization
16531 \begin_inset LatexCommand \index{Variable initialization}
16532
16533 \end_inset
16534
16535 .
16536  On some mcs51 variants xdata
16537 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16538
16539 \end_inset
16540
16541  memory has to be explicitly enabled before it can be accessed or if the
16542  watchdog
16543 \begin_inset LatexCommand \index{watchdog}
16544
16545 \end_inset
16546
16547  needs to be disabled, this is the place to do it.
16548  The startup code clears all internal data memory, 256 bytes by default,
16549  but from 0 to n-1 if 
16550 \emph on
16551 -
16552 \begin_inset ERT
16553 status collapsed
16554
16555 \begin_layout Standard
16556
16557
16558 \backslash
16559 /
16560 \end_layout
16561
16562 \end_inset
16563
16564 -iram-size
16565 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16566
16567 \end_inset
16568
16569 n
16570 \emph default
16571  is used.
16572  (recommended for Chipcon CC1010).
16573 \end_layout
16574
16575 \begin_layout Standard
16576 See also the compiler options 
16577 \emph on
16578 -
16579 \begin_inset ERT
16580 status collapsed
16581
16582 \begin_layout Standard
16583
16584
16585 \backslash
16586 /
16587 \end_layout
16588
16589 \end_inset
16590
16591 -no-xinit
16592 \emph default
16593 -
16594 \emph on
16595 opt
16596 \emph default
16597
16598 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16599
16600 \end_inset
16601
16602
16603 \emph on
16604 -
16605 \begin_inset ERT
16606 status collapsed
16607
16608 \begin_layout Standard
16609
16610
16611 \backslash
16612 /
16613 \end_layout
16614
16615 \end_inset
16616
16617 -main-return
16618 \emph default
16619
16620 \begin_inset LatexCommand \index{-\/-main-return}
16621
16622 \end_inset
16623
16624  and section 
16625 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16626
16627 \end_inset
16628
16629  about MCS51-variants.
16630 \newline
16631
16632 \end_layout
16633
16634 \begin_layout Standard
16635 While these initialization modules are meant as generic startup code there
16636  might be the need for customization.
16637  Let's assume the return value of 
16638 \emph on
16639 _sdcc_external_startup()
16640 \emph default
16641  in 
16642 \emph on
16643 crtstart.asm
16644 \emph default
16645  should not be checked (or 
16646 \emph on
16647 _sdcc_external_startup()
16648 \emph default
16649  should not be called at all).
16650  The recommended way would be to copy 
16651 \emph on
16652 crtstart.asm
16653 \emph default
16654  (f.e.
16655  from 
16656 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16657
16658 \end_inset
16659
16660 ) into the source directory, adapt it there, then assemble it with 
16661 \emph on
16662 asx8051 -plosgff
16663 \begin_inset Foot
16664 status open
16665
16666 \begin_layout Standard
16667 \begin_inset Quotes sld
16668 \end_inset
16669
16670 -plosgff
16671 \begin_inset Quotes srd
16672 \end_inset
16673
16674  are the assembler options used in 
16675 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16676
16677 \end_inset
16678
16679
16680 \end_layout
16681
16682 \end_inset
16683
16684  crtstart.asm
16685 \emph default
16686  and when linking your project explicitely specify 
16687 \emph on
16688 crtstart.rel
16689 \emph default
16690 .
16691  As a bonus a listing of the relocated object file 
16692 \emph on
16693 crtstart.rst
16694 \emph default
16695  is generated.
16696 \end_layout
16697
16698 \begin_layout Standard
16699 \begin_inset VSpace bigskip
16700 \end_inset
16701
16702
16703 \end_layout
16704
16705 \begin_layout Subsection
16706 HC08 Startup Code
16707 \end_layout
16708
16709 \begin_layout Standard
16710 The HC08
16711 \begin_inset LatexCommand \index{HC08}
16712
16713 \end_inset
16714
16715  startup code follows the same scheme as the MCS51 startup code.
16716 \begin_inset VSpace bigskip
16717 \end_inset
16718
16719
16720 \end_layout
16721
16722 \begin_layout Subsection
16723 Z80 Startup Code
16724 \end_layout
16725
16726 \begin_layout Standard
16727 On the Z80
16728 \begin_inset LatexCommand \index{Z80}
16729
16730 \end_inset
16731
16732  the startup code is inserted by linking with crt0.o which is generated from
16733  sdcc/device/lib/z80/crt0.s.
16734  If you need a different startup code you can use the compiler option 
16735 \emph on
16736 -
16737 \series bold
16738 \emph default
16739
16740 \begin_inset ERT
16741 status collapsed
16742
16743 \begin_layout Standard
16744
16745
16746 \backslash
16747 /
16748 \end_layout
16749
16750 \end_inset
16751
16752
16753 \series default
16754 \emph on
16755 -no-std-crt0
16756 \emph default
16757
16758 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16759
16760 \end_inset
16761
16762  and provide your own crt0.o.
16763  
16764 \begin_inset VSpace bigskip
16765 \end_inset
16766
16767
16768 \end_layout
16769
16770 \begin_layout Section
16771 Inline Assembler Code
16772 \begin_inset LatexCommand \index{Assembler routines}
16773
16774 \end_inset
16775
16776
16777 \end_layout
16778
16779 \begin_layout Subsection
16780 A Step by Step Introduction
16781 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16782
16783 \end_inset
16784
16785
16786 \end_layout
16787
16788 \begin_layout Standard
16789 Starting from a small snippet of c-code this example shows for the MCS51
16790  how to use inline assembly, access variables, a function parameter and
16791  an array in xdata memory.
16792  The example uses an MCS51 here but is easily adapted for other architectures.
16793  This is a buffer routine which should be optimized:
16794 \end_layout
16795
16796 \begin_layout Verse
16797
16798 \family typewriter
16799 \size footnotesize
16800 unsigned char __far
16801 \begin_inset LatexCommand \index{far (storage class)}
16802
16803 \end_inset
16804
16805
16806 \begin_inset LatexCommand \index{\_\_far (storage class)}
16807
16808 \end_inset
16809
16810  __at
16811 \begin_inset LatexCommand \index{at}
16812
16813 \end_inset
16814
16815
16816 \begin_inset LatexCommand \index{\_\_at}
16817
16818 \end_inset
16819
16820 (0x7f00) buf[0x100];
16821 \begin_inset LatexCommand \index{Aligned array}
16822
16823 \end_inset
16824
16825
16826 \newline
16827 unsigned char head, tail;\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 /* if interrupts
16845 \begin_inset LatexCommand \index{interrupt}
16846
16847 \end_inset
16848
16849  are involved see
16850 \newline
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 \InsetSpace ~
16859 \InsetSpace ~
16860 \InsetSpace ~
16861 \InsetSpace ~
16862 \InsetSpace ~
16863 \InsetSpace ~
16864 \InsetSpace ~
16865 \InsetSpace ~
16866 \InsetSpace ~
16867 \InsetSpace ~
16868 \InsetSpace ~
16869 \InsetSpace ~
16870 \InsetSpace ~
16871 \InsetSpace ~
16872 \InsetSpace ~
16873 \InsetSpace ~
16874 \InsetSpace ~
16875 \InsetSpace ~
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 \InsetSpace ~
16881 \InsetSpace ~
16882 \InsetSpace ~
16883 \InsetSpace ~
16884 \InsetSpace ~
16885 \InsetSpace ~
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 \InsetSpace ~
16890 \InsetSpace ~
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 \InsetSpace ~
16894 \InsetSpace ~
16895 \InsetSpace ~
16896 section 
16897 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16898
16899 \end_inset
16900
16901  about
16902 \series bold
16903  volatile
16904 \series default
16905  */
16906 \newline
16907
16908 \newline
16909 void to_buffer( unsigned char c ) 
16910 \newline
16911 {
16912 \newline
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 if( head != (unsigned char)(tail-1)
16918  )\InsetSpace ~
16919 /* cast 
16920 \series bold
16921 needed
16922 \series default
16923  to avoid promotion
16924 \begin_inset LatexCommand \index{promotion to signed int}
16925
16926 \end_inset
16927
16928
16929 \begin_inset LatexCommand \index{type promotion}
16930
16931 \end_inset
16932
16933  to integer */
16934 \begin_inset Marginal
16935 status collapsed
16936
16937 \begin_layout Standard
16938
16939 \series bold
16940 \InsetSpace ~
16941 !
16942 \end_layout
16943
16944 \end_inset
16945
16946
16947 \newline
16948 \InsetSpace ~
16949 \InsetSpace ~
16950 \InsetSpace ~
16951 \InsetSpace ~
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 \InsetSpace ~
16956 buf[ head++ ] = c;\InsetSpace ~
16957 \InsetSpace ~
16958 \InsetSpace ~
16959 \InsetSpace ~
16960 \InsetSpace ~
16961 \InsetSpace ~
16962 \InsetSpace ~
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 \InsetSpace ~
16968 \InsetSpace ~
16969 \InsetSpace ~
16970 \InsetSpace ~
16971 \InsetSpace ~
16972 /* access to a 256 byte aligned array */
16973 \newline
16974
16975 \end_layout
16976
16977 \begin_layout Standard
16978 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16979  then a corresponding buffer.asm file is generated.
16980  We define a new function 
16981 \family typewriter
16982 to_buffer_asm()
16983 \family default
16984  in file buffer.c in which we cut and paste the generated code, removing
16985  unwanted comments and some ':'.
16986  Then add 
16987 \begin_inset Quotes sld
16988 \end_inset
16989
16990
16991 \series bold
16992 _asm
16993 \series default
16994
16995 \begin_inset Quotes srd
16996 \end_inset
16997
16998  and 
16999 \begin_inset Quotes sld
17000 \end_inset
17001
17002
17003 \series bold
17004 _endasm;
17005 \series default
17006
17007 \begin_inset Quotes srd
17008 \end_inset
17009
17010
17011 \begin_inset Foot
17012 status open
17013
17014 \begin_layout Standard
17015 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17016  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17017  has to be used.
17018  The latter is also used in the library functions.
17019 \end_layout
17020
17021 \end_inset
17022
17023  to the beginning and the end of the function body:
17024 \end_layout
17025
17026 \begin_layout Verse
17027
17028 \family typewriter
17029 \size footnotesize
17030 /* With a cut and paste from the .asm file, we have something to start with.
17031 \newline
17032 \InsetSpace ~
17033 \InsetSpace ~
17034 \InsetSpace ~
17035 The
17036  function is not yet OK! (registers aren't saved) */ 
17037 \newline
17038 void to_buffer_asm(
17039  unsigned char c ) 
17040 \newline
17041
17042 \newline
17043 \InsetSpace ~
17044 \InsetSpace ~
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 _asm
17048 \begin_inset LatexCommand \index{\_asm}
17049
17050 \end_inset
17051
17052
17053 \begin_inset LatexCommand \index{\_\_asm}
17054
17055 \end_inset
17056
17057
17058 \newline
17059 \InsetSpace ~
17060 \InsetSpace ~
17061 \InsetSpace ~
17062 \InsetSpace ~
17063 mov\InsetSpace ~
17064 \InsetSpace ~
17065 r2,dpl 
17066 \newline
17067 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17068 /* cast 
17069 \series bold
17070 needed
17071 \series default
17072  to avoid promotion
17073 \begin_inset LatexCommand \index{promotion to signed int}
17074
17075 \end_inset
17076
17077
17078 \begin_inset LatexCommand \index{type promotion}
17079
17080 \end_inset
17081
17082  to integer */
17083 \newline
17084 \InsetSpace ~
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 \InsetSpace ~
17088 mov\InsetSpace ~
17089 \InsetSpace ~
17090 a,_tail 
17091 \newline
17092 \InsetSpace ~
17093 \InsetSpace ~
17094 \InsetSpace ~
17095 \InsetSpace ~
17096 dec\InsetSpace ~
17097 \InsetSpace ~
17098
17099 \newline
17100 \InsetSpace ~
17101 \InsetSpace ~
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 mov\InsetSpace ~
17105 \InsetSpace ~
17106 r3,a 
17107 \newline
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 \InsetSpace ~
17112 mov\InsetSpace ~
17113 \InsetSpace ~
17114 a,_head 
17115 \newline
17116 \InsetSpace ~
17117 \InsetSpace ~
17118 \InsetSpace ~
17119 \InsetSpace ~
17120 cjne a,ar3,00106$ 
17121 \newline
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 ret
17127 \newline
17128 00106$:
17129  
17130 \newline
17131 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17132 \begin_inset LatexCommand \index{Aligned array}
17133
17134 \end_inset
17135
17136
17137 \newline
17138 \InsetSpace ~
17139 \InsetSpace ~
17140 \InsetSpace ~
17141 \InsetSpace ~
17142 mov\InsetSpace ~
17143 \InsetSpace ~
17144 r3,_head 
17145 \newline
17146 \InsetSpace ~
17147 \InsetSpace ~
17148 \InsetSpace ~
17149 \InsetSpace ~
17150 inc\InsetSpace ~
17151 \InsetSpace ~
17152 _head 
17153 \newline
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 \InsetSpace ~
17157 \InsetSpace ~
17158 mov\InsetSpace ~
17159 \InsetSpace ~
17160 dpl,r3 
17161 \newline
17162 \InsetSpace ~
17163 \InsetSpace ~
17164 \InsetSpace ~
17165 \InsetSpace ~
17166 mov\InsetSpace ~
17167 \InsetSpace ~
17168 dph,#(_buf >> 8) 
17169 \newline
17170 \InsetSpace ~
17171 \InsetSpace ~
17172 \InsetSpace ~
17173 \InsetSpace ~
17174 mov\InsetSpace ~
17175 \InsetSpace ~
17176 a,r2 
17177 \newline
17178 \InsetSpace ~
17179 \InsetSpace ~
17180 \InsetSpace ~
17181 \InsetSpace ~
17182 movx @dptr,a
17183  
17184 \newline
17185 00103$: 
17186 \newline
17187 \InsetSpace ~
17188 \InsetSpace ~
17189 \InsetSpace ~
17190 \InsetSpace ~
17191 ret
17192 \newline
17193 \InsetSpace ~
17194 \InsetSpace ~
17195 \InsetSpace ~
17196 \InsetSpace ~
17197 _endasm
17198 \begin_inset LatexCommand \index{\_endasm}
17199
17200 \end_inset
17201
17202
17203 \begin_inset LatexCommand \index{\_\_endasm}
17204
17205 \end_inset
17206
17207 ;
17208 \newline
17209
17210 \end_layout
17211
17212 \begin_layout Standard
17213 The new file buffer.c should compile with only one warning about the unreferenced
17214  function argument 'c'.
17215  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17216  (1) and finally have:
17217 \end_layout
17218
17219 \begin_layout Verse
17220
17221 \family typewriter
17222 \size footnotesize
17223 unsigned char __far __at(0x7f00) buf[0x100];
17224 \newline
17225 unsigned char head, tail;
17226 \newline
17227 #define
17228  USE_ASSEMBLY (1)
17229 \newline
17230
17231 \newline
17232 #if !USE_ASSEMBLY
17233 \newline
17234
17235 \newline
17236 void to_buffer( unsigned char c )
17237 \newline
17238 {
17239 \newline
17240 \InsetSpace ~
17241 \InsetSpace ~
17242 \InsetSpace ~
17243 \InsetSpace ~
17244 if(
17245  head != (unsigned char)(tail-1) )
17246 \newline
17247 \InsetSpace ~
17248 \InsetSpace ~
17249 \InsetSpace ~
17250 \InsetSpace ~
17251 \InsetSpace ~
17252 \InsetSpace ~
17253 \InsetSpace ~
17254 \InsetSpace ~
17255 buf[ head++ ] = c;
17256 \newline
17257 }
17258 \newline
17259
17260 \newline
17261 #else
17262 \newline
17263
17264 \newline
17265 void to_buffer(
17266  unsigned char c )
17267 \newline
17268 {
17269 \newline
17270 \InsetSpace ~
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 \InsetSpace ~
17274 c; // to avoid warning: unreferenced function argument
17275 \newline
17276 \InsetSpace ~
17277 \InsetSpace ~
17278 \InsetSpace ~
17279 \InsetSpace ~
17280 _asm
17281 \begin_inset LatexCommand \index{\_asm}
17282
17283 \end_inset
17284
17285
17286 \begin_inset LatexCommand \index{\_\_asm}
17287
17288 \end_inset
17289
17290
17291 \newline
17292 \InsetSpace ~
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 \InsetSpace ~
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 ; save used registers here.
17301  
17302 \newline
17303 \InsetSpace ~
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 \InsetSpace ~
17308 \InsetSpace ~
17309 \InsetSpace ~
17310 \InsetSpace ~
17311 ; If we were still using r2,r3 we would have to push them here.
17312  
17313 \newline
17314 ; if( head != (unsigned char)(tail-1) )
17315 \newline
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 \InsetSpace ~
17323 \InsetSpace ~
17324 mov\InsetSpace ~
17325  a,_tail
17326 \newline
17327 \InsetSpace ~
17328 \InsetSpace ~
17329 \InsetSpace ~
17330 \InsetSpace ~
17331 \InsetSpace ~
17332 \InsetSpace ~
17333 \InsetSpace ~
17334 \InsetSpace ~
17335 dec\InsetSpace ~
17336  a
17337 \newline
17338 \InsetSpace ~
17339 \InsetSpace ~
17340 \InsetSpace ~
17341 \InsetSpace ~
17342 \InsetSpace ~
17343 \InsetSpace ~
17344 \InsetSpace ~
17345 \InsetSpace ~
17346 xrl\InsetSpace ~
17347  a,_head
17348 \newline
17349 \InsetSpace ~
17350 \InsetSpace ~
17351 \InsetSpace ~
17352 \InsetSpace ~
17353 \InsetSpace ~
17354 \InsetSpace ~
17355 \InsetSpace ~
17356 \InsetSpace ~
17357 ; we
17358  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17359 \newline
17360 \InsetSpace ~
17361 \InsetSpace ~
17362 \InsetSpace ~
17363 \InsetSpace ~
17364 \InsetSpace ~
17365 \InsetSpace ~
17366 \InsetSpace ~
17367 \InsetSpace ~
17368 jz\InsetSpace ~
17369 \InsetSpace ~
17370  t_b_end$
17371 \newline
17372 \InsetSpace ~
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 \InsetSpace ~
17377 \InsetSpace ~
17378 \InsetSpace ~
17379 \InsetSpace ~
17380 ;
17381 \newline
17382 ;
17383  buf[ head++ ] = c;
17384 \newline
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 \InsetSpace ~
17388 \InsetSpace ~
17389 \InsetSpace ~
17390 \InsetSpace ~
17391 \InsetSpace ~
17392 \InsetSpace ~
17393 mov\InsetSpace ~
17394  a,dpl \InsetSpace ~
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 \InsetSpace ~
17398 \InsetSpace ~
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 ; dpl holds lower byte of function argument
17402 \newline
17403 \InsetSpace ~
17404 \InsetSpace ~
17405 \InsetSpace ~
17406 \InsetSpace ~
17407 \InsetSpace ~
17408 \InsetSpace ~
17409 \InsetSpace ~
17410 \InsetSpace ~
17411 mov\InsetSpace ~
17412
17413  dpl,_head \InsetSpace ~
17414 \InsetSpace ~
17415 \InsetSpace ~
17416 ; buf is 0x100 byte aligned so head can be used directly
17417 \newline
17418 \InsetSpace ~
17419 \InsetSpace ~
17420 \InsetSpace ~
17421 \InsetSpace ~
17422 \InsetSpace ~
17423 \InsetSpace ~
17424 \InsetSpace ~
17425 \InsetSpace ~
17426 mov\InsetSpace ~
17427  dph,#(_bu
17428 f>>8)
17429 \newline
17430 \InsetSpace ~
17431 \InsetSpace ~
17432 \InsetSpace ~
17433 \InsetSpace ~
17434 \InsetSpace ~
17435 \InsetSpace ~
17436 \InsetSpace ~
17437 \InsetSpace ~
17438 movx @dptr,a
17439 \newline
17440 \InsetSpace ~
17441 \InsetSpace ~
17442 \InsetSpace ~
17443 \InsetSpace ~
17444 \InsetSpace ~
17445 \InsetSpace ~
17446 \InsetSpace ~
17447 \InsetSpace ~
17448 inc \InsetSpace ~
17449 _head
17450 \newline
17451 \InsetSpace ~
17452 \InsetSpace ~
17453 \InsetSpace ~
17454 \InsetSpace ~
17455 \InsetSpace ~
17456 \InsetSpace ~
17457 \InsetSpace ~
17458 \InsetSpace ~
17459 ; we could do an ANL _head,#0x0f here to use a
17460  smaller buffer (see above)
17461 \newline
17462 t_b_end$:
17463 \newline
17464 \InsetSpace ~
17465 \InsetSpace ~
17466 \InsetSpace ~
17467 \InsetSpace ~
17468 \InsetSpace ~
17469 \InsetSpace ~
17470 \InsetSpace ~
17471 \InsetSpace ~
17472 ; restore used registers here 
17473 \newline
17474 \InsetSpace ~
17475 \InsetSpace ~
17476 \InsetSpace ~
17477 \InsetSpace ~
17478 _endasm
17479 \begin_inset LatexCommand \index{\_endasm}
17480
17481 \end_inset
17482
17483
17484 \begin_inset LatexCommand \index{\_\_endasm}
17485
17486 \end_inset
17487
17488 ;
17489 \newline
17490 }
17491 \newline
17492 #endif
17493 \end_layout
17494
17495 \begin_layout Standard
17496 The inline assembler code can contain any valid code understood by the assembler
17497 , this includes any assembler directives and comment lines.
17498  The assembler does not like some characters like ':' or ''' in comments.
17499  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17500 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17501
17502 \end_inset
17503
17504
17505 \begin_inset LatexCommand \index{Assembler documentation}
17506
17507 \end_inset
17508
17509  or online at 
17510 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17511
17512 \end_inset
17513
17514 \InsetSpace ~
17515 .
17516 \end_layout
17517
17518 \begin_layout Standard
17519 The compiler does not do any validation of the code within the 
17520 \family typewriter
17521 _asm
17522 \begin_inset LatexCommand \index{\_asm}
17523
17524 \end_inset
17525
17526
17527 \begin_inset LatexCommand \index{\_\_asm}
17528
17529 \end_inset
17530
17531  ...
17532  _endasm
17533 \size footnotesize
17534
17535 \begin_inset LatexCommand \index{\_endasm}
17536
17537 \end_inset
17538
17539
17540 \begin_inset LatexCommand \index{\_\_endasm}
17541
17542 \end_inset
17543
17544
17545 \size default
17546 ;
17547 \family default
17548  keyword pair.
17549  Specifically it will not know which registers are used and thus register
17550  pushing/popping
17551 \begin_inset LatexCommand \index{push/pop}
17552
17553 \end_inset
17554
17555  has to be done manually.
17556  
17557 \end_layout
17558
17559 \begin_layout Standard
17560 It is recommended that each assembly instruction (including labels) be placed
17561  in a separate line (as the example shows).
17562  When the -
17563 \begin_inset ERT
17564 status collapsed
17565
17566 \begin_layout Standard
17567
17568
17569 \backslash
17570 /
17571 \end_layout
17572
17573 \end_inset
17574
17575 -
17576 \emph on
17577 peep-asm
17578 \begin_inset LatexCommand \index{-\/-peep-asm}
17579
17580 \end_inset
17581
17582
17583 \emph default
17584  command line option is used, the inline assembler code will be passed through
17585  the peephole optimizer
17586 \begin_inset LatexCommand \index{Peephole optimizer}
17587
17588 \end_inset
17589
17590 .
17591  There are only a few (if any) cases where this option makes sense, it might
17592  cause some unexpected changes in the inline assembler code.
17593  Please go through the peephole optimizer rules defined in file 
17594 \emph on
17595 SDCCpeeph.def
17596 \emph default
17597  before using this option.
17598 \end_layout
17599
17600 \begin_layout Subsection
17601 Naked Functions
17602 \begin_inset LatexCommand \label{sub:Naked-Functions}
17603
17604 \end_inset
17605
17606
17607 \begin_inset LatexCommand \index{Naked functions}
17608
17609 \end_inset
17610
17611
17612 \end_layout
17613
17614 \begin_layout Standard
17615 A special keyword may be associated with a function declaring it as 
17616 \emph on
17617 _naked
17618 \begin_inset LatexCommand \index{\_naked}
17619
17620 \end_inset
17621
17622
17623 \begin_inset LatexCommand \index{\_\_naked}
17624
17625 \end_inset
17626
17627 .
17628  
17629 \emph default
17630 The 
17631 \emph on
17632 _naked
17633 \emph default
17634  function modifier attribute prevents the compiler from generating prologue
17635 \begin_inset LatexCommand \index{function prologue}
17636
17637 \end_inset
17638
17639  and epilogue
17640 \begin_inset LatexCommand \index{function epilogue}
17641
17642 \end_inset
17643
17644  code for that function.
17645  This means that the user is entirely responsible for such things as saving
17646  any registers that may need to be preserved, selecting the proper register
17647  bank, generating the 
17648 \emph on
17649 return
17650 \emph default
17651  instruction at the end, etc.
17652  Practically, this means that the contents of the function must be written
17653  in inline assembler.
17654  This is particularly useful for interrupt functions, which can have a large
17655  (and often unnecessary) prologue/epilogue.
17656  For example, compare the code generated by these two functions:
17657 \end_layout
17658
17659 \begin_layout Verse
17660
17661 \family typewriter
17662 volatile
17663 \begin_inset LatexCommand \index{volatile}
17664
17665 \end_inset
17666
17667  data unsigned char counter;
17668 \newline
17669
17670 \newline
17671 void simpleInterrupt(void) __interrupt
17672 \begin_inset LatexCommand \index{interrupt}
17673
17674 \end_inset
17675
17676
17677 \begin_inset LatexCommand \index{\_\_interrupt}
17678
17679 \end_inset
17680
17681  (1)
17682 \newline
17683 {
17684 \newline
17685 \InsetSpace ~
17686 \InsetSpace ~
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 counter++;
17690 \newline
17691 }
17692 \newline
17693
17694 \newline
17695 void nakedInterrupt(void) __interrupt (2) __naked
17696 \newline
17697 {
17698 \newline
17699 \InsetSpace ~
17700 \InsetSpace ~
17701 \InsetSpace ~
17702 \InsetSpace ~
17703 _asm
17704 \begin_inset LatexCommand \index{\_asm}
17705
17706 \end_inset
17707
17708
17709 \begin_inset LatexCommand \index{\_\_asm}
17710
17711 \end_inset
17712
17713
17714 \newline
17715 \InsetSpace ~
17716 \InsetSpace ~
17717 \InsetSpace ~
17718 \InsetSpace ~
17719 \InsetSpace ~
17720 \InsetSpace ~
17721 inc\InsetSpace ~
17722 \InsetSpace ~
17723 \InsetSpace ~
17724 \InsetSpace ~
17725 \InsetSpace ~
17726 _counter ; does not change flags, no need to save psw
17727 \newline
17728 \InsetSpace ~
17729 \InsetSpace ~
17730 \InsetSpace ~
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 \InsetSpace ~
17734 reti\InsetSpace ~
17735 \InsetSpace ~
17736 \InsetSpace ~
17737 \InsetSpace ~
17738 ; MUST explicitly
17739  include ret or reti in _naked function.
17740 \newline
17741 \InsetSpace ~
17742 \InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 _endasm
17746 \begin_inset LatexCommand \index{\_endasm}
17747
17748 \end_inset
17749
17750
17751 \begin_inset LatexCommand \index{\_\_endasm}
17752
17753 \end_inset
17754
17755 ;
17756 \newline
17757 }
17758 \end_layout
17759
17760 \begin_layout Standard
17761 For an 8051 target, the generated simpleInterrupt looks like:
17762 \end_layout
17763
17764 \begin_layout Verse
17765
17766 \family typewriter
17767 Note, this is an 
17768 \emph on
17769 outdated
17770 \emph default
17771  example, recent versions of SDCC generate
17772 \newline
17773 the 
17774 \emph on
17775 same
17776 \emph default
17777  code for simpleInterrupt() and nakedInterrupt()!
17778 \newline
17779
17780 \newline
17781 _simpleInterrupt:
17782 \newline
17783 \InsetSpace ~
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 push\InsetSpace ~
17788 \InsetSpace ~
17789 \InsetSpace ~
17790 \InsetSpace ~
17791 acc
17792 \newline
17793 \InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 \InsetSpace ~
17797 push\InsetSpace ~
17798 \InsetSpace ~
17799 \InsetSpace ~
17800 \InsetSpace ~
17801 b
17802 \newline
17803 \InsetSpace ~
17804 \InsetSpace ~
17805 \InsetSpace ~
17806 \InsetSpace ~
17807 pu
17808 sh\InsetSpace ~
17809 \InsetSpace ~
17810 \InsetSpace ~
17811 \InsetSpace ~
17812 dpl
17813 \newline
17814 \InsetSpace ~
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 push\InsetSpace ~
17819 \InsetSpace ~
17820 \InsetSpace ~
17821 \InsetSpace ~
17822 dph
17823 \newline
17824 \InsetSpace ~
17825 \InsetSpace ~
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 push\InsetSpace ~
17829 \InsetSpace ~
17830 \InsetSpace ~
17831 \InsetSpace ~
17832 psw
17833 \newline
17834 \InsetSpace ~
17835 \InsetSpace ~
17836 \InsetSpace ~
17837 \InsetSpace ~
17838 mov\InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 \InsetSpace ~
17842 \InsetSpace ~
17843 psw,#0x00
17844 \newline
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 \InsetSpace ~
17849 inc\InsetSpace ~
17850 \InsetSpace ~
17851 \InsetSpace ~
17852 \InsetSpace ~
17853 \InsetSpace ~
17854 _counter
17855 \newline
17856 \InsetSpace ~
17857 \InsetSpace ~
17858 \InsetSpace ~
17859 \InsetSpace ~
17860 pop\InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 \InsetSpace ~
17864 \InsetSpace ~
17865 psw
17866 \newline
17867 \InsetSpace ~
17868 \InsetSpace ~
17869 \InsetSpace ~
17870 \InsetSpace ~
17871 pop\InsetSpace ~
17872 \InsetSpace ~
17873 \InsetSpace ~
17874 \InsetSpace ~
17875 \InsetSpace ~
17876 dph
17877 \newline
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 \InsetSpace ~
17882 pop\InsetSpace ~
17883 \InsetSpace ~
17884 \InsetSpace ~
17885 \InsetSpace ~
17886 \InsetSpace ~
17887 dpl
17888 \newline
17889 \InsetSpace ~
17890 \InsetSpace ~
17891 \InsetSpace ~
17892 \InsetSpace ~
17893 pop\InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 \InsetSpace ~
17898 b
17899 \newline
17900 \InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 pop\InsetSpace ~
17905 \InsetSpace ~
17906 \InsetSpace ~
17907 \InsetSpace ~
17908 \InsetSpace ~
17909 acc
17910 \newline
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 \InsetSpace ~
17914 \InsetSpace ~
17915 reti
17916 \end_layout
17917
17918 \begin_layout Standard
17919 whereas nakedInterrupt looks like:
17920 \end_layout
17921
17922 \begin_layout Verse
17923
17924 \family typewriter
17925 _nakedInterrupt:
17926 \newline
17927 \InsetSpace ~
17928 \InsetSpace ~
17929 \InsetSpace ~
17930 \InsetSpace ~
17931 inc\InsetSpace ~
17932 \InsetSpace ~
17933 \InsetSpace ~
17934 \InsetSpace ~
17935 _counter ; does not change flags, no need to save psw
17936 \newline
17937 \InsetSpace ~
17938 \InsetSpace ~
17939 \InsetSpace ~
17940 \InsetSpace ~
17941 reti\InsetSpace ~
17942 \InsetSpace ~
17943 \InsetSpace ~
17944 \InsetSpace ~
17945 \InsetSpace ~
17946 \InsetSpace ~
17947 \InsetSpace ~
17948 \InsetSpace ~
17949 \InsetSpace ~
17950 \InsetSpace ~
17951 \InsetSpace ~
17952 \InsetSpace ~
17953 ;
17954  MUST explicitly include ret or reti in _naked function
17955 \end_layout
17956
17957 \begin_layout Standard
17958 The related directive #pragma exclude
17959 \begin_inset LatexCommand \index{\#pragma exclude}
17960
17961 \end_inset
17962
17963  allows a more fine grained control over pushing & popping
17964 \begin_inset LatexCommand \index{push/pop}
17965
17966 \end_inset
17967
17968  the registers.
17969 \end_layout
17970
17971 \begin_layout Standard
17972 While there is nothing preventing you from writing C code inside a 
17973 \family typewriter
17974 _naked
17975 \family default
17976  function, there are many ways to shoot yourself in the foot doing this,
17977  and it is recommended that you stick to inline assembler.
17978 \end_layout
17979
17980 \begin_layout Subsection
17981 Use of Labels within Inline Assembler
17982 \end_layout
17983
17984 \begin_layout Standard
17985 SDCC allows the use of in-line assembler with a few restrictions regarding
17986  labels.
17987  All labels defined within inline assembler code have to be of the form
17988  
17989 \emph on
17990 nnnnn$
17991 \emph default
17992  where nnnnn is a number less than 100 (which implies a limit of utmost
17993  100 inline assembler labels 
17994 \emph on
17995 per function
17996 \emph default
17997 \noun on
17998 )
17999 \noun default
18000 .
18001 \begin_inset Foot
18002 status open
18003
18004 \begin_layout Standard
18005 This is a slightly more stringent rule than absolutely necessary, but stays
18006  always on the safe side.
18007  Labels in the form of nnnnn$ are local labels in the assembler, locality
18008  of which is confined within two labels of the standard form.
18009  The compiler uses the same form for labels within a function (but starting
18010  from nnnnn=00100); and places always a standard label at the beginning
18011  of a function, thus limiting the locality of labels within the scope of
18012  the function.
18013  So, if the inline assembler part would be embedded into C-code, an improperly
18014  placed non-local label in the assembler would break up the reference space
18015  for labels created by the compiler for the C-code, leading to an assembling
18016  error.
18017 \end_layout
18018
18019 \begin_layout Standard
18020 The numeric part of local labels does not need to have 5 digits (although
18021  this is the form of labels output by the compiler), any valid integer will
18022  do.
18023  Please refer to the assemblers documentation for further details.
18024 \end_layout
18025
18026 \end_inset
18027
18028  
18029 \end_layout
18030
18031 \begin_layout Verse
18032
18033 \family typewriter
18034 _asm
18035 \begin_inset LatexCommand \index{\_asm}
18036
18037 \end_inset
18038
18039
18040 \begin_inset LatexCommand \index{\_\_asm}
18041
18042 \end_inset
18043
18044  
18045 \newline
18046 \InsetSpace ~
18047 \InsetSpace ~
18048 \InsetSpace ~
18049 \InsetSpace ~
18050 mov\InsetSpace ~
18051 \InsetSpace ~
18052 \InsetSpace ~
18053 \InsetSpace ~
18054 \InsetSpace ~
18055 b,#10 
18056 \newline
18057 00001$: 
18058 \newline
18059 \InsetSpace ~
18060 \InsetSpace ~
18061 \InsetSpace ~
18062 \InsetSpace ~
18063 djnz\InsetSpace ~
18064 \InsetSpace ~
18065 \InsetSpace ~
18066 \InsetSpace ~
18067 b,00001$ 
18068 \newline
18069 _endasm
18070 \begin_inset LatexCommand \index{\_endasm}
18071
18072 \end_inset
18073
18074
18075 \begin_inset LatexCommand \index{\_\_endasm}
18076
18077 \end_inset
18078
18079  ;
18080 \end_layout
18081
18082 \begin_layout Standard
18083 Inline assembler code cannot reference any C-labels, however it can reference
18084  labels
18085 \begin_inset LatexCommand \index{Labels}
18086
18087 \end_inset
18088
18089  defined by the inline assembler, e.g.:
18090 \end_layout
18091
18092 \begin_layout Verse
18093
18094 \family typewriter
18095 foo() { 
18096 \newline
18097 \InsetSpace ~
18098 \InsetSpace ~
18099 \InsetSpace ~
18100 \InsetSpace ~
18101 /* some c code */ 
18102 \newline
18103 \InsetSpace ~
18104 \InsetSpace ~
18105 \InsetSpace ~
18106 \InsetSpace ~
18107 _asm 
18108 \newline
18109 \InsetSpace ~
18110 \InsetSpace ~
18111 \InsetSpace ~
18112 \InsetSpace ~
18113 \InsetSpace ~
18114 \InsetSpace ~
18115 ; some assembler code 
18116 \newline
18117 \InsetSpace ~
18118 \InsetSpace ~
18119 \InsetSpace ~
18120 \InsetSpace ~
18121 \InsetSpace ~
18122 \InsetSpace ~
18123 ljmp 0003$ 
18124 \newline
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 \InsetSpace ~
18128 \InsetSpace ~
18129 _endasm;
18130  
18131 \newline
18132 \InsetSpace ~
18133 \InsetSpace ~
18134 \InsetSpace ~
18135 \InsetSpace ~
18136 /* some more c code */ 
18137 \newline
18138 clabel:\InsetSpace ~
18139 \InsetSpace ~
18140 /* inline assembler cannot reference this
18141  label */ 
18142 \begin_inset Foot
18143 status open
18144
18145 \begin_layout Standard
18146 Here, the C-label 
18147 \family typewriter
18148 clabel
18149 \family default
18150  is translated by the compiler into a local label, so the locality of labels
18151  within the function is not broken.
18152 \end_layout
18153
18154 \end_inset
18155
18156
18157 \newline
18158 \InsetSpace ~
18159 \InsetSpace ~
18160 \InsetSpace ~
18161 \InsetSpace ~
18162 _asm
18163 \newline
18164 \InsetSpace ~
18165 \InsetSpace ~
18166 \InsetSpace ~
18167 \InsetSpace ~
18168 0003$: ;label (can be referenced by inline assembler only) 
18169 \newline
18170 \InsetSpace ~
18171 \InsetSpace ~
18172 \InsetSpace ~
18173 \InsetSpace ~
18174 _endasm
18175 \begin_inset LatexCommand \index{\_endasm}
18176
18177 \end_inset
18178
18179
18180 \begin_inset LatexCommand \index{\_\_endasm}
18181
18182 \end_inset
18183
18184  ; 
18185 \newline
18186 \InsetSpace ~
18187 \InsetSpace ~
18188 \InsetSpace ~
18189 \InsetSpace ~
18190 /* some more c code */
18191 \newline
18192 }
18193 \end_layout
18194
18195 \begin_layout Standard
18196 In other words inline assembly code can access labels defined in inline
18197  assembly within the scope of the function.
18198  The same goes the other way, i.e.
18199  labels defines in inline assembly can not be accessed by C statements.
18200 \end_layout
18201
18202 \begin_layout Section
18203 Interfacing with Assembler Code
18204 \begin_inset LatexCommand \index{Assembler routines}
18205
18206 \end_inset
18207
18208
18209 \end_layout
18210
18211 \begin_layout Subsection
18212 Global Registers used for Parameter Passing
18213 \begin_inset LatexCommand \index{Parameter passing}
18214
18215 \end_inset
18216
18217
18218 \end_layout
18219
18220 \begin_layout Standard
18221 The compiler always uses the global registers 
18222 \emph on
18223 DPL, DPH
18224 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18225
18226 \end_inset
18227
18228
18229 \begin_inset LatexCommand \index{DPTR}
18230
18231 \end_inset
18232
18233 , B
18234 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18235
18236 \end_inset
18237
18238  
18239 \emph default
18240 and
18241 \emph on
18242  ACC
18243 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18244
18245 \end_inset
18246
18247
18248 \emph default
18249  to pass the first (non-bit) parameter to a function, and also to pass the
18250  return value 
18251 \begin_inset LatexCommand \index{return value}
18252
18253 \end_inset
18254
18255 of function; according to the following scheme: one byte return value in
18256  
18257 \emph on
18258 DPL
18259 \emph default
18260 , two byte value in 
18261 \emph on
18262 DPL
18263 \emph default
18264  (LSB) and 
18265 \emph on
18266 DPH
18267 \emph default
18268  (MSB).
18269  three byte values (generic pointers) in 
18270 \emph on
18271 DPH
18272 \emph default
18273
18274 \emph on
18275 DPL
18276 \emph default
18277  and 
18278 \emph on
18279 B
18280 \emph default
18281 , and four byte values in 
18282 \emph on
18283 DPH
18284 \emph default
18285
18286 \emph on
18287 DPL
18288 \emph default
18289 ,
18290 \emph on
18291  B
18292 \emph default
18293  and 
18294 \emph on
18295 ACC
18296 \emph default
18297 .
18298  Generic pointers
18299 \begin_inset LatexCommand \index{generic pointer}
18300
18301 \end_inset
18302
18303  contain type of accessed memory in 
18304 \emph on
18305 B
18306 \emph default
18307
18308 \series bold
18309 0x00
18310 \series default
18311  -- xdata/far, 
18312 \series bold
18313 0x40
18314 \series default
18315  -- idata/near -- , 
18316 \series bold
18317 0x60
18318 \series default
18319  -- pdata, 
18320 \series bold
18321 0x80
18322 \series default
18323  -- code
18324 \begin_inset Note Note
18325 status collapsed
18326
18327 \begin_layout Standard
18328 This might not be the case of certain memory models (medium???)
18329 \end_layout
18330
18331 \end_inset
18332
18333 .
18334 \end_layout
18335
18336 \begin_layout Standard
18337 The second parameter onwards is either allocated on the stack (for reentrant
18338  routines or if -
18339 \begin_inset ERT
18340 status collapsed
18341
18342 \begin_layout Standard
18343
18344
18345 \backslash
18346 /
18347 \end_layout
18348
18349 \end_inset
18350
18351 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18352 \end_layout
18353
18354 \begin_layout Standard
18355 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18356  space for reentrant functions or allocated directly in bit memory otherwise.
18357 \end_layout
18358
18359 \begin_layout Standard
18360 Functions (with two or more parameters or bit parameters) that are called
18361  through function pointers
18362 \begin_inset LatexCommand \index{function pointers}
18363
18364 \end_inset
18365
18366  must therefor be reentrant so the compiler knows how to pass the parameters.
18367 \end_layout
18368
18369 \begin_layout Subsection
18370 Registers usage
18371 \end_layout
18372
18373 \begin_layout Standard
18374 Unless the called function is declared as 
18375 \family typewriter
18376 _naked
18377 \family default
18378
18379 \begin_inset LatexCommand \index{naked}
18380
18381 \end_inset
18382
18383 , or the -
18384 \begin_inset ERT
18385 status collapsed
18386
18387 \begin_layout Standard
18388
18389
18390 \backslash
18391 /
18392 \end_layout
18393
18394 \end_inset
18395
18396 -callee-saves
18397 \begin_inset LatexCommand \index{-\/-callee-saves}
18398
18399 \end_inset
18400
18401 /-
18402 \begin_inset ERT
18403 status collapsed
18404
18405 \begin_layout Standard
18406
18407
18408 \backslash
18409 /
18410 \end_layout
18411
18412 \end_inset
18413
18414 -all-callee-saves command line option or the corresponding callee_saves
18415  pragma are used, the caller will save the registers (
18416 \emph on
18417 R0-R7
18418 \emph default
18419 ) around the call, so the called function can destroy they content freely.
18420 \end_layout
18421
18422 \begin_layout Standard
18423 If the called function is not declared as 
18424 \family typewriter
18425 _naked
18426 \family default
18427 , the caller will swap register banks around the call, if caller and callee
18428  use different register banks (having them defined by the 
18429 \family typewriter
18430 _using
18431 \family default
18432  modifier).
18433  
18434 \end_layout
18435
18436 \begin_layout Standard
18437 The called function can also use 
18438 \emph on
18439 DPL
18440 \emph default
18441
18442 \emph on
18443 DPH
18444 \emph default
18445
18446 \emph on
18447 B
18448 \emph default
18449  and 
18450 \emph on
18451 ACC
18452 \emph default
18453  observing that they are used for parameter/return value passing.
18454 \end_layout
18455
18456 \begin_layout Subsection
18457 Assembler Routine (non-reentrant)
18458 \end_layout
18459
18460 \begin_layout Standard
18461 In the following example
18462 \begin_inset LatexCommand \index{reentrant}
18463
18464 \end_inset
18465
18466
18467 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18468
18469 \end_inset
18470
18471  the function c_func calls an assembler routine asm_func, which takes two
18472  parameters
18473 \begin_inset LatexCommand \index{function parameter}
18474
18475 \end_inset
18476
18477 .
18478 \end_layout
18479
18480 \begin_layout Verse
18481
18482 \family typewriter
18483 extern int asm_func(unsigned char, unsigned char);
18484 \newline
18485
18486 \newline
18487 int c_func (unsigned char
18488  i, unsigned char j)
18489 \newline
18490 {
18491 \newline
18492 \InsetSpace ~
18493 \InsetSpace ~
18494 \InsetSpace ~
18495 \InsetSpace ~
18496 return asm_func(i,j);
18497 \newline
18498 }
18499 \newline
18500
18501 \newline
18502 int main()
18503 \newline
18504 {
18505 \newline
18506 \InsetSpace ~
18507 \InsetSpace ~
18508 \InsetSpace ~
18509 \InsetSpace ~
18510 return c_func(10,9);
18511 \newline
18512 }
18513 \end_layout
18514
18515 \begin_layout Standard
18516 The corresponding assembler function is:
18517 \end_layout
18518
18519 \begin_layout Verse
18520
18521 \family typewriter
18522 .globl _asm_func_PARM_2 
18523 \newline
18524 \InsetSpace ~
18525 \InsetSpace ~
18526 \InsetSpace ~
18527 \InsetSpace ~
18528 \InsetSpace ~
18529 \InsetSpace ~
18530 \InsetSpace ~
18531 \InsetSpace ~
18532 .globl _asm_func 
18533 \newline
18534 \InsetSpace ~
18535 \InsetSpace ~
18536 \InsetSpace ~
18537 \InsetSpace ~
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 .area OSEG 
18543 \newline
18544 _asm_func_PARM_2:
18545 \newline
18546 \InsetSpace ~
18547 \InsetSpace ~
18548 \InsetSpace ~
18549 \InsetSpace ~
18550 \InsetSpace ~
18551 \InsetSpace ~
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 .ds   
18555  1 
18556 \newline
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 \InsetSpace ~
18560 \InsetSpace ~
18561 \InsetSpace ~
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 \InsetSpace ~
18565 .area CSEG 
18566 \newline
18567 _asm_func: 
18568 \newline
18569 \InsetSpace ~
18570 \InsetSpace ~
18571 \InsetSpace ~
18572 \InsetSpace ~
18573 \InsetSpace ~
18574 \InsetSpace ~
18575 \InsetSpace ~
18576 \InsetSpace ~
18577 mov\InsetSpace ~
18578 \InsetSpace ~
18579 \InsetSpace ~
18580 \InsetSpace ~
18581 a,dpl 
18582 \newline
18583 \InsetSpace ~
18584 \InsetSpace ~
18585 \InsetSpace ~
18586 \InsetSpace ~
18587 \InsetSpace ~
18588 \InsetSpace ~
18589 \InsetSpace ~
18590 \InsetSpace ~
18591 add\InsetSpace ~
18592 \InsetSpace ~
18593 \InsetSpace ~
18594 \InsetSpace ~
18595 a,_asm_func_PARM_2 
18596 \newline
18597 \InsetSpace ~
18598 \InsetSpace ~
18599 \InsetSpace ~
18600 \InsetSpace ~
18601 \InsetSpace ~
18602 \InsetSpace ~
18603 \InsetSpace ~
18604 \InsetSpace ~
18605 mov\InsetSpace ~
18606 \InsetSpace ~
18607 \InsetSpace ~
18608 \InsetSpace ~
18609 dpl,a 
18610 \newline
18611 \InsetSpace ~
18612 \InsetSpace ~
18613 \InsetSpace ~
18614 \InsetSpace ~
18615 \InsetSpace ~
18616 \InsetSpace ~
18617 \InsetSpace ~
18618 \InsetSpace ~
18619 mov\InsetSpace ~
18620 \InsetSpace ~
18621 \InsetSpace ~
18622 \InsetSpace ~
18623 dph
18624 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18625
18626 \end_inset
18627
18628 ,#0x00 
18629 \newline
18630 \InsetSpace ~
18631 \InsetSpace ~
18632 \InsetSpace ~
18633 \InsetSpace ~
18634 \InsetSpace ~
18635 \InsetSpace ~
18636 \InsetSpace ~
18637 \InsetSpace ~
18638 ret
18639 \end_layout
18640
18641 \begin_layout Standard
18642 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18643  the parameter number starting from 1, and counting from the left.
18644  The first parameter is passed in 
18645 \emph on
18646 DPH
18647 \emph default
18648
18649 \emph on
18650 DPL
18651 \emph default
18652
18653 \emph on
18654 B
18655 \emph default
18656  and 
18657 \emph on
18658 ACC
18659 \emph default
18660  according to the description above.
18661  The variable name for the second parameter will be _<function_name>_PARM_2.
18662 \newline
18663
18664 \newline
18665 Assem
18666 ble the assembler routine with the following command:
18667 \newline
18668
18669 \newline
18670
18671 \family sans
18672 \series bold
18673 asx8051 -losg asmfunc.asm
18674 \newline
18675
18676 \newline
18677
18678 \family default
18679 \series default
18680 Then compile and link the assembler routine to the C source file with the
18681  following command:
18682 \newline
18683
18684 \newline
18685
18686 \family sans
18687 \series bold
18688 sdcc cfunc.c asmfunc.rel
18689 \end_layout
18690
18691 \begin_layout Subsection
18692 Assembler Routine (reentrant)
18693 \end_layout
18694
18695 \begin_layout Standard
18696 In this case
18697 \begin_inset LatexCommand \index{reentrant}
18698
18699 \end_inset
18700
18701
18702 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18703
18704 \end_inset
18705
18706  the second parameter
18707 \begin_inset LatexCommand \index{function parameter}
18708
18709 \end_inset
18710
18711  onwards will be passed on the stack, the parameters are pushed from right
18712  to left i.e.
18713  before the call the second leftmost parameter will be on the top of the
18714  stack (the leftmost parameter is passed in registers).
18715  Here is an example:
18716 \end_layout
18717
18718 \begin_layout Verse
18719
18720 \family typewriter
18721 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18722 \newline
18723
18724 \newline
18725 int
18726  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18727 \newline
18728 {
18729  
18730 \newline
18731 \InsetSpace ~
18732 \InsetSpace ~
18733 \InsetSpace ~
18734 \InsetSpace ~
18735 return asm_func(i,j,k); 
18736 \newline
18737
18738 \newline
18739
18740 \newline
18741 int main() 
18742 \newline
18743
18744 \newline
18745 \InsetSpace ~
18746 \InsetSpace ~
18747 \InsetSpace ~
18748 \InsetSpace ~
18749 return c_func(10,9,8); 
18750 \newline
18751 }
18752 \end_layout
18753
18754 \begin_layout Standard
18755 The corresponding (unoptimized) assembler routine is:
18756 \end_layout
18757
18758 \begin_layout Verse
18759
18760 \family typewriter
18761 .globl _asm_func 
18762 \newline
18763 _asm_func: 
18764 \newline
18765 \InsetSpace ~
18766 \InsetSpace ~
18767 \InsetSpace ~
18768 \InsetSpace ~
18769 push\InsetSpace ~
18770 _bp 
18771 \newline
18772 \InsetSpace ~
18773 \InsetSpace ~
18774 \InsetSpace ~
18775 \InsetSpace ~
18776 mov\InsetSpace ~
18777 \InsetSpace ~
18778 _bp,sp\InsetSpace ~
18779 \InsetSpace ~
18780 \InsetSpace ~
18781 \InsetSpace ~
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 ;stack contains: _bp, return
18785  address, second parameter, third parameter
18786 \newline
18787 \InsetSpace ~
18788 \InsetSpace ~
18789 \InsetSpace ~
18790 \InsetSpace ~
18791 mov\InsetSpace ~
18792 \InsetSpace ~
18793 r2,dpl
18794 \newline
18795 \InsetSpace ~
18796 \InsetSpace ~
18797 \InsetSpace ~
18798 \InsetSpace ~
18799 mov\InsetSpace ~
18800 \InsetSpace ~
18801 a,_bp
18802 \newline
18803 \InsetSpace ~
18804 \InsetSpace ~
18805 \InsetSpace ~
18806 \InsetSpace ~
18807 add\InsetSpace ~
18808 \InsetSpace ~
18809 a,#0xfd\InsetSpace ~
18810 \InsetSpace ~
18811 \InsetSpace ~
18812 \InsetSpace ~
18813 \InsetSpace ~
18814 ;calculate
18815  pointer to the second parameter
18816 \newline
18817 \InsetSpace ~
18818 \InsetSpace ~
18819 \InsetSpace ~
18820 \InsetSpace ~
18821 mov\InsetSpace ~
18822 \InsetSpace ~
18823 r0,a 
18824 \newline
18825 \InsetSpace ~
18826 \InsetSpace ~
18827 \InsetSpace ~
18828 \InsetSpace ~
18829 mov\InsetSpace ~
18830 \InsetSpace ~
18831 a,_bp 
18832 \newline
18833 \InsetSpace ~
18834 \InsetSpace ~
18835 \InsetSpace ~
18836 \InsetSpace ~
18837 add\InsetSpace ~
18838 \InsetSpace ~
18839 a,#0xfc\InsetSpace ~
18840 \InsetSpace ~
18841 \InsetSpace ~
18842 \InsetSpace ~
18843 \InsetSpace ~
18844 ;calculate pointer
18845  to the rightmost parameter
18846 \newline
18847 \InsetSpace ~
18848 \InsetSpace ~
18849 \InsetSpace ~
18850 \InsetSpace ~
18851 mov\InsetSpace ~
18852 \InsetSpace ~
18853 r1,a 
18854 \newline
18855 \InsetSpace ~
18856 \InsetSpace ~
18857 \InsetSpace ~
18858 \InsetSpace ~
18859 mov\InsetSpace ~
18860 \InsetSpace ~
18861 a,@r0
18862 \newline
18863 \InsetSpace ~
18864 \InsetSpace ~
18865 \InsetSpace ~
18866 \InsetSpace ~
18867 add\InsetSpace ~
18868 \InsetSpace ~
18869 a,@r1
18870 \newline
18871 \InsetSpace ~
18872 \InsetSpace ~
18873 \InsetSpace ~
18874 \InsetSpace ~
18875 add\InsetSpace ~
18876 \InsetSpace ~
18877 a,r2\InsetSpace ~
18878 \InsetSpace ~
18879 \InsetSpace ~
18880 \InsetSpace ~
18881 \InsetSpace ~
18882 \InsetSpace ~
18883 \InsetSpace ~
18884 \InsetSpace ~
18885 ;calculate the
18886  result (= sum of all three parameters)
18887 \newline
18888 \InsetSpace ~
18889 \InsetSpace ~
18890 \InsetSpace ~
18891 \InsetSpace ~
18892 mov\InsetSpace ~
18893 \InsetSpace ~
18894 dpl,a\InsetSpace ~
18895 \InsetSpace ~
18896 \InsetSpace ~
18897 \InsetSpace ~
18898 \InsetSpace ~
18899 \InsetSpace ~
18900 \InsetSpace ~
18901 ;return value goes into dptr
18902  (cast into int)
18903 \newline
18904 \InsetSpace ~
18905 \InsetSpace ~
18906 \InsetSpace ~
18907 \InsetSpace ~
18908 mov\InsetSpace ~
18909 \InsetSpace ~
18910 dph,#0x00 
18911 \newline
18912 \InsetSpace ~
18913 \InsetSpace ~
18914 \InsetSpace ~
18915 \InsetSpace ~
18916 mov\InsetSpace ~
18917 \InsetSpace ~
18918 sp,_bp 
18919 \newline
18920 \InsetSpace ~
18921 \InsetSpace ~
18922 \InsetSpace ~
18923 \InsetSpace ~
18924 pop\InsetSpace ~
18925 \InsetSpace ~
18926 _bp 
18927 \newline
18928 \InsetSpace ~
18929 \InsetSpace ~
18930 \InsetSpace ~
18931 \InsetSpace ~
18932 ret
18933 \end_layout
18934
18935 \begin_layout Standard
18936 The compiling and linking procedure remains the same, however note the extra
18937  entry & exit linkage required for the assembler code, _bp is the stack
18938  frame pointer and is used to compute the offset into the stack for parameters
18939  and local variables.
18940 \begin_inset VSpace bigskip
18941 \end_inset
18942
18943
18944 \end_layout
18945
18946 \begin_layout Section
18947 int (16 bit)
18948 \begin_inset LatexCommand \index{int (16 bit)}
18949
18950 \end_inset
18951
18952  and long (32 bit)
18953 \begin_inset LatexCommand \index{long (32 bit)}
18954
18955 \end_inset
18956
18957  Support
18958 \end_layout
18959
18960 \begin_layout Standard
18961 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18962  multiplication and modulus operations are implemented by support routines.
18963  These support routines are all developed in ANSI-C to facilitate porting
18964  to other MCUs, although some model specific assembler optimizations are
18965  used.
18966  The following files contain the described routines, all of them can be
18967  found in <installdir>/share/sdcc/lib.
18968 \newline
18969
18970 \end_layout
18971
18972 \begin_layout Standard
18973 \align center
18974 \begin_inset Tabular
18975 <lyxtabular version="3" rows="11" columns="2">
18976 <features>
18977 <column alignment="left" valignment="top" leftline="true" width="0">
18978 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18979 <row topline="true" bottomline="true">
18980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18981 \begin_inset Text
18982
18983 \begin_layout Standard
18984
18985 \series bold
18986 Function
18987 \end_layout
18988
18989 \end_inset
18990 </cell>
18991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18992 \begin_inset Text
18993
18994 \begin_layout Standard
18995
18996 \series bold
18997 Description
18998 \end_layout
18999
19000 \end_inset
19001 </cell>
19002 </row>
19003 <row topline="true">
19004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19005 \begin_inset Text
19006
19007 \begin_layout Standard
19008 _mulint.c 
19009 \end_layout
19010
19011 \end_inset
19012 </cell>
19013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19014 \begin_inset Text
19015
19016 \begin_layout Standard
19017 16 bit multiplication
19018 \end_layout
19019
19020 \end_inset
19021 </cell>
19022 </row>
19023 <row topline="true">
19024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19025 \begin_inset Text
19026
19027 \begin_layout Standard
19028 _divsint.c 
19029 \end_layout
19030
19031 \end_inset
19032 </cell>
19033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19034 \begin_inset Text
19035
19036 \begin_layout Standard
19037  signed 16 bit division (calls _divuint)
19038 \end_layout
19039
19040 \end_inset
19041 </cell>
19042 </row>
19043 <row topline="true">
19044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19045 \begin_inset Text
19046
19047 \begin_layout Standard
19048 _divuint.c 
19049 \end_layout
19050
19051 \end_inset
19052 </cell>
19053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19054 \begin_inset Text
19055
19056 \begin_layout Standard
19057  unsigned 16 bit division
19058 \end_layout
19059
19060 \end_inset
19061 </cell>
19062 </row>
19063 <row topline="true">
19064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19065 \begin_inset Text
19066
19067 \begin_layout Standard
19068 _modsint.c
19069 \end_layout
19070
19071 \end_inset
19072 </cell>
19073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19074 \begin_inset Text
19075
19076 \begin_layout Standard
19077 signed 16 bit modulus (calls _moduint)
19078 \end_layout
19079
19080 \end_inset
19081 </cell>
19082 </row>
19083 <row topline="true">
19084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19085 \begin_inset Text
19086
19087 \begin_layout Standard
19088 _moduint.c
19089 \end_layout
19090
19091 \end_inset
19092 </cell>
19093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19094 \begin_inset Text
19095
19096 \begin_layout Standard
19097 unsigned 16 bit modulus
19098 \end_layout
19099
19100 \end_inset
19101 </cell>
19102 </row>
19103 <row topline="true">
19104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19105 \begin_inset Text
19106
19107 \begin_layout Standard
19108 _mullong.c
19109 \end_layout
19110
19111 \end_inset
19112 </cell>
19113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19114 \begin_inset Text
19115
19116 \begin_layout Standard
19117 32 bit multiplication
19118 \end_layout
19119
19120 \end_inset
19121 </cell>
19122 </row>
19123 <row topline="true">
19124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19125 \begin_inset Text
19126
19127 \begin_layout Standard
19128 _divslong.c 
19129 \end_layout
19130
19131 \end_inset
19132 </cell>
19133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19134 \begin_inset Text
19135
19136 \begin_layout Standard
19137  signed 32 division (calls _divulong)
19138 \end_layout
19139
19140 \end_inset
19141 </cell>
19142 </row>
19143 <row topline="true">
19144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19145 \begin_inset Text
19146
19147 \begin_layout Standard
19148 _divulong.c 
19149 \end_layout
19150
19151 \end_inset
19152 </cell>
19153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19154 \begin_inset Text
19155
19156 \begin_layout Standard
19157 unsigned 32 division
19158 \end_layout
19159
19160 \end_inset
19161 </cell>
19162 </row>
19163 <row topline="true">
19164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19165 \begin_inset Text
19166
19167 \begin_layout Standard
19168 _modslong.c
19169 \end_layout
19170
19171 \end_inset
19172 </cell>
19173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19174 \begin_inset Text
19175
19176 \begin_layout Standard
19177  signed 32 bit modulus (calls _modulong)
19178 \end_layout
19179
19180 \end_inset
19181 </cell>
19182 </row>
19183 <row topline="true" bottomline="true">
19184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19185 \begin_inset Text
19186
19187 \begin_layout Standard
19188 _modulong.c
19189 \end_layout
19190
19191 \end_inset
19192 </cell>
19193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19194 \begin_inset Text
19195
19196 \begin_layout Standard
19197 unsigned 32 bit modulus
19198 \end_layout
19199
19200 \end_inset
19201 </cell>
19202 </row>
19203 </lyxtabular>
19204
19205 \end_inset
19206
19207
19208 \newline
19209
19210 \end_layout
19211
19212 \begin_layout Standard
19213 Since they are compiled as 
19214 \emph on
19215 non-reentrant
19216 \emph default
19217
19218 \begin_inset LatexCommand \index{reentrant}
19219
19220 \end_inset
19221
19222 , interrupt
19223 \begin_inset LatexCommand \index{interrupt}
19224
19225 \end_inset
19226
19227  service routines should not do any of the above operations.
19228  If this is unavoidable then the above routines will need to be compiled
19229  with the 
19230 \emph on
19231 -
19232 \begin_inset ERT
19233 status collapsed
19234
19235 \begin_layout Standard
19236
19237
19238 \backslash
19239 /
19240 \end_layout
19241
19242 \end_inset
19243
19244 -stack-auto
19245 \begin_inset LatexCommand \index{-\/-stack-auto}
19246
19247 \end_inset
19248
19249
19250 \emph default
19251  option, after which the source program will have to be compiled with 
19252 \emph on
19253 -
19254 \begin_inset ERT
19255 status collapsed
19256
19257 \begin_layout Standard
19258
19259
19260 \backslash
19261 /
19262 \end_layout
19263
19264 \end_inset
19265
19266 -int-long-reent
19267 \begin_inset LatexCommand \index{-\/-int-long-reent}
19268
19269 \end_inset
19270
19271
19272 \emph default
19273  option.
19274  Notice that you don't have to call these routines directly.
19275  The compiler will use them automatically every time an integer operation
19276  is required.
19277 \end_layout
19278
19279 \begin_layout Section
19280 Floating Point Support
19281 \begin_inset LatexCommand \index{Floating point support}
19282
19283 \end_inset
19284
19285
19286 \end_layout
19287
19288 \begin_layout Standard
19289 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19290  The floating point support routines are derived from gcc's floatlib.c and
19291  consist of the following routines:
19292 \newline
19293
19294 \end_layout
19295
19296 \begin_layout Standard
19297 \align center
19298
19299 \size footnotesize
19300 \begin_inset Tabular
19301 <lyxtabular version="3" rows="17" columns="2">
19302 <features>
19303 <column alignment="left" valignment="top" leftline="true" width="0">
19304 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19305 <row topline="true" bottomline="true">
19306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19307 \begin_inset Text
19308
19309 \begin_layout Standard
19310
19311 \family roman
19312 \series medium
19313 \shape up
19314 \size normal
19315 \emph off
19316 \bar no
19317 \noun off
19318 \color none
19319 Function 
19320 \end_layout
19321
19322 \end_inset
19323 </cell>
19324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19325 \begin_inset Text
19326
19327 \begin_layout Standard
19328 Description
19329 \end_layout
19330
19331 \end_inset
19332 </cell>
19333 </row>
19334 <row topline="true">
19335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19336 \begin_inset Text
19337
19338 \begin_layout Standard
19339
19340 \family roman
19341 \series medium
19342 \shape up
19343 \size normal
19344 \emph off
19345 \bar no
19346 \noun off
19347 \color none
19348 _fsadd.c
19349 \end_layout
19350
19351 \end_inset
19352 </cell>
19353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19354 \begin_inset Text
19355
19356 \begin_layout Standard
19357
19358 \family roman
19359 \series medium
19360 \shape up
19361 \size normal
19362 \emph off
19363 \bar no
19364 \noun off
19365 \color none
19366 add floating point numbers
19367 \end_layout
19368
19369 \end_inset
19370 </cell>
19371 </row>
19372 <row topline="true">
19373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19374 \begin_inset Text
19375
19376 \begin_layout Standard
19377
19378 \family roman
19379 \series medium
19380 \shape up
19381 \size normal
19382 \emph off
19383 \bar no
19384 \noun off
19385 \color none
19386 _fssub.c 
19387 \end_layout
19388
19389 \end_inset
19390 </cell>
19391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19392 \begin_inset Text
19393
19394 \begin_layout Standard
19395
19396 \family roman
19397 \series medium
19398 \shape up
19399 \size normal
19400 \emph off
19401 \bar no
19402 \noun off
19403 \color none
19404 subtract floating point numbers 
19405 \end_layout
19406
19407 \end_inset
19408 </cell>
19409 </row>
19410 <row topline="true">
19411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19412 \begin_inset Text
19413
19414 \begin_layout Standard
19415
19416 \family roman
19417 \series medium
19418 \shape up
19419 \size normal
19420 \emph off
19421 \bar no
19422 \noun off
19423 \color none
19424 _fsdiv.c 
19425 \end_layout
19426
19427 \end_inset
19428 </cell>
19429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19430 \begin_inset Text
19431
19432 \begin_layout Standard
19433
19434 \family roman
19435 \series medium
19436 \shape up
19437 \size normal
19438 \emph off
19439 \bar no
19440 \noun off
19441 \color none
19442 divide floating point numbers 
19443 \end_layout
19444
19445 \end_inset
19446 </cell>
19447 </row>
19448 <row topline="true">
19449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19450 \begin_inset Text
19451
19452 \begin_layout Standard
19453
19454 \family roman
19455 \series medium
19456 \shape up
19457 \size normal
19458 \emph off
19459 \bar no
19460 \noun off
19461 \color none
19462 _fsmul.c 
19463 \end_layout
19464
19465 \end_inset
19466 </cell>
19467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19468 \begin_inset Text
19469
19470 \begin_layout Standard
19471
19472 \family roman
19473 \series medium
19474 \shape up
19475 \size normal
19476 \emph off
19477 \bar no
19478 \noun off
19479 \color none
19480 multiply floating point numbers 
19481 \end_layout
19482
19483 \end_inset
19484 </cell>
19485 </row>
19486 <row topline="true">
19487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19488 \begin_inset Text
19489
19490 \begin_layout Standard
19491
19492 \family roman
19493 \series medium
19494 \shape up
19495 \size normal
19496 \emph off
19497 \bar no
19498 \noun off
19499 \color none
19500 _fs2uchar.c
19501 \end_layout
19502
19503 \end_inset
19504 </cell>
19505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19506 \begin_inset Text
19507
19508 \begin_layout Standard
19509
19510 \family roman
19511 \series medium
19512 \shape up
19513 \size normal
19514 \emph off
19515 \bar no
19516 \noun off
19517 \color none
19518 convert floating point to unsigned char
19519 \end_layout
19520
19521 \end_inset
19522 </cell>
19523 </row>
19524 <row topline="true">
19525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19526 \begin_inset Text
19527
19528 \begin_layout Standard
19529
19530 \family roman
19531 \series medium
19532 \shape up
19533 \size normal
19534 \emph off
19535 \bar no
19536 \noun off
19537 \color none
19538 _fs2char.c
19539 \end_layout
19540
19541 \end_inset
19542 </cell>
19543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19544 \begin_inset Text
19545
19546 \begin_layout Standard
19547
19548 \family roman
19549 \series medium
19550 \shape up
19551 \size normal
19552 \emph off
19553 \bar no
19554 \noun off
19555 \color none
19556 convert floating point to signed char
19557 \end_layout
19558
19559 \end_inset
19560 </cell>
19561 </row>
19562 <row topline="true">
19563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19564 \begin_inset Text
19565
19566 \begin_layout Standard
19567
19568 \family roman
19569 \series medium
19570 \shape up
19571 \size normal
19572 \emph off
19573 \bar no
19574 \noun off
19575 \color none
19576 _fs2uint.c
19577 \end_layout
19578
19579 \end_inset
19580 </cell>
19581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19582 \begin_inset Text
19583
19584 \begin_layout Standard
19585
19586 \family roman
19587 \series medium
19588 \shape up
19589 \size normal
19590 \emph off
19591 \bar no
19592 \noun off
19593 \color none
19594 convert floating point to unsigned int
19595 \end_layout
19596
19597 \end_inset
19598 </cell>
19599 </row>
19600 <row topline="true">
19601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19602 \begin_inset Text
19603
19604 \begin_layout Standard
19605
19606 \family roman
19607 \series medium
19608 \shape up
19609 \size normal
19610 \emph off
19611 \bar no
19612 \noun off
19613 \color none
19614 _fs2int.c
19615 \end_layout
19616
19617 \end_inset
19618 </cell>
19619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19620 \begin_inset Text
19621
19622 \begin_layout Standard
19623
19624 \family roman
19625 \series medium
19626 \shape up
19627 \size normal
19628 \emph off
19629 \bar no
19630 \noun off
19631 \color none
19632 convert floating point to signed int
19633 \end_layout
19634
19635 \end_inset
19636 </cell>
19637 </row>
19638 <row topline="true">
19639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19640 \begin_inset Text
19641
19642 \begin_layout Standard
19643
19644 \family roman
19645 \series medium
19646 \shape up
19647 \size normal
19648 \emph off
19649 \bar no
19650 \noun off
19651 \color none
19652 _fs2ulong.
19653 \family default
19654 \series default
19655 \shape default
19656 \size default
19657 \emph default
19658 \bar default
19659 \noun default
19660 c
19661 \end_layout
19662
19663 \end_inset
19664 </cell>
19665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19666 \begin_inset Text
19667
19668 \begin_layout Standard
19669
19670 \family roman
19671 \series medium
19672 \shape up
19673 \size normal
19674 \emph off
19675 \bar no
19676 \noun off
19677 \color none
19678 convert floating point to unsigned long
19679 \end_layout
19680
19681 \end_inset
19682 </cell>
19683 </row>
19684 <row topline="true">
19685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19686 \begin_inset Text
19687
19688 \begin_layout Standard
19689
19690 \family roman
19691 \series medium
19692 \shape up
19693 \size normal
19694 \emph off
19695 \bar no
19696 \noun off
19697 \color none
19698 _fs2long.c
19699 \end_layout
19700
19701 \end_inset
19702 </cell>
19703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19704 \begin_inset Text
19705
19706 \begin_layout Standard
19707
19708 \family roman
19709 \series medium
19710 \shape up
19711 \size normal
19712 \emph off
19713 \bar no
19714 \noun off
19715 \color none
19716 convert floating point to signed long
19717 \end_layout
19718
19719 \end_inset
19720 </cell>
19721 </row>
19722 <row topline="true">
19723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19724 \begin_inset Text
19725
19726 \begin_layout Standard
19727
19728 \family roman
19729 \series medium
19730 \shape up
19731 \size normal
19732 \emph off
19733 \bar no
19734 \noun off
19735 \color none
19736 _uchar2fs.c
19737 \end_layout
19738
19739 \end_inset
19740 </cell>
19741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19742 \begin_inset Text
19743
19744 \begin_layout Standard
19745
19746 \family roman
19747 \series medium
19748 \shape up
19749 \size normal
19750 \emph off
19751 \bar no
19752 \noun off
19753 \color none
19754 convert unsigned char to floating point
19755 \end_layout
19756
19757 \end_inset
19758 </cell>
19759 </row>
19760 <row topline="true">
19761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19762 \begin_inset Text
19763
19764 \begin_layout Standard
19765
19766 \family roman
19767 \series medium
19768 \shape up
19769 \size normal
19770 \emph off
19771 \bar no
19772 \noun off
19773 \color none
19774 _char2fs.c
19775 \end_layout
19776
19777 \end_inset
19778 </cell>
19779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19780 \begin_inset Text
19781
19782 \begin_layout Standard
19783
19784 \family roman
19785 \series medium
19786 \shape up
19787 \size normal
19788 \emph off
19789 \bar no
19790 \noun off
19791 \color none
19792 convert char to floating point number
19793 \end_layout
19794
19795 \end_inset
19796 </cell>
19797 </row>
19798 <row topline="true">
19799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19800 \begin_inset Text
19801
19802 \begin_layout Standard
19803
19804 \family roman
19805 \series medium
19806 \shape up
19807 \size normal
19808 \emph off
19809 \bar no
19810 \noun off
19811 \color none
19812 _uint2fs.c
19813 \end_layout
19814
19815 \end_inset
19816 </cell>
19817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19818 \begin_inset Text
19819
19820 \begin_layout Standard
19821
19822 \family roman
19823 \series medium
19824 \shape up
19825 \size normal
19826 \emph off
19827 \bar no
19828 \noun off
19829 \color none
19830 convert unsigned int to floating point
19831 \end_layout
19832
19833 \end_inset
19834 </cell>
19835 </row>
19836 <row topline="true">
19837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19838 \begin_inset Text
19839
19840 \begin_layout Standard
19841
19842 \family roman
19843 \series medium
19844 \shape up
19845 \size normal
19846 \emph off
19847 \bar no
19848 \noun off
19849 \color none
19850 _int2fs.c
19851 \end_layout
19852
19853 \end_inset
19854 </cell>
19855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19856 \begin_inset Text
19857
19858 \begin_layout Standard
19859
19860 \family roman
19861 \series medium
19862 \shape up
19863 \size normal
19864 \emph off
19865 \bar no
19866 \noun off
19867 \color none
19868 convert int to floating point numbers
19869 \end_layout
19870
19871 \end_inset
19872 </cell>
19873 </row>
19874 <row topline="true">
19875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19876 \begin_inset Text
19877
19878 \begin_layout Standard
19879
19880 \family roman
19881 \series medium
19882 \shape up
19883 \size normal
19884 \emph off
19885 \bar no
19886 \noun off
19887 \color none
19888 _ulong2fs.c
19889 \end_layout
19890
19891 \end_inset
19892 </cell>
19893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19894 \begin_inset Text
19895
19896 \begin_layout Standard
19897
19898 \family roman
19899 \series medium
19900 \shape up
19901 \size normal
19902 \emph off
19903 \bar no
19904 \noun off
19905 \color none
19906 convert unsigned long to floating point number
19907 \end_layout
19908
19909 \end_inset
19910 </cell>
19911 </row>
19912 <row topline="true" bottomline="true">
19913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19914 \begin_inset Text
19915
19916 \begin_layout Standard
19917
19918 \family roman
19919 \series medium
19920 \shape up
19921 \size normal
19922 \emph off
19923 \bar no
19924 \noun off
19925 \color none
19926 _long2fs.c
19927 \end_layout
19928
19929 \end_inset
19930 </cell>
19931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19932 \begin_inset Text
19933
19934 \begin_layout Standard
19935
19936 \family roman
19937 \series medium
19938 \shape up
19939 \size normal
19940 \emph off
19941 \bar no
19942 \noun off
19943 \color none
19944 convert long to floating point number
19945 \end_layout
19946
19947 \end_inset
19948 </cell>
19949 </row>
19950 </lyxtabular>
19951
19952 \end_inset
19953
19954
19955 \newline
19956
19957 \end_layout
19958
19959 \begin_layout Standard
19960 These support routines are developed in ANSI-C so there is room for space
19961  and speed improvement
19962 \begin_inset Foot
19963 status open
19964
19965 \begin_layout Standard
19966 These floating point routines (
19967 \emph on
19968 not
19969 \emph default
19970  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19971  
19972 \end_layout
19973
19974 \end_inset
19975
19976 .
19977  Note if all these routines are used simultaneously the data space might
19978  overflow.
19979  For serious floating point usage the large model might be needed.
19980  Also notice that you don't have to call this routines directly.
19981  The compiler will use them automatically every time a floating point operation
19982  is required.
19983 \begin_inset VSpace bigskip
19984 \end_inset
19985
19986
19987 \end_layout
19988
19989 \begin_layout Section
19990 Library Routines
19991 \begin_inset LatexCommand \index{Libraries}
19992
19993 \end_inset
19994
19995
19996 \end_layout
19997
19998 \begin_layout Standard
19999
20000 \emph on
20001 <pending: this is messy and incomplete - a little more information is in
20002  sdcc/doc/libdoc.txt
20003 \emph default
20004  >
20005 \end_layout
20006
20007 \begin_layout Subsection
20008 Compiler support routines (_gptrget, _mulint etc.)
20009 \end_layout
20010
20011 \begin_layout Subsection
20012 Stdclib functions (puts, printf, strcat etc.)
20013 \end_layout
20014
20015 \begin_layout Subsubsection
20016 <stdio.h>
20017 \end_layout
20018
20019 \begin_layout Paragraph
20020 getchar(), putchar()
20021 \end_layout
20022
20023 \begin_layout Standard
20024 \begin_inset LatexCommand \index{<stdio.h>}
20025
20026 \end_inset
20027
20028 As usual on embedded systems you have to provide your own 
20029 \family typewriter
20030 getchar()
20031 \begin_inset LatexCommand \index{getchar()}
20032
20033 \end_inset
20034
20035  
20036 \family default
20037 and 
20038 \family typewriter
20039 putchar()
20040 \begin_inset LatexCommand \index{putchar()}
20041
20042 \end_inset
20043
20044
20045 \family default
20046  routines.
20047  SDCC does not know whether the system connects to a serial line with or
20048  without handshake, LCD, keyboard or other device.
20049  And whether a 
20050 \family typewriter
20051 lf
20052 \family default
20053  to 
20054 \family typewriter
20055 crlf
20056 \family default
20057  conversion within 
20058 \family typewriter
20059 putchar()
20060 \family default
20061  is intended.
20062  You'll find examples for serial routines f.e.
20063  in sdcc/device/lib.
20064  For the mcs51 this minimalistic polling 
20065 \family typewriter
20066 putchar()
20067 \family default
20068  routine might be a start:
20069 \end_layout
20070
20071 \begin_layout Verse
20072
20073 \family typewriter
20074 void putchar (char c) { 
20075 \newline
20076 \InsetSpace ~
20077 \InsetSpace ~
20078 \InsetSpace ~
20079 \InsetSpace ~
20080 while (!TI)\InsetSpace ~
20081 \InsetSpace ~
20082 \InsetSpace ~
20083  /* assumes UART is initialized */
20084 \newline
20085 \InsetSpace ~
20086 \InsetSpace ~
20087 \InsetSpace ~
20088 \InsetSpace ~
20089 \InsetSpace ~
20090 \InsetSpace ~
20091 \InsetSpace ~
20092 \InsetSpace ~
20093 ;
20094 \newline
20095 \InsetSpace ~
20096 \InsetSpace ~
20097 \InsetSpace ~
20098 \InsetSpace ~
20099 TI
20100  = 0;
20101 \newline
20102 \InsetSpace ~
20103 \InsetSpace ~
20104 \InsetSpace ~
20105 \InsetSpace ~
20106 SBUF = c;
20107 \newline
20108 }
20109 \end_layout
20110
20111 \begin_layout Paragraph
20112 printf()
20113 \end_layout
20114
20115 \begin_layout Standard
20116 The default
20117 \family typewriter
20118  printf()
20119 \begin_inset LatexCommand \index{printf()}
20120
20121 \end_inset
20122
20123
20124 \family default
20125  implementation in
20126 \family typewriter
20127  printf_large.c
20128 \family default
20129  does not support float (except on ds390).
20130  To enable this recompile it with the option 
20131 \emph on
20132 -
20133 \begin_inset ERT
20134 status collapsed
20135
20136 \begin_layout Standard
20137
20138
20139 \backslash
20140 /
20141 \end_layout
20142
20143 \end_inset
20144
20145 DUSE_FLOATS=1
20146 \begin_inset LatexCommand \index{USE\_FLOATS}
20147
20148 \end_inset
20149
20150
20151 \emph default
20152  on the command line.
20153  Use
20154 \emph on
20155  -
20156 \begin_inset ERT
20157 status collapsed
20158
20159 \begin_layout Standard
20160
20161
20162 \backslash
20163 /
20164 \end_layout
20165
20166 \end_inset
20167
20168 -model-large
20169 \begin_inset LatexCommand \index{-\/-model-large}
20170
20171 \end_inset
20172
20173
20174 \emph default
20175  for the mcs51 port, since this uses a lot of memory.
20176 \end_layout
20177
20178 \begin_layout Standard
20179 If you're short on code memory you might want to use 
20180 \family typewriter
20181 printf_small()
20182 \begin_inset LatexCommand \index{printf\_small()}
20183
20184 \end_inset
20185
20186
20187 \family default
20188  
20189 \emph on
20190 instead
20191 \emph default
20192  of
20193 \family typewriter
20194  printf().
20195
20196 \family default
20197  For the mcs51 there additionally are assembly versions 
20198 \family typewriter
20199 printf_tiny()
20200 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20201
20202 \end_inset
20203
20204
20205 \family default
20206  (subset of printf using less than 270 bytes) and 
20207 \family typewriter
20208 printf_fast()
20209 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20210
20211 \end_inset
20212
20213  
20214 \family default
20215 and
20216 \family typewriter
20217  printf_fast_f()
20218 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20219
20220 \end_inset
20221
20222
20223 \family default
20224  (floating-point aware version of printf_fast) which should fit the requirements
20225  of many embedded systems (printf_fast() can be customized by unsetting
20226  #defines to 
20227 \emph on
20228 not
20229 \emph default
20230  support long variables and field widths).
20231  Be sure to use only one of these printf options within a project.
20232 \newline
20233
20234 \end_layout
20235
20236 \begin_layout Standard
20237 Feature matrix of different 
20238 \emph on
20239 printf
20240 \emph default
20241  options on mcs51.
20242 \end_layout
20243
20244 \begin_layout Standard
20245 \begin_inset Tabular
20246 <lyxtabular version="3" rows="14" columns="7">
20247 <features islongtable="true">
20248 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20249 <column alignment="center" valignment="top" leftline="true" width="0">
20250 <column alignment="center" valignment="top" leftline="true" width="12col%">
20251 <column alignment="center" valignment="top" leftline="true" width="10col%">
20252 <column alignment="center" valignment="top" leftline="true" width="0">
20253 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20254 <column alignment="center" valignment="top" rightline="true" width="0">
20255 <row topline="true" bottomline="true" endhead="true">
20256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20257 \begin_inset Text
20258
20259 \begin_layout Standard
20260
20261 \series bold
20262 \size large
20263 mcs51
20264 \end_layout
20265
20266 \end_inset
20267 </cell>
20268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20269 \begin_inset Text
20270
20271 \begin_layout Standard
20272 printf
20273 \begin_inset LatexCommand \index{printf}
20274
20275 \end_inset
20276
20277
20278 \end_layout
20279
20280 \end_inset
20281 </cell>
20282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20283 \begin_inset Text
20284
20285 \begin_layout Standard
20286 printf 
20287 \size scriptsize
20288 USE_FLOATS=1
20289 \end_layout
20290
20291 \end_inset
20292 </cell>
20293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20294 \begin_inset Text
20295
20296 \begin_layout Standard
20297 printf_small
20298 \end_layout
20299
20300 \end_inset
20301 </cell>
20302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20303 \begin_inset Text
20304
20305 \begin_layout Standard
20306 printf_fast
20307 \end_layout
20308
20309 \end_inset
20310 </cell>
20311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20312 \begin_inset Text
20313
20314 \begin_layout Standard
20315 printf_fast_f
20316 \end_layout
20317
20318 \end_inset
20319 </cell>
20320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20321 \begin_inset Text
20322
20323 \begin_layout Standard
20324 printf_tiny
20325 \end_layout
20326
20327 \end_inset
20328 </cell>
20329 </row>
20330 <row topline="true" endhead="true">
20331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20332 \begin_inset Text
20333
20334 \begin_layout Standard
20335 filename
20336 \end_layout
20337
20338 \end_inset
20339 </cell>
20340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20341 \begin_inset Text
20342
20343 \begin_layout Standard
20344
20345 \size scriptsize
20346 printf_large.c
20347 \end_layout
20348
20349 \end_inset
20350 </cell>
20351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20352 \begin_inset Text
20353
20354 \begin_layout Standard
20355
20356 \size scriptsize
20357 printf_large.c
20358 \end_layout
20359
20360 \end_inset
20361 </cell>
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20363 \begin_inset Text
20364
20365 \begin_layout Standard
20366
20367 \size scriptsize
20368 printfl.c
20369 \end_layout
20370
20371 \end_inset
20372 </cell>
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20374 \begin_inset Text
20375
20376 \begin_layout Standard
20377
20378 \size scriptsize
20379 printf_fast.c
20380 \end_layout
20381
20382 \end_inset
20383 </cell>
20384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20385 \begin_inset Text
20386
20387 \begin_layout Standard
20388
20389 \size scriptsize
20390 printf_fast_f.c
20391 \end_layout
20392
20393 \end_inset
20394 </cell>
20395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20396 \begin_inset Text
20397
20398 \begin_layout Standard
20399
20400 \size scriptsize
20401 printf_tiny.c
20402 \end_layout
20403
20404 \end_inset
20405 </cell>
20406 </row>
20407 <row topline="true" endhead="true">
20408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20409 \begin_inset Text
20410
20411 \begin_layout Standard
20412 \begin_inset Quotes sld
20413 \end_inset
20414
20415 Hello World
20416 \begin_inset Quotes srd
20417 \end_inset
20418
20419  size
20420 \end_layout
20421
20422 \begin_layout Standard
20423 small / large
20424 \end_layout
20425
20426 \end_inset
20427 </cell>
20428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20429 \begin_inset Text
20430
20431 \begin_layout Standard
20432 1.7k / 2.4k
20433 \end_layout
20434
20435 \end_inset
20436 </cell>
20437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20438 \begin_inset Text
20439
20440 \begin_layout Standard
20441 4.3k / 5.6k
20442 \end_layout
20443
20444 \end_inset
20445 </cell>
20446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20447 \begin_inset Text
20448
20449 \begin_layout Standard
20450 1.2k / 1.8k
20451 \end_layout
20452
20453 \end_inset
20454 </cell>
20455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20456 \begin_inset Text
20457
20458 \begin_layout Standard
20459 1.3k / 1.3k
20460 \end_layout
20461
20462 \end_inset
20463 </cell>
20464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20465 \begin_inset Text
20466
20467 \begin_layout Standard
20468 1.9k / 1.9k
20469 \end_layout
20470
20471 \end_inset
20472 </cell>
20473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20474 \begin_inset Text
20475
20476 \begin_layout Standard
20477 0.44k / 0.44k
20478 \end_layout
20479
20480 \end_inset
20481 </cell>
20482 </row>
20483 <row topline="true" endhead="true">
20484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20485 \begin_inset Text
20486
20487 \begin_layout Standard
20488 code size
20489 \end_layout
20490
20491 \begin_layout Standard
20492 small / large
20493 \end_layout
20494
20495 \end_inset
20496 </cell>
20497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20498 \begin_inset Text
20499
20500 \begin_layout Standard
20501 1.4k / 2.0k
20502 \end_layout
20503
20504 \end_inset
20505 </cell>
20506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20507 \begin_inset Text
20508
20509 \begin_layout Standard
20510 2.8k / 3.7k
20511 \end_layout
20512
20513 \end_inset
20514 </cell>
20515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20516 \begin_inset Text
20517
20518 \begin_layout Standard
20519 0.45k / 0.47k (+ _ltoa)
20520 \end_layout
20521
20522 \end_inset
20523 </cell>
20524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20525 \begin_inset Text
20526
20527 \begin_layout Standard
20528 1.2k / 1.2k
20529 \end_layout
20530
20531 \end_inset
20532 </cell>
20533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20534 \begin_inset Text
20535
20536 \begin_layout Standard
20537 1.6k / 1.6k
20538 \end_layout
20539
20540 \end_inset
20541 </cell>
20542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20543 \begin_inset Text
20544
20545 \begin_layout Standard
20546 0.26k / 0.26k
20547 \end_layout
20548
20549 \end_inset
20550 </cell>
20551 </row>
20552 <row topline="true">
20553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20554 \begin_inset Text
20555
20556 \begin_layout Standard
20557 formats
20558 \end_layout
20559
20560 \end_inset
20561 </cell>
20562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20563 \begin_inset Text
20564
20565 \begin_layout Standard
20566 cdi
20567 \emph on
20568 o
20569 \emph default
20570 psux
20571 \end_layout
20572
20573 \end_inset
20574 </cell>
20575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20576 \begin_inset Text
20577
20578 \begin_layout Standard
20579
20580 \family roman
20581 \series medium
20582 \shape up
20583 \size normal
20584 \emph off
20585 \bar no
20586 \noun off
20587 \color none
20588 cd
20589 \family default
20590 \series default
20591 \shape default
20592 \size default
20593 \emph default
20594 \bar default
20595 \noun default
20596 f
20597 \family roman
20598 \series medium
20599 \shape up
20600 \size normal
20601 \emph off
20602 \bar no
20603 \noun off
20604 i
20605 \family default
20606 \series default
20607 \shape default
20608 \size default
20609 \emph on
20610 \bar default
20611 \noun default
20612 o
20613 \family roman
20614 \series medium
20615 \shape up
20616 \size normal
20617 \emph off
20618 \bar no
20619 \noun off
20620 psux
20621 \end_layout
20622
20623 \end_inset
20624 </cell>
20625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20626 \begin_inset Text
20627
20628 \begin_layout Standard
20629 c
20630 \family roman
20631 \series medium
20632 \shape up
20633 \size normal
20634 \emph off
20635 \bar no
20636 \noun off
20637 \color none
20638 d
20639 \family default
20640 \series default
20641 \shape default
20642 \size default
20643 \emph on
20644 \bar default
20645 \noun default
20646 o
20647 \family roman
20648 \series medium
20649 \shape up
20650 \size normal
20651 \emph off
20652 \bar no
20653 \noun off
20654 s
20655 \family default
20656 \series default
20657 \shape default
20658 \size default
20659 \emph default
20660 \bar default
20661 \noun default
20662 x
20663 \end_layout
20664
20665 \end_inset
20666 </cell>
20667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20668 \begin_inset Text
20669
20670 \begin_layout Standard
20671 cdsux
20672 \end_layout
20673
20674 \end_inset
20675 </cell>
20676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20677 \begin_inset Text
20678
20679 \begin_layout Standard
20680 cdfsux
20681 \end_layout
20682
20683 \end_inset
20684 </cell>
20685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20686 \begin_inset Text
20687
20688 \begin_layout Standard
20689 cdsux
20690 \end_layout
20691
20692 \end_inset
20693 </cell>
20694 </row>
20695 <row topline="true">
20696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20697 \begin_inset Text
20698
20699 \begin_layout Standard
20700 long (32 bit) support
20701 \end_layout
20702
20703 \end_inset
20704 </cell>
20705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20706 \begin_inset Text
20707
20708 \begin_layout Standard
20709 x
20710 \end_layout
20711
20712 \end_inset
20713 </cell>
20714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20715 \begin_inset Text
20716
20717 \begin_layout Standard
20718 x
20719 \end_layout
20720
20721 \end_inset
20722 </cell>
20723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20724 \begin_inset Text
20725
20726 \begin_layout Standard
20727 x
20728 \end_layout
20729
20730 \end_inset
20731 </cell>
20732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20733 \begin_inset Text
20734
20735 \begin_layout Standard
20736 x
20737 \end_layout
20738
20739 \end_inset
20740 </cell>
20741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20742 \begin_inset Text
20743
20744 \begin_layout Standard
20745
20746 \family roman
20747 \series medium
20748 \shape up
20749 \size normal
20750 \emph off
20751 \bar no
20752 \noun off
20753 \color none
20754 x
20755 \end_layout
20756
20757 \end_inset
20758 </cell>
20759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20760 \begin_inset Text
20761
20762 \begin_layout Standard
20763 -
20764 \end_layout
20765
20766 \end_inset
20767 </cell>
20768 </row>
20769 <row topline="true">
20770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20771 \begin_inset Text
20772
20773 \begin_layout Standard
20774 byte arguments on stack
20775 \end_layout
20776
20777 \end_inset
20778 </cell>
20779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20780 \begin_inset Text
20781
20782 \begin_layout Standard
20783 b
20784 \end_layout
20785
20786 \end_inset
20787 </cell>
20788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20789 \begin_inset Text
20790
20791 \begin_layout Standard
20792 b
20793 \end_layout
20794
20795 \end_inset
20796 </cell>
20797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20798 \begin_inset Text
20799
20800 \begin_layout Standard
20801 -
20802 \end_layout
20803
20804 \end_inset
20805 </cell>
20806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20807 \begin_inset Text
20808
20809 \begin_layout Standard
20810 -
20811 \end_layout
20812
20813 \end_inset
20814 </cell>
20815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20816 \begin_inset Text
20817
20818 \begin_layout Standard
20819 -
20820 \end_layout
20821
20822 \end_inset
20823 </cell>
20824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20825 \begin_inset Text
20826
20827 \begin_layout Standard
20828 -
20829 \end_layout
20830
20831 \end_inset
20832 </cell>
20833 </row>
20834 <row topline="true">
20835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20836 \begin_inset Text
20837
20838 \begin_layout Standard
20839 float format
20840 \begin_inset LatexCommand \index{Floating point support}
20841
20842 \end_inset
20843
20844
20845 \end_layout
20846
20847 \end_inset
20848 </cell>
20849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20850 \begin_inset Text
20851
20852 \begin_layout Standard
20853 -
20854 \end_layout
20855
20856 \end_inset
20857 </cell>
20858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20859 \begin_inset Text
20860
20861 \begin_layout Standard
20862 %f
20863 \end_layout
20864
20865 \end_inset
20866 </cell>
20867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20868 \begin_inset Text
20869
20870 \begin_layout Standard
20871 -
20872 \end_layout
20873
20874 \end_inset
20875 </cell>
20876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20877 \begin_inset Text
20878
20879 \begin_layout Standard
20880 -
20881 \end_layout
20882
20883 \end_inset
20884 </cell>
20885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20886 \begin_inset Text
20887
20888 \begin_layout Standard
20889 %f
20890 \begin_inset Foot
20891 status collapsed
20892
20893 \begin_layout Standard
20894 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20895 \end_layout
20896
20897 \end_inset
20898
20899
20900 \end_layout
20901
20902 \end_inset
20903 </cell>
20904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20905 \begin_inset Text
20906
20907 \begin_layout Standard
20908 -
20909 \end_layout
20910
20911 \end_inset
20912 </cell>
20913 </row>
20914 <row topline="true">
20915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20916 \begin_inset Text
20917
20918 \begin_layout Standard
20919 float formats %e %g
20920 \end_layout
20921
20922 \end_inset
20923 </cell>
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20925 \begin_inset Text
20926
20927 \begin_layout Standard
20928 -
20929 \end_layout
20930
20931 \end_inset
20932 </cell>
20933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20934 \begin_inset Text
20935
20936 \begin_layout Standard
20937 -
20938 \end_layout
20939
20940 \end_inset
20941 </cell>
20942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20943 \begin_inset Text
20944
20945 \begin_layout Standard
20946 -
20947 \end_layout
20948
20949 \end_inset
20950 </cell>
20951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20952 \begin_inset Text
20953
20954 \begin_layout Standard
20955 -
20956 \end_layout
20957
20958 \end_inset
20959 </cell>
20960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20961 \begin_inset Text
20962
20963 \begin_layout Standard
20964 -
20965 \end_layout
20966
20967 \end_inset
20968 </cell>
20969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20970 \begin_inset Text
20971
20972 \begin_layout Standard
20973 -
20974 \end_layout
20975
20976 \end_inset
20977 </cell>
20978 </row>
20979 <row topline="true" bottomline="true">
20980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20981 \begin_inset Text
20982
20983 \begin_layout Standard
20984 field width
20985 \end_layout
20986
20987 \end_inset
20988 </cell>
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20990 \begin_inset Text
20991
20992 \begin_layout Standard
20993 x
20994 \end_layout
20995
20996 \end_inset
20997 </cell>
20998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20999 \begin_inset Text
21000
21001 \begin_layout Standard
21002 x
21003 \end_layout
21004
21005 \end_inset
21006 </cell>
21007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21008 \begin_inset Text
21009
21010 \begin_layout Standard
21011 -
21012 \end_layout
21013
21014 \end_inset
21015 </cell>
21016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21017 \begin_inset Text
21018
21019 \begin_layout Standard
21020 x
21021 \end_layout
21022
21023 \end_inset
21024 </cell>
21025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21026 \begin_inset Text
21027
21028 \begin_layout Standard
21029 x
21030 \end_layout
21031
21032 \end_inset
21033 </cell>
21034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21035 \begin_inset Text
21036
21037 \begin_layout Standard
21038 -
21039 \end_layout
21040
21041 \end_inset
21042 </cell>
21043 </row>
21044 <row bottomline="true">
21045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21046 \begin_inset Text
21047
21048 \begin_layout Standard
21049 string speed
21050 \begin_inset Foot
21051 status collapsed
21052
21053 \begin_layout Standard
21054 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21055 \backslash
21056 r', '
21057 \backslash
21058 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21059 \end_layout
21060
21061 \end_inset
21062
21063 ,
21064 \end_layout
21065
21066 \begin_layout Standard
21067 small / large
21068 \end_layout
21069
21070 \end_inset
21071 </cell>
21072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21073 \begin_inset Text
21074
21075 \begin_layout Standard
21076 1.52 / 2.59 ms
21077 \end_layout
21078
21079 \end_inset
21080 </cell>
21081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21082 \begin_inset Text
21083
21084 \begin_layout Standard
21085 1.53 / 2.62 ms
21086 \end_layout
21087
21088 \end_inset
21089 </cell>
21090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21091 \begin_inset Text
21092
21093 \begin_layout Standard
21094 0.92 / 0.93 ms
21095 \end_layout
21096
21097 \end_inset
21098 </cell>
21099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21100 \begin_inset Text
21101
21102 \begin_layout Standard
21103 0.45 / 0.45 ms
21104 \end_layout
21105
21106 \end_inset
21107 </cell>
21108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21109 \begin_inset Text
21110
21111 \begin_layout Standard
21112 0.46 / 0.46 ms
21113 \end_layout
21114
21115 \end_inset
21116 </cell>
21117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21118 \begin_inset Text
21119
21120 \begin_layout Standard
21121 0.45 / 0.45 ms
21122 \end_layout
21123
21124 \end_inset
21125 </cell>
21126 </row>
21127 <row bottomline="true">
21128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21129 \begin_inset Text
21130
21131 \begin_layout Standard
21132 int speed
21133 \begin_inset Foot
21134 status collapsed
21135
21136 \begin_layout Standard
21137 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21138  putchar()
21139 \end_layout
21140
21141 \end_inset
21142
21143 ,
21144 \end_layout
21145
21146 \begin_layout Standard
21147 small / large
21148 \end_layout
21149
21150 \end_inset
21151 </cell>
21152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21153 \begin_inset Text
21154
21155 \begin_layout Standard
21156 3.01 / 3.61 ms
21157 \end_layout
21158
21159 \end_inset
21160 </cell>
21161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21162 \begin_inset Text
21163
21164 \begin_layout Standard
21165 3.01 / 3.61 ms
21166 \end_layout
21167
21168 \end_inset
21169 </cell>
21170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21171 \begin_inset Text
21172
21173 \begin_layout Standard
21174 3.51 / 18.13 ms
21175 \end_layout
21176
21177 \end_inset
21178 </cell>
21179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21180 \begin_inset Text
21181
21182 \begin_layout Standard
21183 0.22 / 0.22 ms
21184 \end_layout
21185
21186 \end_inset
21187 </cell>
21188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21189 \begin_inset Text
21190
21191 \begin_layout Standard
21192 0.23 / 0.23 ms
21193 \end_layout
21194
21195 \end_inset
21196 </cell>
21197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21198 \begin_inset Text
21199
21200 \begin_layout Standard
21201 0.25 / 0.25 ms
21202 \begin_inset Foot
21203 status collapsed
21204
21205 \begin_layout Standard
21206 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21207 \end_layout
21208
21209 \end_inset
21210
21211
21212 \end_layout
21213
21214 \end_inset
21215 </cell>
21216 </row>
21217 <row bottomline="true">
21218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21219 \begin_inset Text
21220
21221 \begin_layout Standard
21222 long speed
21223 \begin_inset Foot
21224 status collapsed
21225
21226 \begin_layout Standard
21227 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21228  empty putchar()
21229 \end_layout
21230
21231 \end_inset
21232
21233 ,
21234 \end_layout
21235
21236 \begin_layout Standard
21237 small / large
21238 \end_layout
21239
21240 \end_inset
21241 </cell>
21242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21243 \begin_inset Text
21244
21245 \begin_layout Standard
21246 5.37 / 6.31 ms
21247 \end_layout
21248
21249 \end_inset
21250 </cell>
21251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21252 \begin_inset Text
21253
21254 \begin_layout Standard
21255 5.37 / 6.31 ms
21256 \end_layout
21257
21258 \end_inset
21259 </cell>
21260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21261 \begin_inset Text
21262
21263 \begin_layout Standard
21264 8.71 / 40.65 ms
21265 \end_layout
21266
21267 \end_inset
21268 </cell>
21269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21270 \begin_inset Text
21271
21272 \begin_layout Standard
21273 0.40 / 0.40 ms
21274 \end_layout
21275
21276 \end_inset
21277 </cell>
21278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21279 \begin_inset Text
21280
21281 \begin_layout Standard
21282 0.40 / 0.40 ms
21283 \end_layout
21284
21285 \end_inset
21286 </cell>
21287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21288 \begin_inset Text
21289
21290 \begin_layout Standard
21291 -
21292 \end_layout
21293
21294 \end_inset
21295 </cell>
21296 </row>
21297 <row bottomline="true">
21298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21299 \begin_inset Text
21300
21301 \begin_layout Standard
21302 float speed
21303 \begin_inset Foot
21304 status collapsed
21305
21306 \begin_layout Standard
21307 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21308  empty putchar()
21309 \end_layout
21310
21311 \end_inset
21312
21313 ,
21314 \end_layout
21315
21316 \begin_layout Standard
21317 small / large
21318 \end_layout
21319
21320 \end_inset
21321 </cell>
21322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21323 \begin_inset Text
21324
21325 \begin_layout Standard
21326 -
21327 \end_layout
21328
21329 \end_inset
21330 </cell>
21331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21332 \begin_inset Text
21333
21334 \begin_layout Standard
21335 7.49 / 22.47 ms
21336 \end_layout
21337
21338 \end_inset
21339 </cell>
21340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21341 \begin_inset Text
21342
21343 \begin_layout Standard
21344 -
21345 \end_layout
21346
21347 \end_inset
21348 </cell>
21349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21350 \begin_inset Text
21351
21352 \begin_layout Standard
21353 -
21354 \end_layout
21355
21356 \end_inset
21357 </cell>
21358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21359 \begin_inset Text
21360
21361 \begin_layout Standard
21362 1.04 / 1.04 ms
21363 \end_layout
21364
21365 \end_inset
21366 </cell>
21367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21368 \begin_inset Text
21369
21370 \begin_layout Standard
21371 -
21372 \end_layout
21373
21374 \end_inset
21375 </cell>
21376 </row>
21377 </lyxtabular>
21378
21379 \end_inset
21380
21381
21382 \end_layout
21383
21384 \begin_layout Subsubsection
21385 <malloc.h>
21386 \begin_inset LatexCommand \index{malloc.h}
21387
21388 \end_inset
21389
21390
21391 \end_layout
21392
21393 \begin_layout Standard
21394 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21395  using dynamic memory allocation
21396 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21397
21398 \end_inset
21399
21400  and a default heap
21401 \begin_inset LatexCommand \index{heap (malloc)}
21402
21403 \end_inset
21404
21405  space of 1024 bytes is provided for malloc to allocate memory from.
21406  If you need a different heap size you need to recompile _heap.c with the
21407  required size defined in HEAP_SIZE.
21408  It is recommended to make a copy of this file into your project directory
21409  and compile it there with:
21410 \end_layout
21411
21412 \begin_layout Verse
21413
21414 \family typewriter
21415 sdcc -c _heap.c -D HEAD_SIZE=2048
21416 \end_layout
21417
21418 \begin_layout Standard
21419 And then link it with:
21420 \end_layout
21421
21422 \begin_layout Verse
21423
21424 \family typewriter
21425 sdcc main.rel _heap.rel
21426 \end_layout
21427
21428 \begin_layout Subsection
21429 Math functions (sinf, powf, sqrtf etc.)
21430 \end_layout
21431
21432 \begin_layout Subsubsection
21433 <math.h>
21434 \end_layout
21435
21436 \begin_layout Standard
21437 See definitions in file <math.h>.
21438 \end_layout
21439
21440 \begin_layout Subsection
21441 Other libraries
21442 \end_layout
21443
21444 \begin_layout Standard
21445 Libraries
21446 \begin_inset LatexCommand \index{Libraries}
21447
21448 \end_inset
21449
21450  included in SDCC should have a license at least as liberal as the GNU Lesser
21451  General Public License
21452 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21453
21454 \end_inset
21455
21456  
21457 \emph on
21458 LGPL
21459 \emph default
21460 .
21461 \end_layout
21462
21463 \begin_layout Standard
21464 \begin_inset Note Note
21465 status collapsed
21466
21467 \begin_layout Standard
21468 license statements for the libraries are missing.
21469  sdcc/device/lib/ser_ir.c
21470 \end_layout
21471
21472 \begin_layout Standard
21473 or _decdptr f.e.
21474  come with a GPL (as opposed to LGPL) License - this will not be liberal
21475  enough for many embedded programmers.
21476 \end_layout
21477
21478 \end_inset
21479
21480
21481 \end_layout
21482
21483 \begin_layout Standard
21484 If you have ported some library or want to share experience about some code
21485  which f.e.
21486  falls into any of these categories Busses (I
21487 \begin_inset Formula $^{\textrm{2}}$
21488 \end_inset
21489
21490 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21491  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21492  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21493 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21494
21495 \end_inset
21496
21497 \InsetSpace ~
21498 would certainly like to hear about it.
21499 \end_layout
21500
21501 \begin_layout Standard
21502 Programmers coding for embedded systems are not especially famous for being
21503  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21504 e these references are very valuable.
21505  Let's help to create a climate where information is shared.
21506 \begin_inset VSpace bigskip
21507 \end_inset
21508
21509
21510 \end_layout
21511
21512 \begin_layout Section
21513 Memory Models
21514 \end_layout
21515
21516 \begin_layout Subsection
21517 MCS51 Memory Models
21518 \begin_inset LatexCommand \index{Memory model}
21519
21520 \end_inset
21521
21522
21523 \begin_inset LatexCommand \index{MCS51 memory model}
21524
21525 \end_inset
21526
21527
21528 \end_layout
21529
21530 \begin_layout Subsubsection
21531 Small, Medium and Large
21532 \end_layout
21533
21534 \begin_layout Standard
21535 SDCC allows three memory models for MCS51 code, 
21536 \shape slanted
21537 small, medium
21538 \shape default
21539  and 
21540 \shape slanted
21541 large
21542 \shape default
21543 .
21544  Modules compiled with different memory models should 
21545 \emph on
21546 never
21547 \emph default
21548  be combined together or the results would be unpredictable.
21549  The library routines supplied with the compiler are compiled as small,
21550  medium and large.
21551  The compiled library modules are contained in separate directories as small,
21552  medium and large so that you can link to the appropriate set.
21553 \end_layout
21554
21555 \begin_layout Standard
21556 When the medium or large model is used all variables declared without a
21557  storage class will be allocated into the external ram, this includes all
21558  parameters and local variables (for non-reentrant
21559 \begin_inset LatexCommand \index{reentrant}
21560
21561 \end_inset
21562
21563  functions).
21564  When the small model is used variables without storage class are allocated
21565  in the internal ram.
21566 \end_layout
21567
21568 \begin_layout Standard
21569 Judicious usage of the processor specific storage classes
21570 \begin_inset LatexCommand \index{Storage class}
21571
21572 \end_inset
21573
21574  and the 'reentrant' function type will yield much more efficient code,
21575  than using the large model.
21576  Several optimizations are disabled when the program is compiled using the
21577  large model, it is therefore recommended that the small model be used unless
21578  absolutely required.
21579 \end_layout
21580
21581 \begin_layout Subsubsection
21582 External Stack
21583 \begin_inset LatexCommand \label{sub:External-Stack}
21584
21585 \end_inset
21586
21587
21588 \begin_inset LatexCommand \index{stack}
21589
21590 \end_inset
21591
21592
21593 \begin_inset LatexCommand \index{External stack (mcs51)}
21594
21595 \end_inset
21596
21597
21598 \end_layout
21599
21600 \begin_layout Standard
21601 The external stack (-
21602 \begin_inset ERT
21603 status collapsed
21604
21605 \begin_layout Standard
21606
21607
21608 \backslash
21609 /
21610 \end_layout
21611
21612 \end_inset
21613
21614 -xstack option
21615 \begin_inset LatexCommand \index{-\/-xstack}
21616
21617 \end_inset
21618
21619 ) is located in pdata
21620 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21621
21622 \end_inset
21623
21624  memory (usually at the start of the external ram segment) and uses all
21625  unused space in pdata (max.
21626  256 bytes).
21627  When -
21628 \begin_inset ERT
21629 status collapsed
21630
21631 \begin_layout Standard
21632
21633
21634 \backslash
21635 /
21636 \end_layout
21637
21638 \end_inset
21639
21640 -xstack option is used to compile the program, the parameters and local
21641  variables
21642 \begin_inset LatexCommand \index{local variables}
21643
21644 \end_inset
21645
21646  of all reentrant functions are allocated in this area.
21647  This option is provided for programs with large stack space requirements.
21648  When used with the -
21649 \begin_inset ERT
21650 status collapsed
21651
21652 \begin_layout Standard
21653
21654
21655 \backslash
21656 /
21657 \end_layout
21658
21659 \end_inset
21660
21661 -stack-auto
21662 \begin_inset LatexCommand \index{-\/-stack-auto}
21663
21664 \end_inset
21665
21666  option, all parameters and local variables are allocated on the external
21667  stack (note: support libraries will need to be recompiled with the same
21668  options.
21669  There is a predefined target in the library makefile).
21670 \end_layout
21671
21672 \begin_layout Standard
21673 The compiler outputs the higher order address byte of the external ram segment
21674  into port P2
21675 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21676
21677 \end_inset
21678
21679  (see also section 
21680 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21681
21682 \end_inset
21683
21684 ), therefore when using the External Stack option, this port 
21685 \emph on
21686 may not
21687 \emph default
21688  be used by the application program.
21689 \end_layout
21690
21691 \begin_layout Subsection
21692 DS390 Memory Model
21693 \begin_inset LatexCommand \index{Memory model}
21694
21695 \end_inset
21696
21697
21698 \begin_inset LatexCommand \index{DS390 memory model}
21699
21700 \end_inset
21701
21702
21703 \end_layout
21704
21705 \begin_layout Standard
21706 The only model supported is Flat 24
21707 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21708
21709 \end_inset
21710
21711 .
21712  This generates code for the 24 bit contiguous addressing mode of the Dallas
21713  DS80C390 part.
21714  In this mode, up to four meg of external RAM or code space can be directly
21715  addressed.
21716  See the data sheets at www.dalsemi.com for further information on this part.
21717 \newline
21718
21719 \newline
21720 Note
21721  that the compiler does not generate any code to place the processor into
21722  24 bitmode (although 
21723 \emph on
21724 tinibios
21725 \emph default
21726  in the ds390 libraries will do that for you).
21727  If you don't use 
21728 \emph on
21729 tinibios
21730 \emph default
21731
21732 \begin_inset LatexCommand \index{Tinibios (DS390)}
21733
21734 \end_inset
21735
21736 , the boot loader or similar code must ensure that the processor is in 24
21737  bit contiguous addressing mode before calling the SDCC startup code.
21738 \newline
21739
21740 \newline
21741 Like
21742  the 
21743 \emph on
21744 -
21745 \begin_inset ERT
21746 status collapsed
21747
21748 \begin_layout Standard
21749
21750
21751 \backslash
21752 /
21753 \end_layout
21754
21755 \end_inset
21756
21757 -model-large
21758 \emph default
21759  option, variables will by default be placed into the XDATA segment.
21760  
21761 \newline
21762
21763 \newline
21764 Segments may be placed anywhere in the 4 meg address space using the usual
21765  -
21766 \begin_inset ERT
21767 status collapsed
21768
21769 \begin_layout Standard
21770
21771
21772 \backslash
21773 /
21774 \end_layout
21775
21776 \end_inset
21777
21778 -*-loc options.
21779  Note that if any segments are located above 64K, the -r flag must be passed
21780  to the linker to generate the proper segment relocations, and the Intel
21781  HEX output format must be used.
21782  The -r flag can be passed to the linker by using the option 
21783 \emph on
21784 -Wl-r
21785 \emph default
21786  on the SDCC command line.
21787  However, currently the linker can not handle code segments > 64k.
21788 \end_layout
21789
21790 \begin_layout Section
21791 Pragmas
21792 \begin_inset LatexCommand \label{sec:Pragmas}
21793
21794 \end_inset
21795
21796
21797 \begin_inset LatexCommand \index{Pragmas}
21798
21799 \end_inset
21800
21801
21802 \end_layout
21803
21804 \begin_layout Standard
21805 Pragmas are used to turn on and/or off certain compiler options.
21806  Some of them are closely related to corresponding command-line options
21807  (see section 
21808 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21809
21810 \end_inset
21811
21812 ).
21813 \newline
21814 Pragmas should be placed before and/or after a function, placing pragmas
21815  inside a function body could have unpredictable results.
21816 \newline
21817
21818 \newline
21819 SDCC supports the
21820  following #pragma directives:
21821 \end_layout
21822
21823 \begin_layout Itemize
21824
21825 \series bold
21826 save
21827 \series default
21828
21829 \begin_inset LatexCommand \index{\#pragma save}
21830
21831 \end_inset
21832
21833  - this will save most current options to the save/restore stack.
21834  See #pragma\InsetSpace ~
21835 restore.
21836 \end_layout
21837
21838 \begin_layout Itemize
21839
21840 \series bold
21841 restore
21842 \series default
21843
21844 \begin_inset LatexCommand \index{\#pragma restore}
21845
21846 \end_inset
21847
21848  - will restore saved options from the last save.
21849  saves & restores can be nested.
21850  SDCC uses a save/restore stack: save pushes current options to the stack,
21851  restore pulls current options from the stack.
21852  See #pragma\InsetSpace ~
21853 save.
21854 \newline
21855
21856 \end_layout
21857
21858 \begin_layout Itemize
21859
21860 \series bold
21861 callee_saves
21862 \series default
21863
21864 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21865
21866 \end_inset
21867
21868
21869 \begin_inset LatexCommand \index{function prologue}
21870
21871 \end_inset
21872
21873  function1[,function2[,function3...]] 
21874 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21875
21876 \end_inset
21877
21878 - The compiler by default uses a caller saves convention for register saving
21879  across function calls, however this can cause unnecessary register pushing
21880  and popping
21881 \begin_inset LatexCommand \index{push/pop}
21882
21883 \end_inset
21884
21885  when calling small functions from larger functions.
21886  This option can be used to switch off the register saving convention for
21887  the function names specified.
21888  The compiler will not save registers when calling these functions, extra
21889  code need to be manually inserted at the entry and exit for these functions
21890  to save and restore the registers used by these functions, this can SUBSTANTIAL
21891 LY reduce code and improve run time performance of the generated code.
21892  In the future the compiler (with inter procedural analysis) may be able
21893  to determine the appropriate scheme to use for each function call.
21894  If -
21895 \begin_inset ERT
21896 status collapsed
21897
21898 \begin_layout Standard
21899
21900
21901 \backslash
21902 /
21903 \end_layout
21904
21905 \end_inset
21906
21907 -callee-saves command line option is used (see page 
21908 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21909
21910 \end_inset
21911
21912 ), the function names specified in #pragma\InsetSpace ~
21913 callee_saves
21914 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21915
21916 \end_inset
21917
21918  is appended to the list of functions specified in the command line.
21919 \end_layout
21920
21921 \begin_layout Itemize
21922
21923 \series bold
21924 exclude
21925 \series default
21926
21927 \begin_inset LatexCommand \index{\#pragma exclude}
21928
21929 \end_inset
21930
21931  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21932  of pairs of push/pop
21933 \begin_inset LatexCommand \index{push/pop}
21934
21935 \end_inset
21936
21937  instructions in 
21938 \emph on
21939 I
21940 \emph default
21941 nterrupt
21942 \begin_inset LatexCommand \index{interrupt}
21943
21944 \end_inset
21945
21946  
21947 \emph on
21948 S
21949 \emph default
21950 ervice 
21951 \emph on
21952 R
21953 \emph default
21954 outines.
21955  The directive should be placed immediately before the ISR function definition
21956  and it affects ALL ISR functions following it.
21957  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21958 exclude\InsetSpace ~
21959 none
21960 \begin_inset LatexCommand \index{\#pragma exclude}
21961
21962 \end_inset
21963
21964 .
21965  See also the related keyword _naked
21966 \begin_inset LatexCommand \index{\_naked}
21967
21968 \end_inset
21969
21970
21971 \begin_inset LatexCommand \index{\_\_naked}
21972
21973 \end_inset
21974
21975 .
21976 \end_layout
21977
21978 \begin_layout Itemize
21979
21980 \series bold
21981 less_pedantic
21982 \series default
21983
21984 \begin_inset LatexCommand \index{pedantic}
21985
21986 \end_inset
21987
21988
21989 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21990
21991 \end_inset
21992
21993  
21994 \begin_inset LatexCommand \label{ite:less_pedantic}
21995
21996 \end_inset
21997
21998 - the compiler will not warn you anymore for obvious mistakes, you're on
21999  your own now ;-( .
22000  See also the command line option -
22001 \begin_inset ERT
22002 status collapsed
22003
22004 \begin_layout Standard
22005
22006
22007 \backslash
22008 /
22009 \end_layout
22010
22011 \end_inset
22012
22013 -less-pedantic 
22014 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
22015
22016 \end_inset
22017
22018 .
22019  
22020 \newline
22021 More specifically, the following warnings will be disabled: 
22022 \shape italic
22023 comparison is always [true/false] due to limited range of data type
22024 \shape default
22025  (94); 
22026 \shape italic
22027 overflow in implicit constant conversion
22028 \shape default
22029  (158); [the (in)famous] 
22030 \shape italic
22031 conditional flow changed by optimizer: so said EVELYN the modified DOG
22032 \shape default
22033  (110); 
22034 \shape italic
22035 function '[function name]' must return value
22036 \shape default
22037  (59).
22038  
22039 \newline
22040 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22041  level) are disabled, too, namely: 
22042 \shape italic
22043 constant value '[
22044 \begin_inset Note Note
22045 status collapsed
22046
22047 \begin_layout Standard
22048 dunno what comes here - this warning appears to be unused altogether
22049 \end_layout
22050
22051 \end_inset
22052
22053 ]', out of range
22054 \shape default
22055  (81); 
22056 \shape italic
22057 [left/right] shifting more than size of object changed to zero
22058 \shape default
22059  (116); 
22060 \shape italic
22061 unreachable code
22062 \shape default
22063  (126); 
22064 \shape italic
22065 integer overflow in expression
22066 \shape default
22067  (165); 
22068 \shape italic
22069 unmatched #pragma save and #pragma restore
22070 \shape default
22071  (170); 
22072 \shape italic
22073 comparison of 'signed char' with 'unsigned char' requires promotion to int
22074 \shape default
22075  (185); 
22076 \shape italic
22077 ISO C90 does not support flexible array members
22078 \shape default
22079  (187); 
22080 \shape italic
22081 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22082 nam
22083 e]':\InsetSpace ~
22084 [
22085 \begin_inset Note Note
22086 status collapsed
22087
22088 \begin_layout Standard
22089 appears to be always blank - what was supposed to be here?
22090 \end_layout
22091
22092 \end_inset
22093
22094 ]
22095 \shape default
22096  (114); 
22097 \shape italic
22098 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22099  complexity [number]
22100 \shape default
22101  (121).
22102 \end_layout
22103
22104 \begin_layout Itemize
22105
22106 \series bold
22107 disable_warning
22108 \series default
22109  <nnnn>
22110 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22111
22112 \end_inset
22113
22114  - the compiler will not warn you anymore about warning number <nnnn>.
22115 \end_layout
22116
22117 \begin_layout Itemize
22118
22119 \series bold
22120 nogcse
22121 \series default
22122
22123 \begin_inset LatexCommand \index{\#pragma nogcse}
22124
22125 \end_inset
22126
22127  - will stop global common subexpression elimination.
22128 \end_layout
22129
22130 \begin_layout Itemize
22131
22132 \series bold
22133 noinduction
22134 \series default
22135
22136 \begin_inset LatexCommand \index{\#pragma noinduction}
22137
22138 \end_inset
22139
22140  - will stop loop induction optimizations.
22141 \end_layout
22142
22143 \begin_layout Itemize
22144
22145 \series bold
22146 noinvariant
22147 \series default
22148
22149 \begin_inset LatexCommand \index{\#pragma noinvariant}
22150
22151 \end_inset
22152
22153  - will not do loop invariant optimizations.
22154  For more details see Loop Invariants in section
22155 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22156
22157 \end_inset
22158
22159 .
22160 \end_layout
22161
22162 \begin_layout Itemize
22163
22164 \series bold
22165 noiv
22166 \series default
22167
22168 \begin_inset LatexCommand \index{\#pragma noiv}
22169
22170 \end_inset
22171
22172  - Do not generate interrupt
22173 \begin_inset LatexCommand \index{interrupt}
22174
22175 \end_inset
22176
22177  vector table
22178 \begin_inset LatexCommand \index{interrupt vector table}
22179
22180 \end_inset
22181
22182  entries for all ISR functions defined after the pragma.
22183  This is useful in cases where the interrupt vector table must be defined
22184  manually, or when there is a secondary, manually defined interrupt vector
22185  table (e.g.
22186  for the autovector feature of the Cypress EZ-USB FX2).
22187  More elegantly this can be achieved by obmitting the optional interrupt
22188  number after the interrupt keyword, see section 
22189 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22190
22191 \end_inset
22192
22193 \InsetSpace ~
22194 about interrupts.
22195 \end_layout
22196
22197 \begin_layout Itemize
22198
22199 \series bold
22200 nojtbound
22201 \series default
22202
22203 \begin_inset LatexCommand \index{\#pragma nojtbound}
22204
22205 \end_inset
22206
22207  - will not generate code for boundary value checking, when switch statements
22208  are turned into jump-tables (dangerous).
22209  For more details see section 
22210 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22211
22212 \end_inset
22213
22214 .
22215 \end_layout
22216
22217 \begin_layout Itemize
22218
22219 \series bold
22220 noloopreverse
22221 \series default
22222
22223 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22224
22225 \end_inset
22226
22227  - Will not do loop reversal optimization
22228 \end_layout
22229
22230 \begin_layout Itemize
22231
22232 \series bold
22233 nooverlay
22234 \series default
22235
22236 \begin_inset LatexCommand \index{\#pragma nooverlay}
22237
22238 \end_inset
22239
22240  - the compiler will not overlay the parameters and local variables of a
22241  function.
22242 \end_layout
22243
22244 \begin_layout Itemize
22245
22246 \series bold
22247 stackauto
22248 \series default
22249
22250 \begin_inset LatexCommand \index{\#pragma stackauto}
22251
22252 \end_inset
22253
22254 - See option -
22255 \begin_inset ERT
22256 status collapsed
22257
22258 \begin_layout Standard
22259
22260
22261 \backslash
22262 /
22263 \end_layout
22264
22265 \end_inset
22266
22267 -stack-auto
22268 \begin_inset LatexCommand \index{-\/-stack-auto}
22269
22270 \end_inset
22271
22272  and section 
22273 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22274
22275 \end_inset
22276
22277  Parameters and Local Variables.
22278 \end_layout
22279
22280 \begin_layout Itemize
22281
22282 \series bold
22283 opt_code_speed
22284 \series default
22285  
22286 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22287
22288 \end_inset
22289
22290 - The compiler will optimize code generation towards fast code, possibly
22291  at the expense of code size.
22292  Currently this has little effect.
22293 \end_layout
22294
22295 \begin_layout Itemize
22296
22297 \series bold
22298 opt_code_size
22299 \series default
22300  
22301 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22302
22303 \end_inset
22304
22305 - The compiler will optimize code generation towards compact code, possibly
22306  at the expense of code speed.
22307  Currently this has little effect.
22308 \end_layout
22309
22310 \begin_layout Itemize
22311
22312 \series bold
22313 opt_code_balanced
22314 \series default
22315  
22316 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22317
22318 \end_inset
22319
22320 - The compiler will attempt to generate code that is both compact and fast,
22321  as long as meeting one goal is not a detriment to the other (this is the
22322  default).
22323  
22324 \end_layout
22325
22326 \begin_layout Itemize
22327
22328 \series bold
22329 std_sdcc89
22330 \series default
22331  
22332 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22333
22334 \end_inset
22335
22336 - Generally follow the C89 standard, but allow SDCC features that conflict
22337  with the standard (default).
22338 \end_layout
22339
22340 \begin_layout Itemize
22341
22342 \series bold
22343 std_c89
22344 \series default
22345  
22346 \begin_inset LatexCommand \index{\#pragma std\_c89}
22347
22348 \end_inset
22349
22350 - Follow the C89 standard and disable SDCC features that conflict with the
22351  standard.
22352 \end_layout
22353
22354 \begin_layout Itemize
22355
22356 \series bold
22357 std_sdcc99
22358 \series default
22359  
22360 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22361
22362 \end_inset
22363
22364 - Generally follow the C99 standard, but allow SDCC features that conflict
22365  with the standard (incomplete support).
22366 \end_layout
22367
22368 \begin_layout Itemize
22369
22370 \series bold
22371 std_c99
22372 \series default
22373  
22374 \begin_inset LatexCommand \index{\#pragma std\_c99}
22375
22376 \end_inset
22377
22378 - Follow the C99 standard and disable SDCC features that conflict with the
22379  standard (incomplete support).
22380 \end_layout
22381
22382 \begin_layout Itemize
22383
22384 \series bold
22385 codeseg
22386 \series default
22387  <name>
22388 \begin_inset LatexCommand \index{\#pragma codeseg}
22389
22390 \end_inset
22391
22392 - Use this name (max.
22393  8 characters) for the code segment.
22394  See option -
22395 \begin_inset ERT
22396 status collapsed
22397
22398 \begin_layout Standard
22399
22400
22401 \backslash
22402 /
22403 \end_layout
22404
22405 \end_inset
22406
22407 -codeseg.
22408 \end_layout
22409
22410 \begin_layout Itemize
22411
22412 \series bold
22413 constseg
22414 \series default
22415  <name>
22416 \begin_inset LatexCommand \index{\#pragma constseg}
22417
22418 \end_inset
22419
22420 - Use this name (max.
22421  8 characters) for the const segment.
22422  See option -
22423 \begin_inset ERT
22424 status collapsed
22425
22426 \begin_layout Standard
22427
22428
22429 \backslash
22430 /
22431 \end_layout
22432
22433 \end_inset
22434
22435 -constseg.
22436 \end_layout
22437
22438 \begin_layout Standard
22439 The preprocessor SDCPP
22440 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22441
22442 \end_inset
22443
22444  supports the following #pragma directives:
22445 \end_layout
22446
22447 \begin_layout Itemize
22448
22449 \series bold
22450 pedantic_parse_number
22451 \series default
22452
22453 \begin_inset LatexCommand \index{pedantic}
22454
22455 \end_inset
22456
22457
22458 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22459
22460 \end_inset
22461
22462  (+ | -) 
22463 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22464
22465 \end_inset
22466
22467 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22468  properly and the macro LO_B(3) gets expanded.
22469  Default is off.
22470  See also the -
22471 \begin_inset ERT
22472 status collapsed
22473
22474 \begin_layout Standard
22475
22476
22477 \backslash
22478 /
22479 \end_layout
22480
22481 \end_inset
22482
22483 -pedantic-parse-number command line option 
22484 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22485
22486 \end_inset
22487
22488 .
22489  
22490 \newline
22491 Below is an example on how to use this pragma.
22492
22493 \emph on
22494  Note: this functionality is not in conformance with standard!
22495 \end_layout
22496
22497 \begin_layout Verse
22498
22499 \family typewriter
22500 #pragma pedantic_parse_number +
22501 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22502
22503 \end_inset
22504
22505
22506 \newline
22507
22508 \newline
22509 #define LO_B(x) ((x) & 0xff)
22510 \newline
22511
22512 \newline
22513 unsigned char foo(void)
22514 \newline
22515 {
22516 \newline
22517 \InsetSpace ~
22518 \InsetSpace ~
22519 \InsetSpace ~
22520 unsigned char c=0xfe-LO_B(3)
22521 ;
22522 \newline
22523
22524 \newline
22525 \InsetSpace ~
22526 \InsetSpace ~
22527 \InsetSpace ~
22528 return c;
22529 \newline
22530 }
22531 \newline
22532
22533 \end_layout
22534
22535 \begin_layout Itemize
22536
22537 \series bold
22538 preproc_asm
22539 \series default
22540
22541 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22542
22543 \end_inset
22544
22545  (+ | -) - switch _asm _endasm block preprocessing on / off.
22546  Default is on.
22547  You use this prama to define multilines of assembly code.
22548  This will prevent the preprocessor from changing the formating required
22549  by assembly code.
22550  Below is an example on how to use this pragma.
22551 \end_layout
22552
22553 \begin_layout Verse
22554
22555 \family typewriter
22556 #pragma preproc_asm -
22557 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22558
22559 \end_inset
22560
22561
22562 \newline
22563 #define MYDELAY _asm
22564 \newline
22565 \InsetSpace ~
22566 \InsetSpace ~
22567 \InsetSpace ~
22568 nop ;my assembly comment...
22569 \newline
22570 \InsetSpace ~
22571 \InsetSpace ~
22572 \InsetSpace ~
22573 nop
22574 \newline
22575 \InsetSpace ~
22576 \InsetSpace ~
22577 \InsetSpace ~
22578 nop
22579 \newline
22580 _endasm
22581 \newline
22582 #pragma preproc_asm
22583  +
22584 \newline
22585
22586 \newline
22587 void foo (void) 
22588 \newline
22589
22590 \newline
22591 \InsetSpace ~
22592 \InsetSpace ~
22593 \InsetSpace ~
22594  ...
22595  
22596 \newline
22597 \InsetSpace ~
22598 \InsetSpace ~
22599 \InsetSpace ~
22600  MYDELAY;
22601 \newline
22602 \InsetSpace ~
22603 \InsetSpace ~
22604 \InsetSpace ~
22605  ...
22606  
22607 \newline
22608
22609 \newline
22610
22611 \end_layout
22612
22613 \begin_layout Itemize
22614
22615 \series bold
22616 sdcc_hash
22617 \series default
22618
22619 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22620
22621 \end_inset
22622
22623  (+ | -) - Allow "naked" hash in macro definition, for example:
22624 \newline
22625
22626 \family typewriter
22627 #define DIR_LO(x) #(x & 0xff)
22628 \family default
22629
22630 \newline
22631 Default is off.
22632  Below is an example on how to use this pragma.
22633 \end_layout
22634
22635 \begin_layout Verse
22636
22637 \family typewriter
22638 #pragma preproc_asm +
22639 \newline
22640 #pragma sdcc_hash +
22641 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22642
22643 \end_inset
22644
22645
22646 \newline
22647
22648 \newline
22649 #define ROMCALL(x) 
22650 \backslash
22651
22652 \newline
22653 \InsetSpace ~
22654 \InsetSpace ~
22655 \InsetSpace ~
22656 mov R6_B3, #(x & 0xff) 
22657 \backslash
22658
22659 \newline
22660 \InsetSpace ~
22661 \InsetSpace ~
22662 \InsetSpace ~
22663 mov R7_B3, #((x >> 8) & 0xff) 
22664 \backslash
22665
22666 \newline
22667 \InsetSpace ~
22668 \InsetSpace ~
22669 \InsetSpace ~
22670 lcall __romcall
22671 \newline
22672
22673 \newline
22674 ...
22675 \newline
22676 _asm
22677 \newline
22678 ROMCALL(72)
22679 \newline
22680 _endasm;
22681 \newline
22682 ...
22683 \newline
22684
22685 \end_layout
22686
22687 \begin_layout Standard
22688 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22689 ons which might cause the compiler to generate extra stack and/or data space
22690  to store compiler generated temporary variables.
22691  This usually happens in large functions.
22692  Pragma directives should be used as shown in the following example, they
22693  are used to control options and optimizations for a given function.
22694  
22695 \end_layout
22696
22697 \begin_layout Verse
22698
22699 \family typewriter
22700 #pragma save
22701 \begin_inset LatexCommand \index{\#pragma save}
22702
22703 \end_inset
22704
22705  \InsetSpace ~
22706 \InsetSpace ~
22707 \InsetSpace ~
22708 \InsetSpace ~
22709 \InsetSpace ~
22710 \InsetSpace ~
22711 \InsetSpace ~
22712 /* save the current settings */ 
22713 \newline
22714 #pragma nogcse
22715 \begin_inset LatexCommand \index{\#pragma nogcse}
22716
22717 \end_inset
22718
22719  \InsetSpace ~
22720 \InsetSpace ~
22721 \InsetSpace ~
22722 \InsetSpace ~
22723 \InsetSpace ~
22724 /* turnoff global subexpression elimination */ 
22725 \newline
22726 #pragma noinduction
22727 \begin_inset LatexCommand \index{\#pragma noinduction}
22728
22729 \end_inset
22730
22731  /* turn off induction optimizations */ 
22732 \newline
22733 int foo () 
22734 \newline
22735
22736 \newline
22737 \InsetSpace ~
22738  \InsetSpace ~
22739  ...
22740  
22741 \newline
22742 \InsetSpace ~
22743  \InsetSpace ~
22744  /* large code */ 
22745 \newline
22746 \InsetSpace ~
22747  \InsetSpace ~
22748  ...
22749  
22750 \newline
22751
22752 \newline
22753 #pragma restore
22754 \begin_inset LatexCommand \index{\#pragma restore}
22755
22756 \end_inset
22757
22758  /* turn the optimizations back on */
22759 \end_layout
22760
22761 \begin_layout Standard
22762 The compiler will generate a warning message when extra space is allocated.
22763  It is strongly recommended that the save and restore pragmas be used when
22764  changing options for a function.
22765 \newline
22766
22767 \newline
22768
22769 \newline
22770
22771 \end_layout
22772
22773 \begin_layout Section
22774 Defines Created by the Compiler
22775 \end_layout
22776
22777 \begin_layout Standard
22778 The compiler creates the following #defines
22779 \begin_inset LatexCommand \index{\#defines}
22780
22781 \end_inset
22782
22783
22784 \begin_inset LatexCommand \index{Defines created by the compiler}
22785
22786 \end_inset
22787
22788 :
22789 \newline
22790
22791 \end_layout
22792
22793 \begin_layout Standard
22794 \begin_inset Tabular
22795 <lyxtabular version="3" rows="15" columns="2">
22796 <features>
22797 <column alignment="left" valignment="top" leftline="true" width="3in">
22798 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22799 <row topline="true" bottomline="true">
22800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22801 \begin_inset Text
22802
22803 \begin_layout Standard
22804
22805 \series bold
22806 #define
22807 \end_layout
22808
22809 \end_inset
22810 </cell>
22811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22812 \begin_inset Text
22813
22814 \begin_layout Standard
22815
22816 \series bold
22817 Description
22818 \end_layout
22819
22820 \end_inset
22821 </cell>
22822 </row>
22823 <row topline="true">
22824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22825 \begin_inset Text
22826
22827 \begin_layout Standard
22828 SDCC
22829 \begin_inset LatexCommand \index{SDCC}
22830
22831 \end_inset
22832
22833  
22834 \end_layout
22835
22836 \end_inset
22837 </cell>
22838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22839 \begin_inset Text
22840
22841 \begin_layout Standard
22842 Always defined.
22843  Since version 2.5.6 the version number as an int (ex.
22844  256)
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 SDCC_mcs51
22856 \begin_inset LatexCommand \index{SDCC\_mcs51}
22857
22858 \end_inset
22859
22860  or SDCC_ds390
22861 \begin_inset LatexCommand \index{SDCC\_ds390}
22862
22863 \end_inset
22864
22865  or SDCC_z80
22866 \begin_inset LatexCommand \index{SDCC\_z80}
22867
22868 \end_inset
22869
22870 , etc.
22871 \end_layout
22872
22873 \end_inset
22874 </cell>
22875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22876 \begin_inset Text
22877
22878 \begin_layout Standard
22879 depending on the model used (e.g.: -mds390)
22880 \end_layout
22881
22882 \end_inset
22883 </cell>
22884 </row>
22885 <row topline="true">
22886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22887 \begin_inset Text
22888
22889 \begin_layout Standard
22890 __mcs51
22891 \begin_inset LatexCommand \index{\_\_mcs51}
22892
22893 \end_inset
22894
22895 , __ds390
22896 \begin_inset LatexCommand \index{\_\_ds390}
22897
22898 \end_inset
22899
22900 , __hc08
22901 \begin_inset LatexCommand \index{\_\_hc08}
22902
22903 \end_inset
22904
22905 , __z80
22906 \begin_inset LatexCommand \index{\_\_z80}
22907
22908 \end_inset
22909
22910 , etc
22911 \end_layout
22912
22913 \end_inset
22914 </cell>
22915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22916 \begin_inset Text
22917
22918 \begin_layout Standard
22919 depending on the model used (e.g.
22920  -mz80)
22921 \end_layout
22922
22923 \end_inset
22924 </cell>
22925 </row>
22926 <row topline="true">
22927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22928 \begin_inset Text
22929
22930 \begin_layout Standard
22931 SDCC_STACK_AUTO
22932 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22933
22934 \end_inset
22935
22936
22937 \end_layout
22938
22939 \end_inset
22940 </cell>
22941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22942 \begin_inset Text
22943
22944 \begin_layout Standard
22945 when 
22946 \emph on
22947 -
22948 \begin_inset ERT
22949 status collapsed
22950
22951 \begin_layout Standard
22952
22953
22954 \backslash
22955 /
22956 \end_layout
22957
22958 \end_inset
22959
22960 -stack-auto
22961 \emph default
22962  option is used
22963 \end_layout
22964
22965 \end_inset
22966 </cell>
22967 </row>
22968 <row topline="true">
22969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22970 \begin_inset Text
22971
22972 \begin_layout Standard
22973 SDCC_MODEL_SMALL
22974 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22975
22976 \end_inset
22977
22978
22979 \end_layout
22980
22981 \end_inset
22982 </cell>
22983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22984 \begin_inset Text
22985
22986 \begin_layout Standard
22987 when 
22988 \emph on
22989 -
22990 \begin_inset ERT
22991 status collapsed
22992
22993 \begin_layout Standard
22994
22995
22996 \backslash
22997 /
22998 \end_layout
22999
23000 \end_inset
23001
23002 -model-small
23003 \emph default
23004  is used
23005 \end_layout
23006
23007 \end_inset
23008 </cell>
23009 </row>
23010 <row topline="true">
23011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23012 \begin_inset Text
23013
23014 \begin_layout Standard
23015 SDCC_MODEL_MEDIUM
23016 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
23017
23018 \end_inset
23019
23020
23021 \end_layout
23022
23023 \end_inset
23024 </cell>
23025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23026 \begin_inset Text
23027
23028 \begin_layout Standard
23029 when 
23030 \emph on
23031 -
23032 \begin_inset ERT
23033 status collapsed
23034
23035 \begin_layout Standard
23036
23037
23038 \backslash
23039 /
23040 \end_layout
23041
23042 \end_inset
23043
23044 -model-medium
23045 \emph default
23046  is used
23047 \end_layout
23048
23049 \end_inset
23050 </cell>
23051 </row>
23052 <row topline="true">
23053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23054 \begin_inset Text
23055
23056 \begin_layout Standard
23057 SDCC_MODEL_LARGE
23058 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23059
23060 \end_inset
23061
23062
23063 \end_layout
23064
23065 \end_inset
23066 </cell>
23067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23068 \begin_inset Text
23069
23070 \begin_layout Standard
23071 when 
23072 \emph on
23073 -
23074 \begin_inset ERT
23075 status collapsed
23076
23077 \begin_layout Standard
23078
23079
23080 \backslash
23081 /
23082 \end_layout
23083
23084 \end_inset
23085
23086 -model-large
23087 \emph default
23088  is used
23089 \end_layout
23090
23091 \end_inset
23092 </cell>
23093 </row>
23094 <row topline="true">
23095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23096 \begin_inset Text
23097
23098 \begin_layout Standard
23099 SDCC_USE_XSTACK
23100 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23101
23102 \end_inset
23103
23104
23105 \end_layout
23106
23107 \end_inset
23108 </cell>
23109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23110 \begin_inset Text
23111
23112 \begin_layout Standard
23113 when 
23114 \emph on
23115 -
23116 \begin_inset ERT
23117 status collapsed
23118
23119 \begin_layout Standard
23120
23121
23122 \backslash
23123 /
23124 \end_layout
23125
23126 \end_inset
23127
23128 -xstack
23129 \emph default
23130  option is used
23131 \end_layout
23132
23133 \end_inset
23134 </cell>
23135 </row>
23136 <row topline="true">
23137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23138 \begin_inset Text
23139
23140 \begin_layout Standard
23141 SDCC_STACK_TENBIT
23142 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23143
23144 \end_inset
23145
23146  
23147 \end_layout
23148
23149 \end_inset
23150 </cell>
23151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23152 \begin_inset Text
23153
23154 \begin_layout Standard
23155 when 
23156 \emph on
23157 -mds390
23158 \emph default
23159  is used
23160 \end_layout
23161
23162 \end_inset
23163 </cell>
23164 </row>
23165 <row topline="true">
23166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23167 \begin_inset Text
23168
23169 \begin_layout Standard
23170 SDCC_MODEL_FLAT24
23171 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23172
23173 \end_inset
23174
23175
23176 \end_layout
23177
23178 \end_inset
23179 </cell>
23180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23181 \begin_inset Text
23182
23183 \begin_layout Standard
23184 when 
23185 \emph on
23186 -mds390
23187 \emph default
23188  is used
23189 \end_layout
23190
23191 \end_inset
23192 </cell>
23193 </row>
23194 <row topline="true">
23195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23196 \begin_inset Text
23197
23198 \begin_layout Standard
23199 SDCC_REVISION
23200 \begin_inset LatexCommand \index{SDCC\_REVISION}
23201
23202 \end_inset
23203
23204
23205 \end_layout
23206
23207 \end_inset
23208 </cell>
23209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23210 \begin_inset Text
23211
23212 \begin_layout Standard
23213 Always defined.
23214  SDCC svn revision number
23215 \end_layout
23216
23217 \end_inset
23218 </cell>
23219 </row>
23220 <row topline="true">
23221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23222 \begin_inset Text
23223
23224 \begin_layout Standard
23225 SDCC_PARMS_IN_BANK1
23226 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23227
23228 \end_inset
23229
23230
23231 \end_layout
23232
23233 \end_inset
23234 </cell>
23235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23236 \begin_inset Text
23237
23238 \begin_layout Standard
23239 when 
23240 \emph on
23241 -
23242 \begin_inset ERT
23243 status collapsed
23244
23245 \begin_layout Standard
23246
23247
23248 \backslash
23249 /
23250 \end_layout
23251
23252 \end_inset
23253
23254 -parms-in-bank1
23255 \emph default
23256  is used
23257 \end_layout
23258
23259 \end_inset
23260 </cell>
23261 </row>
23262 <row topline="true">
23263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23264 \begin_inset Text
23265
23266 \begin_layout Standard
23267 SDCC_FLOAT_REENT
23268 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23269
23270 \end_inset
23271
23272
23273 \end_layout
23274
23275 \end_inset
23276 </cell>
23277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23278 \begin_inset Text
23279
23280 \begin_layout Standard
23281 when 
23282 \emph on
23283 -
23284 \begin_inset ERT
23285 status collapsed
23286
23287 \begin_layout Standard
23288
23289
23290 \backslash
23291 /
23292 \end_layout
23293
23294 \end_inset
23295
23296 -float-reent
23297 \emph default
23298  is used
23299 \end_layout
23300
23301 \end_inset
23302 </cell>
23303 </row>
23304 <row topline="true" bottomline="true">
23305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23306 \begin_inset Text
23307
23308 \begin_layout Standard
23309 SDCC_INT_LONG_REENT
23310 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23311
23312 \end_inset
23313
23314
23315 \end_layout
23316
23317 \end_inset
23318 </cell>
23319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23320 \begin_inset Text
23321
23322 \begin_layout Standard
23323 when 
23324 \emph on
23325 -
23326 \begin_inset ERT
23327 status collapsed
23328
23329 \begin_layout Standard
23330
23331
23332 \backslash
23333 /
23334 \end_layout
23335
23336 \end_inset
23337
23338 -int-long-reent
23339 \emph default
23340  is used
23341 \end_layout
23342
23343 \end_inset
23344 </cell>
23345 </row>
23346 </lyxtabular>
23347
23348 \end_inset
23349
23350
23351 \end_layout
23352
23353 \begin_layout Chapter
23354 Notes on supported Processors
23355 \end_layout
23356
23357 \begin_layout Section
23358 MCS51 variants
23359 \begin_inset LatexCommand \label{sub:MCS51-variants}
23360
23361 \end_inset
23362
23363
23364 \begin_inset LatexCommand \index{MCS51 variants}
23365
23366 \end_inset
23367
23368
23369 \end_layout
23370
23371 \begin_layout Standard
23372 MCS51 processors are available from many vendors and come in many different
23373  flavours.
23374  While they might differ considerably in respect to Special Function Registers
23375  the core MCS51 is usually not modified or is kept compatible.
23376  
23377 \end_layout
23378
23379 \begin_layout Subsection
23380 pdata access by SFR 
23381 \end_layout
23382
23383 \begin_layout Standard
23384 With the upcome of devices with internal xdata and flash memory devices
23385  using port P2
23386 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23387
23388 \end_inset
23389
23390  as dedicated I/O port is becoming more popular.
23391  Switching the high byte for pdata
23392 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23393
23394 \end_inset
23395
23396  access which was formerly done by port P2 is then achieved by a Special
23397  Function Register
23398 \begin_inset LatexCommand \index{sfr}
23399
23400 \end_inset
23401
23402 .
23403  In well-established MCS51 tradition the address of this 
23404 \emph on
23405 sfr
23406 \emph default
23407  is where the chip designers decided to put it.
23408  Needless to say that they didn't agree on a common name either.
23409  So that the startup code can correctly initialize xdata variables, you
23410  should define an sfr with the name _XPAGE
23411 \family typewriter
23412
23413 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23414
23415 \end_inset
23416
23417
23418 \family default
23419  at the appropriate location if the default, port P2, is not used for this.
23420  Some examples are:
23421 \end_layout
23422
23423 \begin_layout Verse
23424
23425 \family typewriter
23426 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23427  MPAGE */
23428 \end_layout
23429
23430 \begin_layout Verse
23431
23432 \family typewriter
23433 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23434  a.k.a.
23435  MPAGE */
23436 \end_layout
23437
23438 \begin_layout Verse
23439
23440 \family typewriter
23441 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23442  XPAGE */
23443 \end_layout
23444
23445 \begin_layout Verse
23446
23447 \family typewriter
23448 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23449  EMI0CN */
23450 \end_layout
23451
23452 \begin_layout Verse
23453
23454 \family typewriter
23455 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23456  EMI0CN */
23457 \end_layout
23458
23459 \begin_layout Standard
23460 For more exotic implementations further customizations may be needed.
23461  See section 
23462 \begin_inset LatexCommand \ref{sub:Startup-Code}
23463
23464 \end_inset
23465
23466  for other possibilities.
23467 \end_layout
23468
23469 \begin_layout Subsection
23470 Other Features available by SFR
23471 \end_layout
23472
23473 \begin_layout Standard
23474 Some MCS51 variants offer features like Double DPTR
23475 \begin_inset LatexCommand \index{DPTR}
23476
23477 \end_inset
23478
23479 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23480  These are currently not used for the MCS51 port.
23481  If you absolutely need them you can fall back to inline assembly or submit
23482  a patch to SDCC.
23483 \end_layout
23484
23485 \begin_layout Subsection
23486 Bankswitching
23487 \end_layout
23488
23489 \begin_layout Standard
23490 Bankswitching
23491 \begin_inset LatexCommand \index{Bankswitching}
23492
23493 \end_inset
23494
23495  (a.k.a.
23496  code banking
23497 \begin_inset LatexCommand \index{code banking}
23498
23499 \end_inset
23500
23501 ) is a technique to increase the code space above the 64k limit of the 8051.
23502 \end_layout
23503
23504 \begin_layout Subsubsection
23505 Hardware
23506 \end_layout
23507
23508 \begin_layout Standard
23509 \begin_inset Tabular
23510 <lyxtabular version="3" rows="3" columns="4">
23511 <features>
23512 <column alignment="center" valignment="top" width="0">
23513 <column alignment="center" valignment="top" leftline="true" width="0">
23514 <column alignment="center" valignment="top" leftline="true" width="0">
23515 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23516 <row topline="true" bottomline="true">
23517 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23518 \begin_inset Text
23519
23520 \begin_layout Standard
23521 8000-FFFF
23522 \end_layout
23523
23524 \end_inset
23525 </cell>
23526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23527 \begin_inset Text
23528
23529 \begin_layout Standard
23530 bank1
23531 \end_layout
23532
23533 \end_inset
23534 </cell>
23535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23536 \begin_inset Text
23537
23538 \begin_layout Standard
23539 bank2
23540 \end_layout
23541
23542 \end_inset
23543 </cell>
23544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23545 \begin_inset Text
23546
23547 \begin_layout Standard
23548 bank3
23549 \end_layout
23550
23551 \end_inset
23552 </cell>
23553 </row>
23554 <row topline="true" bottomline="true">
23555 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23556 \begin_inset Text
23557
23558 \begin_layout Standard
23559 0000-7FFF
23560 \end_layout
23561
23562 \end_inset
23563 </cell>
23564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23565 \begin_inset Text
23566
23567 \begin_layout Standard
23568 common
23569 \end_layout
23570
23571 \end_inset
23572 </cell>
23573 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23574 \begin_inset Text
23575
23576 \begin_layout Standard
23577
23578 \end_layout
23579
23580 \end_inset
23581 </cell>
23582 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23583 \begin_inset Text
23584
23585 \begin_layout Standard
23586
23587 \end_layout
23588
23589 \end_inset
23590 </cell>
23591 </row>
23592 <row>
23593 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23594 \begin_inset Text
23595
23596 \begin_layout Standard
23597 SiLabs C8051F120 example
23598 \end_layout
23599
23600 \end_inset
23601 </cell>
23602 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23603 \begin_inset Text
23604
23605 \begin_layout Standard
23606
23607 \end_layout
23608
23609 \end_inset
23610 </cell>
23611 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23612 \begin_inset Text
23613
23614 \begin_layout Standard
23615
23616 \end_layout
23617
23618 \end_inset
23619 </cell>
23620 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23621 \begin_inset Text
23622
23623 \begin_layout Standard
23624
23625 \end_layout
23626
23627 \end_inset
23628 </cell>
23629 </row>
23630 </lyxtabular>
23631
23632 \end_inset
23633
23634
23635 \newline
23636
23637 \newline
23638 Usually the hardware uses some sfr (an output port or an internal sfr) to
23639  select a bank and put it in the banked area of the memory map.
23640  The selected bank usually becomes active immediately upon assignment to
23641  this sfr and when running inside a bank it will switch out this code it
23642  is currently running.
23643  Therefor you cannot jump or call directly from one bank to another and
23644  need to use a so-called trampoline in the common area.
23645  For SDCC an example trampoline is in crtbank.asm and you may need to change
23646  it to your 8051 derivative or schematic.
23647  The presented code is written for the C8051F120.
23648 \newline
23649
23650 \newline
23651 When calling a banked function
23652  SDCC will put the LSB of the functions address in register R0, the MSB
23653  in R1 and the bank in R2 and then call this trampoline 
23654 \emph on
23655 __sdcc_banked_call
23656 \emph default
23657 .
23658  The current selected bank is saved on the stack, the new bank is selected
23659  and an indirect jump is made.
23660  When the banked function returns it jumps to 
23661 \emph on
23662 __sdcc_banked_ret
23663 \emph default
23664  which restores the previous bank and returns to the caller.
23665 \end_layout
23666
23667 \begin_layout Subsubsection
23668 Software
23669 \end_layout
23670
23671 \begin_layout Standard
23672 When writing banked software using SDCC you need to use some special keywords
23673  and options.
23674  You also need to take over a bit of work from the linker.
23675 \newline
23676
23677 \newline
23678 To create a function
23679  that can be called from another bank it requires the keyword 
23680 \emph on
23681 banked
23682 \emph default
23683
23684 \begin_inset LatexCommand \index{banked}
23685
23686 \end_inset
23687
23688 .
23689  The caller must see this in the prototype of the callee and the callee
23690  needs it for a proper return.
23691  Called functions within the same bank as the caller do not need the 
23692 \emph on
23693 banked
23694 \emph default
23695  keyword nor do functions in the common area.
23696  Beware: SDCC does not know or check if functions are in the same bank.
23697  This is your responsibility!
23698 \newline
23699
23700 \newline
23701 Normally all functions you write end up in
23702  the segment CSEG.
23703  If you want a function explicitly to reside in the common area put it in
23704  segment HOME.
23705  This applies for instance to interrupt service routines as they should
23706  not be banked.
23707 \end_layout
23708
23709 \begin_layout Standard
23710 Functions that need to be in a switched bank must be put in a named segment.
23711  The name can be mostly anything upto eight characters (e.g.
23712  BANK1).
23713  To do this you either use -
23714 \begin_inset ERT
23715 status collapsed
23716
23717 \begin_layout Standard
23718
23719
23720 \backslash
23721 /
23722 \end_layout
23723
23724 \end_inset
23725
23726 -codeseg BANK1 (See 
23727 \begin_inset LatexCommand \ref{lyx:-codeseg}
23728
23729 \end_inset
23730
23731 ) on the command line when compiling or #pragma codeseg BANK1 (See 
23732 \begin_inset LatexCommand \ref{sec:Pragmas}
23733
23734 \end_inset
23735
23736 ) at the top of the C source file.
23737  The segment name always applies to the whole source file and generated
23738  object so functions for different banks need to be defined in different
23739  source files.
23740 \newline
23741
23742 \newline
23743 When linking your objects you need to tell the linker where
23744  to put your segments.
23745  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23746 00 (See 
23747 \begin_inset LatexCommand \ref{lyx:-Wl option}
23748
23749 \end_inset
23750
23751 ).
23752  This sets the virtual start address of this segment.
23753  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23754  The linker will not check for overflows, again this is your responsibility.
23755 \end_layout
23756
23757 \begin_layout Standard
23758 \begin_inset VSpace bigskip
23759 \end_inset
23760
23761
23762 \end_layout
23763
23764 \begin_layout Section
23765 DS400 port
23766 \end_layout
23767
23768 \begin_layout Standard
23769 The DS80C400
23770 \begin_inset LatexCommand \index{DS80C400}
23771
23772 \end_inset
23773
23774
23775 \begin_inset LatexCommand \index{DS400}
23776
23777 \end_inset
23778
23779  microcontroller has a rich set of peripherals.
23780  In its built-in ROM library it includes functions to access some of the
23781  features, among them is a TCP stack with IP4 and IP6 support.
23782  Library headers (currently in beta status) and other files are provided
23783  at 
23784 \size footnotesize
23785
23786 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23787
23788 \end_inset
23789
23790 .
23791  
23792 \begin_inset VSpace bigskip
23793 \end_inset
23794
23795
23796 \end_layout
23797
23798 \begin_layout Section
23799 The Z80 and gbz80 port
23800 \end_layout
23801
23802 \begin_layout Standard
23803 SDCC can target both the Zilog Z80
23804 \begin_inset LatexCommand \index{Z80}
23805
23806 \end_inset
23807
23808  and the Nintendo Gameboy's Z80-like gbz80
23809 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23810
23811 \end_inset
23812
23813 .
23814  The Z80 port is passed through the same 
23815 \emph on
23816 regressions tests
23817 \begin_inset LatexCommand \index{Regression test}
23818
23819 \end_inset
23820
23821
23822 \emph default
23823  (see section 
23824 \begin_inset LatexCommand \ref{sec:Quality-control}
23825
23826 \end_inset
23827
23828 ) as the MCS51 and DS390 ports, so floating point support, support for long
23829  variables and bitfield support is fine.
23830  See mailing lists and forums about interrupt routines.
23831 \end_layout
23832
23833 \begin_layout Standard
23834 As always, the code is the authoritative reference - see z80/ralloc.c and
23835  z80/gen.c.
23836  The stack
23837 \begin_inset LatexCommand \index{Z80!stack}
23838
23839 \end_inset
23840
23841  frame is similar to that generated by the IAR Z80 compiler.
23842  IX is used as the base pointer, HL and IY are used as a temporary registers,
23843  and BC and DE are available for holding variables.
23844  Return values
23845 \begin_inset LatexCommand \index{Z80!return value}
23846
23847 \end_inset
23848
23849  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23850  bytes).
23851  The gbz80 port use the same set of registers for the return values, but
23852  in a different order of significance: E (one byte), DE (two bytes), or
23853  HLDE (four bytes).
23854 \begin_inset VSpace bigskip
23855 \end_inset
23856
23857
23858 \end_layout
23859
23860 \begin_layout Section
23861 The HC08 port
23862 \end_layout
23863
23864 \begin_layout Standard
23865 The port to the Freescale/Motorola HC08
23866 \begin_inset LatexCommand \index{HC08}
23867
23868 \end_inset
23869
23870  family has been added in October 2003, and is still undergoing some basic
23871  development.
23872  The code generator is complete, but the register allocation is still quite
23873  unoptimized.
23874  Some of the SDCC's standard C library functions have embedded non-HC08
23875  inline assembly and so are not yet usable.
23876 \end_layout
23877
23878 \begin_layout Standard
23879 The HC08 port passes the regression test suite (see section 
23880 \begin_inset LatexCommand \ref{sec:Quality-control}
23881
23882 \end_inset
23883
23884 ).
23885 \begin_inset VSpace bigskip
23886 \end_inset
23887
23888
23889 \end_layout
23890
23891 \begin_layout Section
23892 The PIC14
23893 \begin_inset LatexCommand \index{PIC14}
23894
23895 \end_inset
23896
23897  port
23898 \end_layout
23899
23900 \begin_layout Standard
23901 The PIC14 port adds support for Microchip
23902 \begin_inset LatexCommand \index{Microchip}
23903
23904 \end_inset
23905
23906
23907 \begin_inset Formula $^{\text{TM}}$
23908 \end_inset
23909
23910  PIC
23911 \begin_inset LatexCommand \index{PIC14}
23912
23913 \end_inset
23914
23915
23916 \begin_inset Formula $^{\text{TM}}$
23917 \end_inset
23918
23919  MCUs with 14 bit wide instructions.
23920  This port is not yet mature and still lacks many features.
23921  However, it can work for simple code.
23922 \end_layout
23923
23924 \begin_layout Standard
23925 Currently supported devices include:
23926 \end_layout
23927
23928 \begin_layout Standard
23929 12F: 629, 635, 675, 683
23930 \end_layout
23931
23932 \begin_layout Standard
23933 16C: 432, 433
23934 \end_layout
23935
23936 \begin_layout Standard
23937 16C: 554, 557, 558
23938 \end_layout
23939
23940 \begin_layout Standard
23941 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23942 \end_layout
23943
23944 \begin_layout Standard
23945 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23946  781, 782
23947 \end_layout
23948
23949 \begin_layout Standard
23950 16C: 925, 926
23951 \end_layout
23952
23953 \begin_layout Standard
23954 16CR: 620a, 73, 74, 76, 77
23955 \end_layout
23956
23957 \begin_layout Standard
23958 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
23959  687, 688, 689, 690
23960 \end_layout
23961
23962 \begin_layout Standard
23963 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
23964 \end_layout
23965
23966 \begin_layout Standard
23967 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23968  877, 877a, 88, 886, 887
23969 \end_layout
23970
23971 \begin_layout Standard
23972 16F: 913, 914, 916, 917, 946
23973 \end_layout
23974
23975 \begin_layout Standard
23976 26HV: 626, 785
23977 \end_layout
23978
23979 \begin_layout Standard
23980 An up-to-date list of currently supported devices can be obtained via 
23981 \family typewriter
23982 sdcc -mpic14 -phelp foo.c
23983 \family default
23984  (foo.c must exist...).
23985 \end_layout
23986
23987 \begin_layout Subsection
23988 PIC Code Pages
23989 \begin_inset LatexCommand \index{code page (pic14)}
23990
23991 \end_inset
23992
23993  and Memory Banks
23994 \begin_inset LatexCommand \index{Memory bank (pic14)}
23995
23996 \end_inset
23997
23998
23999 \end_layout
24000
24001 \begin_layout Standard
24002 The linker organizes allocation for the code page and RAM banks.
24003  It does not have intimate knowledge of the code flow.
24004  It will put all the code section of a single .asm file into a single code
24005  page.
24006  In order to make use of multiple code pages, separate asm files must be
24007  used.
24008  The compiler assigns all 
24009 \emph on
24010 static
24011 \emph default
24012  functions of a single .c file into the same code page.
24013 \newline
24014
24015 \newline
24016 To get the best results,
24017  follow these guidelines:
24018 \end_layout
24019
24020 \begin_layout Enumerate
24021 Make local functions static, as non static functions require code page selection
24022  overhead.
24023 \newline
24024 Due to the way sdcc handles functions, place called functions prior
24025  to calling functions in the file wherever possible: Otherwise sdcc will
24026  insert unneccessary pagesel directives around the call, believing that
24027  the called function is externally defined.
24028 \end_layout
24029
24030 \begin_layout Enumerate
24031 For devices that have multiple code pages it is more efficient to use the
24032  same number of files as pages: Use up to 4 separate .c files for the 16F877,
24033  but only 2 files for the 16F874.
24034  This way the linker can put the code for each file into different code
24035  pages and there will be less page selection overhead.
24036 \end_layout
24037
24038 \begin_layout Enumerate
24039 And as for any 8 bit micro (especially for PIC14 as they have a very simple
24040  instruction set), use `unsigned char' wherever possible instead of `int'.
24041 \end_layout
24042
24043 \begin_layout Subsection
24044 Adding New Devices to the Port 
24045 \end_layout
24046
24047 \begin_layout Standard
24048 Adding support for a new 14
24049 \begin_inset ERT
24050 status open
24051
24052 \begin_layout Standard
24053
24054
24055 \backslash
24056 ,
24057 \end_layout
24058
24059 \end_inset
24060
24061 bit PIC MCU requires the following steps:
24062 \end_layout
24063
24064 \begin_layout Enumerate
24065 Create a new device description.
24066 \newline
24067 Each device is described in two files: pic16f*.h
24068  and pic16f*.c.
24069  These files primarily define SFRs, structs to access their bits, and symbolic
24070  configuration options.
24071  Both files can be generated from gputils' .inc files using the perl script
24072  
24073 \family typewriter
24074 support/scripts/inc2h.pl
24075 \family default
24076 .
24077  This file also contains further instructions on how to proceed.
24078 \end_layout
24079
24080 \begin_layout Enumerate
24081 Copy the .h file into SDCC's include path and either add the .c file to your
24082  project or copy it to 
24083 \family typewriter
24084 device/lib/pic/libdev
24085 \family default
24086 .
24087  Afterwards, rebuild and install the libraries.
24088 \end_layout
24089
24090 \begin_layout Enumerate
24091 Edit pic14devices.txt in SDCC's include path (
24092 \family typewriter
24093 device/include/pic/
24094 \family default
24095  in the source tree or 
24096 \family typewriter
24097 /usr/local/share/sdcc/include/pic
24098 \family default
24099  after installation).
24100 \newline
24101 You need to add a device specification here to make
24102  the memory layout (code banks, RAM, aliased memory regions, ...) known to
24103  the compiler.
24104  Probably you can copy and modify an existing entry.
24105  The file format is documented at the top of the file.
24106 \end_layout
24107
24108 \begin_layout Subsection
24109 Interrupt Code
24110 \end_layout
24111
24112 \begin_layout Standard
24113 For the interrupt function, use the keyword `__interrupt'
24114 \begin_inset LatexCommand \index{PIC14!interrupt}
24115
24116 \end_inset
24117
24118  with level number of 0 (PIC14 only has 1 interrupt so this number is only
24119  there to avoid a syntax error - it ought to be fixed).
24120  E.g.:
24121 \end_layout
24122
24123 \begin_layout Verse
24124
24125 \family typewriter
24126 void Intr(void) __interrupt 0
24127 \newline
24128 {
24129 \newline
24130 \InsetSpace ~
24131 \InsetSpace ~
24132 T0IF = 0; /* Clear timer interrupt */
24133 \newline
24134 }
24135 \end_layout
24136
24137 \begin_layout Subsection
24138 Linking and Assembling
24139 \end_layout
24140
24141 \begin_layout Standard
24142 For assembling you can use either GPUTILS'
24143 \begin_inset LatexCommand \index{gputils (pic tools)}
24144
24145 \end_inset
24146
24147  gpasm.exe or MPLAB's mpasmwin.exe.
24148  GPUTILS are available from 
24149 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24150
24151 \end_inset
24152
24153 .
24154  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24155  If you use MPLAB and an interrupt function then the linker script file
24156  vectors section will need to be enlarged to link with mplink.
24157 \newline
24158
24159 \newline
24160 Here is a 
24161 \family typewriter
24162 Makefile
24163 \family default
24164  using GPUTILS:
24165 \end_layout
24166
24167 \begin_layout Verse
24168
24169 \family typewriter
24170 .c.o:
24171 \newline
24172 \InsetSpace ~
24173 \InsetSpace ~
24174 \InsetSpace ~
24175 \InsetSpace ~
24176 \InsetSpace ~
24177 \InsetSpace ~
24178 \InsetSpace ~
24179 \InsetSpace ~
24180 sdcc -V -mpic14 -p16f877 -c $< 
24181 \newline
24182
24183 \newline
24184 $(PRJ).hex: $(OBJS) 
24185 \newline
24186 \InsetSpace ~
24187 \InsetSpace ~
24188 \InsetSpace ~
24189 \InsetSpace ~
24190 \InsetSpace ~
24191 \InsetSpace ~
24192 \InsetSpace ~
24193 \InsetSpace ~
24194 gplink -m -s $(PRJ).lkr
24195  -o $(PRJ).hex $(OBJS) libsdcc.lib
24196 \end_layout
24197
24198 \begin_layout Standard
24199 Here is a 
24200 \family typewriter
24201 Makefile
24202 \family default
24203  using MPLAB:
24204 \end_layout
24205
24206 \begin_layout Verse
24207
24208 \family typewriter
24209 .c.o: 
24210 \newline
24211 \InsetSpace ~
24212 \InsetSpace ~
24213 \InsetSpace ~
24214 \InsetSpace ~
24215 \InsetSpace ~
24216 \InsetSpace ~
24217 \InsetSpace ~
24218 \InsetSpace ~
24219 sdcc -S -V -mpic14 -p16f877 $< 
24220 \newline
24221 \InsetSpace ~
24222 \InsetSpace ~
24223 \InsetSpace ~
24224 \InsetSpace ~
24225 \InsetSpace ~
24226 \InsetSpace ~
24227 \InsetSpace ~
24228 \InsetSpace ~
24229 mpasmwin /q /o $*.asm
24230 \newline
24231
24232 \newline
24233 $(PRJ).hex: $(OBJS)
24234  
24235 \newline
24236 \InsetSpace ~
24237 \InsetSpace ~
24238 \InsetSpace ~
24239 \InsetSpace ~
24240 \InsetSpace ~
24241 \InsetSpace ~
24242 \InsetSpace ~
24243 \InsetSpace ~
24244 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24245 \end_layout
24246
24247 \begin_layout Standard
24248 Please note that indentations within a
24249 \family typewriter
24250  Makefile
24251 \family default
24252  have to be done with a tabulator character.
24253 \end_layout
24254
24255 \begin_layout Subsection
24256 Command-Line Options
24257 \end_layout
24258
24259 \begin_layout Standard
24260 Besides the switches common to all SDCC backends, the PIC14 port accepts
24261  the following options (for an updated list see sdcc -
24262 \begin_inset ERT
24263 status collapsed
24264
24265 \begin_layout Standard
24266
24267
24268 \backslash
24269 /
24270 \end_layout
24271
24272 \end_inset
24273
24274 -help):
24275 \end_layout
24276
24277 \begin_layout Description
24278 -
24279 \begin_inset ERT
24280 status collapsed
24281
24282 \begin_layout Standard
24283
24284
24285 \backslash
24286 /
24287 \end_layout
24288
24289 \end_inset
24290
24291 -debug-xtra
24292 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24293
24294 \end_inset
24295
24296  emit debug info in assembly output
24297 \end_layout
24298
24299 \begin_layout Description
24300 -
24301 \begin_inset ERT
24302 status collapsed
24303
24304 \begin_layout Standard
24305
24306
24307 \backslash
24308 /
24309 \end_layout
24310
24311 \end_inset
24312
24313 -no-pcode-opt
24314 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24315
24316 \end_inset
24317
24318  disable (slightly faulty) optimization on pCode
24319 \end_layout
24320
24321 \begin_layout Description
24322 -
24323 \begin_inset ERT
24324 status collapsed
24325
24326 \begin_layout Standard
24327
24328
24329 \backslash
24330 /
24331 \end_layout
24332
24333 \end_inset
24334
24335 -stack-loc
24336 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24337
24338 \end_inset
24339
24340  sets the lowest address of the argument passing stack (defaults to a suitably
24341  large shared databank to reduce BANKSEL overhead)
24342 \end_layout
24343
24344 \begin_layout Description
24345 -
24346 \begin_inset ERT
24347 status collapsed
24348
24349 \begin_layout Standard
24350
24351
24352 \backslash
24353 /
24354 \end_layout
24355
24356 \end_inset
24357
24358 -stack-size
24359 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24360
24361 \end_inset
24362
24363  sets the size if the argument passing stack (default: 16, minimum: 4)
24364 \end_layout
24365
24366 \begin_layout Subsection
24367 Environment Variables
24368 \end_layout
24369
24370 \begin_layout Standard
24371 The PIC14 port recognizes the following environment variables:
24372 \end_layout
24373
24374 \begin_layout Description
24375 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24376  register (the ones called r0xNNNN) in a section of its own.
24377  By default (if this variable is unset), sdcc tries to cluster registers
24378  in sections in order to reduce the BANKSEL overhead when accessing them.
24379 \end_layout
24380
24381 \begin_layout Subsection
24382 The Library
24383 \end_layout
24384
24385 \begin_layout Standard
24386 The PIC14 library currently only contains support routines required by the
24387  compiler to implement multiplication, division, and floating point support.
24388  No libc-like replacement is available at the moment, though many of the
24389  common sdcc library sources (in 
24390 \family typewriter
24391 device/lib
24392 \family default
24393 ) should also compile with the PIC14 port.
24394 \end_layout
24395
24396 \begin_layout Subsubsection
24397 error: missing definition for symbol ``__gptrget1''
24398 \end_layout
24399
24400 \begin_layout Standard
24401 The PIC14 port uses library routines to provide more complex operations
24402  like multiplication, division/modulus and (generic) pointer dereferencing.
24403  In order to add these routines to your project, you must link with PIC14's
24404  
24405 \family typewriter
24406 libsdcc.lib
24407 \family default
24408 .
24409  For single source file projects this is done automatically, more complex
24410  projects must add 
24411 \family typewriter
24412 libsdcc.lib
24413 \family default
24414  to the linker's arguments.
24415  Make sure you also add an include path for the library (using the -I switch
24416  to the linker)!
24417 \end_layout
24418
24419 \begin_layout Subsubsection
24420 Processor mismatch in file ``XXX''.
24421 \end_layout
24422
24423 \begin_layout Standard
24424 This warning can usually be ignored due to the very good compatibility amongst
24425  14
24426 \begin_inset ERT
24427 status open
24428
24429 \begin_layout Standard
24430
24431
24432 \backslash
24433 ,
24434 \end_layout
24435
24436 \end_inset
24437
24438 bit PIC
24439 \begin_inset LatexCommand \index{PIC14}
24440
24441 \end_inset
24442
24443  devices.
24444 \end_layout
24445
24446 \begin_layout Standard
24447 You might also consider recompiling the library for your specific device
24448  by changing the ARCH=p16f877 (default target) entry in 
24449 \family typewriter
24450 device/lib/pic/Makefile.in
24451 \family default
24452  and 
24453 \family typewriter
24454 device/lib/pic/Makefile
24455 \family default
24456  to reflect your device.
24457  This might even improve performance for smaller devices as unneccesary
24458  BANKSELs might be removed.
24459 \end_layout
24460
24461 \begin_layout Subsection
24462 Known Bugs
24463 \end_layout
24464
24465 \begin_layout Subsubsection
24466 Function arguments
24467 \end_layout
24468
24469 \begin_layout Standard
24470 Functions with variable argument lists (like printf) are not yet supported.
24471  Similarly, taking the address of the first argument passed into a function
24472  does not work: It is currently passed in WREG and has no address...
24473 \end_layout
24474
24475 \begin_layout Subsubsection
24476 Regression tests fail
24477 \end_layout
24478
24479 \begin_layout Standard
24480 Though the small subset of regression tests in src/regression passes, SDCC
24481  regression test suite does not, indicating that there are still major bugs
24482  in the port.
24483  However, many smaller projects have successfully used SDCC in the past...
24484 \end_layout
24485
24486 \begin_layout Standard
24487
24488 \size footnotesize
24489
24490 \newpage
24491
24492 \end_layout
24493
24494 \begin_layout Section
24495 The PIC16
24496 \begin_inset LatexCommand \index{PIC16}
24497
24498 \end_inset
24499
24500  port
24501 \end_layout
24502
24503 \begin_layout Standard
24504 The PIC16 port adds support for Microchip
24505 \begin_inset LatexCommand \index{Microchip}
24506
24507 \end_inset
24508
24509
24510 \begin_inset Formula $^{\text{TM}}$
24511 \end_inset
24512
24513  PIC
24514 \begin_inset LatexCommand \index{PIC}
24515
24516 \end_inset
24517
24518
24519 \begin_inset Formula $^{\text{TM}}$
24520 \end_inset
24521
24522  MCUs with 16 bit wide instructions.
24523  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24524 ; devices supported by the port include:
24525 \end_layout
24526
24527 \begin_layout Standard
24528 18F: 242, 248, 252, 258, 442, 448, 452, 458
24529 \end_layout
24530
24531 \begin_layout Standard
24532 18F: 1220, 1320
24533 \end_layout
24534
24535 \begin_layout Standard
24536 18F: 2220, 2221, 2320, 2321, 2331, 2420, 2423, 2431, 2455, 2480, 24j10
24537 \end_layout
24538
24539 \begin_layout Standard
24540 18F: 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2620, 2680, 2682, 2685
24541 \end_layout
24542
24543 \begin_layout Standard
24544 18F: 4220, 4221, 4320, 4321, 4331, 4420, 4423, 4431, 4455, 4480, 44j10
24545 \end_layout
24546
24547 \begin_layout Standard
24548 18F: 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4620, 4680, 4682, 4685
24549 \end_layout
24550
24551 \begin_layout Standard
24552 18F: 6520, 6585, 6620, 6680, 6720
24553 \end_layout
24554
24555 \begin_layout Standard
24556 18F: 8520, 8585, 8620, 8680, 8720
24557 \end_layout
24558
24559 \begin_layout Standard
24560 A list of supported devices is also available via '
24561 \family typewriter
24562 sdcc -mpic16 -plist
24563 \family default
24564 '.
24565 \end_layout
24566
24567 \begin_layout Subsection
24568 Global Options
24569 \end_layout
24570
24571 \begin_layout Standard
24572 PIC16 port supports the standard command line arguments as supposed, with
24573  the exception of certain cases that will be mentioned in the following
24574  list:
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 -callee-saves
24592 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24593
24594 \end_inset
24595
24596  See -
24597 \begin_inset ERT
24598 status collapsed
24599
24600 \begin_layout Standard
24601
24602
24603 \backslash
24604 /
24605 \end_layout
24606
24607 \end_inset
24608
24609 -all-callee-saves
24610 \end_layout
24611
24612 \begin_layout Description
24613 -
24614 \begin_inset ERT
24615 status collapsed
24616
24617 \begin_layout Standard
24618
24619
24620 \backslash
24621 /
24622 \end_layout
24623
24624 \end_inset
24625
24626 -fommit-frame-pointer
24627 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24628
24629 \end_inset
24630
24631  Frame pointer will be omitted when the function uses no local variables.
24632 \end_layout
24633
24634 \begin_layout Subsection
24635 Port Specific Options
24636 \begin_inset LatexCommand \index{Options PIC16}
24637
24638 \end_inset
24639
24640
24641 \end_layout
24642
24643 \begin_layout Standard
24644 The port specific options appear after the global options in the sdcc -
24645 \begin_inset ERT
24646 status collapsed
24647
24648 \begin_layout Standard
24649
24650
24651 \backslash
24652 /
24653 \end_layout
24654
24655 \end_inset
24656
24657 -help output.
24658 \end_layout
24659
24660 \begin_layout Subsubsection
24661 Code Generation Options
24662 \end_layout
24663
24664 \begin_layout Standard
24665 These options influence the generated assembler code.
24666 \end_layout
24667
24668 \begin_layout Description
24669 -
24670 \begin_inset ERT
24671 status collapsed
24672
24673 \begin_layout Standard
24674
24675
24676 \backslash
24677 /
24678 \end_layout
24679
24680 \end_inset
24681
24682 -pstack-model=[model] Used in conjuction with the command above.
24683  Defines the stack model to be used, valid stack models are:
24684 \end_layout
24685
24686 \begin_deeper
24687 \begin_layout List
24688 \labelwidthstring 00.00.0000
24689
24690 \emph on
24691 small
24692 \emph default
24693  Selects small stack model.
24694  8 bit stack and frame pointers.
24695  Supports 256 bytes stack size.
24696 \end_layout
24697
24698 \begin_layout List
24699 \labelwidthstring 00.00.0000
24700
24701 \emph on
24702 large
24703 \emph default
24704  Selects large stack model.
24705  16 bit stack and frame pointers.
24706  Supports 65536 bytes stack size.
24707 \end_layout
24708
24709 \end_deeper
24710 \begin_layout Description
24711 -
24712 \begin_inset ERT
24713 status collapsed
24714
24715 \begin_layout Standard
24716
24717
24718 \backslash
24719 /
24720 \end_layout
24721
24722 \end_inset
24723
24724 -pno-banksel Do not generate BANKSEL assembler directives.
24725 \end_layout
24726
24727 \begin_layout Description
24728 -
24729 \begin_inset ERT
24730 status collapsed
24731
24732 \begin_layout Standard
24733
24734
24735 \backslash
24736 /
24737 \end_layout
24738
24739 \end_inset
24740
24741 -extended Enable extended instruction set/literal offset addressing mode.
24742  Use with care!
24743 \end_layout
24744
24745 \begin_layout Subsubsection
24746 Optimization Options
24747 \end_layout
24748
24749 \begin_layout Description
24750 -
24751 \begin_inset ERT
24752 status collapsed
24753
24754 \begin_layout Standard
24755
24756
24757 \backslash
24758 /
24759 \end_layout
24760
24761 \end_inset
24762
24763 -obanksel=n Set optimization level for inserting BANKSELs.
24764 \newline
24765
24766 \end_layout
24767
24768 \begin_deeper
24769 \begin_layout List
24770 \labelwidthstring 00.00.0000
24771 0 no optimization
24772 \end_layout
24773
24774 \begin_layout List
24775 \labelwidthstring 00.00.0000
24776 1 checks previous used register and if it is the same then does not emit
24777  BANKSEL, accounts only for labels.
24778 \end_layout
24779
24780 \begin_layout List
24781 \labelwidthstring 00.00.0000
24782 2 tries to check the location of (even different) symbols and removes BANKSELs
24783  if they are in the same bank.
24784  
24785 \newline
24786
24787 \emph on
24788 Important: There might be problems if the linker script has data sections
24789  across bank borders!
24790 \end_layout
24791
24792 \end_deeper
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 -denable-peeps Force the usage of peepholes.
24808  Use with care.
24809 \end_layout
24810
24811 \begin_layout Description
24812 -
24813 \begin_inset ERT
24814 status collapsed
24815
24816 \begin_layout Standard
24817
24818
24819 \backslash
24820 /
24821 \end_layout
24822
24823 \end_inset
24824
24825 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
24826 \end_layout
24827
24828 \begin_layout Description
24829 -
24830 \begin_inset ERT
24831 status collapsed
24832
24833 \begin_layout Standard
24834
24835
24836 \backslash
24837 /
24838 \end_layout
24839
24840 \end_inset
24841
24842 -optimize-cmp Try to optimize some compares.
24843 \end_layout
24844
24845 \begin_layout Description
24846 -
24847 \begin_inset ERT
24848 status collapsed
24849
24850 \begin_layout Standard
24851
24852
24853 \backslash
24854 /
24855 \end_layout
24856
24857 \end_inset
24858
24859 -optimize-df Analyze the dataflow of the generated code and improve it.
24860 \end_layout
24861
24862 \begin_layout Subsubsection
24863 Assembling Options
24864 \end_layout
24865
24866 \begin_layout Description
24867 -
24868 \begin_inset ERT
24869 status collapsed
24870
24871 \begin_layout Standard
24872
24873
24874 \backslash
24875 /
24876 \end_layout
24877
24878 \end_inset
24879
24880 -asm= Sets the full path and name of an external assembler to call.
24881 \end_layout
24882
24883 \begin_layout Description
24884 -
24885 \begin_inset ERT
24886 status collapsed
24887
24888 \begin_layout Standard
24889
24890
24891 \backslash
24892 /
24893 \end_layout
24894
24895 \end_inset
24896
24897 -mplab-comp MPLAB
24898 \begin_inset LatexCommand \index{PIC16!MPLAB}
24899
24900 \end_inset
24901
24902  compatibility option.
24903  Currently only suppresses special gpasm directives.
24904 \end_layout
24905
24906 \begin_layout Subsubsection
24907 Linking Options
24908 \end_layout
24909
24910 \begin_layout Description
24911 -
24912 \begin_inset ERT
24913 status collapsed
24914
24915 \begin_layout Standard
24916
24917
24918 \backslash
24919 /
24920 \end_layout
24921
24922 \end_inset
24923
24924 -link= Sets the full path and name of an external linker to call.
24925 \end_layout
24926
24927 \begin_layout Description
24928 -
24929 \begin_inset ERT
24930 status collapsed
24931
24932 \begin_layout Standard
24933
24934
24935 \backslash
24936 /
24937 \end_layout
24938
24939 \end_inset
24940
24941 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24942  unitialized data variables with [kword].
24943  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24944 \end_layout
24945
24946 \begin_layout Description
24947 -
24948 \begin_inset ERT
24949 status collapsed
24950
24951 \begin_layout Standard
24952
24953
24954 \backslash
24955 /
24956 \end_layout
24957
24958 \end_inset
24959
24960 -ivt-loc=n Place the interrupt vector table at address 
24961 \emph on
24962 n
24963 \emph default
24964 .
24965  Useful for bootloaders.
24966 \end_layout
24967
24968 \begin_layout Description
24969 -
24970 \begin_inset ERT
24971 status collapsed
24972
24973 \begin_layout Standard
24974
24975
24976 \backslash
24977 /
24978 \end_layout
24979
24980 \end_inset
24981
24982 -nodefaultlibs Do not link default libraries when linking.
24983 \end_layout
24984
24985 \begin_layout Description
24986 -
24987 \begin_inset ERT
24988 status collapsed
24989
24990 \begin_layout Standard
24991
24992
24993 \backslash
24994 /
24995 \end_layout
24996
24997 \end_inset
24998
24999 -use-crt= Use a custom run-time module instead of the defaults.
25000 \end_layout
25001
25002 \begin_layout Description
25003 -
25004 \begin_inset ERT
25005 status collapsed
25006
25007 \begin_layout Standard
25008
25009
25010 \backslash
25011 /
25012 \end_layout
25013
25014 \end_inset
25015
25016 -no-crt Don't link the default run-time modules
25017 \end_layout
25018
25019 \begin_layout Subsubsection
25020 Debugging Options
25021 \end_layout
25022
25023 \begin_layout Standard
25024 Debugging options enable extra debugging information in the output files.
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-xtra Similar to -
25042 \begin_inset ERT
25043 status collapsed
25044
25045 \begin_layout Standard
25046
25047
25048 \backslash
25049 /
25050 \end_layout
25051
25052 \end_inset
25053
25054 -debug
25055 \begin_inset LatexCommand \index{-\/-debug}
25056
25057 \end_inset
25058
25059 , but dumps more information.
25060 \end_layout
25061
25062 \begin_layout Description
25063 -
25064 \begin_inset ERT
25065 status collapsed
25066
25067 \begin_layout Standard
25068
25069
25070 \backslash
25071 /
25072 \end_layout
25073
25074 \end_inset
25075
25076 -debug-ralloc Force register allocator to dump <source>.d file with debugging
25077  information.
25078  <source> is the name of the file being compiled.
25079 \end_layout
25080
25081 \begin_layout Description
25082 -
25083 \begin_inset ERT
25084 status collapsed
25085
25086 \begin_layout Standard
25087
25088
25089 \backslash
25090 /
25091 \end_layout
25092
25093 \end_inset
25094
25095 -pcode-verbose Enable pcode debugging information in translation.
25096 \end_layout
25097
25098 \begin_layout Description
25099 -
25100 \begin_inset ERT
25101 status collapsed
25102
25103 \begin_layout Standard
25104
25105
25106 \backslash
25107 /
25108 \end_layout
25109
25110 \end_inset
25111
25112 -calltree Dump call tree in .calltree file.
25113 \end_layout
25114
25115 \begin_layout Description
25116 -
25117 \begin_inset ERT
25118 status collapsed
25119
25120 \begin_layout Standard
25121
25122
25123 \backslash
25124 /
25125 \end_layout
25126
25127 \end_inset
25128
25129 -gstack Trace push/pops for stack pointer overflow.
25130 \end_layout
25131
25132 \begin_layout Subsection
25133 Enviroment Variables
25134 \end_layout
25135
25136 \begin_layout Standard
25137 There is a number of enviromental variables that can be used when running
25138  SDCC to enable certain optimizations or force a specific program behaviour.
25139  these variables are primarily for debugging purposes so they can be enabled/dis
25140 abled at will.
25141 \end_layout
25142
25143 \begin_layout Standard
25144 Currently there is only two such variables available:
25145 \end_layout
25146
25147 \begin_layout Description
25148 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25149  bitfields is optimized by directly loading FSR0 with the address of the
25150  bitfield structure.
25151  Normally SDCC will cast the bitfield structure to a bitfield pointer and
25152  then load FSR0.
25153  This step saves data ram and code space for functions that make heavy use
25154  of bitfields.
25155  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25156  option).
25157  
25158 \end_layout
25159
25160 \begin_layout Description
25161 NO_REG_OPT Do not perform pCode registers optimization.
25162  This should be used for debugging purposes.
25163  If bugs in the pcode optimizer are found, users can benefit from temporarily
25164  disabling the optimizer until the bug is fixed.
25165 \end_layout
25166
25167 \begin_layout Subsection
25168 Preprocessor Macros
25169 \end_layout
25170
25171 \begin_layout Standard
25172 PIC16
25173 \begin_inset LatexCommand \index{PIC16}
25174
25175 \end_inset
25176
25177  port defines the following preprocessor macros while translating a source.
25178 \end_layout
25179
25180 \begin_layout Standard
25181 \align center
25182 \begin_inset Tabular
25183 <lyxtabular version="3" rows="6" columns="2">
25184 <features>
25185 <column alignment="center" valignment="top" leftline="true" width="0">
25186 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25187 <row topline="true" bottomline="true">
25188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25189 \begin_inset Text
25190
25191 \begin_layout Standard
25192 Macro
25193 \end_layout
25194
25195 \end_inset
25196 </cell>
25197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25198 \begin_inset Text
25199
25200 \begin_layout Standard
25201 Description
25202 \end_layout
25203
25204 \end_inset
25205 </cell>
25206 </row>
25207 <row topline="true">
25208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25209 \begin_inset Text
25210
25211 \begin_layout Standard
25212 SDCC_pic16
25213 \end_layout
25214
25215 \end_inset
25216 </cell>
25217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25218 \begin_inset Text
25219
25220 \begin_layout Standard
25221 Port identification
25222 \end_layout
25223
25224 \end_inset
25225 </cell>
25226 </row>
25227 <row topline="true">
25228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25229 \begin_inset Text
25230
25231 \begin_layout Standard
25232 _
25233 \begin_inset ERT
25234 status collapsed
25235
25236 \begin_layout Standard
25237
25238
25239 \backslash
25240 /
25241 \end_layout
25242
25243 \end_inset
25244
25245 _pic16
25246 \end_layout
25247
25248 \end_inset
25249 </cell>
25250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25251 \begin_inset Text
25252
25253 \begin_layout Standard
25254 Port identification (same as above)
25255 \end_layout
25256
25257 \end_inset
25258 </cell>
25259 </row>
25260 <row topline="true">
25261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25262 \begin_inset Text
25263
25264 \begin_layout Standard
25265 pic18fxxxx
25266 \end_layout
25267
25268 \end_inset
25269 </cell>
25270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25271 \begin_inset Text
25272
25273 \begin_layout Standard
25274 MCU Identification.
25275  
25276 \emph on
25277 xxxx
25278 \emph default
25279  is the microcontrol identification number, i.e.
25280  452, 6620, etc
25281 \end_layout
25282
25283 \end_inset
25284 </cell>
25285 </row>
25286 <row topline="true">
25287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25288 \begin_inset Text
25289
25290 \begin_layout Standard
25291 _
25292 \begin_inset ERT
25293 status collapsed
25294
25295 \begin_layout Standard
25296
25297
25298 \backslash
25299 /
25300 \end_layout
25301
25302 \end_inset
25303
25304 _18Fxxxx
25305 \end_layout
25306
25307 \end_inset
25308 </cell>
25309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25310 \begin_inset Text
25311
25312 \begin_layout Standard
25313 MCU Identification (same as above)
25314 \end_layout
25315
25316 \end_inset
25317 </cell>
25318 </row>
25319 <row topline="true" bottomline="true">
25320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25321 \begin_inset Text
25322
25323 \begin_layout Standard
25324 STACK_MODEL_nnn
25325 \end_layout
25326
25327 \end_inset
25328 </cell>
25329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25330 \begin_inset Text
25331
25332 \begin_layout Standard
25333 nnn = SMALL or LARGE respectively according to the stack model used
25334 \end_layout
25335
25336 \end_inset
25337 </cell>
25338 </row>
25339 </lyxtabular>
25340
25341 \end_inset
25342
25343
25344 \end_layout
25345
25346 \begin_layout Standard
25347 In addition the following macros are defined when calling assembler:
25348 \end_layout
25349
25350 \begin_layout Standard
25351 \align center
25352 \begin_inset Tabular
25353 <lyxtabular version="3" rows="4" columns="2">
25354 <features>
25355 <column alignment="center" valignment="top" leftline="true" width="0">
25356 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25357 <row topline="true" bottomline="true">
25358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25359 \begin_inset Text
25360
25361 \begin_layout Standard
25362 Macro
25363 \end_layout
25364
25365 \end_inset
25366 </cell>
25367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25368 \begin_inset Text
25369
25370 \begin_layout Standard
25371 Description
25372 \end_layout
25373
25374 \end_inset
25375 </cell>
25376 </row>
25377 <row topline="true">
25378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25379 \begin_inset Text
25380
25381 \begin_layout Standard
25382 __18Fxxxx
25383 \end_layout
25384
25385 \end_inset
25386 </cell>
25387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25388 \begin_inset Text
25389
25390 \begin_layout Standard
25391 MCU Identification.
25392  
25393 \emph on
25394 xxxx
25395 \emph default
25396  is the microcontrol identification number, i.e.
25397  452, 6620, etc
25398 \end_layout
25399
25400 \end_inset
25401 </cell>
25402 </row>
25403 <row topline="true">
25404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25405 \begin_inset Text
25406
25407 \begin_layout Standard
25408 SDCC_MODEL_nnn
25409 \end_layout
25410
25411 \end_inset
25412 </cell>
25413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25414 \begin_inset Text
25415
25416 \begin_layout Standard
25417 nnn = SMALL or LARGE respectively according to the memory model used for
25418  SDCC
25419 \end_layout
25420
25421 \end_inset
25422 </cell>
25423 </row>
25424 <row topline="true" bottomline="true">
25425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25426 \begin_inset Text
25427
25428 \begin_layout Standard
25429 STACK_MODEL_nnn
25430 \end_layout
25431
25432 \end_inset
25433 </cell>
25434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25435 \begin_inset Text
25436
25437 \begin_layout Standard
25438 nnn = SMALL or LARGE respectively according to the stack model used
25439 \end_layout
25440
25441 \end_inset
25442 </cell>
25443 </row>
25444 </lyxtabular>
25445
25446 \end_inset
25447
25448
25449 \end_layout
25450
25451 \begin_layout Subsection
25452 Directories
25453 \end_layout
25454
25455 \begin_layout Standard
25456 PIC16
25457 \begin_inset LatexCommand \index{PIC16}
25458
25459 \end_inset
25460
25461  port uses the following directories for searching header files and libraries.
25462 \end_layout
25463
25464 \begin_layout Standard
25465 \align center
25466 \begin_inset Tabular
25467 <lyxtabular version="3" rows="3" columns="4">
25468 <features>
25469 <column alignment="center" valignment="top" leftline="true" width="0">
25470 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25471 <column alignment="center" valignment="top" width="0">
25472 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25473 <row topline="true" bottomline="true">
25474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25475 \begin_inset Text
25476
25477 \begin_layout Standard
25478 Directory
25479 \end_layout
25480
25481 \end_inset
25482 </cell>
25483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25484 \begin_inset Text
25485
25486 \begin_layout Standard
25487 Description
25488 \end_layout
25489
25490 \end_inset
25491 </cell>
25492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25493 \begin_inset Text
25494
25495 \begin_layout Standard
25496 Target
25497 \end_layout
25498
25499 \end_inset
25500 </cell>
25501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25502 \begin_inset Text
25503
25504 \begin_layout Standard
25505 Command prefix
25506 \end_layout
25507
25508 \end_inset
25509 </cell>
25510 </row>
25511 <row topline="true">
25512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25513 \begin_inset Text
25514
25515 \begin_layout Standard
25516 PREFIX/sdcc/include/pic16
25517 \end_layout
25518
25519 \end_inset
25520 </cell>
25521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25522 \begin_inset Text
25523
25524 \begin_layout Standard
25525 PIC16 specific headers
25526 \end_layout
25527
25528 \end_inset
25529 </cell>
25530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25531 \begin_inset Text
25532
25533 \begin_layout Standard
25534 Compiler
25535 \end_layout
25536
25537 \end_inset
25538 </cell>
25539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25540 \begin_inset Text
25541
25542 \begin_layout Standard
25543 -I
25544 \end_layout
25545
25546 \end_inset
25547 </cell>
25548 </row>
25549 <row topline="true" bottomline="true">
25550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25551 \begin_inset Text
25552
25553 \begin_layout Standard
25554 PREFIX/sdcc/lib/pic16
25555 \end_layout
25556
25557 \end_inset
25558 </cell>
25559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25560 \begin_inset Text
25561
25562 \begin_layout Standard
25563 PIC16 specific libraries
25564 \end_layout
25565
25566 \end_inset
25567 </cell>
25568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25569 \begin_inset Text
25570
25571 \begin_layout Standard
25572 Linker
25573 \end_layout
25574
25575 \end_inset
25576 </cell>
25577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25578 \begin_inset Text
25579
25580 \begin_layout Standard
25581 -L
25582 \end_layout
25583
25584 \end_inset
25585 </cell>
25586 </row>
25587 </lyxtabular>
25588
25589 \end_inset
25590
25591
25592 \end_layout
25593
25594 \begin_layout Subsection
25595 Pragmas
25596 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25597
25598 \end_inset
25599
25600
25601 \end_layout
25602
25603 \begin_layout Standard
25604 The PIC16
25605 \begin_inset LatexCommand \index{PIC16}
25606
25607 \end_inset
25608
25609  port currently supports the following pragmas:
25610 \end_layout
25611
25612 \begin_layout Description
25613 stack
25614 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25615
25616 \end_inset
25617
25618  This forces the code generator to initialize the stack & frame pointers
25619  at a specific address.
25620  This is an ad hoc solution for cases where no STACK directive is available
25621  in the linker script or gplink is not instructed to create a stack section.
25622 \newline
25623 The
25624  stack pragma should be used only once in a project.
25625  Multiple pragmas may result in indeterminate behaviour of the program.
25626 \begin_inset Foot
25627 status open
25628
25629 \begin_layout Standard
25630 The old format (ie.
25631  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25632  cross page boundaries (or even exceed the available data RAM) and crash
25633  the program.
25634  Make sure that stack does not cross page boundaries when using the SMALL
25635  stack model.
25636 \end_layout
25637
25638 \end_inset
25639
25640
25641 \newline
25642 The format is as follows:
25643 \newline
25644
25645 \end_layout
25646
25647 \begin_layout LyX-Code
25648 #pragma stack bottom_address [stack_size]
25649 \newline
25650
25651 \end_layout
25652
25653 \begin_layout Standard
25654
25655 \emph on
25656 bottom_address
25657 \emph default
25658  is the lower bound of the stack section.
25659  The stack pointer initially will point at address (bottom_address+stack_size-1).
25660 \end_layout
25661
25662 \begin_layout LyX-Code
25663 Example:
25664 \end_layout
25665
25666 \begin_layout LyX-Code
25667
25668 \end_layout
25669
25670 \begin_layout LyX-Code
25671 /* initializes stack of 100 bytes at RAM address 0x200 */
25672 \end_layout
25673
25674 \begin_layout LyX-Code
25675 #pragma stack 0x200 100
25676 \end_layout
25677
25678 \begin_layout Standard
25679 If the stack_size field is omitted then a stack is created with the default
25680  size of 64.
25681  This size might be enough for most programs, but its not enough for operations
25682  with deep function nesting or excessive stack usage.
25683 \end_layout
25684
25685 \begin_layout Description
25686 code
25687 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25688
25689 \end_inset
25690
25691  Force a function to a static FLASH address.
25692 \end_layout
25693
25694 \begin_layout LyX-Code
25695 Example:
25696 \end_layout
25697
25698 \begin_layout LyX-Code
25699
25700 \end_layout
25701
25702 \begin_layout LyX-Code
25703 /* place function test_func at 0x4000 */
25704 \end_layout
25705
25706 \begin_layout LyX-Code
25707 #pragma code test_func 0x4000
25708 \end_layout
25709
25710 \begin_layout LyX-Code
25711
25712 \end_layout
25713
25714 \begin_layout Description
25715 library instructs the linker to use a library module.
25716 \newline
25717 Usage:
25718 \end_layout
25719
25720 \begin_layout LyX-Code
25721 #pragma library module_name
25722 \end_layout
25723
25724 \begin_layout Standard
25725
25726 \emph on
25727 module_name
25728 \emph default
25729  can be any library or object file (including its path).
25730  Note that there are four reserved keywords which have special meaning.
25731  These are:
25732 \end_layout
25733
25734 \begin_layout Standard
25735 \align center
25736 \begin_inset Tabular
25737 <lyxtabular version="3" rows="6" columns="3">
25738 <features>
25739 <column alignment="center" valignment="top" leftline="true" width="0">
25740 <column alignment="block" valignment="top" leftline="true" width="20page%">
25741 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25742 <row topline="true" bottomline="true">
25743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25744 \begin_inset Text
25745
25746 \begin_layout Standard
25747 Keyword
25748 \end_layout
25749
25750 \end_inset
25751 </cell>
25752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25753 \begin_inset Text
25754
25755 \begin_layout Standard
25756 Description
25757 \end_layout
25758
25759 \end_inset
25760 </cell>
25761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25762 \begin_inset Text
25763
25764 \begin_layout Standard
25765 Module to link
25766 \end_layout
25767
25768 \end_inset
25769 </cell>
25770 </row>
25771 <row topline="true">
25772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25773 \begin_inset Text
25774
25775 \begin_layout Standard
25776
25777 \series bold
25778 ignore
25779 \end_layout
25780
25781 \end_inset
25782 </cell>
25783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25784 \begin_inset Text
25785
25786 \begin_layout Standard
25787 ignore all library pragmas
25788 \end_layout
25789
25790 \end_inset
25791 </cell>
25792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25793 \begin_inset Text
25794
25795 \begin_layout Standard
25796
25797 \emph on
25798 (none)
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 c
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 C library
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 libc18f
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 math
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 Math libarary
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 libm18f
25867 \emph default
25868 .lib
25869 \end_layout
25870
25871 \end_inset
25872 </cell>
25873 </row>
25874 <row topline="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 io
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 I/O 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 libio18f*
25902 \emph default
25903 .lib
25904 \end_layout
25905
25906 \end_inset
25907 </cell>
25908 </row>
25909 <row topline="true" bottomline="true">
25910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25911 \begin_inset Text
25912
25913 \begin_layout Standard
25914
25915 \series bold
25916 debug
25917 \end_layout
25918
25919 \end_inset
25920 </cell>
25921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25922 \begin_inset Text
25923
25924 \begin_layout Standard
25925 link the debug library
25926 \end_layout
25927
25928 \end_inset
25929 </cell>
25930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25931 \begin_inset Text
25932
25933 \begin_layout Standard
25934
25935 \emph on
25936 libdebug
25937 \emph default
25938 .lib
25939 \end_layout
25940
25941 \end_inset
25942 </cell>
25943 </row>
25944 </lyxtabular>
25945
25946 \end_inset
25947
25948
25949 \newline
25950 * is the device number, i.e.
25951  452 for PIC18F452 MCU.
25952 \end_layout
25953
25954 \begin_layout Standard
25955 This feature allows for linking with specific libraries withoug having to
25956  explicit name them in the command line.
25957  Note that the 
25958 \noun on
25959 ignore
25960 \noun default
25961  keyword will reject all modules specified by the library pragma.
25962 \end_layout
25963
25964 \begin_layout Description
25965 udata The pragma udata instructs the compiler to emit code so that linker
25966  will place a variable at a specific memory bank.
25967 \end_layout
25968
25969 \begin_layout LyX-Code
25970 Example:
25971 \end_layout
25972
25973 \begin_layout LyX-Code
25974
25975 \end_layout
25976
25977 \begin_layout LyX-Code
25978 /* places variable foo at bank2 */
25979 \end_layout
25980
25981 \begin_layout LyX-Code
25982 #pragma udata bank2 foo
25983 \end_layout
25984
25985 \begin_layout LyX-Code
25986 char foo;
25987 \end_layout
25988
25989 \begin_layout Standard
25990 In order for this pragma to work extra SECTION directives should be added
25991  in the .lkr script.
25992  In the following example a sample .lkr file is shown:
25993 \end_layout
25994
25995 \begin_layout LyX-Code
25996
25997 \end_layout
25998
25999 \begin_layout LyX-Code
26000 // Sample linker script for the PIC18F452 processor
26001 \end_layout
26002
26003 \begin_layout LyX-Code
26004 LIBPATH .
26005 \end_layout
26006
26007 \begin_layout LyX-Code
26008 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
26009 \end_layout
26010
26011 \begin_layout LyX-Code
26012 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
26013 \end_layout
26014
26015 \begin_layout LyX-Code
26016 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
26017 \end_layout
26018
26019 \begin_layout LyX-Code
26020 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
26021 \end_layout
26022
26023 \begin_layout LyX-Code
26024 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
26025 \end_layout
26026
26027 \begin_layout LyX-Code
26028 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
26029 \end_layout
26030
26031 \begin_layout LyX-Code
26032 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
26033 \end_layout
26034
26035 \begin_layout LyX-Code
26036
26037 \end_layout
26038
26039 \begin_layout LyX-Code
26040 DATABANK   NAME=gpr0       START=0x80           END=0xFF
26041 \end_layout
26042
26043 \begin_layout LyX-Code
26044 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
26045 \end_layout
26046
26047 \begin_layout LyX-Code
26048 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
26049 \end_layout
26050
26051 \begin_layout LyX-Code
26052 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
26053 \end_layout
26054
26055 \begin_layout LyX-Code
26056 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
26057 \end_layout
26058
26059 \begin_layout LyX-Code
26060 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
26061 \end_layout
26062
26063 \begin_layout LyX-Code
26064 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
26065 \end_layout
26066
26067 \begin_layout LyX-Code
26068
26069 \end_layout
26070
26071 \begin_layout LyX-Code
26072 SECTION    NAME=CONFIG     ROM=config
26073 \end_layout
26074
26075 \begin_layout LyX-Code
26076
26077 \end_layout
26078
26079 \begin_layout LyX-Code
26080 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
26081 \end_layout
26082
26083 \begin_layout LyX-Code
26084 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
26085 \end_layout
26086
26087 \begin_layout LyX-Code
26088 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
26089 \end_layout
26090
26091 \begin_layout LyX-Code
26092 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
26093 \end_layout
26094
26095 \begin_layout LyX-Code
26096 SECTION    NAME=bank4      RAM=gpr4
26097 \end_layout
26098
26099 \begin_layout LyX-Code
26100 SECTION    NAME=bank5      RAM=gpr5
26101 \end_layout
26102
26103 \begin_layout Standard
26104 The linker will recognise the section name set in the pragma statement and
26105  will position the variable at the memory bank set with the RAM field at
26106  the SECTION line in the linker script file.
26107 \end_layout
26108
26109 \begin_layout Subsection
26110 Header Files
26111 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26112
26113 \end_inset
26114
26115
26116 \end_layout
26117
26118 \begin_layout Standard
26119 There is one main header file
26120 \begin_inset LatexCommand \index{PIC16!Header files}
26121
26122 \end_inset
26123
26124  that can be included to the source files using the pic16
26125 \begin_inset LatexCommand \index{PIC16}
26126
26127 \end_inset
26128
26129  port.
26130  That file is the 
26131 \series bold
26132 pic18fregs.h
26133 \series default
26134 .
26135  This header file contains the definitions for the processor special registers,
26136  so it is necessary if the source accesses them.
26137  It can be included by adding the following line in the beginning of the
26138  file:
26139 \end_layout
26140
26141 \begin_layout LyX-Code
26142 #include <pic18fregs.h>
26143 \end_layout
26144
26145 \begin_layout Standard
26146 The specific microcontroller is selected within the pic18fregs.h automatically,
26147  so the same source can be used with a variety of devices.
26148 \end_layout
26149
26150 \begin_layout Subsection
26151 Libraries
26152 \end_layout
26153
26154 \begin_layout Standard
26155 The libraries
26156 \begin_inset LatexCommand \index{PIC16!Libraries}
26157
26158 \end_inset
26159
26160  that PIC16
26161 \begin_inset LatexCommand \index{PIC16}
26162
26163 \end_inset
26164
26165  port depends on are the microcontroller device libraries which contain
26166  the symbol definitions for the microcontroller special function registers.
26167  These libraries have the format pic18fxxxx.lib, where 
26168 \emph on
26169 xxxx
26170 \emph default
26171  is the microcontroller identification number.
26172  The specific library is selected automatically by the compiler at link
26173  stage according to the selected device.
26174 \end_layout
26175
26176 \begin_layout Standard
26177 Libraries are created with gplib which is part of the gputils package 
26178 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26179
26180 \end_inset
26181
26182 .
26183 \end_layout
26184
26185 \begin_layout Subsubsection*
26186 Building the libraries
26187 \end_layout
26188
26189 \begin_layout Standard
26190 Before using SDCC/pic16 there are some libraries that need to be compiled.
26191  This process is not done automatically by SDCC since not all users use
26192  SDCC for pic16 projects.
26193  So each user should compile the libraries separately.
26194 \end_layout
26195
26196 \begin_layout Standard
26197 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26198 \end_layout
26199
26200 \begin_layout LyX-Code
26201 cd device/lib/pic16
26202 \end_layout
26203
26204 \begin_layout LyX-Code
26205 ./configure
26206 \end_layout
26207
26208 \begin_layout LyX-Code
26209 make
26210 \end_layout
26211
26212 \begin_layout LyX-Code
26213 cd ..
26214 \end_layout
26215
26216 \begin_layout LyX-Code
26217 make model-pic16
26218 \end_layout
26219
26220 \begin_layout LyX-Code
26221 su -c 'make install'     # install the libraries, you need the root password
26222 \end_layout
26223
26224 \begin_layout Standard
26225 If you need to install the headers too, do:
26226 \end_layout
26227
26228 \begin_layout LyX-Code
26229 cd device/include
26230 \end_layout
26231
26232 \begin_layout LyX-Code
26233 su -c 'make install'     # install the headers, you need the root password
26234 \end_layout
26235
26236 \begin_layout Standard
26237 There exist a special target to build the I/O libraries.
26238  This target is not automatically build because it will build the I/O library
26239  for 
26240 \emph on
26241 every
26242 \emph default
26243  supported device.
26244  This way building will take quite a lot of time.
26245  Users are advised to edit the 
26246 \series bold
26247 device/lib/pic16/pics.build
26248 \series default
26249  file and then execute:
26250 \end_layout
26251
26252 \begin_layout LyX-Code
26253 make lib-io
26254 \end_layout
26255
26256 \begin_layout Subsection
26257 Adding New Devices to the Port
26258 \end_layout
26259
26260 \begin_layout Standard
26261 Adding support for a new 16
26262 \begin_inset ERT
26263 status open
26264
26265 \begin_layout Standard
26266
26267
26268 \backslash
26269 ,
26270 \end_layout
26271
26272 \end_inset
26273
26274 bit PIC MCU requires the following steps:
26275 \end_layout
26276
26277 \begin_layout Enumerate
26278 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26279 \newline
26280
26281 \family typewriter
26282 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26283 inc
26284 \end_layout
26285
26286 \begin_layout Enumerate
26287
26288 \family typewriter
26289 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26290 \end_layout
26291
26292 \begin_layout Enumerate
26293
26294 \family typewriter
26295 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26296 \end_layout
26297
26298 \begin_layout Enumerate
26299 Add DEVICE to 
26300 \family typewriter
26301 /path/to/sdcc/device/lib/pic16/pics.all
26302 \family default
26303  (and 
26304 \family typewriter
26305 .build
26306 \family default
26307 ).
26308 \newline
26309 Note: No 18f prefix here!
26310 \end_layout
26311
26312 \begin_layout Enumerate
26313 Set up the I/O library by doing 
26314 \series bold
26315 one
26316 \series default
26317  of the following:
26318 \end_layout
26319
26320 \begin_deeper
26321 \begin_layout Enumerate
26322 Adjust 
26323 \family typewriter
26324 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26325 \family default
26326
26327 \newline
26328 Add your DEVICE if it does not compile in 
26329 \family typewriter
26330 adc
26331 \family default
26332
26333 \family typewriter
26334 i2c
26335 \family default
26336 , or 
26337 \family typewriter
26338 usart
26339 \family default
26340 .
26341 \end_layout
26342
26343 \begin_layout Enumerate
26344 Adjust 
26345 \family typewriter
26346 /path/to/sdcc/device/include/pic16/adc.h
26347 \newline
26348
26349 \family default
26350 Add the new devices to the correct ADC style class.
26351 \end_layout
26352
26353 \end_deeper
26354 \begin_layout Enumerate
26355 Edit 
26356 \family typewriter
26357 /path/to/sdcc/device/include/pic16/pic18fregs.h
26358 \family default
26359 .
26360  The file format is self-explanatory, just add
26361 \newline
26362
26363 \family typewriter
26364 #elif defined(picDEVICE)
26365 \newline
26366 # include <picDEVICE.h>
26367 \family default
26368
26369 \newline
26370 at the right place (keep it sorted).
26371 \end_layout
26372
26373 \begin_layout Enumerate
26374 Edit 
26375 \family typewriter
26376 /path/to/sdcc/device/include/pic16devices.txt
26377 \newline
26378
26379 \family default
26380 Copy and modify an existing entry or create a new one and insert it at the
26381  correct place (keep the file sorted).
26382 \end_layout
26383
26384 \begin_layout Enumerate
26385 Recompile the pic16 libraries.
26386 \end_layout
26387
26388 \begin_layout Subsection
26389 Memory Models
26390 \end_layout
26391
26392 \begin_layout Standard
26393 The following memory models are supported by the PIC16 port:
26394 \end_layout
26395
26396 \begin_layout Itemize
26397 small model
26398 \end_layout
26399
26400 \begin_layout Itemize
26401 large model
26402 \end_layout
26403
26404 \begin_layout Standard
26405 Memory model affects the default size of pointers within the source.
26406  The sizes are shown in the next table:
26407 \end_layout
26408
26409 \begin_layout Standard
26410 \align center
26411 \begin_inset Tabular
26412 <lyxtabular version="3" rows="3" columns="3">
26413 <features>
26414 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26415 <column alignment="center" valignment="top" leftline="true" width="0">
26416 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26417 <row topline="true" bottomline="true">
26418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26419 \begin_inset Text
26420
26421 \begin_layout Standard
26422 Pointer sizes according to memory model
26423 \end_layout
26424
26425 \end_inset
26426 </cell>
26427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26428 \begin_inset Text
26429
26430 \begin_layout Standard
26431 small model
26432 \end_layout
26433
26434 \end_inset
26435 </cell>
26436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26437 \begin_inset Text
26438
26439 \begin_layout Standard
26440 large model
26441 \end_layout
26442
26443 \end_inset
26444 </cell>
26445 </row>
26446 <row topline="true" bottomline="true">
26447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26448 \begin_inset Text
26449
26450 \begin_layout Standard
26451 code pointers
26452 \end_layout
26453
26454 \end_inset
26455 </cell>
26456 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26457 \begin_inset Text
26458
26459 \begin_layout Standard
26460 16-bits
26461 \end_layout
26462
26463 \end_inset
26464 </cell>
26465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26466 \begin_inset Text
26467
26468 \begin_layout Standard
26469 24-bits
26470 \end_layout
26471
26472 \end_inset
26473 </cell>
26474 </row>
26475 <row topline="true" bottomline="true">
26476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26477 \begin_inset Text
26478
26479 \begin_layout Standard
26480 data pointers
26481 \end_layout
26482
26483 \end_inset
26484 </cell>
26485 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26486 \begin_inset Text
26487
26488 \begin_layout Standard
26489 16-bits
26490 \end_layout
26491
26492 \end_inset
26493 </cell>
26494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26495 \begin_inset Text
26496
26497 \begin_layout Standard
26498 16-bits
26499 \end_layout
26500
26501 \end_inset
26502 </cell>
26503 </row>
26504 </lyxtabular>
26505
26506 \end_inset
26507
26508
26509 \end_layout
26510
26511 \begin_layout Standard
26512 It is advisable that all sources within a project are compiled with the
26513  same memory model.
26514  If one wants to override the default memory model, this can be done by
26515  declaring a pointer as 
26516 \series bold
26517 far
26518 \series default
26519  or 
26520 \series bold
26521 near
26522 \series default
26523 .
26524  Far selects large memory model's pointers, while near selects small memory
26525  model's pointers.
26526 \end_layout
26527
26528 \begin_layout Standard
26529 The standard device libraries (see 
26530 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26531
26532 \end_inset
26533
26534 ) contain no reference to pointers, so they can be used with both memory
26535  models.
26536 \end_layout
26537
26538 \begin_layout Subsection
26539 Stack
26540 \end_layout
26541
26542 \begin_layout Standard
26543 The stack
26544 \begin_inset LatexCommand \index{PIC16!stack}
26545
26546 \end_inset
26547
26548  implementation for the PIC16 port uses two indirect registers, FSR1 and
26549  FSR2.
26550 \end_layout
26551
26552 \begin_layout Description
26553 FSR1 is assigned as stack pointer
26554 \end_layout
26555
26556 \begin_layout Description
26557 FSR2 is assigned as frame pointer
26558 \end_layout
26559
26560 \begin_layout Standard
26561 The following stack models are supported by the PIC16 port
26562 \end_layout
26563
26564 \begin_layout Itemize
26565
26566 \noun on
26567 small
26568 \noun default
26569  model
26570 \end_layout
26571
26572 \begin_layout Itemize
26573
26574 \noun on
26575 large
26576 \noun default
26577  model
26578 \end_layout
26579
26580 \begin_layout Standard
26581
26582 \noun on
26583 Small
26584 \noun default
26585  model means that only the FSRxL byte is used to access stack and frame,
26586  while 
26587 \emph on
26588 \noun on
26589 large
26590 \emph default
26591 \noun default
26592  uses both FSRxL and FSRxH registers.
26593  The following table shows the stack/frame pointers sizes according to stack
26594  model and the maximum space they can address:
26595 \end_layout
26596
26597 \begin_layout Standard
26598 \align center
26599 \begin_inset Tabular
26600 <lyxtabular version="3" rows="3" columns="3">
26601 <features>
26602 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26603 <column alignment="center" valignment="top" leftline="true" width="0">
26604 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26605 <row topline="true" bottomline="true">
26606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26607 \begin_inset Text
26608
26609 \begin_layout Standard
26610 Stack & Frame pointer sizes according to stack model
26611 \end_layout
26612
26613 \end_inset
26614 </cell>
26615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26616 \begin_inset Text
26617
26618 \begin_layout Standard
26619 small
26620 \end_layout
26621
26622 \end_inset
26623 </cell>
26624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26625 \begin_inset Text
26626
26627 \begin_layout Standard
26628 large
26629 \end_layout
26630
26631 \end_inset
26632 </cell>
26633 </row>
26634 <row topline="true">
26635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26636 \begin_inset Text
26637
26638 \begin_layout Standard
26639 Stack pointer FSR1
26640 \end_layout
26641
26642 \end_inset
26643 </cell>
26644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26645 \begin_inset Text
26646
26647 \begin_layout Standard
26648 8-bits
26649 \end_layout
26650
26651 \end_inset
26652 </cell>
26653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26654 \begin_inset Text
26655
26656 \begin_layout Standard
26657 16-bits
26658 \end_layout
26659
26660 \end_inset
26661 </cell>
26662 </row>
26663 <row topline="true" bottomline="true">
26664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26665 \begin_inset Text
26666
26667 \begin_layout Standard
26668 Frame pointer FSR2
26669 \end_layout
26670
26671 \end_inset
26672 </cell>
26673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26674 \begin_inset Text
26675
26676 \begin_layout Standard
26677 8-bits
26678 \end_layout
26679
26680 \end_inset
26681 </cell>
26682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26683 \begin_inset Text
26684
26685 \begin_layout Standard
26686 16-bits
26687 \end_layout
26688
26689 \end_inset
26690 </cell>
26691 </row>
26692 </lyxtabular>
26693
26694 \end_inset
26695
26696
26697 \end_layout
26698
26699 \begin_layout Standard
26700
26701 \noun on
26702 Large 
26703 \noun default
26704 stack model is currently not working properly throughout the code generator.
26705  So its use is not advised.
26706  Also there are some other points that need special care:
26707 \newline
26708
26709 \end_layout
26710
26711 \begin_layout Enumerate
26712 Do not create stack sections with size more than one physical bank (that
26713  is 256 bytes)
26714 \end_layout
26715
26716 \begin_layout Enumerate
26717 Stack sections should no cross physical bank limits (i.e.
26718  #pragma stack 0x50 0x100)
26719 \end_layout
26720
26721 \begin_layout Standard
26722 These limitations are caused by the fact that only FSRxL is modified when
26723  using SMALL stack model, so no more than 256 bytes of stack can be used.
26724  This problem will disappear after LARGE model is fully implemented.
26725 \end_layout
26726
26727 \begin_layout Subsection
26728 Functions
26729 \end_layout
26730
26731 \begin_layout Standard
26732 In addition to the standard SDCC function keywords, PIC16
26733 \begin_inset LatexCommand \index{PIC16}
26734
26735 \end_inset
26736
26737  port makes available two more:
26738 \end_layout
26739
26740 \begin_layout Description
26741 wparam
26742 \begin_inset LatexCommand \index{PIC16!wparam}
26743
26744 \end_inset
26745
26746  Use the WREG to pass one byte of the first function argument.
26747  This improves speed but you may not use this for functions with arguments
26748  that are called via function pointers, otherwise the first byte of the
26749  first parameter will get lost.
26750  Usage:
26751 \end_layout
26752
26753 \begin_layout LyX-Code
26754 void func_wparam(int a) wparam
26755 \end_layout
26756
26757 \begin_layout LyX-Code
26758 {
26759 \end_layout
26760
26761 \begin_layout LyX-Code
26762     /* WREG hold the lower part of a */
26763 \end_layout
26764
26765 \begin_layout LyX-Code
26766     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26767  */
26768 \end_layout
26769
26770 \begin_layout LyX-Code
26771 ...
26772 \end_layout
26773
26774 \begin_layout LyX-Code
26775 }
26776 \end_layout
26777
26778 \begin_layout Description
26779 shadowregs
26780 \begin_inset LatexCommand \index{PIC16!shadowregs}
26781
26782 \end_inset
26783
26784  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26785  hardware shadow registers which hold the values of WREG, STATUS and BSR
26786  registers.
26787  This can be done by adding the keyword 
26788 \emph on
26789 shadowregs
26790 \emph default
26791  before the 
26792 \emph on
26793 interrupt
26794 \emph default
26795  keyword in the function's header.
26796 \end_layout
26797
26798 \begin_layout LyX-Code
26799 void isr_shadow(void) shadowregs interrupt 1
26800 \end_layout
26801
26802 \begin_layout LyX-Code
26803 {
26804 \end_layout
26805
26806 \begin_layout LyX-Code
26807 ...
26808 \end_layout
26809
26810 \begin_layout LyX-Code
26811 }
26812 \end_layout
26813
26814 \begin_layout Standard
26815
26816 \emph on
26817 shadowregs
26818 \emph default
26819  instructs the code generator not to store/restore WREG, STATUS, BSR when
26820  entering/exiting the ISR.
26821 \end_layout
26822
26823 \begin_layout Subsection
26824 Function return values
26825 \end_layout
26826
26827 \begin_layout Standard
26828 Return values from functions are placed to the appropriate registers following
26829  a modified Microchip policy optimized for SDCC.
26830  The following table shows these registers:
26831 \end_layout
26832
26833 \begin_layout Standard
26834 \align center
26835 \begin_inset Tabular
26836 <lyxtabular version="3" rows="6" columns="2">
26837 <features>
26838 <column alignment="center" valignment="top" leftline="true" width="0">
26839 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26840 <row topline="true" bottomline="true">
26841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26842 \begin_inset Text
26843
26844 \begin_layout Standard
26845 size
26846 \end_layout
26847
26848 \end_inset
26849 </cell>
26850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26851 \begin_inset Text
26852
26853 \begin_layout Standard
26854 destination register
26855 \end_layout
26856
26857 \end_inset
26858 </cell>
26859 </row>
26860 <row topline="true">
26861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26862 \begin_inset Text
26863
26864 \begin_layout Standard
26865 8 bits
26866 \end_layout
26867
26868 \end_inset
26869 </cell>
26870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26871 \begin_inset Text
26872
26873 \begin_layout Standard
26874 WREG
26875 \end_layout
26876
26877 \end_inset
26878 </cell>
26879 </row>
26880 <row topline="true">
26881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26882 \begin_inset Text
26883
26884 \begin_layout Standard
26885 16 bits
26886 \end_layout
26887
26888 \end_inset
26889 </cell>
26890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26891 \begin_inset Text
26892
26893 \begin_layout Standard
26894 PRODL:WREG
26895 \end_layout
26896
26897 \end_inset
26898 </cell>
26899 </row>
26900 <row topline="true">
26901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26902 \begin_inset Text
26903
26904 \begin_layout Standard
26905 24 bits
26906 \end_layout
26907
26908 \end_inset
26909 </cell>
26910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26911 \begin_inset Text
26912
26913 \begin_layout Standard
26914 PRODH:PRODL:WREG
26915 \end_layout
26916
26917 \end_inset
26918 </cell>
26919 </row>
26920 <row topline="true">
26921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26922 \begin_inset Text
26923
26924 \begin_layout Standard
26925 32 bits
26926 \end_layout
26927
26928 \end_inset
26929 </cell>
26930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26931 \begin_inset Text
26932
26933 \begin_layout Standard
26934 FSR0L:PRODH:PRODL:WREG
26935 \end_layout
26936
26937 \end_inset
26938 </cell>
26939 </row>
26940 <row topline="true" bottomline="true">
26941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26942 \begin_inset Text
26943
26944 \begin_layout Standard
26945 >32 bits
26946 \end_layout
26947
26948 \end_inset
26949 </cell>
26950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26951 \begin_inset Text
26952
26953 \begin_layout Standard
26954 on stack, FSR0 points to the beginning
26955 \end_layout
26956
26957 \end_inset
26958 </cell>
26959 </row>
26960 </lyxtabular>
26961
26962 \end_inset
26963
26964
26965 \end_layout
26966
26967 \begin_layout Subsection
26968 Interrupts
26969 \end_layout
26970
26971 \begin_layout Standard
26972 An interrupt
26973 \begin_inset LatexCommand \index{PIC16!interrupt}
26974
26975 \end_inset
26976
26977  service routine (ISR) is declared using the 
26978 \emph on
26979 interrupt
26980 \emph default
26981  keyword.
26982 \end_layout
26983
26984 \begin_layout LyX-Code
26985 void isr(void) interrupt 
26986 \emph on
26987 n
26988 \end_layout
26989
26990 \begin_layout LyX-Code
26991 {
26992 \end_layout
26993
26994 \begin_layout LyX-Code
26995 ...
26996 \end_layout
26997
26998 \begin_layout LyX-Code
26999 }
27000 \end_layout
27001
27002 \begin_layout Standard
27003
27004 \emph on
27005 n
27006 \emph default
27007  is the interrupt number, which for PIC18F devices can be:
27008 \end_layout
27009
27010 \begin_layout Standard
27011 \align center
27012 \begin_inset Tabular
27013 <lyxtabular version="3" rows="4" columns="3">
27014 <features>
27015 <column alignment="center" valignment="top" leftline="true" width="0">
27016 <column alignment="center" valignment="top" leftline="true" width="0">
27017 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27018 <row topline="true" bottomline="true">
27019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27020 \begin_inset Text
27021
27022 \begin_layout Standard
27023
27024 \emph on
27025 n
27026 \end_layout
27027
27028 \end_inset
27029 </cell>
27030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27031 \begin_inset Text
27032
27033 \begin_layout Standard
27034 Interrupt Vector
27035 \end_layout
27036
27037 \end_inset
27038 </cell>
27039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27040 \begin_inset Text
27041
27042 \begin_layout Standard
27043 Interrupt Vector Address
27044 \end_layout
27045
27046 \end_inset
27047 </cell>
27048 </row>
27049 <row topline="true">
27050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27051 \begin_inset Text
27052
27053 \begin_layout Standard
27054 0
27055 \end_layout
27056
27057 \end_inset
27058 </cell>
27059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27060 \begin_inset Text
27061
27062 \begin_layout Standard
27063 RESET vector
27064 \end_layout
27065
27066 \end_inset
27067 </cell>
27068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27069 \begin_inset Text
27070
27071 \begin_layout Standard
27072 0x000000
27073 \end_layout
27074
27075 \end_inset
27076 </cell>
27077 </row>
27078 <row topline="true">
27079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27080 \begin_inset Text
27081
27082 \begin_layout Standard
27083
27084 \family roman
27085 \series medium
27086 \shape up
27087 \size normal
27088 \emph off
27089 \bar no
27090 \noun off
27091 \color none
27092 1
27093 \end_layout
27094
27095 \end_inset
27096 </cell>
27097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27098 \begin_inset Text
27099
27100 \begin_layout Standard
27101
27102 \family roman
27103 \series medium
27104 \shape up
27105 \size normal
27106 \emph off
27107 \bar no
27108 \noun off
27109 \color none
27110 HIGH priority interrupts
27111 \end_layout
27112
27113 \end_inset
27114 </cell>
27115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27116 \begin_inset Text
27117
27118 \begin_layout Standard
27119 0x000008
27120 \end_layout
27121
27122 \end_inset
27123 </cell>
27124 </row>
27125 <row topline="true" bottomline="true">
27126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27127 \begin_inset Text
27128
27129 \begin_layout Standard
27130 2
27131 \end_layout
27132
27133 \end_inset
27134 </cell>
27135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27136 \begin_inset Text
27137
27138 \begin_layout Standard
27139 LOW priority interrupts
27140 \end_layout
27141
27142 \end_inset
27143 </cell>
27144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27145 \begin_inset Text
27146
27147 \begin_layout Standard
27148 0x000018
27149 \end_layout
27150
27151 \end_inset
27152 </cell>
27153 </row>
27154 </lyxtabular>
27155
27156 \end_inset
27157
27158
27159 \end_layout
27160
27161 \begin_layout Standard
27162 When generating assembly code for ISR the code generator places a 
27163 \noun on
27164 goto 
27165 \noun default
27166 instruction at the 
27167 \emph on
27168 Interrupt Vector Address
27169 \emph default
27170  which points at the genetated ISR.
27171  This single GOTO instruction is part of an automatically generated 
27172 \emph on
27173 interrupt entry point
27174 \emph default
27175  function.
27176  The actuall ISR code is placed as normally would in the code space.
27177  Upon interrupt request, the GOTO instruction is executed which jumps to
27178  the ISR code.
27179  When declaring interrupt functions as _naked this GOTO instruction is 
27180 \series bold
27181 not
27182 \series default
27183  generated.
27184  The whole interrupt functions is therefore placed at the Interrupt Vector
27185  Address of the specific interrupt.
27186  This is not a problem for the LOW priority interrupts, but it is a problem
27187  for the RESET and the HIGH priority interrupts because code may be written
27188  at the next interrupt's vector address and cause undeterminate program
27189  behaviour if that interrupt is raised.
27190 \begin_inset Foot
27191 status open
27192
27193 \begin_layout Standard
27194 This is not a problem when
27195 \end_layout
27196
27197 \begin_layout Enumerate
27198 this is a HIGH interrupt ISR and LOW interrupts are 
27199 \emph on
27200 disabled
27201 \emph default
27202  or not used.
27203 \end_layout
27204
27205 \begin_layout Enumerate
27206 when the ISR is small enough not to reach the next interrupt's vector address.
27207 \end_layout
27208
27209 \end_inset
27210
27211
27212 \end_layout
27213
27214 \begin_layout Standard
27215
27216 \emph on
27217 n
27218 \emph default
27219  may be omitted.
27220  This way a function is generated similar to an ISR, but it is not assigned
27221  to any interrupt.
27222 \end_layout
27223
27224 \begin_layout Standard
27225 When entering an interrupt, currently the PIC16
27226 \begin_inset LatexCommand \index{PIC16}
27227
27228 \end_inset
27229
27230  port automatically saves the following registers:
27231 \end_layout
27232
27233 \begin_layout Itemize
27234 WREG
27235 \end_layout
27236
27237 \begin_layout Itemize
27238 STATUS
27239 \end_layout
27240
27241 \begin_layout Itemize
27242 BSR
27243 \end_layout
27244
27245 \begin_layout Itemize
27246 PROD (PRODL and PRODH)
27247 \end_layout
27248
27249 \begin_layout Itemize
27250 FSR0 (FSR0L and FSR0H)
27251 \end_layout
27252
27253 \begin_layout Standard
27254 These registers are restored upon return from the interrupt routine.
27255 \begin_inset Foot
27256 status open
27257
27258 \begin_layout Standard
27259 NOTE that when the _naked attribute is specified for an interrupt routine,
27260  then NO registers are stored or restored.
27261 \end_layout
27262
27263 \end_inset
27264
27265
27266 \end_layout
27267
27268 \begin_layout Subsection
27269 Generic Pointers
27270 \end_layout
27271
27272 \begin_layout Standard
27273 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27274  There are 3 types of generic pointers currently implemented data, code
27275  and eeprom pointers.
27276  They are differentiated by the value of the 7th and 6th bits of the upper
27277  byte:
27278 \end_layout
27279
27280 \begin_layout Standard
27281 \align center
27282 \begin_inset Tabular
27283 <lyxtabular version="3" rows="5" columns="5">
27284 <features>
27285 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27286 <column alignment="center" valignment="top" width="0">
27287 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27288 <column alignment="center" valignment="top" width="0">
27289 <column alignment="left" valignment="top" rightline="true" width="0">
27290 <row topline="true" bottomline="true">
27291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27292 \begin_inset Text
27293
27294 \begin_layout Standard
27295 pointer type
27296 \end_layout
27297
27298 \end_inset
27299 </cell>
27300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27301 \begin_inset Text
27302
27303 \begin_layout Standard
27304 7th bit
27305 \end_layout
27306
27307 \end_inset
27308 </cell>
27309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27310 \begin_inset Text
27311
27312 \begin_layout Standard
27313 6th bit
27314 \end_layout
27315
27316 \end_inset
27317 </cell>
27318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27319 \begin_inset Text
27320
27321 \begin_layout Standard
27322 rest of the pointer
27323 \end_layout
27324
27325 \end_inset
27326 </cell>
27327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27328 \begin_inset Text
27329
27330 \begin_layout Standard
27331 description
27332 \end_layout
27333
27334 \end_inset
27335 </cell>
27336 </row>
27337 <row topline="true" bottomline="true">
27338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27339 \begin_inset Text
27340
27341 \begin_layout Standard
27342 data 
27343 \end_layout
27344
27345 \end_inset
27346 </cell>
27347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27348 \begin_inset Text
27349
27350 \begin_layout Standard
27351 1
27352 \end_layout
27353
27354 \end_inset
27355 </cell>
27356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27357 \begin_inset Text
27358
27359 \begin_layout Standard
27360 0
27361 \end_layout
27362
27363 \end_inset
27364 </cell>
27365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27366 \begin_inset Text
27367
27368 \begin_layout Standard
27369
27370 \family typewriter
27371 \shape slanted
27372 \emph on
27373 uuuuuu uuuuxxxx xxxxxxxx
27374 \end_layout
27375
27376 \end_inset
27377 </cell>
27378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27379 \begin_inset Text
27380
27381 \begin_layout Standard
27382 a 12-bit data pointer in data RAM memory
27383 \end_layout
27384
27385 \end_inset
27386 </cell>
27387 </row>
27388 <row bottomline="true">
27389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27390 \begin_inset Text
27391
27392 \begin_layout Standard
27393 code
27394 \end_layout
27395
27396 \end_inset
27397 </cell>
27398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27399 \begin_inset Text
27400
27401 \begin_layout Standard
27402 0
27403 \end_layout
27404
27405 \end_inset
27406 </cell>
27407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27408 \begin_inset Text
27409
27410 \begin_layout Standard
27411 0
27412 \end_layout
27413
27414 \end_inset
27415 </cell>
27416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27417 \begin_inset Text
27418
27419 \begin_layout Standard
27420
27421 \family typewriter
27422 \shape slanted
27423 \emph on
27424 uxxxxx xxxxxxxx xxxxxxxx
27425 \end_layout
27426
27427 \end_inset
27428 </cell>
27429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27430 \begin_inset Text
27431
27432 \begin_layout Standard
27433 a 21-bit code pointer in FLASH memory
27434 \end_layout
27435
27436 \end_inset
27437 </cell>
27438 </row>
27439 <row bottomline="true">
27440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27441 \begin_inset Text
27442
27443 \begin_layout Standard
27444 eeprom
27445 \end_layout
27446
27447 \end_inset
27448 </cell>
27449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27450 \begin_inset Text
27451
27452 \begin_layout Standard
27453 0
27454 \end_layout
27455
27456 \end_inset
27457 </cell>
27458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27459 \begin_inset Text
27460
27461 \begin_layout Standard
27462 1
27463 \end_layout
27464
27465 \end_inset
27466 </cell>
27467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27468 \begin_inset Text
27469
27470 \begin_layout Standard
27471
27472 \family typewriter
27473 \shape slanted
27474 \emph on
27475 uuuuuu uuuuuuxx xxxxxxxx
27476 \end_layout
27477
27478 \end_inset
27479 </cell>
27480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27481 \begin_inset Text
27482
27483 \begin_layout Standard
27484 a 10-bit eeprom pointer in EEPROM memory
27485 \end_layout
27486
27487 \end_inset
27488 </cell>
27489 </row>
27490 <row bottomline="true">
27491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27492 \begin_inset Text
27493
27494 \begin_layout Standard
27495 (unimplemented)
27496 \end_layout
27497
27498 \end_inset
27499 </cell>
27500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27501 \begin_inset Text
27502
27503 \begin_layout Standard
27504 1
27505 \end_layout
27506
27507 \end_inset
27508 </cell>
27509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27510 \begin_inset Text
27511
27512 \begin_layout Standard
27513 1
27514 \end_layout
27515
27516 \end_inset
27517 </cell>
27518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27519 \begin_inset Text
27520
27521 \begin_layout Standard
27522
27523 \family typewriter
27524 \shape slanted
27525 \emph on
27526 xxxxxx xxxxxxxx xxxxxxxx
27527 \end_layout
27528
27529 \end_inset
27530 </cell>
27531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27532 \begin_inset Text
27533
27534 \begin_layout Standard
27535 unimplemented pointer type
27536 \end_layout
27537
27538 \end_inset
27539 </cell>
27540 </row>
27541 </lyxtabular>
27542
27543 \end_inset
27544
27545
27546 \end_layout
27547
27548 \begin_layout Standard
27549 Generic pointer are read and written with a set of library functions which
27550  read/write 1, 2, 3, 4 bytes.
27551 \end_layout
27552
27553 \begin_layout Subsection
27554 PIC16 C Libraries
27555 \end_layout
27556
27557 \begin_layout Subsubsection
27558 Standard I/O Streams
27559 \end_layout
27560
27561 \begin_layout Standard
27562 In the 
27563 \emph on
27564 stdio.h
27565 \emph default
27566  the type FILE is defined as:
27567 \end_layout
27568
27569 \begin_layout LyX-Code
27570 typedef char * FILE;
27571 \end_layout
27572
27573 \begin_layout Standard
27574 This type is the stream type implemented I/O in the PIC18F devices.
27575  Also the standard input and output streams are declared in stdio.h:
27576 \end_layout
27577
27578 \begin_layout LyX-Code
27579 extern FILE * stdin;
27580 \end_layout
27581
27582 \begin_layout LyX-Code
27583 extern FILE * stdout;
27584 \end_layout
27585
27586 \begin_layout Standard
27587 The FILE type is actually a generic pointer which defines one more type
27588  of generic pointers, the 
27589 \emph on
27590 stream 
27591 \emph default
27592 pointer.
27593  This new type has the format:
27594 \end_layout
27595
27596 \begin_layout Standard
27597 \align center
27598 \begin_inset Tabular
27599 <lyxtabular version="3" rows="2" columns="7">
27600 <features>
27601 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27602 <column alignment="center" valignment="top" width="0">
27603 <column alignment="center" valignment="top" leftline="true" width="0">
27604 <column alignment="center" valignment="top" leftline="true" width="0">
27605 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27606 <column alignment="center" valignment="top" width="0">
27607 <column alignment="left" valignment="top" rightline="true" width="0">
27608 <row topline="true" bottomline="true">
27609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27610 \begin_inset Text
27611
27612 \begin_layout Standard
27613 pointer type
27614 \end_layout
27615
27616 \end_inset
27617 </cell>
27618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27619 \begin_inset Text
27620
27621 \begin_layout Standard
27622 <7:6>
27623 \end_layout
27624
27625 \end_inset
27626 </cell>
27627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27628 \begin_inset Text
27629
27630 \begin_layout Standard
27631 <5>
27632 \end_layout
27633
27634 \end_inset
27635 </cell>
27636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27637 \begin_inset Text
27638
27639 \begin_layout Standard
27640 <4>
27641 \end_layout
27642
27643 \end_inset
27644 </cell>
27645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27646 \begin_inset Text
27647
27648 \begin_layout Standard
27649 <3:0>
27650 \end_layout
27651
27652 \end_inset
27653 </cell>
27654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27655 \begin_inset Text
27656
27657 \begin_layout Standard
27658 rest of the pointer
27659 \end_layout
27660
27661 \end_inset
27662 </cell>
27663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27664 \begin_inset Text
27665
27666 \begin_layout Standard
27667 descrption
27668 \end_layout
27669
27670 \end_inset
27671 </cell>
27672 </row>
27673 <row topline="true" bottomline="true">
27674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27675 \begin_inset Text
27676
27677 \begin_layout Standard
27678 stream
27679 \end_layout
27680
27681 \end_inset
27682 </cell>
27683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27684 \begin_inset Text
27685
27686 \begin_layout Standard
27687 00
27688 \end_layout
27689
27690 \end_inset
27691 </cell>
27692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27693 \begin_inset Text
27694
27695 \begin_layout Standard
27696 1
27697 \end_layout
27698
27699 \end_inset
27700 </cell>
27701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27702 \begin_inset Text
27703
27704 \begin_layout Standard
27705 0
27706 \end_layout
27707
27708 \end_inset
27709 </cell>
27710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27711 \begin_inset Text
27712
27713 \begin_layout Standard
27714 nnnn
27715 \end_layout
27716
27717 \end_inset
27718 </cell>
27719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27720 \begin_inset Text
27721
27722 \begin_layout Standard
27723
27724 \family typewriter
27725 \shape slanted
27726 \emph on
27727 uuuuuuuu uuuuuuuu
27728 \end_layout
27729
27730 \end_inset
27731 </cell>
27732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27733 \begin_inset Text
27734
27735 \begin_layout Standard
27736 upper byte high nubble is 0x2n, the rest are zeroes
27737 \end_layout
27738
27739 \end_inset
27740 </cell>
27741 </row>
27742 </lyxtabular>
27743
27744 \end_inset
27745
27746
27747 \end_layout
27748
27749 \begin_layout Standard
27750 Currently implemented there are 3 types of streams defined:
27751 \end_layout
27752
27753 \begin_layout Standard
27754 \align center
27755 \begin_inset Tabular
27756 <lyxtabular version="3" rows="4" columns="4">
27757 <features>
27758 <column alignment="center" valignment="top" leftline="true" width="0">
27759 <column alignment="center" valignment="top" leftline="true" width="0">
27760 <column alignment="center" valignment="top" leftline="true" width="0">
27761 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27762 <row topline="true" bottomline="true">
27763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27764 \begin_inset Text
27765
27766 \begin_layout Standard
27767 stream type
27768 \end_layout
27769
27770 \end_inset
27771 </cell>
27772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27773 \begin_inset Text
27774
27775 \begin_layout Standard
27776 value
27777 \end_layout
27778
27779 \end_inset
27780 </cell>
27781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27782 \begin_inset Text
27783
27784 \begin_layout Standard
27785 module
27786 \end_layout
27787
27788 \end_inset
27789 </cell>
27790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27791 \begin_inset Text
27792
27793 \begin_layout Standard
27794 description
27795 \end_layout
27796
27797 \end_inset
27798 </cell>
27799 </row>
27800 <row topline="true">
27801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27802 \begin_inset Text
27803
27804 \begin_layout Standard
27805 STREAM_USART
27806 \end_layout
27807
27808 \end_inset
27809 </cell>
27810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27811 \begin_inset Text
27812
27813 \begin_layout Standard
27814
27815 \family typewriter
27816 0x200000UL
27817 \end_layout
27818
27819 \end_inset
27820 </cell>
27821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27822 \begin_inset Text
27823
27824 \begin_layout Standard
27825 USART
27826 \end_layout
27827
27828 \end_inset
27829 </cell>
27830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27831 \begin_inset Text
27832
27833 \begin_layout Standard
27834 Writes/Reads characters via the USART peripheral
27835 \end_layout
27836
27837 \end_inset
27838 </cell>
27839 </row>
27840 <row topline="true">
27841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27842 \begin_inset Text
27843
27844 \begin_layout Standard
27845 STREAM_MSSP
27846 \end_layout
27847
27848 \end_inset
27849 </cell>
27850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27851 \begin_inset Text
27852
27853 \begin_layout Standard
27854
27855 \family typewriter
27856 0x210000UL
27857 \end_layout
27858
27859 \end_inset
27860 </cell>
27861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27862 \begin_inset Text
27863
27864 \begin_layout Standard
27865 MSSP
27866 \end_layout
27867
27868 \end_inset
27869 </cell>
27870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27871 \begin_inset Text
27872
27873 \begin_layout Standard
27874 Writes/Reads characters via the MSSP peripheral
27875 \end_layout
27876
27877 \end_inset
27878 </cell>
27879 </row>
27880 <row topline="true" bottomline="true">
27881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27882 \begin_inset Text
27883
27884 \begin_layout Standard
27885 STREAM_USER
27886 \end_layout
27887
27888 \end_inset
27889 </cell>
27890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27891 \begin_inset Text
27892
27893 \begin_layout Standard
27894
27895 \family typewriter
27896 0x2f0000UL
27897 \end_layout
27898
27899 \end_inset
27900 </cell>
27901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27902 \begin_inset Text
27903
27904 \begin_layout Standard
27905 (none)
27906 \end_layout
27907
27908 \end_inset
27909 </cell>
27910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27911 \begin_inset Text
27912
27913 \begin_layout Standard
27914 Writes/Reads characters via used defined functions
27915 \end_layout
27916
27917 \end_inset
27918 </cell>
27919 </row>
27920 </lyxtabular>
27921
27922 \end_inset
27923
27924
27925 \end_layout
27926
27927 \begin_layout Standard
27928 The stream identifiers are declared as macros in the stdio.h header.
27929 \end_layout
27930
27931 \begin_layout Standard
27932 In the libc library there exist the functions that are used to write to
27933  each of the above streams.
27934  These are
27935 \end_layout
27936
27937 \begin_layout Description
27938 _
27939 \begin_inset ERT
27940 status collapsed
27941
27942 \begin_layout Standard
27943
27944
27945 \backslash
27946 /
27947 \end_layout
27948
27949 \end_inset
27950
27951 _stream_usart_putchar writes a character at the USART stream
27952 \end_layout
27953
27954 \begin_layout Description
27955 _
27956 \begin_inset ERT
27957 status collapsed
27958
27959 \begin_layout Standard
27960
27961
27962 \backslash
27963 /
27964 \end_layout
27965
27966 \end_inset
27967
27968 _stream_mssp_putchar writes a character at the MSSP stream
27969 \end_layout
27970
27971 \begin_layout Description
27972 putchar dummy function.
27973  This writes a character to a user specified manner.
27974 \end_layout
27975
27976 \begin_layout Standard
27977 In order to increase performance 
27978 \emph on
27979 putchar 
27980 \emph default
27981 is declared in stdio.h as having its parameter in WREG (it has the wparam
27982  keyword).
27983  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27984  in a user-friendly way.
27985  
27986 \emph on
27987 arg
27988 \emph default
27989  is the name of the variable that holds the character to print.
27990  An example follows:
27991 \end_layout
27992
27993 \begin_layout LyX-Code
27994 #include <pic18fregs.h>
27995 \newline
27996 #include <stdio.h>
27997 \newline
27998
27999 \newline
28000 PUTCHAR( c )
28001 \end_layout
28002
28003 \begin_layout LyX-Code
28004 {
28005 \end_layout
28006
28007 \begin_layout LyX-Code
28008     PORTA = c;    /* dump character c to PORTA */
28009 \end_layout
28010
28011 \begin_layout LyX-Code
28012
28013 \newline
28014
28015 \newline
28016 void main(void)
28017 \end_layout
28018
28019 \begin_layout LyX-Code
28020 {
28021 \end_layout
28022
28023 \begin_layout LyX-Code
28024     stdout = STREAM_USER;    /* this is not necessary, since stdout points
28025 \end_layout
28026
28027 \begin_layout LyX-Code
28028                               * by default to STREAM_USER */
28029 \end_layout
28030
28031 \begin_layout LyX-Code
28032     printf (
28033 \begin_inset Quotes sld
28034 \end_inset
28035
28036 This is a printf test
28037 \backslash
28038 n
28039 \begin_inset Quotes srd
28040 \end_inset
28041
28042 );
28043 \end_layout
28044
28045 \begin_layout LyX-Code
28046 }
28047 \end_layout
28048
28049 \begin_layout LyX-Code
28050
28051 \end_layout
28052
28053 \begin_layout Subsubsection
28054 Printing functions
28055 \end_layout
28056
28057 \begin_layout Standard
28058 PIC16 contains an implementation of the printf-family of functions.
28059  There exist the following functions:
28060 \end_layout
28061
28062 \begin_layout LyX-Code
28063 extern unsigned int sprintf(char *buf, char *fmt, ...);
28064 \end_layout
28065
28066 \begin_layout LyX-Code
28067 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
28068 \end_layout
28069
28070 \begin_layout LyX-Code
28071
28072 \end_layout
28073
28074 \begin_layout LyX-Code
28075 extern unsigned int printf(char *fmt, ...);
28076 \end_layout
28077
28078 \begin_layout LyX-Code
28079 extern unsigned int vprintf(char *fmt, va_lista ap);
28080 \end_layout
28081
28082 \begin_layout LyX-Code
28083
28084 \end_layout
28085
28086 \begin_layout LyX-Code
28087 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
28088 \end_layout
28089
28090 \begin_layout LyX-Code
28091 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
28092 \end_layout
28093
28094 \begin_layout Standard
28095 For sprintf and vsprintf 
28096 \emph on
28097 buf 
28098 \emph default
28099 should normally be a data pointer where the resulting string will be placed.
28100  No range checking is done so the user should allocate the necessery buffer.
28101  For fprintf and vfprintf 
28102 \emph on
28103 fp
28104 \emph default
28105  should be a stream pointer (i.e.
28106  stdout, STREAM_MSSP, etc...).
28107 \end_layout
28108
28109 \begin_layout Subsubsection
28110 Signals
28111 \end_layout
28112
28113 \begin_layout Standard
28114 The PIC18F family of microcontrollers supports a number of interrupt sources.
28115  A list of these interrupts is shown in the following table:
28116 \end_layout
28117
28118 \begin_layout Standard
28119 \align center
28120 \begin_inset Tabular
28121 <lyxtabular version="3" rows="11" columns="4">
28122 <features>
28123 <column alignment="left" valignment="top" leftline="true" width="0">
28124 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28125 <column alignment="left" valignment="top" leftline="true" width="0">
28126 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28127 <row topline="true" bottomline="true">
28128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28129 \begin_inset Text
28130
28131 \begin_layout Standard
28132 signal name
28133 \end_layout
28134
28135 \end_inset
28136 </cell>
28137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28138 \begin_inset Text
28139
28140 \begin_layout Standard
28141 description
28142 \end_layout
28143
28144 \end_inset
28145 </cell>
28146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28147 \begin_inset Text
28148
28149 \begin_layout Standard
28150 signal name
28151 \end_layout
28152
28153 \end_inset
28154 </cell>
28155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28156 \begin_inset Text
28157
28158 \begin_layout Standard
28159 descritpion
28160 \end_layout
28161
28162 \end_inset
28163 </cell>
28164 </row>
28165 <row topline="true">
28166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28167 \begin_inset Text
28168
28169 \begin_layout Standard
28170 SIG_RB
28171 \end_layout
28172
28173 \end_inset
28174 </cell>
28175 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28176 \begin_inset Text
28177
28178 \begin_layout Standard
28179 PORTB change interrupt
28180 \end_layout
28181
28182 \end_inset
28183 </cell>
28184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28185 \begin_inset Text
28186
28187 \begin_layout Standard
28188 SIG_EE
28189 \end_layout
28190
28191 \end_inset
28192 </cell>
28193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28194 \begin_inset Text
28195
28196 \begin_layout Standard
28197 EEPROM/FLASH write complete interrupt
28198 \end_layout
28199
28200 \end_inset
28201 </cell>
28202 </row>
28203 <row topline="true">
28204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28205 \begin_inset Text
28206
28207 \begin_layout Standard
28208 SIG_INT0
28209 \end_layout
28210
28211 \end_inset
28212 </cell>
28213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28214 \begin_inset Text
28215
28216 \begin_layout Standard
28217 INT0 external interrupt
28218 \end_layout
28219
28220 \end_inset
28221 </cell>
28222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28223 \begin_inset Text
28224
28225 \begin_layout Standard
28226 SIG_BCOL
28227 \end_layout
28228
28229 \end_inset
28230 </cell>
28231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28232 \begin_inset Text
28233
28234 \begin_layout Standard
28235 Bus collision interrupt
28236 \end_layout
28237
28238 \end_inset
28239 </cell>
28240 </row>
28241 <row topline="true">
28242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28243 \begin_inset Text
28244
28245 \begin_layout Standard
28246 SIG_INT1
28247 \end_layout
28248
28249 \end_inset
28250 </cell>
28251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28252 \begin_inset Text
28253
28254 \begin_layout Standard
28255 INT1 external interrupt
28256 \end_layout
28257
28258 \end_inset
28259 </cell>
28260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28261 \begin_inset Text
28262
28263 \begin_layout Standard
28264 SIG_LVD
28265 \end_layout
28266
28267 \end_inset
28268 </cell>
28269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28270 \begin_inset Text
28271
28272 \begin_layout Standard
28273 Low voltage detect interrupt
28274 \end_layout
28275
28276 \end_inset
28277 </cell>
28278 </row>
28279 <row topline="true">
28280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28281 \begin_inset Text
28282
28283 \begin_layout Standard
28284 SIG_INT2
28285 \end_layout
28286
28287 \end_inset
28288 </cell>
28289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28290 \begin_inset Text
28291
28292 \begin_layout Standard
28293 INT2 external interrupt
28294 \end_layout
28295
28296 \end_inset
28297 </cell>
28298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28299 \begin_inset Text
28300
28301 \begin_layout Standard
28302 SIG_PSP
28303 \end_layout
28304
28305 \end_inset
28306 </cell>
28307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28308 \begin_inset Text
28309
28310 \begin_layout Standard
28311 Parallel slave port interrupt
28312 \end_layout
28313
28314 \end_inset
28315 </cell>
28316 </row>
28317 <row topline="true">
28318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28319 \begin_inset Text
28320
28321 \begin_layout Standard
28322 SIG_CCP1
28323 \end_layout
28324
28325 \end_inset
28326 </cell>
28327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28328 \begin_inset Text
28329
28330 \begin_layout Standard
28331 CCP1 module interrupt
28332 \end_layout
28333
28334 \end_inset
28335 </cell>
28336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28337 \begin_inset Text
28338
28339 \begin_layout Standard
28340 SIG_AD
28341 \end_layout
28342
28343 \end_inset
28344 </cell>
28345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28346 \begin_inset Text
28347
28348 \begin_layout Standard
28349 AD convertion complete interrupt
28350 \end_layout
28351
28352 \end_inset
28353 </cell>
28354 </row>
28355 <row topline="true">
28356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28357 \begin_inset Text
28358
28359 \begin_layout Standard
28360 SIG_CCP2
28361 \end_layout
28362
28363 \end_inset
28364 </cell>
28365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28366 \begin_inset Text
28367
28368 \begin_layout Standard
28369 CCP2 module interrupt
28370 \end_layout
28371
28372 \end_inset
28373 </cell>
28374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28375 \begin_inset Text
28376
28377 \begin_layout Standard
28378 SIG_RC
28379 \end_layout
28380
28381 \end_inset
28382 </cell>
28383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28384 \begin_inset Text
28385
28386 \begin_layout Standard
28387 USART receive interrupt
28388 \end_layout
28389
28390 \end_inset
28391 </cell>
28392 </row>
28393 <row topline="true">
28394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28395 \begin_inset Text
28396
28397 \begin_layout Standard
28398 SIG_TMR0
28399 \end_layout
28400
28401 \end_inset
28402 </cell>
28403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28404 \begin_inset Text
28405
28406 \begin_layout Standard
28407 TMR0 overflow interrupt
28408 \end_layout
28409
28410 \end_inset
28411 </cell>
28412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28413 \begin_inset Text
28414
28415 \begin_layout Standard
28416 SIG_TX
28417 \end_layout
28418
28419 \end_inset
28420 </cell>
28421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28422 \begin_inset Text
28423
28424 \begin_layout Standard
28425 USART transmit interrupt
28426 \end_layout
28427
28428 \end_inset
28429 </cell>
28430 </row>
28431 <row topline="true">
28432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28433 \begin_inset Text
28434
28435 \begin_layout Standard
28436 SIG_TMR1
28437 \end_layout
28438
28439 \end_inset
28440 </cell>
28441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28442 \begin_inset Text
28443
28444 \begin_layout Standard
28445 TMR1 overflow interrupt
28446 \end_layout
28447
28448 \end_inset
28449 </cell>
28450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28451 \begin_inset Text
28452
28453 \begin_layout Standard
28454 SIG_MSSP
28455 \end_layout
28456
28457 \end_inset
28458 </cell>
28459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28460 \begin_inset Text
28461
28462 \begin_layout Standard
28463 SSP receive/transmit interrupt
28464 \end_layout
28465
28466 \end_inset
28467 </cell>
28468 </row>
28469 <row topline="true">
28470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28471 \begin_inset Text
28472
28473 \begin_layout Standard
28474 SIG_TMR2
28475 \end_layout
28476
28477 \end_inset
28478 </cell>
28479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28480 \begin_inset Text
28481
28482 \begin_layout Standard
28483 TMR2 matches PR2 interrupt
28484 \end_layout
28485
28486 \end_inset
28487 </cell>
28488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28489 \begin_inset Text
28490
28491 \begin_layout Standard
28492
28493 \end_layout
28494
28495 \end_inset
28496 </cell>
28497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28498 \begin_inset Text
28499
28500 \begin_layout Standard
28501
28502 \end_layout
28503
28504 \end_inset
28505 </cell>
28506 </row>
28507 <row topline="true" bottomline="true">
28508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28509 \begin_inset Text
28510
28511 \begin_layout Standard
28512 SIG_TMR3
28513 \end_layout
28514
28515 \end_inset
28516 </cell>
28517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28518 \begin_inset Text
28519
28520 \begin_layout Standard
28521 TMR3 overflow interrupt
28522 \end_layout
28523
28524 \end_inset
28525 </cell>
28526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28527 \begin_inset Text
28528
28529 \begin_layout Standard
28530
28531 \end_layout
28532
28533 \end_inset
28534 </cell>
28535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28536 \begin_inset Text
28537
28538 \begin_layout Standard
28539
28540 \end_layout
28541
28542 \end_inset
28543 </cell>
28544 </row>
28545 </lyxtabular>
28546
28547 \end_inset
28548
28549
28550 \end_layout
28551
28552 \begin_layout Standard
28553 The prototypes for these names are defined in the header file 
28554 \emph on
28555 signal.h
28556 \emph default
28557  .
28558 \end_layout
28559
28560 \begin_layout Standard
28561 In order to simplify signal handling, a number of macros is provided:
28562 \end_layout
28563
28564 \begin_layout List
28565 \labelwidthstring 00.00.0000
28566 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28567  high priority interrupts.
28568  
28569 \emph on
28570 name
28571 \emph default
28572  is the function name to use.
28573 \end_layout
28574
28575 \begin_layout List
28576 \labelwidthstring 00.00.0000
28577 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28578  low priority interrupt.
28579  
28580 \emph on
28581 name
28582 \emph default
28583  is the function name to use.
28584 \end_layout
28585
28586 \begin_layout List
28587 \labelwidthstring 00.00.0000
28588 DEF_HANDLER(sig,handler) define a handler for signal 
28589 \emph on
28590 sig.
28591 \end_layout
28592
28593 \begin_layout List
28594 \labelwidthstring 00.00.0000
28595 END_DEF end the declaration of the dispatch table.
28596 \end_layout
28597
28598 \begin_layout Standard
28599 Additionally there are two more macros to simplify the declaration of the
28600  signal handler:
28601 \end_layout
28602
28603 \begin_layout List
28604 \labelwidthstring 00.00.0000
28605
28606 \series medium
28607 SIGHANDLER(handler) 
28608 \series default
28609 this declares the function prototype for the 
28610 \emph on
28611 handler
28612 \emph default
28613  function.
28614 \end_layout
28615
28616 \begin_layout List
28617 \labelwidthstring 00.00.0000
28618 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28619 \end_layout
28620
28621 \begin_layout Standard
28622 An example of using the macros above is shown below:
28623 \end_layout
28624
28625 \begin_layout LyX-Code
28626 #include <pic18fregs.h>
28627 \end_layout
28628
28629 \begin_layout LyX-Code
28630 #include <signal.h>
28631 \newline
28632
28633 \newline
28634 DEF_INTHIGH(high_int)
28635 \end_layout
28636
28637 \begin_layout LyX-Code
28638 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28639 \end_layout
28640
28641 \begin_layout LyX-Code
28642 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28643 \end_layout
28644
28645 \begin_layout LyX-Code
28646 END_DEF
28647 \newline
28648
28649 \newline
28650 SIGHANDLER(_tmr0_handler)
28651 \end_layout
28652
28653 \begin_layout LyX-Code
28654 {
28655 \end_layout
28656
28657 \begin_layout LyX-Code
28658   /* action to be taken when timer 0 overflows */
28659 \end_layout
28660
28661 \begin_layout LyX-Code
28662 }
28663 \newline
28664
28665 \newline
28666 SIGHANDLERNAKED(_bcol_handler)
28667 \end_layout
28668
28669 \begin_layout LyX-Code
28670 {
28671 \end_layout
28672
28673 \begin_layout LyX-Code
28674   _asm
28675 \end_layout
28676
28677 \begin_layout LyX-Code
28678     /* action to be taken when bus collision occurs */
28679 \end_layout
28680
28681 \begin_layout LyX-Code
28682     retfie
28683 \end_layout
28684
28685 \begin_layout LyX-Code
28686  _endasm;
28687 \end_layout
28688
28689 \begin_layout LyX-Code
28690 }
28691 \end_layout
28692
28693 \begin_layout Standard
28694
28695 \series bold
28696 NOTES:
28697 \series default
28698  Special care should be taken when using the above scheme:
28699 \end_layout
28700
28701 \begin_layout Itemize
28702 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28703 \end_layout
28704
28705 \begin_layout Itemize
28706 when declaring SIGHANDLERNAKED handler never forget to use 
28707 \emph on
28708 retfie
28709 \emph default
28710  for proper returning.
28711 \end_layout
28712
28713 \begin_layout Subsection
28714 PIC16 Port -- Tips
28715 \end_layout
28716
28717 \begin_layout Standard
28718 Here you can find some general tips for compiling programs with SDCC/pic16.
28719 \end_layout
28720
28721 \begin_layout Subsubsection
28722 Stack size
28723 \end_layout
28724
28725 \begin_layout Standard
28726 The default stack
28727 \begin_inset LatexCommand \index{PIC16!stack}
28728
28729 \end_inset
28730
28731  size (that is 64 bytes) probably is enough for many programs.
28732  One must take care that when there are many levels of function nesting,
28733  or there is excessive usage of stack, its size should be extended.
28734  An example of such a case is the printf/sprintf family of functions.
28735  If you encounter problems like not being able to print integers, then you
28736  need to set the stack size around the maximum (256 for small stack model).
28737  The following diagram shows what happens when calling printf to print an
28738  integer:
28739 \end_layout
28740
28741 \begin_layout LyX-Code
28742 printf () --> ltoa () --> ultoa () --> divschar ()
28743 \end_layout
28744
28745 \begin_layout Standard
28746 It is should be understood that stack is easily consumed when calling complicate
28747 d functions.
28748  Using command line arguments like -
28749 \begin_inset ERT
28750 status collapsed
28751
28752 \begin_layout Standard
28753
28754
28755 \backslash
28756 /
28757 \end_layout
28758
28759 \end_inset
28760
28761 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28762  stack frames.
28763  Other ways to reduce stack usage may exist.
28764 \end_layout
28765
28766 \begin_layout Subsection
28767 Known Bugs
28768 \end_layout
28769
28770 \begin_layout Standard
28771 The PIC16 Port currently does not pass SDCC's regression test
28772 \begin_inset LatexCommand \index{Regression test (PIC16)}
28773
28774 \end_inset
28775
28776  suite (see section 
28777 \begin_inset LatexCommand \ref{sec:Quality-control}
28778
28779 \end_inset
28780
28781 ) and thus the snapshot build regression tests for the PIC16 target are
28782  currently disabled for all hosts
28783 \emph on
28784 .
28785 \end_layout
28786
28787 \begin_layout Chapter
28788 Debugging
28789 \end_layout
28790
28791 \begin_layout Standard
28792 There are several approaches to debugging your code.
28793  This chapter is meant to show your options and to give detail on some of
28794  them:
28795 \newline
28796
28797 \newline
28798 When writing your code:
28799 \end_layout
28800
28801 \begin_layout Itemize
28802 write your code with debugging in mind (avoid duplicating code, put conceptually
28803  similar variables into structs, use structured code, have strategic points
28804  within your code where all variables are consistent, ...)
28805 \end_layout
28806
28807 \begin_layout Itemize
28808 run a syntax-checking tool like splint
28809 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28810
28811 \end_inset
28812
28813
28814 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28815
28816 \end_inset
28817
28818  (see -
28819 \begin_inset ERT
28820 status collapsed
28821
28822 \begin_layout Standard
28823
28824
28825 \backslash
28826 /
28827 \end_layout
28828
28829 \end_inset
28830
28831 -more-pedantic 
28832 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28833
28834 \end_inset
28835
28836 ) over the code.
28837 \end_layout
28838
28839 \begin_layout Itemize
28840 for the high level code use a C-compiler (like f.e.
28841  GCC) to compile run and debug the code on your host.
28842  See (see -
28843 \begin_inset ERT
28844 status collapsed
28845
28846 \begin_layout Standard
28847
28848
28849 \backslash
28850 /
28851 \end_layout
28852
28853 \end_inset
28854
28855 -more-pedantic 
28856 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28857
28858 \end_inset
28859
28860 ) on how to handle syntax extensions like __xdata, __at(), ...
28861  
28862 \end_layout
28863
28864 \begin_layout Itemize
28865 use another C-compiler to compile code for your target.
28866  Always an option but not recommended:) And not very likely to help you.
28867  If you seriously consider walking this path you should at least occasionally
28868  check portability of your code.
28869  Most commercial compiler vendors will offer an evaluation version so you
28870  can test compile your code or snippets of your code.
28871 \end_layout
28872
28873 \begin_layout Standard
28874 Debugging on a simulator:
28875 \end_layout
28876
28877 \begin_layout Itemize
28878 there is a separate section about SDCDB (section 
28879 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28880
28881 \end_inset
28882
28883 ) below.
28884 \end_layout
28885
28886 \begin_layout Itemize
28887 or (8051 specific) use a freeware/commercial simulator which interfaces
28888  to the AOMF
28889 \begin_inset LatexCommand \index{AOMF, AOMF51}
28890
28891 \end_inset
28892
28893  file (see 
28894 \begin_inset LatexCommand \ref{OMF file}
28895
28896 \end_inset
28897
28898 ) optionally generated by SDCC.
28899 \end_layout
28900
28901 \begin_layout Standard
28902 Debugging On-target: 
28903 \end_layout
28904
28905 \begin_layout Itemize
28906 use a MCU port pin to serially output debug data to the RS232 port of your
28907  host.
28908  You'll probably want some level shifting device typically involving a MAX232
28909  or similar IC.
28910  If the hardware serial port of the MCU is not available search for 'Software
28911  UART' in your favourite search machine.
28912 \end_layout
28913
28914 \begin_layout Itemize
28915 use an on-target monitor.
28916  In this context a monitor is a small program which usually accepts commands
28917  via a serial line and allows to set program counter, to single step through
28918  a program and read/write memory locations.
28919  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28920  
28921 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28922
28923 \end_inset
28924
28925 ).
28926 \end_layout
28927
28928 \begin_layout Itemize
28929 toggle MCU port pins at strategic points within your code and use an oscilloscop
28930 e.
28931  A 
28932 \emph on
28933 digital oscilloscope
28934 \emph default
28935
28936 \begin_inset LatexCommand \index{Oscilloscope}
28937
28938 \end_inset
28939
28940  with deep trace memory is really helpful especially if you have to debug
28941  a realtime application.
28942  If you need to monitor more pins than your oscilloscope provides you can
28943  sometimes get away with a small R-2R network.
28944  On a single channel oscilloscope you could f.e.
28945  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28946 k
28947 \begin_inset Formula $\Omega$
28948 \end_inset
28949
28950  resistor and the other one by a 5\InsetSpace ~
28951 k
28952 \begin_inset Formula $\Omega$
28953 \end_inset
28954
28955  resistor to the oscilloscope probe (check output drive capability of the
28956  pins you want to monitor).
28957  If you need to monitor many more pins a 
28958 \emph on
28959 logic analyzer
28960 \emph default
28961  will be handy.
28962 \end_layout
28963
28964 \begin_layout Itemize
28965 use an ICE (
28966 \emph on
28967 i
28968 \emph default
28969
28970 \emph on
28971 c
28972 \emph default
28973 ircuit 
28974 \emph on
28975 e
28976 \emph default
28977 mulator
28978 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28979
28980 \end_inset
28981
28982 ).
28983  Usually very expensive.
28984  And very nice to have too.
28985  And usually locks you (for years...) to the devices the ICE can emulate.
28986  
28987 \end_layout
28988
28989 \begin_layout Itemize
28990 use a remote debugger.
28991  In most 8-bit systems the symbol information is not available on the target,
28992  and a complete debugger is too bulky for the target system.
28993  Therefore usually a debugger on the host system connects to an on-target
28994  debugging stub which accepts only primitive commands.
28995  
28996 \newline
28997 Terms to enter into your favourite search engine could be 'remote debugging',
28998  'gdb stub' or 'inferior debugger'.
28999  (is there one?)
29000 \end_layout
29001
29002 \begin_layout Itemize
29003 use an on target hardware debugger.
29004  Some of the more modern MCUs include hardware support for setting break
29005  points and monitoring/changing variables by using dedicated hardware pins.
29006  This facility doesn't require additional code to run on the target and
29007  
29008 \emph on
29009 usually
29010 \emph default
29011  doesn't affect runtime behaviour until a breakpoint is hit.
29012  For the mcs51 most hardware debuggers use the AOMF
29013 \begin_inset LatexCommand \index{AOMF, AOMF51}
29014
29015 \end_inset
29016
29017  file (see 
29018 \begin_inset LatexCommand \ref{OMF file}
29019
29020 \end_inset
29021
29022 ) as input file.
29023  
29024 \end_layout
29025
29026 \begin_layout Standard
29027 Last not least:
29028 \end_layout
29029
29030 \begin_layout Itemize
29031 if you are not familiar with any of the following terms you're likely to
29032  run into problems rather sooner than later: 
29033 \emph on
29034 volatile
29035 \emph default
29036
29037 \emph on
29038 atomic
29039 \emph default
29040
29041 \emph on
29042 memory map
29043 \emph default
29044
29045 \emph on
29046 overlay
29047 \emph default
29048 .
29049  As an embedded programmer you 
29050 \emph on
29051 have
29052 \emph default
29053  to know them so why not look them up 
29054 \emph on
29055 before
29056 \emph default
29057  you have problems?)
29058 \end_layout
29059
29060 \begin_layout Itemize
29061 tell someone else about your problem (actually this is a surprisingly effective
29062  means to hunt down the bug even if the listener is not familiar with your
29063  environment).
29064  As 'failure to communicate' is probably one of the job-induced deformations
29065  of an embedded programmer this is highly encouraged.
29066 \end_layout
29067
29068 \begin_layout Section
29069 Debugging with SDCDB
29070 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
29071
29072 \end_inset
29073
29074
29075 \begin_inset LatexCommand \index{SDCDB (debugger)}
29076
29077 \end_inset
29078
29079  
29080 \end_layout
29081
29082 \begin_layout Standard
29083 SDCC is distributed with a source level debugger
29084 \begin_inset LatexCommand \index{Debugger}
29085
29086 \end_inset
29087
29088 .
29089  The debugger uses a command line interface, the command repertoire of the
29090  debugger has been kept as close to gdb
29091 \begin_inset LatexCommand \index{gdb}
29092
29093 \end_inset
29094
29095  (the GNU debugger) as possible.
29096  The configuration and build process is part of the standard compiler installati
29097 on, which also builds and installs the debugger in the target directory
29098  specified during configuration.
29099  The debugger allows you debug BOTH at the C source and at the ASM source
29100  level.
29101 \end_layout
29102
29103 \begin_layout Subsection
29104 Compiling for Debugging
29105 \end_layout
29106
29107 \begin_layout Standard
29108 The -
29109 \begin_inset ERT
29110 status collapsed
29111
29112 \begin_layout Standard
29113
29114
29115 \backslash
29116 /
29117 \end_layout
29118
29119 \end_inset
29120
29121 -debug
29122 \begin_inset LatexCommand \index{-\/-debug}
29123
29124 \end_inset
29125
29126  option must be specified for all files for which debug information is to
29127  be generated.
29128  The compiler generates a .adb file for each of these files.
29129  The linker creates the .cdb
29130 \begin_inset LatexCommand \index{<file>.cdb}
29131
29132 \end_inset
29133
29134  file from the .adb
29135 \begin_inset LatexCommand \index{<file>.adb}
29136
29137 \end_inset
29138
29139  files and the address information.
29140  This .cdb is used by the debugger.
29141 \end_layout
29142
29143 \begin_layout Subsection
29144 How the Debugger Works
29145 \end_layout
29146
29147 \begin_layout Standard
29148 When the -
29149 \begin_inset ERT
29150 status collapsed
29151
29152 \begin_layout Standard
29153
29154
29155 \backslash
29156 /
29157 \end_layout
29158
29159 \end_inset
29160
29161 -debug option is specified the compiler generates extra symbol information
29162  some of which are put into the assembler source and some are put into the
29163  .adb file.
29164  Then the linker creates the .cdb file from the individual .adb files with
29165  the address information for the symbols.
29166  The debugger reads the symbolic information generated by the compiler &
29167  the address information generated by the linker.
29168  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29169  execution is controlled by the debugger.
29170  When a command is issued for the debugger, it translates it into appropriate
29171  commands for the simulator.
29172  (Currently SDCDM only connects to the simulator but 
29173 \emph on
29174 newcdb
29175 \emph default
29176  at 
29177 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29178
29179 \end_inset
29180
29181  is an effort to connect directly to the hardware.) 
29182 \end_layout
29183
29184 \begin_layout Subsection
29185 Starting the Debugger SDCDB
29186 \end_layout
29187
29188 \begin_layout Standard
29189 The debugger can be started using the following command line.
29190  (Assume the file you are debugging has the file name foo).
29191 \newline
29192
29193 \newline
29194
29195 \family sans
29196 \series bold
29197 sdcdb foo
29198 \newline
29199
29200 \family default
29201 \series default
29202
29203 \newline
29204 The debugger will look for the following files.
29205 \end_layout
29206
29207 \begin_layout Itemize
29208 foo.c - the source file.
29209 \end_layout
29210
29211 \begin_layout Itemize
29212 foo.cdb - the debugger symbol information file.
29213 \end_layout
29214
29215 \begin_layout Itemize
29216 foo.ihx - the Intel hex format
29217 \begin_inset LatexCommand \index{Intel hex format}
29218
29219 \end_inset
29220
29221  object file.
29222 \end_layout
29223
29224 \begin_layout Subsection
29225 SDCDB Command Line Options
29226 \end_layout
29227
29228 \begin_layout Itemize
29229 -
29230 \begin_inset ERT
29231 status collapsed
29232
29233 \begin_layout Standard
29234
29235
29236 \backslash
29237 /
29238 \end_layout
29239
29240 \end_inset
29241
29242 -directory=<source file directory> this option can used to specify the directory
29243  search list.
29244  The debugger will look into the directory list specified for source, cdb
29245  & ihx files.
29246  The items in the directory list must be separated by ':', e.g.
29247  if the source files can be in the directories /home/src1 and /home/src2,
29248  the -
29249 \begin_inset ERT
29250 status collapsed
29251
29252 \begin_layout Standard
29253
29254
29255 \backslash
29256 /
29257 \end_layout
29258
29259 \end_inset
29260
29261 -directory option should be -
29262 \begin_inset ERT
29263 status collapsed
29264
29265 \begin_layout Standard
29266
29267
29268 \backslash
29269 /
29270 \end_layout
29271
29272 \end_inset
29273
29274 -directory=/home/src1:/home/src2.
29275  Note there can be no spaces in the option.
29276  
29277 \end_layout
29278
29279 \begin_layout Itemize
29280 -cd <directory> - change to the <directory>.
29281 \end_layout
29282
29283 \begin_layout Itemize
29284 -fullname - used by GUI front ends.
29285 \end_layout
29286
29287 \begin_layout Itemize
29288 -cpu <cpu-type> - this argument is passed to the simulator please see the
29289  simulator docs for details.
29290 \end_layout
29291
29292 \begin_layout Itemize
29293 -X <Clock frequency > this options is passed to the simulator please see
29294  the simulator docs for details.
29295 \end_layout
29296
29297 \begin_layout Itemize
29298 -s <serial port file> passed to simulator see the simulator docs for details.
29299 \end_layout
29300
29301 \begin_layout Itemize
29302 -S <serial in,out> passed to simulator see the simulator docs for details.
29303 \end_layout
29304
29305 \begin_layout Itemize
29306 -k <port number> passed to simulator see the simulator docs for details.
29307 \end_layout
29308
29309 \begin_layout Subsection
29310 SDCDB Debugger Commands
29311 \end_layout
29312
29313 \begin_layout Standard
29314 As mentioned earlier the command interface for the debugger has been deliberatel
29315 y kept as close the GNU debugger gdb, as possible.
29316  This will help the integration with existing graphical user interfaces
29317  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29318  If you use a graphical user interface for the debugger you can skip this
29319  section.
29320 \end_layout
29321
29322 \begin_layout Subsubsection*
29323 break [line | file:line | function | file:function]
29324 \end_layout
29325
29326 \begin_layout Standard
29327 Set breakpoint at specified line or function:
29328 \newline
29329
29330 \newline
29331
29332 \family sans
29333 \series bold
29334 sdcdb>break 100 
29335 \newline
29336 sdcdb>break foo.c:100
29337 \newline
29338 sdcdb>break funcfoo
29339 \newline
29340 sdcdb>break foo.c:funcfoo
29341 \end_layout
29342
29343 \begin_layout Subsubsection*
29344 clear [line | file:line | function | file:function ]
29345 \end_layout
29346
29347 \begin_layout Standard
29348 Clear breakpoint at specified line or function:
29349 \newline
29350
29351 \newline
29352
29353 \family sans
29354 \series bold
29355 sdcdb>clear 100
29356 \newline
29357 sdcdb>clear foo.c:100
29358 \newline
29359 sdcdb>clear funcfoo
29360 \newline
29361 sdcdb>clear foo.c:funcfoo
29362 \end_layout
29363
29364 \begin_layout Subsubsection*
29365 continue
29366 \end_layout
29367
29368 \begin_layout Standard
29369 Continue program being debugged, after breakpoint.
29370 \end_layout
29371
29372 \begin_layout Subsubsection*
29373 finish
29374 \end_layout
29375
29376 \begin_layout Standard
29377 Execute till the end of the current function.
29378 \end_layout
29379
29380 \begin_layout Subsubsection*
29381 delete [n]
29382 \end_layout
29383
29384 \begin_layout Standard
29385 Delete breakpoint number 'n'.
29386  If used without any option clear ALL user defined break points.
29387 \end_layout
29388
29389 \begin_layout Subsubsection*
29390 info [break | stack | frame | registers ]
29391 \end_layout
29392
29393 \begin_layout Itemize
29394 info break - list all breakpoints
29395 \end_layout
29396
29397 \begin_layout Itemize
29398 info stack - show the function call stack.
29399 \end_layout
29400
29401 \begin_layout Itemize
29402 info frame - show information about the current execution frame.
29403 \end_layout
29404
29405 \begin_layout Itemize
29406 info registers - show content of all registers.
29407 \end_layout
29408
29409 \begin_layout Subsubsection*
29410 step
29411 \end_layout
29412
29413 \begin_layout Standard
29414 Step program until it reaches a different source line.
29415  Note: pressing <return> repeats the last command.
29416 \end_layout
29417
29418 \begin_layout Subsubsection*
29419 next
29420 \end_layout
29421
29422 \begin_layout Standard
29423 Step program, proceeding through subroutine calls.
29424 \end_layout
29425
29426 \begin_layout Subsubsection*
29427 run
29428 \end_layout
29429
29430 \begin_layout Standard
29431 Start debugged program.
29432 \end_layout
29433
29434 \begin_layout Subsubsection*
29435 ptype variable 
29436 \end_layout
29437
29438 \begin_layout Standard
29439 Print type information of the variable.
29440 \end_layout
29441
29442 \begin_layout Subsubsection*
29443 print variable
29444 \end_layout
29445
29446 \begin_layout Standard
29447 print value of variable.
29448 \end_layout
29449
29450 \begin_layout Subsubsection*
29451 file filename
29452 \end_layout
29453
29454 \begin_layout Standard
29455 load the given file name.
29456  Note this is an alternate method of loading file for debugging.
29457 \end_layout
29458
29459 \begin_layout Subsubsection*
29460 frame
29461 \end_layout
29462
29463 \begin_layout Standard
29464 print information about current frame.
29465 \end_layout
29466
29467 \begin_layout Subsubsection*
29468 set srcmode
29469 \end_layout
29470
29471 \begin_layout Standard
29472 Toggle between C source & assembly source.
29473 \end_layout
29474
29475 \begin_layout Subsubsection*
29476 ! simulator command
29477 \end_layout
29478
29479 \begin_layout Standard
29480 Send the string following '!' to the simulator, the simulator response is
29481  displayed.
29482  Note the debugger does not interpret the command being sent to the simulator,
29483  so if a command like 'go' is sent the debugger can loose its execution
29484  context and may display incorrect values.
29485 \end_layout
29486
29487 \begin_layout Subsubsection*
29488 quit
29489 \end_layout
29490
29491 \begin_layout Standard
29492 "Watch me now.
29493  Iam going Down.
29494  My name is Bobby Brown"
29495 \end_layout
29496
29497 \begin_layout Subsection
29498 Interfacing SDCDB with DDD
29499 \end_layout
29500
29501 \begin_layout Standard
29502 \begin_inset Note Note
29503 status collapsed
29504
29505 \begin_layout Standard
29506 The screenshot was converted from png to eps with: 
29507 \begin_inset Quotes sld
29508 \end_inset
29509
29510 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29511 \begin_inset Quotes srd
29512 \end_inset
29513
29514  which produces a pretty compact eps file which is free from compression
29515  artifacts.
29516 \end_layout
29517
29518 \begin_layout Standard
29519 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29520  as this broke the build system on Sourceforge (pdf-file was broken.
29521  pdflatex does not accept eps files).
29522 \end_layout
29523
29524 \end_inset
29525
29526
29527 \end_layout
29528
29529 \begin_layout Standard
29530 The 
29531 \emph on
29532 p
29533 \emph default
29534 ortable 
29535 \emph on
29536 n
29537 \emph default
29538 etwork 
29539 \emph on
29540 g
29541 \emph default
29542 raphics File 
29543 \size footnotesize
29544
29545 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29546
29547 \end_inset
29548
29549
29550 \size default
29551  shows a screenshot of a debugging session with DDD
29552 \begin_inset LatexCommand \index{DDD (debugger)}
29553
29554 \end_inset
29555
29556  (Unix only) on a simulated 8032.
29557  The debugging session might not run as smoothly as the screenshot suggests.
29558  The debugger allows setting of breakpoints, displaying and changing variables,
29559  single stepping through C and assembler code.
29560  
29561 \newline
29562 The source was compiled with 
29563 \family sans
29564 \series bold
29565
29566 \newline
29567
29568 \newline
29569 sdcc -
29570 \family default
29571 \series default
29572
29573 \begin_inset ERT
29574 status collapsed
29575
29576 \begin_layout Standard
29577
29578
29579 \backslash
29580 /
29581 \end_layout
29582
29583 \end_inset
29584
29585
29586 \family sans
29587 \series bold
29588 -debug ddd_example.c
29589 \family default
29590 \series default
29591  
29592 \family sans
29593 \series bold
29594
29595 \newline
29596
29597 \family default
29598 \series default
29599
29600 \newline
29601 and DDD was invoked with 
29602 \family sans
29603 \series bold
29604
29605 \newline
29606
29607 \newline
29608 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29609 \end_layout
29610
29611 \begin_layout Standard
29612 \begin_inset Note Note
29613 status open
29614
29615 \begin_layout Standard
29616 Check that the double quotes or an apostroph within the command line survive
29617  the LyX tool chain.
29618  Previously the apostrophs got slanted in the PDF output so a cut and paste
29619  did not work.
29620 \end_layout
29621
29622 \end_inset
29623
29624
29625 \end_layout
29626
29627 \begin_layout Subsection
29628 Interfacing SDCDB with XEmacs
29629 \begin_inset LatexCommand \index{XEmacs}
29630
29631 \end_inset
29632
29633
29634 \begin_inset LatexCommand \index{Emacs}
29635
29636 \end_inset
29637
29638
29639 \end_layout
29640
29641 \begin_layout Standard
29642 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29643  sdcdb.el and sdcdbsrc.el.
29644  These two files can be found in the $(prefix)/bin directory after the installat
29645 ion is complete.
29646  These files need to be loaded into XEmacs for the interface to work.
29647  This can be done at XEmacs startup time by inserting the following into
29648  your '.xemacs' file (which can be found in your HOME directory): 
29649 \newline
29650
29651 \newline
29652
29653 \family typewriter
29654 (load-file sdcdbsrc.el) 
29655 \family default
29656
29657 \newline
29658
29659 \newline
29660 .xemacs is a lisp file so the () around the command is REQUIRED.
29661  The files can also be loaded dynamically while XEmacs is running, set the
29662  environment variable 'EMACSLOADPATH' to the installation bin directory
29663  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29664  To start the interface enter the following command: 
29665 \newline
29666
29667 \newline
29668
29669 \family sans
29670 \series bold
29671 ESC-x sdcdbsrc
29672 \family default
29673 \series default
29674
29675 \newline
29676
29677 \newline
29678 You will prompted to enter the file name to be debugged.
29679  
29680 \newline
29681
29682 \newline
29683 The command line options that are passed to the simulator directly are
29684  bound to default values in the file sdcdbsrc.el.
29685  The variables are listed below, these values maybe changed as required.
29686 \end_layout
29687
29688 \begin_layout Itemize
29689 sdcdbsrc-cpu-type '51
29690 \end_layout
29691
29692 \begin_layout Itemize
29693 sdcdbsrc-frequency '11059200
29694 \end_layout
29695
29696 \begin_layout Itemize
29697 sdcdbsrc-serial nil
29698 \end_layout
29699
29700 \begin_layout Standard
29701 The following is a list of key mapping for the debugger interface.
29702 \end_layout
29703
29704 \begin_layout Standard
29705 \InsetSpace ~
29706
29707 \family typewriter
29708
29709 \newline
29710 ;;\InsetSpace ~
29711 Current Listing :: 
29712 \newline
29713 ;;key\InsetSpace ~
29714 \InsetSpace ~
29715 \InsetSpace ~
29716 \InsetSpace ~
29717 \InsetSpace ~
29718 \InsetSpace ~
29719 \InsetSpace ~
29720 \InsetSpace ~
29721 \InsetSpace ~
29722 \InsetSpace ~
29723 \InsetSpace ~
29724 \InsetSpace ~
29725 \InsetSpace ~
29726 \InsetSpace ~
29727 binding\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 Comment 
29750 \newline
29751 ;;---\InsetSpace ~
29752 \InsetSpace ~
29753 \InsetSpace ~
29754 \InsetSpace ~
29755 \InsetSpace ~
29756 \InsetSpace ~
29757 \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 \InsetSpace ~
29773 \InsetSpace ~
29774 \InsetSpace ~
29775 \InsetSpace ~
29776 \InsetSpace ~
29777 \InsetSpace ~
29778 \InsetSpace ~
29779 \InsetSpace ~
29780 \InsetSpace ~
29781 \InsetSpace ~
29782 \InsetSpace ~
29783 \InsetSpace ~
29784 \InsetSpace ~
29785 \InsetSpace ~
29786 \InsetSpace ~
29787 -------
29788 \newline
29789 ;; 
29790 \newline
29791 ;;\InsetSpace ~
29792 n\InsetSpace ~
29793 \InsetSpace ~
29794 \InsetSpace ~
29795 \InsetSpace ~
29796 \InsetSpace ~
29797 \InsetSpace ~
29798 \InsetSpace ~
29799 \InsetSpace ~
29800 \InsetSpace ~
29801 \InsetSpace ~
29802 \InsetSpace ~
29803 \InsetSpace ~
29804 \InsetSpace ~
29805 \InsetSpace ~
29806 \InsetSpace ~
29807 sdcdb-next-fro
29808 m-src\InsetSpace ~
29809 \InsetSpace ~
29810 \InsetSpace ~
29811 \InsetSpace ~
29812 \InsetSpace ~
29813 \InsetSpace ~
29814 \InsetSpace ~
29815 \InsetSpace ~
29816 \InsetSpace ~
29817 \InsetSpace ~
29818 SDCDB next command 
29819 \newline
29820 ;;\InsetSpace ~
29821 b\InsetSpace ~
29822 \InsetSpace ~
29823 \InsetSpace ~
29824 \InsetSpace ~
29825 \InsetSpace ~
29826 \InsetSpace ~
29827 \InsetSpace ~
29828 \InsetSpace ~
29829 \InsetSpace ~
29830 \InsetSpace ~
29831 \InsetSpace ~
29832 \InsetSpace ~
29833 \InsetSpace ~
29834 \InsetSpace ~
29835 \InsetSpace ~
29836 sdcdb-back-from-src\InsetSpace ~
29837 \InsetSpace ~
29838 \InsetSpace ~
29839 \InsetSpace ~
29840 \InsetSpace ~
29841 \InsetSpace ~
29842 \InsetSpace ~
29843 \InsetSpace ~
29844 \InsetSpace ~
29845 \InsetSpace ~
29846 SDCDB back command 
29847 \newline
29848 ;;\InsetSpace ~
29849 c\InsetSpace ~
29850 \InsetSpace ~
29851 \InsetSpace ~
29852 \InsetSpace ~
29853 \InsetSpace ~
29854 \InsetSpace ~
29855 \InsetSpace ~
29856 \InsetSpace ~
29857 \InsetSpace ~
29858 \InsetSpace ~
29859 \InsetSpace ~
29860 \InsetSpace ~
29861 \InsetSpace ~
29862 \InsetSpace ~
29863 \InsetSpace ~
29864 sdcdb-cont-f
29865 rom-src\InsetSpace ~
29866 \InsetSpace ~
29867 \InsetSpace ~
29868 \InsetSpace ~
29869 \InsetSpace ~
29870 \InsetSpace ~
29871 \InsetSpace ~
29872 \InsetSpace ~
29873 \InsetSpace ~
29874 \InsetSpace ~
29875 SDCDB continue command
29876 \newline
29877 ;;\InsetSpace ~
29878 s\InsetSpace ~
29879 \InsetSpace ~
29880 \InsetSpace ~
29881 \InsetSpace ~
29882 \InsetSpace ~
29883 \InsetSpace ~
29884 \InsetSpace ~
29885 \InsetSpace ~
29886 \InsetSpace ~
29887 \InsetSpace ~
29888 \InsetSpace ~
29889 \InsetSpace ~
29890 \InsetSpace ~
29891 \InsetSpace ~
29892 \InsetSpace ~
29893 sdcdb-step-from-src\InsetSpace ~
29894 \InsetSpace ~
29895 \InsetSpace ~
29896 \InsetSpace ~
29897 \InsetSpace ~
29898 \InsetSpace ~
29899 \InsetSpace ~
29900 \InsetSpace ~
29901 \InsetSpace ~
29902 \InsetSpace ~
29903 SDCDB step command 
29904 \newline
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 sdcdb-w
29922 hatis-c-sexp\InsetSpace ~
29923 \InsetSpace ~
29924 \InsetSpace ~
29925 \InsetSpace ~
29926 \InsetSpace ~
29927 \InsetSpace ~
29928 \InsetSpace ~
29929 \InsetSpace ~
29930 \InsetSpace ~
29931 \InsetSpace ~
29932 SDCDB ptypecommand for data at 
29933 \newline
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 \InsetSpace ~
29947 \InsetSpace ~
29948 \InsetSpace ~
29949 \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 \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 \InsetSpace ~
29979 \InsetSpace ~
29980 \InsetSpace ~
29981 buffer point 
29982 \newline
29983 ;;\InsetSpace ~
29984 x\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 sdcdbsrc-delete\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 SDCD
30014 B Delete all breakpoints if no arg 
30015 \newline
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 \InsetSpace ~
30029 \InsetSpace ~
30030 \InsetSpace ~
30031 \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 \InsetSpace ~
30047 \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 \InsetSpace ~
30063 given or delete arg (C-u arg x) 
30064 \newline
30065 ;;\InsetSpace ~
30066 m\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 sdcdbsrc
30082 -frame\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 SDCDB Display current frame if no arg, 
30098 \newline
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 \InsetSpace ~
30112 \InsetSpace ~
30113 \InsetSpace ~
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 given or display frame arg
30147  
30148 \newline
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 \InsetSpace ~
30162 \InsetSpace ~
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 \InsetSpace ~
30180 \InsetSpace ~
30181 \InsetSpace ~
30182 \InsetSpace ~
30183 \InsetSpace ~
30184 \InsetSpace ~
30185 \InsetSpace ~
30186 \InsetSpace ~
30187 \InsetSpace ~
30188 \InsetSpace ~
30189 \InsetSpace ~
30190 \InsetSpace ~
30191 \InsetSpace ~
30192 \InsetSpace ~
30193 \InsetSpace ~
30194 \InsetSpace ~
30195 \InsetSpace ~
30196 buffer point 
30197 \newline
30198 ;;\InsetSpace ~
30199 !\InsetSpace ~
30200 \InsetSpace ~
30201 \InsetSpace ~
30202 \InsetSpace ~
30203 \InsetSpace ~
30204 \InsetSpace ~
30205 \InsetSpace ~
30206 \InsetSpace ~
30207 \InsetSpace ~
30208 \InsetSpace ~
30209 \InsetSpace ~
30210 \InsetSpace ~
30211 \InsetSpace ~
30212 \InsetSpace ~
30213 \InsetSpace ~
30214 sdcdbsrc-goto-sdcdb\InsetSpace ~
30215 \InsetSpace ~
30216 \InsetSpace ~
30217 \InsetSpace ~
30218 \InsetSpace ~
30219 \InsetSpace ~
30220 \InsetSpace ~
30221 \InsetSpace ~
30222 \InsetSpace ~
30223 \InsetSpace ~
30224 Goto the SDCDB output buffer 
30225 \newline
30226 ;;\InsetSpace ~
30227 p\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 sdcdb-prin
30243 t-c-sexp\InsetSpace ~
30244 \InsetSpace ~
30245 \InsetSpace ~
30246 \InsetSpace ~
30247 \InsetSpace ~
30248 \InsetSpace ~
30249 \InsetSpace ~
30250 \InsetSpace ~
30251 \InsetSpace ~
30252 \InsetSpace ~
30253 \InsetSpace ~
30254 SDCDB print command for data at 
30255 \newline
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 \InsetSpace ~
30269 \InsetSpace ~
30270 \InsetSpace ~
30271 \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 \InsetSpace ~
30287 \InsetSpace ~
30288 \InsetSpace ~
30289 \InsetSpace ~
30290 \InsetSpace ~
30291 \InsetSpace ~
30292 \InsetSpace ~
30293 \InsetSpace ~
30294 \InsetSpace ~
30295 \InsetSpace ~
30296 \InsetSpace ~
30297 \InsetSpace ~
30298 \InsetSpace ~
30299 \InsetSpace ~
30300 \InsetSpace ~
30301 \InsetSpace ~
30302 \InsetSpace ~
30303 buffer point 
30304 \newline
30305 ;;\InsetSpace ~
30306 g\InsetSpace ~
30307 \InsetSpace ~
30308 \InsetSpace ~
30309 \InsetSpace ~
30310 \InsetSpace ~
30311 \InsetSpace ~
30312 \InsetSpace ~
30313 \InsetSpace ~
30314 \InsetSpace ~
30315 \InsetSpace ~
30316 \InsetSpace ~
30317 \InsetSpace ~
30318 \InsetSpace ~
30319 \InsetSpace ~
30320 \InsetSpace ~
30321 sdcdbsrc-goto-sdcdb\InsetSpace ~
30322 \InsetSpace ~
30323 \InsetSpace ~
30324 \InsetSpace ~
30325 \InsetSpace ~
30326 \InsetSpace ~
30327 \InsetSpace ~
30328 \InsetSpace ~
30329 \InsetSpace ~
30330 \InsetSpace ~
30331 Got
30332 o the SDCDB output buffer 
30333 \newline
30334 ;;\InsetSpace ~
30335 t\InsetSpace ~
30336 \InsetSpace ~
30337 \InsetSpace ~
30338 \InsetSpace ~
30339 \InsetSpace ~
30340 \InsetSpace ~
30341 \InsetSpace ~
30342 \InsetSpace ~
30343 \InsetSpace ~
30344 \InsetSpace ~
30345 \InsetSpace ~
30346 \InsetSpace ~
30347 \InsetSpace ~
30348 \InsetSpace ~
30349 \InsetSpace ~
30350 sdcdbsrc-mode\InsetSpace ~
30351 \InsetSpace ~
30352 \InsetSpace ~
30353 \InsetSpace ~
30354 \InsetSpace ~
30355 \InsetSpace ~
30356 \InsetSpace ~
30357 \InsetSpace ~
30358 \InsetSpace ~
30359 \InsetSpace ~
30360 \InsetSpace ~
30361 \InsetSpace ~
30362 \InsetSpace ~
30363 \InsetSpace ~
30364 \InsetSpace ~
30365 \InsetSpace ~
30366 Toggles Sdcdbsrc mode (turns it
30367  off) 
30368 \newline
30369 ;; 
30370 \newline
30371 ;;\InsetSpace ~
30372 C-c\InsetSpace ~
30373 C-f\InsetSpace ~
30374 \InsetSpace ~
30375 \InsetSpace ~
30376 \InsetSpace ~
30377 \InsetSpace ~
30378 \InsetSpace ~
30379 \InsetSpace ~
30380 \InsetSpace ~
30381 \InsetSpace ~
30382 sdcdb-finish-from-src\InsetSpace ~
30383 \InsetSpace ~
30384 \InsetSpace ~
30385 \InsetSpace ~
30386 \InsetSpace ~
30387 \InsetSpace ~
30388 \InsetSpace ~
30389 \InsetSpace ~
30390 SDCDB finish command 
30391 \newline
30392 ;; 
30393 \newline
30394 ;;\InsetSpace ~
30395 C-x\InsetSpace ~
30396 SPC\InsetSpace ~
30397 \InsetSpace ~
30398 \InsetSpace ~
30399 \InsetSpace ~
30400 \InsetSpace ~
30401 \InsetSpace ~
30402 \InsetSpace ~
30403 \InsetSpace ~
30404 \InsetSpace ~
30405 sdcdb-brea
30406 k\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 \InsetSpace ~
30421 \InsetSpace ~
30422 \InsetSpace ~
30423 \InsetSpace ~
30424 Set break for line with point 
30425 \newline
30426 ;;\InsetSpace ~
30427 ESC\InsetSpace ~
30428 t\InsetSpace ~
30429 \InsetSpace ~
30430 \InsetSpace ~
30431 \InsetSpace ~
30432 \InsetSpace ~
30433 \InsetSpace ~
30434 \InsetSpace ~
30435 \InsetSpace ~
30436 \InsetSpace ~
30437 \InsetSpace ~
30438 \InsetSpace ~
30439 sdcdbsrc-mode\InsetSpace ~
30440 \InsetSpace ~
30441 \InsetSpace ~
30442 \InsetSpace ~
30443 \InsetSpace ~
30444 \InsetSpace ~
30445 \InsetSpace ~
30446 \InsetSpace ~
30447 \InsetSpace ~
30448 \InsetSpace ~
30449 \InsetSpace ~
30450 \InsetSpace ~
30451 \InsetSpace ~
30452 \InsetSpace ~
30453 \InsetSpace ~
30454 \InsetSpace ~
30455 Toggle Sdcdbsrc mode 
30456 \newline
30457 ;;\InsetSpace ~
30458 ESC\InsetSpace ~
30459 m\InsetSpace ~
30460 \InsetSpace ~
30461 \InsetSpace ~
30462 \InsetSpace ~
30463 \InsetSpace ~
30464 \InsetSpace ~
30465 \InsetSpace ~
30466 \InsetSpace ~
30467 \InsetSpace ~
30468 \InsetSpace ~
30469 \InsetSpace ~
30470 sdc
30471 dbsrc-srcmode\InsetSpace ~
30472 \InsetSpace ~
30473 \InsetSpace ~
30474 \InsetSpace ~
30475 \InsetSpace ~
30476 \InsetSpace ~
30477 \InsetSpace ~
30478 \InsetSpace ~
30479 \InsetSpace ~
30480 \InsetSpace ~
30481 \InsetSpace ~
30482 \InsetSpace ~
30483 \InsetSpace ~
30484 Toggle list mode 
30485 \newline
30486 ;; 
30487 \newline
30488
30489 \family default
30490
30491 \newpage
30492
30493 \end_layout
30494
30495 \begin_layout Chapter
30496 TIPS
30497 \end_layout
30498
30499 \begin_layout Standard
30500 Here are a few guidelines that will help the compiler generate more efficient
30501  code, some of the tips are specific to this compiler others are generally
30502  good programming practice.
30503 \end_layout
30504
30505 \begin_layout Itemize
30506 Use the smallest data type to represent your data-value.
30507  If it is known in advance that the value is going to be less than 256 then
30508  use an 'unsigned char' instead of a 'short' or 'int'.
30509  Please note, that ANSI C requires both signed and unsigned chars to be
30510  promoted to 'signed int'
30511 \begin_inset LatexCommand \index{promotion to signed int}
30512
30513 \end_inset
30514
30515
30516 \begin_inset Marginal
30517 status collapsed
30518
30519 \begin_layout Standard
30520
30521 \series bold
30522 \InsetSpace ~
30523 !
30524 \end_layout
30525
30526 \end_inset
30527
30528  before doing any operation.
30529  This promotion
30530 \begin_inset LatexCommand \index{type promotion}
30531
30532 \end_inset
30533
30534
30535 \begin_inset LatexCommand \label{type promotion}
30536
30537 \end_inset
30538
30539  can be omitted, if the result is the same.
30540  The effect of the promotion rules together with the sign-extension is often
30541  surprising:
30542 \end_layout
30543
30544 \begin_deeper
30545 \begin_layout Verse
30546
30547 \family typewriter
30548 unsigned char uc = 0xfe;
30549 \newline
30550 if (uc * uc < 0) /* this is true! */
30551 \newline
30552 {
30553 \newline
30554 \InsetSpace ~
30555 \InsetSpace ~
30556 \InsetSpace ~
30557 \InsetSpace ~
30558 ....
30559 \newline
30560 }
30561 \end_layout
30562
30563 \begin_layout Standard
30564
30565 \family typewriter
30566 uc * uc
30567 \family default
30568  is evaluated as 
30569 \family typewriter
30570 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30571 \family default
30572 .
30573  
30574 \newline
30575 Another one:
30576 \end_layout
30577
30578 \begin_layout Verse
30579
30580 \family typewriter
30581 (unsigned char) -12 / (signed char) -3 = ...
30582 \end_layout
30583
30584 \begin_layout Standard
30585 No, the result is not 4:
30586 \end_layout
30587
30588 \begin_layout Verse
30589
30590 \family typewriter
30591 (int) (unsigned char) -12 / (int) (signed char) -3 =
30592 \newline
30593 (int) (unsigned char)
30594  0xf4 / (int) (signed char) 0xfd =
30595 \newline
30596 (int) 0x00f4 / (int) 0xfffd =
30597 \newline
30598 (int) 0x00f4
30599  / (int) 0xfffd =
30600 \newline
30601 (int) 244 / (int) -3 =
30602 \newline
30603 (int) -81 = (int) 0xffaf;
30604 \end_layout
30605
30606 \begin_layout Standard
30607 Don't complain, that gcc gives you a different result.
30608  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30609  Therefore the results are different.
30610 \newline
30611 From 
30612 \begin_inset Quotes sld
30613 \end_inset
30614
30615 comp.lang.c FAQ
30616 \begin_inset Quotes srd
30617 \end_inset
30618
30619 :
30620 \end_layout
30621
30622 \begin_layout Quote
30623
30624 \emph on
30625 If well-defined overflow characteristics are important and negative values
30626  are not, or if you want to steer clear of sign-extension problems when
30627  manipulating bits or bytes, use one of the corresponding unsigned types.
30628  (Beware when mixing signed and unsigned values in expressions, though.)
30629 \newline
30630 Although
30631  character types (especially unsigned char) can be used as "tiny" integers,
30632  doing so is sometimes more trouble than it's worth, due to unpredictable
30633  sign extension and increased code size.
30634 \end_layout
30635
30636 \end_deeper
30637 \begin_layout Itemize
30638 Use unsigned when it is known in advance that the value is not going to
30639  be negative.
30640  This helps especially if you are doing division or multiplication, bit-shifting
30641  or are using an array index.
30642 \end_layout
30643
30644 \begin_layout Itemize
30645 NEVER jump into a LOOP.
30646 \end_layout
30647
30648 \begin_layout Itemize
30649 Declare the variables to be local
30650 \begin_inset LatexCommand \index{local variables}
30651
30652 \end_inset
30653
30654  whenever possible, especially loop control variables (induction).
30655 \end_layout
30656
30657 \begin_layout Itemize
30658 Have a look at the assembly listing to get a 
30659 \begin_inset Quotes sld
30660 \end_inset
30661
30662 feeling
30663 \begin_inset Quotes srd
30664 \end_inset
30665
30666  for the code generation.
30667 \end_layout
30668
30669 \begin_layout Section
30670 Porting code from or to other compilers
30671 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30672
30673 \end_inset
30674
30675
30676 \end_layout
30677
30678 \begin_layout Itemize
30679 check whether endianness of the compilers differs and adapt where needed.
30680 \end_layout
30681
30682 \begin_layout Itemize
30683 check the device specific header files
30684 \begin_inset LatexCommand \index{Header files}
30685
30686 \end_inset
30687
30688
30689 \begin_inset LatexCommand \index{Include files}
30690
30691 \end_inset
30692
30693  for compiler specific syntax.
30694  Eventually include the file <compiler.h
30695 \begin_inset LatexCommand \index{compiler.h (include file)}
30696
30697 \end_inset
30698
30699
30700 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30701
30702 \end_inset
30703
30704  to allow using common header files.
30705  (see f.e.
30706  cc2510fx.h 
30707 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30708
30709 \end_inset
30710
30711 ).
30712 \end_layout
30713
30714 \begin_layout Itemize
30715 check whether the startup code contains the correct initialization (watchdog,
30716  peripherals).
30717 \end_layout
30718
30719 \begin_layout Itemize
30720 check whether the sizes of short, int, long match.
30721 \end_layout
30722
30723 \begin_layout Itemize
30724 check if some 16 or 32 bit hardware registers require a specific addressing
30725  order (least significant or most significant byte first) and adapt if needed
30726  (
30727 \emph on
30728 first
30729 \emph default
30730  and 
30731 \emph on
30732 last
30733 \emph default
30734  relate to time and not to lower/upper memory location here, so this is
30735  
30736 \emph on
30737 not
30738 \emph default
30739  the same as endianness).
30740 \end_layout
30741
30742 \begin_layout Itemize
30743 check whether the keyword 
30744 \emph on
30745 volatile
30746 \emph default
30747  is used where needed.
30748  The compilers might differ in their optimization characteristics (as different
30749  versions of the same compiler might also use more clever optimizations
30750  this is good idea anyway).
30751  See section 
30752 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30753
30754 \end_inset
30755
30756 .
30757 \end_layout
30758
30759 \begin_layout Itemize
30760 check that the compilers are not told to supress warnings.
30761 \end_layout
30762
30763 \begin_layout Itemize
30764 check and convert compiler specific extensions (interrupts, memory areas,
30765  pragmas etc.).
30766 \end_layout
30767
30768 \begin_layout Itemize
30769 check for differences in type promotion.
30770  Especially check for math operations on 
30771 \family typewriter
30772 char
30773 \family default
30774  or 
30775 \family typewriter
30776 unsigned char
30777 \family default
30778  variables.
30779  For the sake of C99 compatibility SDCC will probably promote these to 
30780 \family typewriter
30781 int
30782 \family default
30783  more often than other compilers.
30784  Eventually insert explicit casts to 
30785 \family typewriter
30786 (char) 
30787 \family default
30788 or
30789 \family typewriter
30790  (unsigned char)
30791 \family default
30792 .
30793  Also check that the ~\InsetSpace ~
30794 operator
30795 \begin_inset LatexCommand \index{\~\/ Operator}
30796
30797 \end_inset
30798
30799  is not used on 
30800 \family typewriter
30801 bit
30802 \begin_inset LatexCommand \index{bit}
30803
30804 \end_inset
30805
30806
30807 \family default
30808  variables, use the !\InsetSpace ~
30809 operator instead.
30810  See sections 
30811 \begin_inset LatexCommand \ref{type promotion}
30812
30813 \end_inset
30814
30815  and 
30816 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30817
30818 \end_inset
30819
30820 .
30821 \end_layout
30822
30823 \begin_layout Itemize
30824 check the assembly code generated for interrupt routines (f.e.
30825  for calls to possibly non-reentrant library functions).
30826 \end_layout
30827
30828 \begin_layout Itemize
30829 check whether timing loops result in proper timing (or preferably consider
30830  a rewrite of the code with timer based delays instead).
30831 \end_layout
30832
30833 \begin_layout Itemize
30834 check for differences in printf parameters (some compilers push (va_arg
30835 \begin_inset LatexCommand \index{vararg, va\_arg}
30836
30837 \end_inset
30838
30839 ) char variables as 
30840 \family typewriter
30841 int
30842 \family default
30843  others push them as 
30844 \family typewriter
30845 char
30846 \family default
30847 .
30848  See section 
30849 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30850
30851 \end_inset
30852
30853 ).
30854 \end_layout
30855
30856 \begin_layout Itemize
30857 check the resulting memory map
30858 \begin_inset LatexCommand \index{Memory map}
30859
30860 \end_inset
30861
30862 .
30863  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30864 ly idata, pdata, xdata).
30865  Eventually check if unexpected library functions are included.
30866 \end_layout
30867
30868 \begin_layout Section
30869 Tools
30870 \begin_inset LatexCommand \index{Tools}
30871
30872 \end_inset
30873
30874  included in the distribution
30875 \end_layout
30876
30877 \begin_layout Standard
30878 \align left
30879 \begin_inset Tabular
30880 <lyxtabular version="3" rows="12" columns="3">
30881 <features>
30882 <column alignment="left" valignment="top" leftline="true" width="0pt">
30883 <column alignment="left" valignment="top" leftline="true" width="0pt">
30884 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30885 <row topline="true" bottomline="true">
30886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30887 \begin_inset Text
30888
30889 \begin_layout Standard
30890
30891 \series bold
30892 Name
30893 \end_layout
30894
30895 \end_inset
30896 </cell>
30897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30898 \begin_inset Text
30899
30900 \begin_layout Standard
30901
30902 \series bold
30903 Purpose
30904 \end_layout
30905
30906 \end_inset
30907 </cell>
30908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30909 \begin_inset Text
30910
30911 \begin_layout Standard
30912
30913 \series bold
30914 Directory
30915 \end_layout
30916
30917 \end_inset
30918 </cell>
30919 </row>
30920 <row topline="true">
30921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30922 \begin_inset Text
30923
30924 \begin_layout Standard
30925 uCsim
30926 \begin_inset LatexCommand \index{uCsim}
30927
30928 \end_inset
30929
30930
30931 \end_layout
30932
30933 \end_inset
30934 </cell>
30935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30936 \begin_inset Text
30937
30938 \begin_layout Standard
30939 Simulator for various architectures
30940 \end_layout
30941
30942 \end_inset
30943 </cell>
30944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30945 \begin_inset Text
30946
30947 \begin_layout Standard
30948 sdcc/sim/ucsim
30949 \end_layout
30950
30951 \end_inset
30952 </cell>
30953 </row>
30954 <row topline="true">
30955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30956 \begin_inset Text
30957
30958 \begin_layout Standard
30959 keil2sdcc.pl
30960 \end_layout
30961
30962 \end_inset
30963 </cell>
30964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30965 \begin_inset Text
30966
30967 \begin_layout Standard
30968 header file
30969 \begin_inset LatexCommand \index{Header files}
30970
30971 \end_inset
30972
30973
30974 \begin_inset LatexCommand \index{Include files}
30975
30976 \end_inset
30977
30978  conversion
30979 \end_layout
30980
30981 \end_inset
30982 </cell>
30983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30984 \begin_inset Text
30985
30986 \begin_layout Standard
30987 sdcc/support/scripts
30988 \end_layout
30989
30990 \end_inset
30991 </cell>
30992 </row>
30993 <row topline="true">
30994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30995 \begin_inset Text
30996
30997 \begin_layout Standard
30998 mh2h.c
30999 \end_layout
31000
31001 \end_inset
31002 </cell>
31003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31004 \begin_inset Text
31005
31006 \begin_layout Standard
31007 header file conversion
31008 \end_layout
31009
31010 \end_inset
31011 </cell>
31012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31013 \begin_inset Text
31014
31015 \begin_layout Standard
31016 sdcc/support/scripts
31017 \end_layout
31018
31019 \end_inset
31020 </cell>
31021 </row>
31022 <row topline="true">
31023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31024 \begin_inset Text
31025
31026 \begin_layout Standard
31027 as-gbz80
31028 \end_layout
31029
31030 \end_inset
31031 </cell>
31032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31033 \begin_inset Text
31034
31035 \begin_layout Standard
31036 Assembler
31037 \end_layout
31038
31039 \end_inset
31040 </cell>
31041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31042 \begin_inset Text
31043
31044 \begin_layout Standard
31045
31046 \family roman
31047 \series medium
31048 \shape up
31049 \size normal
31050 \emph off
31051 \bar no
31052 \noun off
31053 \color none
31054 sdcc/bin
31055 \end_layout
31056
31057 \end_inset
31058 </cell>
31059 </row>
31060 <row topline="true">
31061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31062 \begin_inset Text
31063
31064 \begin_layout Standard
31065 as-z80
31066 \end_layout
31067
31068 \end_inset
31069 </cell>
31070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31071 \begin_inset Text
31072
31073 \begin_layout Standard
31074 Assembler
31075 \end_layout
31076
31077 \end_inset
31078 </cell>
31079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31080 \begin_inset Text
31081
31082 \begin_layout Standard
31083
31084 \family roman
31085 \series medium
31086 \shape up
31087 \size normal
31088 \emph off
31089 \bar no
31090 \noun off
31091 \color none
31092 sdcc/bin
31093 \end_layout
31094
31095 \end_inset
31096 </cell>
31097 </row>
31098 <row topline="true">
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31100 \begin_inset Text
31101
31102 \begin_layout Standard
31103 asx8051
31104 \end_layout
31105
31106 \end_inset
31107 </cell>
31108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31109 \begin_inset Text
31110
31111 \begin_layout Standard
31112 Assembler
31113 \end_layout
31114
31115 \end_inset
31116 </cell>
31117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31118 \begin_inset Text
31119
31120 \begin_layout Standard
31121
31122 \family roman
31123 \series medium
31124 \shape up
31125 \size normal
31126 \emph off
31127 \bar no
31128 \noun off
31129 \color none
31130 sdcc/bin
31131 \end_layout
31132
31133 \end_inset
31134 </cell>
31135 </row>
31136 <row topline="true">
31137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31138 \begin_inset Text
31139
31140 \begin_layout Standard
31141 SDCDB
31142 \end_layout
31143
31144 \end_inset
31145 </cell>
31146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31147 \begin_inset Text
31148
31149 \begin_layout Standard
31150 Simulator
31151 \end_layout
31152
31153 \end_inset
31154 </cell>
31155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31156 \begin_inset Text
31157
31158 \begin_layout Standard
31159
31160 \family roman
31161 \series medium
31162 \shape up
31163 \size normal
31164 \emph off
31165 \bar no
31166 \noun off
31167 \color none
31168 sdcc/bin
31169 \end_layout
31170
31171 \end_inset
31172 </cell>
31173 </row>
31174 <row topline="true">
31175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31176 \begin_inset Text
31177
31178 \begin_layout Standard
31179 aslink
31180 \end_layout
31181
31182 \end_inset
31183 </cell>
31184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31185 \begin_inset Text
31186
31187 \begin_layout Standard
31188 Linker
31189 \end_layout
31190
31191 \end_inset
31192 </cell>
31193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31194 \begin_inset Text
31195
31196 \begin_layout Standard
31197
31198 \family roman
31199 \series medium
31200 \shape up
31201 \size normal
31202 \emph off
31203 \bar no
31204 \noun off
31205 \color none
31206 sdcc/bin
31207 \end_layout
31208
31209 \end_inset
31210 </cell>
31211 </row>
31212 <row topline="true">
31213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31214 \begin_inset Text
31215
31216 \begin_layout Standard
31217 link-z80
31218 \end_layout
31219
31220 \end_inset
31221 </cell>
31222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31223 \begin_inset Text
31224
31225 \begin_layout Standard
31226 Linker
31227 \end_layout
31228
31229 \end_inset
31230 </cell>
31231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31232 \begin_inset Text
31233
31234 \begin_layout Standard
31235
31236 \family roman
31237 \series medium
31238 \shape up
31239 \size normal
31240 \emph off
31241 \bar no
31242 \noun off
31243 \color none
31244 sdcc/bin
31245 \end_layout
31246
31247 \end_inset
31248 </cell>
31249 </row>
31250 <row topline="true">
31251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31252 \begin_inset Text
31253
31254 \begin_layout Standard
31255 link-gbz80
31256 \end_layout
31257
31258 \end_inset
31259 </cell>
31260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31261 \begin_inset Text
31262
31263 \begin_layout Standard
31264 Linker
31265 \end_layout
31266
31267 \end_inset
31268 </cell>
31269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31270 \begin_inset Text
31271
31272 \begin_layout Standard
31273
31274 \family roman
31275 \series medium
31276 \shape up
31277 \size normal
31278 \emph off
31279 \bar no
31280 \noun off
31281 \color none
31282 sdcc/bin
31283 \end_layout
31284
31285 \end_inset
31286 </cell>
31287 </row>
31288 <row topline="true" bottomline="true">
31289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31290 \begin_inset Text
31291
31292 \begin_layout Standard
31293 packihx
31294 \end_layout
31295
31296 \end_inset
31297 </cell>
31298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31299 \begin_inset Text
31300
31301 \begin_layout Standard
31302 Intel Hex packer 
31303 \begin_inset LatexCommand \index{packihx (tool)}
31304
31305 \end_inset
31306
31307
31308 \end_layout
31309
31310 \end_inset
31311 </cell>
31312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31313 \begin_inset Text
31314
31315 \begin_layout Standard
31316
31317 \family roman
31318 \series medium
31319 \shape up
31320 \size normal
31321 \emph off
31322 \bar no
31323 \noun off
31324 \color none
31325 sdcc/bin
31326 \end_layout
31327
31328 \end_inset
31329 </cell>
31330 </row>
31331 </lyxtabular>
31332
31333 \end_inset
31334
31335
31336 \newline
31337
31338 \end_layout
31339
31340 \begin_layout Section
31341 Documentation
31342 \begin_inset LatexCommand \index{Documentation}
31343
31344 \end_inset
31345
31346  included in the distribution
31347 \end_layout
31348
31349 \begin_layout Standard
31350 \align left
31351 \begin_inset Tabular
31352 <lyxtabular version="3" rows="10" columns="2">
31353 <features>
31354 <column alignment="block" valignment="top" leftline="true" width="40col%">
31355 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31356 <row topline="true" bottomline="true" endhead="true">
31357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31358 \begin_inset Text
31359
31360 \begin_layout Standard
31361
31362 \series bold
31363 Subject / Title
31364 \end_layout
31365
31366 \end_inset
31367 </cell>
31368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31369 \begin_inset Text
31370
31371 \begin_layout Standard
31372
31373 \series bold
31374 Filename / Where to get
31375 \end_layout
31376
31377 \end_inset
31378 </cell>
31379 </row>
31380 <row topline="true">
31381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31382 \begin_inset Text
31383
31384 \begin_layout Standard
31385 SDCC Compiler User Guide
31386 \end_layout
31387
31388 \end_inset
31389 </cell>
31390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31391 \begin_inset Text
31392
31393 \begin_layout Standard
31394 You're reading it right now
31395 \emph on
31396  \InsetSpace ~
31397 \InsetSpace ~
31398 \InsetSpace ~
31399
31400 \hfill
31401 online at:
31402 \emph default
31403
31404 \newline
31405
31406 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31407
31408 \end_inset
31409
31410
31411 \end_layout
31412
31413 \end_inset
31414 </cell>
31415 </row>
31416 <row topline="true">
31417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31418 \begin_inset Text
31419
31420 \begin_layout Standard
31421 Changelog of SDCC
31422 \end_layout
31423
31424 \end_inset
31425 </cell>
31426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31427 \begin_inset Text
31428
31429 \begin_layout Standard
31430 sdcc/Changelog
31431 \emph on
31432  \InsetSpace ~
31433 \InsetSpace ~
31434 \InsetSpace ~
31435
31436 \hfill
31437 online at:
31438 \emph default
31439
31440 \newline
31441
31442 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31443
31444 \end_inset
31445
31446
31447 \end_layout
31448
31449 \end_inset
31450 </cell>
31451 </row>
31452 <row topline="true">
31453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31454 \begin_inset Text
31455
31456 \begin_layout Standard
31457 ASXXXX
31458 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31459
31460 \end_inset
31461
31462
31463 \begin_inset LatexCommand \index{Assembler documentation}
31464
31465 \end_inset
31466
31467  Assemblers and
31468 \newline
31469 ASLINK
31470 \begin_inset LatexCommand \index{aslink}
31471
31472 \end_inset
31473
31474
31475 \begin_inset LatexCommand \index{Linker documentation}
31476
31477 \end_inset
31478
31479  Relocating Linker
31480 \end_layout
31481
31482 \end_inset
31483 </cell>
31484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31485 \begin_inset Text
31486
31487 \begin_layout Standard
31488 sdcc/as/doc/asxhtm.html 
31489 \emph on
31490 \InsetSpace ~
31491 \InsetSpace ~
31492 \InsetSpace ~
31493
31494 \hfill
31495 online at:
31496 \emph default
31497
31498 \newline
31499
31500 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31501
31502 \end_inset
31503
31504
31505 \end_layout
31506
31507 \end_inset
31508 </cell>
31509 </row>
31510 <row topline="true">
31511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31512 \begin_inset Text
31513
31514 \begin_layout Standard
31515 SDCC regression test
31516 \begin_inset LatexCommand \index{Regression test}
31517
31518 \end_inset
31519
31520
31521 \end_layout
31522
31523 \end_inset
31524 </cell>
31525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31526 \begin_inset Text
31527
31528 \begin_layout Standard
31529 sdcc/doc/test_suite_spec.pdf 
31530 \emph on
31531 \InsetSpace ~
31532 \InsetSpace ~
31533 \InsetSpace ~
31534
31535 \hfill
31536 online at:
31537 \emph default
31538
31539 \newline
31540
31541 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31542
31543 \end_inset
31544
31545
31546 \end_layout
31547
31548 \end_inset
31549 </cell>
31550 </row>
31551 <row topline="true">
31552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31553 \begin_inset Text
31554
31555 \begin_layout Standard
31556 Various notes
31557 \end_layout
31558
31559 \end_inset
31560 </cell>
31561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31562 \begin_inset Text
31563
31564 \begin_layout Standard
31565 sdcc/doc/* 
31566 \emph on
31567 \InsetSpace ~
31568 \InsetSpace ~
31569 \InsetSpace ~
31570
31571 \hfill
31572 online at:
31573 \emph default
31574
31575 \newline
31576
31577 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31578
31579 \end_inset
31580
31581
31582 \end_layout
31583
31584 \end_inset
31585 </cell>
31586 </row>
31587 <row topline="true">
31588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31589 \begin_inset Text
31590
31591 \begin_layout Standard
31592 Notes on debugging with SDCDB
31593 \begin_inset LatexCommand \index{SDCDB (debugger)}
31594
31595 \end_inset
31596
31597
31598 \end_layout
31599
31600 \end_inset
31601 </cell>
31602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31603 \begin_inset Text
31604
31605 \begin_layout Standard
31606 sdcc/debugger/README 
31607 \emph on
31608 \InsetSpace ~
31609 \InsetSpace ~
31610 \InsetSpace ~
31611
31612 \hfill
31613 online at
31614 \emph default
31615 :
31616 \newline
31617
31618 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31619
31620 \end_inset
31621
31622
31623 \end_layout
31624
31625 \end_inset
31626 </cell>
31627 </row>
31628 <row topline="true">
31629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31630 \begin_inset Text
31631
31632 \begin_layout Standard
31633 uCsim
31634 \begin_inset LatexCommand \index{uCsim}
31635
31636 \end_inset
31637
31638  Software simulator for microcontrollers
31639 \end_layout
31640
31641 \end_inset
31642 </cell>
31643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31644 \begin_inset Text
31645
31646 \begin_layout Standard
31647
31648 \family roman
31649 \series medium
31650 \shape up
31651 \size normal
31652 \emph off
31653 \bar no
31654 \noun off
31655 \color none
31656 sdcc/sim/ucsim/doc
31657 \family default
31658 \series default
31659 \shape default
31660 \size default
31661 \emph default
31662 \bar default
31663 \noun default
31664 /index.html 
31665 \emph on
31666 \InsetSpace ~
31667 \InsetSpace ~
31668 \InsetSpace ~
31669
31670 \hfill
31671 online at:
31672 \emph default
31673
31674 \newline
31675
31676 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31677
31678 \end_inset
31679
31680
31681 \end_layout
31682
31683 \end_inset
31684 </cell>
31685 </row>
31686 <row topline="true">
31687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31688 \begin_inset Text
31689
31690 \begin_layout Standard
31691 Temporary notes on the pic16
31692 \begin_inset LatexCommand \index{PIC16}
31693
31694 \end_inset
31695
31696  port
31697 \end_layout
31698
31699 \end_inset
31700 </cell>
31701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31702 \begin_inset Text
31703
31704 \begin_layout Standard
31705 sdcc/src/pic16/NOTES 
31706 \emph on
31707 \InsetSpace ~
31708 \InsetSpace ~
31709 \InsetSpace ~
31710
31711 \hfill
31712 online at:
31713 \newline
31714
31715 \emph default
31716
31717 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31718
31719 \end_inset
31720
31721
31722 \end_layout
31723
31724 \end_inset
31725 </cell>
31726 </row>
31727 <row topline="true" bottomline="true">
31728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31729 \begin_inset Text
31730
31731 \begin_layout Standard
31732 SDCC internal documentation (debugging file format)
31733 \end_layout
31734
31735 \end_inset
31736 </cell>
31737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31738 \begin_inset Text
31739
31740 \begin_layout Standard
31741 sdcc/doc/
31742 \family roman
31743 \series medium
31744 \shape up
31745 \size normal
31746 \emph off
31747 \bar no
31748 \noun off
31749 \color none
31750 cdbfileformat.pd
31751 \family default
31752 \series default
31753 \shape default
31754 \size default
31755 \emph default
31756 \bar default
31757 \noun default
31758 f
31759 \emph on
31760  \InsetSpace ~
31761 \InsetSpace ~
31762 \InsetSpace ~
31763
31764 \hfill
31765 online at:
31766 \emph default
31767
31768 \newline
31769
31770 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31771
31772 \end_inset
31773
31774
31775 \end_layout
31776
31777 \end_inset
31778 </cell>
31779 </row>
31780 </lyxtabular>
31781
31782 \end_inset
31783
31784
31785 \newline
31786
31787 \end_layout
31788
31789 \begin_layout Section
31790 Related open source tools
31791 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31792
31793 \end_inset
31794
31795
31796 \begin_inset LatexCommand \index{Related tools}
31797
31798 \end_inset
31799
31800
31801 \end_layout
31802
31803 \begin_layout Standard
31804 \align left
31805 \begin_inset Tabular
31806 <lyxtabular version="3" rows="16" columns="3">
31807 <features>
31808 <column alignment="left" valignment="top" leftline="true" width="0pt">
31809 <column alignment="block" valignment="top" leftline="true" width="30line%">
31810 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31811 <row topline="true" bottomline="true">
31812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31813 \begin_inset Text
31814
31815 \begin_layout Standard
31816
31817 \series bold
31818 Name
31819 \end_layout
31820
31821 \end_inset
31822 </cell>
31823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31824 \begin_inset Text
31825
31826 \begin_layout Standard
31827
31828 \series bold
31829 Purpose
31830 \end_layout
31831
31832 \end_inset
31833 </cell>
31834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31835 \begin_inset Text
31836
31837 \begin_layout Standard
31838
31839 \series bold
31840 Where to get
31841 \end_layout
31842
31843 \end_inset
31844 </cell>
31845 </row>
31846 <row topline="true">
31847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31848 \begin_inset Text
31849
31850 \begin_layout Standard
31851 gpsim
31852 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31853
31854 \end_inset
31855
31856
31857 \end_layout
31858
31859 \end_inset
31860 </cell>
31861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31862 \begin_inset Text
31863
31864 \begin_layout Standard
31865 PIC simulator
31866 \end_layout
31867
31868 \end_inset
31869 </cell>
31870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31871 \begin_inset Text
31872
31873 \begin_layout Standard
31874 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31875
31876 \end_inset
31877
31878
31879 \end_layout
31880
31881 \end_inset
31882 </cell>
31883 </row>
31884 <row topline="true">
31885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31886 \begin_inset Text
31887
31888 \begin_layout Standard
31889 gputils
31890 \begin_inset LatexCommand \index{gputils (pic tools)}
31891
31892 \end_inset
31893
31894
31895 \end_layout
31896
31897 \end_inset
31898 </cell>
31899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31900 \begin_inset Text
31901
31902 \begin_layout Standard
31903 GNU PIC utilities
31904 \end_layout
31905
31906 \end_inset
31907 </cell>
31908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31909 \begin_inset Text
31910
31911 \begin_layout Standard
31912 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31913
31914 \end_inset
31915
31916
31917 \end_layout
31918
31919 \end_inset
31920 </cell>
31921 </row>
31922 <row topline="true">
31923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31924 \begin_inset Text
31925
31926 \begin_layout Standard
31927 flP5
31928 \end_layout
31929
31930 \end_inset
31931 </cell>
31932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31933 \begin_inset Text
31934
31935 \begin_layout Standard
31936 PIC programmer
31937 \end_layout
31938
31939 \end_inset
31940 </cell>
31941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31942 \begin_inset Text
31943
31944 \begin_layout Standard
31945 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31946
31947 \end_inset
31948
31949
31950 \end_layout
31951
31952 \end_inset
31953 </cell>
31954 </row>
31955 <row topline="true">
31956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31957 \begin_inset Text
31958
31959 \begin_layout Standard
31960 ec2drv/newcdb
31961 \end_layout
31962
31963 \end_inset
31964 </cell>
31965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31966 \begin_inset Text
31967
31968 \begin_layout Standard
31969 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31970  (Unix only)
31971 \end_layout
31972
31973 \end_inset
31974 </cell>
31975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31976 \begin_inset Text
31977
31978 \begin_layout Standard
31979 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31980
31981 \end_inset
31982
31983
31984 \end_layout
31985
31986 \end_inset
31987 </cell>
31988 </row>
31989 <row topline="true">
31990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31991 \begin_inset Text
31992
31993 \begin_layout Standard
31994 indent
31995 \begin_inset LatexCommand \index{indent (source formatting tool)}
31996
31997 \end_inset
31998
31999
32000 \end_layout
32001
32002 \end_inset
32003 </cell>
32004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32005 \begin_inset Text
32006
32007 \begin_layout Standard
32008 Formats C source - Master of the white spaces
32009 \end_layout
32010
32011 \end_inset
32012 </cell>
32013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32014 \begin_inset Text
32015
32016 \begin_layout Standard
32017 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
32018
32019 \end_inset
32020
32021
32022 \end_layout
32023
32024 \end_inset
32025 </cell>
32026 </row>
32027 <row topline="true">
32028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32029 \begin_inset Text
32030
32031 \begin_layout Standard
32032 srecord
32033 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
32034
32035 \end_inset
32036
32037
32038 \end_layout
32039
32040 \end_inset
32041 </cell>
32042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32043 \begin_inset Text
32044
32045 \begin_layout Standard
32046 Object file conversion, checksumming, ...
32047 \end_layout
32048
32049 \end_inset
32050 </cell>
32051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32052 \begin_inset Text
32053
32054 \begin_layout Standard
32055 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
32056
32057 \end_inset
32058
32059
32060 \end_layout
32061
32062 \end_inset
32063 </cell>
32064 </row>
32065 <row topline="true">
32066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32067 \begin_inset Text
32068
32069 \begin_layout Standard
32070 objdump
32071 \begin_inset LatexCommand \index{objdump (tool)}
32072
32073 \end_inset
32074
32075
32076 \end_layout
32077
32078 \end_inset
32079 </cell>
32080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32081 \begin_inset Text
32082
32083 \begin_layout Standard
32084 Object file conversion, ...
32085 \end_layout
32086
32087 \end_inset
32088 </cell>
32089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32090 \begin_inset Text
32091
32092 \begin_layout Standard
32093 Part of binutils (should be there anyway)
32094 \end_layout
32095
32096 \end_inset
32097 </cell>
32098 </row>
32099 <row topline="true">
32100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32101 \begin_inset Text
32102
32103 \begin_layout Standard
32104 cmon51
32105 \end_layout
32106
32107 \end_inset
32108 </cell>
32109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32110 \begin_inset Text
32111
32112 \begin_layout Standard
32113 8051 monitor (hex up-/download, single step, disassemble)
32114 \end_layout
32115
32116 \end_inset
32117 </cell>
32118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32119 \begin_inset Text
32120
32121 \begin_layout Standard
32122 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
32123
32124 \end_inset
32125
32126
32127 \end_layout
32128
32129 \end_inset
32130 </cell>
32131 </row>
32132 <row topline="true">
32133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32134 \begin_inset Text
32135
32136 \begin_layout Standard
32137 doxygen
32138 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32139
32140 \end_inset
32141
32142
32143 \end_layout
32144
32145 \end_inset
32146 </cell>
32147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32148 \begin_inset Text
32149
32150 \begin_layout Standard
32151 Source code documentation system
32152 \end_layout
32153
32154 \end_inset
32155 </cell>
32156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32157 \begin_inset Text
32158
32159 \begin_layout Standard
32160 \begin_inset LatexCommand \url{http://www.doxygen.org}
32161
32162 \end_inset
32163
32164
32165 \end_layout
32166
32167 \end_inset
32168 </cell>
32169 </row>
32170 <row topline="true">
32171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32172 \begin_inset Text
32173
32174 \begin_layout Standard
32175 kdevelop
32176 \end_layout
32177
32178 \end_inset
32179 </cell>
32180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32181 \begin_inset Text
32182
32183 \begin_layout Standard
32184 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32185 \end_layout
32186
32187 \end_inset
32188 </cell>
32189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32190 \begin_inset Text
32191
32192 \begin_layout Standard
32193 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32194
32195 \end_inset
32196
32197
32198 \end_layout
32199
32200 \end_inset
32201 </cell>
32202 </row>
32203 <row topline="true">
32204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32205 \begin_inset Text
32206
32207 \begin_layout Standard
32208 paulmon
32209 \end_layout
32210
32211 \end_inset
32212 </cell>
32213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32214 \begin_inset Text
32215
32216 \begin_layout Standard
32217 8051 monitor (hex up-/download, single step, disassemble)
32218 \end_layout
32219
32220 \end_inset
32221 </cell>
32222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32223 \begin_inset Text
32224
32225 \begin_layout Standard
32226 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32227
32228 \end_inset
32229
32230
32231 \end_layout
32232
32233 \end_inset
32234 </cell>
32235 </row>
32236 <row topline="true">
32237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32238 \begin_inset Text
32239
32240 \begin_layout Standard
32241 splint
32242 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32243
32244 \end_inset
32245
32246
32247 \end_layout
32248
32249 \end_inset
32250 </cell>
32251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32252 \begin_inset Text
32253
32254 \begin_layout Standard
32255 Statically checks c sources (see 
32256 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32257
32258 \end_inset
32259
32260 )
32261 \end_layout
32262
32263 \end_inset
32264 </cell>
32265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32266 \begin_inset Text
32267
32268 \begin_layout Standard
32269 \begin_inset LatexCommand \url{http://www.splint.org}
32270
32271 \end_inset
32272
32273
32274 \end_layout
32275
32276 \end_inset
32277 </cell>
32278 </row>
32279 <row topline="true" bottomline="true">
32280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32281 \begin_inset Text
32282
32283 \begin_layout Standard
32284 ddd
32285 \begin_inset LatexCommand \index{DDD (debugger)}
32286
32287 \end_inset
32288
32289
32290 \end_layout
32291
32292 \end_inset
32293 </cell>
32294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32295 \begin_inset Text
32296
32297 \begin_layout Standard
32298 Debugger, serves nicely as GUI to SDCDB
32299 \begin_inset LatexCommand \index{SDCDB (debugger)}
32300
32301 \end_inset
32302
32303  (Unix only)
32304 \end_layout
32305
32306 \end_inset
32307 </cell>
32308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32309 \begin_inset Text
32310
32311 \begin_layout Standard
32312 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32313
32314 \end_inset
32315
32316
32317 \end_layout
32318
32319 \end_inset
32320 </cell>
32321 </row>
32322 <row bottomline="true">
32323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32324 \begin_inset Text
32325
32326 \begin_layout Standard
32327 d52
32328 \begin_inset LatexCommand \index{d52}
32329
32330 \end_inset
32331
32332
32333 \begin_inset LatexCommand \index{d52 (disassembler)}
32334
32335 \end_inset
32336
32337
32338 \end_layout
32339
32340 \end_inset
32341 </cell>
32342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32343 \begin_inset Text
32344
32345 \begin_layout Standard
32346 Disassembler, can count instruction cycles
32347 \begin_inset LatexCommand \index{instruction cycles (count)}
32348
32349 \end_inset
32350
32351 , use with options -pnd
32352 \end_layout
32353
32354 \end_inset
32355 </cell>
32356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32357 \begin_inset Text
32358
32359 \begin_layout Standard
32360 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32361
32362 \end_inset
32363
32364
32365 \end_layout
32366
32367 \end_inset
32368 </cell>
32369 </row>
32370 <row bottomline="true">
32371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32372 \begin_inset Text
32373
32374 \begin_layout Standard
32375 cmake
32376 \begin_inset LatexCommand \index{cmake}
32377
32378 \end_inset
32379
32380
32381 \end_layout
32382
32383 \end_inset
32384 </cell>
32385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32386 \begin_inset Text
32387
32388 \begin_layout Standard
32389 Cross platform build system, generates Makefiles
32390 \begin_inset LatexCommand \index{Makefile}
32391
32392 \end_inset
32393
32394  and project workspaces
32395 \begin_inset LatexCommand \index{project workspace}
32396
32397 \end_inset
32398
32399
32400 \end_layout
32401
32402 \end_inset
32403 </cell>
32404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32405 \begin_inset Text
32406
32407 \begin_layout Standard
32408 \begin_inset LatexCommand \url{http://www.cmake.org}
32409
32410 \end_inset
32411
32412  \InsetSpace ~
32413 \InsetSpace ~
32414 \InsetSpace ~
32415 \InsetSpace ~
32416 and a dedicated wiki entry: 
32417 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32418
32419 \end_inset
32420
32421
32422 \end_layout
32423
32424 \end_inset
32425 </cell>
32426 </row>
32427 </lyxtabular>
32428
32429 \end_inset
32430
32431
32432 \newline
32433
32434 \end_layout
32435
32436 \begin_layout Section
32437 Related documentation / recommended reading
32438 \end_layout
32439
32440 \begin_layout Standard
32441 \align left
32442 \begin_inset Tabular
32443 <lyxtabular version="3" rows="7" columns="3">
32444 <features>
32445 <column alignment="left" valignment="top" leftline="true" width="0pt">
32446 <column alignment="left" valignment="top" leftline="true" width="0">
32447 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32448 <row topline="true" bottomline="true">
32449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32450 \begin_inset Text
32451
32452 \begin_layout Standard
32453
32454 \series bold
32455 Name
32456 \end_layout
32457
32458 \end_inset
32459 </cell>
32460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32461 \begin_inset Text
32462
32463 \begin_layout Standard
32464
32465 \series bold
32466 Subject / Title
32467 \end_layout
32468
32469 \end_inset
32470 </cell>
32471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32472 \begin_inset Text
32473
32474 \begin_layout Standard
32475
32476 \series bold
32477 Where to get
32478 \end_layout
32479
32480 \end_inset
32481 </cell>
32482 </row>
32483 <row topline="true">
32484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32485 \begin_inset Text
32486
32487 \begin_layout Standard
32488
32489 \family roman
32490 \series medium
32491 \shape up
32492 \size normal
32493 \emph off
32494 \bar no
32495 \noun off
32496 \color none
32497 c-refcard.pdf
32498 \end_layout
32499
32500 \end_inset
32501 </cell>
32502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32503 \begin_inset Text
32504
32505 \begin_layout Standard
32506 C Reference Card
32507 \begin_inset LatexCommand \index{C Reference card}
32508
32509 \end_inset
32510
32511 , 2 pages
32512 \end_layout
32513
32514 \end_inset
32515 </cell>
32516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32517 \begin_inset Text
32518
32519 \begin_layout Standard
32520 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32521
32522 \end_inset
32523
32524
32525 \end_layout
32526
32527 \end_inset
32528 </cell>
32529 </row>
32530 <row topline="true">
32531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32532 \begin_inset Text
32533
32534 \begin_layout Standard
32535 c-faq
32536 \end_layout
32537
32538 \end_inset
32539 </cell>
32540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32541 \begin_inset Text
32542
32543 \begin_layout Standard
32544 C-FAQ
32545 \begin_inset LatexCommand \index{C FAQ}
32546
32547 \end_inset
32548
32549
32550 \end_layout
32551
32552 \end_inset
32553 </cell>
32554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32555 \begin_inset Text
32556
32557 \begin_layout Standard
32558 \begin_inset LatexCommand \url{http://www.c-faq.com}
32559
32560 \end_inset
32561
32562
32563 \end_layout
32564
32565 \end_inset
32566 </cell>
32567 </row>
32568 <row topline="true">
32569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32570 \begin_inset Text
32571
32572 \begin_layout Standard
32573 ISO/IEC 9899:TC2
32574 \end_layout
32575
32576 \end_inset
32577 </cell>
32578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32579 \begin_inset Text
32580
32581 \begin_layout Standard
32582 \begin_inset Quotes sld
32583 \end_inset
32584
32585 C-Standard
32586 \begin_inset Quotes srd
32587 \end_inset
32588
32589
32590 \end_layout
32591
32592 \end_inset
32593 </cell>
32594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32595 \begin_inset Text
32596
32597 \begin_layout Standard
32598
32599 \size footnotesize
32600 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32601
32602 \end_inset
32603
32604
32605 \end_layout
32606
32607 \end_inset
32608 </cell>
32609 </row>
32610 <row topline="true">
32611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32612 \begin_inset Text
32613
32614 \begin_layout Standard
32615 ISO/IEC DTR 18037
32616 \end_layout
32617
32618 \end_inset
32619 </cell>
32620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32621 \begin_inset Text
32622
32623 \begin_layout Standard
32624 \begin_inset Quotes sld
32625 \end_inset
32626
32627 Extensions for Embedded C
32628 \begin_inset Quotes srd
32629 \end_inset
32630
32631
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
32641 \size footnotesize
32642 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32643
32644 \end_inset
32645
32646
32647 \end_layout
32648
32649 \end_inset
32650 </cell>
32651 </row>
32652 <row topline="true">
32653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32654 \begin_inset Text
32655
32656 \begin_layout Standard
32657
32658 \end_layout
32659
32660 \end_inset
32661 </cell>
32662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32663 \begin_inset Text
32664
32665 \begin_layout Standard
32666 Latest datasheet of target CPU
32667 \end_layout
32668
32669 \end_inset
32670 </cell>
32671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32672 \begin_inset Text
32673
32674 \begin_layout Standard
32675 vendor
32676 \end_layout
32677
32678 \end_inset
32679 </cell>
32680 </row>
32681 <row topline="true" bottomline="true">
32682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32683 \begin_inset Text
32684
32685 \begin_layout Standard
32686
32687 \end_layout
32688
32689 \end_inset
32690 </cell>
32691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32692 \begin_inset Text
32693
32694 \begin_layout Standard
32695 Revision history of datasheet
32696 \end_layout
32697
32698 \end_inset
32699 </cell>
32700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32701 \begin_inset Text
32702
32703 \begin_layout Standard
32704 vendor
32705 \end_layout
32706
32707 \end_inset
32708 </cell>
32709 </row>
32710 </lyxtabular>
32711
32712 \end_inset
32713
32714
32715 \newline
32716
32717 \end_layout
32718
32719 \begin_layout Section
32720 Application notes specifically for SDCC
32721 \end_layout
32722
32723 \begin_layout Standard
32724 SDCC makes no claims about the completeness of this list and about up-to-datenes
32725 s or correctness of the application notes
32726 \begin_inset LatexCommand \index{Application notes}
32727
32728 \end_inset
32729
32730 .
32731 \end_layout
32732
32733 \begin_layout Standard
32734 \align left
32735
32736 \size footnotesize
32737 \begin_inset Tabular
32738 <lyxtabular version="3" rows="7" columns="3">
32739 <features>
32740 <column alignment="block" valignment="top" leftline="true" width="17col%">
32741 <column alignment="block" valignment="top" leftline="true" width="27col%">
32742 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32743 <row topline="true" bottomline="true">
32744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32745 \begin_inset Text
32746
32747 \begin_layout Standard
32748
32749 \series bold
32750 \size footnotesize
32751 Vendor
32752 \end_layout
32753
32754 \end_inset
32755 </cell>
32756 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32757 \begin_inset Text
32758
32759 \begin_layout Standard
32760
32761 \series bold
32762 \size footnotesize
32763 Subject / Title
32764 \end_layout
32765
32766 \end_inset
32767 </cell>
32768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32769 \begin_inset Text
32770
32771 \begin_layout Standard
32772
32773 \series bold
32774 \size footnotesize
32775 Where to get
32776 \end_layout
32777
32778 \end_inset
32779 </cell>
32780 </row>
32781 <row topline="true">
32782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32783 \begin_inset Text
32784
32785 \begin_layout Standard
32786
32787 \size footnotesize
32788 Maxim / Dallas
32789 \end_layout
32790
32791 \end_inset
32792 </cell>
32793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32794 \begin_inset Text
32795
32796 \begin_layout Standard
32797
32798 \size footnotesize
32799 Using the SDCC Compiler for the DS80C400
32800 \begin_inset LatexCommand \index{DS80C400}
32801
32802 \end_inset
32803
32804
32805 \end_layout
32806
32807 \end_inset
32808 </cell>
32809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32810 \begin_inset Text
32811
32812 \begin_layout Standard
32813
32814 \size footnotesize
32815 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32816
32817 \end_inset
32818
32819
32820 \end_layout
32821
32822 \end_inset
32823 </cell>
32824 </row>
32825 <row topline="true">
32826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32827 \begin_inset Text
32828
32829 \begin_layout Standard
32830
32831 \size footnotesize
32832 Maxim / Dallas
32833 \end_layout
32834
32835 \end_inset
32836 </cell>
32837 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32838 \begin_inset Text
32839
32840 \begin_layout Standard
32841
32842 \size footnotesize
32843 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32844 \begin_inset LatexCommand \index{DS89C4x0}
32845
32846 \end_inset
32847
32848  Family of Microcontrollers
32849 \end_layout
32850
32851 \end_inset
32852 </cell>
32853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32854 \begin_inset Text
32855
32856 \begin_layout Standard
32857
32858 \size footnotesize
32859 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32860
32861 \end_inset
32862
32863
32864 \end_layout
32865
32866 \end_inset
32867 </cell>
32868 </row>
32869 <row topline="true">
32870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32871 \begin_inset Text
32872
32873 \begin_layout Standard
32874
32875 \size footnotesize
32876 Silicon Laboratories / Cygnal
32877 \end_layout
32878
32879 \end_inset
32880 </cell>
32881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32882 \begin_inset Text
32883
32884 \begin_layout Standard
32885
32886 \size footnotesize
32887 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32888 \begin_inset LatexCommand \index{IDE}
32889
32890 \end_inset
32891
32892
32893 \end_layout
32894
32895 \end_inset
32896 </cell>
32897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32898 \begin_inset Text
32899
32900 \begin_layout Standard
32901
32902 \size footnotesize
32903 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32904
32905 \end_inset
32906
32907
32908 \end_layout
32909
32910 \end_inset
32911 </cell>
32912 </row>
32913 <row topline="true">
32914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32915 \begin_inset Text
32916
32917 \begin_layout Standard
32918
32919 \size footnotesize
32920 Ramtron / Goal Semiconductor
32921 \end_layout
32922
32923 \end_inset
32924 </cell>
32925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32926 \begin_inset Text
32927
32928 \begin_layout Standard
32929
32930 \size footnotesize
32931 Interfacing SDCC to Syn and Textpad
32932 \end_layout
32933
32934 \end_inset
32935 </cell>
32936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32937 \begin_inset Text
32938
32939 \begin_layout Standard
32940
32941 \size footnotesize
32942 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32943
32944 \end_inset
32945
32946
32947 \end_layout
32948
32949 \end_inset
32950 </cell>
32951 </row>
32952 <row topline="true">
32953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32954 \begin_inset Text
32955
32956 \begin_layout Standard
32957
32958 \size footnotesize
32959 Ramtron / Goal Semiconductor
32960 \end_layout
32961
32962 \end_inset
32963 </cell>
32964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32965 \begin_inset Text
32966
32967 \begin_layout Standard
32968
32969 \size footnotesize
32970 Installing and Configuring SDCC and Crimson Editor 
32971 \end_layout
32972
32973 \end_inset
32974 </cell>
32975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32976 \begin_inset Text
32977
32978 \begin_layout Standard
32979
32980 \size footnotesize
32981 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32982
32983 \end_inset
32984
32985
32986 \end_layout
32987
32988 \end_inset
32989 </cell>
32990 </row>
32991 <row topline="true" bottomline="true">
32992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32993 \begin_inset Text
32994
32995 \begin_layout Standard
32996
32997 \size footnotesize
32998 Texas Instruments
32999 \end_layout
33000
33001 \end_inset
33002 </cell>
33003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33004 \begin_inset Text
33005
33006 \begin_layout Standard
33007
33008 \size footnotesize
33009 MSC12xx Programming with SDCC
33010 \end_layout
33011
33012 \end_inset
33013 </cell>
33014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33015 \begin_inset Text
33016
33017 \begin_layout Standard
33018
33019 \size footnotesize
33020 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
33021
33022 \end_inset
33023
33024
33025 \end_layout
33026
33027 \end_inset
33028 </cell>
33029 </row>
33030 </lyxtabular>
33031
33032 \end_inset
33033
33034
33035 \end_layout
33036
33037 \begin_layout Section
33038 Some Questions
33039 \end_layout
33040
33041 \begin_layout Standard
33042 Some questions answered, some pointers given - it might be time to in turn
33043  ask 
33044 \emph on
33045 you
33046 \emph default
33047  some questions: 
33048 \end_layout
33049
33050 \begin_layout Itemize
33051 can you solve your project with the selected microcontroller? Would you
33052  find out early or rather late that your target is too small/slow/whatever?
33053  Can you switch to a slightly better device if it doesn't fit?
33054 \end_layout
33055
33056 \begin_layout Itemize
33057 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
33058  and/or another programming language be more adequate? Would an operating
33059  system on the target device help?
33060 \end_layout
33061
33062 \begin_layout Itemize
33063 if you solved the problem, will the marketing department be happy?
33064 \end_layout
33065
33066 \begin_layout Itemize
33067 if the marketing department is happy, will customers be happy?
33068 \end_layout
33069
33070 \begin_layout Itemize
33071 if you're the project manager, marketing department and maybe even the customer
33072  in one person, have you tried to see the project from the outside?
33073 \end_layout
33074
33075 \begin_layout Itemize
33076 is the project done if you think it is done? Or is just that other interface/pro
33077 tocol/feature/configuration/option missing? How about website, manual(s),
33078  internationali(z|s)ation, packaging, labels, 2nd source for components,
33079  electromagnetic compatability/interference, documentation for production,
33080  production test software, update mechanism, patent issues?
33081 \end_layout
33082
33083 \begin_layout Itemize
33084 is your project adequately positioned in that magic triangle: fame, fortune,
33085  fun?
33086 \end_layout
33087
33088 \begin_layout Standard
33089 Maybe not all answers to these questions are known and some answers may
33090  even be 
33091 \emph on
33092 no
33093 \emph default
33094 , nevertheless knowing these questions may help you to avoid burnout
33095 \begin_inset Foot
33096 status open
33097
33098 \begin_layout Standard
33099 burnout is bad for electronic devices, programmers and motorcycle tyres
33100 \end_layout
33101
33102 \end_inset
33103
33104 .
33105  Chances are you didn't want to hear some of them...
33106 \end_layout
33107
33108 \begin_layout Chapter
33109 Support
33110 \begin_inset LatexCommand \index{Support}
33111
33112 \end_inset
33113
33114
33115 \end_layout
33116
33117 \begin_layout Standard
33118 SDCC has grown to be a large project.
33119  The compiler alone (without the preprocessor, assembler and linker) is
33120  well over 150,000 lines of code (blank stripped).
33121  The open source nature of this project is a key to its continued growth
33122  and support.
33123  You gain the benefit and support of many active software developers and
33124  end users.
33125  Is SDCC perfect? No, that's why we need your help.
33126  The developers take pride in fixing reported bugs.
33127  You can help by reporting the bugs and helping other SDCC users.
33128  There are lots of ways to contribute, and we encourage you to take part
33129  in making SDCC a great software package.
33130  
33131 \end_layout
33132
33133 \begin_layout Standard
33134 The SDCC project is hosted on the SDCC sourceforge site at 
33135 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33136
33137 \end_inset
33138
33139 .
33140  You'll find the complete set of mailing lists
33141 \begin_inset LatexCommand \index{Mailing list(s)}
33142
33143 \end_inset
33144
33145 , forums, bug reporting system, patch submission
33146 \begin_inset LatexCommand \index{Patch submission}
33147
33148 \end_inset
33149
33150  system, download
33151 \begin_inset LatexCommand \index{download}
33152
33153 \end_inset
33154
33155  area and Subversion code repository
33156 \begin_inset LatexCommand \index{Subversion code repository}
33157
33158 \end_inset
33159
33160  there.
33161 \end_layout
33162
33163 \begin_layout Section
33164 Reporting Bugs
33165 \begin_inset LatexCommand \index{Bug reporting}
33166
33167 \end_inset
33168
33169
33170 \begin_inset LatexCommand \index{Reporting bugs}
33171
33172 \end_inset
33173
33174
33175 \end_layout
33176
33177 \begin_layout Standard
33178 The recommended way of reporting bugs is using the infrastructure of the
33179  sourceforge site.
33180  You can follow the status of bug reports there and have an overview about
33181  the known bugs.
33182 \end_layout
33183
33184 \begin_layout Standard
33185 Bug reports are automatically forwarded to the developer mailing list and
33186  will be fixed ASAP.
33187  When reporting a bug, it is very useful to include a small test program
33188  (the smaller the better) which reproduces the problem.
33189  If you can isolate the problem by looking at the generated assembly code,
33190  this can be very helpful.
33191  Compiling your program with the -
33192 \begin_inset ERT
33193 status collapsed
33194
33195 \begin_layout Standard
33196
33197
33198 \backslash
33199 /
33200 \end_layout
33201
33202 \end_inset
33203
33204 -dumpall
33205 \begin_inset LatexCommand \index{-\/-dumpall}
33206
33207 \end_inset
33208
33209  option can sometimes be useful in locating optimization problems.
33210  When reporting a bug please make sure you:
33211 \end_layout
33212
33213 \begin_layout Enumerate
33214 Attach the code you are compiling with SDCC.
33215  
33216 \end_layout
33217
33218 \begin_layout Enumerate
33219 Specify the exact command you use to run SDCC, or attach your Makefile.
33220  
33221 \end_layout
33222
33223 \begin_layout Enumerate
33224 Specify the SDCC version (type "
33225 \family sans
33226 \series bold
33227 sdcc -v
33228 \family default
33229 \series default
33230 "), your platform, and operating system.
33231  
33232 \end_layout
33233
33234 \begin_layout Enumerate
33235 Provide an exact copy of any error message or incorrect output.
33236  
33237 \end_layout
33238
33239 \begin_layout Enumerate
33240 Put something meaningful in the subject of your message.
33241 \end_layout
33242
33243 \begin_layout Standard
33244 Please attempt to include these 5 important parts, as applicable, in all
33245  requests for support or when reporting any problems or bugs with SDCC.
33246  Though this will make your message lengthy, it will greatly improve your
33247  chance that SDCC users and developers will be able to help you.
33248  Some SDCC developers are frustrated by bug reports without code provided
33249  that they can use to reproduce and ultimately fix the problem, so please
33250  be sure to provide sample code if you are reporting a bug! 
33251 \end_layout
33252
33253 \begin_layout Standard
33254 Please have a short check that you are using a recent version of SDCC and
33255  the bug is not yet known.
33256  This is the link for reporting bugs: 
33257 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33258
33259 \end_inset
33260
33261 .
33262  With SDCC on average having more than 200 downloads
33263 \begin_inset LatexCommand \index{download}
33264
33265 \end_inset
33266
33267  on sourceforge per day
33268 \begin_inset Foot
33269 status open
33270
33271 \begin_layout Standard
33272 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33273  between 2002 and 2005.
33274  This does not include other methods of distribution.
33275 \end_layout
33276
33277 \end_inset
33278
33279  there must be some users.
33280  So it's not exactly easy to find a new bug.
33281  If you find one we need it: 
33282 \emph on
33283 reporting bugs is good
33284 \emph default
33285 .
33286 \end_layout
33287
33288 \begin_layout Section
33289 Requesting Features
33290 \begin_inset LatexCommand \label{sub:Requesting-Features}
33291
33292 \end_inset
33293
33294
33295 \begin_inset LatexCommand \index{Feature request}
33296
33297 \end_inset
33298
33299
33300 \begin_inset LatexCommand \index{Requesting features}
33301
33302 \end_inset
33303
33304
33305 \end_layout
33306
33307 \begin_layout Standard
33308 Like bug reports feature requests are forwarded to the developer mailing
33309  list.
33310  This is the link for requesting features: 
33311 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33312
33313 \end_inset
33314
33315 .
33316 \end_layout
33317
33318 \begin_layout Section
33319 Submitting patches
33320 \end_layout
33321
33322 \begin_layout Standard
33323 Like bug reports contributed patches are forwarded to the developer mailing
33324  list.
33325  This is the link for submitting patches
33326 \begin_inset LatexCommand \index{Patch submission}
33327
33328 \end_inset
33329
33330
33331 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33332
33333 \end_inset
33334
33335 .
33336 \end_layout
33337
33338 \begin_layout Standard
33339 You need to specify some parameters to the 
33340 \family typewriter
33341 diff
33342 \family default
33343  command for the patches to be useful.
33344  If you modified more than one file a patch created f.e.
33345  with 
33346 \family sans
33347 \series bold
33348
33349 \begin_inset Quotes sld
33350 \end_inset
33351
33352 diff -Naur unmodified_directory modified_directory >my_changes.patch
33353 \begin_inset Quotes srd
33354 \end_inset
33355
33356
33357 \family default
33358 \series default
33359  will be fine, otherwise 
33360 \family sans
33361 \series bold
33362
33363 \begin_inset Quotes sld
33364 \end_inset
33365
33366 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33367 \begin_inset Quotes srd
33368 \end_inset
33369
33370
33371 \series default
33372  
33373 \family default
33374 will do.
33375 \end_layout
33376
33377 \begin_layout Section
33378 Getting Help
33379 \end_layout
33380
33381 \begin_layout Standard
33382 These links should take you directly to the 
33383 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33384
33385 \end_inset
33386
33387
33388 \begin_inset Foot
33389 status open
33390
33391 \begin_layout Standard
33392 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33393  automated messages (mid 2003)
33394 \end_layout
33395
33396 \end_inset
33397
33398  and the 
33399 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33400
33401 \end_inset
33402
33403 , lists
33404 \begin_inset LatexCommand \index{Mailing list(s)}
33405
33406 \end_inset
33407
33408  and forums are archived and searchable so if you are lucky someone already
33409  had a similar problem.
33410  While mails to the lists themselves are delivered promptly their web front
33411  end on sourceforge sometimes shows a severe time lag (up to several weeks),
33412  if you're seriously using SDCC please consider subscribing to the lists.
33413 \end_layout
33414
33415 \begin_layout Section
33416 ChangeLog
33417 \end_layout
33418
33419 \begin_layout Standard
33420 You can follow the status of the Subversion version
33421 \begin_inset LatexCommand \index{version}
33422
33423 \end_inset
33424
33425  of SDCC by watching the Changelog
33426 \begin_inset LatexCommand \index{Changelog}
33427
33428 \end_inset
33429
33430  in the Subversion repository
33431 \size footnotesize
33432  
33433 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33434
33435 \end_inset
33436
33437 .
33438 \end_layout
33439
33440 \begin_layout Section
33441 Subversion Source Code Repository
33442 \end_layout
33443
33444 \begin_layout Standard
33445 The output of 
33446 \family sans
33447 \series bold
33448 sdcc -
33449 \family default
33450
33451 \begin_inset ERT
33452 status open
33453
33454 \begin_layout Standard
33455
33456
33457 \backslash
33458 /
33459 \end_layout
33460
33461 \end_inset
33462
33463
33464 \family sans
33465 -version
33466 \family default
33467 \series default
33468  or the filenames of the snapshot versions of SDCC include date and its
33469  Subversion
33470 \begin_inset LatexCommand \index{Subversion code repository}
33471
33472 \end_inset
33473
33474  number.
33475  Subversion allows to download the source of recent or previous versions
33476  
33477 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33478
33479 \end_inset
33480
33481  (by number or by date).
33482  An on-line source code browser and detailled instructions are also available
33483  there.
33484  SDCC versions starting from 1999 up to now are available (currently the
33485  versions prior to the conversion from cvs
33486 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33487
33488 \end_inset
33489
33490  to Subversion (April 2006) are either by accessible by Subversion or by
33491  cvs).
33492 \end_layout
33493
33494 \begin_layout Section
33495 Release policy
33496 \begin_inset LatexCommand \index{Release policy}
33497
33498 \end_inset
33499
33500
33501 \end_layout
33502
33503 \begin_layout Standard
33504 Historically there often were long delays between official releases and
33505  the sourceforge download area tends to get not updated at all.
33506  Excuses in the past might have referred to problems with live range analysis,
33507  but as this was fixed a while ago, the current problem is that another
33508  excuse has to be found.
33509  Kidding aside, we have to get better there! On the other hand there are
33510  daily snapshots available at 
33511 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33512
33513 \end_inset
33514
33515 , and you can always build the very last version (hopefully with many bugs
33516  fixed, and features added) from the source code available at 
33517 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33518
33519 \end_inset
33520
33521 .
33522  The SDCC Wiki
33523 \begin_inset LatexCommand \index{wiki}
33524
33525 \end_inset
33526
33527
33528 \begin_inset LatexCommand \index{SDCC Wiki}
33529
33530 \end_inset
33531
33532  at 
33533 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33534
33535 \end_inset
33536
33537  also holds some information about past and future releases.
33538 \end_layout
33539
33540 \begin_layout Section
33541 Examples
33542 \begin_inset LatexCommand \index{Examples}
33543
33544 \end_inset
33545
33546
33547 \end_layout
33548
33549 \begin_layout Standard
33550 You'll find some small examples in the directory 
33551 \emph on
33552 sdcc/device/examples/.
33553  
33554 \emph default
33555 More examples and libraries are available at
33556 \emph on
33557  The SDCC Open Knowledge Resource 
33558 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33559
33560 \end_inset
33561
33562  
33563 \emph default
33564 web site or at 
33565 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33566
33567 \end_inset
33568
33569 .
33570 \end_layout
33571
33572 \begin_layout Standard
33573 \begin_inset Note Note
33574 status collapsed
33575
33576 \begin_layout Standard
33577 I did insert a reference to Paul's web site here although it seems rather
33578  dedicated to a specific 8032 board (I think it's okay because it f.e.
33579  shows LCD/Harddisc interface and has a free 8051 monitor.
33580  Independent 8032 board vendors face hard competition of heavily subsidized
33581  development boards anyway).
33582 \end_layout
33583
33584 \begin_layout Standard
33585 Maybe we should include some links to real world applications.
33586  Preferably pointer to pointers (one for each architecture) so this stays
33587  manageable here?
33588 \end_layout
33589
33590 \end_inset
33591
33592
33593 \end_layout
33594
33595 \begin_layout Section
33596 Quality control
33597 \begin_inset LatexCommand \label{sec:Quality-control}
33598
33599 \end_inset
33600
33601
33602 \begin_inset LatexCommand \index{Quality control}
33603
33604 \end_inset
33605
33606
33607 \end_layout
33608
33609 \begin_layout Standard
33610 The compiler is passed through snaphot build compile and build checks.
33611  The so called 
33612 \shape italic
33613 regression tests
33614 \shape default
33615
33616 \begin_inset LatexCommand \index{Regression test}
33617
33618 \end_inset
33619
33620  check that SDCC itself compiles flawlessly on several host platforms (i386,
33621  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33622  and checks the quality of the code generated by SDCC by running the code
33623  for several target platforms through simulators.
33624  The regression test suite comprises more than 100 files which expand to
33625  more than 500 test cases which include more than 4500 tests.
33626  The results of these tests are published daily on SDCC's snapshot page
33627  (click on the red or green symbols on the right side of 
33628 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33629
33630 \end_inset
33631
33632 ).
33633 \end_layout
33634
33635 \begin_layout Standard
33636 There is a separate document 
33637 \shape italic
33638 test_suite.pdf 
33639 \begin_inset LatexCommand \index{Test suite}
33640
33641 \end_inset
33642
33643
33644 \shape default
33645  
33646 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33647
33648 \end_inset
33649
33650  about the regression test suite.
33651 \end_layout
33652
33653 \begin_layout Standard
33654 You'll find the test code in the directory 
33655 \shape italic
33656 sdcc/support/regression
33657 \shape default
33658 .
33659  You can run these tests manually by running 
33660 \family sans
33661 make
33662 \family default
33663  in this directory (or f.e.
33664  
33665 \family sans
33666 \series bold
33667
33668 \begin_inset Quotes sld
33669 \end_inset
33670
33671 make test-mcs51
33672 \begin_inset Quotes srd
33673 \end_inset
33674
33675
33676 \family default
33677 \series default
33678  if you don't want to run the complete tests).
33679  The test code might also be interesting if you want to look for examples
33680 \begin_inset LatexCommand \index{Examples}
33681
33682 \end_inset
33683
33684  checking corner cases of SDCC or if you plan to submit patches
33685 \begin_inset LatexCommand \index{Patch submission}
33686
33687 \end_inset
33688
33689 .
33690 \end_layout
33691
33692 \begin_layout Standard
33693 The PIC14 port uses a different set of regression tests 
33694 \begin_inset LatexCommand \index{Regression test (PIC14)}
33695
33696 \end_inset
33697
33698 , you'll find them in the directory 
33699 \shape italic
33700 sdcc/src/regression
33701 \shape default
33702 .
33703 \end_layout
33704
33705 \begin_layout Section
33706 Use of SDCC in Education
33707 \end_layout
33708
33709 \begin_layout Standard
33710 In short: 
33711 \emph on
33712 highly
33713 \emph default
33714  encouraged
33715 \begin_inset Foot
33716 status open
33717
33718 \begin_layout Standard
33719 the phrase "use in education" might evoke the association "
33720 \emph on
33721 only
33722 \emph default
33723  fit for use in education".
33724  This connotation is not intended but nevertheless risked as the licensing
33725  of SDCC makes it difficult to offer educational discounts
33726 \end_layout
33727
33728 \end_inset
33729
33730 .
33731  If your rationales are to:
33732 \end_layout
33733
33734 \begin_layout Enumerate
33735 give students a chance to understand the 
33736 \emph on
33737 complete
33738 \emph default
33739  steps of code generation
33740 \end_layout
33741
33742 \begin_layout Enumerate
33743 have a curriculum that can be extended for years.
33744  Then you could use an fpga board as target and your curriculum will seamlessly
33745  extend from logic synthesis (
33746 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33747
33748 \end_inset
33749
33750
33751 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33752
33753 \end_inset
33754
33755 ), over assembly programming, to C to FPGA compilers (
33756 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33757
33758 \end_inset
33759
33760 ) and to C.
33761 \end_layout
33762
33763 \begin_layout Enumerate
33764 be able to insert excursions about skills like using a revision control
33765  system, submitting/applying patches, using a type-setting (as opposed to
33766  word-processing) engine LyX/LaTeX, using 
33767 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33768
33769 \end_inset
33770
33771 , following some 
33772 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33773
33774 \end_inset
33775
33776 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33777  Source Software, CPU simulation, compiler regression tests
33778 \begin_inset LatexCommand \index{Regression test}
33779
33780 \end_inset
33781
33782 .
33783  
33784 \newline
33785 And if there should be a shortage of ideas then you can always point students
33786  to the ever-growing feature request list 
33787 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33788
33789 \end_inset
33790
33791 .
33792 \end_layout
33793
33794 \begin_layout Enumerate
33795 not tie students to a specific host platform and instead allow them to use
33796  a host platform of 
33797 \emph on
33798 their
33799 \emph default
33800  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33801  and eventually 
33802 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33803
33804 \end_inset
33805
33806 )
33807 \end_layout
33808
33809 \begin_layout Enumerate
33810 not encourage students to use illegal copies of educational software
33811 \end_layout
33812
33813 \begin_layout Enumerate
33814 be immune to licensing/availability/price changes of the chosen tool chain
33815 \end_layout
33816
33817 \begin_layout Enumerate
33818 be able to change to a new target platform without having to adopt a new
33819  tool chain
33820 \end_layout
33821
33822 \begin_layout Enumerate
33823 have complete control over and insight into the tool chain
33824 \end_layout
33825
33826 \begin_layout Enumerate
33827 make your students aware about the pros and cons of open source software
33828  development
33829 \end_layout
33830
33831 \begin_layout Enumerate
33832 give back to the public as you are probably at least partially publically
33833  funded
33834 \end_layout
33835
33836 \begin_layout Enumerate
33837 give students a chance to publically prove their skills and to possibly
33838  see a world wide impact
33839 \end_layout
33840
33841 \begin_layout Standard
33842 then SDCC is probably among the first choices.
33843  Well, probably SDCC might be the only choice.
33844 \newpage
33845
33846 \end_layout
33847
33848 \begin_layout Chapter
33849 SDCC Technical Data
33850 \end_layout
33851
33852 \begin_layout Section
33853 Optimizations
33854 \begin_inset LatexCommand \index{Optimizations}
33855
33856 \end_inset
33857
33858
33859 \end_layout
33860
33861 \begin_layout Standard
33862 SDCC performs a host of standard optimizations in addition to some MCU specific
33863  optimizations.
33864  
33865 \end_layout
33866
33867 \begin_layout Subsection
33868 Sub-expression Elimination
33869 \begin_inset LatexCommand \index{Subexpression elimination}
33870
33871 \end_inset
33872
33873
33874 \end_layout
33875
33876 \begin_layout Standard
33877 The compiler does local and 
33878 \emph on
33879 g
33880 \emph default
33881 lobal 
33882 \emph on
33883 c
33884 \emph default
33885 ommon 
33886 \emph on
33887 s
33888 \emph default
33889 ubexpression 
33890 \emph on
33891 e
33892 \emph default
33893 limination, e.g.: 
33894 \end_layout
33895
33896 \begin_layout Verse
33897
33898 \family typewriter
33899 i = x + y + 1; 
33900 \newline
33901 j = x + y;
33902 \end_layout
33903
33904 \begin_layout Standard
33905 will be translated to
33906 \end_layout
33907
33908 \begin_layout Verse
33909
33910 \family typewriter
33911 iTemp = x + y; 
33912 \newline
33913 i = iTemp + 1; 
33914 \newline
33915 j = iTemp;
33916 \end_layout
33917
33918 \begin_layout Standard
33919 Some subexpressions are not as obvious as the above example, e.g.:
33920 \end_layout
33921
33922 \begin_layout Verse
33923
33924 \family typewriter
33925 a->b[i].c = 10; 
33926 \newline
33927 a->b[i].d = 11;
33928 \end_layout
33929
33930 \begin_layout Standard
33931 In this case the address arithmetic a->b[i] will be computed only once;
33932  the equivalent code in C would be.
33933 \end_layout
33934
33935 \begin_layout Verse
33936
33937 \family typewriter
33938 iTemp = a->b[i]; 
33939 \newline
33940 iTemp.c = 10; 
33941 \newline
33942 iTemp.d = 11;
33943 \end_layout
33944
33945 \begin_layout Standard
33946 The compiler will try to keep these temporary variables in registers.
33947 \end_layout
33948
33949 \begin_layout Subsection
33950 Dead-Code Elimination
33951 \begin_inset LatexCommand \index{Dead-code elimination}
33952
33953 \end_inset
33954
33955
33956 \end_layout
33957
33958 \begin_layout Verse
33959
33960 \family typewriter
33961 int global;
33962 \newline
33963
33964 \newline
33965 void f () { 
33966 \newline
33967 \InsetSpace ~
33968 \InsetSpace ~
33969 int i; 
33970 \newline
33971 \InsetSpace ~
33972 \InsetSpace ~
33973 i = 1; \InsetSpace ~
33974 \InsetSpace ~
33975 \InsetSpace ~
33976 \InsetSpace ~
33977 \InsetSpace ~
33978 /* dead store */ 
33979 \newline
33980 \InsetSpace ~
33981 \InsetSpace ~
33982 global = 1;\InsetSpace ~
33983 /* dead
33984  store */ 
33985 \newline
33986 \InsetSpace ~
33987 \InsetSpace ~
33988 global = 2; 
33989 \newline
33990 \InsetSpace ~
33991 \InsetSpace ~
33992 return; 
33993 \newline
33994 \InsetSpace ~
33995 \InsetSpace ~
33996 global = 3;\InsetSpace ~
33997 /* unreachable */ 
33998 \newline
33999 }
34000 \end_layout
34001
34002 \begin_layout Standard
34003 will be changed to
34004 \end_layout
34005
34006 \begin_layout Verse
34007
34008 \family typewriter
34009 int global;
34010 \newline
34011
34012 \newline
34013 void f () {
34014 \newline
34015 \InsetSpace ~
34016 \InsetSpace ~
34017 global = 2; 
34018 \newline
34019 }
34020 \end_layout
34021
34022 \begin_layout Subsection
34023 Copy-Propagation
34024 \begin_inset LatexCommand \index{Copy propagation}
34025
34026 \end_inset
34027
34028
34029 \end_layout
34030
34031 \begin_layout Verse
34032
34033 \family typewriter
34034 int f() { 
34035 \newline
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 int i, j; 
34039 \newline
34040 \InsetSpace ~
34041 \InsetSpace ~
34042 i = 10; 
34043 \newline
34044 \InsetSpace ~
34045 \InsetSpace ~
34046 j = i; 
34047 \newline
34048 \InsetSpace ~
34049 \InsetSpace ~
34050 return j; 
34051 \newline
34052 }
34053 \end_layout
34054
34055 \begin_layout Standard
34056 will be changed to 
34057 \end_layout
34058
34059 \begin_layout Verse
34060
34061 \family typewriter
34062 int f() { 
34063 \newline
34064 \InsetSpace ~
34065 \InsetSpace ~
34066 int i, j; 
34067 \newline
34068 \InsetSpace ~
34069 \InsetSpace ~
34070 i = 10; 
34071 \newline
34072 \InsetSpace ~
34073 \InsetSpace ~
34074 j = 10; 
34075 \newline
34076 \InsetSpace ~
34077 \InsetSpace ~
34078 return 10; 
34079 \newline
34080 }
34081 \end_layout
34082
34083 \begin_layout Standard
34084 Note: the dead stores created by this copy propagation will be eliminated
34085  by dead-code elimination.
34086 \end_layout
34087
34088 \begin_layout Subsection
34089 Loop Optimizations
34090 \begin_inset LatexCommand \index{Loop optimization}
34091
34092 \end_inset
34093
34094
34095 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
34096
34097 \end_inset
34098
34099
34100 \end_layout
34101
34102 \begin_layout Standard
34103 Two types of loop optimizations are done by SDCC 
34104 \emph on
34105 loop invariant
34106 \emph default
34107  lifting and
34108 \emph on
34109  strength reduction
34110 \emph default
34111  of loop induction variables.
34112  In addition to the strength reduction the optimizer marks the induction
34113  variables and the register allocator tries to keep the induction variables
34114  in registers for the duration of the loop.
34115  Because of this preference of the register allocator
34116 \begin_inset LatexCommand \index{Register allocation}
34117
34118 \end_inset
34119
34120 , loop induction optimization causes an increase in register pressure, which
34121  may cause unwanted spilling of other temporary variables into the stack
34122 \begin_inset LatexCommand \index{stack}
34123
34124 \end_inset
34125
34126  / data space.
34127  The compiler will generate a warning message when it is forced to allocate
34128  extra space either on the stack or data space.
34129  If this extra space allocation is undesirable then induction optimization
34130  can be eliminated either for the entire source file (with -
34131 \begin_inset ERT
34132 status collapsed
34133
34134 \begin_layout Standard
34135
34136
34137 \backslash
34138 /
34139 \end_layout
34140
34141 \end_inset
34142
34143 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34144 noinduction
34145 \begin_inset LatexCommand \index{\#pragma noinduction}
34146
34147 \end_inset
34148
34149 .
34150 \newline
34151
34152 \newline
34153 Loop Invariant:
34154 \end_layout
34155
34156 \begin_layout Verse
34157
34158 \family typewriter
34159 for (i = 0 ; i < 100 ; i ++) 
34160 \newline
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 f += k + l;
34166 \end_layout
34167
34168 \begin_layout Standard
34169 changed to
34170 \end_layout
34171
34172 \begin_layout Verse
34173
34174 \family typewriter
34175 itemp = k + l; 
34176 \newline
34177 for (i = 0; i < 100; i++) 
34178 \newline
34179 \InsetSpace ~
34180 \InsetSpace ~
34181 \InsetSpace ~
34182 \InsetSpace ~
34183 f += itemp;
34184 \end_layout
34185
34186 \begin_layout Standard
34187 As mentioned previously some loop invariants are not as apparent, all static
34188  address computations are also moved out of the loop.
34189 \newline
34190
34191 \newline
34192 Strength Reduction
34193 \begin_inset LatexCommand \index{Strength reduction}
34194
34195 \end_inset
34196
34197 , this optimization substitutes an expression by a cheaper expression:
34198 \end_layout
34199
34200 \begin_layout Verse
34201
34202 \family typewriter
34203 for (i=0;i < 100; i++)
34204 \newline
34205 \InsetSpace ~
34206 \InsetSpace ~
34207 \InsetSpace ~
34208 \InsetSpace ~
34209 ar[i*5] = i*3;
34210 \end_layout
34211
34212 \begin_layout Standard
34213 changed to
34214 \end_layout
34215
34216 \begin_layout Verse
34217
34218 \family typewriter
34219 itemp1 = 0; 
34220 \newline
34221 itemp2 = 0; 
34222 \newline
34223 for (i=0;i< 100;i++) { 
34224 \newline
34225 \InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 ar[itemp1] = itemp2; 
34230 \newline
34231 \InsetSpace ~
34232 \InsetSpace ~
34233 \InsetSpace ~
34234 \InsetSpace ~
34235 itemp1
34236  += 5; 
34237 \newline
34238 \InsetSpace ~
34239 \InsetSpace ~
34240 \InsetSpace ~
34241 \InsetSpace ~
34242 itemp2 += 3; 
34243 \newline
34244 }
34245 \end_layout
34246
34247 \begin_layout Standard
34248 The more expensive multiplication
34249 \begin_inset LatexCommand \index{Multiplication}
34250
34251 \end_inset
34252
34253  is changed to a less expensive addition.
34254 \end_layout
34255
34256 \begin_layout Subsection
34257 Loop Reversing
34258 \begin_inset LatexCommand \index{Loop reversing}
34259
34260 \end_inset
34261
34262
34263 \end_layout
34264
34265 \begin_layout Standard
34266 This optimization is done to reduce the overhead of checking loop boundaries
34267  for every iteration.
34268  Some simple loops can be reversed and implemented using a 
34269 \begin_inset Quotes eld
34270 \end_inset
34271
34272 decrement and jump if not zero
34273 \begin_inset Quotes erd
34274 \end_inset
34275
34276  instruction.
34277  SDCC checks for the following criterion to determine if a loop is reversible
34278  (note: more sophisticated compilers use data-dependency analysis to make
34279  this determination, SDCC uses a more simple minded analysis).
34280 \end_layout
34281
34282 \begin_layout Itemize
34283 The 'for' loop is of the form 
34284 \newline
34285
34286 \newline
34287
34288 \family typewriter
34289 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34290  += 1])
34291 \newline
34292 \InsetSpace ~
34293 \InsetSpace ~
34294 \InsetSpace ~
34295 \InsetSpace ~
34296 <for body>
34297 \end_layout
34298
34299 \begin_layout Itemize
34300 The <for body> does not contain 
34301 \begin_inset Quotes eld
34302 \end_inset
34303
34304 continue
34305 \begin_inset Quotes erd
34306 \end_inset
34307
34308  or 'break
34309 \begin_inset Quotes erd
34310 \end_inset
34311
34312 .
34313 \end_layout
34314
34315 \begin_layout Itemize
34316 All goto's are contained within the loop.
34317 \end_layout
34318
34319 \begin_layout Itemize
34320 No function calls within the loop.
34321 \end_layout
34322
34323 \begin_layout Itemize
34324 The loop control variable <sym> is not assigned any value within the loop
34325 \end_layout
34326
34327 \begin_layout Itemize
34328 The loop control variable does NOT participate in any arithmetic operation
34329  within the loop.
34330 \end_layout
34331
34332 \begin_layout Itemize
34333 There are NO switch statements in the loop.
34334 \end_layout
34335
34336 \begin_layout Subsection
34337 Algebraic Simplifications
34338 \end_layout
34339
34340 \begin_layout Standard
34341 SDCC does numerous algebraic simplifications, the following is a small sub-set
34342  of these optimizations.
34343 \end_layout
34344
34345 \begin_layout Verse
34346
34347 \family typewriter
34348 i = j + 0;\InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352  /* changed to: */\InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355 \InsetSpace ~
34356  i = j; 
34357 \newline
34358 i /= 2;\InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365  /* changed to: */\InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369  i >>= 1; 
34370 \newline
34371 i
34372  = j - j;\InsetSpace ~
34373 \InsetSpace ~
34374 \InsetSpace ~
34375 \InsetSpace ~
34376  /* changed to: */\InsetSpace ~
34377 \InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380  i = 0; 
34381 \newline
34382 i = j / 1;\InsetSpace ~
34383 \InsetSpace ~
34384 \InsetSpace ~
34385 \InsetSpace ~
34386  /* changed to: */\InsetSpace ~
34387 \InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390  i = j;
34391 \end_layout
34392
34393 \begin_layout Standard
34394 Note the subexpressions
34395 \begin_inset LatexCommand \index{Subexpression}
34396
34397 \end_inset
34398
34399  given above are generally introduced by macro expansions or as a result
34400  of copy/constant propagation.
34401 \end_layout
34402
34403 \begin_layout Subsection
34404 'switch' Statements
34405 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34406
34407 \end_inset
34408
34409
34410 \begin_inset LatexCommand \index{switch statement}
34411
34412 \end_inset
34413
34414
34415 \end_layout
34416
34417 \begin_layout Standard
34418 SDCC can optimize switch statements to jump tables
34419 \begin_inset LatexCommand \index{jump tables}
34420
34421 \end_inset
34422
34423 .
34424  It makes the decision based on an estimate of the generated code size.
34425  SDCC is quite liberal in the requirements for jump table generation: 
34426 \end_layout
34427
34428 \begin_layout Itemize
34429 The labels need not be in order, and the starting number need not be one
34430  or zero, the case labels are in numerical sequence or not too many case
34431  labels are missing.
34432 \end_layout
34433
34434 \begin_deeper
34435 \begin_layout Verse
34436
34437 \family typewriter
34438 switch(i) {\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 \InsetSpace ~
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 \InsetSpace ~
34464 switch (i) { 
34465 \newline
34466 \InsetSpace ~
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 case 4: ...\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 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 case 0: ...
34496  
34497 \newline
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 case 5: ...\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 \InsetSpace ~
34525 \InsetSpace ~
34526 \InsetSpace ~
34527 case 1: ...
34528  
34529 \newline
34530 \InsetSpace ~
34531 \InsetSpace ~
34532 \InsetSpace ~
34533 case 3: ...\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 \InsetSpace ~
34556 \InsetSpace ~
34557 \InsetSpace ~
34558 \InsetSpace ~
34559
34560 \newline
34561 \InsetSpace ~
34562 \InsetSpace ~
34563 \InsetSpace ~
34564 case 6: ...\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 \InsetSpace ~
34588 \InsetSpace ~
34589 \InsetSpace ~
34590 case 3: ...
34591  
34592 \newline
34593 \InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 case 7: ...\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 \InsetSpace ~
34620 \InsetSpace ~
34621 \InsetSpace ~
34622 case 4: ...
34623  
34624 \newline
34625 \InsetSpace ~
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 case 8: ...\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 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 case 5: ...
34655  
34656 \newline
34657 \InsetSpace ~
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 case 9: ...\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 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686 case 6: ...
34687  
34688 \newline
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 \InsetSpace ~
34692 case 10: ...\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 \InsetSpace ~
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 case 7: ...
34718  
34719 \newline
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 case 11: ...\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 case 8: ...
34749  
34750 \newline
34751 }\InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766 \InsetSpace ~
34767 \InsetSpace ~
34768 \InsetSpace ~
34769 \InsetSpace ~
34770 \InsetSpace ~
34771 \InsetSpace ~
34772 \InsetSpace ~
34773 \InsetSpace ~
34774 \InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779 \InsetSpace ~
34780 \InsetSpace ~
34781 \InsetSpace ~
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787 }
34788 \end_layout
34789
34790 \begin_layout Standard
34791 Both the above switch statements will be implemented using a jump-table.
34792  The example to the right side is slightly more efficient as the check for
34793  the lower boundary of the jump-table is not needed.
34794 \end_layout
34795
34796 \end_deeper
34797 \begin_layout Itemize
34798 The number of case labels is not larger than supported by the target architectur
34799 e.
34800 \end_layout
34801
34802 \begin_layout Itemize
34803 If the case labels are not in numerical sequence ('gaps' between cases)
34804  SDCC checks whether a jump table with additionally inserted dummy cases
34805  is still attractive.
34806  
34807 \end_layout
34808
34809 \begin_layout Itemize
34810 If the starting number is not zero and a check for the lower boundary of
34811  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34812  ...
34813  .
34814 \end_layout
34815
34816 \begin_layout Standard
34817 Switch statements which have large gaps in the numeric sequence or those
34818  that have too many case labels can be split into more than one switch statement
34819  for efficient code generation, e.g.:
34820 \end_layout
34821
34822 \begin_layout Verse
34823
34824 \family typewriter
34825 switch (i) { 
34826 \newline
34827 \InsetSpace ~
34828 \InsetSpace ~
34829 case 1: ...
34830  
34831 \newline
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 case 2: ...
34835  
34836 \newline
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 case 3: ...
34840  
34841 \newline
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 case 4: ...
34845  
34846 \newline
34847 \InsetSpace ~
34848 \InsetSpace ~
34849 case 5: ...
34850  
34851 \newline
34852 \InsetSpace ~
34853 \InsetSpace ~
34854 case 6: ...
34855  
34856 \newline
34857 \InsetSpace ~
34858 \InsetSpace ~
34859 case 7: ...
34860  
34861 \newline
34862 \InsetSpace ~
34863 \InsetSpace ~
34864 case 101: ...
34865  
34866 \newline
34867 \InsetSpace ~
34868 \InsetSpace ~
34869 case 102: ...
34870  
34871 \newline
34872 \InsetSpace ~
34873 \InsetSpace ~
34874 case 103: ...
34875  
34876 \newline
34877 \InsetSpace ~
34878 \InsetSpace ~
34879 case 104: ...
34880  
34881 \newline
34882 \InsetSpace ~
34883 \InsetSpace ~
34884 case 105: ...
34885  
34886 \newline
34887 \InsetSpace ~
34888 \InsetSpace ~
34889 case 106: ...
34890  
34891 \newline
34892 \InsetSpace ~
34893 \InsetSpace ~
34894 case 107: ...
34895  
34896 \newline
34897 }
34898 \end_layout
34899
34900 \begin_layout Standard
34901 If the above switch statement is broken down into two switch statements
34902 \end_layout
34903
34904 \begin_layout Verse
34905
34906 \family typewriter
34907 switch (i) { 
34908 \newline
34909 \InsetSpace ~
34910 \InsetSpace ~
34911 case 1: ...
34912  
34913 \newline
34914 \InsetSpace ~
34915 \InsetSpace ~
34916 case 2: ...
34917  
34918 \newline
34919 \InsetSpace ~
34920 \InsetSpace ~
34921 case 3: ...
34922  
34923 \newline
34924 \InsetSpace ~
34925 \InsetSpace ~
34926 case 4: ...
34927  
34928 \newline
34929 \InsetSpace ~
34930 \InsetSpace ~
34931 case 5: ...
34932  
34933 \newline
34934 \InsetSpace ~
34935 \InsetSpace ~
34936 case 6: ...
34937  
34938 \newline
34939 \InsetSpace ~
34940 \InsetSpace ~
34941 case 7: ...
34942  
34943 \newline
34944 }
34945 \end_layout
34946
34947 \begin_layout Standard
34948 and
34949 \end_layout
34950
34951 \begin_layout Verse
34952
34953 \family typewriter
34954 switch (i) { 
34955 \newline
34956 \InsetSpace ~
34957 \InsetSpace ~
34958 case 101: ...
34959  
34960 \newline
34961 \InsetSpace ~
34962 \InsetSpace ~
34963 case 102: ...
34964  
34965 \newline
34966 \InsetSpace ~
34967 \InsetSpace ~
34968 case 103: ...
34969  
34970 \newline
34971 \InsetSpace ~
34972 \InsetSpace ~
34973 case 104: ...
34974  
34975 \newline
34976 \InsetSpace ~
34977 \InsetSpace ~
34978 case 105: ...
34979  
34980 \newline
34981 \InsetSpace ~
34982 \InsetSpace ~
34983 case 106: ...
34984  
34985 \newline
34986 \InsetSpace ~
34987 \InsetSpace ~
34988 case 107: ...
34989  
34990 \newline
34991 }
34992 \end_layout
34993
34994 \begin_layout Standard
34995 then both the switch statements will be implemented using jump-tables whereas
34996  the unmodified switch statement will not be.
34997 \end_layout
34998
34999 \begin_layout Standard
35000 \begin_inset Note Note
35001 status collapsed
35002
35003 \begin_layout Standard
35004 There might be reasons which SDCC cannot know about to either favour or
35005  not favour jump tables.
35006  If the target system has to be as quick for the last switch case as for
35007  the first (pro jump table), or if the switch argument is known to be zero
35008  in the majority of the cases (contra jump table).
35009 \end_layout
35010
35011 \end_inset
35012
35013
35014 \end_layout
35015
35016 \begin_layout Standard
35017 The pragma nojtbound
35018 \begin_inset LatexCommand \index{\#pragma nojtbound}
35019
35020 \end_inset
35021
35022  can be used to turn off checking the 
35023 \emph on
35024 j
35025 \emph default
35026 ump 
35027 \emph on
35028 t
35029 \emph default
35030 able 
35031 \emph on
35032 bound
35033 \emph default
35034 aries.
35035  It has no effect if a default label is supplied.
35036  Use of this pragma is dangerous: if the switch
35037 \begin_inset LatexCommand \index{switch statement}
35038
35039 \end_inset
35040
35041  argument is not matched by a case statement the processor will happily
35042  jump into Nirvana.
35043 \end_layout
35044
35045 \begin_layout Subsection
35046 Bit-shifting Operations
35047 \begin_inset LatexCommand \index{Bit shifting}
35048
35049 \end_inset
35050
35051 .
35052 \end_layout
35053
35054 \begin_layout Standard
35055 Bit shifting is one of the most frequently used operation in embedded programmin
35056 g.
35057  SDCC tries to implement bit-shift operations in the most efficient way
35058  possible, e.g.:
35059 \end_layout
35060
35061 \begin_layout Verse
35062
35063 \family typewriter
35064 unsigned char i;
35065 \newline
35066 ...
35067  
35068 \newline
35069 i >>= 4; 
35070 \newline
35071 ...
35072 \end_layout
35073
35074 \begin_layout Standard
35075 generates the following code:
35076 \end_layout
35077
35078 \begin_layout Verse
35079
35080 \family typewriter
35081 mov\InsetSpace ~
35082  a,_i 
35083 \newline
35084 swap a 
35085 \newline
35086 anl\InsetSpace ~
35087  a,#0x0f 
35088 \newline
35089 mov\InsetSpace ~
35090  _i,a
35091 \end_layout
35092
35093 \begin_layout Standard
35094 In general SDCC will never setup a loop if the shift count is known.
35095  Another example:
35096 \end_layout
35097
35098 \begin_layout Verse
35099
35100 \family typewriter
35101 unsigned int i; 
35102 \newline
35103 ...
35104  
35105 \newline
35106 i >>= 9; 
35107 \newline
35108 ...
35109 \end_layout
35110
35111 \begin_layout Standard
35112 will generate:
35113 \end_layout
35114
35115 \begin_layout Verse
35116
35117 \family typewriter
35118 mov\InsetSpace ~
35119 \InsetSpace ~
35120 a,(_i + 1) 
35121 \newline
35122 mov\InsetSpace ~
35123 \InsetSpace ~
35124 (_i + 1),#0x00 
35125 \newline
35126 clr\InsetSpace ~
35127 \InsetSpace ~
35128
35129 \newline
35130 rrc\InsetSpace ~
35131 \InsetSpace ~
35132
35133 \newline
35134 mov\InsetSpace ~
35135 \InsetSpace ~
35136 _i,a
35137 \end_layout
35138
35139 \begin_layout Subsection
35140 Bit-rotation
35141 \begin_inset LatexCommand \index{Bit rotation}
35142
35143 \end_inset
35144
35145
35146 \end_layout
35147
35148 \begin_layout Standard
35149 A special case of the bit-shift operation is bit rotation
35150 \begin_inset LatexCommand \index{rotating bits}
35151
35152 \end_inset
35153
35154 , SDCC recognizes the following expression to be a left bit-rotation:
35155 \end_layout
35156
35157 \begin_layout Verse
35158
35159 \family typewriter
35160 \series bold
35161 unsigned
35162 \series default
35163 \InsetSpace ~
35164 \InsetSpace ~
35165 char i;\InsetSpace ~
35166 \InsetSpace ~
35167 \InsetSpace ~
35168 \InsetSpace ~
35169 \InsetSpace ~
35170 \InsetSpace ~
35171 \InsetSpace ~
35172 \InsetSpace ~
35173 \InsetSpace ~
35174 \InsetSpace ~
35175 \InsetSpace ~
35176 /* unsigned is needed for rotation */ 
35177 \newline
35178 ...
35179  
35180 \newline
35181 i = ((i << 1) | (i >> 7)); 
35182 \family default
35183
35184 \newline
35185
35186 \family typewriter
35187 ...
35188 \end_layout
35189
35190 \begin_layout Standard
35191 will generate the following code:
35192 \end_layout
35193
35194 \begin_layout Verse
35195
35196 \family typewriter
35197 mov\InsetSpace ~
35198 \InsetSpace ~
35199 a,_i 
35200 \newline
35201 rl\InsetSpace ~
35202 \InsetSpace ~
35203 \InsetSpace ~
35204
35205 \newline
35206 mov\InsetSpace ~
35207 \InsetSpace ~
35208 _i,a
35209 \end_layout
35210
35211 \begin_layout Standard
35212 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35213 ns of this case will also be recognized as bit-rotation, i.e.: 
35214 \end_layout
35215
35216 \begin_layout Verse
35217
35218 \family typewriter
35219 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35220 \end_layout
35221
35222 \begin_layout Subsection
35223 Nibble and Byte Swapping
35224 \end_layout
35225
35226 \begin_layout Standard
35227 Other special cases of the bit-shift operations are nibble or byte swapping
35228 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35229
35230 \end_inset
35231
35232 , SDCC recognizes the following expressions:
35233 \end_layout
35234
35235 \begin_layout Verse
35236
35237 \family typewriter
35238 \series bold
35239 unsigned
35240 \series default
35241 \InsetSpace ~
35242 \InsetSpace ~
35243 char i; 
35244 \newline
35245
35246 \series bold
35247 unsigned
35248 \series default
35249 \InsetSpace ~
35250 \InsetSpace ~
35251 int j; 
35252 \newline
35253 ...
35254  
35255 \newline
35256 i = ((i << 4) | (i >> 4)); 
35257 \family default
35258
35259 \newline
35260
35261 \family typewriter
35262 j = ((j << 8) | (j >> 8)); 
35263 \end_layout
35264
35265 \begin_layout Standard
35266 and generates a swap instruction for the nibble swapping
35267 \begin_inset LatexCommand \index{Nibble swapping}
35268
35269 \end_inset
35270
35271  or move instructions for the byte swapping
35272 \begin_inset LatexCommand \index{Byte swapping}
35273
35274 \end_inset
35275
35276 .
35277  The 
35278 \begin_inset Quotes sld
35279 \end_inset
35280
35281 j
35282 \begin_inset Quotes srd
35283 \end_inset
35284
35285  example can be used to convert from little to big-endian or vice versa.
35286  If you want to change the endianness of a 
35287 \emph on
35288 signed
35289 \emph default
35290  integer you have to cast to 
35291 \family typewriter
35292 (unsigned int)
35293 \family default
35294  first.
35295 \end_layout
35296
35297 \begin_layout Standard
35298 Note that SDCC stores numbers in little-endian
35299 \begin_inset Foot
35300 status open
35301
35302 \begin_layout Standard
35303 Usually 8-bit processors don't care much about endianness.
35304  This is not the case for the standard 8051 which only has an instruction
35305  to increment its 
35306 \emph on
35307 dptr
35308 \emph default
35309
35310 \begin_inset LatexCommand \index{DPTR}
35311
35312 \end_inset
35313
35314 -datapointer
35315 \emph on
35316  
35317 \emph default
35318 so little-endian is the more efficient byte order.
35319 \end_layout
35320
35321 \end_inset
35322
35323
35324 \begin_inset LatexCommand \index{little-endian}
35325
35326 \end_inset
35327
35328
35329 \begin_inset LatexCommand \index{Endianness}
35330
35331 \end_inset
35332
35333  format (i.e.
35334  lowest order first).
35335 \end_layout
35336
35337 \begin_layout Subsection
35338 Highest Order Bit
35339 \begin_inset LatexCommand \index{Highest Order Bit}
35340
35341 \end_inset
35342
35343  / Any Order Bit
35344 \begin_inset LatexCommand \index{Any Order Bit}
35345
35346 \end_inset
35347
35348
35349 \end_layout
35350
35351 \begin_layout Standard
35352 It is frequently required to obtain the highest order bit of an integral
35353  type (long, int, short or char types).
35354  Also obtaining any other order bit is not uncommon.
35355  SDCC recognizes the following expressions to yield the highest order bit
35356  and generates optimized code for it, e.g.:
35357 \end_layout
35358
35359 \begin_layout Verse
35360
35361 \family typewriter
35362 unsigned int gint; 
35363 \newline
35364
35365 \newline
35366 foo () { 
35367 \newline
35368 \InsetSpace ~
35369 \InsetSpace ~
35370 unsigned char hob1, aob1; 
35371 \newline
35372 \InsetSpace ~
35373 \InsetSpace ~
35374 bit hob2, hob3, aob2,
35375  aob3; 
35376 \newline
35377 \InsetSpace ~
35378 \InsetSpace ~
35379 ...
35380  
35381 \newline
35382 \InsetSpace ~
35383 \InsetSpace ~
35384 hob1 = (gint >> 15) & 1; 
35385 \newline
35386 \InsetSpace ~
35387 \InsetSpace ~
35388 hob2 = (gint >> 15) & 1; 
35389 \newline
35390 \InsetSpace ~
35391 \InsetSpace ~
35392 hob3 = gint & 0x8000;
35393  
35394 \newline
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 aob1 = (gint >> 9) & 1; 
35398 \newline
35399 \InsetSpace ~
35400 \InsetSpace ~
35401 aob2 = (gint >> 8) & 1; 
35402 \newline
35403 \InsetSpace ~
35404 \InsetSpace ~
35405 aob3 = gint & 0x0800; 
35406 \newline
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 ..
35410  
35411 \newline
35412 }
35413 \end_layout
35414
35415 \begin_layout Standard
35416 will generate the following code:
35417 \end_layout
35418
35419 \begin_layout Verse
35420
35421 \family typewriter
35422 \InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426 \InsetSpace ~
35427 \InsetSpace ~
35428 \InsetSpace ~
35429 \InsetSpace ~
35430 \InsetSpace ~
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 \InsetSpace ~
35444 \InsetSpace ~
35445 \InsetSpace ~
35446 \InsetSpace ~
35447  61 ;\InsetSpace ~
35448  hob.c 7 
35449 \newline
35450 000A E5*01\InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 \InsetSpace ~
35454 \InsetSpace ~
35455 \InsetSpace ~
35456 \InsetSpace ~
35457 \InsetSpace ~
35458 \InsetSpace ~
35459 \InsetSpace ~
35460 \InsetSpace ~
35461 \InsetSpace ~
35462 \InsetSpace ~
35463 \InsetSpace ~
35464 \InsetSpace ~
35465  62\InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469 \InsetSpace ~
35470 \InsetSpace ~
35471 \InsetSpace ~
35472 \InsetSpace ~
35473  mov\InsetSpace ~
35474 \InsetSpace ~
35475  a,(_gint + 1) 
35476 \newline
35477 000C 23\InsetSpace ~
35478 \InsetSpace ~
35479 \InsetSpace ~
35480 \InsetSpace ~
35481 \InsetSpace ~
35482 \InsetSpace ~
35483 \InsetSpace ~
35484 \InsetSpace ~
35485 \InsetSpace ~
35486 \InsetSpace ~
35487 \InsetSpace ~
35488 \InsetSpace ~
35489 \InsetSpace ~
35490 \InsetSpace ~
35491 \InsetSpace ~
35492 \InsetSpace ~
35493 \InsetSpace ~
35494 \InsetSpace ~
35495  63\InsetSpace ~
35496 \InsetSpace ~
35497 \InsetSpace ~
35498 \InsetSpace ~
35499 \InsetSpace ~
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 \InsetSpace ~
35503  rl\InsetSpace ~
35504 \InsetSpace ~
35505 \InsetSpace ~
35506  a 
35507 \newline
35508 000D 54 01\InsetSpace ~
35509 \InsetSpace ~
35510 \InsetSpace ~
35511 \InsetSpace ~
35512 \InsetSpace ~
35513 \InsetSpace ~
35514 \InsetSpace ~
35515 \InsetSpace ~
35516 \InsetSpace ~
35517 \InsetSpace ~
35518 \InsetSpace ~
35519 \InsetSpace ~
35520 \InsetSpace ~
35521 \InsetSpace ~
35522 \InsetSpace ~
35523
35524  64\InsetSpace ~
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 \InsetSpace ~
35531 \InsetSpace ~
35532  anl\InsetSpace ~
35533 \InsetSpace ~
35534  a,#0x01 
35535 \newline
35536 000F F5*02\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  65\InsetSpace ~
35552 \InsetSpace ~
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 \InsetSpace ~
35558 \InsetSpace ~
35559  mov\InsetSpace ~
35560 \InsetSpace ~
35561  _foo_hob1_1_1,a 
35562 \newline
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 \InsetSpace ~
35569 \InsetSpace ~
35570 \InsetSpace ~
35571 \InsetSpace ~
35572 \InsetSpace ~
35573 \InsetSpace ~
35574 \InsetSpace ~
35575 \InsetSpace ~
35576 \InsetSpace ~
35577 \InsetSpace ~
35578 \InsetSpace ~
35579 \InsetSpace ~
35580 \InsetSpace ~
35581 \InsetSpace ~
35582 \InsetSpace ~
35583 \InsetSpace ~
35584 \InsetSpace ~
35585 \InsetSpace ~
35586 \InsetSpace ~
35587 \InsetSpace ~
35588  66 ;\InsetSpace ~
35589  hob.c 8 
35590 \newline
35591 0011 E5*01\InsetSpace ~
35592 \InsetSpace ~
35593 \InsetSpace ~
35594 \InsetSpace ~
35595 \InsetSpace ~
35596 \InsetSpace ~
35597 \InsetSpace ~
35598 \InsetSpace ~
35599 \InsetSpace ~
35600 \InsetSpace ~
35601 \InsetSpace ~
35602 \InsetSpace ~
35603 \InsetSpace ~
35604 \InsetSpace ~
35605 \InsetSpace ~
35606
35607  67\InsetSpace ~
35608 \InsetSpace ~
35609 \InsetSpace ~
35610 \InsetSpace ~
35611 \InsetSpace ~
35612 \InsetSpace ~
35613 \InsetSpace ~
35614 \InsetSpace ~
35615  mov\InsetSpace ~
35616 \InsetSpace ~
35617  a,(_gint + 1) 
35618 \newline
35619 0013 33\InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623 \InsetSpace ~
35624 \InsetSpace ~
35625 \InsetSpace ~
35626 \InsetSpace ~
35627 \InsetSpace ~
35628 \InsetSpace ~
35629 \InsetSpace ~
35630 \InsetSpace ~
35631 \InsetSpace ~
35632 \InsetSpace ~
35633 \InsetSpace ~
35634 \InsetSpace ~
35635 \InsetSpace ~
35636 \InsetSpace ~
35637  68\InsetSpace ~
35638 \InsetSpace ~
35639 \InsetSpace ~
35640 \InsetSpace ~
35641 \InsetSpace ~
35642 \InsetSpace ~
35643 \InsetSpace ~
35644 \InsetSpace ~
35645  rlc\InsetSpace ~
35646 \InsetSpace ~
35647  a 
35648 \newline
35649 0014 92*00\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  69\InsetSpace ~
35665 \InsetSpace ~
35666 \InsetSpace ~
35667 \InsetSpace ~
35668 \InsetSpace ~
35669 \InsetSpace ~
35670 \InsetSpace ~
35671 \InsetSpace ~
35672  mov\InsetSpace ~
35673 \InsetSpace ~
35674  _foo_hob2_1_1,c
35675  
35676 \newline
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681 \InsetSpace ~
35682 \InsetSpace ~
35683 \InsetSpace ~
35684 \InsetSpace ~
35685 \InsetSpace ~
35686 \InsetSpace ~
35687 \InsetSpace ~
35688 \InsetSpace ~
35689 \InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 \InsetSpace ~
35693 \InsetSpace ~
35694 \InsetSpace ~
35695 \InsetSpace ~
35696 \InsetSpace ~
35697 \InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700 \InsetSpace ~
35701 \InsetSpace ~
35702  66 ;\InsetSpace ~
35703  hob.c 9 
35704 \newline
35705 0016 E5*01\InsetSpace ~
35706 \InsetSpace ~
35707 \InsetSpace ~
35708 \InsetSpace ~
35709 \InsetSpace ~
35710 \InsetSpace ~
35711 \InsetSpace ~
35712 \InsetSpace ~
35713 \InsetSpace ~
35714 \InsetSpace ~
35715 \InsetSpace ~
35716 \InsetSpace ~
35717 \InsetSpace ~
35718 \InsetSpace ~
35719 \InsetSpace ~
35720  67\InsetSpace ~
35721 \InsetSpace ~
35722 \InsetSpace ~
35723 \InsetSpace ~
35724 \InsetSpace ~
35725 \InsetSpace ~
35726 \InsetSpace ~
35727 \InsetSpace ~
35728  mov\InsetSpace ~
35729 \InsetSpace ~
35730  a,(_gint + 1) 
35731 \newline
35732 0018 33\InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736 \InsetSpace ~
35737 \InsetSpace ~
35738 \InsetSpace ~
35739 \InsetSpace ~
35740 \InsetSpace ~
35741 \InsetSpace ~
35742 \InsetSpace ~
35743 \InsetSpace ~
35744 \InsetSpace ~
35745 \InsetSpace ~
35746 \InsetSpace ~
35747 \InsetSpace ~
35748 \InsetSpace ~
35749 \InsetSpace ~
35750  68\InsetSpace ~
35751 \InsetSpace ~
35752 \InsetSpace ~
35753 \InsetSpace ~
35754 \InsetSpace ~
35755 \InsetSpace ~
35756 \InsetSpace ~
35757 \InsetSpace ~
35758  rlc\InsetSpace ~
35759 \InsetSpace ~
35760  a 
35761 \newline
35762 0019 92*01\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
35778  69\InsetSpace ~
35779 \InsetSpace ~
35780 \InsetSpace ~
35781 \InsetSpace ~
35782 \InsetSpace ~
35783 \InsetSpace ~
35784 \InsetSpace ~
35785 \InsetSpace ~
35786  mov\InsetSpace ~
35787 \InsetSpace ~
35788  _foo_hob3_1_1,c 
35789 \newline
35790 \InsetSpace ~
35791 \InsetSpace ~
35792 \InsetSpace ~
35793 \InsetSpace ~
35794 \InsetSpace ~
35795 \InsetSpace ~
35796 \InsetSpace ~
35797 \InsetSpace ~
35798 \InsetSpace ~
35799 \InsetSpace ~
35800 \InsetSpace ~
35801 \InsetSpace ~
35802 \InsetSpace ~
35803 \InsetSpace ~
35804 \InsetSpace ~
35805 \InsetSpace ~
35806 \InsetSpace ~
35807 \InsetSpace ~
35808 \InsetSpace ~
35809 \InsetSpace ~
35810 \InsetSpace ~
35811 \InsetSpace ~
35812 \InsetSpace ~
35813 \InsetSpace ~
35814 \InsetSpace ~
35815  70 ;\InsetSpace ~
35816  hob.c 10 
35817 \newline
35818 001B E5*01\InsetSpace ~
35819 \InsetSpace ~
35820 \InsetSpace ~
35821 \InsetSpace ~
35822 \InsetSpace ~
35823 \InsetSpace ~
35824 \InsetSpace ~
35825 \InsetSpace ~
35826 \InsetSpace ~
35827 \InsetSpace ~
35828 \InsetSpace ~
35829 \InsetSpace ~
35830 \InsetSpace ~
35831 \InsetSpace ~
35832 \InsetSpace ~
35833  71\InsetSpace ~
35834 \InsetSpace ~
35835 \InsetSpace ~
35836 \InsetSpace ~
35837 \InsetSpace ~
35838 \InsetSpace ~
35839 \InsetSpace ~
35840 \InsetSpace ~
35841  mov\InsetSpace ~
35842 \InsetSpace ~
35843  a,(_gint + 1) 
35844 \newline
35845 001D
35846  03\InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 \InsetSpace ~
35850 \InsetSpace ~
35851 \InsetSpace ~
35852 \InsetSpace ~
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 \InsetSpace ~
35856 \InsetSpace ~
35857 \InsetSpace ~
35858 \InsetSpace ~
35859 \InsetSpace ~
35860 \InsetSpace ~
35861 \InsetSpace ~
35862 \InsetSpace ~
35863 \InsetSpace ~
35864  72\InsetSpace ~
35865 \InsetSpace ~
35866 \InsetSpace ~
35867 \InsetSpace ~
35868 \InsetSpace ~
35869 \InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872  rr\InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875  a 
35876 \newline
35877 001E 54 01\InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884 \InsetSpace ~
35885 \InsetSpace ~
35886 \InsetSpace ~
35887 \InsetSpace ~
35888 \InsetSpace ~
35889 \InsetSpace ~
35890 \InsetSpace ~
35891 \InsetSpace ~
35892  73\InsetSpace ~
35893 \InsetSpace ~
35894 \InsetSpace ~
35895 \InsetSpace ~
35896 \InsetSpace ~
35897 \InsetSpace ~
35898 \InsetSpace ~
35899 \InsetSpace ~
35900  anl\InsetSpace ~
35901 \InsetSpace ~
35902  a,#0x01 
35903 \newline
35904 0020 F5*03\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  74\InsetSpace ~
35920 \InsetSpace ~
35921 \InsetSpace ~
35922 \InsetSpace ~
35923 \InsetSpace ~
35924 \InsetSpace ~
35925 \InsetSpace ~
35926 \InsetSpace ~
35927  mov\InsetSpace ~
35928 \InsetSpace ~
35929  _foo_aob1_1_1,a
35930  
35931 \newline
35932 \InsetSpace ~
35933 \InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936 \InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941 \InsetSpace ~
35942 \InsetSpace ~
35943 \InsetSpace ~
35944 \InsetSpace ~
35945 \InsetSpace ~
35946 \InsetSpace ~
35947 \InsetSpace ~
35948 \InsetSpace ~
35949 \InsetSpace ~
35950 \InsetSpace ~
35951 \InsetSpace ~
35952 \InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956 \InsetSpace ~
35957  75 ;\InsetSpace ~
35958  hob.c 11 
35959 \newline
35960 0022 E5*01\InsetSpace ~
35961 \InsetSpace ~
35962 \InsetSpace ~
35963 \InsetSpace ~
35964 \InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969 \InsetSpace ~
35970 \InsetSpace ~
35971 \InsetSpace ~
35972 \InsetSpace ~
35973 \InsetSpace ~
35974 \InsetSpace ~
35975  76\InsetSpace ~
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983  mov\InsetSpace ~
35984 \InsetSpace ~
35985  a,(_gint + 1) 
35986 \newline
35987 0024 13\InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 \InsetSpace ~
35991 \InsetSpace ~
35992 \InsetSpace ~
35993 \InsetSpace ~
35994 \InsetSpace ~
35995 \InsetSpace ~
35996 \InsetSpace ~
35997 \InsetSpace ~
35998 \InsetSpace ~
35999 \InsetSpace ~
36000 \InsetSpace ~
36001 \InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005  77\InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013  rrc\InsetSpace ~
36014 \InsetSpace ~
36015  a 
36016 \newline
36017 0025 92*02\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
36033  78\InsetSpace ~
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 \InsetSpace ~
36037 \InsetSpace ~
36038 \InsetSpace ~
36039 \InsetSpace ~
36040 \InsetSpace ~
36041  mov\InsetSpace ~
36042 \InsetSpace ~
36043  _foo_aob2_1_1,c 
36044 \newline
36045 \InsetSpace ~
36046 \InsetSpace ~
36047 \InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050 \InsetSpace ~
36051 \InsetSpace ~
36052 \InsetSpace ~
36053 \InsetSpace ~
36054 \InsetSpace ~
36055 \InsetSpace ~
36056 \InsetSpace ~
36057 \InsetSpace ~
36058 \InsetSpace ~
36059 \InsetSpace ~
36060 \InsetSpace ~
36061 \InsetSpace ~
36062 \InsetSpace ~
36063 \InsetSpace ~
36064 \InsetSpace ~
36065 \InsetSpace ~
36066 \InsetSpace ~
36067 \InsetSpace ~
36068 \InsetSpace ~
36069 \InsetSpace ~
36070  79 ;\InsetSpace ~
36071  hob.c 12 
36072 \newline
36073 0027 E5*01\InsetSpace ~
36074 \InsetSpace ~
36075 \InsetSpace ~
36076 \InsetSpace ~
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 \InsetSpace ~
36081 \InsetSpace ~
36082 \InsetSpace ~
36083 \InsetSpace ~
36084 \InsetSpace ~
36085 \InsetSpace ~
36086 \InsetSpace ~
36087 \InsetSpace ~
36088  80\InsetSpace ~
36089 \InsetSpace ~
36090 \InsetSpace ~
36091 \InsetSpace ~
36092 \InsetSpace ~
36093 \InsetSpace ~
36094 \InsetSpace ~
36095 \InsetSpace ~
36096  mov\InsetSpace ~
36097 \InsetSpace ~
36098  a,(_gint + 1) 
36099 \newline
36100 0029
36101  A2 E3\InsetSpace ~
36102 \InsetSpace ~
36103 \InsetSpace ~
36104 \InsetSpace ~
36105 \InsetSpace ~
36106 \InsetSpace ~
36107 \InsetSpace ~
36108 \InsetSpace ~
36109 \InsetSpace ~
36110 \InsetSpace ~
36111 \InsetSpace ~
36112 \InsetSpace ~
36113 \InsetSpace ~
36114 \InsetSpace ~
36115 \InsetSpace ~
36116  81\InsetSpace ~
36117 \InsetSpace ~
36118 \InsetSpace ~
36119 \InsetSpace ~
36120 \InsetSpace ~
36121 \InsetSpace ~
36122 \InsetSpace ~
36123 \InsetSpace ~
36124  mov\InsetSpace ~
36125 \InsetSpace ~
36126  c,acc[3] 
36127 \newline
36128 002B 92*03\InsetSpace ~
36129 \InsetSpace ~
36130 \InsetSpace ~
36131 \InsetSpace ~
36132 \InsetSpace ~
36133 \InsetSpace ~
36134 \InsetSpace ~
36135 \InsetSpace ~
36136 \InsetSpace ~
36137 \InsetSpace ~
36138 \InsetSpace ~
36139 \InsetSpace ~
36140 \InsetSpace ~
36141 \InsetSpace ~
36142 \InsetSpace ~
36143  82\InsetSpace ~
36144 \InsetSpace ~
36145 \InsetSpace ~
36146 \InsetSpace ~
36147 \InsetSpace ~
36148 \InsetSpace ~
36149 \InsetSpace ~
36150 \InsetSpace ~
36151  mov\InsetSpace ~
36152 \InsetSpace ~
36153  _foo_aob3_1_1,c 
36154 \end_layout
36155
36156 \begin_layout Standard
36157 Other variations of these cases however will 
36158 \emph on
36159 not
36160 \emph default
36161  be recognized.
36162  They are standard C expressions, so I heartily recommend these be the only
36163  way to get the highest order bit, (it is portable).
36164  Of course it will be recognized even if it is embedded in other expressions,
36165  e.g.:
36166 \end_layout
36167
36168 \begin_layout Verse
36169
36170 \family typewriter
36171 xyz = gint + ((gint >> 15) & 1);
36172 \end_layout
36173
36174 \begin_layout Standard
36175 will still be recognized.
36176 \end_layout
36177
36178 \begin_layout Subsection
36179 Higher Order Byte
36180 \begin_inset LatexCommand \index{Higher Order Byte}
36181
36182 \end_inset
36183
36184  / Higher Order Word
36185 \begin_inset LatexCommand \index{Higher Order Word}
36186
36187 \end_inset
36188
36189
36190 \end_layout
36191
36192 \begin_layout Standard
36193 It is also frequently required to obtain a higher order byte or word of
36194  a larger integral type (long, int or short types).
36195  SDCC recognizes the following expressions to yield the higher order byte
36196  or word and generates optimized code for it, e.g.:
36197 \end_layout
36198
36199 \begin_layout Verse
36200
36201 \family typewriter
36202 unsigned int gint; 
36203 \newline
36204 unsigned long int glong; 
36205 \newline
36206
36207 \newline
36208 foo () { 
36209 \newline
36210 \InsetSpace ~
36211 \InsetSpace ~
36212 unsigned char hob1,
36213  hob2; 
36214 \newline
36215 \InsetSpace ~
36216 \InsetSpace ~
36217 unsigned int how1, how2; 
36218 \newline
36219 \InsetSpace ~
36220 \InsetSpace ~
36221 ...
36222  
36223 \newline
36224 \InsetSpace ~
36225 \InsetSpace ~
36226 hob1 = (gint >> 8) & 0xFF; 
36227 \newline
36228 \InsetSpace ~
36229 \InsetSpace ~
36230 hob2 = glong >> 24; 
36231 \newline
36232 \InsetSpace ~
36233 \InsetSpace ~
36234 how1 = (glong >> 16) & 0xFFFF;
36235  
36236 \newline
36237 \InsetSpace ~
36238 \InsetSpace ~
36239 how2 = glong >> 8; 
36240 \newline
36241 \InsetSpace ~
36242 \InsetSpace ~
36243 ..
36244  
36245 \newline
36246 }
36247 \end_layout
36248
36249 \begin_layout Standard
36250 will generate the following code:
36251 \end_layout
36252
36253 \begin_layout Verse
36254
36255 \family typewriter
36256 \InsetSpace ~
36257 \InsetSpace ~
36258 \InsetSpace ~
36259 \InsetSpace ~
36260 \InsetSpace ~
36261 \InsetSpace ~
36262 \InsetSpace ~
36263 \InsetSpace ~
36264 \InsetSpace ~
36265 \InsetSpace ~
36266 \InsetSpace ~
36267 \InsetSpace ~
36268 \InsetSpace ~
36269 \InsetSpace ~
36270 \InsetSpace ~
36271 \InsetSpace ~
36272 \InsetSpace ~
36273 \InsetSpace ~
36274 \InsetSpace ~
36275 \InsetSpace ~
36276 \InsetSpace ~
36277 \InsetSpace ~
36278 \InsetSpace ~
36279 \InsetSpace ~
36280 \InsetSpace ~
36281  91 ;\InsetSpace ~
36282  hob.c 15 
36283 \newline
36284 0037 85*01*06\InsetSpace ~
36285 \InsetSpace ~
36286 \InsetSpace ~
36287 \InsetSpace ~
36288 \InsetSpace ~
36289 \InsetSpace ~
36290 \InsetSpace ~
36291 \InsetSpace ~
36292 \InsetSpace ~
36293 \InsetSpace ~
36294 \InsetSpace ~
36295 \InsetSpace ~
36296  92\InsetSpace ~
36297 \InsetSpace ~
36298 \InsetSpace ~
36299 \InsetSpace ~
36300 \InsetSpace ~
36301 \InsetSpace ~
36302 \InsetSpace ~
36303 \InsetSpace ~
36304  mov\InsetSpace ~
36305 \InsetSpace ~
36306  _foo_hob1_1_1,(_gint + 1) 
36307 \newline
36308 \InsetSpace ~
36309 \InsetSpace ~
36310 \InsetSpace ~
36311 \InsetSpace ~
36312 \InsetSpace ~
36313 \InsetSpace ~
36314 \InsetSpace ~
36315 \InsetSpace ~
36316 \InsetSpace ~
36317 \InsetSpace ~
36318 \InsetSpace ~
36319 \InsetSpace ~
36320 \InsetSpace ~
36321 \InsetSpace ~
36322 \InsetSpace ~
36323 \InsetSpace ~
36324 \InsetSpace ~
36325 \InsetSpace ~
36326 \InsetSpace ~
36327 \InsetSpace ~
36328 \InsetSpace ~
36329 \InsetSpace ~
36330 \InsetSpace ~
36331 \InsetSpace ~
36332 \InsetSpace ~
36333  93 ;\InsetSpace ~
36334  hob.c
36335  16 
36336 \newline
36337 003A 85*05*07\InsetSpace ~
36338 \InsetSpace ~
36339 \InsetSpace ~
36340 \InsetSpace ~
36341 \InsetSpace ~
36342 \InsetSpace ~
36343 \InsetSpace ~
36344 \InsetSpace ~
36345 \InsetSpace ~
36346 \InsetSpace ~
36347 \InsetSpace ~
36348 \InsetSpace ~
36349  94\InsetSpace ~
36350 \InsetSpace ~
36351 \InsetSpace ~
36352 \InsetSpace ~
36353 \InsetSpace ~
36354 \InsetSpace ~
36355 \InsetSpace ~
36356 \InsetSpace ~
36357  mov\InsetSpace ~
36358 \InsetSpace ~
36359  _foo_hob2_1_1,(_glong + 3) 
36360 \newline
36361 \InsetSpace ~
36362 \InsetSpace ~
36363 \InsetSpace ~
36364 \InsetSpace ~
36365 \InsetSpace ~
36366 \InsetSpace ~
36367 \InsetSpace ~
36368 \InsetSpace ~
36369 \InsetSpace ~
36370 \InsetSpace ~
36371 \InsetSpace ~
36372 \InsetSpace ~
36373 \InsetSpace ~
36374 \InsetSpace ~
36375 \InsetSpace ~
36376 \InsetSpace ~
36377 \InsetSpace ~
36378 \InsetSpace ~
36379 \InsetSpace ~
36380 \InsetSpace ~
36381 \InsetSpace ~
36382 \InsetSpace ~
36383 \InsetSpace ~
36384 \InsetSpace ~
36385 \InsetSpace ~
36386  95 ;\InsetSpace ~
36387  hob.c 17 
36388 \newline
36389 003D 85*04*08\InsetSpace ~
36390 \InsetSpace ~
36391 \InsetSpace ~
36392 \InsetSpace ~
36393 \InsetSpace ~
36394 \InsetSpace ~
36395 \InsetSpace ~
36396 \InsetSpace ~
36397 \InsetSpace ~
36398 \InsetSpace ~
36399 \InsetSpace ~
36400 \InsetSpace ~
36401
36402  96\InsetSpace ~
36403 \InsetSpace ~
36404 \InsetSpace ~
36405 \InsetSpace ~
36406 \InsetSpace ~
36407 \InsetSpace ~
36408 \InsetSpace ~
36409 \InsetSpace ~
36410  mov\InsetSpace ~
36411 \InsetSpace ~
36412  _foo_how1_1_1,(_glong + 2) 
36413 \newline
36414 0040 85*05*09\InsetSpace ~
36415 \InsetSpace ~
36416 \InsetSpace ~
36417 \InsetSpace ~
36418 \InsetSpace ~
36419 \InsetSpace ~
36420 \InsetSpace ~
36421 \InsetSpace ~
36422 \InsetSpace ~
36423 \InsetSpace ~
36424 \InsetSpace ~
36425 \InsetSpace ~
36426  97\InsetSpace ~
36427 \InsetSpace ~
36428 \InsetSpace ~
36429 \InsetSpace ~
36430 \InsetSpace ~
36431 \InsetSpace ~
36432 \InsetSpace ~
36433 \InsetSpace ~
36434  mov\InsetSpace ~
36435 \InsetSpace ~
36436  (_foo_how1_1_1 +
36437  1),(_glong + 3) 
36438 \newline
36439 0043 85*03*0A\InsetSpace ~
36440 \InsetSpace ~
36441 \InsetSpace ~
36442 \InsetSpace ~
36443 \InsetSpace ~
36444 \InsetSpace ~
36445 \InsetSpace ~
36446 \InsetSpace ~
36447 \InsetSpace ~
36448 \InsetSpace ~
36449 \InsetSpace ~
36450 \InsetSpace ~
36451  98\InsetSpace ~
36452 \InsetSpace ~
36453 \InsetSpace ~
36454 \InsetSpace ~
36455 \InsetSpace ~
36456 \InsetSpace ~
36457 \InsetSpace ~
36458 \InsetSpace ~
36459  mov\InsetSpace ~
36460 \InsetSpace ~
36461  _foo_how2_1_1,(_glong + 1) 
36462 \newline
36463 0046 85*04*0B\InsetSpace ~
36464 \InsetSpace ~
36465 \InsetSpace ~
36466 \InsetSpace ~
36467 \InsetSpace ~
36468 \InsetSpace ~
36469 \InsetSpace ~
36470 \InsetSpace ~
36471 \InsetSpace ~
36472 \InsetSpace ~
36473 \InsetSpace ~
36474 \InsetSpace ~
36475
36476  99\InsetSpace ~
36477 \InsetSpace ~
36478 \InsetSpace ~
36479 \InsetSpace ~
36480 \InsetSpace ~
36481 \InsetSpace ~
36482 \InsetSpace ~
36483 \InsetSpace ~
36484  mov\InsetSpace ~
36485 \InsetSpace ~
36486  (_foo_how2_1_1 + 1),(_glong + 2) 
36487 \end_layout
36488
36489 \begin_layout Standard
36490 Again, variations of these cases may 
36491 \emph on
36492 not
36493 \emph default
36494  be recognized.
36495  They are standard C expressions, so I heartily recommend these be the only
36496  way to get the higher order byte/word, (it is portable).
36497  Of course it will be recognized even if it is embedded in other expressions,
36498  e.g.:
36499 \end_layout
36500
36501 \begin_layout Verse
36502
36503 \family typewriter
36504 xyz = gint + ((gint >> 8) & 0xFF);
36505 \end_layout
36506
36507 \begin_layout Standard
36508 will still be recognized.
36509 \end_layout
36510
36511 \begin_layout Subsection
36512 Peephole Optimizer
36513 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36514
36515 \end_inset
36516
36517
36518 \begin_inset LatexCommand \index{Peephole optimizer}
36519
36520 \end_inset
36521
36522
36523 \end_layout
36524
36525 \begin_layout Standard
36526 The compiler uses a rule based, pattern matching and re-writing mechanism
36527  for peep-hole optimization.
36528  It is inspired by 
36529 \emph on
36530 copt
36531 \emph default
36532  a peep-hole optimizer by Christopher W.
36533  Fraser (cwfraser\InsetSpace ~
36534 @\InsetSpace ~
36535 microsoft.com).
36536  A default set of rules are compiled into the compiler, additional rules
36537  may be added with the 
36538 \emph on
36539 -
36540 \begin_inset ERT
36541 status collapsed
36542
36543 \begin_layout Standard
36544
36545
36546 \backslash
36547 /
36548 \end_layout
36549
36550 \end_inset
36551
36552 -peep-file
36553 \begin_inset LatexCommand \index{-\/-peep-file}
36554
36555 \end_inset
36556
36557  <filename>
36558 \emph default
36559  option.
36560  The rule language is best illustrated with examples.
36561 \end_layout
36562
36563 \begin_layout Verse
36564
36565 \family typewriter
36566 replace { 
36567 \newline
36568 \InsetSpace ~
36569 \InsetSpace ~
36570 mov %1,a 
36571 \newline
36572 \InsetSpace ~
36573 \InsetSpace ~
36574 mov a,%1
36575 \newline
36576 } by {
36577 \newline
36578 \InsetSpace ~
36579 \InsetSpace ~
36580 mov %1,a
36581 \newline
36582 }
36583 \end_layout
36584
36585 \begin_layout Standard
36586 The above rule will change the following assembly
36587 \begin_inset LatexCommand \index{Assembler routines}
36588
36589 \end_inset
36590
36591  sequence:
36592 \end_layout
36593
36594 \begin_layout Verse
36595
36596 \family typewriter
36597 mov r1,a 
36598 \newline
36599 mov a,r1
36600 \end_layout
36601
36602 \begin_layout Standard
36603 to
36604 \end_layout
36605
36606 \begin_layout Verse
36607
36608 \family typewriter
36609 mov r1,a
36610 \end_layout
36611
36612 \begin_layout Standard
36613 Note: All occurrences of a 
36614 \emph on
36615 %n
36616 \emph default
36617  (pattern variable) must denote the same string.
36618  With the above rule, the assembly sequence:
36619 \end_layout
36620
36621 \begin_layout Verse
36622
36623 \family typewriter
36624 mov r1,a 
36625 \newline
36626 mov a,r2
36627 \end_layout
36628
36629 \begin_layout Standard
36630 will remain unmodified.
36631 \newline
36632
36633 \newline
36634 Other special case optimizations may be added by the
36635  user (via 
36636 \emph on
36637 -
36638 \begin_inset ERT
36639 status collapsed
36640
36641 \begin_layout Standard
36642
36643
36644 \backslash
36645 /
36646 \end_layout
36647
36648 \end_inset
36649
36650 -peep-file option
36651 \emph default
36652 ).
36653  E.g.
36654  some variants of the 8051 MCU
36655 \begin_inset LatexCommand \index{MCS51 variants}
36656
36657 \end_inset
36658
36659  allow only 
36660 \family typewriter
36661 ajmp
36662 \family default
36663  and 
36664 \family typewriter
36665 acall
36666 \family default
36667 .
36668  The following two rules will change all 
36669 \family typewriter
36670 ljmp
36671 \family default
36672  and 
36673 \family typewriter
36674 lcall
36675 \family default
36676  to 
36677 \family typewriter
36678 ajmp
36679 \family default
36680  and 
36681 \family typewriter
36682 acall
36683 \end_layout
36684
36685 \begin_layout Verse
36686
36687 \family typewriter
36688 replace { lcall %1 } by { acall %1 } 
36689 \newline
36690 replace { ljmp %1 } by { ajmp %1 }
36691 \end_layout
36692
36693 \begin_layout Standard
36694 (NOTE: from version 2.7.3 on, you can use option -
36695 \emph on
36696
36697 \begin_inset ERT
36698 status collapsed
36699
36700 \begin_layout Standard
36701
36702
36703 \backslash
36704 /
36705 \end_layout
36706
36707 \end_inset
36708
36709
36710 \emph default
36711 -acall-ajmp
36712 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36713
36714 \end_inset
36715
36716 , which also takes care of aligning the interrupt vectors properly.)
36717 \newline
36718
36719 \end_layout
36720
36721 \begin_layout Standard
36722 The 
36723 \emph on
36724 inline-assembler code
36725 \emph default
36726  is also passed through the peep hole optimizer, thus the peephole optimizer
36727  can also be used as an assembly level macro expander.
36728  The rules themselves are MCU dependent whereas the rule language infra-structur
36729 e is MCU independent.
36730  Peephole optimization rules for other MCU can be easily programmed using
36731  the rule language.
36732 \newline
36733
36734 \newline
36735 The syntax for a rule is as follows:
36736 \end_layout
36737
36738 \begin_layout Verse
36739
36740 \family typewriter
36741 rule := replace [ restart ] '{' <assembly sequence> '
36742 \backslash
36743 n' 
36744 \newline
36745 \InsetSpace ~
36746  \InsetSpace ~
36747  \InsetSpace ~
36748  \InsetSpace ~
36749  \InsetSpace ~
36750  \InsetSpace ~
36751  \InsetSpace ~
36752  \InsetSpace ~
36753  \InsetSpace ~
36754  \InsetSpace ~
36755  \InsetSpace ~
36756  \InsetSpace ~
36757  \InsetSpace ~
36758  \InsetSpace ~
36759  '}' by '{' '
36760 \backslash
36761 n' 
36762 \newline
36763 \InsetSpace ~
36764  \InsetSpace ~
36765  \InsetSpace ~
36766  \InsetSpace ~
36767  \InsetSpace ~
36768  \InsetSpace ~
36769  \InsetSpace ~
36770  \InsetSpace ~
36771  \InsetSpace ~
36772  \InsetSpace ~
36773  \InsetSpace ~
36774  \InsetSpace ~
36775  \InsetSpace ~
36776  \InsetSpace ~
36777  \InsetSpace ~
36778  \InsetSpace ~
36779  <assembly sequence> '
36780 \backslash
36781 n' 
36782 \newline
36783 \InsetSpace ~
36784  \InsetSpace ~
36785  \InsetSpace ~
36786  \InsetSpace ~
36787  \InsetSpace ~
36788  \InsetSpace ~
36789  \InsetSpace ~
36790  \InsetSpace ~
36791  \InsetSpace ~
36792  \InsetSpace ~
36793  \InsetSpace ~
36794  \InsetSpace ~
36795  \InsetSpace ~
36796  \InsetSpace ~
36797  '}' [if <functionName> ] '
36798 \backslash
36799 n' 
36800 \end_layout
36801
36802 \begin_layout Standard
36803 <assembly sequence> := assembly instruction (each instruction including
36804  labels must be on a separate line).
36805 \newline
36806
36807 \newline
36808 The optimizer will apply to the rules
36809  one by one from the top in the sequence of their appearance, it will terminate
36810  when all rules are exhausted.
36811  If the 'restart' option is specified, then the optimizer will start matching
36812  the rules again from the top, this option for a rule is expensive (performance)
36813 , it is intended to be used in situations where a transformation will trigger
36814  the same rule again.
36815  An example of this (not a good one, it has side effects) is the following
36816  rule:
36817 \end_layout
36818
36819 \begin_layout Verse
36820
36821 \family typewriter
36822 replace restart { 
36823 \newline
36824 \InsetSpace ~
36825 \InsetSpace ~
36826 pop %1 
36827 \newline
36828 \InsetSpace ~
36829 \InsetSpace ~
36830 push %1 } by { 
36831 \newline
36832 \InsetSpace ~
36833 \InsetSpace ~
36834 ; nop 
36835 \newline
36836 }
36837 \end_layout
36838
36839 \begin_layout Standard
36840 Note that the replace pattern cannot be a blank, but can be a comment line.
36841  Without the 'restart' option only the innermost 'pop' 'push' pair would
36842  be eliminated, i.e.:
36843 \end_layout
36844
36845 \begin_layout Verse
36846
36847 \family typewriter
36848 pop ar1 
36849 \newline
36850 pop ar2 
36851 \newline
36852 push ar2 
36853 \newline
36854 push ar1
36855 \end_layout
36856
36857 \begin_layout Standard
36858 would result in:
36859 \end_layout
36860
36861 \begin_layout Verse
36862
36863 \family typewriter
36864 pop ar1 
36865 \newline
36866 ; nop 
36867 \newline
36868 push ar1
36869 \end_layout
36870
36871 \begin_layout Standard
36872
36873 \emph on
36874 with
36875 \emph default
36876  the restart option the rule will be applied again to the resulting code
36877  and then all the pop-push pairs will be eliminated to yield:
36878 \end_layout
36879
36880 \begin_layout Verse
36881
36882 \family typewriter
36883 ; nop 
36884 \newline
36885 ; nop
36886 \end_layout
36887
36888 \begin_layout Standard
36889 A conditional function can be attached to a rule.
36890  Attaching rules are somewhat more involved, let me illustrate this with
36891  an example.
36892 \end_layout
36893
36894 \begin_layout Verse
36895
36896 \family typewriter
36897 replace { 
36898 \newline
36899 \InsetSpace ~
36900  \InsetSpace ~
36901  \InsetSpace ~
36902 ljmp %5 
36903 \newline
36904 %2:
36905 \newline
36906 } by { 
36907 \newline
36908 \InsetSpace ~
36909  \InsetSpace ~
36910  \InsetSpace ~
36911 sjmp %5 
36912 \newline
36913 %2:
36914 \newline
36915 } if labelInRange
36916 \end_layout
36917
36918 \begin_layout Standard
36919 The optimizer does a look-up of a function name table defined in function
36920  
36921 \emph on
36922 callFuncByName
36923 \emph default
36924  in the source file SDCCpeeph.c, with the name 
36925 \emph on
36926 labelInRange
36927 \emph default
36928 .
36929  If it finds a corresponding entry the function is called.
36930  Note there can be no parameters specified for these functions, in this
36931  case the use of 
36932 \emph on
36933 %5
36934 \emph default
36935  is crucial, since the function 
36936 \emph on
36937 labelInRange
36938 \emph default
36939  expects to find the label in that particular variable (the hash table containin
36940 g the variable bindings is passed as a parameter).
36941  If you want to code more such functions, take a close look at the function
36942  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36943  Currently implemented are 
36944 \emph on
36945 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36946  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36947 \emph default
36948 and
36949 \emph on
36950  notVolatile
36951 \emph default
36952 .
36953 \end_layout
36954
36955 \begin_layout Standard
36956 I know this whole thing is a little kludgey, but maybe some day we will
36957  have some better means.
36958  If you are looking at this file, you will see the default rules that are
36959  compiled into the compiler, you can add your own rules in the default set
36960  there if you get tired of specifying the -
36961 \begin_inset ERT
36962 status collapsed
36963
36964 \begin_layout Standard
36965
36966
36967 \backslash
36968 /
36969 \end_layout
36970
36971 \end_inset
36972
36973 -peep-file option.
36974 \end_layout
36975
36976 \begin_layout Section
36977 ANSI-Compliance
36978 \begin_inset LatexCommand \index{ANSI-compliance}
36979
36980 \end_inset
36981
36982
36983 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36984
36985 \end_inset
36986
36987
36988 \end_layout
36989
36990 \begin_layout Standard
36991 The latest publically available version of the standard 
36992 \emph on
36993 ISO/IEC 9899 - Programming languages - C
36994 \emph default
36995  should be available at: 
36996 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36997
36998 \end_inset
36999
37000 .
37001 \newline
37002
37003 \end_layout
37004
37005 \begin_layout Standard
37006 Deviations from the compliance:
37007 \end_layout
37008
37009 \begin_layout Itemize
37010 functions are not reentrant
37011 \begin_inset LatexCommand \index{reentrant}
37012
37013 \end_inset
37014
37015  unless explicitly declared as such or the 
37016 \series bold
37017 -
37018 \begin_inset ERT
37019 status collapsed
37020
37021 \begin_layout Standard
37022
37023
37024 \backslash
37025 /
37026 \end_layout
37027
37028 \end_inset
37029
37030 -stack-auto
37031 \begin_inset LatexCommand \index{-\/-stack-auto}
37032
37033 \end_inset
37034
37035
37036 \series default
37037  command line option is specified.
37038 \end_layout
37039
37040 \begin_layout Itemize
37041 structures
37042 \begin_inset LatexCommand \index{struct}
37043
37044 \end_inset
37045
37046  and unions
37047 \begin_inset LatexCommand \index{union}
37048
37049 \end_inset
37050
37051  cannot be assigned values directly, cannot be passed as function parameters
37052  or assigned to each other and cannot be a return value
37053 \begin_inset LatexCommand \index{return value}
37054
37055 \end_inset
37056
37057  from a function, e.g.:
37058 \end_layout
37059
37060 \begin_deeper
37061 \begin_layout Verse
37062
37063 \family typewriter
37064 struct s { ...
37065  }; 
37066 \newline
37067 struct s s1, s2; 
37068 \newline
37069 foo() 
37070 \newline
37071
37072 \newline
37073 \InsetSpace ~
37074 \InsetSpace ~
37075 \InsetSpace ~
37076 \InsetSpace ~
37077 ...
37078  
37079 \newline
37080 \InsetSpace ~
37081 \InsetSpace ~
37082 \InsetSpace ~
37083 \InsetSpace ~
37084 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
37085 \newline
37086 \InsetSpace ~
37087 \InsetSpace ~
37088 \InsetSpace ~
37089 \InsetSpace ~
37090 ...
37091  
37092 \newline
37093 }
37094 \newline
37095
37096 \series bold
37097 struct
37098 \series default
37099  s foo1 (
37100 \series bold
37101 struct
37102 \series default
37103  s parms) /* invalid in SDCC although allowed in ANSI */
37104 \newline
37105
37106 \newline
37107 \InsetSpace ~
37108 \InsetSpace ~
37109 \InsetSpace ~
37110 \InsetSpace ~
37111 struct s rets;
37112  
37113 \newline
37114 \InsetSpace ~
37115 \InsetSpace ~
37116 \InsetSpace ~
37117 \InsetSpace ~
37118 ...
37119  
37120 \newline
37121 \InsetSpace ~
37122 \InsetSpace ~
37123 \InsetSpace ~
37124 \InsetSpace ~
37125 return rets; /* is invalid in SDCC although allowed in ANSI */ 
37126 \newline
37127 }
37128 \end_layout
37129
37130 \end_deeper
37131 \begin_layout Itemize
37132 initialization of structure arrays must be fully braced.
37133 \end_layout
37134
37135 \begin_deeper
37136 \begin_layout Verse
37137
37138 \family typewriter
37139 struct s { char x } a[] = {1, 2};\InsetSpace ~
37140 \InsetSpace ~
37141 \InsetSpace ~
37142 \InsetSpace ~
37143 \InsetSpace ~
37144 /* invalid in SDCC */
37145 \newline
37146 struct s { char x
37147  } a[] = {{1}, {2}}; /* OK */
37148 \end_layout
37149
37150 \end_deeper
37151 \begin_layout Itemize
37152 'long long
37153 \begin_inset LatexCommand \index{long long (not supported)}
37154
37155 \end_inset
37156
37157 ' (64 bit integers
37158 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37159
37160 \end_inset
37161
37162 ) not supported.
37163 \end_layout
37164
37165 \begin_layout Itemize
37166 'double
37167 \begin_inset LatexCommand \index{double (not supported)}
37168
37169 \end_inset
37170
37171 ' precision floating point 
37172 \begin_inset LatexCommand \index{Floating point support}
37173
37174 \end_inset
37175
37176 not supported.
37177 \end_layout
37178
37179 \begin_layout Itemize
37180 Old K&R style
37181 \begin_inset LatexCommand \index{K\&R style}
37182
37183 \end_inset
37184
37185  function declarations are NOT allowed.
37186 \end_layout
37187
37188 \begin_deeper
37189 \begin_layout Verse
37190
37191 \family typewriter
37192 foo(i,j) /* this old style of function declarations */ 
37193 \newline
37194 int i,j; /* is valid
37195  in ANSI but not valid in SDCC */ 
37196 \newline
37197
37198 \newline
37199 \InsetSpace ~
37200 \InsetSpace ~
37201 \InsetSpace ~
37202 \InsetSpace ~
37203 ...
37204  
37205 \newline
37206 }
37207 \end_layout
37208
37209 \end_deeper
37210 \begin_layout Itemize
37211 Most enhancements in C99 are not supported, e.g.:
37212 \end_layout
37213
37214 \begin_deeper
37215 \begin_layout Verse
37216
37217 \family typewriter
37218 for (
37219 \series bold
37220 int
37221 \series default
37222  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37223 \end_layout
37224
37225 \end_deeper
37226 \begin_layout Itemize
37227 But some have been added recently in SDCC 2.7.0.
37228  They must be considered alpha quality however.
37229 \end_layout
37230
37231 \begin_deeper
37232 \begin_layout Verse
37233
37234 \family typewriter
37235 \series bold
37236 inline
37237 \begin_inset LatexCommand \index{inline (not supported)}
37238
37239 \end_inset
37240
37241
37242 \series default
37243  int increment (int a) { return a+1; } /* inlines the increment without
37244  function call overhead */
37245 \newline
37246 int * 
37247 \series bold
37248 restrict
37249 \begin_inset LatexCommand \index{inline (not supported)}
37250
37251 \end_inset
37252
37253
37254 \series default
37255  p; /* accepted but ignored */
37256 \end_layout
37257
37258 \end_deeper
37259 \begin_layout Itemize
37260 Certain words that are valid identifiers in the standard may be reserved
37261  words in SDCC unless the 
37262 \series bold
37263 -
37264 \begin_inset ERT
37265 status collapsed
37266
37267 \begin_layout Standard
37268
37269
37270 \backslash
37271 /
37272 \end_layout
37273
37274 \end_inset
37275
37276 -std-c89
37277 \begin_inset LatexCommand \index{-\/-std-c89}
37278
37279 \end_inset
37280
37281  
37282 \series default
37283 or
37284 \series bold
37285  -
37286 \begin_inset ERT
37287 status collapsed
37288
37289 \begin_layout Standard
37290
37291
37292 \backslash
37293 /
37294 \end_layout
37295
37296 \end_inset
37297
37298 -std-c99
37299 \begin_inset LatexCommand \index{-\/-std-c99}
37300
37301 \end_inset
37302
37303
37304 \series default
37305  command line options are used.
37306  These may include (depending on the selected processor): 'at', 'banked',
37307  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37308 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37309  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37310  '_naked'.
37311  Compliant equivalents of these keywords are always available in a form
37312  that begin with two underscores
37313 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37314
37315 \end_inset
37316
37317 , f.e.
37318  '__data' instead of 'data'.
37319 \end_layout
37320
37321 \begin_layout Itemize
37322 Integer promotion of variable arguments is not performed if the argument
37323  is explicitly taypecasted unless the
37324 \series bold
37325  -
37326 \begin_inset ERT
37327 status collapsed
37328
37329 \begin_layout Standard
37330
37331
37332 \backslash
37333 /
37334 \end_layout
37335
37336 \end_inset
37337
37338 -std-c89
37339 \begin_inset LatexCommand \index{-\/-std-c89}
37340
37341 \end_inset
37342
37343  
37344 \series default
37345 or
37346 \series bold
37347  -
37348 \begin_inset ERT
37349 status collapsed
37350
37351 \begin_layout Standard
37352
37353
37354 \backslash
37355 /
37356 \end_layout
37357
37358 \end_inset
37359
37360 -std-c99
37361 \begin_inset LatexCommand \index{-\/-std-c99}
37362
37363 \end_inset
37364
37365
37366 \series default
37367  command line options are used.
37368 \end_layout
37369
37370 \begin_deeper
37371 \begin_layout Verse
37372
37373 \family typewriter
37374 void vararg_func (char *str, ...) { str; }
37375 \newline
37376
37377 \newline
37378 void main (void)
37379 \newline
37380 {
37381 \newline
37382 \InsetSpace ~
37383 \InsetSpace ~
37384 char c = 10;
37385 \newline
37386
37387 \newline
37388 \InsetSpace ~
37389 \InsetSpace ~
37390 /* argument
37391  u is promoted to int before
37392 \newline
37393 \InsetSpace ~
37394 \InsetSpace ~
37395 \InsetSpace ~
37396 * passing to function */
37397 \newline
37398 \InsetSpace ~
37399 \InsetSpace ~
37400 vararg_func ("%c", c);
37401 \newline
37402
37403 \newline
37404 \InsetSpace ~
37405 \InsetSpace ~
37406 /*
37407  argument u is not promoted to int,
37408 \newline
37409 \InsetSpace ~
37410 \InsetSpace ~
37411 \InsetSpace ~
37412 * it is passed as char to function
37413 \newline
37414 \InsetSpace ~
37415 \InsetSpace ~
37416 \InsetSpace ~
37417 * if
37418  --std-cXX is not defined;
37419 \newline
37420 \InsetSpace ~
37421 \InsetSpace ~
37422 \InsetSpace ~
37423 * is promoted to int before passing
37424 \newline
37425 \InsetSpace ~
37426 \InsetSpace ~
37427 \InsetSpace ~
37428 * to function
37429  if --std-cXX is defined */
37430 \newline
37431 \InsetSpace ~
37432 \InsetSpace ~
37433 vararg_func ("%bc", (char)u);
37434 \newline
37435 }
37436 \end_layout
37437
37438 \end_deeper
37439 \begin_layout Section
37440 Cyclomatic Complexity
37441 \begin_inset LatexCommand \index{Cyclomatic complexity}
37442
37443 \end_inset
37444
37445
37446 \end_layout
37447
37448 \begin_layout Standard
37449 Cyclomatic complexity of a function is defined as the number of independent
37450  paths the program can take during execution of the function.
37451  This is an important number since it defines the number test cases you
37452  have to generate to validate the function.
37453  The accepted industry standard for complexity number is 10, if the cyclomatic
37454  complexity reported by SDCC exceeds 10 you should think about simplification
37455  of the function logic.
37456  Note that the complexity level is not related to the number of lines of
37457  code in a function.
37458  Large functions can have low complexity, and small functions can have large
37459  complexity levels.
37460  
37461 \newline
37462
37463 \newline
37464 SDCC uses the following formula to compute the complexity:
37465 \newline
37466
37467 \end_layout
37468
37469 \begin_layout Standard
37470 complexity = (number of edges in control flow graph) - (number of nodes
37471  in control flow graph) + 2;
37472 \newline
37473
37474 \newline
37475 Having said that the industry standard is 10,
37476  you should be aware that in some cases it be may unavoidable to have a
37477  complexity level of less than 10.
37478  For example if you have switch statement with more than 10 case labels,
37479  each case label adds one to the complexity level.
37480  The complexity level is by no means an absolute measure of the algorithmic
37481  complexity of the function, it does however provide a good starting point
37482  for which functions you might look at for further optimization.
37483 \end_layout
37484
37485 \begin_layout Section
37486 Retargetting for other Processors
37487 \end_layout
37488
37489 \begin_layout Standard
37490 The issues for retargetting the compiler are far too numerous to be covered
37491  by this document.
37492  What follows is a brief description of each of the seven phases of the
37493  compiler and its MCU dependency.
37494 \end_layout
37495
37496 \begin_layout Itemize
37497 Parsing the source and building the annotated parse tree.
37498  This phase is largely MCU independent (except for the language extensions).
37499  Syntax & semantic checks are also done in this phase, along with some initial
37500  optimizations like back patching labels and the pattern matching optimizations
37501  like bit-rotation etc.
37502 \end_layout
37503
37504 \begin_layout Itemize
37505 The second phase involves generating an intermediate code which can be easy
37506  manipulated during the later phases.
37507  This phase is entirely MCU independent.
37508  The intermediate code generation assumes the target machine has unlimited
37509  number of registers, and designates them with the name iTemp.
37510  The compiler can be made to dump a human readable form of the code generated
37511  by using the -
37512 \begin_inset ERT
37513 status collapsed
37514
37515 \begin_layout Standard
37516
37517
37518 \backslash
37519 /
37520 \end_layout
37521
37522 \end_inset
37523
37524 -dumpraw option.
37525 \end_layout
37526
37527 \begin_layout Itemize
37528 This phase does the bulk of the standard optimizations and is also MCU independe
37529 nt.
37530  This phase can be broken down into several sub-phases:
37531 \newline
37532
37533 \newline
37534 Break down intermediate
37535  code (iCode) into basic blocks.
37536 \newline
37537 Do control flow & data flow analysis on the
37538  basic blocks.
37539 \newline
37540 Do local common subexpression elimination, then global subexpressio
37541 n elimination
37542 \newline
37543 Dead code elimination
37544 \newline
37545 Loop optimizations
37546 \newline
37547 If loop optimizations
37548  caused any changes then do 'global subexpression elimination' and 'dead
37549  code elimination' again.
37550 \end_layout
37551
37552 \begin_layout Itemize
37553 This phase determines the live-ranges; by live range I mean those iTemp
37554  variables defined by the compiler that still survive after all the optimization
37555 s.
37556  Live range analysis
37557 \begin_inset LatexCommand \index{Live range analysis}
37558
37559 \end_inset
37560
37561  is essential for register allocation, since these computation determines
37562  which of these iTemps will be assigned to registers, and for how long.
37563 \end_layout
37564
37565 \begin_layout Itemize
37566 Phase five is register allocation.
37567  There are two parts to this process.
37568 \newline
37569
37570 \newline
37571 The first part I call 'register packing'
37572  (for lack of a better term).
37573  In this case several MCU specific expression folding is done to reduce
37574  register pressure.
37575 \newline
37576
37577 \newline
37578 The second part is more MCU independent and deals with
37579  allocating registers to the remaining live ranges.
37580  A lot of MCU specific code does creep into this phase because of the limited
37581  number of index registers available in the 8051.
37582 \end_layout
37583
37584 \begin_layout Itemize
37585 The Code generation phase is (unhappily), entirely MCU dependent and very
37586  little (if any at all) of this code can be reused for other MCU.
37587  However the scheme for allocating a homogenized assembler operand for each
37588  iCode operand may be reused.
37589 \end_layout
37590
37591 \begin_layout Itemize
37592 As mentioned in the optimization section the peep-hole optimizer is rule
37593  based system, which can reprogrammed for other MCUs.
37594 \end_layout
37595
37596 \begin_layout Standard
37597 More information is available on SDCC Wiki
37598 \begin_inset LatexCommand \index{wiki}
37599
37600 \end_inset
37601
37602  (preliminary link 
37603 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37604
37605 \end_inset
37606
37607 ) and in the thread 
37608 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37609
37610 \end_inset
37611
37612  .
37613 \end_layout
37614
37615 \begin_layout Chapter
37616 Compiler internals
37617 \begin_inset LatexCommand \index{Compiler internals}
37618
37619 \end_inset
37620
37621
37622 \end_layout
37623
37624 \begin_layout Section
37625 The anatomy of the compiler
37626 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37627
37628 \end_inset
37629
37630
37631 \end_layout
37632
37633 \begin_layout Standard
37634
37635 \shape italic
37636 This is an excerpt from an article published in Circuit Cellar Magazine
37637  in 
37638 \series bold
37639 August 2000
37640 \series default
37641 .
37642  It's a little outdated (the compiler is much more efficient now and user/develo
37643 per friendly), but pretty well exposes the guts of it all.
37644 \shape default
37645
37646 \newline
37647
37648 \newline
37649 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37650  It is fairly easy to retarget for other 8-bit MCU.
37651  Here we take a look at some of the internals of the compiler.
37652  
37653 \end_layout
37654
37655 \begin_layout Paragraph*
37656 Parsing
37657 \begin_inset LatexCommand \index{Parsing}
37658
37659 \end_inset
37660
37661  
37662 \end_layout
37663
37664 \begin_layout Standard
37665 Parsing the input source file and creating an AST (Annotated Syntax Tree
37666 \begin_inset LatexCommand \index{Annotated syntax tree}
37667
37668 \end_inset
37669
37670 ).
37671  This phase also involves propagating types (annotating each node of the
37672  parse tree with type information) and semantic analysis.
37673  There are some MCU specific parsing rules.
37674  For example the storage classes, the extended storage classes are MCU specific
37675  while there may be a xdata storage class for 8051 there is no such storage
37676  class for z80 or Atmel AVR.
37677  SDCC allows MCU specific storage class extensions, i.e.
37678  xdata will be treated as a storage class specifier when parsing 8051 C
37679  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37680  C code.
37681 \end_layout
37682
37683 \begin_layout Paragraph*
37684 Generating iCode
37685 \begin_inset LatexCommand \index{iCode}
37686
37687 \end_inset
37688
37689
37690 \end_layout
37691
37692 \begin_layout Standard
37693 Intermediate code generation.
37694  In this phase the AST is broken down into three-operand form (iCode).
37695  These three operand forms are represented as doubly linked lists.
37696  ICode is the term given to the intermediate form generated by the compiler.
37697  ICode example section shows some examples of iCode generated for some simple
37698  C source functions.
37699 \end_layout
37700
37701 \begin_layout Paragraph*
37702 Optimizations
37703 \begin_inset LatexCommand \index{Optimizations}
37704
37705 \end_inset
37706
37707 .
37708 \end_layout
37709
37710 \begin_layout Standard
37711 Bulk of the target independent optimizations is performed in this phase.
37712  The optimizations include constant propagation, common sub-expression eliminati
37713 on, loop invariant code movement, strength reduction of loop induction variables
37714  and dead-code elimination.
37715 \end_layout
37716
37717 \begin_layout Paragraph*
37718 Live range analysis
37719 \begin_inset LatexCommand \index{Live range analysis}
37720
37721 \end_inset
37722
37723
37724 \end_layout
37725
37726 \begin_layout Standard
37727 During intermediate code generation phase, the compiler assumes the target
37728  machine has infinite number of registers and generates a lot of temporary
37729  variables.
37730  The live range computation determines the lifetime of each of these compiler-ge
37731 nerated temporaries.
37732  A picture speaks a thousand words.
37733  ICode example sections show the live range annotations for each of the
37734  operand.
37735  It is important to note here, each iCode is assigned a number in the order
37736  of its execution in the function.
37737  The live ranges are computed in terms of these numbers.
37738  The from number is the number of the iCode which first defines the operand
37739  and the to number signifies the iCode which uses this operand last.
37740 \end_layout
37741
37742 \begin_layout Paragraph*
37743 Register Allocation
37744 \begin_inset LatexCommand \index{Register allocation}
37745
37746 \end_inset
37747
37748
37749 \end_layout
37750
37751 \begin_layout Standard
37752 The register allocation determines the type and number of registers needed
37753  by each operand.
37754  In most MCUs only a few registers can be used for indirect addressing.
37755  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37756  address the internal ram and DPTR to indirectly address the external ram.
37757  The compiler will try to allocate the appropriate register to pointer variables
37758  if it can.
37759  ICode example section shows the operands annotated with the registers assigned
37760  to them.
37761  The compiler will try to keep operands in registers as much as possible;
37762  there are several schemes the compiler uses to do achieve this.
37763  When the compiler runs out of registers the compiler will check to see
37764  if there are any live operands which is not used or defined in the current
37765  basic block being processed, if there are any found then it will push that
37766  operand and use the registers in this block, the operand will then be popped
37767  at the end of the basic block.
37768  
37769 \end_layout
37770
37771 \begin_layout Standard
37772 There are other MCU specific considerations in this phase.
37773  Some MCUs have an accumulator; very short-lived operands could be assigned
37774  to the accumulator instead of a general-purpose register.
37775 \end_layout
37776
37777 \begin_layout Paragraph*
37778 Code generation
37779 \end_layout
37780
37781 \begin_layout Standard
37782 Figure II gives a table of iCode
37783 \begin_inset LatexCommand \index{iCode}
37784
37785 \end_inset
37786
37787  operations supported by the compiler.
37788  The code generation involves translating these operations into corresponding
37789  assembly code for the processor.
37790  This sounds overly simple but that is the essence of code generation.
37791  Some of the iCode operations are generated on a MCU specific manner for
37792  example, the z80 port does not use registers to pass parameters so the
37793  SEND and RECV iCode operations will not be generated, and it also does
37794  not support JUMPTABLES.
37795  
37796 \newline
37797
37798 \end_layout
37799
37800 \begin_layout Standard
37801
37802 \size footnotesize
37803 Figure II 
37804 \begin_inset Tabular
37805 <lyxtabular version="3" rows="39" columns="4">
37806 <features islongtable="true" headBottomDL="true">
37807 <column alignment="block" valignment="top" leftline="true" width="13col%">
37808 <column alignment="left" valignment="top" leftline="true" width="13col%">
37809 <column alignment="block" valignment="top" leftline="true" width="22col%">
37810 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37811 <row topline="true" bottomline="true" endhead="true">
37812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37813 \begin_inset Text
37814
37815 \begin_layout Standard
37816
37817 \series bold
37818 iCode
37819 \series default
37820
37821 \begin_inset LatexCommand \index{iCode}
37822
37823 \end_inset
37824
37825
37826 \end_layout
37827
37828 \end_inset
37829 </cell>
37830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37831 \begin_inset Text
37832
37833 \begin_layout Standard
37834
37835 \series bold
37836 Operands
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 \series bold
37847 Description
37848 \end_layout
37849
37850 \end_inset
37851 </cell>
37852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37853 \begin_inset Text
37854
37855 \begin_layout Standard
37856
37857 \series bold
37858 C Equivalent
37859 \end_layout
37860
37861 \end_inset
37862 </cell>
37863 </row>
37864 <row topline="true">
37865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37866 \begin_inset Text
37867
37868 \begin_layout Standard
37869
37870 \size footnotesize
37871 '!'
37872 \end_layout
37873
37874 \end_inset
37875 </cell>
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 IC_LEFT() IC_RESULT()
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 NOT operation 
37894 \end_layout
37895
37896 \end_inset
37897 </cell>
37898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37899 \begin_inset Text
37900
37901 \begin_layout Standard
37902
37903 \size footnotesize
37904 IC_RESULT = ! IC_LEFT;
37905 \end_layout
37906
37907 \end_inset
37908 </cell>
37909 </row>
37910 <row topline="true">
37911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37912 \begin_inset Text
37913
37914 \begin_layout Standard
37915
37916 \size footnotesize
37917 '~'
37918 \end_layout
37919
37920 \end_inset
37921 </cell>
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 IC_LEFT() IC_RESULT()
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 Bitwise complement of 
37940 \end_layout
37941
37942 \end_inset
37943 </cell>
37944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37945 \begin_inset Text
37946
37947 \begin_layout Standard
37948
37949 \size footnotesize
37950 IC_RESULT = ~IC_LEFT;
37951 \end_layout
37952
37953 \end_inset
37954 </cell>
37955 </row>
37956 <row topline="true">
37957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37958 \begin_inset Text
37959
37960 \begin_layout Standard
37961
37962 \size footnotesize
37963 RRC
37964 \end_layout
37965
37966 \end_inset
37967 </cell>
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 IC_LEFT() IC_RESULT()
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 Rotate right with carry
37986 \end_layout
37987
37988 \end_inset
37989 </cell>
37990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37991 \begin_inset Text
37992
37993 \begin_layout Standard
37994
37995 \size footnotesize
37996 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37997 \end_layout
37998
37999 \end_inset
38000 </cell>
38001 </row>
38002 <row topline="true">
38003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38004 \begin_inset Text
38005
38006 \begin_layout Standard
38007
38008 \size footnotesize
38009 RLC
38010 \end_layout
38011
38012 \end_inset
38013 </cell>
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 IC_LEFT() IC_RESULT()
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 Rotate left with carry
38032 \end_layout
38033
38034 \end_inset
38035 </cell>
38036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38037 \begin_inset Text
38038
38039 \begin_layout Standard
38040
38041 \size footnotesize
38042 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
38043 \end_layout
38044
38045 \end_inset
38046 </cell>
38047 </row>
38048 <row topline="true">
38049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38050 \begin_inset Text
38051
38052 \begin_layout Standard
38053
38054 \size footnotesize
38055 GETHBIT
38056 \end_layout
38057
38058 \end_inset
38059 </cell>
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 IC_LEFT() IC_RESULT()
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 Get the highest order bit of IC_LEFT
38078 \end_layout
38079
38080 \end_inset
38081 </cell>
38082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38083 \begin_inset Text
38084
38085 \begin_layout Standard
38086
38087 \size footnotesize
38088 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
38089 \end_layout
38090
38091 \end_inset
38092 </cell>
38093 </row>
38094 <row topline="true">
38095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38096 \begin_inset Text
38097
38098 \begin_layout Standard
38099
38100 \size footnotesize
38101 UNARYMINUS
38102 \end_layout
38103
38104 \end_inset
38105 </cell>
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 IC_LEFT() IC_RESULT()
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 Unary minus
38124 \end_layout
38125
38126 \end_inset
38127 </cell>
38128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38129 \begin_inset Text
38130
38131 \begin_layout Standard
38132
38133 \size footnotesize
38134 IC_RESULT = - IC_LEFT;
38135 \end_layout
38136
38137 \end_inset
38138 </cell>
38139 </row>
38140 <row topline="true">
38141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38142 \begin_inset Text
38143
38144 \begin_layout Standard
38145
38146 \size footnotesize
38147 IPUSH
38148 \end_layout
38149
38150 \end_inset
38151 </cell>
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 IC_LEFT()
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 Push the operand into stack
38170 \end_layout
38171
38172 \end_inset
38173 </cell>
38174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38175 \begin_inset Text
38176
38177 \begin_layout Standard
38178
38179 \size footnotesize
38180 NONE
38181 \end_layout
38182
38183 \end_inset
38184 </cell>
38185 </row>
38186 <row topline="true">
38187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38188 \begin_inset Text
38189
38190 \begin_layout Standard
38191
38192 \size footnotesize
38193 IPOP
38194 \end_layout
38195
38196 \end_inset
38197 </cell>
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 IC_LEFT()
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 Pop the operand from the stack 
38216 \end_layout
38217
38218 \end_inset
38219 </cell>
38220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38221 \begin_inset Text
38222
38223 \begin_layout Standard
38224
38225 \size footnotesize
38226 NONE
38227 \end_layout
38228
38229 \end_inset
38230 </cell>
38231 </row>
38232 <row topline="true">
38233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38234 \begin_inset Text
38235
38236 \begin_layout Standard
38237
38238 \size footnotesize
38239 CALL
38240 \end_layout
38241
38242 \end_inset
38243 </cell>
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 IC_LEFT() IC_RESULT()
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 Call the function represented by IC_LEFT 
38262 \end_layout
38263
38264 \end_inset
38265 </cell>
38266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38267 \begin_inset Text
38268
38269 \begin_layout Standard
38270
38271 \size footnotesize
38272 IC_RESULT = IC_LEFT();
38273 \end_layout
38274
38275 \end_inset
38276 </cell>
38277 </row>
38278 <row topline="true">
38279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38280 \begin_inset Text
38281
38282 \begin_layout Standard
38283
38284 \size footnotesize
38285 PCALL
38286 \end_layout
38287
38288 \end_inset
38289 </cell>
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 IC_LEFT() IC_RESULT()
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 Call via function pointer
38308 \end_layout
38309
38310 \end_inset
38311 </cell>
38312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38313 \begin_inset Text
38314
38315 \begin_layout Standard
38316
38317 \size footnotesize
38318 IC_RESULT = (*IC_LEFT)();
38319 \end_layout
38320
38321 \end_inset
38322 </cell>
38323 </row>
38324 <row topline="true">
38325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38326 \begin_inset Text
38327
38328 \begin_layout Standard
38329
38330 \size footnotesize
38331 RETURN
38332 \end_layout
38333
38334 \end_inset
38335 </cell>
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 IC_LEFT()
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 Return the value in operand IC_LEFT 
38354 \end_layout
38355
38356 \end_inset
38357 </cell>
38358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38359 \begin_inset Text
38360
38361 \begin_layout Standard
38362
38363 \size footnotesize
38364 return IC_LEFT;
38365 \end_layout
38366
38367 \end_inset
38368 </cell>
38369 </row>
38370 <row topline="true">
38371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38372 \begin_inset Text
38373
38374 \begin_layout Standard
38375
38376 \size footnotesize
38377 LABEL
38378 \end_layout
38379
38380 \end_inset
38381 </cell>
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 IC_LABEL() 
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 Label
38400 \end_layout
38401
38402 \end_inset
38403 </cell>
38404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38405 \begin_inset Text
38406
38407 \begin_layout Standard
38408
38409 \size footnotesize
38410 IC_LABEL:
38411 \end_layout
38412
38413 \end_inset
38414 </cell>
38415 </row>
38416 <row topline="true">
38417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38418 \begin_inset Text
38419
38420 \begin_layout Standard
38421
38422 \size footnotesize
38423 GOTO
38424 \end_layout
38425
38426 \end_inset
38427 </cell>
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 IC_LABEL() 
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 Goto label
38446 \end_layout
38447
38448 \end_inset
38449 </cell>
38450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38451 \begin_inset Text
38452
38453 \begin_layout Standard
38454
38455 \size footnotesize
38456 goto IC_LABEL();
38457 \end_layout
38458
38459 \end_inset
38460 </cell>
38461 </row>
38462 <row topline="true">
38463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38464 \begin_inset Text
38465
38466 \begin_layout Standard
38467
38468 \size footnotesize
38469 '+'
38470 \end_layout
38471
38472 \end_inset
38473 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
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 Addition
38492 \end_layout
38493
38494 \end_inset
38495 </cell>
38496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38497 \begin_inset Text
38498
38499 \begin_layout Standard
38500
38501 \size footnotesize
38502 IC_RESULT = IC_LEFT + IC_RIGHT
38503 \end_layout
38504
38505 \end_inset
38506 </cell>
38507 </row>
38508 <row topline="true">
38509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38510 \begin_inset Text
38511
38512 \begin_layout Standard
38513
38514 \size footnotesize
38515 '-'
38516 \end_layout
38517
38518 \end_inset
38519 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
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 Subtraction
38538 \end_layout
38539
38540 \end_inset
38541 </cell>
38542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38543 \begin_inset Text
38544
38545 \begin_layout Standard
38546
38547 \size footnotesize
38548 IC_RESULT = IC_LEFT - IC_RIGHT 
38549 \end_layout
38550
38551 \end_inset
38552 </cell>
38553 </row>
38554 <row topline="true">
38555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38556 \begin_inset Text
38557
38558 \begin_layout Standard
38559
38560 \size footnotesize
38561 '*'
38562 \end_layout
38563
38564 \end_inset
38565 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
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 Multiplication 
38584 \end_layout
38585
38586 \end_inset
38587 </cell>
38588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38589 \begin_inset Text
38590
38591 \begin_layout Standard
38592
38593 \size footnotesize
38594 IC_RESULT = IC_LEFT * IC_RIGHT;
38595 \end_layout
38596
38597 \end_inset
38598 </cell>
38599 </row>
38600 <row topline="true">
38601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38602 \begin_inset Text
38603
38604 \begin_layout Standard
38605
38606 \size footnotesize
38607 '/'
38608 \end_layout
38609
38610 \end_inset
38611 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
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 Division
38630 \end_layout
38631
38632 \end_inset
38633 </cell>
38634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38635 \begin_inset Text
38636
38637 \begin_layout Standard
38638
38639 \size footnotesize
38640 IC_RESULT = IC_LEFT / IC_RIGHT;
38641 \end_layout
38642
38643 \end_inset
38644 </cell>
38645 </row>
38646 <row topline="true">
38647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38648 \begin_inset Text
38649
38650 \begin_layout Standard
38651
38652 \size footnotesize
38653 '%'
38654 \end_layout
38655
38656 \end_inset
38657 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
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 Modulus
38676 \end_layout
38677
38678 \end_inset
38679 </cell>
38680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38681 \begin_inset Text
38682
38683 \begin_layout Standard
38684
38685 \size footnotesize
38686 IC_RESULT = IC_LEFT % IC_RIGHT;
38687 \end_layout
38688
38689 \end_inset
38690 </cell>
38691 </row>
38692 <row topline="true">
38693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38694 \begin_inset Text
38695
38696 \begin_layout Standard
38697
38698 \size footnotesize
38699 '<'
38700 \end_layout
38701
38702 \end_inset
38703 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
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 Less than
38722 \end_layout
38723
38724 \end_inset
38725 </cell>
38726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38727 \begin_inset Text
38728
38729 \begin_layout Standard
38730
38731 \size footnotesize
38732 IC_RESULT = IC_LEFT < IC_RIGHT;
38733 \end_layout
38734
38735 \end_inset
38736 </cell>
38737 </row>
38738 <row topline="true">
38739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38740 \begin_inset Text
38741
38742 \begin_layout Standard
38743
38744 \size footnotesize
38745 '>'
38746 \end_layout
38747
38748 \end_inset
38749 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
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 Greater than 
38768 \end_layout
38769
38770 \end_inset
38771 </cell>
38772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38773 \begin_inset Text
38774
38775 \begin_layout Standard
38776
38777 \size footnotesize
38778 IC_RESULT = IC_LEFT > IC_RIGHT;
38779 \end_layout
38780
38781 \end_inset
38782 </cell>
38783 </row>
38784 <row topline="true">
38785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38786 \begin_inset Text
38787
38788 \begin_layout Standard
38789
38790 \size footnotesize
38791 EQ_OP
38792 \end_layout
38793
38794 \end_inset
38795 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
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 Equal to 
38814 \end_layout
38815
38816 \end_inset
38817 </cell>
38818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38819 \begin_inset Text
38820
38821 \begin_layout Standard
38822
38823 \size footnotesize
38824 IC_RESULT = IC_LEFT == IC_RIGHT;
38825 \end_layout
38826
38827 \end_inset
38828 </cell>
38829 </row>
38830 <row topline="true">
38831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38832 \begin_inset Text
38833
38834 \begin_layout Standard
38835
38836 \size footnotesize
38837 AND_OP
38838 \end_layout
38839
38840 \end_inset
38841 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT() 
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 Logical and operation
38860 \end_layout
38861
38862 \end_inset
38863 </cell>
38864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38865 \begin_inset Text
38866
38867 \begin_layout Standard
38868
38869 \size footnotesize
38870 IC_RESULT = IC_LEFT && IC_RIGHT; 
38871 \end_layout
38872
38873 \end_inset
38874 </cell>
38875 </row>
38876 <row topline="true">
38877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38878 \begin_inset Text
38879
38880 \begin_layout Standard
38881
38882 \size footnotesize
38883 OR_OP
38884 \end_layout
38885
38886 \end_inset
38887 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT() 
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 Logical or operation 
38906 \end_layout
38907
38908 \end_inset
38909 </cell>
38910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38911 \begin_inset Text
38912
38913 \begin_layout Standard
38914
38915 \size footnotesize
38916 IC_RESULT = IC_LEFT || IC_RIGHT; 
38917 \end_layout
38918
38919 \end_inset
38920 </cell>
38921 </row>
38922 <row topline="true">
38923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38924 \begin_inset Text
38925
38926 \begin_layout Standard
38927
38928 \size footnotesize
38929 '^'
38930 \end_layout
38931
38932 \end_inset
38933 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT() 
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 Exclusive OR
38952 \end_layout
38953
38954 \end_inset
38955 </cell>
38956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38957 \begin_inset Text
38958
38959 \begin_layout Standard
38960
38961 \size footnotesize
38962 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38963 \end_layout
38964
38965 \end_inset
38966 </cell>
38967 </row>
38968 <row topline="true">
38969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38970 \begin_inset Text
38971
38972 \begin_layout Standard
38973
38974 \size footnotesize
38975 '|'
38976 \end_layout
38977
38978 \end_inset
38979 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT() 
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 Bitwise OR 
38998 \end_layout
38999
39000 \end_inset
39001 </cell>
39002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39003 \begin_inset Text
39004
39005 \begin_layout Standard
39006
39007 \size footnotesize
39008 IC_RESULT = IC_LEFT | IC_RIGHT;
39009 \end_layout
39010
39011 \end_inset
39012 </cell>
39013 </row>
39014 <row topline="true">
39015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39016 \begin_inset Text
39017
39018 \begin_layout Standard
39019
39020 \size footnotesize
39021 BITWISEAND
39022 \end_layout
39023
39024 \end_inset
39025 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
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 Bitwise AND 
39044 \end_layout
39045
39046 \end_inset
39047 </cell>
39048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39049 \begin_inset Text
39050
39051 \begin_layout Standard
39052
39053 \size footnotesize
39054 IC_RESULT = IC_LEFT & IC_RIGHT;
39055 \end_layout
39056
39057 \end_inset
39058 </cell>
39059 </row>
39060 <row topline="true">
39061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39062 \begin_inset Text
39063
39064 \begin_layout Standard
39065
39066 \size footnotesize
39067 LEFT_OP
39068 \end_layout
39069
39070 \end_inset
39071 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
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 Left shift 
39090 \end_layout
39091
39092 \end_inset
39093 </cell>
39094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39095 \begin_inset Text
39096
39097 \begin_layout Standard
39098
39099 \size footnotesize
39100 IC_RESULT = IC_LEFT << IC_RIGHT 
39101 \end_layout
39102
39103 \end_inset
39104 </cell>
39105 </row>
39106 <row topline="true">
39107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39108 \begin_inset Text
39109
39110 \begin_layout Standard
39111
39112 \size footnotesize
39113 RIGHT_OP
39114 \end_layout
39115
39116 \end_inset
39117 </cell>
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 IC_LEFT() IC_RIGHT() IC_RESULT()
39125 \end_layout
39126
39127 \end_inset
39128 </cell>
39129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39130 \begin_inset Text
39131
39132 \begin_layout Standard
39133
39134 \size footnotesize
39135 Right shift
39136 \end_layout
39137
39138 \end_inset
39139 </cell>
39140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39141 \begin_inset Text
39142
39143 \begin_layout Standard
39144
39145 \size footnotesize
39146 IC_RESULT = IC_LEFT >> IC_RIGHT 
39147 \end_layout
39148
39149 \end_inset
39150 </cell>
39151 </row>
39152 <row topline="true">
39153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39154 \begin_inset Text
39155
39156 \begin_layout Standard
39157
39158 \size footnotesize
39159 GET_VALUE_
39160 \newline
39161 AT_ ADDRESS
39162 \end_layout
39163
39164 \end_inset
39165 </cell>
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 IC_LEFT() IC_RESULT()
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 Indirect fetch 
39184 \end_layout
39185
39186 \end_inset
39187 </cell>
39188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39189 \begin_inset Text
39190
39191 \begin_layout Standard
39192
39193 \size footnotesize
39194 IC_RESULT = (*IC_LEFT);
39195 \end_layout
39196
39197 \end_inset
39198 </cell>
39199 </row>
39200 <row topline="true">
39201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39202 \begin_inset Text
39203
39204 \begin_layout Standard
39205
39206 \size footnotesize
39207 POINTER_SET
39208 \end_layout
39209
39210 \end_inset
39211 </cell>
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 IC_RIGHT() IC_RESULT() 
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 Indirect set
39230 \end_layout
39231
39232 \end_inset
39233 </cell>
39234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39235 \begin_inset Text
39236
39237 \begin_layout Standard
39238
39239 \size footnotesize
39240 (*IC_RESULT) = IC_RIGHT;
39241 \end_layout
39242
39243 \end_inset
39244 </cell>
39245 </row>
39246 <row topline="true">
39247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39248 \begin_inset Text
39249
39250 \begin_layout Standard
39251
39252 \size footnotesize
39253 '='
39254 \end_layout
39255
39256 \end_inset
39257 </cell>
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 IC_RIGHT() IC_RESULT()
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 Assignment
39276 \end_layout
39277
39278 \end_inset
39279 </cell>
39280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39281 \begin_inset Text
39282
39283 \begin_layout Standard
39284
39285 \size footnotesize
39286 IC_RESULT = IC_RIGHT;
39287 \end_layout
39288
39289 \end_inset
39290 </cell>
39291 </row>
39292 <row topline="true">
39293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39294 \begin_inset Text
39295
39296 \begin_layout Standard
39297
39298 \size footnotesize
39299 IFX
39300 \end_layout
39301
39302 \end_inset
39303 </cell>
39304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39305 \begin_inset Text
39306
39307 \begin_layout Standard
39308
39309 \size footnotesize
39310 IC_COND IC_TRUE IC_LABEL
39311 \end_layout
39312
39313 \end_inset
39314 </cell>
39315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39316 \begin_inset Text
39317
39318 \begin_layout Standard
39319
39320 \size footnotesize
39321 Conditional jump.
39322  If true label is present then jump to true label if condition is true else
39323  jump to false label if condition is false 
39324 \end_layout
39325
39326 \end_inset
39327 </cell>
39328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39329 \begin_inset Text
39330
39331 \begin_layout Standard
39332
39333 \size footnotesize
39334 if (IC_COND) goto IC_TRUE; 
39335 \newline
39336 \InsetSpace ~
39337 \InsetSpace ~
39338 Or 
39339 \newline
39340 If (!IC_COND) goto IC_FALSE;
39341 \end_layout
39342
39343 \end_inset
39344 </cell>
39345 </row>
39346 <row topline="true">
39347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39348 \begin_inset Text
39349
39350 \begin_layout Standard
39351
39352 \size footnotesize
39353 ADDRESS_OF
39354 \end_layout
39355
39356 \end_inset
39357 </cell>
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 IC_LEFT() IC_RESULT()
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 Address of 
39376 \end_layout
39377
39378 \end_inset
39379 </cell>
39380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39381 \begin_inset Text
39382
39383 \begin_layout Standard
39384
39385 \size footnotesize
39386 IC_RESULT = &IC_LEFT();
39387 \end_layout
39388
39389 \end_inset
39390 </cell>
39391 </row>
39392 <row topline="true">
39393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39394 \begin_inset Text
39395
39396 \begin_layout Standard
39397
39398 \size footnotesize
39399 JUMPTABLE
39400 \end_layout
39401
39402 \end_inset
39403 </cell>
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 IC_JTCOND IC_JTLABELS
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 Jump to list of labels depending on the value of JTCOND
39422 \end_layout
39423
39424 \end_inset
39425 </cell>
39426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39427 \begin_inset Text
39428
39429 \begin_layout Standard
39430
39431 \size footnotesize
39432 Switch statement
39433 \end_layout
39434
39435 \end_inset
39436 </cell>
39437 </row>
39438 <row topline="true">
39439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39440 \begin_inset Text
39441
39442 \begin_layout Standard
39443
39444 \size footnotesize
39445 CAST
39446 \end_layout
39447
39448 \end_inset
39449 </cell>
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 IC_RIGHT() IC_LEFT() IC_RESULT()
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 Cast types 
39468 \end_layout
39469
39470 \end_inset
39471 </cell>
39472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39473 \begin_inset Text
39474
39475 \begin_layout Standard
39476
39477 \size footnotesize
39478 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39479 \end_layout
39480
39481 \end_inset
39482 </cell>
39483 </row>
39484 <row topline="true">
39485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39486 \begin_inset Text
39487
39488 \begin_layout Standard
39489
39490 \size footnotesize
39491 SEND
39492 \end_layout
39493
39494 \end_inset
39495 </cell>
39496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39497 \begin_inset Text
39498
39499 \begin_layout Standard
39500
39501 \size footnotesize
39502 IC_LEFT()
39503 \end_layout
39504
39505 \end_inset
39506 </cell>
39507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39508 \begin_inset Text
39509
39510 \begin_layout Standard
39511
39512 \size footnotesize
39513 This is used for passing parameters in registers; 
39514 \newline
39515 move IC_LEFT to the next
39516  available parameter register.
39517 \end_layout
39518
39519 \end_inset
39520 </cell>
39521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39522 \begin_inset Text
39523
39524 \begin_layout Standard
39525
39526 \size footnotesize
39527 None
39528 \end_layout
39529
39530 \end_inset
39531 </cell>
39532 </row>
39533 <row topline="true">
39534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39535 \begin_inset Text
39536
39537 \begin_layout Standard
39538
39539 \size footnotesize
39540 RECV
39541 \end_layout
39542
39543 \end_inset
39544 </cell>
39545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39546 \begin_inset Text
39547
39548 \begin_layout Standard
39549
39550 \size footnotesize
39551 IC_RESULT()
39552 \end_layout
39553
39554 \end_inset
39555 </cell>
39556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39557 \begin_inset Text
39558
39559 \begin_layout Standard
39560
39561 \size footnotesize
39562 This is used for receiving parameters passed in registers;
39563 \newline
39564 Move the values
39565  in the next parameter register to IC_RESULT 
39566 \end_layout
39567
39568 \end_inset
39569 </cell>
39570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39571 \begin_inset Text
39572
39573 \begin_layout Standard
39574
39575 \size footnotesize
39576 None
39577 \end_layout
39578
39579 \end_inset
39580 </cell>
39581 </row>
39582 <row topline="true" bottomline="true">
39583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39584 \begin_inset Text
39585
39586 \begin_layout Standard
39587
39588 \shape slanted
39589 \size footnotesize
39590 (some more have been added)
39591 \end_layout
39592
39593 \end_inset
39594 </cell>
39595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39596 \begin_inset Text
39597
39598 \begin_layout Standard
39599
39600 \end_layout
39601
39602 \end_inset
39603 </cell>
39604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39605 \begin_inset Text
39606
39607 \begin_layout Standard
39608
39609 \end_layout
39610
39611 \end_inset
39612 </cell>
39613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39614 \begin_inset Text
39615
39616 \begin_layout Standard
39617
39618 \shape slanted
39619 \size footnotesize
39620 see f.e.
39621  
39622 \family typewriter
39623 gen51Code()
39624 \family default
39625  in 
39626 \family typewriter
39627 src/mcs51/gen.c
39628 \end_layout
39629
39630 \end_inset
39631 </cell>
39632 </row>
39633 </lyxtabular>
39634
39635 \end_inset
39636
39637
39638 \end_layout
39639
39640 \begin_layout Standard
39641 \begin_inset Note Note
39642 status collapsed
39643
39644 \begin_layout Standard
39645 In the original article Figure II was announced to be downloadable on 
39646 \shape italic
39647 Circuit Cellar
39648 \shape default
39649 's web site.
39650  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39651 \end_layout
39652
39653 \end_inset
39654
39655
39656 \end_layout
39657
39658 \begin_layout Paragraph*
39659 ICode Example
39660 \begin_inset LatexCommand \index{iCode}
39661
39662 \end_inset
39663
39664
39665 \end_layout
39666
39667 \begin_layout Standard
39668 This section shows some details of iCode.
39669  The example C code does not do anything useful; it is used as an example
39670  to illustrate the intermediate code generated by the compiler.
39671 \end_layout
39672
39673 \begin_layout Verse
39674
39675 \family typewriter
39676 1.\InsetSpace ~
39677 xdata int * p;
39678 \newline
39679 2.\InsetSpace ~
39680 int gint;
39681 \newline
39682 3.\InsetSpace ~
39683 /* This function does nothing useful.
39684  It is used
39685 \newline
39686 4.\InsetSpace ~
39687 \InsetSpace ~
39688 \InsetSpace ~
39689 \InsetSpace ~
39690 for the purpose of explaining iCode */
39691 \newline
39692 5.\InsetSpace ~
39693 short function (data
39694  int *x)
39695 \newline
39696 6.\InsetSpace ~
39697 {
39698 \newline
39699 7.\InsetSpace ~
39700 \InsetSpace ~
39701 \InsetSpace ~
39702 short i=10; \InsetSpace ~
39703 \InsetSpace ~
39704 /* dead initialization eliminated */
39705 \newline
39706 8.\InsetSpace ~
39707 \InsetSpace ~
39708 \InsetSpace ~
39709 short sum=10;
39710  /* dead initialization eliminated */
39711 \newline
39712 9.\InsetSpace ~
39713 \InsetSpace ~
39714 \InsetSpace ~
39715 short mul;
39716 \newline
39717 10.\InsetSpace ~
39718 \InsetSpace ~
39719 int j ;
39720 \newline
39721 11.\InsetSpace ~
39722 \InsetSpace ~
39723 while (*x) *x++
39724  = *p++; 
39725 \newline
39726 12.\InsetSpace ~
39727 \InsetSpace ~
39728 \InsetSpace ~
39729 \InsetSpace ~
39730 sum = 0 ; 
39731 \newline
39732 13.\InsetSpace ~
39733 \InsetSpace ~
39734 mul = 0;
39735 \newline
39736 14.\InsetSpace ~
39737 \InsetSpace ~
39738 /* compiler detects i,j to be induction
39739  variables */
39740 \newline
39741 15.\InsetSpace ~
39742 \InsetSpace ~
39743 for (i = 0, j = 10 ; i < 10 ; i++, j
39744 \family default
39745 -
39746 \begin_inset ERT
39747 status collapsed
39748
39749 \begin_layout Standard
39750
39751
39752 \backslash
39753 /
39754 \end_layout
39755
39756 \end_inset
39757
39758 -
39759 \family typewriter
39760 ) {
39761 \newline
39762 16.\InsetSpace ~
39763 \InsetSpace ~
39764 \InsetSpace ~
39765 \InsetSpace ~
39766 sum += i;
39767 \newline
39768 17.\InsetSpace ~
39769 \InsetSpace ~
39770 \InsetSpace ~
39771 \InsetSpace ~
39772 mul += i * 3; \InsetSpace ~
39773 \InsetSpace ~
39774 /* this multiplication remains */
39775 \newline
39776 18.\InsetSpace ~
39777 \InsetSpace ~
39778 \InsetSpace ~
39779 \InsetSpace ~
39780 gint +=
39781  j * 3;\InsetSpace ~
39782 \InsetSpace ~
39783 /* this multiplication changed to addition */
39784 \newline
39785 19.\InsetSpace ~
39786 \InsetSpace ~
39787 }
39788 \newline
39789 20.\InsetSpace ~
39790 \InsetSpace ~
39791 return sum+mul;
39792 \newline
39793 21.\InsetSpace ~
39794 }
39795 \end_layout
39796
39797 \begin_layout Standard
39798 In addition to the operands each iCode contains information about the filename
39799  and line it corresponds to in the source file.
39800  The first field in the listing should be interpreted as follows:
39801 \newline
39802
39803 \shape italic
39804 \size footnotesize
39805 Filename(linenumber: iCode Execution sequence number : ICode hash table
39806  key : loop depth of the iCode).
39807 \shape default
39808 \size default
39809
39810 \newline
39811 Then follows the human readable form of the ICode operation.
39812  Each operand of this triplet form can be of three basic types a) compiler
39813  generated temporary b) user defined variable c) a constant value.
39814  Note that local variables and parameters are replaced by compiler generated
39815  temporaries.
39816  Live ranges
39817 \begin_inset LatexCommand \index{Live range analysis}
39818
39819 \end_inset
39820
39821  are computed only for temporaries (i.e.
39822  live ranges are not computed for global variables).
39823  Registers
39824 \begin_inset LatexCommand \index{Register allocation}
39825
39826 \end_inset
39827
39828  are allocated for temporaries only.
39829  Operands are formatted in the following manner:
39830 \newline
39831
39832 \shape italic
39833 \size footnotesize
39834 Operand Name [lr live-from : live-to ] { type information } [ registers
39835  allocated ].
39836 \shape default
39837 \size default
39838
39839 \newline
39840 As mentioned earlier the live ranges are computed in terms of the execution
39841  sequence number of the iCodes, for example 
39842 \newline
39843 the iTemp0 is live from (i.e.
39844  first defined in iCode with execution sequence number 3, and is last used
39845  in the iCode with sequence number 5).
39846  For induction variables such as iTemp21 the live range computation extends
39847  the lifetime from the start to the end of the loop.
39848 \newline
39849 The register allocator
39850  used the live range information to allocate registers, the same registers
39851  may be used for different temporaries if their live ranges do not overlap,
39852  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39853  ranges do not overlap.
39854  In addition the allocator also takes into consideration the type and usage
39855  of a temporary, for example itemp6 is a pointer to near space and is used
39856  as to fetch data from (i.e.
39857  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39858  Some short lived temporaries are allocated to special registers which have
39859  meaning to the code generator e.g.
39860  iTemp13 is allocated to a pseudo register CC which tells the back end that
39861  the temporary is used only for a conditional jump the code generation makes
39862  use of this information to optimize a compare and jump ICode.
39863 \newline
39864 There are several
39865  loop optimizations
39866 \begin_inset LatexCommand \index{Loop optimization}
39867
39868 \end_inset
39869
39870  performed by the compiler.
39871  It can detect induction variables iTemp21(i) and iTemp23(j).
39872  Also note the compiler does selective strength reduction
39873 \begin_inset LatexCommand \index{Strength reduction}
39874
39875 \end_inset
39876
39877 , i.e.
39878  the multiplication of an induction variable in line 18 (gint = j * 3) is
39879  changed to addition, a new temporary iTemp17 is allocated and assigned
39880  a initial value, a constant 3 is then added for each iteration of the loop.
39881  The compiler does not change the multiplication
39882 \begin_inset LatexCommand \index{Multiplication}
39883
39884 \end_inset
39885
39886  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39887 \newline
39888
39889 Note the dead code elimination
39890 \begin_inset LatexCommand \index{Dead-code elimination}
39891
39892 \end_inset
39893
39894  optimization eliminated the dead assignments in line 7 & 8 to I and sum
39895  respectively.
39896 \newline
39897
39898 \end_layout
39899
39900 \begin_layout Standard
39901
39902 \size footnotesize
39903 Sample.c (5:1:0:0) _entry($9) :
39904 \end_layout
39905
39906 \begin_layout Standard
39907
39908 \size footnotesize
39909 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39910 \end_layout
39911
39912 \begin_layout Standard
39913
39914 \size footnotesize
39915 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
39916 \end_layout
39917
39918 \begin_layout Standard
39919
39920 \size footnotesize
39921 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39922 \end_layout
39923
39924 \begin_layout Standard
39925
39926 \size footnotesize
39927 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39928  * int}[r2]
39929 \end_layout
39930
39931 \begin_layout Standard
39932
39933 \size footnotesize
39934 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39935 \end_layout
39936
39937 \begin_layout Standard
39938
39939 \size footnotesize
39940 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39941  int}[r0]]
39942 \end_layout
39943
39944 \begin_layout Standard
39945
39946 \size footnotesize
39947 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39948 \end_layout
39949
39950 \begin_layout Standard
39951
39952 \size footnotesize
39953 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39954  * int}
39955 \end_layout
39956
39957 \begin_layout Standard
39958
39959 \size footnotesize
39960 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39961  {short}
39962 \end_layout
39963
39964 \begin_layout Standard
39965
39966 \size footnotesize
39967 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39968  * int}[DPTR]]
39969 \end_layout
39970
39971 \begin_layout Standard
39972
39973 \size footnotesize
39974 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39975 }[r2 r3]
39976 \end_layout
39977
39978 \begin_layout Standard
39979
39980 \size footnotesize
39981 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39982  * int}[r0] + 0x2 {short}
39983 \end_layout
39984
39985 \begin_layout Standard
39986
39987 \size footnotesize
39988 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39989 \end_layout
39990
39991 \begin_layout Standard
39992
39993 \size footnotesize
39994 Sample.c(11:17:21:0)_whilebreak_0($3) :
39995 \end_layout
39996
39997 \begin_layout Standard
39998
39999 \size footnotesize
40000 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40001 \end_layout
40002
40003 \begin_layout Standard
40004
40005 \size footnotesize
40006 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40007 \end_layout
40008
40009 \begin_layout Standard
40010
40011 \size footnotesize
40012 Sample.c(15:20:54:0)preHeaderLbl1($13) :
40013 \end_layout
40014
40015 \begin_layout Standard
40016
40017 \size footnotesize
40018 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40019 \end_layout
40020
40021 \begin_layout Standard
40022
40023 \size footnotesize
40024 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40025 \end_layout
40026
40027 \begin_layout Standard
40028
40029 \size footnotesize
40030 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40031 \end_layout
40032
40033 \begin_layout Standard
40034
40035 \size footnotesize
40036 Sample.c(15:24:26:1)_forcond_0($4) :
40037 \end_layout
40038
40039 \begin_layout Standard
40040
40041 \size footnotesize
40042 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
40043  < 0xa {short}
40044 \end_layout
40045
40046 \begin_layout Standard
40047
40048 \size footnotesize
40049 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40050 \end_layout
40051
40052 \begin_layout Standard
40053
40054 \size footnotesize
40055 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
40056  + ITemp21 [lr21:38]{short}[r4]
40057 \end_layout
40058
40059 \begin_layout Standard
40060
40061 \size footnotesize
40062 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
40063  * 0x3 {short}
40064 \end_layout
40065
40066 \begin_layout Standard
40067
40068 \size footnotesize
40069 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
40070  + iTemp15 [lr29:30]{short}[r1]
40071 \end_layout
40072
40073 \begin_layout Standard
40074
40075 \size footnotesize
40076 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
40077  r0]- 0x3 {short}
40078 \end_layout
40079
40080 \begin_layout Standard
40081
40082 \size footnotesize
40083 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
40084 int}[r7 r0]
40085 \end_layout
40086
40087 \begin_layout Standard
40088
40089 \size footnotesize
40090 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
40091  + 0x1 {short}
40092 \end_layout
40093
40094 \begin_layout Standard
40095
40096 \size footnotesize
40097 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
40098  r6]- 0x1 {short}
40099 \end_layout
40100
40101 \begin_layout Standard
40102
40103 \size footnotesize
40104 Sample.c(19:38:47:1) goto _forcond_0($4)
40105 \end_layout
40106
40107 \begin_layout Standard
40108
40109 \size footnotesize
40110 Sample.c(19:39:48:0)_forbreak_0($7) :
40111 \end_layout
40112
40113 \begin_layout Standard
40114
40115 \size footnotesize
40116 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
40117  + ITemp11 [lr19:40]{short}[r3]
40118 \end_layout
40119
40120 \begin_layout Standard
40121
40122 \size footnotesize
40123 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
40124 \end_layout
40125
40126 \begin_layout Standard
40127
40128 \size footnotesize
40129 Sample.c(20:42:51:0)_return($8) :
40130 \end_layout
40131
40132 \begin_layout Standard
40133
40134 \size footnotesize
40135 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40136 \size default
40137
40138 \newline
40139
40140 \newline
40141 Finally the code generated for this function:
40142 \newline
40143
40144 \end_layout
40145
40146 \begin_layout Standard
40147
40148 \size footnotesize
40149 .area DSEG (DATA)
40150 \end_layout
40151
40152 \begin_layout Standard
40153
40154 \size footnotesize
40155 _p::
40156 \end_layout
40157
40158 \begin_layout Standard
40159
40160 \size footnotesize
40161 \InsetSpace ~
40162 \InsetSpace ~
40163 .ds 2
40164 \end_layout
40165
40166 \begin_layout Standard
40167
40168 \size footnotesize
40169 _gint::
40170 \end_layout
40171
40172 \begin_layout Standard
40173
40174 \size footnotesize
40175 \InsetSpace ~
40176 \InsetSpace ~
40177 .ds 2
40178 \end_layout
40179
40180 \begin_layout Standard
40181
40182 \size footnotesize
40183 ; sample.c 5
40184 \end_layout
40185
40186 \begin_layout Standard
40187
40188 \size footnotesize
40189 ; ----------------------------------------------
40190 \end_layout
40191
40192 \begin_layout Standard
40193
40194 \size footnotesize
40195 ; function function
40196 \end_layout
40197
40198 \begin_layout Standard
40199
40200 \size footnotesize
40201 ; ----------------------------------------------
40202 \end_layout
40203
40204 \begin_layout Standard
40205
40206 \size footnotesize
40207 _function:
40208 \end_layout
40209
40210 \begin_layout Standard
40211
40212 \size footnotesize
40213 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
40214 \end_layout
40215
40216 \begin_layout Standard
40217
40218 \size footnotesize
40219 \InsetSpace ~
40220 \InsetSpace ~
40221 mov r2,dpl
40222 \end_layout
40223
40224 \begin_layout Standard
40225
40226 \size footnotesize
40227 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40228 \end_layout
40229
40230 \begin_layout Standard
40231
40232 \size footnotesize
40233 \InsetSpace ~
40234 \InsetSpace ~
40235 mov ar0,r2
40236 \end_layout
40237
40238 \begin_layout Standard
40239
40240 \size footnotesize
40241 ;_whilecontinue_0($1) :
40242 \end_layout
40243
40244 \begin_layout Standard
40245
40246 \size footnotesize
40247 00101$:
40248 \end_layout
40249
40250 \begin_layout Standard
40251
40252 \size footnotesize
40253 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40254 \end_layout
40255
40256 \begin_layout Standard
40257
40258 \size footnotesize
40259 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40260 \end_layout
40261
40262 \begin_layout Standard
40263
40264 \size footnotesize
40265 \InsetSpace ~
40266 \InsetSpace ~
40267 mov ar2,@r0
40268 \end_layout
40269
40270 \begin_layout Standard
40271
40272 \size footnotesize
40273 \InsetSpace ~
40274 \InsetSpace ~
40275 inc r0
40276 \end_layout
40277
40278 \begin_layout Standard
40279
40280 \size footnotesize
40281 \InsetSpace ~
40282 \InsetSpace ~
40283 mov ar3,@r0
40284 \end_layout
40285
40286 \begin_layout Standard
40287
40288 \size footnotesize
40289 \InsetSpace ~
40290 \InsetSpace ~
40291 dec r0
40292 \end_layout
40293
40294 \begin_layout Standard
40295
40296 \size footnotesize
40297 \InsetSpace ~
40298 \InsetSpace ~
40299 mov a,r2
40300 \end_layout
40301
40302 \begin_layout Standard
40303
40304 \size footnotesize
40305 \InsetSpace ~
40306 \InsetSpace ~
40307 orl a,r3
40308 \end_layout
40309
40310 \begin_layout Standard
40311
40312 \size footnotesize
40313 \InsetSpace ~
40314 \InsetSpace ~
40315 jz 00103$
40316 \end_layout
40317
40318 \begin_layout Standard
40319
40320 \size footnotesize
40321 00114$:
40322 \end_layout
40323
40324 \begin_layout Standard
40325
40326 \size footnotesize
40327 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40328 \end_layout
40329
40330 \begin_layout Standard
40331
40332 \size footnotesize
40333 \InsetSpace ~
40334 \InsetSpace ~
40335 mov dpl,_p
40336 \end_layout
40337
40338 \begin_layout Standard
40339
40340 \size footnotesize
40341 \InsetSpace ~
40342 \InsetSpace ~
40343 mov dph,(_p + 1)
40344 \end_layout
40345
40346 \begin_layout Standard
40347
40348 \size footnotesize
40349 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40350 \end_layout
40351
40352 \begin_layout Standard
40353
40354 \size footnotesize
40355 \InsetSpace ~
40356 \InsetSpace ~
40357 mov a,#0x02
40358 \end_layout
40359
40360 \begin_layout Standard
40361
40362 \size footnotesize
40363 \InsetSpace ~
40364 \InsetSpace ~
40365 add a,_p
40366 \end_layout
40367
40368 \begin_layout Standard
40369
40370 \size footnotesize
40371 \InsetSpace ~
40372 \InsetSpace ~
40373 mov _p,a
40374 \end_layout
40375
40376 \begin_layout Standard
40377
40378 \size footnotesize
40379 \InsetSpace ~
40380 \InsetSpace ~
40381 clr a
40382 \end_layout
40383
40384 \begin_layout Standard
40385
40386 \size footnotesize
40387 \InsetSpace ~
40388 \InsetSpace ~
40389 addc a,(_p + 1)
40390 \end_layout
40391
40392 \begin_layout Standard
40393
40394 \size footnotesize
40395 \InsetSpace ~
40396 \InsetSpace ~
40397 mov (_p + 1),a
40398 \end_layout
40399
40400 \begin_layout Standard
40401
40402 \size footnotesize
40403 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40404 \end_layout
40405
40406 \begin_layout Standard
40407
40408 \size footnotesize
40409 \InsetSpace ~
40410 \InsetSpace ~
40411 movx a,@dptr
40412 \end_layout
40413
40414 \begin_layout Standard
40415
40416 \size footnotesize
40417 \InsetSpace ~
40418 \InsetSpace ~
40419 mov r2,a
40420 \end_layout
40421
40422 \begin_layout Standard
40423
40424 \size footnotesize
40425 \InsetSpace ~
40426 \InsetSpace ~
40427 inc dptr
40428 \end_layout
40429
40430 \begin_layout Standard
40431
40432 \size footnotesize
40433 \InsetSpace ~
40434 \InsetSpace ~
40435 movx a,@dptr
40436 \end_layout
40437
40438 \begin_layout Standard
40439
40440 \size footnotesize
40441 \InsetSpace ~
40442 \InsetSpace ~
40443 mov r3,a
40444 \end_layout
40445
40446 \begin_layout Standard
40447
40448 \size footnotesize
40449 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40450 \end_layout
40451
40452 \begin_layout Standard
40453
40454 \size footnotesize
40455 \InsetSpace ~
40456 \InsetSpace ~
40457 mov @r0,ar2
40458 \end_layout
40459
40460 \begin_layout Standard
40461
40462 \size footnotesize
40463 \InsetSpace ~
40464 \InsetSpace ~
40465 inc r0
40466 \end_layout
40467
40468 \begin_layout Standard
40469
40470 \size footnotesize
40471 \InsetSpace ~
40472 \InsetSpace ~
40473 mov @r0,ar3
40474 \end_layout
40475
40476 \begin_layout Standard
40477
40478 \size footnotesize
40479 ; iTemp6 [lr5:16]{_near * int}[r0] = 
40480 \end_layout
40481
40482 \begin_layout Standard
40483
40484 \size footnotesize
40485 ; iTemp6 [lr5:16]{_near * int}[r0] + 
40486 \end_layout
40487
40488 \begin_layout Standard
40489
40490 \size footnotesize
40491 ; 0x2 {short}
40492 \end_layout
40493
40494 \begin_layout Standard
40495
40496 \size footnotesize
40497 \InsetSpace ~
40498 \InsetSpace ~
40499 inc r0
40500 \end_layout
40501
40502 \begin_layout Standard
40503
40504 \size footnotesize
40505 ; goto _whilecontinue_0($1)
40506 \end_layout
40507
40508 \begin_layout Standard
40509
40510 \size footnotesize
40511 \InsetSpace ~
40512 \InsetSpace ~
40513 sjmp 00101$
40514 \end_layout
40515
40516 \begin_layout Standard
40517
40518 \size footnotesize
40519 ; _whilebreak_0($3) :
40520 \end_layout
40521
40522 \begin_layout Standard
40523
40524 \size footnotesize
40525 00103$:
40526 \end_layout
40527
40528 \begin_layout Standard
40529
40530 \size footnotesize
40531 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40532 \end_layout
40533
40534 \begin_layout Standard
40535
40536 \size footnotesize
40537 \InsetSpace ~
40538 \InsetSpace ~
40539 mov r2,#0x00
40540 \end_layout
40541
40542 \begin_layout Standard
40543
40544 \size footnotesize
40545 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40546 \end_layout
40547
40548 \begin_layout Standard
40549
40550 \size footnotesize
40551 \InsetSpace ~
40552 \InsetSpace ~
40553 mov r3,#0x00
40554 \end_layout
40555
40556 \begin_layout Standard
40557
40558 \size footnotesize
40559 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40560 \end_layout
40561
40562 \begin_layout Standard
40563
40564 \size footnotesize
40565 \InsetSpace ~
40566 \InsetSpace ~
40567 mov r4,#0x00
40568 \end_layout
40569
40570 \begin_layout Standard
40571
40572 \size footnotesize
40573 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40574 \end_layout
40575
40576 \begin_layout Standard
40577
40578 \size footnotesize
40579 \InsetSpace ~
40580 \InsetSpace ~
40581 mov r5,#0x0A
40582 \end_layout
40583
40584 \begin_layout Standard
40585
40586 \size footnotesize
40587 \InsetSpace ~
40588 \InsetSpace ~
40589 mov r6,#0x00
40590 \end_layout
40591
40592 \begin_layout Standard
40593
40594 \size footnotesize
40595 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40596 \end_layout
40597
40598 \begin_layout Standard
40599
40600 \size footnotesize
40601 \InsetSpace ~
40602 \InsetSpace ~
40603 mov r7,#0x1E
40604 \end_layout
40605
40606 \begin_layout Standard
40607
40608 \size footnotesize
40609 \InsetSpace ~
40610 \InsetSpace ~
40611 mov r0,#0x00
40612 \end_layout
40613
40614 \begin_layout Standard
40615
40616 \size footnotesize
40617 ; _forcond_0($4) :
40618 \end_layout
40619
40620 \begin_layout Standard
40621
40622 \size footnotesize
40623 00104$:
40624 \end_layout
40625
40626 \begin_layout Standard
40627
40628 \size footnotesize
40629 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40630 \end_layout
40631
40632 \begin_layout Standard
40633
40634 \size footnotesize
40635 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40636 \end_layout
40637
40638 \begin_layout Standard
40639
40640 \size footnotesize
40641 \InsetSpace ~
40642 \InsetSpace ~
40643 clr c
40644 \end_layout
40645
40646 \begin_layout Standard
40647
40648 \size footnotesize
40649 \InsetSpace ~
40650 \InsetSpace ~
40651 mov a,r4
40652 \end_layout
40653
40654 \begin_layout Standard
40655
40656 \size footnotesize
40657 \InsetSpace ~
40658 \InsetSpace ~
40659 xrl a,#0x80
40660 \end_layout
40661
40662 \begin_layout Standard
40663
40664 \size footnotesize
40665 \InsetSpace ~
40666 \InsetSpace ~
40667 subb a,#0x8a
40668 \end_layout
40669
40670 \begin_layout Standard
40671
40672 \size footnotesize
40673 \InsetSpace ~
40674 \InsetSpace ~
40675 jnc 00107$
40676 \end_layout
40677
40678 \begin_layout Standard
40679
40680 \size footnotesize
40681 00115$:
40682 \end_layout
40683
40684 \begin_layout Standard
40685
40686 \size footnotesize
40687 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40688 \end_layout
40689
40690 \begin_layout Standard
40691
40692 \size footnotesize
40693 ; iTemp21 [lr21:38]{short}[r4]
40694 \end_layout
40695
40696 \begin_layout Standard
40697
40698 \size footnotesize
40699 \InsetSpace ~
40700 \InsetSpace ~
40701 mov a,r4
40702 \end_layout
40703
40704 \begin_layout Standard
40705
40706 \size footnotesize
40707 \InsetSpace ~
40708 \InsetSpace ~
40709 add a,r2
40710 \end_layout
40711
40712 \begin_layout Standard
40713
40714 \size footnotesize
40715 \InsetSpace ~
40716 \InsetSpace ~
40717 mov r2,a
40718 \end_layout
40719
40720 \begin_layout Standard
40721
40722 \size footnotesize
40723 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40724 \end_layout
40725
40726 \begin_layout Standard
40727
40728 \size footnotesize
40729 \InsetSpace ~
40730 \InsetSpace ~
40731 mov b,#0x03
40732 \end_layout
40733
40734 \begin_layout Standard
40735
40736 \size footnotesize
40737 \InsetSpace ~
40738 \InsetSpace ~
40739 mov a,r4
40740 \end_layout
40741
40742 \begin_layout Standard
40743
40744 \size footnotesize
40745 \InsetSpace ~
40746 \InsetSpace ~
40747 mul ab
40748 \end_layout
40749
40750 \begin_layout Standard
40751
40752 \size footnotesize
40753 \InsetSpace ~
40754 \InsetSpace ~
40755 mov r1,a
40756 \end_layout
40757
40758 \begin_layout Standard
40759
40760 \size footnotesize
40761 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40762 \end_layout
40763
40764 \begin_layout Standard
40765
40766 \size footnotesize
40767 ; iTemp15 [lr29:30]{short}[r1]
40768 \end_layout
40769
40770 \begin_layout Standard
40771
40772 \size footnotesize
40773 \InsetSpace ~
40774 \InsetSpace ~
40775 add a,r3
40776 \end_layout
40777
40778 \begin_layout Standard
40779
40780 \size footnotesize
40781 \InsetSpace ~
40782 \InsetSpace ~
40783 mov r3,a
40784 \end_layout
40785
40786 \begin_layout Standard
40787
40788 \size footnotesize
40789 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40790 \end_layout
40791
40792 \begin_layout Standard
40793
40794 \size footnotesize
40795 \InsetSpace ~
40796 \InsetSpace ~
40797 mov a,r7
40798 \end_layout
40799
40800 \begin_layout Standard
40801
40802 \size footnotesize
40803 \InsetSpace ~
40804 \InsetSpace ~
40805 add a,#0xfd
40806 \end_layout
40807
40808 \begin_layout Standard
40809
40810 \size footnotesize
40811 \InsetSpace ~
40812 \InsetSpace ~
40813 mov r7,a
40814 \end_layout
40815
40816 \begin_layout Standard
40817
40818 \size footnotesize
40819 \InsetSpace ~
40820 \InsetSpace ~
40821 mov a,r0
40822 \end_layout
40823
40824 \begin_layout Standard
40825
40826 \size footnotesize
40827 \InsetSpace ~
40828 \InsetSpace ~
40829 addc a,#0xff
40830 \end_layout
40831
40832 \begin_layout Standard
40833
40834 \size footnotesize
40835 \InsetSpace ~
40836 \InsetSpace ~
40837 mov r0,a
40838 \end_layout
40839
40840 \begin_layout Standard
40841
40842 \size footnotesize
40843 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40844 \end_layout
40845
40846 \begin_layout Standard
40847
40848 \size footnotesize
40849 \InsetSpace ~
40850 \InsetSpace ~
40851 mov a,r7
40852 \end_layout
40853
40854 \begin_layout Standard
40855
40856 \size footnotesize
40857 \InsetSpace ~
40858 \InsetSpace ~
40859 add a,_gint
40860 \end_layout
40861
40862 \begin_layout Standard
40863
40864 \size footnotesize
40865 \InsetSpace ~
40866 \InsetSpace ~
40867 mov _gint,a
40868 \end_layout
40869
40870 \begin_layout Standard
40871
40872 \size footnotesize
40873 \InsetSpace ~
40874 \InsetSpace ~
40875 mov a,r0
40876 \end_layout
40877
40878 \begin_layout Standard
40879
40880 \size footnotesize
40881 \InsetSpace ~
40882 \InsetSpace ~
40883 addc a,(_gint + 1)
40884 \end_layout
40885
40886 \begin_layout Standard
40887
40888 \size footnotesize
40889 \InsetSpace ~
40890 \InsetSpace ~
40891 mov (_gint + 1),a
40892 \end_layout
40893
40894 \begin_layout Standard
40895
40896 \size footnotesize
40897 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40898 \end_layout
40899
40900 \begin_layout Standard
40901
40902 \size footnotesize
40903 \InsetSpace ~
40904 \InsetSpace ~
40905 inc r4
40906 \end_layout
40907
40908 \begin_layout Standard
40909
40910 \size footnotesize
40911 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40912 \end_layout
40913
40914 \begin_layout Standard
40915
40916 \size footnotesize
40917 \InsetSpace ~
40918 \InsetSpace ~
40919 dec r5
40920 \end_layout
40921
40922 \begin_layout Standard
40923
40924 \size footnotesize
40925 \InsetSpace ~
40926 \InsetSpace ~
40927 cjne r5,#0xff,00104$
40928 \end_layout
40929
40930 \begin_layout Standard
40931
40932 \size footnotesize
40933 \InsetSpace ~
40934 \InsetSpace ~
40935 dec r6
40936 \end_layout
40937
40938 \begin_layout Standard
40939
40940 \size footnotesize
40941 ; goto _forcond_0($4)
40942 \end_layout
40943
40944 \begin_layout Standard
40945
40946 \size footnotesize
40947 \InsetSpace ~
40948 \InsetSpace ~
40949 sjmp 00104$
40950 \end_layout
40951
40952 \begin_layout Standard
40953
40954 \size footnotesize
40955 ; _forbreak_0($7) :
40956 \end_layout
40957
40958 \begin_layout Standard
40959
40960 \size footnotesize
40961 00107$:
40962 \end_layout
40963
40964 \begin_layout Standard
40965
40966 \size footnotesize
40967 ; ret iTemp24 [lr40:41]{short}
40968 \end_layout
40969
40970 \begin_layout Standard
40971
40972 \size footnotesize
40973 \InsetSpace ~
40974 \InsetSpace ~
40975 mov a,r3
40976 \end_layout
40977
40978 \begin_layout Standard
40979
40980 \size footnotesize
40981 \InsetSpace ~
40982 \InsetSpace ~
40983 add a,r2
40984 \end_layout
40985
40986 \begin_layout Standard
40987
40988 \size footnotesize
40989 \InsetSpace ~
40990 \InsetSpace ~
40991 mov dpl,a
40992 \end_layout
40993
40994 \begin_layout Standard
40995
40996 \size footnotesize
40997 ; _return($8) :
40998 \end_layout
40999
41000 \begin_layout Standard
41001
41002 \size footnotesize
41003 00108$:
41004 \end_layout
41005
41006 \begin_layout Standard
41007
41008 \size footnotesize
41009 \InsetSpace ~
41010 \InsetSpace ~
41011 ret
41012 \newline
41013
41014 \end_layout
41015
41016 \begin_layout Section
41017 A few words about basic block successors, predecessors and dominators
41018 \end_layout
41019
41020 \begin_layout Standard
41021 Successors are basic blocks
41022 \begin_inset LatexCommand \index{Basic blocks}
41023
41024 \end_inset
41025
41026  that might execute after this basic block.
41027 \newline
41028 Predecessors are basic blocks
41029  that might execute before reaching this basic block.
41030 \newline
41031 Dominators are basic
41032  blocks that WILL execute before reaching this basic block.
41033 \newline
41034
41035 \end_layout
41036
41037 \begin_layout Standard
41038 [basic block 1]
41039 \end_layout
41040
41041 \begin_layout Standard
41042 if (something)
41043 \end_layout
41044
41045 \begin_layout Standard
41046 \InsetSpace ~
41047 \InsetSpace ~
41048 \InsetSpace ~
41049 \InsetSpace ~
41050 [basic block 2]
41051 \end_layout
41052
41053 \begin_layout Standard
41054 else
41055 \end_layout
41056
41057 \begin_layout Standard
41058 \InsetSpace ~
41059 \InsetSpace ~
41060 \InsetSpace ~
41061 \InsetSpace ~
41062 [basic block 3]
41063 \end_layout
41064
41065 \begin_layout Standard
41066 [basic block 4]
41067 \newline
41068
41069 \end_layout
41070
41071 \begin_layout Standard
41072 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
41073 \end_layout
41074
41075 \begin_layout Standard
41076 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
41077 \end_layout
41078
41079 \begin_layout Standard
41080 c) domVect of [BB4] = BB1 ...
41081  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
41082  was executed.
41083 \end_layout
41084
41085 \begin_layout Chapter
41086 Acknowledgments
41087 \end_layout
41088
41089 \begin_layout Standard
41090 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
41091
41092 \end_inset
41093
41094
41095 \newline
41096
41097 \newline
41098
41099 \emph on
41100 Thanks to all the other volunteer developers who have helped with coding,
41101  testing, web-page creation, distribution sets, etc.
41102  You know who you are :-)
41103 \emph default
41104
41105 \newline
41106
41107 \newline
41108
41109 \emph on
41110 Thanks to Sourceforge 
41111 \begin_inset LatexCommand \url{http://www.sf.net}
41112
41113 \end_inset
41114
41115  which has hosted the project since 1999 and donates significant download
41116  bandwidth.
41117 \emph default
41118
41119 \newline
41120
41121 \newline
41122
41123 \emph on
41124 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
41125  cycles and bandwidth for snapshot builds.
41126 \newline
41127
41128 \end_layout
41129
41130 \begin_layout Standard
41131 This document was initially written by Sandeep Dutta
41132 \end_layout
41133
41134 \begin_layout Standard
41135 All product names mentioned herein may be trademarks
41136 \begin_inset LatexCommand \index{Trademarks}
41137
41138 \end_inset
41139
41140  of their respective companies.
41141  
41142 \end_layout
41143
41144 \begin_layout Section*
41145 Alphabetical index
41146 \end_layout
41147
41148 \begin_layout Standard
41149 To avoid confusion, the installation and building options for SDCC itself
41150  (chapter 2) are not part of the index.
41151 \end_layout
41152
41153 \begin_layout Standard
41154 \begin_inset LatexCommand \printindex{}
41155
41156 \end_inset
41157
41158
41159 \end_layout
41160
41161 \end_body
41162 \end_document