* support/scripts/sdcc.nsi: added asranlib.exe to the install package
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.5.7 created this file. For more info see http://www.lyx.org/
2 \lyxformat 276
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 \font_roman times
26 \font_sans helvet
27 \font_typewriter courier
28 \font_default_family default
29 \font_sc false
30 \font_osf false
31 \font_sf_scale 100
32 \font_tt_scale 100
33 \graphics default
34 \paperfontsize default
35 \spacing single
36 \papersize letterpaper
37 \use_geometry true
38 \use_amsmath 1
39 \use_esint 0
40 \cite_engine basic
41 \use_bibtopic false
42 \paperorientation portrait
43 \leftmargin 30mm
44 \topmargin 20mm
45 \rightmargin 25mm
46 \bottommargin 20mm
47 \secnumdepth 3
48 \tocdepth 3
49 \paragraph_separation indent
50 \defskip medskip
51 \quotes_language swedish
52 \papercolumns 1
53 \papersides 1
54 \paperpagestyle fancy
55 \tracking_changes false
56 \output_changes false
57 \author "" 
58 \author "" 
59 \end_header
60
61 \begin_body
62
63 \begin_layout Standard
64 \begin_inset Note Note
65 status collapsed
66
67 \begin_layout Standard
68 Please note: double dashed longoptions (e.g.
69  --version) are written this way: -
70 \begin_inset ERT
71 status collapsed
72
73 \begin_layout Standard
74
75
76 \backslash
77 /
78 \end_layout
79
80 \end_inset
81
82 -
83 \end_layout
84
85 \begin_layout Standard
86 Two resp.
87  three consecutive dashes would otherwise result in a long resp.
88  extra long dash.
89 \end_layout
90
91 \begin_layout Standard
92 Architecture specific stuff (like memory models, code examples) should maybe
93  later go
94 \end_layout
95
96 \begin_layout Standard
97 into separate sections/chapters/appendices (it is hard to document PIC or
98  Z80 in 
99 \end_layout
100
101 \begin_layout Standard
102 a 8051 centered document) - for now simply add.
103 \end_layout
104
105 \end_inset
106
107
108 \end_layout
109
110 \begin_layout Title
111 SDCC Compiler User Guide
112 \end_layout
113
114 \begin_layout Date
115
116 \size normal
117 SDCC 2.8.7
118 \size footnotesize
119
120 \newline
121 $Date: 2008-11-16#$ 
122 \newline
123 $Revision: 5272$
124 \end_layout
125
126 \begin_layout Standard
127 \begin_inset Note Note
128 status collapsed
129
130 \begin_layout Standard
131 The above strings enclosed in $ are automatically updated by Subversion
132 \end_layout
133
134 \end_inset
135
136
137 \end_layout
138
139 \begin_layout Standard
140 \begin_inset LatexCommand tableofcontents
141
142 \end_inset
143
144
145 \end_layout
146
147 \begin_layout Chapter
148 Introduction
149 \end_layout
150
151 \begin_layout Section
152 About SDCC
153 \end_layout
154
155 \begin_layout Standard
156
157 \series bold
158 SDCC
159 \series default
160  (
161 \emph on
162 S
163 \emph default
164 mall 
165 \emph on
166 D
167 \emph default
168 evice 
169 \emph on
170 C
171 \emph default
172  
173 \emph on
174 C
175 \emph default
176 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
177  by 
178 \series bold
179 Sandeep Dutta
180 \series default
181  designed for 8 bit Microprocessors.
182  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
183  8051, 8052
184 \begin_inset LatexCommand index
185 name "8031, 8032, 8051, 8052, mcs51 CPU"
186
187 \end_inset
188
189 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
190  Zilog Z80 based MCUs.
191  It can be retargeted for other microprocessors, support for Microchip PIC,
192  Atmel AVR is under development.
193  The entire source code for the compiler is distributed under GPL.
194  SDCC uses ASXXXX
195 \begin_inset LatexCommand index
196 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
197
198 \end_inset
199
200  & ASLINK
201 \begin_inset LatexCommand index
202 name "aslink"
203
204 \end_inset
205
206 , an open source retargetable assembler & linker.
207  SDCC has extensive language extensions suitable for utilizing various microcont
208 rollers and underlying hardware effectively.
209  
210 \newline
211
212 \newline
213 In addition to the MCU specific optimizations SDCC also does a host of
214  standard optimizations like:
215 \end_layout
216
217 \begin_layout Itemize
218 global sub expression elimination, 
219 \end_layout
220
221 \begin_layout Itemize
222 loop optimizations (loop invariant, strength reduction of induction variables
223  and loop reversing), 
224 \end_layout
225
226 \begin_layout Itemize
227 constant folding & propagation, 
228 \end_layout
229
230 \begin_layout Itemize
231 copy propagation, 
232 \end_layout
233
234 \begin_layout Itemize
235 dead code elimination 
236 \end_layout
237
238 \begin_layout Itemize
239 jump tables for 
240 \emph on
241 switch
242 \emph default
243  statements.
244 \end_layout
245
246 \begin_layout Standard
247 For the back-end SDCC uses a global register allocation scheme which should
248  be well suited for other 8 bit MCUs.
249  
250 \newline
251
252 \newline
253 The peep hole optimizer uses a rule based substitution mechanism which
254  is MCU independent.
255  
256 \newline
257
258 \newline
259 Supported data-types are:
260 \end_layout
261
262 \begin_layout Standard
263 \begin_inset Tabular
264 <lyxtabular version="3" rows="8" columns="5">
265 <features>
266 <column alignment="center" valignment="top" leftline="true" width="0">
267 <column alignment="center" valignment="top" leftline="true" width="0">
268 <column alignment="center" valignment="top" leftline="true" width="0">
269 <column alignment="center" valignment="top" leftline="true" width="0">
270 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
271 <row topline="true" bottomline="true">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
273 \begin_inset Text
274
275 \begin_layout Standard
276 type
277 \end_layout
278
279 \end_inset
280 </cell>
281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
282 \begin_inset Text
283
284 \begin_layout Standard
285 width
286 \end_layout
287
288 \end_inset
289 </cell>
290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
291 \begin_inset Text
292
293 \begin_layout Standard
294 default
295 \end_layout
296
297 \end_inset
298 </cell>
299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
300 \begin_inset Text
301
302 \begin_layout Standard
303 signed range
304 \end_layout
305
306 \end_inset
307 </cell>
308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
309 \begin_inset Text
310
311 \begin_layout Standard
312 unsigned range
313 \end_layout
314
315 \end_inset
316 </cell>
317 </row>
318 <row topline="true">
319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
320 \begin_inset Text
321
322 \begin_layout Standard
323 bool
324 \end_layout
325
326 \end_inset
327 </cell>
328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
329 \begin_inset Text
330
331 \begin_layout Standard
332 1 bit
333 \end_layout
334
335 \end_inset
336 </cell>
337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
338 \begin_inset Text
339
340 \begin_layout Standard
341 unsigned
342 \end_layout
343
344 \end_inset
345 </cell>
346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
347 \begin_inset Text
348
349 \begin_layout Standard
350 -
351 \end_layout
352
353 \end_inset
354 </cell>
355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
356 \begin_inset Text
357
358 \begin_layout Standard
359 0, 1
360 \end_layout
361
362 \end_inset
363 </cell>
364 </row>
365 <row topline="true">
366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
367 \begin_inset Text
368
369 \begin_layout Standard
370 char
371 \end_layout
372
373 \end_inset
374 </cell>
375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
376 \begin_inset Text
377
378 \begin_layout Standard
379 8 bits, 1 byte
380 \end_layout
381
382 \end_inset
383 </cell>
384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
385 \begin_inset Text
386
387 \begin_layout Standard
388 signed
389 \end_layout
390
391 \end_inset
392 </cell>
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
394 \begin_inset Text
395
396 \begin_layout Standard
397 -128, +127
398 \end_layout
399
400 \end_inset
401 </cell>
402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
403 \begin_inset Text
404
405 \begin_layout Standard
406 0, +255
407 \end_layout
408
409 \end_inset
410 </cell>
411 </row>
412 <row topline="true">
413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
414 \begin_inset Text
415
416 \begin_layout Standard
417 short
418 \end_layout
419
420 \end_inset
421 </cell>
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
423 \begin_inset Text
424
425 \begin_layout Standard
426 16 bits, 2 bytes
427 \end_layout
428
429 \end_inset
430 </cell>
431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
432 \begin_inset Text
433
434 \begin_layout Standard
435 signed
436 \end_layout
437
438 \end_inset
439 </cell>
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
441 \begin_inset Text
442
443 \begin_layout Standard
444 -32.768, +32.767
445 \end_layout
446
447 \end_inset
448 </cell>
449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
450 \begin_inset Text
451
452 \begin_layout Standard
453 0, +65.535
454 \end_layout
455
456 \end_inset
457 </cell>
458 </row>
459 <row topline="true">
460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
461 \begin_inset Text
462
463 \begin_layout Standard
464 int
465 \end_layout
466
467 \end_inset
468 </cell>
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_inset Text
471
472 \begin_layout Standard
473 16 bits, 2 bytes
474 \end_layout
475
476 \end_inset
477 </cell>
478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
479 \begin_inset Text
480
481 \begin_layout Standard
482 signed
483 \end_layout
484
485 \end_inset
486 </cell>
487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
488 \begin_inset Text
489
490 \begin_layout Standard
491 -32.768, +32.767
492 \end_layout
493
494 \end_inset
495 </cell>
496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
497 \begin_inset Text
498
499 \begin_layout Standard
500 0, +65.535
501 \end_layout
502
503 \end_inset
504 </cell>
505 </row>
506 <row topline="true" bottomline="true">
507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
508 \begin_inset Text
509
510 \begin_layout Standard
511 long
512 \end_layout
513
514 \end_inset
515 </cell>
516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
517 \begin_inset Text
518
519 \begin_layout Standard
520 32 bits, 4 bytes
521 \end_layout
522
523 \end_inset
524 </cell>
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
526 \begin_inset Text
527
528 \begin_layout Standard
529 signed
530 \end_layout
531
532 \end_inset
533 </cell>
534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
535 \begin_inset Text
536
537 \begin_layout Standard
538 -2.147.483.648, +2.147.483.647
539 \end_layout
540
541 \end_inset
542 </cell>
543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
544 \begin_inset Text
545
546 \begin_layout Standard
547 0, +4.294.967.295
548 \end_layout
549
550 \end_inset
551 </cell>
552 </row>
553 <row topline="true" bottomline="true">
554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
555 \begin_inset Text
556
557 \begin_layout Standard
558 float
559 \end_layout
560
561 \end_inset
562 </cell>
563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
564 \begin_inset Text
565
566 \begin_layout Standard
567 4 bytes IEEE 754
568 \end_layout
569
570 \end_inset
571 </cell>
572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
573 \begin_inset Text
574
575 \begin_layout Standard
576 signed
577 \end_layout
578
579 \end_inset
580 </cell>
581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
582 \begin_inset Text
583
584 \begin_layout Standard
585
586 \end_layout
587
588 \end_inset
589 </cell>
590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
591 \begin_inset Text
592
593 \begin_layout Standard
594 1.175494351E-38, 
595 \family roman
596 \series medium
597 \shape up
598 \size normal
599 \emph off
600 \bar no
601 \noun off
602 \color none
603 3.402823466E+38
604 \end_layout
605
606 \end_inset
607 </cell>
608 </row>
609 <row topline="true" bottomline="true">
610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
611 \begin_inset Text
612
613 \begin_layout Standard
614 pointer
615 \end_layout
616
617 \end_inset
618 </cell>
619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
620 \begin_inset Text
621
622 \begin_layout Standard
623 1, 2, 3 or 4 bytes
624 \end_layout
625
626 \end_inset
627 </cell>
628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
629 \begin_inset Text
630
631 \begin_layout Standard
632 generic
633 \end_layout
634
635 \end_inset
636 </cell>
637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
638 \begin_inset Text
639
640 \begin_layout Standard
641
642 \end_layout
643
644 \end_inset
645 </cell>
646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
647 \begin_inset Text
648
649 \begin_layout Standard
650
651 \end_layout
652
653 \end_inset
654 </cell>
655 </row>
656 </lyxtabular>
657
658 \end_inset
659
660
661 \newline
662 The compiler also allows 
663 \emph on
664 inline assembler code
665 \emph default
666  to be embedded anywhere in a function.
667  In addition, routines developed in assembly can also be called.
668 \newline
669
670 \newline
671 SDCC also
672  provides an option (-
673 \begin_inset ERT
674 status collapsed
675
676 \begin_layout Standard
677
678
679 \backslash
680 /
681 \end_layout
682
683 \end_inset
684
685 -cyclomatic) to report the relative complexity of a function.
686  These functions can then be further optimized, or hand coded in assembly
687  if needed.
688  
689 \newline
690
691 \newline
692 SDCC also comes with a companion source level debugger SDCDB.
693  The debugger currently uses ucSim, a free open source simulator for 8051
694  and other micro-controllers.
695 \newline
696
697 \newline
698 The latest SDCC version can be downloaded from
699  
700 \begin_inset LatexCommand url
701 target "http://sdcc.sourceforge.net/snap.php"
702
703 \end_inset
704
705 .
706  
707 \emph on
708 Please note: the compiler will probably always be some steps ahead of this
709  documentation
710 \series bold
711 \emph default
712
713 \begin_inset LatexCommand index
714 name "Status of documentation"
715
716 \end_inset
717
718
719 \begin_inset Foot
720 status open
721
722 \begin_layout Standard
723 Obviously this has pros and cons
724 \end_layout
725
726 \end_inset
727
728 .
729 \end_layout
730
731 \begin_layout Section
732 Open Source
733 \end_layout
734
735 \begin_layout Standard
736 All packages used in this compiler system are 
737 \emph on
738 open source
739 \emph default
740  and 
741 \emph on
742 freeware
743 \emph default
744 ; source code for all the sub-packages (pre-processor, assemblers, linkers
745  etc.) is distributed with the package.
746  This documentation is maintained using a free open source word processor
747  (LyX).
748 \newline
749 This program is free software; you can redistribute it and/or modify
750  it under the terms of the GNU General Public License
751 \begin_inset LatexCommand index
752 name "GNU General Public License, GPL"
753
754 \end_inset
755
756  as published by the Free Software Foundation; either version 2, or (at
757  your option) any later version.
758  This program is distributed in the hope that it will be useful, but WITHOUT
759  ANY WARRANTY; without even the implied warranty
760 \begin_inset LatexCommand index
761 name "warranty"
762
763 \end_inset
764
765  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
766  See the GNU General Public License for more details.
767  You should have received a copy of the GNU General Public License along
768  with this program; if not, write to the Free Software Foundation, 59 Temple
769  Place - Suite 330, Boston, MA 02111-1307, USA.
770  In other words, you are welcome to use, share and improve this program.
771  You are forbidden to forbid anyone else to use, share and improve what
772  you give them.
773  Help stamp out software-hoarding! 
774 \end_layout
775
776 \begin_layout Section
777 Typographic conventions
778 \begin_inset LatexCommand index
779 name "Typographic conventions"
780
781 \end_inset
782
783
784 \end_layout
785
786 \begin_layout Standard
787 Throughout this manual, we will use the following convention.
788  Commands you have to type in are printed in 
789 \family sans
790 \series bold
791 "sans serif"
792 \series default
793 .
794
795 \family default
796  Code samples are printed in 
797 \family typewriter
798 typewriter font.
799
800 \family default
801  Interesting items and new terms are printed in 
802 \emph on
803 italic.
804 \end_layout
805
806 \begin_layout Section
807 Compatibility
808 \begin_inset LatexCommand label
809 name "sec:Compatibility-with-previous"
810
811 \end_inset
812
813  with previous versions
814 \begin_inset LatexCommand index
815 name "Compatibility with previous versions"
816
817 \end_inset
818
819
820 \end_layout
821
822 \begin_layout Standard
823 Newer versions have usually numerous bug fixes compared with the previous
824  version.
825  But we also sometimes introduce some incompatibilities with older versions.
826  Not just for the fun of it, but to make the compiler more stable, efficient
827  and ANSI compliant
828 \begin_inset LatexCommand index
829 name "ANSI-compliance"
830
831 \end_inset
832
833  (see section 
834 \begin_inset LatexCommand ref
835 reference "sub:ANSI-Compliance"
836
837 \end_inset
838
839  for ANSI-Compliance).
840  
841 \begin_inset Note Note
842 status collapsed
843
844 \begin_layout Standard
845 It would be fine to add to each item, in which version was it changed.
846 \end_layout
847
848 \end_inset
849
850
851 \newline
852
853 \end_layout
854
855 \begin_layout Itemize
856 short is now equivalent to int (16 bits), it used to be equivalent to char
857  (8 bits) which is not ANSI compliant.
858  To maintain compatibility, old programs may be compiled using the -
859 \begin_inset ERT
860 status collapsed
861
862 \begin_layout Standard
863
864
865 \backslash
866 /
867 \end_layout
868
869 \end_inset
870
871 -short-is-8bits commandline option (see 
872 \begin_inset LatexCommand vref
873 reference "lyx:--short-is-8bits"
874
875 \end_inset
876
877 ).
878 \end_layout
879
880 \begin_layout Itemize
881 the default directory for gcc-builds where include, library and documentation
882  files are stored is now in /usr/local/share.
883 \end_layout
884
885 \begin_layout Itemize
886 char type parameters to vararg
887 \begin_inset LatexCommand index
888 name "vararg, va\\_arg"
889
890 \end_inset
891
892  functions are casted to int unless explicitly casted and 
893 \series bold
894 -
895 \begin_inset ERT
896 status collapsed
897
898 \begin_layout Standard
899
900
901 \backslash
902 /
903 \end_layout
904
905 \end_inset
906
907 -std-c89
908 \begin_inset LatexCommand index
909 name "-\\/-std-c89"
910
911 \end_inset
912
913
914 \series default
915  and 
916 \series bold
917 -
918 \begin_inset ERT
919 status collapsed
920
921 \begin_layout Standard
922
923
924 \backslash
925 /
926 \end_layout
927
928 \end_inset
929
930 -std-c99
931 \begin_inset LatexCommand index
932 name "-\\/-std-c99"
933
934 \end_inset
935
936
937 \series default
938  command line option are not defined 
939 \begin_inset Marginal
940 status collapsed
941
942 \begin_layout Standard
943
944 \series bold
945 \InsetSpace ~
946 !
947 \end_layout
948
949 \end_inset
950
951 , e.g.: 
952 \newline
953
954 \family typewriter
955 \InsetSpace ~
956 \InsetSpace ~
957 char a=3;
958 \newline
959 \InsetSpace ~
960 \InsetSpace ~
961 printf ("%d %c
962 \backslash
963 n", a, (char)a);
964 \family default
965
966 \newline
967  will push a as an int and as a char resp if 
968 \series bold
969 -
970 \begin_inset ERT
971 status collapsed
972
973 \begin_layout Standard
974
975
976 \backslash
977 /
978 \end_layout
979
980 \end_inset
981
982 -std-c89
983 \begin_inset LatexCommand index
984 name "-\\/-std-c89"
985
986 \end_inset
987
988
989 \series default
990  and 
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-c99
1006 \begin_inset LatexCommand index
1007 name "-\\/-std-c99"
1008
1009 \end_inset
1010
1011
1012 \series default
1013  command line options are not defined,
1014 \newline
1015  will push a as two ints if 
1016 \series bold
1017 -
1018 \begin_inset ERT
1019 status collapsed
1020
1021 \begin_layout Standard
1022
1023
1024 \backslash
1025 /
1026 \end_layout
1027
1028 \end_inset
1029
1030 -std-c89
1031 \begin_inset LatexCommand index
1032 name "-\\/-std-c89"
1033
1034 \end_inset
1035
1036
1037 \series default
1038  or 
1039 \series bold
1040 -
1041 \begin_inset ERT
1042 status collapsed
1043
1044 \begin_layout Standard
1045
1046
1047 \backslash
1048 /
1049 \end_layout
1050
1051 \end_inset
1052
1053 -std-c99
1054 \begin_inset LatexCommand index
1055 name "-\\/-std-c99"
1056
1057 \end_inset
1058
1059
1060 \series default
1061  command line option is defined.
1062 \end_layout
1063
1064 \begin_layout Itemize
1065 option -
1066 \begin_inset ERT
1067 status collapsed
1068
1069 \begin_layout Standard
1070
1071
1072 \backslash
1073 /
1074 \end_layout
1075
1076 \end_inset
1077
1078 -regextend has been removed.
1079 \end_layout
1080
1081 \begin_layout Itemize
1082 option -
1083 \begin_inset ERT
1084 status collapsed
1085
1086 \begin_layout Standard
1087
1088
1089 \backslash
1090 /
1091 \end_layout
1092
1093 \end_inset
1094
1095 -noregparms has been removed.
1096 \end_layout
1097
1098 \begin_layout Itemize
1099 option -
1100 \begin_inset ERT
1101 status collapsed
1102
1103 \begin_layout Standard
1104
1105
1106 \backslash
1107 /
1108 \end_layout
1109
1110 \end_inset
1111
1112 -stack-after-data has been removed.
1113 \end_layout
1114
1115 \begin_layout Itemize
1116 bit
1117 \begin_inset LatexCommand index
1118 name "bit"
1119
1120 \end_inset
1121
1122  and sbit
1123 \begin_inset LatexCommand index
1124 name "sbit"
1125
1126 \end_inset
1127
1128
1129 \begin_inset LatexCommand index
1130 name "\\_\\_sbit"
1131
1132 \end_inset
1133
1134  types now consistently behave like the C99 _Bool type with respect to type
1135  conversion
1136 \begin_inset LatexCommand index
1137 name "type conversion"
1138
1139 \end_inset
1140
1141
1142 \begin_inset LatexCommand index
1143 name "type promotion"
1144
1145 \end_inset
1146
1147 .
1148  The most common incompatibility resulting from this change is related to
1149  bit toggling
1150 \begin_inset LatexCommand index
1151 name "Bit toggling"
1152
1153 \end_inset
1154
1155  idioms, e.g.:
1156 \newline
1157
1158 \family typewriter
1159 \InsetSpace ~
1160 \InsetSpace ~
1161 bit b;
1162 \newline
1163 \InsetSpace ~
1164 \InsetSpace ~
1165 b = ~
1166 \begin_inset LatexCommand index
1167 name "\\~\\/ Operator"
1168
1169 \end_inset
1170
1171 b; /* equivalent to b=1 instead of toggling b */
1172 \begin_inset Marginal
1173 status collapsed
1174
1175 \begin_layout Standard
1176
1177 \series bold
1178 \InsetSpace ~
1179 !
1180 \end_layout
1181
1182 \end_inset
1183
1184
1185 \newline
1186 \InsetSpace ~
1187 \InsetSpace ~
1188 b = !b; /* toggles b */
1189 \newline
1190
1191 \family default
1192 In previous versions, both forms would have toggled the bit.
1193 \end_layout
1194
1195 \begin_layout Itemize
1196 in older versions, the preprocessor was always called with 
1197 \series bold
1198 -
1199 \begin_inset ERT
1200 status collapsed
1201
1202 \begin_layout Standard
1203
1204
1205 \backslash
1206 /
1207 \end_layout
1208
1209 \end_inset
1210
1211 -std-c99
1212 \begin_inset LatexCommand index
1213 name "-\\/-std-c99"
1214
1215 \end_inset
1216
1217
1218 \series default
1219  regardless of the 
1220 \series bold
1221 -
1222 \begin_inset ERT
1223 status collapsed
1224
1225 \begin_layout Standard
1226
1227
1228 \backslash
1229 /
1230 \end_layout
1231
1232 \end_inset
1233
1234 -std-xxx
1235 \series default
1236  setting.
1237  This is no longer true, and can cause compilation failures on code built
1238  with 
1239 \series bold
1240 -
1241 \begin_inset ERT
1242 status collapsed
1243
1244 \begin_layout Standard
1245
1246
1247 \backslash
1248 /
1249 \end_layout
1250
1251 \end_inset
1252
1253 -std-c89
1254 \begin_inset LatexCommand index
1255 name "-\\/-std-c89"
1256
1257 \end_inset
1258
1259
1260 \series default
1261  but using c99 preprocessor features, such as one-line (//) comments
1262 \end_layout
1263
1264 \begin_layout Itemize
1265 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1266  functions supported undocumented and not standard compliant 'b' binary
1267  format specifier ("%b", "%hb" and "%lb").
1268  The 'b' specifier is now disabled by default.
1269  It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1270 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1271 g the library.
1272 \end_layout
1273
1274 \begin_layout Itemize
1275 in versions older then 2.8.5 the unnamed bitfield structure members participated
1276  in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1277  (see section Section 6.7.8 Initialization, clause 9)
1278 \newline
1279
1280 \newline
1281 Old behavior, before
1282  version 2.8.5:
1283 \family typewriter
1284
1285 \newline
1286 \InsetSpace ~
1287 \InsetSpace ~
1288 struct {
1289 \newline
1290 \InsetSpace ~
1291 \InsetSpace ~
1292 \InsetSpace ~
1293 \InsetSpace ~
1294 int a : 2;
1295 \newline
1296 \InsetSpace ~
1297 \InsetSpace ~
1298 \InsetSpace ~
1299 \InsetSpace ~
1300 char\InsetSpace ~
1301  : 2;
1302 \newline
1303 \InsetSpace ~
1304 \InsetSpace ~
1305 \InsetSpace ~
1306 \InsetSpace ~
1307 int b : 2;
1308 \newline
1309 \InsetSpace ~
1310 \InsetSpace ~
1311 } s = {1, 2, 3};
1312 \family default
1313
1314 \newline
1315
1316 \family typewriter
1317 /* s.a = 1, s.b = 3 */
1318 \family default
1319
1320 \newline
1321
1322 \newline
1323 New behavior:
1324 \family typewriter
1325
1326 \newline
1327 \InsetSpace ~
1328 \InsetSpace ~
1329 struct {
1330 \newline
1331 \InsetSpace ~
1332 \InsetSpace ~
1333 \InsetSpace ~
1334 \InsetSpace ~
1335 int a : 2;
1336 \newline
1337 \InsetSpace ~
1338 \InsetSpace ~
1339 \InsetSpace ~
1340 \InsetSpace ~
1341 char\InsetSpace ~
1342  : 2;
1343 \newline
1344 \InsetSpace ~
1345 \InsetSpace ~
1346 \InsetSpace ~
1347 \InsetSpace ~
1348 int b : 2;
1349 \newline
1350 \InsetSpace ~
1351 \InsetSpace ~
1352 } s = {1, 2};
1353 \family default
1354
1355 \newline
1356
1357 \family typewriter
1358 /* s.a = 1, s.b = 2 */
1359 \end_layout
1360
1361 \begin_layout Section
1362 System Requirements
1363 \end_layout
1364
1365 \begin_layout Standard
1366 What do you need before you start installation of SDCC? A computer, and
1367  a desire to compute.
1368  The preferred method of installation is to compile SDCC from source using
1369  GNU gcc and make.
1370  For Windows some pre-compiled binary distributions are available for your
1371  convenience.
1372  You should have some experience with command line tools and compiler use.
1373 \end_layout
1374
1375 \begin_layout Section
1376 Other Resources
1377 \end_layout
1378
1379 \begin_layout Standard
1380 The SDCC home page at 
1381 \begin_inset LatexCommand url
1382 target "http://sdcc.sourceforge.net/"
1383
1384 \end_inset
1385
1386  is a great place to find distribution sets.
1387  You can also find links to the user mailing lists that offer help or discuss
1388  SDCC with other SDCC users.
1389  Web links to other SDCC related sites can also be found here.
1390  This document can be found in the DOC directory of the source package as
1391  a text or HTML file.
1392  A pdf version of this document is available at 
1393 \begin_inset LatexCommand url
1394 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
1395
1396 \end_inset
1397
1398 .
1399  Some of the other tools (simulator and assembler) included with SDCC contain
1400  their own documentation and can be found in the source distribution.
1401  If you want the latest unreleased software, the complete source package
1402  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1403 sdcc/trunk/sdcc.
1404 \end_layout
1405
1406 \begin_layout Section
1407 Wishes for the future
1408 \end_layout
1409
1410 \begin_layout Standard
1411 There are (and always will be) some things that could be done.
1412  Here are some I can think of:
1413 \newline
1414
1415 \end_layout
1416
1417 \begin_layout Standard
1418
1419 \family typewriter
1420 char KernelFunction3(char p) at 0x340;
1421 \newline
1422
1423 \end_layout
1424
1425 \begin_layout Standard
1426
1427 \family typewriter
1428 better code banking
1429 \begin_inset LatexCommand index
1430 name "code banking (limited support)"
1431
1432 \end_inset
1433
1434  support for mcs51
1435 \newline
1436
1437 \newline
1438
1439 \family default
1440 If you can think of some more, please see the section 
1441 \begin_inset LatexCommand ref
1442 reference "sub:Requesting-Features"
1443
1444 \end_inset
1445
1446  about filing feature requests
1447 \begin_inset LatexCommand index
1448 name "Requesting features"
1449
1450 \end_inset
1451
1452
1453 \begin_inset LatexCommand index
1454 name "Feature request"
1455
1456 \end_inset
1457
1458 .
1459 \newline
1460
1461 \end_layout
1462
1463 \begin_layout Chapter
1464 Installing SDCC
1465 \begin_inset LatexCommand index
1466 name "Installation"
1467
1468 \end_inset
1469
1470
1471 \end_layout
1472
1473 \begin_layout Standard
1474 For most users it is sufficient to skip to either section 
1475 \begin_inset LatexCommand ref
1476 reference "sub:Building-SDCC-on-Linux"
1477
1478 \end_inset
1479
1480  (Unix) or section 
1481 \begin_inset LatexCommand ref
1482 reference "sub:Windows-Install"
1483
1484 \end_inset
1485
1486  (Windows).
1487  More detailed instructions follow below.
1488 \end_layout
1489
1490 \begin_layout Section
1491 Configure Options
1492 \begin_inset LatexCommand index
1493 name "Options SDCC configuration"
1494
1495 \end_inset
1496
1497
1498 \end_layout
1499
1500 \begin_layout Standard
1501 The install paths, search paths and other options are defined when running
1502  'configure'.
1503  The defaults can be overridden by:
1504 \end_layout
1505
1506 \begin_layout List
1507 \labelwidthstring 00.00.0000
1508 -
1509 \begin_inset ERT
1510 status collapsed
1511
1512 \begin_layout Standard
1513
1514
1515 \backslash
1516 /
1517 \end_layout
1518
1519 \end_inset
1520
1521 -prefix see table below
1522 \end_layout
1523
1524 \begin_layout List
1525 \labelwidthstring 00.00.0000
1526 -
1527 \begin_inset ERT
1528 status collapsed
1529
1530 \begin_layout Standard
1531
1532
1533 \backslash
1534 /
1535 \end_layout
1536
1537 \end_inset
1538
1539 -exec_prefix see table below
1540 \end_layout
1541
1542 \begin_layout List
1543 \labelwidthstring 00.00.0000
1544 -
1545 \begin_inset ERT
1546 status collapsed
1547
1548 \begin_layout Standard
1549
1550
1551 \backslash
1552 /
1553 \end_layout
1554
1555 \end_inset
1556
1557 -bindir see table below
1558 \end_layout
1559
1560 \begin_layout List
1561 \labelwidthstring 00.00.0000
1562 -
1563 \begin_inset ERT
1564 status collapsed
1565
1566 \begin_layout Standard
1567
1568
1569 \backslash
1570 /
1571 \end_layout
1572
1573 \end_inset
1574
1575 -datadir see table below
1576 \end_layout
1577
1578 \begin_layout List
1579 \labelwidthstring 00.00.0000
1580 -
1581 \begin_inset ERT
1582 status collapsed
1583
1584 \begin_layout Standard
1585
1586
1587 \backslash
1588 /
1589 \end_layout
1590
1591 \end_inset
1592
1593 -datarootdir see table below
1594 \newline
1595
1596 \end_layout
1597
1598 \begin_layout List
1599 \labelwidthstring 00.00.0000
1600 \InsetSpace ~
1601 \InsetSpace ~
1602 docdir environment variable, see table below
1603 \end_layout
1604
1605 \begin_layout List
1606 \labelwidthstring 00.00.0000
1607 \InsetSpace ~
1608 \InsetSpace ~
1609 include_dir_suffix environment variable, see table below
1610 \end_layout
1611
1612 \begin_layout List
1613 \labelwidthstring 00.00.0000
1614 \InsetSpace ~
1615 \InsetSpace ~
1616 lib_dir_suffix environment variable, see table below
1617 \end_layout
1618
1619 \begin_layout List
1620 \labelwidthstring 00.00.0000
1621 \InsetSpace ~
1622 \InsetSpace ~
1623 sdccconf_h_dir_separator environment variable, either / or 
1624 \backslash
1625
1626 \backslash
1627  makes sense here.
1628  This character will only be used in sdccconf.h; don't forget it's a C-header,
1629  therefore a double-backslash is needed there.
1630 \newline
1631
1632 \end_layout
1633
1634 \begin_layout List
1635 \labelwidthstring 00.00.0000
1636 -
1637 \begin_inset ERT
1638 status collapsed
1639
1640 \begin_layout Standard
1641
1642
1643 \backslash
1644 /
1645 \end_layout
1646
1647 \end_inset
1648
1649 -disable-mcs51-port Excludes the Intel mcs51 port
1650 \end_layout
1651
1652 \begin_layout List
1653 \labelwidthstring 00.00.0000
1654 -
1655 \begin_inset ERT
1656 status collapsed
1657
1658 \begin_layout Standard
1659
1660
1661 \backslash
1662 /
1663 \end_layout
1664
1665 \end_inset
1666
1667 -disable-gbz80-port Excludes the Gameboy gbz80 port
1668 \end_layout
1669
1670 \begin_layout List
1671 \labelwidthstring 00.00.0000
1672 -
1673 \begin_inset ERT
1674 status collapsed
1675
1676 \begin_layout Standard
1677
1678
1679 \backslash
1680 /
1681 \end_layout
1682
1683 \end_inset
1684
1685 -disable-z80-port Excludes the z80 port
1686 \end_layout
1687
1688 \begin_layout List
1689 \labelwidthstring 00.00.0000
1690 -
1691 \begin_inset ERT
1692 status collapsed
1693
1694 \begin_layout Standard
1695
1696
1697 \backslash
1698 /
1699 \end_layout
1700
1701 \end_inset
1702
1703 -disable-avr-port Excludes the AVR port
1704 \end_layout
1705
1706 \begin_layout List
1707 \labelwidthstring 00.00.0000
1708 -
1709 \begin_inset ERT
1710 status collapsed
1711
1712 \begin_layout Standard
1713
1714
1715 \backslash
1716 /
1717 \end_layout
1718
1719 \end_inset
1720
1721 -disable-ds390-port Excludes the DS390 port
1722 \end_layout
1723
1724 \begin_layout List
1725 \labelwidthstring 00.00.0000
1726 -
1727 \begin_inset ERT
1728 status collapsed
1729
1730 \begin_layout Standard
1731
1732
1733 \backslash
1734 /
1735 \end_layout
1736
1737 \end_inset
1738
1739 -disable-hc08-port Excludes the HC08 port
1740 \end_layout
1741
1742 \begin_layout List
1743 \labelwidthstring 00.00.0000
1744 -
1745 \begin_inset ERT
1746 status collapsed
1747
1748 \begin_layout Standard
1749
1750
1751 \backslash
1752 /
1753 \end_layout
1754
1755 \end_inset
1756
1757 -disable-pic-port Excludes the PIC14 port
1758 \end_layout
1759
1760 \begin_layout List
1761 \labelwidthstring 00.00.0000
1762 -
1763 \begin_inset ERT
1764 status collapsed
1765
1766 \begin_layout Standard
1767
1768
1769 \backslash
1770 /
1771 \end_layout
1772
1773 \end_inset
1774
1775 -disable-pic16-port Excludes the PIC16 port
1776 \end_layout
1777
1778 \begin_layout List
1779 \labelwidthstring 00.00.0000
1780 -
1781 \begin_inset ERT
1782 status collapsed
1783
1784 \begin_layout Standard
1785
1786
1787 \backslash
1788 /
1789 \end_layout
1790
1791 \end_inset
1792
1793 -disable-xa51-port Excludes the XA51 port
1794 \end_layout
1795
1796 \begin_layout List
1797 \labelwidthstring 00.00.0000
1798 -
1799 \begin_inset ERT
1800 status collapsed
1801
1802 \begin_layout Standard
1803
1804
1805 \backslash
1806 /
1807 \end_layout
1808
1809 \end_inset
1810
1811 -disable-ucsim Disables configuring and building of ucsim
1812 \end_layout
1813
1814 \begin_layout List
1815 \labelwidthstring 00.00.0000
1816 -
1817 \begin_inset ERT
1818 status collapsed
1819
1820 \begin_layout Standard
1821
1822
1823 \backslash
1824 /
1825 \end_layout
1826
1827 \end_inset
1828
1829 -disable-device-lib Disables automatically building device libraries
1830 \end_layout
1831
1832 \begin_layout List
1833 \labelwidthstring 00.00.0000
1834 -
1835 \begin_inset ERT
1836 status collapsed
1837
1838 \begin_layout Standard
1839
1840
1841 \backslash
1842 /
1843 \end_layout
1844
1845 \end_inset
1846
1847 -disable-packihx Disables building packihx
1848 \newline
1849
1850 \end_layout
1851
1852 \begin_layout List
1853 \labelwidthstring 00.00.0000
1854 -
1855 \begin_inset ERT
1856 status collapsed
1857
1858 \begin_layout Standard
1859
1860
1861 \backslash
1862 /
1863 \end_layout
1864
1865 \end_inset
1866
1867 -enable-doc Build pdf, html and txt files from the lyx sources
1868 \end_layout
1869
1870 \begin_layout List
1871 \labelwidthstring 00.00.0000
1872 -
1873 \begin_inset ERT
1874 status collapsed
1875
1876 \begin_layout Standard
1877
1878
1879 \backslash
1880 /
1881 \end_layout
1882
1883 \end_inset
1884
1885 -enable-libgc Use the Bohem memory allocator.
1886  Lower runtime footprint.
1887 \end_layout
1888
1889 \begin_layout List
1890 \labelwidthstring 00.00.0000
1891 -
1892 \begin_inset ERT
1893 status collapsed
1894
1895 \begin_layout Standard
1896
1897
1898 \backslash
1899 /
1900 \end_layout
1901
1902 \end_inset
1903
1904 -without-ccache Do not use ccache even if available
1905 \end_layout
1906
1907 \begin_layout Standard
1908 Furthermore the environment variables CC, CFLAGS, ...
1909  the tools and their arguments can be influenced.
1910  Please see `configure -
1911 \begin_inset ERT
1912 status collapsed
1913
1914 \begin_layout Standard
1915
1916
1917 \backslash
1918 /
1919 \end_layout
1920
1921 \end_inset
1922
1923 -help' and the man/info pages of `configure' for details.
1924 \newline
1925
1926 \newline
1927 The names of the
1928  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1929 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1930  SDCC_LIB_NAME are defined by `configure' too.
1931  At the moment it's not possible to change the default settings (it was
1932  simply never required).
1933 \newline
1934
1935 \newline
1936 These configure options are compiled into the binaries,
1937  and can only be changed by rerunning 'configure' and recompiling SDCC.
1938  The configure options are written in 
1939 \emph on
1940 italics
1941 \emph default
1942  to distinguish them from run time environment variables (see section search
1943  paths).
1944 \newline
1945
1946 \newline
1947 The settings for 
1948 \begin_inset Quotes sld
1949 \end_inset
1950
1951 Win32 builds
1952 \begin_inset Quotes srd
1953 \end_inset
1954
1955  are used by the SDCC team to build the official Win32 binaries.
1956  The SDCC team uses Mingw32 to build the official Windows binaries, because
1957  it's
1958 \end_layout
1959
1960 \begin_layout Enumerate
1961 open source, 
1962 \end_layout
1963
1964 \begin_layout Enumerate
1965 a gcc compiler and last but not least
1966 \end_layout
1967
1968 \begin_layout Enumerate
1969 the binaries can be built by cross compiling on SDCC Distributed Compile
1970  Farm.
1971 \end_layout
1972
1973 \begin_layout Standard
1974 See the examples, how to pass the Win32 settings to 'configure'.
1975  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1976  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1977  for Win32.
1978 \newline
1979
1980 \newline
1981 These defaults are:
1982 \newline
1983
1984 \end_layout
1985
1986 \begin_layout Standard
1987 \align center
1988 \begin_inset Tabular
1989 <lyxtabular version="3" rows="9" columns="3">
1990 <features>
1991 <column alignment="block" valignment="top" leftline="true" width="0in">
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1994 <row topline="true" bottomline="true">
1995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1996 \begin_inset Text
1997
1998 \begin_layout Standard
1999 Variable
2000 \end_layout
2001
2002 \end_inset
2003 </cell>
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2005 \begin_inset Text
2006
2007 \begin_layout Standard
2008 default
2009 \end_layout
2010
2011 \end_inset
2012 </cell>
2013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2014 \begin_inset Text
2015
2016 \begin_layout Standard
2017 Win32 builds
2018 \end_layout
2019
2020 \end_inset
2021 </cell>
2022 </row>
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2025 \begin_inset Text
2026
2027 \begin_layout Standard
2028
2029 \emph on
2030 PREFIX
2031 \end_layout
2032
2033 \end_inset
2034 </cell>
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2036 \begin_inset Text
2037
2038 \begin_layout Standard
2039 /usr/local
2040 \end_layout
2041
2042 \end_inset
2043 </cell>
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2045 \begin_inset Text
2046
2047 \begin_layout Standard
2048
2049 \backslash
2050 sdcc
2051 \end_layout
2052
2053 \end_inset
2054 </cell>
2055 </row>
2056 <row topline="true">
2057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2058 \begin_inset Text
2059
2060 \begin_layout Standard
2061
2062 \emph on
2063 EXEC_PREFIX
2064 \end_layout
2065
2066 \end_inset
2067 </cell>
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2069 \begin_inset Text
2070
2071 \begin_layout Standard
2072
2073 \emph on
2074 $PREFIX
2075 \end_layout
2076
2077 \end_inset
2078 </cell>
2079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2080 \begin_inset Text
2081
2082 \begin_layout Standard
2083
2084 \emph on
2085 $PREFIX
2086 \end_layout
2087
2088 \end_inset
2089 </cell>
2090 </row>
2091 <row topline="true">
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2093 \begin_inset Text
2094
2095 \begin_layout Standard
2096
2097 \emph on
2098 BINDIR
2099 \end_layout
2100
2101 \end_inset
2102 </cell>
2103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2104 \begin_inset Text
2105
2106 \begin_layout Standard
2107
2108 \emph on
2109 $EXEC_PREFIX
2110 \emph default
2111 /bin
2112 \end_layout
2113
2114 \end_inset
2115 </cell>
2116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2117 \begin_inset Text
2118
2119 \begin_layout Standard
2120
2121 \emph on
2122 $EXEC_PREFIX
2123 \emph default
2124
2125 \backslash
2126 bin
2127 \end_layout
2128
2129 \end_inset
2130 </cell>
2131 </row>
2132 <row topline="true">
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2134 \begin_inset Text
2135
2136 \begin_layout Standard
2137
2138 \emph on
2139 DATADIR
2140 \end_layout
2141
2142 \end_inset
2143 </cell>
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2145 \begin_inset Text
2146
2147 \begin_layout Standard
2148
2149 \emph on
2150 $DATAROOTDIR
2151 \end_layout
2152
2153 \end_inset
2154 </cell>
2155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2156 \begin_inset Text
2157
2158 \begin_layout Standard
2159
2160 \emph on
2161 $DATAROOTDIR
2162 \end_layout
2163
2164 \end_inset
2165 </cell>
2166 </row>
2167 <row topline="true">
2168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2169 \begin_inset Text
2170
2171 \begin_layout Standard
2172
2173 \emph on
2174 DATAROOTDIR
2175 \end_layout
2176
2177 \end_inset
2178 </cell>
2179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2180 \begin_inset Text
2181
2182 \begin_layout Standard
2183
2184 \emph on
2185 $PREFIX
2186 \emph default
2187 /share
2188 \end_layout
2189
2190 \end_inset
2191 </cell>
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2193 \begin_inset Text
2194
2195 \begin_layout Standard
2196
2197 \emph on
2198 $PREFIX
2199 \end_layout
2200
2201 \end_inset
2202 </cell>
2203 </row>
2204 <row topline="true">
2205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2206 \begin_inset Text
2207
2208 \begin_layout Standard
2209
2210 \emph on
2211 DOCDIR
2212 \end_layout
2213
2214 \end_inset
2215 </cell>
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2217 \begin_inset Text
2218
2219 \begin_layout Standard
2220
2221 \emph on
2222 $DATAROOTDIR
2223 \emph default
2224 /sdcc/doc
2225 \end_layout
2226
2227 \end_inset
2228 </cell>
2229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2230 \begin_inset Text
2231
2232 \begin_layout Standard
2233
2234 \emph on
2235 $DATAROOTDIR
2236 \emph default
2237
2238 \backslash
2239 doc
2240 \end_layout
2241
2242 \end_inset
2243 </cell>
2244 </row>
2245 <row topline="true">
2246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2247 \begin_inset Text
2248
2249 \begin_layout Standard
2250
2251 \emph on
2252 INCLUDE_DIR_SUFFIX
2253 \end_layout
2254
2255 \end_inset
2256 </cell>
2257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2258 \begin_inset Text
2259
2260 \begin_layout Standard
2261 sdcc/include
2262 \end_layout
2263
2264 \end_inset
2265 </cell>
2266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2267 \begin_inset Text
2268
2269 \begin_layout Standard
2270 include
2271 \end_layout
2272
2273 \end_inset
2274 </cell>
2275 </row>
2276 <row topline="true" bottomline="true">
2277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2278 \begin_inset Text
2279
2280 \begin_layout Standard
2281
2282 \emph on
2283 LIB_DIR_SUFFIX
2284 \end_layout
2285
2286 \end_inset
2287 </cell>
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2289 \begin_inset Text
2290
2291 \begin_layout Standard
2292 sdcc/lib
2293 \end_layout
2294
2295 \end_inset
2296 </cell>
2297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2298 \begin_inset Text
2299
2300 \begin_layout Standard
2301 lib
2302 \end_layout
2303
2304 \end_inset
2305 </cell>
2306 </row>
2307 </lyxtabular>
2308
2309 \end_inset
2310
2311
2312 \newline
2313
2314 \end_layout
2315
2316 \begin_layout Standard
2317 \noindent
2318 'configure' also computes relative paths.
2319  This is needed for full relocatability of a binary package and to complete
2320  search paths (see section search paths below):
2321 \newline
2322  
2323 \end_layout
2324
2325 \begin_layout Standard
2326 \align center
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="4" columns="3">
2329 <features>
2330 <column alignment="block" valignment="top" leftline="true" width="0in">
2331 <column alignment="block" valignment="top" leftline="true" width="0in">
2332 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2333 <row topline="true" bottomline="true">
2334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2335 \begin_inset Text
2336
2337 \begin_layout Standard
2338 Variable (computed)
2339 \end_layout
2340
2341 \end_inset
2342 </cell>
2343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2344 \begin_inset Text
2345
2346 \begin_layout Standard
2347 default
2348 \end_layout
2349
2350 \end_inset
2351 </cell>
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2353 \begin_inset Text
2354
2355 \begin_layout Standard
2356 Win32 builds
2357 \end_layout
2358
2359 \end_inset
2360 </cell>
2361 </row>
2362 <row topline="true" bottomline="true">
2363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2364 \begin_inset Text
2365
2366 \begin_layout Standard
2367
2368 \emph on
2369 BIN2DATA_DIR
2370 \end_layout
2371
2372 \end_inset
2373 </cell>
2374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2375 \begin_inset Text
2376
2377 \begin_layout Standard
2378 ../share
2379 \end_layout
2380
2381 \end_inset
2382 </cell>
2383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2384 \begin_inset Text
2385
2386 \begin_layout Standard
2387 ..
2388 \end_layout
2389
2390 \end_inset
2391 </cell>
2392 </row>
2393 <row bottomline="true">
2394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2395 \begin_inset Text
2396
2397 \begin_layout Standard
2398
2399 \emph on
2400 PREFIX2BIN_DIR
2401 \end_layout
2402
2403 \end_inset
2404 </cell>
2405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2406 \begin_inset Text
2407
2408 \begin_layout Standard
2409 bin
2410 \end_layout
2411
2412 \end_inset
2413 </cell>
2414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2415 \begin_inset Text
2416
2417 \begin_layout Standard
2418 bin
2419 \end_layout
2420
2421 \end_inset
2422 </cell>
2423 </row>
2424 <row bottomline="true">
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2426 \begin_inset Text
2427
2428 \begin_layout Standard
2429
2430 \emph on
2431 PREFIX2DATA_DIR
2432 \end_layout
2433
2434 \end_inset
2435 </cell>
2436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2437 \begin_inset Text
2438
2439 \begin_layout Standard
2440 share/sdcc
2441 \end_layout
2442
2443 \end_inset
2444 </cell>
2445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2446 \begin_inset Text
2447
2448 \begin_layout Standard
2449
2450 \end_layout
2451
2452 \end_inset
2453 </cell>
2454 </row>
2455 </lyxtabular>
2456
2457 \end_inset
2458
2459
2460 \newline
2461
2462 \end_layout
2463
2464 \begin_layout Standard
2465 \noindent
2466 Examples:
2467 \end_layout
2468
2469 \begin_layout LyX-Code
2470 ./configure
2471 \newline
2472 ./configure -
2473 \begin_inset ERT
2474 status collapsed
2475
2476 \begin_layout Standard
2477
2478
2479 \backslash
2480 /
2481 \end_layout
2482
2483 \end_inset
2484
2485 -prefix=
2486 \begin_inset Quotes srd
2487 \end_inset
2488
2489 /usr/bin
2490 \begin_inset Quotes srd
2491 \end_inset
2492
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 -datarootdir=
2507 \begin_inset Quotes srd
2508 \end_inset
2509
2510 /usr/share
2511 \begin_inset Quotes srd
2512 \end_inset
2513
2514
2515 \newline
2516 ./configure -
2517 \begin_inset ERT
2518 status collapsed
2519
2520 \begin_layout Standard
2521
2522
2523 \backslash
2524 /
2525 \end_layout
2526
2527 \end_inset
2528
2529 -disable-avr-port -
2530 \begin_inset ERT
2531 status collapsed
2532
2533 \begin_layout Standard
2534
2535
2536 \backslash
2537 /
2538 \end_layout
2539
2540 \end_inset
2541
2542 -disable-xa51-port
2543 \end_layout
2544
2545 \begin_layout Standard
2546 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2547 32'):
2548 \end_layout
2549
2550 \begin_layout LyX-Code
2551 ./configure 
2552 \backslash
2553
2554 \newline
2555 CC=
2556 \begin_inset Quotes srd
2557 \end_inset
2558
2559 i586-mingw32msvc-gcc
2560 \begin_inset Quotes srd
2561 \end_inset
2562
2563  CXX=
2564 \begin_inset Quotes srd
2565 \end_inset
2566
2567 i586-mingw32msvc-g++
2568 \begin_inset Quotes srd
2569 \end_inset
2570
2571  
2572 \backslash
2573  
2574 \newline
2575 RANLIB=
2576 \begin_inset Quotes srd
2577 \end_inset
2578
2579 i586-mingw32msvc-ranlib
2580 \begin_inset Quotes srd
2581 \end_inset
2582
2583  
2584 \backslash
2585
2586 \newline
2587 STRIP=
2588 \begin_inset Quotes srd
2589 \end_inset
2590
2591 i586-mingw32msvc-strip
2592 \begin_inset Quotes srd
2593 \end_inset
2594
2595  
2596 \backslash
2597
2598 \newline
2599 -
2600 \begin_inset ERT
2601 status collapsed
2602
2603 \begin_layout Standard
2604
2605
2606 \backslash
2607 /
2608 \end_layout
2609
2610 \end_inset
2611
2612 -prefix=
2613 \begin_inset Quotes srd
2614 \end_inset
2615
2616 /sdcc
2617 \begin_inset Quotes srd
2618 \end_inset
2619
2620  
2621 \backslash
2622
2623 \newline
2624 -
2625 \begin_inset ERT
2626 status collapsed
2627
2628 \begin_layout Standard
2629
2630
2631 \backslash
2632 /
2633 \end_layout
2634
2635 \end_inset
2636
2637 -datarootdir=
2638 \begin_inset Quotes srd
2639 \end_inset
2640
2641 /sdcc
2642 \begin_inset Quotes srd
2643 \end_inset
2644
2645  
2646 \backslash
2647
2648 \newline
2649 docdir=
2650 \begin_inset Quotes srd
2651 \end_inset
2652
2653
2654 \backslash
2655 ${datarootdir}/doc
2656 \begin_inset Quotes srd
2657 \end_inset
2658
2659  
2660 \backslash
2661
2662 \newline
2663 include_dir_suffix=
2664 \begin_inset Quotes srd
2665 \end_inset
2666
2667 include
2668 \begin_inset Quotes srd
2669 \end_inset
2670
2671  
2672 \backslash
2673
2674 \newline
2675 lib_dir_suffix=
2676 \begin_inset Quotes srd
2677 \end_inset
2678
2679 lib
2680 \begin_inset Quotes srd
2681 \end_inset
2682
2683  
2684 \backslash
2685
2686 \newline
2687 sdccconf_h_dir_separator=
2688 \begin_inset Quotes srd
2689 \end_inset
2690
2691
2692 \backslash
2693
2694 \backslash
2695
2696 \backslash
2697
2698 \backslash
2699
2700 \begin_inset Quotes srd
2701 \end_inset
2702
2703  
2704 \backslash
2705
2706 \newline
2707 -
2708 \begin_inset ERT
2709 status collapsed
2710
2711 \begin_layout Standard
2712
2713
2714 \backslash
2715 /
2716 \end_layout
2717
2718 \end_inset
2719
2720 -disable-device-lib
2721 \backslash
2722
2723 \newline
2724 -
2725 \begin_inset ERT
2726 status collapsed
2727
2728 \begin_layout Standard
2729
2730
2731 \backslash
2732 /
2733 \end_layout
2734
2735 \end_inset
2736
2737 -host=i586-mingw32msvc
2738 \backslash
2739
2740 \newline
2741 -
2742 \begin_inset ERT
2743 status collapsed
2744
2745 \begin_layout Standard
2746
2747
2748 \backslash
2749 /
2750 \end_layout
2751
2752 \end_inset
2753
2754 -build=unknown-unknown-linux-gnu
2755 \end_layout
2756
2757 \begin_layout Standard
2758 To 
2759 \begin_inset Quotes sld
2760 \end_inset
2761
2762 cross
2763 \begin_inset Quotes srd
2764 \end_inset
2765
2766 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2767 ):
2768 \end_layout
2769
2770 \begin_layout LyX-Code
2771 ./configure -C 
2772 \backslash
2773
2774 \newline
2775 -
2776 \begin_inset ERT
2777 status collapsed
2778
2779 \begin_layout Standard
2780
2781
2782 \backslash
2783 /
2784 \end_layout
2785
2786 \end_inset
2787
2788 -prefix=
2789 \begin_inset Quotes srd
2790 \end_inset
2791
2792 /sdcc
2793 \begin_inset Quotes srd
2794 \end_inset
2795
2796  
2797 \backslash
2798
2799 \newline
2800 -
2801 \begin_inset ERT
2802 status collapsed
2803
2804 \begin_layout Standard
2805
2806
2807 \backslash
2808 /
2809 \end_layout
2810
2811 \end_inset
2812
2813 -datarootdir=
2814 \begin_inset Quotes srd
2815 \end_inset
2816
2817 /sdcc
2818 \begin_inset Quotes srd
2819 \end_inset
2820
2821  
2822 \backslash
2823
2824 \newline
2825 docdir=
2826 \begin_inset Quotes srd
2827 \end_inset
2828
2829
2830 \backslash
2831 ${datarootdir}/doc
2832 \begin_inset Quotes srd
2833 \end_inset
2834
2835  
2836 \backslash
2837  
2838 \newline
2839 include_dir_suffix=
2840 \begin_inset Quotes srd
2841 \end_inset
2842
2843 include
2844 \begin_inset Quotes srd
2845 \end_inset
2846
2847  
2848 \backslash
2849
2850 \newline
2851 lib_dir_suffix=
2852 \begin_inset Quotes srd
2853 \end_inset
2854
2855 lib
2856 \begin_inset Quotes srd
2857 \end_inset
2858
2859  
2860 \backslash
2861
2862 \newline
2863 sdccconf_h_dir_separator=
2864 \begin_inset Quotes srd
2865 \end_inset
2866
2867
2868 \backslash
2869
2870 \backslash
2871
2872 \backslash
2873
2874 \backslash
2875
2876 \begin_inset Quotes srd
2877 \end_inset
2878
2879  
2880 \backslash
2881
2882 \newline
2883 CC=
2884 \begin_inset Quotes srd
2885 \end_inset
2886
2887 gcc -mno-cygwin
2888 \begin_inset Quotes srd
2889 \end_inset
2890
2891  
2892 \backslash
2893
2894 \newline
2895 CXX=
2896 \begin_inset Quotes srd
2897 \end_inset
2898
2899 g++ -mno-cygwin
2900 \begin_inset Quotes srd
2901 \end_inset
2902
2903  
2904 \end_layout
2905
2906 \begin_layout Standard
2907 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2908  The option '-
2909 \begin_inset ERT
2910 status collapsed
2911
2912 \begin_layout Standard
2913
2914
2915 \backslash
2916 /
2917 \end_layout
2918
2919 \end_inset
2920
2921 -C' turns on caching, which gives a little bit extra speed.
2922  However if options are changed, it can be necessary to delete the config.cache
2923  file.
2924 \end_layout
2925
2926 \begin_layout Section
2927 Install paths
2928 \begin_inset LatexCommand label
2929 name "sub:Install-paths"
2930
2931 \end_inset
2932
2933
2934 \begin_inset LatexCommand index
2935 name "Install paths"
2936
2937 \end_inset
2938
2939
2940 \end_layout
2941
2942 \begin_layout Standard
2943 \begin_inset VSpace medskip
2944 \end_inset
2945
2946
2947 \end_layout
2948
2949 \begin_layout Standard
2950 \align center
2951 \begin_inset Tabular
2952 <lyxtabular version="3" rows="5" columns="4">
2953 <features>
2954 <column alignment="left" valignment="top" leftline="true" width="0">
2955 <column alignment="left" valignment="top" leftline="true" width="0">
2956 <column alignment="left" valignment="top" leftline="true" width="0">
2957 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2958 <row topline="true" bottomline="true">
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_inset Text
2961
2962 \begin_layout Standard
2963
2964 \series bold
2965 Description
2966 \end_layout
2967
2968 \end_inset
2969 </cell>
2970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2971 \begin_inset Text
2972
2973 \begin_layout Standard
2974
2975 \series bold
2976 Path
2977 \end_layout
2978
2979 \end_inset
2980 </cell>
2981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2982 \begin_inset Text
2983
2984 \begin_layout Standard
2985
2986 \series bold
2987 Default
2988 \end_layout
2989
2990 \end_inset
2991 </cell>
2992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2993 \begin_inset Text
2994
2995 \begin_layout Standard
2996
2997 \series bold
2998 Win32 builds
2999 \end_layout
3000
3001 \end_inset
3002 </cell>
3003 </row>
3004 <row topline="true">
3005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3006 \begin_inset Text
3007
3008 \begin_layout Standard
3009 Binary files*
3010 \end_layout
3011
3012 \end_inset
3013 </cell>
3014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3015 \begin_inset Text
3016
3017 \begin_layout Standard
3018
3019 \emph on
3020 $EXEC_PREFIX
3021 \end_layout
3022
3023 \end_inset
3024 </cell>
3025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3026 \begin_inset Text
3027
3028 \begin_layout Standard
3029 /usr/local/bin
3030 \end_layout
3031
3032 \end_inset
3033 </cell>
3034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3035 \begin_inset Text
3036
3037 \begin_layout Standard
3038
3039 \backslash
3040 sdcc
3041 \backslash
3042 bin
3043 \end_layout
3044
3045 \end_inset
3046 </cell>
3047 </row>
3048 <row topline="true">
3049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3050 \begin_inset Text
3051
3052 \begin_layout Standard
3053 Include files
3054 \end_layout
3055
3056 \end_inset
3057 </cell>
3058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3059 \begin_inset Text
3060
3061 \begin_layout Standard
3062
3063 \emph on
3064 $DATADIR/ $INCLUDE_DIR_SUFFIX
3065 \end_layout
3066
3067 \end_inset
3068 </cell>
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3070 \begin_inset Text
3071
3072 \begin_layout Standard
3073 /usr/local/share/sdcc/include
3074 \end_layout
3075
3076 \end_inset
3077 </cell>
3078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3079 \begin_inset Text
3080
3081 \begin_layout Standard
3082
3083 \backslash
3084 sdcc
3085 \backslash
3086 include
3087 \end_layout
3088
3089 \end_inset
3090 </cell>
3091 </row>
3092 <row topline="true">
3093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_inset Text
3095
3096 \begin_layout Standard
3097 Library file**
3098 \end_layout
3099
3100 \end_inset
3101 </cell>
3102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3103 \begin_inset Text
3104
3105 \begin_layout Standard
3106
3107 \emph on
3108 $DATADIR/$LIB_DIR_SUFFIX
3109 \end_layout
3110
3111 \end_inset
3112 </cell>
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3114 \begin_inset Text
3115
3116 \begin_layout Standard
3117 /usr/local/share/sdcc/lib
3118 \end_layout
3119
3120 \end_inset
3121 </cell>
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3123 \begin_inset Text
3124
3125 \begin_layout Standard
3126
3127 \backslash
3128 sdcc
3129 \backslash
3130 lib
3131 \end_layout
3132
3133 \end_inset
3134 </cell>
3135 </row>
3136 <row topline="true" bottomline="true">
3137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3138 \begin_inset Text
3139
3140 \begin_layout Standard
3141 Documentation
3142 \end_layout
3143
3144 \end_inset
3145 </cell>
3146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3147 \begin_inset Text
3148
3149 \begin_layout Standard
3150
3151 \emph on
3152 $DOCDIR
3153 \end_layout
3154
3155 \end_inset
3156 </cell>
3157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3158 \begin_inset Text
3159
3160 \begin_layout Standard
3161 /usr/local/share/sdcc/doc
3162 \end_layout
3163
3164 \end_inset
3165 </cell>
3166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3167 \begin_inset Text
3168
3169 \begin_layout Standard
3170
3171 \backslash
3172 sdcc
3173 \backslash
3174 doc
3175 \end_layout
3176
3177 \end_inset
3178 </cell>
3179 </row>
3180 </lyxtabular>
3181
3182 \end_inset
3183
3184
3185 \end_layout
3186
3187 \begin_layout Verse
3188
3189 \size footnotesize
3190 *compiler, preprocessor, assembler, and linker
3191 \newline
3192 **the 
3193 \shape italic
3194 model
3195 \shape default
3196  is auto-appended by the compiler, e.g.
3197  small, large, z80, ds390 etc
3198 \end_layout
3199
3200 \begin_layout Standard
3201 \noindent
3202 The install paths can still be changed during `make install' with e.g.:
3203 \end_layout
3204
3205 \begin_layout LyX-Code
3206 make install prefix=$(HOME)/local/sdcc
3207 \end_layout
3208
3209 \begin_layout Standard
3210 Of course this doesn't change the search paths compiled into the binaries.
3211 \newline
3212
3213 \newline
3214 Moreove
3215 r the install path can be changed by defining DESTDIR
3216 \begin_inset LatexCommand index
3217 name "DESTDIR"
3218
3219 \end_inset
3220
3221 :
3222 \end_layout
3223
3224 \begin_layout LyX-Code
3225 make install DESTDIR=$(HOME)/sdcc.rpm/
3226 \end_layout
3227
3228 \begin_layout Standard
3229 Please note that DESTDIR must have a trailing slash!
3230 \end_layout
3231
3232 \begin_layout Section
3233 Search Paths
3234 \begin_inset LatexCommand label
3235 name "sub:Search-Paths"
3236
3237 \end_inset
3238
3239
3240 \begin_inset LatexCommand index
3241 name "Search path"
3242
3243 \end_inset
3244
3245
3246 \end_layout
3247
3248 \begin_layout Standard
3249 Some search paths or parts of them are determined by configure variables
3250  (in 
3251 \emph on
3252 italics
3253 \emph default
3254 , see section above).
3255  Further search paths are determined by environment variables during runtime.
3256  
3257 \newline
3258 The paths searched when running the compiler are as follows (the first
3259  catch wins):
3260 \newline
3261
3262 \newline
3263 1.
3264  Binary files (preprocessor, assembler and linker)
3265 \newline
3266
3267 \end_layout
3268
3269 \begin_layout Standard
3270 \align center
3271 \begin_inset Tabular
3272 <lyxtabular version="3" rows="4" columns="3">
3273 <features>
3274 <column alignment="block" valignment="top" leftline="true" width="0in">
3275 <column alignment="block" valignment="top" leftline="true" width="0in">
3276 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3277 <row topline="true" bottomline="true">
3278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3279 \begin_inset Text
3280
3281 \begin_layout Standard
3282 Search path
3283 \end_layout
3284
3285 \end_inset
3286 </cell>
3287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3288 \begin_inset Text
3289
3290 \begin_layout Standard
3291 default
3292 \end_layout
3293
3294 \end_inset
3295 </cell>
3296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3297 \begin_inset Text
3298
3299 \begin_layout Standard
3300 Win32 builds
3301 \end_layout
3302
3303 \end_inset
3304 </cell>
3305 </row>
3306 <row topline="true">
3307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3308 \begin_inset Text
3309
3310 \begin_layout Standard
3311 $SDCC_HOME/
3312 \emph on
3313 $PPREFIX2BIN_DIR
3314 \end_layout
3315
3316 \end_inset
3317 </cell>
3318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3319 \begin_inset Text
3320
3321 \begin_layout Standard
3322 $SDCC_HOME/bin
3323 \end_layout
3324
3325 \end_inset
3326 </cell>
3327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3328 \begin_inset Text
3329
3330 \begin_layout Standard
3331 $SDCC_HOME
3332 \backslash
3333 bin
3334 \end_layout
3335
3336 \end_inset
3337 </cell>
3338 </row>
3339 <row topline="true">
3340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3341 \begin_inset Text
3342
3343 \begin_layout Standard
3344 Path of argv[0] (if available)
3345 \end_layout
3346
3347 \end_inset
3348 </cell>
3349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3350 \begin_inset Text
3351
3352 \begin_layout Standard
3353 Path of argv[0]
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 Path of argv[0]
3363 \end_layout
3364
3365 \end_inset
3366 </cell>
3367 </row>
3368 <row topline="true" bottomline="true">
3369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3370 \begin_inset Text
3371
3372 \begin_layout Standard
3373 $PATH
3374 \end_layout
3375
3376 \end_inset
3377 </cell>
3378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3379 \begin_inset Text
3380
3381 \begin_layout Standard
3382 $PATH
3383 \end_layout
3384
3385 \end_inset
3386 </cell>
3387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3388 \begin_inset Text
3389
3390 \begin_layout Standard
3391 $PATH
3392 \end_layout
3393
3394 \end_inset
3395 </cell>
3396 </row>
3397 </lyxtabular>
3398
3399 \end_inset
3400
3401  
3402 \newline
3403
3404 \end_layout
3405
3406 \begin_layout Standard
3407 \noindent
3408 2.
3409  Include files
3410 \newline
3411
3412 \end_layout
3413
3414 \begin_layout Standard
3415 \align center
3416 \begin_inset Tabular
3417 <lyxtabular version="3" rows="6" columns="3">
3418 <features>
3419 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3420 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3421 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3422 <row topline="true" bottomline="true">
3423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3424 \begin_inset Text
3425
3426 \begin_layout Standard
3427 Search path
3428 \end_layout
3429
3430 \end_inset
3431 </cell>
3432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3433 \begin_inset Text
3434
3435 \begin_layout Standard
3436 default
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 Win32 builds
3446 \end_layout
3447
3448 \end_inset
3449 </cell>
3450 </row>
3451 <row topline="true">
3452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3453 \begin_inset Text
3454
3455 \begin_layout Standard
3456 -
3457 \begin_inset ERT
3458 status collapsed
3459
3460 \begin_layout Standard
3461
3462
3463 \backslash
3464 /
3465 \end_layout
3466
3467 \end_inset
3468
3469 -I dir
3470 \end_layout
3471
3472 \end_inset
3473 </cell>
3474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3475 \begin_inset Text
3476
3477 \begin_layout Standard
3478 -
3479 \begin_inset ERT
3480 status collapsed
3481
3482 \begin_layout Standard
3483
3484
3485 \backslash
3486 /
3487 \end_layout
3488
3489 \end_inset
3490
3491 -I dir
3492 \end_layout
3493
3494 \end_inset
3495 </cell>
3496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3497 \begin_inset Text
3498
3499 \begin_layout Standard
3500 -
3501 \begin_inset ERT
3502 status collapsed
3503
3504 \begin_layout Standard
3505
3506
3507 \backslash
3508 /
3509 \end_layout
3510
3511 \end_inset
3512
3513 -I dir
3514 \end_layout
3515
3516 \end_inset
3517 </cell>
3518 </row>
3519 <row topline="true">
3520 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3521 \begin_inset Text
3522
3523 \begin_layout Standard
3524 $SDCC_INCLUDE
3525 \end_layout
3526
3527 \end_inset
3528 </cell>
3529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3530 \begin_inset Text
3531
3532 \begin_layout Standard
3533 $SDCC_INCLUDE
3534 \end_layout
3535
3536 \end_inset
3537 </cell>
3538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3539 \begin_inset Text
3540
3541 \begin_layout Standard
3542 $SDCC_INCLUDE
3543 \end_layout
3544
3545 \end_inset
3546 </cell>
3547 </row>
3548 <row topline="true">
3549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3550 \begin_inset Text
3551
3552 \begin_layout Standard
3553 $SDCC_HOME/
3554 \newline
3555
3556 \emph on
3557 $PREFIX2DATA_DIR/
3558 \newline
3559 $INCLUDE_DIR_SUFFIX
3560 \end_layout
3561
3562 \end_inset
3563 </cell>
3564 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3565 \begin_inset Text
3566
3567 \begin_layout Standard
3568 $SDCC_ HOME/
3569 \newline
3570 share/sdcc/
3571 \newline
3572 include
3573 \end_layout
3574
3575 \end_inset
3576 </cell>
3577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3578 \begin_inset Text
3579
3580 \begin_layout Standard
3581 $SDCC_HOME
3582 \backslash
3583 include
3584 \end_layout
3585
3586 \end_inset
3587 </cell>
3588 </row>
3589 <row topline="true">
3590 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3591 \begin_inset Text
3592
3593 \begin_layout Standard
3594 path(argv[0])/
3595 \newline
3596
3597 \emph on
3598 $BIN2DATADIR/
3599 \emph default
3600
3601 \newline
3602
3603 \emph on
3604 $INCLUDE_DIR_SUFFIX
3605 \end_layout
3606
3607 \end_inset
3608 </cell>
3609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3610 \begin_inset Text
3611
3612 \begin_layout Standard
3613 path(argv[0])/
3614 \newline
3615 ../sdcc/include
3616 \newline
3617 \InsetSpace ~
3618 \InsetSpace ~
3619 \InsetSpace ~
3620 \InsetSpace ~
3621 \InsetSpace ~
3622 \InsetSpace ~
3623 \InsetSpace ~
3624 \InsetSpace ~
3625 \InsetSpace ~
3626 \InsetSpace ~
3627 \InsetSpace ~
3628 \InsetSpace ~
3629 \InsetSpace ~
3630 \InsetSpace ~
3631 \InsetSpace ~
3632 \InsetSpace ~
3633 \InsetSpace ~
3634 \InsetSpace ~
3635 \InsetSpace ~
3636 \InsetSpace ~
3637 \InsetSpace ~
3638 \InsetSpace ~
3639 \InsetSpace ~
3640 \InsetSpace ~
3641 \InsetSpace ~
3642 \InsetSpace ~
3643 \InsetSpace ~
3644 \InsetSpace ~
3645 \InsetSpace ~
3646 \InsetSpace ~
3647 \InsetSpace ~
3648 \InsetSpace ~
3649 \InsetSpace ~
3650 \InsetSpace ~
3651 \InsetSpace ~
3652 \InsetSpace ~
3653 \InsetSpace ~
3654 \InsetSpace ~
3655
3656 \end_layout
3657
3658 \end_inset
3659 </cell>
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3661 \begin_inset Text
3662
3663 \begin_layout Standard
3664 path(argv[0])
3665 \backslash
3666 ..
3667 \backslash
3668 include
3669 \end_layout
3670
3671 \end_inset
3672 </cell>
3673 </row>
3674 <row topline="true" bottomline="true">
3675 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3676 \begin_inset Text
3677
3678 \begin_layout Standard
3679
3680 \emph on
3681 $DATADIR/
3682 \emph default
3683
3684 \newline
3685
3686 \emph on
3687 $INCLUDE_DIR_SUFFIX
3688 \end_layout
3689
3690 \end_inset
3691 </cell>
3692 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3693 \begin_inset Text
3694
3695 \begin_layout Standard
3696 /usr/local/share/sdcc/
3697 \newline
3698 include
3699 \end_layout
3700
3701 \end_inset
3702 </cell>
3703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3704 \begin_inset Text
3705
3706 \begin_layout Standard
3707 (not on Win32)
3708 \end_layout
3709
3710 \end_inset
3711 </cell>
3712 </row>
3713 </lyxtabular>
3714
3715 \end_inset
3716
3717  
3718 \newline
3719
3720 \end_layout
3721
3722 \begin_layout Standard
3723 \noindent
3724 The option -
3725 \begin_inset ERT
3726 status collapsed
3727
3728 \begin_layout Standard
3729
3730
3731 \backslash
3732 /
3733 \end_layout
3734
3735 \end_inset
3736
3737 -nostdinc disables the last two search paths.
3738 \newline
3739
3740 \newline
3741 3.
3742  Library files 
3743 \newline
3744
3745 \end_layout
3746
3747 \begin_layout Standard
3748 With the exception of 
3749 \begin_inset Quotes sld
3750 \end_inset
3751
3752 -
3753 \begin_inset ERT
3754 status collapsed
3755
3756 \begin_layout Standard
3757
3758
3759 \backslash
3760 /
3761 \end_layout
3762
3763 \end_inset
3764
3765 -L dir
3766 \begin_inset Quotes srd
3767 \end_inset
3768
3769  the 
3770 \shape italic
3771 model
3772 \shape default
3773  is auto-appended by the compiler (e.g.
3774  small, large, z80, ds390 etc.).
3775  
3776 \newline
3777
3778 \end_layout
3779
3780 \begin_layout Standard
3781 \align center
3782 \begin_inset Tabular
3783 <lyxtabular version="3" rows="6" columns="3">
3784 <features>
3785 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3786 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3787 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3788 <row topline="true" bottomline="true">
3789 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3790 \begin_inset Text
3791
3792 \begin_layout Standard
3793 Search path
3794 \end_layout
3795
3796 \end_inset
3797 </cell>
3798 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3799 \begin_inset Text
3800
3801 \begin_layout Standard
3802 default
3803 \end_layout
3804
3805 \end_inset
3806 </cell>
3807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3808 \begin_inset Text
3809
3810 \begin_layout Standard
3811 Win32 builds
3812 \end_layout
3813
3814 \end_inset
3815 </cell>
3816 </row>
3817 <row topline="true">
3818 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3819 \begin_inset Text
3820
3821 \begin_layout Standard
3822 -
3823 \begin_inset ERT
3824 status collapsed
3825
3826 \begin_layout Standard
3827
3828
3829 \backslash
3830 /
3831 \end_layout
3832
3833 \end_inset
3834
3835 -L dir
3836 \end_layout
3837
3838 \end_inset
3839 </cell>
3840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3841 \begin_inset Text
3842
3843 \begin_layout Standard
3844 -
3845 \begin_inset ERT
3846 status collapsed
3847
3848 \begin_layout Standard
3849
3850
3851 \backslash
3852 /
3853 \end_layout
3854
3855 \end_inset
3856
3857 -L dir
3858 \end_layout
3859
3860 \end_inset
3861 </cell>
3862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3863 \begin_inset Text
3864
3865 \begin_layout Standard
3866 -
3867 \begin_inset ERT
3868 status collapsed
3869
3870 \begin_layout Standard
3871
3872
3873 \backslash
3874 /
3875 \end_layout
3876
3877 \end_inset
3878
3879 -L dir
3880 \end_layout
3881
3882 \end_inset
3883 </cell>
3884 </row>
3885 <row topline="true">
3886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3887 \begin_inset Text
3888
3889 \begin_layout Standard
3890 $SDCC_LIB/
3891 \newline
3892
3893 \emph on
3894 <model>
3895 \end_layout
3896
3897 \end_inset
3898 </cell>
3899 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3900 \begin_inset Text
3901
3902 \begin_layout Standard
3903 $SDCC_LIB/
3904 \newline
3905
3906 \emph on
3907 <model>
3908 \end_layout
3909
3910 \end_inset
3911 </cell>
3912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3913 \begin_inset Text
3914
3915 \begin_layout Standard
3916 $SDCC_LIB
3917 \backslash
3918
3919 \newline
3920
3921 \emph on
3922 <model>
3923 \end_layout
3924
3925 \end_inset
3926 </cell>
3927 </row>
3928 <row topline="true">
3929 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3930 \begin_inset Text
3931
3932 \begin_layout Standard
3933 $SDCC_HOME/
3934 \newline
3935
3936 \emph on
3937 $PREFIX2DATA_DIR/
3938 \newline
3939 $LIB_DIR_SUFFIX/<model>
3940 \end_layout
3941
3942 \end_inset
3943 </cell>
3944 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3945 \begin_inset Text
3946
3947 \begin_layout Standard
3948 $SDCC_HOME/
3949 \newline
3950 share/sdcc/
3951 \newline
3952 lib/
3953 \emph on
3954 <model>
3955 \end_layout
3956
3957 \end_inset
3958 </cell>
3959 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3960 \begin_inset Text
3961
3962 \begin_layout Standard
3963 $SDCC_HOME
3964 \backslash
3965 lib
3966 \backslash
3967
3968 \emph on
3969
3970 \newline
3971 <model>
3972 \end_layout
3973
3974 \end_inset
3975 </cell>
3976 </row>
3977 <row topline="true">
3978 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3979 \begin_inset Text
3980
3981 \begin_layout Standard
3982 path(argv[0])/
3983 \newline
3984
3985 \emph on
3986 $BIN2DATADIR/
3987 \emph default
3988
3989 \newline
3990
3991 \emph on
3992 $LIB_DIR_SUFFIX/<model>
3993 \end_layout
3994
3995 \end_inset
3996 </cell>
3997 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3998 \begin_inset Text
3999
4000 \begin_layout Standard
4001 path(argv[0])/
4002 \newline
4003 ../sdcc/lib/
4004 \emph on
4005 <model>
4006 \newline
4007 \InsetSpace ~
4008 \InsetSpace ~
4009 \InsetSpace ~
4010 \InsetSpace ~
4011 \InsetSpace ~
4012 \InsetSpace ~
4013 \InsetSpace ~
4014 \InsetSpace ~
4015 \InsetSpace ~
4016 \InsetSpace ~
4017 \InsetSpace ~
4018 \InsetSpace ~
4019 \InsetSpace ~
4020 \InsetSpace ~
4021 \InsetSpace ~
4022 \InsetSpace ~
4023 \InsetSpace ~
4024 \InsetSpace ~
4025 \InsetSpace ~
4026 \InsetSpace ~
4027 \InsetSpace ~
4028 \InsetSpace ~
4029 \InsetSpace ~
4030 \InsetSpace ~
4031 \InsetSpace ~
4032 \InsetSpace ~
4033 \InsetSpace ~
4034 \InsetSpace ~
4035 \InsetSpace ~
4036 \InsetSpace ~
4037 \InsetSpace ~
4038 \InsetSpace ~
4039 \InsetSpace ~
4040 \InsetSpace ~
4041 \InsetSpace ~
4042 \InsetSpace ~
4043 \InsetSpace ~
4044 \InsetSpace ~
4045 \InsetSpace ~
4046
4047 \end_layout
4048
4049 \end_inset
4050 </cell>
4051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4052 \begin_inset Text
4053
4054 \begin_layout Standard
4055 path(argv[0])
4056 \backslash
4057
4058 \newline
4059 ..
4060 \backslash
4061 lib
4062 \backslash
4063
4064 \emph on
4065 <model>
4066 \newline
4067 \InsetSpace ~
4068 \InsetSpace ~
4069 \InsetSpace ~
4070 \InsetSpace ~
4071 \InsetSpace ~
4072 \InsetSpace ~
4073 \InsetSpace ~
4074 \InsetSpace ~
4075 \InsetSpace ~
4076 \InsetSpace ~
4077 \InsetSpace ~
4078 \InsetSpace ~
4079 \InsetSpace ~
4080 \InsetSpace ~
4081 \InsetSpace ~
4082 \InsetSpace ~
4083 \InsetSpace ~
4084 \InsetSpace ~
4085 \InsetSpace ~
4086 \InsetSpace ~
4087 \InsetSpace ~
4088 \InsetSpace ~
4089 \InsetSpace ~
4090 \InsetSpace ~
4091 \InsetSpace ~
4092 \InsetSpace ~
4093 \InsetSpace ~
4094 \InsetSpace ~
4095 \InsetSpace ~
4096 \InsetSpace ~
4097 \InsetSpace ~
4098 \InsetSpace ~
4099 \InsetSpace ~
4100 \InsetSpace ~
4101 \InsetSpace ~
4102
4103 \end_layout
4104
4105 \end_inset
4106 </cell>
4107 </row>
4108 <row topline="true" bottomline="true">
4109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4110 \begin_inset Text
4111
4112 \begin_layout Standard
4113
4114 \emph on
4115 $DATADIR/
4116 \newline
4117 $LIB_DIR_SUFFIX/<model>
4118 \end_layout
4119
4120 \end_inset
4121 </cell>
4122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4123 \begin_inset Text
4124
4125 \begin_layout Standard
4126 /usr/local/share/sdcc/
4127 \newline
4128 lib/
4129 \emph on
4130 <model>
4131 \end_layout
4132
4133 \end_inset
4134 </cell>
4135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4136 \begin_inset Text
4137
4138 \begin_layout Standard
4139 (not on Win32)
4140 \end_layout
4141
4142 \end_inset
4143 </cell>
4144 </row>
4145 </lyxtabular>
4146
4147 \end_inset
4148
4149
4150 \newline
4151
4152 \end_layout
4153
4154 \begin_layout Standard
4155 \begin_inset Note Note
4156 status collapsed
4157
4158 \begin_layout Standard
4159 Don't delete any of the stray spaces in the table above without checking
4160  the HTML output (last line)!
4161 \end_layout
4162
4163 \end_inset
4164
4165
4166 \end_layout
4167
4168 \begin_layout Standard
4169 \InsetSpace ~
4170
4171 \newline
4172 The option -
4173 \begin_inset ERT
4174 status collapsed
4175
4176 \begin_layout Standard
4177
4178
4179 \backslash
4180 /
4181 \end_layout
4182
4183 \end_inset
4184
4185 -nostdlib disables the last two search paths.
4186 \end_layout
4187
4188 \begin_layout Section
4189 Building SDCC
4190 \begin_inset LatexCommand index
4191 name "Building SDCC"
4192
4193 \end_inset
4194
4195
4196 \end_layout
4197
4198 \begin_layout Subsection
4199 Building SDCC on Linux
4200 \begin_inset LatexCommand label
4201 name "sub:Building-SDCC-on-Linux"
4202
4203 \end_inset
4204
4205
4206 \end_layout
4207
4208 \begin_layout Enumerate
4209
4210 \series medium
4211 Download the source package
4212 \series default
4213  either from the SDCC Subversion repository or from snapshot builds
4214 \series medium
4215 , it will be named something like sdcc
4216 \series default
4217 -src
4218 \series medium
4219 -yyyymmdd-rrrr.t
4220 \series default
4221 ar.
4222 \series medium
4223 bz2
4224 \series default
4225  
4226 \begin_inset LatexCommand url
4227 target "http://sdcc.sourceforge.net/snap.php"
4228
4229 \end_inset
4230
4231 .
4232 \end_layout
4233
4234 \begin_layout Enumerate
4235
4236 \series medium
4237 Bring up a command line terminal, such as xterm.
4238 \end_layout
4239
4240 \begin_layout Enumerate
4241
4242 \series medium
4243 Unpack the file using a command like:
4244 \series default
4245  
4246 \family sans
4247 \series bold
4248 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4249 \begin_inset Quotes srd
4250 \end_inset
4251
4252
4253 \family default
4254 \series medium
4255 , this will create a sub-directory called sdcc with all of the sources.
4256 \end_layout
4257
4258 \begin_layout Enumerate
4259 Change directory into the main SDCC directory, for example type: 
4260 \family sans
4261 \series bold
4262 "cd sdcc
4263 \series default
4264 ".
4265 \end_layout
4266
4267 \begin_layout Enumerate
4268
4269 \series medium
4270 Type
4271 \series default
4272  
4273 \family sans
4274 \series bold
4275 "./configure
4276 \family default
4277 \series default
4278 ".
4279  This configures the package for compilation on your system.
4280 \end_layout
4281
4282 \begin_layout Enumerate
4283
4284 \series medium
4285 Type
4286 \series default
4287  
4288 \family sans
4289 \series bold
4290 "make
4291 \family default
4292 \series default
4293 "
4294 \series medium
4295 .
4296
4297 \series default
4298  All of the source packages will compile, this can take a while.
4299 \end_layout
4300
4301 \begin_layout Enumerate
4302
4303 \series medium
4304 Type
4305 \series default
4306  
4307 \family sans
4308 \series bold
4309 "make install"
4310 \family default
4311 \series default
4312  as root
4313 \series medium
4314 .
4315
4316 \series default
4317  This copies the binary executables, the include files, the libraries and
4318  the documentation to the install directories.
4319  Proceed with section 
4320 \begin_inset LatexCommand ref
4321 reference "sec:Testing-the-SDCC"
4322
4323 \end_inset
4324
4325 .
4326 \end_layout
4327
4328 \begin_layout Subsection
4329 Building SDCC on Mac OS X
4330 \end_layout
4331
4332 \begin_layout Standard
4333 Follow the instruction for Linux.
4334 \newline
4335
4336 \newline
4337 On Mac OS X 10.2.x it was reported, that the
4338  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4339  Fortunately there's also gcc 2.9.x installed, which works fine.
4340  This compiler can be selected by running 'configure' with:
4341 \end_layout
4342
4343 \begin_layout LyX-Code
4344 ./configure CC=gcc2 CXX=g++2
4345 \end_layout
4346
4347 \begin_layout Standard
4348 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4349  Xcode.
4350  Run 'configure' with:
4351 \end_layout
4352
4353 \begin_layout LyX-Code
4354 ./configure 
4355 \backslash
4356
4357 \end_layout
4358
4359 \begin_layout LyX-Code
4360 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4361  ppc" 
4362 \backslash
4363
4364 \end_layout
4365
4366 \begin_layout LyX-Code
4367 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4368  ppc" 
4369 \backslash
4370
4371 \end_layout
4372
4373 \begin_layout LyX-Code
4374 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4375 \end_layout
4376
4377 \begin_layout Subsection
4378 Cross compiling SDCC on Linux for Windows
4379 \end_layout
4380
4381 \begin_layout Standard
4382 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4383  See section 'Configure Options'.
4384 \end_layout
4385
4386 \begin_layout Subsection
4387 Building SDCC using Cygwin and Mingw32
4388 \end_layout
4389
4390 \begin_layout Standard
4391 For building and installing a Cygwin executable follow the instructions
4392  for Linux.
4393 \newline
4394
4395 \newline
4396 On Cygwin a 
4397 \begin_inset Quotes sld
4398 \end_inset
4399
4400 native
4401 \begin_inset Quotes srd
4402 \end_inset
4403
4404  Win32-binary can be built, which will not need the Cygwin-DLL.
4405  For the necessary 'configure' options see section 'configure options' or
4406  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4407 \newline
4408
4409 \newline
4410 In order to install
4411  Cygwin on Windows download setup.exe from 
4412 \begin_inset LatexCommand url
4413 name "www.cygwin.com"
4414 target "http://www.cygwin.com/"
4415
4416 \end_inset
4417
4418 .
4419  Run it, set the 
4420 \begin_inset Quotes sld
4421 \end_inset
4422
4423 default text file type
4424 \begin_inset Quotes srd
4425 \end_inset
4426
4427  to 
4428 \begin_inset Quotes sld
4429 \end_inset
4430
4431 unix
4432 \begin_inset Quotes srd
4433 \end_inset
4434
4435  and download/install at least the following packages.
4436  Some packages are selected by default, others will be automatically selected
4437  because of dependencies with the manually selected packages.
4438  Never deselect these packages!
4439 \end_layout
4440
4441 \begin_layout Itemize
4442 flex
4443 \end_layout
4444
4445 \begin_layout Itemize
4446 bison
4447 \end_layout
4448
4449 \begin_layout Itemize
4450 gcc ; version 3.x is fine, no need to use the old 2.9x
4451 \end_layout
4452
4453 \begin_layout Itemize
4454 binutils ; selected with gcc
4455 \end_layout
4456
4457 \begin_layout Itemize
4458 make
4459 \end_layout
4460
4461 \begin_layout Itemize
4462 rxvt ; a nice console, which makes life much easier under windoze (see below)
4463 \end_layout
4464
4465 \begin_layout Itemize
4466 man ; not really needed for building SDCC, but you'll miss it sooner or
4467  later
4468 \end_layout
4469
4470 \begin_layout Itemize
4471 less ; not really needed for building SDCC, but you'll miss it sooner or
4472  later
4473 \end_layout
4474
4475 \begin_layout Itemize
4476 svn ; only if you use Subversion access
4477 \end_layout
4478
4479 \begin_layout Standard
4480 If you want to develop something you'll need:
4481 \end_layout
4482
4483 \begin_layout Itemize
4484 python ; for the regression tests
4485 \end_layout
4486
4487 \begin_layout Itemize
4488 gdb ; the gnu debugger, together with the nice GUI 
4489 \begin_inset Quotes sld
4490 \end_inset
4491
4492 insight
4493 \begin_inset Quotes srd
4494 \end_inset
4495
4496
4497 \end_layout
4498
4499 \begin_layout Itemize
4500 openssh ; to access the CF or commit changes
4501 \end_layout
4502
4503 \begin_layout Itemize
4504 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4505  use autoconf-stable!
4506 \end_layout
4507
4508 \begin_layout Standard
4509 rxvt is a nice console with history.
4510  Replace in your cygwin.bat the line
4511 \end_layout
4512
4513 \begin_layout LyX-Code
4514 bash -
4515 \begin_inset ERT
4516 status collapsed
4517
4518 \begin_layout Standard
4519
4520
4521 \backslash
4522 /
4523 \end_layout
4524
4525 \end_inset
4526
4527 -login -i 
4528 \end_layout
4529
4530 \begin_layout Standard
4531 with (one line):
4532 \end_layout
4533
4534 \begin_layout LyX-Code
4535 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4536 \end_layout
4537
4538 \begin_layout LyX-Code
4539      -bg black -fg white -geometry 100x65 -e bash -
4540 \begin_inset ERT
4541 status collapsed
4542
4543 \begin_layout Standard
4544
4545
4546 \backslash
4547 /
4548 \end_layout
4549
4550 \end_inset
4551
4552 -login
4553 \end_layout
4554
4555 \begin_layout Standard
4556 Text selected with the mouse is automatically copied to the clipboard, pasting
4557  works with shift-insert.
4558 \newline
4559
4560 \newline
4561 The other good tip is to make sure you have no //c/-styl
4562 e paths anywhere, use /cygdrive/c/ instead.
4563  Using // invokes a network lookup which is very slow.
4564  If you think 
4565 \begin_inset Quotes sld
4566 \end_inset
4567
4568 cygdrive
4569 \begin_inset Quotes srd
4570 \end_inset
4571
4572  is too long, you can change it with e.g.
4573 \end_layout
4574
4575 \begin_layout LyX-Code
4576 mount -s -u -c /mnt
4577 \end_layout
4578
4579 \begin_layout Standard
4580 SDCC sources use the unix line ending LF.
4581  Life is much easier, if you store the source tree on a drive which is mounted
4582  in binary mode.
4583  And use an editor which can handle LF-only line endings.
4584  Make sure not to commit files with windows line endings.
4585  The tabulator spacing
4586 \begin_inset LatexCommand index
4587 name "tabulator spacing (8 columns)"
4588
4589 \end_inset
4590
4591  used in the project is 8.
4592  Although a tabulator spacing of 8 is a sensible choice for programmers
4593  (it's a power of 2 and allows to display 8/16 bit signed variables without
4594  loosing columns) the plan is to move towards using only spaces in the source.
4595 \end_layout
4596
4597 \begin_layout Subsection
4598 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4599 \end_layout
4600
4601 \begin_layout Standard
4602
4603 \series medium
4604 Download the source package
4605 \series default
4606  either from the SDCC Subversion repository or from the 
4607 \begin_inset LatexCommand url
4608 name "snapshot builds"
4609 target "http://sdcc.sourceforge.net/snap.php"
4610
4611 \end_inset
4612
4613
4614 \series medium
4615 , it will be named something like sdcc
4616 \series default
4617 -src
4618 \series medium
4619 -yyyymmdd-rrrr.tar.bz2.
4620
4621 \series default
4622  SDCC is distributed with all the projects, workspaces, and files you need
4623  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4624  The workspace name is 'sdcc.dsw'.
4625  Please note that as it is now, all the executables are created in a folder
4626  called sdcc
4627 \backslash
4628 bin_vc.
4629  Once built you need to copy the executables from sdcc
4630 \backslash
4631 bin_vc to sdcc
4632 \backslash
4633 bin before running SDCC.
4634  
4635 \newline
4636
4637 \newline
4638 WARNING: Visual studio is very picky with line terminations; it expects
4639  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4640  When using the Subversion repository it's easiest to configure the svn
4641  client to convert automatically for you.
4642  If however you are getting a message such as "This makefile was not generated
4643  by Developer Studio etc.
4644  etc.
4645 \begin_inset Quotes srd
4646 \end_inset
4647
4648  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4649  need to convert the Unix style line endings to DOS style line endings.
4650  To do so you can use the 
4651 \begin_inset Quotes sld
4652 \end_inset
4653
4654 unix2dos
4655 \begin_inset Quotes srd
4656 \end_inset
4657
4658  utility freely available on the internet.
4659  Doug Hawkins reported in the sdcc-user list that this works:
4660 \newline
4661
4662 \newline
4663 C:
4664 \backslash
4665 Programming
4666 \backslash
4667 SDCC> unix2dos sdcc.dsw
4668 \newline
4669 C:
4670 \backslash
4671 Programming
4672 \backslash
4673 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4674 \newline
4675
4676 \newline
4677 In order to build SDCC with MSVC
4678  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4679  One good place to get them is 
4680 \begin_inset LatexCommand url
4681 name "here"
4682 target "http://unxutils.sourceforge.net"
4683
4684 \end_inset
4685
4686
4687 \newline
4688
4689 \newline
4690 Download the file UnxUtils
4691 \begin_inset LatexCommand index
4692 name "UnxUtils"
4693
4694 \end_inset
4695
4696 .zip.
4697  Now you have to install the utilities and setup MSVC so it can locate the
4698  required programs.
4699  Here there are two alternatives (choose one!):
4700 \end_layout
4701
4702 \begin_layout Enumerate
4703 The easy way:
4704 \newline
4705
4706 \newline
4707 a) Extract UnxUtils.zip to your C:
4708 \backslash
4709  hard disk PRESERVING the original paths, otherwise bison won't work.
4710  (If you are using WinZip make certain that 'Use folder names' is selected)
4711 \newline
4712
4713 \newline
4714 b)
4715  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4716  'Show directories for:' select 'Executable files', and in the directories
4717  window add a new path: 'C:
4718 \backslash
4719 user
4720 \backslash
4721 local
4722 \backslash
4723 wbin', click ok.
4724 \newline
4725
4726 \newline
4727 (As a side effect, you get a bunch of Unix utilities that
4728  could be useful, such as diff and patch.)
4729 \end_layout
4730
4731 \begin_layout Enumerate
4732 A more compact way:
4733 \newline
4734
4735 \newline
4736 This one avoids extracting a bunch of files you may not
4737  use, but requires some extra work:
4738 \newline
4739
4740 \newline
4741 a) Create a directory were to put the
4742  tools needed, or use a directory already present.
4743  Say for example 'C:
4744 \backslash
4745 util'.
4746 \newline
4747
4748 \newline
4749 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4750  gawk.exe to such directory WITHOUT preserving the original paths.
4751  (If you are using WinZip make certain that 'Use folder names' is not selected)
4752 \newline
4753
4754 \newline
4755 c
4756 ) Rename bison.exe to '_bison.exe'.
4757 \newline
4758
4759 \newline
4760 d) Create a batch file 'bison.bat' in 'C:
4761 \backslash
4762 util
4763 \backslash
4764 ' and add these lines: 
4765 \newline
4766 \InsetSpace ~
4767 \InsetSpace ~
4768 set BISON_SIMPLE=C:
4769 \backslash
4770 util
4771 \backslash
4772 bison.simple 
4773 \newline
4774 \InsetSpace ~
4775 \InsetSpace ~
4776 set BISON_HAIRY=C:
4777 \backslash
4778 util
4779 \backslash
4780 bison.hairy
4781 \newline
4782 \InsetSpace ~
4783 \InsetSpace ~
4784 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4785 \newline
4786
4787 \newline
4788 Steps 'c' and 'd' are needed
4789  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4790  reside in some weird Unix directory, '/usr/local/share/' I think.
4791  So it is necessary to tell bison where those files are located if they
4792  are not in such directory.
4793  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4794 \newline
4795
4796 \newline
4797 e
4798 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4799  in 'Show directories for:' select 'Executable files', and in the directories
4800  window add a new path: 'c:
4801 \backslash
4802 util', click ok.
4803  Note that you can use any other path instead of 'c:
4804 \backslash
4805 util', even the path where the Visual C++ tools are, probably: 'C:
4806 \backslash
4807 Program Files
4808 \backslash
4809 Microsoft Visual Studio
4810 \backslash
4811 Common
4812 \backslash
4813 Tools'.
4814  So you don't have to execute step 'e' :)
4815 \end_layout
4816
4817 \begin_layout Standard
4818 That is it.
4819  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4820  the executables from sdcc
4821 \backslash
4822 bin_vc to sdcc
4823 \backslash
4824 bin, and you can compile using SDCC.
4825 \end_layout
4826
4827 \begin_layout Subsection
4828 Building SDCC Using Borland
4829 \end_layout
4830
4831 \begin_layout Enumerate
4832 From the sdcc directory, run the command "make -f Makefile.bcc".
4833  This should regenerate all the .exe files in the bin directory except for
4834  SDCDB and ucSim.
4835 \end_layout
4836
4837 \begin_layout Enumerate
4838 If you modify any source files and need to rebuild, be aware that the dependenci
4839 es may not be correctly calculated.
4840  The safest option is to delete all .obj files and run the build again.
4841  From a Cygwin BASH prompt, this can easily be done with the command (be
4842  sure you are in the sdcc directory):
4843 \newline
4844
4845 \newline
4846
4847 \family sans
4848 \series bold
4849 find .
4850  
4851 \backslash
4852 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4853 \backslash
4854 ) -print -exec rm {} 
4855 \backslash
4856 ;
4857 \family default
4858 \series default
4859
4860 \newline
4861
4862 \newline
4863 or on Windows NT/2000/XP from the command prompt with the command:
4864 \newline
4865
4866 \family sans
4867 \series bold
4868
4869 \newline
4870 del /s *.obj *.lib *.rul
4871 \family default
4872 \series default
4873  from the sdcc directory.
4874 \end_layout
4875
4876 \begin_layout Subsection
4877 Windows Install Using a ZIP Package
4878 \end_layout
4879
4880 \begin_layout Enumerate
4881 Download the binary zip package from 
4882 \begin_inset LatexCommand url
4883 target "http://sdcc.sf.net/snap.php"
4884
4885 \end_inset
4886
4887  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4888  This should unpack to a group of sub-directories.
4889  An example directory structure after unpacking the mingw32 package is:
4890  c:
4891 \backslash
4892 sdcc
4893 \backslash
4894 bin for the executables, c:
4895 \backslash
4896 sdcc
4897 \backslash
4898 include and c:
4899 \backslash
4900 sdcc
4901 \backslash
4902 lib for the include and libraries.
4903 \end_layout
4904
4905 \begin_layout Enumerate
4906 Adjust your environment variable PATH to include the location of the bin
4907  directory or start sdcc using the full path.
4908 \end_layout
4909
4910 \begin_layout Subsection
4911 Windows Install Using the Setup Program
4912 \begin_inset LatexCommand label
4913 name "sub:Windows-Install"
4914
4915 \end_inset
4916
4917
4918 \end_layout
4919
4920 \begin_layout Standard
4921 Download the setup program 
4922 \emph on
4923 sdcc-x.y.z-setup.exe
4924 \emph default
4925  for an official release from 
4926 \newline
4927
4928 \begin_inset LatexCommand url
4929 target "http://sf.net/project/showfiles.php?group_id=599"
4930
4931 \end_inset
4932
4933  or a setup program for one of the snapshots 
4934 \emph on
4935 sdcc-yyyymmdd-xxxx-setup.exe
4936 \emph default
4937  from 
4938 \begin_inset LatexCommand url
4939 target "http://sdcc.sf.net/snap.php"
4940
4941 \end_inset
4942
4943  and execute it.
4944  A windows typical installer will guide you through the installation process.
4945 \end_layout
4946
4947 \begin_layout Subsection
4948 VPATH
4949 \begin_inset LatexCommand index
4950 name "VPATH"
4951
4952 \end_inset
4953
4954  feature
4955 \end_layout
4956
4957 \begin_layout Standard
4958 SDCC supports the VPATH feature provided by configure and make.
4959  It allows to separate the source and build trees.
4960  Here's an example:
4961 \end_layout
4962
4963 \begin_layout Standard
4964
4965 \family typewriter
4966 cd ~\InsetSpace ~
4967 \InsetSpace ~
4968 \InsetSpace ~
4969 \InsetSpace ~
4970 \InsetSpace ~
4971 \InsetSpace ~
4972 \InsetSpace ~
4973 \InsetSpace ~
4974 \InsetSpace ~
4975 \InsetSpace ~
4976 \InsetSpace ~
4977 \InsetSpace ~
4978 \InsetSpace ~
4979 \InsetSpace ~
4980 \InsetSpace ~
4981 \InsetSpace ~
4982 \InsetSpace ~
4983 \InsetSpace ~
4984 \InsetSpace ~
4985 \InsetSpace ~
4986 \InsetSpace ~
4987 # cd $HOME
4988 \end_layout
4989
4990 \begin_layout Standard
4991
4992 \family typewriter
4993 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4994 # extract source to directory sdcc
4995 \end_layout
4996
4997 \begin_layout Standard
4998
4999 \family typewriter
5000 mkdir sdcc.build\InsetSpace ~
5001 \InsetSpace ~
5002 \InsetSpace ~
5003 \InsetSpace ~
5004 \InsetSpace ~
5005 \InsetSpace ~
5006 \InsetSpace ~
5007 \InsetSpace ~
5008 \InsetSpace ~
5009 # put output in sdcc.build
5010 \end_layout
5011
5012 \begin_layout Standard
5013
5014 \family typewriter
5015 cd sdcc.build
5016 \end_layout
5017
5018 \begin_layout Standard
5019
5020 \family typewriter
5021 ../sdcc/configure\InsetSpace ~
5022 \InsetSpace ~
5023 \InsetSpace ~
5024 \InsetSpace ~
5025 \InsetSpace ~
5026 \InsetSpace ~
5027 \InsetSpace ~
5028 \InsetSpace ~
5029 # configure is doing all the magic!
5030 \end_layout
5031
5032 \begin_layout Standard
5033
5034 \family typewriter
5035 make
5036 \end_layout
5037
5038 \begin_layout Standard
5039 \noindent
5040 That's it! 
5041 \series bold
5042 configure
5043 \series default
5044  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
5045  It automagically computes the variables srcdir, top_srcdir and top_buildir
5046  for each directory.
5047  After running 
5048 \series bold
5049 make
5050 \series default
5051  the generated files will be in ~/sdcc.build, while the source files stay
5052  in ~/sdcc.
5053 \newline
5054 This is not only usefull for building different binaries, e.g.
5055  when cross compiling.
5056  It also gives you a much better overview in the source tree when all the
5057  generated files are not scattered between the source files.
5058  And the best thing is: if you want to change a file you can leave the original
5059  file untouched in the source directory.
5060  Simply copy it to the build directory, edit it, enter `make clean', `rm
5061  Makefile.dep' and `make'.
5062  
5063 \series bold
5064 make
5065 \series default
5066  will do the rest for you!
5067 \end_layout
5068
5069 \begin_layout Section
5070 Building the Documentation
5071 \end_layout
5072
5073 \begin_layout Standard
5074 Add -
5075 \begin_inset ERT
5076 status collapsed
5077
5078 \begin_layout Standard
5079
5080
5081 \backslash
5082 /
5083 \end_layout
5084
5085 \end_inset
5086
5087 -enable-doc to the configure arguments to build the documentation together
5088  with all the other stuff.
5089  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
5090  dvips and makeindex) to get the job done.
5091  Another possibility is to change to the doc directory and to type 
5092 \family sans
5093 \series bold
5094
5095 \begin_inset Quotes srd
5096 \end_inset
5097
5098 make
5099 \begin_inset Quotes srd
5100 \end_inset
5101
5102
5103 \family default
5104 \series default
5105  there.
5106  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
5107 x).
5108  Using LyX 
5109 \begin_inset LatexCommand url
5110 target "http://www.lyx.org"
5111
5112 \end_inset
5113
5114  as editor is straightforward.
5115  Prebuilt documentation in html and pdf format is available from 
5116 \begin_inset LatexCommand url
5117 target "http://sdcc.sf.net/snap.php"
5118
5119 \end_inset
5120
5121 .
5122 \end_layout
5123
5124 \begin_layout Section
5125 Reading the Documentation
5126 \begin_inset LatexCommand index
5127 name "Documentation"
5128
5129 \end_inset
5130
5131
5132 \end_layout
5133
5134 \begin_layout Standard
5135 Currently reading the document in pdf format is recommended, as for unknown
5136  reason the hyperlinks are working there whereas in the html version they
5137  are not
5138 \begin_inset Foot
5139 status open
5140
5141 \begin_layout Standard
5142 If you should know why please drop us a note
5143 \end_layout
5144
5145 \end_inset
5146
5147 .
5148  
5149 \newline
5150 You'll find the pdf version
5151 \begin_inset LatexCommand index
5152 name "PDF version of this document"
5153
5154 \end_inset
5155
5156  at 
5157 \begin_inset LatexCommand url
5158 target "http://sdcc.sf.net/doc/sdccman.pdf"
5159
5160 \end_inset
5161
5162 .
5163  
5164 \newline
5165 A html version
5166 \begin_inset LatexCommand index
5167 name "HTML version of this document"
5168
5169 \end_inset
5170
5171  should be online at 
5172 \begin_inset LatexCommand url
5173 target "http://sdcc.sf.net/doc/sdccman.html/index.html"
5174
5175 \end_inset
5176
5177 .
5178 \newline
5179 This documentation is in some aspects different from a commercial documentation:
5180  
5181 \end_layout
5182
5183 \begin_layout Itemize
5184 It tries to document SDCC for several processor architectures in one document
5185  (commercially these probably would be separate documents/products).
5186  This document
5187 \begin_inset LatexCommand index
5188 name "Status of documentation"
5189
5190 \end_inset
5191
5192  currently matches SDCC for mcs51 and DS390 best and does give too few informati
5193 on about f.e.
5194  Z80, PIC14, PIC16 and HC08.
5195 \end_layout
5196
5197 \begin_layout Itemize
5198 There are many references pointing away from this documentation.
5199  Don't let this distract you.
5200  If there f.e.
5201  was a reference like 
5202 \begin_inset LatexCommand url
5203 target "http://www.opencores.org"
5204
5205 \end_inset
5206
5207  together with a statement 
5208 \begin_inset Quotes sld
5209 \end_inset
5210
5211 some processors which are targetted by SDCC can be implemented in a 
5212 \emph on
5213 f
5214 \emph default
5215 ield 
5216 \emph on
5217 p
5218 \emph default
5219 rogrammable 
5220 \emph on
5221 g
5222 \emph default
5223 ate 
5224 \emph on
5225 a
5226 \emph default
5227 rray
5228 \begin_inset LatexCommand index
5229 name "FPGA (field programmable gate array)"
5230
5231 \end_inset
5232
5233
5234 \begin_inset Quotes srd
5235 \end_inset
5236
5237  or 
5238 \begin_inset LatexCommand url
5239 target "http://sf.net/projects/fpgac"
5240
5241 \end_inset
5242
5243
5244 \begin_inset LatexCommand index
5245 name "FpgaC ((subset of) C to FPGA compiler)"
5246
5247 \end_inset
5248
5249  
5250 \begin_inset Quotes sld
5251 \end_inset
5252
5253 have you ever heard of an open source compiler that compiles a subset of
5254  C for an FPGA?
5255 \begin_inset Quotes srd
5256 \end_inset
5257
5258  we expect you to have a quick look there and come back.
5259  If you read this you are on the right track.
5260 \end_layout
5261
5262 \begin_layout Itemize
5263 Some sections attribute more space to problems, restrictions and warnings
5264  than to the solution.
5265 \end_layout
5266
5267 \begin_layout Itemize
5268 The installation section and the section about the debugger is intimidating.
5269 \end_layout
5270
5271 \begin_layout Itemize
5272 There are still lots of typos and there are more different writing styles
5273  than pictures.
5274 \end_layout
5275
5276 \begin_layout Section
5277 Testing the SDCC Compiler
5278 \begin_inset LatexCommand label
5279 name "sec:Testing-the-SDCC"
5280
5281 \end_inset
5282
5283
5284 \end_layout
5285
5286 \begin_layout Standard
5287 The first thing you should do after installing your SDCC compiler is to
5288  see if it runs.
5289  Type 
5290 \family sans
5291 \series bold
5292 "sdcc -
5293 \begin_inset ERT
5294 status collapsed
5295
5296 \begin_layout Standard
5297
5298
5299 \backslash
5300 /
5301 \end_layout
5302
5303 \end_inset
5304
5305 -version"
5306 \begin_inset LatexCommand index
5307 name "version"
5308
5309 \end_inset
5310
5311
5312 \family default
5313 \series default
5314  at the prompt, and the program should run and output its version like:
5315  
5316 \newline
5317
5318 \family typewriter
5319 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5320  (UNIX)
5321 \end_layout
5322
5323 \begin_layout Standard
5324 If it doesn't run, or gives a message about not finding sdcc program, then
5325  you need to check over your installation.
5326  Make sure that the sdcc bin directory is in your executable search path
5327  defined by the PATH environment setting (
5328 \series medium
5329 see
5330 \series default
5331  section 
5332 \begin_inset LatexCommand ref
5333 reference "sub:Install-Trouble-shooting"
5334
5335 \end_inset
5336
5337 \InsetSpace ~
5338
5339 \series medium
5340 Install trouble-shooting for suggestions
5341 \series default
5342 ).
5343  Make sure that the sdcc program is in the bin folder, if not perhaps something
5344  did not install correctly.
5345 \newline
5346
5347 \newline
5348
5349 \series medium
5350 SDCC
5351 \series default
5352  is commonly installed as described in section 
5353 \begin_inset Quotes sld
5354 \end_inset
5355
5356 Install and search paths
5357 \begin_inset Quotes srd
5358 \end_inset
5359
5360 .
5361 \newline
5362
5363 \newline
5364
5365 \series medium
5366 Make sure the compiler works on a very simple example.
5367  Type in the following test.c program using your favorite
5368 \series default
5369  ASCII 
5370 \series medium
5371 editor:
5372 \end_layout
5373
5374 \begin_layout Verse
5375
5376 \family typewriter
5377 char test;
5378 \newline
5379
5380 \newline
5381 void main(void) {
5382 \newline
5383 \InsetSpace ~
5384 \InsetSpace ~
5385 \InsetSpace ~
5386 \InsetSpace ~
5387 test=0;
5388 \newline
5389 }
5390 \end_layout
5391
5392 \begin_layout Standard
5393
5394 \series medium
5395 Compile this using the following command:
5396 \series default
5397  
5398 \family sans
5399 \series bold
5400 "sdcc -c test.c".
5401
5402 \family default
5403 \series default
5404  
5405 \series medium
5406 If all goes well, the compiler will generate a test.asm and test.rel file.
5407  Congratulations, you've just compiled your first program with SDCC.
5408  We used the -c option to tell SDCC not to link the generated code, just
5409  to keep things simple for this step.
5410 \series default
5411
5412 \newline
5413
5414 \newline
5415
5416 \series medium
5417 The next step is to try it with the linker.
5418  Type in
5419 \series default
5420  
5421 \family sans
5422 \series bold
5423 "sdcc test.c
5424 \family default
5425 \series default
5426 "
5427 \series medium
5428 .
5429  If all goes well the compiler will link with the libraries and produce
5430  a test.ihx output file.
5431  If this step fails
5432 \series default
5433  
5434 \series medium
5435 (no test.ihx, and the linker generates warnings), then the problem is most
5436  likely that
5437 \series default
5438  SDCC 
5439 \series medium
5440 cannot find the
5441 \series default
5442  /
5443 \series medium
5444 usr/local/share/sdcc/lib directory
5445 \series default
5446  
5447 \series medium
5448 (see
5449 \series default
5450  section 
5451 \begin_inset LatexCommand ref
5452 reference "sub:Install-Trouble-shooting"
5453
5454 \end_inset
5455
5456 \InsetSpace ~
5457
5458 \series medium
5459 Install trouble-shooting for suggestions).
5460 \series default
5461
5462 \newline
5463
5464 \newline
5465
5466 \series medium
5467 The final test is to ensure
5468 \series default
5469  SDCC 
5470 \series medium
5471 can use the
5472 \series default
5473  standard 
5474 \series medium
5475 header files and libraries.
5476  Edit test.c and change it to the following:
5477 \end_layout
5478
5479 \begin_layout Verse
5480
5481 \family typewriter
5482 #include <string.h>
5483 \newline
5484
5485 \newline
5486 char str1[10];
5487 \newline
5488
5489 \newline
5490 void main(void) {
5491 \newline
5492 \InsetSpace ~
5493 \InsetSpace ~
5494 strcpy(str1, "testing");
5495 \newline
5496 }
5497 \end_layout
5498
5499 \begin_layout Standard
5500
5501 \series medium
5502 Compile this by typing
5503 \series default
5504  
5505 \family sans
5506 \series bold
5507 "sdcc test.c"
5508 \family default
5509 \series medium
5510 .
5511  This should generate a test.ihx output file, and it should give no warnings
5512  such as not finding the string.h file.
5513  If it cannot find the string.h file, then the problem is that
5514 \series default
5515  SDCC 
5516 \series medium
5517 cannot find the /usr/local/share/sdcc/include directory
5518 \series default
5519  
5520 \series medium
5521 (see the
5522 \series default
5523  section 
5524 \begin_inset LatexCommand ref
5525 reference "sub:Install-Trouble-shooting"
5526
5527 \end_inset
5528
5529 \InsetSpace ~
5530
5531 \series medium
5532 Install trouble-shooting section for suggestions).
5533
5534 \series default
5535  Use option 
5536 \series bold
5537 -
5538 \begin_inset ERT
5539 status collapsed
5540
5541 \begin_layout Standard
5542
5543
5544 \backslash
5545 /
5546 \end_layout
5547
5548 \end_inset
5549
5550 -print-search-dirs
5551 \series default
5552
5553 \begin_inset LatexCommand index
5554 name "-\\/-print-search-dirs"
5555
5556 \end_inset
5557
5558  to find exactly where SDCC is looking for the include and lib files.
5559 \end_layout
5560
5561 \begin_layout Section
5562 Install Trouble-shooting
5563 \begin_inset LatexCommand label
5564 name "sub:Install-Trouble-shooting"
5565
5566 \end_inset
5567
5568
5569 \begin_inset LatexCommand index
5570 name "Install trouble-shooting"
5571
5572 \end_inset
5573
5574
5575 \end_layout
5576
5577 \begin_layout Subsection
5578 If SDCC does not build correctly
5579 \end_layout
5580
5581 \begin_layout Standard
5582 A thing to try is starting from scratch by unpacking the .tgz source package
5583  again in an empty directory.
5584  Configure it like:
5585 \newline
5586
5587 \newline
5588
5589 \family sans
5590 \series bold
5591 ./configure 2>&1 | tee configure.log
5592 \family default
5593 \series default
5594
5595 \newline
5596
5597 \newline
5598 and build it like:
5599 \newline
5600
5601 \newline
5602
5603 \family sans
5604 \series bold
5605 make 2>&1 | tee make.log
5606 \family default
5607 \series default
5608
5609 \newline
5610
5611 \newline
5612 If anything goes wrong, you can review the log files to locate the problem.
5613  Or a relevant part of this can be attached to an email that could be helpful
5614  when requesting help from the mailing list.
5615 \end_layout
5616
5617 \begin_layout Subsection
5618 What the 
5619 \begin_inset Quotes sld
5620 \end_inset
5621
5622 ./configure
5623 \begin_inset Quotes srd
5624 \end_inset
5625
5626  does
5627 \end_layout
5628
5629 \begin_layout Standard
5630 The 
5631 \begin_inset Quotes sld
5632 \end_inset
5633
5634 ./configure
5635 \begin_inset Quotes srd
5636 \end_inset
5637
5638  command is a script that analyzes your system and performs some configuration
5639  to ensure the source package compiles on your system.
5640  It will take a few minutes to run, and will compile a few tests to determine
5641  what compiler features are installed.
5642 \end_layout
5643
5644 \begin_layout Subsection
5645 What the 
5646 \begin_inset Quotes sld
5647 \end_inset
5648
5649 make
5650 \begin_inset Quotes srd
5651 \end_inset
5652
5653  does
5654 \end_layout
5655
5656 \begin_layout Standard
5657 This runs the GNU make tool, which automatically compiles all the source
5658  packages into the final installed binary executables.
5659 \end_layout
5660
5661 \begin_layout Subsection
5662 What the 
5663 \begin_inset Quotes sld
5664 \end_inset
5665
5666 make install
5667 \begin_inset Quotes erd
5668 \end_inset
5669
5670  command does.
5671 \end_layout
5672
5673 \begin_layout Standard
5674 This will install the compiler, other executables libraries and include
5675  files into the appropriate directories.
5676  See sections 
5677 \begin_inset LatexCommand ref
5678 reference "sub:Install-paths"
5679
5680 \end_inset
5681
5682 ,\InsetSpace ~
5683
5684 \begin_inset LatexCommand ref
5685 reference "sub:Search-Paths"
5686
5687 \end_inset
5688
5689 \InsetSpace ~
5690 about install and search paths.
5691 \newline
5692 On most systems you will need super-user privilege
5693 s to do this.
5694 \end_layout
5695
5696 \begin_layout Section
5697 Components of SDCC
5698 \end_layout
5699
5700 \begin_layout Standard
5701 SDCC is not just a compiler, but a collection of tools by various developers.
5702  These include linkers, assemblers, simulators and other components.
5703  Here is a summary of some of the components.
5704  Note that the included simulator and assembler have separate documentation
5705  which you can find in the source package in their respective directories.
5706  As SDCC grows to include support for other processors, other packages from
5707  various developers are included and may have their own sets of documentation.
5708 \newline
5709
5710 \newline
5711 You
5712  might want to look at the files which are installed in <installdir>.
5713  At the time of this writing, we find the following programs for gcc-builds:
5714 \newline
5715
5716  
5717 \newline
5718 In <installdir>/bin:
5719 \end_layout
5720
5721 \begin_layout Itemize
5722 sdcc - The compiler.
5723 \end_layout
5724
5725 \begin_layout Itemize
5726 sdcpp - The C preprocessor.
5727 \end_layout
5728
5729 \begin_layout Itemize
5730 asx8051 - The assembler for 8051 type processors.
5731 \end_layout
5732
5733 \begin_layout Itemize
5734 as-z80
5735 \series bold
5736 ,
5737 \series default
5738  as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5739 \end_layout
5740
5741 \begin_layout Itemize
5742 aslink -The linker for 8051 type processors.
5743 \end_layout
5744
5745 \begin_layout Itemize
5746 link-z80
5747 \series bold
5748 ,
5749 \series default
5750  link-gbz80 - The Z80 and GameBoy Z80 linkers.
5751 \end_layout
5752
5753 \begin_layout Itemize
5754 s51 - The ucSim 8051 simulator.
5755 \end_layout
5756
5757 \begin_layout Itemize
5758 sdcdb - The source debugger.
5759 \end_layout
5760
5761 \begin_layout Itemize
5762 packihx - A tool to pack (compress) Intel hex files.
5763 \end_layout
5764
5765 \begin_layout Standard
5766 In <installdir>/share/sdcc/include
5767 \end_layout
5768
5769 \begin_layout Itemize
5770 the include files
5771 \end_layout
5772
5773 \begin_layout Standard
5774 In <installdir>/share/sdcc/lib
5775 \end_layout
5776
5777 \begin_layout Itemize
5778 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5779  relocatables.
5780 \end_layout
5781
5782 \begin_layout Standard
5783 In <installdir>/share/sdcc/doc
5784 \end_layout
5785
5786 \begin_layout Itemize
5787 the documentation
5788 \end_layout
5789
5790 \begin_layout Standard
5791 As development for other processors proceeds, this list will expand to include
5792  executables to support processors like AVR, PIC, etc.
5793 \end_layout
5794
5795 \begin_layout Subsection
5796 sdcc - The Compiler
5797 \end_layout
5798
5799 \begin_layout Standard
5800 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5801  the assembler and linkage editor.
5802 \end_layout
5803
5804 \begin_layout Subsection
5805 sdcpp - The C-Preprocessor
5806 \end_layout
5807
5808 \begin_layout Standard
5809 The preprocessor
5810 \begin_inset LatexCommand index
5811 name "sdcpp (preprocessor)"
5812
5813 \end_inset
5814
5815  is a modified version of the GNU cpp
5816 \begin_inset LatexCommand index
5817 name "cpp|see{sdcpp}"
5818
5819 \end_inset
5820
5821  preprocessor 
5822 \begin_inset LatexCommand url
5823 target "http://gcc.gnu.org/"
5824
5825 \end_inset
5826
5827 .
5828  The C preprocessor is used to pull in #include sources, process #ifdef
5829  statements, #defines and so on.
5830 \end_layout
5831
5832 \begin_layout Subsection
5833 as
5834 \emph on
5835 xxxx
5836 \emph default
5837 , aslink, link-
5838 \emph on
5839 xxx
5840 \emph default
5841  - The Assemblers and Linkage Editors
5842 \end_layout
5843
5844 \begin_layout Standard
5845 This is retargettable assembler & linkage editor, it was developed by Alan
5846  Baldwin.
5847  John Hartman created the version for 8051, and I (Sandeep) have made some
5848  enhancements and bug fixes for it to work properly with SDCC.
5849 \end_layout
5850
5851 \begin_layout Subsection
5852 s51 - The Simulator
5853 \end_layout
5854
5855 \begin_layout Standard
5856 S51
5857 \begin_inset LatexCommand index
5858 name "s51"
5859
5860 \end_inset
5861
5862  is a free open source simulator developed by Daniel Drotos.
5863  The simulator is built as part of the build process.
5864  For more information visit Daniel's web site at: 
5865 \begin_inset LatexCommand url
5866 target "http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51"
5867
5868 \end_inset
5869
5870 .
5871  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5872  XA51 family.
5873 \end_layout
5874
5875 \begin_layout Subsection
5876 sdcdb - Source Level Debugger
5877 \end_layout
5878
5879 \begin_layout Standard
5880 SDCDB
5881 \begin_inset LatexCommand index
5882 name "SDCDB (debugger)"
5883
5884 \end_inset
5885
5886  is the companion source level debugger.
5887  More about SDCDB in section 
5888 \begin_inset LatexCommand ref
5889 reference "cha:Debugging-with-SDCDB"
5890
5891 \end_inset
5892
5893 .
5894  The current version of the debugger uses Daniel's Simulator S51
5895 \begin_inset LatexCommand index
5896 name "s51"
5897
5898 \end_inset
5899
5900 , but can be easily changed to use other simulators.
5901 \end_layout
5902
5903 \begin_layout Chapter
5904 Using SDCC
5905 \end_layout
5906
5907 \begin_layout Section
5908 Compiling
5909 \end_layout
5910
5911 \begin_layout Subsection
5912 Single Source File Projects
5913 \end_layout
5914
5915 \begin_layout Standard
5916 For single source file 8051 projects the process is very simple.
5917  Compile your programs with the following command 
5918 \family sans
5919 \series bold
5920 "sdcc sourcefile.c".
5921
5922 \family default
5923 \series default
5924  This will compile, assemble and link your source file.
5925  Output files are as follows:
5926 \end_layout
5927
5928 \begin_layout Itemize
5929 sourcefile.asm
5930 \begin_inset LatexCommand index
5931 name "<file>.asm"
5932
5933 \end_inset
5934
5935  - Assembler source
5936 \begin_inset LatexCommand index
5937 name "Assembler source"
5938
5939 \end_inset
5940
5941  file created by the compiler
5942 \end_layout
5943
5944 \begin_layout Itemize
5945 sourcefile.lst
5946 \begin_inset LatexCommand index
5947 name "<file>.lst"
5948
5949 \end_inset
5950
5951  - Assembler listing
5952 \begin_inset LatexCommand index
5953 name "Assembler listing"
5954
5955 \end_inset
5956
5957  file created by the Assembler
5958 \end_layout
5959
5960 \begin_layout Itemize
5961 sourcefile.rst
5962 \begin_inset LatexCommand index
5963 name "<file>.rst"
5964
5965 \end_inset
5966
5967  - Assembler listing
5968 \begin_inset LatexCommand index
5969 name "Assembler listing"
5970
5971 \end_inset
5972
5973  file updated with linkedit information, created by linkage editor
5974 \end_layout
5975
5976 \begin_layout Itemize
5977 sourcefile.sym
5978 \begin_inset LatexCommand index
5979 name "<file>.sym"
5980
5981 \end_inset
5982
5983  - symbol listing
5984 \begin_inset LatexCommand index
5985 name "Symbol listing"
5986
5987 \end_inset
5988
5989  for the sourcefile, created by the assembler
5990 \end_layout
5991
5992 \begin_layout Itemize
5993 sourcefile.rel
5994 \begin_inset LatexCommand index
5995 name "<file>.rel"
5996
5997 \end_inset
5998
5999  or sourcefile.o
6000 \begin_inset LatexCommand index
6001 name "<file>.o"
6002
6003 \end_inset
6004
6005  - Object file
6006 \begin_inset LatexCommand index
6007 name "Object file"
6008
6009 \end_inset
6010
6011  created by the assembler, input to Linkage editor
6012 \end_layout
6013
6014 \begin_layout Itemize
6015 sourcefile.map
6016 \begin_inset LatexCommand index
6017 name "<file>.map"
6018
6019 \end_inset
6020
6021  - The memory map
6022 \begin_inset LatexCommand index
6023 name "Memory map"
6024
6025 \end_inset
6026
6027  for the load module, created by the Linker
6028 \end_layout
6029
6030 \begin_layout Itemize
6031 sourcefile.mem
6032 \begin_inset LatexCommand index
6033 name "<file>.mem"
6034
6035 \end_inset
6036
6037  - A file with a summary of the memory usage
6038 \end_layout
6039
6040 \begin_layout Itemize
6041 sourcefile.ihx
6042 \begin_inset LatexCommand index
6043 name "<file>.ihx"
6044
6045 \end_inset
6046
6047  - The load module in Intel hex format
6048 \begin_inset LatexCommand index
6049 name "Intel hex format"
6050
6051 \end_inset
6052
6053  (you can select the Motorola S19 format
6054 \begin_inset LatexCommand index
6055 name "Motorola S19 format"
6056
6057 \end_inset
6058
6059  with -
6060 \begin_inset ERT
6061 status collapsed
6062
6063 \begin_layout Standard
6064
6065
6066 \backslash
6067 /
6068 \end_layout
6069
6070 \end_inset
6071
6072 -out-fmt-s19
6073 \begin_inset LatexCommand index
6074 name "-\\/-out-fmt-s19"
6075
6076 \end_inset
6077
6078 .
6079  If you need another format you might want to use 
6080 \family sans
6081 \shape italic
6082 objdump
6083 \family default
6084 \shape default
6085
6086 \begin_inset LatexCommand index
6087 name "objdump (tool)"
6088
6089 \end_inset
6090
6091  or 
6092 \family sans
6093 \shape italic
6094 srecord
6095 \family default
6096 \shape default
6097
6098 \begin_inset LatexCommand index
6099 name "srecord (bin, hex, ... tool)"
6100
6101 \end_inset
6102
6103
6104 \begin_inset Note Note
6105 status collapsed
6106
6107 \begin_layout Standard
6108 hyperlinks needed
6109 \end_layout
6110
6111 \end_inset
6112
6113  - see also section 
6114 \begin_inset LatexCommand vref
6115 reference "sub:Postprocessing-the-Intel"
6116
6117 \end_inset
6118
6119 ).
6120  Both formats are documented in the documentation of srecord
6121 \begin_inset LatexCommand index
6122 name "srecord (bin, hex, ... tool)"
6123
6124 \end_inset
6125
6126
6127 \end_layout
6128
6129 \begin_layout Itemize
6130 sourcefile.adb
6131 \begin_inset LatexCommand index
6132 name "<file>.adb"
6133
6134 \end_inset
6135
6136  - An intermediate file containing debug information needed to create the
6137  .cdb file (with -
6138 \begin_inset ERT
6139 status collapsed
6140
6141 \begin_layout Standard
6142
6143
6144 \backslash
6145 /
6146 \end_layout
6147
6148 \end_inset
6149
6150 -debug
6151 \begin_inset LatexCommand index
6152 name "-\\/-debug"
6153
6154 \end_inset
6155
6156
6157 \end_layout
6158
6159 \begin_layout Itemize
6160 sourcefile.cdb
6161 \begin_inset LatexCommand index
6162 name "<file>.cdb"
6163
6164 \end_inset
6165
6166  - An optional file (with -
6167 \begin_inset ERT
6168 status collapsed
6169
6170 \begin_layout Standard
6171
6172
6173 \backslash
6174 /
6175 \end_layout
6176
6177 \end_inset
6178
6179 -debug) containing debug information.
6180  The format is documented in cdbfileformat.pdf
6181 \end_layout
6182
6183 \begin_layout Itemize
6184 sourcefile.
6185  - (no extension)
6186 \begin_inset LatexCommand index
6187 name "<file> (no extension)"
6188
6189 \end_inset
6190
6191  An optional AOMF or AOMF51
6192 \begin_inset LatexCommand index
6193 name "AOMF, AOMF51"
6194
6195 \end_inset
6196
6197  
6198 \begin_inset LatexCommand label
6199 name "OMF file"
6200
6201 \end_inset
6202
6203 file containing debug information (generated with option -
6204 \begin_inset ERT
6205 status collapsed
6206
6207 \begin_layout Standard
6208
6209
6210 \backslash
6211 /
6212 \end_layout
6213
6214 \end_inset
6215
6216 -debug).
6217  The (Intel) 
6218 \emph on
6219 a
6220 \emph default
6221 bsolute 
6222 \emph on
6223 o
6224 \emph default
6225 bject 
6226 \emph on
6227 m
6228 \emph default
6229 odule 
6230 \emph on
6231 f
6232 \emph default
6233 ormat is a subformat of the OMF51 format and is commonly used by third party
6234  tools (debuggers
6235 \begin_inset LatexCommand index
6236 name "Debugger"
6237
6238 \end_inset
6239
6240 , simulators, emulators).
6241 \end_layout
6242
6243 \begin_layout Itemize
6244 sourcefile.dump*
6245 \begin_inset LatexCommand index
6246 name "<file>.dump*"
6247
6248 \end_inset
6249
6250  - Dump file to debug the compiler it self (generated with option -
6251 \begin_inset ERT
6252 status collapsed
6253
6254 \begin_layout Standard
6255
6256
6257 \backslash
6258 /
6259 \end_layout
6260
6261 \end_inset
6262
6263 -dumpall) (see section 
6264 \begin_inset LatexCommand ref
6265 reference "sub:Intermediate-Dump-Options"
6266
6267 \end_inset
6268
6269 \InsetSpace ~
6270  and section 
6271 \begin_inset LatexCommand ref
6272 reference "sub:The-anatomy-of"
6273
6274 \end_inset
6275
6276 \InsetSpace ~
6277
6278 \begin_inset Quotes sld
6279 \end_inset
6280
6281 Anatomy of the compiler
6282 \begin_inset Quotes srd
6283 \end_inset
6284
6285 ).
6286 \end_layout
6287
6288 \begin_layout Subsection
6289 Postprocessing the Intel Hex
6290 \begin_inset LatexCommand index
6291 name "Intel hex format"
6292
6293 \end_inset
6294
6295  file
6296 \begin_inset LatexCommand label
6297 name "sub:Postprocessing-the-Intel"
6298
6299 \end_inset
6300
6301
6302 \end_layout
6303
6304 \begin_layout Standard
6305 In most cases this won't be needed but the Intel Hex file
6306 \begin_inset LatexCommand index
6307 name "<file>.ihx"
6308
6309 \end_inset
6310
6311  which is generated by SDCC might include lines of varying length and the
6312  addresses within the file are not guaranteed to be strictly ascending.
6313  If your toolchain or a bootloader does not like this you can use the tool
6314  
6315 \family typewriter
6316 packihx
6317 \family default
6318
6319 \begin_inset LatexCommand index
6320 name "packihx (tool)"
6321
6322 \end_inset
6323
6324  which is part of the SDCC distribution: 
6325 \newline
6326
6327 \newline
6328  
6329 \family sans
6330 \series bold
6331 packihx sourcefile.ihx >sourcefile.hex
6332 \family default
6333 \series default
6334
6335 \newline
6336
6337 \newline
6338 The separately available 
6339 \emph on
6340 srecord
6341 \emph default
6342
6343 \begin_inset LatexCommand index
6344 name "srecord (bin, hex, ... tool)"
6345
6346 \end_inset
6347
6348  package additionally allows to set undefined locations to a predefined
6349  value, to insert checksums
6350 \begin_inset LatexCommand index
6351 name "checksum"
6352
6353 \end_inset
6354
6355  of various flavours (crc, add, xor) and to perform other manipulations
6356  (convert, split, crop, offset, ...).
6357  
6358 \newline
6359
6360 \newline
6361
6362 \family sans
6363 \series bold
6364 srec_cat\InsetSpace ~
6365 \InsetSpace ~
6366 sourcefile.ihx -intel\InsetSpace ~
6367 \InsetSpace ~
6368 -o sourcefile.hex -intel
6369 \newline
6370
6371 \newline
6372
6373 \family default
6374 \series default
6375 An example for a more complex command line
6376 \begin_inset Foot
6377 status open
6378
6379 \begin_layout Standard
6380 the command backfills
6381 \begin_inset LatexCommand index
6382 name "backfill unused memory"
6383
6384 \end_inset
6385
6386  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6387  block is zero.
6388  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6389  will be interpreted as an 
6390 \family typewriter
6391 lcall
6392 \family default
6393  to address 
6394 \family typewriter
6395 0x1212
6396 \family default
6397  (where an emergency routine could sit).
6398 \end_layout
6399
6400 \end_inset
6401
6402  could look like:
6403 \newline
6404
6405 \newline
6406
6407 \family sans
6408 \series bold
6409 \size footnotesize
6410 srec_cat\InsetSpace ~
6411 sourcefile.ihx -intel\InsetSpace ~
6412 \InsetSpace ~
6413 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6414 -little-endian-checksum-nega
6415 tive 0xfffe 0x02 0x02\InsetSpace ~
6416 \InsetSpace ~
6417 -o sourcefile.hex -intel
6418 \size default
6419
6420 \newline
6421
6422 \newline
6423
6424 \family default
6425 \series default
6426 The srecord package is available at 
6427 \begin_inset LatexCommand url
6428 target "http://sf.net/projects/srecord"
6429
6430 \end_inset
6431
6432  .
6433 \end_layout
6434
6435 \begin_layout Subsection
6436 Projects with Multiple Source Files
6437 \end_layout
6438
6439 \begin_layout Standard
6440 SDCC can compile only ONE file at a time.
6441  Let us for example assume that you have a project containing the following
6442  files:
6443 \newline
6444
6445 \newline
6446 foo1.c (contains some functions)
6447 \newline
6448 foo2.c (contains some more functions)
6449 \newline
6450 foomai
6451 n.c (contains more functions and the function main)
6452 \newline
6453
6454 \size footnotesize
6455
6456 \newline
6457
6458 \size default
6459 The first two files will need to be compiled separately with the commands:
6460 \size footnotesize
6461  
6462 \size default
6463
6464 \newline
6465
6466 \newline
6467
6468 \family sans
6469 \series bold
6470 sdcc\InsetSpace ~
6471 -c\InsetSpace ~
6472 foo1.c
6473 \family default
6474 \series default
6475 \size footnotesize
6476
6477 \newline
6478
6479 \family sans
6480 \series bold
6481 \size default
6482 sdcc\InsetSpace ~
6483 -c\InsetSpace ~
6484 foo2.c
6485 \family default
6486 \series default
6487
6488 \newline
6489
6490 \newline
6491 Then compile the source file containing the 
6492 \emph on
6493 main()
6494 \emph default
6495  function and link
6496 \begin_inset LatexCommand index
6497 name "Linker"
6498
6499 \end_inset
6500
6501  the files together with the following command: 
6502 \newline
6503
6504 \newline
6505
6506 \family sans
6507 \series bold
6508 sdcc\InsetSpace ~
6509 foomain.c\InsetSpace ~
6510 foo1.rel\InsetSpace ~
6511 foo2.rel
6512 \family default
6513 \series default
6514
6515 \begin_inset LatexCommand index
6516 name "<file>.rel"
6517
6518 \end_inset
6519
6520
6521 \newline
6522
6523 \newline
6524 Alternatively, 
6525 \emph on
6526 foomain.c
6527 \emph default
6528  can be separately compiled as well: 
6529 \family sans
6530 \series bold
6531
6532 \newline
6533
6534 \newline
6535 sdcc\InsetSpace ~
6536 -c\InsetSpace ~
6537 foomain.c
6538 \newline
6539 sdcc foomain.rel foo1.rel foo2.rel
6540 \newline
6541
6542 \newline
6543
6544 \family default
6545 \series default
6546 The file containing the 
6547 \emph on
6548 main()
6549 \emph default
6550  function 
6551 \noun on
6552 must
6553 \noun default
6554  be the 
6555 \noun on
6556 first
6557 \noun default
6558  file specified in the command line, since the linkage editor processes
6559  file in the order they are presented to it.
6560  The linker is invoked from SDCC using a script file with extension .lnk
6561 \begin_inset LatexCommand index
6562 name "<file>.lnk"
6563
6564 \end_inset
6565
6566 .
6567  You can view this file to troubleshoot linking problems such as those arising
6568  from missing libraries.
6569 \end_layout
6570
6571 \begin_layout Subsection
6572 Projects with Additional Libraries
6573 \begin_inset LatexCommand index
6574 name "Libraries"
6575
6576 \end_inset
6577
6578
6579 \end_layout
6580
6581 \begin_layout Standard
6582 Some reusable routines may be compiled into a library, see the documentation
6583  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6584  for how to create a 
6585 \emph on
6586 .lib
6587 \begin_inset LatexCommand index
6588 name "<file>.lib"
6589
6590 \end_inset
6591
6592
6593 \emph default
6594  library file.
6595  Libraries created in this manner can be included in the command line.
6596  Make sure you include the -L <library-path> option to tell the linker where
6597  to look for these files if they are not in the current directory.
6598  Here is an example, assuming you have the source file 
6599 \emph on
6600 foomain.c
6601 \emph default
6602  and a library 
6603 \emph on
6604 foolib.lib
6605 \emph default
6606  in the directory 
6607 \emph on
6608 mylib
6609 \emph default
6610  (if that is not the same as your current project):
6611 \newline
6612
6613 \newline
6614
6615 \family sans
6616 \series bold
6617 sdcc foomain.c foolib.lib -L mylib
6618 \newline
6619
6620 \newline
6621
6622 \family default
6623 \series default
6624 Note here that 
6625 \emph on
6626 mylib
6627 \emph default
6628  must be an absolute path name.
6629 \newline
6630
6631 \newline
6632 The most efficient way to use libraries is
6633  to keep separate modules in separate source files.
6634  The lib file now should name all the modules.rel
6635 \begin_inset LatexCommand index
6636 name "<file>.rel"
6637
6638 \end_inset
6639
6640  files.
6641  For an example see the standard library file 
6642 \emph on
6643 libsdcc.lib
6644 \emph default
6645  in the directory <installdir>/share/lib/small.
6646 \end_layout
6647
6648 \begin_layout Subsection
6649 Using sdcclib to Create and Manage Libraries
6650 \begin_inset LatexCommand index
6651 name "sdcclib"
6652
6653 \end_inset
6654
6655
6656 \end_layout
6657
6658 \begin_layout Standard
6659 Alternatively, instead of having a .rel file for each entry on the library
6660  file as described in the preceding section, sdcclib can be used to embed
6661  all the modules belonging to such library in the library file itself.
6662  This results in a larger library file, but it greatly reduces the number
6663  of disk files accessed by the linker.
6664   Additionally, the packed library file contains an index of all include
6665  modules and symbols that significantly speeds up the linking process.
6666  To display a list of options supported by sdcclib type:
6667 \newline
6668
6669 \end_layout
6670
6671 \begin_layout Standard
6672
6673 \family sans
6674 \series bold
6675 sdcclib -?
6676 \begin_inset LatexCommand index
6677 name "sdcclib"
6678
6679 \end_inset
6680
6681
6682 \newline
6683
6684 \newline
6685
6686 \family default
6687 \series default
6688 To create a new library file, start by compiling all the required modules.
6689  For example:
6690 \newline
6691
6692 \end_layout
6693
6694 \begin_layout Standard
6695
6696 \family sans
6697 \series bold
6698 sdcc -c _divsint.c
6699 \end_layout
6700
6701 \begin_layout Standard
6702
6703 \family sans
6704 \series bold
6705 sdcc -c _divuint.c
6706 \end_layout
6707
6708 \begin_layout Standard
6709
6710 \family sans
6711 \series bold
6712 sdcc -c _modsint.c
6713 \end_layout
6714
6715 \begin_layout Standard
6716
6717 \family sans
6718 \series bold
6719 sdcc -c _moduint.c
6720 \end_layout
6721
6722 \begin_layout Standard
6723
6724 \family sans
6725 \series bold
6726 sdcc -c _mulint.c
6727 \newline
6728
6729 \end_layout
6730
6731 \begin_layout Standard
6732 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6733  and _mulint.rel.
6734  The next step is to add the .rel files to the library file:
6735 \newline
6736
6737 \end_layout
6738
6739 \begin_layout Standard
6740
6741 \family sans
6742 \series bold
6743 sdcclib libint.lib _divsint.rel
6744 \family default
6745
6746 \begin_inset LatexCommand index
6747 name "sdcclib"
6748
6749 \end_inset
6750
6751
6752 \end_layout
6753
6754 \begin_layout Standard
6755
6756 \family sans
6757 \series bold
6758 sdcclib libint.lib _divuint.rel
6759 \end_layout
6760
6761 \begin_layout Standard
6762
6763 \family sans
6764 \series bold
6765 sdcclib libint.lib _modsint.rel
6766 \end_layout
6767
6768 \begin_layout Standard
6769
6770 \family sans
6771 \series bold
6772 sdcclib libint.lib _moduint.rel
6773 \end_layout
6774
6775 \begin_layout Standard
6776
6777 \family sans
6778 \series bold
6779 sdcclib libint.lib _mulint.rel
6780 \family default
6781 \series default
6782
6783 \newline
6784
6785 \end_layout
6786
6787 \begin_layout Standard
6788 Or, if you preffer:
6789 \family sans
6790 \series bold
6791
6792 \newline
6793
6794 \end_layout
6795
6796 \begin_layout Standard
6797
6798 \family sans
6799 \series bold
6800 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6801 \family default
6802 \series default
6803
6804 \newline
6805
6806 \end_layout
6807
6808 \begin_layout Standard
6809 If the file already exists in the library, it will be replaced.
6810  If a list of .rel files is available, you can tell sdcclib to add those
6811  files to a library.
6812  For example, if the file 'myliblist.txt' contains
6813 \family sans
6814 \series bold
6815
6816 \newline
6817
6818 \end_layout
6819
6820 \begin_layout Standard
6821
6822 \family sans
6823 \series bold
6824 _divsint.rel
6825 \end_layout
6826
6827 \begin_layout Standard
6828
6829 \family sans
6830 \series bold
6831 _divuint.rel
6832 \end_layout
6833
6834 \begin_layout Standard
6835
6836 \family sans
6837 \series bold
6838 _modsint.rel
6839 \end_layout
6840
6841 \begin_layout Standard
6842
6843 \family sans
6844 \series bold
6845 _moduint.rel
6846 \end_layout
6847
6848 \begin_layout Standard
6849
6850 \family sans
6851 \series bold
6852 _mulint.rel
6853 \family default
6854 \series default
6855
6856 \newline
6857
6858 \end_layout
6859
6860 \begin_layout Standard
6861 Use
6862 \family sans
6863 \series bold
6864
6865 \newline
6866
6867 \end_layout
6868
6869 \begin_layout Standard
6870
6871 \family sans
6872 \series bold
6873 sdcclib -l libint.lib myliblist.txt
6874 \family default
6875 \series default
6876
6877 \newline
6878
6879 \end_layout
6880
6881 \begin_layout Standard
6882 Additionally, you can instruct sdcclib to compiles the files before adding
6883  them to the library.
6884  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6885  For example:
6886 \family sans
6887 \series bold
6888
6889 \newline
6890
6891 \end_layout
6892
6893 \begin_layout Standard
6894
6895 \family sans
6896 \series bold
6897 set SDCCLIB_CC=sdcc -c
6898 \end_layout
6899
6900 \begin_layout Standard
6901
6902 \family sans
6903 \series bold
6904 sdcclib -l libint.lib myliblist.txt
6905 \family default
6906 \series default
6907
6908 \newline
6909
6910 \end_layout
6911
6912 \begin_layout Standard
6913 To see what modules and symbols are included in the library, options -s
6914  and -m are available.
6915  For example:
6916 \newline
6917
6918 \newline
6919
6920 \family sans
6921 \series bold
6922 sdcclib -s libint.lib
6923 \family default
6924
6925 \begin_inset LatexCommand index
6926 name "sdcclib"
6927
6928 \end_inset
6929
6930
6931 \newline
6932
6933 \family typewriter
6934 \series default
6935 _divsint.rel:
6936 \end_layout
6937
6938 \begin_layout Standard
6939
6940 \family typewriter
6941 __divsint_a_1_1
6942 \end_layout
6943
6944 \begin_layout Standard
6945
6946 \family typewriter
6947 __divsint_PARM_2
6948 \end_layout
6949
6950 \begin_layout Standard
6951
6952 \family typewriter
6953 __divsint
6954 \newline
6955 _divuint.rel:
6956 \end_layout
6957
6958 \begin_layout Standard
6959
6960 \family typewriter
6961 __divuint_a_1_1
6962 \end_layout
6963
6964 \begin_layout Standard
6965
6966 \family typewriter
6967 __divuint_PARM_2
6968 \end_layout
6969
6970 \begin_layout Standard
6971
6972 \family typewriter
6973 __divuint_reste_1_1
6974 \end_layout
6975
6976 \begin_layout Standard
6977
6978 \family typewriter
6979 __divuint_count_1_1
6980 \end_layout
6981
6982 \begin_layout Standard
6983
6984 \family typewriter
6985 __divuint
6986 \newline
6987 _modsint.rel:
6988 \end_layout
6989
6990 \begin_layout Standard
6991
6992 \family typewriter
6993 __modsint_a_1_1
6994 \end_layout
6995
6996 \begin_layout Standard
6997
6998 \family typewriter
6999 __modsint_PARM_2
7000 \end_layout
7001
7002 \begin_layout Standard
7003
7004 \family typewriter
7005 __modsint
7006 \newline
7007 _moduint.rel:
7008 \end_layout
7009
7010 \begin_layout Standard
7011
7012 \family typewriter
7013 __moduint_a_1_1
7014 \end_layout
7015
7016 \begin_layout Standard
7017
7018 \family typewriter
7019 __moduint_PARM_2
7020 \end_layout
7021
7022 \begin_layout Standard
7023
7024 \family typewriter
7025 __moduint_count_1_1
7026 \end_layout
7027
7028 \begin_layout Standard
7029
7030 \family typewriter
7031 __moduint
7032 \newline
7033 _mulint.rel:
7034 \end_layout
7035
7036 \begin_layout Standard
7037
7038 \family typewriter
7039 __mulint_PARM_2
7040 \end_layout
7041
7042 \begin_layout Standard
7043
7044 \family typewriter
7045 __mulint
7046 \family default
7047 \series bold
7048
7049 \newline
7050
7051 \end_layout
7052
7053 \begin_layout Standard
7054 If the source files are compiled using -
7055 \begin_inset ERT
7056 status collapsed
7057
7058 \begin_layout Standard
7059
7060
7061 \backslash
7062 /
7063 \end_layout
7064
7065 \end_inset
7066
7067 -debug
7068 \begin_inset LatexCommand index
7069 name "-\\/-debug"
7070
7071 \end_inset
7072
7073 , the corresponding debug information file .adb will be include in the library
7074  file as well.
7075  The library files created with sdcclib are plain text files, so they can
7076  be viewed with a text editor.
7077  It is not recommended to modify a library file created with sdcclib using
7078  a text editor, as there are file indexes numbers located across the file
7079  used by the linker to quickly locate the required module to link.
7080  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
7081  it can be safely deleted, since all the information required for linking
7082  is embedded in the library file itself.
7083  Library files created using sdcclib are used as described in the preceding
7084  sections.
7085 \begin_inset VSpace bigskip
7086 \end_inset
7087
7088
7089 \end_layout
7090
7091 \begin_layout Section
7092 Command Line Options
7093 \begin_inset LatexCommand index
7094 name "Command Line Options"
7095
7096 \end_inset
7097
7098
7099 \begin_inset LatexCommand label
7100 name "sec:Command-Line-Options"
7101
7102 \end_inset
7103
7104
7105 \end_layout
7106
7107 \begin_layout Subsection
7108 Processor Selection Options
7109 \begin_inset LatexCommand index
7110 name "Options processor selection"
7111
7112 \end_inset
7113
7114
7115 \begin_inset LatexCommand index
7116 name "Processor selection options"
7117
7118 \end_inset
7119
7120
7121 \end_layout
7122
7123 \begin_layout List
7124 \labelwidthstring 00.00.0000
7125
7126 \series bold
7127 -mmcs51
7128 \begin_inset LatexCommand index
7129 name "-mmcs51"
7130
7131 \end_inset
7132
7133
7134 \series default
7135  Generate code for the Intel MCS51
7136 \begin_inset LatexCommand index
7137 name "MCS51"
7138
7139 \end_inset
7140
7141  family of processors.
7142  This is the default processor target.
7143 \end_layout
7144
7145 \begin_layout List
7146 \labelwidthstring 00.00.0000
7147
7148 \series bold
7149 -mds390
7150 \begin_inset LatexCommand index
7151 name "-mds390"
7152
7153 \end_inset
7154
7155
7156 \series default
7157  Generate code for the Dallas DS80C390
7158 \begin_inset LatexCommand index
7159 name "DS80C390"
7160
7161 \end_inset
7162
7163  processor.
7164 \end_layout
7165
7166 \begin_layout List
7167 \labelwidthstring 00.00.0000
7168
7169 \series bold
7170 -mds400
7171 \begin_inset LatexCommand index
7172 name "-mds400"
7173
7174 \end_inset
7175
7176
7177 \series default
7178  Generate code for the Dallas DS80C400
7179 \begin_inset LatexCommand index
7180 name "DS80C400"
7181
7182 \end_inset
7183
7184  processor.
7185 \end_layout
7186
7187 \begin_layout List
7188 \labelwidthstring 00.00.0000
7189
7190 \series bold
7191 -mhc08
7192 \begin_inset LatexCommand index
7193 name "-mhc08"
7194
7195 \end_inset
7196
7197
7198 \series default
7199  Generate code for the Freescale/Motorola HC08
7200 \begin_inset LatexCommand index
7201 name "HC08"
7202
7203 \end_inset
7204
7205  family of processors.
7206 \end_layout
7207
7208 \begin_layout List
7209 \labelwidthstring 00.00.0000
7210
7211 \series bold
7212 -mz80
7213 \begin_inset LatexCommand index
7214 name "-mz80"
7215
7216 \end_inset
7217
7218
7219 \series default
7220  Generate code for the Zilog Z80
7221 \begin_inset LatexCommand index
7222 name "Z80"
7223
7224 \end_inset
7225
7226  family of processors.
7227 \end_layout
7228
7229 \begin_layout List
7230 \labelwidthstring 00.00.0000
7231
7232 \series bold
7233 -mgbz80
7234 \begin_inset LatexCommand index
7235 name "-mgbz80"
7236
7237 \end_inset
7238
7239
7240 \series default
7241  Generate code for the GameBoy Z80
7242 \begin_inset LatexCommand index
7243 name "gbz80 (GameBoy Z80)"
7244
7245 \end_inset
7246
7247  processor (Not actively maintained).
7248 \end_layout
7249
7250 \begin_layout List
7251 \labelwidthstring 00.00.0000
7252
7253 \series bold
7254 -mavr
7255 \begin_inset LatexCommand index
7256 name "-mavr"
7257
7258 \end_inset
7259
7260
7261 \series default
7262  Generate code for the Atmel AVR
7263 \begin_inset LatexCommand index
7264 name "AVR"
7265
7266 \end_inset
7267
7268  processor (Not maintained, not complete).
7269  AVR users should probably have a look at winavr 
7270 \begin_inset LatexCommand url
7271 target "http://sourceforge.net/projects/winavr"
7272
7273 \end_inset
7274
7275  or 
7276 \begin_inset LatexCommand url
7277 target "http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index"
7278
7279 \end_inset
7280
7281 , which is based on AVR-port of the gcc compiler.
7282 \end_layout
7283
7284 \begin_layout Standard
7285 \begin_inset Note Note
7286 status collapsed
7287
7288 \begin_layout Standard
7289 I think it is fair to direct users there for now.
7290  Open source is also about avoiding unnecessary work .
7291  But I didn't find the 'official' link.
7292 \end_layout
7293
7294 \end_inset
7295
7296
7297 \end_layout
7298
7299 \begin_layout List
7300 \labelwidthstring 00.00.0000
7301
7302 \series bold
7303 -mpic14
7304 \begin_inset LatexCommand index
7305 name "-mpic14"
7306
7307 \end_inset
7308
7309
7310 \series default
7311  Generate code for the Microchip PIC 14
7312 \begin_inset LatexCommand index
7313 name "PIC14"
7314
7315 \end_inset
7316
7317 -bit processors (p16f84 and variants.
7318  In development, not complete).
7319 \end_layout
7320
7321 \begin_layout Standard
7322 \begin_inset Note Note
7323 status collapsed
7324
7325 \begin_layout Standard
7326 p16f627 p16f628 p16f84 p16f873 p16f877?
7327 \end_layout
7328
7329 \end_inset
7330
7331
7332 \end_layout
7333
7334 \begin_layout List
7335 \labelwidthstring 00.00.0000
7336
7337 \series bold
7338 -mpic16
7339 \begin_inset LatexCommand index
7340 name "-mpic16"
7341
7342 \end_inset
7343
7344
7345 \series default
7346  Generate code for the Microchip PIC 16
7347 \begin_inset LatexCommand index
7348 name "PIC16"
7349
7350 \end_inset
7351
7352 -bit processors (p18f452 and variants.
7353  In development, not complete).
7354 \end_layout
7355
7356 \begin_layout List
7357 \labelwidthstring 00.00.0000
7358
7359 \series bold
7360 -mtlcs900h
7361 \series default
7362  Generate code for the Toshiba TLCS-900H
7363 \begin_inset LatexCommand index
7364 name "TLCS-900H"
7365
7366 \end_inset
7367
7368  processor (Not maintained, not complete).
7369 \end_layout
7370
7371 \begin_layout List
7372 \labelwidthstring 00.00.0000
7373
7374 \series bold
7375 -mxa51
7376 \begin_inset LatexCommand index
7377 name "-mxa51"
7378
7379 \end_inset
7380
7381
7382 \series default
7383  Generate code for the Phillips XA51
7384 \begin_inset LatexCommand index
7385 name "XA51"
7386
7387 \end_inset
7388
7389  processor (Not maintained, not complete).
7390 \end_layout
7391
7392 \begin_layout Standard
7393 \begin_inset VSpace bigskip
7394 \end_inset
7395
7396
7397 \end_layout
7398
7399 \begin_layout Subsection
7400 Preprocessor Options
7401 \begin_inset LatexCommand index
7402 name "Options preprocessor"
7403
7404 \end_inset
7405
7406
7407 \begin_inset LatexCommand index
7408 name "Preprocessor options"
7409
7410 \end_inset
7411
7412
7413 \begin_inset LatexCommand index
7414 name "sdcpp (preprocessor)"
7415
7416 \end_inset
7417
7418
7419 \end_layout
7420
7421 \begin_layout List
7422 \labelwidthstring 00.00.0000
7423
7424 \series bold
7425 -I<path>
7426 \begin_inset LatexCommand index
7427 name "-I<path>"
7428
7429 \end_inset
7430
7431
7432 \series default
7433  The additional location where the preprocessor will look for <..h> or 
7434 \begin_inset Quotes eld
7435 \end_inset
7436
7437 ..h
7438 \begin_inset Quotes erd
7439 \end_inset
7440
7441  files.
7442 \end_layout
7443
7444 \begin_layout List
7445 \labelwidthstring 00.00.0000
7446
7447 \series bold
7448 -D<macro[=value]>
7449 \begin_inset LatexCommand index
7450 name "-D<macro[=value]>"
7451
7452 \end_inset
7453
7454
7455 \series default
7456  Command line definition of macros.
7457  Passed to the preprocessor.
7458 \end_layout
7459
7460 \begin_layout List
7461 \labelwidthstring 00.00.0000
7462
7463 \series bold
7464 -M
7465 \begin_inset LatexCommand index
7466 name "-M"
7467
7468 \end_inset
7469
7470
7471 \series default
7472  Tell the preprocessor to output a rule suitable for make describing the
7473  dependencies of each object file.
7474  For each source file, the preprocessor outputs one make-rule whose target
7475  is the object file name for that source file and whose dependencies are
7476  all the files `#include'd in it.
7477  This rule may be a single line or may be continued with `
7478 \backslash
7479 '-newline if it is long.
7480  The list of rules is printed on standard output instead of the preprocessed
7481  C program.
7482  `-M' implies `-E
7483 \begin_inset LatexCommand index
7484 name "-E"
7485
7486 \end_inset
7487
7488 '.
7489 \end_layout
7490
7491 \begin_layout List
7492 \labelwidthstring 00.00.0000
7493
7494 \series bold
7495 -C
7496 \begin_inset LatexCommand index
7497 name "-C"
7498
7499 \end_inset
7500
7501
7502 \series default
7503  Tell the preprocessor not to discard comments.
7504  Used with the `-E' option.
7505 \end_layout
7506
7507 \begin_layout List
7508 \labelwidthstring 00.00.0000
7509
7510 \series bold
7511 -MM
7512 \begin_inset LatexCommand index
7513 name "-MM"
7514
7515 \end_inset
7516
7517
7518 \series default
7519 \size large
7520  
7521 \size default
7522 Like `-M' but the output mentions only the user header files included with
7523  `#include 
7524 \begin_inset Quotes eld
7525 \end_inset
7526
7527 file"'.
7528  System header files included with `#include <file>' are omitted.
7529 \end_layout
7530
7531 \begin_layout List
7532 \labelwidthstring 00.00.0000
7533
7534 \series bold
7535 -Aquestion(answer)
7536 \begin_inset LatexCommand index
7537 name "-Aquestion(answer)"
7538
7539 \end_inset
7540
7541
7542 \series default
7543  Assert the answer answer for question, in case it is tested with a preprocessor
7544  conditional such as `#if #question(answer)'.
7545  `-A-' disables the standard assertions that normally describe the target
7546  machine.
7547 \end_layout
7548
7549 \begin_layout List
7550 \labelwidthstring 00.00.0000
7551
7552 \series bold
7553 -Umacro
7554 \begin_inset LatexCommand index
7555 name "-Umacro"
7556
7557 \end_inset
7558
7559
7560 \series default
7561  Undefine macro macro.
7562  `-U' options are evaluated after all `-D' options, but before any `-include'
7563  and `-imacros' options.
7564 \end_layout
7565
7566 \begin_layout List
7567 \labelwidthstring 00.00.0000
7568
7569 \series bold
7570 -dM
7571 \begin_inset LatexCommand index
7572 name "-dM"
7573
7574 \end_inset
7575
7576
7577 \series default
7578  Tell the preprocessor to output only a list of the macro definitions that
7579  are in effect at the end of preprocessing.
7580  Used with the `-E' option.
7581 \end_layout
7582
7583 \begin_layout List
7584 \labelwidthstring 00.00.0000
7585
7586 \series bold
7587 -dD
7588 \begin_inset LatexCommand index
7589 name "-dD"
7590
7591 \end_inset
7592
7593
7594 \series default
7595  Tell the preprocessor to pass all macro definitions into the output, in
7596  their proper sequence in the rest of the output.
7597 \end_layout
7598
7599 \begin_layout List
7600 \labelwidthstring 00.00.0000
7601
7602 \series bold
7603 -dN
7604 \begin_inset LatexCommand index
7605 name "-dN"
7606
7607 \end_inset
7608
7609
7610 \series default
7611 \size large
7612  
7613 \size default
7614 Like `-dD' except that the macro arguments and contents are omitted.
7615  Only `#define name' is included in the output.
7616 \end_layout
7617
7618 \begin_layout List
7619 \labelwidthstring 00.00.0000
7620
7621 \series bold
7622 -pedantic-parse-number
7623 \begin_inset LatexCommand index
7624 name "pedantic"
7625
7626 \end_inset
7627
7628
7629 \begin_inset LatexCommand index
7630 name "-pedantic-parse-number"
7631
7632 \end_inset
7633
7634
7635 \size large
7636 \bar under
7637
7638 \begin_inset LatexCommand label
7639 name "lyx:-pedantic-parse-number"
7640
7641 \end_inset
7642
7643
7644 \series default
7645 \bar default
7646  
7647 \size default
7648 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7649  and the macro LO_B(3) gets expanded.
7650  See also #pragma pedantic_parse_number 
7651 \begin_inset LatexCommand vpageref
7652 reference "ite:pedantic_parse_number"
7653
7654 \end_inset
7655
7656  in section
7657 \begin_inset LatexCommand ref
7658 reference "sec:Pragmas"
7659
7660 \end_inset
7661
7662  
7663 \emph on
7664 Note: this functionality is not in conformance with C99 standard!
7665 \end_layout
7666
7667 \begin_layout List
7668 \labelwidthstring 00.00.0000
7669
7670 \series bold
7671 -Wp\InsetSpace ~
7672 preprocessorOption[,preprocessorOption]
7673 \series default
7674
7675 \begin_inset LatexCommand index
7676 name "-Wp preprocessorOption[,preprocessorOption]"
7677
7678 \end_inset
7679
7680 ...
7681  Pass the preprocessorOption to the preprocessor 
7682 \family typewriter
7683 sdcpp
7684 \family default
7685
7686 \begin_inset LatexCommand index
7687 name "sdcpp (preprocessor)"
7688
7689 \end_inset
7690
7691 .
7692  SDCC uses an adapted version of the preprocessor 
7693 \emph on
7694 cpp
7695 \emph default
7696  of the GNU Compiler Collection
7697 \begin_inset LatexCommand index
7698 name "gcc (GNU Compiler Collection)"
7699
7700 \end_inset
7701
7702  (
7703 \emph on
7704 gcc
7705 \emph default
7706  
7707 \begin_inset LatexCommand url
7708 target "http://gcc.gnu.org/"
7709
7710 \end_inset
7711
7712 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7713 4.1.1\InsetSpace ~
7714 CPP\InsetSpace ~
7715 Manual
7716  at 
7717 \begin_inset LatexCommand htmlurl
7718 target "http://www.gnu.org/software/gcc/onlinedocs/"
7719
7720 \end_inset
7721
7722 .
7723 \end_layout
7724
7725 \begin_layout Standard
7726 \begin_inset VSpace bigskip
7727 \end_inset
7728
7729
7730 \end_layout
7731
7732 \begin_layout Subsection
7733 Linker Options
7734 \begin_inset LatexCommand index
7735 name "Options linker"
7736
7737 \end_inset
7738
7739
7740 \begin_inset LatexCommand index
7741 name "Linker options"
7742
7743 \end_inset
7744
7745
7746 \end_layout
7747
7748 \begin_layout List
7749 \labelwidthstring 00.00.0000
7750
7751 \series bold
7752 -L\InsetSpace ~
7753 -
7754 \series default
7755
7756 \begin_inset ERT
7757 status collapsed
7758
7759 \begin_layout Standard
7760
7761
7762 \backslash
7763 /
7764 \end_layout
7765
7766 \end_inset
7767
7768
7769 \series bold
7770 -lib-path
7771 \begin_inset LatexCommand index
7772 name "-\\/-lib-path <path>"
7773
7774 \end_inset
7775
7776
7777 \begin_inset LatexCommand index
7778 name "-L -\\/-lib-path"
7779
7780 \end_inset
7781
7782
7783 \series default
7784 \InsetSpace ~
7785 <absolute path to additional libraries> This option is passed to the linkage
7786  editor's additional libraries
7787 \begin_inset LatexCommand index
7788 name "Libraries"
7789
7790 \end_inset
7791
7792  search path.
7793  The path name must be absolute.
7794  Additional library files may be specified in the command line.
7795  See section Compiling programs for more details.
7796 \end_layout
7797
7798 \begin_layout List
7799 \labelwidthstring 00.00.0000
7800
7801 \series bold
7802 -
7803 \begin_inset ERT
7804 status collapsed
7805
7806 \begin_layout Standard
7807
7808
7809 \backslash
7810 /
7811 \end_layout
7812
7813 \end_inset
7814
7815 -xram-loc
7816 \series default
7817
7818 \begin_inset LatexCommand index
7819 name "-\\/-xram-loc <Value>"
7820
7821 \end_inset
7822
7823 \InsetSpace ~
7824 <Value> The start location of the external ram
7825 \begin_inset LatexCommand index
7826 name "xdata (mcs51, ds390 storage class)"
7827
7828 \end_inset
7829
7830 , default value is 0.
7831  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7832 \begin_inset ERT
7833 status collapsed
7834
7835 \begin_layout Standard
7836
7837
7838 \backslash
7839 /
7840 \end_layout
7841
7842 \end_inset
7843
7844 -xram-loc 0x8000 or -
7845 \begin_inset ERT
7846 status collapsed
7847
7848 \begin_layout Standard
7849
7850
7851 \backslash
7852 /
7853 \end_layout
7854
7855 \end_inset
7856
7857 -xram-loc 32768.
7858 \end_layout
7859
7860 \begin_layout List
7861 \labelwidthstring 00.00.0000
7862
7863 \series bold
7864 -
7865 \begin_inset ERT
7866 status collapsed
7867
7868 \begin_layout Standard
7869
7870
7871 \backslash
7872 /
7873 \end_layout
7874
7875 \end_inset
7876
7877 -code-loc
7878 \series default
7879
7880 \begin_inset LatexCommand index
7881 name "-\\/-code-loc <Value>"
7882
7883 \end_inset
7884
7885 \InsetSpace ~
7886 <Value> The start location of the code
7887 \begin_inset LatexCommand index
7888 name "code"
7889
7890 \end_inset
7891
7892  segment, default value 0.
7893  Note when this option is used the interrupt vector table
7894 \begin_inset LatexCommand index
7895 name "interrupt vector table"
7896
7897 \end_inset
7898
7899  is also relocated to the given address.
7900  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7901 \begin_inset ERT
7902 status collapsed
7903
7904 \begin_layout Standard
7905
7906
7907 \backslash
7908 /
7909 \end_layout
7910
7911 \end_inset
7912
7913 -code-loc 0x8000 or -
7914 \begin_inset ERT
7915 status collapsed
7916
7917 \begin_layout Standard
7918
7919
7920 \backslash
7921 /
7922 \end_layout
7923
7924 \end_inset
7925
7926 -code-loc 32768.
7927 \end_layout
7928
7929 \begin_layout List
7930 \labelwidthstring 00.00.0000
7931
7932 \series bold
7933 -
7934 \begin_inset ERT
7935 status collapsed
7936
7937 \begin_layout Standard
7938
7939
7940 \backslash
7941 /
7942 \end_layout
7943
7944 \end_inset
7945
7946 -stack-loc
7947 \series default
7948
7949 \begin_inset LatexCommand index
7950 name "-\\/-stack-loc <Value>"
7951
7952 \end_inset
7953
7954 \InsetSpace ~
7955 <Value> By default the stack
7956 \begin_inset LatexCommand index
7957 name "stack"
7958
7959 \end_inset
7960
7961  is placed after the data segment.
7962  Using this option the stack can be placed anywhere in the internal memory
7963  space of the 8051.
7964  The value entered can be in Hexadecimal or Decimal format, e.g.
7965  -
7966 \begin_inset ERT
7967 status collapsed
7968
7969 \begin_layout Standard
7970
7971
7972 \backslash
7973 /
7974 \end_layout
7975
7976 \end_inset
7977
7978 -stack-loc 0x20 or -
7979 \begin_inset ERT
7980 status collapsed
7981
7982 \begin_layout Standard
7983
7984
7985 \backslash
7986 /
7987 \end_layout
7988
7989 \end_inset
7990
7991 -stack-loc 32.
7992  Since the sp register is incremented before a push or call, the initial
7993  sp will be set to one byte prior the provided value.
7994  The provided value should not overlap any other memory areas such as used
7995  register banks or the data segment and with enough space for the current
7996  application.
7997  The 
7998 \series bold
7999 -
8000 \begin_inset ERT
8001 status collapsed
8002
8003 \begin_layout Standard
8004
8005
8006 \backslash
8007 /
8008 \end_layout
8009
8010 \end_inset
8011
8012 -pack-iram
8013 \series default
8014 \InsetSpace ~
8015
8016 \begin_inset LatexCommand index
8017 name "-\\/-pack-iram"
8018
8019 \end_inset
8020
8021  option (which is now a default setting) will override this setting, so
8022  you should also specify the 
8023 \series bold
8024 -
8025 \begin_inset ERT
8026 status collapsed
8027
8028 \begin_layout Standard
8029
8030
8031 \backslash
8032 /
8033 \end_layout
8034
8035 \end_inset
8036
8037 -no-pack-iram
8038 \series default
8039 \InsetSpace ~
8040
8041 \begin_inset LatexCommand index
8042 name "-\\/-no-pack-iram"
8043
8044 \end_inset
8045
8046  option if you need to manually place the stack.
8047 \end_layout
8048
8049 \begin_layout List
8050 \labelwidthstring 00.00.0000
8051
8052 \series bold
8053 -
8054 \begin_inset ERT
8055 status collapsed
8056
8057 \begin_layout Standard
8058
8059
8060 \backslash
8061 /
8062 \end_layout
8063
8064 \end_inset
8065
8066 -xstack-loc
8067 \series default
8068
8069 \begin_inset LatexCommand index
8070 name "-\\/-xstack-loc <Value>"
8071
8072 \end_inset
8073
8074 \InsetSpace ~
8075 <Value> By default the external stack
8076 \begin_inset LatexCommand index
8077 name "xstack"
8078
8079 \end_inset
8080
8081  is placed after the pdata
8082 \begin_inset LatexCommand index
8083 name "pdata (mcs51, ds390 storage class)"
8084
8085 \end_inset
8086
8087  segment.
8088  Using this option the xstack can be placed anywhere in the external memory
8089  space of the 8051.
8090  The value entered can be in Hexadecimal or Decimal format, e.g.
8091  -
8092 \begin_inset ERT
8093 status collapsed
8094
8095 \begin_layout Standard
8096
8097
8098 \backslash
8099 /
8100 \end_layout
8101
8102 \end_inset
8103
8104 -xstack-loc 0x8000 or -
8105 \begin_inset ERT
8106 status collapsed
8107
8108 \begin_layout Standard
8109
8110
8111 \backslash
8112 /
8113 \end_layout
8114
8115 \end_inset
8116
8117 -stack-loc 32768.
8118  The provided value should not overlap any other memory areas such as the
8119  pdata or xdata segment and with enough space for the current application.
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 -data-loc
8140 \series default
8141
8142 \begin_inset LatexCommand index
8143 name "-\\/-data-loc <Value>"
8144
8145 \end_inset
8146
8147 \InsetSpace ~
8148 <Value> The start location of the internal ram data
8149 \begin_inset LatexCommand index
8150 name "data (mcs51, ds390 storage class)"
8151
8152 \end_inset
8153
8154  segment.
8155  The value entered can be in Hexadecimal or Decimal format, eg.
8156  -
8157 \begin_inset ERT
8158 status collapsed
8159
8160 \begin_layout Standard
8161
8162
8163 \backslash
8164 /
8165 \end_layout
8166
8167 \end_inset
8168
8169 -data-loc 0x20 or -
8170 \begin_inset ERT
8171 status collapsed
8172
8173 \begin_layout Standard
8174
8175
8176 \backslash
8177 /
8178 \end_layout
8179
8180 \end_inset
8181
8182 -data-loc 32.
8183  (By default, the start location of the internal ram data segment  is set
8184  as low as possible in memory, taking into account the used register banks
8185  and the bit segment at address 0x20.
8186  For example if register banks 0 and 1 are used without bit variables, the
8187  data segment will be set, if -
8188 \begin_inset ERT
8189 status collapsed
8190
8191 \begin_layout Standard
8192
8193
8194 \backslash
8195 /
8196 \end_layout
8197
8198 \end_inset
8199
8200 -data-loc is not used, to location 0x10.)
8201 \end_layout
8202
8203 \begin_layout List
8204 \labelwidthstring 00.00.0000
8205
8206 \series bold
8207 -
8208 \begin_inset ERT
8209 status collapsed
8210
8211 \begin_layout Standard
8212
8213
8214 \backslash
8215 /
8216 \end_layout
8217
8218 \end_inset
8219
8220 -idata-loc
8221 \series default
8222
8223 \begin_inset LatexCommand index
8224 name "-\\/-idata-loc <Value>"
8225
8226 \end_inset
8227
8228 \InsetSpace ~
8229 <Value> The start location of the indirectly addressable internal ram
8230 \begin_inset LatexCommand index
8231 name "idata (mcs51, ds390 storage class)"
8232
8233 \end_inset
8234
8235  of the 8051, default value is 0x80.
8236  The value entered can be in Hexadecimal or Decimal format, eg.
8237  -
8238 \begin_inset ERT
8239 status collapsed
8240
8241 \begin_layout Standard
8242
8243
8244 \backslash
8245 /
8246 \end_layout
8247
8248 \end_inset
8249
8250 -idata-loc 0x88 or -
8251 \begin_inset ERT
8252 status collapsed
8253
8254 \begin_layout Standard
8255
8256
8257 \backslash
8258 /
8259 \end_layout
8260
8261 \end_inset
8262
8263 -idata-loc 136.
8264 \end_layout
8265
8266 \begin_layout List
8267 \labelwidthstring 00.00.0000
8268
8269 \series bold
8270 -
8271 \begin_inset ERT
8272 status collapsed
8273
8274 \begin_layout Standard
8275
8276
8277 \backslash
8278 /
8279 \end_layout
8280
8281 \end_inset
8282
8283 -bit-loc
8284 \series default
8285 \InsetSpace ~
8286 <Value> The start location of the bit
8287 \begin_inset LatexCommand index
8288 name "bit"
8289
8290 \end_inset
8291
8292  addressable internal ram of the 8051.
8293  This is 
8294 \emph on
8295 not
8296 \emph default
8297  implemented yet.
8298  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8299 -bBSEG=<Value>.
8300 \end_layout
8301
8302 \begin_layout List
8303 \labelwidthstring 00.00.0000
8304
8305 \series bold
8306 -
8307 \begin_inset ERT
8308 status collapsed
8309
8310 \begin_layout Standard
8311
8312
8313 \backslash
8314 /
8315 \end_layout
8316
8317 \end_inset
8318
8319 -out-fmt-ihx
8320 \begin_inset LatexCommand index
8321 name "-\\/-out-fmt-ihx"
8322
8323 \end_inset
8324
8325  
8326 \series default
8327 The linker output (final object code) is in Intel Hex format.
8328 \begin_inset LatexCommand index
8329 name "Intel hex format"
8330
8331 \end_inset
8332
8333  This is the default option.
8334  The format itself is documented in the documentation of srecord
8335 \begin_inset LatexCommand index
8336 name "srecord (bin, hex, ... tool)"
8337
8338 \end_inset
8339
8340 .
8341 \end_layout
8342
8343 \begin_layout List
8344 \labelwidthstring 00.00.0000
8345
8346 \series bold
8347 -
8348 \begin_inset ERT
8349 status collapsed
8350
8351 \begin_layout Standard
8352
8353
8354 \backslash
8355 /
8356 \end_layout
8357
8358 \end_inset
8359
8360 -out-fmt-s19
8361 \begin_inset LatexCommand index
8362 name "-\\/-out-fmt-s19"
8363
8364 \end_inset
8365
8366  
8367 \series default
8368 The linker output (final object code) is in Motorola S19 format
8369 \begin_inset LatexCommand index
8370 name "Motorola S19 format"
8371
8372 \end_inset
8373
8374 .
8375  The format itself is documented in the documentation of srecord.
8376 \end_layout
8377
8378 \begin_layout List
8379 \labelwidthstring 00.00.0000
8380
8381 \series bold
8382 -
8383 \begin_inset ERT
8384 status collapsed
8385
8386 \begin_layout Standard
8387
8388
8389 \backslash
8390 /
8391 \end_layout
8392
8393 \end_inset
8394
8395 -out-fmt-elf
8396 \begin_inset LatexCommand index
8397 name "-\\/-out-fmt-s19"
8398
8399 \end_inset
8400
8401
8402 \begin_inset LatexCommand index
8403 name "HC08!Options!-\\/-out-fmt-elf"
8404
8405 \end_inset
8406
8407  
8408 \series default
8409 The linker output (final object code) is in ELF format
8410 \begin_inset LatexCommand index
8411 name "ELF format"
8412
8413 \end_inset
8414
8415 .
8416  (Currently only supported for the HC08
8417 \begin_inset LatexCommand index
8418 name "HC08"
8419
8420 \end_inset
8421
8422  processors)
8423 \end_layout
8424
8425 \begin_layout List
8426 \labelwidthstring 00.00.0000
8427
8428 \series bold
8429 -Wl\InsetSpace ~
8430 linkOption[,linkOption]
8431 \series default
8432
8433 \begin_inset LatexCommand index
8434 name "-Wl linkOption[,linkOption]"
8435
8436 \end_inset
8437
8438
8439 \begin_inset LatexCommand label
8440 name "lyx:-Wl option"
8441
8442 \end_inset
8443
8444 ...
8445  Pass the linkOption to the linker.
8446  If a bootloader is used an option like 
8447 \begin_inset Quotes sld
8448 \end_inset
8449
8450 -Wl\InsetSpace ~
8451 -bCSEG=0x1000
8452 \begin_inset Quotes srd
8453 \end_inset
8454
8455  would be typical to set the start of the code segment.
8456  Either use the double quotes around this option or use no space (e.g.
8457  -Wl-bCSEG=0x1000).
8458  See also #pragma constseg and #pragma codeseg in section 
8459 \begin_inset LatexCommand ref
8460 reference "sec:Pragmas"
8461
8462 \end_inset
8463
8464  .
8465  File sdcc/as/doc/asxhtm.html has more on linker options.
8466 \end_layout
8467
8468 \begin_layout Standard
8469 \begin_inset VSpace bigskip
8470 \end_inset
8471
8472
8473 \end_layout
8474
8475 \begin_layout Subsection
8476 MCS51 Options
8477 \begin_inset LatexCommand index
8478 name "Options MCS51"
8479
8480 \end_inset
8481
8482
8483 \begin_inset LatexCommand index
8484 name "MCS51 options"
8485
8486 \end_inset
8487
8488
8489 \end_layout
8490
8491 \begin_layout List
8492 \labelwidthstring 00.00.0000
8493
8494 \series bold
8495 -
8496 \begin_inset ERT
8497 status collapsed
8498
8499 \begin_layout Standard
8500
8501
8502 \backslash
8503 /
8504 \end_layout
8505
8506 \end_inset
8507
8508 -model-small
8509 \begin_inset LatexCommand index
8510 name "-\\/-model-small"
8511
8512 \end_inset
8513
8514
8515 \series default
8516 \size large
8517  
8518 \size default
8519 Generate code for Small Model programs, see section Memory Models for more
8520  details.
8521  This is the default model.
8522 \end_layout
8523
8524 \begin_layout List
8525 \labelwidthstring 00.00.0000
8526
8527 \series bold
8528 -
8529 \begin_inset ERT
8530 status collapsed
8531
8532 \begin_layout Standard
8533
8534
8535 \backslash
8536 /
8537 \end_layout
8538
8539 \end_inset
8540
8541 -model-medium
8542 \begin_inset LatexCommand index
8543 name "-\\/-model-medium"
8544
8545 \end_inset
8546
8547
8548 \series default
8549  Generate code for Medium model programs, see section Memory Models for
8550  more details.
8551  If this option is used all source files in the project have to be compiled
8552  with this option.
8553  It must also be used when invoking the linker.
8554 \end_layout
8555
8556 \begin_layout List
8557 \labelwidthstring 00.00.0000
8558
8559 \series bold
8560 -
8561 \begin_inset ERT
8562 status collapsed
8563
8564 \begin_layout Standard
8565
8566
8567 \backslash
8568 /
8569 \end_layout
8570
8571 \end_inset
8572
8573 -model-large
8574 \begin_inset LatexCommand index
8575 name "-\\/-model-large"
8576
8577 \end_inset
8578
8579
8580 \series default
8581  Generate code for Large model programs, see section Memory Models for more
8582  details.
8583  If this option is used all source files in the project have to be compiled
8584  with this option.
8585  It must also be used when invoking the linker.
8586 \end_layout
8587
8588 \begin_layout List
8589 \labelwidthstring 00.00.0000
8590
8591 \series bold
8592 -
8593 \begin_inset ERT
8594 status collapsed
8595
8596 \begin_layout Standard
8597
8598
8599 \backslash
8600 /
8601 \end_layout
8602
8603 \end_inset
8604
8605 -xstack
8606 \begin_inset LatexCommand index
8607 name "-\\/-xstack"
8608
8609 \end_inset
8610
8611
8612 \series default
8613  Uses a pseudo stack in the pdata
8614 \begin_inset LatexCommand index
8615 name "pdata (mcs51, ds390 storage class)"
8616
8617 \end_inset
8618
8619  area (usually the first 256 bytes in the external ram) for allocating variables
8620  and passing parameters.
8621  See section 
8622 \begin_inset LatexCommand ref
8623 reference "sub:External-Stack"
8624
8625 \end_inset
8626
8627 \InsetSpace ~
8628  External Stack for more details.
8629 \end_layout
8630
8631 \begin_layout List
8632 \labelwidthstring 00.00.0000
8633
8634 \series bold
8635 -
8636 \begin_inset ERT
8637 status collapsed
8638
8639 \begin_layout Standard
8640
8641
8642 \backslash
8643 /
8644 \end_layout
8645
8646 \end_inset
8647
8648 -iram-size
8649 \series default
8650 \InsetSpace ~
8651 <Value>
8652 \begin_inset LatexCommand index
8653 name "-\\/-iram-size <Value>"
8654
8655 \end_inset
8656
8657  Causes the linker to check if the internal ram usage is within limits of
8658  the given value.
8659 \end_layout
8660
8661 \begin_layout List
8662 \labelwidthstring 00.00.0000
8663
8664 \series bold
8665 -
8666 \begin_inset ERT
8667 status collapsed
8668
8669 \begin_layout Standard
8670
8671
8672 \backslash
8673 /
8674 \end_layout
8675
8676 \end_inset
8677
8678 -xram-size
8679 \series default
8680 \InsetSpace ~
8681 <Value>
8682 \begin_inset LatexCommand index
8683 name "-\\/-xram-size <Value>"
8684
8685 \end_inset
8686
8687  Causes the linker to check if the external ram usage is within limits of
8688  the given value.
8689 \end_layout
8690
8691 \begin_layout List
8692 \labelwidthstring 00.00.0000
8693
8694 \series bold
8695 -
8696 \begin_inset ERT
8697 status collapsed
8698
8699 \begin_layout Standard
8700
8701
8702 \backslash
8703 /
8704 \end_layout
8705
8706 \end_inset
8707
8708 -code-size
8709 \series default
8710 \InsetSpace ~
8711 <Value>
8712 \begin_inset LatexCommand index
8713 name "-\\/-code-size <Value>"
8714
8715 \end_inset
8716
8717  Causes the linker to check if the code memory usage is within limits of
8718  the given value.
8719 \end_layout
8720
8721 \begin_layout List
8722 \labelwidthstring 00.00.0000
8723
8724 \series bold
8725 -
8726 \begin_inset ERT
8727 status collapsed
8728
8729 \begin_layout Standard
8730
8731
8732 \backslash
8733 /
8734 \end_layout
8735
8736 \end_inset
8737
8738 -stack-size
8739 \series default
8740 \InsetSpace ~
8741 <Value>
8742 \begin_inset LatexCommand index
8743 name "-\\/-stack-size <Value>"
8744
8745 \end_inset
8746
8747  Causes the linker to check if there is at minimum <Value> bytes for stack.
8748 \end_layout
8749
8750 \begin_layout List
8751 \labelwidthstring 00.00.0000
8752
8753 \series bold
8754 -
8755 \begin_inset ERT
8756 status collapsed
8757
8758 \begin_layout Standard
8759
8760
8761 \backslash
8762 /
8763 \end_layout
8764
8765 \end_inset
8766
8767 -pack-iram
8768 \series default
8769 \InsetSpace ~
8770
8771 \begin_inset LatexCommand index
8772 name "-\\/-pack-iram"
8773
8774 \end_inset
8775
8776  Causes the linker to use unused register banks for data variables and pack
8777  data, idata and stack together.
8778  This is the default now.
8779 \end_layout
8780
8781 \begin_layout List
8782 \labelwidthstring 00.00.0000
8783
8784 \series bold
8785 -
8786 \begin_inset ERT
8787 status collapsed
8788
8789 \begin_layout Standard
8790
8791
8792 \backslash
8793 /
8794 \end_layout
8795
8796 \end_inset
8797
8798 -no-pack-iram
8799 \series default
8800 \InsetSpace ~
8801
8802 \begin_inset LatexCommand index
8803 name "-\\/-no-pack-iram"
8804
8805 \end_inset
8806
8807  Causes the linker to use old style for allocating memory areas.
8808 \end_layout
8809
8810 \begin_layout List
8811 \labelwidthstring 00.00.0000
8812
8813 \series bold
8814 -
8815 \begin_inset ERT
8816 status collapsed
8817
8818 \begin_layout Standard
8819
8820
8821 \backslash
8822 /
8823 \end_layout
8824
8825 \end_inset
8826
8827 -acall-ajmp
8828 \series default
8829 \InsetSpace ~
8830
8831 \begin_inset LatexCommand index
8832 name "-\\/-acall-ajmp"
8833
8834 \end_inset
8835
8836  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8837  acall/ajmp.
8838  Only use this option if your code is in the same 2k block of memory.
8839  You may need to use this option for some 8051 derivatives which lack the
8840  lcall/ljmp instructions..
8841 \end_layout
8842
8843 \begin_layout Standard
8844 \begin_inset VSpace bigskip
8845 \end_inset
8846
8847
8848 \end_layout
8849
8850 \begin_layout Subsection
8851 DS390 / DS400 Options
8852 \begin_inset LatexCommand index
8853 name "Options DS390"
8854
8855 \end_inset
8856
8857
8858 \begin_inset LatexCommand index
8859 name "DS390"
8860
8861 \end_inset
8862
8863
8864 \end_layout
8865
8866 \begin_layout List
8867 \labelwidthstring 00.00.0000
8868
8869 \series bold
8870 -
8871 \begin_inset ERT
8872 status collapsed
8873
8874 \begin_layout Standard
8875
8876
8877 \backslash
8878 /
8879 \end_layout
8880
8881 \end_inset
8882
8883 -model-flat24
8884 \series default
8885
8886 \begin_inset LatexCommand index
8887 name "DS390!Options!-\\/-model-flat24"
8888
8889 \end_inset
8890
8891
8892 \size large
8893  
8894 \size default
8895 Generate 24-bit flat mode code.
8896  This is the one and only that the ds390 code generator supports right now
8897  and is default when using 
8898 \emph on
8899 -mds390
8900 \emph default
8901 .
8902  See section Memory Models for more details.
8903 \end_layout
8904
8905 \begin_layout List
8906 \labelwidthstring 00.00.0000
8907
8908 \series bold
8909 -
8910 \begin_inset ERT
8911 status collapsed
8912
8913 \begin_layout Standard
8914
8915
8916 \backslash
8917 /
8918 \end_layout
8919
8920 \end_inset
8921
8922 -protect-sp-update
8923 \begin_inset LatexCommand index
8924 name "DS390!Options!-\\/-protect-sp-update"
8925
8926 \end_inset
8927
8928
8929 \series default
8930  disable interrupts during ESP:SP updates.
8931 \end_layout
8932
8933 \begin_layout List
8934 \labelwidthstring 00.00.0000
8935
8936 \series bold
8937 -
8938 \begin_inset ERT
8939 status collapsed
8940
8941 \begin_layout Standard
8942
8943
8944 \backslash
8945 /
8946 \end_layout
8947
8948 \end_inset
8949
8950 -stack-10bit
8951 \series default
8952
8953 \begin_inset LatexCommand index
8954 name "DS390!Options!-\\/-stack-10bit"
8955
8956 \end_inset
8957
8958  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8959  This is the one and only that the ds390 code generator supports right now
8960  and is default when using 
8961 \emph on
8962 -mds390
8963 \emph default
8964 .
8965  In this mode, the stack is located in the lower 1K of the internal RAM,
8966  which is mapped to 0x400000.
8967  Note that the support is incomplete, since it still uses a single byte
8968  as the stack pointer.
8969  This means that only the lower 256 bytes of the potential 1K stack space
8970  will actually be used.
8971  However, this does allow you to reclaim the precious 256 bytes of low RAM
8972  for use for the DATA and IDATA segments.
8973  The compiler will not generate any code to put the processor into 10 bit
8974  stack mode.
8975  It is important to ensure that the processor is in this mode before calling
8976  any re-entrant functions compiled with this option.
8977  In principle, this should work with the 
8978 \emph on
8979 -
8980 \begin_inset ERT
8981 status collapsed
8982
8983 \begin_layout Standard
8984
8985
8986 \backslash
8987 /
8988 \end_layout
8989
8990 \end_inset
8991
8992 -stack-auto
8993 \begin_inset LatexCommand index
8994 name "-\\/-stack-auto"
8995
8996 \end_inset
8997
8998
8999 \emph default
9000  option, but that has not been tested.
9001  It is incompatible with the 
9002 \emph on
9003 -
9004 \begin_inset ERT
9005 status collapsed
9006
9007 \begin_layout Standard
9008
9009
9010 \backslash
9011 /
9012 \end_layout
9013
9014 \end_inset
9015
9016 -xstack
9017 \begin_inset LatexCommand index
9018 name "-\\/-xstack"
9019
9020 \end_inset
9021
9022
9023 \emph default
9024  option.
9025  It also only makes sense if the processor is in 24 bit contiguous addressing
9026  mode (see the 
9027 \emph on
9028 -
9029 \begin_inset ERT
9030 status collapsed
9031
9032 \begin_layout Standard
9033
9034
9035 \backslash
9036 /
9037 \end_layout
9038
9039 \end_inset
9040
9041 -model-flat24 option
9042 \emph default
9043 ).
9044 \series bold
9045
9046 \begin_inset Note Note
9047 status collapsed
9048
9049 \begin_layout List
9050 \labelwidthstring 00.00.0000
9051
9052 \series bold
9053 -
9054 \begin_inset ERT
9055 status open
9056
9057 \begin_layout Standard
9058
9059
9060 \backslash
9061 /
9062 \end_layout
9063
9064 \end_inset
9065
9066 -stack-8-bit - switches off the 10-bit mode
9067 \end_layout
9068
9069 \end_inset
9070
9071
9072 \end_layout
9073
9074 \begin_layout List
9075 \labelwidthstring 00.00.0000
9076
9077 \series bold
9078 -
9079 \begin_inset ERT
9080 status collapsed
9081
9082 \begin_layout Standard
9083
9084
9085 \backslash
9086 /
9087 \end_layout
9088
9089 \end_inset
9090
9091 -stack-probe
9092 \begin_inset LatexCommand index
9093 name "DS390!Options!-\\/-stack-probe"
9094
9095 \end_inset
9096
9097
9098 \series default
9099  insert call to function __stack_probe at each function prologue.
9100 \end_layout
9101
9102 \begin_layout List
9103 \labelwidthstring 00.00.0000
9104
9105 \series bold
9106 -
9107 \begin_inset ERT
9108 status open
9109
9110 \begin_layout Standard
9111
9112
9113 \backslash
9114 /
9115 \end_layout
9116
9117 \end_inset
9118
9119 -tini-libid
9120 \begin_inset LatexCommand index
9121 name "DS390!Options!-\\/-tini-libid"
9122
9123 \end_inset
9124
9125
9126 \series default
9127  <nnnn> LibraryID used in -mTININative.
9128  
9129 \end_layout
9130
9131 \begin_layout List
9132 \labelwidthstring 00.00.0000
9133
9134 \series bold
9135 -
9136 \begin_inset ERT
9137 status collapsed
9138
9139 \begin_layout Standard
9140
9141
9142 \backslash
9143 /
9144 \end_layout
9145
9146 \end_inset
9147
9148 -use-accelerator
9149 \begin_inset LatexCommand index
9150 name "DS390!Options!-\\/-use-accelerator"
9151
9152 \end_inset
9153
9154
9155 \series default
9156  generate code for DS390 Arithmetic Accelerator.
9157  
9158 \end_layout
9159
9160 \begin_layout Standard
9161 \begin_inset VSpace bigskip
9162 \end_inset
9163
9164
9165 \end_layout
9166
9167 \begin_layout Subsection
9168 Z80 Options
9169 \begin_inset LatexCommand index
9170 name "Options Z80"
9171
9172 \end_inset
9173
9174
9175 \begin_inset LatexCommand index
9176 name "Z80"
9177
9178 \end_inset
9179
9180
9181 \end_layout
9182
9183 \begin_layout List
9184 \labelwidthstring 00.00.0000
9185
9186 \series bold
9187 -
9188 \begin_inset ERT
9189 status collapsed
9190
9191 \begin_layout Standard
9192
9193
9194 \backslash
9195 /
9196 \end_layout
9197
9198 \end_inset
9199
9200 -callee-saves-bc
9201 \series default
9202
9203 \begin_inset LatexCommand index
9204 name "Z80!Options!-\\/-callee-saves-bc"
9205
9206 \end_inset
9207
9208
9209 \size large
9210  
9211 \size default
9212 Force a called function to always save BC.
9213 \end_layout
9214
9215 \begin_layout List
9216 \labelwidthstring 00.00.0000
9217
9218 \series bold
9219 -
9220 \begin_inset ERT
9221 status collapsed
9222
9223 \begin_layout Standard
9224
9225
9226 \backslash
9227 /
9228 \end_layout
9229
9230 \end_inset
9231
9232 -no-std-crt0
9233 \series default
9234
9235 \begin_inset LatexCommand index
9236 name "Z80!Options!-\\/-no-std-crt0"
9237
9238 \end_inset
9239
9240  When linking, skip the standard crt0.o object file.
9241  You must provide your own crt0.o for your system when linking.
9242 \end_layout
9243
9244 \begin_layout List
9245 \labelwidthstring 00.00.0000
9246
9247 \series bold
9248 -
9249 \begin_inset ERT
9250 status collapsed
9251
9252 \begin_layout Standard
9253
9254
9255 \backslash
9256 /
9257 \end_layout
9258
9259 \end_inset
9260
9261 -portmode=
9262 \series default
9263 <Value>
9264 \begin_inset LatexCommand index
9265 name "Z80!Options!-\\/-portmode=<Value>"
9266
9267 \end_inset
9268
9269  Determinate PORT I/O mode (<Value> is z80 or z180).
9270 \end_layout
9271
9272 \begin_layout List
9273 \labelwidthstring 00.00.0000
9274
9275 \series bold
9276 -
9277 \begin_inset ERT
9278 status collapsed
9279
9280 \begin_layout Standard
9281
9282
9283 \backslash
9284 /
9285 \end_layout
9286
9287 \end_inset
9288
9289 -asm=
9290 \series default
9291 <Value>
9292 \begin_inset LatexCommand index
9293 name "Z80!Options!-\\/-asm=<Value>"
9294
9295 \end_inset
9296
9297  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9298 \end_layout
9299
9300 \begin_layout List
9301 \labelwidthstring 00.00.0000
9302
9303 \series bold
9304 -
9305 \begin_inset ERT
9306 status collapsed
9307
9308 \begin_layout Standard
9309
9310
9311 \backslash
9312 /
9313 \end_layout
9314
9315 \end_inset
9316
9317 -codeseg
9318 \series default
9319 \InsetSpace ~
9320 <Value>
9321 \begin_inset LatexCommand index
9322 name "Z80!Options!-\\/-codeseg <Value>"
9323
9324 \end_inset
9325
9326  Use <Value> for the code segment name.
9327 \end_layout
9328
9329 \begin_layout List
9330 \labelwidthstring 00.00.0000
9331
9332 \series bold
9333 -
9334 \begin_inset ERT
9335 status collapsed
9336
9337 \begin_layout Standard
9338
9339
9340 \backslash
9341 /
9342 \end_layout
9343
9344 \end_inset
9345
9346 -constseg
9347 \series default
9348 \InsetSpace ~
9349 <Value>
9350 \begin_inset LatexCommand index
9351 name "Z80!Options!-\\/-constseg <Value>"
9352
9353 \end_inset
9354
9355  Use <Value> for the const segment name.
9356 \end_layout
9357
9358 \begin_layout List
9359 \labelwidthstring 00.00.0000
9360 \begin_inset VSpace bigskip
9361 \end_inset
9362
9363
9364 \end_layout
9365
9366 \begin_layout Subsection
9367 GBZ80 Options
9368 \begin_inset LatexCommand index
9369 name "Options GBZ80"
9370
9371 \end_inset
9372
9373
9374 \begin_inset LatexCommand index
9375 name "GBZ80"
9376
9377 \end_inset
9378
9379
9380 \end_layout
9381
9382 \begin_layout List
9383 \labelwidthstring 00.00.0000
9384
9385 \series bold
9386 -
9387 \begin_inset ERT
9388 status collapsed
9389
9390 \begin_layout Standard
9391
9392
9393 \backslash
9394 /
9395 \end_layout
9396
9397 \end_inset
9398
9399 -callee-saves-bc
9400 \series default
9401
9402 \begin_inset LatexCommand index
9403 name "GBZ80!Options!-\\/-callee-saves-bc"
9404
9405 \end_inset
9406
9407
9408 \size large
9409  
9410 \size default
9411 Force a called function to always save BC.
9412 \end_layout
9413
9414 \begin_layout List
9415 \labelwidthstring 00.00.0000
9416
9417 \series bold
9418 -
9419 \begin_inset ERT
9420 status collapsed
9421
9422 \begin_layout Standard
9423
9424
9425 \backslash
9426 /
9427 \end_layout
9428
9429 \end_inset
9430
9431 -no-std-crt0
9432 \series default
9433
9434 \begin_inset LatexCommand index
9435 name "Z80!Options!-\\/-no-std-crt0"
9436
9437 \end_inset
9438
9439  When linking, skip the standard crt0.o object file.
9440  You must provide your own crt0.o for your system when linking.
9441 \end_layout
9442
9443 \begin_layout List
9444 \labelwidthstring 00.00.0000
9445
9446 \series bold
9447 -bo
9448 \series default
9449 \InsetSpace ~
9450 <Num>
9451 \begin_inset LatexCommand index
9452 name "GBZ80!Options!-bo <Num>"
9453
9454 \end_inset
9455
9456  Use code bank <Num>.
9457 \end_layout
9458
9459 \begin_layout List
9460 \labelwidthstring 00.00.0000
9461
9462 \series bold
9463 -ba
9464 \series default
9465 \InsetSpace ~
9466 <Num>
9467 \begin_inset LatexCommand index
9468 name "GBZ80!Options!-ba <Num>"
9469
9470 \end_inset
9471
9472  Use data bank <Num>.
9473 \end_layout
9474
9475 \begin_layout List
9476 \labelwidthstring 00.00.0000
9477
9478 \series bold
9479 -
9480 \begin_inset ERT
9481 status collapsed
9482
9483 \begin_layout Standard
9484
9485
9486 \backslash
9487 /
9488 \end_layout
9489
9490 \end_inset
9491
9492 -codeseg
9493 \series default
9494 \InsetSpace ~
9495 <Value>
9496 \begin_inset LatexCommand index
9497 name "GBZ80!Options!-\\/-codeseg <Value>"
9498
9499 \end_inset
9500
9501  Use <Value> for the code segment name.
9502 \end_layout
9503
9504 \begin_layout List
9505 \labelwidthstring 00.00.0000
9506
9507 \series bold
9508 -
9509 \begin_inset ERT
9510 status collapsed
9511
9512 \begin_layout Standard
9513
9514
9515 \backslash
9516 /
9517 \end_layout
9518
9519 \end_inset
9520
9521 -constseg
9522 \series default
9523 \InsetSpace ~
9524 <Value>
9525 \begin_inset LatexCommand index
9526 name "GBZ80!Options!-\\/-constseg <Value>"
9527
9528 \end_inset
9529
9530  Use <Value> for the const segment name.
9531 \end_layout
9532
9533 \begin_layout Standard
9534 \begin_inset VSpace bigskip
9535 \end_inset
9536
9537
9538 \end_layout
9539
9540 \begin_layout Subsection
9541 Optimization Options
9542 \begin_inset LatexCommand index
9543 name "Options optimization"
9544
9545 \end_inset
9546
9547
9548 \begin_inset LatexCommand index
9549 name "Optimization options"
9550
9551 \end_inset
9552
9553
9554 \end_layout
9555
9556 \begin_layout List
9557 \labelwidthstring 00.00.0000
9558
9559 \series bold
9560 -
9561 \begin_inset ERT
9562 status collapsed
9563
9564 \begin_layout Standard
9565
9566
9567 \backslash
9568 /
9569 \end_layout
9570
9571 \end_inset
9572
9573 -nogcse
9574 \begin_inset LatexCommand index
9575 name "-\\/-nogcse"
9576
9577 \end_inset
9578
9579
9580 \series default
9581  Will not do global subexpression elimination, this option may be used when
9582  the compiler creates undesirably large stack/data spaces to store compiler
9583  temporaries (
9584 \emph on
9585 s
9586 \emph default
9587 pill 
9588 \emph on
9589 loc
9590 \emph default
9591 ations, sloc
9592 \begin_inset LatexCommand index
9593 name "sloc (spill location)"
9594
9595 \end_inset
9596
9597 ).
9598  A warning message will be generated when this happens and the compiler
9599  will indicate the number of extra bytes it allocated.
9600  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9601 nogcse
9602 \begin_inset LatexCommand index
9603 name "\\#pragma nogcse"
9604
9605 \end_inset
9606
9607  can be used to turn off global subexpression elimination
9608 \begin_inset LatexCommand index
9609 name "Subexpression elimination"
9610
9611 \end_inset
9612
9613  for a given function only.
9614 \end_layout
9615
9616 \begin_layout List
9617 \labelwidthstring 00.00.0000
9618
9619 \series bold
9620 -
9621 \begin_inset ERT
9622 status collapsed
9623
9624 \begin_layout Standard
9625
9626
9627 \backslash
9628 /
9629 \end_layout
9630
9631 \end_inset
9632
9633 -noinvariant
9634 \begin_inset LatexCommand index
9635 name "-\\/-noinvariant"
9636
9637 \end_inset
9638
9639
9640 \series default
9641  Will not do loop invariant optimizations, this may be turned off for reasons
9642  explained for the previous option.
9643  For more details of loop optimizations performed see Loop Invariants in
9644  section 
9645 \begin_inset LatexCommand ref
9646 reference "sub:Loop-Optimizations"
9647
9648 \end_inset
9649
9650 .
9651  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9652 noinvariant
9653 \begin_inset LatexCommand index
9654 name "\\#pragma noinvariant"
9655
9656 \end_inset
9657
9658  can be used to turn off invariant optimizations for a given function only.
9659 \end_layout
9660
9661 \begin_layout List
9662 \labelwidthstring 00.00.0000
9663
9664 \series bold
9665 -
9666 \begin_inset ERT
9667 status collapsed
9668
9669 \begin_layout Standard
9670
9671
9672 \backslash
9673 /
9674 \end_layout
9675
9676 \end_inset
9677
9678 -noinduction
9679 \begin_inset LatexCommand index
9680 name "-\\/-noinduction"
9681
9682 \end_inset
9683
9684
9685 \series default
9686  Will not do loop induction optimizations, see section strength reduction
9687  for more details.
9688  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9689 noinduction
9690 \begin_inset LatexCommand index
9691 name "\\#pragma noinduction"
9692
9693 \end_inset
9694
9695  can be used to turn off induction optimizations for a given function only.
9696 \end_layout
9697
9698 \begin_layout List
9699 \labelwidthstring 00.00.0000
9700
9701 \series bold
9702 -
9703 \begin_inset ERT
9704 status collapsed
9705
9706 \begin_layout Standard
9707
9708
9709 \backslash
9710 /
9711 \end_layout
9712
9713 \end_inset
9714
9715 -nojtbound
9716 \begin_inset LatexCommand index
9717 name "-\\/-nojtbound"
9718
9719 \end_inset
9720
9721
9722 \size large
9723  
9724 \series default
9725 \size default
9726  Will not generate boundary condition check when switch statements
9727 \begin_inset LatexCommand index
9728 name "switch statement"
9729
9730 \end_inset
9731
9732  are implemented using jump-tables.
9733  See section 
9734 \begin_inset LatexCommand ref
9735 reference "sub:'switch'-Statements"
9736
9737 \end_inset
9738
9739 \InsetSpace ~
9740 Switch Statements for more details.
9741  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9742 nojtbound
9743 \begin_inset LatexCommand index
9744 name "\\#pragma nojtbound"
9745
9746 \end_inset
9747
9748  can be used to turn off boundary checking for jump tables for a given function
9749  only.
9750 \end_layout
9751
9752 \begin_layout List
9753 \labelwidthstring 00.00.0000
9754
9755 \series bold
9756 -
9757 \begin_inset ERT
9758 status collapsed
9759
9760 \begin_layout Standard
9761
9762
9763 \backslash
9764 /
9765 \end_layout
9766
9767 \end_inset
9768
9769 -noloopreverse
9770 \begin_inset LatexCommand index
9771 name "-\\/-noloopreverse"
9772
9773 \end_inset
9774
9775
9776 \series default
9777 \size large
9778  
9779 \size default
9780 Will not do loop reversal 
9781 \begin_inset LatexCommand index
9782 name "Loop reversing"
9783
9784 \end_inset
9785
9786 optimization.
9787 \end_layout
9788
9789 \begin_layout List
9790 \labelwidthstring 00.00.0000
9791 -
9792 \begin_inset ERT
9793 status collapsed
9794
9795 \begin_layout Standard
9796
9797
9798 \backslash
9799 /
9800 \end_layout
9801
9802 \end_inset
9803
9804 -
9805 \series bold
9806 nolabelopt
9807 \series default
9808  
9809 \begin_inset LatexCommand index
9810 name "-\\/-nolabelopt "
9811
9812 \end_inset
9813
9814 Will not optimize labels (makes the dumpfiles more readable).
9815 \end_layout
9816
9817 \begin_layout List
9818 \labelwidthstring 00.00.0000
9819
9820 \series bold
9821 -
9822 \begin_inset ERT
9823 status collapsed
9824
9825 \begin_layout Standard
9826
9827
9828 \backslash
9829 /
9830 \end_layout
9831
9832 \end_inset
9833
9834 -no-xinit-opt
9835 \begin_inset LatexCommand index
9836 name "-\\/-no-xinit-opt"
9837
9838 \end_inset
9839
9840
9841 \series default
9842  Will not memcpy initialized data from code space into xdata space.
9843  This saves a few bytes in code space if you don't have initialized data
9844 \begin_inset LatexCommand index
9845 name "Variable initialization"
9846
9847 \end_inset
9848
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 -nooverlay
9870 \begin_inset LatexCommand index
9871 name "-\\/-nooverlay"
9872
9873 \end_inset
9874
9875
9876 \series default
9877   The compiler will not overlay parameters and local variables of any function,
9878  see section Parameters and local variables for more details.
9879 \end_layout
9880
9881 \begin_layout List
9882 \labelwidthstring 00.00.0000
9883
9884 \series bold
9885 -
9886 \begin_inset ERT
9887 status collapsed
9888
9889 \begin_layout Standard
9890
9891
9892 \backslash
9893 /
9894 \end_layout
9895
9896 \end_inset
9897
9898 -no-peep
9899 \begin_inset LatexCommand index
9900 name "-\\/-no-peep"
9901
9902 \end_inset
9903
9904
9905 \series default
9906  Disable peep-hole optimization with built-in rules.
9907 \end_layout
9908
9909 \begin_layout List
9910 \labelwidthstring 00.00.0000
9911
9912 \series bold
9913 -
9914 \begin_inset ERT
9915 status collapsed
9916
9917 \begin_layout Standard
9918
9919
9920 \backslash
9921 /
9922 \end_layout
9923
9924 \end_inset
9925
9926 -peep-file
9927 \series default
9928
9929 \begin_inset LatexCommand index
9930 name "-\\/-peep-file"
9931
9932 \end_inset
9933
9934 \InsetSpace ~
9935 <filename> This option can be used to use additional rules to be used by
9936  the peep hole optimizer.
9937  See section 
9938 \begin_inset LatexCommand ref
9939 reference "sub:Peephole-Optimizer"
9940
9941 \end_inset
9942
9943 \InsetSpace ~
9944 Peep Hole optimizations for details on how to write these rules.
9945 \end_layout
9946
9947 \begin_layout List
9948 \labelwidthstring 00.00.0000
9949
9950 \series bold
9951 -
9952 \begin_inset ERT
9953 status collapsed
9954
9955 \begin_layout Standard
9956
9957
9958 \backslash
9959 /
9960 \end_layout
9961
9962 \end_inset
9963
9964 -peep-asm
9965 \begin_inset LatexCommand index
9966 name "-\\/-peep-asm"
9967
9968 \end_inset
9969
9970
9971 \series default
9972  Pass the inline assembler code through the peep hole optimizer.
9973  This can cause unexpected changes to inline assembler code, please go through
9974  the peephole optimizer
9975 \begin_inset LatexCommand index
9976 name "Peephole optimizer"
9977
9978 \end_inset
9979
9980  rules defined in the source file tree '<target>/peeph.def' before using
9981  this option.
9982 \end_layout
9983
9984 \begin_layout List
9985 \labelwidthstring 00.00.0000
9986
9987 \series bold
9988 -
9989 \begin_inset ERT
9990 status collapsed
9991
9992 \begin_layout Standard
9993
9994
9995 \backslash
9996 /
9997 \end_layout
9998
9999 \end_inset
10000
10001 -opt-code-speed
10002 \begin_inset LatexCommand index
10003 name "-\\/-opt-code-speed"
10004
10005 \end_inset
10006
10007
10008 \series default
10009  The compiler will optimize code generation towards fast code, possibly
10010  at the expense of code size.
10011 \end_layout
10012
10013 \begin_layout List
10014 \labelwidthstring 00.00.0000
10015
10016 \series bold
10017 -
10018 \begin_inset ERT
10019 status collapsed
10020
10021 \begin_layout Standard
10022
10023
10024 \backslash
10025 /
10026 \end_layout
10027
10028 \end_inset
10029
10030 -opt-code-size
10031 \begin_inset LatexCommand index
10032 name "-\\/-opt-code-size"
10033
10034 \end_inset
10035
10036
10037 \series default
10038  The compiler will optimize code generation towards compact code, possibly
10039  at the expense of code speed.
10040 \end_layout
10041
10042 \begin_layout Standard
10043 \begin_inset VSpace bigskip
10044 \end_inset
10045
10046
10047 \end_layout
10048
10049 \begin_layout Subsection
10050 Other Options
10051 \begin_inset LatexCommand index
10052 name "Options other"
10053
10054 \end_inset
10055
10056
10057 \end_layout
10058
10059 \begin_layout List
10060 \labelwidthstring 00.00.0000
10061
10062 \series bold
10063 -c\InsetSpace ~
10064 -
10065 \begin_inset ERT
10066 status collapsed
10067
10068 \begin_layout Standard
10069
10070
10071 \backslash
10072 /
10073 \end_layout
10074
10075 \end_inset
10076
10077 -compile-only
10078 \begin_inset LatexCommand index
10079 name "-\\/-compile-only"
10080
10081 \end_inset
10082
10083
10084 \begin_inset LatexCommand index
10085 name "-c -\\/-compile-only"
10086
10087 \end_inset
10088
10089
10090 \series default
10091  will compile and assemble the source, but will not call the linkage editor.
10092 \end_layout
10093
10094 \begin_layout List
10095 \labelwidthstring 00.00.0000
10096
10097 \series bold
10098 -
10099 \series default
10100
10101 \begin_inset ERT
10102 status collapsed
10103
10104 \begin_layout Standard
10105
10106
10107 \backslash
10108 /
10109 \end_layout
10110
10111 \end_inset
10112
10113
10114 \series bold
10115 -c1mode
10116 \begin_inset LatexCommand index
10117 name "-\\/-c1mode"
10118
10119 \end_inset
10120
10121
10122 \series default
10123  reads the preprocessed source from standard input and compiles it.
10124  The file name for the assembler output must be specified using the -o option.
10125 \end_layout
10126
10127 \begin_layout List
10128 \labelwidthstring 00.00.0000
10129
10130 \series bold
10131 -E
10132 \begin_inset LatexCommand index
10133 name "-E"
10134
10135 \end_inset
10136
10137
10138 \series default
10139  Run only the C preprocessor.
10140  Preprocess all the C source files specified and output the results to standard
10141  output.
10142 \end_layout
10143
10144 \begin_layout List
10145 \labelwidthstring 00.00.0000
10146
10147 \series bold
10148 -o\InsetSpace ~
10149 <path/file>
10150 \begin_inset LatexCommand index
10151 name "-o <path/file>"
10152
10153 \end_inset
10154
10155
10156 \series default
10157  The output path where everything will be placed or the file name used for
10158  all generated output files.
10159  If the parameter is a path, it must have a trailing slash (or backslash
10160  for the Windows binaries) to be recognized as a path.
10161  Note for Windows users: if the path contains spaces, it should be surrounded
10162  by quotes.
10163  The trailing backslash should be doubled in order to prevent escaping the
10164  final quote, for example: 
10165 \emph on
10166 -o 
10167 \begin_inset Quotes sld
10168 \end_inset
10169
10170 F:
10171 \backslash
10172 Projects
10173 \backslash
10174 test3
10175 \backslash
10176 output 1
10177 \backslash
10178
10179 \backslash
10180
10181 \begin_inset Quotes srd
10182 \end_inset
10183
10184
10185 \emph default
10186  or put after the final quote, for example: 
10187 \emph on
10188 -o 
10189 \begin_inset Quotes sld
10190 \end_inset
10191
10192 F:
10193 \backslash
10194 Projects
10195 \backslash
10196 test3
10197 \backslash
10198 output 1
10199 \begin_inset Quotes srd
10200 \end_inset
10201
10202
10203 \backslash
10204
10205 \emph default
10206 .
10207  The path using slashes for directory delimiters can be used too, for example:
10208  
10209 \emph on
10210 -o 
10211 \begin_inset Quotes sld
10212 \end_inset
10213
10214 F:/Projects/test3/output 1/
10215 \begin_inset Quotes srd
10216 \end_inset
10217
10218
10219 \emph default
10220 .
10221 \end_layout
10222
10223 \begin_layout List
10224 \labelwidthstring 00.00.0000
10225
10226 \series bold
10227 -
10228 \begin_inset ERT
10229 status collapsed
10230
10231 \begin_layout Standard
10232
10233
10234 \backslash
10235 /
10236 \end_layout
10237
10238 \end_inset
10239
10240 -stack-auto
10241 \begin_inset LatexCommand index
10242 name "-\\/-stack-auto"
10243
10244 \end_inset
10245
10246
10247 \series default
10248 \size large
10249  
10250 \size default
10251 All functions in the source file will be compiled as 
10252 \emph on
10253 reentrant
10254 \emph default
10255
10256 \begin_inset LatexCommand index
10257 name "reentrant"
10258
10259 \end_inset
10260
10261 , i.e.
10262  the parameters and local variables will be allocated on the stack
10263 \begin_inset LatexCommand index
10264 name "stack"
10265
10266 \end_inset
10267
10268 .
10269  See section 
10270 \begin_inset LatexCommand ref
10271 reference "sec:Parameters-and-Local-Variables"
10272
10273 \end_inset
10274
10275  Parameters and Local Variables for more details.
10276  If this option is used all source files in the project should be compiled
10277  with this option.
10278  It automatically implies -
10279 \series bold
10280
10281 \begin_inset ERT
10282 status open
10283
10284 \begin_layout Standard
10285
10286
10287 \backslash
10288 /
10289 \end_layout
10290
10291 \end_inset
10292
10293
10294 \series default
10295 -int-long-reent and -
10296 \series bold
10297
10298 \begin_inset ERT
10299 status open
10300
10301 \begin_layout Standard
10302
10303
10304 \backslash
10305 /
10306 \end_layout
10307
10308 \end_inset
10309
10310
10311 \series default
10312 -float-reent.
10313  
10314 \end_layout
10315
10316 \begin_layout List
10317 \labelwidthstring 00.00.0000
10318
10319 \series bold
10320 -
10321 \begin_inset ERT
10322 status collapsed
10323
10324 \begin_layout Standard
10325
10326
10327 \backslash
10328 /
10329 \end_layout
10330
10331 \end_inset
10332
10333 -callee-saves
10334 \begin_inset LatexCommand index
10335 name "-\\/-callee-saves"
10336
10337 \end_inset
10338
10339  
10340 \begin_inset LatexCommand label
10341 name "lyx:--callee-saves-function1[,function2][,function3]..."
10342
10343 \end_inset
10344
10345 function1[,function2][,function3]....
10346
10347 \series default
10348  The compiler by default uses a caller saves convention for register saving
10349  across function calls, however this can cause unnecessary register pushing
10350  and popping when calling small functions from larger functions.
10351  This option can be used to switch the register saving convention for the
10352  function names specified.
10353  The compiler will not save registers when calling these functions, no extra
10354  code will be generated at the entry and exit (function prologue
10355 \series bold
10356
10357 \begin_inset LatexCommand index
10358 name "function prologue"
10359
10360 \end_inset
10361
10362
10363 \series default
10364  and epilogue
10365 \series bold
10366
10367 \begin_inset LatexCommand index
10368 name "function epilogue"
10369
10370 \end_inset
10371
10372
10373 \series default
10374 ) for these functions to save and restore the registers used by these functions,
10375  this can SUBSTANTIALLY reduce code and improve run time performance of
10376  the generated code.
10377  In the future the compiler (with inter procedural analysis) will be able
10378  to determine the appropriate scheme to use for each function call.
10379  DO NOT use this option for built-in functions such as _mulint..., if this
10380  option is used for a library function the appropriate library function
10381  needs to be recompiled with the same option.
10382  If the project consists of multiple source files then all the source file
10383  should be compiled with the same -
10384 \begin_inset ERT
10385 status collapsed
10386
10387 \begin_layout Standard
10388
10389
10390 \backslash
10391 /
10392 \end_layout
10393
10394 \end_inset
10395
10396 -callee-saves option string.
10397  Also see #pragma\InsetSpace ~
10398 callee_saves 
10399 \begin_inset LatexCommand index
10400 name "\\#pragma callee\\_saves"
10401
10402 \end_inset
10403
10404  
10405 \begin_inset LatexCommand vpageref
10406 reference "ite:callee_saves-function1[,function2[,function3...]]--"
10407
10408 \end_inset
10409
10410 .
10411 \end_layout
10412
10413 \begin_layout List
10414 \labelwidthstring 00.00.0000
10415
10416 \series bold
10417 -
10418 \begin_inset ERT
10419 status collapsed
10420
10421 \begin_layout Standard
10422
10423
10424 \backslash
10425 /
10426 \end_layout
10427
10428 \end_inset
10429
10430 -all-callee-saves
10431 \begin_inset LatexCommand index
10432 name "-\\/-all-callee-saves"
10433
10434 \end_inset
10435
10436
10437 \series default
10438  Function of -
10439 \begin_inset ERT
10440 status collapsed
10441
10442 \begin_layout Standard
10443
10444
10445 \backslash
10446 /
10447 \end_layout
10448
10449 \end_inset
10450
10451 -callee-saves will be applied to all functions by default.
10452 \end_layout
10453
10454 \begin_layout List
10455 \labelwidthstring 00.00.0000
10456
10457 \series bold
10458 -
10459 \begin_inset ERT
10460 status collapsed
10461
10462 \begin_layout Standard
10463
10464
10465 \backslash
10466 /
10467 \end_layout
10468
10469 \end_inset
10470
10471 -debug
10472 \begin_inset LatexCommand index
10473 name "-\\/-debug"
10474
10475 \end_inset
10476
10477  
10478 \series default
10479 When this option is used the compiler will generate debug information.
10480  The debug information collected in a file with .cdb extension can be used
10481  with the SDCDB.
10482  For more information see documentation for SDCDB.
10483  Another file with no extension contains debug information in AOMF or AOMF51
10484 \begin_inset LatexCommand index
10485 name "AOMF, AOMF51"
10486
10487 \end_inset
10488
10489  format which is commonly used by third party tools.
10490 \end_layout
10491
10492 \begin_layout List
10493 \labelwidthstring 00.00.0000
10494
10495 \series bold
10496 -S
10497 \begin_inset LatexCommand index
10498 name "-S"
10499
10500 \end_inset
10501
10502
10503 \series default
10504 \size large
10505  
10506 \size default
10507 Stop after the stage of compilation proper; do not assemble.
10508  The output is an assembler code file for the input file specified.
10509 \end_layout
10510
10511 \begin_layout List
10512 \labelwidthstring 00.00.0000
10513
10514 \series bold
10515 -
10516 \begin_inset ERT
10517 status collapsed
10518
10519 \begin_layout Standard
10520
10521
10522 \backslash
10523 /
10524 \end_layout
10525
10526 \end_inset
10527
10528 -int-long-reent
10529 \begin_inset LatexCommand index
10530 name "-\\/-int-long-reent"
10531
10532 \end_inset
10533
10534
10535 \series default
10536  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10537  Note by default these libraries are compiled as non-reentrant.
10538  See section Installation for more details.
10539 \end_layout
10540
10541 \begin_layout List
10542 \labelwidthstring 00.00.0000
10543
10544 \series bold
10545 -
10546 \begin_inset ERT
10547 status collapsed
10548
10549 \begin_layout Standard
10550
10551
10552 \backslash
10553 /
10554 \end_layout
10555
10556 \end_inset
10557
10558 -cyclomatic
10559 \begin_inset LatexCommand index
10560 name "-\\/-cyclomatic"
10561
10562 \end_inset
10563
10564  
10565 \series default
10566 This option will cause the compiler to generate an information message for
10567  each function in the source file.
10568  The message contains some 
10569 \emph on
10570 important
10571 \emph default
10572  information about the function.
10573  The number of edges and nodes the compiler detected in the control flow
10574  graph of the function, and most importantly the 
10575 \emph on
10576 cyclomatic complexity
10577 \begin_inset LatexCommand index
10578 name "Cyclomatic complexity"
10579
10580 \end_inset
10581
10582
10583 \emph default
10584  see section on Cyclomatic Complexity for more details.
10585 \end_layout
10586
10587 \begin_layout List
10588 \labelwidthstring 00.00.0000
10589
10590 \series bold
10591 -
10592 \begin_inset ERT
10593 status collapsed
10594
10595 \begin_layout Standard
10596
10597
10598 \backslash
10599 /
10600 \end_layout
10601
10602 \end_inset
10603
10604 -float-reent
10605 \begin_inset LatexCommand index
10606 name "-\\/-float-reent"
10607
10608 \end_inset
10609
10610
10611 \series default
10612  Floating point library is compiled as reentrant
10613 \begin_inset LatexCommand index
10614 name "reentrant"
10615
10616 \end_inset
10617
10618 .
10619  See section Installation for more details.
10620 \end_layout
10621
10622 \begin_layout List
10623 \labelwidthstring 00.00.0000
10624
10625 \series bold
10626 -
10627 \begin_inset ERT
10628 status collapsed
10629
10630 \begin_layout Standard
10631
10632
10633 \backslash
10634 /
10635 \end_layout
10636
10637 \end_inset
10638
10639 -funsigned-char
10640 \begin_inset LatexCommand index
10641 name "-\\/-funsigned-char"
10642
10643 \end_inset
10644
10645
10646 \series default
10647  The default signedness for every type is 
10648 \family typewriter
10649 signed
10650 \family default
10651 .
10652  In some embedded environments the default signedness of 
10653 \family typewriter
10654 char
10655 \family default
10656  is 
10657 \family typewriter
10658 unsigned
10659 \family default
10660 .
10661  To set the signess for characters to unsigned, use the option -
10662 \series bold
10663
10664 \begin_inset ERT
10665 status open
10666
10667 \begin_layout Standard
10668
10669
10670 \backslash
10671 /
10672 \end_layout
10673
10674 \end_inset
10675
10676
10677 \series default
10678 -funsigned-char.
10679  If this option is set and no signedness keyword (unsigned/signed) is given,
10680  a char will be signed.
10681  All other types are unaffected.
10682 \end_layout
10683
10684 \begin_layout List
10685 \labelwidthstring 00.00.0000
10686
10687 \series bold
10688 -
10689 \begin_inset ERT
10690 status collapsed
10691
10692 \begin_layout Standard
10693
10694
10695 \backslash
10696 /
10697 \end_layout
10698
10699 \end_inset
10700
10701 -main-return
10702 \begin_inset LatexCommand index
10703 name "-\\/-main-return"
10704
10705 \end_inset
10706
10707
10708 \series default
10709  This option can be used if the code generated is called by a monitor program
10710  or if the main routine includes an endless loop.
10711  This option results in slightly smaller code and saves two bytes of stack
10712  space.
10713  The return from the 'main'
10714 \begin_inset LatexCommand index
10715 name "main return"
10716
10717 \end_inset
10718
10719  function will return to the function calling main.
10720  The default setting is to lock up i.e.
10721  generate a '
10722 \family typewriter
10723 sjmp .
10724 \family default
10725 '.
10726 \end_layout
10727
10728 \begin_layout List
10729 \labelwidthstring 00.00.0000
10730
10731 \series bold
10732 -
10733 \begin_inset ERT
10734 status collapsed
10735
10736 \begin_layout Standard
10737
10738
10739 \backslash
10740 /
10741 \end_layout
10742
10743 \end_inset
10744
10745 -nostdinc
10746 \begin_inset LatexCommand index
10747 name "-\\/-nostdinc"
10748
10749 \end_inset
10750
10751
10752 \series default
10753  This will prevent the compiler from passing on the default include path
10754  to the preprocessor.
10755 \end_layout
10756
10757 \begin_layout List
10758 \labelwidthstring 00.00.0000
10759
10760 \series bold
10761 -
10762 \begin_inset ERT
10763 status collapsed
10764
10765 \begin_layout Standard
10766
10767
10768 \backslash
10769 /
10770 \end_layout
10771
10772 \end_inset
10773
10774 -nostdlib
10775 \begin_inset LatexCommand index
10776 name "-\\/-nostdlib"
10777
10778 \end_inset
10779
10780
10781 \series default
10782  This will prevent the compiler from passing on the default library
10783 \begin_inset LatexCommand index
10784 name "Libraries"
10785
10786 \end_inset
10787
10788  path to the linker.
10789 \end_layout
10790
10791 \begin_layout List
10792 \labelwidthstring 00.00.0000
10793
10794 \series bold
10795 -
10796 \begin_inset ERT
10797 status collapsed
10798
10799 \begin_layout Standard
10800
10801
10802 \backslash
10803 /
10804 \end_layout
10805
10806 \end_inset
10807
10808 -verbose
10809 \begin_inset LatexCommand index
10810 name "-\\/-verbose"
10811
10812 \end_inset
10813
10814
10815 \series default
10816  Shows the various actions the compiler is performing.
10817 \end_layout
10818
10819 \begin_layout List
10820 \labelwidthstring 00.00.0000
10821
10822 \series bold
10823 -V
10824 \begin_inset LatexCommand index
10825 name "-V"
10826
10827 \end_inset
10828
10829
10830 \series default
10831  Shows the actual commands the compiler is executing.
10832 \end_layout
10833
10834 \begin_layout List
10835 \labelwidthstring 00.00.0000
10836
10837 \series bold
10838 -
10839 \begin_inset ERT
10840 status collapsed
10841
10842 \begin_layout Standard
10843
10844
10845 \backslash
10846 /
10847 \end_layout
10848
10849 \end_inset
10850
10851 -no-c-code-in-asm
10852 \begin_inset LatexCommand index
10853 name "-\\/-no-c-code-in-asm"
10854
10855 \end_inset
10856
10857
10858 \series default
10859  Hides your ugly and inefficient c-code from the asm file, so you can always
10860  blame the compiler :)
10861 \end_layout
10862
10863 \begin_layout List
10864 \labelwidthstring 00.00.0000
10865
10866 \series bold
10867 -
10868 \begin_inset ERT
10869 status collapsed
10870
10871 \begin_layout Standard
10872
10873
10874 \backslash
10875 /
10876 \end_layout
10877
10878 \end_inset
10879
10880 -fverbose-asm
10881 \begin_inset LatexCommand index
10882 name "-\\/-no-gen-comments"
10883
10884 \end_inset
10885
10886
10887 \series default
10888  Include code generator and peep-hole comments in the generated asm files.
10889 \end_layout
10890
10891 \begin_layout List
10892 \labelwidthstring 00.00.0000
10893
10894 \series bold
10895 -
10896 \begin_inset ERT
10897 status collapsed
10898
10899 \begin_layout Standard
10900
10901
10902 \backslash
10903 /
10904 \end_layout
10905
10906 \end_inset
10907
10908 -no-peep-comments
10909 \begin_inset LatexCommand index
10910 name "-\\/-no-peep-comments"
10911
10912 \end_inset
10913
10914
10915 \series default
10916  Don't include peep-hole comments in the generated asm files even if -
10917 \series bold
10918
10919 \begin_inset ERT
10920 status open
10921
10922 \begin_layout Standard
10923
10924
10925 \backslash
10926 /
10927 \end_layout
10928
10929 \end_inset
10930
10931
10932 \series default
10933 -fverbose-asm option is specified.
10934 \end_layout
10935
10936 \begin_layout List
10937 \labelwidthstring 00.00.0000
10938
10939 \series bold
10940 -
10941 \begin_inset ERT
10942 status collapsed
10943
10944 \begin_layout Standard
10945
10946
10947 \backslash
10948 /
10949 \end_layout
10950
10951 \end_inset
10952
10953 -i-code-in-asm
10954 \begin_inset LatexCommand index
10955 name "-\\/-i-code-in-asm"
10956
10957 \end_inset
10958
10959
10960 \series default
10961  Include i-codes in the asm file.
10962  Sounds like noise but is most helpful for debugging the compiler itself.
10963 \end_layout
10964
10965 \begin_layout List
10966 \labelwidthstring 00.00.0000
10967
10968 \series bold
10969 -
10970 \begin_inset ERT
10971 status collapsed
10972
10973 \begin_layout Standard
10974
10975
10976 \backslash
10977 /
10978 \end_layout
10979
10980 \end_inset
10981
10982 -less-pedantic
10983 \begin_inset LatexCommand index
10984 name "pedantic"
10985
10986 \end_inset
10987
10988
10989 \begin_inset LatexCommand index
10990 name "-\\/-less-pedantic"
10991
10992 \end_inset
10993
10994
10995 \series default
10996
10997 \begin_inset LatexCommand label
10998 name "lyx:--less-pedantic"
10999
11000 \end_inset
11001
11002  Disable some of the more pedantic warnings
11003 \begin_inset LatexCommand index
11004 name "Warnings"
11005
11006 \end_inset
11007
11008 .
11009  For more details, see the less_pedantic pragma 
11010 \begin_inset LatexCommand vpageref
11011 reference "ite:less_pedantic"
11012
11013 \end_inset
11014
11015 .
11016 \end_layout
11017
11018 \begin_layout List
11019 \labelwidthstring 00.00.0000
11020
11021 \series bold
11022 -
11023 \begin_inset ERT
11024 status collapsed
11025
11026 \begin_layout Standard
11027
11028
11029 \backslash
11030 /
11031 \end_layout
11032
11033 \end_inset
11034
11035 -disable-warning\InsetSpace ~
11036 <nnnn>
11037 \begin_inset LatexCommand index
11038 name "-\\/-disable-warning"
11039
11040 \end_inset
11041
11042
11043 \series default
11044  Disable specific warning with number <nnnn>.
11045 \end_layout
11046
11047 \begin_layout List
11048 \labelwidthstring 00.00.0000
11049
11050 \series bold
11051 -
11052 \begin_inset ERT
11053 status collapsed
11054
11055 \begin_layout Standard
11056
11057
11058 \backslash
11059 /
11060 \end_layout
11061
11062 \end_inset
11063
11064 -Werror
11065 \begin_inset LatexCommand index
11066 name "-\\/-Werror"
11067
11068 \end_inset
11069
11070
11071 \series default
11072  Treat all warnings as errors.
11073 \end_layout
11074
11075 \begin_layout List
11076 \labelwidthstring 00.00.0000
11077
11078 \series bold
11079 -
11080 \begin_inset ERT
11081 status collapsed
11082
11083 \begin_layout Standard
11084
11085
11086 \backslash
11087 /
11088 \end_layout
11089
11090 \end_inset
11091
11092 -print-search-dirs
11093 \begin_inset LatexCommand index
11094 name "-\\/-print-search-dirs"
11095
11096 \end_inset
11097
11098
11099 \series default
11100  Display the directories in the compiler's search path
11101 \end_layout
11102
11103 \begin_layout List
11104 \labelwidthstring 00.00.0000
11105
11106 \series bold
11107 -
11108 \begin_inset ERT
11109 status collapsed
11110
11111 \begin_layout Standard
11112
11113
11114 \backslash
11115 /
11116 \end_layout
11117
11118 \end_inset
11119
11120 -vc
11121 \begin_inset LatexCommand index
11122 name "-\\/-vc"
11123
11124 \end_inset
11125
11126
11127 \series default
11128  Display errors and warnings using MSVC style, so you can use SDCC with
11129  the visual studio IDE
11130 \begin_inset LatexCommand index
11131 name "IDE"
11132
11133 \end_inset
11134
11135 .
11136  With SDCC both offering a GCC-like (the default) and a MSVC-like
11137 \begin_inset LatexCommand index
11138 name "MSVC output style"
11139
11140 \end_inset
11141
11142  output style, integration into most programming editors should be straightforwa
11143 rd.
11144 \end_layout
11145
11146 \begin_layout List
11147 \labelwidthstring 00.00.0000
11148
11149 \series bold
11150 -
11151 \begin_inset ERT
11152 status collapsed
11153
11154 \begin_layout Standard
11155
11156
11157 \backslash
11158 /
11159 \end_layout
11160
11161 \end_inset
11162
11163 -use-stdout
11164 \begin_inset LatexCommand index
11165 name "-\\/-use-stdout"
11166
11167 \end_inset
11168
11169
11170 \series default
11171  Send errors and warnings to stdout instead of stderr.
11172 \end_layout
11173
11174 \begin_layout List
11175 \labelwidthstring 00.00.0000
11176
11177 \series bold
11178 -Wa\InsetSpace ~
11179 asmOption[,asmOption]
11180 \series default
11181
11182 \begin_inset LatexCommand index
11183 name "-Wa asmOption[,asmOption]"
11184
11185 \end_inset
11186
11187 ...
11188  Pass the asmOption to the assembler
11189 \begin_inset LatexCommand index
11190 name "Options assembler"
11191
11192 \end_inset
11193
11194
11195 \begin_inset LatexCommand index
11196 name "Assembler options"
11197
11198 \end_inset
11199
11200 .
11201  See file sdcc/as/doc/asxhtm.html for assembler options.cd
11202 \end_layout
11203
11204 \begin_layout List
11205 \labelwidthstring 00.00.0000
11206
11207 \series bold
11208 -
11209 \begin_inset ERT
11210 status collapsed
11211
11212 \begin_layout Standard
11213
11214
11215 \backslash
11216 /
11217 \end_layout
11218
11219 \end_inset
11220
11221 -std-sdcc89
11222 \begin_inset LatexCommand index
11223 name "-\\/-std-sdcc89"
11224
11225 \end_inset
11226
11227
11228 \series default
11229  Generally follow the C89 standard, but allow SDCC features that conflict
11230  with the standard (default).
11231 \end_layout
11232
11233 \begin_layout List
11234 \labelwidthstring 00.00.0000
11235
11236 \series bold
11237 -
11238 \begin_inset ERT
11239 status collapsed
11240
11241 \begin_layout Standard
11242
11243
11244 \backslash
11245 /
11246 \end_layout
11247
11248 \end_inset
11249
11250 -std-c89
11251 \begin_inset LatexCommand index
11252 name "-\\/-std-c89"
11253
11254 \end_inset
11255
11256
11257 \series default
11258  Follow the C89 standard and disable SDCC features that conflict with the
11259  standard.
11260 \end_layout
11261
11262 \begin_layout List
11263 \labelwidthstring 00.00.0000
11264
11265 \series bold
11266 -
11267 \begin_inset ERT
11268 status collapsed
11269
11270 \begin_layout Standard
11271
11272
11273 \backslash
11274 /
11275 \end_layout
11276
11277 \end_inset
11278
11279 -std-sdcc99
11280 \begin_inset LatexCommand index
11281 name "-\\/-std-sdcc99"
11282
11283 \end_inset
11284
11285
11286 \series default
11287  Generally follow the C99 standard, but allow SDCC features that conflict
11288  with the standard (incomplete support).
11289 \end_layout
11290
11291 \begin_layout List
11292 \labelwidthstring 00.00.0000
11293
11294 \series bold
11295 -
11296 \begin_inset ERT
11297 status collapsed
11298
11299 \begin_layout Standard
11300
11301
11302 \backslash
11303 /
11304 \end_layout
11305
11306 \end_inset
11307
11308 -std-c99
11309 \begin_inset LatexCommand index
11310 name "-\\/-std-sdcc99"
11311
11312 \end_inset
11313
11314
11315 \series default
11316  Follow the C99 standard and disable SDCC features that conflict with the
11317  standard (incomplete support).
11318 \end_layout
11319
11320 \begin_layout List
11321 \labelwidthstring 00.00.0000
11322
11323 \series bold
11324 -
11325 \begin_inset ERT
11326 status collapsed
11327
11328 \begin_layout Standard
11329
11330
11331 \backslash
11332 /
11333 \end_layout
11334
11335 \end_inset
11336
11337 -codeseg
11338 \series default
11339
11340 \begin_inset LatexCommand index
11341 name "-\\/-codeseg <Value>"
11342
11343 \end_inset
11344
11345
11346 \begin_inset LatexCommand label
11347 name "lyx:-codeseg"
11348
11349 \end_inset
11350
11351 \InsetSpace ~
11352 <Name> The name to be used for the code
11353 \begin_inset LatexCommand index
11354 name "code"
11355
11356 \end_inset
11357
11358  segment, default CSEG.
11359  This is useful if you need to tell the compiler to put the code in a special
11360  segment so you can later on tell the linker to put this segment in a special
11361  place in memory.
11362  Can be used for instance when using bank switching to put the code in a
11363  bank.
11364 \end_layout
11365
11366 \begin_layout List
11367 \labelwidthstring 00.00.0000
11368
11369 \series bold
11370 -
11371 \begin_inset ERT
11372 status collapsed
11373
11374 \begin_layout Standard
11375
11376
11377 \backslash
11378 /
11379 \end_layout
11380
11381 \end_inset
11382
11383 -constseg
11384 \series default
11385
11386 \begin_inset LatexCommand index
11387 name "-\\/-constseg <Value>"
11388
11389 \end_inset
11390
11391 \InsetSpace ~
11392 <Name> The name to be used for the const
11393 \begin_inset LatexCommand index
11394 name "const"
11395
11396 \end_inset
11397
11398  segment, default CONST.
11399  This is useful if you need to tell the compiler to put the const data in
11400  a special segment so you can later on tell the linker to put this segment
11401  in a special place in memory.
11402  Can be used for instance when using bank switching to put the const data
11403  in a bank.
11404 \end_layout
11405
11406 \begin_layout List
11407 \labelwidthstring 00.00.0000
11408
11409 \series bold
11410 -
11411 \begin_inset ERT
11412 status collapsed
11413
11414 \begin_layout Standard
11415
11416
11417 \backslash
11418 /
11419 \end_layout
11420
11421 \end_inset
11422
11423 -fdollars-in-identifiers
11424 \begin_inset LatexCommand index
11425 name "-\\/-fdollars-in-identifiers"
11426
11427 \end_inset
11428
11429
11430 \series default
11431  Permit '$' as an identifier character.
11432 \end_layout
11433
11434 \begin_layout List
11435 \labelwidthstring 00.00.0000
11436
11437 \series bold
11438 -
11439 \begin_inset ERT
11440 status collapsed
11441
11442 \begin_layout Standard
11443
11444
11445 \backslash
11446 /
11447 \end_layout
11448
11449 \end_inset
11450
11451 -more-pedantic
11452 \series default
11453
11454 \begin_inset LatexCommand index
11455 name "-\\/-more-pedantic"
11456
11457 \end_inset
11458
11459
11460 \begin_inset LatexCommand index
11461 name "pedantic"
11462
11463 \end_inset
11464
11465  Actually this is 
11466 \series bold
11467 \emph on
11468 not
11469 \series default
11470 \emph default
11471  a SDCC compiler option but if you want 
11472 \emph on
11473 more
11474 \emph default
11475  warnings you can use a separate tool dedicated to syntax checking like
11476  splint
11477 \begin_inset LatexCommand label
11478 name "lyx:more-pedantic-SPLINT"
11479
11480 \end_inset
11481
11482
11483 \begin_inset LatexCommand index
11484 name "lint (syntax checking tool)"
11485
11486 \end_inset
11487
11488  
11489 \begin_inset LatexCommand url
11490 target "http://www.splint.org"
11491
11492 \end_inset
11493
11494 .
11495  To make your source files parseable by splint you will have to include
11496  
11497 \family sans
11498 lint.h
11499 \family default
11500
11501 \begin_inset LatexCommand index
11502 name "splint (syntax checking tool)"
11503
11504 \end_inset
11505
11506  in your source file and add brackets around extended keywords (like 
11507 \family sans
11508
11509 \begin_inset Quotes sld
11510 \end_inset
11511
11512 __at\InsetSpace ~
11513
11514 \series bold
11515 (
11516 \series default
11517 0xab
11518 \series bold
11519 )
11520 \series default
11521
11522 \begin_inset Quotes srd
11523 \end_inset
11524
11525
11526 \family default
11527  and 
11528 \family sans
11529
11530 \begin_inset Quotes sld
11531 \end_inset
11532
11533 __interrupt\InsetSpace ~
11534 (2)
11535 \begin_inset Quotes srd
11536 \end_inset
11537
11538
11539 \family default
11540 ).
11541  
11542 \newline
11543 Splint has an excellent on line manual at 
11544 \begin_inset LatexCommand url
11545 target "http://www.splint.org/manual/"
11546
11547 \end_inset
11548
11549  and it's capabilities go beyond pure syntax checking.
11550  You'll need to tell splint the location of SDCC's include files so a typical
11551  command line could look like this: 
11552 \newline
11553
11554 \family sans
11555 splint\InsetSpace ~
11556 -I\InsetSpace ~
11557 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11558 \InsetSpace ~
11559 myprogram.c
11560 \end_layout
11561
11562 \begin_layout List
11563 \labelwidthstring 00.00.0000
11564
11565 \series bold
11566 -
11567 \begin_inset ERT
11568 status collapsed
11569
11570 \begin_layout Standard
11571
11572
11573 \backslash
11574 /
11575 \end_layout
11576
11577 \end_inset
11578
11579 -short-is-8bits
11580 \series default
11581
11582 \begin_inset LatexCommand index
11583 name "-\\/-short-is-8bits"
11584
11585 \end_inset
11586
11587
11588 \begin_inset LatexCommand label
11589 name "lyx:--short-is-8bits"
11590
11591 \end_inset
11592
11593  Treat short as 8-bit (for backward compatibility with older versions of
11594  compiler - see section 
11595 \begin_inset LatexCommand ref
11596 reference "sec:Compatibility-with-previous"
11597
11598 \end_inset
11599
11600 )
11601 \end_layout
11602
11603 \begin_layout Standard
11604 \begin_inset VSpace bigskip
11605 \end_inset
11606
11607
11608 \end_layout
11609
11610 \begin_layout Subsection
11611 Intermediate Dump Options
11612 \begin_inset LatexCommand label
11613 name "sub:Intermediate-Dump-Options"
11614
11615 \end_inset
11616
11617
11618 \begin_inset LatexCommand index
11619 name "Options intermediate dump"
11620
11621 \end_inset
11622
11623
11624 \begin_inset LatexCommand index
11625 name "Intermediate dump options"
11626
11627 \end_inset
11628
11629
11630 \end_layout
11631
11632 \begin_layout Standard
11633 The following options are provided for the purpose of retargetting and debugging
11634  the compiler.
11635  They provide a means to dump the intermediate code (iCode
11636 \begin_inset LatexCommand index
11637 name "iCode"
11638
11639 \end_inset
11640
11641 ) generated by the compiler in human readable form at various stages of
11642  the compilation process.
11643  More on iCodes see chapter 
11644 \begin_inset LatexCommand ref
11645 reference "sub:The-anatomy-of"
11646
11647 \end_inset
11648
11649  
11650 \begin_inset Quotes srd
11651 \end_inset
11652
11653 The anatomy of the compiler
11654 \begin_inset Quotes srd
11655 \end_inset
11656
11657 .
11658 \end_layout
11659
11660 \begin_layout List
11661 \labelwidthstring 00.00.0000
11662
11663 \series bold
11664 -
11665 \begin_inset ERT
11666 status collapsed
11667
11668 \begin_layout Standard
11669
11670
11671 \backslash
11672 /
11673 \end_layout
11674
11675 \end_inset
11676
11677 -dumpraw
11678 \begin_inset LatexCommand index
11679 name "-\\/-dumpraw"
11680
11681 \end_inset
11682
11683
11684 \series default
11685  This option will cause the compiler to dump the intermediate code into
11686  a file of named 
11687 \emph on
11688 <source filename>.dumpraw
11689 \emph default
11690  just after the intermediate code has been generated for a function, i.e.
11691  before any optimizations are done.
11692  The basic blocks
11693 \begin_inset LatexCommand index
11694 name "Basic blocks"
11695
11696 \end_inset
11697
11698  at this stage ordered in the depth first number, so they may not be in
11699  sequence of execution.
11700 \end_layout
11701
11702 \begin_layout List
11703 \labelwidthstring 00.00.0000
11704
11705 \series bold
11706 -
11707 \begin_inset ERT
11708 status collapsed
11709
11710 \begin_layout Standard
11711
11712
11713 \backslash
11714 /
11715 \end_layout
11716
11717 \end_inset
11718
11719 -dumpgcse
11720 \begin_inset LatexCommand index
11721 name "-\\/-dumpgcse"
11722
11723 \end_inset
11724
11725
11726 \series default
11727  Will create a dump of iCodes, after global subexpression elimination
11728 \begin_inset LatexCommand index
11729 name "Global subexpression elimination"
11730
11731 \end_inset
11732
11733 , into a file named 
11734 \emph on
11735 <source filename>.dumpgcse.
11736 \end_layout
11737
11738 \begin_layout List
11739 \labelwidthstring 00.00.0000
11740
11741 \series bold
11742 -
11743 \begin_inset ERT
11744 status collapsed
11745
11746 \begin_layout Standard
11747
11748
11749 \backslash
11750 /
11751 \end_layout
11752
11753 \end_inset
11754
11755 -dumpdeadcode
11756 \begin_inset LatexCommand index
11757 name "-\\/-dumpdeadcode"
11758
11759 \end_inset
11760
11761
11762 \series default
11763  Will create a dump of iCodes, after deadcode elimination
11764 \begin_inset LatexCommand index
11765 name "Dead-code elimination"
11766
11767 \end_inset
11768
11769 , into a file named 
11770 \emph on
11771 <source filename>.dumpdeadcode.
11772 \end_layout
11773
11774 \begin_layout List
11775 \labelwidthstring 00.00.0000
11776
11777 \series bold
11778 -
11779 \begin_inset ERT
11780 status collapsed
11781
11782 \begin_layout Standard
11783
11784
11785 \backslash
11786 /
11787 \end_layout
11788
11789 \end_inset
11790
11791 -dumploop
11792 \begin_inset LatexCommand index
11793 name "-\\/-dumploop"
11794
11795 \end_inset
11796
11797
11798 \series default
11799 \size large
11800  
11801 \size default
11802 Will create a dump of iCodes, after loop optimizations
11803 \begin_inset LatexCommand index
11804 name "Loop optimization"
11805
11806 \end_inset
11807
11808 , into a file named 
11809 \emph on
11810 <source filename>.dumploop.
11811 \end_layout
11812
11813 \begin_layout List
11814 \labelwidthstring 00.00.0000
11815
11816 \series bold
11817 -
11818 \begin_inset ERT
11819 status collapsed
11820
11821 \begin_layout Standard
11822
11823
11824 \backslash
11825 /
11826 \end_layout
11827
11828 \end_inset
11829
11830 -dumprange
11831 \begin_inset LatexCommand index
11832 name "-\\/-dumprange"
11833
11834 \end_inset
11835
11836
11837 \series default
11838 \size large
11839  
11840 \size default
11841 Will create a dump of iCodes, after live range analysis
11842 \begin_inset LatexCommand index
11843 name "Live range analysis"
11844
11845 \end_inset
11846
11847 , into a file named 
11848 \emph on
11849 <source filename>.dumprange.
11850 \end_layout
11851
11852 \begin_layout List
11853 \labelwidthstring 00.00.0000
11854
11855 \series bold
11856 -
11857 \begin_inset ERT
11858 status collapsed
11859
11860 \begin_layout Standard
11861
11862
11863 \backslash
11864 /
11865 \end_layout
11866
11867 \end_inset
11868
11869 -dumlrange
11870 \begin_inset LatexCommand index
11871 name "-\\/-dumlrange"
11872
11873 \end_inset
11874
11875
11876 \series default
11877  Will dump the life ranges
11878 \begin_inset LatexCommand index
11879 name "Live range analysis"
11880
11881 \end_inset
11882
11883  for all symbols.
11884 \end_layout
11885
11886 \begin_layout List
11887 \labelwidthstring 00.00.0000
11888
11889 \series bold
11890 -
11891 \begin_inset ERT
11892 status collapsed
11893
11894 \begin_layout Standard
11895
11896
11897 \backslash
11898 /
11899 \end_layout
11900
11901 \end_inset
11902
11903 -dumpregassign
11904 \begin_inset LatexCommand index
11905 name "-\\/-dumpregassign"
11906
11907 \end_inset
11908
11909  
11910 \series default
11911 Will create a dump of iCodes, after register assignment
11912 \begin_inset LatexCommand index
11913 name "Register assignment"
11914
11915 \end_inset
11916
11917 , into a file named 
11918 \emph on
11919 <source filename>.dumprassgn.
11920 \end_layout
11921
11922 \begin_layout List
11923 \labelwidthstring 00.00.0000
11924
11925 \series bold
11926 -
11927 \begin_inset ERT
11928 status collapsed
11929
11930 \begin_layout Standard
11931
11932
11933 \backslash
11934 /
11935 \end_layout
11936
11937 \end_inset
11938
11939 -dumplrange
11940 \begin_inset LatexCommand index
11941 name "-\\/-dumplrange"
11942
11943 \end_inset
11944
11945
11946 \series default
11947  Will create a dump of the live ranges of iTemp's
11948 \end_layout
11949
11950 \begin_layout List
11951 \labelwidthstring 00.00.0000
11952
11953 \series bold
11954 -
11955 \begin_inset ERT
11956 status collapsed
11957
11958 \begin_layout Standard
11959
11960
11961 \backslash
11962 /
11963 \end_layout
11964
11965 \end_inset
11966
11967 -dumpall
11968 \begin_inset LatexCommand index
11969 name "-\\/-dumpall"
11970
11971 \end_inset
11972
11973
11974 \size large
11975  
11976 \series default
11977 \size default
11978 Will cause all the above mentioned dumps to be created.
11979 \end_layout
11980
11981 \begin_layout Standard
11982 \begin_inset VSpace bigskip
11983 \end_inset
11984
11985
11986 \end_layout
11987
11988 \begin_layout Subsection
11989 Redirecting output on Windows Shells
11990 \end_layout
11991
11992 \begin_layout Standard
11993 By default SDCC writes its error messages to 
11994 \begin_inset Quotes sld
11995 \end_inset
11996
11997 standard error
11998 \begin_inset Quotes srd
11999 \end_inset
12000
12001 .
12002  To force all messages to 
12003 \begin_inset Quotes sld
12004 \end_inset
12005
12006 standard output
12007 \begin_inset Quotes srd
12008 \end_inset
12009
12010  use 
12011 \series bold
12012 -
12013 \series default
12014 \emph on
12015
12016 \begin_inset ERT
12017 status collapsed
12018
12019 \begin_layout Standard
12020
12021
12022 \backslash
12023 /
12024 \end_layout
12025
12026 \end_inset
12027
12028
12029 \series bold
12030 \emph default
12031 -
12032 \series default
12033 use-stdout
12034 \begin_inset LatexCommand index
12035 name "-\\/-use-stdout"
12036
12037 \end_inset
12038
12039 .
12040  Additionally, if you happen to have visual studio installed in your windows
12041  machine, you can use it to compile your sources using a custom build and
12042  the SDCC -
12043 \emph on
12044
12045 \begin_inset ERT
12046 status collapsed
12047
12048 \begin_layout Standard
12049
12050
12051 \backslash
12052 /
12053 \end_layout
12054
12055 \end_inset
12056
12057
12058 \emph default
12059 -vc
12060 \begin_inset LatexCommand index
12061 name "-\\/-vc"
12062
12063 \end_inset
12064
12065  option.
12066  Something like this should work:
12067 \newline
12068
12069 \newline
12070
12071 \series bold
12072 c:
12073 \backslash
12074 sdcc
12075 \backslash
12076 bin
12077 \backslash
12078 sdcc.exe -
12079 \series default
12080 \emph on
12081
12082 \begin_inset ERT
12083 status collapsed
12084
12085 \begin_layout Standard
12086
12087
12088 \backslash
12089 /
12090 \end_layout
12091
12092 \end_inset
12093
12094
12095 \series bold
12096 \emph default
12097 -vc -
12098 \series default
12099 \emph on
12100
12101 \begin_inset ERT
12102 status collapsed
12103
12104 \begin_layout Standard
12105
12106
12107 \backslash
12108 /
12109 \end_layout
12110
12111 \end_inset
12112
12113
12114 \series bold
12115 \emph default
12116 -model-large -c $(InputPath)
12117 \series default
12118
12119 \begin_inset VSpace bigskip
12120 \end_inset
12121
12122
12123 \end_layout
12124
12125 \begin_layout Section
12126 Environment variables
12127 \begin_inset LatexCommand index
12128 name "Environment variables"
12129
12130 \end_inset
12131
12132
12133 \end_layout
12134
12135 \begin_layout Standard
12136 SDCC recognizes the following environment variables:
12137 \end_layout
12138
12139 \begin_layout List
12140 \labelwidthstring 00.00.0000
12141
12142 \series bold
12143 SDCC_LEAVE_SIGNALS
12144 \begin_inset LatexCommand index
12145 name "SDCC\\_LEAVE\\_SIGNALS"
12146
12147 \end_inset
12148
12149
12150 \series default
12151  SDCC installs a signal handler
12152 \begin_inset LatexCommand index
12153 name "signal handler"
12154
12155 \end_inset
12156
12157  to be able to delete temporary files after an user break (^C) or an exception.
12158  If this environment variable is set, SDCC won't install the signal handler
12159  in order to be able to debug SDCC.
12160 \end_layout
12161
12162 \begin_layout List
12163 \labelwidthstring 00.00.0000
12164
12165 \series bold
12166 TMP,\InsetSpace ~
12167 TEMP,\InsetSpace ~
12168 TMPDIR
12169 \begin_inset LatexCommand index
12170 name "TMP, TEMP, TMPDIR"
12171
12172 \end_inset
12173
12174
12175 \series default
12176  Path, where temporary files will be created.
12177  The order of the variables is the search order.
12178  In a standard *nix environment these variables are not set, and there's
12179  no need to set them.
12180  On Windows it's recommended to set one of them.
12181 \end_layout
12182
12183 \begin_layout List
12184 \labelwidthstring 00.00.0000
12185
12186 \series bold
12187 SDCC_HOME
12188 \begin_inset LatexCommand index
12189 name "SDCC\\_HOME"
12190
12191 \end_inset
12192
12193
12194 \series default
12195  Path, see section 
12196 \begin_inset LatexCommand ref
12197 reference "sub:Install-paths"
12198
12199 \end_inset
12200
12201 \InsetSpace ~
12202
12203 \begin_inset Quotes sld
12204 \end_inset
12205
12206  Install Paths
12207 \begin_inset Quotes srd
12208 \end_inset
12209
12210 .
12211 \end_layout
12212
12213 \begin_layout List
12214 \labelwidthstring 00.00.0000
12215
12216 \series bold
12217 SDCC_INCLUDE
12218 \begin_inset LatexCommand index
12219 name "SDCC\\_INCLUDE"
12220
12221 \end_inset
12222
12223
12224 \series default
12225  Path, see section 
12226 \begin_inset LatexCommand ref
12227 reference "sub:Search-Paths"
12228
12229 \end_inset
12230
12231 \InsetSpace ~
12232
12233 \begin_inset Quotes sld
12234 \end_inset
12235
12236 Search Paths
12237 \begin_inset Quotes srd
12238 \end_inset
12239
12240 .
12241 \end_layout
12242
12243 \begin_layout List
12244 \labelwidthstring 00.00.0000
12245
12246 \series bold
12247 SDCC_LIB
12248 \begin_inset LatexCommand index
12249 name "SDCC\\_LIB"
12250
12251 \end_inset
12252
12253
12254 \series default
12255  Path, see section 
12256 \begin_inset LatexCommand ref
12257 reference "sub:Search-Paths"
12258
12259 \end_inset
12260
12261 \InsetSpace ~
12262
12263 \begin_inset Quotes sld
12264 \end_inset
12265
12266 Search Paths
12267 \begin_inset Quotes srd
12268 \end_inset
12269
12270 ..
12271 \end_layout
12272
12273 \begin_layout Standard
12274 There are some more environment variables recognized by SDCC, but these
12275  are solely used for debugging purposes.
12276  They can change or disappear very quickly, and will never be documented.
12277 \begin_inset VSpace bigskip
12278 \end_inset
12279
12280
12281 \end_layout
12282
12283 \begin_layout Section
12284 Storage Class Language Extensions
12285 \end_layout
12286
12287 \begin_layout Subsection
12288 MCS51/DS390 Storage Class
12289 \begin_inset LatexCommand index
12290 name "Storage class"
12291
12292 \end_inset
12293
12294  Language Extensions
12295 \end_layout
12296
12297 \begin_layout Standard
12298 In addition to the ANSI storage classes SDCC allows the following MCS51
12299  specific storage classes:
12300 \end_layout
12301
12302 \begin_layout Subsubsection
12303 data
12304 \begin_inset LatexCommand index
12305 name "data (mcs51, ds390 storage class)"
12306
12307 \end_inset
12308
12309
12310 \begin_inset LatexCommand index
12311 name "\\_\\_data (mcs51, ds390 storage class)"
12312
12313 \end_inset
12314
12315  / near
12316 \begin_inset LatexCommand index
12317 name "near (storage class)"
12318
12319 \end_inset
12320
12321
12322 \begin_inset LatexCommand index
12323 name "\\_\\_near (storage class)"
12324
12325 \end_inset
12326
12327
12328 \end_layout
12329
12330 \begin_layout Standard
12331 This is the 
12332 \series bold
12333 default
12334 \series default
12335  storage class for the Small Memory model (
12336 \emph on
12337 data
12338 \emph default
12339  and 
12340 \emph on
12341 near
12342 \emph default
12343  or the more ANSI-C compliant forms 
12344 \emph on
12345 __data
12346 \emph default
12347  and 
12348 \emph on
12349 __near
12350 \emph default
12351  can be used synonymously).
12352  Variables declared with this storage class will be allocated in the directly
12353  addressable portion of the internal RAM of a 8051, e.g.:
12354 \end_layout
12355
12356 \begin_layout Verse
12357
12358 \family typewriter
12359 __data unsigned char test_data;
12360 \end_layout
12361
12362 \begin_layout Standard
12363 Writing 0x01 to this variable generates the assembly code:
12364 \end_layout
12365
12366 \begin_layout Verse
12367
12368 \family typewriter
12369 75*00 01\InsetSpace ~
12370 \InsetSpace ~
12371 \InsetSpace ~
12372 mov\InsetSpace ~
12373 \InsetSpace ~
12374 _test_data,#0x01
12375 \end_layout
12376
12377 \begin_layout Subsubsection
12378 xdata
12379 \begin_inset LatexCommand index
12380 name "xdata (mcs51, ds390 storage class)"
12381
12382 \end_inset
12383
12384
12385 \begin_inset LatexCommand index
12386 name "\\_\\_xdata (mcs51, ds390 storage class)"
12387
12388 \end_inset
12389
12390  / far
12391 \begin_inset LatexCommand index
12392 name "far (storage class)"
12393
12394 \end_inset
12395
12396
12397 \begin_inset LatexCommand index
12398 name "\\_\\_far (storage class)"
12399
12400 \end_inset
12401
12402
12403 \end_layout
12404
12405 \begin_layout Standard
12406 Variables declared with this storage class will be placed in the external
12407  RAM.
12408  This is the 
12409 \series bold
12410 default
12411 \series default
12412  storage class for the Large Memory model, e.g.:
12413 \end_layout
12414
12415 \begin_layout Verse
12416
12417 \family typewriter
12418 __xdata unsigned char test_xdata;
12419 \end_layout
12420
12421 \begin_layout Standard
12422 Writing 0x01 to this variable generates the assembly code:
12423 \end_layout
12424
12425 \begin_layout Verse
12426
12427 \family typewriter
12428 90s00r00\InsetSpace ~
12429 \InsetSpace ~
12430 \InsetSpace ~
12431 mov\InsetSpace ~
12432 \InsetSpace ~
12433 dptr,#_test_xdata 
12434 \newline
12435 74\InsetSpace ~
12436 01\InsetSpace ~
12437 \InsetSpace ~
12438 \InsetSpace ~
12439 \InsetSpace ~
12440 \InsetSpace ~
12441 \InsetSpace ~
12442 mov\InsetSpace ~
12443 \InsetSpace ~
12444 a,#0x01 
12445 \newline
12446 F0\InsetSpace ~
12447 \InsetSpace ~
12448 \InsetSpace ~
12449 \InsetSpace ~
12450 \InsetSpace ~
12451 \InsetSpace ~
12452 \InsetSpace ~
12453 \InsetSpace ~
12454 \InsetSpace ~
12455 movx\InsetSpace ~
12456 @dptr,a 
12457 \end_layout
12458
12459 \begin_layout Subsubsection
12460 idata
12461 \begin_inset LatexCommand index
12462 name "idata (mcs51, ds390 storage class)"
12463
12464 \end_inset
12465
12466
12467 \begin_inset LatexCommand index
12468 name "\\_\\_idata (mcs51, ds390 storage class)"
12469
12470 \end_inset
12471
12472
12473 \end_layout
12474
12475 \begin_layout Standard
12476 Variables declared with this storage class will be allocated into the indirectly
12477  addressable portion of the internal ram of a 8051, e.g.:
12478 \end_layout
12479
12480 \begin_layout Verse
12481
12482 \family typewriter
12483 __idata unsigned char test_idata;
12484 \end_layout
12485
12486 \begin_layout Standard
12487 Writing 0x01 to this variable generates the assembly code:
12488 \end_layout
12489
12490 \begin_layout Verse
12491
12492 \family typewriter
12493 78r00\InsetSpace ~
12494 \InsetSpace ~
12495 \InsetSpace ~
12496 \InsetSpace ~
12497 \InsetSpace ~
12498 \InsetSpace ~
12499 \InsetSpace ~
12500 mov\InsetSpace ~
12501 \InsetSpace ~
12502 r0,#_test_idata
12503 \newline
12504 76\InsetSpace ~
12505 01\InsetSpace ~
12506 \InsetSpace ~
12507 \InsetSpace ~
12508 \InsetSpace ~
12509 \InsetSpace ~
12510 \InsetSpace ~
12511 \InsetSpace ~
12512 mov\InsetSpace ~
12513 \InsetSpace ~
12514 @r0,#0x01
12515 \end_layout
12516
12517 \begin_layout Standard
12518 Please note, the first 128 byte of idata physically access the same RAM
12519  as the data memory.
12520  The original 8051 had 128 byte idata memory, nowadays most devices have
12521  256 byte idata memory.
12522  The stack
12523 \begin_inset LatexCommand index
12524 name "stack"
12525
12526 \end_inset
12527
12528  is located in idata memory.
12529 \end_layout
12530
12531 \begin_layout Subsubsection
12532 pdata
12533 \begin_inset LatexCommand index
12534 name "pdata (mcs51, ds390 storage class)"
12535
12536 \end_inset
12537
12538
12539 \begin_inset LatexCommand index
12540 name "\\_\\_pdata (mcs51, ds390 storage class)"
12541
12542 \end_inset
12543
12544
12545 \end_layout
12546
12547 \begin_layout Standard
12548 Paged xdata access is just as straightforward as using the other addressing
12549  modes of a 8051.
12550  It is typically located at the start of xdata and has a maximum size of
12551  256 bytes.
12552  The following example writes 0x01 to the pdata variable.
12553  Please note, pdata access physically accesses xdata memory.
12554  The high byte of the address is determined by port P2 
12555 \begin_inset LatexCommand index
12556 name "P2 (mcs51 sfr)"
12557
12558 \end_inset
12559
12560 (or in case of some 8051 variants by a separate Special Function Register,
12561  see section 
12562 \begin_inset LatexCommand ref
12563 reference "sub:MCS51-variants"
12564
12565 \end_inset
12566
12567 ).
12568  This is the 
12569 \series bold
12570 default
12571 \series default
12572  storage class for the Medium Memory model, e.g.:
12573 \end_layout
12574
12575 \begin_layout Verse
12576
12577 \family typewriter
12578 __pdata unsigned char test_pdata;
12579 \end_layout
12580
12581 \begin_layout Standard
12582 Writing 0x01 to this variable generates the assembly code:
12583 \end_layout
12584
12585 \begin_layout Verse
12586
12587 \family typewriter
12588 78r00\InsetSpace ~
12589 \InsetSpace ~
12590 \InsetSpace ~
12591 \InsetSpace ~
12592 \InsetSpace ~
12593 \InsetSpace ~
12594 mov r0,#_test_pdata
12595 \newline
12596 74 01\InsetSpace ~
12597 \InsetSpace ~
12598 \InsetSpace ~
12599 \InsetSpace ~
12600 \InsetSpace ~
12601 \InsetSpace ~
12602 mov a,#0x01 
12603 \newline
12604 F2\InsetSpace ~
12605 \InsetSpace ~
12606 \InsetSpace ~
12607 \InsetSpace ~
12608 \InsetSpace ~
12609 \InsetSpace ~
12610 \InsetSpace ~
12611 \InsetSpace ~
12612 \InsetSpace ~
12613 movx @r0,a
12614 \end_layout
12615
12616 \begin_layout Standard
12617 If the -
12618 \begin_inset ERT
12619 status collapsed
12620
12621 \begin_layout Standard
12622
12623
12624 \backslash
12625 /
12626 \end_layout
12627
12628 \end_inset
12629
12630 -xstack
12631 \begin_inset LatexCommand index
12632 name "-\\/-xstack"
12633
12634 \end_inset
12635
12636  option is used the pdata memory area is followed by the xstack memory area
12637  and the sum of their sizes is limited to 256 bytes.
12638 \end_layout
12639
12640 \begin_layout Subsubsection
12641 code
12642 \begin_inset LatexCommand index
12643 name "code"
12644
12645 \end_inset
12646
12647
12648 \begin_inset LatexCommand index
12649 name "\\_\\_code"
12650
12651 \end_inset
12652
12653
12654 \end_layout
12655
12656 \begin_layout Standard
12657 'Variables' declared with this storage class will be placed in the code
12658  memory:
12659 \end_layout
12660
12661 \begin_layout Verse
12662
12663 \family typewriter
12664 __code unsigned char test_code;
12665 \end_layout
12666
12667 \begin_layout Standard
12668 Read access to this variable generates the assembly code:
12669 \end_layout
12670
12671 \begin_layout Verse
12672
12673 \family typewriter
12674 90s00r6F\InsetSpace ~
12675 \InsetSpace ~
12676 \InsetSpace ~
12677 mov dptr,#_test_code
12678 \newline
12679 E4\InsetSpace ~
12680 \InsetSpace ~
12681 \InsetSpace ~
12682 \InsetSpace ~
12683 \InsetSpace ~
12684 \InsetSpace ~
12685 \InsetSpace ~
12686 \InsetSpace ~
12687 \InsetSpace ~
12688 clr a
12689 \newline
12690 93\InsetSpace ~
12691 \InsetSpace ~
12692 \InsetSpace ~
12693 \InsetSpace ~
12694 \InsetSpace ~
12695 \InsetSpace ~
12696 \InsetSpace ~
12697 \InsetSpace ~
12698 \InsetSpace ~
12699 movc a,@a+dptr 
12700 \end_layout
12701
12702 \begin_layout Standard
12703
12704 \family typewriter
12705 char
12706 \family default
12707  indexed arrays of characters in code memory can be accessed efficiently:
12708 \end_layout
12709
12710 \begin_layout Verse
12711
12712 \family typewriter
12713 __code char test_array[] = {'c','h','e','a','p'}; 
12714 \end_layout
12715
12716 \begin_layout Standard
12717 Read access to this array using an 8-bit unsigned index generates the assembly
12718  code:
12719 \end_layout
12720
12721 \begin_layout Verse
12722
12723 \family typewriter
12724 E5*00\InsetSpace ~
12725 \InsetSpace ~
12726 \InsetSpace ~
12727 \InsetSpace ~
12728 \InsetSpace ~
12729 \InsetSpace ~
12730 mov a,_index 
12731 \end_layout
12732
12733 \begin_layout Verse
12734
12735 \family typewriter
12736 90s00r41\InsetSpace ~
12737 \InsetSpace ~
12738 \InsetSpace ~
12739 mov dptr,#_test_array
12740 \end_layout
12741
12742 \begin_layout Verse
12743
12744 \family typewriter
12745 93\InsetSpace ~
12746 \InsetSpace ~
12747 \InsetSpace ~
12748 \InsetSpace ~
12749 \InsetSpace ~
12750 \InsetSpace ~
12751 \InsetSpace ~
12752 \InsetSpace ~
12753 \InsetSpace ~
12754 movc a,@a+dptr 
12755 \end_layout
12756
12757 \begin_layout Subsubsection
12758 bit
12759 \begin_inset LatexCommand index
12760 name "bit"
12761
12762 \end_inset
12763
12764
12765 \begin_inset LatexCommand index
12766 name "\\_\\_bit"
12767
12768 \end_inset
12769
12770
12771 \end_layout
12772
12773 \begin_layout Standard
12774 This is a data-type and a storage class specifier.
12775  When a variable is declared as a bit, it is allocated into the bit addressable
12776  memory of 8051, e.g.:
12777 \end_layout
12778
12779 \begin_layout Verse
12780
12781 \family typewriter
12782 __bit test_bit;
12783 \end_layout
12784
12785 \begin_layout Standard
12786 Writing 1 to this variable generates the assembly code:
12787 \end_layout
12788
12789 \begin_layout Verse
12790
12791 \family typewriter
12792 D2*00\InsetSpace ~
12793 \InsetSpace ~
12794 \InsetSpace ~
12795 \InsetSpace ~
12796 \InsetSpace ~
12797 \InsetSpace ~
12798 \InsetSpace ~
12799 setb\InsetSpace ~
12800 _test_bit
12801 \end_layout
12802
12803 \begin_layout Standard
12804 The bit addressable memory consists of 128 bits which are located from 0x20
12805  to 0x2f in data memory.
12806  
12807 \newline
12808 Apart from this 8051 specific storage class most architectures support
12809  ANSI-C bitfields
12810 \begin_inset LatexCommand index
12811 name "bitfields"
12812
12813 \end_inset
12814
12815
12816 \begin_inset Foot
12817 status open
12818
12819 \begin_layout Standard
12820 Not really meant as examples, but nevertheless showing what bitfields are
12821  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12822 \end_layout
12823
12824 \end_inset
12825
12826 .
12827  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12828  signed modifier are implemented as unsigned.
12829 \end_layout
12830
12831 \begin_layout Subsubsection
12832 sfr
12833 \begin_inset LatexCommand index
12834 name "sfr"
12835
12836 \end_inset
12837
12838
12839 \begin_inset LatexCommand index
12840 name "\\_\\_sfr"
12841
12842 \end_inset
12843
12844  / sfr16
12845 \begin_inset LatexCommand index
12846 name "sfr16"
12847
12848 \end_inset
12849
12850
12851 \begin_inset LatexCommand index
12852 name "\\_\\_sfr16"
12853
12854 \end_inset
12855
12856  / sfr32
12857 \begin_inset LatexCommand index
12858 name "sfr32"
12859
12860 \end_inset
12861
12862
12863 \begin_inset LatexCommand index
12864 name "\\_\\_sfr32"
12865
12866 \end_inset
12867
12868  / sbit
12869 \begin_inset LatexCommand index
12870 name "\\_\\_sbit"
12871
12872 \end_inset
12873
12874
12875 \begin_inset LatexCommand index
12876 name "sbit"
12877
12878 \end_inset
12879
12880
12881 \end_layout
12882
12883 \begin_layout Standard
12884 Like the bit keyword, 
12885 \emph on
12886 sfr / sfr16 / sfr32 / sbit
12887 \emph default
12888  signify both a data-type and storage class, they are used to describe the
12889  
12890 \emph on
12891 s
12892 \emph default
12893 pecial 
12894 \emph on
12895 f
12896 \emph default
12897 unction 
12898 \emph on
12899 r
12900 \emph default
12901 egisters and 
12902 \emph on
12903 s
12904 \emph default
12905 pecial 
12906 \emph on
12907 bit
12908 \emph default
12909  variables of a 8051, eg:
12910 \end_layout
12911
12912 \begin_layout Verse
12913
12914 \family typewriter
12915 __sfr __at
12916 \begin_inset LatexCommand index
12917 name "at"
12918
12919 \end_inset
12920
12921
12922 \begin_inset LatexCommand index
12923 name "\\_\\_at"
12924
12925 \end_inset
12926
12927  (0x80) P0;\InsetSpace ~
12928  /* special function register P0 at location 0x80 */
12929 \newline
12930
12931 \newline
12932 /* 16 bit
12933  special function register combination for timer 0
12934 \newline
12935 \InsetSpace ~
12936 \InsetSpace ~
12937  with the high byte at
12938  location 0x8C and the low byte at location 0x8A */
12939 \newline
12940 __sfr16 __at (0x8C8A)
12941  TMR0;
12942 \newline
12943
12944 \newline
12945 __sbit __at
12946 \begin_inset LatexCommand index
12947 name "at"
12948
12949 \end_inset
12950
12951
12952 \begin_inset LatexCommand index
12953 name "\\_\\_at"
12954
12955 \end_inset
12956
12957  (0xd7) CY;\InsetSpace ~
12958  /* CY (Carry Flag
12959 \begin_inset LatexCommand index
12960 name "Flags"
12961
12962 \end_inset
12963
12964
12965 \begin_inset LatexCommand index
12966 name "Carry flag"
12967
12968 \end_inset
12969
12970 ) */
12971 \end_layout
12972
12973 \begin_layout Standard
12974 Special function registers which are located on an address dividable by
12975  8 are bit-addressable, an 
12976 \emph on
12977 sbit
12978 \emph default
12979  addresses a specific bit within these sfr.
12980 \newline
12981 16 Bit and 32 bit special function
12982  register combinations which require a certain access order are better not
12983  declared using 
12984 \emph on
12985 sfr16
12986 \emph default
12987  or 
12988 \emph on
12989 sfr32.
12990
12991 \emph default
12992  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12993  this is not guaranteed.
12994 \newline
12995
12996 \end_layout
12997
12998 \begin_layout Standard
12999 Please note, if you use a header file which was written for another compiler
13000  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
13001  likely be 
13002 \emph on
13003 not
13004 \emph default
13005  compatible.
13006  Specifically the syntax 
13007 \family typewriter
13008 \InsetSpace ~
13009 sfr P0 = 0x80;\InsetSpace ~
13010
13011 \family default
13012  is compiled 
13013 \emph on
13014 without warning
13015 \emph default
13016  by SDCC to an assignment of 0x80 to a variable called P0 
13017 \family typewriter
13018
13019 \begin_inset Marginal
13020 status collapsed
13021
13022 \begin_layout Standard
13023
13024 \series bold
13025 \InsetSpace ~
13026 !
13027 \end_layout
13028
13029 \end_inset
13030
13031 .
13032
13033 \family default
13034  
13035 \series bold
13036 Nevertheless it is possible to write header files
13037 \begin_inset LatexCommand index
13038 name "Header files"
13039
13040 \end_inset
13041
13042
13043 \begin_inset LatexCommand index
13044 name "Include files"
13045
13046 \end_inset
13047
13048  which can be shared among different compilers (see section 
13049 \begin_inset LatexCommand ref
13050 reference "sec:Porting-code-to-other-compilers"
13051
13052 \end_inset
13053
13054 ).
13055  
13056 \end_layout
13057
13058 \begin_layout Subsubsection
13059 Pointers
13060 \begin_inset LatexCommand index
13061 name "Pointer"
13062
13063 \end_inset
13064
13065  to MCS51/DS390 specific memory spaces
13066 \end_layout
13067
13068 \begin_layout Standard
13069 SDCC allows (via language extensions) pointers to explicitly point to any
13070  of the memory spaces
13071 \begin_inset LatexCommand index
13072 name "Memory model"
13073
13074 \end_inset
13075
13076  of the 8051.
13077  In addition to the explicit pointers, the compiler uses (by default) generic
13078  pointers which can be used to point to any of the memory spaces.
13079 \newline
13080
13081 \newline
13082 Pointer
13083  declaration examples:
13084 \end_layout
13085
13086 \begin_layout Verse
13087
13088 \family typewriter
13089 /* pointer physically in internal ram pointing to object in external ram
13090  */ 
13091 \newline
13092 __xdata unsigned char * __data p;
13093 \newline
13094
13095 \newline
13096 /* pointer physically in external ram
13097  pointing to object in internal ram */ 
13098 \newline
13099 __data unsigned char * __xdata p;
13100 \newline
13101
13102 \newline
13103 /*
13104  pointer physically in code rom pointing to data in xdata space */ 
13105 \newline
13106 __xdata
13107  unsigned char * __code p;
13108 \newline
13109
13110 \newline
13111 /* pointer physically in code space pointing to
13112  data in code space */ 
13113 \newline
13114 __code unsigned char * __code p;
13115 \newline
13116
13117 \newline
13118 /* generic pointer
13119  physically located in xdata space */
13120 \newline
13121 unsigned char * __xdata p;
13122 \newline
13123
13124 \newline
13125 /* generic
13126  pointer physically located in default memory space */
13127 \newline
13128 unsigned char * p;
13129 \newline
13130
13131 \newline
13132 /*
13133  the following is a function pointer
13134 \begin_inset LatexCommand index
13135 name "function pointer"
13136
13137 \end_inset
13138
13139  physically located in data space */
13140 \newline
13141 char (* __data fp)(void);
13142 \end_layout
13143
13144 \begin_layout Standard
13145 Well you get the idea.
13146  
13147 \newline
13148
13149 \newline
13150 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
13151 \emph on
13152 generic
13153 \emph default
13154  pointers.
13155  
13156 \size small
13157
13158 \newline
13159
13160 \newline
13161
13162 \size default
13163 The highest order byte of the 
13164 \emph on
13165 generic
13166 \emph default
13167  pointers contains the data space information.
13168  Assembler support routines are called whenever data is stored or retrieved
13169  using 
13170 \emph on
13171 generic
13172 \emph default
13173  pointers.
13174  These are useful for developing reusable library
13175 \begin_inset LatexCommand index
13176 name "Libraries"
13177
13178 \end_inset
13179
13180  routines.
13181  Explicitly specifying the pointer
13182 \begin_inset LatexCommand index
13183 name "pointer"
13184
13185 \end_inset
13186
13187  type will generate the most efficient code.
13188 \end_layout
13189
13190 \begin_layout Subsubsection
13191 Notes on MCS51 memory
13192 \begin_inset LatexCommand index
13193 name "MCS51 memory"
13194
13195 \end_inset
13196
13197  layout
13198 \end_layout
13199
13200 \begin_layout Standard
13201 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13202  RAM memory which is structured as follows:
13203 \newline
13204
13205 \newline
13206 - Bytes 00-1F - 32 bytes to hold
13207  up to 4 banks of the registers R0 to R7, 
13208 \newline
13209 - Bytes 20-2F - 16 bytes to hold
13210  128 bit
13211 \begin_inset LatexCommand index
13212 name "bit"
13213
13214 \end_inset
13215
13216  variables and, 
13217 \newline
13218 - Bytes 30-7F - 80 bytes for general purpose use.
13219 \newline
13220
13221 \end_layout
13222
13223 \begin_layout Standard
13224 Additionally some members of the MCS51 family may have up to 128 bytes of
13225  additional, indirectly addressable, internal RAM memory (
13226 \emph on
13227 idata
13228 \emph default
13229
13230 \begin_inset LatexCommand index
13231 name "idata (mcs51, ds390 storage class)"
13232
13233 \end_inset
13234
13235
13236 \begin_inset LatexCommand index
13237 name "\\_\\_idata (mcs51, ds390 storage class)"
13238
13239 \end_inset
13240
13241 ).
13242  Furthermore, some chips may have some built in external memory (
13243 \emph on
13244 xdata
13245 \emph default
13246
13247 \begin_inset LatexCommand index
13248 name "xdata (mcs51, ds390 storage class)"
13249
13250 \end_inset
13251
13252
13253 \begin_inset LatexCommand index
13254 name "\\_\\_xdata (mcs51, ds390 storage class)"
13255
13256 \end_inset
13257
13258 ) which should not be confused with the internal, directly addressable RAM
13259  memory (
13260 \emph on
13261 data
13262 \emph default
13263
13264 \begin_inset LatexCommand index
13265 name "data (mcs51, ds390 storage class)"
13266
13267 \end_inset
13268
13269
13270 \begin_inset LatexCommand index
13271 name "\\_\\_data (mcs51, ds390 storage class)"
13272
13273 \end_inset
13274
13275 ).
13276  Sometimes this built in 
13277 \emph on
13278 xdata
13279 \emph default
13280  memory has to be activated before using it (you can probably find this
13281  information on the datasheet of the microcontroller your are using, see
13282  also section 
13283 \begin_inset LatexCommand ref
13284 reference "sub:Startup-Code"
13285
13286 \end_inset
13287
13288 \InsetSpace ~
13289 Startup-Code).
13290 \end_layout
13291
13292 \begin_layout Standard
13293 Normally SDCC will only use the first bank
13294 \begin_inset LatexCommand index
13295 name "register bank (mcs51, ds390)"
13296
13297 \end_inset
13298
13299  of registers (register bank 0), but it is possible to specify that other
13300  banks of registers (keyword 
13301 \emph on
13302 using
13303 \emph default
13304  
13305 \emph on
13306
13307 \begin_inset LatexCommand index
13308 name "using (mcs51, ds390 register bank)"
13309
13310 \end_inset
13311
13312
13313 \begin_inset LatexCommand index
13314 name "\\_\\_using (mcs51, ds390 register bank)"
13315
13316 \end_inset
13317
13318
13319 \emph default
13320 ) should be used for example in interrupt
13321 \begin_inset LatexCommand index
13322 name "interrupt"
13323
13324 \end_inset
13325
13326
13327 \begin_inset LatexCommand index
13328 name "\\_\\_interrupt"
13329
13330 \end_inset
13331
13332  routines.
13333  By default, the compiler will place the stack after the last byte of allocated
13334  memory for variables.
13335  For example, if the first 2 banks of registers are used, and only four
13336  bytes are used for 
13337 \emph on
13338 data
13339 \emph default
13340  variables, it will position the base of the internal stack at address 20
13341  (0x14).
13342  This implies that as the stack
13343 \begin_inset LatexCommand index
13344 name "stack"
13345
13346 \end_inset
13347
13348  grows, it will use up the remaining register banks, and the 16 bytes used
13349  by the 128 bit variables, and 80 bytes for general purpose use.
13350  If any bit variables are used, the data variables will be placed in unused
13351  register banks and after the byte holding the last bit variable.
13352  For example, if register banks 0 and 1 are used, and there are 9 bit variables
13353  (two bytes used), 
13354 \emph on
13355 data
13356 \emph default
13357  variables will be placed starting from address 0x10 to 0x20 and continue
13358  at address 0x22.
13359  You can also use -
13360 \begin_inset ERT
13361 status collapsed
13362
13363 \begin_layout Standard
13364
13365
13366 \backslash
13367 /
13368 \end_layout
13369
13370 \end_inset
13371
13372 -data-loc
13373 \begin_inset LatexCommand index
13374 name "-\\/-data-loc <Value>"
13375
13376 \end_inset
13377
13378  to specify the start address of the 
13379 \emph on
13380 data
13381 \emph default
13382  and -
13383 \begin_inset ERT
13384 status collapsed
13385
13386 \begin_layout Standard
13387
13388
13389 \backslash
13390 /
13391 \end_layout
13392
13393 \end_inset
13394
13395 -iram-size
13396 \begin_inset LatexCommand index
13397 name "-\\/-iram-size <Value>"
13398
13399 \end_inset
13400
13401  to specify the size of the total internal RAM (
13402 \emph on
13403 data
13404 \emph default
13405 +
13406 \emph on
13407 idata
13408 \emph default
13409 ).
13410  
13411 \newline
13412
13413 \end_layout
13414
13415 \begin_layout Standard
13416 By default the 8051 linker will place the stack after the last byte of (i)data
13417  variables.
13418  Option -
13419 \begin_inset ERT
13420 status collapsed
13421
13422 \begin_layout Standard
13423
13424
13425 \backslash
13426 /
13427 \end_layout
13428
13429 \end_inset
13430
13431 -stack-loc
13432 \begin_inset LatexCommand index
13433 name "-\\/-stack-loc <Value>"
13434
13435 \end_inset
13436
13437  allows you to specify the start of the stack, i.e.
13438  you could start it after any data in the general purpose area.
13439  If your microcontroller has additional indirectly addressable internal
13440  RAM (
13441 \emph on
13442 idata
13443 \emph default
13444 ) you can place the stack on it.
13445  You may also need to use -
13446 \begin_inset ERT
13447 status collapsed
13448
13449 \begin_layout Standard
13450
13451
13452 \backslash
13453 /
13454 \end_layout
13455
13456 \end_inset
13457
13458 -xdata-loc
13459 \begin_inset LatexCommand index
13460 name "-\\/-xdata-loc<Value>"
13461
13462 \end_inset
13463
13464  to set the start address of the external RAM (
13465 \emph on
13466 xdata
13467 \emph default
13468 ) and -
13469 \begin_inset ERT
13470 status collapsed
13471
13472 \begin_layout Standard
13473
13474
13475 \backslash
13476 /
13477 \end_layout
13478
13479 \end_inset
13480
13481 -xram-size
13482 \begin_inset LatexCommand index
13483 name "-\\/-xram-size <Value>"
13484
13485 \end_inset
13486
13487  to specify its size.
13488  Same goes for the code memory, using -
13489 \begin_inset ERT
13490 status collapsed
13491
13492 \begin_layout Standard
13493
13494
13495 \backslash
13496 /
13497 \end_layout
13498
13499 \end_inset
13500
13501 -code-loc
13502 \begin_inset LatexCommand index
13503 name "-\\/-code-loc <Value>"
13504
13505 \end_inset
13506
13507  and -
13508 \begin_inset ERT
13509 status collapsed
13510
13511 \begin_layout Standard
13512
13513
13514 \backslash
13515 /
13516 \end_layout
13517
13518 \end_inset
13519
13520 -code-size
13521 \begin_inset LatexCommand index
13522 name "-\\/-code-size <Value>"
13523
13524 \end_inset
13525
13526 .
13527  If in doubt, don't specify any options and see if the resulting memory
13528  layout is appropriate, then you can adjust it.
13529 \end_layout
13530
13531 \begin_layout Standard
13532 The linker generates two files with memory allocation information.
13533  The first, with extension .map
13534 \begin_inset LatexCommand index
13535 name "<file>.map"
13536
13537 \end_inset
13538
13539  shows all the variables and segments.
13540  The second with extension .mem
13541 \begin_inset LatexCommand index
13542 name "<file>.mem"
13543
13544 \end_inset
13545
13546  shows the final memory layout.
13547  The linker will complain either if memory segments overlap, there is not
13548  enough memory, or there is not enough space for stack.
13549  If you get any linking warnings and/or errors related to stack or segments
13550  allocation, take a look at either the .map or .mem files to find out what
13551  the problem is.
13552  The .mem file may even suggest a solution to the problem.
13553 \begin_inset VSpace bigskip
13554 \end_inset
13555
13556
13557 \end_layout
13558
13559 \begin_layout Subsection
13560 Z80/Z180 Storage Class
13561 \begin_inset LatexCommand index
13562 name "Z80!Storage class"
13563
13564 \end_inset
13565
13566  Language Extensions
13567 \end_layout
13568
13569 \begin_layout Subsubsection
13570 sfr
13571 \begin_inset LatexCommand index
13572 name "sfr"
13573
13574 \end_inset
13575
13576
13577 \begin_inset LatexCommand index
13578 name "\\_\\_sfr"
13579
13580 \end_inset
13581
13582  (in/out to 8-bit addresses)
13583 \end_layout
13584
13585 \begin_layout Standard
13586 The Z80
13587 \begin_inset LatexCommand index
13588 name "Z80"
13589
13590 \end_inset
13591
13592  family has separate address spaces for memory and 
13593 \emph on
13594 i
13595 \emph default
13596 nput/
13597 \emph on
13598 o
13599 \emph default
13600 utput memory.
13601  I/O memory
13602 \begin_inset LatexCommand index
13603 name "I/O memory (Z80, Z180)"
13604
13605 \end_inset
13606
13607
13608 \begin_inset LatexCommand index
13609 name "Z80!I/O memory"
13610
13611 \end_inset
13612
13613
13614 \begin_inset LatexCommand index
13615 name "Z180!I/O memory"
13616
13617 \end_inset
13618
13619  is accessed with special instructions, e.g.:
13620 \end_layout
13621
13622 \begin_layout Verse
13623
13624 \family typewriter
13625 sfr at 0x78 IoPort;\InsetSpace ~
13626 \InsetSpace ~
13627 /* define a var in I/O space at 78h called IoPort */
13628  
13629 \end_layout
13630
13631 \begin_layout Standard
13632 Writing 0x01 to this variable generates the assembly code:
13633 \end_layout
13634
13635 \begin_layout Verse
13636
13637 \family typewriter
13638 3E 01\InsetSpace ~
13639 \InsetSpace ~
13640 \InsetSpace ~
13641 \InsetSpace ~
13642 \InsetSpace ~
13643 \InsetSpace ~
13644 ld a,#0x01
13645 \newline
13646 D3 78\InsetSpace ~
13647 \InsetSpace ~
13648 \InsetSpace ~
13649 \InsetSpace ~
13650 \InsetSpace ~
13651 \InsetSpace ~
13652 out (_IoPort),a 
13653 \end_layout
13654
13655 \begin_layout Subsubsection
13656 banked sfr
13657 \begin_inset LatexCommand index
13658 name "sfr"
13659
13660 \end_inset
13661
13662
13663 \begin_inset LatexCommand index
13664 name "\\_\\_sfr"
13665
13666 \end_inset
13667
13668  (in/out to 16-bit addresses)
13669 \end_layout
13670
13671 \begin_layout Standard
13672 The keyword 
13673 \emph on
13674 banked
13675 \emph default
13676  is used to support 16 bit addresses in I/O memory e.g.:
13677 \end_layout
13678
13679 \begin_layout Verse
13680
13681 \family typewriter
13682 sfr banked at
13683 \begin_inset LatexCommand index
13684 name "at"
13685
13686 \end_inset
13687
13688
13689 \begin_inset LatexCommand index
13690 name "\\_\\_at"
13691
13692 \end_inset
13693
13694  0x123 IoPort; 
13695 \end_layout
13696
13697 \begin_layout Standard
13698 Writing 0x01 to this variable generates the assembly code:
13699 \end_layout
13700
13701 \begin_layout Verse
13702
13703 \family typewriter
13704 01 23 01\InsetSpace ~
13705 \InsetSpace ~
13706 \InsetSpace ~
13707 ld bc,#_IoPort
13708 \newline
13709 3E 01\InsetSpace ~
13710 \InsetSpace ~
13711 \InsetSpace ~
13712 \InsetSpace ~
13713 \InsetSpace ~
13714 \InsetSpace ~
13715 ld a,#0x01 
13716 \newline
13717 ED 79\InsetSpace ~
13718 \InsetSpace ~
13719 \InsetSpace ~
13720 \InsetSpace ~
13721 \InsetSpace ~
13722 \InsetSpace ~
13723 out (c),a 
13724 \end_layout
13725
13726 \begin_layout Subsubsection
13727 sfr
13728 \begin_inset LatexCommand index
13729 name "sfr"
13730
13731 \end_inset
13732
13733
13734 \begin_inset LatexCommand index
13735 name "\\_\\_sfr"
13736
13737 \end_inset
13738
13739  (in0/out0 to 8 bit addresses on Z180
13740 \begin_inset LatexCommand index
13741 name "Z180"
13742
13743 \end_inset
13744
13745 /HD64180
13746 \begin_inset LatexCommand index
13747 name "HD64180 (see Z180)"
13748
13749 \end_inset
13750
13751 )
13752 \end_layout
13753
13754 \begin_layout Standard
13755 The compiler option -
13756 \begin_inset ERT
13757 status collapsed
13758
13759 \begin_layout Standard
13760
13761
13762 \backslash
13763 /
13764 \end_layout
13765
13766 \end_inset
13767
13768 -portmode
13769 \begin_inset LatexCommand index
13770 name "Z180!Options!-\\/-portmode"
13771
13772 \end_inset
13773
13774 =180 (80) and a compiler #pragma\InsetSpace ~
13775 portmode
13776 \begin_inset LatexCommand index
13777 name "Z180!Pragmas!\\#pragma portmode"
13778
13779 \end_inset
13780
13781  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13782 ns 
13783 \family typewriter
13784 in0/out0
13785 \family default
13786  instead of 
13787 \family typewriter
13788 in/out
13789 \family default
13790 .
13791  If you include the file z180.h this will be set automatically.
13792 \begin_inset VSpace bigskip
13793 \end_inset
13794
13795
13796 \end_layout
13797
13798 \begin_layout Subsection
13799 HC08 Storage Class
13800 \begin_inset LatexCommand index
13801 name "HC08!Storage class"
13802
13803 \end_inset
13804
13805  Language Extensions
13806 \end_layout
13807
13808 \begin_layout Subsubsection
13809 data
13810 \begin_inset LatexCommand index
13811 name "data (hc08 storage class)"
13812
13813 \end_inset
13814
13815
13816 \begin_inset LatexCommand index
13817 name "\\_\\_data (hc08 storage class)"
13818
13819 \end_inset
13820
13821  
13822 \end_layout
13823
13824 \begin_layout Standard
13825 The data storage class declares a variable that resides in the first 256
13826  bytes of memory (the direct page).
13827  The HC08
13828 \begin_inset LatexCommand index
13829 name "HC08"
13830
13831 \end_inset
13832
13833  is most efficient at accessing variables (especially pointers) stored here.
13834 \end_layout
13835
13836 \begin_layout Subsubsection
13837 xdata
13838 \begin_inset LatexCommand index
13839 name "xdata (hc08 storage class)"
13840
13841 \end_inset
13842
13843
13844 \begin_inset LatexCommand index
13845 name "\\_\\_xdata (hc08 storage class)"
13846
13847 \end_inset
13848
13849  
13850 \end_layout
13851
13852 \begin_layout Standard
13853 The xdata storage class declares a variable that can reside anywhere in
13854  memory.
13855  This is the default if no storage class is specified.
13856  
13857 \begin_inset VSpace bigskip
13858 \end_inset
13859
13860
13861 \end_layout
13862
13863 \begin_layout Section
13864 Other SDCC language extensions
13865 \begin_inset LatexCommand index
13866 name "Other SDCC language extensions"
13867
13868 \end_inset
13869
13870
13871 \end_layout
13872
13873 \begin_layout Subsection
13874 Binary constants
13875 \end_layout
13876
13877 \begin_layout Standard
13878 SDCC supports the use of binary constants, such as 0b01100010.
13879  This feature is only enabled when the compiler is invoked using --std-sdccxx.
13880 \end_layout
13881
13882 \begin_layout Standard
13883 \begin_inset VSpace bigskip
13884 \end_inset
13885
13886
13887 \end_layout
13888
13889 \begin_layout Section
13890 Absolute Addressing
13891 \begin_inset LatexCommand index
13892 name "Absolute addressing"
13893
13894 \end_inset
13895
13896
13897 \end_layout
13898
13899 \begin_layout Standard
13900 Data items can be assigned an absolute address with the 
13901 \emph on
13902 at
13903 \begin_inset LatexCommand index
13904 name "at"
13905
13906 \end_inset
13907
13908
13909 \begin_inset LatexCommand index
13910 name "\\_\\_at"
13911
13912 \end_inset
13913
13914  <address>
13915 \emph default
13916  keyword, in addition to a storage class, e.g.:
13917 \end_layout
13918
13919 \begin_layout Verse
13920
13921 \family typewriter
13922 xdata
13923 \begin_inset LatexCommand index
13924 name "xdata (mcs51, ds390 storage class)"
13925
13926 \end_inset
13927
13928
13929 \begin_inset LatexCommand index
13930 name "\\_\\_xdata (mcs51, ds390 storage class)"
13931
13932 \end_inset
13933
13934  at
13935 \begin_inset LatexCommand index
13936 name "at"
13937
13938 \end_inset
13939
13940
13941 \begin_inset LatexCommand index
13942 name "\\_\\_at"
13943
13944 \end_inset
13945
13946  0x7ffe unsigned int chksum;
13947 \end_layout
13948
13949 \begin_layout Standard
13950 or, better conforming to ISO/IEC 9899 C:
13951 \end_layout
13952
13953 \begin_layout Verse
13954
13955 \family typewriter
13956 __xdata __at (0x7ffe) unsigned int chksum;
13957 \end_layout
13958
13959 \begin_layout Standard
13960 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13961  of the external ram.
13962  The compiler does 
13963 \emph on
13964 not
13965 \emph default
13966  reserve any space for variables declared in this way
13967 \begin_inset Marginal
13968 status collapsed
13969
13970 \begin_layout Standard
13971
13972 \series bold
13973 \InsetSpace ~
13974 !
13975 \end_layout
13976
13977 \end_inset
13978
13979  (they are implemented with an equate in the assembler).
13980  Thus it is left to the programmer to make sure there are no overlaps with
13981  other variables that are declared without the absolute address.
13982  The assembler listing file (.lst
13983 \begin_inset LatexCommand index
13984 name "<file>.lst"
13985
13986 \end_inset
13987
13988 ) and the linker output files (.rst
13989 \begin_inset LatexCommand index
13990 name "<file>.rst"
13991
13992 \end_inset
13993
13994 ) and (.map
13995 \begin_inset LatexCommand index
13996 name "<file>.map"
13997
13998 \end_inset
13999
14000 ) are good places to look for such overlaps.
14001 \end_layout
14002
14003 \begin_layout Standard
14004 If however you provide an initializer
14005 \begin_inset LatexCommand index
14006 name "Variable initialization"
14007
14008 \end_inset
14009
14010  actual memory allocation will take place and overlaps will be detected
14011  by the linker.
14012  E.g.:
14013 \end_layout
14014
14015 \begin_layout Verse
14016
14017 \family typewriter
14018 __code __at (0x7ff0) char Id[5] = 
14019 \begin_inset Quotes sld
14020 \end_inset
14021
14022 SDCC
14023 \begin_inset Quotes srd
14024 \end_inset
14025
14026 ;
14027 \end_layout
14028
14029 \begin_layout Standard
14030 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
14031  in code memory.
14032 \end_layout
14033
14034 \begin_layout Standard
14035 In case of memory mapped I/O devices the keyword 
14036 \emph on
14037 volatile
14038 \emph default
14039  has to be used to tell the compiler that accesses might not be removed:
14040 \end_layout
14041
14042 \begin_layout Verse
14043
14044 \family typewriter
14045 volatile
14046 \begin_inset LatexCommand index
14047 name "volatile"
14048
14049 \end_inset
14050
14051  __xdata
14052 \begin_inset LatexCommand index
14053 name "xdata (mcs51, ds390 storage class)"
14054
14055 \end_inset
14056
14057  __at
14058 \begin_inset LatexCommand index
14059 name "at"
14060
14061 \end_inset
14062
14063  (0x8000) unsigned char PORTA_8255;
14064 \end_layout
14065
14066 \begin_layout Standard
14067 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
14068 r) array
14069 \family typewriter
14070 \size footnotesize
14071
14072 \begin_inset LatexCommand index
14073 name "Aligned array"
14074
14075 \end_inset
14076
14077
14078 \family default
14079 \size default
14080  starts at a block (256 byte) boundary
14081 \begin_inset LatexCommand index
14082 name "block boundary"
14083
14084 \end_inset
14085
14086  (section 
14087 \begin_inset LatexCommand ref
14088 reference "sub:A-Step-by Assembler Introduction"
14089
14090 \end_inset
14091
14092  has an example).
14093 \newline
14094 Absolute addresses can be specified for variables in all
14095  storage classes, e.g.:
14096 \end_layout
14097
14098 \begin_layout Verse
14099
14100 \family typewriter
14101 __bit
14102 \begin_inset LatexCommand index
14103 name "bit"
14104
14105 \end_inset
14106
14107  __at
14108 \begin_inset LatexCommand index
14109 name "at"
14110
14111 \end_inset
14112
14113  (0x02) bvar;
14114 \end_layout
14115
14116 \begin_layout Standard
14117 The above example will allocate the variable at offset 0x02 in the bit-addressab
14118 le space.
14119  There is no real advantage to assigning absolute addresses to variables
14120  in this manner, unless you want strict control over all the variables allocated.
14121  One possible use would be to write hardware portable code.
14122  For example, if you have a routine that uses one or more of the microcontroller
14123  I/O pins, and such pins are different for two different hardwares, you
14124  can declare the I/O pins in your routine using:
14125 \end_layout
14126
14127 \begin_layout Verse
14128
14129 \family typewriter
14130 extern volatile
14131 \begin_inset LatexCommand index
14132 name "volatile"
14133
14134 \end_inset
14135
14136  __bit MOSI;\InsetSpace ~
14137 \InsetSpace ~
14138 \InsetSpace ~
14139 \InsetSpace ~
14140 /* master out, slave in */
14141 \newline
14142 extern volatile __bit MISO;\InsetSpace ~
14143 \InsetSpace ~
14144 \InsetSpace ~
14145 \InsetSpace ~
14146 /* master
14147  in, slave out */
14148 \newline
14149 extern volatile __bit MCLK;\InsetSpace ~
14150 \InsetSpace ~
14151 \InsetSpace ~
14152 \InsetSpace ~
14153 /* master clock */
14154 \newline
14155
14156 \newline
14157 /* Input and
14158  Output of a byte on a 3-wire serial bus.
14159 \newline
14160 \InsetSpace ~
14161 \InsetSpace ~
14162 \InsetSpace ~
14163 If needed adapt polarity of clock,
14164  polarity of data and bit order
14165 \newline
14166 \InsetSpace ~
14167 */
14168 \newline
14169 unsigned char spi_io(unsigned char out_byte)
14170  
14171 \newline
14172
14173 \newline
14174 \InsetSpace ~
14175 \InsetSpace ~
14176 \InsetSpace ~
14177 \InsetSpace ~
14178 unsigned char i=8;
14179 \newline
14180 \InsetSpace ~
14181 \InsetSpace ~
14182 \InsetSpace ~
14183 \InsetSpace ~
14184 do { 
14185 \newline
14186 \InsetSpace ~
14187 \InsetSpace ~
14188 \InsetSpace ~
14189 \InsetSpace ~
14190 \InsetSpace ~
14191 \InsetSpace ~
14192 \InsetSpace ~
14193 \InsetSpace ~
14194 MOSI = out_byte & 0x80; 
14195 \newline
14196 \InsetSpace ~
14197 \InsetSpace ~
14198 \InsetSpace ~
14199 \InsetSpace ~
14200 \InsetSpace ~
14201 \InsetSpace ~
14202 \InsetSpace ~
14203 \InsetSpace ~
14204 out_byte <<= 1;
14205 \newline
14206 \InsetSpace ~
14207 \InsetSpace ~
14208 \InsetSpace ~
14209 \InsetSpace ~
14210 \InsetSpace ~
14211 \InsetSpace ~
14212 \InsetSpace ~
14213 \InsetSpace ~
14214 MCLK =
14215  1; 
14216 \newline
14217 \InsetSpace ~
14218 \InsetSpace ~
14219 \InsetSpace ~
14220 \InsetSpace ~
14221 \InsetSpace ~
14222 \InsetSpace ~
14223 \InsetSpace ~
14224 \InsetSpace ~
14225 /* _asm nop _endasm; */\InsetSpace ~
14226 \InsetSpace ~
14227 \InsetSpace ~
14228 \InsetSpace ~
14229 \InsetSpace ~
14230 \InsetSpace ~
14231 \InsetSpace ~
14232 \InsetSpace ~
14233 /* for slow peripherals */
14234 \newline
14235 \InsetSpace ~
14236 \InsetSpace ~
14237 \InsetSpace ~
14238 \InsetSpace ~
14239 \InsetSpace ~
14240 \InsetSpace ~
14241 \InsetSpace ~
14242 \InsetSpace ~
14243 if(MISO) 
14244 \newline
14245 \InsetSpace ~
14246 \InsetSpace ~
14247 \InsetSpace ~
14248 \InsetSpace ~
14249 \InsetSpace ~
14250 \InsetSpace ~
14251 \InsetSpace ~
14252 \InsetSpace ~
14253 \InsetSpace ~
14254 \InsetSpace ~
14255 \InsetSpace ~
14256 \InsetSpace ~
14257 out_byte +=
14258  1; 
14259 \newline
14260 \InsetSpace ~
14261 \InsetSpace ~
14262 \InsetSpace ~
14263 \InsetSpace ~
14264 \InsetSpace ~
14265 \InsetSpace ~
14266 \InsetSpace ~
14267 \InsetSpace ~
14268 MCLK = 0; 
14269 \newline
14270 \InsetSpace ~
14271 \InsetSpace ~
14272 \InsetSpace ~
14273 \InsetSpace ~
14274 } while(--i);
14275 \newline
14276 \InsetSpace ~
14277 \InsetSpace ~
14278 \InsetSpace ~
14279 \InsetSpace ~
14280 return out_byte; 
14281 \newline
14282 }
14283 \end_layout
14284
14285 \begin_layout Standard
14286 Then, someplace in the code for the first hardware you would use
14287 \end_layout
14288
14289 \begin_layout Verse
14290
14291 \family typewriter
14292 __bit __at
14293 \begin_inset LatexCommand index
14294 name "at"
14295
14296 \end_inset
14297
14298
14299 \begin_inset LatexCommand index
14300 name "\\_\\_at"
14301
14302 \end_inset
14303
14304  (0x80) MOSI;\InsetSpace ~
14305 \InsetSpace ~
14306 \InsetSpace ~
14307 \InsetSpace ~
14308 /* I/O port 0, bit 0 */
14309 \newline
14310 __bit __at (0x81) MISO;\InsetSpace ~
14311 \InsetSpace ~
14312 \InsetSpace ~
14313 \InsetSpace ~
14314 /* I/O port 0,
14315  bit 1 */
14316 \newline
14317 __bit __at (0x82) MCLK;\InsetSpace ~
14318 \InsetSpace ~
14319 \InsetSpace ~
14320 \InsetSpace ~
14321 /* I/O port 0, bit 2 */
14322 \end_layout
14323
14324 \begin_layout Standard
14325 Similarly, for the second hardware you would use
14326 \end_layout
14327
14328 \begin_layout Verse
14329
14330 \family typewriter
14331 __bit __at (0x83) MOSI;\InsetSpace ~
14332 \InsetSpace ~
14333 \InsetSpace ~
14334 \InsetSpace ~
14335 /* I/O port 0, bit 3 */
14336 \newline
14337 __bit __at (0x91) MISO;\InsetSpace ~
14338 \InsetSpace ~
14339 \InsetSpace ~
14340 \InsetSpace ~
14341 /*
14342  I/O port 1, bit 1 */
14343 \newline
14344 __bit
14345 \begin_inset LatexCommand index
14346 name "bit"
14347
14348 \end_inset
14349
14350  __at (0x92) MCLK;\InsetSpace ~
14351 \InsetSpace ~
14352 \InsetSpace ~
14353 \InsetSpace ~
14354 /* I/O port 1, bit 2 */
14355 \end_layout
14356
14357 \begin_layout Standard
14358 and you can use the same hardware dependent routine without changes, as
14359  for example in a library.
14360  This is somehow similar to sbit, but only one absolute address has to be
14361  specified in the whole project.
14362 \begin_inset VSpace bigskip
14363 \end_inset
14364
14365
14366 \end_layout
14367
14368 \begin_layout Section
14369 Parameters
14370 \begin_inset LatexCommand index
14371 name "Parameters"
14372
14373 \end_inset
14374
14375
14376 \begin_inset LatexCommand index
14377 name "function parameter"
14378
14379 \end_inset
14380
14381  & Local Variables
14382 \begin_inset LatexCommand index
14383 name "local variables"
14384
14385 \end_inset
14386
14387
14388 \begin_inset LatexCommand label
14389 name "sec:Parameters-and-Local-Variables"
14390
14391 \end_inset
14392
14393
14394 \end_layout
14395
14396 \begin_layout Standard
14397 Automatic (local) variables and parameters to functions can either be placed
14398  on the stack or in data-space.
14399  The default action of the compiler is to place these variables in the internal
14400  RAM (for small model) or external RAM (for medium or large model).
14401  This in fact makes them similar to 
14402 \emph on
14403 static
14404 \begin_inset LatexCommand index
14405 name "static"
14406
14407 \end_inset
14408
14409
14410 \emph default
14411  so by default functions are non-reentrant
14412 \begin_inset LatexCommand index
14413 name "reentrant"
14414
14415 \end_inset
14416
14417 .
14418  
14419 \newline
14420
14421 \newline
14422 They can be placed on the stack
14423 \begin_inset LatexCommand index
14424 name "stack"
14425
14426 \end_inset
14427
14428  by using the 
14429 \emph on
14430 -
14431 \begin_inset ERT
14432 status collapsed
14433
14434 \begin_layout Standard
14435
14436
14437 \backslash
14438 /
14439 \end_layout
14440
14441 \end_inset
14442
14443 -stack-auto
14444 \begin_inset LatexCommand index
14445 name "-\\/-stack-auto"
14446
14447 \end_inset
14448
14449
14450 \emph default
14451  option, by using 
14452 \emph on
14453 #pragma\InsetSpace ~
14454 stackauto
14455 \emph default
14456
14457 \begin_inset LatexCommand index
14458 name "\\#pragma stackauto"
14459
14460 \end_inset
14461
14462  or by using the 
14463 \emph on
14464 reentrant
14465 \begin_inset LatexCommand index
14466 name "reentrant"
14467
14468 \end_inset
14469
14470
14471 \emph default
14472  keyword in the function declaration, e.g.:
14473 \end_layout
14474
14475 \begin_layout Verse
14476
14477 \family typewriter
14478 unsigned char foo(char i) __reentrant 
14479 \newline
14480
14481 \newline
14482 \InsetSpace ~
14483 \InsetSpace ~
14484 \InsetSpace ~
14485 \InsetSpace ~
14486 ...
14487  
14488 \newline
14489 }
14490 \end_layout
14491
14492 \begin_layout Standard
14493 Since stack space on 8051 is limited, the 
14494 \emph on
14495 reentrant
14496 \emph default
14497  keyword or the 
14498 \emph on
14499 -
14500 \begin_inset ERT
14501 status collapsed
14502
14503 \begin_layout Standard
14504
14505
14506 \backslash
14507 /
14508 \end_layout
14509
14510 \end_inset
14511
14512 -stack-auto
14513 \emph default
14514  option should be used sparingly.
14515  Note that the reentrant keyword just means that the parameters & local
14516  variables will be allocated to the stack, it 
14517 \emph on
14518 does not
14519 \emph default
14520  mean that the function is register bank
14521 \begin_inset LatexCommand index
14522 name "register bank (mcs51, ds390)"
14523
14524 \end_inset
14525
14526  independent.
14527 \newline
14528
14529 \newline
14530 Local variables
14531 \begin_inset LatexCommand index
14532 name "local variables"
14533
14534 \end_inset
14535
14536  can be assigned storage classes and absolute
14537 \begin_inset LatexCommand index
14538 name "Absolute addressing"
14539
14540 \end_inset
14541
14542  addresses, e.g.: 
14543 \end_layout
14544
14545 \begin_layout Verse
14546
14547 \family typewriter
14548 unsigned char foo() 
14549 \newline
14550 {
14551 \newline
14552 \InsetSpace ~
14553 \InsetSpace ~
14554 \InsetSpace ~
14555 \InsetSpace ~
14556 __xdata unsigned char i;
14557 \newline
14558 \InsetSpace ~
14559 \InsetSpace ~
14560 \InsetSpace ~
14561 \InsetSpace ~
14562 __bit bvar;
14563 \newline
14564 \InsetSpace ~
14565 \InsetSpace ~
14566 \InsetSpace ~
14567 \InsetSpace ~
14568 __data __at
14569 \begin_inset LatexCommand index
14570 name "at"
14571
14572 \end_inset
14573
14574  (0x31) unsigned char j;
14575 \newline
14576 \InsetSpace ~
14577 \InsetSpace ~
14578 \InsetSpace ~
14579 \InsetSpace ~
14580 ...
14581  
14582 \newline
14583 }
14584 \end_layout
14585
14586 \begin_layout Standard
14587 In the above example the variable 
14588 \emph on
14589 i
14590 \emph default
14591  will be allocated in the external ram, 
14592 \emph on
14593 bvar
14594 \emph default
14595  in bit addressable space and 
14596 \emph on
14597 j
14598 \emph default
14599  in internal ram.
14600  When compiled with 
14601 \emph on
14602 -
14603 \begin_inset ERT
14604 status collapsed
14605
14606 \begin_layout Standard
14607
14608
14609 \backslash
14610 /
14611 \end_layout
14612
14613 \end_inset
14614
14615 -stack-auto
14616 \emph default
14617  or when a function is declared as 
14618 \emph on
14619 reentrant
14620 \emph default
14621  this should only be done for static variables.
14622 \end_layout
14623
14624 \begin_layout Standard
14625 Parameters
14626 \begin_inset LatexCommand index
14627 name "function parameter"
14628
14629 \end_inset
14630
14631  however are not allowed any storage class
14632 \begin_inset LatexCommand index
14633 name "Storage class"
14634
14635 \end_inset
14636
14637 , (storage classes for parameters will be ignored), their allocation is
14638  governed by the memory model in use, and the reentrancy options.
14639 \end_layout
14640
14641 \begin_layout Standard
14642 It is however allowed to use bit parameters in reentrant functions and also
14643  non-static local bit variables are supported.
14644  Efficient use is limited to 8 semi-bitregisters in bit space.
14645  They are pushed and popped to stack
14646 \begin_inset LatexCommand index
14647 name "stack"
14648
14649 \end_inset
14650
14651  as a single byte just like the normal registers.
14652 \end_layout
14653
14654 \begin_layout Section
14655 Overlaying
14656 \begin_inset LatexCommand label
14657 name "sub:Overlaying"
14658
14659 \end_inset
14660
14661
14662 \begin_inset LatexCommand index
14663 name "Overlaying"
14664
14665 \end_inset
14666
14667
14668 \end_layout
14669
14670 \begin_layout Standard
14671 For non-reentrant
14672 \begin_inset LatexCommand index
14673 name "reentrant"
14674
14675 \end_inset
14676
14677  functions SDCC will try to reduce internal ram space usage by overlaying
14678  parameters and local variables of a function (if possible).
14679  Parameters and local variables
14680 \begin_inset LatexCommand index
14681 name "local variables"
14682
14683 \end_inset
14684
14685  of a function will be allocated to an overlayable segment if the function
14686  has 
14687 \emph on
14688 no other function calls and the function is non-reentrant and the memory
14689  model
14690 \begin_inset LatexCommand index
14691 name "Memory model"
14692
14693 \end_inset
14694
14695  is small.
14696
14697 \emph default
14698  If an explicit storage class
14699 \begin_inset LatexCommand index
14700 name "Storage class"
14701
14702 \end_inset
14703
14704  is specified for a local variable, it will NOT be overlaid.
14705 \end_layout
14706
14707 \begin_layout Standard
14708 Note that the compiler (not the linkage editor) makes the decision for overlayin
14709 g the data items.
14710  Functions that are called from an interrupt service routine
14711 \begin_inset Marginal
14712 status collapsed
14713
14714 \begin_layout Standard
14715
14716 \series bold
14717 !
14718 \end_layout
14719
14720 \end_inset
14721
14722  should be preceded by a #pragma\InsetSpace ~
14723 nooverlay
14724 \begin_inset LatexCommand index
14725 name "\\#pragma nooverlay"
14726
14727 \end_inset
14728
14729  if they are not reentrant.
14730 \end_layout
14731
14732 \begin_layout Standard
14733 Also note that the compiler does not do any processing of inline assembler
14734  code, so the compiler might incorrectly assign local variables and parameters
14735  of a function into the overlay segment if the inline assembler code calls
14736  other c-functions that might use the overlay.
14737  In that case the #pragma\InsetSpace ~
14738 nooverlay should be used.
14739 \end_layout
14740
14741 \begin_layout Standard
14742 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14743 tion
14744 \begin_inset LatexCommand index
14745 name "Multiplication"
14746
14747 \end_inset
14748
14749  or division
14750 \begin_inset LatexCommand index
14751 name "Division"
14752
14753 \end_inset
14754
14755  will NOT be overlaid since these are implemented using external functions,
14756  e.g.:
14757 \end_layout
14758
14759 \begin_layout Verse
14760
14761 \family typewriter
14762 #pragma save 
14763 \newline
14764 #pragma nooverlay
14765 \begin_inset LatexCommand index
14766 name "\\#pragma nooverlay"
14767
14768 \end_inset
14769
14770  
14771 \newline
14772 void set_error(unsigned char errcd) 
14773 \newline
14774 {
14775 \newline
14776 \InsetSpace ~
14777 \InsetSpace ~
14778 \InsetSpace ~
14779 \InsetSpace ~
14780 P3 = errcd;
14781 \newline
14782
14783 \newline
14784 #pragma restore 
14785 \newline
14786
14787 \newline
14788 void
14789  some_isr () __interrupt
14790 \begin_inset LatexCommand index
14791 name "interrupt"
14792
14793 \end_inset
14794
14795  (2)
14796 \newline
14797 {
14798 \newline
14799 \InsetSpace ~
14800 \InsetSpace ~
14801 \InsetSpace ~
14802 \InsetSpace ~
14803 ...
14804 \newline
14805 \InsetSpace ~
14806 \InsetSpace ~
14807 \InsetSpace ~
14808 \InsetSpace ~
14809 set_error(10);
14810 \newline
14811 \InsetSpace ~
14812 \InsetSpace ~
14813 \InsetSpace ~
14814 \InsetSpace ~
14815 ...
14816  
14817 \newline
14818 }
14819 \end_layout
14820
14821 \begin_layout Standard
14822 In the above example the parameter 
14823 \emph on
14824 errcd
14825 \emph default
14826  for the function 
14827 \emph on
14828 set_error
14829 \emph default
14830  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14831 nooverlay was
14832  not present, this could cause unpredictable runtime behavior when called
14833  from an interrupt service routine.
14834  The #pragma\InsetSpace ~
14835 nooverlay ensures that the parameters and local variables for
14836  the function are NOT overlaid.
14837 \begin_inset VSpace bigskip
14838 \end_inset
14839
14840
14841 \end_layout
14842
14843 \begin_layout Section
14844 Interrupt Service Routines
14845 \begin_inset LatexCommand label
14846 name "sub:Interrupt-Service-Routines"
14847
14848 \end_inset
14849
14850
14851 \end_layout
14852
14853 \begin_layout Subsection
14854 General Information
14855 \end_layout
14856
14857 \begin_layout Standard
14858 SDCC allows 
14859 \emph on
14860 i
14861 \emph default
14862 nterrupt 
14863 \emph on
14864 s
14865 \emph default
14866 ervice 
14867 \emph on
14868 r
14869 \emph default
14870 outines to be coded in C, with some extended keywords.
14871 \end_layout
14872
14873 \begin_layout Verse
14874
14875 \family typewriter
14876 void timer_isr (void) __interrupt (1) __using (1) 
14877 \newline
14878
14879 \newline
14880 \InsetSpace ~
14881 \InsetSpace ~
14882 \InsetSpace ~
14883 \InsetSpace ~
14884 ...
14885  
14886 \newline
14887 }
14888 \end_layout
14889
14890 \begin_layout Standard
14891 The optional number following the 
14892 \emph on
14893 interrupt
14894 \begin_inset LatexCommand index
14895 name "interrupt"
14896
14897 \end_inset
14898
14899
14900 \begin_inset LatexCommand index
14901 name "\\_\\_interrupt"
14902
14903 \end_inset
14904
14905
14906 \emph default
14907  keyword is the interrupt number this routine will service.
14908  When present, the compiler will insert a call to this routine in the interrupt
14909  vector table
14910 \begin_inset LatexCommand index
14911 name "interrupt vector table"
14912
14913 \end_inset
14914
14915  for the interrupt number specified.
14916  If you have multiple source files in your project, interrupt service routines
14917  can be present in any of them, but a prototype of the isr MUST be present
14918  or included in the file that contains the function 
14919 \emph on
14920 main
14921 \emph default
14922 .
14923  The optional (8051 specific) keyword 
14924 \emph on
14925 using
14926 \begin_inset LatexCommand index
14927 name "using (mcs51, ds390 register bank)"
14928
14929 \end_inset
14930
14931
14932 \begin_inset LatexCommand index
14933 name "\\_\\_using (mcs51, ds390 register bank)"
14934
14935 \end_inset
14936
14937
14938 \emph default
14939  can be used to tell the compiler to use the specified register bank when
14940  generating code for this function.
14941  
14942 \newline
14943 Interrupt service routines open the door for some very interesting bugs:
14944 \end_layout
14945
14946 \begin_layout Subsubsection
14947 \begin_inset LatexCommand label
14948 name "sub:Common-interrupt-pitfall-volatile"
14949
14950 \end_inset
14951
14952 Common interrupt pitfall: variable not declared 
14953 \emph on
14954 volatile
14955 \end_layout
14956
14957 \begin_layout Standard
14958 If an interrupt service routine changes variables which are accessed by
14959  other functions these variables have to be declared 
14960 \emph on
14961 volatile
14962 \emph default
14963
14964 \begin_inset LatexCommand index
14965 name "volatile"
14966
14967 \end_inset
14968
14969 .
14970  See 
14971 \begin_inset LatexCommand url
14972 target "http://en.wikipedia.org/wiki/Volatile_variable"
14973
14974 \end_inset
14975
14976  .
14977 \end_layout
14978
14979 \begin_layout Subsubsection
14980 \begin_inset LatexCommand label
14981 name "sub:Common-interrupt-pitfall-non-atomic"
14982
14983 \end_inset
14984
14985 Common interrupt pitfall: 
14986 \emph on
14987 non-atomic access
14988 \end_layout
14989
14990 \begin_layout Standard
14991 If the access to these variables is not 
14992 \emph on
14993 atomic
14994 \begin_inset LatexCommand index
14995 name "atomic"
14996
14997 \end_inset
14998
14999
15000 \emph default
15001  (i.e.
15002  the processor needs more than one instruction for the access and could
15003  be interrupted while accessing the variable) the interrupt must be disabled
15004  during the access to avoid inconsistent data.
15005  
15006 \newline
15007 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
15008  and should be protected by disabling interrupts.
15009  You're not automatically on the safe side if you use 8 bit variables though.
15010  We need an example here: f.e.
15011  on the 8051 the harmless looking 
15012 \begin_inset Quotes srd
15013 \end_inset
15014
15015
15016 \family typewriter
15017 flags\InsetSpace ~
15018 |=\InsetSpace ~
15019 0x80;
15020 \family default
15021
15022 \begin_inset Quotes sld
15023 \end_inset
15024
15025  is not atomic if 
15026 \family typewriter
15027 flags
15028 \family default
15029  resides in xdata.
15030  Setting 
15031 \begin_inset Quotes srd
15032 \end_inset
15033
15034
15035 \family typewriter
15036 flags\InsetSpace ~
15037 |=\InsetSpace ~
15038 0x40;
15039 \family default
15040
15041 \begin_inset Quotes sld
15042 \end_inset
15043
15044  from within an interrupt routine might get lost if the interrupt occurs
15045  at the wrong time.
15046  
15047 \begin_inset Quotes sld
15048 \end_inset
15049
15050
15051 \family typewriter
15052 counter\InsetSpace ~
15053 +=\InsetSpace ~
15054 8;
15055 \family default
15056
15057 \begin_inset Quotes srd
15058 \end_inset
15059
15060  is not atomic on the 8051 even if 
15061 \family typewriter
15062 counter
15063 \family default
15064  is located in data memory.
15065 \newline
15066 Bugs like these are hard to reproduce and can
15067  cause a lot of trouble.
15068  
15069 \end_layout
15070
15071 \begin_layout Subsubsection
15072 \begin_inset LatexCommand label
15073 name "sub:Common-interrupt-pitfall-stack-overflow"
15074
15075 \end_inset
15076
15077 Common interrupt pitfall: 
15078 \emph on
15079 stack overflow
15080 \end_layout
15081
15082 \begin_layout Standard
15083 The return address and the registers used in the interrupt service routine
15084  are saved on the stack
15085 \begin_inset LatexCommand index
15086 name "stack"
15087
15088 \end_inset
15089
15090  so there must be sufficient stack space.
15091  If there isn't variables or registers (or even the return address itself)
15092  will be corrupted.
15093  This 
15094 \emph on
15095 stack overflow
15096 \emph default
15097
15098 \begin_inset LatexCommand index
15099 name "stack overflow"
15100
15101 \end_inset
15102
15103  is most likely to happen if the interrupt occurs during the 
15104 \begin_inset Quotes sld
15105 \end_inset
15106
15107 deepest
15108 \begin_inset Quotes srd
15109 \end_inset
15110
15111  subroutine when the stack is already in use for f.e.
15112  many return addresses.
15113 \end_layout
15114
15115 \begin_layout Subsubsection
15116 \begin_inset LatexCommand label
15117 name "sub:Common-interrupt-pitfall-non-reentrant"
15118
15119 \end_inset
15120
15121 Common interrupt pitfall: 
15122 \emph on
15123 use of non-reentrant functions
15124 \end_layout
15125
15126 \begin_layout Standard
15127 A special note here, int (16 bit) and long (32 bit) integer division
15128 \begin_inset LatexCommand index
15129 name "Division"
15130
15131 \end_inset
15132
15133 , multiplication
15134 \begin_inset LatexCommand index
15135 name "Multiplication"
15136
15137 \end_inset
15138
15139  & modulus
15140 \begin_inset LatexCommand index
15141 name "Modulus"
15142
15143 \end_inset
15144
15145  and floating-point
15146 \begin_inset LatexCommand index
15147 name "Floating point support"
15148
15149 \end_inset
15150
15151  operations are implemented using external support routines.
15152  If an interrupt service routine needs to do any of these operations then
15153  the support routines (as mentioned in a following section) will have to
15154  be recompiled using the 
15155 \emph on
15156 -
15157 \begin_inset ERT
15158 status collapsed
15159
15160 \begin_layout Standard
15161
15162
15163 \backslash
15164 /
15165 \end_layout
15166
15167 \end_inset
15168
15169 -stack-auto
15170 \begin_inset LatexCommand index
15171 name "-\\/-stack-auto"
15172
15173 \end_inset
15174
15175
15176 \emph default
15177  option and the source file will need to be compiled using the 
15178 \emph on
15179 -
15180 \begin_inset ERT
15181 status collapsed
15182
15183 \begin_layout Standard
15184
15185
15186 \backslash
15187 /
15188 \end_layout
15189
15190 \end_inset
15191
15192 -int-long-reent
15193 \emph default
15194
15195 \begin_inset LatexCommand index
15196 name "-\\/-int-long-reent"
15197
15198 \end_inset
15199
15200  compiler option.
15201  
15202 \newline
15203 Note, the type promotion
15204 \begin_inset LatexCommand index
15205 name "type promotion"
15206
15207 \end_inset
15208
15209  required by ANSI C can cause 16 bit routines to be used
15210 \begin_inset Marginal
15211 status collapsed
15212
15213 \begin_layout Standard
15214
15215 \series bold
15216 \InsetSpace ~
15217 !
15218 \end_layout
15219
15220 \end_inset
15221
15222  without the programmer being aware of it.
15223  See f.e.
15224  the cast 
15225 \family typewriter
15226 \series bold
15227 (unsigned char)(tail-1)
15228 \family default
15229 \series default
15230  
15231 \series bold
15232 within the if clause in section 
15233 \begin_inset LatexCommand ref
15234 reference "sub:A-Step-by Assembler Introduction"
15235
15236 \end_inset
15237
15238 .
15239 \end_layout
15240
15241 \begin_layout Standard
15242 Calling other functions from an interrupt service routine is not recommended,
15243  avoid it if possible.
15244  Note that when some function is called from an interrupt service routine
15245  it should be preceded by a #pragma\InsetSpace ~
15246 nooverlay
15247 \begin_inset LatexCommand index
15248 name "\\#pragma nooverlay"
15249
15250 \end_inset
15251
15252  if it is not reentrant.
15253  Furthermore nonreentrant functions should not be called from the main program
15254  while the interrupt service routine might be active.
15255  They also must not be called from low priority interrupt service routines
15256  while a high priority interrupt service routine might be active.
15257  You could use semaphores or make the function 
15258 \emph on
15259 critical
15260 \emph default
15261  if all parameters are passed in registers.
15262 \newline
15263  Also see section 
15264 \begin_inset LatexCommand ref
15265 reference "sub:Overlaying"
15266
15267 \end_inset
15268
15269 \InsetSpace ~
15270 about Overlaying and section 
15271 \begin_inset LatexCommand ref
15272 reference "sub:Functions-using-private-banks"
15273
15274 \end_inset
15275
15276 \InsetSpace ~
15277 about Functions using private register banks.
15278 \begin_inset VSpace bigskip
15279 \end_inset
15280
15281
15282 \end_layout
15283
15284 \begin_layout Subsection
15285 MCS51/DS390 Interrupt Service Routines
15286 \end_layout
15287
15288 \begin_layout Standard
15289 Interrupt
15290 \begin_inset LatexCommand index
15291 name "interrupt"
15292
15293 \end_inset
15294
15295  numbers and the corresponding address & descriptions for the Standard 8051/8052
15296  are listed below.
15297  SDCC will automatically adjust the 
15298 \begin_inset LatexCommand index
15299 name "interrupt vector table"
15300
15301 \end_inset
15302
15303  to the maximum interrupt number specified.
15304 \newline
15305
15306 \end_layout
15307
15308 \begin_layout Standard
15309 \align center
15310 \begin_inset Tabular
15311 <lyxtabular version="3" rows="9" columns="3">
15312 <features>
15313 <column alignment="center" valignment="top" leftline="true" width="0in">
15314 <column alignment="left" valignment="top" leftline="true" width="0in">
15315 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
15316 <row topline="true" bottomline="true">
15317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15318 \begin_inset Text
15319
15320 \begin_layout Standard
15321 Interrupt #
15322 \end_layout
15323
15324 \end_inset
15325 </cell>
15326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15327 \begin_inset Text
15328
15329 \begin_layout Standard
15330 Description
15331 \end_layout
15332
15333 \end_inset
15334 </cell>
15335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15336 \begin_inset Text
15337
15338 \begin_layout Standard
15339 Vector Address
15340 \end_layout
15341
15342 \end_inset
15343 </cell>
15344 </row>
15345 <row topline="true">
15346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15347 \begin_inset Text
15348
15349 \begin_layout Standard
15350 0
15351 \end_layout
15352
15353 \end_inset
15354 </cell>
15355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15356 \begin_inset Text
15357
15358 \begin_layout Standard
15359 External 0
15360 \end_layout
15361
15362 \end_inset
15363 </cell>
15364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15365 \begin_inset Text
15366
15367 \begin_layout Standard
15368 0x0003
15369 \end_layout
15370
15371 \end_inset
15372 </cell>
15373 </row>
15374 <row topline="true">
15375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15376 \begin_inset Text
15377
15378 \begin_layout Standard
15379 1
15380 \end_layout
15381
15382 \end_inset
15383 </cell>
15384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15385 \begin_inset Text
15386
15387 \begin_layout Standard
15388 Timer 0
15389 \end_layout
15390
15391 \end_inset
15392 </cell>
15393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15394 \begin_inset Text
15395
15396 \begin_layout Standard
15397 0x000b
15398 \end_layout
15399
15400 \end_inset
15401 </cell>
15402 </row>
15403 <row topline="true">
15404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15405 \begin_inset Text
15406
15407 \begin_layout Standard
15408 2
15409 \end_layout
15410
15411 \end_inset
15412 </cell>
15413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15414 \begin_inset Text
15415
15416 \begin_layout Standard
15417 External 1
15418 \end_layout
15419
15420 \end_inset
15421 </cell>
15422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15423 \begin_inset Text
15424
15425 \begin_layout Standard
15426 0x0013
15427 \end_layout
15428
15429 \end_inset
15430 </cell>
15431 </row>
15432 <row topline="true">
15433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15434 \begin_inset Text
15435
15436 \begin_layout Standard
15437 3
15438 \end_layout
15439
15440 \end_inset
15441 </cell>
15442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15443 \begin_inset Text
15444
15445 \begin_layout Standard
15446 Timer 1
15447 \end_layout
15448
15449 \end_inset
15450 </cell>
15451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15452 \begin_inset Text
15453
15454 \begin_layout Standard
15455 0x001b
15456 \end_layout
15457
15458 \end_inset
15459 </cell>
15460 </row>
15461 <row topline="true">
15462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15463 \begin_inset Text
15464
15465 \begin_layout Standard
15466 4
15467 \end_layout
15468
15469 \end_inset
15470 </cell>
15471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15472 \begin_inset Text
15473
15474 \begin_layout Standard
15475 Serial
15476 \end_layout
15477
15478 \end_inset
15479 </cell>
15480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15481 \begin_inset Text
15482
15483 \begin_layout Standard
15484 0x0023
15485 \end_layout
15486
15487 \end_inset
15488 </cell>
15489 </row>
15490 <row topline="true">
15491 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15492 \begin_inset Text
15493
15494 \begin_layout Standard
15495 5
15496 \end_layout
15497
15498 \end_inset
15499 </cell>
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15501 \begin_inset Text
15502
15503 \begin_layout Standard
15504 Timer 2 (8052)
15505 \end_layout
15506
15507 \end_inset
15508 </cell>
15509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15510 \begin_inset Text
15511
15512 \begin_layout Standard
15513 0x002b
15514 \end_layout
15515
15516 \end_inset
15517 </cell>
15518 </row>
15519 <row topline="true">
15520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15521 \begin_inset Text
15522
15523 \begin_layout Standard
15524 ...
15525 \end_layout
15526
15527 \end_inset
15528 </cell>
15529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15530 \begin_inset Text
15531
15532 \begin_layout Standard
15533
15534 \end_layout
15535
15536 \end_inset
15537 </cell>
15538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15539 \begin_inset Text
15540
15541 \begin_layout Standard
15542 ...
15543 \end_layout
15544
15545 \end_inset
15546 </cell>
15547 </row>
15548 <row topline="true" bottomline="true">
15549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15550 \begin_inset Text
15551
15552 \begin_layout Standard
15553 n
15554 \end_layout
15555
15556 \end_inset
15557 </cell>
15558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15559 \begin_inset Text
15560
15561 \begin_layout Standard
15562
15563 \end_layout
15564
15565 \end_inset
15566 </cell>
15567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15568 \begin_inset Text
15569
15570 \begin_layout Standard
15571 0x0003 + 8*n
15572 \end_layout
15573
15574 \end_inset
15575 </cell>
15576 </row>
15577 </lyxtabular>
15578
15579 \end_inset
15580
15581
15582 \newline
15583
15584 \end_layout
15585
15586 \begin_layout Standard
15587 If the interrupt service routine is defined without 
15588 \emph on
15589 using
15590 \begin_inset LatexCommand index
15591 name "using (mcs51, ds390 register bank)"
15592
15593 \end_inset
15594
15595
15596 \begin_inset LatexCommand index
15597 name "\\_\\_using (mcs51, ds390 register bank)"
15598
15599 \end_inset
15600
15601
15602 \emph default
15603  a register bank or with register bank 0 (
15604 \emph on
15605 using
15606 \emph default
15607  0), the compiler will save the registers used by itself on the stack upon
15608  entry and restore them at exit, however if such an interrupt service routine
15609  calls another function then the entire register bank will be saved on the
15610  stack.
15611  This scheme may be advantageous for small interrupt service routines which
15612  have low register usage.
15613 \end_layout
15614
15615 \begin_layout Standard
15616 If the interrupt service routine is defined to be using a specific register
15617  bank then only 
15618 \emph on
15619 a, b, dptr
15620 \emph default
15621  & psw are saved and restored, if such an interrupt service routine calls
15622  another function (using another register bank) then the entire register
15623  bank of the called function will be saved on the stack
15624 \begin_inset LatexCommand index
15625 name "stack"
15626
15627 \end_inset
15628
15629 .
15630  This scheme is recommended for larger interrupt service routines.
15631 \begin_inset VSpace bigskip
15632 \end_inset
15633
15634
15635 \end_layout
15636
15637 \begin_layout Subsection
15638 HC08
15639 \begin_inset LatexCommand index
15640 name "HC08"
15641
15642 \end_inset
15643
15644  Interrupt Service Routines
15645 \end_layout
15646
15647 \begin_layout Standard
15648 Since the number of interrupts
15649 \begin_inset LatexCommand index
15650 name "HC08!interrupt"
15651
15652 \end_inset
15653
15654  available is chip specific and the interrupt vector table always ends at
15655  the last byte of memory, the interrupt numbers corresponds to the interrupt
15656  vectors in reverse order of address.
15657  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15658  2 will use the interrupt vector at 0xfffa, and so on.
15659  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15660  this way; instead see section 
15661 \begin_inset LatexCommand ref
15662 reference "sub:Startup-Code"
15663
15664 \end_inset
15665
15666  for details on customizing startup.
15667 \begin_inset VSpace bigskip
15668 \end_inset
15669
15670
15671 \end_layout
15672
15673 \begin_layout Subsection
15674 Z80 Interrupt Service Routines
15675 \end_layout
15676
15677 \begin_layout Standard
15678 The Z80
15679 \begin_inset LatexCommand index
15680 name "Z80"
15681
15682 \end_inset
15683
15684  uses several different methods for determining the correct interrupt
15685 \begin_inset LatexCommand index
15686 name "Z80!interrupt"
15687
15688 \end_inset
15689
15690  vector depending on the hardware implementation.
15691  Therefore, SDCC ignores the optional interrupt number and does not attempt
15692  to generate an interrupt vector table.
15693 \end_layout
15694
15695 \begin_layout Standard
15696 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15697  instruction to return from the interrupt.
15698  To write an interrupt handler for the non-maskable interrupt, which needs
15699  a RETN instruction instead, add the 
15700 \emph on
15701 critical
15702 \emph default
15703  keyword:
15704 \end_layout
15705
15706 \begin_layout Verse
15707
15708 \family typewriter
15709 void nmi_isr (void) critical interrupt
15710 \newline
15711
15712 \newline
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 \InsetSpace ~
15716 \InsetSpace ~
15717 ...
15718  
15719 \newline
15720 }
15721 \end_layout
15722
15723 \begin_layout Standard
15724 However if you need to create a non-interruptable interrupt service routine
15725  you would also require the 
15726 \emph on
15727 critical
15728 \emph default
15729  keyword.
15730  To distinguish between this and an nmi_isr you must provide an interrupt
15731  number.
15732 \begin_inset VSpace bigskip
15733 \end_inset
15734
15735
15736 \end_layout
15737
15738 \begin_layout Section
15739 Enabling and Disabling Interrupts
15740 \end_layout
15741
15742 \begin_layout Subsection
15743 Critical Functions and Critical Statements
15744 \end_layout
15745
15746 \begin_layout Standard
15747 A special keyword may be associated with a block or a function declaring
15748  it as 
15749 \emph on
15750 critical
15751 \emph default
15752 .
15753  SDCC will generate code to disable all interrupts
15754 \begin_inset LatexCommand index
15755 name "interrupt"
15756
15757 \end_inset
15758
15759  upon entry to a critical function and restore the interrupt enable to the
15760  previous state before returning.
15761  Nesting critical functions will need one additional byte on the stack
15762 \begin_inset LatexCommand index
15763 name "stack"
15764
15765 \end_inset
15766
15767  for each call.
15768 \end_layout
15769
15770 \begin_layout Verse
15771
15772 \family typewriter
15773 int foo () __critical
15774 \begin_inset LatexCommand index
15775 name "critical"
15776
15777 \end_inset
15778
15779
15780 \begin_inset LatexCommand index
15781 name "\\_\\_critical"
15782
15783 \end_inset
15784
15785  
15786 \newline
15787
15788 \newline
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 ...
15794  
15795 \newline
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 ...
15801  
15802 \newline
15803 }
15804 \end_layout
15805
15806 \begin_layout Standard
15807 The critical attribute maybe used with other attributes like 
15808 \emph on
15809 reentrant.
15810 \emph default
15811
15812 \newline
15813 The keyword 
15814 \emph on
15815 critical
15816 \emph default
15817  may also be used to disable interrupts more locally:
15818 \end_layout
15819
15820 \begin_layout Verse
15821
15822 \family typewriter
15823 __critical{ i++; }
15824 \end_layout
15825
15826 \begin_layout Standard
15827 More than one statement could have been included in the block.
15828 \end_layout
15829
15830 \begin_layout Subsection
15831 Enabling and Disabling Interrupts directly
15832 \end_layout
15833
15834 \begin_layout Standard
15835 Interrupts
15836 \begin_inset LatexCommand index
15837 name "interrupt"
15838
15839 \end_inset
15840
15841  can also be disabled and enabled directly (8051):
15842 \end_layout
15843
15844 \begin_layout Verse
15845
15846 \family typewriter
15847 EA = 0;\InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 \InsetSpace ~
15853 \InsetSpace ~
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 or:\InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 \InsetSpace ~
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 EA_SAVE = EA;
15871 \end_layout
15872
15873 \begin_layout Verse
15874
15875 \family typewriter
15876 ...\InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 EA = 0;
15907 \end_layout
15908
15909 \begin_layout Verse
15910
15911 \family typewriter
15912 EA = 1;\InsetSpace ~
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 \InsetSpace ~
15938 ...
15939 \end_layout
15940
15941 \begin_layout Verse
15942
15943 \family typewriter
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 \InsetSpace ~
15958 \InsetSpace ~
15959 \InsetSpace ~
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 \InsetSpace ~
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 EA = EA_SAVE;
15978 \end_layout
15979
15980 \begin_layout Standard
15981 On other architectures which have separate opcodes for enabling and disabling
15982  interrupts you might want to make use of defines with inline assembly
15983 \begin_inset LatexCommand index
15984 name "Assembler routines"
15985
15986 \end_inset
15987
15988  (HC08
15989 \begin_inset LatexCommand index
15990 name "HC08!interrupt"
15991
15992 \end_inset
15993
15994 ):
15995 \end_layout
15996
15997 \begin_layout Verse
15998
15999 \family typewriter
16000 #define CLI _asm
16001 \begin_inset LatexCommand index
16002 name "\\_asm"
16003
16004 \end_inset
16005
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 cli\InsetSpace ~
16009 \InsetSpace ~
16010 _endasm
16011 \begin_inset LatexCommand index
16012 name "\\_endasm"
16013
16014 \end_inset
16015
16016
16017 \end_layout
16018
16019 \begin_layout Verse
16020
16021 \family typewriter
16022 #define SEI _asm\InsetSpace ~
16023 \InsetSpace ~
16024 sei\InsetSpace ~
16025 \InsetSpace ~
16026 _endasm; 
16027 \end_layout
16028
16029 \begin_layout Verse
16030
16031 \family typewriter
16032 ...
16033 \end_layout
16034
16035 \begin_layout Standard
16036 Note: it is sometimes sufficient to disable only a specific interrupt source
16037  like f.e.
16038  a timer or serial interrupt by manipulating an 
16039 \emph on
16040 interrupt mask
16041 \begin_inset LatexCommand index
16042 name "interrupt mask"
16043
16044 \end_inset
16045
16046
16047 \emph default
16048  register.
16049  
16050 \end_layout
16051
16052 \begin_layout Standard
16053 Usually the time during which interrupts are disabled should be kept as
16054  short as possible.
16055  This minimizes both 
16056 \emph on
16057 interrupt latency
16058 \emph default
16059
16060 \begin_inset LatexCommand index
16061 name "interrupt latency"
16062
16063 \end_inset
16064
16065  (the time between the occurrence of the interrupt and the execution of
16066  the first code in the interrupt routine) and 
16067 \emph on
16068 interrupt jitter
16069 \emph default
16070
16071 \begin_inset LatexCommand index
16072 name "interrupt jitter"
16073
16074 \end_inset
16075
16076  (the difference between the shortest and the longest interrupt latency).
16077  These really are something different, f.e.
16078  a serial interrupt has to be served before its buffer overruns so it cares
16079  for the maximum interrupt latency, whereas it does not care about jitter.
16080  On a loudspeaker driven via a digital to analog converter which is fed
16081  by an interrupt a latency of a few milliseconds might be tolerable, whereas
16082  a much smaller jitter will be very audible.
16083 \end_layout
16084
16085 \begin_layout Standard
16086 You can reenable interrupts within an interrupt routine and on some architecture
16087 s you can make use of two (or more) levels of 
16088 \emph on
16089 interrupt priorities
16090 \emph default
16091
16092 \begin_inset LatexCommand index
16093 name "interrupt priority"
16094
16095 \end_inset
16096
16097 .
16098  On some architectures which don't support interrupt priorities these can
16099  be implemented by manipulating the interrupt mask and reenabling interrupts
16100  within the interrupt routine.
16101  Check there is sufficient space on the stack
16102 \begin_inset LatexCommand index
16103 name "stack"
16104
16105 \end_inset
16106
16107  and don't add complexity unless you have to.
16108  
16109 \end_layout
16110
16111 \begin_layout Subsection
16112 Semaphore
16113 \begin_inset LatexCommand index
16114 name "semaphore"
16115
16116 \end_inset
16117
16118  locking (mcs51/ds390)
16119 \end_layout
16120
16121 \begin_layout Standard
16122 Some architectures (mcs51/ds390) have an atomic
16123 \begin_inset LatexCommand index
16124 name "atomic"
16125
16126 \end_inset
16127
16128  bit test and clear instruction.
16129  These type of instructions are typically used in preemptive multitasking
16130  systems, where a routine f.e.
16131  claims the use of a data structure ('acquires a lock
16132 \begin_inset LatexCommand index
16133 name "lock"
16134
16135 \end_inset
16136
16137  on it'), makes some modifications and then releases the lock when the data
16138  structure is consistent again.
16139  The instruction may also be used if interrupt and non-interrupt code have
16140  to compete for a resource.
16141  With the atomic bit test and clear instruction interrupts
16142 \begin_inset LatexCommand index
16143 name "interrupt"
16144
16145 \end_inset
16146
16147  don't have to be disabled for the locking operation.
16148  
16149 \end_layout
16150
16151 \begin_layout Standard
16152 SDCC generates this instruction if the source follows this pattern:
16153 \end_layout
16154
16155 \begin_layout Verse
16156
16157 \family typewriter
16158 volatile
16159 \begin_inset LatexCommand index
16160 name "volatile"
16161
16162 \end_inset
16163
16164  bit resource_is_free; 
16165 \newline
16166
16167 \newline
16168 if (resource_is_free) 
16169 \newline
16170 \InsetSpace ~
16171 \InsetSpace ~
16172
16173 \newline
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 resource_is_free=0; 
16179 \newline
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 ...
16185  
16186 \newline
16187 \InsetSpace ~
16188 \InsetSpace ~
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 resource_is_free=1;
16192 \newline
16193 \InsetSpace ~
16194 \InsetSpace ~
16195
16196 \end_layout
16197
16198 \begin_layout Standard
16199 Note, mcs51 and ds390 support only an atomic
16200 \begin_inset LatexCommand index
16201 name "atomic"
16202
16203 \end_inset
16204
16205  bit test and 
16206 \emph on
16207 clear
16208 \emph default
16209  instruction (as opposed to atomic bit test and 
16210 \emph on
16211 set).
16212 \end_layout
16213
16214 \begin_layout Section
16215 Functions using private register banks
16216 \begin_inset LatexCommand label
16217 name "sub:Functions-using-private-banks"
16218
16219 \end_inset
16220
16221  (mcs51/ds390)
16222 \end_layout
16223
16224 \begin_layout Standard
16225 Some architectures have support for quickly changing register sets.
16226  SDCC supports this feature with the 
16227 \emph on
16228 using
16229 \begin_inset LatexCommand index
16230 name "using (mcs51, ds390 register bank)"
16231
16232 \end_inset
16233
16234
16235 \begin_inset LatexCommand index
16236 name "\\_\\_using (mcs51, ds390 register bank)"
16237
16238 \end_inset
16239
16240
16241 \emph default
16242  attribute (which tells the compiler to use a register bank
16243 \begin_inset LatexCommand index
16244 name "register bank (mcs51, ds390)"
16245
16246 \end_inset
16247
16248  other than the default bank zero).
16249  It should only be applied to 
16250 \emph on
16251 interrupt
16252 \begin_inset LatexCommand index
16253 name "interrupt"
16254
16255 \end_inset
16256
16257
16258 \emph default
16259  functions (see footnote below).
16260  This will in most circumstances make the generated ISR code more efficient
16261  since it will not have to save registers on the stack.
16262 \end_layout
16263
16264 \begin_layout Standard
16265 The 
16266 \emph on
16267 using
16268 \emph default
16269  attribute will have no effect on the generated code for a 
16270 \emph on
16271 non-interrupt
16272 \emph default
16273  function (but may occasionally be useful anyway
16274 \begin_inset Foot
16275 status open
16276
16277 \begin_layout Standard
16278 possible exception: if a function is called ONLY from 'interrupt' functions
16279  using a particular bank, it can be declared with the same 'using' attribute
16280  as the calling 'interrupt' functions.
16281  For instance, if you have several ISRs using bank one, and all of them
16282  call memcpy(), it might make sense to create a specialized version of memcpy()
16283  'using 1', since this would prevent the ISR from having to save bank zero
16284  to the stack on entry and switch to bank zero before calling the function
16285 \end_layout
16286
16287 \end_inset
16288
16289 ).
16290 \newline
16291
16292 \emph on
16293 (pending: Note, nowadays the
16294 \emph default
16295  using 
16296 \emph on
16297 attribute has an effect on
16298 \emph default
16299  
16300 \emph on
16301 the generated code for a
16302 \emph default
16303  non-interrupt 
16304 \emph on
16305 function
16306 \emph default
16307 .
16308 \emph on
16309 )
16310 \end_layout
16311
16312 \begin_layout Standard
16313 An 
16314 \emph on
16315 interrupt
16316 \emph default
16317  function using a non-zero bank will assume that it can trash that register
16318  bank, and will not save it.
16319  Since high-priority interrupts
16320 \begin_inset LatexCommand index
16321 name "interrupts"
16322
16323 \end_inset
16324
16325
16326 \begin_inset LatexCommand index
16327 name "interrupt priority"
16328
16329 \end_inset
16330
16331  can interrupt low-priority ones on the 8051 and friends, this means that
16332  if a high-priority ISR 
16333 \emph on
16334 using
16335 \emph default
16336  a particular bank occurs while processing a low-priority ISR 
16337 \emph on
16338 using
16339 \emph default
16340  the same bank, terrible and bad things can happen.
16341  To prevent this, no single register bank should be 
16342 \emph on
16343 used
16344 \emph default
16345  by both a high priority and a low priority ISR.
16346  This is probably most easily done by having all high priority ISRs use
16347  one bank and all low priority ISRs use another.
16348  If you have an ISR which can change priority at runtime, you're on your
16349  own: I suggest using the default bank zero and taking the small performance
16350  hit.
16351 \end_layout
16352
16353 \begin_layout Standard
16354 It is most efficient if your ISR calls no other functions.
16355  If your ISR must call other functions, it is most efficient if those functions
16356  use the same bank as the ISR (see note 1 below); the next best is if the
16357  called functions use bank zero.
16358  It is very inefficient to call a function using a different, non-zero bank
16359  from an ISR.
16360  
16361 \begin_inset VSpace bigskip
16362 \end_inset
16363
16364
16365 \end_layout
16366
16367 \begin_layout Section
16368 Startup Code
16369 \begin_inset LatexCommand label
16370 name "sub:Startup-Code"
16371
16372 \end_inset
16373
16374
16375 \begin_inset LatexCommand index
16376 name "Startup code"
16377
16378 \end_inset
16379
16380
16381 \end_layout
16382
16383 \begin_layout Subsection
16384 MCS51/DS390 Startup Code
16385 \end_layout
16386
16387 \begin_layout Standard
16388 The compiler triggers the linker to link certain initialization modules
16389  from the runtime library
16390 \begin_inset LatexCommand index
16391 name "Runtime library"
16392
16393 \end_inset
16394
16395  called crt<something>.
16396  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
16397  GSINIT5) is not linked unless the -
16398 \series bold
16399
16400 \begin_inset ERT
16401 status open
16402
16403 \begin_layout Standard
16404
16405
16406 \backslash
16407 /
16408 \end_layout
16409
16410 \end_inset
16411
16412
16413 \series default
16414 -xstack option is used.
16415  These modules are highly entangled by the use of special segments/areas,
16416  but a common layout is shown below:
16417 \end_layout
16418
16419 \begin_layout Verse
16420
16421 \family typewriter
16422 \series bold
16423 \size footnotesize
16424 (main.asm)
16425 \end_layout
16426
16427 \begin_layout Verse
16428
16429 \family typewriter
16430 \size footnotesize
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 \InsetSpace ~
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 .area HOME (CODE)
16440 \newline
16441 __interrupt_vect:
16442 \newline
16443 \InsetSpace ~
16444 \InsetSpace ~
16445 \InsetSpace ~
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 ljmp __sdcc_gsinit_startup
16452 \end_layout
16453
16454 \begin_layout Verse
16455
16456 \family typewriter
16457 \series bold
16458 \size footnotesize
16459 (crtstart.asm)
16460 \end_layout
16461
16462 \begin_layout Verse
16463
16464 \family typewriter
16465 \size footnotesize
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 \InsetSpace ~
16470 \InsetSpace ~
16471 \InsetSpace ~
16472 \InsetSpace ~
16473 \InsetSpace ~
16474 .area GSINIT0 (CODE)
16475 \newline
16476 __sdcc_gsinit_startup::
16477 \newline
16478 \InsetSpace ~
16479 \InsetSpace ~
16480 \InsetSpace ~
16481 \InsetSpace ~
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 \InsetSpace ~
16486 mov sp,#__start__stack - 1
16487 \end_layout
16488
16489 \begin_layout Verse
16490
16491 \family typewriter
16492 \series bold
16493 \size footnotesize
16494 (crtxstack.asm)
16495 \end_layout
16496
16497 \begin_layout Verse
16498
16499 \family typewriter
16500 \size footnotesize
16501 \InsetSpace ~
16502 \InsetSpace ~
16503 \InsetSpace ~
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 \InsetSpace ~
16509 .area GSINIT1 (CODE)
16510 \newline
16511 __sdcc_init_xstack::
16512 \newline
16513 ; Need to initialize in GSINIT1 in
16514  case the user's __sdcc_external_startup uses the xstack.
16515 \newline
16516 \InsetSpace ~
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 \InsetSpace ~
16524 mov __XPAGE,#(__start__x
16525 stack >> 8)
16526 \newline
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 \InsetSpace ~
16531 \InsetSpace ~
16532 \InsetSpace ~
16533 \InsetSpace ~
16534 \InsetSpace ~
16535 mov _spx,#__start__xstack
16536 \end_layout
16537
16538 \begin_layout Verse
16539
16540 \family typewriter
16541 \series bold
16542 \size footnotesize
16543 (crtstart.asm)
16544 \end_layout
16545
16546 \begin_layout Verse
16547
16548 \family typewriter
16549 \size footnotesize
16550 \InsetSpace ~
16551 \InsetSpace ~
16552 \InsetSpace ~
16553 \InsetSpace ~
16554 \InsetSpace ~
16555 \InsetSpace ~
16556 \InsetSpace ~
16557 \InsetSpace ~
16558 .area GSINIT2 (CODE)
16559 \newline
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 \InsetSpace ~
16564 \InsetSpace ~
16565 \InsetSpace ~
16566 \InsetSpace ~
16567 \InsetSpace ~
16568 lcall __sdcc_external_startup
16569 \newline
16570 \InsetSpace ~
16571 \InsetSpace ~
16572 \InsetSpace ~
16573 \InsetSpace ~
16574 \InsetSpace ~
16575 \InsetSpace ~
16576 \InsetSpace ~
16577 \InsetSpace ~
16578 mov a,dpl
16579 \newline
16580 \InsetSpace ~
16581 \InsetSpace ~
16582 \InsetSpace ~
16583 \InsetSpace ~
16584 \InsetSpace ~
16585 \InsetSpace ~
16586 \InsetSpace ~
16587 \InsetSpace ~
16588 jz __sdcc_init_data
16589 \newline
16590 \InsetSpace ~
16591 \InsetSpace ~
16592 \InsetSpace ~
16593 \InsetSpace ~
16594 \InsetSpace ~
16595 \InsetSpace ~
16596 \InsetSpace ~
16597 \InsetSpace ~
16598 ljmp
16599  __sdcc_program_startup
16600 \newline
16601 __sdcc_init_data:
16602 \end_layout
16603
16604 \begin_layout Verse
16605
16606 \family typewriter
16607 \series bold
16608 \size footnotesize
16609 (crtxinit.asm)
16610 \end_layout
16611
16612 \begin_layout Verse
16613
16614 \family typewriter
16615 \size footnotesize
16616 \InsetSpace ~
16617 \InsetSpace ~
16618 \InsetSpace ~
16619 \InsetSpace ~
16620 \InsetSpace ~
16621 \InsetSpace ~
16622 \InsetSpace ~
16623 \InsetSpace ~
16624 .area GSINIT3 (CODE)
16625 \newline
16626 __mcs51_genXINIT::
16627 \newline
16628 \InsetSpace ~
16629 \InsetSpace ~
16630 \InsetSpace ~
16631 \InsetSpace ~
16632 \InsetSpace ~
16633 \InsetSpace ~
16634 \InsetSpace ~
16635 \InsetSpace ~
16636 mov r1,#l_XINIT
16637 \newline
16638 \InsetSpace ~
16639 \InsetSpace ~
16640 \InsetSpace ~
16641 \InsetSpace ~
16642 \InsetSpace ~
16643 \InsetSpace ~
16644 \InsetSpace ~
16645 \InsetSpace ~
16646 mov a,r1
16647 \newline
16648 \InsetSpace ~
16649 \InsetSpace ~
16650 \InsetSpace ~
16651 \InsetSpace ~
16652 \InsetSpace ~
16653 \InsetSpace ~
16654 \InsetSpace ~
16655 \InsetSpace ~
16656 orl a,#(l_XINIT
16657  >> 8)
16658 \newline
16659 \InsetSpace ~
16660 \InsetSpace ~
16661 \InsetSpace ~
16662 \InsetSpace ~
16663 \InsetSpace ~
16664 \InsetSpace ~
16665 \InsetSpace ~
16666 \InsetSpace ~
16667 jz 00003$
16668 \newline
16669 \InsetSpace ~
16670 \InsetSpace ~
16671 \InsetSpace ~
16672 \InsetSpace ~
16673 \InsetSpace ~
16674 \InsetSpace ~
16675 \InsetSpace ~
16676 \InsetSpace ~
16677 mov r2,#((l_XINIT+255) >> 8)
16678 \newline
16679 \InsetSpace ~
16680 \InsetSpace ~
16681 \InsetSpace ~
16682 \InsetSpace ~
16683 \InsetSpace ~
16684 \InsetSpace ~
16685 \InsetSpace ~
16686 \InsetSpace ~
16687 mov dptr,#s_XINIT
16688 \newline
16689 \InsetSpace ~
16690 \InsetSpace ~
16691 \InsetSpace ~
16692 \InsetSpace ~
16693 \InsetSpace ~
16694 \InsetSpace ~
16695 \InsetSpace ~
16696 \InsetSpace ~
16697 mov r0,#s_XISEG
16698 \newline
16699 \InsetSpace ~
16700 \InsetSpace ~
16701 \InsetSpace ~
16702 \InsetSpace ~
16703 \InsetSpace ~
16704 \InsetSpace ~
16705 \InsetSpace ~
16706 \InsetSpace ~
16707 mov
16708  __XPAGE,#(s_XISEG >> 8)
16709 \newline
16710 00001$:\InsetSpace ~
16711 clr a
16712 \newline
16713 \InsetSpace ~
16714 \InsetSpace ~
16715 \InsetSpace ~
16716 \InsetSpace ~
16717 \InsetSpace ~
16718 \InsetSpace ~
16719 \InsetSpace ~
16720 \InsetSpace ~
16721 movc a,@a+dptr
16722 \newline
16723 \InsetSpace ~
16724 \InsetSpace ~
16725 \InsetSpace ~
16726 \InsetSpace ~
16727 \InsetSpace ~
16728 \InsetSpace ~
16729 \InsetSpace ~
16730 \InsetSpace ~
16731 movx @r0,a
16732 \newline
16733 \InsetSpace ~
16734 \InsetSpace ~
16735 \InsetSpace ~
16736 \InsetSpace ~
16737 \InsetSpace ~
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 \InsetSpace ~
16741 inc dptr
16742 \newline
16743 \InsetSpace ~
16744 \InsetSpace ~
16745 \InsetSpace ~
16746 \InsetSpace ~
16747 \InsetSpace ~
16748 \InsetSpace ~
16749 \InsetSpace ~
16750 \InsetSpace ~
16751 inc
16752  r0
16753 \newline
16754 \InsetSpace ~
16755 \InsetSpace ~
16756 \InsetSpace ~
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 \InsetSpace ~
16760 \InsetSpace ~
16761 \InsetSpace ~
16762 cjne r0,#0,00002$
16763 \newline
16764 \InsetSpace ~
16765 \InsetSpace ~
16766 \InsetSpace ~
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 inc __XPAGE
16773 \newline
16774 00002$:\InsetSpace ~
16775 djnz r1,00001$
16776 \newline
16777 \InsetSpace ~
16778 \InsetSpace ~
16779 \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 djnz r2,00001$
16786 \newline
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 mov __XPAGE,#0
16796 xFF
16797 \newline
16798 00003$:
16799 \end_layout
16800
16801 \begin_layout Verse
16802
16803 \family typewriter
16804 \series bold
16805 \size footnotesize
16806 (crtclear.asm)
16807 \end_layout
16808
16809 \begin_layout Verse
16810
16811 \family typewriter
16812 \size footnotesize
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 .area GSINIT4 (CODE)
16822 \newline
16823 __mcs51_genRAMCLEAR::
16824 \newline
16825 \InsetSpace ~
16826 \InsetSpace ~
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 clr a
16834 \newline
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 mov r0,#(l_IRAM-1)
16844 \newline
16845 00004$:\InsetSpace ~
16846 mov
16847  @r0,a
16848 \newline
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 djnz r0,00004$
16858 \newline
16859 ; _mcs51_genRAMCLEAR() end
16860 \end_layout
16861
16862 \begin_layout Verse
16863
16864 \family typewriter
16865 \series bold
16866 \size footnotesize
16867 (crtxclear.asm)
16868 \end_layout
16869
16870 \begin_layout Verse
16871
16872 \family typewriter
16873 \size footnotesize
16874 \InsetSpace ~
16875 \InsetSpace ~
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 \InsetSpace ~
16881 \InsetSpace ~
16882 .area GSINIT4 (CODE)
16883 \newline
16884 __mcs51_genXRAMCLEAR::
16885 \newline
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 \InsetSpace ~
16890 \InsetSpace ~
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 \InsetSpace ~
16894 mov r0,#l_PSEG
16895 \newline
16896 \InsetSpace ~
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 \InsetSpace ~
16902 \InsetSpace ~
16903 \InsetSpace ~
16904 mov a,r0
16905 \newline
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 \InsetSpace ~
16912 \InsetSpace ~
16913 \InsetSpace ~
16914 orl a,#(l_PSEG
16915  >> 8)
16916 \newline
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 jz 00006$
16926 \newline
16927 \InsetSpace ~
16928 \InsetSpace ~
16929 \InsetSpace ~
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 \InsetSpace ~
16935 mov r1,#s_PSEG
16936 \newline
16937 \InsetSpace ~
16938 \InsetSpace ~
16939 \InsetSpace ~
16940 \InsetSpace ~
16941 \InsetSpace ~
16942 \InsetSpace ~
16943 \InsetSpace ~
16944 \InsetSpace ~
16945 mov __XPAGE,#(s_PSEG >> 8)
16946 \newline
16947 \InsetSpace ~
16948 \InsetSpace ~
16949 \InsetSpace ~
16950 \InsetSpace ~
16951 \InsetSpace ~
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 clr a
16956 \newline
16957 00005$:\InsetSpace ~
16958 movx
16959  @r1,a
16960 \newline
16961 \InsetSpace ~
16962 \InsetSpace ~
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 \InsetSpace ~
16968 \InsetSpace ~
16969 inc r1
16970 \newline
16971 \InsetSpace ~
16972 \InsetSpace ~
16973 \InsetSpace ~
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 \InsetSpace ~
16977 \InsetSpace ~
16978 \InsetSpace ~
16979 djnz r0,00005$
16980 \newline
16981 00006$:
16982 \newline
16983 \InsetSpace ~
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 mov r0,#l_XSEG
16992 \newline
16993 \InsetSpace ~
16994 \InsetSpace ~
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 mov a,r0
17002 \newline
17003 \InsetSpace ~
17004 \InsetSpace ~
17005 \InsetSpace ~
17006 \InsetSpace ~
17007 \InsetSpace ~
17008 \InsetSpace ~
17009 \InsetSpace ~
17010 \InsetSpace ~
17011 orl a,#(l_XSEG >>
17012  8)
17013 \newline
17014 \InsetSpace ~
17015 \InsetSpace ~
17016 \InsetSpace ~
17017 \InsetSpace ~
17018 \InsetSpace ~
17019 \InsetSpace ~
17020 \InsetSpace ~
17021 \InsetSpace ~
17022 jz 00008$
17023 \newline
17024 \InsetSpace ~
17025 \InsetSpace ~
17026 \InsetSpace ~
17027 \InsetSpace ~
17028 \InsetSpace ~
17029 \InsetSpace ~
17030 \InsetSpace ~
17031 \InsetSpace ~
17032 mov r1,#((l_XSEG + 255) >> 8)
17033 \newline
17034 \InsetSpace ~
17035 \InsetSpace ~
17036 \InsetSpace ~
17037 \InsetSpace ~
17038 \InsetSpace ~
17039 \InsetSpace ~
17040 \InsetSpace ~
17041 \InsetSpace ~
17042 mov dptr,#s_XSEG
17043 \newline
17044 \InsetSpace ~
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 \InsetSpace ~
17048 \InsetSpace ~
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 \InsetSpace ~
17052 clr a
17053 \newline
17054 00007$:\InsetSpace ~
17055 movx
17056  @dptr,a
17057 \newline
17058 \InsetSpace ~
17059 \InsetSpace ~
17060 \InsetSpace ~
17061 \InsetSpace ~
17062 \InsetSpace ~
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 \InsetSpace ~
17066 inc dptr
17067 \newline
17068 \InsetSpace ~
17069 \InsetSpace ~
17070 \InsetSpace ~
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 \InsetSpace ~
17076 djnz r0,00007$
17077 \newline
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 \InsetSpace ~
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 \InsetSpace ~
17086 djnz r1,00007$
17087 \newline
17088 00008$:
17089 \end_layout
17090
17091 \begin_layout Verse
17092
17093 \family typewriter
17094 \series bold
17095 \size footnotesize
17096 (crtxstack.asm)
17097 \end_layout
17098
17099 \begin_layout Verse
17100
17101 \family typewriter
17102 \size footnotesize
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 \InsetSpace ~
17106 \InsetSpace ~
17107 \InsetSpace ~
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 .area GSINIT5 (CODE)
17112 \newline
17113 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
17114  modifies __XPAGE
17115 \newline
17116 ; and __mcs51_genRAMCLEAR modifies _spx.
17117 \newline
17118 \InsetSpace ~
17119 \InsetSpace ~
17120 \InsetSpace ~
17121 \InsetSpace ~
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 mov __XPAGE,#(__start__x
17127 stack >> 8)
17128 \newline
17129 \InsetSpace ~
17130 \InsetSpace ~
17131 \InsetSpace ~
17132 \InsetSpace ~
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 mov _spx,#__start__xstack
17138 \end_layout
17139
17140 \begin_layout Verse
17141
17142 \family typewriter
17143 \series bold
17144 \size footnotesize
17145 (application modules)
17146 \end_layout
17147
17148 \begin_layout Verse
17149
17150 \family typewriter
17151 \size footnotesize
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 \InsetSpace ~
17157 \InsetSpace ~
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 .area GSINIT (CODE)
17161 \end_layout
17162
17163 \begin_layout Verse
17164
17165 \family typewriter
17166 \series bold
17167 \size footnotesize
17168 (main.asm)
17169 \end_layout
17170
17171 \begin_layout Verse
17172
17173 \family typewriter
17174 \size footnotesize
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 \InsetSpace ~
17179 \InsetSpace ~
17180 \InsetSpace ~
17181 \InsetSpace ~
17182 \InsetSpace ~
17183 .area GSFINAL (CODE)
17184 \newline
17185 \InsetSpace ~
17186 \InsetSpace ~
17187 \InsetSpace ~
17188 \InsetSpace ~
17189 \InsetSpace ~
17190 \InsetSpace ~
17191 \InsetSpace ~
17192 \InsetSpace ~
17193 ljmp __sdcc_program_startup
17194 \newline
17195 ;---------------------------------
17196 -----------------------
17197 \newline
17198 ; Home
17199 \newline
17200 ;--------------------------------------------------
17201 ------
17202 \newline
17203 \InsetSpace ~
17204 \InsetSpace ~
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 \InsetSpace ~
17211 .area HOME (CODE)
17212 \newline
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 \InsetSpace ~
17221 .area CSEG (CODE)
17222 \newline
17223 __sdcc_program_startup:
17224 \newline
17225 \InsetSpace ~
17226 \InsetSpace ~
17227 \InsetSpace ~
17228 \InsetSpace ~
17229 \InsetSpace ~
17230 \InsetSpace ~
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 lcall _main
17234 \newline
17235 ;
17236  return from main will lock up
17237 \newline
17238 \InsetSpace ~
17239 \InsetSpace ~
17240 \InsetSpace ~
17241 \InsetSpace ~
17242 \InsetSpace ~
17243 \InsetSpace ~
17244 \InsetSpace ~
17245 \InsetSpace ~
17246 sjmp .
17247 \end_layout
17248
17249 \begin_layout Standard
17250 One of these modules (crtstart.asm) contains a call to the C routine 
17251 \emph on
17252 _sdcc_external_startup()
17253 \begin_inset LatexCommand index
17254 name "\\_sdcc\\_external\\_startup()"
17255
17256 \end_inset
17257
17258
17259 \emph default
17260  at the start of the CODE area.
17261  This routine is also in the runtime library
17262 \begin_inset LatexCommand index
17263 name "Runtime library"
17264
17265 \end_inset
17266
17267  and returns 0 by default.
17268  If this routine returns a non-zero value, the static & global variable
17269  initialization will be skipped and the function main will be invoked.
17270  Otherwise static & global variables will be initialized before the function
17271  main is invoked.
17272  You could add an 
17273 \emph on
17274 _sdcc_external_startup()
17275 \emph default
17276  routine to your program to override the default if you need to setup hardware
17277  or perform some other critical operation prior to static & global variable
17278  initialization
17279 \begin_inset LatexCommand index
17280 name "Variable initialization"
17281
17282 \end_inset
17283
17284 .
17285  On some mcs51 variants xdata
17286 \begin_inset LatexCommand index
17287 name "xdata (mcs51, ds390 storage class)"
17288
17289 \end_inset
17290
17291  memory has to be explicitly enabled before it can be accessed or if the
17292  watchdog
17293 \begin_inset LatexCommand index
17294 name "watchdog"
17295
17296 \end_inset
17297
17298  needs to be disabled, this is the place to do it.
17299  The startup code clears all internal data memory, 256 bytes by default,
17300  but from 0 to n-1 if 
17301 \emph on
17302 -
17303 \begin_inset ERT
17304 status collapsed
17305
17306 \begin_layout Standard
17307
17308
17309 \backslash
17310 /
17311 \end_layout
17312
17313 \end_inset
17314
17315 -iram-size
17316 \begin_inset LatexCommand index
17317 name "-\\/-iram-size <Value>"
17318
17319 \end_inset
17320
17321 n
17322 \emph default
17323  is used.
17324  (recommended for Chipcon CC1010).
17325 \end_layout
17326
17327 \begin_layout Standard
17328 See also the compiler options 
17329 \emph on
17330 -
17331 \begin_inset ERT
17332 status collapsed
17333
17334 \begin_layout Standard
17335
17336
17337 \backslash
17338 /
17339 \end_layout
17340
17341 \end_inset
17342
17343 -no-xinit
17344 \emph default
17345 -
17346 \emph on
17347 opt
17348 \emph default
17349
17350 \begin_inset LatexCommand index
17351 name "-\\/-no-xinit-opt"
17352
17353 \end_inset
17354
17355
17356 \emph on
17357 -
17358 \begin_inset ERT
17359 status collapsed
17360
17361 \begin_layout Standard
17362
17363
17364 \backslash
17365 /
17366 \end_layout
17367
17368 \end_inset
17369
17370 -main-return
17371 \emph default
17372
17373 \begin_inset LatexCommand index
17374 name "-\\/-main-return"
17375
17376 \end_inset
17377
17378  and section 
17379 \begin_inset LatexCommand ref
17380 reference "sub:MCS51-variants"
17381
17382 \end_inset
17383
17384  about MCS51-variants.
17385 \newline
17386
17387 \end_layout
17388
17389 \begin_layout Standard
17390 While these initialization modules are meant as generic startup code there
17391  might be the need for customization.
17392  Let's assume the return value of 
17393 \emph on
17394 _sdcc_external_startup()
17395 \emph default
17396  in 
17397 \emph on
17398 crtstart.asm
17399 \emph default
17400  should not be checked (or 
17401 \emph on
17402 _sdcc_external_startup()
17403 \emph default
17404  should not be called at all).
17405  The recommended way would be to copy 
17406 \emph on
17407 crtstart.asm
17408 \emph default
17409  (f.e.
17410  from 
17411 \begin_inset LatexCommand url
17412 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm"
17413
17414 \end_inset
17415
17416 ) into the source directory, adapt it there, then assemble it with 
17417 \emph on
17418 asx8051 -plosgff
17419 \begin_inset Foot
17420 status open
17421
17422 \begin_layout Standard
17423 \begin_inset Quotes sld
17424 \end_inset
17425
17426 -plosgff
17427 \begin_inset Quotes srd
17428 \end_inset
17429
17430  are the assembler options used in 
17431 \begin_inset LatexCommand url
17432 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup "
17433
17434 \end_inset
17435
17436
17437 \end_layout
17438
17439 \end_inset
17440
17441  crtstart.asm
17442 \emph default
17443  and when linking your project explicitly specify 
17444 \emph on
17445 crtstart.rel
17446 \emph default
17447 .
17448  As a bonus a listing of the relocated object file 
17449 \emph on
17450 crtstart.rst
17451 \emph default
17452  is generated.
17453 \end_layout
17454
17455 \begin_layout Standard
17456 \begin_inset VSpace bigskip
17457 \end_inset
17458
17459
17460 \end_layout
17461
17462 \begin_layout Subsection
17463 HC08 Startup Code
17464 \end_layout
17465
17466 \begin_layout Standard
17467 The HC08
17468 \begin_inset LatexCommand index
17469 name "HC08"
17470
17471 \end_inset
17472
17473  startup code follows the same scheme as the MCS51 startup code.
17474 \begin_inset VSpace bigskip
17475 \end_inset
17476
17477
17478 \end_layout
17479
17480 \begin_layout Subsection
17481 Z80 Startup Code
17482 \end_layout
17483
17484 \begin_layout Standard
17485 On the Z80
17486 \begin_inset LatexCommand index
17487 name "Z80"
17488
17489 \end_inset
17490
17491  the startup code is inserted by linking with crt0.o which is generated from
17492  sdcc/device/lib/z80/crt0.s.
17493  If you need a different startup code you can use the compiler option 
17494 \emph on
17495 -
17496 \series bold
17497 \emph default
17498
17499 \begin_inset ERT
17500 status collapsed
17501
17502 \begin_layout Standard
17503
17504
17505 \backslash
17506 /
17507 \end_layout
17508
17509 \end_inset
17510
17511
17512 \series default
17513 \emph on
17514 -no-std-crt0
17515 \emph default
17516
17517 \begin_inset LatexCommand index
17518 name "-\\/-no-std-crt0"
17519
17520 \end_inset
17521
17522  and provide your own crt0.o.
17523  
17524 \begin_inset VSpace bigskip
17525 \end_inset
17526
17527
17528 \end_layout
17529
17530 \begin_layout Section
17531 Inline Assembler Code
17532 \begin_inset LatexCommand index
17533 name "Assembler routines"
17534
17535 \end_inset
17536
17537
17538 \end_layout
17539
17540 \begin_layout Subsection
17541 A Step by Step Introduction
17542 \begin_inset LatexCommand label
17543 name "sub:A-Step-by Assembler Introduction"
17544
17545 \end_inset
17546
17547
17548 \end_layout
17549
17550 \begin_layout Standard
17551 Starting from a small snippet of c-code this example shows for the MCS51
17552  how to use inline assembly, access variables, a function parameter and
17553  an array in xdata memory.
17554  The example uses an MCS51 here but is easily adapted for other architectures.
17555  This is a buffer routine which should be optimized:
17556 \end_layout
17557
17558 \begin_layout Verse
17559
17560 \family typewriter
17561 \size footnotesize
17562 unsigned char __far
17563 \begin_inset LatexCommand index
17564 name "far (storage class)"
17565
17566 \end_inset
17567
17568
17569 \begin_inset LatexCommand index
17570 name "\\_\\_far (storage class)"
17571
17572 \end_inset
17573
17574  __at
17575 \begin_inset LatexCommand index
17576 name "at"
17577
17578 \end_inset
17579
17580
17581 \begin_inset LatexCommand index
17582 name "\\_\\_at"
17583
17584 \end_inset
17585
17586 (0x7f00) buf[0x100];
17587 \begin_inset LatexCommand index
17588 name "Aligned array"
17589
17590 \end_inset
17591
17592
17593 \newline
17594 unsigned char head, tail;\InsetSpace ~
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 \InsetSpace ~
17602 \InsetSpace ~
17603 \InsetSpace ~
17604 \InsetSpace ~
17605 \InsetSpace ~
17606 \InsetSpace ~
17607 \InsetSpace ~
17608 \InsetSpace ~
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 /* if interrupts
17612 \begin_inset LatexCommand index
17613 name "interrupt"
17614
17615 \end_inset
17616
17617  are involved see
17618 \newline
17619 \InsetSpace ~
17620 \InsetSpace ~
17621 \InsetSpace ~
17622 \InsetSpace ~
17623 \InsetSpace ~
17624 \InsetSpace ~
17625 \InsetSpace ~
17626 \InsetSpace ~
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 \InsetSpace ~
17630 \InsetSpace ~
17631 \InsetSpace ~
17632 \InsetSpace ~
17633 \InsetSpace ~
17634 \InsetSpace ~
17635 \InsetSpace ~
17636 \InsetSpace ~
17637 \InsetSpace ~
17638 \InsetSpace ~
17639 \InsetSpace ~
17640 \InsetSpace ~
17641 \InsetSpace ~
17642 \InsetSpace ~
17643 \InsetSpace ~
17644 \InsetSpace ~
17645 \InsetSpace ~
17646 \InsetSpace ~
17647 \InsetSpace ~
17648 \InsetSpace ~
17649 \InsetSpace ~
17650 \InsetSpace ~
17651 \InsetSpace ~
17652 \InsetSpace ~
17653 \InsetSpace ~
17654 \InsetSpace ~
17655 \InsetSpace ~
17656 \InsetSpace ~
17657 \InsetSpace ~
17658 \InsetSpace ~
17659 \InsetSpace ~
17660 \InsetSpace ~
17661 \InsetSpace ~
17662 \InsetSpace ~
17663 \InsetSpace ~
17664 section 
17665 \begin_inset LatexCommand ref
17666 reference "sub:Common-interrupt-pitfall-volatile"
17667
17668 \end_inset
17669
17670  about
17671 \family default
17672  
17673 \family typewriter
17674 \series bold
17675 volatile
17676 \family default
17677 \series default
17678  
17679 \family typewriter
17680 */
17681 \newline
17682
17683 \newline
17684 void to_buffer( unsigned char c ) 
17685 \newline
17686 {
17687 \newline
17688 \InsetSpace ~
17689 \InsetSpace ~
17690 \InsetSpace ~
17691 \InsetSpace ~
17692 if( head != (unsigned char)(tail-1)
17693  )\InsetSpace ~
17694 /* cast
17695 \family default
17696  
17697 \family typewriter
17698 \series bold
17699 needed
17700 \family default
17701 \series default
17702  
17703 \family typewriter
17704 to avoid promotion
17705 \begin_inset LatexCommand index
17706 name "promotion to signed int"
17707
17708 \end_inset
17709
17710
17711 \begin_inset LatexCommand index
17712 name "type promotion"
17713
17714 \end_inset
17715
17716  to integer */
17717 \begin_inset Marginal
17718 status collapsed
17719
17720 \begin_layout Standard
17721
17722 \series bold
17723 \InsetSpace ~
17724 !
17725 \end_layout
17726
17727 \end_inset
17728
17729
17730 \newline
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 \InsetSpace ~
17734 \InsetSpace ~
17735 \InsetSpace ~
17736 \InsetSpace ~
17737 \InsetSpace ~
17738 \InsetSpace ~
17739 buf[ head++ ] = c;\InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 \InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 \InsetSpace ~
17747 \InsetSpace ~
17748 \InsetSpace ~
17749 \InsetSpace ~
17750 \InsetSpace ~
17751 \InsetSpace ~
17752 \InsetSpace ~
17753 \InsetSpace ~
17754 \InsetSpace ~
17755 /* access to a 256 byte aligned array */
17756 \newline
17757
17758 \end_layout
17759
17760 \begin_layout Standard
17761 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17762  then a corresponding buffer.asm file is generated.
17763  We define a new function 
17764 \family typewriter
17765 to_buffer_asm()
17766 \family default
17767  in file buffer.c in which we cut and paste the generated code, removing
17768  unwanted comments and some ':'.
17769  Then add 
17770 \begin_inset Quotes sld
17771 \end_inset
17772
17773
17774 \series bold
17775 _asm
17776 \series default
17777
17778 \begin_inset Quotes srd
17779 \end_inset
17780
17781  and 
17782 \begin_inset Quotes sld
17783 \end_inset
17784
17785
17786 \series bold
17787 _endasm;
17788 \series default
17789
17790 \begin_inset Quotes srd
17791 \end_inset
17792
17793
17794 \begin_inset Foot
17795 status open
17796
17797 \begin_layout Standard
17798 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17799  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17800  has to be used.
17801  The latter is also used in the library functions.
17802 \end_layout
17803
17804 \end_inset
17805
17806  to the beginning and the end of the function body:
17807 \end_layout
17808
17809 \begin_layout Verse
17810
17811 \family typewriter
17812 \size footnotesize
17813 /* With a cut and paste from the .asm file, we have something to start with.
17814 \newline
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 The
17819  function is not yet OK! (registers aren't saved) */ 
17820 \newline
17821 void to_buffer_asm(
17822  unsigned char c ) 
17823 \newline
17824
17825 \newline
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 _asm
17831 \begin_inset LatexCommand index
17832 name "\\_asm"
17833
17834 \end_inset
17835
17836
17837 \begin_inset LatexCommand index
17838 name "\\_\\_asm"
17839
17840 \end_inset
17841
17842
17843 \newline
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 mov\InsetSpace ~
17849 \InsetSpace ~
17850 r2,dpl 
17851 \newline
17852 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17853 /* cast
17854 \family default
17855  
17856 \family typewriter
17857 \series bold
17858 needed
17859 \family default
17860 \series default
17861  
17862 \family typewriter
17863 to avoid promotion
17864 \begin_inset LatexCommand index
17865 name "promotion to signed int"
17866
17867 \end_inset
17868
17869
17870 \begin_inset LatexCommand index
17871 name "type promotion"
17872
17873 \end_inset
17874
17875  to integer */
17876 \newline
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 mov\InsetSpace ~
17882 \InsetSpace ~
17883 a,_tail 
17884 \newline
17885 \InsetSpace ~
17886 \InsetSpace ~
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 dec\InsetSpace ~
17890 \InsetSpace ~
17891
17892 \newline
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 mov\InsetSpace ~
17898 \InsetSpace ~
17899 r3,a 
17900 \newline
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 mov\InsetSpace ~
17906 \InsetSpace ~
17907 a,_head 
17908 \newline
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 cjne a,ar3,00106$ 
17914 \newline
17915 \InsetSpace ~
17916 \InsetSpace ~
17917 \InsetSpace ~
17918 \InsetSpace ~
17919 ret
17920 \newline
17921 00106$:
17922  
17923 \newline
17924 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17925 \begin_inset LatexCommand index
17926 name "Aligned array"
17927
17928 \end_inset
17929
17930
17931 \newline
17932 \InsetSpace ~
17933 \InsetSpace ~
17934 \InsetSpace ~
17935 \InsetSpace ~
17936 mov\InsetSpace ~
17937 \InsetSpace ~
17938 r3,_head 
17939 \newline
17940 \InsetSpace ~
17941 \InsetSpace ~
17942 \InsetSpace ~
17943 \InsetSpace ~
17944 inc\InsetSpace ~
17945 \InsetSpace ~
17946 _head 
17947 \newline
17948 \InsetSpace ~
17949 \InsetSpace ~
17950 \InsetSpace ~
17951 \InsetSpace ~
17952 mov\InsetSpace ~
17953 \InsetSpace ~
17954 dpl,r3 
17955 \newline
17956 \InsetSpace ~
17957 \InsetSpace ~
17958 \InsetSpace ~
17959 \InsetSpace ~
17960 mov\InsetSpace ~
17961 \InsetSpace ~
17962 dph,#(_buf >> 8) 
17963 \newline
17964 \InsetSpace ~
17965 \InsetSpace ~
17966 \InsetSpace ~
17967 \InsetSpace ~
17968 mov\InsetSpace ~
17969 \InsetSpace ~
17970 a,r2 
17971 \newline
17972 \InsetSpace ~
17973 \InsetSpace ~
17974 \InsetSpace ~
17975 \InsetSpace ~
17976 movx @dptr,a
17977  
17978 \newline
17979 00103$: 
17980 \newline
17981 \InsetSpace ~
17982 \InsetSpace ~
17983 \InsetSpace ~
17984 \InsetSpace ~
17985 ret
17986 \newline
17987 \InsetSpace ~
17988 \InsetSpace ~
17989 \InsetSpace ~
17990 \InsetSpace ~
17991 _endasm
17992 \begin_inset LatexCommand index
17993 name "\\_endasm"
17994
17995 \end_inset
17996
17997
17998 \begin_inset LatexCommand index
17999 name "\\_\\_endasm"
18000
18001 \end_inset
18002
18003 ;
18004 \newline
18005
18006 \end_layout
18007
18008 \begin_layout Standard
18009 The new file buffer.c should compile with only one warning about the unreferenced
18010  function argument 'c'.
18011  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
18012  (1) and finally have:
18013 \end_layout
18014
18015 \begin_layout Verse
18016
18017 \family typewriter
18018 \size footnotesize
18019 unsigned char __far __at(0x7f00) buf[0x100];
18020 \newline
18021 unsigned char head, tail;
18022 \newline
18023 #define
18024  USE_ASSEMBLY (1)
18025 \newline
18026
18027 \newline
18028 #if !USE_ASSEMBLY
18029 \newline
18030
18031 \newline
18032 void to_buffer( unsigned char c )
18033 \newline
18034 {
18035 \newline
18036 \InsetSpace ~
18037 \InsetSpace ~
18038 \InsetSpace ~
18039 \InsetSpace ~
18040 if(
18041  head != (unsigned char)(tail-1) )
18042 \newline
18043 \InsetSpace ~
18044 \InsetSpace ~
18045 \InsetSpace ~
18046 \InsetSpace ~
18047 \InsetSpace ~
18048 \InsetSpace ~
18049 \InsetSpace ~
18050 \InsetSpace ~
18051 buf[ head++ ] = c;
18052 \newline
18053 }
18054 \newline
18055
18056 \newline
18057 #else
18058 \newline
18059
18060 \newline
18061 void to_buffer(
18062  unsigned char c )
18063 \newline
18064 {
18065 \newline
18066 \InsetSpace ~
18067 \InsetSpace ~
18068 \InsetSpace ~
18069 \InsetSpace ~
18070 c; // to avoid warning: unreferenced function argument
18071 \newline
18072 \InsetSpace ~
18073 \InsetSpace ~
18074 \InsetSpace ~
18075 \InsetSpace ~
18076 _asm
18077 \begin_inset LatexCommand index
18078 name "\\_asm"
18079
18080 \end_inset
18081
18082
18083 \begin_inset LatexCommand index
18084 name "\\_\\_asm"
18085
18086 \end_inset
18087
18088
18089 \newline
18090 \InsetSpace ~
18091 \InsetSpace ~
18092 \InsetSpace ~
18093 \InsetSpace ~
18094 \InsetSpace ~
18095 \InsetSpace ~
18096 \InsetSpace ~
18097 \InsetSpace ~
18098 ; save used registers here.
18099  
18100 \newline
18101 \InsetSpace ~
18102 \InsetSpace ~
18103 \InsetSpace ~
18104 \InsetSpace ~
18105 \InsetSpace ~
18106 \InsetSpace ~
18107 \InsetSpace ~
18108 \InsetSpace ~
18109 ; If we were still using r2,r3 we would have to push them here.
18110  
18111 \newline
18112 ; if( head != (unsigned char)(tail-1) )
18113 \newline
18114 \InsetSpace ~
18115 \InsetSpace ~
18116 \InsetSpace ~
18117 \InsetSpace ~
18118 \InsetSpace ~
18119 \InsetSpace ~
18120 \InsetSpace ~
18121 \InsetSpace ~
18122 mov\InsetSpace ~
18123  a,_tail
18124 \newline
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 \InsetSpace ~
18128 \InsetSpace ~
18129 \InsetSpace ~
18130 \InsetSpace ~
18131 \InsetSpace ~
18132 \InsetSpace ~
18133 dec\InsetSpace ~
18134  a
18135 \newline
18136 \InsetSpace ~
18137 \InsetSpace ~
18138 \InsetSpace ~
18139 \InsetSpace ~
18140 \InsetSpace ~
18141 \InsetSpace ~
18142 \InsetSpace ~
18143 \InsetSpace ~
18144 xrl\InsetSpace ~
18145  a,_head
18146 \newline
18147 \InsetSpace ~
18148 \InsetSpace ~
18149 \InsetSpace ~
18150 \InsetSpace ~
18151 \InsetSpace ~
18152 \InsetSpace ~
18153 \InsetSpace ~
18154 \InsetSpace ~
18155 ; we
18156  could do an ANL a,#0x0f here to use a smaller buffer (see below)
18157 \newline
18158 \InsetSpace ~
18159 \InsetSpace ~
18160 \InsetSpace ~
18161 \InsetSpace ~
18162 \InsetSpace ~
18163 \InsetSpace ~
18164 \InsetSpace ~
18165 \InsetSpace ~
18166 jz\InsetSpace ~
18167 \InsetSpace ~
18168  t_b_end$
18169 \newline
18170 \InsetSpace ~
18171 \InsetSpace ~
18172 \InsetSpace ~
18173 \InsetSpace ~
18174 \InsetSpace ~
18175 \InsetSpace ~
18176 \InsetSpace ~
18177 \InsetSpace ~
18178 ;
18179 \newline
18180 ;
18181  buf[ head++ ] = c;
18182 \newline
18183 \InsetSpace ~
18184 \InsetSpace ~
18185 \InsetSpace ~
18186 \InsetSpace ~
18187 \InsetSpace ~
18188 \InsetSpace ~
18189 \InsetSpace ~
18190 \InsetSpace ~
18191 mov\InsetSpace ~
18192  a,dpl \InsetSpace ~
18193 \InsetSpace ~
18194 \InsetSpace ~
18195 \InsetSpace ~
18196 \InsetSpace ~
18197 \InsetSpace ~
18198 \InsetSpace ~
18199 ; dpl holds lower byte of function argument
18200 \newline
18201 \InsetSpace ~
18202 \InsetSpace ~
18203 \InsetSpace ~
18204 \InsetSpace ~
18205 \InsetSpace ~
18206 \InsetSpace ~
18207 \InsetSpace ~
18208 \InsetSpace ~
18209 mov\InsetSpace ~
18210
18211  dpl,_head \InsetSpace ~
18212 \InsetSpace ~
18213 \InsetSpace ~
18214 ; buf is 0x100 byte aligned so head can be used directly
18215 \newline
18216 \InsetSpace ~
18217 \InsetSpace ~
18218 \InsetSpace ~
18219 \InsetSpace ~
18220 \InsetSpace ~
18221 \InsetSpace ~
18222 \InsetSpace ~
18223 \InsetSpace ~
18224 mov\InsetSpace ~
18225  dph,#(_bu
18226 f>>8)
18227 \newline
18228 \InsetSpace ~
18229 \InsetSpace ~
18230 \InsetSpace ~
18231 \InsetSpace ~
18232 \InsetSpace ~
18233 \InsetSpace ~
18234 \InsetSpace ~
18235 \InsetSpace ~
18236 movx @dptr,a
18237 \newline
18238 \InsetSpace ~
18239 \InsetSpace ~
18240 \InsetSpace ~
18241 \InsetSpace ~
18242 \InsetSpace ~
18243 \InsetSpace ~
18244 \InsetSpace ~
18245 \InsetSpace ~
18246 inc \InsetSpace ~
18247 _head
18248 \newline
18249 \InsetSpace ~
18250 \InsetSpace ~
18251 \InsetSpace ~
18252 \InsetSpace ~
18253 \InsetSpace ~
18254 \InsetSpace ~
18255 \InsetSpace ~
18256 \InsetSpace ~
18257 ; we could do an ANL _head,#0x0f here to use a
18258  smaller buffer (see above)
18259 \newline
18260 t_b_end$:
18261 \newline
18262 \InsetSpace ~
18263 \InsetSpace ~
18264 \InsetSpace ~
18265 \InsetSpace ~
18266 \InsetSpace ~
18267 \InsetSpace ~
18268 \InsetSpace ~
18269 \InsetSpace ~
18270 ; restore used registers here 
18271 \newline
18272 \InsetSpace ~
18273 \InsetSpace ~
18274 \InsetSpace ~
18275 \InsetSpace ~
18276 _endasm
18277 \begin_inset LatexCommand index
18278 name "\\_endasm"
18279
18280 \end_inset
18281
18282
18283 \begin_inset LatexCommand index
18284 name "\\_\\_endasm"
18285
18286 \end_inset
18287
18288 ;
18289 \newline
18290 }
18291 \newline
18292 #endif
18293 \end_layout
18294
18295 \begin_layout Standard
18296 The inline assembler code can contain any valid code understood by the assembler
18297 , this includes any assembler directives and comment lines.
18298  The assembler does not like some characters like ':' or ''' in comments.
18299  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
18300 \begin_inset LatexCommand index
18301 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
18302
18303 \end_inset
18304
18305
18306 \begin_inset LatexCommand index
18307 name "Assembler documentation"
18308
18309 \end_inset
18310
18311  or online at 
18312 \begin_inset LatexCommand url
18313 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
18314
18315 \end_inset
18316
18317 \InsetSpace ~
18318 .
18319 \end_layout
18320
18321 \begin_layout Standard
18322 The compiler does not do any validation of the code within the 
18323 \family typewriter
18324 _asm
18325 \begin_inset LatexCommand index
18326 name "\\_asm"
18327
18328 \end_inset
18329
18330
18331 \begin_inset LatexCommand index
18332 name "\\_\\_asm"
18333
18334 \end_inset
18335
18336  ...
18337  _endasm
18338 \size footnotesize
18339
18340 \begin_inset LatexCommand index
18341 name "\\_endasm"
18342
18343 \end_inset
18344
18345
18346 \begin_inset LatexCommand index
18347 name "\\_\\_endasm"
18348
18349 \end_inset
18350
18351
18352 \size default
18353 ;
18354 \family default
18355  keyword pair.
18356  Specifically it will not know which registers are used and thus register
18357  pushing/popping
18358 \begin_inset LatexCommand index
18359 name "push/pop"
18360
18361 \end_inset
18362
18363  has to be done manually.
18364  
18365 \end_layout
18366
18367 \begin_layout Standard
18368 It is recommended that each assembly instruction (including labels) be placed
18369  in a separate line (as the example shows).
18370  When the -
18371 \begin_inset ERT
18372 status collapsed
18373
18374 \begin_layout Standard
18375
18376
18377 \backslash
18378 /
18379 \end_layout
18380
18381 \end_inset
18382
18383 -
18384 \emph on
18385 peep-asm
18386 \begin_inset LatexCommand index
18387 name "-\\/-peep-asm"
18388
18389 \end_inset
18390
18391
18392 \emph default
18393  command line option is used, the inline assembler code will be passed through
18394  the peephole optimizer
18395 \begin_inset LatexCommand index
18396 name "Peephole optimizer"
18397
18398 \end_inset
18399
18400 .
18401  There are only a few (if any) cases where this option makes sense, it might
18402  cause some unexpected changes in the inline assembler code.
18403  Please go through the peephole optimizer rules defined in file 
18404 \emph on
18405 SDCCpeeph.def
18406 \emph default
18407  before using this option.
18408 \end_layout
18409
18410 \begin_layout Subsection
18411 Naked Functions
18412 \begin_inset LatexCommand label
18413 name "sub:Naked-Functions"
18414
18415 \end_inset
18416
18417
18418 \begin_inset LatexCommand index
18419 name "Naked functions"
18420
18421 \end_inset
18422
18423
18424 \end_layout
18425
18426 \begin_layout Standard
18427 A special keyword may be associated with a function declaring it as 
18428 \emph on
18429 _naked
18430 \begin_inset LatexCommand index
18431 name "\\_naked"
18432
18433 \end_inset
18434
18435
18436 \begin_inset LatexCommand index
18437 name "\\_\\_naked"
18438
18439 \end_inset
18440
18441 .
18442
18443 \emph default
18444  The 
18445 \emph on
18446 _naked
18447 \emph default
18448  function modifier attribute prevents the compiler from generating prologue
18449 \begin_inset LatexCommand index
18450 name "function prologue"
18451
18452 \end_inset
18453
18454  and epilogue
18455 \begin_inset LatexCommand index
18456 name "function epilogue"
18457
18458 \end_inset
18459
18460  code for that function.
18461  This means that the user is entirely responsible for such things as saving
18462  any registers that may need to be preserved, selecting the proper register
18463  bank, generating the 
18464 \emph on
18465 return
18466 \emph default
18467  instruction at the end, etc.
18468  Practically, this means that the contents of the function must be written
18469  in inline assembler.
18470  This is particularly useful for interrupt functions, which can have a large
18471  (and often unnecessary) prologue/epilogue.
18472  For example, compare the code generated by these two functions:
18473 \end_layout
18474
18475 \begin_layout Verse
18476
18477 \family typewriter
18478 volatile
18479 \begin_inset LatexCommand index
18480 name "volatile"
18481
18482 \end_inset
18483
18484  data unsigned char counter;
18485 \newline
18486
18487 \newline
18488 void simpleInterrupt(void) __interrupt
18489 \begin_inset LatexCommand index
18490 name "interrupt"
18491
18492 \end_inset
18493
18494
18495 \begin_inset LatexCommand index
18496 name "\\_\\_interrupt"
18497
18498 \end_inset
18499
18500  (1)
18501 \newline
18502 {
18503 \newline
18504 \InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 \InsetSpace ~
18508 counter++;
18509 \newline
18510 }
18511 \newline
18512
18513 \newline
18514 void nakedInterrupt(void) __interrupt (2) __naked
18515 \newline
18516 {
18517 \newline
18518 \InsetSpace ~
18519 \InsetSpace ~
18520 \InsetSpace ~
18521 \InsetSpace ~
18522 _asm
18523 \begin_inset LatexCommand index
18524 name "\\_asm"
18525
18526 \end_inset
18527
18528
18529 \begin_inset LatexCommand index
18530 name "\\_\\_asm"
18531
18532 \end_inset
18533
18534
18535 \newline
18536 \InsetSpace ~
18537 \InsetSpace ~
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 inc\InsetSpace ~
18543 \InsetSpace ~
18544 \InsetSpace ~
18545 \InsetSpace ~
18546 \InsetSpace ~
18547 _counter ; does not change flags, no need to save psw
18548 \newline
18549 \InsetSpace ~
18550 \InsetSpace ~
18551 \InsetSpace ~
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 \InsetSpace ~
18555 reti\InsetSpace ~
18556 \InsetSpace ~
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 ; MUST explicitly
18560  include ret or reti in _naked function.
18561 \newline
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 \InsetSpace ~
18565 \InsetSpace ~
18566 _endasm
18567 \begin_inset LatexCommand index
18568 name "\\_endasm"
18569
18570 \end_inset
18571
18572
18573 \begin_inset LatexCommand index
18574 name "\\_\\_endasm"
18575
18576 \end_inset
18577
18578 ;
18579 \newline
18580 }
18581 \end_layout
18582
18583 \begin_layout Standard
18584 For an 8051 target, the generated simpleInterrupt looks like:
18585 \end_layout
18586
18587 \begin_layout Verse
18588
18589 \family typewriter
18590 Note, this is an
18591 \family default
18592  
18593 \family typewriter
18594 \emph on
18595 outdated
18596 \family default
18597 \emph default
18598  
18599 \family typewriter
18600 example, recent versions of SDCC generate
18601 \newline
18602 the
18603 \family default
18604  
18605 \family typewriter
18606 \emph on
18607 same
18608 \family default
18609 \emph default
18610  
18611 \family typewriter
18612 code for simpleInterrupt() and nakedInterrupt()!
18613 \newline
18614
18615 \newline
18616 _simpleInterrupt:
18617 \newline
18618 \InsetSpace ~
18619 \InsetSpace ~
18620 \InsetSpace ~
18621 \InsetSpace ~
18622 push\InsetSpace ~
18623 \InsetSpace ~
18624 \InsetSpace ~
18625 \InsetSpace ~
18626 acc
18627 \newline
18628 \InsetSpace ~
18629 \InsetSpace ~
18630 \InsetSpace ~
18631 \InsetSpace ~
18632 push\InsetSpace ~
18633 \InsetSpace ~
18634 \InsetSpace ~
18635 \InsetSpace ~
18636 b
18637 \newline
18638 \InsetSpace ~
18639 \InsetSpace ~
18640 \InsetSpace ~
18641 \InsetSpace ~
18642 pus
18643 h\InsetSpace ~
18644 \InsetSpace ~
18645 \InsetSpace ~
18646 \InsetSpace ~
18647 dpl
18648 \newline
18649 \InsetSpace ~
18650 \InsetSpace ~
18651 \InsetSpace ~
18652 \InsetSpace ~
18653 push\InsetSpace ~
18654 \InsetSpace ~
18655 \InsetSpace ~
18656 \InsetSpace ~
18657 dph
18658 \newline
18659 \InsetSpace ~
18660 \InsetSpace ~
18661 \InsetSpace ~
18662 \InsetSpace ~
18663 push\InsetSpace ~
18664 \InsetSpace ~
18665 \InsetSpace ~
18666 \InsetSpace ~
18667 psw
18668 \newline
18669 \InsetSpace ~
18670 \InsetSpace ~
18671 \InsetSpace ~
18672 \InsetSpace ~
18673 mov\InsetSpace ~
18674 \InsetSpace ~
18675 \InsetSpace ~
18676 \InsetSpace ~
18677 \InsetSpace ~
18678 psw,#0x00
18679 \newline
18680 \InsetSpace ~
18681 \InsetSpace ~
18682 \InsetSpace ~
18683 \InsetSpace ~
18684 inc\InsetSpace ~
18685 \InsetSpace ~
18686 \InsetSpace ~
18687 \InsetSpace ~
18688 \InsetSpace ~
18689 _counter
18690 \newline
18691 \InsetSpace ~
18692 \InsetSpace ~
18693 \InsetSpace ~
18694 \InsetSpace ~
18695 pop\InsetSpace ~
18696 \InsetSpace ~
18697 \InsetSpace ~
18698 \InsetSpace ~
18699 \InsetSpace ~
18700 psw
18701 \newline
18702 \InsetSpace ~
18703 \InsetSpace ~
18704 \InsetSpace ~
18705 \InsetSpace ~
18706 pop\InsetSpace ~
18707 \InsetSpace ~
18708 \InsetSpace ~
18709 \InsetSpace ~
18710 \InsetSpace ~
18711 dph
18712 \newline
18713 \InsetSpace ~
18714 \InsetSpace ~
18715 \InsetSpace ~
18716 \InsetSpace ~
18717 pop\InsetSpace ~
18718 \InsetSpace ~
18719 \InsetSpace ~
18720 \InsetSpace ~
18721 \InsetSpace ~
18722 dpl
18723 \newline
18724 \InsetSpace ~
18725 \InsetSpace ~
18726 \InsetSpace ~
18727 \InsetSpace ~
18728 pop\InsetSpace ~
18729 \InsetSpace ~
18730 \InsetSpace ~
18731 \InsetSpace ~
18732 \InsetSpace ~
18733 b
18734 \newline
18735 \InsetSpace ~
18736 \InsetSpace ~
18737 \InsetSpace ~
18738 \InsetSpace ~
18739 pop\InsetSpace ~
18740 \InsetSpace ~
18741 \InsetSpace ~
18742 \InsetSpace ~
18743 \InsetSpace ~
18744 acc
18745 \newline
18746 \InsetSpace ~
18747 \InsetSpace ~
18748 \InsetSpace ~
18749 \InsetSpace ~
18750 reti
18751 \end_layout
18752
18753 \begin_layout Standard
18754 whereas nakedInterrupt looks like:
18755 \end_layout
18756
18757 \begin_layout Verse
18758
18759 \family typewriter
18760 _nakedInterrupt:
18761 \newline
18762 \InsetSpace ~
18763 \InsetSpace ~
18764 \InsetSpace ~
18765 \InsetSpace ~
18766 inc\InsetSpace ~
18767 \InsetSpace ~
18768 \InsetSpace ~
18769 \InsetSpace ~
18770 _counter ; does not change flags, no need to save psw
18771 \newline
18772 \InsetSpace ~
18773 \InsetSpace ~
18774 \InsetSpace ~
18775 \InsetSpace ~
18776 reti\InsetSpace ~
18777 \InsetSpace ~
18778 \InsetSpace ~
18779 \InsetSpace ~
18780 \InsetSpace ~
18781 \InsetSpace ~
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 \InsetSpace ~
18785 \InsetSpace ~
18786 \InsetSpace ~
18787 \InsetSpace ~
18788 ;
18789  MUST explicitly include ret or reti in _naked function
18790 \end_layout
18791
18792 \begin_layout Standard
18793 The related directive #pragma exclude
18794 \begin_inset LatexCommand index
18795 name "\\#pragma exclude"
18796
18797 \end_inset
18798
18799  allows a more fine grained control over pushing & popping
18800 \begin_inset LatexCommand index
18801 name "push/pop"
18802
18803 \end_inset
18804
18805  the registers.
18806 \end_layout
18807
18808 \begin_layout Standard
18809 While there is nothing preventing you from writing C code inside a 
18810 \family typewriter
18811 _naked
18812 \family default
18813  function, there are many ways to shoot yourself in the foot doing this,
18814  and it is recommended that you stick to inline assembler.
18815 \end_layout
18816
18817 \begin_layout Subsection
18818 Use of Labels within Inline Assembler
18819 \end_layout
18820
18821 \begin_layout Standard
18822 SDCC allows the use of in-line assembler with a few restrictions regarding
18823  labels.
18824  All labels defined within inline assembler code have to be of the form
18825  
18826 \emph on
18827 nnnnn$
18828 \emph default
18829  where nnnnn is a number less than 100 (which implies a limit of utmost
18830  100 inline assembler labels 
18831 \emph on
18832 per function
18833 \emph default
18834 \noun on
18835 )
18836 \noun default
18837 .
18838 \begin_inset Foot
18839 status open
18840
18841 \begin_layout Standard
18842 This is a slightly more stringent rule than absolutely necessary, but stays
18843  always on the safe side.
18844  Labels in the form of nnnnn$ are local labels in the assembler, locality
18845  of which is confined within two labels of the standard form.
18846  The compiler uses the same form for labels within a function (but starting
18847  from nnnnn=00100); and places always a standard label at the beginning
18848  of a function, thus limiting the locality of labels within the scope of
18849  the function.
18850  So, if the inline assembler part would be embedded into C-code, an improperly
18851  placed non-local label in the assembler would break up the reference space
18852  for labels created by the compiler for the C-code, leading to an assembling
18853  error.
18854 \end_layout
18855
18856 \begin_layout Standard
18857 The numeric part of local labels does not need to have 5 digits (although
18858  this is the form of labels output by the compiler), any valid integer will
18859  do.
18860  Please refer to the assemblers documentation for further details.
18861 \end_layout
18862
18863 \end_inset
18864
18865  
18866 \end_layout
18867
18868 \begin_layout Verse
18869
18870 \family typewriter
18871 _asm
18872 \begin_inset LatexCommand index
18873 name "\\_asm"
18874
18875 \end_inset
18876
18877
18878 \begin_inset LatexCommand index
18879 name "\\_\\_asm"
18880
18881 \end_inset
18882
18883  
18884 \newline
18885 \InsetSpace ~
18886 \InsetSpace ~
18887 \InsetSpace ~
18888 \InsetSpace ~
18889 mov\InsetSpace ~
18890 \InsetSpace ~
18891 \InsetSpace ~
18892 \InsetSpace ~
18893 \InsetSpace ~
18894 b,#10 
18895 \newline
18896 00001$: 
18897 \newline
18898 \InsetSpace ~
18899 \InsetSpace ~
18900 \InsetSpace ~
18901 \InsetSpace ~
18902 djnz\InsetSpace ~
18903 \InsetSpace ~
18904 \InsetSpace ~
18905 \InsetSpace ~
18906 b,00001$ 
18907 \newline
18908 _endasm
18909 \begin_inset LatexCommand index
18910 name "\\_endasm"
18911
18912 \end_inset
18913
18914
18915 \begin_inset LatexCommand index
18916 name "\\_\\_endasm"
18917
18918 \end_inset
18919
18920  ;
18921 \end_layout
18922
18923 \begin_layout Standard
18924 Inline assembler code cannot reference any C-labels, however it can reference
18925  labels
18926 \begin_inset LatexCommand index
18927 name "Labels"
18928
18929 \end_inset
18930
18931  defined by the inline assembler, e.g.:
18932 \end_layout
18933
18934 \begin_layout Verse
18935
18936 \family typewriter
18937 foo() { 
18938 \newline
18939 \InsetSpace ~
18940 \InsetSpace ~
18941 \InsetSpace ~
18942 \InsetSpace ~
18943 /* some c code */ 
18944 \newline
18945 \InsetSpace ~
18946 \InsetSpace ~
18947 \InsetSpace ~
18948 \InsetSpace ~
18949 _asm 
18950 \newline
18951 \InsetSpace ~
18952 \InsetSpace ~
18953 \InsetSpace ~
18954 \InsetSpace ~
18955 \InsetSpace ~
18956 \InsetSpace ~
18957 ; some assembler code 
18958 \newline
18959 \InsetSpace ~
18960 \InsetSpace ~
18961 \InsetSpace ~
18962 \InsetSpace ~
18963 \InsetSpace ~
18964 \InsetSpace ~
18965 ljmp 0003$ 
18966 \newline
18967 \InsetSpace ~
18968 \InsetSpace ~
18969 \InsetSpace ~
18970 \InsetSpace ~
18971 _endasm;
18972  
18973 \newline
18974 \InsetSpace ~
18975 \InsetSpace ~
18976 \InsetSpace ~
18977 \InsetSpace ~
18978 /* some more c code */ 
18979 \newline
18980 clabel:\InsetSpace ~
18981 \InsetSpace ~
18982 /* inline assembler cannot reference this
18983  label */ 
18984 \begin_inset Foot
18985 status open
18986
18987 \begin_layout Standard
18988 Here, the C-label 
18989 \family typewriter
18990 clabel
18991 \family default
18992  is translated by the compiler into a local label, so the locality of labels
18993  within the function is not broken.
18994 \end_layout
18995
18996 \end_inset
18997
18998
18999 \newline
19000 \InsetSpace ~
19001 \InsetSpace ~
19002 \InsetSpace ~
19003 \InsetSpace ~
19004 _asm
19005 \newline
19006 \InsetSpace ~
19007 \InsetSpace ~
19008 \InsetSpace ~
19009 \InsetSpace ~
19010 0003$: ;label (can be referenced by inline assembler only) 
19011 \newline
19012 \InsetSpace ~
19013 \InsetSpace ~
19014 \InsetSpace ~
19015 \InsetSpace ~
19016 _endasm
19017 \begin_inset LatexCommand index
19018 name "\\_endasm"
19019
19020 \end_inset
19021
19022
19023 \begin_inset LatexCommand index
19024 name "\\_\\_endasm"
19025
19026 \end_inset
19027
19028  ; 
19029 \newline
19030 \InsetSpace ~
19031 \InsetSpace ~
19032 \InsetSpace ~
19033 \InsetSpace ~
19034 /* some more c code */
19035 \newline
19036 }
19037 \end_layout
19038
19039 \begin_layout Standard
19040 In other words inline assembly code can access labels defined in inline
19041  assembly within the scope of the function.
19042  The same goes the other way, i.e.
19043  labels defines in inline assembly can not be accessed by C statements.
19044 \end_layout
19045
19046 \begin_layout Section
19047 Interfacing with Assembler Code
19048 \begin_inset LatexCommand index
19049 name "Assembler routines"
19050
19051 \end_inset
19052
19053
19054 \end_layout
19055
19056 \begin_layout Subsection
19057 Global Registers used for Parameter Passing
19058 \begin_inset LatexCommand index
19059 name "Parameter passing"
19060
19061 \end_inset
19062
19063
19064 \end_layout
19065
19066 \begin_layout Standard
19067 The compiler always uses the global registers 
19068 \emph on
19069 DPL, DPH
19070 \begin_inset LatexCommand index
19071 name "DPTR, DPH, DPL"
19072
19073 \end_inset
19074
19075
19076 \begin_inset LatexCommand index
19077 name "DPTR"
19078
19079 \end_inset
19080
19081 , B
19082 \begin_inset LatexCommand index
19083 name "B (mcs51, ds390 register)"
19084
19085 \end_inset
19086
19087
19088 \emph default
19089  and 
19090 \emph on
19091 ACC
19092 \begin_inset LatexCommand index
19093 name "ACC (mcs51, ds390 register)"
19094
19095 \end_inset
19096
19097
19098 \emph default
19099  to pass the first (non-bit) parameter to a function, and also to pass the
19100  return value 
19101 \begin_inset LatexCommand index
19102 name "return value"
19103
19104 \end_inset
19105
19106 of function; according to the following scheme: one byte return value in
19107  
19108 \emph on
19109 DPL
19110 \emph default
19111 , two byte value in 
19112 \emph on
19113 DPL
19114 \emph default
19115  (LSB) and 
19116 \emph on
19117 DPH
19118 \emph default
19119  (MSB).
19120  three byte values (generic pointers) in 
19121 \emph on
19122 DPH
19123 \emph default
19124
19125 \emph on
19126 DPL
19127 \emph default
19128  and 
19129 \emph on
19130 B
19131 \emph default
19132 , and four byte values in 
19133 \emph on
19134 DPH
19135 \emph default
19136
19137 \emph on
19138 DPL
19139 \emph default
19140
19141 \emph on
19142 B
19143 \emph default
19144  and 
19145 \emph on
19146 ACC
19147 \emph default
19148 .
19149  Generic pointers
19150 \begin_inset LatexCommand index
19151 name "generic pointer"
19152
19153 \end_inset
19154
19155  contain type of accessed memory in 
19156 \emph on
19157 B
19158 \emph default
19159
19160 \series bold
19161 0x00
19162 \series default
19163  -- xdata/far, 
19164 \series bold
19165 0x40
19166 \series default
19167  -- idata/near -- , 
19168 \series bold
19169 0x60
19170 \series default
19171  -- pdata, 
19172 \series bold
19173 0x80
19174 \series default
19175  -- code
19176 \begin_inset Note Note
19177 status collapsed
19178
19179 \begin_layout Standard
19180 This might not be the case of certain memory models (medium???)
19181 \end_layout
19182
19183 \end_inset
19184
19185 .
19186 \end_layout
19187
19188 \begin_layout Standard
19189 The second parameter onwards is either allocated on the stack (for reentrant
19190  routines or if -
19191 \begin_inset ERT
19192 status collapsed
19193
19194 \begin_layout Standard
19195
19196
19197 \backslash
19198 /
19199 \end_layout
19200
19201 \end_inset
19202
19203 -stack-auto is used) or in data/xdata memory (depending on the memory model).
19204 \end_layout
19205
19206 \begin_layout Standard
19207 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
19208  space for reentrant functions or allocated directly in bit memory otherwise.
19209 \end_layout
19210
19211 \begin_layout Standard
19212 Functions (with two or more parameters or bit parameters) that are called
19213  through function pointers
19214 \begin_inset LatexCommand index
19215 name "function pointers"
19216
19217 \end_inset
19218
19219  must therefor be reentrant so the compiler knows how to pass the parameters.
19220 \end_layout
19221
19222 \begin_layout Subsection
19223 Registers usage
19224 \end_layout
19225
19226 \begin_layout Standard
19227 Unless the called function is declared as 
19228 \family typewriter
19229 _naked
19230 \family default
19231
19232 \begin_inset LatexCommand index
19233 name "naked"
19234
19235 \end_inset
19236
19237 , or the -
19238 \begin_inset ERT
19239 status collapsed
19240
19241 \begin_layout Standard
19242
19243
19244 \backslash
19245 /
19246 \end_layout
19247
19248 \end_inset
19249
19250 -callee-saves
19251 \begin_inset LatexCommand index
19252 name "-\\/-callee-saves"
19253
19254 \end_inset
19255
19256 /-
19257 \begin_inset ERT
19258 status collapsed
19259
19260 \begin_layout Standard
19261
19262
19263 \backslash
19264 /
19265 \end_layout
19266
19267 \end_inset
19268
19269 -all-callee-saves command line option or the corresponding callee_saves
19270  pragma are used, the caller will save the registers (
19271 \emph on
19272 R0-R7
19273 \emph default
19274 ) around the call, so the called function can destroy they content freely.
19275 \end_layout
19276
19277 \begin_layout Standard
19278 If the called function is not declared as 
19279 \family typewriter
19280 _naked
19281 \family default
19282 , the caller will swap register banks around the call, if caller and callee
19283  use different register banks (having them defined by the 
19284 \family typewriter
19285 _using
19286 \family default
19287  modifier).
19288  
19289 \end_layout
19290
19291 \begin_layout Standard
19292 The called function can also use 
19293 \emph on
19294 DPL
19295 \emph default
19296
19297 \emph on
19298 DPH
19299 \emph default
19300
19301 \emph on
19302 B
19303 \emph default
19304  and 
19305 \emph on
19306 ACC
19307 \emph default
19308  observing that they are used for parameter/return value passing.
19309 \end_layout
19310
19311 \begin_layout Subsection
19312 Assembler Routine (non-reentrant)
19313 \end_layout
19314
19315 \begin_layout Standard
19316 In the following example
19317 \begin_inset LatexCommand index
19318 name "reentrant"
19319
19320 \end_inset
19321
19322
19323 \begin_inset LatexCommand index
19324 name "Assembler routines (non-reentrant)"
19325
19326 \end_inset
19327
19328  the function c_func calls an assembler routine asm_func, which takes two
19329  parameters
19330 \begin_inset LatexCommand index
19331 name "function parameter"
19332
19333 \end_inset
19334
19335 .
19336 \end_layout
19337
19338 \begin_layout Verse
19339
19340 \family typewriter
19341 extern int asm_func(unsigned char, unsigned char);
19342 \newline
19343
19344 \newline
19345 int c_func (unsigned char
19346  i, unsigned char j)
19347 \newline
19348 {
19349 \newline
19350 \InsetSpace ~
19351 \InsetSpace ~
19352 \InsetSpace ~
19353 \InsetSpace ~
19354 return asm_func(i,j);
19355 \newline
19356 }
19357 \newline
19358
19359 \newline
19360 int main()
19361 \newline
19362 {
19363 \newline
19364 \InsetSpace ~
19365 \InsetSpace ~
19366 \InsetSpace ~
19367 \InsetSpace ~
19368 return c_func(10,9);
19369 \newline
19370 }
19371 \end_layout
19372
19373 \begin_layout Standard
19374 The corresponding assembler function is:
19375 \end_layout
19376
19377 \begin_layout Verse
19378
19379 \family typewriter
19380 .globl _asm_func_PARM_2 
19381 \newline
19382 \InsetSpace ~
19383 \InsetSpace ~
19384 \InsetSpace ~
19385 \InsetSpace ~
19386 \InsetSpace ~
19387 \InsetSpace ~
19388 \InsetSpace ~
19389 \InsetSpace ~
19390 .globl _asm_func 
19391 \newline
19392 \InsetSpace ~
19393 \InsetSpace ~
19394 \InsetSpace ~
19395 \InsetSpace ~
19396 \InsetSpace ~
19397 \InsetSpace ~
19398 \InsetSpace ~
19399 \InsetSpace ~
19400 .area OSEG 
19401 \newline
19402 _asm_func_PARM_2:
19403 \newline
19404 \InsetSpace ~
19405 \InsetSpace ~
19406 \InsetSpace ~
19407 \InsetSpace ~
19408 \InsetSpace ~
19409 \InsetSpace ~
19410 \InsetSpace ~
19411 \InsetSpace ~
19412 .ds   
19413  1 
19414 \newline
19415 \InsetSpace ~
19416 \InsetSpace ~
19417 \InsetSpace ~
19418 \InsetSpace ~
19419 \InsetSpace ~
19420 \InsetSpace ~
19421 \InsetSpace ~
19422 \InsetSpace ~
19423 .area CSEG 
19424 \newline
19425 _asm_func: 
19426 \newline
19427 \InsetSpace ~
19428 \InsetSpace ~
19429 \InsetSpace ~
19430 \InsetSpace ~
19431 \InsetSpace ~
19432 \InsetSpace ~
19433 \InsetSpace ~
19434 \InsetSpace ~
19435 mov\InsetSpace ~
19436 \InsetSpace ~
19437 \InsetSpace ~
19438 \InsetSpace ~
19439 a,dpl 
19440 \newline
19441 \InsetSpace ~
19442 \InsetSpace ~
19443 \InsetSpace ~
19444 \InsetSpace ~
19445 \InsetSpace ~
19446 \InsetSpace ~
19447 \InsetSpace ~
19448 \InsetSpace ~
19449 add\InsetSpace ~
19450 \InsetSpace ~
19451 \InsetSpace ~
19452 \InsetSpace ~
19453 a,_asm_func_PARM_2 
19454 \newline
19455 \InsetSpace ~
19456 \InsetSpace ~
19457 \InsetSpace ~
19458 \InsetSpace ~
19459 \InsetSpace ~
19460 \InsetSpace ~
19461 \InsetSpace ~
19462 \InsetSpace ~
19463 mov\InsetSpace ~
19464 \InsetSpace ~
19465 \InsetSpace ~
19466 \InsetSpace ~
19467 dpl,a 
19468 \newline
19469 \InsetSpace ~
19470 \InsetSpace ~
19471 \InsetSpace ~
19472 \InsetSpace ~
19473 \InsetSpace ~
19474 \InsetSpace ~
19475 \InsetSpace ~
19476 \InsetSpace ~
19477 mov\InsetSpace ~
19478 \InsetSpace ~
19479 \InsetSpace ~
19480 \InsetSpace ~
19481 dph
19482 \begin_inset LatexCommand index
19483 name "DPTR, DPH, DPL"
19484
19485 \end_inset
19486
19487 ,#0x00 
19488 \newline
19489 \InsetSpace ~
19490 \InsetSpace ~
19491 \InsetSpace ~
19492 \InsetSpace ~
19493 \InsetSpace ~
19494 \InsetSpace ~
19495 \InsetSpace ~
19496 \InsetSpace ~
19497 ret
19498 \end_layout
19499
19500 \begin_layout Standard
19501 The parameter naming convention is _<function_name>_PARM_<n>, where n is
19502  the parameter number starting from 1, and counting from the left.
19503  The first parameter is passed in 
19504 \emph on
19505 DPH
19506 \emph default
19507
19508 \emph on
19509 DPL
19510 \emph default
19511
19512 \emph on
19513 B
19514 \emph default
19515  and 
19516 \emph on
19517 ACC
19518 \emph default
19519  according to the description above.
19520  The variable name for the second parameter will be _<function_name>_PARM_2.
19521 \newline
19522
19523 \newline
19524 Assem
19525 ble the assembler routine with the following command:
19526 \newline
19527
19528 \newline
19529
19530 \family sans
19531 \series bold
19532 asx8051 -losg asmfunc.asm
19533 \newline
19534
19535 \newline
19536
19537 \family default
19538 \series default
19539 Then compile and link the assembler routine to the C source file with the
19540  following command:
19541 \newline
19542
19543 \newline
19544
19545 \family sans
19546 \series bold
19547 sdcc cfunc.c asmfunc.rel
19548 \end_layout
19549
19550 \begin_layout Subsection
19551 Assembler Routine (reentrant)
19552 \end_layout
19553
19554 \begin_layout Standard
19555 In this case
19556 \begin_inset LatexCommand index
19557 name "reentrant"
19558
19559 \end_inset
19560
19561
19562 \begin_inset LatexCommand index
19563 name "Assembler routines (reentrant)"
19564
19565 \end_inset
19566
19567  the second parameter
19568 \begin_inset LatexCommand index
19569 name "function parameter"
19570
19571 \end_inset
19572
19573  onwards will be passed on the stack, the parameters are pushed from right
19574  to left i.e.
19575  before the call the second leftmost parameter will be on the top of the
19576  stack (the leftmost parameter is passed in registers).
19577  Here is an example:
19578 \end_layout
19579
19580 \begin_layout Verse
19581
19582 \family typewriter
19583 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
19584 \newline
19585
19586 \newline
19587 int
19588  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
19589 \newline
19590 {
19591  
19592 \newline
19593 \InsetSpace ~
19594 \InsetSpace ~
19595 \InsetSpace ~
19596 \InsetSpace ~
19597 return asm_func(i,j,k); 
19598 \newline
19599
19600 \newline
19601
19602 \newline
19603 int main() 
19604 \newline
19605
19606 \newline
19607 \InsetSpace ~
19608 \InsetSpace ~
19609 \InsetSpace ~
19610 \InsetSpace ~
19611 return c_func(10,9,8); 
19612 \newline
19613 }
19614 \end_layout
19615
19616 \begin_layout Standard
19617 The corresponding (unoptimized) assembler routine is:
19618 \end_layout
19619
19620 \begin_layout Verse
19621
19622 \family typewriter
19623 .globl _asm_func 
19624 \newline
19625 _asm_func: 
19626 \newline
19627 \InsetSpace ~
19628 \InsetSpace ~
19629 \InsetSpace ~
19630 \InsetSpace ~
19631 push\InsetSpace ~
19632 _bp 
19633 \newline
19634 \InsetSpace ~
19635 \InsetSpace ~
19636 \InsetSpace ~
19637 \InsetSpace ~
19638 mov\InsetSpace ~
19639 \InsetSpace ~
19640 _bp,sp\InsetSpace ~
19641 \InsetSpace ~
19642 \InsetSpace ~
19643 \InsetSpace ~
19644 \InsetSpace ~
19645 \InsetSpace ~
19646 ;stack contains: _bp, return
19647  address, second parameter, third parameter
19648 \newline
19649 \InsetSpace ~
19650 \InsetSpace ~
19651 \InsetSpace ~
19652 \InsetSpace ~
19653 mov\InsetSpace ~
19654 \InsetSpace ~
19655 r2,dpl
19656 \newline
19657 \InsetSpace ~
19658 \InsetSpace ~
19659 \InsetSpace ~
19660 \InsetSpace ~
19661 mov\InsetSpace ~
19662 \InsetSpace ~
19663 a,_bp
19664 \newline
19665 \InsetSpace ~
19666 \InsetSpace ~
19667 \InsetSpace ~
19668 \InsetSpace ~
19669 add\InsetSpace ~
19670 \InsetSpace ~
19671 a,#0xfd\InsetSpace ~
19672 \InsetSpace ~
19673 \InsetSpace ~
19674 \InsetSpace ~
19675 \InsetSpace ~
19676 ;calculate
19677  pointer to the second parameter
19678 \newline
19679 \InsetSpace ~
19680 \InsetSpace ~
19681 \InsetSpace ~
19682 \InsetSpace ~
19683 mov\InsetSpace ~
19684 \InsetSpace ~
19685 r0,a 
19686 \newline
19687 \InsetSpace ~
19688 \InsetSpace ~
19689 \InsetSpace ~
19690 \InsetSpace ~
19691 mov\InsetSpace ~
19692 \InsetSpace ~
19693 a,_bp 
19694 \newline
19695 \InsetSpace ~
19696 \InsetSpace ~
19697 \InsetSpace ~
19698 \InsetSpace ~
19699 add\InsetSpace ~
19700 \InsetSpace ~
19701 a,#0xfc\InsetSpace ~
19702 \InsetSpace ~
19703 \InsetSpace ~
19704 \InsetSpace ~
19705 \InsetSpace ~
19706 ;calculate pointer
19707  to the rightmost parameter
19708 \newline
19709 \InsetSpace ~
19710 \InsetSpace ~
19711 \InsetSpace ~
19712 \InsetSpace ~
19713 mov\InsetSpace ~
19714 \InsetSpace ~
19715 r1,a 
19716 \newline
19717 \InsetSpace ~
19718 \InsetSpace ~
19719 \InsetSpace ~
19720 \InsetSpace ~
19721 mov\InsetSpace ~
19722 \InsetSpace ~
19723 a,@r0
19724 \newline
19725 \InsetSpace ~
19726 \InsetSpace ~
19727 \InsetSpace ~
19728 \InsetSpace ~
19729 add\InsetSpace ~
19730 \InsetSpace ~
19731 a,@r1
19732 \newline
19733 \InsetSpace ~
19734 \InsetSpace ~
19735 \InsetSpace ~
19736 \InsetSpace ~
19737 add\InsetSpace ~
19738 \InsetSpace ~
19739 a,r2\InsetSpace ~
19740 \InsetSpace ~
19741 \InsetSpace ~
19742 \InsetSpace ~
19743 \InsetSpace ~
19744 \InsetSpace ~
19745 \InsetSpace ~
19746 \InsetSpace ~
19747 ;calculate the
19748  result (= sum of all three parameters)
19749 \newline
19750 \InsetSpace ~
19751 \InsetSpace ~
19752 \InsetSpace ~
19753 \InsetSpace ~
19754 mov\InsetSpace ~
19755 \InsetSpace ~
19756 dpl,a\InsetSpace ~
19757 \InsetSpace ~
19758 \InsetSpace ~
19759 \InsetSpace ~
19760 \InsetSpace ~
19761 \InsetSpace ~
19762 \InsetSpace ~
19763 ;return value goes into dptr
19764  (cast into int)
19765 \newline
19766 \InsetSpace ~
19767 \InsetSpace ~
19768 \InsetSpace ~
19769 \InsetSpace ~
19770 mov\InsetSpace ~
19771 \InsetSpace ~
19772 dph,#0x00 
19773 \newline
19774 \InsetSpace ~
19775 \InsetSpace ~
19776 \InsetSpace ~
19777 \InsetSpace ~
19778 mov\InsetSpace ~
19779 \InsetSpace ~
19780 sp,_bp 
19781 \newline
19782 \InsetSpace ~
19783 \InsetSpace ~
19784 \InsetSpace ~
19785 \InsetSpace ~
19786 pop\InsetSpace ~
19787 \InsetSpace ~
19788 _bp 
19789 \newline
19790 \InsetSpace ~
19791 \InsetSpace ~
19792 \InsetSpace ~
19793 \InsetSpace ~
19794 ret
19795 \end_layout
19796
19797 \begin_layout Standard
19798 The compiling and linking procedure remains the same, however note the extra
19799  entry & exit linkage required for the assembler code, _bp is the stack
19800  frame pointer and is used to compute the offset into the stack for parameters
19801  and local variables.
19802 \begin_inset VSpace bigskip
19803 \end_inset
19804
19805
19806 \end_layout
19807
19808 \begin_layout Section
19809 int (16 bit)
19810 \begin_inset LatexCommand index
19811 name "int (16 bit)"
19812
19813 \end_inset
19814
19815  and long (32 bit)
19816 \begin_inset LatexCommand index
19817 name "long (32 bit)"
19818
19819 \end_inset
19820
19821  Support
19822 \end_layout
19823
19824 \begin_layout Standard
19825 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19826  multiplication and modulus operations are implemented by support routines.
19827  These support routines are all developed in ANSI-C to facilitate porting
19828  to other MCUs, although some model specific assembler optimizations are
19829  used.
19830  The following files contain the described routines, all of them can be
19831  found in <installdir>/share/sdcc/lib.
19832 \newline
19833
19834 \end_layout
19835
19836 \begin_layout Standard
19837 \align center
19838 \begin_inset Tabular
19839 <lyxtabular version="3" rows="11" columns="2">
19840 <features>
19841 <column alignment="left" valignment="top" leftline="true" width="0">
19842 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19843 <row topline="true" bottomline="true">
19844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19845 \begin_inset Text
19846
19847 \begin_layout Standard
19848
19849 \series bold
19850 Function
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 \series bold
19861 Description
19862 \end_layout
19863
19864 \end_inset
19865 </cell>
19866 </row>
19867 <row topline="true">
19868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19869 \begin_inset Text
19870
19871 \begin_layout Standard
19872 _mulint.c 
19873 \end_layout
19874
19875 \end_inset
19876 </cell>
19877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19878 \begin_inset Text
19879
19880 \begin_layout Standard
19881 16 bit multiplication
19882 \end_layout
19883
19884 \end_inset
19885 </cell>
19886 </row>
19887 <row topline="true">
19888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19889 \begin_inset Text
19890
19891 \begin_layout Standard
19892 _divsint.c 
19893 \end_layout
19894
19895 \end_inset
19896 </cell>
19897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19898 \begin_inset Text
19899
19900 \begin_layout Standard
19901  signed 16 bit division (calls _divuint)
19902 \end_layout
19903
19904 \end_inset
19905 </cell>
19906 </row>
19907 <row topline="true">
19908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19909 \begin_inset Text
19910
19911 \begin_layout Standard
19912 _divuint.c 
19913 \end_layout
19914
19915 \end_inset
19916 </cell>
19917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19918 \begin_inset Text
19919
19920 \begin_layout Standard
19921  unsigned 16 bit division
19922 \end_layout
19923
19924 \end_inset
19925 </cell>
19926 </row>
19927 <row topline="true">
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19929 \begin_inset Text
19930
19931 \begin_layout Standard
19932 _modsint.c
19933 \end_layout
19934
19935 \end_inset
19936 </cell>
19937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19938 \begin_inset Text
19939
19940 \begin_layout Standard
19941 signed 16 bit modulus (calls _moduint)
19942 \end_layout
19943
19944 \end_inset
19945 </cell>
19946 </row>
19947 <row topline="true">
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19949 \begin_inset Text
19950
19951 \begin_layout Standard
19952 _moduint.c
19953 \end_layout
19954
19955 \end_inset
19956 </cell>
19957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19958 \begin_inset Text
19959
19960 \begin_layout Standard
19961 unsigned 16 bit modulus
19962 \end_layout
19963
19964 \end_inset
19965 </cell>
19966 </row>
19967 <row topline="true">
19968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19969 \begin_inset Text
19970
19971 \begin_layout Standard
19972 _mullong.c
19973 \end_layout
19974
19975 \end_inset
19976 </cell>
19977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19978 \begin_inset Text
19979
19980 \begin_layout Standard
19981 32 bit multiplication
19982 \end_layout
19983
19984 \end_inset
19985 </cell>
19986 </row>
19987 <row topline="true">
19988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19989 \begin_inset Text
19990
19991 \begin_layout Standard
19992 _divslong.c 
19993 \end_layout
19994
19995 \end_inset
19996 </cell>
19997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19998 \begin_inset Text
19999
20000 \begin_layout Standard
20001  signed 32 division (calls _divulong)
20002 \end_layout
20003
20004 \end_inset
20005 </cell>
20006 </row>
20007 <row topline="true">
20008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20009 \begin_inset Text
20010
20011 \begin_layout Standard
20012 _divulong.c 
20013 \end_layout
20014
20015 \end_inset
20016 </cell>
20017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20018 \begin_inset Text
20019
20020 \begin_layout Standard
20021 unsigned 32 division
20022 \end_layout
20023
20024 \end_inset
20025 </cell>
20026 </row>
20027 <row topline="true">
20028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20029 \begin_inset Text
20030
20031 \begin_layout Standard
20032 _modslong.c
20033 \end_layout
20034
20035 \end_inset
20036 </cell>
20037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20038 \begin_inset Text
20039
20040 \begin_layout Standard
20041  signed 32 bit modulus (calls _modulong)
20042 \end_layout
20043
20044 \end_inset
20045 </cell>
20046 </row>
20047 <row topline="true" bottomline="true">
20048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20049 \begin_inset Text
20050
20051 \begin_layout Standard
20052 _modulong.c
20053 \end_layout
20054
20055 \end_inset
20056 </cell>
20057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20058 \begin_inset Text
20059
20060 \begin_layout Standard
20061 unsigned 32 bit modulus
20062 \end_layout
20063
20064 \end_inset
20065 </cell>
20066 </row>
20067 </lyxtabular>
20068
20069 \end_inset
20070
20071
20072 \newline
20073
20074 \end_layout
20075
20076 \begin_layout Standard
20077 Since they are compiled as 
20078 \emph on
20079 non-reentrant
20080 \emph default
20081
20082 \begin_inset LatexCommand index
20083 name "reentrant"
20084
20085 \end_inset
20086
20087 , interrupt
20088 \begin_inset LatexCommand index
20089 name "interrupt"
20090
20091 \end_inset
20092
20093  service routines should not do any of the above operations.
20094  If this is unavoidable then the above routines will need to be compiled
20095  with the 
20096 \emph on
20097 -
20098 \begin_inset ERT
20099 status collapsed
20100
20101 \begin_layout Standard
20102
20103
20104 \backslash
20105 /
20106 \end_layout
20107
20108 \end_inset
20109
20110 -stack-auto
20111 \begin_inset LatexCommand index
20112 name "-\\/-stack-auto"
20113
20114 \end_inset
20115
20116
20117 \emph default
20118  option, after which the source program will have to be compiled with 
20119 \emph on
20120 -
20121 \begin_inset ERT
20122 status collapsed
20123
20124 \begin_layout Standard
20125
20126
20127 \backslash
20128 /
20129 \end_layout
20130
20131 \end_inset
20132
20133 -int-long-reent
20134 \begin_inset LatexCommand index
20135 name "-\\/-int-long-reent"
20136
20137 \end_inset
20138
20139
20140 \emph default
20141  option.
20142  Notice that you don't have to call these routines directly.
20143  The compiler will use them automatically every time an integer operation
20144  is required.
20145 \end_layout
20146
20147 \begin_layout Section
20148 Floating Point Support
20149 \begin_inset LatexCommand index
20150 name "Floating point support"
20151
20152 \end_inset
20153
20154
20155 \end_layout
20156
20157 \begin_layout Standard
20158 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
20159  The floating point support routines are derived from gcc's floatlib.c and
20160  consist of the following routines:
20161 \newline
20162
20163 \end_layout
20164
20165 \begin_layout Standard
20166 \align center
20167
20168 \size footnotesize
20169 \begin_inset Tabular
20170 <lyxtabular version="3" rows="17" columns="2">
20171 <features>
20172 <column alignment="left" valignment="top" leftline="true" width="0">
20173 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20174 <row topline="true" bottomline="true">
20175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20176 \begin_inset Text
20177
20178 \begin_layout Standard
20179
20180 \family roman
20181 \series medium
20182 \shape up
20183 \size normal
20184 \emph off
20185 \bar no
20186 \noun off
20187 \color none
20188 Function 
20189 \end_layout
20190
20191 \end_inset
20192 </cell>
20193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20194 \begin_inset Text
20195
20196 \begin_layout Standard
20197 Description
20198 \end_layout
20199
20200 \end_inset
20201 </cell>
20202 </row>
20203 <row topline="true">
20204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20205 \begin_inset Text
20206
20207 \begin_layout Standard
20208
20209 \family roman
20210 \series medium
20211 \shape up
20212 \size normal
20213 \emph off
20214 \bar no
20215 \noun off
20216 \color none
20217 _fsadd.c
20218 \end_layout
20219
20220 \end_inset
20221 </cell>
20222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20223 \begin_inset Text
20224
20225 \begin_layout Standard
20226
20227 \family roman
20228 \series medium
20229 \shape up
20230 \size normal
20231 \emph off
20232 \bar no
20233 \noun off
20234 \color none
20235 add floating point numbers
20236 \end_layout
20237
20238 \end_inset
20239 </cell>
20240 </row>
20241 <row topline="true">
20242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20243 \begin_inset Text
20244
20245 \begin_layout Standard
20246
20247 \family roman
20248 \series medium
20249 \shape up
20250 \size normal
20251 \emph off
20252 \bar no
20253 \noun off
20254 \color none
20255 _fssub.c 
20256 \end_layout
20257
20258 \end_inset
20259 </cell>
20260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20261 \begin_inset Text
20262
20263 \begin_layout Standard
20264
20265 \family roman
20266 \series medium
20267 \shape up
20268 \size normal
20269 \emph off
20270 \bar no
20271 \noun off
20272 \color none
20273 subtract floating point numbers 
20274 \end_layout
20275
20276 \end_inset
20277 </cell>
20278 </row>
20279 <row topline="true">
20280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20281 \begin_inset Text
20282
20283 \begin_layout Standard
20284
20285 \family roman
20286 \series medium
20287 \shape up
20288 \size normal
20289 \emph off
20290 \bar no
20291 \noun off
20292 \color none
20293 _fsdiv.c 
20294 \end_layout
20295
20296 \end_inset
20297 </cell>
20298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20299 \begin_inset Text
20300
20301 \begin_layout Standard
20302
20303 \family roman
20304 \series medium
20305 \shape up
20306 \size normal
20307 \emph off
20308 \bar no
20309 \noun off
20310 \color none
20311 divide floating point numbers 
20312 \end_layout
20313
20314 \end_inset
20315 </cell>
20316 </row>
20317 <row topline="true">
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20319 \begin_inset Text
20320
20321 \begin_layout Standard
20322
20323 \family roman
20324 \series medium
20325 \shape up
20326 \size normal
20327 \emph off
20328 \bar no
20329 \noun off
20330 \color none
20331 _fsmul.c 
20332 \end_layout
20333
20334 \end_inset
20335 </cell>
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20337 \begin_inset Text
20338
20339 \begin_layout Standard
20340
20341 \family roman
20342 \series medium
20343 \shape up
20344 \size normal
20345 \emph off
20346 \bar no
20347 \noun off
20348 \color none
20349 multiply floating point numbers 
20350 \end_layout
20351
20352 \end_inset
20353 </cell>
20354 </row>
20355 <row topline="true">
20356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20357 \begin_inset Text
20358
20359 \begin_layout Standard
20360
20361 \family roman
20362 \series medium
20363 \shape up
20364 \size normal
20365 \emph off
20366 \bar no
20367 \noun off
20368 \color none
20369 _fs2uchar.c
20370 \end_layout
20371
20372 \end_inset
20373 </cell>
20374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20375 \begin_inset Text
20376
20377 \begin_layout Standard
20378
20379 \family roman
20380 \series medium
20381 \shape up
20382 \size normal
20383 \emph off
20384 \bar no
20385 \noun off
20386 \color none
20387 convert floating point to unsigned char
20388 \end_layout
20389
20390 \end_inset
20391 </cell>
20392 </row>
20393 <row topline="true">
20394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20395 \begin_inset Text
20396
20397 \begin_layout Standard
20398
20399 \family roman
20400 \series medium
20401 \shape up
20402 \size normal
20403 \emph off
20404 \bar no
20405 \noun off
20406 \color none
20407 _fs2char.c
20408 \end_layout
20409
20410 \end_inset
20411 </cell>
20412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20413 \begin_inset Text
20414
20415 \begin_layout Standard
20416
20417 \family roman
20418 \series medium
20419 \shape up
20420 \size normal
20421 \emph off
20422 \bar no
20423 \noun off
20424 \color none
20425 convert floating point to signed char
20426 \end_layout
20427
20428 \end_inset
20429 </cell>
20430 </row>
20431 <row topline="true">
20432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20433 \begin_inset Text
20434
20435 \begin_layout Standard
20436
20437 \family roman
20438 \series medium
20439 \shape up
20440 \size normal
20441 \emph off
20442 \bar no
20443 \noun off
20444 \color none
20445 _fs2uint.c
20446 \end_layout
20447
20448 \end_inset
20449 </cell>
20450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20451 \begin_inset Text
20452
20453 \begin_layout Standard
20454
20455 \family roman
20456 \series medium
20457 \shape up
20458 \size normal
20459 \emph off
20460 \bar no
20461 \noun off
20462 \color none
20463 convert floating point to unsigned int
20464 \end_layout
20465
20466 \end_inset
20467 </cell>
20468 </row>
20469 <row topline="true">
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20471 \begin_inset Text
20472
20473 \begin_layout Standard
20474
20475 \family roman
20476 \series medium
20477 \shape up
20478 \size normal
20479 \emph off
20480 \bar no
20481 \noun off
20482 \color none
20483 _fs2int.c
20484 \end_layout
20485
20486 \end_inset
20487 </cell>
20488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20489 \begin_inset Text
20490
20491 \begin_layout Standard
20492
20493 \family roman
20494 \series medium
20495 \shape up
20496 \size normal
20497 \emph off
20498 \bar no
20499 \noun off
20500 \color none
20501 convert floating point to signed int
20502 \end_layout
20503
20504 \end_inset
20505 </cell>
20506 </row>
20507 <row topline="true">
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20509 \begin_inset Text
20510
20511 \begin_layout Standard
20512
20513 \family roman
20514 \series medium
20515 \shape up
20516 \size normal
20517 \emph off
20518 \bar no
20519 \noun off
20520 \color none
20521 _fs2ulong.
20522 \family default
20523 \series default
20524 \shape default
20525 \size default
20526 \emph default
20527 \bar default
20528 \noun default
20529 c
20530 \end_layout
20531
20532 \end_inset
20533 </cell>
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20535 \begin_inset Text
20536
20537 \begin_layout Standard
20538
20539 \family roman
20540 \series medium
20541 \shape up
20542 \size normal
20543 \emph off
20544 \bar no
20545 \noun off
20546 \color none
20547 convert floating point to unsigned long
20548 \end_layout
20549
20550 \end_inset
20551 </cell>
20552 </row>
20553 <row topline="true">
20554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20555 \begin_inset Text
20556
20557 \begin_layout Standard
20558
20559 \family roman
20560 \series medium
20561 \shape up
20562 \size normal
20563 \emph off
20564 \bar no
20565 \noun off
20566 \color none
20567 _fs2long.c
20568 \end_layout
20569
20570 \end_inset
20571 </cell>
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20573 \begin_inset Text
20574
20575 \begin_layout Standard
20576
20577 \family roman
20578 \series medium
20579 \shape up
20580 \size normal
20581 \emph off
20582 \bar no
20583 \noun off
20584 \color none
20585 convert floating point to signed long
20586 \end_layout
20587
20588 \end_inset
20589 </cell>
20590 </row>
20591 <row topline="true">
20592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20593 \begin_inset Text
20594
20595 \begin_layout Standard
20596
20597 \family roman
20598 \series medium
20599 \shape up
20600 \size normal
20601 \emph off
20602 \bar no
20603 \noun off
20604 \color none
20605 _uchar2fs.c
20606 \end_layout
20607
20608 \end_inset
20609 </cell>
20610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20611 \begin_inset Text
20612
20613 \begin_layout Standard
20614
20615 \family roman
20616 \series medium
20617 \shape up
20618 \size normal
20619 \emph off
20620 \bar no
20621 \noun off
20622 \color none
20623 convert unsigned char to floating point
20624 \end_layout
20625
20626 \end_inset
20627 </cell>
20628 </row>
20629 <row topline="true">
20630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20631 \begin_inset Text
20632
20633 \begin_layout Standard
20634
20635 \family roman
20636 \series medium
20637 \shape up
20638 \size normal
20639 \emph off
20640 \bar no
20641 \noun off
20642 \color none
20643 _char2fs.c
20644 \end_layout
20645
20646 \end_inset
20647 </cell>
20648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20649 \begin_inset Text
20650
20651 \begin_layout Standard
20652
20653 \family roman
20654 \series medium
20655 \shape up
20656 \size normal
20657 \emph off
20658 \bar no
20659 \noun off
20660 \color none
20661 convert char to floating point number
20662 \end_layout
20663
20664 \end_inset
20665 </cell>
20666 </row>
20667 <row topline="true">
20668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20669 \begin_inset Text
20670
20671 \begin_layout Standard
20672
20673 \family roman
20674 \series medium
20675 \shape up
20676 \size normal
20677 \emph off
20678 \bar no
20679 \noun off
20680 \color none
20681 _uint2fs.c
20682 \end_layout
20683
20684 \end_inset
20685 </cell>
20686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20687 \begin_inset Text
20688
20689 \begin_layout Standard
20690
20691 \family roman
20692 \series medium
20693 \shape up
20694 \size normal
20695 \emph off
20696 \bar no
20697 \noun off
20698 \color none
20699 convert unsigned int to floating point
20700 \end_layout
20701
20702 \end_inset
20703 </cell>
20704 </row>
20705 <row topline="true">
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20707 \begin_inset Text
20708
20709 \begin_layout Standard
20710
20711 \family roman
20712 \series medium
20713 \shape up
20714 \size normal
20715 \emph off
20716 \bar no
20717 \noun off
20718 \color none
20719 _int2fs.c
20720 \end_layout
20721
20722 \end_inset
20723 </cell>
20724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20725 \begin_inset Text
20726
20727 \begin_layout Standard
20728
20729 \family roman
20730 \series medium
20731 \shape up
20732 \size normal
20733 \emph off
20734 \bar no
20735 \noun off
20736 \color none
20737 convert int to floating point numbers
20738 \end_layout
20739
20740 \end_inset
20741 </cell>
20742 </row>
20743 <row topline="true">
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20745 \begin_inset Text
20746
20747 \begin_layout Standard
20748
20749 \family roman
20750 \series medium
20751 \shape up
20752 \size normal
20753 \emph off
20754 \bar no
20755 \noun off
20756 \color none
20757 _ulong2fs.c
20758 \end_layout
20759
20760 \end_inset
20761 </cell>
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20763 \begin_inset Text
20764
20765 \begin_layout Standard
20766
20767 \family roman
20768 \series medium
20769 \shape up
20770 \size normal
20771 \emph off
20772 \bar no
20773 \noun off
20774 \color none
20775 convert unsigned long to floating point number
20776 \end_layout
20777
20778 \end_inset
20779 </cell>
20780 </row>
20781 <row topline="true" bottomline="true">
20782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20783 \begin_inset Text
20784
20785 \begin_layout Standard
20786
20787 \family roman
20788 \series medium
20789 \shape up
20790 \size normal
20791 \emph off
20792 \bar no
20793 \noun off
20794 \color none
20795 _long2fs.c
20796 \end_layout
20797
20798 \end_inset
20799 </cell>
20800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20801 \begin_inset Text
20802
20803 \begin_layout Standard
20804
20805 \family roman
20806 \series medium
20807 \shape up
20808 \size normal
20809 \emph off
20810 \bar no
20811 \noun off
20812 \color none
20813 convert long to floating point number
20814 \end_layout
20815
20816 \end_inset
20817 </cell>
20818 </row>
20819 </lyxtabular>
20820
20821 \end_inset
20822
20823
20824 \newline
20825
20826 \end_layout
20827
20828 \begin_layout Standard
20829 These support routines are developed in ANSI-C so there is room for space
20830  and speed improvement
20831 \begin_inset Foot
20832 status open
20833
20834 \begin_layout Standard
20835 These floating point routines (
20836 \emph on
20837 not
20838 \emph default
20839  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
20840  
20841 \end_layout
20842
20843 \end_inset
20844
20845 .
20846  Note if all these routines are used simultaneously the data space might
20847  overflow.
20848  For serious floating point usage the large model might be needed.
20849  Also notice that you don't have to call this routines directly.
20850  The compiler will use them automatically every time a floating point operation
20851  is required.
20852 \begin_inset VSpace bigskip
20853 \end_inset
20854
20855
20856 \end_layout
20857
20858 \begin_layout Section
20859 Library Routines
20860 \begin_inset LatexCommand index
20861 name "Libraries"
20862
20863 \end_inset
20864
20865
20866 \end_layout
20867
20868 \begin_layout Standard
20869
20870 \emph on
20871 <pending: this is messy and incomplete - a little more information is in
20872  sdcc/doc/libdoc.txt
20873 \emph default
20874  >
20875 \end_layout
20876
20877 \begin_layout Subsection
20878 Compiler support routines (_gptrget, _mulint etc.)
20879 \end_layout
20880
20881 \begin_layout Subsection
20882 Stdclib functions (puts, printf, strcat etc.)
20883 \end_layout
20884
20885 \begin_layout Subsubsection
20886 <stdio.h>
20887 \end_layout
20888
20889 \begin_layout Paragraph
20890 getchar(), putchar()
20891 \end_layout
20892
20893 \begin_layout Standard
20894 \begin_inset LatexCommand index
20895 name "<stdio.h>"
20896
20897 \end_inset
20898
20899 As usual on embedded systems you have to provide your own 
20900 \family typewriter
20901 getchar()
20902 \begin_inset LatexCommand index
20903 name "getchar()"
20904
20905 \end_inset
20906
20907
20908 \family default
20909  and 
20910 \family typewriter
20911 putchar()
20912 \begin_inset LatexCommand index
20913 name "putchar()"
20914
20915 \end_inset
20916
20917
20918 \family default
20919  routines.
20920  SDCC does not know whether the system connects to a serial line with or
20921  without handshake, LCD, keyboard or other device.
20922  And whether a 
20923 \family typewriter
20924 lf
20925 \family default
20926  to 
20927 \family typewriter
20928 crlf
20929 \family default
20930  conversion within 
20931 \family typewriter
20932 putchar()
20933 \family default
20934  is intended.
20935  You'll find examples for serial routines f.e.
20936  in sdcc/device/lib.
20937  For the mcs51 this minimalistic polling 
20938 \family typewriter
20939 putchar()
20940 \family default
20941  routine might be a start:
20942 \end_layout
20943
20944 \begin_layout Verse
20945
20946 \family typewriter
20947 void putchar (char c) { 
20948 \newline
20949 \InsetSpace ~
20950 \InsetSpace ~
20951 \InsetSpace ~
20952 \InsetSpace ~
20953 while (!TI)\InsetSpace ~
20954 \InsetSpace ~
20955 \InsetSpace ~
20956  /* assumes UART is initialized */
20957 \newline
20958 \InsetSpace ~
20959 \InsetSpace ~
20960 \InsetSpace ~
20961 \InsetSpace ~
20962 \InsetSpace ~
20963 \InsetSpace ~
20964 \InsetSpace ~
20965 \InsetSpace ~
20966 ;
20967 \newline
20968 \InsetSpace ~
20969 \InsetSpace ~
20970 \InsetSpace ~
20971 \InsetSpace ~
20972 TI
20973  = 0;
20974 \newline
20975 \InsetSpace ~
20976 \InsetSpace ~
20977 \InsetSpace ~
20978 \InsetSpace ~
20979 SBUF = c;
20980 \newline
20981 }
20982 \end_layout
20983
20984 \begin_layout Paragraph
20985 printf()
20986 \end_layout
20987
20988 \begin_layout Standard
20989 The default 
20990 \family typewriter
20991 printf()
20992 \begin_inset LatexCommand index
20993 name "printf()"
20994
20995 \end_inset
20996
20997
20998 \family default
20999  implementation in 
21000 \family typewriter
21001 printf_large.c
21002 \family default
21003  does not support float (except on ds390).
21004  To enable this recompile it with the option 
21005 \emph on
21006 -
21007 \begin_inset ERT
21008 status collapsed
21009
21010 \begin_layout Standard
21011
21012
21013 \backslash
21014 /
21015 \end_layout
21016
21017 \end_inset
21018
21019 DUSE_FLOATS=1
21020 \begin_inset LatexCommand index
21021 name "USE\\_FLOATS"
21022
21023 \end_inset
21024
21025
21026 \emph default
21027  on the command line.
21028  Use 
21029 \emph on
21030 -
21031 \begin_inset ERT
21032 status collapsed
21033
21034 \begin_layout Standard
21035
21036
21037 \backslash
21038 /
21039 \end_layout
21040
21041 \end_inset
21042
21043 -model-large
21044 \begin_inset LatexCommand index
21045 name "-\\/-model-large"
21046
21047 \end_inset
21048
21049
21050 \emph default
21051  for the mcs51 port, since this uses a lot of memory.
21052 \end_layout
21053
21054 \begin_layout Standard
21055 If you're short on code memory you might want to use 
21056 \family typewriter
21057 printf_small()
21058 \begin_inset LatexCommand index
21059 name "printf\\_small()"
21060
21061 \end_inset
21062
21063
21064 \family default
21065  
21066 \emph on
21067 instead
21068 \emph default
21069  of 
21070 \family typewriter
21071 printf().
21072
21073 \family default
21074  For the mcs51 there additionally are assembly versions 
21075 \family typewriter
21076 printf_tiny()
21077 \begin_inset LatexCommand index
21078 name "printf\\_tiny() (mcs51)"
21079
21080 \end_inset
21081
21082
21083 \family default
21084  (subset of printf using less than 270 bytes) and 
21085 \family typewriter
21086 printf_fast()
21087 \begin_inset LatexCommand index
21088 name "printf\\_fast() (mcs51)"
21089
21090 \end_inset
21091
21092
21093 \family default
21094  and 
21095 \family typewriter
21096 printf_fast_f()
21097 \begin_inset LatexCommand index
21098 name "printf\\_fast\\_f() (mcs51)"
21099
21100 \end_inset
21101
21102
21103 \family default
21104  (floating-point aware version of printf_fast) which should fit the requirements
21105  of many embedded systems (printf_fast() can be customized by unsetting
21106  #defines to 
21107 \emph on
21108 not
21109 \emph default
21110  support long variables and field widths).
21111  Be sure to use only one of these printf options within a project.
21112 \newline
21113
21114 \end_layout
21115
21116 \begin_layout Standard
21117 Feature matrix of different 
21118 \emph on
21119 printf
21120 \emph default
21121  options on mcs51.
21122 \end_layout
21123
21124 \begin_layout Standard
21125 \begin_inset Tabular
21126 <lyxtabular version="3" rows="14" columns="7">
21127 <features islongtable="true">
21128 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21129 <column alignment="center" valignment="top" leftline="true" width="0">
21130 <column alignment="center" valignment="top" leftline="true" width="12col%">
21131 <column alignment="center" valignment="top" leftline="true" width="10col%">
21132 <column alignment="center" valignment="top" leftline="true" width="0">
21133 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21134 <column alignment="center" valignment="top" rightline="true" width="0">
21135 <row topline="true" bottomline="true" endhead="true">
21136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21137 \begin_inset Text
21138
21139 \begin_layout Standard
21140
21141 \series bold
21142 \size large
21143 mcs51
21144 \end_layout
21145
21146 \end_inset
21147 </cell>
21148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21149 \begin_inset Text
21150
21151 \begin_layout Standard
21152 printf
21153 \begin_inset LatexCommand index
21154 name "printf"
21155
21156 \end_inset
21157
21158
21159 \end_layout
21160
21161 \end_inset
21162 </cell>
21163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21164 \begin_inset Text
21165
21166 \begin_layout Standard
21167 printf 
21168 \size scriptsize
21169 USE_FLOATS=1
21170 \end_layout
21171
21172 \end_inset
21173 </cell>
21174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21175 \begin_inset Text
21176
21177 \begin_layout Standard
21178 printf_small
21179 \end_layout
21180
21181 \end_inset
21182 </cell>
21183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21184 \begin_inset Text
21185
21186 \begin_layout Standard
21187 printf_fast
21188 \end_layout
21189
21190 \end_inset
21191 </cell>
21192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21193 \begin_inset Text
21194
21195 \begin_layout Standard
21196 printf_fast_f
21197 \end_layout
21198
21199 \end_inset
21200 </cell>
21201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21202 \begin_inset Text
21203
21204 \begin_layout Standard
21205 printf_tiny
21206 \end_layout
21207
21208 \end_inset
21209 </cell>
21210 </row>
21211 <row topline="true" endhead="true">
21212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21213 \begin_inset Text
21214
21215 \begin_layout Standard
21216 filename
21217 \end_layout
21218
21219 \end_inset
21220 </cell>
21221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21222 \begin_inset Text
21223
21224 \begin_layout Standard
21225
21226 \size scriptsize
21227 printf_large.c
21228 \end_layout
21229
21230 \end_inset
21231 </cell>
21232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21233 \begin_inset Text
21234
21235 \begin_layout Standard
21236
21237 \size scriptsize
21238 printf_large.c
21239 \end_layout
21240
21241 \end_inset
21242 </cell>
21243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21244 \begin_inset Text
21245
21246 \begin_layout Standard
21247
21248 \size scriptsize
21249 printfl.c
21250 \end_layout
21251
21252 \end_inset
21253 </cell>
21254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21255 \begin_inset Text
21256
21257 \begin_layout Standard
21258
21259 \size scriptsize
21260 printf_fast.c
21261 \end_layout
21262
21263 \end_inset
21264 </cell>
21265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21266 \begin_inset Text
21267
21268 \begin_layout Standard
21269
21270 \size scriptsize
21271 printf_fast_f.c
21272 \end_layout
21273
21274 \end_inset
21275 </cell>
21276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21277 \begin_inset Text
21278
21279 \begin_layout Standard
21280
21281 \size scriptsize
21282 printf_tiny.c
21283 \end_layout
21284
21285 \end_inset
21286 </cell>
21287 </row>
21288 <row topline="true" endhead="true">
21289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21290 \begin_inset Text
21291
21292 \begin_layout Standard
21293 \begin_inset Quotes sld
21294 \end_inset
21295
21296 Hello World
21297 \begin_inset Quotes srd
21298 \end_inset
21299
21300  size
21301 \end_layout
21302
21303 \begin_layout Standard
21304 small / large
21305 \end_layout
21306
21307 \end_inset
21308 </cell>
21309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21310 \begin_inset Text
21311
21312 \begin_layout Standard
21313 1.7k / 2.4k
21314 \end_layout
21315
21316 \end_inset
21317 </cell>
21318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21319 \begin_inset Text
21320
21321 \begin_layout Standard
21322 4.3k / 5.6k
21323 \end_layout
21324
21325 \end_inset
21326 </cell>
21327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21328 \begin_inset Text
21329
21330 \begin_layout Standard
21331 1.2k / 1.8k
21332 \end_layout
21333
21334 \end_inset
21335 </cell>
21336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21337 \begin_inset Text
21338
21339 \begin_layout Standard
21340 1.3k / 1.3k
21341 \end_layout
21342
21343 \end_inset
21344 </cell>
21345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21346 \begin_inset Text
21347
21348 \begin_layout Standard
21349 1.9k / 1.9k
21350 \end_layout
21351
21352 \end_inset
21353 </cell>
21354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21355 \begin_inset Text
21356
21357 \begin_layout Standard
21358 0.44k / 0.44k
21359 \end_layout
21360
21361 \end_inset
21362 </cell>
21363 </row>
21364 <row topline="true" endhead="true">
21365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21366 \begin_inset Text
21367
21368 \begin_layout Standard
21369 code size
21370 \end_layout
21371
21372 \begin_layout Standard
21373 small / large
21374 \end_layout
21375
21376 \end_inset
21377 </cell>
21378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21379 \begin_inset Text
21380
21381 \begin_layout Standard
21382 1.4k / 2.0k
21383 \end_layout
21384
21385 \end_inset
21386 </cell>
21387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21388 \begin_inset Text
21389
21390 \begin_layout Standard
21391 2.8k / 3.7k
21392 \end_layout
21393
21394 \end_inset
21395 </cell>
21396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21397 \begin_inset Text
21398
21399 \begin_layout Standard
21400 0.45k / 0.47k (+ _ltoa)
21401 \end_layout
21402
21403 \end_inset
21404 </cell>
21405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21406 \begin_inset Text
21407
21408 \begin_layout Standard
21409 1.2k / 1.2k
21410 \end_layout
21411
21412 \end_inset
21413 </cell>
21414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21415 \begin_inset Text
21416
21417 \begin_layout Standard
21418 1.6k / 1.6k
21419 \end_layout
21420
21421 \end_inset
21422 </cell>
21423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21424 \begin_inset Text
21425
21426 \begin_layout Standard
21427 0.26k / 0.26k
21428 \end_layout
21429
21430 \end_inset
21431 </cell>
21432 </row>
21433 <row topline="true">
21434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21435 \begin_inset Text
21436
21437 \begin_layout Standard
21438 formats
21439 \end_layout
21440
21441 \end_inset
21442 </cell>
21443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21444 \begin_inset Text
21445
21446 \begin_layout Standard
21447 cdi
21448 \emph on
21449 o
21450 \emph default
21451 psux
21452 \end_layout
21453
21454 \end_inset
21455 </cell>
21456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21457 \begin_inset Text
21458
21459 \begin_layout Standard
21460
21461 \family roman
21462 \series medium
21463 \shape up
21464 \size normal
21465 \emph off
21466 \bar no
21467 \noun off
21468 \color none
21469 cd
21470 \family default
21471 \series default
21472 \shape default
21473 \size default
21474 \emph default
21475 \bar default
21476 \noun default
21477 f
21478 \family roman
21479 \series medium
21480 \shape up
21481 \size normal
21482 \emph off
21483 \bar no
21484 \noun off
21485 i
21486 \family default
21487 \series default
21488 \shape default
21489 \size default
21490 \emph on
21491 \bar default
21492 \noun default
21493 o
21494 \family roman
21495 \series medium
21496 \shape up
21497 \size normal
21498 \emph off
21499 \bar no
21500 \noun off
21501 psux
21502 \end_layout
21503
21504 \end_inset
21505 </cell>
21506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21507 \begin_inset Text
21508
21509 \begin_layout Standard
21510 c
21511 \family roman
21512 \series medium
21513 \shape up
21514 \size normal
21515 \emph off
21516 \bar no
21517 \noun off
21518 \color none
21519 d
21520 \family default
21521 \series default
21522 \shape default
21523 \size default
21524 \emph on
21525 \bar default
21526 \noun default
21527 o
21528 \family roman
21529 \series medium
21530 \shape up
21531 \size normal
21532 \emph off
21533 \bar no
21534 \noun off
21535 s
21536 \family default
21537 \series default
21538 \shape default
21539 \size default
21540 \emph default
21541 \bar default
21542 \noun default
21543 x
21544 \end_layout
21545
21546 \end_inset
21547 </cell>
21548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21549 \begin_inset Text
21550
21551 \begin_layout Standard
21552 cdsux
21553 \end_layout
21554
21555 \end_inset
21556 </cell>
21557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21558 \begin_inset Text
21559
21560 \begin_layout Standard
21561 cdfsux
21562 \end_layout
21563
21564 \end_inset
21565 </cell>
21566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21567 \begin_inset Text
21568
21569 \begin_layout Standard
21570 cdsux
21571 \end_layout
21572
21573 \end_inset
21574 </cell>
21575 </row>
21576 <row topline="true">
21577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21578 \begin_inset Text
21579
21580 \begin_layout Standard
21581 long (32 bit) support
21582 \end_layout
21583
21584 \end_inset
21585 </cell>
21586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21587 \begin_inset Text
21588
21589 \begin_layout Standard
21590 x
21591 \end_layout
21592
21593 \end_inset
21594 </cell>
21595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21596 \begin_inset Text
21597
21598 \begin_layout Standard
21599 x
21600 \end_layout
21601
21602 \end_inset
21603 </cell>
21604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21605 \begin_inset Text
21606
21607 \begin_layout Standard
21608 x
21609 \end_layout
21610
21611 \end_inset
21612 </cell>
21613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21614 \begin_inset Text
21615
21616 \begin_layout Standard
21617 x
21618 \end_layout
21619
21620 \end_inset
21621 </cell>
21622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21623 \begin_inset Text
21624
21625 \begin_layout Standard
21626
21627 \family roman
21628 \series medium
21629 \shape up
21630 \size normal
21631 \emph off
21632 \bar no
21633 \noun off
21634 \color none
21635 x
21636 \end_layout
21637
21638 \end_inset
21639 </cell>
21640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21641 \begin_inset Text
21642
21643 \begin_layout Standard
21644 -
21645 \end_layout
21646
21647 \end_inset
21648 </cell>
21649 </row>
21650 <row topline="true">
21651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21652 \begin_inset Text
21653
21654 \begin_layout Standard
21655 byte arguments on stack
21656 \end_layout
21657
21658 \end_inset
21659 </cell>
21660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21661 \begin_inset Text
21662
21663 \begin_layout Standard
21664 b
21665 \end_layout
21666
21667 \end_inset
21668 </cell>
21669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21670 \begin_inset Text
21671
21672 \begin_layout Standard
21673 b
21674 \end_layout
21675
21676 \end_inset
21677 </cell>
21678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21679 \begin_inset Text
21680
21681 \begin_layout Standard
21682 -
21683 \end_layout
21684
21685 \end_inset
21686 </cell>
21687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21688 \begin_inset Text
21689
21690 \begin_layout Standard
21691 -
21692 \end_layout
21693
21694 \end_inset
21695 </cell>
21696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21697 \begin_inset Text
21698
21699 \begin_layout Standard
21700 -
21701 \end_layout
21702
21703 \end_inset
21704 </cell>
21705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21706 \begin_inset Text
21707
21708 \begin_layout Standard
21709 -
21710 \end_layout
21711
21712 \end_inset
21713 </cell>
21714 </row>
21715 <row topline="true">
21716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21717 \begin_inset Text
21718
21719 \begin_layout Standard
21720 float format
21721 \begin_inset LatexCommand index
21722 name "Floating point support"
21723
21724 \end_inset
21725
21726
21727 \end_layout
21728
21729 \end_inset
21730 </cell>
21731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21732 \begin_inset Text
21733
21734 \begin_layout Standard
21735 -
21736 \end_layout
21737
21738 \end_inset
21739 </cell>
21740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21741 \begin_inset Text
21742
21743 \begin_layout Standard
21744 %f
21745 \end_layout
21746
21747 \end_inset
21748 </cell>
21749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21750 \begin_inset Text
21751
21752 \begin_layout Standard
21753 -
21754 \end_layout
21755
21756 \end_inset
21757 </cell>
21758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21759 \begin_inset Text
21760
21761 \begin_layout Standard
21762 -
21763 \end_layout
21764
21765 \end_inset
21766 </cell>
21767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21768 \begin_inset Text
21769
21770 \begin_layout Standard
21771 %f
21772 \begin_inset Foot
21773 status collapsed
21774
21775 \begin_layout Standard
21776 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21777 \end_layout
21778
21779 \end_inset
21780
21781
21782 \end_layout
21783
21784 \end_inset
21785 </cell>
21786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21787 \begin_inset Text
21788
21789 \begin_layout Standard
21790 -
21791 \end_layout
21792
21793 \end_inset
21794 </cell>
21795 </row>
21796 <row topline="true">
21797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21798 \begin_inset Text
21799
21800 \begin_layout Standard
21801 float formats %e %g
21802 \end_layout
21803
21804 \end_inset
21805 </cell>
21806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21807 \begin_inset Text
21808
21809 \begin_layout Standard
21810 -
21811 \end_layout
21812
21813 \end_inset
21814 </cell>
21815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21816 \begin_inset Text
21817
21818 \begin_layout Standard
21819 -
21820 \end_layout
21821
21822 \end_inset
21823 </cell>
21824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21825 \begin_inset Text
21826
21827 \begin_layout Standard
21828 -
21829 \end_layout
21830
21831 \end_inset
21832 </cell>
21833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21834 \begin_inset Text
21835
21836 \begin_layout Standard
21837 -
21838 \end_layout
21839
21840 \end_inset
21841 </cell>
21842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21843 \begin_inset Text
21844
21845 \begin_layout Standard
21846 -
21847 \end_layout
21848
21849 \end_inset
21850 </cell>
21851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21852 \begin_inset Text
21853
21854 \begin_layout Standard
21855 -
21856 \end_layout
21857
21858 \end_inset
21859 </cell>
21860 </row>
21861 <row topline="true" bottomline="true">
21862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21863 \begin_inset Text
21864
21865 \begin_layout Standard
21866 field width
21867 \end_layout
21868
21869 \end_inset
21870 </cell>
21871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21872 \begin_inset Text
21873
21874 \begin_layout Standard
21875 x
21876 \end_layout
21877
21878 \end_inset
21879 </cell>
21880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21881 \begin_inset Text
21882
21883 \begin_layout Standard
21884 x
21885 \end_layout
21886
21887 \end_inset
21888 </cell>
21889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21890 \begin_inset Text
21891
21892 \begin_layout Standard
21893 -
21894 \end_layout
21895
21896 \end_inset
21897 </cell>
21898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21899 \begin_inset Text
21900
21901 \begin_layout Standard
21902 x
21903 \end_layout
21904
21905 \end_inset
21906 </cell>
21907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21908 \begin_inset Text
21909
21910 \begin_layout Standard
21911 x
21912 \end_layout
21913
21914 \end_inset
21915 </cell>
21916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21917 \begin_inset Text
21918
21919 \begin_layout Standard
21920 -
21921 \end_layout
21922
21923 \end_inset
21924 </cell>
21925 </row>
21926 <row bottomline="true">
21927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21928 \begin_inset Text
21929
21930 \begin_layout Standard
21931 string speed
21932 \begin_inset Foot
21933 status collapsed
21934
21935 \begin_layout Standard
21936 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21937 \backslash
21938 r', '
21939 \backslash
21940 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21941 \end_layout
21942
21943 \end_inset
21944
21945 ,
21946 \end_layout
21947
21948 \begin_layout Standard
21949 small / large
21950 \end_layout
21951
21952 \end_inset
21953 </cell>
21954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21955 \begin_inset Text
21956
21957 \begin_layout Standard
21958 1.52 / 2.59 ms
21959 \end_layout
21960
21961 \end_inset
21962 </cell>
21963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21964 \begin_inset Text
21965
21966 \begin_layout Standard
21967 1.53 / 2.62 ms
21968 \end_layout
21969
21970 \end_inset
21971 </cell>
21972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21973 \begin_inset Text
21974
21975 \begin_layout Standard
21976 0.92 / 0.93 ms
21977 \end_layout
21978
21979 \end_inset
21980 </cell>
21981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21982 \begin_inset Text
21983
21984 \begin_layout Standard
21985 0.45 / 0.45 ms
21986 \end_layout
21987
21988 \end_inset
21989 </cell>
21990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21991 \begin_inset Text
21992
21993 \begin_layout Standard
21994 0.46 / 0.46 ms
21995 \end_layout
21996
21997 \end_inset
21998 </cell>
21999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22000 \begin_inset Text
22001
22002 \begin_layout Standard
22003 0.45 / 0.45 ms
22004 \end_layout
22005
22006 \end_inset
22007 </cell>
22008 </row>
22009 <row bottomline="true">
22010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22011 \begin_inset Text
22012
22013 \begin_layout Standard
22014 int speed
22015 \begin_inset Foot
22016 status collapsed
22017
22018 \begin_layout Standard
22019 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22020  putchar()
22021 \end_layout
22022
22023 \end_inset
22024
22025 ,
22026 \end_layout
22027
22028 \begin_layout Standard
22029 small / large
22030 \end_layout
22031
22032 \end_inset
22033 </cell>
22034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22035 \begin_inset Text
22036
22037 \begin_layout Standard
22038 3.01 / 3.61 ms
22039 \end_layout
22040
22041 \end_inset
22042 </cell>
22043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22044 \begin_inset Text
22045
22046 \begin_layout Standard
22047 3.01 / 3.61 ms
22048 \end_layout
22049
22050 \end_inset
22051 </cell>
22052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22053 \begin_inset Text
22054
22055 \begin_layout Standard
22056 3.51 / 18.13 ms
22057 \end_layout
22058
22059 \end_inset
22060 </cell>
22061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22062 \begin_inset Text
22063
22064 \begin_layout Standard
22065 0.22 / 0.22 ms
22066 \end_layout
22067
22068 \end_inset
22069 </cell>
22070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22071 \begin_inset Text
22072
22073 \begin_layout Standard
22074 0.23 / 0.23 ms
22075 \end_layout
22076
22077 \end_inset
22078 </cell>
22079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22080 \begin_inset Text
22081
22082 \begin_layout Standard
22083 0.25 / 0.25 ms
22084 \begin_inset Foot
22085 status collapsed
22086
22087 \begin_layout Standard
22088 printf_tiny integer speed is data dependent, worst case is 0.33 ms
22089 \end_layout
22090
22091 \end_inset
22092
22093
22094 \end_layout
22095
22096 \end_inset
22097 </cell>
22098 </row>
22099 <row bottomline="true">
22100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22101 \begin_inset Text
22102
22103 \begin_layout Standard
22104 long speed
22105 \begin_inset Foot
22106 status collapsed
22107
22108 \begin_layout Standard
22109 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
22110  empty putchar()
22111 \end_layout
22112
22113 \end_inset
22114
22115 ,
22116 \end_layout
22117
22118 \begin_layout Standard
22119 small / large
22120 \end_layout
22121
22122 \end_inset
22123 </cell>
22124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22125 \begin_inset Text
22126
22127 \begin_layout Standard
22128 5.37 / 6.31 ms
22129 \end_layout
22130
22131 \end_inset
22132 </cell>
22133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22134 \begin_inset Text
22135
22136 \begin_layout Standard
22137 5.37 / 6.31 ms
22138 \end_layout
22139
22140 \end_inset
22141 </cell>
22142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22143 \begin_inset Text
22144
22145 \begin_layout Standard
22146 8.71 / 40.65 ms
22147 \end_layout
22148
22149 \end_inset
22150 </cell>
22151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22152 \begin_inset Text
22153
22154 \begin_layout Standard
22155 0.40 / 0.40 ms
22156 \end_layout
22157
22158 \end_inset
22159 </cell>
22160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22161 \begin_inset Text
22162
22163 \begin_layout Standard
22164 0.40 / 0.40 ms
22165 \end_layout
22166
22167 \end_inset
22168 </cell>
22169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22170 \begin_inset Text
22171
22172 \begin_layout Standard
22173 -
22174 \end_layout
22175
22176 \end_inset
22177 </cell>
22178 </row>
22179 <row bottomline="true">
22180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22181 \begin_inset Text
22182
22183 \begin_layout Standard
22184 float speed
22185 \begin_inset Foot
22186 status collapsed
22187
22188 \begin_layout Standard
22189 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22190  empty putchar()
22191 \end_layout
22192
22193 \end_inset
22194
22195 ,
22196 \end_layout
22197
22198 \begin_layout Standard
22199 small / large
22200 \end_layout
22201
22202 \end_inset
22203 </cell>
22204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22205 \begin_inset Text
22206
22207 \begin_layout Standard
22208 -
22209 \end_layout
22210
22211 \end_inset
22212 </cell>
22213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22214 \begin_inset Text
22215
22216 \begin_layout Standard
22217 7.49 / 22.47 ms
22218 \end_layout
22219
22220 \end_inset
22221 </cell>
22222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22223 \begin_inset Text
22224
22225 \begin_layout Standard
22226 -
22227 \end_layout
22228
22229 \end_inset
22230 </cell>
22231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22232 \begin_inset Text
22233
22234 \begin_layout Standard
22235 -
22236 \end_layout
22237
22238 \end_inset
22239 </cell>
22240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22241 \begin_inset Text
22242
22243 \begin_layout Standard
22244 1.04 / 1.04 ms
22245 \end_layout
22246
22247 \end_inset
22248 </cell>
22249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22250 \begin_inset Text
22251
22252 \begin_layout Standard
22253 -
22254 \end_layout
22255
22256 \end_inset
22257 </cell>
22258 </row>
22259 </lyxtabular>
22260
22261 \end_inset
22262
22263
22264 \end_layout
22265
22266 \begin_layout Subsubsection
22267 <malloc.h>
22268 \begin_inset LatexCommand index
22269 name "malloc.h"
22270
22271 \end_inset
22272
22273
22274 \end_layout
22275
22276 \begin_layout Standard
22277 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22278  using dynamic memory allocation
22279 \begin_inset LatexCommand index
22280 name "dynamic memory allocation (malloc)"
22281
22282 \end_inset
22283
22284  and a default heap
22285 \begin_inset LatexCommand index
22286 name "heap (malloc)"
22287
22288 \end_inset
22289
22290  space of 1024 bytes is provided for malloc to allocate memory from.
22291  If you need a different heap size you need to recompile _heap.c with the
22292  required size defined in HEAP_SIZE.
22293  It is recommended to make a copy of this file into your project directory
22294  and compile it there with:
22295 \end_layout
22296
22297 \begin_layout Verse
22298
22299 \family typewriter
22300 sdcc -c _heap.c -D HEAD_SIZE=2048
22301 \end_layout
22302
22303 \begin_layout Standard
22304 And then link it with:
22305 \end_layout
22306
22307 \begin_layout Verse
22308
22309 \family typewriter
22310 sdcc main.rel _heap.rel
22311 \end_layout
22312
22313 \begin_layout Subsection
22314 Math functions (sinf, powf, sqrtf etc.)
22315 \end_layout
22316
22317 \begin_layout Subsubsection
22318 <math.h>
22319 \end_layout
22320
22321 \begin_layout Standard
22322 See definitions in file <math.h>.
22323 \end_layout
22324
22325 \begin_layout Subsection
22326 Other libraries
22327 \end_layout
22328
22329 \begin_layout Standard
22330 Libraries
22331 \begin_inset LatexCommand index
22332 name "Libraries"
22333
22334 \end_inset
22335
22336  included in SDCC should have a license at least as liberal as the GNU Lesser
22337  General Public License
22338 \begin_inset LatexCommand index
22339 name "GNU Lesser General Public License, LGPL"
22340
22341 \end_inset
22342
22343  
22344 \emph on
22345 LGPL
22346 \emph default
22347 .
22348 \end_layout
22349
22350 \begin_layout Standard
22351 \begin_inset Note Note
22352 status collapsed
22353
22354 \begin_layout Standard
22355 license statements for the libraries are missing.
22356  sdcc/device/lib/ser_ir.c
22357 \end_layout
22358
22359 \begin_layout Standard
22360 or _decdptr f.e.
22361  come with a GPL (as opposed to LGPL) License - this will not be liberal
22362  enough for many embedded programmers.
22363 \end_layout
22364
22365 \end_inset
22366
22367
22368 \end_layout
22369
22370 \begin_layout Standard
22371 If you have ported some library or want to share experience about some code
22372  which f.e.
22373  falls into any of these categories Busses (I
22374 \begin_inset Formula $^{\textrm{2}}$
22375 \end_inset
22376
22377 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22378  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22379  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
22380 \begin_inset LatexCommand url
22381 target "http://sourceforge.net/mail/?group_id=599"
22382
22383 \end_inset
22384
22385 \InsetSpace ~
22386 would certainly like to hear about it.
22387 \end_layout
22388
22389 \begin_layout Standard
22390 Programmers coding for embedded systems are not especially famous for being
22391  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22392 e these references are very valuable.
22393  Let's help to create a climate where information is shared.
22394 \begin_inset VSpace bigskip
22395 \end_inset
22396
22397
22398 \end_layout
22399
22400 \begin_layout Section
22401 Memory Models
22402 \end_layout
22403
22404 \begin_layout Subsection
22405 MCS51 Memory Models
22406 \begin_inset LatexCommand index
22407 name "Memory model"
22408
22409 \end_inset
22410
22411
22412 \begin_inset LatexCommand index
22413 name "MCS51 memory model"
22414
22415 \end_inset
22416
22417
22418 \end_layout
22419
22420 \begin_layout Subsubsection
22421 Small, Medium and Large
22422 \end_layout
22423
22424 \begin_layout Standard
22425 SDCC allows three memory models for MCS51 code, 
22426 \shape slanted
22427 small, medium
22428 \shape default
22429  and 
22430 \shape slanted
22431 large
22432 \shape default
22433 .
22434  Modules compiled with different memory models should 
22435 \emph on
22436 never
22437 \emph default
22438  be combined together or the results would be unpredictable.
22439  The library routines supplied with the compiler are compiled as small,
22440  medium and large.
22441  The compiled library modules are contained in separate directories as small,
22442  medium and large so that you can link to the appropriate set.
22443 \end_layout
22444
22445 \begin_layout Standard
22446 When the medium or large model is used all variables declared without a
22447  storage class will be allocated into the external ram, this includes all
22448  parameters and local variables (for non-reentrant
22449 \begin_inset LatexCommand index
22450 name "reentrant"
22451
22452 \end_inset
22453
22454  functions).
22455  When the small model is used variables without storage class are allocated
22456  in the internal ram.
22457 \end_layout
22458
22459 \begin_layout Standard
22460 Judicious usage of the processor specific storage classes
22461 \begin_inset LatexCommand index
22462 name "Storage class"
22463
22464 \end_inset
22465
22466  and the 'reentrant' function type will yield much more efficient code,
22467  than using the large model.
22468  Several optimizations are disabled when the program is compiled using the
22469  large model, it is therefore recommended that the small model be used unless
22470  absolutely required.
22471 \end_layout
22472
22473 \begin_layout Subsubsection
22474 External Stack
22475 \begin_inset LatexCommand label
22476 name "sub:External-Stack"
22477
22478 \end_inset
22479
22480
22481 \begin_inset LatexCommand index
22482 name "stack"
22483
22484 \end_inset
22485
22486
22487 \begin_inset LatexCommand index
22488 name "External stack (mcs51)"
22489
22490 \end_inset
22491
22492
22493 \end_layout
22494
22495 \begin_layout Standard
22496 The external stack (-
22497 \begin_inset ERT
22498 status collapsed
22499
22500 \begin_layout Standard
22501
22502
22503 \backslash
22504 /
22505 \end_layout
22506
22507 \end_inset
22508
22509 -xstack option
22510 \begin_inset LatexCommand index
22511 name "-\\/-xstack"
22512
22513 \end_inset
22514
22515 ) is located in pdata
22516 \begin_inset LatexCommand index
22517 name "pdata (mcs51, ds390 storage class)"
22518
22519 \end_inset
22520
22521  memory (usually at the start of the external ram segment) and uses all
22522  unused space in pdata (max.
22523  256 bytes).
22524  When -
22525 \begin_inset ERT
22526 status collapsed
22527
22528 \begin_layout Standard
22529
22530
22531 \backslash
22532 /
22533 \end_layout
22534
22535 \end_inset
22536
22537 -xstack option is used to compile the program, the parameters and local
22538  variables
22539 \begin_inset LatexCommand index
22540 name "local variables"
22541
22542 \end_inset
22543
22544  of all reentrant functions are allocated in this area.
22545  This option is provided for programs with large stack space requirements.
22546  When used with the -
22547 \begin_inset ERT
22548 status collapsed
22549
22550 \begin_layout Standard
22551
22552
22553 \backslash
22554 /
22555 \end_layout
22556
22557 \end_inset
22558
22559 -stack-auto
22560 \begin_inset LatexCommand index
22561 name "-\\/-stack-auto"
22562
22563 \end_inset
22564
22565  option, all parameters and local variables are allocated on the external
22566  stack (note: support libraries will need to be recompiled with the same
22567  options.
22568  There is a predefined target in the library makefile).
22569 \end_layout
22570
22571 \begin_layout Standard
22572 The compiler outputs the higher order address byte of the external ram segment
22573  into port P2
22574 \begin_inset LatexCommand index
22575 name "P2 (mcs51 sfr)"
22576
22577 \end_inset
22578
22579  (see also section 
22580 \begin_inset LatexCommand ref
22581 reference "sub:MCS51-variants"
22582
22583 \end_inset
22584
22585 ), therefore when using the External Stack option, this port 
22586 \emph on
22587 may not
22588 \emph default
22589  be used by the application program.
22590 \end_layout
22591
22592 \begin_layout Subsection
22593 DS390 Memory Model
22594 \begin_inset LatexCommand index
22595 name "Memory model"
22596
22597 \end_inset
22598
22599
22600 \begin_inset LatexCommand index
22601 name "DS390 memory model"
22602
22603 \end_inset
22604
22605
22606 \end_layout
22607
22608 \begin_layout Standard
22609 The only model supported is Flat 24
22610 \begin_inset LatexCommand index
22611 name "Flat 24 (DS390 memory model)"
22612
22613 \end_inset
22614
22615 .
22616  This generates code for the 24 bit contiguous addressing mode of the Dallas
22617  DS80C390 part.
22618  In this mode, up to four meg of external RAM or code space can be directly
22619  addressed.
22620  See the data sheets at www.dalsemi.com for further information on this part.
22621 \newline
22622
22623 \newline
22624 Note
22625  that the compiler does not generate any code to place the processor into
22626  24 bitmode (although 
22627 \emph on
22628 tinibios
22629 \emph default
22630  in the ds390 libraries will do that for you).
22631  If you don't use 
22632 \emph on
22633 tinibios
22634 \emph default
22635
22636 \begin_inset LatexCommand index
22637 name "Tinibios (DS390)"
22638
22639 \end_inset
22640
22641 , the boot loader or similar code must ensure that the processor is in 24
22642  bit contiguous addressing mode before calling the SDCC startup code.
22643 \newline
22644
22645 \newline
22646 Like
22647  the 
22648 \emph on
22649 -
22650 \begin_inset ERT
22651 status collapsed
22652
22653 \begin_layout Standard
22654
22655
22656 \backslash
22657 /
22658 \end_layout
22659
22660 \end_inset
22661
22662 -model-large
22663 \emph default
22664  option, variables will by default be placed into the XDATA segment.
22665  
22666 \newline
22667
22668 \newline
22669 Segments may be placed anywhere in the 4 meg address space using the usual
22670  -
22671 \begin_inset ERT
22672 status collapsed
22673
22674 \begin_layout Standard
22675
22676
22677 \backslash
22678 /
22679 \end_layout
22680
22681 \end_inset
22682
22683 -*-loc options.
22684  Note that if any segments are located above 64K, the -r flag must be passed
22685  to the linker to generate the proper segment relocations, and the Intel
22686  HEX output format must be used.
22687  The -r flag can be passed to the linker by using the option 
22688 \emph on
22689 -Wl-r
22690 \emph default
22691  on the SDCC command line.
22692  However, currently the linker can not handle code segments > 64k.
22693 \end_layout
22694
22695 \begin_layout Section
22696 Pragmas
22697 \begin_inset LatexCommand label
22698 name "sec:Pragmas"
22699
22700 \end_inset
22701
22702
22703 \begin_inset LatexCommand index
22704 name "Pragmas"
22705
22706 \end_inset
22707
22708
22709 \end_layout
22710
22711 \begin_layout Standard
22712 Pragmas are used to turn on and/or off certain compiler options.
22713  Some of them are closely related to corresponding command-line options
22714  (see section 
22715 \begin_inset LatexCommand vref
22716 reference "sec:Command-Line-Options"
22717
22718 \end_inset
22719
22720 ).
22721 \newline
22722 Pragmas should be placed before and/or after a function, placing pragmas
22723  inside a function body could have unpredictable results.
22724 \newline
22725
22726 \newline
22727 SDCC supports the
22728  following #pragma directives:
22729 \end_layout
22730
22731 \begin_layout Itemize
22732
22733 \series bold
22734 save
22735 \series default
22736
22737 \begin_inset LatexCommand index
22738 name "\\#pragma save"
22739
22740 \end_inset
22741
22742  - this will save most current options to the save/restore stack.
22743  See #pragma\InsetSpace ~
22744 restore.
22745 \end_layout
22746
22747 \begin_layout Itemize
22748
22749 \series bold
22750 restore
22751 \series default
22752
22753 \begin_inset LatexCommand index
22754 name "\\#pragma restore"
22755
22756 \end_inset
22757
22758  - will restore saved options from the last save.
22759  saves & restores can be nested.
22760  SDCC uses a save/restore stack: save pushes current options to the stack,
22761  restore pulls current options from the stack.
22762  See #pragma\InsetSpace ~
22763 save.
22764 \newline
22765
22766 \end_layout
22767
22768 \begin_layout Itemize
22769
22770 \series bold
22771 callee_saves
22772 \series default
22773
22774 \begin_inset LatexCommand index
22775 name "\\#pragma callee\\_saves"
22776
22777 \end_inset
22778
22779
22780 \begin_inset LatexCommand index
22781 name "function prologue"
22782
22783 \end_inset
22784
22785  function1[,function2[,function3...]] 
22786 \begin_inset LatexCommand label
22787 name "ite:callee_saves-function1[,function2[,function3...]]--"
22788
22789 \end_inset
22790
22791 - The compiler by default uses a caller saves convention for register saving
22792  across function calls, however this can cause unnecessary register pushing
22793  and popping
22794 \begin_inset LatexCommand index
22795 name "push/pop"
22796
22797 \end_inset
22798
22799  when calling small functions from larger functions.
22800  This option can be used to switch off the register saving convention for
22801  the function names specified.
22802  The compiler will not save registers when calling these functions, extra
22803  code need to be manually inserted at the entry and exit for these functions
22804  to save and restore the registers used by these functions, this can SUBSTANTIAL
22805 LY reduce code and improve run time performance of the generated code.
22806  In the future the compiler (with inter procedural analysis) may be able
22807  to determine the appropriate scheme to use for each function call.
22808  If -
22809 \begin_inset ERT
22810 status collapsed
22811
22812 \begin_layout Standard
22813
22814
22815 \backslash
22816 /
22817 \end_layout
22818
22819 \end_inset
22820
22821 -callee-saves command line option is used (see page 
22822 \begin_inset LatexCommand vpageref
22823 reference "lyx:--callee-saves-function1[,function2][,function3]..."
22824
22825 \end_inset
22826
22827 ), the function names specified in #pragma\InsetSpace ~
22828 callee_saves
22829 \begin_inset LatexCommand index
22830 name "\\#pragma callee\\_saves"
22831
22832 \end_inset
22833
22834  is appended to the list of functions specified in the command line.
22835 \end_layout
22836
22837 \begin_layout Itemize
22838
22839 \series bold
22840 exclude
22841 \series default
22842
22843 \begin_inset LatexCommand index
22844 name "\\#pragma exclude"
22845
22846 \end_inset
22847
22848  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22849  of pairs of push/pop
22850 \begin_inset LatexCommand index
22851 name "push/pop"
22852
22853 \end_inset
22854
22855  instructions in 
22856 \emph on
22857 I
22858 \emph default
22859 nterrupt
22860 \begin_inset LatexCommand index
22861 name "interrupt"
22862
22863 \end_inset
22864
22865  
22866 \emph on
22867 S
22868 \emph default
22869 ervice 
22870 \emph on
22871 R
22872 \emph default
22873 outines.
22874  The directive should be placed immediately before the ISR function definition
22875  and it affects ALL ISR functions following it.
22876  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
22877 exclude\InsetSpace ~
22878 none
22879 \begin_inset LatexCommand index
22880 name "\\#pragma exclude"
22881
22882 \end_inset
22883
22884 .
22885  See also the related keyword _naked
22886 \begin_inset LatexCommand index
22887 name "\\_naked"
22888
22889 \end_inset
22890
22891
22892 \begin_inset LatexCommand index
22893 name "\\_\\_naked"
22894
22895 \end_inset
22896
22897 .
22898 \end_layout
22899
22900 \begin_layout Itemize
22901
22902 \series bold
22903 less_pedantic
22904 \series default
22905
22906 \begin_inset LatexCommand index
22907 name "pedantic"
22908
22909 \end_inset
22910
22911
22912 \begin_inset LatexCommand index
22913 name "\\#pragma less\\_pedantic"
22914
22915 \end_inset
22916
22917  
22918 \begin_inset LatexCommand label
22919 name "ite:less_pedantic"
22920
22921 \end_inset
22922
22923 - the compiler will not warn you anymore for obvious mistakes, you're on
22924  your own now ;-( .
22925  See also the command line option -
22926 \begin_inset ERT
22927 status collapsed
22928
22929 \begin_layout Standard
22930
22931
22932 \backslash
22933 /
22934 \end_layout
22935
22936 \end_inset
22937
22938 -less-pedantic 
22939 \begin_inset LatexCommand vpageref
22940 reference "lyx:--less-pedantic"
22941
22942 \end_inset
22943
22944 .
22945  
22946 \newline
22947 More specifically, the following warnings will be disabled: 
22948 \shape italic
22949 comparison is always [true/false] due to limited range of data type
22950 \shape default
22951  (94); 
22952 \shape italic
22953 overflow in implicit constant conversion
22954 \shape default
22955  (158); [the (in)famous] 
22956 \shape italic
22957 conditional flow changed by optimizer: so said EVELYN the modified DOG
22958 \shape default
22959  (110); 
22960 \shape italic
22961 function '[function name]' must return value
22962 \shape default
22963  (59).
22964  
22965 \newline
22966 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22967  level) are disabled, too, namely: 
22968 \shape italic
22969 constant value '[
22970 \begin_inset Note Note
22971 status collapsed
22972
22973 \begin_layout Standard
22974 dunno what comes here - this warning appears to be unused altogether
22975 \end_layout
22976
22977 \end_inset
22978
22979 ]', out of range
22980 \shape default
22981  (81); 
22982 \shape italic
22983 [left/right] shifting more than size of object changed to zero
22984 \shape default
22985  (116); 
22986 \shape italic
22987 unreachable code
22988 \shape default
22989  (126); 
22990 \shape italic
22991 integer overflow in expression
22992 \shape default
22993  (165); 
22994 \shape italic
22995 unmatched #pragma save and #pragma restore
22996 \shape default
22997  (170); 
22998 \shape italic
22999 comparison of 'signed char' with 'unsigned char' requires promotion to int
23000 \shape default
23001  (185); 
23002 \shape italic
23003 ISO C90 does not support flexible array members
23004 \shape default
23005  (187); 
23006 \shape italic
23007 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23008 nam
23009 e]':\InsetSpace ~
23010 [
23011 \begin_inset Note Note
23012 status collapsed
23013
23014 \begin_layout Standard
23015 appears to be always blank - what was supposed to be here?
23016 \end_layout
23017
23018 \end_inset
23019
23020 ]
23021 \shape default
23022  (114); 
23023 \shape italic
23024 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23025  complexity [number]
23026 \shape default
23027  (121).
23028 \end_layout
23029
23030 \begin_layout Itemize
23031
23032 \series bold
23033 disable_warning
23034 \series default
23035  <nnnn>
23036 \begin_inset LatexCommand index
23037 name "\\#pragma disable\\_warning"
23038
23039 \end_inset
23040
23041  - the compiler will not warn you anymore about warning number <nnnn>.
23042 \end_layout
23043
23044 \begin_layout Itemize
23045
23046 \series bold
23047 nogcse
23048 \series default
23049
23050 \begin_inset LatexCommand index
23051 name "\\#pragma nogcse"
23052
23053 \end_inset
23054
23055  - will stop global common subexpression elimination.
23056 \end_layout
23057
23058 \begin_layout Itemize
23059
23060 \series bold
23061 noinduction
23062 \series default
23063
23064 \begin_inset LatexCommand index
23065 name "\\#pragma noinduction"
23066
23067 \end_inset
23068
23069  - will stop loop induction optimizations.
23070 \end_layout
23071
23072 \begin_layout Itemize
23073
23074 \series bold
23075 noinvariant
23076 \series default
23077
23078 \begin_inset LatexCommand index
23079 name "\\#pragma noinvariant"
23080
23081 \end_inset
23082
23083  - will not do loop invariant optimizations.
23084  For more details see Loop Invariants in section
23085 \begin_inset LatexCommand ref
23086 reference "sub:Loop-Optimizations"
23087
23088 \end_inset
23089
23090 .
23091 \end_layout
23092
23093 \begin_layout Itemize
23094
23095 \series bold
23096 noiv
23097 \series default
23098
23099 \begin_inset LatexCommand index
23100 name "\\#pragma noiv"
23101
23102 \end_inset
23103
23104  - Do not generate interrupt
23105 \begin_inset LatexCommand index
23106 name "interrupt"
23107
23108 \end_inset
23109
23110  vector table
23111 \begin_inset LatexCommand index
23112 name "interrupt vector table"
23113
23114 \end_inset
23115
23116  entries for all ISR functions defined after the pragma.
23117  This is useful in cases where the interrupt vector table must be defined
23118  manually, or when there is a secondary, manually defined interrupt vector
23119  table (e.g.
23120  for the autovector feature of the Cypress EZ-USB FX2).
23121  More elegantly this can be achieved by omitting the optional interrupt
23122  number after the interrupt keyword, see section 
23123 \begin_inset LatexCommand ref
23124 reference "sub:Interrupt-Service-Routines"
23125
23126 \end_inset
23127
23128 \InsetSpace ~
23129 about interrupts.
23130 \end_layout
23131
23132 \begin_layout Itemize
23133
23134 \series bold
23135 nojtbound
23136 \series default
23137
23138 \begin_inset LatexCommand index
23139 name "\\#pragma nojtbound"
23140
23141 \end_inset
23142
23143  - will not generate code for boundary value checking, when switch statements
23144  are turned into jump-tables (dangerous).
23145  For more details see section 
23146 \begin_inset LatexCommand ref
23147 reference "sub:'switch'-Statements"
23148
23149 \end_inset
23150
23151 .
23152 \end_layout
23153
23154 \begin_layout Itemize
23155
23156 \series bold
23157 noloopreverse
23158 \series default
23159
23160 \begin_inset LatexCommand index
23161 name "\\#pragma noloopreverse"
23162
23163 \end_inset
23164
23165  - Will not do loop reversal optimization
23166 \end_layout
23167
23168 \begin_layout Itemize
23169
23170 \series bold
23171 nooverlay
23172 \series default
23173
23174 \begin_inset LatexCommand index
23175 name "\\#pragma nooverlay"
23176
23177 \end_inset
23178
23179  - the compiler will not overlay the parameters and local variables of a
23180  function.
23181 \end_layout
23182
23183 \begin_layout Itemize
23184
23185 \series bold
23186 stackauto
23187 \series default
23188
23189 \begin_inset LatexCommand index
23190 name "\\#pragma stackauto"
23191
23192 \end_inset
23193
23194 - See option -
23195 \begin_inset ERT
23196 status collapsed
23197
23198 \begin_layout Standard
23199
23200
23201 \backslash
23202 /
23203 \end_layout
23204
23205 \end_inset
23206
23207 -stack-auto
23208 \begin_inset LatexCommand index
23209 name "-\\/-stack-auto"
23210
23211 \end_inset
23212
23213  and section 
23214 \begin_inset LatexCommand ref
23215 reference "sec:Parameters-and-Local-Variables"
23216
23217 \end_inset
23218
23219  Parameters and Local Variables.
23220 \end_layout
23221
23222 \begin_layout Itemize
23223
23224 \series bold
23225 opt_code_speed
23226 \series default
23227  
23228 \begin_inset LatexCommand index
23229 name "\\#pragma opt\\_code\\_speed"
23230
23231 \end_inset
23232
23233 - The compiler will optimize code generation towards fast code, possibly
23234  at the expense of code size.
23235  Currently this has little effect.
23236 \end_layout
23237
23238 \begin_layout Itemize
23239
23240 \series bold
23241 opt_code_size
23242 \series default
23243  
23244 \begin_inset LatexCommand index
23245 name "\\#pragma opt\\_code\\_size"
23246
23247 \end_inset
23248
23249 - The compiler will optimize code generation towards compact code, possibly
23250  at the expense of code speed.
23251  Currently this has little effect.
23252 \end_layout
23253
23254 \begin_layout Itemize
23255
23256 \series bold
23257 opt_code_balanced
23258 \series default
23259  
23260 \begin_inset LatexCommand index
23261 name "\\#pragma opt\\_code\\_balanced"
23262
23263 \end_inset
23264
23265 - The compiler will attempt to generate code that is both compact and fast,
23266  as long as meeting one goal is not a detriment to the other (this is the
23267  default).
23268  
23269 \end_layout
23270
23271 \begin_layout Itemize
23272
23273 \series bold
23274 std_sdcc89
23275 \series default
23276  
23277 \begin_inset LatexCommand index
23278 name "\\#pragma std\\_sdcc89"
23279
23280 \end_inset
23281
23282 - Generally follow the C89 standard, but allow SDCC features that conflict
23283  with the standard (default).
23284 \end_layout
23285
23286 \begin_layout Itemize
23287
23288 \series bold
23289 std_c89
23290 \series default
23291  
23292 \begin_inset LatexCommand index
23293 name "\\#pragma std\\_c89"
23294
23295 \end_inset
23296
23297 - Follow the C89 standard and disable SDCC features that conflict with the
23298  standard.
23299 \end_layout
23300
23301 \begin_layout Itemize
23302
23303 \series bold
23304 std_sdcc99
23305 \series default
23306  
23307 \begin_inset LatexCommand index
23308 name "\\#pragma std\\_sdcc99"
23309
23310 \end_inset
23311
23312 - Generally follow the C99 standard, but allow SDCC features that conflict
23313  with the standard (incomplete support).
23314 \end_layout
23315
23316 \begin_layout Itemize
23317
23318 \series bold
23319 std_c99
23320 \series default
23321  
23322 \begin_inset LatexCommand index
23323 name "\\#pragma std\\_c99"
23324
23325 \end_inset
23326
23327 - Follow the C99 standard and disable SDCC features that conflict with the
23328  standard (incomplete support).
23329 \end_layout
23330
23331 \begin_layout Itemize
23332
23333 \series bold
23334 codeseg
23335 \series default
23336  <name>
23337 \begin_inset LatexCommand index
23338 name "\\#pragma codeseg"
23339
23340 \end_inset
23341
23342 - Use this name (max.
23343  8 characters) for the code segment.
23344  See option -
23345 \begin_inset ERT
23346 status collapsed
23347
23348 \begin_layout Standard
23349
23350
23351 \backslash
23352 /
23353 \end_layout
23354
23355 \end_inset
23356
23357 -codeseg.
23358 \end_layout
23359
23360 \begin_layout Itemize
23361
23362 \series bold
23363 constseg
23364 \series default
23365  <name>
23366 \begin_inset LatexCommand index
23367 name "\\#pragma constseg"
23368
23369 \end_inset
23370
23371 - Use this name (max.
23372  8 characters) for the const segment.
23373  See option -
23374 \begin_inset ERT
23375 status collapsed
23376
23377 \begin_layout Standard
23378
23379
23380 \backslash
23381 /
23382 \end_layout
23383
23384 \end_inset
23385
23386 -constseg.
23387 \end_layout
23388
23389 \begin_layout Standard
23390 The preprocessor SDCPP
23391 \begin_inset LatexCommand index
23392 name "sdcpp (preprocessor)"
23393
23394 \end_inset
23395
23396  supports the following #pragma directives:
23397 \end_layout
23398
23399 \begin_layout Itemize
23400
23401 \series bold
23402 pedantic_parse_number
23403 \series default
23404
23405 \begin_inset LatexCommand index
23406 name "pedantic"
23407
23408 \end_inset
23409
23410
23411 \begin_inset LatexCommand index
23412 name "\\#pragma pedantic\\_parse\\_number"
23413
23414 \end_inset
23415
23416  (+ | -) 
23417 \begin_inset LatexCommand label
23418 name "ite:pedantic_parse_number"
23419
23420 \end_inset
23421
23422 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23423  properly and the macro LO_B(3) gets expanded.
23424  Default is off.
23425  See also the -
23426 \begin_inset ERT
23427 status collapsed
23428
23429 \begin_layout Standard
23430
23431
23432 \backslash
23433 /
23434 \end_layout
23435
23436 \end_inset
23437
23438 -pedantic-parse-number command line option 
23439 \begin_inset LatexCommand vpageref
23440 reference "lyx:-pedantic-parse-number"
23441
23442 \end_inset
23443
23444 .
23445  
23446 \newline
23447 Below is an example on how to use this pragma.
23448  
23449 \emph on
23450 Note: this functionality is not in conformance with standard!
23451 \end_layout
23452
23453 \begin_layout Verse
23454
23455 \family typewriter
23456 #pragma pedantic_parse_number +
23457 \begin_inset LatexCommand index
23458 name "\\#pragma pedantic\\_parse\\_number"
23459
23460 \end_inset
23461
23462
23463 \newline
23464
23465 \newline
23466 #define LO_B(x) ((x) & 0xff)
23467 \newline
23468
23469 \newline
23470 unsigned char foo(void)
23471 \newline
23472 {
23473 \newline
23474 \InsetSpace ~
23475 \InsetSpace ~
23476 \InsetSpace ~
23477 unsigned char c=0xfe-LO_B(3)
23478 ;
23479 \newline
23480
23481 \newline
23482 \InsetSpace ~
23483 \InsetSpace ~
23484 \InsetSpace ~
23485 return c;
23486 \newline
23487 }
23488 \newline
23489
23490 \end_layout
23491
23492 \begin_layout Itemize
23493
23494 \series bold
23495 preproc_asm
23496 \series default
23497
23498 \begin_inset LatexCommand index
23499 name "\\#pragma preproc\\_asm"
23500
23501 \end_inset
23502
23503  (+ | -) - switch _asm _endasm block preprocessing on / off.
23504  Default is on.
23505  You use this pragma to define multilines of assembly code.
23506  This will prevent the preprocessor from changing the formatting required
23507  by assembly code.
23508  Below is an example on how to use this pragma.
23509 \end_layout
23510
23511 \begin_layout Verse
23512
23513 \family typewriter
23514 #pragma preproc_asm -
23515 \begin_inset LatexCommand index
23516 name "\\#pragma preproc\\_asm"
23517
23518 \end_inset
23519
23520
23521 \newline
23522 #define MYDELAY _asm
23523 \newline
23524 \InsetSpace ~
23525 \InsetSpace ~
23526 \InsetSpace ~
23527 nop ;my assembly comment...
23528 \newline
23529 \InsetSpace ~
23530 \InsetSpace ~
23531 \InsetSpace ~
23532 nop
23533 \newline
23534 \InsetSpace ~
23535 \InsetSpace ~
23536 \InsetSpace ~
23537 nop
23538 \newline
23539 _endasm
23540 \newline
23541 #pragma preproc_asm
23542  +
23543 \newline
23544
23545 \newline
23546 void foo (void) 
23547 \newline
23548
23549 \newline
23550 \InsetSpace ~
23551 \InsetSpace ~
23552 \InsetSpace ~
23553  ...
23554  
23555 \newline
23556 \InsetSpace ~
23557 \InsetSpace ~
23558 \InsetSpace ~
23559  MYDELAY;
23560 \newline
23561 \InsetSpace ~
23562 \InsetSpace ~
23563 \InsetSpace ~
23564  ...
23565  
23566 \newline
23567
23568 \newline
23569
23570 \end_layout
23571
23572 \begin_layout Itemize
23573
23574 \series bold
23575 sdcc_hash
23576 \series default
23577
23578 \begin_inset LatexCommand index
23579 name "\\#pragma sdcc\\_hash"
23580
23581 \end_inset
23582
23583  (+ | -) - Allow "naked" hash in macro definition, for example:
23584 \newline
23585
23586 \family typewriter
23587 #define DIR_LO(x) #(x & 0xff)
23588 \family default
23589
23590 \newline
23591 Default is off.
23592  Below is an example on how to use this pragma.
23593 \end_layout
23594
23595 \begin_layout Verse
23596
23597 \family typewriter
23598 #pragma preproc_asm +
23599 \newline
23600 #pragma sdcc_hash +
23601 \begin_inset LatexCommand index
23602 name "\\#pragma sdcc\\_hash"
23603
23604 \end_inset
23605
23606
23607 \newline
23608
23609 \newline
23610 #define ROMCALL(x) 
23611 \backslash
23612
23613 \newline
23614 \InsetSpace ~
23615 \InsetSpace ~
23616 \InsetSpace ~
23617 mov R6_B3, #(x & 0xff) 
23618 \backslash
23619
23620 \newline
23621 \InsetSpace ~
23622 \InsetSpace ~
23623 \InsetSpace ~
23624 mov R7_B3, #((x >> 8) & 0xff) 
23625 \backslash
23626
23627 \newline
23628 \InsetSpace ~
23629 \InsetSpace ~
23630 \InsetSpace ~
23631 lcall __romcall
23632 \newline
23633
23634 \newline
23635 ...
23636 \newline
23637 _asm
23638 \newline
23639 ROMCALL(72)
23640 \newline
23641 _endasm;
23642 \newline
23643 ...
23644 \newline
23645
23646 \end_layout
23647
23648 \begin_layout Standard
23649 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23650 ons which might cause the compiler to generate extra stack and/or data space
23651  to store compiler generated temporary variables.
23652  This usually happens in large functions.
23653  Pragma directives should be used as shown in the following example, they
23654  are used to control options and optimizations for a given function.
23655  
23656 \end_layout
23657
23658 \begin_layout Verse
23659
23660 \family typewriter
23661 #pragma save
23662 \begin_inset LatexCommand index
23663 name "\\#pragma save"
23664
23665 \end_inset
23666
23667  \InsetSpace ~
23668 \InsetSpace ~
23669 \InsetSpace ~
23670 \InsetSpace ~
23671 \InsetSpace ~
23672 \InsetSpace ~
23673 \InsetSpace ~
23674 /* save the current settings */ 
23675 \newline
23676 #pragma nogcse
23677 \begin_inset LatexCommand index
23678 name "\\#pragma nogcse"
23679
23680 \end_inset
23681
23682  \InsetSpace ~
23683 \InsetSpace ~
23684 \InsetSpace ~
23685 \InsetSpace ~
23686 \InsetSpace ~
23687 /* turnoff global subexpression elimination */ 
23688 \newline
23689 #pragma noinduction
23690 \begin_inset LatexCommand index
23691 name "\\#pragma noinduction"
23692
23693 \end_inset
23694
23695  /* turn off induction optimizations */ 
23696 \newline
23697 int foo () 
23698 \newline
23699
23700 \newline
23701 \InsetSpace ~
23702  \InsetSpace ~
23703  ...
23704  
23705 \newline
23706 \InsetSpace ~
23707  \InsetSpace ~
23708  /* large code */ 
23709 \newline
23710 \InsetSpace ~
23711  \InsetSpace ~
23712  ...
23713  
23714 \newline
23715
23716 \newline
23717 #pragma restore
23718 \begin_inset LatexCommand index
23719 name "\\#pragma restore"
23720
23721 \end_inset
23722
23723  /* turn the optimizations back on */
23724 \end_layout
23725
23726 \begin_layout Standard
23727 The compiler will generate a warning message when extra space is allocated.
23728  It is strongly recommended that the save and restore pragmas be used when
23729  changing options for a function.
23730 \newline
23731
23732 \newline
23733
23734 \newline
23735
23736 \end_layout
23737
23738 \begin_layout Section
23739 Defines Created by the Compiler
23740 \end_layout
23741
23742 \begin_layout Standard
23743 The compiler creates the following #defines
23744 \begin_inset LatexCommand index
23745 name "\\#defines"
23746
23747 \end_inset
23748
23749
23750 \begin_inset LatexCommand index
23751 name "Defines created by the compiler"
23752
23753 \end_inset
23754
23755 :
23756 \newline
23757
23758 \end_layout
23759
23760 \begin_layout Standard
23761 \begin_inset Tabular
23762 <lyxtabular version="3" rows="15" columns="2">
23763 <features>
23764 <column alignment="left" valignment="top" leftline="true" width="3in">
23765 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23766 <row topline="true" bottomline="true">
23767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23768 \begin_inset Text
23769
23770 \begin_layout Standard
23771
23772 \series bold
23773 #define
23774 \end_layout
23775
23776 \end_inset
23777 </cell>
23778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23779 \begin_inset Text
23780
23781 \begin_layout Standard
23782
23783 \series bold
23784 Description
23785 \end_layout
23786
23787 \end_inset
23788 </cell>
23789 </row>
23790 <row topline="true">
23791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23792 \begin_inset Text
23793
23794 \begin_layout Standard
23795 SDCC
23796 \begin_inset LatexCommand index
23797 name "SDCC"
23798
23799 \end_inset
23800
23801  
23802 \end_layout
23803
23804 \end_inset
23805 </cell>
23806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23807 \begin_inset Text
23808
23809 \begin_layout Standard
23810 Always defined.
23811  Since version 2.5.6 the version number as an int (ex.
23812  256)
23813 \end_layout
23814
23815 \end_inset
23816 </cell>
23817 </row>
23818 <row topline="true">
23819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23820 \begin_inset Text
23821
23822 \begin_layout Standard
23823 SDCC_mcs51
23824 \begin_inset LatexCommand index
23825 name "SDCC\\_mcs51"
23826
23827 \end_inset
23828
23829  or SDCC_ds390
23830 \begin_inset LatexCommand index
23831 name "SDCC\\_ds390"
23832
23833 \end_inset
23834
23835  or SDCC_z80
23836 \begin_inset LatexCommand index
23837 name "SDCC\\_z80"
23838
23839 \end_inset
23840
23841 , etc.
23842 \end_layout
23843
23844 \end_inset
23845 </cell>
23846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23847 \begin_inset Text
23848
23849 \begin_layout Standard
23850 depending on the model used (e.g.: -mds390)
23851 \end_layout
23852
23853 \end_inset
23854 </cell>
23855 </row>
23856 <row topline="true">
23857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23858 \begin_inset Text
23859
23860 \begin_layout Standard
23861 __mcs51
23862 \begin_inset LatexCommand index
23863 name "\\_\\_mcs51"
23864
23865 \end_inset
23866
23867 , __ds390
23868 \begin_inset LatexCommand index
23869 name "\\_\\_ds390"
23870
23871 \end_inset
23872
23873 , __hc08
23874 \begin_inset LatexCommand index
23875 name "\\_\\_hc08"
23876
23877 \end_inset
23878
23879 , __z80
23880 \begin_inset LatexCommand index
23881 name "\\_\\_z80"
23882
23883 \end_inset
23884
23885 , etc
23886 \end_layout
23887
23888 \end_inset
23889 </cell>
23890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23891 \begin_inset Text
23892
23893 \begin_layout Standard
23894 depending on the model used (e.g.
23895  -mz80)
23896 \end_layout
23897
23898 \end_inset
23899 </cell>
23900 </row>
23901 <row topline="true">
23902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23903 \begin_inset Text
23904
23905 \begin_layout Standard
23906 SDCC_STACK_AUTO
23907 \begin_inset LatexCommand index
23908 name "SDCC\\_STACK\\_AUTO"
23909
23910 \end_inset
23911
23912
23913 \end_layout
23914
23915 \end_inset
23916 </cell>
23917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23918 \begin_inset Text
23919
23920 \begin_layout Standard
23921 when 
23922 \emph on
23923 -
23924 \begin_inset ERT
23925 status collapsed
23926
23927 \begin_layout Standard
23928
23929
23930 \backslash
23931 /
23932 \end_layout
23933
23934 \end_inset
23935
23936 -stack-auto
23937 \emph default
23938  option is used
23939 \end_layout
23940
23941 \end_inset
23942 </cell>
23943 </row>
23944 <row topline="true">
23945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23946 \begin_inset Text
23947
23948 \begin_layout Standard
23949 SDCC_MODEL_SMALL
23950 \begin_inset LatexCommand index
23951 name "SDCC\\_MODEL\\_SMALL"
23952
23953 \end_inset
23954
23955
23956 \end_layout
23957
23958 \end_inset
23959 </cell>
23960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23961 \begin_inset Text
23962
23963 \begin_layout Standard
23964 when 
23965 \emph on
23966 -
23967 \begin_inset ERT
23968 status collapsed
23969
23970 \begin_layout Standard
23971
23972
23973 \backslash
23974 /
23975 \end_layout
23976
23977 \end_inset
23978
23979 -model-small
23980 \emph default
23981  is used
23982 \end_layout
23983
23984 \end_inset
23985 </cell>
23986 </row>
23987 <row topline="true">
23988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23989 \begin_inset Text
23990
23991 \begin_layout Standard
23992 SDCC_MODEL_MEDIUM
23993 \begin_inset LatexCommand index
23994 name "SDCC\\_MODEL\\_MEDIUM"
23995
23996 \end_inset
23997
23998
23999 \end_layout
24000
24001 \end_inset
24002 </cell>
24003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24004 \begin_inset Text
24005
24006 \begin_layout Standard
24007 when 
24008 \emph on
24009 -
24010 \begin_inset ERT
24011 status collapsed
24012
24013 \begin_layout Standard
24014
24015
24016 \backslash
24017 /
24018 \end_layout
24019
24020 \end_inset
24021
24022 -model-medium
24023 \emph default
24024  is used
24025 \end_layout
24026
24027 \end_inset
24028 </cell>
24029 </row>
24030 <row topline="true">
24031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24032 \begin_inset Text
24033
24034 \begin_layout Standard
24035 SDCC_MODEL_LARGE
24036 \begin_inset LatexCommand index
24037 name "SDCC\\_MODEL\\_LARGE"
24038
24039 \end_inset
24040
24041
24042 \end_layout
24043
24044 \end_inset
24045 </cell>
24046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24047 \begin_inset Text
24048
24049 \begin_layout Standard
24050 when 
24051 \emph on
24052 -
24053 \begin_inset ERT
24054 status collapsed
24055
24056 \begin_layout Standard
24057
24058
24059 \backslash
24060 /
24061 \end_layout
24062
24063 \end_inset
24064
24065 -model-large
24066 \emph default
24067  is used
24068 \end_layout
24069
24070 \end_inset
24071 </cell>
24072 </row>
24073 <row topline="true">
24074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24075 \begin_inset Text
24076
24077 \begin_layout Standard
24078 SDCC_USE_XSTACK
24079 \begin_inset LatexCommand index
24080 name "SDCC\\_USE\\_XSTACK"
24081
24082 \end_inset
24083
24084
24085 \end_layout
24086
24087 \end_inset
24088 </cell>
24089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24090 \begin_inset Text
24091
24092 \begin_layout Standard
24093 when 
24094 \emph on
24095 -
24096 \begin_inset ERT
24097 status collapsed
24098
24099 \begin_layout Standard
24100
24101
24102 \backslash
24103 /
24104 \end_layout
24105
24106 \end_inset
24107
24108 -xstack
24109 \emph default
24110  option is used
24111 \end_layout
24112
24113 \end_inset
24114 </cell>
24115 </row>
24116 <row topline="true">
24117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24118 \begin_inset Text
24119
24120 \begin_layout Standard
24121 SDCC_STACK_TENBIT
24122 \begin_inset LatexCommand index
24123 name "SDCC\\_STACK\\_TENBIT"
24124
24125 \end_inset
24126
24127  
24128 \end_layout
24129
24130 \end_inset
24131 </cell>
24132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24133 \begin_inset Text
24134
24135 \begin_layout Standard
24136 when 
24137 \emph on
24138 -mds390
24139 \emph default
24140  is used
24141 \end_layout
24142
24143 \end_inset
24144 </cell>
24145 </row>
24146 <row topline="true">
24147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24148 \begin_inset Text
24149
24150 \begin_layout Standard
24151 SDCC_MODEL_FLAT24
24152 \begin_inset LatexCommand index
24153 name "SDCC\\_MODEL\\_FLAT24"
24154
24155 \end_inset
24156
24157
24158 \end_layout
24159
24160 \end_inset
24161 </cell>
24162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24163 \begin_inset Text
24164
24165 \begin_layout Standard
24166 when 
24167 \emph on
24168 -mds390
24169 \emph default
24170  is used
24171 \end_layout
24172
24173 \end_inset
24174 </cell>
24175 </row>
24176 <row topline="true">
24177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24178 \begin_inset Text
24179
24180 \begin_layout Standard
24181 SDCC_REVISION
24182 \begin_inset LatexCommand index
24183 name "SDCC\\_REVISION"
24184
24185 \end_inset
24186
24187
24188 \end_layout
24189
24190 \end_inset
24191 </cell>
24192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24193 \begin_inset Text
24194
24195 \begin_layout Standard
24196 Always defined.
24197  SDCC svn revision number
24198 \end_layout
24199
24200 \end_inset
24201 </cell>
24202 </row>
24203 <row topline="true">
24204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24205 \begin_inset Text
24206
24207 \begin_layout Standard
24208 SDCC_PARMS_IN_BANK1
24209 \begin_inset LatexCommand index
24210 name "SDCC\\_PARMS\\_IN\\_BANK1"
24211
24212 \end_inset
24213
24214
24215 \end_layout
24216
24217 \end_inset
24218 </cell>
24219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24220 \begin_inset Text
24221
24222 \begin_layout Standard
24223 when 
24224 \emph on
24225 -
24226 \begin_inset ERT
24227 status collapsed
24228
24229 \begin_layout Standard
24230
24231
24232 \backslash
24233 /
24234 \end_layout
24235
24236 \end_inset
24237
24238 -parms-in-bank1
24239 \emph default
24240  is used
24241 \end_layout
24242
24243 \end_inset
24244 </cell>
24245 </row>
24246 <row topline="true">
24247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24248 \begin_inset Text
24249
24250 \begin_layout Standard
24251 SDCC_FLOAT_REENT
24252 \begin_inset LatexCommand index
24253 name "SDCC\\_MODEL\\_FLAT24"
24254
24255 \end_inset
24256
24257
24258 \end_layout
24259
24260 \end_inset
24261 </cell>
24262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24263 \begin_inset Text
24264
24265 \begin_layout Standard
24266 when 
24267 \emph on
24268 -
24269 \begin_inset ERT
24270 status collapsed
24271
24272 \begin_layout Standard
24273
24274
24275 \backslash
24276 /
24277 \end_layout
24278
24279 \end_inset
24280
24281 -float-reent
24282 \emph default
24283  is used
24284 \end_layout
24285
24286 \end_inset
24287 </cell>
24288 </row>
24289 <row topline="true" bottomline="true">
24290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24291 \begin_inset Text
24292
24293 \begin_layout Standard
24294 SDCC_INT_LONG_REENT
24295 \begin_inset LatexCommand index
24296 name "SDCC\\_INT\\_LONG\\_REENT"
24297
24298 \end_inset
24299
24300
24301 \end_layout
24302
24303 \end_inset
24304 </cell>
24305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24306 \begin_inset Text
24307
24308 \begin_layout Standard
24309 when 
24310 \emph on
24311 -
24312 \begin_inset ERT
24313 status collapsed
24314
24315 \begin_layout Standard
24316
24317
24318 \backslash
24319 /
24320 \end_layout
24321
24322 \end_inset
24323
24324 -int-long-reent
24325 \emph default
24326  is used
24327 \end_layout
24328
24329 \end_inset
24330 </cell>
24331 </row>
24332 </lyxtabular>
24333
24334 \end_inset
24335
24336
24337 \end_layout
24338
24339 \begin_layout Chapter
24340 Notes on supported Processors
24341 \end_layout
24342
24343 \begin_layout Section
24344 MCS51 variants
24345 \begin_inset LatexCommand label
24346 name "sub:MCS51-variants"
24347
24348 \end_inset
24349
24350
24351 \begin_inset LatexCommand index
24352 name "MCS51 variants"
24353
24354 \end_inset
24355
24356
24357 \end_layout
24358
24359 \begin_layout Standard
24360 MCS51 processors are available from many vendors and come in many different
24361  flavours.
24362  While they might differ considerably in respect to Special Function Registers
24363  the core MCS51 is usually not modified or is kept compatible.
24364  
24365 \end_layout
24366
24367 \begin_layout Subsection
24368 pdata access by SFR 
24369 \end_layout
24370
24371 \begin_layout Standard
24372 With the upcome of devices with internal xdata and flash memory devices
24373  using port P2
24374 \begin_inset LatexCommand index
24375 name "P2 (mcs51 sfr)"
24376
24377 \end_inset
24378
24379  as dedicated I/O port is becoming more popular.
24380  Switching the high byte for pdata
24381 \begin_inset LatexCommand index
24382 name "pdata (mcs51, ds390 storage class)"
24383
24384 \end_inset
24385
24386  access which was formerly done by port P2 is then achieved by a Special
24387  Function Register
24388 \begin_inset LatexCommand index
24389 name "sfr"
24390
24391 \end_inset
24392
24393 .
24394  In well-established MCS51 tradition the address of this 
24395 \emph on
24396 sfr
24397 \emph default
24398  is where the chip designers decided to put it.
24399  Needless to say that they didn't agree on a common name either.
24400  So that the startup code can correctly initialize xdata variables, you
24401  should define an sfr with the name _XPAGE
24402 \family typewriter
24403
24404 \begin_inset LatexCommand index
24405 name "\\_XPAGE (mcs51)"
24406
24407 \end_inset
24408
24409
24410 \family default
24411  at the appropriate location if the default, port P2, is not used for this.
24412  Some examples are:
24413 \end_layout
24414
24415 \begin_layout Verse
24416
24417 \family typewriter
24418 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24419  MPAGE */
24420 \end_layout
24421
24422 \begin_layout Verse
24423
24424 \family typewriter
24425 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24426  a.k.a.
24427  MPAGE */
24428 \end_layout
24429
24430 \begin_layout Verse
24431
24432 \family typewriter
24433 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24434  XPAGE */
24435 \end_layout
24436
24437 \begin_layout Verse
24438
24439 \family typewriter
24440 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24441  EMI0CN */
24442 \end_layout
24443
24444 \begin_layout Verse
24445
24446 \family typewriter
24447 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24448  EMI0CN */
24449 \end_layout
24450
24451 \begin_layout Standard
24452 For more exotic implementations further customizations may be needed.
24453  See section 
24454 \begin_inset LatexCommand ref
24455 reference "sub:Startup-Code"
24456
24457 \end_inset
24458
24459  for other possibilities.
24460 \end_layout
24461
24462 \begin_layout Subsection
24463 Other Features available by SFR
24464 \end_layout
24465
24466 \begin_layout Standard
24467 Some MCS51 variants offer features like Double DPTR
24468 \begin_inset LatexCommand index
24469 name "DPTR"
24470
24471 \end_inset
24472
24473 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24474  These are currently not used for the MCS51 port.
24475  If you absolutely need them you can fall back to inline assembly or submit
24476  a patch to SDCC.
24477 \end_layout
24478
24479 \begin_layout Subsection
24480 Bankswitching
24481 \end_layout
24482
24483 \begin_layout Standard
24484 Bankswitching
24485 \begin_inset LatexCommand index
24486 name "Bankswitching"
24487
24488 \end_inset
24489
24490  (a.k.a.
24491  code banking
24492 \begin_inset LatexCommand index
24493 name "code banking"
24494
24495 \end_inset
24496
24497 ) is a technique to increase the code space above the 64k limit of the 8051.
24498 \end_layout
24499
24500 \begin_layout Subsubsection
24501 Hardware
24502 \end_layout
24503
24504 \begin_layout Standard
24505 \begin_inset Tabular
24506 <lyxtabular version="3" rows="3" columns="4">
24507 <features>
24508 <column alignment="center" valignment="top" width="0">
24509 <column alignment="center" valignment="top" leftline="true" width="0">
24510 <column alignment="center" valignment="top" leftline="true" width="0">
24511 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24512 <row topline="true" bottomline="true">
24513 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24514 \begin_inset Text
24515
24516 \begin_layout Standard
24517 8000-FFFF
24518 \end_layout
24519
24520 \end_inset
24521 </cell>
24522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24523 \begin_inset Text
24524
24525 \begin_layout Standard
24526 bank1
24527 \end_layout
24528
24529 \end_inset
24530 </cell>
24531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24532 \begin_inset Text
24533
24534 \begin_layout Standard
24535 bank2
24536 \end_layout
24537
24538 \end_inset
24539 </cell>
24540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24541 \begin_inset Text
24542
24543 \begin_layout Standard
24544 bank3
24545 \end_layout
24546
24547 \end_inset
24548 </cell>
24549 </row>
24550 <row topline="true" bottomline="true">
24551 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24552 \begin_inset Text
24553
24554 \begin_layout Standard
24555 0000-7FFF
24556 \end_layout
24557
24558 \end_inset
24559 </cell>
24560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24561 \begin_inset Text
24562
24563 \begin_layout Standard
24564 common
24565 \end_layout
24566
24567 \end_inset
24568 </cell>
24569 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24570 \begin_inset Text
24571
24572 \begin_layout Standard
24573
24574 \end_layout
24575
24576 \end_inset
24577 </cell>
24578 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24579 \begin_inset Text
24580
24581 \begin_layout Standard
24582
24583 \end_layout
24584
24585 \end_inset
24586 </cell>
24587 </row>
24588 <row>
24589 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24590 \begin_inset Text
24591
24592 \begin_layout Standard
24593 SiLabs C8051F120 example
24594 \end_layout
24595
24596 \end_inset
24597 </cell>
24598 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24599 \begin_inset Text
24600
24601 \begin_layout Standard
24602
24603 \end_layout
24604
24605 \end_inset
24606 </cell>
24607 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24608 \begin_inset Text
24609
24610 \begin_layout Standard
24611
24612 \end_layout
24613
24614 \end_inset
24615 </cell>
24616 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24617 \begin_inset Text
24618
24619 \begin_layout Standard
24620
24621 \end_layout
24622
24623 \end_inset
24624 </cell>
24625 </row>
24626 </lyxtabular>
24627
24628 \end_inset
24629
24630
24631 \newline
24632
24633 \newline
24634 Usually the hardware uses some sfr (an output port or an internal sfr) to
24635  select a bank and put it in the banked area of the memory map.
24636  The selected bank usually becomes active immediately upon assignment to
24637  this sfr and when running inside a bank it will switch out this code it
24638  is currently running.
24639  Therefor you cannot jump or call directly from one bank to another and
24640  need to use a so-called trampoline in the common area.
24641  For SDCC an example trampoline is in crtbank.asm and you may need to change
24642  it to your 8051 derivative or schematic.
24643  The presented code is written for the C8051F120.
24644 \newline
24645
24646 \newline
24647 When calling a banked function
24648  SDCC will put the LSB of the functions address in register R0, the MSB
24649  in R1 and the bank in R2 and then call this trampoline 
24650 \emph on
24651 __sdcc_banked_call
24652 \emph default
24653 .
24654  The current selected bank is saved on the stack, the new bank is selected
24655  and an indirect jump is made.
24656  When the banked function returns it jumps to 
24657 \emph on
24658 __sdcc_banked_ret
24659 \emph default
24660  which restores the previous bank and returns to the caller.
24661 \end_layout
24662
24663 \begin_layout Subsubsection
24664 Software
24665 \end_layout
24666
24667 \begin_layout Standard
24668 When writing banked software using SDCC you need to use some special keywords
24669  and options.
24670  You also need to take over a bit of work from the linker.
24671 \newline
24672
24673 \newline
24674 To create a function
24675  that can be called from another bank it requires the keyword 
24676 \emph on
24677 banked
24678 \emph default
24679
24680 \begin_inset LatexCommand index
24681 name "banked"
24682
24683 \end_inset
24684
24685 .
24686  The caller must see this in the prototype of the callee and the callee
24687  needs it for a proper return.
24688  Called functions within the same bank as the caller do not need the 
24689 \emph on
24690 banked
24691 \emph default
24692  keyword nor do functions in the common area.
24693  Beware: SDCC does not know or check if functions are in the same bank.
24694  This is your responsibility!
24695 \newline
24696
24697 \newline
24698 Normally all functions you write end up in
24699  the segment CSEG.
24700  If you want a function explicitly to reside in the common area put it in
24701  segment HOME.
24702  This applies for instance to interrupt service routines as they should
24703  not be banked.
24704 \end_layout
24705
24706 \begin_layout Standard
24707 Functions that need to be in a switched bank must be put in a named segment.
24708  The name can be mostly anything up to eight characters (e.g.
24709  BANK1).
24710  To do this you either use -
24711 \begin_inset ERT
24712 status collapsed
24713
24714 \begin_layout Standard
24715
24716
24717 \backslash
24718 /
24719 \end_layout
24720
24721 \end_inset
24722
24723 -codeseg BANK1 (See 
24724 \begin_inset LatexCommand ref
24725 reference "lyx:-codeseg"
24726
24727 \end_inset
24728
24729 ) on the command line when compiling or #pragma codeseg BANK1 (See 
24730 \begin_inset LatexCommand ref
24731 reference "sec:Pragmas"
24732
24733 \end_inset
24734
24735 ) at the top of the C source file.
24736  The segment name always applies to the whole source file and generated
24737  object so functions for different banks need to be defined in different
24738  source files.
24739 \newline
24740
24741 \newline
24742 When linking your objects you need to tell the linker where
24743  to put your segments.
24744  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24745 00 (See 
24746 \begin_inset LatexCommand ref
24747 reference "lyx:-Wl option"
24748
24749 \end_inset
24750
24751 ).
24752  This sets the virtual start address of this segment.
24753  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24754  The linker will not check for overflows, again this is your responsibility.
24755 \end_layout
24756
24757 \begin_layout Standard
24758 \begin_inset VSpace bigskip
24759 \end_inset
24760
24761
24762 \end_layout
24763
24764 \begin_layout Section
24765 DS400 port
24766 \end_layout
24767
24768 \begin_layout Standard
24769 The DS80C400
24770 \begin_inset LatexCommand index
24771 name "DS80C400"
24772
24773 \end_inset
24774
24775
24776 \begin_inset LatexCommand index
24777 name "DS400"
24778
24779 \end_inset
24780
24781  microcontroller has a rich set of peripherals.
24782  In its built-in ROM library it includes functions to access some of the
24783  features, among them is a TCP stack with IP4 and IP6 support.
24784  Library headers (currently in beta status) and other files are provided
24785  at 
24786 \size footnotesize
24787
24788 \begin_inset LatexCommand url
24789 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24790
24791 \end_inset
24792
24793 .
24794  
24795 \begin_inset VSpace bigskip
24796 \end_inset
24797
24798
24799 \end_layout
24800
24801 \begin_layout Section
24802 The Z80 and gbz80 port
24803 \end_layout
24804
24805 \begin_layout Standard
24806 SDCC can target both the Zilog Z80
24807 \begin_inset LatexCommand index
24808 name "Z80"
24809
24810 \end_inset
24811
24812  and the Nintendo Gameboy's Z80-like gbz80
24813 \begin_inset LatexCommand index
24814 name "gbz80 (GameBoy Z80)"
24815
24816 \end_inset
24817
24818 .
24819  The Z80 port is passed through the same 
24820 \emph on
24821 regressions tests
24822 \begin_inset LatexCommand index
24823 name "Regression test"
24824
24825 \end_inset
24826
24827
24828 \emph default
24829  (see section 
24830 \begin_inset LatexCommand ref
24831 reference "sec:Quality-control"
24832
24833 \end_inset
24834
24835 ) as the MCS51 and DS390 ports, so floating point support, support for long
24836  variables and bitfield support is fine.
24837  See mailing lists and forums about interrupt routines.
24838 \end_layout
24839
24840 \begin_layout Standard
24841 As always, the code is the authoritative reference - see z80/ralloc.c and
24842  z80/gen.c.
24843  The stack
24844 \begin_inset LatexCommand index
24845 name "Z80!stack"
24846
24847 \end_inset
24848
24849  frame is similar to that generated by the IAR Z80 compiler.
24850  IX is used as the base pointer, HL and IY are used as a temporary registers,
24851  and BC and DE are available for holding variables.
24852  Return values
24853 \begin_inset LatexCommand index
24854 name "Z80!return value"
24855
24856 \end_inset
24857
24858  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
24859  bytes).
24860  The gbz80 port use the same set of registers for the return values, but
24861  in a different order of significance: E (one byte), DE (two bytes), or
24862  HLDE (four bytes).
24863 \begin_inset VSpace bigskip
24864 \end_inset
24865
24866
24867 \end_layout
24868
24869 \begin_layout Section
24870 The HC08 port
24871 \end_layout
24872
24873 \begin_layout Standard
24874 The port to the Freescale/Motorola HC08
24875 \begin_inset LatexCommand index
24876 name "HC08"
24877
24878 \end_inset
24879
24880  family has been added in October 2003, and is still undergoing some basic
24881  development.
24882  The code generator is complete, but the register allocation is still quite
24883  unoptimized.
24884  Some of the SDCC's standard C library functions have embedded non-HC08
24885  inline assembly and so are not yet usable.
24886 \end_layout
24887
24888 \begin_layout Standard
24889 The HC08 port passes the regression test suite (see section 
24890 \begin_inset LatexCommand ref
24891 reference "sec:Quality-control"
24892
24893 \end_inset
24894
24895 ).
24896 \begin_inset VSpace bigskip
24897 \end_inset
24898
24899
24900 \end_layout
24901
24902 \begin_layout Section
24903 The PIC14
24904 \begin_inset LatexCommand index
24905 name "PIC14"
24906
24907 \end_inset
24908
24909  port
24910 \end_layout
24911
24912 \begin_layout Standard
24913 The PIC14 port adds support for Microchip
24914 \begin_inset LatexCommand index
24915 name "Microchip"
24916
24917 \end_inset
24918
24919
24920 \begin_inset Formula $^{\text{TM}}$
24921 \end_inset
24922
24923  PIC
24924 \begin_inset LatexCommand index
24925 name "PIC14"
24926
24927 \end_inset
24928
24929
24930 \begin_inset Formula $^{\text{TM}}$
24931 \end_inset
24932
24933  MCUs with 14 bit wide instructions.
24934  This port is not yet mature and still lacks many features.
24935  However, it can work for simple code.
24936 \end_layout
24937
24938 \begin_layout Standard
24939 \noindent
24940 Currently supported devices include:
24941 \end_layout
24942
24943 \begin_layout Standard
24944 12F: 629, 635, 675, 683
24945 \end_layout
24946
24947 \begin_layout Standard
24948 16C: 432, 433
24949 \end_layout
24950
24951 \begin_layout Standard
24952 16C: 554, 557, 558
24953 \end_layout
24954
24955 \begin_layout Standard
24956 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
24957 \end_layout
24958
24959 \begin_layout Standard
24960 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
24961  781, 782
24962 \end_layout
24963
24964 \begin_layout Standard
24965 16C: 925, 926
24966 \end_layout
24967
24968 \begin_layout Standard
24969 16CR: 620a, 73, 74, 76, 77
24970 \end_layout
24971
24972 \begin_layout Standard
24973 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
24974  687, 688, 689, 690
24975 \end_layout
24976
24977 \begin_layout Standard
24978 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
24979 \end_layout
24980
24981 \begin_layout Standard
24982 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
24983  877, 877a, 88, 886, 887
24984 \end_layout
24985
24986 \begin_layout Standard
24987 16F: 913, 914, 916, 917, 946
24988 \end_layout
24989
24990 \begin_layout Standard
24991 26HV: 626, 785
24992 \end_layout
24993
24994 \begin_layout Standard
24995 \noindent
24996 An up-to-date list of currently supported devices can be obtained via 
24997 \family typewriter
24998 sdcc -mpic14 -phelp foo.c
24999 \family default
25000  (foo.c must exist...).
25001 \end_layout
25002
25003 \begin_layout Subsection
25004 PIC Code Pages
25005 \begin_inset LatexCommand index
25006 name "code page (pic14)"
25007
25008 \end_inset
25009
25010  and Memory Banks
25011 \begin_inset LatexCommand index
25012 name "Memory bank (pic14)"
25013
25014 \end_inset
25015
25016
25017 \end_layout
25018
25019 \begin_layout Standard
25020 The linker organizes allocation for the code page and RAM banks.
25021  It does not have intimate knowledge of the code flow.
25022  It will put all the code section of a single .asm file into a single code
25023  page.
25024  In order to make use of multiple code pages, separate asm files must be
25025  used.
25026  The compiler assigns all 
25027 \emph on
25028 static
25029 \emph default
25030  functions of a single .c file into the same code page.
25031 \newline
25032
25033 \newline
25034 To get the best results,
25035  follow these guidelines:
25036 \end_layout
25037
25038 \begin_layout Enumerate
25039 Make local functions static, as non static functions require code page selection
25040  overhead.
25041 \newline
25042 Due to the way sdcc handles functions, place called functions prior
25043  to calling functions in the file wherever possible: Otherwise sdcc will
25044  insert unnecessary pagesel directives around the call, believing that the
25045  called function is externally defined.
25046 \end_layout
25047
25048 \begin_layout Enumerate
25049 For devices that have multiple code pages it is more efficient to use the
25050  same number of files as pages: Use up to 4 separate .c files for the 16F877,
25051  but only 2 files for the 16F874.
25052  This way the linker can put the code for each file into different code
25053  pages and there will be less page selection overhead.
25054 \end_layout
25055
25056 \begin_layout Enumerate
25057 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25058  instruction set), use `unsigned char' wherever possible instead of `int'.
25059 \end_layout
25060
25061 \begin_layout Subsection
25062 Adding New Devices to the Port 
25063 \end_layout
25064
25065 \begin_layout Standard
25066 Adding support for a new 14
25067 \begin_inset ERT
25068 status open
25069
25070 \begin_layout Standard
25071
25072
25073 \backslash
25074 ,
25075 \end_layout
25076
25077 \end_inset
25078
25079 bit PIC MCU requires the following steps:
25080 \end_layout
25081
25082 \begin_layout Enumerate
25083 Create a new device description.
25084 \newline
25085 Each device is described in two files: pic16f*.h
25086  and pic16f*.c.
25087  These files primarily define SFRs, structs to access their bits, and symbolic
25088  configuration options.
25089  Both files can be generated from gputils' .inc files using the perl script
25090  
25091 \family typewriter
25092 support/scripts/inc2h.pl
25093 \family default
25094 .
25095  This file also contains further instructions on how to proceed.
25096 \end_layout
25097
25098 \begin_layout Enumerate
25099 Copy the .h file into SDCC's include path and either add the .c file to your
25100  project or copy it to 
25101 \family typewriter
25102 device/lib/pic/libdev
25103 \family default
25104 .
25105  Afterwards, rebuild and install the libraries.
25106 \end_layout
25107
25108 \begin_layout Enumerate
25109 Edit pic14devices.txt in SDCC's include path (
25110 \family typewriter
25111 device/include/pic/
25112 \family default
25113  in the source tree or 
25114 \family typewriter
25115 /usr/local/share/sdcc/include/pic
25116 \family default
25117  after installation).
25118 \newline
25119 You need to add a device specification here to make
25120  the memory layout (code banks, RAM, aliased memory regions, ...) known to
25121  the compiler.
25122  Probably you can copy and modify an existing entry.
25123  The file format is documented at the top of the file.
25124 \end_layout
25125
25126 \begin_layout Subsection
25127 Interrupt Code
25128 \end_layout
25129
25130 \begin_layout Standard
25131 For the interrupt function, use the keyword `__interrupt'
25132 \begin_inset LatexCommand index
25133 name "PIC14!interrupt"
25134
25135 \end_inset
25136
25137  with level number of 0 (PIC14 only has 1 interrupt so this number is only
25138  there to avoid a syntax error - it ought to be fixed).
25139  E.g.:
25140 \end_layout
25141
25142 \begin_layout Verse
25143
25144 \family typewriter
25145 void Intr(void) __interrupt 0
25146 \newline
25147 {
25148 \newline
25149 \InsetSpace ~
25150 \InsetSpace ~
25151 T0IF = 0; /* Clear timer interrupt */
25152 \newline
25153 }
25154 \end_layout
25155
25156 \begin_layout Subsection
25157 Linking and Assembling
25158 \end_layout
25159
25160 \begin_layout Standard
25161 For assembling you can use either GPUTILS'
25162 \begin_inset LatexCommand index
25163 name "gputils (pic tools)"
25164
25165 \end_inset
25166
25167  gpasm.exe or MPLAB's mpasmwin.exe.
25168  GPUTILS are available from 
25169 \begin_inset LatexCommand url
25170 target "http://sourceforge.net/projects/gputils"
25171
25172 \end_inset
25173
25174 .
25175  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25176  If you use MPLAB and an interrupt function then the linker script file
25177  vectors section will need to be enlarged to link with mplink.
25178 \newline
25179
25180 \newline
25181 Here is a 
25182 \family typewriter
25183 Makefile
25184 \family default
25185  using GPUTILS:
25186 \end_layout
25187
25188 \begin_layout Verse
25189
25190 \family typewriter
25191 .c.o:
25192 \newline
25193 \InsetSpace ~
25194 \InsetSpace ~
25195 \InsetSpace ~
25196 \InsetSpace ~
25197 \InsetSpace ~
25198 \InsetSpace ~
25199 \InsetSpace ~
25200 \InsetSpace ~
25201 sdcc -V -mpic14 -p16f877 -c $< 
25202 \newline
25203
25204 \newline
25205 $(PRJ).hex: $(OBJS) 
25206 \newline
25207 \InsetSpace ~
25208 \InsetSpace ~
25209 \InsetSpace ~
25210 \InsetSpace ~
25211 \InsetSpace ~
25212 \InsetSpace ~
25213 \InsetSpace ~
25214 \InsetSpace ~
25215 gplink -m -s $(PRJ).lkr
25216  -o $(PRJ).hex $(OBJS) libsdcc.lib
25217 \end_layout
25218
25219 \begin_layout Standard
25220 Here is a 
25221 \family typewriter
25222 Makefile
25223 \family default
25224  using MPLAB:
25225 \end_layout
25226
25227 \begin_layout Verse
25228
25229 \family typewriter
25230 .c.o: 
25231 \newline
25232 \InsetSpace ~
25233 \InsetSpace ~
25234 \InsetSpace ~
25235 \InsetSpace ~
25236 \InsetSpace ~
25237 \InsetSpace ~
25238 \InsetSpace ~
25239 \InsetSpace ~
25240 sdcc -S -V -mpic14 -p16f877 $< 
25241 \newline
25242 \InsetSpace ~
25243 \InsetSpace ~
25244 \InsetSpace ~
25245 \InsetSpace ~
25246 \InsetSpace ~
25247 \InsetSpace ~
25248 \InsetSpace ~
25249 \InsetSpace ~
25250 mpasmwin /q /o $*.asm
25251 \newline
25252
25253 \newline
25254 $(PRJ).hex: $(OBJS)
25255  
25256 \newline
25257 \InsetSpace ~
25258 \InsetSpace ~
25259 \InsetSpace ~
25260 \InsetSpace ~
25261 \InsetSpace ~
25262 \InsetSpace ~
25263 \InsetSpace ~
25264 \InsetSpace ~
25265 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25266 \end_layout
25267
25268 \begin_layout Standard
25269 Please note that indentations within a 
25270 \family typewriter
25271 Makefile
25272 \family default
25273  have to be done with a tabulator character.
25274 \end_layout
25275
25276 \begin_layout Subsection
25277 Command-Line Options
25278 \end_layout
25279
25280 \begin_layout Standard
25281 Besides the switches common to all SDCC backends, the PIC14 port accepts
25282  the following options (for an updated list see sdcc -
25283 \begin_inset ERT
25284 status collapsed
25285
25286 \begin_layout Standard
25287
25288
25289 \backslash
25290 /
25291 \end_layout
25292
25293 \end_inset
25294
25295 -help):
25296 \end_layout
25297
25298 \begin_layout Description
25299 -
25300 \begin_inset ERT
25301 status collapsed
25302
25303 \begin_layout Standard
25304
25305
25306 \backslash
25307 /
25308 \end_layout
25309
25310 \end_inset
25311
25312 -debug-xtra
25313 \begin_inset LatexCommand index
25314 name "PIC14!Options!-\\/-debug-extra"
25315
25316 \end_inset
25317
25318  emit debug info in assembly output
25319 \end_layout
25320
25321 \begin_layout Description
25322 -
25323 \begin_inset ERT
25324 status collapsed
25325
25326 \begin_layout Standard
25327
25328
25329 \backslash
25330 /
25331 \end_layout
25332
25333 \end_inset
25334
25335 -no-pcode-opt
25336 \begin_inset LatexCommand index
25337 name "PIC14!Options!-\\/-no-pcode-opt"
25338
25339 \end_inset
25340
25341  disable (slightly faulty) optimization on pCode
25342 \end_layout
25343
25344 \begin_layout Description
25345 -
25346 \begin_inset ERT
25347 status collapsed
25348
25349 \begin_layout Standard
25350
25351
25352 \backslash
25353 /
25354 \end_layout
25355
25356 \end_inset
25357
25358 -stack-loc
25359 \begin_inset LatexCommand index
25360 name "PIC14!Options!-\\/-stack-loc"
25361
25362 \end_inset
25363
25364  sets the lowest address of the argument passing stack (defaults to a suitably
25365  large shared databank to reduce BANKSEL overhead)
25366 \end_layout
25367
25368 \begin_layout Description
25369 -
25370 \begin_inset ERT
25371 status collapsed
25372
25373 \begin_layout Standard
25374
25375
25376 \backslash
25377 /
25378 \end_layout
25379
25380 \end_inset
25381
25382 -stack-size
25383 \begin_inset LatexCommand index
25384 name "PIC14!Options!-\\/-stack-size"
25385
25386 \end_inset
25387
25388  sets the size if the argument passing stack (default: 16, minimum: 4)
25389 \end_layout
25390
25391 \begin_layout Subsection
25392 Environment Variables
25393 \end_layout
25394
25395 \begin_layout Standard
25396 The PIC14 port recognizes the following environment variables:
25397 \end_layout
25398
25399 \begin_layout Description
25400 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25401  register (the ones called r0xNNNN) in a section of its own.
25402  By default (if this variable is unset), sdcc tries to cluster registers
25403  in sections in order to reduce the BANKSEL overhead when accessing them.
25404 \end_layout
25405
25406 \begin_layout Subsection
25407 The Library
25408 \end_layout
25409
25410 \begin_layout Standard
25411 The PIC14 library currently only contains support routines required by the
25412  compiler to implement multiplication, division, and floating point support.
25413  No libc-like replacement is available at the moment, though many of the
25414  common sdcc library sources (in 
25415 \family typewriter
25416 device/lib
25417 \family default
25418 ) should also compile with the PIC14 port.
25419 \end_layout
25420
25421 \begin_layout Subsubsection
25422 error: missing definition for symbol ``__gptrget1''
25423 \end_layout
25424
25425 \begin_layout Standard
25426 The PIC14 port uses library routines to provide more complex operations
25427  like multiplication, division/modulus and (generic) pointer dereferencing.
25428  In order to add these routines to your project, you must link with PIC14's
25429  
25430 \family typewriter
25431 libsdcc.lib
25432 \family default
25433 .
25434  For single source file projects this is done automatically, more complex
25435  projects must add 
25436 \family typewriter
25437 libsdcc.lib
25438 \family default
25439  to the linker's arguments.
25440  Make sure you also add an include path for the library (using the -I switch
25441  to the linker)!
25442 \end_layout
25443
25444 \begin_layout Subsubsection
25445 Processor mismatch in file ``XXX''.
25446 \end_layout
25447
25448 \begin_layout Standard
25449 This warning can usually be ignored due to the very good compatibility amongst
25450  14
25451 \begin_inset ERT
25452 status open
25453
25454 \begin_layout Standard
25455
25456
25457 \backslash
25458 ,
25459 \end_layout
25460
25461 \end_inset
25462
25463 bit PIC
25464 \begin_inset LatexCommand index
25465 name "PIC14"
25466
25467 \end_inset
25468
25469  devices.
25470 \end_layout
25471
25472 \begin_layout Standard
25473 You might also consider recompiling the library for your specific device
25474  by changing the ARCH=p16f877 (default target) entry in 
25475 \family typewriter
25476 device/lib/pic/Makefile.in
25477 \family default
25478  and 
25479 \family typewriter
25480 device/lib/pic/Makefile
25481 \family default
25482  to reflect your device.
25483  This might even improve performance for smaller devices as unnecessary
25484  BANKSELs might be removed.
25485 \end_layout
25486
25487 \begin_layout Subsection
25488 Known Bugs
25489 \end_layout
25490
25491 \begin_layout Subsubsection
25492 Function arguments
25493 \end_layout
25494
25495 \begin_layout Standard
25496 Functions with variable argument lists (like printf) are not yet supported.
25497  Similarly, taking the address of the first argument passed into a function
25498  does not work: It is currently passed in WREG and has no address...
25499 \end_layout
25500
25501 \begin_layout Subsubsection
25502 Regression tests fail
25503 \end_layout
25504
25505 \begin_layout Standard
25506 Though the small subset of regression tests in src/regression passes, SDCC
25507  regression test suite does not, indicating that there are still major bugs
25508  in the port.
25509  However, many smaller projects have successfully used SDCC in the past...
25510 \end_layout
25511
25512 \begin_layout Standard
25513
25514 \size footnotesize
25515
25516 \newpage
25517
25518 \end_layout
25519
25520 \begin_layout Section
25521 The PIC16
25522 \begin_inset LatexCommand index
25523 name "PIC16"
25524
25525 \end_inset
25526
25527  port
25528 \end_layout
25529
25530 \begin_layout Standard
25531 The PIC16 port adds support for Microchip
25532 \begin_inset LatexCommand index
25533 name "Microchip"
25534
25535 \end_inset
25536
25537
25538 \begin_inset Formula $^{\text{TM}}$
25539 \end_inset
25540
25541  PIC
25542 \begin_inset LatexCommand index
25543 name "PIC"
25544
25545 \end_inset
25546
25547
25548 \begin_inset Formula $^{\text{TM}}$
25549 \end_inset
25550
25551  MCUs with 16 bit wide instructions.
25552  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25553 ; devices supported by the port include:
25554 \end_layout
25555
25556 \begin_layout Standard
25557 18F: 242, 248, 252, 258, 442, 448, 452, 458
25558 \end_layout
25559
25560 \begin_layout Standard
25561 18F: 1220, 1320
25562 \end_layout
25563
25564 \begin_layout Standard
25565 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
25566  24j10
25567 \end_layout
25568
25569 \begin_layout Standard
25570 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
25571  2680, 2682, 2685
25572 \end_layout
25573
25574 \begin_layout Standard
25575 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
25576  44j10
25577 \end_layout
25578
25579 \begin_layout Standard
25580 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
25581  4680, 4682, 4685
25582 \end_layout
25583
25584 \begin_layout Standard
25585 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
25586 \end_layout
25587
25588 \begin_layout Standard
25589 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
25590 \end_layout
25591
25592 \begin_layout Standard
25593 18F: 96j60, 96j65, 97j60
25594 \end_layout
25595
25596 \begin_layout Standard
25597 \noindent
25598 An up-to-date list of supported devices is also available via '
25599 \family typewriter
25600 sdcc -mpic16 -plist
25601 \family default
25602 '.
25603 \end_layout
25604
25605 \begin_layout Subsection
25606 Global Options
25607 \end_layout
25608
25609 \begin_layout Standard
25610 PIC16 port supports the standard command line arguments as supposed, with
25611  the exception of certain cases that will be mentioned in the following
25612  list:
25613 \end_layout
25614
25615 \begin_layout Description
25616 -
25617 \begin_inset ERT
25618 status collapsed
25619
25620 \begin_layout Standard
25621
25622
25623 \backslash
25624 /
25625 \end_layout
25626
25627 \end_inset
25628
25629 -callee-saves
25630 \begin_inset LatexCommand index
25631 name "PIC16!Options!-\\/-callee-saves"
25632
25633 \end_inset
25634
25635  See -
25636 \begin_inset ERT
25637 status collapsed
25638
25639 \begin_layout Standard
25640
25641
25642 \backslash
25643 /
25644 \end_layout
25645
25646 \end_inset
25647
25648 -all-callee-saves
25649 \end_layout
25650
25651 \begin_layout Description
25652 -
25653 \begin_inset ERT
25654 status collapsed
25655
25656 \begin_layout Standard
25657
25658
25659 \backslash
25660 /
25661 \end_layout
25662
25663 \end_inset
25664
25665 -fommit-frame-pointer
25666 \begin_inset LatexCommand index
25667 name "PIC16!Options!-\\/-fommit-frame-pointer"
25668
25669 \end_inset
25670
25671  Frame pointer will be omitted when the function uses no local variables.
25672 \end_layout
25673
25674 \begin_layout Subsection
25675 Port Specific Options
25676 \begin_inset LatexCommand index
25677 name "Options PIC16"
25678
25679 \end_inset
25680
25681
25682 \end_layout
25683
25684 \begin_layout Standard
25685 The port specific options appear after the global options in the sdcc -
25686 \begin_inset ERT
25687 status collapsed
25688
25689 \begin_layout Standard
25690
25691
25692 \backslash
25693 /
25694 \end_layout
25695
25696 \end_inset
25697
25698 -help output.
25699 \end_layout
25700
25701 \begin_layout Subsubsection
25702 Code Generation Options
25703 \end_layout
25704
25705 \begin_layout Standard
25706 These options influence the generated assembler code.
25707 \end_layout
25708
25709 \begin_layout Description
25710 -
25711 \begin_inset ERT
25712 status collapsed
25713
25714 \begin_layout Standard
25715
25716
25717 \backslash
25718 /
25719 \end_layout
25720
25721 \end_inset
25722
25723 -pstack-model=[model] Used in conjunction with the command above.
25724  Defines the stack model to be used, valid stack models are:
25725 \end_layout
25726
25727 \begin_deeper
25728 \begin_layout List
25729 \labelwidthstring 00.00.0000
25730
25731 \emph on
25732 small
25733 \emph default
25734  Selects small stack model.
25735  8 bit stack and frame pointers.
25736  Supports 256 bytes stack size.
25737 \end_layout
25738
25739 \begin_layout List
25740 \labelwidthstring 00.00.0000
25741
25742 \emph on
25743 large
25744 \emph default
25745  Selects large stack model.
25746  16 bit stack and frame pointers.
25747  Supports 65536 bytes stack size.
25748 \end_layout
25749
25750 \end_deeper
25751 \begin_layout Description
25752 -
25753 \begin_inset ERT
25754 status collapsed
25755
25756 \begin_layout Standard
25757
25758
25759 \backslash
25760 /
25761 \end_layout
25762
25763 \end_inset
25764
25765 -pno-banksel Do not generate BANKSEL assembler directives.
25766 \end_layout
25767
25768 \begin_layout Description
25769 -
25770 \begin_inset ERT
25771 status collapsed
25772
25773 \begin_layout Standard
25774
25775
25776 \backslash
25777 /
25778 \end_layout
25779
25780 \end_inset
25781
25782 -extended Enable extended instruction set/literal offset addressing mode.
25783  Use with care!
25784 \end_layout
25785
25786 \begin_layout Subsubsection
25787 Optimization Options
25788 \end_layout
25789
25790 \begin_layout Description
25791 -
25792 \begin_inset ERT
25793 status collapsed
25794
25795 \begin_layout Standard
25796
25797
25798 \backslash
25799 /
25800 \end_layout
25801
25802 \end_inset
25803
25804 -obanksel=n Set optimization level for inserting BANKSELs.
25805 \newline
25806
25807 \end_layout
25808
25809 \begin_deeper
25810 \begin_layout List
25811 \labelwidthstring 00.00.0000
25812 0 no optimization
25813 \end_layout
25814
25815 \begin_layout List
25816 \labelwidthstring 00.00.0000
25817 1 checks previous used register and if it is the same then does not emit
25818  BANKSEL, accounts only for labels.
25819 \end_layout
25820
25821 \begin_layout List
25822 \labelwidthstring 00.00.0000
25823 2 tries to check the location of (even different) symbols and removes BANKSELs
25824  if they are in the same bank.
25825  
25826 \newline
25827
25828 \emph on
25829 Important: There might be problems if the linker script has data sections
25830  across bank borders!
25831 \end_layout
25832
25833 \end_deeper
25834 \begin_layout Description
25835 -
25836 \begin_inset ERT
25837 status collapsed
25838
25839 \begin_layout Standard
25840
25841
25842 \backslash
25843 /
25844 \end_layout
25845
25846 \end_inset
25847
25848 -denable-peeps Force the usage of peepholes.
25849  Use with care.
25850 \end_layout
25851
25852 \begin_layout Description
25853 -
25854 \begin_inset ERT
25855 status collapsed
25856
25857 \begin_layout Standard
25858
25859
25860 \backslash
25861 /
25862 \end_layout
25863
25864 \end_inset
25865
25866 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
25867 \end_layout
25868
25869 \begin_layout Description
25870 -
25871 \begin_inset ERT
25872 status collapsed
25873
25874 \begin_layout Standard
25875
25876
25877 \backslash
25878 /
25879 \end_layout
25880
25881 \end_inset
25882
25883 -optimize-cmp Try to optimize some compares.
25884 \end_layout
25885
25886 \begin_layout Description
25887 -
25888 \begin_inset ERT
25889 status collapsed
25890
25891 \begin_layout Standard
25892
25893
25894 \backslash
25895 /
25896 \end_layout
25897
25898 \end_inset
25899
25900 -optimize-df Analyze the dataflow of the generated code and improve it.
25901 \end_layout
25902
25903 \begin_layout Subsubsection
25904 Assembling Options
25905 \end_layout
25906
25907 \begin_layout Description
25908 -
25909 \begin_inset ERT
25910 status collapsed
25911
25912 \begin_layout Standard
25913
25914
25915 \backslash
25916 /
25917 \end_layout
25918
25919 \end_inset
25920
25921 -asm= Sets the full path and name of an external assembler to call.
25922 \end_layout
25923
25924 \begin_layout Description
25925 -
25926 \begin_inset ERT
25927 status collapsed
25928
25929 \begin_layout Standard
25930
25931
25932 \backslash
25933 /
25934 \end_layout
25935
25936 \end_inset
25937
25938 -mplab-comp MPLAB
25939 \begin_inset LatexCommand index
25940 name "PIC16!MPLAB"
25941
25942 \end_inset
25943
25944  compatibility option.
25945  Currently only suppresses special gpasm directives.
25946 \end_layout
25947
25948 \begin_layout Subsubsection
25949 Linking Options
25950 \end_layout
25951
25952 \begin_layout Description
25953 -
25954 \begin_inset ERT
25955 status collapsed
25956
25957 \begin_layout Standard
25958
25959
25960 \backslash
25961 /
25962 \end_layout
25963
25964 \end_inset
25965
25966 -link= Sets the full path and name of an external linker to call.
25967 \end_layout
25968
25969 \begin_layout Description
25970 -
25971 \begin_inset ERT
25972 status collapsed
25973
25974 \begin_layout Standard
25975
25976
25977 \backslash
25978 /
25979 \end_layout
25980
25981 \end_inset
25982
25983 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
25984  unitialized data variables with [kword].
25985  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
25986 \end_layout
25987
25988 \begin_layout Description
25989 -
25990 \begin_inset ERT
25991 status collapsed
25992
25993 \begin_layout Standard
25994
25995
25996 \backslash
25997 /
25998 \end_layout
25999
26000 \end_inset
26001
26002 -ivt-loc=n Place the interrupt vector table at address 
26003 \emph on
26004 n
26005 \emph default
26006 .
26007  Useful for bootloaders.
26008 \end_layout
26009
26010 \begin_layout Description
26011 -
26012 \begin_inset ERT
26013 status collapsed
26014
26015 \begin_layout Standard
26016
26017
26018 \backslash
26019 /
26020 \end_layout
26021
26022 \end_inset
26023
26024 -nodefaultlibs Do not link default libraries when linking.
26025 \end_layout
26026
26027 \begin_layout Description
26028 -
26029 \begin_inset ERT
26030 status collapsed
26031
26032 \begin_layout Standard
26033
26034
26035 \backslash
26036 /
26037 \end_layout
26038
26039 \end_inset
26040
26041 -use-crt= Use a custom run-time module instead of the defaults.
26042 \end_layout
26043
26044 \begin_layout Description
26045 -
26046 \begin_inset ERT
26047 status collapsed
26048
26049 \begin_layout Standard
26050
26051
26052 \backslash
26053 /
26054 \end_layout
26055
26056 \end_inset
26057
26058 -no-crt Don't link the default run-time modules
26059 \end_layout
26060
26061 \begin_layout Subsubsection
26062 Debugging Options
26063 \end_layout
26064
26065 \begin_layout Standard
26066 Debugging options enable extra debugging information in the output files.
26067 \end_layout
26068
26069 \begin_layout Description
26070 -
26071 \begin_inset ERT
26072 status collapsed
26073
26074 \begin_layout Standard
26075
26076
26077 \backslash
26078 /
26079 \end_layout
26080
26081 \end_inset
26082
26083 -debug-xtra Similar to -
26084 \begin_inset ERT
26085 status collapsed
26086
26087 \begin_layout Standard
26088
26089
26090 \backslash
26091 /
26092 \end_layout
26093
26094 \end_inset
26095
26096 -debug
26097 \begin_inset LatexCommand index
26098 name "-\\/-debug"
26099
26100 \end_inset
26101
26102 , but dumps more information.
26103 \end_layout
26104
26105 \begin_layout Description
26106 -
26107 \begin_inset ERT
26108 status collapsed
26109
26110 \begin_layout Standard
26111
26112
26113 \backslash
26114 /
26115 \end_layout
26116
26117 \end_inset
26118
26119 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26120  information.
26121  <source> is the name of the file being compiled.
26122 \end_layout
26123
26124 \begin_layout Description
26125 -
26126 \begin_inset ERT
26127 status collapsed
26128
26129 \begin_layout Standard
26130
26131
26132 \backslash
26133 /
26134 \end_layout
26135
26136 \end_inset
26137
26138 -pcode-verbose Enable pcode debugging information in translation.
26139 \end_layout
26140
26141 \begin_layout Description
26142 -
26143 \begin_inset ERT
26144 status collapsed
26145
26146 \begin_layout Standard
26147
26148
26149 \backslash
26150 /
26151 \end_layout
26152
26153 \end_inset
26154
26155 -calltree Dump call tree in .calltree file.
26156 \end_layout
26157
26158 \begin_layout Description
26159 -
26160 \begin_inset ERT
26161 status collapsed
26162
26163 \begin_layout Standard
26164
26165
26166 \backslash
26167 /
26168 \end_layout
26169
26170 \end_inset
26171
26172 -gstack Trace push/pops for stack pointer overflow.
26173 \end_layout
26174
26175 \begin_layout Subsection
26176 Environment Variables
26177 \end_layout
26178
26179 \begin_layout Standard
26180 There is a number of environmental variables that can be used when running
26181  SDCC to enable certain optimizations or force a specific program behaviour.
26182  these variables are primarily for debugging purposes so they can be enabled/dis
26183 abled at will.
26184 \end_layout
26185
26186 \begin_layout Standard
26187 Currently there is only two such variables available:
26188 \end_layout
26189
26190 \begin_layout Description
26191 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26192  bitfields is optimized by directly loading FSR0 with the address of the
26193  bitfield structure.
26194  Normally SDCC will cast the bitfield structure to a bitfield pointer and
26195  then load FSR0.
26196  This step saves data ram and code space for functions that make heavy use
26197  of bitfields.
26198  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26199  option).
26200  
26201 \end_layout
26202
26203 \begin_layout Description
26204 NO_REG_OPT Do not perform pCode registers optimization.
26205  This should be used for debugging purposes.
26206  If bugs in the pcode optimizer are found, users can benefit from temporarily
26207  disabling the optimizer until the bug is fixed.
26208 \end_layout
26209
26210 \begin_layout Subsection
26211 Preprocessor Macros
26212 \end_layout
26213
26214 \begin_layout Standard
26215 PIC16
26216 \begin_inset LatexCommand index
26217 name "PIC16"
26218
26219 \end_inset
26220
26221  port defines the following preprocessor macros while translating a source.
26222 \end_layout
26223
26224 \begin_layout Standard
26225 \align center
26226 \begin_inset Tabular
26227 <lyxtabular version="3" rows="6" columns="2">
26228 <features>
26229 <column alignment="center" valignment="top" leftline="true" width="0">
26230 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26231 <row topline="true" bottomline="true">
26232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26233 \begin_inset Text
26234
26235 \begin_layout Standard
26236 Macro
26237 \end_layout
26238
26239 \end_inset
26240 </cell>
26241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26242 \begin_inset Text
26243
26244 \begin_layout Standard
26245 Description
26246 \end_layout
26247
26248 \end_inset
26249 </cell>
26250 </row>
26251 <row topline="true">
26252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26253 \begin_inset Text
26254
26255 \begin_layout Standard
26256 SDCC_pic16
26257 \end_layout
26258
26259 \end_inset
26260 </cell>
26261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26262 \begin_inset Text
26263
26264 \begin_layout Standard
26265 Port identification
26266 \end_layout
26267
26268 \end_inset
26269 </cell>
26270 </row>
26271 <row topline="true">
26272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26273 \begin_inset Text
26274
26275 \begin_layout Standard
26276 _
26277 \begin_inset ERT
26278 status collapsed
26279
26280 \begin_layout Standard
26281
26282
26283 \backslash
26284 /
26285 \end_layout
26286
26287 \end_inset
26288
26289 _pic16
26290 \end_layout
26291
26292 \end_inset
26293 </cell>
26294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26295 \begin_inset Text
26296
26297 \begin_layout Standard
26298 Port identification (same as above)
26299 \end_layout
26300
26301 \end_inset
26302 </cell>
26303 </row>
26304 <row topline="true">
26305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26306 \begin_inset Text
26307
26308 \begin_layout Standard
26309 pic18fxxxx
26310 \end_layout
26311
26312 \end_inset
26313 </cell>
26314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26315 \begin_inset Text
26316
26317 \begin_layout Standard
26318 MCU Identification.
26319  
26320 \emph on
26321 xxxx
26322 \emph default
26323  is the microcontrol identification number, i.e.
26324  452, 6620, etc
26325 \end_layout
26326
26327 \end_inset
26328 </cell>
26329 </row>
26330 <row topline="true">
26331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26332 \begin_inset Text
26333
26334 \begin_layout Standard
26335 _
26336 \begin_inset ERT
26337 status collapsed
26338
26339 \begin_layout Standard
26340
26341
26342 \backslash
26343 /
26344 \end_layout
26345
26346 \end_inset
26347
26348 _18Fxxxx
26349 \end_layout
26350
26351 \end_inset
26352 </cell>
26353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26354 \begin_inset Text
26355
26356 \begin_layout Standard
26357 MCU Identification (same as above)
26358 \end_layout
26359
26360 \end_inset
26361 </cell>
26362 </row>
26363 <row topline="true" bottomline="true">
26364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26365 \begin_inset Text
26366
26367 \begin_layout Standard
26368 STACK_MODEL_nnn
26369 \end_layout
26370
26371 \end_inset
26372 </cell>
26373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26374 \begin_inset Text
26375
26376 \begin_layout Standard
26377 nnn = SMALL or LARGE respectively according to the stack model used
26378 \end_layout
26379
26380 \end_inset
26381 </cell>
26382 </row>
26383 </lyxtabular>
26384
26385 \end_inset
26386
26387
26388 \end_layout
26389
26390 \begin_layout Standard
26391 \noindent
26392 In addition the following macros are defined when calling assembler:
26393 \end_layout
26394
26395 \begin_layout Standard
26396 \align center
26397 \begin_inset Tabular
26398 <lyxtabular version="3" rows="4" columns="2">
26399 <features>
26400 <column alignment="center" valignment="top" leftline="true" width="0">
26401 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26402 <row topline="true" bottomline="true">
26403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26404 \begin_inset Text
26405
26406 \begin_layout Standard
26407 Macro
26408 \end_layout
26409
26410 \end_inset
26411 </cell>
26412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26413 \begin_inset Text
26414
26415 \begin_layout Standard
26416 Description
26417 \end_layout
26418
26419 \end_inset
26420 </cell>
26421 </row>
26422 <row topline="true">
26423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26424 \begin_inset Text
26425
26426 \begin_layout Standard
26427 __18Fxxxx
26428 \end_layout
26429
26430 \end_inset
26431 </cell>
26432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26433 \begin_inset Text
26434
26435 \begin_layout Standard
26436 MCU Identification.
26437  
26438 \emph on
26439 xxxx
26440 \emph default
26441  is the microcontrol identification number, i.e.
26442  452, 6620, etc
26443 \end_layout
26444
26445 \end_inset
26446 </cell>
26447 </row>
26448 <row topline="true">
26449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26450 \begin_inset Text
26451
26452 \begin_layout Standard
26453 SDCC_MODEL_nnn
26454 \end_layout
26455
26456 \end_inset
26457 </cell>
26458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26459 \begin_inset Text
26460
26461 \begin_layout Standard
26462 nnn = SMALL or LARGE respectively according to the memory model used for
26463  SDCC
26464 \end_layout
26465
26466 \end_inset
26467 </cell>
26468 </row>
26469 <row topline="true" bottomline="true">
26470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26471 \begin_inset Text
26472
26473 \begin_layout Standard
26474 STACK_MODEL_nnn
26475 \end_layout
26476
26477 \end_inset
26478 </cell>
26479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26480 \begin_inset Text
26481
26482 \begin_layout Standard
26483 nnn = SMALL or LARGE respectively according to the stack model used
26484 \end_layout
26485
26486 \end_inset
26487 </cell>
26488 </row>
26489 </lyxtabular>
26490
26491 \end_inset
26492
26493
26494 \end_layout
26495
26496 \begin_layout Subsection
26497 Directories
26498 \end_layout
26499
26500 \begin_layout Standard
26501 PIC16
26502 \begin_inset LatexCommand index
26503 name "PIC16"
26504
26505 \end_inset
26506
26507  port uses the following directories for searching header files and libraries.
26508 \end_layout
26509
26510 \begin_layout Standard
26511 \align center
26512 \begin_inset Tabular
26513 <lyxtabular version="3" rows="3" columns="4">
26514 <features>
26515 <column alignment="center" valignment="top" leftline="true" width="0">
26516 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26517 <column alignment="center" valignment="top" width="0">
26518 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26519 <row topline="true" bottomline="true">
26520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26521 \begin_inset Text
26522
26523 \begin_layout Standard
26524 Directory
26525 \end_layout
26526
26527 \end_inset
26528 </cell>
26529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26530 \begin_inset Text
26531
26532 \begin_layout Standard
26533 Description
26534 \end_layout
26535
26536 \end_inset
26537 </cell>
26538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26539 \begin_inset Text
26540
26541 \begin_layout Standard
26542 Target
26543 \end_layout
26544
26545 \end_inset
26546 </cell>
26547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26548 \begin_inset Text
26549
26550 \begin_layout Standard
26551 Command prefix
26552 \end_layout
26553
26554 \end_inset
26555 </cell>
26556 </row>
26557 <row topline="true">
26558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26559 \begin_inset Text
26560
26561 \begin_layout Standard
26562 PREFIX/sdcc/include/pic16
26563 \end_layout
26564
26565 \end_inset
26566 </cell>
26567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26568 \begin_inset Text
26569
26570 \begin_layout Standard
26571 PIC16 specific headers
26572 \end_layout
26573
26574 \end_inset
26575 </cell>
26576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26577 \begin_inset Text
26578
26579 \begin_layout Standard
26580 Compiler
26581 \end_layout
26582
26583 \end_inset
26584 </cell>
26585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26586 \begin_inset Text
26587
26588 \begin_layout Standard
26589 -I
26590 \end_layout
26591
26592 \end_inset
26593 </cell>
26594 </row>
26595 <row topline="true" bottomline="true">
26596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26597 \begin_inset Text
26598
26599 \begin_layout Standard
26600 PREFIX/sdcc/lib/pic16
26601 \end_layout
26602
26603 \end_inset
26604 </cell>
26605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26606 \begin_inset Text
26607
26608 \begin_layout Standard
26609 PIC16 specific libraries
26610 \end_layout
26611
26612 \end_inset
26613 </cell>
26614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26615 \begin_inset Text
26616
26617 \begin_layout Standard
26618 Linker
26619 \end_layout
26620
26621 \end_inset
26622 </cell>
26623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26624 \begin_inset Text
26625
26626 \begin_layout Standard
26627 -L
26628 \end_layout
26629
26630 \end_inset
26631 </cell>
26632 </row>
26633 </lyxtabular>
26634
26635 \end_inset
26636
26637
26638 \end_layout
26639
26640 \begin_layout Subsection
26641 Pragmas
26642 \begin_inset LatexCommand label
26643 name "sub:PIC16_Pragmas"
26644
26645 \end_inset
26646
26647
26648 \end_layout
26649
26650 \begin_layout Standard
26651 The PIC16
26652 \begin_inset LatexCommand index
26653 name "PIC16"
26654
26655 \end_inset
26656
26657  port currently supports the following pragmas:
26658 \end_layout
26659
26660 \begin_layout Description
26661 stack
26662 \begin_inset LatexCommand index
26663 name "PIC16!Pragmas!\\#pragma stack"
26664
26665 \end_inset
26666
26667  This forces the code generator to initialize the stack & frame pointers
26668  at a specific address.
26669  This is an ad hoc solution for cases where no STACK directive is available
26670  in the linker script or gplink is not instructed to create a stack section.
26671 \newline
26672 The
26673  stack pragma should be used only once in a project.
26674  Multiple pragmas may result in indeterminate behaviour of the program.
26675 \begin_inset Foot
26676 status open
26677
26678 \begin_layout Standard
26679 The old format (ie.
26680  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26681  cross page boundaries (or even exceed the available data RAM) and crash
26682  the program.
26683  Make sure that stack does not cross page boundaries when using the SMALL
26684  stack model.
26685 \end_layout
26686
26687 \end_inset
26688
26689
26690 \newline
26691 The format is as follows:
26692 \newline
26693
26694 \end_layout
26695
26696 \begin_layout LyX-Code
26697 #pragma stack bottom_address [stack_size]
26698 \newline
26699
26700 \end_layout
26701
26702 \begin_layout Standard
26703
26704 \emph on
26705 bottom_address
26706 \emph default
26707  is the lower bound of the stack section.
26708  The stack pointer initially will point at address (bottom_address+stack_size-1).
26709 \end_layout
26710
26711 \begin_layout LyX-Code
26712 Example:
26713 \end_layout
26714
26715 \begin_layout LyX-Code
26716
26717 \end_layout
26718
26719 \begin_layout LyX-Code
26720 /* initializes stack of 100 bytes at RAM address 0x200 */
26721 \end_layout
26722
26723 \begin_layout LyX-Code
26724 #pragma stack 0x200 100
26725 \end_layout
26726
26727 \begin_layout Standard
26728 If the stack_size field is omitted then a stack is created with the default
26729  size of 64.
26730  This size might be enough for most programs, but its not enough for operations
26731  with deep function nesting or excessive stack usage.
26732 \end_layout
26733
26734 \begin_layout Description
26735 code
26736 \begin_inset LatexCommand index
26737 name "PIC16!Pragmas!\\#pragma code"
26738
26739 \end_inset
26740
26741  Force a function to a static FLASH address.
26742 \end_layout
26743
26744 \begin_layout LyX-Code
26745 Example:
26746 \end_layout
26747
26748 \begin_layout LyX-Code
26749
26750 \end_layout
26751
26752 \begin_layout LyX-Code
26753 /* place function test_func at 0x4000 */
26754 \end_layout
26755
26756 \begin_layout LyX-Code
26757 #pragma code test_func 0x4000
26758 \end_layout
26759
26760 \begin_layout LyX-Code
26761
26762 \end_layout
26763
26764 \begin_layout Description
26765 library instructs the linker to use a library module.
26766 \newline
26767 Usage:
26768 \end_layout
26769
26770 \begin_layout LyX-Code
26771 #pragma library module_name
26772 \end_layout
26773
26774 \begin_layout Standard
26775
26776 \emph on
26777 module_name
26778 \emph default
26779  can be any library or object file (including its path).
26780  Note that there are four reserved keywords which have special meaning.
26781  These are:
26782 \end_layout
26783
26784 \begin_layout Standard
26785 \align center
26786 \begin_inset Tabular
26787 <lyxtabular version="3" rows="6" columns="3">
26788 <features>
26789 <column alignment="center" valignment="top" leftline="true" width="0">
26790 <column alignment="block" valignment="top" leftline="true" width="20page%">
26791 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26792 <row topline="true" bottomline="true">
26793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26794 \begin_inset Text
26795
26796 \begin_layout Standard
26797 Keyword
26798 \end_layout
26799
26800 \end_inset
26801 </cell>
26802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26803 \begin_inset Text
26804
26805 \begin_layout Standard
26806 Description
26807 \end_layout
26808
26809 \end_inset
26810 </cell>
26811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26812 \begin_inset Text
26813
26814 \begin_layout Standard
26815 Module to link
26816 \end_layout
26817
26818 \end_inset
26819 </cell>
26820 </row>
26821 <row topline="true">
26822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26823 \begin_inset Text
26824
26825 \begin_layout Standard
26826
26827 \series bold
26828 ignore
26829 \end_layout
26830
26831 \end_inset
26832 </cell>
26833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26834 \begin_inset Text
26835
26836 \begin_layout Standard
26837 ignore all library pragmas
26838 \end_layout
26839
26840 \end_inset
26841 </cell>
26842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26843 \begin_inset Text
26844
26845 \begin_layout Standard
26846
26847 \emph on
26848 (none)
26849 \end_layout
26850
26851 \end_inset
26852 </cell>
26853 </row>
26854 <row topline="true">
26855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26856 \begin_inset Text
26857
26858 \begin_layout Standard
26859
26860 \series bold
26861 c
26862 \end_layout
26863
26864 \end_inset
26865 </cell>
26866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26867 \begin_inset Text
26868
26869 \begin_layout Standard
26870 link the C library
26871 \end_layout
26872
26873 \end_inset
26874 </cell>
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26876 \begin_inset Text
26877
26878 \begin_layout Standard
26879
26880 \emph on
26881 libc18f
26882 \emph default
26883 .lib
26884 \end_layout
26885
26886 \end_inset
26887 </cell>
26888 </row>
26889 <row topline="true">
26890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26891 \begin_inset Text
26892
26893 \begin_layout Standard
26894
26895 \series bold
26896 math
26897 \end_layout
26898
26899 \end_inset
26900 </cell>
26901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26902 \begin_inset Text
26903
26904 \begin_layout Standard
26905 link the Math libarary
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
26915 \emph on
26916 libm18f
26917 \emph default
26918 .lib
26919 \end_layout
26920
26921 \end_inset
26922 </cell>
26923 </row>
26924 <row topline="true">
26925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26926 \begin_inset Text
26927
26928 \begin_layout Standard
26929
26930 \series bold
26931 io
26932 \end_layout
26933
26934 \end_inset
26935 </cell>
26936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26937 \begin_inset Text
26938
26939 \begin_layout Standard
26940 link the I/O library
26941 \end_layout
26942
26943 \end_inset
26944 </cell>
26945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26946 \begin_inset Text
26947
26948 \begin_layout Standard
26949
26950 \emph on
26951 libio18f*
26952 \emph default
26953 .lib
26954 \end_layout
26955
26956 \end_inset
26957 </cell>
26958 </row>
26959 <row topline="true" bottomline="true">
26960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26961 \begin_inset Text
26962
26963 \begin_layout Standard
26964
26965 \series bold
26966 debug
26967 \end_layout
26968
26969 \end_inset
26970 </cell>
26971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26972 \begin_inset Text
26973
26974 \begin_layout Standard
26975 link the debug library
26976 \end_layout
26977
26978 \end_inset
26979 </cell>
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26981 \begin_inset Text
26982
26983 \begin_layout Standard
26984
26985 \emph on
26986 libdebug
26987 \emph default
26988 .lib
26989 \end_layout
26990
26991 \end_inset
26992 </cell>
26993 </row>
26994 </lyxtabular>
26995
26996 \end_inset
26997
26998
26999 \newline
27000 * is the device number, i.e.
27001  452 for PIC18F452 MCU.
27002 \end_layout
27003
27004 \begin_layout Standard
27005 \noindent
27006 This feature allows for linking with specific libraries without having to
27007  explicit name them in the command line.
27008  Note that the 
27009 \noun on
27010 ignore
27011 \noun default
27012  keyword will reject all modules specified by the library pragma.
27013 \end_layout
27014
27015 \begin_layout Description
27016 udata The pragma udata instructs the compiler to emit code so that linker
27017  will place a variable at a specific memory bank.
27018 \end_layout
27019
27020 \begin_layout LyX-Code
27021 Example:
27022 \end_layout
27023
27024 \begin_layout LyX-Code
27025
27026 \end_layout
27027
27028 \begin_layout LyX-Code
27029 /* places variable foo at bank2 */
27030 \end_layout
27031
27032 \begin_layout LyX-Code
27033 #pragma udata bank2 foo
27034 \end_layout
27035
27036 \begin_layout LyX-Code
27037 char foo;
27038 \end_layout
27039
27040 \begin_layout Standard
27041 In order for this pragma to work extra SECTION directives should be added
27042  in the .lkr script.
27043  In the following example a sample .lkr file is shown:
27044 \end_layout
27045
27046 \begin_layout LyX-Code
27047
27048 \end_layout
27049
27050 \begin_layout LyX-Code
27051 // Sample linker script for the PIC18F452 processor
27052 \end_layout
27053
27054 \begin_layout LyX-Code
27055 LIBPATH .
27056 \end_layout
27057
27058 \begin_layout LyX-Code
27059 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
27060 \end_layout
27061
27062 \begin_layout LyX-Code
27063 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
27064 \end_layout
27065
27066 \begin_layout LyX-Code
27067 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
27068 \end_layout
27069
27070 \begin_layout LyX-Code
27071 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
27072 \end_layout
27073
27074 \begin_layout LyX-Code
27075 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
27076 \end_layout
27077
27078 \begin_layout LyX-Code
27079 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
27080 \end_layout
27081
27082 \begin_layout LyX-Code
27083 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
27084 \end_layout
27085
27086 \begin_layout LyX-Code
27087
27088 \end_layout
27089
27090 \begin_layout LyX-Code
27091 DATABANK   NAME=gpr0       START=0x80           END=0xFF
27092 \end_layout
27093
27094 \begin_layout LyX-Code
27095 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
27096 \end_layout
27097
27098 \begin_layout LyX-Code
27099 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
27100 \end_layout
27101
27102 \begin_layout LyX-Code
27103 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
27104 \end_layout
27105
27106 \begin_layout LyX-Code
27107 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
27108 \end_layout
27109
27110 \begin_layout LyX-Code
27111 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
27112 \end_layout
27113
27114 \begin_layout LyX-Code
27115 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
27116 \end_layout
27117
27118 \begin_layout LyX-Code
27119
27120 \end_layout
27121
27122 \begin_layout LyX-Code
27123 SECTION    NAME=CONFIG     ROM=config
27124 \end_layout
27125
27126 \begin_layout LyX-Code
27127
27128 \end_layout
27129
27130 \begin_layout LyX-Code
27131 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
27132 \end_layout
27133
27134 \begin_layout LyX-Code
27135 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
27136 \end_layout
27137
27138 \begin_layout LyX-Code
27139 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
27140 \end_layout
27141
27142 \begin_layout LyX-Code
27143 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
27144 \end_layout
27145
27146 \begin_layout LyX-Code
27147 SECTION    NAME=bank4      RAM=gpr4
27148 \end_layout
27149
27150 \begin_layout LyX-Code
27151 SECTION    NAME=bank5      RAM=gpr5
27152 \end_layout
27153
27154 \begin_layout Standard
27155 The linker will recognise the section name set in the pragma statement and
27156  will position the variable at the memory bank set with the RAM field at
27157  the SECTION line in the linker script file.
27158 \end_layout
27159
27160 \begin_layout Subsection
27161 Header Files
27162 \begin_inset LatexCommand label
27163 name "sub:PIC16_Header-Files"
27164
27165 \end_inset
27166
27167
27168 \end_layout
27169
27170 \begin_layout Standard
27171 There is one main header file
27172 \begin_inset LatexCommand index
27173 name "PIC16!Header files"
27174
27175 \end_inset
27176
27177  that can be included to the source files using the pic16
27178 \begin_inset LatexCommand index
27179 name "PIC16"
27180
27181 \end_inset
27182
27183  port.
27184  That file is the 
27185 \series bold
27186 pic18fregs.h
27187 \series default
27188 .
27189  This header file contains the definitions for the processor special registers,
27190  so it is necessary if the source accesses them.
27191  It can be included by adding the following line in the beginning of the
27192  file:
27193 \end_layout
27194
27195 \begin_layout LyX-Code
27196 #include <pic18fregs.h>
27197 \end_layout
27198
27199 \begin_layout Standard
27200 The specific microcontroller is selected within the pic18fregs.h automatically,
27201  so the same source can be used with a variety of devices.
27202 \end_layout
27203
27204 \begin_layout Subsection
27205 Libraries
27206 \begin_inset LatexCommand label
27207 name "sub:pic16Libraries"
27208
27209 \end_inset
27210
27211
27212 \end_layout
27213
27214 \begin_layout Standard
27215 The libraries
27216 \begin_inset LatexCommand index
27217 name "PIC16!Libraries"
27218
27219 \end_inset
27220
27221  that PIC16
27222 \begin_inset LatexCommand index
27223 name "PIC16"
27224
27225 \end_inset
27226
27227  port depends on are the microcontroller device libraries which contain
27228  the symbol definitions for the microcontroller special function registers.
27229  These libraries have the format pic18fxxxx.lib, where 
27230 \emph on
27231 xxxx
27232 \emph default
27233  is the microcontroller identification number.
27234  The specific library is selected automatically by the compiler at link
27235  stage according to the selected device.
27236 \end_layout
27237
27238 \begin_layout Standard
27239 \noindent
27240 Libraries are created with gplib which is part of the gputils package 
27241 \begin_inset LatexCommand url
27242 target "http://sourceforge.net/projects/gputils"
27243
27244 \end_inset
27245
27246 .
27247 \end_layout
27248
27249 \begin_layout Subsubsection*
27250 Building the libraries
27251 \end_layout
27252
27253 \begin_layout Standard
27254 Before using SDCC/pic16 there are some libraries that need to be compiled.
27255  This process is done automatically if gputils are found at SDCC's compile
27256  time.
27257  Should you require to rebuild the pic16 libraries manually, these are the
27258  steps required to do so under Linux or Mac OS X (cygwin might work as well,
27259  but is untested):
27260 \end_layout
27261
27262 \begin_layout LyX-Code
27263 cd device/lib/pic16
27264 \end_layout
27265
27266 \begin_layout LyX-Code
27267 ./configure.gnu
27268 \end_layout
27269
27270 \begin_layout LyX-Code
27271 cd ..
27272 \end_layout
27273
27274 \begin_layout LyX-Code
27275 make model-pic16
27276 \end_layout
27277
27278 \begin_layout LyX-Code
27279 su -c 'make install'     # install the libraries, you need the root password
27280 \end_layout
27281
27282 \begin_layout LyX-Code
27283 cd ../..
27284 \end_layout
27285
27286 \begin_layout Standard
27287 If you need to install the headers too, do:
27288 \end_layout
27289
27290 \begin_layout LyX-Code
27291 cd device/include
27292 \end_layout
27293
27294 \begin_layout LyX-Code
27295 su -c 'make install'     # install the headers, you need the root password
27296 \end_layout
27297
27298 \begin_layout Subsection
27299 Adding New Devices to the Port
27300 \end_layout
27301
27302 \begin_layout Standard
27303 Adding support for a new 16
27304 \begin_inset ERT
27305 status collapsed
27306
27307 \begin_layout Standard
27308
27309
27310 \backslash
27311 ,
27312 \end_layout
27313
27314 \end_inset
27315
27316 bit PIC MCU requires the following steps:
27317 \end_layout
27318
27319 \begin_layout Enumerate
27320 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27321 \newline
27322
27323 \family typewriter
27324 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27325 inc
27326 \end_layout
27327
27328 \begin_layout Enumerate
27329
27330 \family typewriter
27331 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27332 \end_layout
27333
27334 \begin_layout Enumerate
27335
27336 \family typewriter
27337 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27338 \end_layout
27339
27340 \begin_layout Enumerate
27341 Add DEVICE to 
27342 \family typewriter
27343 /path/to/sdcc/device/lib/pic16/pics.all
27344 \family default
27345
27346 \newline
27347 Note: No 18f prefix here!
27348 \end_layout
27349
27350 \begin_layout Enumerate
27351 Edit 
27352 \family typewriter
27353 /path/to/sdcc/device/include/pic16/adc.h
27354 \newline
27355
27356 \family default
27357 Add the new devices to the correct ADC style class (depending on the number
27358  of ADC channels).
27359 \newline
27360 Do not touch 
27361 \family typewriter
27362 adc.h
27363 \family default
27364  if the device does not offer any ADC at all.
27365 \end_layout
27366
27367 \begin_layout Enumerate
27368 Edit 
27369 \family typewriter
27370 /path/to/sdcc/device/include/pic16/pic18fregs.h
27371 \family default
27372
27373 \newline
27374 The file format is self-explanatory, just add
27375 \newline
27376
27377 \family typewriter
27378 #elif defined(picDEVICE)
27379 \newline
27380 #
27381 \begin_inset ERT
27382 status collapsed
27383
27384 \begin_layout Standard
27385
27386
27387 \backslash
27388  
27389 \backslash
27390  
27391 \end_layout
27392
27393 \end_inset
27394
27395 include <picDEVICE.h>
27396 \family default
27397
27398 \newline
27399 at the right place (keep the file sorted, please).
27400 \end_layout
27401
27402 \begin_layout Enumerate
27403 Edit 
27404 \family typewriter
27405 /path/to/sdcc/device/include/pic16devices.txt
27406 \newline
27407
27408 \family default
27409 Copy and modify an existing entry or create a new one and insert it at the
27410  correct place (keep the file sorted, please).
27411 \end_layout
27412
27413 \begin_layout Enumerate
27414 Add the device to 
27415 \family typewriter
27416 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27417 \family default
27418
27419 \newline
27420 Copy an existing entry and adjust the device name.
27421 \end_layout
27422
27423 \begin_layout Enumerate
27424 Add the device to 
27425 \family typewriter
27426 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27427 \family default
27428
27429 \newline
27430 Copy the record from the 18f2220 and adjust the device name.
27431 \newline
27432 If the new device
27433  does not offer ADC, I
27434 \begin_inset Formula $^{\text{2}}$
27435 \end_inset
27436
27437 C, and/or (E)USART functionality as assumed by the library, remove the lines
27438  with references to 
27439 \family typewriter
27440 adc/*.c
27441 \family default
27442
27443 \family typewriter
27444 usart/*.c
27445 \family default
27446 , or 
27447 \family typewriter
27448 usart/*.c
27449 \family default
27450 , respectively.
27451 \end_layout
27452
27453 \begin_layout Enumerate
27454 Update 
27455 \family typewriter
27456 libdev/Makefile.in
27457 \family default
27458  and 
27459 \family typewriter
27460 libio/Makefile.in
27461 \family default
27462  using
27463 \newline
27464
27465 \family typewriter
27466 ./bootstrap.sh
27467 \family default
27468
27469 \newline
27470 in 
27471 \family typewriter
27472 /path/to/sdcc/device/lib/pic16
27473 \family default
27474 .
27475 \end_layout
27476
27477 \begin_layout Enumerate
27478 Recompile the pic16 libraries as described in 
27479 \begin_inset LatexCommand ref
27480 reference "sub:pic16Libraries"
27481
27482 \end_inset
27483
27484 .
27485 \end_layout
27486
27487 \begin_layout Subsection
27488 Memory Models
27489 \end_layout
27490
27491 \begin_layout Standard
27492 The following memory models are supported by the PIC16 port:
27493 \end_layout
27494
27495 \begin_layout Itemize
27496 small model
27497 \end_layout
27498
27499 \begin_layout Itemize
27500 large model
27501 \end_layout
27502
27503 \begin_layout Standard
27504 Memory model affects the default size of pointers within the source.
27505  The sizes are shown in the next table:
27506 \end_layout
27507
27508 \begin_layout Standard
27509 \align center
27510 \begin_inset Tabular
27511 <lyxtabular version="3" rows="3" columns="3">
27512 <features>
27513 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27514 <column alignment="center" valignment="top" leftline="true" width="0">
27515 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27516 <row topline="true" bottomline="true">
27517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27518 \begin_inset Text
27519
27520 \begin_layout Standard
27521 Pointer sizes according to memory model
27522 \end_layout
27523
27524 \end_inset
27525 </cell>
27526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27527 \begin_inset Text
27528
27529 \begin_layout Standard
27530 small model
27531 \end_layout
27532
27533 \end_inset
27534 </cell>
27535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27536 \begin_inset Text
27537
27538 \begin_layout Standard
27539 large model
27540 \end_layout
27541
27542 \end_inset
27543 </cell>
27544 </row>
27545 <row topline="true" bottomline="true">
27546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27547 \begin_inset Text
27548
27549 \begin_layout Standard
27550 code pointers
27551 \end_layout
27552
27553 \end_inset
27554 </cell>
27555 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27556 \begin_inset Text
27557
27558 \begin_layout Standard
27559 16-bits
27560 \end_layout
27561
27562 \end_inset
27563 </cell>
27564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27565 \begin_inset Text
27566
27567 \begin_layout Standard
27568 24-bits
27569 \end_layout
27570
27571 \end_inset
27572 </cell>
27573 </row>
27574 <row topline="true" bottomline="true">
27575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27576 \begin_inset Text
27577
27578 \begin_layout Standard
27579 data pointers
27580 \end_layout
27581
27582 \end_inset
27583 </cell>
27584 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27585 \begin_inset Text
27586
27587 \begin_layout Standard
27588 16-bits
27589 \end_layout
27590
27591 \end_inset
27592 </cell>
27593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27594 \begin_inset Text
27595
27596 \begin_layout Standard
27597 16-bits
27598 \end_layout
27599
27600 \end_inset
27601 </cell>
27602 </row>
27603 </lyxtabular>
27604
27605 \end_inset
27606
27607
27608 \end_layout
27609
27610 \begin_layout Standard
27611 It is advisable that all sources within a project are compiled with the
27612  same memory model.
27613  If one wants to override the default memory model, this can be done by
27614  declaring a pointer as 
27615 \series bold
27616 far
27617 \series default
27618  or 
27619 \series bold
27620 near
27621 \series default
27622 .
27623  Far selects large memory model's pointers, while near selects small memory
27624  model's pointers.
27625 \end_layout
27626
27627 \begin_layout Standard
27628 The standard device libraries (see 
27629 \begin_inset LatexCommand ref
27630 reference "sub:PIC16_Header-Files"
27631
27632 \end_inset
27633
27634 ) contain no reference to pointers, so they can be used with both memory
27635  models.
27636 \end_layout
27637
27638 \begin_layout Subsection
27639 Stack
27640 \end_layout
27641
27642 \begin_layout Standard
27643 The stack
27644 \begin_inset LatexCommand index
27645 name "PIC16!stack"
27646
27647 \end_inset
27648
27649  implementation for the PIC16 port uses two indirect registers, FSR1 and
27650  FSR2.
27651 \end_layout
27652
27653 \begin_layout Description
27654 FSR1 is assigned as stack pointer
27655 \end_layout
27656
27657 \begin_layout Description
27658 FSR2 is assigned as frame pointer
27659 \end_layout
27660
27661 \begin_layout Standard
27662 The following stack models are supported by the PIC16 port
27663 \end_layout
27664
27665 \begin_layout Itemize
27666
27667 \noun on
27668 small
27669 \noun default
27670  model
27671 \end_layout
27672
27673 \begin_layout Itemize
27674
27675 \noun on
27676 large
27677 \noun default
27678  model
27679 \end_layout
27680
27681 \begin_layout Standard
27682
27683 \noun on
27684 Small
27685 \noun default
27686  model means that only the FSRxL byte is used to access stack and frame,
27687  while 
27688 \emph on
27689 \noun on
27690 large
27691 \emph default
27692 \noun default
27693  uses both FSRxL and FSRxH registers.
27694  The following table shows the stack/frame pointers sizes according to stack
27695  model and the maximum space they can address:
27696 \end_layout
27697
27698 \begin_layout Standard
27699 \align center
27700 \begin_inset Tabular
27701 <lyxtabular version="3" rows="3" columns="3">
27702 <features>
27703 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27704 <column alignment="center" valignment="top" leftline="true" width="0">
27705 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27706 <row topline="true" bottomline="true">
27707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27708 \begin_inset Text
27709
27710 \begin_layout Standard
27711 Stack & Frame pointer sizes according to stack model
27712 \end_layout
27713
27714 \end_inset
27715 </cell>
27716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27717 \begin_inset Text
27718
27719 \begin_layout Standard
27720 small
27721 \end_layout
27722
27723 \end_inset
27724 </cell>
27725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27726 \begin_inset Text
27727
27728 \begin_layout Standard
27729 large
27730 \end_layout
27731
27732 \end_inset
27733 </cell>
27734 </row>
27735 <row topline="true">
27736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27737 \begin_inset Text
27738
27739 \begin_layout Standard
27740 Stack pointer FSR1
27741 \end_layout
27742
27743 \end_inset
27744 </cell>
27745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27746 \begin_inset Text
27747
27748 \begin_layout Standard
27749 8-bits
27750 \end_layout
27751
27752 \end_inset
27753 </cell>
27754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27755 \begin_inset Text
27756
27757 \begin_layout Standard
27758 16-bits
27759 \end_layout
27760
27761 \end_inset
27762 </cell>
27763 </row>
27764 <row topline="true" bottomline="true">
27765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27766 \begin_inset Text
27767
27768 \begin_layout Standard
27769 Frame pointer FSR2
27770 \end_layout
27771
27772 \end_inset
27773 </cell>
27774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27775 \begin_inset Text
27776
27777 \begin_layout Standard
27778 8-bits
27779 \end_layout
27780
27781 \end_inset
27782 </cell>
27783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27784 \begin_inset Text
27785
27786 \begin_layout Standard
27787 16-bits
27788 \end_layout
27789
27790 \end_inset
27791 </cell>
27792 </row>
27793 </lyxtabular>
27794
27795 \end_inset
27796
27797
27798 \end_layout
27799
27800 \begin_layout Standard
27801 \noindent
27802
27803 \noun on
27804 Large 
27805 \noun default
27806 stack model is currently not working properly throughout the code generator.
27807  So its use is not advised.
27808  Also there are some other points that need special care:
27809 \newline
27810
27811 \end_layout
27812
27813 \begin_layout Enumerate
27814 Do not create stack sections with size more than one physical bank (that
27815  is 256 bytes)
27816 \end_layout
27817
27818 \begin_layout Enumerate
27819 Stack sections should no cross physical bank limits (i.e.
27820  #pragma stack 0x50 0x100)
27821 \end_layout
27822
27823 \begin_layout Standard
27824 These limitations are caused by the fact that only FSRxL is modified when
27825  using SMALL stack model, so no more than 256 bytes of stack can be used.
27826  This problem will disappear after LARGE model is fully implemented.
27827 \end_layout
27828
27829 \begin_layout Subsection
27830 Functions
27831 \end_layout
27832
27833 \begin_layout Standard
27834 In addition to the standard SDCC function keywords, PIC16
27835 \begin_inset LatexCommand index
27836 name "PIC16"
27837
27838 \end_inset
27839
27840  port makes available two more:
27841 \end_layout
27842
27843 \begin_layout Description
27844 wparam
27845 \begin_inset LatexCommand index
27846 name "PIC16!wparam"
27847
27848 \end_inset
27849
27850  Use the WREG to pass one byte of the first function argument.
27851  This improves speed but you may not use this for functions with arguments
27852  that are called via function pointers, otherwise the first byte of the
27853  first parameter will get lost.
27854  Usage:
27855 \end_layout
27856
27857 \begin_layout LyX-Code
27858 void func_wparam(int a) wparam
27859 \end_layout
27860
27861 \begin_layout LyX-Code
27862 {
27863 \end_layout
27864
27865 \begin_layout LyX-Code
27866     /* WREG hold the lower part of a */
27867 \end_layout
27868
27869 \begin_layout LyX-Code
27870     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
27871  */
27872 \end_layout
27873
27874 \begin_layout LyX-Code
27875 ...
27876 \end_layout
27877
27878 \begin_layout LyX-Code
27879 }
27880 \end_layout
27881
27882 \begin_layout Description
27883 shadowregs
27884 \begin_inset LatexCommand index
27885 name "PIC16!shadowregs"
27886
27887 \end_inset
27888
27889  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
27890  hardware shadow registers which hold the values of WREG, STATUS and BSR
27891  registers.
27892  This can be done by adding the keyword 
27893 \emph on
27894 shadowregs
27895 \emph default
27896  before the 
27897 \emph on
27898 interrupt
27899 \emph default
27900  keyword in the function's header.
27901 \end_layout
27902
27903 \begin_layout LyX-Code
27904 void isr_shadow(void) shadowregs interrupt 1
27905 \end_layout
27906
27907 \begin_layout LyX-Code
27908 {
27909 \end_layout
27910
27911 \begin_layout LyX-Code
27912 ...
27913 \end_layout
27914
27915 \begin_layout LyX-Code
27916 }
27917 \end_layout
27918
27919 \begin_layout Standard
27920
27921 \emph on
27922 shadowregs
27923 \emph default
27924  instructs the code generator not to store/restore WREG, STATUS, BSR when
27925  entering/exiting the ISR.
27926 \end_layout
27927
27928 \begin_layout Subsection
27929 Function return values
27930 \end_layout
27931
27932 \begin_layout Standard
27933 Return values from functions are placed to the appropriate registers following
27934  a modified Microchip policy optimized for SDCC.
27935  The following table shows these registers:
27936 \end_layout
27937
27938 \begin_layout Standard
27939 \align center
27940 \begin_inset Tabular
27941 <lyxtabular version="3" rows="6" columns="2">
27942 <features>
27943 <column alignment="center" valignment="top" leftline="true" width="0">
27944 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27945 <row topline="true" bottomline="true">
27946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27947 \begin_inset Text
27948
27949 \begin_layout Standard
27950 size
27951 \end_layout
27952
27953 \end_inset
27954 </cell>
27955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27956 \begin_inset Text
27957
27958 \begin_layout Standard
27959 destination register
27960 \end_layout
27961
27962 \end_inset
27963 </cell>
27964 </row>
27965 <row topline="true">
27966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27967 \begin_inset Text
27968
27969 \begin_layout Standard
27970 8 bits
27971 \end_layout
27972
27973 \end_inset
27974 </cell>
27975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27976 \begin_inset Text
27977
27978 \begin_layout Standard
27979 WREG
27980 \end_layout
27981
27982 \end_inset
27983 </cell>
27984 </row>
27985 <row topline="true">
27986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27987 \begin_inset Text
27988
27989 \begin_layout Standard
27990 16 bits
27991 \end_layout
27992
27993 \end_inset
27994 </cell>
27995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27996 \begin_inset Text
27997
27998 \begin_layout Standard
27999 PRODL:WREG
28000 \end_layout
28001
28002 \end_inset
28003 </cell>
28004 </row>
28005 <row topline="true">
28006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28007 \begin_inset Text
28008
28009 \begin_layout Standard
28010 24 bits
28011 \end_layout
28012
28013 \end_inset
28014 </cell>
28015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28016 \begin_inset Text
28017
28018 \begin_layout Standard
28019 PRODH:PRODL:WREG
28020 \end_layout
28021
28022 \end_inset
28023 </cell>
28024 </row>
28025 <row topline="true">
28026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28027 \begin_inset Text
28028
28029 \begin_layout Standard
28030 32 bits
28031 \end_layout
28032
28033 \end_inset
28034 </cell>
28035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28036 \begin_inset Text
28037
28038 \begin_layout Standard
28039 FSR0L:PRODH:PRODL:WREG
28040 \end_layout
28041
28042 \end_inset
28043 </cell>
28044 </row>
28045 <row topline="true" bottomline="true">
28046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28047 \begin_inset Text
28048
28049 \begin_layout Standard
28050 >32 bits
28051 \end_layout
28052
28053 \end_inset
28054 </cell>
28055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28056 \begin_inset Text
28057
28058 \begin_layout Standard
28059 on stack, FSR0 points to the beginning
28060 \end_layout
28061
28062 \end_inset
28063 </cell>
28064 </row>
28065 </lyxtabular>
28066
28067 \end_inset
28068
28069
28070 \end_layout
28071
28072 \begin_layout Subsection
28073 Interrupts
28074 \end_layout
28075
28076 \begin_layout Standard
28077 An interrupt
28078 \begin_inset LatexCommand index
28079 name "PIC16!interrupt"
28080
28081 \end_inset
28082
28083  service routine (ISR) is declared using the 
28084 \emph on
28085 interrupt
28086 \emph default
28087  keyword.
28088 \end_layout
28089
28090 \begin_layout LyX-Code
28091 void isr(void) interrupt 
28092 \emph on
28093 n
28094 \end_layout
28095
28096 \begin_layout LyX-Code
28097 {
28098 \end_layout
28099
28100 \begin_layout LyX-Code
28101 ...
28102 \end_layout
28103
28104 \begin_layout LyX-Code
28105 }
28106 \end_layout
28107
28108 \begin_layout Standard
28109
28110 \emph on
28111 n
28112 \emph default
28113  is the interrupt number, which for PIC18F devices can be:
28114 \end_layout
28115
28116 \begin_layout Standard
28117 \align center
28118 \begin_inset Tabular
28119 <lyxtabular version="3" rows="4" columns="3">
28120 <features>
28121 <column alignment="center" valignment="top" leftline="true" width="0">
28122 <column alignment="center" valignment="top" leftline="true" width="0">
28123 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28124 <row topline="true" bottomline="true">
28125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28126 \begin_inset Text
28127
28128 \begin_layout Standard
28129
28130 \emph on
28131 n
28132 \end_layout
28133
28134 \end_inset
28135 </cell>
28136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28137 \begin_inset Text
28138
28139 \begin_layout Standard
28140 Interrupt Vector
28141 \end_layout
28142
28143 \end_inset
28144 </cell>
28145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28146 \begin_inset Text
28147
28148 \begin_layout Standard
28149 Interrupt Vector Address
28150 \end_layout
28151
28152 \end_inset
28153 </cell>
28154 </row>
28155 <row topline="true">
28156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28157 \begin_inset Text
28158
28159 \begin_layout Standard
28160 0
28161 \end_layout
28162
28163 \end_inset
28164 </cell>
28165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28166 \begin_inset Text
28167
28168 \begin_layout Standard
28169 RESET vector
28170 \end_layout
28171
28172 \end_inset
28173 </cell>
28174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28175 \begin_inset Text
28176
28177 \begin_layout Standard
28178 0x000000
28179 \end_layout
28180
28181 \end_inset
28182 </cell>
28183 </row>
28184 <row topline="true">
28185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28186 \begin_inset Text
28187
28188 \begin_layout Standard
28189
28190 \family roman
28191 \series medium
28192 \shape up
28193 \size normal
28194 \emph off
28195 \bar no
28196 \noun off
28197 \color none
28198 1
28199 \end_layout
28200
28201 \end_inset
28202 </cell>
28203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28204 \begin_inset Text
28205
28206 \begin_layout Standard
28207
28208 \family roman
28209 \series medium
28210 \shape up
28211 \size normal
28212 \emph off
28213 \bar no
28214 \noun off
28215 \color none
28216 HIGH priority interrupts
28217 \end_layout
28218
28219 \end_inset
28220 </cell>
28221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28222 \begin_inset Text
28223
28224 \begin_layout Standard
28225 0x000008
28226 \end_layout
28227
28228 \end_inset
28229 </cell>
28230 </row>
28231 <row topline="true" bottomline="true">
28232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28233 \begin_inset Text
28234
28235 \begin_layout Standard
28236 2
28237 \end_layout
28238
28239 \end_inset
28240 </cell>
28241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28242 \begin_inset Text
28243
28244 \begin_layout Standard
28245 LOW priority interrupts
28246 \end_layout
28247
28248 \end_inset
28249 </cell>
28250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28251 \begin_inset Text
28252
28253 \begin_layout Standard
28254 0x000018
28255 \end_layout
28256
28257 \end_inset
28258 </cell>
28259 </row>
28260 </lyxtabular>
28261
28262 \end_inset
28263
28264
28265 \end_layout
28266
28267 \begin_layout Standard
28268 When generating assembly code for ISR the code generator places a 
28269 \noun on
28270 goto 
28271 \noun default
28272 instruction at the 
28273 \emph on
28274 Interrupt Vector Address
28275 \emph default
28276  which points at the generated ISR.
28277  This single GOTO instruction is part of an automatically generated 
28278 \emph on
28279 interrupt entry point
28280 \emph default
28281  function.
28282  The actuall ISR code is placed as normally would in the code space.
28283  Upon interrupt request, the GOTO instruction is executed which jumps to
28284  the ISR code.
28285  When declaring interrupt functions as _naked this GOTO instruction is 
28286 \series bold
28287 not
28288 \series default
28289  generated.
28290  The whole interrupt functions is therefore placed at the Interrupt Vector
28291  Address of the specific interrupt.
28292  This is not a problem for the LOW priority interrupts, but it is a problem
28293  for the RESET and the HIGH priority interrupts because code may be written
28294  at the next interrupt's vector address and cause indeterminate program
28295  behaviour if that interrupt is raised.
28296 \begin_inset Foot
28297 status open
28298
28299 \begin_layout Standard
28300 This is not a problem when
28301 \end_layout
28302
28303 \begin_layout Enumerate
28304 this is a HIGH interrupt ISR and LOW interrupts are 
28305 \emph on
28306 disabled
28307 \emph default
28308  or not used.
28309 \end_layout
28310
28311 \begin_layout Enumerate
28312 when the ISR is small enough not to reach the next interrupt's vector address.
28313 \end_layout
28314
28315 \end_inset
28316
28317
28318 \end_layout
28319
28320 \begin_layout Standard
28321
28322 \emph on
28323 n
28324 \emph default
28325  may be omitted.
28326  This way a function is generated similar to an ISR, but it is not assigned
28327  to any interrupt.
28328 \end_layout
28329
28330 \begin_layout Standard
28331 When entering an interrupt, currently the PIC16
28332 \begin_inset LatexCommand index
28333 name "PIC16"
28334
28335 \end_inset
28336
28337  port automatically saves the following registers:
28338 \end_layout
28339
28340 \begin_layout Itemize
28341 WREG
28342 \end_layout
28343
28344 \begin_layout Itemize
28345 STATUS
28346 \end_layout
28347
28348 \begin_layout Itemize
28349 BSR
28350 \end_layout
28351
28352 \begin_layout Itemize
28353 PROD (PRODL and PRODH)
28354 \end_layout
28355
28356 \begin_layout Itemize
28357 FSR0 (FSR0L and FSR0H)
28358 \end_layout
28359
28360 \begin_layout Standard
28361 These registers are restored upon return from the interrupt routine.
28362 \begin_inset Foot
28363 status open
28364
28365 \begin_layout Standard
28366 NOTE that when the _naked attribute is specified for an interrupt routine,
28367  then NO registers are stored or restored.
28368 \end_layout
28369
28370 \end_inset
28371
28372
28373 \end_layout
28374
28375 \begin_layout Subsection
28376 Generic Pointers
28377 \end_layout
28378
28379 \begin_layout Standard
28380 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28381  There are 3 types of generic pointers currently implemented data, code
28382  and eeprom pointers.
28383  They are differentiated by the value of the 7th and 6th bits of the upper
28384  byte:
28385 \end_layout
28386
28387 \begin_layout Standard
28388 \align center
28389 \begin_inset Tabular
28390 <lyxtabular version="3" rows="5" columns="5">
28391 <features>
28392 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28393 <column alignment="center" valignment="top" width="0">
28394 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28395 <column alignment="center" valignment="top" width="0">
28396 <column alignment="left" valignment="top" rightline="true" width="0">
28397 <row topline="true" bottomline="true">
28398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28399 \begin_inset Text
28400
28401 \begin_layout Standard
28402 pointer type
28403 \end_layout
28404
28405 \end_inset
28406 </cell>
28407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28408 \begin_inset Text
28409
28410 \begin_layout Standard
28411 7th bit
28412 \end_layout
28413
28414 \end_inset
28415 </cell>
28416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28417 \begin_inset Text
28418
28419 \begin_layout Standard
28420 6th bit
28421 \end_layout
28422
28423 \end_inset
28424 </cell>
28425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28426 \begin_inset Text
28427
28428 \begin_layout Standard
28429 rest of the pointer
28430 \end_layout
28431
28432 \end_inset
28433 </cell>
28434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28435 \begin_inset Text
28436
28437 \begin_layout Standard
28438 description
28439 \end_layout
28440
28441 \end_inset
28442 </cell>
28443 </row>
28444 <row topline="true" bottomline="true">
28445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28446 \begin_inset Text
28447
28448 \begin_layout Standard
28449 data 
28450 \end_layout
28451
28452 \end_inset
28453 </cell>
28454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28455 \begin_inset Text
28456
28457 \begin_layout Standard
28458 1
28459 \end_layout
28460
28461 \end_inset
28462 </cell>
28463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28464 \begin_inset Text
28465
28466 \begin_layout Standard
28467 0
28468 \end_layout
28469
28470 \end_inset
28471 </cell>
28472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28473 \begin_inset Text
28474
28475 \begin_layout Standard
28476
28477 \family typewriter
28478 \shape slanted
28479 \emph on
28480 uuuuuu uuuuxxxx xxxxxxxx
28481 \end_layout
28482
28483 \end_inset
28484 </cell>
28485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28486 \begin_inset Text
28487
28488 \begin_layout Standard
28489 a 12-bit data pointer in data RAM memory
28490 \end_layout
28491
28492 \end_inset
28493 </cell>
28494 </row>
28495 <row bottomline="true">
28496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28497 \begin_inset Text
28498
28499 \begin_layout Standard
28500 code
28501 \end_layout
28502
28503 \end_inset
28504 </cell>
28505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28506 \begin_inset Text
28507
28508 \begin_layout Standard
28509 0
28510 \end_layout
28511
28512 \end_inset
28513 </cell>
28514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28515 \begin_inset Text
28516
28517 \begin_layout Standard
28518 0
28519 \end_layout
28520
28521 \end_inset
28522 </cell>
28523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28524 \begin_inset Text
28525
28526 \begin_layout Standard
28527
28528 \family typewriter
28529 \shape slanted
28530 \emph on
28531 uxxxxx xxxxxxxx xxxxxxxx
28532 \end_layout
28533
28534 \end_inset
28535 </cell>
28536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28537 \begin_inset Text
28538
28539 \begin_layout Standard
28540 a 21-bit code pointer in FLASH memory
28541 \end_layout
28542
28543 \end_inset
28544 </cell>
28545 </row>
28546 <row bottomline="true">
28547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28548 \begin_inset Text
28549
28550 \begin_layout Standard
28551 eeprom
28552 \end_layout
28553
28554 \end_inset
28555 </cell>
28556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28557 \begin_inset Text
28558
28559 \begin_layout Standard
28560 0
28561 \end_layout
28562
28563 \end_inset
28564 </cell>
28565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28566 \begin_inset Text
28567
28568 \begin_layout Standard
28569 1
28570 \end_layout
28571
28572 \end_inset
28573 </cell>
28574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28575 \begin_inset Text
28576
28577 \begin_layout Standard
28578
28579 \family typewriter
28580 \shape slanted
28581 \emph on
28582 uuuuuu uuuuuuxx xxxxxxxx
28583 \end_layout
28584
28585 \end_inset
28586 </cell>
28587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28588 \begin_inset Text
28589
28590 \begin_layout Standard
28591 a 10-bit eeprom pointer in EEPROM memory
28592 \end_layout
28593
28594 \end_inset
28595 </cell>
28596 </row>
28597 <row bottomline="true">
28598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28599 \begin_inset Text
28600
28601 \begin_layout Standard
28602 (unimplemented)
28603 \end_layout
28604
28605 \end_inset
28606 </cell>
28607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28608 \begin_inset Text
28609
28610 \begin_layout Standard
28611 1
28612 \end_layout
28613
28614 \end_inset
28615 </cell>
28616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28617 \begin_inset Text
28618
28619 \begin_layout Standard
28620 1
28621 \end_layout
28622
28623 \end_inset
28624 </cell>
28625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28626 \begin_inset Text
28627
28628 \begin_layout Standard
28629
28630 \family typewriter
28631 \shape slanted
28632 \emph on
28633 xxxxxx xxxxxxxx xxxxxxxx
28634 \end_layout
28635
28636 \end_inset
28637 </cell>
28638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28639 \begin_inset Text
28640
28641 \begin_layout Standard
28642 unimplemented pointer type
28643 \end_layout
28644
28645 \end_inset
28646 </cell>
28647 </row>
28648 </lyxtabular>
28649
28650 \end_inset
28651
28652
28653 \end_layout
28654
28655 \begin_layout Standard
28656 \noindent
28657 Generic pointer are read and written with a set of library functions which
28658  read/write 1, 2, 3, 4 bytes.
28659 \end_layout
28660
28661 \begin_layout Subsection
28662 PIC16 C Libraries
28663 \end_layout
28664
28665 \begin_layout Subsubsection
28666 Standard I/O Streams
28667 \end_layout
28668
28669 \begin_layout Standard
28670 In the 
28671 \emph on
28672 stdio.h
28673 \emph default
28674  the type FILE is defined as:
28675 \end_layout
28676
28677 \begin_layout LyX-Code
28678 typedef char * FILE;
28679 \end_layout
28680
28681 \begin_layout Standard
28682 This type is the stream type implemented I/O in the PIC18F devices.
28683  Also the standard input and output streams are declared in stdio.h:
28684 \end_layout
28685
28686 \begin_layout LyX-Code
28687 extern FILE * stdin;
28688 \end_layout
28689
28690 \begin_layout LyX-Code
28691 extern FILE * stdout;
28692 \end_layout
28693
28694 \begin_layout Standard
28695 The FILE type is actually a generic pointer which defines one more type
28696  of generic pointers, the 
28697 \emph on
28698 stream
28699 \emph default
28700  pointer.
28701  This new type has the format:
28702 \end_layout
28703
28704 \begin_layout Standard
28705 \noindent
28706 \align center
28707 \begin_inset Tabular
28708 <lyxtabular version="3" rows="2" columns="7">
28709 <features>
28710 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28711 <column alignment="center" valignment="top" width="0">
28712 <column alignment="center" valignment="top" leftline="true" width="0">
28713 <column alignment="center" valignment="top" leftline="true" width="0">
28714 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28715 <column alignment="center" valignment="top" width="0">
28716 <column alignment="left" valignment="top" rightline="true" width="0">
28717 <row topline="true" bottomline="true">
28718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28719 \begin_inset Text
28720
28721 \begin_layout Standard
28722 pointer type
28723 \end_layout
28724
28725 \end_inset
28726 </cell>
28727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28728 \begin_inset Text
28729
28730 \begin_layout Standard
28731 <7:6>
28732 \end_layout
28733
28734 \end_inset
28735 </cell>
28736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28737 \begin_inset Text
28738
28739 \begin_layout Standard
28740 <5>
28741 \end_layout
28742
28743 \end_inset
28744 </cell>
28745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28746 \begin_inset Text
28747
28748 \begin_layout Standard
28749 <4>
28750 \end_layout
28751
28752 \end_inset
28753 </cell>
28754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28755 \begin_inset Text
28756
28757 \begin_layout Standard
28758 <3:0>
28759 \end_layout
28760
28761 \end_inset
28762 </cell>
28763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28764 \begin_inset Text
28765
28766 \begin_layout Standard
28767 rest of the pointer
28768 \end_layout
28769
28770 \end_inset
28771 </cell>
28772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28773 \begin_inset Text
28774
28775 \begin_layout Standard
28776 descrption
28777 \end_layout
28778
28779 \end_inset
28780 </cell>
28781 </row>
28782 <row topline="true" bottomline="true">
28783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28784 \begin_inset Text
28785
28786 \begin_layout Standard
28787 stream
28788 \end_layout
28789
28790 \end_inset
28791 </cell>
28792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28793 \begin_inset Text
28794
28795 \begin_layout Standard
28796 00
28797 \end_layout
28798
28799 \end_inset
28800 </cell>
28801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28802 \begin_inset Text
28803
28804 \begin_layout Standard
28805 1
28806 \end_layout
28807
28808 \end_inset
28809 </cell>
28810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28811 \begin_inset Text
28812
28813 \begin_layout Standard
28814 0
28815 \end_layout
28816
28817 \end_inset
28818 </cell>
28819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28820 \begin_inset Text
28821
28822 \begin_layout Standard
28823 nnnn
28824 \end_layout
28825
28826 \end_inset
28827 </cell>
28828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28829 \begin_inset Text
28830
28831 \begin_layout Standard
28832
28833 \family typewriter
28834 \shape slanted
28835 \emph on
28836 uuuuuuuu uuuuuuuu
28837 \end_layout
28838
28839 \end_inset
28840 </cell>
28841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28842 \begin_inset Text
28843
28844 \begin_layout Standard
28845 upper byte high nubble is 0x2n, the rest are zeroes
28846 \end_layout
28847
28848 \end_inset
28849 </cell>
28850 </row>
28851 </lyxtabular>
28852
28853 \end_inset
28854
28855
28856 \end_layout
28857
28858 \begin_layout Standard
28859 \noindent
28860 Currently implemented there are 3 types of streams defined:
28861 \end_layout
28862
28863 \begin_layout Standard
28864 \noindent
28865 \align center
28866 \begin_inset Tabular
28867 <lyxtabular version="3" rows="4" columns="4">
28868 <features>
28869 <column alignment="center" valignment="top" leftline="true" width="0">
28870 <column alignment="center" valignment="top" leftline="true" width="0">
28871 <column alignment="center" valignment="top" leftline="true" width="0">
28872 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28873 <row topline="true" bottomline="true">
28874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28875 \begin_inset Text
28876
28877 \begin_layout Standard
28878 stream type
28879 \end_layout
28880
28881 \end_inset
28882 </cell>
28883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28884 \begin_inset Text
28885
28886 \begin_layout Standard
28887 value
28888 \end_layout
28889
28890 \end_inset
28891 </cell>
28892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28893 \begin_inset Text
28894
28895 \begin_layout Standard
28896 module
28897 \end_layout
28898
28899 \end_inset
28900 </cell>
28901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28902 \begin_inset Text
28903
28904 \begin_layout Standard
28905 description
28906 \end_layout
28907
28908 \end_inset
28909 </cell>
28910 </row>
28911 <row topline="true">
28912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28913 \begin_inset Text
28914
28915 \begin_layout Standard
28916 STREAM_USART
28917 \end_layout
28918
28919 \end_inset
28920 </cell>
28921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28922 \begin_inset Text
28923
28924 \begin_layout Standard
28925
28926 \family typewriter
28927 0x200000UL
28928 \end_layout
28929
28930 \end_inset
28931 </cell>
28932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28933 \begin_inset Text
28934
28935 \begin_layout Standard
28936 USART
28937 \end_layout
28938
28939 \end_inset
28940 </cell>
28941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28942 \begin_inset Text
28943
28944 \begin_layout Standard
28945 Writes/Reads characters via the USART peripheral
28946 \end_layout
28947
28948 \end_inset
28949 </cell>
28950 </row>
28951 <row topline="true">
28952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28953 \begin_inset Text
28954
28955 \begin_layout Standard
28956 STREAM_MSSP
28957 \end_layout
28958
28959 \end_inset
28960 </cell>
28961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28962 \begin_inset Text
28963
28964 \begin_layout Standard
28965
28966 \family typewriter
28967 0x210000UL
28968 \end_layout
28969
28970 \end_inset
28971 </cell>
28972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28973 \begin_inset Text
28974
28975 \begin_layout Standard
28976 MSSP
28977 \end_layout
28978
28979 \end_inset
28980 </cell>
28981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28982 \begin_inset Text
28983
28984 \begin_layout Standard
28985 Writes/Reads characters via the MSSP peripheral
28986 \end_layout
28987
28988 \end_inset
28989 </cell>
28990 </row>
28991 <row topline="true" bottomline="true">
28992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28993 \begin_inset Text
28994
28995 \begin_layout Standard
28996 STREAM_USER
28997 \end_layout
28998
28999 \end_inset
29000 </cell>
29001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29002 \begin_inset Text
29003
29004 \begin_layout Standard
29005
29006 \family typewriter
29007 0x2f0000UL
29008 \end_layout
29009
29010 \end_inset
29011 </cell>
29012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29013 \begin_inset Text
29014
29015 \begin_layout Standard
29016 (none)
29017 \end_layout
29018
29019 \end_inset
29020 </cell>
29021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29022 \begin_inset Text
29023
29024 \begin_layout Standard
29025 Writes/Reads characters via used defined functions
29026 \end_layout
29027
29028 \end_inset
29029 </cell>
29030 </row>
29031 </lyxtabular>
29032
29033 \end_inset
29034
29035
29036 \end_layout
29037
29038 \begin_layout Standard
29039 \noindent
29040 The stream identifiers are declared as macros in the stdio.h header.
29041 \end_layout
29042
29043 \begin_layout Standard
29044 \noindent
29045 In the libc library there exist the functions that are used to write to
29046  each of the above streams.
29047  These are
29048 \end_layout
29049
29050 \begin_layout Description
29051 _
29052 \begin_inset ERT
29053 status collapsed
29054
29055 \begin_layout Standard
29056
29057
29058 \backslash
29059 /
29060 \end_layout
29061
29062 \end_inset
29063
29064 _stream_usart_putchar writes a character at the USART stream
29065 \end_layout
29066
29067 \begin_layout Description
29068 _
29069 \begin_inset ERT
29070 status collapsed
29071
29072 \begin_layout Standard
29073
29074
29075 \backslash
29076 /
29077 \end_layout
29078
29079 \end_inset
29080
29081 _stream_mssp_putchar writes a character at the MSSP stream
29082 \end_layout
29083
29084 \begin_layout Description
29085 putchar dummy function.
29086  This writes a character to a user specified manner.
29087 \end_layout
29088
29089 \begin_layout Standard
29090 In order to increase performance 
29091 \emph on
29092 putchar
29093 \emph default
29094  is declared in stdio.h as having its parameter in WREG (it has the wparam
29095  keyword).
29096  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29097  in a user-friendly way.
29098  
29099 \emph on
29100 arg
29101 \emph default
29102  is the name of the variable that holds the character to print.
29103  An example follows:
29104 \end_layout
29105
29106 \begin_layout LyX-Code
29107 #include <pic18fregs.h>
29108 \newline
29109 #include <stdio.h>
29110 \newline
29111
29112 \newline
29113 PUTCHAR( c )
29114 \end_layout
29115
29116 \begin_layout LyX-Code
29117 {
29118 \end_layout
29119
29120 \begin_layout LyX-Code
29121     PORTA = c;    /* dump character c to PORTA */
29122 \end_layout
29123
29124 \begin_layout LyX-Code
29125
29126 \newline
29127
29128 \newline
29129 void main(void)
29130 \end_layout
29131
29132 \begin_layout LyX-Code
29133 {
29134 \end_layout
29135
29136 \begin_layout LyX-Code
29137     stdout = STREAM_USER;    /* this is not necessary, since stdout points
29138 \end_layout
29139
29140 \begin_layout LyX-Code
29141                               * by default to STREAM_USER */
29142 \end_layout
29143
29144 \begin_layout LyX-Code
29145     printf (
29146 \begin_inset Quotes sld
29147 \end_inset
29148
29149 This is a printf test
29150 \backslash
29151 n
29152 \begin_inset Quotes srd
29153 \end_inset
29154
29155 );
29156 \end_layout
29157
29158 \begin_layout LyX-Code
29159 }
29160 \end_layout
29161
29162 \begin_layout LyX-Code
29163
29164 \end_layout
29165
29166 \begin_layout Subsubsection
29167 Printing functions
29168 \end_layout
29169
29170 \begin_layout Standard
29171 PIC16 contains an implementation of the printf-family of functions.
29172  There exist the following functions:
29173 \end_layout
29174
29175 \begin_layout LyX-Code
29176 extern unsigned int sprintf(char *buf, char *fmt, ...);
29177 \end_layout
29178
29179 \begin_layout LyX-Code
29180 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29181 \end_layout
29182
29183 \begin_layout LyX-Code
29184
29185 \end_layout
29186
29187 \begin_layout LyX-Code
29188 extern unsigned int printf(char *fmt, ...);
29189 \end_layout
29190
29191 \begin_layout LyX-Code
29192 extern unsigned int vprintf(char *fmt, va_lista ap);
29193 \end_layout
29194
29195 \begin_layout LyX-Code
29196
29197 \end_layout
29198
29199 \begin_layout LyX-Code
29200 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29201 \end_layout
29202
29203 \begin_layout LyX-Code
29204 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29205 \end_layout
29206
29207 \begin_layout Standard
29208 For sprintf and vsprintf 
29209 \emph on
29210 buf
29211 \emph default
29212  should normally be a data pointer where the resulting string will be placed.
29213  No range checking is done so the user should allocate the necessary buffer.
29214  For fprintf and vfprintf 
29215 \emph on
29216 fp
29217 \emph default
29218  should be a stream pointer (i.e.
29219  stdout, STREAM_MSSP, etc...).
29220 \end_layout
29221
29222 \begin_layout Subsubsection
29223 Signals
29224 \end_layout
29225
29226 \begin_layout Standard
29227 The PIC18F family of microcontrollers supports a number of interrupt sources.
29228  A list of these interrupts is shown in the following table:
29229 \end_layout
29230
29231 \begin_layout Standard
29232 \align center
29233 \begin_inset Tabular
29234 <lyxtabular version="3" rows="11" columns="4">
29235 <features>
29236 <column alignment="left" valignment="top" leftline="true" width="0">
29237 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29238 <column alignment="left" valignment="top" leftline="true" width="0">
29239 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29240 <row topline="true" bottomline="true">
29241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29242 \begin_inset Text
29243
29244 \begin_layout Standard
29245 signal name
29246 \end_layout
29247
29248 \end_inset
29249 </cell>
29250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29251 \begin_inset Text
29252
29253 \begin_layout Standard
29254 description
29255 \end_layout
29256
29257 \end_inset
29258 </cell>
29259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29260 \begin_inset Text
29261
29262 \begin_layout Standard
29263 signal name
29264 \end_layout
29265
29266 \end_inset
29267 </cell>
29268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29269 \begin_inset Text
29270
29271 \begin_layout Standard
29272 description
29273 \end_layout
29274
29275 \end_inset
29276 </cell>
29277 </row>
29278 <row topline="true">
29279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29280 \begin_inset Text
29281
29282 \begin_layout Standard
29283 SIG_RB
29284 \end_layout
29285
29286 \end_inset
29287 </cell>
29288 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29289 \begin_inset Text
29290
29291 \begin_layout Standard
29292 PORTB change interrupt
29293 \end_layout
29294
29295 \end_inset
29296 </cell>
29297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29298 \begin_inset Text
29299
29300 \begin_layout Standard
29301 SIG_EE
29302 \end_layout
29303
29304 \end_inset
29305 </cell>
29306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29307 \begin_inset Text
29308
29309 \begin_layout Standard
29310 EEPROM/FLASH write complete interrupt
29311 \end_layout
29312
29313 \end_inset
29314 </cell>
29315 </row>
29316 <row topline="true">
29317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29318 \begin_inset Text
29319
29320 \begin_layout Standard
29321 SIG_INT0
29322 \end_layout
29323
29324 \end_inset
29325 </cell>
29326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29327 \begin_inset Text
29328
29329 \begin_layout Standard
29330 INT0 external interrupt
29331 \end_layout
29332
29333 \end_inset
29334 </cell>
29335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29336 \begin_inset Text
29337
29338 \begin_layout Standard
29339 SIG_BCOL
29340 \end_layout
29341
29342 \end_inset
29343 </cell>
29344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29345 \begin_inset Text
29346
29347 \begin_layout Standard
29348 Bus collision interrupt
29349 \end_layout
29350
29351 \end_inset
29352 </cell>
29353 </row>
29354 <row topline="true">
29355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29356 \begin_inset Text
29357
29358 \begin_layout Standard
29359 SIG_INT1
29360 \end_layout
29361
29362 \end_inset
29363 </cell>
29364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29365 \begin_inset Text
29366
29367 \begin_layout Standard
29368 INT1 external interrupt
29369 \end_layout
29370
29371 \end_inset
29372 </cell>
29373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29374 \begin_inset Text
29375
29376 \begin_layout Standard
29377 SIG_LVD
29378 \end_layout
29379
29380 \end_inset
29381 </cell>
29382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29383 \begin_inset Text
29384
29385 \begin_layout Standard
29386 Low voltage detect interrupt
29387 \end_layout
29388
29389 \end_inset
29390 </cell>
29391 </row>
29392 <row topline="true">
29393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29394 \begin_inset Text
29395
29396 \begin_layout Standard
29397 SIG_INT2
29398 \end_layout
29399
29400 \end_inset
29401 </cell>
29402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29403 \begin_inset Text
29404
29405 \begin_layout Standard
29406 INT2 external interrupt
29407 \end_layout
29408
29409 \end_inset
29410 </cell>
29411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29412 \begin_inset Text
29413
29414 \begin_layout Standard
29415 SIG_PSP
29416 \end_layout
29417
29418 \end_inset
29419 </cell>
29420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29421 \begin_inset Text
29422
29423 \begin_layout Standard
29424 Parallel slave port interrupt
29425 \end_layout
29426
29427 \end_inset
29428 </cell>
29429 </row>
29430 <row topline="true">
29431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29432 \begin_inset Text
29433
29434 \begin_layout Standard
29435 SIG_CCP1
29436 \end_layout
29437
29438 \end_inset
29439 </cell>
29440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29441 \begin_inset Text
29442
29443 \begin_layout Standard
29444 CCP1 module interrupt
29445 \end_layout
29446
29447 \end_inset
29448 </cell>
29449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29450 \begin_inset Text
29451
29452 \begin_layout Standard
29453 SIG_AD
29454 \end_layout
29455
29456 \end_inset
29457 </cell>
29458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29459 \begin_inset Text
29460
29461 \begin_layout Standard
29462 AD convertion complete interrupt
29463 \end_layout
29464
29465 \end_inset
29466 </cell>
29467 </row>
29468 <row topline="true">
29469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29470 \begin_inset Text
29471
29472 \begin_layout Standard
29473 SIG_CCP2
29474 \end_layout
29475
29476 \end_inset
29477 </cell>
29478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29479 \begin_inset Text
29480
29481 \begin_layout Standard
29482 CCP2 module interrupt
29483 \end_layout
29484
29485 \end_inset
29486 </cell>
29487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29488 \begin_inset Text
29489
29490 \begin_layout Standard
29491 SIG_RC
29492 \end_layout
29493
29494 \end_inset
29495 </cell>
29496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29497 \begin_inset Text
29498
29499 \begin_layout Standard
29500 USART receive interrupt
29501 \end_layout
29502
29503 \end_inset
29504 </cell>
29505 </row>
29506 <row topline="true">
29507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29508 \begin_inset Text
29509
29510 \begin_layout Standard
29511 SIG_TMR0
29512 \end_layout
29513
29514 \end_inset
29515 </cell>
29516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29517 \begin_inset Text
29518
29519 \begin_layout Standard
29520 TMR0 overflow interrupt
29521 \end_layout
29522
29523 \end_inset
29524 </cell>
29525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29526 \begin_inset Text
29527
29528 \begin_layout Standard
29529 SIG_TX
29530 \end_layout
29531
29532 \end_inset
29533 </cell>
29534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29535 \begin_inset Text
29536
29537 \begin_layout Standard
29538 USART transmit interrupt
29539 \end_layout
29540
29541 \end_inset
29542 </cell>
29543 </row>
29544 <row topline="true">
29545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29546 \begin_inset Text
29547
29548 \begin_layout Standard
29549 SIG_TMR1
29550 \end_layout
29551
29552 \end_inset
29553 </cell>
29554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29555 \begin_inset Text
29556
29557 \begin_layout Standard
29558 TMR1 overflow interrupt
29559 \end_layout
29560
29561 \end_inset
29562 </cell>
29563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29564 \begin_inset Text
29565
29566 \begin_layout Standard
29567 SIG_MSSP
29568 \end_layout
29569
29570 \end_inset
29571 </cell>
29572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29573 \begin_inset Text
29574
29575 \begin_layout Standard
29576 SSP receive/transmit interrupt
29577 \end_layout
29578
29579 \end_inset
29580 </cell>
29581 </row>
29582 <row topline="true">
29583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29584 \begin_inset Text
29585
29586 \begin_layout Standard
29587 SIG_TMR2
29588 \end_layout
29589
29590 \end_inset
29591 </cell>
29592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29593 \begin_inset Text
29594
29595 \begin_layout Standard
29596 TMR2 matches PR2 interrupt
29597 \end_layout
29598
29599 \end_inset
29600 </cell>
29601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29602 \begin_inset Text
29603
29604 \begin_layout Standard
29605
29606 \end_layout
29607
29608 \end_inset
29609 </cell>
29610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29611 \begin_inset Text
29612
29613 \begin_layout Standard
29614
29615 \end_layout
29616
29617 \end_inset
29618 </cell>
29619 </row>
29620 <row topline="true" bottomline="true">
29621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29622 \begin_inset Text
29623
29624 \begin_layout Standard
29625 SIG_TMR3
29626 \end_layout
29627
29628 \end_inset
29629 </cell>
29630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29631 \begin_inset Text
29632
29633 \begin_layout Standard
29634 TMR3 overflow interrupt
29635 \end_layout
29636
29637 \end_inset
29638 </cell>
29639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29640 \begin_inset Text
29641
29642 \begin_layout Standard
29643
29644 \end_layout
29645
29646 \end_inset
29647 </cell>
29648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29649 \begin_inset Text
29650
29651 \begin_layout Standard
29652
29653 \end_layout
29654
29655 \end_inset
29656 </cell>
29657 </row>
29658 </lyxtabular>
29659
29660 \end_inset
29661
29662
29663 \end_layout
29664
29665 \begin_layout Standard
29666 \noindent
29667 The prototypes for these names are defined in the header file 
29668 \emph on
29669 signal.h
29670 \emph default
29671  .
29672 \end_layout
29673
29674 \begin_layout Standard
29675 \noindent
29676 In order to simplify signal handling, a number of macros is provided:
29677 \end_layout
29678
29679 \begin_layout List
29680 \labelwidthstring 00.00.0000
29681 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29682  high priority interrupts.
29683  
29684 \emph on
29685 name
29686 \emph default
29687  is the function name to use.
29688 \end_layout
29689
29690 \begin_layout List
29691 \labelwidthstring 00.00.0000
29692 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29693  low priority interrupt.
29694  
29695 \emph on
29696 name
29697 \emph default
29698  is the function name to use.
29699 \end_layout
29700
29701 \begin_layout List
29702 \labelwidthstring 00.00.0000
29703 DEF_HANDLER(sig,handler) define a handler for signal 
29704 \emph on
29705 sig.
29706 \end_layout
29707
29708 \begin_layout List
29709 \labelwidthstring 00.00.0000
29710 END_DEF end the declaration of the dispatch table.
29711 \end_layout
29712
29713 \begin_layout Standard
29714 Additionally there are two more macros to simplify the declaration of the
29715  signal handler:
29716 \end_layout
29717
29718 \begin_layout List
29719 \labelwidthstring 00.00.0000
29720
29721 \series medium
29722 SIGHANDLER(handler)
29723 \series default
29724  this declares the function prototype for the 
29725 \emph on
29726 handler
29727 \emph default
29728  function.
29729 \end_layout
29730
29731 \begin_layout List
29732 \labelwidthstring 00.00.0000
29733 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29734 \end_layout
29735
29736 \begin_layout Standard
29737 An example of using the macros above is shown below:
29738 \end_layout
29739
29740 \begin_layout LyX-Code
29741 #include <pic18fregs.h>
29742 \end_layout
29743
29744 \begin_layout LyX-Code
29745 #include <signal.h>
29746 \newline
29747
29748 \newline
29749 DEF_INTHIGH(high_int)
29750 \end_layout
29751
29752 \begin_layout LyX-Code
29753 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
29754 \end_layout
29755
29756 \begin_layout LyX-Code
29757 DEF_HANDLER(SIG_BCOL, _bcol_handler)
29758 \end_layout
29759
29760 \begin_layout LyX-Code
29761 END_DEF
29762 \newline
29763
29764 \newline
29765 SIGHANDLER(_tmr0_handler)
29766 \end_layout
29767
29768 \begin_layout LyX-Code
29769 {
29770 \end_layout
29771
29772 \begin_layout LyX-Code
29773   /* action to be taken when timer 0 overflows */
29774 \end_layout
29775
29776 \begin_layout LyX-Code
29777 }
29778 \newline
29779
29780 \newline
29781 SIGHANDLERNAKED(_bcol_handler)
29782 \end_layout
29783
29784 \begin_layout LyX-Code
29785 {
29786 \end_layout
29787
29788 \begin_layout LyX-Code
29789   _asm
29790 \end_layout
29791
29792 \begin_layout LyX-Code
29793     /* action to be taken when bus collision occurs */
29794 \end_layout
29795
29796 \begin_layout LyX-Code
29797     retfie
29798 \end_layout
29799
29800 \begin_layout LyX-Code
29801  _endasm;
29802 \end_layout
29803
29804 \begin_layout LyX-Code
29805 }
29806 \end_layout
29807
29808 \begin_layout Standard
29809
29810 \series bold
29811 NOTES:
29812 \series default
29813  Special care should be taken when using the above scheme:
29814 \end_layout
29815
29816 \begin_layout Itemize
29817 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
29818 \end_layout
29819
29820 \begin_layout Itemize
29821 when declaring SIGHANDLERNAKED handler never forget to use 
29822 \emph on
29823 retfie
29824 \emph default
29825  for proper returning.
29826 \end_layout
29827
29828 \begin_layout Subsection
29829 PIC16 Port -- Tips
29830 \end_layout
29831
29832 \begin_layout Standard
29833 Here you can find some general tips for compiling programs with SDCC/pic16.
29834 \end_layout
29835
29836 \begin_layout Subsubsection
29837 Stack size
29838 \end_layout
29839
29840 \begin_layout Standard
29841 The default stack
29842 \begin_inset LatexCommand index
29843 name "PIC16!stack"
29844
29845 \end_inset
29846
29847  size (that is 64 bytes) probably is enough for many programs.
29848  One must take care that when there are many levels of function nesting,
29849  or there is excessive usage of stack, its size should be extended.
29850  An example of such a case is the printf/sprintf family of functions.
29851  If you encounter problems like not being able to print integers, then you
29852  need to set the stack size around the maximum (256 for small stack model).
29853  The following diagram shows what happens when calling printf to print an
29854  integer:
29855 \end_layout
29856
29857 \begin_layout LyX-Code
29858 printf () --> ltoa () --> ultoa () --> divschar ()
29859 \end_layout
29860
29861 \begin_layout Standard
29862 It is should be understood that stack is easily consumed when calling complicate
29863 d functions.
29864  Using command line arguments like -
29865 \begin_inset ERT
29866 status collapsed
29867
29868 \begin_layout Standard
29869
29870
29871 \backslash
29872 /
29873 \end_layout
29874
29875 \end_inset
29876
29877 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
29878  stack frames.
29879  Other ways to reduce stack usage may exist.
29880 \end_layout
29881
29882 \begin_layout Subsection
29883 Known Bugs
29884 \end_layout
29885
29886 \begin_layout Subsubsection
29887 Extended Instruction Set
29888 \end_layout
29889
29890 \begin_layout Standard
29891 The PIC16 port emits code which is incompatible with the extended instruction
29892  set available with many newer devices.
29893  Make sure to always explicitly disable it, usually using
29894 \end_layout
29895
29896 \begin_layout Standard
29897
29898 \family typewriter
29899 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
29900 \end_layout
29901
29902 \begin_layout Standard
29903 \noindent
29904 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
29905  instead of _XINST_OFF_4L.
29906 \end_layout
29907
29908 \begin_layout Subsubsection
29909 Regression Tests
29910 \end_layout
29911
29912 \begin_layout Standard
29913 The PIC16 port currently passes most but not all of the tests in SDCC's
29914  regression test
29915 \begin_inset LatexCommand index
29916 name "Regression test (PIC16)"
29917
29918 \end_inset
29919
29920  suite (see section 
29921 \begin_inset LatexCommand ref
29922 reference "sec:Quality-control"
29923
29924 \end_inset
29925
29926 ), thus no automatic regression tests are currently performed for the PIC16
29927  target.
29928 \end_layout
29929
29930 \begin_layout Chapter
29931 Debugging
29932 \end_layout
29933
29934 \begin_layout Standard
29935 There are several approaches to debugging your code.
29936  This chapter is meant to show your options and to give detail on some of
29937  them:
29938 \newline
29939
29940 \newline
29941 When writing your code:
29942 \end_layout
29943
29944 \begin_layout Itemize
29945 write your code with debugging in mind (avoid duplicating code, put conceptually
29946  similar variables into structs, use structured code, have strategic points
29947  within your code where all variables are consistent, ...)
29948 \end_layout
29949
29950 \begin_layout Itemize
29951 run a syntax-checking tool like splint
29952 \begin_inset LatexCommand index
29953 name "splint (syntax checking tool)"
29954
29955 \end_inset
29956
29957
29958 \begin_inset LatexCommand index
29959 name "lint (syntax checking tool)"
29960
29961 \end_inset
29962
29963  (see -
29964 \begin_inset ERT
29965 status collapsed
29966
29967 \begin_layout Standard
29968
29969
29970 \backslash
29971 /
29972 \end_layout
29973
29974 \end_inset
29975
29976 -more-pedantic 
29977 \begin_inset LatexCommand ref
29978 reference "lyx:more-pedantic-SPLINT"
29979
29980 \end_inset
29981
29982 ) over the code.
29983 \end_layout
29984
29985 \begin_layout Itemize
29986 for the high level code use a C-compiler (like f.e.
29987  GCC) to compile run and debug the code on your host.
29988  See (see -
29989 \begin_inset ERT
29990 status collapsed
29991
29992 \begin_layout Standard
29993
29994
29995 \backslash
29996 /
29997 \end_layout
29998
29999 \end_inset
30000
30001 -more-pedantic 
30002 \begin_inset LatexCommand ref
30003 reference "lyx:more-pedantic-SPLINT"
30004
30005 \end_inset
30006
30007 ) on how to handle syntax extensions like __xdata, __at(), ...
30008  
30009 \end_layout
30010
30011 \begin_layout Itemize
30012 use another C-compiler to compile code for your target.
30013  Always an option but not recommended:) And not very likely to help you.
30014  If you seriously consider walking this path you should at least occasionally
30015  check portability of your code.
30016  Most commercial compiler vendors will offer an evaluation version so you
30017  can test compile your code or snippets of your code.
30018 \end_layout
30019
30020 \begin_layout Standard
30021 Debugging on a simulator:
30022 \end_layout
30023
30024 \begin_layout Itemize
30025 there is a separate section about SDCDB (section 
30026 \begin_inset LatexCommand ref
30027 reference "cha:Debugging-with-SDCDB"
30028
30029 \end_inset
30030
30031 ) below.
30032 \end_layout
30033
30034 \begin_layout Itemize
30035 or (8051 specific) use a freeware/commercial simulator which interfaces
30036  to the AOMF
30037 \begin_inset LatexCommand index
30038 name "AOMF, AOMF51"
30039
30040 \end_inset
30041
30042  file (see 
30043 \begin_inset LatexCommand ref
30044 reference "OMF file"
30045
30046 \end_inset
30047
30048 ) optionally generated by SDCC.
30049 \end_layout
30050
30051 \begin_layout Standard
30052 Debugging On-target: 
30053 \end_layout
30054
30055 \begin_layout Itemize
30056 use a MCU port pin to serially output debug data to the RS232 port of your
30057  host.
30058  You'll probably want some level shifting device typically involving a MAX232
30059  or similar IC.
30060  If the hardware serial port of the MCU is not available search for 'Software
30061  UART' in your favourite search machine.
30062 \end_layout
30063
30064 \begin_layout Itemize
30065 use an on-target monitor.
30066  In this context a monitor is a small program which usually accepts commands
30067  via a serial line and allows to set program counter, to single step through
30068  a program and read/write memory locations.
30069  For the 8051 good examples of monitors are paulmon and cmon51 (see section
30070  
30071 \begin_inset LatexCommand ref
30072 reference "sec:Related-open-source-tools"
30073
30074 \end_inset
30075
30076 ).
30077 \end_layout
30078
30079 \begin_layout Itemize
30080 toggle MCU port pins at strategic points within your code and use an oscilloscop
30081 e.
30082  A 
30083 \emph on
30084 digital oscilloscope
30085 \emph default
30086
30087 \begin_inset LatexCommand index
30088 name "Oscilloscope"
30089
30090 \end_inset
30091
30092  with deep trace memory is really helpful especially if you have to debug
30093  a realtime application.
30094  If you need to monitor more pins than your oscilloscope provides you can
30095  sometimes get away with a small R-2R network.
30096  On a single channel oscilloscope you could f.e.
30097  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30098 k
30099 \begin_inset Formula $\Omega$
30100 \end_inset
30101
30102  resistor and the other one by a 5\InsetSpace ~
30103 k
30104 \begin_inset Formula $\Omega$
30105 \end_inset
30106
30107  resistor to the oscilloscope probe (check output drive capability of the
30108  pins you want to monitor).
30109  If you need to monitor many more pins a 
30110 \emph on
30111 logic analyzer
30112 \emph default
30113  will be handy.
30114 \end_layout
30115
30116 \begin_layout Itemize
30117 use an ICE (
30118 \emph on
30119 i
30120 \emph default
30121
30122 \emph on
30123 c
30124 \emph default
30125 ircuit 
30126 \emph on
30127 e
30128 \emph default
30129 mulator
30130 \begin_inset LatexCommand index
30131 name "ICE (in circuit emulator)"
30132
30133 \end_inset
30134
30135 ).
30136  Usually very expensive.
30137  And very nice to have too.
30138  And usually locks you (for years...) to the devices the ICE can emulate.
30139  
30140 \end_layout
30141
30142 \begin_layout Itemize
30143 use a remote debugger.
30144  In most 8-bit systems the symbol information is not available on the target,
30145  and a complete debugger is too bulky for the target system.
30146  Therefore usually a debugger on the host system connects to an on-target
30147  debugging stub which accepts only primitive commands.
30148  
30149 \newline
30150 Terms to enter into your favourite search engine could be 'remote debugging',
30151  'gdb stub' or 'inferior debugger'.
30152  (is there one?)
30153 \end_layout
30154
30155 \begin_layout Itemize
30156 use an on target hardware debugger.
30157  Some of the more modern MCUs include hardware support for setting break
30158  points and monitoring/changing variables by using dedicated hardware pins.
30159  This facility doesn't require additional code to run on the target and
30160  
30161 \emph on
30162 usually
30163 \emph default
30164  doesn't affect runtime behaviour until a breakpoint is hit.
30165  For the mcs51 most hardware debuggers use the AOMF
30166 \begin_inset LatexCommand index
30167 name "AOMF, AOMF51"
30168
30169 \end_inset
30170
30171  file (see 
30172 \begin_inset LatexCommand ref
30173 reference "OMF file"
30174
30175 \end_inset
30176
30177 ) as input file.
30178  
30179 \end_layout
30180
30181 \begin_layout Standard
30182 Last not least:
30183 \end_layout
30184
30185 \begin_layout Itemize
30186 if you are not familiar with any of the following terms you're likely to
30187  run into problems rather sooner than later: 
30188 \emph on
30189 volatile
30190 \emph default
30191
30192 \emph on
30193 atomic
30194 \emph default
30195
30196 \emph on
30197 memory map
30198 \emph default
30199
30200 \emph on
30201 overlay
30202 \emph default
30203 .
30204  As an embedded programmer you 
30205 \emph on
30206 have
30207 \emph default
30208  to know them so why not look them up 
30209 \emph on
30210 before
30211 \emph default
30212  you have problems?)
30213 \end_layout
30214
30215 \begin_layout Itemize
30216 tell someone else about your problem (actually this is a surprisingly effective
30217  means to hunt down the bug even if the listener is not familiar with your
30218  environment).
30219  As 'failure to communicate' is probably one of the job-induced deformations
30220  of an embedded programmer this is highly encouraged.
30221 \end_layout
30222
30223 \begin_layout Section
30224 Debugging with SDCDB
30225 \begin_inset LatexCommand label
30226 name "cha:Debugging-with-SDCDB"
30227
30228 \end_inset
30229
30230
30231 \begin_inset LatexCommand index
30232 name "SDCDB (debugger)"
30233
30234 \end_inset
30235
30236  
30237 \end_layout
30238
30239 \begin_layout Standard
30240 SDCC is distributed with a source level debugger
30241 \begin_inset LatexCommand index
30242 name "Debugger"
30243
30244 \end_inset
30245
30246 .
30247  The debugger uses a command line interface, the command repertoire of the
30248  debugger has been kept as close to gdb
30249 \begin_inset LatexCommand index
30250 name "gdb"
30251
30252 \end_inset
30253
30254  (the GNU debugger) as possible.
30255  The configuration and build process is part of the standard compiler installati
30256 on, which also builds and installs the debugger in the target directory
30257  specified during configuration.
30258  The debugger allows you debug BOTH at the C source and at the ASM source
30259  level.
30260 \end_layout
30261
30262 \begin_layout Subsection
30263 Compiling for Debugging
30264 \end_layout
30265
30266 \begin_layout Standard
30267 The -
30268 \begin_inset ERT
30269 status collapsed
30270
30271 \begin_layout Standard
30272
30273
30274 \backslash
30275 /
30276 \end_layout
30277
30278 \end_inset
30279
30280 -debug
30281 \begin_inset LatexCommand index
30282 name "-\\/-debug"
30283
30284 \end_inset
30285
30286  option must be specified for all files for which debug information is to
30287  be generated.
30288  The compiler generates a .adb file for each of these files.
30289  The linker creates the .cdb
30290 \begin_inset LatexCommand index
30291 name "<file>.cdb"
30292
30293 \end_inset
30294
30295  file from the .adb
30296 \begin_inset LatexCommand index
30297 name "<file>.adb"
30298
30299 \end_inset
30300
30301  files and the address information.
30302  This .cdb is used by the debugger.
30303 \end_layout
30304
30305 \begin_layout Subsection
30306 How the Debugger Works
30307 \end_layout
30308
30309 \begin_layout Standard
30310 When the -
30311 \begin_inset ERT
30312 status collapsed
30313
30314 \begin_layout Standard
30315
30316
30317 \backslash
30318 /
30319 \end_layout
30320
30321 \end_inset
30322
30323 -debug option is specified the compiler generates extra symbol information
30324  some of which are put into the assembler source and some are put into the
30325  .adb file.
30326  Then the linker creates the .cdb file from the individual .adb files with
30327  the address information for the symbols.
30328  The debugger reads the symbolic information generated by the compiler &
30329  the address information generated by the linker.
30330  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30331  execution is controlled by the debugger.
30332  When a command is issued for the debugger, it translates it into appropriate
30333  commands for the simulator.
30334  (Currently SDCDM only connects to the simulator but 
30335 \emph on
30336 newcdb
30337 \emph default
30338  at 
30339 \begin_inset LatexCommand url
30340 target "http://ec2drv.sf.net/"
30341
30342 \end_inset
30343
30344  is an effort to connect directly to the hardware.) 
30345 \end_layout
30346
30347 \begin_layout Subsection
30348 Starting the Debugger SDCDB
30349 \end_layout
30350
30351 \begin_layout Standard
30352 The debugger can be started using the following command line.
30353  (Assume the file you are debugging has the file name foo).
30354 \newline
30355
30356 \newline
30357
30358 \family sans
30359 \series bold
30360 sdcdb foo
30361 \newline
30362
30363 \family default
30364 \series default
30365
30366 \newline
30367 The debugger will look for the following files.
30368 \end_layout
30369
30370 \begin_layout Itemize
30371 foo.c - the source file.
30372 \end_layout
30373
30374 \begin_layout Itemize
30375 foo.cdb - the debugger symbol information file.
30376 \end_layout
30377
30378 \begin_layout Itemize
30379 foo.ihx - the Intel hex format
30380 \begin_inset LatexCommand index
30381 name "Intel hex format"
30382
30383 \end_inset
30384
30385  object file.
30386 \end_layout
30387
30388 \begin_layout Subsection
30389 SDCDB Command Line Options
30390 \end_layout
30391
30392 \begin_layout Itemize
30393 -
30394 \begin_inset ERT
30395 status collapsed
30396
30397 \begin_layout Standard
30398
30399
30400 \backslash
30401 /
30402 \end_layout
30403
30404 \end_inset
30405
30406 -directory=<source file directory> this option can used to specify the directory
30407  search list.
30408  The debugger will look into the directory list specified for source, cdb
30409  & ihx files.
30410  The items in the directory list must be separated by ':', e.g.
30411  if the source files can be in the directories /home/src1 and /home/src2,
30412  the -
30413 \begin_inset ERT
30414 status collapsed
30415
30416 \begin_layout Standard
30417
30418
30419 \backslash
30420 /
30421 \end_layout
30422
30423 \end_inset
30424
30425 -directory option should be -
30426 \begin_inset ERT
30427 status collapsed
30428
30429 \begin_layout Standard
30430
30431
30432 \backslash
30433 /
30434 \end_layout
30435
30436 \end_inset
30437
30438 -directory=/home/src1:/home/src2.
30439  Note there can be no spaces in the option.
30440  
30441 \end_layout
30442
30443 \begin_layout Itemize
30444 -cd <directory> - change to the <directory>.
30445 \end_layout
30446
30447 \begin_layout Itemize
30448 -fullname - used by GUI front ends.
30449 \end_layout
30450
30451 \begin_layout Itemize
30452 -cpu <cpu-type> - this argument is passed to the simulator please see the
30453  simulator docs for details.
30454 \end_layout
30455
30456 \begin_layout Itemize
30457 -X <Clock frequency > this options is passed to the simulator please see
30458  the simulator docs for details.
30459 \end_layout
30460
30461 \begin_layout Itemize
30462 -s <serial port file> passed to simulator see the simulator docs for details.
30463 \end_layout
30464
30465 \begin_layout Itemize
30466 -S <serial in,out> passed to simulator see the simulator docs for details.
30467 \end_layout
30468
30469 \begin_layout Itemize
30470 -k <port number> passed to simulator see the simulator docs for details.
30471 \end_layout
30472
30473 \begin_layout Subsection
30474 SDCDB Debugger Commands
30475 \end_layout
30476
30477 \begin_layout Standard
30478 As mentioned earlier the command interface for the debugger has been deliberatel
30479 y kept as close the GNU debugger gdb, as possible.
30480  This will help the integration with existing graphical user interfaces
30481  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30482  If you use a graphical user interface for the debugger you can skip this
30483  section.
30484 \end_layout
30485
30486 \begin_layout Subsubsection*
30487 break [line | file:line | function | file:function]
30488 \end_layout
30489
30490 \begin_layout Standard
30491 Set breakpoint at specified line or function:
30492 \newline
30493
30494 \newline
30495
30496 \family sans
30497 \series bold
30498 sdcdb>break 100 
30499 \newline
30500 sdcdb>break foo.c:100
30501 \newline
30502 sdcdb>break funcfoo
30503 \newline
30504 sdcdb>break foo.c:funcfoo
30505 \end_layout
30506
30507 \begin_layout Subsubsection*
30508 clear [line | file:line | function | file:function ]
30509 \end_layout
30510
30511 \begin_layout Standard
30512 Clear breakpoint at specified line or function:
30513 \newline
30514
30515 \newline
30516
30517 \family sans
30518 \series bold
30519 sdcdb>clear 100
30520 \newline
30521 sdcdb>clear foo.c:100
30522 \newline
30523 sdcdb>clear funcfoo
30524 \newline
30525 sdcdb>clear foo.c:funcfoo
30526 \end_layout
30527
30528 \begin_layout Subsubsection*
30529 continue
30530 \end_layout
30531
30532 \begin_layout Standard
30533 Continue program being debugged, after breakpoint.
30534 \end_layout
30535
30536 \begin_layout Subsubsection*
30537 finish
30538 \end_layout
30539
30540 \begin_layout Standard
30541 Execute till the end of the current function.
30542 \end_layout
30543
30544 \begin_layout Subsubsection*
30545 delete [n]
30546 \end_layout
30547
30548 \begin_layout Standard
30549 Delete breakpoint number 'n'.
30550  If used without any option clear ALL user defined break points.
30551 \end_layout
30552
30553 \begin_layout Subsubsection*
30554 info [break | stack | frame | registers ]
30555 \end_layout
30556
30557 \begin_layout Itemize
30558 info break - list all breakpoints
30559 \end_layout
30560
30561 \begin_layout Itemize
30562 info stack - show the function call stack.
30563 \end_layout
30564
30565 \begin_layout Itemize
30566 info frame - show information about the current execution frame.
30567 \end_layout
30568
30569 \begin_layout Itemize
30570 info registers - show content of all registers.
30571 \end_layout
30572
30573 \begin_layout Subsubsection*
30574 step
30575 \end_layout
30576
30577 \begin_layout Standard
30578 Step program until it reaches a different source line.
30579  Note: pressing <return> repeats the last command.
30580 \end_layout
30581
30582 \begin_layout Subsubsection*
30583 next
30584 \end_layout
30585
30586 \begin_layout Standard
30587 Step program, proceeding through subroutine calls.
30588 \end_layout
30589
30590 \begin_layout Subsubsection*
30591 run
30592 \end_layout
30593
30594 \begin_layout Standard
30595 Start debugged program.
30596 \end_layout
30597
30598 \begin_layout Subsubsection*
30599 ptype variable 
30600 \end_layout
30601
30602 \begin_layout Standard
30603 Print type information of the variable.
30604 \end_layout
30605
30606 \begin_layout Subsubsection*
30607 print variable
30608 \end_layout
30609
30610 \begin_layout Standard
30611 print value of variable.
30612 \end_layout
30613
30614 \begin_layout Subsubsection*
30615 file filename
30616 \end_layout
30617
30618 \begin_layout Standard
30619 load the given file name.
30620  Note this is an alternate method of loading file for debugging.
30621 \end_layout
30622
30623 \begin_layout Subsubsection*
30624 frame
30625 \end_layout
30626
30627 \begin_layout Standard
30628 print information about current frame.
30629 \end_layout
30630
30631 \begin_layout Subsubsection*
30632 set srcmode
30633 \end_layout
30634
30635 \begin_layout Standard
30636 Toggle between C source & assembly source.
30637 \end_layout
30638
30639 \begin_layout Subsubsection*
30640 ! simulator command
30641 \end_layout
30642
30643 \begin_layout Standard
30644 Send the string following '!' to the simulator, the simulator response is
30645  displayed.
30646  Note the debugger does not interpret the command being sent to the simulator,
30647  so if a command like 'go' is sent the debugger can loose its execution
30648  context and may display incorrect values.
30649 \end_layout
30650
30651 \begin_layout Subsubsection*
30652 quit
30653 \end_layout
30654
30655 \begin_layout Standard
30656 "Watch me now.
30657  Iam going Down.
30658  My name is Bobby Brown"
30659 \end_layout
30660
30661 \begin_layout Subsection
30662 Interfacing SDCDB with DDD
30663 \end_layout
30664
30665 \begin_layout Standard
30666 \begin_inset Note Note
30667 status collapsed
30668
30669 \begin_layout Standard
30670 The screenshot was converted from png to eps with: 
30671 \begin_inset Quotes sld
30672 \end_inset
30673
30674 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30675 \begin_inset Quotes srd
30676 \end_inset
30677
30678  which produces a pretty compact eps file which is free from compression
30679  artifacts.
30680 \end_layout
30681
30682 \begin_layout Standard
30683 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30684  as this broke the build system on Sourceforge (pdf-file was broken.
30685  pdflatex does not accept eps files).
30686 \end_layout
30687
30688 \end_inset
30689
30690
30691 \end_layout
30692
30693 \begin_layout Standard
30694 The 
30695 \emph on
30696 p
30697 \emph default
30698 ortable 
30699 \emph on
30700 n
30701 \emph default
30702 etwork 
30703 \emph on
30704 g
30705 \emph default
30706 raphics File 
30707 \size footnotesize
30708
30709 \begin_inset LatexCommand url
30710 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30711
30712 \end_inset
30713
30714
30715 \size default
30716  shows a screenshot of a debugging session with DDD
30717 \begin_inset LatexCommand index
30718 name "DDD (debugger)"
30719
30720 \end_inset
30721
30722  (Unix only) on a simulated 8032.
30723  The debugging session might not run as smoothly as the screenshot suggests.
30724  The debugger allows setting of breakpoints, displaying and changing variables,
30725  single stepping through C and assembler code.
30726  
30727 \newline
30728 The source was compiled with 
30729 \family sans
30730 \series bold
30731
30732 \newline
30733
30734 \newline
30735 sdcc -
30736 \family default
30737 \series default
30738
30739 \begin_inset ERT
30740 status collapsed
30741
30742 \begin_layout Standard
30743
30744
30745 \backslash
30746 /
30747 \end_layout
30748
30749 \end_inset
30750
30751
30752 \family sans
30753 \series bold
30754 -debug ddd_example.c
30755 \family default
30756 \series default
30757  
30758 \family sans
30759 \series bold
30760
30761 \newline
30762
30763 \family default
30764 \series default
30765
30766 \newline
30767 and DDD was invoked with 
30768 \family sans
30769 \series bold
30770
30771 \newline
30772
30773 \newline
30774 ddd -debugger "sdcdb -cpu 8032 ddd_example"
30775 \end_layout
30776
30777 \begin_layout Standard
30778 \begin_inset Note Note
30779 status open
30780
30781 \begin_layout Standard
30782 Check that the double quotes or an apostrophe within the command line survive
30783  the LyX tool chain.
30784  Previously the apostrophes got slanted in the PDF output so a cut and paste
30785  did not work.
30786 \end_layout
30787
30788 \end_inset
30789
30790
30791 \end_layout
30792
30793 \begin_layout Subsection
30794 Interfacing SDCDB with XEmacs
30795 \begin_inset LatexCommand index
30796 name "XEmacs"
30797
30798 \end_inset
30799
30800
30801 \begin_inset LatexCommand index
30802 name "Emacs"
30803
30804 \end_inset
30805
30806
30807 \end_layout
30808
30809 \begin_layout Standard
30810 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
30811  sdcdb.el and sdcdbsrc.el.
30812  These two files can be found in the $(prefix)/bin directory after the installat
30813 ion is complete.
30814  These files need to be loaded into XEmacs for the interface to work.
30815  This can be done at XEmacs startup time by inserting the following into
30816  your '.xemacs' file (which can be found in your HOME directory): 
30817 \newline
30818
30819 \newline
30820
30821 \family typewriter
30822 (load-file sdcdbsrc.el)
30823 \family default
30824  
30825 \newline
30826
30827 \newline
30828 .xemacs is a lisp file so the () around the command is REQUIRED.
30829  The files can also be loaded dynamically while XEmacs is running, set the
30830  environment variable 'EMACSLOADPATH' to the installation bin directory
30831  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
30832  To start the interface enter the following command: 
30833 \newline
30834
30835 \newline
30836
30837 \family sans
30838 \series bold
30839 ESC-x sdcdbsrc
30840 \family default
30841 \series default
30842
30843 \newline
30844
30845 \newline
30846 You will prompted to enter the file name to be debugged.
30847  
30848 \newline
30849
30850 \newline
30851 The command line options that are passed to the simulator directly are
30852  bound to default values in the file sdcdbsrc.el.
30853  The variables are listed below, these values maybe changed as required.
30854 \end_layout
30855
30856 \begin_layout Itemize
30857 sdcdbsrc-cpu-type '51
30858 \end_layout
30859
30860 \begin_layout Itemize
30861 sdcdbsrc-frequency '11059200
30862 \end_layout
30863
30864 \begin_layout Itemize
30865 sdcdbsrc-serial nil
30866 \end_layout
30867
30868 \begin_layout Standard
30869 The following is a list of key mapping for the debugger interface.
30870 \end_layout
30871
30872 \begin_layout Standard
30873 \InsetSpace ~
30874
30875 \family typewriter
30876
30877 \newline
30878 ;;\InsetSpace ~
30879 Current Listing :: 
30880 \newline
30881 ;;key\InsetSpace ~
30882 \InsetSpace ~
30883 \InsetSpace ~
30884 \InsetSpace ~
30885 \InsetSpace ~
30886 \InsetSpace ~
30887 \InsetSpace ~
30888 \InsetSpace ~
30889 \InsetSpace ~
30890 \InsetSpace ~
30891 \InsetSpace ~
30892 \InsetSpace ~
30893 \InsetSpace ~
30894 \InsetSpace ~
30895 binding\InsetSpace ~
30896 \InsetSpace ~
30897 \InsetSpace ~
30898 \InsetSpace ~
30899 \InsetSpace ~
30900 \InsetSpace ~
30901 \InsetSpace ~
30902 \InsetSpace ~
30903 \InsetSpace ~
30904 \InsetSpace ~
30905 \InsetSpace ~
30906 \InsetSpace ~
30907 \InsetSpace ~
30908 \InsetSpace ~
30909 \InsetSpace ~
30910 \InsetSpace ~
30911 \InsetSpace ~
30912 \InsetSpace ~
30913 \InsetSpace ~
30914 \InsetSpace ~
30915 \InsetSpace ~
30916 \InsetSpace ~
30917 Comment 
30918 \newline
30919 ;;---\InsetSpace ~
30920 \InsetSpace ~
30921 \InsetSpace ~
30922 \InsetSpace ~
30923 \InsetSpace ~
30924 \InsetSpace ~
30925 \InsetSpace ~
30926 \InsetSpace ~
30927 \InsetSpace ~
30928 \InsetSpace ~
30929 \InsetSpace ~
30930 \InsetSpace ~
30931 \InsetSpace ~
30932 \InsetSpace ~
30933 -------\InsetSpace ~
30934 \InsetSpace ~
30935 \InsetSpace ~
30936 \InsetSpace ~
30937 \InsetSpace ~
30938 \InsetSpace ~
30939 \InsetSpace ~
30940 \InsetSpace ~
30941 \InsetSpace ~
30942 \InsetSpace ~
30943 \InsetSpace ~
30944 \InsetSpace ~
30945 \InsetSpace ~
30946 \InsetSpace ~
30947 \InsetSpace ~
30948 \InsetSpace ~
30949 \InsetSpace ~
30950 \InsetSpace ~
30951 \InsetSpace ~
30952 \InsetSpace ~
30953 \InsetSpace ~
30954 \InsetSpace ~
30955 -------
30956 \newline
30957 ;; 
30958 \newline
30959 ;;\InsetSpace ~
30960 n\InsetSpace ~
30961 \InsetSpace ~
30962 \InsetSpace ~
30963 \InsetSpace ~
30964 \InsetSpace ~
30965 \InsetSpace ~
30966 \InsetSpace ~
30967 \InsetSpace ~
30968 \InsetSpace ~
30969 \InsetSpace ~
30970 \InsetSpace ~
30971 \InsetSpace ~
30972 \InsetSpace ~
30973 \InsetSpace ~
30974 \InsetSpace ~
30975 sdcdb-next-fro
30976 m-src\InsetSpace ~
30977 \InsetSpace ~
30978 \InsetSpace ~
30979 \InsetSpace ~
30980 \InsetSpace ~
30981 \InsetSpace ~
30982 \InsetSpace ~
30983 \InsetSpace ~
30984 \InsetSpace ~
30985 \InsetSpace ~
30986 SDCDB next command 
30987 \newline
30988 ;;\InsetSpace ~
30989 b\InsetSpace ~
30990 \InsetSpace ~
30991 \InsetSpace ~
30992 \InsetSpace ~
30993 \InsetSpace ~
30994 \InsetSpace ~
30995 \InsetSpace ~
30996 \InsetSpace ~
30997 \InsetSpace ~
30998 \InsetSpace ~
30999 \InsetSpace ~
31000 \InsetSpace ~
31001 \InsetSpace ~
31002 \InsetSpace ~
31003 \InsetSpace ~
31004 sdcdb-back-from-src\InsetSpace ~
31005 \InsetSpace ~
31006 \InsetSpace ~
31007 \InsetSpace ~
31008 \InsetSpace ~
31009 \InsetSpace ~
31010 \InsetSpace ~
31011 \InsetSpace ~
31012 \InsetSpace ~
31013 \InsetSpace ~
31014 SDCDB back command 
31015 \newline
31016 ;;\InsetSpace ~
31017 c\InsetSpace ~
31018 \InsetSpace ~
31019 \InsetSpace ~
31020 \InsetSpace ~
31021 \InsetSpace ~
31022 \InsetSpace ~
31023 \InsetSpace ~
31024 \InsetSpace ~
31025 \InsetSpace ~
31026 \InsetSpace ~
31027 \InsetSpace ~
31028 \InsetSpace ~
31029 \InsetSpace ~
31030 \InsetSpace ~
31031 \InsetSpace ~
31032 sdcdb-cont-f
31033 rom-src\InsetSpace ~
31034 \InsetSpace ~
31035 \InsetSpace ~
31036 \InsetSpace ~
31037 \InsetSpace ~
31038 \InsetSpace ~
31039 \InsetSpace ~
31040 \InsetSpace ~
31041 \InsetSpace ~
31042 \InsetSpace ~
31043 SDCDB continue command
31044 \newline
31045 ;;\InsetSpace ~
31046 s\InsetSpace ~
31047 \InsetSpace ~
31048 \InsetSpace ~
31049 \InsetSpace ~
31050 \InsetSpace ~
31051 \InsetSpace ~
31052 \InsetSpace ~
31053 \InsetSpace ~
31054 \InsetSpace ~
31055 \InsetSpace ~
31056 \InsetSpace ~
31057 \InsetSpace ~
31058 \InsetSpace ~
31059 \InsetSpace ~
31060 \InsetSpace ~
31061 sdcdb-step-from-src\InsetSpace ~
31062 \InsetSpace ~
31063 \InsetSpace ~
31064 \InsetSpace ~
31065 \InsetSpace ~
31066 \InsetSpace ~
31067 \InsetSpace ~
31068 \InsetSpace ~
31069 \InsetSpace ~
31070 \InsetSpace ~
31071 SDCDB step command 
31072 \newline
31073 ;;\InsetSpace ~
31074 ?\InsetSpace ~
31075 \InsetSpace ~
31076 \InsetSpace ~
31077 \InsetSpace ~
31078 \InsetSpace ~
31079 \InsetSpace ~
31080 \InsetSpace ~
31081 \InsetSpace ~
31082 \InsetSpace ~
31083 \InsetSpace ~
31084 \InsetSpace ~
31085 \InsetSpace ~
31086 \InsetSpace ~
31087 \InsetSpace ~
31088 \InsetSpace ~
31089 sdcdb-w
31090 hatis-c-sexp\InsetSpace ~
31091 \InsetSpace ~
31092 \InsetSpace ~
31093 \InsetSpace ~
31094 \InsetSpace ~
31095 \InsetSpace ~
31096 \InsetSpace ~
31097 \InsetSpace ~
31098 \InsetSpace ~
31099 \InsetSpace ~
31100 SDCDB ptypecommand for data at 
31101 \newline
31102 ;;\InsetSpace ~
31103 \InsetSpace ~
31104 \InsetSpace ~
31105 \InsetSpace ~
31106 \InsetSpace ~
31107 \InsetSpace ~
31108 \InsetSpace ~
31109 \InsetSpace ~
31110 \InsetSpace ~
31111 \InsetSpace ~
31112 \InsetSpace ~
31113 \InsetSpace ~
31114 \InsetSpace ~
31115 \InsetSpace ~
31116 \InsetSpace ~
31117 \InsetSpace ~
31118 \InsetSpace ~
31119 \InsetSpace ~
31120 \InsetSpace ~
31121 \InsetSpace ~
31122 \InsetSpace ~
31123 \InsetSpace ~
31124 \InsetSpace ~
31125 \InsetSpace ~
31126 \InsetSpace ~
31127 \InsetSpace ~
31128 \InsetSpace ~
31129 \InsetSpace ~
31130 \InsetSpace ~
31131 \InsetSpace ~
31132 \InsetSpace ~
31133 \InsetSpace ~
31134 \InsetSpace ~
31135 \InsetSpace ~
31136 \InsetSpace ~
31137 \InsetSpace ~
31138 \InsetSpace ~
31139 \InsetSpace ~
31140 \InsetSpace ~
31141 \InsetSpace ~
31142 \InsetSpace ~
31143 \InsetSpace ~
31144 \InsetSpace ~
31145 \InsetSpace ~
31146 \InsetSpace ~
31147 \InsetSpace ~
31148 \InsetSpace ~
31149 buffer point 
31150 \newline
31151 ;;\InsetSpace ~
31152 x\InsetSpace ~
31153 \InsetSpace ~
31154 \InsetSpace ~
31155 \InsetSpace ~
31156 \InsetSpace ~
31157 \InsetSpace ~
31158 \InsetSpace ~
31159 \InsetSpace ~
31160 \InsetSpace ~
31161 \InsetSpace ~
31162 \InsetSpace ~
31163 \InsetSpace ~
31164 \InsetSpace ~
31165 \InsetSpace ~
31166 \InsetSpace ~
31167 sdcdbsrc-delete\InsetSpace ~
31168 \InsetSpace ~
31169 \InsetSpace ~
31170 \InsetSpace ~
31171 \InsetSpace ~
31172 \InsetSpace ~
31173 \InsetSpace ~
31174 \InsetSpace ~
31175 \InsetSpace ~
31176 \InsetSpace ~
31177 \InsetSpace ~
31178 \InsetSpace ~
31179 \InsetSpace ~
31180 \InsetSpace ~
31181 SDCD
31182 B Delete all breakpoints if no arg 
31183 \newline
31184 ;;\InsetSpace ~
31185 \InsetSpace ~
31186 \InsetSpace ~
31187 \InsetSpace ~
31188 \InsetSpace ~
31189 \InsetSpace ~
31190 \InsetSpace ~
31191 \InsetSpace ~
31192 \InsetSpace ~
31193 \InsetSpace ~
31194 \InsetSpace ~
31195 \InsetSpace ~
31196 \InsetSpace ~
31197 \InsetSpace ~
31198 \InsetSpace ~
31199 \InsetSpace ~
31200 \InsetSpace ~
31201 \InsetSpace ~
31202 \InsetSpace ~
31203 \InsetSpace ~
31204 \InsetSpace ~
31205 \InsetSpace ~
31206 \InsetSpace ~
31207 \InsetSpace ~
31208 \InsetSpace ~
31209 \InsetSpace ~
31210 \InsetSpace ~
31211 \InsetSpace ~
31212 \InsetSpace ~
31213 \InsetSpace ~
31214 \InsetSpace ~
31215 \InsetSpace ~
31216 \InsetSpace ~
31217 \InsetSpace ~
31218 \InsetSpace ~
31219 \InsetSpace ~
31220 \InsetSpace ~
31221 \InsetSpace ~
31222 \InsetSpace ~
31223 \InsetSpace ~
31224 \InsetSpace ~
31225 \InsetSpace ~
31226 \InsetSpace ~
31227 \InsetSpace ~
31228 \InsetSpace ~
31229 \InsetSpace ~
31230 \InsetSpace ~
31231 given or delete arg (C-u arg x) 
31232 \newline
31233 ;;\InsetSpace ~
31234 m\InsetSpace ~
31235 \InsetSpace ~
31236 \InsetSpace ~
31237 \InsetSpace ~
31238 \InsetSpace ~
31239 \InsetSpace ~
31240 \InsetSpace ~
31241 \InsetSpace ~
31242 \InsetSpace ~
31243 \InsetSpace ~
31244 \InsetSpace ~
31245 \InsetSpace ~
31246 \InsetSpace ~
31247 \InsetSpace ~
31248 \InsetSpace ~
31249 sdcdbsrc
31250 -frame\InsetSpace ~
31251 \InsetSpace ~
31252 \InsetSpace ~
31253 \InsetSpace ~
31254 \InsetSpace ~
31255 \InsetSpace ~
31256 \InsetSpace ~
31257 \InsetSpace ~
31258 \InsetSpace ~
31259 \InsetSpace ~
31260 \InsetSpace ~
31261 \InsetSpace ~
31262 \InsetSpace ~
31263 \InsetSpace ~
31264 \InsetSpace ~
31265 SDCDB Display current frame if no arg, 
31266 \newline
31267 ;;\InsetSpace ~
31268 \InsetSpace ~
31269 \InsetSpace ~
31270 \InsetSpace ~
31271 \InsetSpace ~
31272 \InsetSpace ~
31273 \InsetSpace ~
31274 \InsetSpace ~
31275 \InsetSpace ~
31276 \InsetSpace ~
31277 \InsetSpace ~
31278 \InsetSpace ~
31279 \InsetSpace ~
31280 \InsetSpace ~
31281 \InsetSpace ~
31282 \InsetSpace ~
31283 \InsetSpace ~
31284 \InsetSpace ~
31285 \InsetSpace ~
31286 \InsetSpace ~
31287 \InsetSpace ~
31288 \InsetSpace ~
31289 \InsetSpace ~
31290 \InsetSpace ~
31291 \InsetSpace ~
31292 \InsetSpace ~
31293 \InsetSpace ~
31294 \InsetSpace ~
31295 \InsetSpace ~
31296 \InsetSpace ~
31297 \InsetSpace ~
31298 \InsetSpace ~
31299 \InsetSpace ~
31300 \InsetSpace ~
31301 \InsetSpace ~
31302 \InsetSpace ~
31303 \InsetSpace ~
31304 \InsetSpace ~
31305 \InsetSpace ~
31306 \InsetSpace ~
31307 \InsetSpace ~
31308 \InsetSpace ~
31309 \InsetSpace ~
31310 \InsetSpace ~
31311 \InsetSpace ~
31312 \InsetSpace ~
31313 \InsetSpace ~
31314 given or display frame arg
31315  
31316 \newline
31317 ;;\InsetSpace ~
31318 \InsetSpace ~
31319 \InsetSpace ~
31320 \InsetSpace ~
31321 \InsetSpace ~
31322 \InsetSpace ~
31323 \InsetSpace ~
31324 \InsetSpace ~
31325 \InsetSpace ~
31326 \InsetSpace ~
31327 \InsetSpace ~
31328 \InsetSpace ~
31329 \InsetSpace ~
31330 \InsetSpace ~
31331 \InsetSpace ~
31332 \InsetSpace ~
31333 \InsetSpace ~
31334 \InsetSpace ~
31335 \InsetSpace ~
31336 \InsetSpace ~
31337 \InsetSpace ~
31338 \InsetSpace ~
31339 \InsetSpace ~
31340 \InsetSpace ~
31341 \InsetSpace ~
31342 \InsetSpace ~
31343 \InsetSpace ~
31344 \InsetSpace ~
31345 \InsetSpace ~
31346 \InsetSpace ~
31347 \InsetSpace ~
31348 \InsetSpace ~
31349 \InsetSpace ~
31350 \InsetSpace ~
31351 \InsetSpace ~
31352 \InsetSpace ~
31353 \InsetSpace ~
31354 \InsetSpace ~
31355 \InsetSpace ~
31356 \InsetSpace ~
31357 \InsetSpace ~
31358 \InsetSpace ~
31359 \InsetSpace ~
31360 \InsetSpace ~
31361 \InsetSpace ~
31362 \InsetSpace ~
31363 \InsetSpace ~
31364 buffer point 
31365 \newline
31366 ;;\InsetSpace ~
31367 !\InsetSpace ~
31368 \InsetSpace ~
31369 \InsetSpace ~
31370 \InsetSpace ~
31371 \InsetSpace ~
31372 \InsetSpace ~
31373 \InsetSpace ~
31374 \InsetSpace ~
31375 \InsetSpace ~
31376 \InsetSpace ~
31377 \InsetSpace ~
31378 \InsetSpace ~
31379 \InsetSpace ~
31380 \InsetSpace ~
31381 \InsetSpace ~
31382 sdcdbsrc-goto-sdcdb\InsetSpace ~
31383 \InsetSpace ~
31384 \InsetSpace ~
31385 \InsetSpace ~
31386 \InsetSpace ~
31387 \InsetSpace ~
31388 \InsetSpace ~
31389 \InsetSpace ~
31390 \InsetSpace ~
31391 \InsetSpace ~
31392 Goto the SDCDB output buffer 
31393 \newline
31394 ;;\InsetSpace ~
31395 p\InsetSpace ~
31396 \InsetSpace ~
31397 \InsetSpace ~
31398 \InsetSpace ~
31399 \InsetSpace ~
31400 \InsetSpace ~
31401 \InsetSpace ~
31402 \InsetSpace ~
31403 \InsetSpace ~
31404 \InsetSpace ~
31405 \InsetSpace ~
31406 \InsetSpace ~
31407 \InsetSpace ~
31408 \InsetSpace ~
31409 \InsetSpace ~
31410 sdcdb-prin
31411 t-c-sexp\InsetSpace ~
31412 \InsetSpace ~
31413 \InsetSpace ~
31414 \InsetSpace ~
31415 \InsetSpace ~
31416 \InsetSpace ~
31417 \InsetSpace ~
31418 \InsetSpace ~
31419 \InsetSpace ~
31420 \InsetSpace ~
31421 \InsetSpace ~
31422 SDCDB print command for data at 
31423 \newline
31424 ;;\InsetSpace ~
31425 \InsetSpace ~
31426 \InsetSpace ~
31427 \InsetSpace ~
31428 \InsetSpace ~
31429 \InsetSpace ~
31430 \InsetSpace ~
31431 \InsetSpace ~
31432 \InsetSpace ~
31433 \InsetSpace ~
31434 \InsetSpace ~
31435 \InsetSpace ~
31436 \InsetSpace ~
31437 \InsetSpace ~
31438 \InsetSpace ~
31439 \InsetSpace ~
31440 \InsetSpace ~
31441 \InsetSpace ~
31442 \InsetSpace ~
31443 \InsetSpace ~
31444 \InsetSpace ~
31445 \InsetSpace ~
31446 \InsetSpace ~
31447 \InsetSpace ~
31448 \InsetSpace ~
31449 \InsetSpace ~
31450 \InsetSpace ~
31451 \InsetSpace ~
31452 \InsetSpace ~
31453 \InsetSpace ~
31454 \InsetSpace ~
31455 \InsetSpace ~
31456 \InsetSpace ~
31457 \InsetSpace ~
31458 \InsetSpace ~
31459 \InsetSpace ~
31460 \InsetSpace ~
31461 \InsetSpace ~
31462 \InsetSpace ~
31463 \InsetSpace ~
31464 \InsetSpace ~
31465 \InsetSpace ~
31466 \InsetSpace ~
31467 \InsetSpace ~
31468 \InsetSpace ~
31469 \InsetSpace ~
31470 \InsetSpace ~
31471 buffer point 
31472 \newline
31473 ;;\InsetSpace ~
31474 g\InsetSpace ~
31475 \InsetSpace ~
31476 \InsetSpace ~
31477 \InsetSpace ~
31478 \InsetSpace ~
31479 \InsetSpace ~
31480 \InsetSpace ~
31481 \InsetSpace ~
31482 \InsetSpace ~
31483 \InsetSpace ~
31484 \InsetSpace ~
31485 \InsetSpace ~
31486 \InsetSpace ~
31487 \InsetSpace ~
31488 \InsetSpace ~
31489 sdcdbsrc-goto-sdcdb\InsetSpace ~
31490 \InsetSpace ~
31491 \InsetSpace ~
31492 \InsetSpace ~
31493 \InsetSpace ~
31494 \InsetSpace ~
31495 \InsetSpace ~
31496 \InsetSpace ~
31497 \InsetSpace ~
31498 \InsetSpace ~
31499 Got
31500 o the SDCDB output buffer 
31501 \newline
31502 ;;\InsetSpace ~
31503 t\InsetSpace ~
31504 \InsetSpace ~
31505 \InsetSpace ~
31506 \InsetSpace ~
31507 \InsetSpace ~
31508 \InsetSpace ~
31509 \InsetSpace ~
31510 \InsetSpace ~
31511 \InsetSpace ~
31512 \InsetSpace ~
31513 \InsetSpace ~
31514 \InsetSpace ~
31515 \InsetSpace ~
31516 \InsetSpace ~
31517 \InsetSpace ~
31518 sdcdbsrc-mode\InsetSpace ~
31519 \InsetSpace ~
31520 \InsetSpace ~
31521 \InsetSpace ~
31522 \InsetSpace ~
31523 \InsetSpace ~
31524 \InsetSpace ~
31525 \InsetSpace ~
31526 \InsetSpace ~
31527 \InsetSpace ~
31528 \InsetSpace ~
31529 \InsetSpace ~
31530 \InsetSpace ~
31531 \InsetSpace ~
31532 \InsetSpace ~
31533 \InsetSpace ~
31534 Toggles Sdcdbsrc mode (turns it
31535  off) 
31536 \newline
31537 ;; 
31538 \newline
31539 ;;\InsetSpace ~
31540 C-c\InsetSpace ~
31541 C-f\InsetSpace ~
31542 \InsetSpace ~
31543 \InsetSpace ~
31544 \InsetSpace ~
31545 \InsetSpace ~
31546 \InsetSpace ~
31547 \InsetSpace ~
31548 \InsetSpace ~
31549 \InsetSpace ~
31550 sdcdb-finish-from-src\InsetSpace ~
31551 \InsetSpace ~
31552 \InsetSpace ~
31553 \InsetSpace ~
31554 \InsetSpace ~
31555 \InsetSpace ~
31556 \InsetSpace ~
31557 \InsetSpace ~
31558 SDCDB finish command 
31559 \newline
31560 ;; 
31561 \newline
31562 ;;\InsetSpace ~
31563 C-x\InsetSpace ~
31564 SPC\InsetSpace ~
31565 \InsetSpace ~
31566 \InsetSpace ~
31567 \InsetSpace ~
31568 \InsetSpace ~
31569 \InsetSpace ~
31570 \InsetSpace ~
31571 \InsetSpace ~
31572 \InsetSpace ~
31573 sdcdb-brea
31574 k\InsetSpace ~
31575 \InsetSpace ~
31576 \InsetSpace ~
31577 \InsetSpace ~
31578 \InsetSpace ~
31579 \InsetSpace ~
31580 \InsetSpace ~
31581 \InsetSpace ~
31582 \InsetSpace ~
31583 \InsetSpace ~
31584 \InsetSpace ~
31585 \InsetSpace ~
31586 \InsetSpace ~
31587 \InsetSpace ~
31588 \InsetSpace ~
31589 \InsetSpace ~
31590 \InsetSpace ~
31591 \InsetSpace ~
31592 Set break for line with point 
31593 \newline
31594 ;;\InsetSpace ~
31595 ESC\InsetSpace ~
31596 t\InsetSpace ~
31597 \InsetSpace ~
31598 \InsetSpace ~
31599 \InsetSpace ~
31600 \InsetSpace ~
31601 \InsetSpace ~
31602 \InsetSpace ~
31603 \InsetSpace ~
31604 \InsetSpace ~
31605 \InsetSpace ~
31606 \InsetSpace ~
31607 sdcdbsrc-mode\InsetSpace ~
31608 \InsetSpace ~
31609 \InsetSpace ~
31610 \InsetSpace ~
31611 \InsetSpace ~
31612 \InsetSpace ~
31613 \InsetSpace ~
31614 \InsetSpace ~
31615 \InsetSpace ~
31616 \InsetSpace ~
31617 \InsetSpace ~
31618 \InsetSpace ~
31619 \InsetSpace ~
31620 \InsetSpace ~
31621 \InsetSpace ~
31622 \InsetSpace ~
31623 Toggle Sdcdbsrc mode 
31624 \newline
31625 ;;\InsetSpace ~
31626 ESC\InsetSpace ~
31627 m\InsetSpace ~
31628 \InsetSpace ~
31629 \InsetSpace ~
31630 \InsetSpace ~
31631 \InsetSpace ~
31632 \InsetSpace ~
31633 \InsetSpace ~
31634 \InsetSpace ~
31635 \InsetSpace ~
31636 \InsetSpace ~
31637 \InsetSpace ~
31638 sdc
31639 dbsrc-srcmode\InsetSpace ~
31640 \InsetSpace ~
31641 \InsetSpace ~
31642 \InsetSpace ~
31643 \InsetSpace ~
31644 \InsetSpace ~
31645 \InsetSpace ~
31646 \InsetSpace ~
31647 \InsetSpace ~
31648 \InsetSpace ~
31649 \InsetSpace ~
31650 \InsetSpace ~
31651 \InsetSpace ~
31652 Toggle list mode 
31653 \newline
31654 ;; 
31655 \newline
31656
31657 \family default
31658
31659 \newpage
31660
31661 \end_layout
31662
31663 \begin_layout Chapter
31664 TIPS
31665 \end_layout
31666
31667 \begin_layout Standard
31668 Here are a few guidelines that will help the compiler generate more efficient
31669  code, some of the tips are specific to this compiler others are generally
31670  good programming practice.
31671 \end_layout
31672
31673 \begin_layout Itemize
31674 Use the smallest data type to represent your data-value.
31675  If it is known in advance that the value is going to be less than 256 then
31676  use an 'unsigned char' instead of a 'short' or 'int'.
31677  Please note, that ANSI C requires both signed and unsigned chars to be
31678  promoted to 'signed int'
31679 \begin_inset LatexCommand index
31680 name "promotion to signed int"
31681
31682 \end_inset
31683
31684
31685 \begin_inset Marginal
31686 status collapsed
31687
31688 \begin_layout Standard
31689
31690 \series bold
31691 \InsetSpace ~
31692 !
31693 \end_layout
31694
31695 \end_inset
31696
31697  before doing any operation.
31698  This promotion
31699 \begin_inset LatexCommand index
31700 name "type promotion"
31701
31702 \end_inset
31703
31704
31705 \begin_inset LatexCommand label
31706 name "type promotion"
31707
31708 \end_inset
31709
31710  can be omitted, if the result is the same.
31711  The effect of the promotion rules together with the sign-extension is often
31712  surprising:
31713 \end_layout
31714
31715 \begin_deeper
31716 \begin_layout Verse
31717
31718 \family typewriter
31719 unsigned char uc = 0xfe;
31720 \newline
31721 if (uc * uc < 0) /* this is true! */
31722 \newline
31723 {
31724 \newline
31725 \InsetSpace ~
31726 \InsetSpace ~
31727 \InsetSpace ~
31728 \InsetSpace ~
31729 ....
31730 \newline
31731 }
31732 \end_layout
31733
31734 \begin_layout Standard
31735
31736 \family typewriter
31737 uc * uc
31738 \family default
31739  is evaluated as 
31740 \family typewriter
31741 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
31742 \family default
31743 .
31744  
31745 \newline
31746 Another one:
31747 \end_layout
31748
31749 \begin_layout Verse
31750
31751 \family typewriter
31752 (unsigned char) -12 / (signed char) -3 = ...
31753 \end_layout
31754
31755 \begin_layout Standard
31756 No, the result is not 4:
31757 \end_layout
31758
31759 \begin_layout Verse
31760
31761 \family typewriter
31762 (int) (unsigned char) -12 / (int) (signed char) -3 =
31763 \newline
31764 (int) (unsigned char)
31765  0xf4 / (int) (signed char) 0xfd =
31766 \newline
31767 (int) 0x00f4 / (int) 0xfffd =
31768 \newline
31769 (int) 0x00f4
31770  / (int) 0xfffd =
31771 \newline
31772 (int) 244 / (int) -3 =
31773 \newline
31774 (int) -81 = (int) 0xffaf;
31775 \end_layout
31776
31777 \begin_layout Standard
31778 Don't complain, that gcc gives you a different result.
31779  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
31780  Therefore the results are different.
31781 \newline
31782 From 
31783 \begin_inset Quotes sld
31784 \end_inset
31785
31786 comp.lang.c FAQ
31787 \begin_inset Quotes srd
31788 \end_inset
31789
31790 :
31791 \end_layout
31792
31793 \begin_layout Quote
31794
31795 \emph on
31796 If well-defined overflow characteristics are important and negative values
31797  are not, or if you want to steer clear of sign-extension problems when
31798  manipulating bits or bytes, use one of the corresponding unsigned types.
31799  (Beware when mixing signed and unsigned values in expressions, though.)
31800 \newline
31801 Although
31802  character types (especially unsigned char) can be used as "tiny" integers,
31803  doing so is sometimes more trouble than it's worth, due to unpredictable
31804  sign extension and increased code size.
31805 \end_layout
31806
31807 \end_deeper
31808 \begin_layout Itemize
31809 Use unsigned when it is known in advance that the value is not going to
31810  be negative.
31811  This helps especially if you are doing division or multiplication, bit-shifting
31812  or are using an array index.
31813 \end_layout
31814
31815 \begin_layout Itemize
31816 NEVER jump into a LOOP.
31817 \end_layout
31818
31819 \begin_layout Itemize
31820 Declare the variables to be local
31821 \begin_inset LatexCommand index
31822 name "local variables"
31823
31824 \end_inset
31825
31826  whenever possible, especially loop control variables (induction).
31827 \end_layout
31828
31829 \begin_layout Itemize
31830 Have a look at the assembly listing to get a 
31831 \begin_inset Quotes sld
31832 \end_inset
31833
31834 feeling
31835 \begin_inset Quotes srd
31836 \end_inset
31837
31838  for the code generation.
31839 \end_layout
31840
31841 \begin_layout Section
31842 Porting code from or to other compilers
31843 \begin_inset LatexCommand label
31844 name "sec:Porting-code-to-other-compilers"
31845
31846 \end_inset
31847
31848
31849 \end_layout
31850
31851 \begin_layout Itemize
31852 check whether endianness of the compilers differs and adapt where needed.
31853 \end_layout
31854
31855 \begin_layout Itemize
31856 check the device specific header files
31857 \begin_inset LatexCommand index
31858 name "Header files"
31859
31860 \end_inset
31861
31862
31863 \begin_inset LatexCommand index
31864 name "Include files"
31865
31866 \end_inset
31867
31868  for compiler specific syntax.
31869  Eventually include the file <compiler.h
31870 \begin_inset LatexCommand index
31871 name "compiler.h (include file)"
31872
31873 \end_inset
31874
31875
31876 \begin_inset LatexCommand url
31877 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
31878
31879 \end_inset
31880
31881  to allow using common header files.
31882  (see f.e.
31883  cc2510fx.h 
31884 \begin_inset LatexCommand url
31885 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
31886
31887 \end_inset
31888
31889 ).
31890 \end_layout
31891
31892 \begin_layout Itemize
31893 check whether the startup code contains the correct initialization (watchdog,
31894  peripherals).
31895 \end_layout
31896
31897 \begin_layout Itemize
31898 check whether the sizes of short, int, long match.
31899 \end_layout
31900
31901 \begin_layout Itemize
31902 check if some 16 or 32 bit hardware registers require a specific addressing
31903  order (least significant or most significant byte first) and adapt if needed
31904  (
31905 \emph on
31906 first
31907 \emph default
31908  and 
31909 \emph on
31910 last
31911 \emph default
31912  relate to time and not to lower/upper memory location here, so this is
31913  
31914 \emph on
31915 not
31916 \emph default
31917  the same as endianness).
31918 \end_layout
31919
31920 \begin_layout Itemize
31921 check whether the keyword 
31922 \emph on
31923 volatile
31924 \emph default
31925  is used where needed.
31926  The compilers might differ in their optimization characteristics (as different
31927  versions of the same compiler might also use more clever optimizations
31928  this is good idea anyway).
31929  See section 
31930 \begin_inset LatexCommand ref
31931 reference "sub:Common-interrupt-pitfall-volatile"
31932
31933 \end_inset
31934
31935 .
31936 \end_layout
31937
31938 \begin_layout Itemize
31939 check that the compilers are not told to suppress warnings.
31940 \end_layout
31941
31942 \begin_layout Itemize
31943 check and convert compiler specific extensions (interrupts, memory areas,
31944  pragmas etc.).
31945 \end_layout
31946
31947 \begin_layout Itemize
31948 check for differences in type promotion.
31949  Especially check for math operations on 
31950 \family typewriter
31951 char
31952 \family default
31953  or 
31954 \family typewriter
31955 unsigned char
31956 \family default
31957  variables.
31958  For the sake of C99 compatibility SDCC will probably promote these to 
31959 \family typewriter
31960 int
31961 \family default
31962  more often than other compilers.
31963  Eventually insert explicit casts to 
31964 \family typewriter
31965 (char)
31966 \family default
31967  or 
31968 \family typewriter
31969 (unsigned char)
31970 \family default
31971 .
31972  Also check that the ~\InsetSpace ~
31973 operator
31974 \begin_inset LatexCommand index
31975 name "\\~\\/ Operator"
31976
31977 \end_inset
31978
31979  is not used on 
31980 \family typewriter
31981 bit
31982 \begin_inset LatexCommand index
31983 name "bit"
31984
31985 \end_inset
31986
31987
31988 \family default
31989  variables, use the !\InsetSpace ~
31990 operator instead.
31991  See sections 
31992 \begin_inset LatexCommand ref
31993 reference "type promotion"
31994
31995 \end_inset
31996
31997  and 
31998 \begin_inset LatexCommand ref
31999 reference "sec:Compatibility-with-previous"
32000
32001 \end_inset
32002
32003 .
32004 \end_layout
32005
32006 \begin_layout Itemize
32007 check the assembly code generated for interrupt routines (f.e.
32008  for calls to possibly non-reentrant library functions).
32009 \end_layout
32010
32011 \begin_layout Itemize
32012 check whether timing loops result in proper timing (or preferably consider
32013  a rewrite of the code with timer based delays instead).
32014 \end_layout
32015
32016 \begin_layout Itemize
32017 check for differences in printf parameters (some compilers push (va_arg
32018 \begin_inset LatexCommand index
32019 name "vararg, va\\_arg"
32020
32021 \end_inset
32022
32023 ) char variables as 
32024 \family typewriter
32025 int
32026 \family default
32027  others push them as 
32028 \family typewriter
32029 char
32030 \family default
32031 .
32032  See section 
32033 \begin_inset LatexCommand ref
32034 reference "sec:Compatibility-with-previous"
32035
32036 \end_inset
32037
32038 ).
32039 \end_layout
32040
32041 \begin_layout Itemize
32042 check the resulting memory map
32043 \begin_inset LatexCommand index
32044 name "Memory map"
32045
32046 \end_inset
32047
32048 .
32049  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32050 ly idata, pdata, xdata).
32051  Eventually check if unexpected library functions are included.
32052 \end_layout
32053
32054 \begin_layout Section
32055 Tools
32056 \begin_inset LatexCommand index
32057 name "Tools"
32058
32059 \end_inset
32060
32061  included in the distribution
32062 \end_layout
32063
32064 \begin_layout Standard
32065 \align left
32066 \begin_inset Tabular
32067 <lyxtabular version="3" rows="12" columns="3">
32068 <features>
32069 <column alignment="left" valignment="top" leftline="true" width="0pt">
32070 <column alignment="left" valignment="top" leftline="true" width="0pt">
32071 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32072 <row topline="true" bottomline="true">
32073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32074 \begin_inset Text
32075
32076 \begin_layout Standard
32077
32078 \series bold
32079 Name
32080 \end_layout
32081
32082 \end_inset
32083 </cell>
32084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32085 \begin_inset Text
32086
32087 \begin_layout Standard
32088
32089 \series bold
32090 Purpose
32091 \end_layout
32092
32093 \end_inset
32094 </cell>
32095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32096 \begin_inset Text
32097
32098 \begin_layout Standard
32099
32100 \series bold
32101 Directory
32102 \end_layout
32103
32104 \end_inset
32105 </cell>
32106 </row>
32107 <row topline="true">
32108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32109 \begin_inset Text
32110
32111 \begin_layout Standard
32112 uCsim
32113 \begin_inset LatexCommand index
32114 name "uCsim"
32115
32116 \end_inset
32117
32118
32119 \end_layout
32120
32121 \end_inset
32122 </cell>
32123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32124 \begin_inset Text
32125
32126 \begin_layout Standard
32127 Simulator for various architectures
32128 \end_layout
32129
32130 \end_inset
32131 </cell>
32132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32133 \begin_inset Text
32134
32135 \begin_layout Standard
32136 sdcc/sim/ucsim
32137 \end_layout
32138
32139 \end_inset
32140 </cell>
32141 </row>
32142 <row topline="true">
32143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32144 \begin_inset Text
32145
32146 \begin_layout Standard
32147 keil2sdcc.pl
32148 \end_layout
32149
32150 \end_inset
32151 </cell>
32152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32153 \begin_inset Text
32154
32155 \begin_layout Standard
32156 header file
32157 \begin_inset LatexCommand index
32158 name "Header files"
32159
32160 \end_inset
32161
32162
32163 \begin_inset LatexCommand index
32164 name "Include files"
32165
32166 \end_inset
32167
32168  conversion
32169 \end_layout
32170
32171 \end_inset
32172 </cell>
32173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32174 \begin_inset Text
32175
32176 \begin_layout Standard
32177 sdcc/support/scripts
32178 \end_layout
32179
32180 \end_inset
32181 </cell>
32182 </row>
32183 <row topline="true">
32184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32185 \begin_inset Text
32186
32187 \begin_layout Standard
32188 mh2h.c
32189 \end_layout
32190
32191 \end_inset
32192 </cell>
32193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32194 \begin_inset Text
32195
32196 \begin_layout Standard
32197 header file conversion
32198 \end_layout
32199
32200 \end_inset
32201 </cell>
32202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32203 \begin_inset Text
32204
32205 \begin_layout Standard
32206 sdcc/support/scripts
32207 \end_layout
32208
32209 \end_inset
32210 </cell>
32211 </row>
32212 <row topline="true">
32213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32214 \begin_inset Text
32215
32216 \begin_layout Standard
32217 as-gbz80
32218 \end_layout
32219
32220 \end_inset
32221 </cell>
32222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32223 \begin_inset Text
32224
32225 \begin_layout Standard
32226 Assembler
32227 \end_layout
32228
32229 \end_inset
32230 </cell>
32231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32232 \begin_inset Text
32233
32234 \begin_layout Standard
32235
32236 \family roman
32237 \series medium
32238 \shape up
32239 \size normal
32240 \emph off
32241 \bar no
32242 \noun off
32243 \color none
32244 sdcc/bin
32245 \end_layout
32246
32247 \end_inset
32248 </cell>
32249 </row>
32250 <row topline="true">
32251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32252 \begin_inset Text
32253
32254 \begin_layout Standard
32255 as-z80
32256 \end_layout
32257
32258 \end_inset
32259 </cell>
32260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32261 \begin_inset Text
32262
32263 \begin_layout Standard
32264 Assembler
32265 \end_layout
32266
32267 \end_inset
32268 </cell>
32269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32270 \begin_inset Text
32271
32272 \begin_layout Standard
32273
32274 \family roman
32275 \series medium
32276 \shape up
32277 \size normal
32278 \emph off
32279 \bar no
32280 \noun off
32281 \color none
32282 sdcc/bin
32283 \end_layout
32284
32285 \end_inset
32286 </cell>
32287 </row>
32288 <row topline="true">
32289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32290 \begin_inset Text
32291
32292 \begin_layout Standard
32293 asx8051
32294 \end_layout
32295
32296 \end_inset
32297 </cell>
32298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32299 \begin_inset Text
32300
32301 \begin_layout Standard
32302 Assembler
32303 \end_layout
32304
32305 \end_inset
32306 </cell>
32307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32308 \begin_inset Text
32309
32310 \begin_layout Standard
32311
32312 \family roman
32313 \series medium
32314 \shape up
32315 \size normal
32316 \emph off
32317 \bar no
32318 \noun off
32319 \color none
32320 sdcc/bin
32321 \end_layout
32322
32323 \end_inset
32324 </cell>
32325 </row>
32326 <row topline="true">
32327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32328 \begin_inset Text
32329
32330 \begin_layout Standard
32331 SDCDB
32332 \end_layout
32333
32334 \end_inset
32335 </cell>
32336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32337 \begin_inset Text
32338
32339 \begin_layout Standard
32340 Simulator
32341 \end_layout
32342
32343 \end_inset
32344 </cell>
32345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32346 \begin_inset Text
32347
32348 \begin_layout Standard
32349
32350 \family roman
32351 \series medium
32352 \shape up
32353 \size normal
32354 \emph off
32355 \bar no
32356 \noun off
32357 \color none
32358 sdcc/bin
32359 \end_layout
32360
32361 \end_inset
32362 </cell>
32363 </row>
32364 <row topline="true">
32365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32366 \begin_inset Text
32367
32368 \begin_layout Standard
32369 aslink
32370 \end_layout
32371
32372 \end_inset
32373 </cell>
32374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32375 \begin_inset Text
32376
32377 \begin_layout Standard
32378 Linker
32379 \end_layout
32380
32381 \end_inset
32382 </cell>
32383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32384 \begin_inset Text
32385
32386 \begin_layout Standard
32387
32388 \family roman
32389 \series medium
32390 \shape up
32391 \size normal
32392 \emph off
32393 \bar no
32394 \noun off
32395 \color none
32396 sdcc/bin
32397 \end_layout
32398
32399 \end_inset
32400 </cell>
32401 </row>
32402 <row topline="true">
32403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32404 \begin_inset Text
32405
32406 \begin_layout Standard
32407 link-z80
32408 \end_layout
32409
32410 \end_inset
32411 </cell>
32412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32413 \begin_inset Text
32414
32415 \begin_layout Standard
32416 Linker
32417 \end_layout
32418
32419 \end_inset
32420 </cell>
32421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32422 \begin_inset Text
32423
32424 \begin_layout Standard
32425
32426 \family roman
32427 \series medium
32428 \shape up
32429 \size normal
32430 \emph off
32431 \bar no
32432 \noun off
32433 \color none
32434 sdcc/bin
32435 \end_layout
32436
32437 \end_inset
32438 </cell>
32439 </row>
32440 <row topline="true">
32441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32442 \begin_inset Text
32443
32444 \begin_layout Standard
32445 link-gbz80
32446 \end_layout
32447
32448 \end_inset
32449 </cell>
32450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32451 \begin_inset Text
32452
32453 \begin_layout Standard
32454 Linker
32455 \end_layout
32456
32457 \end_inset
32458 </cell>
32459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32460 \begin_inset Text
32461
32462 \begin_layout Standard
32463
32464 \family roman
32465 \series medium
32466 \shape up
32467 \size normal
32468 \emph off
32469 \bar no
32470 \noun off
32471 \color none
32472 sdcc/bin
32473 \end_layout
32474
32475 \end_inset
32476 </cell>
32477 </row>
32478 <row topline="true" bottomline="true">
32479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32480 \begin_inset Text
32481
32482 \begin_layout Standard
32483 packihx
32484 \end_layout
32485
32486 \end_inset
32487 </cell>
32488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32489 \begin_inset Text
32490
32491 \begin_layout Standard
32492 Intel Hex packer 
32493 \begin_inset LatexCommand index
32494 name "packihx (tool)"
32495
32496 \end_inset
32497
32498
32499 \end_layout
32500
32501 \end_inset
32502 </cell>
32503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32504 \begin_inset Text
32505
32506 \begin_layout Standard
32507
32508 \family roman
32509 \series medium
32510 \shape up
32511 \size normal
32512 \emph off
32513 \bar no
32514 \noun off
32515 \color none
32516 sdcc/bin
32517 \end_layout
32518
32519 \end_inset
32520 </cell>
32521 </row>
32522 </lyxtabular>
32523
32524 \end_inset
32525
32526
32527 \newline
32528
32529 \end_layout
32530
32531 \begin_layout Section
32532 Documentation
32533 \begin_inset LatexCommand index
32534 name "Documentation"
32535
32536 \end_inset
32537
32538  included in the distribution
32539 \end_layout
32540
32541 \begin_layout Standard
32542 \align left
32543 \begin_inset Tabular
32544 <lyxtabular version="3" rows="10" columns="2">
32545 <features>
32546 <column alignment="block" valignment="top" leftline="true" width="40col%">
32547 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32548 <row topline="true" bottomline="true" endhead="true">
32549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32550 \begin_inset Text
32551
32552 \begin_layout Standard
32553
32554 \series bold
32555 Subject / Title
32556 \end_layout
32557
32558 \end_inset
32559 </cell>
32560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32561 \begin_inset Text
32562
32563 \begin_layout Standard
32564
32565 \series bold
32566 Filename / Where to get
32567 \end_layout
32568
32569 \end_inset
32570 </cell>
32571 </row>
32572 <row topline="true">
32573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32574 \begin_inset Text
32575
32576 \begin_layout Standard
32577 SDCC Compiler User Guide
32578 \end_layout
32579
32580 \end_inset
32581 </cell>
32582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32583 \begin_inset Text
32584
32585 \begin_layout Standard
32586 You're reading it right now 
32587 \emph on
32588 \InsetSpace ~
32589 \InsetSpace ~
32590 \InsetSpace ~
32591
32592 \hfill
32593 online at:
32594 \emph default
32595
32596 \newline
32597
32598 \begin_inset LatexCommand url
32599 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32600
32601 \end_inset
32602
32603
32604 \end_layout
32605
32606 \end_inset
32607 </cell>
32608 </row>
32609 <row topline="true">
32610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32611 \begin_inset Text
32612
32613 \begin_layout Standard
32614 Changelog of SDCC
32615 \end_layout
32616
32617 \end_inset
32618 </cell>
32619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32620 \begin_inset Text
32621
32622 \begin_layout Standard
32623 sdcc/Changelog 
32624 \emph on
32625 \InsetSpace ~
32626 \InsetSpace ~
32627 \InsetSpace ~
32628
32629 \hfill
32630 online at:
32631 \emph default
32632
32633 \newline
32634
32635 \begin_inset LatexCommand url
32636 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32637
32638 \end_inset
32639
32640
32641 \end_layout
32642
32643 \end_inset
32644 </cell>
32645 </row>
32646 <row topline="true">
32647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32648 \begin_inset Text
32649
32650 \begin_layout Standard
32651 ASXXXX
32652 \begin_inset LatexCommand index
32653 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32654
32655 \end_inset
32656
32657
32658 \begin_inset LatexCommand index
32659 name "Assembler documentation"
32660
32661 \end_inset
32662
32663  Assemblers and
32664 \newline
32665 ASLINK
32666 \begin_inset LatexCommand index
32667 name "aslink"
32668
32669 \end_inset
32670
32671
32672 \begin_inset LatexCommand index
32673 name "Linker documentation"
32674
32675 \end_inset
32676
32677  Relocating Linker
32678 \end_layout
32679
32680 \end_inset
32681 </cell>
32682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32683 \begin_inset Text
32684
32685 \begin_layout Standard
32686 sdcc/as/doc/asxhtm.html 
32687 \emph on
32688 \InsetSpace ~
32689 \InsetSpace ~
32690 \InsetSpace ~
32691
32692 \hfill
32693 online at:
32694 \emph default
32695
32696 \newline
32697
32698 \begin_inset LatexCommand url
32699 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32700
32701 \end_inset
32702
32703
32704 \end_layout
32705
32706 \end_inset
32707 </cell>
32708 </row>
32709 <row topline="true">
32710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32711 \begin_inset Text
32712
32713 \begin_layout Standard
32714 SDCC regression test
32715 \begin_inset LatexCommand index
32716 name "Regression test"
32717
32718 \end_inset
32719
32720
32721 \end_layout
32722
32723 \end_inset
32724 </cell>
32725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32726 \begin_inset Text
32727
32728 \begin_layout Standard
32729 sdcc/doc/test_suite_spec.pdf 
32730 \emph on
32731 \InsetSpace ~
32732 \InsetSpace ~
32733 \InsetSpace ~
32734
32735 \hfill
32736 online at:
32737 \emph default
32738
32739 \newline
32740
32741 \begin_inset LatexCommand url
32742 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
32743
32744 \end_inset
32745
32746
32747 \end_layout
32748
32749 \end_inset
32750 </cell>
32751 </row>
32752 <row topline="true">
32753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32754 \begin_inset Text
32755
32756 \begin_layout Standard
32757 Various notes
32758 \end_layout
32759
32760 \end_inset
32761 </cell>
32762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32763 \begin_inset Text
32764
32765 \begin_layout Standard
32766 sdcc/doc/* 
32767 \emph on
32768 \InsetSpace ~
32769 \InsetSpace ~
32770 \InsetSpace ~
32771
32772 \hfill
32773 online at:
32774 \emph default
32775
32776 \newline
32777
32778 \begin_inset LatexCommand url
32779 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
32780
32781 \end_inset
32782
32783
32784 \end_layout
32785
32786 \end_inset
32787 </cell>
32788 </row>
32789 <row topline="true">
32790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32791 \begin_inset Text
32792
32793 \begin_layout Standard
32794 Notes on debugging with SDCDB
32795 \begin_inset LatexCommand index
32796 name "SDCDB (debugger)"
32797
32798 \end_inset
32799
32800
32801 \end_layout
32802
32803 \end_inset
32804 </cell>
32805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32806 \begin_inset Text
32807
32808 \begin_layout Standard
32809 sdcc/debugger/README 
32810 \emph on
32811 \InsetSpace ~
32812 \InsetSpace ~
32813 \InsetSpace ~
32814
32815 \hfill
32816 online at
32817 \emph default
32818 :
32819 \newline
32820
32821 \begin_inset LatexCommand url
32822 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
32823
32824 \end_inset
32825
32826
32827 \end_layout
32828
32829 \end_inset
32830 </cell>
32831 </row>
32832 <row topline="true">
32833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32834 \begin_inset Text
32835
32836 \begin_layout Standard
32837 uCsim
32838 \begin_inset LatexCommand index
32839 name "uCsim"
32840
32841 \end_inset
32842
32843  Software simulator for microcontrollers
32844 \end_layout
32845
32846 \end_inset
32847 </cell>
32848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32849 \begin_inset Text
32850
32851 \begin_layout Standard
32852
32853 \family roman
32854 \series medium
32855 \shape up
32856 \size normal
32857 \emph off
32858 \bar no
32859 \noun off
32860 \color none
32861 sdcc/sim/ucsim/doc
32862 \family default
32863 \series default
32864 \shape default
32865 \size default
32866 \emph default
32867 \bar default
32868 \noun default
32869 /index.html 
32870 \emph on
32871 \InsetSpace ~
32872 \InsetSpace ~
32873 \InsetSpace ~
32874
32875 \hfill
32876 online at:
32877 \emph default
32878
32879 \newline
32880
32881 \begin_inset LatexCommand url
32882 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
32883
32884 \end_inset
32885
32886
32887 \end_layout
32888
32889 \end_inset
32890 </cell>
32891 </row>
32892 <row topline="true">
32893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32894 \begin_inset Text
32895
32896 \begin_layout Standard
32897 Temporary notes on the pic16
32898 \begin_inset LatexCommand index
32899 name "PIC16"
32900
32901 \end_inset
32902
32903  port
32904 \end_layout
32905
32906 \end_inset
32907 </cell>
32908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32909 \begin_inset Text
32910
32911 \begin_layout Standard
32912 sdcc/src/pic16/NOTES 
32913 \emph on
32914 \InsetSpace ~
32915 \InsetSpace ~
32916 \InsetSpace ~
32917
32918 \hfill
32919 online at:
32920 \newline
32921
32922 \emph default
32923
32924 \begin_inset LatexCommand url
32925 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
32926
32927 \end_inset
32928
32929
32930 \end_layout
32931
32932 \end_inset
32933 </cell>
32934 </row>
32935 <row topline="true" bottomline="true">
32936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32937 \begin_inset Text
32938
32939 \begin_layout Standard
32940 SDCC internal documentation (debugging file format)
32941 \end_layout
32942
32943 \end_inset
32944 </cell>
32945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32946 \begin_inset Text
32947
32948 \begin_layout Standard
32949 sdcc/doc/
32950 \family roman
32951 \series medium
32952 \shape up
32953 \size normal
32954 \emph off
32955 \bar no
32956 \noun off
32957 \color none
32958 cdbfileformat.pd
32959 \family default
32960 \series default
32961 \shape default
32962 \size default
32963 \emph default
32964 \bar default
32965 \noun default
32966
32967 \emph on
32968 \InsetSpace ~
32969 \InsetSpace ~
32970 \InsetSpace ~
32971
32972 \hfill
32973 online at:
32974 \emph default
32975
32976 \newline
32977
32978 \begin_inset LatexCommand url
32979 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
32980
32981 \end_inset
32982
32983
32984 \end_layout
32985
32986 \end_inset
32987 </cell>
32988 </row>
32989 </lyxtabular>
32990
32991 \end_inset
32992
32993
32994 \newline
32995
32996 \end_layout
32997
32998 \begin_layout Section
32999 Related open source tools
33000 \begin_inset LatexCommand label
33001 name "sec:Related-open-source-tools"
33002
33003 \end_inset
33004
33005
33006 \begin_inset LatexCommand index
33007 name "Related tools"
33008
33009 \end_inset
33010
33011
33012 \end_layout
33013
33014 \begin_layout Standard
33015 \align left
33016 \begin_inset Tabular
33017 <lyxtabular version="3" rows="16" columns="3">
33018 <features>
33019 <column alignment="left" valignment="top" leftline="true" width="0pt">
33020 <column alignment="block" valignment="top" leftline="true" width="30line%">
33021 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33022 <row topline="true" bottomline="true">
33023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33024 \begin_inset Text
33025
33026 \begin_layout Standard
33027
33028 \series bold
33029 Name
33030 \end_layout
33031
33032 \end_inset
33033 </cell>
33034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33035 \begin_inset Text
33036
33037 \begin_layout Standard
33038
33039 \series bold
33040 Purpose
33041 \end_layout
33042
33043 \end_inset
33044 </cell>
33045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33046 \begin_inset Text
33047
33048 \begin_layout Standard
33049
33050 \series bold
33051 Where to get
33052 \end_layout
33053
33054 \end_inset
33055 </cell>
33056 </row>
33057 <row topline="true">
33058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33059 \begin_inset Text
33060
33061 \begin_layout Standard
33062 gpsim
33063 \begin_inset LatexCommand index
33064 name "gpsim (pic simulator)"
33065
33066 \end_inset
33067
33068
33069 \end_layout
33070
33071 \end_inset
33072 </cell>
33073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33074 \begin_inset Text
33075
33076 \begin_layout Standard
33077 PIC simulator
33078 \end_layout
33079
33080 \end_inset
33081 </cell>
33082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33083 \begin_inset Text
33084
33085 \begin_layout Standard
33086 \begin_inset LatexCommand url
33087 target "http://www.dattalo.com/gnupic/gpsim.html"
33088
33089 \end_inset
33090
33091
33092 \end_layout
33093
33094 \end_inset
33095 </cell>
33096 </row>
33097 <row topline="true">
33098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33099 \begin_inset Text
33100
33101 \begin_layout Standard
33102 gputils
33103 \begin_inset LatexCommand index
33104 name "gputils (pic tools)"
33105
33106 \end_inset
33107
33108
33109 \end_layout
33110
33111 \end_inset
33112 </cell>
33113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33114 \begin_inset Text
33115
33116 \begin_layout Standard
33117 GNU PIC utilities
33118 \end_layout
33119
33120 \end_inset
33121 </cell>
33122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33123 \begin_inset Text
33124
33125 \begin_layout Standard
33126 \begin_inset LatexCommand url
33127 target "http://sourceforge.net/projects/gputils"
33128
33129 \end_inset
33130
33131
33132 \end_layout
33133
33134 \end_inset
33135 </cell>
33136 </row>
33137 <row topline="true">
33138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33139 \begin_inset Text
33140
33141 \begin_layout Standard
33142 flP5
33143 \end_layout
33144
33145 \end_inset
33146 </cell>
33147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33148 \begin_inset Text
33149
33150 \begin_layout Standard
33151 PIC programmer
33152 \end_layout
33153
33154 \end_inset
33155 </cell>
33156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33157 \begin_inset Text
33158
33159 \begin_layout Standard
33160 \begin_inset LatexCommand url
33161 target "http://freshmeat.net/projects/flp5/"
33162
33163 \end_inset
33164
33165
33166 \end_layout
33167
33168 \end_inset
33169 </cell>
33170 </row>
33171 <row topline="true">
33172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33173 \begin_inset Text
33174
33175 \begin_layout Standard
33176 ec2drv/newcdb
33177 \end_layout
33178
33179 \end_inset
33180 </cell>
33181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33182 \begin_inset Text
33183
33184 \begin_layout Standard
33185 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33186  (Unix only)
33187 \end_layout
33188
33189 \end_inset
33190 </cell>
33191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33192 \begin_inset Text
33193
33194 \begin_layout Standard
33195 \begin_inset LatexCommand url
33196 target "http://sourceforge.net/projects/ec2drv"
33197
33198 \end_inset
33199
33200
33201 \end_layout
33202
33203 \end_inset
33204 </cell>
33205 </row>
33206 <row topline="true">
33207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33208 \begin_inset Text
33209
33210 \begin_layout Standard
33211 indent
33212 \begin_inset LatexCommand index
33213 name "indent (source formatting tool)"
33214
33215 \end_inset
33216
33217
33218 \end_layout
33219
33220 \end_inset
33221 </cell>
33222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33223 \begin_inset Text
33224
33225 \begin_layout Standard
33226 Formats C source - Master of the white spaces
33227 \end_layout
33228
33229 \end_inset
33230 </cell>
33231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33232 \begin_inset Text
33233
33234 \begin_layout Standard
33235 \begin_inset LatexCommand url
33236 target "http://directory.fsf.org/GNU/indent.html"
33237
33238 \end_inset
33239
33240
33241 \end_layout
33242
33243 \end_inset
33244 </cell>
33245 </row>
33246 <row topline="true">
33247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33248 \begin_inset Text
33249
33250 \begin_layout Standard
33251 srecord
33252 \begin_inset LatexCommand index
33253 name "srecord (bin, hex, ... tool)"
33254
33255 \end_inset
33256
33257
33258 \end_layout
33259
33260 \end_inset
33261 </cell>
33262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33263 \begin_inset Text
33264
33265 \begin_layout Standard
33266 Object file conversion, checksumming, ...
33267 \end_layout
33268
33269 \end_inset
33270 </cell>
33271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33272 \begin_inset Text
33273
33274 \begin_layout Standard
33275 \begin_inset LatexCommand url
33276 target "http://sourceforge.net/projects/srecord"
33277
33278 \end_inset
33279
33280
33281 \end_layout
33282
33283 \end_inset
33284 </cell>
33285 </row>
33286 <row topline="true">
33287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33288 \begin_inset Text
33289
33290 \begin_layout Standard
33291 objdump
33292 \begin_inset LatexCommand index
33293 name "objdump (tool)"
33294
33295 \end_inset
33296
33297
33298 \end_layout
33299
33300 \end_inset
33301 </cell>
33302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33303 \begin_inset Text
33304
33305 \begin_layout Standard
33306 Object file conversion, ...
33307 \end_layout
33308
33309 \end_inset
33310 </cell>
33311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33312 \begin_inset Text
33313
33314 \begin_layout Standard
33315 Part of binutils (should be there anyway)
33316 \end_layout
33317
33318 \end_inset
33319 </cell>
33320 </row>
33321 <row topline="true">
33322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33323 \begin_inset Text
33324
33325 \begin_layout Standard
33326 cmon51
33327 \end_layout
33328
33329 \end_inset
33330 </cell>
33331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33332 \begin_inset Text
33333
33334 \begin_layout Standard
33335 8051 monitor (hex up-/download, single step, disassemble)
33336 \end_layout
33337
33338 \end_inset
33339 </cell>
33340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33341 \begin_inset Text
33342
33343 \begin_layout Standard
33344 \begin_inset LatexCommand url
33345 target "http://sourceforge.net/projects/cmon51"
33346
33347 \end_inset
33348
33349
33350 \end_layout
33351
33352 \end_inset
33353 </cell>
33354 </row>
33355 <row topline="true">
33356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33357 \begin_inset Text
33358
33359 \begin_layout Standard
33360 doxygen
33361 \begin_inset LatexCommand index
33362 name "doxygen (source documentation tool)"
33363
33364 \end_inset
33365
33366
33367 \end_layout
33368
33369 \end_inset
33370 </cell>
33371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33372 \begin_inset Text
33373
33374 \begin_layout Standard
33375 Source code documentation system
33376 \end_layout
33377
33378 \end_inset
33379 </cell>
33380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33381 \begin_inset Text
33382
33383 \begin_layout Standard
33384 \begin_inset LatexCommand url
33385 target "http://www.doxygen.org"
33386
33387 \end_inset
33388
33389
33390 \end_layout
33391
33392 \end_inset
33393 </cell>
33394 </row>
33395 <row topline="true">
33396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33397 \begin_inset Text
33398
33399 \begin_layout Standard
33400 kdevelop
33401 \end_layout
33402
33403 \end_inset
33404 </cell>
33405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33406 \begin_inset Text
33407
33408 \begin_layout Standard
33409 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33410 \end_layout
33411
33412 \end_inset
33413 </cell>
33414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33415 \begin_inset Text
33416
33417 \begin_layout Standard
33418 \begin_inset LatexCommand url
33419 target "http://www.kdevelop.org"
33420
33421 \end_inset
33422
33423
33424 \end_layout
33425
33426 \end_inset
33427 </cell>
33428 </row>
33429 <row topline="true">
33430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33431 \begin_inset Text
33432
33433 \begin_layout Standard
33434 paulmon
33435 \end_layout
33436
33437 \end_inset
33438 </cell>
33439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33440 \begin_inset Text
33441
33442 \begin_layout Standard
33443 8051 monitor (hex up-/download, single step, disassemble)
33444 \end_layout
33445
33446 \end_inset
33447 </cell>
33448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33449 \begin_inset Text
33450
33451 \begin_layout Standard
33452 \begin_inset LatexCommand url
33453 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33454
33455 \end_inset
33456
33457
33458 \end_layout
33459
33460 \end_inset
33461 </cell>
33462 </row>
33463 <row topline="true">
33464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33465 \begin_inset Text
33466
33467 \begin_layout Standard
33468 splint
33469 \begin_inset LatexCommand index
33470 name "splint (syntax checking tool)"
33471
33472 \end_inset
33473
33474
33475 \end_layout
33476
33477 \end_inset
33478 </cell>
33479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33480 \begin_inset Text
33481
33482 \begin_layout Standard
33483 Statically checks c sources (see 
33484 \begin_inset LatexCommand ref
33485 reference "lyx:more-pedantic-SPLINT"
33486
33487 \end_inset
33488
33489 )
33490 \end_layout
33491
33492 \end_inset
33493 </cell>
33494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33495 \begin_inset Text
33496
33497 \begin_layout Standard
33498 \begin_inset LatexCommand url
33499 target "http://www.splint.org"
33500
33501 \end_inset
33502
33503
33504 \end_layout
33505
33506 \end_inset
33507 </cell>
33508 </row>
33509 <row topline="true" bottomline="true">
33510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33511 \begin_inset Text
33512
33513 \begin_layout Standard
33514 ddd
33515 \begin_inset LatexCommand index
33516 name "DDD (debugger)"
33517
33518 \end_inset
33519
33520
33521 \end_layout
33522
33523 \end_inset
33524 </cell>
33525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33526 \begin_inset Text
33527
33528 \begin_layout Standard
33529 Debugger, serves nicely as GUI to SDCDB
33530 \begin_inset LatexCommand index
33531 name "SDCDB (debugger)"
33532
33533 \end_inset
33534
33535  (Unix only)
33536 \end_layout
33537
33538 \end_inset
33539 </cell>
33540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33541 \begin_inset Text
33542
33543 \begin_layout Standard
33544 \begin_inset LatexCommand url
33545 target "http://www.gnu.org/software/ddd/"
33546
33547 \end_inset
33548
33549
33550 \end_layout
33551
33552 \end_inset
33553 </cell>
33554 </row>
33555 <row bottomline="true">
33556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33557 \begin_inset Text
33558
33559 \begin_layout Standard
33560 d52
33561 \begin_inset LatexCommand index
33562 name "d52"
33563
33564 \end_inset
33565
33566
33567 \begin_inset LatexCommand index
33568 name "d52 (disassembler)"
33569
33570 \end_inset
33571
33572
33573 \end_layout
33574
33575 \end_inset
33576 </cell>
33577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33578 \begin_inset Text
33579
33580 \begin_layout Standard
33581 Disassembler, can count instruction cycles
33582 \begin_inset LatexCommand index
33583 name "instruction cycles (count)"
33584
33585 \end_inset
33586
33587 , use with options -pnd
33588 \end_layout
33589
33590 \end_inset
33591 </cell>
33592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33593 \begin_inset Text
33594
33595 \begin_layout Standard
33596 \begin_inset LatexCommand url
33597 target "http://www.8052.com/users/disasm/"
33598
33599 \end_inset
33600
33601
33602 \end_layout
33603
33604 \end_inset
33605 </cell>
33606 </row>
33607 <row bottomline="true">
33608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33609 \begin_inset Text
33610
33611 \begin_layout Standard
33612 cmake
33613 \begin_inset LatexCommand index
33614 name "cmake"
33615
33616 \end_inset
33617
33618
33619 \end_layout
33620
33621 \end_inset
33622 </cell>
33623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33624 \begin_inset Text
33625
33626 \begin_layout Standard
33627 Cross platform build system, generates Makefiles
33628 \begin_inset LatexCommand index
33629 name "Makefile"
33630
33631 \end_inset
33632
33633  and project workspaces
33634 \begin_inset LatexCommand index
33635 name "project workspace"
33636
33637 \end_inset
33638
33639
33640 \end_layout
33641
33642 \end_inset
33643 </cell>
33644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33645 \begin_inset Text
33646
33647 \begin_layout Standard
33648 \begin_inset LatexCommand url
33649 target "http://www.cmake.org"
33650
33651 \end_inset
33652
33653  \InsetSpace ~
33654 \InsetSpace ~
33655 \InsetSpace ~
33656 \InsetSpace ~
33657 and a dedicated wiki entry: 
33658 \begin_inset LatexCommand url
33659 target "http://www.cmake.org/Wiki/CmakeSdcc"
33660
33661 \end_inset
33662
33663
33664 \end_layout
33665
33666 \end_inset
33667 </cell>
33668 </row>
33669 </lyxtabular>
33670
33671 \end_inset
33672
33673
33674 \newline
33675
33676 \end_layout
33677
33678 \begin_layout Section
33679 Related documentation / recommended reading
33680 \end_layout
33681
33682 \begin_layout Standard
33683 \align left
33684 \begin_inset Tabular
33685 <lyxtabular version="3" rows="7" columns="3">
33686 <features>
33687 <column alignment="left" valignment="top" leftline="true" width="0pt">
33688 <column alignment="left" valignment="top" leftline="true" width="0">
33689 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33690 <row topline="true" bottomline="true">
33691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33692 \begin_inset Text
33693
33694 \begin_layout Standard
33695
33696 \series bold
33697 Name
33698 \end_layout
33699
33700 \end_inset
33701 </cell>
33702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33703 \begin_inset Text
33704
33705 \begin_layout Standard
33706
33707 \series bold
33708 Subject / Title
33709 \end_layout
33710
33711 \end_inset
33712 </cell>
33713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33714 \begin_inset Text
33715
33716 \begin_layout Standard
33717
33718 \series bold
33719 Where to get
33720 \end_layout
33721
33722 \end_inset
33723 </cell>
33724 </row>
33725 <row topline="true">
33726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33727 \begin_inset Text
33728
33729 \begin_layout Standard
33730
33731 \family roman
33732 \series medium
33733 \shape up
33734 \size normal
33735 \emph off
33736 \bar no
33737 \noun off
33738 \color none
33739 c-refcard.pdf
33740 \end_layout
33741
33742 \end_inset
33743 </cell>
33744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33745 \begin_inset Text
33746
33747 \begin_layout Standard
33748 C Reference Card
33749 \begin_inset LatexCommand index
33750 name "C Reference card"
33751
33752 \end_inset
33753
33754 , 2 pages
33755 \end_layout
33756
33757 \end_inset
33758 </cell>
33759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33760 \begin_inset Text
33761
33762 \begin_layout Standard
33763 \begin_inset LatexCommand url
33764 target "http://refcards.com/refcards/c/index.html"
33765
33766 \end_inset
33767
33768
33769 \end_layout
33770
33771 \end_inset
33772 </cell>
33773 </row>
33774 <row topline="true">
33775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33776 \begin_inset Text
33777
33778 \begin_layout Standard
33779 c-faq
33780 \end_layout
33781
33782 \end_inset
33783 </cell>
33784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33785 \begin_inset Text
33786
33787 \begin_layout Standard
33788 C-FAQ
33789 \begin_inset LatexCommand index
33790 name "C FAQ"
33791
33792 \end_inset
33793
33794
33795 \end_layout
33796
33797 \end_inset
33798 </cell>
33799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33800 \begin_inset Text
33801
33802 \begin_layout Standard
33803 \begin_inset LatexCommand url
33804 target "http://www.c-faq.com"
33805
33806 \end_inset
33807
33808
33809 \end_layout
33810
33811 \end_inset
33812 </cell>
33813 </row>
33814 <row topline="true">
33815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33816 \begin_inset Text
33817
33818 \begin_layout Standard
33819 ISO/IEC 9899:TC2
33820 \end_layout
33821
33822 \end_inset
33823 </cell>
33824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33825 \begin_inset Text
33826
33827 \begin_layout Standard
33828 \begin_inset Quotes sld
33829 \end_inset
33830
33831 C-Standard
33832 \begin_inset Quotes srd
33833 \end_inset
33834
33835
33836 \end_layout
33837
33838 \end_inset
33839 </cell>
33840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33841 \begin_inset Text
33842
33843 \begin_layout Standard
33844
33845 \size footnotesize
33846 \begin_inset LatexCommand url
33847 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
33848
33849 \end_inset
33850
33851
33852 \end_layout
33853
33854 \end_inset
33855 </cell>
33856 </row>
33857 <row topline="true">
33858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33859 \begin_inset Text
33860
33861 \begin_layout Standard
33862 ISO/IEC DTR 18037
33863 \end_layout
33864
33865 \end_inset
33866 </cell>
33867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33868 \begin_inset Text
33869
33870 \begin_layout Standard
33871 \begin_inset Quotes sld
33872 \end_inset
33873
33874 Extensions for Embedded C
33875 \begin_inset Quotes srd
33876 \end_inset
33877
33878
33879 \end_layout
33880
33881 \end_inset
33882 </cell>
33883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33884 \begin_inset Text
33885
33886 \begin_layout Standard
33887
33888 \size footnotesize
33889 \begin_inset LatexCommand url
33890 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
33891
33892 \end_inset
33893
33894
33895 \end_layout
33896
33897 \end_inset
33898 </cell>
33899 </row>
33900 <row topline="true">
33901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33902 \begin_inset Text
33903
33904 \begin_layout Standard
33905
33906 \end_layout
33907
33908 \end_inset
33909 </cell>
33910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33911 \begin_inset Text
33912
33913 \begin_layout Standard
33914 Latest datasheet of target CPU
33915 \end_layout
33916
33917 \end_inset
33918 </cell>
33919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33920 \begin_inset Text
33921
33922 \begin_layout Standard
33923 vendor
33924 \end_layout
33925
33926 \end_inset
33927 </cell>
33928 </row>
33929 <row topline="true" bottomline="true">
33930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33931 \begin_inset Text
33932
33933 \begin_layout Standard
33934
33935 \end_layout
33936
33937 \end_inset
33938 </cell>
33939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33940 \begin_inset Text
33941
33942 \begin_layout Standard
33943 Revision history of datasheet
33944 \end_layout
33945
33946 \end_inset
33947 </cell>
33948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33949 \begin_inset Text
33950
33951 \begin_layout Standard
33952 vendor
33953 \end_layout
33954
33955 \end_inset
33956 </cell>
33957 </row>
33958 </lyxtabular>
33959
33960 \end_inset
33961
33962
33963 \newline
33964
33965 \end_layout
33966
33967 \begin_layout Section
33968 Application notes specifically for SDCC
33969 \end_layout
33970
33971 \begin_layout Standard
33972 SDCC makes no claims about the completeness of this list and about up-to-datenes
33973 s or correctness of the application notes
33974 \begin_inset LatexCommand index
33975 name "Application notes"
33976
33977 \end_inset
33978
33979 .
33980 \end_layout
33981
33982 \begin_layout Standard
33983 \align left
33984
33985 \size footnotesize
33986 \begin_inset Tabular
33987 <lyxtabular version="3" rows="7" columns="3">
33988 <features>
33989 <column alignment="block" valignment="top" leftline="true" width="17col%">
33990 <column alignment="block" valignment="top" leftline="true" width="27col%">
33991 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
33992 <row topline="true" bottomline="true">
33993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33994 \begin_inset Text
33995
33996 \begin_layout Standard
33997
33998 \series bold
33999 \size footnotesize
34000 Vendor
34001 \end_layout
34002
34003 \end_inset
34004 </cell>
34005 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34006 \begin_inset Text
34007
34008 \begin_layout Standard
34009
34010 \series bold
34011 \size footnotesize
34012 Subject / Title
34013 \end_layout
34014
34015 \end_inset
34016 </cell>
34017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34018 \begin_inset Text
34019
34020 \begin_layout Standard
34021
34022 \series bold
34023 \size footnotesize
34024 Where to get
34025 \end_layout
34026
34027 \end_inset
34028 </cell>
34029 </row>
34030 <row topline="true">
34031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34032 \begin_inset Text
34033
34034 \begin_layout Standard
34035
34036 \size footnotesize
34037 Maxim / Dallas
34038 \end_layout
34039
34040 \end_inset
34041 </cell>
34042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34043 \begin_inset Text
34044
34045 \begin_layout Standard
34046
34047 \size footnotesize
34048 Using the SDCC Compiler for the DS80C400
34049 \begin_inset LatexCommand index
34050 name "DS80C400"
34051
34052 \end_inset
34053
34054
34055 \end_layout
34056
34057 \end_inset
34058 </cell>
34059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34060 \begin_inset Text
34061
34062 \begin_layout Standard
34063
34064 \size footnotesize
34065 \begin_inset LatexCommand url
34066 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34067
34068 \end_inset
34069
34070
34071 \end_layout
34072
34073 \end_inset
34074 </cell>
34075 </row>
34076 <row topline="true">
34077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34078 \begin_inset Text
34079
34080 \begin_layout Standard
34081
34082 \size footnotesize
34083 Maxim / Dallas
34084 \end_layout
34085
34086 \end_inset
34087 </cell>
34088 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34089 \begin_inset Text
34090
34091 \begin_layout Standard
34092
34093 \size footnotesize
34094 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34095 \begin_inset LatexCommand index
34096 name "DS89C4x0"
34097
34098 \end_inset
34099
34100  Family of Microcontrollers
34101 \end_layout
34102
34103 \end_inset
34104 </cell>
34105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34106 \begin_inset Text
34107
34108 \begin_layout Standard
34109
34110 \size footnotesize
34111 \begin_inset LatexCommand url
34112 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34113
34114 \end_inset
34115
34116
34117 \end_layout
34118
34119 \end_inset
34120 </cell>
34121 </row>
34122 <row topline="true">
34123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34124 \begin_inset Text
34125
34126 \begin_layout Standard
34127
34128 \size footnotesize
34129 Silicon Laboratories / Cygnal
34130 \end_layout
34131
34132 \end_inset
34133 </cell>
34134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34135 \begin_inset Text
34136
34137 \begin_layout Standard
34138
34139 \size footnotesize
34140 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34141 \begin_inset LatexCommand index
34142 name "IDE"
34143
34144 \end_inset
34145
34146
34147 \end_layout
34148
34149 \end_inset
34150 </cell>
34151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34152 \begin_inset Text
34153
34154 \begin_layout Standard
34155
34156 \size footnotesize
34157 \begin_inset LatexCommand url
34158 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34159
34160 \end_inset
34161
34162
34163 \end_layout
34164
34165 \end_inset
34166 </cell>
34167 </row>
34168 <row topline="true">
34169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34170 \begin_inset Text
34171
34172 \begin_layout Standard
34173
34174 \size footnotesize
34175 Ramtron / Goal Semiconductor
34176 \end_layout
34177
34178 \end_inset
34179 </cell>
34180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34181 \begin_inset Text
34182
34183 \begin_layout Standard
34184
34185 \size footnotesize
34186 Interfacing SDCC to Syn and Textpad
34187 \end_layout
34188
34189 \end_inset
34190 </cell>
34191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34192 \begin_inset Text
34193
34194 \begin_layout Standard
34195
34196 \size footnotesize
34197 \begin_inset LatexCommand url
34198 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34199
34200 \end_inset
34201
34202
34203 \end_layout
34204
34205 \end_inset
34206 </cell>
34207 </row>
34208 <row topline="true">
34209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34210 \begin_inset Text
34211
34212 \begin_layout Standard
34213
34214 \size footnotesize
34215 Ramtron / Goal Semiconductor
34216 \end_layout
34217
34218 \end_inset
34219 </cell>
34220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34221 \begin_inset Text
34222
34223 \begin_layout Standard
34224
34225 \size footnotesize
34226 Installing and Configuring SDCC and Crimson Editor 
34227 \end_layout
34228
34229 \end_inset
34230 </cell>
34231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34232 \begin_inset Text
34233
34234 \begin_layout Standard
34235
34236 \size footnotesize
34237 \begin_inset LatexCommand url
34238 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34239
34240 \end_inset
34241
34242
34243 \end_layout
34244
34245 \end_inset
34246 </cell>
34247 </row>
34248 <row topline="true" bottomline="true">
34249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34250 \begin_inset Text
34251
34252 \begin_layout Standard
34253
34254 \size footnotesize
34255 Texas Instruments
34256 \end_layout
34257
34258 \end_inset
34259 </cell>
34260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34261 \begin_inset Text
34262
34263 \begin_layout Standard
34264
34265 \size footnotesize
34266 MSC12xx Programming with SDCC
34267 \end_layout
34268
34269 \end_inset
34270 </cell>
34271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34272 \begin_inset Text
34273
34274 \begin_layout Standard
34275
34276 \size footnotesize
34277 \begin_inset LatexCommand url
34278 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34279
34280 \end_inset
34281
34282
34283 \end_layout
34284
34285 \end_inset
34286 </cell>
34287 </row>
34288 </lyxtabular>
34289
34290 \end_inset
34291
34292
34293 \end_layout
34294
34295 \begin_layout Section
34296 Some Questions
34297 \end_layout
34298
34299 \begin_layout Standard
34300 Some questions answered, some pointers given - it might be time to in turn
34301  ask 
34302 \emph on
34303 you
34304 \emph default
34305  some questions: 
34306 \end_layout
34307
34308 \begin_layout Itemize
34309 can you solve your project with the selected microcontroller? Would you
34310  find out early or rather late that your target is too small/slow/whatever?
34311  Can you switch to a slightly better device if it doesn't fit?
34312 \end_layout
34313
34314 \begin_layout Itemize
34315 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34316  and/or another programming language be more adequate? Would an operating
34317  system on the target device help?
34318 \end_layout
34319
34320 \begin_layout Itemize
34321 if you solved the problem, will the marketing department be happy?
34322 \end_layout
34323
34324 \begin_layout Itemize
34325 if the marketing department is happy, will customers be happy?
34326 \end_layout
34327
34328 \begin_layout Itemize
34329 if you're the project manager, marketing department and maybe even the customer
34330  in one person, have you tried to see the project from the outside?
34331 \end_layout
34332
34333 \begin_layout Itemize
34334 is the project done if you think it is done? Or is just that other interface/pro
34335 tocol/feature/configuration/option missing? How about website, manual(s),
34336  internationali(z|s)ation, packaging, labels, 2nd source for components,
34337  electromagnetic compatability/interference, documentation for production,
34338  production test software, update mechanism, patent issues?
34339 \end_layout
34340
34341 \begin_layout Itemize
34342 is your project adequately positioned in that magic triangle: fame, fortune,
34343  fun?
34344 \end_layout
34345
34346 \begin_layout Standard
34347 Maybe not all answers to these questions are known and some answers may
34348  even be 
34349 \emph on
34350 no
34351 \emph default
34352 , nevertheless knowing these questions may help you to avoid burnout
34353 \begin_inset Foot
34354 status open
34355
34356 \begin_layout Standard
34357 burnout is bad for electronic devices, programmers and motorcycle tyres
34358 \end_layout
34359
34360 \end_inset
34361
34362 .
34363  Chances are you didn't want to hear some of them...
34364 \end_layout
34365
34366 \begin_layout Chapter
34367 Support
34368 \begin_inset LatexCommand index
34369 name "Support"
34370
34371 \end_inset
34372
34373
34374 \end_layout
34375
34376 \begin_layout Standard
34377 SDCC has grown to be a large project.
34378  The compiler alone (without the preprocessor, assembler and linker) is
34379  well over 150,000 lines of code (blank stripped).
34380  The open source nature of this project is a key to its continued growth
34381  and support.
34382  You gain the benefit and support of many active software developers and
34383  end users.
34384  Is SDCC perfect? No, that's why we need your help.
34385  The developers take pride in fixing reported bugs.
34386  You can help by reporting the bugs and helping other SDCC users.
34387  There are lots of ways to contribute, and we encourage you to take part
34388  in making SDCC a great software package.
34389  
34390 \end_layout
34391
34392 \begin_layout Standard
34393 The SDCC project is hosted on the SDCC sourceforge site at 
34394 \begin_inset LatexCommand htmlurl
34395 target "http://sourceforge.net/projects/sdcc"
34396
34397 \end_inset
34398
34399 .
34400  You'll find the complete set of mailing lists
34401 \begin_inset LatexCommand index
34402 name "Mailing list(s)"
34403
34404 \end_inset
34405
34406 , forums, bug reporting system, patch submission
34407 \begin_inset LatexCommand index
34408 name "Patch submission"
34409
34410 \end_inset
34411
34412  system, download
34413 \begin_inset LatexCommand index
34414 name "download"
34415
34416 \end_inset
34417
34418  area and Subversion code repository
34419 \begin_inset LatexCommand index
34420 name "Subversion code repository"
34421
34422 \end_inset
34423
34424  there.
34425 \end_layout
34426
34427 \begin_layout Section
34428 Reporting Bugs
34429 \begin_inset LatexCommand index
34430 name "Bug reporting"
34431
34432 \end_inset
34433
34434
34435 \begin_inset LatexCommand index
34436 name "Reporting bugs"
34437
34438 \end_inset
34439
34440
34441 \end_layout
34442
34443 \begin_layout Standard
34444 The recommended way of reporting bugs is using the infrastructure of the
34445  sourceforge site.
34446  You can follow the status of bug reports there and have an overview about
34447  the known bugs.
34448 \end_layout
34449
34450 \begin_layout Standard
34451 Bug reports are automatically forwarded to the developer mailing list and
34452  will be fixed ASAP.
34453  When reporting a bug, it is very useful to include a small test program
34454  (the smaller the better) which reproduces the problem.
34455  If you can isolate the problem by looking at the generated assembly code,
34456  this can be very helpful.
34457  Compiling your program with the -
34458 \begin_inset ERT
34459 status collapsed
34460
34461 \begin_layout Standard
34462
34463
34464 \backslash
34465 /
34466 \end_layout
34467
34468 \end_inset
34469
34470 -dumpall
34471 \begin_inset LatexCommand index
34472 name "-\\/-dumpall"
34473
34474 \end_inset
34475
34476  option can sometimes be useful in locating optimization problems.
34477  When reporting a bug please make sure you:
34478 \end_layout
34479
34480 \begin_layout Enumerate
34481 Attach the code you are compiling with SDCC.
34482  
34483 \end_layout
34484
34485 \begin_layout Enumerate
34486 Specify the exact command you use to run SDCC, or attach your Makefile.
34487  
34488 \end_layout
34489
34490 \begin_layout Enumerate
34491 Specify the SDCC version (type "
34492 \family sans
34493 \series bold
34494 sdcc -v
34495 \family default
34496 \series default
34497 "), your platform, and operating system.
34498  
34499 \end_layout
34500
34501 \begin_layout Enumerate
34502 Provide an exact copy of any error message or incorrect output.
34503  
34504 \end_layout
34505
34506 \begin_layout Enumerate
34507 Put something meaningful in the subject of your message.
34508 \end_layout
34509
34510 \begin_layout Standard
34511 Please attempt to include these 5 important parts, as applicable, in all
34512  requests for support or when reporting any problems or bugs with SDCC.
34513  Though this will make your message lengthy, it will greatly improve your
34514  chance that SDCC users and developers will be able to help you.
34515  Some SDCC developers are frustrated by bug reports without code provided
34516  that they can use to reproduce and ultimately fix the problem, so please
34517  be sure to provide sample code if you are reporting a bug! 
34518 \end_layout
34519
34520 \begin_layout Standard
34521 Please have a short check that you are using a recent version of SDCC and
34522  the bug is not yet known.
34523  This is the link for reporting bugs: 
34524 \begin_inset LatexCommand htmlurl
34525 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34526
34527 \end_inset
34528
34529 .
34530  With SDCC on average having more than 200 downloads
34531 \begin_inset LatexCommand index
34532 name "download"
34533
34534 \end_inset
34535
34536  on sourceforge per day
34537 \begin_inset Foot
34538 status open
34539
34540 \begin_layout Standard
34541 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34542  between 2002 and 2005.
34543  This does not include other methods of distribution.
34544 \end_layout
34545
34546 \end_inset
34547
34548  there must be some users.
34549  So it's not exactly easy to find a new bug.
34550  If you find one we need it: 
34551 \emph on
34552 reporting bugs is good
34553 \emph default
34554 .
34555 \end_layout
34556
34557 \begin_layout Section
34558 Requesting Features
34559 \begin_inset LatexCommand label
34560 name "sub:Requesting-Features"
34561
34562 \end_inset
34563
34564
34565 \begin_inset LatexCommand index
34566 name "Feature request"
34567
34568 \end_inset
34569
34570
34571 \begin_inset LatexCommand index
34572 name "Requesting features"
34573
34574 \end_inset
34575
34576
34577 \end_layout
34578
34579 \begin_layout Standard
34580 Like bug reports feature requests are forwarded to the developer mailing
34581  list.
34582  This is the link for requesting features: 
34583 \begin_inset LatexCommand htmlurl
34584 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34585
34586 \end_inset
34587
34588 .
34589 \end_layout
34590
34591 \begin_layout Section
34592 Submitting patches
34593 \end_layout
34594
34595 \begin_layout Standard
34596 Like bug reports contributed patches are forwarded to the developer mailing
34597  list.
34598  This is the link for submitting patches
34599 \begin_inset LatexCommand index
34600 name "Patch submission"
34601
34602 \end_inset
34603
34604
34605 \begin_inset LatexCommand url
34606 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34607
34608 \end_inset
34609
34610 .
34611 \end_layout
34612
34613 \begin_layout Standard
34614 You need to specify some parameters to the 
34615 \family typewriter
34616 diff
34617 \family default
34618  command for the patches to be useful.
34619  If you modified more than one file a patch created f.e.
34620  with 
34621 \family sans
34622 \series bold
34623
34624 \begin_inset Quotes sld
34625 \end_inset
34626
34627 diff -Naur unmodified_directory modified_directory >my_changes.patch
34628 \begin_inset Quotes srd
34629 \end_inset
34630
34631
34632 \family default
34633 \series default
34634  will be fine, otherwise 
34635 \family sans
34636 \series bold
34637
34638 \begin_inset Quotes sld
34639 \end_inset
34640
34641 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34642 \begin_inset Quotes srd
34643 \end_inset
34644
34645
34646 \family default
34647 \series default
34648  will do.
34649 \end_layout
34650
34651 \begin_layout Section
34652 Getting Help
34653 \end_layout
34654
34655 \begin_layout Standard
34656 These links should take you directly to the 
34657 \begin_inset LatexCommand url
34658 name "Mailing lists"
34659 target "http://sourceforge.net/mail/?group_id=599"
34660
34661 \end_inset
34662
34663
34664 \begin_inset Foot
34665 status open
34666
34667 \begin_layout Standard
34668 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34669  automated messages (mid 2003)
34670 \end_layout
34671
34672 \end_inset
34673
34674  and the 
34675 \begin_inset LatexCommand url
34676 name "Forums"
34677 target "http://sourceforge.net/forum/?group_id=599"
34678
34679 \end_inset
34680
34681 , lists
34682 \begin_inset LatexCommand index
34683 name "Mailing list(s)"
34684
34685 \end_inset
34686
34687  and forums are archived and searchable so if you are lucky someone already
34688  had a similar problem.
34689  While mails to the lists themselves are delivered promptly their web front
34690  end on sourceforge sometimes shows a severe time lag (up to several weeks),
34691  if you're seriously using SDCC please consider subscribing to the lists.
34692 \end_layout
34693
34694 \begin_layout Section
34695 ChangeLog
34696 \end_layout
34697
34698 \begin_layout Standard
34699 You can follow the status of the Subversion version
34700 \begin_inset LatexCommand index
34701 name "version"
34702
34703 \end_inset
34704
34705  of SDCC by watching the Changelog
34706 \begin_inset LatexCommand index
34707 name "Changelog"
34708
34709 \end_inset
34710
34711  in the Subversion repository
34712 \size footnotesize
34713  
34714 \begin_inset LatexCommand htmlurl
34715 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34716
34717 \end_inset
34718
34719 .
34720 \end_layout
34721
34722 \begin_layout Section
34723 Subversion Source Code Repository
34724 \end_layout
34725
34726 \begin_layout Standard
34727 The output of 
34728 \family sans
34729 \series bold
34730 sdcc -
34731 \family default
34732
34733 \begin_inset ERT
34734 status open
34735
34736 \begin_layout Standard
34737
34738
34739 \backslash
34740 /
34741 \end_layout
34742
34743 \end_inset
34744
34745
34746 \family sans
34747 -version
34748 \family default
34749 \series default
34750  or the filenames of the snapshot versions of SDCC include date and its
34751  Subversion
34752 \begin_inset LatexCommand index
34753 name "Subversion code repository"
34754
34755 \end_inset
34756
34757  number.
34758  Subversion allows to download the source of recent or previous versions
34759  
34760 \begin_inset LatexCommand url
34761 target "http://sourceforge.net/svn/?group_id=599"
34762
34763 \end_inset
34764
34765  (by number or by date).
34766  An on-line source code browser and detailled instructions are also available
34767  there.
34768  SDCC versions starting from 1999 up to now are available (currently the
34769  versions prior to the conversion from cvs
34770 \begin_inset LatexCommand index
34771 name "cvs|see{Subversion}"
34772
34773 \end_inset
34774
34775  to Subversion (April 2006) are either by accessible by Subversion or by
34776  cvs).
34777 \end_layout
34778
34779 \begin_layout Section
34780 Release policy
34781 \begin_inset LatexCommand index
34782 name "Release policy"
34783
34784 \end_inset
34785
34786
34787 \end_layout
34788
34789 \begin_layout Standard
34790 Historically there often were long delays between official releases and
34791  the sourceforge download area tends to get not updated at all.
34792  Excuses in the past might have referred to problems with live range analysis,
34793  but as this was fixed a while ago, the current problem is that another
34794  excuse has to be found.
34795  Kidding aside, we have to get better there! On the other hand there are
34796  daily snapshots available at 
34797 \begin_inset LatexCommand htmlurl
34798 name "snap"
34799 target "http://sdcc.sourceforge.net/snap.php"
34800
34801 \end_inset
34802
34803 , and you can always build the very last version (hopefully with many bugs
34804  fixed, and features added) from the source code available at 
34805 \begin_inset LatexCommand htmlurl
34806 name "Source"
34807 target "http://sdcc.sourceforge.net/snap.php#Source"
34808
34809 \end_inset
34810
34811 .
34812  The SDCC Wiki
34813 \begin_inset LatexCommand index
34814 name "wiki"
34815
34816 \end_inset
34817
34818
34819 \begin_inset LatexCommand index
34820 name "SDCC Wiki"
34821
34822 \end_inset
34823
34824  at 
34825 \begin_inset LatexCommand url
34826 target "http://sdcc.wiki.sourceforge.net/"
34827
34828 \end_inset
34829
34830  also holds some information about past and future releases.
34831 \end_layout
34832
34833 \begin_layout Section
34834 Examples
34835 \begin_inset LatexCommand index
34836 name "Examples"
34837
34838 \end_inset
34839
34840
34841 \end_layout
34842
34843 \begin_layout Standard
34844 You'll find some small examples in the directory 
34845 \emph on
34846 sdcc/device/examples/.
34847
34848 \emph default
34849  More examples and libraries are available at 
34850 \emph on
34851 The SDCC Open Knowledge Resource 
34852 \begin_inset LatexCommand url
34853 target "http://sdccokr.dl9sec.de/"
34854
34855 \end_inset
34856
34857
34858 \emph default
34859  web site or at 
34860 \begin_inset LatexCommand url
34861 target "http://www.pjrc.com/tech/8051/"
34862
34863 \end_inset
34864
34865 .
34866 \end_layout
34867
34868 \begin_layout Standard
34869 \begin_inset Note Note
34870 status collapsed
34871
34872 \begin_layout Standard
34873 I did insert a reference to Paul's web site here although it seems rather
34874  dedicated to a specific 8032 board (I think it's okay because it f.e.
34875  shows LCD/Harddisc interface and has a free 8051 monitor.
34876  Independent 8032 board vendors face hard competition of heavily subsidized
34877  development boards anyway).
34878 \end_layout
34879
34880 \begin_layout Standard
34881 Maybe we should include some links to real world applications.
34882  Preferably pointer to pointers (one for each architecture) so this stays
34883  manageable here?
34884 \end_layout
34885
34886 \end_inset
34887
34888
34889 \end_layout
34890
34891 \begin_layout Section
34892 Quality control
34893 \begin_inset LatexCommand label
34894 name "sec:Quality-control"
34895
34896 \end_inset
34897
34898
34899 \begin_inset LatexCommand index
34900 name "Quality control"
34901
34902 \end_inset
34903
34904
34905 \end_layout
34906
34907 \begin_layout Standard
34908 The compiler is passed through snaphot build compile and build checks.
34909  The so called 
34910 \shape italic
34911 regression tests
34912 \shape default
34913
34914 \begin_inset LatexCommand index
34915 name "Regression test"
34916
34917 \end_inset
34918
34919  check that SDCC itself compiles flawlessly on several host platforms (i386,
34920  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
34921  and checks the quality of the code generated by SDCC by running the code
34922  for several target platforms through simulators.
34923  The regression test suite comprises more than 100 files which expand to
34924  more than 500 test cases which include more than 4500 tests.
34925  The results of these tests are published daily on SDCC's snapshot page
34926  (click on the red or green symbols on the right side of 
34927 \begin_inset LatexCommand url
34928 target "http://sdcc.sourceforge.net/snap.php"
34929
34930 \end_inset
34931
34932 ).
34933 \end_layout
34934
34935 \begin_layout Standard
34936 There is a separate document 
34937 \shape italic
34938 test_suite.pdf 
34939 \begin_inset LatexCommand index
34940 name "Test suite"
34941
34942 \end_inset
34943
34944
34945 \shape default
34946  
34947 \begin_inset LatexCommand url
34948 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
34949
34950 \end_inset
34951
34952  about the regression test suite.
34953 \end_layout
34954
34955 \begin_layout Standard
34956 You'll find the test code in the directory 
34957 \shape italic
34958 sdcc/support/regression
34959 \shape default
34960 .
34961  You can run these tests manually by running 
34962 \family sans
34963 make
34964 \family default
34965  in this directory (or f.e.
34966  
34967 \family sans
34968 \series bold
34969
34970 \begin_inset Quotes sld
34971 \end_inset
34972
34973 make test-mcs51
34974 \begin_inset Quotes srd
34975 \end_inset
34976
34977
34978 \family default
34979 \series default
34980  if you don't want to run the complete tests).
34981  The test code might also be interesting if you want to look for examples
34982 \begin_inset LatexCommand index
34983 name "Examples"
34984
34985 \end_inset
34986
34987  checking corner cases of SDCC or if you plan to submit patches
34988 \begin_inset LatexCommand index
34989 name "Patch submission"
34990
34991 \end_inset
34992
34993 .
34994 \end_layout
34995
34996 \begin_layout Standard
34997 The PIC14 port uses a different set of regression tests 
34998 \begin_inset LatexCommand index
34999 name "Regression test (PIC14)"
35000
35001 \end_inset
35002
35003 , you'll find them in the directory 
35004 \shape italic
35005 sdcc/src/regression
35006 \shape default
35007 .
35008 \end_layout
35009
35010 \begin_layout Section
35011 Use of SDCC in Education
35012 \end_layout
35013
35014 \begin_layout Standard
35015 In short: 
35016 \emph on
35017 highly
35018 \emph default
35019  encouraged
35020 \begin_inset Foot
35021 status open
35022
35023 \begin_layout Standard
35024 the phrase "use in education" might evoke the association "
35025 \emph on
35026 only
35027 \emph default
35028  fit for use in education".
35029  This connotation is not intended but nevertheless risked as the licensing
35030  of SDCC makes it difficult to offer educational discounts
35031 \end_layout
35032
35033 \end_inset
35034
35035 .
35036  If your rationales are to:
35037 \end_layout
35038
35039 \begin_layout Enumerate
35040 give students a chance to understand the 
35041 \emph on
35042 complete
35043 \emph default
35044  steps of code generation
35045 \end_layout
35046
35047 \begin_layout Enumerate
35048 have a curriculum that can be extended for years.
35049  Then you could use an fpga board as target and your curriculum will seamlessly
35050  extend from logic synthesis (
35051 \begin_inset LatexCommand url
35052 name "http://www.opencores.org"
35053 target "opencores.org"
35054
35055 \end_inset
35056
35057
35058 \begin_inset LatexCommand url
35059 name "Oregano"
35060 target "http://www.oregano.at/ip/ip01.htm"
35061
35062 \end_inset
35063
35064 ), over assembly programming, to C to FPGA compilers (
35065 \begin_inset LatexCommand url
35066 name "FPGAC"
35067 target "http://sf.net/projects/fpgac"
35068
35069 \end_inset
35070
35071 ) and to C.
35072 \end_layout
35073
35074 \begin_layout Enumerate
35075 be able to insert excursions about skills like using a revision control
35076  system, submitting/applying patches, using a type-setting (as opposed to
35077  word-processing) engine LyX/LaTeX, using 
35078 \begin_inset LatexCommand url
35079 name "SourceForge"
35080 target "http://www.sf.net"
35081
35082 \end_inset
35083
35084 , following some 
35085 \begin_inset LatexCommand url
35086 name "netiquette"
35087 target "http://en.wikipedia.org/wiki/Netiquette"
35088
35089 \end_inset
35090
35091 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35092  Source Software, CPU simulation, compiler regression tests
35093 \begin_inset LatexCommand index
35094 name "Regression test"
35095
35096 \end_inset
35097
35098 .
35099  
35100 \newline
35101 And if there should be a shortage of ideas then you can always point students
35102  to the ever-growing feature request list 
35103 \begin_inset LatexCommand htmlurl
35104 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35105
35106 \end_inset
35107
35108 .
35109 \end_layout
35110
35111 \begin_layout Enumerate
35112 not tie students to a specific host platform and instead allow them to use
35113  a host platform of 
35114 \emph on
35115 their
35116 \emph default
35117  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35118  and eventually 
35119 \begin_inset LatexCommand url
35120 name "OLPC"
35121 target "http://www.laptop.org"
35122
35123 \end_inset
35124
35125 )
35126 \end_layout
35127
35128 \begin_layout Enumerate
35129 not encourage students to use illegal copies of educational software
35130 \end_layout
35131
35132 \begin_layout Enumerate
35133 be immune to licensing/availability/price changes of the chosen tool chain
35134 \end_layout
35135
35136 \begin_layout Enumerate
35137 be able to change to a new target platform without having to adopt a new
35138  tool chain
35139 \end_layout
35140
35141 \begin_layout Enumerate
35142 have complete control over and insight into the tool chain
35143 \end_layout
35144
35145 \begin_layout Enumerate
35146 make your students aware about the pros and cons of open source software
35147  development
35148 \end_layout
35149
35150 \begin_layout Enumerate
35151 give back to the public as you are probably at least partially publicly
35152  funded
35153 \end_layout
35154
35155 \begin_layout Enumerate
35156 give students a chance to publicly prove their skills and to possibly see
35157  a world wide impact
35158 \end_layout
35159
35160 \begin_layout Standard
35161 then SDCC is probably among the first choices.
35162  Well, probably SDCC might be the only choice.
35163 \newpage
35164
35165 \end_layout
35166
35167 \begin_layout Chapter
35168 SDCC Technical Data
35169 \end_layout
35170
35171 \begin_layout Section
35172 Optimizations
35173 \begin_inset LatexCommand index
35174 name "Optimizations"
35175
35176 \end_inset
35177
35178
35179 \end_layout
35180
35181 \begin_layout Standard
35182 SDCC performs a host of standard optimizations in addition to some MCU specific
35183  optimizations.
35184  
35185 \end_layout
35186
35187 \begin_layout Subsection
35188 Sub-expression Elimination
35189 \begin_inset LatexCommand index
35190 name "Subexpression elimination"
35191
35192 \end_inset
35193
35194
35195 \end_layout
35196
35197 \begin_layout Standard
35198 The compiler does local and 
35199 \emph on
35200 g
35201 \emph default
35202 lobal 
35203 \emph on
35204 c
35205 \emph default
35206 ommon 
35207 \emph on
35208 s
35209 \emph default
35210 ubexpression 
35211 \emph on
35212 e
35213 \emph default
35214 limination, e.g.: 
35215 \end_layout
35216
35217 \begin_layout Verse
35218
35219 \family typewriter
35220 i = x + y + 1; 
35221 \newline
35222 j = x + y;
35223 \end_layout
35224
35225 \begin_layout Standard
35226 will be translated to
35227 \end_layout
35228
35229 \begin_layout Verse
35230
35231 \family typewriter
35232 iTemp = x + y; 
35233 \newline
35234 i = iTemp + 1; 
35235 \newline
35236 j = iTemp;
35237 \end_layout
35238
35239 \begin_layout Standard
35240 Some subexpressions are not as obvious as the above example, e.g.:
35241 \end_layout
35242
35243 \begin_layout Verse
35244
35245 \family typewriter
35246 a->b[i].c = 10; 
35247 \newline
35248 a->b[i].d = 11;
35249 \end_layout
35250
35251 \begin_layout Standard
35252 In this case the address arithmetic a->b[i] will be computed only once;
35253  the equivalent code in C would be.
35254 \end_layout
35255
35256 \begin_layout Verse
35257
35258 \family typewriter
35259 iTemp = a->b[i]; 
35260 \newline
35261 iTemp.c = 10; 
35262 \newline
35263 iTemp.d = 11;
35264 \end_layout
35265
35266 \begin_layout Standard
35267 The compiler will try to keep these temporary variables in registers.
35268 \end_layout
35269
35270 \begin_layout Subsection
35271 Dead-Code Elimination
35272 \begin_inset LatexCommand index
35273 name "Dead-code elimination"
35274
35275 \end_inset
35276
35277
35278 \end_layout
35279
35280 \begin_layout Verse
35281
35282 \family typewriter
35283 int global;
35284 \newline
35285
35286 \newline
35287 void f () { 
35288 \newline
35289 \InsetSpace ~
35290 \InsetSpace ~
35291 int i; 
35292 \newline
35293 \InsetSpace ~
35294 \InsetSpace ~
35295 i = 1; \InsetSpace ~
35296 \InsetSpace ~
35297 \InsetSpace ~
35298 \InsetSpace ~
35299 \InsetSpace ~
35300 /* dead store */ 
35301 \newline
35302 \InsetSpace ~
35303 \InsetSpace ~
35304 global = 1;\InsetSpace ~
35305 /* dead
35306  store */ 
35307 \newline
35308 \InsetSpace ~
35309 \InsetSpace ~
35310 global = 2; 
35311 \newline
35312 \InsetSpace ~
35313 \InsetSpace ~
35314 return; 
35315 \newline
35316 \InsetSpace ~
35317 \InsetSpace ~
35318 global = 3;\InsetSpace ~
35319 /* unreachable */ 
35320 \newline
35321 }
35322 \end_layout
35323
35324 \begin_layout Standard
35325 will be changed to
35326 \end_layout
35327
35328 \begin_layout Verse
35329
35330 \family typewriter
35331 int global;
35332 \newline
35333
35334 \newline
35335 void f () {
35336 \newline
35337 \InsetSpace ~
35338 \InsetSpace ~
35339 global = 2; 
35340 \newline
35341 }
35342 \end_layout
35343
35344 \begin_layout Subsection
35345 Copy-Propagation
35346 \begin_inset LatexCommand index
35347 name "Copy propagation"
35348
35349 \end_inset
35350
35351
35352 \end_layout
35353
35354 \begin_layout Verse
35355
35356 \family typewriter
35357 int f() { 
35358 \newline
35359 \InsetSpace ~
35360 \InsetSpace ~
35361 int i, j; 
35362 \newline
35363 \InsetSpace ~
35364 \InsetSpace ~
35365 i = 10; 
35366 \newline
35367 \InsetSpace ~
35368 \InsetSpace ~
35369 j = i; 
35370 \newline
35371 \InsetSpace ~
35372 \InsetSpace ~
35373 return j; 
35374 \newline
35375 }
35376 \end_layout
35377
35378 \begin_layout Standard
35379 will be changed to 
35380 \end_layout
35381
35382 \begin_layout Verse
35383
35384 \family typewriter
35385 int f() { 
35386 \newline
35387 \InsetSpace ~
35388 \InsetSpace ~
35389 int i, j; 
35390 \newline
35391 \InsetSpace ~
35392 \InsetSpace ~
35393 i = 10; 
35394 \newline
35395 \InsetSpace ~
35396 \InsetSpace ~
35397 j = 10; 
35398 \newline
35399 \InsetSpace ~
35400 \InsetSpace ~
35401 return 10; 
35402 \newline
35403 }
35404 \end_layout
35405
35406 \begin_layout Standard
35407 Note: the dead stores created by this copy propagation will be eliminated
35408  by dead-code elimination.
35409 \end_layout
35410
35411 \begin_layout Subsection
35412 Loop Optimizations
35413 \begin_inset LatexCommand index
35414 name "Loop optimization"
35415
35416 \end_inset
35417
35418
35419 \begin_inset LatexCommand label
35420 name "sub:Loop-Optimizations"
35421
35422 \end_inset
35423
35424
35425 \end_layout
35426
35427 \begin_layout Standard
35428 Two types of loop optimizations are done by SDCC 
35429 \emph on
35430 loop invariant
35431 \emph default
35432  lifting and 
35433 \emph on
35434 strength reduction
35435 \emph default
35436  of loop induction variables.
35437  In addition to the strength reduction the optimizer marks the induction
35438  variables and the register allocator tries to keep the induction variables
35439  in registers for the duration of the loop.
35440  Because of this preference of the register allocator
35441 \begin_inset LatexCommand index
35442 name "Register allocation"
35443
35444 \end_inset
35445
35446 , loop induction optimization causes an increase in register pressure, which
35447  may cause unwanted spilling of other temporary variables into the stack
35448 \begin_inset LatexCommand index
35449 name "stack"
35450
35451 \end_inset
35452
35453  / data space.
35454  The compiler will generate a warning message when it is forced to allocate
35455  extra space either on the stack or data space.
35456  If this extra space allocation is undesirable then induction optimization
35457  can be eliminated either for the entire source file (with -
35458 \begin_inset ERT
35459 status collapsed
35460
35461 \begin_layout Standard
35462
35463
35464 \backslash
35465 /
35466 \end_layout
35467
35468 \end_inset
35469
35470 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35471 noinduction
35472 \begin_inset LatexCommand index
35473 name "\\#pragma noinduction"
35474
35475 \end_inset
35476
35477 .
35478 \newline
35479
35480 \newline
35481 Loop Invariant:
35482 \end_layout
35483
35484 \begin_layout Verse
35485
35486 \family typewriter
35487 for (i = 0 ; i < 100 ; i ++) 
35488 \newline
35489 \InsetSpace ~
35490 \InsetSpace ~
35491 \InsetSpace ~
35492 \InsetSpace ~
35493 f += k + l;
35494 \end_layout
35495
35496 \begin_layout Standard
35497 changed to
35498 \end_layout
35499
35500 \begin_layout Verse
35501
35502 \family typewriter
35503 itemp = k + l; 
35504 \newline
35505 for (i = 0; i < 100; i++) 
35506 \newline
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510 \InsetSpace ~
35511 f += itemp;
35512 \end_layout
35513
35514 \begin_layout Standard
35515 As mentioned previously some loop invariants are not as apparent, all static
35516  address computations are also moved out of the loop.
35517 \newline
35518
35519 \newline
35520 Strength Reduction
35521 \begin_inset LatexCommand index
35522 name "Strength reduction"
35523
35524 \end_inset
35525
35526 , this optimization substitutes an expression by a cheaper expression:
35527 \end_layout
35528
35529 \begin_layout Verse
35530
35531 \family typewriter
35532 for (i=0;i < 100; i++)
35533 \newline
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 ar[i*5] = i*3;
35539 \end_layout
35540
35541 \begin_layout Standard
35542 changed to
35543 \end_layout
35544
35545 \begin_layout Verse
35546
35547 \family typewriter
35548 itemp1 = 0; 
35549 \newline
35550 itemp2 = 0; 
35551 \newline
35552 for (i=0;i< 100;i++) { 
35553 \newline
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 \InsetSpace ~
35558 ar[itemp1] = itemp2; 
35559 \newline
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 itemp1
35565  += 5; 
35566 \newline
35567 \InsetSpace ~
35568 \InsetSpace ~
35569 \InsetSpace ~
35570 \InsetSpace ~
35571 itemp2 += 3; 
35572 \newline
35573 }
35574 \end_layout
35575
35576 \begin_layout Standard
35577 The more expensive multiplication
35578 \begin_inset LatexCommand index
35579 name "Multiplication"
35580
35581 \end_inset
35582
35583  is changed to a less expensive addition.
35584 \end_layout
35585
35586 \begin_layout Subsection
35587 Loop Reversing
35588 \begin_inset LatexCommand index
35589 name "Loop reversing"
35590
35591 \end_inset
35592
35593
35594 \end_layout
35595
35596 \begin_layout Standard
35597 This optimization is done to reduce the overhead of checking loop boundaries
35598  for every iteration.
35599  Some simple loops can be reversed and implemented using a 
35600 \begin_inset Quotes eld
35601 \end_inset
35602
35603 decrement and jump if not zero
35604 \begin_inset Quotes erd
35605 \end_inset
35606
35607  instruction.
35608  SDCC checks for the following criterion to determine if a loop is reversible
35609  (note: more sophisticated compilers use data-dependency analysis to make
35610  this determination, SDCC uses a more simple minded analysis).
35611 \end_layout
35612
35613 \begin_layout Itemize
35614 The 'for' loop is of the form 
35615 \newline
35616
35617 \newline
35618
35619 \family typewriter
35620 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35621  += 1])
35622 \newline
35623 \InsetSpace ~
35624 \InsetSpace ~
35625 \InsetSpace ~
35626 \InsetSpace ~
35627 <for body>
35628 \end_layout
35629
35630 \begin_layout Itemize
35631 The <for body> does not contain 
35632 \begin_inset Quotes eld
35633 \end_inset
35634
35635 continue
35636 \begin_inset Quotes erd
35637 \end_inset
35638
35639  or 'break
35640 \begin_inset Quotes erd
35641 \end_inset
35642
35643 .
35644 \end_layout
35645
35646 \begin_layout Itemize
35647 All goto's are contained within the loop.
35648 \end_layout
35649
35650 \begin_layout Itemize
35651 No function calls within the loop.
35652 \end_layout
35653
35654 \begin_layout Itemize
35655 The loop control variable <sym> is not assigned any value within the loop
35656 \end_layout
35657
35658 \begin_layout Itemize
35659 The loop control variable does NOT participate in any arithmetic operation
35660  within the loop.
35661 \end_layout
35662
35663 \begin_layout Itemize
35664 There are NO switch statements in the loop.
35665 \end_layout
35666
35667 \begin_layout Subsection
35668 Algebraic Simplifications
35669 \end_layout
35670
35671 \begin_layout Standard
35672 SDCC does numerous algebraic simplifications, the following is a small sub-set
35673  of these optimizations.
35674 \end_layout
35675
35676 \begin_layout Verse
35677
35678 \family typewriter
35679 i = j + 0;\InsetSpace ~
35680 \InsetSpace ~
35681 \InsetSpace ~
35682 \InsetSpace ~
35683  /* changed to: */\InsetSpace ~
35684 \InsetSpace ~
35685 \InsetSpace ~
35686 \InsetSpace ~
35687  i = j; 
35688 \newline
35689 i /= 2;\InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 \InsetSpace ~
35693 \InsetSpace ~
35694 \InsetSpace ~
35695 \InsetSpace ~
35696  /* changed to: */\InsetSpace ~
35697 \InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700  i >>= 1; 
35701 \newline
35702 i
35703  = j - j;\InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707  /* changed to: */\InsetSpace ~
35708 \InsetSpace ~
35709 \InsetSpace ~
35710 \InsetSpace ~
35711  i = 0; 
35712 \newline
35713 i = j / 1;\InsetSpace ~
35714 \InsetSpace ~
35715 \InsetSpace ~
35716 \InsetSpace ~
35717  /* changed to: */\InsetSpace ~
35718 \InsetSpace ~
35719 \InsetSpace ~
35720 \InsetSpace ~
35721  i = j;
35722 \end_layout
35723
35724 \begin_layout Standard
35725 Note the subexpressions
35726 \begin_inset LatexCommand index
35727 name "Subexpression"
35728
35729 \end_inset
35730
35731  given above are generally introduced by macro expansions or as a result
35732  of copy/constant propagation.
35733 \end_layout
35734
35735 \begin_layout Subsection
35736 'switch' Statements
35737 \begin_inset LatexCommand label
35738 name "sub:'switch'-Statements"
35739
35740 \end_inset
35741
35742
35743 \begin_inset LatexCommand index
35744 name "switch statement"
35745
35746 \end_inset
35747
35748
35749 \end_layout
35750
35751 \begin_layout Standard
35752 SDCC can optimize switch statements to jump tables
35753 \begin_inset LatexCommand index
35754 name "jump tables"
35755
35756 \end_inset
35757
35758 .
35759  It makes the decision based on an estimate of the generated code size.
35760  SDCC is quite liberal in the requirements for jump table generation: 
35761 \end_layout
35762
35763 \begin_layout Itemize
35764 The labels need not be in order, and the starting number need not be one
35765  or zero, the case labels are in numerical sequence or not too many case
35766  labels are missing.
35767 \end_layout
35768
35769 \begin_deeper
35770 \begin_layout Verse
35771
35772 \family typewriter
35773 switch(i) {\InsetSpace ~
35774 \InsetSpace ~
35775 \InsetSpace ~
35776 \InsetSpace ~
35777 \InsetSpace ~
35778 \InsetSpace ~
35779 \InsetSpace ~
35780 \InsetSpace ~
35781 \InsetSpace ~
35782 \InsetSpace ~
35783 \InsetSpace ~
35784 \InsetSpace ~
35785 \InsetSpace ~
35786 \InsetSpace ~
35787 \InsetSpace ~
35788 \InsetSpace ~
35789 \InsetSpace ~
35790 \InsetSpace ~
35791 \InsetSpace ~
35792 \InsetSpace ~
35793 \InsetSpace ~
35794 \InsetSpace ~
35795 \InsetSpace ~
35796 \InsetSpace ~
35797 \InsetSpace ~
35798 \InsetSpace ~
35799 switch (i) { 
35800 \newline
35801 \InsetSpace ~
35802 \InsetSpace ~
35803 \InsetSpace ~
35804 case 4: ...\InsetSpace ~
35805 \InsetSpace ~
35806 \InsetSpace ~
35807 \InsetSpace ~
35808 \InsetSpace ~
35809 \InsetSpace ~
35810 \InsetSpace ~
35811 \InsetSpace ~
35812 \InsetSpace ~
35813 \InsetSpace ~
35814 \InsetSpace ~
35815 \InsetSpace ~
35816 \InsetSpace ~
35817 \InsetSpace ~
35818 \InsetSpace ~
35819 \InsetSpace ~
35820 \InsetSpace ~
35821 \InsetSpace ~
35822 \InsetSpace ~
35823 \InsetSpace ~
35824 \InsetSpace ~
35825 \InsetSpace ~
35826 \InsetSpace ~
35827 \InsetSpace ~
35828 \InsetSpace ~
35829 \InsetSpace ~
35830 case 0: ...
35831  
35832 \newline
35833 \InsetSpace ~
35834 \InsetSpace ~
35835 \InsetSpace ~
35836 case 5: ...\InsetSpace ~
35837 \InsetSpace ~
35838 \InsetSpace ~
35839 \InsetSpace ~
35840 \InsetSpace ~
35841 \InsetSpace ~
35842 \InsetSpace ~
35843 \InsetSpace ~
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 \InsetSpace ~
35850 \InsetSpace ~
35851 \InsetSpace ~
35852 \InsetSpace ~
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 \InsetSpace ~
35856 \InsetSpace ~
35857 \InsetSpace ~
35858 \InsetSpace ~
35859 \InsetSpace ~
35860 \InsetSpace ~
35861 \InsetSpace ~
35862 case 1: ...
35863  
35864 \newline
35865 \InsetSpace ~
35866 \InsetSpace ~
35867 \InsetSpace ~
35868 case 3: ...\InsetSpace ~
35869 \InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872 \InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884 \InsetSpace ~
35885 \InsetSpace ~
35886 \InsetSpace ~
35887 \InsetSpace ~
35888 \InsetSpace ~
35889 \InsetSpace ~
35890 \InsetSpace ~
35891 \InsetSpace ~
35892 \InsetSpace ~
35893 \InsetSpace ~
35894
35895 \newline
35896 \InsetSpace ~
35897 \InsetSpace ~
35898 \InsetSpace ~
35899 case 6: ...\InsetSpace ~
35900 \InsetSpace ~
35901 \InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 \InsetSpace ~
35907 \InsetSpace ~
35908 \InsetSpace ~
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 \InsetSpace ~
35912 \InsetSpace ~
35913 \InsetSpace ~
35914 \InsetSpace ~
35915 \InsetSpace ~
35916 \InsetSpace ~
35917 \InsetSpace ~
35918 \InsetSpace ~
35919 \InsetSpace ~
35920 \InsetSpace ~
35921 \InsetSpace ~
35922 \InsetSpace ~
35923 \InsetSpace ~
35924 \InsetSpace ~
35925 case 3: ...
35926  
35927 \newline
35928 \InsetSpace ~
35929 \InsetSpace ~
35930 \InsetSpace ~
35931 case 7: ...\InsetSpace ~
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 case 4: ...
35958  
35959 \newline
35960 \InsetSpace ~
35961 \InsetSpace ~
35962 \InsetSpace ~
35963 case 8: ...\InsetSpace ~
35964 \InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969 \InsetSpace ~
35970 \InsetSpace ~
35971 \InsetSpace ~
35972 \InsetSpace ~
35973 \InsetSpace ~
35974 \InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 case 5: ...
35990  
35991 \newline
35992 \InsetSpace ~
35993 \InsetSpace ~
35994 \InsetSpace ~
35995 case 9: ...\InsetSpace ~
35996 \InsetSpace ~
35997 \InsetSpace ~
35998 \InsetSpace ~
35999 \InsetSpace ~
36000 \InsetSpace ~
36001 \InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 \InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019 \InsetSpace ~
36020 \InsetSpace ~
36021 case 6: ...
36022  
36023 \newline
36024 \InsetSpace ~
36025 \InsetSpace ~
36026 \InsetSpace ~
36027 case 10: ...\InsetSpace ~
36028 \InsetSpace ~
36029 \InsetSpace ~
36030 \InsetSpace ~
36031 \InsetSpace ~
36032 \InsetSpace ~
36033 \InsetSpace ~
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 \InsetSpace ~
36037 \InsetSpace ~
36038 \InsetSpace ~
36039 \InsetSpace ~
36040 \InsetSpace ~
36041 \InsetSpace ~
36042 \InsetSpace ~
36043 \InsetSpace ~
36044 \InsetSpace ~
36045 \InsetSpace ~
36046 \InsetSpace ~
36047 \InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050 \InsetSpace ~
36051 \InsetSpace ~
36052 case 7: ...
36053  
36054 \newline
36055 \InsetSpace ~
36056 \InsetSpace ~
36057 \InsetSpace ~
36058 case 11: ...\InsetSpace ~
36059 \InsetSpace ~
36060 \InsetSpace ~
36061 \InsetSpace ~
36062 \InsetSpace ~
36063 \InsetSpace ~
36064 \InsetSpace ~
36065 \InsetSpace ~
36066 \InsetSpace ~
36067 \InsetSpace ~
36068 \InsetSpace ~
36069 \InsetSpace ~
36070 \InsetSpace ~
36071 \InsetSpace ~
36072 \InsetSpace ~
36073 \InsetSpace ~
36074 \InsetSpace ~
36075 \InsetSpace ~
36076 \InsetSpace ~
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 \InsetSpace ~
36081 \InsetSpace ~
36082 \InsetSpace ~
36083 case 8: ...
36084  
36085 \newline
36086 }\InsetSpace ~
36087 \InsetSpace ~
36088 \InsetSpace ~
36089 \InsetSpace ~
36090 \InsetSpace ~
36091 \InsetSpace ~
36092 \InsetSpace ~
36093 \InsetSpace ~
36094 \InsetSpace ~
36095 \InsetSpace ~
36096 \InsetSpace ~
36097 \InsetSpace ~
36098 \InsetSpace ~
36099 \InsetSpace ~
36100 \InsetSpace ~
36101 \InsetSpace ~
36102 \InsetSpace ~
36103 \InsetSpace ~
36104 \InsetSpace ~
36105 \InsetSpace ~
36106 \InsetSpace ~
36107 \InsetSpace ~
36108 \InsetSpace ~
36109 \InsetSpace ~
36110 \InsetSpace ~
36111 \InsetSpace ~
36112 \InsetSpace ~
36113 \InsetSpace ~
36114 \InsetSpace ~
36115 \InsetSpace ~
36116 \InsetSpace ~
36117 \InsetSpace ~
36118 \InsetSpace ~
36119 \InsetSpace ~
36120 \InsetSpace ~
36121 \InsetSpace ~
36122 }
36123 \end_layout
36124
36125 \begin_layout Standard
36126 Both the above switch statements will be implemented using a jump-table.
36127  The example to the right side is slightly more efficient as the check for
36128  the lower boundary of the jump-table is not needed.
36129 \end_layout
36130
36131 \end_deeper
36132 \begin_layout Itemize
36133 The number of case labels is not larger than supported by the target architectur
36134 e.
36135 \end_layout
36136
36137 \begin_layout Itemize
36138 If the case labels are not in numerical sequence ('gaps' between cases)
36139  SDCC checks whether a jump table with additionally inserted dummy cases
36140  is still attractive.
36141  
36142 \end_layout
36143
36144 \begin_layout Itemize
36145 If the starting number is not zero and a check for the lower boundary of
36146  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36147  ...
36148  .
36149 \end_layout
36150
36151 \begin_layout Standard
36152 Switch statements which have large gaps in the numeric sequence or those
36153  that have too many case labels can be split into more than one switch statement
36154  for efficient code generation, e.g.:
36155 \end_layout
36156
36157 \begin_layout Verse
36158
36159 \family typewriter
36160 switch (i) { 
36161 \newline
36162 \InsetSpace ~
36163 \InsetSpace ~
36164 case 1: ...
36165  
36166 \newline
36167 \InsetSpace ~
36168 \InsetSpace ~
36169 case 2: ...
36170  
36171 \newline
36172 \InsetSpace ~
36173 \InsetSpace ~
36174 case 3: ...
36175  
36176 \newline
36177 \InsetSpace ~
36178 \InsetSpace ~
36179 case 4: ...
36180  
36181 \newline
36182 \InsetSpace ~
36183 \InsetSpace ~
36184 case 5: ...
36185  
36186 \newline
36187 \InsetSpace ~
36188 \InsetSpace ~
36189 case 6: ...
36190  
36191 \newline
36192 \InsetSpace ~
36193 \InsetSpace ~
36194 case 7: ...
36195  
36196 \newline
36197 \InsetSpace ~
36198 \InsetSpace ~
36199 case 101: ...
36200  
36201 \newline
36202 \InsetSpace ~
36203 \InsetSpace ~
36204 case 102: ...
36205  
36206 \newline
36207 \InsetSpace ~
36208 \InsetSpace ~
36209 case 103: ...
36210  
36211 \newline
36212 \InsetSpace ~
36213 \InsetSpace ~
36214 case 104: ...
36215  
36216 \newline
36217 \InsetSpace ~
36218 \InsetSpace ~
36219 case 105: ...
36220  
36221 \newline
36222 \InsetSpace ~
36223 \InsetSpace ~
36224 case 106: ...
36225  
36226 \newline
36227 \InsetSpace ~
36228 \InsetSpace ~
36229 case 107: ...
36230  
36231 \newline
36232 }
36233 \end_layout
36234
36235 \begin_layout Standard
36236 If the above switch statement is broken down into two switch statements
36237 \end_layout
36238
36239 \begin_layout Verse
36240
36241 \family typewriter
36242 switch (i) { 
36243 \newline
36244 \InsetSpace ~
36245 \InsetSpace ~
36246 case 1: ...
36247  
36248 \newline
36249 \InsetSpace ~
36250 \InsetSpace ~
36251 case 2: ...
36252  
36253 \newline
36254 \InsetSpace ~
36255 \InsetSpace ~
36256 case 3: ...
36257  
36258 \newline
36259 \InsetSpace ~
36260 \InsetSpace ~
36261 case 4: ...
36262  
36263 \newline
36264 \InsetSpace ~
36265 \InsetSpace ~
36266 case 5: ...
36267  
36268 \newline
36269 \InsetSpace ~
36270 \InsetSpace ~
36271 case 6: ...
36272  
36273 \newline
36274 \InsetSpace ~
36275 \InsetSpace ~
36276 case 7: ...
36277  
36278 \newline
36279 }
36280 \end_layout
36281
36282 \begin_layout Standard
36283 and
36284 \end_layout
36285
36286 \begin_layout Verse
36287
36288 \family typewriter
36289 switch (i) { 
36290 \newline
36291 \InsetSpace ~
36292 \InsetSpace ~
36293 case 101: ...
36294  
36295 \newline
36296 \InsetSpace ~
36297 \InsetSpace ~
36298 case 102: ...
36299  
36300 \newline
36301 \InsetSpace ~
36302 \InsetSpace ~
36303 case 103: ...
36304  
36305 \newline
36306 \InsetSpace ~
36307 \InsetSpace ~
36308 case 104: ...
36309  
36310 \newline
36311 \InsetSpace ~
36312 \InsetSpace ~
36313 case 105: ...
36314  
36315 \newline
36316 \InsetSpace ~
36317 \InsetSpace ~
36318 case 106: ...
36319  
36320 \newline
36321 \InsetSpace ~
36322 \InsetSpace ~
36323 case 107: ...
36324  
36325 \newline
36326 }
36327 \end_layout
36328
36329 \begin_layout Standard
36330 then both the switch statements will be implemented using jump-tables whereas
36331  the unmodified switch statement will not be.
36332 \end_layout
36333
36334 \begin_layout Standard
36335 \begin_inset Note Note
36336 status collapsed
36337
36338 \begin_layout Standard
36339 There might be reasons which SDCC cannot know about to either favour or
36340  not favour jump tables.
36341  If the target system has to be as quick for the last switch case as for
36342  the first (pro jump table), or if the switch argument is known to be zero
36343  in the majority of the cases (contra jump table).
36344 \end_layout
36345
36346 \end_inset
36347
36348
36349 \end_layout
36350
36351 \begin_layout Standard
36352 The pragma nojtbound
36353 \begin_inset LatexCommand index
36354 name "\\#pragma nojtbound"
36355
36356 \end_inset
36357
36358  can be used to turn off checking the 
36359 \emph on
36360 j
36361 \emph default
36362 ump 
36363 \emph on
36364 t
36365 \emph default
36366 able 
36367 \emph on
36368 bound
36369 \emph default
36370 aries.
36371  It has no effect if a default label is supplied.
36372  Use of this pragma is dangerous: if the switch
36373 \begin_inset LatexCommand index
36374 name "switch statement"
36375
36376 \end_inset
36377
36378  argument is not matched by a case statement the processor will happily
36379  jump into Nirvana.
36380 \end_layout
36381
36382 \begin_layout Subsection
36383 Bit-shifting Operations
36384 \begin_inset LatexCommand index
36385 name "Bit shifting"
36386
36387 \end_inset
36388
36389 .
36390 \end_layout
36391
36392 \begin_layout Standard
36393 Bit shifting is one of the most frequently used operation in embedded programmin
36394 g.
36395  SDCC tries to implement bit-shift operations in the most efficient way
36396  possible, e.g.:
36397 \end_layout
36398
36399 \begin_layout Verse
36400
36401 \family typewriter
36402 unsigned char i;
36403 \newline
36404 ...
36405  
36406 \newline
36407 i >>= 4; 
36408 \newline
36409 ...
36410 \end_layout
36411
36412 \begin_layout Standard
36413 generates the following code:
36414 \end_layout
36415
36416 \begin_layout Verse
36417
36418 \family typewriter
36419 mov\InsetSpace ~
36420  a,_i 
36421 \newline
36422 swap a 
36423 \newline
36424 anl\InsetSpace ~
36425  a,#0x0f 
36426 \newline
36427 mov\InsetSpace ~
36428  _i,a
36429 \end_layout
36430
36431 \begin_layout Standard
36432 In general SDCC will never setup a loop if the shift count is known.
36433  Another example:
36434 \end_layout
36435
36436 \begin_layout Verse
36437
36438 \family typewriter
36439 unsigned int i; 
36440 \newline
36441 ...
36442  
36443 \newline
36444 i >>= 9; 
36445 \newline
36446 ...
36447 \end_layout
36448
36449 \begin_layout Standard
36450 will generate:
36451 \end_layout
36452
36453 \begin_layout Verse
36454
36455 \family typewriter
36456 mov\InsetSpace ~
36457 \InsetSpace ~
36458 a,(_i + 1) 
36459 \newline
36460 mov\InsetSpace ~
36461 \InsetSpace ~
36462 (_i + 1),#0x00 
36463 \newline
36464 clr\InsetSpace ~
36465 \InsetSpace ~
36466
36467 \newline
36468 rrc\InsetSpace ~
36469 \InsetSpace ~
36470
36471 \newline
36472 mov\InsetSpace ~
36473 \InsetSpace ~
36474 _i,a
36475 \end_layout
36476
36477 \begin_layout Subsection
36478 Bit-rotation
36479 \begin_inset LatexCommand index
36480 name "Bit rotation"
36481
36482 \end_inset
36483
36484
36485 \end_layout
36486
36487 \begin_layout Standard
36488 A special case of the bit-shift operation is bit rotation
36489 \begin_inset LatexCommand index
36490 name "rotating bits"
36491
36492 \end_inset
36493
36494 , SDCC recognizes the following expression to be a left bit-rotation:
36495 \end_layout
36496
36497 \begin_layout Verse
36498
36499 \family typewriter
36500 \series bold
36501 unsigned
36502 \series default
36503 \InsetSpace ~
36504 \InsetSpace ~
36505 char i;\InsetSpace ~
36506 \InsetSpace ~
36507 \InsetSpace ~
36508 \InsetSpace ~
36509 \InsetSpace ~
36510 \InsetSpace ~
36511 \InsetSpace ~
36512 \InsetSpace ~
36513 \InsetSpace ~
36514 \InsetSpace ~
36515 \InsetSpace ~
36516 /* unsigned is needed for rotation */ 
36517 \newline
36518 ...
36519  
36520 \newline
36521 i = ((i << 1) | (i >> 7));
36522 \family default
36523  
36524 \newline
36525
36526 \family typewriter
36527 ...
36528 \end_layout
36529
36530 \begin_layout Standard
36531 will generate the following code:
36532 \end_layout
36533
36534 \begin_layout Verse
36535
36536 \family typewriter
36537 mov\InsetSpace ~
36538 \InsetSpace ~
36539 a,_i 
36540 \newline
36541 rl\InsetSpace ~
36542 \InsetSpace ~
36543 \InsetSpace ~
36544
36545 \newline
36546 mov\InsetSpace ~
36547 \InsetSpace ~
36548 _i,a
36549 \end_layout
36550
36551 \begin_layout Standard
36552 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36553 ns of this case will also be recognized as bit-rotation, i.e.: 
36554 \end_layout
36555
36556 \begin_layout Verse
36557
36558 \family typewriter
36559 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36560 \end_layout
36561
36562 \begin_layout Subsection
36563 Nibble and Byte Swapping
36564 \end_layout
36565
36566 \begin_layout Standard
36567 Other special cases of the bit-shift operations are nibble or byte swapping
36568 \begin_inset LatexCommand index
36569 name "swapping nibbles/bytes"
36570
36571 \end_inset
36572
36573 , SDCC recognizes the following expressions:
36574 \end_layout
36575
36576 \begin_layout Verse
36577
36578 \family typewriter
36579 \series bold
36580 unsigned
36581 \series default
36582 \InsetSpace ~
36583 \InsetSpace ~
36584 char i; 
36585 \newline
36586
36587 \series bold
36588 unsigned
36589 \series default
36590 \InsetSpace ~
36591 \InsetSpace ~
36592 int j; 
36593 \newline
36594 ...
36595  
36596 \newline
36597 i = ((i << 4) | (i >> 4));
36598 \family default
36599  
36600 \newline
36601
36602 \family typewriter
36603 j = ((j << 8) | (j >> 8)); 
36604 \end_layout
36605
36606 \begin_layout Standard
36607 and generates a swap instruction for the nibble swapping
36608 \begin_inset LatexCommand index
36609 name "Nibble swapping"
36610
36611 \end_inset
36612
36613  or move instructions for the byte swapping
36614 \begin_inset LatexCommand index
36615 name "Byte swapping"
36616
36617 \end_inset
36618
36619 .
36620  The 
36621 \begin_inset Quotes sld
36622 \end_inset
36623
36624 j
36625 \begin_inset Quotes srd
36626 \end_inset
36627
36628  example can be used to convert from little to big-endian or vice versa.
36629  If you want to change the endianness of a 
36630 \emph on
36631 signed
36632 \emph default
36633  integer you have to cast to 
36634 \family typewriter
36635 (unsigned int)
36636 \family default
36637  first.
36638 \end_layout
36639
36640 \begin_layout Standard
36641 Note that SDCC stores numbers in little-endian
36642 \begin_inset Foot
36643 status open
36644
36645 \begin_layout Standard
36646 Usually 8-bit processors don't care much about endianness.
36647  This is not the case for the standard 8051 which only has an instruction
36648  to increment its 
36649 \emph on
36650 dptr
36651 \emph default
36652
36653 \begin_inset LatexCommand index
36654 name "DPTR"
36655
36656 \end_inset
36657
36658 -datapointer so little-endian is the more efficient byte order.
36659 \end_layout
36660
36661 \end_inset
36662
36663
36664 \begin_inset LatexCommand index
36665 name "little-endian"
36666
36667 \end_inset
36668
36669
36670 \begin_inset LatexCommand index
36671 name "Endianness"
36672
36673 \end_inset
36674
36675  format (i.e.
36676  lowest order first).
36677 \end_layout
36678
36679 \begin_layout Subsection
36680 Highest Order Bit
36681 \begin_inset LatexCommand index
36682 name "Highest Order Bit"
36683
36684 \end_inset
36685
36686  / Any Order Bit
36687 \begin_inset LatexCommand index
36688 name "Any Order Bit"
36689
36690 \end_inset
36691
36692
36693 \end_layout
36694
36695 \begin_layout Standard
36696 It is frequently required to obtain the highest order bit of an integral
36697  type (long, int, short or char types).
36698  Also obtaining any other order bit is not uncommon.
36699  SDCC recognizes the following expressions to yield the highest order bit
36700  and generates optimized code for it, e.g.:
36701 \end_layout
36702
36703 \begin_layout Verse
36704
36705 \family typewriter
36706 unsigned int gint; 
36707 \newline
36708
36709 \newline
36710 foo () { 
36711 \newline
36712 \InsetSpace ~
36713 \InsetSpace ~
36714 unsigned char hob1, aob1; 
36715 \newline
36716 \InsetSpace ~
36717 \InsetSpace ~
36718 bit hob2, hob3, aob2,
36719  aob3; 
36720 \newline
36721 \InsetSpace ~
36722 \InsetSpace ~
36723 ...
36724  
36725 \newline
36726 \InsetSpace ~
36727 \InsetSpace ~
36728 hob1 = (gint >> 15) & 1; 
36729 \newline
36730 \InsetSpace ~
36731 \InsetSpace ~
36732 hob2 = (gint >> 15) & 1; 
36733 \newline
36734 \InsetSpace ~
36735 \InsetSpace ~
36736 hob3 = gint & 0x8000;
36737  
36738 \newline
36739 \InsetSpace ~
36740 \InsetSpace ~
36741 aob1 = (gint >> 9) & 1; 
36742 \newline
36743 \InsetSpace ~
36744 \InsetSpace ~
36745 aob2 = (gint >> 8) & 1; 
36746 \newline
36747 \InsetSpace ~
36748 \InsetSpace ~
36749 aob3 = gint & 0x0800; 
36750 \newline
36751 \InsetSpace ~
36752 \InsetSpace ~
36753 ..
36754  
36755 \newline
36756 }
36757 \end_layout
36758
36759 \begin_layout Standard
36760 will generate the following code:
36761 \end_layout
36762
36763 \begin_layout Verse
36764
36765 \family typewriter
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 \InsetSpace ~
36780 \InsetSpace ~
36781 \InsetSpace ~
36782 \InsetSpace ~
36783 \InsetSpace ~
36784 \InsetSpace ~
36785 \InsetSpace ~
36786 \InsetSpace ~
36787 \InsetSpace ~
36788 \InsetSpace ~
36789 \InsetSpace ~
36790 \InsetSpace ~
36791  61 ;\InsetSpace ~
36792  hob.c 7 
36793 \newline
36794 000A E5*01\InsetSpace ~
36795 \InsetSpace ~
36796 \InsetSpace ~
36797 \InsetSpace ~
36798 \InsetSpace ~
36799 \InsetSpace ~
36800 \InsetSpace ~
36801 \InsetSpace ~
36802 \InsetSpace ~
36803 \InsetSpace ~
36804 \InsetSpace ~
36805 \InsetSpace ~
36806 \InsetSpace ~
36807 \InsetSpace ~
36808 \InsetSpace ~
36809  62\InsetSpace ~
36810 \InsetSpace ~
36811 \InsetSpace ~
36812 \InsetSpace ~
36813 \InsetSpace ~
36814 \InsetSpace ~
36815 \InsetSpace ~
36816 \InsetSpace ~
36817  mov\InsetSpace ~
36818 \InsetSpace ~
36819  a,(_gint + 1) 
36820 \newline
36821 000C 23\InsetSpace ~
36822 \InsetSpace ~
36823 \InsetSpace ~
36824 \InsetSpace ~
36825 \InsetSpace ~
36826 \InsetSpace ~
36827 \InsetSpace ~
36828 \InsetSpace ~
36829 \InsetSpace ~
36830 \InsetSpace ~
36831 \InsetSpace ~
36832 \InsetSpace ~
36833 \InsetSpace ~
36834 \InsetSpace ~
36835 \InsetSpace ~
36836 \InsetSpace ~
36837 \InsetSpace ~
36838 \InsetSpace ~
36839  63\InsetSpace ~
36840 \InsetSpace ~
36841 \InsetSpace ~
36842 \InsetSpace ~
36843 \InsetSpace ~
36844 \InsetSpace ~
36845 \InsetSpace ~
36846 \InsetSpace ~
36847  rl\InsetSpace ~
36848 \InsetSpace ~
36849 \InsetSpace ~
36850  a 
36851 \newline
36852 000D 54 01\InsetSpace ~
36853 \InsetSpace ~
36854 \InsetSpace ~
36855 \InsetSpace ~
36856 \InsetSpace ~
36857 \InsetSpace ~
36858 \InsetSpace ~
36859 \InsetSpace ~
36860 \InsetSpace ~
36861 \InsetSpace ~
36862 \InsetSpace ~
36863 \InsetSpace ~
36864 \InsetSpace ~
36865 \InsetSpace ~
36866 \InsetSpace ~
36867
36868  64\InsetSpace ~
36869 \InsetSpace ~
36870 \InsetSpace ~
36871 \InsetSpace ~
36872 \InsetSpace ~
36873 \InsetSpace ~
36874 \InsetSpace ~
36875 \InsetSpace ~
36876  anl\InsetSpace ~
36877 \InsetSpace ~
36878  a,#0x01 
36879 \newline
36880 000F F5*02\InsetSpace ~
36881 \InsetSpace ~
36882 \InsetSpace ~
36883 \InsetSpace ~
36884 \InsetSpace ~
36885 \InsetSpace ~
36886 \InsetSpace ~
36887 \InsetSpace ~
36888 \InsetSpace ~
36889 \InsetSpace ~
36890 \InsetSpace ~
36891 \InsetSpace ~
36892 \InsetSpace ~
36893 \InsetSpace ~
36894 \InsetSpace ~
36895  65\InsetSpace ~
36896 \InsetSpace ~
36897 \InsetSpace ~
36898 \InsetSpace ~
36899 \InsetSpace ~
36900 \InsetSpace ~
36901 \InsetSpace ~
36902 \InsetSpace ~
36903  mov\InsetSpace ~
36904 \InsetSpace ~
36905  _foo_hob1_1_1,a 
36906 \newline
36907 \InsetSpace ~
36908 \InsetSpace ~
36909 \InsetSpace ~
36910 \InsetSpace ~
36911 \InsetSpace ~
36912 \InsetSpace ~
36913 \InsetSpace ~
36914 \InsetSpace ~
36915 \InsetSpace ~
36916 \InsetSpace ~
36917 \InsetSpace ~
36918 \InsetSpace ~
36919 \InsetSpace ~
36920 \InsetSpace ~
36921 \InsetSpace ~
36922 \InsetSpace ~
36923 \InsetSpace ~
36924 \InsetSpace ~
36925 \InsetSpace ~
36926 \InsetSpace ~
36927 \InsetSpace ~
36928 \InsetSpace ~
36929 \InsetSpace ~
36930 \InsetSpace ~
36931 \InsetSpace ~
36932  66 ;\InsetSpace ~
36933  hob.c 8 
36934 \newline
36935 0011 E5*01\InsetSpace ~
36936 \InsetSpace ~
36937 \InsetSpace ~
36938 \InsetSpace ~
36939 \InsetSpace ~
36940 \InsetSpace ~
36941 \InsetSpace ~
36942 \InsetSpace ~
36943 \InsetSpace ~
36944 \InsetSpace ~
36945 \InsetSpace ~
36946 \InsetSpace ~
36947 \InsetSpace ~
36948 \InsetSpace ~
36949 \InsetSpace ~
36950
36951  67\InsetSpace ~
36952 \InsetSpace ~
36953 \InsetSpace ~
36954 \InsetSpace ~
36955 \InsetSpace ~
36956 \InsetSpace ~
36957 \InsetSpace ~
36958 \InsetSpace ~
36959  mov\InsetSpace ~
36960 \InsetSpace ~
36961  a,(_gint + 1) 
36962 \newline
36963 0013 33\InsetSpace ~
36964 \InsetSpace ~
36965 \InsetSpace ~
36966 \InsetSpace ~
36967 \InsetSpace ~
36968 \InsetSpace ~
36969 \InsetSpace ~
36970 \InsetSpace ~
36971 \InsetSpace ~
36972 \InsetSpace ~
36973 \InsetSpace ~
36974 \InsetSpace ~
36975 \InsetSpace ~
36976 \InsetSpace ~
36977 \InsetSpace ~
36978 \InsetSpace ~
36979 \InsetSpace ~
36980 \InsetSpace ~
36981  68\InsetSpace ~
36982 \InsetSpace ~
36983 \InsetSpace ~
36984 \InsetSpace ~
36985 \InsetSpace ~
36986 \InsetSpace ~
36987 \InsetSpace ~
36988 \InsetSpace ~
36989  rlc\InsetSpace ~
36990 \InsetSpace ~
36991  a 
36992 \newline
36993 0014 92*00\InsetSpace ~
36994 \InsetSpace ~
36995 \InsetSpace ~
36996 \InsetSpace ~
36997 \InsetSpace ~
36998 \InsetSpace ~
36999 \InsetSpace ~
37000 \InsetSpace ~
37001 \InsetSpace ~
37002 \InsetSpace ~
37003 \InsetSpace ~
37004 \InsetSpace ~
37005 \InsetSpace ~
37006 \InsetSpace ~
37007 \InsetSpace ~
37008  69\InsetSpace ~
37009 \InsetSpace ~
37010 \InsetSpace ~
37011 \InsetSpace ~
37012 \InsetSpace ~
37013 \InsetSpace ~
37014 \InsetSpace ~
37015 \InsetSpace ~
37016  mov\InsetSpace ~
37017 \InsetSpace ~
37018  _foo_hob2_1_1,c
37019  
37020 \newline
37021 \InsetSpace ~
37022 \InsetSpace ~
37023 \InsetSpace ~
37024 \InsetSpace ~
37025 \InsetSpace ~
37026 \InsetSpace ~
37027 \InsetSpace ~
37028 \InsetSpace ~
37029 \InsetSpace ~
37030 \InsetSpace ~
37031 \InsetSpace ~
37032 \InsetSpace ~
37033 \InsetSpace ~
37034 \InsetSpace ~
37035 \InsetSpace ~
37036 \InsetSpace ~
37037 \InsetSpace ~
37038 \InsetSpace ~
37039 \InsetSpace ~
37040 \InsetSpace ~
37041 \InsetSpace ~
37042 \InsetSpace ~
37043 \InsetSpace ~
37044 \InsetSpace ~
37045 \InsetSpace ~
37046  66 ;\InsetSpace ~
37047  hob.c 9 
37048 \newline
37049 0016 E5*01\InsetSpace ~
37050 \InsetSpace ~
37051 \InsetSpace ~
37052 \InsetSpace ~
37053 \InsetSpace ~
37054 \InsetSpace ~
37055 \InsetSpace ~
37056 \InsetSpace ~
37057 \InsetSpace ~
37058 \InsetSpace ~
37059 \InsetSpace ~
37060 \InsetSpace ~
37061 \InsetSpace ~
37062 \InsetSpace ~
37063 \InsetSpace ~
37064  67\InsetSpace ~
37065 \InsetSpace ~
37066 \InsetSpace ~
37067 \InsetSpace ~
37068 \InsetSpace ~
37069 \InsetSpace ~
37070 \InsetSpace ~
37071 \InsetSpace ~
37072  mov\InsetSpace ~
37073 \InsetSpace ~
37074  a,(_gint + 1) 
37075 \newline
37076 0018 33\InsetSpace ~
37077 \InsetSpace ~
37078 \InsetSpace ~
37079 \InsetSpace ~
37080 \InsetSpace ~
37081 \InsetSpace ~
37082 \InsetSpace ~
37083 \InsetSpace ~
37084 \InsetSpace ~
37085 \InsetSpace ~
37086 \InsetSpace ~
37087 \InsetSpace ~
37088 \InsetSpace ~
37089 \InsetSpace ~
37090 \InsetSpace ~
37091 \InsetSpace ~
37092 \InsetSpace ~
37093 \InsetSpace ~
37094  68\InsetSpace ~
37095 \InsetSpace ~
37096 \InsetSpace ~
37097 \InsetSpace ~
37098 \InsetSpace ~
37099 \InsetSpace ~
37100 \InsetSpace ~
37101 \InsetSpace ~
37102  rlc\InsetSpace ~
37103 \InsetSpace ~
37104  a 
37105 \newline
37106 0019 92*01\InsetSpace ~
37107 \InsetSpace ~
37108 \InsetSpace ~
37109 \InsetSpace ~
37110 \InsetSpace ~
37111 \InsetSpace ~
37112 \InsetSpace ~
37113 \InsetSpace ~
37114 \InsetSpace ~
37115 \InsetSpace ~
37116 \InsetSpace ~
37117 \InsetSpace ~
37118 \InsetSpace ~
37119 \InsetSpace ~
37120 \InsetSpace ~
37121
37122  69\InsetSpace ~
37123 \InsetSpace ~
37124 \InsetSpace ~
37125 \InsetSpace ~
37126 \InsetSpace ~
37127 \InsetSpace ~
37128 \InsetSpace ~
37129 \InsetSpace ~
37130  mov\InsetSpace ~
37131 \InsetSpace ~
37132  _foo_hob3_1_1,c 
37133 \newline
37134 \InsetSpace ~
37135 \InsetSpace ~
37136 \InsetSpace ~
37137 \InsetSpace ~
37138 \InsetSpace ~
37139 \InsetSpace ~
37140 \InsetSpace ~
37141 \InsetSpace ~
37142 \InsetSpace ~
37143 \InsetSpace ~
37144 \InsetSpace ~
37145 \InsetSpace ~
37146 \InsetSpace ~
37147 \InsetSpace ~
37148 \InsetSpace ~
37149 \InsetSpace ~
37150 \InsetSpace ~
37151 \InsetSpace ~
37152 \InsetSpace ~
37153 \InsetSpace ~
37154 \InsetSpace ~
37155 \InsetSpace ~
37156 \InsetSpace ~
37157 \InsetSpace ~
37158 \InsetSpace ~
37159  70 ;\InsetSpace ~
37160  hob.c 10 
37161 \newline
37162 001B E5*01\InsetSpace ~
37163 \InsetSpace ~
37164 \InsetSpace ~
37165 \InsetSpace ~
37166 \InsetSpace ~
37167 \InsetSpace ~
37168 \InsetSpace ~
37169 \InsetSpace ~
37170 \InsetSpace ~
37171 \InsetSpace ~
37172 \InsetSpace ~
37173 \InsetSpace ~
37174 \InsetSpace ~
37175 \InsetSpace ~
37176 \InsetSpace ~
37177  71\InsetSpace ~
37178 \InsetSpace ~
37179 \InsetSpace ~
37180 \InsetSpace ~
37181 \InsetSpace ~
37182 \InsetSpace ~
37183 \InsetSpace ~
37184 \InsetSpace ~
37185  mov\InsetSpace ~
37186 \InsetSpace ~
37187  a,(_gint + 1) 
37188 \newline
37189 001D
37190  03\InsetSpace ~
37191 \InsetSpace ~
37192 \InsetSpace ~
37193 \InsetSpace ~
37194 \InsetSpace ~
37195 \InsetSpace ~
37196 \InsetSpace ~
37197 \InsetSpace ~
37198 \InsetSpace ~
37199 \InsetSpace ~
37200 \InsetSpace ~
37201 \InsetSpace ~
37202 \InsetSpace ~
37203 \InsetSpace ~
37204 \InsetSpace ~
37205 \InsetSpace ~
37206 \InsetSpace ~
37207 \InsetSpace ~
37208  72\InsetSpace ~
37209 \InsetSpace ~
37210 \InsetSpace ~
37211 \InsetSpace ~
37212 \InsetSpace ~
37213 \InsetSpace ~
37214 \InsetSpace ~
37215 \InsetSpace ~
37216  rr\InsetSpace ~
37217 \InsetSpace ~
37218 \InsetSpace ~
37219  a 
37220 \newline
37221 001E 54 01\InsetSpace ~
37222 \InsetSpace ~
37223 \InsetSpace ~
37224 \InsetSpace ~
37225 \InsetSpace ~
37226 \InsetSpace ~
37227 \InsetSpace ~
37228 \InsetSpace ~
37229 \InsetSpace ~
37230 \InsetSpace ~
37231 \InsetSpace ~
37232 \InsetSpace ~
37233 \InsetSpace ~
37234 \InsetSpace ~
37235 \InsetSpace ~
37236  73\InsetSpace ~
37237 \InsetSpace ~
37238 \InsetSpace ~
37239 \InsetSpace ~
37240 \InsetSpace ~
37241 \InsetSpace ~
37242 \InsetSpace ~
37243 \InsetSpace ~
37244  anl\InsetSpace ~
37245 \InsetSpace ~
37246  a,#0x01 
37247 \newline
37248 0020 F5*03\InsetSpace ~
37249 \InsetSpace ~
37250 \InsetSpace ~
37251 \InsetSpace ~
37252 \InsetSpace ~
37253 \InsetSpace ~
37254 \InsetSpace ~
37255 \InsetSpace ~
37256 \InsetSpace ~
37257 \InsetSpace ~
37258 \InsetSpace ~
37259 \InsetSpace ~
37260 \InsetSpace ~
37261 \InsetSpace ~
37262 \InsetSpace ~
37263  74\InsetSpace ~
37264 \InsetSpace ~
37265 \InsetSpace ~
37266 \InsetSpace ~
37267 \InsetSpace ~
37268 \InsetSpace ~
37269 \InsetSpace ~
37270 \InsetSpace ~
37271  mov\InsetSpace ~
37272 \InsetSpace ~
37273  _foo_aob1_1_1,a
37274  
37275 \newline
37276 \InsetSpace ~
37277 \InsetSpace ~
37278 \InsetSpace ~
37279 \InsetSpace ~
37280 \InsetSpace ~
37281 \InsetSpace ~
37282 \InsetSpace ~
37283 \InsetSpace ~
37284 \InsetSpace ~
37285 \InsetSpace ~
37286 \InsetSpace ~
37287 \InsetSpace ~
37288 \InsetSpace ~
37289 \InsetSpace ~
37290 \InsetSpace ~
37291 \InsetSpace ~
37292 \InsetSpace ~
37293 \InsetSpace ~
37294 \InsetSpace ~
37295 \InsetSpace ~
37296 \InsetSpace ~
37297 \InsetSpace ~
37298 \InsetSpace ~
37299 \InsetSpace ~
37300 \InsetSpace ~
37301  75 ;\InsetSpace ~
37302  hob.c 11 
37303 \newline
37304 0022 E5*01\InsetSpace ~
37305 \InsetSpace ~
37306 \InsetSpace ~
37307 \InsetSpace ~
37308 \InsetSpace ~
37309 \InsetSpace ~
37310 \InsetSpace ~
37311 \InsetSpace ~
37312 \InsetSpace ~
37313 \InsetSpace ~
37314 \InsetSpace ~
37315 \InsetSpace ~
37316 \InsetSpace ~
37317 \InsetSpace ~
37318 \InsetSpace ~
37319  76\InsetSpace ~
37320 \InsetSpace ~
37321 \InsetSpace ~
37322 \InsetSpace ~
37323 \InsetSpace ~
37324 \InsetSpace ~
37325 \InsetSpace ~
37326 \InsetSpace ~
37327  mov\InsetSpace ~
37328 \InsetSpace ~
37329  a,(_gint + 1) 
37330 \newline
37331 0024 13\InsetSpace ~
37332 \InsetSpace ~
37333 \InsetSpace ~
37334 \InsetSpace ~
37335 \InsetSpace ~
37336 \InsetSpace ~
37337 \InsetSpace ~
37338 \InsetSpace ~
37339 \InsetSpace ~
37340 \InsetSpace ~
37341 \InsetSpace ~
37342 \InsetSpace ~
37343 \InsetSpace ~
37344 \InsetSpace ~
37345 \InsetSpace ~
37346 \InsetSpace ~
37347 \InsetSpace ~
37348 \InsetSpace ~
37349  77\InsetSpace ~
37350 \InsetSpace ~
37351 \InsetSpace ~
37352 \InsetSpace ~
37353 \InsetSpace ~
37354 \InsetSpace ~
37355 \InsetSpace ~
37356 \InsetSpace ~
37357  rrc\InsetSpace ~
37358 \InsetSpace ~
37359  a 
37360 \newline
37361 0025 92*02\InsetSpace ~
37362 \InsetSpace ~
37363 \InsetSpace ~
37364 \InsetSpace ~
37365 \InsetSpace ~
37366 \InsetSpace ~
37367 \InsetSpace ~
37368 \InsetSpace ~
37369 \InsetSpace ~
37370 \InsetSpace ~
37371 \InsetSpace ~
37372 \InsetSpace ~
37373 \InsetSpace ~
37374 \InsetSpace ~
37375 \InsetSpace ~
37376
37377  78\InsetSpace ~
37378 \InsetSpace ~
37379 \InsetSpace ~
37380 \InsetSpace ~
37381 \InsetSpace ~
37382 \InsetSpace ~
37383 \InsetSpace ~
37384 \InsetSpace ~
37385  mov\InsetSpace ~
37386 \InsetSpace ~
37387  _foo_aob2_1_1,c 
37388 \newline
37389 \InsetSpace ~
37390 \InsetSpace ~
37391 \InsetSpace ~
37392 \InsetSpace ~
37393 \InsetSpace ~
37394 \InsetSpace ~
37395 \InsetSpace ~
37396 \InsetSpace ~
37397 \InsetSpace ~
37398 \InsetSpace ~
37399 \InsetSpace ~
37400 \InsetSpace ~
37401 \InsetSpace ~
37402 \InsetSpace ~
37403 \InsetSpace ~
37404 \InsetSpace ~
37405 \InsetSpace ~
37406 \InsetSpace ~
37407 \InsetSpace ~
37408 \InsetSpace ~
37409 \InsetSpace ~
37410 \InsetSpace ~
37411 \InsetSpace ~
37412 \InsetSpace ~
37413 \InsetSpace ~
37414  79 ;\InsetSpace ~
37415  hob.c 12 
37416 \newline
37417 0027 E5*01\InsetSpace ~
37418 \InsetSpace ~
37419 \InsetSpace ~
37420 \InsetSpace ~
37421 \InsetSpace ~
37422 \InsetSpace ~
37423 \InsetSpace ~
37424 \InsetSpace ~
37425 \InsetSpace ~
37426 \InsetSpace ~
37427 \InsetSpace ~
37428 \InsetSpace ~
37429 \InsetSpace ~
37430 \InsetSpace ~
37431 \InsetSpace ~
37432  80\InsetSpace ~
37433 \InsetSpace ~
37434 \InsetSpace ~
37435 \InsetSpace ~
37436 \InsetSpace ~
37437 \InsetSpace ~
37438 \InsetSpace ~
37439 \InsetSpace ~
37440  mov\InsetSpace ~
37441 \InsetSpace ~
37442  a,(_gint + 1) 
37443 \newline
37444 0029
37445  A2 E3\InsetSpace ~
37446 \InsetSpace ~
37447 \InsetSpace ~
37448 \InsetSpace ~
37449 \InsetSpace ~
37450 \InsetSpace ~
37451 \InsetSpace ~
37452 \InsetSpace ~
37453 \InsetSpace ~
37454 \InsetSpace ~
37455 \InsetSpace ~
37456 \InsetSpace ~
37457 \InsetSpace ~
37458 \InsetSpace ~
37459 \InsetSpace ~
37460  81\InsetSpace ~
37461 \InsetSpace ~
37462 \InsetSpace ~
37463 \InsetSpace ~
37464 \InsetSpace ~
37465 \InsetSpace ~
37466 \InsetSpace ~
37467 \InsetSpace ~
37468  mov\InsetSpace ~
37469 \InsetSpace ~
37470  c,acc[3] 
37471 \newline
37472 002B 92*03\InsetSpace ~
37473 \InsetSpace ~
37474 \InsetSpace ~
37475 \InsetSpace ~
37476 \InsetSpace ~
37477 \InsetSpace ~
37478 \InsetSpace ~
37479 \InsetSpace ~
37480 \InsetSpace ~
37481 \InsetSpace ~
37482 \InsetSpace ~
37483 \InsetSpace ~
37484 \InsetSpace ~
37485 \InsetSpace ~
37486 \InsetSpace ~
37487  82\InsetSpace ~
37488 \InsetSpace ~
37489 \InsetSpace ~
37490 \InsetSpace ~
37491 \InsetSpace ~
37492 \InsetSpace ~
37493 \InsetSpace ~
37494 \InsetSpace ~
37495  mov\InsetSpace ~
37496 \InsetSpace ~
37497  _foo_aob3_1_1,c 
37498 \end_layout
37499
37500 \begin_layout Standard
37501 Other variations of these cases however will 
37502 \emph on
37503 not
37504 \emph default
37505  be recognized.
37506  They are standard C expressions, so I heartily recommend these be the only
37507  way to get the highest order bit, (it is portable).
37508  Of course it will be recognized even if it is embedded in other expressions,
37509  e.g.:
37510 \end_layout
37511
37512 \begin_layout Verse
37513
37514 \family typewriter
37515 xyz = gint + ((gint >> 15) & 1);
37516 \end_layout
37517
37518 \begin_layout Standard
37519 will still be recognized.
37520 \end_layout
37521
37522 \begin_layout Subsection
37523 Higher Order Byte
37524 \begin_inset LatexCommand index
37525 name "Higher Order Byte"
37526
37527 \end_inset
37528
37529  / Higher Order Word
37530 \begin_inset LatexCommand index
37531 name "Higher Order Word"
37532
37533 \end_inset
37534
37535
37536 \end_layout
37537
37538 \begin_layout Standard
37539 It is also frequently required to obtain a higher order byte or word of
37540  a larger integral type (long, int or short types).
37541  SDCC recognizes the following expressions to yield the higher order byte
37542  or word and generates optimized code for it, e.g.:
37543 \end_layout
37544
37545 \begin_layout Verse
37546
37547 \family typewriter
37548 unsigned int gint; 
37549 \newline
37550 unsigned long int glong; 
37551 \newline
37552
37553 \newline
37554 foo () { 
37555 \newline
37556 \InsetSpace ~
37557 \InsetSpace ~
37558 unsigned char hob1,
37559  hob2; 
37560 \newline
37561 \InsetSpace ~
37562 \InsetSpace ~
37563 unsigned int how1, how2; 
37564 \newline
37565 \InsetSpace ~
37566 \InsetSpace ~
37567 ...
37568  
37569 \newline
37570 \InsetSpace ~
37571 \InsetSpace ~
37572 hob1 = (gint >> 8) & 0xFF; 
37573 \newline
37574 \InsetSpace ~
37575 \InsetSpace ~
37576 hob2 = glong >> 24; 
37577 \newline
37578 \InsetSpace ~
37579 \InsetSpace ~
37580 how1 = (glong >> 16) & 0xFFFF;
37581  
37582 \newline
37583 \InsetSpace ~
37584 \InsetSpace ~
37585 how2 = glong >> 8; 
37586 \newline
37587 \InsetSpace ~
37588 \InsetSpace ~
37589 ..
37590  
37591 \newline
37592 }
37593 \end_layout
37594
37595 \begin_layout Standard
37596 will generate the following code:
37597 \end_layout
37598
37599 \begin_layout Verse
37600
37601 \family typewriter
37602 \InsetSpace ~
37603 \InsetSpace ~
37604 \InsetSpace ~
37605 \InsetSpace ~
37606 \InsetSpace ~
37607 \InsetSpace ~
37608 \InsetSpace ~
37609 \InsetSpace ~
37610 \InsetSpace ~
37611 \InsetSpace ~
37612 \InsetSpace ~
37613 \InsetSpace ~
37614 \InsetSpace ~
37615 \InsetSpace ~
37616 \InsetSpace ~
37617 \InsetSpace ~
37618 \InsetSpace ~
37619 \InsetSpace ~
37620 \InsetSpace ~
37621 \InsetSpace ~
37622 \InsetSpace ~
37623 \InsetSpace ~
37624 \InsetSpace ~
37625 \InsetSpace ~
37626 \InsetSpace ~
37627  91 ;\InsetSpace ~
37628  hob.c 15 
37629 \newline
37630 0037 85*01*06\InsetSpace ~
37631 \InsetSpace ~
37632 \InsetSpace ~
37633 \InsetSpace ~
37634 \InsetSpace ~
37635 \InsetSpace ~
37636 \InsetSpace ~
37637 \InsetSpace ~
37638 \InsetSpace ~
37639 \InsetSpace ~
37640 \InsetSpace ~
37641 \InsetSpace ~
37642  92\InsetSpace ~
37643 \InsetSpace ~
37644 \InsetSpace ~
37645 \InsetSpace ~
37646 \InsetSpace ~
37647 \InsetSpace ~
37648 \InsetSpace ~
37649 \InsetSpace ~
37650  mov\InsetSpace ~
37651 \InsetSpace ~
37652  _foo_hob1_1_1,(_gint + 1) 
37653 \newline
37654 \InsetSpace ~
37655 \InsetSpace ~
37656 \InsetSpace ~
37657 \InsetSpace ~
37658 \InsetSpace ~
37659 \InsetSpace ~
37660 \InsetSpace ~
37661 \InsetSpace ~
37662 \InsetSpace ~
37663 \InsetSpace ~
37664 \InsetSpace ~
37665 \InsetSpace ~
37666 \InsetSpace ~
37667 \InsetSpace ~
37668 \InsetSpace ~
37669 \InsetSpace ~
37670 \InsetSpace ~
37671 \InsetSpace ~
37672 \InsetSpace ~
37673 \InsetSpace ~
37674 \InsetSpace ~
37675 \InsetSpace ~
37676 \InsetSpace ~
37677 \InsetSpace ~
37678 \InsetSpace ~
37679  93 ;\InsetSpace ~
37680  hob.c
37681  16 
37682 \newline
37683 003A 85*05*07\InsetSpace ~
37684 \InsetSpace ~
37685 \InsetSpace ~
37686 \InsetSpace ~
37687 \InsetSpace ~
37688 \InsetSpace ~
37689 \InsetSpace ~
37690 \InsetSpace ~
37691 \InsetSpace ~
37692 \InsetSpace ~
37693 \InsetSpace ~
37694 \InsetSpace ~
37695  94\InsetSpace ~
37696 \InsetSpace ~
37697 \InsetSpace ~
37698 \InsetSpace ~
37699 \InsetSpace ~
37700 \InsetSpace ~
37701 \InsetSpace ~
37702 \InsetSpace ~
37703  mov\InsetSpace ~
37704 \InsetSpace ~
37705  _foo_hob2_1_1,(_glong + 3) 
37706 \newline
37707 \InsetSpace ~
37708 \InsetSpace ~
37709 \InsetSpace ~
37710 \InsetSpace ~
37711 \InsetSpace ~
37712 \InsetSpace ~
37713 \InsetSpace ~
37714 \InsetSpace ~
37715 \InsetSpace ~
37716 \InsetSpace ~
37717 \InsetSpace ~
37718 \InsetSpace ~
37719 \InsetSpace ~
37720 \InsetSpace ~
37721 \InsetSpace ~
37722 \InsetSpace ~
37723 \InsetSpace ~
37724 \InsetSpace ~
37725 \InsetSpace ~
37726 \InsetSpace ~
37727 \InsetSpace ~
37728 \InsetSpace ~
37729 \InsetSpace ~
37730 \InsetSpace ~
37731 \InsetSpace ~
37732  95 ;\InsetSpace ~
37733  hob.c 17 
37734 \newline
37735 003D 85*04*08\InsetSpace ~
37736 \InsetSpace ~
37737 \InsetSpace ~
37738 \InsetSpace ~
37739 \InsetSpace ~
37740 \InsetSpace ~
37741 \InsetSpace ~
37742 \InsetSpace ~
37743 \InsetSpace ~
37744 \InsetSpace ~
37745 \InsetSpace ~
37746 \InsetSpace ~
37747
37748  96\InsetSpace ~
37749 \InsetSpace ~
37750 \InsetSpace ~
37751 \InsetSpace ~
37752 \InsetSpace ~
37753 \InsetSpace ~
37754 \InsetSpace ~
37755 \InsetSpace ~
37756  mov\InsetSpace ~
37757 \InsetSpace ~
37758  _foo_how1_1_1,(_glong + 2) 
37759 \newline
37760 0040 85*05*09\InsetSpace ~
37761 \InsetSpace ~
37762 \InsetSpace ~
37763 \InsetSpace ~
37764 \InsetSpace ~
37765 \InsetSpace ~
37766 \InsetSpace ~
37767 \InsetSpace ~
37768 \InsetSpace ~
37769 \InsetSpace ~
37770 \InsetSpace ~
37771 \InsetSpace ~
37772  97\InsetSpace ~
37773 \InsetSpace ~
37774 \InsetSpace ~
37775 \InsetSpace ~
37776 \InsetSpace ~
37777 \InsetSpace ~
37778 \InsetSpace ~
37779 \InsetSpace ~
37780  mov\InsetSpace ~
37781 \InsetSpace ~
37782  (_foo_how1_1_1 +
37783  1),(_glong + 3) 
37784 \newline
37785 0043 85*03*0A\InsetSpace ~
37786 \InsetSpace ~
37787 \InsetSpace ~
37788 \InsetSpace ~
37789 \InsetSpace ~
37790 \InsetSpace ~
37791 \InsetSpace ~
37792 \InsetSpace ~
37793 \InsetSpace ~
37794 \InsetSpace ~
37795 \InsetSpace ~
37796 \InsetSpace ~
37797  98\InsetSpace ~
37798 \InsetSpace ~
37799 \InsetSpace ~
37800 \InsetSpace ~
37801 \InsetSpace ~
37802 \InsetSpace ~
37803 \InsetSpace ~
37804 \InsetSpace ~
37805  mov\InsetSpace ~
37806 \InsetSpace ~
37807  _foo_how2_1_1,(_glong + 1) 
37808 \newline
37809 0046 85*04*0B\InsetSpace ~
37810 \InsetSpace ~
37811 \InsetSpace ~
37812 \InsetSpace ~
37813 \InsetSpace ~
37814 \InsetSpace ~
37815 \InsetSpace ~
37816 \InsetSpace ~
37817 \InsetSpace ~
37818 \InsetSpace ~
37819 \InsetSpace ~
37820 \InsetSpace ~
37821
37822  99\InsetSpace ~
37823 \InsetSpace ~
37824 \InsetSpace ~
37825 \InsetSpace ~
37826 \InsetSpace ~
37827 \InsetSpace ~
37828 \InsetSpace ~
37829 \InsetSpace ~
37830  mov\InsetSpace ~
37831 \InsetSpace ~
37832  (_foo_how2_1_1 + 1),(_glong + 2) 
37833 \end_layout
37834
37835 \begin_layout Standard
37836 Again, variations of these cases may 
37837 \emph on
37838 not
37839 \emph default
37840  be recognized.
37841  They are standard C expressions, so I heartily recommend these be the only
37842  way to get the higher order byte/word, (it is portable).
37843  Of course it will be recognized even if it is embedded in other expressions,
37844  e.g.:
37845 \end_layout
37846
37847 \begin_layout Verse
37848
37849 \family typewriter
37850 xyz = gint + ((gint >> 8) & 0xFF);
37851 \end_layout
37852
37853 \begin_layout Standard
37854 will still be recognized.
37855 \end_layout
37856
37857 \begin_layout Subsection
37858 Peephole Optimizer
37859 \begin_inset LatexCommand label
37860 name "sub:Peephole-Optimizer"
37861
37862 \end_inset
37863
37864
37865 \begin_inset LatexCommand index
37866 name "Peephole optimizer"
37867
37868 \end_inset
37869
37870
37871 \end_layout
37872
37873 \begin_layout Standard
37874 The compiler uses a rule based, pattern matching and re-writing mechanism
37875  for peep-hole optimization.
37876  It is inspired by 
37877 \emph on
37878 copt
37879 \emph default
37880  a peep-hole optimizer by Christopher W.
37881  Fraser (cwfraser\InsetSpace ~
37882 @\InsetSpace ~
37883 microsoft.com).
37884  A default set of rules are compiled into the compiler, additional rules
37885  may be added with the 
37886 \emph on
37887 -
37888 \begin_inset ERT
37889 status collapsed
37890
37891 \begin_layout Standard
37892
37893
37894 \backslash
37895 /
37896 \end_layout
37897
37898 \end_inset
37899
37900 -peep-file
37901 \begin_inset LatexCommand index
37902 name "-\\/-peep-file"
37903
37904 \end_inset
37905
37906  <filename>
37907 \emph default
37908  option.
37909  The rule language is best illustrated with examples.
37910 \end_layout
37911
37912 \begin_layout Verse
37913
37914 \family typewriter
37915 replace { 
37916 \newline
37917 \InsetSpace ~
37918 \InsetSpace ~
37919 mov %1,a 
37920 \newline
37921 \InsetSpace ~
37922 \InsetSpace ~
37923 mov a,%1
37924 \newline
37925 } by {
37926 \newline
37927 \InsetSpace ~
37928 \InsetSpace ~
37929 mov %1,a
37930 \newline
37931 }
37932 \end_layout
37933
37934 \begin_layout Standard
37935 The above rule will change the following assembly
37936 \begin_inset LatexCommand index
37937 name "Assembler routines"
37938
37939 \end_inset
37940
37941  sequence:
37942 \end_layout
37943
37944 \begin_layout Verse
37945
37946 \family typewriter
37947 mov r1,a 
37948 \newline
37949 mov a,r1
37950 \end_layout
37951
37952 \begin_layout Standard
37953 to
37954 \end_layout
37955
37956 \begin_layout Verse
37957
37958 \family typewriter
37959 mov r1,a
37960 \end_layout
37961
37962 \begin_layout Standard
37963 Note: All occurrences of a 
37964 \emph on
37965 %n
37966 \emph default
37967  (pattern variable) must denote the same string.
37968  With the above rule, the assembly sequence:
37969 \end_layout
37970
37971 \begin_layout Verse
37972
37973 \family typewriter
37974 mov r1,a 
37975 \newline
37976 mov a,r2
37977 \end_layout
37978
37979 \begin_layout Standard
37980 will remain unmodified.
37981 \newline
37982
37983 \newline
37984 Other special case optimizations may be added by the
37985  user (via 
37986 \emph on
37987 -
37988 \begin_inset ERT
37989 status collapsed
37990
37991 \begin_layout Standard
37992
37993
37994 \backslash
37995 /
37996 \end_layout
37997
37998 \end_inset
37999
38000 -peep-file option
38001 \emph default
38002 ).
38003  E.g.
38004  some variants of the 8051 MCU
38005 \begin_inset LatexCommand index
38006 name "MCS51 variants"
38007
38008 \end_inset
38009
38010  allow only 
38011 \family typewriter
38012 ajmp
38013 \family default
38014  and 
38015 \family typewriter
38016 acall
38017 \family default
38018 .
38019  The following two rules will change all 
38020 \family typewriter
38021 ljmp
38022 \family default
38023  and 
38024 \family typewriter
38025 lcall
38026 \family default
38027  to 
38028 \family typewriter
38029 ajmp
38030 \family default
38031  and 
38032 \family typewriter
38033 acall
38034 \end_layout
38035
38036 \begin_layout Verse
38037
38038 \family typewriter
38039 replace { lcall %1 } by { acall %1 } 
38040 \newline
38041 replace { ljmp %1 } by { ajmp %1 }
38042 \end_layout
38043
38044 \begin_layout Standard
38045 (NOTE: from version 2.7.3 on, you can use option -
38046 \emph on
38047
38048 \begin_inset ERT
38049 status collapsed
38050
38051 \begin_layout Standard
38052
38053
38054 \backslash
38055 /
38056 \end_layout
38057
38058 \end_inset
38059
38060
38061 \emph default
38062 -acall-ajmp
38063 \begin_inset LatexCommand index
38064 name "-\\/-acall-ajmp"
38065
38066 \end_inset
38067
38068 , which also takes care of aligning the interrupt vectors properly.)
38069 \newline
38070
38071 \end_layout
38072
38073 \begin_layout Standard
38074 The 
38075 \emph on
38076 inline-assembler code
38077 \emph default
38078  is also passed through the peep hole optimizer, thus the peephole optimizer
38079  can also be used as an assembly level macro expander.
38080  The rules themselves are MCU dependent whereas the rule language infra-structur
38081 e is MCU independent.
38082  Peephole optimization rules for other MCU can be easily programmed using
38083  the rule language.
38084 \newline
38085
38086 \newline
38087 The syntax for a rule is as follows:
38088 \end_layout
38089
38090 \begin_layout Verse
38091
38092 \family typewriter
38093 rule := replace [ restart ] '{' <assembly sequence> '
38094 \backslash
38095 n' 
38096 \newline
38097 \InsetSpace ~
38098  \InsetSpace ~
38099  \InsetSpace ~
38100  \InsetSpace ~
38101  \InsetSpace ~
38102  \InsetSpace ~
38103  \InsetSpace ~
38104  \InsetSpace ~
38105  \InsetSpace ~
38106  \InsetSpace ~
38107  \InsetSpace ~
38108  \InsetSpace ~
38109  \InsetSpace ~
38110  \InsetSpace ~
38111  '}' by '{' '
38112 \backslash
38113 n' 
38114 \newline
38115 \InsetSpace ~
38116  \InsetSpace ~
38117  \InsetSpace ~
38118  \InsetSpace ~
38119  \InsetSpace ~
38120  \InsetSpace ~
38121  \InsetSpace ~
38122  \InsetSpace ~
38123  \InsetSpace ~
38124  \InsetSpace ~
38125  \InsetSpace ~
38126  \InsetSpace ~
38127  \InsetSpace ~
38128  \InsetSpace ~
38129  \InsetSpace ~
38130  \InsetSpace ~
38131  <assembly sequence> '
38132 \backslash
38133 n' 
38134 \newline
38135 \InsetSpace ~
38136  \InsetSpace ~
38137  \InsetSpace ~
38138  \InsetSpace ~
38139  \InsetSpace ~
38140  \InsetSpace ~
38141  \InsetSpace ~
38142  \InsetSpace ~
38143  \InsetSpace ~
38144  \InsetSpace ~
38145  \InsetSpace ~
38146  \InsetSpace ~
38147  \InsetSpace ~
38148  \InsetSpace ~
38149  '}' [if <functionName> ] '
38150 \backslash
38151 n' 
38152 \end_layout
38153
38154 \begin_layout Standard
38155 <assembly sequence> := assembly instruction (each instruction including
38156  labels must be on a separate line).
38157 \newline
38158
38159 \newline
38160 The optimizer will apply to the rules
38161  one by one from the top in the sequence of their appearance, it will terminate
38162  when all rules are exhausted.
38163  If the 'restart' option is specified, then the optimizer will start matching
38164  the rules again from the top, this option for a rule is expensive (performance)
38165 , it is intended to be used in situations where a transformation will trigger
38166  the same rule again.
38167  An example of this (not a good one, it has side effects) is the following
38168  rule:
38169 \end_layout
38170
38171 \begin_layout Verse
38172
38173 \family typewriter
38174 replace restart { 
38175 \newline
38176 \InsetSpace ~
38177 \InsetSpace ~
38178 pop %1 
38179 \newline
38180 \InsetSpace ~
38181 \InsetSpace ~
38182 push %1 } by { 
38183 \newline
38184 \InsetSpace ~
38185 \InsetSpace ~
38186 ; nop 
38187 \newline
38188 }
38189 \end_layout
38190
38191 \begin_layout Standard
38192 Note that the replace pattern cannot be a blank, but can be a comment line.
38193  Without the 'restart' option only the innermost 'pop' 'push' pair would
38194  be eliminated, i.e.:
38195 \end_layout
38196
38197 \begin_layout Verse
38198
38199 \family typewriter
38200 pop ar1 
38201 \newline
38202 pop ar2 
38203 \newline
38204 push ar2 
38205 \newline
38206 push ar1
38207 \end_layout
38208
38209 \begin_layout Standard
38210 would result in:
38211 \end_layout
38212
38213 \begin_layout Verse
38214
38215 \family typewriter
38216 pop ar1 
38217 \newline
38218 ; nop 
38219 \newline
38220 push ar1
38221 \end_layout
38222
38223 \begin_layout Standard
38224
38225 \emph on
38226 with
38227 \emph default
38228  the restart option the rule will be applied again to the resulting code
38229  and then all the pop-push pairs will be eliminated to yield:
38230 \end_layout
38231
38232 \begin_layout Verse
38233
38234 \family typewriter
38235 ; nop 
38236 \newline
38237 ; nop
38238 \end_layout
38239
38240 \begin_layout Standard
38241 A conditional function can be attached to a rule.
38242  Attaching rules are somewhat more involved, let me illustrate this with
38243  an example.
38244 \end_layout
38245
38246 \begin_layout Verse
38247
38248 \family typewriter
38249 replace { 
38250 \newline
38251 \InsetSpace ~
38252  \InsetSpace ~
38253  \InsetSpace ~
38254 ljmp %5 
38255 \newline
38256 %2:
38257 \newline
38258 } by { 
38259 \newline
38260 \InsetSpace ~
38261  \InsetSpace ~
38262  \InsetSpace ~
38263 sjmp %5 
38264 \newline
38265 %2:
38266 \newline
38267 } if labelInRange
38268 \end_layout
38269
38270 \begin_layout Standard
38271 The optimizer does a look-up of a function name table defined in function
38272  
38273 \emph on
38274 callFuncByName
38275 \emph default
38276  in the source file SDCCpeeph.c, with the name 
38277 \emph on
38278 labelInRange
38279 \emph default
38280 .
38281  If it finds a corresponding entry the function is called.
38282  Note there can be no parameters specified for these functions, in this
38283  case the use of 
38284 \emph on
38285 %5
38286 \emph default
38287  is crucial, since the function 
38288 \emph on
38289 labelInRange
38290 \emph default
38291  expects to find the label in that particular variable (the hash table containin
38292 g the variable bindings is passed as a parameter).
38293  If you want to code more such functions, take a close look at the function
38294  labelInRange and the calling mechanism in source file SDCCpeeph.c.
38295  Currently implemented are 
38296 \emph on
38297 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38298  24bitMode, portIsDS390, 24bitModeAndPortDS390
38299 \emph default
38300  and 
38301 \emph on
38302 notVolatile
38303 \emph default
38304 .
38305 \end_layout
38306
38307 \begin_layout Standard
38308 I know this whole thing is a little kludgey, but maybe some day we will
38309  have some better means.
38310  If you are looking at this file, you will see the default rules that are
38311  compiled into the compiler, you can add your own rules in the default set
38312  there if you get tired of specifying the -
38313 \begin_inset ERT
38314 status collapsed
38315
38316 \begin_layout Standard
38317
38318
38319 \backslash
38320 /
38321 \end_layout
38322
38323 \end_inset
38324
38325 -peep-file option.
38326 \end_layout
38327
38328 \begin_layout Section
38329 ANSI-Compliance
38330 \begin_inset LatexCommand index
38331 name "ANSI-compliance"
38332
38333 \end_inset
38334
38335
38336 \begin_inset LatexCommand label
38337 name "sub:ANSI-Compliance"
38338
38339 \end_inset
38340
38341
38342 \end_layout
38343
38344 \begin_layout Standard
38345 The latest publicly available version of the standard 
38346 \emph on
38347 ISO/IEC 9899 - Programming languages - C
38348 \emph default
38349  should be available at: 
38350 \begin_inset LatexCommand url
38351 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38352
38353 \end_inset
38354
38355 .
38356 \newline
38357
38358 \end_layout
38359
38360 \begin_layout Standard
38361 Deviations from the compliance:
38362 \end_layout
38363
38364 \begin_layout Itemize
38365 functions are not reentrant
38366 \begin_inset LatexCommand index
38367 name "reentrant"
38368
38369 \end_inset
38370
38371  unless explicitly declared as such or the 
38372 \series bold
38373 -
38374 \begin_inset ERT
38375 status collapsed
38376
38377 \begin_layout Standard
38378
38379
38380 \backslash
38381 /
38382 \end_layout
38383
38384 \end_inset
38385
38386 -stack-auto
38387 \begin_inset LatexCommand index
38388 name "-\\/-stack-auto"
38389
38390 \end_inset
38391
38392
38393 \series default
38394  command line option is specified.
38395 \end_layout
38396
38397 \begin_layout Itemize
38398 structures
38399 \begin_inset LatexCommand index
38400 name "struct"
38401
38402 \end_inset
38403
38404  and unions
38405 \begin_inset LatexCommand index
38406 name "union"
38407
38408 \end_inset
38409
38410  cannot be assigned values directly, cannot be passed as function parameters
38411  or assigned to each other and cannot be a return value
38412 \begin_inset LatexCommand index
38413 name "return value"
38414
38415 \end_inset
38416
38417  from a function, e.g.:
38418 \end_layout
38419
38420 \begin_deeper
38421 \begin_layout Verse
38422
38423 \family typewriter
38424 struct s { ...
38425  }; 
38426 \newline
38427 struct s s1, s2; 
38428 \newline
38429 foo() 
38430 \newline
38431
38432 \newline
38433 \InsetSpace ~
38434 \InsetSpace ~
38435 \InsetSpace ~
38436 \InsetSpace ~
38437 ...
38438  
38439 \newline
38440 \InsetSpace ~
38441 \InsetSpace ~
38442 \InsetSpace ~
38443 \InsetSpace ~
38444 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
38445 \newline
38446 \InsetSpace ~
38447 \InsetSpace ~
38448 \InsetSpace ~
38449 \InsetSpace ~
38450 ...
38451  
38452 \newline
38453 }
38454 \newline
38455
38456 \series bold
38457 struct
38458 \family default
38459 \series default
38460  
38461 \family typewriter
38462 s foo1 (
38463 \series bold
38464 struct
38465 \family default
38466 \series default
38467  
38468 \family typewriter
38469 s parms) /* invalid in SDCC although allowed in ANSI */
38470 \newline
38471
38472 \newline
38473 \InsetSpace ~
38474 \InsetSpace ~
38475 \InsetSpace ~
38476 \InsetSpace ~
38477 struct s rets;
38478  
38479 \newline
38480 \InsetSpace ~
38481 \InsetSpace ~
38482 \InsetSpace ~
38483 \InsetSpace ~
38484 ...
38485  
38486 \newline
38487 \InsetSpace ~
38488 \InsetSpace ~
38489 \InsetSpace ~
38490 \InsetSpace ~
38491 return rets; /* is invalid in SDCC although allowed in ANSI */ 
38492 \newline
38493 }
38494 \end_layout
38495
38496 \end_deeper
38497 \begin_layout Itemize
38498 initialization of structure arrays must be fully braced.
38499 \end_layout
38500
38501 \begin_deeper
38502 \begin_layout Verse
38503
38504 \family typewriter
38505 struct s { char x } a[] = {1, 2};\InsetSpace ~
38506 \InsetSpace ~
38507 \InsetSpace ~
38508 \InsetSpace ~
38509 \InsetSpace ~
38510 /* invalid in SDCC */
38511 \newline
38512 struct s { char x
38513  } a[] = {{1}, {2}}; /* OK */
38514 \end_layout
38515
38516 \end_deeper
38517 \begin_layout Itemize
38518 'long long
38519 \begin_inset LatexCommand index
38520 name "long long (not supported)"
38521
38522 \end_inset
38523
38524 ' (64 bit integers
38525 \begin_inset LatexCommand index
38526 name "int (64 bit) (not supported)"
38527
38528 \end_inset
38529
38530 ) not supported.
38531 \end_layout
38532
38533 \begin_layout Itemize
38534 'double
38535 \begin_inset LatexCommand index
38536 name "double (not supported)"
38537
38538 \end_inset
38539
38540 ' precision floating point 
38541 \begin_inset LatexCommand index
38542 name "Floating point support"
38543
38544 \end_inset
38545
38546 not supported.
38547 \end_layout
38548
38549 \begin_layout Itemize
38550 Old K&R style
38551 \begin_inset LatexCommand index
38552 name "K\\&R style"
38553
38554 \end_inset
38555
38556  function declarations are NOT allowed.
38557 \end_layout
38558
38559 \begin_deeper
38560 \begin_layout Verse
38561
38562 \family typewriter
38563 foo(i,j) /* this old style of function declarations */ 
38564 \newline
38565 int i,j; /* is valid
38566  in ANSI but not valid in SDCC */ 
38567 \newline
38568
38569 \newline
38570 \InsetSpace ~
38571 \InsetSpace ~
38572 \InsetSpace ~
38573 \InsetSpace ~
38574 ...
38575  
38576 \newline
38577 }
38578 \end_layout
38579
38580 \end_deeper
38581 \begin_layout Itemize
38582 Most enhancements in C99 are not supported, e.g.:
38583 \end_layout
38584
38585 \begin_deeper
38586 \begin_layout Verse
38587
38588 \family typewriter
38589 for (
38590 \series bold
38591 int
38592 \family default
38593 \series default
38594  
38595 \family typewriter
38596 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38597 \end_layout
38598
38599 \end_deeper
38600 \begin_layout Itemize
38601 But some have been added recently in SDCC 2.7.0.
38602  They must be considered alpha quality however.
38603 \end_layout
38604
38605 \begin_deeper
38606 \begin_layout Verse
38607
38608 \family typewriter
38609 \series bold
38610 inline
38611 \begin_inset LatexCommand index
38612 name "inline (not supported)"
38613
38614 \end_inset
38615
38616
38617 \family default
38618 \series default
38619  
38620 \family typewriter
38621 int increment (int a) { return a+1; } /* inlines the increment without function
38622  call overhead */
38623 \newline
38624 int *
38625 \family default
38626  
38627 \family typewriter
38628 \series bold
38629 restrict
38630 \begin_inset LatexCommand index
38631 name "inline (not supported)"
38632
38633 \end_inset
38634
38635
38636 \family default
38637 \series default
38638  
38639 \family typewriter
38640 p; /* accepted but ignored */
38641 \end_layout
38642
38643 \end_deeper
38644 \begin_layout Itemize
38645 Certain words that are valid identifiers in the standard may be reserved
38646  words in SDCC unless the 
38647 \series bold
38648 -
38649 \begin_inset ERT
38650 status collapsed
38651
38652 \begin_layout Standard
38653
38654
38655 \backslash
38656 /
38657 \end_layout
38658
38659 \end_inset
38660
38661 -std-c89
38662 \begin_inset LatexCommand index
38663 name "-\\/-std-c89"
38664
38665 \end_inset
38666
38667
38668 \series default
38669  or 
38670 \series bold
38671 -
38672 \begin_inset ERT
38673 status collapsed
38674
38675 \begin_layout Standard
38676
38677
38678 \backslash
38679 /
38680 \end_layout
38681
38682 \end_inset
38683
38684 -std-c99
38685 \begin_inset LatexCommand index
38686 name "-\\/-std-c99"
38687
38688 \end_inset
38689
38690
38691 \series default
38692  command line options are used.
38693  These may include (depending on the selected processor): 'at', 'banked',
38694  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38695 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38696  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38697  '_naked'.
38698  Compliant equivalents of these keywords are always available in a form
38699  that begin with two underscores
38700 \begin_inset LatexCommand index
38701 name "\\_\\_ (prefix for extended keywords)"
38702
38703 \end_inset
38704
38705 , f.e.
38706  '__data' instead of 'data'.
38707 \end_layout
38708
38709 \begin_layout Itemize
38710 Integer promotion of variable arguments is not performed if the argument
38711  is explicitly taypecasted unless the 
38712 \series bold
38713 -
38714 \begin_inset ERT
38715 status collapsed
38716
38717 \begin_layout Standard
38718
38719
38720 \backslash
38721 /
38722 \end_layout
38723
38724 \end_inset
38725
38726 -std-c89
38727 \begin_inset LatexCommand index
38728 name "-\\/-std-c89"
38729
38730 \end_inset
38731
38732
38733 \series default
38734  or 
38735 \series bold
38736 -
38737 \begin_inset ERT
38738 status collapsed
38739
38740 \begin_layout Standard
38741
38742
38743 \backslash
38744 /
38745 \end_layout
38746
38747 \end_inset
38748
38749 -std-c99
38750 \begin_inset LatexCommand index
38751 name "-\\/-std-c99"
38752
38753 \end_inset
38754
38755
38756 \series default
38757  command line options are used.
38758 \end_layout
38759
38760 \begin_deeper
38761 \begin_layout Verse
38762
38763 \family typewriter
38764 void vararg_func (char *str, ...) { str; }
38765 \newline
38766
38767 \newline
38768 void main (void)
38769 \newline
38770 {
38771 \newline
38772 \InsetSpace ~
38773 \InsetSpace ~
38774 char c = 10;
38775 \newline
38776
38777 \newline
38778 \InsetSpace ~
38779 \InsetSpace ~
38780 /* argument
38781  u is promoted to int before
38782 \newline
38783 \InsetSpace ~
38784 \InsetSpace ~
38785 \InsetSpace ~
38786 * passing to function */
38787 \newline
38788 \InsetSpace ~
38789 \InsetSpace ~
38790 vararg_func ("%c", c);
38791 \newline
38792
38793 \newline
38794 \InsetSpace ~
38795 \InsetSpace ~
38796 /*
38797  argument u is not promoted to int,
38798 \newline
38799 \InsetSpace ~
38800 \InsetSpace ~
38801 \InsetSpace ~
38802 * it is passed as char to function
38803 \newline
38804 \InsetSpace ~
38805 \InsetSpace ~
38806 \InsetSpace ~
38807 * if
38808  --std-cXX is not defined;
38809 \newline
38810 \InsetSpace ~
38811 \InsetSpace ~
38812 \InsetSpace ~
38813 * is promoted to int before passing
38814 \newline
38815 \InsetSpace ~
38816 \InsetSpace ~
38817 \InsetSpace ~
38818 * to function
38819  if --std-cXX is defined */
38820 \newline
38821 \InsetSpace ~
38822 \InsetSpace ~
38823 vararg_func ("%bc", (char)u);
38824 \newline
38825 }
38826 \end_layout
38827
38828 \end_deeper
38829 \begin_layout Section
38830 Cyclomatic Complexity
38831 \begin_inset LatexCommand index
38832 name "Cyclomatic complexity"
38833
38834 \end_inset
38835
38836
38837 \end_layout
38838
38839 \begin_layout Standard
38840 Cyclomatic complexity of a function is defined as the number of independent
38841  paths the program can take during execution of the function.
38842  This is an important number since it defines the number test cases you
38843  have to generate to validate the function.
38844  The accepted industry standard for complexity number is 10, if the cyclomatic
38845  complexity reported by SDCC exceeds 10 you should think about simplification
38846  of the function logic.
38847  Note that the complexity level is not related to the number of lines of
38848  code in a function.
38849  Large functions can have low complexity, and small functions can have large
38850  complexity levels.
38851  
38852 \newline
38853
38854 \newline
38855 SDCC uses the following formula to compute the complexity:
38856 \newline
38857
38858 \end_layout
38859
38860 \begin_layout Standard
38861 complexity = (number of edges in control flow graph) - (number of nodes
38862  in control flow graph) + 2;
38863 \newline
38864
38865 \newline
38866 Having said that the industry standard is 10,
38867  you should be aware that in some cases it be may unavoidable to have a
38868  complexity level of less than 10.
38869  For example if you have switch statement with more than 10 case labels,
38870  each case label adds one to the complexity level.
38871  The complexity level is by no means an absolute measure of the algorithmic
38872  complexity of the function, it does however provide a good starting point
38873  for which functions you might look at for further optimization.
38874 \end_layout
38875
38876 \begin_layout Section
38877 Retargetting for other Processors
38878 \end_layout
38879
38880 \begin_layout Standard
38881 The issues for retargetting the compiler are far too numerous to be covered
38882  by this document.
38883  What follows is a brief description of each of the seven phases of the
38884  compiler and its MCU dependency.
38885 \end_layout
38886
38887 \begin_layout Itemize
38888 Parsing the source and building the annotated parse tree.
38889  This phase is largely MCU independent (except for the language extensions).
38890  Syntax & semantic checks are also done in this phase, along with some initial
38891  optimizations like back patching labels and the pattern matching optimizations
38892  like bit-rotation etc.
38893 \end_layout
38894
38895 \begin_layout Itemize
38896 The second phase involves generating an intermediate code which can be easy
38897  manipulated during the later phases.
38898  This phase is entirely MCU independent.
38899  The intermediate code generation assumes the target machine has unlimited
38900  number of registers, and designates them with the name iTemp.
38901  The compiler can be made to dump a human readable form of the code generated
38902  by using the -
38903 \begin_inset ERT
38904 status collapsed
38905
38906 \begin_layout Standard
38907
38908
38909 \backslash
38910 /
38911 \end_layout
38912
38913 \end_inset
38914
38915 -dumpraw option.
38916 \end_layout
38917
38918 \begin_layout Itemize
38919 This phase does the bulk of the standard optimizations and is also MCU independe
38920 nt.
38921  This phase can be broken down into several sub-phases:
38922 \newline
38923
38924 \newline
38925 Break down intermediate
38926  code (iCode) into basic blocks.
38927 \newline
38928 Do control flow & data flow analysis on the
38929  basic blocks.
38930 \newline
38931 Do local common subexpression elimination, then global subexpressio
38932 n elimination
38933 \newline
38934 Dead code elimination
38935 \newline
38936 Loop optimizations
38937 \newline
38938 If loop optimizations
38939  caused any changes then do 'global subexpression elimination' and 'dead
38940  code elimination' again.
38941 \end_layout
38942
38943 \begin_layout Itemize
38944 This phase determines the live-ranges; by live range I mean those iTemp
38945  variables defined by the compiler that still survive after all the optimization
38946 s.
38947  Live range analysis
38948 \begin_inset LatexCommand index
38949 name "Live range analysis"
38950
38951 \end_inset
38952
38953  is essential for register allocation, since these computation determines
38954  which of these iTemps will be assigned to registers, and for how long.
38955 \end_layout
38956
38957 \begin_layout Itemize
38958 Phase five is register allocation.
38959  There are two parts to this process.
38960 \newline
38961
38962 \newline
38963 The first part I call 'register packing'
38964  (for lack of a better term).
38965  In this case several MCU specific expression folding is done to reduce
38966  register pressure.
38967 \newline
38968
38969 \newline
38970 The second part is more MCU independent and deals with
38971  allocating registers to the remaining live ranges.
38972  A lot of MCU specific code does creep into this phase because of the limited
38973  number of index registers available in the 8051.
38974 \end_layout
38975
38976 \begin_layout Itemize
38977 The Code generation phase is (unhappily), entirely MCU dependent and very
38978  little (if any at all) of this code can be reused for other MCU.
38979  However the scheme for allocating a homogenized assembler operand for each
38980  iCode operand may be reused.
38981 \end_layout
38982
38983 \begin_layout Itemize
38984 As mentioned in the optimization section the peep-hole optimizer is rule
38985  based system, which can reprogrammed for other MCUs.
38986 \end_layout
38987
38988 \begin_layout Standard
38989 More information is available on SDCC Wiki
38990 \begin_inset LatexCommand index
38991 name "wiki"
38992
38993 \end_inset
38994
38995  (preliminary link 
38996 \begin_inset LatexCommand url
38997 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
38998
38999 \end_inset
39000
39001 ) and in the thread 
39002 \begin_inset LatexCommand url
39003 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39004
39005 \end_inset
39006
39007  .
39008 \end_layout
39009
39010 \begin_layout Chapter
39011 Compiler internals
39012 \begin_inset LatexCommand index
39013 name "Compiler internals"
39014
39015 \end_inset
39016
39017
39018 \end_layout
39019
39020 \begin_layout Section
39021 The anatomy of the compiler
39022 \begin_inset LatexCommand label
39023 name "sub:The-anatomy-of"
39024
39025 \end_inset
39026
39027
39028 \end_layout
39029
39030 \begin_layout Standard
39031
39032 \shape italic
39033 This is an excerpt from an article published in Circuit Cellar Magazine
39034  in
39035 \shape default
39036  
39037 \series bold
39038 \shape italic
39039 August 2000
39040 \series default
39041 .
39042  It's a little outdated (the compiler is much more efficient now and user/develo
39043 per friendly), but pretty well exposes the guts of it all.
39044 \shape default
39045
39046 \newline
39047
39048 \newline
39049 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39050  It is fairly easy to retarget for other 8-bit MCU.
39051  Here we take a look at some of the internals of the compiler.
39052  
39053 \end_layout
39054
39055 \begin_layout Paragraph*
39056 Parsing
39057 \begin_inset LatexCommand index
39058 name "Parsing"
39059
39060 \end_inset
39061
39062  
39063 \end_layout
39064
39065 \begin_layout Standard
39066 Parsing the input source file and creating an AST (Annotated Syntax Tree
39067 \begin_inset LatexCommand index
39068 name "Annotated syntax tree"
39069
39070 \end_inset
39071
39072 ).
39073  This phase also involves propagating types (annotating each node of the
39074  parse tree with type information) and semantic analysis.
39075  There are some MCU specific parsing rules.
39076  For example the storage classes, the extended storage classes are MCU specific
39077  while there may be a xdata storage class for 8051 there is no such storage
39078  class for z80 or Atmel AVR.
39079  SDCC allows MCU specific storage class extensions, i.e.
39080  xdata will be treated as a storage class specifier when parsing 8051 C
39081  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39082  C code.
39083 \end_layout
39084
39085 \begin_layout Paragraph*
39086 Generating iCode
39087 \begin_inset LatexCommand index
39088 name "iCode"
39089
39090 \end_inset
39091
39092
39093 \end_layout
39094
39095 \begin_layout Standard
39096 Intermediate code generation.
39097  In this phase the AST is broken down into three-operand form (iCode).
39098  These three operand forms are represented as doubly linked lists.
39099  ICode is the term given to the intermediate form generated by the compiler.
39100  ICode example section shows some examples of iCode generated for some simple
39101  C source functions.
39102 \end_layout
39103
39104 \begin_layout Paragraph*
39105 Optimizations
39106 \begin_inset LatexCommand index
39107 name "Optimizations"
39108
39109 \end_inset
39110
39111 .
39112 \end_layout
39113
39114 \begin_layout Standard
39115 Bulk of the target independent optimizations is performed in this phase.
39116  The optimizations include constant propagation, common sub-expression eliminati
39117 on, loop invariant code movement, strength reduction of loop induction variables
39118  and dead-code elimination.
39119 \end_layout
39120
39121 \begin_layout Paragraph*
39122 Live range analysis
39123 \begin_inset LatexCommand index
39124 name "Live range analysis"
39125
39126 \end_inset
39127
39128
39129 \end_layout
39130
39131 \begin_layout Standard
39132 During intermediate code generation phase, the compiler assumes the target
39133  machine has infinite number of registers and generates a lot of temporary
39134  variables.
39135  The live range computation determines the lifetime of each of these compiler-ge
39136 nerated temporaries.
39137  A picture speaks a thousand words.
39138  ICode example sections show the live range annotations for each of the
39139  operand.
39140  It is important to note here, each iCode is assigned a number in the order
39141  of its execution in the function.
39142  The live ranges are computed in terms of these numbers.
39143  The from number is the number of the iCode which first defines the operand
39144  and the to number signifies the iCode which uses this operand last.
39145 \end_layout
39146
39147 \begin_layout Paragraph*
39148 Register Allocation
39149 \begin_inset LatexCommand index
39150 name "Register allocation"
39151
39152 \end_inset
39153
39154
39155 \end_layout
39156
39157 \begin_layout Standard
39158 The register allocation determines the type and number of registers needed
39159  by each operand.
39160  In most MCUs only a few registers can be used for indirect addressing.
39161  In case of 8051 for example the registers R0 & R1 can be used to indirectly
39162  address the internal ram and DPTR to indirectly address the external ram.
39163  The compiler will try to allocate the appropriate register to pointer variables
39164  if it can.
39165  ICode example section shows the operands annotated with the registers assigned
39166  to them.
39167  The compiler will try to keep operands in registers as much as possible;
39168  there are several schemes the compiler uses to do achieve this.
39169  When the compiler runs out of registers the compiler will check to see
39170  if there are any live operands which is not used or defined in the current
39171  basic block being processed, if there are any found then it will push that
39172  operand and use the registers in this block, the operand will then be popped
39173  at the end of the basic block.
39174  
39175 \end_layout
39176
39177 \begin_layout Standard
39178 There are other MCU specific considerations in this phase.
39179  Some MCUs have an accumulator; very short-lived operands could be assigned
39180  to the accumulator instead of a general-purpose register.
39181 \end_layout
39182
39183 \begin_layout Paragraph*
39184 Code generation
39185 \end_layout
39186
39187 \begin_layout Standard
39188 Figure II gives a table of iCode
39189 \begin_inset LatexCommand index
39190 name "iCode"
39191
39192 \end_inset
39193
39194  operations supported by the compiler.
39195  The code generation involves translating these operations into corresponding
39196  assembly code for the processor.
39197  This sounds overly simple but that is the essence of code generation.
39198  Some of the iCode operations are generated on a MCU specific manner for
39199  example, the z80 port does not use registers to pass parameters so the
39200  SEND and RECV iCode operations will not be generated, and it also does
39201  not support JUMPTABLES.
39202  
39203 \newline
39204
39205 \end_layout
39206
39207 \begin_layout Standard
39208
39209 \size footnotesize
39210 Figure II 
39211 \begin_inset Tabular
39212 <lyxtabular version="3" rows="39" columns="4">
39213 <features islongtable="true" headBottomDL="true">
39214 <column alignment="block" valignment="top" leftline="true" width="13col%">
39215 <column alignment="left" valignment="top" leftline="true" width="13col%">
39216 <column alignment="block" valignment="top" leftline="true" width="22col%">
39217 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39218 <row topline="true" bottomline="true" endhead="true">
39219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39220 \begin_inset Text
39221
39222 \begin_layout Standard
39223
39224 \series bold
39225 iCode
39226 \series default
39227
39228 \begin_inset LatexCommand index
39229 name "iCode"
39230
39231 \end_inset
39232
39233
39234 \end_layout
39235
39236 \end_inset
39237 </cell>
39238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39239 \begin_inset Text
39240
39241 \begin_layout Standard
39242
39243 \series bold
39244 Operands
39245 \end_layout
39246
39247 \end_inset
39248 </cell>
39249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39250 \begin_inset Text
39251
39252 \begin_layout Standard
39253
39254 \series bold
39255 Description
39256 \end_layout
39257
39258 \end_inset
39259 </cell>
39260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39261 \begin_inset Text
39262
39263 \begin_layout Standard
39264
39265 \series bold
39266 C Equivalent
39267 \end_layout
39268
39269 \end_inset
39270 </cell>
39271 </row>
39272 <row topline="true">
39273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39274 \begin_inset Text
39275
39276 \begin_layout Standard
39277
39278 \size footnotesize
39279 '!'
39280 \end_layout
39281
39282 \end_inset
39283 </cell>
39284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39285 \begin_inset Text
39286
39287 \begin_layout Standard
39288
39289 \size footnotesize
39290 IC_LEFT() IC_RESULT()
39291 \end_layout
39292
39293 \end_inset
39294 </cell>
39295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39296 \begin_inset Text
39297
39298 \begin_layout Standard
39299
39300 \size footnotesize
39301 NOT operation 
39302 \end_layout
39303
39304 \end_inset
39305 </cell>
39306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39307 \begin_inset Text
39308
39309 \begin_layout Standard
39310
39311 \size footnotesize
39312 IC_RESULT = ! IC_LEFT;
39313 \end_layout
39314
39315 \end_inset
39316 </cell>
39317 </row>
39318 <row topline="true">
39319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39320 \begin_inset Text
39321
39322 \begin_layout Standard
39323
39324 \size footnotesize
39325 '~'
39326 \end_layout
39327
39328 \end_inset
39329 </cell>
39330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39331 \begin_inset Text
39332
39333 \begin_layout Standard
39334
39335 \size footnotesize
39336 IC_LEFT() IC_RESULT()
39337 \end_layout
39338
39339 \end_inset
39340 </cell>
39341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39342 \begin_inset Text
39343
39344 \begin_layout Standard
39345
39346 \size footnotesize
39347 Bitwise complement of 
39348 \end_layout
39349
39350 \end_inset
39351 </cell>
39352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39353 \begin_inset Text
39354
39355 \begin_layout Standard
39356
39357 \size footnotesize
39358 IC_RESULT = ~IC_LEFT;
39359 \end_layout
39360
39361 \end_inset
39362 </cell>
39363 </row>
39364 <row topline="true">
39365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39366 \begin_inset Text
39367
39368 \begin_layout Standard
39369
39370 \size footnotesize
39371 RRC
39372 \end_layout
39373
39374 \end_inset
39375 </cell>
39376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39377 \begin_inset Text
39378
39379 \begin_layout Standard
39380
39381 \size footnotesize
39382 IC_LEFT() IC_RESULT()
39383 \end_layout
39384
39385 \end_inset
39386 </cell>
39387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39388 \begin_inset Text
39389
39390 \begin_layout Standard
39391
39392 \size footnotesize
39393 Rotate right with carry
39394 \end_layout
39395
39396 \end_inset
39397 </cell>
39398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39399 \begin_inset Text
39400
39401 \begin_layout Standard
39402
39403 \size footnotesize
39404 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39405 \end_layout
39406
39407 \end_inset
39408 </cell>
39409 </row>
39410 <row topline="true">
39411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39412 \begin_inset Text
39413
39414 \begin_layout Standard
39415
39416 \size footnotesize
39417 RLC
39418 \end_layout
39419
39420 \end_inset
39421 </cell>
39422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39423 \begin_inset Text
39424
39425 \begin_layout Standard
39426
39427 \size footnotesize
39428 IC_LEFT() IC_RESULT()
39429 \end_layout
39430
39431 \end_inset
39432 </cell>
39433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39434 \begin_inset Text
39435
39436 \begin_layout Standard
39437
39438 \size footnotesize
39439 Rotate left with carry
39440 \end_layout
39441
39442 \end_inset
39443 </cell>
39444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39445 \begin_inset Text
39446
39447 \begin_layout Standard
39448
39449 \size footnotesize
39450 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39451 \end_layout
39452
39453 \end_inset
39454 </cell>
39455 </row>
39456 <row topline="true">
39457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39458 \begin_inset Text
39459
39460 \begin_layout Standard
39461
39462 \size footnotesize
39463 GETHBIT
39464 \end_layout
39465
39466 \end_inset
39467 </cell>
39468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39469 \begin_inset Text
39470
39471 \begin_layout Standard
39472
39473 \size footnotesize
39474 IC_LEFT() IC_RESULT()
39475 \end_layout
39476
39477 \end_inset
39478 </cell>
39479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39480 \begin_inset Text
39481
39482 \begin_layout Standard
39483
39484 \size footnotesize
39485 Get the highest order bit of IC_LEFT
39486 \end_layout
39487
39488 \end_inset
39489 </cell>
39490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39491 \begin_inset Text
39492
39493 \begin_layout Standard
39494
39495 \size footnotesize
39496 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39497 \end_layout
39498
39499 \end_inset
39500 </cell>
39501 </row>
39502 <row topline="true">
39503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39504 \begin_inset Text
39505
39506 \begin_layout Standard
39507
39508 \size footnotesize
39509 UNARYMINUS
39510 \end_layout
39511
39512 \end_inset
39513 </cell>
39514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39515 \begin_inset Text
39516
39517 \begin_layout Standard
39518
39519 \size footnotesize
39520 IC_LEFT() IC_RESULT()
39521 \end_layout
39522
39523 \end_inset
39524 </cell>
39525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39526 \begin_inset Text
39527
39528 \begin_layout Standard
39529
39530 \size footnotesize
39531 Unary minus
39532 \end_layout
39533
39534 \end_inset
39535 </cell>
39536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39537 \begin_inset Text
39538
39539 \begin_layout Standard
39540
39541 \size footnotesize
39542 IC_RESULT = - IC_LEFT;
39543 \end_layout
39544
39545 \end_inset
39546 </cell>
39547 </row>
39548 <row topline="true">
39549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39550 \begin_inset Text
39551
39552 \begin_layout Standard
39553
39554 \size footnotesize
39555 IPUSH
39556 \end_layout
39557
39558 \end_inset
39559 </cell>
39560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39561 \begin_inset Text
39562
39563 \begin_layout Standard
39564
39565 \size footnotesize
39566 IC_LEFT()
39567 \end_layout
39568
39569 \end_inset
39570 </cell>
39571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39572 \begin_inset Text
39573
39574 \begin_layout Standard
39575
39576 \size footnotesize
39577 Push the operand into stack
39578 \end_layout
39579
39580 \end_inset
39581 </cell>
39582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39583 \begin_inset Text
39584
39585 \begin_layout Standard
39586
39587 \size footnotesize
39588 NONE
39589 \end_layout
39590
39591 \end_inset
39592 </cell>
39593 </row>
39594 <row topline="true">
39595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39596 \begin_inset Text
39597
39598 \begin_layout Standard
39599
39600 \size footnotesize
39601 IPOP
39602 \end_layout
39603
39604 \end_inset
39605 </cell>
39606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39607 \begin_inset Text
39608
39609 \begin_layout Standard
39610
39611 \size footnotesize
39612 IC_LEFT()
39613 \end_layout
39614
39615 \end_inset
39616 </cell>
39617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39618 \begin_inset Text
39619
39620 \begin_layout Standard
39621
39622 \size footnotesize
39623 Pop the operand from the stack 
39624 \end_layout
39625
39626 \end_inset
39627 </cell>
39628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39629 \begin_inset Text
39630
39631 \begin_layout Standard
39632
39633 \size footnotesize
39634 NONE
39635 \end_layout
39636
39637 \end_inset
39638 </cell>
39639 </row>
39640 <row topline="true">
39641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39642 \begin_inset Text
39643
39644 \begin_layout Standard
39645
39646 \size footnotesize
39647 CALL
39648 \end_layout
39649
39650 \end_inset
39651 </cell>
39652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39653 \begin_inset Text
39654
39655 \begin_layout Standard
39656
39657 \size footnotesize
39658 IC_LEFT() IC_RESULT()
39659 \end_layout
39660
39661 \end_inset
39662 </cell>
39663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39664 \begin_inset Text
39665
39666 \begin_layout Standard
39667
39668 \size footnotesize
39669 Call the function represented by IC_LEFT 
39670 \end_layout
39671
39672 \end_inset
39673 </cell>
39674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39675 \begin_inset Text
39676
39677 \begin_layout Standard
39678
39679 \size footnotesize
39680 IC_RESULT = IC_LEFT();
39681 \end_layout
39682
39683 \end_inset
39684 </cell>
39685 </row>
39686 <row topline="true">
39687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39688 \begin_inset Text
39689
39690 \begin_layout Standard
39691
39692 \size footnotesize
39693 PCALL
39694 \end_layout
39695
39696 \end_inset
39697 </cell>
39698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39699 \begin_inset Text
39700
39701 \begin_layout Standard
39702
39703 \size footnotesize
39704 IC_LEFT() IC_RESULT()
39705 \end_layout
39706
39707 \end_inset
39708 </cell>
39709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39710 \begin_inset Text
39711
39712 \begin_layout Standard
39713
39714 \size footnotesize
39715 Call via function pointer
39716 \end_layout
39717
39718 \end_inset
39719 </cell>
39720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39721 \begin_inset Text
39722
39723 \begin_layout Standard
39724
39725 \size footnotesize
39726 IC_RESULT = (*IC_LEFT)();
39727 \end_layout
39728
39729 \end_inset
39730 </cell>
39731 </row>
39732 <row topline="true">
39733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39734 \begin_inset Text
39735
39736 \begin_layout Standard
39737
39738 \size footnotesize
39739 RETURN
39740 \end_layout
39741
39742 \end_inset
39743 </cell>
39744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39745 \begin_inset Text
39746
39747 \begin_layout Standard
39748
39749 \size footnotesize
39750 IC_LEFT()
39751 \end_layout
39752
39753 \end_inset
39754 </cell>
39755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39756 \begin_inset Text
39757
39758 \begin_layout Standard
39759
39760 \size footnotesize
39761 Return the value in operand IC_LEFT 
39762 \end_layout
39763
39764 \end_inset
39765 </cell>
39766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39767 \begin_inset Text
39768
39769 \begin_layout Standard
39770
39771 \size footnotesize
39772 return IC_LEFT;
39773 \end_layout
39774
39775 \end_inset
39776 </cell>
39777 </row>
39778 <row topline="true">
39779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39780 \begin_inset Text
39781
39782 \begin_layout Standard
39783
39784 \size footnotesize
39785 LABEL
39786 \end_layout
39787
39788 \end_inset
39789 </cell>
39790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39791 \begin_inset Text
39792
39793 \begin_layout Standard
39794
39795 \size footnotesize
39796 IC_LABEL() 
39797 \end_layout
39798
39799 \end_inset
39800 </cell>
39801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39802 \begin_inset Text
39803
39804 \begin_layout Standard
39805
39806 \size footnotesize
39807 Label
39808 \end_layout
39809
39810 \end_inset
39811 </cell>
39812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39813 \begin_inset Text
39814
39815 \begin_layout Standard
39816
39817 \size footnotesize
39818 IC_LABEL:
39819 \end_layout
39820
39821 \end_inset
39822 </cell>
39823 </row>
39824 <row topline="true">
39825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39826 \begin_inset Text
39827
39828 \begin_layout Standard
39829
39830 \size footnotesize
39831 GOTO
39832 \end_layout
39833
39834 \end_inset
39835 </cell>
39836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39837 \begin_inset Text
39838
39839 \begin_layout Standard
39840
39841 \size footnotesize
39842 IC_LABEL() 
39843 \end_layout
39844
39845 \end_inset
39846 </cell>
39847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39848 \begin_inset Text
39849
39850 \begin_layout Standard
39851
39852 \size footnotesize
39853 Goto label
39854 \end_layout
39855
39856 \end_inset
39857 </cell>
39858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39859 \begin_inset Text
39860
39861 \begin_layout Standard
39862
39863 \size footnotesize
39864 goto IC_LABEL();
39865 \end_layout
39866
39867 \end_inset
39868 </cell>
39869 </row>
39870 <row topline="true">
39871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39872 \begin_inset Text
39873
39874 \begin_layout Standard
39875
39876 \size footnotesize
39877 '+'
39878 \end_layout
39879
39880 \end_inset
39881 </cell>
39882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39883 \begin_inset Text
39884
39885 \begin_layout Standard
39886
39887 \size footnotesize
39888 IC_LEFT() IC_RIGHT() IC_RESULT()
39889 \end_layout
39890
39891 \end_inset
39892 </cell>
39893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39894 \begin_inset Text
39895
39896 \begin_layout Standard
39897
39898 \size footnotesize
39899 Addition
39900 \end_layout
39901
39902 \end_inset
39903 </cell>
39904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39905 \begin_inset Text
39906
39907 \begin_layout Standard
39908
39909 \size footnotesize
39910 IC_RESULT = IC_LEFT + IC_RIGHT
39911 \end_layout
39912
39913 \end_inset
39914 </cell>
39915 </row>
39916 <row topline="true">
39917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39918 \begin_inset Text
39919
39920 \begin_layout Standard
39921
39922 \size footnotesize
39923 '-'
39924 \end_layout
39925
39926 \end_inset
39927 </cell>
39928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39929 \begin_inset Text
39930
39931 \begin_layout Standard
39932
39933 \size footnotesize
39934 IC_LEFT() IC_RIGHT() IC_RESULT()
39935 \end_layout
39936
39937 \end_inset
39938 </cell>
39939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39940 \begin_inset Text
39941
39942 \begin_layout Standard
39943
39944 \size footnotesize
39945 Subtraction
39946 \end_layout
39947
39948 \end_inset
39949 </cell>
39950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39951 \begin_inset Text
39952
39953 \begin_layout Standard
39954
39955 \size footnotesize
39956 IC_RESULT = IC_LEFT - IC_RIGHT 
39957 \end_layout
39958
39959 \end_inset
39960 </cell>
39961 </row>
39962 <row topline="true">
39963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39964 \begin_inset Text
39965
39966 \begin_layout Standard
39967
39968 \size footnotesize
39969 '*'
39970 \end_layout
39971
39972 \end_inset
39973 </cell>
39974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39975 \begin_inset Text
39976
39977 \begin_layout Standard
39978
39979 \size footnotesize
39980 IC_LEFT() IC_RIGHT() IC_RESULT()
39981 \end_layout
39982
39983 \end_inset
39984 </cell>
39985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39986 \begin_inset Text
39987
39988 \begin_layout Standard
39989
39990 \size footnotesize
39991 Multiplication 
39992 \end_layout
39993
39994 \end_inset
39995 </cell>
39996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39997 \begin_inset Text
39998
39999 \begin_layout Standard
40000
40001 \size footnotesize
40002 IC_RESULT = IC_LEFT * IC_RIGHT;
40003 \end_layout
40004
40005 \end_inset
40006 </cell>
40007 </row>
40008 <row topline="true">
40009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40010 \begin_inset Text
40011
40012 \begin_layout Standard
40013
40014 \size footnotesize
40015 '/'
40016 \end_layout
40017
40018 \end_inset
40019 </cell>
40020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40021 \begin_inset Text
40022
40023 \begin_layout Standard
40024
40025 \size footnotesize
40026 IC_LEFT() IC_RIGHT() IC_RESULT()
40027 \end_layout
40028
40029 \end_inset
40030 </cell>
40031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40032 \begin_inset Text
40033
40034 \begin_layout Standard
40035
40036 \size footnotesize
40037 Division
40038 \end_layout
40039
40040 \end_inset
40041 </cell>
40042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40043 \begin_inset Text
40044
40045 \begin_layout Standard
40046
40047 \size footnotesize
40048 IC_RESULT = IC_LEFT / IC_RIGHT;
40049 \end_layout
40050
40051 \end_inset
40052 </cell>
40053 </row>
40054 <row topline="true">
40055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40056 \begin_inset Text
40057
40058 \begin_layout Standard
40059
40060 \size footnotesize
40061 '%'
40062 \end_layout
40063
40064 \end_inset
40065 </cell>
40066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40067 \begin_inset Text
40068
40069 \begin_layout Standard
40070
40071 \size footnotesize
40072 IC_LEFT() IC_RIGHT() IC_RESULT()
40073 \end_layout
40074
40075 \end_inset
40076 </cell>
40077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40078 \begin_inset Text
40079
40080 \begin_layout Standard
40081
40082 \size footnotesize
40083 Modulus
40084 \end_layout
40085
40086 \end_inset
40087 </cell>
40088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40089 \begin_inset Text
40090
40091 \begin_layout Standard
40092
40093 \size footnotesize
40094 IC_RESULT = IC_LEFT % IC_RIGHT;
40095 \end_layout
40096
40097 \end_inset
40098 </cell>
40099 </row>
40100 <row topline="true">
40101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40102 \begin_inset Text
40103
40104 \begin_layout Standard
40105
40106 \size footnotesize
40107 '<'
40108 \end_layout
40109
40110 \end_inset
40111 </cell>
40112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40113 \begin_inset Text
40114
40115 \begin_layout Standard
40116
40117 \size footnotesize
40118 IC_LEFT() IC_RIGHT() IC_RESULT()
40119 \end_layout
40120
40121 \end_inset
40122 </cell>
40123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40124 \begin_inset Text
40125
40126 \begin_layout Standard
40127
40128 \size footnotesize
40129 Less than
40130 \end_layout
40131
40132 \end_inset
40133 </cell>
40134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40135 \begin_inset Text
40136
40137 \begin_layout Standard
40138
40139 \size footnotesize
40140 IC_RESULT = IC_LEFT < IC_RIGHT;
40141 \end_layout
40142
40143 \end_inset
40144 </cell>
40145 </row>
40146 <row topline="true">
40147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40148 \begin_inset Text
40149
40150 \begin_layout Standard
40151
40152 \size footnotesize
40153 '>'
40154 \end_layout
40155
40156 \end_inset
40157 </cell>
40158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40159 \begin_inset Text
40160
40161 \begin_layout Standard
40162
40163 \size footnotesize
40164 IC_LEFT() IC_RIGHT() IC_RESULT()
40165 \end_layout
40166
40167 \end_inset
40168 </cell>
40169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40170 \begin_inset Text
40171
40172 \begin_layout Standard
40173
40174 \size footnotesize
40175 Greater than 
40176 \end_layout
40177
40178 \end_inset
40179 </cell>
40180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40181 \begin_inset Text
40182
40183 \begin_layout Standard
40184
40185 \size footnotesize
40186 IC_RESULT = IC_LEFT > IC_RIGHT;
40187 \end_layout
40188
40189 \end_inset
40190 </cell>
40191 </row>
40192 <row topline="true">
40193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40194 \begin_inset Text
40195
40196 \begin_layout Standard
40197
40198 \size footnotesize
40199 EQ_OP
40200 \end_layout
40201
40202 \end_inset
40203 </cell>
40204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40205 \begin_inset Text
40206
40207 \begin_layout Standard
40208
40209 \size footnotesize
40210 IC_LEFT() IC_RIGHT() IC_RESULT()
40211 \end_layout
40212
40213 \end_inset
40214 </cell>
40215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40216 \begin_inset Text
40217
40218 \begin_layout Standard
40219
40220 \size footnotesize
40221 Equal to 
40222 \end_layout
40223
40224 \end_inset
40225 </cell>
40226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40227 \begin_inset Text
40228
40229 \begin_layout Standard
40230
40231 \size footnotesize
40232 IC_RESULT = IC_LEFT == IC_RIGHT;
40233 \end_layout
40234
40235 \end_inset
40236 </cell>
40237 </row>
40238 <row topline="true">
40239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40240 \begin_inset Text
40241
40242 \begin_layout Standard
40243
40244 \size footnotesize
40245 AND_OP
40246 \end_layout
40247
40248 \end_inset
40249 </cell>
40250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40251 \begin_inset Text
40252
40253 \begin_layout Standard
40254
40255 \size footnotesize
40256 IC_LEFT() IC_RIGHT() IC_RESULT() 
40257 \end_layout
40258
40259 \end_inset
40260 </cell>
40261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40262 \begin_inset Text
40263
40264 \begin_layout Standard
40265
40266 \size footnotesize
40267 Logical and operation
40268 \end_layout
40269
40270 \end_inset
40271 </cell>
40272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40273 \begin_inset Text
40274
40275 \begin_layout Standard
40276
40277 \size footnotesize
40278 IC_RESULT = IC_LEFT && IC_RIGHT; 
40279 \end_layout
40280
40281 \end_inset
40282 </cell>
40283 </row>
40284 <row topline="true">
40285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40286 \begin_inset Text
40287
40288 \begin_layout Standard
40289
40290 \size footnotesize
40291 OR_OP
40292 \end_layout
40293
40294 \end_inset
40295 </cell>
40296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40297 \begin_inset Text
40298
40299 \begin_layout Standard
40300
40301 \size footnotesize
40302 IC_LEFT() IC_RIGHT() IC_RESULT() 
40303 \end_layout
40304
40305 \end_inset
40306 </cell>
40307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40308 \begin_inset Text
40309
40310 \begin_layout Standard
40311
40312 \size footnotesize
40313 Logical or operation 
40314 \end_layout
40315
40316 \end_inset
40317 </cell>
40318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40319 \begin_inset Text
40320
40321 \begin_layout Standard
40322
40323 \size footnotesize
40324 IC_RESULT = IC_LEFT || IC_RIGHT; 
40325 \end_layout
40326
40327 \end_inset
40328 </cell>
40329 </row>
40330 <row topline="true">
40331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40332 \begin_inset Text
40333
40334 \begin_layout Standard
40335
40336 \size footnotesize
40337 '^'
40338 \end_layout
40339
40340 \end_inset
40341 </cell>
40342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40343 \begin_inset Text
40344
40345 \begin_layout Standard
40346
40347 \size footnotesize
40348 IC_LEFT() IC_RIGHT() IC_RESULT() 
40349 \end_layout
40350
40351 \end_inset
40352 </cell>
40353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40354 \begin_inset Text
40355
40356 \begin_layout Standard
40357
40358 \size footnotesize
40359 Exclusive OR
40360 \end_layout
40361
40362 \end_inset
40363 </cell>
40364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40365 \begin_inset Text
40366
40367 \begin_layout Standard
40368
40369 \size footnotesize
40370 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40371 \end_layout
40372
40373 \end_inset
40374 </cell>
40375 </row>
40376 <row topline="true">
40377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40378 \begin_inset Text
40379
40380 \begin_layout Standard
40381
40382 \size footnotesize
40383 '|'
40384 \end_layout
40385
40386 \end_inset
40387 </cell>
40388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40389 \begin_inset Text
40390
40391 \begin_layout Standard
40392
40393 \size footnotesize
40394 IC_LEFT() IC_RIGHT() IC_RESULT() 
40395 \end_layout
40396
40397 \end_inset
40398 </cell>
40399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40400 \begin_inset Text
40401
40402 \begin_layout Standard
40403
40404 \size footnotesize
40405 Bitwise OR 
40406 \end_layout
40407
40408 \end_inset
40409 </cell>
40410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40411 \begin_inset Text
40412
40413 \begin_layout Standard
40414
40415 \size footnotesize
40416 IC_RESULT = IC_LEFT | IC_RIGHT;
40417 \end_layout
40418
40419 \end_inset
40420 </cell>
40421 </row>
40422 <row topline="true">
40423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40424 \begin_inset Text
40425
40426 \begin_layout Standard
40427
40428 \size footnotesize
40429 BITWISEAND
40430 \end_layout
40431
40432 \end_inset
40433 </cell>
40434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40435 \begin_inset Text
40436
40437 \begin_layout Standard
40438
40439 \size footnotesize
40440 IC_LEFT() IC_RIGHT() IC_RESULT()
40441 \end_layout
40442
40443 \end_inset
40444 </cell>
40445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40446 \begin_inset Text
40447
40448 \begin_layout Standard
40449
40450 \size footnotesize
40451 Bitwise AND 
40452 \end_layout
40453
40454 \end_inset
40455 </cell>
40456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40457 \begin_inset Text
40458
40459 \begin_layout Standard
40460
40461 \size footnotesize
40462 IC_RESULT = IC_LEFT & IC_RIGHT;
40463 \end_layout
40464
40465 \end_inset
40466 </cell>
40467 </row>
40468 <row topline="true">
40469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40470 \begin_inset Text
40471
40472 \begin_layout Standard
40473
40474 \size footnotesize
40475 LEFT_OP
40476 \end_layout
40477
40478 \end_inset
40479 </cell>
40480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40481 \begin_inset Text
40482
40483 \begin_layout Standard
40484
40485 \size footnotesize
40486 IC_LEFT() IC_RIGHT() IC_RESULT()
40487 \end_layout
40488
40489 \end_inset
40490 </cell>
40491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40492 \begin_inset Text
40493
40494 \begin_layout Standard
40495
40496 \size footnotesize
40497 Left shift 
40498 \end_layout
40499
40500 \end_inset
40501 </cell>
40502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40503 \begin_inset Text
40504
40505 \begin_layout Standard
40506
40507 \size footnotesize
40508 IC_RESULT = IC_LEFT << IC_RIGHT 
40509 \end_layout
40510
40511 \end_inset
40512 </cell>
40513 </row>
40514 <row topline="true">
40515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40516 \begin_inset Text
40517
40518 \begin_layout Standard
40519
40520 \size footnotesize
40521 RIGHT_OP
40522 \end_layout
40523
40524 \end_inset
40525 </cell>
40526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40527 \begin_inset Text
40528
40529 \begin_layout Standard
40530
40531 \size footnotesize
40532 IC_LEFT() IC_RIGHT() IC_RESULT()
40533 \end_layout
40534
40535 \end_inset
40536 </cell>
40537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40538 \begin_inset Text
40539
40540 \begin_layout Standard
40541
40542 \size footnotesize
40543 Right shift
40544 \end_layout
40545
40546 \end_inset
40547 </cell>
40548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40549 \begin_inset Text
40550
40551 \begin_layout Standard
40552
40553 \size footnotesize
40554 IC_RESULT = IC_LEFT >> IC_RIGHT 
40555 \end_layout
40556
40557 \end_inset
40558 </cell>
40559 </row>
40560 <row topline="true">
40561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40562 \begin_inset Text
40563
40564 \begin_layout Standard
40565
40566 \size footnotesize
40567 GET_VALUE_
40568 \newline
40569 AT_ ADDRESS
40570 \end_layout
40571
40572 \end_inset
40573 </cell>
40574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40575 \begin_inset Text
40576
40577 \begin_layout Standard
40578
40579 \size footnotesize
40580 IC_LEFT() IC_RESULT()
40581 \end_layout
40582
40583 \end_inset
40584 </cell>
40585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40586 \begin_inset Text
40587
40588 \begin_layout Standard
40589
40590 \size footnotesize
40591 Indirect fetch 
40592 \end_layout
40593
40594 \end_inset
40595 </cell>
40596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40597 \begin_inset Text
40598
40599 \begin_layout Standard
40600
40601 \size footnotesize
40602 IC_RESULT = (*IC_LEFT);
40603 \end_layout
40604
40605 \end_inset
40606 </cell>
40607 </row>
40608 <row topline="true">
40609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40610 \begin_inset Text
40611
40612 \begin_layout Standard
40613
40614 \size footnotesize
40615 POINTER_SET
40616 \end_layout
40617
40618 \end_inset
40619 </cell>
40620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40621 \begin_inset Text
40622
40623 \begin_layout Standard
40624
40625 \size footnotesize
40626 IC_RIGHT() IC_RESULT() 
40627 \end_layout
40628
40629 \end_inset
40630 </cell>
40631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40632 \begin_inset Text
40633
40634 \begin_layout Standard
40635
40636 \size footnotesize
40637 Indirect set
40638 \end_layout
40639
40640 \end_inset
40641 </cell>
40642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40643 \begin_inset Text
40644
40645 \begin_layout Standard
40646
40647 \size footnotesize
40648 (*IC_RESULT) = IC_RIGHT;
40649 \end_layout
40650
40651 \end_inset
40652 </cell>
40653 </row>
40654 <row topline="true">
40655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40656 \begin_inset Text
40657
40658 \begin_layout Standard
40659
40660 \size footnotesize
40661 '='
40662 \end_layout
40663
40664 \end_inset
40665 </cell>
40666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40667 \begin_inset Text
40668
40669 \begin_layout Standard
40670
40671 \size footnotesize
40672 IC_RIGHT() IC_RESULT()
40673 \end_layout
40674
40675 \end_inset
40676 </cell>
40677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40678 \begin_inset Text
40679
40680 \begin_layout Standard
40681
40682 \size footnotesize
40683 Assignment
40684 \end_layout
40685
40686 \end_inset
40687 </cell>
40688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40689 \begin_inset Text
40690
40691 \begin_layout Standard
40692
40693 \size footnotesize
40694 IC_RESULT = IC_RIGHT;
40695 \end_layout
40696
40697 \end_inset
40698 </cell>
40699 </row>
40700 <row topline="true">
40701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40702 \begin_inset Text
40703
40704 \begin_layout Standard
40705
40706 \size footnotesize
40707 IFX
40708 \end_layout
40709
40710 \end_inset
40711 </cell>
40712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40713 \begin_inset Text
40714
40715 \begin_layout Standard
40716
40717 \size footnotesize
40718 IC_COND IC_TRUE IC_LABEL
40719 \end_layout
40720
40721 \end_inset
40722 </cell>
40723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40724 \begin_inset Text
40725
40726 \begin_layout Standard
40727
40728 \size footnotesize
40729 Conditional jump.
40730  If true label is present then jump to true label if condition is true else
40731  jump to false label if condition is false 
40732 \end_layout
40733
40734 \end_inset
40735 </cell>
40736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40737 \begin_inset Text
40738
40739 \begin_layout Standard
40740
40741 \size footnotesize
40742 if (IC_COND) goto IC_TRUE; 
40743 \newline
40744 \InsetSpace ~
40745 \InsetSpace ~
40746 Or 
40747 \newline
40748 If (!IC_COND) goto IC_FALSE;
40749 \end_layout
40750
40751 \end_inset
40752 </cell>
40753 </row>
40754 <row topline="true">
40755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40756 \begin_inset Text
40757
40758 \begin_layout Standard
40759
40760 \size footnotesize
40761 ADDRESS_OF
40762 \end_layout
40763
40764 \end_inset
40765 </cell>
40766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40767 \begin_inset Text
40768
40769 \begin_layout Standard
40770
40771 \size footnotesize
40772 IC_LEFT() IC_RESULT()
40773 \end_layout
40774
40775 \end_inset
40776 </cell>
40777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40778 \begin_inset Text
40779
40780 \begin_layout Standard
40781
40782 \size footnotesize
40783 Address of 
40784 \end_layout
40785
40786 \end_inset
40787 </cell>
40788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40789 \begin_inset Text
40790
40791 \begin_layout Standard
40792
40793 \size footnotesize
40794 IC_RESULT = &IC_LEFT();
40795 \end_layout
40796
40797 \end_inset
40798 </cell>
40799 </row>
40800 <row topline="true">
40801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40802 \begin_inset Text
40803
40804 \begin_layout Standard
40805
40806 \size footnotesize
40807 JUMPTABLE
40808 \end_layout
40809
40810 \end_inset
40811 </cell>
40812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40813 \begin_inset Text
40814
40815 \begin_layout Standard
40816
40817 \size footnotesize
40818 IC_JTCOND IC_JTLABELS
40819 \end_layout
40820
40821 \end_inset
40822 </cell>
40823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40824 \begin_inset Text
40825
40826 \begin_layout Standard
40827
40828 \size footnotesize
40829 Jump to list of labels depending on the value of JTCOND
40830 \end_layout
40831
40832 \end_inset
40833 </cell>
40834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40835 \begin_inset Text
40836
40837 \begin_layout Standard
40838
40839 \size footnotesize
40840 Switch statement
40841 \end_layout
40842
40843 \end_inset
40844 </cell>
40845 </row>
40846 <row topline="true">
40847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40848 \begin_inset Text
40849
40850 \begin_layout Standard
40851
40852 \size footnotesize
40853 CAST
40854 \end_layout
40855
40856 \end_inset
40857 </cell>
40858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40859 \begin_inset Text
40860
40861 \begin_layout Standard
40862
40863 \size footnotesize
40864 IC_RIGHT() IC_LEFT() IC_RESULT()
40865 \end_layout
40866
40867 \end_inset
40868 </cell>
40869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40870 \begin_inset Text
40871
40872 \begin_layout Standard
40873
40874 \size footnotesize
40875 Cast types 
40876 \end_layout
40877
40878 \end_inset
40879 </cell>
40880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40881 \begin_inset Text
40882
40883 \begin_layout Standard
40884
40885 \size footnotesize
40886 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
40887 \end_layout
40888
40889 \end_inset
40890 </cell>
40891 </row>
40892 <row topline="true">
40893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40894 \begin_inset Text
40895
40896 \begin_layout Standard
40897
40898 \size footnotesize
40899 SEND
40900 \end_layout
40901
40902 \end_inset
40903 </cell>
40904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40905 \begin_inset Text
40906
40907 \begin_layout Standard
40908
40909 \size footnotesize
40910 IC_LEFT()
40911 \end_layout
40912
40913 \end_inset
40914 </cell>
40915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40916 \begin_inset Text
40917
40918 \begin_layout Standard
40919
40920 \size footnotesize
40921 This is used for passing parameters in registers; 
40922 \newline
40923 move IC_LEFT to the next
40924  available parameter register.
40925 \end_layout
40926
40927 \end_inset
40928 </cell>
40929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40930 \begin_inset Text
40931
40932 \begin_layout Standard
40933
40934 \size footnotesize
40935 None
40936 \end_layout
40937
40938 \end_inset
40939 </cell>
40940 </row>
40941 <row topline="true">
40942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40943 \begin_inset Text
40944
40945 \begin_layout Standard
40946
40947 \size footnotesize
40948 RECV
40949 \end_layout
40950
40951 \end_inset
40952 </cell>
40953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40954 \begin_inset Text
40955
40956 \begin_layout Standard
40957
40958 \size footnotesize
40959 IC_RESULT()
40960 \end_layout
40961
40962 \end_inset
40963 </cell>
40964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40965 \begin_inset Text
40966
40967 \begin_layout Standard
40968
40969 \size footnotesize
40970 This is used for receiving parameters passed in registers;
40971 \newline
40972 Move the values
40973  in the next parameter register to IC_RESULT 
40974 \end_layout
40975
40976 \end_inset
40977 </cell>
40978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40979 \begin_inset Text
40980
40981 \begin_layout Standard
40982
40983 \size footnotesize
40984 None
40985 \end_layout
40986
40987 \end_inset
40988 </cell>
40989 </row>
40990 <row topline="true" bottomline="true">
40991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40992 \begin_inset Text
40993
40994 \begin_layout Standard
40995
40996 \shape slanted
40997 \size footnotesize
40998 (some more have been added)
40999 \end_layout
41000
41001 \end_inset
41002 </cell>
41003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41004 \begin_inset Text
41005
41006 \begin_layout Standard
41007
41008 \end_layout
41009
41010 \end_inset
41011 </cell>
41012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41013 \begin_inset Text
41014
41015 \begin_layout Standard
41016
41017 \end_layout
41018
41019 \end_inset
41020 </cell>
41021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41022 \begin_inset Text
41023
41024 \begin_layout Standard
41025
41026 \shape slanted
41027 \size footnotesize
41028 see f.e.
41029
41030 \shape default
41031  
41032 \family typewriter
41033 \shape slanted
41034 gen51Code()
41035 \family default
41036 \shape default
41037  
41038 \shape slanted
41039 in
41040 \shape default
41041  
41042 \family typewriter
41043 \shape slanted
41044 src/mcs51/gen.c
41045 \end_layout
41046
41047 \end_inset
41048 </cell>
41049 </row>
41050 </lyxtabular>
41051
41052 \end_inset
41053
41054
41055 \end_layout
41056
41057 \begin_layout Standard
41058 \begin_inset Note Note
41059 status collapsed
41060
41061 \begin_layout Standard
41062 In the original article Figure II was announced to be downloadable on 
41063 \shape italic
41064 Circuit Cellar
41065 \shape default
41066 's web site.
41067  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41068 \end_layout
41069
41070 \end_inset
41071
41072
41073 \end_layout
41074
41075 \begin_layout Paragraph*
41076 ICode Example
41077 \begin_inset LatexCommand index
41078 name "iCode"
41079
41080 \end_inset
41081
41082
41083 \end_layout
41084
41085 \begin_layout Standard
41086 This section shows some details of iCode.
41087  The example C code does not do anything useful; it is used as an example
41088  to illustrate the intermediate code generated by the compiler.
41089 \end_layout
41090
41091 \begin_layout Verse
41092
41093 \family typewriter
41094 1.\InsetSpace ~
41095 xdata int * p;
41096 \newline
41097 2.\InsetSpace ~
41098 int gint;
41099 \newline
41100 3.\InsetSpace ~
41101 /* This function does nothing useful.
41102  It is used
41103 \newline
41104 4.\InsetSpace ~
41105 \InsetSpace ~
41106 \InsetSpace ~
41107 \InsetSpace ~
41108 for the purpose of explaining iCode */
41109 \newline
41110 5.\InsetSpace ~
41111 short function (data
41112  int *x)
41113 \newline
41114 6.\InsetSpace ~
41115 {
41116 \newline
41117 7.\InsetSpace ~
41118 \InsetSpace ~
41119 \InsetSpace ~
41120 short i=10; \InsetSpace ~
41121 \InsetSpace ~
41122 /* dead initialization eliminated */
41123 \newline
41124 8.\InsetSpace ~
41125 \InsetSpace ~
41126 \InsetSpace ~
41127 short sum=10;
41128  /* dead initialization eliminated */
41129 \newline
41130 9.\InsetSpace ~
41131 \InsetSpace ~
41132 \InsetSpace ~
41133 short mul;
41134 \newline
41135 10.\InsetSpace ~
41136 \InsetSpace ~
41137 int j ;
41138 \newline
41139 11.\InsetSpace ~
41140 \InsetSpace ~
41141 while (*x) *x++
41142  = *p++; 
41143 \newline
41144 12.\InsetSpace ~
41145 \InsetSpace ~
41146 \InsetSpace ~
41147 \InsetSpace ~
41148 sum = 0 ; 
41149 \newline
41150 13.\InsetSpace ~
41151 \InsetSpace ~
41152 mul = 0;
41153 \newline
41154 14.\InsetSpace ~
41155 \InsetSpace ~
41156 /* compiler detects i,j to be induction
41157  variables */
41158 \newline
41159 15.\InsetSpace ~
41160 \InsetSpace ~
41161 for (i = 0, j = 10 ; i < 10 ; i++, j
41162 \family default
41163 -
41164 \begin_inset ERT
41165 status collapsed
41166
41167 \begin_layout Standard
41168
41169
41170 \backslash
41171 /
41172 \end_layout
41173
41174 \end_inset
41175
41176 -
41177 \family typewriter
41178 ) {
41179 \newline
41180 16.\InsetSpace ~
41181 \InsetSpace ~
41182 \InsetSpace ~
41183 \InsetSpace ~
41184 sum += i;
41185 \newline
41186 17.\InsetSpace ~
41187 \InsetSpace ~
41188 \InsetSpace ~
41189 \InsetSpace ~
41190 mul += i * 3; \InsetSpace ~
41191 \InsetSpace ~
41192 /* this multiplication remains */
41193 \newline
41194 18.\InsetSpace ~
41195 \InsetSpace ~
41196 \InsetSpace ~
41197 \InsetSpace ~
41198 gint +=
41199  j * 3;\InsetSpace ~
41200 \InsetSpace ~
41201 /* this multiplication changed to addition */
41202 \newline
41203 19.\InsetSpace ~
41204 \InsetSpace ~
41205 }
41206 \newline
41207 20.\InsetSpace ~
41208 \InsetSpace ~
41209 return sum+mul;
41210 \newline
41211 21.\InsetSpace ~
41212 }
41213 \end_layout
41214
41215 \begin_layout Standard
41216 In addition to the operands each iCode contains information about the filename
41217  and line it corresponds to in the source file.
41218  The first field in the listing should be interpreted as follows:
41219 \newline
41220
41221 \shape italic
41222 \size footnotesize
41223 Filename(linenumber: iCode Execution sequence number : ICode hash table
41224  key : loop depth of the iCode).
41225 \shape default
41226 \size default
41227
41228 \newline
41229 Then follows the human readable form of the ICode operation.
41230  Each operand of this triplet form can be of three basic types a) compiler
41231  generated temporary b) user defined variable c) a constant value.
41232  Note that local variables and parameters are replaced by compiler generated
41233  temporaries.
41234  Live ranges
41235 \begin_inset LatexCommand index
41236 name "Live range analysis"
41237
41238 \end_inset
41239
41240  are computed only for temporaries (i.e.
41241  live ranges are not computed for global variables).
41242  Registers
41243 \begin_inset LatexCommand index
41244 name "Register allocation"
41245
41246 \end_inset
41247
41248  are allocated for temporaries only.
41249  Operands are formatted in the following manner:
41250 \newline
41251
41252 \shape italic
41253 \size footnotesize
41254 Operand Name [lr live-from : live-to ] { type information } [ registers
41255  allocated ].
41256 \shape default
41257 \size default
41258
41259 \newline
41260 As mentioned earlier the live ranges are computed in terms of the execution
41261  sequence number of the iCodes, for example 
41262 \newline
41263 the iTemp0 is live from (i.e.
41264  first defined in iCode with execution sequence number 3, and is last used
41265  in the iCode with sequence number 5).
41266  For induction variables such as iTemp21 the live range computation extends
41267  the lifetime from the start to the end of the loop.
41268 \newline
41269 The register allocator
41270  used the live range information to allocate registers, the same registers
41271  may be used for different temporaries if their live ranges do not overlap,
41272  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41273  ranges do not overlap.
41274  In addition the allocator also takes into consideration the type and usage
41275  of a temporary, for example itemp6 is a pointer to near space and is used
41276  as to fetch data from (i.e.
41277  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41278  Some short lived temporaries are allocated to special registers which have
41279  meaning to the code generator e.g.
41280  iTemp13 is allocated to a pseudo register CC which tells the back end that
41281  the temporary is used only for a conditional jump the code generation makes
41282  use of this information to optimize a compare and jump ICode.
41283 \newline
41284 There are several
41285  loop optimizations
41286 \begin_inset LatexCommand index
41287 name "Loop optimization"
41288
41289 \end_inset
41290
41291  performed by the compiler.
41292  It can detect induction variables iTemp21(i) and iTemp23(j).
41293  Also note the compiler does selective strength reduction
41294 \begin_inset LatexCommand index
41295 name "Strength reduction"
41296
41297 \end_inset
41298
41299 , i.e.
41300  the multiplication of an induction variable in line 18 (gint = j * 3) is
41301  changed to addition, a new temporary iTemp17 is allocated and assigned
41302  a initial value, a constant 3 is then added for each iteration of the loop.
41303  The compiler does not change the multiplication
41304 \begin_inset LatexCommand index
41305 name "Multiplication"
41306
41307 \end_inset
41308
41309  in line 17 however since the processor does support an 8 * 8 bit multiplication.
41310 \newline
41311
41312 Note the dead code elimination
41313 \begin_inset LatexCommand index
41314 name "Dead-code elimination"
41315
41316 \end_inset
41317
41318  optimization eliminated the dead assignments in line 7 & 8 to I and sum
41319  respectively.
41320 \newline
41321
41322 \end_layout
41323
41324 \begin_layout Standard
41325
41326 \size footnotesize
41327 Sample.c (5:1:0:0) _entry($9) :
41328 \end_layout
41329
41330 \begin_layout Standard
41331
41332 \size footnotesize
41333 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41334 \end_layout
41335
41336 \begin_layout Standard
41337
41338 \size footnotesize
41339 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
41340 \end_layout
41341
41342 \begin_layout Standard
41343
41344 \size footnotesize
41345 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41346 \end_layout
41347
41348 \begin_layout Standard
41349
41350 \size footnotesize
41351 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41352  * int}[r2]
41353 \end_layout
41354
41355 \begin_layout Standard
41356
41357 \size footnotesize
41358 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41359 \end_layout
41360
41361 \begin_layout Standard
41362
41363 \size footnotesize
41364 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41365  int}[r0]]
41366 \end_layout
41367
41368 \begin_layout Standard
41369
41370 \size footnotesize
41371 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41372 \end_layout
41373
41374 \begin_layout Standard
41375
41376 \size footnotesize
41377 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41378  * int}
41379 \end_layout
41380
41381 \begin_layout Standard
41382
41383 \size footnotesize
41384 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41385  {short}
41386 \end_layout
41387
41388 \begin_layout Standard
41389
41390 \size footnotesize
41391 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41392  * int}[DPTR]]
41393 \end_layout
41394
41395 \begin_layout Standard
41396
41397 \size footnotesize
41398 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41399 }[r2 r3]
41400 \end_layout
41401
41402 \begin_layout Standard
41403
41404 \size footnotesize
41405 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41406  * int}[r0] + 0x2 {short}
41407 \end_layout
41408
41409 \begin_layout Standard
41410
41411 \size footnotesize
41412 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41413 \end_layout
41414
41415 \begin_layout Standard
41416
41417 \size footnotesize
41418 Sample.c(11:17:21:0)_whilebreak_0($3) :
41419 \end_layout
41420
41421 \begin_layout Standard
41422
41423 \size footnotesize
41424 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41425 \end_layout
41426
41427 \begin_layout Standard
41428
41429 \size footnotesize
41430 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41431 \end_layout
41432
41433 \begin_layout Standard
41434
41435 \size footnotesize
41436 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41437 \end_layout
41438
41439 \begin_layout Standard
41440
41441 \size footnotesize
41442 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41443 \end_layout
41444
41445 \begin_layout Standard
41446
41447 \size footnotesize
41448 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41449 \end_layout
41450
41451 \begin_layout Standard
41452
41453 \size footnotesize
41454 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41455 \end_layout
41456
41457 \begin_layout Standard
41458
41459 \size footnotesize
41460 Sample.c(15:24:26:1)_forcond_0($4) :
41461 \end_layout
41462
41463 \begin_layout Standard
41464
41465 \size footnotesize
41466 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41467  < 0xa {short}
41468 \end_layout
41469
41470 \begin_layout Standard
41471
41472 \size footnotesize
41473 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41474 \end_layout
41475
41476 \begin_layout Standard
41477
41478 \size footnotesize
41479 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41480  + ITemp21 [lr21:38]{short}[r4]
41481 \end_layout
41482
41483 \begin_layout Standard
41484
41485 \size footnotesize
41486 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41487  * 0x3 {short}
41488 \end_layout
41489
41490 \begin_layout Standard
41491
41492 \size footnotesize
41493 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41494  + iTemp15 [lr29:30]{short}[r1]
41495 \end_layout
41496
41497 \begin_layout Standard
41498
41499 \size footnotesize
41500 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41501  r0]- 0x3 {short}
41502 \end_layout
41503
41504 \begin_layout Standard
41505
41506 \size footnotesize
41507 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41508 int}[r7 r0]
41509 \end_layout
41510
41511 \begin_layout Standard
41512
41513 \size footnotesize
41514 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41515  + 0x1 {short}
41516 \end_layout
41517
41518 \begin_layout Standard
41519
41520 \size footnotesize
41521 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41522  r6]- 0x1 {short}
41523 \end_layout
41524
41525 \begin_layout Standard
41526
41527 \size footnotesize
41528 Sample.c(19:38:47:1) goto _forcond_0($4)
41529 \end_layout
41530
41531 \begin_layout Standard
41532
41533 \size footnotesize
41534 Sample.c(19:39:48:0)_forbreak_0($7) :
41535 \end_layout
41536
41537 \begin_layout Standard
41538
41539 \size footnotesize
41540 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41541  + ITemp11 [lr19:40]{short}[r3]
41542 \end_layout
41543
41544 \begin_layout Standard
41545
41546 \size footnotesize
41547 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41548 \end_layout
41549
41550 \begin_layout Standard
41551
41552 \size footnotesize
41553 Sample.c(20:42:51:0)_return($8) :
41554 \end_layout
41555
41556 \begin_layout Standard
41557
41558 \size footnotesize
41559 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41560 \size default
41561
41562 \newline
41563
41564 \newline
41565 Finally the code generated for this function:
41566 \newline
41567
41568 \end_layout
41569
41570 \begin_layout Standard
41571
41572 \size footnotesize
41573 .area DSEG (DATA)
41574 \end_layout
41575
41576 \begin_layout Standard
41577
41578 \size footnotesize
41579 _p::
41580 \end_layout
41581
41582 \begin_layout Standard
41583
41584 \size footnotesize
41585 \InsetSpace ~
41586 \InsetSpace ~
41587 .ds 2
41588 \end_layout
41589
41590 \begin_layout Standard
41591
41592 \size footnotesize
41593 _gint::
41594 \end_layout
41595
41596 \begin_layout Standard
41597
41598 \size footnotesize
41599 \InsetSpace ~
41600 \InsetSpace ~
41601 .ds 2
41602 \end_layout
41603
41604 \begin_layout Standard
41605
41606 \size footnotesize
41607 ; sample.c 5
41608 \end_layout
41609
41610 \begin_layout Standard
41611
41612 \size footnotesize
41613 ; ----------------------------------------------
41614 \end_layout
41615
41616 \begin_layout Standard
41617
41618 \size footnotesize
41619 ; function function
41620 \end_layout
41621
41622 \begin_layout Standard
41623
41624 \size footnotesize
41625 ; ----------------------------------------------
41626 \end_layout
41627
41628 \begin_layout Standard
41629
41630 \size footnotesize
41631 _function:
41632 \end_layout
41633
41634 \begin_layout Standard
41635
41636 \size footnotesize
41637 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
41638 \end_layout
41639
41640 \begin_layout Standard
41641
41642 \size footnotesize
41643 \InsetSpace ~
41644 \InsetSpace ~
41645 mov r2,dpl
41646 \end_layout
41647
41648 \begin_layout Standard
41649
41650 \size footnotesize
41651 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41652 \end_layout
41653
41654 \begin_layout Standard
41655
41656 \size footnotesize
41657 \InsetSpace ~
41658 \InsetSpace ~
41659 mov ar0,r2
41660 \end_layout
41661
41662 \begin_layout Standard
41663
41664 \size footnotesize
41665 ;_whilecontinue_0($1) :
41666 \end_layout
41667
41668 \begin_layout Standard
41669
41670 \size footnotesize
41671 00101$:
41672 \end_layout
41673
41674 \begin_layout Standard
41675
41676 \size footnotesize
41677 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41678 \end_layout
41679
41680 \begin_layout Standard
41681
41682 \size footnotesize
41683 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41684 \end_layout
41685
41686 \begin_layout Standard
41687
41688 \size footnotesize
41689 \InsetSpace ~
41690 \InsetSpace ~
41691 mov ar2,@r0
41692 \end_layout
41693
41694 \begin_layout Standard
41695
41696 \size footnotesize
41697 \InsetSpace ~
41698 \InsetSpace ~
41699 inc r0
41700 \end_layout
41701
41702 \begin_layout Standard
41703
41704 \size footnotesize
41705 \InsetSpace ~
41706 \InsetSpace ~
41707 mov ar3,@r0
41708 \end_layout
41709
41710 \begin_layout Standard
41711
41712 \size footnotesize
41713 \InsetSpace ~
41714 \InsetSpace ~
41715 dec r0
41716 \end_layout
41717
41718 \begin_layout Standard
41719
41720 \size footnotesize
41721 \InsetSpace ~
41722 \InsetSpace ~
41723 mov a,r2
41724 \end_layout
41725
41726 \begin_layout Standard
41727
41728 \size footnotesize
41729 \InsetSpace ~
41730 \InsetSpace ~
41731 orl a,r3
41732 \end_layout
41733
41734 \begin_layout Standard
41735
41736 \size footnotesize
41737 \InsetSpace ~
41738 \InsetSpace ~
41739 jz 00103$
41740 \end_layout
41741
41742 \begin_layout Standard
41743
41744 \size footnotesize
41745 00114$:
41746 \end_layout
41747
41748 \begin_layout Standard
41749
41750 \size footnotesize
41751 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
41752 \end_layout
41753
41754 \begin_layout Standard
41755
41756 \size footnotesize
41757 \InsetSpace ~
41758 \InsetSpace ~
41759 mov dpl,_p
41760 \end_layout
41761
41762 \begin_layout Standard
41763
41764 \size footnotesize
41765 \InsetSpace ~
41766 \InsetSpace ~
41767 mov dph,(_p + 1)
41768 \end_layout
41769
41770 \begin_layout Standard
41771
41772 \size footnotesize
41773 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
41774 \end_layout
41775
41776 \begin_layout Standard
41777
41778 \size footnotesize
41779 \InsetSpace ~
41780 \InsetSpace ~
41781 mov a,#0x02
41782 \end_layout
41783
41784 \begin_layout Standard
41785
41786 \size footnotesize
41787 \InsetSpace ~
41788 \InsetSpace ~
41789 add a,_p
41790 \end_layout
41791
41792 \begin_layout Standard
41793
41794 \size footnotesize
41795 \InsetSpace ~
41796 \InsetSpace ~
41797 mov _p,a
41798 \end_layout
41799
41800 \begin_layout Standard
41801
41802 \size footnotesize
41803 \InsetSpace ~
41804 \InsetSpace ~
41805 clr a
41806 \end_layout
41807
41808 \begin_layout Standard
41809
41810 \size footnotesize
41811 \InsetSpace ~
41812 \InsetSpace ~
41813 addc a,(_p + 1)
41814 \end_layout
41815
41816 \begin_layout Standard
41817
41818 \size footnotesize
41819 \InsetSpace ~
41820 \InsetSpace ~
41821 mov (_p + 1),a
41822 \end_layout
41823
41824 \begin_layout Standard
41825
41826 \size footnotesize
41827 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
41828 \end_layout
41829
41830 \begin_layout Standard
41831
41832 \size footnotesize
41833 \InsetSpace ~
41834 \InsetSpace ~
41835 movx a,@dptr
41836 \end_layout
41837
41838 \begin_layout Standard
41839
41840 \size footnotesize
41841 \InsetSpace ~
41842 \InsetSpace ~
41843 mov r2,a
41844 \end_layout
41845
41846 \begin_layout Standard
41847
41848 \size footnotesize
41849 \InsetSpace ~
41850 \InsetSpace ~
41851 inc dptr
41852 \end_layout
41853
41854 \begin_layout Standard
41855
41856 \size footnotesize
41857 \InsetSpace ~
41858 \InsetSpace ~
41859 movx a,@dptr
41860 \end_layout
41861
41862 \begin_layout Standard
41863
41864 \size footnotesize
41865 \InsetSpace ~
41866 \InsetSpace ~
41867 mov r3,a
41868 \end_layout
41869
41870 \begin_layout Standard
41871
41872 \size footnotesize
41873 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
41874 \end_layout
41875
41876 \begin_layout Standard
41877
41878 \size footnotesize
41879 \InsetSpace ~
41880 \InsetSpace ~
41881 mov @r0,ar2
41882 \end_layout
41883
41884 \begin_layout Standard
41885
41886 \size footnotesize
41887 \InsetSpace ~
41888 \InsetSpace ~
41889 inc r0
41890 \end_layout
41891
41892 \begin_layout Standard
41893
41894 \size footnotesize
41895 \InsetSpace ~
41896 \InsetSpace ~
41897 mov @r0,ar3
41898 \end_layout
41899
41900 \begin_layout Standard
41901
41902 \size footnotesize
41903 ; iTemp6 [lr5:16]{_near * int}[r0] = 
41904 \end_layout
41905
41906 \begin_layout Standard
41907
41908 \size footnotesize
41909 ; iTemp6 [lr5:16]{_near * int}[r0] + 
41910 \end_layout
41911
41912 \begin_layout Standard
41913
41914 \size footnotesize
41915 ; 0x2 {short}
41916 \end_layout
41917
41918 \begin_layout Standard
41919
41920 \size footnotesize
41921 \InsetSpace ~
41922 \InsetSpace ~
41923 inc r0
41924 \end_layout
41925
41926 \begin_layout Standard
41927
41928 \size footnotesize
41929 ; goto _whilecontinue_0($1)
41930 \end_layout
41931
41932 \begin_layout Standard
41933
41934 \size footnotesize
41935 \InsetSpace ~
41936 \InsetSpace ~
41937 sjmp 00101$
41938 \end_layout
41939
41940 \begin_layout Standard
41941
41942 \size footnotesize
41943 ; _whilebreak_0($3) :
41944 \end_layout
41945
41946 \begin_layout Standard
41947
41948 \size footnotesize
41949 00103$:
41950 \end_layout
41951
41952 \begin_layout Standard
41953
41954 \size footnotesize
41955 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41956 \end_layout
41957
41958 \begin_layout Standard
41959
41960 \size footnotesize
41961 \InsetSpace ~
41962 \InsetSpace ~
41963 mov r2,#0x00
41964 \end_layout
41965
41966 \begin_layout Standard
41967
41968 \size footnotesize
41969 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41970 \end_layout
41971
41972 \begin_layout Standard
41973
41974 \size footnotesize
41975 \InsetSpace ~
41976 \InsetSpace ~
41977 mov r3,#0x00
41978 \end_layout
41979
41980 \begin_layout Standard
41981
41982 \size footnotesize
41983 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41984 \end_layout
41985
41986 \begin_layout Standard
41987
41988 \size footnotesize
41989 \InsetSpace ~
41990 \InsetSpace ~
41991 mov r4,#0x00
41992 \end_layout
41993
41994 \begin_layout Standard
41995
41996 \size footnotesize
41997 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41998 \end_layout
41999
42000 \begin_layout Standard
42001
42002 \size footnotesize
42003 \InsetSpace ~
42004 \InsetSpace ~
42005 mov r5,#0x0A
42006 \end_layout
42007
42008 \begin_layout Standard
42009
42010 \size footnotesize
42011 \InsetSpace ~
42012 \InsetSpace ~
42013 mov r6,#0x00
42014 \end_layout
42015
42016 \begin_layout Standard
42017
42018 \size footnotesize
42019 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42020 \end_layout
42021
42022 \begin_layout Standard
42023
42024 \size footnotesize
42025 \InsetSpace ~
42026 \InsetSpace ~
42027 mov r7,#0x1E
42028 \end_layout
42029
42030 \begin_layout Standard
42031
42032 \size footnotesize
42033 \InsetSpace ~
42034 \InsetSpace ~
42035 mov r0,#0x00
42036 \end_layout
42037
42038 \begin_layout Standard
42039
42040 \size footnotesize
42041 ; _forcond_0($4) :
42042 \end_layout
42043
42044 \begin_layout Standard
42045
42046 \size footnotesize
42047 00104$:
42048 \end_layout
42049
42050 \begin_layout Standard
42051
42052 \size footnotesize
42053 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42054 \end_layout
42055
42056 \begin_layout Standard
42057
42058 \size footnotesize
42059 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42060 \end_layout
42061
42062 \begin_layout Standard
42063
42064 \size footnotesize
42065 \InsetSpace ~
42066 \InsetSpace ~
42067 clr c
42068 \end_layout
42069
42070 \begin_layout Standard
42071
42072 \size footnotesize
42073 \InsetSpace ~
42074 \InsetSpace ~
42075 mov a,r4
42076 \end_layout
42077
42078 \begin_layout Standard
42079
42080 \size footnotesize
42081 \InsetSpace ~
42082 \InsetSpace ~
42083 xrl a,#0x80
42084 \end_layout
42085
42086 \begin_layout Standard
42087
42088 \size footnotesize
42089 \InsetSpace ~
42090 \InsetSpace ~
42091 subb a,#0x8a
42092 \end_layout
42093
42094 \begin_layout Standard
42095
42096 \size footnotesize
42097 \InsetSpace ~
42098 \InsetSpace ~
42099 jnc 00107$
42100 \end_layout
42101
42102 \begin_layout Standard
42103
42104 \size footnotesize
42105 00115$:
42106 \end_layout
42107
42108 \begin_layout Standard
42109
42110 \size footnotesize
42111 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
42112 \end_layout
42113
42114 \begin_layout Standard
42115
42116 \size footnotesize
42117 ; iTemp21 [lr21:38]{short}[r4]
42118 \end_layout
42119
42120 \begin_layout Standard
42121
42122 \size footnotesize
42123 \InsetSpace ~
42124 \InsetSpace ~
42125 mov a,r4
42126 \end_layout
42127
42128 \begin_layout Standard
42129
42130 \size footnotesize
42131 \InsetSpace ~
42132 \InsetSpace ~
42133 add a,r2
42134 \end_layout
42135
42136 \begin_layout Standard
42137
42138 \size footnotesize
42139 \InsetSpace ~
42140 \InsetSpace ~
42141 mov r2,a
42142 \end_layout
42143
42144 \begin_layout Standard
42145
42146 \size footnotesize
42147 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42148 \end_layout
42149
42150 \begin_layout Standard
42151
42152 \size footnotesize
42153 \InsetSpace ~
42154 \InsetSpace ~
42155 mov b,#0x03
42156 \end_layout
42157
42158 \begin_layout Standard
42159
42160 \size footnotesize
42161 \InsetSpace ~
42162 \InsetSpace ~
42163 mov a,r4
42164 \end_layout
42165
42166 \begin_layout Standard
42167
42168 \size footnotesize
42169 \InsetSpace ~
42170 \InsetSpace ~
42171 mul ab
42172 \end_layout
42173
42174 \begin_layout Standard
42175
42176 \size footnotesize
42177 \InsetSpace ~
42178 \InsetSpace ~
42179 mov r1,a
42180 \end_layout
42181
42182 \begin_layout Standard
42183
42184 \size footnotesize
42185 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
42186 \end_layout
42187
42188 \begin_layout Standard
42189
42190 \size footnotesize
42191 ; iTemp15 [lr29:30]{short}[r1]
42192 \end_layout
42193
42194 \begin_layout Standard
42195
42196 \size footnotesize
42197 \InsetSpace ~
42198 \InsetSpace ~
42199 add a,r3
42200 \end_layout
42201
42202 \begin_layout Standard
42203
42204 \size footnotesize
42205 \InsetSpace ~
42206 \InsetSpace ~
42207 mov r3,a
42208 \end_layout
42209
42210 \begin_layout Standard
42211
42212 \size footnotesize
42213 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42214 \end_layout
42215
42216 \begin_layout Standard
42217
42218 \size footnotesize
42219 \InsetSpace ~
42220 \InsetSpace ~
42221 mov a,r7
42222 \end_layout
42223
42224 \begin_layout Standard
42225
42226 \size footnotesize
42227 \InsetSpace ~
42228 \InsetSpace ~
42229 add a,#0xfd
42230 \end_layout
42231
42232 \begin_layout Standard
42233
42234 \size footnotesize
42235 \InsetSpace ~
42236 \InsetSpace ~
42237 mov r7,a
42238 \end_layout
42239
42240 \begin_layout Standard
42241
42242 \size footnotesize
42243 \InsetSpace ~
42244 \InsetSpace ~
42245 mov a,r0
42246 \end_layout
42247
42248 \begin_layout Standard
42249
42250 \size footnotesize
42251 \InsetSpace ~
42252 \InsetSpace ~
42253 addc a,#0xff
42254 \end_layout
42255
42256 \begin_layout Standard
42257
42258 \size footnotesize
42259 \InsetSpace ~
42260 \InsetSpace ~
42261 mov r0,a
42262 \end_layout
42263
42264 \begin_layout Standard
42265
42266 \size footnotesize
42267 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42268 \end_layout
42269
42270 \begin_layout Standard
42271
42272 \size footnotesize
42273 \InsetSpace ~
42274 \InsetSpace ~
42275 mov a,r7
42276 \end_layout
42277
42278 \begin_layout Standard
42279
42280 \size footnotesize
42281 \InsetSpace ~
42282 \InsetSpace ~
42283 add a,_gint
42284 \end_layout
42285
42286 \begin_layout Standard
42287
42288 \size footnotesize
42289 \InsetSpace ~
42290 \InsetSpace ~
42291 mov _gint,a
42292 \end_layout
42293
42294 \begin_layout Standard
42295
42296 \size footnotesize
42297 \InsetSpace ~
42298 \InsetSpace ~
42299 mov a,r0
42300 \end_layout
42301
42302 \begin_layout Standard
42303
42304 \size footnotesize
42305 \InsetSpace ~
42306 \InsetSpace ~
42307 addc a,(_gint + 1)
42308 \end_layout
42309
42310 \begin_layout Standard
42311
42312 \size footnotesize
42313 \InsetSpace ~
42314 \InsetSpace ~
42315 mov (_gint + 1),a
42316 \end_layout
42317
42318 \begin_layout Standard
42319
42320 \size footnotesize
42321 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42322 \end_layout
42323
42324 \begin_layout Standard
42325
42326 \size footnotesize
42327 \InsetSpace ~
42328 \InsetSpace ~
42329 inc r4
42330 \end_layout
42331
42332 \begin_layout Standard
42333
42334 \size footnotesize
42335 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42336 \end_layout
42337
42338 \begin_layout Standard
42339
42340 \size footnotesize
42341 \InsetSpace ~
42342 \InsetSpace ~
42343 dec r5
42344 \end_layout
42345
42346 \begin_layout Standard
42347
42348 \size footnotesize
42349 \InsetSpace ~
42350 \InsetSpace ~
42351 cjne r5,#0xff,00104$
42352 \end_layout
42353
42354 \begin_layout Standard
42355
42356 \size footnotesize
42357 \InsetSpace ~
42358 \InsetSpace ~
42359 dec r6
42360 \end_layout
42361
42362 \begin_layout Standard
42363
42364 \size footnotesize
42365 ; goto _forcond_0($4)
42366 \end_layout
42367
42368 \begin_layout Standard
42369
42370 \size footnotesize
42371 \InsetSpace ~
42372 \InsetSpace ~
42373 sjmp 00104$
42374 \end_layout
42375
42376 \begin_layout Standard
42377
42378 \size footnotesize
42379 ; _forbreak_0($7) :
42380 \end_layout
42381
42382 \begin_layout Standard
42383
42384 \size footnotesize
42385 00107$:
42386 \end_layout
42387
42388 \begin_layout Standard
42389
42390 \size footnotesize
42391 ; ret iTemp24 [lr40:41]{short}
42392 \end_layout
42393
42394 \begin_layout Standard
42395
42396 \size footnotesize
42397 \InsetSpace ~
42398 \InsetSpace ~
42399 mov a,r3
42400 \end_layout
42401
42402 \begin_layout Standard
42403
42404 \size footnotesize
42405 \InsetSpace ~
42406 \InsetSpace ~
42407 add a,r2
42408 \end_layout
42409
42410 \begin_layout Standard
42411
42412 \size footnotesize
42413 \InsetSpace ~
42414 \InsetSpace ~
42415 mov dpl,a
42416 \end_layout
42417
42418 \begin_layout Standard
42419
42420 \size footnotesize
42421 ; _return($8) :
42422 \end_layout
42423
42424 \begin_layout Standard
42425
42426 \size footnotesize
42427 00108$:
42428 \end_layout
42429
42430 \begin_layout Standard
42431
42432 \size footnotesize
42433 \InsetSpace ~
42434 \InsetSpace ~
42435 ret
42436 \newline
42437
42438 \end_layout
42439
42440 \begin_layout Section
42441 A few words about basic block successors, predecessors and dominators
42442 \end_layout
42443
42444 \begin_layout Standard
42445 Successors are basic blocks
42446 \begin_inset LatexCommand index
42447 name "Basic blocks"
42448
42449 \end_inset
42450
42451  that might execute after this basic block.
42452 \newline
42453 Predecessors are basic blocks
42454  that might execute before reaching this basic block.
42455 \newline
42456 Dominators are basic
42457  blocks that WILL execute before reaching this basic block.
42458 \newline
42459
42460 \end_layout
42461
42462 \begin_layout Standard
42463 [basic block 1]
42464 \end_layout
42465
42466 \begin_layout Standard
42467 if (something)
42468 \end_layout
42469
42470 \begin_layout Standard
42471 \InsetSpace ~
42472 \InsetSpace ~
42473 \InsetSpace ~
42474 \InsetSpace ~
42475 [basic block 2]
42476 \end_layout
42477
42478 \begin_layout Standard
42479 else
42480 \end_layout
42481
42482 \begin_layout Standard
42483 \InsetSpace ~
42484 \InsetSpace ~
42485 \InsetSpace ~
42486 \InsetSpace ~
42487 [basic block 3]
42488 \end_layout
42489
42490 \begin_layout Standard
42491 [basic block 4]
42492 \newline
42493
42494 \end_layout
42495
42496 \begin_layout Standard
42497 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42498 \end_layout
42499
42500 \begin_layout Standard
42501 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42502 \end_layout
42503
42504 \begin_layout Standard
42505 c) domVect of [BB4] = BB1 ...
42506  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42507  was executed.
42508 \end_layout
42509
42510 \begin_layout Chapter
42511 Acknowledgments
42512 \end_layout
42513
42514 \begin_layout Standard
42515 \begin_inset LatexCommand url
42516 target "http://sdcc.sourceforge.net/#Who"
42517
42518 \end_inset
42519
42520
42521 \newline
42522
42523 \newline
42524
42525 \emph on
42526 Thanks to all the other volunteer developers who have helped with coding,
42527  testing, web-page creation, distribution sets, etc.
42528  You know who you are :-)
42529 \emph default
42530
42531 \newline
42532
42533 \newline
42534
42535 \emph on
42536 Thanks to Sourceforge 
42537 \begin_inset LatexCommand url
42538 target "http://www.sf.net"
42539
42540 \end_inset
42541
42542  which has hosted the project since 1999 and donates significant download
42543  bandwidth.
42544 \emph default
42545
42546 \newline
42547
42548 \newline
42549
42550 \emph on
42551 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42552  cycles and bandwidth for snapshot builds.
42553 \newline
42554
42555 \end_layout
42556
42557 \begin_layout Standard
42558 This document was initially written by Sandeep Dutta
42559 \end_layout
42560
42561 \begin_layout Standard
42562 All product names mentioned herein may be trademarks
42563 \begin_inset LatexCommand index
42564 name "Trademarks"
42565
42566 \end_inset
42567
42568  of their respective companies.
42569  
42570 \end_layout
42571
42572 \begin_layout Section*
42573 Alphabetical index
42574 \end_layout
42575
42576 \begin_layout Standard
42577 To avoid confusion, the installation and building options for SDCC itself
42578  (chapter 2) are not part of the index.
42579 \end_layout
42580
42581 \begin_layout Standard
42582 \begin_inset LatexCommand printindex
42583
42584 \end_inset
42585
42586
42587 \end_layout
42588
42589 \end_body
42590 \end_document