2007-04-13 Jan Waclawek <wek AT efton.sk>
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.2 created this file. For more info see http://www.lyx.org/
2 \lyxformat 245
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \fontscheme pslatex
26 \graphics default
27 \paperfontsize default
28 \spacing single
29 \papersize letterpaper
30 \use_geometry true
31 \use_amsmath 1
32 \cite_engine basic
33 \use_bibtopic false
34 \paperorientation portrait
35 \leftmargin 30mm
36 \topmargin 20mm
37 \rightmargin 25mm
38 \bottommargin 20mm
39 \secnumdepth 3
40 \tocdepth 3
41 \paragraph_separation indent
42 \defskip medskip
43 \quotes_language swedish
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47 \tracking_changes false
48 \output_changes true
49 \end_header
50
51 \begin_body
52
53 \begin_layout Standard
54 \begin_inset Note Note
55 status collapsed
56
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59  --version) are written this way: -
60 \begin_inset ERT
61 status collapsed
62
63 \begin_layout Standard
64
65
66 \backslash
67 /
68 \end_layout
69
70 \end_inset
71
72 -
73 \end_layout
74
75 \begin_layout Standard
76 Two resp.
77  three consecutive dashes would otherwise result in a long resp.
78  extra long dash.
79 \end_layout
80
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
83  later go
84 \end_layout
85
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
88  Z80 in 
89 \end_layout
90
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
93 \end_layout
94
95 \end_inset
96
97
98 \end_layout
99
100 \begin_layout Title
101 SDCC Compiler User Guide
102 \end_layout
103
104 \begin_layout Date
105
106 \size normal
107 SDCC 2.6.5
108 \size footnotesize
109
110 \newline
111 $Date$ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Note
118 status collapsed
119
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
122 \end_layout
123
124 \end_inset
125
126
127 \end_layout
128
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
131
132 \end_inset
133
134
135 \end_layout
136
137 \begin_layout Chapter
138 Introduction
139 \end_layout
140
141 \begin_layout Section
142 About SDCC
143 \end_layout
144
145 \begin_layout Standard
146
147 \series bold
148 SDCC
149 \series default
150  (
151 \emph on
152 S
153 \emph default
154 mall 
155 \emph on
156 D
157 \emph default
158 evice 
159 \emph on
160 C
161 \emph default
162  
163 \emph on
164 C
165 \emph default
166 ompiler) is a free open source, retargettable, optimizing ANSI-C compiler
167  by 
168 \series bold
169 Sandeep Dutta
170 \series default
171  designed for 8 bit Microprocessors.
172  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
173  8051, 8052
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
175
176 \end_inset
177
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179  Zilog Z80 based MCUs.
180  It can be retargeted for other microprocessors, support for Microchip PIC,
181  Atmel AVR is under development.
182  The entire source code for the compiler is distributed under GPL.
183  SDCC uses ASXXXX
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185
186 \end_inset
187
188  & ASLINK
189 \begin_inset LatexCommand \index{aslink}
190
191 \end_inset
192
193 , an open source retargetable assembler & linker.
194  SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
196  
197 \newline
198
199 \newline
200 In addition to the MCU specific optimizations SDCC also does a host of
201  standard optimizations like:
202 \end_layout
203
204 \begin_layout Itemize
205 global sub expression elimination, 
206 \end_layout
207
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
210  and loop reversing), 
211 \end_layout
212
213 \begin_layout Itemize
214 constant folding & propagation, 
215 \end_layout
216
217 \begin_layout Itemize
218 copy propagation, 
219 \end_layout
220
221 \begin_layout Itemize
222 dead code elimination 
223 \end_layout
224
225 \begin_layout Itemize
226 jump tables for 
227 \emph on
228 switch
229 \emph default
230  statements.
231 \end_layout
232
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235  be well suited for other 8 bit MCUs.
236  
237 \newline
238
239 \newline
240 The peep hole optimizer uses a rule based substitution mechanism which
241  is MCU independent.
242  
243 \newline
244
245 \newline
246 Supported data-types are:
247 \end_layout
248
249 \begin_layout Standard
250 \begin_inset Tabular
251 <lyxtabular version="3" rows="8" columns="5">
252 <features>
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \begin_layout Standard
263 type
264 \end_layout
265
266 \end_inset
267 </cell>
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
269 \begin_inset Text
270
271 \begin_layout Standard
272 width
273 \end_layout
274
275 \end_inset
276 </cell>
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \begin_layout Standard
281 default
282 \end_layout
283
284 \end_inset
285 </cell>
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
287 \begin_inset Text
288
289 \begin_layout Standard
290 signed range
291 \end_layout
292
293 \end_inset
294 </cell>
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
296 \begin_inset Text
297
298 \begin_layout Standard
299 unsigned range
300 \end_layout
301
302 \end_inset
303 </cell>
304 </row>
305 <row topline="true">
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
307 \begin_inset Text
308
309 \begin_layout Standard
310 bool
311 \end_layout
312
313 \end_inset
314 </cell>
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
316 \begin_inset Text
317
318 \begin_layout Standard
319 1 bit
320 \end_layout
321
322 \end_inset
323 </cell>
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 \begin_inset Text
326
327 \begin_layout Standard
328 unsigned
329 \end_layout
330
331 \end_inset
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
334 \begin_inset Text
335
336 \begin_layout Standard
337 -
338 \end_layout
339
340 \end_inset
341 </cell>
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 \begin_inset Text
344
345 \begin_layout Standard
346 0, 1
347 \end_layout
348
349 \end_inset
350 </cell>
351 </row>
352 <row topline="true">
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
354 \begin_inset Text
355
356 \begin_layout Standard
357 char
358 \end_layout
359
360 \end_inset
361 </cell>
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
363 \begin_inset Text
364
365 \begin_layout Standard
366 8 bits, 1 byte
367 \end_layout
368
369 \end_inset
370 </cell>
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 \begin_inset Text
373
374 \begin_layout Standard
375 signed
376 \end_layout
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \begin_layout Standard
384 -128, +127
385 \end_layout
386
387 \end_inset
388 </cell>
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
390 \begin_inset Text
391
392 \begin_layout Standard
393 0, +255
394 \end_layout
395
396 \end_inset
397 </cell>
398 </row>
399 <row topline="true">
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 \begin_inset Text
402
403 \begin_layout Standard
404 short
405 \end_layout
406
407 \end_inset
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \begin_layout Standard
413 16 bits, 2 bytes
414 \end_layout
415
416 \end_inset
417 </cell>
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 \begin_inset Text
420
421 \begin_layout Standard
422 signed
423 \end_layout
424
425 \end_inset
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \begin_layout Standard
431 -32.768, +32.767
432 \end_layout
433
434 \end_inset
435 </cell>
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
437 \begin_inset Text
438
439 \begin_layout Standard
440 0, +65.535
441 \end_layout
442
443 \end_inset
444 </cell>
445 </row>
446 <row topline="true">
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 \begin_inset Text
449
450 \begin_layout Standard
451 int
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 16 bits, 2 bytes
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 signed
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 -32.768, +32.767
479 \end_layout
480
481 \end_inset
482 </cell>
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
484 \begin_inset Text
485
486 \begin_layout Standard
487 0, +65.535
488 \end_layout
489
490 \end_inset
491 </cell>
492 </row>
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 \begin_inset Text
496
497 \begin_layout Standard
498 long
499 \end_layout
500
501 \end_inset
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \begin_layout Standard
507 32 bits, 4 bytes
508 \end_layout
509
510 \end_inset
511 </cell>
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
513 \begin_inset Text
514
515 \begin_layout Standard
516 signed
517 \end_layout
518
519 \end_inset
520 </cell>
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
522 \begin_inset Text
523
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
526 \end_layout
527
528 \end_inset
529 </cell>
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
531 \begin_inset Text
532
533 \begin_layout Standard
534 0, +4.294.967.295
535 \end_layout
536
537 \end_inset
538 </cell>
539 </row>
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \begin_layout Standard
545 float
546 \end_layout
547
548 \end_inset
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
551 \begin_inset Text
552
553 \begin_layout Standard
554 4 bytes IEEE 754
555 \end_layout
556
557 \end_inset
558 </cell>
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
560 \begin_inset Text
561
562 \begin_layout Standard
563 signed
564 \end_layout
565
566 \end_inset
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
569 \begin_inset Text
570
571 \begin_layout Standard
572
573 \end_layout
574
575 \end_inset
576 </cell>
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
578 \begin_inset Text
579
580 \begin_layout Standard
581 1.175494351E-38, 
582 \family roman
583 \series medium
584 \shape up
585 \size normal
586 \emph off
587 \bar no
588 \noun off
589 \color none
590 3.402823466E+38
591 \end_layout
592
593 \end_inset
594 </cell>
595 </row>
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
598 \begin_inset Text
599
600 \begin_layout Standard
601 pointer
602 \end_layout
603
604 \end_inset
605 </cell>
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
607 \begin_inset Text
608
609 \begin_layout Standard
610 1, 2, 3 or 4 bytes
611 \end_layout
612
613 \end_inset
614 </cell>
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
616 \begin_inset Text
617
618 \begin_layout Standard
619 generic
620 \end_layout
621
622 \end_inset
623 </cell>
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
625 \begin_inset Text
626
627 \begin_layout Standard
628
629 \end_layout
630
631 \end_inset
632 </cell>
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634 \begin_inset Text
635
636 \begin_layout Standard
637
638 \end_layout
639
640 \end_inset
641 </cell>
642 </row>
643 </lyxtabular>
644
645 \end_inset
646
647
648 \newline
649 The compiler also allows 
650 \emph on
651 inline assembler code
652 \emph default
653  to be embedded anywhere in a function.
654  In addition, routines developed in assembly can also be called.
655 \newline
656
657 \newline
658 SDCC also
659  provides an option (-
660 \begin_inset ERT
661 status collapsed
662
663 \begin_layout Standard
664
665
666 \backslash
667 /
668 \end_layout
669
670 \end_inset
671
672 -cyclomatic) to report the relative complexity of a function.
673  These functions can then be further optimized, or hand coded in assembly
674  if needed.
675  
676 \newline
677
678 \newline
679 SDCC also comes with a companion source level debugger SDCDB, the debugger
680  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
681 \newline
682
683 \newline
684
685 The latest version can be downloaded from 
686 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
687
688 \end_inset
689
690 .
691
692 \series bold
693  
694 \series default
695 \emph on
696 Please note: the compiler will probably always be some steps ahead of this
697  documentation
698 \series bold
699 \emph default
700
701 \begin_inset LatexCommand \index{Status of documentation}
702
703 \end_inset
704
705
706 \begin_inset Foot
707 status open
708
709 \begin_layout Standard
710 Obviously this has pros and cons
711 \end_layout
712
713 \end_inset
714
715 .
716 \end_layout
717
718 \begin_layout Section
719 Open Source
720 \end_layout
721
722 \begin_layout Standard
723 All packages used in this compiler system are 
724 \emph on
725 open source
726 \emph default
727  and 
728 \emph on
729 freeware
730 \emph default
731 ; source code for all the sub-packages (pre-processor, assemblers, linkers
732  etc) is distributed with the package.
733  This documentation is maintained using a freeware word processor (LyX).
734 \newline
735 This
736  program is free software; you can redistribute it and/or modify it under
737  the terms of the GNU General Public License
738 \begin_inset LatexCommand \index{GNU General Public License, GPL}
739
740 \end_inset
741
742  as published by the Free Software Foundation; either version 2, or (at
743  your option) any later version.
744  This program is distributed in the hope that it will be useful, but WITHOUT
745  ANY WARRANTY; without even the implied warranty
746 \begin_inset LatexCommand \index{warranty}
747
748 \end_inset
749
750  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
751  See the GNU General Public License for more details.
752  You should have received a copy of the GNU General Public License along
753  with this program; if not, write to the Free Software Foundation, 59 Temple
754  Place - Suite 330, Boston, MA 02111-1307, USA.
755  In other words, you are welcome to use, share and improve this program.
756  You are forbidden to forbid anyone else to use, share and improve what
757  you give them.
758  Help stamp out software-hoarding! 
759 \end_layout
760
761 \begin_layout Section
762 Typographic conventions
763 \begin_inset LatexCommand \index{Typographic conventions}
764
765 \end_inset
766
767
768 \end_layout
769
770 \begin_layout Standard
771 Throughout this manual, we will use the following convention.
772  Commands you have to type in are printed in 
773 \family sans
774 \series bold
775 "sans serif"
776 \series default
777 .
778
779 \family default
780  Code samples are printed in 
781 \family typewriter
782 typewriter font.
783
784 \family default
785  Interesting items and new terms are printed in 
786 \emph on
787 italic.
788 \end_layout
789
790 \begin_layout Section
791 Compatibility
792 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
793
794 \end_inset
795
796  with previous versions
797 \begin_inset LatexCommand \index{Compatibility with previous versions}
798
799 \end_inset
800
801
802 \end_layout
803
804 \begin_layout Standard
805 Newer versions have usually numerous bug fixes compared with the previous
806  version.
807  But we also sometimes introduce some incompatibilities with older versions.
808  Not just for the fun of it, but to make the compiler more stable, efficient
809  and ANSI compliant
810 \begin_inset LatexCommand \index{ANSI-compliance}
811
812 \end_inset
813
814  (see section 
815 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
816
817 \end_inset
818
819  for ANSI-Compliance).
820  
821 \begin_inset Note Note
822 status collapsed
823
824 \begin_layout Standard
825 It would be fine to add to each item, in which version was it changed.
826 \end_layout
827
828 \end_inset
829
830
831 \newline
832
833 \end_layout
834
835 \begin_layout Itemize
836 short is now equivalent to int (16 bits), it used to be equivalent to char
837  (8 bits) which is not ANSI compliant.
838  To maintain compatibility, old programs may be compiled using the --short-is-8b
839 its commandline option (see 
840 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
841
842 \end_inset
843
844 ).
845 \end_layout
846
847 \begin_layout Itemize
848 the default directory for gcc-builds where include, library and documentation
849  files are stored is now in /usr/local/share.
850 \end_layout
851
852 \begin_layout Itemize
853 char type parameters to vararg
854 \begin_inset LatexCommand \index{vararg, va\_arg}
855
856 \end_inset
857
858  functions are casted to int unless explicitly casted
859 \begin_inset Marginal
860 status collapsed
861
862 \begin_layout Standard
863
864 \series bold
865 \InsetSpace ~
866 !
867 \end_layout
868
869 \end_inset
870
871 , e.g.: 
872 \newline
873
874 \family typewriter
875 \InsetSpace ~
876 \InsetSpace ~
877 char a=3;
878 \newline
879 \InsetSpace ~
880 \InsetSpace ~
881 printf ("%d %c
882 \backslash
883 n", a, (char)a);
884 \family default
885
886 \newline
887  will push a as an int and as a char resp.
888 \end_layout
889
890 \begin_layout Itemize
891 option -
892 \begin_inset ERT
893 status collapsed
894
895 \begin_layout Standard
896
897
898 \backslash
899 /
900 \end_layout
901
902 \end_inset
903
904 -regextend has been removed.
905 \end_layout
906
907 \begin_layout Itemize
908 option -
909 \begin_inset ERT
910 status collapsed
911
912 \begin_layout Standard
913
914
915 \backslash
916 /
917 \end_layout
918
919 \end_inset
920
921 -noregparms has been removed.
922 \end_layout
923
924 \begin_layout Itemize
925 option -
926 \begin_inset ERT
927 status collapsed
928
929 \begin_layout Standard
930
931
932 \backslash
933 /
934 \end_layout
935
936 \end_inset
937
938 -stack-after-data has been removed.
939 \end_layout
940
941 \begin_layout Itemize
942 bit
943 \begin_inset LatexCommand \index{bit}
944
945 \end_inset
946
947  and sbit
948 \begin_inset LatexCommand \index{sbit}
949
950 \end_inset
951
952
953 \begin_inset LatexCommand \index{\_\_sbit}
954
955 \end_inset
956
957  types now consistently behave like the C99 _Bool type with respect to type
958  conversion
959 \begin_inset LatexCommand \index{type conversion}
960
961 \end_inset
962
963
964 \begin_inset LatexCommand \index{type promotion}
965
966 \end_inset
967
968 .
969  The most common incompatibility resulting from this change is related to
970  bit toggling
971 \begin_inset LatexCommand \index{Bit toggling}
972
973 \end_inset
974
975  idioms, e.g.:
976 \newline
977
978 \family typewriter
979 \InsetSpace ~
980 \InsetSpace ~
981 bit b;
982 \newline
983 \InsetSpace ~
984 \InsetSpace ~
985 b = ~
986 \begin_inset LatexCommand \index{\~\/ Operator}
987
988 \end_inset
989
990 b; /* equivalent to b=1 instead of toggling b */
991 \begin_inset Marginal
992 status collapsed
993
994 \begin_layout Standard
995
996 \series bold
997 \InsetSpace ~
998 !
999 \end_layout
1000
1001 \end_inset
1002
1003
1004 \newline
1005 \InsetSpace ~
1006 \InsetSpace ~
1007 b = !b; /* toggles b */
1008 \newline
1009
1010 \family default
1011 In previous versions, both forms would have toggled the bit.
1012 \end_layout
1013
1014 \begin_layout Standard
1015
1016 \emph on
1017 <pending: more incompatibilities?>
1018 \end_layout
1019
1020 \begin_layout Section
1021 System Requirements
1022 \end_layout
1023
1024 \begin_layout Standard
1025 What do you need before you start installation of SDCC? A computer, and
1026  a desire to compute.
1027  The preferred method of installation is to compile SDCC from source using
1028  GNU gcc and make.
1029  For Windows some pre-compiled binary distributions are available for your
1030  convenience.
1031  You should have some experience with command line tools and compiler use.
1032 \end_layout
1033
1034 \begin_layout Section
1035 Other Resources
1036 \end_layout
1037
1038 \begin_layout Standard
1039 The SDCC home page at 
1040 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1041
1042 \end_inset
1043
1044  is a great place to find distribution sets.
1045  You can also find links to the user mailing lists that offer help or discuss
1046  SDCC with other SDCC users.
1047  Web links to other SDCC related sites can also be found here.
1048  This document can be found in the DOC directory of the source package as
1049  a text or HTML file.
1050  A pdf version of this document is available at 
1051 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1052
1053 \end_inset
1054
1055 .
1056  Some of the other tools (simulator and assembler) included with SDCC contain
1057  their own documentation and can be found in the source distribution.
1058  If you want the latest unreleased software, the complete source package
1059  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1060 sdcc/trunk/sdcc.
1061 \end_layout
1062
1063 \begin_layout Section
1064 Wishes for the future
1065 \end_layout
1066
1067 \begin_layout Standard
1068 There are (and always will be) some things that could be done.
1069  Here are some I can think of:
1070 \newline
1071
1072 \end_layout
1073
1074 \begin_layout Standard
1075
1076 \family typewriter
1077 char KernelFunction3(char p) at 0x340;
1078 \newline
1079
1080 \end_layout
1081
1082 \begin_layout Standard
1083
1084 \family typewriter
1085 better code banking
1086 \begin_inset LatexCommand \index{code banking (limited support)}
1087
1088 \end_inset
1089
1090  support for mcs51
1091 \newline
1092
1093 \newline
1094
1095 \family default
1096 If you can think of some more, please see the section 
1097 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1098
1099 \end_inset
1100
1101  about filing feature requests
1102 \begin_inset LatexCommand \index{Requesting features}
1103
1104 \end_inset
1105
1106
1107 \begin_inset LatexCommand \index{Feature request}
1108
1109 \end_inset
1110
1111 .
1112 \newline
1113
1114 \end_layout
1115
1116 \begin_layout Chapter
1117 Installing SDCC
1118 \begin_inset LatexCommand \index{Installation}
1119
1120 \end_inset
1121
1122
1123 \end_layout
1124
1125 \begin_layout Standard
1126 For most users it is sufficient to skip to either section 
1127 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1128
1129 \end_inset
1130
1131  (Unix) or section 
1132 \begin_inset LatexCommand \ref{sub:Windows-Install}
1133
1134 \end_inset
1135
1136  (Windows).
1137  More detailed instructions follow below.
1138 \end_layout
1139
1140 \begin_layout Section
1141 Configure Options
1142 \begin_inset LatexCommand \index{Options SDCC configuration}
1143
1144 \end_inset
1145
1146
1147 \end_layout
1148
1149 \begin_layout Standard
1150 The install paths, search paths and other options are defined when running
1151  'configure'.
1152  The defaults can be overridden by:
1153 \end_layout
1154
1155 \begin_layout List
1156 \labelwidthstring 00.00.0000
1157 -
1158 \begin_inset ERT
1159 status collapsed
1160
1161 \begin_layout Standard
1162
1163
1164 \backslash
1165 /
1166 \end_layout
1167
1168 \end_inset
1169
1170 -prefix see table below
1171 \end_layout
1172
1173 \begin_layout List
1174 \labelwidthstring 00.00.0000
1175 -
1176 \begin_inset ERT
1177 status collapsed
1178
1179 \begin_layout Standard
1180
1181
1182 \backslash
1183 /
1184 \end_layout
1185
1186 \end_inset
1187
1188 -exec_prefix see table below
1189 \end_layout
1190
1191 \begin_layout List
1192 \labelwidthstring 00.00.0000
1193 -
1194 \begin_inset ERT
1195 status collapsed
1196
1197 \begin_layout Standard
1198
1199
1200 \backslash
1201 /
1202 \end_layout
1203
1204 \end_inset
1205
1206 -bindir see table below
1207 \end_layout
1208
1209 \begin_layout List
1210 \labelwidthstring 00.00.0000
1211 -
1212 \begin_inset ERT
1213 status collapsed
1214
1215 \begin_layout Standard
1216
1217
1218 \backslash
1219 /
1220 \end_layout
1221
1222 \end_inset
1223
1224 -datadir see table below
1225 \end_layout
1226
1227 \begin_layout List
1228 \labelwidthstring 00.00.0000
1229 -
1230 \begin_inset ERT
1231 status collapsed
1232
1233 \begin_layout Standard
1234
1235
1236 \backslash
1237 /
1238 \end_layout
1239
1240 \end_inset
1241
1242 -datarootdir see table below
1243 \newline
1244
1245 \end_layout
1246
1247 \begin_layout List
1248 \labelwidthstring 00.00.0000
1249 \InsetSpace ~
1250 \InsetSpace ~
1251 docdir environment variable, see table below
1252 \end_layout
1253
1254 \begin_layout List
1255 \labelwidthstring 00.00.0000
1256 \InsetSpace ~
1257 \InsetSpace ~
1258 include_dir_suffix environment variable, see table below
1259 \end_layout
1260
1261 \begin_layout List
1262 \labelwidthstring 00.00.0000
1263 \InsetSpace ~
1264 \InsetSpace ~
1265 lib_dir_suffix environment variable, see table below
1266 \end_layout
1267
1268 \begin_layout List
1269 \labelwidthstring 00.00.0000
1270 \InsetSpace ~
1271 \InsetSpace ~
1272 sdccconf_h_dir_separator environment variable, either / or 
1273 \backslash
1274
1275 \backslash
1276  makes sense here.
1277  This character will only be used in sdccconf.h; don't forget it's a C-header,
1278  therefore a double-backslash is needed there.
1279 \newline
1280
1281 \end_layout
1282
1283 \begin_layout List
1284 \labelwidthstring 00.00.0000
1285 -
1286 \begin_inset ERT
1287 status collapsed
1288
1289 \begin_layout Standard
1290
1291
1292 \backslash
1293 /
1294 \end_layout
1295
1296 \end_inset
1297
1298 -disable-mcs51-port Excludes the Intel mcs51 port
1299 \end_layout
1300
1301 \begin_layout List
1302 \labelwidthstring 00.00.0000
1303 -
1304 \begin_inset ERT
1305 status collapsed
1306
1307 \begin_layout Standard
1308
1309
1310 \backslash
1311 /
1312 \end_layout
1313
1314 \end_inset
1315
1316 -disable-gbz80-port Excludes the Gameboy gbz80 port
1317 \end_layout
1318
1319 \begin_layout List
1320 \labelwidthstring 00.00.0000
1321 -
1322 \begin_inset ERT
1323 status collapsed
1324
1325 \begin_layout Standard
1326
1327
1328 \backslash
1329 /
1330 \end_layout
1331
1332 \end_inset
1333
1334 -disable-z80-port Excludes the z80 port
1335 \end_layout
1336
1337 \begin_layout List
1338 \labelwidthstring 00.00.0000
1339 -
1340 \begin_inset ERT
1341 status collapsed
1342
1343 \begin_layout Standard
1344
1345
1346 \backslash
1347 /
1348 \end_layout
1349
1350 \end_inset
1351
1352 -disable-avr-port Excludes the AVR port
1353 \end_layout
1354
1355 \begin_layout List
1356 \labelwidthstring 00.00.0000
1357 -
1358 \begin_inset ERT
1359 status collapsed
1360
1361 \begin_layout Standard
1362
1363
1364 \backslash
1365 /
1366 \end_layout
1367
1368 \end_inset
1369
1370 -disable-ds390-port Excludes the DS390 port
1371 \end_layout
1372
1373 \begin_layout List
1374 \labelwidthstring 00.00.0000
1375 -
1376 \begin_inset ERT
1377 status collapsed
1378
1379 \begin_layout Standard
1380
1381
1382 \backslash
1383 /
1384 \end_layout
1385
1386 \end_inset
1387
1388 -disable-hc08-port Excludes the HC08 port
1389 \end_layout
1390
1391 \begin_layout List
1392 \labelwidthstring 00.00.0000
1393 -
1394 \begin_inset ERT
1395 status collapsed
1396
1397 \begin_layout Standard
1398
1399
1400 \backslash
1401 /
1402 \end_layout
1403
1404 \end_inset
1405
1406 -disable-pic-port Excludes the PIC port
1407 \end_layout
1408
1409 \begin_layout List
1410 \labelwidthstring 00.00.0000
1411 -
1412 \begin_inset ERT
1413 status collapsed
1414
1415 \begin_layout Standard
1416
1417
1418 \backslash
1419 /
1420 \end_layout
1421
1422 \end_inset
1423
1424 -disable-xa51-port Excludes the XA51 port
1425 \end_layout
1426
1427 \begin_layout List
1428 \labelwidthstring 00.00.0000
1429 -
1430 \begin_inset ERT
1431 status collapsed
1432
1433 \begin_layout Standard
1434
1435
1436 \backslash
1437 /
1438 \end_layout
1439
1440 \end_inset
1441
1442 -disable-ucsim Disables configuring and building of ucsim
1443 \end_layout
1444
1445 \begin_layout List
1446 \labelwidthstring 00.00.0000
1447 -
1448 \begin_inset ERT
1449 status collapsed
1450
1451 \begin_layout Standard
1452
1453
1454 \backslash
1455 /
1456 \end_layout
1457
1458 \end_inset
1459
1460 -disable-device-lib Disables automatically building device libraries
1461 \end_layout
1462
1463 \begin_layout List
1464 \labelwidthstring 00.00.0000
1465 -
1466 \begin_inset ERT
1467 status collapsed
1468
1469 \begin_layout Standard
1470
1471
1472 \backslash
1473 /
1474 \end_layout
1475
1476 \end_inset
1477
1478 -disable-packihx Disables building packihx
1479 \newline
1480
1481 \end_layout
1482
1483 \begin_layout List
1484 \labelwidthstring 00.00.0000
1485 -
1486 \begin_inset ERT
1487 status collapsed
1488
1489 \begin_layout Standard
1490
1491
1492 \backslash
1493 /
1494 \end_layout
1495
1496 \end_inset
1497
1498 -enable-doc Build pdf, html and txt files from the lyx sources
1499 \end_layout
1500
1501 \begin_layout List
1502 \labelwidthstring 00.00.0000
1503 -
1504 \begin_inset ERT
1505 status collapsed
1506
1507 \begin_layout Standard
1508
1509
1510 \backslash
1511 /
1512 \end_layout
1513
1514 \end_inset
1515
1516 -enable-libgc Use the Bohem memory allocator.
1517  Lower runtime footprint.
1518 \end_layout
1519
1520 \begin_layout Standard
1521 Furthermore the environment variables CC, CFLAGS, ...
1522  the tools and their arguments can be influenced.
1523  Please see `configure -
1524 \begin_inset ERT
1525 status collapsed
1526
1527 \begin_layout Standard
1528
1529
1530 \backslash
1531 /
1532 \end_layout
1533
1534 \end_inset
1535
1536 -help` and the man/info pages of `configure` for details.
1537 \newline
1538
1539 \newline
1540 The names of the
1541  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1542 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1543  SDCC_LIB_NAME are defined by `configure` too.
1544  At the moment it's not possible to change the default settings (it was
1545  simply never required).
1546 \newline
1547
1548 \newline
1549 These configure options are compiled into the binaries,
1550  and can only be changed by rerunning 'configure' and recompiling SDCC.
1551  The configure options are written in 
1552 \emph on
1553 italics
1554 \emph default
1555  to distinguish them from run time environment variables (see section search
1556  paths).
1557 \newline
1558
1559 \newline
1560 The settings for 
1561 \begin_inset Quotes sld
1562 \end_inset
1563
1564 Win32 builds
1565 \begin_inset Quotes srd
1566 \end_inset
1567
1568  are used by the SDCC team to build the official Win32 binaries.
1569  The SDCC team uses Mingw32 to build the official Windows binaries, because
1570  it's
1571 \end_layout
1572
1573 \begin_layout Enumerate
1574 open source, 
1575 \end_layout
1576
1577 \begin_layout Enumerate
1578 a gcc compiler and last but not least
1579 \end_layout
1580
1581 \begin_layout Enumerate
1582 the binaries can be built by cross compiling on SDCC Distributed Compile
1583  Farm.
1584 \end_layout
1585
1586 \begin_layout Standard
1587 See the examples, how to pass the Win32 settings to 'configure'.
1588  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1589  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1590  for Win32.
1591 \newline
1592
1593 \newline
1594 These defaults are:
1595 \newline
1596
1597 \end_layout
1598
1599 \begin_layout Standard
1600 \align center
1601 \begin_inset Tabular
1602 <lyxtabular version="3" rows="9" columns="3">
1603 <features>
1604 <column alignment="block" valignment="top" leftline="true" width="0in">
1605 <column alignment="block" valignment="top" leftline="true" width="0in">
1606 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1607 <row topline="true" bottomline="true">
1608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1609 \begin_inset Text
1610
1611 \begin_layout Standard
1612 Variable
1613 \end_layout
1614
1615 \end_inset
1616 </cell>
1617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1618 \begin_inset Text
1619
1620 \begin_layout Standard
1621 default
1622 \end_layout
1623
1624 \end_inset
1625 </cell>
1626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1627 \begin_inset Text
1628
1629 \begin_layout Standard
1630 Win32 builds
1631 \end_layout
1632
1633 \end_inset
1634 </cell>
1635 </row>
1636 <row topline="true">
1637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1638 \begin_inset Text
1639
1640 \begin_layout Standard
1641
1642 \emph on
1643 PREFIX
1644 \end_layout
1645
1646 \end_inset
1647 </cell>
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1649 \begin_inset Text
1650
1651 \begin_layout Standard
1652 /usr/local
1653 \end_layout
1654
1655 \end_inset
1656 </cell>
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1658 \begin_inset Text
1659
1660 \begin_layout Standard
1661
1662 \backslash
1663 sdcc
1664 \end_layout
1665
1666 \end_inset
1667 </cell>
1668 </row>
1669 <row topline="true">
1670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1671 \begin_inset Text
1672
1673 \begin_layout Standard
1674
1675 \emph on
1676 EXEC_PREFIX
1677 \end_layout
1678
1679 \end_inset
1680 </cell>
1681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1682 \begin_inset Text
1683
1684 \begin_layout Standard
1685
1686 \emph on
1687 $PREFIX
1688 \end_layout
1689
1690 \end_inset
1691 </cell>
1692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1693 \begin_inset Text
1694
1695 \begin_layout Standard
1696
1697 \emph on
1698 $PREFIX
1699 \end_layout
1700
1701 \end_inset
1702 </cell>
1703 </row>
1704 <row topline="true">
1705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1706 \begin_inset Text
1707
1708 \begin_layout Standard
1709
1710 \emph on
1711 BINDIR
1712 \end_layout
1713
1714 \end_inset
1715 </cell>
1716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1717 \begin_inset Text
1718
1719 \begin_layout Standard
1720
1721 \emph on
1722 $EXEC_PREFIX
1723 \emph default
1724 /bin
1725 \end_layout
1726
1727 \end_inset
1728 </cell>
1729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1730 \begin_inset Text
1731
1732 \begin_layout Standard
1733
1734 \emph on
1735 $EXEC_PREFIX
1736 \emph default
1737
1738 \backslash
1739 bin
1740 \end_layout
1741
1742 \end_inset
1743 </cell>
1744 </row>
1745 <row topline="true">
1746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1747 \begin_inset Text
1748
1749 \begin_layout Standard
1750
1751 \emph on
1752 DATADIR
1753 \end_layout
1754
1755 \end_inset
1756 </cell>
1757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1758 \begin_inset Text
1759
1760 \begin_layout Standard
1761
1762 \emph on
1763 $DATAROOTDIR
1764 \end_layout
1765
1766 \end_inset
1767 </cell>
1768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1769 \begin_inset Text
1770
1771 \begin_layout Standard
1772
1773 \emph on
1774 $DATAROOTDIR
1775 \end_layout
1776
1777 \end_inset
1778 </cell>
1779 </row>
1780 <row topline="true">
1781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1782 \begin_inset Text
1783
1784 \begin_layout Standard
1785
1786 \emph on
1787 DATAROOTDIR
1788 \end_layout
1789
1790 \end_inset
1791 </cell>
1792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1793 \begin_inset Text
1794
1795 \begin_layout Standard
1796
1797 \emph on
1798 $PREFIX
1799 \emph default
1800 /share
1801 \end_layout
1802
1803 \end_inset
1804 </cell>
1805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1806 \begin_inset Text
1807
1808 \begin_layout Standard
1809
1810 \emph on
1811 $PREFIX
1812 \end_layout
1813
1814 \end_inset
1815 </cell>
1816 </row>
1817 <row topline="true">
1818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1819 \begin_inset Text
1820
1821 \begin_layout Standard
1822
1823 \emph on
1824 DOCDIR
1825 \end_layout
1826
1827 \end_inset
1828 </cell>
1829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1830 \begin_inset Text
1831
1832 \begin_layout Standard
1833
1834 \emph on
1835 $DATAROOTDIR
1836 \emph default
1837 /sdcc/doc
1838 \end_layout
1839
1840 \end_inset
1841 </cell>
1842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1843 \begin_inset Text
1844
1845 \begin_layout Standard
1846
1847 \emph on
1848 $DATAROOTDIR
1849 \emph default
1850
1851 \backslash
1852 doc
1853 \end_layout
1854
1855 \end_inset
1856 </cell>
1857 </row>
1858 <row topline="true">
1859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1860 \begin_inset Text
1861
1862 \begin_layout Standard
1863
1864 \emph on
1865 INCLUDE_DIR_SUFFIX
1866 \end_layout
1867
1868 \end_inset
1869 </cell>
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1871 \begin_inset Text
1872
1873 \begin_layout Standard
1874 sdcc/include
1875 \end_layout
1876
1877 \end_inset
1878 </cell>
1879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1880 \begin_inset Text
1881
1882 \begin_layout Standard
1883 include
1884 \end_layout
1885
1886 \end_inset
1887 </cell>
1888 </row>
1889 <row topline="true" bottomline="true">
1890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1891 \begin_inset Text
1892
1893 \begin_layout Standard
1894
1895 \emph on
1896 LIB_DIR_SUFFIX
1897 \end_layout
1898
1899 \end_inset
1900 </cell>
1901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1902 \begin_inset Text
1903
1904 \begin_layout Standard
1905 sdcc/lib
1906 \end_layout
1907
1908 \end_inset
1909 </cell>
1910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1911 \begin_inset Text
1912
1913 \begin_layout Standard
1914 lib
1915 \end_layout
1916
1917 \end_inset
1918 </cell>
1919 </row>
1920 </lyxtabular>
1921
1922 \end_inset
1923
1924
1925 \newline
1926
1927 \end_layout
1928
1929 \begin_layout Standard
1930 \noindent
1931 'configure' also computes relative paths.
1932  This is needed for full relocatability of a binary package and to complete
1933  search paths (see section search paths below):
1934 \newline
1935  
1936 \end_layout
1937
1938 \begin_layout Standard
1939 \align center
1940 \begin_inset Tabular
1941 <lyxtabular version="3" rows="4" columns="3">
1942 <features>
1943 <column alignment="block" valignment="top" leftline="true" width="0in">
1944 <column alignment="block" valignment="top" leftline="true" width="0in">
1945 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1946 <row topline="true" bottomline="true">
1947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1948 \begin_inset Text
1949
1950 \begin_layout Standard
1951 Variable (computed)
1952 \end_layout
1953
1954 \end_inset
1955 </cell>
1956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1957 \begin_inset Text
1958
1959 \begin_layout Standard
1960 default
1961 \end_layout
1962
1963 \end_inset
1964 </cell>
1965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1966 \begin_inset Text
1967
1968 \begin_layout Standard
1969 Win32 builds
1970 \end_layout
1971
1972 \end_inset
1973 </cell>
1974 </row>
1975 <row topline="true" bottomline="true">
1976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1977 \begin_inset Text
1978
1979 \begin_layout Standard
1980
1981 \emph on
1982 BIN2DATA_DIR
1983 \end_layout
1984
1985 \end_inset
1986 </cell>
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1988 \begin_inset Text
1989
1990 \begin_layout Standard
1991 ../share
1992 \end_layout
1993
1994 \end_inset
1995 </cell>
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1997 \begin_inset Text
1998
1999 \begin_layout Standard
2000 ..
2001 \end_layout
2002
2003 \end_inset
2004 </cell>
2005 </row>
2006 <row bottomline="true">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2008 \begin_inset Text
2009
2010 \begin_layout Standard
2011
2012 \emph on
2013 PREFIX2BIN_DIR
2014 \end_layout
2015
2016 \end_inset
2017 </cell>
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2019 \begin_inset Text
2020
2021 \begin_layout Standard
2022 bin
2023 \end_layout
2024
2025 \end_inset
2026 </cell>
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2028 \begin_inset Text
2029
2030 \begin_layout Standard
2031 bin
2032 \end_layout
2033
2034 \end_inset
2035 </cell>
2036 </row>
2037 <row bottomline="true">
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2039 \begin_inset Text
2040
2041 \begin_layout Standard
2042
2043 \emph on
2044 PREFIX2DATA_DIR
2045 \end_layout
2046
2047 \end_inset
2048 </cell>
2049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2050 \begin_inset Text
2051
2052 \begin_layout Standard
2053 share/sdcc
2054 \end_layout
2055
2056 \end_inset
2057 </cell>
2058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2059 \begin_inset Text
2060
2061 \begin_layout Standard
2062
2063 \end_layout
2064
2065 \end_inset
2066 </cell>
2067 </row>
2068 </lyxtabular>
2069
2070 \end_inset
2071
2072
2073 \newline
2074
2075 \end_layout
2076
2077 \begin_layout Standard
2078 \noindent
2079 Examples:
2080 \end_layout
2081
2082 \begin_layout LyX-Code
2083 ./configure
2084 \newline
2085 ./configure -
2086 \begin_inset ERT
2087 status collapsed
2088
2089 \begin_layout Standard
2090
2091
2092 \backslash
2093 /
2094 \end_layout
2095
2096 \end_inset
2097
2098 -prefix=
2099 \begin_inset Quotes srd
2100 \end_inset
2101
2102 /usr/bin
2103 \begin_inset Quotes srd
2104 \end_inset
2105
2106  -
2107 \begin_inset ERT
2108 status collapsed
2109
2110 \begin_layout Standard
2111
2112
2113 \backslash
2114 /
2115 \end_layout
2116
2117 \end_inset
2118
2119 -datarootdir=
2120 \begin_inset Quotes srd
2121 \end_inset
2122
2123 /usr/share
2124 \begin_inset Quotes srd
2125 \end_inset
2126
2127
2128 \newline
2129 ./configure -
2130 \begin_inset ERT
2131 status collapsed
2132
2133 \begin_layout Standard
2134
2135
2136 \backslash
2137 /
2138 \end_layout
2139
2140 \end_inset
2141
2142 -disable-avr-port -
2143 \begin_inset ERT
2144 status collapsed
2145
2146 \begin_layout Standard
2147
2148
2149 \backslash
2150 /
2151 \end_layout
2152
2153 \end_inset
2154
2155 -disable-xa51-port
2156 \end_layout
2157
2158 \begin_layout Standard
2159 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2160 32'):
2161 \end_layout
2162
2163 \begin_layout LyX-Code
2164 ./configure 
2165 \backslash
2166
2167 \newline
2168 CC=
2169 \begin_inset Quotes srd
2170 \end_inset
2171
2172 i586-mingw32msvc-gcc
2173 \begin_inset Quotes srd
2174 \end_inset
2175
2176  CXX=
2177 \begin_inset Quotes srd
2178 \end_inset
2179
2180 i586-mingw32msvc-g++
2181 \begin_inset Quotes srd
2182 \end_inset
2183
2184  
2185 \backslash
2186  
2187 \newline
2188 RANLIB=
2189 \begin_inset Quotes srd
2190 \end_inset
2191
2192 i586-mingw32msvc-ranlib
2193 \begin_inset Quotes srd
2194 \end_inset
2195
2196  
2197 \backslash
2198
2199 \newline
2200 STRIP=
2201 \begin_inset Quotes srd
2202 \end_inset
2203
2204 i586-mingw32msvc-strip
2205 \begin_inset Quotes srd
2206 \end_inset
2207
2208  
2209 \backslash
2210
2211 \newline
2212 -
2213 \begin_inset ERT
2214 status collapsed
2215
2216 \begin_layout Standard
2217
2218
2219 \backslash
2220 /
2221 \end_layout
2222
2223 \end_inset
2224
2225 -prefix=
2226 \begin_inset Quotes srd
2227 \end_inset
2228
2229 /sdcc
2230 \begin_inset Quotes srd
2231 \end_inset
2232
2233  
2234 \backslash
2235
2236 \newline
2237 -
2238 \begin_inset ERT
2239 status collapsed
2240
2241 \begin_layout Standard
2242
2243
2244 \backslash
2245 /
2246 \end_layout
2247
2248 \end_inset
2249
2250 -datarootdir=
2251 \begin_inset Quotes srd
2252 \end_inset
2253
2254 /sdcc
2255 \begin_inset Quotes srd
2256 \end_inset
2257
2258  
2259 \backslash
2260
2261 \newline
2262 docdir=
2263 \begin_inset Quotes srd
2264 \end_inset
2265
2266
2267 \backslash
2268 ${datarootdir}/doc
2269 \begin_inset Quotes srd
2270 \end_inset
2271
2272  
2273 \backslash
2274
2275 \newline
2276 include_dir_suffix=
2277 \begin_inset Quotes srd
2278 \end_inset
2279
2280 include
2281 \begin_inset Quotes srd
2282 \end_inset
2283
2284  
2285 \backslash
2286
2287 \newline
2288 lib_dir_suffix=
2289 \begin_inset Quotes srd
2290 \end_inset
2291
2292 lib
2293 \begin_inset Quotes srd
2294 \end_inset
2295
2296  
2297 \backslash
2298
2299 \newline
2300 sdccconf_h_dir_separator=
2301 \begin_inset Quotes srd
2302 \end_inset
2303
2304
2305 \backslash
2306
2307 \backslash
2308
2309 \backslash
2310
2311 \backslash
2312
2313 \begin_inset Quotes srd
2314 \end_inset
2315
2316  
2317 \backslash
2318
2319 \newline
2320 -
2321 \begin_inset ERT
2322 status collapsed
2323
2324 \begin_layout Standard
2325
2326
2327 \backslash
2328 /
2329 \end_layout
2330
2331 \end_inset
2332
2333 -disable-device-lib
2334 \backslash
2335
2336 \newline
2337 -
2338 \begin_inset ERT
2339 status collapsed
2340
2341 \begin_layout Standard
2342
2343
2344 \backslash
2345 /
2346 \end_layout
2347
2348 \end_inset
2349
2350 -host=i586-mingw32msvc
2351 \backslash
2352
2353 \newline
2354 -
2355 \begin_inset ERT
2356 status collapsed
2357
2358 \begin_layout Standard
2359
2360
2361 \backslash
2362 /
2363 \end_layout
2364
2365 \end_inset
2366
2367 -build=unknown-unknown-linux-gnu
2368 \end_layout
2369
2370 \begin_layout Standard
2371 To 
2372 \begin_inset Quotes sld
2373 \end_inset
2374
2375 cross
2376 \begin_inset Quotes srd
2377 \end_inset
2378
2379 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2380 ):
2381 \end_layout
2382
2383 \begin_layout LyX-Code
2384 ./configure -C 
2385 \backslash
2386
2387 \newline
2388 -
2389 \begin_inset ERT
2390 status collapsed
2391
2392 \begin_layout Standard
2393
2394
2395 \backslash
2396 /
2397 \end_layout
2398
2399 \end_inset
2400
2401 -prefix=
2402 \begin_inset Quotes srd
2403 \end_inset
2404
2405 /sdcc
2406 \begin_inset Quotes srd
2407 \end_inset
2408
2409  
2410 \backslash
2411
2412 \newline
2413 -
2414 \begin_inset ERT
2415 status collapsed
2416
2417 \begin_layout Standard
2418
2419
2420 \backslash
2421 /
2422 \end_layout
2423
2424 \end_inset
2425
2426 -datarootdir=
2427 \begin_inset Quotes srd
2428 \end_inset
2429
2430 /sdcc
2431 \begin_inset Quotes srd
2432 \end_inset
2433
2434  
2435 \backslash
2436
2437 \newline
2438 docdir=
2439 \begin_inset Quotes srd
2440 \end_inset
2441
2442
2443 \backslash
2444 ${datarootdir}/doc
2445 \begin_inset Quotes srd
2446 \end_inset
2447
2448  
2449 \backslash
2450  
2451 \newline
2452 include_dir_suffix=
2453 \begin_inset Quotes srd
2454 \end_inset
2455
2456 include
2457 \begin_inset Quotes srd
2458 \end_inset
2459
2460  
2461 \backslash
2462
2463 \newline
2464 lib_dir_suffix=
2465 \begin_inset Quotes srd
2466 \end_inset
2467
2468 lib
2469 \begin_inset Quotes srd
2470 \end_inset
2471
2472  
2473 \backslash
2474
2475 \newline
2476 sdccconf_h_dir_separator=
2477 \begin_inset Quotes srd
2478 \end_inset
2479
2480
2481 \backslash
2482
2483 \backslash
2484
2485 \backslash
2486
2487 \backslash
2488
2489 \begin_inset Quotes srd
2490 \end_inset
2491
2492  
2493 \backslash
2494
2495 \newline
2496 CC=
2497 \begin_inset Quotes srd
2498 \end_inset
2499
2500 gcc -mno-cygwin
2501 \begin_inset Quotes srd
2502 \end_inset
2503
2504  
2505 \backslash
2506
2507 \newline
2508 CXX=
2509 \begin_inset Quotes srd
2510 \end_inset
2511
2512 g++ -mno-cygwin
2513 \begin_inset Quotes srd
2514 \end_inset
2515
2516  
2517 \end_layout
2518
2519 \begin_layout Standard
2520 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2521  The option '-
2522 \begin_inset ERT
2523 status collapsed
2524
2525 \begin_layout Standard
2526
2527
2528 \backslash
2529 /
2530 \end_layout
2531
2532 \end_inset
2533
2534 -C' turns on caching, which gives a little bit extra speed.
2535  However if options are changed, it can be necessary to delete the config.cache
2536  file.
2537 \end_layout
2538
2539 \begin_layout Section
2540 Install paths
2541 \begin_inset LatexCommand \label{sub:Install-paths}
2542
2543 \end_inset
2544
2545
2546 \begin_inset LatexCommand \index{Install paths}
2547
2548 \end_inset
2549
2550
2551 \end_layout
2552
2553 \begin_layout Standard
2554 \begin_inset VSpace medskip
2555 \end_inset
2556
2557
2558 \end_layout
2559
2560 \begin_layout Standard
2561 \align center
2562 \begin_inset Tabular
2563 <lyxtabular version="3" rows="5" columns="4">
2564 <features>
2565 <column alignment="left" valignment="top" leftline="true" width="0">
2566 <column alignment="left" valignment="top" leftline="true" width="0">
2567 <column alignment="left" valignment="top" leftline="true" width="0">
2568 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2569 <row topline="true" bottomline="true">
2570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2571 \begin_inset Text
2572
2573 \begin_layout Standard
2574
2575 \series bold
2576 Description
2577 \end_layout
2578
2579 \end_inset
2580 </cell>
2581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2582 \begin_inset Text
2583
2584 \begin_layout Standard
2585
2586 \series bold
2587 Path
2588 \end_layout
2589
2590 \end_inset
2591 </cell>
2592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2593 \begin_inset Text
2594
2595 \begin_layout Standard
2596
2597 \series bold
2598 Default
2599 \end_layout
2600
2601 \end_inset
2602 </cell>
2603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2604 \begin_inset Text
2605
2606 \begin_layout Standard
2607
2608 \series bold
2609 Win32 builds
2610 \end_layout
2611
2612 \end_inset
2613 </cell>
2614 </row>
2615 <row topline="true">
2616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2617 \begin_inset Text
2618
2619 \begin_layout Standard
2620 Binary files*
2621 \end_layout
2622
2623 \end_inset
2624 </cell>
2625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2626 \begin_inset Text
2627
2628 \begin_layout Standard
2629
2630 \emph on
2631 $EXEC_PREFIX
2632 \end_layout
2633
2634 \end_inset
2635 </cell>
2636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2637 \begin_inset Text
2638
2639 \begin_layout Standard
2640 /usr/local/bin
2641 \end_layout
2642
2643 \end_inset
2644 </cell>
2645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2646 \begin_inset Text
2647
2648 \begin_layout Standard
2649
2650 \backslash
2651 sdcc
2652 \backslash
2653 bin
2654 \end_layout
2655
2656 \end_inset
2657 </cell>
2658 </row>
2659 <row topline="true">
2660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2661 \begin_inset Text
2662
2663 \begin_layout Standard
2664 Include files
2665 \end_layout
2666
2667 \end_inset
2668 </cell>
2669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2670 \begin_inset Text
2671
2672 \begin_layout Standard
2673
2674 \emph on
2675 $DATADIR/ $INCLUDE_DIR_SUFFIX
2676 \end_layout
2677
2678 \end_inset
2679 </cell>
2680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2681 \begin_inset Text
2682
2683 \begin_layout Standard
2684 /usr/local/share/sdcc/include
2685 \end_layout
2686
2687 \end_inset
2688 </cell>
2689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2690 \begin_inset Text
2691
2692 \begin_layout Standard
2693
2694 \backslash
2695 sdcc
2696 \backslash
2697 include
2698 \end_layout
2699
2700 \end_inset
2701 </cell>
2702 </row>
2703 <row topline="true">
2704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2705 \begin_inset Text
2706
2707 \begin_layout Standard
2708 Library file**
2709 \end_layout
2710
2711 \end_inset
2712 </cell>
2713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2714 \begin_inset Text
2715
2716 \begin_layout Standard
2717
2718 \emph on
2719 $DATADIR/$LIB_DIR_SUFFIX
2720 \end_layout
2721
2722 \end_inset
2723 </cell>
2724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2725 \begin_inset Text
2726
2727 \begin_layout Standard
2728 /usr/local/share/sdcc/lib
2729 \end_layout
2730
2731 \end_inset
2732 </cell>
2733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2734 \begin_inset Text
2735
2736 \begin_layout Standard
2737
2738 \backslash
2739 sdcc
2740 \backslash
2741 lib
2742 \end_layout
2743
2744 \end_inset
2745 </cell>
2746 </row>
2747 <row topline="true" bottomline="true">
2748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2749 \begin_inset Text
2750
2751 \begin_layout Standard
2752 Documentation
2753 \end_layout
2754
2755 \end_inset
2756 </cell>
2757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_inset Text
2759
2760 \begin_layout Standard
2761
2762 \emph on
2763 $DOCDIR
2764 \end_layout
2765
2766 \end_inset
2767 </cell>
2768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2769 \begin_inset Text
2770
2771 \begin_layout Standard
2772 /usr/local/share/sdcc/doc
2773 \end_layout
2774
2775 \end_inset
2776 </cell>
2777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2778 \begin_inset Text
2779
2780 \begin_layout Standard
2781
2782 \backslash
2783 sdcc
2784 \backslash
2785 doc
2786 \end_layout
2787
2788 \end_inset
2789 </cell>
2790 </row>
2791 </lyxtabular>
2792
2793 \end_inset
2794
2795
2796 \end_layout
2797
2798 \begin_layout Verse
2799
2800 \size footnotesize
2801 *compiler, preprocessor, assembler, and linker
2802 \newline
2803 **the 
2804 \shape italic
2805 model
2806 \shape default
2807  is auto-appended by the compiler, e.g.
2808  small, large, z80, ds390 etc
2809 \end_layout
2810
2811 \begin_layout Standard
2812 \noindent
2813 The install paths can still be changed during `make install` with e.g.:
2814 \end_layout
2815
2816 \begin_layout LyX-Code
2817 make install prefix=$(HOME)/local/sdcc
2818 \end_layout
2819
2820 \begin_layout Standard
2821 Of course this doesn't change the search paths compiled into the binaries.
2822 \newline
2823
2824 \newline
2825 Moreove
2826 r the install path can be changed by defining DESTDIR
2827 \begin_inset LatexCommand \index{DESTDIR}
2828
2829 \end_inset
2830
2831 :
2832 \end_layout
2833
2834 \begin_layout LyX-Code
2835 make install DESTDIR=$(HOME)/sdcc.rpm/
2836 \end_layout
2837
2838 \begin_layout Standard
2839 Please note that DESTDIR must have a trailing slash!
2840 \end_layout
2841
2842 \begin_layout Section
2843 Search Paths
2844 \begin_inset LatexCommand \label{sub:Search-Paths}
2845
2846 \end_inset
2847
2848
2849 \begin_inset LatexCommand \index{Search path}
2850
2851 \end_inset
2852
2853
2854 \end_layout
2855
2856 \begin_layout Standard
2857 Some search paths or parts of them are determined by configure variables
2858  (in 
2859 \emph on
2860 italics
2861 \emph default
2862 , see section above).
2863  Further search paths are determined by environment variables during runtime.
2864  
2865 \newline
2866 The paths searched when running the compiler are as follows (the first
2867  catch wins):
2868 \newline
2869
2870 \newline
2871 1.
2872  Binary files (preprocessor, assembler and linker)
2873 \newline
2874
2875 \end_layout
2876
2877 \begin_layout Standard
2878 \align center
2879 \begin_inset Tabular
2880 <lyxtabular version="3" rows="4" columns="3">
2881 <features>
2882 <column alignment="block" valignment="top" leftline="true" width="0in">
2883 <column alignment="block" valignment="top" leftline="true" width="0in">
2884 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2885 <row topline="true" bottomline="true">
2886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2887 \begin_inset Text
2888
2889 \begin_layout Standard
2890 Search path
2891 \end_layout
2892
2893 \end_inset
2894 </cell>
2895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2896 \begin_inset Text
2897
2898 \begin_layout Standard
2899 default
2900 \end_layout
2901
2902 \end_inset
2903 </cell>
2904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2905 \begin_inset Text
2906
2907 \begin_layout Standard
2908 Win32 builds
2909 \end_layout
2910
2911 \end_inset
2912 </cell>
2913 </row>
2914 <row topline="true">
2915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2916 \begin_inset Text
2917
2918 \begin_layout Standard
2919 $SDCC_HOME/
2920 \emph on
2921 $PPREFIX2BIN_DIR
2922 \end_layout
2923
2924 \end_inset
2925 </cell>
2926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2927 \begin_inset Text
2928
2929 \begin_layout Standard
2930 $SDCC_HOME/bin
2931 \end_layout
2932
2933 \end_inset
2934 </cell>
2935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2936 \begin_inset Text
2937
2938 \begin_layout Standard
2939 $SDCC_HOME
2940 \backslash
2941 bin
2942 \end_layout
2943
2944 \end_inset
2945 </cell>
2946 </row>
2947 <row topline="true">
2948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2949 \begin_inset Text
2950
2951 \begin_layout Standard
2952 Path of argv[0] (if available)
2953 \end_layout
2954
2955 \end_inset
2956 </cell>
2957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2958 \begin_inset Text
2959
2960 \begin_layout Standard
2961 Path of argv[0]
2962 \end_layout
2963
2964 \end_inset
2965 </cell>
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2967 \begin_inset Text
2968
2969 \begin_layout Standard
2970 Path of argv[0]
2971 \end_layout
2972
2973 \end_inset
2974 </cell>
2975 </row>
2976 <row topline="true" bottomline="true">
2977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2978 \begin_inset Text
2979
2980 \begin_layout Standard
2981 $PATH
2982 \end_layout
2983
2984 \end_inset
2985 </cell>
2986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2987 \begin_inset Text
2988
2989 \begin_layout Standard
2990 $PATH
2991 \end_layout
2992
2993 \end_inset
2994 </cell>
2995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2996 \begin_inset Text
2997
2998 \begin_layout Standard
2999 $PATH
3000 \end_layout
3001
3002 \end_inset
3003 </cell>
3004 </row>
3005 </lyxtabular>
3006
3007 \end_inset
3008
3009  
3010 \newline
3011
3012 \end_layout
3013
3014 \begin_layout Standard
3015 \noindent
3016 2.
3017  Include files
3018 \newline
3019
3020 \end_layout
3021
3022 \begin_layout Standard
3023 \align center
3024 \begin_inset Tabular
3025 <lyxtabular version="3" rows="6" columns="3">
3026 <features>
3027 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3028 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3029 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3030 <row topline="true" bottomline="true">
3031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3032 \begin_inset Text
3033
3034 \begin_layout Standard
3035 Search path
3036 \end_layout
3037
3038 \end_inset
3039 </cell>
3040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3041 \begin_inset Text
3042
3043 \begin_layout Standard
3044 default
3045 \end_layout
3046
3047 \end_inset
3048 </cell>
3049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3050 \begin_inset Text
3051
3052 \begin_layout Standard
3053 Win32 builds
3054 \end_layout
3055
3056 \end_inset
3057 </cell>
3058 </row>
3059 <row topline="true">
3060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_inset Text
3062
3063 \begin_layout Standard
3064 -
3065 \begin_inset ERT
3066 status collapsed
3067
3068 \begin_layout Standard
3069
3070
3071 \backslash
3072 /
3073 \end_layout
3074
3075 \end_inset
3076
3077 -I dir
3078 \end_layout
3079
3080 \end_inset
3081 </cell>
3082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3083 \begin_inset Text
3084
3085 \begin_layout Standard
3086 -
3087 \begin_inset ERT
3088 status collapsed
3089
3090 \begin_layout Standard
3091
3092
3093 \backslash
3094 /
3095 \end_layout
3096
3097 \end_inset
3098
3099 -I dir
3100 \end_layout
3101
3102 \end_inset
3103 </cell>
3104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3105 \begin_inset Text
3106
3107 \begin_layout Standard
3108 -
3109 \begin_inset ERT
3110 status collapsed
3111
3112 \begin_layout Standard
3113
3114
3115 \backslash
3116 /
3117 \end_layout
3118
3119 \end_inset
3120
3121 -I dir
3122 \end_layout
3123
3124 \end_inset
3125 </cell>
3126 </row>
3127 <row topline="true">
3128 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3129 \begin_inset Text
3130
3131 \begin_layout Standard
3132 $SDCC_INCLUDE
3133 \end_layout
3134
3135 \end_inset
3136 </cell>
3137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3138 \begin_inset Text
3139
3140 \begin_layout Standard
3141 $SDCC_INCLUDE
3142 \end_layout
3143
3144 \end_inset
3145 </cell>
3146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3147 \begin_inset Text
3148
3149 \begin_layout Standard
3150 $SDCC_INCLUDE
3151 \end_layout
3152
3153 \end_inset
3154 </cell>
3155 </row>
3156 <row topline="true">
3157 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3158 \begin_inset Text
3159
3160 \begin_layout Standard
3161 $SDCC_HOME/
3162 \newline
3163
3164 \emph on
3165 $PREFIX2DATA_DIR/
3166 \newline
3167 $INCLUDE_DIR_SUFFIX
3168 \end_layout
3169
3170 \end_inset
3171 </cell>
3172 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3173 \begin_inset Text
3174
3175 \begin_layout Standard
3176 $SDCC_ HOME/
3177 \newline
3178 share/sdcc/
3179 \newline
3180 include
3181 \end_layout
3182
3183 \end_inset
3184 </cell>
3185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3186 \begin_inset Text
3187
3188 \begin_layout Standard
3189 $SDCC_HOME
3190 \backslash
3191 include
3192 \end_layout
3193
3194 \end_inset
3195 </cell>
3196 </row>
3197 <row topline="true">
3198 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3199 \begin_inset Text
3200
3201 \begin_layout Standard
3202 path(argv[0])/
3203 \newline
3204
3205 \emph on
3206 $BIN2DATADIR/
3207 \emph default
3208
3209 \newline
3210
3211 \emph on
3212 $INCLUDE_DIR_SUFFIX
3213 \end_layout
3214
3215 \end_inset
3216 </cell>
3217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3218 \begin_inset Text
3219
3220 \begin_layout Standard
3221 path(argv[0])/
3222 \newline
3223 ../sdcc/include
3224 \newline
3225 \InsetSpace ~
3226 \InsetSpace ~
3227 \InsetSpace ~
3228 \InsetSpace ~
3229 \InsetSpace ~
3230 \InsetSpace ~
3231 \InsetSpace ~
3232 \InsetSpace ~
3233 \InsetSpace ~
3234 \InsetSpace ~
3235 \InsetSpace ~
3236 \InsetSpace ~
3237 \InsetSpace ~
3238 \InsetSpace ~
3239 \InsetSpace ~
3240 \InsetSpace ~
3241 \InsetSpace ~
3242 \InsetSpace ~
3243 \InsetSpace ~
3244 \InsetSpace ~
3245 \InsetSpace ~
3246 \InsetSpace ~
3247 \InsetSpace ~
3248 \InsetSpace ~
3249 \InsetSpace ~
3250 \InsetSpace ~
3251 \InsetSpace ~
3252 \InsetSpace ~
3253 \InsetSpace ~
3254 \InsetSpace ~
3255 \InsetSpace ~
3256 \InsetSpace ~
3257 \InsetSpace ~
3258 \InsetSpace ~
3259 \InsetSpace ~
3260 \InsetSpace ~
3261 \InsetSpace ~
3262 \InsetSpace ~
3263
3264 \end_layout
3265
3266 \end_inset
3267 </cell>
3268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3269 \begin_inset Text
3270
3271 \begin_layout Standard
3272 path(argv[0])
3273 \backslash
3274 ..
3275 \backslash
3276 include
3277 \end_layout
3278
3279 \end_inset
3280 </cell>
3281 </row>
3282 <row topline="true" bottomline="true">
3283 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3284 \begin_inset Text
3285
3286 \begin_layout Standard
3287
3288 \emph on
3289 $DATADIR/
3290 \emph default
3291
3292 \newline
3293
3294 \emph on
3295 $INCLUDE_DIR_SUFFIX
3296 \end_layout
3297
3298 \end_inset
3299 </cell>
3300 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3301 \begin_inset Text
3302
3303 \begin_layout Standard
3304 /usr/local/share/sdcc/
3305 \newline
3306 include
3307 \end_layout
3308
3309 \end_inset
3310 </cell>
3311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3312 \begin_inset Text
3313
3314 \begin_layout Standard
3315 (not on Win32)
3316 \end_layout
3317
3318 \end_inset
3319 </cell>
3320 </row>
3321 </lyxtabular>
3322
3323 \end_inset
3324
3325  
3326 \newline
3327
3328 \end_layout
3329
3330 \begin_layout Standard
3331 \noindent
3332 The option -
3333 \begin_inset ERT
3334 status collapsed
3335
3336 \begin_layout Standard
3337
3338
3339 \backslash
3340 /
3341 \end_layout
3342
3343 \end_inset
3344
3345 -nostdinc disables the last two search paths.
3346 \newline
3347
3348 \newline
3349 3.
3350  Library files 
3351 \newline
3352
3353 \end_layout
3354
3355 \begin_layout Standard
3356 With the exception of 
3357 \begin_inset Quotes sld
3358 \end_inset
3359
3360 -
3361 \begin_inset ERT
3362 status collapsed
3363
3364 \begin_layout Standard
3365
3366
3367 \backslash
3368 /
3369 \end_layout
3370
3371 \end_inset
3372
3373 -L dir
3374 \begin_inset Quotes srd
3375 \end_inset
3376
3377  the 
3378 \shape italic
3379 model
3380 \shape default
3381  is auto-appended by the compiler (e.g.
3382  small, large, z80, ds390 etc.).
3383  
3384 \newline
3385
3386 \end_layout
3387
3388 \begin_layout Standard
3389 \align center
3390 \begin_inset Tabular
3391 <lyxtabular version="3" rows="6" columns="3">
3392 <features>
3393 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3394 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3395 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3396 <row topline="true" bottomline="true">
3397 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3398 \begin_inset Text
3399
3400 \begin_layout Standard
3401 Search path
3402 \end_layout
3403
3404 \end_inset
3405 </cell>
3406 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3407 \begin_inset Text
3408
3409 \begin_layout Standard
3410 default
3411 \end_layout
3412
3413 \end_inset
3414 </cell>
3415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3416 \begin_inset Text
3417
3418 \begin_layout Standard
3419 Win32 builds
3420 \end_layout
3421
3422 \end_inset
3423 </cell>
3424 </row>
3425 <row topline="true">
3426 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3427 \begin_inset Text
3428
3429 \begin_layout Standard
3430 -
3431 \begin_inset ERT
3432 status collapsed
3433
3434 \begin_layout Standard
3435
3436
3437 \backslash
3438 /
3439 \end_layout
3440
3441 \end_inset
3442
3443 -L dir
3444 \end_layout
3445
3446 \end_inset
3447 </cell>
3448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3449 \begin_inset Text
3450
3451 \begin_layout Standard
3452 -
3453 \begin_inset ERT
3454 status collapsed
3455
3456 \begin_layout Standard
3457
3458
3459 \backslash
3460 /
3461 \end_layout
3462
3463 \end_inset
3464
3465 -L dir
3466 \end_layout
3467
3468 \end_inset
3469 </cell>
3470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3471 \begin_inset Text
3472
3473 \begin_layout Standard
3474 -
3475 \begin_inset ERT
3476 status collapsed
3477
3478 \begin_layout Standard
3479
3480
3481 \backslash
3482 /
3483 \end_layout
3484
3485 \end_inset
3486
3487 -L dir
3488 \end_layout
3489
3490 \end_inset
3491 </cell>
3492 </row>
3493 <row topline="true">
3494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3495 \begin_inset Text
3496
3497 \begin_layout Standard
3498 $SDCC_LIB/
3499 \newline
3500
3501 \emph on
3502 <model>
3503 \end_layout
3504
3505 \end_inset
3506 </cell>
3507 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3508 \begin_inset Text
3509
3510 \begin_layout Standard
3511 $SDCC_LIB/
3512 \newline
3513
3514 \emph on
3515 <model>
3516 \end_layout
3517
3518 \end_inset
3519 </cell>
3520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3521 \begin_inset Text
3522
3523 \begin_layout Standard
3524 $SDCC_LIB
3525 \backslash
3526
3527 \newline
3528
3529 \emph on
3530 <model>
3531 \end_layout
3532
3533 \end_inset
3534 </cell>
3535 </row>
3536 <row topline="true">
3537 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3538 \begin_inset Text
3539
3540 \begin_layout Standard
3541 $SDCC_HOME/
3542 \newline
3543
3544 \emph on
3545 $PREFIX2DATA_DIR/
3546 \newline
3547 $LIB_DIR_SUFFIX/<model>
3548 \end_layout
3549
3550 \end_inset
3551 </cell>
3552 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3553 \begin_inset Text
3554
3555 \begin_layout Standard
3556 $SDCC_HOME/
3557 \newline
3558 share/sdcc/
3559 \newline
3560 lib/
3561 \emph on
3562 <model>
3563 \end_layout
3564
3565 \end_inset
3566 </cell>
3567 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3568 \begin_inset Text
3569
3570 \begin_layout Standard
3571 $SDCC_HOME
3572 \backslash
3573 lib
3574 \backslash
3575
3576 \emph on
3577
3578 \newline
3579 <model>
3580 \end_layout
3581
3582 \end_inset
3583 </cell>
3584 </row>
3585 <row topline="true">
3586 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3587 \begin_inset Text
3588
3589 \begin_layout Standard
3590 path(argv[0])/
3591 \newline
3592
3593 \emph on
3594 $BIN2DATADIR/
3595 \emph default
3596
3597 \newline
3598
3599 \emph on
3600 $LIB_DIR_SUFFIX/<model>
3601 \end_layout
3602
3603 \end_inset
3604 </cell>
3605 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3606 \begin_inset Text
3607
3608 \begin_layout Standard
3609 path(argv[0])/
3610 \newline
3611 ../sdcc/lib/
3612 \emph on
3613 <model>
3614 \newline
3615 \InsetSpace ~
3616 \InsetSpace ~
3617 \InsetSpace ~
3618 \InsetSpace ~
3619 \InsetSpace ~
3620 \InsetSpace ~
3621 \InsetSpace ~
3622 \InsetSpace ~
3623 \InsetSpace ~
3624 \InsetSpace ~
3625 \InsetSpace ~
3626 \InsetSpace ~
3627 \InsetSpace ~
3628 \InsetSpace ~
3629 \InsetSpace ~
3630 \InsetSpace ~
3631 \InsetSpace ~
3632 \InsetSpace ~
3633 \InsetSpace ~
3634 \InsetSpace ~
3635 \InsetSpace ~
3636 \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
3655 \end_layout
3656
3657 \end_inset
3658 </cell>
3659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3660 \begin_inset Text
3661
3662 \begin_layout Standard
3663 path(argv[0])
3664 \backslash
3665
3666 \newline
3667 ..
3668 \backslash
3669 lib
3670 \backslash
3671
3672 \emph on
3673 <model>
3674 \newline
3675 \InsetSpace ~
3676 \InsetSpace ~
3677 \InsetSpace ~
3678 \InsetSpace ~
3679 \InsetSpace ~
3680 \InsetSpace ~
3681 \InsetSpace ~
3682 \InsetSpace ~
3683 \InsetSpace ~
3684 \InsetSpace ~
3685 \InsetSpace ~
3686 \InsetSpace ~
3687 \InsetSpace ~
3688 \InsetSpace ~
3689 \InsetSpace ~
3690 \InsetSpace ~
3691 \InsetSpace ~
3692 \InsetSpace ~
3693 \InsetSpace ~
3694 \InsetSpace ~
3695 \InsetSpace ~
3696 \InsetSpace ~
3697 \InsetSpace ~
3698 \InsetSpace ~
3699 \InsetSpace ~
3700 \InsetSpace ~
3701 \InsetSpace ~
3702 \InsetSpace ~
3703 \InsetSpace ~
3704 \InsetSpace ~
3705 \InsetSpace ~
3706 \InsetSpace ~
3707 \InsetSpace ~
3708 \InsetSpace ~
3709 \InsetSpace ~
3710
3711 \end_layout
3712
3713 \end_inset
3714 </cell>
3715 </row>
3716 <row topline="true" bottomline="true">
3717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3718 \begin_inset Text
3719
3720 \begin_layout Standard
3721
3722 \emph on
3723 $DATADIR/
3724 \newline
3725 $LIB_DIR_SUFFIX/<model>
3726 \end_layout
3727
3728 \end_inset
3729 </cell>
3730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3731 \begin_inset Text
3732
3733 \begin_layout Standard
3734 /usr/local/share/sdcc/
3735 \newline
3736 lib/
3737 \emph on
3738 <model>
3739 \end_layout
3740
3741 \end_inset
3742 </cell>
3743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3744 \begin_inset Text
3745
3746 \begin_layout Standard
3747 (not on Win32)
3748 \end_layout
3749
3750 \end_inset
3751 </cell>
3752 </row>
3753 </lyxtabular>
3754
3755 \end_inset
3756
3757
3758 \newline
3759
3760 \end_layout
3761
3762 \begin_layout Standard
3763 \begin_inset Note Note
3764 status collapsed
3765
3766 \begin_layout Standard
3767 Don't delete any of the stray spaces in the table above without checking
3768  the HTML output (last line)!
3769 \end_layout
3770
3771 \end_inset
3772
3773
3774 \end_layout
3775
3776 \begin_layout Standard
3777 \InsetSpace ~
3778
3779 \newline
3780 The option -
3781 \begin_inset ERT
3782 status collapsed
3783
3784 \begin_layout Standard
3785
3786
3787 \backslash
3788 /
3789 \end_layout
3790
3791 \end_inset
3792
3793 -nostdlib disables the last two search paths.
3794 \end_layout
3795
3796 \begin_layout Section
3797 Building SDCC
3798 \begin_inset LatexCommand \index{Building SDCC}
3799
3800 \end_inset
3801
3802
3803 \end_layout
3804
3805 \begin_layout Subsection
3806 Building SDCC on Linux
3807 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3808
3809 \end_inset
3810
3811
3812 \end_layout
3813
3814 \begin_layout Enumerate
3815
3816 \series medium
3817 Download the source package
3818 \series default
3819  either from the SDCC Subversion repository or from snapshot builds
3820 \series medium
3821 , it will be named something like sdcc
3822 \series default
3823 -src
3824 \series medium
3825 -yyyymmdd-rrrr.t
3826 \series default
3827 ar.
3828 \series medium
3829 bz2
3830 \series default
3831  
3832 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3833
3834 \end_inset
3835
3836 .
3837 \end_layout
3838
3839 \begin_layout Enumerate
3840
3841 \series medium
3842 Bring up a command line terminal, such as xterm.
3843 \end_layout
3844
3845 \begin_layout Enumerate
3846
3847 \series medium
3848 Unpack the file using a command like: 
3849 \family sans
3850 \series bold
3851 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3852 \begin_inset Quotes srd
3853 \end_inset
3854
3855
3856 \family default
3857 \series medium
3858 , this will create a sub-directory called sdcc with all of the sources.
3859 \end_layout
3860
3861 \begin_layout Enumerate
3862 Change directory into the main SDCC directory, for example type: 
3863 \family sans
3864 \series bold
3865 "cd sdcc
3866 \series default
3867 ".
3868 \end_layout
3869
3870 \begin_layout Enumerate
3871
3872 \series medium
3873 Type 
3874 \family sans
3875 \series bold
3876 "./configure
3877 \family default
3878 \series default
3879 ".
3880  This configures the package for compilation on your system.
3881 \end_layout
3882
3883 \begin_layout Enumerate
3884
3885 \series medium
3886 Type 
3887 \family sans
3888 \series bold
3889 "make
3890 \family default
3891 \series default
3892 "
3893 \series medium
3894 .
3895
3896 \series default
3897  All of the source packages will compile, this can take a while.
3898 \end_layout
3899
3900 \begin_layout Enumerate
3901
3902 \series medium
3903 Type 
3904 \family sans
3905 \series bold
3906 "make install"
3907 \family default
3908 \series default
3909  as root
3910 \series medium
3911 .
3912
3913 \series default
3914  This copies the binary executables, the include files, the libraries and
3915  the documentation to the install directories.
3916  Proceed with section 
3917 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3918
3919 \end_inset
3920
3921 .
3922 \end_layout
3923
3924 \begin_layout Subsection
3925 Building SDCC on OSX 2.x
3926 \end_layout
3927
3928 \begin_layout Standard
3929 Follow the instruction for Linux.
3930 \newline
3931
3932 \newline
3933 On OSX 2.x it was reported, that the default
3934  gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3935  Fortunately there's also gcc 2.9.x installed, which works fine.
3936  This compiler can be selected by running 'configure' with:
3937 \end_layout
3938
3939 \begin_layout LyX-Code
3940 ./configure CC=gcc2 CXX=g++2
3941 \end_layout
3942
3943 \begin_layout Subsection
3944 Cross compiling SDCC on Linux for Windows
3945 \end_layout
3946
3947 \begin_layout Standard
3948 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3949  See section 'Configure Options'.
3950 \end_layout
3951
3952 \begin_layout Subsection
3953 Building SDCC using Cygwin and Mingw32
3954 \end_layout
3955
3956 \begin_layout Standard
3957 For building and installing a Cygwin executable follow the instructions
3958  for Linux.
3959 \newline
3960
3961 \newline
3962 On Cygwin a 
3963 \begin_inset Quotes sld
3964 \end_inset
3965
3966 native
3967 \begin_inset Quotes srd
3968 \end_inset
3969
3970  Win32-binary can be built, which will not need the Cygwin-DLL.
3971  For the necessary 'configure' options see section 'configure options' or
3972  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3973 \newline
3974
3975 \newline
3976 In order to install
3977  Cygwin on Windows download setup.exe from 
3978 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3979
3980 \end_inset
3981
3982 .
3983  Run it, set the 
3984 \begin_inset Quotes sld
3985 \end_inset
3986
3987 default text file type
3988 \begin_inset Quotes srd
3989 \end_inset
3990
3991  to 
3992 \begin_inset Quotes sld
3993 \end_inset
3994
3995 unix
3996 \begin_inset Quotes srd
3997 \end_inset
3998
3999  and download/install at least the following packages.
4000  Some packages are selected by default, others will be automatically selected
4001  because of dependencies with the manually selected packages.
4002  Never deselect these packages!
4003 \end_layout
4004
4005 \begin_layout Itemize
4006 flex
4007 \end_layout
4008
4009 \begin_layout Itemize
4010 bison
4011 \end_layout
4012
4013 \begin_layout Itemize
4014 gcc ; version 3.x is fine, no need to use the old 2.9x
4015 \end_layout
4016
4017 \begin_layout Itemize
4018 binutils ; selected with gcc
4019 \end_layout
4020
4021 \begin_layout Itemize
4022 make
4023 \end_layout
4024
4025 \begin_layout Itemize
4026 rxvt ; a nice console, which makes life much easier under windoze (see below)
4027 \end_layout
4028
4029 \begin_layout Itemize
4030 man ; not really needed for building SDCC, but you'll miss it sooner or
4031  later
4032 \end_layout
4033
4034 \begin_layout Itemize
4035 less ; not really needed for building SDCC, but you'll miss it sooner or
4036  later
4037 \end_layout
4038
4039 \begin_layout Itemize
4040 svn ; only if you use Subversion access
4041 \end_layout
4042
4043 \begin_layout Standard
4044 If you want to develop something you'll need:
4045 \end_layout
4046
4047 \begin_layout Itemize
4048 python ; for the regression tests
4049 \end_layout
4050
4051 \begin_layout Itemize
4052 gdb ; the gnu debugger, together with the nice GUI 
4053 \begin_inset Quotes sld
4054 \end_inset
4055
4056 insight
4057 \begin_inset Quotes srd
4058 \end_inset
4059
4060
4061 \end_layout
4062
4063 \begin_layout Itemize
4064 openssh ; to access the CF or commit changes
4065 \end_layout
4066
4067 \begin_layout Itemize
4068 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4069  use autoconf-stable!
4070 \end_layout
4071
4072 \begin_layout Standard
4073 rxvt is a nice console with history.
4074  Replace in your cygwin.bat the line
4075 \end_layout
4076
4077 \begin_layout LyX-Code
4078 bash -
4079 \begin_inset ERT
4080 status collapsed
4081
4082 \begin_layout Standard
4083
4084
4085 \backslash
4086 /
4087 \end_layout
4088
4089 \end_inset
4090
4091 -login -i 
4092 \end_layout
4093
4094 \begin_layout Standard
4095 with (one line):
4096 \end_layout
4097
4098 \begin_layout LyX-Code
4099 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4100 \end_layout
4101
4102 \begin_layout LyX-Code
4103      -bg black -fg white -geometry 100x65 -e bash -
4104 \begin_inset ERT
4105 status collapsed
4106
4107 \begin_layout Standard
4108
4109
4110 \backslash
4111 /
4112 \end_layout
4113
4114 \end_inset
4115
4116 -login
4117 \end_layout
4118
4119 \begin_layout Standard
4120 Text selected with the mouse is automatically copied to the clipboard, pasting
4121  works with shift-insert.
4122 \newline
4123
4124 \newline
4125 The other good tip is to make sure you have no //c/-styl
4126 e paths anywhere, use /cygdrive/c/ instead.
4127  Using // invokes a network lookup which is very slow.
4128  If you think 
4129 \begin_inset Quotes sld
4130 \end_inset
4131
4132 cygdrive
4133 \begin_inset Quotes srd
4134 \end_inset
4135
4136  is too long, you can change it with e.g.
4137 \end_layout
4138
4139 \begin_layout LyX-Code
4140 mount -s -u -c /mnt
4141 \end_layout
4142
4143 \begin_layout Standard
4144 SDCC sources use the unix line ending LF.
4145  Life is much easier, if you store the source tree on a drive which is mounted
4146  in binary mode.
4147  And use an editor which can handle LF-only line endings.
4148  Make sure not to commit files with windows line endings.
4149  The tabulator spacing
4150 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4151
4152 \end_inset
4153
4154  used in the project is 8.
4155  Although a tabulator spacing of 8 is a sensible choice for programmers
4156  (it's a power of 2 and allows to display 8/16 bit signed variables without
4157  loosing columns) the plan is to move towards using only spaces in the source.
4158 \end_layout
4159
4160 \begin_layout Subsection
4161 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4162 \end_layout
4163
4164 \begin_layout Standard
4165
4166 \series medium
4167 Download the source package
4168 \series default
4169  either from the SDCC Subversion repository or from the 
4170 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4171
4172 \end_inset
4173
4174
4175 \series medium
4176 , it will be named something like sdcc
4177 \series default
4178 -src
4179 \series medium
4180 -yyyymmdd-rrrr.tar.bz2.
4181
4182 \series default
4183  SDCC is distributed with all the projects, workspaces, and files you need
4184  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4185  The workspace name is 'sdcc.dsw'.
4186  Please note that as it is now, all the executables are created in a folder
4187  called sdcc
4188 \backslash
4189 bin_vc.
4190  Once built you need to copy the executables from sdcc
4191 \backslash
4192 bin_vc to sdcc
4193 \backslash
4194 bin before running SDCC.
4195  
4196 \newline
4197
4198 \newline
4199 WARNING: Visual studio is very picky with line terminations; it expects
4200  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4201  When using the Subversion repository it's easiest to configure the svn
4202  client to convert automatically for you.
4203  If however you are getting a message such as "This makefile was not generated
4204  by Developer Studio etc.
4205  etc.
4206 \begin_inset Quotes srd
4207 \end_inset
4208
4209  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4210  need to convert the Unix style line endings to DOS style line endings.
4211  To do so you can use the 
4212 \begin_inset Quotes sld
4213 \end_inset
4214
4215 unix2dos
4216 \begin_inset Quotes srd
4217 \end_inset
4218
4219  utility freely available on the internet.
4220  Doug Hawkins reported in the sdcc-user list that this works:
4221 \newline
4222
4223 \newline
4224 C:
4225 \backslash
4226 Programming
4227 \backslash
4228 SDCC> unix2dos sdcc.dsw
4229 \newline
4230 C:
4231 \backslash
4232 Programming
4233 \backslash
4234 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4235 \newline
4236
4237 \newline
4238 In order to build SDCC with MSVC
4239  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4240  One good place to get them is 
4241 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4242
4243 \end_inset
4244
4245
4246 \newline
4247
4248 \newline
4249 Download the file UnxUtils
4250 \begin_inset LatexCommand \index{UnxUtils}
4251
4252 \end_inset
4253
4254 .zip.
4255  Now you have to install the utilities and setup MSVC so it can locate the
4256  required programs.
4257  Here there are two alternatives (choose one!):
4258 \end_layout
4259
4260 \begin_layout Enumerate
4261 The easy way:
4262 \newline
4263
4264 \newline
4265 a) Extract UnxUtils.zip to your C:
4266 \backslash
4267  hard disk PRESERVING the original paths, otherwise bison won't work.
4268  (If you are using WinZip make certain that 'Use folder names' is selected)
4269 \newline
4270
4271 \newline
4272 b)
4273  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4274  'Show directories for:' select 'Executable files', and in the directories
4275  window add a new path: 'C:
4276 \backslash
4277 user
4278 \backslash
4279 local
4280 \backslash
4281 wbin', click ok.
4282 \newline
4283
4284 \newline
4285 (As a side effect, you get a bunch of Unix utilities that
4286  could be useful, such as diff and patch.)
4287 \end_layout
4288
4289 \begin_layout Enumerate
4290 A more compact way:
4291 \newline
4292
4293 \newline
4294 This one avoids extracting a bunch of files you may not
4295  use, but requires some extra work:
4296 \newline
4297
4298 \newline
4299 a) Create a directory were to put the
4300  tools needed, or use a directory already present.
4301  Say for example 'C:
4302 \backslash
4303 util'.
4304 \newline
4305
4306 \newline
4307 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4308  gawk.exe to such directory WITHOUT preserving the original paths.
4309  (If you are using WinZip make certain that 'Use folder names' is not selected)
4310 \newline
4311
4312 \newline
4313 c
4314 ) Rename bison.exe to '_bison.exe'.
4315 \newline
4316
4317 \newline
4318 d) Create a batch file 'bison.bat' in 'C:
4319 \backslash
4320 util
4321 \backslash
4322 ' and add these lines: 
4323 \newline
4324 \InsetSpace ~
4325 \InsetSpace ~
4326 set BISON_SIMPLE=C:
4327 \backslash
4328 util
4329 \backslash
4330 bison.simple 
4331 \newline
4332 \InsetSpace ~
4333 \InsetSpace ~
4334 set BISON_HAIRY=C:
4335 \backslash
4336 util
4337 \backslash
4338 bison.hairy
4339 \newline
4340 \InsetSpace ~
4341 \InsetSpace ~
4342 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4343 \newline
4344
4345 \newline
4346 Steps 'c' and 'd' are needed
4347  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4348  reside in some weird Unix directory, '/usr/local/share/' I think.
4349  So it is necessary to tell bison where those files are located if they
4350  are not in such directory.
4351  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4352 \newline
4353
4354 \newline
4355 e
4356 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4357  in 'Show directories for:' select 'Executable files', and in the directories
4358  window add a new path: 'c:
4359 \backslash
4360 util', click ok.
4361  Note that you can use any other path instead of 'c:
4362 \backslash
4363 util', even the path where the Visual C++ tools are, probably: 'C:
4364 \backslash
4365 Program Files
4366 \backslash
4367 Microsoft Visual Studio
4368 \backslash
4369 Common
4370 \backslash
4371 Tools'.
4372  So you don't have to execute step 'e' :)
4373 \end_layout
4374
4375 \begin_layout Standard
4376 That is it.
4377  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4378  the executables from sdcc
4379 \backslash
4380 bin_vc to sdcc
4381 \backslash
4382 bin, and you can compile using SDCC.
4383 \end_layout
4384
4385 \begin_layout Subsection
4386 Building SDCC Using Borland
4387 \end_layout
4388
4389 \begin_layout Enumerate
4390 From the sdcc directory, run the command "make -f Makefile.bcc".
4391  This should regenerate all the .exe files in the bin directory except for
4392  SDCDB and ucSim.
4393 \end_layout
4394
4395 \begin_layout Enumerate
4396 If you modify any source files and need to rebuild, be aware that the dependenci
4397 es may not be correctly calculated.
4398  The safest option is to delete all .obj files and run the build again.
4399  From a Cygwin BASH prompt, this can easily be done with the command (be
4400  sure you are in the sdcc directory):
4401 \newline
4402
4403 \newline
4404
4405 \family sans
4406 \series bold
4407 find .
4408  
4409 \backslash
4410 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4411 \backslash
4412 ) -print -exec rm {} 
4413 \backslash
4414 ;
4415 \family default
4416 \series default
4417
4418 \newline
4419
4420 \newline
4421 or on Windows NT/2000/XP from the command prompt with the command:
4422 \newline
4423
4424 \family sans
4425 \series bold
4426
4427 \newline
4428 del /s *.obj *.lib *.rul
4429 \family default
4430 \series default
4431  from the sdcc directory.
4432 \end_layout
4433
4434 \begin_layout Subsection
4435 Windows Install Using a ZIP Package
4436 \end_layout
4437
4438 \begin_layout Enumerate
4439 Download the binary zip package from 
4440 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4441
4442 \end_inset
4443
4444  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4445  This should unpack to a group of sub-directories.
4446  An example directory structure after unpacking the mingw32 package is:
4447  c:
4448 \backslash
4449 sdcc
4450 \backslash
4451 bin for the executables, c:
4452 \backslash
4453 sdcc
4454 \backslash
4455 include and c:
4456 \backslash
4457 sdcc
4458 \backslash
4459 lib for the include and libraries.
4460 \end_layout
4461
4462 \begin_layout Enumerate
4463 Adjust your environment variable PATH to include the location of the bin
4464  directory or start sdcc using the full path.
4465 \end_layout
4466
4467 \begin_layout Subsection
4468 Windows Install Using the Setup Program
4469 \begin_inset LatexCommand \label{sub:Windows-Install}
4470
4471 \end_inset
4472
4473
4474 \end_layout
4475
4476 \begin_layout Standard
4477 Download the setup program 
4478 \emph on
4479 sdcc-x.y.z-setup.exe
4480 \emph default
4481  for an official release from 
4482 \newline
4483
4484 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4485
4486 \end_inset
4487
4488  or a setup program for one of the snapshots 
4489 \emph on
4490 sdcc-yyyymmdd-xxxx-setup.exe
4491 \emph default
4492  from 
4493 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4494
4495 \end_inset
4496
4497  and execute it.
4498  A windows typical installer will guide you through the installation process.
4499 \end_layout
4500
4501 \begin_layout Subsection
4502 VPATH
4503 \begin_inset LatexCommand \index{VPATH}
4504
4505 \end_inset
4506
4507  feature
4508 \end_layout
4509
4510 \begin_layout Standard
4511 SDCC supports the VPATH feature provided by configure and make.
4512  It allows to separate the source and build trees.
4513  Here's an example:
4514 \end_layout
4515
4516 \begin_layout Standard
4517
4518 \family typewriter
4519 cd ~\InsetSpace ~
4520 \InsetSpace ~
4521 \InsetSpace ~
4522 \InsetSpace ~
4523 \InsetSpace ~
4524 \InsetSpace ~
4525 \InsetSpace ~
4526 \InsetSpace ~
4527 \InsetSpace ~
4528 \InsetSpace ~
4529 \InsetSpace ~
4530 \InsetSpace ~
4531 \InsetSpace ~
4532 \InsetSpace ~
4533 \InsetSpace ~
4534 \InsetSpace ~
4535 \InsetSpace ~
4536 \InsetSpace ~
4537 \InsetSpace ~
4538 \InsetSpace ~
4539 \InsetSpace ~
4540 # cd $HOME
4541 \end_layout
4542
4543 \begin_layout Standard
4544
4545 \family typewriter
4546 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4547 # extract source to directory sdcc
4548 \end_layout
4549
4550 \begin_layout Standard
4551
4552 \family typewriter
4553 mkdir sdcc.build\InsetSpace ~
4554 \InsetSpace ~
4555 \InsetSpace ~
4556 \InsetSpace ~
4557 \InsetSpace ~
4558 \InsetSpace ~
4559 \InsetSpace ~
4560 \InsetSpace ~
4561 \InsetSpace ~
4562 # put output in sdcc.build
4563 \end_layout
4564
4565 \begin_layout Standard
4566
4567 \family typewriter
4568 cd sdcc.build
4569 \end_layout
4570
4571 \begin_layout Standard
4572
4573 \family typewriter
4574 ../sdcc/configure\InsetSpace ~
4575 \InsetSpace ~
4576 \InsetSpace ~
4577 \InsetSpace ~
4578 \InsetSpace ~
4579 \InsetSpace ~
4580 \InsetSpace ~
4581 \InsetSpace ~
4582 # configure is doing all the magic!
4583 \end_layout
4584
4585 \begin_layout Standard
4586
4587 \family typewriter
4588 make
4589 \end_layout
4590
4591 \begin_layout Standard
4592 \noindent
4593 That's it! 
4594 \series bold
4595 configure
4596 \series default
4597  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4598  It automagically computes the variables srcdir, top_srcdir and top_buildir
4599  for each directory.
4600  After running 
4601 \series bold
4602 make
4603 \series default
4604  the generated files will be in ~/sdcc.build, while the source files stay
4605  in ~/sdcc.
4606 \newline
4607 This is not only usefull for building different binaries, e.g.
4608  when cross compiling.
4609  It also gives you a much better overview in the source tree when all the
4610  generated files are not scattered between the source files.
4611  And the best thing is: if you want to change a file you can leave the original
4612  file untouched in the source directory.
4613  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4614  Makefile.dep` and `make`.
4615  
4616 \series bold
4617 make
4618 \series default
4619  will do the rest for you!
4620 \end_layout
4621
4622 \begin_layout Section
4623 Building the Documentation
4624 \end_layout
4625
4626 \begin_layout Standard
4627 Add -
4628 \begin_inset ERT
4629 status collapsed
4630
4631 \begin_layout Standard
4632
4633
4634 \backslash
4635 /
4636 \end_layout
4637
4638 \end_inset
4639
4640 -enable-doc to the configure arguments to build the documentation together
4641  with all the other stuff.
4642  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4643  dvips and makeindex) to get the job done.
4644  Another possibility is to change to the doc directory and to type 
4645 \family sans
4646 \series bold
4647
4648 \begin_inset Quotes srd
4649 \end_inset
4650
4651 make
4652 \begin_inset Quotes srd
4653 \end_inset
4654
4655
4656 \family default
4657 \series default
4658  there.
4659  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4660 x).
4661  Using LyX 
4662 \begin_inset LatexCommand \url{http://www.lyx.org}
4663
4664 \end_inset
4665
4666  as editor is straightforward.
4667  Prebuilt documentation in html and pdf format is available from 
4668 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4669
4670 \end_inset
4671
4672 .
4673 \end_layout
4674
4675 \begin_layout Section
4676 Reading the Documentation
4677 \begin_inset LatexCommand \index{Documentation}
4678
4679 \end_inset
4680
4681
4682 \end_layout
4683
4684 \begin_layout Standard
4685 Currently reading the document in pdf format is recommended, as for unknown
4686  reason the hyperlinks are working there whereas in the html version they
4687  are not
4688 \begin_inset Foot
4689 status open
4690
4691 \begin_layout Standard
4692 If you should know why please drop us a note
4693 \end_layout
4694
4695 \end_inset
4696
4697 .
4698  
4699 \newline
4700 You'll find the pdf version
4701 \begin_inset LatexCommand \index{PDF version of this document}
4702
4703 \end_inset
4704
4705  at 
4706 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4707
4708 \end_inset
4709
4710 .
4711  
4712 \newline
4713 A html version
4714 \begin_inset LatexCommand \index{HTML version of this document}
4715
4716 \end_inset
4717
4718  should be online at 
4719 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4720
4721 \end_inset
4722
4723 .
4724 \newline
4725 This documentation is in some aspects different from a commercial documentation:
4726  
4727 \end_layout
4728
4729 \begin_layout Itemize
4730 It tries to document SDCC for several processor architectures in one document
4731  (commercially these probably would be separate documents/products).
4732  This document
4733 \begin_inset LatexCommand \index{Status of documentation}
4734
4735 \end_inset
4736
4737  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4738 on about f.e.
4739  Z80, PIC14, PIC16 and HC08.
4740 \end_layout
4741
4742 \begin_layout Itemize
4743 There are many references pointing away from this documentation.
4744  Don't let this distract you.
4745  If there f.e.
4746  was a reference like 
4747 \begin_inset LatexCommand \url{http://www.opencores.org}
4748
4749 \end_inset
4750
4751  together with a statement 
4752 \begin_inset Quotes sld
4753 \end_inset
4754
4755 some processors which are targetted by SDCC can be implemented in a 
4756 \emph on
4757 f
4758 \emph default
4759 ield 
4760 \emph on
4761 p
4762 \emph default
4763 rogrammable 
4764 \emph on
4765 g
4766 \emph default
4767 ate 
4768 \emph on
4769 a
4770 \emph default
4771 rray
4772 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4773
4774 \end_inset
4775
4776
4777 \begin_inset Quotes srd
4778 \end_inset
4779
4780  or 
4781 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4782
4783 \end_inset
4784
4785
4786 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4787
4788 \end_inset
4789
4790  
4791 \begin_inset Quotes sld
4792 \end_inset
4793
4794 have you ever heard of an open source compiler that compiles a subset of
4795  C for an FPGA?
4796 \begin_inset Quotes srd
4797 \end_inset
4798
4799  we expect you to have a quick look there and come back.
4800  If you read this you are on the right track.
4801 \end_layout
4802
4803 \begin_layout Itemize
4804 Some sections attribute more space to problems, restrictions and warnings
4805  than to the solution.
4806 \end_layout
4807
4808 \begin_layout Itemize
4809 The installation section and the section about the debugger is intimidating.
4810 \end_layout
4811
4812 \begin_layout Itemize
4813 There are still lots of typos and there are more different writing styles
4814  than pictures.
4815 \end_layout
4816
4817 \begin_layout Section
4818 Testing the SDCC Compiler
4819 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4820
4821 \end_inset
4822
4823
4824 \end_layout
4825
4826 \begin_layout Standard
4827 The first thing you should do after installing your SDCC compiler is to
4828  see if it runs.
4829  Type 
4830 \family sans
4831 \series bold
4832 "sdcc -
4833 \begin_inset ERT
4834 status collapsed
4835
4836 \begin_layout Standard
4837
4838
4839 \backslash
4840 /
4841 \end_layout
4842
4843 \end_inset
4844
4845 -version"
4846 \begin_inset LatexCommand \index{version}
4847
4848 \end_inset
4849
4850
4851 \family default
4852 \series default
4853  at the prompt, and the program should run and output its version like:
4854  
4855 \newline
4856
4857 \family typewriter
4858 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4859  (UNIX)
4860 \end_layout
4861
4862 \begin_layout Standard
4863 If it doesn't run, or gives a message about not finding sdcc program, then
4864  you need to check over your installation.
4865  Make sure that the sdcc bin directory is in your executable search path
4866  defined by the PATH environment setting (
4867 \series medium
4868 see 
4869 \series default
4870 section 
4871 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4872
4873 \end_inset
4874
4875 \InsetSpace ~
4876
4877 \series medium
4878 Install trouble-shooting for suggestions
4879 \series default
4880 ).
4881  Make sure that the sdcc program is in the bin folder, if not perhaps something
4882  did not install correctly.
4883 \newline
4884
4885 \newline
4886
4887 \series medium
4888 SDCC 
4889 \series default
4890 is commonly installed as described in section 
4891 \begin_inset Quotes sld
4892 \end_inset
4893
4894 Install and search paths
4895 \begin_inset Quotes srd
4896 \end_inset
4897
4898 .
4899 \newline
4900
4901 \newline
4902
4903 \series medium
4904 Make sure the compiler works on a very simple example.
4905  Type in the following test.c program using your favorite 
4906 \series default
4907 ASCII 
4908 \series medium
4909 editor:
4910 \end_layout
4911
4912 \begin_layout Verse
4913
4914 \family typewriter
4915 char test;
4916 \newline
4917
4918 \newline
4919 void main(void) {
4920 \newline
4921 \InsetSpace ~
4922 \InsetSpace ~
4923 \InsetSpace ~
4924 \InsetSpace ~
4925 test=0;
4926 \newline
4927 }
4928 \end_layout
4929
4930 \begin_layout Standard
4931
4932 \series medium
4933 Compile this using the following command: 
4934 \family sans
4935 \series bold
4936 "sdcc -c test.c".
4937
4938 \family default
4939 \series default
4940  
4941 \series medium
4942 If all goes well, the compiler will generate a test.asm and test.rel file.
4943  Congratulations, you've just compiled your first program with SDCC.
4944  We used the -c option to tell SDCC not to link the generated code, just
4945  to keep things simple for this step.
4946 \series default
4947
4948 \newline
4949
4950 \newline
4951
4952 \series medium
4953 The next step is to try it with the linker.
4954  Type in 
4955 \family sans
4956 \series bold
4957 "sdcc test.c
4958 \family default
4959 \series default
4960 "
4961 \series medium
4962 .
4963  If all goes well the compiler will link with the libraries and produce
4964  a test.ihx output file.
4965  If this step fails
4966 \series default
4967  
4968 \series medium
4969 (no test.ihx, and the linker generates warnings), then the problem is most
4970  likely that 
4971 \series default
4972 SDCC
4973 \series medium
4974  cannot find the 
4975 \series default
4976 /
4977 \series medium
4978 usr/local/share/sdcc/lib directory
4979 \series default
4980  
4981 \series medium
4982 (see 
4983 \series default
4984 section 
4985 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4986
4987 \end_inset
4988
4989 \InsetSpace ~
4990
4991 \series medium
4992 Install trouble-shooting for suggestions).
4993 \series default
4994
4995 \newline
4996
4997 \newline
4998
4999 \series medium
5000 The final test is to ensure 
5001 \series default
5002 SDCC
5003 \series medium
5004  can use the 
5005 \series default
5006 standard
5007 \series medium
5008  header files and libraries.
5009  Edit test.c and change it to the following:
5010 \end_layout
5011
5012 \begin_layout Verse
5013
5014 \family typewriter
5015 #include <string.h>
5016 \newline
5017
5018 \newline
5019 char str1[10];
5020 \newline
5021
5022 \newline
5023 void main(void) {
5024 \newline
5025 \InsetSpace ~
5026 \InsetSpace ~
5027 strcpy(str1, "testing");
5028 \newline
5029 }
5030 \end_layout
5031
5032 \begin_layout Standard
5033
5034 \series medium
5035 Compile this by typing 
5036 \family sans
5037 \series bold
5038 "sdcc test.c"
5039 \family default
5040 \series medium
5041 .
5042  This should generate a test.ihx output file, and it should give no warnings
5043  such as not finding the string.h file.
5044  If it cannot find the string.h file, then the problem is that 
5045 \series default
5046 SDCC
5047 \series medium
5048  cannot find the /usr/local/share/sdcc/include directory
5049 \series default
5050  
5051 \series medium
5052 (see the 
5053 \series default
5054 section 
5055 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5056
5057 \end_inset
5058
5059 \InsetSpace ~
5060
5061 \series medium
5062 Install trouble-shooting section for suggestions).
5063
5064 \series default
5065  Use option 
5066 \series bold
5067 -
5068 \begin_inset ERT
5069 status collapsed
5070
5071 \begin_layout Standard
5072
5073
5074 \backslash
5075 /
5076 \end_layout
5077
5078 \end_inset
5079
5080 -print-search-dirs
5081 \series default
5082
5083 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5084
5085 \end_inset
5086
5087  to find exactly where SDCC is looking for the include and lib files.
5088 \end_layout
5089
5090 \begin_layout Section
5091 Install Trouble-shooting
5092 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5093
5094 \end_inset
5095
5096
5097 \begin_inset LatexCommand \index{Install trouble-shooting}
5098
5099 \end_inset
5100
5101
5102 \end_layout
5103
5104 \begin_layout Subsection
5105 If SDCC does not build correctly
5106 \end_layout
5107
5108 \begin_layout Standard
5109 A thing to try is starting from scratch by unpacking the .tgz source package
5110  again in an empty directory.
5111  Configure it like:
5112 \newline
5113
5114 \newline
5115
5116 \family sans
5117 \series bold
5118 ./configure 2>&1 | tee configure.log
5119 \family default
5120 \series default
5121
5122 \newline
5123
5124 \newline
5125 and build it like:
5126 \newline
5127
5128 \newline
5129
5130 \family sans
5131 \series bold
5132 make 2>&1 | tee make.log
5133 \family default
5134 \series default
5135
5136 \newline
5137
5138 \newline
5139 If anything goes wrong, you can review the log files to locate the problem.
5140  Or a relevant part of this can be attached to an email that could be helpful
5141  when requesting help from the mailing list.
5142 \end_layout
5143
5144 \begin_layout Subsection
5145 What the 
5146 \begin_inset Quotes sld
5147 \end_inset
5148
5149 ./configure
5150 \begin_inset Quotes srd
5151 \end_inset
5152
5153  does
5154 \end_layout
5155
5156 \begin_layout Standard
5157 The 
5158 \begin_inset Quotes sld
5159 \end_inset
5160
5161 ./configure
5162 \begin_inset Quotes srd
5163 \end_inset
5164
5165  command is a script that analyzes your system and performs some configuration
5166  to ensure the source package compiles on your system.
5167  It will take a few minutes to run, and will compile a few tests to determine
5168  what compiler features are installed.
5169 \end_layout
5170
5171 \begin_layout Subsection
5172 What the 
5173 \begin_inset Quotes sld
5174 \end_inset
5175
5176 make
5177 \begin_inset Quotes srd
5178 \end_inset
5179
5180  does
5181 \end_layout
5182
5183 \begin_layout Standard
5184 This runs the GNU make tool, which automatically compiles all the source
5185  packages into the final installed binary executables.
5186 \end_layout
5187
5188 \begin_layout Subsection
5189 What the 
5190 \begin_inset Quotes sld
5191 \end_inset
5192
5193 make install
5194 \begin_inset Quotes erd
5195 \end_inset
5196
5197  command does.
5198 \end_layout
5199
5200 \begin_layout Standard
5201 This will install the compiler, other executables libraries and include
5202  files into the appropriate directories.
5203  See sections 
5204 \begin_inset LatexCommand \ref{sub:Install-paths}
5205
5206 \end_inset
5207
5208 ,\InsetSpace ~
5209
5210 \begin_inset LatexCommand \ref{sub:Search-Paths}
5211
5212 \end_inset
5213
5214 \InsetSpace ~
5215 about install and search paths.
5216 \newline
5217 On most systems you will need super-user privilege
5218 s to do this.
5219 \end_layout
5220
5221 \begin_layout Section
5222 Components of SDCC
5223 \end_layout
5224
5225 \begin_layout Standard
5226 SDCC is not just a compiler, but a collection of tools by various developers.
5227  These include linkers, assemblers, simulators and other components.
5228  Here is a summary of some of the components.
5229  Note that the included simulator and assembler have separate documentation
5230  which you can find in the source package in their respective directories.
5231  As SDCC grows to include support for other processors, other packages from
5232  various developers are included and may have their own sets of documentation.
5233 \newline
5234
5235 \newline
5236 You
5237  might want to look at the files which are installed in <installdir>.
5238  At the time of this writing, we find the following programs for gcc-builds:
5239 \newline
5240
5241  
5242 \newline
5243 In <installdir>/bin:
5244 \end_layout
5245
5246 \begin_layout Itemize
5247 sdcc - The compiler.
5248 \end_layout
5249
5250 \begin_layout Itemize
5251 sdcpp - The C preprocessor.
5252 \end_layout
5253
5254 \begin_layout Itemize
5255 asx8051 - The assembler for 8051 type processors.
5256 \end_layout
5257
5258 \begin_layout Itemize
5259 as-z80
5260 \series bold
5261
5262 \series default
5263 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5264 \end_layout
5265
5266 \begin_layout Itemize
5267 aslink -The linker for 8051 type processors.
5268 \end_layout
5269
5270 \begin_layout Itemize
5271 link-z80
5272 \series bold
5273
5274 \series default
5275 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5276 \end_layout
5277
5278 \begin_layout Itemize
5279 s51 - The ucSim 8051 simulator.
5280 \end_layout
5281
5282 \begin_layout Itemize
5283 sdcdb - The source debugger.
5284 \end_layout
5285
5286 \begin_layout Itemize
5287 packihx - A tool to pack (compress) Intel hex files.
5288 \end_layout
5289
5290 \begin_layout Standard
5291 In <installdir>/share/sdcc/include
5292 \end_layout
5293
5294 \begin_layout Itemize
5295 the include files
5296 \end_layout
5297
5298 \begin_layout Standard
5299 In <installdir>/share/sdcc/lib
5300 \end_layout
5301
5302 \begin_layout Itemize
5303 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5304  relocatables.
5305 \end_layout
5306
5307 \begin_layout Standard
5308 In <installdir>/share/sdcc/doc
5309 \end_layout
5310
5311 \begin_layout Itemize
5312 the documentation
5313 \end_layout
5314
5315 \begin_layout Standard
5316 As development for other processors proceeds, this list will expand to include
5317  executables to support processors like AVR, PIC, etc.
5318 \end_layout
5319
5320 \begin_layout Subsection
5321 sdcc - The Compiler
5322 \end_layout
5323
5324 \begin_layout Standard
5325 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5326  the assembler and linkage editor.
5327 \end_layout
5328
5329 \begin_layout Subsection
5330 sdcpp - The C-Preprocessor
5331 \end_layout
5332
5333 \begin_layout Standard
5334 The preprocessor
5335 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5336
5337 \end_inset
5338
5339  is a modified version of the GNU cpp
5340 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5341
5342 \end_inset
5343
5344  preprocessor 
5345 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5346
5347 \end_inset
5348
5349 .
5350  The C preprocessor is used to pull in #include sources, process #ifdef
5351  statements, #defines and so on.
5352 \end_layout
5353
5354 \begin_layout Subsection
5355 as
5356 \emph on
5357 xxxx
5358 \emph default
5359 , aslink, link-
5360 \emph on
5361 xxx
5362 \emph default
5363  - The Assemblers and Linkage Editors
5364 \end_layout
5365
5366 \begin_layout Standard
5367 This is retargettable assembler & linkage editor, it was developed by Alan
5368  Baldwin.
5369  John Hartman created the version for 8051, and I (Sandeep) have made some
5370  enhancements and bug fixes for it to work properly with SDCC.
5371 \end_layout
5372
5373 \begin_layout Subsection
5374 s51 - The Simulator
5375 \end_layout
5376
5377 \begin_layout Standard
5378 S51
5379 \begin_inset LatexCommand \index{s51}
5380
5381 \end_inset
5382
5383  is a freeware, opensource simulator developed by Daniel Drotos.
5384  The simulator is built as part of the build process.
5385  For more information visit Daniel's web site at: 
5386 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5387
5388 \end_inset
5389
5390 .
5391  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5392  XA51 family.
5393 \end_layout
5394
5395 \begin_layout Subsection
5396 sdcdb - Source Level Debugger
5397 \end_layout
5398
5399 \begin_layout Standard
5400 SDCDB
5401 \begin_inset LatexCommand \index{SDCDB (debugger)}
5402
5403 \end_inset
5404
5405  is the companion source level debugger.
5406  More about SDCDB in section 
5407 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5408
5409 \end_inset
5410
5411 .
5412  The current version of the debugger uses Daniel's Simulator S51
5413 \begin_inset LatexCommand \index{s51}
5414
5415 \end_inset
5416
5417 , but can be easily changed to use other simulators.
5418 \end_layout
5419
5420 \begin_layout Chapter
5421 Using SDCC
5422 \end_layout
5423
5424 \begin_layout Section
5425 Compiling
5426 \end_layout
5427
5428 \begin_layout Subsection
5429 Single Source File Projects
5430 \end_layout
5431
5432 \begin_layout Standard
5433 For single source file 8051 projects the process is very simple.
5434  Compile your programs with the following command 
5435 \family sans
5436 \series bold
5437 "sdcc sourcefile.c".
5438
5439 \family default
5440 \series default
5441  This will compile, assemble and link your source file.
5442  Output files are as follows:
5443 \end_layout
5444
5445 \begin_layout Itemize
5446 sourcefile.asm
5447 \begin_inset LatexCommand \index{<file>.asm}
5448
5449 \end_inset
5450
5451  - Assembler source
5452 \begin_inset LatexCommand \index{Assembler source}
5453
5454 \end_inset
5455
5456  file created by the compiler
5457 \end_layout
5458
5459 \begin_layout Itemize
5460 sourcefile.lst
5461 \begin_inset LatexCommand \index{<file>.lst}
5462
5463 \end_inset
5464
5465  - Assembler listing
5466 \begin_inset LatexCommand \index{Assembler listing}
5467
5468 \end_inset
5469
5470  file created by the Assembler
5471 \end_layout
5472
5473 \begin_layout Itemize
5474 sourcefile.rst
5475 \begin_inset LatexCommand \index{<file>.rst}
5476
5477 \end_inset
5478
5479  - Assembler listing
5480 \begin_inset LatexCommand \index{Assembler listing}
5481
5482 \end_inset
5483
5484  file updated with linkedit information, created by linkage editor
5485 \end_layout
5486
5487 \begin_layout Itemize
5488 sourcefile.sym
5489 \begin_inset LatexCommand \index{<file>.sym}
5490
5491 \end_inset
5492
5493  - symbol listing
5494 \begin_inset LatexCommand \index{Symbol listing}
5495
5496 \end_inset
5497
5498  for the sourcefile, created by the assembler
5499 \end_layout
5500
5501 \begin_layout Itemize
5502 sourcefile.rel
5503 \begin_inset LatexCommand \index{<file>.rel}
5504
5505 \end_inset
5506
5507  or sourcefile.o
5508 \begin_inset LatexCommand \index{<file>.o}
5509
5510 \end_inset
5511
5512  - Object file
5513 \begin_inset LatexCommand \index{Object file}
5514
5515 \end_inset
5516
5517  created by the assembler, input to Linkage editor
5518 \end_layout
5519
5520 \begin_layout Itemize
5521 sourcefile.map
5522 \begin_inset LatexCommand \index{<file>.map}
5523
5524 \end_inset
5525
5526  - The memory map
5527 \begin_inset LatexCommand \index{Memory map}
5528
5529 \end_inset
5530
5531  for the load module, created by the Linker
5532 \end_layout
5533
5534 \begin_layout Itemize
5535 sourcefile.mem
5536 \begin_inset LatexCommand \index{<file>.mem}
5537
5538 \end_inset
5539
5540  - A file with a summary of the memory usage
5541 \end_layout
5542
5543 \begin_layout Itemize
5544 sourcefile.ihx
5545 \begin_inset LatexCommand \index{<file>.ihx}
5546
5547 \end_inset
5548
5549  - The load module in Intel hex format
5550 \begin_inset LatexCommand \index{Intel hex format}
5551
5552 \end_inset
5553
5554  (you can select the Motorola S19 format
5555 \begin_inset LatexCommand \index{Motorola S19 format}
5556
5557 \end_inset
5558
5559  with -
5560 \begin_inset ERT
5561 status collapsed
5562
5563 \begin_layout Standard
5564
5565
5566 \backslash
5567 /
5568 \end_layout
5569
5570 \end_inset
5571
5572 -out-fmt-s19
5573 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5574
5575 \end_inset
5576
5577 .
5578  If you need another format you might want to use 
5579 \family sans
5580 \shape italic
5581 objdump
5582 \family default
5583 \shape default
5584
5585 \begin_inset LatexCommand \index{objdump (tool)}
5586
5587 \end_inset
5588
5589  or
5590 \family sans
5591 \shape italic
5592  srecord
5593 \family default
5594 \shape default
5595
5596 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5597
5598 \end_inset
5599
5600
5601 \begin_inset Note Note
5602 status collapsed
5603
5604 \begin_layout Standard
5605 hyperlinks needed
5606 \end_layout
5607
5608 \end_inset
5609
5610  - see also section 
5611 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5612
5613 \end_inset
5614
5615 ).
5616  Both formats are documented in the documentation of srecord
5617 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5618
5619 \end_inset
5620
5621
5622 \end_layout
5623
5624 \begin_layout Itemize
5625 sourcefile.adb
5626 \begin_inset LatexCommand \index{<file>.adb}
5627
5628 \end_inset
5629
5630  - An intermediate file containing debug information needed to create the
5631  .cdb file (with -
5632 \begin_inset ERT
5633 status collapsed
5634
5635 \begin_layout Standard
5636
5637
5638 \backslash
5639 /
5640 \end_layout
5641
5642 \end_inset
5643
5644 -debug
5645 \begin_inset LatexCommand \index{-\/-debug}
5646
5647 \end_inset
5648
5649
5650 \end_layout
5651
5652 \begin_layout Itemize
5653 sourcefile.cdb
5654 \begin_inset LatexCommand \index{<file>.cdb}
5655
5656 \end_inset
5657
5658  - An optional file (with -
5659 \begin_inset ERT
5660 status collapsed
5661
5662 \begin_layout Standard
5663
5664
5665 \backslash
5666 /
5667 \end_layout
5668
5669 \end_inset
5670
5671 -debug) containing debug information.
5672  The format is documented in cdbfileformat.pdf
5673 \end_layout
5674
5675 \begin_layout Itemize
5676 sourcefile.
5677  - (no extension)
5678 \begin_inset LatexCommand \index{<file> (no extension)}
5679
5680 \end_inset
5681
5682  An optional AOMF or AOMF51
5683 \begin_inset LatexCommand \index{AOMF, AOMF51}
5684
5685 \end_inset
5686
5687  
5688 \begin_inset LatexCommand \label{OMF file}
5689
5690 \end_inset
5691
5692 file containing debug information (generated with option -
5693 \begin_inset ERT
5694 status collapsed
5695
5696 \begin_layout Standard
5697
5698
5699 \backslash
5700 /
5701 \end_layout
5702
5703 \end_inset
5704
5705 -debug).
5706  The (Intel)
5707 \emph on
5708  a
5709 \emph default
5710 bsolute 
5711 \emph on
5712 o
5713 \emph default
5714 bject 
5715 \emph on
5716 m
5717 \emph default
5718 odule 
5719 \emph on
5720 f
5721 \emph default
5722 ormat is a subformat of the OMF51 format and is commonly used by third party
5723  tools (debuggers
5724 \begin_inset LatexCommand \index{Debugger}
5725
5726 \end_inset
5727
5728 , simulators, emulators).
5729 \end_layout
5730
5731 \begin_layout Itemize
5732 sourcefile.dump*
5733 \begin_inset LatexCommand \index{<file>.dump*}
5734
5735 \end_inset
5736
5737  - Dump file to debug the compiler it self (generated with option -
5738 \begin_inset ERT
5739 status collapsed
5740
5741 \begin_layout Standard
5742
5743
5744 \backslash
5745 /
5746 \end_layout
5747
5748 \end_inset
5749
5750 -dumpall) (see section 
5751 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5752
5753 \end_inset
5754
5755 \InsetSpace ~
5756  and section 
5757 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5758
5759 \end_inset
5760
5761 \InsetSpace ~
5762
5763 \begin_inset Quotes sld
5764 \end_inset
5765
5766 Anatomy of the compiler
5767 \begin_inset Quotes srd
5768 \end_inset
5769
5770 ).
5771 \end_layout
5772
5773 \begin_layout Subsection
5774 Postprocessing the Intel Hex
5775 \begin_inset LatexCommand \index{Intel hex format}
5776
5777 \end_inset
5778
5779  file
5780 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5781
5782 \end_inset
5783
5784
5785 \end_layout
5786
5787 \begin_layout Standard
5788 In most cases this won't be needed but the Intel Hex file
5789 \begin_inset LatexCommand \index{<file>.ihx}
5790
5791 \end_inset
5792
5793  which is generated by SDCC might include lines of varying length and the
5794  addresses within the file are not guaranteed to be strictly ascending.
5795  If your toolchain or a bootloader does not like this you can use the tool
5796  
5797 \family typewriter
5798 packihx
5799 \family default
5800
5801 \begin_inset LatexCommand \index{packihx (tool)}
5802
5803 \end_inset
5804
5805  which is part of the SDCC distribution: 
5806 \newline
5807
5808 \newline
5809
5810 \family sans
5811 \series bold
5812  packihx sourcefile.ihx >sourcefile.hex
5813 \family default
5814 \series default
5815
5816 \newline
5817
5818 \newline
5819 The separately available
5820 \emph on
5821  srecord
5822 \emph default
5823
5824 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5825
5826 \end_inset
5827
5828  package additionally allows to set undefined locations to a predefined
5829  value, to insert checksums
5830 \begin_inset LatexCommand \index{checksum}
5831
5832 \end_inset
5833
5834  of various flavours (crc, add, xor) and to perform other manipulations
5835  (convert, split, crop, offset, ...).
5836  
5837 \newline
5838
5839 \newline
5840
5841 \family sans
5842 \series bold
5843 srec_cat\InsetSpace ~
5844 \InsetSpace ~
5845 sourcefile.ihx -intel\InsetSpace ~
5846 \InsetSpace ~
5847 -o sourcefile.hex -intel
5848 \newline
5849
5850 \newline
5851
5852 \family default
5853 \series default
5854 An example for a more complex command line
5855 \begin_inset Foot
5856 status open
5857
5858 \begin_layout Standard
5859 the command backfills
5860 \begin_inset LatexCommand \index{backfill unused memory}
5861
5862 \end_inset
5863
5864  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5865  block is zero.
5866  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5867  will be interpreted as an 
5868 \family typewriter
5869 lcall
5870 \family default
5871  to address 
5872 \family typewriter
5873 0x1212
5874 \family default
5875  (where an emergency routine could sit).
5876 \end_layout
5877
5878 \end_inset
5879
5880  could look like:
5881 \newline
5882
5883 \newline
5884
5885 \family sans
5886 \series bold
5887 \size footnotesize
5888 srec_cat\InsetSpace ~
5889 sourcefile.ihx -intel\InsetSpace ~
5890 \InsetSpace ~
5891 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5892 -little-endian-checksum-nega
5893 tive 0xfffe 0x02 0x02\InsetSpace ~
5894 \InsetSpace ~
5895 -o sourcefile.hex -intel
5896 \size default
5897
5898 \newline
5899
5900 \newline
5901
5902 \family default
5903 \series default
5904 The srecord package is available at 
5905 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5906
5907 \end_inset
5908
5909  .
5910 \end_layout
5911
5912 \begin_layout Subsection
5913 Projects with Multiple Source Files
5914 \end_layout
5915
5916 \begin_layout Standard
5917 SDCC can compile only ONE file at a time.
5918  Let us for example assume that you have a project containing the following
5919  files:
5920 \newline
5921
5922 \newline
5923 foo1.c (contains some functions)
5924 \newline
5925 foo2.c (contains some more functions)
5926 \newline
5927 foomai
5928 n.c (contains more functions and the function main)
5929 \newline
5930
5931 \size footnotesize
5932
5933 \newline
5934
5935 \size default
5936 The first two files will need to be compiled separately with the commands:
5937 \size footnotesize
5938  
5939 \size default
5940
5941 \newline
5942
5943 \newline
5944
5945 \family sans
5946 \series bold
5947 sdcc\InsetSpace ~
5948 -c\InsetSpace ~
5949 foo1.c
5950 \family default
5951 \series default
5952 \size footnotesize
5953
5954 \newline
5955
5956 \family sans
5957 \series bold
5958 \size default
5959 sdcc\InsetSpace ~
5960 -c\InsetSpace ~
5961 foo2.c
5962 \family default
5963 \series default
5964
5965 \newline
5966
5967 \newline
5968 Then compile the source file containing the 
5969 \emph on
5970 main()
5971 \emph default
5972  function and link
5973 \begin_inset LatexCommand \index{Linker}
5974
5975 \end_inset
5976
5977  the files together with the following command: 
5978 \newline
5979
5980 \newline
5981
5982 \family sans
5983 \series bold
5984 sdcc\InsetSpace ~
5985 foomain.c\InsetSpace ~
5986 foo1.rel\InsetSpace ~
5987 foo2.rel
5988 \family default
5989 \series default
5990
5991 \begin_inset LatexCommand \index{<file>.rel}
5992
5993 \end_inset
5994
5995
5996 \newline
5997
5998 \newline
5999 Alternatively, 
6000 \emph on
6001 foomain.c 
6002 \emph default
6003 can be separately compiled as well: 
6004 \family sans
6005 \series bold
6006
6007 \newline
6008
6009 \newline
6010 sdcc\InsetSpace ~
6011 -c\InsetSpace ~
6012 foomain.c
6013 \newline
6014 sdcc foomain.rel foo1.rel foo2.rel
6015 \newline
6016
6017 \newline
6018
6019 \family default
6020 \series default
6021 The file containing the 
6022 \emph on
6023 main()
6024 \emph default
6025  function
6026 \emph on
6027  
6028 \emph default
6029 \noun on
6030 must
6031 \noun default
6032  be the 
6033 \noun on
6034 first
6035 \noun default
6036  file specified in the command line, since the linkage editor processes
6037  file in the order they are presented to it.
6038  The linker is invoked from SDCC using a script file with extension .lnk
6039 \begin_inset LatexCommand \index{<file>.lnk}
6040
6041 \end_inset
6042
6043 .
6044  You can view this file to troubleshoot linking problems such as those arising
6045  from missing libraries.
6046 \end_layout
6047
6048 \begin_layout Subsection
6049 Projects with Additional Libraries
6050 \begin_inset LatexCommand \index{Libraries}
6051
6052 \end_inset
6053
6054
6055 \end_layout
6056
6057 \begin_layout Standard
6058 Some reusable routines may be compiled into a library, see the documentation
6059  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6060  for how to create a 
6061 \emph on
6062 .lib
6063 \begin_inset LatexCommand \index{<file>.lib}
6064
6065 \end_inset
6066
6067
6068 \emph default
6069  library file.
6070  Libraries created in this manner can be included in the command line.
6071  Make sure you include the -L <library-path> option to tell the linker where
6072  to look for these files if they are not in the current directory.
6073  Here is an example, assuming you have the source file 
6074 \emph on
6075 foomain.c
6076 \emph default
6077  and a library
6078 \emph on
6079  foolib.lib
6080 \emph default
6081  in the directory 
6082 \emph on
6083 mylib
6084 \emph default
6085  (if that is not the same as your current project):
6086 \newline
6087
6088 \newline
6089
6090 \family sans
6091 \series bold
6092 sdcc foomain.c foolib.lib -L mylib
6093 \newline
6094
6095 \newline
6096
6097 \family default
6098 \series default
6099 Note here that
6100 \emph on
6101  mylib
6102 \emph default
6103  must be an absolute path name.
6104 \newline
6105
6106 \newline
6107 The most efficient way to use libraries is
6108  to keep separate modules in separate source files.
6109  The lib file now should name all the modules.rel
6110 \begin_inset LatexCommand \index{<file>.rel}
6111
6112 \end_inset
6113
6114  files.
6115  For an example see the standard library file 
6116 \emph on
6117 libsdcc.lib
6118 \emph default
6119  in the directory <installdir>/share/lib/small.
6120 \end_layout
6121
6122 \begin_layout Subsection
6123 Using sdcclib to Create and Manage Libraries
6124 \begin_inset LatexCommand \index{sdcclib}
6125
6126 \end_inset
6127
6128
6129 \end_layout
6130
6131 \begin_layout Standard
6132 Alternatively, instead of having a .rel file for each entry on the library
6133  file as described in the preceding section, sdcclib can be used to embed
6134  all the modules belonging to such library in the library file itself.
6135  This results in a larger library file, but it greatly reduces the number
6136  of disk files accessed by the linker.
6137   Additionally, the packed library file contains an index of all include
6138  modules and symbols that significantly speeds up the linking process.
6139  To display a list of options supported by sdcclib type:
6140 \newline
6141
6142 \end_layout
6143
6144 \begin_layout Standard
6145
6146 \family sans
6147 \series bold
6148 sdcclib -?
6149 \begin_inset LatexCommand \index{sdcclib}
6150
6151 \end_inset
6152
6153
6154 \newline
6155
6156 \newline
6157
6158 \family default
6159 \series default
6160 To create a new library file, start by compiling all the required modules.
6161  For example:
6162 \newline
6163
6164 \end_layout
6165
6166 \begin_layout Standard
6167
6168 \family sans
6169 \series bold
6170 sdcc -c _divsint.c
6171 \end_layout
6172
6173 \begin_layout Standard
6174
6175 \family sans
6176 \series bold
6177 sdcc -c _divuint.c
6178 \end_layout
6179
6180 \begin_layout Standard
6181
6182 \family sans
6183 \series bold
6184 sdcc -c _modsint.c
6185 \end_layout
6186
6187 \begin_layout Standard
6188
6189 \family sans
6190 \series bold
6191 sdcc -c _moduint.c
6192 \end_layout
6193
6194 \begin_layout Standard
6195
6196 \family sans
6197 \series bold
6198 sdcc -c _mulint.c
6199 \newline
6200
6201 \end_layout
6202
6203 \begin_layout Standard
6204 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6205  and _mulint.rel.
6206  The next step is to add the .rel files to the library file:
6207 \newline
6208
6209 \end_layout
6210
6211 \begin_layout Standard
6212
6213 \family sans
6214 \series bold
6215 sdcclib libint.lib _divsint.rel
6216 \family default
6217
6218 \begin_inset LatexCommand \index{sdcclib}
6219
6220 \end_inset
6221
6222
6223 \end_layout
6224
6225 \begin_layout Standard
6226
6227 \family sans
6228 \series bold
6229 sdcclib libint.lib _divuint.rel
6230 \end_layout
6231
6232 \begin_layout Standard
6233
6234 \family sans
6235 \series bold
6236 sdcclib libint.lib _modsint.rel
6237 \end_layout
6238
6239 \begin_layout Standard
6240
6241 \family sans
6242 \series bold
6243 sdcclib libint.lib _moduint.rel
6244 \end_layout
6245
6246 \begin_layout Standard
6247
6248 \family sans
6249 \series bold
6250 sdcclib libint.lib _mulint.rel
6251 \series default
6252
6253 \newline
6254
6255 \end_layout
6256
6257 \begin_layout Standard
6258 If the file already exists in the library, it will be replaced.
6259  To see what modules and symbols are included in the library, options -s
6260  and -m are available.
6261  For example:
6262 \newline
6263
6264 \newline
6265
6266 \family sans
6267 \series bold
6268 sdcclib -s libint.lib
6269 \family default
6270
6271 \begin_inset LatexCommand \index{sdcclib}
6272
6273 \end_inset
6274
6275
6276 \newline
6277
6278 \family typewriter
6279 \series default
6280 _divsint.rel:
6281 \end_layout
6282
6283 \begin_layout Standard
6284
6285 \family typewriter
6286 __divsint_a_1_1
6287 \end_layout
6288
6289 \begin_layout Standard
6290
6291 \family typewriter
6292 __divsint_PARM_2
6293 \end_layout
6294
6295 \begin_layout Standard
6296
6297 \family typewriter
6298 __divsint
6299 \newline
6300 _divuint.rel:
6301 \end_layout
6302
6303 \begin_layout Standard
6304
6305 \family typewriter
6306 __divuint_a_1_1
6307 \end_layout
6308
6309 \begin_layout Standard
6310
6311 \family typewriter
6312 __divuint_PARM_2
6313 \end_layout
6314
6315 \begin_layout Standard
6316
6317 \family typewriter
6318 __divuint_reste_1_1
6319 \end_layout
6320
6321 \begin_layout Standard
6322
6323 \family typewriter
6324 __divuint_count_1_1
6325 \end_layout
6326
6327 \begin_layout Standard
6328
6329 \family typewriter
6330 __divuint
6331 \newline
6332 _modsint.rel:
6333 \end_layout
6334
6335 \begin_layout Standard
6336
6337 \family typewriter
6338 __modsint_a_1_1
6339 \end_layout
6340
6341 \begin_layout Standard
6342
6343 \family typewriter
6344 __modsint_PARM_2
6345 \end_layout
6346
6347 \begin_layout Standard
6348
6349 \family typewriter
6350 __modsint
6351 \newline
6352 _moduint.rel:
6353 \end_layout
6354
6355 \begin_layout Standard
6356
6357 \family typewriter
6358 __moduint_a_1_1
6359 \end_layout
6360
6361 \begin_layout Standard
6362
6363 \family typewriter
6364 __moduint_PARM_2
6365 \end_layout
6366
6367 \begin_layout Standard
6368
6369 \family typewriter
6370 __moduint_count_1_1
6371 \end_layout
6372
6373 \begin_layout Standard
6374
6375 \family typewriter
6376 __moduint
6377 \newline
6378 _mulint.rel:
6379 \end_layout
6380
6381 \begin_layout Standard
6382
6383 \family typewriter
6384 __mulint_PARM_2
6385 \end_layout
6386
6387 \begin_layout Standard
6388
6389 \family typewriter
6390 __mulint
6391 \family default
6392 \series bold
6393
6394 \newline
6395
6396 \end_layout
6397
6398 \begin_layout Standard
6399 If the source files are compiled using -
6400 \begin_inset ERT
6401 status collapsed
6402
6403 \begin_layout Standard
6404
6405
6406 \backslash
6407 /
6408 \end_layout
6409
6410 \end_inset
6411
6412 -debug
6413 \begin_inset LatexCommand \index{-\/-debug}
6414
6415 \end_inset
6416
6417 , the corresponding debug information file .adb will be include in the library
6418  file as well.
6419  The library files created with sdcclib are plain text files, so they can
6420  be viewed with a text editor.
6421  It is not recomended to modify a library file created with sdcclib using
6422  a text editor, as there are file indexes numbers located accross the file
6423  used by the linker to quickly locate the required module to link.
6424  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6425  it can be safely deleted, since all the information required for linking
6426  is embedded in the library file itself.
6427  Library files created using sdcclib are used as described in the preceding
6428  sections.
6429 \begin_inset VSpace bigskip
6430 \end_inset
6431
6432
6433 \end_layout
6434
6435 \begin_layout Section
6436 Command Line Options
6437 \begin_inset LatexCommand \index{Command Line Options}
6438
6439 \end_inset
6440
6441
6442 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6443
6444 \end_inset
6445
6446
6447 \end_layout
6448
6449 \begin_layout Subsection
6450 Processor Selection Options
6451 \begin_inset LatexCommand \index{Options processor selection}
6452
6453 \end_inset
6454
6455
6456 \begin_inset LatexCommand \index{Processor selection options}
6457
6458 \end_inset
6459
6460
6461 \end_layout
6462
6463 \begin_layout List
6464 \labelwidthstring 00.00.0000
6465
6466 \series bold
6467 -mmcs51
6468 \begin_inset LatexCommand \index{-mmcs51}
6469
6470 \end_inset
6471
6472
6473 \series default
6474  Generate code for the Intel MCS51
6475 \begin_inset LatexCommand \index{MCS51}
6476
6477 \end_inset
6478
6479  family of processors.
6480  This is the default processor target.
6481 \end_layout
6482
6483 \begin_layout List
6484 \labelwidthstring 00.00.0000
6485
6486 \series bold
6487 -mds390
6488 \begin_inset LatexCommand \index{-mds390}
6489
6490 \end_inset
6491
6492
6493 \series default
6494  Generate code for the Dallas DS80C390
6495 \begin_inset LatexCommand \index{DS80C390}
6496
6497 \end_inset
6498
6499  processor.
6500 \end_layout
6501
6502 \begin_layout List
6503 \labelwidthstring 00.00.0000
6504
6505 \series bold
6506 -mds400
6507 \begin_inset LatexCommand \index{-mds400}
6508
6509 \end_inset
6510
6511
6512 \series default
6513  Generate code for the Dallas DS80C400
6514 \begin_inset LatexCommand \index{DS80C400}
6515
6516 \end_inset
6517
6518  processor.
6519 \end_layout
6520
6521 \begin_layout List
6522 \labelwidthstring 00.00.0000
6523
6524 \series bold
6525 -mhc08
6526 \begin_inset LatexCommand \index{-mhc08}
6527
6528 \end_inset
6529
6530
6531 \series default
6532  Generate code for the Freescale/Motorola HC08
6533 \begin_inset LatexCommand \index{HC08}
6534
6535 \end_inset
6536
6537  family of processors.
6538 \end_layout
6539
6540 \begin_layout List
6541 \labelwidthstring 00.00.0000
6542
6543 \series bold
6544 -mz80
6545 \begin_inset LatexCommand \index{-mz80}
6546
6547 \end_inset
6548
6549
6550 \series default
6551  Generate code for the Zilog Z80
6552 \begin_inset LatexCommand \index{Z80}
6553
6554 \end_inset
6555
6556  family of processors.
6557 \end_layout
6558
6559 \begin_layout List
6560 \labelwidthstring 00.00.0000
6561
6562 \series bold
6563 -mgbz80
6564 \begin_inset LatexCommand \index{-mgbz80}
6565
6566 \end_inset
6567
6568
6569 \series default
6570  Generate code for the GameBoy Z80
6571 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6572
6573 \end_inset
6574
6575  processor (Not actively maintained).
6576 \end_layout
6577
6578 \begin_layout List
6579 \labelwidthstring 00.00.0000
6580
6581 \series bold
6582 -mavr
6583 \begin_inset LatexCommand \index{-mavr}
6584
6585 \end_inset
6586
6587
6588 \series default
6589  Generate code for the Atmel AVR
6590 \begin_inset LatexCommand \index{AVR}
6591
6592 \end_inset
6593
6594  processor (Not maintained, not complete).
6595  AVR users should probably have a look at winavr 
6596 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6597
6598 \end_inset
6599
6600  or 
6601 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6602
6603 \end_inset
6604
6605 , which is based on AVR-port of the gcc compiler.
6606 \end_layout
6607
6608 \begin_layout Standard
6609 \begin_inset Note Note
6610 status collapsed
6611
6612 \begin_layout Standard
6613 I think it is fair to direct users there for now.
6614  Open source is also about avoiding unnecessary work .
6615  But I didn't find the 'official' link.
6616 \end_layout
6617
6618 \end_inset
6619
6620
6621 \end_layout
6622
6623 \begin_layout List
6624 \labelwidthstring 00.00.0000
6625
6626 \series bold
6627 -mpic14
6628 \begin_inset LatexCommand \index{-mpic14}
6629
6630 \end_inset
6631
6632
6633 \series default
6634  Generate code for the Microchip PIC 14
6635 \begin_inset LatexCommand \index{PIC14}
6636
6637 \end_inset
6638
6639 -bit processors (p16f84 and variants.
6640  In development, not complete).
6641 \end_layout
6642
6643 \begin_layout Standard
6644 \begin_inset Note Note
6645 status collapsed
6646
6647 \begin_layout Standard
6648 p16f627 p16f628 p16f84 p16f873 p16f877?
6649 \end_layout
6650
6651 \end_inset
6652
6653
6654 \end_layout
6655
6656 \begin_layout List
6657 \labelwidthstring 00.00.0000
6658
6659 \series bold
6660 -mpic16
6661 \begin_inset LatexCommand \index{-mpic16}
6662
6663 \end_inset
6664
6665
6666 \series default
6667  Generate code for the Microchip PIC 16
6668 \begin_inset LatexCommand \index{PIC16}
6669
6670 \end_inset
6671
6672 -bit processors (p18f452 and variants.
6673  In development, not complete).
6674 \end_layout
6675
6676 \begin_layout List
6677 \labelwidthstring 00.00.0000
6678
6679 \series bold
6680 -mtlcs900h
6681 \series default
6682  Generate code for the Toshiba TLCS-900H
6683 \begin_inset LatexCommand \index{TLCS-900H}
6684
6685 \end_inset
6686
6687  processor (Not maintained, not complete).
6688 \end_layout
6689
6690 \begin_layout List
6691 \labelwidthstring 00.00.0000
6692
6693 \series bold
6694 -mxa51
6695 \begin_inset LatexCommand \index{-mxa51}
6696
6697 \end_inset
6698
6699
6700 \series default
6701  Generate code for the Phillips XA51
6702 \begin_inset LatexCommand \index{XA51}
6703
6704 \end_inset
6705
6706  processor (Not maintained, not complete).
6707 \end_layout
6708
6709 \begin_layout Standard
6710 \begin_inset VSpace bigskip
6711 \end_inset
6712
6713
6714 \end_layout
6715
6716 \begin_layout Subsection
6717 Preprocessor Options
6718 \begin_inset LatexCommand \index{Options preprocessor}
6719
6720 \end_inset
6721
6722
6723 \begin_inset LatexCommand \index{Preprocessor options}
6724
6725 \end_inset
6726
6727
6728 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6729
6730 \end_inset
6731
6732
6733 \end_layout
6734
6735 \begin_layout List
6736 \labelwidthstring 00.00.0000
6737
6738 \series bold
6739 -I<path>
6740 \begin_inset LatexCommand \index{-I<path>}
6741
6742 \end_inset
6743
6744
6745 \series default
6746  The additional location where the preprocessor will look for <..h> or 
6747 \begin_inset Quotes eld
6748 \end_inset
6749
6750 ..h
6751 \begin_inset Quotes erd
6752 \end_inset
6753
6754  files.
6755 \end_layout
6756
6757 \begin_layout List
6758 \labelwidthstring 00.00.0000
6759
6760 \series bold
6761 -D<macro[=value]>
6762 \begin_inset LatexCommand \index{-D<macro[=value]>}
6763
6764 \end_inset
6765
6766
6767 \series default
6768  Command line definition of macros.
6769  Passed to the preprocessor.
6770 \end_layout
6771
6772 \begin_layout List
6773 \labelwidthstring 00.00.0000
6774
6775 \series bold
6776 -M
6777 \begin_inset LatexCommand \index{-M}
6778
6779 \end_inset
6780
6781
6782 \series default
6783  Tell the preprocessor to output a rule suitable for make describing the
6784  dependencies of each object file.
6785  For each source file, the preprocessor outputs one make-rule whose target
6786  is the object file name for that source file and whose dependencies are
6787  all the files `#include'd in it.
6788  This rule may be a single line or may be continued with `
6789 \backslash
6790 '-newline if it is long.
6791  The list of rules is printed on standard output instead of the preprocessed
6792  C program.
6793  `-M' implies `-E
6794 \begin_inset LatexCommand \index{-E}
6795
6796 \end_inset
6797
6798 '.
6799 \end_layout
6800
6801 \begin_layout List
6802 \labelwidthstring 00.00.0000
6803
6804 \series bold
6805 -C
6806 \begin_inset LatexCommand \index{-C}
6807
6808 \end_inset
6809
6810
6811 \series default
6812  Tell the preprocessor not to discard comments.
6813  Used with the `-E' option.
6814 \end_layout
6815
6816 \begin_layout List
6817 \labelwidthstring 00.00.0000
6818
6819 \series bold
6820 -MM
6821 \begin_inset LatexCommand \index{-MM}
6822
6823 \end_inset
6824
6825
6826 \size large
6827 \bar under
6828  
6829 \series default
6830 \size default
6831 \bar default
6832 Like `-M' but the output mentions only the user header files included with
6833  `#include 
6834 \begin_inset Quotes eld
6835 \end_inset
6836
6837 file"'.
6838  System header files included with `#include <file>' are omitted.
6839 \end_layout
6840
6841 \begin_layout List
6842 \labelwidthstring 00.00.0000
6843
6844 \series bold
6845 -Aquestion(answer)
6846 \begin_inset LatexCommand \index{-Aquestion(answer)}
6847
6848 \end_inset
6849
6850
6851 \series default
6852  Assert the answer answer for question, in case it is tested with a preprocessor
6853  conditional such as `#if #question(answer)'.
6854  `-A-' disables the standard assertions that normally describe the target
6855  machine.
6856 \end_layout
6857
6858 \begin_layout List
6859 \labelwidthstring 00.00.0000
6860
6861 \series bold
6862 -Umacro
6863 \begin_inset LatexCommand \index{-Umacro}
6864
6865 \end_inset
6866
6867
6868 \series default
6869  Undefine macro macro.
6870  `-U' options are evaluated after all `-D' options, but before any `-include'
6871  and `-imacros' options.
6872 \end_layout
6873
6874 \begin_layout List
6875 \labelwidthstring 00.00.0000
6876
6877 \series bold
6878 -dM
6879 \begin_inset LatexCommand \index{-dM}
6880
6881 \end_inset
6882
6883
6884 \series default
6885  Tell the preprocessor to output only a list of the macro definitions that
6886  are in effect at the end of preprocessing.
6887  Used with the `-E' option.
6888 \end_layout
6889
6890 \begin_layout List
6891 \labelwidthstring 00.00.0000
6892
6893 \series bold
6894 -dD
6895 \begin_inset LatexCommand \index{-dD}
6896
6897 \end_inset
6898
6899
6900 \series default
6901  Tell the preprocessor to pass all macro definitions into the output, in
6902  their proper sequence in the rest of the output.
6903 \end_layout
6904
6905 \begin_layout List
6906 \labelwidthstring 00.00.0000
6907
6908 \series bold
6909 -dN
6910 \begin_inset LatexCommand \index{-dN}
6911
6912 \end_inset
6913
6914
6915 \size large
6916 \bar under
6917  
6918 \series default
6919 \size default
6920 \bar default
6921 Like `-dD' except that the macro arguments and contents are omitted.
6922  Only `#define name' is included in the output.
6923 \end_layout
6924
6925 \begin_layout List
6926 \labelwidthstring 00.00.0000
6927
6928 \series bold
6929 -pedantic-parse-number
6930 \begin_inset LatexCommand \index{pedantic}
6931
6932 \end_inset
6933
6934
6935 \begin_inset LatexCommand \index{-pedantic-parse-number}
6936
6937 \end_inset
6938
6939
6940 \size large
6941 \bar under
6942
6943 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
6944
6945 \end_inset
6946
6947  
6948 \series default
6949 \size default
6950 \bar default
6951 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6952  and the macro LO_B(3) gets expanded.
6953  See also #pragma pedantic_parse_number 
6954 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
6955
6956 \end_inset
6957
6958  in section
6959 \begin_inset LatexCommand \ref{sec:Pragmas}
6960
6961 \end_inset
6962
6963  
6964 \emph on
6965 Note: this functionality is not in conformance with 
6966 \begin_inset Note Note
6967 status collapsed
6968
6969 \begin_layout Standard
6970 which standard? C99? 
6971 \end_layout
6972
6973 \end_inset
6974
6975 standard!
6976 \end_layout
6977
6978 \begin_layout List
6979 \labelwidthstring 00.00.0000
6980
6981 \series bold
6982 -Wp\InsetSpace ~
6983 preprocessorOption[,preprocessorOption]
6984 \series default
6985
6986 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6987
6988 \end_inset
6989
6990 ...
6991  Pass the preprocessorOption to the preprocessor 
6992 \family typewriter
6993 sdcpp
6994 \family default
6995
6996 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6997
6998 \end_inset
6999
7000 .
7001  SDCC uses an adapted version of the preprocessor 
7002 \emph on
7003 cpp
7004 \emph default
7005  of the GNU Compiler Collection
7006 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7007
7008 \end_inset
7009
7010  (
7011 \emph on
7012 gcc
7013 \emph default
7014  
7015 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7016
7017 \end_inset
7018
7019 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7020 4.1.1\InsetSpace ~
7021 CPP\InsetSpace ~
7022 Manual
7023  at 
7024 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7025
7026 \end_inset
7027
7028 .
7029 \end_layout
7030
7031 \begin_layout Standard
7032 \begin_inset VSpace bigskip
7033 \end_inset
7034
7035
7036 \end_layout
7037
7038 \begin_layout Subsection
7039 Linker Options
7040 \begin_inset LatexCommand \index{Options linker}
7041
7042 \end_inset
7043
7044
7045 \begin_inset LatexCommand \index{Linker options}
7046
7047 \end_inset
7048
7049
7050 \end_layout
7051
7052 \begin_layout List
7053 \labelwidthstring 00.00.0000
7054
7055 \series bold
7056 -L\InsetSpace ~
7057 -
7058 \series default
7059
7060 \begin_inset ERT
7061 status collapsed
7062
7063 \begin_layout Standard
7064
7065
7066 \backslash
7067 /
7068 \end_layout
7069
7070 \end_inset
7071
7072
7073 \series bold
7074 -lib-path
7075 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7076
7077 \end_inset
7078
7079
7080 \begin_inset LatexCommand \index{-L -\/-lib-path}
7081
7082 \end_inset
7083
7084
7085 \series default
7086 \InsetSpace ~
7087 <absolute path to additional libraries> This option is passed to the linkage
7088  editor's additional libraries
7089 \begin_inset LatexCommand \index{Libraries}
7090
7091 \end_inset
7092
7093  search path.
7094  The path name must be absolute.
7095  Additional library files may be specified in the command line.
7096  See section Compiling programs for more details.
7097 \end_layout
7098
7099 \begin_layout List
7100 \labelwidthstring 00.00.0000
7101
7102 \series bold
7103 -
7104 \begin_inset ERT
7105 status collapsed
7106
7107 \begin_layout Standard
7108
7109
7110 \backslash
7111 /
7112 \end_layout
7113
7114 \end_inset
7115
7116 -xram-loc
7117 \series default
7118
7119 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7120
7121 \end_inset
7122
7123 \InsetSpace ~
7124 <Value> The start location of the external ram
7125 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7126
7127 \end_inset
7128
7129 , default value is 0.
7130  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7131 \begin_inset ERT
7132 status collapsed
7133
7134 \begin_layout Standard
7135
7136
7137 \backslash
7138 /
7139 \end_layout
7140
7141 \end_inset
7142
7143 -xram-loc 0x8000 or -
7144 \begin_inset ERT
7145 status collapsed
7146
7147 \begin_layout Standard
7148
7149
7150 \backslash
7151 /
7152 \end_layout
7153
7154 \end_inset
7155
7156 -xram-loc 32768.
7157 \end_layout
7158
7159 \begin_layout List
7160 \labelwidthstring 00.00.0000
7161
7162 \series bold
7163 -
7164 \begin_inset ERT
7165 status collapsed
7166
7167 \begin_layout Standard
7168
7169
7170 \backslash
7171 /
7172 \end_layout
7173
7174 \end_inset
7175
7176 -code-loc
7177 \series default
7178
7179 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7180
7181 \end_inset
7182
7183 \InsetSpace ~
7184 <Value> The start location of the code
7185 \begin_inset LatexCommand \index{code}
7186
7187 \end_inset
7188
7189  segment, default value 0.
7190  Note when this option is used the interrupt vector table
7191 \begin_inset LatexCommand \index{interrupt vector table}
7192
7193 \end_inset
7194
7195  is also relocated to the given address.
7196  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7197 \begin_inset ERT
7198 status collapsed
7199
7200 \begin_layout Standard
7201
7202
7203 \backslash
7204 /
7205 \end_layout
7206
7207 \end_inset
7208
7209 -code-loc 0x8000 or -
7210 \begin_inset ERT
7211 status collapsed
7212
7213 \begin_layout Standard
7214
7215
7216 \backslash
7217 /
7218 \end_layout
7219
7220 \end_inset
7221
7222 -code-loc 32768.
7223 \end_layout
7224
7225 \begin_layout List
7226 \labelwidthstring 00.00.0000
7227
7228 \series bold
7229 -
7230 \begin_inset ERT
7231 status collapsed
7232
7233 \begin_layout Standard
7234
7235
7236 \backslash
7237 /
7238 \end_layout
7239
7240 \end_inset
7241
7242 -stack-loc
7243 \series default
7244
7245 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7246
7247 \end_inset
7248
7249 \InsetSpace ~
7250 <Value> By default the stack
7251 \begin_inset LatexCommand \index{stack}
7252
7253 \end_inset
7254
7255  is placed after the data segment.
7256  Using this option the stack can be placed anywhere in the internal memory
7257  space of the 8051.
7258  The value entered can be in Hexadecimal or Decimal format, e.g.
7259  -
7260 \begin_inset ERT
7261 status collapsed
7262
7263 \begin_layout Standard
7264
7265
7266 \backslash
7267 /
7268 \end_layout
7269
7270 \end_inset
7271
7272 -stack-loc 0x20 or -
7273 \begin_inset ERT
7274 status collapsed
7275
7276 \begin_layout Standard
7277
7278
7279 \backslash
7280 /
7281 \end_layout
7282
7283 \end_inset
7284
7285 -stack-loc 32.
7286  Since the sp register is incremented before a push or call, the initial
7287  sp will be set to one byte prior the provided value.
7288  The provided value should not overlap any other memory areas such as used
7289  register banks or the data segment and with enough space for the current
7290  application.
7291  The 
7292 \series bold
7293 -
7294 \begin_inset ERT
7295 status collapsed
7296
7297 \begin_layout Standard
7298
7299
7300 \backslash
7301 /
7302 \end_layout
7303
7304 \end_inset
7305
7306 -pack-iram
7307 \series default
7308 \InsetSpace ~
7309
7310 \begin_inset LatexCommand \index{-\/-pack-iram}
7311
7312 \end_inset
7313
7314  option (which is now a default setting) will override this setting, so
7315  you should also specify the 
7316 \series bold
7317 -
7318 \begin_inset ERT
7319 status collapsed
7320
7321 \begin_layout Standard
7322
7323
7324 \backslash
7325 /
7326 \end_layout
7327
7328 \end_inset
7329
7330 -no-pack-iram
7331 \series default
7332 \InsetSpace ~
7333
7334 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7335
7336 \end_inset
7337
7338  option if you need to manually place the stack.
7339 \end_layout
7340
7341 \begin_layout List
7342 \labelwidthstring 00.00.0000
7343
7344 \series bold
7345 -
7346 \begin_inset ERT
7347 status collapsed
7348
7349 \begin_layout Standard
7350
7351
7352 \backslash
7353 /
7354 \end_layout
7355
7356 \end_inset
7357
7358 -xstack-loc
7359 \series default
7360
7361 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7362
7363 \end_inset
7364
7365 \InsetSpace ~
7366 <Value> By default the external stack
7367 \begin_inset LatexCommand \index{xstack}
7368
7369 \end_inset
7370
7371  is placed after the pdata
7372 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7373
7374 \end_inset
7375
7376  segment.
7377  Using this option the xstack can be placed anywhere in the external memory
7378  space of the 8051.
7379  The value entered can be in Hexadecimal or Decimal format, e.g.
7380  -
7381 \begin_inset ERT
7382 status collapsed
7383
7384 \begin_layout Standard
7385
7386
7387 \backslash
7388 /
7389 \end_layout
7390
7391 \end_inset
7392
7393 -xstack-loc 0x8000 or -
7394 \begin_inset ERT
7395 status collapsed
7396
7397 \begin_layout Standard
7398
7399
7400 \backslash
7401 /
7402 \end_layout
7403
7404 \end_inset
7405
7406 -stack-loc 32768.
7407  The provided value should not overlap any other memory areas such as the
7408  pdata or xdata segment and with enough space for the current application.
7409 \end_layout
7410
7411 \begin_layout List
7412 \labelwidthstring 00.00.0000
7413
7414 \series bold
7415 -
7416 \begin_inset ERT
7417 status collapsed
7418
7419 \begin_layout Standard
7420
7421
7422 \backslash
7423 /
7424 \end_layout
7425
7426 \end_inset
7427
7428 -data-loc
7429 \series default
7430
7431 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7432
7433 \end_inset
7434
7435 \InsetSpace ~
7436 <Value> The start location of the internal ram data
7437 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7438
7439 \end_inset
7440
7441  segment.
7442  The value entered can be in Hexadecimal or Decimal format, eg.
7443  -
7444 \begin_inset ERT
7445 status collapsed
7446
7447 \begin_layout Standard
7448
7449
7450 \backslash
7451 /
7452 \end_layout
7453
7454 \end_inset
7455
7456 -data-loc 0x20 or -
7457 \begin_inset ERT
7458 status collapsed
7459
7460 \begin_layout Standard
7461
7462
7463 \backslash
7464 /
7465 \end_layout
7466
7467 \end_inset
7468
7469 -data-loc 32.
7470  (By default, the start location of the internal ram data segment  is set
7471  as low as possible in memory, taking into account the used register banks
7472  and the bit segment at address 0x20.
7473  For example if register banks 0 and 1 are used without bit variables, the
7474  data segment will be set, if -
7475 \begin_inset ERT
7476 status collapsed
7477
7478 \begin_layout Standard
7479
7480
7481 \backslash
7482 /
7483 \end_layout
7484
7485 \end_inset
7486
7487 -data-loc is not used, to location 0x10.)
7488 \end_layout
7489
7490 \begin_layout List
7491 \labelwidthstring 00.00.0000
7492
7493 \series bold
7494 -
7495 \begin_inset ERT
7496 status collapsed
7497
7498 \begin_layout Standard
7499
7500
7501 \backslash
7502 /
7503 \end_layout
7504
7505 \end_inset
7506
7507 -idata-loc
7508 \series default
7509
7510 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7511
7512 \end_inset
7513
7514 \InsetSpace ~
7515 <Value> The start location of the indirectly addressable internal ram
7516 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7517
7518 \end_inset
7519
7520  of the 8051, default value is 0x80.
7521  The value entered can be in Hexadecimal or Decimal format, eg.
7522  -
7523 \begin_inset ERT
7524 status collapsed
7525
7526 \begin_layout Standard
7527
7528
7529 \backslash
7530 /
7531 \end_layout
7532
7533 \end_inset
7534
7535 -idata-loc 0x88 or -
7536 \begin_inset ERT
7537 status collapsed
7538
7539 \begin_layout Standard
7540
7541
7542 \backslash
7543 /
7544 \end_layout
7545
7546 \end_inset
7547
7548 -idata-loc 136.
7549 \end_layout
7550
7551 \begin_layout List
7552 \labelwidthstring 00.00.0000
7553
7554 \series bold
7555 -
7556 \begin_inset ERT
7557 status collapsed
7558
7559 \begin_layout Standard
7560
7561
7562 \backslash
7563 /
7564 \end_layout
7565
7566 \end_inset
7567
7568 -bit-loc
7569 \series default
7570 \InsetSpace ~
7571 <Value> The start location of the bit
7572 \begin_inset LatexCommand \index{bit}
7573
7574 \end_inset
7575
7576  addressable internal ram of the 8051.
7577  This is 
7578 \emph on
7579 not
7580 \emph default
7581  implemented yet.
7582  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7583 -bBSEG=<Value>.
7584 \end_layout
7585
7586 \begin_layout List
7587 \labelwidthstring 00.00.0000
7588
7589 \series bold
7590 -
7591 \begin_inset ERT
7592 status collapsed
7593
7594 \begin_layout Standard
7595
7596
7597 \backslash
7598 /
7599 \end_layout
7600
7601 \end_inset
7602
7603 -out-fmt-ihx
7604 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7605
7606 \end_inset
7607
7608
7609 \bar under
7610  
7611 \series default
7612 \bar default
7613 The linker output (final object code) is in Intel Hex format.
7614 \begin_inset LatexCommand \index{Intel hex format}
7615
7616 \end_inset
7617
7618  This is the default option.
7619  The format itself is documented in the documentation of srecord
7620 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7621
7622 \end_inset
7623
7624 .
7625 \end_layout
7626
7627 \begin_layout List
7628 \labelwidthstring 00.00.0000
7629
7630 \series bold
7631 -
7632 \begin_inset ERT
7633 status collapsed
7634
7635 \begin_layout Standard
7636
7637
7638 \backslash
7639 /
7640 \end_layout
7641
7642 \end_inset
7643
7644 -out-fmt-s19
7645 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7646
7647 \end_inset
7648
7649
7650 \bar under
7651  
7652 \series default
7653 \bar default
7654 The linker output (final object code) is in Motorola S19 format
7655 \begin_inset LatexCommand \index{Motorola S19 format}
7656
7657 \end_inset
7658
7659 .
7660  The format itself is documented in the documentation of srecord.
7661 \end_layout
7662
7663 \begin_layout List
7664 \labelwidthstring 00.00.0000
7665
7666 \series bold
7667 -
7668 \begin_inset ERT
7669 status collapsed
7670
7671 \begin_layout Standard
7672
7673
7674 \backslash
7675 /
7676 \end_layout
7677
7678 \end_inset
7679
7680 -out-fmt-elf
7681 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7682
7683 \end_inset
7684
7685
7686 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7687
7688 \end_inset
7689
7690
7691 \bar under
7692  
7693 \series default
7694 \bar default
7695 The linker output (final object code) is in ELF format
7696 \begin_inset LatexCommand \index{ELF format}
7697
7698 \end_inset
7699
7700 .
7701  (Currently only supported for the HC08
7702 \begin_inset LatexCommand \index{HC08}
7703
7704 \end_inset
7705
7706  processors)
7707 \end_layout
7708
7709 \begin_layout List
7710 \labelwidthstring 00.00.0000
7711
7712 \series bold
7713 -Wl\InsetSpace ~
7714 linkOption[,linkOption]
7715 \series default
7716
7717 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7718
7719 \end_inset
7720
7721 ...
7722  Pass the linkOption to the linker.
7723  If a bootloader is used an option like 
7724 \begin_inset Quotes sld
7725 \end_inset
7726
7727 -Wl\InsetSpace ~
7728 -bCSEG=0x1000
7729 \begin_inset Quotes srd
7730 \end_inset
7731
7732  would be typical to set the start of the code segment.
7733  See also #pragma constseg and #pragma codeseg in section 
7734 \begin_inset LatexCommand \ref{sec:Pragmas}
7735
7736 \end_inset
7737
7738  .
7739  File sdcc/as/doc/asxhtm.html has more on linker options.
7740 \end_layout
7741
7742 \begin_layout Standard
7743 \begin_inset VSpace bigskip
7744 \end_inset
7745
7746
7747 \end_layout
7748
7749 \begin_layout Subsection
7750 MCS51 Options
7751 \begin_inset LatexCommand \index{Options MCS51}
7752
7753 \end_inset
7754
7755
7756 \begin_inset LatexCommand \index{MCS51 options}
7757
7758 \end_inset
7759
7760
7761 \end_layout
7762
7763 \begin_layout List
7764 \labelwidthstring 00.00.0000
7765
7766 \series bold
7767 -
7768 \begin_inset ERT
7769 status collapsed
7770
7771 \begin_layout Standard
7772
7773
7774 \backslash
7775 /
7776 \end_layout
7777
7778 \end_inset
7779
7780 -model-small
7781 \begin_inset LatexCommand \index{-\/-model-small}
7782
7783 \end_inset
7784
7785
7786 \series default
7787 \size large
7788 \emph on
7789  
7790 \size default
7791 \emph default
7792 Generate code for Small Model programs, see section Memory Models for more
7793  details.
7794  This is the default model.
7795 \end_layout
7796
7797 \begin_layout List
7798 \labelwidthstring 00.00.0000
7799
7800 \series bold
7801 -
7802 \begin_inset ERT
7803 status collapsed
7804
7805 \begin_layout Standard
7806
7807
7808 \backslash
7809 /
7810 \end_layout
7811
7812 \end_inset
7813
7814 -model-medium
7815 \begin_inset LatexCommand \index{-\/-model-medium}
7816
7817 \end_inset
7818
7819
7820 \series default
7821  Generate code for Medium model programs, see section Memory Models for
7822  more details.
7823  If this option is used all source files in the project have to be compiled
7824  with this option.
7825  It must also be used when invoking the linker.
7826 \end_layout
7827
7828 \begin_layout List
7829 \labelwidthstring 00.00.0000
7830
7831 \series bold
7832 -
7833 \begin_inset ERT
7834 status collapsed
7835
7836 \begin_layout Standard
7837
7838
7839 \backslash
7840 /
7841 \end_layout
7842
7843 \end_inset
7844
7845 -model-large
7846 \begin_inset LatexCommand \index{-\/-model-large}
7847
7848 \end_inset
7849
7850
7851 \series default
7852  Generate code for Large model programs, see section Memory Models for more
7853  details.
7854  If this option is used all source files in the project have to be compiled
7855  with this option.
7856  It must also be used when invoking the linker.
7857 \end_layout
7858
7859 \begin_layout List
7860 \labelwidthstring 00.00.0000
7861
7862 \series bold
7863 -
7864 \begin_inset ERT
7865 status collapsed
7866
7867 \begin_layout Standard
7868
7869
7870 \backslash
7871 /
7872 \end_layout
7873
7874 \end_inset
7875
7876 -xstack
7877 \begin_inset LatexCommand \index{-\/-xstack}
7878
7879 \end_inset
7880
7881
7882 \series default
7883  Uses a pseudo stack in the pdata
7884 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7885
7886 \end_inset
7887
7888  area (usually the first 256 bytes in the external ram) for allocating variables
7889  and passing parameters.
7890  See section 
7891 \begin_inset LatexCommand \ref{sub:External-Stack}
7892
7893 \end_inset
7894
7895 \InsetSpace ~
7896  External Stack for more details.
7897 \end_layout
7898
7899 \begin_layout List
7900 \labelwidthstring 00.00.0000
7901
7902 \series bold
7903 -
7904 \begin_inset ERT
7905 status collapsed
7906
7907 \begin_layout Standard
7908
7909
7910 \backslash
7911 /
7912 \end_layout
7913
7914 \end_inset
7915
7916 -iram-size
7917 \series default
7918 \InsetSpace ~
7919 <Value>
7920 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7921
7922 \end_inset
7923
7924  Causes the linker to check if the internal ram usage is within limits of
7925  the given value.
7926 \end_layout
7927
7928 \begin_layout List
7929 \labelwidthstring 00.00.0000
7930
7931 \series bold
7932 -
7933 \begin_inset ERT
7934 status collapsed
7935
7936 \begin_layout Standard
7937
7938
7939 \backslash
7940 /
7941 \end_layout
7942
7943 \end_inset
7944
7945 -xram-size
7946 \series default
7947 \InsetSpace ~
7948 <Value>
7949 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7950
7951 \end_inset
7952
7953  Causes the linker to check if the external ram usage is within limits of
7954  the given value.
7955 \end_layout
7956
7957 \begin_layout List
7958 \labelwidthstring 00.00.0000
7959
7960 \series bold
7961 -
7962 \begin_inset ERT
7963 status collapsed
7964
7965 \begin_layout Standard
7966
7967
7968 \backslash
7969 /
7970 \end_layout
7971
7972 \end_inset
7973
7974 -code-size
7975 \series default
7976 \InsetSpace ~
7977 <Value>
7978 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7979
7980 \end_inset
7981
7982  Causes the linker to check if the code memory usage is within limits of
7983  the given value.
7984 \end_layout
7985
7986 \begin_layout List
7987 \labelwidthstring 00.00.0000
7988
7989 \series bold
7990 -
7991 \begin_inset ERT
7992 status collapsed
7993
7994 \begin_layout Standard
7995
7996
7997 \backslash
7998 /
7999 \end_layout
8000
8001 \end_inset
8002
8003 -stack-size
8004 \series default
8005 \InsetSpace ~
8006 <Value>
8007 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8008
8009 \end_inset
8010
8011  Causes the linker to check if there is at minimum <Value> bytes for stack.
8012 \end_layout
8013
8014 \begin_layout List
8015 \labelwidthstring 00.00.0000
8016
8017 \series bold
8018 -
8019 \begin_inset ERT
8020 status collapsed
8021
8022 \begin_layout Standard
8023
8024
8025 \backslash
8026 /
8027 \end_layout
8028
8029 \end_inset
8030
8031 -pack-iram
8032 \series default
8033 \InsetSpace ~
8034
8035 \begin_inset LatexCommand \index{-\/-pack-iram}
8036
8037 \end_inset
8038
8039  Causes the linker to use unused register banks for data variables and pack
8040  data, idata and stack together.
8041  This is the default now.
8042 \end_layout
8043
8044 \begin_layout List
8045 \labelwidthstring 00.00.0000
8046
8047 \series bold
8048 -
8049 \begin_inset ERT
8050 status collapsed
8051
8052 \begin_layout Standard
8053
8054
8055 \backslash
8056 /
8057 \end_layout
8058
8059 \end_inset
8060
8061 -no-pack-iram
8062 \series default
8063 \InsetSpace ~
8064
8065 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8066
8067 \end_inset
8068
8069  Causes the linker to use old style for allocating memory areas.
8070 \end_layout
8071
8072 \begin_layout Standard
8073 \begin_inset VSpace bigskip
8074 \end_inset
8075
8076
8077 \end_layout
8078
8079 \begin_layout Subsection
8080 DS390 / DS400 Options
8081 \begin_inset LatexCommand \index{Options DS390}
8082
8083 \end_inset
8084
8085
8086 \begin_inset LatexCommand \index{DS390}
8087
8088 \end_inset
8089
8090
8091 \end_layout
8092
8093 \begin_layout List
8094 \labelwidthstring 00.00.0000
8095
8096 \series bold
8097 -
8098 \begin_inset ERT
8099 status collapsed
8100
8101 \begin_layout Standard
8102
8103
8104 \backslash
8105 /
8106 \end_layout
8107
8108 \end_inset
8109
8110 -model-flat24
8111 \series default
8112
8113 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8114
8115 \end_inset
8116
8117
8118 \size large
8119 \emph on
8120  
8121 \size default
8122 \emph default
8123 Generate 24-bit flat mode code.
8124  This is the one and only that the ds390 code generator supports right now
8125  and is default when using 
8126 \emph on
8127 -mds390
8128 \emph default
8129 .
8130  See section Memory Models for more details.
8131 \end_layout
8132
8133 \begin_layout List
8134 \labelwidthstring 00.00.0000
8135
8136 \series bold
8137 -
8138 \begin_inset ERT
8139 status collapsed
8140
8141 \begin_layout Standard
8142
8143
8144 \backslash
8145 /
8146 \end_layout
8147
8148 \end_inset
8149
8150 -protect-sp-update
8151 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8152
8153 \end_inset
8154
8155
8156 \series default
8157  disable interrupts during ESP:SP updates.
8158 \end_layout
8159
8160 \begin_layout List
8161 \labelwidthstring 00.00.0000
8162
8163 \series bold
8164 -
8165 \begin_inset ERT
8166 status collapsed
8167
8168 \begin_layout Standard
8169
8170
8171 \backslash
8172 /
8173 \end_layout
8174
8175 \end_inset
8176
8177 -stack-10bit
8178 \series default
8179
8180 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8181
8182 \end_inset
8183
8184  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8185  This is the one and only that the ds390 code generator supports right now
8186  and is default when using 
8187 \emph on
8188 -mds390
8189 \emph default
8190 .
8191  In this mode, the stack is located in the lower 1K of the internal RAM,
8192  which is mapped to 0x400000.
8193  Note that the support is incomplete, since it still uses a single byte
8194  as the stack pointer.
8195  This means that only the lower 256 bytes of the potential 1K stack space
8196  will actually be used.
8197  However, this does allow you to reclaim the precious 256 bytes of low RAM
8198  for use for the DATA and IDATA segments.
8199  The compiler will not generate any code to put the processor into 10 bit
8200  stack mode.
8201  It is important to ensure that the processor is in this mode before calling
8202  any re-entrant functions compiled with this option.
8203  In principle, this should work with the 
8204 \emph on
8205 -
8206 \begin_inset ERT
8207 status collapsed
8208
8209 \begin_layout Standard
8210
8211
8212 \backslash
8213 /
8214 \end_layout
8215
8216 \end_inset
8217
8218 -stack-auto
8219 \begin_inset LatexCommand \index{-\/-stack-auto}
8220
8221 \end_inset
8222
8223
8224 \emph default
8225  option, but that has not been tested.
8226  It is incompatible with the 
8227 \emph on
8228 -
8229 \begin_inset ERT
8230 status collapsed
8231
8232 \begin_layout Standard
8233
8234
8235 \backslash
8236 /
8237 \end_layout
8238
8239 \end_inset
8240
8241 -xstack
8242 \begin_inset LatexCommand \index{-\/-xstack}
8243
8244 \end_inset
8245
8246
8247 \emph default
8248  option.
8249  It also only makes sense if the processor is in 24 bit contiguous addressing
8250  mode (see the 
8251 \emph on
8252 -
8253 \begin_inset ERT
8254 status collapsed
8255
8256 \begin_layout Standard
8257
8258
8259 \backslash
8260 /
8261 \end_layout
8262
8263 \end_inset
8264
8265 -model-flat24 option
8266 \emph default
8267 ).
8268 \series bold
8269
8270 \begin_inset Note Note
8271 status collapsed
8272
8273 \begin_layout List
8274 \labelwidthstring 00.00.0000
8275
8276 \series bold
8277 --stack-8-bit - switches off the 10-bit mode
8278 \end_layout
8279
8280 \end_inset
8281
8282
8283 \end_layout
8284
8285 \begin_layout List
8286 \labelwidthstring 00.00.0000
8287
8288 \series bold
8289 -
8290 \begin_inset ERT
8291 status collapsed
8292
8293 \begin_layout Standard
8294
8295
8296 \backslash
8297 /
8298 \end_layout
8299
8300 \end_inset
8301
8302 -stack-probe
8303 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8304
8305 \end_inset
8306
8307
8308 \series default
8309  insert call to function __stack_probe at each function prologue.
8310 \end_layout
8311
8312 \begin_layout List
8313 \labelwidthstring 00.00.0000
8314
8315 \series bold
8316 -
8317 \begin_inset ERT
8318 status collapsed
8319
8320 \begin_layout Standard
8321
8322
8323 \backslash
8324 /
8325 \end_layout
8326
8327 \end_inset
8328
8329 -tini-libid
8330 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8331
8332 \end_inset
8333
8334
8335 \series default
8336  <nnnn> LibraryID used in -mTININative.
8337  
8338 \end_layout
8339
8340 \begin_layout List
8341 \labelwidthstring 00.00.0000
8342
8343 \series bold
8344 -
8345 \begin_inset ERT
8346 status collapsed
8347
8348 \begin_layout Standard
8349
8350
8351 \backslash
8352 /
8353 \end_layout
8354
8355 \end_inset
8356
8357 -use-accelerator
8358 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8359
8360 \end_inset
8361
8362
8363 \series default
8364  generate code for DS390 Arithmetic Accelerator.
8365  
8366 \end_layout
8367
8368 \begin_layout Standard
8369 \begin_inset VSpace bigskip
8370 \end_inset
8371
8372
8373 \end_layout
8374
8375 \begin_layout Subsection
8376 Z80 Options
8377 \begin_inset LatexCommand \index{Options Z80}
8378
8379 \end_inset
8380
8381
8382 \begin_inset LatexCommand \index{Z80}
8383
8384 \end_inset
8385
8386
8387 \end_layout
8388
8389 \begin_layout List
8390 \labelwidthstring 00.00.0000
8391
8392 \series bold
8393 -
8394 \begin_inset ERT
8395 status collapsed
8396
8397 \begin_layout Standard
8398
8399
8400 \backslash
8401 /
8402 \end_layout
8403
8404 \end_inset
8405
8406 -callee-saves-bc
8407 \series default
8408
8409 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8410
8411 \end_inset
8412
8413
8414 \size large
8415 \emph on
8416  
8417 \size default
8418 \emph default
8419 Force a called function to always save BC.
8420 \end_layout
8421
8422 \begin_layout List
8423 \labelwidthstring 00.00.0000
8424
8425 \series bold
8426 -
8427 \begin_inset ERT
8428 status collapsed
8429
8430 \begin_layout Standard
8431
8432
8433 \backslash
8434 /
8435 \end_layout
8436
8437 \end_inset
8438
8439 -no-std-crt0
8440 \series default
8441
8442 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8443
8444 \end_inset
8445
8446  When linking, skip the standard crt0.o object file.
8447  You must provide your own crt0.o for your system when linking.
8448  
8449 \end_layout
8450
8451 \begin_layout Standard
8452 \begin_inset VSpace bigskip
8453 \end_inset
8454
8455
8456 \end_layout
8457
8458 \begin_layout Subsection
8459 Optimization Options
8460 \begin_inset LatexCommand \index{Options optimization}
8461
8462 \end_inset
8463
8464
8465 \begin_inset LatexCommand \index{Optimization options}
8466
8467 \end_inset
8468
8469
8470 \end_layout
8471
8472 \begin_layout List
8473 \labelwidthstring 00.00.0000
8474
8475 \series bold
8476 -
8477 \begin_inset ERT
8478 status collapsed
8479
8480 \begin_layout Standard
8481
8482
8483 \backslash
8484 /
8485 \end_layout
8486
8487 \end_inset
8488
8489 -nogcse
8490 \begin_inset LatexCommand \index{-\/-nogcse}
8491
8492 \end_inset
8493
8494
8495 \series default
8496  Will not do global subexpression elimination, this option may be used when
8497  the compiler creates undesirably large stack/data spaces to store compiler
8498  temporaries (
8499 \emph on
8500 s
8501 \emph default
8502 pill 
8503 \emph on
8504 loc
8505 \emph default
8506 ations, sloc
8507 \begin_inset LatexCommand \index{sloc (spill location)}
8508
8509 \end_inset
8510
8511 ).
8512  A warning message will be generated when this happens and the compiler
8513  will indicate the number of extra bytes it allocated.
8514  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8515 nogcse
8516 \begin_inset LatexCommand \index{\#pragma nogcse}
8517
8518 \end_inset
8519
8520  can be used to turn off global subexpression elimination
8521 \begin_inset LatexCommand \index{Subexpression elimination}
8522
8523 \end_inset
8524
8525  for a given function only.
8526 \end_layout
8527
8528 \begin_layout List
8529 \labelwidthstring 00.00.0000
8530
8531 \series bold
8532 -
8533 \begin_inset ERT
8534 status collapsed
8535
8536 \begin_layout Standard
8537
8538
8539 \backslash
8540 /
8541 \end_layout
8542
8543 \end_inset
8544
8545 -noinvariant
8546 \begin_inset LatexCommand \index{-\/-noinvariant}
8547
8548 \end_inset
8549
8550
8551 \series default
8552  Will not do loop invariant optimizations, this may be turned off for reasons
8553  explained for the previous option.
8554  For more details of loop optimizations performed see Loop Invariants in
8555  section 
8556 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8557
8558 \end_inset
8559
8560 .
8561  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8562 noinvariant
8563 \begin_inset LatexCommand \index{\#pragma noinvariant}
8564
8565 \end_inset
8566
8567  can be used to turn off invariant optimizations for a given function only.
8568 \end_layout
8569
8570 \begin_layout List
8571 \labelwidthstring 00.00.0000
8572
8573 \series bold
8574 -
8575 \begin_inset ERT
8576 status collapsed
8577
8578 \begin_layout Standard
8579
8580
8581 \backslash
8582 /
8583 \end_layout
8584
8585 \end_inset
8586
8587 -noinduction
8588 \begin_inset LatexCommand \index{-\/-noinduction}
8589
8590 \end_inset
8591
8592
8593 \series default
8594  Will not do loop induction optimizations, see section strength reduction
8595  for more details.
8596  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8597 noinduction
8598 \begin_inset LatexCommand \index{\#pragma noinduction}
8599
8600 \end_inset
8601
8602  can be used to turn off induction optimizations for a given function only.
8603 \end_layout
8604
8605 \begin_layout List
8606 \labelwidthstring 00.00.0000
8607
8608 \series bold
8609 -
8610 \begin_inset ERT
8611 status collapsed
8612
8613 \begin_layout Standard
8614
8615
8616 \backslash
8617 /
8618 \end_layout
8619
8620 \end_inset
8621
8622 -nojtbound
8623 \begin_inset LatexCommand \index{-\/-nojtbound}
8624
8625 \end_inset
8626
8627
8628 \size large
8629 \bar under
8630  
8631 \series default
8632 \size default
8633 \bar default
8634  Will not generate boundary condition check when switch statements
8635 \begin_inset LatexCommand \index{switch statement}
8636
8637 \end_inset
8638
8639  are implemented using jump-tables.
8640  See section 
8641 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8642
8643 \end_inset
8644
8645 \InsetSpace ~
8646 Switch Statements for more details.
8647  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8648 nojtbound
8649 \begin_inset LatexCommand \index{\#pragma nojtbound}
8650
8651 \end_inset
8652
8653  can be used to turn off boundary checking for jump tables for a given function
8654  only.
8655 \end_layout
8656
8657 \begin_layout List
8658 \labelwidthstring 00.00.0000
8659
8660 \series bold
8661 -
8662 \begin_inset ERT
8663 status collapsed
8664
8665 \begin_layout Standard
8666
8667
8668 \backslash
8669 /
8670 \end_layout
8671
8672 \end_inset
8673
8674 -noloopreverse
8675 \begin_inset LatexCommand \index{-\/-noloopreverse}
8676
8677 \end_inset
8678
8679
8680 \series default
8681 \size large
8682  
8683 \size default
8684 Will not do loop reversal 
8685 \begin_inset LatexCommand \index{Loop reversing}
8686
8687 \end_inset
8688
8689 optimization.
8690 \end_layout
8691
8692 \begin_layout List
8693 \labelwidthstring 00.00.0000
8694 -
8695 \begin_inset ERT
8696 status collapsed
8697
8698 \begin_layout Standard
8699
8700
8701 \backslash
8702 /
8703 \end_layout
8704
8705 \end_inset
8706
8707 -
8708 \series bold
8709 nolabelopt
8710 \series default
8711  
8712 \begin_inset LatexCommand \index{-\/-nolabelopt }
8713
8714 \end_inset
8715
8716 Will not optimize labels (makes the dumpfiles more readable).
8717 \end_layout
8718
8719 \begin_layout List
8720 \labelwidthstring 00.00.0000
8721
8722 \series bold
8723 -
8724 \begin_inset ERT
8725 status collapsed
8726
8727 \begin_layout Standard
8728
8729
8730 \backslash
8731 /
8732 \end_layout
8733
8734 \end_inset
8735
8736 -no-xinit-opt
8737 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8738
8739 \end_inset
8740
8741
8742 \series default
8743  Will not memcpy initialized data from code space into xdata space.
8744  This saves a few bytes in code space if you don't have initialized data
8745 \begin_inset LatexCommand \index{Variable initialization}
8746
8747 \end_inset
8748
8749 .
8750 \end_layout
8751
8752 \begin_layout List
8753 \labelwidthstring 00.00.0000
8754
8755 \series bold
8756 -
8757 \begin_inset ERT
8758 status collapsed
8759
8760 \begin_layout Standard
8761
8762
8763 \backslash
8764 /
8765 \end_layout
8766
8767 \end_inset
8768
8769 -nooverlay
8770 \begin_inset LatexCommand \index{-\/-nooverlay}
8771
8772 \end_inset
8773
8774
8775 \series default
8776   The compiler will not overlay parameters and local variables of any function,
8777  see section Parameters and local variables for more details.
8778 \end_layout
8779
8780 \begin_layout List
8781 \labelwidthstring 00.00.0000
8782
8783 \series bold
8784 -
8785 \begin_inset ERT
8786 status collapsed
8787
8788 \begin_layout Standard
8789
8790
8791 \backslash
8792 /
8793 \end_layout
8794
8795 \end_inset
8796
8797 -no-peep
8798 \begin_inset LatexCommand \index{-\/-no-peep}
8799
8800 \end_inset
8801
8802
8803 \series default
8804  Disable peep-hole optimization with built-in rules.
8805 \end_layout
8806
8807 \begin_layout List
8808 \labelwidthstring 00.00.0000
8809
8810 \series bold
8811 -
8812 \begin_inset ERT
8813 status collapsed
8814
8815 \begin_layout Standard
8816
8817
8818 \backslash
8819 /
8820 \end_layout
8821
8822 \end_inset
8823
8824 -peep-file
8825 \series default
8826
8827 \begin_inset LatexCommand \index{-\/-peep-file}
8828
8829 \end_inset
8830
8831 \InsetSpace ~
8832 <filename> This option can be used to use additional rules to be used by
8833  the peep hole optimizer.
8834  See section 
8835 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8836
8837 \end_inset
8838
8839 \InsetSpace ~
8840 Peep Hole optimizations for details on how to write these rules.
8841 \end_layout
8842
8843 \begin_layout List
8844 \labelwidthstring 00.00.0000
8845
8846 \series bold
8847 -
8848 \begin_inset ERT
8849 status collapsed
8850
8851 \begin_layout Standard
8852
8853
8854 \backslash
8855 /
8856 \end_layout
8857
8858 \end_inset
8859
8860 -peep-asm
8861 \begin_inset LatexCommand \index{-\/-peep-asm}
8862
8863 \end_inset
8864
8865
8866 \series default
8867  Pass the inline assembler code through the peep hole optimizer.
8868  This can cause unexpected changes to inline assembler code, please go through
8869  the peephole optimizer
8870 \begin_inset LatexCommand \index{Peephole optimizer}
8871
8872 \end_inset
8873
8874  rules defined in the source file tree '<target>/peeph.def' before using
8875  this option.
8876 \end_layout
8877
8878 \begin_layout List
8879 \labelwidthstring 00.00.0000
8880
8881 \series bold
8882 -
8883 \begin_inset ERT
8884 status collapsed
8885
8886 \begin_layout Standard
8887
8888
8889 \backslash
8890 /
8891 \end_layout
8892
8893 \end_inset
8894
8895 -opt-code-speed
8896 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8897
8898 \end_inset
8899
8900
8901 \series default
8902  The compiler will optimize code generation towards fast code, possibly
8903  at the expense of code size.
8904 \end_layout
8905
8906 \begin_layout List
8907 \labelwidthstring 00.00.0000
8908
8909 \series bold
8910 -
8911 \begin_inset ERT
8912 status collapsed
8913
8914 \begin_layout Standard
8915
8916
8917 \backslash
8918 /
8919 \end_layout
8920
8921 \end_inset
8922
8923 -opt-code-size
8924 \begin_inset LatexCommand \index{-\/-opt-code-size}
8925
8926 \end_inset
8927
8928
8929 \series default
8930  The compiler will optimize code generation towards compact code, possibly
8931  at the expense of code speed.
8932 \end_layout
8933
8934 \begin_layout Standard
8935 \begin_inset VSpace bigskip
8936 \end_inset
8937
8938
8939 \end_layout
8940
8941 \begin_layout Subsection
8942 Other Options
8943 \begin_inset LatexCommand \index{Options other}
8944
8945 \end_inset
8946
8947
8948 \end_layout
8949
8950 \begin_layout List
8951 \labelwidthstring 00.00.0000
8952
8953 \series bold
8954 -c\InsetSpace ~
8955 -
8956 \begin_inset ERT
8957 status collapsed
8958
8959 \begin_layout Standard
8960
8961
8962 \backslash
8963 /
8964 \end_layout
8965
8966 \end_inset
8967
8968 -compile-only
8969 \begin_inset LatexCommand \index{-\/-compile-only}
8970
8971 \end_inset
8972
8973
8974 \begin_inset LatexCommand \index{-c -\/-compile-only}
8975
8976 \end_inset
8977
8978
8979 \series default
8980  will compile and assemble the source, but will not call the linkage editor.
8981 \end_layout
8982
8983 \begin_layout List
8984 \labelwidthstring 00.00.0000
8985
8986 \series bold
8987 -
8988 \series default
8989
8990 \begin_inset ERT
8991 status collapsed
8992
8993 \begin_layout Standard
8994
8995
8996 \backslash
8997 /
8998 \end_layout
8999
9000 \end_inset
9001
9002
9003 \series bold
9004 -c1mode
9005 \begin_inset LatexCommand \index{-\/-c1mode}
9006
9007 \end_inset
9008
9009
9010 \series default
9011  reads the preprocessed source from standard input and compiles it.
9012  The file name for the assembler output must be specified using the -o option.
9013 \end_layout
9014
9015 \begin_layout List
9016 \labelwidthstring 00.00.0000
9017
9018 \series bold
9019 -E
9020 \begin_inset LatexCommand \index{-E}
9021
9022 \end_inset
9023
9024
9025 \series default
9026  Run only the C preprocessor.
9027  Preprocess all the C source files specified and output the results to standard
9028  output.
9029 \end_layout
9030
9031 \begin_layout List
9032 \labelwidthstring 00.00.0000
9033
9034 \series bold
9035 -o\InsetSpace ~
9036 <path/file>
9037 \begin_inset LatexCommand \index{-o <path/file>}
9038
9039 \end_inset
9040
9041  
9042 \series default
9043 The output path resp.
9044  file where everything will be placed.
9045  If the parameter is a path, it must have a trailing slash (or backslash
9046  for the Windows binaries) to be recognized as a path.
9047  
9048 \end_layout
9049
9050 \begin_layout List
9051 \labelwidthstring 00.00.0000
9052
9053 \series bold
9054 -
9055 \begin_inset ERT
9056 status collapsed
9057
9058 \begin_layout Standard
9059
9060
9061 \backslash
9062 /
9063 \end_layout
9064
9065 \end_inset
9066
9067 -stack-auto
9068 \begin_inset LatexCommand \index{-\/-stack-auto}
9069
9070 \end_inset
9071
9072
9073 \series default
9074 \size large
9075 \emph on
9076  
9077 \size default
9078 \emph default
9079 All functions in the source file will be compiled as 
9080 \emph on
9081 reentrant
9082 \emph default
9083
9084 \begin_inset LatexCommand \index{reentrant}
9085
9086 \end_inset
9087
9088 , i.e.
9089  the parameters and local variables will be allocated on the stack
9090 \begin_inset LatexCommand \index{stack}
9091
9092 \end_inset
9093
9094 .
9095  See section 
9096 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9097
9098 \end_inset
9099
9100  Parameters and Local Variables for more details.
9101  If this option is used all source files in the project should be compiled
9102  with this option.
9103  It automatically implies --int-long-reent and --float-reent.
9104  
9105 \end_layout
9106
9107 \begin_layout List
9108 \labelwidthstring 00.00.0000
9109
9110 \series bold
9111 -
9112 \begin_inset ERT
9113 status collapsed
9114
9115 \begin_layout Standard
9116
9117
9118 \backslash
9119 /
9120 \end_layout
9121
9122 \end_inset
9123
9124 -callee-saves
9125 \begin_inset LatexCommand \index{-\/-callee-saves}
9126
9127 \end_inset
9128
9129  
9130 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9131
9132 \end_inset
9133
9134 function1[,function2][,function3]....
9135
9136 \series default
9137  The compiler by default uses a caller saves convention for register saving
9138  across function calls, however this can cause unnecessary register pushing
9139  and popping when calling small functions from larger functions.
9140  This option can be used to switch the register saving convention for the
9141  function names specified.
9142  The compiler will not save registers when calling these functions, no extra
9143  code will be generated at the entry and exit (function prologue
9144 \series bold
9145
9146 \begin_inset LatexCommand \index{function prologue}
9147
9148 \end_inset
9149
9150
9151 \series default
9152  and epilogue
9153 \series bold
9154
9155 \begin_inset LatexCommand \index{function epilogue}
9156
9157 \end_inset
9158
9159
9160 \series default
9161 ) for these functions to save and restore the registers used by these functions,
9162  this can SUBSTANTIALLY reduce code and improve run time performance of
9163  the generated code.
9164  In the future the compiler (with inter procedural analysis) will be able
9165  to determine the appropriate scheme to use for each function call.
9166  DO NOT use this option for built-in functions such as _mulint..., if this
9167  option is used for a library function the appropriate library function
9168  needs to be recompiled with the same option.
9169  If the project consists of multiple source files then all the source file
9170  should be compiled with the same -
9171 \begin_inset ERT
9172 status collapsed
9173
9174 \begin_layout Standard
9175
9176
9177 \backslash
9178 /
9179 \end_layout
9180
9181 \end_inset
9182
9183 -callee-saves option string.
9184  Also see #pragma\InsetSpace ~
9185 callee_saves 
9186 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9187
9188 \end_inset
9189
9190  
9191 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9192
9193 \end_inset
9194
9195 .
9196 \end_layout
9197
9198 \begin_layout List
9199 \labelwidthstring 00.00.0000
9200
9201 \series bold
9202 -
9203 \begin_inset ERT
9204 status collapsed
9205
9206 \begin_layout Standard
9207
9208
9209 \backslash
9210 /
9211 \end_layout
9212
9213 \end_inset
9214
9215 -all-callee-saves
9216 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9217
9218 \end_inset
9219
9220  
9221 \series default
9222 Function of
9223 \series bold
9224  
9225 \series default
9226 -
9227 \begin_inset ERT
9228 status collapsed
9229
9230 \begin_layout Standard
9231
9232
9233 \backslash
9234 /
9235 \end_layout
9236
9237 \end_inset
9238
9239 -callee-saves will be applied to all functions by default.
9240 \end_layout
9241
9242 \begin_layout List
9243 \labelwidthstring 00.00.0000
9244
9245 \series bold
9246 -
9247 \begin_inset ERT
9248 status collapsed
9249
9250 \begin_layout Standard
9251
9252
9253 \backslash
9254 /
9255 \end_layout
9256
9257 \end_inset
9258
9259 -debug
9260 \begin_inset LatexCommand \index{-\/-debug}
9261
9262 \end_inset
9263
9264
9265 \bar under
9266  
9267 \series default
9268 \bar default
9269 When this option is used the compiler will generate debug information.
9270  The debug information collected in a file with .cdb extension can be used
9271  with the SDCDB.
9272  For more information see documentation for SDCDB.
9273  Another file with no extension contains debug information in AOMF or AOMF51
9274 \begin_inset LatexCommand \index{AOMF, AOMF51}
9275
9276 \end_inset
9277
9278  format which is commonly used by third party tools.
9279 \end_layout
9280
9281 \begin_layout List
9282 \labelwidthstring 00.00.0000
9283
9284 \series bold
9285 -S
9286 \begin_inset LatexCommand \index{-S}
9287
9288 \end_inset
9289
9290
9291 \size large
9292 \bar under
9293  
9294 \series default
9295 \size default
9296 \bar default
9297 Stop after the stage of compilation proper; do not assemble.
9298  The output is an assembler code file for the input file specified.
9299 \end_layout
9300
9301 \begin_layout List
9302 \labelwidthstring 00.00.0000
9303
9304 \series bold
9305 -
9306 \begin_inset ERT
9307 status collapsed
9308
9309 \begin_layout Standard
9310
9311
9312 \backslash
9313 /
9314 \end_layout
9315
9316 \end_inset
9317
9318 -int-long-reent
9319 \begin_inset LatexCommand \index{-\/-int-long-reent}
9320
9321 \end_inset
9322
9323
9324 \series default
9325  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9326  Note by default these libraries are compiled as non-reentrant.
9327  See section Installation for more details.
9328 \end_layout
9329
9330 \begin_layout List
9331 \labelwidthstring 00.00.0000
9332
9333 \series bold
9334 -
9335 \begin_inset ERT
9336 status collapsed
9337
9338 \begin_layout Standard
9339
9340
9341 \backslash
9342 /
9343 \end_layout
9344
9345 \end_inset
9346
9347 -cyclomatic
9348 \begin_inset LatexCommand \index{-\/-cyclomatic}
9349
9350 \end_inset
9351
9352
9353 \bar under
9354  
9355 \series default
9356 \bar default
9357 This option will cause the compiler to generate an information message for
9358  each function in the source file.
9359  The message contains some 
9360 \emph on
9361 important
9362 \emph default
9363  information about the function.
9364  The number of edges and nodes the compiler detected in the control flow
9365  graph of the function, and most importantly the 
9366 \emph on
9367 cyclomatic complexity
9368 \begin_inset LatexCommand \index{Cyclomatic complexity}
9369
9370 \end_inset
9371
9372
9373 \emph default
9374  see section on Cyclomatic Complexity for more details.
9375 \end_layout
9376
9377 \begin_layout List
9378 \labelwidthstring 00.00.0000
9379
9380 \series bold
9381 -
9382 \begin_inset ERT
9383 status collapsed
9384
9385 \begin_layout Standard
9386
9387
9388 \backslash
9389 /
9390 \end_layout
9391
9392 \end_inset
9393
9394 -float-reent
9395 \begin_inset LatexCommand \index{-\/-float-reent}
9396
9397 \end_inset
9398
9399
9400 \series default
9401  Floating point library is compiled as reentrant
9402 \begin_inset LatexCommand \index{reentrant}
9403
9404 \end_inset
9405
9406 .
9407  See section Installation for more details.
9408 \end_layout
9409
9410 \begin_layout List
9411 \labelwidthstring 00.00.0000
9412
9413 \series bold
9414 -
9415 \begin_inset ERT
9416 status collapsed
9417
9418 \begin_layout Standard
9419
9420
9421 \backslash
9422 /
9423 \end_layout
9424
9425 \end_inset
9426
9427 -funsigned-char
9428 \begin_inset LatexCommand \index{-\/-funsigned-char}
9429
9430 \end_inset
9431
9432
9433 \series default
9434  The default signedness for every type is
9435 \family typewriter
9436  signed
9437 \family default
9438 .
9439  In some embedded environments the default signedness of
9440 \family typewriter
9441  char
9442 \family default
9443  is
9444 \family typewriter
9445  unsigned
9446 \family default
9447 .
9448  To set the signess for characters to unsigned, use the option --funsigned-char.
9449  If this option is set and no signedness keyword (unsigned/signed) is given,
9450  a char will be signed.
9451  All other types are unaffected.
9452 \end_layout
9453
9454 \begin_layout List
9455 \labelwidthstring 00.00.0000
9456
9457 \series bold
9458 -
9459 \begin_inset ERT
9460 status collapsed
9461
9462 \begin_layout Standard
9463
9464
9465 \backslash
9466 /
9467 \end_layout
9468
9469 \end_inset
9470
9471 -main-return
9472 \begin_inset LatexCommand \index{-\/-main-return}
9473
9474 \end_inset
9475
9476
9477 \series default
9478  This option can be used if the code generated is called by a monitor program
9479  or if the main routine includes an endless loop.
9480  This option results in slightly smaller code and saves two bytes of stack
9481  space.
9482  The return from the 'main'
9483 \begin_inset LatexCommand \index{main return}
9484
9485 \end_inset
9486
9487  function will return to the function calling main.
9488  The default setting is to lock up i.e.
9489  generate a '
9490 \family typewriter
9491 sjmp .
9492 \family default
9493 '.
9494 \end_layout
9495
9496 \begin_layout List
9497 \labelwidthstring 00.00.0000
9498
9499 \series bold
9500 -
9501 \begin_inset ERT
9502 status collapsed
9503
9504 \begin_layout Standard
9505
9506
9507 \backslash
9508 /
9509 \end_layout
9510
9511 \end_inset
9512
9513 -nostdinc
9514 \begin_inset LatexCommand \index{-\/-nostdinc}
9515
9516 \end_inset
9517
9518
9519 \series default
9520  This will prevent the compiler from passing on the default include path
9521  to the preprocessor.
9522 \end_layout
9523
9524 \begin_layout List
9525 \labelwidthstring 00.00.0000
9526
9527 \series bold
9528 -
9529 \begin_inset ERT
9530 status collapsed
9531
9532 \begin_layout Standard
9533
9534
9535 \backslash
9536 /
9537 \end_layout
9538
9539 \end_inset
9540
9541 -nostdlib
9542 \begin_inset LatexCommand \index{-\/-nostdlib}
9543
9544 \end_inset
9545
9546
9547 \series default
9548  This will prevent the compiler from passing on the default library
9549 \begin_inset LatexCommand \index{Libraries}
9550
9551 \end_inset
9552
9553  path to the linker.
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 -verbose
9574 \begin_inset LatexCommand \index{-\/-verbose}
9575
9576 \end_inset
9577
9578
9579 \series default
9580  Shows the various actions the compiler is performing.
9581 \end_layout
9582
9583 \begin_layout List
9584 \labelwidthstring 00.00.0000
9585
9586 \series bold
9587 -V
9588 \begin_inset LatexCommand \index{-V}
9589
9590 \end_inset
9591
9592
9593 \series default
9594  Shows the actual commands the compiler is executing.
9595 \end_layout
9596
9597 \begin_layout List
9598 \labelwidthstring 00.00.0000
9599
9600 \series bold
9601 -
9602 \begin_inset ERT
9603 status collapsed
9604
9605 \begin_layout Standard
9606
9607
9608 \backslash
9609 /
9610 \end_layout
9611
9612 \end_inset
9613
9614 -no-c-code-in-asm
9615 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9616
9617 \end_inset
9618
9619
9620 \series default
9621  Hides your ugly and inefficient c-code from the asm file, so you can always
9622  blame the compiler :)
9623 \end_layout
9624
9625 \begin_layout List
9626 \labelwidthstring 00.00.0000
9627
9628 \series bold
9629 -
9630 \begin_inset ERT
9631 status collapsed
9632
9633 \begin_layout Standard
9634
9635
9636 \backslash
9637 /
9638 \end_layout
9639
9640 \end_inset
9641
9642 -no-peep-comments
9643 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9644
9645 \end_inset
9646
9647
9648 \series default
9649  Will not include peep-hole comments in the generated files.
9650 \end_layout
9651
9652 \begin_layout List
9653 \labelwidthstring 00.00.0000
9654
9655 \series bold
9656 -
9657 \begin_inset ERT
9658 status collapsed
9659
9660 \begin_layout Standard
9661
9662
9663 \backslash
9664 /
9665 \end_layout
9666
9667 \end_inset
9668
9669 -no-gen-comments
9670 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9671
9672 \end_inset
9673
9674
9675 \series default
9676  Will not include code generator comments in the generated files.
9677 \end_layout
9678
9679 \begin_layout List
9680 \labelwidthstring 00.00.0000
9681
9682 \series bold
9683 -
9684 \begin_inset ERT
9685 status collapsed
9686
9687 \begin_layout Standard
9688
9689
9690 \backslash
9691 /
9692 \end_layout
9693
9694 \end_inset
9695
9696 -i-code-in-asm
9697 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9698
9699 \end_inset
9700
9701
9702 \series default
9703  Include i-codes in the asm file.
9704  Sounds like noise but is most helpful for debugging the compiler itself.
9705 \end_layout
9706
9707 \begin_layout List
9708 \labelwidthstring 00.00.0000
9709
9710 \series bold
9711 -
9712 \begin_inset ERT
9713 status collapsed
9714
9715 \begin_layout Standard
9716
9717
9718 \backslash
9719 /
9720 \end_layout
9721
9722 \end_inset
9723
9724 -less-pedantic
9725 \begin_inset LatexCommand \index{pedantic}
9726
9727 \end_inset
9728
9729
9730 \begin_inset LatexCommand \index{-\/-less-pedantic}
9731
9732 \end_inset
9733
9734
9735 \series default
9736
9737 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9738
9739 \end_inset
9740
9741  Disable some of the more pedantic warnings
9742 \begin_inset LatexCommand \index{Warnings}
9743
9744 \end_inset
9745
9746 .
9747  For more details, see the less_pedantic pragma 
9748 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9749
9750 \end_inset
9751
9752 .
9753 \end_layout
9754
9755 \begin_layout List
9756 \labelwidthstring 00.00.0000
9757
9758 \series bold
9759 -
9760 \begin_inset ERT
9761 status collapsed
9762
9763 \begin_layout Standard
9764
9765
9766 \backslash
9767 /
9768 \end_layout
9769
9770 \end_inset
9771
9772 -disable-warning\InsetSpace ~
9773 <nnnn>
9774 \begin_inset LatexCommand \index{-\/-disable-warning}
9775
9776 \end_inset
9777
9778
9779 \series default
9780  Disable specific warning with number <nnnn>.
9781 \end_layout
9782
9783 \begin_layout List
9784 \labelwidthstring 00.00.0000
9785
9786 \series bold
9787 -
9788 \begin_inset ERT
9789 status collapsed
9790
9791 \begin_layout Standard
9792
9793
9794 \backslash
9795 /
9796 \end_layout
9797
9798 \end_inset
9799
9800 -print-search-dirs
9801 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9802
9803 \end_inset
9804
9805
9806 \series default
9807  Display the directories in the compiler's search path
9808 \end_layout
9809
9810 \begin_layout List
9811 \labelwidthstring 00.00.0000
9812
9813 \series bold
9814 -
9815 \begin_inset ERT
9816 status collapsed
9817
9818 \begin_layout Standard
9819
9820
9821 \backslash
9822 /
9823 \end_layout
9824
9825 \end_inset
9826
9827 -vc
9828 \begin_inset LatexCommand \index{-\/-vc}
9829
9830 \end_inset
9831
9832
9833 \series default
9834  Display errors and warnings using MSVC style, so you can use SDCC with
9835  the visual studio IDE
9836 \begin_inset LatexCommand \index{IDE}
9837
9838 \end_inset
9839
9840 .
9841  With SDCC both offering a GCC-like (the default) and a MSVC-like
9842 \begin_inset LatexCommand \index{MSVC output style}
9843
9844 \end_inset
9845
9846  output style, integration into most programming editors should be straightforwa
9847 rd.
9848 \end_layout
9849
9850 \begin_layout List
9851 \labelwidthstring 00.00.0000
9852
9853 \series bold
9854 -
9855 \begin_inset ERT
9856 status collapsed
9857
9858 \begin_layout Standard
9859
9860
9861 \backslash
9862 /
9863 \end_layout
9864
9865 \end_inset
9866
9867 -use-stdout
9868 \begin_inset LatexCommand \index{-\/-use-stdout}
9869
9870 \end_inset
9871
9872
9873 \series default
9874  Send errors and warnings to stdout instead of stderr.
9875 \end_layout
9876
9877 \begin_layout List
9878 \labelwidthstring 00.00.0000
9879
9880 \series bold
9881 -Wa\InsetSpace ~
9882 asmOption[,asmOption]
9883 \series default
9884
9885 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9886
9887 \end_inset
9888
9889 ...
9890  Pass the asmOption to the assembler
9891 \begin_inset LatexCommand \index{Options assembler}
9892
9893 \end_inset
9894
9895
9896 \begin_inset LatexCommand \index{Assembler options}
9897
9898 \end_inset
9899
9900 .
9901  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9902 \end_layout
9903
9904 \begin_layout List
9905 \labelwidthstring 00.00.0000
9906
9907 \series bold
9908 -
9909 \begin_inset ERT
9910 status collapsed
9911
9912 \begin_layout Standard
9913
9914
9915 \backslash
9916 /
9917 \end_layout
9918
9919 \end_inset
9920
9921 -std-sdcc89
9922 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9923
9924 \end_inset
9925
9926
9927 \series default
9928  Generally follow the C89 standard, but allow SDCC features that conflict
9929  with the standard (default).
9930 \end_layout
9931
9932 \begin_layout List
9933 \labelwidthstring 00.00.0000
9934
9935 \series bold
9936 -
9937 \begin_inset ERT
9938 status collapsed
9939
9940 \begin_layout Standard
9941
9942
9943 \backslash
9944 /
9945 \end_layout
9946
9947 \end_inset
9948
9949 -std-c89
9950 \begin_inset LatexCommand \index{-\/-std-c89}
9951
9952 \end_inset
9953
9954
9955 \series default
9956  Follow the C89 standard and disable SDCC features that conflict with the
9957  standard.
9958 \end_layout
9959
9960 \begin_layout List
9961 \labelwidthstring 00.00.0000
9962
9963 \series bold
9964 -
9965 \begin_inset ERT
9966 status collapsed
9967
9968 \begin_layout Standard
9969
9970
9971 \backslash
9972 /
9973 \end_layout
9974
9975 \end_inset
9976
9977 -std-sdcc99
9978 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9979
9980 \end_inset
9981
9982
9983 \series default
9984  Generally follow the C99 standard, but allow SDCC features that conflict
9985  with the standard (incomplete support).
9986 \end_layout
9987
9988 \begin_layout List
9989 \labelwidthstring 00.00.0000
9990
9991 \series bold
9992 -
9993 \begin_inset ERT
9994 status collapsed
9995
9996 \begin_layout Standard
9997
9998
9999 \backslash
10000 /
10001 \end_layout
10002
10003 \end_inset
10004
10005 -std-c99
10006 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10007
10008 \end_inset
10009
10010
10011 \series default
10012  Follow the C99 standard and disable SDCC features that conflict with the
10013  standard (incomplete support).
10014 \end_layout
10015
10016 \begin_layout List
10017 \labelwidthstring 00.00.0000
10018
10019 \series bold
10020 -
10021 \begin_inset ERT
10022 status collapsed
10023
10024 \begin_layout Standard
10025
10026
10027 \backslash
10028 /
10029 \end_layout
10030
10031 \end_inset
10032
10033 -codeseg
10034 \series default
10035
10036 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10037
10038 \end_inset
10039
10040 \InsetSpace ~
10041 <Name> The name to be used for the code
10042 \begin_inset LatexCommand \index{code}
10043
10044 \end_inset
10045
10046  segment, default CSEG.
10047  This is useful if you need to tell the compiler to put the code in a special
10048  segment so you can later on tell the linker to put this segment in a special
10049  place in memory.
10050  Can be used for instance when using bank switching to put the code in a
10051  bank.
10052 \end_layout
10053
10054 \begin_layout List
10055 \labelwidthstring 00.00.0000
10056
10057 \series bold
10058 -
10059 \begin_inset ERT
10060 status collapsed
10061
10062 \begin_layout Standard
10063
10064
10065 \backslash
10066 /
10067 \end_layout
10068
10069 \end_inset
10070
10071 -constseg
10072 \series default
10073
10074 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10075
10076 \end_inset
10077
10078 \InsetSpace ~
10079 <Name> The name to be used for the const
10080 \begin_inset LatexCommand \index{code}
10081
10082 \end_inset
10083
10084  segment, default CONST.
10085  This is useful if you need to tell the compiler to put the const data in
10086  a special segment so you can later on tell the linker to put this segment
10087  in a special place in memory.
10088  Can be used for instance when using bank switching to put the const data
10089  in a bank.
10090 \end_layout
10091
10092 \begin_layout List
10093 \labelwidthstring 00.00.0000
10094
10095 \series bold
10096 -
10097 \begin_inset ERT
10098 status collapsed
10099
10100 \begin_layout Standard
10101
10102
10103 \backslash
10104 /
10105 \end_layout
10106
10107 \end_inset
10108
10109 -fdollars-in-identifiers
10110 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10111
10112 \end_inset
10113
10114
10115 \series default
10116  Permit '$' as an identifier character-
10117 \end_layout
10118
10119 \begin_layout List
10120 \labelwidthstring 00.00.0000
10121
10122 \series bold
10123 -
10124 \begin_inset ERT
10125 status collapsed
10126
10127 \begin_layout Standard
10128
10129
10130 \backslash
10131 /
10132 \end_layout
10133
10134 \end_inset
10135
10136 -more-pedantic
10137 \series default
10138
10139 \begin_inset LatexCommand \index{-\/-more-pedantic}
10140
10141 \end_inset
10142
10143
10144 \begin_inset LatexCommand \index{pedantic}
10145
10146 \end_inset
10147
10148  Actually this is 
10149 \series bold
10150 \emph on
10151 not
10152 \series default
10153 \emph default
10154  a SDCC compiler option but if you want 
10155 \emph on
10156 more
10157 \emph default
10158  warnings you can use a separate tool dedicated to syntax checking like
10159  splint
10160 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10161
10162 \end_inset
10163
10164
10165 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10166
10167 \end_inset
10168
10169  
10170 \begin_inset LatexCommand \url{http://www.splint.org}
10171
10172 \end_inset
10173
10174 .
10175  To make your source files parseable by splint you will have to include
10176  
10177 \family sans
10178 lint.h
10179 \family default
10180
10181 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10182
10183 \end_inset
10184
10185  in your source file and add brackets around extended keywords (like 
10186 \family sans
10187
10188 \begin_inset Quotes sld
10189 \end_inset
10190
10191 __at\InsetSpace ~
10192
10193 \series bold
10194 (
10195 \series default
10196 0xab
10197 \series bold
10198 )
10199 \series default
10200
10201 \begin_inset Quotes srd
10202 \end_inset
10203
10204
10205 \family default
10206  and 
10207 \family sans
10208
10209 \begin_inset Quotes sld
10210 \end_inset
10211
10212 __interrupt\InsetSpace ~
10213 (2)
10214 \begin_inset Quotes srd
10215 \end_inset
10216
10217
10218 \family default
10219 ).
10220  
10221 \newline
10222 Splint has an excellent on line manual at 
10223 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10224
10225 \end_inset
10226
10227  and it's capabilities go beyond pure syntax checking.
10228  You'll need to tell splint the location of SDCC's include files so a typical
10229  command line could look like this: 
10230 \newline
10231
10232 \family sans
10233 splint\InsetSpace ~
10234 -I\InsetSpace ~
10235 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10236 \InsetSpace ~
10237 myprogram.c
10238 \end_layout
10239
10240 \begin_layout List
10241 \labelwidthstring 00.00.0000
10242
10243 \series bold
10244 -
10245 \begin_inset ERT
10246 status collapsed
10247
10248 \begin_layout Standard
10249
10250
10251 \backslash
10252 /
10253 \end_layout
10254
10255 \end_inset
10256
10257 -short-is-8bits
10258 \series default
10259
10260 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10261
10262 \end_inset
10263
10264
10265 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10266
10267 \end_inset
10268
10269  Treat short as 8-bit (for backward compatibility with older versions of
10270  compiler - see section 
10271 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10272
10273 \end_inset
10274
10275 )
10276 \end_layout
10277
10278 \begin_layout Standard
10279 \begin_inset VSpace bigskip
10280 \end_inset
10281
10282
10283 \end_layout
10284
10285 \begin_layout Subsection
10286 Intermediate Dump Options
10287 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10288
10289 \end_inset
10290
10291
10292 \begin_inset LatexCommand \index{Options intermediate dump}
10293
10294 \end_inset
10295
10296
10297 \begin_inset LatexCommand \index{Intermediate dump options}
10298
10299 \end_inset
10300
10301
10302 \end_layout
10303
10304 \begin_layout Standard
10305 The following options are provided for the purpose of retargetting and debugging
10306  the compiler.
10307  They provide a means to dump the intermediate code (iCode
10308 \begin_inset LatexCommand \index{iCode}
10309
10310 \end_inset
10311
10312 ) generated by the compiler in human readable form at various stages of
10313  the compilation process.
10314  More on iCodes see chapter 
10315 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10316
10317 \end_inset
10318
10319  
10320 \begin_inset Quotes srd
10321 \end_inset
10322
10323 The anatomy of the compiler
10324 \begin_inset Quotes srd
10325 \end_inset
10326
10327 .
10328 \end_layout
10329
10330 \begin_layout List
10331 \labelwidthstring 00.00.0000
10332
10333 \series bold
10334 -
10335 \begin_inset ERT
10336 status collapsed
10337
10338 \begin_layout Standard
10339
10340
10341 \backslash
10342 /
10343 \end_layout
10344
10345 \end_inset
10346
10347 -dumpraw
10348 \begin_inset LatexCommand \index{-\/-dumpraw}
10349
10350 \end_inset
10351
10352
10353 \series default
10354  This option will cause the compiler to dump the intermediate code into
10355  a file of named 
10356 \emph on
10357 <source filename>.dumpraw
10358 \emph default
10359  just after the intermediate code has been generated for a function, i.e.
10360  before any optimizations are done.
10361  The basic blocks
10362 \begin_inset LatexCommand \index{Basic blocks}
10363
10364 \end_inset
10365
10366  at this stage ordered in the depth first number, so they may not be in
10367  sequence of execution.
10368 \end_layout
10369
10370 \begin_layout List
10371 \labelwidthstring 00.00.0000
10372
10373 \series bold
10374 -
10375 \begin_inset ERT
10376 status collapsed
10377
10378 \begin_layout Standard
10379
10380
10381 \backslash
10382 /
10383 \end_layout
10384
10385 \end_inset
10386
10387 -dumpgcse
10388 \begin_inset LatexCommand \index{-\/-dumpgcse}
10389
10390 \end_inset
10391
10392
10393 \series default
10394  Will create a dump of iCode's, after global subexpression elimination
10395 \begin_inset LatexCommand \index{Global subexpression elimination}
10396
10397 \end_inset
10398
10399 , into a file named 
10400 \emph on
10401 <source filename>.dumpgcse.
10402 \end_layout
10403
10404 \begin_layout List
10405 \labelwidthstring 00.00.0000
10406
10407 \series bold
10408 -
10409 \begin_inset ERT
10410 status collapsed
10411
10412 \begin_layout Standard
10413
10414
10415 \backslash
10416 /
10417 \end_layout
10418
10419 \end_inset
10420
10421 -dumpdeadcode
10422 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10423
10424 \end_inset
10425
10426
10427 \series default
10428  Will create a dump of iCode's, after deadcode elimination
10429 \begin_inset LatexCommand \index{Dead-code elimination}
10430
10431 \end_inset
10432
10433 , into a file named 
10434 \emph on
10435 <source filename>.dumpdeadcode.
10436 \end_layout
10437
10438 \begin_layout List
10439 \labelwidthstring 00.00.0000
10440
10441 \series bold
10442 -
10443 \begin_inset ERT
10444 status collapsed
10445
10446 \begin_layout Standard
10447
10448
10449 \backslash
10450 /
10451 \end_layout
10452
10453 \end_inset
10454
10455 -dumploop
10456 \begin_inset LatexCommand \index{-\/-dumploop}
10457
10458 \end_inset
10459
10460
10461 \series default
10462 \size large
10463  
10464 \size default
10465 Will create a dump of iCode's, after loop optimizations
10466 \begin_inset LatexCommand \index{Loop optimization}
10467
10468 \end_inset
10469
10470 , into a file named 
10471 \emph on
10472 <source filename>.dumploop.
10473 \end_layout
10474
10475 \begin_layout List
10476 \labelwidthstring 00.00.0000
10477
10478 \series bold
10479 -
10480 \begin_inset ERT
10481 status collapsed
10482
10483 \begin_layout Standard
10484
10485
10486 \backslash
10487 /
10488 \end_layout
10489
10490 \end_inset
10491
10492 -dumprange
10493 \begin_inset LatexCommand \index{-\/-dumprange}
10494
10495 \end_inset
10496
10497
10498 \series default
10499 \size large
10500  
10501 \size default
10502 Will create a dump of iCode's, after live range analysis
10503 \begin_inset LatexCommand \index{Live range analysis}
10504
10505 \end_inset
10506
10507 , into a file named 
10508 \emph on
10509 <source filename>.dumprange.
10510 \end_layout
10511
10512 \begin_layout List
10513 \labelwidthstring 00.00.0000
10514
10515 \series bold
10516 -
10517 \begin_inset ERT
10518 status collapsed
10519
10520 \begin_layout Standard
10521
10522
10523 \backslash
10524 /
10525 \end_layout
10526
10527 \end_inset
10528
10529 -dumlrange
10530 \begin_inset LatexCommand \index{-\/-dumlrange}
10531
10532 \end_inset
10533
10534
10535 \series default
10536  Will dump the life ranges
10537 \begin_inset LatexCommand \index{Live range analysis}
10538
10539 \end_inset
10540
10541  for all symbols.
10542 \end_layout
10543
10544 \begin_layout List
10545 \labelwidthstring 00.00.0000
10546
10547 \series bold
10548 -
10549 \begin_inset ERT
10550 status collapsed
10551
10552 \begin_layout Standard
10553
10554
10555 \backslash
10556 /
10557 \end_layout
10558
10559 \end_inset
10560
10561 -dumpregassign
10562 \begin_inset LatexCommand \index{-\/-dumpregassign}
10563
10564 \end_inset
10565
10566
10567 \bar under
10568  
10569 \series default
10570 \bar default
10571 Will create a dump of iCode's, after register assignment
10572 \begin_inset LatexCommand \index{Register assignment}
10573
10574 \end_inset
10575
10576 , into a file named 
10577 \emph on
10578 <source filename>.dumprassgn.
10579 \end_layout
10580
10581 \begin_layout List
10582 \labelwidthstring 00.00.0000
10583
10584 \series bold
10585 -
10586 \begin_inset ERT
10587 status collapsed
10588
10589 \begin_layout Standard
10590
10591
10592 \backslash
10593 /
10594 \end_layout
10595
10596 \end_inset
10597
10598 -dumplrange
10599 \begin_inset LatexCommand \index{-\/-dumplrange}
10600
10601 \end_inset
10602
10603
10604 \series default
10605  Will create a dump of the live ranges of iTemp's
10606 \end_layout
10607
10608 \begin_layout List
10609 \labelwidthstring 00.00.0000
10610
10611 \series bold
10612 -
10613 \begin_inset ERT
10614 status collapsed
10615
10616 \begin_layout Standard
10617
10618
10619 \backslash
10620 /
10621 \end_layout
10622
10623 \end_inset
10624
10625 -dumpall
10626 \begin_inset LatexCommand \index{-\/-dumpall}
10627
10628 \end_inset
10629
10630
10631 \size large
10632 \bar under
10633  
10634 \series default
10635 \size default
10636 \bar default
10637 Will cause all the above mentioned dumps to be created.
10638 \end_layout
10639
10640 \begin_layout Standard
10641 \begin_inset VSpace bigskip
10642 \end_inset
10643
10644
10645 \end_layout
10646
10647 \begin_layout Subsection
10648 Redirecting output on Windows Shells
10649 \end_layout
10650
10651 \begin_layout Standard
10652 By default SDCC writes it's error messages to 
10653 \begin_inset Quotes sld
10654 \end_inset
10655
10656 standard error
10657 \begin_inset Quotes srd
10658 \end_inset
10659
10660 .
10661  To force all messages to 
10662 \begin_inset Quotes sld
10663 \end_inset
10664
10665 standard output
10666 \begin_inset Quotes srd
10667 \end_inset
10668
10669  use 
10670 \series bold
10671 -
10672 \series default
10673 \emph on
10674
10675 \begin_inset ERT
10676 status collapsed
10677
10678 \begin_layout Standard
10679
10680
10681 \backslash
10682 /
10683 \end_layout
10684
10685 \end_inset
10686
10687
10688 \series bold
10689 \emph default
10690 -
10691 \series default
10692 use-stdout
10693 \begin_inset LatexCommand \index{-\/-use-stdout}
10694
10695 \end_inset
10696
10697 .
10698  Additionally, if you happen to have visual studio installed in your windows
10699  machine, you can use it to compile your sources using a custom build and
10700  the SDCC -
10701 \emph on
10702
10703 \begin_inset ERT
10704 status collapsed
10705
10706 \begin_layout Standard
10707
10708
10709 \backslash
10710 /
10711 \end_layout
10712
10713 \end_inset
10714
10715
10716 \emph default
10717 -vc
10718 \begin_inset LatexCommand \index{-\/-vc}
10719
10720 \end_inset
10721
10722  option.
10723  Something like this should work:
10724 \newline
10725
10726 \newline
10727
10728 \series bold
10729 c:
10730 \backslash
10731 sdcc
10732 \backslash
10733 bin
10734 \backslash
10735 sdcc.exe -
10736 \series default
10737 \emph on
10738
10739 \begin_inset ERT
10740 status collapsed
10741
10742 \begin_layout Standard
10743
10744
10745 \backslash
10746 /
10747 \end_layout
10748
10749 \end_inset
10750
10751
10752 \series bold
10753 \emph default
10754 -vc -
10755 \series default
10756 \emph on
10757
10758 \begin_inset ERT
10759 status collapsed
10760
10761 \begin_layout Standard
10762
10763
10764 \backslash
10765 /
10766 \end_layout
10767
10768 \end_inset
10769
10770
10771 \series bold
10772 \emph default
10773 -model-large -c $(InputPath)
10774 \series default
10775
10776 \begin_inset VSpace bigskip
10777 \end_inset
10778
10779
10780 \end_layout
10781
10782 \begin_layout Section
10783 Environment variables
10784 \begin_inset LatexCommand \index{Environment variables}
10785
10786 \end_inset
10787
10788
10789 \end_layout
10790
10791 \begin_layout Standard
10792 SDCC recognizes the following environment variables:
10793 \end_layout
10794
10795 \begin_layout List
10796 \labelwidthstring 00.00.0000
10797
10798 \series bold
10799 SDCC_LEAVE_SIGNALS
10800 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10801
10802 \end_inset
10803
10804
10805 \series default
10806  SDCC installs a signal handler
10807 \begin_inset LatexCommand \index{signal handler}
10808
10809 \end_inset
10810
10811  to be able to delete temporary files after an user break (^C) or an exception.
10812  If this environment variable is set, SDCC won't install the signal handler
10813  in order to be able to debug SDCC.
10814 \end_layout
10815
10816 \begin_layout List
10817 \labelwidthstring 00.00.0000
10818
10819 \series bold
10820 TMP,\InsetSpace ~
10821 TEMP,\InsetSpace ~
10822 TMPDIR
10823 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10824
10825 \end_inset
10826
10827
10828 \series default
10829  Path, where temporary files will be created.
10830  The order of the variables is the search order.
10831  In a standard *nix environment these variables are not set, and there's
10832  no need to set them.
10833  On Windows it's recommended to set one of them.
10834 \end_layout
10835
10836 \begin_layout List
10837 \labelwidthstring 00.00.0000
10838
10839 \series bold
10840 SDCC_HOME
10841 \begin_inset LatexCommand \index{SDCC\_HOME}
10842
10843 \end_inset
10844
10845
10846 \series default
10847  Path, see section 
10848 \begin_inset LatexCommand \ref{sub:Install-paths}
10849
10850 \end_inset
10851
10852 \InsetSpace ~
10853
10854 \begin_inset Quotes sld
10855 \end_inset
10856
10857  Install Paths
10858 \begin_inset Quotes srd
10859 \end_inset
10860
10861 .
10862 \end_layout
10863
10864 \begin_layout List
10865 \labelwidthstring 00.00.0000
10866
10867 \series bold
10868 SDCC_INCLUDE
10869 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10870
10871 \end_inset
10872
10873
10874 \series default
10875  Path, see section 
10876 \begin_inset LatexCommand \ref{sub:Search-Paths}
10877
10878 \end_inset
10879
10880 \InsetSpace ~
10881
10882 \begin_inset Quotes sld
10883 \end_inset
10884
10885 Search Paths
10886 \begin_inset Quotes srd
10887 \end_inset
10888
10889 .
10890 \end_layout
10891
10892 \begin_layout List
10893 \labelwidthstring 00.00.0000
10894
10895 \series bold
10896 SDCC_LIB
10897 \begin_inset LatexCommand \index{SDCC\_LIB}
10898
10899 \end_inset
10900
10901
10902 \series default
10903  Path, see section 
10904 \begin_inset LatexCommand \ref{sub:Search-Paths}
10905
10906 \end_inset
10907
10908 \InsetSpace ~
10909
10910 \begin_inset Quotes sld
10911 \end_inset
10912
10913 Search Paths
10914 \begin_inset Quotes srd
10915 \end_inset
10916
10917 ..
10918 \end_layout
10919
10920 \begin_layout Standard
10921 There are some more environment variables recognized by SDCC, but these
10922  are solely used for debugging purposes.
10923  They can change or disappear very quickly, and will never be documented.
10924 \begin_inset VSpace bigskip
10925 \end_inset
10926
10927
10928 \end_layout
10929
10930 \begin_layout Section
10931 Storage Class Language Extensions
10932 \end_layout
10933
10934 \begin_layout Subsection
10935 MCS51/DS390 Storage Class
10936 \begin_inset LatexCommand \index{Storage class}
10937
10938 \end_inset
10939
10940  Language Extensions
10941 \end_layout
10942
10943 \begin_layout Standard
10944 In addition to the ANSI storage classes SDCC allows the following MCS51
10945  specific storage classes:
10946 \end_layout
10947
10948 \begin_layout Subsubsection
10949 data
10950 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10951
10952 \end_inset
10953
10954
10955 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10956
10957 \end_inset
10958
10959  / near
10960 \begin_inset LatexCommand \index{near (storage class)}
10961
10962 \end_inset
10963
10964
10965 \begin_inset LatexCommand \index{\_\_near (storage class)}
10966
10967 \end_inset
10968
10969
10970 \end_layout
10971
10972 \begin_layout Standard
10973 This is the 
10974 \series bold
10975 default
10976 \series default
10977  storage class for the Small Memory model (
10978 \emph on
10979 data
10980 \emph default
10981  and 
10982 \emph on
10983 near
10984 \emph default
10985  or the more ANSI-C compliant forms 
10986 \emph on
10987 __data
10988 \emph default
10989  and 
10990 \emph on
10991 __near
10992 \emph default
10993  can be used synonymously).
10994  Variables declared with this storage class will be allocated in the directly
10995  addressable portion of the internal RAM of a 8051, e.g.:
10996 \end_layout
10997
10998 \begin_layout Verse
10999
11000 \family typewriter
11001 __data unsigned char test_data;
11002 \end_layout
11003
11004 \begin_layout Standard
11005 Writing 0x01 to this variable generates the assembly code:
11006 \end_layout
11007
11008 \begin_layout Verse
11009
11010 \family typewriter
11011 75*00 01\InsetSpace ~
11012 \InsetSpace ~
11013 \InsetSpace ~
11014 mov\InsetSpace ~
11015 \InsetSpace ~
11016 _test_data,#0x01
11017 \end_layout
11018
11019 \begin_layout Subsubsection
11020 xdata
11021 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11022
11023 \end_inset
11024
11025
11026 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11027
11028 \end_inset
11029
11030  / far
11031 \begin_inset LatexCommand \index{far (storage class)}
11032
11033 \end_inset
11034
11035
11036 \begin_inset LatexCommand \index{\_\_far (storage class)}
11037
11038 \end_inset
11039
11040
11041 \end_layout
11042
11043 \begin_layout Standard
11044 Variables declared with this storage class will be placed in the external
11045  RAM.
11046  This is the 
11047 \series bold
11048 default
11049 \series default
11050  storage class for the Large Memory model, e.g.:
11051 \end_layout
11052
11053 \begin_layout Verse
11054
11055 \family typewriter
11056 __xdata unsigned char test_xdata;
11057 \end_layout
11058
11059 \begin_layout Standard
11060 Writing 0x01 to this variable generates the assembly code:
11061 \end_layout
11062
11063 \begin_layout Verse
11064
11065 \family typewriter
11066 90s00r00\InsetSpace ~
11067 \InsetSpace ~
11068 \InsetSpace ~
11069 mov\InsetSpace ~
11070 \InsetSpace ~
11071 dptr,#_test_xdata 
11072 \newline
11073 74\InsetSpace ~
11074 01\InsetSpace ~
11075 \InsetSpace ~
11076 \InsetSpace ~
11077 \InsetSpace ~
11078 \InsetSpace ~
11079 \InsetSpace ~
11080 mov\InsetSpace ~
11081 \InsetSpace ~
11082 a,#0x01 
11083 \newline
11084 F0\InsetSpace ~
11085 \InsetSpace ~
11086 \InsetSpace ~
11087 \InsetSpace ~
11088 \InsetSpace ~
11089 \InsetSpace ~
11090 \InsetSpace ~
11091 \InsetSpace ~
11092 \InsetSpace ~
11093 movx\InsetSpace ~
11094 @dptr,a 
11095 \end_layout
11096
11097 \begin_layout Subsubsection
11098 idata
11099 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11100
11101 \end_inset
11102
11103
11104 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11105
11106 \end_inset
11107
11108
11109 \end_layout
11110
11111 \begin_layout Standard
11112 Variables declared with this storage class will be allocated into the indirectly
11113  addressable portion of the internal ram of a 8051, e.g.:
11114 \end_layout
11115
11116 \begin_layout Verse
11117
11118 \family typewriter
11119 __idata unsigned char test_idata;
11120 \end_layout
11121
11122 \begin_layout Standard
11123 Writing 0x01 to this variable generates the assembly code:
11124 \end_layout
11125
11126 \begin_layout Verse
11127
11128 \family typewriter
11129 78r00\InsetSpace ~
11130 \InsetSpace ~
11131 \InsetSpace ~
11132 \InsetSpace ~
11133 \InsetSpace ~
11134 \InsetSpace ~
11135 \InsetSpace ~
11136 mov\InsetSpace ~
11137 \InsetSpace ~
11138 r0,#_test_idata
11139 \newline
11140 76\InsetSpace ~
11141 01\InsetSpace ~
11142 \InsetSpace ~
11143 \InsetSpace ~
11144 \InsetSpace ~
11145 \InsetSpace ~
11146 \InsetSpace ~
11147 \InsetSpace ~
11148 mov\InsetSpace ~
11149 \InsetSpace ~
11150 @r0,#0x01
11151 \end_layout
11152
11153 \begin_layout Standard
11154 Please note, the first 128 byte of idata physically access the same RAM
11155  as the data memory.
11156  The original 8051 had 128 byte idata memory, nowadays most devices have
11157  256 byte idata memory.
11158  The stack
11159 \begin_inset LatexCommand \index{stack}
11160
11161 \end_inset
11162
11163  is located in idata memory.
11164 \end_layout
11165
11166 \begin_layout Subsubsection
11167 pdata
11168 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11169
11170 \end_inset
11171
11172
11173 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11174
11175 \end_inset
11176
11177
11178 \end_layout
11179
11180 \begin_layout Standard
11181 Paged xdata access is just as straightforward as using the other addressing
11182  modes of a 8051.
11183  It is typically located at the start of xdata and has a maximum size of
11184  256 bytes.
11185  The following example writes 0x01 to the pdata variable.
11186  Please note, pdata access physically accesses xdata memory.
11187  The high byte of the address is determined by port P2 
11188 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11189
11190 \end_inset
11191
11192 (or in case of some 8051 variants by a separate Special Function Register,
11193  see section 
11194 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11195
11196 \end_inset
11197
11198 ).
11199  This is the 
11200 \series bold
11201 default
11202 \series default
11203  storage class for the Medium Memory model, e.g.:
11204 \end_layout
11205
11206 \begin_layout Verse
11207
11208 \family typewriter
11209 __pdata unsigned char test_pdata;
11210 \end_layout
11211
11212 \begin_layout Standard
11213 Writing 0x01 to this variable generates the assembly code:
11214 \end_layout
11215
11216 \begin_layout Verse
11217
11218 \family typewriter
11219 78r00\InsetSpace ~
11220 \InsetSpace ~
11221 \InsetSpace ~
11222 \InsetSpace ~
11223 \InsetSpace ~
11224 \InsetSpace ~
11225 mov r0,#_test_pdata
11226 \newline
11227 74 01\InsetSpace ~
11228 \InsetSpace ~
11229 \InsetSpace ~
11230 \InsetSpace ~
11231 \InsetSpace ~
11232 \InsetSpace ~
11233 mov a,#0x01 
11234 \newline
11235 F2\InsetSpace ~
11236 \InsetSpace ~
11237 \InsetSpace ~
11238 \InsetSpace ~
11239 \InsetSpace ~
11240 \InsetSpace ~
11241 \InsetSpace ~
11242 \InsetSpace ~
11243 \InsetSpace ~
11244 movx @r0,a
11245 \end_layout
11246
11247 \begin_layout Standard
11248 If the -
11249 \begin_inset ERT
11250 status collapsed
11251
11252 \begin_layout Standard
11253
11254
11255 \backslash
11256 /
11257 \end_layout
11258
11259 \end_inset
11260
11261 -xstack
11262 \begin_inset LatexCommand \index{-\/-xstack}
11263
11264 \end_inset
11265
11266  option is used the pdata memory area is followed by the xstack memory area
11267  and the sum of their sizes is limited to 256 bytes.
11268 \end_layout
11269
11270 \begin_layout Subsubsection
11271 code
11272 \begin_inset LatexCommand \index{code}
11273
11274 \end_inset
11275
11276
11277 \begin_inset LatexCommand \index{\_\_code}
11278
11279 \end_inset
11280
11281
11282 \end_layout
11283
11284 \begin_layout Standard
11285 'Variables' declared with this storage class will be placed in the code
11286  memory:
11287 \end_layout
11288
11289 \begin_layout Verse
11290
11291 \family typewriter
11292 __code unsigned char test_code;
11293 \end_layout
11294
11295 \begin_layout Standard
11296 Read access to this variable generates the assembly code:
11297 \end_layout
11298
11299 \begin_layout Verse
11300
11301 \family typewriter
11302 90s00r6F\InsetSpace ~
11303 \InsetSpace ~
11304 \InsetSpace ~
11305 mov dptr,#_test_code
11306 \newline
11307 E4\InsetSpace ~
11308 \InsetSpace ~
11309 \InsetSpace ~
11310 \InsetSpace ~
11311 \InsetSpace ~
11312 \InsetSpace ~
11313 \InsetSpace ~
11314 \InsetSpace ~
11315 \InsetSpace ~
11316 clr a
11317 \newline
11318 93\InsetSpace ~
11319 \InsetSpace ~
11320 \InsetSpace ~
11321 \InsetSpace ~
11322 \InsetSpace ~
11323 \InsetSpace ~
11324 \InsetSpace ~
11325 \InsetSpace ~
11326 \InsetSpace ~
11327 movc a,@a+dptr 
11328 \end_layout
11329
11330 \begin_layout Standard
11331
11332 \family typewriter
11333 char
11334 \family default
11335  indexed arrays of characters in code memory can be accessed efficiently:
11336 \end_layout
11337
11338 \begin_layout Verse
11339
11340 \family typewriter
11341 __code char test_array[] = {'c','h','e','a','p'}; 
11342 \end_layout
11343
11344 \begin_layout Standard
11345 Read access to this array using an 8-bit unsigned index generates the assembly
11346  code:
11347 \end_layout
11348
11349 \begin_layout Verse
11350
11351 \family typewriter
11352 E5*00\InsetSpace ~
11353 \InsetSpace ~
11354 \InsetSpace ~
11355 \InsetSpace ~
11356 \InsetSpace ~
11357 \InsetSpace ~
11358 mov a,_index 
11359 \end_layout
11360
11361 \begin_layout Verse
11362
11363 \family typewriter
11364 90s00r41\InsetSpace ~
11365 \InsetSpace ~
11366 \InsetSpace ~
11367 mov dptr,#_test_array
11368 \end_layout
11369
11370 \begin_layout Verse
11371
11372 \family typewriter
11373 93\InsetSpace ~
11374 \InsetSpace ~
11375 \InsetSpace ~
11376 \InsetSpace ~
11377 \InsetSpace ~
11378 \InsetSpace ~
11379 \InsetSpace ~
11380 \InsetSpace ~
11381 \InsetSpace ~
11382 movc a,@a+dptr 
11383 \end_layout
11384
11385 \begin_layout Subsubsection
11386 bit
11387 \begin_inset LatexCommand \index{bit}
11388
11389 \end_inset
11390
11391
11392 \begin_inset LatexCommand \index{\_\_bit}
11393
11394 \end_inset
11395
11396
11397 \end_layout
11398
11399 \begin_layout Standard
11400 This is a data-type and a storage class specifier.
11401  When a variable is declared as a bit, it is allocated into the bit addressable
11402  memory of 8051, e.g.:
11403 \end_layout
11404
11405 \begin_layout Verse
11406
11407 \family typewriter
11408 __bit test_bit;
11409 \end_layout
11410
11411 \begin_layout Standard
11412 Writing 1 to this variable generates the assembly code:
11413 \end_layout
11414
11415 \begin_layout Verse
11416
11417 \family typewriter
11418 D2*00\InsetSpace ~
11419 \InsetSpace ~
11420 \InsetSpace ~
11421 \InsetSpace ~
11422 \InsetSpace ~
11423 \InsetSpace ~
11424 \InsetSpace ~
11425 setb\InsetSpace ~
11426 _test_bit
11427 \end_layout
11428
11429 \begin_layout Standard
11430 The bit addressable memory consists of 128 bits which are located from 0x20
11431  to 0x2f in data memory.
11432  
11433 \newline
11434 Apart from this 8051 specific storage class most architectures support
11435  ANSI-C bitfields
11436 \begin_inset LatexCommand \index{bitfields}
11437
11438 \end_inset
11439
11440
11441 \begin_inset Foot
11442 status open
11443
11444 \begin_layout Standard
11445 Not really meant as examples, but nevertheless showing what bitfields are
11446  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11447 \end_layout
11448
11449 \end_inset
11450
11451 .
11452  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11453  signed modifier are implemented as unsigned.
11454 \end_layout
11455
11456 \begin_layout Subsubsection
11457 sfr
11458 \begin_inset LatexCommand \index{sfr}
11459
11460 \end_inset
11461
11462
11463 \begin_inset LatexCommand \index{\_\_sfr}
11464
11465 \end_inset
11466
11467  / sfr16
11468 \begin_inset LatexCommand \index{sfr16}
11469
11470 \end_inset
11471
11472
11473 \begin_inset LatexCommand \index{\_\_sfr16}
11474
11475 \end_inset
11476
11477  / sfr32
11478 \begin_inset LatexCommand \index{sfr32}
11479
11480 \end_inset
11481
11482
11483 \begin_inset LatexCommand \index{\_\_sfr32}
11484
11485 \end_inset
11486
11487  / sbit
11488 \begin_inset LatexCommand \index{\_\_sbit}
11489
11490 \end_inset
11491
11492
11493 \begin_inset LatexCommand \index{sbit}
11494
11495 \end_inset
11496
11497
11498 \end_layout
11499
11500 \begin_layout Standard
11501 Like the bit keyword, 
11502 \emph on
11503 sfr / sfr16 / sfr32 / sbit 
11504 \emph default
11505 signify both a data-type and storage class, they are used to describe the
11506  
11507 \emph on
11508 s
11509 \emph default
11510 pecial 
11511 \emph on
11512 f
11513 \emph default
11514 unction 
11515 \emph on
11516 r
11517 \emph default
11518 egisters and 
11519 \emph on
11520 s
11521 \emph default
11522 pecial 
11523 \emph on
11524 bit
11525 \emph default
11526  variables of a 8051, eg:
11527 \end_layout
11528
11529 \begin_layout Verse
11530
11531 \family typewriter
11532 __sfr __at
11533 \begin_inset LatexCommand \index{at}
11534
11535 \end_inset
11536
11537
11538 \begin_inset LatexCommand \index{\_\_at}
11539
11540 \end_inset
11541
11542  (0x80) P0;\InsetSpace ~
11543  /* special function register P0 at location 0x80 */
11544 \newline
11545
11546 \newline
11547 /* 16 bit
11548  special function register combination for timer 0
11549 \newline
11550 \InsetSpace ~
11551 \InsetSpace ~
11552  with the high byte at
11553  location 0x8C and the low byte at location 0x8A */
11554 \newline
11555 __sfr16 __at (0x8C8A)
11556  TMR0;
11557 \newline
11558
11559 \newline
11560 __sbit __at
11561 \begin_inset LatexCommand \index{at}
11562
11563 \end_inset
11564
11565
11566 \begin_inset LatexCommand \index{\_\_at}
11567
11568 \end_inset
11569
11570  (0xd7) CY;\InsetSpace ~
11571  /* CY (Carry Flag
11572 \begin_inset LatexCommand \index{Flags}
11573
11574 \end_inset
11575
11576
11577 \begin_inset LatexCommand \index{Carry flag}
11578
11579 \end_inset
11580
11581 ) */
11582 \end_layout
11583
11584 \begin_layout Standard
11585 Special function registers which are located on an address dividable by
11586  8 are bit-addressable, an
11587 \emph on
11588  sbit
11589 \emph default
11590  addresses a specific bit within these sfr.
11591 \newline
11592 16 Bit and 32 bit special function
11593  register combinations which require a certain access order are better not
11594  declared using 
11595 \emph on
11596 sfr16
11597 \emph default
11598  or 
11599 \emph on
11600 sfr32.
11601
11602 \emph default
11603  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11604  this is not guaranteed.
11605 \newline
11606
11607 \end_layout
11608
11609 \begin_layout Standard
11610 Please note, if you use a header file which was written for another compiler
11611  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11612  likely be 
11613 \emph on
11614 not 
11615 \emph default
11616 compatible.
11617  Specifically the syntax 
11618 \family typewriter
11619 \InsetSpace ~
11620 sfr P0 = 0x80;\InsetSpace ~
11621
11622 \family default
11623  is compiled 
11624 \emph on
11625 without warning
11626 \emph default
11627  by SDCC to an assignment of 0x80 to a variable called P0 
11628 \family typewriter
11629
11630 \begin_inset Marginal
11631 status collapsed
11632
11633 \begin_layout Standard
11634
11635 \series bold
11636 \InsetSpace ~
11637 !
11638 \end_layout
11639
11640 \end_inset
11641
11642 .
11643  
11644 \family default
11645 Nevertheless it is possible to write header files
11646 \begin_inset LatexCommand \index{Header files}
11647
11648 \end_inset
11649
11650
11651 \begin_inset LatexCommand \index{Include files}
11652
11653 \end_inset
11654
11655  which can be shared among different compilers (see section 
11656 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11657
11658 \end_inset
11659
11660 ).
11661  
11662 \end_layout
11663
11664 \begin_layout Subsubsection
11665 Pointers
11666 \begin_inset LatexCommand \index{Pointer}
11667
11668 \end_inset
11669
11670  to MCS51/DS390 specific memory spaces
11671 \end_layout
11672
11673 \begin_layout Standard
11674 SDCC allows (via language extensions) pointers to explicitly point to any
11675  of the memory spaces
11676 \begin_inset LatexCommand \index{Memory model}
11677
11678 \end_inset
11679
11680  of the 8051.
11681  In addition to the explicit pointers, the compiler uses (by default) generic
11682  pointers which can be used to point to any of the memory spaces.
11683 \newline
11684
11685 \newline
11686 Pointer
11687  declaration examples:
11688 \end_layout
11689
11690 \begin_layout Verse
11691
11692 \family typewriter
11693 /* pointer physically in internal ram pointing to object in external ram
11694  */ 
11695 \newline
11696 __xdata unsigned char * __data p;
11697 \newline
11698
11699 \newline
11700 /* pointer physically in external ram
11701  pointing to object in internal ram */ 
11702 \newline
11703 __data unsigned char * __xdata p;
11704 \newline
11705
11706 \newline
11707 /*
11708  pointer physically in code rom pointing to data in xdata space */ 
11709 \newline
11710 __xdata
11711  unsigned char * __code p;
11712 \newline
11713
11714 \newline
11715 /* pointer physically in code space pointing to
11716  data in code space */ 
11717 \newline
11718 __code unsigned char * __code p;
11719 \newline
11720
11721 \newline
11722 /* generic pointer
11723  physically located in xdata space */
11724 \newline
11725 unsigned char * __xdata p;
11726 \newline
11727
11728 \newline
11729 /* generic
11730  pointer physically located in default memory space */
11731 \newline
11732 unsigned char * p;
11733 \newline
11734
11735 \newline
11736 /*
11737  the following is a function pointer
11738 \begin_inset LatexCommand \index{function pointer}
11739
11740 \end_inset
11741
11742  physically located in data space */
11743 \newline
11744 char (* __data fp)(void);
11745 \end_layout
11746
11747 \begin_layout Standard
11748 Well you get the idea.
11749  
11750 \newline
11751
11752 \newline
11753 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
11754 \emph on
11755 generic
11756 \emph default
11757  pointers.
11758  
11759 \size small
11760
11761 \newline
11762
11763 \newline
11764
11765 \size default
11766 The highest order byte of the 
11767 \emph on
11768 generic
11769 \emph default
11770  pointers contains the data space information.
11771  Assembler support routines are called whenever data is stored or retrieved
11772  using 
11773 \emph on
11774 generic
11775 \emph default
11776  pointers.
11777  These are useful for developing reusable library
11778 \begin_inset LatexCommand \index{Libraries}
11779
11780 \end_inset
11781
11782  routines.
11783  Explicitly specifying the pointer
11784 \begin_inset LatexCommand \index{pointer}
11785
11786 \end_inset
11787
11788  type will generate the most efficient code.
11789 \end_layout
11790
11791 \begin_layout Subsubsection
11792 Notes on MCS51 memory
11793 \begin_inset LatexCommand \index{MCS51 memory}
11794
11795 \end_inset
11796
11797  layout
11798 \end_layout
11799
11800 \begin_layout Standard
11801 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11802  RAM memory which is structured as follows:
11803 \newline
11804
11805 \newline
11806 - Bytes 00-1F - 32 bytes to hold
11807  up to 4 banks of the registers R0 to R7, 
11808 \newline
11809 - Bytes 20-2F - 16 bytes to hold
11810  128 bit
11811 \begin_inset LatexCommand \index{bit}
11812
11813 \end_inset
11814
11815  variables and, 
11816 \newline
11817 - Bytes 30-7F - 80 bytes for general purpose use.
11818 \newline
11819
11820 \end_layout
11821
11822 \begin_layout Standard
11823 Additionally some members of the MCS51 family may have up to 128 bytes of
11824  additional, indirectly addressable, internal RAM memory (
11825 \emph on
11826 idata
11827 \emph default
11828
11829 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11830
11831 \end_inset
11832
11833
11834 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11835
11836 \end_inset
11837
11838 ).
11839  Furthermore, some chips may have some built in external memory (
11840 \emph on
11841 xdata
11842 \emph default
11843
11844 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11845
11846 \end_inset
11847
11848
11849 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11850
11851 \end_inset
11852
11853 ) which should not be confused with the internal, directly addressable RAM
11854  memory (
11855 \emph on
11856 data
11857 \emph default
11858
11859 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11860
11861 \end_inset
11862
11863
11864 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11865
11866 \end_inset
11867
11868 ).
11869  Sometimes this built in 
11870 \emph on
11871 xdata
11872 \emph default
11873  memory has to be activated before using it (you can probably find this
11874  information on the datasheet of the microcontroller your are using, see
11875  also section 
11876 \begin_inset LatexCommand \ref{sub:Startup-Code}
11877
11878 \end_inset
11879
11880 \InsetSpace ~
11881 Startup-Code).
11882 \end_layout
11883
11884 \begin_layout Standard
11885 Normally SDCC will only use the first bank
11886 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11887
11888 \end_inset
11889
11890  of registers (register bank 0), but it is possible to specify that other
11891  banks of registers (keyword 
11892 \emph on
11893 using
11894 \emph default
11895  
11896 \emph on
11897
11898 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11899
11900 \end_inset
11901
11902
11903 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11904
11905 \end_inset
11906
11907
11908 \emph default
11909 ) should be used for example in interrupt
11910 \begin_inset LatexCommand \index{interrupt}
11911
11912 \end_inset
11913
11914
11915 \begin_inset LatexCommand \index{\_\_interrupt}
11916
11917 \end_inset
11918
11919  routines.
11920  By default, the compiler will place the stack after the last byte of allocated
11921  memory for variables.
11922  For example, if the first 2 banks of registers are used, and only four
11923  bytes are used for 
11924 \emph on
11925 data
11926 \emph default
11927  variables, it will position the base of the internal stack at address 20
11928  (0x14).
11929  This implies that as the stack
11930 \begin_inset LatexCommand \index{stack}
11931
11932 \end_inset
11933
11934  grows, it will use up the remaining register banks, and the 16 bytes used
11935  by the 128 bit variables, and 80 bytes for general purpose use.
11936  If any bit variables are used, the data variables will be placed in unused
11937  register banks and after the byte holding the last bit variable.
11938  For example, if register banks 0 and 1 are used, and there are 9 bit variables
11939  (two bytes used), 
11940 \emph on
11941 data
11942 \emph default
11943  variables will be placed starting from address 0x10 to 0x20 and continue
11944  at address 0x22.
11945  You can also use -
11946 \begin_inset ERT
11947 status collapsed
11948
11949 \begin_layout Standard
11950
11951
11952 \backslash
11953 /
11954 \end_layout
11955
11956 \end_inset
11957
11958 -data-loc
11959 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11960
11961 \end_inset
11962
11963  to specify the start address of the 
11964 \emph on
11965 data
11966 \emph default
11967  and -
11968 \begin_inset ERT
11969 status collapsed
11970
11971 \begin_layout Standard
11972
11973
11974 \backslash
11975 /
11976 \end_layout
11977
11978 \end_inset
11979
11980 -iram-size
11981 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11982
11983 \end_inset
11984
11985  to specify the size of the total internal RAM (
11986 \emph on
11987 data
11988 \emph default
11989 +
11990 \emph on
11991 idata
11992 \emph default
11993 ).
11994  
11995 \newline
11996
11997 \end_layout
11998
11999 \begin_layout Standard
12000 By default the 8051 linker will place the stack after the last byte of (i)data
12001  variables.
12002  Option -
12003 \begin_inset ERT
12004 status collapsed
12005
12006 \begin_layout Standard
12007
12008
12009 \backslash
12010 /
12011 \end_layout
12012
12013 \end_inset
12014
12015 -stack-loc
12016 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12017
12018 \end_inset
12019
12020  allows you to specify the start of the stack, i.e.
12021  you could start it after any data in the general purpose area.
12022  If your microcontroller has additional indirectly addressable internal
12023  RAM (
12024 \emph on
12025 idata
12026 \emph default
12027 ) you can place the stack on it.
12028  You may also need to use -
12029 \begin_inset ERT
12030 status collapsed
12031
12032 \begin_layout Standard
12033
12034
12035 \backslash
12036 /
12037 \end_layout
12038
12039 \end_inset
12040
12041 -xdata-loc
12042 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12043
12044 \end_inset
12045
12046  to set the start address of the external RAM (
12047 \emph on
12048 xdata
12049 \emph default
12050 ) and -
12051 \begin_inset ERT
12052 status collapsed
12053
12054 \begin_layout Standard
12055
12056
12057 \backslash
12058 /
12059 \end_layout
12060
12061 \end_inset
12062
12063 -xram-size
12064 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12065
12066 \end_inset
12067
12068  to specify its size.
12069  Same goes for the code memory, using -
12070 \begin_inset ERT
12071 status collapsed
12072
12073 \begin_layout Standard
12074
12075
12076 \backslash
12077 /
12078 \end_layout
12079
12080 \end_inset
12081
12082 -code-loc
12083 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12084
12085 \end_inset
12086
12087  and -
12088 \begin_inset ERT
12089 status collapsed
12090
12091 \begin_layout Standard
12092
12093
12094 \backslash
12095 /
12096 \end_layout
12097
12098 \end_inset
12099
12100 -code-size
12101 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12102
12103 \end_inset
12104
12105 .
12106  If in doubt, don't specify any options and see if the resulting memory
12107  layout is appropriate, then you can adjust it.
12108 \end_layout
12109
12110 \begin_layout Standard
12111 The linker generates two files with memory allocation information.
12112  The first, with extension .map
12113 \begin_inset LatexCommand \index{<file>.map}
12114
12115 \end_inset
12116
12117  shows all the variables and segments.
12118  The second with extension .mem
12119 \begin_inset LatexCommand \index{<file>.mem}
12120
12121 \end_inset
12122
12123  shows the final memory layout.
12124  The linker will complain either if memory segments overlap, there is not
12125  enough memory, or there is not enough space for stack.
12126  If you get any linking warnings and/or errors related to stack or segments
12127  allocation, take a look at either the .map or .mem files to find out what
12128  the problem is.
12129  The .mem file may even suggest a solution to the problem.
12130 \begin_inset VSpace bigskip
12131 \end_inset
12132
12133
12134 \end_layout
12135
12136 \begin_layout Subsection
12137 Z80/Z180 Storage Class
12138 \begin_inset LatexCommand \index{Z80!Storage class}
12139
12140 \end_inset
12141
12142  Language Extensions
12143 \end_layout
12144
12145 \begin_layout Subsubsection
12146 sfr
12147 \begin_inset LatexCommand \index{sfr}
12148
12149 \end_inset
12150
12151
12152 \begin_inset LatexCommand \index{\_\_sfr}
12153
12154 \end_inset
12155
12156  (in/out to 8-bit addresses)
12157 \end_layout
12158
12159 \begin_layout Standard
12160 The Z80
12161 \begin_inset LatexCommand \index{Z80}
12162
12163 \end_inset
12164
12165  family has separate address spaces for memory and 
12166 \emph on
12167 i
12168 \emph default
12169 nput/
12170 \emph on
12171 o
12172 \emph default
12173 utput memory.
12174  I/O memory
12175 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12176
12177 \end_inset
12178
12179
12180 \begin_inset LatexCommand \index{Z80!I/O memory}
12181
12182 \end_inset
12183
12184
12185 \begin_inset LatexCommand \index{Z180!I/O memory}
12186
12187 \end_inset
12188
12189  is accessed with special instructions, e.g.:
12190 \end_layout
12191
12192 \begin_layout Verse
12193
12194 \family typewriter
12195 sfr at 0x78 IoPort;\InsetSpace ~
12196 \InsetSpace ~
12197 /* define a var in I/O space at 78h called IoPort */
12198  
12199 \end_layout
12200
12201 \begin_layout Standard
12202 Writing 0x01 to this variable generates the assembly code:
12203 \end_layout
12204
12205 \begin_layout Verse
12206
12207 \family typewriter
12208 3E 01\InsetSpace ~
12209 \InsetSpace ~
12210 \InsetSpace ~
12211 \InsetSpace ~
12212 \InsetSpace ~
12213 \InsetSpace ~
12214 ld a,#0x01
12215 \newline
12216 D3 78\InsetSpace ~
12217 \InsetSpace ~
12218 \InsetSpace ~
12219 \InsetSpace ~
12220 \InsetSpace ~
12221 \InsetSpace ~
12222 out (_IoPort),a 
12223 \end_layout
12224
12225 \begin_layout Subsubsection
12226 banked sfr
12227 \begin_inset LatexCommand \index{sfr}
12228
12229 \end_inset
12230
12231
12232 \begin_inset LatexCommand \index{\_\_sfr}
12233
12234 \end_inset
12235
12236  (in/out to 16-bit addresses)
12237 \end_layout
12238
12239 \begin_layout Standard
12240 The keyword 
12241 \emph on
12242 banked
12243 \emph default
12244  is used to support 16 bit addresses in I/O memory e.g.:
12245 \end_layout
12246
12247 \begin_layout Verse
12248
12249 \family typewriter
12250 sfr banked at
12251 \begin_inset LatexCommand \index{at}
12252
12253 \end_inset
12254
12255
12256 \begin_inset LatexCommand \index{\_\_at}
12257
12258 \end_inset
12259
12260  0x123 IoPort; 
12261 \end_layout
12262
12263 \begin_layout Standard
12264 Writing 0x01 to this variable generates the assembly code:
12265 \end_layout
12266
12267 \begin_layout Verse
12268
12269 \family typewriter
12270 01 23 01\InsetSpace ~
12271 \InsetSpace ~
12272 \InsetSpace ~
12273 ld bc,#_IoPort
12274 \newline
12275 3E 01\InsetSpace ~
12276 \InsetSpace ~
12277 \InsetSpace ~
12278 \InsetSpace ~
12279 \InsetSpace ~
12280 \InsetSpace ~
12281 ld a,#0x01 
12282 \newline
12283 ED 79\InsetSpace ~
12284 \InsetSpace ~
12285 \InsetSpace ~
12286 \InsetSpace ~
12287 \InsetSpace ~
12288 \InsetSpace ~
12289 out (c),a 
12290 \end_layout
12291
12292 \begin_layout Subsubsection
12293 sfr
12294 \begin_inset LatexCommand \index{sfr}
12295
12296 \end_inset
12297
12298
12299 \begin_inset LatexCommand \index{\_\_sfr}
12300
12301 \end_inset
12302
12303  (in0/out0 to 8 bit addresses on Z180
12304 \begin_inset LatexCommand \index{Z180}
12305
12306 \end_inset
12307
12308 /HD64180
12309 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12310
12311 \end_inset
12312
12313 )
12314 \end_layout
12315
12316 \begin_layout Standard
12317 The compiler option -
12318 \begin_inset ERT
12319 status collapsed
12320
12321 \begin_layout Standard
12322
12323
12324 \backslash
12325 /
12326 \end_layout
12327
12328 \end_inset
12329
12330 -portmode
12331 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12332
12333 \end_inset
12334
12335 =180 (80) and a compiler #pragma\InsetSpace ~
12336 portmode
12337 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12338
12339 \end_inset
12340
12341  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12342 ns 
12343 \family typewriter
12344 in0/out0
12345 \family default
12346  instead of 
12347 \family typewriter
12348 in/out
12349 \family default
12350 .
12351  If you include the file z180.h this will be set automatically.
12352 \begin_inset VSpace bigskip
12353 \end_inset
12354
12355
12356 \end_layout
12357
12358 \begin_layout Subsection
12359 HC08 Storage Class
12360 \begin_inset LatexCommand \index{HC08!Storage class}
12361
12362 \end_inset
12363
12364  Language Extensions
12365 \end_layout
12366
12367 \begin_layout Subsubsection
12368 data
12369 \begin_inset LatexCommand \index{data (hc08 storage class)}
12370
12371 \end_inset
12372
12373
12374 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12375
12376 \end_inset
12377
12378  
12379 \end_layout
12380
12381 \begin_layout Standard
12382 The data storage class declares a variable that resides in the first 256
12383  bytes of memory (the direct page).
12384  The HC08
12385 \begin_inset LatexCommand \index{HC08}
12386
12387 \end_inset
12388
12389  is most efficient at accessing variables (especially pointers) stored here.
12390 \end_layout
12391
12392 \begin_layout Subsubsection
12393 xdata
12394 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12395
12396 \end_inset
12397
12398
12399 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12400
12401 \end_inset
12402
12403  
12404 \end_layout
12405
12406 \begin_layout Standard
12407 The xdata storage class declares a variable that can reside anywhere in
12408  memory.
12409  This is the default if no storage class is specified.
12410  
12411 \begin_inset VSpace bigskip
12412 \end_inset
12413
12414
12415 \end_layout
12416
12417 \begin_layout Section
12418 Absolute Addressing
12419 \begin_inset LatexCommand \index{Absolute addressing}
12420
12421 \end_inset
12422
12423
12424 \end_layout
12425
12426 \begin_layout Standard
12427 Data items can be assigned an absolute address with the 
12428 \emph on
12429 at
12430 \begin_inset LatexCommand \index{at}
12431
12432 \end_inset
12433
12434
12435 \begin_inset LatexCommand \index{\_\_at}
12436
12437 \end_inset
12438
12439  <address>
12440 \emph default
12441  keyword, in addition to a storage class, e.g.:
12442 \end_layout
12443
12444 \begin_layout Verse
12445
12446 \family typewriter
12447 xdata
12448 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12449
12450 \end_inset
12451
12452
12453 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12454
12455 \end_inset
12456
12457  at
12458 \begin_inset LatexCommand \index{at}
12459
12460 \end_inset
12461
12462
12463 \begin_inset LatexCommand \index{\_\_at}
12464
12465 \end_inset
12466
12467  0x7ffe unsigned int chksum;
12468 \end_layout
12469
12470 \begin_layout Standard
12471 or, better conforming to ISO/IEC 9899 C:
12472 \end_layout
12473
12474 \begin_layout Verse
12475
12476 \family typewriter
12477 __xdata __at (0x7ffe) unsigned int chksum;
12478 \end_layout
12479
12480 \begin_layout Standard
12481 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12482  of the external ram.
12483  The compiler does 
12484 \emph on
12485 not
12486 \emph default
12487  reserve any space for variables declared in this way
12488 \begin_inset Marginal
12489 status collapsed
12490
12491 \begin_layout Standard
12492
12493 \series bold
12494 \InsetSpace ~
12495 !
12496 \end_layout
12497
12498 \end_inset
12499
12500  (they are implemented with an equate in the assembler).
12501  Thus it is left to the programmer to make sure there are no overlaps with
12502  other variables that are declared without the absolute address.
12503  The assembler listing file (.lst
12504 \begin_inset LatexCommand \index{<file>.lst}
12505
12506 \end_inset
12507
12508 ) and the linker output files (.rst
12509 \begin_inset LatexCommand \index{<file>.rst}
12510
12511 \end_inset
12512
12513 ) and (.map
12514 \begin_inset LatexCommand \index{<file>.map}
12515
12516 \end_inset
12517
12518 ) are good places to look for such overlaps.
12519  Variables with an absolute address are 
12520 \emph on
12521 not
12522 \begin_inset Marginal
12523 status collapsed
12524
12525 \begin_layout Standard
12526
12527 \series bold
12528 \InsetSpace ~
12529 !
12530 \end_layout
12531
12532 \end_inset
12533
12534
12535 \emph default
12536  initialized
12537 \begin_inset LatexCommand \index{Variable initialization}
12538
12539 \end_inset
12540
12541 .
12542 \end_layout
12543
12544 \begin_layout Standard
12545 In case of memory mapped I/O devices the keyword 
12546 \emph on
12547 volatile
12548 \emph default
12549  has to be used to tell the compiler that accesses might not be removed:
12550 \end_layout
12551
12552 \begin_layout Verse
12553
12554 \family typewriter
12555 volatile
12556 \begin_inset LatexCommand \index{volatile}
12557
12558 \end_inset
12559
12560  __xdata
12561 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12562
12563 \end_inset
12564
12565  __at
12566 \begin_inset LatexCommand \index{at}
12567
12568 \end_inset
12569
12570  (0x8000) unsigned char PORTA_8255;
12571 \end_layout
12572
12573 \begin_layout Standard
12574 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12575 r) array
12576 \family typewriter
12577 \size footnotesize
12578
12579 \begin_inset LatexCommand \index{Aligned array}
12580
12581 \end_inset
12582
12583
12584 \family default
12585 \size default
12586  starts at a block (256 byte) boundary
12587 \begin_inset LatexCommand \index{block boundary}
12588
12589 \end_inset
12590
12591  (section 
12592 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12593
12594 \end_inset
12595
12596  has an example).
12597 \newline
12598 Absolute addresses can be specified for variables in all
12599  storage classes, e.g.:
12600 \end_layout
12601
12602 \begin_layout Verse
12603
12604 \family typewriter
12605 __bit
12606 \begin_inset LatexCommand \index{bit}
12607
12608 \end_inset
12609
12610  __at
12611 \begin_inset LatexCommand \index{at}
12612
12613 \end_inset
12614
12615  (0x02) bvar;
12616 \end_layout
12617
12618 \begin_layout Standard
12619 The above example will allocate the variable at offset 0x02 in the bit-addressab
12620 le space.
12621  There is no real advantage to assigning absolute addresses to variables
12622  in this manner, unless you want strict control over all the variables allocated.
12623  One possible use would be to write hardware portable code.
12624  For example, if you have a routine that uses one or more of the microcontroller
12625  I/O pins, and such pins are different for two different hardwares, you
12626  can declare the I/O pins in your routine using:
12627 \end_layout
12628
12629 \begin_layout Verse
12630
12631 \family typewriter
12632 extern volatile
12633 \begin_inset LatexCommand \index{volatile}
12634
12635 \end_inset
12636
12637  __bit MOSI;\InsetSpace ~
12638 \InsetSpace ~
12639 \InsetSpace ~
12640 \InsetSpace ~
12641 /* master out, slave in */
12642 \newline
12643 extern volatile __bit MISO;\InsetSpace ~
12644 \InsetSpace ~
12645 \InsetSpace ~
12646 \InsetSpace ~
12647 /* master
12648  in, slave out */
12649 \newline
12650 extern volatile __bit MCLK;\InsetSpace ~
12651 \InsetSpace ~
12652 \InsetSpace ~
12653 \InsetSpace ~
12654 /* master clock */
12655 \newline
12656
12657 \newline
12658 /* Input and
12659  Output of a byte on a 3-wire serial bus.
12660 \newline
12661 \InsetSpace ~
12662 \InsetSpace ~
12663 \InsetSpace ~
12664 If needed adapt polarity of clock,
12665  polarity of data and bit order
12666 \newline
12667 \InsetSpace ~
12668 */
12669 \newline
12670 unsigned char spi_io(unsigned char out_byte)
12671  
12672 \newline
12673
12674 \newline
12675 \InsetSpace ~
12676 \InsetSpace ~
12677 \InsetSpace ~
12678 \InsetSpace ~
12679 unsigned char i=8;
12680 \newline
12681 \InsetSpace ~
12682 \InsetSpace ~
12683 \InsetSpace ~
12684 \InsetSpace ~
12685 do { 
12686 \newline
12687 \InsetSpace ~
12688 \InsetSpace ~
12689 \InsetSpace ~
12690 \InsetSpace ~
12691 \InsetSpace ~
12692 \InsetSpace ~
12693 \InsetSpace ~
12694 \InsetSpace ~
12695 MOSI = out_byte & 0x80; 
12696 \newline
12697 \InsetSpace ~
12698 \InsetSpace ~
12699 \InsetSpace ~
12700 \InsetSpace ~
12701 \InsetSpace ~
12702 \InsetSpace ~
12703 \InsetSpace ~
12704 \InsetSpace ~
12705 out_byte <<= 1;
12706 \newline
12707 \InsetSpace ~
12708 \InsetSpace ~
12709 \InsetSpace ~
12710 \InsetSpace ~
12711 \InsetSpace ~
12712 \InsetSpace ~
12713 \InsetSpace ~
12714 \InsetSpace ~
12715 MCLK =
12716  1; 
12717 \newline
12718 \InsetSpace ~
12719 \InsetSpace ~
12720 \InsetSpace ~
12721 \InsetSpace ~
12722 \InsetSpace ~
12723 \InsetSpace ~
12724 \InsetSpace ~
12725 \InsetSpace ~
12726 /* _asm nop _endasm; */\InsetSpace ~
12727 \InsetSpace ~
12728 \InsetSpace ~
12729 \InsetSpace ~
12730 \InsetSpace ~
12731 \InsetSpace ~
12732 \InsetSpace ~
12733 \InsetSpace ~
12734 /* for slow peripherals */
12735 \newline
12736 \InsetSpace ~
12737 \InsetSpace ~
12738 \InsetSpace ~
12739 \InsetSpace ~
12740 \InsetSpace ~
12741 \InsetSpace ~
12742 \InsetSpace ~
12743 \InsetSpace ~
12744 if(MISO) 
12745 \newline
12746 \InsetSpace ~
12747 \InsetSpace ~
12748 \InsetSpace ~
12749 \InsetSpace ~
12750 \InsetSpace ~
12751 \InsetSpace ~
12752 \InsetSpace ~
12753 \InsetSpace ~
12754 \InsetSpace ~
12755 \InsetSpace ~
12756 \InsetSpace ~
12757 \InsetSpace ~
12758 out_byte +=
12759  1; 
12760 \newline
12761 \InsetSpace ~
12762 \InsetSpace ~
12763 \InsetSpace ~
12764 \InsetSpace ~
12765 \InsetSpace ~
12766 \InsetSpace ~
12767 \InsetSpace ~
12768 \InsetSpace ~
12769 MCLK = 0; 
12770 \newline
12771 \InsetSpace ~
12772 \InsetSpace ~
12773 \InsetSpace ~
12774 \InsetSpace ~
12775 } while(--i);
12776 \newline
12777 \InsetSpace ~
12778 \InsetSpace ~
12779 \InsetSpace ~
12780 \InsetSpace ~
12781 return out_byte; 
12782 \newline
12783 }
12784 \end_layout
12785
12786 \begin_layout Standard
12787 Then, someplace in the code for the first hardware you would use
12788 \end_layout
12789
12790 \begin_layout Verse
12791
12792 \family typewriter
12793 __bit __at
12794 \begin_inset LatexCommand \index{at}
12795
12796 \end_inset
12797
12798
12799 \begin_inset LatexCommand \index{\_\_at}
12800
12801 \end_inset
12802
12803  (0x80) MOSI;\InsetSpace ~
12804 \InsetSpace ~
12805 \InsetSpace ~
12806 \InsetSpace ~
12807 /* I/O port 0, bit 0 */
12808 \newline
12809 __bit __at (0x81) MISO;\InsetSpace ~
12810 \InsetSpace ~
12811 \InsetSpace ~
12812 \InsetSpace ~
12813 /* I/O port 0,
12814  bit 1 */
12815 \newline
12816 __bit __at (0x82) MCLK;\InsetSpace ~
12817 \InsetSpace ~
12818 \InsetSpace ~
12819 \InsetSpace ~
12820 /* I/O port 0, bit 2 */
12821 \end_layout
12822
12823 \begin_layout Standard
12824 Similarly, for the second hardware you would use
12825 \end_layout
12826
12827 \begin_layout Verse
12828
12829 \family typewriter
12830 __bit __at (0x83) MOSI;\InsetSpace ~
12831 \InsetSpace ~
12832 \InsetSpace ~
12833 \InsetSpace ~
12834 /* I/O port 0, bit 3 */
12835 \newline
12836 __bit __at (0x91) MISO;\InsetSpace ~
12837 \InsetSpace ~
12838 \InsetSpace ~
12839 \InsetSpace ~
12840 /*
12841  I/O port 1, bit 1 */
12842 \newline
12843 __bit
12844 \begin_inset LatexCommand \index{bit}
12845
12846 \end_inset
12847
12848  __at (0x92) MCLK;\InsetSpace ~
12849 \InsetSpace ~
12850 \InsetSpace ~
12851 \InsetSpace ~
12852 /* I/O port 1, bit 2 */
12853 \end_layout
12854
12855 \begin_layout Standard
12856 and you can use the same hardware dependent routine without changes, as
12857  for example in a library.
12858  This is somehow similar to sbit, but only one absolute address has to be
12859  specified in the whole project.
12860 \begin_inset VSpace bigskip
12861 \end_inset
12862
12863
12864 \end_layout
12865
12866 \begin_layout Section
12867 Parameters
12868 \begin_inset LatexCommand \index{Parameters}
12869
12870 \end_inset
12871
12872
12873 \begin_inset LatexCommand \index{function parameter}
12874
12875 \end_inset
12876
12877  & Local Variables
12878 \begin_inset LatexCommand \index{local variables}
12879
12880 \end_inset
12881
12882
12883 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12884
12885 \end_inset
12886
12887
12888 \end_layout
12889
12890 \begin_layout Standard
12891 Automatic (local) variables and parameters to functions can either be placed
12892  on the stack or in data-space.
12893  The default action of the compiler is to place these variables in the internal
12894  RAM (for small model) or external RAM (for large model).
12895  This in fact makes them similar to 
12896 \emph on
12897 static
12898 \begin_inset LatexCommand \index{static}
12899
12900 \end_inset
12901
12902
12903 \emph default
12904  so by default functions are non-reentrant
12905 \begin_inset LatexCommand \index{reentrant}
12906
12907 \end_inset
12908
12909 .
12910  
12911 \newline
12912
12913 \newline
12914 They can be placed on the stack
12915 \begin_inset LatexCommand \index{stack}
12916
12917 \end_inset
12918
12919  by using the
12920 \emph on
12921  -
12922 \begin_inset ERT
12923 status collapsed
12924
12925 \begin_layout Standard
12926
12927
12928 \backslash
12929 /
12930 \end_layout
12931
12932 \end_inset
12933
12934 -stack-auto
12935 \begin_inset LatexCommand \index{-\/-stack-auto}
12936
12937 \end_inset
12938
12939
12940 \emph default
12941  option, by using 
12942 \emph on
12943 #pragma\InsetSpace ~
12944 stackauto
12945 \emph default
12946
12947 \begin_inset LatexCommand \index{\#pragma stackauto}
12948
12949 \end_inset
12950
12951  or by using the 
12952 \emph on
12953 reentrant
12954 \begin_inset LatexCommand \index{reentrant}
12955
12956 \end_inset
12957
12958
12959 \emph default
12960  keyword in the function declaration, e.g.:
12961 \end_layout
12962
12963 \begin_layout Verse
12964
12965 \family typewriter
12966 unsigned char foo(char i) __reentrant 
12967 \newline
12968
12969 \newline
12970 \InsetSpace ~
12971 \InsetSpace ~
12972 \InsetSpace ~
12973 \InsetSpace ~
12974 ...
12975  
12976 \newline
12977 }
12978 \end_layout
12979
12980 \begin_layout Standard
12981 Since stack space on 8051 is limited, the 
12982 \emph on
12983 reentrant 
12984 \emph default
12985 keyword or the
12986 \emph on
12987  -
12988 \begin_inset ERT
12989 status collapsed
12990
12991 \begin_layout Standard
12992
12993
12994 \backslash
12995 /
12996 \end_layout
12997
12998 \end_inset
12999
13000 -stack-auto
13001 \emph default
13002  option should be used sparingly.
13003  Note that the reentrant keyword just means that the parameters & local
13004  variables will be allocated to the stack, it 
13005 \emph on
13006 does not
13007 \emph default
13008  mean that the function is register bank
13009 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13010
13011 \end_inset
13012
13013  independent.
13014 \newline
13015
13016 \newline
13017 Local variables
13018 \begin_inset LatexCommand \index{local variables}
13019
13020 \end_inset
13021
13022  can be assigned storage classes and absolute
13023 \begin_inset LatexCommand \index{Absolute addressing}
13024
13025 \end_inset
13026
13027  addresses, e.g.: 
13028 \end_layout
13029
13030 \begin_layout Verse
13031
13032 \family typewriter
13033 unsigned char foo() 
13034 \newline
13035 {
13036 \newline
13037 \InsetSpace ~
13038 \InsetSpace ~
13039 \InsetSpace ~
13040 \InsetSpace ~
13041 __xdata unsigned char i;
13042 \newline
13043 \InsetSpace ~
13044 \InsetSpace ~
13045 \InsetSpace ~
13046 \InsetSpace ~
13047 __bit bvar;
13048 \newline
13049 \InsetSpace ~
13050 \InsetSpace ~
13051 \InsetSpace ~
13052 \InsetSpace ~
13053 __data __at
13054 \begin_inset LatexCommand \index{at}
13055
13056 \end_inset
13057
13058  (0x31) unsigned char j;
13059 \newline
13060 \InsetSpace ~
13061 \InsetSpace ~
13062 \InsetSpace ~
13063 \InsetSpace ~
13064 ...
13065  
13066 \newline
13067 }
13068 \end_layout
13069
13070 \begin_layout Standard
13071 In the above example the variable 
13072 \emph on
13073 i
13074 \emph default
13075  will be allocated in the external ram, 
13076 \emph on
13077 bvar
13078 \emph default
13079  in bit addressable space and
13080 \emph on
13081  j
13082 \emph default
13083  in internal ram.
13084  When compiled with 
13085 \emph on
13086 -
13087 \begin_inset ERT
13088 status collapsed
13089
13090 \begin_layout Standard
13091
13092
13093 \backslash
13094 /
13095 \end_layout
13096
13097 \end_inset
13098
13099 -stack-auto
13100 \emph default
13101  or when a function is declared as 
13102 \emph on
13103 reentrant
13104 \emph default
13105  this should only be done for static variables.
13106 \end_layout
13107
13108 \begin_layout Standard
13109 Parameters
13110 \begin_inset LatexCommand \index{function parameter}
13111
13112 \end_inset
13113
13114  however are not allowed any storage class
13115 \begin_inset LatexCommand \index{Storage class}
13116
13117 \end_inset
13118
13119 , (storage classes for parameters will be ignored), their allocation is
13120  governed by the memory model in use, and the reentrancy options.
13121 \end_layout
13122
13123 \begin_layout Standard
13124 It is however allowed to use bit parameters in reentrant functions and also
13125  non-static local bit variables are supported.
13126  Efficient use is limited to 8 semi-bitregisters in bit space.
13127  They are pushed and popped to stack
13128 \begin_inset LatexCommand \index{stack}
13129
13130 \end_inset
13131
13132  as a single byte just like the normal registers.
13133 \end_layout
13134
13135 \begin_layout Section
13136 Overlaying
13137 \begin_inset LatexCommand \label{sub:Overlaying}
13138
13139 \end_inset
13140
13141
13142 \begin_inset LatexCommand \index{Overlaying}
13143
13144 \end_inset
13145
13146
13147 \end_layout
13148
13149 \begin_layout Standard
13150 For non-reentrant
13151 \begin_inset LatexCommand \index{reentrant}
13152
13153 \end_inset
13154
13155  functions SDCC will try to reduce internal ram space usage by overlaying
13156  parameters and local variables of a function (if possible).
13157  Parameters and local variables
13158 \begin_inset LatexCommand \index{local variables}
13159
13160 \end_inset
13161
13162  of a function will be allocated to an overlayable segment if the function
13163  has 
13164 \emph on
13165 no other function calls and the function is non-reentrant and the memory
13166  model
13167 \begin_inset LatexCommand \index{Memory model}
13168
13169 \end_inset
13170
13171  is small.
13172
13173 \emph default
13174  If an explicit storage class
13175 \begin_inset LatexCommand \index{Storage class}
13176
13177 \end_inset
13178
13179  is specified for a local variable, it will NOT be overlayed.
13180 \end_layout
13181
13182 \begin_layout Standard
13183 Note that the compiler (not the linkage editor) makes the decision for overlayin
13184 g the data items.
13185  Functions that are called from an interrupt service routine
13186 \begin_inset Marginal
13187 status collapsed
13188
13189 \begin_layout Standard
13190
13191 \series bold
13192 !
13193 \end_layout
13194
13195 \end_inset
13196
13197  should be preceded by a #pragma\InsetSpace ~
13198 nooverlay
13199 \begin_inset LatexCommand \index{\#pragma nooverlay}
13200
13201 \end_inset
13202
13203  if they are not reentrant.
13204 \end_layout
13205
13206 \begin_layout Standard
13207 Also note that the compiler does not do any processing of inline assembler
13208  code, so the compiler might incorrectly assign local variables and parameters
13209  of a function into the overlay segment if the inline assembler code calls
13210  other c-functions that might use the overlay.
13211  In that case the #pragma\InsetSpace ~
13212 nooverlay should be used.
13213 \end_layout
13214
13215 \begin_layout Standard
13216 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13217 tion
13218 \begin_inset LatexCommand \index{Multiplication}
13219
13220 \end_inset
13221
13222  or division
13223 \begin_inset LatexCommand \index{Division}
13224
13225 \end_inset
13226
13227  will NOT be overlayed since these are implemented using external functions,
13228  e.g.:
13229 \end_layout
13230
13231 \begin_layout Verse
13232
13233 \family typewriter
13234 #pragma save 
13235 \newline
13236 #pragma nooverlay
13237 \begin_inset LatexCommand \index{\#pragma nooverlay}
13238
13239 \end_inset
13240
13241  
13242 \newline
13243 void set_error(unsigned char errcd) 
13244 \newline
13245 {
13246 \newline
13247 \InsetSpace ~
13248 \InsetSpace ~
13249 \InsetSpace ~
13250 \InsetSpace ~
13251 P3 = errcd;
13252 \newline
13253
13254 \newline
13255 #pragma restore 
13256 \newline
13257
13258 \newline
13259 void
13260  some_isr () __interrupt
13261 \begin_inset LatexCommand \index{interrupt}
13262
13263 \end_inset
13264
13265  (2)
13266 \newline
13267 {
13268 \newline
13269 \InsetSpace ~
13270 \InsetSpace ~
13271 \InsetSpace ~
13272 \InsetSpace ~
13273 ...
13274 \newline
13275 \InsetSpace ~
13276 \InsetSpace ~
13277 \InsetSpace ~
13278 \InsetSpace ~
13279 set_error(10);
13280 \newline
13281 \InsetSpace ~
13282 \InsetSpace ~
13283 \InsetSpace ~
13284 \InsetSpace ~
13285 ...
13286  
13287 \newline
13288 }
13289 \end_layout
13290
13291 \begin_layout Standard
13292 In the above example the parameter 
13293 \emph on
13294 errcd
13295 \emph default
13296  for the function 
13297 \emph on
13298 set_error
13299 \emph default
13300  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13301 nooverlay was
13302  not present, this could cause unpredictable runtime behavior when called
13303  from an interrupt service routine.
13304  The #pragma\InsetSpace ~
13305 nooverlay ensures that the parameters and local variables for
13306  the function are NOT overlayed.
13307 \begin_inset VSpace bigskip
13308 \end_inset
13309
13310
13311 \end_layout
13312
13313 \begin_layout Section
13314 Interrupt Service Routines
13315 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13316
13317 \end_inset
13318
13319
13320 \end_layout
13321
13322 \begin_layout Subsection
13323 General Information
13324 \end_layout
13325
13326 \begin_layout Standard
13327 SDCC allows 
13328 \emph on
13329 i
13330 \emph default
13331 nterrupt 
13332 \emph on
13333 s
13334 \emph default
13335 ervice 
13336 \emph on
13337 r
13338 \emph default
13339 outines to be coded in C, with some extended keywords.
13340 \end_layout
13341
13342 \begin_layout Verse
13343
13344 \family typewriter
13345 void timer_isr (void) __interrupt (1) __using (1) 
13346 \newline
13347
13348 \newline
13349 \InsetSpace ~
13350 \InsetSpace ~
13351 \InsetSpace ~
13352 \InsetSpace ~
13353 ...
13354  
13355 \newline
13356 }
13357 \end_layout
13358
13359 \begin_layout Standard
13360 The optional number following the 
13361 \emph on
13362 interrupt
13363 \begin_inset LatexCommand \index{interrupt}
13364
13365 \end_inset
13366
13367
13368 \begin_inset LatexCommand \index{\_\_interrupt}
13369
13370 \end_inset
13371
13372
13373 \emph default
13374  keyword is the interrupt number this routine will service.
13375  When present, the compiler will insert a call to this routine in the interrupt
13376  vector table
13377 \begin_inset LatexCommand \index{interrupt vector table}
13378
13379 \end_inset
13380
13381  for the interrupt number specified.
13382  If you have multiple source files in your project, interrupt service routines
13383  can be present in any of them, but a prototype of the isr MUST be present
13384  or included in the file that contains the function 
13385 \emph on
13386 main
13387 \emph default
13388 .
13389  The optional (8051 specific) keyword 
13390 \emph on
13391 using
13392 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13393
13394 \end_inset
13395
13396
13397 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13398
13399 \end_inset
13400
13401
13402 \emph default
13403  can be used to tell the compiler to use the specified register bank when
13404  generating code for this function.
13405  
13406 \newline
13407 Interrupt service routines open the door for some very interesting bugs:
13408 \end_layout
13409
13410 \begin_layout Subsubsection
13411 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13412
13413 \end_inset
13414
13415 Common interrupt pitfall: variable not declared 
13416 \emph on
13417 volatile
13418 \end_layout
13419
13420 \begin_layout Standard
13421 If an interrupt service routine changes variables which are accessed by
13422  other functions these variables have to be declared 
13423 \emph on
13424 volatile
13425 \emph default
13426
13427 \begin_inset LatexCommand \index{volatile}
13428
13429 \end_inset
13430
13431 .
13432  See 
13433 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13434
13435 \end_inset
13436
13437  .
13438 \end_layout
13439
13440 \begin_layout Subsubsection
13441 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13442
13443 \end_inset
13444
13445 Common interrupt pitfall: 
13446 \emph on
13447 non-atomic access
13448 \end_layout
13449
13450 \begin_layout Standard
13451 If the access to these variables is not 
13452 \emph on
13453 atomic
13454 \begin_inset LatexCommand \index{atomic}
13455
13456 \end_inset
13457
13458
13459 \emph default
13460  (i.e.
13461  the processor needs more than one instruction for the access and could
13462  be interrupted while accessing the variable) the interrupt must be disabled
13463  during the access to avoid inconsistent data.
13464  
13465 \newline
13466 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13467  and should be protected by disabling interrupts.
13468  You're not automatically on the safe side if you use 8 bit variables though.
13469  We need an example here: f.e.
13470  on the 8051 the harmless looking 
13471 \begin_inset Quotes srd
13472 \end_inset
13473
13474
13475 \family typewriter
13476 flags\InsetSpace ~
13477 |=\InsetSpace ~
13478 0x80;
13479 \family default
13480
13481 \begin_inset Quotes sld
13482 \end_inset
13483
13484  is not atomic if 
13485 \family typewriter
13486 flags
13487 \family default
13488  resides in xdata.
13489  Setting 
13490 \begin_inset Quotes srd
13491 \end_inset
13492
13493
13494 \family typewriter
13495 flags\InsetSpace ~
13496 |=\InsetSpace ~
13497 0x40;
13498 \family default
13499
13500 \begin_inset Quotes sld
13501 \end_inset
13502
13503  from within an interrupt routine might get lost if the interrupt occurs
13504  at the wrong time.
13505  
13506 \begin_inset Quotes sld
13507 \end_inset
13508
13509
13510 \family typewriter
13511 counter\InsetSpace ~
13512 +=\InsetSpace ~
13513 8;
13514 \family default
13515
13516 \begin_inset Quotes srd
13517 \end_inset
13518
13519  is not atomic on the 8051 even if 
13520 \family typewriter
13521 counter
13522 \family default
13523  is located in data memory.
13524 \newline
13525 Bugs like these are hard to reproduce and can
13526  cause a lot of trouble.
13527  
13528 \end_layout
13529
13530 \begin_layout Subsubsection
13531 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13532
13533 \end_inset
13534
13535 Common interrupt pitfall: 
13536 \emph on
13537 stack overflow
13538 \end_layout
13539
13540 \begin_layout Standard
13541 The return address and the registers used in the interrupt service routine
13542  are saved on the stack
13543 \begin_inset LatexCommand \index{stack}
13544
13545 \end_inset
13546
13547  so there must be sufficient stack space.
13548  If there isn't variables or registers (or even the return address itself)
13549  will be corrupted.
13550  This 
13551 \emph on
13552 stack overflow
13553 \emph default
13554
13555 \begin_inset LatexCommand \index{stack overflow}
13556
13557 \end_inset
13558
13559  is most likely to happen if the interrupt occurs during the 
13560 \begin_inset Quotes sld
13561 \end_inset
13562
13563 deepest
13564 \begin_inset Quotes srd
13565 \end_inset
13566
13567  subroutine when the stack is already in use for f.e.
13568  many return addresses.
13569 \end_layout
13570
13571 \begin_layout Subsubsection
13572 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13573
13574 \end_inset
13575
13576 Common interrupt pitfall: 
13577 \emph on
13578 use of non-reentrant functions
13579 \end_layout
13580
13581 \begin_layout Standard
13582 A special note here, int (16 bit) and long (32 bit) integer division
13583 \begin_inset LatexCommand \index{Division}
13584
13585 \end_inset
13586
13587 , multiplication
13588 \begin_inset LatexCommand \index{Multiplication}
13589
13590 \end_inset
13591
13592  & modulus
13593 \begin_inset LatexCommand \index{Modulus}
13594
13595 \end_inset
13596
13597  and floating-point
13598 \begin_inset LatexCommand \index{Floating point support}
13599
13600 \end_inset
13601
13602  operations are implemented using external support routines.
13603  If an interrupt service routine needs to do any of these operations then
13604  the support routines (as mentioned in a following section) will have to
13605  be recompiled using the
13606 \emph on
13607  -
13608 \begin_inset ERT
13609 status collapsed
13610
13611 \begin_layout Standard
13612
13613
13614 \backslash
13615 /
13616 \end_layout
13617
13618 \end_inset
13619
13620 -stack-auto
13621 \begin_inset LatexCommand \index{-\/-stack-auto}
13622
13623 \end_inset
13624
13625
13626 \emph default
13627  option and the source file will need to be compiled using the 
13628 \emph on
13629 -
13630 \begin_inset ERT
13631 status collapsed
13632
13633 \begin_layout Standard
13634
13635
13636 \backslash
13637 /
13638 \end_layout
13639
13640 \end_inset
13641
13642 -int-long-reent
13643 \emph default
13644
13645 \begin_inset LatexCommand \index{-\/-int-long-reent}
13646
13647 \end_inset
13648
13649  compiler option.
13650  
13651 \newline
13652 Note, the type promotion
13653 \begin_inset LatexCommand \index{type promotion}
13654
13655 \end_inset
13656
13657  required by ANSI C can cause 16 bit routines to be used
13658 \begin_inset Marginal
13659 status collapsed
13660
13661 \begin_layout Standard
13662
13663 \series bold
13664 \InsetSpace ~
13665 !
13666 \end_layout
13667
13668 \end_inset
13669
13670  without the programmer being aware of it.
13671  See f.e.
13672  the cast 
13673 \family typewriter
13674 (unsigned char)(tail-1)
13675 \family default
13676  within the if clause in section 
13677 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13678
13679 \end_inset
13680
13681 .
13682 \end_layout
13683
13684 \begin_layout Standard
13685 Calling other functions from an interrupt service routine is not recommended,
13686  avoid it if possible.
13687  Note that when some function is called from an interrupt service routine
13688  it should be preceded by a #pragma\InsetSpace ~
13689 nooverlay
13690 \begin_inset LatexCommand \index{\#pragma nooverlay}
13691
13692 \end_inset
13693
13694  if it is not reentrant.
13695  Furthermore nonreentrant functions should not be called from the main program
13696  while the interrupt service routine might be active.
13697  They also must not be called from low priority interrupt service routines
13698  while a high priority interrupt service routine might be active.
13699  You could use semaphores or make the function
13700 \emph on
13701  critical
13702 \emph default
13703  if all parameters are passed in registers.
13704 \newline
13705  Also see section 
13706 \begin_inset LatexCommand \ref{sub:Overlaying}
13707
13708 \end_inset
13709
13710 \InsetSpace ~
13711 about Overlaying and section 
13712 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13713
13714 \end_inset
13715
13716 \InsetSpace ~
13717 about Functions using private register banks.
13718 \begin_inset VSpace bigskip
13719 \end_inset
13720
13721
13722 \end_layout
13723
13724 \begin_layout Subsection
13725 MCS51/DS390 Interrupt Service Routines
13726 \end_layout
13727
13728 \begin_layout Standard
13729 Interrupt
13730 \begin_inset LatexCommand \index{interrupt}
13731
13732 \end_inset
13733
13734  numbers and the corresponding address & descriptions for the Standard 8051/8052
13735  are listed below.
13736  SDCC will automatically adjust the 
13737 \begin_inset LatexCommand \index{interrupt vector table}
13738
13739 \end_inset
13740
13741  to the maximum interrupt number specified.
13742 \newline
13743
13744 \end_layout
13745
13746 \begin_layout Standard
13747 \align center
13748 \begin_inset Tabular
13749 <lyxtabular version="3" rows="9" columns="3">
13750 <features>
13751 <column alignment="center" valignment="top" leftline="true" width="0in">
13752 <column alignment="left" valignment="top" leftline="true" width="0in">
13753 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13754 <row topline="true" bottomline="true">
13755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13756 \begin_inset Text
13757
13758 \begin_layout Standard
13759 Interrupt #
13760 \end_layout
13761
13762 \end_inset
13763 </cell>
13764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13765 \begin_inset Text
13766
13767 \begin_layout Standard
13768 Description
13769 \end_layout
13770
13771 \end_inset
13772 </cell>
13773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13774 \begin_inset Text
13775
13776 \begin_layout Standard
13777 Vector Address
13778 \end_layout
13779
13780 \end_inset
13781 </cell>
13782 </row>
13783 <row topline="true">
13784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13785 \begin_inset Text
13786
13787 \begin_layout Standard
13788 0
13789 \end_layout
13790
13791 \end_inset
13792 </cell>
13793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13794 \begin_inset Text
13795
13796 \begin_layout Standard
13797 External 0
13798 \end_layout
13799
13800 \end_inset
13801 </cell>
13802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13803 \begin_inset Text
13804
13805 \begin_layout Standard
13806 0x0003
13807 \end_layout
13808
13809 \end_inset
13810 </cell>
13811 </row>
13812 <row topline="true">
13813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13814 \begin_inset Text
13815
13816 \begin_layout Standard
13817 1
13818 \end_layout
13819
13820 \end_inset
13821 </cell>
13822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13823 \begin_inset Text
13824
13825 \begin_layout Standard
13826 Timer 0
13827 \end_layout
13828
13829 \end_inset
13830 </cell>
13831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13832 \begin_inset Text
13833
13834 \begin_layout Standard
13835 0x000b
13836 \end_layout
13837
13838 \end_inset
13839 </cell>
13840 </row>
13841 <row topline="true">
13842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13843 \begin_inset Text
13844
13845 \begin_layout Standard
13846 2
13847 \end_layout
13848
13849 \end_inset
13850 </cell>
13851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13852 \begin_inset Text
13853
13854 \begin_layout Standard
13855 External 1
13856 \end_layout
13857
13858 \end_inset
13859 </cell>
13860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13861 \begin_inset Text
13862
13863 \begin_layout Standard
13864 0x0013
13865 \end_layout
13866
13867 \end_inset
13868 </cell>
13869 </row>
13870 <row topline="true">
13871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13872 \begin_inset Text
13873
13874 \begin_layout Standard
13875 3
13876 \end_layout
13877
13878 \end_inset
13879 </cell>
13880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13881 \begin_inset Text
13882
13883 \begin_layout Standard
13884 Timer 1
13885 \end_layout
13886
13887 \end_inset
13888 </cell>
13889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13890 \begin_inset Text
13891
13892 \begin_layout Standard
13893 0x001b
13894 \end_layout
13895
13896 \end_inset
13897 </cell>
13898 </row>
13899 <row topline="true">
13900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13901 \begin_inset Text
13902
13903 \begin_layout Standard
13904 4
13905 \end_layout
13906
13907 \end_inset
13908 </cell>
13909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13910 \begin_inset Text
13911
13912 \begin_layout Standard
13913 Serial
13914 \end_layout
13915
13916 \end_inset
13917 </cell>
13918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13919 \begin_inset Text
13920
13921 \begin_layout Standard
13922 0x0023
13923 \end_layout
13924
13925 \end_inset
13926 </cell>
13927 </row>
13928 <row topline="true">
13929 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13930 \begin_inset Text
13931
13932 \begin_layout Standard
13933 5
13934 \end_layout
13935
13936 \end_inset
13937 </cell>
13938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13939 \begin_inset Text
13940
13941 \begin_layout Standard
13942 Timer 2 (8052)
13943 \end_layout
13944
13945 \end_inset
13946 </cell>
13947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13948 \begin_inset Text
13949
13950 \begin_layout Standard
13951 0x002b
13952 \end_layout
13953
13954 \end_inset
13955 </cell>
13956 </row>
13957 <row topline="true">
13958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13959 \begin_inset Text
13960
13961 \begin_layout Standard
13962 ...
13963 \end_layout
13964
13965 \end_inset
13966 </cell>
13967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13968 \begin_inset Text
13969
13970 \begin_layout Standard
13971
13972 \end_layout
13973
13974 \end_inset
13975 </cell>
13976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13977 \begin_inset Text
13978
13979 \begin_layout Standard
13980 ...
13981 \end_layout
13982
13983 \end_inset
13984 </cell>
13985 </row>
13986 <row topline="true" bottomline="true">
13987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13988 \begin_inset Text
13989
13990 \begin_layout Standard
13991 n
13992 \end_layout
13993
13994 \end_inset
13995 </cell>
13996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13997 \begin_inset Text
13998
13999 \begin_layout Standard
14000
14001 \end_layout
14002
14003 \end_inset
14004 </cell>
14005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14006 \begin_inset Text
14007
14008 \begin_layout Standard
14009 0x0003 + 8*n
14010 \end_layout
14011
14012 \end_inset
14013 </cell>
14014 </row>
14015 </lyxtabular>
14016
14017 \end_inset
14018
14019
14020 \newline
14021
14022 \end_layout
14023
14024 \begin_layout Standard
14025 If the interrupt service routine is defined without 
14026 \emph on
14027 using
14028 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14029
14030 \end_inset
14031
14032
14033 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14034
14035 \end_inset
14036
14037
14038 \emph default
14039  a register bank or with register bank 0 (
14040 \emph on
14041 using
14042 \emph default
14043  0), the compiler will save the registers used by itself on the stack upon
14044  entry and restore them at exit, however if such an interrupt service routine
14045  calls another function then the entire register bank will be saved on the
14046  stack.
14047  This scheme may be advantageous for small interrupt service routines which
14048  have low register usage.
14049 \end_layout
14050
14051 \begin_layout Standard
14052 If the interrupt service routine is defined to be using a specific register
14053  bank then only 
14054 \emph on
14055 a, b, dptr
14056 \emph default
14057  & psw are saved and restored, if such an interrupt service routine calls
14058  another function (using another register bank) then the entire register
14059  bank of the called function will be saved on the stack
14060 \begin_inset LatexCommand \index{stack}
14061
14062 \end_inset
14063
14064 .
14065  This scheme is recommended for larger interrupt service routines.
14066 \begin_inset VSpace bigskip
14067 \end_inset
14068
14069
14070 \end_layout
14071
14072 \begin_layout Subsection
14073 HC08
14074 \begin_inset LatexCommand \index{HC08}
14075
14076 \end_inset
14077
14078  Interrupt Service Routines
14079 \end_layout
14080
14081 \begin_layout Standard
14082 Since the number of interrupts
14083 \begin_inset LatexCommand \index{HC08!interrupt}
14084
14085 \end_inset
14086
14087  available is chip specific and the interrupt vector table always ends at
14088  the last byte of memory, the interrupt numbers corresponds to the interrupt
14089  vectors in reverse order of address.
14090  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14091  2 will use the interrupt vector at 0xfffa, and so on.
14092  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14093  this way; instead see section 
14094 \begin_inset LatexCommand \ref{sub:Startup-Code}
14095
14096 \end_inset
14097
14098  for details on customizing startup.
14099 \begin_inset VSpace bigskip
14100 \end_inset
14101
14102
14103 \end_layout
14104
14105 \begin_layout Subsection
14106 Z80 Interrupt Service Routines
14107 \end_layout
14108
14109 \begin_layout Standard
14110 The Z80
14111 \begin_inset LatexCommand \index{Z80}
14112
14113 \end_inset
14114
14115  uses several different methods for determining the correct interrupt
14116 \begin_inset LatexCommand \index{Z80!interrupt}
14117
14118 \end_inset
14119
14120  vector depending on the hardware implementation.
14121  Therefore, SDCC ignores the optional interrupt number and does not attempt
14122  to generate an interrupt vector table.
14123 \end_layout
14124
14125 \begin_layout Standard
14126 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14127  instruction to return from the interrupt.
14128  To write an interrupt handler for the non-maskable interrupt, which needs
14129  a RETN instruction instead, add the 
14130 \emph on
14131 critical
14132 \emph default
14133  keyword:
14134 \end_layout
14135
14136 \begin_layout Verse
14137
14138 \family typewriter
14139 void nmi_isr (void) critical interrupt
14140 \newline
14141
14142 \newline
14143 \InsetSpace ~
14144 \InsetSpace ~
14145 \InsetSpace ~
14146 \InsetSpace ~
14147 ...
14148  
14149 \newline
14150 }
14151 \end_layout
14152
14153 \begin_layout Standard
14154 However if you need to create a non-interruptable interrupt service routine
14155  you would also require the 
14156 \emph on
14157 critical
14158 \emph default
14159  keyword.
14160  To distinguish between this and an nmi_isr you must provide an interrupt
14161  number.
14162 \begin_inset VSpace bigskip
14163 \end_inset
14164
14165
14166 \end_layout
14167
14168 \begin_layout Section
14169 Enabling and Disabling Interrupts
14170 \end_layout
14171
14172 \begin_layout Subsection
14173 Critical Functions and Critical Statements
14174 \end_layout
14175
14176 \begin_layout Standard
14177 A special keyword may be associated with a block or a function declaring
14178  it as 
14179 \emph on
14180 critical
14181 \emph default
14182 .
14183  SDCC will generate code to disable all interrupts
14184 \begin_inset LatexCommand \index{interrupt}
14185
14186 \end_inset
14187
14188  upon entry to a critical function and restore the interrupt enable to the
14189  previous state before returning.
14190  Nesting critical functions will need one additional byte on the stack
14191 \begin_inset LatexCommand \index{stack}
14192
14193 \end_inset
14194
14195  for each call.
14196 \end_layout
14197
14198 \begin_layout Verse
14199
14200 \family typewriter
14201 int foo () __critical
14202 \begin_inset LatexCommand \index{critical}
14203
14204 \end_inset
14205
14206
14207 \begin_inset LatexCommand \index{\_\_critical}
14208
14209 \end_inset
14210
14211  
14212 \newline
14213
14214 \newline
14215 \InsetSpace ~
14216 \InsetSpace ~
14217 \InsetSpace ~
14218 \InsetSpace ~
14219 ...
14220  
14221 \newline
14222 \InsetSpace ~
14223 \InsetSpace ~
14224 \InsetSpace ~
14225 \InsetSpace ~
14226 ...
14227  
14228 \newline
14229 }
14230 \end_layout
14231
14232 \begin_layout Standard
14233 The critical attribute maybe used with other attributes like 
14234 \emph on
14235 reentrant.
14236 \emph default
14237
14238 \newline
14239 The keyword 
14240 \emph on
14241 critical
14242 \emph default
14243  may also be used to disable interrupts more locally:
14244 \end_layout
14245
14246 \begin_layout Verse
14247
14248 \family typewriter
14249 __critical{ i++; }
14250 \end_layout
14251
14252 \begin_layout Standard
14253 More than one statement could have been included in the block.
14254 \end_layout
14255
14256 \begin_layout Subsection
14257 Enabling and Disabling Interrupts directly
14258 \end_layout
14259
14260 \begin_layout Standard
14261 Interrupts
14262 \begin_inset LatexCommand \index{interrupt}
14263
14264 \end_inset
14265
14266  can also be disabled and enabled directly (8051):
14267 \end_layout
14268
14269 \begin_layout Verse
14270
14271 \family typewriter
14272 EA = 0;\InsetSpace ~
14273 \InsetSpace ~
14274 \InsetSpace ~
14275 \InsetSpace ~
14276 \InsetSpace ~
14277 \InsetSpace ~
14278 \InsetSpace ~
14279 \InsetSpace ~
14280 \InsetSpace ~
14281 \InsetSpace ~
14282 \InsetSpace ~
14283 \InsetSpace ~
14284 or:\InsetSpace ~
14285 \InsetSpace ~
14286 \InsetSpace ~
14287 \InsetSpace ~
14288 \InsetSpace ~
14289 \InsetSpace ~
14290 \InsetSpace ~
14291 \InsetSpace ~
14292 \InsetSpace ~
14293 \InsetSpace ~
14294 \InsetSpace ~
14295 EA_SAVE = EA;
14296 \end_layout
14297
14298 \begin_layout Verse
14299
14300 \family typewriter
14301 ...\InsetSpace ~
14302 \InsetSpace ~
14303 \InsetSpace ~
14304 \InsetSpace ~
14305 \InsetSpace ~
14306 \InsetSpace ~
14307 \InsetSpace ~
14308 \InsetSpace ~
14309 \InsetSpace ~
14310 \InsetSpace ~
14311 \InsetSpace ~
14312 \InsetSpace ~
14313 \InsetSpace ~
14314 \InsetSpace ~
14315 \InsetSpace ~
14316 \InsetSpace ~
14317 \InsetSpace ~
14318 \InsetSpace ~
14319 \InsetSpace ~
14320 \InsetSpace ~
14321 \InsetSpace ~
14322 \InsetSpace ~
14323 \InsetSpace ~
14324 \InsetSpace ~
14325 \InsetSpace ~
14326 \InsetSpace ~
14327 \InsetSpace ~
14328 \InsetSpace ~
14329 \InsetSpace ~
14330 \InsetSpace ~
14331 EA = 0;
14332 \end_layout
14333
14334 \begin_layout Verse
14335
14336 \family typewriter
14337 EA = 1;\InsetSpace ~
14338 \InsetSpace ~
14339 \InsetSpace ~
14340 \InsetSpace ~
14341 \InsetSpace ~
14342 \InsetSpace ~
14343 \InsetSpace ~
14344 \InsetSpace ~
14345 \InsetSpace ~
14346 \InsetSpace ~
14347 \InsetSpace ~
14348 \InsetSpace ~
14349 \InsetSpace ~
14350 \InsetSpace ~
14351 \InsetSpace ~
14352 \InsetSpace ~
14353 \InsetSpace ~
14354 \InsetSpace ~
14355 \InsetSpace ~
14356 \InsetSpace ~
14357 \InsetSpace ~
14358 \InsetSpace ~
14359 \InsetSpace ~
14360 \InsetSpace ~
14361 \InsetSpace ~
14362 \InsetSpace ~
14363 ...
14364 \end_layout
14365
14366 \begin_layout Verse
14367
14368 \family typewriter
14369 \InsetSpace ~
14370 \InsetSpace ~
14371 \InsetSpace ~
14372 \InsetSpace ~
14373 \InsetSpace ~
14374 \InsetSpace ~
14375 \InsetSpace ~
14376 \InsetSpace ~
14377 \InsetSpace ~
14378 \InsetSpace ~
14379 \InsetSpace ~
14380 \InsetSpace ~
14381 \InsetSpace ~
14382 \InsetSpace ~
14383 \InsetSpace ~
14384 \InsetSpace ~
14385 \InsetSpace ~
14386 \InsetSpace ~
14387 \InsetSpace ~
14388 \InsetSpace ~
14389 \InsetSpace ~
14390 \InsetSpace ~
14391 \InsetSpace ~
14392 \InsetSpace ~
14393 \InsetSpace ~
14394 \InsetSpace ~
14395 \InsetSpace ~
14396 \InsetSpace ~
14397 \InsetSpace ~
14398 \InsetSpace ~
14399 \InsetSpace ~
14400 \InsetSpace ~
14401 \InsetSpace ~
14402 EA = EA_SAVE;
14403 \end_layout
14404
14405 \begin_layout Standard
14406 On other architectures which have seperate opcodes for enabling and disabling
14407  interrupts you might want to make use of defines with inline assembly
14408 \begin_inset LatexCommand \index{Assembler routines}
14409
14410 \end_inset
14411
14412  (HC08
14413 \begin_inset LatexCommand \index{HC08!interrupt}
14414
14415 \end_inset
14416
14417 ):
14418 \end_layout
14419
14420 \begin_layout Verse
14421
14422 \family typewriter
14423 #define CLI _asm
14424 \begin_inset LatexCommand \index{\_asm}
14425
14426 \end_inset
14427
14428 \InsetSpace ~
14429 \InsetSpace ~
14430 cli\InsetSpace ~
14431 \InsetSpace ~
14432 _endasm
14433 \begin_inset LatexCommand \index{\_endasm}
14434
14435 \end_inset
14436
14437
14438 \end_layout
14439
14440 \begin_layout Verse
14441
14442 \family typewriter
14443 #define SEI _asm\InsetSpace ~
14444 \InsetSpace ~
14445 sei\InsetSpace ~
14446 \InsetSpace ~
14447 _endasm; 
14448 \end_layout
14449
14450 \begin_layout Verse
14451
14452 \family typewriter
14453 ...
14454 \end_layout
14455
14456 \begin_layout Standard
14457 Note: it is sometimes sufficient to disable only a specific interrupt source
14458  like f.e.
14459  a timer or serial interrupt by manipulating an 
14460 \emph on
14461 interrupt mask
14462 \begin_inset LatexCommand \index{interrupt mask}
14463
14464 \end_inset
14465
14466
14467 \emph default
14468  register.
14469  
14470 \end_layout
14471
14472 \begin_layout Standard
14473 Usually the time during which interrupts are disabled should be kept as
14474  short as possible.
14475  This minimizes both 
14476 \emph on
14477 interrupt latency
14478 \emph default
14479
14480 \begin_inset LatexCommand \index{interrupt latency}
14481
14482 \end_inset
14483
14484  (the time between the occurrence of the interrupt and the execution of
14485  the first code in the interrupt routine) and 
14486 \emph on
14487 interrupt jitter
14488 \emph default
14489
14490 \begin_inset LatexCommand \index{interrupt jitter}
14491
14492 \end_inset
14493
14494  (the difference between the shortest and the longest interrupt latency).
14495  These really are something different, f.e.
14496  a serial interrupt has to be served before its buffer overruns so it cares
14497  for the maximum interrupt latency, whereas it does not care about jitter.
14498  On a loudspeaker driven via a digital to analog converter which is fed
14499  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14500  a much smaller jitter will be very audible.
14501 \end_layout
14502
14503 \begin_layout Standard
14504 You can reenable interrupts within an interrupt routine and on some architecture
14505 s you can make use of two (or more) levels of 
14506 \emph on
14507 interrupt priorities
14508 \emph default
14509
14510 \begin_inset LatexCommand \index{interrupt priority}
14511
14512 \end_inset
14513
14514 .
14515  On some architectures which don't support interrupt priorities these can
14516  be implemented by manipulating the interrupt mask and reenabling interrupts
14517  within the interrupt routine.
14518  Check there is sufficient space on the stack
14519 \begin_inset LatexCommand \index{stack}
14520
14521 \end_inset
14522
14523  and don't add complexity unless you have to.
14524  
14525 \end_layout
14526
14527 \begin_layout Subsection
14528 Semaphore
14529 \begin_inset LatexCommand \index{semaphore}
14530
14531 \end_inset
14532
14533  locking (mcs51/ds390)
14534 \end_layout
14535
14536 \begin_layout Standard
14537 Some architectures (mcs51/ds390) have an atomic
14538 \begin_inset LatexCommand \index{atomic}
14539
14540 \end_inset
14541
14542  bit test and
14543 \emph on
14544  
14545 \emph default
14546 clear
14547 \emph on
14548  
14549 \emph default
14550 instruction.
14551  These type of instructions are typically used in preemptive multitasking
14552  systems, where a routine f.e.
14553  claims the use of a data structure ('acquires a lock
14554 \begin_inset LatexCommand \index{lock}
14555
14556 \end_inset
14557
14558  on it'), makes some modifications and then releases the lock when the data
14559  structure is consistent again.
14560  The instruction may also be used if interrupt and non-interrupt code have
14561  to compete for a resource.
14562  With the atomic bit test and clear instruction interrupts
14563 \begin_inset LatexCommand \index{interrupt}
14564
14565 \end_inset
14566
14567  don't have to be disabled for the locking operation.
14568  
14569 \end_layout
14570
14571 \begin_layout Standard
14572 SDCC generates this instruction if the source follows this pattern:
14573 \end_layout
14574
14575 \begin_layout Verse
14576
14577 \family typewriter
14578 volatile
14579 \begin_inset LatexCommand \index{volatile}
14580
14581 \end_inset
14582
14583  bit resource_is_free; 
14584 \newline
14585
14586 \newline
14587 if (resource_is_free) 
14588 \newline
14589 \InsetSpace ~
14590 \InsetSpace ~
14591
14592 \newline
14593 \InsetSpace ~
14594 \InsetSpace ~
14595 \InsetSpace ~
14596 \InsetSpace ~
14597 resource_is_free=0; 
14598 \newline
14599 \InsetSpace ~
14600 \InsetSpace ~
14601 \InsetSpace ~
14602 \InsetSpace ~
14603 ...
14604  
14605 \newline
14606 \InsetSpace ~
14607 \InsetSpace ~
14608 \InsetSpace ~
14609 \InsetSpace ~
14610 resource_is_free=1;
14611 \newline
14612 \InsetSpace ~
14613 \InsetSpace ~
14614
14615 \end_layout
14616
14617 \begin_layout Standard
14618 Note, mcs51 and ds390 support only an atomic
14619 \begin_inset LatexCommand \index{atomic}
14620
14621 \end_inset
14622
14623  bit test and 
14624 \emph on
14625 clear
14626 \emph default
14627  instruction (as opposed to atomic bit test and 
14628 \emph on
14629 set).
14630 \end_layout
14631
14632 \begin_layout Section
14633 Functions using private register banks
14634 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14635
14636 \end_inset
14637
14638  (mcs51/ds390)
14639 \end_layout
14640
14641 \begin_layout Standard
14642 Some architectures have support for quickly changing register sets.
14643  SDCC supports this feature with the 
14644 \emph on
14645 using
14646 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14647
14648 \end_inset
14649
14650
14651 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14652
14653 \end_inset
14654
14655
14656 \emph default
14657  attribute (which tells the compiler to use a register bank
14658 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14659
14660 \end_inset
14661
14662  other than the default bank zero).
14663  It should only be applied to 
14664 \emph on
14665 interrupt
14666 \begin_inset LatexCommand \index{interrupt}
14667
14668 \end_inset
14669
14670
14671 \emph default
14672  functions (see footnote below).
14673  This will in most circumstances make the generated ISR code more efficient
14674  since it will not have to save registers on the stack.
14675 \end_layout
14676
14677 \begin_layout Standard
14678 The 
14679 \emph on
14680 using
14681 \emph default
14682  attribute will have no effect on the generated code for a 
14683 \emph on
14684 non-interrupt
14685 \emph default
14686  function (but may occasionally be useful anyway
14687 \begin_inset Foot
14688 status open
14689
14690 \begin_layout Standard
14691 possible exception: if a function is called ONLY from 'interrupt' functions
14692  using a particular bank, it can be declared with the same 'using' attribute
14693  as the calling 'interrupt' functions.
14694  For instance, if you have several ISRs using bank one, and all of them
14695  call memcpy(), it might make sense to create a specialized version of memcpy()
14696  'using 1', since this would prevent the ISR from having to save bank zero
14697  to the stack on entry and switch to bank zero before calling the function
14698 \end_layout
14699
14700 \end_inset
14701
14702 ).
14703 \newline
14704
14705 \emph on
14706 (pending: Note, nowadays the 
14707 \emph default
14708 using
14709 \emph on
14710  attribute has an effect on
14711 \emph default
14712  
14713 \emph on
14714 the generated code for a 
14715 \emph default
14716 non-interrupt
14717 \emph on
14718  function
14719 \emph default
14720 .
14721 \emph on
14722 )
14723 \end_layout
14724
14725 \begin_layout Standard
14726 An 
14727 \emph on
14728 interrupt
14729 \emph default
14730  function using a non-zero bank will assume that it can trash that register
14731  bank, and will not save it.
14732  Since high-priority interrupts
14733 \begin_inset LatexCommand \index{interrupts}
14734
14735 \end_inset
14736
14737
14738 \begin_inset LatexCommand \index{interrupt priority}
14739
14740 \end_inset
14741
14742  can interrupt low-priority ones on the 8051 and friends, this means that
14743  if a high-priority ISR 
14744 \emph on
14745 using
14746 \emph default
14747  a particular bank occurs while processing a low-priority ISR 
14748 \emph on
14749 using
14750 \emph default
14751  the same bank, terrible and bad things can happen.
14752  To prevent this, no single register bank should be 
14753 \emph on
14754 used
14755 \emph default
14756  by both a high priority and a low priority ISR.
14757  This is probably most easily done by having all high priority ISRs use
14758  one bank and all low priority ISRs use another.
14759  If you have an ISR which can change priority at runtime, you're on your
14760  own: I suggest using the default bank zero and taking the small performance
14761  hit.
14762 \end_layout
14763
14764 \begin_layout Standard
14765 It is most efficient if your ISR calls no other functions.
14766  If your ISR must call other functions, it is most efficient if those functions
14767  use the same bank as the ISR (see note 1 below); the next best is if the
14768  called functions use bank zero.
14769  It is very inefficient to call a function using a different, non-zero bank
14770  from an ISR.
14771  
14772 \begin_inset VSpace bigskip
14773 \end_inset
14774
14775
14776 \end_layout
14777
14778 \begin_layout Section
14779 Startup Code
14780 \begin_inset LatexCommand \label{sub:Startup-Code}
14781
14782 \end_inset
14783
14784
14785 \begin_inset LatexCommand \index{Startup code}
14786
14787 \end_inset
14788
14789
14790 \end_layout
14791
14792 \begin_layout Subsection
14793 MCS51/DS390 Startup Code
14794 \end_layout
14795
14796 \begin_layout Standard
14797 The compiler triggers the linker to link certain initialization modules
14798  from the runtime library
14799 \begin_inset LatexCommand \index{Runtime library}
14800
14801 \end_inset
14802
14803  called crt<something>.
14804  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14805  GSINIT5) is not linked unless the --xstack option is used.
14806  These modules are highly entangled by the use of special segments/areas,
14807  but a common layout is shown below:
14808 \end_layout
14809
14810 \begin_layout Verse
14811
14812 \family typewriter
14813 \series bold
14814 \size footnotesize
14815 (main.asm)
14816 \end_layout
14817
14818 \begin_layout Verse
14819
14820 \family typewriter
14821 \size footnotesize
14822 \InsetSpace ~
14823 \InsetSpace ~
14824 \InsetSpace ~
14825 \InsetSpace ~
14826 \InsetSpace ~
14827 \InsetSpace ~
14828 \InsetSpace ~
14829 \InsetSpace ~
14830 .area HOME (CODE)
14831 \newline
14832 __interrupt_vect:
14833 \newline
14834 \InsetSpace ~
14835 \InsetSpace ~
14836 \InsetSpace ~
14837 \InsetSpace ~
14838 \InsetSpace ~
14839 \InsetSpace ~
14840 \InsetSpace ~
14841 \InsetSpace ~
14842 ljmp __sdcc_gsinit_startup
14843 \end_layout
14844
14845 \begin_layout Verse
14846
14847 \family typewriter
14848 \series bold
14849 \size footnotesize
14850 (crtstart.asm)
14851 \end_layout
14852
14853 \begin_layout Verse
14854
14855 \family typewriter
14856 \size footnotesize
14857 \InsetSpace ~
14858 \InsetSpace ~
14859 \InsetSpace ~
14860 \InsetSpace ~
14861 \InsetSpace ~
14862 \InsetSpace ~
14863 \InsetSpace ~
14864 \InsetSpace ~
14865 .area GSINIT0 (CODE)
14866 \newline
14867 __sdcc_gsinit_startup::
14868 \newline
14869 \InsetSpace ~
14870 \InsetSpace ~
14871 \InsetSpace ~
14872 \InsetSpace ~
14873 \InsetSpace ~
14874 \InsetSpace ~
14875 \InsetSpace ~
14876 \InsetSpace ~
14877 mov sp,#__start__stack - 1
14878 \end_layout
14879
14880 \begin_layout Verse
14881
14882 \family typewriter
14883 \series bold
14884 \size footnotesize
14885 (crtxstack.asm)
14886 \end_layout
14887
14888 \begin_layout Verse
14889
14890 \family typewriter
14891 \size footnotesize
14892 \InsetSpace ~
14893 \InsetSpace ~
14894 \InsetSpace ~
14895 \InsetSpace ~
14896 \InsetSpace ~
14897 \InsetSpace ~
14898 \InsetSpace ~
14899 \InsetSpace ~
14900 .area GSINIT1 (CODE)
14901 \newline
14902 __sdcc_init_xstack::
14903 \newline
14904 ; Need to initialize in GSINIT1 in
14905  case the user's __sdcc_external_startup uses the xstack.
14906 \newline
14907 \InsetSpace ~
14908 \InsetSpace ~
14909 \InsetSpace ~
14910 \InsetSpace ~
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 mov __XPAGE,#(__start__x
14916 stack >> 8)
14917 \newline
14918 \InsetSpace ~
14919 \InsetSpace ~
14920 \InsetSpace ~
14921 \InsetSpace ~
14922 \InsetSpace ~
14923 \InsetSpace ~
14924 \InsetSpace ~
14925 \InsetSpace ~
14926 mov _spx,#__start__xstack
14927 \end_layout
14928
14929 \begin_layout Verse
14930
14931 \family typewriter
14932 \series bold
14933 \size footnotesize
14934 (crtstart.asm)
14935 \end_layout
14936
14937 \begin_layout Verse
14938
14939 \family typewriter
14940 \size footnotesize
14941 \InsetSpace ~
14942 \InsetSpace ~
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 \InsetSpace ~
14946 \InsetSpace ~
14947 \InsetSpace ~
14948 \InsetSpace ~
14949 .area GSINIT2 (CODE)
14950 \newline
14951 \InsetSpace ~
14952 \InsetSpace ~
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 \InsetSpace ~
14956 \InsetSpace ~
14957 \InsetSpace ~
14958 \InsetSpace ~
14959 lcall __sdcc_external_startup
14960 \newline
14961 \InsetSpace ~
14962 \InsetSpace ~
14963 \InsetSpace ~
14964 \InsetSpace ~
14965 \InsetSpace ~
14966 \InsetSpace ~
14967 \InsetSpace ~
14968 \InsetSpace ~
14969 mov a,dpl
14970 \newline
14971 \InsetSpace ~
14972 \InsetSpace ~
14973 \InsetSpace ~
14974 \InsetSpace ~
14975 \InsetSpace ~
14976 \InsetSpace ~
14977 \InsetSpace ~
14978 \InsetSpace ~
14979 jz __sdcc_init_data
14980 \newline
14981 \InsetSpace ~
14982 \InsetSpace ~
14983 \InsetSpace ~
14984 \InsetSpace ~
14985 \InsetSpace ~
14986 \InsetSpace ~
14987 \InsetSpace ~
14988 \InsetSpace ~
14989 ljmp
14990  __sdcc_program_startup
14991 \newline
14992 __sdcc_init_data:
14993 \end_layout
14994
14995 \begin_layout Verse
14996
14997 \family typewriter
14998 \series bold
14999 \size footnotesize
15000 (crtxinit.asm)
15001 \end_layout
15002
15003 \begin_layout Verse
15004
15005 \family typewriter
15006 \size footnotesize
15007 \InsetSpace ~
15008 \InsetSpace ~
15009 \InsetSpace ~
15010 \InsetSpace ~
15011 \InsetSpace ~
15012 \InsetSpace ~
15013 \InsetSpace ~
15014 \InsetSpace ~
15015 .area GSINIT3 (CODE)
15016 \newline
15017 __mcs51_genXINIT::
15018 \newline
15019 \InsetSpace ~
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 \InsetSpace ~
15025 \InsetSpace ~
15026 \InsetSpace ~
15027 mov r1,#l_XINIT
15028 \newline
15029 \InsetSpace ~
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 \InsetSpace ~
15034 \InsetSpace ~
15035 \InsetSpace ~
15036 \InsetSpace ~
15037 mov a,r1
15038 \newline
15039 \InsetSpace ~
15040 \InsetSpace ~
15041 \InsetSpace ~
15042 \InsetSpace ~
15043 \InsetSpace ~
15044 \InsetSpace ~
15045 \InsetSpace ~
15046 \InsetSpace ~
15047 orl a,#(l_XINIT
15048  >> 8)
15049 \newline
15050 \InsetSpace ~
15051 \InsetSpace ~
15052 \InsetSpace ~
15053 \InsetSpace ~
15054 \InsetSpace ~
15055 \InsetSpace ~
15056 \InsetSpace ~
15057 \InsetSpace ~
15058 jz 00003$
15059 \newline
15060 \InsetSpace ~
15061 \InsetSpace ~
15062 \InsetSpace ~
15063 \InsetSpace ~
15064 \InsetSpace ~
15065 \InsetSpace ~
15066 \InsetSpace ~
15067 \InsetSpace ~
15068 mov r2,#((l_XINIT+255) >> 8)
15069 \newline
15070 \InsetSpace ~
15071 \InsetSpace ~
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 mov dptr,#s_XINIT
15079 \newline
15080 \InsetSpace ~
15081 \InsetSpace ~
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 mov r0,#s_XISEG
15089 \newline
15090 \InsetSpace ~
15091 \InsetSpace ~
15092 \InsetSpace ~
15093 \InsetSpace ~
15094 \InsetSpace ~
15095 \InsetSpace ~
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 mov
15099  __XPAGE,#(s_XISEG >> 8)
15100 \newline
15101 00001$:\InsetSpace ~
15102 clr a
15103 \newline
15104 \InsetSpace ~
15105 \InsetSpace ~
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
15109 \InsetSpace ~
15110 \InsetSpace ~
15111 \InsetSpace ~
15112 movc a,@a+dptr
15113 \newline
15114 \InsetSpace ~
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 movx @r0,a
15123 \newline
15124 \InsetSpace ~
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 inc dptr
15133 \newline
15134 \InsetSpace ~
15135 \InsetSpace ~
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 inc
15143  r0
15144 \newline
15145 \InsetSpace ~
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 cjne r0,#0,00002$
15154 \newline
15155 \InsetSpace ~
15156 \InsetSpace ~
15157 \InsetSpace ~
15158 \InsetSpace ~
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 \InsetSpace ~
15163 inc __XPAGE
15164 \newline
15165 00002$:\InsetSpace ~
15166 djnz r1,00001$
15167 \newline
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 djnz r2,00001$
15177 \newline
15178 \InsetSpace ~
15179 \InsetSpace ~
15180 \InsetSpace ~
15181 \InsetSpace ~
15182 \InsetSpace ~
15183 \InsetSpace ~
15184 \InsetSpace ~
15185 \InsetSpace ~
15186 mov __XPAGE,#0
15187 xFF
15188 \newline
15189 00003$:
15190 \end_layout
15191
15192 \begin_layout Verse
15193
15194 \family typewriter
15195 \series bold
15196 \size footnotesize
15197 (crtclear.asm)
15198 \end_layout
15199
15200 \begin_layout Verse
15201
15202 \family typewriter
15203 \size footnotesize
15204 \InsetSpace ~
15205 \InsetSpace ~
15206 \InsetSpace ~
15207 \InsetSpace ~
15208 \InsetSpace ~
15209 \InsetSpace ~
15210 \InsetSpace ~
15211 \InsetSpace ~
15212 .area GSINIT4 (CODE)
15213 \newline
15214 __mcs51_genRAMCLEAR::
15215 \newline
15216 \InsetSpace ~
15217 \InsetSpace ~
15218 \InsetSpace ~
15219 \InsetSpace ~
15220 \InsetSpace ~
15221 \InsetSpace ~
15222 \InsetSpace ~
15223 \InsetSpace ~
15224 clr a
15225 \newline
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 \InsetSpace ~
15229 \InsetSpace ~
15230 \InsetSpace ~
15231 \InsetSpace ~
15232 \InsetSpace ~
15233 \InsetSpace ~
15234 mov r0,#(l_IRAM-1)
15235 \newline
15236 00004$:\InsetSpace ~
15237 mov
15238  @r0,a
15239 \newline
15240 \InsetSpace ~
15241 \InsetSpace ~
15242 \InsetSpace ~
15243 \InsetSpace ~
15244 \InsetSpace ~
15245 \InsetSpace ~
15246 \InsetSpace ~
15247 \InsetSpace ~
15248 djnz r0,00004$
15249 \newline
15250 ; _mcs51_genRAMCLEAR() end
15251 \end_layout
15252
15253 \begin_layout Verse
15254
15255 \family typewriter
15256 \series bold
15257 \size footnotesize
15258 (crtxclear.asm)
15259 \end_layout
15260
15261 \begin_layout Verse
15262
15263 \family typewriter
15264 \size footnotesize
15265 \InsetSpace ~
15266 \InsetSpace ~
15267 \InsetSpace ~
15268 \InsetSpace ~
15269 \InsetSpace ~
15270 \InsetSpace ~
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 .area GSINIT4 (CODE)
15274 \newline
15275 __mcs51_genXRAMCLEAR::
15276 \newline
15277 \InsetSpace ~
15278 \InsetSpace ~
15279 \InsetSpace ~
15280 \InsetSpace ~
15281 \InsetSpace ~
15282 \InsetSpace ~
15283 \InsetSpace ~
15284 \InsetSpace ~
15285 mov r0,#l_PSEG
15286 \newline
15287 \InsetSpace ~
15288 \InsetSpace ~
15289 \InsetSpace ~
15290 \InsetSpace ~
15291 \InsetSpace ~
15292 \InsetSpace ~
15293 \InsetSpace ~
15294 \InsetSpace ~
15295 mov a,r0
15296 \newline
15297 \InsetSpace ~
15298 \InsetSpace ~
15299 \InsetSpace ~
15300 \InsetSpace ~
15301 \InsetSpace ~
15302 \InsetSpace ~
15303 \InsetSpace ~
15304 \InsetSpace ~
15305 jz 00006$
15306 \newline
15307 \InsetSpace ~
15308 \InsetSpace ~
15309 \InsetSpace ~
15310 \InsetSpace ~
15311 \InsetSpace ~
15312 \InsetSpace ~
15313 \InsetSpace ~
15314 \InsetSpace ~
15315 mov
15316  r1,#s_PSEG
15317 \newline
15318 \InsetSpace ~
15319 \InsetSpace ~
15320 \InsetSpace ~
15321 \InsetSpace ~
15322 \InsetSpace ~
15323 \InsetSpace ~
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 mov __XPAGE,#(s_PSEG >> 8)
15327 \newline
15328 \InsetSpace ~
15329 \InsetSpace ~
15330 \InsetSpace ~
15331 \InsetSpace ~
15332 \InsetSpace ~
15333 \InsetSpace ~
15334 \InsetSpace ~
15335 \InsetSpace ~
15336 clr a
15337 \newline
15338 00005$:\InsetSpace ~
15339 movx @r1,a
15340 \newline
15341 \InsetSpace ~
15342 \InsetSpace ~
15343 \InsetSpace ~
15344 \InsetSpace ~
15345 \InsetSpace ~
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 inc r1
15350 \newline
15351 \InsetSpace ~
15352 \InsetSpace ~
15353 \InsetSpace ~
15354 \InsetSpace ~
15355 \InsetSpace ~
15356 \InsetSpace ~
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 djnz r0,00005$
15360 \newline
15361 0
15362 0006$:
15363 \newline
15364 \InsetSpace ~
15365 \InsetSpace ~
15366 \InsetSpace ~
15367 \InsetSpace ~
15368 \InsetSpace ~
15369 \InsetSpace ~
15370 \InsetSpace ~
15371 \InsetSpace ~
15372 mov r0,#l_XSEG
15373 \newline
15374 \InsetSpace ~
15375 \InsetSpace ~
15376 \InsetSpace ~
15377 \InsetSpace ~
15378 \InsetSpace ~
15379 \InsetSpace ~
15380 \InsetSpace ~
15381 \InsetSpace ~
15382 mov a,r0
15383 \newline
15384 \InsetSpace ~
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 \InsetSpace ~
15389 \InsetSpace ~
15390 \InsetSpace ~
15391 \InsetSpace ~
15392 orl a,#(l_XSEG >> 8)
15393 \newline
15394 \InsetSpace ~
15395 \InsetSpace ~
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 \InsetSpace ~
15402 jz 00008$
15403 \newline
15404 \InsetSpace ~
15405 \InsetSpace ~
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 \InsetSpace ~
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 \InsetSpace ~
15412 mov r1,#((l_XSEG
15413  + 255) >> 8)
15414 \newline
15415 \InsetSpace ~
15416 \InsetSpace ~
15417 \InsetSpace ~
15418 \InsetSpace ~
15419 \InsetSpace ~
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 mov dptr,#s_XSEG
15424 \newline
15425 \InsetSpace ~
15426 \InsetSpace ~
15427 \InsetSpace ~
15428 \InsetSpace ~
15429 \InsetSpace ~
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 clr a
15434 \newline
15435 00007$:\InsetSpace ~
15436 movx @dptr,a
15437 \newline
15438 \InsetSpace ~
15439 \InsetSpace ~
15440 \InsetSpace ~
15441 \InsetSpace ~
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 \InsetSpace ~
15445 \InsetSpace ~
15446 inc dptr
15447 \newline
15448 \InsetSpace ~
15449 \InsetSpace ~
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 \InsetSpace ~
15454 \InsetSpace ~
15455 \InsetSpace ~
15456 djnz r0,00007$
15457 \newline
15458 \InsetSpace ~
15459 \InsetSpace ~
15460 \InsetSpace ~
15461 \InsetSpace ~
15462 \InsetSpace ~
15463 \InsetSpace ~
15464 \InsetSpace ~
15465 \InsetSpace ~
15466 djnz
15467  r1,00007$
15468 \newline
15469 00008$:
15470 \end_layout
15471
15472 \begin_layout Verse
15473
15474 \family typewriter
15475 \series bold
15476 \size footnotesize
15477 (crtxstack.asm)
15478 \end_layout
15479
15480 \begin_layout Verse
15481
15482 \family typewriter
15483 \size footnotesize
15484 \InsetSpace ~
15485 \InsetSpace ~
15486 \InsetSpace ~
15487 \InsetSpace ~
15488 \InsetSpace ~
15489 \InsetSpace ~
15490 \InsetSpace ~
15491 \InsetSpace ~
15492 .area GSINIT5 (CODE)
15493 \newline
15494 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15495  modifies __XPAGE
15496 \newline
15497 ; and __mcs51_genRAMCLEAR modifies _spx.
15498 \newline
15499 \InsetSpace ~
15500 \InsetSpace ~
15501 \InsetSpace ~
15502 \InsetSpace ~
15503 \InsetSpace ~
15504 \InsetSpace ~
15505 \InsetSpace ~
15506 \InsetSpace ~
15507 mov __XPAGE,#(__start__x
15508 stack >> 8)
15509 \newline
15510 \InsetSpace ~
15511 \InsetSpace ~
15512 \InsetSpace ~
15513 \InsetSpace ~
15514 \InsetSpace ~
15515 \InsetSpace ~
15516 \InsetSpace ~
15517 \InsetSpace ~
15518 mov _spx,#__start__xstack
15519 \end_layout
15520
15521 \begin_layout Verse
15522
15523 \family typewriter
15524 \series bold
15525 \size footnotesize
15526 (application modules)
15527 \end_layout
15528
15529 \begin_layout Verse
15530
15531 \family typewriter
15532 \size footnotesize
15533 \InsetSpace ~
15534 \InsetSpace ~
15535 \InsetSpace ~
15536 \InsetSpace ~
15537 \InsetSpace ~
15538 \InsetSpace ~
15539 \InsetSpace ~
15540 \InsetSpace ~
15541 .area GSINIT (CODE)
15542 \end_layout
15543
15544 \begin_layout Verse
15545
15546 \family typewriter
15547 \series bold
15548 \size footnotesize
15549 (main.asm)
15550 \end_layout
15551
15552 \begin_layout Verse
15553
15554 \family typewriter
15555 \size footnotesize
15556 \InsetSpace ~
15557 \InsetSpace ~
15558 \InsetSpace ~
15559 \InsetSpace ~
15560 \InsetSpace ~
15561 \InsetSpace ~
15562 \InsetSpace ~
15563 \InsetSpace ~
15564 .area GSFINAL (CODE)
15565 \newline
15566 \InsetSpace ~
15567 \InsetSpace ~
15568 \InsetSpace ~
15569 \InsetSpace ~
15570 \InsetSpace ~
15571 \InsetSpace ~
15572 \InsetSpace ~
15573 \InsetSpace ~
15574 ljmp __sdcc_program_startup
15575 \newline
15576 ;---------------------------------
15577 -----------------------
15578 \newline
15579 ; Home
15580 \newline
15581 ;--------------------------------------------------
15582 ------
15583 \newline
15584 \InsetSpace ~
15585 \InsetSpace ~
15586 \InsetSpace ~
15587 \InsetSpace ~
15588 \InsetSpace ~
15589 \InsetSpace ~
15590 \InsetSpace ~
15591 \InsetSpace ~
15592 .area HOME (CODE)
15593 \newline
15594 \InsetSpace ~
15595 \InsetSpace ~
15596 \InsetSpace ~
15597 \InsetSpace ~
15598 \InsetSpace ~
15599 \InsetSpace ~
15600 \InsetSpace ~
15601 \InsetSpace ~
15602 .area CSEG (CODE)
15603 \newline
15604 __sdcc_program_startup:
15605 \newline
15606 \InsetSpace ~
15607 \InsetSpace ~
15608 \InsetSpace ~
15609 \InsetSpace ~
15610 \InsetSpace ~
15611 \InsetSpace ~
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 lcall _main
15615 \newline
15616 ;
15617  return from main will lock up
15618 \newline
15619 \InsetSpace ~
15620 \InsetSpace ~
15621 \InsetSpace ~
15622 \InsetSpace ~
15623 \InsetSpace ~
15624 \InsetSpace ~
15625 \InsetSpace ~
15626 \InsetSpace ~
15627 sjmp .
15628 \end_layout
15629
15630 \begin_layout Standard
15631 One of these modules (crtstart.asm) contains a call to the C routine 
15632 \emph on
15633 _sdcc_external_startup()
15634 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15635
15636 \end_inset
15637
15638
15639 \series bold
15640 \emph default
15641  
15642 \series default
15643 at the start of the CODE area.
15644  This routine is also in the runtime library
15645 \begin_inset LatexCommand \index{Runtime library}
15646
15647 \end_inset
15648
15649  and returns 0 by default.
15650  If this routine returns a non-zero value, the static & global variable
15651  initialization will be skipped and the function main will be invoked.
15652  Otherwise static & global variables will be initialized before the function
15653  main is invoked.
15654  You could add an 
15655 \emph on
15656 _sdcc_external_startup()
15657 \emph default
15658  routine to your program to override the default if you need to setup hardware
15659  or perform some other critical operation prior to static & global variable
15660  initialization
15661 \begin_inset LatexCommand \index{Variable initialization}
15662
15663 \end_inset
15664
15665 .
15666  On some mcs51 variants xdata
15667 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15668
15669 \end_inset
15670
15671  memory has to be explicitly enabled before it can be accessed or if the
15672  watchdog
15673 \begin_inset LatexCommand \index{watchdog}
15674
15675 \end_inset
15676
15677  needs to be disabled, this is the place to do it.
15678  The startup code clears all internal data memory, 256 bytes by default,
15679  but from 0 to n-1 if 
15680 \emph on
15681 -
15682 \begin_inset ERT
15683 status collapsed
15684
15685 \begin_layout Standard
15686
15687
15688 \backslash
15689 /
15690 \end_layout
15691
15692 \end_inset
15693
15694 -iram-size
15695 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15696
15697 \end_inset
15698
15699 n
15700 \emph default
15701  is used.
15702  (recommended for Chipcon CC1010).
15703 \end_layout
15704
15705 \begin_layout Standard
15706 See also the compiler options 
15707 \emph on
15708 -
15709 \begin_inset ERT
15710 status collapsed
15711
15712 \begin_layout Standard
15713
15714
15715 \backslash
15716 /
15717 \end_layout
15718
15719 \end_inset
15720
15721 -no-xinit
15722 \emph default
15723 -
15724 \emph on
15725 opt
15726 \emph default
15727
15728 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15729
15730 \end_inset
15731
15732
15733 \emph on
15734 -
15735 \begin_inset ERT
15736 status collapsed
15737
15738 \begin_layout Standard
15739
15740
15741 \backslash
15742 /
15743 \end_layout
15744
15745 \end_inset
15746
15747 -main-return
15748 \emph default
15749
15750 \begin_inset LatexCommand \index{-\/-main-return}
15751
15752 \end_inset
15753
15754  and section 
15755 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15756
15757 \end_inset
15758
15759  about MCS51-variants.
15760 \begin_inset VSpace bigskip
15761 \end_inset
15762
15763
15764 \end_layout
15765
15766 \begin_layout Subsection
15767 HC08 Startup Code
15768 \end_layout
15769
15770 \begin_layout Standard
15771 The HC08
15772 \begin_inset LatexCommand \index{HC08}
15773
15774 \end_inset
15775
15776  startup code follows the same scheme as the MCS51 startup code.
15777 \begin_inset VSpace bigskip
15778 \end_inset
15779
15780
15781 \end_layout
15782
15783 \begin_layout Subsection
15784 Z80 Startup Code
15785 \end_layout
15786
15787 \begin_layout Standard
15788 On the Z80
15789 \begin_inset LatexCommand \index{Z80}
15790
15791 \end_inset
15792
15793  the startup code is inserted by linking with crt0.o which is generated from
15794  sdcc/device/lib/z80/crt0.s.
15795  If you need a different startup code you can use the compiler option 
15796 \emph on
15797 -
15798 \series bold
15799 \emph default
15800
15801 \begin_inset ERT
15802 status collapsed
15803
15804 \begin_layout Standard
15805
15806
15807 \backslash
15808 /
15809 \end_layout
15810
15811 \end_inset
15812
15813
15814 \series default
15815 \emph on
15816 -no-std-crt0
15817 \emph default
15818
15819 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15820
15821 \end_inset
15822
15823  and provide your own crt0.o.
15824  
15825 \begin_inset VSpace bigskip
15826 \end_inset
15827
15828
15829 \end_layout
15830
15831 \begin_layout Section
15832 Inline Assembler Code
15833 \begin_inset LatexCommand \index{Assembler routines}
15834
15835 \end_inset
15836
15837
15838 \end_layout
15839
15840 \begin_layout Subsection
15841 A Step by Step Introduction
15842 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15843
15844 \end_inset
15845
15846
15847 \end_layout
15848
15849 \begin_layout Standard
15850 Starting from a small snippet of c-code this example shows for the MCS51
15851  how to use inline assembly, access variables, a function parameter and
15852  an array in xdata memory.
15853  The example uses an MCS51 here but is easily adapted for other architectures.
15854  This is a buffer routine which should be optimized:
15855 \end_layout
15856
15857 \begin_layout Verse
15858
15859 \family typewriter
15860 \size footnotesize
15861 unsigned char __far
15862 \begin_inset LatexCommand \index{far (storage class)}
15863
15864 \end_inset
15865
15866
15867 \begin_inset LatexCommand \index{\_\_far (storage class)}
15868
15869 \end_inset
15870
15871  __at
15872 \begin_inset LatexCommand \index{at}
15873
15874 \end_inset
15875
15876
15877 \begin_inset LatexCommand \index{\_\_at}
15878
15879 \end_inset
15880
15881 (0x7f00) buf[0x100];
15882 \begin_inset LatexCommand \index{Aligned array}
15883
15884 \end_inset
15885
15886
15887 \newline
15888 unsigned char head, tail;\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 /* if interrupts
15906 \begin_inset LatexCommand \index{interrupt}
15907
15908 \end_inset
15909
15910  are involved see
15911 \newline
15912 \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 \InsetSpace ~
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
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 section 
15958 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15959
15960 \end_inset
15961
15962  about
15963 \series bold
15964  volatile
15965 \series default
15966  */
15967 \newline
15968
15969 \newline
15970 void to_buffer( unsigned char c ) 
15971 \newline
15972 {
15973 \newline
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 if( head != (unsigned char)(tail-1)
15979  )\InsetSpace ~
15980 /* cast 
15981 \series bold
15982 needed
15983 \series default
15984  to avoid promotion
15985 \begin_inset LatexCommand \index{promotion to signed int}
15986
15987 \end_inset
15988
15989
15990 \begin_inset LatexCommand \index{type promotion}
15991
15992 \end_inset
15993
15994  to integer */
15995 \begin_inset Marginal
15996 status collapsed
15997
15998 \begin_layout Standard
15999
16000 \series bold
16001 \InsetSpace ~
16002 !
16003 \end_layout
16004
16005 \end_inset
16006
16007
16008 \newline
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 \InsetSpace ~
16014 \InsetSpace ~
16015 \InsetSpace ~
16016 \InsetSpace ~
16017 buf[ head++ ] = c;\InsetSpace ~
16018 \InsetSpace ~
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 \InsetSpace ~
16025 \InsetSpace ~
16026 \InsetSpace ~
16027 \InsetSpace ~
16028 \InsetSpace ~
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 /* access to a 256 byte aligned array */
16034 \newline
16035
16036 \end_layout
16037
16038 \begin_layout Standard
16039 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16040  then a corresponding buffer.asm file is generated.
16041  We define a new function 
16042 \family typewriter
16043 to_buffer_asm()
16044 \family default
16045  in file buffer.c in which we cut and paste the generated code, removing
16046  unwanted comments and some ':'.
16047  Then add 
16048 \begin_inset Quotes sld
16049 \end_inset
16050
16051
16052 \series bold
16053 _asm
16054 \series default
16055
16056 \begin_inset Quotes srd
16057 \end_inset
16058
16059  and 
16060 \begin_inset Quotes sld
16061 \end_inset
16062
16063
16064 \series bold
16065 _endasm;
16066 \series default
16067
16068 \begin_inset Quotes srd
16069 \end_inset
16070
16071
16072 \begin_inset Foot
16073 status open
16074
16075 \begin_layout Standard
16076 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16077  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16078  has to be used.
16079  The latter is also used in the library functions.
16080 \end_layout
16081
16082 \end_inset
16083
16084  to the beginning and the end of the function body:
16085 \end_layout
16086
16087 \begin_layout Verse
16088
16089 \family typewriter
16090 \size footnotesize
16091 /* With a cut and paste from the .asm file, we have something to start with.
16092 \newline
16093 \InsetSpace ~
16094 \InsetSpace ~
16095 \InsetSpace ~
16096 The
16097  function is not yet OK! (registers aren't saved) */ 
16098 \newline
16099 void to_buffer_asm(
16100  unsigned char c ) 
16101 \newline
16102
16103 \newline
16104 \InsetSpace ~
16105 \InsetSpace ~
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 _asm
16109 \begin_inset LatexCommand \index{\_asm}
16110
16111 \end_inset
16112
16113
16114 \begin_inset LatexCommand \index{\_\_asm}
16115
16116 \end_inset
16117
16118
16119 \newline
16120 \InsetSpace ~
16121 \InsetSpace ~
16122 \InsetSpace ~
16123 \InsetSpace ~
16124 mov\InsetSpace ~
16125 \InsetSpace ~
16126 r2,dpl 
16127 \newline
16128 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16129 /* cast 
16130 \series bold
16131 needed
16132 \series default
16133  to avoid promotion
16134 \begin_inset LatexCommand \index{promotion to signed int}
16135
16136 \end_inset
16137
16138
16139 \begin_inset LatexCommand \index{type promotion}
16140
16141 \end_inset
16142
16143  to integer */
16144 \newline
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 mov\InsetSpace ~
16150 \InsetSpace ~
16151 a,_tail 
16152 \newline
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 dec\InsetSpace ~
16158 \InsetSpace ~
16159
16160 \newline
16161 \InsetSpace ~
16162 \InsetSpace ~
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 mov\InsetSpace ~
16166 \InsetSpace ~
16167 r3,a 
16168 \newline
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 \InsetSpace ~
16172 \InsetSpace ~
16173 mov\InsetSpace ~
16174 \InsetSpace ~
16175 a,_head 
16176 \newline
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 cjne a,ar3,00106$ 
16182 \newline
16183 \InsetSpace ~
16184 \InsetSpace ~
16185 \InsetSpace ~
16186 \InsetSpace ~
16187 ret
16188 \newline
16189 00106$:
16190  
16191 \newline
16192 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16193 \begin_inset LatexCommand \index{Aligned array}
16194
16195 \end_inset
16196
16197
16198 \newline
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 mov\InsetSpace ~
16204 \InsetSpace ~
16205 r3,_head 
16206 \newline
16207 \InsetSpace ~
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 \InsetSpace ~
16211 inc\InsetSpace ~
16212 \InsetSpace ~
16213 _head 
16214 \newline
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 \InsetSpace ~
16219 mov\InsetSpace ~
16220 \InsetSpace ~
16221 dpl,r3 
16222 \newline
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 mov\InsetSpace ~
16228 \InsetSpace ~
16229 dph,#(_buf >> 8) 
16230 \newline
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 mov\InsetSpace ~
16236 \InsetSpace ~
16237 a,r2 
16238 \newline
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 movx @dptr,a
16244  
16245 \newline
16246 00103$: 
16247 \newline
16248 \InsetSpace ~
16249 \InsetSpace ~
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 ret
16253 \newline
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 _endasm
16259 \begin_inset LatexCommand \index{\_endasm}
16260
16261 \end_inset
16262
16263
16264 \begin_inset LatexCommand \index{\_\_endasm}
16265
16266 \end_inset
16267
16268 ;
16269 \newline
16270
16271 \end_layout
16272
16273 \begin_layout Standard
16274 The new file buffer.c should compile with only one warning about the unreferenced
16275  function argument 'c'.
16276  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16277  (1) and finally have:
16278 \end_layout
16279
16280 \begin_layout Verse
16281
16282 \family typewriter
16283 \size footnotesize
16284 unsigned char __far __at(0x7f00) buf[0x100];
16285 \newline
16286 unsigned char head, tail;
16287 \newline
16288 #define
16289  USE_ASSEMBLY (1)
16290 \newline
16291
16292 \newline
16293 #if !USE_ASSEMBLY
16294 \newline
16295
16296 \newline
16297 void to_buffer( unsigned char c )
16298 \newline
16299 {
16300 \newline
16301 \InsetSpace ~
16302 \InsetSpace ~
16303 \InsetSpace ~
16304 \InsetSpace ~
16305 if(
16306  head != (unsigned char)(tail-1) )
16307 \newline
16308 \InsetSpace ~
16309 \InsetSpace ~
16310 \InsetSpace ~
16311 \InsetSpace ~
16312 \InsetSpace ~
16313 \InsetSpace ~
16314 \InsetSpace ~
16315 \InsetSpace ~
16316 buf[ head++ ] = c;
16317 \newline
16318 }
16319 \newline
16320
16321 \newline
16322 #else
16323 \newline
16324
16325 \newline
16326 void to_buffer(
16327  unsigned char c )
16328 \newline
16329 {
16330 \newline
16331 \InsetSpace ~
16332 \InsetSpace ~
16333 \InsetSpace ~
16334 \InsetSpace ~
16335 c; // to avoid warning: unreferenced function argument
16336 \newline
16337 \InsetSpace ~
16338 \InsetSpace ~
16339 \InsetSpace ~
16340 \InsetSpace ~
16341 _asm
16342 \begin_inset LatexCommand \index{\_asm}
16343
16344 \end_inset
16345
16346
16347 \begin_inset LatexCommand \index{\_\_asm}
16348
16349 \end_inset
16350
16351
16352 \newline
16353 \InsetSpace ~
16354 \InsetSpace ~
16355 \InsetSpace ~
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 ; save used registers here.
16362  
16363 \newline
16364 \InsetSpace ~
16365 \InsetSpace ~
16366 \InsetSpace ~
16367 \InsetSpace ~
16368 \InsetSpace ~
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 \InsetSpace ~
16372 ; If we were still using r2,r3 we would have to push them here.
16373  
16374 \newline
16375 ; if( head != (unsigned char)(tail-1) )
16376 \newline
16377 \InsetSpace ~
16378 \InsetSpace ~
16379 \InsetSpace ~
16380 \InsetSpace ~
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 mov\InsetSpace ~
16386  a,_tail
16387 \newline
16388 \InsetSpace ~
16389 \InsetSpace ~
16390 \InsetSpace ~
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 dec\InsetSpace ~
16397  a
16398 \newline
16399 \InsetSpace ~
16400 \InsetSpace ~
16401 \InsetSpace ~
16402 \InsetSpace ~
16403 \InsetSpace ~
16404 \InsetSpace ~
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 xrl\InsetSpace ~
16408  a,_head
16409 \newline
16410 \InsetSpace ~
16411 \InsetSpace ~
16412 \InsetSpace ~
16413 \InsetSpace ~
16414 \InsetSpace ~
16415 \InsetSpace ~
16416 \InsetSpace ~
16417 \InsetSpace ~
16418 ; we
16419  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16420 \newline
16421 \InsetSpace ~
16422 \InsetSpace ~
16423 \InsetSpace ~
16424 \InsetSpace ~
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 \InsetSpace ~
16428 \InsetSpace ~
16429 jz\InsetSpace ~
16430 \InsetSpace ~
16431  t_b_end$
16432 \newline
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 \InsetSpace ~
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 \InsetSpace ~
16440 \InsetSpace ~
16441 ;
16442 \newline
16443 ;
16444  buf[ head++ ] = c;
16445 \newline
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 \InsetSpace ~
16453 \InsetSpace ~
16454 mov\InsetSpace ~
16455  a,dpl \InsetSpace ~
16456 \InsetSpace ~
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 ; dpl holds lower byte of function argument
16463 \newline
16464 \InsetSpace ~
16465 \InsetSpace ~
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 \InsetSpace ~
16470 \InsetSpace ~
16471 \InsetSpace ~
16472 mov\InsetSpace ~
16473
16474  dpl,_head \InsetSpace ~
16475 \InsetSpace ~
16476 \InsetSpace ~
16477 ; buf is 0x100 byte aligned so head can be used directly
16478 \newline
16479 \InsetSpace ~
16480 \InsetSpace ~
16481 \InsetSpace ~
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 \InsetSpace ~
16486 \InsetSpace ~
16487 mov\InsetSpace ~
16488  dph,#(_bu
16489 f>>8)
16490 \newline
16491 \InsetSpace ~
16492 \InsetSpace ~
16493 \InsetSpace ~
16494 \InsetSpace ~
16495 \InsetSpace ~
16496 \InsetSpace ~
16497 \InsetSpace ~
16498 \InsetSpace ~
16499 movx @dptr,a
16500 \newline
16501 \InsetSpace ~
16502 \InsetSpace ~
16503 \InsetSpace ~
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 \InsetSpace ~
16509 inc \InsetSpace ~
16510 _head
16511 \newline
16512 \InsetSpace ~
16513 \InsetSpace ~
16514 \InsetSpace ~
16515 \InsetSpace ~
16516 \InsetSpace ~
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 \InsetSpace ~
16520 ; we could do an ANL _head,#0x0f here to use a
16521  smaller buffer (see above)
16522 \newline
16523 t_b_end$:
16524 \newline
16525 \InsetSpace ~
16526 \InsetSpace ~
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 \InsetSpace ~
16531 \InsetSpace ~
16532 \InsetSpace ~
16533 ; restore used registers here 
16534 \newline
16535 \InsetSpace ~
16536 \InsetSpace ~
16537 \InsetSpace ~
16538 \InsetSpace ~
16539 _endasm
16540 \begin_inset LatexCommand \index{\_endasm}
16541
16542 \end_inset
16543
16544
16545 \begin_inset LatexCommand \index{\_\_endasm}
16546
16547 \end_inset
16548
16549 ;
16550 \newline
16551 }
16552 \newline
16553 #endif
16554 \end_layout
16555
16556 \begin_layout Standard
16557 The inline assembler code can contain any valid code understood by the assembler
16558 , this includes any assembler directives and comment lines.
16559  The assembler does not like some characters like ':' or ''' in comments.
16560  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16561 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16562
16563 \end_inset
16564
16565
16566 \begin_inset LatexCommand \index{Assembler documentation}
16567
16568 \end_inset
16569
16570  or online at 
16571 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16572
16573 \end_inset
16574
16575 \InsetSpace ~
16576 .
16577 \end_layout
16578
16579 \begin_layout Standard
16580 The compiler does not do any validation of the code within the 
16581 \family typewriter
16582 _asm
16583 \begin_inset LatexCommand \index{\_asm}
16584
16585 \end_inset
16586
16587
16588 \begin_inset LatexCommand \index{\_\_asm}
16589
16590 \end_inset
16591
16592  ...
16593  _endasm
16594 \size footnotesize
16595
16596 \begin_inset LatexCommand \index{\_endasm}
16597
16598 \end_inset
16599
16600
16601 \begin_inset LatexCommand \index{\_\_endasm}
16602
16603 \end_inset
16604
16605
16606 \size default
16607 ;
16608 \family default
16609  keyword pair.
16610  Specifically it will not know which registers are used and thus register
16611  pushing/popping
16612 \begin_inset LatexCommand \index{push/pop}
16613
16614 \end_inset
16615
16616  has to be done manually.
16617  
16618 \end_layout
16619
16620 \begin_layout Standard
16621 It is recommended that each assembly instruction (including labels) be placed
16622  in a separate line (as the example shows).
16623  When the -
16624 \begin_inset ERT
16625 status collapsed
16626
16627 \begin_layout Standard
16628
16629
16630 \backslash
16631 /
16632 \end_layout
16633
16634 \end_inset
16635
16636 -
16637 \emph on
16638 peep-asm
16639 \begin_inset LatexCommand \index{-\/-peep-asm}
16640
16641 \end_inset
16642
16643
16644 \emph default
16645  command line option is used, the inline assembler code will be passed through
16646  the peephole optimizer
16647 \begin_inset LatexCommand \index{Peephole optimizer}
16648
16649 \end_inset
16650
16651 .
16652  There are only a few (if any) cases where this option makes sense, it might
16653  cause some unexpected changes in the inline assembler code.
16654  Please go through the peephole optimizer rules defined in file 
16655 \emph on
16656 SDCCpeeph.def
16657 \emph default
16658  before using this option.
16659 \end_layout
16660
16661 \begin_layout Subsection
16662 Naked Functions
16663 \begin_inset LatexCommand \label{sub:Naked-Functions}
16664
16665 \end_inset
16666
16667
16668 \begin_inset LatexCommand \index{Naked functions}
16669
16670 \end_inset
16671
16672
16673 \end_layout
16674
16675 \begin_layout Standard
16676 A special keyword may be associated with a function declaring it as 
16677 \emph on
16678 _naked
16679 \begin_inset LatexCommand \index{\_naked}
16680
16681 \end_inset
16682
16683
16684 \begin_inset LatexCommand \index{\_\_naked}
16685
16686 \end_inset
16687
16688 .
16689  
16690 \emph default
16691 The 
16692 \emph on
16693 _naked
16694 \emph default
16695  function modifier attribute prevents the compiler from generating prologue
16696 \begin_inset LatexCommand \index{function prologue}
16697
16698 \end_inset
16699
16700  and epilogue
16701 \begin_inset LatexCommand \index{function epilogue}
16702
16703 \end_inset
16704
16705  code for that function.
16706  This means that the user is entirely responsible for such things as saving
16707  any registers that may need to be preserved, selecting the proper register
16708  bank, generating the 
16709 \emph on
16710 return
16711 \emph default
16712  instruction at the end, etc.
16713  Practically, this means that the contents of the function must be written
16714  in inline assembler.
16715  This is particularly useful for interrupt functions, which can have a large
16716  (and often unnecessary) prologue/epilogue.
16717  For example, compare the code generated by these two functions:
16718 \end_layout
16719
16720 \begin_layout Verse
16721
16722 \family typewriter
16723 volatile
16724 \begin_inset LatexCommand \index{volatile}
16725
16726 \end_inset
16727
16728  data unsigned char counter;
16729 \newline
16730
16731 \newline
16732 void simpleInterrupt(void) __interrupt
16733 \begin_inset LatexCommand \index{interrupt}
16734
16735 \end_inset
16736
16737
16738 \begin_inset LatexCommand \index{\_\_interrupt}
16739
16740 \end_inset
16741
16742  (1)
16743 \newline
16744 {
16745 \newline
16746 \InsetSpace ~
16747 \InsetSpace ~
16748 \InsetSpace ~
16749 \InsetSpace ~
16750 counter++;
16751 \newline
16752 }
16753 \newline
16754
16755 \newline
16756 void nakedInterrupt(void) __interrupt (2) __naked
16757 \newline
16758 {
16759 \newline
16760 \InsetSpace ~
16761 \InsetSpace ~
16762 \InsetSpace ~
16763 \InsetSpace ~
16764 _asm
16765 \begin_inset LatexCommand \index{\_asm}
16766
16767 \end_inset
16768
16769
16770 \begin_inset LatexCommand \index{\_\_asm}
16771
16772 \end_inset
16773
16774
16775 \newline
16776 \InsetSpace ~
16777 \InsetSpace ~
16778 \InsetSpace ~
16779 \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 inc\InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 \InsetSpace ~
16787 _counter ; does not change flags, no need to save psw
16788 \newline
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 reti\InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 ; MUST explicitly
16800  include ret or reti in _naked function.
16801 \newline
16802 \InsetSpace ~
16803 \InsetSpace ~
16804 \InsetSpace ~
16805 \InsetSpace ~
16806 _endasm
16807 \begin_inset LatexCommand \index{\_endasm}
16808
16809 \end_inset
16810
16811
16812 \begin_inset LatexCommand \index{\_\_endasm}
16813
16814 \end_inset
16815
16816 ;
16817 \newline
16818 }
16819 \end_layout
16820
16821 \begin_layout Standard
16822 For an 8051 target, the generated simpleInterrupt looks like:
16823 \end_layout
16824
16825 \begin_layout Verse
16826
16827 \family typewriter
16828 Note, this is an 
16829 \emph on
16830 outdated
16831 \emph default
16832  example, recent versions of SDCC generate
16833 \newline
16834 the 
16835 \emph on
16836 same
16837 \emph default
16838  code for simpleInterrupt() and nakedInterrupt()!
16839 \newline
16840
16841 \newline
16842 _simpleInterrupt:
16843 \newline
16844 \InsetSpace ~
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 push\InsetSpace ~
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 acc
16853 \newline
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 push\InsetSpace ~
16859 \InsetSpace ~
16860 \InsetSpace ~
16861 \InsetSpace ~
16862 b
16863 \newline
16864 \InsetSpace ~
16865 \InsetSpace ~
16866 \InsetSpace ~
16867 \InsetSpace ~
16868 pu
16869 sh\InsetSpace ~
16870 \InsetSpace ~
16871 \InsetSpace ~
16872 \InsetSpace ~
16873 dpl
16874 \newline
16875 \InsetSpace ~
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 push\InsetSpace ~
16880 \InsetSpace ~
16881 \InsetSpace ~
16882 \InsetSpace ~
16883 dph
16884 \newline
16885 \InsetSpace ~
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 push\InsetSpace ~
16890 \InsetSpace ~
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 psw
16894 \newline
16895 \InsetSpace ~
16896 \InsetSpace ~
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 mov\InsetSpace ~
16900 \InsetSpace ~
16901 \InsetSpace ~
16902 \InsetSpace ~
16903 \InsetSpace ~
16904 psw,#0x00
16905 \newline
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 inc\InsetSpace ~
16911 \InsetSpace ~
16912 \InsetSpace ~
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 _counter
16916 \newline
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 pop\InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 \InsetSpace ~
16926 psw
16927 \newline
16928 \InsetSpace ~
16929 \InsetSpace ~
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 pop\InsetSpace ~
16933 \InsetSpace ~
16934 \InsetSpace ~
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 dph
16938 \newline
16939 \InsetSpace ~
16940 \InsetSpace ~
16941 \InsetSpace ~
16942 \InsetSpace ~
16943 pop\InsetSpace ~
16944 \InsetSpace ~
16945 \InsetSpace ~
16946 \InsetSpace ~
16947 \InsetSpace ~
16948 dpl
16949 \newline
16950 \InsetSpace ~
16951 \InsetSpace ~
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 pop\InsetSpace ~
16955 \InsetSpace ~
16956 \InsetSpace ~
16957 \InsetSpace ~
16958 \InsetSpace ~
16959 b
16960 \newline
16961 \InsetSpace ~
16962 \InsetSpace ~
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 pop\InsetSpace ~
16966 \InsetSpace ~
16967 \InsetSpace ~
16968 \InsetSpace ~
16969 \InsetSpace ~
16970 acc
16971 \newline
16972 \InsetSpace ~
16973 \InsetSpace ~
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 reti
16977 \end_layout
16978
16979 \begin_layout Standard
16980 whereas nakedInterrupt looks like:
16981 \end_layout
16982
16983 \begin_layout Verse
16984
16985 \family typewriter
16986 _nakedInterrupt:
16987 \newline
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 \InsetSpace ~
16992 inc\InsetSpace ~
16993 \InsetSpace ~
16994 \InsetSpace ~
16995 \InsetSpace ~
16996 _counter ; does not change flags, no need to save psw
16997 \newline
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 reti\InsetSpace ~
17003 \InsetSpace ~
17004 \InsetSpace ~
17005 \InsetSpace ~
17006 \InsetSpace ~
17007 \InsetSpace ~
17008 \InsetSpace ~
17009 \InsetSpace ~
17010 \InsetSpace ~
17011 \InsetSpace ~
17012 \InsetSpace ~
17013 \InsetSpace ~
17014 ;
17015  MUST explicitly include ret or reti in _naked function
17016 \end_layout
17017
17018 \begin_layout Standard
17019 The related directive #pragma exclude
17020 \begin_inset LatexCommand \index{\#pragma exclude}
17021
17022 \end_inset
17023
17024  allows a more fine grained control over pushing & popping
17025 \begin_inset LatexCommand \index{push/pop}
17026
17027 \end_inset
17028
17029  the registers.
17030 \end_layout
17031
17032 \begin_layout Standard
17033 While there is nothing preventing you from writing C code inside a 
17034 \family typewriter
17035 _naked
17036 \family default
17037  function, there are many ways to shoot yourself in the foot doing this,
17038  and it is recommended that you stick to inline assembler.
17039 \end_layout
17040
17041 \begin_layout Subsection
17042 Use of Labels within Inline Assembler
17043 \end_layout
17044
17045 \begin_layout Standard
17046 SDCC allows the use of in-line assembler with a few restrictions regarding
17047  labels.
17048  In older versions of the compiler all labels defined within inline assembler
17049  code had to be of the form 
17050 \emph on
17051 nnnnn$
17052 \emph default
17053  where nnnnn is a number less than 100 (which implies a limit of utmost
17054  100 inline assembler labels 
17055 \emph on
17056 per function
17057 \emph default
17058 \noun on
17059 )
17060 \noun default
17061 .
17062  
17063 \end_layout
17064
17065 \begin_layout Verse
17066
17067 \family typewriter
17068 _asm
17069 \begin_inset LatexCommand \index{\_asm}
17070
17071 \end_inset
17072
17073
17074 \begin_inset LatexCommand \index{\_\_asm}
17075
17076 \end_inset
17077
17078  
17079 \newline
17080 \InsetSpace ~
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 mov\InsetSpace ~
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 \InsetSpace ~
17088 \InsetSpace ~
17089 b,#10 
17090 \newline
17091 00001$: 
17092 \newline
17093 \InsetSpace ~
17094 \InsetSpace ~
17095 \InsetSpace ~
17096 \InsetSpace ~
17097 djnz\InsetSpace ~
17098 \InsetSpace ~
17099 \InsetSpace ~
17100 \InsetSpace ~
17101 b,00001$ 
17102 \newline
17103 _endasm
17104 \begin_inset LatexCommand \index{\_endasm}
17105
17106 \end_inset
17107
17108
17109 \begin_inset LatexCommand \index{\_\_endasm}
17110
17111 \end_inset
17112
17113  ;
17114 \end_layout
17115
17116 \begin_layout Standard
17117 Inline assembler code cannot reference any C-labels, however it can reference
17118  labels
17119 \begin_inset LatexCommand \index{Labels}
17120
17121 \end_inset
17122
17123  defined by the inline assembler, e.g.:
17124 \end_layout
17125
17126 \begin_layout Verse
17127
17128 \family typewriter
17129 foo() { 
17130 \newline
17131 \InsetSpace ~
17132 \InsetSpace ~
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 /* some c code */ 
17136 \newline
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 \InsetSpace ~
17140 \InsetSpace ~
17141 _asm 
17142 \newline
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 \InsetSpace ~
17147 \InsetSpace ~
17148 \InsetSpace ~
17149 ; some assembler code 
17150 \newline
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 \InsetSpace ~
17157 ljmp $0003 
17158 \newline
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 \InsetSpace ~
17162 \InsetSpace ~
17163 _endasm;
17164  
17165 \newline
17166 \InsetSpace ~
17167 \InsetSpace ~
17168 \InsetSpace ~
17169 \InsetSpace ~
17170 /* some more c code */ 
17171 \newline
17172 clabel:\InsetSpace ~
17173 \InsetSpace ~
17174 /* inline assembler cannot reference this
17175  label */ 
17176 \newline
17177 \InsetSpace ~
17178 \InsetSpace ~
17179 \InsetSpace ~
17180 \InsetSpace ~
17181 _asm
17182 \newline
17183 \InsetSpace ~
17184 \InsetSpace ~
17185 \InsetSpace ~
17186 \InsetSpace ~
17187 $0003: ;label (can be referenced by inline assembler only)
17188  
17189 \newline
17190 \InsetSpace ~
17191 \InsetSpace ~
17192 \InsetSpace ~
17193 \InsetSpace ~
17194 _endasm
17195 \begin_inset LatexCommand \index{\_endasm}
17196
17197 \end_inset
17198
17199
17200 \begin_inset LatexCommand \index{\_\_endasm}
17201
17202 \end_inset
17203
17204  ; 
17205 \newline
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 /* some more c code */
17211 \newline
17212 }
17213 \end_layout
17214
17215 \begin_layout Standard
17216 In other words inline assembly code can access labels defined in inline
17217  assembly within the scope of the function.
17218  The same goes the other way, i.e.
17219  labels defines in inline assembly can not be accessed by C statements.
17220 \end_layout
17221
17222 \begin_layout Section
17223 Interfacing with Assembler Code
17224 \begin_inset LatexCommand \index{Assembler routines}
17225
17226 \end_inset
17227
17228
17229 \end_layout
17230
17231 \begin_layout Subsection
17232 Global Registers used for Parameter Passing
17233 \begin_inset LatexCommand \index{Parameter passing}
17234
17235 \end_inset
17236
17237
17238 \end_layout
17239
17240 \begin_layout Standard
17241 The compiler always uses the global registers 
17242 \emph on
17243 DPL, DPH
17244 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17245
17246 \end_inset
17247
17248
17249 \begin_inset LatexCommand \index{DPTR}
17250
17251 \end_inset
17252
17253 , B
17254 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17255
17256 \end_inset
17257
17258  
17259 \emph default
17260 and
17261 \emph on
17262  ACC
17263 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17264
17265 \end_inset
17266
17267
17268 \emph default
17269  to pass the first parameter to a function, and also to pass the return
17270  value 
17271 \begin_inset LatexCommand \index{return value}
17272
17273 \end_inset
17274
17275 of function; according to the following scheme: one byte return value in
17276  
17277 \emph on
17278 DPL
17279 \emph default
17280 , two byte value in 
17281 \emph on
17282 DPL
17283 \emph default
17284  (LSB) and 
17285 \emph on
17286 DPH
17287 \emph default
17288  (MSB).
17289  three byte values (generic pointers) in 
17290 \emph on
17291 DPH
17292 \emph default
17293
17294 \emph on
17295 DPL
17296 \emph default
17297  and 
17298 \emph on
17299 B
17300 \emph default
17301 , and four byte values in 
17302 \emph on
17303 DPH
17304 \emph default
17305
17306 \emph on
17307 DPL
17308 \emph default
17309 ,
17310 \emph on
17311  B
17312 \emph default
17313  and 
17314 \emph on
17315 ACC
17316 \emph default
17317 .
17318  Generic pointers
17319 \begin_inset LatexCommand \index{generic pointer}
17320
17321 \end_inset
17322
17323  contain type of accessed memory in 
17324 \emph on
17325 B
17326 \emph default
17327
17328 \series bold
17329 0x00
17330 \series default
17331  -- xdata/far, 
17332 \series bold
17333 0x40
17334 \series default
17335  -- idata/near -- , 
17336 \series bold
17337 0x60
17338 \series default
17339  -- pdata, 
17340 \series bold
17341 0x80
17342 \series default
17343  -- code
17344 \begin_inset Note Note
17345 status collapsed
17346
17347 \begin_layout Standard
17348 This might not be the case of certain memory models (medium???)
17349 \end_layout
17350
17351 \end_inset
17352
17353 .
17354 \end_layout
17355
17356 \begin_layout Standard
17357 The second parameter onwards is either allocated on the stack (for reentrant
17358  routines or if -
17359 \begin_inset ERT
17360 status collapsed
17361
17362 \begin_layout Standard
17363
17364
17365 \backslash
17366 /
17367 \end_layout
17368
17369 \end_inset
17370
17371 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17372  
17373 \end_layout
17374
17375 \begin_layout Subsection
17376 Registers usage
17377 \end_layout
17378
17379 \begin_layout Standard
17380 Unless the called function is declared as 
17381 \family typewriter
17382 _naked
17383 \family default
17384
17385 \begin_inset LatexCommand \index{naked}
17386
17387 \end_inset
17388
17389 , or the -
17390 \begin_inset ERT
17391 status collapsed
17392
17393 \begin_layout Standard
17394
17395
17396 \backslash
17397 /
17398 \end_layout
17399
17400 \end_inset
17401
17402 -callee-saves
17403 \begin_inset LatexCommand \index{-\/-callee-saves}
17404
17405 \end_inset
17406
17407 /-
17408 \begin_inset ERT
17409 status collapsed
17410
17411 \begin_layout Standard
17412
17413
17414 \backslash
17415 /
17416 \end_layout
17417
17418 \end_inset
17419
17420 -all-callee-saves command line option or the corresponding callee_saves
17421  pragma are used, the caller will save the registers (
17422 \emph on
17423 R0-R7
17424 \emph default
17425 ) around the call, so the called function can destroy they content freely.
17426 \end_layout
17427
17428 \begin_layout Standard
17429 If the called function is not declared as 
17430 \family typewriter
17431 _naked
17432 \family default
17433 , the caller will swap register banks around the call, if caller and callee
17434  use different register banks (having them defined by the 
17435 \family typewriter
17436 _using
17437 \family default
17438  modifier).
17439  
17440 \end_layout
17441
17442 \begin_layout Standard
17443 The called function can also use 
17444 \emph on
17445 DPL
17446 \emph default
17447
17448 \emph on
17449 DPH
17450 \emph default
17451
17452 \emph on
17453 B
17454 \emph default
17455  and 
17456 \emph on
17457 ACC
17458 \emph default
17459  observing that they are used for parameter/return value passing.
17460 \end_layout
17461
17462 \begin_layout Subsection
17463 Assembler Routine (non-reentrant)
17464 \end_layout
17465
17466 \begin_layout Standard
17467 In the following example
17468 \begin_inset LatexCommand \index{reentrant}
17469
17470 \end_inset
17471
17472
17473 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17474
17475 \end_inset
17476
17477  the function c_func calls an assembler routine asm_func, which takes two
17478  parameters
17479 \begin_inset LatexCommand \index{function parameter}
17480
17481 \end_inset
17482
17483 .
17484 \end_layout
17485
17486 \begin_layout Verse
17487
17488 \family typewriter
17489 extern int asm_func(unsigned char, unsigned char);
17490 \newline
17491
17492 \newline
17493 int c_func (unsigned char
17494  i, unsigned char j)
17495 \newline
17496 {
17497 \newline
17498 \InsetSpace ~
17499 \InsetSpace ~
17500 \InsetSpace ~
17501 \InsetSpace ~
17502 return asm_func(i,j);
17503 \newline
17504 }
17505 \newline
17506
17507 \newline
17508 int main()
17509 \newline
17510 {
17511 \newline
17512 \InsetSpace ~
17513 \InsetSpace ~
17514 \InsetSpace ~
17515 \InsetSpace ~
17516 return c_func(10,9);
17517 \newline
17518 }
17519 \end_layout
17520
17521 \begin_layout Standard
17522 The corresponding assembler function is:
17523 \end_layout
17524
17525 \begin_layout Verse
17526
17527 \family typewriter
17528 .globl _asm_func_PARM_2 
17529 \newline
17530 \InsetSpace ~
17531 \InsetSpace ~
17532 \InsetSpace ~
17533 \InsetSpace ~
17534 \InsetSpace ~
17535 \InsetSpace ~
17536 \InsetSpace ~
17537 \InsetSpace ~
17538 .globl _asm_func 
17539 \newline
17540 \InsetSpace ~
17541 \InsetSpace ~
17542 \InsetSpace ~
17543 \InsetSpace ~
17544 \InsetSpace ~
17545 \InsetSpace ~
17546 \InsetSpace ~
17547 \InsetSpace ~
17548 .area OSEG 
17549 \newline
17550 _asm_func_PARM_2:
17551 \newline
17552 \InsetSpace ~
17553 \InsetSpace ~
17554 \InsetSpace ~
17555 \InsetSpace ~
17556 \InsetSpace ~
17557 \InsetSpace ~
17558 \InsetSpace ~
17559 \InsetSpace ~
17560 .ds   
17561  1 
17562 \newline
17563 \InsetSpace ~
17564 \InsetSpace ~
17565 \InsetSpace ~
17566 \InsetSpace ~
17567 \InsetSpace ~
17568 \InsetSpace ~
17569 \InsetSpace ~
17570 \InsetSpace ~
17571 .area CSEG 
17572 \newline
17573 _asm_func: 
17574 \newline
17575 \InsetSpace ~
17576 \InsetSpace ~
17577 \InsetSpace ~
17578 \InsetSpace ~
17579 \InsetSpace ~
17580 \InsetSpace ~
17581 \InsetSpace ~
17582 \InsetSpace ~
17583 mov\InsetSpace ~
17584 \InsetSpace ~
17585 \InsetSpace ~
17586 \InsetSpace ~
17587 a,dpl 
17588 \newline
17589 \InsetSpace ~
17590 \InsetSpace ~
17591 \InsetSpace ~
17592 \InsetSpace ~
17593 \InsetSpace ~
17594 \InsetSpace ~
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 add\InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 a,_asm_func_PARM_2 
17602 \newline
17603 \InsetSpace ~
17604 \InsetSpace ~
17605 \InsetSpace ~
17606 \InsetSpace ~
17607 \InsetSpace ~
17608 \InsetSpace ~
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 mov\InsetSpace ~
17612 \InsetSpace ~
17613 \InsetSpace ~
17614 \InsetSpace ~
17615 dpl,a 
17616 \newline
17617 \InsetSpace ~
17618 \InsetSpace ~
17619 \InsetSpace ~
17620 \InsetSpace ~
17621 \InsetSpace ~
17622 \InsetSpace ~
17623 \InsetSpace ~
17624 \InsetSpace ~
17625 mov\InsetSpace ~
17626 \InsetSpace ~
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 dph
17630 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17631
17632 \end_inset
17633
17634 ,#0x00 
17635 \newline
17636 \InsetSpace ~
17637 \InsetSpace ~
17638 \InsetSpace ~
17639 \InsetSpace ~
17640 \InsetSpace ~
17641 \InsetSpace ~
17642 \InsetSpace ~
17643 \InsetSpace ~
17644 ret
17645 \end_layout
17646
17647 \begin_layout Standard
17648 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17649  the parameter number starting from 1, and counting from the left.
17650  The first parameter is passed in 
17651 \emph on
17652 DPH
17653 \emph default
17654
17655 \emph on
17656 DPL
17657 \emph default
17658
17659 \emph on
17660 B
17661 \emph default
17662  and 
17663 \emph on
17664 ACC
17665 \emph default
17666  according to the description above.
17667  The variable name for the second parameter will be _<function_name>_PARM_2.
17668 \newline
17669
17670 \newline
17671 Assem
17672 ble the assembler routine with the following command:
17673 \newline
17674
17675 \newline
17676
17677 \family sans
17678 \series bold
17679 asx8051 -losg asmfunc.asm
17680 \newline
17681
17682 \newline
17683
17684 \family default
17685 \series default
17686 Then compile and link the assembler routine to the C source file with the
17687  following command:
17688 \newline
17689
17690 \newline
17691
17692 \family sans
17693 \series bold
17694 sdcc cfunc.c asmfunc.rel
17695 \end_layout
17696
17697 \begin_layout Subsection
17698 Assembler Routine (reentrant)
17699 \end_layout
17700
17701 \begin_layout Standard
17702 In this case
17703 \begin_inset LatexCommand \index{reentrant}
17704
17705 \end_inset
17706
17707
17708 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17709
17710 \end_inset
17711
17712  the second parameter
17713 \begin_inset LatexCommand \index{function parameter}
17714
17715 \end_inset
17716
17717  onwards will be passed on the stack, the parameters are pushed from right
17718  to left i.e.
17719  before the call the second leftmost parameter will be on the top of the
17720  stack (the leftmost parameter is passed in registers).
17721  Here is an example:
17722 \end_layout
17723
17724 \begin_layout Verse
17725
17726 \family typewriter
17727 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17728 \newline
17729
17730 \newline
17731 int
17732  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
17733 \newline
17734 {
17735  
17736 \newline
17737 \InsetSpace ~
17738 \InsetSpace ~
17739 \InsetSpace ~
17740 \InsetSpace ~
17741 return asm_func(i,j,k); 
17742 \newline
17743
17744 \newline
17745
17746 \newline
17747 int main() 
17748 \newline
17749
17750 \newline
17751 \InsetSpace ~
17752 \InsetSpace ~
17753 \InsetSpace ~
17754 \InsetSpace ~
17755 return c_func(10,9,8); 
17756 \newline
17757 }
17758 \end_layout
17759
17760 \begin_layout Standard
17761 The corresponding (unoptimized) assembler routine is:
17762 \end_layout
17763
17764 \begin_layout Verse
17765
17766 \family typewriter
17767 .globl _asm_func 
17768 \newline
17769 _asm_func: 
17770 \newline
17771 \InsetSpace ~
17772 \InsetSpace ~
17773 \InsetSpace ~
17774 \InsetSpace ~
17775 push\InsetSpace ~
17776 _bp 
17777 \newline
17778 \InsetSpace ~
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 \InsetSpace ~
17782 mov\InsetSpace ~
17783 \InsetSpace ~
17784 _bp,sp\InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 \InsetSpace ~
17788 \InsetSpace ~
17789 \InsetSpace ~
17790 ;stack contains: _bp, return
17791  address, second parameter, third parameter
17792 \newline
17793 \InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 \InsetSpace ~
17797 mov\InsetSpace ~
17798 \InsetSpace ~
17799 r2,dpl
17800 \newline
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 \InsetSpace ~
17804 \InsetSpace ~
17805 mov\InsetSpace ~
17806 \InsetSpace ~
17807 a,_bp
17808 \newline
17809 \InsetSpace ~
17810 \InsetSpace ~
17811 \InsetSpace ~
17812 \InsetSpace ~
17813 add\InsetSpace ~
17814 \InsetSpace ~
17815 a,#0xfd\InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 \InsetSpace ~
17820 ;calculate
17821  pointer to the second parameter
17822 \newline
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 \InsetSpace ~
17826 \InsetSpace ~
17827 mov\InsetSpace ~
17828 \InsetSpace ~
17829 r0,a 
17830 \newline
17831 \InsetSpace ~
17832 \InsetSpace ~
17833 \InsetSpace ~
17834 \InsetSpace ~
17835 mov\InsetSpace ~
17836 \InsetSpace ~
17837 a,_bp 
17838 \newline
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 \InsetSpace ~
17842 \InsetSpace ~
17843 add\InsetSpace ~
17844 \InsetSpace ~
17845 a,#0xfc\InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 \InsetSpace ~
17849 \InsetSpace ~
17850 ;calculate pointer
17851  to the rightmost parameter
17852 \newline
17853 \InsetSpace ~
17854 \InsetSpace ~
17855 \InsetSpace ~
17856 \InsetSpace ~
17857 mov\InsetSpace ~
17858 \InsetSpace ~
17859 r1,a 
17860 \newline
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 \InsetSpace ~
17864 \InsetSpace ~
17865 mov\InsetSpace ~
17866 \InsetSpace ~
17867 a,@r0
17868 \newline
17869 \InsetSpace ~
17870 \InsetSpace ~
17871 \InsetSpace ~
17872 \InsetSpace ~
17873 add\InsetSpace ~
17874 \InsetSpace ~
17875 a,@r1
17876 \newline
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 add\InsetSpace ~
17882 \InsetSpace ~
17883 a,r2\InsetSpace ~
17884 \InsetSpace ~
17885 \InsetSpace ~
17886 \InsetSpace ~
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 \InsetSpace ~
17890 \InsetSpace ~
17891 ;calculate the
17892  result (= sum of all three parameters)
17893 \newline
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 \InsetSpace ~
17898 mov\InsetSpace ~
17899 \InsetSpace ~
17900 dpl,a\InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 \InsetSpace ~
17907 ;return value goes into dptr
17908  (cast into int)
17909 \newline
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 \InsetSpace ~
17914 mov\InsetSpace ~
17915 \InsetSpace ~
17916 dph,#0x00 
17917 \newline
17918 \InsetSpace ~
17919 \InsetSpace ~
17920 \InsetSpace ~
17921 \InsetSpace ~
17922 mov\InsetSpace ~
17923 \InsetSpace ~
17924 sp,_bp 
17925 \newline
17926 \InsetSpace ~
17927 \InsetSpace ~
17928 \InsetSpace ~
17929 \InsetSpace ~
17930 pop\InsetSpace ~
17931 \InsetSpace ~
17932 _bp 
17933 \newline
17934 \InsetSpace ~
17935 \InsetSpace ~
17936 \InsetSpace ~
17937 \InsetSpace ~
17938 ret
17939 \end_layout
17940
17941 \begin_layout Standard
17942 The compiling and linking procedure remains the same, however note the extra
17943  entry & exit linkage required for the assembler code, _bp is the stack
17944  frame pointer and is used to compute the offset into the stack for parameters
17945  and local variables.
17946 \begin_inset VSpace bigskip
17947 \end_inset
17948
17949
17950 \end_layout
17951
17952 \begin_layout Section
17953 int (16 bit)
17954 \begin_inset LatexCommand \index{int (16 bit)}
17955
17956 \end_inset
17957
17958  and long (32 bit)
17959 \begin_inset LatexCommand \index{long (32 bit)}
17960
17961 \end_inset
17962
17963  Support
17964 \end_layout
17965
17966 \begin_layout Standard
17967 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17968  multiplication and modulus operations are implemented by support routines.
17969  These support routines are all developed in ANSI-C to facilitate porting
17970  to other MCUs, although some model specific assembler optimizations are
17971  used.
17972  The following files contain the described routines, all of them can be
17973  found in <installdir>/share/sdcc/lib.
17974 \newline
17975
17976 \end_layout
17977
17978 \begin_layout Standard
17979 \align center
17980 \begin_inset Tabular
17981 <lyxtabular version="3" rows="11" columns="2">
17982 <features>
17983 <column alignment="left" valignment="top" leftline="true" width="0">
17984 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17985 <row topline="true" bottomline="true">
17986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17987 \begin_inset Text
17988
17989 \begin_layout Standard
17990
17991 \series bold
17992 Function
17993 \end_layout
17994
17995 \end_inset
17996 </cell>
17997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17998 \begin_inset Text
17999
18000 \begin_layout Standard
18001
18002 \series bold
18003 Description
18004 \end_layout
18005
18006 \end_inset
18007 </cell>
18008 </row>
18009 <row topline="true">
18010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18011 \begin_inset Text
18012
18013 \begin_layout Standard
18014 _mulint.c 
18015 \end_layout
18016
18017 \end_inset
18018 </cell>
18019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18020 \begin_inset Text
18021
18022 \begin_layout Standard
18023 16 bit multiplication
18024 \end_layout
18025
18026 \end_inset
18027 </cell>
18028 </row>
18029 <row topline="true">
18030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18031 \begin_inset Text
18032
18033 \begin_layout Standard
18034 _divsint.c 
18035 \end_layout
18036
18037 \end_inset
18038 </cell>
18039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18040 \begin_inset Text
18041
18042 \begin_layout Standard
18043  signed 16 bit division (calls _divuint)
18044 \end_layout
18045
18046 \end_inset
18047 </cell>
18048 </row>
18049 <row topline="true">
18050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18051 \begin_inset Text
18052
18053 \begin_layout Standard
18054 _divuint.c 
18055 \end_layout
18056
18057 \end_inset
18058 </cell>
18059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18060 \begin_inset Text
18061
18062 \begin_layout Standard
18063  unsigned 16 bit division
18064 \end_layout
18065
18066 \end_inset
18067 </cell>
18068 </row>
18069 <row topline="true">
18070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18071 \begin_inset Text
18072
18073 \begin_layout Standard
18074 _modsint.c
18075 \end_layout
18076
18077 \end_inset
18078 </cell>
18079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18080 \begin_inset Text
18081
18082 \begin_layout Standard
18083 signed 16 bit modulus (calls _moduint)
18084 \end_layout
18085
18086 \end_inset
18087 </cell>
18088 </row>
18089 <row topline="true">
18090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18091 \begin_inset Text
18092
18093 \begin_layout Standard
18094 _moduint.c
18095 \end_layout
18096
18097 \end_inset
18098 </cell>
18099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18100 \begin_inset Text
18101
18102 \begin_layout Standard
18103 unsigned 16 bit modulus
18104 \end_layout
18105
18106 \end_inset
18107 </cell>
18108 </row>
18109 <row topline="true">
18110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18111 \begin_inset Text
18112
18113 \begin_layout Standard
18114 _mullong.c
18115 \end_layout
18116
18117 \end_inset
18118 </cell>
18119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18120 \begin_inset Text
18121
18122 \begin_layout Standard
18123 32 bit multiplication
18124 \end_layout
18125
18126 \end_inset
18127 </cell>
18128 </row>
18129 <row topline="true">
18130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18131 \begin_inset Text
18132
18133 \begin_layout Standard
18134 _divslong.c 
18135 \end_layout
18136
18137 \end_inset
18138 </cell>
18139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18140 \begin_inset Text
18141
18142 \begin_layout Standard
18143  signed 32 division (calls _divulong)
18144 \end_layout
18145
18146 \end_inset
18147 </cell>
18148 </row>
18149 <row topline="true">
18150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18151 \begin_inset Text
18152
18153 \begin_layout Standard
18154 _divulong.c 
18155 \end_layout
18156
18157 \end_inset
18158 </cell>
18159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18160 \begin_inset Text
18161
18162 \begin_layout Standard
18163 unsigned 32 division
18164 \end_layout
18165
18166 \end_inset
18167 </cell>
18168 </row>
18169 <row topline="true">
18170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18171 \begin_inset Text
18172
18173 \begin_layout Standard
18174 _modslong.c
18175 \end_layout
18176
18177 \end_inset
18178 </cell>
18179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18180 \begin_inset Text
18181
18182 \begin_layout Standard
18183  signed 32 bit modulus (calls _modulong)
18184 \end_layout
18185
18186 \end_inset
18187 </cell>
18188 </row>
18189 <row topline="true" bottomline="true">
18190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18191 \begin_inset Text
18192
18193 \begin_layout Standard
18194 _modulong.c
18195 \end_layout
18196
18197 \end_inset
18198 </cell>
18199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18200 \begin_inset Text
18201
18202 \begin_layout Standard
18203 unsigned 32 bit modulus
18204 \end_layout
18205
18206 \end_inset
18207 </cell>
18208 </row>
18209 </lyxtabular>
18210
18211 \end_inset
18212
18213
18214 \newline
18215
18216 \end_layout
18217
18218 \begin_layout Standard
18219 Since they are compiled as 
18220 \emph on
18221 non-reentrant
18222 \emph default
18223
18224 \begin_inset LatexCommand \index{reentrant}
18225
18226 \end_inset
18227
18228 , interrupt
18229 \begin_inset LatexCommand \index{interrupt}
18230
18231 \end_inset
18232
18233  service routines should not do any of the above operations.
18234  If this is unavoidable then the above routines will need to be compiled
18235  with the 
18236 \emph on
18237 -
18238 \begin_inset ERT
18239 status collapsed
18240
18241 \begin_layout Standard
18242
18243
18244 \backslash
18245 /
18246 \end_layout
18247
18248 \end_inset
18249
18250 -stack-auto
18251 \begin_inset LatexCommand \index{-\/-stack-auto}
18252
18253 \end_inset
18254
18255
18256 \emph default
18257  option, after which the source program will have to be compiled with 
18258 \emph on
18259 -
18260 \begin_inset ERT
18261 status collapsed
18262
18263 \begin_layout Standard
18264
18265
18266 \backslash
18267 /
18268 \end_layout
18269
18270 \end_inset
18271
18272 -int-long-reent
18273 \begin_inset LatexCommand \index{-\/-int-long-reent}
18274
18275 \end_inset
18276
18277
18278 \emph default
18279  option.
18280  Notice that you don't have to call these routines directly.
18281  The compiler will use them automatically every time an integer operation
18282  is required.
18283 \end_layout
18284
18285 \begin_layout Section
18286 Floating Point Support
18287 \begin_inset LatexCommand \index{Floating point support}
18288
18289 \end_inset
18290
18291
18292 \end_layout
18293
18294 \begin_layout Standard
18295 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18296  The floating point support routines are derived from gcc's floatlib.c and
18297  consist of the following routines:
18298 \newline
18299
18300 \end_layout
18301
18302 \begin_layout Standard
18303 \align center
18304
18305 \size footnotesize
18306 \begin_inset Tabular
18307 <lyxtabular version="3" rows="17" columns="2">
18308 <features>
18309 <column alignment="left" valignment="top" leftline="true" width="0">
18310 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18311 <row topline="true" bottomline="true">
18312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18313 \begin_inset Text
18314
18315 \begin_layout Standard
18316
18317 \family roman
18318 \series medium
18319 \shape up
18320 \size normal
18321 \emph off
18322 \bar no
18323 \noun off
18324 \color none
18325 Function 
18326 \end_layout
18327
18328 \end_inset
18329 </cell>
18330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18331 \begin_inset Text
18332
18333 \begin_layout Standard
18334 Description
18335 \end_layout
18336
18337 \end_inset
18338 </cell>
18339 </row>
18340 <row topline="true">
18341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18342 \begin_inset Text
18343
18344 \begin_layout Standard
18345
18346 \family roman
18347 \series medium
18348 \shape up
18349 \size normal
18350 \emph off
18351 \bar no
18352 \noun off
18353 \color none
18354 _fsadd.c
18355 \end_layout
18356
18357 \end_inset
18358 </cell>
18359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18360 \begin_inset Text
18361
18362 \begin_layout Standard
18363
18364 \family roman
18365 \series medium
18366 \shape up
18367 \size normal
18368 \emph off
18369 \bar no
18370 \noun off
18371 \color none
18372 add floating point numbers
18373 \end_layout
18374
18375 \end_inset
18376 </cell>
18377 </row>
18378 <row topline="true">
18379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18380 \begin_inset Text
18381
18382 \begin_layout Standard
18383
18384 \family roman
18385 \series medium
18386 \shape up
18387 \size normal
18388 \emph off
18389 \bar no
18390 \noun off
18391 \color none
18392 _fssub.c 
18393 \end_layout
18394
18395 \end_inset
18396 </cell>
18397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18398 \begin_inset Text
18399
18400 \begin_layout Standard
18401
18402 \family roman
18403 \series medium
18404 \shape up
18405 \size normal
18406 \emph off
18407 \bar no
18408 \noun off
18409 \color none
18410 subtract floating point numbers 
18411 \end_layout
18412
18413 \end_inset
18414 </cell>
18415 </row>
18416 <row topline="true">
18417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18418 \begin_inset Text
18419
18420 \begin_layout Standard
18421
18422 \family roman
18423 \series medium
18424 \shape up
18425 \size normal
18426 \emph off
18427 \bar no
18428 \noun off
18429 \color none
18430 _fsdiv.c 
18431 \end_layout
18432
18433 \end_inset
18434 </cell>
18435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18436 \begin_inset Text
18437
18438 \begin_layout Standard
18439
18440 \family roman
18441 \series medium
18442 \shape up
18443 \size normal
18444 \emph off
18445 \bar no
18446 \noun off
18447 \color none
18448 divide floating point numbers 
18449 \end_layout
18450
18451 \end_inset
18452 </cell>
18453 </row>
18454 <row topline="true">
18455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18456 \begin_inset Text
18457
18458 \begin_layout Standard
18459
18460 \family roman
18461 \series medium
18462 \shape up
18463 \size normal
18464 \emph off
18465 \bar no
18466 \noun off
18467 \color none
18468 _fsmul.c 
18469 \end_layout
18470
18471 \end_inset
18472 </cell>
18473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18474 \begin_inset Text
18475
18476 \begin_layout Standard
18477
18478 \family roman
18479 \series medium
18480 \shape up
18481 \size normal
18482 \emph off
18483 \bar no
18484 \noun off
18485 \color none
18486 multiply floating point numbers 
18487 \end_layout
18488
18489 \end_inset
18490 </cell>
18491 </row>
18492 <row topline="true">
18493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18494 \begin_inset Text
18495
18496 \begin_layout Standard
18497
18498 \family roman
18499 \series medium
18500 \shape up
18501 \size normal
18502 \emph off
18503 \bar no
18504 \noun off
18505 \color none
18506 _fs2uchar.c
18507 \end_layout
18508
18509 \end_inset
18510 </cell>
18511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18512 \begin_inset Text
18513
18514 \begin_layout Standard
18515
18516 \family roman
18517 \series medium
18518 \shape up
18519 \size normal
18520 \emph off
18521 \bar no
18522 \noun off
18523 \color none
18524 convert floating point to unsigned char
18525 \end_layout
18526
18527 \end_inset
18528 </cell>
18529 </row>
18530 <row topline="true">
18531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18532 \begin_inset Text
18533
18534 \begin_layout Standard
18535
18536 \family roman
18537 \series medium
18538 \shape up
18539 \size normal
18540 \emph off
18541 \bar no
18542 \noun off
18543 \color none
18544 _fs2char.c
18545 \end_layout
18546
18547 \end_inset
18548 </cell>
18549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18550 \begin_inset Text
18551
18552 \begin_layout Standard
18553
18554 \family roman
18555 \series medium
18556 \shape up
18557 \size normal
18558 \emph off
18559 \bar no
18560 \noun off
18561 \color none
18562 convert floating point to signed char
18563 \end_layout
18564
18565 \end_inset
18566 </cell>
18567 </row>
18568 <row topline="true">
18569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18570 \begin_inset Text
18571
18572 \begin_layout Standard
18573
18574 \family roman
18575 \series medium
18576 \shape up
18577 \size normal
18578 \emph off
18579 \bar no
18580 \noun off
18581 \color none
18582 _fs2uint.c
18583 \end_layout
18584
18585 \end_inset
18586 </cell>
18587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18588 \begin_inset Text
18589
18590 \begin_layout Standard
18591
18592 \family roman
18593 \series medium
18594 \shape up
18595 \size normal
18596 \emph off
18597 \bar no
18598 \noun off
18599 \color none
18600 convert floating point to unsigned int
18601 \end_layout
18602
18603 \end_inset
18604 </cell>
18605 </row>
18606 <row topline="true">
18607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18608 \begin_inset Text
18609
18610 \begin_layout Standard
18611
18612 \family roman
18613 \series medium
18614 \shape up
18615 \size normal
18616 \emph off
18617 \bar no
18618 \noun off
18619 \color none
18620 _fs2int.c
18621 \end_layout
18622
18623 \end_inset
18624 </cell>
18625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18626 \begin_inset Text
18627
18628 \begin_layout Standard
18629
18630 \family roman
18631 \series medium
18632 \shape up
18633 \size normal
18634 \emph off
18635 \bar no
18636 \noun off
18637 \color none
18638 convert floating point to signed int
18639 \end_layout
18640
18641 \end_inset
18642 </cell>
18643 </row>
18644 <row topline="true">
18645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18646 \begin_inset Text
18647
18648 \begin_layout Standard
18649
18650 \family roman
18651 \series medium
18652 \shape up
18653 \size normal
18654 \emph off
18655 \bar no
18656 \noun off
18657 \color none
18658 _fs2ulong.
18659 \family default
18660 \series default
18661 \shape default
18662 \size default
18663 \emph default
18664 \bar default
18665 \noun default
18666 c
18667 \end_layout
18668
18669 \end_inset
18670 </cell>
18671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18672 \begin_inset Text
18673
18674 \begin_layout Standard
18675
18676 \family roman
18677 \series medium
18678 \shape up
18679 \size normal
18680 \emph off
18681 \bar no
18682 \noun off
18683 \color none
18684 convert floating point to unsigned long
18685 \end_layout
18686
18687 \end_inset
18688 </cell>
18689 </row>
18690 <row topline="true">
18691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18692 \begin_inset Text
18693
18694 \begin_layout Standard
18695
18696 \family roman
18697 \series medium
18698 \shape up
18699 \size normal
18700 \emph off
18701 \bar no
18702 \noun off
18703 \color none
18704 _fs2long.c
18705 \end_layout
18706
18707 \end_inset
18708 </cell>
18709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18710 \begin_inset Text
18711
18712 \begin_layout Standard
18713
18714 \family roman
18715 \series medium
18716 \shape up
18717 \size normal
18718 \emph off
18719 \bar no
18720 \noun off
18721 \color none
18722 convert floating point to signed long
18723 \end_layout
18724
18725 \end_inset
18726 </cell>
18727 </row>
18728 <row topline="true">
18729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18730 \begin_inset Text
18731
18732 \begin_layout Standard
18733
18734 \family roman
18735 \series medium
18736 \shape up
18737 \size normal
18738 \emph off
18739 \bar no
18740 \noun off
18741 \color none
18742 _uchar2fs.c
18743 \end_layout
18744
18745 \end_inset
18746 </cell>
18747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18748 \begin_inset Text
18749
18750 \begin_layout Standard
18751
18752 \family roman
18753 \series medium
18754 \shape up
18755 \size normal
18756 \emph off
18757 \bar no
18758 \noun off
18759 \color none
18760 convert unsigned char to floating point
18761 \end_layout
18762
18763 \end_inset
18764 </cell>
18765 </row>
18766 <row topline="true">
18767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18768 \begin_inset Text
18769
18770 \begin_layout Standard
18771
18772 \family roman
18773 \series medium
18774 \shape up
18775 \size normal
18776 \emph off
18777 \bar no
18778 \noun off
18779 \color none
18780 _char2fs.c
18781 \end_layout
18782
18783 \end_inset
18784 </cell>
18785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18786 \begin_inset Text
18787
18788 \begin_layout Standard
18789
18790 \family roman
18791 \series medium
18792 \shape up
18793 \size normal
18794 \emph off
18795 \bar no
18796 \noun off
18797 \color none
18798 convert char to floating point number
18799 \end_layout
18800
18801 \end_inset
18802 </cell>
18803 </row>
18804 <row topline="true">
18805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18806 \begin_inset Text
18807
18808 \begin_layout Standard
18809
18810 \family roman
18811 \series medium
18812 \shape up
18813 \size normal
18814 \emph off
18815 \bar no
18816 \noun off
18817 \color none
18818 _uint2fs.c
18819 \end_layout
18820
18821 \end_inset
18822 </cell>
18823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18824 \begin_inset Text
18825
18826 \begin_layout Standard
18827
18828 \family roman
18829 \series medium
18830 \shape up
18831 \size normal
18832 \emph off
18833 \bar no
18834 \noun off
18835 \color none
18836 convert unsigned int to floating point
18837 \end_layout
18838
18839 \end_inset
18840 </cell>
18841 </row>
18842 <row topline="true">
18843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18844 \begin_inset Text
18845
18846 \begin_layout Standard
18847
18848 \family roman
18849 \series medium
18850 \shape up
18851 \size normal
18852 \emph off
18853 \bar no
18854 \noun off
18855 \color none
18856 _int2fs.c
18857 \end_layout
18858
18859 \end_inset
18860 </cell>
18861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18862 \begin_inset Text
18863
18864 \begin_layout Standard
18865
18866 \family roman
18867 \series medium
18868 \shape up
18869 \size normal
18870 \emph off
18871 \bar no
18872 \noun off
18873 \color none
18874 convert int to floating point numbers
18875 \end_layout
18876
18877 \end_inset
18878 </cell>
18879 </row>
18880 <row topline="true">
18881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18882 \begin_inset Text
18883
18884 \begin_layout Standard
18885
18886 \family roman
18887 \series medium
18888 \shape up
18889 \size normal
18890 \emph off
18891 \bar no
18892 \noun off
18893 \color none
18894 _ulong2fs.c
18895 \end_layout
18896
18897 \end_inset
18898 </cell>
18899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18900 \begin_inset Text
18901
18902 \begin_layout Standard
18903
18904 \family roman
18905 \series medium
18906 \shape up
18907 \size normal
18908 \emph off
18909 \bar no
18910 \noun off
18911 \color none
18912 convert unsigned long to floating point number
18913 \end_layout
18914
18915 \end_inset
18916 </cell>
18917 </row>
18918 <row topline="true" bottomline="true">
18919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18920 \begin_inset Text
18921
18922 \begin_layout Standard
18923
18924 \family roman
18925 \series medium
18926 \shape up
18927 \size normal
18928 \emph off
18929 \bar no
18930 \noun off
18931 \color none
18932 _long2fs.c
18933 \end_layout
18934
18935 \end_inset
18936 </cell>
18937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18938 \begin_inset Text
18939
18940 \begin_layout Standard
18941
18942 \family roman
18943 \series medium
18944 \shape up
18945 \size normal
18946 \emph off
18947 \bar no
18948 \noun off
18949 \color none
18950 convert long to floating point number
18951 \end_layout
18952
18953 \end_inset
18954 </cell>
18955 </row>
18956 </lyxtabular>
18957
18958 \end_inset
18959
18960
18961 \newline
18962
18963 \end_layout
18964
18965 \begin_layout Standard
18966 These support routines are developed in ANSI-C so there is room for space
18967  and speed improvement
18968 \begin_inset Foot
18969 status open
18970
18971 \begin_layout Standard
18972 These floating point routines (
18973 \emph on
18974 not
18975 \emph default
18976  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18977  
18978 \end_layout
18979
18980 \end_inset
18981
18982 .
18983  Note if all these routines are used simultaneously the data space might
18984  overflow.
18985  For serious floating point usage the large model might be needed.
18986  Also notice that you don't have to call this routines directly.
18987  The compiler will use them automatically every time a floating point operation
18988  is required.
18989 \begin_inset VSpace bigskip
18990 \end_inset
18991
18992
18993 \end_layout
18994
18995 \begin_layout Section
18996 Library Routines
18997 \begin_inset LatexCommand \index{Libraries}
18998
18999 \end_inset
19000
19001
19002 \end_layout
19003
19004 \begin_layout Standard
19005
19006 \emph on
19007 <pending: this is messy and incomplete - a little more information is in
19008  sdcc/doc/libdoc.txt
19009 \emph default
19010  >
19011 \end_layout
19012
19013 \begin_layout Subsection
19014 Compiler support routines (_gptrget, _mulint etc.)
19015 \end_layout
19016
19017 \begin_layout Subsection
19018 Stdclib functions (puts, printf, strcat etc.)
19019 \end_layout
19020
19021 \begin_layout Subsubsection
19022 <stdio.h>
19023 \end_layout
19024
19025 \begin_layout Paragraph
19026 getchar(), putchar()
19027 \end_layout
19028
19029 \begin_layout Standard
19030 \begin_inset LatexCommand \index{<stdio.h>}
19031
19032 \end_inset
19033
19034 As usual on embedded systems you have to provide your own 
19035 \family typewriter
19036 getchar()
19037 \begin_inset LatexCommand \index{getchar()}
19038
19039 \end_inset
19040
19041  
19042 \family default
19043 and 
19044 \family typewriter
19045 putchar()
19046 \begin_inset LatexCommand \index{putchar()}
19047
19048 \end_inset
19049
19050
19051 \family default
19052  routines.
19053  SDCC does not know whether the system connects to a serial line with or
19054  without handshake, LCD, keyboard or other device.
19055  And whether a 
19056 \family typewriter
19057 lf
19058 \family default
19059  to 
19060 \family typewriter
19061 crlf
19062 \family default
19063  conversion within 
19064 \family typewriter
19065 putchar()
19066 \family default
19067  is intended.
19068  You'll find examples for serial routines f.e.
19069  in sdcc/device/lib.
19070  For the mcs51 this minimalistic polling 
19071 \family typewriter
19072 putchar()
19073 \family default
19074  routine might be a start:
19075 \end_layout
19076
19077 \begin_layout Verse
19078
19079 \family typewriter
19080 void putchar (char c) { 
19081 \newline
19082 \InsetSpace ~
19083 \InsetSpace ~
19084 \InsetSpace ~
19085 \InsetSpace ~
19086 while (!TI)\InsetSpace ~
19087 \InsetSpace ~
19088 \InsetSpace ~
19089  /* assumes UART is initialized */
19090 \newline
19091 \InsetSpace ~
19092 \InsetSpace ~
19093 \InsetSpace ~
19094 \InsetSpace ~
19095 \InsetSpace ~
19096 \InsetSpace ~
19097 \InsetSpace ~
19098 \InsetSpace ~
19099 ;
19100 \newline
19101 \InsetSpace ~
19102 \InsetSpace ~
19103 \InsetSpace ~
19104 \InsetSpace ~
19105 TI
19106  = 0;
19107 \newline
19108 \InsetSpace ~
19109 \InsetSpace ~
19110 \InsetSpace ~
19111 \InsetSpace ~
19112 SBUF = c;
19113 \newline
19114 }
19115 \end_layout
19116
19117 \begin_layout Paragraph
19118 printf()
19119 \end_layout
19120
19121 \begin_layout Standard
19122 The default
19123 \family typewriter
19124  printf()
19125 \begin_inset LatexCommand \index{printf()}
19126
19127 \end_inset
19128
19129
19130 \family default
19131  implementation in
19132 \family typewriter
19133  printf_large.c
19134 \family default
19135  does not support float (except on ds390).
19136  To enable this recompile it with the option 
19137 \emph on
19138 -
19139 \begin_inset ERT
19140 status collapsed
19141
19142 \begin_layout Standard
19143
19144
19145 \backslash
19146 /
19147 \end_layout
19148
19149 \end_inset
19150
19151 DUSE_FLOATS=1
19152 \begin_inset LatexCommand \index{USE\_FLOATS}
19153
19154 \end_inset
19155
19156
19157 \emph default
19158  on the command line.
19159  Use
19160 \emph on
19161  -
19162 \begin_inset ERT
19163 status collapsed
19164
19165 \begin_layout Standard
19166
19167
19168 \backslash
19169 /
19170 \end_layout
19171
19172 \end_inset
19173
19174 -model-large
19175 \begin_inset LatexCommand \index{-\/-model-large}
19176
19177 \end_inset
19178
19179
19180 \emph default
19181  for the mcs51 port, since this uses a lot of memory.
19182 \end_layout
19183
19184 \begin_layout Standard
19185 If you're short on code memory you might want to use 
19186 \family typewriter
19187 printf_small()
19188 \begin_inset LatexCommand \index{printf\_small()}
19189
19190 \end_inset
19191
19192
19193 \family default
19194  
19195 \emph on
19196 instead
19197 \emph default
19198  of
19199 \family typewriter
19200  printf().
19201
19202 \family default
19203  For the mcs51 there additionally are assembly versions 
19204 \family typewriter
19205 printf_tiny()
19206 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19207
19208 \end_inset
19209
19210
19211 \family default
19212  (subset of printf using less than 270 bytes) and 
19213 \family typewriter
19214 printf_fast()
19215 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19216
19217 \end_inset
19218
19219  
19220 \family default
19221 and
19222 \family typewriter
19223  printf_fast_f()
19224 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19225
19226 \end_inset
19227
19228
19229 \family default
19230  (floating-point aware version of printf_fast) which should fit the requirements
19231  of many embedded systems (printf_fast() can be customized by unsetting
19232  #defines to 
19233 \emph on
19234 not
19235 \emph default
19236  support long variables and field widths).
19237  Be sure to use only one of these printf options within a project.
19238 \newline
19239
19240 \end_layout
19241
19242 \begin_layout Standard
19243 Feature matrix of different 
19244 \emph on
19245 printf
19246 \emph default
19247  options on mcs51.
19248 \end_layout
19249
19250 \begin_layout Standard
19251 \begin_inset Tabular
19252 <lyxtabular version="3" rows="14" columns="7">
19253 <features islongtable="true">
19254 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19255 <column alignment="center" valignment="top" leftline="true" width="0">
19256 <column alignment="center" valignment="top" leftline="true" width="12col%">
19257 <column alignment="center" valignment="top" leftline="true" width="10col%">
19258 <column alignment="center" valignment="top" leftline="true" width="0">
19259 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19260 <column alignment="center" valignment="top" rightline="true" width="0">
19261 <row topline="true" bottomline="true" endhead="true">
19262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19263 \begin_inset Text
19264
19265 \begin_layout Standard
19266
19267 \series bold
19268 \size large
19269 mcs51
19270 \end_layout
19271
19272 \end_inset
19273 </cell>
19274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19275 \begin_inset Text
19276
19277 \begin_layout Standard
19278 printf
19279 \begin_inset LatexCommand \index{printf}
19280
19281 \end_inset
19282
19283
19284 \end_layout
19285
19286 \end_inset
19287 </cell>
19288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19289 \begin_inset Text
19290
19291 \begin_layout Standard
19292 printf 
19293 \size scriptsize
19294 USE_FLOATS=1
19295 \end_layout
19296
19297 \end_inset
19298 </cell>
19299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19300 \begin_inset Text
19301
19302 \begin_layout Standard
19303 printf_small
19304 \end_layout
19305
19306 \end_inset
19307 </cell>
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19309 \begin_inset Text
19310
19311 \begin_layout Standard
19312 printf_fast
19313 \end_layout
19314
19315 \end_inset
19316 </cell>
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19318 \begin_inset Text
19319
19320 \begin_layout Standard
19321 printf_fast_f
19322 \end_layout
19323
19324 \end_inset
19325 </cell>
19326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19327 \begin_inset Text
19328
19329 \begin_layout Standard
19330 printf_tiny
19331 \end_layout
19332
19333 \end_inset
19334 </cell>
19335 </row>
19336 <row topline="true" endhead="true">
19337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19338 \begin_inset Text
19339
19340 \begin_layout Standard
19341 filename
19342 \end_layout
19343
19344 \end_inset
19345 </cell>
19346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19347 \begin_inset Text
19348
19349 \begin_layout Standard
19350
19351 \size scriptsize
19352 printf_large.c
19353 \end_layout
19354
19355 \end_inset
19356 </cell>
19357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19358 \begin_inset Text
19359
19360 \begin_layout Standard
19361
19362 \size scriptsize
19363 printf_large.c
19364 \end_layout
19365
19366 \end_inset
19367 </cell>
19368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19369 \begin_inset Text
19370
19371 \begin_layout Standard
19372
19373 \size scriptsize
19374 printfl.c
19375 \end_layout
19376
19377 \end_inset
19378 </cell>
19379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19380 \begin_inset Text
19381
19382 \begin_layout Standard
19383
19384 \size scriptsize
19385 printf_fast.c
19386 \end_layout
19387
19388 \end_inset
19389 </cell>
19390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19391 \begin_inset Text
19392
19393 \begin_layout Standard
19394
19395 \size scriptsize
19396 printf_fast_f.c
19397 \end_layout
19398
19399 \end_inset
19400 </cell>
19401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19402 \begin_inset Text
19403
19404 \begin_layout Standard
19405
19406 \size scriptsize
19407 printf_tiny.c
19408 \end_layout
19409
19410 \end_inset
19411 </cell>
19412 </row>
19413 <row topline="true" endhead="true">
19414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19415 \begin_inset Text
19416
19417 \begin_layout Standard
19418 \begin_inset Quotes sld
19419 \end_inset
19420
19421 Hello World
19422 \begin_inset Quotes srd
19423 \end_inset
19424
19425  size
19426 \end_layout
19427
19428 \begin_layout Standard
19429 small / large
19430 \end_layout
19431
19432 \end_inset
19433 </cell>
19434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19435 \begin_inset Text
19436
19437 \begin_layout Standard
19438 1.7k / 2.4k
19439 \end_layout
19440
19441 \end_inset
19442 </cell>
19443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19444 \begin_inset Text
19445
19446 \begin_layout Standard
19447 4.3k / 5.6k
19448 \end_layout
19449
19450 \end_inset
19451 </cell>
19452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19453 \begin_inset Text
19454
19455 \begin_layout Standard
19456 1.2k / 1.8k
19457 \end_layout
19458
19459 \end_inset
19460 </cell>
19461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19462 \begin_inset Text
19463
19464 \begin_layout Standard
19465 1.3k / 1.3k
19466 \end_layout
19467
19468 \end_inset
19469 </cell>
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19471 \begin_inset Text
19472
19473 \begin_layout Standard
19474 1.9k / 1.9k
19475 \end_layout
19476
19477 \end_inset
19478 </cell>
19479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19480 \begin_inset Text
19481
19482 \begin_layout Standard
19483 0.44k / 0.44k
19484 \end_layout
19485
19486 \end_inset
19487 </cell>
19488 </row>
19489 <row topline="true" endhead="true">
19490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19491 \begin_inset Text
19492
19493 \begin_layout Standard
19494 code size
19495 \end_layout
19496
19497 \begin_layout Standard
19498 small / large
19499 \end_layout
19500
19501 \end_inset
19502 </cell>
19503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19504 \begin_inset Text
19505
19506 \begin_layout Standard
19507 1.4k / 2.0k
19508 \end_layout
19509
19510 \end_inset
19511 </cell>
19512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19513 \begin_inset Text
19514
19515 \begin_layout Standard
19516 2.8k / 3.7k
19517 \end_layout
19518
19519 \end_inset
19520 </cell>
19521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19522 \begin_inset Text
19523
19524 \begin_layout Standard
19525 0.45k / 0.47k (+ _ltoa)
19526 \end_layout
19527
19528 \end_inset
19529 </cell>
19530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19531 \begin_inset Text
19532
19533 \begin_layout Standard
19534 1.2k / 1.2k
19535 \end_layout
19536
19537 \end_inset
19538 </cell>
19539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19540 \begin_inset Text
19541
19542 \begin_layout Standard
19543 1.6k / 1.6k
19544 \end_layout
19545
19546 \end_inset
19547 </cell>
19548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19549 \begin_inset Text
19550
19551 \begin_layout Standard
19552 0.26k / 0.26k
19553 \end_layout
19554
19555 \end_inset
19556 </cell>
19557 </row>
19558 <row topline="true">
19559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19560 \begin_inset Text
19561
19562 \begin_layout Standard
19563 formats
19564 \end_layout
19565
19566 \end_inset
19567 </cell>
19568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19569 \begin_inset Text
19570
19571 \begin_layout Standard
19572 cdi
19573 \emph on
19574 o
19575 \emph default
19576 psux
19577 \end_layout
19578
19579 \end_inset
19580 </cell>
19581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19582 \begin_inset Text
19583
19584 \begin_layout Standard
19585
19586 \family roman
19587 \series medium
19588 \shape up
19589 \size normal
19590 \emph off
19591 \bar no
19592 \noun off
19593 \color none
19594 cd
19595 \family default
19596 \series default
19597 \shape default
19598 \size default
19599 \emph default
19600 \bar default
19601 \noun default
19602 f
19603 \family roman
19604 \series medium
19605 \shape up
19606 \size normal
19607 \emph off
19608 \bar no
19609 \noun off
19610 i
19611 \family default
19612 \series default
19613 \shape default
19614 \size default
19615 \emph on
19616 \bar default
19617 \noun default
19618 o
19619 \family roman
19620 \series medium
19621 \shape up
19622 \size normal
19623 \emph off
19624 \bar no
19625 \noun off
19626 psux
19627 \end_layout
19628
19629 \end_inset
19630 </cell>
19631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19632 \begin_inset Text
19633
19634 \begin_layout Standard
19635 c
19636 \family roman
19637 \series medium
19638 \shape up
19639 \size normal
19640 \emph off
19641 \bar no
19642 \noun off
19643 \color none
19644 d
19645 \family default
19646 \series default
19647 \shape default
19648 \size default
19649 \emph on
19650 \bar default
19651 \noun default
19652 o
19653 \family roman
19654 \series medium
19655 \shape up
19656 \size normal
19657 \emph off
19658 \bar no
19659 \noun off
19660 s
19661 \family default
19662 \series default
19663 \shape default
19664 \size default
19665 \emph default
19666 \bar default
19667 \noun default
19668 x
19669 \end_layout
19670
19671 \end_inset
19672 </cell>
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19674 \begin_inset Text
19675
19676 \begin_layout Standard
19677 cdsux
19678 \end_layout
19679
19680 \end_inset
19681 </cell>
19682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19683 \begin_inset Text
19684
19685 \begin_layout Standard
19686 cdfsux
19687 \end_layout
19688
19689 \end_inset
19690 </cell>
19691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19692 \begin_inset Text
19693
19694 \begin_layout Standard
19695 cdsux
19696 \end_layout
19697
19698 \end_inset
19699 </cell>
19700 </row>
19701 <row topline="true">
19702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19703 \begin_inset Text
19704
19705 \begin_layout Standard
19706 long (32 bit) support
19707 \end_layout
19708
19709 \end_inset
19710 </cell>
19711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19712 \begin_inset Text
19713
19714 \begin_layout Standard
19715 x
19716 \end_layout
19717
19718 \end_inset
19719 </cell>
19720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19721 \begin_inset Text
19722
19723 \begin_layout Standard
19724 x
19725 \end_layout
19726
19727 \end_inset
19728 </cell>
19729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19730 \begin_inset Text
19731
19732 \begin_layout Standard
19733 x
19734 \end_layout
19735
19736 \end_inset
19737 </cell>
19738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19739 \begin_inset Text
19740
19741 \begin_layout Standard
19742 x
19743 \end_layout
19744
19745 \end_inset
19746 </cell>
19747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19748 \begin_inset Text
19749
19750 \begin_layout Standard
19751
19752 \family roman
19753 \series medium
19754 \shape up
19755 \size normal
19756 \emph off
19757 \bar no
19758 \noun off
19759 \color none
19760 x
19761 \end_layout
19762
19763 \end_inset
19764 </cell>
19765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19766 \begin_inset Text
19767
19768 \begin_layout Standard
19769 -
19770 \end_layout
19771
19772 \end_inset
19773 </cell>
19774 </row>
19775 <row topline="true">
19776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19777 \begin_inset Text
19778
19779 \begin_layout Standard
19780 byte arguments on stack
19781 \end_layout
19782
19783 \end_inset
19784 </cell>
19785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19786 \begin_inset Text
19787
19788 \begin_layout Standard
19789 b
19790 \end_layout
19791
19792 \end_inset
19793 </cell>
19794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19795 \begin_inset Text
19796
19797 \begin_layout Standard
19798 b
19799 \end_layout
19800
19801 \end_inset
19802 </cell>
19803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19804 \begin_inset Text
19805
19806 \begin_layout Standard
19807 -
19808 \end_layout
19809
19810 \end_inset
19811 </cell>
19812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19813 \begin_inset Text
19814
19815 \begin_layout Standard
19816 -
19817 \end_layout
19818
19819 \end_inset
19820 </cell>
19821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19822 \begin_inset Text
19823
19824 \begin_layout Standard
19825 -
19826 \end_layout
19827
19828 \end_inset
19829 </cell>
19830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19831 \begin_inset Text
19832
19833 \begin_layout Standard
19834 -
19835 \end_layout
19836
19837 \end_inset
19838 </cell>
19839 </row>
19840 <row topline="true">
19841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19842 \begin_inset Text
19843
19844 \begin_layout Standard
19845 float format
19846 \begin_inset LatexCommand \index{Floating point support}
19847
19848 \end_inset
19849
19850
19851 \end_layout
19852
19853 \end_inset
19854 </cell>
19855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19856 \begin_inset Text
19857
19858 \begin_layout Standard
19859 -
19860 \end_layout
19861
19862 \end_inset
19863 </cell>
19864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19865 \begin_inset Text
19866
19867 \begin_layout Standard
19868 %f
19869 \end_layout
19870
19871 \end_inset
19872 </cell>
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19874 \begin_inset Text
19875
19876 \begin_layout Standard
19877 -
19878 \end_layout
19879
19880 \end_inset
19881 </cell>
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19883 \begin_inset Text
19884
19885 \begin_layout Standard
19886 -
19887 \end_layout
19888
19889 \end_inset
19890 </cell>
19891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19892 \begin_inset Text
19893
19894 \begin_layout Standard
19895 %f
19896 \begin_inset Foot
19897 status collapsed
19898
19899 \begin_layout Standard
19900 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19901 \end_layout
19902
19903 \end_inset
19904
19905
19906 \end_layout
19907
19908 \end_inset
19909 </cell>
19910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19911 \begin_inset Text
19912
19913 \begin_layout Standard
19914 -
19915 \end_layout
19916
19917 \end_inset
19918 </cell>
19919 </row>
19920 <row topline="true">
19921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19922 \begin_inset Text
19923
19924 \begin_layout Standard
19925 float formats %e %g
19926 \end_layout
19927
19928 \end_inset
19929 </cell>
19930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19931 \begin_inset Text
19932
19933 \begin_layout Standard
19934 -
19935 \end_layout
19936
19937 \end_inset
19938 </cell>
19939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19940 \begin_inset Text
19941
19942 \begin_layout Standard
19943 -
19944 \end_layout
19945
19946 \end_inset
19947 </cell>
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19949 \begin_inset Text
19950
19951 \begin_layout Standard
19952 -
19953 \end_layout
19954
19955 \end_inset
19956 </cell>
19957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19958 \begin_inset Text
19959
19960 \begin_layout Standard
19961 -
19962 \end_layout
19963
19964 \end_inset
19965 </cell>
19966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19967 \begin_inset Text
19968
19969 \begin_layout Standard
19970 -
19971 \end_layout
19972
19973 \end_inset
19974 </cell>
19975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19976 \begin_inset Text
19977
19978 \begin_layout Standard
19979 -
19980 \end_layout
19981
19982 \end_inset
19983 </cell>
19984 </row>
19985 <row topline="true" bottomline="true">
19986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19987 \begin_inset Text
19988
19989 \begin_layout Standard
19990 field width
19991 \end_layout
19992
19993 \end_inset
19994 </cell>
19995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19996 \begin_inset Text
19997
19998 \begin_layout Standard
19999 x
20000 \end_layout
20001
20002 \end_inset
20003 </cell>
20004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20005 \begin_inset Text
20006
20007 \begin_layout Standard
20008 x
20009 \end_layout
20010
20011 \end_inset
20012 </cell>
20013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20014 \begin_inset Text
20015
20016 \begin_layout Standard
20017 -
20018 \end_layout
20019
20020 \end_inset
20021 </cell>
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20023 \begin_inset Text
20024
20025 \begin_layout Standard
20026 x
20027 \end_layout
20028
20029 \end_inset
20030 </cell>
20031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20032 \begin_inset Text
20033
20034 \begin_layout Standard
20035 x
20036 \end_layout
20037
20038 \end_inset
20039 </cell>
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20041 \begin_inset Text
20042
20043 \begin_layout Standard
20044 -
20045 \end_layout
20046
20047 \end_inset
20048 </cell>
20049 </row>
20050 <row bottomline="true">
20051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20052 \begin_inset Text
20053
20054 \begin_layout Standard
20055 string speed
20056 \begin_inset Foot
20057 status collapsed
20058
20059 \begin_layout Standard
20060 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20061 \backslash
20062 r', '
20063 \backslash
20064 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20065 \end_layout
20066
20067 \end_inset
20068
20069 ,
20070 \end_layout
20071
20072 \begin_layout Standard
20073 small / large
20074 \end_layout
20075
20076 \end_inset
20077 </cell>
20078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20079 \begin_inset Text
20080
20081 \begin_layout Standard
20082 1.52 / 2.59 ms
20083 \end_layout
20084
20085 \end_inset
20086 </cell>
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20088 \begin_inset Text
20089
20090 \begin_layout Standard
20091 1.53 / 2.62 ms
20092 \end_layout
20093
20094 \end_inset
20095 </cell>
20096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20097 \begin_inset Text
20098
20099 \begin_layout Standard
20100 0.92 / 0.93 ms
20101 \end_layout
20102
20103 \end_inset
20104 </cell>
20105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20106 \begin_inset Text
20107
20108 \begin_layout Standard
20109 0.45 / 0.45 ms
20110 \end_layout
20111
20112 \end_inset
20113 </cell>
20114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20115 \begin_inset Text
20116
20117 \begin_layout Standard
20118 0.46 / 0.46 ms
20119 \end_layout
20120
20121 \end_inset
20122 </cell>
20123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20124 \begin_inset Text
20125
20126 \begin_layout Standard
20127 0.45 / 0.45 ms
20128 \end_layout
20129
20130 \end_inset
20131 </cell>
20132 </row>
20133 <row bottomline="true">
20134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20135 \begin_inset Text
20136
20137 \begin_layout Standard
20138 int speed
20139 \begin_inset Foot
20140 status collapsed
20141
20142 \begin_layout Standard
20143 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20144  putchar()
20145 \end_layout
20146
20147 \end_inset
20148
20149 ,
20150 \end_layout
20151
20152 \begin_layout Standard
20153 small / large
20154 \end_layout
20155
20156 \end_inset
20157 </cell>
20158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20159 \begin_inset Text
20160
20161 \begin_layout Standard
20162 3.01 / 3.61 ms
20163 \end_layout
20164
20165 \end_inset
20166 </cell>
20167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20168 \begin_inset Text
20169
20170 \begin_layout Standard
20171 3.01 / 3.61 ms
20172 \end_layout
20173
20174 \end_inset
20175 </cell>
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20177 \begin_inset Text
20178
20179 \begin_layout Standard
20180 3.51 / 18.13 ms
20181 \end_layout
20182
20183 \end_inset
20184 </cell>
20185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20186 \begin_inset Text
20187
20188 \begin_layout Standard
20189 0.22 / 0.22 ms
20190 \end_layout
20191
20192 \end_inset
20193 </cell>
20194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20195 \begin_inset Text
20196
20197 \begin_layout Standard
20198 0.23 / 0.23 ms
20199 \end_layout
20200
20201 \end_inset
20202 </cell>
20203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20204 \begin_inset Text
20205
20206 \begin_layout Standard
20207 0.25 / 0.25 ms
20208 \begin_inset Foot
20209 status collapsed
20210
20211 \begin_layout Standard
20212 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20213 \end_layout
20214
20215 \end_inset
20216
20217
20218 \end_layout
20219
20220 \end_inset
20221 </cell>
20222 </row>
20223 <row bottomline="true">
20224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20225 \begin_inset Text
20226
20227 \begin_layout Standard
20228 long speed
20229 \begin_inset Foot
20230 status collapsed
20231
20232 \begin_layout Standard
20233 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20234  empty putchar()
20235 \end_layout
20236
20237 \end_inset
20238
20239 ,
20240 \end_layout
20241
20242 \begin_layout Standard
20243 small / large
20244 \end_layout
20245
20246 \end_inset
20247 </cell>
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20249 \begin_inset Text
20250
20251 \begin_layout Standard
20252 5.37 / 6.31 ms
20253 \end_layout
20254
20255 \end_inset
20256 </cell>
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20258 \begin_inset Text
20259
20260 \begin_layout Standard
20261 5.37 / 6.31 ms
20262 \end_layout
20263
20264 \end_inset
20265 </cell>
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20267 \begin_inset Text
20268
20269 \begin_layout Standard
20270 8.71 / 40.65 ms
20271 \end_layout
20272
20273 \end_inset
20274 </cell>
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20276 \begin_inset Text
20277
20278 \begin_layout Standard
20279 0.40 / 0.40 ms
20280 \end_layout
20281
20282 \end_inset
20283 </cell>
20284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20285 \begin_inset Text
20286
20287 \begin_layout Standard
20288 0.40 / 0.40 ms
20289 \end_layout
20290
20291 \end_inset
20292 </cell>
20293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20294 \begin_inset Text
20295
20296 \begin_layout Standard
20297 -
20298 \end_layout
20299
20300 \end_inset
20301 </cell>
20302 </row>
20303 <row bottomline="true">
20304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20305 \begin_inset Text
20306
20307 \begin_layout Standard
20308 float speed
20309 \begin_inset Foot
20310 status collapsed
20311
20312 \begin_layout Standard
20313 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20314  empty putchar()
20315 \end_layout
20316
20317 \end_inset
20318
20319 ,
20320 \end_layout
20321
20322 \begin_layout Standard
20323 small / large
20324 \end_layout
20325
20326 \end_inset
20327 </cell>
20328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20329 \begin_inset Text
20330
20331 \begin_layout Standard
20332 -
20333 \end_layout
20334
20335 \end_inset
20336 </cell>
20337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20338 \begin_inset Text
20339
20340 \begin_layout Standard
20341 7.49 / 22.47 ms
20342 \end_layout
20343
20344 \end_inset
20345 </cell>
20346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20347 \begin_inset Text
20348
20349 \begin_layout Standard
20350 -
20351 \end_layout
20352
20353 \end_inset
20354 </cell>
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20356 \begin_inset Text
20357
20358 \begin_layout Standard
20359 -
20360 \end_layout
20361
20362 \end_inset
20363 </cell>
20364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20365 \begin_inset Text
20366
20367 \begin_layout Standard
20368 1.04 / 1.04 ms
20369 \end_layout
20370
20371 \end_inset
20372 </cell>
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20374 \begin_inset Text
20375
20376 \begin_layout Standard
20377 -
20378 \end_layout
20379
20380 \end_inset
20381 </cell>
20382 </row>
20383 </lyxtabular>
20384
20385 \end_inset
20386
20387
20388 \end_layout
20389
20390 \begin_layout Subsubsection
20391 <malloc.h>
20392 \begin_inset LatexCommand \index{malloc.h}
20393
20394 \end_inset
20395
20396
20397 \end_layout
20398
20399 \begin_layout Standard
20400 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20401  using dynamic memory allocation
20402 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20403
20404 \end_inset
20405
20406  and a default heap
20407 \begin_inset LatexCommand \index{heap (malloc)}
20408
20409 \end_inset
20410
20411  space of 1024 bytes is provided for malloc to allocate memory from.
20412  If you need a different heap size you need to recompile _heap.c with the
20413  required size defined in HEAP_SIZE.
20414  It is recommended to make a copy of this file into your project directory
20415  and compile it there with:
20416 \end_layout
20417
20418 \begin_layout Verse
20419
20420 \family typewriter
20421 sdcc -c _heap.c -D HEAD_SIZE=2048
20422 \end_layout
20423
20424 \begin_layout Standard
20425 And then link it with:
20426 \end_layout
20427
20428 \begin_layout Verse
20429
20430 \family typewriter
20431 sdcc main.rel _heap.rel
20432 \end_layout
20433
20434 \begin_layout Subsection
20435 Math functions (sinf, powf, sqrtf etc.)
20436 \end_layout
20437
20438 \begin_layout Subsubsection
20439 <math.h>
20440 \end_layout
20441
20442 \begin_layout Standard
20443 See definitions in file <math.h>.
20444 \end_layout
20445
20446 \begin_layout Subsection
20447 Other libraries
20448 \end_layout
20449
20450 \begin_layout Standard
20451 Libraries
20452 \begin_inset LatexCommand \index{Libraries}
20453
20454 \end_inset
20455
20456  included in SDCC should have a license at least as liberal as the GNU Lesser
20457  General Public License
20458 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20459
20460 \end_inset
20461
20462  
20463 \emph on
20464 LGPL
20465 \emph default
20466 .
20467 \end_layout
20468
20469 \begin_layout Standard
20470 \begin_inset Note Note
20471 status collapsed
20472
20473 \begin_layout Standard
20474 license statements for the libraries are missing.
20475  sdcc/device/lib/ser_ir.c
20476 \end_layout
20477
20478 \begin_layout Standard
20479 or _decdptr f.e.
20480  come with a GPL (as opposed to LGPL) License - this will not be liberal
20481  enough for many embedded programmers.
20482 \end_layout
20483
20484 \end_inset
20485
20486
20487 \end_layout
20488
20489 \begin_layout Standard
20490 If you have ported some library or want to share experience about some code
20491  which f.e.
20492  falls into any of these categories Busses (I
20493 \begin_inset Formula $^{\textrm{2}}$
20494 \end_inset
20495
20496 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20497  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20498  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20499 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20500
20501 \end_inset
20502
20503 \InsetSpace ~
20504 would certainly like to hear about it.
20505 \end_layout
20506
20507 \begin_layout Standard
20508 Programmers coding for embedded systems are not especially famous for being
20509  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20510 e these references are very valuable.
20511  Let's help to create a climate where information is shared.
20512 \begin_inset VSpace bigskip
20513 \end_inset
20514
20515
20516 \end_layout
20517
20518 \begin_layout Section
20519 Memory Models
20520 \end_layout
20521
20522 \begin_layout Subsection
20523 MCS51 Memory Models
20524 \begin_inset LatexCommand \index{Memory model}
20525
20526 \end_inset
20527
20528
20529 \begin_inset LatexCommand \index{MCS51 memory model}
20530
20531 \end_inset
20532
20533
20534 \end_layout
20535
20536 \begin_layout Subsubsection
20537 Small, Medium and Large
20538 \end_layout
20539
20540 \begin_layout Standard
20541 SDCC allows three memory models for MCS51 code, 
20542 \shape slanted
20543 small, medium
20544 \shape default
20545  and 
20546 \shape slanted
20547 large
20548 \shape default
20549 .
20550  Modules compiled with different memory models should 
20551 \emph on
20552 never
20553 \emph default
20554  be combined together or the results would be unpredictable.
20555  The library routines supplied with the compiler are compiled as small,
20556  medium and large.
20557  The compiled library modules are contained in separate directories as small,
20558  medium and large so that you can link to the appropriate set.
20559 \end_layout
20560
20561 \begin_layout Standard
20562 When the medium or large model is used all variables declared without a
20563  storage class will be allocated into the external ram, this includes all
20564  parameters and local variables (for non-reentrant
20565 \begin_inset LatexCommand \index{reentrant}
20566
20567 \end_inset
20568
20569  functions).
20570  When the small model is used variables without storage class are allocated
20571  in the internal ram.
20572 \end_layout
20573
20574 \begin_layout Standard
20575 Judicious usage of the processor specific storage classes
20576 \begin_inset LatexCommand \index{Storage class}
20577
20578 \end_inset
20579
20580  and the 'reentrant' function type will yield much more efficient code,
20581  than using the large model.
20582  Several optimizations are disabled when the program is compiled using the
20583  large model, it is therefore recommended that the small model be used unless
20584  absolutely required.
20585 \end_layout
20586
20587 \begin_layout Subsubsection
20588 External Stack
20589 \begin_inset LatexCommand \label{sub:External-Stack}
20590
20591 \end_inset
20592
20593
20594 \begin_inset LatexCommand \index{stack}
20595
20596 \end_inset
20597
20598
20599 \begin_inset LatexCommand \index{External stack (mcs51)}
20600
20601 \end_inset
20602
20603
20604 \end_layout
20605
20606 \begin_layout Standard
20607 The external stack (-
20608 \begin_inset ERT
20609 status collapsed
20610
20611 \begin_layout Standard
20612
20613
20614 \backslash
20615 /
20616 \end_layout
20617
20618 \end_inset
20619
20620 -xstack option
20621 \begin_inset LatexCommand \index{-\/-xstack}
20622
20623 \end_inset
20624
20625 ) is located in pdata
20626 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20627
20628 \end_inset
20629
20630  memory (usually at the start of the external ram segment) and uses all
20631  unused space in pdata (max.
20632  256 bytes).
20633  When -
20634 \begin_inset ERT
20635 status collapsed
20636
20637 \begin_layout Standard
20638
20639
20640 \backslash
20641 /
20642 \end_layout
20643
20644 \end_inset
20645
20646 -xstack option is used to compile the program, the parameters and local
20647  variables
20648 \begin_inset LatexCommand \index{local variables}
20649
20650 \end_inset
20651
20652  of all reentrant functions are allocated in this area.
20653  This option is provided for programs with large stack space requirements.
20654  When used with the -
20655 \begin_inset ERT
20656 status collapsed
20657
20658 \begin_layout Standard
20659
20660
20661 \backslash
20662 /
20663 \end_layout
20664
20665 \end_inset
20666
20667 -stack-auto
20668 \begin_inset LatexCommand \index{-\/-stack-auto}
20669
20670 \end_inset
20671
20672  option, all parameters and local variables are allocated on the external
20673  stack (note: support libraries will need to be recompiled with the same
20674  options.
20675  There is a predefined target in the library makefile).
20676 \end_layout
20677
20678 \begin_layout Standard
20679 The compiler outputs the higher order address byte of the external ram segment
20680  into port P2
20681 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20682
20683 \end_inset
20684
20685  (see also section 
20686 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20687
20688 \end_inset
20689
20690 ), therefore when using the External Stack option, this port 
20691 \emph on
20692 may not
20693 \emph default
20694  be used by the application program.
20695 \end_layout
20696
20697 \begin_layout Subsection
20698 DS390 Memory Model
20699 \begin_inset LatexCommand \index{Memory model}
20700
20701 \end_inset
20702
20703
20704 \begin_inset LatexCommand \index{DS390 memory model}
20705
20706 \end_inset
20707
20708
20709 \end_layout
20710
20711 \begin_layout Standard
20712 The only model supported is Flat 24
20713 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20714
20715 \end_inset
20716
20717 .
20718  This generates code for the 24 bit contiguous addressing mode of the Dallas
20719  DS80C390 part.
20720  In this mode, up to four meg of external RAM or code space can be directly
20721  addressed.
20722  See the data sheets at www.dalsemi.com for further information on this part.
20723 \newline
20724
20725 \newline
20726 Note
20727  that the compiler does not generate any code to place the processor into
20728  24 bitmode (although 
20729 \emph on
20730 tinibios
20731 \emph default
20732  in the ds390 libraries will do that for you).
20733  If you don't use 
20734 \emph on
20735 tinibios
20736 \emph default
20737
20738 \begin_inset LatexCommand \index{Tinibios (DS390)}
20739
20740 \end_inset
20741
20742 , the boot loader or similar code must ensure that the processor is in 24
20743  bit contiguous addressing mode before calling the SDCC startup code.
20744 \newline
20745
20746 \newline
20747 Like
20748  the 
20749 \emph on
20750 -
20751 \begin_inset ERT
20752 status collapsed
20753
20754 \begin_layout Standard
20755
20756
20757 \backslash
20758 /
20759 \end_layout
20760
20761 \end_inset
20762
20763 -model-large
20764 \emph default
20765  option, variables will by default be placed into the XDATA segment.
20766  
20767 \newline
20768
20769 \newline
20770 Segments may be placed anywhere in the 4 meg address space using the usual
20771  -
20772 \begin_inset ERT
20773 status collapsed
20774
20775 \begin_layout Standard
20776
20777
20778 \backslash
20779 /
20780 \end_layout
20781
20782 \end_inset
20783
20784 -*-loc options.
20785  Note that if any segments are located above 64K, the -r flag must be passed
20786  to the linker to generate the proper segment relocations, and the Intel
20787  HEX output format must be used.
20788  The -r flag can be passed to the linker by using the option 
20789 \emph on
20790 -Wl-r
20791 \emph default
20792  on the SDCC command line.
20793  However, currently the linker can not handle code segments > 64k.
20794 \end_layout
20795
20796 \begin_layout Section
20797 Pragmas
20798 \begin_inset LatexCommand \label{sec:Pragmas}
20799
20800 \end_inset
20801
20802
20803 \begin_inset LatexCommand \index{Pragmas}
20804
20805 \end_inset
20806
20807
20808 \end_layout
20809
20810 \begin_layout Standard
20811 Pragmas are used to turn on and/or off certain compiler options.
20812  Some of them are closely related to corresponding command-line options
20813  (see section 
20814 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20815
20816 \end_inset
20817
20818 ).
20819 \newline
20820 Pragmas should be placed before and/or after a function, placing pragmas
20821  inside a function body could have unpredictable results.
20822 \newline
20823
20824 \newline
20825 SDCC supports the
20826  following #pragma directives:
20827 \end_layout
20828
20829 \begin_layout Itemize
20830
20831 \series bold
20832 save
20833 \series default
20834
20835 \begin_inset LatexCommand \index{\#pragma save}
20836
20837 \end_inset
20838
20839  - this will save most current options to the save/restore stack.
20840  See #pragma\InsetSpace ~
20841 restore.
20842 \end_layout
20843
20844 \begin_layout Itemize
20845
20846 \series bold
20847 restore
20848 \series default
20849
20850 \begin_inset LatexCommand \index{\#pragma restore}
20851
20852 \end_inset
20853
20854  - will restore saved options from the last save.
20855  saves & restores can be nested.
20856  SDCC uses a save/restore stack: save pushes current options to the stack,
20857  restore pulls current options from the stack.
20858  See #pragma\InsetSpace ~
20859 save.
20860 \newline
20861
20862 \end_layout
20863
20864 \begin_layout Itemize
20865
20866 \series bold
20867 callee_saves
20868 \series default
20869
20870 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20871
20872 \end_inset
20873
20874
20875 \begin_inset LatexCommand \index{function prologue}
20876
20877 \end_inset
20878
20879  function1[,function2[,function3...]] 
20880 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20881
20882 \end_inset
20883
20884 - The compiler by default uses a caller saves convention for register saving
20885  across function calls, however this can cause unnecessary register pushing
20886  and popping
20887 \begin_inset LatexCommand \index{push/pop}
20888
20889 \end_inset
20890
20891  when calling small functions from larger functions.
20892  This option can be used to switch off the register saving convention for
20893  the function names specified.
20894  The compiler will not save registers when calling these functions, extra
20895  code need to be manually inserted at the entry and exit for these functions
20896  to save and restore the registers used by these functions, this can SUBSTANTIAL
20897 LY reduce code and improve run time performance of the generated code.
20898  In the future the compiler (with inter procedural analysis) may be able
20899  to determine the appropriate scheme to use for each function call.
20900  If -
20901 \begin_inset ERT
20902 status collapsed
20903
20904 \begin_layout Standard
20905
20906
20907 \backslash
20908 /
20909 \end_layout
20910
20911 \end_inset
20912
20913 -callee-saves command line option is used (see page 
20914 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20915
20916 \end_inset
20917
20918 ), the function names specified in #pragma\InsetSpace ~
20919 callee_saves
20920 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20921
20922 \end_inset
20923
20924  is appended to the list of functions specified in the command line.
20925 \end_layout
20926
20927 \begin_layout Itemize
20928
20929 \series bold
20930 exclude
20931 \series default
20932
20933 \begin_inset LatexCommand \index{\#pragma exclude}
20934
20935 \end_inset
20936
20937  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20938  of pairs of push/pop
20939 \begin_inset LatexCommand \index{push/pop}
20940
20941 \end_inset
20942
20943  instructions in 
20944 \emph on
20945 I
20946 \emph default
20947 nterrupt
20948 \begin_inset LatexCommand \index{interrupt}
20949
20950 \end_inset
20951
20952  
20953 \emph on
20954 S
20955 \emph default
20956 ervice 
20957 \emph on
20958 R
20959 \emph default
20960 outines.
20961  The directive should be placed immediately before the ISR function definition
20962  and it affects ALL ISR functions following it.
20963  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20964 exclude\InsetSpace ~
20965 none
20966 \begin_inset LatexCommand \index{\#pragma exclude}
20967
20968 \end_inset
20969
20970 .
20971  See also the related keyword _naked
20972 \begin_inset LatexCommand \index{\_naked}
20973
20974 \end_inset
20975
20976
20977 \begin_inset LatexCommand \index{\_\_naked}
20978
20979 \end_inset
20980
20981 .
20982 \end_layout
20983
20984 \begin_layout Itemize
20985
20986 \series bold
20987 less_pedantic
20988 \series default
20989
20990 \begin_inset LatexCommand \index{pedantic}
20991
20992 \end_inset
20993
20994
20995 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
20996
20997 \end_inset
20998
20999  
21000 \begin_inset LatexCommand \label{ite:less_pedantic}
21001
21002 \end_inset
21003
21004 - the compiler will not warn you anymore for obvious mistakes, you'r on
21005  your own now ;-( .
21006  See also the command line option -
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 -less-pedantic 
21020 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21021
21022 \end_inset
21023
21024 .
21025  
21026 \newline
21027 More specifically, the following warnings will be disabled: 
21028 \shape italic
21029 comparison is always [true/false] due to limited range of data type
21030 \shape default
21031  (94); 
21032 \shape italic
21033 overflow in implicit constant conversion
21034 \shape default
21035  (158); [the (in)famous] 
21036 \shape italic
21037 conditional flow changed by optimizer: so said EVELYN the modified DOG
21038 \shape default
21039  (110); 
21040 \shape italic
21041 function '[function name]' must return value
21042 \shape default
21043  (59).
21044  
21045 \newline
21046 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21047  level) are disabled, too, namely: 
21048 \shape italic
21049 constant value '[
21050 \begin_inset Note Note
21051 status collapsed
21052
21053 \begin_layout Standard
21054 dunno what comes here - this warning appears to be unused altogether
21055 \end_layout
21056
21057 \end_inset
21058
21059 ]', out of range
21060 \shape default
21061  (81); 
21062 \shape italic
21063 [left/right] shifting more than size of object changed to zero
21064 \shape default
21065  (116); 
21066 \shape italic
21067 unreachable code
21068 \shape default
21069  (126); 
21070 \shape italic
21071 integer overflow in expression
21072 \shape default
21073  (165); 
21074 \shape italic
21075 unmatched #pragma save and #pragma restore
21076 \shape default
21077  (170); 
21078 \shape italic
21079 comparison of 'signed char' with 'unsigned char' requires promotion to int
21080 \shape default
21081  (185); 
21082 \shape italic
21083 ISO C90 does not support flexible array members
21084 \shape default
21085  (187); 
21086 \shape italic
21087 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21088 nam
21089 e]':\InsetSpace ~
21090 [
21091 \begin_inset Note Note
21092 status collapsed
21093
21094 \begin_layout Standard
21095 appears to be always blank - what was supposed to be here?
21096 \end_layout
21097
21098 \end_inset
21099
21100 ]
21101 \shape default
21102  (114); 
21103 \shape italic
21104 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21105  complexity [number]
21106 \shape default
21107  (121).
21108 \end_layout
21109
21110 \begin_layout Itemize
21111
21112 \series bold
21113 disable_warning
21114 \series default
21115  <nnnn>
21116 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21117
21118 \end_inset
21119
21120  - the compiler will not warn you anymore about warning number <nnnn>.
21121  
21122 \begin_inset Note Note
21123 status open
21124
21125 \begin_layout Itemize
21126 \begin_inset Quotes sld
21127 \end_inset
21128
21129 For list of warnings and corresponding codes, see err_warn.txt
21130 \begin_inset Quotes srd
21131 \end_inset
21132
21133  This list should probably be part of the manual? See Patch #1697136 
21134 \end_layout
21135
21136 \end_inset
21137
21138 .
21139 \end_layout
21140
21141 \begin_layout Itemize
21142
21143 \series bold
21144 nogcse
21145 \series default
21146
21147 \begin_inset LatexCommand \index{\#pragma nogcse}
21148
21149 \end_inset
21150
21151  - will stop global common subexpression elimination.
21152 \end_layout
21153
21154 \begin_layout Itemize
21155
21156 \series bold
21157 noinduction
21158 \series default
21159
21160 \begin_inset LatexCommand \index{\#pragma noinduction}
21161
21162 \end_inset
21163
21164  - will stop loop induction optimizations.
21165 \end_layout
21166
21167 \begin_layout Itemize
21168
21169 \series bold
21170 noinvariant
21171 \series default
21172
21173 \begin_inset LatexCommand \index{\#pragma noinvariant}
21174
21175 \end_inset
21176
21177  - will not do loop invariant optimizations.
21178  For more details see Loop Invariants in section
21179 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21180
21181 \end_inset
21182
21183 .
21184 \end_layout
21185
21186 \begin_layout Itemize
21187
21188 \series bold
21189 noiv
21190 \series default
21191
21192 \begin_inset LatexCommand \index{\#pragma noiv}
21193
21194 \end_inset
21195
21196  - Do not generate interrupt
21197 \begin_inset LatexCommand \index{interrupt}
21198
21199 \end_inset
21200
21201  vector table
21202 \begin_inset LatexCommand \index{interrupt vector table}
21203
21204 \end_inset
21205
21206  entries for all ISR functions defined after the pragma.
21207  This is useful in cases where the interrupt vector table must be defined
21208  manually, or when there is a secondary, manually defined interrupt vector
21209  table (e.g.
21210  for the autovector feature of the Cypress EZ-USB FX2).
21211  More elegantly this can be achieved by obmitting the optional interrupt
21212  number after the interrupt keyword, see section 
21213 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21214
21215 \end_inset
21216
21217 \InsetSpace ~
21218 about interrupts.
21219 \end_layout
21220
21221 \begin_layout Itemize
21222
21223 \series bold
21224 nojtbound
21225 \series default
21226
21227 \begin_inset LatexCommand \index{\#pragma nojtbound}
21228
21229 \end_inset
21230
21231  - will not generate code for boundary value checking, when switch statements
21232  are turned into jump-tables (dangerous).
21233  For more details see section 
21234 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21235
21236 \end_inset
21237
21238 .
21239 \end_layout
21240
21241 \begin_layout Itemize
21242
21243 \series bold
21244 noloopreverse
21245 \series default
21246
21247 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21248
21249 \end_inset
21250
21251  - Will not do loop reversal optimization
21252 \end_layout
21253
21254 \begin_layout Itemize
21255
21256 \series bold
21257 nooverlay
21258 \series default
21259
21260 \begin_inset LatexCommand \index{\#pragma nooverlay}
21261
21262 \end_inset
21263
21264  - the compiler will not overlay the parameters and local variables of a
21265  function.
21266 \end_layout
21267
21268 \begin_layout Itemize
21269
21270 \series bold
21271 stackauto
21272 \series default
21273
21274 \begin_inset LatexCommand \index{\#pragma stackauto}
21275
21276 \end_inset
21277
21278 - See option -
21279 \begin_inset ERT
21280 status collapsed
21281
21282 \begin_layout Standard
21283
21284
21285 \backslash
21286 /
21287 \end_layout
21288
21289 \end_inset
21290
21291 -stack-auto
21292 \begin_inset LatexCommand \index{-\/-stack-auto}
21293
21294 \end_inset
21295
21296  and section 
21297 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21298
21299 \end_inset
21300
21301  Parameters and Local Variables.
21302 \end_layout
21303
21304 \begin_layout Itemize
21305
21306 \series bold
21307 opt_code_speed
21308 \series default
21309  
21310 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21311
21312 \end_inset
21313
21314 - The compiler will optimize code generation towards fast code, possibly
21315  at the expense of code size.
21316  Currently this has little effect.
21317 \end_layout
21318
21319 \begin_layout Itemize
21320
21321 \series bold
21322 opt_code_size
21323 \series default
21324  
21325 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21326
21327 \end_inset
21328
21329 - The compiler will optimize code generation towards compact code, possibly
21330  at the expense of code speed.
21331  Currently this has little effect.
21332 \end_layout
21333
21334 \begin_layout Itemize
21335
21336 \series bold
21337 opt_code_balanced
21338 \series default
21339  
21340 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21341
21342 \end_inset
21343
21344 - The compiler will attempt to generate code that is both compact and fast,
21345  as long as meeting one goal is not a detriment to the other (this is the
21346  default).
21347  
21348 \end_layout
21349
21350 \begin_layout Itemize
21351
21352 \series bold
21353 std_sdcc89
21354 \series default
21355  
21356 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21357
21358 \end_inset
21359
21360 - Generally follow the C89 standard, but allow SDCC features that conflict
21361  with the standard (default).
21362 \end_layout
21363
21364 \begin_layout Itemize
21365
21366 \series bold
21367 std_c89
21368 \series default
21369  
21370 \begin_inset LatexCommand \index{\#pragma std\_c89}
21371
21372 \end_inset
21373
21374 - Follow the C89 standard and disable SDCC features that conflict with the
21375  standard.
21376 \end_layout
21377
21378 \begin_layout Itemize
21379
21380 \series bold
21381 std_sdcc99
21382 \series default
21383  
21384 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21385
21386 \end_inset
21387
21388 - Generally follow the C99 standard, but allow SDCC features that conflict
21389  with the standard (incomplete support).
21390 \end_layout
21391
21392 \begin_layout Itemize
21393
21394 \series bold
21395 std_c99
21396 \series default
21397  
21398 \begin_inset LatexCommand \index{\#pragma std\_c99}
21399
21400 \end_inset
21401
21402 - Follow the C99 standard and disable SDCC features that conflict with the
21403  standard (incomplete support).
21404 \end_layout
21405
21406 \begin_layout Itemize
21407
21408 \series bold
21409 codeseg
21410 \series default
21411  <name>
21412 \begin_inset LatexCommand \index{\#pragma codeseg}
21413
21414 \end_inset
21415
21416 - Use this name (max.
21417  8 characters) for the code segment.
21418  See option -
21419 \begin_inset ERT
21420 status collapsed
21421
21422 \begin_layout Standard
21423
21424
21425 \backslash
21426 /
21427 \end_layout
21428
21429 \end_inset
21430
21431 -codeseg.
21432 \end_layout
21433
21434 \begin_layout Itemize
21435
21436 \series bold
21437 constseg
21438 \series default
21439  <name>
21440 \begin_inset LatexCommand \index{\#pragma constseg}
21441
21442 \end_inset
21443
21444 - Use this name (max.
21445  8 characters) for the const segment.
21446  See option -
21447 \begin_inset ERT
21448 status collapsed
21449
21450 \begin_layout Standard
21451
21452
21453 \backslash
21454 /
21455 \end_layout
21456
21457 \end_inset
21458
21459 -constseg.
21460 \end_layout
21461
21462 \begin_layout Standard
21463 The preprocessor SDCPP
21464 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21465
21466 \end_inset
21467
21468  supports the following #pragma directives:
21469 \end_layout
21470
21471 \begin_layout Itemize
21472
21473 \series bold
21474 pedantic_parse_number
21475 \series default
21476
21477 \begin_inset LatexCommand \index{pedantic}
21478
21479 \end_inset
21480
21481
21482 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21483
21484 \end_inset
21485
21486  (+ | -) 
21487 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21488
21489 \end_inset
21490
21491 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21492  properly and the macro LO_B(3) gets expanded.
21493  Default is off.
21494  See also the -
21495 \begin_inset ERT
21496 status collapsed
21497
21498 \begin_layout Standard
21499
21500
21501 \backslash
21502 /
21503 \end_layout
21504
21505 \end_inset
21506
21507 -pedantic-parse-number command line option 
21508 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21509
21510 \end_inset
21511
21512 .
21513  
21514 \newline
21515 Below is an example on how to use this pragma.
21516
21517 \emph on
21518  Note: this functionality is not in conformance with standard!
21519 \end_layout
21520
21521 \begin_layout Verse
21522
21523 \family typewriter
21524 #pragma pedantic_parse_number +
21525 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21526
21527 \end_inset
21528
21529
21530 \newline
21531
21532 \newline
21533 #define LO_B(x) ((x) & 0xff)
21534 \newline
21535
21536 \newline
21537 unsigned char foo(void)
21538 \newline
21539 {
21540 \newline
21541 \InsetSpace ~
21542 \InsetSpace ~
21543 \InsetSpace ~
21544 unsigned char c=0xfe-LO_B(3)
21545 ;
21546 \newline
21547
21548 \newline
21549 \InsetSpace ~
21550 \InsetSpace ~
21551 \InsetSpace ~
21552 return c;
21553 \newline
21554 }
21555 \newline
21556
21557 \end_layout
21558
21559 \begin_layout Itemize
21560
21561 \series bold
21562 preproc_asm
21563 \series default
21564
21565 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21566
21567 \end_inset
21568
21569  (+ | -) - switch _asm _endasm block preprocessing on / off.
21570  Default is on.
21571  You use this prama to define multilines of assembly code.
21572  This will prevent the preprocessor from changing the formating required
21573  by assembly code.
21574  Below is an example on how to use this pragma.
21575 \end_layout
21576
21577 \begin_layout Verse
21578
21579 \family typewriter
21580 #pragma preproc_asm -
21581 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21582
21583 \end_inset
21584
21585
21586 \newline
21587 #define MYDELAY _asm
21588 \newline
21589 \InsetSpace ~
21590 \InsetSpace ~
21591 \InsetSpace ~
21592 nop ;my assembly comment...
21593 \newline
21594 \InsetSpace ~
21595 \InsetSpace ~
21596 \InsetSpace ~
21597 nop
21598 \newline
21599 \InsetSpace ~
21600 \InsetSpace ~
21601 \InsetSpace ~
21602 nop
21603 \newline
21604 _endasm
21605 \newline
21606 #pragma preproc_asm
21607  +
21608 \newline
21609
21610 \newline
21611 void foo (void) 
21612 \newline
21613
21614 \newline
21615 \InsetSpace ~
21616 \InsetSpace ~
21617 \InsetSpace ~
21618  ...
21619  
21620 \newline
21621 \InsetSpace ~
21622 \InsetSpace ~
21623 \InsetSpace ~
21624  MYDELAY;
21625 \newline
21626 \InsetSpace ~
21627 \InsetSpace ~
21628 \InsetSpace ~
21629  ...
21630  
21631 \newline
21632
21633 \newline
21634
21635 \end_layout
21636
21637 \begin_layout Itemize
21638
21639 \series bold
21640 sdcc_hash
21641 \series default
21642
21643 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21644
21645 \end_inset
21646
21647  (+ | -) - Allow "naked" hash in macro definition, for example:
21648 \newline
21649
21650 \family typewriter
21651 #define DIR_LO(x) #(x & 0xff)
21652 \family default
21653
21654 \newline
21655 Default is off.
21656  Below is an example on how to use this pragma.
21657 \end_layout
21658
21659 \begin_layout Verse
21660
21661 \family typewriter
21662 #pragma preproc_asm +
21663 \newline
21664 #pragma sdcc_hash +
21665 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21666
21667 \end_inset
21668
21669
21670 \newline
21671
21672 \newline
21673 #define ROMCALL(x) 
21674 \backslash
21675
21676 \newline
21677 \InsetSpace ~
21678 \InsetSpace ~
21679 \InsetSpace ~
21680 mov R6_B3, #(x & 0xff) 
21681 \backslash
21682
21683 \newline
21684 \InsetSpace ~
21685 \InsetSpace ~
21686 \InsetSpace ~
21687 mov R7_B3, #((x >> 8) & 0xff) 
21688 \backslash
21689
21690 \newline
21691 \InsetSpace ~
21692 \InsetSpace ~
21693 \InsetSpace ~
21694 lcall __romcall
21695 \newline
21696
21697 \newline
21698 ...
21699 \newline
21700 _asm
21701 \newline
21702 ROMCALL(72)
21703 \newline
21704 _endasm;
21705 \newline
21706 ...
21707 \newline
21708
21709 \end_layout
21710
21711 \begin_layout Standard
21712 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21713 ons which might cause the compiler to generate extra stack and/or data space
21714  to store compiler generated temporary variables.
21715  This usually happens in large functions.
21716  Pragma directives should be used as shown in the following example, they
21717  are used to control options and optimizations for a given function.
21718  
21719 \end_layout
21720
21721 \begin_layout Verse
21722
21723 \family typewriter
21724 #pragma save
21725 \begin_inset LatexCommand \index{\#pragma save}
21726
21727 \end_inset
21728
21729  \InsetSpace ~
21730 \InsetSpace ~
21731 \InsetSpace ~
21732 \InsetSpace ~
21733 \InsetSpace ~
21734 \InsetSpace ~
21735 \InsetSpace ~
21736 /* save the current settings */ 
21737 \newline
21738 #pragma nogcse
21739 \begin_inset LatexCommand \index{\#pragma nogcse}
21740
21741 \end_inset
21742
21743  \InsetSpace ~
21744 \InsetSpace ~
21745 \InsetSpace ~
21746 \InsetSpace ~
21747 \InsetSpace ~
21748 /* turnoff global subexpression elimination */ 
21749 \newline
21750 #pragma noinduction
21751 \begin_inset LatexCommand \index{\#pragma noinduction}
21752
21753 \end_inset
21754
21755  /* turn off induction optimizations */ 
21756 \newline
21757 int foo () 
21758 \newline
21759
21760 \newline
21761 \InsetSpace ~
21762  \InsetSpace ~
21763  ...
21764  
21765 \newline
21766 \InsetSpace ~
21767  \InsetSpace ~
21768  /* large code */ 
21769 \newline
21770 \InsetSpace ~
21771  \InsetSpace ~
21772  ...
21773  
21774 \newline
21775
21776 \newline
21777 #pragma restore
21778 \begin_inset LatexCommand \index{\#pragma restore}
21779
21780 \end_inset
21781
21782  /* turn the optimizations back on */
21783 \end_layout
21784
21785 \begin_layout Standard
21786 The compiler will generate a warning message when extra space is allocated.
21787  It is strongly recommended that the save and restore pragma's be used when
21788  changing options for a function.
21789 \newline
21790
21791 \newline
21792
21793 \newline
21794
21795 \end_layout
21796
21797 \begin_layout Section
21798 Defines Created by the Compiler
21799 \end_layout
21800
21801 \begin_layout Standard
21802 The compiler creates the following #defines
21803 \begin_inset LatexCommand \index{\#defines}
21804
21805 \end_inset
21806
21807
21808 \begin_inset LatexCommand \index{Defines created by the compiler}
21809
21810 \end_inset
21811
21812 :
21813 \newline
21814
21815 \end_layout
21816
21817 \begin_layout Standard
21818 \begin_inset Tabular
21819 <lyxtabular version="3" rows="11" columns="2">
21820 <features>
21821 <column alignment="left" valignment="top" leftline="true" width="3in">
21822 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21823 <row topline="true" bottomline="true">
21824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21825 \begin_inset Text
21826
21827 \begin_layout Standard
21828
21829 \series bold
21830 #define
21831 \end_layout
21832
21833 \end_inset
21834 </cell>
21835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21836 \begin_inset Text
21837
21838 \begin_layout Standard
21839
21840 \series bold
21841 Description
21842 \end_layout
21843
21844 \end_inset
21845 </cell>
21846 </row>
21847 <row topline="true">
21848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21849 \begin_inset Text
21850
21851 \begin_layout Standard
21852 SDCC
21853 \begin_inset LatexCommand \index{SDCC}
21854
21855 \end_inset
21856
21857  
21858 \end_layout
21859
21860 \end_inset
21861 </cell>
21862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21863 \begin_inset Text
21864
21865 \begin_layout Standard
21866 Always defined.
21867  Since version 2.5.6 the version number as an int (ex.
21868  256)
21869 \end_layout
21870
21871 \end_inset
21872 </cell>
21873 </row>
21874 <row topline="true">
21875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21876 \begin_inset Text
21877
21878 \begin_layout Standard
21879 SDCC_mcs51
21880 \begin_inset LatexCommand \index{SDCC\_mcs51}
21881
21882 \end_inset
21883
21884  or SDCC_ds390
21885 \begin_inset LatexCommand \index{SDCC\_ds390}
21886
21887 \end_inset
21888
21889  or SDCC_z80
21890 \begin_inset LatexCommand \index{SDCC\_z80}
21891
21892 \end_inset
21893
21894 , etc.
21895 \end_layout
21896
21897 \end_inset
21898 </cell>
21899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21900 \begin_inset Text
21901
21902 \begin_layout Standard
21903 depending on the model used (e.g.: -mds390)
21904 \end_layout
21905
21906 \end_inset
21907 </cell>
21908 </row>
21909 <row topline="true">
21910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21911 \begin_inset Text
21912
21913 \begin_layout Standard
21914 __mcs51
21915 \begin_inset LatexCommand \index{\_\_mcs51}
21916
21917 \end_inset
21918
21919 , __ds390
21920 \begin_inset LatexCommand \index{\_\_ds390}
21921
21922 \end_inset
21923
21924 , __hc08
21925 \begin_inset LatexCommand \index{\_\_hc08}
21926
21927 \end_inset
21928
21929 , __z80
21930 \begin_inset LatexCommand \index{\_\_z80}
21931
21932 \end_inset
21933
21934 , etc
21935 \end_layout
21936
21937 \end_inset
21938 </cell>
21939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21940 \begin_inset Text
21941
21942 \begin_layout Standard
21943 depending on the model used (e.g.
21944  -mz80)
21945 \end_layout
21946
21947 \end_inset
21948 </cell>
21949 </row>
21950 <row topline="true">
21951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21952 \begin_inset Text
21953
21954 \begin_layout Standard
21955 SDCC_STACK_AUTO
21956 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21957
21958 \end_inset
21959
21960
21961 \end_layout
21962
21963 \end_inset
21964 </cell>
21965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21966 \begin_inset Text
21967
21968 \begin_layout Standard
21969 when 
21970 \emph on
21971 -
21972 \begin_inset ERT
21973 status collapsed
21974
21975 \begin_layout Standard
21976
21977
21978 \backslash
21979 /
21980 \end_layout
21981
21982 \end_inset
21983
21984 -stack-auto
21985 \emph default
21986  option is used
21987 \end_layout
21988
21989 \end_inset
21990 </cell>
21991 </row>
21992 <row topline="true">
21993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21994 \begin_inset Text
21995
21996 \begin_layout Standard
21997 SDCC_MODEL_SMALL
21998 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
21999
22000 \end_inset
22001
22002
22003 \end_layout
22004
22005 \end_inset
22006 </cell>
22007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22008 \begin_inset Text
22009
22010 \begin_layout Standard
22011 when 
22012 \emph on
22013 -
22014 \begin_inset ERT
22015 status collapsed
22016
22017 \begin_layout Standard
22018
22019
22020 \backslash
22021 /
22022 \end_layout
22023
22024 \end_inset
22025
22026 -model-small
22027 \emph default
22028  is used
22029 \end_layout
22030
22031 \end_inset
22032 </cell>
22033 </row>
22034 <row topline="true">
22035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22036 \begin_inset Text
22037
22038 \begin_layout Standard
22039 SDCC_MODEL_MEDIUM
22040 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22041
22042 \end_inset
22043
22044
22045 \end_layout
22046
22047 \end_inset
22048 </cell>
22049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22050 \begin_inset Text
22051
22052 \begin_layout Standard
22053 when 
22054 \emph on
22055 -
22056 \begin_inset ERT
22057 status collapsed
22058
22059 \begin_layout Standard
22060
22061
22062 \backslash
22063 /
22064 \end_layout
22065
22066 \end_inset
22067
22068 -model-medium
22069 \emph default
22070  is used
22071 \end_layout
22072
22073 \end_inset
22074 </cell>
22075 </row>
22076 <row topline="true">
22077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22078 \begin_inset Text
22079
22080 \begin_layout Standard
22081 SDCC_MODEL_LARGE
22082 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22083
22084 \end_inset
22085
22086
22087 \end_layout
22088
22089 \end_inset
22090 </cell>
22091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22092 \begin_inset Text
22093
22094 \begin_layout Standard
22095 when 
22096 \emph on
22097 -
22098 \begin_inset ERT
22099 status collapsed
22100
22101 \begin_layout Standard
22102
22103
22104 \backslash
22105 /
22106 \end_layout
22107
22108 \end_inset
22109
22110 -model-large
22111 \emph default
22112  is used
22113 \end_layout
22114
22115 \end_inset
22116 </cell>
22117 </row>
22118 <row topline="true">
22119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22120 \begin_inset Text
22121
22122 \begin_layout Standard
22123 SDCC_USE_XSTACK
22124 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22125
22126 \end_inset
22127
22128
22129 \end_layout
22130
22131 \end_inset
22132 </cell>
22133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22134 \begin_inset Text
22135
22136 \begin_layout Standard
22137 when 
22138 \emph on
22139 -
22140 \begin_inset ERT
22141 status collapsed
22142
22143 \begin_layout Standard
22144
22145
22146 \backslash
22147 /
22148 \end_layout
22149
22150 \end_inset
22151
22152 -xstack
22153 \emph default
22154  option is used
22155 \end_layout
22156
22157 \end_inset
22158 </cell>
22159 </row>
22160 <row topline="true">
22161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22162 \begin_inset Text
22163
22164 \begin_layout Standard
22165 SDCC_STACK_TENBIT
22166 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22167
22168 \end_inset
22169
22170  
22171 \end_layout
22172
22173 \end_inset
22174 </cell>
22175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22176 \begin_inset Text
22177
22178 \begin_layout Standard
22179 when 
22180 \emph on
22181 -mds390
22182 \emph default
22183  is used
22184 \end_layout
22185
22186 \end_inset
22187 </cell>
22188 </row>
22189 <row topline="true" bottomline="true">
22190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22191 \begin_inset Text
22192
22193 \begin_layout Standard
22194 SDCC_MODEL_FLAT24
22195 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22196
22197 \end_inset
22198
22199
22200 \end_layout
22201
22202 \end_inset
22203 </cell>
22204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22205 \begin_inset Text
22206
22207 \begin_layout Standard
22208 when 
22209 \emph on
22210 -mds390
22211 \emph default
22212  is used
22213 \end_layout
22214
22215 \end_inset
22216 </cell>
22217 </row>
22218 </lyxtabular>
22219
22220 \end_inset
22221
22222
22223 \end_layout
22224
22225 \begin_layout Chapter
22226 Notes on supported Processors
22227 \end_layout
22228
22229 \begin_layout Section
22230 MCS51 variants
22231 \begin_inset LatexCommand \label{sub:MCS51-variants}
22232
22233 \end_inset
22234
22235
22236 \begin_inset LatexCommand \index{MCS51 variants}
22237
22238 \end_inset
22239
22240
22241 \end_layout
22242
22243 \begin_layout Standard
22244 MCS51 processors are available from many vendors and come in many different
22245  flavours.
22246  While they might differ considerably in respect to Special Function Registers
22247  the core MCS51 is usually not modified or is kept compatible.
22248  
22249 \end_layout
22250
22251 \begin_layout Subsection
22252 pdata access by SFR 
22253 \end_layout
22254
22255 \begin_layout Standard
22256 With the upcome of devices with internal xdata and flash memory devices
22257  using port P2
22258 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22259
22260 \end_inset
22261
22262  as dedicated I/O port is becoming more popular.
22263  Switching the high byte for pdata
22264 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22265
22266 \end_inset
22267
22268  access which was formerly done by port P2 is then achieved by a Special
22269  Function Register
22270 \begin_inset LatexCommand \index{sfr}
22271
22272 \end_inset
22273
22274 .
22275  In well-established MCS51 tradition the address of this 
22276 \emph on
22277 sfr
22278 \emph default
22279  is where the chip designers decided to put it.
22280  Needless to say that they didn't agree on a common name either.
22281  So that the startup code can correctly initialize xdata variables, you
22282  should define an sfr with the name _XPAGE
22283 \family typewriter
22284
22285 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22286
22287 \end_inset
22288
22289
22290 \family default
22291  at the appropriate location if the default, port P2, is not used for this.
22292  Some examples are:
22293 \end_layout
22294
22295 \begin_layout Verse
22296
22297 \family typewriter
22298 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22299  MPAGE */
22300 \end_layout
22301
22302 \begin_layout Verse
22303
22304 \family typewriter
22305 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22306  a.k.a.
22307  MPAGE */
22308 \end_layout
22309
22310 \begin_layout Verse
22311
22312 \family typewriter
22313 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22314  XPAGE */
22315 \end_layout
22316
22317 \begin_layout Verse
22318
22319 \family typewriter
22320 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22321  EMI0CN */
22322 \end_layout
22323
22324 \begin_layout Verse
22325
22326 \family typewriter
22327 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22328  EMI0CN */
22329 \end_layout
22330
22331 \begin_layout Standard
22332 For more exotic implementations further customizations may be needed.
22333  See section 
22334 \begin_inset LatexCommand \ref{sub:Startup-Code}
22335
22336 \end_inset
22337
22338  for other possibilities.
22339 \end_layout
22340
22341 \begin_layout Subsection
22342 Other Features available by SFR
22343 \end_layout
22344
22345 \begin_layout Standard
22346 Some MCS51 variants offer features like Double DPTR
22347 \begin_inset LatexCommand \index{DPTR}
22348
22349 \end_inset
22350
22351 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22352  These are currently not used for the MCS51 port.
22353  If you absolutely need them you can fall back to inline assembly or submit
22354  a patch to SDCC.
22355 \begin_inset VSpace bigskip
22356 \end_inset
22357
22358
22359 \end_layout
22360
22361 \begin_layout Section
22362 DS400 port
22363 \end_layout
22364
22365 \begin_layout Standard
22366 The DS80C400
22367 \begin_inset LatexCommand \index{DS80C400}
22368
22369 \end_inset
22370
22371
22372 \begin_inset LatexCommand \index{DS400}
22373
22374 \end_inset
22375
22376  microcontroller has a rich set of peripherals.
22377  In its built-in ROM library it includes functions to access some of the
22378  features, among them is a TCP stack with IP4 and IP6 support.
22379  Library headers (currently in beta status) and other files are provided
22380  at 
22381 \size footnotesize
22382
22383 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22384
22385 \end_inset
22386
22387 .
22388  
22389 \begin_inset VSpace bigskip
22390 \end_inset
22391
22392
22393 \end_layout
22394
22395 \begin_layout Section
22396 The Z80 and gbz80 port
22397 \end_layout
22398
22399 \begin_layout Standard
22400 SDCC can target both the Zilog Z80
22401 \begin_inset LatexCommand \index{Z80}
22402
22403 \end_inset
22404
22405  and the Nintendo Gameboy's Z80-like gbz80
22406 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22407
22408 \end_inset
22409
22410 .
22411  The Z80 port is passed through the same 
22412 \emph on
22413 regressions tests
22414 \begin_inset LatexCommand \index{Regression test}
22415
22416 \end_inset
22417
22418
22419 \emph default
22420  (see section 
22421 \begin_inset LatexCommand \ref{sec:Quality-control}
22422
22423 \end_inset
22424
22425 ) as the MCS51 and DS390 ports, so floating point support, support for long
22426  variables and bitfield support is fine.
22427  See mailing lists and forums about interrupt routines.
22428 \end_layout
22429
22430 \begin_layout Standard
22431 As always, the code is the authoritative reference - see z80/ralloc.c and
22432  z80/gen.c.
22433  The stack
22434 \begin_inset LatexCommand \index{Z80!stack}
22435
22436 \end_inset
22437
22438  frame is similar to that generated by the IAR Z80 compiler.
22439  IX is used as the base pointer, HL and IY are used as a temporary registers,
22440  and BC and DE are available for holding variables.
22441  Return values
22442 \begin_inset LatexCommand \index{Z80!return value}
22443
22444 \end_inset
22445
22446  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22447  bytes).
22448  The gbz80 port use the same set of registers for the return values, but
22449  in a different order of significance: E (one byte), DE (two bytes), or
22450  HLDE (four bytes).
22451 \begin_inset VSpace bigskip
22452 \end_inset
22453
22454
22455 \end_layout
22456
22457 \begin_layout Section
22458 The HC08 port
22459 \end_layout
22460
22461 \begin_layout Standard
22462 The port to the Freescale/Motorola HC08
22463 \begin_inset LatexCommand \index{HC08}
22464
22465 \end_inset
22466
22467  family has been added in October 2003, and is still undergoing some basic
22468  development.
22469  The code generator is complete, but the register allocation is still quite
22470  unoptimized.
22471  Some of the SDCC's standard C library functions have embedded non-HC08
22472  inline assembly and so are not yet usable.
22473 \end_layout
22474
22475 \begin_layout Standard
22476 The HC08 port passes the regression test suite (see section 
22477 \begin_inset LatexCommand \ref{sec:Quality-control}
22478
22479 \end_inset
22480
22481 ).
22482 \begin_inset VSpace bigskip
22483 \end_inset
22484
22485
22486 \newpage
22487
22488 \end_layout
22489
22490 \begin_layout Section
22491 The PIC14 port
22492 \end_layout
22493
22494 \begin_layout Standard
22495 The 14bit PIC
22496 \begin_inset LatexCommand \index{PIC14}
22497
22498 \end_inset
22499
22500  port still requires a major effort from the development community.
22501  However it can work for simple code.
22502  It passes its (smaller set of) regression tests
22503 \begin_inset LatexCommand \index{Regression test (PIC14)}
22504
22505 \end_inset
22506
22507  in the directory 
22508 \shape italic
22509 sdcc/src/regression
22510 \shape default
22511 .
22512 \end_layout
22513
22514 \begin_layout Subsection
22515 C code and 14bit PIC code page
22516 \begin_inset LatexCommand \index{code page (pic14)}
22517
22518 \end_inset
22519
22520  and RAM banks
22521 \begin_inset LatexCommand \index{RAM bank (pic14)}
22522
22523 \end_inset
22524
22525
22526 \end_layout
22527
22528 \begin_layout Standard
22529 The linker organizes allocation for the code page and RAM banks.
22530  It does not have intimate knowledge of the code flow.
22531  It will put all the code section of a single asm file into a single code
22532  page.
22533  In order to make use of multiple code pages, separate asm files must be
22534  used.
22535  The compiler treats all functions of a single C file as being in the same
22536  code page unless it is non static.
22537 \newline
22538
22539 \newline
22540 To get the best follow these guide lines:
22541 \end_layout
22542
22543 \begin_layout Enumerate
22544 Make local functions static, as non static functions require code page selection
22545  overhead.
22546 \end_layout
22547
22548 \begin_layout Enumerate
22549 For devices that have multiple code pages it is more efficient to use the
22550  same number of files as pages, i.e.
22551  for the 16F877 use 4 separate files and i.e.
22552  for the 16F874 use 2 separate files.
22553  This way the linker can put the code for each file into different code
22554  pages and there's less page selection overhead.
22555 \end_layout
22556
22557 \begin_layout Enumerate
22558 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22559  instruction set), use 'unsigned char' whereever possible instead of 'int'.
22560 \end_layout
22561
22562 \begin_layout Subsection
22563 Creating a device include file 
22564 \end_layout
22565
22566 \begin_layout Standard
22567 For generating a device include file
22568 \begin_inset LatexCommand \index{PIC14!Header files}
22569
22570 \end_inset
22571
22572  use the support perl script inc2h.pl kept in directory support/script.
22573 \end_layout
22574
22575 \begin_layout Subsection
22576 Interrupt code
22577 \end_layout
22578
22579 \begin_layout Standard
22580 For the interrupt function, use the keyword '__interrupt'
22581 \begin_inset LatexCommand \index{PIC14!interrupt}
22582
22583 \end_inset
22584
22585  with level number of 0 (PIC14 only has 1 interrupt so this number is only
22586  there to avoid a syntax error - it ought to be fixed).
22587  E.g.:
22588 \end_layout
22589
22590 \begin_layout Verse
22591
22592 \family typewriter
22593 void Intr(void) __interrupt 0
22594 \newline
22595 {
22596 \newline
22597 \InsetSpace ~
22598 \InsetSpace ~
22599 T0IF = 0; /* Clear timer interrupt */
22600 \newline
22601 }
22602 \end_layout
22603
22604 \begin_layout Subsection
22605 Linking and assembling
22606 \end_layout
22607
22608 \begin_layout Standard
22609 For assembling you can use either GPUTILS'
22610 \begin_inset LatexCommand \index{gputils (pic tools)}
22611
22612 \end_inset
22613
22614  gpasm.exe or MPLAB's mpasmwin.exe.
22615  GPUTILS is available from 
22616 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22617
22618 \end_inset
22619
22620 .
22621  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22622  If you use MPLAB and an interrupt function then the linker script file
22623  vectors section will need to be enlarged to link with mplink.
22624 \newline
22625
22626 \newline
22627 Here is a 
22628 \family typewriter
22629 Makefile
22630 \family default
22631  using GPUTILS:
22632 \end_layout
22633
22634 \begin_layout Verse
22635
22636 \family typewriter
22637 .c.o:
22638 \newline
22639 \InsetSpace ~
22640 \InsetSpace ~
22641 \InsetSpace ~
22642 \InsetSpace ~
22643 \InsetSpace ~
22644 \InsetSpace ~
22645 \InsetSpace ~
22646 \InsetSpace ~
22647 sdcc -S -V -mpic14 -p16F877 $< 
22648 \newline
22649 \InsetSpace ~
22650 \InsetSpace ~
22651 \InsetSpace ~
22652 \InsetSpace ~
22653 \InsetSpace ~
22654 \InsetSpace ~
22655 \InsetSpace ~
22656 \InsetSpace ~
22657 gpasm -c $*.asm
22658 \newline
22659
22660 \newline
22661 $(PRJ).hex: $(OBJS) 
22662 \newline
22663 \InsetSpace ~
22664 \InsetSpace ~
22665 \InsetSpace ~
22666 \InsetSpace ~
22667 \InsetSpace ~
22668 \InsetSpace ~
22669 \InsetSpace ~
22670 \InsetSpace ~
22671 gplink
22672  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22673 \end_layout
22674
22675 \begin_layout Standard
22676 Here is a 
22677 \family typewriter
22678 Makefile
22679 \family default
22680  using MPLAB:
22681 \end_layout
22682
22683 \begin_layout Verse
22684
22685 \family typewriter
22686 .c.o: 
22687 \newline
22688 \InsetSpace ~
22689 \InsetSpace ~
22690 \InsetSpace ~
22691 \InsetSpace ~
22692 \InsetSpace ~
22693 \InsetSpace ~
22694 \InsetSpace ~
22695 \InsetSpace ~
22696 sdcc -S -V -mpic14 -p16F877 $< 
22697 \newline
22698 \InsetSpace ~
22699 \InsetSpace ~
22700 \InsetSpace ~
22701 \InsetSpace ~
22702 \InsetSpace ~
22703 \InsetSpace ~
22704 \InsetSpace ~
22705 \InsetSpace ~
22706 mpasmwin /q /o $*.asm
22707 \newline
22708
22709 \newline
22710 $(PRJ).hex: $(OBJS)
22711  
22712 \newline
22713 \InsetSpace ~
22714 \InsetSpace ~
22715 \InsetSpace ~
22716 \InsetSpace ~
22717 \InsetSpace ~
22718 \InsetSpace ~
22719 \InsetSpace ~
22720 \InsetSpace ~
22721 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22722 \end_layout
22723
22724 \begin_layout Standard
22725 Please note that indentations within a
22726 \family typewriter
22727  Makefile
22728 \family default
22729  have to be done with a tabulator character.
22730 \end_layout
22731
22732 \begin_layout Subsection
22733 Command-line options
22734 \end_layout
22735
22736 \begin_layout Standard
22737 Besides the switches common to all SDCC backends, the PIC14 port accepts
22738  the following options (for an updated list see sdcc -
22739 \begin_inset ERT
22740 status collapsed
22741
22742 \begin_layout Standard
22743
22744
22745 \backslash
22746 /
22747 \end_layout
22748
22749 \end_inset
22750
22751 -help):
22752 \end_layout
22753
22754 \begin_layout List
22755 \labelwidthstring 00.00.0000
22756 -
22757 \begin_inset ERT
22758 status collapsed
22759
22760 \begin_layout Standard
22761
22762
22763 \backslash
22764 /
22765 \end_layout
22766
22767 \end_inset
22768
22769 -debug-extra
22770 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22771
22772 \end_inset
22773
22774  emit debug info in assembly output
22775 \end_layout
22776
22777 \begin_layout List
22778 \labelwidthstring 00.00.0000
22779 -
22780 \begin_inset ERT
22781 status collapsed
22782
22783 \begin_layout Standard
22784
22785
22786 \backslash
22787 /
22788 \end_layout
22789
22790 \end_inset
22791
22792 -no-pcode-opt
22793 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22794
22795 \end_inset
22796
22797  disable (slightly faulty) optimization on pCode
22798 \end_layout
22799
22800 \begin_layout List
22801 \labelwidthstring 00.00.0000
22802 -
22803 \begin_inset ERT
22804 status collapsed
22805
22806 \begin_layout Standard
22807
22808
22809 \backslash
22810 /
22811 \end_layout
22812
22813 \end_inset
22814
22815 -stack-loc
22816 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22817
22818 \end_inset
22819
22820  sets the lowest address of the argument passing stack (defaults to a suitably
22821  large shared databank to reduce BANKSEL overhead)
22822 \end_layout
22823
22824 \begin_layout List
22825 \labelwidthstring 00.00.0000
22826 -
22827 \begin_inset ERT
22828 status collapsed
22829
22830 \begin_layout Standard
22831
22832
22833 \backslash
22834 /
22835 \end_layout
22836
22837 \end_inset
22838
22839 -stack-size
22840 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22841
22842 \end_inset
22843
22844  sets the size if the argument passing stack (default: 16, minimum: 4)
22845 \end_layout
22846
22847 \begin_layout Subsection
22848 The library
22849 \end_layout
22850
22851 \begin_layout Subsubsection
22852 error: missing definition for symbol 
22853 \begin_inset Quotes sld
22854 \end_inset
22855
22856 __gptrget1
22857 \begin_inset Quotes srd
22858 \end_inset
22859
22860
22861 \end_layout
22862
22863 \begin_layout Standard
22864 The PIC14 port uses library routines to provide more complex operations
22865  like multiplication, division/modulus and (generic) pointer dereferencing.
22866  In order to add these routines to your project, you must link with PIC14's
22867  
22868 \family typewriter
22869 libsdcc.lib
22870 \family default
22871 .
22872  For single source file projects this is done automatically, more complex
22873  projects must add 
22874 \family typewriter
22875 libsdcc.lib
22876 \family default
22877  to the linker's arguments.
22878  Make sure you also add an include path for the library (using the -I switch
22879  to the linker)!
22880 \end_layout
22881
22882 \begin_layout Subsubsection
22883 Processor mismatch in file 
22884 \begin_inset Quotes sld
22885 \end_inset
22886
22887 XXX
22888 \begin_inset Quotes srd
22889 \end_inset
22890
22891 .
22892 \end_layout
22893
22894 \begin_layout Standard
22895 This warning can usually be ignored due to the very good compatibility amongst
22896  14 bit PIC
22897 \begin_inset LatexCommand \index{PIC14}
22898
22899 \end_inset
22900
22901  devices.
22902 \end_layout
22903
22904 \begin_layout Standard
22905 You might also consider recompiling the library for your specific device
22906  by changing the ARCH=p16f877 (default target) entry in 
22907 \family typewriter
22908 device/lib/pic/Makefile.in
22909 \family default
22910  and 
22911 \family typewriter
22912 device/lib/pic/Makefile
22913 \family default
22914  to reflect your device.
22915  This might even improve performance for smaller devices as unneccesary
22916  BANKSELs migth be removed.
22917 \end_layout
22918
22919 \begin_layout Subsection
22920 Known bugs
22921 \end_layout
22922
22923 \begin_layout Subsubsection
22924 initialized data
22925 \end_layout
22926
22927 \begin_layout Standard
22928 Currently, data can only be initialized if it resides in the source file
22929  together with 
22930 \emph on
22931 main()
22932 \emph default
22933 .
22934  Data in other source files will silently 
22935 \series bold
22936 not
22937 \series default
22938  be initialized.
22939 \family typewriter
22940 \size footnotesize
22941
22942 \begin_inset Marginal
22943 status collapsed
22944
22945 \begin_layout Standard
22946
22947 \series bold
22948 \InsetSpace ~
22949 !
22950 \end_layout
22951
22952 \end_inset
22953
22954
22955 \family default
22956
22957 \newpage
22958
22959 \end_layout
22960
22961 \begin_layout Section
22962 The PIC16
22963 \begin_inset LatexCommand \index{PIC16}
22964
22965 \end_inset
22966
22967  port
22968 \end_layout
22969
22970 \begin_layout Standard
22971 The PIC16
22972 \begin_inset LatexCommand \index{PIC16}
22973
22974 \end_inset
22975
22976  port is the portion of SDCC that is responsible to produce code for the
22977  Microchip
22978 \begin_inset LatexCommand \index{Microchip}
22979
22980 \end_inset
22981
22982 (TM) microcontrollers with 16 bit core.
22983  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22984  Currently supported devices are:
22985 \end_layout
22986
22987 \begin_layout Standard
22988 \align center
22989 \begin_inset Tabular
22990 <lyxtabular version="3" rows="4" columns="6">
22991 <features>
22992 <column alignment="center" valignment="top" leftline="true" width="0">
22993 <column alignment="center" valignment="top" leftline="true" width="0">
22994 <column alignment="center" valignment="top" leftline="true" width="0">
22995 <column alignment="center" valignment="top" leftline="true" width="0">
22996 <column alignment="center" valignment="top" leftline="true" width="0">
22997 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22998 <row topline="true">
22999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23000 \begin_inset Text
23001
23002 \begin_layout Standard
23003 18F242
23004 \end_layout
23005
23006 \end_inset
23007 </cell>
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23009 \begin_inset Text
23010
23011 \begin_layout Standard
23012 18F248
23013 \end_layout
23014
23015 \end_inset
23016 </cell>
23017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23018 \begin_inset Text
23019
23020 \begin_layout Standard
23021 18F252
23022 \end_layout
23023
23024 \end_inset
23025 </cell>
23026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23027 \begin_inset Text
23028
23029 \begin_layout Standard
23030 18F258
23031 \end_layout
23032
23033 \end_inset
23034 </cell>
23035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23036 \begin_inset Text
23037
23038 \begin_layout Standard
23039 18F442
23040 \end_layout
23041
23042 \end_inset
23043 </cell>
23044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23045 \begin_inset Text
23046
23047 \begin_layout Standard
23048 18F448
23049 \end_layout
23050
23051 \end_inset
23052 </cell>
23053 </row>
23054 <row topline="true">
23055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23056 \begin_inset Text
23057
23058 \begin_layout Standard
23059 18F452
23060 \end_layout
23061
23062 \end_inset
23063 </cell>
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23065 \begin_inset Text
23066
23067 \begin_layout Standard
23068 18F458
23069 \end_layout
23070
23071 \end_inset
23072 </cell>
23073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23074 \begin_inset Text
23075
23076 \begin_layout Standard
23077 18F1220
23078 \end_layout
23079
23080 \end_inset
23081 </cell>
23082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23083 \begin_inset Text
23084
23085 \begin_layout Standard
23086 18F2220
23087 \end_layout
23088
23089 \end_inset
23090 </cell>
23091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23092 \begin_inset Text
23093
23094 \begin_layout Standard
23095 18F2550
23096 \end_layout
23097
23098 \end_inset
23099 </cell>
23100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23101 \begin_inset Text
23102
23103 \begin_layout Standard
23104 18F4331
23105 \end_layout
23106
23107 \end_inset
23108 </cell>
23109 </row>
23110 <row topline="true">
23111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23112 \begin_inset Text
23113
23114 \begin_layout Standard
23115 18F4455
23116 \end_layout
23117
23118 \end_inset
23119 </cell>
23120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23121 \begin_inset Text
23122
23123 \begin_layout Standard
23124 18F6520
23125 \end_layout
23126
23127 \end_inset
23128 </cell>
23129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23130 \begin_inset Text
23131
23132 \begin_layout Standard
23133 18F6620
23134 \end_layout
23135
23136 \end_inset
23137 </cell>
23138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23139 \begin_inset Text
23140
23141 \begin_layout Standard
23142 18F6680
23143 \end_layout
23144
23145 \end_inset
23146 </cell>
23147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23148 \begin_inset Text
23149
23150 \begin_layout Standard
23151 18F6720
23152 \end_layout
23153
23154 \end_inset
23155 </cell>
23156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23157 \begin_inset Text
23158
23159 \begin_layout Standard
23160 18F8520
23161 \end_layout
23162
23163 \end_inset
23164 </cell>
23165 </row>
23166 <row topline="true" bottomline="true">
23167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23168 \begin_inset Text
23169
23170 \begin_layout Standard
23171 18F8620
23172 \end_layout
23173
23174 \end_inset
23175 </cell>
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23177 \begin_inset Text
23178
23179 \begin_layout Standard
23180 18F8680
23181 \end_layout
23182
23183 \end_inset
23184 </cell>
23185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23186 \begin_inset Text
23187
23188 \begin_layout Standard
23189 18F8720
23190 \end_layout
23191
23192 \end_inset
23193 </cell>
23194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23195 \begin_inset Text
23196
23197 \begin_layout Standard
23198
23199 \end_layout
23200
23201 \end_inset
23202 </cell>
23203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23204 \begin_inset Text
23205
23206 \begin_layout Standard
23207
23208 \end_layout
23209
23210 \end_inset
23211 </cell>
23212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23213 \begin_inset Text
23214
23215 \begin_layout Standard
23216
23217 \end_layout
23218
23219 \end_inset
23220 </cell>
23221 </row>
23222 </lyxtabular>
23223
23224 \end_inset
23225
23226
23227 \end_layout
23228
23229 \begin_layout Subsection
23230 Global Options
23231 \end_layout
23232
23233 \begin_layout Standard
23234 PIC16 port supports the standard command line arguments as supposed, with
23235  the exception of certain cases that will be mentioned in the following
23236  list:
23237 \end_layout
23238
23239 \begin_layout List
23240 \labelwidthstring 00.00.0000
23241 -
23242 \begin_inset ERT
23243 status collapsed
23244
23245 \begin_layout Standard
23246
23247
23248 \backslash
23249 /
23250 \end_layout
23251
23252 \end_inset
23253
23254 -callee-saves
23255 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23256
23257 \end_inset
23258
23259  See -
23260 \begin_inset ERT
23261 status collapsed
23262
23263 \begin_layout Standard
23264
23265
23266 \backslash
23267 /
23268 \end_layout
23269
23270 \end_inset
23271
23272 -all-callee-saves
23273 \end_layout
23274
23275 \begin_layout List
23276 \labelwidthstring 00.00.0000
23277 -
23278 \begin_inset ERT
23279 status collapsed
23280
23281 \begin_layout Standard
23282
23283
23284 \backslash
23285 /
23286 \end_layout
23287
23288 \end_inset
23289
23290 -fommit-frame-pointer
23291 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23292
23293 \end_inset
23294
23295  Frame pointer will be omitted when the function uses no local variables.
23296 \end_layout
23297
23298 \begin_layout Subsection
23299 Port Specific Options
23300 \begin_inset LatexCommand \index{Options PIC16}
23301
23302 \end_inset
23303
23304
23305 \end_layout
23306
23307 \begin_layout Standard
23308 The port specific options appear after the global options in the sdcc --help
23309  output.
23310 \end_layout
23311
23312 \begin_layout Subsubsection
23313 General Options
23314 \end_layout
23315
23316 \begin_layout Standard
23317 General options enable certain port features and optimizations.
23318 \end_layout
23319
23320 \begin_layout List
23321 \labelwidthstring 00.00.0000
23322 -
23323 \begin_inset ERT
23324 status collapsed
23325
23326 \begin_layout Standard
23327
23328
23329 \backslash
23330 /
23331 \end_layout
23332
23333 \end_inset
23334
23335 -pstack-model=[model] Used in conjuction with the command above.
23336  Defines the stack model to be used, valid stack models are : 
23337 \end_layout
23338
23339 \begin_deeper
23340 \begin_layout List
23341 \labelwidthstring 00.00.0000
23342
23343 \emph on
23344 small
23345 \emph default
23346  Selects small stack model.
23347  8 bit stack and frame pointers.
23348  Supports 256 bytes stack size.
23349 \end_layout
23350
23351 \begin_layout List
23352 \labelwidthstring 00.00.0000
23353
23354 \emph on
23355 large
23356 \emph default
23357  Selects large stack model.
23358  16 bit stack and frame pointers.
23359  Supports 65536 bytes stack size.
23360 \end_layout
23361
23362 \end_deeper
23363 \begin_layout List
23364 \labelwidthstring 00.00.0000
23365 -
23366 \begin_inset ERT
23367 status collapsed
23368
23369 \begin_layout Standard
23370
23371
23372 \backslash
23373 /
23374 \end_layout
23375
23376 \end_inset
23377
23378 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23379  unitialized data variables with [kword].
23380  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23381 \end_layout
23382
23383 \begin_layout List
23384 \labelwidthstring 00.00.0000
23385 -
23386 \begin_inset ERT
23387 status collapsed
23388
23389 \begin_layout Standard
23390
23391
23392 \backslash
23393 /
23394 \end_layout
23395
23396 \end_inset
23397
23398 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23399  Useful for bootloaders.
23400 \end_layout
23401
23402 \begin_layout List
23403 \labelwidthstring 00.00.0000
23404 -
23405 \begin_inset ERT
23406 status collapsed
23407
23408 \begin_layout Standard
23409
23410
23411 \backslash
23412 /
23413 \end_layout
23414
23415 \end_inset
23416
23417 -asm= sets the full path and name of an external assembler to call.
23418 \end_layout
23419
23420 \begin_layout List
23421 \labelwidthstring 00.00.0000
23422 -
23423 \begin_inset ERT
23424 status collapsed
23425
23426 \begin_layout Standard
23427
23428
23429 \backslash
23430 /
23431 \end_layout
23432
23433 \end_inset
23434
23435 -link= sets the full path and name of an external linker to call.
23436 \end_layout
23437
23438 \begin_layout List
23439 \labelwidthstring 00.00.0000
23440 -
23441 \begin_inset ERT
23442 status collapsed
23443
23444 \begin_layout Standard
23445
23446
23447 \backslash
23448 /
23449 \end_layout
23450
23451 \end_inset
23452
23453 -mplab-comp MPLAB
23454 \begin_inset LatexCommand \index{PIC16!MPLAB}
23455
23456 \end_inset
23457
23458  compatibility option.
23459  Currently only suppresses special gpasm directives.
23460 \end_layout
23461
23462 \begin_layout Subsubsection
23463 Optimization Options
23464 \end_layout
23465
23466 \begin_layout List
23467 \labelwidthstring 00.00.0000
23468 -
23469 \begin_inset ERT
23470 status collapsed
23471
23472 \begin_layout Standard
23473
23474
23475 \backslash
23476 /
23477 \end_layout
23478
23479 \end_inset
23480
23481 -optimize-goto Try to use (conditional) BRA instead of GOTO
23482 \end_layout
23483
23484 \begin_layout List
23485 \labelwidthstring 00.00.0000
23486 -
23487 \begin_inset ERT
23488 status collapsed
23489
23490 \begin_layout Standard
23491
23492
23493 \backslash
23494 /
23495 \end_layout
23496
23497 \end_inset
23498
23499 -optimize-cmp Try to optimize some compares.
23500 \end_layout
23501
23502 \begin_layout List
23503 \labelwidthstring 00.00.0000
23504 -
23505 \begin_inset ERT
23506 status collapsed
23507
23508 \begin_layout Standard
23509
23510
23511 \backslash
23512 /
23513 \end_layout
23514
23515 \end_inset
23516
23517 -optimize-df Analyze the dataflow of the generated code and improve it.
23518 \end_layout
23519
23520 \begin_layout List
23521 \labelwidthstring 00.00.0000
23522 -
23523 \begin_inset ERT
23524 status collapsed
23525
23526 \begin_layout Standard
23527
23528
23529 \backslash
23530 /
23531 \end_layout
23532
23533 \end_inset
23534
23535 -obanksel=nn Set optimization level for inserting BANKSELs.
23536 \newline
23537
23538 \end_layout
23539
23540 \begin_deeper
23541 \begin_layout List
23542 \labelwidthstring 00.00.0000
23543 0 no optimization
23544 \end_layout
23545
23546 \begin_layout List
23547 \labelwidthstring 00.00.0000
23548 1 checks previous used register and if it is the same then does not emit
23549  BANKSEL, accounts only for labels.
23550 \end_layout
23551
23552 \begin_layout List
23553 \labelwidthstring 00.00.0000
23554 2 tries to check the location of (even different) symbols and removes BANKSELs
23555  if they are in the same bank.
23556  
23557 \newline
23558
23559 \emph on
23560 Important: There might be problems if the linker script has data sections
23561  across bank borders!
23562 \end_layout
23563
23564 \end_deeper
23565 \begin_layout Subsubsection
23566 Linking Options
23567 \end_layout
23568
23569 \begin_layout List
23570 \labelwidthstring 00.00.0000
23571 -
23572 \begin_inset ERT
23573 status collapsed
23574
23575 \begin_layout Standard
23576
23577
23578 \backslash
23579 /
23580 \end_layout
23581
23582 \end_inset
23583
23584 -nodefaultlibs do not link default libraries when linking
23585 \end_layout
23586
23587 \begin_layout List
23588 \labelwidthstring 00.00.0000
23589 -
23590 \begin_inset ERT
23591 status collapsed
23592
23593 \begin_layout Standard
23594
23595
23596 \backslash
23597 /
23598 \end_layout
23599
23600 \end_inset
23601
23602 -no-crt Don't link the default run-time modules
23603 \end_layout
23604
23605 \begin_layout List
23606 \labelwidthstring 00.00.0000
23607 -
23608 \begin_inset ERT
23609 status collapsed
23610
23611 \begin_layout Standard
23612
23613
23614 \backslash
23615 /
23616 \end_layout
23617
23618 \end_inset
23619
23620 -use-crt= Use a custom run-time module instead of the defaults.
23621 \end_layout
23622
23623 \begin_layout Subsubsection
23624 Debugging Options
23625 \end_layout
23626
23627 \begin_layout Standard
23628 Debugging options enable extra debugging information in the output files.
23629 \end_layout
23630
23631 \begin_layout List
23632 \labelwidthstring 00.00.0000
23633 -
23634 \begin_inset ERT
23635 status collapsed
23636
23637 \begin_layout Standard
23638
23639
23640 \backslash
23641 /
23642 \end_layout
23643
23644 \end_inset
23645
23646 -debug-xtra Similar to -
23647 \begin_inset ERT
23648 status collapsed
23649
23650 \begin_layout Standard
23651
23652
23653 \backslash
23654 /
23655 \end_layout
23656
23657 \end_inset
23658
23659 -debug
23660 \begin_inset LatexCommand \index{-\/-debug}
23661
23662 \end_inset
23663
23664 , but dumps more information.
23665 \end_layout
23666
23667 \begin_layout List
23668 \labelwidthstring 00.00.0000
23669 -
23670 \begin_inset ERT
23671 status collapsed
23672
23673 \begin_layout Standard
23674
23675
23676 \backslash
23677 /
23678 \end_layout
23679
23680 \end_inset
23681
23682 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23683  information.
23684  <source> is the name of the file compiled.
23685 \end_layout
23686
23687 \begin_layout List
23688 \labelwidthstring 00.00.0000
23689 -
23690 \begin_inset ERT
23691 status collapsed
23692
23693 \begin_layout Standard
23694
23695
23696 \backslash
23697 /
23698 \end_layout
23699
23700 \end_inset
23701
23702 -pcode-verbose Enable pcode debugging information in translation.
23703 \end_layout
23704
23705 \begin_layout List
23706 \labelwidthstring 00.00.0000
23707 -
23708 \begin_inset ERT
23709 status collapsed
23710
23711 \begin_layout Standard
23712
23713
23714 \backslash
23715 /
23716 \end_layout
23717
23718 \end_inset
23719
23720 -denable-peeps Force the usage of peepholes.
23721  Use with care.
23722 \end_layout
23723
23724 \begin_layout List
23725 \labelwidthstring 00.00.0000
23726 -
23727 \begin_inset ERT
23728 status collapsed
23729
23730 \begin_layout Standard
23731
23732
23733 \backslash
23734 /
23735 \end_layout
23736
23737 \end_inset
23738
23739 -gstack Trace push/pops for stack pointer overflow
23740 \end_layout
23741
23742 \begin_layout List
23743 \labelwidthstring 00.00.0000
23744 -
23745 \begin_inset ERT
23746 status collapsed
23747
23748 \begin_layout Standard
23749
23750
23751 \backslash
23752 /
23753 \end_layout
23754
23755 \end_inset
23756
23757 -call-tree dump call tree in .calltree file
23758 \end_layout
23759
23760 \begin_layout Subsection
23761 Enviromental Variables
23762 \end_layout
23763
23764 \begin_layout Standard
23765 There is a number of enviromental variables that can be used when running
23766  SDCC to enable certain optimizations or force a specific program behaviour.
23767  these variables are primarily for debugging purposes so they can be enabled/dis
23768 abled at will.
23769 \end_layout
23770
23771 \begin_layout Standard
23772 Currently there is only two such variables available:
23773 \end_layout
23774
23775 \begin_layout List
23776 \labelwidthstring 00.00.0000
23777 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23778  bitfields is optimized by directly loading FSR0 with the address of the
23779  bitfield structure.
23780  Normally SDCC will cast the bitfield structure to a bitfield pointer and
23781  then load FSR0.
23782  This step saves data ram and code space for functions that perform heavy
23783  use of bitfields.
23784  (ie.
23785  80 bytes of code space are saved when compiling malloc.c with this option).
23786  
23787 \end_layout
23788
23789 \begin_layout List
23790 \labelwidthstring 00.00.0000
23791 NO_REG_OPT do not perform pCode registers optimization.
23792  This should be used for debugging purposes.
23793  In some where bugs in the pcode optimizer are found, users can benefit
23794  from temporarily disabling the optimizer until the bug is fixed.
23795 \end_layout
23796
23797 \begin_layout Subsection
23798 Preprocessor Macros
23799 \end_layout
23800
23801 \begin_layout Standard
23802 PIC16
23803 \begin_inset LatexCommand \index{PIC16}
23804
23805 \end_inset
23806
23807  port defines the following preprocessor macros while translating a source.
23808 \end_layout
23809
23810 \begin_layout Standard
23811 \align center
23812 \begin_inset Tabular
23813 <lyxtabular version="3" rows="6" columns="2">
23814 <features>
23815 <column alignment="center" valignment="top" leftline="true" width="0">
23816 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23817 <row topline="true" bottomline="true">
23818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23819 \begin_inset Text
23820
23821 \begin_layout Standard
23822 Macro
23823 \end_layout
23824
23825 \end_inset
23826 </cell>
23827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23828 \begin_inset Text
23829
23830 \begin_layout Standard
23831 Description
23832 \end_layout
23833
23834 \end_inset
23835 </cell>
23836 </row>
23837 <row topline="true">
23838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23839 \begin_inset Text
23840
23841 \begin_layout Standard
23842 SDCC_pic16
23843 \end_layout
23844
23845 \end_inset
23846 </cell>
23847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23848 \begin_inset Text
23849
23850 \begin_layout Standard
23851 Port identification
23852 \end_layout
23853
23854 \end_inset
23855 </cell>
23856 </row>
23857 <row topline="true">
23858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23859 \begin_inset Text
23860
23861 \begin_layout Standard
23862 _
23863 \begin_inset ERT
23864 status collapsed
23865
23866 \begin_layout Standard
23867
23868
23869 \backslash
23870 /
23871 \end_layout
23872
23873 \end_inset
23874
23875 _pic16
23876 \end_layout
23877
23878 \end_inset
23879 </cell>
23880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23881 \begin_inset Text
23882
23883 \begin_layout Standard
23884 Port identification (same as above)
23885 \end_layout
23886
23887 \end_inset
23888 </cell>
23889 </row>
23890 <row topline="true">
23891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23892 \begin_inset Text
23893
23894 \begin_layout Standard
23895 pic18fxxxx
23896 \end_layout
23897
23898 \end_inset
23899 </cell>
23900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23901 \begin_inset Text
23902
23903 \begin_layout Standard
23904 MCU Identification.
23905  
23906 \emph on
23907 xxxx
23908 \emph default
23909  is the microcontrol identification number, i.e.
23910  452, 6620, etc
23911 \end_layout
23912
23913 \end_inset
23914 </cell>
23915 </row>
23916 <row topline="true">
23917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23918 \begin_inset Text
23919
23920 \begin_layout Standard
23921 _
23922 \begin_inset ERT
23923 status collapsed
23924
23925 \begin_layout Standard
23926
23927
23928 \backslash
23929 /
23930 \end_layout
23931
23932 \end_inset
23933
23934 _18Fxxxx
23935 \end_layout
23936
23937 \end_inset
23938 </cell>
23939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23940 \begin_inset Text
23941
23942 \begin_layout Standard
23943 MCU Identification (same as above)
23944 \end_layout
23945
23946 \end_inset
23947 </cell>
23948 </row>
23949 <row topline="true" bottomline="true">
23950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23951 \begin_inset Text
23952
23953 \begin_layout Standard
23954 STACK_MODEL_nnn
23955 \end_layout
23956
23957 \end_inset
23958 </cell>
23959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23960 \begin_inset Text
23961
23962 \begin_layout Standard
23963 nnn = SMALL or LARGE respectively according to the stack model used
23964 \end_layout
23965
23966 \end_inset
23967 </cell>
23968 </row>
23969 </lyxtabular>
23970
23971 \end_inset
23972
23973
23974 \end_layout
23975
23976 \begin_layout Standard
23977 In addition the following macros are defined when calling assembler:
23978 \end_layout
23979
23980 \begin_layout Standard
23981 \align center
23982 \begin_inset Tabular
23983 <lyxtabular version="3" rows="4" columns="2">
23984 <features>
23985 <column alignment="center" valignment="top" leftline="true" width="0">
23986 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23987 <row topline="true" bottomline="true">
23988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23989 \begin_inset Text
23990
23991 \begin_layout Standard
23992 Macro
23993 \end_layout
23994
23995 \end_inset
23996 </cell>
23997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23998 \begin_inset Text
23999
24000 \begin_layout Standard
24001 Description
24002 \end_layout
24003
24004 \end_inset
24005 </cell>
24006 </row>
24007 <row topline="true">
24008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24009 \begin_inset Text
24010
24011 \begin_layout Standard
24012 __18Fxxxx
24013 \end_layout
24014
24015 \end_inset
24016 </cell>
24017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24018 \begin_inset Text
24019
24020 \begin_layout Standard
24021 MCU Identification.
24022  
24023 \emph on
24024 xxxx
24025 \emph default
24026  is the microcontrol identification number, i.e.
24027  452, 6620, etc
24028 \end_layout
24029
24030 \end_inset
24031 </cell>
24032 </row>
24033 <row topline="true">
24034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24035 \begin_inset Text
24036
24037 \begin_layout Standard
24038 SDCC_MODEL_nnn
24039 \end_layout
24040
24041 \end_inset
24042 </cell>
24043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24044 \begin_inset Text
24045
24046 \begin_layout Standard
24047 nnn = SMALL or LARGE respectively according to the memory model used for
24048  SDCC
24049 \end_layout
24050
24051 \end_inset
24052 </cell>
24053 </row>
24054 <row topline="true" bottomline="true">
24055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24056 \begin_inset Text
24057
24058 \begin_layout Standard
24059 STACK_MODEL_nnn
24060 \end_layout
24061
24062 \end_inset
24063 </cell>
24064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24065 \begin_inset Text
24066
24067 \begin_layout Standard
24068 nnn = SMALL or LARGE respectively according to the stack model used
24069 \end_layout
24070
24071 \end_inset
24072 </cell>
24073 </row>
24074 </lyxtabular>
24075
24076 \end_inset
24077
24078
24079 \end_layout
24080
24081 \begin_layout Subsection
24082 Directories
24083 \end_layout
24084
24085 \begin_layout Standard
24086 PIC16
24087 \begin_inset LatexCommand \index{PIC16}
24088
24089 \end_inset
24090
24091  port uses the following directories for searching header files and libraries.
24092 \end_layout
24093
24094 \begin_layout Standard
24095 \align center
24096 \begin_inset Tabular
24097 <lyxtabular version="3" rows="3" columns="4">
24098 <features>
24099 <column alignment="center" valignment="top" leftline="true" width="0">
24100 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24101 <column alignment="center" valignment="top" width="0">
24102 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24103 <row topline="true" bottomline="true">
24104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24105 \begin_inset Text
24106
24107 \begin_layout Standard
24108 Directory
24109 \end_layout
24110
24111 \end_inset
24112 </cell>
24113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24114 \begin_inset Text
24115
24116 \begin_layout Standard
24117 Description
24118 \end_layout
24119
24120 \end_inset
24121 </cell>
24122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24123 \begin_inset Text
24124
24125 \begin_layout Standard
24126 Target
24127 \end_layout
24128
24129 \end_inset
24130 </cell>
24131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24132 \begin_inset Text
24133
24134 \begin_layout Standard
24135 Command prefix
24136 \end_layout
24137
24138 \end_inset
24139 </cell>
24140 </row>
24141 <row topline="true">
24142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24143 \begin_inset Text
24144
24145 \begin_layout Standard
24146 PREFIX/sdcc/include/pic16
24147 \end_layout
24148
24149 \end_inset
24150 </cell>
24151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24152 \begin_inset Text
24153
24154 \begin_layout Standard
24155 PIC16 specific headers
24156 \end_layout
24157
24158 \end_inset
24159 </cell>
24160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24161 \begin_inset Text
24162
24163 \begin_layout Standard
24164 Compiler
24165 \end_layout
24166
24167 \end_inset
24168 </cell>
24169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24170 \begin_inset Text
24171
24172 \begin_layout Standard
24173 -I
24174 \end_layout
24175
24176 \end_inset
24177 </cell>
24178 </row>
24179 <row topline="true" bottomline="true">
24180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24181 \begin_inset Text
24182
24183 \begin_layout Standard
24184 PREFIX/sdcc/lib/pic16
24185 \end_layout
24186
24187 \end_inset
24188 </cell>
24189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24190 \begin_inset Text
24191
24192 \begin_layout Standard
24193 PIC16 specific libraries
24194 \end_layout
24195
24196 \end_inset
24197 </cell>
24198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24199 \begin_inset Text
24200
24201 \begin_layout Standard
24202 Linker
24203 \end_layout
24204
24205 \end_inset
24206 </cell>
24207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24208 \begin_inset Text
24209
24210 \begin_layout Standard
24211 -L
24212 \end_layout
24213
24214 \end_inset
24215 </cell>
24216 </row>
24217 </lyxtabular>
24218
24219 \end_inset
24220
24221
24222 \end_layout
24223
24224 \begin_layout Subsection
24225 Pragmas
24226 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24227
24228 \end_inset
24229
24230
24231 \end_layout
24232
24233 \begin_layout Standard
24234 PIC16
24235 \begin_inset LatexCommand \index{PIC16}
24236
24237 \end_inset
24238
24239  port currently supports the following pragmas:
24240 \end_layout
24241
24242 \begin_layout List
24243 \labelwidthstring 00.00.0000
24244 stack
24245 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24246
24247 \end_inset
24248
24249  pragma stack
24250 \begin_inset LatexCommand \index{PIC16!stack}
24251
24252 \end_inset
24253
24254  forces the code generator to initialize the stack & frame pointers at a
24255  specific address.
24256  This is an adhoc solution for cases where no STACK directive is available
24257  in the linker script or gplink is not instructed to create a stack section.
24258 \newline
24259 The
24260  stack pragma should be used only once in a project.
24261  Multiple pragmas may result in indeterminate behaviour of the program.
24262 \begin_inset Foot
24263 status open
24264
24265 \begin_layout Standard
24266 The old format (ie.
24267  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24268  cross page boundaries (or even exceed the available data RAM) and crash
24269  the program.
24270  Make sure that stack does not cross page boundaries when using the SMALL
24271  stack model.
24272 \end_layout
24273
24274 \end_inset
24275
24276
24277 \newline
24278 The format is as follows:
24279 \end_layout
24280
24281 \begin_layout LyX-Code
24282 #pragma stack bottom_address [stack_size]
24283 \end_layout
24284
24285 \begin_layout Standard
24286
24287 \emph on
24288 bottom_address
24289 \emph default
24290  is the lower bound of the stack section.
24291  The stack pointer initially will point at address (bottom_address+stack_size-1).
24292 \end_layout
24293
24294 \begin_layout LyX-Code
24295 Example:
24296 \end_layout
24297
24298 \begin_layout LyX-Code
24299
24300 \end_layout
24301
24302 \begin_layout LyX-Code
24303 /* initializes stack of 100 bytes at RAM address 0x200 */
24304 \end_layout
24305
24306 \begin_layout LyX-Code
24307 #pragma stack 0x200 100
24308 \end_layout
24309
24310 \begin_layout Standard
24311 If the stack_size field is omitted then a stack is created with the default
24312  size of 64.
24313  This size might be enough for most programs, but its not enough for operations
24314  with deep function nesting or excessive stack usage.
24315 \end_layout
24316
24317 \begin_layout List
24318 \labelwidthstring 00.00.0000
24319 code
24320 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24321
24322 \end_inset
24323
24324  place a function symbol at static FLASH address
24325 \end_layout
24326
24327 \begin_layout LyX-Code
24328 Example:
24329 \end_layout
24330
24331 \begin_layout LyX-Code
24332
24333 \end_layout
24334
24335 \begin_layout LyX-Code
24336 /* place function test_func at 0x4000 */
24337 \end_layout
24338
24339 \begin_layout LyX-Code
24340 #pragma code test_func 0x4000
24341 \end_layout
24342
24343 \begin_layout LyX-Code
24344
24345 \end_layout
24346
24347 \begin_layout List
24348 \labelwidthstring 00.00.0000
24349 library instructs the linker to use a library module.
24350 \newline
24351 Usage:
24352 \end_layout
24353
24354 \begin_layout LyX-Code
24355 #pragma library module_name
24356 \end_layout
24357
24358 \begin_layout Standard
24359
24360 \emph on
24361 module_name
24362 \emph default
24363  can be any library or object file (including its path).
24364  Note that there are four reserved keywords which have special meaning.
24365  These are:
24366 \end_layout
24367
24368 \begin_layout Standard
24369 \align center
24370 \begin_inset Tabular
24371 <lyxtabular version="3" rows="6" columns="3">
24372 <features>
24373 <column alignment="center" valignment="top" leftline="true" width="0">
24374 <column alignment="block" valignment="top" leftline="true" width="20page%">
24375 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24376 <row topline="true" bottomline="true">
24377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24378 \begin_inset Text
24379
24380 \begin_layout Standard
24381 Keyword
24382 \end_layout
24383
24384 \end_inset
24385 </cell>
24386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24387 \begin_inset Text
24388
24389 \begin_layout Standard
24390 Description
24391 \end_layout
24392
24393 \end_inset
24394 </cell>
24395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24396 \begin_inset Text
24397
24398 \begin_layout Standard
24399 Module to link
24400 \end_layout
24401
24402 \end_inset
24403 </cell>
24404 </row>
24405 <row topline="true">
24406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24407 \begin_inset Text
24408
24409 \begin_layout Standard
24410
24411 \series bold
24412 ignore
24413 \end_layout
24414
24415 \end_inset
24416 </cell>
24417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24418 \begin_inset Text
24419
24420 \begin_layout Standard
24421 ignore all library pragmas
24422 \end_layout
24423
24424 \end_inset
24425 </cell>
24426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24427 \begin_inset Text
24428
24429 \begin_layout Standard
24430
24431 \emph on
24432 (none)
24433 \end_layout
24434
24435 \end_inset
24436 </cell>
24437 </row>
24438 <row topline="true">
24439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24440 \begin_inset Text
24441
24442 \begin_layout Standard
24443
24444 \series bold
24445 c
24446 \end_layout
24447
24448 \end_inset
24449 </cell>
24450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24451 \begin_inset Text
24452
24453 \begin_layout Standard
24454 link the C library
24455 \end_layout
24456
24457 \end_inset
24458 </cell>
24459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24460 \begin_inset Text
24461
24462 \begin_layout Standard
24463
24464 \emph on
24465 libc18f
24466 \emph default
24467 .lib
24468 \end_layout
24469
24470 \end_inset
24471 </cell>
24472 </row>
24473 <row topline="true">
24474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24475 \begin_inset Text
24476
24477 \begin_layout Standard
24478
24479 \series bold
24480 math
24481 \end_layout
24482
24483 \end_inset
24484 </cell>
24485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24486 \begin_inset Text
24487
24488 \begin_layout Standard
24489 link the Math libarary
24490 \end_layout
24491
24492 \end_inset
24493 </cell>
24494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24495 \begin_inset Text
24496
24497 \begin_layout Standard
24498
24499 \emph on
24500 libm18f
24501 \emph default
24502 .lib
24503 \end_layout
24504
24505 \end_inset
24506 </cell>
24507 </row>
24508 <row topline="true">
24509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24510 \begin_inset Text
24511
24512 \begin_layout Standard
24513
24514 \series bold
24515 io
24516 \end_layout
24517
24518 \end_inset
24519 </cell>
24520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24521 \begin_inset Text
24522
24523 \begin_layout Standard
24524 link the I/O library
24525 \end_layout
24526
24527 \end_inset
24528 </cell>
24529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24530 \begin_inset Text
24531
24532 \begin_layout Standard
24533
24534 \emph on
24535 libio18f*
24536 \emph default
24537 .lib
24538 \end_layout
24539
24540 \end_inset
24541 </cell>
24542 </row>
24543 <row topline="true" bottomline="true">
24544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24545 \begin_inset Text
24546
24547 \begin_layout Standard
24548
24549 \series bold
24550 debug
24551 \end_layout
24552
24553 \end_inset
24554 </cell>
24555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24556 \begin_inset Text
24557
24558 \begin_layout Standard
24559 link the debug library
24560 \end_layout
24561
24562 \end_inset
24563 </cell>
24564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24565 \begin_inset Text
24566
24567 \begin_layout Standard
24568
24569 \emph on
24570 libdebug
24571 \emph default
24572 .lib
24573 \end_layout
24574
24575 \end_inset
24576 </cell>
24577 </row>
24578 </lyxtabular>
24579
24580 \end_inset
24581
24582
24583 \newline
24584 * is the device number, i.e.
24585  452 for PIC18F452 MCU.
24586 \end_layout
24587
24588 \begin_layout Standard
24589 This feature allows for linking with specific libraries withoug having to
24590  explicit name them in the command line.
24591  Note that the 
24592 \noun on
24593 ignore
24594 \noun default
24595  keyword will reject all modules specified by the library pragma.
24596 \end_layout
24597
24598 \begin_layout List
24599 \labelwidthstring 00.00.0000
24600 udata pragma udata instructs the compiler to emit code so that linker will
24601  place a variable at a specific memory bank
24602 \end_layout
24603
24604 \begin_layout LyX-Code
24605 Example:
24606 \end_layout
24607
24608 \begin_layout LyX-Code
24609
24610 \end_layout
24611
24612 \begin_layout LyX-Code
24613 /* places variable foo at bank2 */
24614 \end_layout
24615
24616 \begin_layout LyX-Code
24617 #pragma udata bank2 foo
24618 \end_layout
24619
24620 \begin_layout LyX-Code
24621 char foo;
24622 \end_layout
24623
24624 \begin_layout Standard
24625 In order for this pragma to work extra SECTION directives should be added
24626  in the .lkr script.
24627  In the following example a sample .lkr file is shown:
24628 \end_layout
24629
24630 \begin_layout LyX-Code
24631
24632 \end_layout
24633
24634 \begin_layout LyX-Code
24635 // Sample linker script for the PIC18F452 processor
24636 \end_layout
24637
24638 \begin_layout LyX-Code
24639 LIBPATH .
24640 \end_layout
24641
24642 \begin_layout LyX-Code
24643 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24644 \end_layout
24645
24646 \begin_layout LyX-Code
24647 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24648 \end_layout
24649
24650 \begin_layout LyX-Code
24651 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24652 \end_layout
24653
24654 \begin_layout LyX-Code
24655 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24656 \end_layout
24657
24658 \begin_layout LyX-Code
24659 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24660 \end_layout
24661
24662 \begin_layout LyX-Code
24663 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24664 \end_layout
24665
24666 \begin_layout LyX-Code
24667 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24668 \end_layout
24669
24670 \begin_layout LyX-Code
24671
24672 \end_layout
24673
24674 \begin_layout LyX-Code
24675 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24676 \end_layout
24677
24678 \begin_layout LyX-Code
24679 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24680 \end_layout
24681
24682 \begin_layout LyX-Code
24683 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24684 \end_layout
24685
24686 \begin_layout LyX-Code
24687 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24688 \end_layout
24689
24690 \begin_layout LyX-Code
24691 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24692 \end_layout
24693
24694 \begin_layout LyX-Code
24695 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24696 \end_layout
24697
24698 \begin_layout LyX-Code
24699 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24700 \end_layout
24701
24702 \begin_layout LyX-Code
24703
24704 \end_layout
24705
24706 \begin_layout LyX-Code
24707 SECTION    NAME=CONFIG     ROM=config
24708 \end_layout
24709
24710 \begin_layout LyX-Code
24711
24712 \end_layout
24713
24714 \begin_layout LyX-Code
24715 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
24716 \end_layout
24717
24718 \begin_layout LyX-Code
24719 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
24720 \end_layout
24721
24722 \begin_layout LyX-Code
24723 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
24724 \end_layout
24725
24726 \begin_layout LyX-Code
24727 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
24728 \end_layout
24729
24730 \begin_layout LyX-Code
24731 SECTION    NAME=bank4      RAM=gpr4
24732 \end_layout
24733
24734 \begin_layout LyX-Code
24735 SECTION    NAME=bank5      RAM=gpr5
24736 \end_layout
24737
24738 \begin_layout Standard
24739 The linker will recognise the section name set in the pragma statement and
24740  will position the variable at the memory bank set with the RAM field at
24741  the SECTION line in the linker script file.
24742 \end_layout
24743
24744 \begin_layout Subsection
24745 Header Files
24746 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24747
24748 \end_inset
24749
24750
24751 \end_layout
24752
24753 \begin_layout Standard
24754 There is one main header file
24755 \begin_inset LatexCommand \index{PIC16!Header files}
24756
24757 \end_inset
24758
24759  that can be included to the source files using the pic16
24760 \begin_inset LatexCommand \index{PIC16}
24761
24762 \end_inset
24763
24764  port.
24765  That file is the 
24766 \series bold
24767 pic18fregs.h
24768 \series default
24769 .
24770  This header file contains the definitions for the processor special registers,
24771  so it is necessary if the source accesses them.
24772  It can be included by adding the following line in the beginning of the
24773  file:
24774 \end_layout
24775
24776 \begin_layout LyX-Code
24777 #include <pic18fregs.h>
24778 \end_layout
24779
24780 \begin_layout Standard
24781 The specific microcontroller is selected within the pic18fregs.h automatically,
24782  so the same source can be used with a variety of devices.
24783 \end_layout
24784
24785 \begin_layout Subsection
24786 Libraries
24787 \end_layout
24788
24789 \begin_layout Standard
24790 The libraries
24791 \begin_inset LatexCommand \index{PIC16!Libraries}
24792
24793 \end_inset
24794
24795  that PIC16
24796 \begin_inset LatexCommand \index{PIC16}
24797
24798 \end_inset
24799
24800  port depends on are the microcontroller device libraries which contain
24801  the symbol definitions for the microcontroller special function registers.
24802  These libraries have the format pic18fxxxx.lib, where 
24803 \emph on
24804 xxxx
24805 \emph default
24806  is the microcontroller identification number.
24807  The specific library is selected automatically by the compiler at link
24808  stage according to the selected device.
24809 \end_layout
24810
24811 \begin_layout Standard
24812 Libraries are created with gplib which is part of the gputils package 
24813 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24814
24815 \end_inset
24816
24817 .
24818 \end_layout
24819
24820 \begin_layout Subsubsection*
24821 Building the libraries
24822 \end_layout
24823
24824 \begin_layout Standard
24825 Before using SDCC/pic16 there are some libraries that need to be compiled.
24826  This process is not done automatically by SDCC since not all users use
24827  SDCC for pic16 projects.
24828  So each user should compile the libraries separately.
24829 \end_layout
24830
24831 \begin_layout Standard
24832 The steps to compile the pic16 libraries under Linux are:
24833 \end_layout
24834
24835 \begin_layout LyX-Code
24836 cd device/lib/pic16
24837 \end_layout
24838
24839 \begin_layout LyX-Code
24840 ./configure
24841 \end_layout
24842
24843 \begin_layout LyX-Code
24844 make
24845 \end_layout
24846
24847 \begin_layout LyX-Code
24848 cd ..
24849 \end_layout
24850
24851 \begin_layout LyX-Code
24852 make model-pic16
24853 \end_layout
24854
24855 \begin_layout LyX-Code
24856 su -c 'make install'     # install the libraries, you need the root password
24857 \end_layout
24858
24859 \begin_layout Standard
24860 If you need to install the headers too, do:
24861 \end_layout
24862
24863 \begin_layout LyX-Code
24864 cd device/include
24865 \end_layout
24866
24867 \begin_layout LyX-Code
24868 su -c 'make install'     # install the headers, you need the root password
24869 \end_layout
24870
24871 \begin_layout Standard
24872 There exist a special target to build the I/O libraries.
24873  This target is not automatically build because it will build the I/O library
24874  for 
24875 \emph on
24876 every
24877 \emph default
24878  supported device.
24879  This way building will take quite a lot of time.
24880  Users are advised to edit the 
24881 \series bold
24882 device/lib/pic16/pics.build
24883 \series default
24884  file and then execute:
24885 \end_layout
24886
24887 \begin_layout LyX-Code
24888 make lib-io
24889 \end_layout
24890
24891 \begin_layout Subsection
24892 Memory Models
24893 \end_layout
24894
24895 \begin_layout Standard
24896 The following memory models are supported by the PIC16 port:
24897 \end_layout
24898
24899 \begin_layout Itemize
24900 small model
24901 \end_layout
24902
24903 \begin_layout Itemize
24904 large model
24905 \end_layout
24906
24907 \begin_layout Standard
24908 Memory model affects the default size of pointers within the source.
24909  The sizes are shown in the next table:
24910 \end_layout
24911
24912 \begin_layout Standard
24913 \align center
24914 \begin_inset Tabular
24915 <lyxtabular version="3" rows="3" columns="3">
24916 <features>
24917 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24918 <column alignment="center" valignment="top" leftline="true" width="0">
24919 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24920 <row topline="true" bottomline="true">
24921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24922 \begin_inset Text
24923
24924 \begin_layout Standard
24925 Pointer sizes according to memory model
24926 \end_layout
24927
24928 \end_inset
24929 </cell>
24930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24931 \begin_inset Text
24932
24933 \begin_layout Standard
24934 small model
24935 \end_layout
24936
24937 \end_inset
24938 </cell>
24939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24940 \begin_inset Text
24941
24942 \begin_layout Standard
24943 large model
24944 \end_layout
24945
24946 \end_inset
24947 </cell>
24948 </row>
24949 <row topline="true" bottomline="true">
24950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24951 \begin_inset Text
24952
24953 \begin_layout Standard
24954 code pointers
24955 \end_layout
24956
24957 \end_inset
24958 </cell>
24959 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24960 \begin_inset Text
24961
24962 \begin_layout Standard
24963 16-bits
24964 \end_layout
24965
24966 \end_inset
24967 </cell>
24968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24969 \begin_inset Text
24970
24971 \begin_layout Standard
24972 24-bits
24973 \end_layout
24974
24975 \end_inset
24976 </cell>
24977 </row>
24978 <row topline="true" bottomline="true">
24979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24980 \begin_inset Text
24981
24982 \begin_layout Standard
24983 data pointers
24984 \end_layout
24985
24986 \end_inset
24987 </cell>
24988 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24989 \begin_inset Text
24990
24991 \begin_layout Standard
24992 16-bits
24993 \end_layout
24994
24995 \end_inset
24996 </cell>
24997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24998 \begin_inset Text
24999
25000 \begin_layout Standard
25001 16-bits
25002 \end_layout
25003
25004 \end_inset
25005 </cell>
25006 </row>
25007 </lyxtabular>
25008
25009 \end_inset
25010
25011
25012 \end_layout
25013
25014 \begin_layout Standard
25015 It is advisable that all sources within a project are compiled with the
25016  same memory model.
25017  If one wants to override the default memory model, this can be done by
25018  declaring a pointer as 
25019 \series bold
25020 far
25021 \series default
25022  or 
25023 \series bold
25024 near
25025 \series default
25026 .
25027  Far selects large memory model's pointers, while near selects small memory
25028  model's pointers.
25029 \end_layout
25030
25031 \begin_layout Standard
25032 The standard device libraries (see 
25033 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25034
25035 \end_inset
25036
25037 ) contain no reference to pointers, so they can be used with both memory
25038  models.
25039 \end_layout
25040
25041 \begin_layout Subsection
25042 Stack
25043 \end_layout
25044
25045 \begin_layout Standard
25046 The stack
25047 \begin_inset LatexCommand \index{PIC16!stack}
25048
25049 \end_inset
25050
25051  implementation for the PIC16 port uses two indirect registers, FSR1 and
25052  FSR2.
25053 \end_layout
25054
25055 \begin_layout List
25056 \labelwidthstring 00.00.0000
25057 FSR1 is assigned as stack pointer
25058 \end_layout
25059
25060 \begin_layout List
25061 \labelwidthstring 00.00.0000
25062 FSR2 is assigned as frame pointer
25063 \end_layout
25064
25065 \begin_layout Standard
25066 The following stack models are supported by the PIC16 port
25067 \end_layout
25068
25069 \begin_layout Itemize
25070
25071 \noun on
25072 small
25073 \noun default
25074  model
25075 \end_layout
25076
25077 \begin_layout Itemize
25078
25079 \noun on
25080 large
25081 \noun default
25082  model
25083 \end_layout
25084
25085 \begin_layout Standard
25086
25087 \noun on
25088 Small
25089 \noun default
25090  model means that only the FSRxL byte is used to access stack and frame,
25091  while 
25092 \emph on
25093 \noun on
25094 large
25095 \emph default
25096 \noun default
25097  uses both FSRxL and FSRxH registers.
25098  The following table shows the stack/frame pointers sizes according to stack
25099  model and the maximum space they can address:
25100 \end_layout
25101
25102 \begin_layout Standard
25103 \align center
25104 \begin_inset Tabular
25105 <lyxtabular version="3" rows="3" columns="3">
25106 <features>
25107 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25108 <column alignment="center" valignment="top" leftline="true" width="0">
25109 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25110 <row topline="true" bottomline="true">
25111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25112 \begin_inset Text
25113
25114 \begin_layout Standard
25115 Stack & Frame pointer sizes according to stack model
25116 \end_layout
25117
25118 \end_inset
25119 </cell>
25120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25121 \begin_inset Text
25122
25123 \begin_layout Standard
25124 small
25125 \end_layout
25126
25127 \end_inset
25128 </cell>
25129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25130 \begin_inset Text
25131
25132 \begin_layout Standard
25133 large
25134 \end_layout
25135
25136 \end_inset
25137 </cell>
25138 </row>
25139 <row topline="true">
25140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25141 \begin_inset Text
25142
25143 \begin_layout Standard
25144 Stack pointer FSR1
25145 \end_layout
25146
25147 \end_inset
25148 </cell>
25149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25150 \begin_inset Text
25151
25152 \begin_layout Standard
25153 8-bits
25154 \end_layout
25155
25156 \end_inset
25157 </cell>
25158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25159 \begin_inset Text
25160
25161 \begin_layout Standard
25162 16-bits
25163 \end_layout
25164
25165 \end_inset
25166 </cell>
25167 </row>
25168 <row topline="true" bottomline="true">
25169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25170 \begin_inset Text
25171
25172 \begin_layout Standard
25173 Frame pointer FSR2
25174 \end_layout
25175
25176 \end_inset
25177 </cell>
25178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25179 \begin_inset Text
25180
25181 \begin_layout Standard
25182 8-bits
25183 \end_layout
25184
25185 \end_inset
25186 </cell>
25187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25188 \begin_inset Text
25189
25190 \begin_layout Standard
25191 16-bits
25192 \end_layout
25193
25194 \end_inset
25195 </cell>
25196 </row>
25197 </lyxtabular>
25198
25199 \end_inset
25200
25201
25202 \end_layout
25203
25204 \begin_layout Standard
25205
25206 \noun on
25207 Large 
25208 \noun default
25209 stack model is currently not working properly throughout the code generator.
25210  So its use is not advised.
25211  Also there are some other points that need special care:
25212 \newline
25213
25214 \end_layout
25215
25216 \begin_layout Enumerate
25217 Do not create stack sections with size more than one physical bank (that
25218  is 256 bytes)
25219 \end_layout
25220
25221 \begin_layout Enumerate
25222 Stack sections should no cross physical bank limits (i.e.
25223  #pragma stack 0x50 0x100)
25224 \end_layout
25225
25226 \begin_layout Standard
25227 These limitations are caused by the fact that only FSRxL is modified when
25228  using SMALL stack model, so no more than 256 bytes of stack can be used.
25229  This problem will disappear after LARGE model is fully implemented.
25230 \end_layout
25231
25232 \begin_layout Subsection
25233 Functions
25234 \end_layout
25235
25236 \begin_layout Standard
25237 In addition to the standard SDCC function keywords, PIC16
25238 \begin_inset LatexCommand \index{PIC16}
25239
25240 \end_inset
25241
25242  port makes available two more:
25243 \end_layout
25244
25245 \begin_layout List
25246 \labelwidthstring 00.00.0000
25247 wparam
25248 \begin_inset LatexCommand \index{PIC16!wparam}
25249
25250 \end_inset
25251
25252  Use the WREG to pass one byte of the first function argument.
25253  This improves speed but you may not use this for functions with arguments
25254  that are called via function pointers, otherwise the first byte of the
25255  first parameter will get lost.
25256  Usage:
25257 \end_layout
25258
25259 \begin_layout LyX-Code
25260 void func_wparam(int a) wparam
25261 \end_layout
25262
25263 \begin_layout LyX-Code
25264 {
25265 \end_layout
25266
25267 \begin_layout LyX-Code
25268     /* WREG hold the lower part of a */
25269 \end_layout
25270
25271 \begin_layout LyX-Code
25272     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25273  */
25274 \end_layout
25275
25276 \begin_layout LyX-Code
25277 ...
25278 \end_layout
25279
25280 \begin_layout LyX-Code
25281 }
25282 \end_layout
25283
25284 \begin_layout List
25285 \labelwidthstring 00.00.0000
25286 shadowregs
25287 \begin_inset LatexCommand \index{PIC16!shadowregs}
25288
25289 \end_inset
25290
25291  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25292  hardware shadow registers which hold the values of WREG, STATUS and BSR
25293  registers.
25294  This can be done by adding the keyword 
25295 \emph on
25296 shadowregs
25297 \emph default
25298  before the 
25299 \emph on
25300 interrupt
25301 \emph default
25302  keyword in the function's header.
25303 \end_layout
25304
25305 \begin_layout LyX-Code
25306 void isr_shadow(void) shadowregs interrupt 1
25307 \end_layout
25308
25309 \begin_layout LyX-Code
25310 {
25311 \end_layout
25312
25313 \begin_layout LyX-Code
25314 ...
25315 \end_layout
25316
25317 \begin_layout LyX-Code
25318 }
25319 \end_layout
25320
25321 \begin_layout Standard
25322
25323 \emph on
25324 shadowregs
25325 \emph default
25326  instructs the code generator not to store/restore WREG, STATUS, BSR when
25327  entering/exiting the ISR.
25328 \end_layout
25329
25330 \begin_layout Subsection
25331 Function return values
25332 \end_layout
25333
25334 \begin_layout Standard
25335 Return values from functions are placed to the appropriate registers following
25336  a modified Microchip policy optimized for SDCC.
25337  The following table shows these registers:
25338 \end_layout
25339
25340 \begin_layout Standard
25341 \align center
25342 \begin_inset Tabular
25343 <lyxtabular version="3" rows="6" columns="2">
25344 <features>
25345 <column alignment="center" valignment="top" leftline="true" width="0">
25346 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25347 <row topline="true" bottomline="true">
25348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25349 \begin_inset Text
25350
25351 \begin_layout Standard
25352 size
25353 \end_layout
25354
25355 \end_inset
25356 </cell>
25357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25358 \begin_inset Text
25359
25360 \begin_layout Standard
25361 destination register
25362 \end_layout
25363
25364 \end_inset
25365 </cell>
25366 </row>
25367 <row topline="true">
25368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25369 \begin_inset Text
25370
25371 \begin_layout Standard
25372 8 bits
25373 \end_layout
25374
25375 \end_inset
25376 </cell>
25377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25378 \begin_inset Text
25379
25380 \begin_layout Standard
25381 WREG
25382 \end_layout
25383
25384 \end_inset
25385 </cell>
25386 </row>
25387 <row topline="true">
25388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25389 \begin_inset Text
25390
25391 \begin_layout Standard
25392 16 bits
25393 \end_layout
25394
25395 \end_inset
25396 </cell>
25397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25398 \begin_inset Text
25399
25400 \begin_layout Standard
25401 PRODL:WREG
25402 \end_layout
25403
25404 \end_inset
25405 </cell>
25406 </row>
25407 <row topline="true">
25408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25409 \begin_inset Text
25410
25411 \begin_layout Standard
25412 24 bits
25413 \end_layout
25414
25415 \end_inset
25416 </cell>
25417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25418 \begin_inset Text
25419
25420 \begin_layout Standard
25421 PRODH:PRODL:WREG
25422 \end_layout
25423
25424 \end_inset
25425 </cell>
25426 </row>
25427 <row topline="true">
25428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25429 \begin_inset Text
25430
25431 \begin_layout Standard
25432 32 bits
25433 \end_layout
25434
25435 \end_inset
25436 </cell>
25437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25438 \begin_inset Text
25439
25440 \begin_layout Standard
25441 FSR0L:PRODH:PRODL:WREG
25442 \end_layout
25443
25444 \end_inset
25445 </cell>
25446 </row>
25447 <row topline="true" bottomline="true">
25448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25449 \begin_inset Text
25450
25451 \begin_layout Standard
25452 >32 bits
25453 \end_layout
25454
25455 \end_inset
25456 </cell>
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25458 \begin_inset Text
25459
25460 \begin_layout Standard
25461 on stack, FSR0 points to the beginning
25462 \end_layout
25463
25464 \end_inset
25465 </cell>
25466 </row>
25467 </lyxtabular>
25468
25469 \end_inset
25470
25471
25472 \end_layout
25473
25474 \begin_layout Subsection
25475 Interrupts
25476 \end_layout
25477
25478 \begin_layout Standard
25479 An interrupt
25480 \begin_inset LatexCommand \index{PIC16!interrupt}
25481
25482 \end_inset
25483
25484  service routine (ISR) is declared using the 
25485 \emph on
25486 interrupt
25487 \emph default
25488  keyword.
25489 \end_layout
25490
25491 \begin_layout LyX-Code
25492 void isr(void) interrupt 
25493 \emph on
25494 n
25495 \end_layout
25496
25497 \begin_layout LyX-Code
25498 {
25499 \end_layout
25500
25501 \begin_layout LyX-Code
25502 ...
25503 \end_layout
25504
25505 \begin_layout LyX-Code
25506 }
25507 \end_layout
25508
25509 \begin_layout Standard
25510
25511 \emph on
25512 n
25513 \emph default
25514  is the interrupt number, which for PIC18F devices can be:
25515 \end_layout
25516
25517 \begin_layout Standard
25518 \align center
25519 \begin_inset Tabular
25520 <lyxtabular version="3" rows="4" columns="3">
25521 <features>
25522 <column alignment="center" valignment="top" leftline="true" width="0">
25523 <column alignment="center" valignment="top" leftline="true" width="0">
25524 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25525 <row topline="true" bottomline="true">
25526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25527 \begin_inset Text
25528
25529 \begin_layout Standard
25530
25531 \emph on
25532 n
25533 \end_layout
25534
25535 \end_inset
25536 </cell>
25537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25538 \begin_inset Text
25539
25540 \begin_layout Standard
25541 Interrupt Vector
25542 \end_layout
25543
25544 \end_inset
25545 </cell>
25546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25547 \begin_inset Text
25548
25549 \begin_layout Standard
25550 Interrupt Vector Address
25551 \end_layout
25552
25553 \end_inset
25554 </cell>
25555 </row>
25556 <row topline="true">
25557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25558 \begin_inset Text
25559
25560 \begin_layout Standard
25561 0
25562 \end_layout
25563
25564 \end_inset
25565 </cell>
25566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25567 \begin_inset Text
25568
25569 \begin_layout Standard
25570 RESET vector
25571 \end_layout
25572
25573 \end_inset
25574 </cell>
25575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25576 \begin_inset Text
25577
25578 \begin_layout Standard
25579 0x000000
25580 \end_layout
25581
25582 \end_inset
25583 </cell>
25584 </row>
25585 <row topline="true">
25586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25587 \begin_inset Text
25588
25589 \begin_layout Standard
25590
25591 \family roman
25592 \series medium
25593 \shape up
25594 \size normal
25595 \emph off
25596 \bar no
25597 \noun off
25598 \color none
25599 1
25600 \end_layout
25601
25602 \end_inset
25603 </cell>
25604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25605 \begin_inset Text
25606
25607 \begin_layout Standard
25608
25609 \family roman
25610 \series medium
25611 \shape up
25612 \size normal
25613 \emph off
25614 \bar no
25615 \noun off
25616 \color none
25617 HIGH priority interrupts
25618 \end_layout
25619
25620 \end_inset
25621 </cell>
25622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25623 \begin_inset Text
25624
25625 \begin_layout Standard
25626 0x000008
25627 \end_layout
25628
25629 \end_inset
25630 </cell>
25631 </row>
25632 <row topline="true" bottomline="true">
25633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25634 \begin_inset Text
25635
25636 \begin_layout Standard
25637 2
25638 \end_layout
25639
25640 \end_inset
25641 </cell>
25642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25643 \begin_inset Text
25644
25645 \begin_layout Standard
25646 LOW priority interrupts
25647 \end_layout
25648
25649 \end_inset
25650 </cell>
25651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25652 \begin_inset Text
25653
25654 \begin_layout Standard
25655 0x000018
25656 \end_layout
25657
25658 \end_inset
25659 </cell>
25660 </row>
25661 </lyxtabular>
25662
25663 \end_inset
25664
25665
25666 \end_layout
25667
25668 \begin_layout Standard
25669 When generating assembly code for ISR the code generator places a 
25670 \noun on
25671 goto 
25672 \noun default
25673 instruction at the 
25674 \emph on
25675 Interrupt Vector Address
25676 \emph default
25677  which points at the genetated ISR.
25678  This single GOTO instruction is part of an automatically generated 
25679 \emph on
25680 interrupt entry point
25681 \emph default
25682  function.
25683  The actuall ISR code is placed as normally would in the code space.
25684  Upon interrupt request, the GOTO instruction is executed which jumps to
25685  the ISR code.
25686  When declaring interrupt functions as _naked this GOTO instruction is 
25687 \series bold
25688 not
25689 \series default
25690  generated.
25691  The whole interrupt functions is therefore placed at the Interrupt Vector
25692  Address of the specific interrupt.
25693  This is not a problem for the LOW priority interrupts, but it is a problem
25694  for the RESET and the HIGH priority interrupts because code may be written
25695  at the next interrupt´s vector address and cause undeterminate program
25696  behaviour if that interrupt is raised.
25697 \begin_inset Foot
25698 status open
25699
25700 \begin_layout Standard
25701 This is not a problem when
25702 \end_layout
25703
25704 \begin_layout Enumerate
25705 this is a HIGH interrupt ISR and LOW interrupts are 
25706 \emph on
25707 disabled
25708 \emph default
25709  or not used.
25710 \end_layout
25711
25712 \begin_layout Enumerate
25713 when the ISR is small enough not to reach the next interrupt´s vector address.
25714 \end_layout
25715
25716 \end_inset
25717
25718
25719 \end_layout
25720
25721 \begin_layout Standard
25722
25723 \emph on
25724 n
25725 \emph default
25726  is possible to be omitted.
25727  This way a function is generated similar to an ISR, but it is not assigned
25728  to any interrupt.
25729 \end_layout
25730
25731 \begin_layout Standard
25732 When entering an interrupt, currently the PIC16
25733 \begin_inset LatexCommand \index{PIC16}
25734
25735 \end_inset
25736
25737  port automatically saves the following registers:
25738 \end_layout
25739
25740 \begin_layout Itemize
25741 WREG
25742 \end_layout
25743
25744 \begin_layout Itemize
25745 STATUS
25746 \end_layout
25747
25748 \begin_layout Itemize
25749 BSR
25750 \end_layout
25751
25752 \begin_layout Itemize
25753 PROD (PRODL and PRODH)
25754 \end_layout
25755
25756 \begin_layout Itemize
25757 FSR0 (FSR0L and FSR0H)
25758 \end_layout
25759
25760 \begin_layout Standard
25761 These registers are restored upon return from the interrupt routine.
25762 \begin_inset Foot
25763 status open
25764
25765 \begin_layout Standard
25766 NOTE that when the _naked attribute is specified for an interrupt routine,
25767  then NO registers are stored or restored.
25768 \end_layout
25769
25770 \end_inset
25771
25772
25773 \end_layout
25774
25775 \begin_layout Subsection
25776 Generic Pointers
25777 \end_layout
25778
25779 \begin_layout Standard
25780 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25781  There are 3 types of generic pointers currently implemented data, code
25782  and eeprom pointers.
25783  They are differentiated by the value of the 7th and 6th bits of the upper
25784  byte:
25785 \end_layout
25786
25787 \begin_layout Standard
25788 \align center
25789 \begin_inset Tabular
25790 <lyxtabular version="3" rows="5" columns="5">
25791 <features>
25792 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25793 <column alignment="center" valignment="top" width="0">
25794 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25795 <column alignment="center" valignment="top" width="0">
25796 <column alignment="left" valignment="top" rightline="true" width="0">
25797 <row topline="true" bottomline="true">
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25799 \begin_inset Text
25800
25801 \begin_layout Standard
25802 pointer type
25803 \end_layout
25804
25805 \end_inset
25806 </cell>
25807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25808 \begin_inset Text
25809
25810 \begin_layout Standard
25811 7th bit
25812 \end_layout
25813
25814 \end_inset
25815 </cell>
25816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25817 \begin_inset Text
25818
25819 \begin_layout Standard
25820 6th bit
25821 \end_layout
25822
25823 \end_inset
25824 </cell>
25825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25826 \begin_inset Text
25827
25828 \begin_layout Standard
25829 rest of the pointer
25830 \end_layout
25831
25832 \end_inset
25833 </cell>
25834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25835 \begin_inset Text
25836
25837 \begin_layout Standard
25838 description
25839 \end_layout
25840
25841 \end_inset
25842 </cell>
25843 </row>
25844 <row topline="true" bottomline="true">
25845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25846 \begin_inset Text
25847
25848 \begin_layout Standard
25849 data 
25850 \end_layout
25851
25852 \end_inset
25853 </cell>
25854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25855 \begin_inset Text
25856
25857 \begin_layout Standard
25858 1
25859 \end_layout
25860
25861 \end_inset
25862 </cell>
25863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25864 \begin_inset Text
25865
25866 \begin_layout Standard
25867 0
25868 \end_layout
25869
25870 \end_inset
25871 </cell>
25872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25873 \begin_inset Text
25874
25875 \begin_layout Standard
25876
25877 \family typewriter
25878 \shape slanted
25879 \emph on
25880 uuuuuu uuuuxxxx xxxxxxxx
25881 \end_layout
25882
25883 \end_inset
25884 </cell>
25885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25886 \begin_inset Text
25887
25888 \begin_layout Standard
25889 a 12-bit data pointer in data RAM memory
25890 \end_layout
25891
25892 \end_inset
25893 </cell>
25894 </row>
25895 <row bottomline="true">
25896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25897 \begin_inset Text
25898
25899 \begin_layout Standard
25900 code
25901 \end_layout
25902
25903 \end_inset
25904 </cell>
25905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25906 \begin_inset Text
25907
25908 \begin_layout Standard
25909 0
25910 \end_layout
25911
25912 \end_inset
25913 </cell>
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25915 \begin_inset Text
25916
25917 \begin_layout Standard
25918 0
25919 \end_layout
25920
25921 \end_inset
25922 </cell>
25923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25924 \begin_inset Text
25925
25926 \begin_layout Standard
25927
25928 \family typewriter
25929 \shape slanted
25930 \emph on
25931 uxxxxx xxxxxxxx xxxxxxxx
25932 \end_layout
25933
25934 \end_inset
25935 </cell>
25936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25937 \begin_inset Text
25938
25939 \begin_layout Standard
25940 a 21-bit code pointer in FLASH memory
25941 \end_layout
25942
25943 \end_inset
25944 </cell>
25945 </row>
25946 <row bottomline="true">
25947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25948 \begin_inset Text
25949
25950 \begin_layout Standard
25951 eeprom
25952 \end_layout
25953
25954 \end_inset
25955 </cell>
25956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25957 \begin_inset Text
25958
25959 \begin_layout Standard
25960 0
25961 \end_layout
25962
25963 \end_inset
25964 </cell>
25965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25966 \begin_inset Text
25967
25968 \begin_layout Standard
25969 1
25970 \end_layout
25971
25972 \end_inset
25973 </cell>
25974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25975 \begin_inset Text
25976
25977 \begin_layout Standard
25978
25979 \family typewriter
25980 \shape slanted
25981 \emph on
25982 uuuuuu uuuuuuxx xxxxxxxx
25983 \end_layout
25984
25985 \end_inset
25986 </cell>
25987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25988 \begin_inset Text
25989
25990 \begin_layout Standard
25991 a 10-bit eeprom pointer in EEPROM memory
25992 \end_layout
25993
25994 \end_inset
25995 </cell>
25996 </row>
25997 <row bottomline="true">
25998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25999 \begin_inset Text
26000
26001 \begin_layout Standard
26002 (unimplemented)
26003 \end_layout
26004
26005 \end_inset
26006 </cell>
26007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26008 \begin_inset Text
26009
26010 \begin_layout Standard
26011 1
26012 \end_layout
26013
26014 \end_inset
26015 </cell>
26016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26017 \begin_inset Text
26018
26019 \begin_layout Standard
26020 1
26021 \end_layout
26022
26023 \end_inset
26024 </cell>
26025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26026 \begin_inset Text
26027
26028 \begin_layout Standard
26029
26030 \family typewriter
26031 \shape slanted
26032 \emph on
26033 xxxxxx xxxxxxxx xxxxxxxx
26034 \end_layout
26035
26036 \end_inset
26037 </cell>
26038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26039 \begin_inset Text
26040
26041 \begin_layout Standard
26042 unimplemented pointer type
26043 \end_layout
26044
26045 \end_inset
26046 </cell>
26047 </row>
26048 </lyxtabular>
26049
26050 \end_inset
26051
26052
26053 \end_layout
26054
26055 \begin_layout Standard
26056 Generic pointer are read and written with a set of library functions which
26057  read/write 1, 2, 3, 4 bytes.
26058 \end_layout
26059
26060 \begin_layout Subsection
26061 PIC16 C Libraries
26062 \end_layout
26063
26064 \begin_layout Subsubsection
26065 Standard I/O Streams
26066 \end_layout
26067
26068 \begin_layout Standard
26069 In the 
26070 \emph on
26071 stdio.h
26072 \emph default
26073  the type FILE is defined as:
26074 \end_layout
26075
26076 \begin_layout LyX-Code
26077 typedef char * FILE;
26078 \end_layout
26079
26080 \begin_layout Standard
26081 This type is the stream type implemented I/O in the PIC18F devices.
26082  Also the standard input and output streams are declared in stdio.h:
26083 \end_layout
26084
26085 \begin_layout LyX-Code
26086 extern FILE * stdin;
26087 \end_layout
26088
26089 \begin_layout LyX-Code
26090 extern FILE * stdout;
26091 \end_layout
26092
26093 \begin_layout Standard
26094 The FILE type is actually a generic pointer which defines one more type
26095  of generic pointers, the 
26096 \emph on
26097 stream 
26098 \emph default
26099 pointer.
26100  This new type has the format:
26101 \end_layout
26102
26103 \begin_layout Standard
26104 \align center
26105 \begin_inset Tabular
26106 <lyxtabular version="3" rows="2" columns="7">
26107 <features>
26108 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26109 <column alignment="center" valignment="top" width="0">
26110 <column alignment="center" valignment="top" leftline="true" width="0">
26111 <column alignment="center" valignment="top" leftline="true" width="0">
26112 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26113 <column alignment="center" valignment="top" width="0">
26114 <column alignment="left" valignment="top" rightline="true" width="0">
26115 <row topline="true" bottomline="true">
26116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26117 \begin_inset Text
26118
26119 \begin_layout Standard
26120 pointer type
26121 \end_layout
26122
26123 \end_inset
26124 </cell>
26125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26126 \begin_inset Text
26127
26128 \begin_layout Standard
26129 <7:6>
26130 \end_layout
26131
26132 \end_inset
26133 </cell>
26134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26135 \begin_inset Text
26136
26137 \begin_layout Standard
26138 <5>
26139 \end_layout
26140
26141 \end_inset
26142 </cell>
26143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26144 \begin_inset Text
26145
26146 \begin_layout Standard
26147 <4>
26148 \end_layout
26149
26150 \end_inset
26151 </cell>
26152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26153 \begin_inset Text
26154
26155 \begin_layout Standard
26156 <3:0>
26157 \end_layout
26158
26159 \end_inset
26160 </cell>
26161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26162 \begin_inset Text
26163
26164 \begin_layout Standard
26165 rest of the pointer
26166 \end_layout
26167
26168 \end_inset
26169 </cell>
26170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26171 \begin_inset Text
26172
26173 \begin_layout Standard
26174 descrption
26175 \end_layout
26176
26177 \end_inset
26178 </cell>
26179 </row>
26180 <row topline="true" bottomline="true">
26181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26182 \begin_inset Text
26183
26184 \begin_layout Standard
26185 stream
26186 \end_layout
26187
26188 \end_inset
26189 </cell>
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26191 \begin_inset Text
26192
26193 \begin_layout Standard
26194 00
26195 \end_layout
26196
26197 \end_inset
26198 </cell>
26199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26200 \begin_inset Text
26201
26202 \begin_layout Standard
26203 1
26204 \end_layout
26205
26206 \end_inset
26207 </cell>
26208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26209 \begin_inset Text
26210
26211 \begin_layout Standard
26212 0
26213 \end_layout
26214
26215 \end_inset
26216 </cell>
26217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26218 \begin_inset Text
26219
26220 \begin_layout Standard
26221 nnnn
26222 \end_layout
26223
26224 \end_inset
26225 </cell>
26226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26227 \begin_inset Text
26228
26229 \begin_layout Standard
26230
26231 \family typewriter
26232 \shape slanted
26233 \emph on
26234 uuuuuuuu uuuuuuuu
26235 \end_layout
26236
26237 \end_inset
26238 </cell>
26239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26240 \begin_inset Text
26241
26242 \begin_layout Standard
26243 upper byte high nubble is 0x2n, the rest are zeroes
26244 \end_layout
26245
26246 \end_inset
26247 </cell>
26248 </row>
26249 </lyxtabular>
26250
26251 \end_inset
26252
26253
26254 \end_layout
26255
26256 \begin_layout Standard
26257 Currently implemented there are 3 types of streams defined:
26258 \end_layout
26259
26260 \begin_layout Standard
26261 \align center
26262 \begin_inset Tabular
26263 <lyxtabular version="3" rows="4" columns="4">
26264 <features>
26265 <column alignment="center" valignment="top" leftline="true" width="0">
26266 <column alignment="center" valignment="top" leftline="true" width="0">
26267 <column alignment="center" valignment="top" leftline="true" width="0">
26268 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26269 <row topline="true" bottomline="true">
26270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26271 \begin_inset Text
26272
26273 \begin_layout Standard
26274 stream type
26275 \end_layout
26276
26277 \end_inset
26278 </cell>
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26280 \begin_inset Text
26281
26282 \begin_layout Standard
26283 value
26284 \end_layout
26285
26286 \end_inset
26287 </cell>
26288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26289 \begin_inset Text
26290
26291 \begin_layout Standard
26292 module
26293 \end_layout
26294
26295 \end_inset
26296 </cell>
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26298 \begin_inset Text
26299
26300 \begin_layout Standard
26301 description
26302 \end_layout
26303
26304 \end_inset
26305 </cell>
26306 </row>
26307 <row topline="true">
26308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26309 \begin_inset Text
26310
26311 \begin_layout Standard
26312 STREAM_USART
26313 \end_layout
26314
26315 \end_inset
26316 </cell>
26317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26318 \begin_inset Text
26319
26320 \begin_layout Standard
26321
26322 \family typewriter
26323 0x200000UL
26324 \end_layout
26325
26326 \end_inset
26327 </cell>
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26329 \begin_inset Text
26330
26331 \begin_layout Standard
26332 USART
26333 \end_layout
26334
26335 \end_inset
26336 </cell>
26337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26338 \begin_inset Text
26339
26340 \begin_layout Standard
26341 Writes/Reads characters via the USART peripheral
26342 \end_layout
26343
26344 \end_inset
26345 </cell>
26346 </row>
26347 <row topline="true">
26348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26349 \begin_inset Text
26350
26351 \begin_layout Standard
26352 STREAM_MSSP
26353 \end_layout
26354
26355 \end_inset
26356 </cell>
26357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26358 \begin_inset Text
26359
26360 \begin_layout Standard
26361
26362 \family typewriter
26363 0x210000UL
26364 \end_layout
26365
26366 \end_inset
26367 </cell>
26368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26369 \begin_inset Text
26370
26371 \begin_layout Standard
26372 MSSP
26373 \end_layout
26374
26375 \end_inset
26376 </cell>
26377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26378 \begin_inset Text
26379
26380 \begin_layout Standard
26381 Writes/Reads characters via the MSSP peripheral
26382 \end_layout
26383
26384 \end_inset
26385 </cell>
26386 </row>
26387 <row topline="true" bottomline="true">
26388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26389 \begin_inset Text
26390
26391 \begin_layout Standard
26392 STREAM_USER
26393 \end_layout
26394
26395 \end_inset
26396 </cell>
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26398 \begin_inset Text
26399
26400 \begin_layout Standard
26401
26402 \family typewriter
26403 0x2f0000UL
26404 \end_layout
26405
26406 \end_inset
26407 </cell>
26408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26409 \begin_inset Text
26410
26411 \begin_layout Standard
26412 (none)
26413 \end_layout
26414
26415 \end_inset
26416 </cell>
26417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26418 \begin_inset Text
26419
26420 \begin_layout Standard
26421 Writes/Reads characters via used defined functions
26422 \end_layout
26423
26424 \end_inset
26425 </cell>
26426 </row>
26427 </lyxtabular>
26428
26429 \end_inset
26430
26431
26432 \end_layout
26433
26434 \begin_layout Standard
26435 The stream identifiers are declared as macros in the stdio.h header.
26436 \end_layout
26437
26438 \begin_layout Standard
26439 In the libc library there exist the functions that are used to write to
26440  each of the above streams.
26441  These are
26442 \end_layout
26443
26444 \begin_layout List
26445 \labelwidthstring 00.00.0000
26446 _
26447 \begin_inset ERT
26448 status collapsed
26449
26450 \begin_layout Standard
26451
26452
26453 \backslash
26454 /
26455 \end_layout
26456
26457 \end_inset
26458
26459 _stream_usart_putchar writes a character at the USART stream
26460 \end_layout
26461
26462 \begin_layout List
26463 \labelwidthstring 00.00.0000
26464 _
26465 \begin_inset ERT
26466 status collapsed
26467
26468 \begin_layout Standard
26469
26470
26471 \backslash
26472 /
26473 \end_layout
26474
26475 \end_inset
26476
26477 _stream_mssp_putchar writes a character at the MSSP stream
26478 \end_layout
26479
26480 \begin_layout List
26481 \labelwidthstring 00.00.0000
26482 putchar dummy function.
26483  This writes a character to a user specified manner.
26484 \end_layout
26485
26486 \begin_layout Standard
26487 In order to increase performance 
26488 \emph on
26489 putchar 
26490 \emph default
26491 is declared in stdio.h as having its parameter in WREG (it has the wparam
26492  keyword).
26493  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26494  in a user-friendly way.
26495  
26496 \emph on
26497 arg
26498 \emph default
26499  is the name of the variable that holds the character to print.
26500  An example follows:
26501 \end_layout
26502
26503 \begin_layout LyX-Code
26504 #include <pic18fregs.h>
26505 \newline
26506 #include <stdio.h>
26507 \newline
26508
26509 \newline
26510 PUTCHAR( c )
26511 \end_layout
26512
26513 \begin_layout LyX-Code
26514 {
26515 \end_layout
26516
26517 \begin_layout LyX-Code
26518     PORTA = c;    /* dump character c to PORTA */
26519 \end_layout
26520
26521 \begin_layout LyX-Code
26522
26523 \newline
26524
26525 \newline
26526 void main(void)
26527 \end_layout
26528
26529 \begin_layout LyX-Code
26530 {
26531 \end_layout
26532
26533 \begin_layout LyX-Code
26534     stdout = STREAM_USER;    /* this is not necessary, since stdout points
26535 \end_layout
26536
26537 \begin_layout LyX-Code
26538                               * by default to STREAM_USER */
26539 \end_layout
26540
26541 \begin_layout LyX-Code
26542     printf (¨This is a printf test
26543 \backslash
26544 n¨);
26545 \end_layout
26546
26547 \begin_layout LyX-Code
26548 }
26549 \end_layout
26550
26551 \begin_layout LyX-Code
26552
26553 \end_layout
26554
26555 \begin_layout Subsubsection
26556 Printing functions
26557 \end_layout
26558
26559 \begin_layout Standard
26560 PIC16 contains an implementation of the printf-family of functions.
26561  There exist the following functions:
26562 \end_layout
26563
26564 \begin_layout LyX-Code
26565 extern unsigned int sprintf(char *buf, char *fmt, ...);
26566 \end_layout
26567
26568 \begin_layout LyX-Code
26569 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26570 \end_layout
26571
26572 \begin_layout LyX-Code
26573
26574 \end_layout
26575
26576 \begin_layout LyX-Code
26577 extern unsigned int printf(char *fmt, ...);
26578 \end_layout
26579
26580 \begin_layout LyX-Code
26581 extern unsigned int vprintf(char *fmt, va_lista ap);
26582 \end_layout
26583
26584 \begin_layout LyX-Code
26585
26586 \end_layout
26587
26588 \begin_layout LyX-Code
26589 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26590 \end_layout
26591
26592 \begin_layout LyX-Code
26593 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26594 \end_layout
26595
26596 \begin_layout Standard
26597 For sprintf and vsprintf 
26598 \emph on
26599 buf 
26600 \emph default
26601 should normally be a data pointer where the resulting string will be placed.
26602  No range checking is done so the user should allocate the necessery buffer.
26603  For fprintf and vfprintf 
26604 \emph on
26605 fp
26606 \emph default
26607  should be a stream pointer (i.e.
26608  stdout, STREAM_MSSP, etc...).
26609 \end_layout
26610
26611 \begin_layout Subsubsection
26612 Signals
26613 \end_layout
26614
26615 \begin_layout Standard
26616 The PIC18F family of microcontrollers supports a number of interrupt sources.
26617  A list of these interrupts is shown in the following table:
26618 \end_layout
26619
26620 \begin_layout Standard
26621 \align center
26622 \begin_inset Tabular
26623 <lyxtabular version="3" rows="11" columns="4">
26624 <features>
26625 <column alignment="left" valignment="top" leftline="true" width="0">
26626 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26627 <column alignment="left" valignment="top" leftline="true" width="0">
26628 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26629 <row topline="true" bottomline="true">
26630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26631 \begin_inset Text
26632
26633 \begin_layout Standard
26634 signal name
26635 \end_layout
26636
26637 \end_inset
26638 </cell>
26639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26640 \begin_inset Text
26641
26642 \begin_layout Standard
26643 description
26644 \end_layout
26645
26646 \end_inset
26647 </cell>
26648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26649 \begin_inset Text
26650
26651 \begin_layout Standard
26652 signal name
26653 \end_layout
26654
26655 \end_inset
26656 </cell>
26657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26658 \begin_inset Text
26659
26660 \begin_layout Standard
26661 descritpion
26662 \end_layout
26663
26664 \end_inset
26665 </cell>
26666 </row>
26667 <row topline="true">
26668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26669 \begin_inset Text
26670
26671 \begin_layout Standard
26672 SIG_RB
26673 \end_layout
26674
26675 \end_inset
26676 </cell>
26677 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26678 \begin_inset Text
26679
26680 \begin_layout Standard
26681 PORTB change interrupt
26682 \end_layout
26683
26684 \end_inset
26685 </cell>
26686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26687 \begin_inset Text
26688
26689 \begin_layout Standard
26690 SIG_EE
26691 \end_layout
26692
26693 \end_inset
26694 </cell>
26695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26696 \begin_inset Text
26697
26698 \begin_layout Standard
26699 EEPROM/FLASH write complete interrupt
26700 \end_layout
26701
26702 \end_inset
26703 </cell>
26704 </row>
26705 <row topline="true">
26706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26707 \begin_inset Text
26708
26709 \begin_layout Standard
26710 SIG_INT0
26711 \end_layout
26712
26713 \end_inset
26714 </cell>
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26716 \begin_inset Text
26717
26718 \begin_layout Standard
26719 INT0 external interrupt
26720 \end_layout
26721
26722 \end_inset
26723 </cell>
26724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26725 \begin_inset Text
26726
26727 \begin_layout Standard
26728 SIG_BCOL
26729 \end_layout
26730
26731 \end_inset
26732 </cell>
26733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26734 \begin_inset Text
26735
26736 \begin_layout Standard
26737 Bus collision interrupt
26738 \end_layout
26739
26740 \end_inset
26741 </cell>
26742 </row>
26743 <row topline="true">
26744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26745 \begin_inset Text
26746
26747 \begin_layout Standard
26748 SIG_INT1
26749 \end_layout
26750
26751 \end_inset
26752 </cell>
26753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26754 \begin_inset Text
26755
26756 \begin_layout Standard
26757 INT1 external interrupt
26758 \end_layout
26759
26760 \end_inset
26761 </cell>
26762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26763 \begin_inset Text
26764
26765 \begin_layout Standard
26766 SIG_LVD
26767 \end_layout
26768
26769 \end_inset
26770 </cell>
26771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26772 \begin_inset Text
26773
26774 \begin_layout Standard
26775 Low voltage detect interrupt
26776 \end_layout
26777
26778 \end_inset
26779 </cell>
26780 </row>
26781 <row topline="true">
26782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26783 \begin_inset Text
26784
26785 \begin_layout Standard
26786 SIG_INT2
26787 \end_layout
26788
26789 \end_inset
26790 </cell>
26791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26792 \begin_inset Text
26793
26794 \begin_layout Standard
26795 INT2 external interrupt
26796 \end_layout
26797
26798 \end_inset
26799 </cell>
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26801 \begin_inset Text
26802
26803 \begin_layout Standard
26804 SIG_PSP
26805 \end_layout
26806
26807 \end_inset
26808 </cell>
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26810 \begin_inset Text
26811
26812 \begin_layout Standard
26813 Parallel slave port interrupt
26814 \end_layout
26815
26816 \end_inset
26817 </cell>
26818 </row>
26819 <row topline="true">
26820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26821 \begin_inset Text
26822
26823 \begin_layout Standard
26824 SIG_CCP1
26825 \end_layout
26826
26827 \end_inset
26828 </cell>
26829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26830 \begin_inset Text
26831
26832 \begin_layout Standard
26833 CCP1 module interrupt
26834 \end_layout
26835
26836 \end_inset
26837 </cell>
26838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26839 \begin_inset Text
26840
26841 \begin_layout Standard
26842 SIG_AD
26843 \end_layout
26844
26845 \end_inset
26846 </cell>
26847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26848 \begin_inset Text
26849
26850 \begin_layout Standard
26851 AD convertion complete interrupt
26852 \end_layout
26853
26854 \end_inset
26855 </cell>
26856 </row>
26857 <row topline="true">
26858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26859 \begin_inset Text
26860
26861 \begin_layout Standard
26862 SIG_CCP2
26863 \end_layout
26864
26865 \end_inset
26866 </cell>
26867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26868 \begin_inset Text
26869
26870 \begin_layout Standard
26871 CCP2 module interrupt
26872 \end_layout
26873
26874 \end_inset
26875 </cell>
26876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26877 \begin_inset Text
26878
26879 \begin_layout Standard
26880 SIG_RC
26881 \end_layout
26882
26883 \end_inset
26884 </cell>
26885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26886 \begin_inset Text
26887
26888 \begin_layout Standard
26889 USART receive interrupt
26890 \end_layout
26891
26892 \end_inset
26893 </cell>
26894 </row>
26895 <row topline="true">
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26897 \begin_inset Text
26898
26899 \begin_layout Standard
26900 SIG_TMR0
26901 \end_layout
26902
26903 \end_inset
26904 </cell>
26905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26906 \begin_inset Text
26907
26908 \begin_layout Standard
26909 TMR0 overflow interrupt
26910 \end_layout
26911
26912 \end_inset
26913 </cell>
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26915 \begin_inset Text
26916
26917 \begin_layout Standard
26918 SIG_TX
26919 \end_layout
26920
26921 \end_inset
26922 </cell>
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26924 \begin_inset Text
26925
26926 \begin_layout Standard
26927 USART transmit interrupt
26928 \end_layout
26929
26930 \end_inset
26931 </cell>
26932 </row>
26933 <row topline="true">
26934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26935 \begin_inset Text
26936
26937 \begin_layout Standard
26938 SIG_TMR1
26939 \end_layout
26940
26941 \end_inset
26942 </cell>
26943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26944 \begin_inset Text
26945
26946 \begin_layout Standard
26947 TMR1 overflow interrupt
26948 \end_layout
26949
26950 \end_inset
26951 </cell>
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26953 \begin_inset Text
26954
26955 \begin_layout Standard
26956 SIG_MSSP
26957 \end_layout
26958
26959 \end_inset
26960 </cell>
26961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26962 \begin_inset Text
26963
26964 \begin_layout Standard
26965 SSP receive/transmit interrupt
26966 \end_layout
26967
26968 \end_inset
26969 </cell>
26970 </row>
26971 <row topline="true">
26972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26973 \begin_inset Text
26974
26975 \begin_layout Standard
26976 SIG_TMR2
26977 \end_layout
26978
26979 \end_inset
26980 </cell>
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26982 \begin_inset Text
26983
26984 \begin_layout Standard
26985 TMR2 matches PR2 interrupt
26986 \end_layout
26987
26988 \end_inset
26989 </cell>
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26991 \begin_inset Text
26992
26993 \begin_layout Standard
26994
26995 \end_layout
26996
26997 \end_inset
26998 </cell>
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27000 \begin_inset Text
27001
27002 \begin_layout Standard
27003
27004 \end_layout
27005
27006 \end_inset
27007 </cell>
27008 </row>
27009 <row topline="true" bottomline="true">
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27011 \begin_inset Text
27012
27013 \begin_layout Standard
27014 SIG_TMR3
27015 \end_layout
27016
27017 \end_inset
27018 </cell>
27019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27020 \begin_inset Text
27021
27022 \begin_layout Standard
27023 TMR3 overflow interrupt
27024 \end_layout
27025
27026 \end_inset
27027 </cell>
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27029 \begin_inset Text
27030
27031 \begin_layout Standard
27032
27033 \end_layout
27034
27035 \end_inset
27036 </cell>
27037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27038 \begin_inset Text
27039
27040 \begin_layout Standard
27041
27042 \end_layout
27043
27044 \end_inset
27045 </cell>
27046 </row>
27047 </lyxtabular>
27048
27049 \end_inset
27050
27051
27052 \end_layout
27053
27054 \begin_layout Standard
27055 The prototypes for these names are defined in the header file 
27056 \emph on
27057 signal.h
27058 \emph default
27059  .
27060 \end_layout
27061
27062 \begin_layout Standard
27063 In order to simplify signal handling, a number of macros is provided:
27064 \end_layout
27065
27066 \begin_layout List
27067 \labelwidthstring 00.00.0000
27068 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27069  high priority interrupts.
27070  
27071 \emph on
27072 name
27073 \emph default
27074  is the function name to use.
27075 \end_layout
27076
27077 \begin_layout List
27078 \labelwidthstring 00.00.0000
27079 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27080  low priority interrupt.
27081  
27082 \emph on
27083 name
27084 \emph default
27085  is the function name to use.
27086 \end_layout
27087
27088 \begin_layout List
27089 \labelwidthstring 00.00.0000
27090 DEF_HANDLER(sig,handler) define a handler for signal 
27091 \emph on
27092 sig.
27093 \end_layout
27094
27095 \begin_layout List
27096 \labelwidthstring 00.00.0000
27097 END_DEF end the declaration of the dispatch table.
27098 \end_layout
27099
27100 \begin_layout Standard
27101 Additionally there are two more macros to simplify the declaration of the
27102  signal handler:
27103 \end_layout
27104
27105 \begin_layout List
27106 \labelwidthstring 00.00.0000
27107
27108 \series medium
27109 SIGHANDLER(handler) 
27110 \series default
27111 this declares the function prototype for the 
27112 \emph on
27113 handler
27114 \emph default
27115  function.
27116 \end_layout
27117
27118 \begin_layout List
27119 \labelwidthstring 00.00.0000
27120 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27121 \end_layout
27122
27123 \begin_layout Standard
27124 An example of using the macros above is shown below:
27125 \end_layout
27126
27127 \begin_layout LyX-Code
27128 #include <pic18fregs.h>
27129 \end_layout
27130
27131 \begin_layout LyX-Code
27132 #include <signal.h>
27133 \newline
27134
27135 \newline
27136 DEF_INTHIGH(high_int)
27137 \end_layout
27138
27139 \begin_layout LyX-Code
27140 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27141 \end_layout
27142
27143 \begin_layout LyX-Code
27144 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27145 \end_layout
27146
27147 \begin_layout LyX-Code
27148 END_DEF
27149 \newline
27150
27151 \newline
27152 SIGHANDLER(_tmr0_handler)
27153 \end_layout
27154
27155 \begin_layout LyX-Code
27156 {
27157 \end_layout
27158
27159 \begin_layout LyX-Code
27160   /* action to be taken when timer 0 overflows */
27161 \end_layout
27162
27163 \begin_layout LyX-Code
27164 }
27165 \newline
27166
27167 \newline
27168 SIGHANDLERNAKED(_bcol_handler)
27169 \end_layout
27170
27171 \begin_layout LyX-Code
27172 {
27173 \end_layout
27174
27175 \begin_layout LyX-Code
27176   _asm
27177 \end_layout
27178
27179 \begin_layout LyX-Code
27180     /* action to be taken when bus collision occurs */
27181 \end_layout
27182
27183 \begin_layout LyX-Code
27184     retfie
27185 \end_layout
27186
27187 \begin_layout LyX-Code
27188  _endasm;
27189 \end_layout
27190
27191 \begin_layout LyX-Code
27192 }
27193 \end_layout
27194
27195 \begin_layout Standard
27196
27197 \series bold
27198 NOTES:
27199 \series default
27200  Special care should be taken when using the above scheme:
27201 \end_layout
27202
27203 \begin_layout Itemize
27204 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27205 \end_layout
27206
27207 \begin_layout Itemize
27208 when declaring SIGHANDLERNAKED handler never forget to use 
27209 \emph on
27210 retfie
27211 \emph default
27212  for proper returning.
27213 \end_layout
27214
27215 \begin_layout Subsection
27216 PIC16 Port -- Tips
27217 \end_layout
27218
27219 \begin_layout Standard
27220 Here you can find some general tips for compiling programs with SDCC/pic16.
27221 \end_layout
27222
27223 \begin_layout Subsubsection
27224 Stack size
27225 \end_layout
27226
27227 \begin_layout Standard
27228 The default stack
27229 \begin_inset LatexCommand \index{PIC16!stack}
27230
27231 \end_inset
27232
27233  size (that is 64 bytes) probably is enough for many programs.
27234  One must take care that when there are many levels of function nesting,
27235  or there is excessive usage of stack, its size should be extended.
27236  An example of such a case is the printf/sprintf family of functions.
27237  If you encounter problems like not being able to print integers, then you
27238  need to set the stack size around the maximum (256 for small stack model).
27239  The following diagram shows what happens when calling printf to print an
27240  integer:
27241 \end_layout
27242
27243 \begin_layout LyX-Code
27244 printf () --> ltoa () --> ultoa () --> divschar ()
27245 \end_layout
27246
27247 \begin_layout Standard
27248 It is should be understood that stack is easily consumed when calling complicate
27249 d functions.
27250  Using command line arguments like -
27251 \begin_inset ERT
27252 status collapsed
27253
27254 \begin_layout Standard
27255
27256
27257 \backslash
27258 /
27259 \end_layout
27260
27261 \end_inset
27262
27263 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27264  stack frames.
27265  Other ways to reduce stack usage may exist.
27266 \end_layout
27267
27268 \begin_layout Subsection
27269 Known bugs
27270 \end_layout
27271
27272 \begin_layout Standard
27273 The PIC16 Port currently does not pass SDCC's regression test
27274 \begin_inset LatexCommand \index{Regression test (PIC16)}
27275
27276 \end_inset
27277
27278  suite (see section 
27279 \begin_inset LatexCommand \ref{sec:Quality-control}
27280
27281 \end_inset
27282
27283 ) and thus the snapshot build regression tests for the PIC16 target are
27284  currently disabled for all hosts
27285 \emph on
27286 .
27287 \end_layout
27288
27289 \begin_layout Chapter
27290 Debugging
27291 \end_layout
27292
27293 \begin_layout Standard
27294 There are several approaches to debugging your code.
27295  This chapter is meant to show your options and to give detail on some of
27296  them:
27297 \newline
27298
27299 \newline
27300 When writing your code:
27301 \end_layout
27302
27303 \begin_layout Itemize
27304 write your code with debugging in mind (avoid duplicating code, put conceptually
27305  similar variables into structs, use structured code, have strategic points
27306  within your code where all variables are consistent, ...)
27307 \end_layout
27308
27309 \begin_layout Itemize
27310 run a syntax-checking tool like splint
27311 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27312
27313 \end_inset
27314
27315
27316 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27317
27318 \end_inset
27319
27320  (see -
27321 \begin_inset ERT
27322 status collapsed
27323
27324 \begin_layout Standard
27325
27326
27327 \backslash
27328 /
27329 \end_layout
27330
27331 \end_inset
27332
27333 -more-pedantic 
27334 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27335
27336 \end_inset
27337
27338 ) over the code.
27339 \end_layout
27340
27341 \begin_layout Itemize
27342 for the high level code use a C-compiler (like f.e.
27343  GCC) to compile run and debug the code on your host.
27344  See (see -
27345 \begin_inset ERT
27346 status collapsed
27347
27348 \begin_layout Standard
27349
27350
27351 \backslash
27352 /
27353 \end_layout
27354
27355 \end_inset
27356
27357 -more-pedantic 
27358 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27359
27360 \end_inset
27361
27362 ) on how to handle syntax extensions like __xdata, __at(), ...
27363  
27364 \end_layout
27365
27366 \begin_layout Itemize
27367 use another C-compiler to compile code for your target.
27368  Always an option but not recommended:) And not very likely to help you.
27369  If you seriously consider walking this path you should at least occasionally
27370  check portability of your code.
27371  Most commercial compiler vendors will offer an evaluation version so you
27372  can test compile your code or snippets of your code.
27373 \end_layout
27374
27375 \begin_layout Standard
27376 Debugging on a simulator:
27377 \end_layout
27378
27379 \begin_layout Itemize
27380 there is a separate section about SDCDB (section 
27381 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27382
27383 \end_inset
27384
27385 ) below.
27386 \end_layout
27387
27388 \begin_layout Itemize
27389 or (8051 specific) use a freeware/commercial simulator which interfaces
27390  to the AOMF
27391 \begin_inset LatexCommand \index{AOMF, AOMF51}
27392
27393 \end_inset
27394
27395  file (see 
27396 \begin_inset LatexCommand \ref{OMF file}
27397
27398 \end_inset
27399
27400 ) optionally generated by SDCC.
27401 \end_layout
27402
27403 \begin_layout Standard
27404 Debugging On-target: 
27405 \end_layout
27406
27407 \begin_layout Itemize
27408 use a MCU port pin to serially output debug data to the RS232 port of your
27409  host.
27410  You'll probably want some level shifting device typically involving a MAX232
27411  or similar IC.
27412  If the hardware serial port of the MCU is not available search for 'Software
27413  UART' in your favourite search machine.
27414 \end_layout
27415
27416 \begin_layout Itemize
27417 use an on-target monitor.
27418  In this context a monitor is a small program which usually accepts commands
27419  via a serial line and allows to set program counter, to single step through
27420  a program and read/write memory locations.
27421  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27422  
27423 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27424
27425 \end_inset
27426
27427 ).
27428 \end_layout
27429
27430 \begin_layout Itemize
27431 toggle MCU port pins at strategic points within your code and use an oscilloscop
27432 e.
27433  A 
27434 \emph on
27435 digital oscilloscope
27436 \emph default
27437
27438 \begin_inset LatexCommand \index{Oscilloscope}
27439
27440 \end_inset
27441
27442  with deep trace memory is really helpful especially if you have to debug
27443  a realtime application.
27444  If you need to monitor more pins than your oscilloscope provides you can
27445  sometimes get away with a small R-2R network.
27446  On a single channel oscilloscope you could f.e.
27447  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27448 k
27449 \begin_inset Formula $\Omega$
27450 \end_inset
27451
27452  resistor and the other one by a 5\InsetSpace ~
27453 k
27454 \begin_inset Formula $\Omega$
27455 \end_inset
27456
27457  resistor to the oscilloscope probe (check output drive capability of the
27458  pins you want to monitor).
27459  If you need to monitor many more pins a 
27460 \emph on
27461 logic analyzer
27462 \emph default
27463  will be handy.
27464 \end_layout
27465
27466 \begin_layout Itemize
27467 use an ICE (
27468 \emph on
27469 i
27470 \emph default
27471
27472 \emph on
27473 c
27474 \emph default
27475 ircuit 
27476 \emph on
27477 e
27478 \emph default
27479 mulator
27480 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27481
27482 \end_inset
27483
27484 ).
27485  Usually very expensive.
27486  And very nice to have too.
27487  And usually locks you (for years...) to the devices the ICE can emulate.
27488  
27489 \end_layout
27490
27491 \begin_layout Itemize
27492 use a remote debugger.
27493  In most 8-bit systems the symbol information is not available on the target,
27494  and a complete debugger is too bulky for the target system.
27495  Therefore usually a debugger on the host system connects to an on-target
27496  debugging stub which accepts only primitive commands.
27497  
27498 \newline
27499 Terms to enter into your favourite search engine could be 'remote debugging',
27500  'gdb stub' or 'inferior debugger'.
27501  (is there one?)
27502 \end_layout
27503
27504 \begin_layout Itemize
27505 use an on target hardware debugger.
27506  Some of the more modern MCUs include hardware support for setting break
27507  points and monitoring/changing variables by using dedicated hardware pins.
27508  This facility doesn't require additional code to run on the target and
27509  
27510 \emph on
27511 usually
27512 \emph default
27513  doesn't affect runtime behaviour until a breakpoint is hit.
27514  For the mcs51 most hardware debuggers use the AOMF
27515 \begin_inset LatexCommand \index{AOMF, AOMF51}
27516
27517 \end_inset
27518
27519  file (see 
27520 \begin_inset LatexCommand \ref{OMF file}
27521
27522 \end_inset
27523
27524 ) as input file.
27525  
27526 \end_layout
27527
27528 \begin_layout Standard
27529 Last not least:
27530 \end_layout
27531
27532 \begin_layout Itemize
27533 if you are not familiar with any of the following terms you're likely to
27534  run into problems rather sooner than later: 
27535 \emph on
27536 volatile
27537 \emph default
27538
27539 \emph on
27540 atomic
27541 \emph default
27542
27543 \emph on
27544 memory map
27545 \emph default
27546
27547 \emph on
27548 overlay
27549 \emph default
27550 .
27551  As an embedded programmer you 
27552 \emph on
27553 have
27554 \emph default
27555  to know them so why not look them up 
27556 \emph on
27557 before
27558 \emph default
27559  you have problems?)
27560 \end_layout
27561
27562 \begin_layout Itemize
27563 tell someone else about your problem (actually this is a surprisingly effective
27564  means to hunt down the bug even if the listener is not familiar with your
27565  environment).
27566  As 'failure to communicate' is probably one of the job-induced deformations
27567  of an embedded programmer this is highly encouraged.
27568 \end_layout
27569
27570 \begin_layout Section
27571 Debugging with SDCDB
27572 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27573
27574 \end_inset
27575
27576
27577 \begin_inset LatexCommand \index{SDCDB (debugger)}
27578
27579 \end_inset
27580
27581  
27582 \end_layout
27583
27584 \begin_layout Standard
27585 SDCC is distributed with a source level debugger
27586 \begin_inset LatexCommand \index{Debugger}
27587
27588 \end_inset
27589
27590 .
27591  The debugger uses a command line interface, the command repertoire of the
27592  debugger has been kept as close to gdb
27593 \begin_inset LatexCommand \index{gdb}
27594
27595 \end_inset
27596
27597  (the GNU debugger) as possible.
27598  The configuration and build process is part of the standard compiler installati
27599 on, which also builds and installs the debugger in the target directory
27600  specified during configuration.
27601  The debugger allows you debug BOTH at the C source and at the ASM source
27602  level.
27603 \end_layout
27604
27605 \begin_layout Subsection
27606 Compiling for Debugging
27607 \end_layout
27608
27609 \begin_layout Standard
27610 The -
27611 \begin_inset ERT
27612 status collapsed
27613
27614 \begin_layout Standard
27615
27616
27617 \backslash
27618 /
27619 \end_layout
27620
27621 \end_inset
27622
27623 -debug
27624 \begin_inset LatexCommand \index{-\/-debug}
27625
27626 \end_inset
27627
27628  option must be specified for all files for which debug information is to
27629  be generated.
27630  The compiler generates a .adb file for each of these files.
27631  The linker creates the .cdb
27632 \begin_inset LatexCommand \index{<file>.cdb}
27633
27634 \end_inset
27635
27636  file from the .adb
27637 \begin_inset LatexCommand \index{<file>.adb}
27638
27639 \end_inset
27640
27641  files and the address information.
27642  This .cdb is used by the debugger.
27643 \end_layout
27644
27645 \begin_layout Subsection
27646 How the Debugger Works
27647 \end_layout
27648
27649 \begin_layout Standard
27650 When the -
27651 \begin_inset ERT
27652 status collapsed
27653
27654 \begin_layout Standard
27655
27656
27657 \backslash
27658 /
27659 \end_layout
27660
27661 \end_inset
27662
27663 -debug option is specified the compiler generates extra symbol information
27664  some of which are put into the assembler source and some are put into the
27665  .adb file.
27666  Then the linker creates the .cdb file from the individual .adb files with
27667  the address information for the symbols.
27668  The debugger reads the symbolic information generated by the compiler &
27669  the address information generated by the linker.
27670  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27671  execution is controlled by the debugger.
27672  When a command is issued for the debugger, it translates it into appropriate
27673  commands for the simulator.
27674  (Currently SDCDM only connects to the simulator but 
27675 \emph on
27676 newcdb
27677 \emph default
27678  at 
27679 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27680
27681 \end_inset
27682
27683  is an effort to connect directly to the hardware.) 
27684 \end_layout
27685
27686 \begin_layout Subsection
27687 Starting the Debugger SDCDB
27688 \end_layout
27689
27690 \begin_layout Standard
27691 The debugger can be started using the following command line.
27692  (Assume the file you are debugging has the file name foo).
27693 \newline
27694
27695 \newline
27696
27697 \family sans
27698 \series bold
27699 sdcdb foo
27700 \newline
27701
27702 \family default
27703 \series default
27704
27705 \newline
27706 The debugger will look for the following files.
27707 \end_layout
27708
27709 \begin_layout Itemize
27710 foo.c - the source file.
27711 \end_layout
27712
27713 \begin_layout Itemize
27714 foo.cdb - the debugger symbol information file.
27715 \end_layout
27716
27717 \begin_layout Itemize
27718 foo.ihx - the Intel hex format
27719 \begin_inset LatexCommand \index{Intel hex format}
27720
27721 \end_inset
27722
27723  object file.
27724 \end_layout
27725
27726 \begin_layout Subsection
27727 SDCDB Command Line Options
27728 \end_layout
27729
27730 \begin_layout Itemize
27731 -
27732 \begin_inset ERT
27733 status collapsed
27734
27735 \begin_layout Standard
27736
27737
27738 \backslash
27739 /
27740 \end_layout
27741
27742 \end_inset
27743
27744 -directory=<source file directory> this option can used to specify the directory
27745  search list.
27746  The debugger will look into the directory list specified for source, cdb
27747  & ihx files.
27748  The items in the directory list must be separated by ':', e.g.
27749  if the source files can be in the directories /home/src1 and /home/src2,
27750  the -
27751 \begin_inset ERT
27752 status collapsed
27753
27754 \begin_layout Standard
27755
27756
27757 \backslash
27758 /
27759 \end_layout
27760
27761 \end_inset
27762
27763 -directory option should be -
27764 \begin_inset ERT
27765 status collapsed
27766
27767 \begin_layout Standard
27768
27769
27770 \backslash
27771 /
27772 \end_layout
27773
27774 \end_inset
27775
27776 -directory=/home/src1:/home/src2.
27777  Note there can be no spaces in the option.
27778  
27779 \end_layout
27780
27781 \begin_layout Itemize
27782 -cd <directory> - change to the <directory>.
27783 \end_layout
27784
27785 \begin_layout Itemize
27786 -fullname - used by GUI front ends.
27787 \end_layout
27788
27789 \begin_layout Itemize
27790 -cpu <cpu-type> - this argument is passed to the simulator please see the
27791  simulator docs for details.
27792 \end_layout
27793
27794 \begin_layout Itemize
27795 -X <Clock frequency > this options is passed to the simulator please see
27796  the simulator docs for details.
27797 \end_layout
27798
27799 \begin_layout Itemize
27800 -s <serial port file> passed to simulator see the simulator docs for details.
27801 \end_layout
27802
27803 \begin_layout Itemize
27804 -S <serial in,out> passed to simulator see the simulator docs for details.
27805 \end_layout
27806
27807 \begin_layout Itemize
27808 -k <port number> passed to simulator see the simulator docs for details.
27809 \end_layout
27810
27811 \begin_layout Subsection
27812 SDCDB Debugger Commands
27813 \end_layout
27814
27815 \begin_layout Standard
27816 As mentioned earlier the command interface for the debugger has been deliberatel
27817 y kept as close the GNU debugger gdb, as possible.
27818  This will help the integration with existing graphical user interfaces
27819  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27820  If you use a graphical user interface for the debugger you can skip this
27821  section.
27822 \end_layout
27823
27824 \begin_layout Subsubsection*
27825 break [line | file:line | function | file:function]
27826 \end_layout
27827
27828 \begin_layout Standard
27829 Set breakpoint at specified line or function:
27830 \newline
27831
27832 \newline
27833
27834 \family sans
27835 \series bold
27836 sdcdb>break 100 
27837 \newline
27838 sdcdb>break foo.c:100
27839 \newline
27840 sdcdb>break funcfoo
27841 \newline
27842 sdcdb>break foo.c:funcfoo
27843 \end_layout
27844
27845 \begin_layout Subsubsection*
27846 clear [line | file:line | function | file:function ]
27847 \end_layout
27848
27849 \begin_layout Standard
27850 Clear breakpoint at specified line or function:
27851 \newline
27852
27853 \newline
27854
27855 \family sans
27856 \series bold
27857 sdcdb>clear 100
27858 \newline
27859 sdcdb>clear foo.c:100
27860 \newline
27861 sdcdb>clear funcfoo
27862 \newline
27863 sdcdb>clear foo.c:funcfoo
27864 \end_layout
27865
27866 \begin_layout Subsubsection*
27867 continue
27868 \end_layout
27869
27870 \begin_layout Standard
27871 Continue program being debugged, after breakpoint.
27872 \end_layout
27873
27874 \begin_layout Subsubsection*
27875 finish
27876 \end_layout
27877
27878 \begin_layout Standard
27879 Execute till the end of the current function.
27880 \end_layout
27881
27882 \begin_layout Subsubsection*
27883 delete [n]
27884 \end_layout
27885
27886 \begin_layout Standard
27887 Delete breakpoint number 'n'.
27888  If used without any option clear ALL user defined break points.
27889 \end_layout
27890
27891 \begin_layout Subsubsection*
27892 info [break | stack | frame | registers ]
27893 \end_layout
27894
27895 \begin_layout Itemize
27896 info break - list all breakpoints
27897 \end_layout
27898
27899 \begin_layout Itemize
27900 info stack - show the function call stack.
27901 \end_layout
27902
27903 \begin_layout Itemize
27904 info frame - show information about the current execution frame.
27905 \end_layout
27906
27907 \begin_layout Itemize
27908 info registers - show content of all registers.
27909 \end_layout
27910
27911 \begin_layout Subsubsection*
27912 step
27913 \end_layout
27914
27915 \begin_layout Standard
27916 Step program until it reaches a different source line.
27917  Note: pressing <return> repeats the last command.
27918 \end_layout
27919
27920 \begin_layout Subsubsection*
27921 next
27922 \end_layout
27923
27924 \begin_layout Standard
27925 Step program, proceeding through subroutine calls.
27926 \end_layout
27927
27928 \begin_layout Subsubsection*
27929 run
27930 \end_layout
27931
27932 \begin_layout Standard
27933 Start debugged program.
27934 \end_layout
27935
27936 \begin_layout Subsubsection*
27937 ptype variable 
27938 \end_layout
27939
27940 \begin_layout Standard
27941 Print type information of the variable.
27942 \end_layout
27943
27944 \begin_layout Subsubsection*
27945 print variable
27946 \end_layout
27947
27948 \begin_layout Standard
27949 print value of variable.
27950 \end_layout
27951
27952 \begin_layout Subsubsection*
27953 file filename
27954 \end_layout
27955
27956 \begin_layout Standard
27957 load the given file name.
27958  Note this is an alternate method of loading file for debugging.
27959 \end_layout
27960
27961 \begin_layout Subsubsection*
27962 frame
27963 \end_layout
27964
27965 \begin_layout Standard
27966 print information about current frame.
27967 \end_layout
27968
27969 \begin_layout Subsubsection*
27970 set srcmode
27971 \end_layout
27972
27973 \begin_layout Standard
27974 Toggle between C source & assembly source.
27975 \end_layout
27976
27977 \begin_layout Subsubsection*
27978 ! simulator command
27979 \end_layout
27980
27981 \begin_layout Standard
27982 Send the string following '!' to the simulator, the simulator response is
27983  displayed.
27984  Note the debugger does not interpret the command being sent to the simulator,
27985  so if a command like 'go' is sent the debugger can loose its execution
27986  context and may display incorrect values.
27987 \end_layout
27988
27989 \begin_layout Subsubsection*
27990 quit
27991 \end_layout
27992
27993 \begin_layout Standard
27994 "Watch me now.
27995  Iam going Down.
27996  My name is Bobby Brown"
27997 \end_layout
27998
27999 \begin_layout Subsection
28000 Interfacing SDCDB with DDD
28001 \end_layout
28002
28003 \begin_layout Standard
28004 \begin_inset Note Note
28005 status collapsed
28006
28007 \begin_layout Standard
28008 The screenshot was converted from png to eps with: 
28009 \begin_inset Quotes sld
28010 \end_inset
28011
28012 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28013 \begin_inset Quotes srd
28014 \end_inset
28015
28016  which produces a pretty compact eps file which is free from compression
28017  artifacts.
28018 \end_layout
28019
28020 \begin_layout Standard
28021 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28022  as this broke the build system on Sourceforge (pdf-file was broken.
28023  pdflatex does not accept eps files).
28024 \end_layout
28025
28026 \end_inset
28027
28028
28029 \end_layout
28030
28031 \begin_layout Standard
28032 The 
28033 \emph on
28034 p
28035 \emph default
28036 ortable 
28037 \emph on
28038 n
28039 \emph default
28040 etwork 
28041 \emph on
28042 g
28043 \emph default
28044 raphics File 
28045 \size footnotesize
28046
28047 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28048
28049 \end_inset
28050
28051
28052 \size default
28053  shows a screenshot of a debugging session with DDD
28054 \begin_inset LatexCommand \index{DDD (debugger)}
28055
28056 \end_inset
28057
28058  (Unix only) on a simulated 8032.
28059  The debugging session might not run as smoothly as the screenshot suggests.
28060  The debugger allows setting of breakpoints, displaying and changing variables,
28061  single stepping through C and assembler code.
28062  
28063 \newline
28064 The source was compiled with 
28065 \family sans
28066 \series bold
28067
28068 \newline
28069
28070 \newline
28071 sdcc -
28072 \family default
28073 \series default
28074
28075 \begin_inset ERT
28076 status collapsed
28077
28078 \begin_layout Standard
28079
28080
28081 \backslash
28082 /
28083 \end_layout
28084
28085 \end_inset
28086
28087
28088 \family sans
28089 \series bold
28090 -debug ddd_example.c
28091 \family default
28092 \series default
28093  
28094 \family sans
28095 \series bold
28096
28097 \newline
28098
28099 \family default
28100 \series default
28101
28102 \newline
28103 and DDD was invoked with 
28104 \family sans
28105 \series bold
28106
28107 \newline
28108
28109 \newline
28110 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28111 \end_layout
28112
28113 \begin_layout Standard
28114 \begin_inset Note Note
28115 status open
28116
28117 \begin_layout Standard
28118 Check that the double quotes or an apostroph within the command line survive
28119  the LyX tool chain.
28120  Previously the apostrophs got slanted in the PDF output so a cut and paste
28121  did not work.
28122 \end_layout
28123
28124 \end_inset
28125
28126
28127 \end_layout
28128
28129 \begin_layout Subsection
28130 Interfacing SDCDB with XEmacs
28131 \begin_inset LatexCommand \index{XEmacs}
28132
28133 \end_inset
28134
28135
28136 \begin_inset LatexCommand \index{Emacs}
28137
28138 \end_inset
28139
28140
28141 \end_layout
28142
28143 \begin_layout Standard
28144 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28145  sdcdb.el and sdcdbsrc.el.
28146  These two files can be found in the $(prefix)/bin directory after the installat
28147 ion is complete.
28148  These files need to be loaded into XEmacs for the interface to work.
28149  This can be done at XEmacs startup time by inserting the following into
28150  your '.xemacs' file (which can be found in your HOME directory): 
28151 \newline
28152
28153 \newline
28154
28155 \family typewriter
28156 (load-file sdcdbsrc.el) 
28157 \family default
28158
28159 \newline
28160
28161 \newline
28162 .xemacs is a lisp file so the () around the command is REQUIRED.
28163  The files can also be loaded dynamically while XEmacs is running, set the
28164  environment variable 'EMACSLOADPATH' to the installation bin directory
28165  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28166  To start the interface enter the following command: 
28167 \newline
28168
28169 \newline
28170
28171 \family sans
28172 \series bold
28173 ESC-x sdcdbsrc
28174 \family default
28175 \series default
28176
28177 \newline
28178
28179 \newline
28180 You will prompted to enter the file name to be debugged.
28181  
28182 \newline
28183
28184 \newline
28185 The command line options that are passed to the simulator directly are
28186  bound to default values in the file sdcdbsrc.el.
28187  The variables are listed below, these values maybe changed as required.
28188 \end_layout
28189
28190 \begin_layout Itemize
28191 sdcdbsrc-cpu-type '51
28192 \end_layout
28193
28194 \begin_layout Itemize
28195 sdcdbsrc-frequency '11059200
28196 \end_layout
28197
28198 \begin_layout Itemize
28199 sdcdbsrc-serial nil
28200 \end_layout
28201
28202 \begin_layout Standard
28203 The following is a list of key mapping for the debugger interface.
28204 \end_layout
28205
28206 \begin_layout Standard
28207 \InsetSpace ~
28208
28209 \family typewriter
28210
28211 \newline
28212 ;;\InsetSpace ~
28213 Current Listing :: 
28214 \newline
28215 ;;key\InsetSpace ~
28216 \InsetSpace ~
28217 \InsetSpace ~
28218 \InsetSpace ~
28219 \InsetSpace ~
28220 \InsetSpace ~
28221 \InsetSpace ~
28222 \InsetSpace ~
28223 \InsetSpace ~
28224 \InsetSpace ~
28225 \InsetSpace ~
28226 \InsetSpace ~
28227 \InsetSpace ~
28228 \InsetSpace ~
28229 binding\InsetSpace ~
28230 \InsetSpace ~
28231 \InsetSpace ~
28232 \InsetSpace ~
28233 \InsetSpace ~
28234 \InsetSpace ~
28235 \InsetSpace ~
28236 \InsetSpace ~
28237 \InsetSpace ~
28238 \InsetSpace ~
28239 \InsetSpace ~
28240 \InsetSpace ~
28241 \InsetSpace ~
28242 \InsetSpace ~
28243 \InsetSpace ~
28244 \InsetSpace ~
28245 \InsetSpace ~
28246 \InsetSpace ~
28247 \InsetSpace ~
28248 \InsetSpace ~
28249 \InsetSpace ~
28250 \InsetSpace ~
28251 Comment 
28252 \newline
28253 ;;---\InsetSpace ~
28254 \InsetSpace ~
28255 \InsetSpace ~
28256 \InsetSpace ~
28257 \InsetSpace ~
28258 \InsetSpace ~
28259 \InsetSpace ~
28260 \InsetSpace ~
28261 \InsetSpace ~
28262 \InsetSpace ~
28263 \InsetSpace ~
28264 \InsetSpace ~
28265 \InsetSpace ~
28266 \InsetSpace ~
28267 -------\InsetSpace ~
28268 \InsetSpace ~
28269 \InsetSpace ~
28270 \InsetSpace ~
28271 \InsetSpace ~
28272 \InsetSpace ~
28273 \InsetSpace ~
28274 \InsetSpace ~
28275 \InsetSpace ~
28276 \InsetSpace ~
28277 \InsetSpace ~
28278 \InsetSpace ~
28279 \InsetSpace ~
28280 \InsetSpace ~
28281 \InsetSpace ~
28282 \InsetSpace ~
28283 \InsetSpace ~
28284 \InsetSpace ~
28285 \InsetSpace ~
28286 \InsetSpace ~
28287 \InsetSpace ~
28288 \InsetSpace ~
28289 -------
28290 \newline
28291 ;; 
28292 \newline
28293 ;;\InsetSpace ~
28294 n\InsetSpace ~
28295 \InsetSpace ~
28296 \InsetSpace ~
28297 \InsetSpace ~
28298 \InsetSpace ~
28299 \InsetSpace ~
28300 \InsetSpace ~
28301 \InsetSpace ~
28302 \InsetSpace ~
28303 \InsetSpace ~
28304 \InsetSpace ~
28305 \InsetSpace ~
28306 \InsetSpace ~
28307 \InsetSpace ~
28308 \InsetSpace ~
28309 sdcdb-next-fro
28310 m-src\InsetSpace ~
28311 \InsetSpace ~
28312 \InsetSpace ~
28313 \InsetSpace ~
28314 \InsetSpace ~
28315 \InsetSpace ~
28316 \InsetSpace ~
28317 \InsetSpace ~
28318 \InsetSpace ~
28319 \InsetSpace ~
28320 SDCDB next command 
28321 \newline
28322 ;;\InsetSpace ~
28323 b\InsetSpace ~
28324 \InsetSpace ~
28325 \InsetSpace ~
28326 \InsetSpace ~
28327 \InsetSpace ~
28328 \InsetSpace ~
28329 \InsetSpace ~
28330 \InsetSpace ~
28331 \InsetSpace ~
28332 \InsetSpace ~
28333 \InsetSpace ~
28334 \InsetSpace ~
28335 \InsetSpace ~
28336 \InsetSpace ~
28337 \InsetSpace ~
28338 sdcdb-back-from-src\InsetSpace ~
28339 \InsetSpace ~
28340 \InsetSpace ~
28341 \InsetSpace ~
28342 \InsetSpace ~
28343 \InsetSpace ~
28344 \InsetSpace ~
28345 \InsetSpace ~
28346 \InsetSpace ~
28347 \InsetSpace ~
28348 SDCDB back command 
28349 \newline
28350 ;;\InsetSpace ~
28351 c\InsetSpace ~
28352 \InsetSpace ~
28353 \InsetSpace ~
28354 \InsetSpace ~
28355 \InsetSpace ~
28356 \InsetSpace ~
28357 \InsetSpace ~
28358 \InsetSpace ~
28359 \InsetSpace ~
28360 \InsetSpace ~
28361 \InsetSpace ~
28362 \InsetSpace ~
28363 \InsetSpace ~
28364 \InsetSpace ~
28365 \InsetSpace ~
28366 sdcdb-cont-f
28367 rom-src\InsetSpace ~
28368 \InsetSpace ~
28369 \InsetSpace ~
28370 \InsetSpace ~
28371 \InsetSpace ~
28372 \InsetSpace ~
28373 \InsetSpace ~
28374 \InsetSpace ~
28375 \InsetSpace ~
28376 \InsetSpace ~
28377 SDCDB continue command
28378 \newline
28379 ;;\InsetSpace ~
28380 s\InsetSpace ~
28381 \InsetSpace ~
28382 \InsetSpace ~
28383 \InsetSpace ~
28384 \InsetSpace ~
28385 \InsetSpace ~
28386 \InsetSpace ~
28387 \InsetSpace ~
28388 \InsetSpace ~
28389 \InsetSpace ~
28390 \InsetSpace ~
28391 \InsetSpace ~
28392 \InsetSpace ~
28393 \InsetSpace ~
28394 \InsetSpace ~
28395 sdcdb-step-from-src\InsetSpace ~
28396 \InsetSpace ~
28397 \InsetSpace ~
28398 \InsetSpace ~
28399 \InsetSpace ~
28400 \InsetSpace ~
28401 \InsetSpace ~
28402 \InsetSpace ~
28403 \InsetSpace ~
28404 \InsetSpace ~
28405 SDCDB step command 
28406 \newline
28407 ;;\InsetSpace ~
28408 ?\InsetSpace ~
28409 \InsetSpace ~
28410 \InsetSpace ~
28411 \InsetSpace ~
28412 \InsetSpace ~
28413 \InsetSpace ~
28414 \InsetSpace ~
28415 \InsetSpace ~
28416 \InsetSpace ~
28417 \InsetSpace ~
28418 \InsetSpace ~
28419 \InsetSpace ~
28420 \InsetSpace ~
28421 \InsetSpace ~
28422 \InsetSpace ~
28423 sdcdb-w
28424 hatis-c-sexp\InsetSpace ~
28425 \InsetSpace ~
28426 \InsetSpace ~
28427 \InsetSpace ~
28428 \InsetSpace ~
28429 \InsetSpace ~
28430 \InsetSpace ~
28431 \InsetSpace ~
28432 \InsetSpace ~
28433 \InsetSpace ~
28434 SDCDB ptypecommand for data at 
28435 \newline
28436 ;;\InsetSpace ~
28437 \InsetSpace ~
28438 \InsetSpace ~
28439 \InsetSpace ~
28440 \InsetSpace ~
28441 \InsetSpace ~
28442 \InsetSpace ~
28443 \InsetSpace ~
28444 \InsetSpace ~
28445 \InsetSpace ~
28446 \InsetSpace ~
28447 \InsetSpace ~
28448 \InsetSpace ~
28449 \InsetSpace ~
28450 \InsetSpace ~
28451 \InsetSpace ~
28452 \InsetSpace ~
28453 \InsetSpace ~
28454 \InsetSpace ~
28455 \InsetSpace ~
28456 \InsetSpace ~
28457 \InsetSpace ~
28458 \InsetSpace ~
28459 \InsetSpace ~
28460 \InsetSpace ~
28461 \InsetSpace ~
28462 \InsetSpace ~
28463 \InsetSpace ~
28464 \InsetSpace ~
28465 \InsetSpace ~
28466 \InsetSpace ~
28467 \InsetSpace ~
28468 \InsetSpace ~
28469 \InsetSpace ~
28470 \InsetSpace ~
28471 \InsetSpace ~
28472 \InsetSpace ~
28473 \InsetSpace ~
28474 \InsetSpace ~
28475 \InsetSpace ~
28476 \InsetSpace ~
28477 \InsetSpace ~
28478 \InsetSpace ~
28479 \InsetSpace ~
28480 \InsetSpace ~
28481 \InsetSpace ~
28482 \InsetSpace ~
28483 buffer point 
28484 \newline
28485 ;;\InsetSpace ~
28486 x\InsetSpace ~
28487 \InsetSpace ~
28488 \InsetSpace ~
28489 \InsetSpace ~
28490 \InsetSpace ~
28491 \InsetSpace ~
28492 \InsetSpace ~
28493 \InsetSpace ~
28494 \InsetSpace ~
28495 \InsetSpace ~
28496 \InsetSpace ~
28497 \InsetSpace ~
28498 \InsetSpace ~
28499 \InsetSpace ~
28500 \InsetSpace ~
28501 sdcdbsrc-delete\InsetSpace ~
28502 \InsetSpace ~
28503 \InsetSpace ~
28504 \InsetSpace ~
28505 \InsetSpace ~
28506 \InsetSpace ~
28507 \InsetSpace ~
28508 \InsetSpace ~
28509 \InsetSpace ~
28510 \InsetSpace ~
28511 \InsetSpace ~
28512 \InsetSpace ~
28513 \InsetSpace ~
28514 \InsetSpace ~
28515 SDCD
28516 B Delete all breakpoints if no arg 
28517 \newline
28518 ;;\InsetSpace ~
28519 \InsetSpace ~
28520 \InsetSpace ~
28521 \InsetSpace ~
28522 \InsetSpace ~
28523 \InsetSpace ~
28524 \InsetSpace ~
28525 \InsetSpace ~
28526 \InsetSpace ~
28527 \InsetSpace ~
28528 \InsetSpace ~
28529 \InsetSpace ~
28530 \InsetSpace ~
28531 \InsetSpace ~
28532 \InsetSpace ~
28533 \InsetSpace ~
28534 \InsetSpace ~
28535 \InsetSpace ~
28536 \InsetSpace ~
28537 \InsetSpace ~
28538 \InsetSpace ~
28539 \InsetSpace ~
28540 \InsetSpace ~
28541 \InsetSpace ~
28542 \InsetSpace ~
28543 \InsetSpace ~
28544 \InsetSpace ~
28545 \InsetSpace ~
28546 \InsetSpace ~
28547 \InsetSpace ~
28548 \InsetSpace ~
28549 \InsetSpace ~
28550 \InsetSpace ~
28551 \InsetSpace ~
28552 \InsetSpace ~
28553 \InsetSpace ~
28554 \InsetSpace ~
28555 \InsetSpace ~
28556 \InsetSpace ~
28557 \InsetSpace ~
28558 \InsetSpace ~
28559 \InsetSpace ~
28560 \InsetSpace ~
28561 \InsetSpace ~
28562 \InsetSpace ~
28563 \InsetSpace ~
28564 \InsetSpace ~
28565 given or delete arg (C-u arg x) 
28566 \newline
28567 ;;\InsetSpace ~
28568 m\InsetSpace ~
28569 \InsetSpace ~
28570 \InsetSpace ~
28571 \InsetSpace ~
28572 \InsetSpace ~
28573 \InsetSpace ~
28574 \InsetSpace ~
28575 \InsetSpace ~
28576 \InsetSpace ~
28577 \InsetSpace ~
28578 \InsetSpace ~
28579 \InsetSpace ~
28580 \InsetSpace ~
28581 \InsetSpace ~
28582 \InsetSpace ~
28583 sdcdbsrc
28584 -frame\InsetSpace ~
28585 \InsetSpace ~
28586 \InsetSpace ~
28587 \InsetSpace ~
28588 \InsetSpace ~
28589 \InsetSpace ~
28590 \InsetSpace ~
28591 \InsetSpace ~
28592 \InsetSpace ~
28593 \InsetSpace ~
28594 \InsetSpace ~
28595 \InsetSpace ~
28596 \InsetSpace ~
28597 \InsetSpace ~
28598 \InsetSpace ~
28599 SDCDB Display current frame if no arg, 
28600 \newline
28601 ;;\InsetSpace ~
28602 \InsetSpace ~
28603 \InsetSpace ~
28604 \InsetSpace ~
28605 \InsetSpace ~
28606 \InsetSpace ~
28607 \InsetSpace ~
28608 \InsetSpace ~
28609 \InsetSpace ~
28610 \InsetSpace ~
28611 \InsetSpace ~
28612 \InsetSpace ~
28613 \InsetSpace ~
28614 \InsetSpace ~
28615 \InsetSpace ~
28616 \InsetSpace ~
28617 \InsetSpace ~
28618 \InsetSpace ~
28619 \InsetSpace ~
28620 \InsetSpace ~
28621 \InsetSpace ~
28622 \InsetSpace ~
28623 \InsetSpace ~
28624 \InsetSpace ~
28625 \InsetSpace ~
28626 \InsetSpace ~
28627 \InsetSpace ~
28628 \InsetSpace ~
28629 \InsetSpace ~
28630 \InsetSpace ~
28631 \InsetSpace ~
28632 \InsetSpace ~
28633 \InsetSpace ~
28634 \InsetSpace ~
28635 \InsetSpace ~
28636 \InsetSpace ~
28637 \InsetSpace ~
28638 \InsetSpace ~
28639 \InsetSpace ~
28640 \InsetSpace ~
28641 \InsetSpace ~
28642 \InsetSpace ~
28643 \InsetSpace ~
28644 \InsetSpace ~
28645 \InsetSpace ~
28646 \InsetSpace ~
28647 \InsetSpace ~
28648 given or display frame arg
28649  
28650 \newline
28651 ;;\InsetSpace ~
28652 \InsetSpace ~
28653 \InsetSpace ~
28654 \InsetSpace ~
28655 \InsetSpace ~
28656 \InsetSpace ~
28657 \InsetSpace ~
28658 \InsetSpace ~
28659 \InsetSpace ~
28660 \InsetSpace ~
28661 \InsetSpace ~
28662 \InsetSpace ~
28663 \InsetSpace ~
28664 \InsetSpace ~
28665 \InsetSpace ~
28666 \InsetSpace ~
28667 \InsetSpace ~
28668 \InsetSpace ~
28669 \InsetSpace ~
28670 \InsetSpace ~
28671 \InsetSpace ~
28672 \InsetSpace ~
28673 \InsetSpace ~
28674 \InsetSpace ~
28675 \InsetSpace ~
28676 \InsetSpace ~
28677 \InsetSpace ~
28678 \InsetSpace ~
28679 \InsetSpace ~
28680 \InsetSpace ~
28681 \InsetSpace ~
28682 \InsetSpace ~
28683 \InsetSpace ~
28684 \InsetSpace ~
28685 \InsetSpace ~
28686 \InsetSpace ~
28687 \InsetSpace ~
28688 \InsetSpace ~
28689 \InsetSpace ~
28690 \InsetSpace ~
28691 \InsetSpace ~
28692 \InsetSpace ~
28693 \InsetSpace ~
28694 \InsetSpace ~
28695 \InsetSpace ~
28696 \InsetSpace ~
28697 \InsetSpace ~
28698 buffer point 
28699 \newline
28700 ;;\InsetSpace ~
28701 !\InsetSpace ~
28702 \InsetSpace ~
28703 \InsetSpace ~
28704 \InsetSpace ~
28705 \InsetSpace ~
28706 \InsetSpace ~
28707 \InsetSpace ~
28708 \InsetSpace ~
28709 \InsetSpace ~
28710 \InsetSpace ~
28711 \InsetSpace ~
28712 \InsetSpace ~
28713 \InsetSpace ~
28714 \InsetSpace ~
28715 \InsetSpace ~
28716 sdcdbsrc-goto-sdcdb\InsetSpace ~
28717 \InsetSpace ~
28718 \InsetSpace ~
28719 \InsetSpace ~
28720 \InsetSpace ~
28721 \InsetSpace ~
28722 \InsetSpace ~
28723 \InsetSpace ~
28724 \InsetSpace ~
28725 \InsetSpace ~
28726 Goto the SDCDB output buffer 
28727 \newline
28728 ;;\InsetSpace ~
28729 p\InsetSpace ~
28730 \InsetSpace ~
28731 \InsetSpace ~
28732 \InsetSpace ~
28733 \InsetSpace ~
28734 \InsetSpace ~
28735 \InsetSpace ~
28736 \InsetSpace ~
28737 \InsetSpace ~
28738 \InsetSpace ~
28739 \InsetSpace ~
28740 \InsetSpace ~
28741 \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744 sdcdb-prin
28745 t-c-sexp\InsetSpace ~
28746 \InsetSpace ~
28747 \InsetSpace ~
28748 \InsetSpace ~
28749 \InsetSpace ~
28750 \InsetSpace ~
28751 \InsetSpace ~
28752 \InsetSpace ~
28753 \InsetSpace ~
28754 \InsetSpace ~
28755 \InsetSpace ~
28756 SDCDB print command for data at 
28757 \newline
28758 ;;\InsetSpace ~
28759 \InsetSpace ~
28760 \InsetSpace ~
28761 \InsetSpace ~
28762 \InsetSpace ~
28763 \InsetSpace ~
28764 \InsetSpace ~
28765 \InsetSpace ~
28766 \InsetSpace ~
28767 \InsetSpace ~
28768 \InsetSpace ~
28769 \InsetSpace ~
28770 \InsetSpace ~
28771 \InsetSpace ~
28772 \InsetSpace ~
28773 \InsetSpace ~
28774 \InsetSpace ~
28775 \InsetSpace ~
28776 \InsetSpace ~
28777 \InsetSpace ~
28778 \InsetSpace ~
28779 \InsetSpace ~
28780 \InsetSpace ~
28781 \InsetSpace ~
28782 \InsetSpace ~
28783 \InsetSpace ~
28784 \InsetSpace ~
28785 \InsetSpace ~
28786 \InsetSpace ~
28787 \InsetSpace ~
28788 \InsetSpace ~
28789 \InsetSpace ~
28790 \InsetSpace ~
28791 \InsetSpace ~
28792 \InsetSpace ~
28793 \InsetSpace ~
28794 \InsetSpace ~
28795 \InsetSpace ~
28796 \InsetSpace ~
28797 \InsetSpace ~
28798 \InsetSpace ~
28799 \InsetSpace ~
28800 \InsetSpace ~
28801 \InsetSpace ~
28802 \InsetSpace ~
28803 \InsetSpace ~
28804 \InsetSpace ~
28805 buffer point 
28806 \newline
28807 ;;\InsetSpace ~
28808 g\InsetSpace ~
28809 \InsetSpace ~
28810 \InsetSpace ~
28811 \InsetSpace ~
28812 \InsetSpace ~
28813 \InsetSpace ~
28814 \InsetSpace ~
28815 \InsetSpace ~
28816 \InsetSpace ~
28817 \InsetSpace ~
28818 \InsetSpace ~
28819 \InsetSpace ~
28820 \InsetSpace ~
28821 \InsetSpace ~
28822 \InsetSpace ~
28823 sdcdbsrc-goto-sdcdb\InsetSpace ~
28824 \InsetSpace ~
28825 \InsetSpace ~
28826 \InsetSpace ~
28827 \InsetSpace ~
28828 \InsetSpace ~
28829 \InsetSpace ~
28830 \InsetSpace ~
28831 \InsetSpace ~
28832 \InsetSpace ~
28833 Got
28834 o the SDCDB output buffer 
28835 \newline
28836 ;;\InsetSpace ~
28837 t\InsetSpace ~
28838 \InsetSpace ~
28839 \InsetSpace ~
28840 \InsetSpace ~
28841 \InsetSpace ~
28842 \InsetSpace ~
28843 \InsetSpace ~
28844 \InsetSpace ~
28845 \InsetSpace ~
28846 \InsetSpace ~
28847 \InsetSpace ~
28848 \InsetSpace ~
28849 \InsetSpace ~
28850 \InsetSpace ~
28851 \InsetSpace ~
28852 sdcdbsrc-mode\InsetSpace ~
28853 \InsetSpace ~
28854 \InsetSpace ~
28855 \InsetSpace ~
28856 \InsetSpace ~
28857 \InsetSpace ~
28858 \InsetSpace ~
28859 \InsetSpace ~
28860 \InsetSpace ~
28861 \InsetSpace ~
28862 \InsetSpace ~
28863 \InsetSpace ~
28864 \InsetSpace ~
28865 \InsetSpace ~
28866 \InsetSpace ~
28867 \InsetSpace ~
28868 Toggles Sdcdbsrc mode (turns it
28869  off) 
28870 \newline
28871 ;; 
28872 \newline
28873 ;;\InsetSpace ~
28874 C-c\InsetSpace ~
28875 C-f\InsetSpace ~
28876 \InsetSpace ~
28877 \InsetSpace ~
28878 \InsetSpace ~
28879 \InsetSpace ~
28880 \InsetSpace ~
28881 \InsetSpace ~
28882 \InsetSpace ~
28883 \InsetSpace ~
28884 sdcdb-finish-from-src\InsetSpace ~
28885 \InsetSpace ~
28886 \InsetSpace ~
28887 \InsetSpace ~
28888 \InsetSpace ~
28889 \InsetSpace ~
28890 \InsetSpace ~
28891 \InsetSpace ~
28892 SDCDB finish command 
28893 \newline
28894 ;; 
28895 \newline
28896 ;;\InsetSpace ~
28897 C-x\InsetSpace ~
28898 SPC\InsetSpace ~
28899 \InsetSpace ~
28900 \InsetSpace ~
28901 \InsetSpace ~
28902 \InsetSpace ~
28903 \InsetSpace ~
28904 \InsetSpace ~
28905 \InsetSpace ~
28906 \InsetSpace ~
28907 sdcdb-brea
28908 k\InsetSpace ~
28909 \InsetSpace ~
28910 \InsetSpace ~
28911 \InsetSpace ~
28912 \InsetSpace ~
28913 \InsetSpace ~
28914 \InsetSpace ~
28915 \InsetSpace ~
28916 \InsetSpace ~
28917 \InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 \InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 Set break for line with point 
28927 \newline
28928 ;;\InsetSpace ~
28929 ESC\InsetSpace ~
28930 t\InsetSpace ~
28931 \InsetSpace ~
28932 \InsetSpace ~
28933 \InsetSpace ~
28934 \InsetSpace ~
28935 \InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 \InsetSpace ~
28940 \InsetSpace ~
28941 sdcdbsrc-mode\InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 \InsetSpace ~
28945 \InsetSpace ~
28946 \InsetSpace ~
28947 \InsetSpace ~
28948 \InsetSpace ~
28949 \InsetSpace ~
28950 \InsetSpace ~
28951 \InsetSpace ~
28952 \InsetSpace ~
28953 \InsetSpace ~
28954 \InsetSpace ~
28955 \InsetSpace ~
28956 \InsetSpace ~
28957 Toggle Sdcdbsrc mode 
28958 \newline
28959 ;;\InsetSpace ~
28960 ESC\InsetSpace ~
28961 m\InsetSpace ~
28962 \InsetSpace ~
28963 \InsetSpace ~
28964 \InsetSpace ~
28965 \InsetSpace ~
28966 \InsetSpace ~
28967 \InsetSpace ~
28968 \InsetSpace ~
28969 \InsetSpace ~
28970 \InsetSpace ~
28971 \InsetSpace ~
28972 sdc
28973 dbsrc-srcmode\InsetSpace ~
28974 \InsetSpace ~
28975 \InsetSpace ~
28976 \InsetSpace ~
28977 \InsetSpace ~
28978 \InsetSpace ~
28979 \InsetSpace ~
28980 \InsetSpace ~
28981 \InsetSpace ~
28982 \InsetSpace ~
28983 \InsetSpace ~
28984 \InsetSpace ~
28985 \InsetSpace ~
28986 Toggle list mode 
28987 \newline
28988 ;; 
28989 \newline
28990
28991 \family default
28992
28993 \newpage
28994
28995 \end_layout
28996
28997 \begin_layout Chapter
28998 TIPS
28999 \end_layout
29000
29001 \begin_layout Standard
29002 Here are a few guidelines that will help the compiler generate more efficient
29003  code, some of the tips are specific to this compiler others are generally
29004  good programming practice.
29005 \end_layout
29006
29007 \begin_layout Itemize
29008 Use the smallest data type to represent your data-value.
29009  If it is known in advance that the value is going to be less than 256 then
29010  use an 'unsigned char' instead of a 'short' or 'int'.
29011  Please note, that ANSI C requires both signed and unsigned chars to be
29012  promoted to 'signed int'
29013 \begin_inset LatexCommand \index{promotion to signed int}
29014
29015 \end_inset
29016
29017
29018 \begin_inset Marginal
29019 status collapsed
29020
29021 \begin_layout Standard
29022
29023 \series bold
29024 \InsetSpace ~
29025 !
29026 \end_layout
29027
29028 \end_inset
29029
29030  before doing any operation.
29031  This promotion
29032 \begin_inset LatexCommand \index{type promotion}
29033
29034 \end_inset
29035
29036
29037 \begin_inset LatexCommand \label{type promotion}
29038
29039 \end_inset
29040
29041  can be omitted, if the result is the same.
29042  The effect of the promotion rules together with the sign-extension is often
29043  surprising:
29044 \end_layout
29045
29046 \begin_deeper
29047 \begin_layout Verse
29048
29049 \family typewriter
29050 unsigned char uc = 0xfe;
29051 \newline
29052 if (uc * uc < 0) /* this is true! */
29053 \newline
29054 {
29055 \newline
29056 \InsetSpace ~
29057 \InsetSpace ~
29058 \InsetSpace ~
29059 \InsetSpace ~
29060 ....
29061 \newline
29062 }
29063 \end_layout
29064
29065 \begin_layout Standard
29066
29067 \family typewriter
29068 uc * uc
29069 \family default
29070  is evaluated as 
29071 \family typewriter
29072 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29073 \family default
29074 .
29075  
29076 \newline
29077 Another one:
29078 \end_layout
29079
29080 \begin_layout Verse
29081
29082 \family typewriter
29083 (unsigned char) -12 / (signed char) -3 = ...
29084 \end_layout
29085
29086 \begin_layout Standard
29087 No, the result is not 4:
29088 \end_layout
29089
29090 \begin_layout Verse
29091
29092 \family typewriter
29093 (int) (unsigned char) -12 / (int) (signed char) -3 =
29094 \newline
29095 (int) (unsigned char)
29096  0xf4 / (int) (signed char) 0xfd =
29097 \newline
29098 (int) 0x00f4 / (int) 0xfffd =
29099 \newline
29100 (int) 0x00f4
29101  / (int) 0xfffd =
29102 \newline
29103 (int) 244 / (int) -3 =
29104 \newline
29105 (int) -81 = (int) 0xffaf;
29106 \end_layout
29107
29108 \begin_layout Standard
29109 Don't complain, that gcc gives you a different result.
29110  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29111  Therefore the results are different.
29112 \newline
29113 From 
29114 \begin_inset Quotes sld
29115 \end_inset
29116
29117 comp.lang.c FAQ
29118 \begin_inset Quotes srd
29119 \end_inset
29120
29121 :
29122 \end_layout
29123
29124 \begin_layout Quote
29125
29126 \emph on
29127 If well-defined overflow characteristics are important and negative values
29128  are not, or if you want to steer clear of sign-extension problems when
29129  manipulating bits or bytes, use one of the corresponding unsigned types.
29130  (Beware when mixing signed and unsigned values in expressions, though.)
29131 \newline
29132 Although
29133  character types (especially unsigned char) can be used as "tiny" integers,
29134  doing so is sometimes more trouble than it's worth, due to unpredictable
29135  sign extension and increased code size.
29136 \end_layout
29137
29138 \end_deeper
29139 \begin_layout Itemize
29140 Use unsigned when it is known in advance that the value is not going to
29141  be negative.
29142  This helps especially if you are doing division or multiplication, bit-shifting
29143  or are using an array index.
29144 \end_layout
29145
29146 \begin_layout Itemize
29147 NEVER jump into a LOOP.
29148 \end_layout
29149
29150 \begin_layout Itemize
29151 Declare the variables to be local
29152 \begin_inset LatexCommand \index{local variables}
29153
29154 \end_inset
29155
29156  whenever possible, especially loop control variables (induction).
29157 \end_layout
29158
29159 \begin_layout Itemize
29160 Have a look at the assembly listing to get a 
29161 \begin_inset Quotes sld
29162 \end_inset
29163
29164 feeling
29165 \begin_inset Quotes srd
29166 \end_inset
29167
29168  for the code generation.
29169 \end_layout
29170
29171 \begin_layout Section
29172 Porting code from or to other compilers
29173 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29174
29175 \end_inset
29176
29177
29178 \end_layout
29179
29180 \begin_layout Itemize
29181 check whether endianness of the compilers differs and adapt where needed.
29182 \end_layout
29183
29184 \begin_layout Itemize
29185 check the device specific header files
29186 \begin_inset LatexCommand \index{Header files}
29187
29188 \end_inset
29189
29190
29191 \begin_inset LatexCommand \index{Include files}
29192
29193 \end_inset
29194
29195  for compiler specific syntax.
29196  Eventually include the file <compiler.h
29197 \begin_inset LatexCommand \index{compiler.h (include file)}
29198
29199 \end_inset
29200
29201
29202 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29203
29204 \end_inset
29205
29206  to allow using common header files.
29207  (see f.e.
29208  cc2510fx.h 
29209 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29210
29211 \end_inset
29212
29213 ).
29214 \end_layout
29215
29216 \begin_layout Itemize
29217 check whether the startup code contains the correct initialization (watchdog,
29218  peripherals).
29219 \end_layout
29220
29221 \begin_layout Itemize
29222 check whether the sizes of short, int, long match.
29223 \end_layout
29224
29225 \begin_layout Itemize
29226 check if some 16 or 32 bit hardware registers require a specific addressing
29227  order (least significant or most significant byte first) and adapt if needed
29228  (
29229 \emph on
29230 first
29231 \emph default
29232  and 
29233 \emph on
29234 last
29235 \emph default
29236  relate to time and not to lower/upper memory location here, so this is
29237  
29238 \emph on
29239 not
29240 \emph default
29241  the same as endianness).
29242 \end_layout
29243
29244 \begin_layout Itemize
29245 check whether the keyword 
29246 \emph on
29247 volatile
29248 \emph default
29249  is used where needed.
29250  The compilers might differ in their optimization characteristics (as different
29251  versions of the same compiler might also use more clever optimizations
29252  this is good idea anyway).
29253  See section 
29254 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29255
29256 \end_inset
29257
29258 .
29259 \end_layout
29260
29261 \begin_layout Itemize
29262 check that the compilers are not told to supress warnings.
29263 \end_layout
29264
29265 \begin_layout Itemize
29266 check and convert compiler specific extensions (interrupts, memory areas,
29267  pragmas etc.).
29268 \end_layout
29269
29270 \begin_layout Itemize
29271 check for differences in type promotion.
29272  Especially check for math operations on 
29273 \family typewriter
29274 char
29275 \family default
29276  or 
29277 \family typewriter
29278 unsigned char
29279 \family default
29280  variables.
29281  For the sake of C99 compatibility SDCC will probably promote these to 
29282 \family typewriter
29283 int
29284 \family default
29285  more often than other compilers.
29286  Eventually insert explicit casts to 
29287 \family typewriter
29288 (char) 
29289 \family default
29290 or
29291 \family typewriter
29292  (unsigned char)
29293 \family default
29294 .
29295  Also check that the ~\InsetSpace ~
29296 operator
29297 \begin_inset LatexCommand \index{\~\/ Operator}
29298
29299 \end_inset
29300
29301  is not used on 
29302 \family typewriter
29303 bit
29304 \begin_inset LatexCommand \index{bit}
29305
29306 \end_inset
29307
29308
29309 \family default
29310  variables, use the !\InsetSpace ~
29311 operator instead.
29312  See sections 
29313 \begin_inset LatexCommand \ref{type promotion}
29314
29315 \end_inset
29316
29317  and 
29318 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29319
29320 \end_inset
29321
29322 .
29323 \end_layout
29324
29325 \begin_layout Itemize
29326 check the assembly code generated for interrupt routines (f.e.
29327  for calls to possibly non-reentrant library functions).
29328 \end_layout
29329
29330 \begin_layout Itemize
29331 check whether timing loops result in proper timing (or preferably consider
29332  a rewrite of the code with timer based delays instead).
29333 \end_layout
29334
29335 \begin_layout Itemize
29336 check for differences in printf parameters (some compilers push (va_arg
29337 \begin_inset LatexCommand \index{vararg, va\_arg}
29338
29339 \end_inset
29340
29341 ) char variables as 
29342 \family typewriter
29343 int
29344 \family default
29345  others push them as 
29346 \family typewriter
29347 char
29348 \family default
29349 .
29350  See section 
29351 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29352
29353 \end_inset
29354
29355 ).
29356 \end_layout
29357
29358 \begin_layout Itemize
29359 check the resulting memory map
29360 \begin_inset LatexCommand \index{Memory map}
29361
29362 \end_inset
29363
29364 .
29365  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29366 ly idata, pdata, xdata).
29367  Eventually check if unexpected library functions are included.
29368 \end_layout
29369
29370 \begin_layout Section
29371 Tools
29372 \begin_inset LatexCommand \index{Tools}
29373
29374 \end_inset
29375
29376  included in the distribution
29377 \end_layout
29378
29379 \begin_layout Standard
29380 \align left
29381 \begin_inset Tabular
29382 <lyxtabular version="3" rows="12" columns="3">
29383 <features>
29384 <column alignment="left" valignment="top" leftline="true" width="0pt">
29385 <column alignment="left" valignment="top" leftline="true" width="0pt">
29386 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29387 <row topline="true" bottomline="true">
29388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29389 \begin_inset Text
29390
29391 \begin_layout Standard
29392
29393 \series bold
29394 Name
29395 \end_layout
29396
29397 \end_inset
29398 </cell>
29399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29400 \begin_inset Text
29401
29402 \begin_layout Standard
29403
29404 \series bold
29405 Purpose
29406 \end_layout
29407
29408 \end_inset
29409 </cell>
29410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29411 \begin_inset Text
29412
29413 \begin_layout Standard
29414
29415 \series bold
29416 Directory
29417 \end_layout
29418
29419 \end_inset
29420 </cell>
29421 </row>
29422 <row topline="true">
29423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29424 \begin_inset Text
29425
29426 \begin_layout Standard
29427 uCsim
29428 \begin_inset LatexCommand \index{uCsim}
29429
29430 \end_inset
29431
29432
29433 \end_layout
29434
29435 \end_inset
29436 </cell>
29437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29438 \begin_inset Text
29439
29440 \begin_layout Standard
29441 Simulator for various architectures
29442 \end_layout
29443
29444 \end_inset
29445 </cell>
29446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29447 \begin_inset Text
29448
29449 \begin_layout Standard
29450 sdcc/sim/ucsim
29451 \end_layout
29452
29453 \end_inset
29454 </cell>
29455 </row>
29456 <row topline="true">
29457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29458 \begin_inset Text
29459
29460 \begin_layout Standard
29461 keil2sdcc.pl
29462 \end_layout
29463
29464 \end_inset
29465 </cell>
29466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29467 \begin_inset Text
29468
29469 \begin_layout Standard
29470 header file
29471 \begin_inset LatexCommand \index{Header files}
29472
29473 \end_inset
29474
29475
29476 \begin_inset LatexCommand \index{Include files}
29477
29478 \end_inset
29479
29480  conversion
29481 \end_layout
29482
29483 \end_inset
29484 </cell>
29485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29486 \begin_inset Text
29487
29488 \begin_layout Standard
29489 sdcc/support/scripts
29490 \end_layout
29491
29492 \end_inset
29493 </cell>
29494 </row>
29495 <row topline="true">
29496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29497 \begin_inset Text
29498
29499 \begin_layout Standard
29500 mh2h.c
29501 \end_layout
29502
29503 \end_inset
29504 </cell>
29505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29506 \begin_inset Text
29507
29508 \begin_layout Standard
29509 header file conversion
29510 \end_layout
29511
29512 \end_inset
29513 </cell>
29514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29515 \begin_inset Text
29516
29517 \begin_layout Standard
29518 sdcc/support/scripts
29519 \end_layout
29520
29521 \end_inset
29522 </cell>
29523 </row>
29524 <row topline="true">
29525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29526 \begin_inset Text
29527
29528 \begin_layout Standard
29529 as-gbz80
29530 \end_layout
29531
29532 \end_inset
29533 </cell>
29534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29535 \begin_inset Text
29536
29537 \begin_layout Standard
29538 Assembler
29539 \end_layout
29540
29541 \end_inset
29542 </cell>
29543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29544 \begin_inset Text
29545
29546 \begin_layout Standard
29547
29548 \family roman
29549 \series medium
29550 \shape up
29551 \size normal
29552 \emph off
29553 \bar no
29554 \noun off
29555 \color none
29556 sdcc/bin
29557 \end_layout
29558
29559 \end_inset
29560 </cell>
29561 </row>
29562 <row topline="true">
29563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29564 \begin_inset Text
29565
29566 \begin_layout Standard
29567 as-z80
29568 \end_layout
29569
29570 \end_inset
29571 </cell>
29572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29573 \begin_inset Text
29574
29575 \begin_layout Standard
29576 Assembler
29577 \end_layout
29578
29579 \end_inset
29580 </cell>
29581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29582 \begin_inset Text
29583
29584 \begin_layout Standard
29585
29586 \family roman
29587 \series medium
29588 \shape up
29589 \size normal
29590 \emph off
29591 \bar no
29592 \noun off
29593 \color none
29594 sdcc/bin
29595 \end_layout
29596
29597 \end_inset
29598 </cell>
29599 </row>
29600 <row topline="true">
29601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29602 \begin_inset Text
29603
29604 \begin_layout Standard
29605 asx8051
29606 \end_layout
29607
29608 \end_inset
29609 </cell>
29610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29611 \begin_inset Text
29612
29613 \begin_layout Standard
29614 Assembler
29615 \end_layout
29616
29617 \end_inset
29618 </cell>
29619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29620 \begin_inset Text
29621
29622 \begin_layout Standard
29623
29624 \family roman
29625 \series medium
29626 \shape up
29627 \size normal
29628 \emph off
29629 \bar no
29630 \noun off
29631 \color none
29632 sdcc/bin
29633 \end_layout
29634
29635 \end_inset
29636 </cell>
29637 </row>
29638 <row topline="true">
29639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29640 \begin_inset Text
29641
29642 \begin_layout Standard
29643 SDCDB
29644 \end_layout
29645
29646 \end_inset
29647 </cell>
29648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29649 \begin_inset Text
29650
29651 \begin_layout Standard
29652 Simulator
29653 \end_layout
29654
29655 \end_inset
29656 </cell>
29657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29658 \begin_inset Text
29659
29660 \begin_layout Standard
29661
29662 \family roman
29663 \series medium
29664 \shape up
29665 \size normal
29666 \emph off
29667 \bar no
29668 \noun off
29669 \color none
29670 sdcc/bin
29671 \end_layout
29672
29673 \end_inset
29674 </cell>
29675 </row>
29676 <row topline="true">
29677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29678 \begin_inset Text
29679
29680 \begin_layout Standard
29681 aslink
29682 \end_layout
29683
29684 \end_inset
29685 </cell>
29686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29687 \begin_inset Text
29688
29689 \begin_layout Standard
29690 Linker
29691 \end_layout
29692
29693 \end_inset
29694 </cell>
29695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29696 \begin_inset Text
29697
29698 \begin_layout Standard
29699
29700 \family roman
29701 \series medium
29702 \shape up
29703 \size normal
29704 \emph off
29705 \bar no
29706 \noun off
29707 \color none
29708 sdcc/bin
29709 \end_layout
29710
29711 \end_inset
29712 </cell>
29713 </row>
29714 <row topline="true">
29715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29716 \begin_inset Text
29717
29718 \begin_layout Standard
29719 link-z80
29720 \end_layout
29721
29722 \end_inset
29723 </cell>
29724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29725 \begin_inset Text
29726
29727 \begin_layout Standard
29728 Linker
29729 \end_layout
29730
29731 \end_inset
29732 </cell>
29733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29734 \begin_inset Text
29735
29736 \begin_layout Standard
29737
29738 \family roman
29739 \series medium
29740 \shape up
29741 \size normal
29742 \emph off
29743 \bar no
29744 \noun off
29745 \color none
29746 sdcc/bin
29747 \end_layout
29748
29749 \end_inset
29750 </cell>
29751 </row>
29752 <row topline="true">
29753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29754 \begin_inset Text
29755
29756 \begin_layout Standard
29757 link-gbz80
29758 \end_layout
29759
29760 \end_inset
29761 </cell>
29762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29763 \begin_inset Text
29764
29765 \begin_layout Standard
29766 Linker
29767 \end_layout
29768
29769 \end_inset
29770 </cell>
29771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29772 \begin_inset Text
29773
29774 \begin_layout Standard
29775
29776 \family roman
29777 \series medium
29778 \shape up
29779 \size normal
29780 \emph off
29781 \bar no
29782 \noun off
29783 \color none
29784 sdcc/bin
29785 \end_layout
29786
29787 \end_inset
29788 </cell>
29789 </row>
29790 <row topline="true" bottomline="true">
29791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29792 \begin_inset Text
29793
29794 \begin_layout Standard
29795 packihx
29796 \end_layout
29797
29798 \end_inset
29799 </cell>
29800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29801 \begin_inset Text
29802
29803 \begin_layout Standard
29804 Intel Hex packer 
29805 \begin_inset LatexCommand \index{packihx (tool)}
29806
29807 \end_inset
29808
29809
29810 \end_layout
29811
29812 \end_inset
29813 </cell>
29814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29815 \begin_inset Text
29816
29817 \begin_layout Standard
29818
29819 \family roman
29820 \series medium
29821 \shape up
29822 \size normal
29823 \emph off
29824 \bar no
29825 \noun off
29826 \color none
29827 sdcc/bin
29828 \end_layout
29829
29830 \end_inset
29831 </cell>
29832 </row>
29833 </lyxtabular>
29834
29835 \end_inset
29836
29837
29838 \newline
29839
29840 \end_layout
29841
29842 \begin_layout Section
29843 Documentation
29844 \begin_inset LatexCommand \index{Documentation}
29845
29846 \end_inset
29847
29848  included in the distribution
29849 \end_layout
29850
29851 \begin_layout Standard
29852 \align left
29853 \begin_inset Tabular
29854 <lyxtabular version="3" rows="10" columns="2">
29855 <features>
29856 <column alignment="block" valignment="top" leftline="true" width="40col%">
29857 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29858 <row topline="true" bottomline="true" endhead="true">
29859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29860 \begin_inset Text
29861
29862 \begin_layout Standard
29863
29864 \series bold
29865 Subject / Title
29866 \end_layout
29867
29868 \end_inset
29869 </cell>
29870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29871 \begin_inset Text
29872
29873 \begin_layout Standard
29874
29875 \series bold
29876 Filename / Where to get
29877 \end_layout
29878
29879 \end_inset
29880 </cell>
29881 </row>
29882 <row topline="true">
29883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29884 \begin_inset Text
29885
29886 \begin_layout Standard
29887 SDCC Compiler User Guide
29888 \end_layout
29889
29890 \end_inset
29891 </cell>
29892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29893 \begin_inset Text
29894
29895 \begin_layout Standard
29896 You're reading it right now
29897 \emph on
29898  \InsetSpace ~
29899 \InsetSpace ~
29900 \InsetSpace ~
29901
29902 \hfill
29903 online at:
29904 \emph default
29905
29906 \newline
29907
29908 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29909
29910 \end_inset
29911
29912
29913 \end_layout
29914
29915 \end_inset
29916 </cell>
29917 </row>
29918 <row topline="true">
29919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29920 \begin_inset Text
29921
29922 \begin_layout Standard
29923 Changelog of SDCC
29924 \end_layout
29925
29926 \end_inset
29927 </cell>
29928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29929 \begin_inset Text
29930
29931 \begin_layout Standard
29932 sdcc/Changelog
29933 \emph on
29934  \InsetSpace ~
29935 \InsetSpace ~
29936 \InsetSpace ~
29937
29938 \hfill
29939 online at:
29940 \emph default
29941
29942 \newline
29943
29944 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29945
29946 \end_inset
29947
29948
29949 \end_layout
29950
29951 \end_inset
29952 </cell>
29953 </row>
29954 <row topline="true">
29955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29956 \begin_inset Text
29957
29958 \begin_layout Standard
29959 ASXXXX
29960 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29961
29962 \end_inset
29963
29964
29965 \begin_inset LatexCommand \index{Assembler documentation}
29966
29967 \end_inset
29968
29969  Assemblers and
29970 \newline
29971 ASLINK
29972 \begin_inset LatexCommand \index{aslink}
29973
29974 \end_inset
29975
29976
29977 \begin_inset LatexCommand \index{Linker documentation}
29978
29979 \end_inset
29980
29981  Relocating Linker
29982 \end_layout
29983
29984 \end_inset
29985 </cell>
29986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29987 \begin_inset Text
29988
29989 \begin_layout Standard
29990 sdcc/as/doc/asxhtm.html 
29991 \emph on
29992 \InsetSpace ~
29993 \InsetSpace ~
29994 \InsetSpace ~
29995
29996 \hfill
29997 online at:
29998 \emph default
29999
30000 \newline
30001
30002 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30003
30004 \end_inset
30005
30006
30007 \end_layout
30008
30009 \end_inset
30010 </cell>
30011 </row>
30012 <row topline="true">
30013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30014 \begin_inset Text
30015
30016 \begin_layout Standard
30017 SDCC regression test
30018 \begin_inset LatexCommand \index{Regression test}
30019
30020 \end_inset
30021
30022
30023 \end_layout
30024
30025 \end_inset
30026 </cell>
30027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30028 \begin_inset Text
30029
30030 \begin_layout Standard
30031 sdcc/doc/test_suite_spec.pdf 
30032 \emph on
30033 \InsetSpace ~
30034 \InsetSpace ~
30035 \InsetSpace ~
30036
30037 \hfill
30038 online at:
30039 \emph default
30040
30041 \newline
30042
30043 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30044
30045 \end_inset
30046
30047
30048 \end_layout
30049
30050 \end_inset
30051 </cell>
30052 </row>
30053 <row topline="true">
30054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30055 \begin_inset Text
30056
30057 \begin_layout Standard
30058 Various notes
30059 \end_layout
30060
30061 \end_inset
30062 </cell>
30063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30064 \begin_inset Text
30065
30066 \begin_layout Standard
30067 sdcc/doc/* 
30068 \emph on
30069 \InsetSpace ~
30070 \InsetSpace ~
30071 \InsetSpace ~
30072
30073 \hfill
30074 online at:
30075 \emph default
30076
30077 \newline
30078
30079 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30080
30081 \end_inset
30082
30083
30084 \end_layout
30085
30086 \end_inset
30087 </cell>
30088 </row>
30089 <row topline="true">
30090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30091 \begin_inset Text
30092
30093 \begin_layout Standard
30094 Notes on debugging with SDCDB
30095 \begin_inset LatexCommand \index{SDCDB (debugger)}
30096
30097 \end_inset
30098
30099
30100 \end_layout
30101
30102 \end_inset
30103 </cell>
30104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30105 \begin_inset Text
30106
30107 \begin_layout Standard
30108 sdcc/debugger/README 
30109 \emph on
30110 \InsetSpace ~
30111 \InsetSpace ~
30112 \InsetSpace ~
30113
30114 \hfill
30115 online at
30116 \emph default
30117 :
30118 \newline
30119
30120 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30121
30122 \end_inset
30123
30124
30125 \end_layout
30126
30127 \end_inset
30128 </cell>
30129 </row>
30130 <row topline="true">
30131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30132 \begin_inset Text
30133
30134 \begin_layout Standard
30135 uCsim
30136 \begin_inset LatexCommand \index{uCsim}
30137
30138 \end_inset
30139
30140  Software simulator for microcontrollers
30141 \end_layout
30142
30143 \end_inset
30144 </cell>
30145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30146 \begin_inset Text
30147
30148 \begin_layout Standard
30149
30150 \family roman
30151 \series medium
30152 \shape up
30153 \size normal
30154 \emph off
30155 \bar no
30156 \noun off
30157 \color none
30158 sdcc/sim/ucsim/doc
30159 \family default
30160 \series default
30161 \shape default
30162 \size default
30163 \emph default
30164 \bar default
30165 \noun default
30166 /index.html 
30167 \emph on
30168 \InsetSpace ~
30169 \InsetSpace ~
30170 \InsetSpace ~
30171
30172 \hfill
30173 online at:
30174 \emph default
30175
30176 \newline
30177
30178 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30179
30180 \end_inset
30181
30182
30183 \end_layout
30184
30185 \end_inset
30186 </cell>
30187 </row>
30188 <row topline="true">
30189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30190 \begin_inset Text
30191
30192 \begin_layout Standard
30193 Temporary notes on the pic16
30194 \begin_inset LatexCommand \index{PIC16}
30195
30196 \end_inset
30197
30198  port
30199 \end_layout
30200
30201 \end_inset
30202 </cell>
30203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30204 \begin_inset Text
30205
30206 \begin_layout Standard
30207 sdcc/src/pic16/NOTES 
30208 \emph on
30209 \InsetSpace ~
30210 \InsetSpace ~
30211 \InsetSpace ~
30212
30213 \hfill
30214 online at:
30215 \newline
30216
30217 \emph default
30218
30219 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30220
30221 \end_inset
30222
30223
30224 \end_layout
30225
30226 \end_inset
30227 </cell>
30228 </row>
30229 <row topline="true" bottomline="true">
30230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30231 \begin_inset Text
30232
30233 \begin_layout Standard
30234 SDCC internal documentation (debugging file format)
30235 \end_layout
30236
30237 \end_inset
30238 </cell>
30239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30240 \begin_inset Text
30241
30242 \begin_layout Standard
30243 sdcc/doc/
30244 \family roman
30245 \series medium
30246 \shape up
30247 \size normal
30248 \emph off
30249 \bar no
30250 \noun off
30251 \color none
30252 cdbfileformat.pd
30253 \family default
30254 \series default
30255 \shape default
30256 \size default
30257 \emph default
30258 \bar default
30259 \noun default
30260 f
30261 \emph on
30262  \InsetSpace ~
30263 \InsetSpace ~
30264 \InsetSpace ~
30265
30266 \hfill
30267 online at:
30268 \emph default
30269
30270 \newline
30271
30272 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30273
30274 \end_inset
30275
30276
30277 \end_layout
30278
30279 \end_inset
30280 </cell>
30281 </row>
30282 </lyxtabular>
30283
30284 \end_inset
30285
30286
30287 \newline
30288
30289 \end_layout
30290
30291 \begin_layout Section
30292 Related open source tools
30293 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30294
30295 \end_inset
30296
30297
30298 \begin_inset LatexCommand \index{Related tools}
30299
30300 \end_inset
30301
30302
30303 \end_layout
30304
30305 \begin_layout Standard
30306 \align left
30307 \begin_inset Tabular
30308 <lyxtabular version="3" rows="14" columns="3">
30309 <features>
30310 <column alignment="left" valignment="top" leftline="true" width="0pt">
30311 <column alignment="block" valignment="top" leftline="true" width="30line%">
30312 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30313 <row topline="true" bottomline="true">
30314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30315 \begin_inset Text
30316
30317 \begin_layout Standard
30318
30319 \series bold
30320 Name
30321 \end_layout
30322
30323 \end_inset
30324 </cell>
30325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30326 \begin_inset Text
30327
30328 \begin_layout Standard
30329
30330 \series bold
30331 Purpose
30332 \end_layout
30333
30334 \end_inset
30335 </cell>
30336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30337 \begin_inset Text
30338
30339 \begin_layout Standard
30340
30341 \series bold
30342 Where to get
30343 \end_layout
30344
30345 \end_inset
30346 </cell>
30347 </row>
30348 <row topline="true">
30349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30350 \begin_inset Text
30351
30352 \begin_layout Standard
30353 gpsim
30354 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30355
30356 \end_inset
30357
30358
30359 \end_layout
30360
30361 \end_inset
30362 </cell>
30363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30364 \begin_inset Text
30365
30366 \begin_layout Standard
30367 PIC simulator
30368 \end_layout
30369
30370 \end_inset
30371 </cell>
30372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30373 \begin_inset Text
30374
30375 \begin_layout Standard
30376 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30377
30378 \end_inset
30379
30380
30381 \end_layout
30382
30383 \end_inset
30384 </cell>
30385 </row>
30386 <row topline="true">
30387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30388 \begin_inset Text
30389
30390 \begin_layout Standard
30391 gputils
30392 \begin_inset LatexCommand \index{gputils (pic tools)}
30393
30394 \end_inset
30395
30396
30397 \end_layout
30398
30399 \end_inset
30400 </cell>
30401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30402 \begin_inset Text
30403
30404 \begin_layout Standard
30405 GNU PIC utilities
30406 \end_layout
30407
30408 \end_inset
30409 </cell>
30410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30411 \begin_inset Text
30412
30413 \begin_layout Standard
30414 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30415
30416 \end_inset
30417
30418
30419 \end_layout
30420
30421 \end_inset
30422 </cell>
30423 </row>
30424 <row topline="true">
30425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30426 \begin_inset Text
30427
30428 \begin_layout Standard
30429 flP5
30430 \end_layout
30431
30432 \end_inset
30433 </cell>
30434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30435 \begin_inset Text
30436
30437 \begin_layout Standard
30438 PIC programmer
30439 \end_layout
30440
30441 \end_inset
30442 </cell>
30443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30444 \begin_inset Text
30445
30446 \begin_layout Standard
30447 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30448
30449 \end_inset
30450
30451
30452 \end_layout
30453
30454 \end_inset
30455 </cell>
30456 </row>
30457 <row topline="true">
30458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30459 \begin_inset Text
30460
30461 \begin_layout Standard
30462 ec2drv/newcdb
30463 \end_layout
30464
30465 \end_inset
30466 </cell>
30467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30468 \begin_inset Text
30469
30470 \begin_layout Standard
30471 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30472  (Unix only)
30473 \end_layout
30474
30475 \end_inset
30476 </cell>
30477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30478 \begin_inset Text
30479
30480 \begin_layout Standard
30481 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30482
30483 \end_inset
30484
30485
30486 \end_layout
30487
30488 \end_inset
30489 </cell>
30490 </row>
30491 <row topline="true">
30492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30493 \begin_inset Text
30494
30495 \begin_layout Standard
30496 indent
30497 \begin_inset LatexCommand \index{indent (source formatting tool)}
30498
30499 \end_inset
30500
30501
30502 \end_layout
30503
30504 \end_inset
30505 </cell>
30506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30507 \begin_inset Text
30508
30509 \begin_layout Standard
30510 Formats C source - Master of the white spaces
30511 \end_layout
30512
30513 \end_inset
30514 </cell>
30515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30516 \begin_inset Text
30517
30518 \begin_layout Standard
30519 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30520
30521 \end_inset
30522
30523
30524 \end_layout
30525
30526 \end_inset
30527 </cell>
30528 </row>
30529 <row topline="true">
30530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30531 \begin_inset Text
30532
30533 \begin_layout Standard
30534 srecord
30535 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30536
30537 \end_inset
30538
30539
30540 \end_layout
30541
30542 \end_inset
30543 </cell>
30544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30545 \begin_inset Text
30546
30547 \begin_layout Standard
30548 Object file conversion, checksumming, ...
30549 \end_layout
30550
30551 \end_inset
30552 </cell>
30553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30554 \begin_inset Text
30555
30556 \begin_layout Standard
30557 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30558
30559 \end_inset
30560
30561
30562 \end_layout
30563
30564 \end_inset
30565 </cell>
30566 </row>
30567 <row topline="true">
30568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30569 \begin_inset Text
30570
30571 \begin_layout Standard
30572 objdump
30573 \begin_inset LatexCommand \index{objdump (tool)}
30574
30575 \end_inset
30576
30577
30578 \end_layout
30579
30580 \end_inset
30581 </cell>
30582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30583 \begin_inset Text
30584
30585 \begin_layout Standard
30586 Object file conversion, ...
30587 \end_layout
30588
30589 \end_inset
30590 </cell>
30591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30592 \begin_inset Text
30593
30594 \begin_layout Standard
30595 Part of binutils (should be there anyway)
30596 \end_layout
30597
30598 \end_inset
30599 </cell>
30600 </row>
30601 <row topline="true">
30602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30603 \begin_inset Text
30604
30605 \begin_layout Standard
30606 cmon51
30607 \end_layout
30608
30609 \end_inset
30610 </cell>
30611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30612 \begin_inset Text
30613
30614 \begin_layout Standard
30615 8051 monitor (hex up-/download, single step, disassemble)
30616 \end_layout
30617
30618 \end_inset
30619 </cell>
30620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30621 \begin_inset Text
30622
30623 \begin_layout Standard
30624 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30625
30626 \end_inset
30627
30628
30629 \end_layout
30630
30631 \end_inset
30632 </cell>
30633 </row>
30634 <row topline="true">
30635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30636 \begin_inset Text
30637
30638 \begin_layout Standard
30639 doxygen
30640 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30641
30642 \end_inset
30643
30644
30645 \end_layout
30646
30647 \end_inset
30648 </cell>
30649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30650 \begin_inset Text
30651
30652 \begin_layout Standard
30653 Source code documentation system
30654 \end_layout
30655
30656 \end_inset
30657 </cell>
30658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30659 \begin_inset Text
30660
30661 \begin_layout Standard
30662 \begin_inset LatexCommand \url{http://www.doxygen.org}
30663
30664 \end_inset
30665
30666
30667 \end_layout
30668
30669 \end_inset
30670 </cell>
30671 </row>
30672 <row topline="true">
30673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30674 \begin_inset Text
30675
30676 \begin_layout Standard
30677 kdevelop
30678 \end_layout
30679
30680 \end_inset
30681 </cell>
30682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30683 \begin_inset Text
30684
30685 \begin_layout Standard
30686 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30687 \end_layout
30688
30689 \end_inset
30690 </cell>
30691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30692 \begin_inset Text
30693
30694 \begin_layout Standard
30695 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30696
30697 \end_inset
30698
30699
30700 \end_layout
30701
30702 \end_inset
30703 </cell>
30704 </row>
30705 <row topline="true">
30706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30707 \begin_inset Text
30708
30709 \begin_layout Standard
30710 paulmon
30711 \end_layout
30712
30713 \end_inset
30714 </cell>
30715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30716 \begin_inset Text
30717
30718 \begin_layout Standard
30719 8051 monitor (hex up-/download, single step, disassemble)
30720 \end_layout
30721
30722 \end_inset
30723 </cell>
30724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30725 \begin_inset Text
30726
30727 \begin_layout Standard
30728 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30729
30730 \end_inset
30731
30732
30733 \end_layout
30734
30735 \end_inset
30736 </cell>
30737 </row>
30738 <row topline="true">
30739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30740 \begin_inset Text
30741
30742 \begin_layout Standard
30743 splint
30744 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30745
30746 \end_inset
30747
30748
30749 \end_layout
30750
30751 \end_inset
30752 </cell>
30753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30754 \begin_inset Text
30755
30756 \begin_layout Standard
30757 Statically checks c sources (see 
30758 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30759
30760 \end_inset
30761
30762 )
30763 \end_layout
30764
30765 \end_inset
30766 </cell>
30767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30768 \begin_inset Text
30769
30770 \begin_layout Standard
30771 \begin_inset LatexCommand \url{http://www.splint.org}
30772
30773 \end_inset
30774
30775
30776 \end_layout
30777
30778 \end_inset
30779 </cell>
30780 </row>
30781 <row topline="true" bottomline="true">
30782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30783 \begin_inset Text
30784
30785 \begin_layout Standard
30786 ddd
30787 \begin_inset LatexCommand \index{DDD (debugger)}
30788
30789 \end_inset
30790
30791
30792 \end_layout
30793
30794 \end_inset
30795 </cell>
30796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30797 \begin_inset Text
30798
30799 \begin_layout Standard
30800 Debugger, serves nicely as GUI to SDCDB
30801 \begin_inset LatexCommand \index{SDCDB (debugger)}
30802
30803 \end_inset
30804
30805  (Unix only)
30806 \end_layout
30807
30808 \end_inset
30809 </cell>
30810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30811 \begin_inset Text
30812
30813 \begin_layout Standard
30814 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30815
30816 \end_inset
30817
30818
30819 \end_layout
30820
30821 \end_inset
30822 </cell>
30823 </row>
30824 </lyxtabular>
30825
30826 \end_inset
30827
30828
30829 \newline
30830
30831 \end_layout
30832
30833 \begin_layout Section
30834 Related documentation / recommended reading
30835 \end_layout
30836
30837 \begin_layout Standard
30838 \align left
30839 \begin_inset Tabular
30840 <lyxtabular version="3" rows="7" columns="3">
30841 <features>
30842 <column alignment="left" valignment="top" leftline="true" width="0pt">
30843 <column alignment="left" valignment="top" leftline="true" width="0">
30844 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30845 <row topline="true" bottomline="true">
30846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30847 \begin_inset Text
30848
30849 \begin_layout Standard
30850
30851 \series bold
30852 Name
30853 \end_layout
30854
30855 \end_inset
30856 </cell>
30857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30858 \begin_inset Text
30859
30860 \begin_layout Standard
30861
30862 \series bold
30863 Subject / Title
30864 \end_layout
30865
30866 \end_inset
30867 </cell>
30868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30869 \begin_inset Text
30870
30871 \begin_layout Standard
30872
30873 \series bold
30874 Where to get
30875 \end_layout
30876
30877 \end_inset
30878 </cell>
30879 </row>
30880 <row topline="true">
30881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30882 \begin_inset Text
30883
30884 \begin_layout Standard
30885
30886 \family roman
30887 \series medium
30888 \shape up
30889 \size normal
30890 \emph off
30891 \bar no
30892 \noun off
30893 \color none
30894 c-refcard.pdf
30895 \end_layout
30896
30897 \end_inset
30898 </cell>
30899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30900 \begin_inset Text
30901
30902 \begin_layout Standard
30903 C Reference Card
30904 \begin_inset LatexCommand \index{C Reference card}
30905
30906 \end_inset
30907
30908 , 2 pages
30909 \end_layout
30910
30911 \end_inset
30912 </cell>
30913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30914 \begin_inset Text
30915
30916 \begin_layout Standard
30917 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30918
30919 \end_inset
30920
30921
30922 \end_layout
30923
30924 \end_inset
30925 </cell>
30926 </row>
30927 <row topline="true">
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30929 \begin_inset Text
30930
30931 \begin_layout Standard
30932 c-faq
30933 \end_layout
30934
30935 \end_inset
30936 </cell>
30937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30938 \begin_inset Text
30939
30940 \begin_layout Standard
30941 C-FAQ
30942 \begin_inset LatexCommand \index{C FAQ}
30943
30944 \end_inset
30945
30946
30947 \end_layout
30948
30949 \end_inset
30950 </cell>
30951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30952 \begin_inset Text
30953
30954 \begin_layout Standard
30955 \begin_inset LatexCommand \url{http://www.c-faq.com}
30956
30957 \end_inset
30958
30959
30960 \end_layout
30961
30962 \end_inset
30963 </cell>
30964 </row>
30965 <row topline="true">
30966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30967 \begin_inset Text
30968
30969 \begin_layout Standard
30970 ISO/IEC 9899:TC2
30971 \end_layout
30972
30973 \end_inset
30974 </cell>
30975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30976 \begin_inset Text
30977
30978 \begin_layout Standard
30979 \begin_inset Quotes sld
30980 \end_inset
30981
30982 C-Standard
30983 \begin_inset Quotes srd
30984 \end_inset
30985
30986
30987 \end_layout
30988
30989 \end_inset
30990 </cell>
30991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30992 \begin_inset Text
30993
30994 \begin_layout Standard
30995
30996 \size footnotesize
30997 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30998
30999 \end_inset
31000
31001
31002 \end_layout
31003
31004 \end_inset
31005 </cell>
31006 </row>
31007 <row topline="true">
31008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31009 \begin_inset Text
31010
31011 \begin_layout Standard
31012 ISO/IEC DTR 18037
31013 \end_layout
31014
31015 \end_inset
31016 </cell>
31017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31018 \begin_inset Text
31019
31020 \begin_layout Standard
31021 \begin_inset Quotes sld
31022 \end_inset
31023
31024 Extensions for Embedded C
31025 \begin_inset Quotes srd
31026 \end_inset
31027
31028
31029 \end_layout
31030
31031 \end_inset
31032 </cell>
31033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31034 \begin_inset Text
31035
31036 \begin_layout Standard
31037
31038 \size footnotesize
31039 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31040
31041 \end_inset
31042
31043
31044 \end_layout
31045
31046 \end_inset
31047 </cell>
31048 </row>
31049 <row topline="true">
31050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31051 \begin_inset Text
31052
31053 \begin_layout Standard
31054
31055 \end_layout
31056
31057 \end_inset
31058 </cell>
31059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31060 \begin_inset Text
31061
31062 \begin_layout Standard
31063 Latest datasheet of target CPU
31064 \end_layout
31065
31066 \end_inset
31067 </cell>
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31069 \begin_inset Text
31070
31071 \begin_layout Standard
31072 vendor
31073 \end_layout
31074
31075 \end_inset
31076 </cell>
31077 </row>
31078 <row topline="true" bottomline="true">
31079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31080 \begin_inset Text
31081
31082 \begin_layout Standard
31083
31084 \end_layout
31085
31086 \end_inset
31087 </cell>
31088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31089 \begin_inset Text
31090
31091 \begin_layout Standard
31092 Revision history of datasheet
31093 \end_layout
31094
31095 \end_inset
31096 </cell>
31097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31098 \begin_inset Text
31099
31100 \begin_layout Standard
31101 vendor
31102 \end_layout
31103
31104 \end_inset
31105 </cell>
31106 </row>
31107 </lyxtabular>
31108
31109 \end_inset
31110
31111
31112 \newline
31113
31114 \end_layout
31115
31116 \begin_layout Section
31117 Application notes specifically for SDCC
31118 \end_layout
31119
31120 \begin_layout Standard
31121 SDCC makes no claims about the completeness of this list and about up-to-datenes
31122 s or correctness of the application notes
31123 \begin_inset LatexCommand \index{Application notes}
31124
31125 \end_inset
31126
31127 .
31128 \end_layout
31129
31130 \begin_layout Standard
31131 \align left
31132
31133 \size footnotesize
31134 \begin_inset Tabular
31135 <lyxtabular version="3" rows="7" columns="3">
31136 <features>
31137 <column alignment="block" valignment="top" leftline="true" width="17col%">
31138 <column alignment="block" valignment="top" leftline="true" width="27col%">
31139 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31140 <row topline="true" bottomline="true">
31141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31142 \begin_inset Text
31143
31144 \begin_layout Standard
31145
31146 \series bold
31147 \size footnotesize
31148 Vendor
31149 \end_layout
31150
31151 \end_inset
31152 </cell>
31153 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31154 \begin_inset Text
31155
31156 \begin_layout Standard
31157
31158 \series bold
31159 \size footnotesize
31160 Subject / Title
31161 \end_layout
31162
31163 \end_inset
31164 </cell>
31165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31166 \begin_inset Text
31167
31168 \begin_layout Standard
31169
31170 \series bold
31171 \size footnotesize
31172 Where to get
31173 \end_layout
31174
31175 \end_inset
31176 </cell>
31177 </row>
31178 <row topline="true">
31179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31180 \begin_inset Text
31181
31182 \begin_layout Standard
31183
31184 \size footnotesize
31185 Maxim / Dallas
31186 \end_layout
31187
31188 \end_inset
31189 </cell>
31190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31191 \begin_inset Text
31192
31193 \begin_layout Standard
31194
31195 \size footnotesize
31196 Using the SDCC Compiler for the DS80C400
31197 \begin_inset LatexCommand \index{DS80C400}
31198
31199 \end_inset
31200
31201
31202 \end_layout
31203
31204 \end_inset
31205 </cell>
31206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31207 \begin_inset Text
31208
31209 \begin_layout Standard
31210
31211 \size footnotesize
31212 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31213
31214 \end_inset
31215
31216
31217 \end_layout
31218
31219 \end_inset
31220 </cell>
31221 </row>
31222 <row topline="true">
31223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31224 \begin_inset Text
31225
31226 \begin_layout Standard
31227
31228 \size footnotesize
31229 Maxim / Dallas
31230 \end_layout
31231
31232 \end_inset
31233 </cell>
31234 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31235 \begin_inset Text
31236
31237 \begin_layout Standard
31238
31239 \size footnotesize
31240 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31241 \begin_inset LatexCommand \index{DS89C4x0}
31242
31243 \end_inset
31244
31245  Family of Microcontrollers
31246 \end_layout
31247
31248 \end_inset
31249 </cell>
31250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31251 \begin_inset Text
31252
31253 \begin_layout Standard
31254
31255 \size footnotesize
31256 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31257
31258 \end_inset
31259
31260
31261 \end_layout
31262
31263 \end_inset
31264 </cell>
31265 </row>
31266 <row topline="true">
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31268 \begin_inset Text
31269
31270 \begin_layout Standard
31271
31272 \size footnotesize
31273 Silicon Laboratories / Cygnal
31274 \end_layout
31275
31276 \end_inset
31277 </cell>
31278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31279 \begin_inset Text
31280
31281 \begin_layout Standard
31282
31283 \size footnotesize
31284 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31285 \begin_inset LatexCommand \index{IDE}
31286
31287 \end_inset
31288
31289
31290 \end_layout
31291
31292 \end_inset
31293 </cell>
31294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31295 \begin_inset Text
31296
31297 \begin_layout Standard
31298
31299 \size footnotesize
31300 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31301
31302 \end_inset
31303
31304
31305 \end_layout
31306
31307 \end_inset
31308 </cell>
31309 </row>
31310 <row topline="true">
31311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31312 \begin_inset Text
31313
31314 \begin_layout Standard
31315
31316 \size footnotesize
31317 Ramtron / Goal Semiconductor
31318 \end_layout
31319
31320 \end_inset
31321 </cell>
31322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31323 \begin_inset Text
31324
31325 \begin_layout Standard
31326
31327 \size footnotesize
31328 Interfacing SDCC to Syn and Textpad
31329 \end_layout
31330
31331 \end_inset
31332 </cell>
31333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31334 \begin_inset Text
31335
31336 \begin_layout Standard
31337
31338 \size footnotesize
31339 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31340
31341 \end_inset
31342
31343
31344 \end_layout
31345
31346 \end_inset
31347 </cell>
31348 </row>
31349 <row topline="true">
31350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31351 \begin_inset Text
31352
31353 \begin_layout Standard
31354
31355 \size footnotesize
31356 Ramtron / Goal Semiconductor
31357 \end_layout
31358
31359 \end_inset
31360 </cell>
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31362 \begin_inset Text
31363
31364 \begin_layout Standard
31365
31366 \size footnotesize
31367 Installing and Configuring SDCC and Crimson Editor 
31368 \end_layout
31369
31370 \end_inset
31371 </cell>
31372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31373 \begin_inset Text
31374
31375 \begin_layout Standard
31376
31377 \size footnotesize
31378 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31379
31380 \end_inset
31381
31382
31383 \end_layout
31384
31385 \end_inset
31386 </cell>
31387 </row>
31388 <row topline="true" bottomline="true">
31389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31390 \begin_inset Text
31391
31392 \begin_layout Standard
31393
31394 \size footnotesize
31395 Texas Instruments
31396 \end_layout
31397
31398 \end_inset
31399 </cell>
31400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31401 \begin_inset Text
31402
31403 \begin_layout Standard
31404
31405 \size footnotesize
31406 MSC12xx Programming with SDCC
31407 \end_layout
31408
31409 \end_inset
31410 </cell>
31411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31412 \begin_inset Text
31413
31414 \begin_layout Standard
31415
31416 \size footnotesize
31417 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31418
31419 \end_inset
31420
31421
31422 \end_layout
31423
31424 \end_inset
31425 </cell>
31426 </row>
31427 </lyxtabular>
31428
31429 \end_inset
31430
31431
31432 \end_layout
31433
31434 \begin_layout Section
31435 Some Questions
31436 \end_layout
31437
31438 \begin_layout Standard
31439 Some questions answered, some pointers given - it might be time to in turn
31440  ask 
31441 \emph on
31442 you
31443 \emph default
31444  some questions: 
31445 \end_layout
31446
31447 \begin_layout Itemize
31448 can you solve your project with the selected microcontroller? Would you
31449  find out early or rather late that your target is too small/slow/whatever?
31450  Can you switch to a slightly better device if it doesn't fit?
31451 \end_layout
31452
31453 \begin_layout Itemize
31454 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31455  and/or another programming language be more adequate? Would an operating
31456  system on the target device help?
31457 \end_layout
31458
31459 \begin_layout Itemize
31460 if you solved the problem, will the marketing department be happy?
31461 \end_layout
31462
31463 \begin_layout Itemize
31464 if the marketing department is happy, will customers be happy?
31465 \end_layout
31466
31467 \begin_layout Itemize
31468 if you're the project manager, marketing department and maybe even the customer
31469  in one person, have you tried to see the project from the outside?
31470 \end_layout
31471
31472 \begin_layout Itemize
31473 is the project done if you think it is done? Or is just that other interface/pro
31474 tocol/feature/configuration/option missing? How about website, manual(s),
31475  internationali(z|s)ation, packaging, labels, 2nd source for components,
31476  electromagnetic compatability/interference, documentation for production,
31477  production test software, update mechanism, patent issues?
31478 \end_layout
31479
31480 \begin_layout Itemize
31481 is your project adequately positioned in that magic triangle: fame, fortune,
31482  fun?
31483 \end_layout
31484
31485 \begin_layout Standard
31486 Maybe not all answers to these questions are known and some answers may
31487  even be 
31488 \emph on
31489 no
31490 \emph default
31491 , nevertheless knowing these questions may help you to avoid burnout
31492 \begin_inset Foot
31493 status open
31494
31495 \begin_layout Standard
31496 burnout is bad for electronic devices, programmers and motorcycle tyres
31497 \end_layout
31498
31499 \end_inset
31500
31501 .
31502  Chances are you didn't want to hear some of them...
31503 \end_layout
31504
31505 \begin_layout Chapter
31506 Support
31507 \begin_inset LatexCommand \index{Support}
31508
31509 \end_inset
31510
31511
31512 \end_layout
31513
31514 \begin_layout Standard
31515 SDCC has grown to be a large project.
31516  The compiler alone (without the preprocessor, assembler and linker) is
31517  well over 150,000 lines of code (blank stripped).
31518  The open source nature of this project is a key to its continued growth
31519  and support.
31520  You gain the benefit and support of many active software developers and
31521  end users.
31522  Is SDCC perfect? No, that's why we need your help.
31523  The developers take pride in fixing reported bugs.
31524  You can help by reporting the bugs and helping other SDCC users.
31525  There are lots of ways to contribute, and we encourage you to take part
31526  in making SDCC a great software package.
31527  
31528 \end_layout
31529
31530 \begin_layout Standard
31531 The SDCC project is hosted on the SDCC sourceforge site at 
31532 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31533
31534 \end_inset
31535
31536 .
31537  You'll find the complete set of mailing lists
31538 \begin_inset LatexCommand \index{Mailing list(s)}
31539
31540 \end_inset
31541
31542 , forums, bug reporting system, patch submission
31543 \begin_inset LatexCommand \index{Patch submission}
31544
31545 \end_inset
31546
31547  system, download
31548 \begin_inset LatexCommand \index{download}
31549
31550 \end_inset
31551
31552  area and Subversion code repository
31553 \begin_inset LatexCommand \index{Subversion code repository}
31554
31555 \end_inset
31556
31557  there.
31558 \end_layout
31559
31560 \begin_layout Section
31561 Reporting Bugs
31562 \begin_inset LatexCommand \index{Bug reporting}
31563
31564 \end_inset
31565
31566
31567 \begin_inset LatexCommand \index{Reporting bugs}
31568
31569 \end_inset
31570
31571
31572 \end_layout
31573
31574 \begin_layout Standard
31575 The recommended way of reporting bugs is using the infrastructure of the
31576  sourceforge site.
31577  You can follow the status of bug reports there and have an overview about
31578  the known bugs.
31579 \end_layout
31580
31581 \begin_layout Standard
31582 Bug reports are automatically forwarded to the developer mailing list and
31583  will be fixed ASAP.
31584  When reporting a bug, it is very useful to include a small test program
31585  (the smaller the better) which reproduces the problem.
31586  If you can isolate the problem by looking at the generated assembly code,
31587  this can be very helpful.
31588  Compiling your program with the -
31589 \begin_inset ERT
31590 status collapsed
31591
31592 \begin_layout Standard
31593
31594
31595 \backslash
31596 /
31597 \end_layout
31598
31599 \end_inset
31600
31601 -dumpall
31602 \begin_inset LatexCommand \index{-\/-dumpall}
31603
31604 \end_inset
31605
31606  option can sometimes be useful in locating optimization problems.
31607  When reporting a bug please make sure you:
31608 \end_layout
31609
31610 \begin_layout Enumerate
31611 Attach the code you are compiling with SDCC.
31612  
31613 \end_layout
31614
31615 \begin_layout Enumerate
31616 Specify the exact command you use to run SDCC, or attach your Makefile.
31617  
31618 \end_layout
31619
31620 \begin_layout Enumerate
31621 Specify the SDCC version (type "
31622 \family sans
31623 \series bold
31624 sdcc -v
31625 \family default
31626 \series default
31627 "), your platform, and operating system.
31628  
31629 \end_layout
31630
31631 \begin_layout Enumerate
31632 Provide an exact copy of any error message or incorrect output.
31633  
31634 \end_layout
31635
31636 \begin_layout Enumerate
31637 Put something meaningful in the subject of your message.
31638 \end_layout
31639
31640 \begin_layout Standard
31641 Please attempt to include these 5 important parts, as applicable, in all
31642  requests for support or when reporting any problems or bugs with SDCC.
31643  Though this will make your message lengthy, it will greatly improve your
31644  chance that SDCC users and developers will be able to help you.
31645  Some SDCC developers are frustrated by bug reports without code provided
31646  that they can use to reproduce and ultimately fix the problem, so please
31647  be sure to provide sample code if you are reporting a bug! 
31648 \end_layout
31649
31650 \begin_layout Standard
31651 Please have a short check that you are using a recent version of SDCC and
31652  the bug is not yet known.
31653  This is the link for reporting bugs: 
31654 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31655
31656 \end_inset
31657
31658 .
31659  With SDCC on average having more than 200 downloads
31660 \begin_inset LatexCommand \index{download}
31661
31662 \end_inset
31663
31664  on sourceforge per day
31665 \begin_inset Foot
31666 status open
31667
31668 \begin_layout Standard
31669 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31670  between 2002 and 2005.
31671  This does not include other methods of distribution.
31672 \end_layout
31673
31674 \end_inset
31675
31676  there must be some users.
31677  So it's not exactly easy to find a new bug.
31678  If you find one we need it: 
31679 \emph on
31680 reporting bugs is good
31681 \emph default
31682 .
31683 \end_layout
31684
31685 \begin_layout Section
31686 Requesting Features
31687 \begin_inset LatexCommand \label{sub:Requesting-Features}
31688
31689 \end_inset
31690
31691
31692 \begin_inset LatexCommand \index{Feature request}
31693
31694 \end_inset
31695
31696
31697 \begin_inset LatexCommand \index{Requesting features}
31698
31699 \end_inset
31700
31701
31702 \end_layout
31703
31704 \begin_layout Standard
31705 Like bug reports feature requests are forwarded to the developer mailing
31706  list.
31707  This is the link for requesting features: 
31708 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31709
31710 \end_inset
31711
31712 .
31713 \end_layout
31714
31715 \begin_layout Section
31716 Submitting patches
31717 \end_layout
31718
31719 \begin_layout Standard
31720 Like bug reports contributed patches are forwarded to the developer mailing
31721  list.
31722  This is the link for submitting patches
31723 \begin_inset LatexCommand \index{Patch submission}
31724
31725 \end_inset
31726
31727
31728 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31729
31730 \end_inset
31731
31732 .
31733 \end_layout
31734
31735 \begin_layout Standard
31736 You need to specify some parameters to the 
31737 \family typewriter
31738 diff
31739 \family default
31740  command for the patches to be useful.
31741  If you modified more than one file a patch created f.e.
31742  with 
31743 \family sans
31744 \series bold
31745
31746 \begin_inset Quotes sld
31747 \end_inset
31748
31749 diff -Naur unmodified_directory modified_directory >my_changes.patch
31750 \begin_inset Quotes srd
31751 \end_inset
31752
31753
31754 \family default
31755 \series default
31756  will be fine, otherwise 
31757 \family sans
31758 \series bold
31759
31760 \begin_inset Quotes sld
31761 \end_inset
31762
31763 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31764 \begin_inset Quotes srd
31765 \end_inset
31766
31767
31768 \series default
31769  
31770 \family default
31771 will do.
31772 \end_layout
31773
31774 \begin_layout Section
31775 Getting Help
31776 \end_layout
31777
31778 \begin_layout Standard
31779 These links should take you directly to the 
31780 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31781
31782 \end_inset
31783
31784
31785 \begin_inset Foot
31786 status open
31787
31788 \begin_layout Standard
31789 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31790  automated messages (mid 2003)
31791 \end_layout
31792
31793 \end_inset
31794
31795  and the 
31796 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31797
31798 \end_inset
31799
31800 , lists
31801 \begin_inset LatexCommand \index{Mailing list(s)}
31802
31803 \end_inset
31804
31805  and forums are archived and searchable so if you are lucky someone already
31806  had a similar problem.
31807  While mails to the lists themselves are delivered promptly their web front
31808  end on sourceforge sometimes shows a severe time lag (up to several weeks),
31809  if you're seriously using SDCC please consider subscribing to the lists.
31810 \end_layout
31811
31812 \begin_layout Section
31813 ChangeLog
31814 \end_layout
31815
31816 \begin_layout Standard
31817 You can follow the status of the Subversion version
31818 \begin_inset LatexCommand \index{version}
31819
31820 \end_inset
31821
31822  of SDCC by watching the Changelog
31823 \begin_inset LatexCommand \index{Changelog}
31824
31825 \end_inset
31826
31827  in the Subversion repository
31828 \size footnotesize
31829  
31830 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31831
31832 \end_inset
31833
31834 .
31835 \end_layout
31836
31837 \begin_layout Section
31838 Subversion Source Code Repository
31839 \end_layout
31840
31841 \begin_layout Standard
31842 The output of 
31843 \family sans
31844 \series bold
31845 sdcc --version
31846 \family default
31847 \series default
31848  or the filenames of the snapshot versions of SDCC include date and its
31849  Subversion
31850 \begin_inset LatexCommand \index{Subversion code repository}
31851
31852 \end_inset
31853
31854  number.
31855  Subversion allows to download the source of recent or previous versions
31856  
31857 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31858
31859 \end_inset
31860
31861  (by number or by date).
31862  An on-line source code browser and detailled instructions are also available
31863  there.
31864  SDCC versions starting from 1999 up to now are available (currently the
31865  versions prior to the conversion from cvs
31866 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31867
31868 \end_inset
31869
31870  to Subversion (April 2006) are either by accessible by Subversion or by
31871  cvs).
31872 \end_layout
31873
31874 \begin_layout Section
31875 Release policy
31876 \begin_inset LatexCommand \index{Release policy}
31877
31878 \end_inset
31879
31880
31881 \end_layout
31882
31883 \begin_layout Standard
31884 Historically there often were long delays between official releases and
31885  the sourceforge download area tends to get not updated at all.
31886  Excuses in the past might have referred to problems with live range analysis,
31887  but as this was fixed a while ago, the current problem is that another
31888  excuse has to be found.
31889  Kidding aside, we have to get better there! On the other hand there are
31890  daily snapshots available at 
31891 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31892
31893 \end_inset
31894
31895 , and you can always build the very last version (hopefully with many bugs
31896  fixed, and features added) from the source code available at 
31897 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31898
31899 \end_inset
31900
31901 .
31902  A release wiki
31903 \begin_inset LatexCommand \index{wiki}
31904
31905 \end_inset
31906
31907
31908 \begin_inset LatexCommand \index{Release wiki}
31909
31910 \end_inset
31911
31912  at 
31913 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31914
31915 \end_inset
31916
31917  also holds some information about past and future releases.
31918 \end_layout
31919
31920 \begin_layout Section
31921 Examples
31922 \begin_inset LatexCommand \index{Examples}
31923
31924 \end_inset
31925
31926
31927 \end_layout
31928
31929 \begin_layout Standard
31930 You'll find some small examples in the directory 
31931 \emph on
31932 sdcc/device/examples/.
31933  
31934 \emph default
31935 More examples and libraries are available at
31936 \emph on
31937  The SDCC Open Knowledge Resource 
31938 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31939
31940 \end_inset
31941
31942  
31943 \emph default
31944 web site or at 
31945 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31946
31947 \end_inset
31948
31949 .
31950 \end_layout
31951
31952 \begin_layout Standard
31953 \begin_inset Note Note
31954 status collapsed
31955
31956 \begin_layout Standard
31957 I did insert a reference to Paul's web site here although it seems rather
31958  dedicated to a specific 8032 board (I think it's okay because it f.e.
31959  shows LCD/Harddisc interface and has a free 8051 monitor.
31960  Independent 8032 board vendors face hard competition of heavily subsidized
31961  development boards anyway).
31962 \end_layout
31963
31964 \begin_layout Standard
31965 Maybe we should include some links to real world applications.
31966  Preferably pointer to pointers (one for each architecture) so this stays
31967  manageable here?
31968 \end_layout
31969
31970 \end_inset
31971
31972
31973 \end_layout
31974
31975 \begin_layout Section
31976 Quality control
31977 \begin_inset LatexCommand \label{sec:Quality-control}
31978
31979 \end_inset
31980
31981
31982 \begin_inset LatexCommand \index{Quality control}
31983
31984 \end_inset
31985
31986
31987 \end_layout
31988
31989 \begin_layout Standard
31990 The compiler is passed through snaphot build compile and build checks.
31991  The so called 
31992 \shape italic
31993 regression tests
31994 \shape default
31995
31996 \begin_inset LatexCommand \index{Regression test}
31997
31998 \end_inset
31999
32000  check that SDCC itself compiles flawlessly on several host platforms (i386,
32001  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
32002  the quality of the code generated by SDCC by running the code for several
32003  target platforms through simulators.
32004  The regression test suite comprises more than 100 files which expand to
32005  more than 500 test cases which include more than 4500 tests.
32006  The results of these tests are published daily on SDCC's snapshot page
32007  (click on the red or green symbols on the right side of 
32008 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32009
32010 \end_inset
32011
32012 ).
32013 \end_layout
32014
32015 \begin_layout Standard
32016 There is a separate document 
32017 \shape italic
32018 test_suite.pdf 
32019 \begin_inset LatexCommand \index{Test suite}
32020
32021 \end_inset
32022
32023
32024 \shape default
32025  
32026 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32027
32028 \end_inset
32029
32030  about the regression test suite.
32031 \end_layout
32032
32033 \begin_layout Standard
32034 You'll find the test code in the directory 
32035 \shape italic
32036 sdcc/support/regression
32037 \shape default
32038 .
32039  You can run these tests manually by running 
32040 \family sans
32041 make
32042 \family default
32043  in this directory (or f.e.
32044  
32045 \family sans
32046 \series bold
32047
32048 \begin_inset Quotes sld
32049 \end_inset
32050
32051 make test-mcs51
32052 \begin_inset Quotes srd
32053 \end_inset
32054
32055
32056 \family default
32057 \series default
32058  if you don't want to run the complete tests).
32059  The test code might also be interesting if you want to look for examples
32060 \begin_inset LatexCommand \index{Examples}
32061
32062 \end_inset
32063
32064  checking corner cases of SDCC or if you plan to submit patches
32065 \begin_inset LatexCommand \index{Patch submission}
32066
32067 \end_inset
32068
32069 .
32070 \end_layout
32071
32072 \begin_layout Standard
32073 The 14bit pic port uses a different set of regression tests 
32074 \begin_inset LatexCommand \index{Regression test (PIC14)}
32075
32076 \end_inset
32077
32078 , you'll find them in the directory 
32079 \shape italic
32080 sdcc/src/regression
32081 \shape default
32082 .
32083 \end_layout
32084
32085 \begin_layout Section
32086 Use of SDCC in Education
32087 \end_layout
32088
32089 \begin_layout Standard
32090 In short: 
32091 \emph on
32092 highly
32093 \emph default
32094  encouraged
32095 \begin_inset Foot
32096 status open
32097
32098 \begin_layout Standard
32099 the phrase "use in education" might evoke the association "
32100 \emph on
32101 only
32102 \emph default
32103  fit for use in education".
32104  This connotation is not intended but nevertheless risked as the licensing
32105  of SDCC makes it difficult to offer educational discounts
32106 \end_layout
32107
32108 \end_inset
32109
32110 .
32111  If your rationales are to:
32112 \end_layout
32113
32114 \begin_layout Enumerate
32115 give students a chance to understand the 
32116 \emph on
32117 complete
32118 \emph default
32119  steps of code generation
32120 \end_layout
32121
32122 \begin_layout Enumerate
32123 have a curriculum that can be extended for years.
32124  Then you could use an fpga board as target and your curriculum will seamlessly
32125  extend from logic synthesis (
32126 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32127
32128 \end_inset
32129
32130
32131 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32132
32133 \end_inset
32134
32135 ), over assembly programming, to C to FPGA compilers (
32136 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32137
32138 \end_inset
32139
32140 ) and to C.
32141 \end_layout
32142
32143 \begin_layout Enumerate
32144 be able to insert excursions about skills like using a revision control
32145  system, submitting/applying patches, using a type-setting (as opposed to
32146  word-processing) engine LyX/LaTeX, using 
32147 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32148
32149 \end_inset
32150
32151 , following some 
32152 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32153
32154 \end_inset
32155
32156 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32157  Source Software, CPU simulation, compiler regression tests
32158 \begin_inset LatexCommand \index{Regression test}
32159
32160 \end_inset
32161
32162 .
32163  
32164 \newline
32165 And if there should be a shortage of ideas then you can always point students
32166  to the ever-growing feature request list 
32167 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32168
32169 \end_inset
32170
32171 .
32172 \end_layout
32173
32174 \begin_layout Enumerate
32175 not tie students to a specific host platform and instead allow them to use
32176  a host platform of 
32177 \emph on
32178 their
32179 \emph default
32180  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
32181  eventually 
32182 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32183
32184 \end_inset
32185
32186 )
32187 \end_layout
32188
32189 \begin_layout Enumerate
32190 not encourage students to use illegal copies of educational software
32191 \end_layout
32192
32193 \begin_layout Enumerate
32194 be immune to licensing/availability/price changes of the chosen tool chain
32195 \end_layout
32196
32197 \begin_layout Enumerate
32198 be able to change to a new target platform without having to adopt a new
32199  tool chain
32200 \end_layout
32201
32202 \begin_layout Enumerate
32203 have complete control over and insight into the tool chain
32204 \end_layout
32205
32206 \begin_layout Enumerate
32207 make your students aware about the pros and cons of open source software
32208  development
32209 \end_layout
32210
32211 \begin_layout Enumerate
32212 give back to the public as you are probably at least partially publically
32213  funded
32214 \end_layout
32215
32216 \begin_layout Enumerate
32217 give students a chance to publically prove their skills and to possibly
32218  see a world wide impact
32219 \end_layout
32220
32221 \begin_layout Standard
32222 then SDCC is probably among the first choices.
32223  Well, probably SDCC might be the only choice.
32224 \newpage
32225
32226 \end_layout
32227
32228 \begin_layout Chapter
32229 SDCC Technical Data
32230 \end_layout
32231
32232 \begin_layout Section
32233 Optimizations
32234 \begin_inset LatexCommand \index{Optimizations}
32235
32236 \end_inset
32237
32238
32239 \end_layout
32240
32241 \begin_layout Standard
32242 SDCC performs a host of standard optimizations in addition to some MCU specific
32243  optimizations.
32244  
32245 \end_layout
32246
32247 \begin_layout Subsection
32248 Sub-expression Elimination
32249 \begin_inset LatexCommand \index{Subexpression elimination}
32250
32251 \end_inset
32252
32253
32254 \end_layout
32255
32256 \begin_layout Standard
32257 The compiler does local and 
32258 \emph on
32259 g
32260 \emph default
32261 lobal 
32262 \emph on
32263 c
32264 \emph default
32265 ommon 
32266 \emph on
32267 s
32268 \emph default
32269 ubexpression 
32270 \emph on
32271 e
32272 \emph default
32273 limination, e.g.: 
32274 \end_layout
32275
32276 \begin_layout Verse
32277
32278 \family typewriter
32279 i = x + y + 1; 
32280 \newline
32281 j = x + y;
32282 \end_layout
32283
32284 \begin_layout Standard
32285 will be translated to
32286 \end_layout
32287
32288 \begin_layout Verse
32289
32290 \family typewriter
32291 iTemp = x + y; 
32292 \newline
32293 i = iTemp + 1; 
32294 \newline
32295 j = iTemp;
32296 \end_layout
32297
32298 \begin_layout Standard
32299 Some subexpressions are not as obvious as the above example, e.g.:
32300 \end_layout
32301
32302 \begin_layout Verse
32303
32304 \family typewriter
32305 a->b[i].c = 10; 
32306 \newline
32307 a->b[i].d = 11;
32308 \end_layout
32309
32310 \begin_layout Standard
32311 In this case the address arithmetic a->b[i] will be computed only once;
32312  the equivalent code in C would be.
32313 \end_layout
32314
32315 \begin_layout Verse
32316
32317 \family typewriter
32318 iTemp = a->b[i]; 
32319 \newline
32320 iTemp.c = 10; 
32321 \newline
32322 iTemp.d = 11;
32323 \end_layout
32324
32325 \begin_layout Standard
32326 The compiler will try to keep these temporary variables in registers.
32327 \end_layout
32328
32329 \begin_layout Subsection
32330 Dead-Code Elimination
32331 \begin_inset LatexCommand \index{Dead-code elimination}
32332
32333 \end_inset
32334
32335
32336 \end_layout
32337
32338 \begin_layout Verse
32339
32340 \family typewriter
32341 int global;
32342 \newline
32343
32344 \newline
32345 void f () { 
32346 \newline
32347 \InsetSpace ~
32348 \InsetSpace ~
32349 int i; 
32350 \newline
32351 \InsetSpace ~
32352 \InsetSpace ~
32353 i = 1; \InsetSpace ~
32354 \InsetSpace ~
32355 \InsetSpace ~
32356 \InsetSpace ~
32357 \InsetSpace ~
32358 /* dead store */ 
32359 \newline
32360 \InsetSpace ~
32361 \InsetSpace ~
32362 global = 1;\InsetSpace ~
32363 /* dead
32364  store */ 
32365 \newline
32366 \InsetSpace ~
32367 \InsetSpace ~
32368 global = 2; 
32369 \newline
32370 \InsetSpace ~
32371 \InsetSpace ~
32372 return; 
32373 \newline
32374 \InsetSpace ~
32375 \InsetSpace ~
32376 global = 3;\InsetSpace ~
32377 /* unreachable */ 
32378 \newline
32379 }
32380 \end_layout
32381
32382 \begin_layout Standard
32383 will be changed to
32384 \end_layout
32385
32386 \begin_layout Verse
32387
32388 \family typewriter
32389 int global;
32390 \newline
32391
32392 \newline
32393 void f () {
32394 \newline
32395 \InsetSpace ~
32396 \InsetSpace ~
32397 global = 2; 
32398 \newline
32399 }
32400 \end_layout
32401
32402 \begin_layout Subsection
32403 Copy-Propagation
32404 \begin_inset LatexCommand \index{Copy propagation}
32405
32406 \end_inset
32407
32408
32409 \end_layout
32410
32411 \begin_layout Verse
32412
32413 \family typewriter
32414 int f() { 
32415 \newline
32416 \InsetSpace ~
32417 \InsetSpace ~
32418 int i, j; 
32419 \newline
32420 \InsetSpace ~
32421 \InsetSpace ~
32422 i = 10; 
32423 \newline
32424 \InsetSpace ~
32425 \InsetSpace ~
32426 j = i; 
32427 \newline
32428 \InsetSpace ~
32429 \InsetSpace ~
32430 return j; 
32431 \newline
32432 }
32433 \end_layout
32434
32435 \begin_layout Standard
32436 will be changed to 
32437 \end_layout
32438
32439 \begin_layout Verse
32440
32441 \family typewriter
32442 int f() { 
32443 \newline
32444 \InsetSpace ~
32445 \InsetSpace ~
32446 int i, j; 
32447 \newline
32448 \InsetSpace ~
32449 \InsetSpace ~
32450 i = 10; 
32451 \newline
32452 \InsetSpace ~
32453 \InsetSpace ~
32454 j = 10; 
32455 \newline
32456 \InsetSpace ~
32457 \InsetSpace ~
32458 return 10; 
32459 \newline
32460 }
32461 \end_layout
32462
32463 \begin_layout Standard
32464 Note: the dead stores created by this copy propagation will be eliminated
32465  by dead-code elimination.
32466 \end_layout
32467
32468 \begin_layout Subsection
32469 Loop Optimizations
32470 \begin_inset LatexCommand \index{Loop optimization}
32471
32472 \end_inset
32473
32474
32475 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32476
32477 \end_inset
32478
32479
32480 \end_layout
32481
32482 \begin_layout Standard
32483 Two types of loop optimizations are done by SDCC 
32484 \emph on
32485 loop invariant
32486 \emph default
32487  lifting and
32488 \emph on
32489  strength reduction
32490 \emph default
32491  of loop induction variables.
32492  In addition to the strength reduction the optimizer marks the induction
32493  variables and the register allocator tries to keep the induction variables
32494  in registers for the duration of the loop.
32495  Because of this preference of the register allocator
32496 \begin_inset LatexCommand \index{Register allocation}
32497
32498 \end_inset
32499
32500 , loop induction optimization causes an increase in register pressure, which
32501  may cause unwanted spilling of other temporary variables into the stack
32502 \begin_inset LatexCommand \index{stack}
32503
32504 \end_inset
32505
32506  / data space.
32507  The compiler will generate a warning message when it is forced to allocate
32508  extra space either on the stack or data space.
32509  If this extra space allocation is undesirable then induction optimization
32510  can be eliminated either for the entire source file (with -
32511 \begin_inset ERT
32512 status collapsed
32513
32514 \begin_layout Standard
32515
32516
32517 \backslash
32518 /
32519 \end_layout
32520
32521 \end_inset
32522
32523 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32524 noinduction
32525 \begin_inset LatexCommand \index{\#pragma noinduction}
32526
32527 \end_inset
32528
32529 .
32530 \newline
32531
32532 \newline
32533 Loop Invariant:
32534 \end_layout
32535
32536 \begin_layout Verse
32537
32538 \family typewriter
32539 for (i = 0 ; i < 100 ; i ++) 
32540 \newline
32541 \InsetSpace ~
32542 \InsetSpace ~
32543 \InsetSpace ~
32544 \InsetSpace ~
32545 f += k + l;
32546 \end_layout
32547
32548 \begin_layout Standard
32549 changed to
32550 \end_layout
32551
32552 \begin_layout Verse
32553
32554 \family typewriter
32555 itemp = k + l; 
32556 \newline
32557 for (i = 0; i < 100; i++) 
32558 \newline
32559 \InsetSpace ~
32560 \InsetSpace ~
32561 \InsetSpace ~
32562 \InsetSpace ~
32563 f += itemp;
32564 \end_layout
32565
32566 \begin_layout Standard
32567 As mentioned previously some loop invariants are not as apparent, all static
32568  address computations are also moved out of the loop.
32569 \newline
32570
32571 \newline
32572 Strength Reduction
32573 \begin_inset LatexCommand \index{Strength reduction}
32574
32575 \end_inset
32576
32577 , this optimization substitutes an expression by a cheaper expression:
32578 \end_layout
32579
32580 \begin_layout Verse
32581
32582 \family typewriter
32583 for (i=0;i < 100; i++)
32584 \newline
32585 \InsetSpace ~
32586 \InsetSpace ~
32587 \InsetSpace ~
32588 \InsetSpace ~
32589 ar[i*5] = i*3;
32590 \end_layout
32591
32592 \begin_layout Standard
32593 changed to
32594 \end_layout
32595
32596 \begin_layout Verse
32597
32598 \family typewriter
32599 itemp1 = 0; 
32600 \newline
32601 itemp2 = 0; 
32602 \newline
32603 for (i=0;i< 100;i++) { 
32604 \newline
32605 \InsetSpace ~
32606 \InsetSpace ~
32607 \InsetSpace ~
32608 \InsetSpace ~
32609 ar[itemp1] = itemp2; 
32610 \newline
32611 \InsetSpace ~
32612 \InsetSpace ~
32613 \InsetSpace ~
32614 \InsetSpace ~
32615 itemp1
32616  += 5; 
32617 \newline
32618 \InsetSpace ~
32619 \InsetSpace ~
32620 \InsetSpace ~
32621 \InsetSpace ~
32622 itemp2 += 3; 
32623 \newline
32624 }
32625 \end_layout
32626
32627 \begin_layout Standard
32628 The more expensive multiplication
32629 \begin_inset LatexCommand \index{Multiplication}
32630
32631 \end_inset
32632
32633  is changed to a less expensive addition.
32634 \end_layout
32635
32636 \begin_layout Subsection
32637 Loop Reversing
32638 \begin_inset LatexCommand \index{Loop reversing}
32639
32640 \end_inset
32641
32642
32643 \end_layout
32644
32645 \begin_layout Standard
32646 This optimization is done to reduce the overhead of checking loop boundaries
32647  for every iteration.
32648  Some simple loops can be reversed and implemented using a 
32649 \begin_inset Quotes eld
32650 \end_inset
32651
32652 decrement and jump if not zero
32653 \begin_inset Quotes erd
32654 \end_inset
32655
32656  instruction.
32657  SDCC checks for the following criterion to determine if a loop is reversible
32658  (note: more sophisticated compilers use data-dependency analysis to make
32659  this determination, SDCC uses a more simple minded analysis).
32660 \end_layout
32661
32662 \begin_layout Itemize
32663 The 'for' loop is of the form 
32664 \newline
32665
32666 \newline
32667
32668 \family typewriter
32669 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32670  += 1])
32671 \newline
32672 \InsetSpace ~
32673 \InsetSpace ~
32674 \InsetSpace ~
32675 \InsetSpace ~
32676 <for body>
32677 \end_layout
32678
32679 \begin_layout Itemize
32680 The <for body> does not contain 
32681 \begin_inset Quotes eld
32682 \end_inset
32683
32684 continue
32685 \begin_inset Quotes erd
32686 \end_inset
32687
32688  or 'break
32689 \begin_inset Quotes erd
32690 \end_inset
32691
32692 .
32693 \end_layout
32694
32695 \begin_layout Itemize
32696 All goto's are contained within the loop.
32697 \end_layout
32698
32699 \begin_layout Itemize
32700 No function calls within the loop.
32701 \end_layout
32702
32703 \begin_layout Itemize
32704 The loop control variable <sym> is not assigned any value within the loop
32705 \end_layout
32706
32707 \begin_layout Itemize
32708 The loop control variable does NOT participate in any arithmetic operation
32709  within the loop.
32710 \end_layout
32711
32712 \begin_layout Itemize
32713 There are NO switch statements in the loop.
32714 \end_layout
32715
32716 \begin_layout Subsection
32717 Algebraic Simplifications
32718 \end_layout
32719
32720 \begin_layout Standard
32721 SDCC does numerous algebraic simplifications, the following is a small sub-set
32722  of these optimizations.
32723 \end_layout
32724
32725 \begin_layout Verse
32726
32727 \family typewriter
32728 i = j + 0;\InsetSpace ~
32729 \InsetSpace ~
32730 \InsetSpace ~
32731 \InsetSpace ~
32732  /* changed to: */\InsetSpace ~
32733 \InsetSpace ~
32734 \InsetSpace ~
32735 \InsetSpace ~
32736  i = j; 
32737 \newline
32738 i /= 2;\InsetSpace ~
32739 \InsetSpace ~
32740 \InsetSpace ~
32741 \InsetSpace ~
32742 \InsetSpace ~
32743 \InsetSpace ~
32744 \InsetSpace ~
32745  /* changed to: */\InsetSpace ~
32746 \InsetSpace ~
32747 \InsetSpace ~
32748 \InsetSpace ~
32749  i >>= 1; 
32750 \newline
32751 i
32752  = j - j;\InsetSpace ~
32753 \InsetSpace ~
32754 \InsetSpace ~
32755 \InsetSpace ~
32756  /* changed to: */\InsetSpace ~
32757 \InsetSpace ~
32758 \InsetSpace ~
32759 \InsetSpace ~
32760  i = 0; 
32761 \newline
32762 i = j / 1;\InsetSpace ~
32763 \InsetSpace ~
32764 \InsetSpace ~
32765 \InsetSpace ~
32766  /* changed to: */\InsetSpace ~
32767 \InsetSpace ~
32768 \InsetSpace ~
32769 \InsetSpace ~
32770  i = j;
32771 \end_layout
32772
32773 \begin_layout Standard
32774 Note the subexpressions
32775 \begin_inset LatexCommand \index{Subexpression}
32776
32777 \end_inset
32778
32779  given above are generally introduced by macro expansions or as a result
32780  of copy/constant propagation.
32781 \end_layout
32782
32783 \begin_layout Subsection
32784 'switch' Statements
32785 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32786
32787 \end_inset
32788
32789
32790 \begin_inset LatexCommand \index{switch statement}
32791
32792 \end_inset
32793
32794
32795 \end_layout
32796
32797 \begin_layout Standard
32798 SDCC can optimize switch statements to jump tables
32799 \begin_inset LatexCommand \index{jump tables}
32800
32801 \end_inset
32802
32803 .
32804  It makes the decision based on an estimate of the generated code size.
32805  SDCC is quite liberal in the requirements for jump table generation: 
32806 \end_layout
32807
32808 \begin_layout Itemize
32809 The labels need not be in order, and the starting number need not be one
32810  or zero, the case labels are in numerical sequence or not too many case
32811  labels are missing.
32812 \end_layout
32813
32814 \begin_deeper
32815 \begin_layout Verse
32816
32817 \family typewriter
32818 switch(i) {\InsetSpace ~
32819 \InsetSpace ~
32820 \InsetSpace ~
32821 \InsetSpace ~
32822 \InsetSpace ~
32823 \InsetSpace ~
32824 \InsetSpace ~
32825 \InsetSpace ~
32826 \InsetSpace ~
32827 \InsetSpace ~
32828 \InsetSpace ~
32829 \InsetSpace ~
32830 \InsetSpace ~
32831 \InsetSpace ~
32832 \InsetSpace ~
32833 \InsetSpace ~
32834 \InsetSpace ~
32835 \InsetSpace ~
32836 \InsetSpace ~
32837 \InsetSpace ~
32838 \InsetSpace ~
32839 \InsetSpace ~
32840 \InsetSpace ~
32841 \InsetSpace ~
32842 \InsetSpace ~
32843 \InsetSpace ~
32844 switch (i) { 
32845 \newline
32846 \InsetSpace ~
32847 \InsetSpace ~
32848 \InsetSpace ~
32849 case 4: ...\InsetSpace ~
32850 \InsetSpace ~
32851 \InsetSpace ~
32852 \InsetSpace ~
32853 \InsetSpace ~
32854 \InsetSpace ~
32855 \InsetSpace ~
32856 \InsetSpace ~
32857 \InsetSpace ~
32858 \InsetSpace ~
32859 \InsetSpace ~
32860 \InsetSpace ~
32861 \InsetSpace ~
32862 \InsetSpace ~
32863 \InsetSpace ~
32864 \InsetSpace ~
32865 \InsetSpace ~
32866 \InsetSpace ~
32867 \InsetSpace ~
32868 \InsetSpace ~
32869 \InsetSpace ~
32870 \InsetSpace ~
32871 \InsetSpace ~
32872 \InsetSpace ~
32873 \InsetSpace ~
32874 \InsetSpace ~
32875 case 0: ...
32876  
32877 \newline
32878 \InsetSpace ~
32879 \InsetSpace ~
32880 \InsetSpace ~
32881 case 5: ...\InsetSpace ~
32882 \InsetSpace ~
32883 \InsetSpace ~
32884 \InsetSpace ~
32885 \InsetSpace ~
32886 \InsetSpace ~
32887 \InsetSpace ~
32888 \InsetSpace ~
32889 \InsetSpace ~
32890 \InsetSpace ~
32891 \InsetSpace ~
32892 \InsetSpace ~
32893 \InsetSpace ~
32894 \InsetSpace ~
32895 \InsetSpace ~
32896 \InsetSpace ~
32897 \InsetSpace ~
32898 \InsetSpace ~
32899 \InsetSpace ~
32900 \InsetSpace ~
32901 \InsetSpace ~
32902 \InsetSpace ~
32903 \InsetSpace ~
32904 \InsetSpace ~
32905 \InsetSpace ~
32906 \InsetSpace ~
32907 case 1: ...
32908  
32909 \newline
32910 \InsetSpace ~
32911 \InsetSpace ~
32912 \InsetSpace ~
32913 case 3: ...\InsetSpace ~
32914 \InsetSpace ~
32915 \InsetSpace ~
32916 \InsetSpace ~
32917 \InsetSpace ~
32918 \InsetSpace ~
32919 \InsetSpace ~
32920 \InsetSpace ~
32921 \InsetSpace ~
32922 \InsetSpace ~
32923 \InsetSpace ~
32924 \InsetSpace ~
32925 \InsetSpace ~
32926 \InsetSpace ~
32927 \InsetSpace ~
32928 \InsetSpace ~
32929 \InsetSpace ~
32930 \InsetSpace ~
32931 \InsetSpace ~
32932 \InsetSpace ~
32933 \InsetSpace ~
32934 \InsetSpace ~
32935 \InsetSpace ~
32936 \InsetSpace ~
32937 \InsetSpace ~
32938 \InsetSpace ~
32939
32940 \newline
32941 \InsetSpace ~
32942 \InsetSpace ~
32943 \InsetSpace ~
32944 case 6: ...\InsetSpace ~
32945 \InsetSpace ~
32946 \InsetSpace ~
32947 \InsetSpace ~
32948 \InsetSpace ~
32949 \InsetSpace ~
32950 \InsetSpace ~
32951 \InsetSpace ~
32952 \InsetSpace ~
32953 \InsetSpace ~
32954 \InsetSpace ~
32955 \InsetSpace ~
32956 \InsetSpace ~
32957 \InsetSpace ~
32958 \InsetSpace ~
32959 \InsetSpace ~
32960 \InsetSpace ~
32961 \InsetSpace ~
32962 \InsetSpace ~
32963 \InsetSpace ~
32964 \InsetSpace ~
32965 \InsetSpace ~
32966 \InsetSpace ~
32967 \InsetSpace ~
32968 \InsetSpace ~
32969 \InsetSpace ~
32970 case 3: ...
32971  
32972 \newline
32973 \InsetSpace ~
32974 \InsetSpace ~
32975 \InsetSpace ~
32976 case 7: ...\InsetSpace ~
32977 \InsetSpace ~
32978 \InsetSpace ~
32979 \InsetSpace ~
32980 \InsetSpace ~
32981 \InsetSpace ~
32982 \InsetSpace ~
32983 \InsetSpace ~
32984 \InsetSpace ~
32985 \InsetSpace ~
32986 \InsetSpace ~
32987 \InsetSpace ~
32988 \InsetSpace ~
32989 \InsetSpace ~
32990 \InsetSpace ~
32991 \InsetSpace ~
32992 \InsetSpace ~
32993 \InsetSpace ~
32994 \InsetSpace ~
32995 \InsetSpace ~
32996 \InsetSpace ~
32997 \InsetSpace ~
32998 \InsetSpace ~
32999 \InsetSpace ~
33000 \InsetSpace ~
33001 \InsetSpace ~
33002 case 4: ...
33003  
33004 \newline
33005 \InsetSpace ~
33006 \InsetSpace ~
33007 \InsetSpace ~
33008 case 8: ...\InsetSpace ~
33009 \InsetSpace ~
33010 \InsetSpace ~
33011 \InsetSpace ~
33012 \InsetSpace ~
33013 \InsetSpace ~
33014 \InsetSpace ~
33015 \InsetSpace ~
33016 \InsetSpace ~
33017 \InsetSpace ~
33018 \InsetSpace ~
33019 \InsetSpace ~
33020 \InsetSpace ~
33021 \InsetSpace ~
33022 \InsetSpace ~
33023 \InsetSpace ~
33024 \InsetSpace ~
33025 \InsetSpace ~
33026 \InsetSpace ~
33027 \InsetSpace ~
33028 \InsetSpace ~
33029 \InsetSpace ~
33030 \InsetSpace ~
33031 \InsetSpace ~
33032 \InsetSpace ~
33033 \InsetSpace ~
33034 case 5: ...
33035  
33036 \newline
33037 \InsetSpace ~
33038 \InsetSpace ~
33039 \InsetSpace ~
33040 case 9: ...\InsetSpace ~
33041 \InsetSpace ~
33042 \InsetSpace ~
33043 \InsetSpace ~
33044 \InsetSpace ~
33045 \InsetSpace ~
33046 \InsetSpace ~
33047 \InsetSpace ~
33048 \InsetSpace ~
33049 \InsetSpace ~
33050 \InsetSpace ~
33051 \InsetSpace ~
33052 \InsetSpace ~
33053 \InsetSpace ~
33054 \InsetSpace ~
33055 \InsetSpace ~
33056 \InsetSpace ~
33057 \InsetSpace ~
33058 \InsetSpace ~
33059 \InsetSpace ~
33060 \InsetSpace ~
33061 \InsetSpace ~
33062 \InsetSpace ~
33063 \InsetSpace ~
33064 \InsetSpace ~
33065 \InsetSpace ~
33066 case 6: ...
33067  
33068 \newline
33069 \InsetSpace ~
33070 \InsetSpace ~
33071 \InsetSpace ~
33072 case 10: ...\InsetSpace ~
33073 \InsetSpace ~
33074 \InsetSpace ~
33075 \InsetSpace ~
33076 \InsetSpace ~
33077 \InsetSpace ~
33078 \InsetSpace ~
33079 \InsetSpace ~
33080 \InsetSpace ~
33081 \InsetSpace ~
33082 \InsetSpace ~
33083 \InsetSpace ~
33084 \InsetSpace ~
33085 \InsetSpace ~
33086 \InsetSpace ~
33087 \InsetSpace ~
33088 \InsetSpace ~
33089 \InsetSpace ~
33090 \InsetSpace ~
33091 \InsetSpace ~
33092 \InsetSpace ~
33093 \InsetSpace ~
33094 \InsetSpace ~
33095 \InsetSpace ~
33096 \InsetSpace ~
33097 case 7: ...
33098  
33099 \newline
33100 \InsetSpace ~
33101 \InsetSpace ~
33102 \InsetSpace ~
33103 case 11: ...\InsetSpace ~
33104 \InsetSpace ~
33105 \InsetSpace ~
33106 \InsetSpace ~
33107 \InsetSpace ~
33108 \InsetSpace ~
33109 \InsetSpace ~
33110 \InsetSpace ~
33111 \InsetSpace ~
33112 \InsetSpace ~
33113 \InsetSpace ~
33114 \InsetSpace ~
33115 \InsetSpace ~
33116 \InsetSpace ~
33117 \InsetSpace ~
33118 \InsetSpace ~
33119 \InsetSpace ~
33120 \InsetSpace ~
33121 \InsetSpace ~
33122 \InsetSpace ~
33123 \InsetSpace ~
33124 \InsetSpace ~
33125 \InsetSpace ~
33126 \InsetSpace ~
33127 \InsetSpace ~
33128 case 8: ...
33129  
33130 \newline
33131 }\InsetSpace ~
33132 \InsetSpace ~
33133 \InsetSpace ~
33134 \InsetSpace ~
33135 \InsetSpace ~
33136 \InsetSpace ~
33137 \InsetSpace ~
33138 \InsetSpace ~
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 \InsetSpace ~
33142 \InsetSpace ~
33143 \InsetSpace ~
33144 \InsetSpace ~
33145 \InsetSpace ~
33146 \InsetSpace ~
33147 \InsetSpace ~
33148 \InsetSpace ~
33149 \InsetSpace ~
33150 \InsetSpace ~
33151 \InsetSpace ~
33152 \InsetSpace ~
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 \InsetSpace ~
33156 \InsetSpace ~
33157 \InsetSpace ~
33158 \InsetSpace ~
33159 \InsetSpace ~
33160 \InsetSpace ~
33161 \InsetSpace ~
33162 \InsetSpace ~
33163 \InsetSpace ~
33164 \InsetSpace ~
33165 \InsetSpace ~
33166 \InsetSpace ~
33167 }
33168 \end_layout
33169
33170 \begin_layout Standard
33171 Both the above switch statements will be implemented using a jump-table.
33172  The example to the right side is slightly more efficient as the check for
33173  the lower boundary of the jump-table is not needed.
33174 \end_layout
33175
33176 \end_deeper
33177 \begin_layout Itemize
33178 The number of case labels is not larger than supported by the target architectur
33179 e.
33180 \end_layout
33181
33182 \begin_layout Itemize
33183 If the case labels are not in numerical sequence ('gaps' between cases)
33184  SDCC checks whether a jump table with additionally inserted dummy cases
33185  is still attractive.
33186  
33187 \end_layout
33188
33189 \begin_layout Itemize
33190 If the starting number is not zero and a check for the lower boundary of
33191  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33192  ...
33193  .
33194 \end_layout
33195
33196 \begin_layout Standard
33197 Switch statements which have large gaps in the numeric sequence or those
33198  that have too many case labels can be split into more than one switch statement
33199  for efficient code generation, e.g.:
33200 \end_layout
33201
33202 \begin_layout Verse
33203
33204 \family typewriter
33205 switch (i) { 
33206 \newline
33207 \InsetSpace ~
33208 \InsetSpace ~
33209 case 1: ...
33210  
33211 \newline
33212 \InsetSpace ~
33213 \InsetSpace ~
33214 case 2: ...
33215  
33216 \newline
33217 \InsetSpace ~
33218 \InsetSpace ~
33219 case 3: ...
33220  
33221 \newline
33222 \InsetSpace ~
33223 \InsetSpace ~
33224 case 4: ...
33225  
33226 \newline
33227 \InsetSpace ~
33228 \InsetSpace ~
33229 case 5: ...
33230  
33231 \newline
33232 \InsetSpace ~
33233 \InsetSpace ~
33234 case 6: ...
33235  
33236 \newline
33237 \InsetSpace ~
33238 \InsetSpace ~
33239 case 7: ...
33240  
33241 \newline
33242 \InsetSpace ~
33243 \InsetSpace ~
33244 case 101: ...
33245  
33246 \newline
33247 \InsetSpace ~
33248 \InsetSpace ~
33249 case 102: ...
33250  
33251 \newline
33252 \InsetSpace ~
33253 \InsetSpace ~
33254 case 103: ...
33255  
33256 \newline
33257 \InsetSpace ~
33258 \InsetSpace ~
33259 case 104: ...
33260  
33261 \newline
33262 \InsetSpace ~
33263 \InsetSpace ~
33264 case 105: ...
33265  
33266 \newline
33267 \InsetSpace ~
33268 \InsetSpace ~
33269 case 106: ...
33270  
33271 \newline
33272 \InsetSpace ~
33273 \InsetSpace ~
33274 case 107: ...
33275  
33276 \newline
33277 }
33278 \end_layout
33279
33280 \begin_layout Standard
33281 If the above switch statement is broken down into two switch statements
33282 \end_layout
33283
33284 \begin_layout Verse
33285
33286 \family typewriter
33287 switch (i) { 
33288 \newline
33289 \InsetSpace ~
33290 \InsetSpace ~
33291 case 1: ...
33292  
33293 \newline
33294 \InsetSpace ~
33295 \InsetSpace ~
33296 case 2: ...
33297  
33298 \newline
33299 \InsetSpace ~
33300 \InsetSpace ~
33301 case 3: ...
33302  
33303 \newline
33304 \InsetSpace ~
33305 \InsetSpace ~
33306 case 4: ...
33307  
33308 \newline
33309 \InsetSpace ~
33310 \InsetSpace ~
33311 case 5: ...
33312  
33313 \newline
33314 \InsetSpace ~
33315 \InsetSpace ~
33316 case 6: ...
33317  
33318 \newline
33319 \InsetSpace ~
33320 \InsetSpace ~
33321 case 7: ...
33322  
33323 \newline
33324 }
33325 \end_layout
33326
33327 \begin_layout Standard
33328 and
33329 \end_layout
33330
33331 \begin_layout Verse
33332
33333 \family typewriter
33334 switch (i) { 
33335 \newline
33336 \InsetSpace ~
33337 \InsetSpace ~
33338 case 101: ...
33339  
33340 \newline
33341 \InsetSpace ~
33342 \InsetSpace ~
33343 case 102: ...
33344  
33345 \newline
33346 \InsetSpace ~
33347 \InsetSpace ~
33348 case 103: ...
33349  
33350 \newline
33351 \InsetSpace ~
33352 \InsetSpace ~
33353 case 104: ...
33354  
33355 \newline
33356 \InsetSpace ~
33357 \InsetSpace ~
33358 case 105: ...
33359  
33360 \newline
33361 \InsetSpace ~
33362 \InsetSpace ~
33363 case 106: ...
33364  
33365 \newline
33366 \InsetSpace ~
33367 \InsetSpace ~
33368 case 107: ...
33369  
33370 \newline
33371 }
33372 \end_layout
33373
33374 \begin_layout Standard
33375 then both the switch statements will be implemented using jump-tables whereas
33376  the unmodified switch statement will not be.
33377 \end_layout
33378
33379 \begin_layout Standard
33380 \begin_inset Note Note
33381 status collapsed
33382
33383 \begin_layout Standard
33384 There might be reasons which SDCC cannot know about to either favour or
33385  not favour jump tables.
33386  If the target system has to be as quick for the last switch case as for
33387  the first (pro jump table), or if the switch argument is known to be zero
33388  in the majority of the cases (contra jump table).
33389 \end_layout
33390
33391 \end_inset
33392
33393
33394 \end_layout
33395
33396 \begin_layout Standard
33397 The pragma nojtbound
33398 \begin_inset LatexCommand \index{\#pragma nojtbound}
33399
33400 \end_inset
33401
33402  can be used to turn off checking the 
33403 \emph on
33404 j
33405 \emph default
33406 ump 
33407 \emph on
33408 t
33409 \emph default
33410 able 
33411 \emph on
33412 bound
33413 \emph default
33414 aries.
33415  It has no effect if a default label is supplied.
33416  Use of this pragma is dangerous: if the switch
33417 \begin_inset LatexCommand \index{switch statement}
33418
33419 \end_inset
33420
33421  argument is not matched by a case statement the processor will happily
33422  jump into Nirvana.
33423 \end_layout
33424
33425 \begin_layout Subsection
33426 Bit-shifting Operations
33427 \begin_inset LatexCommand \index{Bit shifting}
33428
33429 \end_inset
33430
33431 .
33432 \end_layout
33433
33434 \begin_layout Standard
33435 Bit shifting is one of the most frequently used operation in embedded programmin
33436 g.
33437  SDCC tries to implement bit-shift operations in the most efficient way
33438  possible, e.g.:
33439 \end_layout
33440
33441 \begin_layout Verse
33442
33443 \family typewriter
33444 unsigned char i;
33445 \newline
33446 ...
33447  
33448 \newline
33449 i >>= 4; 
33450 \newline
33451 ...
33452 \end_layout
33453
33454 \begin_layout Standard
33455 generates the following code:
33456 \end_layout
33457
33458 \begin_layout Verse
33459
33460 \family typewriter
33461 mov\InsetSpace ~
33462  a,_i 
33463 \newline
33464 swap a 
33465 \newline
33466 anl\InsetSpace ~
33467  a,#0x0f 
33468 \newline
33469 mov\InsetSpace ~
33470  _i,a
33471 \end_layout
33472
33473 \begin_layout Standard
33474 In general SDCC will never setup a loop if the shift count is known.
33475  Another example:
33476 \end_layout
33477
33478 \begin_layout Verse
33479
33480 \family typewriter
33481 unsigned int i; 
33482 \newline
33483 ...
33484  
33485 \newline
33486 i >>= 9; 
33487 \newline
33488 ...
33489 \end_layout
33490
33491 \begin_layout Standard
33492 will generate:
33493 \end_layout
33494
33495 \begin_layout Verse
33496
33497 \family typewriter
33498 mov\InsetSpace ~
33499 \InsetSpace ~
33500 a,(_i + 1) 
33501 \newline
33502 mov\InsetSpace ~
33503 \InsetSpace ~
33504 (_i + 1),#0x00 
33505 \newline
33506 clr\InsetSpace ~
33507 \InsetSpace ~
33508
33509 \newline
33510 rrc\InsetSpace ~
33511 \InsetSpace ~
33512
33513 \newline
33514 mov\InsetSpace ~
33515 \InsetSpace ~
33516 _i,a
33517 \end_layout
33518
33519 \begin_layout Subsection
33520 Bit-rotation
33521 \begin_inset LatexCommand \index{Bit rotation}
33522
33523 \end_inset
33524
33525
33526 \end_layout
33527
33528 \begin_layout Standard
33529 A special case of the bit-shift operation is bit rotation
33530 \begin_inset LatexCommand \index{rotating bits}
33531
33532 \end_inset
33533
33534 , SDCC recognizes the following expression to be a left bit-rotation:
33535 \end_layout
33536
33537 \begin_layout Verse
33538
33539 \family typewriter
33540 \series bold
33541 unsigned
33542 \series default
33543 \InsetSpace ~
33544 \InsetSpace ~
33545 char i;\InsetSpace ~
33546 \InsetSpace ~
33547 \InsetSpace ~
33548 \InsetSpace ~
33549 \InsetSpace ~
33550 \InsetSpace ~
33551 \InsetSpace ~
33552 \InsetSpace ~
33553 \InsetSpace ~
33554 \InsetSpace ~
33555 \InsetSpace ~
33556 /* unsigned is needed for rotation */ 
33557 \newline
33558 ...
33559  
33560 \newline
33561 i = ((i << 1) | (i >> 7)); 
33562 \family default
33563
33564 \newline
33565
33566 \family typewriter
33567 ...
33568 \end_layout
33569
33570 \begin_layout Standard
33571 will generate the following code:
33572 \end_layout
33573
33574 \begin_layout Verse
33575
33576 \family typewriter
33577 mov\InsetSpace ~
33578 \InsetSpace ~
33579 a,_i 
33580 \newline
33581 rl\InsetSpace ~
33582 \InsetSpace ~
33583 \InsetSpace ~
33584
33585 \newline
33586 mov\InsetSpace ~
33587 \InsetSpace ~
33588 _i,a
33589 \end_layout
33590
33591 \begin_layout Standard
33592 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33593 ns of this case will also be recognized as bit-rotation, i.e.: 
33594 \end_layout
33595
33596 \begin_layout Verse
33597
33598 \family typewriter
33599 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33600 \end_layout
33601
33602 \begin_layout Subsection
33603 Nibble and Byte Swapping
33604 \end_layout
33605
33606 \begin_layout Standard
33607 Other special cases of the bit-shift operations are nibble or byte swapping
33608 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33609
33610 \end_inset
33611
33612 , SDCC recognizes the following expressions:
33613 \end_layout
33614
33615 \begin_layout Verse
33616
33617 \family typewriter
33618 \series bold
33619 unsigned
33620 \series default
33621 \InsetSpace ~
33622 \InsetSpace ~
33623 char i; 
33624 \newline
33625
33626 \series bold
33627 unsigned
33628 \series default
33629 \InsetSpace ~
33630 \InsetSpace ~
33631 int j; 
33632 \newline
33633 ...
33634  
33635 \newline
33636 i = ((i << 4) | (i >> 4)); 
33637 \family default
33638
33639 \newline
33640
33641 \family typewriter
33642 j = ((j << 8) | (j >> 8)); 
33643 \end_layout
33644
33645 \begin_layout Standard
33646 and generates a swap instruction for the nibble swapping
33647 \begin_inset LatexCommand \index{Nibble swapping}
33648
33649 \end_inset
33650
33651  or move instructions for the byte swapping
33652 \begin_inset LatexCommand \index{Byte swapping}
33653
33654 \end_inset
33655
33656 .
33657  The 
33658 \begin_inset Quotes sld
33659 \end_inset
33660
33661 j
33662 \begin_inset Quotes srd
33663 \end_inset
33664
33665  example can be used to convert from little to big-endian or vice versa.
33666  If you want to change the endianness of a 
33667 \emph on
33668 signed
33669 \emph default
33670  integer you have to cast to 
33671 \family typewriter
33672 (unsigned int)
33673 \family default
33674  first.
33675 \end_layout
33676
33677 \begin_layout Standard
33678 Note that SDCC stores numbers in little-endian
33679 \begin_inset Foot
33680 status open
33681
33682 \begin_layout Standard
33683 Usually 8-bit processors don't care much about endianness.
33684  This is not the case for the standard 8051 which only has an instruction
33685  to increment its 
33686 \emph on
33687 dptr
33688 \emph default
33689
33690 \begin_inset LatexCommand \index{DPTR}
33691
33692 \end_inset
33693
33694 -datapointer
33695 \emph on
33696  
33697 \emph default
33698 so little-endian is the more efficient byte order.
33699 \end_layout
33700
33701 \end_inset
33702
33703
33704 \begin_inset LatexCommand \index{little-endian}
33705
33706 \end_inset
33707
33708
33709 \begin_inset LatexCommand \index{Endianness}
33710
33711 \end_inset
33712
33713  format (i.e.
33714  lowest order first).
33715 \end_layout
33716
33717 \begin_layout Subsection
33718 Highest Order Bit
33719 \begin_inset LatexCommand \index{Highest Order Bit}
33720
33721 \end_inset
33722
33723  / Any Order Bit
33724 \begin_inset LatexCommand \index{Any Order Bit}
33725
33726 \end_inset
33727
33728
33729 \end_layout
33730
33731 \begin_layout Standard
33732 It is frequently required to obtain the highest order bit of an integral
33733  type (long, int, short or char types).
33734  Also obtaining any other order bit is not uncommon.
33735  SDCC recognizes the following expressions to yield the highest order bit
33736  and generates optimized code for it, e.g.:
33737 \end_layout
33738
33739 \begin_layout Verse
33740
33741 \family typewriter
33742 unsigned int gint; 
33743 \newline
33744
33745 \newline
33746 foo () { 
33747 \newline
33748 \InsetSpace ~
33749 \InsetSpace ~
33750 unsigned char hob1, aob1; 
33751 \newline
33752 \InsetSpace ~
33753 \InsetSpace ~
33754 bit hob2, hob3, aob2,
33755  aob3; 
33756 \newline
33757 \InsetSpace ~
33758 \InsetSpace ~
33759 ...
33760  
33761 \newline
33762 \InsetSpace ~
33763 \InsetSpace ~
33764 hob1 = (gint >> 15) & 1; 
33765 \newline
33766 \InsetSpace ~
33767 \InsetSpace ~
33768 hob2 = (gint >> 15) & 1; 
33769 \newline
33770 \InsetSpace ~
33771 \InsetSpace ~
33772 hob3 = gint & 0x8000;
33773  
33774 \newline
33775 \InsetSpace ~
33776 \InsetSpace ~
33777 aob1 = (gint >> 9) & 1; 
33778 \newline
33779 \InsetSpace ~
33780 \InsetSpace ~
33781 aob2 = (gint >> 8) & 1; 
33782 \newline
33783 \InsetSpace ~
33784 \InsetSpace ~
33785 aob3 = gint & 0x0800; 
33786 \newline
33787 \InsetSpace ~
33788 \InsetSpace ~
33789 ..
33790  
33791 \newline
33792 }
33793 \end_layout
33794
33795 \begin_layout Standard
33796 will generate the following code:
33797 \end_layout
33798
33799 \begin_layout Verse
33800
33801 \family typewriter
33802 \InsetSpace ~
33803 \InsetSpace ~
33804 \InsetSpace ~
33805 \InsetSpace ~
33806 \InsetSpace ~
33807 \InsetSpace ~
33808 \InsetSpace ~
33809 \InsetSpace ~
33810 \InsetSpace ~
33811 \InsetSpace ~
33812 \InsetSpace ~
33813 \InsetSpace ~
33814 \InsetSpace ~
33815 \InsetSpace ~
33816 \InsetSpace ~
33817 \InsetSpace ~
33818 \InsetSpace ~
33819 \InsetSpace ~
33820 \InsetSpace ~
33821 \InsetSpace ~
33822 \InsetSpace ~
33823 \InsetSpace ~
33824 \InsetSpace ~
33825 \InsetSpace ~
33826 \InsetSpace ~
33827  61 ;\InsetSpace ~
33828  hob.c 7 
33829 \newline
33830 000A E5*01\InsetSpace ~
33831 \InsetSpace ~
33832 \InsetSpace ~
33833 \InsetSpace ~
33834 \InsetSpace ~
33835 \InsetSpace ~
33836 \InsetSpace ~
33837 \InsetSpace ~
33838 \InsetSpace ~
33839 \InsetSpace ~
33840 \InsetSpace ~
33841 \InsetSpace ~
33842 \InsetSpace ~
33843 \InsetSpace ~
33844 \InsetSpace ~
33845  62\InsetSpace ~
33846 \InsetSpace ~
33847 \InsetSpace ~
33848 \InsetSpace ~
33849 \InsetSpace ~
33850 \InsetSpace ~
33851 \InsetSpace ~
33852 \InsetSpace ~
33853  mov\InsetSpace ~
33854 \InsetSpace ~
33855  a,(_gint + 1) 
33856 \newline
33857 000C 23\InsetSpace ~
33858 \InsetSpace ~
33859 \InsetSpace ~
33860 \InsetSpace ~
33861 \InsetSpace ~
33862 \InsetSpace ~
33863 \InsetSpace ~
33864 \InsetSpace ~
33865 \InsetSpace ~
33866 \InsetSpace ~
33867 \InsetSpace ~
33868 \InsetSpace ~
33869 \InsetSpace ~
33870 \InsetSpace ~
33871 \InsetSpace ~
33872 \InsetSpace ~
33873 \InsetSpace ~
33874 \InsetSpace ~
33875  63\InsetSpace ~
33876 \InsetSpace ~
33877 \InsetSpace ~
33878 \InsetSpace ~
33879 \InsetSpace ~
33880 \InsetSpace ~
33881 \InsetSpace ~
33882 \InsetSpace ~
33883  rl\InsetSpace ~
33884 \InsetSpace ~
33885 \InsetSpace ~
33886  a 
33887 \newline
33888 000D 54 01\InsetSpace ~
33889 \InsetSpace ~
33890 \InsetSpace ~
33891 \InsetSpace ~
33892 \InsetSpace ~
33893 \InsetSpace ~
33894 \InsetSpace ~
33895 \InsetSpace ~
33896 \InsetSpace ~
33897 \InsetSpace ~
33898 \InsetSpace ~
33899 \InsetSpace ~
33900 \InsetSpace ~
33901 \InsetSpace ~
33902 \InsetSpace ~
33903
33904  64\InsetSpace ~
33905 \InsetSpace ~
33906 \InsetSpace ~
33907 \InsetSpace ~
33908 \InsetSpace ~
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 \InsetSpace ~
33912  anl\InsetSpace ~
33913 \InsetSpace ~
33914  a,#0x01 
33915 \newline
33916 000F F5*02\InsetSpace ~
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 \InsetSpace ~
33920 \InsetSpace ~
33921 \InsetSpace ~
33922 \InsetSpace ~
33923 \InsetSpace ~
33924 \InsetSpace ~
33925 \InsetSpace ~
33926 \InsetSpace ~
33927 \InsetSpace ~
33928 \InsetSpace ~
33929 \InsetSpace ~
33930 \InsetSpace ~
33931  65\InsetSpace ~
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 \InsetSpace ~
33935 \InsetSpace ~
33936 \InsetSpace ~
33937 \InsetSpace ~
33938 \InsetSpace ~
33939  mov\InsetSpace ~
33940 \InsetSpace ~
33941  _foo_hob1_1_1,a 
33942 \newline
33943 \InsetSpace ~
33944 \InsetSpace ~
33945 \InsetSpace ~
33946 \InsetSpace ~
33947 \InsetSpace ~
33948 \InsetSpace ~
33949 \InsetSpace ~
33950 \InsetSpace ~
33951 \InsetSpace ~
33952 \InsetSpace ~
33953 \InsetSpace ~
33954 \InsetSpace ~
33955 \InsetSpace ~
33956 \InsetSpace ~
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 \InsetSpace ~
33960 \InsetSpace ~
33961 \InsetSpace ~
33962 \InsetSpace ~
33963 \InsetSpace ~
33964 \InsetSpace ~
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 \InsetSpace ~
33968  66 ;\InsetSpace ~
33969  hob.c 8 
33970 \newline
33971 0011 E5*01\InsetSpace ~
33972 \InsetSpace ~
33973 \InsetSpace ~
33974 \InsetSpace ~
33975 \InsetSpace ~
33976 \InsetSpace ~
33977 \InsetSpace ~
33978 \InsetSpace ~
33979 \InsetSpace ~
33980 \InsetSpace ~
33981 \InsetSpace ~
33982 \InsetSpace ~
33983 \InsetSpace ~
33984 \InsetSpace ~
33985 \InsetSpace ~
33986
33987  67\InsetSpace ~
33988 \InsetSpace ~
33989 \InsetSpace ~
33990 \InsetSpace ~
33991 \InsetSpace ~
33992 \InsetSpace ~
33993 \InsetSpace ~
33994 \InsetSpace ~
33995  mov\InsetSpace ~
33996 \InsetSpace ~
33997  a,(_gint + 1) 
33998 \newline
33999 0013 33\InsetSpace ~
34000 \InsetSpace ~
34001 \InsetSpace ~
34002 \InsetSpace ~
34003 \InsetSpace ~
34004 \InsetSpace ~
34005 \InsetSpace ~
34006 \InsetSpace ~
34007 \InsetSpace ~
34008 \InsetSpace ~
34009 \InsetSpace ~
34010 \InsetSpace ~
34011 \InsetSpace ~
34012 \InsetSpace ~
34013 \InsetSpace ~
34014 \InsetSpace ~
34015 \InsetSpace ~
34016 \InsetSpace ~
34017  68\InsetSpace ~
34018 \InsetSpace ~
34019 \InsetSpace ~
34020 \InsetSpace ~
34021 \InsetSpace ~
34022 \InsetSpace ~
34023 \InsetSpace ~
34024 \InsetSpace ~
34025  rlc\InsetSpace ~
34026 \InsetSpace ~
34027  a 
34028 \newline
34029 0014 92*00\InsetSpace ~
34030 \InsetSpace ~
34031 \InsetSpace ~
34032 \InsetSpace ~
34033 \InsetSpace ~
34034 \InsetSpace ~
34035 \InsetSpace ~
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 \InsetSpace ~
34039 \InsetSpace ~
34040 \InsetSpace ~
34041 \InsetSpace ~
34042 \InsetSpace ~
34043 \InsetSpace ~
34044  69\InsetSpace ~
34045 \InsetSpace ~
34046 \InsetSpace ~
34047 \InsetSpace ~
34048 \InsetSpace ~
34049 \InsetSpace ~
34050 \InsetSpace ~
34051 \InsetSpace ~
34052  mov\InsetSpace ~
34053 \InsetSpace ~
34054  _foo_hob2_1_1,c
34055  
34056 \newline
34057 \InsetSpace ~
34058 \InsetSpace ~
34059 \InsetSpace ~
34060 \InsetSpace ~
34061 \InsetSpace ~
34062 \InsetSpace ~
34063 \InsetSpace ~
34064 \InsetSpace ~
34065 \InsetSpace ~
34066 \InsetSpace ~
34067 \InsetSpace ~
34068 \InsetSpace ~
34069 \InsetSpace ~
34070 \InsetSpace ~
34071 \InsetSpace ~
34072 \InsetSpace ~
34073 \InsetSpace ~
34074 \InsetSpace ~
34075 \InsetSpace ~
34076 \InsetSpace ~
34077 \InsetSpace ~
34078 \InsetSpace ~
34079 \InsetSpace ~
34080 \InsetSpace ~
34081 \InsetSpace ~
34082  66 ;\InsetSpace ~
34083  hob.c 9 
34084 \newline
34085 0016 E5*01\InsetSpace ~
34086 \InsetSpace ~
34087 \InsetSpace ~
34088 \InsetSpace ~
34089 \InsetSpace ~
34090 \InsetSpace ~
34091 \InsetSpace ~
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 \InsetSpace ~
34099 \InsetSpace ~
34100  67\InsetSpace ~
34101 \InsetSpace ~
34102 \InsetSpace ~
34103 \InsetSpace ~
34104 \InsetSpace ~
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 \InsetSpace ~
34108  mov\InsetSpace ~
34109 \InsetSpace ~
34110  a,(_gint + 1) 
34111 \newline
34112 0018 33\InsetSpace ~
34113 \InsetSpace ~
34114 \InsetSpace ~
34115 \InsetSpace ~
34116 \InsetSpace ~
34117 \InsetSpace ~
34118 \InsetSpace ~
34119 \InsetSpace ~
34120 \InsetSpace ~
34121 \InsetSpace ~
34122 \InsetSpace ~
34123 \InsetSpace ~
34124 \InsetSpace ~
34125 \InsetSpace ~
34126 \InsetSpace ~
34127 \InsetSpace ~
34128 \InsetSpace ~
34129 \InsetSpace ~
34130  68\InsetSpace ~
34131 \InsetSpace ~
34132 \InsetSpace ~
34133 \InsetSpace ~
34134 \InsetSpace ~
34135 \InsetSpace ~
34136 \InsetSpace ~
34137 \InsetSpace ~
34138  rlc\InsetSpace ~
34139 \InsetSpace ~
34140  a 
34141 \newline
34142 0019 92*01\InsetSpace ~
34143 \InsetSpace ~
34144 \InsetSpace ~
34145 \InsetSpace ~
34146 \InsetSpace ~
34147 \InsetSpace ~
34148 \InsetSpace ~
34149 \InsetSpace ~
34150 \InsetSpace ~
34151 \InsetSpace ~
34152 \InsetSpace ~
34153 \InsetSpace ~
34154 \InsetSpace ~
34155 \InsetSpace ~
34156 \InsetSpace ~
34157
34158  69\InsetSpace ~
34159 \InsetSpace ~
34160 \InsetSpace ~
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 \InsetSpace ~
34166  mov\InsetSpace ~
34167 \InsetSpace ~
34168  _foo_hob3_1_1,c 
34169 \newline
34170 \InsetSpace ~
34171 \InsetSpace ~
34172 \InsetSpace ~
34173 \InsetSpace ~
34174 \InsetSpace ~
34175 \InsetSpace ~
34176 \InsetSpace ~
34177 \InsetSpace ~
34178 \InsetSpace ~
34179 \InsetSpace ~
34180 \InsetSpace ~
34181 \InsetSpace ~
34182 \InsetSpace ~
34183 \InsetSpace ~
34184 \InsetSpace ~
34185 \InsetSpace ~
34186 \InsetSpace ~
34187 \InsetSpace ~
34188 \InsetSpace ~
34189 \InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194 \InsetSpace ~
34195  70 ;\InsetSpace ~
34196  hob.c 10 
34197 \newline
34198 001B E5*01\InsetSpace ~
34199 \InsetSpace ~
34200 \InsetSpace ~
34201 \InsetSpace ~
34202 \InsetSpace ~
34203 \InsetSpace ~
34204 \InsetSpace ~
34205 \InsetSpace ~
34206 \InsetSpace ~
34207 \InsetSpace ~
34208 \InsetSpace ~
34209 \InsetSpace ~
34210 \InsetSpace ~
34211 \InsetSpace ~
34212 \InsetSpace ~
34213  71\InsetSpace ~
34214 \InsetSpace ~
34215 \InsetSpace ~
34216 \InsetSpace ~
34217 \InsetSpace ~
34218 \InsetSpace ~
34219 \InsetSpace ~
34220 \InsetSpace ~
34221  mov\InsetSpace ~
34222 \InsetSpace ~
34223  a,(_gint + 1) 
34224 \newline
34225 001D
34226  03\InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230 \InsetSpace ~
34231 \InsetSpace ~
34232 \InsetSpace ~
34233 \InsetSpace ~
34234 \InsetSpace ~
34235 \InsetSpace ~
34236 \InsetSpace ~
34237 \InsetSpace ~
34238 \InsetSpace ~
34239 \InsetSpace ~
34240 \InsetSpace ~
34241 \InsetSpace ~
34242 \InsetSpace ~
34243 \InsetSpace ~
34244  72\InsetSpace ~
34245 \InsetSpace ~
34246 \InsetSpace ~
34247 \InsetSpace ~
34248 \InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252  rr\InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255  a 
34256 \newline
34257 001E 54 01\InsetSpace ~
34258 \InsetSpace ~
34259 \InsetSpace ~
34260 \InsetSpace ~
34261 \InsetSpace ~
34262 \InsetSpace ~
34263 \InsetSpace ~
34264 \InsetSpace ~
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 \InsetSpace ~
34268 \InsetSpace ~
34269 \InsetSpace ~
34270 \InsetSpace ~
34271 \InsetSpace ~
34272  73\InsetSpace ~
34273 \InsetSpace ~
34274 \InsetSpace ~
34275 \InsetSpace ~
34276 \InsetSpace ~
34277 \InsetSpace ~
34278 \InsetSpace ~
34279 \InsetSpace ~
34280  anl\InsetSpace ~
34281 \InsetSpace ~
34282  a,#0x01 
34283 \newline
34284 0020 F5*03\InsetSpace ~
34285 \InsetSpace ~
34286 \InsetSpace ~
34287 \InsetSpace ~
34288 \InsetSpace ~
34289 \InsetSpace ~
34290 \InsetSpace ~
34291 \InsetSpace ~
34292 \InsetSpace ~
34293 \InsetSpace ~
34294 \InsetSpace ~
34295 \InsetSpace ~
34296 \InsetSpace ~
34297 \InsetSpace ~
34298 \InsetSpace ~
34299  74\InsetSpace ~
34300 \InsetSpace ~
34301 \InsetSpace ~
34302 \InsetSpace ~
34303 \InsetSpace ~
34304 \InsetSpace ~
34305 \InsetSpace ~
34306 \InsetSpace ~
34307  mov\InsetSpace ~
34308 \InsetSpace ~
34309  _foo_aob1_1_1,a
34310  
34311 \newline
34312 \InsetSpace ~
34313 \InsetSpace ~
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 \InsetSpace ~
34317 \InsetSpace ~
34318 \InsetSpace ~
34319 \InsetSpace ~
34320 \InsetSpace ~
34321 \InsetSpace ~
34322 \InsetSpace ~
34323 \InsetSpace ~
34324 \InsetSpace ~
34325 \InsetSpace ~
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 \InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 \InsetSpace ~
34337  75 ;\InsetSpace ~
34338  hob.c 11 
34339 \newline
34340 0022 E5*01\InsetSpace ~
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345 \InsetSpace ~
34346 \InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355  76\InsetSpace ~
34356 \InsetSpace ~
34357 \InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363  mov\InsetSpace ~
34364 \InsetSpace ~
34365  a,(_gint + 1) 
34366 \newline
34367 0024 13\InsetSpace ~
34368 \InsetSpace ~
34369 \InsetSpace ~
34370 \InsetSpace ~
34371 \InsetSpace ~
34372 \InsetSpace ~
34373 \InsetSpace ~
34374 \InsetSpace ~
34375 \InsetSpace ~
34376 \InsetSpace ~
34377 \InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381 \InsetSpace ~
34382 \InsetSpace ~
34383 \InsetSpace ~
34384 \InsetSpace ~
34385  77\InsetSpace ~
34386 \InsetSpace ~
34387 \InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392 \InsetSpace ~
34393  rrc\InsetSpace ~
34394 \InsetSpace ~
34395  a 
34396 \newline
34397 0025 92*02\InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 \InsetSpace ~
34401 \InsetSpace ~
34402 \InsetSpace ~
34403 \InsetSpace ~
34404 \InsetSpace ~
34405 \InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411 \InsetSpace ~
34412
34413  78\InsetSpace ~
34414 \InsetSpace ~
34415 \InsetSpace ~
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421  mov\InsetSpace ~
34422 \InsetSpace ~
34423  _foo_aob2_1_1,c 
34424 \newline
34425 \InsetSpace ~
34426 \InsetSpace ~
34427 \InsetSpace ~
34428 \InsetSpace ~
34429 \InsetSpace ~
34430 \InsetSpace ~
34431 \InsetSpace ~
34432 \InsetSpace ~
34433 \InsetSpace ~
34434 \InsetSpace ~
34435 \InsetSpace ~
34436 \InsetSpace ~
34437 \InsetSpace ~
34438 \InsetSpace ~
34439 \InsetSpace ~
34440 \InsetSpace ~
34441 \InsetSpace ~
34442 \InsetSpace ~
34443 \InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450  79 ;\InsetSpace ~
34451  hob.c 12 
34452 \newline
34453 0027 E5*01\InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457 \InsetSpace ~
34458 \InsetSpace ~
34459 \InsetSpace ~
34460 \InsetSpace ~
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 \InsetSpace ~
34464 \InsetSpace ~
34465 \InsetSpace ~
34466 \InsetSpace ~
34467 \InsetSpace ~
34468  80\InsetSpace ~
34469 \InsetSpace ~
34470 \InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476  mov\InsetSpace ~
34477 \InsetSpace ~
34478  a,(_gint + 1) 
34479 \newline
34480 0029
34481  A2 E3\InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 \InsetSpace ~
34487 \InsetSpace ~
34488 \InsetSpace ~
34489 \InsetSpace ~
34490 \InsetSpace ~
34491 \InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 \InsetSpace ~
34496  81\InsetSpace ~
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504  mov\InsetSpace ~
34505 \InsetSpace ~
34506  c,acc[3] 
34507 \newline
34508 002B 92*03\InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513 \InsetSpace ~
34514 \InsetSpace ~
34515 \InsetSpace ~
34516 \InsetSpace ~
34517 \InsetSpace ~
34518 \InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521 \InsetSpace ~
34522 \InsetSpace ~
34523  82\InsetSpace ~
34524 \InsetSpace ~
34525 \InsetSpace ~
34526 \InsetSpace ~
34527 \InsetSpace ~
34528 \InsetSpace ~
34529 \InsetSpace ~
34530 \InsetSpace ~
34531  mov\InsetSpace ~
34532 \InsetSpace ~
34533  _foo_aob3_1_1,c 
34534 \end_layout
34535
34536 \begin_layout Standard
34537 Other variations of these cases however will 
34538 \emph on
34539 not
34540 \emph default
34541  be recognized.
34542  They are standard C expressions, so I heartily recommend these be the only
34543  way to get the highest order bit, (it is portable).
34544  Of course it will be recognized even if it is embedded in other expressions,
34545  e.g.:
34546 \end_layout
34547
34548 \begin_layout Verse
34549
34550 \family typewriter
34551 xyz = gint + ((gint >> 15) & 1);
34552 \end_layout
34553
34554 \begin_layout Standard
34555 will still be recognized.
34556 \end_layout
34557
34558 \begin_layout Subsection
34559 Higher Order Byte
34560 \begin_inset LatexCommand \index{Higher Order Byte}
34561
34562 \end_inset
34563
34564  / Higher Order Word
34565 \begin_inset LatexCommand \index{Higher Order Word}
34566
34567 \end_inset
34568
34569
34570 \end_layout
34571
34572 \begin_layout Standard
34573 It is also frequently required to obtain a higher order byte or word of
34574  a larger integral type (long, int or short types).
34575  SDCC recognizes the following expressions to yield the higher order byte
34576  or word and generates optimized code for it, e.g.:
34577 \end_layout
34578
34579 \begin_layout Verse
34580
34581 \family typewriter
34582 unsigned int gint; 
34583 \newline
34584 unsigned long int glong; 
34585 \newline
34586
34587 \newline
34588 foo () { 
34589 \newline
34590 \InsetSpace ~
34591 \InsetSpace ~
34592 unsigned char hob1,
34593  hob2; 
34594 \newline
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 unsigned int how1, how2; 
34598 \newline
34599 \InsetSpace ~
34600 \InsetSpace ~
34601 ...
34602  
34603 \newline
34604 \InsetSpace ~
34605 \InsetSpace ~
34606 hob1 = (gint >> 8) & 0xFF; 
34607 \newline
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 hob2 = glong >> 24; 
34611 \newline
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 how1 = (glong >> 16) & 0xFFFF;
34615  
34616 \newline
34617 \InsetSpace ~
34618 \InsetSpace ~
34619 how2 = glong >> 8; 
34620 \newline
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 ..
34624  
34625 \newline
34626 }
34627 \end_layout
34628
34629 \begin_layout Standard
34630 will generate the following code:
34631 \end_layout
34632
34633 \begin_layout Verse
34634
34635 \family typewriter
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 \InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657 \InsetSpace ~
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 \InsetSpace ~
34661  91 ;\InsetSpace ~
34662  hob.c 15 
34663 \newline
34664 0037 85*01*06\InsetSpace ~
34665 \InsetSpace ~
34666 \InsetSpace ~
34667 \InsetSpace ~
34668 \InsetSpace ~
34669 \InsetSpace ~
34670 \InsetSpace ~
34671 \InsetSpace ~
34672 \InsetSpace ~
34673 \InsetSpace ~
34674 \InsetSpace ~
34675 \InsetSpace ~
34676  92\InsetSpace ~
34677 \InsetSpace ~
34678 \InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684  mov\InsetSpace ~
34685 \InsetSpace ~
34686  _foo_hob1_1_1,(_gint + 1) 
34687 \newline
34688 \InsetSpace ~
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 \InsetSpace ~
34703 \InsetSpace ~
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713  93 ;\InsetSpace ~
34714  hob.c
34715  16 
34716 \newline
34717 003A 85*05*07\InsetSpace ~
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729  94\InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737  mov\InsetSpace ~
34738 \InsetSpace ~
34739  _foo_hob2_1_1,(_glong + 3) 
34740 \newline
34741 \InsetSpace ~
34742 \InsetSpace ~
34743 \InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766  95 ;\InsetSpace ~
34767  hob.c 17 
34768 \newline
34769 003D 85*04*08\InsetSpace ~
34770 \InsetSpace ~
34771 \InsetSpace ~
34772 \InsetSpace ~
34773 \InsetSpace ~
34774 \InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779 \InsetSpace ~
34780 \InsetSpace ~
34781
34782  96\InsetSpace ~
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788 \InsetSpace ~
34789 \InsetSpace ~
34790  mov\InsetSpace ~
34791 \InsetSpace ~
34792  _foo_how1_1_1,(_glong + 2) 
34793 \newline
34794 0040 85*05*09\InsetSpace ~
34795 \InsetSpace ~
34796 \InsetSpace ~
34797 \InsetSpace ~
34798 \InsetSpace ~
34799 \InsetSpace ~
34800 \InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803 \InsetSpace ~
34804 \InsetSpace ~
34805 \InsetSpace ~
34806  97\InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814  mov\InsetSpace ~
34815 \InsetSpace ~
34816  (_foo_how1_1_1 +
34817  1),(_glong + 3) 
34818 \newline
34819 0043 85*03*0A\InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828 \InsetSpace ~
34829 \InsetSpace ~
34830 \InsetSpace ~
34831  98\InsetSpace ~
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839  mov\InsetSpace ~
34840 \InsetSpace ~
34841  _foo_how2_1_1,(_glong + 1) 
34842 \newline
34843 0046 85*04*0B\InsetSpace ~
34844 \InsetSpace ~
34845 \InsetSpace ~
34846 \InsetSpace ~
34847 \InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 \InsetSpace ~
34852 \InsetSpace ~
34853 \InsetSpace ~
34854 \InsetSpace ~
34855
34856  99\InsetSpace ~
34857 \InsetSpace ~
34858 \InsetSpace ~
34859 \InsetSpace ~
34860 \InsetSpace ~
34861 \InsetSpace ~
34862 \InsetSpace ~
34863 \InsetSpace ~
34864  mov\InsetSpace ~
34865 \InsetSpace ~
34866  (_foo_how2_1_1 + 1),(_glong + 2) 
34867 \end_layout
34868
34869 \begin_layout Standard
34870 Again, variations of these cases may 
34871 \emph on
34872 not
34873 \emph default
34874  be recognized.
34875  They are standard C expressions, so I heartily recommend these be the only
34876  way to get the higher order byte/word, (it is portable).
34877  Of course it will be recognized even if it is embedded in other expressions,
34878  e.g.:
34879 \end_layout
34880
34881 \begin_layout Verse
34882
34883 \family typewriter
34884 xyz = gint + ((gint >> 8) & 0xFF);
34885 \end_layout
34886
34887 \begin_layout Standard
34888 will still be recognized.
34889 \end_layout
34890
34891 \begin_layout Subsection
34892 Peephole Optimizer
34893 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34894
34895 \end_inset
34896
34897
34898 \begin_inset LatexCommand \index{Peephole optimizer}
34899
34900 \end_inset
34901
34902
34903 \end_layout
34904
34905 \begin_layout Standard
34906 The compiler uses a rule based, pattern matching and re-writing mechanism
34907  for peep-hole optimization.
34908  It is inspired by 
34909 \emph on
34910 copt
34911 \emph default
34912  a peep-hole optimizer by Christopher W.
34913  Fraser (cwfraser\InsetSpace ~
34914 @\InsetSpace ~
34915 microsoft.com).
34916  A default set of rules are compiled into the compiler, additional rules
34917  may be added with the 
34918 \emph on
34919 -
34920 \begin_inset ERT
34921 status collapsed
34922
34923 \begin_layout Standard
34924
34925
34926 \backslash
34927 /
34928 \end_layout
34929
34930 \end_inset
34931
34932 -peep-file
34933 \begin_inset LatexCommand \index{-\/-peep-file}
34934
34935 \end_inset
34936
34937  <filename>
34938 \emph default
34939  option.
34940  The rule language is best illustrated with examples.
34941 \end_layout
34942
34943 \begin_layout Verse
34944
34945 \family typewriter
34946 replace { 
34947 \newline
34948 \InsetSpace ~
34949 \InsetSpace ~
34950 mov %1,a 
34951 \newline
34952 \InsetSpace ~
34953 \InsetSpace ~
34954 mov a,%1
34955 \newline
34956 } by {
34957 \newline
34958 \InsetSpace ~
34959 \InsetSpace ~
34960 mov %1,a
34961 \newline
34962 }
34963 \end_layout
34964
34965 \begin_layout Standard
34966 The above rule will change the following assembly
34967 \begin_inset LatexCommand \index{Assembler routines}
34968
34969 \end_inset
34970
34971  sequence:
34972 \end_layout
34973
34974 \begin_layout Verse
34975
34976 \family typewriter
34977 mov r1,a 
34978 \newline
34979 mov a,r1
34980 \end_layout
34981
34982 \begin_layout Standard
34983 to
34984 \end_layout
34985
34986 \begin_layout Verse
34987
34988 \family typewriter
34989 mov r1,a
34990 \end_layout
34991
34992 \begin_layout Standard
34993 Note: All occurrences of a 
34994 \emph on
34995 %n
34996 \emph default
34997  (pattern variable) must denote the same string.
34998  With the above rule, the assembly sequence:
34999 \end_layout
35000
35001 \begin_layout Verse
35002
35003 \family typewriter
35004 mov r1,a 
35005 \newline
35006 mov a,r2
35007 \end_layout
35008
35009 \begin_layout Standard
35010 will remain unmodified.
35011 \newline
35012
35013 \newline
35014 Other special case optimizations may be added by the
35015  user (via 
35016 \emph on
35017 -
35018 \begin_inset ERT
35019 status collapsed
35020
35021 \begin_layout Standard
35022
35023
35024 \backslash
35025 /
35026 \end_layout
35027
35028 \end_inset
35029
35030 -peep-file option
35031 \emph default
35032 ).
35033  E.g.
35034  some variants of the 8051 MCU
35035 \begin_inset LatexCommand \index{MCS51 variants}
35036
35037 \end_inset
35038
35039  allow only 
35040 \family typewriter
35041 ajmp
35042 \family default
35043  and 
35044 \family typewriter
35045 acall
35046 \family default
35047 .
35048  The following two rules will change all 
35049 \family typewriter
35050 ljmp
35051 \family default
35052  and 
35053 \family typewriter
35054 lcall
35055 \family default
35056  to 
35057 \family typewriter
35058 ajmp
35059 \family default
35060  and 
35061 \family typewriter
35062 acall
35063 \end_layout
35064
35065 \begin_layout Verse
35066
35067 \family typewriter
35068 replace { lcall %1 } by { acall %1 } 
35069 \newline
35070 replace { ljmp %1 } by { ajmp %1 }
35071 \end_layout
35072
35073 \begin_layout Standard
35074 The 
35075 \emph on
35076 inline-assembler code
35077 \emph default
35078  is also passed through the peep hole optimizer, thus the peephole optimizer
35079  can also be used as an assembly level macro expander.
35080  The rules themselves are MCU dependent whereas the rule language infra-structur
35081 e is MCU independent.
35082  Peephole optimization rules for other MCU can be easily programmed using
35083  the rule language.
35084 \newline
35085
35086 \newline
35087 The syntax for a rule is as follows:
35088 \end_layout
35089
35090 \begin_layout Verse
35091
35092 \family typewriter
35093 rule := replace [ restart ] '{' <assembly sequence> '
35094 \backslash
35095 n' 
35096 \newline
35097 \InsetSpace ~
35098  \InsetSpace ~
35099  \InsetSpace ~
35100  \InsetSpace ~
35101  \InsetSpace ~
35102  \InsetSpace ~
35103  \InsetSpace ~
35104  \InsetSpace ~
35105  \InsetSpace ~
35106  \InsetSpace ~
35107  \InsetSpace ~
35108  \InsetSpace ~
35109  \InsetSpace ~
35110  \InsetSpace ~
35111  '}' by '{' '
35112 \backslash
35113 n' 
35114 \newline
35115 \InsetSpace ~
35116  \InsetSpace ~
35117  \InsetSpace ~
35118  \InsetSpace ~
35119  \InsetSpace ~
35120  \InsetSpace ~
35121  \InsetSpace ~
35122  \InsetSpace ~
35123  \InsetSpace ~
35124  \InsetSpace ~
35125  \InsetSpace ~
35126  \InsetSpace ~
35127  \InsetSpace ~
35128  \InsetSpace ~
35129  \InsetSpace ~
35130  \InsetSpace ~
35131  <assembly sequence> '
35132 \backslash
35133 n' 
35134 \newline
35135 \InsetSpace ~
35136  \InsetSpace ~
35137  \InsetSpace ~
35138  \InsetSpace ~
35139  \InsetSpace ~
35140  \InsetSpace ~
35141  \InsetSpace ~
35142  \InsetSpace ~
35143  \InsetSpace ~
35144  \InsetSpace ~
35145  \InsetSpace ~
35146  \InsetSpace ~
35147  \InsetSpace ~
35148  \InsetSpace ~
35149  '}' [if <functionName> ] '
35150 \backslash
35151 n' 
35152 \end_layout
35153
35154 \begin_layout Standard
35155 <assembly sequence> := assembly instruction (each instruction including
35156  labels must be on a separate line).
35157 \newline
35158
35159 \newline
35160 The optimizer will apply to the rules
35161  one by one from the top in the sequence of their appearance, it will terminate
35162  when all rules are exhausted.
35163  If the 'restart' option is specified, then the optimizer will start matching
35164  the rules again from the top, this option for a rule is expensive (performance)
35165 , it is intended to be used in situations where a transformation will trigger
35166  the same rule again.
35167  An example of this (not a good one, it has side effects) is the following
35168  rule:
35169 \end_layout
35170
35171 \begin_layout Verse
35172
35173 \family typewriter
35174 replace restart { 
35175 \newline
35176 \InsetSpace ~
35177 \InsetSpace ~
35178 pop %1 
35179 \newline
35180 \InsetSpace ~
35181 \InsetSpace ~
35182 push %1 } by { 
35183 \newline
35184 \InsetSpace ~
35185 \InsetSpace ~
35186 ; nop 
35187 \newline
35188 }
35189 \end_layout
35190
35191 \begin_layout Standard
35192 Note that the replace pattern cannot be a blank, but can be a comment line.
35193  Without the 'restart' option only the innermost 'pop' 'push' pair would
35194  be eliminated, i.e.:
35195 \end_layout
35196
35197 \begin_layout Verse
35198
35199 \family typewriter
35200 pop ar1 
35201 \newline
35202 pop ar2 
35203 \newline
35204 push ar2 
35205 \newline
35206 push ar1
35207 \end_layout
35208
35209 \begin_layout Standard
35210 would result in:
35211 \end_layout
35212
35213 \begin_layout Verse
35214
35215 \family typewriter
35216 pop ar1 
35217 \newline
35218 ; nop 
35219 \newline
35220 push ar1
35221 \end_layout
35222
35223 \begin_layout Standard
35224
35225 \emph on
35226 with
35227 \emph default
35228  the restart option the rule will be applied again to the resulting code
35229  and then all the pop-push pairs will be eliminated to yield:
35230 \end_layout
35231
35232 \begin_layout Verse
35233
35234 \family typewriter
35235 ; nop 
35236 \newline
35237 ; nop
35238 \end_layout
35239
35240 \begin_layout Standard
35241 A conditional function can be attached to a rule.
35242  Attaching rules are somewhat more involved, let me illustrate this with
35243  an example.
35244 \end_layout
35245
35246 \begin_layout Verse
35247
35248 \family typewriter
35249 replace { 
35250 \newline
35251 \InsetSpace ~
35252  \InsetSpace ~
35253  \InsetSpace ~
35254 ljmp %5 
35255 \newline
35256 %2:
35257 \newline
35258 } by { 
35259 \newline
35260 \InsetSpace ~
35261  \InsetSpace ~
35262  \InsetSpace ~
35263 sjmp %5 
35264 \newline
35265 %2:
35266 \newline
35267 } if labelInRange
35268 \end_layout
35269
35270 \begin_layout Standard
35271 The optimizer does a look-up of a function name table defined in function
35272  
35273 \emph on
35274 callFuncByName
35275 \emph default
35276  in the source file SDCCpeeph.c, with the name 
35277 \emph on
35278 labelInRange
35279 \emph default
35280 .
35281  If it finds a corresponding entry the function is called.
35282  Note there can be no parameters specified for these functions, in this
35283  case the use of 
35284 \emph on
35285 %5
35286 \emph default
35287  is crucial, since the function 
35288 \emph on
35289 labelInRange
35290 \emph default
35291  expects to find the label in that particular variable (the hash table containin
35292 g the variable bindings is passed as a parameter).
35293  If you want to code more such functions, take a close look at the function
35294  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35295  Currently implemented are 
35296 \emph on
35297 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35298  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35299 \emph default
35300 and
35301 \emph on
35302  notVolatile
35303 \emph default
35304 .
35305 \end_layout
35306
35307 \begin_layout Standard
35308 I know this whole thing is a little kludgey, but maybe some day we will
35309  have some better means.
35310  If you are looking at this file, you will see the default rules that are
35311  compiled into the compiler, you can add your own rules in the default set
35312  there if you get tired of specifying the -
35313 \begin_inset ERT
35314 status collapsed
35315
35316 \begin_layout Standard
35317
35318
35319 \backslash
35320 /
35321 \end_layout
35322
35323 \end_inset
35324
35325 -peep-file option.
35326 \end_layout
35327
35328 \begin_layout Section
35329 ANSI-Compliance
35330 \begin_inset LatexCommand \index{ANSI-compliance}
35331
35332 \end_inset
35333
35334
35335 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35336
35337 \end_inset
35338
35339
35340 \end_layout
35341
35342 \begin_layout Standard
35343 The latest publically available version of the standard 
35344 \emph on
35345 ISO/IEC 9899 - Programming languages - C
35346 \emph default
35347  should be available at: 
35348 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35349
35350 \end_inset
35351
35352 .
35353 \newline
35354
35355 \end_layout
35356
35357 \begin_layout Standard
35358 Deviations from the compliance:
35359 \end_layout
35360
35361 \begin_layout Itemize
35362 functions are not reentrant
35363 \begin_inset LatexCommand \index{reentrant}
35364
35365 \end_inset
35366
35367  unless explicitly declared as such or the 
35368 \series bold
35369 -
35370 \begin_inset ERT
35371 status collapsed
35372
35373 \begin_layout Standard
35374
35375
35376 \backslash
35377 /
35378 \end_layout
35379
35380 \end_inset
35381
35382 -stack-auto
35383 \begin_inset LatexCommand \index{-\/-stack-auto}
35384
35385 \end_inset
35386
35387
35388 \series default
35389  command line option is specified.
35390 \end_layout
35391
35392 \begin_layout Itemize
35393 structures
35394 \begin_inset LatexCommand \index{struct}
35395
35396 \end_inset
35397
35398  and unions
35399 \begin_inset LatexCommand \index{union}
35400
35401 \end_inset
35402
35403  cannot be assigned values directly, cannot be passed as function parameters
35404  or assigned to each other and cannot be a return value
35405 \begin_inset LatexCommand \index{return value}
35406
35407 \end_inset
35408
35409  from a function, e.g.:
35410 \end_layout
35411
35412 \begin_deeper
35413 \begin_layout Verse
35414
35415 \family typewriter
35416 struct s { ...
35417  }; 
35418 \newline
35419 struct s s1, s2; 
35420 \newline
35421 foo() 
35422 \newline
35423
35424 \newline
35425 \InsetSpace ~
35426 \InsetSpace ~
35427 \InsetSpace ~
35428 \InsetSpace ~
35429 ...
35430  
35431 \newline
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35437 \newline
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 ...
35443  
35444 \newline
35445 }
35446 \newline
35447
35448 \series bold
35449 struct
35450 \series default
35451  s foo1 (
35452 \series bold
35453 struct
35454 \series default
35455  s parms) /* invalid in SDCC although allowed in ANSI */
35456 \newline
35457
35458 \newline
35459 \InsetSpace ~
35460 \InsetSpace ~
35461 \InsetSpace ~
35462 \InsetSpace ~
35463 struct s rets;
35464  
35465 \newline
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469 \InsetSpace ~
35470 ...
35471  
35472 \newline
35473 \InsetSpace ~
35474 \InsetSpace ~
35475 \InsetSpace ~
35476 \InsetSpace ~
35477 return rets; /* is invalid in SDCC although allowed in ANSI */ 
35478 \newline
35479 }
35480 \end_layout
35481
35482 \end_deeper
35483 \begin_layout Itemize
35484 initialization of structure arrays must be fully braced.
35485 \end_layout
35486
35487 \begin_deeper
35488 \begin_layout Verse
35489
35490 \family typewriter
35491 struct s { char x } a[] = {1, 2};\InsetSpace ~
35492 \InsetSpace ~
35493 \InsetSpace ~
35494 \InsetSpace ~
35495 \InsetSpace ~
35496 /* invalid in SDCC */
35497 \newline
35498 struct s { char x
35499  } a[] = {{1}, {2}}; /* OK */
35500 \end_layout
35501
35502 \end_deeper
35503 \begin_layout Itemize
35504 'long long
35505 \begin_inset LatexCommand \index{long long (not supported)}
35506
35507 \end_inset
35508
35509 ' (64 bit integers
35510 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35511
35512 \end_inset
35513
35514 ) not supported.
35515 \end_layout
35516
35517 \begin_layout Itemize
35518 'double
35519 \begin_inset LatexCommand \index{double (not supported)}
35520
35521 \end_inset
35522
35523 ' precision floating point 
35524 \begin_inset LatexCommand \index{Floating point support}
35525
35526 \end_inset
35527
35528 not supported.
35529 \end_layout
35530
35531 \begin_layout Itemize
35532 Old K&R style
35533 \begin_inset LatexCommand \index{K\&R style}
35534
35535 \end_inset
35536
35537  function declarations are NOT allowed.
35538 \end_layout
35539
35540 \begin_deeper
35541 \begin_layout Verse
35542
35543 \family typewriter
35544 foo(i,j) /* this old style of function declarations */ 
35545 \newline
35546 int i,j; /* are valid
35547  in ANSI but not valid in SDCC */ 
35548 \newline
35549
35550 \newline
35551 \InsetSpace ~
35552 \InsetSpace ~
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 ...
35556  
35557 \newline
35558 }
35559 \end_layout
35560
35561 \end_deeper
35562 \begin_layout Itemize
35563 Most enhancements in C99 are not supported, f.e.:
35564 \end_layout
35565
35566 \begin_deeper
35567 \begin_layout Verse
35568
35569 \family typewriter
35570 \series bold
35571 inline
35572 \begin_inset LatexCommand \index{inline (not supported)}
35573
35574 \end_inset
35575
35576
35577 \series default
35578  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35579  in C99.
35580  An empty define 
35581 \emph on
35582 #define inline
35583 \emph default
35584  can be used as a work around */
35585 \newline
35586
35587 \newline
35588 for (
35589 \series bold
35590 int
35591 \series default
35592  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35593 \end_layout
35594
35595 \end_deeper
35596 \begin_layout Itemize
35597 Certain words that are valid identifiers in the standard may be reserved
35598  words in SDCC unless the 
35599 \series bold
35600 -
35601 \begin_inset ERT
35602 status collapsed
35603
35604 \begin_layout Standard
35605
35606
35607 \backslash
35608 /
35609 \end_layout
35610
35611 \end_inset
35612
35613 -std-c89
35614 \begin_inset LatexCommand \index{-\/-std-c89}
35615
35616 \end_inset
35617
35618  or -
35619 \begin_inset ERT
35620 status collapsed
35621
35622 \begin_layout Standard
35623
35624
35625 \backslash
35626 /
35627 \end_layout
35628
35629 \end_inset
35630
35631 -std-c99
35632 \begin_inset LatexCommand \index{-\/-std-c99}
35633
35634 \end_inset
35635
35636
35637 \series default
35638  command line options are used.
35639  These may include (depending on the selected processor): 'at', 'banked',
35640  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35641 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35642  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35643  '_naked'.
35644  Compliant equivalents of these keywords are always available in a form
35645  that begin with two underscores
35646 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35647
35648 \end_inset
35649
35650 , f.e.
35651  '__data' instead of 'data'.
35652 \end_layout
35653
35654 \begin_layout Section
35655 Cyclomatic Complexity
35656 \begin_inset LatexCommand \index{Cyclomatic complexity}
35657
35658 \end_inset
35659
35660
35661 \end_layout
35662
35663 \begin_layout Standard
35664 Cyclomatic complexity of a function is defined as the number of independent
35665  paths the program can take during execution of the function.
35666  This is an important number since it defines the number test cases you
35667  have to generate to validate the function.
35668  The accepted industry standard for complexity number is 10, if the cyclomatic
35669  complexity reported by SDCC exceeds 10 you should think about simplification
35670  of the function logic.
35671  Note that the complexity level is not related to the number of lines of
35672  code in a function.
35673  Large functions can have low complexity, and small functions can have large
35674  complexity levels.
35675  
35676 \newline
35677
35678 \newline
35679 SDCC uses the following formula to compute the complexity:
35680 \newline
35681
35682 \end_layout
35683
35684 \begin_layout Standard
35685 complexity = (number of edges in control flow graph) - (number of nodes
35686  in control flow graph) + 2;
35687 \newline
35688
35689 \newline
35690 Having said that the industry standard is 10,
35691  you should be aware that in some cases it be may unavoidable to have a
35692  complexity level of less than 10.
35693  For example if you have switch statement with more than 10 case labels,
35694  each case label adds one to the complexity level.
35695  The complexity level is by no means an absolute measure of the algorithmic
35696  complexity of the function, it does however provide a good starting point
35697  for which functions you might look at for further optimization.
35698 \end_layout
35699
35700 \begin_layout Section
35701 Retargetting for other Processors
35702 \end_layout
35703
35704 \begin_layout Standard
35705 The issues for retargetting the compiler are far too numerous to be covered
35706  by this document.
35707  What follows is a brief description of each of the seven phases of the
35708  compiler and its MCU dependency.
35709 \end_layout
35710
35711 \begin_layout Itemize
35712 Parsing the source and building the annotated parse tree.
35713  This phase is largely MCU independent (except for the language extensions).
35714  Syntax & semantic checks are also done in this phase, along with some initial
35715  optimizations like back patching labels and the pattern matching optimizations
35716  like bit-rotation etc.
35717 \end_layout
35718
35719 \begin_layout Itemize
35720 The second phase involves generating an intermediate code which can be easy
35721  manipulated during the later phases.
35722  This phase is entirely MCU independent.
35723  The intermediate code generation assumes the target machine has unlimited
35724  number of registers, and designates them with the name iTemp.
35725  The compiler can be made to dump a human readable form of the code generated
35726  by using the -
35727 \begin_inset ERT
35728 status collapsed
35729
35730 \begin_layout Standard
35731
35732
35733 \backslash
35734 /
35735 \end_layout
35736
35737 \end_inset
35738
35739 -dumpraw option.
35740 \end_layout
35741
35742 \begin_layout Itemize
35743 This phase does the bulk of the standard optimizations and is also MCU independe
35744 nt.
35745  This phase can be broken down into several sub-phases:
35746 \newline
35747
35748 \newline
35749 Break down intermediate
35750  code (iCode) into basic blocks.
35751 \newline
35752 Do control flow & data flow analysis on the
35753  basic blocks.
35754 \newline
35755 Do local common subexpression elimination, then global subexpressio
35756 n elimination
35757 \newline
35758 Dead code elimination
35759 \newline
35760 Loop optimizations
35761 \newline
35762 If loop optimizations
35763  caused any changes then do 'global subexpression elimination' and 'dead
35764  code elimination' again.
35765 \end_layout
35766
35767 \begin_layout Itemize
35768 This phase determines the live-ranges; by live range I mean those iTemp
35769  variables defined by the compiler that still survive after all the optimization
35770 s.
35771  Live range analysis
35772 \begin_inset LatexCommand \index{Live range analysis}
35773
35774 \end_inset
35775
35776  is essential for register allocation, since these computation determines
35777  which of these iTemps will be assigned to registers, and for how long.
35778 \end_layout
35779
35780 \begin_layout Itemize
35781 Phase five is register allocation.
35782  There are two parts to this process.
35783 \newline
35784
35785 \newline
35786 The first part I call 'register packing'
35787  (for lack of a better term).
35788  In this case several MCU specific expression folding is done to reduce
35789  register pressure.
35790 \newline
35791
35792 \newline
35793 The second part is more MCU independent and deals with
35794  allocating registers to the remaining live ranges.
35795  A lot of MCU specific code does creep into this phase because of the limited
35796  number of index registers available in the 8051.
35797 \end_layout
35798
35799 \begin_layout Itemize
35800 The Code generation phase is (unhappily), entirely MCU dependent and very
35801  little (if any at all) of this code can be reused for other MCU.
35802  However the scheme for allocating a homogenized assembler operand for each
35803  iCode operand may be reused.
35804 \end_layout
35805
35806 \begin_layout Itemize
35807 As mentioned in the optimization section the peep-hole optimizer is rule
35808  based system, which can reprogrammed for other MCUs.
35809 \end_layout
35810
35811 \begin_layout Standard
35812 More information is available in a wiki
35813 \begin_inset LatexCommand \index{wiki}
35814
35815 \end_inset
35816
35817  (preliminary link 
35818 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35819
35820 \end_inset
35821
35822 ) and in the thread 
35823 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35824
35825 \end_inset
35826
35827  .
35828 \end_layout
35829
35830 \begin_layout Chapter
35831 Compiler internals
35832 \begin_inset LatexCommand \index{Compiler internals}
35833
35834 \end_inset
35835
35836
35837 \end_layout
35838
35839 \begin_layout Section
35840 The anatomy of the compiler
35841 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35842
35843 \end_inset
35844
35845
35846 \end_layout
35847
35848 \begin_layout Standard
35849
35850 \shape italic
35851 This is an excerpt from an article published in Circuit Cellar Magazine
35852  in 
35853 \series bold
35854 August 2000
35855 \series default
35856 .
35857  It's a little outdated (the compiler is much more efficient now and user/develo
35858 per friendly), but pretty well exposes the guts of it all.
35859 \shape default
35860
35861 \newline
35862
35863 \newline
35864 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35865  It is fairly easy to retarget for other 8-bit MCU.
35866  Here we take a look at some of the internals of the compiler.
35867  
35868 \end_layout
35869
35870 \begin_layout Paragraph*
35871 Parsing
35872 \begin_inset LatexCommand \index{Parsing}
35873
35874 \end_inset
35875
35876  
35877 \end_layout
35878
35879 \begin_layout Standard
35880 Parsing the input source file and creating an AST (Annotated Syntax Tree
35881 \begin_inset LatexCommand \index{Annotated syntax tree}
35882
35883 \end_inset
35884
35885 ).
35886  This phase also involves propagating types (annotating each node of the
35887  parse tree with type information) and semantic analysis.
35888  There are some MCU specific parsing rules.
35889  For example the storage classes, the extended storage classes are MCU specific
35890  while there may be a xdata storage class for 8051 there is no such storage
35891  class for z80 or Atmel AVR.
35892  SDCC allows MCU specific storage class extensions, i.e.
35893  xdata will be treated as a storage class specifier when parsing 8051 C
35894  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35895  C code.
35896 \end_layout
35897
35898 \begin_layout Paragraph*
35899 Generating iCode
35900 \begin_inset LatexCommand \index{iCode}
35901
35902 \end_inset
35903
35904
35905 \end_layout
35906
35907 \begin_layout Standard
35908 Intermediate code generation.
35909  In this phase the AST is broken down into three-operand form (iCode).
35910  These three operand forms are represented as doubly linked lists.
35911  ICode is the term given to the intermediate form generated by the compiler.
35912  ICode example section shows some examples of iCode generated for some simple
35913  C source functions.
35914 \end_layout
35915
35916 \begin_layout Paragraph*
35917 Optimizations
35918 \begin_inset LatexCommand \index{Optimizations}
35919
35920 \end_inset
35921
35922 .
35923 \end_layout
35924
35925 \begin_layout Standard
35926 Bulk of the target independent optimizations is performed in this phase.
35927  The optimizations include constant propagation, common sub-expression eliminati
35928 on, loop invariant code movement, strength reduction of loop induction variables
35929  and dead-code elimination.
35930 \end_layout
35931
35932 \begin_layout Paragraph*
35933 Live range analysis
35934 \begin_inset LatexCommand \index{Live range analysis}
35935
35936 \end_inset
35937
35938
35939 \end_layout
35940
35941 \begin_layout Standard
35942 During intermediate code generation phase, the compiler assumes the target
35943  machine has infinite number of registers and generates a lot of temporary
35944  variables.
35945  The live range computation determines the lifetime of each of these compiler-ge
35946 nerated temporaries.
35947  A picture speaks a thousand words.
35948  ICode example sections show the live range annotations for each of the
35949  operand.
35950  It is important to note here, each iCode is assigned a number in the order
35951  of its execution in the function.
35952  The live ranges are computed in terms of these numbers.
35953  The from number is the number of the iCode which first defines the operand
35954  and the to number signifies the iCode which uses this operand last.
35955 \end_layout
35956
35957 \begin_layout Paragraph*
35958 Register Allocation
35959 \begin_inset LatexCommand \index{Register allocation}
35960
35961 \end_inset
35962
35963
35964 \end_layout
35965
35966 \begin_layout Standard
35967 The register allocation determines the type and number of registers needed
35968  by each operand.
35969  In most MCUs only a few registers can be used for indirect addressing.
35970  In case of 8051 for example the registers R0 & R1 can be used to indirectly
35971  address the internal ram and DPTR to indirectly address the external ram.
35972  The compiler will try to allocate the appropriate register to pointer variables
35973  if it can.
35974  ICode example section shows the operands annotated with the registers assigned
35975  to them.
35976  The compiler will try to keep operands in registers as much as possible;
35977  there are several schemes the compiler uses to do achieve this.
35978  When the compiler runs out of registers the compiler will check to see
35979  if there are any live operands which is not used or defined in the current
35980  basic block being processed, if there are any found then it will push that
35981  operand and use the registers in this block, the operand will then be popped
35982  at the end of the basic block.
35983  
35984 \end_layout
35985
35986 \begin_layout Standard
35987 There are other MCU specific considerations in this phase.
35988  Some MCUs have an accumulator; very short-lived operands could be assigned
35989  to the accumulator instead of a general-purpose register.
35990 \end_layout
35991
35992 \begin_layout Paragraph*
35993 Code generation
35994 \end_layout
35995
35996 \begin_layout Standard
35997 Figure II gives a table of iCode
35998 \begin_inset LatexCommand \index{iCode}
35999
36000 \end_inset
36001
36002  operations supported by the compiler.
36003  The code generation involves translating these operations into corresponding
36004  assembly code for the processor.
36005  This sounds overly simple but that is the essence of code generation.
36006  Some of the iCode operations are generated on a MCU specific manner for
36007  example, the z80 port does not use registers to pass parameters so the
36008  SEND and RECV iCode operations will not be generated, and it also does
36009  not support JUMPTABLES.
36010  
36011 \newline
36012
36013 \end_layout
36014
36015 \begin_layout Standard
36016
36017 \size footnotesize
36018 Figure II 
36019 \begin_inset Tabular
36020 <lyxtabular version="3" rows="39" columns="4">
36021 <features islongtable="true" headBottomDL="true">
36022 <column alignment="block" valignment="top" leftline="true" width="13col%">
36023 <column alignment="left" valignment="top" leftline="true" width="13col%">
36024 <column alignment="block" valignment="top" leftline="true" width="22col%">
36025 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36026 <row topline="true" bottomline="true" endhead="true">
36027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36028 \begin_inset Text
36029
36030 \begin_layout Standard
36031
36032 \series bold
36033 iCode
36034 \series default
36035
36036 \begin_inset LatexCommand \index{iCode}
36037
36038 \end_inset
36039
36040
36041 \end_layout
36042
36043 \end_inset
36044 </cell>
36045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36046 \begin_inset Text
36047
36048 \begin_layout Standard
36049
36050 \series bold
36051 Operands
36052 \end_layout
36053
36054 \end_inset
36055 </cell>
36056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36057 \begin_inset Text
36058
36059 \begin_layout Standard
36060
36061 \series bold
36062 Description
36063 \end_layout
36064
36065 \end_inset
36066 </cell>
36067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36068 \begin_inset Text
36069
36070 \begin_layout Standard
36071
36072 \series bold
36073 C Equivalent
36074 \end_layout
36075
36076 \end_inset
36077 </cell>
36078 </row>
36079 <row topline="true">
36080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36081 \begin_inset Text
36082
36083 \begin_layout Standard
36084
36085 \size footnotesize
36086 '!'
36087 \end_layout
36088
36089 \end_inset
36090 </cell>
36091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36092 \begin_inset Text
36093
36094 \begin_layout Standard
36095
36096 \size footnotesize
36097 IC_LEFT() IC_RESULT()
36098 \end_layout
36099
36100 \end_inset
36101 </cell>
36102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36103 \begin_inset Text
36104
36105 \begin_layout Standard
36106
36107 \size footnotesize
36108 NOT operation 
36109 \end_layout
36110
36111 \end_inset
36112 </cell>
36113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36114 \begin_inset Text
36115
36116 \begin_layout Standard
36117
36118 \size footnotesize
36119 IC_RESULT = ! IC_LEFT;
36120 \end_layout
36121
36122 \end_inset
36123 </cell>
36124 </row>
36125 <row topline="true">
36126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36127 \begin_inset Text
36128
36129 \begin_layout Standard
36130
36131 \size footnotesize
36132 '~'
36133 \end_layout
36134
36135 \end_inset
36136 </cell>
36137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36138 \begin_inset Text
36139
36140 \begin_layout Standard
36141
36142 \size footnotesize
36143 IC_LEFT() IC_RESULT()
36144 \end_layout
36145
36146 \end_inset
36147 </cell>
36148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36149 \begin_inset Text
36150
36151 \begin_layout Standard
36152
36153 \size footnotesize
36154 Bitwise complement of 
36155 \end_layout
36156
36157 \end_inset
36158 </cell>
36159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36160 \begin_inset Text
36161
36162 \begin_layout Standard
36163
36164 \size footnotesize
36165 IC_RESULT = ~IC_LEFT;
36166 \end_layout
36167
36168 \end_inset
36169 </cell>
36170 </row>
36171 <row topline="true">
36172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36173 \begin_inset Text
36174
36175 \begin_layout Standard
36176
36177 \size footnotesize
36178 RRC
36179 \end_layout
36180
36181 \end_inset
36182 </cell>
36183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36184 \begin_inset Text
36185
36186 \begin_layout Standard
36187
36188 \size footnotesize
36189 IC_LEFT() IC_RESULT()
36190 \end_layout
36191
36192 \end_inset
36193 </cell>
36194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36195 \begin_inset Text
36196
36197 \begin_layout Standard
36198
36199 \size footnotesize
36200 Rotate right with carry
36201 \end_layout
36202
36203 \end_inset
36204 </cell>
36205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36206 \begin_inset Text
36207
36208 \begin_layout Standard
36209
36210 \size footnotesize
36211 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36212 \end_layout
36213
36214 \end_inset
36215 </cell>
36216 </row>
36217 <row topline="true">
36218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36219 \begin_inset Text
36220
36221 \begin_layout Standard
36222
36223 \size footnotesize
36224 RLC
36225 \end_layout
36226
36227 \end_inset
36228 </cell>
36229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36230 \begin_inset Text
36231
36232 \begin_layout Standard
36233
36234 \size footnotesize
36235 IC_LEFT() IC_RESULT()
36236 \end_layout
36237
36238 \end_inset
36239 </cell>
36240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36241 \begin_inset Text
36242
36243 \begin_layout Standard
36244
36245 \size footnotesize
36246 Rotate left with carry
36247 \end_layout
36248
36249 \end_inset
36250 </cell>
36251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36252 \begin_inset Text
36253
36254 \begin_layout Standard
36255
36256 \size footnotesize
36257 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36258 \end_layout
36259
36260 \end_inset
36261 </cell>
36262 </row>
36263 <row topline="true">
36264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36265 \begin_inset Text
36266
36267 \begin_layout Standard
36268
36269 \size footnotesize
36270 GETHBIT
36271 \end_layout
36272
36273 \end_inset
36274 </cell>
36275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36276 \begin_inset Text
36277
36278 \begin_layout Standard
36279
36280 \size footnotesize
36281 IC_LEFT() IC_RESULT()
36282 \end_layout
36283
36284 \end_inset
36285 </cell>
36286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36287 \begin_inset Text
36288
36289 \begin_layout Standard
36290
36291 \size footnotesize
36292 Get the highest order bit of IC_LEFT
36293 \end_layout
36294
36295 \end_inset
36296 </cell>
36297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36298 \begin_inset Text
36299
36300 \begin_layout Standard
36301
36302 \size footnotesize
36303 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36304 \end_layout
36305
36306 \end_inset
36307 </cell>
36308 </row>
36309 <row topline="true">
36310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36311 \begin_inset Text
36312
36313 \begin_layout Standard
36314
36315 \size footnotesize
36316 UNARYMINUS
36317 \end_layout
36318
36319 \end_inset
36320 </cell>
36321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36322 \begin_inset Text
36323
36324 \begin_layout Standard
36325
36326 \size footnotesize
36327 IC_LEFT() IC_RESULT()
36328 \end_layout
36329
36330 \end_inset
36331 </cell>
36332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36333 \begin_inset Text
36334
36335 \begin_layout Standard
36336
36337 \size footnotesize
36338 Unary minus
36339 \end_layout
36340
36341 \end_inset
36342 </cell>
36343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36344 \begin_inset Text
36345
36346 \begin_layout Standard
36347
36348 \size footnotesize
36349 IC_RESULT = - IC_LEFT;
36350 \end_layout
36351
36352 \end_inset
36353 </cell>
36354 </row>
36355 <row topline="true">
36356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36357 \begin_inset Text
36358
36359 \begin_layout Standard
36360
36361 \size footnotesize
36362 IPUSH
36363 \end_layout
36364
36365 \end_inset
36366 </cell>
36367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36368 \begin_inset Text
36369
36370 \begin_layout Standard
36371
36372 \size footnotesize
36373 IC_LEFT()
36374 \end_layout
36375
36376 \end_inset
36377 </cell>
36378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36379 \begin_inset Text
36380
36381 \begin_layout Standard
36382
36383 \size footnotesize
36384 Push the operand into stack
36385 \end_layout
36386
36387 \end_inset
36388 </cell>
36389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36390 \begin_inset Text
36391
36392 \begin_layout Standard
36393
36394 \size footnotesize
36395 NONE
36396 \end_layout
36397
36398 \end_inset
36399 </cell>
36400 </row>
36401 <row topline="true">
36402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36403 \begin_inset Text
36404
36405 \begin_layout Standard
36406
36407 \size footnotesize
36408 IPOP
36409 \end_layout
36410
36411 \end_inset
36412 </cell>
36413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36414 \begin_inset Text
36415
36416 \begin_layout Standard
36417
36418 \size footnotesize
36419 IC_LEFT()
36420 \end_layout
36421
36422 \end_inset
36423 </cell>
36424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36425 \begin_inset Text
36426
36427 \begin_layout Standard
36428
36429 \size footnotesize
36430 Pop the operand from the stack 
36431 \end_layout
36432
36433 \end_inset
36434 </cell>
36435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36436 \begin_inset Text
36437
36438 \begin_layout Standard
36439
36440 \size footnotesize
36441 NONE
36442 \end_layout
36443
36444 \end_inset
36445 </cell>
36446 </row>
36447 <row topline="true">
36448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36449 \begin_inset Text
36450
36451 \begin_layout Standard
36452
36453 \size footnotesize
36454 CALL
36455 \end_layout
36456
36457 \end_inset
36458 </cell>
36459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36460 \begin_inset Text
36461
36462 \begin_layout Standard
36463
36464 \size footnotesize
36465 IC_LEFT() IC_RESULT()
36466 \end_layout
36467
36468 \end_inset
36469 </cell>
36470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36471 \begin_inset Text
36472
36473 \begin_layout Standard
36474
36475 \size footnotesize
36476 Call the function represented by IC_LEFT 
36477 \end_layout
36478
36479 \end_inset
36480 </cell>
36481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36482 \begin_inset Text
36483
36484 \begin_layout Standard
36485
36486 \size footnotesize
36487 IC_RESULT = IC_LEFT();
36488 \end_layout
36489
36490 \end_inset
36491 </cell>
36492 </row>
36493 <row topline="true">
36494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36495 \begin_inset Text
36496
36497 \begin_layout Standard
36498
36499 \size footnotesize
36500 PCALL
36501 \end_layout
36502
36503 \end_inset
36504 </cell>
36505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36506 \begin_inset Text
36507
36508 \begin_layout Standard
36509
36510 \size footnotesize
36511 IC_LEFT() IC_RESULT()
36512 \end_layout
36513
36514 \end_inset
36515 </cell>
36516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36517 \begin_inset Text
36518
36519 \begin_layout Standard
36520
36521 \size footnotesize
36522 Call via function pointer
36523 \end_layout
36524
36525 \end_inset
36526 </cell>
36527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36528 \begin_inset Text
36529
36530 \begin_layout Standard
36531
36532 \size footnotesize
36533 IC_RESULT = (*IC_LEFT)();
36534 \end_layout
36535
36536 \end_inset
36537 </cell>
36538 </row>
36539 <row topline="true">
36540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36541 \begin_inset Text
36542
36543 \begin_layout Standard
36544
36545 \size footnotesize
36546 RETURN
36547 \end_layout
36548
36549 \end_inset
36550 </cell>
36551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36552 \begin_inset Text
36553
36554 \begin_layout Standard
36555
36556 \size footnotesize
36557 IC_LEFT()
36558 \end_layout
36559
36560 \end_inset
36561 </cell>
36562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36563 \begin_inset Text
36564
36565 \begin_layout Standard
36566
36567 \size footnotesize
36568 Return the value in operand IC_LEFT 
36569 \end_layout
36570
36571 \end_inset
36572 </cell>
36573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36574 \begin_inset Text
36575
36576 \begin_layout Standard
36577
36578 \size footnotesize
36579 return IC_LEFT;
36580 \end_layout
36581
36582 \end_inset
36583 </cell>
36584 </row>
36585 <row topline="true">
36586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36587 \begin_inset Text
36588
36589 \begin_layout Standard
36590
36591 \size footnotesize
36592 LABEL
36593 \end_layout
36594
36595 \end_inset
36596 </cell>
36597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36598 \begin_inset Text
36599
36600 \begin_layout Standard
36601
36602 \size footnotesize
36603 IC_LABEL() 
36604 \end_layout
36605
36606 \end_inset
36607 </cell>
36608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36609 \begin_inset Text
36610
36611 \begin_layout Standard
36612
36613 \size footnotesize
36614 Label
36615 \end_layout
36616
36617 \end_inset
36618 </cell>
36619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36620 \begin_inset Text
36621
36622 \begin_layout Standard
36623
36624 \size footnotesize
36625 IC_LABEL:
36626 \end_layout
36627
36628 \end_inset
36629 </cell>
36630 </row>
36631 <row topline="true">
36632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36633 \begin_inset Text
36634
36635 \begin_layout Standard
36636
36637 \size footnotesize
36638 GOTO
36639 \end_layout
36640
36641 \end_inset
36642 </cell>
36643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36644 \begin_inset Text
36645
36646 \begin_layout Standard
36647
36648 \size footnotesize
36649 IC_LABEL() 
36650 \end_layout
36651
36652 \end_inset
36653 </cell>
36654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36655 \begin_inset Text
36656
36657 \begin_layout Standard
36658
36659 \size footnotesize
36660 Goto label
36661 \end_layout
36662
36663 \end_inset
36664 </cell>
36665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36666 \begin_inset Text
36667
36668 \begin_layout Standard
36669
36670 \size footnotesize
36671 goto IC_LABEL();
36672 \end_layout
36673
36674 \end_inset
36675 </cell>
36676 </row>
36677 <row topline="true">
36678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36679 \begin_inset Text
36680
36681 \begin_layout Standard
36682
36683 \size footnotesize
36684 '+'
36685 \end_layout
36686
36687 \end_inset
36688 </cell>
36689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36690 \begin_inset Text
36691
36692 \begin_layout Standard
36693
36694 \size footnotesize
36695 IC_LEFT() IC_RIGHT() IC_RESULT()
36696 \end_layout
36697
36698 \end_inset
36699 </cell>
36700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36701 \begin_inset Text
36702
36703 \begin_layout Standard
36704
36705 \size footnotesize
36706 Addition
36707 \end_layout
36708
36709 \end_inset
36710 </cell>
36711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36712 \begin_inset Text
36713
36714 \begin_layout Standard
36715
36716 \size footnotesize
36717 IC_RESULT = IC_LEFT + IC_RIGHT
36718 \end_layout
36719
36720 \end_inset
36721 </cell>
36722 </row>
36723 <row topline="true">
36724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36725 \begin_inset Text
36726
36727 \begin_layout Standard
36728
36729 \size footnotesize
36730 '-'
36731 \end_layout
36732
36733 \end_inset
36734 </cell>
36735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36736 \begin_inset Text
36737
36738 \begin_layout Standard
36739
36740 \size footnotesize
36741 IC_LEFT() IC_RIGHT() IC_RESULT()
36742 \end_layout
36743
36744 \end_inset
36745 </cell>
36746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36747 \begin_inset Text
36748
36749 \begin_layout Standard
36750
36751 \size footnotesize
36752 Subtraction
36753 \end_layout
36754
36755 \end_inset
36756 </cell>
36757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36758 \begin_inset Text
36759
36760 \begin_layout Standard
36761
36762 \size footnotesize
36763 IC_RESULT = IC_LEFT - IC_RIGHT 
36764 \end_layout
36765
36766 \end_inset
36767 </cell>
36768 </row>
36769 <row topline="true">
36770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36771 \begin_inset Text
36772
36773 \begin_layout Standard
36774
36775 \size footnotesize
36776 '*'
36777 \end_layout
36778
36779 \end_inset
36780 </cell>
36781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36782 \begin_inset Text
36783
36784 \begin_layout Standard
36785
36786 \size footnotesize
36787 IC_LEFT() IC_RIGHT() IC_RESULT()
36788 \end_layout
36789
36790 \end_inset
36791 </cell>
36792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36793 \begin_inset Text
36794
36795 \begin_layout Standard
36796
36797 \size footnotesize
36798 Multiplication 
36799 \end_layout
36800
36801 \end_inset
36802 </cell>
36803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36804 \begin_inset Text
36805
36806 \begin_layout Standard
36807
36808 \size footnotesize
36809 IC_RESULT = IC_LEFT * IC_RIGHT;
36810 \end_layout
36811
36812 \end_inset
36813 </cell>
36814 </row>
36815 <row topline="true">
36816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36817 \begin_inset Text
36818
36819 \begin_layout Standard
36820
36821 \size footnotesize
36822 '/'
36823 \end_layout
36824
36825 \end_inset
36826 </cell>
36827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36828 \begin_inset Text
36829
36830 \begin_layout Standard
36831
36832 \size footnotesize
36833 IC_LEFT() IC_RIGHT() IC_RESULT()
36834 \end_layout
36835
36836 \end_inset
36837 </cell>
36838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36839 \begin_inset Text
36840
36841 \begin_layout Standard
36842
36843 \size footnotesize
36844 Division
36845 \end_layout
36846
36847 \end_inset
36848 </cell>
36849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36850 \begin_inset Text
36851
36852 \begin_layout Standard
36853
36854 \size footnotesize
36855 IC_RESULT = IC_LEFT / IC_RIGHT;
36856 \end_layout
36857
36858 \end_inset
36859 </cell>
36860 </row>
36861 <row topline="true">
36862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36863 \begin_inset Text
36864
36865 \begin_layout Standard
36866
36867 \size footnotesize
36868 '%'
36869 \end_layout
36870
36871 \end_inset
36872 </cell>
36873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36874 \begin_inset Text
36875
36876 \begin_layout Standard
36877
36878 \size footnotesize
36879 IC_LEFT() IC_RIGHT() IC_RESULT()
36880 \end_layout
36881
36882 \end_inset
36883 </cell>
36884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36885 \begin_inset Text
36886
36887 \begin_layout Standard
36888
36889 \size footnotesize
36890 Modulus
36891 \end_layout
36892
36893 \end_inset
36894 </cell>
36895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36896 \begin_inset Text
36897
36898 \begin_layout Standard
36899
36900 \size footnotesize
36901 IC_RESULT = IC_LEFT % IC_RIGHT;
36902 \end_layout
36903
36904 \end_inset
36905 </cell>
36906 </row>
36907 <row topline="true">
36908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36909 \begin_inset Text
36910
36911 \begin_layout Standard
36912
36913 \size footnotesize
36914 '<'
36915 \end_layout
36916
36917 \end_inset
36918 </cell>
36919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36920 \begin_inset Text
36921
36922 \begin_layout Standard
36923
36924 \size footnotesize
36925 IC_LEFT() IC_RIGHT() IC_RESULT()
36926 \end_layout
36927
36928 \end_inset
36929 </cell>
36930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36931 \begin_inset Text
36932
36933 \begin_layout Standard
36934
36935 \size footnotesize
36936 Less than
36937 \end_layout
36938
36939 \end_inset
36940 </cell>
36941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36942 \begin_inset Text
36943
36944 \begin_layout Standard
36945
36946 \size footnotesize
36947 IC_RESULT = IC_LEFT < IC_RIGHT;
36948 \end_layout
36949
36950 \end_inset
36951 </cell>
36952 </row>
36953 <row topline="true">
36954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36955 \begin_inset Text
36956
36957 \begin_layout Standard
36958
36959 \size footnotesize
36960 '>'
36961 \end_layout
36962
36963 \end_inset
36964 </cell>
36965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36966 \begin_inset Text
36967
36968 \begin_layout Standard
36969
36970 \size footnotesize
36971 IC_LEFT() IC_RIGHT() IC_RESULT()
36972 \end_layout
36973
36974 \end_inset
36975 </cell>
36976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36977 \begin_inset Text
36978
36979 \begin_layout Standard
36980
36981 \size footnotesize
36982 Greater than 
36983 \end_layout
36984
36985 \end_inset
36986 </cell>
36987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36988 \begin_inset Text
36989
36990 \begin_layout Standard
36991
36992 \size footnotesize
36993 IC_RESULT = IC_LEFT > IC_RIGHT;
36994 \end_layout
36995
36996 \end_inset
36997 </cell>
36998 </row>
36999 <row topline="true">
37000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37001 \begin_inset Text
37002
37003 \begin_layout Standard
37004
37005 \size footnotesize
37006 EQ_OP
37007 \end_layout
37008
37009 \end_inset
37010 </cell>
37011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37012 \begin_inset Text
37013
37014 \begin_layout Standard
37015
37016 \size footnotesize
37017 IC_LEFT() IC_RIGHT() IC_RESULT()
37018 \end_layout
37019
37020 \end_inset
37021 </cell>
37022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37023 \begin_inset Text
37024
37025 \begin_layout Standard
37026
37027 \size footnotesize
37028 Equal to 
37029 \end_layout
37030
37031 \end_inset
37032 </cell>
37033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37034 \begin_inset Text
37035
37036 \begin_layout Standard
37037
37038 \size footnotesize
37039 IC_RESULT = IC_LEFT == IC_RIGHT;
37040 \end_layout
37041
37042 \end_inset
37043 </cell>
37044 </row>
37045 <row topline="true">
37046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37047 \begin_inset Text
37048
37049 \begin_layout Standard
37050
37051 \size footnotesize
37052 AND_OP
37053 \end_layout
37054
37055 \end_inset
37056 </cell>
37057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37058 \begin_inset Text
37059
37060 \begin_layout Standard
37061
37062 \size footnotesize
37063 IC_LEFT() IC_RIGHT() IC_RESULT() 
37064 \end_layout
37065
37066 \end_inset
37067 </cell>
37068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37069 \begin_inset Text
37070
37071 \begin_layout Standard
37072
37073 \size footnotesize
37074 Logical and operation
37075 \end_layout
37076
37077 \end_inset
37078 </cell>
37079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37080 \begin_inset Text
37081
37082 \begin_layout Standard
37083
37084 \size footnotesize
37085 IC_RESULT = IC_LEFT && IC_RIGHT; 
37086 \end_layout
37087
37088 \end_inset
37089 </cell>
37090 </row>
37091 <row topline="true">
37092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37093 \begin_inset Text
37094
37095 \begin_layout Standard
37096
37097 \size footnotesize
37098 OR_OP
37099 \end_layout
37100
37101 \end_inset
37102 </cell>
37103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37104 \begin_inset Text
37105
37106 \begin_layout Standard
37107
37108 \size footnotesize
37109 IC_LEFT() IC_RIGHT() IC_RESULT() 
37110 \end_layout
37111
37112 \end_inset
37113 </cell>
37114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37115 \begin_inset Text
37116
37117 \begin_layout Standard
37118
37119 \size footnotesize
37120 Logical or operation 
37121 \end_layout
37122
37123 \end_inset
37124 </cell>
37125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37126 \begin_inset Text
37127
37128 \begin_layout Standard
37129
37130 \size footnotesize
37131 IC_RESULT = IC_LEFT || IC_RIGHT; 
37132 \end_layout
37133
37134 \end_inset
37135 </cell>
37136 </row>
37137 <row topline="true">
37138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37139 \begin_inset Text
37140
37141 \begin_layout Standard
37142
37143 \size footnotesize
37144 '^'
37145 \end_layout
37146
37147 \end_inset
37148 </cell>
37149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37150 \begin_inset Text
37151
37152 \begin_layout Standard
37153
37154 \size footnotesize
37155 IC_LEFT() IC_RIGHT() IC_RESULT() 
37156 \end_layout
37157
37158 \end_inset
37159 </cell>
37160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37161 \begin_inset Text
37162
37163 \begin_layout Standard
37164
37165 \size footnotesize
37166 Exclusive OR
37167 \end_layout
37168
37169 \end_inset
37170 </cell>
37171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37172 \begin_inset Text
37173
37174 \begin_layout Standard
37175
37176 \size footnotesize
37177 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37178 \end_layout
37179
37180 \end_inset
37181 </cell>
37182 </row>
37183 <row topline="true">
37184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37185 \begin_inset Text
37186
37187 \begin_layout Standard
37188
37189 \size footnotesize
37190 '|'
37191 \end_layout
37192
37193 \end_inset
37194 </cell>
37195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37196 \begin_inset Text
37197
37198 \begin_layout Standard
37199
37200 \size footnotesize
37201 IC_LEFT() IC_RIGHT() IC_RESULT() 
37202 \end_layout
37203
37204 \end_inset
37205 </cell>
37206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37207 \begin_inset Text
37208
37209 \begin_layout Standard
37210
37211 \size footnotesize
37212 Bitwise OR 
37213 \end_layout
37214
37215 \end_inset
37216 </cell>
37217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37218 \begin_inset Text
37219
37220 \begin_layout Standard
37221
37222 \size footnotesize
37223 IC_RESULT = IC_LEFT | IC_RIGHT;
37224 \end_layout
37225
37226 \end_inset
37227 </cell>
37228 </row>
37229 <row topline="true">
37230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37231 \begin_inset Text
37232
37233 \begin_layout Standard
37234
37235 \size footnotesize
37236 BITWISEAND
37237 \end_layout
37238
37239 \end_inset
37240 </cell>
37241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37242 \begin_inset Text
37243
37244 \begin_layout Standard
37245
37246 \size footnotesize
37247 IC_LEFT() IC_RIGHT() IC_RESULT()
37248 \end_layout
37249
37250 \end_inset
37251 </cell>
37252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37253 \begin_inset Text
37254
37255 \begin_layout Standard
37256
37257 \size footnotesize
37258 Bitwise AND 
37259 \end_layout
37260
37261 \end_inset
37262 </cell>
37263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37264 \begin_inset Text
37265
37266 \begin_layout Standard
37267
37268 \size footnotesize
37269 IC_RESULT = IC_LEFT & IC_RIGHT;
37270 \end_layout
37271
37272 \end_inset
37273 </cell>
37274 </row>
37275 <row topline="true">
37276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37277 \begin_inset Text
37278
37279 \begin_layout Standard
37280
37281 \size footnotesize
37282 LEFT_OP
37283 \end_layout
37284
37285 \end_inset
37286 </cell>
37287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37288 \begin_inset Text
37289
37290 \begin_layout Standard
37291
37292 \size footnotesize
37293 IC_LEFT() IC_RIGHT() IC_RESULT()
37294 \end_layout
37295
37296 \end_inset
37297 </cell>
37298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37299 \begin_inset Text
37300
37301 \begin_layout Standard
37302
37303 \size footnotesize
37304 Left shift 
37305 \end_layout
37306
37307 \end_inset
37308 </cell>
37309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37310 \begin_inset Text
37311
37312 \begin_layout Standard
37313
37314 \size footnotesize
37315 IC_RESULT = IC_LEFT << IC_RIGHT 
37316 \end_layout
37317
37318 \end_inset
37319 </cell>
37320 </row>
37321 <row topline="true">
37322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37323 \begin_inset Text
37324
37325 \begin_layout Standard
37326
37327 \size footnotesize
37328 RIGHT_OP
37329 \end_layout
37330
37331 \end_inset
37332 </cell>
37333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37334 \begin_inset Text
37335
37336 \begin_layout Standard
37337
37338 \size footnotesize
37339 IC_LEFT() IC_RIGHT() IC_RESULT()
37340 \end_layout
37341
37342 \end_inset
37343 </cell>
37344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37345 \begin_inset Text
37346
37347 \begin_layout Standard
37348
37349 \size footnotesize
37350 Right shift
37351 \end_layout
37352
37353 \end_inset
37354 </cell>
37355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37356 \begin_inset Text
37357
37358 \begin_layout Standard
37359
37360 \size footnotesize
37361 IC_RESULT = IC_LEFT >> IC_RIGHT 
37362 \end_layout
37363
37364 \end_inset
37365 </cell>
37366 </row>
37367 <row topline="true">
37368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37369 \begin_inset Text
37370
37371 \begin_layout Standard
37372
37373 \size footnotesize
37374 GET_VALUE_
37375 \newline
37376 AT_ ADDRESS
37377 \end_layout
37378
37379 \end_inset
37380 </cell>
37381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37382 \begin_inset Text
37383
37384 \begin_layout Standard
37385
37386 \size footnotesize
37387 IC_LEFT() IC_RESULT()
37388 \end_layout
37389
37390 \end_inset
37391 </cell>
37392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37393 \begin_inset Text
37394
37395 \begin_layout Standard
37396
37397 \size footnotesize
37398 Indirect fetch 
37399 \end_layout
37400
37401 \end_inset
37402 </cell>
37403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37404 \begin_inset Text
37405
37406 \begin_layout Standard
37407
37408 \size footnotesize
37409 IC_RESULT = (*IC_LEFT);
37410 \end_layout
37411
37412 \end_inset
37413 </cell>
37414 </row>
37415 <row topline="true">
37416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37417 \begin_inset Text
37418
37419 \begin_layout Standard
37420
37421 \size footnotesize
37422 POINTER_SET
37423 \end_layout
37424
37425 \end_inset
37426 </cell>
37427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37428 \begin_inset Text
37429
37430 \begin_layout Standard
37431
37432 \size footnotesize
37433 IC_RIGHT() IC_RESULT() 
37434 \end_layout
37435
37436 \end_inset
37437 </cell>
37438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37439 \begin_inset Text
37440
37441 \begin_layout Standard
37442
37443 \size footnotesize
37444 Indirect set
37445 \end_layout
37446
37447 \end_inset
37448 </cell>
37449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37450 \begin_inset Text
37451
37452 \begin_layout Standard
37453
37454 \size footnotesize
37455 (*IC_RESULT) = IC_RIGHT;
37456 \end_layout
37457
37458 \end_inset
37459 </cell>
37460 </row>
37461 <row topline="true">
37462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37463 \begin_inset Text
37464
37465 \begin_layout Standard
37466
37467 \size footnotesize
37468 '='
37469 \end_layout
37470
37471 \end_inset
37472 </cell>
37473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37474 \begin_inset Text
37475
37476 \begin_layout Standard
37477
37478 \size footnotesize
37479 IC_RIGHT() IC_RESULT()
37480 \end_layout
37481
37482 \end_inset
37483 </cell>
37484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37485 \begin_inset Text
37486
37487 \begin_layout Standard
37488
37489 \size footnotesize
37490 Assignment
37491 \end_layout
37492
37493 \end_inset
37494 </cell>
37495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37496 \begin_inset Text
37497
37498 \begin_layout Standard
37499
37500 \size footnotesize
37501 IC_RESULT = IC_RIGHT;
37502 \end_layout
37503
37504 \end_inset
37505 </cell>
37506 </row>
37507 <row topline="true">
37508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37509 \begin_inset Text
37510
37511 \begin_layout Standard
37512
37513 \size footnotesize
37514 IFX
37515 \end_layout
37516
37517 \end_inset
37518 </cell>
37519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37520 \begin_inset Text
37521
37522 \begin_layout Standard
37523
37524 \size footnotesize
37525 IC_COND IC_TRUE IC_LABEL
37526 \end_layout
37527
37528 \end_inset
37529 </cell>
37530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37531 \begin_inset Text
37532
37533 \begin_layout Standard
37534
37535 \size footnotesize
37536 Conditional jump.
37537  If true label is present then jump to true label if condition is true else
37538  jump to false label if condition is false 
37539 \end_layout
37540
37541 \end_inset
37542 </cell>
37543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37544 \begin_inset Text
37545
37546 \begin_layout Standard
37547
37548 \size footnotesize
37549 if (IC_COND) goto IC_TRUE; 
37550 \newline
37551 \InsetSpace ~
37552 \InsetSpace ~
37553 Or 
37554 \newline
37555 If (!IC_COND) goto IC_FALSE;
37556 \end_layout
37557
37558 \end_inset
37559 </cell>
37560 </row>
37561 <row topline="true">
37562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37563 \begin_inset Text
37564
37565 \begin_layout Standard
37566
37567 \size footnotesize
37568 ADDRESS_OF
37569 \end_layout
37570
37571 \end_inset
37572 </cell>
37573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37574 \begin_inset Text
37575
37576 \begin_layout Standard
37577
37578 \size footnotesize
37579 IC_LEFT() IC_RESULT()
37580 \end_layout
37581
37582 \end_inset
37583 </cell>
37584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37585 \begin_inset Text
37586
37587 \begin_layout Standard
37588
37589 \size footnotesize
37590 Address of 
37591 \end_layout
37592
37593 \end_inset
37594 </cell>
37595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37596 \begin_inset Text
37597
37598 \begin_layout Standard
37599
37600 \size footnotesize
37601 IC_RESULT = &IC_LEFT();
37602 \end_layout
37603
37604 \end_inset
37605 </cell>
37606 </row>
37607 <row topline="true">
37608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37609 \begin_inset Text
37610
37611 \begin_layout Standard
37612
37613 \size footnotesize
37614 JUMPTABLE
37615 \end_layout
37616
37617 \end_inset
37618 </cell>
37619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37620 \begin_inset Text
37621
37622 \begin_layout Standard
37623
37624 \size footnotesize
37625 IC_JTCOND IC_JTLABELS
37626 \end_layout
37627
37628 \end_inset
37629 </cell>
37630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37631 \begin_inset Text
37632
37633 \begin_layout Standard
37634
37635 \size footnotesize
37636 Jump to list of labels depending on the value of JTCOND
37637 \end_layout
37638
37639 \end_inset
37640 </cell>
37641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37642 \begin_inset Text
37643
37644 \begin_layout Standard
37645
37646 \size footnotesize
37647 Switch statement
37648 \end_layout
37649
37650 \end_inset
37651 </cell>
37652 </row>
37653 <row topline="true">
37654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37655 \begin_inset Text
37656
37657 \begin_layout Standard
37658
37659 \size footnotesize
37660 CAST
37661 \end_layout
37662
37663 \end_inset
37664 </cell>
37665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37666 \begin_inset Text
37667
37668 \begin_layout Standard
37669
37670 \size footnotesize
37671 IC_RIGHT() IC_LEFT() IC_RESULT()
37672 \end_layout
37673
37674 \end_inset
37675 </cell>
37676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37677 \begin_inset Text
37678
37679 \begin_layout Standard
37680
37681 \size footnotesize
37682 Cast types 
37683 \end_layout
37684
37685 \end_inset
37686 </cell>
37687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37688 \begin_inset Text
37689
37690 \begin_layout Standard
37691
37692 \size footnotesize
37693 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37694 \end_layout
37695
37696 \end_inset
37697 </cell>
37698 </row>
37699 <row topline="true">
37700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37701 \begin_inset Text
37702
37703 \begin_layout Standard
37704
37705 \size footnotesize
37706 SEND
37707 \end_layout
37708
37709 \end_inset
37710 </cell>
37711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37712 \begin_inset Text
37713
37714 \begin_layout Standard
37715
37716 \size footnotesize
37717 IC_LEFT()
37718 \end_layout
37719
37720 \end_inset
37721 </cell>
37722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37723 \begin_inset Text
37724
37725 \begin_layout Standard
37726
37727 \size footnotesize
37728 This is used for passing parameters in registers; 
37729 \newline
37730 move IC_LEFT to the next
37731  available parameter register.
37732 \end_layout
37733
37734 \end_inset
37735 </cell>
37736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37737 \begin_inset Text
37738
37739 \begin_layout Standard
37740
37741 \size footnotesize
37742 None
37743 \end_layout
37744
37745 \end_inset
37746 </cell>
37747 </row>
37748 <row topline="true">
37749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37750 \begin_inset Text
37751
37752 \begin_layout Standard
37753
37754 \size footnotesize
37755 RECV
37756 \end_layout
37757
37758 \end_inset
37759 </cell>
37760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37761 \begin_inset Text
37762
37763 \begin_layout Standard
37764
37765 \size footnotesize
37766 IC_RESULT()
37767 \end_layout
37768
37769 \end_inset
37770 </cell>
37771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37772 \begin_inset Text
37773
37774 \begin_layout Standard
37775
37776 \size footnotesize
37777 This is used for receiving parameters passed in registers;
37778 \newline
37779 Move the values
37780  in the next parameter register to IC_RESULT 
37781 \end_layout
37782
37783 \end_inset
37784 </cell>
37785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37786 \begin_inset Text
37787
37788 \begin_layout Standard
37789
37790 \size footnotesize
37791 None
37792 \end_layout
37793
37794 \end_inset
37795 </cell>
37796 </row>
37797 <row topline="true" bottomline="true">
37798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37799 \begin_inset Text
37800
37801 \begin_layout Standard
37802
37803 \shape slanted
37804 \size footnotesize
37805 (some more have been added)
37806 \end_layout
37807
37808 \end_inset
37809 </cell>
37810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37811 \begin_inset Text
37812
37813 \begin_layout Standard
37814
37815 \end_layout
37816
37817 \end_inset
37818 </cell>
37819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37820 \begin_inset Text
37821
37822 \begin_layout Standard
37823
37824 \end_layout
37825
37826 \end_inset
37827 </cell>
37828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37829 \begin_inset Text
37830
37831 \begin_layout Standard
37832
37833 \shape slanted
37834 \size footnotesize
37835 see f.e.
37836  
37837 \family typewriter
37838 gen51Code()
37839 \family default
37840  in 
37841 \family typewriter
37842 src/mcs51/gen.c
37843 \end_layout
37844
37845 \end_inset
37846 </cell>
37847 </row>
37848 </lyxtabular>
37849
37850 \end_inset
37851
37852
37853 \end_layout
37854
37855 \begin_layout Standard
37856 \begin_inset Note Note
37857 status collapsed
37858
37859 \begin_layout Standard
37860 In the original article Figure II was announced to be downloadable on 
37861 \shape italic
37862 Circuit Cellar
37863 \shape default
37864 's web site.
37865  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37866 \end_layout
37867
37868 \end_inset
37869
37870
37871 \end_layout
37872
37873 \begin_layout Paragraph*
37874 ICode Example
37875 \begin_inset LatexCommand \index{iCode}
37876
37877 \end_inset
37878
37879
37880 \end_layout
37881
37882 \begin_layout Standard
37883 This section shows some details of iCode.
37884  The example C code does not do anything useful; it is used as an example
37885  to illustrate the intermediate code generated by the compiler.
37886 \end_layout
37887
37888 \begin_layout Verse
37889
37890 \family typewriter
37891 1.\InsetSpace ~
37892 xdata int * p;
37893 \newline
37894 2.\InsetSpace ~
37895 int gint;
37896 \newline
37897 3.\InsetSpace ~
37898 /* This function does nothing useful.
37899  It is used
37900 \newline
37901 4.\InsetSpace ~
37902 \InsetSpace ~
37903 \InsetSpace ~
37904 \InsetSpace ~
37905 for the purpose of explaining iCode */
37906 \newline
37907 5.\InsetSpace ~
37908 short function (data
37909  int *x)
37910 \newline
37911 6.\InsetSpace ~
37912 {
37913 \newline
37914 7.\InsetSpace ~
37915 \InsetSpace ~
37916 \InsetSpace ~
37917 short i=10; \InsetSpace ~
37918 \InsetSpace ~
37919 /* dead initialization eliminated */
37920 \newline
37921 8.\InsetSpace ~
37922 \InsetSpace ~
37923 \InsetSpace ~
37924 short sum=10;
37925  /* dead initialization eliminated */
37926 \newline
37927 9.\InsetSpace ~
37928 \InsetSpace ~
37929 \InsetSpace ~
37930 short mul;
37931 \newline
37932 10.\InsetSpace ~
37933 \InsetSpace ~
37934 int j ;
37935 \newline
37936 11.\InsetSpace ~
37937 \InsetSpace ~
37938 while (*x) *x++
37939  = *p++; 
37940 \newline
37941 12.\InsetSpace ~
37942 \InsetSpace ~
37943 \InsetSpace ~
37944 \InsetSpace ~
37945 sum = 0 ; 
37946 \newline
37947 13.\InsetSpace ~
37948 \InsetSpace ~
37949 mul = 0;
37950 \newline
37951 14.\InsetSpace ~
37952 \InsetSpace ~
37953 /* compiler detects i,j to be induction
37954  variables */
37955 \newline
37956 15.\InsetSpace ~
37957 \InsetSpace ~
37958 for (i = 0, j = 10 ; i < 10 ; i++, j
37959 \family default
37960 -
37961 \begin_inset ERT
37962 status collapsed
37963
37964 \begin_layout Standard
37965
37966
37967 \backslash
37968 /
37969 \end_layout
37970
37971 \end_inset
37972
37973 -
37974 \family typewriter
37975 ) {
37976 \newline
37977 16.\InsetSpace ~
37978 \InsetSpace ~
37979 \InsetSpace ~
37980 \InsetSpace ~
37981 sum += i;
37982 \newline
37983 17.\InsetSpace ~
37984 \InsetSpace ~
37985 \InsetSpace ~
37986 \InsetSpace ~
37987 mul += i * 3; \InsetSpace ~
37988 \InsetSpace ~
37989 /* this multiplication remains */
37990 \newline
37991 18.\InsetSpace ~
37992 \InsetSpace ~
37993 \InsetSpace ~
37994 \InsetSpace ~
37995 gint +=
37996  j * 3;\InsetSpace ~
37997 \InsetSpace ~
37998 /* this multiplication changed to addition */
37999 \newline
38000 19.\InsetSpace ~
38001 \InsetSpace ~
38002 }
38003 \newline
38004 20.\InsetSpace ~
38005 \InsetSpace ~
38006 return sum+mul;
38007 \newline
38008 21.\InsetSpace ~
38009 }
38010 \end_layout
38011
38012 \begin_layout Standard
38013 In addition to the operands each iCode contains information about the filename
38014  and line it corresponds to in the source file.
38015  The first field in the listing should be interpreted as follows:
38016 \newline
38017
38018 \shape italic
38019 \size footnotesize
38020 Filename(linenumber: iCode Execution sequence number : ICode hash table
38021  key : loop depth of the iCode).
38022 \shape default
38023 \size default
38024
38025 \newline
38026 Then follows the human readable form of the ICode operation.
38027  Each operand of this triplet form can be of three basic types a) compiler
38028  generated temporary b) user defined variable c) a constant value.
38029  Note that local variables and parameters are replaced by compiler generated
38030  temporaries.
38031  Live ranges
38032 \begin_inset LatexCommand \index{Live range analysis}
38033
38034 \end_inset
38035
38036  are computed only for temporaries (i.e.
38037  live ranges are not computed for global variables).
38038  Registers
38039 \begin_inset LatexCommand \index{Register allocation}
38040
38041 \end_inset
38042
38043  are allocated for temporaries only.
38044  Operands are formatted in the following manner:
38045 \newline
38046
38047 \shape italic
38048 \size footnotesize
38049 Operand Name [lr live-from : live-to ] { type information } [ registers
38050  allocated ].
38051 \shape default
38052 \size default
38053
38054 \newline
38055 As mentioned earlier the live ranges are computed in terms of the execution
38056  sequence number of the iCodes, for example 
38057 \newline
38058 the iTemp0 is live from (i.e.
38059  first defined in iCode with execution sequence number 3, and is last used
38060  in the iCode with sequence number 5).
38061  For induction variables such as iTemp21 the live range computation extends
38062  the lifetime from the start to the end of the loop.
38063 \newline
38064 The register allocator
38065  used the live range information to allocate registers, the same registers
38066  may be used for different temporaries if their live ranges do not overlap,
38067  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38068  ranges do not overlap.
38069  In addition the allocator also takes into consideration the type and usage
38070  of a temporary, for example itemp6 is a pointer to near space and is used
38071  as to fetch data from (i.e.
38072  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38073  Some short lived temporaries are allocated to special registers which have
38074  meaning to the code generator e.g.
38075  iTemp13 is allocated to a pseudo register CC which tells the back end that
38076  the temporary is used only for a conditional jump the code generation makes
38077  use of this information to optimize a compare and jump ICode.
38078 \newline
38079 There are several
38080  loop optimizations
38081 \begin_inset LatexCommand \index{Loop optimization}
38082
38083 \end_inset
38084
38085  performed by the compiler.
38086  It can detect induction variables iTemp21(i) and iTemp23(j).
38087  Also note the compiler does selective strength reduction
38088 \begin_inset LatexCommand \index{Strength reduction}
38089
38090 \end_inset
38091
38092 , i.e.
38093  the multiplication of an induction variable in line 18 (gint = j * 3) is
38094  changed to addition, a new temporary iTemp17 is allocated and assigned
38095  a initial value, a constant 3 is then added for each iteration of the loop.
38096  The compiler does not change the multiplication
38097 \begin_inset LatexCommand \index{Multiplication}
38098
38099 \end_inset
38100
38101  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38102 \newline
38103
38104 Note the dead code elimination
38105 \begin_inset LatexCommand \index{Dead-code elimination}
38106
38107 \end_inset
38108
38109  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38110  respectively.
38111 \newline
38112
38113 \end_layout
38114
38115 \begin_layout Standard
38116
38117 \size footnotesize
38118 Sample.c (5:1:0:0) _entry($9) :
38119 \end_layout
38120
38121 \begin_layout Standard
38122
38123 \size footnotesize
38124 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38125 \end_layout
38126
38127 \begin_layout Standard
38128
38129 \size footnotesize
38130 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38131 \end_layout
38132
38133 \begin_layout Standard
38134
38135 \size footnotesize
38136 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38137 \end_layout
38138
38139 \begin_layout Standard
38140
38141 \size footnotesize
38142 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38143  * int}[r2]
38144 \end_layout
38145
38146 \begin_layout Standard
38147
38148 \size footnotesize
38149 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38150 \end_layout
38151
38152 \begin_layout Standard
38153
38154 \size footnotesize
38155 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38156  int}[r0]]
38157 \end_layout
38158
38159 \begin_layout Standard
38160
38161 \size footnotesize
38162 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38163 \end_layout
38164
38165 \begin_layout Standard
38166
38167 \size footnotesize
38168 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38169  * int}
38170 \end_layout
38171
38172 \begin_layout Standard
38173
38174 \size footnotesize
38175 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38176  {short}
38177 \end_layout
38178
38179 \begin_layout Standard
38180
38181 \size footnotesize
38182 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38183  * int}[DPTR]]
38184 \end_layout
38185
38186 \begin_layout Standard
38187
38188 \size footnotesize
38189 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38190 }[r2 r3]
38191 \end_layout
38192
38193 \begin_layout Standard
38194
38195 \size footnotesize
38196 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38197  * int}[r0] + 0x2 {short}
38198 \end_layout
38199
38200 \begin_layout Standard
38201
38202 \size footnotesize
38203 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38204 \end_layout
38205
38206 \begin_layout Standard
38207
38208 \size footnotesize
38209 Sample.c(11:17:21:0)_whilebreak_0($3) :
38210 \end_layout
38211
38212 \begin_layout Standard
38213
38214 \size footnotesize
38215 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38216 \end_layout
38217
38218 \begin_layout Standard
38219
38220 \size footnotesize
38221 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38222 \end_layout
38223
38224 \begin_layout Standard
38225
38226 \size footnotesize
38227 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38228 \end_layout
38229
38230 \begin_layout Standard
38231
38232 \size footnotesize
38233 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38234 \end_layout
38235
38236 \begin_layout Standard
38237
38238 \size footnotesize
38239 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38240 \end_layout
38241
38242 \begin_layout Standard
38243
38244 \size footnotesize
38245 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38246 \end_layout
38247
38248 \begin_layout Standard
38249
38250 \size footnotesize
38251 Sample.c(15:24:26:1)_forcond_0($4) :
38252 \end_layout
38253
38254 \begin_layout Standard
38255
38256 \size footnotesize
38257 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38258  < 0xa {short}
38259 \end_layout
38260
38261 \begin_layout Standard
38262
38263 \size footnotesize
38264 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38265 \end_layout
38266
38267 \begin_layout Standard
38268
38269 \size footnotesize
38270 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38271  + ITemp21 [lr21:38]{short}[r4]
38272 \end_layout
38273
38274 \begin_layout Standard
38275
38276 \size footnotesize
38277 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38278  * 0x3 {short}
38279 \end_layout
38280
38281 \begin_layout Standard
38282
38283 \size footnotesize
38284 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38285  + iTemp15 [lr29:30]{short}[r1]
38286 \end_layout
38287
38288 \begin_layout Standard
38289
38290 \size footnotesize
38291 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38292  r0]- 0x3 {short}
38293 \end_layout
38294
38295 \begin_layout Standard
38296
38297 \size footnotesize
38298 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38299 int}[r7 r0]
38300 \end_layout
38301
38302 \begin_layout Standard
38303
38304 \size footnotesize
38305 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38306  + 0x1 {short}
38307 \end_layout
38308
38309 \begin_layout Standard
38310
38311 \size footnotesize
38312 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38313  r6]- 0x1 {short}
38314 \end_layout
38315
38316 \begin_layout Standard
38317
38318 \size footnotesize
38319 Sample.c(19:38:47:1) goto _forcond_0($4)
38320 \end_layout
38321
38322 \begin_layout Standard
38323
38324 \size footnotesize
38325 Sample.c(19:39:48:0)_forbreak_0($7) :
38326 \end_layout
38327
38328 \begin_layout Standard
38329
38330 \size footnotesize
38331 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38332  + ITemp11 [lr19:40]{short}[r3]
38333 \end_layout
38334
38335 \begin_layout Standard
38336
38337 \size footnotesize
38338 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38339 \end_layout
38340
38341 \begin_layout Standard
38342
38343 \size footnotesize
38344 Sample.c(20:42:51:0)_return($8) :
38345 \end_layout
38346
38347 \begin_layout Standard
38348
38349 \size footnotesize
38350 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38351 \size default
38352
38353 \newline
38354
38355 \newline
38356 Finally the code generated for this function:
38357 \newline
38358
38359 \end_layout
38360
38361 \begin_layout Standard
38362
38363 \size footnotesize
38364 .area DSEG (DATA)
38365 \end_layout
38366
38367 \begin_layout Standard
38368
38369 \size footnotesize
38370 _p::
38371 \end_layout
38372
38373 \begin_layout Standard
38374
38375 \size footnotesize
38376 \InsetSpace ~
38377 \InsetSpace ~
38378 .ds 2
38379 \end_layout
38380
38381 \begin_layout Standard
38382
38383 \size footnotesize
38384 _gint::
38385 \end_layout
38386
38387 \begin_layout Standard
38388
38389 \size footnotesize
38390 \InsetSpace ~
38391 \InsetSpace ~
38392 .ds 2
38393 \end_layout
38394
38395 \begin_layout Standard
38396
38397 \size footnotesize
38398 ; sample.c 5
38399 \end_layout
38400
38401 \begin_layout Standard
38402
38403 \size footnotesize
38404 ; ----------------------------------------------
38405 \end_layout
38406
38407 \begin_layout Standard
38408
38409 \size footnotesize
38410 ; function function
38411 \end_layout
38412
38413 \begin_layout Standard
38414
38415 \size footnotesize
38416 ; ----------------------------------------------
38417 \end_layout
38418
38419 \begin_layout Standard
38420
38421 \size footnotesize
38422 _function:
38423 \end_layout
38424
38425 \begin_layout Standard
38426
38427 \size footnotesize
38428 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38429 \end_layout
38430
38431 \begin_layout Standard
38432
38433 \size footnotesize
38434 \InsetSpace ~
38435 \InsetSpace ~
38436 mov r2,dpl
38437 \end_layout
38438
38439 \begin_layout Standard
38440
38441 \size footnotesize
38442 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38443 \end_layout
38444
38445 \begin_layout Standard
38446
38447 \size footnotesize
38448 \InsetSpace ~
38449 \InsetSpace ~
38450 mov ar0,r2
38451 \end_layout
38452
38453 \begin_layout Standard
38454
38455 \size footnotesize
38456 ;_whilecontinue_0($1) :
38457 \end_layout
38458
38459 \begin_layout Standard
38460
38461 \size footnotesize
38462 00101$:
38463 \end_layout
38464
38465 \begin_layout Standard
38466
38467 \size footnotesize
38468 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38469 \end_layout
38470
38471 \begin_layout Standard
38472
38473 \size footnotesize
38474 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38475 \end_layout
38476
38477 \begin_layout Standard
38478
38479 \size footnotesize
38480 \InsetSpace ~
38481 \InsetSpace ~
38482 mov ar2,@r0
38483 \end_layout
38484
38485 \begin_layout Standard
38486
38487 \size footnotesize
38488 \InsetSpace ~
38489 \InsetSpace ~
38490 inc r0
38491 \end_layout
38492
38493 \begin_layout Standard
38494
38495 \size footnotesize
38496 \InsetSpace ~
38497 \InsetSpace ~
38498 mov ar3,@r0
38499 \end_layout
38500
38501 \begin_layout Standard
38502
38503 \size footnotesize
38504 \InsetSpace ~
38505 \InsetSpace ~
38506 dec r0
38507 \end_layout
38508
38509 \begin_layout Standard
38510
38511 \size footnotesize
38512 \InsetSpace ~
38513 \InsetSpace ~
38514 mov a,r2
38515 \end_layout
38516
38517 \begin_layout Standard
38518
38519 \size footnotesize
38520 \InsetSpace ~
38521 \InsetSpace ~
38522 orl a,r3
38523 \end_layout
38524
38525 \begin_layout Standard
38526
38527 \size footnotesize
38528 \InsetSpace ~
38529 \InsetSpace ~
38530 jz 00103$
38531 \end_layout
38532
38533 \begin_layout Standard
38534
38535 \size footnotesize
38536 00114$:
38537 \end_layout
38538
38539 \begin_layout Standard
38540
38541 \size footnotesize
38542 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38543 \end_layout
38544
38545 \begin_layout Standard
38546
38547 \size footnotesize
38548 \InsetSpace ~
38549 \InsetSpace ~
38550 mov dpl,_p
38551 \end_layout
38552
38553 \begin_layout Standard
38554
38555 \size footnotesize
38556 \InsetSpace ~
38557 \InsetSpace ~
38558 mov dph,(_p + 1)
38559 \end_layout
38560
38561 \begin_layout Standard
38562
38563 \size footnotesize
38564 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38565 \end_layout
38566
38567 \begin_layout Standard
38568
38569 \size footnotesize
38570 \InsetSpace ~
38571 \InsetSpace ~
38572 mov a,#0x02
38573 \end_layout
38574
38575 \begin_layout Standard
38576
38577 \size footnotesize
38578 \InsetSpace ~
38579 \InsetSpace ~
38580 add a,_p
38581 \end_layout
38582
38583 \begin_layout Standard
38584
38585 \size footnotesize
38586 \InsetSpace ~
38587 \InsetSpace ~
38588 mov _p,a
38589 \end_layout
38590
38591 \begin_layout Standard
38592
38593 \size footnotesize
38594 \InsetSpace ~
38595 \InsetSpace ~
38596 clr a
38597 \end_layout
38598
38599 \begin_layout Standard
38600
38601 \size footnotesize
38602 \InsetSpace ~
38603 \InsetSpace ~
38604 addc a,(_p + 1)
38605 \end_layout
38606
38607 \begin_layout Standard
38608
38609 \size footnotesize
38610 \InsetSpace ~
38611 \InsetSpace ~
38612 mov (_p + 1),a
38613 \end_layout
38614
38615 \begin_layout Standard
38616
38617 \size footnotesize
38618 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38619 \end_layout
38620
38621 \begin_layout Standard
38622
38623 \size footnotesize
38624 \InsetSpace ~
38625 \InsetSpace ~
38626 movx a,@dptr
38627 \end_layout
38628
38629 \begin_layout Standard
38630
38631 \size footnotesize
38632 \InsetSpace ~
38633 \InsetSpace ~
38634 mov r2,a
38635 \end_layout
38636
38637 \begin_layout Standard
38638
38639 \size footnotesize
38640 \InsetSpace ~
38641 \InsetSpace ~
38642 inc dptr
38643 \end_layout
38644
38645 \begin_layout Standard
38646
38647 \size footnotesize
38648 \InsetSpace ~
38649 \InsetSpace ~
38650 movx a,@dptr
38651 \end_layout
38652
38653 \begin_layout Standard
38654
38655 \size footnotesize
38656 \InsetSpace ~
38657 \InsetSpace ~
38658 mov r3,a
38659 \end_layout
38660
38661 \begin_layout Standard
38662
38663 \size footnotesize
38664 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38665 \end_layout
38666
38667 \begin_layout Standard
38668
38669 \size footnotesize
38670 \InsetSpace ~
38671 \InsetSpace ~
38672 mov @r0,ar2
38673 \end_layout
38674
38675 \begin_layout Standard
38676
38677 \size footnotesize
38678 \InsetSpace ~
38679 \InsetSpace ~
38680 inc r0
38681 \end_layout
38682
38683 \begin_layout Standard
38684
38685 \size footnotesize
38686 \InsetSpace ~
38687 \InsetSpace ~
38688 mov @r0,ar3
38689 \end_layout
38690
38691 \begin_layout Standard
38692
38693 \size footnotesize
38694 ; iTemp6 [lr5:16]{_near * int}[r0] = 
38695 \end_layout
38696
38697 \begin_layout Standard
38698
38699 \size footnotesize
38700 ; iTemp6 [lr5:16]{_near * int}[r0] + 
38701 \end_layout
38702
38703 \begin_layout Standard
38704
38705 \size footnotesize
38706 ; 0x2 {short}
38707 \end_layout
38708
38709 \begin_layout Standard
38710
38711 \size footnotesize
38712 \InsetSpace ~
38713 \InsetSpace ~
38714 inc r0
38715 \end_layout
38716
38717 \begin_layout Standard
38718
38719 \size footnotesize
38720 ; goto _whilecontinue_0($1)
38721 \end_layout
38722
38723 \begin_layout Standard
38724
38725 \size footnotesize
38726 \InsetSpace ~
38727 \InsetSpace ~
38728 sjmp 00101$
38729 \end_layout
38730
38731 \begin_layout Standard
38732
38733 \size footnotesize
38734 ; _whilebreak_0($3) :
38735 \end_layout
38736
38737 \begin_layout Standard
38738
38739 \size footnotesize
38740 00103$:
38741 \end_layout
38742
38743 \begin_layout Standard
38744
38745 \size footnotesize
38746 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38747 \end_layout
38748
38749 \begin_layout Standard
38750
38751 \size footnotesize
38752 \InsetSpace ~
38753 \InsetSpace ~
38754 mov r2,#0x00
38755 \end_layout
38756
38757 \begin_layout Standard
38758
38759 \size footnotesize
38760 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38761 \end_layout
38762
38763 \begin_layout Standard
38764
38765 \size footnotesize
38766 \InsetSpace ~
38767 \InsetSpace ~
38768 mov r3,#0x00
38769 \end_layout
38770
38771 \begin_layout Standard
38772
38773 \size footnotesize
38774 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38775 \end_layout
38776
38777 \begin_layout Standard
38778
38779 \size footnotesize
38780 \InsetSpace ~
38781 \InsetSpace ~
38782 mov r4,#0x00
38783 \end_layout
38784
38785 \begin_layout Standard
38786
38787 \size footnotesize
38788 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38789 \end_layout
38790
38791 \begin_layout Standard
38792
38793 \size footnotesize
38794 \InsetSpace ~
38795 \InsetSpace ~
38796 mov r5,#0x0A
38797 \end_layout
38798
38799 \begin_layout Standard
38800
38801 \size footnotesize
38802 \InsetSpace ~
38803 \InsetSpace ~
38804 mov r6,#0x00
38805 \end_layout
38806
38807 \begin_layout Standard
38808
38809 \size footnotesize
38810 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38811 \end_layout
38812
38813 \begin_layout Standard
38814
38815 \size footnotesize
38816 \InsetSpace ~
38817 \InsetSpace ~
38818 mov r7,#0x1E
38819 \end_layout
38820
38821 \begin_layout Standard
38822
38823 \size footnotesize
38824 \InsetSpace ~
38825 \InsetSpace ~
38826 mov r0,#0x00
38827 \end_layout
38828
38829 \begin_layout Standard
38830
38831 \size footnotesize
38832 ; _forcond_0($4) :
38833 \end_layout
38834
38835 \begin_layout Standard
38836
38837 \size footnotesize
38838 00104$:
38839 \end_layout
38840
38841 \begin_layout Standard
38842
38843 \size footnotesize
38844 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38845 \end_layout
38846
38847 \begin_layout Standard
38848
38849 \size footnotesize
38850 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38851 \end_layout
38852
38853 \begin_layout Standard
38854
38855 \size footnotesize
38856 \InsetSpace ~
38857 \InsetSpace ~
38858 clr c
38859 \end_layout
38860
38861 \begin_layout Standard
38862
38863 \size footnotesize
38864 \InsetSpace ~
38865 \InsetSpace ~
38866 mov a,r4
38867 \end_layout
38868
38869 \begin_layout Standard
38870
38871 \size footnotesize
38872 \InsetSpace ~
38873 \InsetSpace ~
38874 xrl a,#0x80
38875 \end_layout
38876
38877 \begin_layout Standard
38878
38879 \size footnotesize
38880 \InsetSpace ~
38881 \InsetSpace ~
38882 subb a,#0x8a
38883 \end_layout
38884
38885 \begin_layout Standard
38886
38887 \size footnotesize
38888 \InsetSpace ~
38889 \InsetSpace ~
38890 jnc 00107$
38891 \end_layout
38892
38893 \begin_layout Standard
38894
38895 \size footnotesize
38896 00115$:
38897 \end_layout
38898
38899 \begin_layout Standard
38900
38901 \size footnotesize
38902 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
38903 \end_layout
38904
38905 \begin_layout Standard
38906
38907 \size footnotesize
38908 ; iTemp21 [lr21:38]{short}[r4]
38909 \end_layout
38910
38911 \begin_layout Standard
38912
38913 \size footnotesize
38914 \InsetSpace ~
38915 \InsetSpace ~
38916 mov a,r4
38917 \end_layout
38918
38919 \begin_layout Standard
38920
38921 \size footnotesize
38922 \InsetSpace ~
38923 \InsetSpace ~
38924 add a,r2
38925 \end_layout
38926
38927 \begin_layout Standard
38928
38929 \size footnotesize
38930 \InsetSpace ~
38931 \InsetSpace ~
38932 mov r2,a
38933 \end_layout
38934
38935 \begin_layout Standard
38936
38937 \size footnotesize
38938 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38939 \end_layout
38940
38941 \begin_layout Standard
38942
38943 \size footnotesize
38944 \InsetSpace ~
38945 \InsetSpace ~
38946 mov b,#0x03
38947 \end_layout
38948
38949 \begin_layout Standard
38950
38951 \size footnotesize
38952 \InsetSpace ~
38953 \InsetSpace ~
38954 mov a,r4
38955 \end_layout
38956
38957 \begin_layout Standard
38958
38959 \size footnotesize
38960 \InsetSpace ~
38961 \InsetSpace ~
38962 mul ab
38963 \end_layout
38964
38965 \begin_layout Standard
38966
38967 \size footnotesize
38968 \InsetSpace ~
38969 \InsetSpace ~
38970 mov r1,a
38971 \end_layout
38972
38973 \begin_layout Standard
38974
38975 \size footnotesize
38976 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
38977 \end_layout
38978
38979 \begin_layout Standard
38980
38981 \size footnotesize
38982 ; iTemp15 [lr29:30]{short}[r1]
38983 \end_layout
38984
38985 \begin_layout Standard
38986
38987 \size footnotesize
38988 \InsetSpace ~
38989 \InsetSpace ~
38990 add a,r3
38991 \end_layout
38992
38993 \begin_layout Standard
38994
38995 \size footnotesize
38996 \InsetSpace ~
38997 \InsetSpace ~
38998 mov r3,a
38999 \end_layout
39000
39001 \begin_layout Standard
39002
39003 \size footnotesize
39004 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39005 \end_layout
39006
39007 \begin_layout Standard
39008
39009 \size footnotesize
39010 \InsetSpace ~
39011 \InsetSpace ~
39012 mov a,r7
39013 \end_layout
39014
39015 \begin_layout Standard
39016
39017 \size footnotesize
39018 \InsetSpace ~
39019 \InsetSpace ~
39020 add a,#0xfd
39021 \end_layout
39022
39023 \begin_layout Standard
39024
39025 \size footnotesize
39026 \InsetSpace ~
39027 \InsetSpace ~
39028 mov r7,a
39029 \end_layout
39030
39031 \begin_layout Standard
39032
39033 \size footnotesize
39034 \InsetSpace ~
39035 \InsetSpace ~
39036 mov a,r0
39037 \end_layout
39038
39039 \begin_layout Standard
39040
39041 \size footnotesize
39042 \InsetSpace ~
39043 \InsetSpace ~
39044 addc a,#0xff
39045 \end_layout
39046
39047 \begin_layout Standard
39048
39049 \size footnotesize
39050 \InsetSpace ~
39051 \InsetSpace ~
39052 mov r0,a
39053 \end_layout
39054
39055 \begin_layout Standard
39056
39057 \size footnotesize
39058 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39059 \end_layout
39060
39061 \begin_layout Standard
39062
39063 \size footnotesize
39064 \InsetSpace ~
39065 \InsetSpace ~
39066 mov a,r7
39067 \end_layout
39068
39069 \begin_layout Standard
39070
39071 \size footnotesize
39072 \InsetSpace ~
39073 \InsetSpace ~
39074 add a,_gint
39075 \end_layout
39076
39077 \begin_layout Standard
39078
39079 \size footnotesize
39080 \InsetSpace ~
39081 \InsetSpace ~
39082 mov _gint,a
39083 \end_layout
39084
39085 \begin_layout Standard
39086
39087 \size footnotesize
39088 \InsetSpace ~
39089 \InsetSpace ~
39090 mov a,r0
39091 \end_layout
39092
39093 \begin_layout Standard
39094
39095 \size footnotesize
39096 \InsetSpace ~
39097 \InsetSpace ~
39098 addc a,(_gint + 1)
39099 \end_layout
39100
39101 \begin_layout Standard
39102
39103 \size footnotesize
39104 \InsetSpace ~
39105 \InsetSpace ~
39106 mov (_gint + 1),a
39107 \end_layout
39108
39109 \begin_layout Standard
39110
39111 \size footnotesize
39112 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39113 \end_layout
39114
39115 \begin_layout Standard
39116
39117 \size footnotesize
39118 \InsetSpace ~
39119 \InsetSpace ~
39120 inc r4
39121 \end_layout
39122
39123 \begin_layout Standard
39124
39125 \size footnotesize
39126 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39127 \end_layout
39128
39129 \begin_layout Standard
39130
39131 \size footnotesize
39132 \InsetSpace ~
39133 \InsetSpace ~
39134 dec r5
39135 \end_layout
39136
39137 \begin_layout Standard
39138
39139 \size footnotesize
39140 \InsetSpace ~
39141 \InsetSpace ~
39142 cjne r5,#0xff,00104$
39143 \end_layout
39144
39145 \begin_layout Standard
39146
39147 \size footnotesize
39148 \InsetSpace ~
39149 \InsetSpace ~
39150 dec r6
39151 \end_layout
39152
39153 \begin_layout Standard
39154
39155 \size footnotesize
39156 ; goto _forcond_0($4)
39157 \end_layout
39158
39159 \begin_layout Standard
39160
39161 \size footnotesize
39162 \InsetSpace ~
39163 \InsetSpace ~
39164 sjmp 00104$
39165 \end_layout
39166
39167 \begin_layout Standard
39168
39169 \size footnotesize
39170 ; _forbreak_0($7) :
39171 \end_layout
39172
39173 \begin_layout Standard
39174
39175 \size footnotesize
39176 00107$:
39177 \end_layout
39178
39179 \begin_layout Standard
39180
39181 \size footnotesize
39182 ; ret iTemp24 [lr40:41]{short}
39183 \end_layout
39184
39185 \begin_layout Standard
39186
39187 \size footnotesize
39188 \InsetSpace ~
39189 \InsetSpace ~
39190 mov a,r3
39191 \end_layout
39192
39193 \begin_layout Standard
39194
39195 \size footnotesize
39196 \InsetSpace ~
39197 \InsetSpace ~
39198 add a,r2
39199 \end_layout
39200
39201 \begin_layout Standard
39202
39203 \size footnotesize
39204 \InsetSpace ~
39205 \InsetSpace ~
39206 mov dpl,a
39207 \end_layout
39208
39209 \begin_layout Standard
39210
39211 \size footnotesize
39212 ; _return($8) :
39213 \end_layout
39214
39215 \begin_layout Standard
39216
39217 \size footnotesize
39218 00108$:
39219 \end_layout
39220
39221 \begin_layout Standard
39222
39223 \size footnotesize
39224 \InsetSpace ~
39225 \InsetSpace ~
39226 ret
39227 \newline
39228
39229 \end_layout
39230
39231 \begin_layout Section
39232 A few words about basic block successors, predecessors and dominators
39233 \end_layout
39234
39235 \begin_layout Standard
39236 Successors are basic blocks
39237 \begin_inset LatexCommand \index{Basic blocks}
39238
39239 \end_inset
39240
39241  that might execute after this basic block.
39242 \newline
39243 Predecessors are basic blocks
39244  that might execute before reaching this basic block.
39245 \newline
39246 Dominators are basic
39247  blocks that WILL execute before reaching this basic block.
39248 \newline
39249
39250 \end_layout
39251
39252 \begin_layout Standard
39253 [basic block 1]
39254 \end_layout
39255
39256 \begin_layout Standard
39257 if (something)
39258 \end_layout
39259
39260 \begin_layout Standard
39261 \InsetSpace ~
39262 \InsetSpace ~
39263 \InsetSpace ~
39264 \InsetSpace ~
39265 [basic block 2]
39266 \end_layout
39267
39268 \begin_layout Standard
39269 else
39270 \end_layout
39271
39272 \begin_layout Standard
39273 \InsetSpace ~
39274 \InsetSpace ~
39275 \InsetSpace ~
39276 \InsetSpace ~
39277 [basic block 3]
39278 \end_layout
39279
39280 \begin_layout Standard
39281 [basic block 4]
39282 \newline
39283
39284 \end_layout
39285
39286 \begin_layout Standard
39287 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39288 \end_layout
39289
39290 \begin_layout Standard
39291 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39292 \end_layout
39293
39294 \begin_layout Standard
39295 c) domVect of [BB4] = BB1 ...
39296  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39297  was executed.
39298 \end_layout
39299
39300 \begin_layout Chapter
39301 Acknowledgments
39302 \end_layout
39303
39304 \begin_layout Standard
39305 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39306
39307 \end_inset
39308
39309
39310 \newline
39311
39312 \newline
39313
39314 \emph on
39315 Thanks to all the other volunteer developers who have helped with coding,
39316  testing, web-page creation, distribution sets, etc.
39317  You know who you are :-)
39318 \emph default
39319
39320 \newline
39321
39322 \newline
39323
39324 \emph on
39325 Also thanks to Sourceforge 
39326 \begin_inset LatexCommand \url{http://www.sf.net}
39327
39328 \end_inset
39329
39330  which has hosted the project since 1999 and donates significant download
39331  bandwidth and probably more than 
39332 \begin_inset ERT
39333 status collapsed
39334
39335 \begin_layout Standard
39336
39337 $10^{13}$
39338 \end_layout
39339
39340 \end_inset
39341
39342 CPU cycles per day.
39343 \newline
39344  
39345 \begin_inset Note Note
39346 status open
39347
39348 \begin_layout Standard
39349 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39350  minutes for (configure+make+regression test), and there is (i386, amd64,
39351  alpha, ppc64, (mingw32), sparc, macosx).
39352  
39353 \end_layout
39354
39355 \end_inset
39356
39357
39358 \end_layout
39359
39360 \begin_layout Standard
39361 This document was initially written by Sandeep Dutta
39362 \end_layout
39363
39364 \begin_layout Standard
39365 All product names mentioned herein may be trademarks
39366 \begin_inset LatexCommand \index{Trademarks}
39367
39368 \end_inset
39369
39370  of their respective companies.
39371  
39372 \end_layout
39373
39374 \begin_layout Section*
39375 Alphabetical index
39376 \end_layout
39377
39378 \begin_layout Standard
39379 To avoid confusion, the installation and building options for SDCC itself
39380  (chapter 2) are not part of the index.
39381 \end_layout
39382
39383 \begin_layout Standard
39384 \begin_inset LatexCommand \printindex{}
39385
39386 \end_inset
39387
39388
39389 \end_layout
39390
39391 \end_body
39392 \end_document