* doc/sdccman.lyx: -pedantic-parse-number is not in conformance with
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.4 created this file. For more info see http://www.lyx.org/
2 \lyxformat 245
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \fontscheme pslatex
26 \graphics default
27 \paperfontsize default
28 \spacing single
29 \papersize letterpaper
30 \use_geometry true
31 \use_amsmath 1
32 \cite_engine basic
33 \use_bibtopic false
34 \paperorientation portrait
35 \leftmargin 30mm
36 \topmargin 20mm
37 \rightmargin 25mm
38 \bottommargin 20mm
39 \secnumdepth 3
40 \tocdepth 3
41 \paragraph_separation indent
42 \defskip medskip
43 \quotes_language swedish
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47 \tracking_changes false
48 \output_changes true
49 \end_header
50
51 \begin_body
52
53 \begin_layout Standard
54 \begin_inset Note Note
55 status collapsed
56
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59  --version) are written this way: -
60 \begin_inset ERT
61 status collapsed
62
63 \begin_layout Standard
64
65
66 \backslash
67 /
68 \end_layout
69
70 \end_inset
71
72 -
73 \end_layout
74
75 \begin_layout Standard
76 Two resp.
77  three consecutive dashes 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 C99 standard!
6966 \end_layout
6967
6968 \begin_layout List
6969 \labelwidthstring 00.00.0000
6970
6971 \series bold
6972 -Wp\InsetSpace ~
6973 preprocessorOption[,preprocessorOption]
6974 \series default
6975
6976 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6977
6978 \end_inset
6979
6980 ...
6981  Pass the preprocessorOption to the preprocessor 
6982 \family typewriter
6983 sdcpp
6984 \family default
6985
6986 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6987
6988 \end_inset
6989
6990 .
6991  SDCC uses an adapted version of the preprocessor 
6992 \emph on
6993 cpp
6994 \emph default
6995  of the GNU Compiler Collection
6996 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6997
6998 \end_inset
6999
7000  (
7001 \emph on
7002 gcc
7003 \emph default
7004  
7005 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7006
7007 \end_inset
7008
7009 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7010 4.1.1\InsetSpace ~
7011 CPP\InsetSpace ~
7012 Manual
7013  at 
7014 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7015
7016 \end_inset
7017
7018 .
7019 \end_layout
7020
7021 \begin_layout Standard
7022 \begin_inset VSpace bigskip
7023 \end_inset
7024
7025
7026 \end_layout
7027
7028 \begin_layout Subsection
7029 Linker Options
7030 \begin_inset LatexCommand \index{Options linker}
7031
7032 \end_inset
7033
7034
7035 \begin_inset LatexCommand \index{Linker options}
7036
7037 \end_inset
7038
7039
7040 \end_layout
7041
7042 \begin_layout List
7043 \labelwidthstring 00.00.0000
7044
7045 \series bold
7046 -L\InsetSpace ~
7047 -
7048 \series default
7049
7050 \begin_inset ERT
7051 status collapsed
7052
7053 \begin_layout Standard
7054
7055
7056 \backslash
7057 /
7058 \end_layout
7059
7060 \end_inset
7061
7062
7063 \series bold
7064 -lib-path
7065 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7066
7067 \end_inset
7068
7069
7070 \begin_inset LatexCommand \index{-L -\/-lib-path}
7071
7072 \end_inset
7073
7074
7075 \series default
7076 \InsetSpace ~
7077 <absolute path to additional libraries> This option is passed to the linkage
7078  editor's additional libraries
7079 \begin_inset LatexCommand \index{Libraries}
7080
7081 \end_inset
7082
7083  search path.
7084  The path name must be absolute.
7085  Additional library files may be specified in the command line.
7086  See section Compiling programs for more details.
7087 \end_layout
7088
7089 \begin_layout List
7090 \labelwidthstring 00.00.0000
7091
7092 \series bold
7093 -
7094 \begin_inset ERT
7095 status collapsed
7096
7097 \begin_layout Standard
7098
7099
7100 \backslash
7101 /
7102 \end_layout
7103
7104 \end_inset
7105
7106 -xram-loc
7107 \series default
7108
7109 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7110
7111 \end_inset
7112
7113 \InsetSpace ~
7114 <Value> The start location of the external ram
7115 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7116
7117 \end_inset
7118
7119 , default value is 0.
7120  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7121 \begin_inset ERT
7122 status collapsed
7123
7124 \begin_layout Standard
7125
7126
7127 \backslash
7128 /
7129 \end_layout
7130
7131 \end_inset
7132
7133 -xram-loc 0x8000 or -
7134 \begin_inset ERT
7135 status collapsed
7136
7137 \begin_layout Standard
7138
7139
7140 \backslash
7141 /
7142 \end_layout
7143
7144 \end_inset
7145
7146 -xram-loc 32768.
7147 \end_layout
7148
7149 \begin_layout List
7150 \labelwidthstring 00.00.0000
7151
7152 \series bold
7153 -
7154 \begin_inset ERT
7155 status collapsed
7156
7157 \begin_layout Standard
7158
7159
7160 \backslash
7161 /
7162 \end_layout
7163
7164 \end_inset
7165
7166 -code-loc
7167 \series default
7168
7169 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7170
7171 \end_inset
7172
7173 \InsetSpace ~
7174 <Value> The start location of the code
7175 \begin_inset LatexCommand \index{code}
7176
7177 \end_inset
7178
7179  segment, default value 0.
7180  Note when this option is used the interrupt vector table
7181 \begin_inset LatexCommand \index{interrupt vector table}
7182
7183 \end_inset
7184
7185  is also relocated to the given address.
7186  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7187 \begin_inset ERT
7188 status collapsed
7189
7190 \begin_layout Standard
7191
7192
7193 \backslash
7194 /
7195 \end_layout
7196
7197 \end_inset
7198
7199 -code-loc 0x8000 or -
7200 \begin_inset ERT
7201 status collapsed
7202
7203 \begin_layout Standard
7204
7205
7206 \backslash
7207 /
7208 \end_layout
7209
7210 \end_inset
7211
7212 -code-loc 32768.
7213 \end_layout
7214
7215 \begin_layout List
7216 \labelwidthstring 00.00.0000
7217
7218 \series bold
7219 -
7220 \begin_inset ERT
7221 status collapsed
7222
7223 \begin_layout Standard
7224
7225
7226 \backslash
7227 /
7228 \end_layout
7229
7230 \end_inset
7231
7232 -stack-loc
7233 \series default
7234
7235 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7236
7237 \end_inset
7238
7239 \InsetSpace ~
7240 <Value> By default the stack
7241 \begin_inset LatexCommand \index{stack}
7242
7243 \end_inset
7244
7245  is placed after the data segment.
7246  Using this option the stack can be placed anywhere in the internal memory
7247  space of the 8051.
7248  The value entered can be in Hexadecimal or Decimal format, e.g.
7249  -
7250 \begin_inset ERT
7251 status collapsed
7252
7253 \begin_layout Standard
7254
7255
7256 \backslash
7257 /
7258 \end_layout
7259
7260 \end_inset
7261
7262 -stack-loc 0x20 or -
7263 \begin_inset ERT
7264 status collapsed
7265
7266 \begin_layout Standard
7267
7268
7269 \backslash
7270 /
7271 \end_layout
7272
7273 \end_inset
7274
7275 -stack-loc 32.
7276  Since the sp register is incremented before a push or call, the initial
7277  sp will be set to one byte prior the provided value.
7278  The provided value should not overlap any other memory areas such as used
7279  register banks or the data segment and with enough space for the current
7280  application.
7281  The 
7282 \series bold
7283 -
7284 \begin_inset ERT
7285 status collapsed
7286
7287 \begin_layout Standard
7288
7289
7290 \backslash
7291 /
7292 \end_layout
7293
7294 \end_inset
7295
7296 -pack-iram
7297 \series default
7298 \InsetSpace ~
7299
7300 \begin_inset LatexCommand \index{-\/-pack-iram}
7301
7302 \end_inset
7303
7304  option (which is now a default setting) will override this setting, so
7305  you should also specify the 
7306 \series bold
7307 -
7308 \begin_inset ERT
7309 status collapsed
7310
7311 \begin_layout Standard
7312
7313
7314 \backslash
7315 /
7316 \end_layout
7317
7318 \end_inset
7319
7320 -no-pack-iram
7321 \series default
7322 \InsetSpace ~
7323
7324 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7325
7326 \end_inset
7327
7328  option if you need to manually place the stack.
7329 \end_layout
7330
7331 \begin_layout List
7332 \labelwidthstring 00.00.0000
7333
7334 \series bold
7335 -
7336 \begin_inset ERT
7337 status collapsed
7338
7339 \begin_layout Standard
7340
7341
7342 \backslash
7343 /
7344 \end_layout
7345
7346 \end_inset
7347
7348 -xstack-loc
7349 \series default
7350
7351 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7352
7353 \end_inset
7354
7355 \InsetSpace ~
7356 <Value> By default the external stack
7357 \begin_inset LatexCommand \index{xstack}
7358
7359 \end_inset
7360
7361  is placed after the pdata
7362 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7363
7364 \end_inset
7365
7366  segment.
7367  Using this option the xstack can be placed anywhere in the external memory
7368  space of the 8051.
7369  The value entered can be in Hexadecimal or Decimal format, e.g.
7370  -
7371 \begin_inset ERT
7372 status collapsed
7373
7374 \begin_layout Standard
7375
7376
7377 \backslash
7378 /
7379 \end_layout
7380
7381 \end_inset
7382
7383 -xstack-loc 0x8000 or -
7384 \begin_inset ERT
7385 status collapsed
7386
7387 \begin_layout Standard
7388
7389
7390 \backslash
7391 /
7392 \end_layout
7393
7394 \end_inset
7395
7396 -stack-loc 32768.
7397  The provided value should not overlap any other memory areas such as the
7398  pdata or xdata segment and with enough space for the current application.
7399 \end_layout
7400
7401 \begin_layout List
7402 \labelwidthstring 00.00.0000
7403
7404 \series bold
7405 -
7406 \begin_inset ERT
7407 status collapsed
7408
7409 \begin_layout Standard
7410
7411
7412 \backslash
7413 /
7414 \end_layout
7415
7416 \end_inset
7417
7418 -data-loc
7419 \series default
7420
7421 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7422
7423 \end_inset
7424
7425 \InsetSpace ~
7426 <Value> The start location of the internal ram data
7427 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7428
7429 \end_inset
7430
7431  segment.
7432  The value entered can be in Hexadecimal or Decimal format, eg.
7433  -
7434 \begin_inset ERT
7435 status collapsed
7436
7437 \begin_layout Standard
7438
7439
7440 \backslash
7441 /
7442 \end_layout
7443
7444 \end_inset
7445
7446 -data-loc 0x20 or -
7447 \begin_inset ERT
7448 status collapsed
7449
7450 \begin_layout Standard
7451
7452
7453 \backslash
7454 /
7455 \end_layout
7456
7457 \end_inset
7458
7459 -data-loc 32.
7460  (By default, the start location of the internal ram data segment  is set
7461  as low as possible in memory, taking into account the used register banks
7462  and the bit segment at address 0x20.
7463  For example if register banks 0 and 1 are used without bit variables, the
7464  data segment will be set, if -
7465 \begin_inset ERT
7466 status collapsed
7467
7468 \begin_layout Standard
7469
7470
7471 \backslash
7472 /
7473 \end_layout
7474
7475 \end_inset
7476
7477 -data-loc is not used, to location 0x10.)
7478 \end_layout
7479
7480 \begin_layout List
7481 \labelwidthstring 00.00.0000
7482
7483 \series bold
7484 -
7485 \begin_inset ERT
7486 status collapsed
7487
7488 \begin_layout Standard
7489
7490
7491 \backslash
7492 /
7493 \end_layout
7494
7495 \end_inset
7496
7497 -idata-loc
7498 \series default
7499
7500 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7501
7502 \end_inset
7503
7504 \InsetSpace ~
7505 <Value> The start location of the indirectly addressable internal ram
7506 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7507
7508 \end_inset
7509
7510  of the 8051, default value is 0x80.
7511  The value entered can be in Hexadecimal or Decimal format, eg.
7512  -
7513 \begin_inset ERT
7514 status collapsed
7515
7516 \begin_layout Standard
7517
7518
7519 \backslash
7520 /
7521 \end_layout
7522
7523 \end_inset
7524
7525 -idata-loc 0x88 or -
7526 \begin_inset ERT
7527 status collapsed
7528
7529 \begin_layout Standard
7530
7531
7532 \backslash
7533 /
7534 \end_layout
7535
7536 \end_inset
7537
7538 -idata-loc 136.
7539 \end_layout
7540
7541 \begin_layout List
7542 \labelwidthstring 00.00.0000
7543
7544 \series bold
7545 -
7546 \begin_inset ERT
7547 status collapsed
7548
7549 \begin_layout Standard
7550
7551
7552 \backslash
7553 /
7554 \end_layout
7555
7556 \end_inset
7557
7558 -bit-loc
7559 \series default
7560 \InsetSpace ~
7561 <Value> The start location of the bit
7562 \begin_inset LatexCommand \index{bit}
7563
7564 \end_inset
7565
7566  addressable internal ram of the 8051.
7567  This is 
7568 \emph on
7569 not
7570 \emph default
7571  implemented yet.
7572  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7573 -bBSEG=<Value>.
7574 \end_layout
7575
7576 \begin_layout List
7577 \labelwidthstring 00.00.0000
7578
7579 \series bold
7580 -
7581 \begin_inset ERT
7582 status collapsed
7583
7584 \begin_layout Standard
7585
7586
7587 \backslash
7588 /
7589 \end_layout
7590
7591 \end_inset
7592
7593 -out-fmt-ihx
7594 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7595
7596 \end_inset
7597
7598
7599 \bar under
7600  
7601 \series default
7602 \bar default
7603 The linker output (final object code) is in Intel Hex format.
7604 \begin_inset LatexCommand \index{Intel hex format}
7605
7606 \end_inset
7607
7608  This is the default option.
7609  The format itself is documented in the documentation of srecord
7610 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7611
7612 \end_inset
7613
7614 .
7615 \end_layout
7616
7617 \begin_layout List
7618 \labelwidthstring 00.00.0000
7619
7620 \series bold
7621 -
7622 \begin_inset ERT
7623 status collapsed
7624
7625 \begin_layout Standard
7626
7627
7628 \backslash
7629 /
7630 \end_layout
7631
7632 \end_inset
7633
7634 -out-fmt-s19
7635 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7636
7637 \end_inset
7638
7639
7640 \bar under
7641  
7642 \series default
7643 \bar default
7644 The linker output (final object code) is in Motorola S19 format
7645 \begin_inset LatexCommand \index{Motorola S19 format}
7646
7647 \end_inset
7648
7649 .
7650  The format itself is documented in the documentation of srecord.
7651 \end_layout
7652
7653 \begin_layout List
7654 \labelwidthstring 00.00.0000
7655
7656 \series bold
7657 -
7658 \begin_inset ERT
7659 status collapsed
7660
7661 \begin_layout Standard
7662
7663
7664 \backslash
7665 /
7666 \end_layout
7667
7668 \end_inset
7669
7670 -out-fmt-elf
7671 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7672
7673 \end_inset
7674
7675
7676 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7677
7678 \end_inset
7679
7680
7681 \bar under
7682  
7683 \series default
7684 \bar default
7685 The linker output (final object code) is in ELF format
7686 \begin_inset LatexCommand \index{ELF format}
7687
7688 \end_inset
7689
7690 .
7691  (Currently only supported for the HC08
7692 \begin_inset LatexCommand \index{HC08}
7693
7694 \end_inset
7695
7696  processors)
7697 \end_layout
7698
7699 \begin_layout List
7700 \labelwidthstring 00.00.0000
7701
7702 \series bold
7703 -Wl\InsetSpace ~
7704 linkOption[,linkOption]
7705 \series default
7706
7707 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7708
7709 \end_inset
7710
7711 ...
7712  Pass the linkOption to the linker.
7713  If a bootloader is used an option like 
7714 \begin_inset Quotes sld
7715 \end_inset
7716
7717 -Wl\InsetSpace ~
7718 -bCSEG=0x1000
7719 \begin_inset Quotes srd
7720 \end_inset
7721
7722  would be typical to set the start of the code segment.
7723  See also #pragma constseg and #pragma codeseg in section 
7724 \begin_inset LatexCommand \ref{sec:Pragmas}
7725
7726 \end_inset
7727
7728  .
7729  File sdcc/as/doc/asxhtm.html has more on linker options.
7730 \end_layout
7731
7732 \begin_layout Standard
7733 \begin_inset VSpace bigskip
7734 \end_inset
7735
7736
7737 \end_layout
7738
7739 \begin_layout Subsection
7740 MCS51 Options
7741 \begin_inset LatexCommand \index{Options MCS51}
7742
7743 \end_inset
7744
7745
7746 \begin_inset LatexCommand \index{MCS51 options}
7747
7748 \end_inset
7749
7750
7751 \end_layout
7752
7753 \begin_layout List
7754 \labelwidthstring 00.00.0000
7755
7756 \series bold
7757 -
7758 \begin_inset ERT
7759 status collapsed
7760
7761 \begin_layout Standard
7762
7763
7764 \backslash
7765 /
7766 \end_layout
7767
7768 \end_inset
7769
7770 -model-small
7771 \begin_inset LatexCommand \index{-\/-model-small}
7772
7773 \end_inset
7774
7775
7776 \series default
7777 \size large
7778 \emph on
7779  
7780 \size default
7781 \emph default
7782 Generate code for Small Model programs, see section Memory Models for more
7783  details.
7784  This is the default model.
7785 \end_layout
7786
7787 \begin_layout List
7788 \labelwidthstring 00.00.0000
7789
7790 \series bold
7791 -
7792 \begin_inset ERT
7793 status collapsed
7794
7795 \begin_layout Standard
7796
7797
7798 \backslash
7799 /
7800 \end_layout
7801
7802 \end_inset
7803
7804 -model-medium
7805 \begin_inset LatexCommand \index{-\/-model-medium}
7806
7807 \end_inset
7808
7809
7810 \series default
7811  Generate code for Medium model programs, see section Memory Models for
7812  more details.
7813  If this option is used all source files in the project have to be compiled
7814  with this option.
7815  It must also be used when invoking the linker.
7816 \end_layout
7817
7818 \begin_layout List
7819 \labelwidthstring 00.00.0000
7820
7821 \series bold
7822 -
7823 \begin_inset ERT
7824 status collapsed
7825
7826 \begin_layout Standard
7827
7828
7829 \backslash
7830 /
7831 \end_layout
7832
7833 \end_inset
7834
7835 -model-large
7836 \begin_inset LatexCommand \index{-\/-model-large}
7837
7838 \end_inset
7839
7840
7841 \series default
7842  Generate code for Large model programs, see section Memory Models for more
7843  details.
7844  If this option is used all source files in the project have to be compiled
7845  with this option.
7846  It must also be used when invoking the linker.
7847 \end_layout
7848
7849 \begin_layout List
7850 \labelwidthstring 00.00.0000
7851
7852 \series bold
7853 -
7854 \begin_inset ERT
7855 status collapsed
7856
7857 \begin_layout Standard
7858
7859
7860 \backslash
7861 /
7862 \end_layout
7863
7864 \end_inset
7865
7866 -xstack
7867 \begin_inset LatexCommand \index{-\/-xstack}
7868
7869 \end_inset
7870
7871
7872 \series default
7873  Uses a pseudo stack in the pdata
7874 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7875
7876 \end_inset
7877
7878  area (usually the first 256 bytes in the external ram) for allocating variables
7879  and passing parameters.
7880  See section 
7881 \begin_inset LatexCommand \ref{sub:External-Stack}
7882
7883 \end_inset
7884
7885 \InsetSpace ~
7886  External Stack for more details.
7887 \end_layout
7888
7889 \begin_layout List
7890 \labelwidthstring 00.00.0000
7891
7892 \series bold
7893 -
7894 \begin_inset ERT
7895 status collapsed
7896
7897 \begin_layout Standard
7898
7899
7900 \backslash
7901 /
7902 \end_layout
7903
7904 \end_inset
7905
7906 -iram-size
7907 \series default
7908 \InsetSpace ~
7909 <Value>
7910 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7911
7912 \end_inset
7913
7914  Causes the linker to check if the internal ram usage is within limits of
7915  the given value.
7916 \end_layout
7917
7918 \begin_layout List
7919 \labelwidthstring 00.00.0000
7920
7921 \series bold
7922 -
7923 \begin_inset ERT
7924 status collapsed
7925
7926 \begin_layout Standard
7927
7928
7929 \backslash
7930 /
7931 \end_layout
7932
7933 \end_inset
7934
7935 -xram-size
7936 \series default
7937 \InsetSpace ~
7938 <Value>
7939 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7940
7941 \end_inset
7942
7943  Causes the linker to check if the external ram usage is within limits of
7944  the given value.
7945 \end_layout
7946
7947 \begin_layout List
7948 \labelwidthstring 00.00.0000
7949
7950 \series bold
7951 -
7952 \begin_inset ERT
7953 status collapsed
7954
7955 \begin_layout Standard
7956
7957
7958 \backslash
7959 /
7960 \end_layout
7961
7962 \end_inset
7963
7964 -code-size
7965 \series default
7966 \InsetSpace ~
7967 <Value>
7968 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7969
7970 \end_inset
7971
7972  Causes the linker to check if the code memory usage is within limits of
7973  the given value.
7974 \end_layout
7975
7976 \begin_layout List
7977 \labelwidthstring 00.00.0000
7978
7979 \series bold
7980 -
7981 \begin_inset ERT
7982 status collapsed
7983
7984 \begin_layout Standard
7985
7986
7987 \backslash
7988 /
7989 \end_layout
7990
7991 \end_inset
7992
7993 -stack-size
7994 \series default
7995 \InsetSpace ~
7996 <Value>
7997 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7998
7999 \end_inset
8000
8001  Causes the linker to check if there is at minimum <Value> bytes for stack.
8002 \end_layout
8003
8004 \begin_layout List
8005 \labelwidthstring 00.00.0000
8006
8007 \series bold
8008 -
8009 \begin_inset ERT
8010 status collapsed
8011
8012 \begin_layout Standard
8013
8014
8015 \backslash
8016 /
8017 \end_layout
8018
8019 \end_inset
8020
8021 -pack-iram
8022 \series default
8023 \InsetSpace ~
8024
8025 \begin_inset LatexCommand \index{-\/-pack-iram}
8026
8027 \end_inset
8028
8029  Causes the linker to use unused register banks for data variables and pack
8030  data, idata and stack together.
8031  This is the default now.
8032 \end_layout
8033
8034 \begin_layout List
8035 \labelwidthstring 00.00.0000
8036
8037 \series bold
8038 -
8039 \begin_inset ERT
8040 status collapsed
8041
8042 \begin_layout Standard
8043
8044
8045 \backslash
8046 /
8047 \end_layout
8048
8049 \end_inset
8050
8051 -no-pack-iram
8052 \series default
8053 \InsetSpace ~
8054
8055 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8056
8057 \end_inset
8058
8059  Causes the linker to use old style for allocating memory areas.
8060 \end_layout
8061
8062 \begin_layout Standard
8063 \begin_inset VSpace bigskip
8064 \end_inset
8065
8066
8067 \end_layout
8068
8069 \begin_layout Subsection
8070 DS390 / DS400 Options
8071 \begin_inset LatexCommand \index{Options DS390}
8072
8073 \end_inset
8074
8075
8076 \begin_inset LatexCommand \index{DS390}
8077
8078 \end_inset
8079
8080
8081 \end_layout
8082
8083 \begin_layout List
8084 \labelwidthstring 00.00.0000
8085
8086 \series bold
8087 -
8088 \begin_inset ERT
8089 status collapsed
8090
8091 \begin_layout Standard
8092
8093
8094 \backslash
8095 /
8096 \end_layout
8097
8098 \end_inset
8099
8100 -model-flat24
8101 \series default
8102
8103 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8104
8105 \end_inset
8106
8107
8108 \size large
8109 \emph on
8110  
8111 \size default
8112 \emph default
8113 Generate 24-bit flat mode code.
8114  This is the one and only that the ds390 code generator supports right now
8115  and is default when using 
8116 \emph on
8117 -mds390
8118 \emph default
8119 .
8120  See section Memory Models for more details.
8121 \end_layout
8122
8123 \begin_layout List
8124 \labelwidthstring 00.00.0000
8125
8126 \series bold
8127 -
8128 \begin_inset ERT
8129 status collapsed
8130
8131 \begin_layout Standard
8132
8133
8134 \backslash
8135 /
8136 \end_layout
8137
8138 \end_inset
8139
8140 -protect-sp-update
8141 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8142
8143 \end_inset
8144
8145
8146 \series default
8147  disable interrupts during ESP:SP updates.
8148 \end_layout
8149
8150 \begin_layout List
8151 \labelwidthstring 00.00.0000
8152
8153 \series bold
8154 -
8155 \begin_inset ERT
8156 status collapsed
8157
8158 \begin_layout Standard
8159
8160
8161 \backslash
8162 /
8163 \end_layout
8164
8165 \end_inset
8166
8167 -stack-10bit
8168 \series default
8169
8170 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8171
8172 \end_inset
8173
8174  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8175  This is the one and only that the ds390 code generator supports right now
8176  and is default when using 
8177 \emph on
8178 -mds390
8179 \emph default
8180 .
8181  In this mode, the stack is located in the lower 1K of the internal RAM,
8182  which is mapped to 0x400000.
8183  Note that the support is incomplete, since it still uses a single byte
8184  as the stack pointer.
8185  This means that only the lower 256 bytes of the potential 1K stack space
8186  will actually be used.
8187  However, this does allow you to reclaim the precious 256 bytes of low RAM
8188  for use for the DATA and IDATA segments.
8189  The compiler will not generate any code to put the processor into 10 bit
8190  stack mode.
8191  It is important to ensure that the processor is in this mode before calling
8192  any re-entrant functions compiled with this option.
8193  In principle, this should work with the 
8194 \emph on
8195 -
8196 \begin_inset ERT
8197 status collapsed
8198
8199 \begin_layout Standard
8200
8201
8202 \backslash
8203 /
8204 \end_layout
8205
8206 \end_inset
8207
8208 -stack-auto
8209 \begin_inset LatexCommand \index{-\/-stack-auto}
8210
8211 \end_inset
8212
8213
8214 \emph default
8215  option, but that has not been tested.
8216  It is incompatible with the 
8217 \emph on
8218 -
8219 \begin_inset ERT
8220 status collapsed
8221
8222 \begin_layout Standard
8223
8224
8225 \backslash
8226 /
8227 \end_layout
8228
8229 \end_inset
8230
8231 -xstack
8232 \begin_inset LatexCommand \index{-\/-xstack}
8233
8234 \end_inset
8235
8236
8237 \emph default
8238  option.
8239  It also only makes sense if the processor is in 24 bit contiguous addressing
8240  mode (see the 
8241 \emph on
8242 -
8243 \begin_inset ERT
8244 status collapsed
8245
8246 \begin_layout Standard
8247
8248
8249 \backslash
8250 /
8251 \end_layout
8252
8253 \end_inset
8254
8255 -model-flat24 option
8256 \emph default
8257 ).
8258 \series bold
8259
8260 \begin_inset Note Note
8261 status collapsed
8262
8263 \begin_layout List
8264 \labelwidthstring 00.00.0000
8265
8266 \series bold
8267 --stack-8-bit - switches off the 10-bit mode
8268 \end_layout
8269
8270 \end_inset
8271
8272
8273 \end_layout
8274
8275 \begin_layout List
8276 \labelwidthstring 00.00.0000
8277
8278 \series bold
8279 -
8280 \begin_inset ERT
8281 status collapsed
8282
8283 \begin_layout Standard
8284
8285
8286 \backslash
8287 /
8288 \end_layout
8289
8290 \end_inset
8291
8292 -stack-probe
8293 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8294
8295 \end_inset
8296
8297
8298 \series default
8299  insert call to function __stack_probe at each function prologue.
8300 \end_layout
8301
8302 \begin_layout List
8303 \labelwidthstring 00.00.0000
8304
8305 \series bold
8306 -
8307 \begin_inset ERT
8308 status collapsed
8309
8310 \begin_layout Standard
8311
8312
8313 \backslash
8314 /
8315 \end_layout
8316
8317 \end_inset
8318
8319 -tini-libid
8320 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8321
8322 \end_inset
8323
8324
8325 \series default
8326  <nnnn> LibraryID used in -mTININative.
8327  
8328 \end_layout
8329
8330 \begin_layout List
8331 \labelwidthstring 00.00.0000
8332
8333 \series bold
8334 -
8335 \begin_inset ERT
8336 status collapsed
8337
8338 \begin_layout Standard
8339
8340
8341 \backslash
8342 /
8343 \end_layout
8344
8345 \end_inset
8346
8347 -use-accelerator
8348 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8349
8350 \end_inset
8351
8352
8353 \series default
8354  generate code for DS390 Arithmetic Accelerator.
8355  
8356 \end_layout
8357
8358 \begin_layout Standard
8359 \begin_inset VSpace bigskip
8360 \end_inset
8361
8362
8363 \end_layout
8364
8365 \begin_layout Subsection
8366 Z80 Options
8367 \begin_inset LatexCommand \index{Options Z80}
8368
8369 \end_inset
8370
8371
8372 \begin_inset LatexCommand \index{Z80}
8373
8374 \end_inset
8375
8376
8377 \end_layout
8378
8379 \begin_layout List
8380 \labelwidthstring 00.00.0000
8381
8382 \series bold
8383 -
8384 \begin_inset ERT
8385 status collapsed
8386
8387 \begin_layout Standard
8388
8389
8390 \backslash
8391 /
8392 \end_layout
8393
8394 \end_inset
8395
8396 -callee-saves-bc
8397 \series default
8398
8399 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8400
8401 \end_inset
8402
8403
8404 \size large
8405 \emph on
8406  
8407 \size default
8408 \emph default
8409 Force a called function to always save BC.
8410 \end_layout
8411
8412 \begin_layout List
8413 \labelwidthstring 00.00.0000
8414
8415 \series bold
8416 -
8417 \begin_inset ERT
8418 status collapsed
8419
8420 \begin_layout Standard
8421
8422
8423 \backslash
8424 /
8425 \end_layout
8426
8427 \end_inset
8428
8429 -no-std-crt0
8430 \series default
8431
8432 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8433
8434 \end_inset
8435
8436  When linking, skip the standard crt0.o object file.
8437  You must provide your own crt0.o for your system when linking.
8438  
8439 \end_layout
8440
8441 \begin_layout Standard
8442 \begin_inset VSpace bigskip
8443 \end_inset
8444
8445
8446 \end_layout
8447
8448 \begin_layout Subsection
8449 Optimization Options
8450 \begin_inset LatexCommand \index{Options optimization}
8451
8452 \end_inset
8453
8454
8455 \begin_inset LatexCommand \index{Optimization options}
8456
8457 \end_inset
8458
8459
8460 \end_layout
8461
8462 \begin_layout List
8463 \labelwidthstring 00.00.0000
8464
8465 \series bold
8466 -
8467 \begin_inset ERT
8468 status collapsed
8469
8470 \begin_layout Standard
8471
8472
8473 \backslash
8474 /
8475 \end_layout
8476
8477 \end_inset
8478
8479 -nogcse
8480 \begin_inset LatexCommand \index{-\/-nogcse}
8481
8482 \end_inset
8483
8484
8485 \series default
8486  Will not do global subexpression elimination, this option may be used when
8487  the compiler creates undesirably large stack/data spaces to store compiler
8488  temporaries (
8489 \emph on
8490 s
8491 \emph default
8492 pill 
8493 \emph on
8494 loc
8495 \emph default
8496 ations, sloc
8497 \begin_inset LatexCommand \index{sloc (spill location)}
8498
8499 \end_inset
8500
8501 ).
8502  A warning message will be generated when this happens and the compiler
8503  will indicate the number of extra bytes it allocated.
8504  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8505 nogcse
8506 \begin_inset LatexCommand \index{\#pragma nogcse}
8507
8508 \end_inset
8509
8510  can be used to turn off global subexpression elimination
8511 \begin_inset LatexCommand \index{Subexpression elimination}
8512
8513 \end_inset
8514
8515  for a given function only.
8516 \end_layout
8517
8518 \begin_layout List
8519 \labelwidthstring 00.00.0000
8520
8521 \series bold
8522 -
8523 \begin_inset ERT
8524 status collapsed
8525
8526 \begin_layout Standard
8527
8528
8529 \backslash
8530 /
8531 \end_layout
8532
8533 \end_inset
8534
8535 -noinvariant
8536 \begin_inset LatexCommand \index{-\/-noinvariant}
8537
8538 \end_inset
8539
8540
8541 \series default
8542  Will not do loop invariant optimizations, this may be turned off for reasons
8543  explained for the previous option.
8544  For more details of loop optimizations performed see Loop Invariants in
8545  section 
8546 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8547
8548 \end_inset
8549
8550 .
8551  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8552 noinvariant
8553 \begin_inset LatexCommand \index{\#pragma noinvariant}
8554
8555 \end_inset
8556
8557  can be used to turn off invariant optimizations for a given function only.
8558 \end_layout
8559
8560 \begin_layout List
8561 \labelwidthstring 00.00.0000
8562
8563 \series bold
8564 -
8565 \begin_inset ERT
8566 status collapsed
8567
8568 \begin_layout Standard
8569
8570
8571 \backslash
8572 /
8573 \end_layout
8574
8575 \end_inset
8576
8577 -noinduction
8578 \begin_inset LatexCommand \index{-\/-noinduction}
8579
8580 \end_inset
8581
8582
8583 \series default
8584  Will not do loop induction optimizations, see section strength reduction
8585  for more details.
8586  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8587 noinduction
8588 \begin_inset LatexCommand \index{\#pragma noinduction}
8589
8590 \end_inset
8591
8592  can be used to turn off induction optimizations for a given function only.
8593 \end_layout
8594
8595 \begin_layout List
8596 \labelwidthstring 00.00.0000
8597
8598 \series bold
8599 -
8600 \begin_inset ERT
8601 status collapsed
8602
8603 \begin_layout Standard
8604
8605
8606 \backslash
8607 /
8608 \end_layout
8609
8610 \end_inset
8611
8612 -nojtbound
8613 \begin_inset LatexCommand \index{-\/-nojtbound}
8614
8615 \end_inset
8616
8617
8618 \size large
8619 \bar under
8620  
8621 \series default
8622 \size default
8623 \bar default
8624  Will not generate boundary condition check when switch statements
8625 \begin_inset LatexCommand \index{switch statement}
8626
8627 \end_inset
8628
8629  are implemented using jump-tables.
8630  See section 
8631 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8632
8633 \end_inset
8634
8635 \InsetSpace ~
8636 Switch Statements for more details.
8637  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8638 nojtbound
8639 \begin_inset LatexCommand \index{\#pragma nojtbound}
8640
8641 \end_inset
8642
8643  can be used to turn off boundary checking for jump tables for a given function
8644  only.
8645 \end_layout
8646
8647 \begin_layout List
8648 \labelwidthstring 00.00.0000
8649
8650 \series bold
8651 -
8652 \begin_inset ERT
8653 status collapsed
8654
8655 \begin_layout Standard
8656
8657
8658 \backslash
8659 /
8660 \end_layout
8661
8662 \end_inset
8663
8664 -noloopreverse
8665 \begin_inset LatexCommand \index{-\/-noloopreverse}
8666
8667 \end_inset
8668
8669
8670 \series default
8671 \size large
8672  
8673 \size default
8674 Will not do loop reversal 
8675 \begin_inset LatexCommand \index{Loop reversing}
8676
8677 \end_inset
8678
8679 optimization.
8680 \end_layout
8681
8682 \begin_layout List
8683 \labelwidthstring 00.00.0000
8684 -
8685 \begin_inset ERT
8686 status collapsed
8687
8688 \begin_layout Standard
8689
8690
8691 \backslash
8692 /
8693 \end_layout
8694
8695 \end_inset
8696
8697 -
8698 \series bold
8699 nolabelopt
8700 \series default
8701  
8702 \begin_inset LatexCommand \index{-\/-nolabelopt }
8703
8704 \end_inset
8705
8706 Will not optimize labels (makes the dumpfiles more readable).
8707 \end_layout
8708
8709 \begin_layout List
8710 \labelwidthstring 00.00.0000
8711
8712 \series bold
8713 -
8714 \begin_inset ERT
8715 status collapsed
8716
8717 \begin_layout Standard
8718
8719
8720 \backslash
8721 /
8722 \end_layout
8723
8724 \end_inset
8725
8726 -no-xinit-opt
8727 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8728
8729 \end_inset
8730
8731
8732 \series default
8733  Will not memcpy initialized data from code space into xdata space.
8734  This saves a few bytes in code space if you don't have initialized data
8735 \begin_inset LatexCommand \index{Variable initialization}
8736
8737 \end_inset
8738
8739 .
8740 \end_layout
8741
8742 \begin_layout List
8743 \labelwidthstring 00.00.0000
8744
8745 \series bold
8746 -
8747 \begin_inset ERT
8748 status collapsed
8749
8750 \begin_layout Standard
8751
8752
8753 \backslash
8754 /
8755 \end_layout
8756
8757 \end_inset
8758
8759 -nooverlay
8760 \begin_inset LatexCommand \index{-\/-nooverlay}
8761
8762 \end_inset
8763
8764
8765 \series default
8766   The compiler will not overlay parameters and local variables of any function,
8767  see section Parameters and local variables for more details.
8768 \end_layout
8769
8770 \begin_layout List
8771 \labelwidthstring 00.00.0000
8772
8773 \series bold
8774 -
8775 \begin_inset ERT
8776 status collapsed
8777
8778 \begin_layout Standard
8779
8780
8781 \backslash
8782 /
8783 \end_layout
8784
8785 \end_inset
8786
8787 -no-peep
8788 \begin_inset LatexCommand \index{-\/-no-peep}
8789
8790 \end_inset
8791
8792
8793 \series default
8794  Disable peep-hole optimization with built-in rules.
8795 \end_layout
8796
8797 \begin_layout List
8798 \labelwidthstring 00.00.0000
8799
8800 \series bold
8801 -
8802 \begin_inset ERT
8803 status collapsed
8804
8805 \begin_layout Standard
8806
8807
8808 \backslash
8809 /
8810 \end_layout
8811
8812 \end_inset
8813
8814 -peep-file
8815 \series default
8816
8817 \begin_inset LatexCommand \index{-\/-peep-file}
8818
8819 \end_inset
8820
8821 \InsetSpace ~
8822 <filename> This option can be used to use additional rules to be used by
8823  the peep hole optimizer.
8824  See section 
8825 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8826
8827 \end_inset
8828
8829 \InsetSpace ~
8830 Peep Hole optimizations for details on how to write these rules.
8831 \end_layout
8832
8833 \begin_layout List
8834 \labelwidthstring 00.00.0000
8835
8836 \series bold
8837 -
8838 \begin_inset ERT
8839 status collapsed
8840
8841 \begin_layout Standard
8842
8843
8844 \backslash
8845 /
8846 \end_layout
8847
8848 \end_inset
8849
8850 -peep-asm
8851 \begin_inset LatexCommand \index{-\/-peep-asm}
8852
8853 \end_inset
8854
8855
8856 \series default
8857  Pass the inline assembler code through the peep hole optimizer.
8858  This can cause unexpected changes to inline assembler code, please go through
8859  the peephole optimizer
8860 \begin_inset LatexCommand \index{Peephole optimizer}
8861
8862 \end_inset
8863
8864  rules defined in the source file tree '<target>/peeph.def' before using
8865  this option.
8866 \end_layout
8867
8868 \begin_layout List
8869 \labelwidthstring 00.00.0000
8870
8871 \series bold
8872 -
8873 \begin_inset ERT
8874 status collapsed
8875
8876 \begin_layout Standard
8877
8878
8879 \backslash
8880 /
8881 \end_layout
8882
8883 \end_inset
8884
8885 -opt-code-speed
8886 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8887
8888 \end_inset
8889
8890
8891 \series default
8892  The compiler will optimize code generation towards fast code, possibly
8893  at the expense of code size.
8894 \end_layout
8895
8896 \begin_layout List
8897 \labelwidthstring 00.00.0000
8898
8899 \series bold
8900 -
8901 \begin_inset ERT
8902 status collapsed
8903
8904 \begin_layout Standard
8905
8906
8907 \backslash
8908 /
8909 \end_layout
8910
8911 \end_inset
8912
8913 -opt-code-size
8914 \begin_inset LatexCommand \index{-\/-opt-code-size}
8915
8916 \end_inset
8917
8918
8919 \series default
8920  The compiler will optimize code generation towards compact code, possibly
8921  at the expense of code speed.
8922 \end_layout
8923
8924 \begin_layout Standard
8925 \begin_inset VSpace bigskip
8926 \end_inset
8927
8928
8929 \end_layout
8930
8931 \begin_layout Subsection
8932 Other Options
8933 \begin_inset LatexCommand \index{Options other}
8934
8935 \end_inset
8936
8937
8938 \end_layout
8939
8940 \begin_layout List
8941 \labelwidthstring 00.00.0000
8942
8943 \series bold
8944 -c\InsetSpace ~
8945 -
8946 \begin_inset ERT
8947 status collapsed
8948
8949 \begin_layout Standard
8950
8951
8952 \backslash
8953 /
8954 \end_layout
8955
8956 \end_inset
8957
8958 -compile-only
8959 \begin_inset LatexCommand \index{-\/-compile-only}
8960
8961 \end_inset
8962
8963
8964 \begin_inset LatexCommand \index{-c -\/-compile-only}
8965
8966 \end_inset
8967
8968
8969 \series default
8970  will compile and assemble the source, but will not call the linkage editor.
8971 \end_layout
8972
8973 \begin_layout List
8974 \labelwidthstring 00.00.0000
8975
8976 \series bold
8977 -
8978 \series default
8979
8980 \begin_inset ERT
8981 status collapsed
8982
8983 \begin_layout Standard
8984
8985
8986 \backslash
8987 /
8988 \end_layout
8989
8990 \end_inset
8991
8992
8993 \series bold
8994 -c1mode
8995 \begin_inset LatexCommand \index{-\/-c1mode}
8996
8997 \end_inset
8998
8999
9000 \series default
9001  reads the preprocessed source from standard input and compiles it.
9002  The file name for the assembler output must be specified using the -o option.
9003 \end_layout
9004
9005 \begin_layout List
9006 \labelwidthstring 00.00.0000
9007
9008 \series bold
9009 -E
9010 \begin_inset LatexCommand \index{-E}
9011
9012 \end_inset
9013
9014
9015 \series default
9016  Run only the C preprocessor.
9017  Preprocess all the C source files specified and output the results to standard
9018  output.
9019 \end_layout
9020
9021 \begin_layout List
9022 \labelwidthstring 00.00.0000
9023
9024 \series bold
9025 -o\InsetSpace ~
9026 <path/file>
9027 \begin_inset LatexCommand \index{-o <path/file>}
9028
9029 \end_inset
9030
9031  
9032 \series default
9033 The output path resp.
9034  file where everything will be placed.
9035  If the parameter is a path, it must have a trailing slash (or backslash
9036  for the Windows binaries) to be recognized as a path.
9037  
9038 \end_layout
9039
9040 \begin_layout List
9041 \labelwidthstring 00.00.0000
9042
9043 \series bold
9044 -
9045 \begin_inset ERT
9046 status collapsed
9047
9048 \begin_layout Standard
9049
9050
9051 \backslash
9052 /
9053 \end_layout
9054
9055 \end_inset
9056
9057 -stack-auto
9058 \begin_inset LatexCommand \index{-\/-stack-auto}
9059
9060 \end_inset
9061
9062
9063 \series default
9064 \size large
9065 \emph on
9066  
9067 \size default
9068 \emph default
9069 All functions in the source file will be compiled as 
9070 \emph on
9071 reentrant
9072 \emph default
9073
9074 \begin_inset LatexCommand \index{reentrant}
9075
9076 \end_inset
9077
9078 , i.e.
9079  the parameters and local variables will be allocated on the stack
9080 \begin_inset LatexCommand \index{stack}
9081
9082 \end_inset
9083
9084 .
9085  See section 
9086 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9087
9088 \end_inset
9089
9090  Parameters and Local Variables for more details.
9091  If this option is used all source files in the project should be compiled
9092  with this option.
9093  It automatically implies --int-long-reent and --float-reent.
9094  
9095 \end_layout
9096
9097 \begin_layout List
9098 \labelwidthstring 00.00.0000
9099
9100 \series bold
9101 -
9102 \begin_inset ERT
9103 status collapsed
9104
9105 \begin_layout Standard
9106
9107
9108 \backslash
9109 /
9110 \end_layout
9111
9112 \end_inset
9113
9114 -callee-saves
9115 \begin_inset LatexCommand \index{-\/-callee-saves}
9116
9117 \end_inset
9118
9119  
9120 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9121
9122 \end_inset
9123
9124 function1[,function2][,function3]....
9125
9126 \series default
9127  The compiler by default uses a caller saves convention for register saving
9128  across function calls, however this can cause unnecessary register pushing
9129  and popping when calling small functions from larger functions.
9130  This option can be used to switch the register saving convention for the
9131  function names specified.
9132  The compiler will not save registers when calling these functions, no extra
9133  code will be generated at the entry and exit (function prologue
9134 \series bold
9135
9136 \begin_inset LatexCommand \index{function prologue}
9137
9138 \end_inset
9139
9140
9141 \series default
9142  and epilogue
9143 \series bold
9144
9145 \begin_inset LatexCommand \index{function epilogue}
9146
9147 \end_inset
9148
9149
9150 \series default
9151 ) for these functions to save and restore the registers used by these functions,
9152  this can SUBSTANTIALLY reduce code and improve run time performance of
9153  the generated code.
9154  In the future the compiler (with inter procedural analysis) will be able
9155  to determine the appropriate scheme to use for each function call.
9156  DO NOT use this option for built-in functions such as _mulint..., if this
9157  option is used for a library function the appropriate library function
9158  needs to be recompiled with the same option.
9159  If the project consists of multiple source files then all the source file
9160  should be compiled with the same -
9161 \begin_inset ERT
9162 status collapsed
9163
9164 \begin_layout Standard
9165
9166
9167 \backslash
9168 /
9169 \end_layout
9170
9171 \end_inset
9172
9173 -callee-saves option string.
9174  Also see #pragma\InsetSpace ~
9175 callee_saves 
9176 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9177
9178 \end_inset
9179
9180  
9181 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9182
9183 \end_inset
9184
9185 .
9186 \end_layout
9187
9188 \begin_layout List
9189 \labelwidthstring 00.00.0000
9190
9191 \series bold
9192 -
9193 \begin_inset ERT
9194 status collapsed
9195
9196 \begin_layout Standard
9197
9198
9199 \backslash
9200 /
9201 \end_layout
9202
9203 \end_inset
9204
9205 -all-callee-saves
9206 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9207
9208 \end_inset
9209
9210  
9211 \series default
9212 Function of
9213 \series bold
9214  
9215 \series default
9216 -
9217 \begin_inset ERT
9218 status collapsed
9219
9220 \begin_layout Standard
9221
9222
9223 \backslash
9224 /
9225 \end_layout
9226
9227 \end_inset
9228
9229 -callee-saves will be applied to all functions by default.
9230 \end_layout
9231
9232 \begin_layout List
9233 \labelwidthstring 00.00.0000
9234
9235 \series bold
9236 -
9237 \begin_inset ERT
9238 status collapsed
9239
9240 \begin_layout Standard
9241
9242
9243 \backslash
9244 /
9245 \end_layout
9246
9247 \end_inset
9248
9249 -debug
9250 \begin_inset LatexCommand \index{-\/-debug}
9251
9252 \end_inset
9253
9254
9255 \bar under
9256  
9257 \series default
9258 \bar default
9259 When this option is used the compiler will generate debug information.
9260  The debug information collected in a file with .cdb extension can be used
9261  with the SDCDB.
9262  For more information see documentation for SDCDB.
9263  Another file with no extension contains debug information in AOMF or AOMF51
9264 \begin_inset LatexCommand \index{AOMF, AOMF51}
9265
9266 \end_inset
9267
9268  format which is commonly used by third party tools.
9269 \end_layout
9270
9271 \begin_layout List
9272 \labelwidthstring 00.00.0000
9273
9274 \series bold
9275 -S
9276 \begin_inset LatexCommand \index{-S}
9277
9278 \end_inset
9279
9280
9281 \size large
9282 \bar under
9283  
9284 \series default
9285 \size default
9286 \bar default
9287 Stop after the stage of compilation proper; do not assemble.
9288  The output is an assembler code file for the input file specified.
9289 \end_layout
9290
9291 \begin_layout List
9292 \labelwidthstring 00.00.0000
9293
9294 \series bold
9295 -
9296 \begin_inset ERT
9297 status collapsed
9298
9299 \begin_layout Standard
9300
9301
9302 \backslash
9303 /
9304 \end_layout
9305
9306 \end_inset
9307
9308 -int-long-reent
9309 \begin_inset LatexCommand \index{-\/-int-long-reent}
9310
9311 \end_inset
9312
9313
9314 \series default
9315  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9316  Note by default these libraries are compiled as non-reentrant.
9317  See section Installation for more details.
9318 \end_layout
9319
9320 \begin_layout List
9321 \labelwidthstring 00.00.0000
9322
9323 \series bold
9324 -
9325 \begin_inset ERT
9326 status collapsed
9327
9328 \begin_layout Standard
9329
9330
9331 \backslash
9332 /
9333 \end_layout
9334
9335 \end_inset
9336
9337 -cyclomatic
9338 \begin_inset LatexCommand \index{-\/-cyclomatic}
9339
9340 \end_inset
9341
9342
9343 \bar under
9344  
9345 \series default
9346 \bar default
9347 This option will cause the compiler to generate an information message for
9348  each function in the source file.
9349  The message contains some 
9350 \emph on
9351 important
9352 \emph default
9353  information about the function.
9354  The number of edges and nodes the compiler detected in the control flow
9355  graph of the function, and most importantly the 
9356 \emph on
9357 cyclomatic complexity
9358 \begin_inset LatexCommand \index{Cyclomatic complexity}
9359
9360 \end_inset
9361
9362
9363 \emph default
9364  see section on Cyclomatic Complexity for more details.
9365 \end_layout
9366
9367 \begin_layout List
9368 \labelwidthstring 00.00.0000
9369
9370 \series bold
9371 -
9372 \begin_inset ERT
9373 status collapsed
9374
9375 \begin_layout Standard
9376
9377
9378 \backslash
9379 /
9380 \end_layout
9381
9382 \end_inset
9383
9384 -float-reent
9385 \begin_inset LatexCommand \index{-\/-float-reent}
9386
9387 \end_inset
9388
9389
9390 \series default
9391  Floating point library is compiled as reentrant
9392 \begin_inset LatexCommand \index{reentrant}
9393
9394 \end_inset
9395
9396 .
9397  See section Installation for more details.
9398 \end_layout
9399
9400 \begin_layout List
9401 \labelwidthstring 00.00.0000
9402
9403 \series bold
9404 -
9405 \begin_inset ERT
9406 status collapsed
9407
9408 \begin_layout Standard
9409
9410
9411 \backslash
9412 /
9413 \end_layout
9414
9415 \end_inset
9416
9417 -funsigned-char
9418 \begin_inset LatexCommand \index{-\/-funsigned-char}
9419
9420 \end_inset
9421
9422
9423 \series default
9424  The default signedness for every type is
9425 \family typewriter
9426  signed
9427 \family default
9428 .
9429  In some embedded environments the default signedness of
9430 \family typewriter
9431  char
9432 \family default
9433  is
9434 \family typewriter
9435  unsigned
9436 \family default
9437 .
9438  To set the signess for characters to unsigned, use the option --funsigned-char.
9439  If this option is set and no signedness keyword (unsigned/signed) is given,
9440  a char will be signed.
9441  All other types are unaffected.
9442 \end_layout
9443
9444 \begin_layout List
9445 \labelwidthstring 00.00.0000
9446
9447 \series bold
9448 -
9449 \begin_inset ERT
9450 status collapsed
9451
9452 \begin_layout Standard
9453
9454
9455 \backslash
9456 /
9457 \end_layout
9458
9459 \end_inset
9460
9461 -main-return
9462 \begin_inset LatexCommand \index{-\/-main-return}
9463
9464 \end_inset
9465
9466
9467 \series default
9468  This option can be used if the code generated is called by a monitor program
9469  or if the main routine includes an endless loop.
9470  This option results in slightly smaller code and saves two bytes of stack
9471  space.
9472  The return from the 'main'
9473 \begin_inset LatexCommand \index{main return}
9474
9475 \end_inset
9476
9477  function will return to the function calling main.
9478  The default setting is to lock up i.e.
9479  generate a '
9480 \family typewriter
9481 sjmp .
9482 \family default
9483 '.
9484 \end_layout
9485
9486 \begin_layout List
9487 \labelwidthstring 00.00.0000
9488
9489 \series bold
9490 -
9491 \begin_inset ERT
9492 status collapsed
9493
9494 \begin_layout Standard
9495
9496
9497 \backslash
9498 /
9499 \end_layout
9500
9501 \end_inset
9502
9503 -nostdinc
9504 \begin_inset LatexCommand \index{-\/-nostdinc}
9505
9506 \end_inset
9507
9508
9509 \series default
9510  This will prevent the compiler from passing on the default include path
9511  to the preprocessor.
9512 \end_layout
9513
9514 \begin_layout List
9515 \labelwidthstring 00.00.0000
9516
9517 \series bold
9518 -
9519 \begin_inset ERT
9520 status collapsed
9521
9522 \begin_layout Standard
9523
9524
9525 \backslash
9526 /
9527 \end_layout
9528
9529 \end_inset
9530
9531 -nostdlib
9532 \begin_inset LatexCommand \index{-\/-nostdlib}
9533
9534 \end_inset
9535
9536
9537 \series default
9538  This will prevent the compiler from passing on the default library
9539 \begin_inset LatexCommand \index{Libraries}
9540
9541 \end_inset
9542
9543  path to the linker.
9544 \end_layout
9545
9546 \begin_layout List
9547 \labelwidthstring 00.00.0000
9548
9549 \series bold
9550 -
9551 \begin_inset ERT
9552 status collapsed
9553
9554 \begin_layout Standard
9555
9556
9557 \backslash
9558 /
9559 \end_layout
9560
9561 \end_inset
9562
9563 -verbose
9564 \begin_inset LatexCommand \index{-\/-verbose}
9565
9566 \end_inset
9567
9568
9569 \series default
9570  Shows the various actions the compiler is performing.
9571 \end_layout
9572
9573 \begin_layout List
9574 \labelwidthstring 00.00.0000
9575
9576 \series bold
9577 -V
9578 \begin_inset LatexCommand \index{-V}
9579
9580 \end_inset
9581
9582
9583 \series default
9584  Shows the actual commands the compiler is executing.
9585 \end_layout
9586
9587 \begin_layout List
9588 \labelwidthstring 00.00.0000
9589
9590 \series bold
9591 -
9592 \begin_inset ERT
9593 status collapsed
9594
9595 \begin_layout Standard
9596
9597
9598 \backslash
9599 /
9600 \end_layout
9601
9602 \end_inset
9603
9604 -no-c-code-in-asm
9605 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9606
9607 \end_inset
9608
9609
9610 \series default
9611  Hides your ugly and inefficient c-code from the asm file, so you can always
9612  blame the compiler :)
9613 \end_layout
9614
9615 \begin_layout List
9616 \labelwidthstring 00.00.0000
9617
9618 \series bold
9619 -
9620 \begin_inset ERT
9621 status collapsed
9622
9623 \begin_layout Standard
9624
9625
9626 \backslash
9627 /
9628 \end_layout
9629
9630 \end_inset
9631
9632 -no-peep-comments
9633 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9634
9635 \end_inset
9636
9637
9638 \series default
9639  Will not include peep-hole comments in the generated files.
9640 \end_layout
9641
9642 \begin_layout List
9643 \labelwidthstring 00.00.0000
9644
9645 \series bold
9646 -
9647 \begin_inset ERT
9648 status collapsed
9649
9650 \begin_layout Standard
9651
9652
9653 \backslash
9654 /
9655 \end_layout
9656
9657 \end_inset
9658
9659 -no-gen-comments
9660 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9661
9662 \end_inset
9663
9664
9665 \series default
9666  Will not include code generator comments in the generated files.
9667 \end_layout
9668
9669 \begin_layout List
9670 \labelwidthstring 00.00.0000
9671
9672 \series bold
9673 -
9674 \begin_inset ERT
9675 status collapsed
9676
9677 \begin_layout Standard
9678
9679
9680 \backslash
9681 /
9682 \end_layout
9683
9684 \end_inset
9685
9686 -i-code-in-asm
9687 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9688
9689 \end_inset
9690
9691
9692 \series default
9693  Include i-codes in the asm file.
9694  Sounds like noise but is most helpful for debugging the compiler itself.
9695 \end_layout
9696
9697 \begin_layout List
9698 \labelwidthstring 00.00.0000
9699
9700 \series bold
9701 -
9702 \begin_inset ERT
9703 status collapsed
9704
9705 \begin_layout Standard
9706
9707
9708 \backslash
9709 /
9710 \end_layout
9711
9712 \end_inset
9713
9714 -less-pedantic
9715 \begin_inset LatexCommand \index{pedantic}
9716
9717 \end_inset
9718
9719
9720 \begin_inset LatexCommand \index{-\/-less-pedantic}
9721
9722 \end_inset
9723
9724
9725 \series default
9726
9727 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9728
9729 \end_inset
9730
9731  Disable some of the more pedantic warnings
9732 \begin_inset LatexCommand \index{Warnings}
9733
9734 \end_inset
9735
9736 .
9737  For more details, see the less_pedantic pragma 
9738 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9739
9740 \end_inset
9741
9742 .
9743 \end_layout
9744
9745 \begin_layout List
9746 \labelwidthstring 00.00.0000
9747
9748 \series bold
9749 -
9750 \begin_inset ERT
9751 status collapsed
9752
9753 \begin_layout Standard
9754
9755
9756 \backslash
9757 /
9758 \end_layout
9759
9760 \end_inset
9761
9762 -disable-warning\InsetSpace ~
9763 <nnnn>
9764 \begin_inset LatexCommand \index{-\/-disable-warning}
9765
9766 \end_inset
9767
9768
9769 \series default
9770  Disable specific warning with number <nnnn>.
9771 \end_layout
9772
9773 \begin_layout List
9774 \labelwidthstring 00.00.0000
9775
9776 \series bold
9777 -
9778 \begin_inset ERT
9779 status collapsed
9780
9781 \begin_layout Standard
9782
9783
9784 \backslash
9785 /
9786 \end_layout
9787
9788 \end_inset
9789
9790 -print-search-dirs
9791 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9792
9793 \end_inset
9794
9795
9796 \series default
9797  Display the directories in the compiler's search path
9798 \end_layout
9799
9800 \begin_layout List
9801 \labelwidthstring 00.00.0000
9802
9803 \series bold
9804 -
9805 \begin_inset ERT
9806 status collapsed
9807
9808 \begin_layout Standard
9809
9810
9811 \backslash
9812 /
9813 \end_layout
9814
9815 \end_inset
9816
9817 -vc
9818 \begin_inset LatexCommand \index{-\/-vc}
9819
9820 \end_inset
9821
9822
9823 \series default
9824  Display errors and warnings using MSVC style, so you can use SDCC with
9825  the visual studio IDE
9826 \begin_inset LatexCommand \index{IDE}
9827
9828 \end_inset
9829
9830 .
9831  With SDCC both offering a GCC-like (the default) and a MSVC-like
9832 \begin_inset LatexCommand \index{MSVC output style}
9833
9834 \end_inset
9835
9836  output style, integration into most programming editors should be straightforwa
9837 rd.
9838 \end_layout
9839
9840 \begin_layout List
9841 \labelwidthstring 00.00.0000
9842
9843 \series bold
9844 -
9845 \begin_inset ERT
9846 status collapsed
9847
9848 \begin_layout Standard
9849
9850
9851 \backslash
9852 /
9853 \end_layout
9854
9855 \end_inset
9856
9857 -use-stdout
9858 \begin_inset LatexCommand \index{-\/-use-stdout}
9859
9860 \end_inset
9861
9862
9863 \series default
9864  Send errors and warnings to stdout instead of stderr.
9865 \end_layout
9866
9867 \begin_layout List
9868 \labelwidthstring 00.00.0000
9869
9870 \series bold
9871 -Wa\InsetSpace ~
9872 asmOption[,asmOption]
9873 \series default
9874
9875 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9876
9877 \end_inset
9878
9879 ...
9880  Pass the asmOption to the assembler
9881 \begin_inset LatexCommand \index{Options assembler}
9882
9883 \end_inset
9884
9885
9886 \begin_inset LatexCommand \index{Assembler options}
9887
9888 \end_inset
9889
9890 .
9891  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9892 \end_layout
9893
9894 \begin_layout List
9895 \labelwidthstring 00.00.0000
9896
9897 \series bold
9898 -
9899 \begin_inset ERT
9900 status collapsed
9901
9902 \begin_layout Standard
9903
9904
9905 \backslash
9906 /
9907 \end_layout
9908
9909 \end_inset
9910
9911 -std-sdcc89
9912 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9913
9914 \end_inset
9915
9916
9917 \series default
9918  Generally follow the C89 standard, but allow SDCC features that conflict
9919  with the standard (default).
9920 \end_layout
9921
9922 \begin_layout List
9923 \labelwidthstring 00.00.0000
9924
9925 \series bold
9926 -
9927 \begin_inset ERT
9928 status collapsed
9929
9930 \begin_layout Standard
9931
9932
9933 \backslash
9934 /
9935 \end_layout
9936
9937 \end_inset
9938
9939 -std-c89
9940 \begin_inset LatexCommand \index{-\/-std-c89}
9941
9942 \end_inset
9943
9944
9945 \series default
9946  Follow the C89 standard and disable SDCC features that conflict with the
9947  standard.
9948 \end_layout
9949
9950 \begin_layout List
9951 \labelwidthstring 00.00.0000
9952
9953 \series bold
9954 -
9955 \begin_inset ERT
9956 status collapsed
9957
9958 \begin_layout Standard
9959
9960
9961 \backslash
9962 /
9963 \end_layout
9964
9965 \end_inset
9966
9967 -std-sdcc99
9968 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9969
9970 \end_inset
9971
9972
9973 \series default
9974  Generally follow the C99 standard, but allow SDCC features that conflict
9975  with the standard (incomplete support).
9976 \end_layout
9977
9978 \begin_layout List
9979 \labelwidthstring 00.00.0000
9980
9981 \series bold
9982 -
9983 \begin_inset ERT
9984 status collapsed
9985
9986 \begin_layout Standard
9987
9988
9989 \backslash
9990 /
9991 \end_layout
9992
9993 \end_inset
9994
9995 -std-c99
9996 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9997
9998 \end_inset
9999
10000
10001 \series default
10002  Follow the C99 standard and disable SDCC features that conflict with the
10003  standard (incomplete support).
10004 \end_layout
10005
10006 \begin_layout List
10007 \labelwidthstring 00.00.0000
10008
10009 \series bold
10010 -
10011 \begin_inset ERT
10012 status collapsed
10013
10014 \begin_layout Standard
10015
10016
10017 \backslash
10018 /
10019 \end_layout
10020
10021 \end_inset
10022
10023 -codeseg
10024 \series default
10025
10026 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10027
10028 \end_inset
10029
10030 \InsetSpace ~
10031 <Name> The name to be used for the code
10032 \begin_inset LatexCommand \index{code}
10033
10034 \end_inset
10035
10036  segment, default CSEG.
10037  This is useful if you need to tell the compiler to put the code in a special
10038  segment so you can later on tell the linker to put this segment in a special
10039  place in memory.
10040  Can be used for instance when using bank switching to put the code in a
10041  bank.
10042 \end_layout
10043
10044 \begin_layout List
10045 \labelwidthstring 00.00.0000
10046
10047 \series bold
10048 -
10049 \begin_inset ERT
10050 status collapsed
10051
10052 \begin_layout Standard
10053
10054
10055 \backslash
10056 /
10057 \end_layout
10058
10059 \end_inset
10060
10061 -constseg
10062 \series default
10063
10064 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10065
10066 \end_inset
10067
10068 \InsetSpace ~
10069 <Name> The name to be used for the const
10070 \begin_inset LatexCommand \index{code}
10071
10072 \end_inset
10073
10074  segment, default CONST.
10075  This is useful if you need to tell the compiler to put the const data in
10076  a special segment so you can later on tell the linker to put this segment
10077  in a special place in memory.
10078  Can be used for instance when using bank switching to put the const data
10079  in a bank.
10080 \end_layout
10081
10082 \begin_layout List
10083 \labelwidthstring 00.00.0000
10084
10085 \series bold
10086 -
10087 \begin_inset ERT
10088 status collapsed
10089
10090 \begin_layout Standard
10091
10092
10093 \backslash
10094 /
10095 \end_layout
10096
10097 \end_inset
10098
10099 -fdollars-in-identifiers
10100 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10101
10102 \end_inset
10103
10104
10105 \series default
10106  Permit '$' as an identifier character.
10107 \end_layout
10108
10109 \begin_layout List
10110 \labelwidthstring 00.00.0000
10111
10112 \series bold
10113 -
10114 \begin_inset ERT
10115 status collapsed
10116
10117 \begin_layout Standard
10118
10119
10120 \backslash
10121 /
10122 \end_layout
10123
10124 \end_inset
10125
10126 -more-pedantic
10127 \series default
10128
10129 \begin_inset LatexCommand \index{-\/-more-pedantic}
10130
10131 \end_inset
10132
10133
10134 \begin_inset LatexCommand \index{pedantic}
10135
10136 \end_inset
10137
10138  Actually this is 
10139 \series bold
10140 \emph on
10141 not
10142 \series default
10143 \emph default
10144  a SDCC compiler option but if you want 
10145 \emph on
10146 more
10147 \emph default
10148  warnings you can use a separate tool dedicated to syntax checking like
10149  splint
10150 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10151
10152 \end_inset
10153
10154
10155 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10156
10157 \end_inset
10158
10159  
10160 \begin_inset LatexCommand \url{http://www.splint.org}
10161
10162 \end_inset
10163
10164 .
10165  To make your source files parseable by splint you will have to include
10166  
10167 \family sans
10168 lint.h
10169 \family default
10170
10171 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10172
10173 \end_inset
10174
10175  in your source file and add brackets around extended keywords (like 
10176 \family sans
10177
10178 \begin_inset Quotes sld
10179 \end_inset
10180
10181 __at\InsetSpace ~
10182
10183 \series bold
10184 (
10185 \series default
10186 0xab
10187 \series bold
10188 )
10189 \series default
10190
10191 \begin_inset Quotes srd
10192 \end_inset
10193
10194
10195 \family default
10196  and 
10197 \family sans
10198
10199 \begin_inset Quotes sld
10200 \end_inset
10201
10202 __interrupt\InsetSpace ~
10203 (2)
10204 \begin_inset Quotes srd
10205 \end_inset
10206
10207
10208 \family default
10209 ).
10210  
10211 \newline
10212 Splint has an excellent on line manual at 
10213 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10214
10215 \end_inset
10216
10217  and it's capabilities go beyond pure syntax checking.
10218  You'll need to tell splint the location of SDCC's include files so a typical
10219  command line could look like this: 
10220 \newline
10221
10222 \family sans
10223 splint\InsetSpace ~
10224 -I\InsetSpace ~
10225 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10226 \InsetSpace ~
10227 myprogram.c
10228 \end_layout
10229
10230 \begin_layout List
10231 \labelwidthstring 00.00.0000
10232
10233 \series bold
10234 -
10235 \begin_inset ERT
10236 status collapsed
10237
10238 \begin_layout Standard
10239
10240
10241 \backslash
10242 /
10243 \end_layout
10244
10245 \end_inset
10246
10247 -short-is-8bits
10248 \series default
10249
10250 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10251
10252 \end_inset
10253
10254
10255 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10256
10257 \end_inset
10258
10259  Treat short as 8-bit (for backward compatibility with older versions of
10260  compiler - see section 
10261 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10262
10263 \end_inset
10264
10265 )
10266 \end_layout
10267
10268 \begin_layout Standard
10269 \begin_inset VSpace bigskip
10270 \end_inset
10271
10272
10273 \end_layout
10274
10275 \begin_layout Subsection
10276 Intermediate Dump Options
10277 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10278
10279 \end_inset
10280
10281
10282 \begin_inset LatexCommand \index{Options intermediate dump}
10283
10284 \end_inset
10285
10286
10287 \begin_inset LatexCommand \index{Intermediate dump options}
10288
10289 \end_inset
10290
10291
10292 \end_layout
10293
10294 \begin_layout Standard
10295 The following options are provided for the purpose of retargetting and debugging
10296  the compiler.
10297  They provide a means to dump the intermediate code (iCode
10298 \begin_inset LatexCommand \index{iCode}
10299
10300 \end_inset
10301
10302 ) generated by the compiler in human readable form at various stages of
10303  the compilation process.
10304  More on iCodes see chapter 
10305 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10306
10307 \end_inset
10308
10309  
10310 \begin_inset Quotes srd
10311 \end_inset
10312
10313 The anatomy of the compiler
10314 \begin_inset Quotes srd
10315 \end_inset
10316
10317 .
10318 \end_layout
10319
10320 \begin_layout List
10321 \labelwidthstring 00.00.0000
10322
10323 \series bold
10324 -
10325 \begin_inset ERT
10326 status collapsed
10327
10328 \begin_layout Standard
10329
10330
10331 \backslash
10332 /
10333 \end_layout
10334
10335 \end_inset
10336
10337 -dumpraw
10338 \begin_inset LatexCommand \index{-\/-dumpraw}
10339
10340 \end_inset
10341
10342
10343 \series default
10344  This option will cause the compiler to dump the intermediate code into
10345  a file of named 
10346 \emph on
10347 <source filename>.dumpraw
10348 \emph default
10349  just after the intermediate code has been generated for a function, i.e.
10350  before any optimizations are done.
10351  The basic blocks
10352 \begin_inset LatexCommand \index{Basic blocks}
10353
10354 \end_inset
10355
10356  at this stage ordered in the depth first number, so they may not be in
10357  sequence of execution.
10358 \end_layout
10359
10360 \begin_layout List
10361 \labelwidthstring 00.00.0000
10362
10363 \series bold
10364 -
10365 \begin_inset ERT
10366 status collapsed
10367
10368 \begin_layout Standard
10369
10370
10371 \backslash
10372 /
10373 \end_layout
10374
10375 \end_inset
10376
10377 -dumpgcse
10378 \begin_inset LatexCommand \index{-\/-dumpgcse}
10379
10380 \end_inset
10381
10382
10383 \series default
10384  Will create a dump of iCode's, after global subexpression elimination
10385 \begin_inset LatexCommand \index{Global subexpression elimination}
10386
10387 \end_inset
10388
10389 , into a file named 
10390 \emph on
10391 <source filename>.dumpgcse.
10392 \end_layout
10393
10394 \begin_layout List
10395 \labelwidthstring 00.00.0000
10396
10397 \series bold
10398 -
10399 \begin_inset ERT
10400 status collapsed
10401
10402 \begin_layout Standard
10403
10404
10405 \backslash
10406 /
10407 \end_layout
10408
10409 \end_inset
10410
10411 -dumpdeadcode
10412 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10413
10414 \end_inset
10415
10416
10417 \series default
10418  Will create a dump of iCode's, after deadcode elimination
10419 \begin_inset LatexCommand \index{Dead-code elimination}
10420
10421 \end_inset
10422
10423 , into a file named 
10424 \emph on
10425 <source filename>.dumpdeadcode.
10426 \end_layout
10427
10428 \begin_layout List
10429 \labelwidthstring 00.00.0000
10430
10431 \series bold
10432 -
10433 \begin_inset ERT
10434 status collapsed
10435
10436 \begin_layout Standard
10437
10438
10439 \backslash
10440 /
10441 \end_layout
10442
10443 \end_inset
10444
10445 -dumploop
10446 \begin_inset LatexCommand \index{-\/-dumploop}
10447
10448 \end_inset
10449
10450
10451 \series default
10452 \size large
10453  
10454 \size default
10455 Will create a dump of iCode's, after loop optimizations
10456 \begin_inset LatexCommand \index{Loop optimization}
10457
10458 \end_inset
10459
10460 , into a file named 
10461 \emph on
10462 <source filename>.dumploop.
10463 \end_layout
10464
10465 \begin_layout List
10466 \labelwidthstring 00.00.0000
10467
10468 \series bold
10469 -
10470 \begin_inset ERT
10471 status collapsed
10472
10473 \begin_layout Standard
10474
10475
10476 \backslash
10477 /
10478 \end_layout
10479
10480 \end_inset
10481
10482 -dumprange
10483 \begin_inset LatexCommand \index{-\/-dumprange}
10484
10485 \end_inset
10486
10487
10488 \series default
10489 \size large
10490  
10491 \size default
10492 Will create a dump of iCode's, after live range analysis
10493 \begin_inset LatexCommand \index{Live range analysis}
10494
10495 \end_inset
10496
10497 , into a file named 
10498 \emph on
10499 <source filename>.dumprange.
10500 \end_layout
10501
10502 \begin_layout List
10503 \labelwidthstring 00.00.0000
10504
10505 \series bold
10506 -
10507 \begin_inset ERT
10508 status collapsed
10509
10510 \begin_layout Standard
10511
10512
10513 \backslash
10514 /
10515 \end_layout
10516
10517 \end_inset
10518
10519 -dumlrange
10520 \begin_inset LatexCommand \index{-\/-dumlrange}
10521
10522 \end_inset
10523
10524
10525 \series default
10526  Will dump the life ranges
10527 \begin_inset LatexCommand \index{Live range analysis}
10528
10529 \end_inset
10530
10531  for all symbols.
10532 \end_layout
10533
10534 \begin_layout List
10535 \labelwidthstring 00.00.0000
10536
10537 \series bold
10538 -
10539 \begin_inset ERT
10540 status collapsed
10541
10542 \begin_layout Standard
10543
10544
10545 \backslash
10546 /
10547 \end_layout
10548
10549 \end_inset
10550
10551 -dumpregassign
10552 \begin_inset LatexCommand \index{-\/-dumpregassign}
10553
10554 \end_inset
10555
10556
10557 \bar under
10558  
10559 \series default
10560 \bar default
10561 Will create a dump of iCode's, after register assignment
10562 \begin_inset LatexCommand \index{Register assignment}
10563
10564 \end_inset
10565
10566 , into a file named 
10567 \emph on
10568 <source filename>.dumprassgn.
10569 \end_layout
10570
10571 \begin_layout List
10572 \labelwidthstring 00.00.0000
10573
10574 \series bold
10575 -
10576 \begin_inset ERT
10577 status collapsed
10578
10579 \begin_layout Standard
10580
10581
10582 \backslash
10583 /
10584 \end_layout
10585
10586 \end_inset
10587
10588 -dumplrange
10589 \begin_inset LatexCommand \index{-\/-dumplrange}
10590
10591 \end_inset
10592
10593
10594 \series default
10595  Will create a dump of the live ranges of iTemp's
10596 \end_layout
10597
10598 \begin_layout List
10599 \labelwidthstring 00.00.0000
10600
10601 \series bold
10602 -
10603 \begin_inset ERT
10604 status collapsed
10605
10606 \begin_layout Standard
10607
10608
10609 \backslash
10610 /
10611 \end_layout
10612
10613 \end_inset
10614
10615 -dumpall
10616 \begin_inset LatexCommand \index{-\/-dumpall}
10617
10618 \end_inset
10619
10620
10621 \size large
10622 \bar under
10623  
10624 \series default
10625 \size default
10626 \bar default
10627 Will cause all the above mentioned dumps to be created.
10628 \end_layout
10629
10630 \begin_layout Standard
10631 \begin_inset VSpace bigskip
10632 \end_inset
10633
10634
10635 \end_layout
10636
10637 \begin_layout Subsection
10638 Redirecting output on Windows Shells
10639 \end_layout
10640
10641 \begin_layout Standard
10642 By default SDCC writes it's error messages to 
10643 \begin_inset Quotes sld
10644 \end_inset
10645
10646 standard error
10647 \begin_inset Quotes srd
10648 \end_inset
10649
10650 .
10651  To force all messages to 
10652 \begin_inset Quotes sld
10653 \end_inset
10654
10655 standard output
10656 \begin_inset Quotes srd
10657 \end_inset
10658
10659  use 
10660 \series bold
10661 -
10662 \series default
10663 \emph on
10664
10665 \begin_inset ERT
10666 status collapsed
10667
10668 \begin_layout Standard
10669
10670
10671 \backslash
10672 /
10673 \end_layout
10674
10675 \end_inset
10676
10677
10678 \series bold
10679 \emph default
10680 -
10681 \series default
10682 use-stdout
10683 \begin_inset LatexCommand \index{-\/-use-stdout}
10684
10685 \end_inset
10686
10687 .
10688  Additionally, if you happen to have visual studio installed in your windows
10689  machine, you can use it to compile your sources using a custom build and
10690  the SDCC -
10691 \emph on
10692
10693 \begin_inset ERT
10694 status collapsed
10695
10696 \begin_layout Standard
10697
10698
10699 \backslash
10700 /
10701 \end_layout
10702
10703 \end_inset
10704
10705
10706 \emph default
10707 -vc
10708 \begin_inset LatexCommand \index{-\/-vc}
10709
10710 \end_inset
10711
10712  option.
10713  Something like this should work:
10714 \newline
10715
10716 \newline
10717
10718 \series bold
10719 c:
10720 \backslash
10721 sdcc
10722 \backslash
10723 bin
10724 \backslash
10725 sdcc.exe -
10726 \series default
10727 \emph on
10728
10729 \begin_inset ERT
10730 status collapsed
10731
10732 \begin_layout Standard
10733
10734
10735 \backslash
10736 /
10737 \end_layout
10738
10739 \end_inset
10740
10741
10742 \series bold
10743 \emph default
10744 -vc -
10745 \series default
10746 \emph on
10747
10748 \begin_inset ERT
10749 status collapsed
10750
10751 \begin_layout Standard
10752
10753
10754 \backslash
10755 /
10756 \end_layout
10757
10758 \end_inset
10759
10760
10761 \series bold
10762 \emph default
10763 -model-large -c $(InputPath)
10764 \series default
10765
10766 \begin_inset VSpace bigskip
10767 \end_inset
10768
10769
10770 \end_layout
10771
10772 \begin_layout Section
10773 Environment variables
10774 \begin_inset LatexCommand \index{Environment variables}
10775
10776 \end_inset
10777
10778
10779 \end_layout
10780
10781 \begin_layout Standard
10782 SDCC recognizes the following environment variables:
10783 \end_layout
10784
10785 \begin_layout List
10786 \labelwidthstring 00.00.0000
10787
10788 \series bold
10789 SDCC_LEAVE_SIGNALS
10790 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10791
10792 \end_inset
10793
10794
10795 \series default
10796  SDCC installs a signal handler
10797 \begin_inset LatexCommand \index{signal handler}
10798
10799 \end_inset
10800
10801  to be able to delete temporary files after an user break (^C) or an exception.
10802  If this environment variable is set, SDCC won't install the signal handler
10803  in order to be able to debug SDCC.
10804 \end_layout
10805
10806 \begin_layout List
10807 \labelwidthstring 00.00.0000
10808
10809 \series bold
10810 TMP,\InsetSpace ~
10811 TEMP,\InsetSpace ~
10812 TMPDIR
10813 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10814
10815 \end_inset
10816
10817
10818 \series default
10819  Path, where temporary files will be created.
10820  The order of the variables is the search order.
10821  In a standard *nix environment these variables are not set, and there's
10822  no need to set them.
10823  On Windows it's recommended to set one of them.
10824 \end_layout
10825
10826 \begin_layout List
10827 \labelwidthstring 00.00.0000
10828
10829 \series bold
10830 SDCC_HOME
10831 \begin_inset LatexCommand \index{SDCC\_HOME}
10832
10833 \end_inset
10834
10835
10836 \series default
10837  Path, see section 
10838 \begin_inset LatexCommand \ref{sub:Install-paths}
10839
10840 \end_inset
10841
10842 \InsetSpace ~
10843
10844 \begin_inset Quotes sld
10845 \end_inset
10846
10847  Install Paths
10848 \begin_inset Quotes srd
10849 \end_inset
10850
10851 .
10852 \end_layout
10853
10854 \begin_layout List
10855 \labelwidthstring 00.00.0000
10856
10857 \series bold
10858 SDCC_INCLUDE
10859 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10860
10861 \end_inset
10862
10863
10864 \series default
10865  Path, see section 
10866 \begin_inset LatexCommand \ref{sub:Search-Paths}
10867
10868 \end_inset
10869
10870 \InsetSpace ~
10871
10872 \begin_inset Quotes sld
10873 \end_inset
10874
10875 Search Paths
10876 \begin_inset Quotes srd
10877 \end_inset
10878
10879 .
10880 \end_layout
10881
10882 \begin_layout List
10883 \labelwidthstring 00.00.0000
10884
10885 \series bold
10886 SDCC_LIB
10887 \begin_inset LatexCommand \index{SDCC\_LIB}
10888
10889 \end_inset
10890
10891
10892 \series default
10893  Path, see section 
10894 \begin_inset LatexCommand \ref{sub:Search-Paths}
10895
10896 \end_inset
10897
10898 \InsetSpace ~
10899
10900 \begin_inset Quotes sld
10901 \end_inset
10902
10903 Search Paths
10904 \begin_inset Quotes srd
10905 \end_inset
10906
10907 ..
10908 \end_layout
10909
10910 \begin_layout Standard
10911 There are some more environment variables recognized by SDCC, but these
10912  are solely used for debugging purposes.
10913  They can change or disappear very quickly, and will never be documented.
10914 \begin_inset VSpace bigskip
10915 \end_inset
10916
10917
10918 \end_layout
10919
10920 \begin_layout Section
10921 Storage Class Language Extensions
10922 \end_layout
10923
10924 \begin_layout Subsection
10925 MCS51/DS390 Storage Class
10926 \begin_inset LatexCommand \index{Storage class}
10927
10928 \end_inset
10929
10930  Language Extensions
10931 \end_layout
10932
10933 \begin_layout Standard
10934 In addition to the ANSI storage classes SDCC allows the following MCS51
10935  specific storage classes:
10936 \end_layout
10937
10938 \begin_layout Subsubsection
10939 data
10940 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10941
10942 \end_inset
10943
10944
10945 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10946
10947 \end_inset
10948
10949  / near
10950 \begin_inset LatexCommand \index{near (storage class)}
10951
10952 \end_inset
10953
10954
10955 \begin_inset LatexCommand \index{\_\_near (storage class)}
10956
10957 \end_inset
10958
10959
10960 \end_layout
10961
10962 \begin_layout Standard
10963 This is the 
10964 \series bold
10965 default
10966 \series default
10967  storage class for the Small Memory model (
10968 \emph on
10969 data
10970 \emph default
10971  and 
10972 \emph on
10973 near
10974 \emph default
10975  or the more ANSI-C compliant forms 
10976 \emph on
10977 __data
10978 \emph default
10979  and 
10980 \emph on
10981 __near
10982 \emph default
10983  can be used synonymously).
10984  Variables declared with this storage class will be allocated in the directly
10985  addressable portion of the internal RAM of a 8051, e.g.:
10986 \end_layout
10987
10988 \begin_layout Verse
10989
10990 \family typewriter
10991 __data unsigned char test_data;
10992 \end_layout
10993
10994 \begin_layout Standard
10995 Writing 0x01 to this variable generates the assembly code:
10996 \end_layout
10997
10998 \begin_layout Verse
10999
11000 \family typewriter
11001 75*00 01\InsetSpace ~
11002 \InsetSpace ~
11003 \InsetSpace ~
11004 mov\InsetSpace ~
11005 \InsetSpace ~
11006 _test_data,#0x01
11007 \end_layout
11008
11009 \begin_layout Subsubsection
11010 xdata
11011 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11012
11013 \end_inset
11014
11015
11016 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11017
11018 \end_inset
11019
11020  / far
11021 \begin_inset LatexCommand \index{far (storage class)}
11022
11023 \end_inset
11024
11025
11026 \begin_inset LatexCommand \index{\_\_far (storage class)}
11027
11028 \end_inset
11029
11030
11031 \end_layout
11032
11033 \begin_layout Standard
11034 Variables declared with this storage class will be placed in the external
11035  RAM.
11036  This is the 
11037 \series bold
11038 default
11039 \series default
11040  storage class for the Large Memory model, e.g.:
11041 \end_layout
11042
11043 \begin_layout Verse
11044
11045 \family typewriter
11046 __xdata unsigned char test_xdata;
11047 \end_layout
11048
11049 \begin_layout Standard
11050 Writing 0x01 to this variable generates the assembly code:
11051 \end_layout
11052
11053 \begin_layout Verse
11054
11055 \family typewriter
11056 90s00r00\InsetSpace ~
11057 \InsetSpace ~
11058 \InsetSpace ~
11059 mov\InsetSpace ~
11060 \InsetSpace ~
11061 dptr,#_test_xdata 
11062 \newline
11063 74\InsetSpace ~
11064 01\InsetSpace ~
11065 \InsetSpace ~
11066 \InsetSpace ~
11067 \InsetSpace ~
11068 \InsetSpace ~
11069 \InsetSpace ~
11070 mov\InsetSpace ~
11071 \InsetSpace ~
11072 a,#0x01 
11073 \newline
11074 F0\InsetSpace ~
11075 \InsetSpace ~
11076 \InsetSpace ~
11077 \InsetSpace ~
11078 \InsetSpace ~
11079 \InsetSpace ~
11080 \InsetSpace ~
11081 \InsetSpace ~
11082 \InsetSpace ~
11083 movx\InsetSpace ~
11084 @dptr,a 
11085 \end_layout
11086
11087 \begin_layout Subsubsection
11088 idata
11089 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11090
11091 \end_inset
11092
11093
11094 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11095
11096 \end_inset
11097
11098
11099 \end_layout
11100
11101 \begin_layout Standard
11102 Variables declared with this storage class will be allocated into the indirectly
11103  addressable portion of the internal ram of a 8051, e.g.:
11104 \end_layout
11105
11106 \begin_layout Verse
11107
11108 \family typewriter
11109 __idata unsigned char test_idata;
11110 \end_layout
11111
11112 \begin_layout Standard
11113 Writing 0x01 to this variable generates the assembly code:
11114 \end_layout
11115
11116 \begin_layout Verse
11117
11118 \family typewriter
11119 78r00\InsetSpace ~
11120 \InsetSpace ~
11121 \InsetSpace ~
11122 \InsetSpace ~
11123 \InsetSpace ~
11124 \InsetSpace ~
11125 \InsetSpace ~
11126 mov\InsetSpace ~
11127 \InsetSpace ~
11128 r0,#_test_idata
11129 \newline
11130 76\InsetSpace ~
11131 01\InsetSpace ~
11132 \InsetSpace ~
11133 \InsetSpace ~
11134 \InsetSpace ~
11135 \InsetSpace ~
11136 \InsetSpace ~
11137 \InsetSpace ~
11138 mov\InsetSpace ~
11139 \InsetSpace ~
11140 @r0,#0x01
11141 \end_layout
11142
11143 \begin_layout Standard
11144 Please note, the first 128 byte of idata physically access the same RAM
11145  as the data memory.
11146  The original 8051 had 128 byte idata memory, nowadays most devices have
11147  256 byte idata memory.
11148  The stack
11149 \begin_inset LatexCommand \index{stack}
11150
11151 \end_inset
11152
11153  is located in idata memory.
11154 \end_layout
11155
11156 \begin_layout Subsubsection
11157 pdata
11158 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11159
11160 \end_inset
11161
11162
11163 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11164
11165 \end_inset
11166
11167
11168 \end_layout
11169
11170 \begin_layout Standard
11171 Paged xdata access is just as straightforward as using the other addressing
11172  modes of a 8051.
11173  It is typically located at the start of xdata and has a maximum size of
11174  256 bytes.
11175  The following example writes 0x01 to the pdata variable.
11176  Please note, pdata access physically accesses xdata memory.
11177  The high byte of the address is determined by port P2 
11178 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11179
11180 \end_inset
11181
11182 (or in case of some 8051 variants by a separate Special Function Register,
11183  see section 
11184 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11185
11186 \end_inset
11187
11188 ).
11189  This is the 
11190 \series bold
11191 default
11192 \series default
11193  storage class for the Medium Memory model, e.g.:
11194 \end_layout
11195
11196 \begin_layout Verse
11197
11198 \family typewriter
11199 __pdata unsigned char test_pdata;
11200 \end_layout
11201
11202 \begin_layout Standard
11203 Writing 0x01 to this variable generates the assembly code:
11204 \end_layout
11205
11206 \begin_layout Verse
11207
11208 \family typewriter
11209 78r00\InsetSpace ~
11210 \InsetSpace ~
11211 \InsetSpace ~
11212 \InsetSpace ~
11213 \InsetSpace ~
11214 \InsetSpace ~
11215 mov r0,#_test_pdata
11216 \newline
11217 74 01\InsetSpace ~
11218 \InsetSpace ~
11219 \InsetSpace ~
11220 \InsetSpace ~
11221 \InsetSpace ~
11222 \InsetSpace ~
11223 mov a,#0x01 
11224 \newline
11225 F2\InsetSpace ~
11226 \InsetSpace ~
11227 \InsetSpace ~
11228 \InsetSpace ~
11229 \InsetSpace ~
11230 \InsetSpace ~
11231 \InsetSpace ~
11232 \InsetSpace ~
11233 \InsetSpace ~
11234 movx @r0,a
11235 \end_layout
11236
11237 \begin_layout Standard
11238 If the -
11239 \begin_inset ERT
11240 status collapsed
11241
11242 \begin_layout Standard
11243
11244
11245 \backslash
11246 /
11247 \end_layout
11248
11249 \end_inset
11250
11251 -xstack
11252 \begin_inset LatexCommand \index{-\/-xstack}
11253
11254 \end_inset
11255
11256  option is used the pdata memory area is followed by the xstack memory area
11257  and the sum of their sizes is limited to 256 bytes.
11258 \end_layout
11259
11260 \begin_layout Subsubsection
11261 code
11262 \begin_inset LatexCommand \index{code}
11263
11264 \end_inset
11265
11266
11267 \begin_inset LatexCommand \index{\_\_code}
11268
11269 \end_inset
11270
11271
11272 \end_layout
11273
11274 \begin_layout Standard
11275 'Variables' declared with this storage class will be placed in the code
11276  memory:
11277 \end_layout
11278
11279 \begin_layout Verse
11280
11281 \family typewriter
11282 __code unsigned char test_code;
11283 \end_layout
11284
11285 \begin_layout Standard
11286 Read access to this variable generates the assembly code:
11287 \end_layout
11288
11289 \begin_layout Verse
11290
11291 \family typewriter
11292 90s00r6F\InsetSpace ~
11293 \InsetSpace ~
11294 \InsetSpace ~
11295 mov dptr,#_test_code
11296 \newline
11297 E4\InsetSpace ~
11298 \InsetSpace ~
11299 \InsetSpace ~
11300 \InsetSpace ~
11301 \InsetSpace ~
11302 \InsetSpace ~
11303 \InsetSpace ~
11304 \InsetSpace ~
11305 \InsetSpace ~
11306 clr a
11307 \newline
11308 93\InsetSpace ~
11309 \InsetSpace ~
11310 \InsetSpace ~
11311 \InsetSpace ~
11312 \InsetSpace ~
11313 \InsetSpace ~
11314 \InsetSpace ~
11315 \InsetSpace ~
11316 \InsetSpace ~
11317 movc a,@a+dptr 
11318 \end_layout
11319
11320 \begin_layout Standard
11321
11322 \family typewriter
11323 char
11324 \family default
11325  indexed arrays of characters in code memory can be accessed efficiently:
11326 \end_layout
11327
11328 \begin_layout Verse
11329
11330 \family typewriter
11331 __code char test_array[] = {'c','h','e','a','p'}; 
11332 \end_layout
11333
11334 \begin_layout Standard
11335 Read access to this array using an 8-bit unsigned index generates the assembly
11336  code:
11337 \end_layout
11338
11339 \begin_layout Verse
11340
11341 \family typewriter
11342 E5*00\InsetSpace ~
11343 \InsetSpace ~
11344 \InsetSpace ~
11345 \InsetSpace ~
11346 \InsetSpace ~
11347 \InsetSpace ~
11348 mov a,_index 
11349 \end_layout
11350
11351 \begin_layout Verse
11352
11353 \family typewriter
11354 90s00r41\InsetSpace ~
11355 \InsetSpace ~
11356 \InsetSpace ~
11357 mov dptr,#_test_array
11358 \end_layout
11359
11360 \begin_layout Verse
11361
11362 \family typewriter
11363 93\InsetSpace ~
11364 \InsetSpace ~
11365 \InsetSpace ~
11366 \InsetSpace ~
11367 \InsetSpace ~
11368 \InsetSpace ~
11369 \InsetSpace ~
11370 \InsetSpace ~
11371 \InsetSpace ~
11372 movc a,@a+dptr 
11373 \end_layout
11374
11375 \begin_layout Subsubsection
11376 bit
11377 \begin_inset LatexCommand \index{bit}
11378
11379 \end_inset
11380
11381
11382 \begin_inset LatexCommand \index{\_\_bit}
11383
11384 \end_inset
11385
11386
11387 \end_layout
11388
11389 \begin_layout Standard
11390 This is a data-type and a storage class specifier.
11391  When a variable is declared as a bit, it is allocated into the bit addressable
11392  memory of 8051, e.g.:
11393 \end_layout
11394
11395 \begin_layout Verse
11396
11397 \family typewriter
11398 __bit test_bit;
11399 \end_layout
11400
11401 \begin_layout Standard
11402 Writing 1 to this variable generates the assembly code:
11403 \end_layout
11404
11405 \begin_layout Verse
11406
11407 \family typewriter
11408 D2*00\InsetSpace ~
11409 \InsetSpace ~
11410 \InsetSpace ~
11411 \InsetSpace ~
11412 \InsetSpace ~
11413 \InsetSpace ~
11414 \InsetSpace ~
11415 setb\InsetSpace ~
11416 _test_bit
11417 \end_layout
11418
11419 \begin_layout Standard
11420 The bit addressable memory consists of 128 bits which are located from 0x20
11421  to 0x2f in data memory.
11422  
11423 \newline
11424 Apart from this 8051 specific storage class most architectures support
11425  ANSI-C bitfields
11426 \begin_inset LatexCommand \index{bitfields}
11427
11428 \end_inset
11429
11430
11431 \begin_inset Foot
11432 status open
11433
11434 \begin_layout Standard
11435 Not really meant as examples, but nevertheless showing what bitfields are
11436  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11437 \end_layout
11438
11439 \end_inset
11440
11441 .
11442  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11443  signed modifier are implemented as unsigned.
11444 \end_layout
11445
11446 \begin_layout Subsubsection
11447 sfr
11448 \begin_inset LatexCommand \index{sfr}
11449
11450 \end_inset
11451
11452
11453 \begin_inset LatexCommand \index{\_\_sfr}
11454
11455 \end_inset
11456
11457  / sfr16
11458 \begin_inset LatexCommand \index{sfr16}
11459
11460 \end_inset
11461
11462
11463 \begin_inset LatexCommand \index{\_\_sfr16}
11464
11465 \end_inset
11466
11467  / sfr32
11468 \begin_inset LatexCommand \index{sfr32}
11469
11470 \end_inset
11471
11472
11473 \begin_inset LatexCommand \index{\_\_sfr32}
11474
11475 \end_inset
11476
11477  / sbit
11478 \begin_inset LatexCommand \index{\_\_sbit}
11479
11480 \end_inset
11481
11482
11483 \begin_inset LatexCommand \index{sbit}
11484
11485 \end_inset
11486
11487
11488 \end_layout
11489
11490 \begin_layout Standard
11491 Like the bit keyword, 
11492 \emph on
11493 sfr / sfr16 / sfr32 / sbit 
11494 \emph default
11495 signify both a data-type and storage class, they are used to describe the
11496  
11497 \emph on
11498 s
11499 \emph default
11500 pecial 
11501 \emph on
11502 f
11503 \emph default
11504 unction 
11505 \emph on
11506 r
11507 \emph default
11508 egisters and 
11509 \emph on
11510 s
11511 \emph default
11512 pecial 
11513 \emph on
11514 bit
11515 \emph default
11516  variables of a 8051, eg:
11517 \end_layout
11518
11519 \begin_layout Verse
11520
11521 \family typewriter
11522 __sfr __at
11523 \begin_inset LatexCommand \index{at}
11524
11525 \end_inset
11526
11527
11528 \begin_inset LatexCommand \index{\_\_at}
11529
11530 \end_inset
11531
11532  (0x80) P0;\InsetSpace ~
11533  /* special function register P0 at location 0x80 */
11534 \newline
11535
11536 \newline
11537 /* 16 bit
11538  special function register combination for timer 0
11539 \newline
11540 \InsetSpace ~
11541 \InsetSpace ~
11542  with the high byte at
11543  location 0x8C and the low byte at location 0x8A */
11544 \newline
11545 __sfr16 __at (0x8C8A)
11546  TMR0;
11547 \newline
11548
11549 \newline
11550 __sbit __at
11551 \begin_inset LatexCommand \index{at}
11552
11553 \end_inset
11554
11555
11556 \begin_inset LatexCommand \index{\_\_at}
11557
11558 \end_inset
11559
11560  (0xd7) CY;\InsetSpace ~
11561  /* CY (Carry Flag
11562 \begin_inset LatexCommand \index{Flags}
11563
11564 \end_inset
11565
11566
11567 \begin_inset LatexCommand \index{Carry flag}
11568
11569 \end_inset
11570
11571 ) */
11572 \end_layout
11573
11574 \begin_layout Standard
11575 Special function registers which are located on an address dividable by
11576  8 are bit-addressable, an
11577 \emph on
11578  sbit
11579 \emph default
11580  addresses a specific bit within these sfr.
11581 \newline
11582 16 Bit and 32 bit special function
11583  register combinations which require a certain access order are better not
11584  declared using 
11585 \emph on
11586 sfr16
11587 \emph default
11588  or 
11589 \emph on
11590 sfr32.
11591
11592 \emph default
11593  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11594  this is not guaranteed.
11595 \newline
11596
11597 \end_layout
11598
11599 \begin_layout Standard
11600 Please note, if you use a header file which was written for another compiler
11601  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11602  likely be 
11603 \emph on
11604 not 
11605 \emph default
11606 compatible.
11607  Specifically the syntax 
11608 \family typewriter
11609 \InsetSpace ~
11610 sfr P0 = 0x80;\InsetSpace ~
11611
11612 \family default
11613  is compiled 
11614 \emph on
11615 without warning
11616 \emph default
11617  by SDCC to an assignment of 0x80 to a variable called P0 
11618 \family typewriter
11619
11620 \begin_inset Marginal
11621 status collapsed
11622
11623 \begin_layout Standard
11624
11625 \series bold
11626 \InsetSpace ~
11627 !
11628 \end_layout
11629
11630 \end_inset
11631
11632 .
11633  
11634 \family default
11635 Nevertheless it is possible to write header files
11636 \begin_inset LatexCommand \index{Header files}
11637
11638 \end_inset
11639
11640
11641 \begin_inset LatexCommand \index{Include files}
11642
11643 \end_inset
11644
11645  which can be shared among different compilers (see section 
11646 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11647
11648 \end_inset
11649
11650 ).
11651  
11652 \end_layout
11653
11654 \begin_layout Subsubsection
11655 Pointers
11656 \begin_inset LatexCommand \index{Pointer}
11657
11658 \end_inset
11659
11660  to MCS51/DS390 specific memory spaces
11661 \end_layout
11662
11663 \begin_layout Standard
11664 SDCC allows (via language extensions) pointers to explicitly point to any
11665  of the memory spaces
11666 \begin_inset LatexCommand \index{Memory model}
11667
11668 \end_inset
11669
11670  of the 8051.
11671  In addition to the explicit pointers, the compiler uses (by default) generic
11672  pointers which can be used to point to any of the memory spaces.
11673 \newline
11674
11675 \newline
11676 Pointer
11677  declaration examples:
11678 \end_layout
11679
11680 \begin_layout Verse
11681
11682 \family typewriter
11683 /* pointer physically in internal ram pointing to object in external ram
11684  */ 
11685 \newline
11686 __xdata unsigned char * __data p;
11687 \newline
11688
11689 \newline
11690 /* pointer physically in external ram
11691  pointing to object in internal ram */ 
11692 \newline
11693 __data unsigned char * __xdata p;
11694 \newline
11695
11696 \newline
11697 /*
11698  pointer physically in code rom pointing to data in xdata space */ 
11699 \newline
11700 __xdata
11701  unsigned char * __code p;
11702 \newline
11703
11704 \newline
11705 /* pointer physically in code space pointing to
11706  data in code space */ 
11707 \newline
11708 __code unsigned char * __code p;
11709 \newline
11710
11711 \newline
11712 /* generic pointer
11713  physically located in xdata space */
11714 \newline
11715 unsigned char * __xdata p;
11716 \newline
11717
11718 \newline
11719 /* generic
11720  pointer physically located in default memory space */
11721 \newline
11722 unsigned char * p;
11723 \newline
11724
11725 \newline
11726 /*
11727  the following is a function pointer
11728 \begin_inset LatexCommand \index{function pointer}
11729
11730 \end_inset
11731
11732  physically located in data space */
11733 \newline
11734 char (* __data fp)(void);
11735 \end_layout
11736
11737 \begin_layout Standard
11738 Well you get the idea.
11739  
11740 \newline
11741
11742 \newline
11743 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
11744 \emph on
11745 generic
11746 \emph default
11747  pointers.
11748  
11749 \size small
11750
11751 \newline
11752
11753 \newline
11754
11755 \size default
11756 The highest order byte of the 
11757 \emph on
11758 generic
11759 \emph default
11760  pointers contains the data space information.
11761  Assembler support routines are called whenever data is stored or retrieved
11762  using 
11763 \emph on
11764 generic
11765 \emph default
11766  pointers.
11767  These are useful for developing reusable library
11768 \begin_inset LatexCommand \index{Libraries}
11769
11770 \end_inset
11771
11772  routines.
11773  Explicitly specifying the pointer
11774 \begin_inset LatexCommand \index{pointer}
11775
11776 \end_inset
11777
11778  type will generate the most efficient code.
11779 \end_layout
11780
11781 \begin_layout Subsubsection
11782 Notes on MCS51 memory
11783 \begin_inset LatexCommand \index{MCS51 memory}
11784
11785 \end_inset
11786
11787  layout
11788 \end_layout
11789
11790 \begin_layout Standard
11791 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11792  RAM memory which is structured as follows:
11793 \newline
11794
11795 \newline
11796 - Bytes 00-1F - 32 bytes to hold
11797  up to 4 banks of the registers R0 to R7, 
11798 \newline
11799 - Bytes 20-2F - 16 bytes to hold
11800  128 bit
11801 \begin_inset LatexCommand \index{bit}
11802
11803 \end_inset
11804
11805  variables and, 
11806 \newline
11807 - Bytes 30-7F - 80 bytes for general purpose use.
11808 \newline
11809
11810 \end_layout
11811
11812 \begin_layout Standard
11813 Additionally some members of the MCS51 family may have up to 128 bytes of
11814  additional, indirectly addressable, internal RAM memory (
11815 \emph on
11816 idata
11817 \emph default
11818
11819 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11820
11821 \end_inset
11822
11823
11824 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11825
11826 \end_inset
11827
11828 ).
11829  Furthermore, some chips may have some built in external memory (
11830 \emph on
11831 xdata
11832 \emph default
11833
11834 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11835
11836 \end_inset
11837
11838
11839 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11840
11841 \end_inset
11842
11843 ) which should not be confused with the internal, directly addressable RAM
11844  memory (
11845 \emph on
11846 data
11847 \emph default
11848
11849 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11850
11851 \end_inset
11852
11853
11854 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11855
11856 \end_inset
11857
11858 ).
11859  Sometimes this built in 
11860 \emph on
11861 xdata
11862 \emph default
11863  memory has to be activated before using it (you can probably find this
11864  information on the datasheet of the microcontroller your are using, see
11865  also section 
11866 \begin_inset LatexCommand \ref{sub:Startup-Code}
11867
11868 \end_inset
11869
11870 \InsetSpace ~
11871 Startup-Code).
11872 \end_layout
11873
11874 \begin_layout Standard
11875 Normally SDCC will only use the first bank
11876 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11877
11878 \end_inset
11879
11880  of registers (register bank 0), but it is possible to specify that other
11881  banks of registers (keyword 
11882 \emph on
11883 using
11884 \emph default
11885  
11886 \emph on
11887
11888 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11889
11890 \end_inset
11891
11892
11893 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11894
11895 \end_inset
11896
11897
11898 \emph default
11899 ) should be used for example in interrupt
11900 \begin_inset LatexCommand \index{interrupt}
11901
11902 \end_inset
11903
11904
11905 \begin_inset LatexCommand \index{\_\_interrupt}
11906
11907 \end_inset
11908
11909  routines.
11910  By default, the compiler will place the stack after the last byte of allocated
11911  memory for variables.
11912  For example, if the first 2 banks of registers are used, and only four
11913  bytes are used for 
11914 \emph on
11915 data
11916 \emph default
11917  variables, it will position the base of the internal stack at address 20
11918  (0x14).
11919  This implies that as the stack
11920 \begin_inset LatexCommand \index{stack}
11921
11922 \end_inset
11923
11924  grows, it will use up the remaining register banks, and the 16 bytes used
11925  by the 128 bit variables, and 80 bytes for general purpose use.
11926  If any bit variables are used, the data variables will be placed in unused
11927  register banks and after the byte holding the last bit variable.
11928  For example, if register banks 0 and 1 are used, and there are 9 bit variables
11929  (two bytes used), 
11930 \emph on
11931 data
11932 \emph default
11933  variables will be placed starting from address 0x10 to 0x20 and continue
11934  at address 0x22.
11935  You can also use -
11936 \begin_inset ERT
11937 status collapsed
11938
11939 \begin_layout Standard
11940
11941
11942 \backslash
11943 /
11944 \end_layout
11945
11946 \end_inset
11947
11948 -data-loc
11949 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11950
11951 \end_inset
11952
11953  to specify the start address of the 
11954 \emph on
11955 data
11956 \emph default
11957  and -
11958 \begin_inset ERT
11959 status collapsed
11960
11961 \begin_layout Standard
11962
11963
11964 \backslash
11965 /
11966 \end_layout
11967
11968 \end_inset
11969
11970 -iram-size
11971 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11972
11973 \end_inset
11974
11975  to specify the size of the total internal RAM (
11976 \emph on
11977 data
11978 \emph default
11979 +
11980 \emph on
11981 idata
11982 \emph default
11983 ).
11984  
11985 \newline
11986
11987 \end_layout
11988
11989 \begin_layout Standard
11990 By default the 8051 linker will place the stack after the last byte of (i)data
11991  variables.
11992  Option -
11993 \begin_inset ERT
11994 status collapsed
11995
11996 \begin_layout Standard
11997
11998
11999 \backslash
12000 /
12001 \end_layout
12002
12003 \end_inset
12004
12005 -stack-loc
12006 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12007
12008 \end_inset
12009
12010  allows you to specify the start of the stack, i.e.
12011  you could start it after any data in the general purpose area.
12012  If your microcontroller has additional indirectly addressable internal
12013  RAM (
12014 \emph on
12015 idata
12016 \emph default
12017 ) you can place the stack on it.
12018  You may also need to use -
12019 \begin_inset ERT
12020 status collapsed
12021
12022 \begin_layout Standard
12023
12024
12025 \backslash
12026 /
12027 \end_layout
12028
12029 \end_inset
12030
12031 -xdata-loc
12032 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12033
12034 \end_inset
12035
12036  to set the start address of the external RAM (
12037 \emph on
12038 xdata
12039 \emph default
12040 ) and -
12041 \begin_inset ERT
12042 status collapsed
12043
12044 \begin_layout Standard
12045
12046
12047 \backslash
12048 /
12049 \end_layout
12050
12051 \end_inset
12052
12053 -xram-size
12054 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12055
12056 \end_inset
12057
12058  to specify its size.
12059  Same goes for the code memory, using -
12060 \begin_inset ERT
12061 status collapsed
12062
12063 \begin_layout Standard
12064
12065
12066 \backslash
12067 /
12068 \end_layout
12069
12070 \end_inset
12071
12072 -code-loc
12073 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12074
12075 \end_inset
12076
12077  and -
12078 \begin_inset ERT
12079 status collapsed
12080
12081 \begin_layout Standard
12082
12083
12084 \backslash
12085 /
12086 \end_layout
12087
12088 \end_inset
12089
12090 -code-size
12091 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12092
12093 \end_inset
12094
12095 .
12096  If in doubt, don't specify any options and see if the resulting memory
12097  layout is appropriate, then you can adjust it.
12098 \end_layout
12099
12100 \begin_layout Standard
12101 The linker generates two files with memory allocation information.
12102  The first, with extension .map
12103 \begin_inset LatexCommand \index{<file>.map}
12104
12105 \end_inset
12106
12107  shows all the variables and segments.
12108  The second with extension .mem
12109 \begin_inset LatexCommand \index{<file>.mem}
12110
12111 \end_inset
12112
12113  shows the final memory layout.
12114  The linker will complain either if memory segments overlap, there is not
12115  enough memory, or there is not enough space for stack.
12116  If you get any linking warnings and/or errors related to stack or segments
12117  allocation, take a look at either the .map or .mem files to find out what
12118  the problem is.
12119  The .mem file may even suggest a solution to the problem.
12120 \begin_inset VSpace bigskip
12121 \end_inset
12122
12123
12124 \end_layout
12125
12126 \begin_layout Subsection
12127 Z80/Z180 Storage Class
12128 \begin_inset LatexCommand \index{Z80!Storage class}
12129
12130 \end_inset
12131
12132  Language Extensions
12133 \end_layout
12134
12135 \begin_layout Subsubsection
12136 sfr
12137 \begin_inset LatexCommand \index{sfr}
12138
12139 \end_inset
12140
12141
12142 \begin_inset LatexCommand \index{\_\_sfr}
12143
12144 \end_inset
12145
12146  (in/out to 8-bit addresses)
12147 \end_layout
12148
12149 \begin_layout Standard
12150 The Z80
12151 \begin_inset LatexCommand \index{Z80}
12152
12153 \end_inset
12154
12155  family has separate address spaces for memory and 
12156 \emph on
12157 i
12158 \emph default
12159 nput/
12160 \emph on
12161 o
12162 \emph default
12163 utput memory.
12164  I/O memory
12165 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12166
12167 \end_inset
12168
12169
12170 \begin_inset LatexCommand \index{Z80!I/O memory}
12171
12172 \end_inset
12173
12174
12175 \begin_inset LatexCommand \index{Z180!I/O memory}
12176
12177 \end_inset
12178
12179  is accessed with special instructions, e.g.:
12180 \end_layout
12181
12182 \begin_layout Verse
12183
12184 \family typewriter
12185 sfr at 0x78 IoPort;\InsetSpace ~
12186 \InsetSpace ~
12187 /* define a var in I/O space at 78h called IoPort */
12188  
12189 \end_layout
12190
12191 \begin_layout Standard
12192 Writing 0x01 to this variable generates the assembly code:
12193 \end_layout
12194
12195 \begin_layout Verse
12196
12197 \family typewriter
12198 3E 01\InsetSpace ~
12199 \InsetSpace ~
12200 \InsetSpace ~
12201 \InsetSpace ~
12202 \InsetSpace ~
12203 \InsetSpace ~
12204 ld a,#0x01
12205 \newline
12206 D3 78\InsetSpace ~
12207 \InsetSpace ~
12208 \InsetSpace ~
12209 \InsetSpace ~
12210 \InsetSpace ~
12211 \InsetSpace ~
12212 out (_IoPort),a 
12213 \end_layout
12214
12215 \begin_layout Subsubsection
12216 banked sfr
12217 \begin_inset LatexCommand \index{sfr}
12218
12219 \end_inset
12220
12221
12222 \begin_inset LatexCommand \index{\_\_sfr}
12223
12224 \end_inset
12225
12226  (in/out to 16-bit addresses)
12227 \end_layout
12228
12229 \begin_layout Standard
12230 The keyword 
12231 \emph on
12232 banked
12233 \emph default
12234  is used to support 16 bit addresses in I/O memory e.g.:
12235 \end_layout
12236
12237 \begin_layout Verse
12238
12239 \family typewriter
12240 sfr banked at
12241 \begin_inset LatexCommand \index{at}
12242
12243 \end_inset
12244
12245
12246 \begin_inset LatexCommand \index{\_\_at}
12247
12248 \end_inset
12249
12250  0x123 IoPort; 
12251 \end_layout
12252
12253 \begin_layout Standard
12254 Writing 0x01 to this variable generates the assembly code:
12255 \end_layout
12256
12257 \begin_layout Verse
12258
12259 \family typewriter
12260 01 23 01\InsetSpace ~
12261 \InsetSpace ~
12262 \InsetSpace ~
12263 ld bc,#_IoPort
12264 \newline
12265 3E 01\InsetSpace ~
12266 \InsetSpace ~
12267 \InsetSpace ~
12268 \InsetSpace ~
12269 \InsetSpace ~
12270 \InsetSpace ~
12271 ld a,#0x01 
12272 \newline
12273 ED 79\InsetSpace ~
12274 \InsetSpace ~
12275 \InsetSpace ~
12276 \InsetSpace ~
12277 \InsetSpace ~
12278 \InsetSpace ~
12279 out (c),a 
12280 \end_layout
12281
12282 \begin_layout Subsubsection
12283 sfr
12284 \begin_inset LatexCommand \index{sfr}
12285
12286 \end_inset
12287
12288
12289 \begin_inset LatexCommand \index{\_\_sfr}
12290
12291 \end_inset
12292
12293  (in0/out0 to 8 bit addresses on Z180
12294 \begin_inset LatexCommand \index{Z180}
12295
12296 \end_inset
12297
12298 /HD64180
12299 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12300
12301 \end_inset
12302
12303 )
12304 \end_layout
12305
12306 \begin_layout Standard
12307 The compiler option -
12308 \begin_inset ERT
12309 status collapsed
12310
12311 \begin_layout Standard
12312
12313
12314 \backslash
12315 /
12316 \end_layout
12317
12318 \end_inset
12319
12320 -portmode
12321 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12322
12323 \end_inset
12324
12325 =180 (80) and a compiler #pragma\InsetSpace ~
12326 portmode
12327 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12328
12329 \end_inset
12330
12331  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12332 ns 
12333 \family typewriter
12334 in0/out0
12335 \family default
12336  instead of 
12337 \family typewriter
12338 in/out
12339 \family default
12340 .
12341  If you include the file z180.h this will be set automatically.
12342 \begin_inset VSpace bigskip
12343 \end_inset
12344
12345
12346 \end_layout
12347
12348 \begin_layout Subsection
12349 HC08 Storage Class
12350 \begin_inset LatexCommand \index{HC08!Storage class}
12351
12352 \end_inset
12353
12354  Language Extensions
12355 \end_layout
12356
12357 \begin_layout Subsubsection
12358 data
12359 \begin_inset LatexCommand \index{data (hc08 storage class)}
12360
12361 \end_inset
12362
12363
12364 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12365
12366 \end_inset
12367
12368  
12369 \end_layout
12370
12371 \begin_layout Standard
12372 The data storage class declares a variable that resides in the first 256
12373  bytes of memory (the direct page).
12374  The HC08
12375 \begin_inset LatexCommand \index{HC08}
12376
12377 \end_inset
12378
12379  is most efficient at accessing variables (especially pointers) stored here.
12380 \end_layout
12381
12382 \begin_layout Subsubsection
12383 xdata
12384 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12385
12386 \end_inset
12387
12388
12389 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12390
12391 \end_inset
12392
12393  
12394 \end_layout
12395
12396 \begin_layout Standard
12397 The xdata storage class declares a variable that can reside anywhere in
12398  memory.
12399  This is the default if no storage class is specified.
12400  
12401 \begin_inset VSpace bigskip
12402 \end_inset
12403
12404
12405 \end_layout
12406
12407 \begin_layout Section
12408 Absolute Addressing
12409 \begin_inset LatexCommand \index{Absolute addressing}
12410
12411 \end_inset
12412
12413
12414 \end_layout
12415
12416 \begin_layout Standard
12417 Data items can be assigned an absolute address with the 
12418 \emph on
12419 at
12420 \begin_inset LatexCommand \index{at}
12421
12422 \end_inset
12423
12424
12425 \begin_inset LatexCommand \index{\_\_at}
12426
12427 \end_inset
12428
12429  <address>
12430 \emph default
12431  keyword, in addition to a storage class, e.g.:
12432 \end_layout
12433
12434 \begin_layout Verse
12435
12436 \family typewriter
12437 xdata
12438 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12439
12440 \end_inset
12441
12442
12443 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12444
12445 \end_inset
12446
12447  at
12448 \begin_inset LatexCommand \index{at}
12449
12450 \end_inset
12451
12452
12453 \begin_inset LatexCommand \index{\_\_at}
12454
12455 \end_inset
12456
12457  0x7ffe unsigned int chksum;
12458 \end_layout
12459
12460 \begin_layout Standard
12461 or, better conforming to ISO/IEC 9899 C:
12462 \end_layout
12463
12464 \begin_layout Verse
12465
12466 \family typewriter
12467 __xdata __at (0x7ffe) unsigned int chksum;
12468 \end_layout
12469
12470 \begin_layout Standard
12471 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12472  of the external ram.
12473  The compiler does 
12474 \emph on
12475 not
12476 \emph default
12477  reserve any space for variables declared in this way
12478 \begin_inset Marginal
12479 status collapsed
12480
12481 \begin_layout Standard
12482
12483 \series bold
12484 \InsetSpace ~
12485 !
12486 \end_layout
12487
12488 \end_inset
12489
12490  (they are implemented with an equate in the assembler).
12491  Thus it is left to the programmer to make sure there are no overlaps with
12492  other variables that are declared without the absolute address.
12493  The assembler listing file (.lst
12494 \begin_inset LatexCommand \index{<file>.lst}
12495
12496 \end_inset
12497
12498 ) and the linker output files (.rst
12499 \begin_inset LatexCommand \index{<file>.rst}
12500
12501 \end_inset
12502
12503 ) and (.map
12504 \begin_inset LatexCommand \index{<file>.map}
12505
12506 \end_inset
12507
12508 ) are good places to look for such overlaps.
12509  Variables with an absolute address are 
12510 \emph on
12511 not
12512 \begin_inset Marginal
12513 status collapsed
12514
12515 \begin_layout Standard
12516
12517 \series bold
12518 \InsetSpace ~
12519 !
12520 \end_layout
12521
12522 \end_inset
12523
12524
12525 \emph default
12526  initialized
12527 \begin_inset LatexCommand \index{Variable initialization}
12528
12529 \end_inset
12530
12531 .
12532 \end_layout
12533
12534 \begin_layout Standard
12535 In case of memory mapped I/O devices the keyword 
12536 \emph on
12537 volatile
12538 \emph default
12539  has to be used to tell the compiler that accesses might not be removed:
12540 \end_layout
12541
12542 \begin_layout Verse
12543
12544 \family typewriter
12545 volatile
12546 \begin_inset LatexCommand \index{volatile}
12547
12548 \end_inset
12549
12550  __xdata
12551 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12552
12553 \end_inset
12554
12555  __at
12556 \begin_inset LatexCommand \index{at}
12557
12558 \end_inset
12559
12560  (0x8000) unsigned char PORTA_8255;
12561 \end_layout
12562
12563 \begin_layout Standard
12564 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12565 r) array
12566 \family typewriter
12567 \size footnotesize
12568
12569 \begin_inset LatexCommand \index{Aligned array}
12570
12571 \end_inset
12572
12573
12574 \family default
12575 \size default
12576  starts at a block (256 byte) boundary
12577 \begin_inset LatexCommand \index{block boundary}
12578
12579 \end_inset
12580
12581  (section 
12582 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12583
12584 \end_inset
12585
12586  has an example).
12587 \newline
12588 Absolute addresses can be specified for variables in all
12589  storage classes, e.g.:
12590 \end_layout
12591
12592 \begin_layout Verse
12593
12594 \family typewriter
12595 __bit
12596 \begin_inset LatexCommand \index{bit}
12597
12598 \end_inset
12599
12600  __at
12601 \begin_inset LatexCommand \index{at}
12602
12603 \end_inset
12604
12605  (0x02) bvar;
12606 \end_layout
12607
12608 \begin_layout Standard
12609 The above example will allocate the variable at offset 0x02 in the bit-addressab
12610 le space.
12611  There is no real advantage to assigning absolute addresses to variables
12612  in this manner, unless you want strict control over all the variables allocated.
12613  One possible use would be to write hardware portable code.
12614  For example, if you have a routine that uses one or more of the microcontroller
12615  I/O pins, and such pins are different for two different hardwares, you
12616  can declare the I/O pins in your routine using:
12617 \end_layout
12618
12619 \begin_layout Verse
12620
12621 \family typewriter
12622 extern volatile
12623 \begin_inset LatexCommand \index{volatile}
12624
12625 \end_inset
12626
12627  __bit MOSI;\InsetSpace ~
12628 \InsetSpace ~
12629 \InsetSpace ~
12630 \InsetSpace ~
12631 /* master out, slave in */
12632 \newline
12633 extern volatile __bit MISO;\InsetSpace ~
12634 \InsetSpace ~
12635 \InsetSpace ~
12636 \InsetSpace ~
12637 /* master
12638  in, slave out */
12639 \newline
12640 extern volatile __bit MCLK;\InsetSpace ~
12641 \InsetSpace ~
12642 \InsetSpace ~
12643 \InsetSpace ~
12644 /* master clock */
12645 \newline
12646
12647 \newline
12648 /* Input and
12649  Output of a byte on a 3-wire serial bus.
12650 \newline
12651 \InsetSpace ~
12652 \InsetSpace ~
12653 \InsetSpace ~
12654 If needed adapt polarity of clock,
12655  polarity of data and bit order
12656 \newline
12657 \InsetSpace ~
12658 */
12659 \newline
12660 unsigned char spi_io(unsigned char out_byte)
12661  
12662 \newline
12663
12664 \newline
12665 \InsetSpace ~
12666 \InsetSpace ~
12667 \InsetSpace ~
12668 \InsetSpace ~
12669 unsigned char i=8;
12670 \newline
12671 \InsetSpace ~
12672 \InsetSpace ~
12673 \InsetSpace ~
12674 \InsetSpace ~
12675 do { 
12676 \newline
12677 \InsetSpace ~
12678 \InsetSpace ~
12679 \InsetSpace ~
12680 \InsetSpace ~
12681 \InsetSpace ~
12682 \InsetSpace ~
12683 \InsetSpace ~
12684 \InsetSpace ~
12685 MOSI = out_byte & 0x80; 
12686 \newline
12687 \InsetSpace ~
12688 \InsetSpace ~
12689 \InsetSpace ~
12690 \InsetSpace ~
12691 \InsetSpace ~
12692 \InsetSpace ~
12693 \InsetSpace ~
12694 \InsetSpace ~
12695 out_byte <<= 1;
12696 \newline
12697 \InsetSpace ~
12698 \InsetSpace ~
12699 \InsetSpace ~
12700 \InsetSpace ~
12701 \InsetSpace ~
12702 \InsetSpace ~
12703 \InsetSpace ~
12704 \InsetSpace ~
12705 MCLK =
12706  1; 
12707 \newline
12708 \InsetSpace ~
12709 \InsetSpace ~
12710 \InsetSpace ~
12711 \InsetSpace ~
12712 \InsetSpace ~
12713 \InsetSpace ~
12714 \InsetSpace ~
12715 \InsetSpace ~
12716 /* _asm nop _endasm; */\InsetSpace ~
12717 \InsetSpace ~
12718 \InsetSpace ~
12719 \InsetSpace ~
12720 \InsetSpace ~
12721 \InsetSpace ~
12722 \InsetSpace ~
12723 \InsetSpace ~
12724 /* for slow peripherals */
12725 \newline
12726 \InsetSpace ~
12727 \InsetSpace ~
12728 \InsetSpace ~
12729 \InsetSpace ~
12730 \InsetSpace ~
12731 \InsetSpace ~
12732 \InsetSpace ~
12733 \InsetSpace ~
12734 if(MISO) 
12735 \newline
12736 \InsetSpace ~
12737 \InsetSpace ~
12738 \InsetSpace ~
12739 \InsetSpace ~
12740 \InsetSpace ~
12741 \InsetSpace ~
12742 \InsetSpace ~
12743 \InsetSpace ~
12744 \InsetSpace ~
12745 \InsetSpace ~
12746 \InsetSpace ~
12747 \InsetSpace ~
12748 out_byte +=
12749  1; 
12750 \newline
12751 \InsetSpace ~
12752 \InsetSpace ~
12753 \InsetSpace ~
12754 \InsetSpace ~
12755 \InsetSpace ~
12756 \InsetSpace ~
12757 \InsetSpace ~
12758 \InsetSpace ~
12759 MCLK = 0; 
12760 \newline
12761 \InsetSpace ~
12762 \InsetSpace ~
12763 \InsetSpace ~
12764 \InsetSpace ~
12765 } while(--i);
12766 \newline
12767 \InsetSpace ~
12768 \InsetSpace ~
12769 \InsetSpace ~
12770 \InsetSpace ~
12771 return out_byte; 
12772 \newline
12773 }
12774 \end_layout
12775
12776 \begin_layout Standard
12777 Then, someplace in the code for the first hardware you would use
12778 \end_layout
12779
12780 \begin_layout Verse
12781
12782 \family typewriter
12783 __bit __at
12784 \begin_inset LatexCommand \index{at}
12785
12786 \end_inset
12787
12788
12789 \begin_inset LatexCommand \index{\_\_at}
12790
12791 \end_inset
12792
12793  (0x80) MOSI;\InsetSpace ~
12794 \InsetSpace ~
12795 \InsetSpace ~
12796 \InsetSpace ~
12797 /* I/O port 0, bit 0 */
12798 \newline
12799 __bit __at (0x81) MISO;\InsetSpace ~
12800 \InsetSpace ~
12801 \InsetSpace ~
12802 \InsetSpace ~
12803 /* I/O port 0,
12804  bit 1 */
12805 \newline
12806 __bit __at (0x82) MCLK;\InsetSpace ~
12807 \InsetSpace ~
12808 \InsetSpace ~
12809 \InsetSpace ~
12810 /* I/O port 0, bit 2 */
12811 \end_layout
12812
12813 \begin_layout Standard
12814 Similarly, for the second hardware you would use
12815 \end_layout
12816
12817 \begin_layout Verse
12818
12819 \family typewriter
12820 __bit __at (0x83) MOSI;\InsetSpace ~
12821 \InsetSpace ~
12822 \InsetSpace ~
12823 \InsetSpace ~
12824 /* I/O port 0, bit 3 */
12825 \newline
12826 __bit __at (0x91) MISO;\InsetSpace ~
12827 \InsetSpace ~
12828 \InsetSpace ~
12829 \InsetSpace ~
12830 /*
12831  I/O port 1, bit 1 */
12832 \newline
12833 __bit
12834 \begin_inset LatexCommand \index{bit}
12835
12836 \end_inset
12837
12838  __at (0x92) MCLK;\InsetSpace ~
12839 \InsetSpace ~
12840 \InsetSpace ~
12841 \InsetSpace ~
12842 /* I/O port 1, bit 2 */
12843 \end_layout
12844
12845 \begin_layout Standard
12846 and you can use the same hardware dependent routine without changes, as
12847  for example in a library.
12848  This is somehow similar to sbit, but only one absolute address has to be
12849  specified in the whole project.
12850 \begin_inset VSpace bigskip
12851 \end_inset
12852
12853
12854 \end_layout
12855
12856 \begin_layout Section
12857 Parameters
12858 \begin_inset LatexCommand \index{Parameters}
12859
12860 \end_inset
12861
12862
12863 \begin_inset LatexCommand \index{function parameter}
12864
12865 \end_inset
12866
12867  & Local Variables
12868 \begin_inset LatexCommand \index{local variables}
12869
12870 \end_inset
12871
12872
12873 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12874
12875 \end_inset
12876
12877
12878 \end_layout
12879
12880 \begin_layout Standard
12881 Automatic (local) variables and parameters to functions can either be placed
12882  on the stack or in data-space.
12883  The default action of the compiler is to place these variables in the internal
12884  RAM (for small model) or external RAM (for large model).
12885  This in fact makes them similar to 
12886 \emph on
12887 static
12888 \begin_inset LatexCommand \index{static}
12889
12890 \end_inset
12891
12892
12893 \emph default
12894  so by default functions are non-reentrant
12895 \begin_inset LatexCommand \index{reentrant}
12896
12897 \end_inset
12898
12899 .
12900  
12901 \newline
12902
12903 \newline
12904 They can be placed on the stack
12905 \begin_inset LatexCommand \index{stack}
12906
12907 \end_inset
12908
12909  by using the
12910 \emph on
12911  -
12912 \begin_inset ERT
12913 status collapsed
12914
12915 \begin_layout Standard
12916
12917
12918 \backslash
12919 /
12920 \end_layout
12921
12922 \end_inset
12923
12924 -stack-auto
12925 \begin_inset LatexCommand \index{-\/-stack-auto}
12926
12927 \end_inset
12928
12929
12930 \emph default
12931  option, by using 
12932 \emph on
12933 #pragma\InsetSpace ~
12934 stackauto
12935 \emph default
12936
12937 \begin_inset LatexCommand \index{\#pragma stackauto}
12938
12939 \end_inset
12940
12941  or by using the 
12942 \emph on
12943 reentrant
12944 \begin_inset LatexCommand \index{reentrant}
12945
12946 \end_inset
12947
12948
12949 \emph default
12950  keyword in the function declaration, e.g.:
12951 \end_layout
12952
12953 \begin_layout Verse
12954
12955 \family typewriter
12956 unsigned char foo(char i) __reentrant 
12957 \newline
12958
12959 \newline
12960 \InsetSpace ~
12961 \InsetSpace ~
12962 \InsetSpace ~
12963 \InsetSpace ~
12964 ...
12965  
12966 \newline
12967 }
12968 \end_layout
12969
12970 \begin_layout Standard
12971 Since stack space on 8051 is limited, the 
12972 \emph on
12973 reentrant 
12974 \emph default
12975 keyword or the
12976 \emph on
12977  -
12978 \begin_inset ERT
12979 status collapsed
12980
12981 \begin_layout Standard
12982
12983
12984 \backslash
12985 /
12986 \end_layout
12987
12988 \end_inset
12989
12990 -stack-auto
12991 \emph default
12992  option should be used sparingly.
12993  Note that the reentrant keyword just means that the parameters & local
12994  variables will be allocated to the stack, it 
12995 \emph on
12996 does not
12997 \emph default
12998  mean that the function is register bank
12999 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13000
13001 \end_inset
13002
13003  independent.
13004 \newline
13005
13006 \newline
13007 Local variables
13008 \begin_inset LatexCommand \index{local variables}
13009
13010 \end_inset
13011
13012  can be assigned storage classes and absolute
13013 \begin_inset LatexCommand \index{Absolute addressing}
13014
13015 \end_inset
13016
13017  addresses, e.g.: 
13018 \end_layout
13019
13020 \begin_layout Verse
13021
13022 \family typewriter
13023 unsigned char foo() 
13024 \newline
13025 {
13026 \newline
13027 \InsetSpace ~
13028 \InsetSpace ~
13029 \InsetSpace ~
13030 \InsetSpace ~
13031 __xdata unsigned char i;
13032 \newline
13033 \InsetSpace ~
13034 \InsetSpace ~
13035 \InsetSpace ~
13036 \InsetSpace ~
13037 __bit bvar;
13038 \newline
13039 \InsetSpace ~
13040 \InsetSpace ~
13041 \InsetSpace ~
13042 \InsetSpace ~
13043 __data __at
13044 \begin_inset LatexCommand \index{at}
13045
13046 \end_inset
13047
13048  (0x31) unsigned char j;
13049 \newline
13050 \InsetSpace ~
13051 \InsetSpace ~
13052 \InsetSpace ~
13053 \InsetSpace ~
13054 ...
13055  
13056 \newline
13057 }
13058 \end_layout
13059
13060 \begin_layout Standard
13061 In the above example the variable 
13062 \emph on
13063 i
13064 \emph default
13065  will be allocated in the external ram, 
13066 \emph on
13067 bvar
13068 \emph default
13069  in bit addressable space and
13070 \emph on
13071  j
13072 \emph default
13073  in internal ram.
13074  When compiled with 
13075 \emph on
13076 -
13077 \begin_inset ERT
13078 status collapsed
13079
13080 \begin_layout Standard
13081
13082
13083 \backslash
13084 /
13085 \end_layout
13086
13087 \end_inset
13088
13089 -stack-auto
13090 \emph default
13091  or when a function is declared as 
13092 \emph on
13093 reentrant
13094 \emph default
13095  this should only be done for static variables.
13096 \end_layout
13097
13098 \begin_layout Standard
13099 Parameters
13100 \begin_inset LatexCommand \index{function parameter}
13101
13102 \end_inset
13103
13104  however are not allowed any storage class
13105 \begin_inset LatexCommand \index{Storage class}
13106
13107 \end_inset
13108
13109 , (storage classes for parameters will be ignored), their allocation is
13110  governed by the memory model in use, and the reentrancy options.
13111 \end_layout
13112
13113 \begin_layout Standard
13114 It is however allowed to use bit parameters in reentrant functions and also
13115  non-static local bit variables are supported.
13116  Efficient use is limited to 8 semi-bitregisters in bit space.
13117  They are pushed and popped to stack
13118 \begin_inset LatexCommand \index{stack}
13119
13120 \end_inset
13121
13122  as a single byte just like the normal registers.
13123 \end_layout
13124
13125 \begin_layout Section
13126 Overlaying
13127 \begin_inset LatexCommand \label{sub:Overlaying}
13128
13129 \end_inset
13130
13131
13132 \begin_inset LatexCommand \index{Overlaying}
13133
13134 \end_inset
13135
13136
13137 \end_layout
13138
13139 \begin_layout Standard
13140 For non-reentrant
13141 \begin_inset LatexCommand \index{reentrant}
13142
13143 \end_inset
13144
13145  functions SDCC will try to reduce internal ram space usage by overlaying
13146  parameters and local variables of a function (if possible).
13147  Parameters and local variables
13148 \begin_inset LatexCommand \index{local variables}
13149
13150 \end_inset
13151
13152  of a function will be allocated to an overlayable segment if the function
13153  has 
13154 \emph on
13155 no other function calls and the function is non-reentrant and the memory
13156  model
13157 \begin_inset LatexCommand \index{Memory model}
13158
13159 \end_inset
13160
13161  is small.
13162
13163 \emph default
13164  If an explicit storage class
13165 \begin_inset LatexCommand \index{Storage class}
13166
13167 \end_inset
13168
13169  is specified for a local variable, it will NOT be overlayed.
13170 \end_layout
13171
13172 \begin_layout Standard
13173 Note that the compiler (not the linkage editor) makes the decision for overlayin
13174 g the data items.
13175  Functions that are called from an interrupt service routine
13176 \begin_inset Marginal
13177 status collapsed
13178
13179 \begin_layout Standard
13180
13181 \series bold
13182 !
13183 \end_layout
13184
13185 \end_inset
13186
13187  should be preceded by a #pragma\InsetSpace ~
13188 nooverlay
13189 \begin_inset LatexCommand \index{\#pragma nooverlay}
13190
13191 \end_inset
13192
13193  if they are not reentrant.
13194 \end_layout
13195
13196 \begin_layout Standard
13197 Also note that the compiler does not do any processing of inline assembler
13198  code, so the compiler might incorrectly assign local variables and parameters
13199  of a function into the overlay segment if the inline assembler code calls
13200  other c-functions that might use the overlay.
13201  In that case the #pragma\InsetSpace ~
13202 nooverlay should be used.
13203 \end_layout
13204
13205 \begin_layout Standard
13206 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13207 tion
13208 \begin_inset LatexCommand \index{Multiplication}
13209
13210 \end_inset
13211
13212  or division
13213 \begin_inset LatexCommand \index{Division}
13214
13215 \end_inset
13216
13217  will NOT be overlayed since these are implemented using external functions,
13218  e.g.:
13219 \end_layout
13220
13221 \begin_layout Verse
13222
13223 \family typewriter
13224 #pragma save 
13225 \newline
13226 #pragma nooverlay
13227 \begin_inset LatexCommand \index{\#pragma nooverlay}
13228
13229 \end_inset
13230
13231  
13232 \newline
13233 void set_error(unsigned char errcd) 
13234 \newline
13235 {
13236 \newline
13237 \InsetSpace ~
13238 \InsetSpace ~
13239 \InsetSpace ~
13240 \InsetSpace ~
13241 P3 = errcd;
13242 \newline
13243
13244 \newline
13245 #pragma restore 
13246 \newline
13247
13248 \newline
13249 void
13250  some_isr () __interrupt
13251 \begin_inset LatexCommand \index{interrupt}
13252
13253 \end_inset
13254
13255  (2)
13256 \newline
13257 {
13258 \newline
13259 \InsetSpace ~
13260 \InsetSpace ~
13261 \InsetSpace ~
13262 \InsetSpace ~
13263 ...
13264 \newline
13265 \InsetSpace ~
13266 \InsetSpace ~
13267 \InsetSpace ~
13268 \InsetSpace ~
13269 set_error(10);
13270 \newline
13271 \InsetSpace ~
13272 \InsetSpace ~
13273 \InsetSpace ~
13274 \InsetSpace ~
13275 ...
13276  
13277 \newline
13278 }
13279 \end_layout
13280
13281 \begin_layout Standard
13282 In the above example the parameter 
13283 \emph on
13284 errcd
13285 \emph default
13286  for the function 
13287 \emph on
13288 set_error
13289 \emph default
13290  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13291 nooverlay was
13292  not present, this could cause unpredictable runtime behavior when called
13293  from an interrupt service routine.
13294  The #pragma\InsetSpace ~
13295 nooverlay ensures that the parameters and local variables for
13296  the function are NOT overlayed.
13297 \begin_inset VSpace bigskip
13298 \end_inset
13299
13300
13301 \end_layout
13302
13303 \begin_layout Section
13304 Interrupt Service Routines
13305 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13306
13307 \end_inset
13308
13309
13310 \end_layout
13311
13312 \begin_layout Subsection
13313 General Information
13314 \end_layout
13315
13316 \begin_layout Standard
13317 SDCC allows 
13318 \emph on
13319 i
13320 \emph default
13321 nterrupt 
13322 \emph on
13323 s
13324 \emph default
13325 ervice 
13326 \emph on
13327 r
13328 \emph default
13329 outines to be coded in C, with some extended keywords.
13330 \end_layout
13331
13332 \begin_layout Verse
13333
13334 \family typewriter
13335 void timer_isr (void) __interrupt (1) __using (1) 
13336 \newline
13337
13338 \newline
13339 \InsetSpace ~
13340 \InsetSpace ~
13341 \InsetSpace ~
13342 \InsetSpace ~
13343 ...
13344  
13345 \newline
13346 }
13347 \end_layout
13348
13349 \begin_layout Standard
13350 The optional number following the 
13351 \emph on
13352 interrupt
13353 \begin_inset LatexCommand \index{interrupt}
13354
13355 \end_inset
13356
13357
13358 \begin_inset LatexCommand \index{\_\_interrupt}
13359
13360 \end_inset
13361
13362
13363 \emph default
13364  keyword is the interrupt number this routine will service.
13365  When present, the compiler will insert a call to this routine in the interrupt
13366  vector table
13367 \begin_inset LatexCommand \index{interrupt vector table}
13368
13369 \end_inset
13370
13371  for the interrupt number specified.
13372  If you have multiple source files in your project, interrupt service routines
13373  can be present in any of them, but a prototype of the isr MUST be present
13374  or included in the file that contains the function 
13375 \emph on
13376 main
13377 \emph default
13378 .
13379  The optional (8051 specific) keyword 
13380 \emph on
13381 using
13382 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13383
13384 \end_inset
13385
13386
13387 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13388
13389 \end_inset
13390
13391
13392 \emph default
13393  can be used to tell the compiler to use the specified register bank when
13394  generating code for this function.
13395  
13396 \newline
13397 Interrupt service routines open the door for some very interesting bugs:
13398 \end_layout
13399
13400 \begin_layout Subsubsection
13401 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13402
13403 \end_inset
13404
13405 Common interrupt pitfall: variable not declared 
13406 \emph on
13407 volatile
13408 \end_layout
13409
13410 \begin_layout Standard
13411 If an interrupt service routine changes variables which are accessed by
13412  other functions these variables have to be declared 
13413 \emph on
13414 volatile
13415 \emph default
13416
13417 \begin_inset LatexCommand \index{volatile}
13418
13419 \end_inset
13420
13421 .
13422  See 
13423 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13424
13425 \end_inset
13426
13427  .
13428 \end_layout
13429
13430 \begin_layout Subsubsection
13431 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13432
13433 \end_inset
13434
13435 Common interrupt pitfall: 
13436 \emph on
13437 non-atomic access
13438 \end_layout
13439
13440 \begin_layout Standard
13441 If the access to these variables is not 
13442 \emph on
13443 atomic
13444 \begin_inset LatexCommand \index{atomic}
13445
13446 \end_inset
13447
13448
13449 \emph default
13450  (i.e.
13451  the processor needs more than one instruction for the access and could
13452  be interrupted while accessing the variable) the interrupt must be disabled
13453  during the access to avoid inconsistent data.
13454  
13455 \newline
13456 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13457  and should be protected by disabling interrupts.
13458  You're not automatically on the safe side if you use 8 bit variables though.
13459  We need an example here: f.e.
13460  on the 8051 the harmless looking 
13461 \begin_inset Quotes srd
13462 \end_inset
13463
13464
13465 \family typewriter
13466 flags\InsetSpace ~
13467 |=\InsetSpace ~
13468 0x80;
13469 \family default
13470
13471 \begin_inset Quotes sld
13472 \end_inset
13473
13474  is not atomic if 
13475 \family typewriter
13476 flags
13477 \family default
13478  resides in xdata.
13479  Setting 
13480 \begin_inset Quotes srd
13481 \end_inset
13482
13483
13484 \family typewriter
13485 flags\InsetSpace ~
13486 |=\InsetSpace ~
13487 0x40;
13488 \family default
13489
13490 \begin_inset Quotes sld
13491 \end_inset
13492
13493  from within an interrupt routine might get lost if the interrupt occurs
13494  at the wrong time.
13495  
13496 \begin_inset Quotes sld
13497 \end_inset
13498
13499
13500 \family typewriter
13501 counter\InsetSpace ~
13502 +=\InsetSpace ~
13503 8;
13504 \family default
13505
13506 \begin_inset Quotes srd
13507 \end_inset
13508
13509  is not atomic on the 8051 even if 
13510 \family typewriter
13511 counter
13512 \family default
13513  is located in data memory.
13514 \newline
13515 Bugs like these are hard to reproduce and can
13516  cause a lot of trouble.
13517  
13518 \end_layout
13519
13520 \begin_layout Subsubsection
13521 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13522
13523 \end_inset
13524
13525 Common interrupt pitfall: 
13526 \emph on
13527 stack overflow
13528 \end_layout
13529
13530 \begin_layout Standard
13531 The return address and the registers used in the interrupt service routine
13532  are saved on the stack
13533 \begin_inset LatexCommand \index{stack}
13534
13535 \end_inset
13536
13537  so there must be sufficient stack space.
13538  If there isn't variables or registers (or even the return address itself)
13539  will be corrupted.
13540  This 
13541 \emph on
13542 stack overflow
13543 \emph default
13544
13545 \begin_inset LatexCommand \index{stack overflow}
13546
13547 \end_inset
13548
13549  is most likely to happen if the interrupt occurs during the 
13550 \begin_inset Quotes sld
13551 \end_inset
13552
13553 deepest
13554 \begin_inset Quotes srd
13555 \end_inset
13556
13557  subroutine when the stack is already in use for f.e.
13558  many return addresses.
13559 \end_layout
13560
13561 \begin_layout Subsubsection
13562 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13563
13564 \end_inset
13565
13566 Common interrupt pitfall: 
13567 \emph on
13568 use of non-reentrant functions
13569 \end_layout
13570
13571 \begin_layout Standard
13572 A special note here, int (16 bit) and long (32 bit) integer division
13573 \begin_inset LatexCommand \index{Division}
13574
13575 \end_inset
13576
13577 , multiplication
13578 \begin_inset LatexCommand \index{Multiplication}
13579
13580 \end_inset
13581
13582  & modulus
13583 \begin_inset LatexCommand \index{Modulus}
13584
13585 \end_inset
13586
13587  and floating-point
13588 \begin_inset LatexCommand \index{Floating point support}
13589
13590 \end_inset
13591
13592  operations are implemented using external support routines.
13593  If an interrupt service routine needs to do any of these operations then
13594  the support routines (as mentioned in a following section) will have to
13595  be recompiled using the
13596 \emph on
13597  -
13598 \begin_inset ERT
13599 status collapsed
13600
13601 \begin_layout Standard
13602
13603
13604 \backslash
13605 /
13606 \end_layout
13607
13608 \end_inset
13609
13610 -stack-auto
13611 \begin_inset LatexCommand \index{-\/-stack-auto}
13612
13613 \end_inset
13614
13615
13616 \emph default
13617  option and the source file will need to be compiled using the 
13618 \emph on
13619 -
13620 \begin_inset ERT
13621 status collapsed
13622
13623 \begin_layout Standard
13624
13625
13626 \backslash
13627 /
13628 \end_layout
13629
13630 \end_inset
13631
13632 -int-long-reent
13633 \emph default
13634
13635 \begin_inset LatexCommand \index{-\/-int-long-reent}
13636
13637 \end_inset
13638
13639  compiler option.
13640  
13641 \newline
13642 Note, the type promotion
13643 \begin_inset LatexCommand \index{type promotion}
13644
13645 \end_inset
13646
13647  required by ANSI C can cause 16 bit routines to be used
13648 \begin_inset Marginal
13649 status collapsed
13650
13651 \begin_layout Standard
13652
13653 \series bold
13654 \InsetSpace ~
13655 !
13656 \end_layout
13657
13658 \end_inset
13659
13660  without the programmer being aware of it.
13661  See f.e.
13662  the cast 
13663 \family typewriter
13664 (unsigned char)(tail-1)
13665 \family default
13666  within the if clause in section 
13667 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13668
13669 \end_inset
13670
13671 .
13672 \end_layout
13673
13674 \begin_layout Standard
13675 Calling other functions from an interrupt service routine is not recommended,
13676  avoid it if possible.
13677  Note that when some function is called from an interrupt service routine
13678  it should be preceded by a #pragma\InsetSpace ~
13679 nooverlay
13680 \begin_inset LatexCommand \index{\#pragma nooverlay}
13681
13682 \end_inset
13683
13684  if it is not reentrant.
13685  Furthermore nonreentrant functions should not be called from the main program
13686  while the interrupt service routine might be active.
13687  They also must not be called from low priority interrupt service routines
13688  while a high priority interrupt service routine might be active.
13689  You could use semaphores or make the function
13690 \emph on
13691  critical
13692 \emph default
13693  if all parameters are passed in registers.
13694 \newline
13695  Also see section 
13696 \begin_inset LatexCommand \ref{sub:Overlaying}
13697
13698 \end_inset
13699
13700 \InsetSpace ~
13701 about Overlaying and section 
13702 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13703
13704 \end_inset
13705
13706 \InsetSpace ~
13707 about Functions using private register banks.
13708 \begin_inset VSpace bigskip
13709 \end_inset
13710
13711
13712 \end_layout
13713
13714 \begin_layout Subsection
13715 MCS51/DS390 Interrupt Service Routines
13716 \end_layout
13717
13718 \begin_layout Standard
13719 Interrupt
13720 \begin_inset LatexCommand \index{interrupt}
13721
13722 \end_inset
13723
13724  numbers and the corresponding address & descriptions for the Standard 8051/8052
13725  are listed below.
13726  SDCC will automatically adjust the 
13727 \begin_inset LatexCommand \index{interrupt vector table}
13728
13729 \end_inset
13730
13731  to the maximum interrupt number specified.
13732 \newline
13733
13734 \end_layout
13735
13736 \begin_layout Standard
13737 \align center
13738 \begin_inset Tabular
13739 <lyxtabular version="3" rows="9" columns="3">
13740 <features>
13741 <column alignment="center" valignment="top" leftline="true" width="0in">
13742 <column alignment="left" valignment="top" leftline="true" width="0in">
13743 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13744 <row topline="true" bottomline="true">
13745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13746 \begin_inset Text
13747
13748 \begin_layout Standard
13749 Interrupt #
13750 \end_layout
13751
13752 \end_inset
13753 </cell>
13754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13755 \begin_inset Text
13756
13757 \begin_layout Standard
13758 Description
13759 \end_layout
13760
13761 \end_inset
13762 </cell>
13763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13764 \begin_inset Text
13765
13766 \begin_layout Standard
13767 Vector Address
13768 \end_layout
13769
13770 \end_inset
13771 </cell>
13772 </row>
13773 <row topline="true">
13774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13775 \begin_inset Text
13776
13777 \begin_layout Standard
13778 0
13779 \end_layout
13780
13781 \end_inset
13782 </cell>
13783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13784 \begin_inset Text
13785
13786 \begin_layout Standard
13787 External 0
13788 \end_layout
13789
13790 \end_inset
13791 </cell>
13792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13793 \begin_inset Text
13794
13795 \begin_layout Standard
13796 0x0003
13797 \end_layout
13798
13799 \end_inset
13800 </cell>
13801 </row>
13802 <row topline="true">
13803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13804 \begin_inset Text
13805
13806 \begin_layout Standard
13807 1
13808 \end_layout
13809
13810 \end_inset
13811 </cell>
13812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13813 \begin_inset Text
13814
13815 \begin_layout Standard
13816 Timer 0
13817 \end_layout
13818
13819 \end_inset
13820 </cell>
13821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13822 \begin_inset Text
13823
13824 \begin_layout Standard
13825 0x000b
13826 \end_layout
13827
13828 \end_inset
13829 </cell>
13830 </row>
13831 <row topline="true">
13832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13833 \begin_inset Text
13834
13835 \begin_layout Standard
13836 2
13837 \end_layout
13838
13839 \end_inset
13840 </cell>
13841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13842 \begin_inset Text
13843
13844 \begin_layout Standard
13845 External 1
13846 \end_layout
13847
13848 \end_inset
13849 </cell>
13850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13851 \begin_inset Text
13852
13853 \begin_layout Standard
13854 0x0013
13855 \end_layout
13856
13857 \end_inset
13858 </cell>
13859 </row>
13860 <row topline="true">
13861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13862 \begin_inset Text
13863
13864 \begin_layout Standard
13865 3
13866 \end_layout
13867
13868 \end_inset
13869 </cell>
13870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13871 \begin_inset Text
13872
13873 \begin_layout Standard
13874 Timer 1
13875 \end_layout
13876
13877 \end_inset
13878 </cell>
13879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13880 \begin_inset Text
13881
13882 \begin_layout Standard
13883 0x001b
13884 \end_layout
13885
13886 \end_inset
13887 </cell>
13888 </row>
13889 <row topline="true">
13890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13891 \begin_inset Text
13892
13893 \begin_layout Standard
13894 4
13895 \end_layout
13896
13897 \end_inset
13898 </cell>
13899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13900 \begin_inset Text
13901
13902 \begin_layout Standard
13903 Serial
13904 \end_layout
13905
13906 \end_inset
13907 </cell>
13908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13909 \begin_inset Text
13910
13911 \begin_layout Standard
13912 0x0023
13913 \end_layout
13914
13915 \end_inset
13916 </cell>
13917 </row>
13918 <row topline="true">
13919 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13920 \begin_inset Text
13921
13922 \begin_layout Standard
13923 5
13924 \end_layout
13925
13926 \end_inset
13927 </cell>
13928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13929 \begin_inset Text
13930
13931 \begin_layout Standard
13932 Timer 2 (8052)
13933 \end_layout
13934
13935 \end_inset
13936 </cell>
13937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13938 \begin_inset Text
13939
13940 \begin_layout Standard
13941 0x002b
13942 \end_layout
13943
13944 \end_inset
13945 </cell>
13946 </row>
13947 <row topline="true">
13948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13949 \begin_inset Text
13950
13951 \begin_layout Standard
13952 ...
13953 \end_layout
13954
13955 \end_inset
13956 </cell>
13957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13958 \begin_inset Text
13959
13960 \begin_layout Standard
13961
13962 \end_layout
13963
13964 \end_inset
13965 </cell>
13966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13967 \begin_inset Text
13968
13969 \begin_layout Standard
13970 ...
13971 \end_layout
13972
13973 \end_inset
13974 </cell>
13975 </row>
13976 <row topline="true" bottomline="true">
13977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13978 \begin_inset Text
13979
13980 \begin_layout Standard
13981 n
13982 \end_layout
13983
13984 \end_inset
13985 </cell>
13986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13987 \begin_inset Text
13988
13989 \begin_layout Standard
13990
13991 \end_layout
13992
13993 \end_inset
13994 </cell>
13995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13996 \begin_inset Text
13997
13998 \begin_layout Standard
13999 0x0003 + 8*n
14000 \end_layout
14001
14002 \end_inset
14003 </cell>
14004 </row>
14005 </lyxtabular>
14006
14007 \end_inset
14008
14009
14010 \newline
14011
14012 \end_layout
14013
14014 \begin_layout Standard
14015 If the interrupt service routine is defined without 
14016 \emph on
14017 using
14018 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14019
14020 \end_inset
14021
14022
14023 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14024
14025 \end_inset
14026
14027
14028 \emph default
14029  a register bank or with register bank 0 (
14030 \emph on
14031 using
14032 \emph default
14033  0), the compiler will save the registers used by itself on the stack upon
14034  entry and restore them at exit, however if such an interrupt service routine
14035  calls another function then the entire register bank will be saved on the
14036  stack.
14037  This scheme may be advantageous for small interrupt service routines which
14038  have low register usage.
14039 \end_layout
14040
14041 \begin_layout Standard
14042 If the interrupt service routine is defined to be using a specific register
14043  bank then only 
14044 \emph on
14045 a, b, dptr
14046 \emph default
14047  & psw are saved and restored, if such an interrupt service routine calls
14048  another function (using another register bank) then the entire register
14049  bank of the called function will be saved on the stack
14050 \begin_inset LatexCommand \index{stack}
14051
14052 \end_inset
14053
14054 .
14055  This scheme is recommended for larger interrupt service routines.
14056 \begin_inset VSpace bigskip
14057 \end_inset
14058
14059
14060 \end_layout
14061
14062 \begin_layout Subsection
14063 HC08
14064 \begin_inset LatexCommand \index{HC08}
14065
14066 \end_inset
14067
14068  Interrupt Service Routines
14069 \end_layout
14070
14071 \begin_layout Standard
14072 Since the number of interrupts
14073 \begin_inset LatexCommand \index{HC08!interrupt}
14074
14075 \end_inset
14076
14077  available is chip specific and the interrupt vector table always ends at
14078  the last byte of memory, the interrupt numbers corresponds to the interrupt
14079  vectors in reverse order of address.
14080  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14081  2 will use the interrupt vector at 0xfffa, and so on.
14082  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14083  this way; instead see section 
14084 \begin_inset LatexCommand \ref{sub:Startup-Code}
14085
14086 \end_inset
14087
14088  for details on customizing startup.
14089 \begin_inset VSpace bigskip
14090 \end_inset
14091
14092
14093 \end_layout
14094
14095 \begin_layout Subsection
14096 Z80 Interrupt Service Routines
14097 \end_layout
14098
14099 \begin_layout Standard
14100 The Z80
14101 \begin_inset LatexCommand \index{Z80}
14102
14103 \end_inset
14104
14105  uses several different methods for determining the correct interrupt
14106 \begin_inset LatexCommand \index{Z80!interrupt}
14107
14108 \end_inset
14109
14110  vector depending on the hardware implementation.
14111  Therefore, SDCC ignores the optional interrupt number and does not attempt
14112  to generate an interrupt vector table.
14113 \end_layout
14114
14115 \begin_layout Standard
14116 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14117  instruction to return from the interrupt.
14118  To write an interrupt handler for the non-maskable interrupt, which needs
14119  a RETN instruction instead, add the 
14120 \emph on
14121 critical
14122 \emph default
14123  keyword:
14124 \end_layout
14125
14126 \begin_layout Verse
14127
14128 \family typewriter
14129 void nmi_isr (void) critical interrupt
14130 \newline
14131
14132 \newline
14133 \InsetSpace ~
14134 \InsetSpace ~
14135 \InsetSpace ~
14136 \InsetSpace ~
14137 ...
14138  
14139 \newline
14140 }
14141 \end_layout
14142
14143 \begin_layout Standard
14144 However if you need to create a non-interruptable interrupt service routine
14145  you would also require the 
14146 \emph on
14147 critical
14148 \emph default
14149  keyword.
14150  To distinguish between this and an nmi_isr you must provide an interrupt
14151  number.
14152 \begin_inset VSpace bigskip
14153 \end_inset
14154
14155
14156 \end_layout
14157
14158 \begin_layout Section
14159 Enabling and Disabling Interrupts
14160 \end_layout
14161
14162 \begin_layout Subsection
14163 Critical Functions and Critical Statements
14164 \end_layout
14165
14166 \begin_layout Standard
14167 A special keyword may be associated with a block or a function declaring
14168  it as 
14169 \emph on
14170 critical
14171 \emph default
14172 .
14173  SDCC will generate code to disable all interrupts
14174 \begin_inset LatexCommand \index{interrupt}
14175
14176 \end_inset
14177
14178  upon entry to a critical function and restore the interrupt enable to the
14179  previous state before returning.
14180  Nesting critical functions will need one additional byte on the stack
14181 \begin_inset LatexCommand \index{stack}
14182
14183 \end_inset
14184
14185  for each call.
14186 \end_layout
14187
14188 \begin_layout Verse
14189
14190 \family typewriter
14191 int foo () __critical
14192 \begin_inset LatexCommand \index{critical}
14193
14194 \end_inset
14195
14196
14197 \begin_inset LatexCommand \index{\_\_critical}
14198
14199 \end_inset
14200
14201  
14202 \newline
14203
14204 \newline
14205 \InsetSpace ~
14206 \InsetSpace ~
14207 \InsetSpace ~
14208 \InsetSpace ~
14209 ...
14210  
14211 \newline
14212 \InsetSpace ~
14213 \InsetSpace ~
14214 \InsetSpace ~
14215 \InsetSpace ~
14216 ...
14217  
14218 \newline
14219 }
14220 \end_layout
14221
14222 \begin_layout Standard
14223 The critical attribute maybe used with other attributes like 
14224 \emph on
14225 reentrant.
14226 \emph default
14227
14228 \newline
14229 The keyword 
14230 \emph on
14231 critical
14232 \emph default
14233  may also be used to disable interrupts more locally:
14234 \end_layout
14235
14236 \begin_layout Verse
14237
14238 \family typewriter
14239 __critical{ i++; }
14240 \end_layout
14241
14242 \begin_layout Standard
14243 More than one statement could have been included in the block.
14244 \end_layout
14245
14246 \begin_layout Subsection
14247 Enabling and Disabling Interrupts directly
14248 \end_layout
14249
14250 \begin_layout Standard
14251 Interrupts
14252 \begin_inset LatexCommand \index{interrupt}
14253
14254 \end_inset
14255
14256  can also be disabled and enabled directly (8051):
14257 \end_layout
14258
14259 \begin_layout Verse
14260
14261 \family typewriter
14262 EA = 0;\InsetSpace ~
14263 \InsetSpace ~
14264 \InsetSpace ~
14265 \InsetSpace ~
14266 \InsetSpace ~
14267 \InsetSpace ~
14268 \InsetSpace ~
14269 \InsetSpace ~
14270 \InsetSpace ~
14271 \InsetSpace ~
14272 \InsetSpace ~
14273 \InsetSpace ~
14274 or:\InsetSpace ~
14275 \InsetSpace ~
14276 \InsetSpace ~
14277 \InsetSpace ~
14278 \InsetSpace ~
14279 \InsetSpace ~
14280 \InsetSpace ~
14281 \InsetSpace ~
14282 \InsetSpace ~
14283 \InsetSpace ~
14284 \InsetSpace ~
14285 EA_SAVE = EA;
14286 \end_layout
14287
14288 \begin_layout Verse
14289
14290 \family typewriter
14291 ...\InsetSpace ~
14292 \InsetSpace ~
14293 \InsetSpace ~
14294 \InsetSpace ~
14295 \InsetSpace ~
14296 \InsetSpace ~
14297 \InsetSpace ~
14298 \InsetSpace ~
14299 \InsetSpace ~
14300 \InsetSpace ~
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 EA = 0;
14322 \end_layout
14323
14324 \begin_layout Verse
14325
14326 \family typewriter
14327 EA = 1;\InsetSpace ~
14328 \InsetSpace ~
14329 \InsetSpace ~
14330 \InsetSpace ~
14331 \InsetSpace ~
14332 \InsetSpace ~
14333 \InsetSpace ~
14334 \InsetSpace ~
14335 \InsetSpace ~
14336 \InsetSpace ~
14337 \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 ...
14354 \end_layout
14355
14356 \begin_layout Verse
14357
14358 \family typewriter
14359 \InsetSpace ~
14360 \InsetSpace ~
14361 \InsetSpace ~
14362 \InsetSpace ~
14363 \InsetSpace ~
14364 \InsetSpace ~
14365 \InsetSpace ~
14366 \InsetSpace ~
14367 \InsetSpace ~
14368 \InsetSpace ~
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 EA = EA_SAVE;
14393 \end_layout
14394
14395 \begin_layout Standard
14396 On other architectures which have seperate opcodes for enabling and disabling
14397  interrupts you might want to make use of defines with inline assembly
14398 \begin_inset LatexCommand \index{Assembler routines}
14399
14400 \end_inset
14401
14402  (HC08
14403 \begin_inset LatexCommand \index{HC08!interrupt}
14404
14405 \end_inset
14406
14407 ):
14408 \end_layout
14409
14410 \begin_layout Verse
14411
14412 \family typewriter
14413 #define CLI _asm
14414 \begin_inset LatexCommand \index{\_asm}
14415
14416 \end_inset
14417
14418 \InsetSpace ~
14419 \InsetSpace ~
14420 cli\InsetSpace ~
14421 \InsetSpace ~
14422 _endasm
14423 \begin_inset LatexCommand \index{\_endasm}
14424
14425 \end_inset
14426
14427
14428 \end_layout
14429
14430 \begin_layout Verse
14431
14432 \family typewriter
14433 #define SEI _asm\InsetSpace ~
14434 \InsetSpace ~
14435 sei\InsetSpace ~
14436 \InsetSpace ~
14437 _endasm; 
14438 \end_layout
14439
14440 \begin_layout Verse
14441
14442 \family typewriter
14443 ...
14444 \end_layout
14445
14446 \begin_layout Standard
14447 Note: it is sometimes sufficient to disable only a specific interrupt source
14448  like f.e.
14449  a timer or serial interrupt by manipulating an 
14450 \emph on
14451 interrupt mask
14452 \begin_inset LatexCommand \index{interrupt mask}
14453
14454 \end_inset
14455
14456
14457 \emph default
14458  register.
14459  
14460 \end_layout
14461
14462 \begin_layout Standard
14463 Usually the time during which interrupts are disabled should be kept as
14464  short as possible.
14465  This minimizes both 
14466 \emph on
14467 interrupt latency
14468 \emph default
14469
14470 \begin_inset LatexCommand \index{interrupt latency}
14471
14472 \end_inset
14473
14474  (the time between the occurrence of the interrupt and the execution of
14475  the first code in the interrupt routine) and 
14476 \emph on
14477 interrupt jitter
14478 \emph default
14479
14480 \begin_inset LatexCommand \index{interrupt jitter}
14481
14482 \end_inset
14483
14484  (the difference between the shortest and the longest interrupt latency).
14485  These really are something different, f.e.
14486  a serial interrupt has to be served before its buffer overruns so it cares
14487  for the maximum interrupt latency, whereas it does not care about jitter.
14488  On a loudspeaker driven via a digital to analog converter which is fed
14489  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14490  a much smaller jitter will be very audible.
14491 \end_layout
14492
14493 \begin_layout Standard
14494 You can reenable interrupts within an interrupt routine and on some architecture
14495 s you can make use of two (or more) levels of 
14496 \emph on
14497 interrupt priorities
14498 \emph default
14499
14500 \begin_inset LatexCommand \index{interrupt priority}
14501
14502 \end_inset
14503
14504 .
14505  On some architectures which don't support interrupt priorities these can
14506  be implemented by manipulating the interrupt mask and reenabling interrupts
14507  within the interrupt routine.
14508  Check there is sufficient space on the stack
14509 \begin_inset LatexCommand \index{stack}
14510
14511 \end_inset
14512
14513  and don't add complexity unless you have to.
14514  
14515 \end_layout
14516
14517 \begin_layout Subsection
14518 Semaphore
14519 \begin_inset LatexCommand \index{semaphore}
14520
14521 \end_inset
14522
14523  locking (mcs51/ds390)
14524 \end_layout
14525
14526 \begin_layout Standard
14527 Some architectures (mcs51/ds390) have an atomic
14528 \begin_inset LatexCommand \index{atomic}
14529
14530 \end_inset
14531
14532  bit test and
14533 \emph on
14534  
14535 \emph default
14536 clear
14537 \emph on
14538  
14539 \emph default
14540 instruction.
14541  These type of instructions are typically used in preemptive multitasking
14542  systems, where a routine f.e.
14543  claims the use of a data structure ('acquires a lock
14544 \begin_inset LatexCommand \index{lock}
14545
14546 \end_inset
14547
14548  on it'), makes some modifications and then releases the lock when the data
14549  structure is consistent again.
14550  The instruction may also be used if interrupt and non-interrupt code have
14551  to compete for a resource.
14552  With the atomic bit test and clear instruction interrupts
14553 \begin_inset LatexCommand \index{interrupt}
14554
14555 \end_inset
14556
14557  don't have to be disabled for the locking operation.
14558  
14559 \end_layout
14560
14561 \begin_layout Standard
14562 SDCC generates this instruction if the source follows this pattern:
14563 \end_layout
14564
14565 \begin_layout Verse
14566
14567 \family typewriter
14568 volatile
14569 \begin_inset LatexCommand \index{volatile}
14570
14571 \end_inset
14572
14573  bit resource_is_free; 
14574 \newline
14575
14576 \newline
14577 if (resource_is_free) 
14578 \newline
14579 \InsetSpace ~
14580 \InsetSpace ~
14581
14582 \newline
14583 \InsetSpace ~
14584 \InsetSpace ~
14585 \InsetSpace ~
14586 \InsetSpace ~
14587 resource_is_free=0; 
14588 \newline
14589 \InsetSpace ~
14590 \InsetSpace ~
14591 \InsetSpace ~
14592 \InsetSpace ~
14593 ...
14594  
14595 \newline
14596 \InsetSpace ~
14597 \InsetSpace ~
14598 \InsetSpace ~
14599 \InsetSpace ~
14600 resource_is_free=1;
14601 \newline
14602 \InsetSpace ~
14603 \InsetSpace ~
14604
14605 \end_layout
14606
14607 \begin_layout Standard
14608 Note, mcs51 and ds390 support only an atomic
14609 \begin_inset LatexCommand \index{atomic}
14610
14611 \end_inset
14612
14613  bit test and 
14614 \emph on
14615 clear
14616 \emph default
14617  instruction (as opposed to atomic bit test and 
14618 \emph on
14619 set).
14620 \end_layout
14621
14622 \begin_layout Section
14623 Functions using private register banks
14624 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14625
14626 \end_inset
14627
14628  (mcs51/ds390)
14629 \end_layout
14630
14631 \begin_layout Standard
14632 Some architectures have support for quickly changing register sets.
14633  SDCC supports this feature with the 
14634 \emph on
14635 using
14636 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14637
14638 \end_inset
14639
14640
14641 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14642
14643 \end_inset
14644
14645
14646 \emph default
14647  attribute (which tells the compiler to use a register bank
14648 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14649
14650 \end_inset
14651
14652  other than the default bank zero).
14653  It should only be applied to 
14654 \emph on
14655 interrupt
14656 \begin_inset LatexCommand \index{interrupt}
14657
14658 \end_inset
14659
14660
14661 \emph default
14662  functions (see footnote below).
14663  This will in most circumstances make the generated ISR code more efficient
14664  since it will not have to save registers on the stack.
14665 \end_layout
14666
14667 \begin_layout Standard
14668 The 
14669 \emph on
14670 using
14671 \emph default
14672  attribute will have no effect on the generated code for a 
14673 \emph on
14674 non-interrupt
14675 \emph default
14676  function (but may occasionally be useful anyway
14677 \begin_inset Foot
14678 status open
14679
14680 \begin_layout Standard
14681 possible exception: if a function is called ONLY from 'interrupt' functions
14682  using a particular bank, it can be declared with the same 'using' attribute
14683  as the calling 'interrupt' functions.
14684  For instance, if you have several ISRs using bank one, and all of them
14685  call memcpy(), it might make sense to create a specialized version of memcpy()
14686  'using 1', since this would prevent the ISR from having to save bank zero
14687  to the stack on entry and switch to bank zero before calling the function
14688 \end_layout
14689
14690 \end_inset
14691
14692 ).
14693 \newline
14694
14695 \emph on
14696 (pending: Note, nowadays the 
14697 \emph default
14698 using
14699 \emph on
14700  attribute has an effect on
14701 \emph default
14702  
14703 \emph on
14704 the generated code for a 
14705 \emph default
14706 non-interrupt
14707 \emph on
14708  function
14709 \emph default
14710 .
14711 \emph on
14712 )
14713 \end_layout
14714
14715 \begin_layout Standard
14716 An 
14717 \emph on
14718 interrupt
14719 \emph default
14720  function using a non-zero bank will assume that it can trash that register
14721  bank, and will not save it.
14722  Since high-priority interrupts
14723 \begin_inset LatexCommand \index{interrupts}
14724
14725 \end_inset
14726
14727
14728 \begin_inset LatexCommand \index{interrupt priority}
14729
14730 \end_inset
14731
14732  can interrupt low-priority ones on the 8051 and friends, this means that
14733  if a high-priority ISR 
14734 \emph on
14735 using
14736 \emph default
14737  a particular bank occurs while processing a low-priority ISR 
14738 \emph on
14739 using
14740 \emph default
14741  the same bank, terrible and bad things can happen.
14742  To prevent this, no single register bank should be 
14743 \emph on
14744 used
14745 \emph default
14746  by both a high priority and a low priority ISR.
14747  This is probably most easily done by having all high priority ISRs use
14748  one bank and all low priority ISRs use another.
14749  If you have an ISR which can change priority at runtime, you're on your
14750  own: I suggest using the default bank zero and taking the small performance
14751  hit.
14752 \end_layout
14753
14754 \begin_layout Standard
14755 It is most efficient if your ISR calls no other functions.
14756  If your ISR must call other functions, it is most efficient if those functions
14757  use the same bank as the ISR (see note 1 below); the next best is if the
14758  called functions use bank zero.
14759  It is very inefficient to call a function using a different, non-zero bank
14760  from an ISR.
14761  
14762 \begin_inset VSpace bigskip
14763 \end_inset
14764
14765
14766 \end_layout
14767
14768 \begin_layout Section
14769 Startup Code
14770 \begin_inset LatexCommand \label{sub:Startup-Code}
14771
14772 \end_inset
14773
14774
14775 \begin_inset LatexCommand \index{Startup code}
14776
14777 \end_inset
14778
14779
14780 \end_layout
14781
14782 \begin_layout Subsection
14783 MCS51/DS390 Startup Code
14784 \end_layout
14785
14786 \begin_layout Standard
14787 The compiler triggers the linker to link certain initialization modules
14788  from the runtime library
14789 \begin_inset LatexCommand \index{Runtime library}
14790
14791 \end_inset
14792
14793  called crt<something>.
14794  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14795  GSINIT5) is not linked unless the --xstack option is used.
14796  These modules are highly entangled by the use of special segments/areas,
14797  but a common layout is shown below:
14798 \end_layout
14799
14800 \begin_layout Verse
14801
14802 \family typewriter
14803 \series bold
14804 \size footnotesize
14805 (main.asm)
14806 \end_layout
14807
14808 \begin_layout Verse
14809
14810 \family typewriter
14811 \size footnotesize
14812 \InsetSpace ~
14813 \InsetSpace ~
14814 \InsetSpace ~
14815 \InsetSpace ~
14816 \InsetSpace ~
14817 \InsetSpace ~
14818 \InsetSpace ~
14819 \InsetSpace ~
14820 .area HOME (CODE)
14821 \newline
14822 __interrupt_vect:
14823 \newline
14824 \InsetSpace ~
14825 \InsetSpace ~
14826 \InsetSpace ~
14827 \InsetSpace ~
14828 \InsetSpace ~
14829 \InsetSpace ~
14830 \InsetSpace ~
14831 \InsetSpace ~
14832 ljmp __sdcc_gsinit_startup
14833 \end_layout
14834
14835 \begin_layout Verse
14836
14837 \family typewriter
14838 \series bold
14839 \size footnotesize
14840 (crtstart.asm)
14841 \end_layout
14842
14843 \begin_layout Verse
14844
14845 \family typewriter
14846 \size footnotesize
14847 \InsetSpace ~
14848 \InsetSpace ~
14849 \InsetSpace ~
14850 \InsetSpace ~
14851 \InsetSpace ~
14852 \InsetSpace ~
14853 \InsetSpace ~
14854 \InsetSpace ~
14855 .area GSINIT0 (CODE)
14856 \newline
14857 __sdcc_gsinit_startup::
14858 \newline
14859 \InsetSpace ~
14860 \InsetSpace ~
14861 \InsetSpace ~
14862 \InsetSpace ~
14863 \InsetSpace ~
14864 \InsetSpace ~
14865 \InsetSpace ~
14866 \InsetSpace ~
14867 mov sp,#__start__stack - 1
14868 \end_layout
14869
14870 \begin_layout Verse
14871
14872 \family typewriter
14873 \series bold
14874 \size footnotesize
14875 (crtxstack.asm)
14876 \end_layout
14877
14878 \begin_layout Verse
14879
14880 \family typewriter
14881 \size footnotesize
14882 \InsetSpace ~
14883 \InsetSpace ~
14884 \InsetSpace ~
14885 \InsetSpace ~
14886 \InsetSpace ~
14887 \InsetSpace ~
14888 \InsetSpace ~
14889 \InsetSpace ~
14890 .area GSINIT1 (CODE)
14891 \newline
14892 __sdcc_init_xstack::
14893 \newline
14894 ; Need to initialize in GSINIT1 in
14895  case the user's __sdcc_external_startup uses the xstack.
14896 \newline
14897 \InsetSpace ~
14898 \InsetSpace ~
14899 \InsetSpace ~
14900 \InsetSpace ~
14901 \InsetSpace ~
14902 \InsetSpace ~
14903 \InsetSpace ~
14904 \InsetSpace ~
14905 mov __XPAGE,#(__start__x
14906 stack >> 8)
14907 \newline
14908 \InsetSpace ~
14909 \InsetSpace ~
14910 \InsetSpace ~
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 \InsetSpace ~
14916 mov _spx,#__start__xstack
14917 \end_layout
14918
14919 \begin_layout Verse
14920
14921 \family typewriter
14922 \series bold
14923 \size footnotesize
14924 (crtstart.asm)
14925 \end_layout
14926
14927 \begin_layout Verse
14928
14929 \family typewriter
14930 \size footnotesize
14931 \InsetSpace ~
14932 \InsetSpace ~
14933 \InsetSpace ~
14934 \InsetSpace ~
14935 \InsetSpace ~
14936 \InsetSpace ~
14937 \InsetSpace ~
14938 \InsetSpace ~
14939 .area GSINIT2 (CODE)
14940 \newline
14941 \InsetSpace ~
14942 \InsetSpace ~
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 \InsetSpace ~
14946 \InsetSpace ~
14947 \InsetSpace ~
14948 \InsetSpace ~
14949 lcall __sdcc_external_startup
14950 \newline
14951 \InsetSpace ~
14952 \InsetSpace ~
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 \InsetSpace ~
14956 \InsetSpace ~
14957 \InsetSpace ~
14958 \InsetSpace ~
14959 mov a,dpl
14960 \newline
14961 \InsetSpace ~
14962 \InsetSpace ~
14963 \InsetSpace ~
14964 \InsetSpace ~
14965 \InsetSpace ~
14966 \InsetSpace ~
14967 \InsetSpace ~
14968 \InsetSpace ~
14969 jz __sdcc_init_data
14970 \newline
14971 \InsetSpace ~
14972 \InsetSpace ~
14973 \InsetSpace ~
14974 \InsetSpace ~
14975 \InsetSpace ~
14976 \InsetSpace ~
14977 \InsetSpace ~
14978 \InsetSpace ~
14979 ljmp
14980  __sdcc_program_startup
14981 \newline
14982 __sdcc_init_data:
14983 \end_layout
14984
14985 \begin_layout Verse
14986
14987 \family typewriter
14988 \series bold
14989 \size footnotesize
14990 (crtxinit.asm)
14991 \end_layout
14992
14993 \begin_layout Verse
14994
14995 \family typewriter
14996 \size footnotesize
14997 \InsetSpace ~
14998 \InsetSpace ~
14999 \InsetSpace ~
15000 \InsetSpace ~
15001 \InsetSpace ~
15002 \InsetSpace ~
15003 \InsetSpace ~
15004 \InsetSpace ~
15005 .area GSINIT3 (CODE)
15006 \newline
15007 __mcs51_genXINIT::
15008 \newline
15009 \InsetSpace ~
15010 \InsetSpace ~
15011 \InsetSpace ~
15012 \InsetSpace ~
15013 \InsetSpace ~
15014 \InsetSpace ~
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 mov r1,#l_XINIT
15018 \newline
15019 \InsetSpace ~
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 \InsetSpace ~
15025 \InsetSpace ~
15026 \InsetSpace ~
15027 mov a,r1
15028 \newline
15029 \InsetSpace ~
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 \InsetSpace ~
15034 \InsetSpace ~
15035 \InsetSpace ~
15036 \InsetSpace ~
15037 orl a,#(l_XINIT
15038  >> 8)
15039 \newline
15040 \InsetSpace ~
15041 \InsetSpace ~
15042 \InsetSpace ~
15043 \InsetSpace ~
15044 \InsetSpace ~
15045 \InsetSpace ~
15046 \InsetSpace ~
15047 \InsetSpace ~
15048 jz 00003$
15049 \newline
15050 \InsetSpace ~
15051 \InsetSpace ~
15052 \InsetSpace ~
15053 \InsetSpace ~
15054 \InsetSpace ~
15055 \InsetSpace ~
15056 \InsetSpace ~
15057 \InsetSpace ~
15058 mov r2,#((l_XINIT+255) >> 8)
15059 \newline
15060 \InsetSpace ~
15061 \InsetSpace ~
15062 \InsetSpace ~
15063 \InsetSpace ~
15064 \InsetSpace ~
15065 \InsetSpace ~
15066 \InsetSpace ~
15067 \InsetSpace ~
15068 mov dptr,#s_XINIT
15069 \newline
15070 \InsetSpace ~
15071 \InsetSpace ~
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 mov r0,#s_XISEG
15079 \newline
15080 \InsetSpace ~
15081 \InsetSpace ~
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 mov
15089  __XPAGE,#(s_XISEG >> 8)
15090 \newline
15091 00001$:\InsetSpace ~
15092 clr a
15093 \newline
15094 \InsetSpace ~
15095 \InsetSpace ~
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 movc a,@a+dptr
15103 \newline
15104 \InsetSpace ~
15105 \InsetSpace ~
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
15109 \InsetSpace ~
15110 \InsetSpace ~
15111 \InsetSpace ~
15112 movx @r0,a
15113 \newline
15114 \InsetSpace ~
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 inc dptr
15123 \newline
15124 \InsetSpace ~
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 inc
15133  r0
15134 \newline
15135 \InsetSpace ~
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 cjne r0,#0,00002$
15144 \newline
15145 \InsetSpace ~
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 inc __XPAGE
15154 \newline
15155 00002$:\InsetSpace ~
15156 djnz r1,00001$
15157 \newline
15158 \InsetSpace ~
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 djnz r2,00001$
15167 \newline
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 mov __XPAGE,#0
15177 xFF
15178 \newline
15179 00003$:
15180 \end_layout
15181
15182 \begin_layout Verse
15183
15184 \family typewriter
15185 \series bold
15186 \size footnotesize
15187 (crtclear.asm)
15188 \end_layout
15189
15190 \begin_layout Verse
15191
15192 \family typewriter
15193 \size footnotesize
15194 \InsetSpace ~
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 \InsetSpace ~
15201 \InsetSpace ~
15202 .area GSINIT4 (CODE)
15203 \newline
15204 __mcs51_genRAMCLEAR::
15205 \newline
15206 \InsetSpace ~
15207 \InsetSpace ~
15208 \InsetSpace ~
15209 \InsetSpace ~
15210 \InsetSpace ~
15211 \InsetSpace ~
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 clr a
15215 \newline
15216 \InsetSpace ~
15217 \InsetSpace ~
15218 \InsetSpace ~
15219 \InsetSpace ~
15220 \InsetSpace ~
15221 \InsetSpace ~
15222 \InsetSpace ~
15223 \InsetSpace ~
15224 mov r0,#(l_IRAM-1)
15225 \newline
15226 00004$:\InsetSpace ~
15227 mov
15228  @r0,a
15229 \newline
15230 \InsetSpace ~
15231 \InsetSpace ~
15232 \InsetSpace ~
15233 \InsetSpace ~
15234 \InsetSpace ~
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 djnz r0,00004$
15239 \newline
15240 ; _mcs51_genRAMCLEAR() end
15241 \end_layout
15242
15243 \begin_layout Verse
15244
15245 \family typewriter
15246 \series bold
15247 \size footnotesize
15248 (crtxclear.asm)
15249 \end_layout
15250
15251 \begin_layout Verse
15252
15253 \family typewriter
15254 \size footnotesize
15255 \InsetSpace ~
15256 \InsetSpace ~
15257 \InsetSpace ~
15258 \InsetSpace ~
15259 \InsetSpace ~
15260 \InsetSpace ~
15261 \InsetSpace ~
15262 \InsetSpace ~
15263 .area GSINIT4 (CODE)
15264 \newline
15265 __mcs51_genXRAMCLEAR::
15266 \newline
15267 \InsetSpace ~
15268 \InsetSpace ~
15269 \InsetSpace ~
15270 \InsetSpace ~
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 \InsetSpace ~
15274 \InsetSpace ~
15275 mov r0,#l_PSEG
15276 \newline
15277 \InsetSpace ~
15278 \InsetSpace ~
15279 \InsetSpace ~
15280 \InsetSpace ~
15281 \InsetSpace ~
15282 \InsetSpace ~
15283 \InsetSpace ~
15284 \InsetSpace ~
15285 mov a,r0
15286 \newline
15287 \InsetSpace ~
15288 \InsetSpace ~
15289 \InsetSpace ~
15290 \InsetSpace ~
15291 \InsetSpace ~
15292 \InsetSpace ~
15293 \InsetSpace ~
15294 \InsetSpace ~
15295 jz 00006$
15296 \newline
15297 \InsetSpace ~
15298 \InsetSpace ~
15299 \InsetSpace ~
15300 \InsetSpace ~
15301 \InsetSpace ~
15302 \InsetSpace ~
15303 \InsetSpace ~
15304 \InsetSpace ~
15305 mov
15306  r1,#s_PSEG
15307 \newline
15308 \InsetSpace ~
15309 \InsetSpace ~
15310 \InsetSpace ~
15311 \InsetSpace ~
15312 \InsetSpace ~
15313 \InsetSpace ~
15314 \InsetSpace ~
15315 \InsetSpace ~
15316 mov __XPAGE,#(s_PSEG >> 8)
15317 \newline
15318 \InsetSpace ~
15319 \InsetSpace ~
15320 \InsetSpace ~
15321 \InsetSpace ~
15322 \InsetSpace ~
15323 \InsetSpace ~
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 clr a
15327 \newline
15328 00005$:\InsetSpace ~
15329 movx @r1,a
15330 \newline
15331 \InsetSpace ~
15332 \InsetSpace ~
15333 \InsetSpace ~
15334 \InsetSpace ~
15335 \InsetSpace ~
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 inc r1
15340 \newline
15341 \InsetSpace ~
15342 \InsetSpace ~
15343 \InsetSpace ~
15344 \InsetSpace ~
15345 \InsetSpace ~
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 djnz r0,00005$
15350 \newline
15351 0
15352 0006$:
15353 \newline
15354 \InsetSpace ~
15355 \InsetSpace ~
15356 \InsetSpace ~
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 \InsetSpace ~
15360 \InsetSpace ~
15361 \InsetSpace ~
15362 mov r0,#l_XSEG
15363 \newline
15364 \InsetSpace ~
15365 \InsetSpace ~
15366 \InsetSpace ~
15367 \InsetSpace ~
15368 \InsetSpace ~
15369 \InsetSpace ~
15370 \InsetSpace ~
15371 \InsetSpace ~
15372 mov a,r0
15373 \newline
15374 \InsetSpace ~
15375 \InsetSpace ~
15376 \InsetSpace ~
15377 \InsetSpace ~
15378 \InsetSpace ~
15379 \InsetSpace ~
15380 \InsetSpace ~
15381 \InsetSpace ~
15382 orl a,#(l_XSEG >> 8)
15383 \newline
15384 \InsetSpace ~
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 \InsetSpace ~
15389 \InsetSpace ~
15390 \InsetSpace ~
15391 \InsetSpace ~
15392 jz 00008$
15393 \newline
15394 \InsetSpace ~
15395 \InsetSpace ~
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 \InsetSpace ~
15402 mov r1,#((l_XSEG
15403  + 255) >> 8)
15404 \newline
15405 \InsetSpace ~
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 \InsetSpace ~
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 \InsetSpace ~
15412 \InsetSpace ~
15413 mov dptr,#s_XSEG
15414 \newline
15415 \InsetSpace ~
15416 \InsetSpace ~
15417 \InsetSpace ~
15418 \InsetSpace ~
15419 \InsetSpace ~
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 clr a
15424 \newline
15425 00007$:\InsetSpace ~
15426 movx @dptr,a
15427 \newline
15428 \InsetSpace ~
15429 \InsetSpace ~
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 \InsetSpace ~
15434 \InsetSpace ~
15435 \InsetSpace ~
15436 inc dptr
15437 \newline
15438 \InsetSpace ~
15439 \InsetSpace ~
15440 \InsetSpace ~
15441 \InsetSpace ~
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 \InsetSpace ~
15445 \InsetSpace ~
15446 djnz r0,00007$
15447 \newline
15448 \InsetSpace ~
15449 \InsetSpace ~
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 \InsetSpace ~
15454 \InsetSpace ~
15455 \InsetSpace ~
15456 djnz
15457  r1,00007$
15458 \newline
15459 00008$:
15460 \end_layout
15461
15462 \begin_layout Verse
15463
15464 \family typewriter
15465 \series bold
15466 \size footnotesize
15467 (crtxstack.asm)
15468 \end_layout
15469
15470 \begin_layout Verse
15471
15472 \family typewriter
15473 \size footnotesize
15474 \InsetSpace ~
15475 \InsetSpace ~
15476 \InsetSpace ~
15477 \InsetSpace ~
15478 \InsetSpace ~
15479 \InsetSpace ~
15480 \InsetSpace ~
15481 \InsetSpace ~
15482 .area GSINIT5 (CODE)
15483 \newline
15484 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15485  modifies __XPAGE
15486 \newline
15487 ; and __mcs51_genRAMCLEAR modifies _spx.
15488 \newline
15489 \InsetSpace ~
15490 \InsetSpace ~
15491 \InsetSpace ~
15492 \InsetSpace ~
15493 \InsetSpace ~
15494 \InsetSpace ~
15495 \InsetSpace ~
15496 \InsetSpace ~
15497 mov __XPAGE,#(__start__x
15498 stack >> 8)
15499 \newline
15500 \InsetSpace ~
15501 \InsetSpace ~
15502 \InsetSpace ~
15503 \InsetSpace ~
15504 \InsetSpace ~
15505 \InsetSpace ~
15506 \InsetSpace ~
15507 \InsetSpace ~
15508 mov _spx,#__start__xstack
15509 \end_layout
15510
15511 \begin_layout Verse
15512
15513 \family typewriter
15514 \series bold
15515 \size footnotesize
15516 (application modules)
15517 \end_layout
15518
15519 \begin_layout Verse
15520
15521 \family typewriter
15522 \size footnotesize
15523 \InsetSpace ~
15524 \InsetSpace ~
15525 \InsetSpace ~
15526 \InsetSpace ~
15527 \InsetSpace ~
15528 \InsetSpace ~
15529 \InsetSpace ~
15530 \InsetSpace ~
15531 .area GSINIT (CODE)
15532 \end_layout
15533
15534 \begin_layout Verse
15535
15536 \family typewriter
15537 \series bold
15538 \size footnotesize
15539 (main.asm)
15540 \end_layout
15541
15542 \begin_layout Verse
15543
15544 \family typewriter
15545 \size footnotesize
15546 \InsetSpace ~
15547 \InsetSpace ~
15548 \InsetSpace ~
15549 \InsetSpace ~
15550 \InsetSpace ~
15551 \InsetSpace ~
15552 \InsetSpace ~
15553 \InsetSpace ~
15554 .area GSFINAL (CODE)
15555 \newline
15556 \InsetSpace ~
15557 \InsetSpace ~
15558 \InsetSpace ~
15559 \InsetSpace ~
15560 \InsetSpace ~
15561 \InsetSpace ~
15562 \InsetSpace ~
15563 \InsetSpace ~
15564 ljmp __sdcc_program_startup
15565 \newline
15566 ;---------------------------------
15567 -----------------------
15568 \newline
15569 ; Home
15570 \newline
15571 ;--------------------------------------------------
15572 ------
15573 \newline
15574 \InsetSpace ~
15575 \InsetSpace ~
15576 \InsetSpace ~
15577 \InsetSpace ~
15578 \InsetSpace ~
15579 \InsetSpace ~
15580 \InsetSpace ~
15581 \InsetSpace ~
15582 .area HOME (CODE)
15583 \newline
15584 \InsetSpace ~
15585 \InsetSpace ~
15586 \InsetSpace ~
15587 \InsetSpace ~
15588 \InsetSpace ~
15589 \InsetSpace ~
15590 \InsetSpace ~
15591 \InsetSpace ~
15592 .area CSEG (CODE)
15593 \newline
15594 __sdcc_program_startup:
15595 \newline
15596 \InsetSpace ~
15597 \InsetSpace ~
15598 \InsetSpace ~
15599 \InsetSpace ~
15600 \InsetSpace ~
15601 \InsetSpace ~
15602 \InsetSpace ~
15603 \InsetSpace ~
15604 lcall _main
15605 \newline
15606 ;
15607  return from main will lock up
15608 \newline
15609 \InsetSpace ~
15610 \InsetSpace ~
15611 \InsetSpace ~
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 sjmp .
15618 \end_layout
15619
15620 \begin_layout Standard
15621 One of these modules (crtstart.asm) contains a call to the C routine 
15622 \emph on
15623 _sdcc_external_startup()
15624 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15625
15626 \end_inset
15627
15628
15629 \series bold
15630 \emph default
15631  
15632 \series default
15633 at the start of the CODE area.
15634  This routine is also in the runtime library
15635 \begin_inset LatexCommand \index{Runtime library}
15636
15637 \end_inset
15638
15639  and returns 0 by default.
15640  If this routine returns a non-zero value, the static & global variable
15641  initialization will be skipped and the function main will be invoked.
15642  Otherwise static & global variables will be initialized before the function
15643  main is invoked.
15644  You could add an 
15645 \emph on
15646 _sdcc_external_startup()
15647 \emph default
15648  routine to your program to override the default if you need to setup hardware
15649  or perform some other critical operation prior to static & global variable
15650  initialization
15651 \begin_inset LatexCommand \index{Variable initialization}
15652
15653 \end_inset
15654
15655 .
15656  On some mcs51 variants xdata
15657 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15658
15659 \end_inset
15660
15661  memory has to be explicitly enabled before it can be accessed or if the
15662  watchdog
15663 \begin_inset LatexCommand \index{watchdog}
15664
15665 \end_inset
15666
15667  needs to be disabled, this is the place to do it.
15668  The startup code clears all internal data memory, 256 bytes by default,
15669  but from 0 to n-1 if 
15670 \emph on
15671 -
15672 \begin_inset ERT
15673 status collapsed
15674
15675 \begin_layout Standard
15676
15677
15678 \backslash
15679 /
15680 \end_layout
15681
15682 \end_inset
15683
15684 -iram-size
15685 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15686
15687 \end_inset
15688
15689 n
15690 \emph default
15691  is used.
15692  (recommended for Chipcon CC1010).
15693 \end_layout
15694
15695 \begin_layout Standard
15696 See also the compiler options 
15697 \emph on
15698 -
15699 \begin_inset ERT
15700 status collapsed
15701
15702 \begin_layout Standard
15703
15704
15705 \backslash
15706 /
15707 \end_layout
15708
15709 \end_inset
15710
15711 -no-xinit
15712 \emph default
15713 -
15714 \emph on
15715 opt
15716 \emph default
15717
15718 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15719
15720 \end_inset
15721
15722
15723 \emph on
15724 -
15725 \begin_inset ERT
15726 status collapsed
15727
15728 \begin_layout Standard
15729
15730
15731 \backslash
15732 /
15733 \end_layout
15734
15735 \end_inset
15736
15737 -main-return
15738 \emph default
15739
15740 \begin_inset LatexCommand \index{-\/-main-return}
15741
15742 \end_inset
15743
15744  and section 
15745 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15746
15747 \end_inset
15748
15749  about MCS51-variants.
15750 \begin_inset VSpace bigskip
15751 \end_inset
15752
15753
15754 \end_layout
15755
15756 \begin_layout Subsection
15757 HC08 Startup Code
15758 \end_layout
15759
15760 \begin_layout Standard
15761 The HC08
15762 \begin_inset LatexCommand \index{HC08}
15763
15764 \end_inset
15765
15766  startup code follows the same scheme as the MCS51 startup code.
15767 \begin_inset VSpace bigskip
15768 \end_inset
15769
15770
15771 \end_layout
15772
15773 \begin_layout Subsection
15774 Z80 Startup Code
15775 \end_layout
15776
15777 \begin_layout Standard
15778 On the Z80
15779 \begin_inset LatexCommand \index{Z80}
15780
15781 \end_inset
15782
15783  the startup code is inserted by linking with crt0.o which is generated from
15784  sdcc/device/lib/z80/crt0.s.
15785  If you need a different startup code you can use the compiler option 
15786 \emph on
15787 -
15788 \series bold
15789 \emph default
15790
15791 \begin_inset ERT
15792 status collapsed
15793
15794 \begin_layout Standard
15795
15796
15797 \backslash
15798 /
15799 \end_layout
15800
15801 \end_inset
15802
15803
15804 \series default
15805 \emph on
15806 -no-std-crt0
15807 \emph default
15808
15809 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15810
15811 \end_inset
15812
15813  and provide your own crt0.o.
15814  
15815 \begin_inset VSpace bigskip
15816 \end_inset
15817
15818
15819 \end_layout
15820
15821 \begin_layout Section
15822 Inline Assembler Code
15823 \begin_inset LatexCommand \index{Assembler routines}
15824
15825 \end_inset
15826
15827
15828 \end_layout
15829
15830 \begin_layout Subsection
15831 A Step by Step Introduction
15832 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15833
15834 \end_inset
15835
15836
15837 \end_layout
15838
15839 \begin_layout Standard
15840 Starting from a small snippet of c-code this example shows for the MCS51
15841  how to use inline assembly, access variables, a function parameter and
15842  an array in xdata memory.
15843  The example uses an MCS51 here but is easily adapted for other architectures.
15844  This is a buffer routine which should be optimized:
15845 \end_layout
15846
15847 \begin_layout Verse
15848
15849 \family typewriter
15850 \size footnotesize
15851 unsigned char __far
15852 \begin_inset LatexCommand \index{far (storage class)}
15853
15854 \end_inset
15855
15856
15857 \begin_inset LatexCommand \index{\_\_far (storage class)}
15858
15859 \end_inset
15860
15861  __at
15862 \begin_inset LatexCommand \index{at}
15863
15864 \end_inset
15865
15866
15867 \begin_inset LatexCommand \index{\_\_at}
15868
15869 \end_inset
15870
15871 (0x7f00) buf[0x100];
15872 \begin_inset LatexCommand \index{Aligned array}
15873
15874 \end_inset
15875
15876
15877 \newline
15878 unsigned char head, tail;\InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 /* if interrupts
15896 \begin_inset LatexCommand \index{interrupt}
15897
15898 \end_inset
15899
15900  are involved see
15901 \newline
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
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 section 
15948 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15949
15950 \end_inset
15951
15952  about
15953 \series bold
15954  volatile
15955 \series default
15956  */
15957 \newline
15958
15959 \newline
15960 void to_buffer( unsigned char c ) 
15961 \newline
15962 {
15963 \newline
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 if( head != (unsigned char)(tail-1)
15969  )\InsetSpace ~
15970 /* cast 
15971 \series bold
15972 needed
15973 \series default
15974  to avoid promotion
15975 \begin_inset LatexCommand \index{promotion to signed int}
15976
15977 \end_inset
15978
15979
15980 \begin_inset LatexCommand \index{type promotion}
15981
15982 \end_inset
15983
15984  to integer */
15985 \begin_inset Marginal
15986 status collapsed
15987
15988 \begin_layout Standard
15989
15990 \series bold
15991 \InsetSpace ~
15992 !
15993 \end_layout
15994
15995 \end_inset
15996
15997
15998 \newline
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 buf[ head++ ] = c;\InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 \InsetSpace ~
16014 \InsetSpace ~
16015 \InsetSpace ~
16016 \InsetSpace ~
16017 \InsetSpace ~
16018 \InsetSpace ~
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 /* access to a 256 byte aligned array */
16024 \newline
16025
16026 \end_layout
16027
16028 \begin_layout Standard
16029 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16030  then a corresponding buffer.asm file is generated.
16031  We define a new function 
16032 \family typewriter
16033 to_buffer_asm()
16034 \family default
16035  in file buffer.c in which we cut and paste the generated code, removing
16036  unwanted comments and some ':'.
16037  Then add 
16038 \begin_inset Quotes sld
16039 \end_inset
16040
16041
16042 \series bold
16043 _asm
16044 \series default
16045
16046 \begin_inset Quotes srd
16047 \end_inset
16048
16049  and 
16050 \begin_inset Quotes sld
16051 \end_inset
16052
16053
16054 \series bold
16055 _endasm;
16056 \series default
16057
16058 \begin_inset Quotes srd
16059 \end_inset
16060
16061
16062 \begin_inset Foot
16063 status open
16064
16065 \begin_layout Standard
16066 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16067  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16068  has to be used.
16069  The latter is also used in the library functions.
16070 \end_layout
16071
16072 \end_inset
16073
16074  to the beginning and the end of the function body:
16075 \end_layout
16076
16077 \begin_layout Verse
16078
16079 \family typewriter
16080 \size footnotesize
16081 /* With a cut and paste from the .asm file, we have something to start with.
16082 \newline
16083 \InsetSpace ~
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 The
16087  function is not yet OK! (registers aren't saved) */ 
16088 \newline
16089 void to_buffer_asm(
16090  unsigned char c ) 
16091 \newline
16092
16093 \newline
16094 \InsetSpace ~
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 _asm
16099 \begin_inset LatexCommand \index{\_asm}
16100
16101 \end_inset
16102
16103
16104 \begin_inset LatexCommand \index{\_\_asm}
16105
16106 \end_inset
16107
16108
16109 \newline
16110 \InsetSpace ~
16111 \InsetSpace ~
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 mov\InsetSpace ~
16115 \InsetSpace ~
16116 r2,dpl 
16117 \newline
16118 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16119 /* cast 
16120 \series bold
16121 needed
16122 \series default
16123  to avoid promotion
16124 \begin_inset LatexCommand \index{promotion to signed int}
16125
16126 \end_inset
16127
16128
16129 \begin_inset LatexCommand \index{type promotion}
16130
16131 \end_inset
16132
16133  to integer */
16134 \newline
16135 \InsetSpace ~
16136 \InsetSpace ~
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 mov\InsetSpace ~
16140 \InsetSpace ~
16141 a,_tail 
16142 \newline
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 dec\InsetSpace ~
16148 \InsetSpace ~
16149
16150 \newline
16151 \InsetSpace ~
16152 \InsetSpace ~
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 mov\InsetSpace ~
16156 \InsetSpace ~
16157 r3,a 
16158 \newline
16159 \InsetSpace ~
16160 \InsetSpace ~
16161 \InsetSpace ~
16162 \InsetSpace ~
16163 mov\InsetSpace ~
16164 \InsetSpace ~
16165 a,_head 
16166 \newline
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 cjne a,ar3,00106$ 
16172 \newline
16173 \InsetSpace ~
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 ret
16178 \newline
16179 00106$:
16180  
16181 \newline
16182 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16183 \begin_inset LatexCommand \index{Aligned array}
16184
16185 \end_inset
16186
16187
16188 \newline
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 mov\InsetSpace ~
16194 \InsetSpace ~
16195 r3,_head 
16196 \newline
16197 \InsetSpace ~
16198 \InsetSpace ~
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 inc\InsetSpace ~
16202 \InsetSpace ~
16203 _head 
16204 \newline
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 \InsetSpace ~
16208 \InsetSpace ~
16209 mov\InsetSpace ~
16210 \InsetSpace ~
16211 dpl,r3 
16212 \newline
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 mov\InsetSpace ~
16218 \InsetSpace ~
16219 dph,#(_buf >> 8) 
16220 \newline
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 mov\InsetSpace ~
16226 \InsetSpace ~
16227 a,r2 
16228 \newline
16229 \InsetSpace ~
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 movx @dptr,a
16234  
16235 \newline
16236 00103$: 
16237 \newline
16238 \InsetSpace ~
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 ret
16243 \newline
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 _endasm
16249 \begin_inset LatexCommand \index{\_endasm}
16250
16251 \end_inset
16252
16253
16254 \begin_inset LatexCommand \index{\_\_endasm}
16255
16256 \end_inset
16257
16258 ;
16259 \newline
16260
16261 \end_layout
16262
16263 \begin_layout Standard
16264 The new file buffer.c should compile with only one warning about the unreferenced
16265  function argument 'c'.
16266  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16267  (1) and finally have:
16268 \end_layout
16269
16270 \begin_layout Verse
16271
16272 \family typewriter
16273 \size footnotesize
16274 unsigned char __far __at(0x7f00) buf[0x100];
16275 \newline
16276 unsigned char head, tail;
16277 \newline
16278 #define
16279  USE_ASSEMBLY (1)
16280 \newline
16281
16282 \newline
16283 #if !USE_ASSEMBLY
16284 \newline
16285
16286 \newline
16287 void to_buffer( unsigned char c )
16288 \newline
16289 {
16290 \newline
16291 \InsetSpace ~
16292 \InsetSpace ~
16293 \InsetSpace ~
16294 \InsetSpace ~
16295 if(
16296  head != (unsigned char)(tail-1) )
16297 \newline
16298 \InsetSpace ~
16299 \InsetSpace ~
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 \InsetSpace ~
16303 \InsetSpace ~
16304 \InsetSpace ~
16305 \InsetSpace ~
16306 buf[ head++ ] = c;
16307 \newline
16308 }
16309 \newline
16310
16311 \newline
16312 #else
16313 \newline
16314
16315 \newline
16316 void to_buffer(
16317  unsigned char c )
16318 \newline
16319 {
16320 \newline
16321 \InsetSpace ~
16322 \InsetSpace ~
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 c; // to avoid warning: unreferenced function argument
16326 \newline
16327 \InsetSpace ~
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 _asm
16332 \begin_inset LatexCommand \index{\_asm}
16333
16334 \end_inset
16335
16336
16337 \begin_inset LatexCommand \index{\_\_asm}
16338
16339 \end_inset
16340
16341
16342 \newline
16343 \InsetSpace ~
16344 \InsetSpace ~
16345 \InsetSpace ~
16346 \InsetSpace ~
16347 \InsetSpace ~
16348 \InsetSpace ~
16349 \InsetSpace ~
16350 \InsetSpace ~
16351 ; save used registers here.
16352  
16353 \newline
16354 \InsetSpace ~
16355 \InsetSpace ~
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 \InsetSpace ~
16362 ; If we were still using r2,r3 we would have to push them here.
16363  
16364 \newline
16365 ; if( head != (unsigned char)(tail-1) )
16366 \newline
16367 \InsetSpace ~
16368 \InsetSpace ~
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 \InsetSpace ~
16372 \InsetSpace ~
16373 \InsetSpace ~
16374 \InsetSpace ~
16375 mov\InsetSpace ~
16376  a,_tail
16377 \newline
16378 \InsetSpace ~
16379 \InsetSpace ~
16380 \InsetSpace ~
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 \InsetSpace ~
16386 dec\InsetSpace ~
16387  a
16388 \newline
16389 \InsetSpace ~
16390 \InsetSpace ~
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 xrl\InsetSpace ~
16398  a,_head
16399 \newline
16400 \InsetSpace ~
16401 \InsetSpace ~
16402 \InsetSpace ~
16403 \InsetSpace ~
16404 \InsetSpace ~
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 \InsetSpace ~
16408 ; we
16409  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16410 \newline
16411 \InsetSpace ~
16412 \InsetSpace ~
16413 \InsetSpace ~
16414 \InsetSpace ~
16415 \InsetSpace ~
16416 \InsetSpace ~
16417 \InsetSpace ~
16418 \InsetSpace ~
16419 jz\InsetSpace ~
16420 \InsetSpace ~
16421  t_b_end$
16422 \newline
16423 \InsetSpace ~
16424 \InsetSpace ~
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 \InsetSpace ~
16428 \InsetSpace ~
16429 \InsetSpace ~
16430 \InsetSpace ~
16431 ;
16432 \newline
16433 ;
16434  buf[ head++ ] = c;
16435 \newline
16436 \InsetSpace ~
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 \InsetSpace ~
16440 \InsetSpace ~
16441 \InsetSpace ~
16442 \InsetSpace ~
16443 \InsetSpace ~
16444 mov\InsetSpace ~
16445  a,dpl \InsetSpace ~
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 ; dpl holds lower byte of function argument
16453 \newline
16454 \InsetSpace ~
16455 \InsetSpace ~
16456 \InsetSpace ~
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 mov\InsetSpace ~
16463
16464  dpl,_head \InsetSpace ~
16465 \InsetSpace ~
16466 \InsetSpace ~
16467 ; buf is 0x100 byte aligned so head can be used directly
16468 \newline
16469 \InsetSpace ~
16470 \InsetSpace ~
16471 \InsetSpace ~
16472 \InsetSpace ~
16473 \InsetSpace ~
16474 \InsetSpace ~
16475 \InsetSpace ~
16476 \InsetSpace ~
16477 mov\InsetSpace ~
16478  dph,#(_bu
16479 f>>8)
16480 \newline
16481 \InsetSpace ~
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 \InsetSpace ~
16486 \InsetSpace ~
16487 \InsetSpace ~
16488 \InsetSpace ~
16489 movx @dptr,a
16490 \newline
16491 \InsetSpace ~
16492 \InsetSpace ~
16493 \InsetSpace ~
16494 \InsetSpace ~
16495 \InsetSpace ~
16496 \InsetSpace ~
16497 \InsetSpace ~
16498 \InsetSpace ~
16499 inc \InsetSpace ~
16500 _head
16501 \newline
16502 \InsetSpace ~
16503 \InsetSpace ~
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 \InsetSpace ~
16509 \InsetSpace ~
16510 ; we could do an ANL _head,#0x0f here to use a
16511  smaller buffer (see above)
16512 \newline
16513 t_b_end$:
16514 \newline
16515 \InsetSpace ~
16516 \InsetSpace ~
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 ; restore used registers here 
16524 \newline
16525 \InsetSpace ~
16526 \InsetSpace ~
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 _endasm
16530 \begin_inset LatexCommand \index{\_endasm}
16531
16532 \end_inset
16533
16534
16535 \begin_inset LatexCommand \index{\_\_endasm}
16536
16537 \end_inset
16538
16539 ;
16540 \newline
16541 }
16542 \newline
16543 #endif
16544 \end_layout
16545
16546 \begin_layout Standard
16547 The inline assembler code can contain any valid code understood by the assembler
16548 , this includes any assembler directives and comment lines.
16549  The assembler does not like some characters like ':' or ''' in comments.
16550  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16551 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16552
16553 \end_inset
16554
16555
16556 \begin_inset LatexCommand \index{Assembler documentation}
16557
16558 \end_inset
16559
16560  or online at 
16561 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16562
16563 \end_inset
16564
16565 \InsetSpace ~
16566 .
16567 \end_layout
16568
16569 \begin_layout Standard
16570 The compiler does not do any validation of the code within the 
16571 \family typewriter
16572 _asm
16573 \begin_inset LatexCommand \index{\_asm}
16574
16575 \end_inset
16576
16577
16578 \begin_inset LatexCommand \index{\_\_asm}
16579
16580 \end_inset
16581
16582  ...
16583  _endasm
16584 \size footnotesize
16585
16586 \begin_inset LatexCommand \index{\_endasm}
16587
16588 \end_inset
16589
16590
16591 \begin_inset LatexCommand \index{\_\_endasm}
16592
16593 \end_inset
16594
16595
16596 \size default
16597 ;
16598 \family default
16599  keyword pair.
16600  Specifically it will not know which registers are used and thus register
16601  pushing/popping
16602 \begin_inset LatexCommand \index{push/pop}
16603
16604 \end_inset
16605
16606  has to be done manually.
16607  
16608 \end_layout
16609
16610 \begin_layout Standard
16611 It is recommended that each assembly instruction (including labels) be placed
16612  in a separate line (as the example shows).
16613  When the -
16614 \begin_inset ERT
16615 status collapsed
16616
16617 \begin_layout Standard
16618
16619
16620 \backslash
16621 /
16622 \end_layout
16623
16624 \end_inset
16625
16626 -
16627 \emph on
16628 peep-asm
16629 \begin_inset LatexCommand \index{-\/-peep-asm}
16630
16631 \end_inset
16632
16633
16634 \emph default
16635  command line option is used, the inline assembler code will be passed through
16636  the peephole optimizer
16637 \begin_inset LatexCommand \index{Peephole optimizer}
16638
16639 \end_inset
16640
16641 .
16642  There are only a few (if any) cases where this option makes sense, it might
16643  cause some unexpected changes in the inline assembler code.
16644  Please go through the peephole optimizer rules defined in file 
16645 \emph on
16646 SDCCpeeph.def
16647 \emph default
16648  before using this option.
16649 \end_layout
16650
16651 \begin_layout Subsection
16652 Naked Functions
16653 \begin_inset LatexCommand \label{sub:Naked-Functions}
16654
16655 \end_inset
16656
16657
16658 \begin_inset LatexCommand \index{Naked functions}
16659
16660 \end_inset
16661
16662
16663 \end_layout
16664
16665 \begin_layout Standard
16666 A special keyword may be associated with a function declaring it as 
16667 \emph on
16668 _naked
16669 \begin_inset LatexCommand \index{\_naked}
16670
16671 \end_inset
16672
16673
16674 \begin_inset LatexCommand \index{\_\_naked}
16675
16676 \end_inset
16677
16678 .
16679  
16680 \emph default
16681 The 
16682 \emph on
16683 _naked
16684 \emph default
16685  function modifier attribute prevents the compiler from generating prologue
16686 \begin_inset LatexCommand \index{function prologue}
16687
16688 \end_inset
16689
16690  and epilogue
16691 \begin_inset LatexCommand \index{function epilogue}
16692
16693 \end_inset
16694
16695  code for that function.
16696  This means that the user is entirely responsible for such things as saving
16697  any registers that may need to be preserved, selecting the proper register
16698  bank, generating the 
16699 \emph on
16700 return
16701 \emph default
16702  instruction at the end, etc.
16703  Practically, this means that the contents of the function must be written
16704  in inline assembler.
16705  This is particularly useful for interrupt functions, which can have a large
16706  (and often unnecessary) prologue/epilogue.
16707  For example, compare the code generated by these two functions:
16708 \end_layout
16709
16710 \begin_layout Verse
16711
16712 \family typewriter
16713 volatile
16714 \begin_inset LatexCommand \index{volatile}
16715
16716 \end_inset
16717
16718  data unsigned char counter;
16719 \newline
16720
16721 \newline
16722 void simpleInterrupt(void) __interrupt
16723 \begin_inset LatexCommand \index{interrupt}
16724
16725 \end_inset
16726
16727
16728 \begin_inset LatexCommand \index{\_\_interrupt}
16729
16730 \end_inset
16731
16732  (1)
16733 \newline
16734 {
16735 \newline
16736 \InsetSpace ~
16737 \InsetSpace ~
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 counter++;
16741 \newline
16742 }
16743 \newline
16744
16745 \newline
16746 void nakedInterrupt(void) __interrupt (2) __naked
16747 \newline
16748 {
16749 \newline
16750 \InsetSpace ~
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 _asm
16755 \begin_inset LatexCommand \index{\_asm}
16756
16757 \end_inset
16758
16759
16760 \begin_inset LatexCommand \index{\_\_asm}
16761
16762 \end_inset
16763
16764
16765 \newline
16766 \InsetSpace ~
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 inc\InsetSpace ~
16773 \InsetSpace ~
16774 \InsetSpace ~
16775 \InsetSpace ~
16776 \InsetSpace ~
16777 _counter ; does not change flags, no need to save psw
16778 \newline
16779 \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 reti\InsetSpace ~
16786 \InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 ; MUST explicitly
16790  include ret or reti in _naked function.
16791 \newline
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 _endasm
16797 \begin_inset LatexCommand \index{\_endasm}
16798
16799 \end_inset
16800
16801
16802 \begin_inset LatexCommand \index{\_\_endasm}
16803
16804 \end_inset
16805
16806 ;
16807 \newline
16808 }
16809 \end_layout
16810
16811 \begin_layout Standard
16812 For an 8051 target, the generated simpleInterrupt looks like:
16813 \end_layout
16814
16815 \begin_layout Verse
16816
16817 \family typewriter
16818 Note, this is an 
16819 \emph on
16820 outdated
16821 \emph default
16822  example, recent versions of SDCC generate
16823 \newline
16824 the 
16825 \emph on
16826 same
16827 \emph default
16828  code for simpleInterrupt() and nakedInterrupt()!
16829 \newline
16830
16831 \newline
16832 _simpleInterrupt:
16833 \newline
16834 \InsetSpace ~
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 push\InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 acc
16843 \newline
16844 \InsetSpace ~
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 push\InsetSpace ~
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 b
16853 \newline
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 pu
16859 sh\InsetSpace ~
16860 \InsetSpace ~
16861 \InsetSpace ~
16862 \InsetSpace ~
16863 dpl
16864 \newline
16865 \InsetSpace ~
16866 \InsetSpace ~
16867 \InsetSpace ~
16868 \InsetSpace ~
16869 push\InsetSpace ~
16870 \InsetSpace ~
16871 \InsetSpace ~
16872 \InsetSpace ~
16873 dph
16874 \newline
16875 \InsetSpace ~
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 push\InsetSpace ~
16880 \InsetSpace ~
16881 \InsetSpace ~
16882 \InsetSpace ~
16883 psw
16884 \newline
16885 \InsetSpace ~
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 mov\InsetSpace ~
16890 \InsetSpace ~
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 \InsetSpace ~
16894 psw,#0x00
16895 \newline
16896 \InsetSpace ~
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 \InsetSpace ~
16900 inc\InsetSpace ~
16901 \InsetSpace ~
16902 \InsetSpace ~
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 _counter
16906 \newline
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 pop\InsetSpace ~
16912 \InsetSpace ~
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 psw
16917 \newline
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 pop\InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 \InsetSpace ~
16926 \InsetSpace ~
16927 dph
16928 \newline
16929 \InsetSpace ~
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 pop\InsetSpace ~
16934 \InsetSpace ~
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 \InsetSpace ~
16938 dpl
16939 \newline
16940 \InsetSpace ~
16941 \InsetSpace ~
16942 \InsetSpace ~
16943 \InsetSpace ~
16944 pop\InsetSpace ~
16945 \InsetSpace ~
16946 \InsetSpace ~
16947 \InsetSpace ~
16948 \InsetSpace ~
16949 b
16950 \newline
16951 \InsetSpace ~
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 pop\InsetSpace ~
16956 \InsetSpace ~
16957 \InsetSpace ~
16958 \InsetSpace ~
16959 \InsetSpace ~
16960 acc
16961 \newline
16962 \InsetSpace ~
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 reti
16967 \end_layout
16968
16969 \begin_layout Standard
16970 whereas nakedInterrupt looks like:
16971 \end_layout
16972
16973 \begin_layout Verse
16974
16975 \family typewriter
16976 _nakedInterrupt:
16977 \newline
16978 \InsetSpace ~
16979 \InsetSpace ~
16980 \InsetSpace ~
16981 \InsetSpace ~
16982 inc\InsetSpace ~
16983 \InsetSpace ~
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 _counter ; does not change flags, no need to save psw
16987 \newline
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 \InsetSpace ~
16992 reti\InsetSpace ~
16993 \InsetSpace ~
16994 \InsetSpace ~
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 \InsetSpace ~
17003 \InsetSpace ~
17004 ;
17005  MUST explicitly include ret or reti in _naked function
17006 \end_layout
17007
17008 \begin_layout Standard
17009 The related directive #pragma exclude
17010 \begin_inset LatexCommand \index{\#pragma exclude}
17011
17012 \end_inset
17013
17014  allows a more fine grained control over pushing & popping
17015 \begin_inset LatexCommand \index{push/pop}
17016
17017 \end_inset
17018
17019  the registers.
17020 \end_layout
17021
17022 \begin_layout Standard
17023 While there is nothing preventing you from writing C code inside a 
17024 \family typewriter
17025 _naked
17026 \family default
17027  function, there are many ways to shoot yourself in the foot doing this,
17028  and it is recommended that you stick to inline assembler.
17029 \end_layout
17030
17031 \begin_layout Subsection
17032 Use of Labels within Inline Assembler
17033 \end_layout
17034
17035 \begin_layout Standard
17036 SDCC allows the use of in-line assembler with a few restrictions regarding
17037  labels.
17038  In older versions of the compiler all labels defined within inline assembler
17039  code had to be of the form 
17040 \emph on
17041 nnnnn$
17042 \emph default
17043  where nnnnn is a number less than 100 (which implies a limit of utmost
17044  100 inline assembler labels 
17045 \emph on
17046 per function
17047 \emph default
17048 \noun on
17049 )
17050 \noun default
17051 .
17052  
17053 \end_layout
17054
17055 \begin_layout Verse
17056
17057 \family typewriter
17058 _asm
17059 \begin_inset LatexCommand \index{\_asm}
17060
17061 \end_inset
17062
17063
17064 \begin_inset LatexCommand \index{\_\_asm}
17065
17066 \end_inset
17067
17068  
17069 \newline
17070 \InsetSpace ~
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 mov\InsetSpace ~
17075 \InsetSpace ~
17076 \InsetSpace ~
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 b,#10 
17080 \newline
17081 00001$: 
17082 \newline
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 djnz\InsetSpace ~
17088 \InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 b,00001$ 
17092 \newline
17093 _endasm
17094 \begin_inset LatexCommand \index{\_endasm}
17095
17096 \end_inset
17097
17098
17099 \begin_inset LatexCommand \index{\_\_endasm}
17100
17101 \end_inset
17102
17103  ;
17104 \end_layout
17105
17106 \begin_layout Standard
17107 Inline assembler code cannot reference any C-labels, however it can reference
17108  labels
17109 \begin_inset LatexCommand \index{Labels}
17110
17111 \end_inset
17112
17113  defined by the inline assembler, e.g.:
17114 \end_layout
17115
17116 \begin_layout Verse
17117
17118 \family typewriter
17119 foo() { 
17120 \newline
17121 \InsetSpace ~
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 /* some c code */ 
17126 \newline
17127 \InsetSpace ~
17128 \InsetSpace ~
17129 \InsetSpace ~
17130 \InsetSpace ~
17131 _asm 
17132 \newline
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 ; some assembler code 
17140 \newline
17141 \InsetSpace ~
17142 \InsetSpace ~
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 \InsetSpace ~
17147 ljmp $0003 
17148 \newline
17149 \InsetSpace ~
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 _endasm;
17154  
17155 \newline
17156 \InsetSpace ~
17157 \InsetSpace ~
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 /* some more c code */ 
17161 \newline
17162 clabel:\InsetSpace ~
17163 \InsetSpace ~
17164 /* inline assembler cannot reference this
17165  label */ 
17166 \newline
17167 \InsetSpace ~
17168 \InsetSpace ~
17169 \InsetSpace ~
17170 \InsetSpace ~
17171 _asm
17172 \newline
17173 \InsetSpace ~
17174 \InsetSpace ~
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 $0003: ;label (can be referenced by inline assembler only)
17178  
17179 \newline
17180 \InsetSpace ~
17181 \InsetSpace ~
17182 \InsetSpace ~
17183 \InsetSpace ~
17184 _endasm
17185 \begin_inset LatexCommand \index{\_endasm}
17186
17187 \end_inset
17188
17189
17190 \begin_inset LatexCommand \index{\_\_endasm}
17191
17192 \end_inset
17193
17194  ; 
17195 \newline
17196 \InsetSpace ~
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 \InsetSpace ~
17200 /* some more c code */
17201 \newline
17202 }
17203 \end_layout
17204
17205 \begin_layout Standard
17206 In other words inline assembly code can access labels defined in inline
17207  assembly within the scope of the function.
17208  The same goes the other way, i.e.
17209  labels defines in inline assembly can not be accessed by C statements.
17210 \end_layout
17211
17212 \begin_layout Section
17213 Interfacing with Assembler Code
17214 \begin_inset LatexCommand \index{Assembler routines}
17215
17216 \end_inset
17217
17218
17219 \end_layout
17220
17221 \begin_layout Subsection
17222 Global Registers used for Parameter Passing
17223 \begin_inset LatexCommand \index{Parameter passing}
17224
17225 \end_inset
17226
17227
17228 \end_layout
17229
17230 \begin_layout Standard
17231 The compiler always uses the global registers 
17232 \emph on
17233 DPL, DPH
17234 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17235
17236 \end_inset
17237
17238
17239 \begin_inset LatexCommand \index{DPTR}
17240
17241 \end_inset
17242
17243 , B
17244 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17245
17246 \end_inset
17247
17248  
17249 \emph default
17250 and
17251 \emph on
17252  ACC
17253 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17254
17255 \end_inset
17256
17257
17258 \emph default
17259  to pass the first parameter to a function, and also to pass the return
17260  value 
17261 \begin_inset LatexCommand \index{return value}
17262
17263 \end_inset
17264
17265 of function; according to the following scheme: one byte return value in
17266  
17267 \emph on
17268 DPL
17269 \emph default
17270 , two byte value in 
17271 \emph on
17272 DPL
17273 \emph default
17274  (LSB) and 
17275 \emph on
17276 DPH
17277 \emph default
17278  (MSB).
17279  three byte values (generic pointers) in 
17280 \emph on
17281 DPH
17282 \emph default
17283
17284 \emph on
17285 DPL
17286 \emph default
17287  and 
17288 \emph on
17289 B
17290 \emph default
17291 , and four byte values in 
17292 \emph on
17293 DPH
17294 \emph default
17295
17296 \emph on
17297 DPL
17298 \emph default
17299 ,
17300 \emph on
17301  B
17302 \emph default
17303  and 
17304 \emph on
17305 ACC
17306 \emph default
17307 .
17308  Generic pointers
17309 \begin_inset LatexCommand \index{generic pointer}
17310
17311 \end_inset
17312
17313  contain type of accessed memory in 
17314 \emph on
17315 B
17316 \emph default
17317
17318 \series bold
17319 0x00
17320 \series default
17321  -- xdata/far, 
17322 \series bold
17323 0x40
17324 \series default
17325  -- idata/near -- , 
17326 \series bold
17327 0x60
17328 \series default
17329  -- pdata, 
17330 \series bold
17331 0x80
17332 \series default
17333  -- code
17334 \begin_inset Note Note
17335 status collapsed
17336
17337 \begin_layout Standard
17338 This might not be the case of certain memory models (medium???)
17339 \end_layout
17340
17341 \end_inset
17342
17343 .
17344 \end_layout
17345
17346 \begin_layout Standard
17347 The second parameter onwards is either allocated on the stack (for reentrant
17348  routines or if -
17349 \begin_inset ERT
17350 status collapsed
17351
17352 \begin_layout Standard
17353
17354
17355 \backslash
17356 /
17357 \end_layout
17358
17359 \end_inset
17360
17361 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17362  
17363 \end_layout
17364
17365 \begin_layout Subsection
17366 Registers usage
17367 \end_layout
17368
17369 \begin_layout Standard
17370 Unless the called function is declared as 
17371 \family typewriter
17372 _naked
17373 \family default
17374
17375 \begin_inset LatexCommand \index{naked}
17376
17377 \end_inset
17378
17379 , or the -
17380 \begin_inset ERT
17381 status collapsed
17382
17383 \begin_layout Standard
17384
17385
17386 \backslash
17387 /
17388 \end_layout
17389
17390 \end_inset
17391
17392 -callee-saves
17393 \begin_inset LatexCommand \index{-\/-callee-saves}
17394
17395 \end_inset
17396
17397 /-
17398 \begin_inset ERT
17399 status collapsed
17400
17401 \begin_layout Standard
17402
17403
17404 \backslash
17405 /
17406 \end_layout
17407
17408 \end_inset
17409
17410 -all-callee-saves command line option or the corresponding callee_saves
17411  pragma are used, the caller will save the registers (
17412 \emph on
17413 R0-R7
17414 \emph default
17415 ) around the call, so the called function can destroy they content freely.
17416 \end_layout
17417
17418 \begin_layout Standard
17419 If the called function is not declared as 
17420 \family typewriter
17421 _naked
17422 \family default
17423 , the caller will swap register banks around the call, if caller and callee
17424  use different register banks (having them defined by the 
17425 \family typewriter
17426 _using
17427 \family default
17428  modifier).
17429  
17430 \end_layout
17431
17432 \begin_layout Standard
17433 The called function can also use 
17434 \emph on
17435 DPL
17436 \emph default
17437
17438 \emph on
17439 DPH
17440 \emph default
17441
17442 \emph on
17443 B
17444 \emph default
17445  and 
17446 \emph on
17447 ACC
17448 \emph default
17449  observing that they are used for parameter/return value passing.
17450 \end_layout
17451
17452 \begin_layout Subsection
17453 Assembler Routine (non-reentrant)
17454 \end_layout
17455
17456 \begin_layout Standard
17457 In the following example
17458 \begin_inset LatexCommand \index{reentrant}
17459
17460 \end_inset
17461
17462
17463 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17464
17465 \end_inset
17466
17467  the function c_func calls an assembler routine asm_func, which takes two
17468  parameters
17469 \begin_inset LatexCommand \index{function parameter}
17470
17471 \end_inset
17472
17473 .
17474 \end_layout
17475
17476 \begin_layout Verse
17477
17478 \family typewriter
17479 extern int asm_func(unsigned char, unsigned char);
17480 \newline
17481
17482 \newline
17483 int c_func (unsigned char
17484  i, unsigned char j)
17485 \newline
17486 {
17487 \newline
17488 \InsetSpace ~
17489 \InsetSpace ~
17490 \InsetSpace ~
17491 \InsetSpace ~
17492 return asm_func(i,j);
17493 \newline
17494 }
17495 \newline
17496
17497 \newline
17498 int main()
17499 \newline
17500 {
17501 \newline
17502 \InsetSpace ~
17503 \InsetSpace ~
17504 \InsetSpace ~
17505 \InsetSpace ~
17506 return c_func(10,9);
17507 \newline
17508 }
17509 \end_layout
17510
17511 \begin_layout Standard
17512 The corresponding assembler function is:
17513 \end_layout
17514
17515 \begin_layout Verse
17516
17517 \family typewriter
17518 .globl _asm_func_PARM_2 
17519 \newline
17520 \InsetSpace ~
17521 \InsetSpace ~
17522 \InsetSpace ~
17523 \InsetSpace ~
17524 \InsetSpace ~
17525 \InsetSpace ~
17526 \InsetSpace ~
17527 \InsetSpace ~
17528 .globl _asm_func 
17529 \newline
17530 \InsetSpace ~
17531 \InsetSpace ~
17532 \InsetSpace ~
17533 \InsetSpace ~
17534 \InsetSpace ~
17535 \InsetSpace ~
17536 \InsetSpace ~
17537 \InsetSpace ~
17538 .area OSEG 
17539 \newline
17540 _asm_func_PARM_2:
17541 \newline
17542 \InsetSpace ~
17543 \InsetSpace ~
17544 \InsetSpace ~
17545 \InsetSpace ~
17546 \InsetSpace ~
17547 \InsetSpace ~
17548 \InsetSpace ~
17549 \InsetSpace ~
17550 .ds   
17551  1 
17552 \newline
17553 \InsetSpace ~
17554 \InsetSpace ~
17555 \InsetSpace ~
17556 \InsetSpace ~
17557 \InsetSpace ~
17558 \InsetSpace ~
17559 \InsetSpace ~
17560 \InsetSpace ~
17561 .area CSEG 
17562 \newline
17563 _asm_func: 
17564 \newline
17565 \InsetSpace ~
17566 \InsetSpace ~
17567 \InsetSpace ~
17568 \InsetSpace ~
17569 \InsetSpace ~
17570 \InsetSpace ~
17571 \InsetSpace ~
17572 \InsetSpace ~
17573 mov\InsetSpace ~
17574 \InsetSpace ~
17575 \InsetSpace ~
17576 \InsetSpace ~
17577 a,dpl 
17578 \newline
17579 \InsetSpace ~
17580 \InsetSpace ~
17581 \InsetSpace ~
17582 \InsetSpace ~
17583 \InsetSpace ~
17584 \InsetSpace ~
17585 \InsetSpace ~
17586 \InsetSpace ~
17587 add\InsetSpace ~
17588 \InsetSpace ~
17589 \InsetSpace ~
17590 \InsetSpace ~
17591 a,_asm_func_PARM_2 
17592 \newline
17593 \InsetSpace ~
17594 \InsetSpace ~
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 mov\InsetSpace ~
17602 \InsetSpace ~
17603 \InsetSpace ~
17604 \InsetSpace ~
17605 dpl,a 
17606 \newline
17607 \InsetSpace ~
17608 \InsetSpace ~
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 \InsetSpace ~
17612 \InsetSpace ~
17613 \InsetSpace ~
17614 \InsetSpace ~
17615 mov\InsetSpace ~
17616 \InsetSpace ~
17617 \InsetSpace ~
17618 \InsetSpace ~
17619 dph
17620 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17621
17622 \end_inset
17623
17624 ,#0x00 
17625 \newline
17626 \InsetSpace ~
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 \InsetSpace ~
17630 \InsetSpace ~
17631 \InsetSpace ~
17632 \InsetSpace ~
17633 \InsetSpace ~
17634 ret
17635 \end_layout
17636
17637 \begin_layout Standard
17638 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17639  the parameter number starting from 1, and counting from the left.
17640  The first parameter is passed in 
17641 \emph on
17642 DPH
17643 \emph default
17644
17645 \emph on
17646 DPL
17647 \emph default
17648
17649 \emph on
17650 B
17651 \emph default
17652  and 
17653 \emph on
17654 ACC
17655 \emph default
17656  according to the description above.
17657  The variable name for the second parameter will be _<function_name>_PARM_2.
17658 \newline
17659
17660 \newline
17661 Assem
17662 ble the assembler routine with the following command:
17663 \newline
17664
17665 \newline
17666
17667 \family sans
17668 \series bold
17669 asx8051 -losg asmfunc.asm
17670 \newline
17671
17672 \newline
17673
17674 \family default
17675 \series default
17676 Then compile and link the assembler routine to the C source file with the
17677  following command:
17678 \newline
17679
17680 \newline
17681
17682 \family sans
17683 \series bold
17684 sdcc cfunc.c asmfunc.rel
17685 \end_layout
17686
17687 \begin_layout Subsection
17688 Assembler Routine (reentrant)
17689 \end_layout
17690
17691 \begin_layout Standard
17692 In this case
17693 \begin_inset LatexCommand \index{reentrant}
17694
17695 \end_inset
17696
17697
17698 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17699
17700 \end_inset
17701
17702  the second parameter
17703 \begin_inset LatexCommand \index{function parameter}
17704
17705 \end_inset
17706
17707  onwards will be passed on the stack, the parameters are pushed from right
17708  to left i.e.
17709  before the call the second leftmost parameter will be on the top of the
17710  stack (the leftmost parameter is passed in registers).
17711  Here is an example:
17712 \end_layout
17713
17714 \begin_layout Verse
17715
17716 \family typewriter
17717 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17718 \newline
17719
17720 \newline
17721 int
17722  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
17723 \newline
17724 {
17725  
17726 \newline
17727 \InsetSpace ~
17728 \InsetSpace ~
17729 \InsetSpace ~
17730 \InsetSpace ~
17731 return asm_func(i,j,k); 
17732 \newline
17733
17734 \newline
17735
17736 \newline
17737 int main() 
17738 \newline
17739
17740 \newline
17741 \InsetSpace ~
17742 \InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 return c_func(10,9,8); 
17746 \newline
17747 }
17748 \end_layout
17749
17750 \begin_layout Standard
17751 The corresponding (unoptimized) assembler routine is:
17752 \end_layout
17753
17754 \begin_layout Verse
17755
17756 \family typewriter
17757 .globl _asm_func 
17758 \newline
17759 _asm_func: 
17760 \newline
17761 \InsetSpace ~
17762 \InsetSpace ~
17763 \InsetSpace ~
17764 \InsetSpace ~
17765 push\InsetSpace ~
17766 _bp 
17767 \newline
17768 \InsetSpace ~
17769 \InsetSpace ~
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 mov\InsetSpace ~
17773 \InsetSpace ~
17774 _bp,sp\InsetSpace ~
17775 \InsetSpace ~
17776 \InsetSpace ~
17777 \InsetSpace ~
17778 \InsetSpace ~
17779 \InsetSpace ~
17780 ;stack contains: _bp, return
17781  address, second parameter, third parameter
17782 \newline
17783 \InsetSpace ~
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 mov\InsetSpace ~
17788 \InsetSpace ~
17789 r2,dpl
17790 \newline
17791 \InsetSpace ~
17792 \InsetSpace ~
17793 \InsetSpace ~
17794 \InsetSpace ~
17795 mov\InsetSpace ~
17796 \InsetSpace ~
17797 a,_bp
17798 \newline
17799 \InsetSpace ~
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 add\InsetSpace ~
17804 \InsetSpace ~
17805 a,#0xfd\InsetSpace ~
17806 \InsetSpace ~
17807 \InsetSpace ~
17808 \InsetSpace ~
17809 \InsetSpace ~
17810 ;calculate
17811  pointer to the second parameter
17812 \newline
17813 \InsetSpace ~
17814 \InsetSpace ~
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 mov\InsetSpace ~
17818 \InsetSpace ~
17819 r0,a 
17820 \newline
17821 \InsetSpace ~
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 mov\InsetSpace ~
17826 \InsetSpace ~
17827 a,_bp 
17828 \newline
17829 \InsetSpace ~
17830 \InsetSpace ~
17831 \InsetSpace ~
17832 \InsetSpace ~
17833 add\InsetSpace ~
17834 \InsetSpace ~
17835 a,#0xfc\InsetSpace ~
17836 \InsetSpace ~
17837 \InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 ;calculate pointer
17841  to the rightmost parameter
17842 \newline
17843 \InsetSpace ~
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 mov\InsetSpace ~
17848 \InsetSpace ~
17849 r1,a 
17850 \newline
17851 \InsetSpace ~
17852 \InsetSpace ~
17853 \InsetSpace ~
17854 \InsetSpace ~
17855 mov\InsetSpace ~
17856 \InsetSpace ~
17857 a,@r0
17858 \newline
17859 \InsetSpace ~
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 add\InsetSpace ~
17864 \InsetSpace ~
17865 a,@r1
17866 \newline
17867 \InsetSpace ~
17868 \InsetSpace ~
17869 \InsetSpace ~
17870 \InsetSpace ~
17871 add\InsetSpace ~
17872 \InsetSpace ~
17873 a,r2\InsetSpace ~
17874 \InsetSpace ~
17875 \InsetSpace ~
17876 \InsetSpace ~
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 ;calculate the
17882  result (= sum of all three parameters)
17883 \newline
17884 \InsetSpace ~
17885 \InsetSpace ~
17886 \InsetSpace ~
17887 \InsetSpace ~
17888 mov\InsetSpace ~
17889 \InsetSpace ~
17890 dpl,a\InsetSpace ~
17891 \InsetSpace ~
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 ;return value goes into dptr
17898  (cast into int)
17899 \newline
17900 \InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 mov\InsetSpace ~
17905 \InsetSpace ~
17906 dph,#0x00 
17907 \newline
17908 \InsetSpace ~
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 mov\InsetSpace ~
17913 \InsetSpace ~
17914 sp,_bp 
17915 \newline
17916 \InsetSpace ~
17917 \InsetSpace ~
17918 \InsetSpace ~
17919 \InsetSpace ~
17920 pop\InsetSpace ~
17921 \InsetSpace ~
17922 _bp 
17923 \newline
17924 \InsetSpace ~
17925 \InsetSpace ~
17926 \InsetSpace ~
17927 \InsetSpace ~
17928 ret
17929 \end_layout
17930
17931 \begin_layout Standard
17932 The compiling and linking procedure remains the same, however note the extra
17933  entry & exit linkage required for the assembler code, _bp is the stack
17934  frame pointer and is used to compute the offset into the stack for parameters
17935  and local variables.
17936 \begin_inset VSpace bigskip
17937 \end_inset
17938
17939
17940 \end_layout
17941
17942 \begin_layout Section
17943 int (16 bit)
17944 \begin_inset LatexCommand \index{int (16 bit)}
17945
17946 \end_inset
17947
17948  and long (32 bit)
17949 \begin_inset LatexCommand \index{long (32 bit)}
17950
17951 \end_inset
17952
17953  Support
17954 \end_layout
17955
17956 \begin_layout Standard
17957 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17958  multiplication and modulus operations are implemented by support routines.
17959  These support routines are all developed in ANSI-C to facilitate porting
17960  to other MCUs, although some model specific assembler optimizations are
17961  used.
17962  The following files contain the described routines, all of them can be
17963  found in <installdir>/share/sdcc/lib.
17964 \newline
17965
17966 \end_layout
17967
17968 \begin_layout Standard
17969 \align center
17970 \begin_inset Tabular
17971 <lyxtabular version="3" rows="11" columns="2">
17972 <features>
17973 <column alignment="left" valignment="top" leftline="true" width="0">
17974 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17975 <row topline="true" bottomline="true">
17976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17977 \begin_inset Text
17978
17979 \begin_layout Standard
17980
17981 \series bold
17982 Function
17983 \end_layout
17984
17985 \end_inset
17986 </cell>
17987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17988 \begin_inset Text
17989
17990 \begin_layout Standard
17991
17992 \series bold
17993 Description
17994 \end_layout
17995
17996 \end_inset
17997 </cell>
17998 </row>
17999 <row topline="true">
18000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18001 \begin_inset Text
18002
18003 \begin_layout Standard
18004 _mulint.c 
18005 \end_layout
18006
18007 \end_inset
18008 </cell>
18009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18010 \begin_inset Text
18011
18012 \begin_layout Standard
18013 16 bit multiplication
18014 \end_layout
18015
18016 \end_inset
18017 </cell>
18018 </row>
18019 <row topline="true">
18020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18021 \begin_inset Text
18022
18023 \begin_layout Standard
18024 _divsint.c 
18025 \end_layout
18026
18027 \end_inset
18028 </cell>
18029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18030 \begin_inset Text
18031
18032 \begin_layout Standard
18033  signed 16 bit division (calls _divuint)
18034 \end_layout
18035
18036 \end_inset
18037 </cell>
18038 </row>
18039 <row topline="true">
18040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18041 \begin_inset Text
18042
18043 \begin_layout Standard
18044 _divuint.c 
18045 \end_layout
18046
18047 \end_inset
18048 </cell>
18049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18050 \begin_inset Text
18051
18052 \begin_layout Standard
18053  unsigned 16 bit division
18054 \end_layout
18055
18056 \end_inset
18057 </cell>
18058 </row>
18059 <row topline="true">
18060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18061 \begin_inset Text
18062
18063 \begin_layout Standard
18064 _modsint.c
18065 \end_layout
18066
18067 \end_inset
18068 </cell>
18069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18070 \begin_inset Text
18071
18072 \begin_layout Standard
18073 signed 16 bit modulus (calls _moduint)
18074 \end_layout
18075
18076 \end_inset
18077 </cell>
18078 </row>
18079 <row topline="true">
18080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18081 \begin_inset Text
18082
18083 \begin_layout Standard
18084 _moduint.c
18085 \end_layout
18086
18087 \end_inset
18088 </cell>
18089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18090 \begin_inset Text
18091
18092 \begin_layout Standard
18093 unsigned 16 bit modulus
18094 \end_layout
18095
18096 \end_inset
18097 </cell>
18098 </row>
18099 <row topline="true">
18100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18101 \begin_inset Text
18102
18103 \begin_layout Standard
18104 _mullong.c
18105 \end_layout
18106
18107 \end_inset
18108 </cell>
18109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18110 \begin_inset Text
18111
18112 \begin_layout Standard
18113 32 bit multiplication
18114 \end_layout
18115
18116 \end_inset
18117 </cell>
18118 </row>
18119 <row topline="true">
18120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18121 \begin_inset Text
18122
18123 \begin_layout Standard
18124 _divslong.c 
18125 \end_layout
18126
18127 \end_inset
18128 </cell>
18129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18130 \begin_inset Text
18131
18132 \begin_layout Standard
18133  signed 32 division (calls _divulong)
18134 \end_layout
18135
18136 \end_inset
18137 </cell>
18138 </row>
18139 <row topline="true">
18140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18141 \begin_inset Text
18142
18143 \begin_layout Standard
18144 _divulong.c 
18145 \end_layout
18146
18147 \end_inset
18148 </cell>
18149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18150 \begin_inset Text
18151
18152 \begin_layout Standard
18153 unsigned 32 division
18154 \end_layout
18155
18156 \end_inset
18157 </cell>
18158 </row>
18159 <row topline="true">
18160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18161 \begin_inset Text
18162
18163 \begin_layout Standard
18164 _modslong.c
18165 \end_layout
18166
18167 \end_inset
18168 </cell>
18169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18170 \begin_inset Text
18171
18172 \begin_layout Standard
18173  signed 32 bit modulus (calls _modulong)
18174 \end_layout
18175
18176 \end_inset
18177 </cell>
18178 </row>
18179 <row topline="true" bottomline="true">
18180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18181 \begin_inset Text
18182
18183 \begin_layout Standard
18184 _modulong.c
18185 \end_layout
18186
18187 \end_inset
18188 </cell>
18189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18190 \begin_inset Text
18191
18192 \begin_layout Standard
18193 unsigned 32 bit modulus
18194 \end_layout
18195
18196 \end_inset
18197 </cell>
18198 </row>
18199 </lyxtabular>
18200
18201 \end_inset
18202
18203
18204 \newline
18205
18206 \end_layout
18207
18208 \begin_layout Standard
18209 Since they are compiled as 
18210 \emph on
18211 non-reentrant
18212 \emph default
18213
18214 \begin_inset LatexCommand \index{reentrant}
18215
18216 \end_inset
18217
18218 , interrupt
18219 \begin_inset LatexCommand \index{interrupt}
18220
18221 \end_inset
18222
18223  service routines should not do any of the above operations.
18224  If this is unavoidable then the above routines will need to be compiled
18225  with the 
18226 \emph on
18227 -
18228 \begin_inset ERT
18229 status collapsed
18230
18231 \begin_layout Standard
18232
18233
18234 \backslash
18235 /
18236 \end_layout
18237
18238 \end_inset
18239
18240 -stack-auto
18241 \begin_inset LatexCommand \index{-\/-stack-auto}
18242
18243 \end_inset
18244
18245
18246 \emph default
18247  option, after which the source program will have to be compiled with 
18248 \emph on
18249 -
18250 \begin_inset ERT
18251 status collapsed
18252
18253 \begin_layout Standard
18254
18255
18256 \backslash
18257 /
18258 \end_layout
18259
18260 \end_inset
18261
18262 -int-long-reent
18263 \begin_inset LatexCommand \index{-\/-int-long-reent}
18264
18265 \end_inset
18266
18267
18268 \emph default
18269  option.
18270  Notice that you don't have to call these routines directly.
18271  The compiler will use them automatically every time an integer operation
18272  is required.
18273 \end_layout
18274
18275 \begin_layout Section
18276 Floating Point Support
18277 \begin_inset LatexCommand \index{Floating point support}
18278
18279 \end_inset
18280
18281
18282 \end_layout
18283
18284 \begin_layout Standard
18285 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18286  The floating point support routines are derived from gcc's floatlib.c and
18287  consist of the following routines:
18288 \newline
18289
18290 \end_layout
18291
18292 \begin_layout Standard
18293 \align center
18294
18295 \size footnotesize
18296 \begin_inset Tabular
18297 <lyxtabular version="3" rows="17" columns="2">
18298 <features>
18299 <column alignment="left" valignment="top" leftline="true" width="0">
18300 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18301 <row topline="true" bottomline="true">
18302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18303 \begin_inset Text
18304
18305 \begin_layout Standard
18306
18307 \family roman
18308 \series medium
18309 \shape up
18310 \size normal
18311 \emph off
18312 \bar no
18313 \noun off
18314 \color none
18315 Function 
18316 \end_layout
18317
18318 \end_inset
18319 </cell>
18320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18321 \begin_inset Text
18322
18323 \begin_layout Standard
18324 Description
18325 \end_layout
18326
18327 \end_inset
18328 </cell>
18329 </row>
18330 <row topline="true">
18331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18332 \begin_inset Text
18333
18334 \begin_layout Standard
18335
18336 \family roman
18337 \series medium
18338 \shape up
18339 \size normal
18340 \emph off
18341 \bar no
18342 \noun off
18343 \color none
18344 _fsadd.c
18345 \end_layout
18346
18347 \end_inset
18348 </cell>
18349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18350 \begin_inset Text
18351
18352 \begin_layout Standard
18353
18354 \family roman
18355 \series medium
18356 \shape up
18357 \size normal
18358 \emph off
18359 \bar no
18360 \noun off
18361 \color none
18362 add floating point numbers
18363 \end_layout
18364
18365 \end_inset
18366 </cell>
18367 </row>
18368 <row topline="true">
18369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18370 \begin_inset Text
18371
18372 \begin_layout Standard
18373
18374 \family roman
18375 \series medium
18376 \shape up
18377 \size normal
18378 \emph off
18379 \bar no
18380 \noun off
18381 \color none
18382 _fssub.c 
18383 \end_layout
18384
18385 \end_inset
18386 </cell>
18387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18388 \begin_inset Text
18389
18390 \begin_layout Standard
18391
18392 \family roman
18393 \series medium
18394 \shape up
18395 \size normal
18396 \emph off
18397 \bar no
18398 \noun off
18399 \color none
18400 subtract floating point numbers 
18401 \end_layout
18402
18403 \end_inset
18404 </cell>
18405 </row>
18406 <row topline="true">
18407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18408 \begin_inset Text
18409
18410 \begin_layout Standard
18411
18412 \family roman
18413 \series medium
18414 \shape up
18415 \size normal
18416 \emph off
18417 \bar no
18418 \noun off
18419 \color none
18420 _fsdiv.c 
18421 \end_layout
18422
18423 \end_inset
18424 </cell>
18425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18426 \begin_inset Text
18427
18428 \begin_layout Standard
18429
18430 \family roman
18431 \series medium
18432 \shape up
18433 \size normal
18434 \emph off
18435 \bar no
18436 \noun off
18437 \color none
18438 divide floating point numbers 
18439 \end_layout
18440
18441 \end_inset
18442 </cell>
18443 </row>
18444 <row topline="true">
18445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18446 \begin_inset Text
18447
18448 \begin_layout Standard
18449
18450 \family roman
18451 \series medium
18452 \shape up
18453 \size normal
18454 \emph off
18455 \bar no
18456 \noun off
18457 \color none
18458 _fsmul.c 
18459 \end_layout
18460
18461 \end_inset
18462 </cell>
18463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18464 \begin_inset Text
18465
18466 \begin_layout Standard
18467
18468 \family roman
18469 \series medium
18470 \shape up
18471 \size normal
18472 \emph off
18473 \bar no
18474 \noun off
18475 \color none
18476 multiply floating point numbers 
18477 \end_layout
18478
18479 \end_inset
18480 </cell>
18481 </row>
18482 <row topline="true">
18483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18484 \begin_inset Text
18485
18486 \begin_layout Standard
18487
18488 \family roman
18489 \series medium
18490 \shape up
18491 \size normal
18492 \emph off
18493 \bar no
18494 \noun off
18495 \color none
18496 _fs2uchar.c
18497 \end_layout
18498
18499 \end_inset
18500 </cell>
18501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18502 \begin_inset Text
18503
18504 \begin_layout Standard
18505
18506 \family roman
18507 \series medium
18508 \shape up
18509 \size normal
18510 \emph off
18511 \bar no
18512 \noun off
18513 \color none
18514 convert floating point to unsigned char
18515 \end_layout
18516
18517 \end_inset
18518 </cell>
18519 </row>
18520 <row topline="true">
18521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18522 \begin_inset Text
18523
18524 \begin_layout Standard
18525
18526 \family roman
18527 \series medium
18528 \shape up
18529 \size normal
18530 \emph off
18531 \bar no
18532 \noun off
18533 \color none
18534 _fs2char.c
18535 \end_layout
18536
18537 \end_inset
18538 </cell>
18539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18540 \begin_inset Text
18541
18542 \begin_layout Standard
18543
18544 \family roman
18545 \series medium
18546 \shape up
18547 \size normal
18548 \emph off
18549 \bar no
18550 \noun off
18551 \color none
18552 convert floating point to signed char
18553 \end_layout
18554
18555 \end_inset
18556 </cell>
18557 </row>
18558 <row topline="true">
18559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18560 \begin_inset Text
18561
18562 \begin_layout Standard
18563
18564 \family roman
18565 \series medium
18566 \shape up
18567 \size normal
18568 \emph off
18569 \bar no
18570 \noun off
18571 \color none
18572 _fs2uint.c
18573 \end_layout
18574
18575 \end_inset
18576 </cell>
18577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18578 \begin_inset Text
18579
18580 \begin_layout Standard
18581
18582 \family roman
18583 \series medium
18584 \shape up
18585 \size normal
18586 \emph off
18587 \bar no
18588 \noun off
18589 \color none
18590 convert floating point to unsigned int
18591 \end_layout
18592
18593 \end_inset
18594 </cell>
18595 </row>
18596 <row topline="true">
18597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18598 \begin_inset Text
18599
18600 \begin_layout Standard
18601
18602 \family roman
18603 \series medium
18604 \shape up
18605 \size normal
18606 \emph off
18607 \bar no
18608 \noun off
18609 \color none
18610 _fs2int.c
18611 \end_layout
18612
18613 \end_inset
18614 </cell>
18615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18616 \begin_inset Text
18617
18618 \begin_layout Standard
18619
18620 \family roman
18621 \series medium
18622 \shape up
18623 \size normal
18624 \emph off
18625 \bar no
18626 \noun off
18627 \color none
18628 convert floating point to signed int
18629 \end_layout
18630
18631 \end_inset
18632 </cell>
18633 </row>
18634 <row topline="true">
18635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18636 \begin_inset Text
18637
18638 \begin_layout Standard
18639
18640 \family roman
18641 \series medium
18642 \shape up
18643 \size normal
18644 \emph off
18645 \bar no
18646 \noun off
18647 \color none
18648 _fs2ulong.
18649 \family default
18650 \series default
18651 \shape default
18652 \size default
18653 \emph default
18654 \bar default
18655 \noun default
18656 c
18657 \end_layout
18658
18659 \end_inset
18660 </cell>
18661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18662 \begin_inset Text
18663
18664 \begin_layout Standard
18665
18666 \family roman
18667 \series medium
18668 \shape up
18669 \size normal
18670 \emph off
18671 \bar no
18672 \noun off
18673 \color none
18674 convert floating point to unsigned long
18675 \end_layout
18676
18677 \end_inset
18678 </cell>
18679 </row>
18680 <row topline="true">
18681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18682 \begin_inset Text
18683
18684 \begin_layout Standard
18685
18686 \family roman
18687 \series medium
18688 \shape up
18689 \size normal
18690 \emph off
18691 \bar no
18692 \noun off
18693 \color none
18694 _fs2long.c
18695 \end_layout
18696
18697 \end_inset
18698 </cell>
18699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18700 \begin_inset Text
18701
18702 \begin_layout Standard
18703
18704 \family roman
18705 \series medium
18706 \shape up
18707 \size normal
18708 \emph off
18709 \bar no
18710 \noun off
18711 \color none
18712 convert floating point to signed long
18713 \end_layout
18714
18715 \end_inset
18716 </cell>
18717 </row>
18718 <row topline="true">
18719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18720 \begin_inset Text
18721
18722 \begin_layout Standard
18723
18724 \family roman
18725 \series medium
18726 \shape up
18727 \size normal
18728 \emph off
18729 \bar no
18730 \noun off
18731 \color none
18732 _uchar2fs.c
18733 \end_layout
18734
18735 \end_inset
18736 </cell>
18737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18738 \begin_inset Text
18739
18740 \begin_layout Standard
18741
18742 \family roman
18743 \series medium
18744 \shape up
18745 \size normal
18746 \emph off
18747 \bar no
18748 \noun off
18749 \color none
18750 convert unsigned char to floating point
18751 \end_layout
18752
18753 \end_inset
18754 </cell>
18755 </row>
18756 <row topline="true">
18757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18758 \begin_inset Text
18759
18760 \begin_layout Standard
18761
18762 \family roman
18763 \series medium
18764 \shape up
18765 \size normal
18766 \emph off
18767 \bar no
18768 \noun off
18769 \color none
18770 _char2fs.c
18771 \end_layout
18772
18773 \end_inset
18774 </cell>
18775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18776 \begin_inset Text
18777
18778 \begin_layout Standard
18779
18780 \family roman
18781 \series medium
18782 \shape up
18783 \size normal
18784 \emph off
18785 \bar no
18786 \noun off
18787 \color none
18788 convert char to floating point number
18789 \end_layout
18790
18791 \end_inset
18792 </cell>
18793 </row>
18794 <row topline="true">
18795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18796 \begin_inset Text
18797
18798 \begin_layout Standard
18799
18800 \family roman
18801 \series medium
18802 \shape up
18803 \size normal
18804 \emph off
18805 \bar no
18806 \noun off
18807 \color none
18808 _uint2fs.c
18809 \end_layout
18810
18811 \end_inset
18812 </cell>
18813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18814 \begin_inset Text
18815
18816 \begin_layout Standard
18817
18818 \family roman
18819 \series medium
18820 \shape up
18821 \size normal
18822 \emph off
18823 \bar no
18824 \noun off
18825 \color none
18826 convert unsigned int to floating point
18827 \end_layout
18828
18829 \end_inset
18830 </cell>
18831 </row>
18832 <row topline="true">
18833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18834 \begin_inset Text
18835
18836 \begin_layout Standard
18837
18838 \family roman
18839 \series medium
18840 \shape up
18841 \size normal
18842 \emph off
18843 \bar no
18844 \noun off
18845 \color none
18846 _int2fs.c
18847 \end_layout
18848
18849 \end_inset
18850 </cell>
18851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18852 \begin_inset Text
18853
18854 \begin_layout Standard
18855
18856 \family roman
18857 \series medium
18858 \shape up
18859 \size normal
18860 \emph off
18861 \bar no
18862 \noun off
18863 \color none
18864 convert int to floating point numbers
18865 \end_layout
18866
18867 \end_inset
18868 </cell>
18869 </row>
18870 <row topline="true">
18871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18872 \begin_inset Text
18873
18874 \begin_layout Standard
18875
18876 \family roman
18877 \series medium
18878 \shape up
18879 \size normal
18880 \emph off
18881 \bar no
18882 \noun off
18883 \color none
18884 _ulong2fs.c
18885 \end_layout
18886
18887 \end_inset
18888 </cell>
18889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18890 \begin_inset Text
18891
18892 \begin_layout Standard
18893
18894 \family roman
18895 \series medium
18896 \shape up
18897 \size normal
18898 \emph off
18899 \bar no
18900 \noun off
18901 \color none
18902 convert unsigned long to floating point number
18903 \end_layout
18904
18905 \end_inset
18906 </cell>
18907 </row>
18908 <row topline="true" bottomline="true">
18909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18910 \begin_inset Text
18911
18912 \begin_layout Standard
18913
18914 \family roman
18915 \series medium
18916 \shape up
18917 \size normal
18918 \emph off
18919 \bar no
18920 \noun off
18921 \color none
18922 _long2fs.c
18923 \end_layout
18924
18925 \end_inset
18926 </cell>
18927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18928 \begin_inset Text
18929
18930 \begin_layout Standard
18931
18932 \family roman
18933 \series medium
18934 \shape up
18935 \size normal
18936 \emph off
18937 \bar no
18938 \noun off
18939 \color none
18940 convert long to floating point number
18941 \end_layout
18942
18943 \end_inset
18944 </cell>
18945 </row>
18946 </lyxtabular>
18947
18948 \end_inset
18949
18950
18951 \newline
18952
18953 \end_layout
18954
18955 \begin_layout Standard
18956 These support routines are developed in ANSI-C so there is room for space
18957  and speed improvement
18958 \begin_inset Foot
18959 status open
18960
18961 \begin_layout Standard
18962 These floating point routines (
18963 \emph on
18964 not
18965 \emph default
18966  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18967  
18968 \end_layout
18969
18970 \end_inset
18971
18972 .
18973  Note if all these routines are used simultaneously the data space might
18974  overflow.
18975  For serious floating point usage the large model might be needed.
18976  Also notice that you don't have to call this routines directly.
18977  The compiler will use them automatically every time a floating point operation
18978  is required.
18979 \begin_inset VSpace bigskip
18980 \end_inset
18981
18982
18983 \end_layout
18984
18985 \begin_layout Section
18986 Library Routines
18987 \begin_inset LatexCommand \index{Libraries}
18988
18989 \end_inset
18990
18991
18992 \end_layout
18993
18994 \begin_layout Standard
18995
18996 \emph on
18997 <pending: this is messy and incomplete - a little more information is in
18998  sdcc/doc/libdoc.txt
18999 \emph default
19000  >
19001 \end_layout
19002
19003 \begin_layout Subsection
19004 Compiler support routines (_gptrget, _mulint etc.)
19005 \end_layout
19006
19007 \begin_layout Subsection
19008 Stdclib functions (puts, printf, strcat etc.)
19009 \end_layout
19010
19011 \begin_layout Subsubsection
19012 <stdio.h>
19013 \end_layout
19014
19015 \begin_layout Paragraph
19016 getchar(), putchar()
19017 \end_layout
19018
19019 \begin_layout Standard
19020 \begin_inset LatexCommand \index{<stdio.h>}
19021
19022 \end_inset
19023
19024 As usual on embedded systems you have to provide your own 
19025 \family typewriter
19026 getchar()
19027 \begin_inset LatexCommand \index{getchar()}
19028
19029 \end_inset
19030
19031  
19032 \family default
19033 and 
19034 \family typewriter
19035 putchar()
19036 \begin_inset LatexCommand \index{putchar()}
19037
19038 \end_inset
19039
19040
19041 \family default
19042  routines.
19043  SDCC does not know whether the system connects to a serial line with or
19044  without handshake, LCD, keyboard or other device.
19045  And whether a 
19046 \family typewriter
19047 lf
19048 \family default
19049  to 
19050 \family typewriter
19051 crlf
19052 \family default
19053  conversion within 
19054 \family typewriter
19055 putchar()
19056 \family default
19057  is intended.
19058  You'll find examples for serial routines f.e.
19059  in sdcc/device/lib.
19060  For the mcs51 this minimalistic polling 
19061 \family typewriter
19062 putchar()
19063 \family default
19064  routine might be a start:
19065 \end_layout
19066
19067 \begin_layout Verse
19068
19069 \family typewriter
19070 void putchar (char c) { 
19071 \newline
19072 \InsetSpace ~
19073 \InsetSpace ~
19074 \InsetSpace ~
19075 \InsetSpace ~
19076 while (!TI)\InsetSpace ~
19077 \InsetSpace ~
19078 \InsetSpace ~
19079  /* assumes UART is initialized */
19080 \newline
19081 \InsetSpace ~
19082 \InsetSpace ~
19083 \InsetSpace ~
19084 \InsetSpace ~
19085 \InsetSpace ~
19086 \InsetSpace ~
19087 \InsetSpace ~
19088 \InsetSpace ~
19089 ;
19090 \newline
19091 \InsetSpace ~
19092 \InsetSpace ~
19093 \InsetSpace ~
19094 \InsetSpace ~
19095 TI
19096  = 0;
19097 \newline
19098 \InsetSpace ~
19099 \InsetSpace ~
19100 \InsetSpace ~
19101 \InsetSpace ~
19102 SBUF = c;
19103 \newline
19104 }
19105 \end_layout
19106
19107 \begin_layout Paragraph
19108 printf()
19109 \end_layout
19110
19111 \begin_layout Standard
19112 The default
19113 \family typewriter
19114  printf()
19115 \begin_inset LatexCommand \index{printf()}
19116
19117 \end_inset
19118
19119
19120 \family default
19121  implementation in
19122 \family typewriter
19123  printf_large.c
19124 \family default
19125  does not support float (except on ds390).
19126  To enable this recompile it with the option 
19127 \emph on
19128 -
19129 \begin_inset ERT
19130 status collapsed
19131
19132 \begin_layout Standard
19133
19134
19135 \backslash
19136 /
19137 \end_layout
19138
19139 \end_inset
19140
19141 DUSE_FLOATS=1
19142 \begin_inset LatexCommand \index{USE\_FLOATS}
19143
19144 \end_inset
19145
19146
19147 \emph default
19148  on the command line.
19149  Use
19150 \emph on
19151  -
19152 \begin_inset ERT
19153 status collapsed
19154
19155 \begin_layout Standard
19156
19157
19158 \backslash
19159 /
19160 \end_layout
19161
19162 \end_inset
19163
19164 -model-large
19165 \begin_inset LatexCommand \index{-\/-model-large}
19166
19167 \end_inset
19168
19169
19170 \emph default
19171  for the mcs51 port, since this uses a lot of memory.
19172 \end_layout
19173
19174 \begin_layout Standard
19175 If you're short on code memory you might want to use 
19176 \family typewriter
19177 printf_small()
19178 \begin_inset LatexCommand \index{printf\_small()}
19179
19180 \end_inset
19181
19182
19183 \family default
19184  
19185 \emph on
19186 instead
19187 \emph default
19188  of
19189 \family typewriter
19190  printf().
19191
19192 \family default
19193  For the mcs51 there additionally are assembly versions 
19194 \family typewriter
19195 printf_tiny()
19196 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19197
19198 \end_inset
19199
19200
19201 \family default
19202  (subset of printf using less than 270 bytes) and 
19203 \family typewriter
19204 printf_fast()
19205 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19206
19207 \end_inset
19208
19209  
19210 \family default
19211 and
19212 \family typewriter
19213  printf_fast_f()
19214 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19215
19216 \end_inset
19217
19218
19219 \family default
19220  (floating-point aware version of printf_fast) which should fit the requirements
19221  of many embedded systems (printf_fast() can be customized by unsetting
19222  #defines to 
19223 \emph on
19224 not
19225 \emph default
19226  support long variables and field widths).
19227  Be sure to use only one of these printf options within a project.
19228 \newline
19229
19230 \end_layout
19231
19232 \begin_layout Standard
19233 Feature matrix of different 
19234 \emph on
19235 printf
19236 \emph default
19237  options on mcs51.
19238 \end_layout
19239
19240 \begin_layout Standard
19241 \begin_inset Tabular
19242 <lyxtabular version="3" rows="14" columns="7">
19243 <features islongtable="true">
19244 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19245 <column alignment="center" valignment="top" leftline="true" width="0">
19246 <column alignment="center" valignment="top" leftline="true" width="12col%">
19247 <column alignment="center" valignment="top" leftline="true" width="10col%">
19248 <column alignment="center" valignment="top" leftline="true" width="0">
19249 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19250 <column alignment="center" valignment="top" rightline="true" width="0">
19251 <row topline="true" bottomline="true" endhead="true">
19252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19253 \begin_inset Text
19254
19255 \begin_layout Standard
19256
19257 \series bold
19258 \size large
19259 mcs51
19260 \end_layout
19261
19262 \end_inset
19263 </cell>
19264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19265 \begin_inset Text
19266
19267 \begin_layout Standard
19268 printf
19269 \begin_inset LatexCommand \index{printf}
19270
19271 \end_inset
19272
19273
19274 \end_layout
19275
19276 \end_inset
19277 </cell>
19278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19279 \begin_inset Text
19280
19281 \begin_layout Standard
19282 printf 
19283 \size scriptsize
19284 USE_FLOATS=1
19285 \end_layout
19286
19287 \end_inset
19288 </cell>
19289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19290 \begin_inset Text
19291
19292 \begin_layout Standard
19293 printf_small
19294 \end_layout
19295
19296 \end_inset
19297 </cell>
19298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19299 \begin_inset Text
19300
19301 \begin_layout Standard
19302 printf_fast
19303 \end_layout
19304
19305 \end_inset
19306 </cell>
19307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19308 \begin_inset Text
19309
19310 \begin_layout Standard
19311 printf_fast_f
19312 \end_layout
19313
19314 \end_inset
19315 </cell>
19316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19317 \begin_inset Text
19318
19319 \begin_layout Standard
19320 printf_tiny
19321 \end_layout
19322
19323 \end_inset
19324 </cell>
19325 </row>
19326 <row topline="true" endhead="true">
19327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19328 \begin_inset Text
19329
19330 \begin_layout Standard
19331 filename
19332 \end_layout
19333
19334 \end_inset
19335 </cell>
19336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19337 \begin_inset Text
19338
19339 \begin_layout Standard
19340
19341 \size scriptsize
19342 printf_large.c
19343 \end_layout
19344
19345 \end_inset
19346 </cell>
19347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19348 \begin_inset Text
19349
19350 \begin_layout Standard
19351
19352 \size scriptsize
19353 printf_large.c
19354 \end_layout
19355
19356 \end_inset
19357 </cell>
19358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19359 \begin_inset Text
19360
19361 \begin_layout Standard
19362
19363 \size scriptsize
19364 printfl.c
19365 \end_layout
19366
19367 \end_inset
19368 </cell>
19369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19370 \begin_inset Text
19371
19372 \begin_layout Standard
19373
19374 \size scriptsize
19375 printf_fast.c
19376 \end_layout
19377
19378 \end_inset
19379 </cell>
19380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19381 \begin_inset Text
19382
19383 \begin_layout Standard
19384
19385 \size scriptsize
19386 printf_fast_f.c
19387 \end_layout
19388
19389 \end_inset
19390 </cell>
19391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19392 \begin_inset Text
19393
19394 \begin_layout Standard
19395
19396 \size scriptsize
19397 printf_tiny.c
19398 \end_layout
19399
19400 \end_inset
19401 </cell>
19402 </row>
19403 <row topline="true" endhead="true">
19404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19405 \begin_inset Text
19406
19407 \begin_layout Standard
19408 \begin_inset Quotes sld
19409 \end_inset
19410
19411 Hello World
19412 \begin_inset Quotes srd
19413 \end_inset
19414
19415  size
19416 \end_layout
19417
19418 \begin_layout Standard
19419 small / large
19420 \end_layout
19421
19422 \end_inset
19423 </cell>
19424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19425 \begin_inset Text
19426
19427 \begin_layout Standard
19428 1.7k / 2.4k
19429 \end_layout
19430
19431 \end_inset
19432 </cell>
19433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19434 \begin_inset Text
19435
19436 \begin_layout Standard
19437 4.3k / 5.6k
19438 \end_layout
19439
19440 \end_inset
19441 </cell>
19442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19443 \begin_inset Text
19444
19445 \begin_layout Standard
19446 1.2k / 1.8k
19447 \end_layout
19448
19449 \end_inset
19450 </cell>
19451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19452 \begin_inset Text
19453
19454 \begin_layout Standard
19455 1.3k / 1.3k
19456 \end_layout
19457
19458 \end_inset
19459 </cell>
19460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19461 \begin_inset Text
19462
19463 \begin_layout Standard
19464 1.9k / 1.9k
19465 \end_layout
19466
19467 \end_inset
19468 </cell>
19469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19470 \begin_inset Text
19471
19472 \begin_layout Standard
19473 0.44k / 0.44k
19474 \end_layout
19475
19476 \end_inset
19477 </cell>
19478 </row>
19479 <row topline="true" endhead="true">
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19481 \begin_inset Text
19482
19483 \begin_layout Standard
19484 code size
19485 \end_layout
19486
19487 \begin_layout Standard
19488 small / large
19489 \end_layout
19490
19491 \end_inset
19492 </cell>
19493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19494 \begin_inset Text
19495
19496 \begin_layout Standard
19497 1.4k / 2.0k
19498 \end_layout
19499
19500 \end_inset
19501 </cell>
19502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19503 \begin_inset Text
19504
19505 \begin_layout Standard
19506 2.8k / 3.7k
19507 \end_layout
19508
19509 \end_inset
19510 </cell>
19511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19512 \begin_inset Text
19513
19514 \begin_layout Standard
19515 0.45k / 0.47k (+ _ltoa)
19516 \end_layout
19517
19518 \end_inset
19519 </cell>
19520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19521 \begin_inset Text
19522
19523 \begin_layout Standard
19524 1.2k / 1.2k
19525 \end_layout
19526
19527 \end_inset
19528 </cell>
19529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19530 \begin_inset Text
19531
19532 \begin_layout Standard
19533 1.6k / 1.6k
19534 \end_layout
19535
19536 \end_inset
19537 </cell>
19538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19539 \begin_inset Text
19540
19541 \begin_layout Standard
19542 0.26k / 0.26k
19543 \end_layout
19544
19545 \end_inset
19546 </cell>
19547 </row>
19548 <row topline="true">
19549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19550 \begin_inset Text
19551
19552 \begin_layout Standard
19553 formats
19554 \end_layout
19555
19556 \end_inset
19557 </cell>
19558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19559 \begin_inset Text
19560
19561 \begin_layout Standard
19562 cdi
19563 \emph on
19564 o
19565 \emph default
19566 psux
19567 \end_layout
19568
19569 \end_inset
19570 </cell>
19571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19572 \begin_inset Text
19573
19574 \begin_layout Standard
19575
19576 \family roman
19577 \series medium
19578 \shape up
19579 \size normal
19580 \emph off
19581 \bar no
19582 \noun off
19583 \color none
19584 cd
19585 \family default
19586 \series default
19587 \shape default
19588 \size default
19589 \emph default
19590 \bar default
19591 \noun default
19592 f
19593 \family roman
19594 \series medium
19595 \shape up
19596 \size normal
19597 \emph off
19598 \bar no
19599 \noun off
19600 i
19601 \family default
19602 \series default
19603 \shape default
19604 \size default
19605 \emph on
19606 \bar default
19607 \noun default
19608 o
19609 \family roman
19610 \series medium
19611 \shape up
19612 \size normal
19613 \emph off
19614 \bar no
19615 \noun off
19616 psux
19617 \end_layout
19618
19619 \end_inset
19620 </cell>
19621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19622 \begin_inset Text
19623
19624 \begin_layout Standard
19625 c
19626 \family roman
19627 \series medium
19628 \shape up
19629 \size normal
19630 \emph off
19631 \bar no
19632 \noun off
19633 \color none
19634 d
19635 \family default
19636 \series default
19637 \shape default
19638 \size default
19639 \emph on
19640 \bar default
19641 \noun default
19642 o
19643 \family roman
19644 \series medium
19645 \shape up
19646 \size normal
19647 \emph off
19648 \bar no
19649 \noun off
19650 s
19651 \family default
19652 \series default
19653 \shape default
19654 \size default
19655 \emph default
19656 \bar default
19657 \noun default
19658 x
19659 \end_layout
19660
19661 \end_inset
19662 </cell>
19663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19664 \begin_inset Text
19665
19666 \begin_layout Standard
19667 cdsux
19668 \end_layout
19669
19670 \end_inset
19671 </cell>
19672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19673 \begin_inset Text
19674
19675 \begin_layout Standard
19676 cdfsux
19677 \end_layout
19678
19679 \end_inset
19680 </cell>
19681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19682 \begin_inset Text
19683
19684 \begin_layout Standard
19685 cdsux
19686 \end_layout
19687
19688 \end_inset
19689 </cell>
19690 </row>
19691 <row topline="true">
19692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19693 \begin_inset Text
19694
19695 \begin_layout Standard
19696 long (32 bit) support
19697 \end_layout
19698
19699 \end_inset
19700 </cell>
19701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19702 \begin_inset Text
19703
19704 \begin_layout Standard
19705 x
19706 \end_layout
19707
19708 \end_inset
19709 </cell>
19710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19711 \begin_inset Text
19712
19713 \begin_layout Standard
19714 x
19715 \end_layout
19716
19717 \end_inset
19718 </cell>
19719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19720 \begin_inset Text
19721
19722 \begin_layout Standard
19723 x
19724 \end_layout
19725
19726 \end_inset
19727 </cell>
19728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19729 \begin_inset Text
19730
19731 \begin_layout Standard
19732 x
19733 \end_layout
19734
19735 \end_inset
19736 </cell>
19737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19738 \begin_inset Text
19739
19740 \begin_layout Standard
19741
19742 \family roman
19743 \series medium
19744 \shape up
19745 \size normal
19746 \emph off
19747 \bar no
19748 \noun off
19749 \color none
19750 x
19751 \end_layout
19752
19753 \end_inset
19754 </cell>
19755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19756 \begin_inset Text
19757
19758 \begin_layout Standard
19759 -
19760 \end_layout
19761
19762 \end_inset
19763 </cell>
19764 </row>
19765 <row topline="true">
19766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19767 \begin_inset Text
19768
19769 \begin_layout Standard
19770 byte arguments on stack
19771 \end_layout
19772
19773 \end_inset
19774 </cell>
19775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19776 \begin_inset Text
19777
19778 \begin_layout Standard
19779 b
19780 \end_layout
19781
19782 \end_inset
19783 </cell>
19784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19785 \begin_inset Text
19786
19787 \begin_layout Standard
19788 b
19789 \end_layout
19790
19791 \end_inset
19792 </cell>
19793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19794 \begin_inset Text
19795
19796 \begin_layout Standard
19797 -
19798 \end_layout
19799
19800 \end_inset
19801 </cell>
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19803 \begin_inset Text
19804
19805 \begin_layout Standard
19806 -
19807 \end_layout
19808
19809 \end_inset
19810 </cell>
19811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19812 \begin_inset Text
19813
19814 \begin_layout Standard
19815 -
19816 \end_layout
19817
19818 \end_inset
19819 </cell>
19820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19821 \begin_inset Text
19822
19823 \begin_layout Standard
19824 -
19825 \end_layout
19826
19827 \end_inset
19828 </cell>
19829 </row>
19830 <row topline="true">
19831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19832 \begin_inset Text
19833
19834 \begin_layout Standard
19835 float format
19836 \begin_inset LatexCommand \index{Floating point support}
19837
19838 \end_inset
19839
19840
19841 \end_layout
19842
19843 \end_inset
19844 </cell>
19845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19846 \begin_inset Text
19847
19848 \begin_layout Standard
19849 -
19850 \end_layout
19851
19852 \end_inset
19853 </cell>
19854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19855 \begin_inset Text
19856
19857 \begin_layout Standard
19858 %f
19859 \end_layout
19860
19861 \end_inset
19862 </cell>
19863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19864 \begin_inset Text
19865
19866 \begin_layout Standard
19867 -
19868 \end_layout
19869
19870 \end_inset
19871 </cell>
19872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19873 \begin_inset Text
19874
19875 \begin_layout Standard
19876 -
19877 \end_layout
19878
19879 \end_inset
19880 </cell>
19881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19882 \begin_inset Text
19883
19884 \begin_layout Standard
19885 %f
19886 \begin_inset Foot
19887 status collapsed
19888
19889 \begin_layout Standard
19890 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19891 \end_layout
19892
19893 \end_inset
19894
19895
19896 \end_layout
19897
19898 \end_inset
19899 </cell>
19900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19901 \begin_inset Text
19902
19903 \begin_layout Standard
19904 -
19905 \end_layout
19906
19907 \end_inset
19908 </cell>
19909 </row>
19910 <row topline="true">
19911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19912 \begin_inset Text
19913
19914 \begin_layout Standard
19915 float formats %e %g
19916 \end_layout
19917
19918 \end_inset
19919 </cell>
19920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19921 \begin_inset Text
19922
19923 \begin_layout Standard
19924 -
19925 \end_layout
19926
19927 \end_inset
19928 </cell>
19929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19930 \begin_inset Text
19931
19932 \begin_layout Standard
19933 -
19934 \end_layout
19935
19936 \end_inset
19937 </cell>
19938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19939 \begin_inset Text
19940
19941 \begin_layout Standard
19942 -
19943 \end_layout
19944
19945 \end_inset
19946 </cell>
19947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19948 \begin_inset Text
19949
19950 \begin_layout Standard
19951 -
19952 \end_layout
19953
19954 \end_inset
19955 </cell>
19956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19957 \begin_inset Text
19958
19959 \begin_layout Standard
19960 -
19961 \end_layout
19962
19963 \end_inset
19964 </cell>
19965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19966 \begin_inset Text
19967
19968 \begin_layout Standard
19969 -
19970 \end_layout
19971
19972 \end_inset
19973 </cell>
19974 </row>
19975 <row topline="true" bottomline="true">
19976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19977 \begin_inset Text
19978
19979 \begin_layout Standard
19980 field width
19981 \end_layout
19982
19983 \end_inset
19984 </cell>
19985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19986 \begin_inset Text
19987
19988 \begin_layout Standard
19989 x
19990 \end_layout
19991
19992 \end_inset
19993 </cell>
19994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19995 \begin_inset Text
19996
19997 \begin_layout Standard
19998 x
19999 \end_layout
20000
20001 \end_inset
20002 </cell>
20003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20004 \begin_inset Text
20005
20006 \begin_layout Standard
20007 -
20008 \end_layout
20009
20010 \end_inset
20011 </cell>
20012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20013 \begin_inset Text
20014
20015 \begin_layout Standard
20016 x
20017 \end_layout
20018
20019 \end_inset
20020 </cell>
20021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20022 \begin_inset Text
20023
20024 \begin_layout Standard
20025 x
20026 \end_layout
20027
20028 \end_inset
20029 </cell>
20030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20031 \begin_inset Text
20032
20033 \begin_layout Standard
20034 -
20035 \end_layout
20036
20037 \end_inset
20038 </cell>
20039 </row>
20040 <row bottomline="true">
20041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20042 \begin_inset Text
20043
20044 \begin_layout Standard
20045 string speed
20046 \begin_inset Foot
20047 status collapsed
20048
20049 \begin_layout Standard
20050 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20051 \backslash
20052 r', '
20053 \backslash
20054 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20055 \end_layout
20056
20057 \end_inset
20058
20059 ,
20060 \end_layout
20061
20062 \begin_layout Standard
20063 small / large
20064 \end_layout
20065
20066 \end_inset
20067 </cell>
20068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20069 \begin_inset Text
20070
20071 \begin_layout Standard
20072 1.52 / 2.59 ms
20073 \end_layout
20074
20075 \end_inset
20076 </cell>
20077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20078 \begin_inset Text
20079
20080 \begin_layout Standard
20081 1.53 / 2.62 ms
20082 \end_layout
20083
20084 \end_inset
20085 </cell>
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20087 \begin_inset Text
20088
20089 \begin_layout Standard
20090 0.92 / 0.93 ms
20091 \end_layout
20092
20093 \end_inset
20094 </cell>
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20096 \begin_inset Text
20097
20098 \begin_layout Standard
20099 0.45 / 0.45 ms
20100 \end_layout
20101
20102 \end_inset
20103 </cell>
20104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20105 \begin_inset Text
20106
20107 \begin_layout Standard
20108 0.46 / 0.46 ms
20109 \end_layout
20110
20111 \end_inset
20112 </cell>
20113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20114 \begin_inset Text
20115
20116 \begin_layout Standard
20117 0.45 / 0.45 ms
20118 \end_layout
20119
20120 \end_inset
20121 </cell>
20122 </row>
20123 <row bottomline="true">
20124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20125 \begin_inset Text
20126
20127 \begin_layout Standard
20128 int speed
20129 \begin_inset Foot
20130 status collapsed
20131
20132 \begin_layout Standard
20133 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20134  putchar()
20135 \end_layout
20136
20137 \end_inset
20138
20139 ,
20140 \end_layout
20141
20142 \begin_layout Standard
20143 small / large
20144 \end_layout
20145
20146 \end_inset
20147 </cell>
20148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20149 \begin_inset Text
20150
20151 \begin_layout Standard
20152 3.01 / 3.61 ms
20153 \end_layout
20154
20155 \end_inset
20156 </cell>
20157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20158 \begin_inset Text
20159
20160 \begin_layout Standard
20161 3.01 / 3.61 ms
20162 \end_layout
20163
20164 \end_inset
20165 </cell>
20166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20167 \begin_inset Text
20168
20169 \begin_layout Standard
20170 3.51 / 18.13 ms
20171 \end_layout
20172
20173 \end_inset
20174 </cell>
20175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20176 \begin_inset Text
20177
20178 \begin_layout Standard
20179 0.22 / 0.22 ms
20180 \end_layout
20181
20182 \end_inset
20183 </cell>
20184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20185 \begin_inset Text
20186
20187 \begin_layout Standard
20188 0.23 / 0.23 ms
20189 \end_layout
20190
20191 \end_inset
20192 </cell>
20193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20194 \begin_inset Text
20195
20196 \begin_layout Standard
20197 0.25 / 0.25 ms
20198 \begin_inset Foot
20199 status collapsed
20200
20201 \begin_layout Standard
20202 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20203 \end_layout
20204
20205 \end_inset
20206
20207
20208 \end_layout
20209
20210 \end_inset
20211 </cell>
20212 </row>
20213 <row bottomline="true">
20214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20215 \begin_inset Text
20216
20217 \begin_layout Standard
20218 long speed
20219 \begin_inset Foot
20220 status collapsed
20221
20222 \begin_layout Standard
20223 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20224  empty putchar()
20225 \end_layout
20226
20227 \end_inset
20228
20229 ,
20230 \end_layout
20231
20232 \begin_layout Standard
20233 small / large
20234 \end_layout
20235
20236 \end_inset
20237 </cell>
20238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20239 \begin_inset Text
20240
20241 \begin_layout Standard
20242 5.37 / 6.31 ms
20243 \end_layout
20244
20245 \end_inset
20246 </cell>
20247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20248 \begin_inset Text
20249
20250 \begin_layout Standard
20251 5.37 / 6.31 ms
20252 \end_layout
20253
20254 \end_inset
20255 </cell>
20256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20257 \begin_inset Text
20258
20259 \begin_layout Standard
20260 8.71 / 40.65 ms
20261 \end_layout
20262
20263 \end_inset
20264 </cell>
20265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20266 \begin_inset Text
20267
20268 \begin_layout Standard
20269 0.40 / 0.40 ms
20270 \end_layout
20271
20272 \end_inset
20273 </cell>
20274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20275 \begin_inset Text
20276
20277 \begin_layout Standard
20278 0.40 / 0.40 ms
20279 \end_layout
20280
20281 \end_inset
20282 </cell>
20283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20284 \begin_inset Text
20285
20286 \begin_layout Standard
20287 -
20288 \end_layout
20289
20290 \end_inset
20291 </cell>
20292 </row>
20293 <row bottomline="true">
20294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20295 \begin_inset Text
20296
20297 \begin_layout Standard
20298 float speed
20299 \begin_inset Foot
20300 status collapsed
20301
20302 \begin_layout Standard
20303 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20304  empty putchar()
20305 \end_layout
20306
20307 \end_inset
20308
20309 ,
20310 \end_layout
20311
20312 \begin_layout Standard
20313 small / large
20314 \end_layout
20315
20316 \end_inset
20317 </cell>
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20319 \begin_inset Text
20320
20321 \begin_layout Standard
20322 -
20323 \end_layout
20324
20325 \end_inset
20326 </cell>
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20328 \begin_inset Text
20329
20330 \begin_layout Standard
20331 7.49 / 22.47 ms
20332 \end_layout
20333
20334 \end_inset
20335 </cell>
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20337 \begin_inset Text
20338
20339 \begin_layout Standard
20340 -
20341 \end_layout
20342
20343 \end_inset
20344 </cell>
20345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20346 \begin_inset Text
20347
20348 \begin_layout Standard
20349 -
20350 \end_layout
20351
20352 \end_inset
20353 </cell>
20354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20355 \begin_inset Text
20356
20357 \begin_layout Standard
20358 1.04 / 1.04 ms
20359 \end_layout
20360
20361 \end_inset
20362 </cell>
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20364 \begin_inset Text
20365
20366 \begin_layout Standard
20367 -
20368 \end_layout
20369
20370 \end_inset
20371 </cell>
20372 </row>
20373 </lyxtabular>
20374
20375 \end_inset
20376
20377
20378 \end_layout
20379
20380 \begin_layout Subsubsection
20381 <malloc.h>
20382 \begin_inset LatexCommand \index{malloc.h}
20383
20384 \end_inset
20385
20386
20387 \end_layout
20388
20389 \begin_layout Standard
20390 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20391  using dynamic memory allocation
20392 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20393
20394 \end_inset
20395
20396  and a default heap
20397 \begin_inset LatexCommand \index{heap (malloc)}
20398
20399 \end_inset
20400
20401  space of 1024 bytes is provided for malloc to allocate memory from.
20402  If you need a different heap size you need to recompile _heap.c with the
20403  required size defined in HEAP_SIZE.
20404  It is recommended to make a copy of this file into your project directory
20405  and compile it there with:
20406 \end_layout
20407
20408 \begin_layout Verse
20409
20410 \family typewriter
20411 sdcc -c _heap.c -D HEAD_SIZE=2048
20412 \end_layout
20413
20414 \begin_layout Standard
20415 And then link it with:
20416 \end_layout
20417
20418 \begin_layout Verse
20419
20420 \family typewriter
20421 sdcc main.rel _heap.rel
20422 \end_layout
20423
20424 \begin_layout Subsection
20425 Math functions (sinf, powf, sqrtf etc.)
20426 \end_layout
20427
20428 \begin_layout Subsubsection
20429 <math.h>
20430 \end_layout
20431
20432 \begin_layout Standard
20433 See definitions in file <math.h>.
20434 \end_layout
20435
20436 \begin_layout Subsection
20437 Other libraries
20438 \end_layout
20439
20440 \begin_layout Standard
20441 Libraries
20442 \begin_inset LatexCommand \index{Libraries}
20443
20444 \end_inset
20445
20446  included in SDCC should have a license at least as liberal as the GNU Lesser
20447  General Public License
20448 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20449
20450 \end_inset
20451
20452  
20453 \emph on
20454 LGPL
20455 \emph default
20456 .
20457 \end_layout
20458
20459 \begin_layout Standard
20460 \begin_inset Note Note
20461 status collapsed
20462
20463 \begin_layout Standard
20464 license statements for the libraries are missing.
20465  sdcc/device/lib/ser_ir.c
20466 \end_layout
20467
20468 \begin_layout Standard
20469 or _decdptr f.e.
20470  come with a GPL (as opposed to LGPL) License - this will not be liberal
20471  enough for many embedded programmers.
20472 \end_layout
20473
20474 \end_inset
20475
20476
20477 \end_layout
20478
20479 \begin_layout Standard
20480 If you have ported some library or want to share experience about some code
20481  which f.e.
20482  falls into any of these categories Busses (I
20483 \begin_inset Formula $^{\textrm{2}}$
20484 \end_inset
20485
20486 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20487  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20488  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20489 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20490
20491 \end_inset
20492
20493 \InsetSpace ~
20494 would certainly like to hear about it.
20495 \end_layout
20496
20497 \begin_layout Standard
20498 Programmers coding for embedded systems are not especially famous for being
20499  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20500 e these references are very valuable.
20501  Let's help to create a climate where information is shared.
20502 \begin_inset VSpace bigskip
20503 \end_inset
20504
20505
20506 \end_layout
20507
20508 \begin_layout Section
20509 Memory Models
20510 \end_layout
20511
20512 \begin_layout Subsection
20513 MCS51 Memory Models
20514 \begin_inset LatexCommand \index{Memory model}
20515
20516 \end_inset
20517
20518
20519 \begin_inset LatexCommand \index{MCS51 memory model}
20520
20521 \end_inset
20522
20523
20524 \end_layout
20525
20526 \begin_layout Subsubsection
20527 Small, Medium and Large
20528 \end_layout
20529
20530 \begin_layout Standard
20531 SDCC allows three memory models for MCS51 code, 
20532 \shape slanted
20533 small, medium
20534 \shape default
20535  and 
20536 \shape slanted
20537 large
20538 \shape default
20539 .
20540  Modules compiled with different memory models should 
20541 \emph on
20542 never
20543 \emph default
20544  be combined together or the results would be unpredictable.
20545  The library routines supplied with the compiler are compiled as small,
20546  medium and large.
20547  The compiled library modules are contained in separate directories as small,
20548  medium and large so that you can link to the appropriate set.
20549 \end_layout
20550
20551 \begin_layout Standard
20552 When the medium or large model is used all variables declared without a
20553  storage class will be allocated into the external ram, this includes all
20554  parameters and local variables (for non-reentrant
20555 \begin_inset LatexCommand \index{reentrant}
20556
20557 \end_inset
20558
20559  functions).
20560  When the small model is used variables without storage class are allocated
20561  in the internal ram.
20562 \end_layout
20563
20564 \begin_layout Standard
20565 Judicious usage of the processor specific storage classes
20566 \begin_inset LatexCommand \index{Storage class}
20567
20568 \end_inset
20569
20570  and the 'reentrant' function type will yield much more efficient code,
20571  than using the large model.
20572  Several optimizations are disabled when the program is compiled using the
20573  large model, it is therefore recommended that the small model be used unless
20574  absolutely required.
20575 \end_layout
20576
20577 \begin_layout Subsubsection
20578 External Stack
20579 \begin_inset LatexCommand \label{sub:External-Stack}
20580
20581 \end_inset
20582
20583
20584 \begin_inset LatexCommand \index{stack}
20585
20586 \end_inset
20587
20588
20589 \begin_inset LatexCommand \index{External stack (mcs51)}
20590
20591 \end_inset
20592
20593
20594 \end_layout
20595
20596 \begin_layout Standard
20597 The external stack (-
20598 \begin_inset ERT
20599 status collapsed
20600
20601 \begin_layout Standard
20602
20603
20604 \backslash
20605 /
20606 \end_layout
20607
20608 \end_inset
20609
20610 -xstack option
20611 \begin_inset LatexCommand \index{-\/-xstack}
20612
20613 \end_inset
20614
20615 ) is located in pdata
20616 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20617
20618 \end_inset
20619
20620  memory (usually at the start of the external ram segment) and uses all
20621  unused space in pdata (max.
20622  256 bytes).
20623  When -
20624 \begin_inset ERT
20625 status collapsed
20626
20627 \begin_layout Standard
20628
20629
20630 \backslash
20631 /
20632 \end_layout
20633
20634 \end_inset
20635
20636 -xstack option is used to compile the program, the parameters and local
20637  variables
20638 \begin_inset LatexCommand \index{local variables}
20639
20640 \end_inset
20641
20642  of all reentrant functions are allocated in this area.
20643  This option is provided for programs with large stack space requirements.
20644  When used with the -
20645 \begin_inset ERT
20646 status collapsed
20647
20648 \begin_layout Standard
20649
20650
20651 \backslash
20652 /
20653 \end_layout
20654
20655 \end_inset
20656
20657 -stack-auto
20658 \begin_inset LatexCommand \index{-\/-stack-auto}
20659
20660 \end_inset
20661
20662  option, all parameters and local variables are allocated on the external
20663  stack (note: support libraries will need to be recompiled with the same
20664  options.
20665  There is a predefined target in the library makefile).
20666 \end_layout
20667
20668 \begin_layout Standard
20669 The compiler outputs the higher order address byte of the external ram segment
20670  into port P2
20671 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20672
20673 \end_inset
20674
20675  (see also section 
20676 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20677
20678 \end_inset
20679
20680 ), therefore when using the External Stack option, this port 
20681 \emph on
20682 may not
20683 \emph default
20684  be used by the application program.
20685 \end_layout
20686
20687 \begin_layout Subsection
20688 DS390 Memory Model
20689 \begin_inset LatexCommand \index{Memory model}
20690
20691 \end_inset
20692
20693
20694 \begin_inset LatexCommand \index{DS390 memory model}
20695
20696 \end_inset
20697
20698
20699 \end_layout
20700
20701 \begin_layout Standard
20702 The only model supported is Flat 24
20703 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20704
20705 \end_inset
20706
20707 .
20708  This generates code for the 24 bit contiguous addressing mode of the Dallas
20709  DS80C390 part.
20710  In this mode, up to four meg of external RAM or code space can be directly
20711  addressed.
20712  See the data sheets at www.dalsemi.com for further information on this part.
20713 \newline
20714
20715 \newline
20716 Note
20717  that the compiler does not generate any code to place the processor into
20718  24 bitmode (although 
20719 \emph on
20720 tinibios
20721 \emph default
20722  in the ds390 libraries will do that for you).
20723  If you don't use 
20724 \emph on
20725 tinibios
20726 \emph default
20727
20728 \begin_inset LatexCommand \index{Tinibios (DS390)}
20729
20730 \end_inset
20731
20732 , the boot loader or similar code must ensure that the processor is in 24
20733  bit contiguous addressing mode before calling the SDCC startup code.
20734 \newline
20735
20736 \newline
20737 Like
20738  the 
20739 \emph on
20740 -
20741 \begin_inset ERT
20742 status collapsed
20743
20744 \begin_layout Standard
20745
20746
20747 \backslash
20748 /
20749 \end_layout
20750
20751 \end_inset
20752
20753 -model-large
20754 \emph default
20755  option, variables will by default be placed into the XDATA segment.
20756  
20757 \newline
20758
20759 \newline
20760 Segments may be placed anywhere in the 4 meg address space using the usual
20761  -
20762 \begin_inset ERT
20763 status collapsed
20764
20765 \begin_layout Standard
20766
20767
20768 \backslash
20769 /
20770 \end_layout
20771
20772 \end_inset
20773
20774 -*-loc options.
20775  Note that if any segments are located above 64K, the -r flag must be passed
20776  to the linker to generate the proper segment relocations, and the Intel
20777  HEX output format must be used.
20778  The -r flag can be passed to the linker by using the option 
20779 \emph on
20780 -Wl-r
20781 \emph default
20782  on the SDCC command line.
20783  However, currently the linker can not handle code segments > 64k.
20784 \end_layout
20785
20786 \begin_layout Section
20787 Pragmas
20788 \begin_inset LatexCommand \label{sec:Pragmas}
20789
20790 \end_inset
20791
20792
20793 \begin_inset LatexCommand \index{Pragmas}
20794
20795 \end_inset
20796
20797
20798 \end_layout
20799
20800 \begin_layout Standard
20801 Pragmas are used to turn on and/or off certain compiler options.
20802  Some of them are closely related to corresponding command-line options
20803  (see section 
20804 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20805
20806 \end_inset
20807
20808 ).
20809 \newline
20810 Pragmas should be placed before and/or after a function, placing pragmas
20811  inside a function body could have unpredictable results.
20812 \newline
20813
20814 \newline
20815 SDCC supports the
20816  following #pragma directives:
20817 \end_layout
20818
20819 \begin_layout Itemize
20820
20821 \series bold
20822 save
20823 \series default
20824
20825 \begin_inset LatexCommand \index{\#pragma save}
20826
20827 \end_inset
20828
20829  - this will save most current options to the save/restore stack.
20830  See #pragma\InsetSpace ~
20831 restore.
20832 \end_layout
20833
20834 \begin_layout Itemize
20835
20836 \series bold
20837 restore
20838 \series default
20839
20840 \begin_inset LatexCommand \index{\#pragma restore}
20841
20842 \end_inset
20843
20844  - will restore saved options from the last save.
20845  saves & restores can be nested.
20846  SDCC uses a save/restore stack: save pushes current options to the stack,
20847  restore pulls current options from the stack.
20848  See #pragma\InsetSpace ~
20849 save.
20850 \newline
20851
20852 \end_layout
20853
20854 \begin_layout Itemize
20855
20856 \series bold
20857 callee_saves
20858 \series default
20859
20860 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20861
20862 \end_inset
20863
20864
20865 \begin_inset LatexCommand \index{function prologue}
20866
20867 \end_inset
20868
20869  function1[,function2[,function3...]] 
20870 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20871
20872 \end_inset
20873
20874 - The compiler by default uses a caller saves convention for register saving
20875  across function calls, however this can cause unnecessary register pushing
20876  and popping
20877 \begin_inset LatexCommand \index{push/pop}
20878
20879 \end_inset
20880
20881  when calling small functions from larger functions.
20882  This option can be used to switch off the register saving convention for
20883  the function names specified.
20884  The compiler will not save registers when calling these functions, extra
20885  code need to be manually inserted at the entry and exit for these functions
20886  to save and restore the registers used by these functions, this can SUBSTANTIAL
20887 LY reduce code and improve run time performance of the generated code.
20888  In the future the compiler (with inter procedural analysis) may be able
20889  to determine the appropriate scheme to use for each function call.
20890  If -
20891 \begin_inset ERT
20892 status collapsed
20893
20894 \begin_layout Standard
20895
20896
20897 \backslash
20898 /
20899 \end_layout
20900
20901 \end_inset
20902
20903 -callee-saves command line option is used (see page 
20904 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20905
20906 \end_inset
20907
20908 ), the function names specified in #pragma\InsetSpace ~
20909 callee_saves
20910 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20911
20912 \end_inset
20913
20914  is appended to the list of functions specified in the command line.
20915 \end_layout
20916
20917 \begin_layout Itemize
20918
20919 \series bold
20920 exclude
20921 \series default
20922
20923 \begin_inset LatexCommand \index{\#pragma exclude}
20924
20925 \end_inset
20926
20927  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20928  of pairs of push/pop
20929 \begin_inset LatexCommand \index{push/pop}
20930
20931 \end_inset
20932
20933  instructions in 
20934 \emph on
20935 I
20936 \emph default
20937 nterrupt
20938 \begin_inset LatexCommand \index{interrupt}
20939
20940 \end_inset
20941
20942  
20943 \emph on
20944 S
20945 \emph default
20946 ervice 
20947 \emph on
20948 R
20949 \emph default
20950 outines.
20951  The directive should be placed immediately before the ISR function definition
20952  and it affects ALL ISR functions following it.
20953  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20954 exclude\InsetSpace ~
20955 none
20956 \begin_inset LatexCommand \index{\#pragma exclude}
20957
20958 \end_inset
20959
20960 .
20961  See also the related keyword _naked
20962 \begin_inset LatexCommand \index{\_naked}
20963
20964 \end_inset
20965
20966
20967 \begin_inset LatexCommand \index{\_\_naked}
20968
20969 \end_inset
20970
20971 .
20972 \end_layout
20973
20974 \begin_layout Itemize
20975
20976 \series bold
20977 less_pedantic
20978 \series default
20979
20980 \begin_inset LatexCommand \index{pedantic}
20981
20982 \end_inset
20983
20984
20985 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
20986
20987 \end_inset
20988
20989  
20990 \begin_inset LatexCommand \label{ite:less_pedantic}
20991
20992 \end_inset
20993
20994 - the compiler will not warn you anymore for obvious mistakes, you'r on
20995  your own now ;-( .
20996  See also the command line option -
20997 \begin_inset ERT
20998 status collapsed
20999
21000 \begin_layout Standard
21001
21002
21003 \backslash
21004 /
21005 \end_layout
21006
21007 \end_inset
21008
21009 -less-pedantic 
21010 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21011
21012 \end_inset
21013
21014 .
21015  
21016 \newline
21017 More specifically, the following warnings will be disabled: 
21018 \shape italic
21019 comparison is always [true/false] due to limited range of data type
21020 \shape default
21021  (94); 
21022 \shape italic
21023 overflow in implicit constant conversion
21024 \shape default
21025  (158); [the (in)famous] 
21026 \shape italic
21027 conditional flow changed by optimizer: so said EVELYN the modified DOG
21028 \shape default
21029  (110); 
21030 \shape italic
21031 function '[function name]' must return value
21032 \shape default
21033  (59).
21034  
21035 \newline
21036 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21037  level) are disabled, too, namely: 
21038 \shape italic
21039 constant value '[
21040 \begin_inset Note Note
21041 status collapsed
21042
21043 \begin_layout Standard
21044 dunno what comes here - this warning appears to be unused altogether
21045 \end_layout
21046
21047 \end_inset
21048
21049 ]', out of range
21050 \shape default
21051  (81); 
21052 \shape italic
21053 [left/right] shifting more than size of object changed to zero
21054 \shape default
21055  (116); 
21056 \shape italic
21057 unreachable code
21058 \shape default
21059  (126); 
21060 \shape italic
21061 integer overflow in expression
21062 \shape default
21063  (165); 
21064 \shape italic
21065 unmatched #pragma save and #pragma restore
21066 \shape default
21067  (170); 
21068 \shape italic
21069 comparison of 'signed char' with 'unsigned char' requires promotion to int
21070 \shape default
21071  (185); 
21072 \shape italic
21073 ISO C90 does not support flexible array members
21074 \shape default
21075  (187); 
21076 \shape italic
21077 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21078 nam
21079 e]':\InsetSpace ~
21080 [
21081 \begin_inset Note Note
21082 status collapsed
21083
21084 \begin_layout Standard
21085 appears to be always blank - what was supposed to be here?
21086 \end_layout
21087
21088 \end_inset
21089
21090 ]
21091 \shape default
21092  (114); 
21093 \shape italic
21094 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21095  complexity [number]
21096 \shape default
21097  (121).
21098 \end_layout
21099
21100 \begin_layout Itemize
21101
21102 \series bold
21103 disable_warning
21104 \series default
21105  <nnnn>
21106 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21107
21108 \end_inset
21109
21110  - the compiler will not warn you anymore about warning number <nnnn>.
21111  
21112 \begin_inset Note Note
21113 status open
21114
21115 \begin_layout Itemize
21116 \begin_inset Quotes sld
21117 \end_inset
21118
21119 For list of warnings and corresponding codes, see err_warn.txt
21120 \begin_inset Quotes srd
21121 \end_inset
21122
21123  This list should probably be part of the manual? See Patch #1697136 
21124 \end_layout
21125
21126 \end_inset
21127
21128 .
21129 \end_layout
21130
21131 \begin_layout Itemize
21132
21133 \series bold
21134 nogcse
21135 \series default
21136
21137 \begin_inset LatexCommand \index{\#pragma nogcse}
21138
21139 \end_inset
21140
21141  - will stop global common subexpression elimination.
21142 \end_layout
21143
21144 \begin_layout Itemize
21145
21146 \series bold
21147 noinduction
21148 \series default
21149
21150 \begin_inset LatexCommand \index{\#pragma noinduction}
21151
21152 \end_inset
21153
21154  - will stop loop induction optimizations.
21155 \end_layout
21156
21157 \begin_layout Itemize
21158
21159 \series bold
21160 noinvariant
21161 \series default
21162
21163 \begin_inset LatexCommand \index{\#pragma noinvariant}
21164
21165 \end_inset
21166
21167  - will not do loop invariant optimizations.
21168  For more details see Loop Invariants in section
21169 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21170
21171 \end_inset
21172
21173 .
21174 \end_layout
21175
21176 \begin_layout Itemize
21177
21178 \series bold
21179 noiv
21180 \series default
21181
21182 \begin_inset LatexCommand \index{\#pragma noiv}
21183
21184 \end_inset
21185
21186  - Do not generate interrupt
21187 \begin_inset LatexCommand \index{interrupt}
21188
21189 \end_inset
21190
21191  vector table
21192 \begin_inset LatexCommand \index{interrupt vector table}
21193
21194 \end_inset
21195
21196  entries for all ISR functions defined after the pragma.
21197  This is useful in cases where the interrupt vector table must be defined
21198  manually, or when there is a secondary, manually defined interrupt vector
21199  table (e.g.
21200  for the autovector feature of the Cypress EZ-USB FX2).
21201  More elegantly this can be achieved by obmitting the optional interrupt
21202  number after the interrupt keyword, see section 
21203 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21204
21205 \end_inset
21206
21207 \InsetSpace ~
21208 about interrupts.
21209 \end_layout
21210
21211 \begin_layout Itemize
21212
21213 \series bold
21214 nojtbound
21215 \series default
21216
21217 \begin_inset LatexCommand \index{\#pragma nojtbound}
21218
21219 \end_inset
21220
21221  - will not generate code for boundary value checking, when switch statements
21222  are turned into jump-tables (dangerous).
21223  For more details see section 
21224 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21225
21226 \end_inset
21227
21228 .
21229 \end_layout
21230
21231 \begin_layout Itemize
21232
21233 \series bold
21234 noloopreverse
21235 \series default
21236
21237 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21238
21239 \end_inset
21240
21241  - Will not do loop reversal optimization
21242 \end_layout
21243
21244 \begin_layout Itemize
21245
21246 \series bold
21247 nooverlay
21248 \series default
21249
21250 \begin_inset LatexCommand \index{\#pragma nooverlay}
21251
21252 \end_inset
21253
21254  - the compiler will not overlay the parameters and local variables of a
21255  function.
21256 \end_layout
21257
21258 \begin_layout Itemize
21259
21260 \series bold
21261 stackauto
21262 \series default
21263
21264 \begin_inset LatexCommand \index{\#pragma stackauto}
21265
21266 \end_inset
21267
21268 - See option -
21269 \begin_inset ERT
21270 status collapsed
21271
21272 \begin_layout Standard
21273
21274
21275 \backslash
21276 /
21277 \end_layout
21278
21279 \end_inset
21280
21281 -stack-auto
21282 \begin_inset LatexCommand \index{-\/-stack-auto}
21283
21284 \end_inset
21285
21286  and section 
21287 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21288
21289 \end_inset
21290
21291  Parameters and Local Variables.
21292 \end_layout
21293
21294 \begin_layout Itemize
21295
21296 \series bold
21297 opt_code_speed
21298 \series default
21299  
21300 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21301
21302 \end_inset
21303
21304 - The compiler will optimize code generation towards fast code, possibly
21305  at the expense of code size.
21306  Currently this has little effect.
21307 \end_layout
21308
21309 \begin_layout Itemize
21310
21311 \series bold
21312 opt_code_size
21313 \series default
21314  
21315 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21316
21317 \end_inset
21318
21319 - The compiler will optimize code generation towards compact code, possibly
21320  at the expense of code speed.
21321  Currently this has little effect.
21322 \end_layout
21323
21324 \begin_layout Itemize
21325
21326 \series bold
21327 opt_code_balanced
21328 \series default
21329  
21330 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21331
21332 \end_inset
21333
21334 - The compiler will attempt to generate code that is both compact and fast,
21335  as long as meeting one goal is not a detriment to the other (this is the
21336  default).
21337  
21338 \end_layout
21339
21340 \begin_layout Itemize
21341
21342 \series bold
21343 std_sdcc89
21344 \series default
21345  
21346 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21347
21348 \end_inset
21349
21350 - Generally follow the C89 standard, but allow SDCC features that conflict
21351  with the standard (default).
21352 \end_layout
21353
21354 \begin_layout Itemize
21355
21356 \series bold
21357 std_c89
21358 \series default
21359  
21360 \begin_inset LatexCommand \index{\#pragma std\_c89}
21361
21362 \end_inset
21363
21364 - Follow the C89 standard and disable SDCC features that conflict with the
21365  standard.
21366 \end_layout
21367
21368 \begin_layout Itemize
21369
21370 \series bold
21371 std_sdcc99
21372 \series default
21373  
21374 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21375
21376 \end_inset
21377
21378 - Generally follow the C99 standard, but allow SDCC features that conflict
21379  with the standard (incomplete support).
21380 \end_layout
21381
21382 \begin_layout Itemize
21383
21384 \series bold
21385 std_c99
21386 \series default
21387  
21388 \begin_inset LatexCommand \index{\#pragma std\_c99}
21389
21390 \end_inset
21391
21392 - Follow the C99 standard and disable SDCC features that conflict with the
21393  standard (incomplete support).
21394 \end_layout
21395
21396 \begin_layout Itemize
21397
21398 \series bold
21399 codeseg
21400 \series default
21401  <name>
21402 \begin_inset LatexCommand \index{\#pragma codeseg}
21403
21404 \end_inset
21405
21406 - Use this name (max.
21407  8 characters) for the code segment.
21408  See option -
21409 \begin_inset ERT
21410 status collapsed
21411
21412 \begin_layout Standard
21413
21414
21415 \backslash
21416 /
21417 \end_layout
21418
21419 \end_inset
21420
21421 -codeseg.
21422 \end_layout
21423
21424 \begin_layout Itemize
21425
21426 \series bold
21427 constseg
21428 \series default
21429  <name>
21430 \begin_inset LatexCommand \index{\#pragma constseg}
21431
21432 \end_inset
21433
21434 - Use this name (max.
21435  8 characters) for the const segment.
21436  See option -
21437 \begin_inset ERT
21438 status collapsed
21439
21440 \begin_layout Standard
21441
21442
21443 \backslash
21444 /
21445 \end_layout
21446
21447 \end_inset
21448
21449 -constseg.
21450 \end_layout
21451
21452 \begin_layout Standard
21453 The preprocessor SDCPP
21454 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21455
21456 \end_inset
21457
21458  supports the following #pragma directives:
21459 \end_layout
21460
21461 \begin_layout Itemize
21462
21463 \series bold
21464 pedantic_parse_number
21465 \series default
21466
21467 \begin_inset LatexCommand \index{pedantic}
21468
21469 \end_inset
21470
21471
21472 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21473
21474 \end_inset
21475
21476  (+ | -) 
21477 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21478
21479 \end_inset
21480
21481 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21482  properly and the macro LO_B(3) gets expanded.
21483  Default is off.
21484  See also the -
21485 \begin_inset ERT
21486 status collapsed
21487
21488 \begin_layout Standard
21489
21490
21491 \backslash
21492 /
21493 \end_layout
21494
21495 \end_inset
21496
21497 -pedantic-parse-number command line option 
21498 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21499
21500 \end_inset
21501
21502 .
21503  
21504 \newline
21505 Below is an example on how to use this pragma.
21506
21507 \emph on
21508  Note: this functionality is not in conformance with standard!
21509 \end_layout
21510
21511 \begin_layout Verse
21512
21513 \family typewriter
21514 #pragma pedantic_parse_number +
21515 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21516
21517 \end_inset
21518
21519
21520 \newline
21521
21522 \newline
21523 #define LO_B(x) ((x) & 0xff)
21524 \newline
21525
21526 \newline
21527 unsigned char foo(void)
21528 \newline
21529 {
21530 \newline
21531 \InsetSpace ~
21532 \InsetSpace ~
21533 \InsetSpace ~
21534 unsigned char c=0xfe-LO_B(3)
21535 ;
21536 \newline
21537
21538 \newline
21539 \InsetSpace ~
21540 \InsetSpace ~
21541 \InsetSpace ~
21542 return c;
21543 \newline
21544 }
21545 \newline
21546
21547 \end_layout
21548
21549 \begin_layout Itemize
21550
21551 \series bold
21552 preproc_asm
21553 \series default
21554
21555 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21556
21557 \end_inset
21558
21559  (+ | -) - switch _asm _endasm block preprocessing on / off.
21560  Default is on.
21561  You use this prama to define multilines of assembly code.
21562  This will prevent the preprocessor from changing the formating required
21563  by assembly code.
21564  Below is an example on how to use this pragma.
21565 \end_layout
21566
21567 \begin_layout Verse
21568
21569 \family typewriter
21570 #pragma preproc_asm -
21571 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21572
21573 \end_inset
21574
21575
21576 \newline
21577 #define MYDELAY _asm
21578 \newline
21579 \InsetSpace ~
21580 \InsetSpace ~
21581 \InsetSpace ~
21582 nop ;my assembly comment...
21583 \newline
21584 \InsetSpace ~
21585 \InsetSpace ~
21586 \InsetSpace ~
21587 nop
21588 \newline
21589 \InsetSpace ~
21590 \InsetSpace ~
21591 \InsetSpace ~
21592 nop
21593 \newline
21594 _endasm
21595 \newline
21596 #pragma preproc_asm
21597  +
21598 \newline
21599
21600 \newline
21601 void foo (void) 
21602 \newline
21603
21604 \newline
21605 \InsetSpace ~
21606 \InsetSpace ~
21607 \InsetSpace ~
21608  ...
21609  
21610 \newline
21611 \InsetSpace ~
21612 \InsetSpace ~
21613 \InsetSpace ~
21614  MYDELAY;
21615 \newline
21616 \InsetSpace ~
21617 \InsetSpace ~
21618 \InsetSpace ~
21619  ...
21620  
21621 \newline
21622
21623 \newline
21624
21625 \end_layout
21626
21627 \begin_layout Itemize
21628
21629 \series bold
21630 sdcc_hash
21631 \series default
21632
21633 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21634
21635 \end_inset
21636
21637  (+ | -) - Allow "naked" hash in macro definition, for example:
21638 \newline
21639
21640 \family typewriter
21641 #define DIR_LO(x) #(x & 0xff)
21642 \family default
21643
21644 \newline
21645 Default is off.
21646  Below is an example on how to use this pragma.
21647 \end_layout
21648
21649 \begin_layout Verse
21650
21651 \family typewriter
21652 #pragma preproc_asm +
21653 \newline
21654 #pragma sdcc_hash +
21655 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21656
21657 \end_inset
21658
21659
21660 \newline
21661
21662 \newline
21663 #define ROMCALL(x) 
21664 \backslash
21665
21666 \newline
21667 \InsetSpace ~
21668 \InsetSpace ~
21669 \InsetSpace ~
21670 mov R6_B3, #(x & 0xff) 
21671 \backslash
21672
21673 \newline
21674 \InsetSpace ~
21675 \InsetSpace ~
21676 \InsetSpace ~
21677 mov R7_B3, #((x >> 8) & 0xff) 
21678 \backslash
21679
21680 \newline
21681 \InsetSpace ~
21682 \InsetSpace ~
21683 \InsetSpace ~
21684 lcall __romcall
21685 \newline
21686
21687 \newline
21688 ...
21689 \newline
21690 _asm
21691 \newline
21692 ROMCALL(72)
21693 \newline
21694 _endasm;
21695 \newline
21696 ...
21697 \newline
21698
21699 \end_layout
21700
21701 \begin_layout Standard
21702 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21703 ons which might cause the compiler to generate extra stack and/or data space
21704  to store compiler generated temporary variables.
21705  This usually happens in large functions.
21706  Pragma directives should be used as shown in the following example, they
21707  are used to control options and optimizations for a given function.
21708  
21709 \end_layout
21710
21711 \begin_layout Verse
21712
21713 \family typewriter
21714 #pragma save
21715 \begin_inset LatexCommand \index{\#pragma save}
21716
21717 \end_inset
21718
21719  \InsetSpace ~
21720 \InsetSpace ~
21721 \InsetSpace ~
21722 \InsetSpace ~
21723 \InsetSpace ~
21724 \InsetSpace ~
21725 \InsetSpace ~
21726 /* save the current settings */ 
21727 \newline
21728 #pragma nogcse
21729 \begin_inset LatexCommand \index{\#pragma nogcse}
21730
21731 \end_inset
21732
21733  \InsetSpace ~
21734 \InsetSpace ~
21735 \InsetSpace ~
21736 \InsetSpace ~
21737 \InsetSpace ~
21738 /* turnoff global subexpression elimination */ 
21739 \newline
21740 #pragma noinduction
21741 \begin_inset LatexCommand \index{\#pragma noinduction}
21742
21743 \end_inset
21744
21745  /* turn off induction optimizations */ 
21746 \newline
21747 int foo () 
21748 \newline
21749
21750 \newline
21751 \InsetSpace ~
21752  \InsetSpace ~
21753  ...
21754  
21755 \newline
21756 \InsetSpace ~
21757  \InsetSpace ~
21758  /* large code */ 
21759 \newline
21760 \InsetSpace ~
21761  \InsetSpace ~
21762  ...
21763  
21764 \newline
21765
21766 \newline
21767 #pragma restore
21768 \begin_inset LatexCommand \index{\#pragma restore}
21769
21770 \end_inset
21771
21772  /* turn the optimizations back on */
21773 \end_layout
21774
21775 \begin_layout Standard
21776 The compiler will generate a warning message when extra space is allocated.
21777  It is strongly recommended that the save and restore pragma's be used when
21778  changing options for a function.
21779 \newline
21780
21781 \newline
21782
21783 \newline
21784
21785 \end_layout
21786
21787 \begin_layout Section
21788 Defines Created by the Compiler
21789 \end_layout
21790
21791 \begin_layout Standard
21792 The compiler creates the following #defines
21793 \begin_inset LatexCommand \index{\#defines}
21794
21795 \end_inset
21796
21797
21798 \begin_inset LatexCommand \index{Defines created by the compiler}
21799
21800 \end_inset
21801
21802 :
21803 \newline
21804
21805 \end_layout
21806
21807 \begin_layout Standard
21808 \begin_inset Tabular
21809 <lyxtabular version="3" rows="11" columns="2">
21810 <features>
21811 <column alignment="left" valignment="top" leftline="true" width="3in">
21812 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21813 <row topline="true" bottomline="true">
21814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21815 \begin_inset Text
21816
21817 \begin_layout Standard
21818
21819 \series bold
21820 #define
21821 \end_layout
21822
21823 \end_inset
21824 </cell>
21825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21826 \begin_inset Text
21827
21828 \begin_layout Standard
21829
21830 \series bold
21831 Description
21832 \end_layout
21833
21834 \end_inset
21835 </cell>
21836 </row>
21837 <row topline="true">
21838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21839 \begin_inset Text
21840
21841 \begin_layout Standard
21842 SDCC
21843 \begin_inset LatexCommand \index{SDCC}
21844
21845 \end_inset
21846
21847  
21848 \end_layout
21849
21850 \end_inset
21851 </cell>
21852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21853 \begin_inset Text
21854
21855 \begin_layout Standard
21856 Always defined.
21857  Since version 2.5.6 the version number as an int (ex.
21858  256)
21859 \end_layout
21860
21861 \end_inset
21862 </cell>
21863 </row>
21864 <row topline="true">
21865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21866 \begin_inset Text
21867
21868 \begin_layout Standard
21869 SDCC_mcs51
21870 \begin_inset LatexCommand \index{SDCC\_mcs51}
21871
21872 \end_inset
21873
21874  or SDCC_ds390
21875 \begin_inset LatexCommand \index{SDCC\_ds390}
21876
21877 \end_inset
21878
21879  or SDCC_z80
21880 \begin_inset LatexCommand \index{SDCC\_z80}
21881
21882 \end_inset
21883
21884 , etc.
21885 \end_layout
21886
21887 \end_inset
21888 </cell>
21889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21890 \begin_inset Text
21891
21892 \begin_layout Standard
21893 depending on the model used (e.g.: -mds390)
21894 \end_layout
21895
21896 \end_inset
21897 </cell>
21898 </row>
21899 <row topline="true">
21900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21901 \begin_inset Text
21902
21903 \begin_layout Standard
21904 __mcs51
21905 \begin_inset LatexCommand \index{\_\_mcs51}
21906
21907 \end_inset
21908
21909 , __ds390
21910 \begin_inset LatexCommand \index{\_\_ds390}
21911
21912 \end_inset
21913
21914 , __hc08
21915 \begin_inset LatexCommand \index{\_\_hc08}
21916
21917 \end_inset
21918
21919 , __z80
21920 \begin_inset LatexCommand \index{\_\_z80}
21921
21922 \end_inset
21923
21924 , etc
21925 \end_layout
21926
21927 \end_inset
21928 </cell>
21929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21930 \begin_inset Text
21931
21932 \begin_layout Standard
21933 depending on the model used (e.g.
21934  -mz80)
21935 \end_layout
21936
21937 \end_inset
21938 </cell>
21939 </row>
21940 <row topline="true">
21941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21942 \begin_inset Text
21943
21944 \begin_layout Standard
21945 SDCC_STACK_AUTO
21946 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21947
21948 \end_inset
21949
21950
21951 \end_layout
21952
21953 \end_inset
21954 </cell>
21955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21956 \begin_inset Text
21957
21958 \begin_layout Standard
21959 when 
21960 \emph on
21961 -
21962 \begin_inset ERT
21963 status collapsed
21964
21965 \begin_layout Standard
21966
21967
21968 \backslash
21969 /
21970 \end_layout
21971
21972 \end_inset
21973
21974 -stack-auto
21975 \emph default
21976  option is used
21977 \end_layout
21978
21979 \end_inset
21980 </cell>
21981 </row>
21982 <row topline="true">
21983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21984 \begin_inset Text
21985
21986 \begin_layout Standard
21987 SDCC_MODEL_SMALL
21988 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
21989
21990 \end_inset
21991
21992
21993 \end_layout
21994
21995 \end_inset
21996 </cell>
21997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21998 \begin_inset Text
21999
22000 \begin_layout Standard
22001 when 
22002 \emph on
22003 -
22004 \begin_inset ERT
22005 status collapsed
22006
22007 \begin_layout Standard
22008
22009
22010 \backslash
22011 /
22012 \end_layout
22013
22014 \end_inset
22015
22016 -model-small
22017 \emph default
22018  is used
22019 \end_layout
22020
22021 \end_inset
22022 </cell>
22023 </row>
22024 <row topline="true">
22025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22026 \begin_inset Text
22027
22028 \begin_layout Standard
22029 SDCC_MODEL_MEDIUM
22030 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22031
22032 \end_inset
22033
22034
22035 \end_layout
22036
22037 \end_inset
22038 </cell>
22039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22040 \begin_inset Text
22041
22042 \begin_layout Standard
22043 when 
22044 \emph on
22045 -
22046 \begin_inset ERT
22047 status collapsed
22048
22049 \begin_layout Standard
22050
22051
22052 \backslash
22053 /
22054 \end_layout
22055
22056 \end_inset
22057
22058 -model-medium
22059 \emph default
22060  is used
22061 \end_layout
22062
22063 \end_inset
22064 </cell>
22065 </row>
22066 <row topline="true">
22067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22068 \begin_inset Text
22069
22070 \begin_layout Standard
22071 SDCC_MODEL_LARGE
22072 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22073
22074 \end_inset
22075
22076
22077 \end_layout
22078
22079 \end_inset
22080 </cell>
22081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22082 \begin_inset Text
22083
22084 \begin_layout Standard
22085 when 
22086 \emph on
22087 -
22088 \begin_inset ERT
22089 status collapsed
22090
22091 \begin_layout Standard
22092
22093
22094 \backslash
22095 /
22096 \end_layout
22097
22098 \end_inset
22099
22100 -model-large
22101 \emph default
22102  is used
22103 \end_layout
22104
22105 \end_inset
22106 </cell>
22107 </row>
22108 <row topline="true">
22109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22110 \begin_inset Text
22111
22112 \begin_layout Standard
22113 SDCC_USE_XSTACK
22114 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22115
22116 \end_inset
22117
22118
22119 \end_layout
22120
22121 \end_inset
22122 </cell>
22123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22124 \begin_inset Text
22125
22126 \begin_layout Standard
22127 when 
22128 \emph on
22129 -
22130 \begin_inset ERT
22131 status collapsed
22132
22133 \begin_layout Standard
22134
22135
22136 \backslash
22137 /
22138 \end_layout
22139
22140 \end_inset
22141
22142 -xstack
22143 \emph default
22144  option is used
22145 \end_layout
22146
22147 \end_inset
22148 </cell>
22149 </row>
22150 <row topline="true">
22151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22152 \begin_inset Text
22153
22154 \begin_layout Standard
22155 SDCC_STACK_TENBIT
22156 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22157
22158 \end_inset
22159
22160  
22161 \end_layout
22162
22163 \end_inset
22164 </cell>
22165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22166 \begin_inset Text
22167
22168 \begin_layout Standard
22169 when 
22170 \emph on
22171 -mds390
22172 \emph default
22173  is used
22174 \end_layout
22175
22176 \end_inset
22177 </cell>
22178 </row>
22179 <row topline="true" bottomline="true">
22180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22181 \begin_inset Text
22182
22183 \begin_layout Standard
22184 SDCC_MODEL_FLAT24
22185 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22186
22187 \end_inset
22188
22189
22190 \end_layout
22191
22192 \end_inset
22193 </cell>
22194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22195 \begin_inset Text
22196
22197 \begin_layout Standard
22198 when 
22199 \emph on
22200 -mds390
22201 \emph default
22202  is used
22203 \end_layout
22204
22205 \end_inset
22206 </cell>
22207 </row>
22208 </lyxtabular>
22209
22210 \end_inset
22211
22212
22213 \end_layout
22214
22215 \begin_layout Chapter
22216 Notes on supported Processors
22217 \end_layout
22218
22219 \begin_layout Section
22220 MCS51 variants
22221 \begin_inset LatexCommand \label{sub:MCS51-variants}
22222
22223 \end_inset
22224
22225
22226 \begin_inset LatexCommand \index{MCS51 variants}
22227
22228 \end_inset
22229
22230
22231 \end_layout
22232
22233 \begin_layout Standard
22234 MCS51 processors are available from many vendors and come in many different
22235  flavours.
22236  While they might differ considerably in respect to Special Function Registers
22237  the core MCS51 is usually not modified or is kept compatible.
22238  
22239 \end_layout
22240
22241 \begin_layout Subsection
22242 pdata access by SFR 
22243 \end_layout
22244
22245 \begin_layout Standard
22246 With the upcome of devices with internal xdata and flash memory devices
22247  using port P2
22248 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22249
22250 \end_inset
22251
22252  as dedicated I/O port is becoming more popular.
22253  Switching the high byte for pdata
22254 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22255
22256 \end_inset
22257
22258  access which was formerly done by port P2 is then achieved by a Special
22259  Function Register
22260 \begin_inset LatexCommand \index{sfr}
22261
22262 \end_inset
22263
22264 .
22265  In well-established MCS51 tradition the address of this 
22266 \emph on
22267 sfr
22268 \emph default
22269  is where the chip designers decided to put it.
22270  Needless to say that they didn't agree on a common name either.
22271  So that the startup code can correctly initialize xdata variables, you
22272  should define an sfr with the name _XPAGE
22273 \family typewriter
22274
22275 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22276
22277 \end_inset
22278
22279
22280 \family default
22281  at the appropriate location if the default, port P2, is not used for this.
22282  Some examples are:
22283 \end_layout
22284
22285 \begin_layout Verse
22286
22287 \family typewriter
22288 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22289  MPAGE */
22290 \end_layout
22291
22292 \begin_layout Verse
22293
22294 \family typewriter
22295 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22296  a.k.a.
22297  MPAGE */
22298 \end_layout
22299
22300 \begin_layout Verse
22301
22302 \family typewriter
22303 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22304  XPAGE */
22305 \end_layout
22306
22307 \begin_layout Verse
22308
22309 \family typewriter
22310 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22311  EMI0CN */
22312 \end_layout
22313
22314 \begin_layout Verse
22315
22316 \family typewriter
22317 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22318  EMI0CN */
22319 \end_layout
22320
22321 \begin_layout Standard
22322 For more exotic implementations further customizations may be needed.
22323  See section 
22324 \begin_inset LatexCommand \ref{sub:Startup-Code}
22325
22326 \end_inset
22327
22328  for other possibilities.
22329 \end_layout
22330
22331 \begin_layout Subsection
22332 Other Features available by SFR
22333 \end_layout
22334
22335 \begin_layout Standard
22336 Some MCS51 variants offer features like Double DPTR
22337 \begin_inset LatexCommand \index{DPTR}
22338
22339 \end_inset
22340
22341 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22342  These are currently not used for the MCS51 port.
22343  If you absolutely need them you can fall back to inline assembly or submit
22344  a patch to SDCC.
22345 \begin_inset VSpace bigskip
22346 \end_inset
22347
22348
22349 \end_layout
22350
22351 \begin_layout Section
22352 DS400 port
22353 \end_layout
22354
22355 \begin_layout Standard
22356 The DS80C400
22357 \begin_inset LatexCommand \index{DS80C400}
22358
22359 \end_inset
22360
22361
22362 \begin_inset LatexCommand \index{DS400}
22363
22364 \end_inset
22365
22366  microcontroller has a rich set of peripherals.
22367  In its built-in ROM library it includes functions to access some of the
22368  features, among them is a TCP stack with IP4 and IP6 support.
22369  Library headers (currently in beta status) and other files are provided
22370  at 
22371 \size footnotesize
22372
22373 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22374
22375 \end_inset
22376
22377 .
22378  
22379 \begin_inset VSpace bigskip
22380 \end_inset
22381
22382
22383 \end_layout
22384
22385 \begin_layout Section
22386 The Z80 and gbz80 port
22387 \end_layout
22388
22389 \begin_layout Standard
22390 SDCC can target both the Zilog Z80
22391 \begin_inset LatexCommand \index{Z80}
22392
22393 \end_inset
22394
22395  and the Nintendo Gameboy's Z80-like gbz80
22396 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22397
22398 \end_inset
22399
22400 .
22401  The Z80 port is passed through the same 
22402 \emph on
22403 regressions tests
22404 \begin_inset LatexCommand \index{Regression test}
22405
22406 \end_inset
22407
22408
22409 \emph default
22410  (see section 
22411 \begin_inset LatexCommand \ref{sec:Quality-control}
22412
22413 \end_inset
22414
22415 ) as the MCS51 and DS390 ports, so floating point support, support for long
22416  variables and bitfield support is fine.
22417  See mailing lists and forums about interrupt routines.
22418 \end_layout
22419
22420 \begin_layout Standard
22421 As always, the code is the authoritative reference - see z80/ralloc.c and
22422  z80/gen.c.
22423  The stack
22424 \begin_inset LatexCommand \index{Z80!stack}
22425
22426 \end_inset
22427
22428  frame is similar to that generated by the IAR Z80 compiler.
22429  IX is used as the base pointer, HL and IY are used as a temporary registers,
22430  and BC and DE are available for holding variables.
22431  Return values
22432 \begin_inset LatexCommand \index{Z80!return value}
22433
22434 \end_inset
22435
22436  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22437  bytes).
22438  The gbz80 port use the same set of registers for the return values, but
22439  in a different order of significance: E (one byte), DE (two bytes), or
22440  HLDE (four bytes).
22441 \begin_inset VSpace bigskip
22442 \end_inset
22443
22444
22445 \end_layout
22446
22447 \begin_layout Section
22448 The HC08 port
22449 \end_layout
22450
22451 \begin_layout Standard
22452 The port to the Freescale/Motorola HC08
22453 \begin_inset LatexCommand \index{HC08}
22454
22455 \end_inset
22456
22457  family has been added in October 2003, and is still undergoing some basic
22458  development.
22459  The code generator is complete, but the register allocation is still quite
22460  unoptimized.
22461  Some of the SDCC's standard C library functions have embedded non-HC08
22462  inline assembly and so are not yet usable.
22463 \end_layout
22464
22465 \begin_layout Standard
22466 The HC08 port passes the regression test suite (see section 
22467 \begin_inset LatexCommand \ref{sec:Quality-control}
22468
22469 \end_inset
22470
22471 ).
22472 \begin_inset VSpace bigskip
22473 \end_inset
22474
22475
22476 \newpage
22477
22478 \end_layout
22479
22480 \begin_layout Section
22481 The PIC14 port
22482 \end_layout
22483
22484 \begin_layout Standard
22485 The 14bit PIC
22486 \begin_inset LatexCommand \index{PIC14}
22487
22488 \end_inset
22489
22490  port still requires a major effort from the development community.
22491  However it can work for simple code.
22492  It passes its (smaller set of) regression tests
22493 \begin_inset LatexCommand \index{Regression test (PIC14)}
22494
22495 \end_inset
22496
22497  in the directory 
22498 \shape italic
22499 sdcc/src/regression
22500 \shape default
22501 .
22502 \end_layout
22503
22504 \begin_layout Subsection
22505 C code and 14bit PIC code page
22506 \begin_inset LatexCommand \index{code page (pic14)}
22507
22508 \end_inset
22509
22510  and RAM banks
22511 \begin_inset LatexCommand \index{RAM bank (pic14)}
22512
22513 \end_inset
22514
22515
22516 \end_layout
22517
22518 \begin_layout Standard
22519 The linker organizes allocation for the code page and RAM banks.
22520  It does not have intimate knowledge of the code flow.
22521  It will put all the code section of a single asm file into a single code
22522  page.
22523  In order to make use of multiple code pages, separate asm files must be
22524  used.
22525  The compiler treats all functions of a single C file as being in the same
22526  code page unless it is non static.
22527 \newline
22528
22529 \newline
22530 To get the best follow these guide lines:
22531 \end_layout
22532
22533 \begin_layout Enumerate
22534 Make local functions static, as non static functions require code page selection
22535  overhead.
22536 \end_layout
22537
22538 \begin_layout Enumerate
22539 For devices that have multiple code pages it is more efficient to use the
22540  same number of files as pages, i.e.
22541  for the 16F877 use 4 separate files and i.e.
22542  for the 16F874 use 2 separate files.
22543  This way the linker can put the code for each file into different code
22544  pages and there's less page selection overhead.
22545 \end_layout
22546
22547 \begin_layout Enumerate
22548 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22549  instruction set), use 'unsigned char' whereever possible instead of 'int'.
22550 \end_layout
22551
22552 \begin_layout Subsection
22553 Creating a device include file 
22554 \end_layout
22555
22556 \begin_layout Standard
22557 For generating a device include file
22558 \begin_inset LatexCommand \index{PIC14!Header files}
22559
22560 \end_inset
22561
22562  use the support perl script inc2h.pl kept in directory support/script.
22563 \end_layout
22564
22565 \begin_layout Subsection
22566 Interrupt code
22567 \end_layout
22568
22569 \begin_layout Standard
22570 For the interrupt function, use the keyword '__interrupt'
22571 \begin_inset LatexCommand \index{PIC14!interrupt}
22572
22573 \end_inset
22574
22575  with level number of 0 (PIC14 only has 1 interrupt so this number is only
22576  there to avoid a syntax error - it ought to be fixed).
22577  E.g.:
22578 \end_layout
22579
22580 \begin_layout Verse
22581
22582 \family typewriter
22583 void Intr(void) __interrupt 0
22584 \newline
22585 {
22586 \newline
22587 \InsetSpace ~
22588 \InsetSpace ~
22589 T0IF = 0; /* Clear timer interrupt */
22590 \newline
22591 }
22592 \end_layout
22593
22594 \begin_layout Subsection
22595 Linking and assembling
22596 \end_layout
22597
22598 \begin_layout Standard
22599 For assembling you can use either GPUTILS'
22600 \begin_inset LatexCommand \index{gputils (pic tools)}
22601
22602 \end_inset
22603
22604  gpasm.exe or MPLAB's mpasmwin.exe.
22605  GPUTILS is available from 
22606 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22607
22608 \end_inset
22609
22610 .
22611  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22612  If you use MPLAB and an interrupt function then the linker script file
22613  vectors section will need to be enlarged to link with mplink.
22614 \newline
22615
22616 \newline
22617 Here is a 
22618 \family typewriter
22619 Makefile
22620 \family default
22621  using GPUTILS:
22622 \end_layout
22623
22624 \begin_layout Verse
22625
22626 \family typewriter
22627 .c.o:
22628 \newline
22629 \InsetSpace ~
22630 \InsetSpace ~
22631 \InsetSpace ~
22632 \InsetSpace ~
22633 \InsetSpace ~
22634 \InsetSpace ~
22635 \InsetSpace ~
22636 \InsetSpace ~
22637 sdcc -S -V -mpic14 -p16F877 $< 
22638 \newline
22639 \InsetSpace ~
22640 \InsetSpace ~
22641 \InsetSpace ~
22642 \InsetSpace ~
22643 \InsetSpace ~
22644 \InsetSpace ~
22645 \InsetSpace ~
22646 \InsetSpace ~
22647 gpasm -c $*.asm
22648 \newline
22649
22650 \newline
22651 $(PRJ).hex: $(OBJS) 
22652 \newline
22653 \InsetSpace ~
22654 \InsetSpace ~
22655 \InsetSpace ~
22656 \InsetSpace ~
22657 \InsetSpace ~
22658 \InsetSpace ~
22659 \InsetSpace ~
22660 \InsetSpace ~
22661 gplink
22662  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22663 \end_layout
22664
22665 \begin_layout Standard
22666 Here is a 
22667 \family typewriter
22668 Makefile
22669 \family default
22670  using MPLAB:
22671 \end_layout
22672
22673 \begin_layout Verse
22674
22675 \family typewriter
22676 .c.o: 
22677 \newline
22678 \InsetSpace ~
22679 \InsetSpace ~
22680 \InsetSpace ~
22681 \InsetSpace ~
22682 \InsetSpace ~
22683 \InsetSpace ~
22684 \InsetSpace ~
22685 \InsetSpace ~
22686 sdcc -S -V -mpic14 -p16F877 $< 
22687 \newline
22688 \InsetSpace ~
22689 \InsetSpace ~
22690 \InsetSpace ~
22691 \InsetSpace ~
22692 \InsetSpace ~
22693 \InsetSpace ~
22694 \InsetSpace ~
22695 \InsetSpace ~
22696 mpasmwin /q /o $*.asm
22697 \newline
22698
22699 \newline
22700 $(PRJ).hex: $(OBJS)
22701  
22702 \newline
22703 \InsetSpace ~
22704 \InsetSpace ~
22705 \InsetSpace ~
22706 \InsetSpace ~
22707 \InsetSpace ~
22708 \InsetSpace ~
22709 \InsetSpace ~
22710 \InsetSpace ~
22711 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22712 \end_layout
22713
22714 \begin_layout Standard
22715 Please note that indentations within a
22716 \family typewriter
22717  Makefile
22718 \family default
22719  have to be done with a tabulator character.
22720 \end_layout
22721
22722 \begin_layout Subsection
22723 Command-line options
22724 \end_layout
22725
22726 \begin_layout Standard
22727 Besides the switches common to all SDCC backends, the PIC14 port accepts
22728  the following options (for an updated list see sdcc -
22729 \begin_inset ERT
22730 status collapsed
22731
22732 \begin_layout Standard
22733
22734
22735 \backslash
22736 /
22737 \end_layout
22738
22739 \end_inset
22740
22741 -help):
22742 \end_layout
22743
22744 \begin_layout List
22745 \labelwidthstring 00.00.0000
22746 -
22747 \begin_inset ERT
22748 status collapsed
22749
22750 \begin_layout Standard
22751
22752
22753 \backslash
22754 /
22755 \end_layout
22756
22757 \end_inset
22758
22759 -debug-extra
22760 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22761
22762 \end_inset
22763
22764  emit debug info in assembly output
22765 \end_layout
22766
22767 \begin_layout List
22768 \labelwidthstring 00.00.0000
22769 -
22770 \begin_inset ERT
22771 status collapsed
22772
22773 \begin_layout Standard
22774
22775
22776 \backslash
22777 /
22778 \end_layout
22779
22780 \end_inset
22781
22782 -no-pcode-opt
22783 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22784
22785 \end_inset
22786
22787  disable (slightly faulty) optimization on pCode
22788 \end_layout
22789
22790 \begin_layout List
22791 \labelwidthstring 00.00.0000
22792 -
22793 \begin_inset ERT
22794 status collapsed
22795
22796 \begin_layout Standard
22797
22798
22799 \backslash
22800 /
22801 \end_layout
22802
22803 \end_inset
22804
22805 -stack-loc
22806 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22807
22808 \end_inset
22809
22810  sets the lowest address of the argument passing stack (defaults to a suitably
22811  large shared databank to reduce BANKSEL overhead)
22812 \end_layout
22813
22814 \begin_layout List
22815 \labelwidthstring 00.00.0000
22816 -
22817 \begin_inset ERT
22818 status collapsed
22819
22820 \begin_layout Standard
22821
22822
22823 \backslash
22824 /
22825 \end_layout
22826
22827 \end_inset
22828
22829 -stack-size
22830 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22831
22832 \end_inset
22833
22834  sets the size if the argument passing stack (default: 16, minimum: 4)
22835 \end_layout
22836
22837 \begin_layout Subsection
22838 The library
22839 \end_layout
22840
22841 \begin_layout Subsubsection
22842 error: missing definition for symbol 
22843 \begin_inset Quotes sld
22844 \end_inset
22845
22846 __gptrget1
22847 \begin_inset Quotes srd
22848 \end_inset
22849
22850
22851 \end_layout
22852
22853 \begin_layout Standard
22854 The PIC14 port uses library routines to provide more complex operations
22855  like multiplication, division/modulus and (generic) pointer dereferencing.
22856  In order to add these routines to your project, you must link with PIC14's
22857  
22858 \family typewriter
22859 libsdcc.lib
22860 \family default
22861 .
22862  For single source file projects this is done automatically, more complex
22863  projects must add 
22864 \family typewriter
22865 libsdcc.lib
22866 \family default
22867  to the linker's arguments.
22868  Make sure you also add an include path for the library (using the -I switch
22869  to the linker)!
22870 \end_layout
22871
22872 \begin_layout Subsubsection
22873 Processor mismatch in file 
22874 \begin_inset Quotes sld
22875 \end_inset
22876
22877 XXX
22878 \begin_inset Quotes srd
22879 \end_inset
22880
22881 .
22882 \end_layout
22883
22884 \begin_layout Standard
22885 This warning can usually be ignored due to the very good compatibility amongst
22886  14 bit PIC
22887 \begin_inset LatexCommand \index{PIC14}
22888
22889 \end_inset
22890
22891  devices.
22892 \end_layout
22893
22894 \begin_layout Standard
22895 You might also consider recompiling the library for your specific device
22896  by changing the ARCH=p16f877 (default target) entry in 
22897 \family typewriter
22898 device/lib/pic/Makefile.in
22899 \family default
22900  and 
22901 \family typewriter
22902 device/lib/pic/Makefile
22903 \family default
22904  to reflect your device.
22905  This might even improve performance for smaller devices as unneccesary
22906  BANKSELs migth be removed.
22907 \end_layout
22908
22909 \begin_layout Subsection
22910 Known bugs
22911 \end_layout
22912
22913 \begin_layout Subsubsection
22914 initialized data
22915 \end_layout
22916
22917 \begin_layout Standard
22918 Currently, data can only be initialized if it resides in the source file
22919  together with 
22920 \emph on
22921 main()
22922 \emph default
22923 .
22924  Data in other source files will silently 
22925 \series bold
22926 not
22927 \series default
22928  be initialized.
22929 \family typewriter
22930 \size footnotesize
22931
22932 \begin_inset Marginal
22933 status collapsed
22934
22935 \begin_layout Standard
22936
22937 \series bold
22938 \InsetSpace ~
22939 !
22940 \end_layout
22941
22942 \end_inset
22943
22944
22945 \family default
22946
22947 \newpage
22948
22949 \end_layout
22950
22951 \begin_layout Section
22952 The PIC16
22953 \begin_inset LatexCommand \index{PIC16}
22954
22955 \end_inset
22956
22957  port
22958 \end_layout
22959
22960 \begin_layout Standard
22961 The PIC16
22962 \begin_inset LatexCommand \index{PIC16}
22963
22964 \end_inset
22965
22966  port is the portion of SDCC that is responsible to produce code for the
22967  Microchip
22968 \begin_inset LatexCommand \index{Microchip}
22969
22970 \end_inset
22971
22972 (TM) microcontrollers with 16 bit core.
22973  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22974  Currently supported devices are:
22975 \end_layout
22976
22977 \begin_layout Standard
22978 \align center
22979 \begin_inset Tabular
22980 <lyxtabular version="3" rows="4" columns="6">
22981 <features>
22982 <column alignment="center" valignment="top" leftline="true" width="0">
22983 <column alignment="center" valignment="top" leftline="true" width="0">
22984 <column alignment="center" valignment="top" leftline="true" width="0">
22985 <column alignment="center" valignment="top" leftline="true" width="0">
22986 <column alignment="center" valignment="top" leftline="true" width="0">
22987 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22988 <row topline="true">
22989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22990 \begin_inset Text
22991
22992 \begin_layout Standard
22993 18F242
22994 \end_layout
22995
22996 \end_inset
22997 </cell>
22998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22999 \begin_inset Text
23000
23001 \begin_layout Standard
23002 18F248
23003 \end_layout
23004
23005 \end_inset
23006 </cell>
23007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23008 \begin_inset Text
23009
23010 \begin_layout Standard
23011 18F252
23012 \end_layout
23013
23014 \end_inset
23015 </cell>
23016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23017 \begin_inset Text
23018
23019 \begin_layout Standard
23020 18F258
23021 \end_layout
23022
23023 \end_inset
23024 </cell>
23025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23026 \begin_inset Text
23027
23028 \begin_layout Standard
23029 18F442
23030 \end_layout
23031
23032 \end_inset
23033 </cell>
23034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23035 \begin_inset Text
23036
23037 \begin_layout Standard
23038 18F448
23039 \end_layout
23040
23041 \end_inset
23042 </cell>
23043 </row>
23044 <row topline="true">
23045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23046 \begin_inset Text
23047
23048 \begin_layout Standard
23049 18F452
23050 \end_layout
23051
23052 \end_inset
23053 </cell>
23054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23055 \begin_inset Text
23056
23057 \begin_layout Standard
23058 18F458
23059 \end_layout
23060
23061 \end_inset
23062 </cell>
23063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23064 \begin_inset Text
23065
23066 \begin_layout Standard
23067 18F1220
23068 \end_layout
23069
23070 \end_inset
23071 </cell>
23072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23073 \begin_inset Text
23074
23075 \begin_layout Standard
23076 18F2220
23077 \end_layout
23078
23079 \end_inset
23080 </cell>
23081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23082 \begin_inset Text
23083
23084 \begin_layout Standard
23085 18F2550
23086 \end_layout
23087
23088 \end_inset
23089 </cell>
23090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23091 \begin_inset Text
23092
23093 \begin_layout Standard
23094 18F4331
23095 \end_layout
23096
23097 \end_inset
23098 </cell>
23099 </row>
23100 <row topline="true">
23101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23102 \begin_inset Text
23103
23104 \begin_layout Standard
23105 18F4455
23106 \end_layout
23107
23108 \end_inset
23109 </cell>
23110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23111 \begin_inset Text
23112
23113 \begin_layout Standard
23114 18F6520
23115 \end_layout
23116
23117 \end_inset
23118 </cell>
23119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23120 \begin_inset Text
23121
23122 \begin_layout Standard
23123 18F6620
23124 \end_layout
23125
23126 \end_inset
23127 </cell>
23128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23129 \begin_inset Text
23130
23131 \begin_layout Standard
23132 18F6680
23133 \end_layout
23134
23135 \end_inset
23136 </cell>
23137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23138 \begin_inset Text
23139
23140 \begin_layout Standard
23141 18F6720
23142 \end_layout
23143
23144 \end_inset
23145 </cell>
23146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23147 \begin_inset Text
23148
23149 \begin_layout Standard
23150 18F8520
23151 \end_layout
23152
23153 \end_inset
23154 </cell>
23155 </row>
23156 <row topline="true" bottomline="true">
23157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23158 \begin_inset Text
23159
23160 \begin_layout Standard
23161 18F8620
23162 \end_layout
23163
23164 \end_inset
23165 </cell>
23166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23167 \begin_inset Text
23168
23169 \begin_layout Standard
23170 18F8680
23171 \end_layout
23172
23173 \end_inset
23174 </cell>
23175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23176 \begin_inset Text
23177
23178 \begin_layout Standard
23179 18F8720
23180 \end_layout
23181
23182 \end_inset
23183 </cell>
23184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23185 \begin_inset Text
23186
23187 \begin_layout Standard
23188
23189 \end_layout
23190
23191 \end_inset
23192 </cell>
23193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23194 \begin_inset Text
23195
23196 \begin_layout Standard
23197
23198 \end_layout
23199
23200 \end_inset
23201 </cell>
23202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23203 \begin_inset Text
23204
23205 \begin_layout Standard
23206
23207 \end_layout
23208
23209 \end_inset
23210 </cell>
23211 </row>
23212 </lyxtabular>
23213
23214 \end_inset
23215
23216
23217 \end_layout
23218
23219 \begin_layout Subsection
23220 Global Options
23221 \end_layout
23222
23223 \begin_layout Standard
23224 PIC16 port supports the standard command line arguments as supposed, with
23225  the exception of certain cases that will be mentioned in the following
23226  list:
23227 \end_layout
23228
23229 \begin_layout List
23230 \labelwidthstring 00.00.0000
23231 -
23232 \begin_inset ERT
23233 status collapsed
23234
23235 \begin_layout Standard
23236
23237
23238 \backslash
23239 /
23240 \end_layout
23241
23242 \end_inset
23243
23244 -callee-saves
23245 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23246
23247 \end_inset
23248
23249  See -
23250 \begin_inset ERT
23251 status collapsed
23252
23253 \begin_layout Standard
23254
23255
23256 \backslash
23257 /
23258 \end_layout
23259
23260 \end_inset
23261
23262 -all-callee-saves
23263 \end_layout
23264
23265 \begin_layout List
23266 \labelwidthstring 00.00.0000
23267 -
23268 \begin_inset ERT
23269 status collapsed
23270
23271 \begin_layout Standard
23272
23273
23274 \backslash
23275 /
23276 \end_layout
23277
23278 \end_inset
23279
23280 -fommit-frame-pointer
23281 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23282
23283 \end_inset
23284
23285  Frame pointer will be omitted when the function uses no local variables.
23286 \end_layout
23287
23288 \begin_layout Subsection
23289 Port Specific Options
23290 \begin_inset LatexCommand \index{Options PIC16}
23291
23292 \end_inset
23293
23294
23295 \end_layout
23296
23297 \begin_layout Standard
23298 The port specific options appear after the global options in the sdcc --help
23299  output.
23300 \end_layout
23301
23302 \begin_layout Subsubsection
23303 General Options
23304 \end_layout
23305
23306 \begin_layout Standard
23307 General options enable certain port features and optimizations.
23308 \end_layout
23309
23310 \begin_layout List
23311 \labelwidthstring 00.00.0000
23312 -
23313 \begin_inset ERT
23314 status collapsed
23315
23316 \begin_layout Standard
23317
23318
23319 \backslash
23320 /
23321 \end_layout
23322
23323 \end_inset
23324
23325 -pstack-model=[model] Used in conjuction with the command above.
23326  Defines the stack model to be used, valid stack models are : 
23327 \end_layout
23328
23329 \begin_deeper
23330 \begin_layout List
23331 \labelwidthstring 00.00.0000
23332
23333 \emph on
23334 small
23335 \emph default
23336  Selects small stack model.
23337  8 bit stack and frame pointers.
23338  Supports 256 bytes stack size.
23339 \end_layout
23340
23341 \begin_layout List
23342 \labelwidthstring 00.00.0000
23343
23344 \emph on
23345 large
23346 \emph default
23347  Selects large stack model.
23348  16 bit stack and frame pointers.
23349  Supports 65536 bytes stack size.
23350 \end_layout
23351
23352 \end_deeper
23353 \begin_layout List
23354 \labelwidthstring 00.00.0000
23355 -
23356 \begin_inset ERT
23357 status collapsed
23358
23359 \begin_layout Standard
23360
23361
23362 \backslash
23363 /
23364 \end_layout
23365
23366 \end_inset
23367
23368 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23369  unitialized data variables with [kword].
23370  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23371 \end_layout
23372
23373 \begin_layout List
23374 \labelwidthstring 00.00.0000
23375 -
23376 \begin_inset ERT
23377 status collapsed
23378
23379 \begin_layout Standard
23380
23381
23382 \backslash
23383 /
23384 \end_layout
23385
23386 \end_inset
23387
23388 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23389  Useful for bootloaders.
23390 \end_layout
23391
23392 \begin_layout List
23393 \labelwidthstring 00.00.0000
23394 -
23395 \begin_inset ERT
23396 status collapsed
23397
23398 \begin_layout Standard
23399
23400
23401 \backslash
23402 /
23403 \end_layout
23404
23405 \end_inset
23406
23407 -asm= sets the full path and name of an external assembler to call.
23408 \end_layout
23409
23410 \begin_layout List
23411 \labelwidthstring 00.00.0000
23412 -
23413 \begin_inset ERT
23414 status collapsed
23415
23416 \begin_layout Standard
23417
23418
23419 \backslash
23420 /
23421 \end_layout
23422
23423 \end_inset
23424
23425 -link= sets the full path and name of an external linker to call.
23426 \end_layout
23427
23428 \begin_layout List
23429 \labelwidthstring 00.00.0000
23430 -
23431 \begin_inset ERT
23432 status collapsed
23433
23434 \begin_layout Standard
23435
23436
23437 \backslash
23438 /
23439 \end_layout
23440
23441 \end_inset
23442
23443 -mplab-comp MPLAB
23444 \begin_inset LatexCommand \index{PIC16!MPLAB}
23445
23446 \end_inset
23447
23448  compatibility option.
23449  Currently only suppresses special gpasm directives.
23450 \end_layout
23451
23452 \begin_layout Subsubsection
23453 Optimization Options
23454 \end_layout
23455
23456 \begin_layout List
23457 \labelwidthstring 00.00.0000
23458 -
23459 \begin_inset ERT
23460 status collapsed
23461
23462 \begin_layout Standard
23463
23464
23465 \backslash
23466 /
23467 \end_layout
23468
23469 \end_inset
23470
23471 -optimize-goto Try to use (conditional) BRA instead of GOTO
23472 \end_layout
23473
23474 \begin_layout List
23475 \labelwidthstring 00.00.0000
23476 -
23477 \begin_inset ERT
23478 status collapsed
23479
23480 \begin_layout Standard
23481
23482
23483 \backslash
23484 /
23485 \end_layout
23486
23487 \end_inset
23488
23489 -optimize-cmp Try to optimize some compares.
23490 \end_layout
23491
23492 \begin_layout List
23493 \labelwidthstring 00.00.0000
23494 -
23495 \begin_inset ERT
23496 status collapsed
23497
23498 \begin_layout Standard
23499
23500
23501 \backslash
23502 /
23503 \end_layout
23504
23505 \end_inset
23506
23507 -optimize-df Analyze the dataflow of the generated code and improve it.
23508 \end_layout
23509
23510 \begin_layout List
23511 \labelwidthstring 00.00.0000
23512 -
23513 \begin_inset ERT
23514 status collapsed
23515
23516 \begin_layout Standard
23517
23518
23519 \backslash
23520 /
23521 \end_layout
23522
23523 \end_inset
23524
23525 -obanksel=nn Set optimization level for inserting BANKSELs.
23526 \newline
23527
23528 \end_layout
23529
23530 \begin_deeper
23531 \begin_layout List
23532 \labelwidthstring 00.00.0000
23533 0 no optimization
23534 \end_layout
23535
23536 \begin_layout List
23537 \labelwidthstring 00.00.0000
23538 1 checks previous used register and if it is the same then does not emit
23539  BANKSEL, accounts only for labels.
23540 \end_layout
23541
23542 \begin_layout List
23543 \labelwidthstring 00.00.0000
23544 2 tries to check the location of (even different) symbols and removes BANKSELs
23545  if they are in the same bank.
23546  
23547 \newline
23548
23549 \emph on
23550 Important: There might be problems if the linker script has data sections
23551  across bank borders!
23552 \end_layout
23553
23554 \end_deeper
23555 \begin_layout Subsubsection
23556 Linking Options
23557 \end_layout
23558
23559 \begin_layout List
23560 \labelwidthstring 00.00.0000
23561 -
23562 \begin_inset ERT
23563 status collapsed
23564
23565 \begin_layout Standard
23566
23567
23568 \backslash
23569 /
23570 \end_layout
23571
23572 \end_inset
23573
23574 -nodefaultlibs do not link default libraries when linking
23575 \end_layout
23576
23577 \begin_layout List
23578 \labelwidthstring 00.00.0000
23579 -
23580 \begin_inset ERT
23581 status collapsed
23582
23583 \begin_layout Standard
23584
23585
23586 \backslash
23587 /
23588 \end_layout
23589
23590 \end_inset
23591
23592 -no-crt Don't link the default run-time modules
23593 \end_layout
23594
23595 \begin_layout List
23596 \labelwidthstring 00.00.0000
23597 -
23598 \begin_inset ERT
23599 status collapsed
23600
23601 \begin_layout Standard
23602
23603
23604 \backslash
23605 /
23606 \end_layout
23607
23608 \end_inset
23609
23610 -use-crt= Use a custom run-time module instead of the defaults.
23611 \end_layout
23612
23613 \begin_layout Subsubsection
23614 Debugging Options
23615 \end_layout
23616
23617 \begin_layout Standard
23618 Debugging options enable extra debugging information in the output files.
23619 \end_layout
23620
23621 \begin_layout List
23622 \labelwidthstring 00.00.0000
23623 -
23624 \begin_inset ERT
23625 status collapsed
23626
23627 \begin_layout Standard
23628
23629
23630 \backslash
23631 /
23632 \end_layout
23633
23634 \end_inset
23635
23636 -debug-xtra Similar to -
23637 \begin_inset ERT
23638 status collapsed
23639
23640 \begin_layout Standard
23641
23642
23643 \backslash
23644 /
23645 \end_layout
23646
23647 \end_inset
23648
23649 -debug
23650 \begin_inset LatexCommand \index{-\/-debug}
23651
23652 \end_inset
23653
23654 , but dumps more information.
23655 \end_layout
23656
23657 \begin_layout List
23658 \labelwidthstring 00.00.0000
23659 -
23660 \begin_inset ERT
23661 status collapsed
23662
23663 \begin_layout Standard
23664
23665
23666 \backslash
23667 /
23668 \end_layout
23669
23670 \end_inset
23671
23672 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23673  information.
23674  <source> is the name of the file compiled.
23675 \end_layout
23676
23677 \begin_layout List
23678 \labelwidthstring 00.00.0000
23679 -
23680 \begin_inset ERT
23681 status collapsed
23682
23683 \begin_layout Standard
23684
23685
23686 \backslash
23687 /
23688 \end_layout
23689
23690 \end_inset
23691
23692 -pcode-verbose Enable pcode debugging information in translation.
23693 \end_layout
23694
23695 \begin_layout List
23696 \labelwidthstring 00.00.0000
23697 -
23698 \begin_inset ERT
23699 status collapsed
23700
23701 \begin_layout Standard
23702
23703
23704 \backslash
23705 /
23706 \end_layout
23707
23708 \end_inset
23709
23710 -denable-peeps Force the usage of peepholes.
23711  Use with care.
23712 \end_layout
23713
23714 \begin_layout List
23715 \labelwidthstring 00.00.0000
23716 -
23717 \begin_inset ERT
23718 status collapsed
23719
23720 \begin_layout Standard
23721
23722
23723 \backslash
23724 /
23725 \end_layout
23726
23727 \end_inset
23728
23729 -gstack Trace push/pops for stack pointer overflow
23730 \end_layout
23731
23732 \begin_layout List
23733 \labelwidthstring 00.00.0000
23734 -
23735 \begin_inset ERT
23736 status collapsed
23737
23738 \begin_layout Standard
23739
23740
23741 \backslash
23742 /
23743 \end_layout
23744
23745 \end_inset
23746
23747 -call-tree dump call tree in .calltree file
23748 \end_layout
23749
23750 \begin_layout Subsection
23751 Enviromental Variables
23752 \end_layout
23753
23754 \begin_layout Standard
23755 There is a number of enviromental variables that can be used when running
23756  SDCC to enable certain optimizations or force a specific program behaviour.
23757  these variables are primarily for debugging purposes so they can be enabled/dis
23758 abled at will.
23759 \end_layout
23760
23761 \begin_layout Standard
23762 Currently there is only two such variables available:
23763 \end_layout
23764
23765 \begin_layout List
23766 \labelwidthstring 00.00.0000
23767 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23768  bitfields is optimized by directly loading FSR0 with the address of the
23769  bitfield structure.
23770  Normally SDCC will cast the bitfield structure to a bitfield pointer and
23771  then load FSR0.
23772  This step saves data ram and code space for functions that perform heavy
23773  use of bitfields.
23774  (ie.
23775  80 bytes of code space are saved when compiling malloc.c with this option).
23776  
23777 \end_layout
23778
23779 \begin_layout List
23780 \labelwidthstring 00.00.0000
23781 NO_REG_OPT do not perform pCode registers optimization.
23782  This should be used for debugging purposes.
23783  In some where bugs in the pcode optimizer are found, users can benefit
23784  from temporarily disabling the optimizer until the bug is fixed.
23785 \end_layout
23786
23787 \begin_layout Subsection
23788 Preprocessor Macros
23789 \end_layout
23790
23791 \begin_layout Standard
23792 PIC16
23793 \begin_inset LatexCommand \index{PIC16}
23794
23795 \end_inset
23796
23797  port defines the following preprocessor macros while translating a source.
23798 \end_layout
23799
23800 \begin_layout Standard
23801 \align center
23802 \begin_inset Tabular
23803 <lyxtabular version="3" rows="6" columns="2">
23804 <features>
23805 <column alignment="center" valignment="top" leftline="true" width="0">
23806 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23807 <row topline="true" bottomline="true">
23808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23809 \begin_inset Text
23810
23811 \begin_layout Standard
23812 Macro
23813 \end_layout
23814
23815 \end_inset
23816 </cell>
23817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23818 \begin_inset Text
23819
23820 \begin_layout Standard
23821 Description
23822 \end_layout
23823
23824 \end_inset
23825 </cell>
23826 </row>
23827 <row topline="true">
23828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23829 \begin_inset Text
23830
23831 \begin_layout Standard
23832 SDCC_pic16
23833 \end_layout
23834
23835 \end_inset
23836 </cell>
23837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23838 \begin_inset Text
23839
23840 \begin_layout Standard
23841 Port identification
23842 \end_layout
23843
23844 \end_inset
23845 </cell>
23846 </row>
23847 <row topline="true">
23848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23849 \begin_inset Text
23850
23851 \begin_layout Standard
23852 _
23853 \begin_inset ERT
23854 status collapsed
23855
23856 \begin_layout Standard
23857
23858
23859 \backslash
23860 /
23861 \end_layout
23862
23863 \end_inset
23864
23865 _pic16
23866 \end_layout
23867
23868 \end_inset
23869 </cell>
23870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23871 \begin_inset Text
23872
23873 \begin_layout Standard
23874 Port identification (same as above)
23875 \end_layout
23876
23877 \end_inset
23878 </cell>
23879 </row>
23880 <row topline="true">
23881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23882 \begin_inset Text
23883
23884 \begin_layout Standard
23885 pic18fxxxx
23886 \end_layout
23887
23888 \end_inset
23889 </cell>
23890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23891 \begin_inset Text
23892
23893 \begin_layout Standard
23894 MCU Identification.
23895  
23896 \emph on
23897 xxxx
23898 \emph default
23899  is the microcontrol identification number, i.e.
23900  452, 6620, etc
23901 \end_layout
23902
23903 \end_inset
23904 </cell>
23905 </row>
23906 <row topline="true">
23907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23908 \begin_inset Text
23909
23910 \begin_layout Standard
23911 _
23912 \begin_inset ERT
23913 status collapsed
23914
23915 \begin_layout Standard
23916
23917
23918 \backslash
23919 /
23920 \end_layout
23921
23922 \end_inset
23923
23924 _18Fxxxx
23925 \end_layout
23926
23927 \end_inset
23928 </cell>
23929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23930 \begin_inset Text
23931
23932 \begin_layout Standard
23933 MCU Identification (same as above)
23934 \end_layout
23935
23936 \end_inset
23937 </cell>
23938 </row>
23939 <row topline="true" bottomline="true">
23940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23941 \begin_inset Text
23942
23943 \begin_layout Standard
23944 STACK_MODEL_nnn
23945 \end_layout
23946
23947 \end_inset
23948 </cell>
23949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23950 \begin_inset Text
23951
23952 \begin_layout Standard
23953 nnn = SMALL or LARGE respectively according to the stack model used
23954 \end_layout
23955
23956 \end_inset
23957 </cell>
23958 </row>
23959 </lyxtabular>
23960
23961 \end_inset
23962
23963
23964 \end_layout
23965
23966 \begin_layout Standard
23967 In addition the following macros are defined when calling assembler:
23968 \end_layout
23969
23970 \begin_layout Standard
23971 \align center
23972 \begin_inset Tabular
23973 <lyxtabular version="3" rows="4" columns="2">
23974 <features>
23975 <column alignment="center" valignment="top" leftline="true" width="0">
23976 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23977 <row topline="true" bottomline="true">
23978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23979 \begin_inset Text
23980
23981 \begin_layout Standard
23982 Macro
23983 \end_layout
23984
23985 \end_inset
23986 </cell>
23987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23988 \begin_inset Text
23989
23990 \begin_layout Standard
23991 Description
23992 \end_layout
23993
23994 \end_inset
23995 </cell>
23996 </row>
23997 <row topline="true">
23998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23999 \begin_inset Text
24000
24001 \begin_layout Standard
24002 __18Fxxxx
24003 \end_layout
24004
24005 \end_inset
24006 </cell>
24007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24008 \begin_inset Text
24009
24010 \begin_layout Standard
24011 MCU Identification.
24012  
24013 \emph on
24014 xxxx
24015 \emph default
24016  is the microcontrol identification number, i.e.
24017  452, 6620, etc
24018 \end_layout
24019
24020 \end_inset
24021 </cell>
24022 </row>
24023 <row topline="true">
24024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24025 \begin_inset Text
24026
24027 \begin_layout Standard
24028 SDCC_MODEL_nnn
24029 \end_layout
24030
24031 \end_inset
24032 </cell>
24033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24034 \begin_inset Text
24035
24036 \begin_layout Standard
24037 nnn = SMALL or LARGE respectively according to the memory model used for
24038  SDCC
24039 \end_layout
24040
24041 \end_inset
24042 </cell>
24043 </row>
24044 <row topline="true" bottomline="true">
24045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24046 \begin_inset Text
24047
24048 \begin_layout Standard
24049 STACK_MODEL_nnn
24050 \end_layout
24051
24052 \end_inset
24053 </cell>
24054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24055 \begin_inset Text
24056
24057 \begin_layout Standard
24058 nnn = SMALL or LARGE respectively according to the stack model used
24059 \end_layout
24060
24061 \end_inset
24062 </cell>
24063 </row>
24064 </lyxtabular>
24065
24066 \end_inset
24067
24068
24069 \end_layout
24070
24071 \begin_layout Subsection
24072 Directories
24073 \end_layout
24074
24075 \begin_layout Standard
24076 PIC16
24077 \begin_inset LatexCommand \index{PIC16}
24078
24079 \end_inset
24080
24081  port uses the following directories for searching header files and libraries.
24082 \end_layout
24083
24084 \begin_layout Standard
24085 \align center
24086 \begin_inset Tabular
24087 <lyxtabular version="3" rows="3" columns="4">
24088 <features>
24089 <column alignment="center" valignment="top" leftline="true" width="0">
24090 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24091 <column alignment="center" valignment="top" width="0">
24092 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24093 <row topline="true" bottomline="true">
24094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24095 \begin_inset Text
24096
24097 \begin_layout Standard
24098 Directory
24099 \end_layout
24100
24101 \end_inset
24102 </cell>
24103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24104 \begin_inset Text
24105
24106 \begin_layout Standard
24107 Description
24108 \end_layout
24109
24110 \end_inset
24111 </cell>
24112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24113 \begin_inset Text
24114
24115 \begin_layout Standard
24116 Target
24117 \end_layout
24118
24119 \end_inset
24120 </cell>
24121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24122 \begin_inset Text
24123
24124 \begin_layout Standard
24125 Command prefix
24126 \end_layout
24127
24128 \end_inset
24129 </cell>
24130 </row>
24131 <row topline="true">
24132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24133 \begin_inset Text
24134
24135 \begin_layout Standard
24136 PREFIX/sdcc/include/pic16
24137 \end_layout
24138
24139 \end_inset
24140 </cell>
24141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24142 \begin_inset Text
24143
24144 \begin_layout Standard
24145 PIC16 specific headers
24146 \end_layout
24147
24148 \end_inset
24149 </cell>
24150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24151 \begin_inset Text
24152
24153 \begin_layout Standard
24154 Compiler
24155 \end_layout
24156
24157 \end_inset
24158 </cell>
24159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24160 \begin_inset Text
24161
24162 \begin_layout Standard
24163 -I
24164 \end_layout
24165
24166 \end_inset
24167 </cell>
24168 </row>
24169 <row topline="true" bottomline="true">
24170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24171 \begin_inset Text
24172
24173 \begin_layout Standard
24174 PREFIX/sdcc/lib/pic16
24175 \end_layout
24176
24177 \end_inset
24178 </cell>
24179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24180 \begin_inset Text
24181
24182 \begin_layout Standard
24183 PIC16 specific libraries
24184 \end_layout
24185
24186 \end_inset
24187 </cell>
24188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24189 \begin_inset Text
24190
24191 \begin_layout Standard
24192 Linker
24193 \end_layout
24194
24195 \end_inset
24196 </cell>
24197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24198 \begin_inset Text
24199
24200 \begin_layout Standard
24201 -L
24202 \end_layout
24203
24204 \end_inset
24205 </cell>
24206 </row>
24207 </lyxtabular>
24208
24209 \end_inset
24210
24211
24212 \end_layout
24213
24214 \begin_layout Subsection
24215 Pragmas
24216 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24217
24218 \end_inset
24219
24220
24221 \end_layout
24222
24223 \begin_layout Standard
24224 PIC16
24225 \begin_inset LatexCommand \index{PIC16}
24226
24227 \end_inset
24228
24229  port currently supports the following pragmas:
24230 \end_layout
24231
24232 \begin_layout List
24233 \labelwidthstring 00.00.0000
24234 stack
24235 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24236
24237 \end_inset
24238
24239  pragma stack
24240 \begin_inset LatexCommand \index{PIC16!stack}
24241
24242 \end_inset
24243
24244  forces the code generator to initialize the stack & frame pointers at a
24245  specific address.
24246  This is an adhoc solution for cases where no STACK directive is available
24247  in the linker script or gplink is not instructed to create a stack section.
24248 \newline
24249 The
24250  stack pragma should be used only once in a project.
24251  Multiple pragmas may result in indeterminate behaviour of the program.
24252 \begin_inset Foot
24253 status open
24254
24255 \begin_layout Standard
24256 The old format (ie.
24257  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24258  cross page boundaries (or even exceed the available data RAM) and crash
24259  the program.
24260  Make sure that stack does not cross page boundaries when using the SMALL
24261  stack model.
24262 \end_layout
24263
24264 \end_inset
24265
24266
24267 \newline
24268 The format is as follows:
24269 \end_layout
24270
24271 \begin_layout LyX-Code
24272 #pragma stack bottom_address [stack_size]
24273 \end_layout
24274
24275 \begin_layout Standard
24276
24277 \emph on
24278 bottom_address
24279 \emph default
24280  is the lower bound of the stack section.
24281  The stack pointer initially will point at address (bottom_address+stack_size-1).
24282 \end_layout
24283
24284 \begin_layout LyX-Code
24285 Example:
24286 \end_layout
24287
24288 \begin_layout LyX-Code
24289
24290 \end_layout
24291
24292 \begin_layout LyX-Code
24293 /* initializes stack of 100 bytes at RAM address 0x200 */
24294 \end_layout
24295
24296 \begin_layout LyX-Code
24297 #pragma stack 0x200 100
24298 \end_layout
24299
24300 \begin_layout Standard
24301 If the stack_size field is omitted then a stack is created with the default
24302  size of 64.
24303  This size might be enough for most programs, but its not enough for operations
24304  with deep function nesting or excessive stack usage.
24305 \end_layout
24306
24307 \begin_layout List
24308 \labelwidthstring 00.00.0000
24309 code
24310 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24311
24312 \end_inset
24313
24314  place a function symbol at static FLASH address
24315 \end_layout
24316
24317 \begin_layout LyX-Code
24318 Example:
24319 \end_layout
24320
24321 \begin_layout LyX-Code
24322
24323 \end_layout
24324
24325 \begin_layout LyX-Code
24326 /* place function test_func at 0x4000 */
24327 \end_layout
24328
24329 \begin_layout LyX-Code
24330 #pragma code test_func 0x4000
24331 \end_layout
24332
24333 \begin_layout LyX-Code
24334
24335 \end_layout
24336
24337 \begin_layout List
24338 \labelwidthstring 00.00.0000
24339 library instructs the linker to use a library module.
24340 \newline
24341 Usage:
24342 \end_layout
24343
24344 \begin_layout LyX-Code
24345 #pragma library module_name
24346 \end_layout
24347
24348 \begin_layout Standard
24349
24350 \emph on
24351 module_name
24352 \emph default
24353  can be any library or object file (including its path).
24354  Note that there are four reserved keywords which have special meaning.
24355  These are:
24356 \end_layout
24357
24358 \begin_layout Standard
24359 \align center
24360 \begin_inset Tabular
24361 <lyxtabular version="3" rows="6" columns="3">
24362 <features>
24363 <column alignment="center" valignment="top" leftline="true" width="0">
24364 <column alignment="block" valignment="top" leftline="true" width="20page%">
24365 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24366 <row topline="true" bottomline="true">
24367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24368 \begin_inset Text
24369
24370 \begin_layout Standard
24371 Keyword
24372 \end_layout
24373
24374 \end_inset
24375 </cell>
24376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24377 \begin_inset Text
24378
24379 \begin_layout Standard
24380 Description
24381 \end_layout
24382
24383 \end_inset
24384 </cell>
24385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24386 \begin_inset Text
24387
24388 \begin_layout Standard
24389 Module to link
24390 \end_layout
24391
24392 \end_inset
24393 </cell>
24394 </row>
24395 <row topline="true">
24396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24397 \begin_inset Text
24398
24399 \begin_layout Standard
24400
24401 \series bold
24402 ignore
24403 \end_layout
24404
24405 \end_inset
24406 </cell>
24407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24408 \begin_inset Text
24409
24410 \begin_layout Standard
24411 ignore all library pragmas
24412 \end_layout
24413
24414 \end_inset
24415 </cell>
24416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24417 \begin_inset Text
24418
24419 \begin_layout Standard
24420
24421 \emph on
24422 (none)
24423 \end_layout
24424
24425 \end_inset
24426 </cell>
24427 </row>
24428 <row topline="true">
24429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24430 \begin_inset Text
24431
24432 \begin_layout Standard
24433
24434 \series bold
24435 c
24436 \end_layout
24437
24438 \end_inset
24439 </cell>
24440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24441 \begin_inset Text
24442
24443 \begin_layout Standard
24444 link the C library
24445 \end_layout
24446
24447 \end_inset
24448 </cell>
24449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24450 \begin_inset Text
24451
24452 \begin_layout Standard
24453
24454 \emph on
24455 libc18f
24456 \emph default
24457 .lib
24458 \end_layout
24459
24460 \end_inset
24461 </cell>
24462 </row>
24463 <row topline="true">
24464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24465 \begin_inset Text
24466
24467 \begin_layout Standard
24468
24469 \series bold
24470 math
24471 \end_layout
24472
24473 \end_inset
24474 </cell>
24475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24476 \begin_inset Text
24477
24478 \begin_layout Standard
24479 link the Math libarary
24480 \end_layout
24481
24482 \end_inset
24483 </cell>
24484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24485 \begin_inset Text
24486
24487 \begin_layout Standard
24488
24489 \emph on
24490 libm18f
24491 \emph default
24492 .lib
24493 \end_layout
24494
24495 \end_inset
24496 </cell>
24497 </row>
24498 <row topline="true">
24499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24500 \begin_inset Text
24501
24502 \begin_layout Standard
24503
24504 \series bold
24505 io
24506 \end_layout
24507
24508 \end_inset
24509 </cell>
24510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24511 \begin_inset Text
24512
24513 \begin_layout Standard
24514 link the I/O library
24515 \end_layout
24516
24517 \end_inset
24518 </cell>
24519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24520 \begin_inset Text
24521
24522 \begin_layout Standard
24523
24524 \emph on
24525 libio18f*
24526 \emph default
24527 .lib
24528 \end_layout
24529
24530 \end_inset
24531 </cell>
24532 </row>
24533 <row topline="true" bottomline="true">
24534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24535 \begin_inset Text
24536
24537 \begin_layout Standard
24538
24539 \series bold
24540 debug
24541 \end_layout
24542
24543 \end_inset
24544 </cell>
24545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24546 \begin_inset Text
24547
24548 \begin_layout Standard
24549 link the debug library
24550 \end_layout
24551
24552 \end_inset
24553 </cell>
24554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24555 \begin_inset Text
24556
24557 \begin_layout Standard
24558
24559 \emph on
24560 libdebug
24561 \emph default
24562 .lib
24563 \end_layout
24564
24565 \end_inset
24566 </cell>
24567 </row>
24568 </lyxtabular>
24569
24570 \end_inset
24571
24572
24573 \newline
24574 * is the device number, i.e.
24575  452 for PIC18F452 MCU.
24576 \end_layout
24577
24578 \begin_layout Standard
24579 This feature allows for linking with specific libraries withoug having to
24580  explicit name them in the command line.
24581  Note that the 
24582 \noun on
24583 ignore
24584 \noun default
24585  keyword will reject all modules specified by the library pragma.
24586 \end_layout
24587
24588 \begin_layout List
24589 \labelwidthstring 00.00.0000
24590 udata pragma udata instructs the compiler to emit code so that linker will
24591  place a variable at a specific memory bank
24592 \end_layout
24593
24594 \begin_layout LyX-Code
24595 Example:
24596 \end_layout
24597
24598 \begin_layout LyX-Code
24599
24600 \end_layout
24601
24602 \begin_layout LyX-Code
24603 /* places variable foo at bank2 */
24604 \end_layout
24605
24606 \begin_layout LyX-Code
24607 #pragma udata bank2 foo
24608 \end_layout
24609
24610 \begin_layout LyX-Code
24611 char foo;
24612 \end_layout
24613
24614 \begin_layout Standard
24615 In order for this pragma to work extra SECTION directives should be added
24616  in the .lkr script.
24617  In the following example a sample .lkr file is shown:
24618 \end_layout
24619
24620 \begin_layout LyX-Code
24621
24622 \end_layout
24623
24624 \begin_layout LyX-Code
24625 // Sample linker script for the PIC18F452 processor
24626 \end_layout
24627
24628 \begin_layout LyX-Code
24629 LIBPATH .
24630 \end_layout
24631
24632 \begin_layout LyX-Code
24633 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24634 \end_layout
24635
24636 \begin_layout LyX-Code
24637 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24638 \end_layout
24639
24640 \begin_layout LyX-Code
24641 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24642 \end_layout
24643
24644 \begin_layout LyX-Code
24645 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24646 \end_layout
24647
24648 \begin_layout LyX-Code
24649 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24650 \end_layout
24651
24652 \begin_layout LyX-Code
24653 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24654 \end_layout
24655
24656 \begin_layout LyX-Code
24657 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24658 \end_layout
24659
24660 \begin_layout LyX-Code
24661
24662 \end_layout
24663
24664 \begin_layout LyX-Code
24665 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24666 \end_layout
24667
24668 \begin_layout LyX-Code
24669 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24670 \end_layout
24671
24672 \begin_layout LyX-Code
24673 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24674 \end_layout
24675
24676 \begin_layout LyX-Code
24677 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24678 \end_layout
24679
24680 \begin_layout LyX-Code
24681 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24682 \end_layout
24683
24684 \begin_layout LyX-Code
24685 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24686 \end_layout
24687
24688 \begin_layout LyX-Code
24689 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24690 \end_layout
24691
24692 \begin_layout LyX-Code
24693
24694 \end_layout
24695
24696 \begin_layout LyX-Code
24697 SECTION    NAME=CONFIG     ROM=config
24698 \end_layout
24699
24700 \begin_layout LyX-Code
24701
24702 \end_layout
24703
24704 \begin_layout LyX-Code
24705 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
24706 \end_layout
24707
24708 \begin_layout LyX-Code
24709 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
24710 \end_layout
24711
24712 \begin_layout LyX-Code
24713 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
24714 \end_layout
24715
24716 \begin_layout LyX-Code
24717 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
24718 \end_layout
24719
24720 \begin_layout LyX-Code
24721 SECTION    NAME=bank4      RAM=gpr4
24722 \end_layout
24723
24724 \begin_layout LyX-Code
24725 SECTION    NAME=bank5      RAM=gpr5
24726 \end_layout
24727
24728 \begin_layout Standard
24729 The linker will recognise the section name set in the pragma statement and
24730  will position the variable at the memory bank set with the RAM field at
24731  the SECTION line in the linker script file.
24732 \end_layout
24733
24734 \begin_layout Subsection
24735 Header Files
24736 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24737
24738 \end_inset
24739
24740
24741 \end_layout
24742
24743 \begin_layout Standard
24744 There is one main header file
24745 \begin_inset LatexCommand \index{PIC16!Header files}
24746
24747 \end_inset
24748
24749  that can be included to the source files using the pic16
24750 \begin_inset LatexCommand \index{PIC16}
24751
24752 \end_inset
24753
24754  port.
24755  That file is the 
24756 \series bold
24757 pic18fregs.h
24758 \series default
24759 .
24760  This header file contains the definitions for the processor special registers,
24761  so it is necessary if the source accesses them.
24762  It can be included by adding the following line in the beginning of the
24763  file:
24764 \end_layout
24765
24766 \begin_layout LyX-Code
24767 #include <pic18fregs.h>
24768 \end_layout
24769
24770 \begin_layout Standard
24771 The specific microcontroller is selected within the pic18fregs.h automatically,
24772  so the same source can be used with a variety of devices.
24773 \end_layout
24774
24775 \begin_layout Subsection
24776 Libraries
24777 \end_layout
24778
24779 \begin_layout Standard
24780 The libraries
24781 \begin_inset LatexCommand \index{PIC16!Libraries}
24782
24783 \end_inset
24784
24785  that PIC16
24786 \begin_inset LatexCommand \index{PIC16}
24787
24788 \end_inset
24789
24790  port depends on are the microcontroller device libraries which contain
24791  the symbol definitions for the microcontroller special function registers.
24792  These libraries have the format pic18fxxxx.lib, where 
24793 \emph on
24794 xxxx
24795 \emph default
24796  is the microcontroller identification number.
24797  The specific library is selected automatically by the compiler at link
24798  stage according to the selected device.
24799 \end_layout
24800
24801 \begin_layout Standard
24802 Libraries are created with gplib which is part of the gputils package 
24803 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24804
24805 \end_inset
24806
24807 .
24808 \end_layout
24809
24810 \begin_layout Subsubsection*
24811 Building the libraries
24812 \end_layout
24813
24814 \begin_layout Standard
24815 Before using SDCC/pic16 there are some libraries that need to be compiled.
24816  This process is not done automatically by SDCC since not all users use
24817  SDCC for pic16 projects.
24818  So each user should compile the libraries separately.
24819 \end_layout
24820
24821 \begin_layout Standard
24822 The steps to compile the pic16 libraries under Linux are:
24823 \end_layout
24824
24825 \begin_layout LyX-Code
24826 cd device/lib/pic16
24827 \end_layout
24828
24829 \begin_layout LyX-Code
24830 ./configure
24831 \end_layout
24832
24833 \begin_layout LyX-Code
24834 make
24835 \end_layout
24836
24837 \begin_layout LyX-Code
24838 cd ..
24839 \end_layout
24840
24841 \begin_layout LyX-Code
24842 make model-pic16
24843 \end_layout
24844
24845 \begin_layout LyX-Code
24846 su -c 'make install'     # install the libraries, you need the root password
24847 \end_layout
24848
24849 \begin_layout Standard
24850 If you need to install the headers too, do:
24851 \end_layout
24852
24853 \begin_layout LyX-Code
24854 cd device/include
24855 \end_layout
24856
24857 \begin_layout LyX-Code
24858 su -c 'make install'     # install the headers, you need the root password
24859 \end_layout
24860
24861 \begin_layout Standard
24862 There exist a special target to build the I/O libraries.
24863  This target is not automatically build because it will build the I/O library
24864  for 
24865 \emph on
24866 every
24867 \emph default
24868  supported device.
24869  This way building will take quite a lot of time.
24870  Users are advised to edit the 
24871 \series bold
24872 device/lib/pic16/pics.build
24873 \series default
24874  file and then execute:
24875 \end_layout
24876
24877 \begin_layout LyX-Code
24878 make lib-io
24879 \end_layout
24880
24881 \begin_layout Subsection
24882 Memory Models
24883 \end_layout
24884
24885 \begin_layout Standard
24886 The following memory models are supported by the PIC16 port:
24887 \end_layout
24888
24889 \begin_layout Itemize
24890 small model
24891 \end_layout
24892
24893 \begin_layout Itemize
24894 large model
24895 \end_layout
24896
24897 \begin_layout Standard
24898 Memory model affects the default size of pointers within the source.
24899  The sizes are shown in the next table:
24900 \end_layout
24901
24902 \begin_layout Standard
24903 \align center
24904 \begin_inset Tabular
24905 <lyxtabular version="3" rows="3" columns="3">
24906 <features>
24907 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24908 <column alignment="center" valignment="top" leftline="true" width="0">
24909 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24910 <row topline="true" bottomline="true">
24911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24912 \begin_inset Text
24913
24914 \begin_layout Standard
24915 Pointer sizes according to memory model
24916 \end_layout
24917
24918 \end_inset
24919 </cell>
24920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24921 \begin_inset Text
24922
24923 \begin_layout Standard
24924 small model
24925 \end_layout
24926
24927 \end_inset
24928 </cell>
24929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24930 \begin_inset Text
24931
24932 \begin_layout Standard
24933 large model
24934 \end_layout
24935
24936 \end_inset
24937 </cell>
24938 </row>
24939 <row topline="true" bottomline="true">
24940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24941 \begin_inset Text
24942
24943 \begin_layout Standard
24944 code pointers
24945 \end_layout
24946
24947 \end_inset
24948 </cell>
24949 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24950 \begin_inset Text
24951
24952 \begin_layout Standard
24953 16-bits
24954 \end_layout
24955
24956 \end_inset
24957 </cell>
24958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24959 \begin_inset Text
24960
24961 \begin_layout Standard
24962 24-bits
24963 \end_layout
24964
24965 \end_inset
24966 </cell>
24967 </row>
24968 <row topline="true" bottomline="true">
24969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24970 \begin_inset Text
24971
24972 \begin_layout Standard
24973 data pointers
24974 \end_layout
24975
24976 \end_inset
24977 </cell>
24978 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24979 \begin_inset Text
24980
24981 \begin_layout Standard
24982 16-bits
24983 \end_layout
24984
24985 \end_inset
24986 </cell>
24987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24988 \begin_inset Text
24989
24990 \begin_layout Standard
24991 16-bits
24992 \end_layout
24993
24994 \end_inset
24995 </cell>
24996 </row>
24997 </lyxtabular>
24998
24999 \end_inset
25000
25001
25002 \end_layout
25003
25004 \begin_layout Standard
25005 It is advisable that all sources within a project are compiled with the
25006  same memory model.
25007  If one wants to override the default memory model, this can be done by
25008  declaring a pointer as 
25009 \series bold
25010 far
25011 \series default
25012  or 
25013 \series bold
25014 near
25015 \series default
25016 .
25017  Far selects large memory model's pointers, while near selects small memory
25018  model's pointers.
25019 \end_layout
25020
25021 \begin_layout Standard
25022 The standard device libraries (see 
25023 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25024
25025 \end_inset
25026
25027 ) contain no reference to pointers, so they can be used with both memory
25028  models.
25029 \end_layout
25030
25031 \begin_layout Subsection
25032 Stack
25033 \end_layout
25034
25035 \begin_layout Standard
25036 The stack
25037 \begin_inset LatexCommand \index{PIC16!stack}
25038
25039 \end_inset
25040
25041  implementation for the PIC16 port uses two indirect registers, FSR1 and
25042  FSR2.
25043 \end_layout
25044
25045 \begin_layout List
25046 \labelwidthstring 00.00.0000
25047 FSR1 is assigned as stack pointer
25048 \end_layout
25049
25050 \begin_layout List
25051 \labelwidthstring 00.00.0000
25052 FSR2 is assigned as frame pointer
25053 \end_layout
25054
25055 \begin_layout Standard
25056 The following stack models are supported by the PIC16 port
25057 \end_layout
25058
25059 \begin_layout Itemize
25060
25061 \noun on
25062 small
25063 \noun default
25064  model
25065 \end_layout
25066
25067 \begin_layout Itemize
25068
25069 \noun on
25070 large
25071 \noun default
25072  model
25073 \end_layout
25074
25075 \begin_layout Standard
25076
25077 \noun on
25078 Small
25079 \noun default
25080  model means that only the FSRxL byte is used to access stack and frame,
25081  while 
25082 \emph on
25083 \noun on
25084 large
25085 \emph default
25086 \noun default
25087  uses both FSRxL and FSRxH registers.
25088  The following table shows the stack/frame pointers sizes according to stack
25089  model and the maximum space they can address:
25090 \end_layout
25091
25092 \begin_layout Standard
25093 \align center
25094 \begin_inset Tabular
25095 <lyxtabular version="3" rows="3" columns="3">
25096 <features>
25097 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25098 <column alignment="center" valignment="top" leftline="true" width="0">
25099 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25100 <row topline="true" bottomline="true">
25101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25102 \begin_inset Text
25103
25104 \begin_layout Standard
25105 Stack & Frame pointer sizes according to stack model
25106 \end_layout
25107
25108 \end_inset
25109 </cell>
25110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25111 \begin_inset Text
25112
25113 \begin_layout Standard
25114 small
25115 \end_layout
25116
25117 \end_inset
25118 </cell>
25119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25120 \begin_inset Text
25121
25122 \begin_layout Standard
25123 large
25124 \end_layout
25125
25126 \end_inset
25127 </cell>
25128 </row>
25129 <row topline="true">
25130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25131 \begin_inset Text
25132
25133 \begin_layout Standard
25134 Stack pointer FSR1
25135 \end_layout
25136
25137 \end_inset
25138 </cell>
25139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25140 \begin_inset Text
25141
25142 \begin_layout Standard
25143 8-bits
25144 \end_layout
25145
25146 \end_inset
25147 </cell>
25148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25149 \begin_inset Text
25150
25151 \begin_layout Standard
25152 16-bits
25153 \end_layout
25154
25155 \end_inset
25156 </cell>
25157 </row>
25158 <row topline="true" bottomline="true">
25159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25160 \begin_inset Text
25161
25162 \begin_layout Standard
25163 Frame pointer FSR2
25164 \end_layout
25165
25166 \end_inset
25167 </cell>
25168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25169 \begin_inset Text
25170
25171 \begin_layout Standard
25172 8-bits
25173 \end_layout
25174
25175 \end_inset
25176 </cell>
25177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25178 \begin_inset Text
25179
25180 \begin_layout Standard
25181 16-bits
25182 \end_layout
25183
25184 \end_inset
25185 </cell>
25186 </row>
25187 </lyxtabular>
25188
25189 \end_inset
25190
25191
25192 \end_layout
25193
25194 \begin_layout Standard
25195
25196 \noun on
25197 Large 
25198 \noun default
25199 stack model is currently not working properly throughout the code generator.
25200  So its use is not advised.
25201  Also there are some other points that need special care:
25202 \newline
25203
25204 \end_layout
25205
25206 \begin_layout Enumerate
25207 Do not create stack sections with size more than one physical bank (that
25208  is 256 bytes)
25209 \end_layout
25210
25211 \begin_layout Enumerate
25212 Stack sections should no cross physical bank limits (i.e.
25213  #pragma stack 0x50 0x100)
25214 \end_layout
25215
25216 \begin_layout Standard
25217 These limitations are caused by the fact that only FSRxL is modified when
25218  using SMALL stack model, so no more than 256 bytes of stack can be used.
25219  This problem will disappear after LARGE model is fully implemented.
25220 \end_layout
25221
25222 \begin_layout Subsection
25223 Functions
25224 \end_layout
25225
25226 \begin_layout Standard
25227 In addition to the standard SDCC function keywords, PIC16
25228 \begin_inset LatexCommand \index{PIC16}
25229
25230 \end_inset
25231
25232  port makes available two more:
25233 \end_layout
25234
25235 \begin_layout List
25236 \labelwidthstring 00.00.0000
25237 wparam
25238 \begin_inset LatexCommand \index{PIC16!wparam}
25239
25240 \end_inset
25241
25242  Use the WREG to pass one byte of the first function argument.
25243  This improves speed but you may not use this for functions with arguments
25244  that are called via function pointers, otherwise the first byte of the
25245  first parameter will get lost.
25246  Usage:
25247 \end_layout
25248
25249 \begin_layout LyX-Code
25250 void func_wparam(int a) wparam
25251 \end_layout
25252
25253 \begin_layout LyX-Code
25254 {
25255 \end_layout
25256
25257 \begin_layout LyX-Code
25258     /* WREG hold the lower part of a */
25259 \end_layout
25260
25261 \begin_layout LyX-Code
25262     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25263  */
25264 \end_layout
25265
25266 \begin_layout LyX-Code
25267 ...
25268 \end_layout
25269
25270 \begin_layout LyX-Code
25271 }
25272 \end_layout
25273
25274 \begin_layout List
25275 \labelwidthstring 00.00.0000
25276 shadowregs
25277 \begin_inset LatexCommand \index{PIC16!shadowregs}
25278
25279 \end_inset
25280
25281  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25282  hardware shadow registers which hold the values of WREG, STATUS and BSR
25283  registers.
25284  This can be done by adding the keyword 
25285 \emph on
25286 shadowregs
25287 \emph default
25288  before the 
25289 \emph on
25290 interrupt
25291 \emph default
25292  keyword in the function's header.
25293 \end_layout
25294
25295 \begin_layout LyX-Code
25296 void isr_shadow(void) shadowregs interrupt 1
25297 \end_layout
25298
25299 \begin_layout LyX-Code
25300 {
25301 \end_layout
25302
25303 \begin_layout LyX-Code
25304 ...
25305 \end_layout
25306
25307 \begin_layout LyX-Code
25308 }
25309 \end_layout
25310
25311 \begin_layout Standard
25312
25313 \emph on
25314 shadowregs
25315 \emph default
25316  instructs the code generator not to store/restore WREG, STATUS, BSR when
25317  entering/exiting the ISR.
25318 \end_layout
25319
25320 \begin_layout Subsection
25321 Function return values
25322 \end_layout
25323
25324 \begin_layout Standard
25325 Return values from functions are placed to the appropriate registers following
25326  a modified Microchip policy optimized for SDCC.
25327  The following table shows these registers:
25328 \end_layout
25329
25330 \begin_layout Standard
25331 \align center
25332 \begin_inset Tabular
25333 <lyxtabular version="3" rows="6" columns="2">
25334 <features>
25335 <column alignment="center" valignment="top" leftline="true" width="0">
25336 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25337 <row topline="true" bottomline="true">
25338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25339 \begin_inset Text
25340
25341 \begin_layout Standard
25342 size
25343 \end_layout
25344
25345 \end_inset
25346 </cell>
25347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25348 \begin_inset Text
25349
25350 \begin_layout Standard
25351 destination register
25352 \end_layout
25353
25354 \end_inset
25355 </cell>
25356 </row>
25357 <row topline="true">
25358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25359 \begin_inset Text
25360
25361 \begin_layout Standard
25362 8 bits
25363 \end_layout
25364
25365 \end_inset
25366 </cell>
25367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25368 \begin_inset Text
25369
25370 \begin_layout Standard
25371 WREG
25372 \end_layout
25373
25374 \end_inset
25375 </cell>
25376 </row>
25377 <row topline="true">
25378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25379 \begin_inset Text
25380
25381 \begin_layout Standard
25382 16 bits
25383 \end_layout
25384
25385 \end_inset
25386 </cell>
25387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25388 \begin_inset Text
25389
25390 \begin_layout Standard
25391 PRODL:WREG
25392 \end_layout
25393
25394 \end_inset
25395 </cell>
25396 </row>
25397 <row topline="true">
25398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25399 \begin_inset Text
25400
25401 \begin_layout Standard
25402 24 bits
25403 \end_layout
25404
25405 \end_inset
25406 </cell>
25407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25408 \begin_inset Text
25409
25410 \begin_layout Standard
25411 PRODH:PRODL:WREG
25412 \end_layout
25413
25414 \end_inset
25415 </cell>
25416 </row>
25417 <row topline="true">
25418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25419 \begin_inset Text
25420
25421 \begin_layout Standard
25422 32 bits
25423 \end_layout
25424
25425 \end_inset
25426 </cell>
25427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25428 \begin_inset Text
25429
25430 \begin_layout Standard
25431 FSR0L:PRODH:PRODL:WREG
25432 \end_layout
25433
25434 \end_inset
25435 </cell>
25436 </row>
25437 <row topline="true" bottomline="true">
25438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25439 \begin_inset Text
25440
25441 \begin_layout Standard
25442 >32 bits
25443 \end_layout
25444
25445 \end_inset
25446 </cell>
25447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25448 \begin_inset Text
25449
25450 \begin_layout Standard
25451 on stack, FSR0 points to the beginning
25452 \end_layout
25453
25454 \end_inset
25455 </cell>
25456 </row>
25457 </lyxtabular>
25458
25459 \end_inset
25460
25461
25462 \end_layout
25463
25464 \begin_layout Subsection
25465 Interrupts
25466 \end_layout
25467
25468 \begin_layout Standard
25469 An interrupt
25470 \begin_inset LatexCommand \index{PIC16!interrupt}
25471
25472 \end_inset
25473
25474  service routine (ISR) is declared using the 
25475 \emph on
25476 interrupt
25477 \emph default
25478  keyword.
25479 \end_layout
25480
25481 \begin_layout LyX-Code
25482 void isr(void) interrupt 
25483 \emph on
25484 n
25485 \end_layout
25486
25487 \begin_layout LyX-Code
25488 {
25489 \end_layout
25490
25491 \begin_layout LyX-Code
25492 ...
25493 \end_layout
25494
25495 \begin_layout LyX-Code
25496 }
25497 \end_layout
25498
25499 \begin_layout Standard
25500
25501 \emph on
25502 n
25503 \emph default
25504  is the interrupt number, which for PIC18F devices can be:
25505 \end_layout
25506
25507 \begin_layout Standard
25508 \align center
25509 \begin_inset Tabular
25510 <lyxtabular version="3" rows="4" columns="3">
25511 <features>
25512 <column alignment="center" valignment="top" leftline="true" width="0">
25513 <column alignment="center" valignment="top" leftline="true" width="0">
25514 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25515 <row topline="true" bottomline="true">
25516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25517 \begin_inset Text
25518
25519 \begin_layout Standard
25520
25521 \emph on
25522 n
25523 \end_layout
25524
25525 \end_inset
25526 </cell>
25527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25528 \begin_inset Text
25529
25530 \begin_layout Standard
25531 Interrupt Vector
25532 \end_layout
25533
25534 \end_inset
25535 </cell>
25536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25537 \begin_inset Text
25538
25539 \begin_layout Standard
25540 Interrupt Vector Address
25541 \end_layout
25542
25543 \end_inset
25544 </cell>
25545 </row>
25546 <row topline="true">
25547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25548 \begin_inset Text
25549
25550 \begin_layout Standard
25551 0
25552 \end_layout
25553
25554 \end_inset
25555 </cell>
25556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25557 \begin_inset Text
25558
25559 \begin_layout Standard
25560 RESET vector
25561 \end_layout
25562
25563 \end_inset
25564 </cell>
25565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25566 \begin_inset Text
25567
25568 \begin_layout Standard
25569 0x000000
25570 \end_layout
25571
25572 \end_inset
25573 </cell>
25574 </row>
25575 <row topline="true">
25576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25577 \begin_inset Text
25578
25579 \begin_layout Standard
25580
25581 \family roman
25582 \series medium
25583 \shape up
25584 \size normal
25585 \emph off
25586 \bar no
25587 \noun off
25588 \color none
25589 1
25590 \end_layout
25591
25592 \end_inset
25593 </cell>
25594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25595 \begin_inset Text
25596
25597 \begin_layout Standard
25598
25599 \family roman
25600 \series medium
25601 \shape up
25602 \size normal
25603 \emph off
25604 \bar no
25605 \noun off
25606 \color none
25607 HIGH priority interrupts
25608 \end_layout
25609
25610 \end_inset
25611 </cell>
25612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25613 \begin_inset Text
25614
25615 \begin_layout Standard
25616 0x000008
25617 \end_layout
25618
25619 \end_inset
25620 </cell>
25621 </row>
25622 <row topline="true" bottomline="true">
25623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25624 \begin_inset Text
25625
25626 \begin_layout Standard
25627 2
25628 \end_layout
25629
25630 \end_inset
25631 </cell>
25632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25633 \begin_inset Text
25634
25635 \begin_layout Standard
25636 LOW priority interrupts
25637 \end_layout
25638
25639 \end_inset
25640 </cell>
25641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25642 \begin_inset Text
25643
25644 \begin_layout Standard
25645 0x000018
25646 \end_layout
25647
25648 \end_inset
25649 </cell>
25650 </row>
25651 </lyxtabular>
25652
25653 \end_inset
25654
25655
25656 \end_layout
25657
25658 \begin_layout Standard
25659 When generating assembly code for ISR the code generator places a 
25660 \noun on
25661 goto 
25662 \noun default
25663 instruction at the 
25664 \emph on
25665 Interrupt Vector Address
25666 \emph default
25667  which points at the genetated ISR.
25668  This single GOTO instruction is part of an automatically generated 
25669 \emph on
25670 interrupt entry point
25671 \emph default
25672  function.
25673  The actuall ISR code is placed as normally would in the code space.
25674  Upon interrupt request, the GOTO instruction is executed which jumps to
25675  the ISR code.
25676  When declaring interrupt functions as _naked this GOTO instruction is 
25677 \series bold
25678 not
25679 \series default
25680  generated.
25681  The whole interrupt functions is therefore placed at the Interrupt Vector
25682  Address of the specific interrupt.
25683  This is not a problem for the LOW priority interrupts, but it is a problem
25684  for the RESET and the HIGH priority interrupts because code may be written
25685  at the next interrupt´s vector address and cause undeterminate program
25686  behaviour if that interrupt is raised.
25687 \begin_inset Foot
25688 status open
25689
25690 \begin_layout Standard
25691 This is not a problem when
25692 \end_layout
25693
25694 \begin_layout Enumerate
25695 this is a HIGH interrupt ISR and LOW interrupts are 
25696 \emph on
25697 disabled
25698 \emph default
25699  or not used.
25700 \end_layout
25701
25702 \begin_layout Enumerate
25703 when the ISR is small enough not to reach the next interrupt´s vector address.
25704 \end_layout
25705
25706 \end_inset
25707
25708
25709 \end_layout
25710
25711 \begin_layout Standard
25712
25713 \emph on
25714 n
25715 \emph default
25716  is possible to be omitted.
25717  This way a function is generated similar to an ISR, but it is not assigned
25718  to any interrupt.
25719 \end_layout
25720
25721 \begin_layout Standard
25722 When entering an interrupt, currently the PIC16
25723 \begin_inset LatexCommand \index{PIC16}
25724
25725 \end_inset
25726
25727  port automatically saves the following registers:
25728 \end_layout
25729
25730 \begin_layout Itemize
25731 WREG
25732 \end_layout
25733
25734 \begin_layout Itemize
25735 STATUS
25736 \end_layout
25737
25738 \begin_layout Itemize
25739 BSR
25740 \end_layout
25741
25742 \begin_layout Itemize
25743 PROD (PRODL and PRODH)
25744 \end_layout
25745
25746 \begin_layout Itemize
25747 FSR0 (FSR0L and FSR0H)
25748 \end_layout
25749
25750 \begin_layout Standard
25751 These registers are restored upon return from the interrupt routine.
25752 \begin_inset Foot
25753 status open
25754
25755 \begin_layout Standard
25756 NOTE that when the _naked attribute is specified for an interrupt routine,
25757  then NO registers are stored or restored.
25758 \end_layout
25759
25760 \end_inset
25761
25762
25763 \end_layout
25764
25765 \begin_layout Subsection
25766 Generic Pointers
25767 \end_layout
25768
25769 \begin_layout Standard
25770 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25771  There are 3 types of generic pointers currently implemented data, code
25772  and eeprom pointers.
25773  They are differentiated by the value of the 7th and 6th bits of the upper
25774  byte:
25775 \end_layout
25776
25777 \begin_layout Standard
25778 \align center
25779 \begin_inset Tabular
25780 <lyxtabular version="3" rows="5" columns="5">
25781 <features>
25782 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25783 <column alignment="center" valignment="top" width="0">
25784 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25785 <column alignment="center" valignment="top" width="0">
25786 <column alignment="left" valignment="top" rightline="true" width="0">
25787 <row topline="true" bottomline="true">
25788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25789 \begin_inset Text
25790
25791 \begin_layout Standard
25792 pointer type
25793 \end_layout
25794
25795 \end_inset
25796 </cell>
25797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25798 \begin_inset Text
25799
25800 \begin_layout Standard
25801 7th bit
25802 \end_layout
25803
25804 \end_inset
25805 </cell>
25806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25807 \begin_inset Text
25808
25809 \begin_layout Standard
25810 6th bit
25811 \end_layout
25812
25813 \end_inset
25814 </cell>
25815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25816 \begin_inset Text
25817
25818 \begin_layout Standard
25819 rest of the pointer
25820 \end_layout
25821
25822 \end_inset
25823 </cell>
25824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25825 \begin_inset Text
25826
25827 \begin_layout Standard
25828 description
25829 \end_layout
25830
25831 \end_inset
25832 </cell>
25833 </row>
25834 <row topline="true" bottomline="true">
25835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25836 \begin_inset Text
25837
25838 \begin_layout Standard
25839 data 
25840 \end_layout
25841
25842 \end_inset
25843 </cell>
25844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25845 \begin_inset Text
25846
25847 \begin_layout Standard
25848 1
25849 \end_layout
25850
25851 \end_inset
25852 </cell>
25853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25854 \begin_inset Text
25855
25856 \begin_layout Standard
25857 0
25858 \end_layout
25859
25860 \end_inset
25861 </cell>
25862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25863 \begin_inset Text
25864
25865 \begin_layout Standard
25866
25867 \family typewriter
25868 \shape slanted
25869 \emph on
25870 uuuuuu uuuuxxxx xxxxxxxx
25871 \end_layout
25872
25873 \end_inset
25874 </cell>
25875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25876 \begin_inset Text
25877
25878 \begin_layout Standard
25879 a 12-bit data pointer in data RAM memory
25880 \end_layout
25881
25882 \end_inset
25883 </cell>
25884 </row>
25885 <row bottomline="true">
25886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25887 \begin_inset Text
25888
25889 \begin_layout Standard
25890 code
25891 \end_layout
25892
25893 \end_inset
25894 </cell>
25895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25896 \begin_inset Text
25897
25898 \begin_layout Standard
25899 0
25900 \end_layout
25901
25902 \end_inset
25903 </cell>
25904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25905 \begin_inset Text
25906
25907 \begin_layout Standard
25908 0
25909 \end_layout
25910
25911 \end_inset
25912 </cell>
25913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25914 \begin_inset Text
25915
25916 \begin_layout Standard
25917
25918 \family typewriter
25919 \shape slanted
25920 \emph on
25921 uxxxxx xxxxxxxx xxxxxxxx
25922 \end_layout
25923
25924 \end_inset
25925 </cell>
25926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25927 \begin_inset Text
25928
25929 \begin_layout Standard
25930 a 21-bit code pointer in FLASH memory
25931 \end_layout
25932
25933 \end_inset
25934 </cell>
25935 </row>
25936 <row bottomline="true">
25937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25938 \begin_inset Text
25939
25940 \begin_layout Standard
25941 eeprom
25942 \end_layout
25943
25944 \end_inset
25945 </cell>
25946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25947 \begin_inset Text
25948
25949 \begin_layout Standard
25950 0
25951 \end_layout
25952
25953 \end_inset
25954 </cell>
25955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25956 \begin_inset Text
25957
25958 \begin_layout Standard
25959 1
25960 \end_layout
25961
25962 \end_inset
25963 </cell>
25964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25965 \begin_inset Text
25966
25967 \begin_layout Standard
25968
25969 \family typewriter
25970 \shape slanted
25971 \emph on
25972 uuuuuu uuuuuuxx xxxxxxxx
25973 \end_layout
25974
25975 \end_inset
25976 </cell>
25977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25978 \begin_inset Text
25979
25980 \begin_layout Standard
25981 a 10-bit eeprom pointer in EEPROM memory
25982 \end_layout
25983
25984 \end_inset
25985 </cell>
25986 </row>
25987 <row bottomline="true">
25988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25989 \begin_inset Text
25990
25991 \begin_layout Standard
25992 (unimplemented)
25993 \end_layout
25994
25995 \end_inset
25996 </cell>
25997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25998 \begin_inset Text
25999
26000 \begin_layout Standard
26001 1
26002 \end_layout
26003
26004 \end_inset
26005 </cell>
26006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26007 \begin_inset Text
26008
26009 \begin_layout Standard
26010 1
26011 \end_layout
26012
26013 \end_inset
26014 </cell>
26015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26016 \begin_inset Text
26017
26018 \begin_layout Standard
26019
26020 \family typewriter
26021 \shape slanted
26022 \emph on
26023 xxxxxx xxxxxxxx xxxxxxxx
26024 \end_layout
26025
26026 \end_inset
26027 </cell>
26028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26029 \begin_inset Text
26030
26031 \begin_layout Standard
26032 unimplemented pointer type
26033 \end_layout
26034
26035 \end_inset
26036 </cell>
26037 </row>
26038 </lyxtabular>
26039
26040 \end_inset
26041
26042
26043 \end_layout
26044
26045 \begin_layout Standard
26046 Generic pointer are read and written with a set of library functions which
26047  read/write 1, 2, 3, 4 bytes.
26048 \end_layout
26049
26050 \begin_layout Subsection
26051 PIC16 C Libraries
26052 \end_layout
26053
26054 \begin_layout Subsubsection
26055 Standard I/O Streams
26056 \end_layout
26057
26058 \begin_layout Standard
26059 In the 
26060 \emph on
26061 stdio.h
26062 \emph default
26063  the type FILE is defined as:
26064 \end_layout
26065
26066 \begin_layout LyX-Code
26067 typedef char * FILE;
26068 \end_layout
26069
26070 \begin_layout Standard
26071 This type is the stream type implemented I/O in the PIC18F devices.
26072  Also the standard input and output streams are declared in stdio.h:
26073 \end_layout
26074
26075 \begin_layout LyX-Code
26076 extern FILE * stdin;
26077 \end_layout
26078
26079 \begin_layout LyX-Code
26080 extern FILE * stdout;
26081 \end_layout
26082
26083 \begin_layout Standard
26084 The FILE type is actually a generic pointer which defines one more type
26085  of generic pointers, the 
26086 \emph on
26087 stream 
26088 \emph default
26089 pointer.
26090  This new type has the format:
26091 \end_layout
26092
26093 \begin_layout Standard
26094 \align center
26095 \begin_inset Tabular
26096 <lyxtabular version="3" rows="2" columns="7">
26097 <features>
26098 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26099 <column alignment="center" valignment="top" width="0">
26100 <column alignment="center" valignment="top" leftline="true" width="0">
26101 <column alignment="center" valignment="top" leftline="true" width="0">
26102 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26103 <column alignment="center" valignment="top" width="0">
26104 <column alignment="left" valignment="top" rightline="true" width="0">
26105 <row topline="true" bottomline="true">
26106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26107 \begin_inset Text
26108
26109 \begin_layout Standard
26110 pointer type
26111 \end_layout
26112
26113 \end_inset
26114 </cell>
26115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26116 \begin_inset Text
26117
26118 \begin_layout Standard
26119 <7:6>
26120 \end_layout
26121
26122 \end_inset
26123 </cell>
26124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26125 \begin_inset Text
26126
26127 \begin_layout Standard
26128 <5>
26129 \end_layout
26130
26131 \end_inset
26132 </cell>
26133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26134 \begin_inset Text
26135
26136 \begin_layout Standard
26137 <4>
26138 \end_layout
26139
26140 \end_inset
26141 </cell>
26142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26143 \begin_inset Text
26144
26145 \begin_layout Standard
26146 <3:0>
26147 \end_layout
26148
26149 \end_inset
26150 </cell>
26151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26152 \begin_inset Text
26153
26154 \begin_layout Standard
26155 rest of the pointer
26156 \end_layout
26157
26158 \end_inset
26159 </cell>
26160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26161 \begin_inset Text
26162
26163 \begin_layout Standard
26164 descrption
26165 \end_layout
26166
26167 \end_inset
26168 </cell>
26169 </row>
26170 <row topline="true" bottomline="true">
26171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26172 \begin_inset Text
26173
26174 \begin_layout Standard
26175 stream
26176 \end_layout
26177
26178 \end_inset
26179 </cell>
26180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26181 \begin_inset Text
26182
26183 \begin_layout Standard
26184 00
26185 \end_layout
26186
26187 \end_inset
26188 </cell>
26189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26190 \begin_inset Text
26191
26192 \begin_layout Standard
26193 1
26194 \end_layout
26195
26196 \end_inset
26197 </cell>
26198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26199 \begin_inset Text
26200
26201 \begin_layout Standard
26202 0
26203 \end_layout
26204
26205 \end_inset
26206 </cell>
26207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26208 \begin_inset Text
26209
26210 \begin_layout Standard
26211 nnnn
26212 \end_layout
26213
26214 \end_inset
26215 </cell>
26216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26217 \begin_inset Text
26218
26219 \begin_layout Standard
26220
26221 \family typewriter
26222 \shape slanted
26223 \emph on
26224 uuuuuuuu uuuuuuuu
26225 \end_layout
26226
26227 \end_inset
26228 </cell>
26229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26230 \begin_inset Text
26231
26232 \begin_layout Standard
26233 upper byte high nubble is 0x2n, the rest are zeroes
26234 \end_layout
26235
26236 \end_inset
26237 </cell>
26238 </row>
26239 </lyxtabular>
26240
26241 \end_inset
26242
26243
26244 \end_layout
26245
26246 \begin_layout Standard
26247 Currently implemented there are 3 types of streams defined:
26248 \end_layout
26249
26250 \begin_layout Standard
26251 \align center
26252 \begin_inset Tabular
26253 <lyxtabular version="3" rows="4" columns="4">
26254 <features>
26255 <column alignment="center" valignment="top" leftline="true" width="0">
26256 <column alignment="center" valignment="top" leftline="true" width="0">
26257 <column alignment="center" valignment="top" leftline="true" width="0">
26258 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26259 <row topline="true" bottomline="true">
26260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26261 \begin_inset Text
26262
26263 \begin_layout Standard
26264 stream type
26265 \end_layout
26266
26267 \end_inset
26268 </cell>
26269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26270 \begin_inset Text
26271
26272 \begin_layout Standard
26273 value
26274 \end_layout
26275
26276 \end_inset
26277 </cell>
26278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26279 \begin_inset Text
26280
26281 \begin_layout Standard
26282 module
26283 \end_layout
26284
26285 \end_inset
26286 </cell>
26287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26288 \begin_inset Text
26289
26290 \begin_layout Standard
26291 description
26292 \end_layout
26293
26294 \end_inset
26295 </cell>
26296 </row>
26297 <row topline="true">
26298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26299 \begin_inset Text
26300
26301 \begin_layout Standard
26302 STREAM_USART
26303 \end_layout
26304
26305 \end_inset
26306 </cell>
26307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26308 \begin_inset Text
26309
26310 \begin_layout Standard
26311
26312 \family typewriter
26313 0x200000UL
26314 \end_layout
26315
26316 \end_inset
26317 </cell>
26318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26319 \begin_inset Text
26320
26321 \begin_layout Standard
26322 USART
26323 \end_layout
26324
26325 \end_inset
26326 </cell>
26327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26328 \begin_inset Text
26329
26330 \begin_layout Standard
26331 Writes/Reads characters via the USART peripheral
26332 \end_layout
26333
26334 \end_inset
26335 </cell>
26336 </row>
26337 <row topline="true">
26338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26339 \begin_inset Text
26340
26341 \begin_layout Standard
26342 STREAM_MSSP
26343 \end_layout
26344
26345 \end_inset
26346 </cell>
26347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26348 \begin_inset Text
26349
26350 \begin_layout Standard
26351
26352 \family typewriter
26353 0x210000UL
26354 \end_layout
26355
26356 \end_inset
26357 </cell>
26358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26359 \begin_inset Text
26360
26361 \begin_layout Standard
26362 MSSP
26363 \end_layout
26364
26365 \end_inset
26366 </cell>
26367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26368 \begin_inset Text
26369
26370 \begin_layout Standard
26371 Writes/Reads characters via the MSSP peripheral
26372 \end_layout
26373
26374 \end_inset
26375 </cell>
26376 </row>
26377 <row topline="true" bottomline="true">
26378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26379 \begin_inset Text
26380
26381 \begin_layout Standard
26382 STREAM_USER
26383 \end_layout
26384
26385 \end_inset
26386 </cell>
26387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26388 \begin_inset Text
26389
26390 \begin_layout Standard
26391
26392 \family typewriter
26393 0x2f0000UL
26394 \end_layout
26395
26396 \end_inset
26397 </cell>
26398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26399 \begin_inset Text
26400
26401 \begin_layout Standard
26402 (none)
26403 \end_layout
26404
26405 \end_inset
26406 </cell>
26407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26408 \begin_inset Text
26409
26410 \begin_layout Standard
26411 Writes/Reads characters via used defined functions
26412 \end_layout
26413
26414 \end_inset
26415 </cell>
26416 </row>
26417 </lyxtabular>
26418
26419 \end_inset
26420
26421
26422 \end_layout
26423
26424 \begin_layout Standard
26425 The stream identifiers are declared as macros in the stdio.h header.
26426 \end_layout
26427
26428 \begin_layout Standard
26429 In the libc library there exist the functions that are used to write to
26430  each of the above streams.
26431  These are
26432 \end_layout
26433
26434 \begin_layout List
26435 \labelwidthstring 00.00.0000
26436 _
26437 \begin_inset ERT
26438 status collapsed
26439
26440 \begin_layout Standard
26441
26442
26443 \backslash
26444 /
26445 \end_layout
26446
26447 \end_inset
26448
26449 _stream_usart_putchar writes a character at the USART stream
26450 \end_layout
26451
26452 \begin_layout List
26453 \labelwidthstring 00.00.0000
26454 _
26455 \begin_inset ERT
26456 status collapsed
26457
26458 \begin_layout Standard
26459
26460
26461 \backslash
26462 /
26463 \end_layout
26464
26465 \end_inset
26466
26467 _stream_mssp_putchar writes a character at the MSSP stream
26468 \end_layout
26469
26470 \begin_layout List
26471 \labelwidthstring 00.00.0000
26472 putchar dummy function.
26473  This writes a character to a user specified manner.
26474 \end_layout
26475
26476 \begin_layout Standard
26477 In order to increase performance 
26478 \emph on
26479 putchar 
26480 \emph default
26481 is declared in stdio.h as having its parameter in WREG (it has the wparam
26482  keyword).
26483  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26484  in a user-friendly way.
26485  
26486 \emph on
26487 arg
26488 \emph default
26489  is the name of the variable that holds the character to print.
26490  An example follows:
26491 \end_layout
26492
26493 \begin_layout LyX-Code
26494 #include <pic18fregs.h>
26495 \newline
26496 #include <stdio.h>
26497 \newline
26498
26499 \newline
26500 PUTCHAR( c )
26501 \end_layout
26502
26503 \begin_layout LyX-Code
26504 {
26505 \end_layout
26506
26507 \begin_layout LyX-Code
26508     PORTA = c;    /* dump character c to PORTA */
26509 \end_layout
26510
26511 \begin_layout LyX-Code
26512
26513 \newline
26514
26515 \newline
26516 void main(void)
26517 \end_layout
26518
26519 \begin_layout LyX-Code
26520 {
26521 \end_layout
26522
26523 \begin_layout LyX-Code
26524     stdout = STREAM_USER;    /* this is not necessary, since stdout points
26525 \end_layout
26526
26527 \begin_layout LyX-Code
26528                               * by default to STREAM_USER */
26529 \end_layout
26530
26531 \begin_layout LyX-Code
26532     printf (¨This is a printf test
26533 \backslash
26534 n¨);
26535 \end_layout
26536
26537 \begin_layout LyX-Code
26538 }
26539 \end_layout
26540
26541 \begin_layout LyX-Code
26542
26543 \end_layout
26544
26545 \begin_layout Subsubsection
26546 Printing functions
26547 \end_layout
26548
26549 \begin_layout Standard
26550 PIC16 contains an implementation of the printf-family of functions.
26551  There exist the following functions:
26552 \end_layout
26553
26554 \begin_layout LyX-Code
26555 extern unsigned int sprintf(char *buf, char *fmt, ...);
26556 \end_layout
26557
26558 \begin_layout LyX-Code
26559 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26560 \end_layout
26561
26562 \begin_layout LyX-Code
26563
26564 \end_layout
26565
26566 \begin_layout LyX-Code
26567 extern unsigned int printf(char *fmt, ...);
26568 \end_layout
26569
26570 \begin_layout LyX-Code
26571 extern unsigned int vprintf(char *fmt, va_lista ap);
26572 \end_layout
26573
26574 \begin_layout LyX-Code
26575
26576 \end_layout
26577
26578 \begin_layout LyX-Code
26579 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26580 \end_layout
26581
26582 \begin_layout LyX-Code
26583 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26584 \end_layout
26585
26586 \begin_layout Standard
26587 For sprintf and vsprintf 
26588 \emph on
26589 buf 
26590 \emph default
26591 should normally be a data pointer where the resulting string will be placed.
26592  No range checking is done so the user should allocate the necessery buffer.
26593  For fprintf and vfprintf 
26594 \emph on
26595 fp
26596 \emph default
26597  should be a stream pointer (i.e.
26598  stdout, STREAM_MSSP, etc...).
26599 \end_layout
26600
26601 \begin_layout Subsubsection
26602 Signals
26603 \end_layout
26604
26605 \begin_layout Standard
26606 The PIC18F family of microcontrollers supports a number of interrupt sources.
26607  A list of these interrupts is shown in the following table:
26608 \end_layout
26609
26610 \begin_layout Standard
26611 \align center
26612 \begin_inset Tabular
26613 <lyxtabular version="3" rows="11" columns="4">
26614 <features>
26615 <column alignment="left" valignment="top" leftline="true" width="0">
26616 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26617 <column alignment="left" valignment="top" leftline="true" width="0">
26618 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26619 <row topline="true" bottomline="true">
26620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26621 \begin_inset Text
26622
26623 \begin_layout Standard
26624 signal name
26625 \end_layout
26626
26627 \end_inset
26628 </cell>
26629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26630 \begin_inset Text
26631
26632 \begin_layout Standard
26633 description
26634 \end_layout
26635
26636 \end_inset
26637 </cell>
26638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26639 \begin_inset Text
26640
26641 \begin_layout Standard
26642 signal name
26643 \end_layout
26644
26645 \end_inset
26646 </cell>
26647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26648 \begin_inset Text
26649
26650 \begin_layout Standard
26651 descritpion
26652 \end_layout
26653
26654 \end_inset
26655 </cell>
26656 </row>
26657 <row topline="true">
26658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26659 \begin_inset Text
26660
26661 \begin_layout Standard
26662 SIG_RB
26663 \end_layout
26664
26665 \end_inset
26666 </cell>
26667 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26668 \begin_inset Text
26669
26670 \begin_layout Standard
26671 PORTB change interrupt
26672 \end_layout
26673
26674 \end_inset
26675 </cell>
26676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26677 \begin_inset Text
26678
26679 \begin_layout Standard
26680 SIG_EE
26681 \end_layout
26682
26683 \end_inset
26684 </cell>
26685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26686 \begin_inset Text
26687
26688 \begin_layout Standard
26689 EEPROM/FLASH write complete interrupt
26690 \end_layout
26691
26692 \end_inset
26693 </cell>
26694 </row>
26695 <row topline="true">
26696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26697 \begin_inset Text
26698
26699 \begin_layout Standard
26700 SIG_INT0
26701 \end_layout
26702
26703 \end_inset
26704 </cell>
26705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26706 \begin_inset Text
26707
26708 \begin_layout Standard
26709 INT0 external interrupt
26710 \end_layout
26711
26712 \end_inset
26713 </cell>
26714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26715 \begin_inset Text
26716
26717 \begin_layout Standard
26718 SIG_BCOL
26719 \end_layout
26720
26721 \end_inset
26722 </cell>
26723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26724 \begin_inset Text
26725
26726 \begin_layout Standard
26727 Bus collision interrupt
26728 \end_layout
26729
26730 \end_inset
26731 </cell>
26732 </row>
26733 <row topline="true">
26734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26735 \begin_inset Text
26736
26737 \begin_layout Standard
26738 SIG_INT1
26739 \end_layout
26740
26741 \end_inset
26742 </cell>
26743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26744 \begin_inset Text
26745
26746 \begin_layout Standard
26747 INT1 external interrupt
26748 \end_layout
26749
26750 \end_inset
26751 </cell>
26752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26753 \begin_inset Text
26754
26755 \begin_layout Standard
26756 SIG_LVD
26757 \end_layout
26758
26759 \end_inset
26760 </cell>
26761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26762 \begin_inset Text
26763
26764 \begin_layout Standard
26765 Low voltage detect interrupt
26766 \end_layout
26767
26768 \end_inset
26769 </cell>
26770 </row>
26771 <row topline="true">
26772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26773 \begin_inset Text
26774
26775 \begin_layout Standard
26776 SIG_INT2
26777 \end_layout
26778
26779 \end_inset
26780 </cell>
26781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26782 \begin_inset Text
26783
26784 \begin_layout Standard
26785 INT2 external interrupt
26786 \end_layout
26787
26788 \end_inset
26789 </cell>
26790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26791 \begin_inset Text
26792
26793 \begin_layout Standard
26794 SIG_PSP
26795 \end_layout
26796
26797 \end_inset
26798 </cell>
26799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26800 \begin_inset Text
26801
26802 \begin_layout Standard
26803 Parallel slave port interrupt
26804 \end_layout
26805
26806 \end_inset
26807 </cell>
26808 </row>
26809 <row topline="true">
26810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26811 \begin_inset Text
26812
26813 \begin_layout Standard
26814 SIG_CCP1
26815 \end_layout
26816
26817 \end_inset
26818 </cell>
26819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26820 \begin_inset Text
26821
26822 \begin_layout Standard
26823 CCP1 module interrupt
26824 \end_layout
26825
26826 \end_inset
26827 </cell>
26828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26829 \begin_inset Text
26830
26831 \begin_layout Standard
26832 SIG_AD
26833 \end_layout
26834
26835 \end_inset
26836 </cell>
26837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26838 \begin_inset Text
26839
26840 \begin_layout Standard
26841 AD convertion complete interrupt
26842 \end_layout
26843
26844 \end_inset
26845 </cell>
26846 </row>
26847 <row topline="true">
26848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26849 \begin_inset Text
26850
26851 \begin_layout Standard
26852 SIG_CCP2
26853 \end_layout
26854
26855 \end_inset
26856 </cell>
26857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26858 \begin_inset Text
26859
26860 \begin_layout Standard
26861 CCP2 module interrupt
26862 \end_layout
26863
26864 \end_inset
26865 </cell>
26866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26867 \begin_inset Text
26868
26869 \begin_layout Standard
26870 SIG_RC
26871 \end_layout
26872
26873 \end_inset
26874 </cell>
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26876 \begin_inset Text
26877
26878 \begin_layout Standard
26879 USART receive interrupt
26880 \end_layout
26881
26882 \end_inset
26883 </cell>
26884 </row>
26885 <row topline="true">
26886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26887 \begin_inset Text
26888
26889 \begin_layout Standard
26890 SIG_TMR0
26891 \end_layout
26892
26893 \end_inset
26894 </cell>
26895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26896 \begin_inset Text
26897
26898 \begin_layout Standard
26899 TMR0 overflow interrupt
26900 \end_layout
26901
26902 \end_inset
26903 </cell>
26904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26905 \begin_inset Text
26906
26907 \begin_layout Standard
26908 SIG_TX
26909 \end_layout
26910
26911 \end_inset
26912 </cell>
26913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26914 \begin_inset Text
26915
26916 \begin_layout Standard
26917 USART transmit interrupt
26918 \end_layout
26919
26920 \end_inset
26921 </cell>
26922 </row>
26923 <row topline="true">
26924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26925 \begin_inset Text
26926
26927 \begin_layout Standard
26928 SIG_TMR1
26929 \end_layout
26930
26931 \end_inset
26932 </cell>
26933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26934 \begin_inset Text
26935
26936 \begin_layout Standard
26937 TMR1 overflow interrupt
26938 \end_layout
26939
26940 \end_inset
26941 </cell>
26942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26943 \begin_inset Text
26944
26945 \begin_layout Standard
26946 SIG_MSSP
26947 \end_layout
26948
26949 \end_inset
26950 </cell>
26951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26952 \begin_inset Text
26953
26954 \begin_layout Standard
26955 SSP receive/transmit interrupt
26956 \end_layout
26957
26958 \end_inset
26959 </cell>
26960 </row>
26961 <row topline="true">
26962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26963 \begin_inset Text
26964
26965 \begin_layout Standard
26966 SIG_TMR2
26967 \end_layout
26968
26969 \end_inset
26970 </cell>
26971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26972 \begin_inset Text
26973
26974 \begin_layout Standard
26975 TMR2 matches PR2 interrupt
26976 \end_layout
26977
26978 \end_inset
26979 </cell>
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26981 \begin_inset Text
26982
26983 \begin_layout Standard
26984
26985 \end_layout
26986
26987 \end_inset
26988 </cell>
26989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26990 \begin_inset Text
26991
26992 \begin_layout Standard
26993
26994 \end_layout
26995
26996 \end_inset
26997 </cell>
26998 </row>
26999 <row topline="true" bottomline="true">
27000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27001 \begin_inset Text
27002
27003 \begin_layout Standard
27004 SIG_TMR3
27005 \end_layout
27006
27007 \end_inset
27008 </cell>
27009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27010 \begin_inset Text
27011
27012 \begin_layout Standard
27013 TMR3 overflow interrupt
27014 \end_layout
27015
27016 \end_inset
27017 </cell>
27018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27019 \begin_inset Text
27020
27021 \begin_layout Standard
27022
27023 \end_layout
27024
27025 \end_inset
27026 </cell>
27027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27028 \begin_inset Text
27029
27030 \begin_layout Standard
27031
27032 \end_layout
27033
27034 \end_inset
27035 </cell>
27036 </row>
27037 </lyxtabular>
27038
27039 \end_inset
27040
27041
27042 \end_layout
27043
27044 \begin_layout Standard
27045 The prototypes for these names are defined in the header file 
27046 \emph on
27047 signal.h
27048 \emph default
27049  .
27050 \end_layout
27051
27052 \begin_layout Standard
27053 In order to simplify signal handling, a number of macros is provided:
27054 \end_layout
27055
27056 \begin_layout List
27057 \labelwidthstring 00.00.0000
27058 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27059  high priority interrupts.
27060  
27061 \emph on
27062 name
27063 \emph default
27064  is the function name to use.
27065 \end_layout
27066
27067 \begin_layout List
27068 \labelwidthstring 00.00.0000
27069 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27070  low priority interrupt.
27071  
27072 \emph on
27073 name
27074 \emph default
27075  is the function name to use.
27076 \end_layout
27077
27078 \begin_layout List
27079 \labelwidthstring 00.00.0000
27080 DEF_HANDLER(sig,handler) define a handler for signal 
27081 \emph on
27082 sig.
27083 \end_layout
27084
27085 \begin_layout List
27086 \labelwidthstring 00.00.0000
27087 END_DEF end the declaration of the dispatch table.
27088 \end_layout
27089
27090 \begin_layout Standard
27091 Additionally there are two more macros to simplify the declaration of the
27092  signal handler:
27093 \end_layout
27094
27095 \begin_layout List
27096 \labelwidthstring 00.00.0000
27097
27098 \series medium
27099 SIGHANDLER(handler) 
27100 \series default
27101 this declares the function prototype for the 
27102 \emph on
27103 handler
27104 \emph default
27105  function.
27106 \end_layout
27107
27108 \begin_layout List
27109 \labelwidthstring 00.00.0000
27110 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27111 \end_layout
27112
27113 \begin_layout Standard
27114 An example of using the macros above is shown below:
27115 \end_layout
27116
27117 \begin_layout LyX-Code
27118 #include <pic18fregs.h>
27119 \end_layout
27120
27121 \begin_layout LyX-Code
27122 #include <signal.h>
27123 \newline
27124
27125 \newline
27126 DEF_INTHIGH(high_int)
27127 \end_layout
27128
27129 \begin_layout LyX-Code
27130 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27131 \end_layout
27132
27133 \begin_layout LyX-Code
27134 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27135 \end_layout
27136
27137 \begin_layout LyX-Code
27138 END_DEF
27139 \newline
27140
27141 \newline
27142 SIGHANDLER(_tmr0_handler)
27143 \end_layout
27144
27145 \begin_layout LyX-Code
27146 {
27147 \end_layout
27148
27149 \begin_layout LyX-Code
27150   /* action to be taken when timer 0 overflows */
27151 \end_layout
27152
27153 \begin_layout LyX-Code
27154 }
27155 \newline
27156
27157 \newline
27158 SIGHANDLERNAKED(_bcol_handler)
27159 \end_layout
27160
27161 \begin_layout LyX-Code
27162 {
27163 \end_layout
27164
27165 \begin_layout LyX-Code
27166   _asm
27167 \end_layout
27168
27169 \begin_layout LyX-Code
27170     /* action to be taken when bus collision occurs */
27171 \end_layout
27172
27173 \begin_layout LyX-Code
27174     retfie
27175 \end_layout
27176
27177 \begin_layout LyX-Code
27178  _endasm;
27179 \end_layout
27180
27181 \begin_layout LyX-Code
27182 }
27183 \end_layout
27184
27185 \begin_layout Standard
27186
27187 \series bold
27188 NOTES:
27189 \series default
27190  Special care should be taken when using the above scheme:
27191 \end_layout
27192
27193 \begin_layout Itemize
27194 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27195 \end_layout
27196
27197 \begin_layout Itemize
27198 when declaring SIGHANDLERNAKED handler never forget to use 
27199 \emph on
27200 retfie
27201 \emph default
27202  for proper returning.
27203 \end_layout
27204
27205 \begin_layout Subsection
27206 PIC16 Port -- Tips
27207 \end_layout
27208
27209 \begin_layout Standard
27210 Here you can find some general tips for compiling programs with SDCC/pic16.
27211 \end_layout
27212
27213 \begin_layout Subsubsection
27214 Stack size
27215 \end_layout
27216
27217 \begin_layout Standard
27218 The default stack
27219 \begin_inset LatexCommand \index{PIC16!stack}
27220
27221 \end_inset
27222
27223  size (that is 64 bytes) probably is enough for many programs.
27224  One must take care that when there are many levels of function nesting,
27225  or there is excessive usage of stack, its size should be extended.
27226  An example of such a case is the printf/sprintf family of functions.
27227  If you encounter problems like not being able to print integers, then you
27228  need to set the stack size around the maximum (256 for small stack model).
27229  The following diagram shows what happens when calling printf to print an
27230  integer:
27231 \end_layout
27232
27233 \begin_layout LyX-Code
27234 printf () --> ltoa () --> ultoa () --> divschar ()
27235 \end_layout
27236
27237 \begin_layout Standard
27238 It is should be understood that stack is easily consumed when calling complicate
27239 d functions.
27240  Using command line arguments like -
27241 \begin_inset ERT
27242 status collapsed
27243
27244 \begin_layout Standard
27245
27246
27247 \backslash
27248 /
27249 \end_layout
27250
27251 \end_inset
27252
27253 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27254  stack frames.
27255  Other ways to reduce stack usage may exist.
27256 \end_layout
27257
27258 \begin_layout Subsection
27259 Known bugs
27260 \end_layout
27261
27262 \begin_layout Standard
27263 The PIC16 Port currently does not pass SDCC's regression test
27264 \begin_inset LatexCommand \index{Regression test (PIC16)}
27265
27266 \end_inset
27267
27268  suite (see section 
27269 \begin_inset LatexCommand \ref{sec:Quality-control}
27270
27271 \end_inset
27272
27273 ) and thus the snapshot build regression tests for the PIC16 target are
27274  currently disabled for all hosts
27275 \emph on
27276 .
27277 \end_layout
27278
27279 \begin_layout Chapter
27280 Debugging
27281 \end_layout
27282
27283 \begin_layout Standard
27284 There are several approaches to debugging your code.
27285  This chapter is meant to show your options and to give detail on some of
27286  them:
27287 \newline
27288
27289 \newline
27290 When writing your code:
27291 \end_layout
27292
27293 \begin_layout Itemize
27294 write your code with debugging in mind (avoid duplicating code, put conceptually
27295  similar variables into structs, use structured code, have strategic points
27296  within your code where all variables are consistent, ...)
27297 \end_layout
27298
27299 \begin_layout Itemize
27300 run a syntax-checking tool like splint
27301 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27302
27303 \end_inset
27304
27305
27306 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27307
27308 \end_inset
27309
27310  (see -
27311 \begin_inset ERT
27312 status collapsed
27313
27314 \begin_layout Standard
27315
27316
27317 \backslash
27318 /
27319 \end_layout
27320
27321 \end_inset
27322
27323 -more-pedantic 
27324 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27325
27326 \end_inset
27327
27328 ) over the code.
27329 \end_layout
27330
27331 \begin_layout Itemize
27332 for the high level code use a C-compiler (like f.e.
27333  GCC) to compile run and debug the code on your host.
27334  See (see -
27335 \begin_inset ERT
27336 status collapsed
27337
27338 \begin_layout Standard
27339
27340
27341 \backslash
27342 /
27343 \end_layout
27344
27345 \end_inset
27346
27347 -more-pedantic 
27348 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27349
27350 \end_inset
27351
27352 ) on how to handle syntax extensions like __xdata, __at(), ...
27353  
27354 \end_layout
27355
27356 \begin_layout Itemize
27357 use another C-compiler to compile code for your target.
27358  Always an option but not recommended:) And not very likely to help you.
27359  If you seriously consider walking this path you should at least occasionally
27360  check portability of your code.
27361  Most commercial compiler vendors will offer an evaluation version so you
27362  can test compile your code or snippets of your code.
27363 \end_layout
27364
27365 \begin_layout Standard
27366 Debugging on a simulator:
27367 \end_layout
27368
27369 \begin_layout Itemize
27370 there is a separate section about SDCDB (section 
27371 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27372
27373 \end_inset
27374
27375 ) below.
27376 \end_layout
27377
27378 \begin_layout Itemize
27379 or (8051 specific) use a freeware/commercial simulator which interfaces
27380  to the AOMF
27381 \begin_inset LatexCommand \index{AOMF, AOMF51}
27382
27383 \end_inset
27384
27385  file (see 
27386 \begin_inset LatexCommand \ref{OMF file}
27387
27388 \end_inset
27389
27390 ) optionally generated by SDCC.
27391 \end_layout
27392
27393 \begin_layout Standard
27394 Debugging On-target: 
27395 \end_layout
27396
27397 \begin_layout Itemize
27398 use a MCU port pin to serially output debug data to the RS232 port of your
27399  host.
27400  You'll probably want some level shifting device typically involving a MAX232
27401  or similar IC.
27402  If the hardware serial port of the MCU is not available search for 'Software
27403  UART' in your favourite search machine.
27404 \end_layout
27405
27406 \begin_layout Itemize
27407 use an on-target monitor.
27408  In this context a monitor is a small program which usually accepts commands
27409  via a serial line and allows to set program counter, to single step through
27410  a program and read/write memory locations.
27411  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27412  
27413 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27414
27415 \end_inset
27416
27417 ).
27418 \end_layout
27419
27420 \begin_layout Itemize
27421 toggle MCU port pins at strategic points within your code and use an oscilloscop
27422 e.
27423  A 
27424 \emph on
27425 digital oscilloscope
27426 \emph default
27427
27428 \begin_inset LatexCommand \index{Oscilloscope}
27429
27430 \end_inset
27431
27432  with deep trace memory is really helpful especially if you have to debug
27433  a realtime application.
27434  If you need to monitor more pins than your oscilloscope provides you can
27435  sometimes get away with a small R-2R network.
27436  On a single channel oscilloscope you could f.e.
27437  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27438 k
27439 \begin_inset Formula $\Omega$
27440 \end_inset
27441
27442  resistor and the other one by a 5\InsetSpace ~
27443 k
27444 \begin_inset Formula $\Omega$
27445 \end_inset
27446
27447  resistor to the oscilloscope probe (check output drive capability of the
27448  pins you want to monitor).
27449  If you need to monitor many more pins a 
27450 \emph on
27451 logic analyzer
27452 \emph default
27453  will be handy.
27454 \end_layout
27455
27456 \begin_layout Itemize
27457 use an ICE (
27458 \emph on
27459 i
27460 \emph default
27461
27462 \emph on
27463 c
27464 \emph default
27465 ircuit 
27466 \emph on
27467 e
27468 \emph default
27469 mulator
27470 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27471
27472 \end_inset
27473
27474 ).
27475  Usually very expensive.
27476  And very nice to have too.
27477  And usually locks you (for years...) to the devices the ICE can emulate.
27478  
27479 \end_layout
27480
27481 \begin_layout Itemize
27482 use a remote debugger.
27483  In most 8-bit systems the symbol information is not available on the target,
27484  and a complete debugger is too bulky for the target system.
27485  Therefore usually a debugger on the host system connects to an on-target
27486  debugging stub which accepts only primitive commands.
27487  
27488 \newline
27489 Terms to enter into your favourite search engine could be 'remote debugging',
27490  'gdb stub' or 'inferior debugger'.
27491  (is there one?)
27492 \end_layout
27493
27494 \begin_layout Itemize
27495 use an on target hardware debugger.
27496  Some of the more modern MCUs include hardware support for setting break
27497  points and monitoring/changing variables by using dedicated hardware pins.
27498  This facility doesn't require additional code to run on the target and
27499  
27500 \emph on
27501 usually
27502 \emph default
27503  doesn't affect runtime behaviour until a breakpoint is hit.
27504  For the mcs51 most hardware debuggers use the AOMF
27505 \begin_inset LatexCommand \index{AOMF, AOMF51}
27506
27507 \end_inset
27508
27509  file (see 
27510 \begin_inset LatexCommand \ref{OMF file}
27511
27512 \end_inset
27513
27514 ) as input file.
27515  
27516 \end_layout
27517
27518 \begin_layout Standard
27519 Last not least:
27520 \end_layout
27521
27522 \begin_layout Itemize
27523 if you are not familiar with any of the following terms you're likely to
27524  run into problems rather sooner than later: 
27525 \emph on
27526 volatile
27527 \emph default
27528
27529 \emph on
27530 atomic
27531 \emph default
27532
27533 \emph on
27534 memory map
27535 \emph default
27536
27537 \emph on
27538 overlay
27539 \emph default
27540 .
27541  As an embedded programmer you 
27542 \emph on
27543 have
27544 \emph default
27545  to know them so why not look them up 
27546 \emph on
27547 before
27548 \emph default
27549  you have problems?)
27550 \end_layout
27551
27552 \begin_layout Itemize
27553 tell someone else about your problem (actually this is a surprisingly effective
27554  means to hunt down the bug even if the listener is not familiar with your
27555  environment).
27556  As 'failure to communicate' is probably one of the job-induced deformations
27557  of an embedded programmer this is highly encouraged.
27558 \end_layout
27559
27560 \begin_layout Section
27561 Debugging with SDCDB
27562 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27563
27564 \end_inset
27565
27566
27567 \begin_inset LatexCommand \index{SDCDB (debugger)}
27568
27569 \end_inset
27570
27571  
27572 \end_layout
27573
27574 \begin_layout Standard
27575 SDCC is distributed with a source level debugger
27576 \begin_inset LatexCommand \index{Debugger}
27577
27578 \end_inset
27579
27580 .
27581  The debugger uses a command line interface, the command repertoire of the
27582  debugger has been kept as close to gdb
27583 \begin_inset LatexCommand \index{gdb}
27584
27585 \end_inset
27586
27587  (the GNU debugger) as possible.
27588  The configuration and build process is part of the standard compiler installati
27589 on, which also builds and installs the debugger in the target directory
27590  specified during configuration.
27591  The debugger allows you debug BOTH at the C source and at the ASM source
27592  level.
27593 \end_layout
27594
27595 \begin_layout Subsection
27596 Compiling for Debugging
27597 \end_layout
27598
27599 \begin_layout Standard
27600 The -
27601 \begin_inset ERT
27602 status collapsed
27603
27604 \begin_layout Standard
27605
27606
27607 \backslash
27608 /
27609 \end_layout
27610
27611 \end_inset
27612
27613 -debug
27614 \begin_inset LatexCommand \index{-\/-debug}
27615
27616 \end_inset
27617
27618  option must be specified for all files for which debug information is to
27619  be generated.
27620  The compiler generates a .adb file for each of these files.
27621  The linker creates the .cdb
27622 \begin_inset LatexCommand \index{<file>.cdb}
27623
27624 \end_inset
27625
27626  file from the .adb
27627 \begin_inset LatexCommand \index{<file>.adb}
27628
27629 \end_inset
27630
27631  files and the address information.
27632  This .cdb is used by the debugger.
27633 \end_layout
27634
27635 \begin_layout Subsection
27636 How the Debugger Works
27637 \end_layout
27638
27639 \begin_layout Standard
27640 When the -
27641 \begin_inset ERT
27642 status collapsed
27643
27644 \begin_layout Standard
27645
27646
27647 \backslash
27648 /
27649 \end_layout
27650
27651 \end_inset
27652
27653 -debug option is specified the compiler generates extra symbol information
27654  some of which are put into the assembler source and some are put into the
27655  .adb file.
27656  Then the linker creates the .cdb file from the individual .adb files with
27657  the address information for the symbols.
27658  The debugger reads the symbolic information generated by the compiler &
27659  the address information generated by the linker.
27660  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27661  execution is controlled by the debugger.
27662  When a command is issued for the debugger, it translates it into appropriate
27663  commands for the simulator.
27664  (Currently SDCDM only connects to the simulator but 
27665 \emph on
27666 newcdb
27667 \emph default
27668  at 
27669 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27670
27671 \end_inset
27672
27673  is an effort to connect directly to the hardware.) 
27674 \end_layout
27675
27676 \begin_layout Subsection
27677 Starting the Debugger SDCDB
27678 \end_layout
27679
27680 \begin_layout Standard
27681 The debugger can be started using the following command line.
27682  (Assume the file you are debugging has the file name foo).
27683 \newline
27684
27685 \newline
27686
27687 \family sans
27688 \series bold
27689 sdcdb foo
27690 \newline
27691
27692 \family default
27693 \series default
27694
27695 \newline
27696 The debugger will look for the following files.
27697 \end_layout
27698
27699 \begin_layout Itemize
27700 foo.c - the source file.
27701 \end_layout
27702
27703 \begin_layout Itemize
27704 foo.cdb - the debugger symbol information file.
27705 \end_layout
27706
27707 \begin_layout Itemize
27708 foo.ihx - the Intel hex format
27709 \begin_inset LatexCommand \index{Intel hex format}
27710
27711 \end_inset
27712
27713  object file.
27714 \end_layout
27715
27716 \begin_layout Subsection
27717 SDCDB Command Line Options
27718 \end_layout
27719
27720 \begin_layout Itemize
27721 -
27722 \begin_inset ERT
27723 status collapsed
27724
27725 \begin_layout Standard
27726
27727
27728 \backslash
27729 /
27730 \end_layout
27731
27732 \end_inset
27733
27734 -directory=<source file directory> this option can used to specify the directory
27735  search list.
27736  The debugger will look into the directory list specified for source, cdb
27737  & ihx files.
27738  The items in the directory list must be separated by ':', e.g.
27739  if the source files can be in the directories /home/src1 and /home/src2,
27740  the -
27741 \begin_inset ERT
27742 status collapsed
27743
27744 \begin_layout Standard
27745
27746
27747 \backslash
27748 /
27749 \end_layout
27750
27751 \end_inset
27752
27753 -directory option should be -
27754 \begin_inset ERT
27755 status collapsed
27756
27757 \begin_layout Standard
27758
27759
27760 \backslash
27761 /
27762 \end_layout
27763
27764 \end_inset
27765
27766 -directory=/home/src1:/home/src2.
27767  Note there can be no spaces in the option.
27768  
27769 \end_layout
27770
27771 \begin_layout Itemize
27772 -cd <directory> - change to the <directory>.
27773 \end_layout
27774
27775 \begin_layout Itemize
27776 -fullname - used by GUI front ends.
27777 \end_layout
27778
27779 \begin_layout Itemize
27780 -cpu <cpu-type> - this argument is passed to the simulator please see the
27781  simulator docs for details.
27782 \end_layout
27783
27784 \begin_layout Itemize
27785 -X <Clock frequency > this options is passed to the simulator please see
27786  the simulator docs for details.
27787 \end_layout
27788
27789 \begin_layout Itemize
27790 -s <serial port file> passed to simulator see the simulator docs for details.
27791 \end_layout
27792
27793 \begin_layout Itemize
27794 -S <serial in,out> passed to simulator see the simulator docs for details.
27795 \end_layout
27796
27797 \begin_layout Itemize
27798 -k <port number> passed to simulator see the simulator docs for details.
27799 \end_layout
27800
27801 \begin_layout Subsection
27802 SDCDB Debugger Commands
27803 \end_layout
27804
27805 \begin_layout Standard
27806 As mentioned earlier the command interface for the debugger has been deliberatel
27807 y kept as close the GNU debugger gdb, as possible.
27808  This will help the integration with existing graphical user interfaces
27809  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27810  If you use a graphical user interface for the debugger you can skip this
27811  section.
27812 \end_layout
27813
27814 \begin_layout Subsubsection*
27815 break [line | file:line | function | file:function]
27816 \end_layout
27817
27818 \begin_layout Standard
27819 Set breakpoint at specified line or function:
27820 \newline
27821
27822 \newline
27823
27824 \family sans
27825 \series bold
27826 sdcdb>break 100 
27827 \newline
27828 sdcdb>break foo.c:100
27829 \newline
27830 sdcdb>break funcfoo
27831 \newline
27832 sdcdb>break foo.c:funcfoo
27833 \end_layout
27834
27835 \begin_layout Subsubsection*
27836 clear [line | file:line | function | file:function ]
27837 \end_layout
27838
27839 \begin_layout Standard
27840 Clear breakpoint at specified line or function:
27841 \newline
27842
27843 \newline
27844
27845 \family sans
27846 \series bold
27847 sdcdb>clear 100
27848 \newline
27849 sdcdb>clear foo.c:100
27850 \newline
27851 sdcdb>clear funcfoo
27852 \newline
27853 sdcdb>clear foo.c:funcfoo
27854 \end_layout
27855
27856 \begin_layout Subsubsection*
27857 continue
27858 \end_layout
27859
27860 \begin_layout Standard
27861 Continue program being debugged, after breakpoint.
27862 \end_layout
27863
27864 \begin_layout Subsubsection*
27865 finish
27866 \end_layout
27867
27868 \begin_layout Standard
27869 Execute till the end of the current function.
27870 \end_layout
27871
27872 \begin_layout Subsubsection*
27873 delete [n]
27874 \end_layout
27875
27876 \begin_layout Standard
27877 Delete breakpoint number 'n'.
27878  If used without any option clear ALL user defined break points.
27879 \end_layout
27880
27881 \begin_layout Subsubsection*
27882 info [break | stack | frame | registers ]
27883 \end_layout
27884
27885 \begin_layout Itemize
27886 info break - list all breakpoints
27887 \end_layout
27888
27889 \begin_layout Itemize
27890 info stack - show the function call stack.
27891 \end_layout
27892
27893 \begin_layout Itemize
27894 info frame - show information about the current execution frame.
27895 \end_layout
27896
27897 \begin_layout Itemize
27898 info registers - show content of all registers.
27899 \end_layout
27900
27901 \begin_layout Subsubsection*
27902 step
27903 \end_layout
27904
27905 \begin_layout Standard
27906 Step program until it reaches a different source line.
27907  Note: pressing <return> repeats the last command.
27908 \end_layout
27909
27910 \begin_layout Subsubsection*
27911 next
27912 \end_layout
27913
27914 \begin_layout Standard
27915 Step program, proceeding through subroutine calls.
27916 \end_layout
27917
27918 \begin_layout Subsubsection*
27919 run
27920 \end_layout
27921
27922 \begin_layout Standard
27923 Start debugged program.
27924 \end_layout
27925
27926 \begin_layout Subsubsection*
27927 ptype variable 
27928 \end_layout
27929
27930 \begin_layout Standard
27931 Print type information of the variable.
27932 \end_layout
27933
27934 \begin_layout Subsubsection*
27935 print variable
27936 \end_layout
27937
27938 \begin_layout Standard
27939 print value of variable.
27940 \end_layout
27941
27942 \begin_layout Subsubsection*
27943 file filename
27944 \end_layout
27945
27946 \begin_layout Standard
27947 load the given file name.
27948  Note this is an alternate method of loading file for debugging.
27949 \end_layout
27950
27951 \begin_layout Subsubsection*
27952 frame
27953 \end_layout
27954
27955 \begin_layout Standard
27956 print information about current frame.
27957 \end_layout
27958
27959 \begin_layout Subsubsection*
27960 set srcmode
27961 \end_layout
27962
27963 \begin_layout Standard
27964 Toggle between C source & assembly source.
27965 \end_layout
27966
27967 \begin_layout Subsubsection*
27968 ! simulator command
27969 \end_layout
27970
27971 \begin_layout Standard
27972 Send the string following '!' to the simulator, the simulator response is
27973  displayed.
27974  Note the debugger does not interpret the command being sent to the simulator,
27975  so if a command like 'go' is sent the debugger can loose its execution
27976  context and may display incorrect values.
27977 \end_layout
27978
27979 \begin_layout Subsubsection*
27980 quit
27981 \end_layout
27982
27983 \begin_layout Standard
27984 "Watch me now.
27985  Iam going Down.
27986  My name is Bobby Brown"
27987 \end_layout
27988
27989 \begin_layout Subsection
27990 Interfacing SDCDB with DDD
27991 \end_layout
27992
27993 \begin_layout Standard
27994 \begin_inset Note Note
27995 status collapsed
27996
27997 \begin_layout Standard
27998 The screenshot was converted from png to eps with: 
27999 \begin_inset Quotes sld
28000 \end_inset
28001
28002 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28003 \begin_inset Quotes srd
28004 \end_inset
28005
28006  which produces a pretty compact eps file which is free from compression
28007  artifacts.
28008 \end_layout
28009
28010 \begin_layout Standard
28011 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28012  as this broke the build system on Sourceforge (pdf-file was broken.
28013  pdflatex does not accept eps files).
28014 \end_layout
28015
28016 \end_inset
28017
28018
28019 \end_layout
28020
28021 \begin_layout Standard
28022 The 
28023 \emph on
28024 p
28025 \emph default
28026 ortable 
28027 \emph on
28028 n
28029 \emph default
28030 etwork 
28031 \emph on
28032 g
28033 \emph default
28034 raphics File 
28035 \size footnotesize
28036
28037 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28038
28039 \end_inset
28040
28041
28042 \size default
28043  shows a screenshot of a debugging session with DDD
28044 \begin_inset LatexCommand \index{DDD (debugger)}
28045
28046 \end_inset
28047
28048  (Unix only) on a simulated 8032.
28049  The debugging session might not run as smoothly as the screenshot suggests.
28050  The debugger allows setting of breakpoints, displaying and changing variables,
28051  single stepping through C and assembler code.
28052  
28053 \newline
28054 The source was compiled with 
28055 \family sans
28056 \series bold
28057
28058 \newline
28059
28060 \newline
28061 sdcc -
28062 \family default
28063 \series default
28064
28065 \begin_inset ERT
28066 status collapsed
28067
28068 \begin_layout Standard
28069
28070
28071 \backslash
28072 /
28073 \end_layout
28074
28075 \end_inset
28076
28077
28078 \family sans
28079 \series bold
28080 -debug ddd_example.c
28081 \family default
28082 \series default
28083  
28084 \family sans
28085 \series bold
28086
28087 \newline
28088
28089 \family default
28090 \series default
28091
28092 \newline
28093 and DDD was invoked with 
28094 \family sans
28095 \series bold
28096
28097 \newline
28098
28099 \newline
28100 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28101 \end_layout
28102
28103 \begin_layout Standard
28104 \begin_inset Note Note
28105 status open
28106
28107 \begin_layout Standard
28108 Check that the double quotes or an apostroph within the command line survive
28109  the LyX tool chain.
28110  Previously the apostrophs got slanted in the PDF output so a cut and paste
28111  did not work.
28112 \end_layout
28113
28114 \end_inset
28115
28116
28117 \end_layout
28118
28119 \begin_layout Subsection
28120 Interfacing SDCDB with XEmacs
28121 \begin_inset LatexCommand \index{XEmacs}
28122
28123 \end_inset
28124
28125
28126 \begin_inset LatexCommand \index{Emacs}
28127
28128 \end_inset
28129
28130
28131 \end_layout
28132
28133 \begin_layout Standard
28134 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28135  sdcdb.el and sdcdbsrc.el.
28136  These two files can be found in the $(prefix)/bin directory after the installat
28137 ion is complete.
28138  These files need to be loaded into XEmacs for the interface to work.
28139  This can be done at XEmacs startup time by inserting the following into
28140  your '.xemacs' file (which can be found in your HOME directory): 
28141 \newline
28142
28143 \newline
28144
28145 \family typewriter
28146 (load-file sdcdbsrc.el) 
28147 \family default
28148
28149 \newline
28150
28151 \newline
28152 .xemacs is a lisp file so the () around the command is REQUIRED.
28153  The files can also be loaded dynamically while XEmacs is running, set the
28154  environment variable 'EMACSLOADPATH' to the installation bin directory
28155  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28156  To start the interface enter the following command: 
28157 \newline
28158
28159 \newline
28160
28161 \family sans
28162 \series bold
28163 ESC-x sdcdbsrc
28164 \family default
28165 \series default
28166
28167 \newline
28168
28169 \newline
28170 You will prompted to enter the file name to be debugged.
28171  
28172 \newline
28173
28174 \newline
28175 The command line options that are passed to the simulator directly are
28176  bound to default values in the file sdcdbsrc.el.
28177  The variables are listed below, these values maybe changed as required.
28178 \end_layout
28179
28180 \begin_layout Itemize
28181 sdcdbsrc-cpu-type '51
28182 \end_layout
28183
28184 \begin_layout Itemize
28185 sdcdbsrc-frequency '11059200
28186 \end_layout
28187
28188 \begin_layout Itemize
28189 sdcdbsrc-serial nil
28190 \end_layout
28191
28192 \begin_layout Standard
28193 The following is a list of key mapping for the debugger interface.
28194 \end_layout
28195
28196 \begin_layout Standard
28197 \InsetSpace ~
28198
28199 \family typewriter
28200
28201 \newline
28202 ;;\InsetSpace ~
28203 Current Listing :: 
28204 \newline
28205 ;;key\InsetSpace ~
28206 \InsetSpace ~
28207 \InsetSpace ~
28208 \InsetSpace ~
28209 \InsetSpace ~
28210 \InsetSpace ~
28211 \InsetSpace ~
28212 \InsetSpace ~
28213 \InsetSpace ~
28214 \InsetSpace ~
28215 \InsetSpace ~
28216 \InsetSpace ~
28217 \InsetSpace ~
28218 \InsetSpace ~
28219 binding\InsetSpace ~
28220 \InsetSpace ~
28221 \InsetSpace ~
28222 \InsetSpace ~
28223 \InsetSpace ~
28224 \InsetSpace ~
28225 \InsetSpace ~
28226 \InsetSpace ~
28227 \InsetSpace ~
28228 \InsetSpace ~
28229 \InsetSpace ~
28230 \InsetSpace ~
28231 \InsetSpace ~
28232 \InsetSpace ~
28233 \InsetSpace ~
28234 \InsetSpace ~
28235 \InsetSpace ~
28236 \InsetSpace ~
28237 \InsetSpace ~
28238 \InsetSpace ~
28239 \InsetSpace ~
28240 \InsetSpace ~
28241 Comment 
28242 \newline
28243 ;;---\InsetSpace ~
28244 \InsetSpace ~
28245 \InsetSpace ~
28246 \InsetSpace ~
28247 \InsetSpace ~
28248 \InsetSpace ~
28249 \InsetSpace ~
28250 \InsetSpace ~
28251 \InsetSpace ~
28252 \InsetSpace ~
28253 \InsetSpace ~
28254 \InsetSpace ~
28255 \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 -------
28280 \newline
28281 ;; 
28282 \newline
28283 ;;\InsetSpace ~
28284 n\InsetSpace ~
28285 \InsetSpace ~
28286 \InsetSpace ~
28287 \InsetSpace ~
28288 \InsetSpace ~
28289 \InsetSpace ~
28290 \InsetSpace ~
28291 \InsetSpace ~
28292 \InsetSpace ~
28293 \InsetSpace ~
28294 \InsetSpace ~
28295 \InsetSpace ~
28296 \InsetSpace ~
28297 \InsetSpace ~
28298 \InsetSpace ~
28299 sdcdb-next-fro
28300 m-src\InsetSpace ~
28301 \InsetSpace ~
28302 \InsetSpace ~
28303 \InsetSpace ~
28304 \InsetSpace ~
28305 \InsetSpace ~
28306 \InsetSpace ~
28307 \InsetSpace ~
28308 \InsetSpace ~
28309 \InsetSpace ~
28310 SDCDB next command 
28311 \newline
28312 ;;\InsetSpace ~
28313 b\InsetSpace ~
28314 \InsetSpace ~
28315 \InsetSpace ~
28316 \InsetSpace ~
28317 \InsetSpace ~
28318 \InsetSpace ~
28319 \InsetSpace ~
28320 \InsetSpace ~
28321 \InsetSpace ~
28322 \InsetSpace ~
28323 \InsetSpace ~
28324 \InsetSpace ~
28325 \InsetSpace ~
28326 \InsetSpace ~
28327 \InsetSpace ~
28328 sdcdb-back-from-src\InsetSpace ~
28329 \InsetSpace ~
28330 \InsetSpace ~
28331 \InsetSpace ~
28332 \InsetSpace ~
28333 \InsetSpace ~
28334 \InsetSpace ~
28335 \InsetSpace ~
28336 \InsetSpace ~
28337 \InsetSpace ~
28338 SDCDB back command 
28339 \newline
28340 ;;\InsetSpace ~
28341 c\InsetSpace ~
28342 \InsetSpace ~
28343 \InsetSpace ~
28344 \InsetSpace ~
28345 \InsetSpace ~
28346 \InsetSpace ~
28347 \InsetSpace ~
28348 \InsetSpace ~
28349 \InsetSpace ~
28350 \InsetSpace ~
28351 \InsetSpace ~
28352 \InsetSpace ~
28353 \InsetSpace ~
28354 \InsetSpace ~
28355 \InsetSpace ~
28356 sdcdb-cont-f
28357 rom-src\InsetSpace ~
28358 \InsetSpace ~
28359 \InsetSpace ~
28360 \InsetSpace ~
28361 \InsetSpace ~
28362 \InsetSpace ~
28363 \InsetSpace ~
28364 \InsetSpace ~
28365 \InsetSpace ~
28366 \InsetSpace ~
28367 SDCDB continue command
28368 \newline
28369 ;;\InsetSpace ~
28370 s\InsetSpace ~
28371 \InsetSpace ~
28372 \InsetSpace ~
28373 \InsetSpace ~
28374 \InsetSpace ~
28375 \InsetSpace ~
28376 \InsetSpace ~
28377 \InsetSpace ~
28378 \InsetSpace ~
28379 \InsetSpace ~
28380 \InsetSpace ~
28381 \InsetSpace ~
28382 \InsetSpace ~
28383 \InsetSpace ~
28384 \InsetSpace ~
28385 sdcdb-step-from-src\InsetSpace ~
28386 \InsetSpace ~
28387 \InsetSpace ~
28388 \InsetSpace ~
28389 \InsetSpace ~
28390 \InsetSpace ~
28391 \InsetSpace ~
28392 \InsetSpace ~
28393 \InsetSpace ~
28394 \InsetSpace ~
28395 SDCDB step command 
28396 \newline
28397 ;;\InsetSpace ~
28398 ?\InsetSpace ~
28399 \InsetSpace ~
28400 \InsetSpace ~
28401 \InsetSpace ~
28402 \InsetSpace ~
28403 \InsetSpace ~
28404 \InsetSpace ~
28405 \InsetSpace ~
28406 \InsetSpace ~
28407 \InsetSpace ~
28408 \InsetSpace ~
28409 \InsetSpace ~
28410 \InsetSpace ~
28411 \InsetSpace ~
28412 \InsetSpace ~
28413 sdcdb-w
28414 hatis-c-sexp\InsetSpace ~
28415 \InsetSpace ~
28416 \InsetSpace ~
28417 \InsetSpace ~
28418 \InsetSpace ~
28419 \InsetSpace ~
28420 \InsetSpace ~
28421 \InsetSpace ~
28422 \InsetSpace ~
28423 \InsetSpace ~
28424 SDCDB ptypecommand for data at 
28425 \newline
28426 ;;\InsetSpace ~
28427 \InsetSpace ~
28428 \InsetSpace ~
28429 \InsetSpace ~
28430 \InsetSpace ~
28431 \InsetSpace ~
28432 \InsetSpace ~
28433 \InsetSpace ~
28434 \InsetSpace ~
28435 \InsetSpace ~
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 buffer point 
28474 \newline
28475 ;;\InsetSpace ~
28476 x\InsetSpace ~
28477 \InsetSpace ~
28478 \InsetSpace ~
28479 \InsetSpace ~
28480 \InsetSpace ~
28481 \InsetSpace ~
28482 \InsetSpace ~
28483 \InsetSpace ~
28484 \InsetSpace ~
28485 \InsetSpace ~
28486 \InsetSpace ~
28487 \InsetSpace ~
28488 \InsetSpace ~
28489 \InsetSpace ~
28490 \InsetSpace ~
28491 sdcdbsrc-delete\InsetSpace ~
28492 \InsetSpace ~
28493 \InsetSpace ~
28494 \InsetSpace ~
28495 \InsetSpace ~
28496 \InsetSpace ~
28497 \InsetSpace ~
28498 \InsetSpace ~
28499 \InsetSpace ~
28500 \InsetSpace ~
28501 \InsetSpace ~
28502 \InsetSpace ~
28503 \InsetSpace ~
28504 \InsetSpace ~
28505 SDCD
28506 B Delete all breakpoints if no arg 
28507 \newline
28508 ;;\InsetSpace ~
28509 \InsetSpace ~
28510 \InsetSpace ~
28511 \InsetSpace ~
28512 \InsetSpace ~
28513 \InsetSpace ~
28514 \InsetSpace ~
28515 \InsetSpace ~
28516 \InsetSpace ~
28517 \InsetSpace ~
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 given or delete arg (C-u arg x) 
28556 \newline
28557 ;;\InsetSpace ~
28558 m\InsetSpace ~
28559 \InsetSpace ~
28560 \InsetSpace ~
28561 \InsetSpace ~
28562 \InsetSpace ~
28563 \InsetSpace ~
28564 \InsetSpace ~
28565 \InsetSpace ~
28566 \InsetSpace ~
28567 \InsetSpace ~
28568 \InsetSpace ~
28569 \InsetSpace ~
28570 \InsetSpace ~
28571 \InsetSpace ~
28572 \InsetSpace ~
28573 sdcdbsrc
28574 -frame\InsetSpace ~
28575 \InsetSpace ~
28576 \InsetSpace ~
28577 \InsetSpace ~
28578 \InsetSpace ~
28579 \InsetSpace ~
28580 \InsetSpace ~
28581 \InsetSpace ~
28582 \InsetSpace ~
28583 \InsetSpace ~
28584 \InsetSpace ~
28585 \InsetSpace ~
28586 \InsetSpace ~
28587 \InsetSpace ~
28588 \InsetSpace ~
28589 SDCDB Display current frame if no arg, 
28590 \newline
28591 ;;\InsetSpace ~
28592 \InsetSpace ~
28593 \InsetSpace ~
28594 \InsetSpace ~
28595 \InsetSpace ~
28596 \InsetSpace ~
28597 \InsetSpace ~
28598 \InsetSpace ~
28599 \InsetSpace ~
28600 \InsetSpace ~
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 given or display frame arg
28639  
28640 \newline
28641 ;;\InsetSpace ~
28642 \InsetSpace ~
28643 \InsetSpace ~
28644 \InsetSpace ~
28645 \InsetSpace ~
28646 \InsetSpace ~
28647 \InsetSpace ~
28648 \InsetSpace ~
28649 \InsetSpace ~
28650 \InsetSpace ~
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 buffer point 
28689 \newline
28690 ;;\InsetSpace ~
28691 !\InsetSpace ~
28692 \InsetSpace ~
28693 \InsetSpace ~
28694 \InsetSpace ~
28695 \InsetSpace ~
28696 \InsetSpace ~
28697 \InsetSpace ~
28698 \InsetSpace ~
28699 \InsetSpace ~
28700 \InsetSpace ~
28701 \InsetSpace ~
28702 \InsetSpace ~
28703 \InsetSpace ~
28704 \InsetSpace ~
28705 \InsetSpace ~
28706 sdcdbsrc-goto-sdcdb\InsetSpace ~
28707 \InsetSpace ~
28708 \InsetSpace ~
28709 \InsetSpace ~
28710 \InsetSpace ~
28711 \InsetSpace ~
28712 \InsetSpace ~
28713 \InsetSpace ~
28714 \InsetSpace ~
28715 \InsetSpace ~
28716 Goto the SDCDB output buffer 
28717 \newline
28718 ;;\InsetSpace ~
28719 p\InsetSpace ~
28720 \InsetSpace ~
28721 \InsetSpace ~
28722 \InsetSpace ~
28723 \InsetSpace ~
28724 \InsetSpace ~
28725 \InsetSpace ~
28726 \InsetSpace ~
28727 \InsetSpace ~
28728 \InsetSpace ~
28729 \InsetSpace ~
28730 \InsetSpace ~
28731 \InsetSpace ~
28732 \InsetSpace ~
28733 \InsetSpace ~
28734 sdcdb-prin
28735 t-c-sexp\InsetSpace ~
28736 \InsetSpace ~
28737 \InsetSpace ~
28738 \InsetSpace ~
28739 \InsetSpace ~
28740 \InsetSpace ~
28741 \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744 \InsetSpace ~
28745 \InsetSpace ~
28746 SDCDB print command for data at 
28747 \newline
28748 ;;\InsetSpace ~
28749 \InsetSpace ~
28750 \InsetSpace ~
28751 \InsetSpace ~
28752 \InsetSpace ~
28753 \InsetSpace ~
28754 \InsetSpace ~
28755 \InsetSpace ~
28756 \InsetSpace ~
28757 \InsetSpace ~
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 buffer point 
28796 \newline
28797 ;;\InsetSpace ~
28798 g\InsetSpace ~
28799 \InsetSpace ~
28800 \InsetSpace ~
28801 \InsetSpace ~
28802 \InsetSpace ~
28803 \InsetSpace ~
28804 \InsetSpace ~
28805 \InsetSpace ~
28806 \InsetSpace ~
28807 \InsetSpace ~
28808 \InsetSpace ~
28809 \InsetSpace ~
28810 \InsetSpace ~
28811 \InsetSpace ~
28812 \InsetSpace ~
28813 sdcdbsrc-goto-sdcdb\InsetSpace ~
28814 \InsetSpace ~
28815 \InsetSpace ~
28816 \InsetSpace ~
28817 \InsetSpace ~
28818 \InsetSpace ~
28819 \InsetSpace ~
28820 \InsetSpace ~
28821 \InsetSpace ~
28822 \InsetSpace ~
28823 Got
28824 o the SDCDB output buffer 
28825 \newline
28826 ;;\InsetSpace ~
28827 t\InsetSpace ~
28828 \InsetSpace ~
28829 \InsetSpace ~
28830 \InsetSpace ~
28831 \InsetSpace ~
28832 \InsetSpace ~
28833 \InsetSpace ~
28834 \InsetSpace ~
28835 \InsetSpace ~
28836 \InsetSpace ~
28837 \InsetSpace ~
28838 \InsetSpace ~
28839 \InsetSpace ~
28840 \InsetSpace ~
28841 \InsetSpace ~
28842 sdcdbsrc-mode\InsetSpace ~
28843 \InsetSpace ~
28844 \InsetSpace ~
28845 \InsetSpace ~
28846 \InsetSpace ~
28847 \InsetSpace ~
28848 \InsetSpace ~
28849 \InsetSpace ~
28850 \InsetSpace ~
28851 \InsetSpace ~
28852 \InsetSpace ~
28853 \InsetSpace ~
28854 \InsetSpace ~
28855 \InsetSpace ~
28856 \InsetSpace ~
28857 \InsetSpace ~
28858 Toggles Sdcdbsrc mode (turns it
28859  off) 
28860 \newline
28861 ;; 
28862 \newline
28863 ;;\InsetSpace ~
28864 C-c\InsetSpace ~
28865 C-f\InsetSpace ~
28866 \InsetSpace ~
28867 \InsetSpace ~
28868 \InsetSpace ~
28869 \InsetSpace ~
28870 \InsetSpace ~
28871 \InsetSpace ~
28872 \InsetSpace ~
28873 \InsetSpace ~
28874 sdcdb-finish-from-src\InsetSpace ~
28875 \InsetSpace ~
28876 \InsetSpace ~
28877 \InsetSpace ~
28878 \InsetSpace ~
28879 \InsetSpace ~
28880 \InsetSpace ~
28881 \InsetSpace ~
28882 SDCDB finish command 
28883 \newline
28884 ;; 
28885 \newline
28886 ;;\InsetSpace ~
28887 C-x\InsetSpace ~
28888 SPC\InsetSpace ~
28889 \InsetSpace ~
28890 \InsetSpace ~
28891 \InsetSpace ~
28892 \InsetSpace ~
28893 \InsetSpace ~
28894 \InsetSpace ~
28895 \InsetSpace ~
28896 \InsetSpace ~
28897 sdcdb-brea
28898 k\InsetSpace ~
28899 \InsetSpace ~
28900 \InsetSpace ~
28901 \InsetSpace ~
28902 \InsetSpace ~
28903 \InsetSpace ~
28904 \InsetSpace ~
28905 \InsetSpace ~
28906 \InsetSpace ~
28907 \InsetSpace ~
28908 \InsetSpace ~
28909 \InsetSpace ~
28910 \InsetSpace ~
28911 \InsetSpace ~
28912 \InsetSpace ~
28913 \InsetSpace ~
28914 \InsetSpace ~
28915 \InsetSpace ~
28916 Set break for line with point 
28917 \newline
28918 ;;\InsetSpace ~
28919 ESC\InsetSpace ~
28920 t\InsetSpace ~
28921 \InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 \InsetSpace ~
28928 \InsetSpace ~
28929 \InsetSpace ~
28930 \InsetSpace ~
28931 sdcdbsrc-mode\InsetSpace ~
28932 \InsetSpace ~
28933 \InsetSpace ~
28934 \InsetSpace ~
28935 \InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 \InsetSpace ~
28940 \InsetSpace ~
28941 \InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 \InsetSpace ~
28945 \InsetSpace ~
28946 \InsetSpace ~
28947 Toggle Sdcdbsrc mode 
28948 \newline
28949 ;;\InsetSpace ~
28950 ESC\InsetSpace ~
28951 m\InsetSpace ~
28952 \InsetSpace ~
28953 \InsetSpace ~
28954 \InsetSpace ~
28955 \InsetSpace ~
28956 \InsetSpace ~
28957 \InsetSpace ~
28958 \InsetSpace ~
28959 \InsetSpace ~
28960 \InsetSpace ~
28961 \InsetSpace ~
28962 sdc
28963 dbsrc-srcmode\InsetSpace ~
28964 \InsetSpace ~
28965 \InsetSpace ~
28966 \InsetSpace ~
28967 \InsetSpace ~
28968 \InsetSpace ~
28969 \InsetSpace ~
28970 \InsetSpace ~
28971 \InsetSpace ~
28972 \InsetSpace ~
28973 \InsetSpace ~
28974 \InsetSpace ~
28975 \InsetSpace ~
28976 Toggle list mode 
28977 \newline
28978 ;; 
28979 \newline
28980
28981 \family default
28982
28983 \newpage
28984
28985 \end_layout
28986
28987 \begin_layout Chapter
28988 TIPS
28989 \end_layout
28990
28991 \begin_layout Standard
28992 Here are a few guidelines that will help the compiler generate more efficient
28993  code, some of the tips are specific to this compiler others are generally
28994  good programming practice.
28995 \end_layout
28996
28997 \begin_layout Itemize
28998 Use the smallest data type to represent your data-value.
28999  If it is known in advance that the value is going to be less than 256 then
29000  use an 'unsigned char' instead of a 'short' or 'int'.
29001  Please note, that ANSI C requires both signed and unsigned chars to be
29002  promoted to 'signed int'
29003 \begin_inset LatexCommand \index{promotion to signed int}
29004
29005 \end_inset
29006
29007
29008 \begin_inset Marginal
29009 status collapsed
29010
29011 \begin_layout Standard
29012
29013 \series bold
29014 \InsetSpace ~
29015 !
29016 \end_layout
29017
29018 \end_inset
29019
29020  before doing any operation.
29021  This promotion
29022 \begin_inset LatexCommand \index{type promotion}
29023
29024 \end_inset
29025
29026
29027 \begin_inset LatexCommand \label{type promotion}
29028
29029 \end_inset
29030
29031  can be omitted, if the result is the same.
29032  The effect of the promotion rules together with the sign-extension is often
29033  surprising:
29034 \end_layout
29035
29036 \begin_deeper
29037 \begin_layout Verse
29038
29039 \family typewriter
29040 unsigned char uc = 0xfe;
29041 \newline
29042 if (uc * uc < 0) /* this is true! */
29043 \newline
29044 {
29045 \newline
29046 \InsetSpace ~
29047 \InsetSpace ~
29048 \InsetSpace ~
29049 \InsetSpace ~
29050 ....
29051 \newline
29052 }
29053 \end_layout
29054
29055 \begin_layout Standard
29056
29057 \family typewriter
29058 uc * uc
29059 \family default
29060  is evaluated as 
29061 \family typewriter
29062 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29063 \family default
29064 .
29065  
29066 \newline
29067 Another one:
29068 \end_layout
29069
29070 \begin_layout Verse
29071
29072 \family typewriter
29073 (unsigned char) -12 / (signed char) -3 = ...
29074 \end_layout
29075
29076 \begin_layout Standard
29077 No, the result is not 4:
29078 \end_layout
29079
29080 \begin_layout Verse
29081
29082 \family typewriter
29083 (int) (unsigned char) -12 / (int) (signed char) -3 =
29084 \newline
29085 (int) (unsigned char)
29086  0xf4 / (int) (signed char) 0xfd =
29087 \newline
29088 (int) 0x00f4 / (int) 0xfffd =
29089 \newline
29090 (int) 0x00f4
29091  / (int) 0xfffd =
29092 \newline
29093 (int) 244 / (int) -3 =
29094 \newline
29095 (int) -81 = (int) 0xffaf;
29096 \end_layout
29097
29098 \begin_layout Standard
29099 Don't complain, that gcc gives you a different result.
29100  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29101  Therefore the results are different.
29102 \newline
29103 From 
29104 \begin_inset Quotes sld
29105 \end_inset
29106
29107 comp.lang.c FAQ
29108 \begin_inset Quotes srd
29109 \end_inset
29110
29111 :
29112 \end_layout
29113
29114 \begin_layout Quote
29115
29116 \emph on
29117 If well-defined overflow characteristics are important and negative values
29118  are not, or if you want to steer clear of sign-extension problems when
29119  manipulating bits or bytes, use one of the corresponding unsigned types.
29120  (Beware when mixing signed and unsigned values in expressions, though.)
29121 \newline
29122 Although
29123  character types (especially unsigned char) can be used as "tiny" integers,
29124  doing so is sometimes more trouble than it's worth, due to unpredictable
29125  sign extension and increased code size.
29126 \end_layout
29127
29128 \end_deeper
29129 \begin_layout Itemize
29130 Use unsigned when it is known in advance that the value is not going to
29131  be negative.
29132  This helps especially if you are doing division or multiplication, bit-shifting
29133  or are using an array index.
29134 \end_layout
29135
29136 \begin_layout Itemize
29137 NEVER jump into a LOOP.
29138 \end_layout
29139
29140 \begin_layout Itemize
29141 Declare the variables to be local
29142 \begin_inset LatexCommand \index{local variables}
29143
29144 \end_inset
29145
29146  whenever possible, especially loop control variables (induction).
29147 \end_layout
29148
29149 \begin_layout Itemize
29150 Have a look at the assembly listing to get a 
29151 \begin_inset Quotes sld
29152 \end_inset
29153
29154 feeling
29155 \begin_inset Quotes srd
29156 \end_inset
29157
29158  for the code generation.
29159 \end_layout
29160
29161 \begin_layout Section
29162 Porting code from or to other compilers
29163 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29164
29165 \end_inset
29166
29167
29168 \end_layout
29169
29170 \begin_layout Itemize
29171 check whether endianness of the compilers differs and adapt where needed.
29172 \end_layout
29173
29174 \begin_layout Itemize
29175 check the device specific header files
29176 \begin_inset LatexCommand \index{Header files}
29177
29178 \end_inset
29179
29180
29181 \begin_inset LatexCommand \index{Include files}
29182
29183 \end_inset
29184
29185  for compiler specific syntax.
29186  Eventually include the file <compiler.h
29187 \begin_inset LatexCommand \index{compiler.h (include file)}
29188
29189 \end_inset
29190
29191
29192 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29193
29194 \end_inset
29195
29196  to allow using common header files.
29197  (see f.e.
29198  cc2510fx.h 
29199 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29200
29201 \end_inset
29202
29203 ).
29204 \end_layout
29205
29206 \begin_layout Itemize
29207 check whether the startup code contains the correct initialization (watchdog,
29208  peripherals).
29209 \end_layout
29210
29211 \begin_layout Itemize
29212 check whether the sizes of short, int, long match.
29213 \end_layout
29214
29215 \begin_layout Itemize
29216 check if some 16 or 32 bit hardware registers require a specific addressing
29217  order (least significant or most significant byte first) and adapt if needed
29218  (
29219 \emph on
29220 first
29221 \emph default
29222  and 
29223 \emph on
29224 last
29225 \emph default
29226  relate to time and not to lower/upper memory location here, so this is
29227  
29228 \emph on
29229 not
29230 \emph default
29231  the same as endianness).
29232 \end_layout
29233
29234 \begin_layout Itemize
29235 check whether the keyword 
29236 \emph on
29237 volatile
29238 \emph default
29239  is used where needed.
29240  The compilers might differ in their optimization characteristics (as different
29241  versions of the same compiler might also use more clever optimizations
29242  this is good idea anyway).
29243  See section 
29244 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29245
29246 \end_inset
29247
29248 .
29249 \end_layout
29250
29251 \begin_layout Itemize
29252 check that the compilers are not told to supress warnings.
29253 \end_layout
29254
29255 \begin_layout Itemize
29256 check and convert compiler specific extensions (interrupts, memory areas,
29257  pragmas etc.).
29258 \end_layout
29259
29260 \begin_layout Itemize
29261 check for differences in type promotion.
29262  Especially check for math operations on 
29263 \family typewriter
29264 char
29265 \family default
29266  or 
29267 \family typewriter
29268 unsigned char
29269 \family default
29270  variables.
29271  For the sake of C99 compatibility SDCC will probably promote these to 
29272 \family typewriter
29273 int
29274 \family default
29275  more often than other compilers.
29276  Eventually insert explicit casts to 
29277 \family typewriter
29278 (char) 
29279 \family default
29280 or
29281 \family typewriter
29282  (unsigned char)
29283 \family default
29284 .
29285  Also check that the ~\InsetSpace ~
29286 operator
29287 \begin_inset LatexCommand \index{\~\/ Operator}
29288
29289 \end_inset
29290
29291  is not used on 
29292 \family typewriter
29293 bit
29294 \begin_inset LatexCommand \index{bit}
29295
29296 \end_inset
29297
29298
29299 \family default
29300  variables, use the !\InsetSpace ~
29301 operator instead.
29302  See sections 
29303 \begin_inset LatexCommand \ref{type promotion}
29304
29305 \end_inset
29306
29307  and 
29308 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29309
29310 \end_inset
29311
29312 .
29313 \end_layout
29314
29315 \begin_layout Itemize
29316 check the assembly code generated for interrupt routines (f.e.
29317  for calls to possibly non-reentrant library functions).
29318 \end_layout
29319
29320 \begin_layout Itemize
29321 check whether timing loops result in proper timing (or preferably consider
29322  a rewrite of the code with timer based delays instead).
29323 \end_layout
29324
29325 \begin_layout Itemize
29326 check for differences in printf parameters (some compilers push (va_arg
29327 \begin_inset LatexCommand \index{vararg, va\_arg}
29328
29329 \end_inset
29330
29331 ) char variables as 
29332 \family typewriter
29333 int
29334 \family default
29335  others push them as 
29336 \family typewriter
29337 char
29338 \family default
29339 .
29340  See section 
29341 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29342
29343 \end_inset
29344
29345 ).
29346 \end_layout
29347
29348 \begin_layout Itemize
29349 check the resulting memory map
29350 \begin_inset LatexCommand \index{Memory map}
29351
29352 \end_inset
29353
29354 .
29355  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29356 ly idata, pdata, xdata).
29357  Eventually check if unexpected library functions are included.
29358 \end_layout
29359
29360 \begin_layout Section
29361 Tools
29362 \begin_inset LatexCommand \index{Tools}
29363
29364 \end_inset
29365
29366  included in the distribution
29367 \end_layout
29368
29369 \begin_layout Standard
29370 \align left
29371 \begin_inset Tabular
29372 <lyxtabular version="3" rows="12" columns="3">
29373 <features>
29374 <column alignment="left" valignment="top" leftline="true" width="0pt">
29375 <column alignment="left" valignment="top" leftline="true" width="0pt">
29376 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29377 <row topline="true" bottomline="true">
29378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29379 \begin_inset Text
29380
29381 \begin_layout Standard
29382
29383 \series bold
29384 Name
29385 \end_layout
29386
29387 \end_inset
29388 </cell>
29389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29390 \begin_inset Text
29391
29392 \begin_layout Standard
29393
29394 \series bold
29395 Purpose
29396 \end_layout
29397
29398 \end_inset
29399 </cell>
29400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29401 \begin_inset Text
29402
29403 \begin_layout Standard
29404
29405 \series bold
29406 Directory
29407 \end_layout
29408
29409 \end_inset
29410 </cell>
29411 </row>
29412 <row topline="true">
29413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29414 \begin_inset Text
29415
29416 \begin_layout Standard
29417 uCsim
29418 \begin_inset LatexCommand \index{uCsim}
29419
29420 \end_inset
29421
29422
29423 \end_layout
29424
29425 \end_inset
29426 </cell>
29427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29428 \begin_inset Text
29429
29430 \begin_layout Standard
29431 Simulator for various architectures
29432 \end_layout
29433
29434 \end_inset
29435 </cell>
29436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29437 \begin_inset Text
29438
29439 \begin_layout Standard
29440 sdcc/sim/ucsim
29441 \end_layout
29442
29443 \end_inset
29444 </cell>
29445 </row>
29446 <row topline="true">
29447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29448 \begin_inset Text
29449
29450 \begin_layout Standard
29451 keil2sdcc.pl
29452 \end_layout
29453
29454 \end_inset
29455 </cell>
29456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29457 \begin_inset Text
29458
29459 \begin_layout Standard
29460 header file
29461 \begin_inset LatexCommand \index{Header files}
29462
29463 \end_inset
29464
29465
29466 \begin_inset LatexCommand \index{Include files}
29467
29468 \end_inset
29469
29470  conversion
29471 \end_layout
29472
29473 \end_inset
29474 </cell>
29475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29476 \begin_inset Text
29477
29478 \begin_layout Standard
29479 sdcc/support/scripts
29480 \end_layout
29481
29482 \end_inset
29483 </cell>
29484 </row>
29485 <row topline="true">
29486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29487 \begin_inset Text
29488
29489 \begin_layout Standard
29490 mh2h.c
29491 \end_layout
29492
29493 \end_inset
29494 </cell>
29495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29496 \begin_inset Text
29497
29498 \begin_layout Standard
29499 header file conversion
29500 \end_layout
29501
29502 \end_inset
29503 </cell>
29504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29505 \begin_inset Text
29506
29507 \begin_layout Standard
29508 sdcc/support/scripts
29509 \end_layout
29510
29511 \end_inset
29512 </cell>
29513 </row>
29514 <row topline="true">
29515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29516 \begin_inset Text
29517
29518 \begin_layout Standard
29519 as-gbz80
29520 \end_layout
29521
29522 \end_inset
29523 </cell>
29524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29525 \begin_inset Text
29526
29527 \begin_layout Standard
29528 Assembler
29529 \end_layout
29530
29531 \end_inset
29532 </cell>
29533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29534 \begin_inset Text
29535
29536 \begin_layout Standard
29537
29538 \family roman
29539 \series medium
29540 \shape up
29541 \size normal
29542 \emph off
29543 \bar no
29544 \noun off
29545 \color none
29546 sdcc/bin
29547 \end_layout
29548
29549 \end_inset
29550 </cell>
29551 </row>
29552 <row topline="true">
29553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29554 \begin_inset Text
29555
29556 \begin_layout Standard
29557 as-z80
29558 \end_layout
29559
29560 \end_inset
29561 </cell>
29562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29563 \begin_inset Text
29564
29565 \begin_layout Standard
29566 Assembler
29567 \end_layout
29568
29569 \end_inset
29570 </cell>
29571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29572 \begin_inset Text
29573
29574 \begin_layout Standard
29575
29576 \family roman
29577 \series medium
29578 \shape up
29579 \size normal
29580 \emph off
29581 \bar no
29582 \noun off
29583 \color none
29584 sdcc/bin
29585 \end_layout
29586
29587 \end_inset
29588 </cell>
29589 </row>
29590 <row topline="true">
29591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29592 \begin_inset Text
29593
29594 \begin_layout Standard
29595 asx8051
29596 \end_layout
29597
29598 \end_inset
29599 </cell>
29600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29601 \begin_inset Text
29602
29603 \begin_layout Standard
29604 Assembler
29605 \end_layout
29606
29607 \end_inset
29608 </cell>
29609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29610 \begin_inset Text
29611
29612 \begin_layout Standard
29613
29614 \family roman
29615 \series medium
29616 \shape up
29617 \size normal
29618 \emph off
29619 \bar no
29620 \noun off
29621 \color none
29622 sdcc/bin
29623 \end_layout
29624
29625 \end_inset
29626 </cell>
29627 </row>
29628 <row topline="true">
29629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29630 \begin_inset Text
29631
29632 \begin_layout Standard
29633 SDCDB
29634 \end_layout
29635
29636 \end_inset
29637 </cell>
29638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29639 \begin_inset Text
29640
29641 \begin_layout Standard
29642 Simulator
29643 \end_layout
29644
29645 \end_inset
29646 </cell>
29647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29648 \begin_inset Text
29649
29650 \begin_layout Standard
29651
29652 \family roman
29653 \series medium
29654 \shape up
29655 \size normal
29656 \emph off
29657 \bar no
29658 \noun off
29659 \color none
29660 sdcc/bin
29661 \end_layout
29662
29663 \end_inset
29664 </cell>
29665 </row>
29666 <row topline="true">
29667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29668 \begin_inset Text
29669
29670 \begin_layout Standard
29671 aslink
29672 \end_layout
29673
29674 \end_inset
29675 </cell>
29676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29677 \begin_inset Text
29678
29679 \begin_layout Standard
29680 Linker
29681 \end_layout
29682
29683 \end_inset
29684 </cell>
29685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29686 \begin_inset Text
29687
29688 \begin_layout Standard
29689
29690 \family roman
29691 \series medium
29692 \shape up
29693 \size normal
29694 \emph off
29695 \bar no
29696 \noun off
29697 \color none
29698 sdcc/bin
29699 \end_layout
29700
29701 \end_inset
29702 </cell>
29703 </row>
29704 <row topline="true">
29705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29706 \begin_inset Text
29707
29708 \begin_layout Standard
29709 link-z80
29710 \end_layout
29711
29712 \end_inset
29713 </cell>
29714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29715 \begin_inset Text
29716
29717 \begin_layout Standard
29718 Linker
29719 \end_layout
29720
29721 \end_inset
29722 </cell>
29723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29724 \begin_inset Text
29725
29726 \begin_layout Standard
29727
29728 \family roman
29729 \series medium
29730 \shape up
29731 \size normal
29732 \emph off
29733 \bar no
29734 \noun off
29735 \color none
29736 sdcc/bin
29737 \end_layout
29738
29739 \end_inset
29740 </cell>
29741 </row>
29742 <row topline="true">
29743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29744 \begin_inset Text
29745
29746 \begin_layout Standard
29747 link-gbz80
29748 \end_layout
29749
29750 \end_inset
29751 </cell>
29752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29753 \begin_inset Text
29754
29755 \begin_layout Standard
29756 Linker
29757 \end_layout
29758
29759 \end_inset
29760 </cell>
29761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29762 \begin_inset Text
29763
29764 \begin_layout Standard
29765
29766 \family roman
29767 \series medium
29768 \shape up
29769 \size normal
29770 \emph off
29771 \bar no
29772 \noun off
29773 \color none
29774 sdcc/bin
29775 \end_layout
29776
29777 \end_inset
29778 </cell>
29779 </row>
29780 <row topline="true" bottomline="true">
29781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29782 \begin_inset Text
29783
29784 \begin_layout Standard
29785 packihx
29786 \end_layout
29787
29788 \end_inset
29789 </cell>
29790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29791 \begin_inset Text
29792
29793 \begin_layout Standard
29794 Intel Hex packer 
29795 \begin_inset LatexCommand \index{packihx (tool)}
29796
29797 \end_inset
29798
29799
29800 \end_layout
29801
29802 \end_inset
29803 </cell>
29804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29805 \begin_inset Text
29806
29807 \begin_layout Standard
29808
29809 \family roman
29810 \series medium
29811 \shape up
29812 \size normal
29813 \emph off
29814 \bar no
29815 \noun off
29816 \color none
29817 sdcc/bin
29818 \end_layout
29819
29820 \end_inset
29821 </cell>
29822 </row>
29823 </lyxtabular>
29824
29825 \end_inset
29826
29827
29828 \newline
29829
29830 \end_layout
29831
29832 \begin_layout Section
29833 Documentation
29834 \begin_inset LatexCommand \index{Documentation}
29835
29836 \end_inset
29837
29838  included in the distribution
29839 \end_layout
29840
29841 \begin_layout Standard
29842 \align left
29843 \begin_inset Tabular
29844 <lyxtabular version="3" rows="10" columns="2">
29845 <features>
29846 <column alignment="block" valignment="top" leftline="true" width="40col%">
29847 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29848 <row topline="true" bottomline="true" endhead="true">
29849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29850 \begin_inset Text
29851
29852 \begin_layout Standard
29853
29854 \series bold
29855 Subject / Title
29856 \end_layout
29857
29858 \end_inset
29859 </cell>
29860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29861 \begin_inset Text
29862
29863 \begin_layout Standard
29864
29865 \series bold
29866 Filename / Where to get
29867 \end_layout
29868
29869 \end_inset
29870 </cell>
29871 </row>
29872 <row topline="true">
29873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29874 \begin_inset Text
29875
29876 \begin_layout Standard
29877 SDCC Compiler User Guide
29878 \end_layout
29879
29880 \end_inset
29881 </cell>
29882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29883 \begin_inset Text
29884
29885 \begin_layout Standard
29886 You're reading it right now
29887 \emph on
29888  \InsetSpace ~
29889 \InsetSpace ~
29890 \InsetSpace ~
29891
29892 \hfill
29893 online at:
29894 \emph default
29895
29896 \newline
29897
29898 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29899
29900 \end_inset
29901
29902
29903 \end_layout
29904
29905 \end_inset
29906 </cell>
29907 </row>
29908 <row topline="true">
29909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29910 \begin_inset Text
29911
29912 \begin_layout Standard
29913 Changelog of SDCC
29914 \end_layout
29915
29916 \end_inset
29917 </cell>
29918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29919 \begin_inset Text
29920
29921 \begin_layout Standard
29922 sdcc/Changelog
29923 \emph on
29924  \InsetSpace ~
29925 \InsetSpace ~
29926 \InsetSpace ~
29927
29928 \hfill
29929 online at:
29930 \emph default
29931
29932 \newline
29933
29934 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29935
29936 \end_inset
29937
29938
29939 \end_layout
29940
29941 \end_inset
29942 </cell>
29943 </row>
29944 <row topline="true">
29945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29946 \begin_inset Text
29947
29948 \begin_layout Standard
29949 ASXXXX
29950 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29951
29952 \end_inset
29953
29954
29955 \begin_inset LatexCommand \index{Assembler documentation}
29956
29957 \end_inset
29958
29959  Assemblers and
29960 \newline
29961 ASLINK
29962 \begin_inset LatexCommand \index{aslink}
29963
29964 \end_inset
29965
29966
29967 \begin_inset LatexCommand \index{Linker documentation}
29968
29969 \end_inset
29970
29971  Relocating Linker
29972 \end_layout
29973
29974 \end_inset
29975 </cell>
29976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29977 \begin_inset Text
29978
29979 \begin_layout Standard
29980 sdcc/as/doc/asxhtm.html 
29981 \emph on
29982 \InsetSpace ~
29983 \InsetSpace ~
29984 \InsetSpace ~
29985
29986 \hfill
29987 online at:
29988 \emph default
29989
29990 \newline
29991
29992 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
29993
29994 \end_inset
29995
29996
29997 \end_layout
29998
29999 \end_inset
30000 </cell>
30001 </row>
30002 <row topline="true">
30003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30004 \begin_inset Text
30005
30006 \begin_layout Standard
30007 SDCC regression test
30008 \begin_inset LatexCommand \index{Regression test}
30009
30010 \end_inset
30011
30012
30013 \end_layout
30014
30015 \end_inset
30016 </cell>
30017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30018 \begin_inset Text
30019
30020 \begin_layout Standard
30021 sdcc/doc/test_suite_spec.pdf 
30022 \emph on
30023 \InsetSpace ~
30024 \InsetSpace ~
30025 \InsetSpace ~
30026
30027 \hfill
30028 online at:
30029 \emph default
30030
30031 \newline
30032
30033 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30034
30035 \end_inset
30036
30037
30038 \end_layout
30039
30040 \end_inset
30041 </cell>
30042 </row>
30043 <row topline="true">
30044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30045 \begin_inset Text
30046
30047 \begin_layout Standard
30048 Various notes
30049 \end_layout
30050
30051 \end_inset
30052 </cell>
30053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30054 \begin_inset Text
30055
30056 \begin_layout Standard
30057 sdcc/doc/* 
30058 \emph on
30059 \InsetSpace ~
30060 \InsetSpace ~
30061 \InsetSpace ~
30062
30063 \hfill
30064 online at:
30065 \emph default
30066
30067 \newline
30068
30069 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30070
30071 \end_inset
30072
30073
30074 \end_layout
30075
30076 \end_inset
30077 </cell>
30078 </row>
30079 <row topline="true">
30080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30081 \begin_inset Text
30082
30083 \begin_layout Standard
30084 Notes on debugging with SDCDB
30085 \begin_inset LatexCommand \index{SDCDB (debugger)}
30086
30087 \end_inset
30088
30089
30090 \end_layout
30091
30092 \end_inset
30093 </cell>
30094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30095 \begin_inset Text
30096
30097 \begin_layout Standard
30098 sdcc/debugger/README 
30099 \emph on
30100 \InsetSpace ~
30101 \InsetSpace ~
30102 \InsetSpace ~
30103
30104 \hfill
30105 online at
30106 \emph default
30107 :
30108 \newline
30109
30110 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30111
30112 \end_inset
30113
30114
30115 \end_layout
30116
30117 \end_inset
30118 </cell>
30119 </row>
30120 <row topline="true">
30121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30122 \begin_inset Text
30123
30124 \begin_layout Standard
30125 uCsim
30126 \begin_inset LatexCommand \index{uCsim}
30127
30128 \end_inset
30129
30130  Software simulator for microcontrollers
30131 \end_layout
30132
30133 \end_inset
30134 </cell>
30135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30136 \begin_inset Text
30137
30138 \begin_layout Standard
30139
30140 \family roman
30141 \series medium
30142 \shape up
30143 \size normal
30144 \emph off
30145 \bar no
30146 \noun off
30147 \color none
30148 sdcc/sim/ucsim/doc
30149 \family default
30150 \series default
30151 \shape default
30152 \size default
30153 \emph default
30154 \bar default
30155 \noun default
30156 /index.html 
30157 \emph on
30158 \InsetSpace ~
30159 \InsetSpace ~
30160 \InsetSpace ~
30161
30162 \hfill
30163 online at:
30164 \emph default
30165
30166 \newline
30167
30168 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30169
30170 \end_inset
30171
30172
30173 \end_layout
30174
30175 \end_inset
30176 </cell>
30177 </row>
30178 <row topline="true">
30179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30180 \begin_inset Text
30181
30182 \begin_layout Standard
30183 Temporary notes on the pic16
30184 \begin_inset LatexCommand \index{PIC16}
30185
30186 \end_inset
30187
30188  port
30189 \end_layout
30190
30191 \end_inset
30192 </cell>
30193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30194 \begin_inset Text
30195
30196 \begin_layout Standard
30197 sdcc/src/pic16/NOTES 
30198 \emph on
30199 \InsetSpace ~
30200 \InsetSpace ~
30201 \InsetSpace ~
30202
30203 \hfill
30204 online at:
30205 \newline
30206
30207 \emph default
30208
30209 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30210
30211 \end_inset
30212
30213
30214 \end_layout
30215
30216 \end_inset
30217 </cell>
30218 </row>
30219 <row topline="true" bottomline="true">
30220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30221 \begin_inset Text
30222
30223 \begin_layout Standard
30224 SDCC internal documentation (debugging file format)
30225 \end_layout
30226
30227 \end_inset
30228 </cell>
30229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30230 \begin_inset Text
30231
30232 \begin_layout Standard
30233 sdcc/doc/
30234 \family roman
30235 \series medium
30236 \shape up
30237 \size normal
30238 \emph off
30239 \bar no
30240 \noun off
30241 \color none
30242 cdbfileformat.pd
30243 \family default
30244 \series default
30245 \shape default
30246 \size default
30247 \emph default
30248 \bar default
30249 \noun default
30250 f
30251 \emph on
30252  \InsetSpace ~
30253 \InsetSpace ~
30254 \InsetSpace ~
30255
30256 \hfill
30257 online at:
30258 \emph default
30259
30260 \newline
30261
30262 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30263
30264 \end_inset
30265
30266
30267 \end_layout
30268
30269 \end_inset
30270 </cell>
30271 </row>
30272 </lyxtabular>
30273
30274 \end_inset
30275
30276
30277 \newline
30278
30279 \end_layout
30280
30281 \begin_layout Section
30282 Related open source tools
30283 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30284
30285 \end_inset
30286
30287
30288 \begin_inset LatexCommand \index{Related tools}
30289
30290 \end_inset
30291
30292
30293 \end_layout
30294
30295 \begin_layout Standard
30296 \align left
30297 \begin_inset Tabular
30298 <lyxtabular version="3" rows="14" columns="3">
30299 <features>
30300 <column alignment="left" valignment="top" leftline="true" width="0pt">
30301 <column alignment="block" valignment="top" leftline="true" width="30line%">
30302 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30303 <row topline="true" bottomline="true">
30304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30305 \begin_inset Text
30306
30307 \begin_layout Standard
30308
30309 \series bold
30310 Name
30311 \end_layout
30312
30313 \end_inset
30314 </cell>
30315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30316 \begin_inset Text
30317
30318 \begin_layout Standard
30319
30320 \series bold
30321 Purpose
30322 \end_layout
30323
30324 \end_inset
30325 </cell>
30326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30327 \begin_inset Text
30328
30329 \begin_layout Standard
30330
30331 \series bold
30332 Where to get
30333 \end_layout
30334
30335 \end_inset
30336 </cell>
30337 </row>
30338 <row topline="true">
30339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30340 \begin_inset Text
30341
30342 \begin_layout Standard
30343 gpsim
30344 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30345
30346 \end_inset
30347
30348
30349 \end_layout
30350
30351 \end_inset
30352 </cell>
30353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30354 \begin_inset Text
30355
30356 \begin_layout Standard
30357 PIC simulator
30358 \end_layout
30359
30360 \end_inset
30361 </cell>
30362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30363 \begin_inset Text
30364
30365 \begin_layout Standard
30366 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30367
30368 \end_inset
30369
30370
30371 \end_layout
30372
30373 \end_inset
30374 </cell>
30375 </row>
30376 <row topline="true">
30377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30378 \begin_inset Text
30379
30380 \begin_layout Standard
30381 gputils
30382 \begin_inset LatexCommand \index{gputils (pic tools)}
30383
30384 \end_inset
30385
30386
30387 \end_layout
30388
30389 \end_inset
30390 </cell>
30391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30392 \begin_inset Text
30393
30394 \begin_layout Standard
30395 GNU PIC utilities
30396 \end_layout
30397
30398 \end_inset
30399 </cell>
30400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30401 \begin_inset Text
30402
30403 \begin_layout Standard
30404 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30405
30406 \end_inset
30407
30408
30409 \end_layout
30410
30411 \end_inset
30412 </cell>
30413 </row>
30414 <row topline="true">
30415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30416 \begin_inset Text
30417
30418 \begin_layout Standard
30419 flP5
30420 \end_layout
30421
30422 \end_inset
30423 </cell>
30424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30425 \begin_inset Text
30426
30427 \begin_layout Standard
30428 PIC programmer
30429 \end_layout
30430
30431 \end_inset
30432 </cell>
30433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30434 \begin_inset Text
30435
30436 \begin_layout Standard
30437 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30438
30439 \end_inset
30440
30441
30442 \end_layout
30443
30444 \end_inset
30445 </cell>
30446 </row>
30447 <row topline="true">
30448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30449 \begin_inset Text
30450
30451 \begin_layout Standard
30452 ec2drv/newcdb
30453 \end_layout
30454
30455 \end_inset
30456 </cell>
30457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30458 \begin_inset Text
30459
30460 \begin_layout Standard
30461 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30462  (Unix only)
30463 \end_layout
30464
30465 \end_inset
30466 </cell>
30467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30468 \begin_inset Text
30469
30470 \begin_layout Standard
30471 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30472
30473 \end_inset
30474
30475
30476 \end_layout
30477
30478 \end_inset
30479 </cell>
30480 </row>
30481 <row topline="true">
30482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30483 \begin_inset Text
30484
30485 \begin_layout Standard
30486 indent
30487 \begin_inset LatexCommand \index{indent (source formatting tool)}
30488
30489 \end_inset
30490
30491
30492 \end_layout
30493
30494 \end_inset
30495 </cell>
30496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30497 \begin_inset Text
30498
30499 \begin_layout Standard
30500 Formats C source - Master of the white spaces
30501 \end_layout
30502
30503 \end_inset
30504 </cell>
30505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30506 \begin_inset Text
30507
30508 \begin_layout Standard
30509 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30510
30511 \end_inset
30512
30513
30514 \end_layout
30515
30516 \end_inset
30517 </cell>
30518 </row>
30519 <row topline="true">
30520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30521 \begin_inset Text
30522
30523 \begin_layout Standard
30524 srecord
30525 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30526
30527 \end_inset
30528
30529
30530 \end_layout
30531
30532 \end_inset
30533 </cell>
30534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30535 \begin_inset Text
30536
30537 \begin_layout Standard
30538 Object file conversion, checksumming, ...
30539 \end_layout
30540
30541 \end_inset
30542 </cell>
30543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30544 \begin_inset Text
30545
30546 \begin_layout Standard
30547 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30548
30549 \end_inset
30550
30551
30552 \end_layout
30553
30554 \end_inset
30555 </cell>
30556 </row>
30557 <row topline="true">
30558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30559 \begin_inset Text
30560
30561 \begin_layout Standard
30562 objdump
30563 \begin_inset LatexCommand \index{objdump (tool)}
30564
30565 \end_inset
30566
30567
30568 \end_layout
30569
30570 \end_inset
30571 </cell>
30572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30573 \begin_inset Text
30574
30575 \begin_layout Standard
30576 Object file conversion, ...
30577 \end_layout
30578
30579 \end_inset
30580 </cell>
30581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30582 \begin_inset Text
30583
30584 \begin_layout Standard
30585 Part of binutils (should be there anyway)
30586 \end_layout
30587
30588 \end_inset
30589 </cell>
30590 </row>
30591 <row topline="true">
30592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30593 \begin_inset Text
30594
30595 \begin_layout Standard
30596 cmon51
30597 \end_layout
30598
30599 \end_inset
30600 </cell>
30601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30602 \begin_inset Text
30603
30604 \begin_layout Standard
30605 8051 monitor (hex up-/download, single step, disassemble)
30606 \end_layout
30607
30608 \end_inset
30609 </cell>
30610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30611 \begin_inset Text
30612
30613 \begin_layout Standard
30614 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30615
30616 \end_inset
30617
30618
30619 \end_layout
30620
30621 \end_inset
30622 </cell>
30623 </row>
30624 <row topline="true">
30625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30626 \begin_inset Text
30627
30628 \begin_layout Standard
30629 doxygen
30630 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30631
30632 \end_inset
30633
30634
30635 \end_layout
30636
30637 \end_inset
30638 </cell>
30639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30640 \begin_inset Text
30641
30642 \begin_layout Standard
30643 Source code documentation system
30644 \end_layout
30645
30646 \end_inset
30647 </cell>
30648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30649 \begin_inset Text
30650
30651 \begin_layout Standard
30652 \begin_inset LatexCommand \url{http://www.doxygen.org}
30653
30654 \end_inset
30655
30656
30657 \end_layout
30658
30659 \end_inset
30660 </cell>
30661 </row>
30662 <row topline="true">
30663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30664 \begin_inset Text
30665
30666 \begin_layout Standard
30667 kdevelop
30668 \end_layout
30669
30670 \end_inset
30671 </cell>
30672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30673 \begin_inset Text
30674
30675 \begin_layout Standard
30676 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30677 \end_layout
30678
30679 \end_inset
30680 </cell>
30681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30682 \begin_inset Text
30683
30684 \begin_layout Standard
30685 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30686
30687 \end_inset
30688
30689
30690 \end_layout
30691
30692 \end_inset
30693 </cell>
30694 </row>
30695 <row topline="true">
30696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30697 \begin_inset Text
30698
30699 \begin_layout Standard
30700 paulmon
30701 \end_layout
30702
30703 \end_inset
30704 </cell>
30705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30706 \begin_inset Text
30707
30708 \begin_layout Standard
30709 8051 monitor (hex up-/download, single step, disassemble)
30710 \end_layout
30711
30712 \end_inset
30713 </cell>
30714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30715 \begin_inset Text
30716
30717 \begin_layout Standard
30718 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30719
30720 \end_inset
30721
30722
30723 \end_layout
30724
30725 \end_inset
30726 </cell>
30727 </row>
30728 <row topline="true">
30729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30730 \begin_inset Text
30731
30732 \begin_layout Standard
30733 splint
30734 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30735
30736 \end_inset
30737
30738
30739 \end_layout
30740
30741 \end_inset
30742 </cell>
30743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30744 \begin_inset Text
30745
30746 \begin_layout Standard
30747 Statically checks c sources (see 
30748 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30749
30750 \end_inset
30751
30752 )
30753 \end_layout
30754
30755 \end_inset
30756 </cell>
30757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30758 \begin_inset Text
30759
30760 \begin_layout Standard
30761 \begin_inset LatexCommand \url{http://www.splint.org}
30762
30763 \end_inset
30764
30765
30766 \end_layout
30767
30768 \end_inset
30769 </cell>
30770 </row>
30771 <row topline="true" bottomline="true">
30772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30773 \begin_inset Text
30774
30775 \begin_layout Standard
30776 ddd
30777 \begin_inset LatexCommand \index{DDD (debugger)}
30778
30779 \end_inset
30780
30781
30782 \end_layout
30783
30784 \end_inset
30785 </cell>
30786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30787 \begin_inset Text
30788
30789 \begin_layout Standard
30790 Debugger, serves nicely as GUI to SDCDB
30791 \begin_inset LatexCommand \index{SDCDB (debugger)}
30792
30793 \end_inset
30794
30795  (Unix only)
30796 \end_layout
30797
30798 \end_inset
30799 </cell>
30800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30801 \begin_inset Text
30802
30803 \begin_layout Standard
30804 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30805
30806 \end_inset
30807
30808
30809 \end_layout
30810
30811 \end_inset
30812 </cell>
30813 </row>
30814 </lyxtabular>
30815
30816 \end_inset
30817
30818
30819 \newline
30820
30821 \end_layout
30822
30823 \begin_layout Section
30824 Related documentation / recommended reading
30825 \end_layout
30826
30827 \begin_layout Standard
30828 \align left
30829 \begin_inset Tabular
30830 <lyxtabular version="3" rows="7" columns="3">
30831 <features>
30832 <column alignment="left" valignment="top" leftline="true" width="0pt">
30833 <column alignment="left" valignment="top" leftline="true" width="0">
30834 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30835 <row topline="true" bottomline="true">
30836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30837 \begin_inset Text
30838
30839 \begin_layout Standard
30840
30841 \series bold
30842 Name
30843 \end_layout
30844
30845 \end_inset
30846 </cell>
30847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30848 \begin_inset Text
30849
30850 \begin_layout Standard
30851
30852 \series bold
30853 Subject / Title
30854 \end_layout
30855
30856 \end_inset
30857 </cell>
30858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30859 \begin_inset Text
30860
30861 \begin_layout Standard
30862
30863 \series bold
30864 Where to get
30865 \end_layout
30866
30867 \end_inset
30868 </cell>
30869 </row>
30870 <row topline="true">
30871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30872 \begin_inset Text
30873
30874 \begin_layout Standard
30875
30876 \family roman
30877 \series medium
30878 \shape up
30879 \size normal
30880 \emph off
30881 \bar no
30882 \noun off
30883 \color none
30884 c-refcard.pdf
30885 \end_layout
30886
30887 \end_inset
30888 </cell>
30889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30890 \begin_inset Text
30891
30892 \begin_layout Standard
30893 C Reference Card
30894 \begin_inset LatexCommand \index{C Reference card}
30895
30896 \end_inset
30897
30898 , 2 pages
30899 \end_layout
30900
30901 \end_inset
30902 </cell>
30903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30904 \begin_inset Text
30905
30906 \begin_layout Standard
30907 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30908
30909 \end_inset
30910
30911
30912 \end_layout
30913
30914 \end_inset
30915 </cell>
30916 </row>
30917 <row topline="true">
30918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30919 \begin_inset Text
30920
30921 \begin_layout Standard
30922 c-faq
30923 \end_layout
30924
30925 \end_inset
30926 </cell>
30927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30928 \begin_inset Text
30929
30930 \begin_layout Standard
30931 C-FAQ
30932 \begin_inset LatexCommand \index{C FAQ}
30933
30934 \end_inset
30935
30936
30937 \end_layout
30938
30939 \end_inset
30940 </cell>
30941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30942 \begin_inset Text
30943
30944 \begin_layout Standard
30945 \begin_inset LatexCommand \url{http://www.c-faq.com}
30946
30947 \end_inset
30948
30949
30950 \end_layout
30951
30952 \end_inset
30953 </cell>
30954 </row>
30955 <row topline="true">
30956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30957 \begin_inset Text
30958
30959 \begin_layout Standard
30960 ISO/IEC 9899:TC2
30961 \end_layout
30962
30963 \end_inset
30964 </cell>
30965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30966 \begin_inset Text
30967
30968 \begin_layout Standard
30969 \begin_inset Quotes sld
30970 \end_inset
30971
30972 C-Standard
30973 \begin_inset Quotes srd
30974 \end_inset
30975
30976
30977 \end_layout
30978
30979 \end_inset
30980 </cell>
30981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30982 \begin_inset Text
30983
30984 \begin_layout Standard
30985
30986 \size footnotesize
30987 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30988
30989 \end_inset
30990
30991
30992 \end_layout
30993
30994 \end_inset
30995 </cell>
30996 </row>
30997 <row topline="true">
30998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30999 \begin_inset Text
31000
31001 \begin_layout Standard
31002 ISO/IEC DTR 18037
31003 \end_layout
31004
31005 \end_inset
31006 </cell>
31007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31008 \begin_inset Text
31009
31010 \begin_layout Standard
31011 \begin_inset Quotes sld
31012 \end_inset
31013
31014 Extensions for Embedded C
31015 \begin_inset Quotes srd
31016 \end_inset
31017
31018
31019 \end_layout
31020
31021 \end_inset
31022 </cell>
31023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31024 \begin_inset Text
31025
31026 \begin_layout Standard
31027
31028 \size footnotesize
31029 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31030
31031 \end_inset
31032
31033
31034 \end_layout
31035
31036 \end_inset
31037 </cell>
31038 </row>
31039 <row topline="true">
31040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31041 \begin_inset Text
31042
31043 \begin_layout Standard
31044
31045 \end_layout
31046
31047 \end_inset
31048 </cell>
31049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31050 \begin_inset Text
31051
31052 \begin_layout Standard
31053 Latest datasheet of target CPU
31054 \end_layout
31055
31056 \end_inset
31057 </cell>
31058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31059 \begin_inset Text
31060
31061 \begin_layout Standard
31062 vendor
31063 \end_layout
31064
31065 \end_inset
31066 </cell>
31067 </row>
31068 <row topline="true" bottomline="true">
31069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31070 \begin_inset Text
31071
31072 \begin_layout Standard
31073
31074 \end_layout
31075
31076 \end_inset
31077 </cell>
31078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31079 \begin_inset Text
31080
31081 \begin_layout Standard
31082 Revision history of datasheet
31083 \end_layout
31084
31085 \end_inset
31086 </cell>
31087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31088 \begin_inset Text
31089
31090 \begin_layout Standard
31091 vendor
31092 \end_layout
31093
31094 \end_inset
31095 </cell>
31096 </row>
31097 </lyxtabular>
31098
31099 \end_inset
31100
31101
31102 \newline
31103
31104 \end_layout
31105
31106 \begin_layout Section
31107 Application notes specifically for SDCC
31108 \end_layout
31109
31110 \begin_layout Standard
31111 SDCC makes no claims about the completeness of this list and about up-to-datenes
31112 s or correctness of the application notes
31113 \begin_inset LatexCommand \index{Application notes}
31114
31115 \end_inset
31116
31117 .
31118 \end_layout
31119
31120 \begin_layout Standard
31121 \align left
31122
31123 \size footnotesize
31124 \begin_inset Tabular
31125 <lyxtabular version="3" rows="7" columns="3">
31126 <features>
31127 <column alignment="block" valignment="top" leftline="true" width="17col%">
31128 <column alignment="block" valignment="top" leftline="true" width="27col%">
31129 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31130 <row topline="true" bottomline="true">
31131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31132 \begin_inset Text
31133
31134 \begin_layout Standard
31135
31136 \series bold
31137 \size footnotesize
31138 Vendor
31139 \end_layout
31140
31141 \end_inset
31142 </cell>
31143 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31144 \begin_inset Text
31145
31146 \begin_layout Standard
31147
31148 \series bold
31149 \size footnotesize
31150 Subject / Title
31151 \end_layout
31152
31153 \end_inset
31154 </cell>
31155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31156 \begin_inset Text
31157
31158 \begin_layout Standard
31159
31160 \series bold
31161 \size footnotesize
31162 Where to get
31163 \end_layout
31164
31165 \end_inset
31166 </cell>
31167 </row>
31168 <row topline="true">
31169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31170 \begin_inset Text
31171
31172 \begin_layout Standard
31173
31174 \size footnotesize
31175 Maxim / Dallas
31176 \end_layout
31177
31178 \end_inset
31179 </cell>
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31181 \begin_inset Text
31182
31183 \begin_layout Standard
31184
31185 \size footnotesize
31186 Using the SDCC Compiler for the DS80C400
31187 \begin_inset LatexCommand \index{DS80C400}
31188
31189 \end_inset
31190
31191
31192 \end_layout
31193
31194 \end_inset
31195 </cell>
31196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31197 \begin_inset Text
31198
31199 \begin_layout Standard
31200
31201 \size footnotesize
31202 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31203
31204 \end_inset
31205
31206
31207 \end_layout
31208
31209 \end_inset
31210 </cell>
31211 </row>
31212 <row topline="true">
31213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31214 \begin_inset Text
31215
31216 \begin_layout Standard
31217
31218 \size footnotesize
31219 Maxim / Dallas
31220 \end_layout
31221
31222 \end_inset
31223 </cell>
31224 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31225 \begin_inset Text
31226
31227 \begin_layout Standard
31228
31229 \size footnotesize
31230 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31231 \begin_inset LatexCommand \index{DS89C4x0}
31232
31233 \end_inset
31234
31235  Family of Microcontrollers
31236 \end_layout
31237
31238 \end_inset
31239 </cell>
31240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31241 \begin_inset Text
31242
31243 \begin_layout Standard
31244
31245 \size footnotesize
31246 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31247
31248 \end_inset
31249
31250
31251 \end_layout
31252
31253 \end_inset
31254 </cell>
31255 </row>
31256 <row topline="true">
31257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31258 \begin_inset Text
31259
31260 \begin_layout Standard
31261
31262 \size footnotesize
31263 Silicon Laboratories / Cygnal
31264 \end_layout
31265
31266 \end_inset
31267 </cell>
31268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31269 \begin_inset Text
31270
31271 \begin_layout Standard
31272
31273 \size footnotesize
31274 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31275 \begin_inset LatexCommand \index{IDE}
31276
31277 \end_inset
31278
31279
31280 \end_layout
31281
31282 \end_inset
31283 </cell>
31284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31285 \begin_inset Text
31286
31287 \begin_layout Standard
31288
31289 \size footnotesize
31290 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31291
31292 \end_inset
31293
31294
31295 \end_layout
31296
31297 \end_inset
31298 </cell>
31299 </row>
31300 <row topline="true">
31301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31302 \begin_inset Text
31303
31304 \begin_layout Standard
31305
31306 \size footnotesize
31307 Ramtron / Goal Semiconductor
31308 \end_layout
31309
31310 \end_inset
31311 </cell>
31312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31313 \begin_inset Text
31314
31315 \begin_layout Standard
31316
31317 \size footnotesize
31318 Interfacing SDCC to Syn and Textpad
31319 \end_layout
31320
31321 \end_inset
31322 </cell>
31323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31324 \begin_inset Text
31325
31326 \begin_layout Standard
31327
31328 \size footnotesize
31329 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31330
31331 \end_inset
31332
31333
31334 \end_layout
31335
31336 \end_inset
31337 </cell>
31338 </row>
31339 <row topline="true">
31340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31341 \begin_inset Text
31342
31343 \begin_layout Standard
31344
31345 \size footnotesize
31346 Ramtron / Goal Semiconductor
31347 \end_layout
31348
31349 \end_inset
31350 </cell>
31351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31352 \begin_inset Text
31353
31354 \begin_layout Standard
31355
31356 \size footnotesize
31357 Installing and Configuring SDCC and Crimson Editor 
31358 \end_layout
31359
31360 \end_inset
31361 </cell>
31362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31363 \begin_inset Text
31364
31365 \begin_layout Standard
31366
31367 \size footnotesize
31368 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31369
31370 \end_inset
31371
31372
31373 \end_layout
31374
31375 \end_inset
31376 </cell>
31377 </row>
31378 <row topline="true" bottomline="true">
31379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31380 \begin_inset Text
31381
31382 \begin_layout Standard
31383
31384 \size footnotesize
31385 Texas Instruments
31386 \end_layout
31387
31388 \end_inset
31389 </cell>
31390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31391 \begin_inset Text
31392
31393 \begin_layout Standard
31394
31395 \size footnotesize
31396 MSC12xx Programming with SDCC
31397 \end_layout
31398
31399 \end_inset
31400 </cell>
31401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31402 \begin_inset Text
31403
31404 \begin_layout Standard
31405
31406 \size footnotesize
31407 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31408
31409 \end_inset
31410
31411
31412 \end_layout
31413
31414 \end_inset
31415 </cell>
31416 </row>
31417 </lyxtabular>
31418
31419 \end_inset
31420
31421
31422 \end_layout
31423
31424 \begin_layout Section
31425 Some Questions
31426 \end_layout
31427
31428 \begin_layout Standard
31429 Some questions answered, some pointers given - it might be time to in turn
31430  ask 
31431 \emph on
31432 you
31433 \emph default
31434  some questions: 
31435 \end_layout
31436
31437 \begin_layout Itemize
31438 can you solve your project with the selected microcontroller? Would you
31439  find out early or rather late that your target is too small/slow/whatever?
31440  Can you switch to a slightly better device if it doesn't fit?
31441 \end_layout
31442
31443 \begin_layout Itemize
31444 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31445  and/or another programming language be more adequate? Would an operating
31446  system on the target device help?
31447 \end_layout
31448
31449 \begin_layout Itemize
31450 if you solved the problem, will the marketing department be happy?
31451 \end_layout
31452
31453 \begin_layout Itemize
31454 if the marketing department is happy, will customers be happy?
31455 \end_layout
31456
31457 \begin_layout Itemize
31458 if you're the project manager, marketing department and maybe even the customer
31459  in one person, have you tried to see the project from the outside?
31460 \end_layout
31461
31462 \begin_layout Itemize
31463 is the project done if you think it is done? Or is just that other interface/pro
31464 tocol/feature/configuration/option missing? How about website, manual(s),
31465  internationali(z|s)ation, packaging, labels, 2nd source for components,
31466  electromagnetic compatability/interference, documentation for production,
31467  production test software, update mechanism, patent issues?
31468 \end_layout
31469
31470 \begin_layout Itemize
31471 is your project adequately positioned in that magic triangle: fame, fortune,
31472  fun?
31473 \end_layout
31474
31475 \begin_layout Standard
31476 Maybe not all answers to these questions are known and some answers may
31477  even be 
31478 \emph on
31479 no
31480 \emph default
31481 , nevertheless knowing these questions may help you to avoid burnout
31482 \begin_inset Foot
31483 status open
31484
31485 \begin_layout Standard
31486 burnout is bad for electronic devices, programmers and motorcycle tyres
31487 \end_layout
31488
31489 \end_inset
31490
31491 .
31492  Chances are you didn't want to hear some of them...
31493 \end_layout
31494
31495 \begin_layout Chapter
31496 Support
31497 \begin_inset LatexCommand \index{Support}
31498
31499 \end_inset
31500
31501
31502 \end_layout
31503
31504 \begin_layout Standard
31505 SDCC has grown to be a large project.
31506  The compiler alone (without the preprocessor, assembler and linker) is
31507  well over 150,000 lines of code (blank stripped).
31508  The open source nature of this project is a key to its continued growth
31509  and support.
31510  You gain the benefit and support of many active software developers and
31511  end users.
31512  Is SDCC perfect? No, that's why we need your help.
31513  The developers take pride in fixing reported bugs.
31514  You can help by reporting the bugs and helping other SDCC users.
31515  There are lots of ways to contribute, and we encourage you to take part
31516  in making SDCC a great software package.
31517  
31518 \end_layout
31519
31520 \begin_layout Standard
31521 The SDCC project is hosted on the SDCC sourceforge site at 
31522 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31523
31524 \end_inset
31525
31526 .
31527  You'll find the complete set of mailing lists
31528 \begin_inset LatexCommand \index{Mailing list(s)}
31529
31530 \end_inset
31531
31532 , forums, bug reporting system, patch submission
31533 \begin_inset LatexCommand \index{Patch submission}
31534
31535 \end_inset
31536
31537  system, download
31538 \begin_inset LatexCommand \index{download}
31539
31540 \end_inset
31541
31542  area and Subversion code repository
31543 \begin_inset LatexCommand \index{Subversion code repository}
31544
31545 \end_inset
31546
31547  there.
31548 \end_layout
31549
31550 \begin_layout Section
31551 Reporting Bugs
31552 \begin_inset LatexCommand \index{Bug reporting}
31553
31554 \end_inset
31555
31556
31557 \begin_inset LatexCommand \index{Reporting bugs}
31558
31559 \end_inset
31560
31561
31562 \end_layout
31563
31564 \begin_layout Standard
31565 The recommended way of reporting bugs is using the infrastructure of the
31566  sourceforge site.
31567  You can follow the status of bug reports there and have an overview about
31568  the known bugs.
31569 \end_layout
31570
31571 \begin_layout Standard
31572 Bug reports are automatically forwarded to the developer mailing list and
31573  will be fixed ASAP.
31574  When reporting a bug, it is very useful to include a small test program
31575  (the smaller the better) which reproduces the problem.
31576  If you can isolate the problem by looking at the generated assembly code,
31577  this can be very helpful.
31578  Compiling your program with the -
31579 \begin_inset ERT
31580 status collapsed
31581
31582 \begin_layout Standard
31583
31584
31585 \backslash
31586 /
31587 \end_layout
31588
31589 \end_inset
31590
31591 -dumpall
31592 \begin_inset LatexCommand \index{-\/-dumpall}
31593
31594 \end_inset
31595
31596  option can sometimes be useful in locating optimization problems.
31597  When reporting a bug please make sure you:
31598 \end_layout
31599
31600 \begin_layout Enumerate
31601 Attach the code you are compiling with SDCC.
31602  
31603 \end_layout
31604
31605 \begin_layout Enumerate
31606 Specify the exact command you use to run SDCC, or attach your Makefile.
31607  
31608 \end_layout
31609
31610 \begin_layout Enumerate
31611 Specify the SDCC version (type "
31612 \family sans
31613 \series bold
31614 sdcc -v
31615 \family default
31616 \series default
31617 "), your platform, and operating system.
31618  
31619 \end_layout
31620
31621 \begin_layout Enumerate
31622 Provide an exact copy of any error message or incorrect output.
31623  
31624 \end_layout
31625
31626 \begin_layout Enumerate
31627 Put something meaningful in the subject of your message.
31628 \end_layout
31629
31630 \begin_layout Standard
31631 Please attempt to include these 5 important parts, as applicable, in all
31632  requests for support or when reporting any problems or bugs with SDCC.
31633  Though this will make your message lengthy, it will greatly improve your
31634  chance that SDCC users and developers will be able to help you.
31635  Some SDCC developers are frustrated by bug reports without code provided
31636  that they can use to reproduce and ultimately fix the problem, so please
31637  be sure to provide sample code if you are reporting a bug! 
31638 \end_layout
31639
31640 \begin_layout Standard
31641 Please have a short check that you are using a recent version of SDCC and
31642  the bug is not yet known.
31643  This is the link for reporting bugs: 
31644 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31645
31646 \end_inset
31647
31648 .
31649  With SDCC on average having more than 200 downloads
31650 \begin_inset LatexCommand \index{download}
31651
31652 \end_inset
31653
31654  on sourceforge per day
31655 \begin_inset Foot
31656 status open
31657
31658 \begin_layout Standard
31659 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31660  between 2002 and 2005.
31661  This does not include other methods of distribution.
31662 \end_layout
31663
31664 \end_inset
31665
31666  there must be some users.
31667  So it's not exactly easy to find a new bug.
31668  If you find one we need it: 
31669 \emph on
31670 reporting bugs is good
31671 \emph default
31672 .
31673 \end_layout
31674
31675 \begin_layout Section
31676 Requesting Features
31677 \begin_inset LatexCommand \label{sub:Requesting-Features}
31678
31679 \end_inset
31680
31681
31682 \begin_inset LatexCommand \index{Feature request}
31683
31684 \end_inset
31685
31686
31687 \begin_inset LatexCommand \index{Requesting features}
31688
31689 \end_inset
31690
31691
31692 \end_layout
31693
31694 \begin_layout Standard
31695 Like bug reports feature requests are forwarded to the developer mailing
31696  list.
31697  This is the link for requesting features: 
31698 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31699
31700 \end_inset
31701
31702 .
31703 \end_layout
31704
31705 \begin_layout Section
31706 Submitting patches
31707 \end_layout
31708
31709 \begin_layout Standard
31710 Like bug reports contributed patches are forwarded to the developer mailing
31711  list.
31712  This is the link for submitting patches
31713 \begin_inset LatexCommand \index{Patch submission}
31714
31715 \end_inset
31716
31717
31718 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31719
31720 \end_inset
31721
31722 .
31723 \end_layout
31724
31725 \begin_layout Standard
31726 You need to specify some parameters to the 
31727 \family typewriter
31728 diff
31729 \family default
31730  command for the patches to be useful.
31731  If you modified more than one file a patch created f.e.
31732  with 
31733 \family sans
31734 \series bold
31735
31736 \begin_inset Quotes sld
31737 \end_inset
31738
31739 diff -Naur unmodified_directory modified_directory >my_changes.patch
31740 \begin_inset Quotes srd
31741 \end_inset
31742
31743
31744 \family default
31745 \series default
31746  will be fine, otherwise 
31747 \family sans
31748 \series bold
31749
31750 \begin_inset Quotes sld
31751 \end_inset
31752
31753 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31754 \begin_inset Quotes srd
31755 \end_inset
31756
31757
31758 \series default
31759  
31760 \family default
31761 will do.
31762 \end_layout
31763
31764 \begin_layout Section
31765 Getting Help
31766 \end_layout
31767
31768 \begin_layout Standard
31769 These links should take you directly to the 
31770 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31771
31772 \end_inset
31773
31774
31775 \begin_inset Foot
31776 status open
31777
31778 \begin_layout Standard
31779 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31780  automated messages (mid 2003)
31781 \end_layout
31782
31783 \end_inset
31784
31785  and the 
31786 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31787
31788 \end_inset
31789
31790 , lists
31791 \begin_inset LatexCommand \index{Mailing list(s)}
31792
31793 \end_inset
31794
31795  and forums are archived and searchable so if you are lucky someone already
31796  had a similar problem.
31797  While mails to the lists themselves are delivered promptly their web front
31798  end on sourceforge sometimes shows a severe time lag (up to several weeks),
31799  if you're seriously using SDCC please consider subscribing to the lists.
31800 \end_layout
31801
31802 \begin_layout Section
31803 ChangeLog
31804 \end_layout
31805
31806 \begin_layout Standard
31807 You can follow the status of the Subversion version
31808 \begin_inset LatexCommand \index{version}
31809
31810 \end_inset
31811
31812  of SDCC by watching the Changelog
31813 \begin_inset LatexCommand \index{Changelog}
31814
31815 \end_inset
31816
31817  in the Subversion repository
31818 \size footnotesize
31819  
31820 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31821
31822 \end_inset
31823
31824 .
31825 \end_layout
31826
31827 \begin_layout Section
31828 Subversion Source Code Repository
31829 \end_layout
31830
31831 \begin_layout Standard
31832 The output of 
31833 \family sans
31834 \series bold
31835 sdcc --version
31836 \family default
31837 \series default
31838  or the filenames of the snapshot versions of SDCC include date and its
31839  Subversion
31840 \begin_inset LatexCommand \index{Subversion code repository}
31841
31842 \end_inset
31843
31844  number.
31845  Subversion allows to download the source of recent or previous versions
31846  
31847 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31848
31849 \end_inset
31850
31851  (by number or by date).
31852  An on-line source code browser and detailled instructions are also available
31853  there.
31854  SDCC versions starting from 1999 up to now are available (currently the
31855  versions prior to the conversion from cvs
31856 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31857
31858 \end_inset
31859
31860  to Subversion (April 2006) are either by accessible by Subversion or by
31861  cvs).
31862 \end_layout
31863
31864 \begin_layout Section
31865 Release policy
31866 \begin_inset LatexCommand \index{Release policy}
31867
31868 \end_inset
31869
31870
31871 \end_layout
31872
31873 \begin_layout Standard
31874 Historically there often were long delays between official releases and
31875  the sourceforge download area tends to get not updated at all.
31876  Excuses in the past might have referred to problems with live range analysis,
31877  but as this was fixed a while ago, the current problem is that another
31878  excuse has to be found.
31879  Kidding aside, we have to get better there! On the other hand there are
31880  daily snapshots available at 
31881 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31882
31883 \end_inset
31884
31885 , and you can always build the very last version (hopefully with many bugs
31886  fixed, and features added) from the source code available at 
31887 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31888
31889 \end_inset
31890
31891 .
31892  A release wiki
31893 \begin_inset LatexCommand \index{wiki}
31894
31895 \end_inset
31896
31897
31898 \begin_inset LatexCommand \index{Release wiki}
31899
31900 \end_inset
31901
31902  at 
31903 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31904
31905 \end_inset
31906
31907  also holds some information about past and future releases.
31908 \end_layout
31909
31910 \begin_layout Section
31911 Examples
31912 \begin_inset LatexCommand \index{Examples}
31913
31914 \end_inset
31915
31916
31917 \end_layout
31918
31919 \begin_layout Standard
31920 You'll find some small examples in the directory 
31921 \emph on
31922 sdcc/device/examples/.
31923  
31924 \emph default
31925 More examples and libraries are available at
31926 \emph on
31927  The SDCC Open Knowledge Resource 
31928 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31929
31930 \end_inset
31931
31932  
31933 \emph default
31934 web site or at 
31935 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31936
31937 \end_inset
31938
31939 .
31940 \end_layout
31941
31942 \begin_layout Standard
31943 \begin_inset Note Note
31944 status collapsed
31945
31946 \begin_layout Standard
31947 I did insert a reference to Paul's web site here although it seems rather
31948  dedicated to a specific 8032 board (I think it's okay because it f.e.
31949  shows LCD/Harddisc interface and has a free 8051 monitor.
31950  Independent 8032 board vendors face hard competition of heavily subsidized
31951  development boards anyway).
31952 \end_layout
31953
31954 \begin_layout Standard
31955 Maybe we should include some links to real world applications.
31956  Preferably pointer to pointers (one for each architecture) so this stays
31957  manageable here?
31958 \end_layout
31959
31960 \end_inset
31961
31962
31963 \end_layout
31964
31965 \begin_layout Section
31966 Quality control
31967 \begin_inset LatexCommand \label{sec:Quality-control}
31968
31969 \end_inset
31970
31971
31972 \begin_inset LatexCommand \index{Quality control}
31973
31974 \end_inset
31975
31976
31977 \end_layout
31978
31979 \begin_layout Standard
31980 The compiler is passed through snaphot build compile and build checks.
31981  The so called 
31982 \shape italic
31983 regression tests
31984 \shape default
31985
31986 \begin_inset LatexCommand \index{Regression test}
31987
31988 \end_inset
31989
31990  check that SDCC itself compiles flawlessly on several host platforms (i386,
31991  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
31992  the quality of the code generated by SDCC by running the code for several
31993  target platforms through simulators.
31994  The regression test suite comprises more than 100 files which expand to
31995  more than 500 test cases which include more than 4500 tests.
31996  The results of these tests are published daily on SDCC's snapshot page
31997  (click on the red or green symbols on the right side of 
31998 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
31999
32000 \end_inset
32001
32002 ).
32003 \end_layout
32004
32005 \begin_layout Standard
32006 There is a separate document 
32007 \shape italic
32008 test_suite.pdf 
32009 \begin_inset LatexCommand \index{Test suite}
32010
32011 \end_inset
32012
32013
32014 \shape default
32015  
32016 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32017
32018 \end_inset
32019
32020  about the regression test suite.
32021 \end_layout
32022
32023 \begin_layout Standard
32024 You'll find the test code in the directory 
32025 \shape italic
32026 sdcc/support/regression
32027 \shape default
32028 .
32029  You can run these tests manually by running 
32030 \family sans
32031 make
32032 \family default
32033  in this directory (or f.e.
32034  
32035 \family sans
32036 \series bold
32037
32038 \begin_inset Quotes sld
32039 \end_inset
32040
32041 make test-mcs51
32042 \begin_inset Quotes srd
32043 \end_inset
32044
32045
32046 \family default
32047 \series default
32048  if you don't want to run the complete tests).
32049  The test code might also be interesting if you want to look for examples
32050 \begin_inset LatexCommand \index{Examples}
32051
32052 \end_inset
32053
32054  checking corner cases of SDCC or if you plan to submit patches
32055 \begin_inset LatexCommand \index{Patch submission}
32056
32057 \end_inset
32058
32059 .
32060 \end_layout
32061
32062 \begin_layout Standard
32063 The 14bit pic port uses a different set of regression tests 
32064 \begin_inset LatexCommand \index{Regression test (PIC14)}
32065
32066 \end_inset
32067
32068 , you'll find them in the directory 
32069 \shape italic
32070 sdcc/src/regression
32071 \shape default
32072 .
32073 \end_layout
32074
32075 \begin_layout Section
32076 Use of SDCC in Education
32077 \end_layout
32078
32079 \begin_layout Standard
32080 In short: 
32081 \emph on
32082 highly
32083 \emph default
32084  encouraged
32085 \begin_inset Foot
32086 status open
32087
32088 \begin_layout Standard
32089 the phrase "use in education" might evoke the association "
32090 \emph on
32091 only
32092 \emph default
32093  fit for use in education".
32094  This connotation is not intended but nevertheless risked as the licensing
32095  of SDCC makes it difficult to offer educational discounts
32096 \end_layout
32097
32098 \end_inset
32099
32100 .
32101  If your rationales are to:
32102 \end_layout
32103
32104 \begin_layout Enumerate
32105 give students a chance to understand the 
32106 \emph on
32107 complete
32108 \emph default
32109  steps of code generation
32110 \end_layout
32111
32112 \begin_layout Enumerate
32113 have a curriculum that can be extended for years.
32114  Then you could use an fpga board as target and your curriculum will seamlessly
32115  extend from logic synthesis (
32116 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32117
32118 \end_inset
32119
32120
32121 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32122
32123 \end_inset
32124
32125 ), over assembly programming, to C to FPGA compilers (
32126 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32127
32128 \end_inset
32129
32130 ) and to C.
32131 \end_layout
32132
32133 \begin_layout Enumerate
32134 be able to insert excursions about skills like using a revision control
32135  system, submitting/applying patches, using a type-setting (as opposed to
32136  word-processing) engine LyX/LaTeX, using 
32137 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32138
32139 \end_inset
32140
32141 , following some 
32142 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32143
32144 \end_inset
32145
32146 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32147  Source Software, CPU simulation, compiler regression tests
32148 \begin_inset LatexCommand \index{Regression test}
32149
32150 \end_inset
32151
32152 .
32153  
32154 \newline
32155 And if there should be a shortage of ideas then you can always point students
32156  to the ever-growing feature request list 
32157 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32158
32159 \end_inset
32160
32161 .
32162 \end_layout
32163
32164 \begin_layout Enumerate
32165 not tie students to a specific host platform and instead allow them to use
32166  a host platform of 
32167 \emph on
32168 their
32169 \emph default
32170  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
32171  eventually 
32172 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32173
32174 \end_inset
32175
32176 )
32177 \end_layout
32178
32179 \begin_layout Enumerate
32180 not encourage students to use illegal copies of educational software
32181 \end_layout
32182
32183 \begin_layout Enumerate
32184 be immune to licensing/availability/price changes of the chosen tool chain
32185 \end_layout
32186
32187 \begin_layout Enumerate
32188 be able to change to a new target platform without having to adopt a new
32189  tool chain
32190 \end_layout
32191
32192 \begin_layout Enumerate
32193 have complete control over and insight into the tool chain
32194 \end_layout
32195
32196 \begin_layout Enumerate
32197 make your students aware about the pros and cons of open source software
32198  development
32199 \end_layout
32200
32201 \begin_layout Enumerate
32202 give back to the public as you are probably at least partially publically
32203  funded
32204 \end_layout
32205
32206 \begin_layout Enumerate
32207 give students a chance to publically prove their skills and to possibly
32208  see a world wide impact
32209 \end_layout
32210
32211 \begin_layout Standard
32212 then SDCC is probably among the first choices.
32213  Well, probably SDCC might be the only choice.
32214 \newpage
32215
32216 \end_layout
32217
32218 \begin_layout Chapter
32219 SDCC Technical Data
32220 \end_layout
32221
32222 \begin_layout Section
32223 Optimizations
32224 \begin_inset LatexCommand \index{Optimizations}
32225
32226 \end_inset
32227
32228
32229 \end_layout
32230
32231 \begin_layout Standard
32232 SDCC performs a host of standard optimizations in addition to some MCU specific
32233  optimizations.
32234  
32235 \end_layout
32236
32237 \begin_layout Subsection
32238 Sub-expression Elimination
32239 \begin_inset LatexCommand \index{Subexpression elimination}
32240
32241 \end_inset
32242
32243
32244 \end_layout
32245
32246 \begin_layout Standard
32247 The compiler does local and 
32248 \emph on
32249 g
32250 \emph default
32251 lobal 
32252 \emph on
32253 c
32254 \emph default
32255 ommon 
32256 \emph on
32257 s
32258 \emph default
32259 ubexpression 
32260 \emph on
32261 e
32262 \emph default
32263 limination, e.g.: 
32264 \end_layout
32265
32266 \begin_layout Verse
32267
32268 \family typewriter
32269 i = x + y + 1; 
32270 \newline
32271 j = x + y;
32272 \end_layout
32273
32274 \begin_layout Standard
32275 will be translated to
32276 \end_layout
32277
32278 \begin_layout Verse
32279
32280 \family typewriter
32281 iTemp = x + y; 
32282 \newline
32283 i = iTemp + 1; 
32284 \newline
32285 j = iTemp;
32286 \end_layout
32287
32288 \begin_layout Standard
32289 Some subexpressions are not as obvious as the above example, e.g.:
32290 \end_layout
32291
32292 \begin_layout Verse
32293
32294 \family typewriter
32295 a->b[i].c = 10; 
32296 \newline
32297 a->b[i].d = 11;
32298 \end_layout
32299
32300 \begin_layout Standard
32301 In this case the address arithmetic a->b[i] will be computed only once;
32302  the equivalent code in C would be.
32303 \end_layout
32304
32305 \begin_layout Verse
32306
32307 \family typewriter
32308 iTemp = a->b[i]; 
32309 \newline
32310 iTemp.c = 10; 
32311 \newline
32312 iTemp.d = 11;
32313 \end_layout
32314
32315 \begin_layout Standard
32316 The compiler will try to keep these temporary variables in registers.
32317 \end_layout
32318
32319 \begin_layout Subsection
32320 Dead-Code Elimination
32321 \begin_inset LatexCommand \index{Dead-code elimination}
32322
32323 \end_inset
32324
32325
32326 \end_layout
32327
32328 \begin_layout Verse
32329
32330 \family typewriter
32331 int global;
32332 \newline
32333
32334 \newline
32335 void f () { 
32336 \newline
32337 \InsetSpace ~
32338 \InsetSpace ~
32339 int i; 
32340 \newline
32341 \InsetSpace ~
32342 \InsetSpace ~
32343 i = 1; \InsetSpace ~
32344 \InsetSpace ~
32345 \InsetSpace ~
32346 \InsetSpace ~
32347 \InsetSpace ~
32348 /* dead store */ 
32349 \newline
32350 \InsetSpace ~
32351 \InsetSpace ~
32352 global = 1;\InsetSpace ~
32353 /* dead
32354  store */ 
32355 \newline
32356 \InsetSpace ~
32357 \InsetSpace ~
32358 global = 2; 
32359 \newline
32360 \InsetSpace ~
32361 \InsetSpace ~
32362 return; 
32363 \newline
32364 \InsetSpace ~
32365 \InsetSpace ~
32366 global = 3;\InsetSpace ~
32367 /* unreachable */ 
32368 \newline
32369 }
32370 \end_layout
32371
32372 \begin_layout Standard
32373 will be changed to
32374 \end_layout
32375
32376 \begin_layout Verse
32377
32378 \family typewriter
32379 int global;
32380 \newline
32381
32382 \newline
32383 void f () {
32384 \newline
32385 \InsetSpace ~
32386 \InsetSpace ~
32387 global = 2; 
32388 \newline
32389 }
32390 \end_layout
32391
32392 \begin_layout Subsection
32393 Copy-Propagation
32394 \begin_inset LatexCommand \index{Copy propagation}
32395
32396 \end_inset
32397
32398
32399 \end_layout
32400
32401 \begin_layout Verse
32402
32403 \family typewriter
32404 int f() { 
32405 \newline
32406 \InsetSpace ~
32407 \InsetSpace ~
32408 int i, j; 
32409 \newline
32410 \InsetSpace ~
32411 \InsetSpace ~
32412 i = 10; 
32413 \newline
32414 \InsetSpace ~
32415 \InsetSpace ~
32416 j = i; 
32417 \newline
32418 \InsetSpace ~
32419 \InsetSpace ~
32420 return j; 
32421 \newline
32422 }
32423 \end_layout
32424
32425 \begin_layout Standard
32426 will be changed to 
32427 \end_layout
32428
32429 \begin_layout Verse
32430
32431 \family typewriter
32432 int f() { 
32433 \newline
32434 \InsetSpace ~
32435 \InsetSpace ~
32436 int i, j; 
32437 \newline
32438 \InsetSpace ~
32439 \InsetSpace ~
32440 i = 10; 
32441 \newline
32442 \InsetSpace ~
32443 \InsetSpace ~
32444 j = 10; 
32445 \newline
32446 \InsetSpace ~
32447 \InsetSpace ~
32448 return 10; 
32449 \newline
32450 }
32451 \end_layout
32452
32453 \begin_layout Standard
32454 Note: the dead stores created by this copy propagation will be eliminated
32455  by dead-code elimination.
32456 \end_layout
32457
32458 \begin_layout Subsection
32459 Loop Optimizations
32460 \begin_inset LatexCommand \index{Loop optimization}
32461
32462 \end_inset
32463
32464
32465 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32466
32467 \end_inset
32468
32469
32470 \end_layout
32471
32472 \begin_layout Standard
32473 Two types of loop optimizations are done by SDCC 
32474 \emph on
32475 loop invariant
32476 \emph default
32477  lifting and
32478 \emph on
32479  strength reduction
32480 \emph default
32481  of loop induction variables.
32482  In addition to the strength reduction the optimizer marks the induction
32483  variables and the register allocator tries to keep the induction variables
32484  in registers for the duration of the loop.
32485  Because of this preference of the register allocator
32486 \begin_inset LatexCommand \index{Register allocation}
32487
32488 \end_inset
32489
32490 , loop induction optimization causes an increase in register pressure, which
32491  may cause unwanted spilling of other temporary variables into the stack
32492 \begin_inset LatexCommand \index{stack}
32493
32494 \end_inset
32495
32496  / data space.
32497  The compiler will generate a warning message when it is forced to allocate
32498  extra space either on the stack or data space.
32499  If this extra space allocation is undesirable then induction optimization
32500  can be eliminated either for the entire source file (with -
32501 \begin_inset ERT
32502 status collapsed
32503
32504 \begin_layout Standard
32505
32506
32507 \backslash
32508 /
32509 \end_layout
32510
32511 \end_inset
32512
32513 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32514 noinduction
32515 \begin_inset LatexCommand \index{\#pragma noinduction}
32516
32517 \end_inset
32518
32519 .
32520 \newline
32521
32522 \newline
32523 Loop Invariant:
32524 \end_layout
32525
32526 \begin_layout Verse
32527
32528 \family typewriter
32529 for (i = 0 ; i < 100 ; i ++) 
32530 \newline
32531 \InsetSpace ~
32532 \InsetSpace ~
32533 \InsetSpace ~
32534 \InsetSpace ~
32535 f += k + l;
32536 \end_layout
32537
32538 \begin_layout Standard
32539 changed to
32540 \end_layout
32541
32542 \begin_layout Verse
32543
32544 \family typewriter
32545 itemp = k + l; 
32546 \newline
32547 for (i = 0; i < 100; i++) 
32548 \newline
32549 \InsetSpace ~
32550 \InsetSpace ~
32551 \InsetSpace ~
32552 \InsetSpace ~
32553 f += itemp;
32554 \end_layout
32555
32556 \begin_layout Standard
32557 As mentioned previously some loop invariants are not as apparent, all static
32558  address computations are also moved out of the loop.
32559 \newline
32560
32561 \newline
32562 Strength Reduction
32563 \begin_inset LatexCommand \index{Strength reduction}
32564
32565 \end_inset
32566
32567 , this optimization substitutes an expression by a cheaper expression:
32568 \end_layout
32569
32570 \begin_layout Verse
32571
32572 \family typewriter
32573 for (i=0;i < 100; i++)
32574 \newline
32575 \InsetSpace ~
32576 \InsetSpace ~
32577 \InsetSpace ~
32578 \InsetSpace ~
32579 ar[i*5] = i*3;
32580 \end_layout
32581
32582 \begin_layout Standard
32583 changed to
32584 \end_layout
32585
32586 \begin_layout Verse
32587
32588 \family typewriter
32589 itemp1 = 0; 
32590 \newline
32591 itemp2 = 0; 
32592 \newline
32593 for (i=0;i< 100;i++) { 
32594 \newline
32595 \InsetSpace ~
32596 \InsetSpace ~
32597 \InsetSpace ~
32598 \InsetSpace ~
32599 ar[itemp1] = itemp2; 
32600 \newline
32601 \InsetSpace ~
32602 \InsetSpace ~
32603 \InsetSpace ~
32604 \InsetSpace ~
32605 itemp1
32606  += 5; 
32607 \newline
32608 \InsetSpace ~
32609 \InsetSpace ~
32610 \InsetSpace ~
32611 \InsetSpace ~
32612 itemp2 += 3; 
32613 \newline
32614 }
32615 \end_layout
32616
32617 \begin_layout Standard
32618 The more expensive multiplication
32619 \begin_inset LatexCommand \index{Multiplication}
32620
32621 \end_inset
32622
32623  is changed to a less expensive addition.
32624 \end_layout
32625
32626 \begin_layout Subsection
32627 Loop Reversing
32628 \begin_inset LatexCommand \index{Loop reversing}
32629
32630 \end_inset
32631
32632
32633 \end_layout
32634
32635 \begin_layout Standard
32636 This optimization is done to reduce the overhead of checking loop boundaries
32637  for every iteration.
32638  Some simple loops can be reversed and implemented using a 
32639 \begin_inset Quotes eld
32640 \end_inset
32641
32642 decrement and jump if not zero
32643 \begin_inset Quotes erd
32644 \end_inset
32645
32646  instruction.
32647  SDCC checks for the following criterion to determine if a loop is reversible
32648  (note: more sophisticated compilers use data-dependency analysis to make
32649  this determination, SDCC uses a more simple minded analysis).
32650 \end_layout
32651
32652 \begin_layout Itemize
32653 The 'for' loop is of the form 
32654 \newline
32655
32656 \newline
32657
32658 \family typewriter
32659 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32660  += 1])
32661 \newline
32662 \InsetSpace ~
32663 \InsetSpace ~
32664 \InsetSpace ~
32665 \InsetSpace ~
32666 <for body>
32667 \end_layout
32668
32669 \begin_layout Itemize
32670 The <for body> does not contain 
32671 \begin_inset Quotes eld
32672 \end_inset
32673
32674 continue
32675 \begin_inset Quotes erd
32676 \end_inset
32677
32678  or 'break
32679 \begin_inset Quotes erd
32680 \end_inset
32681
32682 .
32683 \end_layout
32684
32685 \begin_layout Itemize
32686 All goto's are contained within the loop.
32687 \end_layout
32688
32689 \begin_layout Itemize
32690 No function calls within the loop.
32691 \end_layout
32692
32693 \begin_layout Itemize
32694 The loop control variable <sym> is not assigned any value within the loop
32695 \end_layout
32696
32697 \begin_layout Itemize
32698 The loop control variable does NOT participate in any arithmetic operation
32699  within the loop.
32700 \end_layout
32701
32702 \begin_layout Itemize
32703 There are NO switch statements in the loop.
32704 \end_layout
32705
32706 \begin_layout Subsection
32707 Algebraic Simplifications
32708 \end_layout
32709
32710 \begin_layout Standard
32711 SDCC does numerous algebraic simplifications, the following is a small sub-set
32712  of these optimizations.
32713 \end_layout
32714
32715 \begin_layout Verse
32716
32717 \family typewriter
32718 i = j + 0;\InsetSpace ~
32719 \InsetSpace ~
32720 \InsetSpace ~
32721 \InsetSpace ~
32722  /* changed to: */\InsetSpace ~
32723 \InsetSpace ~
32724 \InsetSpace ~
32725 \InsetSpace ~
32726  i = j; 
32727 \newline
32728 i /= 2;\InsetSpace ~
32729 \InsetSpace ~
32730 \InsetSpace ~
32731 \InsetSpace ~
32732 \InsetSpace ~
32733 \InsetSpace ~
32734 \InsetSpace ~
32735  /* changed to: */\InsetSpace ~
32736 \InsetSpace ~
32737 \InsetSpace ~
32738 \InsetSpace ~
32739  i >>= 1; 
32740 \newline
32741 i
32742  = j - j;\InsetSpace ~
32743 \InsetSpace ~
32744 \InsetSpace ~
32745 \InsetSpace ~
32746  /* changed to: */\InsetSpace ~
32747 \InsetSpace ~
32748 \InsetSpace ~
32749 \InsetSpace ~
32750  i = 0; 
32751 \newline
32752 i = j / 1;\InsetSpace ~
32753 \InsetSpace ~
32754 \InsetSpace ~
32755 \InsetSpace ~
32756  /* changed to: */\InsetSpace ~
32757 \InsetSpace ~
32758 \InsetSpace ~
32759 \InsetSpace ~
32760  i = j;
32761 \end_layout
32762
32763 \begin_layout Standard
32764 Note the subexpressions
32765 \begin_inset LatexCommand \index{Subexpression}
32766
32767 \end_inset
32768
32769  given above are generally introduced by macro expansions or as a result
32770  of copy/constant propagation.
32771 \end_layout
32772
32773 \begin_layout Subsection
32774 'switch' Statements
32775 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32776
32777 \end_inset
32778
32779
32780 \begin_inset LatexCommand \index{switch statement}
32781
32782 \end_inset
32783
32784
32785 \end_layout
32786
32787 \begin_layout Standard
32788 SDCC can optimize switch statements to jump tables
32789 \begin_inset LatexCommand \index{jump tables}
32790
32791 \end_inset
32792
32793 .
32794  It makes the decision based on an estimate of the generated code size.
32795  SDCC is quite liberal in the requirements for jump table generation: 
32796 \end_layout
32797
32798 \begin_layout Itemize
32799 The labels need not be in order, and the starting number need not be one
32800  or zero, the case labels are in numerical sequence or not too many case
32801  labels are missing.
32802 \end_layout
32803
32804 \begin_deeper
32805 \begin_layout Verse
32806
32807 \family typewriter
32808 switch(i) {\InsetSpace ~
32809 \InsetSpace ~
32810 \InsetSpace ~
32811 \InsetSpace ~
32812 \InsetSpace ~
32813 \InsetSpace ~
32814 \InsetSpace ~
32815 \InsetSpace ~
32816 \InsetSpace ~
32817 \InsetSpace ~
32818 \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 switch (i) { 
32835 \newline
32836 \InsetSpace ~
32837 \InsetSpace ~
32838 \InsetSpace ~
32839 case 4: ...\InsetSpace ~
32840 \InsetSpace ~
32841 \InsetSpace ~
32842 \InsetSpace ~
32843 \InsetSpace ~
32844 \InsetSpace ~
32845 \InsetSpace ~
32846 \InsetSpace ~
32847 \InsetSpace ~
32848 \InsetSpace ~
32849 \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 case 0: ...
32866  
32867 \newline
32868 \InsetSpace ~
32869 \InsetSpace ~
32870 \InsetSpace ~
32871 case 5: ...\InsetSpace ~
32872 \InsetSpace ~
32873 \InsetSpace ~
32874 \InsetSpace ~
32875 \InsetSpace ~
32876 \InsetSpace ~
32877 \InsetSpace ~
32878 \InsetSpace ~
32879 \InsetSpace ~
32880 \InsetSpace ~
32881 \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 case 1: ...
32898  
32899 \newline
32900 \InsetSpace ~
32901 \InsetSpace ~
32902 \InsetSpace ~
32903 case 3: ...\InsetSpace ~
32904 \InsetSpace ~
32905 \InsetSpace ~
32906 \InsetSpace ~
32907 \InsetSpace ~
32908 \InsetSpace ~
32909 \InsetSpace ~
32910 \InsetSpace ~
32911 \InsetSpace ~
32912 \InsetSpace ~
32913 \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
32930 \newline
32931 \InsetSpace ~
32932 \InsetSpace ~
32933 \InsetSpace ~
32934 case 6: ...\InsetSpace ~
32935 \InsetSpace ~
32936 \InsetSpace ~
32937 \InsetSpace ~
32938 \InsetSpace ~
32939 \InsetSpace ~
32940 \InsetSpace ~
32941 \InsetSpace ~
32942 \InsetSpace ~
32943 \InsetSpace ~
32944 \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 case 3: ...
32961  
32962 \newline
32963 \InsetSpace ~
32964 \InsetSpace ~
32965 \InsetSpace ~
32966 case 7: ...\InsetSpace ~
32967 \InsetSpace ~
32968 \InsetSpace ~
32969 \InsetSpace ~
32970 \InsetSpace ~
32971 \InsetSpace ~
32972 \InsetSpace ~
32973 \InsetSpace ~
32974 \InsetSpace ~
32975 \InsetSpace ~
32976 \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 case 4: ...
32993  
32994 \newline
32995 \InsetSpace ~
32996 \InsetSpace ~
32997 \InsetSpace ~
32998 case 8: ...\InsetSpace ~
32999 \InsetSpace ~
33000 \InsetSpace ~
33001 \InsetSpace ~
33002 \InsetSpace ~
33003 \InsetSpace ~
33004 \InsetSpace ~
33005 \InsetSpace ~
33006 \InsetSpace ~
33007 \InsetSpace ~
33008 \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 case 5: ...
33025  
33026 \newline
33027 \InsetSpace ~
33028 \InsetSpace ~
33029 \InsetSpace ~
33030 case 9: ...\InsetSpace ~
33031 \InsetSpace ~
33032 \InsetSpace ~
33033 \InsetSpace ~
33034 \InsetSpace ~
33035 \InsetSpace ~
33036 \InsetSpace ~
33037 \InsetSpace ~
33038 \InsetSpace ~
33039 \InsetSpace ~
33040 \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 case 6: ...
33057  
33058 \newline
33059 \InsetSpace ~
33060 \InsetSpace ~
33061 \InsetSpace ~
33062 case 10: ...\InsetSpace ~
33063 \InsetSpace ~
33064 \InsetSpace ~
33065 \InsetSpace ~
33066 \InsetSpace ~
33067 \InsetSpace ~
33068 \InsetSpace ~
33069 \InsetSpace ~
33070 \InsetSpace ~
33071 \InsetSpace ~
33072 \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 case 7: ...
33088  
33089 \newline
33090 \InsetSpace ~
33091 \InsetSpace ~
33092 \InsetSpace ~
33093 case 11: ...\InsetSpace ~
33094 \InsetSpace ~
33095 \InsetSpace ~
33096 \InsetSpace ~
33097 \InsetSpace ~
33098 \InsetSpace ~
33099 \InsetSpace ~
33100 \InsetSpace ~
33101 \InsetSpace ~
33102 \InsetSpace ~
33103 \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 case 8: ...
33119  
33120 \newline
33121 }\InsetSpace ~
33122 \InsetSpace ~
33123 \InsetSpace ~
33124 \InsetSpace ~
33125 \InsetSpace ~
33126 \InsetSpace ~
33127 \InsetSpace ~
33128 \InsetSpace ~
33129 \InsetSpace ~
33130 \InsetSpace ~
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 }
33158 \end_layout
33159
33160 \begin_layout Standard
33161 Both the above switch statements will be implemented using a jump-table.
33162  The example to the right side is slightly more efficient as the check for
33163  the lower boundary of the jump-table is not needed.
33164 \end_layout
33165
33166 \end_deeper
33167 \begin_layout Itemize
33168 The number of case labels is not larger than supported by the target architectur
33169 e.
33170 \end_layout
33171
33172 \begin_layout Itemize
33173 If the case labels are not in numerical sequence ('gaps' between cases)
33174  SDCC checks whether a jump table with additionally inserted dummy cases
33175  is still attractive.
33176  
33177 \end_layout
33178
33179 \begin_layout Itemize
33180 If the starting number is not zero and a check for the lower boundary of
33181  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33182  ...
33183  .
33184 \end_layout
33185
33186 \begin_layout Standard
33187 Switch statements which have large gaps in the numeric sequence or those
33188  that have too many case labels can be split into more than one switch statement
33189  for efficient code generation, e.g.:
33190 \end_layout
33191
33192 \begin_layout Verse
33193
33194 \family typewriter
33195 switch (i) { 
33196 \newline
33197 \InsetSpace ~
33198 \InsetSpace ~
33199 case 1: ...
33200  
33201 \newline
33202 \InsetSpace ~
33203 \InsetSpace ~
33204 case 2: ...
33205  
33206 \newline
33207 \InsetSpace ~
33208 \InsetSpace ~
33209 case 3: ...
33210  
33211 \newline
33212 \InsetSpace ~
33213 \InsetSpace ~
33214 case 4: ...
33215  
33216 \newline
33217 \InsetSpace ~
33218 \InsetSpace ~
33219 case 5: ...
33220  
33221 \newline
33222 \InsetSpace ~
33223 \InsetSpace ~
33224 case 6: ...
33225  
33226 \newline
33227 \InsetSpace ~
33228 \InsetSpace ~
33229 case 7: ...
33230  
33231 \newline
33232 \InsetSpace ~
33233 \InsetSpace ~
33234 case 101: ...
33235  
33236 \newline
33237 \InsetSpace ~
33238 \InsetSpace ~
33239 case 102: ...
33240  
33241 \newline
33242 \InsetSpace ~
33243 \InsetSpace ~
33244 case 103: ...
33245  
33246 \newline
33247 \InsetSpace ~
33248 \InsetSpace ~
33249 case 104: ...
33250  
33251 \newline
33252 \InsetSpace ~
33253 \InsetSpace ~
33254 case 105: ...
33255  
33256 \newline
33257 \InsetSpace ~
33258 \InsetSpace ~
33259 case 106: ...
33260  
33261 \newline
33262 \InsetSpace ~
33263 \InsetSpace ~
33264 case 107: ...
33265  
33266 \newline
33267 }
33268 \end_layout
33269
33270 \begin_layout Standard
33271 If the above switch statement is broken down into two switch statements
33272 \end_layout
33273
33274 \begin_layout Verse
33275
33276 \family typewriter
33277 switch (i) { 
33278 \newline
33279 \InsetSpace ~
33280 \InsetSpace ~
33281 case 1: ...
33282  
33283 \newline
33284 \InsetSpace ~
33285 \InsetSpace ~
33286 case 2: ...
33287  
33288 \newline
33289 \InsetSpace ~
33290 \InsetSpace ~
33291 case 3: ...
33292  
33293 \newline
33294 \InsetSpace ~
33295 \InsetSpace ~
33296 case 4: ...
33297  
33298 \newline
33299 \InsetSpace ~
33300 \InsetSpace ~
33301 case 5: ...
33302  
33303 \newline
33304 \InsetSpace ~
33305 \InsetSpace ~
33306 case 6: ...
33307  
33308 \newline
33309 \InsetSpace ~
33310 \InsetSpace ~
33311 case 7: ...
33312  
33313 \newline
33314 }
33315 \end_layout
33316
33317 \begin_layout Standard
33318 and
33319 \end_layout
33320
33321 \begin_layout Verse
33322
33323 \family typewriter
33324 switch (i) { 
33325 \newline
33326 \InsetSpace ~
33327 \InsetSpace ~
33328 case 101: ...
33329  
33330 \newline
33331 \InsetSpace ~
33332 \InsetSpace ~
33333 case 102: ...
33334  
33335 \newline
33336 \InsetSpace ~
33337 \InsetSpace ~
33338 case 103: ...
33339  
33340 \newline
33341 \InsetSpace ~
33342 \InsetSpace ~
33343 case 104: ...
33344  
33345 \newline
33346 \InsetSpace ~
33347 \InsetSpace ~
33348 case 105: ...
33349  
33350 \newline
33351 \InsetSpace ~
33352 \InsetSpace ~
33353 case 106: ...
33354  
33355 \newline
33356 \InsetSpace ~
33357 \InsetSpace ~
33358 case 107: ...
33359  
33360 \newline
33361 }
33362 \end_layout
33363
33364 \begin_layout Standard
33365 then both the switch statements will be implemented using jump-tables whereas
33366  the unmodified switch statement will not be.
33367 \end_layout
33368
33369 \begin_layout Standard
33370 \begin_inset Note Note
33371 status collapsed
33372
33373 \begin_layout Standard
33374 There might be reasons which SDCC cannot know about to either favour or
33375  not favour jump tables.
33376  If the target system has to be as quick for the last switch case as for
33377  the first (pro jump table), or if the switch argument is known to be zero
33378  in the majority of the cases (contra jump table).
33379 \end_layout
33380
33381 \end_inset
33382
33383
33384 \end_layout
33385
33386 \begin_layout Standard
33387 The pragma nojtbound
33388 \begin_inset LatexCommand \index{\#pragma nojtbound}
33389
33390 \end_inset
33391
33392  can be used to turn off checking the 
33393 \emph on
33394 j
33395 \emph default
33396 ump 
33397 \emph on
33398 t
33399 \emph default
33400 able 
33401 \emph on
33402 bound
33403 \emph default
33404 aries.
33405  It has no effect if a default label is supplied.
33406  Use of this pragma is dangerous: if the switch
33407 \begin_inset LatexCommand \index{switch statement}
33408
33409 \end_inset
33410
33411  argument is not matched by a case statement the processor will happily
33412  jump into Nirvana.
33413 \end_layout
33414
33415 \begin_layout Subsection
33416 Bit-shifting Operations
33417 \begin_inset LatexCommand \index{Bit shifting}
33418
33419 \end_inset
33420
33421 .
33422 \end_layout
33423
33424 \begin_layout Standard
33425 Bit shifting is one of the most frequently used operation in embedded programmin
33426 g.
33427  SDCC tries to implement bit-shift operations in the most efficient way
33428  possible, e.g.:
33429 \end_layout
33430
33431 \begin_layout Verse
33432
33433 \family typewriter
33434 unsigned char i;
33435 \newline
33436 ...
33437  
33438 \newline
33439 i >>= 4; 
33440 \newline
33441 ...
33442 \end_layout
33443
33444 \begin_layout Standard
33445 generates the following code:
33446 \end_layout
33447
33448 \begin_layout Verse
33449
33450 \family typewriter
33451 mov\InsetSpace ~
33452  a,_i 
33453 \newline
33454 swap a 
33455 \newline
33456 anl\InsetSpace ~
33457  a,#0x0f 
33458 \newline
33459 mov\InsetSpace ~
33460  _i,a
33461 \end_layout
33462
33463 \begin_layout Standard
33464 In general SDCC will never setup a loop if the shift count is known.
33465  Another example:
33466 \end_layout
33467
33468 \begin_layout Verse
33469
33470 \family typewriter
33471 unsigned int i; 
33472 \newline
33473 ...
33474  
33475 \newline
33476 i >>= 9; 
33477 \newline
33478 ...
33479 \end_layout
33480
33481 \begin_layout Standard
33482 will generate:
33483 \end_layout
33484
33485 \begin_layout Verse
33486
33487 \family typewriter
33488 mov\InsetSpace ~
33489 \InsetSpace ~
33490 a,(_i + 1) 
33491 \newline
33492 mov\InsetSpace ~
33493 \InsetSpace ~
33494 (_i + 1),#0x00 
33495 \newline
33496 clr\InsetSpace ~
33497 \InsetSpace ~
33498
33499 \newline
33500 rrc\InsetSpace ~
33501 \InsetSpace ~
33502
33503 \newline
33504 mov\InsetSpace ~
33505 \InsetSpace ~
33506 _i,a
33507 \end_layout
33508
33509 \begin_layout Subsection
33510 Bit-rotation
33511 \begin_inset LatexCommand \index{Bit rotation}
33512
33513 \end_inset
33514
33515
33516 \end_layout
33517
33518 \begin_layout Standard
33519 A special case of the bit-shift operation is bit rotation
33520 \begin_inset LatexCommand \index{rotating bits}
33521
33522 \end_inset
33523
33524 , SDCC recognizes the following expression to be a left bit-rotation:
33525 \end_layout
33526
33527 \begin_layout Verse
33528
33529 \family typewriter
33530 \series bold
33531 unsigned
33532 \series default
33533 \InsetSpace ~
33534 \InsetSpace ~
33535 char i;\InsetSpace ~
33536 \InsetSpace ~
33537 \InsetSpace ~
33538 \InsetSpace ~
33539 \InsetSpace ~
33540 \InsetSpace ~
33541 \InsetSpace ~
33542 \InsetSpace ~
33543 \InsetSpace ~
33544 \InsetSpace ~
33545 \InsetSpace ~
33546 /* unsigned is needed for rotation */ 
33547 \newline
33548 ...
33549  
33550 \newline
33551 i = ((i << 1) | (i >> 7)); 
33552 \family default
33553
33554 \newline
33555
33556 \family typewriter
33557 ...
33558 \end_layout
33559
33560 \begin_layout Standard
33561 will generate the following code:
33562 \end_layout
33563
33564 \begin_layout Verse
33565
33566 \family typewriter
33567 mov\InsetSpace ~
33568 \InsetSpace ~
33569 a,_i 
33570 \newline
33571 rl\InsetSpace ~
33572 \InsetSpace ~
33573 \InsetSpace ~
33574
33575 \newline
33576 mov\InsetSpace ~
33577 \InsetSpace ~
33578 _i,a
33579 \end_layout
33580
33581 \begin_layout Standard
33582 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33583 ns of this case will also be recognized as bit-rotation, i.e.: 
33584 \end_layout
33585
33586 \begin_layout Verse
33587
33588 \family typewriter
33589 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33590 \end_layout
33591
33592 \begin_layout Subsection
33593 Nibble and Byte Swapping
33594 \end_layout
33595
33596 \begin_layout Standard
33597 Other special cases of the bit-shift operations are nibble or byte swapping
33598 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33599
33600 \end_inset
33601
33602 , SDCC recognizes the following expressions:
33603 \end_layout
33604
33605 \begin_layout Verse
33606
33607 \family typewriter
33608 \series bold
33609 unsigned
33610 \series default
33611 \InsetSpace ~
33612 \InsetSpace ~
33613 char i; 
33614 \newline
33615
33616 \series bold
33617 unsigned
33618 \series default
33619 \InsetSpace ~
33620 \InsetSpace ~
33621 int j; 
33622 \newline
33623 ...
33624  
33625 \newline
33626 i = ((i << 4) | (i >> 4)); 
33627 \family default
33628
33629 \newline
33630
33631 \family typewriter
33632 j = ((j << 8) | (j >> 8)); 
33633 \end_layout
33634
33635 \begin_layout Standard
33636 and generates a swap instruction for the nibble swapping
33637 \begin_inset LatexCommand \index{Nibble swapping}
33638
33639 \end_inset
33640
33641  or move instructions for the byte swapping
33642 \begin_inset LatexCommand \index{Byte swapping}
33643
33644 \end_inset
33645
33646 .
33647  The 
33648 \begin_inset Quotes sld
33649 \end_inset
33650
33651 j
33652 \begin_inset Quotes srd
33653 \end_inset
33654
33655  example can be used to convert from little to big-endian or vice versa.
33656  If you want to change the endianness of a 
33657 \emph on
33658 signed
33659 \emph default
33660  integer you have to cast to 
33661 \family typewriter
33662 (unsigned int)
33663 \family default
33664  first.
33665 \end_layout
33666
33667 \begin_layout Standard
33668 Note that SDCC stores numbers in little-endian
33669 \begin_inset Foot
33670 status open
33671
33672 \begin_layout Standard
33673 Usually 8-bit processors don't care much about endianness.
33674  This is not the case for the standard 8051 which only has an instruction
33675  to increment its 
33676 \emph on
33677 dptr
33678 \emph default
33679
33680 \begin_inset LatexCommand \index{DPTR}
33681
33682 \end_inset
33683
33684 -datapointer
33685 \emph on
33686  
33687 \emph default
33688 so little-endian is the more efficient byte order.
33689 \end_layout
33690
33691 \end_inset
33692
33693
33694 \begin_inset LatexCommand \index{little-endian}
33695
33696 \end_inset
33697
33698
33699 \begin_inset LatexCommand \index{Endianness}
33700
33701 \end_inset
33702
33703  format (i.e.
33704  lowest order first).
33705 \end_layout
33706
33707 \begin_layout Subsection
33708 Highest Order Bit
33709 \begin_inset LatexCommand \index{Highest Order Bit}
33710
33711 \end_inset
33712
33713  / Any Order Bit
33714 \begin_inset LatexCommand \index{Any Order Bit}
33715
33716 \end_inset
33717
33718
33719 \end_layout
33720
33721 \begin_layout Standard
33722 It is frequently required to obtain the highest order bit of an integral
33723  type (long, int, short or char types).
33724  Also obtaining any other order bit is not uncommon.
33725  SDCC recognizes the following expressions to yield the highest order bit
33726  and generates optimized code for it, e.g.:
33727 \end_layout
33728
33729 \begin_layout Verse
33730
33731 \family typewriter
33732 unsigned int gint; 
33733 \newline
33734
33735 \newline
33736 foo () { 
33737 \newline
33738 \InsetSpace ~
33739 \InsetSpace ~
33740 unsigned char hob1, aob1; 
33741 \newline
33742 \InsetSpace ~
33743 \InsetSpace ~
33744 bit hob2, hob3, aob2,
33745  aob3; 
33746 \newline
33747 \InsetSpace ~
33748 \InsetSpace ~
33749 ...
33750  
33751 \newline
33752 \InsetSpace ~
33753 \InsetSpace ~
33754 hob1 = (gint >> 15) & 1; 
33755 \newline
33756 \InsetSpace ~
33757 \InsetSpace ~
33758 hob2 = (gint >> 15) & 1; 
33759 \newline
33760 \InsetSpace ~
33761 \InsetSpace ~
33762 hob3 = gint & 0x8000;
33763  
33764 \newline
33765 \InsetSpace ~
33766 \InsetSpace ~
33767 aob1 = (gint >> 9) & 1; 
33768 \newline
33769 \InsetSpace ~
33770 \InsetSpace ~
33771 aob2 = (gint >> 8) & 1; 
33772 \newline
33773 \InsetSpace ~
33774 \InsetSpace ~
33775 aob3 = gint & 0x0800; 
33776 \newline
33777 \InsetSpace ~
33778 \InsetSpace ~
33779 ..
33780  
33781 \newline
33782 }
33783 \end_layout
33784
33785 \begin_layout Standard
33786 will generate the following code:
33787 \end_layout
33788
33789 \begin_layout Verse
33790
33791 \family typewriter
33792 \InsetSpace ~
33793 \InsetSpace ~
33794 \InsetSpace ~
33795 \InsetSpace ~
33796 \InsetSpace ~
33797 \InsetSpace ~
33798 \InsetSpace ~
33799 \InsetSpace ~
33800 \InsetSpace ~
33801 \InsetSpace ~
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  61 ;\InsetSpace ~
33818  hob.c 7 
33819 \newline
33820 000A E5*01\InsetSpace ~
33821 \InsetSpace ~
33822 \InsetSpace ~
33823 \InsetSpace ~
33824 \InsetSpace ~
33825 \InsetSpace ~
33826 \InsetSpace ~
33827 \InsetSpace ~
33828 \InsetSpace ~
33829 \InsetSpace ~
33830 \InsetSpace ~
33831 \InsetSpace ~
33832 \InsetSpace ~
33833 \InsetSpace ~
33834 \InsetSpace ~
33835  62\InsetSpace ~
33836 \InsetSpace ~
33837 \InsetSpace ~
33838 \InsetSpace ~
33839 \InsetSpace ~
33840 \InsetSpace ~
33841 \InsetSpace ~
33842 \InsetSpace ~
33843  mov\InsetSpace ~
33844 \InsetSpace ~
33845  a,(_gint + 1) 
33846 \newline
33847 000C 23\InsetSpace ~
33848 \InsetSpace ~
33849 \InsetSpace ~
33850 \InsetSpace ~
33851 \InsetSpace ~
33852 \InsetSpace ~
33853 \InsetSpace ~
33854 \InsetSpace ~
33855 \InsetSpace ~
33856 \InsetSpace ~
33857 \InsetSpace ~
33858 \InsetSpace ~
33859 \InsetSpace ~
33860 \InsetSpace ~
33861 \InsetSpace ~
33862 \InsetSpace ~
33863 \InsetSpace ~
33864 \InsetSpace ~
33865  63\InsetSpace ~
33866 \InsetSpace ~
33867 \InsetSpace ~
33868 \InsetSpace ~
33869 \InsetSpace ~
33870 \InsetSpace ~
33871 \InsetSpace ~
33872 \InsetSpace ~
33873  rl\InsetSpace ~
33874 \InsetSpace ~
33875 \InsetSpace ~
33876  a 
33877 \newline
33878 000D 54 01\InsetSpace ~
33879 \InsetSpace ~
33880 \InsetSpace ~
33881 \InsetSpace ~
33882 \InsetSpace ~
33883 \InsetSpace ~
33884 \InsetSpace ~
33885 \InsetSpace ~
33886 \InsetSpace ~
33887 \InsetSpace ~
33888 \InsetSpace ~
33889 \InsetSpace ~
33890 \InsetSpace ~
33891 \InsetSpace ~
33892 \InsetSpace ~
33893
33894  64\InsetSpace ~
33895 \InsetSpace ~
33896 \InsetSpace ~
33897 \InsetSpace ~
33898 \InsetSpace ~
33899 \InsetSpace ~
33900 \InsetSpace ~
33901 \InsetSpace ~
33902  anl\InsetSpace ~
33903 \InsetSpace ~
33904  a,#0x01 
33905 \newline
33906 000F F5*02\InsetSpace ~
33907 \InsetSpace ~
33908 \InsetSpace ~
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 \InsetSpace ~
33912 \InsetSpace ~
33913 \InsetSpace ~
33914 \InsetSpace ~
33915 \InsetSpace ~
33916 \InsetSpace ~
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 \InsetSpace ~
33920 \InsetSpace ~
33921  65\InsetSpace ~
33922 \InsetSpace ~
33923 \InsetSpace ~
33924 \InsetSpace ~
33925 \InsetSpace ~
33926 \InsetSpace ~
33927 \InsetSpace ~
33928 \InsetSpace ~
33929  mov\InsetSpace ~
33930 \InsetSpace ~
33931  _foo_hob1_1_1,a 
33932 \newline
33933 \InsetSpace ~
33934 \InsetSpace ~
33935 \InsetSpace ~
33936 \InsetSpace ~
33937 \InsetSpace ~
33938 \InsetSpace ~
33939 \InsetSpace ~
33940 \InsetSpace ~
33941 \InsetSpace ~
33942 \InsetSpace ~
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  66 ;\InsetSpace ~
33959  hob.c 8 
33960 \newline
33961 0011 E5*01\InsetSpace ~
33962 \InsetSpace ~
33963 \InsetSpace ~
33964 \InsetSpace ~
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 \InsetSpace ~
33968 \InsetSpace ~
33969 \InsetSpace ~
33970 \InsetSpace ~
33971 \InsetSpace ~
33972 \InsetSpace ~
33973 \InsetSpace ~
33974 \InsetSpace ~
33975 \InsetSpace ~
33976
33977  67\InsetSpace ~
33978 \InsetSpace ~
33979 \InsetSpace ~
33980 \InsetSpace ~
33981 \InsetSpace ~
33982 \InsetSpace ~
33983 \InsetSpace ~
33984 \InsetSpace ~
33985  mov\InsetSpace ~
33986 \InsetSpace ~
33987  a,(_gint + 1) 
33988 \newline
33989 0013 33\InsetSpace ~
33990 \InsetSpace ~
33991 \InsetSpace ~
33992 \InsetSpace ~
33993 \InsetSpace ~
33994 \InsetSpace ~
33995 \InsetSpace ~
33996 \InsetSpace ~
33997 \InsetSpace ~
33998 \InsetSpace ~
33999 \InsetSpace ~
34000 \InsetSpace ~
34001 \InsetSpace ~
34002 \InsetSpace ~
34003 \InsetSpace ~
34004 \InsetSpace ~
34005 \InsetSpace ~
34006 \InsetSpace ~
34007  68\InsetSpace ~
34008 \InsetSpace ~
34009 \InsetSpace ~
34010 \InsetSpace ~
34011 \InsetSpace ~
34012 \InsetSpace ~
34013 \InsetSpace ~
34014 \InsetSpace ~
34015  rlc\InsetSpace ~
34016 \InsetSpace ~
34017  a 
34018 \newline
34019 0014 92*00\InsetSpace ~
34020 \InsetSpace ~
34021 \InsetSpace ~
34022 \InsetSpace ~
34023 \InsetSpace ~
34024 \InsetSpace ~
34025 \InsetSpace ~
34026 \InsetSpace ~
34027 \InsetSpace ~
34028 \InsetSpace ~
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 \InsetSpace ~
34032 \InsetSpace ~
34033 \InsetSpace ~
34034  69\InsetSpace ~
34035 \InsetSpace ~
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 \InsetSpace ~
34039 \InsetSpace ~
34040 \InsetSpace ~
34041 \InsetSpace ~
34042  mov\InsetSpace ~
34043 \InsetSpace ~
34044  _foo_hob2_1_1,c
34045  
34046 \newline
34047 \InsetSpace ~
34048 \InsetSpace ~
34049 \InsetSpace ~
34050 \InsetSpace ~
34051 \InsetSpace ~
34052 \InsetSpace ~
34053 \InsetSpace ~
34054 \InsetSpace ~
34055 \InsetSpace ~
34056 \InsetSpace ~
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  66 ;\InsetSpace ~
34073  hob.c 9 
34074 \newline
34075 0016 E5*01\InsetSpace ~
34076 \InsetSpace ~
34077 \InsetSpace ~
34078 \InsetSpace ~
34079 \InsetSpace ~
34080 \InsetSpace ~
34081 \InsetSpace ~
34082 \InsetSpace ~
34083 \InsetSpace ~
34084 \InsetSpace ~
34085 \InsetSpace ~
34086 \InsetSpace ~
34087 \InsetSpace ~
34088 \InsetSpace ~
34089 \InsetSpace ~
34090  67\InsetSpace ~
34091 \InsetSpace ~
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 \InsetSpace ~
34098  mov\InsetSpace ~
34099 \InsetSpace ~
34100  a,(_gint + 1) 
34101 \newline
34102 0018 33\InsetSpace ~
34103 \InsetSpace ~
34104 \InsetSpace ~
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 \InsetSpace ~
34109 \InsetSpace ~
34110 \InsetSpace ~
34111 \InsetSpace ~
34112 \InsetSpace ~
34113 \InsetSpace ~
34114 \InsetSpace ~
34115 \InsetSpace ~
34116 \InsetSpace ~
34117 \InsetSpace ~
34118 \InsetSpace ~
34119 \InsetSpace ~
34120  68\InsetSpace ~
34121 \InsetSpace ~
34122 \InsetSpace ~
34123 \InsetSpace ~
34124 \InsetSpace ~
34125 \InsetSpace ~
34126 \InsetSpace ~
34127 \InsetSpace ~
34128  rlc\InsetSpace ~
34129 \InsetSpace ~
34130  a 
34131 \newline
34132 0019 92*01\InsetSpace ~
34133 \InsetSpace ~
34134 \InsetSpace ~
34135 \InsetSpace ~
34136 \InsetSpace ~
34137 \InsetSpace ~
34138 \InsetSpace ~
34139 \InsetSpace ~
34140 \InsetSpace ~
34141 \InsetSpace ~
34142 \InsetSpace ~
34143 \InsetSpace ~
34144 \InsetSpace ~
34145 \InsetSpace ~
34146 \InsetSpace ~
34147
34148  69\InsetSpace ~
34149 \InsetSpace ~
34150 \InsetSpace ~
34151 \InsetSpace ~
34152 \InsetSpace ~
34153 \InsetSpace ~
34154 \InsetSpace ~
34155 \InsetSpace ~
34156  mov\InsetSpace ~
34157 \InsetSpace ~
34158  _foo_hob3_1_1,c 
34159 \newline
34160 \InsetSpace ~
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 \InsetSpace ~
34166 \InsetSpace ~
34167 \InsetSpace ~
34168 \InsetSpace ~
34169 \InsetSpace ~
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  70 ;\InsetSpace ~
34186  hob.c 10 
34187 \newline
34188 001B E5*01\InsetSpace ~
34189 \InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194 \InsetSpace ~
34195 \InsetSpace ~
34196 \InsetSpace ~
34197 \InsetSpace ~
34198 \InsetSpace ~
34199 \InsetSpace ~
34200 \InsetSpace ~
34201 \InsetSpace ~
34202 \InsetSpace ~
34203  71\InsetSpace ~
34204 \InsetSpace ~
34205 \InsetSpace ~
34206 \InsetSpace ~
34207 \InsetSpace ~
34208 \InsetSpace ~
34209 \InsetSpace ~
34210 \InsetSpace ~
34211  mov\InsetSpace ~
34212 \InsetSpace ~
34213  a,(_gint + 1) 
34214 \newline
34215 001D
34216  03\InsetSpace ~
34217 \InsetSpace ~
34218 \InsetSpace ~
34219 \InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225 \InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230 \InsetSpace ~
34231 \InsetSpace ~
34232 \InsetSpace ~
34233 \InsetSpace ~
34234  72\InsetSpace ~
34235 \InsetSpace ~
34236 \InsetSpace ~
34237 \InsetSpace ~
34238 \InsetSpace ~
34239 \InsetSpace ~
34240 \InsetSpace ~
34241 \InsetSpace ~
34242  rr\InsetSpace ~
34243 \InsetSpace ~
34244 \InsetSpace ~
34245  a 
34246 \newline
34247 001E 54 01\InsetSpace ~
34248 \InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258 \InsetSpace ~
34259 \InsetSpace ~
34260 \InsetSpace ~
34261 \InsetSpace ~
34262  73\InsetSpace ~
34263 \InsetSpace ~
34264 \InsetSpace ~
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 \InsetSpace ~
34268 \InsetSpace ~
34269 \InsetSpace ~
34270  anl\InsetSpace ~
34271 \InsetSpace ~
34272  a,#0x01 
34273 \newline
34274 0020 F5*03\InsetSpace ~
34275 \InsetSpace ~
34276 \InsetSpace ~
34277 \InsetSpace ~
34278 \InsetSpace ~
34279 \InsetSpace ~
34280 \InsetSpace ~
34281 \InsetSpace ~
34282 \InsetSpace ~
34283 \InsetSpace ~
34284 \InsetSpace ~
34285 \InsetSpace ~
34286 \InsetSpace ~
34287 \InsetSpace ~
34288 \InsetSpace ~
34289  74\InsetSpace ~
34290 \InsetSpace ~
34291 \InsetSpace ~
34292 \InsetSpace ~
34293 \InsetSpace ~
34294 \InsetSpace ~
34295 \InsetSpace ~
34296 \InsetSpace ~
34297  mov\InsetSpace ~
34298 \InsetSpace ~
34299  _foo_aob1_1_1,a
34300  
34301 \newline
34302 \InsetSpace ~
34303 \InsetSpace ~
34304 \InsetSpace ~
34305 \InsetSpace ~
34306 \InsetSpace ~
34307 \InsetSpace ~
34308 \InsetSpace ~
34309 \InsetSpace ~
34310 \InsetSpace ~
34311 \InsetSpace ~
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  75 ;\InsetSpace ~
34328  hob.c 11 
34329 \newline
34330 0022 E5*01\InsetSpace ~
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 \InsetSpace ~
34337 \InsetSpace ~
34338 \InsetSpace ~
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345  76\InsetSpace ~
34346 \InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353  mov\InsetSpace ~
34354 \InsetSpace ~
34355  a,(_gint + 1) 
34356 \newline
34357 0024 13\InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369 \InsetSpace ~
34370 \InsetSpace ~
34371 \InsetSpace ~
34372 \InsetSpace ~
34373 \InsetSpace ~
34374 \InsetSpace ~
34375  77\InsetSpace ~
34376 \InsetSpace ~
34377 \InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381 \InsetSpace ~
34382 \InsetSpace ~
34383  rrc\InsetSpace ~
34384 \InsetSpace ~
34385  a 
34386 \newline
34387 0025 92*02\InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392 \InsetSpace ~
34393 \InsetSpace ~
34394 \InsetSpace ~
34395 \InsetSpace ~
34396 \InsetSpace ~
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 \InsetSpace ~
34401 \InsetSpace ~
34402
34403  78\InsetSpace ~
34404 \InsetSpace ~
34405 \InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411  mov\InsetSpace ~
34412 \InsetSpace ~
34413  _foo_aob2_1_1,c 
34414 \newline
34415 \InsetSpace ~
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421 \InsetSpace ~
34422 \InsetSpace ~
34423 \InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426 \InsetSpace ~
34427 \InsetSpace ~
34428 \InsetSpace ~
34429 \InsetSpace ~
34430 \InsetSpace ~
34431 \InsetSpace ~
34432 \InsetSpace ~
34433 \InsetSpace ~
34434 \InsetSpace ~
34435 \InsetSpace ~
34436 \InsetSpace ~
34437 \InsetSpace ~
34438 \InsetSpace ~
34439 \InsetSpace ~
34440  79 ;\InsetSpace ~
34441  hob.c 12 
34442 \newline
34443 0027 E5*01\InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450 \InsetSpace ~
34451 \InsetSpace ~
34452 \InsetSpace ~
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457 \InsetSpace ~
34458  80\InsetSpace ~
34459 \InsetSpace ~
34460 \InsetSpace ~
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 \InsetSpace ~
34464 \InsetSpace ~
34465 \InsetSpace ~
34466  mov\InsetSpace ~
34467 \InsetSpace ~
34468  a,(_gint + 1) 
34469 \newline
34470 0029
34471  A2 E3\InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 \InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486  81\InsetSpace ~
34487 \InsetSpace ~
34488 \InsetSpace ~
34489 \InsetSpace ~
34490 \InsetSpace ~
34491 \InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494  mov\InsetSpace ~
34495 \InsetSpace ~
34496  c,acc[3] 
34497 \newline
34498 002B 92*03\InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505 \InsetSpace ~
34506 \InsetSpace ~
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513  82\InsetSpace ~
34514 \InsetSpace ~
34515 \InsetSpace ~
34516 \InsetSpace ~
34517 \InsetSpace ~
34518 \InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521  mov\InsetSpace ~
34522 \InsetSpace ~
34523  _foo_aob3_1_1,c 
34524 \end_layout
34525
34526 \begin_layout Standard
34527 Other variations of these cases however will 
34528 \emph on
34529 not
34530 \emph default
34531  be recognized.
34532  They are standard C expressions, so I heartily recommend these be the only
34533  way to get the highest order bit, (it is portable).
34534  Of course it will be recognized even if it is embedded in other expressions,
34535  e.g.:
34536 \end_layout
34537
34538 \begin_layout Verse
34539
34540 \family typewriter
34541 xyz = gint + ((gint >> 15) & 1);
34542 \end_layout
34543
34544 \begin_layout Standard
34545 will still be recognized.
34546 \end_layout
34547
34548 \begin_layout Subsection
34549 Higher Order Byte
34550 \begin_inset LatexCommand \index{Higher Order Byte}
34551
34552 \end_inset
34553
34554  / Higher Order Word
34555 \begin_inset LatexCommand \index{Higher Order Word}
34556
34557 \end_inset
34558
34559
34560 \end_layout
34561
34562 \begin_layout Standard
34563 It is also frequently required to obtain a higher order byte or word of
34564  a larger integral type (long, int or short types).
34565  SDCC recognizes the following expressions to yield the higher order byte
34566  or word and generates optimized code for it, e.g.:
34567 \end_layout
34568
34569 \begin_layout Verse
34570
34571 \family typewriter
34572 unsigned int gint; 
34573 \newline
34574 unsigned long int glong; 
34575 \newline
34576
34577 \newline
34578 foo () { 
34579 \newline
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 unsigned char hob1,
34583  hob2; 
34584 \newline
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 unsigned int how1, how2; 
34588 \newline
34589 \InsetSpace ~
34590 \InsetSpace ~
34591 ...
34592  
34593 \newline
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 hob1 = (gint >> 8) & 0xFF; 
34597 \newline
34598 \InsetSpace ~
34599 \InsetSpace ~
34600 hob2 = glong >> 24; 
34601 \newline
34602 \InsetSpace ~
34603 \InsetSpace ~
34604 how1 = (glong >> 16) & 0xFFFF;
34605  
34606 \newline
34607 \InsetSpace ~
34608 \InsetSpace ~
34609 how2 = glong >> 8; 
34610 \newline
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 ..
34614  
34615 \newline
34616 }
34617 \end_layout
34618
34619 \begin_layout Standard
34620 will generate the following code:
34621 \end_layout
34622
34623 \begin_layout Verse
34624
34625 \family typewriter
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 \InsetSpace ~
34630 \InsetSpace ~
34631 \InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651  91 ;\InsetSpace ~
34652  hob.c 15 
34653 \newline
34654 0037 85*01*06\InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657 \InsetSpace ~
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 \InsetSpace ~
34661 \InsetSpace ~
34662 \InsetSpace ~
34663 \InsetSpace ~
34664 \InsetSpace ~
34665 \InsetSpace ~
34666  92\InsetSpace ~
34667 \InsetSpace ~
34668 \InsetSpace ~
34669 \InsetSpace ~
34670 \InsetSpace ~
34671 \InsetSpace ~
34672 \InsetSpace ~
34673 \InsetSpace ~
34674  mov\InsetSpace ~
34675 \InsetSpace ~
34676  _foo_hob1_1_1,(_gint + 1) 
34677 \newline
34678 \InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686 \InsetSpace ~
34687 \InsetSpace ~
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  93 ;\InsetSpace ~
34704  hob.c
34705  16 
34706 \newline
34707 003A 85*05*07\InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713 \InsetSpace ~
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 \InsetSpace ~
34719  94\InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727  mov\InsetSpace ~
34728 \InsetSpace ~
34729  _foo_hob2_1_1,(_glong + 3) 
34730 \newline
34731 \InsetSpace ~
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739 \InsetSpace ~
34740 \InsetSpace ~
34741 \InsetSpace ~
34742 \InsetSpace ~
34743 \InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756  95 ;\InsetSpace ~
34757  hob.c 17 
34758 \newline
34759 003D 85*04*08\InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766 \InsetSpace ~
34767 \InsetSpace ~
34768 \InsetSpace ~
34769 \InsetSpace ~
34770 \InsetSpace ~
34771
34772  96\InsetSpace ~
34773 \InsetSpace ~
34774 \InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779 \InsetSpace ~
34780  mov\InsetSpace ~
34781 \InsetSpace ~
34782  _foo_how1_1_1,(_glong + 2) 
34783 \newline
34784 0040 85*05*09\InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788 \InsetSpace ~
34789 \InsetSpace ~
34790 \InsetSpace ~
34791 \InsetSpace ~
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796  97\InsetSpace ~
34797 \InsetSpace ~
34798 \InsetSpace ~
34799 \InsetSpace ~
34800 \InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803 \InsetSpace ~
34804  mov\InsetSpace ~
34805 \InsetSpace ~
34806  (_foo_how1_1_1 +
34807  1),(_glong + 3) 
34808 \newline
34809 0043 85*03*0A\InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 \InsetSpace ~
34821  98\InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828 \InsetSpace ~
34829  mov\InsetSpace ~
34830 \InsetSpace ~
34831  _foo_how2_1_1,(_glong + 1) 
34832 \newline
34833 0046 85*04*0B\InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 \InsetSpace ~
34845
34846  99\InsetSpace ~
34847 \InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 \InsetSpace ~
34852 \InsetSpace ~
34853 \InsetSpace ~
34854  mov\InsetSpace ~
34855 \InsetSpace ~
34856  (_foo_how2_1_1 + 1),(_glong + 2) 
34857 \end_layout
34858
34859 \begin_layout Standard
34860 Again, variations of these cases may 
34861 \emph on
34862 not
34863 \emph default
34864  be recognized.
34865  They are standard C expressions, so I heartily recommend these be the only
34866  way to get the higher order byte/word, (it is portable).
34867  Of course it will be recognized even if it is embedded in other expressions,
34868  e.g.:
34869 \end_layout
34870
34871 \begin_layout Verse
34872
34873 \family typewriter
34874 xyz = gint + ((gint >> 8) & 0xFF);
34875 \end_layout
34876
34877 \begin_layout Standard
34878 will still be recognized.
34879 \end_layout
34880
34881 \begin_layout Subsection
34882 Peephole Optimizer
34883 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34884
34885 \end_inset
34886
34887
34888 \begin_inset LatexCommand \index{Peephole optimizer}
34889
34890 \end_inset
34891
34892
34893 \end_layout
34894
34895 \begin_layout Standard
34896 The compiler uses a rule based, pattern matching and re-writing mechanism
34897  for peep-hole optimization.
34898  It is inspired by 
34899 \emph on
34900 copt
34901 \emph default
34902  a peep-hole optimizer by Christopher W.
34903  Fraser (cwfraser\InsetSpace ~
34904 @\InsetSpace ~
34905 microsoft.com).
34906  A default set of rules are compiled into the compiler, additional rules
34907  may be added with the 
34908 \emph on
34909 -
34910 \begin_inset ERT
34911 status collapsed
34912
34913 \begin_layout Standard
34914
34915
34916 \backslash
34917 /
34918 \end_layout
34919
34920 \end_inset
34921
34922 -peep-file
34923 \begin_inset LatexCommand \index{-\/-peep-file}
34924
34925 \end_inset
34926
34927  <filename>
34928 \emph default
34929  option.
34930  The rule language is best illustrated with examples.
34931 \end_layout
34932
34933 \begin_layout Verse
34934
34935 \family typewriter
34936 replace { 
34937 \newline
34938 \InsetSpace ~
34939 \InsetSpace ~
34940 mov %1,a 
34941 \newline
34942 \InsetSpace ~
34943 \InsetSpace ~
34944 mov a,%1
34945 \newline
34946 } by {
34947 \newline
34948 \InsetSpace ~
34949 \InsetSpace ~
34950 mov %1,a
34951 \newline
34952 }
34953 \end_layout
34954
34955 \begin_layout Standard
34956 The above rule will change the following assembly
34957 \begin_inset LatexCommand \index{Assembler routines}
34958
34959 \end_inset
34960
34961  sequence:
34962 \end_layout
34963
34964 \begin_layout Verse
34965
34966 \family typewriter
34967 mov r1,a 
34968 \newline
34969 mov a,r1
34970 \end_layout
34971
34972 \begin_layout Standard
34973 to
34974 \end_layout
34975
34976 \begin_layout Verse
34977
34978 \family typewriter
34979 mov r1,a
34980 \end_layout
34981
34982 \begin_layout Standard
34983 Note: All occurrences of a 
34984 \emph on
34985 %n
34986 \emph default
34987  (pattern variable) must denote the same string.
34988  With the above rule, the assembly sequence:
34989 \end_layout
34990
34991 \begin_layout Verse
34992
34993 \family typewriter
34994 mov r1,a 
34995 \newline
34996 mov a,r2
34997 \end_layout
34998
34999 \begin_layout Standard
35000 will remain unmodified.
35001 \newline
35002
35003 \newline
35004 Other special case optimizations may be added by the
35005  user (via 
35006 \emph on
35007 -
35008 \begin_inset ERT
35009 status collapsed
35010
35011 \begin_layout Standard
35012
35013
35014 \backslash
35015 /
35016 \end_layout
35017
35018 \end_inset
35019
35020 -peep-file option
35021 \emph default
35022 ).
35023  E.g.
35024  some variants of the 8051 MCU
35025 \begin_inset LatexCommand \index{MCS51 variants}
35026
35027 \end_inset
35028
35029  allow only 
35030 \family typewriter
35031 ajmp
35032 \family default
35033  and 
35034 \family typewriter
35035 acall
35036 \family default
35037 .
35038  The following two rules will change all 
35039 \family typewriter
35040 ljmp
35041 \family default
35042  and 
35043 \family typewriter
35044 lcall
35045 \family default
35046  to 
35047 \family typewriter
35048 ajmp
35049 \family default
35050  and 
35051 \family typewriter
35052 acall
35053 \end_layout
35054
35055 \begin_layout Verse
35056
35057 \family typewriter
35058 replace { lcall %1 } by { acall %1 } 
35059 \newline
35060 replace { ljmp %1 } by { ajmp %1 }
35061 \end_layout
35062
35063 \begin_layout Standard
35064 The 
35065 \emph on
35066 inline-assembler code
35067 \emph default
35068  is also passed through the peep hole optimizer, thus the peephole optimizer
35069  can also be used as an assembly level macro expander.
35070  The rules themselves are MCU dependent whereas the rule language infra-structur
35071 e is MCU independent.
35072  Peephole optimization rules for other MCU can be easily programmed using
35073  the rule language.
35074 \newline
35075
35076 \newline
35077 The syntax for a rule is as follows:
35078 \end_layout
35079
35080 \begin_layout Verse
35081
35082 \family typewriter
35083 rule := replace [ restart ] '{' <assembly sequence> '
35084 \backslash
35085 n' 
35086 \newline
35087 \InsetSpace ~
35088  \InsetSpace ~
35089  \InsetSpace ~
35090  \InsetSpace ~
35091  \InsetSpace ~
35092  \InsetSpace ~
35093  \InsetSpace ~
35094  \InsetSpace ~
35095  \InsetSpace ~
35096  \InsetSpace ~
35097  \InsetSpace ~
35098  \InsetSpace ~
35099  \InsetSpace ~
35100  \InsetSpace ~
35101  '}' by '{' '
35102 \backslash
35103 n' 
35104 \newline
35105 \InsetSpace ~
35106  \InsetSpace ~
35107  \InsetSpace ~
35108  \InsetSpace ~
35109  \InsetSpace ~
35110  \InsetSpace ~
35111  \InsetSpace ~
35112  \InsetSpace ~
35113  \InsetSpace ~
35114  \InsetSpace ~
35115  \InsetSpace ~
35116  \InsetSpace ~
35117  \InsetSpace ~
35118  \InsetSpace ~
35119  \InsetSpace ~
35120  \InsetSpace ~
35121  <assembly sequence> '
35122 \backslash
35123 n' 
35124 \newline
35125 \InsetSpace ~
35126  \InsetSpace ~
35127  \InsetSpace ~
35128  \InsetSpace ~
35129  \InsetSpace ~
35130  \InsetSpace ~
35131  \InsetSpace ~
35132  \InsetSpace ~
35133  \InsetSpace ~
35134  \InsetSpace ~
35135  \InsetSpace ~
35136  \InsetSpace ~
35137  \InsetSpace ~
35138  \InsetSpace ~
35139  '}' [if <functionName> ] '
35140 \backslash
35141 n' 
35142 \end_layout
35143
35144 \begin_layout Standard
35145 <assembly sequence> := assembly instruction (each instruction including
35146  labels must be on a separate line).
35147 \newline
35148
35149 \newline
35150 The optimizer will apply to the rules
35151  one by one from the top in the sequence of their appearance, it will terminate
35152  when all rules are exhausted.
35153  If the 'restart' option is specified, then the optimizer will start matching
35154  the rules again from the top, this option for a rule is expensive (performance)
35155 , it is intended to be used in situations where a transformation will trigger
35156  the same rule again.
35157  An example of this (not a good one, it has side effects) is the following
35158  rule:
35159 \end_layout
35160
35161 \begin_layout Verse
35162
35163 \family typewriter
35164 replace restart { 
35165 \newline
35166 \InsetSpace ~
35167 \InsetSpace ~
35168 pop %1 
35169 \newline
35170 \InsetSpace ~
35171 \InsetSpace ~
35172 push %1 } by { 
35173 \newline
35174 \InsetSpace ~
35175 \InsetSpace ~
35176 ; nop 
35177 \newline
35178 }
35179 \end_layout
35180
35181 \begin_layout Standard
35182 Note that the replace pattern cannot be a blank, but can be a comment line.
35183  Without the 'restart' option only the innermost 'pop' 'push' pair would
35184  be eliminated, i.e.:
35185 \end_layout
35186
35187 \begin_layout Verse
35188
35189 \family typewriter
35190 pop ar1 
35191 \newline
35192 pop ar2 
35193 \newline
35194 push ar2 
35195 \newline
35196 push ar1
35197 \end_layout
35198
35199 \begin_layout Standard
35200 would result in:
35201 \end_layout
35202
35203 \begin_layout Verse
35204
35205 \family typewriter
35206 pop ar1 
35207 \newline
35208 ; nop 
35209 \newline
35210 push ar1
35211 \end_layout
35212
35213 \begin_layout Standard
35214
35215 \emph on
35216 with
35217 \emph default
35218  the restart option the rule will be applied again to the resulting code
35219  and then all the pop-push pairs will be eliminated to yield:
35220 \end_layout
35221
35222 \begin_layout Verse
35223
35224 \family typewriter
35225 ; nop 
35226 \newline
35227 ; nop
35228 \end_layout
35229
35230 \begin_layout Standard
35231 A conditional function can be attached to a rule.
35232  Attaching rules are somewhat more involved, let me illustrate this with
35233  an example.
35234 \end_layout
35235
35236 \begin_layout Verse
35237
35238 \family typewriter
35239 replace { 
35240 \newline
35241 \InsetSpace ~
35242  \InsetSpace ~
35243  \InsetSpace ~
35244 ljmp %5 
35245 \newline
35246 %2:
35247 \newline
35248 } by { 
35249 \newline
35250 \InsetSpace ~
35251  \InsetSpace ~
35252  \InsetSpace ~
35253 sjmp %5 
35254 \newline
35255 %2:
35256 \newline
35257 } if labelInRange
35258 \end_layout
35259
35260 \begin_layout Standard
35261 The optimizer does a look-up of a function name table defined in function
35262  
35263 \emph on
35264 callFuncByName
35265 \emph default
35266  in the source file SDCCpeeph.c, with the name 
35267 \emph on
35268 labelInRange
35269 \emph default
35270 .
35271  If it finds a corresponding entry the function is called.
35272  Note there can be no parameters specified for these functions, in this
35273  case the use of 
35274 \emph on
35275 %5
35276 \emph default
35277  is crucial, since the function 
35278 \emph on
35279 labelInRange
35280 \emph default
35281  expects to find the label in that particular variable (the hash table containin
35282 g the variable bindings is passed as a parameter).
35283  If you want to code more such functions, take a close look at the function
35284  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35285  Currently implemented are 
35286 \emph on
35287 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35288  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35289 \emph default
35290 and
35291 \emph on
35292  notVolatile
35293 \emph default
35294 .
35295 \end_layout
35296
35297 \begin_layout Standard
35298 I know this whole thing is a little kludgey, but maybe some day we will
35299  have some better means.
35300  If you are looking at this file, you will see the default rules that are
35301  compiled into the compiler, you can add your own rules in the default set
35302  there if you get tired of specifying the -
35303 \begin_inset ERT
35304 status collapsed
35305
35306 \begin_layout Standard
35307
35308
35309 \backslash
35310 /
35311 \end_layout
35312
35313 \end_inset
35314
35315 -peep-file option.
35316 \end_layout
35317
35318 \begin_layout Section
35319 ANSI-Compliance
35320 \begin_inset LatexCommand \index{ANSI-compliance}
35321
35322 \end_inset
35323
35324
35325 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35326
35327 \end_inset
35328
35329
35330 \end_layout
35331
35332 \begin_layout Standard
35333 The latest publically available version of the standard 
35334 \emph on
35335 ISO/IEC 9899 - Programming languages - C
35336 \emph default
35337  should be available at: 
35338 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35339
35340 \end_inset
35341
35342 .
35343 \newline
35344
35345 \end_layout
35346
35347 \begin_layout Standard
35348 Deviations from the compliance:
35349 \end_layout
35350
35351 \begin_layout Itemize
35352 functions are not reentrant
35353 \begin_inset LatexCommand \index{reentrant}
35354
35355 \end_inset
35356
35357  unless explicitly declared as such or the 
35358 \series bold
35359 -
35360 \begin_inset ERT
35361 status collapsed
35362
35363 \begin_layout Standard
35364
35365
35366 \backslash
35367 /
35368 \end_layout
35369
35370 \end_inset
35371
35372 -stack-auto
35373 \begin_inset LatexCommand \index{-\/-stack-auto}
35374
35375 \end_inset
35376
35377
35378 \series default
35379  command line option is specified.
35380 \end_layout
35381
35382 \begin_layout Itemize
35383 structures
35384 \begin_inset LatexCommand \index{struct}
35385
35386 \end_inset
35387
35388  and unions
35389 \begin_inset LatexCommand \index{union}
35390
35391 \end_inset
35392
35393  cannot be assigned values directly, cannot be passed as function parameters
35394  or assigned to each other and cannot be a return value
35395 \begin_inset LatexCommand \index{return value}
35396
35397 \end_inset
35398
35399  from a function, e.g.:
35400 \end_layout
35401
35402 \begin_deeper
35403 \begin_layout Verse
35404
35405 \family typewriter
35406 struct s { ...
35407  }; 
35408 \newline
35409 struct s s1, s2; 
35410 \newline
35411 foo() 
35412 \newline
35413
35414 \newline
35415 \InsetSpace ~
35416 \InsetSpace ~
35417 \InsetSpace ~
35418 \InsetSpace ~
35419 ...
35420  
35421 \newline
35422 \InsetSpace ~
35423 \InsetSpace ~
35424 \InsetSpace ~
35425 \InsetSpace ~
35426 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35427 \newline
35428 \InsetSpace ~
35429 \InsetSpace ~
35430 \InsetSpace ~
35431 \InsetSpace ~
35432 ...
35433  
35434 \newline
35435 }
35436 \newline
35437
35438 \series bold
35439 struct
35440 \series default
35441  s foo1 (
35442 \series bold
35443 struct
35444 \series default
35445  s parms) /* invalid in SDCC although allowed in ANSI */
35446 \newline
35447
35448 \newline
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 struct s rets;
35454  
35455 \newline
35456 \InsetSpace ~
35457 \InsetSpace ~
35458 \InsetSpace ~
35459 \InsetSpace ~
35460 ...
35461  
35462 \newline
35463 \InsetSpace ~
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 return rets; /* is invalid in SDCC although allowed in ANSI */ 
35468 \newline
35469 }
35470 \end_layout
35471
35472 \end_deeper
35473 \begin_layout Itemize
35474 initialization of structure arrays must be fully braced.
35475 \end_layout
35476
35477 \begin_deeper
35478 \begin_layout Verse
35479
35480 \family typewriter
35481 struct s { char x } a[] = {1, 2};\InsetSpace ~
35482 \InsetSpace ~
35483 \InsetSpace ~
35484 \InsetSpace ~
35485 \InsetSpace ~
35486 /* invalid in SDCC */
35487 \newline
35488 struct s { char x
35489  } a[] = {{1}, {2}}; /* OK */
35490 \end_layout
35491
35492 \end_deeper
35493 \begin_layout Itemize
35494 'long long
35495 \begin_inset LatexCommand \index{long long (not supported)}
35496
35497 \end_inset
35498
35499 ' (64 bit integers
35500 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35501
35502 \end_inset
35503
35504 ) not supported.
35505 \end_layout
35506
35507 \begin_layout Itemize
35508 'double
35509 \begin_inset LatexCommand \index{double (not supported)}
35510
35511 \end_inset
35512
35513 ' precision floating point 
35514 \begin_inset LatexCommand \index{Floating point support}
35515
35516 \end_inset
35517
35518 not supported.
35519 \end_layout
35520
35521 \begin_layout Itemize
35522 Old K&R style
35523 \begin_inset LatexCommand \index{K\&R style}
35524
35525 \end_inset
35526
35527  function declarations are NOT allowed.
35528 \end_layout
35529
35530 \begin_deeper
35531 \begin_layout Verse
35532
35533 \family typewriter
35534 foo(i,j) /* this old style of function declarations */ 
35535 \newline
35536 int i,j; /* are valid
35537  in ANSI but not valid in SDCC */ 
35538 \newline
35539
35540 \newline
35541 \InsetSpace ~
35542 \InsetSpace ~
35543 \InsetSpace ~
35544 \InsetSpace ~
35545 ...
35546  
35547 \newline
35548 }
35549 \end_layout
35550
35551 \end_deeper
35552 \begin_layout Itemize
35553 Most enhancements in C99 are not supported, f.e.:
35554 \end_layout
35555
35556 \begin_deeper
35557 \begin_layout Verse
35558
35559 \family typewriter
35560 \series bold
35561 inline
35562 \begin_inset LatexCommand \index{inline (not supported)}
35563
35564 \end_inset
35565
35566
35567 \series default
35568  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35569  in C99.
35570  An empty define 
35571 \emph on
35572 #define inline
35573 \emph default
35574  can be used as a work around */
35575 \newline
35576
35577 \newline
35578 for (
35579 \series bold
35580 int
35581 \series default
35582  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35583 \end_layout
35584
35585 \end_deeper
35586 \begin_layout Itemize
35587 Certain words that are valid identifiers in the standard may be reserved
35588  words in SDCC unless the 
35589 \series bold
35590 -
35591 \begin_inset ERT
35592 status collapsed
35593
35594 \begin_layout Standard
35595
35596
35597 \backslash
35598 /
35599 \end_layout
35600
35601 \end_inset
35602
35603 -std-c89
35604 \begin_inset LatexCommand \index{-\/-std-c89}
35605
35606 \end_inset
35607
35608  or -
35609 \begin_inset ERT
35610 status collapsed
35611
35612 \begin_layout Standard
35613
35614
35615 \backslash
35616 /
35617 \end_layout
35618
35619 \end_inset
35620
35621 -std-c99
35622 \begin_inset LatexCommand \index{-\/-std-c99}
35623
35624 \end_inset
35625
35626
35627 \series default
35628  command line options are used.
35629  These may include (depending on the selected processor): 'at', 'banked',
35630  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35631 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35632  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35633  '_naked'.
35634  Compliant equivalents of these keywords are always available in a form
35635  that begin with two underscores
35636 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35637
35638 \end_inset
35639
35640 , f.e.
35641  '__data' instead of 'data'.
35642 \end_layout
35643
35644 \begin_layout Section
35645 Cyclomatic Complexity
35646 \begin_inset LatexCommand \index{Cyclomatic complexity}
35647
35648 \end_inset
35649
35650
35651 \end_layout
35652
35653 \begin_layout Standard
35654 Cyclomatic complexity of a function is defined as the number of independent
35655  paths the program can take during execution of the function.
35656  This is an important number since it defines the number test cases you
35657  have to generate to validate the function.
35658  The accepted industry standard for complexity number is 10, if the cyclomatic
35659  complexity reported by SDCC exceeds 10 you should think about simplification
35660  of the function logic.
35661  Note that the complexity level is not related to the number of lines of
35662  code in a function.
35663  Large functions can have low complexity, and small functions can have large
35664  complexity levels.
35665  
35666 \newline
35667
35668 \newline
35669 SDCC uses the following formula to compute the complexity:
35670 \newline
35671
35672 \end_layout
35673
35674 \begin_layout Standard
35675 complexity = (number of edges in control flow graph) - (number of nodes
35676  in control flow graph) + 2;
35677 \newline
35678
35679 \newline
35680 Having said that the industry standard is 10,
35681  you should be aware that in some cases it be may unavoidable to have a
35682  complexity level of less than 10.
35683  For example if you have switch statement with more than 10 case labels,
35684  each case label adds one to the complexity level.
35685  The complexity level is by no means an absolute measure of the algorithmic
35686  complexity of the function, it does however provide a good starting point
35687  for which functions you might look at for further optimization.
35688 \end_layout
35689
35690 \begin_layout Section
35691 Retargetting for other Processors
35692 \end_layout
35693
35694 \begin_layout Standard
35695 The issues for retargetting the compiler are far too numerous to be covered
35696  by this document.
35697  What follows is a brief description of each of the seven phases of the
35698  compiler and its MCU dependency.
35699 \end_layout
35700
35701 \begin_layout Itemize
35702 Parsing the source and building the annotated parse tree.
35703  This phase is largely MCU independent (except for the language extensions).
35704  Syntax & semantic checks are also done in this phase, along with some initial
35705  optimizations like back patching labels and the pattern matching optimizations
35706  like bit-rotation etc.
35707 \end_layout
35708
35709 \begin_layout Itemize
35710 The second phase involves generating an intermediate code which can be easy
35711  manipulated during the later phases.
35712  This phase is entirely MCU independent.
35713  The intermediate code generation assumes the target machine has unlimited
35714  number of registers, and designates them with the name iTemp.
35715  The compiler can be made to dump a human readable form of the code generated
35716  by using the -
35717 \begin_inset ERT
35718 status collapsed
35719
35720 \begin_layout Standard
35721
35722
35723 \backslash
35724 /
35725 \end_layout
35726
35727 \end_inset
35728
35729 -dumpraw option.
35730 \end_layout
35731
35732 \begin_layout Itemize
35733 This phase does the bulk of the standard optimizations and is also MCU independe
35734 nt.
35735  This phase can be broken down into several sub-phases:
35736 \newline
35737
35738 \newline
35739 Break down intermediate
35740  code (iCode) into basic blocks.
35741 \newline
35742 Do control flow & data flow analysis on the
35743  basic blocks.
35744 \newline
35745 Do local common subexpression elimination, then global subexpressio
35746 n elimination
35747 \newline
35748 Dead code elimination
35749 \newline
35750 Loop optimizations
35751 \newline
35752 If loop optimizations
35753  caused any changes then do 'global subexpression elimination' and 'dead
35754  code elimination' again.
35755 \end_layout
35756
35757 \begin_layout Itemize
35758 This phase determines the live-ranges; by live range I mean those iTemp
35759  variables defined by the compiler that still survive after all the optimization
35760 s.
35761  Live range analysis
35762 \begin_inset LatexCommand \index{Live range analysis}
35763
35764 \end_inset
35765
35766  is essential for register allocation, since these computation determines
35767  which of these iTemps will be assigned to registers, and for how long.
35768 \end_layout
35769
35770 \begin_layout Itemize
35771 Phase five is register allocation.
35772  There are two parts to this process.
35773 \newline
35774
35775 \newline
35776 The first part I call 'register packing'
35777  (for lack of a better term).
35778  In this case several MCU specific expression folding is done to reduce
35779  register pressure.
35780 \newline
35781
35782 \newline
35783 The second part is more MCU independent and deals with
35784  allocating registers to the remaining live ranges.
35785  A lot of MCU specific code does creep into this phase because of the limited
35786  number of index registers available in the 8051.
35787 \end_layout
35788
35789 \begin_layout Itemize
35790 The Code generation phase is (unhappily), entirely MCU dependent and very
35791  little (if any at all) of this code can be reused for other MCU.
35792  However the scheme for allocating a homogenized assembler operand for each
35793  iCode operand may be reused.
35794 \end_layout
35795
35796 \begin_layout Itemize
35797 As mentioned in the optimization section the peep-hole optimizer is rule
35798  based system, which can reprogrammed for other MCUs.
35799 \end_layout
35800
35801 \begin_layout Standard
35802 More information is available in a wiki
35803 \begin_inset LatexCommand \index{wiki}
35804
35805 \end_inset
35806
35807  (preliminary link 
35808 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35809
35810 \end_inset
35811
35812 ) and in the thread 
35813 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35814
35815 \end_inset
35816
35817  .
35818 \end_layout
35819
35820 \begin_layout Chapter
35821 Compiler internals
35822 \begin_inset LatexCommand \index{Compiler internals}
35823
35824 \end_inset
35825
35826
35827 \end_layout
35828
35829 \begin_layout Section
35830 The anatomy of the compiler
35831 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35832
35833 \end_inset
35834
35835
35836 \end_layout
35837
35838 \begin_layout Standard
35839
35840 \shape italic
35841 This is an excerpt from an article published in Circuit Cellar Magazine
35842  in 
35843 \series bold
35844 August 2000
35845 \series default
35846 .
35847  It's a little outdated (the compiler is much more efficient now and user/develo
35848 per friendly), but pretty well exposes the guts of it all.
35849 \shape default
35850
35851 \newline
35852
35853 \newline
35854 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35855  It is fairly easy to retarget for other 8-bit MCU.
35856  Here we take a look at some of the internals of the compiler.
35857  
35858 \end_layout
35859
35860 \begin_layout Paragraph*
35861 Parsing
35862 \begin_inset LatexCommand \index{Parsing}
35863
35864 \end_inset
35865
35866  
35867 \end_layout
35868
35869 \begin_layout Standard
35870 Parsing the input source file and creating an AST (Annotated Syntax Tree
35871 \begin_inset LatexCommand \index{Annotated syntax tree}
35872
35873 \end_inset
35874
35875 ).
35876  This phase also involves propagating types (annotating each node of the
35877  parse tree with type information) and semantic analysis.
35878  There are some MCU specific parsing rules.
35879  For example the storage classes, the extended storage classes are MCU specific
35880  while there may be a xdata storage class for 8051 there is no such storage
35881  class for z80 or Atmel AVR.
35882  SDCC allows MCU specific storage class extensions, i.e.
35883  xdata will be treated as a storage class specifier when parsing 8051 C
35884  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35885  C code.
35886 \end_layout
35887
35888 \begin_layout Paragraph*
35889 Generating iCode
35890 \begin_inset LatexCommand \index{iCode}
35891
35892 \end_inset
35893
35894
35895 \end_layout
35896
35897 \begin_layout Standard
35898 Intermediate code generation.
35899  In this phase the AST is broken down into three-operand form (iCode).
35900  These three operand forms are represented as doubly linked lists.
35901  ICode is the term given to the intermediate form generated by the compiler.
35902  ICode example section shows some examples of iCode generated for some simple
35903  C source functions.
35904 \end_layout
35905
35906 \begin_layout Paragraph*
35907 Optimizations
35908 \begin_inset LatexCommand \index{Optimizations}
35909
35910 \end_inset
35911
35912 .
35913 \end_layout
35914
35915 \begin_layout Standard
35916 Bulk of the target independent optimizations is performed in this phase.
35917  The optimizations include constant propagation, common sub-expression eliminati
35918 on, loop invariant code movement, strength reduction of loop induction variables
35919  and dead-code elimination.
35920 \end_layout
35921
35922 \begin_layout Paragraph*
35923 Live range analysis
35924 \begin_inset LatexCommand \index{Live range analysis}
35925
35926 \end_inset
35927
35928
35929 \end_layout
35930
35931 \begin_layout Standard
35932 During intermediate code generation phase, the compiler assumes the target
35933  machine has infinite number of registers and generates a lot of temporary
35934  variables.
35935  The live range computation determines the lifetime of each of these compiler-ge
35936 nerated temporaries.
35937  A picture speaks a thousand words.
35938  ICode example sections show the live range annotations for each of the
35939  operand.
35940  It is important to note here, each iCode is assigned a number in the order
35941  of its execution in the function.
35942  The live ranges are computed in terms of these numbers.
35943  The from number is the number of the iCode which first defines the operand
35944  and the to number signifies the iCode which uses this operand last.
35945 \end_layout
35946
35947 \begin_layout Paragraph*
35948 Register Allocation
35949 \begin_inset LatexCommand \index{Register allocation}
35950
35951 \end_inset
35952
35953
35954 \end_layout
35955
35956 \begin_layout Standard
35957 The register allocation determines the type and number of registers needed
35958  by each operand.
35959  In most MCUs only a few registers can be used for indirect addressing.
35960  In case of 8051 for example the registers R0 & R1 can be used to indirectly
35961  address the internal ram and DPTR to indirectly address the external ram.
35962  The compiler will try to allocate the appropriate register to pointer variables
35963  if it can.
35964  ICode example section shows the operands annotated with the registers assigned
35965  to them.
35966  The compiler will try to keep operands in registers as much as possible;
35967  there are several schemes the compiler uses to do achieve this.
35968  When the compiler runs out of registers the compiler will check to see
35969  if there are any live operands which is not used or defined in the current
35970  basic block being processed, if there are any found then it will push that
35971  operand and use the registers in this block, the operand will then be popped
35972  at the end of the basic block.
35973  
35974 \end_layout
35975
35976 \begin_layout Standard
35977 There are other MCU specific considerations in this phase.
35978  Some MCUs have an accumulator; very short-lived operands could be assigned
35979  to the accumulator instead of a general-purpose register.
35980 \end_layout
35981
35982 \begin_layout Paragraph*
35983 Code generation
35984 \end_layout
35985
35986 \begin_layout Standard
35987 Figure II gives a table of iCode
35988 \begin_inset LatexCommand \index{iCode}
35989
35990 \end_inset
35991
35992  operations supported by the compiler.
35993  The code generation involves translating these operations into corresponding
35994  assembly code for the processor.
35995  This sounds overly simple but that is the essence of code generation.
35996  Some of the iCode operations are generated on a MCU specific manner for
35997  example, the z80 port does not use registers to pass parameters so the
35998  SEND and RECV iCode operations will not be generated, and it also does
35999  not support JUMPTABLES.
36000  
36001 \newline
36002
36003 \end_layout
36004
36005 \begin_layout Standard
36006
36007 \size footnotesize
36008 Figure II 
36009 \begin_inset Tabular
36010 <lyxtabular version="3" rows="39" columns="4">
36011 <features islongtable="true" headBottomDL="true">
36012 <column alignment="block" valignment="top" leftline="true" width="13col%">
36013 <column alignment="left" valignment="top" leftline="true" width="13col%">
36014 <column alignment="block" valignment="top" leftline="true" width="22col%">
36015 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36016 <row topline="true" bottomline="true" endhead="true">
36017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36018 \begin_inset Text
36019
36020 \begin_layout Standard
36021
36022 \series bold
36023 iCode
36024 \series default
36025
36026 \begin_inset LatexCommand \index{iCode}
36027
36028 \end_inset
36029
36030
36031 \end_layout
36032
36033 \end_inset
36034 </cell>
36035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36036 \begin_inset Text
36037
36038 \begin_layout Standard
36039
36040 \series bold
36041 Operands
36042 \end_layout
36043
36044 \end_inset
36045 </cell>
36046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36047 \begin_inset Text
36048
36049 \begin_layout Standard
36050
36051 \series bold
36052 Description
36053 \end_layout
36054
36055 \end_inset
36056 </cell>
36057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36058 \begin_inset Text
36059
36060 \begin_layout Standard
36061
36062 \series bold
36063 C Equivalent
36064 \end_layout
36065
36066 \end_inset
36067 </cell>
36068 </row>
36069 <row topline="true">
36070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36071 \begin_inset Text
36072
36073 \begin_layout Standard
36074
36075 \size footnotesize
36076 '!'
36077 \end_layout
36078
36079 \end_inset
36080 </cell>
36081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36082 \begin_inset Text
36083
36084 \begin_layout Standard
36085
36086 \size footnotesize
36087 IC_LEFT() IC_RESULT()
36088 \end_layout
36089
36090 \end_inset
36091 </cell>
36092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36093 \begin_inset Text
36094
36095 \begin_layout Standard
36096
36097 \size footnotesize
36098 NOT operation 
36099 \end_layout
36100
36101 \end_inset
36102 </cell>
36103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36104 \begin_inset Text
36105
36106 \begin_layout Standard
36107
36108 \size footnotesize
36109 IC_RESULT = ! IC_LEFT;
36110 \end_layout
36111
36112 \end_inset
36113 </cell>
36114 </row>
36115 <row topline="true">
36116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36117 \begin_inset Text
36118
36119 \begin_layout Standard
36120
36121 \size footnotesize
36122 '~'
36123 \end_layout
36124
36125 \end_inset
36126 </cell>
36127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36128 \begin_inset Text
36129
36130 \begin_layout Standard
36131
36132 \size footnotesize
36133 IC_LEFT() IC_RESULT()
36134 \end_layout
36135
36136 \end_inset
36137 </cell>
36138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36139 \begin_inset Text
36140
36141 \begin_layout Standard
36142
36143 \size footnotesize
36144 Bitwise complement of 
36145 \end_layout
36146
36147 \end_inset
36148 </cell>
36149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36150 \begin_inset Text
36151
36152 \begin_layout Standard
36153
36154 \size footnotesize
36155 IC_RESULT = ~IC_LEFT;
36156 \end_layout
36157
36158 \end_inset
36159 </cell>
36160 </row>
36161 <row topline="true">
36162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36163 \begin_inset Text
36164
36165 \begin_layout Standard
36166
36167 \size footnotesize
36168 RRC
36169 \end_layout
36170
36171 \end_inset
36172 </cell>
36173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36174 \begin_inset Text
36175
36176 \begin_layout Standard
36177
36178 \size footnotesize
36179 IC_LEFT() IC_RESULT()
36180 \end_layout
36181
36182 \end_inset
36183 </cell>
36184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36185 \begin_inset Text
36186
36187 \begin_layout Standard
36188
36189 \size footnotesize
36190 Rotate right with carry
36191 \end_layout
36192
36193 \end_inset
36194 </cell>
36195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36196 \begin_inset Text
36197
36198 \begin_layout Standard
36199
36200 \size footnotesize
36201 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36202 \end_layout
36203
36204 \end_inset
36205 </cell>
36206 </row>
36207 <row topline="true">
36208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36209 \begin_inset Text
36210
36211 \begin_layout Standard
36212
36213 \size footnotesize
36214 RLC
36215 \end_layout
36216
36217 \end_inset
36218 </cell>
36219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36220 \begin_inset Text
36221
36222 \begin_layout Standard
36223
36224 \size footnotesize
36225 IC_LEFT() IC_RESULT()
36226 \end_layout
36227
36228 \end_inset
36229 </cell>
36230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36231 \begin_inset Text
36232
36233 \begin_layout Standard
36234
36235 \size footnotesize
36236 Rotate left with carry
36237 \end_layout
36238
36239 \end_inset
36240 </cell>
36241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36242 \begin_inset Text
36243
36244 \begin_layout Standard
36245
36246 \size footnotesize
36247 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36248 \end_layout
36249
36250 \end_inset
36251 </cell>
36252 </row>
36253 <row topline="true">
36254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36255 \begin_inset Text
36256
36257 \begin_layout Standard
36258
36259 \size footnotesize
36260 GETHBIT
36261 \end_layout
36262
36263 \end_inset
36264 </cell>
36265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36266 \begin_inset Text
36267
36268 \begin_layout Standard
36269
36270 \size footnotesize
36271 IC_LEFT() IC_RESULT()
36272 \end_layout
36273
36274 \end_inset
36275 </cell>
36276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36277 \begin_inset Text
36278
36279 \begin_layout Standard
36280
36281 \size footnotesize
36282 Get the highest order bit of IC_LEFT
36283 \end_layout
36284
36285 \end_inset
36286 </cell>
36287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36288 \begin_inset Text
36289
36290 \begin_layout Standard
36291
36292 \size footnotesize
36293 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36294 \end_layout
36295
36296 \end_inset
36297 </cell>
36298 </row>
36299 <row topline="true">
36300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36301 \begin_inset Text
36302
36303 \begin_layout Standard
36304
36305 \size footnotesize
36306 UNARYMINUS
36307 \end_layout
36308
36309 \end_inset
36310 </cell>
36311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36312 \begin_inset Text
36313
36314 \begin_layout Standard
36315
36316 \size footnotesize
36317 IC_LEFT() IC_RESULT()
36318 \end_layout
36319
36320 \end_inset
36321 </cell>
36322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36323 \begin_inset Text
36324
36325 \begin_layout Standard
36326
36327 \size footnotesize
36328 Unary minus
36329 \end_layout
36330
36331 \end_inset
36332 </cell>
36333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36334 \begin_inset Text
36335
36336 \begin_layout Standard
36337
36338 \size footnotesize
36339 IC_RESULT = - IC_LEFT;
36340 \end_layout
36341
36342 \end_inset
36343 </cell>
36344 </row>
36345 <row topline="true">
36346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36347 \begin_inset Text
36348
36349 \begin_layout Standard
36350
36351 \size footnotesize
36352 IPUSH
36353 \end_layout
36354
36355 \end_inset
36356 </cell>
36357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36358 \begin_inset Text
36359
36360 \begin_layout Standard
36361
36362 \size footnotesize
36363 IC_LEFT()
36364 \end_layout
36365
36366 \end_inset
36367 </cell>
36368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36369 \begin_inset Text
36370
36371 \begin_layout Standard
36372
36373 \size footnotesize
36374 Push the operand into stack
36375 \end_layout
36376
36377 \end_inset
36378 </cell>
36379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36380 \begin_inset Text
36381
36382 \begin_layout Standard
36383
36384 \size footnotesize
36385 NONE
36386 \end_layout
36387
36388 \end_inset
36389 </cell>
36390 </row>
36391 <row topline="true">
36392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36393 \begin_inset Text
36394
36395 \begin_layout Standard
36396
36397 \size footnotesize
36398 IPOP
36399 \end_layout
36400
36401 \end_inset
36402 </cell>
36403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36404 \begin_inset Text
36405
36406 \begin_layout Standard
36407
36408 \size footnotesize
36409 IC_LEFT()
36410 \end_layout
36411
36412 \end_inset
36413 </cell>
36414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36415 \begin_inset Text
36416
36417 \begin_layout Standard
36418
36419 \size footnotesize
36420 Pop the operand from the stack 
36421 \end_layout
36422
36423 \end_inset
36424 </cell>
36425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36426 \begin_inset Text
36427
36428 \begin_layout Standard
36429
36430 \size footnotesize
36431 NONE
36432 \end_layout
36433
36434 \end_inset
36435 </cell>
36436 </row>
36437 <row topline="true">
36438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36439 \begin_inset Text
36440
36441 \begin_layout Standard
36442
36443 \size footnotesize
36444 CALL
36445 \end_layout
36446
36447 \end_inset
36448 </cell>
36449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36450 \begin_inset Text
36451
36452 \begin_layout Standard
36453
36454 \size footnotesize
36455 IC_LEFT() IC_RESULT()
36456 \end_layout
36457
36458 \end_inset
36459 </cell>
36460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36461 \begin_inset Text
36462
36463 \begin_layout Standard
36464
36465 \size footnotesize
36466 Call the function represented by IC_LEFT 
36467 \end_layout
36468
36469 \end_inset
36470 </cell>
36471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36472 \begin_inset Text
36473
36474 \begin_layout Standard
36475
36476 \size footnotesize
36477 IC_RESULT = IC_LEFT();
36478 \end_layout
36479
36480 \end_inset
36481 </cell>
36482 </row>
36483 <row topline="true">
36484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36485 \begin_inset Text
36486
36487 \begin_layout Standard
36488
36489 \size footnotesize
36490 PCALL
36491 \end_layout
36492
36493 \end_inset
36494 </cell>
36495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36496 \begin_inset Text
36497
36498 \begin_layout Standard
36499
36500 \size footnotesize
36501 IC_LEFT() IC_RESULT()
36502 \end_layout
36503
36504 \end_inset
36505 </cell>
36506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36507 \begin_inset Text
36508
36509 \begin_layout Standard
36510
36511 \size footnotesize
36512 Call via function pointer
36513 \end_layout
36514
36515 \end_inset
36516 </cell>
36517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36518 \begin_inset Text
36519
36520 \begin_layout Standard
36521
36522 \size footnotesize
36523 IC_RESULT = (*IC_LEFT)();
36524 \end_layout
36525
36526 \end_inset
36527 </cell>
36528 </row>
36529 <row topline="true">
36530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36531 \begin_inset Text
36532
36533 \begin_layout Standard
36534
36535 \size footnotesize
36536 RETURN
36537 \end_layout
36538
36539 \end_inset
36540 </cell>
36541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36542 \begin_inset Text
36543
36544 \begin_layout Standard
36545
36546 \size footnotesize
36547 IC_LEFT()
36548 \end_layout
36549
36550 \end_inset
36551 </cell>
36552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36553 \begin_inset Text
36554
36555 \begin_layout Standard
36556
36557 \size footnotesize
36558 Return the value in operand IC_LEFT 
36559 \end_layout
36560
36561 \end_inset
36562 </cell>
36563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36564 \begin_inset Text
36565
36566 \begin_layout Standard
36567
36568 \size footnotesize
36569 return IC_LEFT;
36570 \end_layout
36571
36572 \end_inset
36573 </cell>
36574 </row>
36575 <row topline="true">
36576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36577 \begin_inset Text
36578
36579 \begin_layout Standard
36580
36581 \size footnotesize
36582 LABEL
36583 \end_layout
36584
36585 \end_inset
36586 </cell>
36587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36588 \begin_inset Text
36589
36590 \begin_layout Standard
36591
36592 \size footnotesize
36593 IC_LABEL() 
36594 \end_layout
36595
36596 \end_inset
36597 </cell>
36598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36599 \begin_inset Text
36600
36601 \begin_layout Standard
36602
36603 \size footnotesize
36604 Label
36605 \end_layout
36606
36607 \end_inset
36608 </cell>
36609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36610 \begin_inset Text
36611
36612 \begin_layout Standard
36613
36614 \size footnotesize
36615 IC_LABEL:
36616 \end_layout
36617
36618 \end_inset
36619 </cell>
36620 </row>
36621 <row topline="true">
36622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36623 \begin_inset Text
36624
36625 \begin_layout Standard
36626
36627 \size footnotesize
36628 GOTO
36629 \end_layout
36630
36631 \end_inset
36632 </cell>
36633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36634 \begin_inset Text
36635
36636 \begin_layout Standard
36637
36638 \size footnotesize
36639 IC_LABEL() 
36640 \end_layout
36641
36642 \end_inset
36643 </cell>
36644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36645 \begin_inset Text
36646
36647 \begin_layout Standard
36648
36649 \size footnotesize
36650 Goto label
36651 \end_layout
36652
36653 \end_inset
36654 </cell>
36655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36656 \begin_inset Text
36657
36658 \begin_layout Standard
36659
36660 \size footnotesize
36661 goto IC_LABEL();
36662 \end_layout
36663
36664 \end_inset
36665 </cell>
36666 </row>
36667 <row topline="true">
36668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36669 \begin_inset Text
36670
36671 \begin_layout Standard
36672
36673 \size footnotesize
36674 '+'
36675 \end_layout
36676
36677 \end_inset
36678 </cell>
36679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36680 \begin_inset Text
36681
36682 \begin_layout Standard
36683
36684 \size footnotesize
36685 IC_LEFT() IC_RIGHT() IC_RESULT()
36686 \end_layout
36687
36688 \end_inset
36689 </cell>
36690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36691 \begin_inset Text
36692
36693 \begin_layout Standard
36694
36695 \size footnotesize
36696 Addition
36697 \end_layout
36698
36699 \end_inset
36700 </cell>
36701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36702 \begin_inset Text
36703
36704 \begin_layout Standard
36705
36706 \size footnotesize
36707 IC_RESULT = IC_LEFT + IC_RIGHT
36708 \end_layout
36709
36710 \end_inset
36711 </cell>
36712 </row>
36713 <row topline="true">
36714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36715 \begin_inset Text
36716
36717 \begin_layout Standard
36718
36719 \size footnotesize
36720 '-'
36721 \end_layout
36722
36723 \end_inset
36724 </cell>
36725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36726 \begin_inset Text
36727
36728 \begin_layout Standard
36729
36730 \size footnotesize
36731 IC_LEFT() IC_RIGHT() IC_RESULT()
36732 \end_layout
36733
36734 \end_inset
36735 </cell>
36736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36737 \begin_inset Text
36738
36739 \begin_layout Standard
36740
36741 \size footnotesize
36742 Subtraction
36743 \end_layout
36744
36745 \end_inset
36746 </cell>
36747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36748 \begin_inset Text
36749
36750 \begin_layout Standard
36751
36752 \size footnotesize
36753 IC_RESULT = IC_LEFT - IC_RIGHT 
36754 \end_layout
36755
36756 \end_inset
36757 </cell>
36758 </row>
36759 <row topline="true">
36760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36761 \begin_inset Text
36762
36763 \begin_layout Standard
36764
36765 \size footnotesize
36766 '*'
36767 \end_layout
36768
36769 \end_inset
36770 </cell>
36771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36772 \begin_inset Text
36773
36774 \begin_layout Standard
36775
36776 \size footnotesize
36777 IC_LEFT() IC_RIGHT() IC_RESULT()
36778 \end_layout
36779
36780 \end_inset
36781 </cell>
36782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36783 \begin_inset Text
36784
36785 \begin_layout Standard
36786
36787 \size footnotesize
36788 Multiplication 
36789 \end_layout
36790
36791 \end_inset
36792 </cell>
36793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36794 \begin_inset Text
36795
36796 \begin_layout Standard
36797
36798 \size footnotesize
36799 IC_RESULT = IC_LEFT * IC_RIGHT;
36800 \end_layout
36801
36802 \end_inset
36803 </cell>
36804 </row>
36805 <row topline="true">
36806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36807 \begin_inset Text
36808
36809 \begin_layout Standard
36810
36811 \size footnotesize
36812 '/'
36813 \end_layout
36814
36815 \end_inset
36816 </cell>
36817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36818 \begin_inset Text
36819
36820 \begin_layout Standard
36821
36822 \size footnotesize
36823 IC_LEFT() IC_RIGHT() IC_RESULT()
36824 \end_layout
36825
36826 \end_inset
36827 </cell>
36828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36829 \begin_inset Text
36830
36831 \begin_layout Standard
36832
36833 \size footnotesize
36834 Division
36835 \end_layout
36836
36837 \end_inset
36838 </cell>
36839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36840 \begin_inset Text
36841
36842 \begin_layout Standard
36843
36844 \size footnotesize
36845 IC_RESULT = IC_LEFT / IC_RIGHT;
36846 \end_layout
36847
36848 \end_inset
36849 </cell>
36850 </row>
36851 <row topline="true">
36852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36853 \begin_inset Text
36854
36855 \begin_layout Standard
36856
36857 \size footnotesize
36858 '%'
36859 \end_layout
36860
36861 \end_inset
36862 </cell>
36863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36864 \begin_inset Text
36865
36866 \begin_layout Standard
36867
36868 \size footnotesize
36869 IC_LEFT() IC_RIGHT() IC_RESULT()
36870 \end_layout
36871
36872 \end_inset
36873 </cell>
36874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36875 \begin_inset Text
36876
36877 \begin_layout Standard
36878
36879 \size footnotesize
36880 Modulus
36881 \end_layout
36882
36883 \end_inset
36884 </cell>
36885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36886 \begin_inset Text
36887
36888 \begin_layout Standard
36889
36890 \size footnotesize
36891 IC_RESULT = IC_LEFT % IC_RIGHT;
36892 \end_layout
36893
36894 \end_inset
36895 </cell>
36896 </row>
36897 <row topline="true">
36898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36899 \begin_inset Text
36900
36901 \begin_layout Standard
36902
36903 \size footnotesize
36904 '<'
36905 \end_layout
36906
36907 \end_inset
36908 </cell>
36909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36910 \begin_inset Text
36911
36912 \begin_layout Standard
36913
36914 \size footnotesize
36915 IC_LEFT() IC_RIGHT() IC_RESULT()
36916 \end_layout
36917
36918 \end_inset
36919 </cell>
36920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36921 \begin_inset Text
36922
36923 \begin_layout Standard
36924
36925 \size footnotesize
36926 Less than
36927 \end_layout
36928
36929 \end_inset
36930 </cell>
36931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36932 \begin_inset Text
36933
36934 \begin_layout Standard
36935
36936 \size footnotesize
36937 IC_RESULT = IC_LEFT < IC_RIGHT;
36938 \end_layout
36939
36940 \end_inset
36941 </cell>
36942 </row>
36943 <row topline="true">
36944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36945 \begin_inset Text
36946
36947 \begin_layout Standard
36948
36949 \size footnotesize
36950 '>'
36951 \end_layout
36952
36953 \end_inset
36954 </cell>
36955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36956 \begin_inset Text
36957
36958 \begin_layout Standard
36959
36960 \size footnotesize
36961 IC_LEFT() IC_RIGHT() IC_RESULT()
36962 \end_layout
36963
36964 \end_inset
36965 </cell>
36966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36967 \begin_inset Text
36968
36969 \begin_layout Standard
36970
36971 \size footnotesize
36972 Greater than 
36973 \end_layout
36974
36975 \end_inset
36976 </cell>
36977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36978 \begin_inset Text
36979
36980 \begin_layout Standard
36981
36982 \size footnotesize
36983 IC_RESULT = IC_LEFT > IC_RIGHT;
36984 \end_layout
36985
36986 \end_inset
36987 </cell>
36988 </row>
36989 <row topline="true">
36990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36991 \begin_inset Text
36992
36993 \begin_layout Standard
36994
36995 \size footnotesize
36996 EQ_OP
36997 \end_layout
36998
36999 \end_inset
37000 </cell>
37001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37002 \begin_inset Text
37003
37004 \begin_layout Standard
37005
37006 \size footnotesize
37007 IC_LEFT() IC_RIGHT() IC_RESULT()
37008 \end_layout
37009
37010 \end_inset
37011 </cell>
37012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37013 \begin_inset Text
37014
37015 \begin_layout Standard
37016
37017 \size footnotesize
37018 Equal to 
37019 \end_layout
37020
37021 \end_inset
37022 </cell>
37023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37024 \begin_inset Text
37025
37026 \begin_layout Standard
37027
37028 \size footnotesize
37029 IC_RESULT = IC_LEFT == IC_RIGHT;
37030 \end_layout
37031
37032 \end_inset
37033 </cell>
37034 </row>
37035 <row topline="true">
37036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37037 \begin_inset Text
37038
37039 \begin_layout Standard
37040
37041 \size footnotesize
37042 AND_OP
37043 \end_layout
37044
37045 \end_inset
37046 </cell>
37047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37048 \begin_inset Text
37049
37050 \begin_layout Standard
37051
37052 \size footnotesize
37053 IC_LEFT() IC_RIGHT() IC_RESULT() 
37054 \end_layout
37055
37056 \end_inset
37057 </cell>
37058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37059 \begin_inset Text
37060
37061 \begin_layout Standard
37062
37063 \size footnotesize
37064 Logical and operation
37065 \end_layout
37066
37067 \end_inset
37068 </cell>
37069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37070 \begin_inset Text
37071
37072 \begin_layout Standard
37073
37074 \size footnotesize
37075 IC_RESULT = IC_LEFT && IC_RIGHT; 
37076 \end_layout
37077
37078 \end_inset
37079 </cell>
37080 </row>
37081 <row topline="true">
37082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37083 \begin_inset Text
37084
37085 \begin_layout Standard
37086
37087 \size footnotesize
37088 OR_OP
37089 \end_layout
37090
37091 \end_inset
37092 </cell>
37093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37094 \begin_inset Text
37095
37096 \begin_layout Standard
37097
37098 \size footnotesize
37099 IC_LEFT() IC_RIGHT() IC_RESULT() 
37100 \end_layout
37101
37102 \end_inset
37103 </cell>
37104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37105 \begin_inset Text
37106
37107 \begin_layout Standard
37108
37109 \size footnotesize
37110 Logical or operation 
37111 \end_layout
37112
37113 \end_inset
37114 </cell>
37115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37116 \begin_inset Text
37117
37118 \begin_layout Standard
37119
37120 \size footnotesize
37121 IC_RESULT = IC_LEFT || IC_RIGHT; 
37122 \end_layout
37123
37124 \end_inset
37125 </cell>
37126 </row>
37127 <row topline="true">
37128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37129 \begin_inset Text
37130
37131 \begin_layout Standard
37132
37133 \size footnotesize
37134 '^'
37135 \end_layout
37136
37137 \end_inset
37138 </cell>
37139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37140 \begin_inset Text
37141
37142 \begin_layout Standard
37143
37144 \size footnotesize
37145 IC_LEFT() IC_RIGHT() IC_RESULT() 
37146 \end_layout
37147
37148 \end_inset
37149 </cell>
37150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37151 \begin_inset Text
37152
37153 \begin_layout Standard
37154
37155 \size footnotesize
37156 Exclusive OR
37157 \end_layout
37158
37159 \end_inset
37160 </cell>
37161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37162 \begin_inset Text
37163
37164 \begin_layout Standard
37165
37166 \size footnotesize
37167 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37168 \end_layout
37169
37170 \end_inset
37171 </cell>
37172 </row>
37173 <row topline="true">
37174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37175 \begin_inset Text
37176
37177 \begin_layout Standard
37178
37179 \size footnotesize
37180 '|'
37181 \end_layout
37182
37183 \end_inset
37184 </cell>
37185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37186 \begin_inset Text
37187
37188 \begin_layout Standard
37189
37190 \size footnotesize
37191 IC_LEFT() IC_RIGHT() IC_RESULT() 
37192 \end_layout
37193
37194 \end_inset
37195 </cell>
37196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37197 \begin_inset Text
37198
37199 \begin_layout Standard
37200
37201 \size footnotesize
37202 Bitwise OR 
37203 \end_layout
37204
37205 \end_inset
37206 </cell>
37207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37208 \begin_inset Text
37209
37210 \begin_layout Standard
37211
37212 \size footnotesize
37213 IC_RESULT = IC_LEFT | IC_RIGHT;
37214 \end_layout
37215
37216 \end_inset
37217 </cell>
37218 </row>
37219 <row topline="true">
37220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37221 \begin_inset Text
37222
37223 \begin_layout Standard
37224
37225 \size footnotesize
37226 BITWISEAND
37227 \end_layout
37228
37229 \end_inset
37230 </cell>
37231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37232 \begin_inset Text
37233
37234 \begin_layout Standard
37235
37236 \size footnotesize
37237 IC_LEFT() IC_RIGHT() IC_RESULT()
37238 \end_layout
37239
37240 \end_inset
37241 </cell>
37242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37243 \begin_inset Text
37244
37245 \begin_layout Standard
37246
37247 \size footnotesize
37248 Bitwise AND 
37249 \end_layout
37250
37251 \end_inset
37252 </cell>
37253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37254 \begin_inset Text
37255
37256 \begin_layout Standard
37257
37258 \size footnotesize
37259 IC_RESULT = IC_LEFT & IC_RIGHT;
37260 \end_layout
37261
37262 \end_inset
37263 </cell>
37264 </row>
37265 <row topline="true">
37266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37267 \begin_inset Text
37268
37269 \begin_layout Standard
37270
37271 \size footnotesize
37272 LEFT_OP
37273 \end_layout
37274
37275 \end_inset
37276 </cell>
37277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37278 \begin_inset Text
37279
37280 \begin_layout Standard
37281
37282 \size footnotesize
37283 IC_LEFT() IC_RIGHT() IC_RESULT()
37284 \end_layout
37285
37286 \end_inset
37287 </cell>
37288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37289 \begin_inset Text
37290
37291 \begin_layout Standard
37292
37293 \size footnotesize
37294 Left shift 
37295 \end_layout
37296
37297 \end_inset
37298 </cell>
37299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37300 \begin_inset Text
37301
37302 \begin_layout Standard
37303
37304 \size footnotesize
37305 IC_RESULT = IC_LEFT << IC_RIGHT 
37306 \end_layout
37307
37308 \end_inset
37309 </cell>
37310 </row>
37311 <row topline="true">
37312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37313 \begin_inset Text
37314
37315 \begin_layout Standard
37316
37317 \size footnotesize
37318 RIGHT_OP
37319 \end_layout
37320
37321 \end_inset
37322 </cell>
37323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37324 \begin_inset Text
37325
37326 \begin_layout Standard
37327
37328 \size footnotesize
37329 IC_LEFT() IC_RIGHT() IC_RESULT()
37330 \end_layout
37331
37332 \end_inset
37333 </cell>
37334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37335 \begin_inset Text
37336
37337 \begin_layout Standard
37338
37339 \size footnotesize
37340 Right shift
37341 \end_layout
37342
37343 \end_inset
37344 </cell>
37345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37346 \begin_inset Text
37347
37348 \begin_layout Standard
37349
37350 \size footnotesize
37351 IC_RESULT = IC_LEFT >> IC_RIGHT 
37352 \end_layout
37353
37354 \end_inset
37355 </cell>
37356 </row>
37357 <row topline="true">
37358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37359 \begin_inset Text
37360
37361 \begin_layout Standard
37362
37363 \size footnotesize
37364 GET_VALUE_
37365 \newline
37366 AT_ ADDRESS
37367 \end_layout
37368
37369 \end_inset
37370 </cell>
37371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37372 \begin_inset Text
37373
37374 \begin_layout Standard
37375
37376 \size footnotesize
37377 IC_LEFT() IC_RESULT()
37378 \end_layout
37379
37380 \end_inset
37381 </cell>
37382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37383 \begin_inset Text
37384
37385 \begin_layout Standard
37386
37387 \size footnotesize
37388 Indirect fetch 
37389 \end_layout
37390
37391 \end_inset
37392 </cell>
37393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37394 \begin_inset Text
37395
37396 \begin_layout Standard
37397
37398 \size footnotesize
37399 IC_RESULT = (*IC_LEFT);
37400 \end_layout
37401
37402 \end_inset
37403 </cell>
37404 </row>
37405 <row topline="true">
37406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37407 \begin_inset Text
37408
37409 \begin_layout Standard
37410
37411 \size footnotesize
37412 POINTER_SET
37413 \end_layout
37414
37415 \end_inset
37416 </cell>
37417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37418 \begin_inset Text
37419
37420 \begin_layout Standard
37421
37422 \size footnotesize
37423 IC_RIGHT() IC_RESULT() 
37424 \end_layout
37425
37426 \end_inset
37427 </cell>
37428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37429 \begin_inset Text
37430
37431 \begin_layout Standard
37432
37433 \size footnotesize
37434 Indirect set
37435 \end_layout
37436
37437 \end_inset
37438 </cell>
37439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37440 \begin_inset Text
37441
37442 \begin_layout Standard
37443
37444 \size footnotesize
37445 (*IC_RESULT) = IC_RIGHT;
37446 \end_layout
37447
37448 \end_inset
37449 </cell>
37450 </row>
37451 <row topline="true">
37452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37453 \begin_inset Text
37454
37455 \begin_layout Standard
37456
37457 \size footnotesize
37458 '='
37459 \end_layout
37460
37461 \end_inset
37462 </cell>
37463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37464 \begin_inset Text
37465
37466 \begin_layout Standard
37467
37468 \size footnotesize
37469 IC_RIGHT() IC_RESULT()
37470 \end_layout
37471
37472 \end_inset
37473 </cell>
37474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37475 \begin_inset Text
37476
37477 \begin_layout Standard
37478
37479 \size footnotesize
37480 Assignment
37481 \end_layout
37482
37483 \end_inset
37484 </cell>
37485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37486 \begin_inset Text
37487
37488 \begin_layout Standard
37489
37490 \size footnotesize
37491 IC_RESULT = IC_RIGHT;
37492 \end_layout
37493
37494 \end_inset
37495 </cell>
37496 </row>
37497 <row topline="true">
37498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37499 \begin_inset Text
37500
37501 \begin_layout Standard
37502
37503 \size footnotesize
37504 IFX
37505 \end_layout
37506
37507 \end_inset
37508 </cell>
37509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37510 \begin_inset Text
37511
37512 \begin_layout Standard
37513
37514 \size footnotesize
37515 IC_COND IC_TRUE IC_LABEL
37516 \end_layout
37517
37518 \end_inset
37519 </cell>
37520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37521 \begin_inset Text
37522
37523 \begin_layout Standard
37524
37525 \size footnotesize
37526 Conditional jump.
37527  If true label is present then jump to true label if condition is true else
37528  jump to false label if condition is false 
37529 \end_layout
37530
37531 \end_inset
37532 </cell>
37533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37534 \begin_inset Text
37535
37536 \begin_layout Standard
37537
37538 \size footnotesize
37539 if (IC_COND) goto IC_TRUE; 
37540 \newline
37541 \InsetSpace ~
37542 \InsetSpace ~
37543 Or 
37544 \newline
37545 If (!IC_COND) goto IC_FALSE;
37546 \end_layout
37547
37548 \end_inset
37549 </cell>
37550 </row>
37551 <row topline="true">
37552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37553 \begin_inset Text
37554
37555 \begin_layout Standard
37556
37557 \size footnotesize
37558 ADDRESS_OF
37559 \end_layout
37560
37561 \end_inset
37562 </cell>
37563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37564 \begin_inset Text
37565
37566 \begin_layout Standard
37567
37568 \size footnotesize
37569 IC_LEFT() IC_RESULT()
37570 \end_layout
37571
37572 \end_inset
37573 </cell>
37574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37575 \begin_inset Text
37576
37577 \begin_layout Standard
37578
37579 \size footnotesize
37580 Address of 
37581 \end_layout
37582
37583 \end_inset
37584 </cell>
37585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37586 \begin_inset Text
37587
37588 \begin_layout Standard
37589
37590 \size footnotesize
37591 IC_RESULT = &IC_LEFT();
37592 \end_layout
37593
37594 \end_inset
37595 </cell>
37596 </row>
37597 <row topline="true">
37598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37599 \begin_inset Text
37600
37601 \begin_layout Standard
37602
37603 \size footnotesize
37604 JUMPTABLE
37605 \end_layout
37606
37607 \end_inset
37608 </cell>
37609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37610 \begin_inset Text
37611
37612 \begin_layout Standard
37613
37614 \size footnotesize
37615 IC_JTCOND IC_JTLABELS
37616 \end_layout
37617
37618 \end_inset
37619 </cell>
37620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37621 \begin_inset Text
37622
37623 \begin_layout Standard
37624
37625 \size footnotesize
37626 Jump to list of labels depending on the value of JTCOND
37627 \end_layout
37628
37629 \end_inset
37630 </cell>
37631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37632 \begin_inset Text
37633
37634 \begin_layout Standard
37635
37636 \size footnotesize
37637 Switch statement
37638 \end_layout
37639
37640 \end_inset
37641 </cell>
37642 </row>
37643 <row topline="true">
37644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37645 \begin_inset Text
37646
37647 \begin_layout Standard
37648
37649 \size footnotesize
37650 CAST
37651 \end_layout
37652
37653 \end_inset
37654 </cell>
37655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37656 \begin_inset Text
37657
37658 \begin_layout Standard
37659
37660 \size footnotesize
37661 IC_RIGHT() IC_LEFT() IC_RESULT()
37662 \end_layout
37663
37664 \end_inset
37665 </cell>
37666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37667 \begin_inset Text
37668
37669 \begin_layout Standard
37670
37671 \size footnotesize
37672 Cast types 
37673 \end_layout
37674
37675 \end_inset
37676 </cell>
37677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37678 \begin_inset Text
37679
37680 \begin_layout Standard
37681
37682 \size footnotesize
37683 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37684 \end_layout
37685
37686 \end_inset
37687 </cell>
37688 </row>
37689 <row topline="true">
37690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37691 \begin_inset Text
37692
37693 \begin_layout Standard
37694
37695 \size footnotesize
37696 SEND
37697 \end_layout
37698
37699 \end_inset
37700 </cell>
37701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37702 \begin_inset Text
37703
37704 \begin_layout Standard
37705
37706 \size footnotesize
37707 IC_LEFT()
37708 \end_layout
37709
37710 \end_inset
37711 </cell>
37712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37713 \begin_inset Text
37714
37715 \begin_layout Standard
37716
37717 \size footnotesize
37718 This is used for passing parameters in registers; 
37719 \newline
37720 move IC_LEFT to the next
37721  available parameter register.
37722 \end_layout
37723
37724 \end_inset
37725 </cell>
37726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37727 \begin_inset Text
37728
37729 \begin_layout Standard
37730
37731 \size footnotesize
37732 None
37733 \end_layout
37734
37735 \end_inset
37736 </cell>
37737 </row>
37738 <row topline="true">
37739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37740 \begin_inset Text
37741
37742 \begin_layout Standard
37743
37744 \size footnotesize
37745 RECV
37746 \end_layout
37747
37748 \end_inset
37749 </cell>
37750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37751 \begin_inset Text
37752
37753 \begin_layout Standard
37754
37755 \size footnotesize
37756 IC_RESULT()
37757 \end_layout
37758
37759 \end_inset
37760 </cell>
37761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37762 \begin_inset Text
37763
37764 \begin_layout Standard
37765
37766 \size footnotesize
37767 This is used for receiving parameters passed in registers;
37768 \newline
37769 Move the values
37770  in the next parameter register to IC_RESULT 
37771 \end_layout
37772
37773 \end_inset
37774 </cell>
37775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37776 \begin_inset Text
37777
37778 \begin_layout Standard
37779
37780 \size footnotesize
37781 None
37782 \end_layout
37783
37784 \end_inset
37785 </cell>
37786 </row>
37787 <row topline="true" bottomline="true">
37788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37789 \begin_inset Text
37790
37791 \begin_layout Standard
37792
37793 \shape slanted
37794 \size footnotesize
37795 (some more have been added)
37796 \end_layout
37797
37798 \end_inset
37799 </cell>
37800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37801 \begin_inset Text
37802
37803 \begin_layout Standard
37804
37805 \end_layout
37806
37807 \end_inset
37808 </cell>
37809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37810 \begin_inset Text
37811
37812 \begin_layout Standard
37813
37814 \end_layout
37815
37816 \end_inset
37817 </cell>
37818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37819 \begin_inset Text
37820
37821 \begin_layout Standard
37822
37823 \shape slanted
37824 \size footnotesize
37825 see f.e.
37826  
37827 \family typewriter
37828 gen51Code()
37829 \family default
37830  in 
37831 \family typewriter
37832 src/mcs51/gen.c
37833 \end_layout
37834
37835 \end_inset
37836 </cell>
37837 </row>
37838 </lyxtabular>
37839
37840 \end_inset
37841
37842
37843 \end_layout
37844
37845 \begin_layout Standard
37846 \begin_inset Note Note
37847 status collapsed
37848
37849 \begin_layout Standard
37850 In the original article Figure II was announced to be downloadable on 
37851 \shape italic
37852 Circuit Cellar
37853 \shape default
37854 's web site.
37855  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37856 \end_layout
37857
37858 \end_inset
37859
37860
37861 \end_layout
37862
37863 \begin_layout Paragraph*
37864 ICode Example
37865 \begin_inset LatexCommand \index{iCode}
37866
37867 \end_inset
37868
37869
37870 \end_layout
37871
37872 \begin_layout Standard
37873 This section shows some details of iCode.
37874  The example C code does not do anything useful; it is used as an example
37875  to illustrate the intermediate code generated by the compiler.
37876 \end_layout
37877
37878 \begin_layout Verse
37879
37880 \family typewriter
37881 1.\InsetSpace ~
37882 xdata int * p;
37883 \newline
37884 2.\InsetSpace ~
37885 int gint;
37886 \newline
37887 3.\InsetSpace ~
37888 /* This function does nothing useful.
37889  It is used
37890 \newline
37891 4.\InsetSpace ~
37892 \InsetSpace ~
37893 \InsetSpace ~
37894 \InsetSpace ~
37895 for the purpose of explaining iCode */
37896 \newline
37897 5.\InsetSpace ~
37898 short function (data
37899  int *x)
37900 \newline
37901 6.\InsetSpace ~
37902 {
37903 \newline
37904 7.\InsetSpace ~
37905 \InsetSpace ~
37906 \InsetSpace ~
37907 short i=10; \InsetSpace ~
37908 \InsetSpace ~
37909 /* dead initialization eliminated */
37910 \newline
37911 8.\InsetSpace ~
37912 \InsetSpace ~
37913 \InsetSpace ~
37914 short sum=10;
37915  /* dead initialization eliminated */
37916 \newline
37917 9.\InsetSpace ~
37918 \InsetSpace ~
37919 \InsetSpace ~
37920 short mul;
37921 \newline
37922 10.\InsetSpace ~
37923 \InsetSpace ~
37924 int j ;
37925 \newline
37926 11.\InsetSpace ~
37927 \InsetSpace ~
37928 while (*x) *x++
37929  = *p++; 
37930 \newline
37931 12.\InsetSpace ~
37932 \InsetSpace ~
37933 \InsetSpace ~
37934 \InsetSpace ~
37935 sum = 0 ; 
37936 \newline
37937 13.\InsetSpace ~
37938 \InsetSpace ~
37939 mul = 0;
37940 \newline
37941 14.\InsetSpace ~
37942 \InsetSpace ~
37943 /* compiler detects i,j to be induction
37944  variables */
37945 \newline
37946 15.\InsetSpace ~
37947 \InsetSpace ~
37948 for (i = 0, j = 10 ; i < 10 ; i++, j
37949 \family default
37950 -
37951 \begin_inset ERT
37952 status collapsed
37953
37954 \begin_layout Standard
37955
37956
37957 \backslash
37958 /
37959 \end_layout
37960
37961 \end_inset
37962
37963 -
37964 \family typewriter
37965 ) {
37966 \newline
37967 16.\InsetSpace ~
37968 \InsetSpace ~
37969 \InsetSpace ~
37970 \InsetSpace ~
37971 sum += i;
37972 \newline
37973 17.\InsetSpace ~
37974 \InsetSpace ~
37975 \InsetSpace ~
37976 \InsetSpace ~
37977 mul += i * 3; \InsetSpace ~
37978 \InsetSpace ~
37979 /* this multiplication remains */
37980 \newline
37981 18.\InsetSpace ~
37982 \InsetSpace ~
37983 \InsetSpace ~
37984 \InsetSpace ~
37985 gint +=
37986  j * 3;\InsetSpace ~
37987 \InsetSpace ~
37988 /* this multiplication changed to addition */
37989 \newline
37990 19.\InsetSpace ~
37991 \InsetSpace ~
37992 }
37993 \newline
37994 20.\InsetSpace ~
37995 \InsetSpace ~
37996 return sum+mul;
37997 \newline
37998 21.\InsetSpace ~
37999 }
38000 \end_layout
38001
38002 \begin_layout Standard
38003 In addition to the operands each iCode contains information about the filename
38004  and line it corresponds to in the source file.
38005  The first field in the listing should be interpreted as follows:
38006 \newline
38007
38008 \shape italic
38009 \size footnotesize
38010 Filename(linenumber: iCode Execution sequence number : ICode hash table
38011  key : loop depth of the iCode).
38012 \shape default
38013 \size default
38014
38015 \newline
38016 Then follows the human readable form of the ICode operation.
38017  Each operand of this triplet form can be of three basic types a) compiler
38018  generated temporary b) user defined variable c) a constant value.
38019  Note that local variables and parameters are replaced by compiler generated
38020  temporaries.
38021  Live ranges
38022 \begin_inset LatexCommand \index{Live range analysis}
38023
38024 \end_inset
38025
38026  are computed only for temporaries (i.e.
38027  live ranges are not computed for global variables).
38028  Registers
38029 \begin_inset LatexCommand \index{Register allocation}
38030
38031 \end_inset
38032
38033  are allocated for temporaries only.
38034  Operands are formatted in the following manner:
38035 \newline
38036
38037 \shape italic
38038 \size footnotesize
38039 Operand Name [lr live-from : live-to ] { type information } [ registers
38040  allocated ].
38041 \shape default
38042 \size default
38043
38044 \newline
38045 As mentioned earlier the live ranges are computed in terms of the execution
38046  sequence number of the iCodes, for example 
38047 \newline
38048 the iTemp0 is live from (i.e.
38049  first defined in iCode with execution sequence number 3, and is last used
38050  in the iCode with sequence number 5).
38051  For induction variables such as iTemp21 the live range computation extends
38052  the lifetime from the start to the end of the loop.
38053 \newline
38054 The register allocator
38055  used the live range information to allocate registers, the same registers
38056  may be used for different temporaries if their live ranges do not overlap,
38057  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38058  ranges do not overlap.
38059  In addition the allocator also takes into consideration the type and usage
38060  of a temporary, for example itemp6 is a pointer to near space and is used
38061  as to fetch data from (i.e.
38062  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38063  Some short lived temporaries are allocated to special registers which have
38064  meaning to the code generator e.g.
38065  iTemp13 is allocated to a pseudo register CC which tells the back end that
38066  the temporary is used only for a conditional jump the code generation makes
38067  use of this information to optimize a compare and jump ICode.
38068 \newline
38069 There are several
38070  loop optimizations
38071 \begin_inset LatexCommand \index{Loop optimization}
38072
38073 \end_inset
38074
38075  performed by the compiler.
38076  It can detect induction variables iTemp21(i) and iTemp23(j).
38077  Also note the compiler does selective strength reduction
38078 \begin_inset LatexCommand \index{Strength reduction}
38079
38080 \end_inset
38081
38082 , i.e.
38083  the multiplication of an induction variable in line 18 (gint = j * 3) is
38084  changed to addition, a new temporary iTemp17 is allocated and assigned
38085  a initial value, a constant 3 is then added for each iteration of the loop.
38086  The compiler does not change the multiplication
38087 \begin_inset LatexCommand \index{Multiplication}
38088
38089 \end_inset
38090
38091  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38092 \newline
38093
38094 Note the dead code elimination
38095 \begin_inset LatexCommand \index{Dead-code elimination}
38096
38097 \end_inset
38098
38099  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38100  respectively.
38101 \newline
38102
38103 \end_layout
38104
38105 \begin_layout Standard
38106
38107 \size footnotesize
38108 Sample.c (5:1:0:0) _entry($9) :
38109 \end_layout
38110
38111 \begin_layout Standard
38112
38113 \size footnotesize
38114 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38115 \end_layout
38116
38117 \begin_layout Standard
38118
38119 \size footnotesize
38120 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38121 \end_layout
38122
38123 \begin_layout Standard
38124
38125 \size footnotesize
38126 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38127 \end_layout
38128
38129 \begin_layout Standard
38130
38131 \size footnotesize
38132 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38133  * int}[r2]
38134 \end_layout
38135
38136 \begin_layout Standard
38137
38138 \size footnotesize
38139 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38140 \end_layout
38141
38142 \begin_layout Standard
38143
38144 \size footnotesize
38145 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38146  int}[r0]]
38147 \end_layout
38148
38149 \begin_layout Standard
38150
38151 \size footnotesize
38152 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38153 \end_layout
38154
38155 \begin_layout Standard
38156
38157 \size footnotesize
38158 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38159  * int}
38160 \end_layout
38161
38162 \begin_layout Standard
38163
38164 \size footnotesize
38165 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38166  {short}
38167 \end_layout
38168
38169 \begin_layout Standard
38170
38171 \size footnotesize
38172 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38173  * int}[DPTR]]
38174 \end_layout
38175
38176 \begin_layout Standard
38177
38178 \size footnotesize
38179 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38180 }[r2 r3]
38181 \end_layout
38182
38183 \begin_layout Standard
38184
38185 \size footnotesize
38186 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38187  * int}[r0] + 0x2 {short}
38188 \end_layout
38189
38190 \begin_layout Standard
38191
38192 \size footnotesize
38193 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38194 \end_layout
38195
38196 \begin_layout Standard
38197
38198 \size footnotesize
38199 Sample.c(11:17:21:0)_whilebreak_0($3) :
38200 \end_layout
38201
38202 \begin_layout Standard
38203
38204 \size footnotesize
38205 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38206 \end_layout
38207
38208 \begin_layout Standard
38209
38210 \size footnotesize
38211 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38212 \end_layout
38213
38214 \begin_layout Standard
38215
38216 \size footnotesize
38217 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38218 \end_layout
38219
38220 \begin_layout Standard
38221
38222 \size footnotesize
38223 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38224 \end_layout
38225
38226 \begin_layout Standard
38227
38228 \size footnotesize
38229 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38230 \end_layout
38231
38232 \begin_layout Standard
38233
38234 \size footnotesize
38235 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38236 \end_layout
38237
38238 \begin_layout Standard
38239
38240 \size footnotesize
38241 Sample.c(15:24:26:1)_forcond_0($4) :
38242 \end_layout
38243
38244 \begin_layout Standard
38245
38246 \size footnotesize
38247 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38248  < 0xa {short}
38249 \end_layout
38250
38251 \begin_layout Standard
38252
38253 \size footnotesize
38254 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38255 \end_layout
38256
38257 \begin_layout Standard
38258
38259 \size footnotesize
38260 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38261  + ITemp21 [lr21:38]{short}[r4]
38262 \end_layout
38263
38264 \begin_layout Standard
38265
38266 \size footnotesize
38267 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38268  * 0x3 {short}
38269 \end_layout
38270
38271 \begin_layout Standard
38272
38273 \size footnotesize
38274 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38275  + iTemp15 [lr29:30]{short}[r1]
38276 \end_layout
38277
38278 \begin_layout Standard
38279
38280 \size footnotesize
38281 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38282  r0]- 0x3 {short}
38283 \end_layout
38284
38285 \begin_layout Standard
38286
38287 \size footnotesize
38288 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38289 int}[r7 r0]
38290 \end_layout
38291
38292 \begin_layout Standard
38293
38294 \size footnotesize
38295 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38296  + 0x1 {short}
38297 \end_layout
38298
38299 \begin_layout Standard
38300
38301 \size footnotesize
38302 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38303  r6]- 0x1 {short}
38304 \end_layout
38305
38306 \begin_layout Standard
38307
38308 \size footnotesize
38309 Sample.c(19:38:47:1) goto _forcond_0($4)
38310 \end_layout
38311
38312 \begin_layout Standard
38313
38314 \size footnotesize
38315 Sample.c(19:39:48:0)_forbreak_0($7) :
38316 \end_layout
38317
38318 \begin_layout Standard
38319
38320 \size footnotesize
38321 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38322  + ITemp11 [lr19:40]{short}[r3]
38323 \end_layout
38324
38325 \begin_layout Standard
38326
38327 \size footnotesize
38328 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38329 \end_layout
38330
38331 \begin_layout Standard
38332
38333 \size footnotesize
38334 Sample.c(20:42:51:0)_return($8) :
38335 \end_layout
38336
38337 \begin_layout Standard
38338
38339 \size footnotesize
38340 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38341 \size default
38342
38343 \newline
38344
38345 \newline
38346 Finally the code generated for this function:
38347 \newline
38348
38349 \end_layout
38350
38351 \begin_layout Standard
38352
38353 \size footnotesize
38354 .area DSEG (DATA)
38355 \end_layout
38356
38357 \begin_layout Standard
38358
38359 \size footnotesize
38360 _p::
38361 \end_layout
38362
38363 \begin_layout Standard
38364
38365 \size footnotesize
38366 \InsetSpace ~
38367 \InsetSpace ~
38368 .ds 2
38369 \end_layout
38370
38371 \begin_layout Standard
38372
38373 \size footnotesize
38374 _gint::
38375 \end_layout
38376
38377 \begin_layout Standard
38378
38379 \size footnotesize
38380 \InsetSpace ~
38381 \InsetSpace ~
38382 .ds 2
38383 \end_layout
38384
38385 \begin_layout Standard
38386
38387 \size footnotesize
38388 ; sample.c 5
38389 \end_layout
38390
38391 \begin_layout Standard
38392
38393 \size footnotesize
38394 ; ----------------------------------------------
38395 \end_layout
38396
38397 \begin_layout Standard
38398
38399 \size footnotesize
38400 ; function function
38401 \end_layout
38402
38403 \begin_layout Standard
38404
38405 \size footnotesize
38406 ; ----------------------------------------------
38407 \end_layout
38408
38409 \begin_layout Standard
38410
38411 \size footnotesize
38412 _function:
38413 \end_layout
38414
38415 \begin_layout Standard
38416
38417 \size footnotesize
38418 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38419 \end_layout
38420
38421 \begin_layout Standard
38422
38423 \size footnotesize
38424 \InsetSpace ~
38425 \InsetSpace ~
38426 mov r2,dpl
38427 \end_layout
38428
38429 \begin_layout Standard
38430
38431 \size footnotesize
38432 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38433 \end_layout
38434
38435 \begin_layout Standard
38436
38437 \size footnotesize
38438 \InsetSpace ~
38439 \InsetSpace ~
38440 mov ar0,r2
38441 \end_layout
38442
38443 \begin_layout Standard
38444
38445 \size footnotesize
38446 ;_whilecontinue_0($1) :
38447 \end_layout
38448
38449 \begin_layout Standard
38450
38451 \size footnotesize
38452 00101$:
38453 \end_layout
38454
38455 \begin_layout Standard
38456
38457 \size footnotesize
38458 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38459 \end_layout
38460
38461 \begin_layout Standard
38462
38463 \size footnotesize
38464 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38465 \end_layout
38466
38467 \begin_layout Standard
38468
38469 \size footnotesize
38470 \InsetSpace ~
38471 \InsetSpace ~
38472 mov ar2,@r0
38473 \end_layout
38474
38475 \begin_layout Standard
38476
38477 \size footnotesize
38478 \InsetSpace ~
38479 \InsetSpace ~
38480 inc r0
38481 \end_layout
38482
38483 \begin_layout Standard
38484
38485 \size footnotesize
38486 \InsetSpace ~
38487 \InsetSpace ~
38488 mov ar3,@r0
38489 \end_layout
38490
38491 \begin_layout Standard
38492
38493 \size footnotesize
38494 \InsetSpace ~
38495 \InsetSpace ~
38496 dec r0
38497 \end_layout
38498
38499 \begin_layout Standard
38500
38501 \size footnotesize
38502 \InsetSpace ~
38503 \InsetSpace ~
38504 mov a,r2
38505 \end_layout
38506
38507 \begin_layout Standard
38508
38509 \size footnotesize
38510 \InsetSpace ~
38511 \InsetSpace ~
38512 orl a,r3
38513 \end_layout
38514
38515 \begin_layout Standard
38516
38517 \size footnotesize
38518 \InsetSpace ~
38519 \InsetSpace ~
38520 jz 00103$
38521 \end_layout
38522
38523 \begin_layout Standard
38524
38525 \size footnotesize
38526 00114$:
38527 \end_layout
38528
38529 \begin_layout Standard
38530
38531 \size footnotesize
38532 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38533 \end_layout
38534
38535 \begin_layout Standard
38536
38537 \size footnotesize
38538 \InsetSpace ~
38539 \InsetSpace ~
38540 mov dpl,_p
38541 \end_layout
38542
38543 \begin_layout Standard
38544
38545 \size footnotesize
38546 \InsetSpace ~
38547 \InsetSpace ~
38548 mov dph,(_p + 1)
38549 \end_layout
38550
38551 \begin_layout Standard
38552
38553 \size footnotesize
38554 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38555 \end_layout
38556
38557 \begin_layout Standard
38558
38559 \size footnotesize
38560 \InsetSpace ~
38561 \InsetSpace ~
38562 mov a,#0x02
38563 \end_layout
38564
38565 \begin_layout Standard
38566
38567 \size footnotesize
38568 \InsetSpace ~
38569 \InsetSpace ~
38570 add a,_p
38571 \end_layout
38572
38573 \begin_layout Standard
38574
38575 \size footnotesize
38576 \InsetSpace ~
38577 \InsetSpace ~
38578 mov _p,a
38579 \end_layout
38580
38581 \begin_layout Standard
38582
38583 \size footnotesize
38584 \InsetSpace ~
38585 \InsetSpace ~
38586 clr a
38587 \end_layout
38588
38589 \begin_layout Standard
38590
38591 \size footnotesize
38592 \InsetSpace ~
38593 \InsetSpace ~
38594 addc a,(_p + 1)
38595 \end_layout
38596
38597 \begin_layout Standard
38598
38599 \size footnotesize
38600 \InsetSpace ~
38601 \InsetSpace ~
38602 mov (_p + 1),a
38603 \end_layout
38604
38605 \begin_layout Standard
38606
38607 \size footnotesize
38608 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38609 \end_layout
38610
38611 \begin_layout Standard
38612
38613 \size footnotesize
38614 \InsetSpace ~
38615 \InsetSpace ~
38616 movx a,@dptr
38617 \end_layout
38618
38619 \begin_layout Standard
38620
38621 \size footnotesize
38622 \InsetSpace ~
38623 \InsetSpace ~
38624 mov r2,a
38625 \end_layout
38626
38627 \begin_layout Standard
38628
38629 \size footnotesize
38630 \InsetSpace ~
38631 \InsetSpace ~
38632 inc dptr
38633 \end_layout
38634
38635 \begin_layout Standard
38636
38637 \size footnotesize
38638 \InsetSpace ~
38639 \InsetSpace ~
38640 movx a,@dptr
38641 \end_layout
38642
38643 \begin_layout Standard
38644
38645 \size footnotesize
38646 \InsetSpace ~
38647 \InsetSpace ~
38648 mov r3,a
38649 \end_layout
38650
38651 \begin_layout Standard
38652
38653 \size footnotesize
38654 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38655 \end_layout
38656
38657 \begin_layout Standard
38658
38659 \size footnotesize
38660 \InsetSpace ~
38661 \InsetSpace ~
38662 mov @r0,ar2
38663 \end_layout
38664
38665 \begin_layout Standard
38666
38667 \size footnotesize
38668 \InsetSpace ~
38669 \InsetSpace ~
38670 inc r0
38671 \end_layout
38672
38673 \begin_layout Standard
38674
38675 \size footnotesize
38676 \InsetSpace ~
38677 \InsetSpace ~
38678 mov @r0,ar3
38679 \end_layout
38680
38681 \begin_layout Standard
38682
38683 \size footnotesize
38684 ; iTemp6 [lr5:16]{_near * int}[r0] = 
38685 \end_layout
38686
38687 \begin_layout Standard
38688
38689 \size footnotesize
38690 ; iTemp6 [lr5:16]{_near * int}[r0] + 
38691 \end_layout
38692
38693 \begin_layout Standard
38694
38695 \size footnotesize
38696 ; 0x2 {short}
38697 \end_layout
38698
38699 \begin_layout Standard
38700
38701 \size footnotesize
38702 \InsetSpace ~
38703 \InsetSpace ~
38704 inc r0
38705 \end_layout
38706
38707 \begin_layout Standard
38708
38709 \size footnotesize
38710 ; goto _whilecontinue_0($1)
38711 \end_layout
38712
38713 \begin_layout Standard
38714
38715 \size footnotesize
38716 \InsetSpace ~
38717 \InsetSpace ~
38718 sjmp 00101$
38719 \end_layout
38720
38721 \begin_layout Standard
38722
38723 \size footnotesize
38724 ; _whilebreak_0($3) :
38725 \end_layout
38726
38727 \begin_layout Standard
38728
38729 \size footnotesize
38730 00103$:
38731 \end_layout
38732
38733 \begin_layout Standard
38734
38735 \size footnotesize
38736 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38737 \end_layout
38738
38739 \begin_layout Standard
38740
38741 \size footnotesize
38742 \InsetSpace ~
38743 \InsetSpace ~
38744 mov r2,#0x00
38745 \end_layout
38746
38747 \begin_layout Standard
38748
38749 \size footnotesize
38750 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38751 \end_layout
38752
38753 \begin_layout Standard
38754
38755 \size footnotesize
38756 \InsetSpace ~
38757 \InsetSpace ~
38758 mov r3,#0x00
38759 \end_layout
38760
38761 \begin_layout Standard
38762
38763 \size footnotesize
38764 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38765 \end_layout
38766
38767 \begin_layout Standard
38768
38769 \size footnotesize
38770 \InsetSpace ~
38771 \InsetSpace ~
38772 mov r4,#0x00
38773 \end_layout
38774
38775 \begin_layout Standard
38776
38777 \size footnotesize
38778 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38779 \end_layout
38780
38781 \begin_layout Standard
38782
38783 \size footnotesize
38784 \InsetSpace ~
38785 \InsetSpace ~
38786 mov r5,#0x0A
38787 \end_layout
38788
38789 \begin_layout Standard
38790
38791 \size footnotesize
38792 \InsetSpace ~
38793 \InsetSpace ~
38794 mov r6,#0x00
38795 \end_layout
38796
38797 \begin_layout Standard
38798
38799 \size footnotesize
38800 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38801 \end_layout
38802
38803 \begin_layout Standard
38804
38805 \size footnotesize
38806 \InsetSpace ~
38807 \InsetSpace ~
38808 mov r7,#0x1E
38809 \end_layout
38810
38811 \begin_layout Standard
38812
38813 \size footnotesize
38814 \InsetSpace ~
38815 \InsetSpace ~
38816 mov r0,#0x00
38817 \end_layout
38818
38819 \begin_layout Standard
38820
38821 \size footnotesize
38822 ; _forcond_0($4) :
38823 \end_layout
38824
38825 \begin_layout Standard
38826
38827 \size footnotesize
38828 00104$:
38829 \end_layout
38830
38831 \begin_layout Standard
38832
38833 \size footnotesize
38834 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38835 \end_layout
38836
38837 \begin_layout Standard
38838
38839 \size footnotesize
38840 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38841 \end_layout
38842
38843 \begin_layout Standard
38844
38845 \size footnotesize
38846 \InsetSpace ~
38847 \InsetSpace ~
38848 clr c
38849 \end_layout
38850
38851 \begin_layout Standard
38852
38853 \size footnotesize
38854 \InsetSpace ~
38855 \InsetSpace ~
38856 mov a,r4
38857 \end_layout
38858
38859 \begin_layout Standard
38860
38861 \size footnotesize
38862 \InsetSpace ~
38863 \InsetSpace ~
38864 xrl a,#0x80
38865 \end_layout
38866
38867 \begin_layout Standard
38868
38869 \size footnotesize
38870 \InsetSpace ~
38871 \InsetSpace ~
38872 subb a,#0x8a
38873 \end_layout
38874
38875 \begin_layout Standard
38876
38877 \size footnotesize
38878 \InsetSpace ~
38879 \InsetSpace ~
38880 jnc 00107$
38881 \end_layout
38882
38883 \begin_layout Standard
38884
38885 \size footnotesize
38886 00115$:
38887 \end_layout
38888
38889 \begin_layout Standard
38890
38891 \size footnotesize
38892 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
38893 \end_layout
38894
38895 \begin_layout Standard
38896
38897 \size footnotesize
38898 ; iTemp21 [lr21:38]{short}[r4]
38899 \end_layout
38900
38901 \begin_layout Standard
38902
38903 \size footnotesize
38904 \InsetSpace ~
38905 \InsetSpace ~
38906 mov a,r4
38907 \end_layout
38908
38909 \begin_layout Standard
38910
38911 \size footnotesize
38912 \InsetSpace ~
38913 \InsetSpace ~
38914 add a,r2
38915 \end_layout
38916
38917 \begin_layout Standard
38918
38919 \size footnotesize
38920 \InsetSpace ~
38921 \InsetSpace ~
38922 mov r2,a
38923 \end_layout
38924
38925 \begin_layout Standard
38926
38927 \size footnotesize
38928 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38929 \end_layout
38930
38931 \begin_layout Standard
38932
38933 \size footnotesize
38934 \InsetSpace ~
38935 \InsetSpace ~
38936 mov b,#0x03
38937 \end_layout
38938
38939 \begin_layout Standard
38940
38941 \size footnotesize
38942 \InsetSpace ~
38943 \InsetSpace ~
38944 mov a,r4
38945 \end_layout
38946
38947 \begin_layout Standard
38948
38949 \size footnotesize
38950 \InsetSpace ~
38951 \InsetSpace ~
38952 mul ab
38953 \end_layout
38954
38955 \begin_layout Standard
38956
38957 \size footnotesize
38958 \InsetSpace ~
38959 \InsetSpace ~
38960 mov r1,a
38961 \end_layout
38962
38963 \begin_layout Standard
38964
38965 \size footnotesize
38966 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
38967 \end_layout
38968
38969 \begin_layout Standard
38970
38971 \size footnotesize
38972 ; iTemp15 [lr29:30]{short}[r1]
38973 \end_layout
38974
38975 \begin_layout Standard
38976
38977 \size footnotesize
38978 \InsetSpace ~
38979 \InsetSpace ~
38980 add a,r3
38981 \end_layout
38982
38983 \begin_layout Standard
38984
38985 \size footnotesize
38986 \InsetSpace ~
38987 \InsetSpace ~
38988 mov r3,a
38989 \end_layout
38990
38991 \begin_layout Standard
38992
38993 \size footnotesize
38994 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
38995 \end_layout
38996
38997 \begin_layout Standard
38998
38999 \size footnotesize
39000 \InsetSpace ~
39001 \InsetSpace ~
39002 mov a,r7
39003 \end_layout
39004
39005 \begin_layout Standard
39006
39007 \size footnotesize
39008 \InsetSpace ~
39009 \InsetSpace ~
39010 add a,#0xfd
39011 \end_layout
39012
39013 \begin_layout Standard
39014
39015 \size footnotesize
39016 \InsetSpace ~
39017 \InsetSpace ~
39018 mov r7,a
39019 \end_layout
39020
39021 \begin_layout Standard
39022
39023 \size footnotesize
39024 \InsetSpace ~
39025 \InsetSpace ~
39026 mov a,r0
39027 \end_layout
39028
39029 \begin_layout Standard
39030
39031 \size footnotesize
39032 \InsetSpace ~
39033 \InsetSpace ~
39034 addc a,#0xff
39035 \end_layout
39036
39037 \begin_layout Standard
39038
39039 \size footnotesize
39040 \InsetSpace ~
39041 \InsetSpace ~
39042 mov r0,a
39043 \end_layout
39044
39045 \begin_layout Standard
39046
39047 \size footnotesize
39048 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39049 \end_layout
39050
39051 \begin_layout Standard
39052
39053 \size footnotesize
39054 \InsetSpace ~
39055 \InsetSpace ~
39056 mov a,r7
39057 \end_layout
39058
39059 \begin_layout Standard
39060
39061 \size footnotesize
39062 \InsetSpace ~
39063 \InsetSpace ~
39064 add a,_gint
39065 \end_layout
39066
39067 \begin_layout Standard
39068
39069 \size footnotesize
39070 \InsetSpace ~
39071 \InsetSpace ~
39072 mov _gint,a
39073 \end_layout
39074
39075 \begin_layout Standard
39076
39077 \size footnotesize
39078 \InsetSpace ~
39079 \InsetSpace ~
39080 mov a,r0
39081 \end_layout
39082
39083 \begin_layout Standard
39084
39085 \size footnotesize
39086 \InsetSpace ~
39087 \InsetSpace ~
39088 addc a,(_gint + 1)
39089 \end_layout
39090
39091 \begin_layout Standard
39092
39093 \size footnotesize
39094 \InsetSpace ~
39095 \InsetSpace ~
39096 mov (_gint + 1),a
39097 \end_layout
39098
39099 \begin_layout Standard
39100
39101 \size footnotesize
39102 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39103 \end_layout
39104
39105 \begin_layout Standard
39106
39107 \size footnotesize
39108 \InsetSpace ~
39109 \InsetSpace ~
39110 inc r4
39111 \end_layout
39112
39113 \begin_layout Standard
39114
39115 \size footnotesize
39116 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39117 \end_layout
39118
39119 \begin_layout Standard
39120
39121 \size footnotesize
39122 \InsetSpace ~
39123 \InsetSpace ~
39124 dec r5
39125 \end_layout
39126
39127 \begin_layout Standard
39128
39129 \size footnotesize
39130 \InsetSpace ~
39131 \InsetSpace ~
39132 cjne r5,#0xff,00104$
39133 \end_layout
39134
39135 \begin_layout Standard
39136
39137 \size footnotesize
39138 \InsetSpace ~
39139 \InsetSpace ~
39140 dec r6
39141 \end_layout
39142
39143 \begin_layout Standard
39144
39145 \size footnotesize
39146 ; goto _forcond_0($4)
39147 \end_layout
39148
39149 \begin_layout Standard
39150
39151 \size footnotesize
39152 \InsetSpace ~
39153 \InsetSpace ~
39154 sjmp 00104$
39155 \end_layout
39156
39157 \begin_layout Standard
39158
39159 \size footnotesize
39160 ; _forbreak_0($7) :
39161 \end_layout
39162
39163 \begin_layout Standard
39164
39165 \size footnotesize
39166 00107$:
39167 \end_layout
39168
39169 \begin_layout Standard
39170
39171 \size footnotesize
39172 ; ret iTemp24 [lr40:41]{short}
39173 \end_layout
39174
39175 \begin_layout Standard
39176
39177 \size footnotesize
39178 \InsetSpace ~
39179 \InsetSpace ~
39180 mov a,r3
39181 \end_layout
39182
39183 \begin_layout Standard
39184
39185 \size footnotesize
39186 \InsetSpace ~
39187 \InsetSpace ~
39188 add a,r2
39189 \end_layout
39190
39191 \begin_layout Standard
39192
39193 \size footnotesize
39194 \InsetSpace ~
39195 \InsetSpace ~
39196 mov dpl,a
39197 \end_layout
39198
39199 \begin_layout Standard
39200
39201 \size footnotesize
39202 ; _return($8) :
39203 \end_layout
39204
39205 \begin_layout Standard
39206
39207 \size footnotesize
39208 00108$:
39209 \end_layout
39210
39211 \begin_layout Standard
39212
39213 \size footnotesize
39214 \InsetSpace ~
39215 \InsetSpace ~
39216 ret
39217 \newline
39218
39219 \end_layout
39220
39221 \begin_layout Section
39222 A few words about basic block successors, predecessors and dominators
39223 \end_layout
39224
39225 \begin_layout Standard
39226 Successors are basic blocks
39227 \begin_inset LatexCommand \index{Basic blocks}
39228
39229 \end_inset
39230
39231  that might execute after this basic block.
39232 \newline
39233 Predecessors are basic blocks
39234  that might execute before reaching this basic block.
39235 \newline
39236 Dominators are basic
39237  blocks that WILL execute before reaching this basic block.
39238 \newline
39239
39240 \end_layout
39241
39242 \begin_layout Standard
39243 [basic block 1]
39244 \end_layout
39245
39246 \begin_layout Standard
39247 if (something)
39248 \end_layout
39249
39250 \begin_layout Standard
39251 \InsetSpace ~
39252 \InsetSpace ~
39253 \InsetSpace ~
39254 \InsetSpace ~
39255 [basic block 2]
39256 \end_layout
39257
39258 \begin_layout Standard
39259 else
39260 \end_layout
39261
39262 \begin_layout Standard
39263 \InsetSpace ~
39264 \InsetSpace ~
39265 \InsetSpace ~
39266 \InsetSpace ~
39267 [basic block 3]
39268 \end_layout
39269
39270 \begin_layout Standard
39271 [basic block 4]
39272 \newline
39273
39274 \end_layout
39275
39276 \begin_layout Standard
39277 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39278 \end_layout
39279
39280 \begin_layout Standard
39281 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39282 \end_layout
39283
39284 \begin_layout Standard
39285 c) domVect of [BB4] = BB1 ...
39286  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39287  was executed.
39288 \end_layout
39289
39290 \begin_layout Chapter
39291 Acknowledgments
39292 \end_layout
39293
39294 \begin_layout Standard
39295 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39296
39297 \end_inset
39298
39299
39300 \newline
39301
39302 \newline
39303
39304 \emph on
39305 Thanks to all the other volunteer developers who have helped with coding,
39306  testing, web-page creation, distribution sets, etc.
39307  You know who you are :-)
39308 \emph default
39309
39310 \newline
39311
39312 \newline
39313
39314 \emph on
39315 Also thanks to Sourceforge 
39316 \begin_inset LatexCommand \url{http://www.sf.net}
39317
39318 \end_inset
39319
39320  which has hosted the project since 1999 and donates significant download
39321  bandwidth and probably more than 
39322 \begin_inset ERT
39323 status collapsed
39324
39325 \begin_layout Standard
39326
39327 $10^{13}$
39328 \end_layout
39329
39330 \end_inset
39331
39332 CPU cycles per day.
39333 \newline
39334  
39335 \begin_inset Note Note
39336 status open
39337
39338 \begin_layout Standard
39339 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39340  minutes for (configure+make+regression test), and there is (i386, amd64,
39341  alpha, ppc64, (mingw32), sparc, macosx).
39342  
39343 \end_layout
39344
39345 \end_inset
39346
39347
39348 \end_layout
39349
39350 \begin_layout Standard
39351 This document was initially written by Sandeep Dutta
39352 \end_layout
39353
39354 \begin_layout Standard
39355 All product names mentioned herein may be trademarks
39356 \begin_inset LatexCommand \index{Trademarks}
39357
39358 \end_inset
39359
39360  of their respective companies.
39361  
39362 \end_layout
39363
39364 \begin_layout Section*
39365 Alphabetical index
39366 \end_layout
39367
39368 \begin_layout Standard
39369 To avoid confusion, the installation and building options for SDCC itself
39370  (chapter 2) are not part of the index.
39371 \end_layout
39372
39373 \begin_layout Standard
39374 \begin_inset LatexCommand \printindex{}
39375
39376 \end_inset
39377
39378
39379 \end_layout
39380
39381 \end_body
39382 \end_document