* doc/sdccman.lyx:
[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 free open source, retargettable, optimizing ANSI-C compiler
167  by 
168 \series bold
169 Sandeep Dutta
170 \series default
171  designed for 8 bit Microprocessors.
172  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
173  8051, 8052
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
175
176 \end_inset
177
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179  Zilog Z80 based MCUs.
180  It can be retargeted for other microprocessors, support for Microchip PIC,
181  Atmel AVR is under development.
182  The entire source code for the compiler is distributed under GPL.
183  SDCC uses ASXXXX
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185
186 \end_inset
187
188  & ASLINK
189 \begin_inset LatexCommand \index{aslink}
190
191 \end_inset
192
193 , an open source retargetable assembler & linker.
194  SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
196  
197 \newline
198
199 \newline
200 In addition to the MCU specific optimizations SDCC also does a host of
201  standard optimizations like:
202 \end_layout
203
204 \begin_layout Itemize
205 global sub expression elimination, 
206 \end_layout
207
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
210  and loop reversing), 
211 \end_layout
212
213 \begin_layout Itemize
214 constant folding & propagation, 
215 \end_layout
216
217 \begin_layout Itemize
218 copy propagation, 
219 \end_layout
220
221 \begin_layout Itemize
222 dead code elimination 
223 \end_layout
224
225 \begin_layout Itemize
226 jump tables for 
227 \emph on
228 switch
229 \emph default
230  statements.
231 \end_layout
232
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235  be well suited for other 8 bit MCUs.
236  
237 \newline
238
239 \newline
240 The peep hole optimizer uses a rule based substitution mechanism which
241  is MCU independent.
242  
243 \newline
244
245 \newline
246 Supported data-types are:
247 \end_layout
248
249 \begin_layout Standard
250 \begin_inset Tabular
251 <lyxtabular version="3" rows="8" columns="5">
252 <features>
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \begin_layout Standard
263 type
264 \end_layout
265
266 \end_inset
267 </cell>
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
269 \begin_inset Text
270
271 \begin_layout Standard
272 width
273 \end_layout
274
275 \end_inset
276 </cell>
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \begin_layout Standard
281 default
282 \end_layout
283
284 \end_inset
285 </cell>
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
287 \begin_inset Text
288
289 \begin_layout Standard
290 signed range
291 \end_layout
292
293 \end_inset
294 </cell>
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
296 \begin_inset Text
297
298 \begin_layout Standard
299 unsigned range
300 \end_layout
301
302 \end_inset
303 </cell>
304 </row>
305 <row topline="true">
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
307 \begin_inset Text
308
309 \begin_layout Standard
310 bool
311 \end_layout
312
313 \end_inset
314 </cell>
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
316 \begin_inset Text
317
318 \begin_layout Standard
319 1 bit
320 \end_layout
321
322 \end_inset
323 </cell>
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 \begin_inset Text
326
327 \begin_layout Standard
328 unsigned
329 \end_layout
330
331 \end_inset
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
334 \begin_inset Text
335
336 \begin_layout Standard
337 -
338 \end_layout
339
340 \end_inset
341 </cell>
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 \begin_inset Text
344
345 \begin_layout Standard
346 0, 1
347 \end_layout
348
349 \end_inset
350 </cell>
351 </row>
352 <row topline="true">
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
354 \begin_inset Text
355
356 \begin_layout Standard
357 char
358 \end_layout
359
360 \end_inset
361 </cell>
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
363 \begin_inset Text
364
365 \begin_layout Standard
366 8 bits, 1 byte
367 \end_layout
368
369 \end_inset
370 </cell>
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 \begin_inset Text
373
374 \begin_layout Standard
375 signed
376 \end_layout
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \begin_layout Standard
384 -128, +127
385 \end_layout
386
387 \end_inset
388 </cell>
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
390 \begin_inset Text
391
392 \begin_layout Standard
393 0, +255
394 \end_layout
395
396 \end_inset
397 </cell>
398 </row>
399 <row topline="true">
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 \begin_inset Text
402
403 \begin_layout Standard
404 short
405 \end_layout
406
407 \end_inset
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \begin_layout Standard
413 16 bits, 2 bytes
414 \end_layout
415
416 \end_inset
417 </cell>
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 \begin_inset Text
420
421 \begin_layout Standard
422 signed
423 \end_layout
424
425 \end_inset
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \begin_layout Standard
431 -32.768, +32.767
432 \end_layout
433
434 \end_inset
435 </cell>
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
437 \begin_inset Text
438
439 \begin_layout Standard
440 0, +65.535
441 \end_layout
442
443 \end_inset
444 </cell>
445 </row>
446 <row topline="true">
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 \begin_inset Text
449
450 \begin_layout Standard
451 int
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 16 bits, 2 bytes
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 signed
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 -32.768, +32.767
479 \end_layout
480
481 \end_inset
482 </cell>
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
484 \begin_inset Text
485
486 \begin_layout Standard
487 0, +65.535
488 \end_layout
489
490 \end_inset
491 </cell>
492 </row>
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 \begin_inset Text
496
497 \begin_layout Standard
498 long
499 \end_layout
500
501 \end_inset
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \begin_layout Standard
507 32 bits, 4 bytes
508 \end_layout
509
510 \end_inset
511 </cell>
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
513 \begin_inset Text
514
515 \begin_layout Standard
516 signed
517 \end_layout
518
519 \end_inset
520 </cell>
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
522 \begin_inset Text
523
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
526 \end_layout
527
528 \end_inset
529 </cell>
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
531 \begin_inset Text
532
533 \begin_layout Standard
534 0, +4.294.967.295
535 \end_layout
536
537 \end_inset
538 </cell>
539 </row>
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \begin_layout Standard
545 float
546 \end_layout
547
548 \end_inset
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
551 \begin_inset Text
552
553 \begin_layout Standard
554 4 bytes IEEE 754
555 \end_layout
556
557 \end_inset
558 </cell>
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
560 \begin_inset Text
561
562 \begin_layout Standard
563 signed
564 \end_layout
565
566 \end_inset
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
569 \begin_inset Text
570
571 \begin_layout Standard
572
573 \end_layout
574
575 \end_inset
576 </cell>
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
578 \begin_inset Text
579
580 \begin_layout Standard
581 1.175494351E-38, 
582 \family roman
583 \series medium
584 \shape up
585 \size normal
586 \emph off
587 \bar no
588 \noun off
589 \color none
590 3.402823466E+38
591 \end_layout
592
593 \end_inset
594 </cell>
595 </row>
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
598 \begin_inset Text
599
600 \begin_layout Standard
601 pointer
602 \end_layout
603
604 \end_inset
605 </cell>
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
607 \begin_inset Text
608
609 \begin_layout Standard
610 1, 2, 3 or 4 bytes
611 \end_layout
612
613 \end_inset
614 </cell>
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
616 \begin_inset Text
617
618 \begin_layout Standard
619 generic
620 \end_layout
621
622 \end_inset
623 </cell>
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
625 \begin_inset Text
626
627 \begin_layout Standard
628
629 \end_layout
630
631 \end_inset
632 </cell>
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634 \begin_inset Text
635
636 \begin_layout Standard
637
638 \end_layout
639
640 \end_inset
641 </cell>
642 </row>
643 </lyxtabular>
644
645 \end_inset
646
647
648 \newline
649 The compiler also allows 
650 \emph on
651 inline assembler code
652 \emph default
653  to be embedded anywhere in a function.
654  In addition, routines developed in assembly can also be called.
655 \newline
656
657 \newline
658 SDCC also
659  provides an option (-
660 \begin_inset ERT
661 status collapsed
662
663 \begin_layout Standard
664
665
666 \backslash
667 /
668 \end_layout
669
670 \end_inset
671
672 -cyclomatic) to report the relative complexity of a function.
673  These functions can then be further optimized, or hand coded in assembly
674  if needed.
675  
676 \newline
677
678 \newline
679 SDCC also comes with a companion source level debugger SDCDB.
680  The debugger currently uses ucSim, a free open source simulator for 8051
681  and other micro-controllers.
682 \newline
683
684 \newline
685 The latest SDCC version can be downloaded from
686  
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
688
689 \end_inset
690
691 .
692
693 \series bold
694  
695 \series default
696 \emph on
697 Please note: the compiler will probably always be some steps ahead of this
698  documentation
699 \series bold
700 \emph default
701
702 \begin_inset LatexCommand \index{Status of documentation}
703
704 \end_inset
705
706
707 \begin_inset Foot
708 status open
709
710 \begin_layout Standard
711 Obviously this has pros and cons
712 \end_layout
713
714 \end_inset
715
716 .
717 \end_layout
718
719 \begin_layout Section
720 Open Source
721 \end_layout
722
723 \begin_layout Standard
724 All packages used in this compiler system are 
725 \emph on
726 open source
727 \emph default
728  and 
729 \emph on
730 freeware
731 \emph default
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733  etc) is distributed with the package.
734  This documentation is maintained using a free open source word processor
735  (LyX).
736 \newline
737 This program is free software; you can redistribute it and/or modify
738  it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
740
741 \end_inset
742
743  as published by the Free Software Foundation; either version 2, or (at
744  your option) any later version.
745  This program is distributed in the hope that it will be useful, but WITHOUT
746  ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
748
749 \end_inset
750
751  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752  See the GNU General Public License for more details.
753  You should have received a copy of the GNU General Public License along
754  with this program; if not, write to the Free Software Foundation, 59 Temple
755  Place - Suite 330, Boston, MA 02111-1307, USA.
756  In other words, you are welcome to use, share and improve this program.
757  You are forbidden to forbid anyone else to use, share and improve what
758  you give them.
759  Help stamp out software-hoarding! 
760 \end_layout
761
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
765
766 \end_inset
767
768
769 \end_layout
770
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773  Commands you have to type in are printed in 
774 \family sans
775 \series bold
776 "sans serif"
777 \series default
778 .
779
780 \family default
781  Code samples are printed in 
782 \family typewriter
783 typewriter font.
784
785 \family default
786  Interesting items and new terms are printed in 
787 \emph on
788 italic.
789 \end_layout
790
791 \begin_layout Section
792 Compatibility
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
794
795 \end_inset
796
797  with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
799
800 \end_inset
801
802
803 \end_layout
804
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
807  version.
808  But we also sometimes introduce some incompatibilities with older versions.
809  Not just for the fun of it, but to make the compiler more stable, efficient
810  and ANSI compliant
811 \begin_inset LatexCommand \index{ANSI-compliance}
812
813 \end_inset
814
815  (see section 
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
817
818 \end_inset
819
820  for ANSI-Compliance).
821  
822 \begin_inset Note Note
823 status collapsed
824
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
827 \end_layout
828
829 \end_inset
830
831
832 \newline
833
834 \end_layout
835
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838  (8 bits) which is not ANSI compliant.
839  To maintain compatibility, old programs may be compiled using the --short-is-8b
840 its commandline option (see 
841 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
842
843 \end_inset
844
845 ).
846 \end_layout
847
848 \begin_layout Itemize
849 the default directory for gcc-builds where include, library and documentation
850  files are stored is now in /usr/local/share.
851 \end_layout
852
853 \begin_layout Itemize
854 char type parameters to vararg
855 \begin_inset LatexCommand \index{vararg, va\_arg}
856
857 \end_inset
858
859  functions are casted to int unless explicitly casted
860 \begin_inset Marginal
861 status collapsed
862
863 \begin_layout Standard
864
865 \series bold
866 \InsetSpace ~
867 !
868 \end_layout
869
870 \end_inset
871
872 , e.g.: 
873 \newline
874
875 \family typewriter
876 \InsetSpace ~
877 \InsetSpace ~
878 char a=3;
879 \newline
880 \InsetSpace ~
881 \InsetSpace ~
882 printf ("%d %c
883 \backslash
884 n", a, (char)a);
885 \family default
886
887 \newline
888  will push a as an int and as a char resp.
889 \end_layout
890
891 \begin_layout Itemize
892 option -
893 \begin_inset ERT
894 status collapsed
895
896 \begin_layout Standard
897
898
899 \backslash
900 /
901 \end_layout
902
903 \end_inset
904
905 -regextend has been removed.
906 \end_layout
907
908 \begin_layout Itemize
909 option -
910 \begin_inset ERT
911 status collapsed
912
913 \begin_layout Standard
914
915
916 \backslash
917 /
918 \end_layout
919
920 \end_inset
921
922 -noregparms has been removed.
923 \end_layout
924
925 \begin_layout Itemize
926 option -
927 \begin_inset ERT
928 status collapsed
929
930 \begin_layout Standard
931
932
933 \backslash
934 /
935 \end_layout
936
937 \end_inset
938
939 -stack-after-data has been removed.
940 \end_layout
941
942 \begin_layout Itemize
943 bit
944 \begin_inset LatexCommand \index{bit}
945
946 \end_inset
947
948  and sbit
949 \begin_inset LatexCommand \index{sbit}
950
951 \end_inset
952
953
954 \begin_inset LatexCommand \index{\_\_sbit}
955
956 \end_inset
957
958  types now consistently behave like the C99 _Bool type with respect to type
959  conversion
960 \begin_inset LatexCommand \index{type conversion}
961
962 \end_inset
963
964
965 \begin_inset LatexCommand \index{type promotion}
966
967 \end_inset
968
969 .
970  The most common incompatibility resulting from this change is related to
971  bit toggling
972 \begin_inset LatexCommand \index{Bit toggling}
973
974 \end_inset
975
976  idioms, e.g.:
977 \newline
978
979 \family typewriter
980 \InsetSpace ~
981 \InsetSpace ~
982 bit b;
983 \newline
984 \InsetSpace ~
985 \InsetSpace ~
986 b = ~
987 \begin_inset LatexCommand \index{\~\/ Operator}
988
989 \end_inset
990
991 b; /* equivalent to b=1 instead of toggling b */
992 \begin_inset Marginal
993 status collapsed
994
995 \begin_layout Standard
996
997 \series bold
998 \InsetSpace ~
999 !
1000 \end_layout
1001
1002 \end_inset
1003
1004
1005 \newline
1006 \InsetSpace ~
1007 \InsetSpace ~
1008 b = !b; /* toggles b */
1009 \newline
1010
1011 \family default
1012 In previous versions, both forms would have toggled the bit.
1013 \end_layout
1014
1015 \begin_layout Standard
1016
1017 \emph on
1018 <pending: more incompatibilities?>
1019 \end_layout
1020
1021 \begin_layout Section
1022 System Requirements
1023 \end_layout
1024
1025 \begin_layout Standard
1026 What do you need before you start installation of SDCC? A computer, and
1027  a desire to compute.
1028  The preferred method of installation is to compile SDCC from source using
1029  GNU gcc and make.
1030  For Windows some pre-compiled binary distributions are available for your
1031  convenience.
1032  You should have some experience with command line tools and compiler use.
1033 \end_layout
1034
1035 \begin_layout Section
1036 Other Resources
1037 \end_layout
1038
1039 \begin_layout Standard
1040 The SDCC home page at 
1041 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1042
1043 \end_inset
1044
1045  is a great place to find distribution sets.
1046  You can also find links to the user mailing lists that offer help or discuss
1047  SDCC with other SDCC users.
1048  Web links to other SDCC related sites can also be found here.
1049  This document can be found in the DOC directory of the source package as
1050  a text or HTML file.
1051  A pdf version of this document is available at 
1052 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1053
1054 \end_inset
1055
1056 .
1057  Some of the other tools (simulator and assembler) included with SDCC contain
1058  their own documentation and can be found in the source distribution.
1059  If you want the latest unreleased software, the complete source package
1060  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1061 sdcc/trunk/sdcc.
1062 \end_layout
1063
1064 \begin_layout Section
1065 Wishes for the future
1066 \end_layout
1067
1068 \begin_layout Standard
1069 There are (and always will be) some things that could be done.
1070  Here are some I can think of:
1071 \newline
1072
1073 \end_layout
1074
1075 \begin_layout Standard
1076
1077 \family typewriter
1078 char KernelFunction3(char p) at 0x340;
1079 \newline
1080
1081 \end_layout
1082
1083 \begin_layout Standard
1084
1085 \family typewriter
1086 better code banking
1087 \begin_inset LatexCommand \index{code banking (limited support)}
1088
1089 \end_inset
1090
1091  support for mcs51
1092 \newline
1093
1094 \newline
1095
1096 \family default
1097 If you can think of some more, please see the section 
1098 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1099
1100 \end_inset
1101
1102  about filing feature requests
1103 \begin_inset LatexCommand \index{Requesting features}
1104
1105 \end_inset
1106
1107
1108 \begin_inset LatexCommand \index{Feature request}
1109
1110 \end_inset
1111
1112 .
1113 \newline
1114
1115 \end_layout
1116
1117 \begin_layout Chapter
1118 Installing SDCC
1119 \begin_inset LatexCommand \index{Installation}
1120
1121 \end_inset
1122
1123
1124 \end_layout
1125
1126 \begin_layout Standard
1127 For most users it is sufficient to skip to either section 
1128 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1129
1130 \end_inset
1131
1132  (Unix) or section 
1133 \begin_inset LatexCommand \ref{sub:Windows-Install}
1134
1135 \end_inset
1136
1137  (Windows).
1138  More detailed instructions follow below.
1139 \end_layout
1140
1141 \begin_layout Section
1142 Configure Options
1143 \begin_inset LatexCommand \index{Options SDCC configuration}
1144
1145 \end_inset
1146
1147
1148 \end_layout
1149
1150 \begin_layout Standard
1151 The install paths, search paths and other options are defined when running
1152  'configure'.
1153  The defaults can be overridden by:
1154 \end_layout
1155
1156 \begin_layout List
1157 \labelwidthstring 00.00.0000
1158 -
1159 \begin_inset ERT
1160 status collapsed
1161
1162 \begin_layout Standard
1163
1164
1165 \backslash
1166 /
1167 \end_layout
1168
1169 \end_inset
1170
1171 -prefix see table below
1172 \end_layout
1173
1174 \begin_layout List
1175 \labelwidthstring 00.00.0000
1176 -
1177 \begin_inset ERT
1178 status collapsed
1179
1180 \begin_layout Standard
1181
1182
1183 \backslash
1184 /
1185 \end_layout
1186
1187 \end_inset
1188
1189 -exec_prefix see table below
1190 \end_layout
1191
1192 \begin_layout List
1193 \labelwidthstring 00.00.0000
1194 -
1195 \begin_inset ERT
1196 status collapsed
1197
1198 \begin_layout Standard
1199
1200
1201 \backslash
1202 /
1203 \end_layout
1204
1205 \end_inset
1206
1207 -bindir see table below
1208 \end_layout
1209
1210 \begin_layout List
1211 \labelwidthstring 00.00.0000
1212 -
1213 \begin_inset ERT
1214 status collapsed
1215
1216 \begin_layout Standard
1217
1218
1219 \backslash
1220 /
1221 \end_layout
1222
1223 \end_inset
1224
1225 -datadir see table below
1226 \end_layout
1227
1228 \begin_layout List
1229 \labelwidthstring 00.00.0000
1230 -
1231 \begin_inset ERT
1232 status collapsed
1233
1234 \begin_layout Standard
1235
1236
1237 \backslash
1238 /
1239 \end_layout
1240
1241 \end_inset
1242
1243 -datarootdir see table below
1244 \newline
1245
1246 \end_layout
1247
1248 \begin_layout List
1249 \labelwidthstring 00.00.0000
1250 \InsetSpace ~
1251 \InsetSpace ~
1252 docdir environment variable, see table below
1253 \end_layout
1254
1255 \begin_layout List
1256 \labelwidthstring 00.00.0000
1257 \InsetSpace ~
1258 \InsetSpace ~
1259 include_dir_suffix environment variable, see table below
1260 \end_layout
1261
1262 \begin_layout List
1263 \labelwidthstring 00.00.0000
1264 \InsetSpace ~
1265 \InsetSpace ~
1266 lib_dir_suffix environment variable, see table below
1267 \end_layout
1268
1269 \begin_layout List
1270 \labelwidthstring 00.00.0000
1271 \InsetSpace ~
1272 \InsetSpace ~
1273 sdccconf_h_dir_separator environment variable, either / or 
1274 \backslash
1275
1276 \backslash
1277  makes sense here.
1278  This character will only be used in sdccconf.h; don't forget it's a C-header,
1279  therefore a double-backslash is needed there.
1280 \newline
1281
1282 \end_layout
1283
1284 \begin_layout List
1285 \labelwidthstring 00.00.0000
1286 -
1287 \begin_inset ERT
1288 status collapsed
1289
1290 \begin_layout Standard
1291
1292
1293 \backslash
1294 /
1295 \end_layout
1296
1297 \end_inset
1298
1299 -disable-mcs51-port Excludes the Intel mcs51 port
1300 \end_layout
1301
1302 \begin_layout List
1303 \labelwidthstring 00.00.0000
1304 -
1305 \begin_inset ERT
1306 status collapsed
1307
1308 \begin_layout Standard
1309
1310
1311 \backslash
1312 /
1313 \end_layout
1314
1315 \end_inset
1316
1317 -disable-gbz80-port Excludes the Gameboy gbz80 port
1318 \end_layout
1319
1320 \begin_layout List
1321 \labelwidthstring 00.00.0000
1322 -
1323 \begin_inset ERT
1324 status collapsed
1325
1326 \begin_layout Standard
1327
1328
1329 \backslash
1330 /
1331 \end_layout
1332
1333 \end_inset
1334
1335 -disable-z80-port Excludes the z80 port
1336 \end_layout
1337
1338 \begin_layout List
1339 \labelwidthstring 00.00.0000
1340 -
1341 \begin_inset ERT
1342 status collapsed
1343
1344 \begin_layout Standard
1345
1346
1347 \backslash
1348 /
1349 \end_layout
1350
1351 \end_inset
1352
1353 -disable-avr-port Excludes the AVR port
1354 \end_layout
1355
1356 \begin_layout List
1357 \labelwidthstring 00.00.0000
1358 -
1359 \begin_inset ERT
1360 status collapsed
1361
1362 \begin_layout Standard
1363
1364
1365 \backslash
1366 /
1367 \end_layout
1368
1369 \end_inset
1370
1371 -disable-ds390-port Excludes the DS390 port
1372 \end_layout
1373
1374 \begin_layout List
1375 \labelwidthstring 00.00.0000
1376 -
1377 \begin_inset ERT
1378 status collapsed
1379
1380 \begin_layout Standard
1381
1382
1383 \backslash
1384 /
1385 \end_layout
1386
1387 \end_inset
1388
1389 -disable-hc08-port Excludes the HC08 port
1390 \end_layout
1391
1392 \begin_layout List
1393 \labelwidthstring 00.00.0000
1394 -
1395 \begin_inset ERT
1396 status collapsed
1397
1398 \begin_layout Standard
1399
1400
1401 \backslash
1402 /
1403 \end_layout
1404
1405 \end_inset
1406
1407 -disable-pic-port Excludes the PIC port
1408 \end_layout
1409
1410 \begin_layout List
1411 \labelwidthstring 00.00.0000
1412 -
1413 \begin_inset ERT
1414 status collapsed
1415
1416 \begin_layout Standard
1417
1418
1419 \backslash
1420 /
1421 \end_layout
1422
1423 \end_inset
1424
1425 -disable-xa51-port Excludes the XA51 port
1426 \end_layout
1427
1428 \begin_layout List
1429 \labelwidthstring 00.00.0000
1430 -
1431 \begin_inset ERT
1432 status collapsed
1433
1434 \begin_layout Standard
1435
1436
1437 \backslash
1438 /
1439 \end_layout
1440
1441 \end_inset
1442
1443 -disable-ucsim Disables configuring and building of ucsim
1444 \end_layout
1445
1446 \begin_layout List
1447 \labelwidthstring 00.00.0000
1448 -
1449 \begin_inset ERT
1450 status collapsed
1451
1452 \begin_layout Standard
1453
1454
1455 \backslash
1456 /
1457 \end_layout
1458
1459 \end_inset
1460
1461 -disable-device-lib Disables automatically building device libraries
1462 \end_layout
1463
1464 \begin_layout List
1465 \labelwidthstring 00.00.0000
1466 -
1467 \begin_inset ERT
1468 status collapsed
1469
1470 \begin_layout Standard
1471
1472
1473 \backslash
1474 /
1475 \end_layout
1476
1477 \end_inset
1478
1479 -disable-packihx Disables building packihx
1480 \newline
1481
1482 \end_layout
1483
1484 \begin_layout List
1485 \labelwidthstring 00.00.0000
1486 -
1487 \begin_inset ERT
1488 status collapsed
1489
1490 \begin_layout Standard
1491
1492
1493 \backslash
1494 /
1495 \end_layout
1496
1497 \end_inset
1498
1499 -enable-doc Build pdf, html and txt files from the lyx sources
1500 \end_layout
1501
1502 \begin_layout List
1503 \labelwidthstring 00.00.0000
1504 -
1505 \begin_inset ERT
1506 status collapsed
1507
1508 \begin_layout Standard
1509
1510
1511 \backslash
1512 /
1513 \end_layout
1514
1515 \end_inset
1516
1517 -enable-libgc Use the Bohem memory allocator.
1518  Lower runtime footprint.
1519 \end_layout
1520
1521 \begin_layout Standard
1522 Furthermore the environment variables CC, CFLAGS, ...
1523  the tools and their arguments can be influenced.
1524  Please see `configure -
1525 \begin_inset ERT
1526 status collapsed
1527
1528 \begin_layout Standard
1529
1530
1531 \backslash
1532 /
1533 \end_layout
1534
1535 \end_inset
1536
1537 -help` and the man/info pages of `configure` for details.
1538 \newline
1539
1540 \newline
1541 The names of the
1542  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1543 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1544  SDCC_LIB_NAME are defined by `configure` too.
1545  At the moment it's not possible to change the default settings (it was
1546  simply never required).
1547 \newline
1548
1549 \newline
1550 These configure options are compiled into the binaries,
1551  and can only be changed by rerunning 'configure' and recompiling SDCC.
1552  The configure options are written in 
1553 \emph on
1554 italics
1555 \emph default
1556  to distinguish them from run time environment variables (see section search
1557  paths).
1558 \newline
1559
1560 \newline
1561 The settings for 
1562 \begin_inset Quotes sld
1563 \end_inset
1564
1565 Win32 builds
1566 \begin_inset Quotes srd
1567 \end_inset
1568
1569  are used by the SDCC team to build the official Win32 binaries.
1570  The SDCC team uses Mingw32 to build the official Windows binaries, because
1571  it's
1572 \end_layout
1573
1574 \begin_layout Enumerate
1575 open source, 
1576 \end_layout
1577
1578 \begin_layout Enumerate
1579 a gcc compiler and last but not least
1580 \end_layout
1581
1582 \begin_layout Enumerate
1583 the binaries can be built by cross compiling on SDCC Distributed Compile
1584  Farm.
1585 \end_layout
1586
1587 \begin_layout Standard
1588 See the examples, how to pass the Win32 settings to 'configure'.
1589  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1590  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1591  for Win32.
1592 \newline
1593
1594 \newline
1595 These defaults are:
1596 \newline
1597
1598 \end_layout
1599
1600 \begin_layout Standard
1601 \align center
1602 \begin_inset Tabular
1603 <lyxtabular version="3" rows="9" columns="3">
1604 <features>
1605 <column alignment="block" valignment="top" leftline="true" width="0in">
1606 <column alignment="block" valignment="top" leftline="true" width="0in">
1607 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1608 <row topline="true" bottomline="true">
1609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1610 \begin_inset Text
1611
1612 \begin_layout Standard
1613 Variable
1614 \end_layout
1615
1616 \end_inset
1617 </cell>
1618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1619 \begin_inset Text
1620
1621 \begin_layout Standard
1622 default
1623 \end_layout
1624
1625 \end_inset
1626 </cell>
1627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1628 \begin_inset Text
1629
1630 \begin_layout Standard
1631 Win32 builds
1632 \end_layout
1633
1634 \end_inset
1635 </cell>
1636 </row>
1637 <row topline="true">
1638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1639 \begin_inset Text
1640
1641 \begin_layout Standard
1642
1643 \emph on
1644 PREFIX
1645 \end_layout
1646
1647 \end_inset
1648 </cell>
1649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1650 \begin_inset Text
1651
1652 \begin_layout Standard
1653 /usr/local
1654 \end_layout
1655
1656 \end_inset
1657 </cell>
1658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1659 \begin_inset Text
1660
1661 \begin_layout Standard
1662
1663 \backslash
1664 sdcc
1665 \end_layout
1666
1667 \end_inset
1668 </cell>
1669 </row>
1670 <row topline="true">
1671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1672 \begin_inset Text
1673
1674 \begin_layout Standard
1675
1676 \emph on
1677 EXEC_PREFIX
1678 \end_layout
1679
1680 \end_inset
1681 </cell>
1682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1683 \begin_inset Text
1684
1685 \begin_layout Standard
1686
1687 \emph on
1688 $PREFIX
1689 \end_layout
1690
1691 \end_inset
1692 </cell>
1693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1694 \begin_inset Text
1695
1696 \begin_layout Standard
1697
1698 \emph on
1699 $PREFIX
1700 \end_layout
1701
1702 \end_inset
1703 </cell>
1704 </row>
1705 <row topline="true">
1706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1707 \begin_inset Text
1708
1709 \begin_layout Standard
1710
1711 \emph on
1712 BINDIR
1713 \end_layout
1714
1715 \end_inset
1716 </cell>
1717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1718 \begin_inset Text
1719
1720 \begin_layout Standard
1721
1722 \emph on
1723 $EXEC_PREFIX
1724 \emph default
1725 /bin
1726 \end_layout
1727
1728 \end_inset
1729 </cell>
1730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1731 \begin_inset Text
1732
1733 \begin_layout Standard
1734
1735 \emph on
1736 $EXEC_PREFIX
1737 \emph default
1738
1739 \backslash
1740 bin
1741 \end_layout
1742
1743 \end_inset
1744 </cell>
1745 </row>
1746 <row topline="true">
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1748 \begin_inset Text
1749
1750 \begin_layout Standard
1751
1752 \emph on
1753 DATADIR
1754 \end_layout
1755
1756 \end_inset
1757 </cell>
1758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1759 \begin_inset Text
1760
1761 \begin_layout Standard
1762
1763 \emph on
1764 $DATAROOTDIR
1765 \end_layout
1766
1767 \end_inset
1768 </cell>
1769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1770 \begin_inset Text
1771
1772 \begin_layout Standard
1773
1774 \emph on
1775 $DATAROOTDIR
1776 \end_layout
1777
1778 \end_inset
1779 </cell>
1780 </row>
1781 <row topline="true">
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 \begin_inset Text
1784
1785 \begin_layout Standard
1786
1787 \emph on
1788 DATAROOTDIR
1789 \end_layout
1790
1791 \end_inset
1792 </cell>
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1794 \begin_inset Text
1795
1796 \begin_layout Standard
1797
1798 \emph on
1799 $PREFIX
1800 \emph default
1801 /share
1802 \end_layout
1803
1804 \end_inset
1805 </cell>
1806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1807 \begin_inset Text
1808
1809 \begin_layout Standard
1810
1811 \emph on
1812 $PREFIX
1813 \end_layout
1814
1815 \end_inset
1816 </cell>
1817 </row>
1818 <row topline="true">
1819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1820 \begin_inset Text
1821
1822 \begin_layout Standard
1823
1824 \emph on
1825 DOCDIR
1826 \end_layout
1827
1828 \end_inset
1829 </cell>
1830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1831 \begin_inset Text
1832
1833 \begin_layout Standard
1834
1835 \emph on
1836 $DATAROOTDIR
1837 \emph default
1838 /sdcc/doc
1839 \end_layout
1840
1841 \end_inset
1842 </cell>
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1844 \begin_inset Text
1845
1846 \begin_layout Standard
1847
1848 \emph on
1849 $DATAROOTDIR
1850 \emph default
1851
1852 \backslash
1853 doc
1854 \end_layout
1855
1856 \end_inset
1857 </cell>
1858 </row>
1859 <row topline="true">
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1861 \begin_inset Text
1862
1863 \begin_layout Standard
1864
1865 \emph on
1866 INCLUDE_DIR_SUFFIX
1867 \end_layout
1868
1869 \end_inset
1870 </cell>
1871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1872 \begin_inset Text
1873
1874 \begin_layout Standard
1875 sdcc/include
1876 \end_layout
1877
1878 \end_inset
1879 </cell>
1880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1881 \begin_inset Text
1882
1883 \begin_layout Standard
1884 include
1885 \end_layout
1886
1887 \end_inset
1888 </cell>
1889 </row>
1890 <row topline="true" bottomline="true">
1891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1892 \begin_inset Text
1893
1894 \begin_layout Standard
1895
1896 \emph on
1897 LIB_DIR_SUFFIX
1898 \end_layout
1899
1900 \end_inset
1901 </cell>
1902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1903 \begin_inset Text
1904
1905 \begin_layout Standard
1906 sdcc/lib
1907 \end_layout
1908
1909 \end_inset
1910 </cell>
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1912 \begin_inset Text
1913
1914 \begin_layout Standard
1915 lib
1916 \end_layout
1917
1918 \end_inset
1919 </cell>
1920 </row>
1921 </lyxtabular>
1922
1923 \end_inset
1924
1925
1926 \newline
1927
1928 \end_layout
1929
1930 \begin_layout Standard
1931 \noindent
1932 'configure' also computes relative paths.
1933  This is needed for full relocatability of a binary package and to complete
1934  search paths (see section search paths below):
1935 \newline
1936  
1937 \end_layout
1938
1939 \begin_layout Standard
1940 \align center
1941 \begin_inset Tabular
1942 <lyxtabular version="3" rows="4" columns="3">
1943 <features>
1944 <column alignment="block" valignment="top" leftline="true" width="0in">
1945 <column alignment="block" valignment="top" leftline="true" width="0in">
1946 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1947 <row topline="true" bottomline="true">
1948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1949 \begin_inset Text
1950
1951 \begin_layout Standard
1952 Variable (computed)
1953 \end_layout
1954
1955 \end_inset
1956 </cell>
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1958 \begin_inset Text
1959
1960 \begin_layout Standard
1961 default
1962 \end_layout
1963
1964 \end_inset
1965 </cell>
1966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1967 \begin_inset Text
1968
1969 \begin_layout Standard
1970 Win32 builds
1971 \end_layout
1972
1973 \end_inset
1974 </cell>
1975 </row>
1976 <row topline="true" bottomline="true">
1977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1978 \begin_inset Text
1979
1980 \begin_layout Standard
1981
1982 \emph on
1983 BIN2DATA_DIR
1984 \end_layout
1985
1986 \end_inset
1987 </cell>
1988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1989 \begin_inset Text
1990
1991 \begin_layout Standard
1992 ../share
1993 \end_layout
1994
1995 \end_inset
1996 </cell>
1997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1998 \begin_inset Text
1999
2000 \begin_layout Standard
2001 ..
2002 \end_layout
2003
2004 \end_inset
2005 </cell>
2006 </row>
2007 <row bottomline="true">
2008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2009 \begin_inset Text
2010
2011 \begin_layout Standard
2012
2013 \emph on
2014 PREFIX2BIN_DIR
2015 \end_layout
2016
2017 \end_inset
2018 </cell>
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2020 \begin_inset Text
2021
2022 \begin_layout Standard
2023 bin
2024 \end_layout
2025
2026 \end_inset
2027 </cell>
2028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2029 \begin_inset Text
2030
2031 \begin_layout Standard
2032 bin
2033 \end_layout
2034
2035 \end_inset
2036 </cell>
2037 </row>
2038 <row bottomline="true">
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2040 \begin_inset Text
2041
2042 \begin_layout Standard
2043
2044 \emph on
2045 PREFIX2DATA_DIR
2046 \end_layout
2047
2048 \end_inset
2049 </cell>
2050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2051 \begin_inset Text
2052
2053 \begin_layout Standard
2054 share/sdcc
2055 \end_layout
2056
2057 \end_inset
2058 </cell>
2059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2060 \begin_inset Text
2061
2062 \begin_layout Standard
2063
2064 \end_layout
2065
2066 \end_inset
2067 </cell>
2068 </row>
2069 </lyxtabular>
2070
2071 \end_inset
2072
2073
2074 \newline
2075
2076 \end_layout
2077
2078 \begin_layout Standard
2079 \noindent
2080 Examples:
2081 \end_layout
2082
2083 \begin_layout LyX-Code
2084 ./configure
2085 \newline
2086 ./configure -
2087 \begin_inset ERT
2088 status collapsed
2089
2090 \begin_layout Standard
2091
2092
2093 \backslash
2094 /
2095 \end_layout
2096
2097 \end_inset
2098
2099 -prefix=
2100 \begin_inset Quotes srd
2101 \end_inset
2102
2103 /usr/bin
2104 \begin_inset Quotes srd
2105 \end_inset
2106
2107  -
2108 \begin_inset ERT
2109 status collapsed
2110
2111 \begin_layout Standard
2112
2113
2114 \backslash
2115 /
2116 \end_layout
2117
2118 \end_inset
2119
2120 -datarootdir=
2121 \begin_inset Quotes srd
2122 \end_inset
2123
2124 /usr/share
2125 \begin_inset Quotes srd
2126 \end_inset
2127
2128
2129 \newline
2130 ./configure -
2131 \begin_inset ERT
2132 status collapsed
2133
2134 \begin_layout Standard
2135
2136
2137 \backslash
2138 /
2139 \end_layout
2140
2141 \end_inset
2142
2143 -disable-avr-port -
2144 \begin_inset ERT
2145 status collapsed
2146
2147 \begin_layout Standard
2148
2149
2150 \backslash
2151 /
2152 \end_layout
2153
2154 \end_inset
2155
2156 -disable-xa51-port
2157 \end_layout
2158
2159 \begin_layout Standard
2160 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2161 32'):
2162 \end_layout
2163
2164 \begin_layout LyX-Code
2165 ./configure 
2166 \backslash
2167
2168 \newline
2169 CC=
2170 \begin_inset Quotes srd
2171 \end_inset
2172
2173 i586-mingw32msvc-gcc
2174 \begin_inset Quotes srd
2175 \end_inset
2176
2177  CXX=
2178 \begin_inset Quotes srd
2179 \end_inset
2180
2181 i586-mingw32msvc-g++
2182 \begin_inset Quotes srd
2183 \end_inset
2184
2185  
2186 \backslash
2187  
2188 \newline
2189 RANLIB=
2190 \begin_inset Quotes srd
2191 \end_inset
2192
2193 i586-mingw32msvc-ranlib
2194 \begin_inset Quotes srd
2195 \end_inset
2196
2197  
2198 \backslash
2199
2200 \newline
2201 STRIP=
2202 \begin_inset Quotes srd
2203 \end_inset
2204
2205 i586-mingw32msvc-strip
2206 \begin_inset Quotes srd
2207 \end_inset
2208
2209  
2210 \backslash
2211
2212 \newline
2213 -
2214 \begin_inset ERT
2215 status collapsed
2216
2217 \begin_layout Standard
2218
2219
2220 \backslash
2221 /
2222 \end_layout
2223
2224 \end_inset
2225
2226 -prefix=
2227 \begin_inset Quotes srd
2228 \end_inset
2229
2230 /sdcc
2231 \begin_inset Quotes srd
2232 \end_inset
2233
2234  
2235 \backslash
2236
2237 \newline
2238 -
2239 \begin_inset ERT
2240 status collapsed
2241
2242 \begin_layout Standard
2243
2244
2245 \backslash
2246 /
2247 \end_layout
2248
2249 \end_inset
2250
2251 -datarootdir=
2252 \begin_inset Quotes srd
2253 \end_inset
2254
2255 /sdcc
2256 \begin_inset Quotes srd
2257 \end_inset
2258
2259  
2260 \backslash
2261
2262 \newline
2263 docdir=
2264 \begin_inset Quotes srd
2265 \end_inset
2266
2267
2268 \backslash
2269 ${datarootdir}/doc
2270 \begin_inset Quotes srd
2271 \end_inset
2272
2273  
2274 \backslash
2275
2276 \newline
2277 include_dir_suffix=
2278 \begin_inset Quotes srd
2279 \end_inset
2280
2281 include
2282 \begin_inset Quotes srd
2283 \end_inset
2284
2285  
2286 \backslash
2287
2288 \newline
2289 lib_dir_suffix=
2290 \begin_inset Quotes srd
2291 \end_inset
2292
2293 lib
2294 \begin_inset Quotes srd
2295 \end_inset
2296
2297  
2298 \backslash
2299
2300 \newline
2301 sdccconf_h_dir_separator=
2302 \begin_inset Quotes srd
2303 \end_inset
2304
2305
2306 \backslash
2307
2308 \backslash
2309
2310 \backslash
2311
2312 \backslash
2313
2314 \begin_inset Quotes srd
2315 \end_inset
2316
2317  
2318 \backslash
2319
2320 \newline
2321 -
2322 \begin_inset ERT
2323 status collapsed
2324
2325 \begin_layout Standard
2326
2327
2328 \backslash
2329 /
2330 \end_layout
2331
2332 \end_inset
2333
2334 -disable-device-lib
2335 \backslash
2336
2337 \newline
2338 -
2339 \begin_inset ERT
2340 status collapsed
2341
2342 \begin_layout Standard
2343
2344
2345 \backslash
2346 /
2347 \end_layout
2348
2349 \end_inset
2350
2351 -host=i586-mingw32msvc
2352 \backslash
2353
2354 \newline
2355 -
2356 \begin_inset ERT
2357 status collapsed
2358
2359 \begin_layout Standard
2360
2361
2362 \backslash
2363 /
2364 \end_layout
2365
2366 \end_inset
2367
2368 -build=unknown-unknown-linux-gnu
2369 \end_layout
2370
2371 \begin_layout Standard
2372 To 
2373 \begin_inset Quotes sld
2374 \end_inset
2375
2376 cross
2377 \begin_inset Quotes srd
2378 \end_inset
2379
2380 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2381 ):
2382 \end_layout
2383
2384 \begin_layout LyX-Code
2385 ./configure -C 
2386 \backslash
2387
2388 \newline
2389 -
2390 \begin_inset ERT
2391 status collapsed
2392
2393 \begin_layout Standard
2394
2395
2396 \backslash
2397 /
2398 \end_layout
2399
2400 \end_inset
2401
2402 -prefix=
2403 \begin_inset Quotes srd
2404 \end_inset
2405
2406 /sdcc
2407 \begin_inset Quotes srd
2408 \end_inset
2409
2410  
2411 \backslash
2412
2413 \newline
2414 -
2415 \begin_inset ERT
2416 status collapsed
2417
2418 \begin_layout Standard
2419
2420
2421 \backslash
2422 /
2423 \end_layout
2424
2425 \end_inset
2426
2427 -datarootdir=
2428 \begin_inset Quotes srd
2429 \end_inset
2430
2431 /sdcc
2432 \begin_inset Quotes srd
2433 \end_inset
2434
2435  
2436 \backslash
2437
2438 \newline
2439 docdir=
2440 \begin_inset Quotes srd
2441 \end_inset
2442
2443
2444 \backslash
2445 ${datarootdir}/doc
2446 \begin_inset Quotes srd
2447 \end_inset
2448
2449  
2450 \backslash
2451  
2452 \newline
2453 include_dir_suffix=
2454 \begin_inset Quotes srd
2455 \end_inset
2456
2457 include
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461  
2462 \backslash
2463
2464 \newline
2465 lib_dir_suffix=
2466 \begin_inset Quotes srd
2467 \end_inset
2468
2469 lib
2470 \begin_inset Quotes srd
2471 \end_inset
2472
2473  
2474 \backslash
2475
2476 \newline
2477 sdccconf_h_dir_separator=
2478 \begin_inset Quotes srd
2479 \end_inset
2480
2481
2482 \backslash
2483
2484 \backslash
2485
2486 \backslash
2487
2488 \backslash
2489
2490 \begin_inset Quotes srd
2491 \end_inset
2492
2493  
2494 \backslash
2495
2496 \newline
2497 CC=
2498 \begin_inset Quotes srd
2499 \end_inset
2500
2501 gcc -mno-cygwin
2502 \begin_inset Quotes srd
2503 \end_inset
2504
2505  
2506 \backslash
2507
2508 \newline
2509 CXX=
2510 \begin_inset Quotes srd
2511 \end_inset
2512
2513 g++ -mno-cygwin
2514 \begin_inset Quotes srd
2515 \end_inset
2516
2517  
2518 \end_layout
2519
2520 \begin_layout Standard
2521 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2522  The option '-
2523 \begin_inset ERT
2524 status collapsed
2525
2526 \begin_layout Standard
2527
2528
2529 \backslash
2530 /
2531 \end_layout
2532
2533 \end_inset
2534
2535 -C' turns on caching, which gives a little bit extra speed.
2536  However if options are changed, it can be necessary to delete the config.cache
2537  file.
2538 \end_layout
2539
2540 \begin_layout Section
2541 Install paths
2542 \begin_inset LatexCommand \label{sub:Install-paths}
2543
2544 \end_inset
2545
2546
2547 \begin_inset LatexCommand \index{Install paths}
2548
2549 \end_inset
2550
2551
2552 \end_layout
2553
2554 \begin_layout Standard
2555 \begin_inset VSpace medskip
2556 \end_inset
2557
2558
2559 \end_layout
2560
2561 \begin_layout Standard
2562 \align center
2563 \begin_inset Tabular
2564 <lyxtabular version="3" rows="5" columns="4">
2565 <features>
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" width="0">
2569 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2570 <row topline="true" bottomline="true">
2571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2572 \begin_inset Text
2573
2574 \begin_layout Standard
2575
2576 \series bold
2577 Description
2578 \end_layout
2579
2580 \end_inset
2581 </cell>
2582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2583 \begin_inset Text
2584
2585 \begin_layout Standard
2586
2587 \series bold
2588 Path
2589 \end_layout
2590
2591 \end_inset
2592 </cell>
2593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2594 \begin_inset Text
2595
2596 \begin_layout Standard
2597
2598 \series bold
2599 Default
2600 \end_layout
2601
2602 \end_inset
2603 </cell>
2604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2605 \begin_inset Text
2606
2607 \begin_layout Standard
2608
2609 \series bold
2610 Win32 builds
2611 \end_layout
2612
2613 \end_inset
2614 </cell>
2615 </row>
2616 <row topline="true">
2617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2618 \begin_inset Text
2619
2620 \begin_layout Standard
2621 Binary files*
2622 \end_layout
2623
2624 \end_inset
2625 </cell>
2626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2627 \begin_inset Text
2628
2629 \begin_layout Standard
2630
2631 \emph on
2632 $EXEC_PREFIX
2633 \end_layout
2634
2635 \end_inset
2636 </cell>
2637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2638 \begin_inset Text
2639
2640 \begin_layout Standard
2641 /usr/local/bin
2642 \end_layout
2643
2644 \end_inset
2645 </cell>
2646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2647 \begin_inset Text
2648
2649 \begin_layout Standard
2650
2651 \backslash
2652 sdcc
2653 \backslash
2654 bin
2655 \end_layout
2656
2657 \end_inset
2658 </cell>
2659 </row>
2660 <row topline="true">
2661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2662 \begin_inset Text
2663
2664 \begin_layout Standard
2665 Include files
2666 \end_layout
2667
2668 \end_inset
2669 </cell>
2670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2671 \begin_inset Text
2672
2673 \begin_layout Standard
2674
2675 \emph on
2676 $DATADIR/ $INCLUDE_DIR_SUFFIX
2677 \end_layout
2678
2679 \end_inset
2680 </cell>
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 \begin_inset Text
2683
2684 \begin_layout Standard
2685 /usr/local/share/sdcc/include
2686 \end_layout
2687
2688 \end_inset
2689 </cell>
2690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2691 \begin_inset Text
2692
2693 \begin_layout Standard
2694
2695 \backslash
2696 sdcc
2697 \backslash
2698 include
2699 \end_layout
2700
2701 \end_inset
2702 </cell>
2703 </row>
2704 <row topline="true">
2705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2706 \begin_inset Text
2707
2708 \begin_layout Standard
2709 Library file**
2710 \end_layout
2711
2712 \end_inset
2713 </cell>
2714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2715 \begin_inset Text
2716
2717 \begin_layout Standard
2718
2719 \emph on
2720 $DATADIR/$LIB_DIR_SUFFIX
2721 \end_layout
2722
2723 \end_inset
2724 </cell>
2725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2726 \begin_inset Text
2727
2728 \begin_layout Standard
2729 /usr/local/share/sdcc/lib
2730 \end_layout
2731
2732 \end_inset
2733 </cell>
2734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2735 \begin_inset Text
2736
2737 \begin_layout Standard
2738
2739 \backslash
2740 sdcc
2741 \backslash
2742 lib
2743 \end_layout
2744
2745 \end_inset
2746 </cell>
2747 </row>
2748 <row topline="true" bottomline="true">
2749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2750 \begin_inset Text
2751
2752 \begin_layout Standard
2753 Documentation
2754 \end_layout
2755
2756 \end_inset
2757 </cell>
2758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2759 \begin_inset Text
2760
2761 \begin_layout Standard
2762
2763 \emph on
2764 $DOCDIR
2765 \end_layout
2766
2767 \end_inset
2768 </cell>
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2770 \begin_inset Text
2771
2772 \begin_layout Standard
2773 /usr/local/share/sdcc/doc
2774 \end_layout
2775
2776 \end_inset
2777 </cell>
2778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2779 \begin_inset Text
2780
2781 \begin_layout Standard
2782
2783 \backslash
2784 sdcc
2785 \backslash
2786 doc
2787 \end_layout
2788
2789 \end_inset
2790 </cell>
2791 </row>
2792 </lyxtabular>
2793
2794 \end_inset
2795
2796
2797 \end_layout
2798
2799 \begin_layout Verse
2800
2801 \size footnotesize
2802 *compiler, preprocessor, assembler, and linker
2803 \newline
2804 **the 
2805 \shape italic
2806 model
2807 \shape default
2808  is auto-appended by the compiler, e.g.
2809  small, large, z80, ds390 etc
2810 \end_layout
2811
2812 \begin_layout Standard
2813 \noindent
2814 The install paths can still be changed during `make install` with e.g.:
2815 \end_layout
2816
2817 \begin_layout LyX-Code
2818 make install prefix=$(HOME)/local/sdcc
2819 \end_layout
2820
2821 \begin_layout Standard
2822 Of course this doesn't change the search paths compiled into the binaries.
2823 \newline
2824
2825 \newline
2826 Moreove
2827 r the install path can be changed by defining DESTDIR
2828 \begin_inset LatexCommand \index{DESTDIR}
2829
2830 \end_inset
2831
2832 :
2833 \end_layout
2834
2835 \begin_layout LyX-Code
2836 make install DESTDIR=$(HOME)/sdcc.rpm/
2837 \end_layout
2838
2839 \begin_layout Standard
2840 Please note that DESTDIR must have a trailing slash!
2841 \end_layout
2842
2843 \begin_layout Section
2844 Search Paths
2845 \begin_inset LatexCommand \label{sub:Search-Paths}
2846
2847 \end_inset
2848
2849
2850 \begin_inset LatexCommand \index{Search path}
2851
2852 \end_inset
2853
2854
2855 \end_layout
2856
2857 \begin_layout Standard
2858 Some search paths or parts of them are determined by configure variables
2859  (in 
2860 \emph on
2861 italics
2862 \emph default
2863 , see section above).
2864  Further search paths are determined by environment variables during runtime.
2865  
2866 \newline
2867 The paths searched when running the compiler are as follows (the first
2868  catch wins):
2869 \newline
2870
2871 \newline
2872 1.
2873  Binary files (preprocessor, assembler and linker)
2874 \newline
2875
2876 \end_layout
2877
2878 \begin_layout Standard
2879 \align center
2880 \begin_inset Tabular
2881 <lyxtabular version="3" rows="4" columns="3">
2882 <features>
2883 <column alignment="block" valignment="top" leftline="true" width="0in">
2884 <column alignment="block" valignment="top" leftline="true" width="0in">
2885 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2886 <row topline="true" bottomline="true">
2887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2888 \begin_inset Text
2889
2890 \begin_layout Standard
2891 Search path
2892 \end_layout
2893
2894 \end_inset
2895 </cell>
2896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2897 \begin_inset Text
2898
2899 \begin_layout Standard
2900 default
2901 \end_layout
2902
2903 \end_inset
2904 </cell>
2905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2906 \begin_inset Text
2907
2908 \begin_layout Standard
2909 Win32 builds
2910 \end_layout
2911
2912 \end_inset
2913 </cell>
2914 </row>
2915 <row topline="true">
2916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2917 \begin_inset Text
2918
2919 \begin_layout Standard
2920 $SDCC_HOME/
2921 \emph on
2922 $PPREFIX2BIN_DIR
2923 \end_layout
2924
2925 \end_inset
2926 </cell>
2927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2928 \begin_inset Text
2929
2930 \begin_layout Standard
2931 $SDCC_HOME/bin
2932 \end_layout
2933
2934 \end_inset
2935 </cell>
2936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2937 \begin_inset Text
2938
2939 \begin_layout Standard
2940 $SDCC_HOME
2941 \backslash
2942 bin
2943 \end_layout
2944
2945 \end_inset
2946 </cell>
2947 </row>
2948 <row topline="true">
2949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2950 \begin_inset Text
2951
2952 \begin_layout Standard
2953 Path of argv[0] (if available)
2954 \end_layout
2955
2956 \end_inset
2957 </cell>
2958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2959 \begin_inset Text
2960
2961 \begin_layout Standard
2962 Path of argv[0]
2963 \end_layout
2964
2965 \end_inset
2966 </cell>
2967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2968 \begin_inset Text
2969
2970 \begin_layout Standard
2971 Path of argv[0]
2972 \end_layout
2973
2974 \end_inset
2975 </cell>
2976 </row>
2977 <row topline="true" bottomline="true">
2978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2979 \begin_inset Text
2980
2981 \begin_layout Standard
2982 $PATH
2983 \end_layout
2984
2985 \end_inset
2986 </cell>
2987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2988 \begin_inset Text
2989
2990 \begin_layout Standard
2991 $PATH
2992 \end_layout
2993
2994 \end_inset
2995 </cell>
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2997 \begin_inset Text
2998
2999 \begin_layout Standard
3000 $PATH
3001 \end_layout
3002
3003 \end_inset
3004 </cell>
3005 </row>
3006 </lyxtabular>
3007
3008 \end_inset
3009
3010  
3011 \newline
3012
3013 \end_layout
3014
3015 \begin_layout Standard
3016 \noindent
3017 2.
3018  Include files
3019 \newline
3020
3021 \end_layout
3022
3023 \begin_layout Standard
3024 \align center
3025 \begin_inset Tabular
3026 <lyxtabular version="3" rows="6" columns="3">
3027 <features>
3028 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3029 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3030 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3031 <row topline="true" bottomline="true">
3032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3033 \begin_inset Text
3034
3035 \begin_layout Standard
3036 Search path
3037 \end_layout
3038
3039 \end_inset
3040 </cell>
3041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3042 \begin_inset Text
3043
3044 \begin_layout Standard
3045 default
3046 \end_layout
3047
3048 \end_inset
3049 </cell>
3050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3051 \begin_inset Text
3052
3053 \begin_layout Standard
3054 Win32 builds
3055 \end_layout
3056
3057 \end_inset
3058 </cell>
3059 </row>
3060 <row topline="true">
3061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3062 \begin_inset Text
3063
3064 \begin_layout Standard
3065 -
3066 \begin_inset ERT
3067 status collapsed
3068
3069 \begin_layout Standard
3070
3071
3072 \backslash
3073 /
3074 \end_layout
3075
3076 \end_inset
3077
3078 -I dir
3079 \end_layout
3080
3081 \end_inset
3082 </cell>
3083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3084 \begin_inset Text
3085
3086 \begin_layout Standard
3087 -
3088 \begin_inset ERT
3089 status collapsed
3090
3091 \begin_layout Standard
3092
3093
3094 \backslash
3095 /
3096 \end_layout
3097
3098 \end_inset
3099
3100 -I dir
3101 \end_layout
3102
3103 \end_inset
3104 </cell>
3105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3106 \begin_inset Text
3107
3108 \begin_layout Standard
3109 -
3110 \begin_inset ERT
3111 status collapsed
3112
3113 \begin_layout Standard
3114
3115
3116 \backslash
3117 /
3118 \end_layout
3119
3120 \end_inset
3121
3122 -I dir
3123 \end_layout
3124
3125 \end_inset
3126 </cell>
3127 </row>
3128 <row topline="true">
3129 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3130 \begin_inset Text
3131
3132 \begin_layout Standard
3133 $SDCC_INCLUDE
3134 \end_layout
3135
3136 \end_inset
3137 </cell>
3138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3139 \begin_inset Text
3140
3141 \begin_layout Standard
3142 $SDCC_INCLUDE
3143 \end_layout
3144
3145 \end_inset
3146 </cell>
3147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3148 \begin_inset Text
3149
3150 \begin_layout Standard
3151 $SDCC_INCLUDE
3152 \end_layout
3153
3154 \end_inset
3155 </cell>
3156 </row>
3157 <row topline="true">
3158 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3159 \begin_inset Text
3160
3161 \begin_layout Standard
3162 $SDCC_HOME/
3163 \newline
3164
3165 \emph on
3166 $PREFIX2DATA_DIR/
3167 \newline
3168 $INCLUDE_DIR_SUFFIX
3169 \end_layout
3170
3171 \end_inset
3172 </cell>
3173 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3174 \begin_inset Text
3175
3176 \begin_layout Standard
3177 $SDCC_ HOME/
3178 \newline
3179 share/sdcc/
3180 \newline
3181 include
3182 \end_layout
3183
3184 \end_inset
3185 </cell>
3186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3187 \begin_inset Text
3188
3189 \begin_layout Standard
3190 $SDCC_HOME
3191 \backslash
3192 include
3193 \end_layout
3194
3195 \end_inset
3196 </cell>
3197 </row>
3198 <row topline="true">
3199 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3200 \begin_inset Text
3201
3202 \begin_layout Standard
3203 path(argv[0])/
3204 \newline
3205
3206 \emph on
3207 $BIN2DATADIR/
3208 \emph default
3209
3210 \newline
3211
3212 \emph on
3213 $INCLUDE_DIR_SUFFIX
3214 \end_layout
3215
3216 \end_inset
3217 </cell>
3218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3219 \begin_inset Text
3220
3221 \begin_layout Standard
3222 path(argv[0])/
3223 \newline
3224 ../sdcc/include
3225 \newline
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 \InsetSpace ~
3264
3265 \end_layout
3266
3267 \end_inset
3268 </cell>
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3270 \begin_inset Text
3271
3272 \begin_layout Standard
3273 path(argv[0])
3274 \backslash
3275 ..
3276 \backslash
3277 include
3278 \end_layout
3279
3280 \end_inset
3281 </cell>
3282 </row>
3283 <row topline="true" bottomline="true">
3284 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3285 \begin_inset Text
3286
3287 \begin_layout Standard
3288
3289 \emph on
3290 $DATADIR/
3291 \emph default
3292
3293 \newline
3294
3295 \emph on
3296 $INCLUDE_DIR_SUFFIX
3297 \end_layout
3298
3299 \end_inset
3300 </cell>
3301 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3302 \begin_inset Text
3303
3304 \begin_layout Standard
3305 /usr/local/share/sdcc/
3306 \newline
3307 include
3308 \end_layout
3309
3310 \end_inset
3311 </cell>
3312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3313 \begin_inset Text
3314
3315 \begin_layout Standard
3316 (not on Win32)
3317 \end_layout
3318
3319 \end_inset
3320 </cell>
3321 </row>
3322 </lyxtabular>
3323
3324 \end_inset
3325
3326  
3327 \newline
3328
3329 \end_layout
3330
3331 \begin_layout Standard
3332 \noindent
3333 The option -
3334 \begin_inset ERT
3335 status collapsed
3336
3337 \begin_layout Standard
3338
3339
3340 \backslash
3341 /
3342 \end_layout
3343
3344 \end_inset
3345
3346 -nostdinc disables the last two search paths.
3347 \newline
3348
3349 \newline
3350 3.
3351  Library files 
3352 \newline
3353
3354 \end_layout
3355
3356 \begin_layout Standard
3357 With the exception of 
3358 \begin_inset Quotes sld
3359 \end_inset
3360
3361 -
3362 \begin_inset ERT
3363 status collapsed
3364
3365 \begin_layout Standard
3366
3367
3368 \backslash
3369 /
3370 \end_layout
3371
3372 \end_inset
3373
3374 -L dir
3375 \begin_inset Quotes srd
3376 \end_inset
3377
3378  the 
3379 \shape italic
3380 model
3381 \shape default
3382  is auto-appended by the compiler (e.g.
3383  small, large, z80, ds390 etc.).
3384  
3385 \newline
3386
3387 \end_layout
3388
3389 \begin_layout Standard
3390 \align center
3391 \begin_inset Tabular
3392 <lyxtabular version="3" rows="6" columns="3">
3393 <features>
3394 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3395 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3396 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3397 <row topline="true" bottomline="true">
3398 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3399 \begin_inset Text
3400
3401 \begin_layout Standard
3402 Search path
3403 \end_layout
3404
3405 \end_inset
3406 </cell>
3407 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3408 \begin_inset Text
3409
3410 \begin_layout Standard
3411 default
3412 \end_layout
3413
3414 \end_inset
3415 </cell>
3416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3417 \begin_inset Text
3418
3419 \begin_layout Standard
3420 Win32 builds
3421 \end_layout
3422
3423 \end_inset
3424 </cell>
3425 </row>
3426 <row topline="true">
3427 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3428 \begin_inset Text
3429
3430 \begin_layout Standard
3431 -
3432 \begin_inset ERT
3433 status collapsed
3434
3435 \begin_layout Standard
3436
3437
3438 \backslash
3439 /
3440 \end_layout
3441
3442 \end_inset
3443
3444 -L dir
3445 \end_layout
3446
3447 \end_inset
3448 </cell>
3449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3450 \begin_inset Text
3451
3452 \begin_layout Standard
3453 -
3454 \begin_inset ERT
3455 status collapsed
3456
3457 \begin_layout Standard
3458
3459
3460 \backslash
3461 /
3462 \end_layout
3463
3464 \end_inset
3465
3466 -L dir
3467 \end_layout
3468
3469 \end_inset
3470 </cell>
3471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3472 \begin_inset Text
3473
3474 \begin_layout Standard
3475 -
3476 \begin_inset ERT
3477 status collapsed
3478
3479 \begin_layout Standard
3480
3481
3482 \backslash
3483 /
3484 \end_layout
3485
3486 \end_inset
3487
3488 -L dir
3489 \end_layout
3490
3491 \end_inset
3492 </cell>
3493 </row>
3494 <row topline="true">
3495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3496 \begin_inset Text
3497
3498 \begin_layout Standard
3499 $SDCC_LIB/
3500 \newline
3501
3502 \emph on
3503 <model>
3504 \end_layout
3505
3506 \end_inset
3507 </cell>
3508 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3509 \begin_inset Text
3510
3511 \begin_layout Standard
3512 $SDCC_LIB/
3513 \newline
3514
3515 \emph on
3516 <model>
3517 \end_layout
3518
3519 \end_inset
3520 </cell>
3521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3522 \begin_inset Text
3523
3524 \begin_layout Standard
3525 $SDCC_LIB
3526 \backslash
3527
3528 \newline
3529
3530 \emph on
3531 <model>
3532 \end_layout
3533
3534 \end_inset
3535 </cell>
3536 </row>
3537 <row topline="true">
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3539 \begin_inset Text
3540
3541 \begin_layout Standard
3542 $SDCC_HOME/
3543 \newline
3544
3545 \emph on
3546 $PREFIX2DATA_DIR/
3547 \newline
3548 $LIB_DIR_SUFFIX/<model>
3549 \end_layout
3550
3551 \end_inset
3552 </cell>
3553 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3554 \begin_inset Text
3555
3556 \begin_layout Standard
3557 $SDCC_HOME/
3558 \newline
3559 share/sdcc/
3560 \newline
3561 lib/
3562 \emph on
3563 <model>
3564 \end_layout
3565
3566 \end_inset
3567 </cell>
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3569 \begin_inset Text
3570
3571 \begin_layout Standard
3572 $SDCC_HOME
3573 \backslash
3574 lib
3575 \backslash
3576
3577 \emph on
3578
3579 \newline
3580 <model>
3581 \end_layout
3582
3583 \end_inset
3584 </cell>
3585 </row>
3586 <row topline="true">
3587 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3588 \begin_inset Text
3589
3590 \begin_layout Standard
3591 path(argv[0])/
3592 \newline
3593
3594 \emph on
3595 $BIN2DATADIR/
3596 \emph default
3597
3598 \newline
3599
3600 \emph on
3601 $LIB_DIR_SUFFIX/<model>
3602 \end_layout
3603
3604 \end_inset
3605 </cell>
3606 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3607 \begin_inset Text
3608
3609 \begin_layout Standard
3610 path(argv[0])/
3611 \newline
3612 ../sdcc/lib/
3613 \emph on
3614 <model>
3615 \newline
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 \InsetSpace ~
3655
3656 \end_layout
3657
3658 \end_inset
3659 </cell>
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3661 \begin_inset Text
3662
3663 \begin_layout Standard
3664 path(argv[0])
3665 \backslash
3666
3667 \newline
3668 ..
3669 \backslash
3670 lib
3671 \backslash
3672
3673 \emph on
3674 <model>
3675 \newline
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 \InsetSpace ~
3711
3712 \end_layout
3713
3714 \end_inset
3715 </cell>
3716 </row>
3717 <row topline="true" bottomline="true">
3718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3719 \begin_inset Text
3720
3721 \begin_layout Standard
3722
3723 \emph on
3724 $DATADIR/
3725 \newline
3726 $LIB_DIR_SUFFIX/<model>
3727 \end_layout
3728
3729 \end_inset
3730 </cell>
3731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3732 \begin_inset Text
3733
3734 \begin_layout Standard
3735 /usr/local/share/sdcc/
3736 \newline
3737 lib/
3738 \emph on
3739 <model>
3740 \end_layout
3741
3742 \end_inset
3743 </cell>
3744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3745 \begin_inset Text
3746
3747 \begin_layout Standard
3748 (not on Win32)
3749 \end_layout
3750
3751 \end_inset
3752 </cell>
3753 </row>
3754 </lyxtabular>
3755
3756 \end_inset
3757
3758
3759 \newline
3760
3761 \end_layout
3762
3763 \begin_layout Standard
3764 \begin_inset Note Note
3765 status collapsed
3766
3767 \begin_layout Standard
3768 Don't delete any of the stray spaces in the table above without checking
3769  the HTML output (last line)!
3770 \end_layout
3771
3772 \end_inset
3773
3774
3775 \end_layout
3776
3777 \begin_layout Standard
3778 \InsetSpace ~
3779
3780 \newline
3781 The option -
3782 \begin_inset ERT
3783 status collapsed
3784
3785 \begin_layout Standard
3786
3787
3788 \backslash
3789 /
3790 \end_layout
3791
3792 \end_inset
3793
3794 -nostdlib disables the last two search paths.
3795 \end_layout
3796
3797 \begin_layout Section
3798 Building SDCC
3799 \begin_inset LatexCommand \index{Building SDCC}
3800
3801 \end_inset
3802
3803
3804 \end_layout
3805
3806 \begin_layout Subsection
3807 Building SDCC on Linux
3808 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3809
3810 \end_inset
3811
3812
3813 \end_layout
3814
3815 \begin_layout Enumerate
3816
3817 \series medium
3818 Download the source package
3819 \series default
3820  either from the SDCC Subversion repository or from snapshot builds
3821 \series medium
3822 , it will be named something like sdcc
3823 \series default
3824 -src
3825 \series medium
3826 -yyyymmdd-rrrr.t
3827 \series default
3828 ar.
3829 \series medium
3830 bz2
3831 \series default
3832  
3833 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3834
3835 \end_inset
3836
3837 .
3838 \end_layout
3839
3840 \begin_layout Enumerate
3841
3842 \series medium
3843 Bring up a command line terminal, such as xterm.
3844 \end_layout
3845
3846 \begin_layout Enumerate
3847
3848 \series medium
3849 Unpack the file using a command like: 
3850 \family sans
3851 \series bold
3852 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3853 \begin_inset Quotes srd
3854 \end_inset
3855
3856
3857 \family default
3858 \series medium
3859 , this will create a sub-directory called sdcc with all of the sources.
3860 \end_layout
3861
3862 \begin_layout Enumerate
3863 Change directory into the main SDCC directory, for example type: 
3864 \family sans
3865 \series bold
3866 "cd sdcc
3867 \series default
3868 ".
3869 \end_layout
3870
3871 \begin_layout Enumerate
3872
3873 \series medium
3874 Type 
3875 \family sans
3876 \series bold
3877 "./configure
3878 \family default
3879 \series default
3880 ".
3881  This configures the package for compilation on your system.
3882 \end_layout
3883
3884 \begin_layout Enumerate
3885
3886 \series medium
3887 Type 
3888 \family sans
3889 \series bold
3890 "make
3891 \family default
3892 \series default
3893 "
3894 \series medium
3895 .
3896
3897 \series default
3898  All of the source packages will compile, this can take a while.
3899 \end_layout
3900
3901 \begin_layout Enumerate
3902
3903 \series medium
3904 Type 
3905 \family sans
3906 \series bold
3907 "make install"
3908 \family default
3909 \series default
3910  as root
3911 \series medium
3912 .
3913
3914 \series default
3915  This copies the binary executables, the include files, the libraries and
3916  the documentation to the install directories.
3917  Proceed with section 
3918 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3919
3920 \end_inset
3921
3922 .
3923 \end_layout
3924
3925 \begin_layout Subsection
3926 Building SDCC on Mac OS X
3927 \end_layout
3928
3929 \begin_layout Standard
3930 Follow the instruction for Linux.
3931 \newline
3932
3933 \newline
3934 On Mac OS X 10.2.x it was reported, that the
3935  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3936  Fortunately there's also gcc 2.9.x installed, which works fine.
3937  This compiler can be selected by running 'configure' with:
3938 \end_layout
3939
3940 \begin_layout LyX-Code
3941 ./configure CC=gcc2 CXX=g++2
3942 \end_layout
3943
3944 \begin_layout Subsection
3945 Cross compiling SDCC on Linux for Windows
3946 \end_layout
3947
3948 \begin_layout Standard
3949 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3950  See section 'Configure Options'.
3951 \end_layout
3952
3953 \begin_layout Subsection
3954 Building SDCC using Cygwin and Mingw32
3955 \end_layout
3956
3957 \begin_layout Standard
3958 For building and installing a Cygwin executable follow the instructions
3959  for Linux.
3960 \newline
3961
3962 \newline
3963 On Cygwin a 
3964 \begin_inset Quotes sld
3965 \end_inset
3966
3967 native
3968 \begin_inset Quotes srd
3969 \end_inset
3970
3971  Win32-binary can be built, which will not need the Cygwin-DLL.
3972  For the necessary 'configure' options see section 'configure options' or
3973  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3974 \newline
3975
3976 \newline
3977 In order to install
3978  Cygwin on Windows download setup.exe from 
3979 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3980
3981 \end_inset
3982
3983 .
3984  Run it, set the 
3985 \begin_inset Quotes sld
3986 \end_inset
3987
3988 default text file type
3989 \begin_inset Quotes srd
3990 \end_inset
3991
3992  to 
3993 \begin_inset Quotes sld
3994 \end_inset
3995
3996 unix
3997 \begin_inset Quotes srd
3998 \end_inset
3999
4000  and download/install at least the following packages.
4001  Some packages are selected by default, others will be automatically selected
4002  because of dependencies with the manually selected packages.
4003  Never deselect these packages!
4004 \end_layout
4005
4006 \begin_layout Itemize
4007 flex
4008 \end_layout
4009
4010 \begin_layout Itemize
4011 bison
4012 \end_layout
4013
4014 \begin_layout Itemize
4015 gcc ; version 3.x is fine, no need to use the old 2.9x
4016 \end_layout
4017
4018 \begin_layout Itemize
4019 binutils ; selected with gcc
4020 \end_layout
4021
4022 \begin_layout Itemize
4023 make
4024 \end_layout
4025
4026 \begin_layout Itemize
4027 rxvt ; a nice console, which makes life much easier under windoze (see below)
4028 \end_layout
4029
4030 \begin_layout Itemize
4031 man ; not really needed for building SDCC, but you'll miss it sooner or
4032  later
4033 \end_layout
4034
4035 \begin_layout Itemize
4036 less ; not really needed for building SDCC, but you'll miss it sooner or
4037  later
4038 \end_layout
4039
4040 \begin_layout Itemize
4041 svn ; only if you use Subversion access
4042 \end_layout
4043
4044 \begin_layout Standard
4045 If you want to develop something you'll need:
4046 \end_layout
4047
4048 \begin_layout Itemize
4049 python ; for the regression tests
4050 \end_layout
4051
4052 \begin_layout Itemize
4053 gdb ; the gnu debugger, together with the nice GUI 
4054 \begin_inset Quotes sld
4055 \end_inset
4056
4057 insight
4058 \begin_inset Quotes srd
4059 \end_inset
4060
4061
4062 \end_layout
4063
4064 \begin_layout Itemize
4065 openssh ; to access the CF or commit changes
4066 \end_layout
4067
4068 \begin_layout Itemize
4069 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4070  use autoconf-stable!
4071 \end_layout
4072
4073 \begin_layout Standard
4074 rxvt is a nice console with history.
4075  Replace in your cygwin.bat the line
4076 \end_layout
4077
4078 \begin_layout LyX-Code
4079 bash -
4080 \begin_inset ERT
4081 status collapsed
4082
4083 \begin_layout Standard
4084
4085
4086 \backslash
4087 /
4088 \end_layout
4089
4090 \end_inset
4091
4092 -login -i 
4093 \end_layout
4094
4095 \begin_layout Standard
4096 with (one line):
4097 \end_layout
4098
4099 \begin_layout LyX-Code
4100 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4101 \end_layout
4102
4103 \begin_layout LyX-Code
4104      -bg black -fg white -geometry 100x65 -e bash -
4105 \begin_inset ERT
4106 status collapsed
4107
4108 \begin_layout Standard
4109
4110
4111 \backslash
4112 /
4113 \end_layout
4114
4115 \end_inset
4116
4117 -login
4118 \end_layout
4119
4120 \begin_layout Standard
4121 Text selected with the mouse is automatically copied to the clipboard, pasting
4122  works with shift-insert.
4123 \newline
4124
4125 \newline
4126 The other good tip is to make sure you have no //c/-styl
4127 e paths anywhere, use /cygdrive/c/ instead.
4128  Using // invokes a network lookup which is very slow.
4129  If you think 
4130 \begin_inset Quotes sld
4131 \end_inset
4132
4133 cygdrive
4134 \begin_inset Quotes srd
4135 \end_inset
4136
4137  is too long, you can change it with e.g.
4138 \end_layout
4139
4140 \begin_layout LyX-Code
4141 mount -s -u -c /mnt
4142 \end_layout
4143
4144 \begin_layout Standard
4145 SDCC sources use the unix line ending LF.
4146  Life is much easier, if you store the source tree on a drive which is mounted
4147  in binary mode.
4148  And use an editor which can handle LF-only line endings.
4149  Make sure not to commit files with windows line endings.
4150  The tabulator spacing
4151 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4152
4153 \end_inset
4154
4155  used in the project is 8.
4156  Although a tabulator spacing of 8 is a sensible choice for programmers
4157  (it's a power of 2 and allows to display 8/16 bit signed variables without
4158  loosing columns) the plan is to move towards using only spaces in the source.
4159 \end_layout
4160
4161 \begin_layout Subsection
4162 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4163 \end_layout
4164
4165 \begin_layout Standard
4166
4167 \series medium
4168 Download the source package
4169 \series default
4170  either from the SDCC Subversion repository or from the 
4171 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4172
4173 \end_inset
4174
4175
4176 \series medium
4177 , it will be named something like sdcc
4178 \series default
4179 -src
4180 \series medium
4181 -yyyymmdd-rrrr.tar.bz2.
4182
4183 \series default
4184  SDCC is distributed with all the projects, workspaces, and files you need
4185  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4186  The workspace name is 'sdcc.dsw'.
4187  Please note that as it is now, all the executables are created in a folder
4188  called sdcc
4189 \backslash
4190 bin_vc.
4191  Once built you need to copy the executables from sdcc
4192 \backslash
4193 bin_vc to sdcc
4194 \backslash
4195 bin before running SDCC.
4196  
4197 \newline
4198
4199 \newline
4200 WARNING: Visual studio is very picky with line terminations; it expects
4201  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4202  When using the Subversion repository it's easiest to configure the svn
4203  client to convert automatically for you.
4204  If however you are getting a message such as "This makefile was not generated
4205  by Developer Studio etc.
4206  etc.
4207 \begin_inset Quotes srd
4208 \end_inset
4209
4210  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4211  need to convert the Unix style line endings to DOS style line endings.
4212  To do so you can use the 
4213 \begin_inset Quotes sld
4214 \end_inset
4215
4216 unix2dos
4217 \begin_inset Quotes srd
4218 \end_inset
4219
4220  utility freely available on the internet.
4221  Doug Hawkins reported in the sdcc-user list that this works:
4222 \newline
4223
4224 \newline
4225 C:
4226 \backslash
4227 Programming
4228 \backslash
4229 SDCC> unix2dos sdcc.dsw
4230 \newline
4231 C:
4232 \backslash
4233 Programming
4234 \backslash
4235 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4236 \newline
4237
4238 \newline
4239 In order to build SDCC with MSVC
4240  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4241  One good place to get them is 
4242 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4243
4244 \end_inset
4245
4246
4247 \newline
4248
4249 \newline
4250 Download the file UnxUtils
4251 \begin_inset LatexCommand \index{UnxUtils}
4252
4253 \end_inset
4254
4255 .zip.
4256  Now you have to install the utilities and setup MSVC so it can locate the
4257  required programs.
4258  Here there are two alternatives (choose one!):
4259 \end_layout
4260
4261 \begin_layout Enumerate
4262 The easy way:
4263 \newline
4264
4265 \newline
4266 a) Extract UnxUtils.zip to your C:
4267 \backslash
4268  hard disk PRESERVING the original paths, otherwise bison won't work.
4269  (If you are using WinZip make certain that 'Use folder names' is selected)
4270 \newline
4271
4272 \newline
4273 b)
4274  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4275  'Show directories for:' select 'Executable files', and in the directories
4276  window add a new path: 'C:
4277 \backslash
4278 user
4279 \backslash
4280 local
4281 \backslash
4282 wbin', click ok.
4283 \newline
4284
4285 \newline
4286 (As a side effect, you get a bunch of Unix utilities that
4287  could be useful, such as diff and patch.)
4288 \end_layout
4289
4290 \begin_layout Enumerate
4291 A more compact way:
4292 \newline
4293
4294 \newline
4295 This one avoids extracting a bunch of files you may not
4296  use, but requires some extra work:
4297 \newline
4298
4299 \newline
4300 a) Create a directory were to put the
4301  tools needed, or use a directory already present.
4302  Say for example 'C:
4303 \backslash
4304 util'.
4305 \newline
4306
4307 \newline
4308 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4309  gawk.exe to such directory WITHOUT preserving the original paths.
4310  (If you are using WinZip make certain that 'Use folder names' is not selected)
4311 \newline
4312
4313 \newline
4314 c
4315 ) Rename bison.exe to '_bison.exe'.
4316 \newline
4317
4318 \newline
4319 d) Create a batch file 'bison.bat' in 'C:
4320 \backslash
4321 util
4322 \backslash
4323 ' and add these lines: 
4324 \newline
4325 \InsetSpace ~
4326 \InsetSpace ~
4327 set BISON_SIMPLE=C:
4328 \backslash
4329 util
4330 \backslash
4331 bison.simple 
4332 \newline
4333 \InsetSpace ~
4334 \InsetSpace ~
4335 set BISON_HAIRY=C:
4336 \backslash
4337 util
4338 \backslash
4339 bison.hairy
4340 \newline
4341 \InsetSpace ~
4342 \InsetSpace ~
4343 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4344 \newline
4345
4346 \newline
4347 Steps 'c' and 'd' are needed
4348  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4349  reside in some weird Unix directory, '/usr/local/share/' I think.
4350  So it is necessary to tell bison where those files are located if they
4351  are not in such directory.
4352  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4353 \newline
4354
4355 \newline
4356 e
4357 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4358  in 'Show directories for:' select 'Executable files', and in the directories
4359  window add a new path: 'c:
4360 \backslash
4361 util', click ok.
4362  Note that you can use any other path instead of 'c:
4363 \backslash
4364 util', even the path where the Visual C++ tools are, probably: 'C:
4365 \backslash
4366 Program Files
4367 \backslash
4368 Microsoft Visual Studio
4369 \backslash
4370 Common
4371 \backslash
4372 Tools'.
4373  So you don't have to execute step 'e' :)
4374 \end_layout
4375
4376 \begin_layout Standard
4377 That is it.
4378  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4379  the executables from sdcc
4380 \backslash
4381 bin_vc to sdcc
4382 \backslash
4383 bin, and you can compile using SDCC.
4384 \end_layout
4385
4386 \begin_layout Subsection
4387 Building SDCC Using Borland
4388 \end_layout
4389
4390 \begin_layout Enumerate
4391 From the sdcc directory, run the command "make -f Makefile.bcc".
4392  This should regenerate all the .exe files in the bin directory except for
4393  SDCDB and ucSim.
4394 \end_layout
4395
4396 \begin_layout Enumerate
4397 If you modify any source files and need to rebuild, be aware that the dependenci
4398 es may not be correctly calculated.
4399  The safest option is to delete all .obj files and run the build again.
4400  From a Cygwin BASH prompt, this can easily be done with the command (be
4401  sure you are in the sdcc directory):
4402 \newline
4403
4404 \newline
4405
4406 \family sans
4407 \series bold
4408 find .
4409  
4410 \backslash
4411 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4412 \backslash
4413 ) -print -exec rm {} 
4414 \backslash
4415 ;
4416 \family default
4417 \series default
4418
4419 \newline
4420
4421 \newline
4422 or on Windows NT/2000/XP from the command prompt with the command:
4423 \newline
4424
4425 \family sans
4426 \series bold
4427
4428 \newline
4429 del /s *.obj *.lib *.rul
4430 \family default
4431 \series default
4432  from the sdcc directory.
4433 \end_layout
4434
4435 \begin_layout Subsection
4436 Windows Install Using a ZIP Package
4437 \end_layout
4438
4439 \begin_layout Enumerate
4440 Download the binary zip package from 
4441 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4442
4443 \end_inset
4444
4445  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4446  This should unpack to a group of sub-directories.
4447  An example directory structure after unpacking the mingw32 package is:
4448  c:
4449 \backslash
4450 sdcc
4451 \backslash
4452 bin for the executables, c:
4453 \backslash
4454 sdcc
4455 \backslash
4456 include and c:
4457 \backslash
4458 sdcc
4459 \backslash
4460 lib for the include and libraries.
4461 \end_layout
4462
4463 \begin_layout Enumerate
4464 Adjust your environment variable PATH to include the location of the bin
4465  directory or start sdcc using the full path.
4466 \end_layout
4467
4468 \begin_layout Subsection
4469 Windows Install Using the Setup Program
4470 \begin_inset LatexCommand \label{sub:Windows-Install}
4471
4472 \end_inset
4473
4474
4475 \end_layout
4476
4477 \begin_layout Standard
4478 Download the setup program 
4479 \emph on
4480 sdcc-x.y.z-setup.exe
4481 \emph default
4482  for an official release from 
4483 \newline
4484
4485 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4486
4487 \end_inset
4488
4489  or a setup program for one of the snapshots 
4490 \emph on
4491 sdcc-yyyymmdd-xxxx-setup.exe
4492 \emph default
4493  from 
4494 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4495
4496 \end_inset
4497
4498  and execute it.
4499  A windows typical installer will guide you through the installation process.
4500 \end_layout
4501
4502 \begin_layout Subsection
4503 VPATH
4504 \begin_inset LatexCommand \index{VPATH}
4505
4506 \end_inset
4507
4508  feature
4509 \end_layout
4510
4511 \begin_layout Standard
4512 SDCC supports the VPATH feature provided by configure and make.
4513  It allows to separate the source and build trees.
4514  Here's an example:
4515 \end_layout
4516
4517 \begin_layout Standard
4518
4519 \family typewriter
4520 cd ~\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 \InsetSpace ~
4541 # cd $HOME
4542 \end_layout
4543
4544 \begin_layout Standard
4545
4546 \family typewriter
4547 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4548 # extract source to directory sdcc
4549 \end_layout
4550
4551 \begin_layout Standard
4552
4553 \family typewriter
4554 mkdir sdcc.build\InsetSpace ~
4555 \InsetSpace ~
4556 \InsetSpace ~
4557 \InsetSpace ~
4558 \InsetSpace ~
4559 \InsetSpace ~
4560 \InsetSpace ~
4561 \InsetSpace ~
4562 \InsetSpace ~
4563 # put output in sdcc.build
4564 \end_layout
4565
4566 \begin_layout Standard
4567
4568 \family typewriter
4569 cd sdcc.build
4570 \end_layout
4571
4572 \begin_layout Standard
4573
4574 \family typewriter
4575 ../sdcc/configure\InsetSpace ~
4576 \InsetSpace ~
4577 \InsetSpace ~
4578 \InsetSpace ~
4579 \InsetSpace ~
4580 \InsetSpace ~
4581 \InsetSpace ~
4582 \InsetSpace ~
4583 # configure is doing all the magic!
4584 \end_layout
4585
4586 \begin_layout Standard
4587
4588 \family typewriter
4589 make
4590 \end_layout
4591
4592 \begin_layout Standard
4593 \noindent
4594 That's it! 
4595 \series bold
4596 configure
4597 \series default
4598  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4599  It automagically computes the variables srcdir, top_srcdir and top_buildir
4600  for each directory.
4601  After running 
4602 \series bold
4603 make
4604 \series default
4605  the generated files will be in ~/sdcc.build, while the source files stay
4606  in ~/sdcc.
4607 \newline
4608 This is not only usefull for building different binaries, e.g.
4609  when cross compiling.
4610  It also gives you a much better overview in the source tree when all the
4611  generated files are not scattered between the source files.
4612  And the best thing is: if you want to change a file you can leave the original
4613  file untouched in the source directory.
4614  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4615  Makefile.dep` and `make`.
4616  
4617 \series bold
4618 make
4619 \series default
4620  will do the rest for you!
4621 \end_layout
4622
4623 \begin_layout Section
4624 Building the Documentation
4625 \end_layout
4626
4627 \begin_layout Standard
4628 Add -
4629 \begin_inset ERT
4630 status collapsed
4631
4632 \begin_layout Standard
4633
4634
4635 \backslash
4636 /
4637 \end_layout
4638
4639 \end_inset
4640
4641 -enable-doc to the configure arguments to build the documentation together
4642  with all the other stuff.
4643  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4644  dvips and makeindex) to get the job done.
4645  Another possibility is to change to the doc directory and to type 
4646 \family sans
4647 \series bold
4648
4649 \begin_inset Quotes srd
4650 \end_inset
4651
4652 make
4653 \begin_inset Quotes srd
4654 \end_inset
4655
4656
4657 \family default
4658 \series default
4659  there.
4660  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4661 x).
4662  Using LyX 
4663 \begin_inset LatexCommand \url{http://www.lyx.org}
4664
4665 \end_inset
4666
4667  as editor is straightforward.
4668  Prebuilt documentation in html and pdf format is available from 
4669 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4670
4671 \end_inset
4672
4673 .
4674 \end_layout
4675
4676 \begin_layout Section
4677 Reading the Documentation
4678 \begin_inset LatexCommand \index{Documentation}
4679
4680 \end_inset
4681
4682
4683 \end_layout
4684
4685 \begin_layout Standard
4686 Currently reading the document in pdf format is recommended, as for unknown
4687  reason the hyperlinks are working there whereas in the html version they
4688  are not
4689 \begin_inset Foot
4690 status open
4691
4692 \begin_layout Standard
4693 If you should know why please drop us a note
4694 \end_layout
4695
4696 \end_inset
4697
4698 .
4699  
4700 \newline
4701 You'll find the pdf version
4702 \begin_inset LatexCommand \index{PDF version of this document}
4703
4704 \end_inset
4705
4706  at 
4707 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4708
4709 \end_inset
4710
4711 .
4712  
4713 \newline
4714 A html version
4715 \begin_inset LatexCommand \index{HTML version of this document}
4716
4717 \end_inset
4718
4719  should be online at 
4720 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4721
4722 \end_inset
4723
4724 .
4725 \newline
4726 This documentation is in some aspects different from a commercial documentation:
4727  
4728 \end_layout
4729
4730 \begin_layout Itemize
4731 It tries to document SDCC for several processor architectures in one document
4732  (commercially these probably would be separate documents/products).
4733  This document
4734 \begin_inset LatexCommand \index{Status of documentation}
4735
4736 \end_inset
4737
4738  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4739 on about f.e.
4740  Z80, PIC14, PIC16 and HC08.
4741 \end_layout
4742
4743 \begin_layout Itemize
4744 There are many references pointing away from this documentation.
4745  Don't let this distract you.
4746  If there f.e.
4747  was a reference like 
4748 \begin_inset LatexCommand \url{http://www.opencores.org}
4749
4750 \end_inset
4751
4752  together with a statement 
4753 \begin_inset Quotes sld
4754 \end_inset
4755
4756 some processors which are targetted by SDCC can be implemented in a 
4757 \emph on
4758 f
4759 \emph default
4760 ield 
4761 \emph on
4762 p
4763 \emph default
4764 rogrammable 
4765 \emph on
4766 g
4767 \emph default
4768 ate 
4769 \emph on
4770 a
4771 \emph default
4772 rray
4773 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4774
4775 \end_inset
4776
4777
4778 \begin_inset Quotes srd
4779 \end_inset
4780
4781  or 
4782 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4783
4784 \end_inset
4785
4786
4787 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4788
4789 \end_inset
4790
4791  
4792 \begin_inset Quotes sld
4793 \end_inset
4794
4795 have you ever heard of an open source compiler that compiles a subset of
4796  C for an FPGA?
4797 \begin_inset Quotes srd
4798 \end_inset
4799
4800  we expect you to have a quick look there and come back.
4801  If you read this you are on the right track.
4802 \end_layout
4803
4804 \begin_layout Itemize
4805 Some sections attribute more space to problems, restrictions and warnings
4806  than to the solution.
4807 \end_layout
4808
4809 \begin_layout Itemize
4810 The installation section and the section about the debugger is intimidating.
4811 \end_layout
4812
4813 \begin_layout Itemize
4814 There are still lots of typos and there are more different writing styles
4815  than pictures.
4816 \end_layout
4817
4818 \begin_layout Section
4819 Testing the SDCC Compiler
4820 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4821
4822 \end_inset
4823
4824
4825 \end_layout
4826
4827 \begin_layout Standard
4828 The first thing you should do after installing your SDCC compiler is to
4829  see if it runs.
4830  Type 
4831 \family sans
4832 \series bold
4833 "sdcc -
4834 \begin_inset ERT
4835 status collapsed
4836
4837 \begin_layout Standard
4838
4839
4840 \backslash
4841 /
4842 \end_layout
4843
4844 \end_inset
4845
4846 -version"
4847 \begin_inset LatexCommand \index{version}
4848
4849 \end_inset
4850
4851
4852 \family default
4853 \series default
4854  at the prompt, and the program should run and output its version like:
4855  
4856 \newline
4857
4858 \family typewriter
4859 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4860  (UNIX)
4861 \end_layout
4862
4863 \begin_layout Standard
4864 If it doesn't run, or gives a message about not finding sdcc program, then
4865  you need to check over your installation.
4866  Make sure that the sdcc bin directory is in your executable search path
4867  defined by the PATH environment setting (
4868 \series medium
4869 see 
4870 \series default
4871 section 
4872 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4873
4874 \end_inset
4875
4876 \InsetSpace ~
4877
4878 \series medium
4879 Install trouble-shooting for suggestions
4880 \series default
4881 ).
4882  Make sure that the sdcc program is in the bin folder, if not perhaps something
4883  did not install correctly.
4884 \newline
4885
4886 \newline
4887
4888 \series medium
4889 SDCC 
4890 \series default
4891 is commonly installed as described in section 
4892 \begin_inset Quotes sld
4893 \end_inset
4894
4895 Install and search paths
4896 \begin_inset Quotes srd
4897 \end_inset
4898
4899 .
4900 \newline
4901
4902 \newline
4903
4904 \series medium
4905 Make sure the compiler works on a very simple example.
4906  Type in the following test.c program using your favorite 
4907 \series default
4908 ASCII 
4909 \series medium
4910 editor:
4911 \end_layout
4912
4913 \begin_layout Verse
4914
4915 \family typewriter
4916 char test;
4917 \newline
4918
4919 \newline
4920 void main(void) {
4921 \newline
4922 \InsetSpace ~
4923 \InsetSpace ~
4924 \InsetSpace ~
4925 \InsetSpace ~
4926 test=0;
4927 \newline
4928 }
4929 \end_layout
4930
4931 \begin_layout Standard
4932
4933 \series medium
4934 Compile this using the following command: 
4935 \family sans
4936 \series bold
4937 "sdcc -c test.c".
4938
4939 \family default
4940 \series default
4941  
4942 \series medium
4943 If all goes well, the compiler will generate a test.asm and test.rel file.
4944  Congratulations, you've just compiled your first program with SDCC.
4945  We used the -c option to tell SDCC not to link the generated code, just
4946  to keep things simple for this step.
4947 \series default
4948
4949 \newline
4950
4951 \newline
4952
4953 \series medium
4954 The next step is to try it with the linker.
4955  Type in 
4956 \family sans
4957 \series bold
4958 "sdcc test.c
4959 \family default
4960 \series default
4961 "
4962 \series medium
4963 .
4964  If all goes well the compiler will link with the libraries and produce
4965  a test.ihx output file.
4966  If this step fails
4967 \series default
4968  
4969 \series medium
4970 (no test.ihx, and the linker generates warnings), then the problem is most
4971  likely that 
4972 \series default
4973 SDCC
4974 \series medium
4975  cannot find the 
4976 \series default
4977 /
4978 \series medium
4979 usr/local/share/sdcc/lib directory
4980 \series default
4981  
4982 \series medium
4983 (see 
4984 \series default
4985 section 
4986 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4987
4988 \end_inset
4989
4990 \InsetSpace ~
4991
4992 \series medium
4993 Install trouble-shooting for suggestions).
4994 \series default
4995
4996 \newline
4997
4998 \newline
4999
5000 \series medium
5001 The final test is to ensure 
5002 \series default
5003 SDCC
5004 \series medium
5005  can use the 
5006 \series default
5007 standard
5008 \series medium
5009  header files and libraries.
5010  Edit test.c and change it to the following:
5011 \end_layout
5012
5013 \begin_layout Verse
5014
5015 \family typewriter
5016 #include <string.h>
5017 \newline
5018
5019 \newline
5020 char str1[10];
5021 \newline
5022
5023 \newline
5024 void main(void) {
5025 \newline
5026 \InsetSpace ~
5027 \InsetSpace ~
5028 strcpy(str1, "testing");
5029 \newline
5030 }
5031 \end_layout
5032
5033 \begin_layout Standard
5034
5035 \series medium
5036 Compile this by typing 
5037 \family sans
5038 \series bold
5039 "sdcc test.c"
5040 \family default
5041 \series medium
5042 .
5043  This should generate a test.ihx output file, and it should give no warnings
5044  such as not finding the string.h file.
5045  If it cannot find the string.h file, then the problem is that 
5046 \series default
5047 SDCC
5048 \series medium
5049  cannot find the /usr/local/share/sdcc/include directory
5050 \series default
5051  
5052 \series medium
5053 (see the 
5054 \series default
5055 section 
5056 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5057
5058 \end_inset
5059
5060 \InsetSpace ~
5061
5062 \series medium
5063 Install trouble-shooting section for suggestions).
5064
5065 \series default
5066  Use option 
5067 \series bold
5068 -
5069 \begin_inset ERT
5070 status collapsed
5071
5072 \begin_layout Standard
5073
5074
5075 \backslash
5076 /
5077 \end_layout
5078
5079 \end_inset
5080
5081 -print-search-dirs
5082 \series default
5083
5084 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5085
5086 \end_inset
5087
5088  to find exactly where SDCC is looking for the include and lib files.
5089 \end_layout
5090
5091 \begin_layout Section
5092 Install Trouble-shooting
5093 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5094
5095 \end_inset
5096
5097
5098 \begin_inset LatexCommand \index{Install trouble-shooting}
5099
5100 \end_inset
5101
5102
5103 \end_layout
5104
5105 \begin_layout Subsection
5106 If SDCC does not build correctly
5107 \end_layout
5108
5109 \begin_layout Standard
5110 A thing to try is starting from scratch by unpacking the .tgz source package
5111  again in an empty directory.
5112  Configure it like:
5113 \newline
5114
5115 \newline
5116
5117 \family sans
5118 \series bold
5119 ./configure 2>&1 | tee configure.log
5120 \family default
5121 \series default
5122
5123 \newline
5124
5125 \newline
5126 and build it like:
5127 \newline
5128
5129 \newline
5130
5131 \family sans
5132 \series bold
5133 make 2>&1 | tee make.log
5134 \family default
5135 \series default
5136
5137 \newline
5138
5139 \newline
5140 If anything goes wrong, you can review the log files to locate the problem.
5141  Or a relevant part of this can be attached to an email that could be helpful
5142  when requesting help from the mailing list.
5143 \end_layout
5144
5145 \begin_layout Subsection
5146 What the 
5147 \begin_inset Quotes sld
5148 \end_inset
5149
5150 ./configure
5151 \begin_inset Quotes srd
5152 \end_inset
5153
5154  does
5155 \end_layout
5156
5157 \begin_layout Standard
5158 The 
5159 \begin_inset Quotes sld
5160 \end_inset
5161
5162 ./configure
5163 \begin_inset Quotes srd
5164 \end_inset
5165
5166  command is a script that analyzes your system and performs some configuration
5167  to ensure the source package compiles on your system.
5168  It will take a few minutes to run, and will compile a few tests to determine
5169  what compiler features are installed.
5170 \end_layout
5171
5172 \begin_layout Subsection
5173 What the 
5174 \begin_inset Quotes sld
5175 \end_inset
5176
5177 make
5178 \begin_inset Quotes srd
5179 \end_inset
5180
5181  does
5182 \end_layout
5183
5184 \begin_layout Standard
5185 This runs the GNU make tool, which automatically compiles all the source
5186  packages into the final installed binary executables.
5187 \end_layout
5188
5189 \begin_layout Subsection
5190 What the 
5191 \begin_inset Quotes sld
5192 \end_inset
5193
5194 make install
5195 \begin_inset Quotes erd
5196 \end_inset
5197
5198  command does.
5199 \end_layout
5200
5201 \begin_layout Standard
5202 This will install the compiler, other executables libraries and include
5203  files into the appropriate directories.
5204  See sections 
5205 \begin_inset LatexCommand \ref{sub:Install-paths}
5206
5207 \end_inset
5208
5209 ,\InsetSpace ~
5210
5211 \begin_inset LatexCommand \ref{sub:Search-Paths}
5212
5213 \end_inset
5214
5215 \InsetSpace ~
5216 about install and search paths.
5217 \newline
5218 On most systems you will need super-user privilege
5219 s to do this.
5220 \end_layout
5221
5222 \begin_layout Section
5223 Components of SDCC
5224 \end_layout
5225
5226 \begin_layout Standard
5227 SDCC is not just a compiler, but a collection of tools by various developers.
5228  These include linkers, assemblers, simulators and other components.
5229  Here is a summary of some of the components.
5230  Note that the included simulator and assembler have separate documentation
5231  which you can find in the source package in their respective directories.
5232  As SDCC grows to include support for other processors, other packages from
5233  various developers are included and may have their own sets of documentation.
5234 \newline
5235
5236 \newline
5237 You
5238  might want to look at the files which are installed in <installdir>.
5239  At the time of this writing, we find the following programs for gcc-builds:
5240 \newline
5241
5242  
5243 \newline
5244 In <installdir>/bin:
5245 \end_layout
5246
5247 \begin_layout Itemize
5248 sdcc - The compiler.
5249 \end_layout
5250
5251 \begin_layout Itemize
5252 sdcpp - The C preprocessor.
5253 \end_layout
5254
5255 \begin_layout Itemize
5256 asx8051 - The assembler for 8051 type processors.
5257 \end_layout
5258
5259 \begin_layout Itemize
5260 as-z80
5261 \series bold
5262
5263 \series default
5264 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5265 \end_layout
5266
5267 \begin_layout Itemize
5268 aslink -The linker for 8051 type processors.
5269 \end_layout
5270
5271 \begin_layout Itemize
5272 link-z80
5273 \series bold
5274
5275 \series default
5276 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5277 \end_layout
5278
5279 \begin_layout Itemize
5280 s51 - The ucSim 8051 simulator.
5281 \end_layout
5282
5283 \begin_layout Itemize
5284 sdcdb - The source debugger.
5285 \end_layout
5286
5287 \begin_layout Itemize
5288 packihx - A tool to pack (compress) Intel hex files.
5289 \end_layout
5290
5291 \begin_layout Standard
5292 In <installdir>/share/sdcc/include
5293 \end_layout
5294
5295 \begin_layout Itemize
5296 the include files
5297 \end_layout
5298
5299 \begin_layout Standard
5300 In <installdir>/share/sdcc/lib
5301 \end_layout
5302
5303 \begin_layout Itemize
5304 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5305  relocatables.
5306 \end_layout
5307
5308 \begin_layout Standard
5309 In <installdir>/share/sdcc/doc
5310 \end_layout
5311
5312 \begin_layout Itemize
5313 the documentation
5314 \end_layout
5315
5316 \begin_layout Standard
5317 As development for other processors proceeds, this list will expand to include
5318  executables to support processors like AVR, PIC, etc.
5319 \end_layout
5320
5321 \begin_layout Subsection
5322 sdcc - The Compiler
5323 \end_layout
5324
5325 \begin_layout Standard
5326 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5327  the assembler and linkage editor.
5328 \end_layout
5329
5330 \begin_layout Subsection
5331 sdcpp - The C-Preprocessor
5332 \end_layout
5333
5334 \begin_layout Standard
5335 The preprocessor
5336 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5337
5338 \end_inset
5339
5340  is a modified version of the GNU cpp
5341 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5342
5343 \end_inset
5344
5345  preprocessor 
5346 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5347
5348 \end_inset
5349
5350 .
5351  The C preprocessor is used to pull in #include sources, process #ifdef
5352  statements, #defines and so on.
5353 \end_layout
5354
5355 \begin_layout Subsection
5356 as
5357 \emph on
5358 xxxx
5359 \emph default
5360 , aslink, link-
5361 \emph on
5362 xxx
5363 \emph default
5364  - The Assemblers and Linkage Editors
5365 \end_layout
5366
5367 \begin_layout Standard
5368 This is retargettable assembler & linkage editor, it was developed by Alan
5369  Baldwin.
5370  John Hartman created the version for 8051, and I (Sandeep) have made some
5371  enhancements and bug fixes for it to work properly with SDCC.
5372 \end_layout
5373
5374 \begin_layout Subsection
5375 s51 - The Simulator
5376 \end_layout
5377
5378 \begin_layout Standard
5379 S51
5380 \begin_inset LatexCommand \index{s51}
5381
5382 \end_inset
5383
5384  is a free open source simulator developed by Daniel Drotos.
5385  The simulator is built as part of the build process.
5386  For more information visit Daniel's web site at: 
5387 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5388
5389 \end_inset
5390
5391 .
5392  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5393  XA51 family.
5394 \end_layout
5395
5396 \begin_layout Subsection
5397 sdcdb - Source Level Debugger
5398 \end_layout
5399
5400 \begin_layout Standard
5401 SDCDB
5402 \begin_inset LatexCommand \index{SDCDB (debugger)}
5403
5404 \end_inset
5405
5406  is the companion source level debugger.
5407  More about SDCDB in section 
5408 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5409
5410 \end_inset
5411
5412 .
5413  The current version of the debugger uses Daniel's Simulator S51
5414 \begin_inset LatexCommand \index{s51}
5415
5416 \end_inset
5417
5418 , but can be easily changed to use other simulators.
5419 \end_layout
5420
5421 \begin_layout Chapter
5422 Using SDCC
5423 \end_layout
5424
5425 \begin_layout Section
5426 Compiling
5427 \end_layout
5428
5429 \begin_layout Subsection
5430 Single Source File Projects
5431 \end_layout
5432
5433 \begin_layout Standard
5434 For single source file 8051 projects the process is very simple.
5435  Compile your programs with the following command 
5436 \family sans
5437 \series bold
5438 "sdcc sourcefile.c".
5439
5440 \family default
5441 \series default
5442  This will compile, assemble and link your source file.
5443  Output files are as follows:
5444 \end_layout
5445
5446 \begin_layout Itemize
5447 sourcefile.asm
5448 \begin_inset LatexCommand \index{<file>.asm}
5449
5450 \end_inset
5451
5452  - Assembler source
5453 \begin_inset LatexCommand \index{Assembler source}
5454
5455 \end_inset
5456
5457  file created by the compiler
5458 \end_layout
5459
5460 \begin_layout Itemize
5461 sourcefile.lst
5462 \begin_inset LatexCommand \index{<file>.lst}
5463
5464 \end_inset
5465
5466  - Assembler listing
5467 \begin_inset LatexCommand \index{Assembler listing}
5468
5469 \end_inset
5470
5471  file created by the Assembler
5472 \end_layout
5473
5474 \begin_layout Itemize
5475 sourcefile.rst
5476 \begin_inset LatexCommand \index{<file>.rst}
5477
5478 \end_inset
5479
5480  - Assembler listing
5481 \begin_inset LatexCommand \index{Assembler listing}
5482
5483 \end_inset
5484
5485  file updated with linkedit information, created by linkage editor
5486 \end_layout
5487
5488 \begin_layout Itemize
5489 sourcefile.sym
5490 \begin_inset LatexCommand \index{<file>.sym}
5491
5492 \end_inset
5493
5494  - symbol listing
5495 \begin_inset LatexCommand \index{Symbol listing}
5496
5497 \end_inset
5498
5499  for the sourcefile, created by the assembler
5500 \end_layout
5501
5502 \begin_layout Itemize
5503 sourcefile.rel
5504 \begin_inset LatexCommand \index{<file>.rel}
5505
5506 \end_inset
5507
5508  or sourcefile.o
5509 \begin_inset LatexCommand \index{<file>.o}
5510
5511 \end_inset
5512
5513  - Object file
5514 \begin_inset LatexCommand \index{Object file}
5515
5516 \end_inset
5517
5518  created by the assembler, input to Linkage editor
5519 \end_layout
5520
5521 \begin_layout Itemize
5522 sourcefile.map
5523 \begin_inset LatexCommand \index{<file>.map}
5524
5525 \end_inset
5526
5527  - The memory map
5528 \begin_inset LatexCommand \index{Memory map}
5529
5530 \end_inset
5531
5532  for the load module, created by the Linker
5533 \end_layout
5534
5535 \begin_layout Itemize
5536 sourcefile.mem
5537 \begin_inset LatexCommand \index{<file>.mem}
5538
5539 \end_inset
5540
5541  - A file with a summary of the memory usage
5542 \end_layout
5543
5544 \begin_layout Itemize
5545 sourcefile.ihx
5546 \begin_inset LatexCommand \index{<file>.ihx}
5547
5548 \end_inset
5549
5550  - The load module in Intel hex format
5551 \begin_inset LatexCommand \index{Intel hex format}
5552
5553 \end_inset
5554
5555  (you can select the Motorola S19 format
5556 \begin_inset LatexCommand \index{Motorola S19 format}
5557
5558 \end_inset
5559
5560  with -
5561 \begin_inset ERT
5562 status collapsed
5563
5564 \begin_layout Standard
5565
5566
5567 \backslash
5568 /
5569 \end_layout
5570
5571 \end_inset
5572
5573 -out-fmt-s19
5574 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5575
5576 \end_inset
5577
5578 .
5579  If you need another format you might want to use 
5580 \family sans
5581 \shape italic
5582 objdump
5583 \family default
5584 \shape default
5585
5586 \begin_inset LatexCommand \index{objdump (tool)}
5587
5588 \end_inset
5589
5590  or
5591 \family sans
5592 \shape italic
5593  srecord
5594 \family default
5595 \shape default
5596
5597 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5598
5599 \end_inset
5600
5601
5602 \begin_inset Note Note
5603 status collapsed
5604
5605 \begin_layout Standard
5606 hyperlinks needed
5607 \end_layout
5608
5609 \end_inset
5610
5611  - see also section 
5612 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5613
5614 \end_inset
5615
5616 ).
5617  Both formats are documented in the documentation of srecord
5618 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5619
5620 \end_inset
5621
5622
5623 \end_layout
5624
5625 \begin_layout Itemize
5626 sourcefile.adb
5627 \begin_inset LatexCommand \index{<file>.adb}
5628
5629 \end_inset
5630
5631  - An intermediate file containing debug information needed to create the
5632  .cdb file (with -
5633 \begin_inset ERT
5634 status collapsed
5635
5636 \begin_layout Standard
5637
5638
5639 \backslash
5640 /
5641 \end_layout
5642
5643 \end_inset
5644
5645 -debug
5646 \begin_inset LatexCommand \index{-\/-debug}
5647
5648 \end_inset
5649
5650
5651 \end_layout
5652
5653 \begin_layout Itemize
5654 sourcefile.cdb
5655 \begin_inset LatexCommand \index{<file>.cdb}
5656
5657 \end_inset
5658
5659  - An optional file (with -
5660 \begin_inset ERT
5661 status collapsed
5662
5663 \begin_layout Standard
5664
5665
5666 \backslash
5667 /
5668 \end_layout
5669
5670 \end_inset
5671
5672 -debug) containing debug information.
5673  The format is documented in cdbfileformat.pdf
5674 \end_layout
5675
5676 \begin_layout Itemize
5677 sourcefile.
5678  - (no extension)
5679 \begin_inset LatexCommand \index{<file> (no extension)}
5680
5681 \end_inset
5682
5683  An optional AOMF or AOMF51
5684 \begin_inset LatexCommand \index{AOMF, AOMF51}
5685
5686 \end_inset
5687
5688  
5689 \begin_inset LatexCommand \label{OMF file}
5690
5691 \end_inset
5692
5693 file containing debug information (generated with option -
5694 \begin_inset ERT
5695 status collapsed
5696
5697 \begin_layout Standard
5698
5699
5700 \backslash
5701 /
5702 \end_layout
5703
5704 \end_inset
5705
5706 -debug).
5707  The (Intel)
5708 \emph on
5709  a
5710 \emph default
5711 bsolute 
5712 \emph on
5713 o
5714 \emph default
5715 bject 
5716 \emph on
5717 m
5718 \emph default
5719 odule 
5720 \emph on
5721 f
5722 \emph default
5723 ormat is a subformat of the OMF51 format and is commonly used by third party
5724  tools (debuggers
5725 \begin_inset LatexCommand \index{Debugger}
5726
5727 \end_inset
5728
5729 , simulators, emulators).
5730 \end_layout
5731
5732 \begin_layout Itemize
5733 sourcefile.dump*
5734 \begin_inset LatexCommand \index{<file>.dump*}
5735
5736 \end_inset
5737
5738  - Dump file to debug the compiler it self (generated with option -
5739 \begin_inset ERT
5740 status collapsed
5741
5742 \begin_layout Standard
5743
5744
5745 \backslash
5746 /
5747 \end_layout
5748
5749 \end_inset
5750
5751 -dumpall) (see section 
5752 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5753
5754 \end_inset
5755
5756 \InsetSpace ~
5757  and section 
5758 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5759
5760 \end_inset
5761
5762 \InsetSpace ~
5763
5764 \begin_inset Quotes sld
5765 \end_inset
5766
5767 Anatomy of the compiler
5768 \begin_inset Quotes srd
5769 \end_inset
5770
5771 ).
5772 \end_layout
5773
5774 \begin_layout Subsection
5775 Postprocessing the Intel Hex
5776 \begin_inset LatexCommand \index{Intel hex format}
5777
5778 \end_inset
5779
5780  file
5781 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5782
5783 \end_inset
5784
5785
5786 \end_layout
5787
5788 \begin_layout Standard
5789 In most cases this won't be needed but the Intel Hex file
5790 \begin_inset LatexCommand \index{<file>.ihx}
5791
5792 \end_inset
5793
5794  which is generated by SDCC might include lines of varying length and the
5795  addresses within the file are not guaranteed to be strictly ascending.
5796  If your toolchain or a bootloader does not like this you can use the tool
5797  
5798 \family typewriter
5799 packihx
5800 \family default
5801
5802 \begin_inset LatexCommand \index{packihx (tool)}
5803
5804 \end_inset
5805
5806  which is part of the SDCC distribution: 
5807 \newline
5808
5809 \newline
5810
5811 \family sans
5812 \series bold
5813  packihx sourcefile.ihx >sourcefile.hex
5814 \family default
5815 \series default
5816
5817 \newline
5818
5819 \newline
5820 The separately available
5821 \emph on
5822  srecord
5823 \emph default
5824
5825 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5826
5827 \end_inset
5828
5829  package additionally allows to set undefined locations to a predefined
5830  value, to insert checksums
5831 \begin_inset LatexCommand \index{checksum}
5832
5833 \end_inset
5834
5835  of various flavours (crc, add, xor) and to perform other manipulations
5836  (convert, split, crop, offset, ...).
5837  
5838 \newline
5839
5840 \newline
5841
5842 \family sans
5843 \series bold
5844 srec_cat\InsetSpace ~
5845 \InsetSpace ~
5846 sourcefile.ihx -intel\InsetSpace ~
5847 \InsetSpace ~
5848 -o sourcefile.hex -intel
5849 \newline
5850
5851 \newline
5852
5853 \family default
5854 \series default
5855 An example for a more complex command line
5856 \begin_inset Foot
5857 status open
5858
5859 \begin_layout Standard
5860 the command backfills
5861 \begin_inset LatexCommand \index{backfill unused memory}
5862
5863 \end_inset
5864
5865  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5866  block is zero.
5867  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5868  will be interpreted as an 
5869 \family typewriter
5870 lcall
5871 \family default
5872  to address 
5873 \family typewriter
5874 0x1212
5875 \family default
5876  (where an emergency routine could sit).
5877 \end_layout
5878
5879 \end_inset
5880
5881  could look like:
5882 \newline
5883
5884 \newline
5885
5886 \family sans
5887 \series bold
5888 \size footnotesize
5889 srec_cat\InsetSpace ~
5890 sourcefile.ihx -intel\InsetSpace ~
5891 \InsetSpace ~
5892 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5893 -little-endian-checksum-nega
5894 tive 0xfffe 0x02 0x02\InsetSpace ~
5895 \InsetSpace ~
5896 -o sourcefile.hex -intel
5897 \size default
5898
5899 \newline
5900
5901 \newline
5902
5903 \family default
5904 \series default
5905 The srecord package is available at 
5906 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5907
5908 \end_inset
5909
5910  .
5911 \end_layout
5912
5913 \begin_layout Subsection
5914 Projects with Multiple Source Files
5915 \end_layout
5916
5917 \begin_layout Standard
5918 SDCC can compile only ONE file at a time.
5919  Let us for example assume that you have a project containing the following
5920  files:
5921 \newline
5922
5923 \newline
5924 foo1.c (contains some functions)
5925 \newline
5926 foo2.c (contains some more functions)
5927 \newline
5928 foomai
5929 n.c (contains more functions and the function main)
5930 \newline
5931
5932 \size footnotesize
5933
5934 \newline
5935
5936 \size default
5937 The first two files will need to be compiled separately with the commands:
5938 \size footnotesize
5939  
5940 \size default
5941
5942 \newline
5943
5944 \newline
5945
5946 \family sans
5947 \series bold
5948 sdcc\InsetSpace ~
5949 -c\InsetSpace ~
5950 foo1.c
5951 \family default
5952 \series default
5953 \size footnotesize
5954
5955 \newline
5956
5957 \family sans
5958 \series bold
5959 \size default
5960 sdcc\InsetSpace ~
5961 -c\InsetSpace ~
5962 foo2.c
5963 \family default
5964 \series default
5965
5966 \newline
5967
5968 \newline
5969 Then compile the source file containing the 
5970 \emph on
5971 main()
5972 \emph default
5973  function and link
5974 \begin_inset LatexCommand \index{Linker}
5975
5976 \end_inset
5977
5978  the files together with the following command: 
5979 \newline
5980
5981 \newline
5982
5983 \family sans
5984 \series bold
5985 sdcc\InsetSpace ~
5986 foomain.c\InsetSpace ~
5987 foo1.rel\InsetSpace ~
5988 foo2.rel
5989 \family default
5990 \series default
5991
5992 \begin_inset LatexCommand \index{<file>.rel}
5993
5994 \end_inset
5995
5996
5997 \newline
5998
5999 \newline
6000 Alternatively, 
6001 \emph on
6002 foomain.c 
6003 \emph default
6004 can be separately compiled as well: 
6005 \family sans
6006 \series bold
6007
6008 \newline
6009
6010 \newline
6011 sdcc\InsetSpace ~
6012 -c\InsetSpace ~
6013 foomain.c
6014 \newline
6015 sdcc foomain.rel foo1.rel foo2.rel
6016 \newline
6017
6018 \newline
6019
6020 \family default
6021 \series default
6022 The file containing the 
6023 \emph on
6024 main()
6025 \emph default
6026  function
6027 \emph on
6028  
6029 \emph default
6030 \noun on
6031 must
6032 \noun default
6033  be the 
6034 \noun on
6035 first
6036 \noun default
6037  file specified in the command line, since the linkage editor processes
6038  file in the order they are presented to it.
6039  The linker is invoked from SDCC using a script file with extension .lnk
6040 \begin_inset LatexCommand \index{<file>.lnk}
6041
6042 \end_inset
6043
6044 .
6045  You can view this file to troubleshoot linking problems such as those arising
6046  from missing libraries.
6047 \end_layout
6048
6049 \begin_layout Subsection
6050 Projects with Additional Libraries
6051 \begin_inset LatexCommand \index{Libraries}
6052
6053 \end_inset
6054
6055
6056 \end_layout
6057
6058 \begin_layout Standard
6059 Some reusable routines may be compiled into a library, see the documentation
6060  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6061  for how to create a 
6062 \emph on
6063 .lib
6064 \begin_inset LatexCommand \index{<file>.lib}
6065
6066 \end_inset
6067
6068
6069 \emph default
6070  library file.
6071  Libraries created in this manner can be included in the command line.
6072  Make sure you include the -L <library-path> option to tell the linker where
6073  to look for these files if they are not in the current directory.
6074  Here is an example, assuming you have the source file 
6075 \emph on
6076 foomain.c
6077 \emph default
6078  and a library
6079 \emph on
6080  foolib.lib
6081 \emph default
6082  in the directory 
6083 \emph on
6084 mylib
6085 \emph default
6086  (if that is not the same as your current project):
6087 \newline
6088
6089 \newline
6090
6091 \family sans
6092 \series bold
6093 sdcc foomain.c foolib.lib -L mylib
6094 \newline
6095
6096 \newline
6097
6098 \family default
6099 \series default
6100 Note here that
6101 \emph on
6102  mylib
6103 \emph default
6104  must be an absolute path name.
6105 \newline
6106
6107 \newline
6108 The most efficient way to use libraries is
6109  to keep separate modules in separate source files.
6110  The lib file now should name all the modules.rel
6111 \begin_inset LatexCommand \index{<file>.rel}
6112
6113 \end_inset
6114
6115  files.
6116  For an example see the standard library file 
6117 \emph on
6118 libsdcc.lib
6119 \emph default
6120  in the directory <installdir>/share/lib/small.
6121 \end_layout
6122
6123 \begin_layout Subsection
6124 Using sdcclib to Create and Manage Libraries
6125 \begin_inset LatexCommand \index{sdcclib}
6126
6127 \end_inset
6128
6129
6130 \end_layout
6131
6132 \begin_layout Standard
6133 Alternatively, instead of having a .rel file for each entry on the library
6134  file as described in the preceding section, sdcclib can be used to embed
6135  all the modules belonging to such library in the library file itself.
6136  This results in a larger library file, but it greatly reduces the number
6137  of disk files accessed by the linker.
6138   Additionally, the packed library file contains an index of all include
6139  modules and symbols that significantly speeds up the linking process.
6140  To display a list of options supported by sdcclib type:
6141 \newline
6142
6143 \end_layout
6144
6145 \begin_layout Standard
6146
6147 \family sans
6148 \series bold
6149 sdcclib -?
6150 \begin_inset LatexCommand \index{sdcclib}
6151
6152 \end_inset
6153
6154
6155 \newline
6156
6157 \newline
6158
6159 \family default
6160 \series default
6161 To create a new library file, start by compiling all the required modules.
6162  For example:
6163 \newline
6164
6165 \end_layout
6166
6167 \begin_layout Standard
6168
6169 \family sans
6170 \series bold
6171 sdcc -c _divsint.c
6172 \end_layout
6173
6174 \begin_layout Standard
6175
6176 \family sans
6177 \series bold
6178 sdcc -c _divuint.c
6179 \end_layout
6180
6181 \begin_layout Standard
6182
6183 \family sans
6184 \series bold
6185 sdcc -c _modsint.c
6186 \end_layout
6187
6188 \begin_layout Standard
6189
6190 \family sans
6191 \series bold
6192 sdcc -c _moduint.c
6193 \end_layout
6194
6195 \begin_layout Standard
6196
6197 \family sans
6198 \series bold
6199 sdcc -c _mulint.c
6200 \newline
6201
6202 \end_layout
6203
6204 \begin_layout Standard
6205 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6206  and _mulint.rel.
6207  The next step is to add the .rel files to the library file:
6208 \newline
6209
6210 \end_layout
6211
6212 \begin_layout Standard
6213
6214 \family sans
6215 \series bold
6216 sdcclib libint.lib _divsint.rel
6217 \family default
6218
6219 \begin_inset LatexCommand \index{sdcclib}
6220
6221 \end_inset
6222
6223
6224 \end_layout
6225
6226 \begin_layout Standard
6227
6228 \family sans
6229 \series bold
6230 sdcclib libint.lib _divuint.rel
6231 \end_layout
6232
6233 \begin_layout Standard
6234
6235 \family sans
6236 \series bold
6237 sdcclib libint.lib _modsint.rel
6238 \end_layout
6239
6240 \begin_layout Standard
6241
6242 \family sans
6243 \series bold
6244 sdcclib libint.lib _moduint.rel
6245 \end_layout
6246
6247 \begin_layout Standard
6248
6249 \family sans
6250 \series bold
6251 sdcclib libint.lib _mulint.rel
6252 \series default
6253
6254 \newline
6255
6256 \end_layout
6257
6258 \begin_layout Standard
6259 If the file already exists in the library, it will be replaced.
6260  To see what modules and symbols are included in the library, options -s
6261  and -m are available.
6262  For example:
6263 \newline
6264
6265 \newline
6266
6267 \family sans
6268 \series bold
6269 sdcclib -s libint.lib
6270 \family default
6271
6272 \begin_inset LatexCommand \index{sdcclib}
6273
6274 \end_inset
6275
6276
6277 \newline
6278
6279 \family typewriter
6280 \series default
6281 _divsint.rel:
6282 \end_layout
6283
6284 \begin_layout Standard
6285
6286 \family typewriter
6287 __divsint_a_1_1
6288 \end_layout
6289
6290 \begin_layout Standard
6291
6292 \family typewriter
6293 __divsint_PARM_2
6294 \end_layout
6295
6296 \begin_layout Standard
6297
6298 \family typewriter
6299 __divsint
6300 \newline
6301 _divuint.rel:
6302 \end_layout
6303
6304 \begin_layout Standard
6305
6306 \family typewriter
6307 __divuint_a_1_1
6308 \end_layout
6309
6310 \begin_layout Standard
6311
6312 \family typewriter
6313 __divuint_PARM_2
6314 \end_layout
6315
6316 \begin_layout Standard
6317
6318 \family typewriter
6319 __divuint_reste_1_1
6320 \end_layout
6321
6322 \begin_layout Standard
6323
6324 \family typewriter
6325 __divuint_count_1_1
6326 \end_layout
6327
6328 \begin_layout Standard
6329
6330 \family typewriter
6331 __divuint
6332 \newline
6333 _modsint.rel:
6334 \end_layout
6335
6336 \begin_layout Standard
6337
6338 \family typewriter
6339 __modsint_a_1_1
6340 \end_layout
6341
6342 \begin_layout Standard
6343
6344 \family typewriter
6345 __modsint_PARM_2
6346 \end_layout
6347
6348 \begin_layout Standard
6349
6350 \family typewriter
6351 __modsint
6352 \newline
6353 _moduint.rel:
6354 \end_layout
6355
6356 \begin_layout Standard
6357
6358 \family typewriter
6359 __moduint_a_1_1
6360 \end_layout
6361
6362 \begin_layout Standard
6363
6364 \family typewriter
6365 __moduint_PARM_2
6366 \end_layout
6367
6368 \begin_layout Standard
6369
6370 \family typewriter
6371 __moduint_count_1_1
6372 \end_layout
6373
6374 \begin_layout Standard
6375
6376 \family typewriter
6377 __moduint
6378 \newline
6379 _mulint.rel:
6380 \end_layout
6381
6382 \begin_layout Standard
6383
6384 \family typewriter
6385 __mulint_PARM_2
6386 \end_layout
6387
6388 \begin_layout Standard
6389
6390 \family typewriter
6391 __mulint
6392 \family default
6393 \series bold
6394
6395 \newline
6396
6397 \end_layout
6398
6399 \begin_layout Standard
6400 If the source files are compiled using -
6401 \begin_inset ERT
6402 status collapsed
6403
6404 \begin_layout Standard
6405
6406
6407 \backslash
6408 /
6409 \end_layout
6410
6411 \end_inset
6412
6413 -debug
6414 \begin_inset LatexCommand \index{-\/-debug}
6415
6416 \end_inset
6417
6418 , the corresponding debug information file .adb will be include in the library
6419  file as well.
6420  The library files created with sdcclib are plain text files, so they can
6421  be viewed with a text editor.
6422  It is not recomended to modify a library file created with sdcclib using
6423  a text editor, as there are file indexes numbers located accross the file
6424  used by the linker to quickly locate the required module to link.
6425  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6426  it can be safely deleted, since all the information required for linking
6427  is embedded in the library file itself.
6428  Library files created using sdcclib are used as described in the preceding
6429  sections.
6430 \begin_inset VSpace bigskip
6431 \end_inset
6432
6433
6434 \end_layout
6435
6436 \begin_layout Section
6437 Command Line Options
6438 \begin_inset LatexCommand \index{Command Line Options}
6439
6440 \end_inset
6441
6442
6443 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6444
6445 \end_inset
6446
6447
6448 \end_layout
6449
6450 \begin_layout Subsection
6451 Processor Selection Options
6452 \begin_inset LatexCommand \index{Options processor selection}
6453
6454 \end_inset
6455
6456
6457 \begin_inset LatexCommand \index{Processor selection options}
6458
6459 \end_inset
6460
6461
6462 \end_layout
6463
6464 \begin_layout List
6465 \labelwidthstring 00.00.0000
6466
6467 \series bold
6468 -mmcs51
6469 \begin_inset LatexCommand \index{-mmcs51}
6470
6471 \end_inset
6472
6473
6474 \series default
6475  Generate code for the Intel MCS51
6476 \begin_inset LatexCommand \index{MCS51}
6477
6478 \end_inset
6479
6480  family of processors.
6481  This is the default processor target.
6482 \end_layout
6483
6484 \begin_layout List
6485 \labelwidthstring 00.00.0000
6486
6487 \series bold
6488 -mds390
6489 \begin_inset LatexCommand \index{-mds390}
6490
6491 \end_inset
6492
6493
6494 \series default
6495  Generate code for the Dallas DS80C390
6496 \begin_inset LatexCommand \index{DS80C390}
6497
6498 \end_inset
6499
6500  processor.
6501 \end_layout
6502
6503 \begin_layout List
6504 \labelwidthstring 00.00.0000
6505
6506 \series bold
6507 -mds400
6508 \begin_inset LatexCommand \index{-mds400}
6509
6510 \end_inset
6511
6512
6513 \series default
6514  Generate code for the Dallas DS80C400
6515 \begin_inset LatexCommand \index{DS80C400}
6516
6517 \end_inset
6518
6519  processor.
6520 \end_layout
6521
6522 \begin_layout List
6523 \labelwidthstring 00.00.0000
6524
6525 \series bold
6526 -mhc08
6527 \begin_inset LatexCommand \index{-mhc08}
6528
6529 \end_inset
6530
6531
6532 \series default
6533  Generate code for the Freescale/Motorola HC08
6534 \begin_inset LatexCommand \index{HC08}
6535
6536 \end_inset
6537
6538  family of processors.
6539 \end_layout
6540
6541 \begin_layout List
6542 \labelwidthstring 00.00.0000
6543
6544 \series bold
6545 -mz80
6546 \begin_inset LatexCommand \index{-mz80}
6547
6548 \end_inset
6549
6550
6551 \series default
6552  Generate code for the Zilog Z80
6553 \begin_inset LatexCommand \index{Z80}
6554
6555 \end_inset
6556
6557  family of processors.
6558 \end_layout
6559
6560 \begin_layout List
6561 \labelwidthstring 00.00.0000
6562
6563 \series bold
6564 -mgbz80
6565 \begin_inset LatexCommand \index{-mgbz80}
6566
6567 \end_inset
6568
6569
6570 \series default
6571  Generate code for the GameBoy Z80
6572 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6573
6574 \end_inset
6575
6576  processor (Not actively maintained).
6577 \end_layout
6578
6579 \begin_layout List
6580 \labelwidthstring 00.00.0000
6581
6582 \series bold
6583 -mavr
6584 \begin_inset LatexCommand \index{-mavr}
6585
6586 \end_inset
6587
6588
6589 \series default
6590  Generate code for the Atmel AVR
6591 \begin_inset LatexCommand \index{AVR}
6592
6593 \end_inset
6594
6595  processor (Not maintained, not complete).
6596  AVR users should probably have a look at winavr 
6597 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6598
6599 \end_inset
6600
6601  or 
6602 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6603
6604 \end_inset
6605
6606 , which is based on AVR-port of the gcc compiler.
6607 \end_layout
6608
6609 \begin_layout Standard
6610 \begin_inset Note Note
6611 status collapsed
6612
6613 \begin_layout Standard
6614 I think it is fair to direct users there for now.
6615  Open source is also about avoiding unnecessary work .
6616  But I didn't find the 'official' link.
6617 \end_layout
6618
6619 \end_inset
6620
6621
6622 \end_layout
6623
6624 \begin_layout List
6625 \labelwidthstring 00.00.0000
6626
6627 \series bold
6628 -mpic14
6629 \begin_inset LatexCommand \index{-mpic14}
6630
6631 \end_inset
6632
6633
6634 \series default
6635  Generate code for the Microchip PIC 14
6636 \begin_inset LatexCommand \index{PIC14}
6637
6638 \end_inset
6639
6640 -bit processors (p16f84 and variants.
6641  In development, not complete).
6642 \end_layout
6643
6644 \begin_layout Standard
6645 \begin_inset Note Note
6646 status collapsed
6647
6648 \begin_layout Standard
6649 p16f627 p16f628 p16f84 p16f873 p16f877?
6650 \end_layout
6651
6652 \end_inset
6653
6654
6655 \end_layout
6656
6657 \begin_layout List
6658 \labelwidthstring 00.00.0000
6659
6660 \series bold
6661 -mpic16
6662 \begin_inset LatexCommand \index{-mpic16}
6663
6664 \end_inset
6665
6666
6667 \series default
6668  Generate code for the Microchip PIC 16
6669 \begin_inset LatexCommand \index{PIC16}
6670
6671 \end_inset
6672
6673 -bit processors (p18f452 and variants.
6674  In development, not complete).
6675 \end_layout
6676
6677 \begin_layout List
6678 \labelwidthstring 00.00.0000
6679
6680 \series bold
6681 -mtlcs900h
6682 \series default
6683  Generate code for the Toshiba TLCS-900H
6684 \begin_inset LatexCommand \index{TLCS-900H}
6685
6686 \end_inset
6687
6688  processor (Not maintained, not complete).
6689 \end_layout
6690
6691 \begin_layout List
6692 \labelwidthstring 00.00.0000
6693
6694 \series bold
6695 -mxa51
6696 \begin_inset LatexCommand \index{-mxa51}
6697
6698 \end_inset
6699
6700
6701 \series default
6702  Generate code for the Phillips XA51
6703 \begin_inset LatexCommand \index{XA51}
6704
6705 \end_inset
6706
6707  processor (Not maintained, not complete).
6708 \end_layout
6709
6710 \begin_layout Standard
6711 \begin_inset VSpace bigskip
6712 \end_inset
6713
6714
6715 \end_layout
6716
6717 \begin_layout Subsection
6718 Preprocessor Options
6719 \begin_inset LatexCommand \index{Options preprocessor}
6720
6721 \end_inset
6722
6723
6724 \begin_inset LatexCommand \index{Preprocessor options}
6725
6726 \end_inset
6727
6728
6729 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6730
6731 \end_inset
6732
6733
6734 \end_layout
6735
6736 \begin_layout List
6737 \labelwidthstring 00.00.0000
6738
6739 \series bold
6740 -I<path>
6741 \begin_inset LatexCommand \index{-I<path>}
6742
6743 \end_inset
6744
6745
6746 \series default
6747  The additional location where the preprocessor will look for <..h> or 
6748 \begin_inset Quotes eld
6749 \end_inset
6750
6751 ..h
6752 \begin_inset Quotes erd
6753 \end_inset
6754
6755  files.
6756 \end_layout
6757
6758 \begin_layout List
6759 \labelwidthstring 00.00.0000
6760
6761 \series bold
6762 -D<macro[=value]>
6763 \begin_inset LatexCommand \index{-D<macro[=value]>}
6764
6765 \end_inset
6766
6767
6768 \series default
6769  Command line definition of macros.
6770  Passed to the preprocessor.
6771 \end_layout
6772
6773 \begin_layout List
6774 \labelwidthstring 00.00.0000
6775
6776 \series bold
6777 -M
6778 \begin_inset LatexCommand \index{-M}
6779
6780 \end_inset
6781
6782
6783 \series default
6784  Tell the preprocessor to output a rule suitable for make describing the
6785  dependencies of each object file.
6786  For each source file, the preprocessor outputs one make-rule whose target
6787  is the object file name for that source file and whose dependencies are
6788  all the files `#include'd in it.
6789  This rule may be a single line or may be continued with `
6790 \backslash
6791 '-newline if it is long.
6792  The list of rules is printed on standard output instead of the preprocessed
6793  C program.
6794  `-M' implies `-E
6795 \begin_inset LatexCommand \index{-E}
6796
6797 \end_inset
6798
6799 '.
6800 \end_layout
6801
6802 \begin_layout List
6803 \labelwidthstring 00.00.0000
6804
6805 \series bold
6806 -C
6807 \begin_inset LatexCommand \index{-C}
6808
6809 \end_inset
6810
6811
6812 \series default
6813  Tell the preprocessor not to discard comments.
6814  Used with the `-E' option.
6815 \end_layout
6816
6817 \begin_layout List
6818 \labelwidthstring 00.00.0000
6819
6820 \series bold
6821 -MM
6822 \begin_inset LatexCommand \index{-MM}
6823
6824 \end_inset
6825
6826
6827 \size large
6828 \bar under
6829  
6830 \series default
6831 \size default
6832 \bar default
6833 Like `-M' but the output mentions only the user header files included with
6834  `#include 
6835 \begin_inset Quotes eld
6836 \end_inset
6837
6838 file"'.
6839  System header files included with `#include <file>' are omitted.
6840 \end_layout
6841
6842 \begin_layout List
6843 \labelwidthstring 00.00.0000
6844
6845 \series bold
6846 -Aquestion(answer)
6847 \begin_inset LatexCommand \index{-Aquestion(answer)}
6848
6849 \end_inset
6850
6851
6852 \series default
6853  Assert the answer answer for question, in case it is tested with a preprocessor
6854  conditional such as `#if #question(answer)'.
6855  `-A-' disables the standard assertions that normally describe the target
6856  machine.
6857 \end_layout
6858
6859 \begin_layout List
6860 \labelwidthstring 00.00.0000
6861
6862 \series bold
6863 -Umacro
6864 \begin_inset LatexCommand \index{-Umacro}
6865
6866 \end_inset
6867
6868
6869 \series default
6870  Undefine macro macro.
6871  `-U' options are evaluated after all `-D' options, but before any `-include'
6872  and `-imacros' options.
6873 \end_layout
6874
6875 \begin_layout List
6876 \labelwidthstring 00.00.0000
6877
6878 \series bold
6879 -dM
6880 \begin_inset LatexCommand \index{-dM}
6881
6882 \end_inset
6883
6884
6885 \series default
6886  Tell the preprocessor to output only a list of the macro definitions that
6887  are in effect at the end of preprocessing.
6888  Used with the `-E' option.
6889 \end_layout
6890
6891 \begin_layout List
6892 \labelwidthstring 00.00.0000
6893
6894 \series bold
6895 -dD
6896 \begin_inset LatexCommand \index{-dD}
6897
6898 \end_inset
6899
6900
6901 \series default
6902  Tell the preprocessor to pass all macro definitions into the output, in
6903  their proper sequence in the rest of the output.
6904 \end_layout
6905
6906 \begin_layout List
6907 \labelwidthstring 00.00.0000
6908
6909 \series bold
6910 -dN
6911 \begin_inset LatexCommand \index{-dN}
6912
6913 \end_inset
6914
6915
6916 \size large
6917 \bar under
6918  
6919 \series default
6920 \size default
6921 \bar default
6922 Like `-dD' except that the macro arguments and contents are omitted.
6923  Only `#define name' is included in the output.
6924 \end_layout
6925
6926 \begin_layout List
6927 \labelwidthstring 00.00.0000
6928
6929 \series bold
6930 -pedantic-parse-number
6931 \begin_inset LatexCommand \index{pedantic}
6932
6933 \end_inset
6934
6935
6936 \begin_inset LatexCommand \index{-pedantic-parse-number}
6937
6938 \end_inset
6939
6940
6941 \size large
6942 \bar under
6943
6944 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
6945
6946 \end_inset
6947
6948  
6949 \series default
6950 \size default
6951 \bar default
6952 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6953  and the macro LO_B(3) gets expanded.
6954  See also #pragma pedantic_parse_number 
6955 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
6956
6957 \end_inset
6958
6959  in section
6960 \begin_inset LatexCommand \ref{sec:Pragmas}
6961
6962 \end_inset
6963
6964  
6965 \emph on
6966 Note: this functionality is not in conformance with C99 standard!
6967 \end_layout
6968
6969 \begin_layout List
6970 \labelwidthstring 00.00.0000
6971
6972 \series bold
6973 -Wp\InsetSpace ~
6974 preprocessorOption[,preprocessorOption]
6975 \series default
6976
6977 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6978
6979 \end_inset
6980
6981 ...
6982  Pass the preprocessorOption to the preprocessor 
6983 \family typewriter
6984 sdcpp
6985 \family default
6986
6987 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6988
6989 \end_inset
6990
6991 .
6992  SDCC uses an adapted version of the preprocessor 
6993 \emph on
6994 cpp
6995 \emph default
6996  of the GNU Compiler Collection
6997 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6998
6999 \end_inset
7000
7001  (
7002 \emph on
7003 gcc
7004 \emph default
7005  
7006 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7007
7008 \end_inset
7009
7010 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7011 4.1.1\InsetSpace ~
7012 CPP\InsetSpace ~
7013 Manual
7014  at 
7015 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7016
7017 \end_inset
7018
7019 .
7020 \end_layout
7021
7022 \begin_layout Standard
7023 \begin_inset VSpace bigskip
7024 \end_inset
7025
7026
7027 \end_layout
7028
7029 \begin_layout Subsection
7030 Linker Options
7031 \begin_inset LatexCommand \index{Options linker}
7032
7033 \end_inset
7034
7035
7036 \begin_inset LatexCommand \index{Linker options}
7037
7038 \end_inset
7039
7040
7041 \end_layout
7042
7043 \begin_layout List
7044 \labelwidthstring 00.00.0000
7045
7046 \series bold
7047 -L\InsetSpace ~
7048 -
7049 \series default
7050
7051 \begin_inset ERT
7052 status collapsed
7053
7054 \begin_layout Standard
7055
7056
7057 \backslash
7058 /
7059 \end_layout
7060
7061 \end_inset
7062
7063
7064 \series bold
7065 -lib-path
7066 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7067
7068 \end_inset
7069
7070
7071 \begin_inset LatexCommand \index{-L -\/-lib-path}
7072
7073 \end_inset
7074
7075
7076 \series default
7077 \InsetSpace ~
7078 <absolute path to additional libraries> This option is passed to the linkage
7079  editor's additional libraries
7080 \begin_inset LatexCommand \index{Libraries}
7081
7082 \end_inset
7083
7084  search path.
7085  The path name must be absolute.
7086  Additional library files may be specified in the command line.
7087  See section Compiling programs for more details.
7088 \end_layout
7089
7090 \begin_layout List
7091 \labelwidthstring 00.00.0000
7092
7093 \series bold
7094 -
7095 \begin_inset ERT
7096 status collapsed
7097
7098 \begin_layout Standard
7099
7100
7101 \backslash
7102 /
7103 \end_layout
7104
7105 \end_inset
7106
7107 -xram-loc
7108 \series default
7109
7110 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7111
7112 \end_inset
7113
7114 \InsetSpace ~
7115 <Value> The start location of the external ram
7116 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7117
7118 \end_inset
7119
7120 , default value is 0.
7121  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7122 \begin_inset ERT
7123 status collapsed
7124
7125 \begin_layout Standard
7126
7127
7128 \backslash
7129 /
7130 \end_layout
7131
7132 \end_inset
7133
7134 -xram-loc 0x8000 or -
7135 \begin_inset ERT
7136 status collapsed
7137
7138 \begin_layout Standard
7139
7140
7141 \backslash
7142 /
7143 \end_layout
7144
7145 \end_inset
7146
7147 -xram-loc 32768.
7148 \end_layout
7149
7150 \begin_layout List
7151 \labelwidthstring 00.00.0000
7152
7153 \series bold
7154 -
7155 \begin_inset ERT
7156 status collapsed
7157
7158 \begin_layout Standard
7159
7160
7161 \backslash
7162 /
7163 \end_layout
7164
7165 \end_inset
7166
7167 -code-loc
7168 \series default
7169
7170 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7171
7172 \end_inset
7173
7174 \InsetSpace ~
7175 <Value> The start location of the code
7176 \begin_inset LatexCommand \index{code}
7177
7178 \end_inset
7179
7180  segment, default value 0.
7181  Note when this option is used the interrupt vector table
7182 \begin_inset LatexCommand \index{interrupt vector table}
7183
7184 \end_inset
7185
7186  is also relocated to the given address.
7187  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7188 \begin_inset ERT
7189 status collapsed
7190
7191 \begin_layout Standard
7192
7193
7194 \backslash
7195 /
7196 \end_layout
7197
7198 \end_inset
7199
7200 -code-loc 0x8000 or -
7201 \begin_inset ERT
7202 status collapsed
7203
7204 \begin_layout Standard
7205
7206
7207 \backslash
7208 /
7209 \end_layout
7210
7211 \end_inset
7212
7213 -code-loc 32768.
7214 \end_layout
7215
7216 \begin_layout List
7217 \labelwidthstring 00.00.0000
7218
7219 \series bold
7220 -
7221 \begin_inset ERT
7222 status collapsed
7223
7224 \begin_layout Standard
7225
7226
7227 \backslash
7228 /
7229 \end_layout
7230
7231 \end_inset
7232
7233 -stack-loc
7234 \series default
7235
7236 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7237
7238 \end_inset
7239
7240 \InsetSpace ~
7241 <Value> By default the stack
7242 \begin_inset LatexCommand \index{stack}
7243
7244 \end_inset
7245
7246  is placed after the data segment.
7247  Using this option the stack can be placed anywhere in the internal memory
7248  space of the 8051.
7249  The value entered can be in Hexadecimal or Decimal format, e.g.
7250  -
7251 \begin_inset ERT
7252 status collapsed
7253
7254 \begin_layout Standard
7255
7256
7257 \backslash
7258 /
7259 \end_layout
7260
7261 \end_inset
7262
7263 -stack-loc 0x20 or -
7264 \begin_inset ERT
7265 status collapsed
7266
7267 \begin_layout Standard
7268
7269
7270 \backslash
7271 /
7272 \end_layout
7273
7274 \end_inset
7275
7276 -stack-loc 32.
7277  Since the sp register is incremented before a push or call, the initial
7278  sp will be set to one byte prior the provided value.
7279  The provided value should not overlap any other memory areas such as used
7280  register banks or the data segment and with enough space for the current
7281  application.
7282  The 
7283 \series bold
7284 -
7285 \begin_inset ERT
7286 status collapsed
7287
7288 \begin_layout Standard
7289
7290
7291 \backslash
7292 /
7293 \end_layout
7294
7295 \end_inset
7296
7297 -pack-iram
7298 \series default
7299 \InsetSpace ~
7300
7301 \begin_inset LatexCommand \index{-\/-pack-iram}
7302
7303 \end_inset
7304
7305  option (which is now a default setting) will override this setting, so
7306  you should also specify the 
7307 \series bold
7308 -
7309 \begin_inset ERT
7310 status collapsed
7311
7312 \begin_layout Standard
7313
7314
7315 \backslash
7316 /
7317 \end_layout
7318
7319 \end_inset
7320
7321 -no-pack-iram
7322 \series default
7323 \InsetSpace ~
7324
7325 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7326
7327 \end_inset
7328
7329  option if you need to manually place the stack.
7330 \end_layout
7331
7332 \begin_layout List
7333 \labelwidthstring 00.00.0000
7334
7335 \series bold
7336 -
7337 \begin_inset ERT
7338 status collapsed
7339
7340 \begin_layout Standard
7341
7342
7343 \backslash
7344 /
7345 \end_layout
7346
7347 \end_inset
7348
7349 -xstack-loc
7350 \series default
7351
7352 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7353
7354 \end_inset
7355
7356 \InsetSpace ~
7357 <Value> By default the external stack
7358 \begin_inset LatexCommand \index{xstack}
7359
7360 \end_inset
7361
7362  is placed after the pdata
7363 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7364
7365 \end_inset
7366
7367  segment.
7368  Using this option the xstack can be placed anywhere in the external memory
7369  space of the 8051.
7370  The value entered can be in Hexadecimal or Decimal format, e.g.
7371  -
7372 \begin_inset ERT
7373 status collapsed
7374
7375 \begin_layout Standard
7376
7377
7378 \backslash
7379 /
7380 \end_layout
7381
7382 \end_inset
7383
7384 -xstack-loc 0x8000 or -
7385 \begin_inset ERT
7386 status collapsed
7387
7388 \begin_layout Standard
7389
7390
7391 \backslash
7392 /
7393 \end_layout
7394
7395 \end_inset
7396
7397 -stack-loc 32768.
7398  The provided value should not overlap any other memory areas such as the
7399  pdata or xdata segment and with enough space for the current application.
7400 \end_layout
7401
7402 \begin_layout List
7403 \labelwidthstring 00.00.0000
7404
7405 \series bold
7406 -
7407 \begin_inset ERT
7408 status collapsed
7409
7410 \begin_layout Standard
7411
7412
7413 \backslash
7414 /
7415 \end_layout
7416
7417 \end_inset
7418
7419 -data-loc
7420 \series default
7421
7422 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7423
7424 \end_inset
7425
7426 \InsetSpace ~
7427 <Value> The start location of the internal ram data
7428 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7429
7430 \end_inset
7431
7432  segment.
7433  The value entered can be in Hexadecimal or Decimal format, eg.
7434  -
7435 \begin_inset ERT
7436 status collapsed
7437
7438 \begin_layout Standard
7439
7440
7441 \backslash
7442 /
7443 \end_layout
7444
7445 \end_inset
7446
7447 -data-loc 0x20 or -
7448 \begin_inset ERT
7449 status collapsed
7450
7451 \begin_layout Standard
7452
7453
7454 \backslash
7455 /
7456 \end_layout
7457
7458 \end_inset
7459
7460 -data-loc 32.
7461  (By default, the start location of the internal ram data segment  is set
7462  as low as possible in memory, taking into account the used register banks
7463  and the bit segment at address 0x20.
7464  For example if register banks 0 and 1 are used without bit variables, the
7465  data segment will be set, if -
7466 \begin_inset ERT
7467 status collapsed
7468
7469 \begin_layout Standard
7470
7471
7472 \backslash
7473 /
7474 \end_layout
7475
7476 \end_inset
7477
7478 -data-loc is not used, to location 0x10.)
7479 \end_layout
7480
7481 \begin_layout List
7482 \labelwidthstring 00.00.0000
7483
7484 \series bold
7485 -
7486 \begin_inset ERT
7487 status collapsed
7488
7489 \begin_layout Standard
7490
7491
7492 \backslash
7493 /
7494 \end_layout
7495
7496 \end_inset
7497
7498 -idata-loc
7499 \series default
7500
7501 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7502
7503 \end_inset
7504
7505 \InsetSpace ~
7506 <Value> The start location of the indirectly addressable internal ram
7507 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7508
7509 \end_inset
7510
7511  of the 8051, default value is 0x80.
7512  The value entered can be in Hexadecimal or Decimal format, eg.
7513  -
7514 \begin_inset ERT
7515 status collapsed
7516
7517 \begin_layout Standard
7518
7519
7520 \backslash
7521 /
7522 \end_layout
7523
7524 \end_inset
7525
7526 -idata-loc 0x88 or -
7527 \begin_inset ERT
7528 status collapsed
7529
7530 \begin_layout Standard
7531
7532
7533 \backslash
7534 /
7535 \end_layout
7536
7537 \end_inset
7538
7539 -idata-loc 136.
7540 \end_layout
7541
7542 \begin_layout List
7543 \labelwidthstring 00.00.0000
7544
7545 \series bold
7546 -
7547 \begin_inset ERT
7548 status collapsed
7549
7550 \begin_layout Standard
7551
7552
7553 \backslash
7554 /
7555 \end_layout
7556
7557 \end_inset
7558
7559 -bit-loc
7560 \series default
7561 \InsetSpace ~
7562 <Value> The start location of the bit
7563 \begin_inset LatexCommand \index{bit}
7564
7565 \end_inset
7566
7567  addressable internal ram of the 8051.
7568  This is 
7569 \emph on
7570 not
7571 \emph default
7572  implemented yet.
7573  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7574 -bBSEG=<Value>.
7575 \end_layout
7576
7577 \begin_layout List
7578 \labelwidthstring 00.00.0000
7579
7580 \series bold
7581 -
7582 \begin_inset ERT
7583 status collapsed
7584
7585 \begin_layout Standard
7586
7587
7588 \backslash
7589 /
7590 \end_layout
7591
7592 \end_inset
7593
7594 -out-fmt-ihx
7595 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7596
7597 \end_inset
7598
7599
7600 \bar under
7601  
7602 \series default
7603 \bar default
7604 The linker output (final object code) is in Intel Hex format.
7605 \begin_inset LatexCommand \index{Intel hex format}
7606
7607 \end_inset
7608
7609  This is the default option.
7610  The format itself is documented in the documentation of srecord
7611 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7612
7613 \end_inset
7614
7615 .
7616 \end_layout
7617
7618 \begin_layout List
7619 \labelwidthstring 00.00.0000
7620
7621 \series bold
7622 -
7623 \begin_inset ERT
7624 status collapsed
7625
7626 \begin_layout Standard
7627
7628
7629 \backslash
7630 /
7631 \end_layout
7632
7633 \end_inset
7634
7635 -out-fmt-s19
7636 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7637
7638 \end_inset
7639
7640
7641 \bar under
7642  
7643 \series default
7644 \bar default
7645 The linker output (final object code) is in Motorola S19 format
7646 \begin_inset LatexCommand \index{Motorola S19 format}
7647
7648 \end_inset
7649
7650 .
7651  The format itself is documented in the documentation of srecord.
7652 \end_layout
7653
7654 \begin_layout List
7655 \labelwidthstring 00.00.0000
7656
7657 \series bold
7658 -
7659 \begin_inset ERT
7660 status collapsed
7661
7662 \begin_layout Standard
7663
7664
7665 \backslash
7666 /
7667 \end_layout
7668
7669 \end_inset
7670
7671 -out-fmt-elf
7672 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7673
7674 \end_inset
7675
7676
7677 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7678
7679 \end_inset
7680
7681
7682 \bar under
7683  
7684 \series default
7685 \bar default
7686 The linker output (final object code) is in ELF format
7687 \begin_inset LatexCommand \index{ELF format}
7688
7689 \end_inset
7690
7691 .
7692  (Currently only supported for the HC08
7693 \begin_inset LatexCommand \index{HC08}
7694
7695 \end_inset
7696
7697  processors)
7698 \end_layout
7699
7700 \begin_layout List
7701 \labelwidthstring 00.00.0000
7702
7703 \series bold
7704 -Wl\InsetSpace ~
7705 linkOption[,linkOption]
7706 \series default
7707
7708 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7709
7710 \end_inset
7711
7712 ...
7713  Pass the linkOption to the linker.
7714  If a bootloader is used an option like 
7715 \begin_inset Quotes sld
7716 \end_inset
7717
7718 -Wl\InsetSpace ~
7719 -bCSEG=0x1000
7720 \begin_inset Quotes srd
7721 \end_inset
7722
7723  would be typical to set the start of the code segment.
7724  See also #pragma constseg and #pragma codeseg in section 
7725 \begin_inset LatexCommand \ref{sec:Pragmas}
7726
7727 \end_inset
7728
7729  .
7730  File sdcc/as/doc/asxhtm.html has more on linker options.
7731 \end_layout
7732
7733 \begin_layout Standard
7734 \begin_inset VSpace bigskip
7735 \end_inset
7736
7737
7738 \end_layout
7739
7740 \begin_layout Subsection
7741 MCS51 Options
7742 \begin_inset LatexCommand \index{Options MCS51}
7743
7744 \end_inset
7745
7746
7747 \begin_inset LatexCommand \index{MCS51 options}
7748
7749 \end_inset
7750
7751
7752 \end_layout
7753
7754 \begin_layout List
7755 \labelwidthstring 00.00.0000
7756
7757 \series bold
7758 -
7759 \begin_inset ERT
7760 status collapsed
7761
7762 \begin_layout Standard
7763
7764
7765 \backslash
7766 /
7767 \end_layout
7768
7769 \end_inset
7770
7771 -model-small
7772 \begin_inset LatexCommand \index{-\/-model-small}
7773
7774 \end_inset
7775
7776
7777 \series default
7778 \size large
7779 \emph on
7780  
7781 \size default
7782 \emph default
7783 Generate code for Small Model programs, see section Memory Models for more
7784  details.
7785  This is the default model.
7786 \end_layout
7787
7788 \begin_layout List
7789 \labelwidthstring 00.00.0000
7790
7791 \series bold
7792 -
7793 \begin_inset ERT
7794 status collapsed
7795
7796 \begin_layout Standard
7797
7798
7799 \backslash
7800 /
7801 \end_layout
7802
7803 \end_inset
7804
7805 -model-medium
7806 \begin_inset LatexCommand \index{-\/-model-medium}
7807
7808 \end_inset
7809
7810
7811 \series default
7812  Generate code for Medium model programs, see section Memory Models for
7813  more details.
7814  If this option is used all source files in the project have to be compiled
7815  with this option.
7816  It must also be used when invoking the linker.
7817 \end_layout
7818
7819 \begin_layout List
7820 \labelwidthstring 00.00.0000
7821
7822 \series bold
7823 -
7824 \begin_inset ERT
7825 status collapsed
7826
7827 \begin_layout Standard
7828
7829
7830 \backslash
7831 /
7832 \end_layout
7833
7834 \end_inset
7835
7836 -model-large
7837 \begin_inset LatexCommand \index{-\/-model-large}
7838
7839 \end_inset
7840
7841
7842 \series default
7843  Generate code for Large model programs, see section Memory Models for more
7844  details.
7845  If this option is used all source files in the project have to be compiled
7846  with this option.
7847  It must also be used when invoking the linker.
7848 \end_layout
7849
7850 \begin_layout List
7851 \labelwidthstring 00.00.0000
7852
7853 \series bold
7854 -
7855 \begin_inset ERT
7856 status collapsed
7857
7858 \begin_layout Standard
7859
7860
7861 \backslash
7862 /
7863 \end_layout
7864
7865 \end_inset
7866
7867 -xstack
7868 \begin_inset LatexCommand \index{-\/-xstack}
7869
7870 \end_inset
7871
7872
7873 \series default
7874  Uses a pseudo stack in the pdata
7875 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7876
7877 \end_inset
7878
7879  area (usually the first 256 bytes in the external ram) for allocating variables
7880  and passing parameters.
7881  See section 
7882 \begin_inset LatexCommand \ref{sub:External-Stack}
7883
7884 \end_inset
7885
7886 \InsetSpace ~
7887  External Stack for more details.
7888 \end_layout
7889
7890 \begin_layout List
7891 \labelwidthstring 00.00.0000
7892
7893 \series bold
7894 -
7895 \begin_inset ERT
7896 status collapsed
7897
7898 \begin_layout Standard
7899
7900
7901 \backslash
7902 /
7903 \end_layout
7904
7905 \end_inset
7906
7907 -iram-size
7908 \series default
7909 \InsetSpace ~
7910 <Value>
7911 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7912
7913 \end_inset
7914
7915  Causes the linker to check if the internal ram usage is within limits of
7916  the given value.
7917 \end_layout
7918
7919 \begin_layout List
7920 \labelwidthstring 00.00.0000
7921
7922 \series bold
7923 -
7924 \begin_inset ERT
7925 status collapsed
7926
7927 \begin_layout Standard
7928
7929
7930 \backslash
7931 /
7932 \end_layout
7933
7934 \end_inset
7935
7936 -xram-size
7937 \series default
7938 \InsetSpace ~
7939 <Value>
7940 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7941
7942 \end_inset
7943
7944  Causes the linker to check if the external ram usage is within limits of
7945  the given value.
7946 \end_layout
7947
7948 \begin_layout List
7949 \labelwidthstring 00.00.0000
7950
7951 \series bold
7952 -
7953 \begin_inset ERT
7954 status collapsed
7955
7956 \begin_layout Standard
7957
7958
7959 \backslash
7960 /
7961 \end_layout
7962
7963 \end_inset
7964
7965 -code-size
7966 \series default
7967 \InsetSpace ~
7968 <Value>
7969 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7970
7971 \end_inset
7972
7973  Causes the linker to check if the code memory usage is within limits of
7974  the given value.
7975 \end_layout
7976
7977 \begin_layout List
7978 \labelwidthstring 00.00.0000
7979
7980 \series bold
7981 -
7982 \begin_inset ERT
7983 status collapsed
7984
7985 \begin_layout Standard
7986
7987
7988 \backslash
7989 /
7990 \end_layout
7991
7992 \end_inset
7993
7994 -stack-size
7995 \series default
7996 \InsetSpace ~
7997 <Value>
7998 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7999
8000 \end_inset
8001
8002  Causes the linker to check if there is at minimum <Value> bytes for stack.
8003 \end_layout
8004
8005 \begin_layout List
8006 \labelwidthstring 00.00.0000
8007
8008 \series bold
8009 -
8010 \begin_inset ERT
8011 status collapsed
8012
8013 \begin_layout Standard
8014
8015
8016 \backslash
8017 /
8018 \end_layout
8019
8020 \end_inset
8021
8022 -pack-iram
8023 \series default
8024 \InsetSpace ~
8025
8026 \begin_inset LatexCommand \index{-\/-pack-iram}
8027
8028 \end_inset
8029
8030  Causes the linker to use unused register banks for data variables and pack
8031  data, idata and stack together.
8032  This is the default now.
8033 \end_layout
8034
8035 \begin_layout List
8036 \labelwidthstring 00.00.0000
8037
8038 \series bold
8039 -
8040 \begin_inset ERT
8041 status collapsed
8042
8043 \begin_layout Standard
8044
8045
8046 \backslash
8047 /
8048 \end_layout
8049
8050 \end_inset
8051
8052 -no-pack-iram
8053 \series default
8054 \InsetSpace ~
8055
8056 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8057
8058 \end_inset
8059
8060  Causes the linker to use old style for allocating memory areas.
8061 \end_layout
8062
8063 \begin_layout Standard
8064 \begin_inset VSpace bigskip
8065 \end_inset
8066
8067
8068 \end_layout
8069
8070 \begin_layout Subsection
8071 DS390 / DS400 Options
8072 \begin_inset LatexCommand \index{Options DS390}
8073
8074 \end_inset
8075
8076
8077 \begin_inset LatexCommand \index{DS390}
8078
8079 \end_inset
8080
8081
8082 \end_layout
8083
8084 \begin_layout List
8085 \labelwidthstring 00.00.0000
8086
8087 \series bold
8088 -
8089 \begin_inset ERT
8090 status collapsed
8091
8092 \begin_layout Standard
8093
8094
8095 \backslash
8096 /
8097 \end_layout
8098
8099 \end_inset
8100
8101 -model-flat24
8102 \series default
8103
8104 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8105
8106 \end_inset
8107
8108
8109 \size large
8110 \emph on
8111  
8112 \size default
8113 \emph default
8114 Generate 24-bit flat mode code.
8115  This is the one and only that the ds390 code generator supports right now
8116  and is default when using 
8117 \emph on
8118 -mds390
8119 \emph default
8120 .
8121  See section Memory Models for more details.
8122 \end_layout
8123
8124 \begin_layout List
8125 \labelwidthstring 00.00.0000
8126
8127 \series bold
8128 -
8129 \begin_inset ERT
8130 status collapsed
8131
8132 \begin_layout Standard
8133
8134
8135 \backslash
8136 /
8137 \end_layout
8138
8139 \end_inset
8140
8141 -protect-sp-update
8142 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8143
8144 \end_inset
8145
8146
8147 \series default
8148  disable interrupts during ESP:SP updates.
8149 \end_layout
8150
8151 \begin_layout List
8152 \labelwidthstring 00.00.0000
8153
8154 \series bold
8155 -
8156 \begin_inset ERT
8157 status collapsed
8158
8159 \begin_layout Standard
8160
8161
8162 \backslash
8163 /
8164 \end_layout
8165
8166 \end_inset
8167
8168 -stack-10bit
8169 \series default
8170
8171 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8172
8173 \end_inset
8174
8175  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8176  This is the one and only that the ds390 code generator supports right now
8177  and is default when using 
8178 \emph on
8179 -mds390
8180 \emph default
8181 .
8182  In this mode, the stack is located in the lower 1K of the internal RAM,
8183  which is mapped to 0x400000.
8184  Note that the support is incomplete, since it still uses a single byte
8185  as the stack pointer.
8186  This means that only the lower 256 bytes of the potential 1K stack space
8187  will actually be used.
8188  However, this does allow you to reclaim the precious 256 bytes of low RAM
8189  for use for the DATA and IDATA segments.
8190  The compiler will not generate any code to put the processor into 10 bit
8191  stack mode.
8192  It is important to ensure that the processor is in this mode before calling
8193  any re-entrant functions compiled with this option.
8194  In principle, this should work with the 
8195 \emph on
8196 -
8197 \begin_inset ERT
8198 status collapsed
8199
8200 \begin_layout Standard
8201
8202
8203 \backslash
8204 /
8205 \end_layout
8206
8207 \end_inset
8208
8209 -stack-auto
8210 \begin_inset LatexCommand \index{-\/-stack-auto}
8211
8212 \end_inset
8213
8214
8215 \emph default
8216  option, but that has not been tested.
8217  It is incompatible with the 
8218 \emph on
8219 -
8220 \begin_inset ERT
8221 status collapsed
8222
8223 \begin_layout Standard
8224
8225
8226 \backslash
8227 /
8228 \end_layout
8229
8230 \end_inset
8231
8232 -xstack
8233 \begin_inset LatexCommand \index{-\/-xstack}
8234
8235 \end_inset
8236
8237
8238 \emph default
8239  option.
8240  It also only makes sense if the processor is in 24 bit contiguous addressing
8241  mode (see the 
8242 \emph on
8243 -
8244 \begin_inset ERT
8245 status collapsed
8246
8247 \begin_layout Standard
8248
8249
8250 \backslash
8251 /
8252 \end_layout
8253
8254 \end_inset
8255
8256 -model-flat24 option
8257 \emph default
8258 ).
8259 \series bold
8260
8261 \begin_inset Note Note
8262 status collapsed
8263
8264 \begin_layout List
8265 \labelwidthstring 00.00.0000
8266
8267 \series bold
8268 --stack-8-bit - switches off the 10-bit mode
8269 \end_layout
8270
8271 \end_inset
8272
8273
8274 \end_layout
8275
8276 \begin_layout List
8277 \labelwidthstring 00.00.0000
8278
8279 \series bold
8280 -
8281 \begin_inset ERT
8282 status collapsed
8283
8284 \begin_layout Standard
8285
8286
8287 \backslash
8288 /
8289 \end_layout
8290
8291 \end_inset
8292
8293 -stack-probe
8294 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8295
8296 \end_inset
8297
8298
8299 \series default
8300  insert call to function __stack_probe at each function prologue.
8301 \end_layout
8302
8303 \begin_layout List
8304 \labelwidthstring 00.00.0000
8305
8306 \series bold
8307 -
8308 \begin_inset ERT
8309 status collapsed
8310
8311 \begin_layout Standard
8312
8313
8314 \backslash
8315 /
8316 \end_layout
8317
8318 \end_inset
8319
8320 -tini-libid
8321 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8322
8323 \end_inset
8324
8325
8326 \series default
8327  <nnnn> LibraryID used in -mTININative.
8328  
8329 \end_layout
8330
8331 \begin_layout List
8332 \labelwidthstring 00.00.0000
8333
8334 \series bold
8335 -
8336 \begin_inset ERT
8337 status collapsed
8338
8339 \begin_layout Standard
8340
8341
8342 \backslash
8343 /
8344 \end_layout
8345
8346 \end_inset
8347
8348 -use-accelerator
8349 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8350
8351 \end_inset
8352
8353
8354 \series default
8355  generate code for DS390 Arithmetic Accelerator.
8356  
8357 \end_layout
8358
8359 \begin_layout Standard
8360 \begin_inset VSpace bigskip
8361 \end_inset
8362
8363
8364 \end_layout
8365
8366 \begin_layout Subsection
8367 Z80 Options
8368 \begin_inset LatexCommand \index{Options Z80}
8369
8370 \end_inset
8371
8372
8373 \begin_inset LatexCommand \index{Z80}
8374
8375 \end_inset
8376
8377
8378 \end_layout
8379
8380 \begin_layout List
8381 \labelwidthstring 00.00.0000
8382
8383 \series bold
8384 -
8385 \begin_inset ERT
8386 status collapsed
8387
8388 \begin_layout Standard
8389
8390
8391 \backslash
8392 /
8393 \end_layout
8394
8395 \end_inset
8396
8397 -callee-saves-bc
8398 \series default
8399
8400 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8401
8402 \end_inset
8403
8404
8405 \size large
8406 \emph on
8407  
8408 \size default
8409 \emph default
8410 Force a called function to always save BC.
8411 \end_layout
8412
8413 \begin_layout List
8414 \labelwidthstring 00.00.0000
8415
8416 \series bold
8417 -
8418 \begin_inset ERT
8419 status collapsed
8420
8421 \begin_layout Standard
8422
8423
8424 \backslash
8425 /
8426 \end_layout
8427
8428 \end_inset
8429
8430 -no-std-crt0
8431 \series default
8432
8433 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8434
8435 \end_inset
8436
8437  When linking, skip the standard crt0.o object file.
8438  You must provide your own crt0.o for your system when linking.
8439  
8440 \end_layout
8441
8442 \begin_layout Standard
8443 \begin_inset VSpace bigskip
8444 \end_inset
8445
8446
8447 \end_layout
8448
8449 \begin_layout Subsection
8450 Optimization Options
8451 \begin_inset LatexCommand \index{Options optimization}
8452
8453 \end_inset
8454
8455
8456 \begin_inset LatexCommand \index{Optimization options}
8457
8458 \end_inset
8459
8460
8461 \end_layout
8462
8463 \begin_layout List
8464 \labelwidthstring 00.00.0000
8465
8466 \series bold
8467 -
8468 \begin_inset ERT
8469 status collapsed
8470
8471 \begin_layout Standard
8472
8473
8474 \backslash
8475 /
8476 \end_layout
8477
8478 \end_inset
8479
8480 -nogcse
8481 \begin_inset LatexCommand \index{-\/-nogcse}
8482
8483 \end_inset
8484
8485
8486 \series default
8487  Will not do global subexpression elimination, this option may be used when
8488  the compiler creates undesirably large stack/data spaces to store compiler
8489  temporaries (
8490 \emph on
8491 s
8492 \emph default
8493 pill 
8494 \emph on
8495 loc
8496 \emph default
8497 ations, sloc
8498 \begin_inset LatexCommand \index{sloc (spill location)}
8499
8500 \end_inset
8501
8502 ).
8503  A warning message will be generated when this happens and the compiler
8504  will indicate the number of extra bytes it allocated.
8505  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8506 nogcse
8507 \begin_inset LatexCommand \index{\#pragma nogcse}
8508
8509 \end_inset
8510
8511  can be used to turn off global subexpression elimination
8512 \begin_inset LatexCommand \index{Subexpression elimination}
8513
8514 \end_inset
8515
8516  for a given function only.
8517 \end_layout
8518
8519 \begin_layout List
8520 \labelwidthstring 00.00.0000
8521
8522 \series bold
8523 -
8524 \begin_inset ERT
8525 status collapsed
8526
8527 \begin_layout Standard
8528
8529
8530 \backslash
8531 /
8532 \end_layout
8533
8534 \end_inset
8535
8536 -noinvariant
8537 \begin_inset LatexCommand \index{-\/-noinvariant}
8538
8539 \end_inset
8540
8541
8542 \series default
8543  Will not do loop invariant optimizations, this may be turned off for reasons
8544  explained for the previous option.
8545  For more details of loop optimizations performed see Loop Invariants in
8546  section 
8547 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8548
8549 \end_inset
8550
8551 .
8552  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8553 noinvariant
8554 \begin_inset LatexCommand \index{\#pragma noinvariant}
8555
8556 \end_inset
8557
8558  can be used to turn off invariant optimizations for a given function only.
8559 \end_layout
8560
8561 \begin_layout List
8562 \labelwidthstring 00.00.0000
8563
8564 \series bold
8565 -
8566 \begin_inset ERT
8567 status collapsed
8568
8569 \begin_layout Standard
8570
8571
8572 \backslash
8573 /
8574 \end_layout
8575
8576 \end_inset
8577
8578 -noinduction
8579 \begin_inset LatexCommand \index{-\/-noinduction}
8580
8581 \end_inset
8582
8583
8584 \series default
8585  Will not do loop induction optimizations, see section strength reduction
8586  for more details.
8587  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8588 noinduction
8589 \begin_inset LatexCommand \index{\#pragma noinduction}
8590
8591 \end_inset
8592
8593  can be used to turn off induction optimizations for a given function only.
8594 \end_layout
8595
8596 \begin_layout List
8597 \labelwidthstring 00.00.0000
8598
8599 \series bold
8600 -
8601 \begin_inset ERT
8602 status collapsed
8603
8604 \begin_layout Standard
8605
8606
8607 \backslash
8608 /
8609 \end_layout
8610
8611 \end_inset
8612
8613 -nojtbound
8614 \begin_inset LatexCommand \index{-\/-nojtbound}
8615
8616 \end_inset
8617
8618
8619 \size large
8620 \bar under
8621  
8622 \series default
8623 \size default
8624 \bar default
8625  Will not generate boundary condition check when switch statements
8626 \begin_inset LatexCommand \index{switch statement}
8627
8628 \end_inset
8629
8630  are implemented using jump-tables.
8631  See section 
8632 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8633
8634 \end_inset
8635
8636 \InsetSpace ~
8637 Switch Statements for more details.
8638  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8639 nojtbound
8640 \begin_inset LatexCommand \index{\#pragma nojtbound}
8641
8642 \end_inset
8643
8644  can be used to turn off boundary checking for jump tables for a given function
8645  only.
8646 \end_layout
8647
8648 \begin_layout List
8649 \labelwidthstring 00.00.0000
8650
8651 \series bold
8652 -
8653 \begin_inset ERT
8654 status collapsed
8655
8656 \begin_layout Standard
8657
8658
8659 \backslash
8660 /
8661 \end_layout
8662
8663 \end_inset
8664
8665 -noloopreverse
8666 \begin_inset LatexCommand \index{-\/-noloopreverse}
8667
8668 \end_inset
8669
8670
8671 \series default
8672 \size large
8673  
8674 \size default
8675 Will not do loop reversal 
8676 \begin_inset LatexCommand \index{Loop reversing}
8677
8678 \end_inset
8679
8680 optimization.
8681 \end_layout
8682
8683 \begin_layout List
8684 \labelwidthstring 00.00.0000
8685 -
8686 \begin_inset ERT
8687 status collapsed
8688
8689 \begin_layout Standard
8690
8691
8692 \backslash
8693 /
8694 \end_layout
8695
8696 \end_inset
8697
8698 -
8699 \series bold
8700 nolabelopt
8701 \series default
8702  
8703 \begin_inset LatexCommand \index{-\/-nolabelopt }
8704
8705 \end_inset
8706
8707 Will not optimize labels (makes the dumpfiles more readable).
8708 \end_layout
8709
8710 \begin_layout List
8711 \labelwidthstring 00.00.0000
8712
8713 \series bold
8714 -
8715 \begin_inset ERT
8716 status collapsed
8717
8718 \begin_layout Standard
8719
8720
8721 \backslash
8722 /
8723 \end_layout
8724
8725 \end_inset
8726
8727 -no-xinit-opt
8728 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8729
8730 \end_inset
8731
8732
8733 \series default
8734  Will not memcpy initialized data from code space into xdata space.
8735  This saves a few bytes in code space if you don't have initialized data
8736 \begin_inset LatexCommand \index{Variable initialization}
8737
8738 \end_inset
8739
8740 .
8741 \end_layout
8742
8743 \begin_layout List
8744 \labelwidthstring 00.00.0000
8745
8746 \series bold
8747 -
8748 \begin_inset ERT
8749 status collapsed
8750
8751 \begin_layout Standard
8752
8753
8754 \backslash
8755 /
8756 \end_layout
8757
8758 \end_inset
8759
8760 -nooverlay
8761 \begin_inset LatexCommand \index{-\/-nooverlay}
8762
8763 \end_inset
8764
8765
8766 \series default
8767   The compiler will not overlay parameters and local variables of any function,
8768  see section Parameters and local variables for more details.
8769 \end_layout
8770
8771 \begin_layout List
8772 \labelwidthstring 00.00.0000
8773
8774 \series bold
8775 -
8776 \begin_inset ERT
8777 status collapsed
8778
8779 \begin_layout Standard
8780
8781
8782 \backslash
8783 /
8784 \end_layout
8785
8786 \end_inset
8787
8788 -no-peep
8789 \begin_inset LatexCommand \index{-\/-no-peep}
8790
8791 \end_inset
8792
8793
8794 \series default
8795  Disable peep-hole optimization with built-in rules.
8796 \end_layout
8797
8798 \begin_layout List
8799 \labelwidthstring 00.00.0000
8800
8801 \series bold
8802 -
8803 \begin_inset ERT
8804 status collapsed
8805
8806 \begin_layout Standard
8807
8808
8809 \backslash
8810 /
8811 \end_layout
8812
8813 \end_inset
8814
8815 -peep-file
8816 \series default
8817
8818 \begin_inset LatexCommand \index{-\/-peep-file}
8819
8820 \end_inset
8821
8822 \InsetSpace ~
8823 <filename> This option can be used to use additional rules to be used by
8824  the peep hole optimizer.
8825  See section 
8826 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8827
8828 \end_inset
8829
8830 \InsetSpace ~
8831 Peep Hole optimizations for details on how to write these rules.
8832 \end_layout
8833
8834 \begin_layout List
8835 \labelwidthstring 00.00.0000
8836
8837 \series bold
8838 -
8839 \begin_inset ERT
8840 status collapsed
8841
8842 \begin_layout Standard
8843
8844
8845 \backslash
8846 /
8847 \end_layout
8848
8849 \end_inset
8850
8851 -peep-asm
8852 \begin_inset LatexCommand \index{-\/-peep-asm}
8853
8854 \end_inset
8855
8856
8857 \series default
8858  Pass the inline assembler code through the peep hole optimizer.
8859  This can cause unexpected changes to inline assembler code, please go through
8860  the peephole optimizer
8861 \begin_inset LatexCommand \index{Peephole optimizer}
8862
8863 \end_inset
8864
8865  rules defined in the source file tree '<target>/peeph.def' before using
8866  this option.
8867 \end_layout
8868
8869 \begin_layout List
8870 \labelwidthstring 00.00.0000
8871
8872 \series bold
8873 -
8874 \begin_inset ERT
8875 status collapsed
8876
8877 \begin_layout Standard
8878
8879
8880 \backslash
8881 /
8882 \end_layout
8883
8884 \end_inset
8885
8886 -opt-code-speed
8887 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8888
8889 \end_inset
8890
8891
8892 \series default
8893  The compiler will optimize code generation towards fast code, possibly
8894  at the expense of code size.
8895 \end_layout
8896
8897 \begin_layout List
8898 \labelwidthstring 00.00.0000
8899
8900 \series bold
8901 -
8902 \begin_inset ERT
8903 status collapsed
8904
8905 \begin_layout Standard
8906
8907
8908 \backslash
8909 /
8910 \end_layout
8911
8912 \end_inset
8913
8914 -opt-code-size
8915 \begin_inset LatexCommand \index{-\/-opt-code-size}
8916
8917 \end_inset
8918
8919
8920 \series default
8921  The compiler will optimize code generation towards compact code, possibly
8922  at the expense of code speed.
8923 \end_layout
8924
8925 \begin_layout Standard
8926 \begin_inset VSpace bigskip
8927 \end_inset
8928
8929
8930 \end_layout
8931
8932 \begin_layout Subsection
8933 Other Options
8934 \begin_inset LatexCommand \index{Options other}
8935
8936 \end_inset
8937
8938
8939 \end_layout
8940
8941 \begin_layout List
8942 \labelwidthstring 00.00.0000
8943
8944 \series bold
8945 -c\InsetSpace ~
8946 -
8947 \begin_inset ERT
8948 status collapsed
8949
8950 \begin_layout Standard
8951
8952
8953 \backslash
8954 /
8955 \end_layout
8956
8957 \end_inset
8958
8959 -compile-only
8960 \begin_inset LatexCommand \index{-\/-compile-only}
8961
8962 \end_inset
8963
8964
8965 \begin_inset LatexCommand \index{-c -\/-compile-only}
8966
8967 \end_inset
8968
8969
8970 \series default
8971  will compile and assemble the source, but will not call the linkage editor.
8972 \end_layout
8973
8974 \begin_layout List
8975 \labelwidthstring 00.00.0000
8976
8977 \series bold
8978 -
8979 \series default
8980
8981 \begin_inset ERT
8982 status collapsed
8983
8984 \begin_layout Standard
8985
8986
8987 \backslash
8988 /
8989 \end_layout
8990
8991 \end_inset
8992
8993
8994 \series bold
8995 -c1mode
8996 \begin_inset LatexCommand \index{-\/-c1mode}
8997
8998 \end_inset
8999
9000
9001 \series default
9002  reads the preprocessed source from standard input and compiles it.
9003  The file name for the assembler output must be specified using the -o option.
9004 \end_layout
9005
9006 \begin_layout List
9007 \labelwidthstring 00.00.0000
9008
9009 \series bold
9010 -E
9011 \begin_inset LatexCommand \index{-E}
9012
9013 \end_inset
9014
9015
9016 \series default
9017  Run only the C preprocessor.
9018  Preprocess all the C source files specified and output the results to standard
9019  output.
9020 \end_layout
9021
9022 \begin_layout List
9023 \labelwidthstring 00.00.0000
9024
9025 \series bold
9026 -o\InsetSpace ~
9027 <path/file>
9028 \begin_inset LatexCommand \index{-o <path/file>}
9029
9030 \end_inset
9031
9032  
9033 \series default
9034 The output path where everything will be placed or the file name used for
9035  all generated output files.
9036  If the parameter is a path, it must have a trailing slash (or backslash
9037  for the Windows binaries) to be recognized as a path.
9038
9039 \emph on
9040  
9041 \emph default
9042 Note for Windows users: if the path contains spaces, it should be surrounded
9043  by quotes.
9044  The trailing backslash should be doubled in order to prevent escaping the
9045  final quote, for example: 
9046 \emph on
9047 -o 
9048 \begin_inset Quotes sld
9049 \end_inset
9050
9051 F:
9052 \backslash
9053 Projects
9054 \backslash
9055 test3
9056 \backslash
9057 output 1
9058 \backslash
9059
9060 \backslash
9061
9062 \begin_inset Quotes srd
9063 \end_inset
9064
9065
9066 \emph default
9067  or put after the final quote, for example: 
9068 \emph on
9069 -o 
9070 \begin_inset Quotes sld
9071 \end_inset
9072
9073 F:
9074 \backslash
9075 Projects
9076 \backslash
9077 test3
9078 \backslash
9079 output 1
9080 \begin_inset Quotes srd
9081 \end_inset
9082
9083
9084 \backslash
9085
9086 \emph default
9087 .
9088  The path using slashes for directory delimiters can be used too, for example:
9089  
9090 \emph on
9091 -o 
9092 \begin_inset Quotes sld
9093 \end_inset
9094
9095 F:/Projects/test3/output 1/
9096 \begin_inset Quotes srd
9097 \end_inset
9098
9099
9100 \emph default
9101 .
9102 \end_layout
9103
9104 \begin_layout List
9105 \labelwidthstring 00.00.0000
9106
9107 \series bold
9108 -
9109 \begin_inset ERT
9110 status collapsed
9111
9112 \begin_layout Standard
9113
9114
9115 \backslash
9116 /
9117 \end_layout
9118
9119 \end_inset
9120
9121 -stack-auto
9122 \begin_inset LatexCommand \index{-\/-stack-auto}
9123
9124 \end_inset
9125
9126
9127 \series default
9128 \size large
9129 \emph on
9130  
9131 \size default
9132 \emph default
9133 All functions in the source file will be compiled as 
9134 \emph on
9135 reentrant
9136 \emph default
9137
9138 \begin_inset LatexCommand \index{reentrant}
9139
9140 \end_inset
9141
9142 , i.e.
9143  the parameters and local variables will be allocated on the stack
9144 \begin_inset LatexCommand \index{stack}
9145
9146 \end_inset
9147
9148 .
9149  See section 
9150 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9151
9152 \end_inset
9153
9154  Parameters and Local Variables for more details.
9155  If this option is used all source files in the project should be compiled
9156  with this option.
9157  It automatically implies --int-long-reent and --float-reent.
9158  
9159 \end_layout
9160
9161 \begin_layout List
9162 \labelwidthstring 00.00.0000
9163
9164 \series bold
9165 -
9166 \begin_inset ERT
9167 status collapsed
9168
9169 \begin_layout Standard
9170
9171
9172 \backslash
9173 /
9174 \end_layout
9175
9176 \end_inset
9177
9178 -callee-saves
9179 \begin_inset LatexCommand \index{-\/-callee-saves}
9180
9181 \end_inset
9182
9183  
9184 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9185
9186 \end_inset
9187
9188 function1[,function2][,function3]....
9189
9190 \series default
9191  The compiler by default uses a caller saves convention for register saving
9192  across function calls, however this can cause unnecessary register pushing
9193  and popping when calling small functions from larger functions.
9194  This option can be used to switch the register saving convention for the
9195  function names specified.
9196  The compiler will not save registers when calling these functions, no extra
9197  code will be generated at the entry and exit (function prologue
9198 \series bold
9199
9200 \begin_inset LatexCommand \index{function prologue}
9201
9202 \end_inset
9203
9204
9205 \series default
9206  and epilogue
9207 \series bold
9208
9209 \begin_inset LatexCommand \index{function epilogue}
9210
9211 \end_inset
9212
9213
9214 \series default
9215 ) for these functions to save and restore the registers used by these functions,
9216  this can SUBSTANTIALLY reduce code and improve run time performance of
9217  the generated code.
9218  In the future the compiler (with inter procedural analysis) will be able
9219  to determine the appropriate scheme to use for each function call.
9220  DO NOT use this option for built-in functions such as _mulint..., if this
9221  option is used for a library function the appropriate library function
9222  needs to be recompiled with the same option.
9223  If the project consists of multiple source files then all the source file
9224  should be compiled with the same -
9225 \begin_inset ERT
9226 status collapsed
9227
9228 \begin_layout Standard
9229
9230
9231 \backslash
9232 /
9233 \end_layout
9234
9235 \end_inset
9236
9237 -callee-saves option string.
9238  Also see #pragma\InsetSpace ~
9239 callee_saves 
9240 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9241
9242 \end_inset
9243
9244  
9245 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9246
9247 \end_inset
9248
9249 .
9250 \end_layout
9251
9252 \begin_layout List
9253 \labelwidthstring 00.00.0000
9254
9255 \series bold
9256 -
9257 \begin_inset ERT
9258 status collapsed
9259
9260 \begin_layout Standard
9261
9262
9263 \backslash
9264 /
9265 \end_layout
9266
9267 \end_inset
9268
9269 -all-callee-saves
9270 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9271
9272 \end_inset
9273
9274  
9275 \series default
9276 Function of
9277 \series bold
9278  
9279 \series default
9280 -
9281 \begin_inset ERT
9282 status collapsed
9283
9284 \begin_layout Standard
9285
9286
9287 \backslash
9288 /
9289 \end_layout
9290
9291 \end_inset
9292
9293 -callee-saves will be applied to all functions by default.
9294 \end_layout
9295
9296 \begin_layout List
9297 \labelwidthstring 00.00.0000
9298
9299 \series bold
9300 -
9301 \begin_inset ERT
9302 status collapsed
9303
9304 \begin_layout Standard
9305
9306
9307 \backslash
9308 /
9309 \end_layout
9310
9311 \end_inset
9312
9313 -debug
9314 \begin_inset LatexCommand \index{-\/-debug}
9315
9316 \end_inset
9317
9318
9319 \bar under
9320  
9321 \series default
9322 \bar default
9323 When this option is used the compiler will generate debug information.
9324  The debug information collected in a file with .cdb extension can be used
9325  with the SDCDB.
9326  For more information see documentation for SDCDB.
9327  Another file with no extension contains debug information in AOMF or AOMF51
9328 \begin_inset LatexCommand \index{AOMF, AOMF51}
9329
9330 \end_inset
9331
9332  format which is commonly used by third party tools.
9333 \end_layout
9334
9335 \begin_layout List
9336 \labelwidthstring 00.00.0000
9337
9338 \series bold
9339 -S
9340 \begin_inset LatexCommand \index{-S}
9341
9342 \end_inset
9343
9344
9345 \size large
9346 \bar under
9347  
9348 \series default
9349 \size default
9350 \bar default
9351 Stop after the stage of compilation proper; do not assemble.
9352  The output is an assembler code file for the input file specified.
9353 \end_layout
9354
9355 \begin_layout List
9356 \labelwidthstring 00.00.0000
9357
9358 \series bold
9359 -
9360 \begin_inset ERT
9361 status collapsed
9362
9363 \begin_layout Standard
9364
9365
9366 \backslash
9367 /
9368 \end_layout
9369
9370 \end_inset
9371
9372 -int-long-reent
9373 \begin_inset LatexCommand \index{-\/-int-long-reent}
9374
9375 \end_inset
9376
9377
9378 \series default
9379  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9380  Note by default these libraries are compiled as non-reentrant.
9381  See section Installation for more details.
9382 \end_layout
9383
9384 \begin_layout List
9385 \labelwidthstring 00.00.0000
9386
9387 \series bold
9388 -
9389 \begin_inset ERT
9390 status collapsed
9391
9392 \begin_layout Standard
9393
9394
9395 \backslash
9396 /
9397 \end_layout
9398
9399 \end_inset
9400
9401 -cyclomatic
9402 \begin_inset LatexCommand \index{-\/-cyclomatic}
9403
9404 \end_inset
9405
9406
9407 \bar under
9408  
9409 \series default
9410 \bar default
9411 This option will cause the compiler to generate an information message for
9412  each function in the source file.
9413  The message contains some 
9414 \emph on
9415 important
9416 \emph default
9417  information about the function.
9418  The number of edges and nodes the compiler detected in the control flow
9419  graph of the function, and most importantly the 
9420 \emph on
9421 cyclomatic complexity
9422 \begin_inset LatexCommand \index{Cyclomatic complexity}
9423
9424 \end_inset
9425
9426
9427 \emph default
9428  see section on Cyclomatic Complexity for more details.
9429 \end_layout
9430
9431 \begin_layout List
9432 \labelwidthstring 00.00.0000
9433
9434 \series bold
9435 -
9436 \begin_inset ERT
9437 status collapsed
9438
9439 \begin_layout Standard
9440
9441
9442 \backslash
9443 /
9444 \end_layout
9445
9446 \end_inset
9447
9448 -float-reent
9449 \begin_inset LatexCommand \index{-\/-float-reent}
9450
9451 \end_inset
9452
9453
9454 \series default
9455  Floating point library is compiled as reentrant
9456 \begin_inset LatexCommand \index{reentrant}
9457
9458 \end_inset
9459
9460 .
9461  See section Installation for more details.
9462 \end_layout
9463
9464 \begin_layout List
9465 \labelwidthstring 00.00.0000
9466
9467 \series bold
9468 -
9469 \begin_inset ERT
9470 status collapsed
9471
9472 \begin_layout Standard
9473
9474
9475 \backslash
9476 /
9477 \end_layout
9478
9479 \end_inset
9480
9481 -funsigned-char
9482 \begin_inset LatexCommand \index{-\/-funsigned-char}
9483
9484 \end_inset
9485
9486
9487 \series default
9488  The default signedness for every type is
9489 \family typewriter
9490  signed
9491 \family default
9492 .
9493  In some embedded environments the default signedness of
9494 \family typewriter
9495  char
9496 \family default
9497  is
9498 \family typewriter
9499  unsigned
9500 \family default
9501 .
9502  To set the signess for characters to unsigned, use the option --funsigned-char.
9503  If this option is set and no signedness keyword (unsigned/signed) is given,
9504  a char will be signed.
9505  All other types are unaffected.
9506 \end_layout
9507
9508 \begin_layout List
9509 \labelwidthstring 00.00.0000
9510
9511 \series bold
9512 -
9513 \begin_inset ERT
9514 status collapsed
9515
9516 \begin_layout Standard
9517
9518
9519 \backslash
9520 /
9521 \end_layout
9522
9523 \end_inset
9524
9525 -main-return
9526 \begin_inset LatexCommand \index{-\/-main-return}
9527
9528 \end_inset
9529
9530
9531 \series default
9532  This option can be used if the code generated is called by a monitor program
9533  or if the main routine includes an endless loop.
9534  This option results in slightly smaller code and saves two bytes of stack
9535  space.
9536  The return from the 'main'
9537 \begin_inset LatexCommand \index{main return}
9538
9539 \end_inset
9540
9541  function will return to the function calling main.
9542  The default setting is to lock up i.e.
9543  generate a '
9544 \family typewriter
9545 sjmp .
9546 \family default
9547 '.
9548 \end_layout
9549
9550 \begin_layout List
9551 \labelwidthstring 00.00.0000
9552
9553 \series bold
9554 -
9555 \begin_inset ERT
9556 status collapsed
9557
9558 \begin_layout Standard
9559
9560
9561 \backslash
9562 /
9563 \end_layout
9564
9565 \end_inset
9566
9567 -nostdinc
9568 \begin_inset LatexCommand \index{-\/-nostdinc}
9569
9570 \end_inset
9571
9572
9573 \series default
9574  This will prevent the compiler from passing on the default include path
9575  to the preprocessor.
9576 \end_layout
9577
9578 \begin_layout List
9579 \labelwidthstring 00.00.0000
9580
9581 \series bold
9582 -
9583 \begin_inset ERT
9584 status collapsed
9585
9586 \begin_layout Standard
9587
9588
9589 \backslash
9590 /
9591 \end_layout
9592
9593 \end_inset
9594
9595 -nostdlib
9596 \begin_inset LatexCommand \index{-\/-nostdlib}
9597
9598 \end_inset
9599
9600
9601 \series default
9602  This will prevent the compiler from passing on the default library
9603 \begin_inset LatexCommand \index{Libraries}
9604
9605 \end_inset
9606
9607  path to the linker.
9608 \end_layout
9609
9610 \begin_layout List
9611 \labelwidthstring 00.00.0000
9612
9613 \series bold
9614 -
9615 \begin_inset ERT
9616 status collapsed
9617
9618 \begin_layout Standard
9619
9620
9621 \backslash
9622 /
9623 \end_layout
9624
9625 \end_inset
9626
9627 -verbose
9628 \begin_inset LatexCommand \index{-\/-verbose}
9629
9630 \end_inset
9631
9632
9633 \series default
9634  Shows the various actions the compiler is performing.
9635 \end_layout
9636
9637 \begin_layout List
9638 \labelwidthstring 00.00.0000
9639
9640 \series bold
9641 -V
9642 \begin_inset LatexCommand \index{-V}
9643
9644 \end_inset
9645
9646
9647 \series default
9648  Shows the actual commands the compiler is executing.
9649 \end_layout
9650
9651 \begin_layout List
9652 \labelwidthstring 00.00.0000
9653
9654 \series bold
9655 -
9656 \begin_inset ERT
9657 status collapsed
9658
9659 \begin_layout Standard
9660
9661
9662 \backslash
9663 /
9664 \end_layout
9665
9666 \end_inset
9667
9668 -no-c-code-in-asm
9669 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9670
9671 \end_inset
9672
9673
9674 \series default
9675  Hides your ugly and inefficient c-code from the asm file, so you can always
9676  blame the compiler :)
9677 \end_layout
9678
9679 \begin_layout List
9680 \labelwidthstring 00.00.0000
9681
9682 \series bold
9683 -
9684 \begin_inset ERT
9685 status collapsed
9686
9687 \begin_layout Standard
9688
9689
9690 \backslash
9691 /
9692 \end_layout
9693
9694 \end_inset
9695
9696 -fverbose-asm
9697 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9698
9699 \end_inset
9700
9701
9702 \series default
9703  Include code generator and peep-hole comments in the generated asm files.
9704 \end_layout
9705
9706 \begin_layout List
9707 \labelwidthstring 00.00.0000
9708
9709 \series bold
9710 -
9711 \begin_inset ERT
9712 status collapsed
9713
9714 \begin_layout Standard
9715
9716
9717 \backslash
9718 /
9719 \end_layout
9720
9721 \end_inset
9722
9723 -no-peep-comments
9724 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9725
9726 \end_inset
9727
9728
9729 \series default
9730  Don't include peep-hole comments in the generated asm files even if --fverbose-
9731 asm option is specified.
9732 \end_layout
9733
9734 \begin_layout List
9735 \labelwidthstring 00.00.0000
9736
9737 \series bold
9738 -
9739 \begin_inset ERT
9740 status collapsed
9741
9742 \begin_layout Standard
9743
9744
9745 \backslash
9746 /
9747 \end_layout
9748
9749 \end_inset
9750
9751 -i-code-in-asm
9752 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9753
9754 \end_inset
9755
9756
9757 \series default
9758  Include i-codes in the asm file.
9759  Sounds like noise but is most helpful for debugging the compiler itself.
9760 \end_layout
9761
9762 \begin_layout List
9763 \labelwidthstring 00.00.0000
9764
9765 \series bold
9766 -
9767 \begin_inset ERT
9768 status collapsed
9769
9770 \begin_layout Standard
9771
9772
9773 \backslash
9774 /
9775 \end_layout
9776
9777 \end_inset
9778
9779 -less-pedantic
9780 \begin_inset LatexCommand \index{pedantic}
9781
9782 \end_inset
9783
9784
9785 \begin_inset LatexCommand \index{-\/-less-pedantic}
9786
9787 \end_inset
9788
9789
9790 \series default
9791
9792 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9793
9794 \end_inset
9795
9796  Disable some of the more pedantic warnings
9797 \begin_inset LatexCommand \index{Warnings}
9798
9799 \end_inset
9800
9801 .
9802  For more details, see the less_pedantic pragma 
9803 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9804
9805 \end_inset
9806
9807 .
9808 \end_layout
9809
9810 \begin_layout List
9811 \labelwidthstring 00.00.0000
9812
9813 \series bold
9814 -
9815 \begin_inset ERT
9816 status collapsed
9817
9818 \begin_layout Standard
9819
9820
9821 \backslash
9822 /
9823 \end_layout
9824
9825 \end_inset
9826
9827 -disable-warning\InsetSpace ~
9828 <nnnn>
9829 \begin_inset LatexCommand \index{-\/-disable-warning}
9830
9831 \end_inset
9832
9833
9834 \series default
9835  Disable specific warning with number <nnnn>.
9836 \end_layout
9837
9838 \begin_layout List
9839 \labelwidthstring 00.00.0000
9840
9841 \series bold
9842 -
9843 \begin_inset ERT
9844 status collapsed
9845
9846 \begin_layout Standard
9847
9848
9849 \backslash
9850 /
9851 \end_layout
9852
9853 \end_inset
9854
9855 -print-search-dirs
9856 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9857
9858 \end_inset
9859
9860
9861 \series default
9862  Display the directories in the compiler's search path
9863 \end_layout
9864
9865 \begin_layout List
9866 \labelwidthstring 00.00.0000
9867
9868 \series bold
9869 -
9870 \begin_inset ERT
9871 status collapsed
9872
9873 \begin_layout Standard
9874
9875
9876 \backslash
9877 /
9878 \end_layout
9879
9880 \end_inset
9881
9882 -vc
9883 \begin_inset LatexCommand \index{-\/-vc}
9884
9885 \end_inset
9886
9887
9888 \series default
9889  Display errors and warnings using MSVC style, so you can use SDCC with
9890  the visual studio IDE
9891 \begin_inset LatexCommand \index{IDE}
9892
9893 \end_inset
9894
9895 .
9896  With SDCC both offering a GCC-like (the default) and a MSVC-like
9897 \begin_inset LatexCommand \index{MSVC output style}
9898
9899 \end_inset
9900
9901  output style, integration into most programming editors should be straightforwa
9902 rd.
9903 \end_layout
9904
9905 \begin_layout List
9906 \labelwidthstring 00.00.0000
9907
9908 \series bold
9909 -
9910 \begin_inset ERT
9911 status collapsed
9912
9913 \begin_layout Standard
9914
9915
9916 \backslash
9917 /
9918 \end_layout
9919
9920 \end_inset
9921
9922 -use-stdout
9923 \begin_inset LatexCommand \index{-\/-use-stdout}
9924
9925 \end_inset
9926
9927
9928 \series default
9929  Send errors and warnings to stdout instead of stderr.
9930 \end_layout
9931
9932 \begin_layout List
9933 \labelwidthstring 00.00.0000
9934
9935 \series bold
9936 -Wa\InsetSpace ~
9937 asmOption[,asmOption]
9938 \series default
9939
9940 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9941
9942 \end_inset
9943
9944 ...
9945  Pass the asmOption to the assembler
9946 \begin_inset LatexCommand \index{Options assembler}
9947
9948 \end_inset
9949
9950
9951 \begin_inset LatexCommand \index{Assembler options}
9952
9953 \end_inset
9954
9955 .
9956  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9957 \end_layout
9958
9959 \begin_layout List
9960 \labelwidthstring 00.00.0000
9961
9962 \series bold
9963 -
9964 \begin_inset ERT
9965 status collapsed
9966
9967 \begin_layout Standard
9968
9969
9970 \backslash
9971 /
9972 \end_layout
9973
9974 \end_inset
9975
9976 -std-sdcc89
9977 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9978
9979 \end_inset
9980
9981
9982 \series default
9983  Generally follow the C89 standard, but allow SDCC features that conflict
9984  with the standard (default).
9985 \end_layout
9986
9987 \begin_layout List
9988 \labelwidthstring 00.00.0000
9989
9990 \series bold
9991 -
9992 \begin_inset ERT
9993 status collapsed
9994
9995 \begin_layout Standard
9996
9997
9998 \backslash
9999 /
10000 \end_layout
10001
10002 \end_inset
10003
10004 -std-c89
10005 \begin_inset LatexCommand \index{-\/-std-c89}
10006
10007 \end_inset
10008
10009
10010 \series default
10011  Follow the C89 standard and disable SDCC features that conflict with the
10012  standard.
10013 \end_layout
10014
10015 \begin_layout List
10016 \labelwidthstring 00.00.0000
10017
10018 \series bold
10019 -
10020 \begin_inset ERT
10021 status collapsed
10022
10023 \begin_layout Standard
10024
10025
10026 \backslash
10027 /
10028 \end_layout
10029
10030 \end_inset
10031
10032 -std-sdcc99
10033 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10034
10035 \end_inset
10036
10037
10038 \series default
10039  Generally follow the C99 standard, but allow SDCC features that conflict
10040  with the standard (incomplete support).
10041 \end_layout
10042
10043 \begin_layout List
10044 \labelwidthstring 00.00.0000
10045
10046 \series bold
10047 -
10048 \begin_inset ERT
10049 status collapsed
10050
10051 \begin_layout Standard
10052
10053
10054 \backslash
10055 /
10056 \end_layout
10057
10058 \end_inset
10059
10060 -std-c99
10061 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10062
10063 \end_inset
10064
10065
10066 \series default
10067  Follow the C99 standard and disable SDCC features that conflict with the
10068  standard (incomplete support).
10069 \end_layout
10070
10071 \begin_layout List
10072 \labelwidthstring 00.00.0000
10073
10074 \series bold
10075 -
10076 \begin_inset ERT
10077 status collapsed
10078
10079 \begin_layout Standard
10080
10081
10082 \backslash
10083 /
10084 \end_layout
10085
10086 \end_inset
10087
10088 -codeseg
10089 \series default
10090
10091 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10092
10093 \end_inset
10094
10095 \InsetSpace ~
10096 <Name> The name to be used for the code
10097 \begin_inset LatexCommand \index{code}
10098
10099 \end_inset
10100
10101  segment, default CSEG.
10102  This is useful if you need to tell the compiler to put the code in a special
10103  segment so you can later on tell the linker to put this segment in a special
10104  place in memory.
10105  Can be used for instance when using bank switching to put the code in a
10106  bank.
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 -constseg
10127 \series default
10128
10129 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10130
10131 \end_inset
10132
10133 \InsetSpace ~
10134 <Name> The name to be used for the const
10135 \begin_inset LatexCommand \index{const}
10136
10137 \end_inset
10138
10139  segment, default CONST.
10140  This is useful if you need to tell the compiler to put the const data in
10141  a special segment so you can later on tell the linker to put this segment
10142  in a special place in memory.
10143  Can be used for instance when using bank switching to put the const data
10144  in a bank.
10145 \end_layout
10146
10147 \begin_layout List
10148 \labelwidthstring 00.00.0000
10149
10150 \series bold
10151 -
10152 \begin_inset ERT
10153 status collapsed
10154
10155 \begin_layout Standard
10156
10157
10158 \backslash
10159 /
10160 \end_layout
10161
10162 \end_inset
10163
10164 -fdollars-in-identifiers
10165 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10166
10167 \end_inset
10168
10169
10170 \series default
10171  Permit '$' as an identifier character.
10172 \end_layout
10173
10174 \begin_layout List
10175 \labelwidthstring 00.00.0000
10176
10177 \series bold
10178 -
10179 \begin_inset ERT
10180 status collapsed
10181
10182 \begin_layout Standard
10183
10184
10185 \backslash
10186 /
10187 \end_layout
10188
10189 \end_inset
10190
10191 -more-pedantic
10192 \series default
10193
10194 \begin_inset LatexCommand \index{-\/-more-pedantic}
10195
10196 \end_inset
10197
10198
10199 \begin_inset LatexCommand \index{pedantic}
10200
10201 \end_inset
10202
10203  Actually this is 
10204 \series bold
10205 \emph on
10206 not
10207 \series default
10208 \emph default
10209  a SDCC compiler option but if you want 
10210 \emph on
10211 more
10212 \emph default
10213  warnings you can use a separate tool dedicated to syntax checking like
10214  splint
10215 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10216
10217 \end_inset
10218
10219
10220 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10221
10222 \end_inset
10223
10224  
10225 \begin_inset LatexCommand \url{http://www.splint.org}
10226
10227 \end_inset
10228
10229 .
10230  To make your source files parseable by splint you will have to include
10231  
10232 \family sans
10233 lint.h
10234 \family default
10235
10236 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10237
10238 \end_inset
10239
10240  in your source file and add brackets around extended keywords (like 
10241 \family sans
10242
10243 \begin_inset Quotes sld
10244 \end_inset
10245
10246 __at\InsetSpace ~
10247
10248 \series bold
10249 (
10250 \series default
10251 0xab
10252 \series bold
10253 )
10254 \series default
10255
10256 \begin_inset Quotes srd
10257 \end_inset
10258
10259
10260 \family default
10261  and 
10262 \family sans
10263
10264 \begin_inset Quotes sld
10265 \end_inset
10266
10267 __interrupt\InsetSpace ~
10268 (2)
10269 \begin_inset Quotes srd
10270 \end_inset
10271
10272
10273 \family default
10274 ).
10275  
10276 \newline
10277 Splint has an excellent on line manual at 
10278 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10279
10280 \end_inset
10281
10282  and it's capabilities go beyond pure syntax checking.
10283  You'll need to tell splint the location of SDCC's include files so a typical
10284  command line could look like this: 
10285 \newline
10286
10287 \family sans
10288 splint\InsetSpace ~
10289 -I\InsetSpace ~
10290 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10291 \InsetSpace ~
10292 myprogram.c
10293 \end_layout
10294
10295 \begin_layout List
10296 \labelwidthstring 00.00.0000
10297
10298 \series bold
10299 -
10300 \begin_inset ERT
10301 status collapsed
10302
10303 \begin_layout Standard
10304
10305
10306 \backslash
10307 /
10308 \end_layout
10309
10310 \end_inset
10311
10312 -short-is-8bits
10313 \series default
10314
10315 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10316
10317 \end_inset
10318
10319
10320 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10321
10322 \end_inset
10323
10324  Treat short as 8-bit (for backward compatibility with older versions of
10325  compiler - see section 
10326 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10327
10328 \end_inset
10329
10330 )
10331 \end_layout
10332
10333 \begin_layout Standard
10334 \begin_inset VSpace bigskip
10335 \end_inset
10336
10337
10338 \end_layout
10339
10340 \begin_layout Subsection
10341 Intermediate Dump Options
10342 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10343
10344 \end_inset
10345
10346
10347 \begin_inset LatexCommand \index{Options intermediate dump}
10348
10349 \end_inset
10350
10351
10352 \begin_inset LatexCommand \index{Intermediate dump options}
10353
10354 \end_inset
10355
10356
10357 \end_layout
10358
10359 \begin_layout Standard
10360 The following options are provided for the purpose of retargetting and debugging
10361  the compiler.
10362  They provide a means to dump the intermediate code (iCode
10363 \begin_inset LatexCommand \index{iCode}
10364
10365 \end_inset
10366
10367 ) generated by the compiler in human readable form at various stages of
10368  the compilation process.
10369  More on iCodes see chapter 
10370 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10371
10372 \end_inset
10373
10374  
10375 \begin_inset Quotes srd
10376 \end_inset
10377
10378 The anatomy of the compiler
10379 \begin_inset Quotes srd
10380 \end_inset
10381
10382 .
10383 \end_layout
10384
10385 \begin_layout List
10386 \labelwidthstring 00.00.0000
10387
10388 \series bold
10389 -
10390 \begin_inset ERT
10391 status collapsed
10392
10393 \begin_layout Standard
10394
10395
10396 \backslash
10397 /
10398 \end_layout
10399
10400 \end_inset
10401
10402 -dumpraw
10403 \begin_inset LatexCommand \index{-\/-dumpraw}
10404
10405 \end_inset
10406
10407
10408 \series default
10409  This option will cause the compiler to dump the intermediate code into
10410  a file of named 
10411 \emph on
10412 <source filename>.dumpraw
10413 \emph default
10414  just after the intermediate code has been generated for a function, i.e.
10415  before any optimizations are done.
10416  The basic blocks
10417 \begin_inset LatexCommand \index{Basic blocks}
10418
10419 \end_inset
10420
10421  at this stage ordered in the depth first number, so they may not be in
10422  sequence of execution.
10423 \end_layout
10424
10425 \begin_layout List
10426 \labelwidthstring 00.00.0000
10427
10428 \series bold
10429 -
10430 \begin_inset ERT
10431 status collapsed
10432
10433 \begin_layout Standard
10434
10435
10436 \backslash
10437 /
10438 \end_layout
10439
10440 \end_inset
10441
10442 -dumpgcse
10443 \begin_inset LatexCommand \index{-\/-dumpgcse}
10444
10445 \end_inset
10446
10447
10448 \series default
10449  Will create a dump of iCode's, after global subexpression elimination
10450 \begin_inset LatexCommand \index{Global subexpression elimination}
10451
10452 \end_inset
10453
10454 , into a file named 
10455 \emph on
10456 <source filename>.dumpgcse.
10457 \end_layout
10458
10459 \begin_layout List
10460 \labelwidthstring 00.00.0000
10461
10462 \series bold
10463 -
10464 \begin_inset ERT
10465 status collapsed
10466
10467 \begin_layout Standard
10468
10469
10470 \backslash
10471 /
10472 \end_layout
10473
10474 \end_inset
10475
10476 -dumpdeadcode
10477 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10478
10479 \end_inset
10480
10481
10482 \series default
10483  Will create a dump of iCode's, after deadcode elimination
10484 \begin_inset LatexCommand \index{Dead-code elimination}
10485
10486 \end_inset
10487
10488 , into a file named 
10489 \emph on
10490 <source filename>.dumpdeadcode.
10491 \end_layout
10492
10493 \begin_layout List
10494 \labelwidthstring 00.00.0000
10495
10496 \series bold
10497 -
10498 \begin_inset ERT
10499 status collapsed
10500
10501 \begin_layout Standard
10502
10503
10504 \backslash
10505 /
10506 \end_layout
10507
10508 \end_inset
10509
10510 -dumploop
10511 \begin_inset LatexCommand \index{-\/-dumploop}
10512
10513 \end_inset
10514
10515
10516 \series default
10517 \size large
10518  
10519 \size default
10520 Will create a dump of iCode's, after loop optimizations
10521 \begin_inset LatexCommand \index{Loop optimization}
10522
10523 \end_inset
10524
10525 , into a file named 
10526 \emph on
10527 <source filename>.dumploop.
10528 \end_layout
10529
10530 \begin_layout List
10531 \labelwidthstring 00.00.0000
10532
10533 \series bold
10534 -
10535 \begin_inset ERT
10536 status collapsed
10537
10538 \begin_layout Standard
10539
10540
10541 \backslash
10542 /
10543 \end_layout
10544
10545 \end_inset
10546
10547 -dumprange
10548 \begin_inset LatexCommand \index{-\/-dumprange}
10549
10550 \end_inset
10551
10552
10553 \series default
10554 \size large
10555  
10556 \size default
10557 Will create a dump of iCode's, after live range analysis
10558 \begin_inset LatexCommand \index{Live range analysis}
10559
10560 \end_inset
10561
10562 , into a file named 
10563 \emph on
10564 <source filename>.dumprange.
10565 \end_layout
10566
10567 \begin_layout List
10568 \labelwidthstring 00.00.0000
10569
10570 \series bold
10571 -
10572 \begin_inset ERT
10573 status collapsed
10574
10575 \begin_layout Standard
10576
10577
10578 \backslash
10579 /
10580 \end_layout
10581
10582 \end_inset
10583
10584 -dumlrange
10585 \begin_inset LatexCommand \index{-\/-dumlrange}
10586
10587 \end_inset
10588
10589
10590 \series default
10591  Will dump the life ranges
10592 \begin_inset LatexCommand \index{Live range analysis}
10593
10594 \end_inset
10595
10596  for all symbols.
10597 \end_layout
10598
10599 \begin_layout List
10600 \labelwidthstring 00.00.0000
10601
10602 \series bold
10603 -
10604 \begin_inset ERT
10605 status collapsed
10606
10607 \begin_layout Standard
10608
10609
10610 \backslash
10611 /
10612 \end_layout
10613
10614 \end_inset
10615
10616 -dumpregassign
10617 \begin_inset LatexCommand \index{-\/-dumpregassign}
10618
10619 \end_inset
10620
10621
10622 \bar under
10623  
10624 \series default
10625 \bar default
10626 Will create a dump of iCode's, after register assignment
10627 \begin_inset LatexCommand \index{Register assignment}
10628
10629 \end_inset
10630
10631 , into a file named 
10632 \emph on
10633 <source filename>.dumprassgn.
10634 \end_layout
10635
10636 \begin_layout List
10637 \labelwidthstring 00.00.0000
10638
10639 \series bold
10640 -
10641 \begin_inset ERT
10642 status collapsed
10643
10644 \begin_layout Standard
10645
10646
10647 \backslash
10648 /
10649 \end_layout
10650
10651 \end_inset
10652
10653 -dumplrange
10654 \begin_inset LatexCommand \index{-\/-dumplrange}
10655
10656 \end_inset
10657
10658
10659 \series default
10660  Will create a dump of the live ranges of iTemp's
10661 \end_layout
10662
10663 \begin_layout List
10664 \labelwidthstring 00.00.0000
10665
10666 \series bold
10667 -
10668 \begin_inset ERT
10669 status collapsed
10670
10671 \begin_layout Standard
10672
10673
10674 \backslash
10675 /
10676 \end_layout
10677
10678 \end_inset
10679
10680 -dumpall
10681 \begin_inset LatexCommand \index{-\/-dumpall}
10682
10683 \end_inset
10684
10685
10686 \size large
10687 \bar under
10688  
10689 \series default
10690 \size default
10691 \bar default
10692 Will cause all the above mentioned dumps to be created.
10693 \end_layout
10694
10695 \begin_layout Standard
10696 \begin_inset VSpace bigskip
10697 \end_inset
10698
10699
10700 \end_layout
10701
10702 \begin_layout Subsection
10703 Redirecting output on Windows Shells
10704 \end_layout
10705
10706 \begin_layout Standard
10707 By default SDCC writes it's error messages to 
10708 \begin_inset Quotes sld
10709 \end_inset
10710
10711 standard error
10712 \begin_inset Quotes srd
10713 \end_inset
10714
10715 .
10716  To force all messages to 
10717 \begin_inset Quotes sld
10718 \end_inset
10719
10720 standard output
10721 \begin_inset Quotes srd
10722 \end_inset
10723
10724  use 
10725 \series bold
10726 -
10727 \series default
10728 \emph on
10729
10730 \begin_inset ERT
10731 status collapsed
10732
10733 \begin_layout Standard
10734
10735
10736 \backslash
10737 /
10738 \end_layout
10739
10740 \end_inset
10741
10742
10743 \series bold
10744 \emph default
10745 -
10746 \series default
10747 use-stdout
10748 \begin_inset LatexCommand \index{-\/-use-stdout}
10749
10750 \end_inset
10751
10752 .
10753  Additionally, if you happen to have visual studio installed in your windows
10754  machine, you can use it to compile your sources using a custom build and
10755  the SDCC -
10756 \emph on
10757
10758 \begin_inset ERT
10759 status collapsed
10760
10761 \begin_layout Standard
10762
10763
10764 \backslash
10765 /
10766 \end_layout
10767
10768 \end_inset
10769
10770
10771 \emph default
10772 -vc
10773 \begin_inset LatexCommand \index{-\/-vc}
10774
10775 \end_inset
10776
10777  option.
10778  Something like this should work:
10779 \newline
10780
10781 \newline
10782
10783 \series bold
10784 c:
10785 \backslash
10786 sdcc
10787 \backslash
10788 bin
10789 \backslash
10790 sdcc.exe -
10791 \series default
10792 \emph on
10793
10794 \begin_inset ERT
10795 status collapsed
10796
10797 \begin_layout Standard
10798
10799
10800 \backslash
10801 /
10802 \end_layout
10803
10804 \end_inset
10805
10806
10807 \series bold
10808 \emph default
10809 -vc -
10810 \series default
10811 \emph on
10812
10813 \begin_inset ERT
10814 status collapsed
10815
10816 \begin_layout Standard
10817
10818
10819 \backslash
10820 /
10821 \end_layout
10822
10823 \end_inset
10824
10825
10826 \series bold
10827 \emph default
10828 -model-large -c $(InputPath)
10829 \series default
10830
10831 \begin_inset VSpace bigskip
10832 \end_inset
10833
10834
10835 \end_layout
10836
10837 \begin_layout Section
10838 Environment variables
10839 \begin_inset LatexCommand \index{Environment variables}
10840
10841 \end_inset
10842
10843
10844 \end_layout
10845
10846 \begin_layout Standard
10847 SDCC recognizes the following environment variables:
10848 \end_layout
10849
10850 \begin_layout List
10851 \labelwidthstring 00.00.0000
10852
10853 \series bold
10854 SDCC_LEAVE_SIGNALS
10855 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10856
10857 \end_inset
10858
10859
10860 \series default
10861  SDCC installs a signal handler
10862 \begin_inset LatexCommand \index{signal handler}
10863
10864 \end_inset
10865
10866  to be able to delete temporary files after an user break (^C) or an exception.
10867  If this environment variable is set, SDCC won't install the signal handler
10868  in order to be able to debug SDCC.
10869 \end_layout
10870
10871 \begin_layout List
10872 \labelwidthstring 00.00.0000
10873
10874 \series bold
10875 TMP,\InsetSpace ~
10876 TEMP,\InsetSpace ~
10877 TMPDIR
10878 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10879
10880 \end_inset
10881
10882
10883 \series default
10884  Path, where temporary files will be created.
10885  The order of the variables is the search order.
10886  In a standard *nix environment these variables are not set, and there's
10887  no need to set them.
10888  On Windows it's recommended to set one of them.
10889 \end_layout
10890
10891 \begin_layout List
10892 \labelwidthstring 00.00.0000
10893
10894 \series bold
10895 SDCC_HOME
10896 \begin_inset LatexCommand \index{SDCC\_HOME}
10897
10898 \end_inset
10899
10900
10901 \series default
10902  Path, see section 
10903 \begin_inset LatexCommand \ref{sub:Install-paths}
10904
10905 \end_inset
10906
10907 \InsetSpace ~
10908
10909 \begin_inset Quotes sld
10910 \end_inset
10911
10912  Install Paths
10913 \begin_inset Quotes srd
10914 \end_inset
10915
10916 .
10917 \end_layout
10918
10919 \begin_layout List
10920 \labelwidthstring 00.00.0000
10921
10922 \series bold
10923 SDCC_INCLUDE
10924 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10925
10926 \end_inset
10927
10928
10929 \series default
10930  Path, see section 
10931 \begin_inset LatexCommand \ref{sub:Search-Paths}
10932
10933 \end_inset
10934
10935 \InsetSpace ~
10936
10937 \begin_inset Quotes sld
10938 \end_inset
10939
10940 Search Paths
10941 \begin_inset Quotes srd
10942 \end_inset
10943
10944 .
10945 \end_layout
10946
10947 \begin_layout List
10948 \labelwidthstring 00.00.0000
10949
10950 \series bold
10951 SDCC_LIB
10952 \begin_inset LatexCommand \index{SDCC\_LIB}
10953
10954 \end_inset
10955
10956
10957 \series default
10958  Path, see section 
10959 \begin_inset LatexCommand \ref{sub:Search-Paths}
10960
10961 \end_inset
10962
10963 \InsetSpace ~
10964
10965 \begin_inset Quotes sld
10966 \end_inset
10967
10968 Search Paths
10969 \begin_inset Quotes srd
10970 \end_inset
10971
10972 ..
10973 \end_layout
10974
10975 \begin_layout Standard
10976 There are some more environment variables recognized by SDCC, but these
10977  are solely used for debugging purposes.
10978  They can change or disappear very quickly, and will never be documented.
10979 \begin_inset VSpace bigskip
10980 \end_inset
10981
10982
10983 \end_layout
10984
10985 \begin_layout Section
10986 Storage Class Language Extensions
10987 \end_layout
10988
10989 \begin_layout Subsection
10990 MCS51/DS390 Storage Class
10991 \begin_inset LatexCommand \index{Storage class}
10992
10993 \end_inset
10994
10995  Language Extensions
10996 \end_layout
10997
10998 \begin_layout Standard
10999 In addition to the ANSI storage classes SDCC allows the following MCS51
11000  specific storage classes:
11001 \end_layout
11002
11003 \begin_layout Subsubsection
11004 data
11005 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11006
11007 \end_inset
11008
11009
11010 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11011
11012 \end_inset
11013
11014  / near
11015 \begin_inset LatexCommand \index{near (storage class)}
11016
11017 \end_inset
11018
11019
11020 \begin_inset LatexCommand \index{\_\_near (storage class)}
11021
11022 \end_inset
11023
11024
11025 \end_layout
11026
11027 \begin_layout Standard
11028 This is the 
11029 \series bold
11030 default
11031 \series default
11032  storage class for the Small Memory model (
11033 \emph on
11034 data
11035 \emph default
11036  and 
11037 \emph on
11038 near
11039 \emph default
11040  or the more ANSI-C compliant forms 
11041 \emph on
11042 __data
11043 \emph default
11044  and 
11045 \emph on
11046 __near
11047 \emph default
11048  can be used synonymously).
11049  Variables declared with this storage class will be allocated in the directly
11050  addressable portion of the internal RAM of a 8051, e.g.:
11051 \end_layout
11052
11053 \begin_layout Verse
11054
11055 \family typewriter
11056 __data unsigned char test_data;
11057 \end_layout
11058
11059 \begin_layout Standard
11060 Writing 0x01 to this variable generates the assembly code:
11061 \end_layout
11062
11063 \begin_layout Verse
11064
11065 \family typewriter
11066 75*00 01\InsetSpace ~
11067 \InsetSpace ~
11068 \InsetSpace ~
11069 mov\InsetSpace ~
11070 \InsetSpace ~
11071 _test_data,#0x01
11072 \end_layout
11073
11074 \begin_layout Subsubsection
11075 xdata
11076 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11077
11078 \end_inset
11079
11080
11081 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11082
11083 \end_inset
11084
11085  / far
11086 \begin_inset LatexCommand \index{far (storage class)}
11087
11088 \end_inset
11089
11090
11091 \begin_inset LatexCommand \index{\_\_far (storage class)}
11092
11093 \end_inset
11094
11095
11096 \end_layout
11097
11098 \begin_layout Standard
11099 Variables declared with this storage class will be placed in the external
11100  RAM.
11101  This is the 
11102 \series bold
11103 default
11104 \series default
11105  storage class for the Large Memory model, e.g.:
11106 \end_layout
11107
11108 \begin_layout Verse
11109
11110 \family typewriter
11111 __xdata unsigned char test_xdata;
11112 \end_layout
11113
11114 \begin_layout Standard
11115 Writing 0x01 to this variable generates the assembly code:
11116 \end_layout
11117
11118 \begin_layout Verse
11119
11120 \family typewriter
11121 90s00r00\InsetSpace ~
11122 \InsetSpace ~
11123 \InsetSpace ~
11124 mov\InsetSpace ~
11125 \InsetSpace ~
11126 dptr,#_test_xdata 
11127 \newline
11128 74\InsetSpace ~
11129 01\InsetSpace ~
11130 \InsetSpace ~
11131 \InsetSpace ~
11132 \InsetSpace ~
11133 \InsetSpace ~
11134 \InsetSpace ~
11135 mov\InsetSpace ~
11136 \InsetSpace ~
11137 a,#0x01 
11138 \newline
11139 F0\InsetSpace ~
11140 \InsetSpace ~
11141 \InsetSpace ~
11142 \InsetSpace ~
11143 \InsetSpace ~
11144 \InsetSpace ~
11145 \InsetSpace ~
11146 \InsetSpace ~
11147 \InsetSpace ~
11148 movx\InsetSpace ~
11149 @dptr,a 
11150 \end_layout
11151
11152 \begin_layout Subsubsection
11153 idata
11154 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11155
11156 \end_inset
11157
11158
11159 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11160
11161 \end_inset
11162
11163
11164 \end_layout
11165
11166 \begin_layout Standard
11167 Variables declared with this storage class will be allocated into the indirectly
11168  addressable portion of the internal ram of a 8051, e.g.:
11169 \end_layout
11170
11171 \begin_layout Verse
11172
11173 \family typewriter
11174 __idata unsigned char test_idata;
11175 \end_layout
11176
11177 \begin_layout Standard
11178 Writing 0x01 to this variable generates the assembly code:
11179 \end_layout
11180
11181 \begin_layout Verse
11182
11183 \family typewriter
11184 78r00\InsetSpace ~
11185 \InsetSpace ~
11186 \InsetSpace ~
11187 \InsetSpace ~
11188 \InsetSpace ~
11189 \InsetSpace ~
11190 \InsetSpace ~
11191 mov\InsetSpace ~
11192 \InsetSpace ~
11193 r0,#_test_idata
11194 \newline
11195 76\InsetSpace ~
11196 01\InsetSpace ~
11197 \InsetSpace ~
11198 \InsetSpace ~
11199 \InsetSpace ~
11200 \InsetSpace ~
11201 \InsetSpace ~
11202 \InsetSpace ~
11203 mov\InsetSpace ~
11204 \InsetSpace ~
11205 @r0,#0x01
11206 \end_layout
11207
11208 \begin_layout Standard
11209 Please note, the first 128 byte of idata physically access the same RAM
11210  as the data memory.
11211  The original 8051 had 128 byte idata memory, nowadays most devices have
11212  256 byte idata memory.
11213  The stack
11214 \begin_inset LatexCommand \index{stack}
11215
11216 \end_inset
11217
11218  is located in idata memory.
11219 \end_layout
11220
11221 \begin_layout Subsubsection
11222 pdata
11223 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11224
11225 \end_inset
11226
11227
11228 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11229
11230 \end_inset
11231
11232
11233 \end_layout
11234
11235 \begin_layout Standard
11236 Paged xdata access is just as straightforward as using the other addressing
11237  modes of a 8051.
11238  It is typically located at the start of xdata and has a maximum size of
11239  256 bytes.
11240  The following example writes 0x01 to the pdata variable.
11241  Please note, pdata access physically accesses xdata memory.
11242  The high byte of the address is determined by port P2 
11243 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11244
11245 \end_inset
11246
11247 (or in case of some 8051 variants by a separate Special Function Register,
11248  see section 
11249 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11250
11251 \end_inset
11252
11253 ).
11254  This is the 
11255 \series bold
11256 default
11257 \series default
11258  storage class for the Medium Memory model, e.g.:
11259 \end_layout
11260
11261 \begin_layout Verse
11262
11263 \family typewriter
11264 __pdata unsigned char test_pdata;
11265 \end_layout
11266
11267 \begin_layout Standard
11268 Writing 0x01 to this variable generates the assembly code:
11269 \end_layout
11270
11271 \begin_layout Verse
11272
11273 \family typewriter
11274 78r00\InsetSpace ~
11275 \InsetSpace ~
11276 \InsetSpace ~
11277 \InsetSpace ~
11278 \InsetSpace ~
11279 \InsetSpace ~
11280 mov r0,#_test_pdata
11281 \newline
11282 74 01\InsetSpace ~
11283 \InsetSpace ~
11284 \InsetSpace ~
11285 \InsetSpace ~
11286 \InsetSpace ~
11287 \InsetSpace ~
11288 mov a,#0x01 
11289 \newline
11290 F2\InsetSpace ~
11291 \InsetSpace ~
11292 \InsetSpace ~
11293 \InsetSpace ~
11294 \InsetSpace ~
11295 \InsetSpace ~
11296 \InsetSpace ~
11297 \InsetSpace ~
11298 \InsetSpace ~
11299 movx @r0,a
11300 \end_layout
11301
11302 \begin_layout Standard
11303 If the -
11304 \begin_inset ERT
11305 status collapsed
11306
11307 \begin_layout Standard
11308
11309
11310 \backslash
11311 /
11312 \end_layout
11313
11314 \end_inset
11315
11316 -xstack
11317 \begin_inset LatexCommand \index{-\/-xstack}
11318
11319 \end_inset
11320
11321  option is used the pdata memory area is followed by the xstack memory area
11322  and the sum of their sizes is limited to 256 bytes.
11323 \end_layout
11324
11325 \begin_layout Subsubsection
11326 code
11327 \begin_inset LatexCommand \index{code}
11328
11329 \end_inset
11330
11331
11332 \begin_inset LatexCommand \index{\_\_code}
11333
11334 \end_inset
11335
11336
11337 \end_layout
11338
11339 \begin_layout Standard
11340 'Variables' declared with this storage class will be placed in the code
11341  memory:
11342 \end_layout
11343
11344 \begin_layout Verse
11345
11346 \family typewriter
11347 __code unsigned char test_code;
11348 \end_layout
11349
11350 \begin_layout Standard
11351 Read access to this variable generates the assembly code:
11352 \end_layout
11353
11354 \begin_layout Verse
11355
11356 \family typewriter
11357 90s00r6F\InsetSpace ~
11358 \InsetSpace ~
11359 \InsetSpace ~
11360 mov dptr,#_test_code
11361 \newline
11362 E4\InsetSpace ~
11363 \InsetSpace ~
11364 \InsetSpace ~
11365 \InsetSpace ~
11366 \InsetSpace ~
11367 \InsetSpace ~
11368 \InsetSpace ~
11369 \InsetSpace ~
11370 \InsetSpace ~
11371 clr a
11372 \newline
11373 93\InsetSpace ~
11374 \InsetSpace ~
11375 \InsetSpace ~
11376 \InsetSpace ~
11377 \InsetSpace ~
11378 \InsetSpace ~
11379 \InsetSpace ~
11380 \InsetSpace ~
11381 \InsetSpace ~
11382 movc a,@a+dptr 
11383 \end_layout
11384
11385 \begin_layout Standard
11386
11387 \family typewriter
11388 char
11389 \family default
11390  indexed arrays of characters in code memory can be accessed efficiently:
11391 \end_layout
11392
11393 \begin_layout Verse
11394
11395 \family typewriter
11396 __code char test_array[] = {'c','h','e','a','p'}; 
11397 \end_layout
11398
11399 \begin_layout Standard
11400 Read access to this array using an 8-bit unsigned index generates the assembly
11401  code:
11402 \end_layout
11403
11404 \begin_layout Verse
11405
11406 \family typewriter
11407 E5*00\InsetSpace ~
11408 \InsetSpace ~
11409 \InsetSpace ~
11410 \InsetSpace ~
11411 \InsetSpace ~
11412 \InsetSpace ~
11413 mov a,_index 
11414 \end_layout
11415
11416 \begin_layout Verse
11417
11418 \family typewriter
11419 90s00r41\InsetSpace ~
11420 \InsetSpace ~
11421 \InsetSpace ~
11422 mov dptr,#_test_array
11423 \end_layout
11424
11425 \begin_layout Verse
11426
11427 \family typewriter
11428 93\InsetSpace ~
11429 \InsetSpace ~
11430 \InsetSpace ~
11431 \InsetSpace ~
11432 \InsetSpace ~
11433 \InsetSpace ~
11434 \InsetSpace ~
11435 \InsetSpace ~
11436 \InsetSpace ~
11437 movc a,@a+dptr 
11438 \end_layout
11439
11440 \begin_layout Subsubsection
11441 bit
11442 \begin_inset LatexCommand \index{bit}
11443
11444 \end_inset
11445
11446
11447 \begin_inset LatexCommand \index{\_\_bit}
11448
11449 \end_inset
11450
11451
11452 \end_layout
11453
11454 \begin_layout Standard
11455 This is a data-type and a storage class specifier.
11456  When a variable is declared as a bit, it is allocated into the bit addressable
11457  memory of 8051, e.g.:
11458 \end_layout
11459
11460 \begin_layout Verse
11461
11462 \family typewriter
11463 __bit test_bit;
11464 \end_layout
11465
11466 \begin_layout Standard
11467 Writing 1 to this variable generates the assembly code:
11468 \end_layout
11469
11470 \begin_layout Verse
11471
11472 \family typewriter
11473 D2*00\InsetSpace ~
11474 \InsetSpace ~
11475 \InsetSpace ~
11476 \InsetSpace ~
11477 \InsetSpace ~
11478 \InsetSpace ~
11479 \InsetSpace ~
11480 setb\InsetSpace ~
11481 _test_bit
11482 \end_layout
11483
11484 \begin_layout Standard
11485 The bit addressable memory consists of 128 bits which are located from 0x20
11486  to 0x2f in data memory.
11487  
11488 \newline
11489 Apart from this 8051 specific storage class most architectures support
11490  ANSI-C bitfields
11491 \begin_inset LatexCommand \index{bitfields}
11492
11493 \end_inset
11494
11495
11496 \begin_inset Foot
11497 status open
11498
11499 \begin_layout Standard
11500 Not really meant as examples, but nevertheless showing what bitfields are
11501  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11502 \end_layout
11503
11504 \end_inset
11505
11506 .
11507  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11508  signed modifier are implemented as unsigned.
11509 \end_layout
11510
11511 \begin_layout Subsubsection
11512 sfr
11513 \begin_inset LatexCommand \index{sfr}
11514
11515 \end_inset
11516
11517
11518 \begin_inset LatexCommand \index{\_\_sfr}
11519
11520 \end_inset
11521
11522  / sfr16
11523 \begin_inset LatexCommand \index{sfr16}
11524
11525 \end_inset
11526
11527
11528 \begin_inset LatexCommand \index{\_\_sfr16}
11529
11530 \end_inset
11531
11532  / sfr32
11533 \begin_inset LatexCommand \index{sfr32}
11534
11535 \end_inset
11536
11537
11538 \begin_inset LatexCommand \index{\_\_sfr32}
11539
11540 \end_inset
11541
11542  / sbit
11543 \begin_inset LatexCommand \index{\_\_sbit}
11544
11545 \end_inset
11546
11547
11548 \begin_inset LatexCommand \index{sbit}
11549
11550 \end_inset
11551
11552
11553 \end_layout
11554
11555 \begin_layout Standard
11556 Like the bit keyword, 
11557 \emph on
11558 sfr / sfr16 / sfr32 / sbit 
11559 \emph default
11560 signify both a data-type and storage class, they are used to describe the
11561  
11562 \emph on
11563 s
11564 \emph default
11565 pecial 
11566 \emph on
11567 f
11568 \emph default
11569 unction 
11570 \emph on
11571 r
11572 \emph default
11573 egisters and 
11574 \emph on
11575 s
11576 \emph default
11577 pecial 
11578 \emph on
11579 bit
11580 \emph default
11581  variables of a 8051, eg:
11582 \end_layout
11583
11584 \begin_layout Verse
11585
11586 \family typewriter
11587 __sfr __at
11588 \begin_inset LatexCommand \index{at}
11589
11590 \end_inset
11591
11592
11593 \begin_inset LatexCommand \index{\_\_at}
11594
11595 \end_inset
11596
11597  (0x80) P0;\InsetSpace ~
11598  /* special function register P0 at location 0x80 */
11599 \newline
11600
11601 \newline
11602 /* 16 bit
11603  special function register combination for timer 0
11604 \newline
11605 \InsetSpace ~
11606 \InsetSpace ~
11607  with the high byte at
11608  location 0x8C and the low byte at location 0x8A */
11609 \newline
11610 __sfr16 __at (0x8C8A)
11611  TMR0;
11612 \newline
11613
11614 \newline
11615 __sbit __at
11616 \begin_inset LatexCommand \index{at}
11617
11618 \end_inset
11619
11620
11621 \begin_inset LatexCommand \index{\_\_at}
11622
11623 \end_inset
11624
11625  (0xd7) CY;\InsetSpace ~
11626  /* CY (Carry Flag
11627 \begin_inset LatexCommand \index{Flags}
11628
11629 \end_inset
11630
11631
11632 \begin_inset LatexCommand \index{Carry flag}
11633
11634 \end_inset
11635
11636 ) */
11637 \end_layout
11638
11639 \begin_layout Standard
11640 Special function registers which are located on an address dividable by
11641  8 are bit-addressable, an
11642 \emph on
11643  sbit
11644 \emph default
11645  addresses a specific bit within these sfr.
11646 \newline
11647 16 Bit and 32 bit special function
11648  register combinations which require a certain access order are better not
11649  declared using 
11650 \emph on
11651 sfr16
11652 \emph default
11653  or 
11654 \emph on
11655 sfr32.
11656
11657 \emph default
11658  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11659  this is not guaranteed.
11660 \newline
11661
11662 \end_layout
11663
11664 \begin_layout Standard
11665 Please note, if you use a header file which was written for another compiler
11666  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11667  likely be 
11668 \emph on
11669 not 
11670 \emph default
11671 compatible.
11672  Specifically the syntax 
11673 \family typewriter
11674 \InsetSpace ~
11675 sfr P0 = 0x80;\InsetSpace ~
11676
11677 \family default
11678  is compiled 
11679 \emph on
11680 without warning
11681 \emph default
11682  by SDCC to an assignment of 0x80 to a variable called P0 
11683 \family typewriter
11684
11685 \begin_inset Marginal
11686 status collapsed
11687
11688 \begin_layout Standard
11689
11690 \series bold
11691 \InsetSpace ~
11692 !
11693 \end_layout
11694
11695 \end_inset
11696
11697 .
11698  
11699 \family default
11700 Nevertheless it is possible to write header files
11701 \begin_inset LatexCommand \index{Header files}
11702
11703 \end_inset
11704
11705
11706 \begin_inset LatexCommand \index{Include files}
11707
11708 \end_inset
11709
11710  which can be shared among different compilers (see section 
11711 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11712
11713 \end_inset
11714
11715 ).
11716  
11717 \end_layout
11718
11719 \begin_layout Subsubsection
11720 Pointers
11721 \begin_inset LatexCommand \index{Pointer}
11722
11723 \end_inset
11724
11725  to MCS51/DS390 specific memory spaces
11726 \end_layout
11727
11728 \begin_layout Standard
11729 SDCC allows (via language extensions) pointers to explicitly point to any
11730  of the memory spaces
11731 \begin_inset LatexCommand \index{Memory model}
11732
11733 \end_inset
11734
11735  of the 8051.
11736  In addition to the explicit pointers, the compiler uses (by default) generic
11737  pointers which can be used to point to any of the memory spaces.
11738 \newline
11739
11740 \newline
11741 Pointer
11742  declaration examples:
11743 \end_layout
11744
11745 \begin_layout Verse
11746
11747 \family typewriter
11748 /* pointer physically in internal ram pointing to object in external ram
11749  */ 
11750 \newline
11751 __xdata unsigned char * __data p;
11752 \newline
11753
11754 \newline
11755 /* pointer physically in external ram
11756  pointing to object in internal ram */ 
11757 \newline
11758 __data unsigned char * __xdata p;
11759 \newline
11760
11761 \newline
11762 /*
11763  pointer physically in code rom pointing to data in xdata space */ 
11764 \newline
11765 __xdata
11766  unsigned char * __code p;
11767 \newline
11768
11769 \newline
11770 /* pointer physically in code space pointing to
11771  data in code space */ 
11772 \newline
11773 __code unsigned char * __code p;
11774 \newline
11775
11776 \newline
11777 /* generic pointer
11778  physically located in xdata space */
11779 \newline
11780 unsigned char * __xdata p;
11781 \newline
11782
11783 \newline
11784 /* generic
11785  pointer physically located in default memory space */
11786 \newline
11787 unsigned char * p;
11788 \newline
11789
11790 \newline
11791 /*
11792  the following is a function pointer
11793 \begin_inset LatexCommand \index{function pointer}
11794
11795 \end_inset
11796
11797  physically located in data space */
11798 \newline
11799 char (* __data fp)(void);
11800 \end_layout
11801
11802 \begin_layout Standard
11803 Well you get the idea.
11804  
11805 \newline
11806
11807 \newline
11808 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
11809 \emph on
11810 generic
11811 \emph default
11812  pointers.
11813  
11814 \size small
11815
11816 \newline
11817
11818 \newline
11819
11820 \size default
11821 The highest order byte of the 
11822 \emph on
11823 generic
11824 \emph default
11825  pointers contains the data space information.
11826  Assembler support routines are called whenever data is stored or retrieved
11827  using 
11828 \emph on
11829 generic
11830 \emph default
11831  pointers.
11832  These are useful for developing reusable library
11833 \begin_inset LatexCommand \index{Libraries}
11834
11835 \end_inset
11836
11837  routines.
11838  Explicitly specifying the pointer
11839 \begin_inset LatexCommand \index{pointer}
11840
11841 \end_inset
11842
11843  type will generate the most efficient code.
11844 \end_layout
11845
11846 \begin_layout Subsubsection
11847 Notes on MCS51 memory
11848 \begin_inset LatexCommand \index{MCS51 memory}
11849
11850 \end_inset
11851
11852  layout
11853 \end_layout
11854
11855 \begin_layout Standard
11856 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11857  RAM memory which is structured as follows:
11858 \newline
11859
11860 \newline
11861 - Bytes 00-1F - 32 bytes to hold
11862  up to 4 banks of the registers R0 to R7, 
11863 \newline
11864 - Bytes 20-2F - 16 bytes to hold
11865  128 bit
11866 \begin_inset LatexCommand \index{bit}
11867
11868 \end_inset
11869
11870  variables and, 
11871 \newline
11872 - Bytes 30-7F - 80 bytes for general purpose use.
11873 \newline
11874
11875 \end_layout
11876
11877 \begin_layout Standard
11878 Additionally some members of the MCS51 family may have up to 128 bytes of
11879  additional, indirectly addressable, internal RAM memory (
11880 \emph on
11881 idata
11882 \emph default
11883
11884 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11885
11886 \end_inset
11887
11888
11889 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11890
11891 \end_inset
11892
11893 ).
11894  Furthermore, some chips may have some built in external memory (
11895 \emph on
11896 xdata
11897 \emph default
11898
11899 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11900
11901 \end_inset
11902
11903
11904 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11905
11906 \end_inset
11907
11908 ) which should not be confused with the internal, directly addressable RAM
11909  memory (
11910 \emph on
11911 data
11912 \emph default
11913
11914 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11915
11916 \end_inset
11917
11918
11919 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11920
11921 \end_inset
11922
11923 ).
11924  Sometimes this built in 
11925 \emph on
11926 xdata
11927 \emph default
11928  memory has to be activated before using it (you can probably find this
11929  information on the datasheet of the microcontroller your are using, see
11930  also section 
11931 \begin_inset LatexCommand \ref{sub:Startup-Code}
11932
11933 \end_inset
11934
11935 \InsetSpace ~
11936 Startup-Code).
11937 \end_layout
11938
11939 \begin_layout Standard
11940 Normally SDCC will only use the first bank
11941 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11942
11943 \end_inset
11944
11945  of registers (register bank 0), but it is possible to specify that other
11946  banks of registers (keyword 
11947 \emph on
11948 using
11949 \emph default
11950  
11951 \emph on
11952
11953 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11954
11955 \end_inset
11956
11957
11958 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11959
11960 \end_inset
11961
11962
11963 \emph default
11964 ) should be used for example in interrupt
11965 \begin_inset LatexCommand \index{interrupt}
11966
11967 \end_inset
11968
11969
11970 \begin_inset LatexCommand \index{\_\_interrupt}
11971
11972 \end_inset
11973
11974  routines.
11975  By default, the compiler will place the stack after the last byte of allocated
11976  memory for variables.
11977  For example, if the first 2 banks of registers are used, and only four
11978  bytes are used for 
11979 \emph on
11980 data
11981 \emph default
11982  variables, it will position the base of the internal stack at address 20
11983  (0x14).
11984  This implies that as the stack
11985 \begin_inset LatexCommand \index{stack}
11986
11987 \end_inset
11988
11989  grows, it will use up the remaining register banks, and the 16 bytes used
11990  by the 128 bit variables, and 80 bytes for general purpose use.
11991  If any bit variables are used, the data variables will be placed in unused
11992  register banks and after the byte holding the last bit variable.
11993  For example, if register banks 0 and 1 are used, and there are 9 bit variables
11994  (two bytes used), 
11995 \emph on
11996 data
11997 \emph default
11998  variables will be placed starting from address 0x10 to 0x20 and continue
11999  at address 0x22.
12000  You can also use -
12001 \begin_inset ERT
12002 status collapsed
12003
12004 \begin_layout Standard
12005
12006
12007 \backslash
12008 /
12009 \end_layout
12010
12011 \end_inset
12012
12013 -data-loc
12014 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12015
12016 \end_inset
12017
12018  to specify the start address of the 
12019 \emph on
12020 data
12021 \emph default
12022  and -
12023 \begin_inset ERT
12024 status collapsed
12025
12026 \begin_layout Standard
12027
12028
12029 \backslash
12030 /
12031 \end_layout
12032
12033 \end_inset
12034
12035 -iram-size
12036 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12037
12038 \end_inset
12039
12040  to specify the size of the total internal RAM (
12041 \emph on
12042 data
12043 \emph default
12044 +
12045 \emph on
12046 idata
12047 \emph default
12048 ).
12049  
12050 \newline
12051
12052 \end_layout
12053
12054 \begin_layout Standard
12055 By default the 8051 linker will place the stack after the last byte of (i)data
12056  variables.
12057  Option -
12058 \begin_inset ERT
12059 status collapsed
12060
12061 \begin_layout Standard
12062
12063
12064 \backslash
12065 /
12066 \end_layout
12067
12068 \end_inset
12069
12070 -stack-loc
12071 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12072
12073 \end_inset
12074
12075  allows you to specify the start of the stack, i.e.
12076  you could start it after any data in the general purpose area.
12077  If your microcontroller has additional indirectly addressable internal
12078  RAM (
12079 \emph on
12080 idata
12081 \emph default
12082 ) you can place the stack on it.
12083  You may also need to use -
12084 \begin_inset ERT
12085 status collapsed
12086
12087 \begin_layout Standard
12088
12089
12090 \backslash
12091 /
12092 \end_layout
12093
12094 \end_inset
12095
12096 -xdata-loc
12097 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12098
12099 \end_inset
12100
12101  to set the start address of the external RAM (
12102 \emph on
12103 xdata
12104 \emph default
12105 ) and -
12106 \begin_inset ERT
12107 status collapsed
12108
12109 \begin_layout Standard
12110
12111
12112 \backslash
12113 /
12114 \end_layout
12115
12116 \end_inset
12117
12118 -xram-size
12119 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12120
12121 \end_inset
12122
12123  to specify its size.
12124  Same goes for the code memory, using -
12125 \begin_inset ERT
12126 status collapsed
12127
12128 \begin_layout Standard
12129
12130
12131 \backslash
12132 /
12133 \end_layout
12134
12135 \end_inset
12136
12137 -code-loc
12138 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12139
12140 \end_inset
12141
12142  and -
12143 \begin_inset ERT
12144 status collapsed
12145
12146 \begin_layout Standard
12147
12148
12149 \backslash
12150 /
12151 \end_layout
12152
12153 \end_inset
12154
12155 -code-size
12156 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12157
12158 \end_inset
12159
12160 .
12161  If in doubt, don't specify any options and see if the resulting memory
12162  layout is appropriate, then you can adjust it.
12163 \end_layout
12164
12165 \begin_layout Standard
12166 The linker generates two files with memory allocation information.
12167  The first, with extension .map
12168 \begin_inset LatexCommand \index{<file>.map}
12169
12170 \end_inset
12171
12172  shows all the variables and segments.
12173  The second with extension .mem
12174 \begin_inset LatexCommand \index{<file>.mem}
12175
12176 \end_inset
12177
12178  shows the final memory layout.
12179  The linker will complain either if memory segments overlap, there is not
12180  enough memory, or there is not enough space for stack.
12181  If you get any linking warnings and/or errors related to stack or segments
12182  allocation, take a look at either the .map or .mem files to find out what
12183  the problem is.
12184  The .mem file may even suggest a solution to the problem.
12185 \begin_inset VSpace bigskip
12186 \end_inset
12187
12188
12189 \end_layout
12190
12191 \begin_layout Subsection
12192 Z80/Z180 Storage Class
12193 \begin_inset LatexCommand \index{Z80!Storage class}
12194
12195 \end_inset
12196
12197  Language Extensions
12198 \end_layout
12199
12200 \begin_layout Subsubsection
12201 sfr
12202 \begin_inset LatexCommand \index{sfr}
12203
12204 \end_inset
12205
12206
12207 \begin_inset LatexCommand \index{\_\_sfr}
12208
12209 \end_inset
12210
12211  (in/out to 8-bit addresses)
12212 \end_layout
12213
12214 \begin_layout Standard
12215 The Z80
12216 \begin_inset LatexCommand \index{Z80}
12217
12218 \end_inset
12219
12220  family has separate address spaces for memory and 
12221 \emph on
12222 i
12223 \emph default
12224 nput/
12225 \emph on
12226 o
12227 \emph default
12228 utput memory.
12229  I/O memory
12230 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12231
12232 \end_inset
12233
12234
12235 \begin_inset LatexCommand \index{Z80!I/O memory}
12236
12237 \end_inset
12238
12239
12240 \begin_inset LatexCommand \index{Z180!I/O memory}
12241
12242 \end_inset
12243
12244  is accessed with special instructions, e.g.:
12245 \end_layout
12246
12247 \begin_layout Verse
12248
12249 \family typewriter
12250 sfr at 0x78 IoPort;\InsetSpace ~
12251 \InsetSpace ~
12252 /* define a var in I/O space at 78h called IoPort */
12253  
12254 \end_layout
12255
12256 \begin_layout Standard
12257 Writing 0x01 to this variable generates the assembly code:
12258 \end_layout
12259
12260 \begin_layout Verse
12261
12262 \family typewriter
12263 3E 01\InsetSpace ~
12264 \InsetSpace ~
12265 \InsetSpace ~
12266 \InsetSpace ~
12267 \InsetSpace ~
12268 \InsetSpace ~
12269 ld a,#0x01
12270 \newline
12271 D3 78\InsetSpace ~
12272 \InsetSpace ~
12273 \InsetSpace ~
12274 \InsetSpace ~
12275 \InsetSpace ~
12276 \InsetSpace ~
12277 out (_IoPort),a 
12278 \end_layout
12279
12280 \begin_layout Subsubsection
12281 banked sfr
12282 \begin_inset LatexCommand \index{sfr}
12283
12284 \end_inset
12285
12286
12287 \begin_inset LatexCommand \index{\_\_sfr}
12288
12289 \end_inset
12290
12291  (in/out to 16-bit addresses)
12292 \end_layout
12293
12294 \begin_layout Standard
12295 The keyword 
12296 \emph on
12297 banked
12298 \emph default
12299  is used to support 16 bit addresses in I/O memory e.g.:
12300 \end_layout
12301
12302 \begin_layout Verse
12303
12304 \family typewriter
12305 sfr banked at
12306 \begin_inset LatexCommand \index{at}
12307
12308 \end_inset
12309
12310
12311 \begin_inset LatexCommand \index{\_\_at}
12312
12313 \end_inset
12314
12315  0x123 IoPort; 
12316 \end_layout
12317
12318 \begin_layout Standard
12319 Writing 0x01 to this variable generates the assembly code:
12320 \end_layout
12321
12322 \begin_layout Verse
12323
12324 \family typewriter
12325 01 23 01\InsetSpace ~
12326 \InsetSpace ~
12327 \InsetSpace ~
12328 ld bc,#_IoPort
12329 \newline
12330 3E 01\InsetSpace ~
12331 \InsetSpace ~
12332 \InsetSpace ~
12333 \InsetSpace ~
12334 \InsetSpace ~
12335 \InsetSpace ~
12336 ld a,#0x01 
12337 \newline
12338 ED 79\InsetSpace ~
12339 \InsetSpace ~
12340 \InsetSpace ~
12341 \InsetSpace ~
12342 \InsetSpace ~
12343 \InsetSpace ~
12344 out (c),a 
12345 \end_layout
12346
12347 \begin_layout Subsubsection
12348 sfr
12349 \begin_inset LatexCommand \index{sfr}
12350
12351 \end_inset
12352
12353
12354 \begin_inset LatexCommand \index{\_\_sfr}
12355
12356 \end_inset
12357
12358  (in0/out0 to 8 bit addresses on Z180
12359 \begin_inset LatexCommand \index{Z180}
12360
12361 \end_inset
12362
12363 /HD64180
12364 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12365
12366 \end_inset
12367
12368 )
12369 \end_layout
12370
12371 \begin_layout Standard
12372 The compiler option -
12373 \begin_inset ERT
12374 status collapsed
12375
12376 \begin_layout Standard
12377
12378
12379 \backslash
12380 /
12381 \end_layout
12382
12383 \end_inset
12384
12385 -portmode
12386 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12387
12388 \end_inset
12389
12390 =180 (80) and a compiler #pragma\InsetSpace ~
12391 portmode
12392 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12393
12394 \end_inset
12395
12396  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12397 ns 
12398 \family typewriter
12399 in0/out0
12400 \family default
12401  instead of 
12402 \family typewriter
12403 in/out
12404 \family default
12405 .
12406  If you include the file z180.h this will be set automatically.
12407 \begin_inset VSpace bigskip
12408 \end_inset
12409
12410
12411 \end_layout
12412
12413 \begin_layout Subsection
12414 HC08 Storage Class
12415 \begin_inset LatexCommand \index{HC08!Storage class}
12416
12417 \end_inset
12418
12419  Language Extensions
12420 \end_layout
12421
12422 \begin_layout Subsubsection
12423 data
12424 \begin_inset LatexCommand \index{data (hc08 storage class)}
12425
12426 \end_inset
12427
12428
12429 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12430
12431 \end_inset
12432
12433  
12434 \end_layout
12435
12436 \begin_layout Standard
12437 The data storage class declares a variable that resides in the first 256
12438  bytes of memory (the direct page).
12439  The HC08
12440 \begin_inset LatexCommand \index{HC08}
12441
12442 \end_inset
12443
12444  is most efficient at accessing variables (especially pointers) stored here.
12445 \end_layout
12446
12447 \begin_layout Subsubsection
12448 xdata
12449 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12450
12451 \end_inset
12452
12453
12454 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12455
12456 \end_inset
12457
12458  
12459 \end_layout
12460
12461 \begin_layout Standard
12462 The xdata storage class declares a variable that can reside anywhere in
12463  memory.
12464  This is the default if no storage class is specified.
12465  
12466 \begin_inset VSpace bigskip
12467 \end_inset
12468
12469
12470 \end_layout
12471
12472 \begin_layout Section
12473 Absolute Addressing
12474 \begin_inset LatexCommand \index{Absolute addressing}
12475
12476 \end_inset
12477
12478
12479 \end_layout
12480
12481 \begin_layout Standard
12482 Data items can be assigned an absolute address with the 
12483 \emph on
12484 at
12485 \begin_inset LatexCommand \index{at}
12486
12487 \end_inset
12488
12489
12490 \begin_inset LatexCommand \index{\_\_at}
12491
12492 \end_inset
12493
12494  <address>
12495 \emph default
12496  keyword, in addition to a storage class, e.g.:
12497 \end_layout
12498
12499 \begin_layout Verse
12500
12501 \family typewriter
12502 xdata
12503 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12504
12505 \end_inset
12506
12507
12508 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12509
12510 \end_inset
12511
12512  at
12513 \begin_inset LatexCommand \index{at}
12514
12515 \end_inset
12516
12517
12518 \begin_inset LatexCommand \index{\_\_at}
12519
12520 \end_inset
12521
12522  0x7ffe unsigned int chksum;
12523 \end_layout
12524
12525 \begin_layout Standard
12526 or, better conforming to ISO/IEC 9899 C:
12527 \end_layout
12528
12529 \begin_layout Verse
12530
12531 \family typewriter
12532 __xdata __at (0x7ffe) unsigned int chksum;
12533 \end_layout
12534
12535 \begin_layout Standard
12536 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12537  of the external ram.
12538  The compiler does 
12539 \emph on
12540 not
12541 \emph default
12542  reserve any space for variables declared in this way
12543 \begin_inset Marginal
12544 status collapsed
12545
12546 \begin_layout Standard
12547
12548 \series bold
12549 \InsetSpace ~
12550 !
12551 \end_layout
12552
12553 \end_inset
12554
12555  (they are implemented with an equate in the assembler).
12556  Thus it is left to the programmer to make sure there are no overlaps with
12557  other variables that are declared without the absolute address.
12558  The assembler listing file (.lst
12559 \begin_inset LatexCommand \index{<file>.lst}
12560
12561 \end_inset
12562
12563 ) and the linker output files (.rst
12564 \begin_inset LatexCommand \index{<file>.rst}
12565
12566 \end_inset
12567
12568 ) and (.map
12569 \begin_inset LatexCommand \index{<file>.map}
12570
12571 \end_inset
12572
12573 ) are good places to look for such overlaps.
12574  Variables with an absolute address are 
12575 \emph on
12576 not
12577 \begin_inset Marginal
12578 status collapsed
12579
12580 \begin_layout Standard
12581
12582 \series bold
12583 \InsetSpace ~
12584 !
12585 \end_layout
12586
12587 \end_inset
12588
12589
12590 \emph default
12591  initialized
12592 \begin_inset LatexCommand \index{Variable initialization}
12593
12594 \end_inset
12595
12596 .
12597 \end_layout
12598
12599 \begin_layout Standard
12600 In case of memory mapped I/O devices the keyword 
12601 \emph on
12602 volatile
12603 \emph default
12604  has to be used to tell the compiler that accesses might not be removed:
12605 \end_layout
12606
12607 \begin_layout Verse
12608
12609 \family typewriter
12610 volatile
12611 \begin_inset LatexCommand \index{volatile}
12612
12613 \end_inset
12614
12615  __xdata
12616 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12617
12618 \end_inset
12619
12620  __at
12621 \begin_inset LatexCommand \index{at}
12622
12623 \end_inset
12624
12625  (0x8000) unsigned char PORTA_8255;
12626 \end_layout
12627
12628 \begin_layout Standard
12629 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12630 r) array
12631 \family typewriter
12632 \size footnotesize
12633
12634 \begin_inset LatexCommand \index{Aligned array}
12635
12636 \end_inset
12637
12638
12639 \family default
12640 \size default
12641  starts at a block (256 byte) boundary
12642 \begin_inset LatexCommand \index{block boundary}
12643
12644 \end_inset
12645
12646  (section 
12647 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12648
12649 \end_inset
12650
12651  has an example).
12652 \newline
12653 Absolute addresses can be specified for variables in all
12654  storage classes, e.g.:
12655 \end_layout
12656
12657 \begin_layout Verse
12658
12659 \family typewriter
12660 __bit
12661 \begin_inset LatexCommand \index{bit}
12662
12663 \end_inset
12664
12665  __at
12666 \begin_inset LatexCommand \index{at}
12667
12668 \end_inset
12669
12670  (0x02) bvar;
12671 \end_layout
12672
12673 \begin_layout Standard
12674 The above example will allocate the variable at offset 0x02 in the bit-addressab
12675 le space.
12676  There is no real advantage to assigning absolute addresses to variables
12677  in this manner, unless you want strict control over all the variables allocated.
12678  One possible use would be to write hardware portable code.
12679  For example, if you have a routine that uses one or more of the microcontroller
12680  I/O pins, and such pins are different for two different hardwares, you
12681  can declare the I/O pins in your routine using:
12682 \end_layout
12683
12684 \begin_layout Verse
12685
12686 \family typewriter
12687 extern volatile
12688 \begin_inset LatexCommand \index{volatile}
12689
12690 \end_inset
12691
12692  __bit MOSI;\InsetSpace ~
12693 \InsetSpace ~
12694 \InsetSpace ~
12695 \InsetSpace ~
12696 /* master out, slave in */
12697 \newline
12698 extern volatile __bit MISO;\InsetSpace ~
12699 \InsetSpace ~
12700 \InsetSpace ~
12701 \InsetSpace ~
12702 /* master
12703  in, slave out */
12704 \newline
12705 extern volatile __bit MCLK;\InsetSpace ~
12706 \InsetSpace ~
12707 \InsetSpace ~
12708 \InsetSpace ~
12709 /* master clock */
12710 \newline
12711
12712 \newline
12713 /* Input and
12714  Output of a byte on a 3-wire serial bus.
12715 \newline
12716 \InsetSpace ~
12717 \InsetSpace ~
12718 \InsetSpace ~
12719 If needed adapt polarity of clock,
12720  polarity of data and bit order
12721 \newline
12722 \InsetSpace ~
12723 */
12724 \newline
12725 unsigned char spi_io(unsigned char out_byte)
12726  
12727 \newline
12728
12729 \newline
12730 \InsetSpace ~
12731 \InsetSpace ~
12732 \InsetSpace ~
12733 \InsetSpace ~
12734 unsigned char i=8;
12735 \newline
12736 \InsetSpace ~
12737 \InsetSpace ~
12738 \InsetSpace ~
12739 \InsetSpace ~
12740 do { 
12741 \newline
12742 \InsetSpace ~
12743 \InsetSpace ~
12744 \InsetSpace ~
12745 \InsetSpace ~
12746 \InsetSpace ~
12747 \InsetSpace ~
12748 \InsetSpace ~
12749 \InsetSpace ~
12750 MOSI = out_byte & 0x80; 
12751 \newline
12752 \InsetSpace ~
12753 \InsetSpace ~
12754 \InsetSpace ~
12755 \InsetSpace ~
12756 \InsetSpace ~
12757 \InsetSpace ~
12758 \InsetSpace ~
12759 \InsetSpace ~
12760 out_byte <<= 1;
12761 \newline
12762 \InsetSpace ~
12763 \InsetSpace ~
12764 \InsetSpace ~
12765 \InsetSpace ~
12766 \InsetSpace ~
12767 \InsetSpace ~
12768 \InsetSpace ~
12769 \InsetSpace ~
12770 MCLK =
12771  1; 
12772 \newline
12773 \InsetSpace ~
12774 \InsetSpace ~
12775 \InsetSpace ~
12776 \InsetSpace ~
12777 \InsetSpace ~
12778 \InsetSpace ~
12779 \InsetSpace ~
12780 \InsetSpace ~
12781 /* _asm nop _endasm; */\InsetSpace ~
12782 \InsetSpace ~
12783 \InsetSpace ~
12784 \InsetSpace ~
12785 \InsetSpace ~
12786 \InsetSpace ~
12787 \InsetSpace ~
12788 \InsetSpace ~
12789 /* for slow peripherals */
12790 \newline
12791 \InsetSpace ~
12792 \InsetSpace ~
12793 \InsetSpace ~
12794 \InsetSpace ~
12795 \InsetSpace ~
12796 \InsetSpace ~
12797 \InsetSpace ~
12798 \InsetSpace ~
12799 if(MISO) 
12800 \newline
12801 \InsetSpace ~
12802 \InsetSpace ~
12803 \InsetSpace ~
12804 \InsetSpace ~
12805 \InsetSpace ~
12806 \InsetSpace ~
12807 \InsetSpace ~
12808 \InsetSpace ~
12809 \InsetSpace ~
12810 \InsetSpace ~
12811 \InsetSpace ~
12812 \InsetSpace ~
12813 out_byte +=
12814  1; 
12815 \newline
12816 \InsetSpace ~
12817 \InsetSpace ~
12818 \InsetSpace ~
12819 \InsetSpace ~
12820 \InsetSpace ~
12821 \InsetSpace ~
12822 \InsetSpace ~
12823 \InsetSpace ~
12824 MCLK = 0; 
12825 \newline
12826 \InsetSpace ~
12827 \InsetSpace ~
12828 \InsetSpace ~
12829 \InsetSpace ~
12830 } while(--i);
12831 \newline
12832 \InsetSpace ~
12833 \InsetSpace ~
12834 \InsetSpace ~
12835 \InsetSpace ~
12836 return out_byte; 
12837 \newline
12838 }
12839 \end_layout
12840
12841 \begin_layout Standard
12842 Then, someplace in the code for the first hardware you would use
12843 \end_layout
12844
12845 \begin_layout Verse
12846
12847 \family typewriter
12848 __bit __at
12849 \begin_inset LatexCommand \index{at}
12850
12851 \end_inset
12852
12853
12854 \begin_inset LatexCommand \index{\_\_at}
12855
12856 \end_inset
12857
12858  (0x80) MOSI;\InsetSpace ~
12859 \InsetSpace ~
12860 \InsetSpace ~
12861 \InsetSpace ~
12862 /* I/O port 0, bit 0 */
12863 \newline
12864 __bit __at (0x81) MISO;\InsetSpace ~
12865 \InsetSpace ~
12866 \InsetSpace ~
12867 \InsetSpace ~
12868 /* I/O port 0,
12869  bit 1 */
12870 \newline
12871 __bit __at (0x82) MCLK;\InsetSpace ~
12872 \InsetSpace ~
12873 \InsetSpace ~
12874 \InsetSpace ~
12875 /* I/O port 0, bit 2 */
12876 \end_layout
12877
12878 \begin_layout Standard
12879 Similarly, for the second hardware you would use
12880 \end_layout
12881
12882 \begin_layout Verse
12883
12884 \family typewriter
12885 __bit __at (0x83) MOSI;\InsetSpace ~
12886 \InsetSpace ~
12887 \InsetSpace ~
12888 \InsetSpace ~
12889 /* I/O port 0, bit 3 */
12890 \newline
12891 __bit __at (0x91) MISO;\InsetSpace ~
12892 \InsetSpace ~
12893 \InsetSpace ~
12894 \InsetSpace ~
12895 /*
12896  I/O port 1, bit 1 */
12897 \newline
12898 __bit
12899 \begin_inset LatexCommand \index{bit}
12900
12901 \end_inset
12902
12903  __at (0x92) MCLK;\InsetSpace ~
12904 \InsetSpace ~
12905 \InsetSpace ~
12906 \InsetSpace ~
12907 /* I/O port 1, bit 2 */
12908 \end_layout
12909
12910 \begin_layout Standard
12911 and you can use the same hardware dependent routine without changes, as
12912  for example in a library.
12913  This is somehow similar to sbit, but only one absolute address has to be
12914  specified in the whole project.
12915 \begin_inset VSpace bigskip
12916 \end_inset
12917
12918
12919 \end_layout
12920
12921 \begin_layout Section
12922 Parameters
12923 \begin_inset LatexCommand \index{Parameters}
12924
12925 \end_inset
12926
12927
12928 \begin_inset LatexCommand \index{function parameter}
12929
12930 \end_inset
12931
12932  & Local Variables
12933 \begin_inset LatexCommand \index{local variables}
12934
12935 \end_inset
12936
12937
12938 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12939
12940 \end_inset
12941
12942
12943 \end_layout
12944
12945 \begin_layout Standard
12946 Automatic (local) variables and parameters to functions can either be placed
12947  on the stack or in data-space.
12948  The default action of the compiler is to place these variables in the internal
12949  RAM (for small model) or external RAM (for large model).
12950  This in fact makes them similar to 
12951 \emph on
12952 static
12953 \begin_inset LatexCommand \index{static}
12954
12955 \end_inset
12956
12957
12958 \emph default
12959  so by default functions are non-reentrant
12960 \begin_inset LatexCommand \index{reentrant}
12961
12962 \end_inset
12963
12964 .
12965  
12966 \newline
12967
12968 \newline
12969 They can be placed on the stack
12970 \begin_inset LatexCommand \index{stack}
12971
12972 \end_inset
12973
12974  by using the
12975 \emph on
12976  -
12977 \begin_inset ERT
12978 status collapsed
12979
12980 \begin_layout Standard
12981
12982
12983 \backslash
12984 /
12985 \end_layout
12986
12987 \end_inset
12988
12989 -stack-auto
12990 \begin_inset LatexCommand \index{-\/-stack-auto}
12991
12992 \end_inset
12993
12994
12995 \emph default
12996  option, by using 
12997 \emph on
12998 #pragma\InsetSpace ~
12999 stackauto
13000 \emph default
13001
13002 \begin_inset LatexCommand \index{\#pragma stackauto}
13003
13004 \end_inset
13005
13006  or by using the 
13007 \emph on
13008 reentrant
13009 \begin_inset LatexCommand \index{reentrant}
13010
13011 \end_inset
13012
13013
13014 \emph default
13015  keyword in the function declaration, e.g.:
13016 \end_layout
13017
13018 \begin_layout Verse
13019
13020 \family typewriter
13021 unsigned char foo(char i) __reentrant 
13022 \newline
13023
13024 \newline
13025 \InsetSpace ~
13026 \InsetSpace ~
13027 \InsetSpace ~
13028 \InsetSpace ~
13029 ...
13030  
13031 \newline
13032 }
13033 \end_layout
13034
13035 \begin_layout Standard
13036 Since stack space on 8051 is limited, the 
13037 \emph on
13038 reentrant 
13039 \emph default
13040 keyword or the
13041 \emph on
13042  -
13043 \begin_inset ERT
13044 status collapsed
13045
13046 \begin_layout Standard
13047
13048
13049 \backslash
13050 /
13051 \end_layout
13052
13053 \end_inset
13054
13055 -stack-auto
13056 \emph default
13057  option should be used sparingly.
13058  Note that the reentrant keyword just means that the parameters & local
13059  variables will be allocated to the stack, it 
13060 \emph on
13061 does not
13062 \emph default
13063  mean that the function is register bank
13064 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13065
13066 \end_inset
13067
13068  independent.
13069 \newline
13070
13071 \newline
13072 Local variables
13073 \begin_inset LatexCommand \index{local variables}
13074
13075 \end_inset
13076
13077  can be assigned storage classes and absolute
13078 \begin_inset LatexCommand \index{Absolute addressing}
13079
13080 \end_inset
13081
13082  addresses, e.g.: 
13083 \end_layout
13084
13085 \begin_layout Verse
13086
13087 \family typewriter
13088 unsigned char foo() 
13089 \newline
13090 {
13091 \newline
13092 \InsetSpace ~
13093 \InsetSpace ~
13094 \InsetSpace ~
13095 \InsetSpace ~
13096 __xdata unsigned char i;
13097 \newline
13098 \InsetSpace ~
13099 \InsetSpace ~
13100 \InsetSpace ~
13101 \InsetSpace ~
13102 __bit bvar;
13103 \newline
13104 \InsetSpace ~
13105 \InsetSpace ~
13106 \InsetSpace ~
13107 \InsetSpace ~
13108 __data __at
13109 \begin_inset LatexCommand \index{at}
13110
13111 \end_inset
13112
13113  (0x31) unsigned char j;
13114 \newline
13115 \InsetSpace ~
13116 \InsetSpace ~
13117 \InsetSpace ~
13118 \InsetSpace ~
13119 ...
13120  
13121 \newline
13122 }
13123 \end_layout
13124
13125 \begin_layout Standard
13126 In the above example the variable 
13127 \emph on
13128 i
13129 \emph default
13130  will be allocated in the external ram, 
13131 \emph on
13132 bvar
13133 \emph default
13134  in bit addressable space and
13135 \emph on
13136  j
13137 \emph default
13138  in internal ram.
13139  When compiled with 
13140 \emph on
13141 -
13142 \begin_inset ERT
13143 status collapsed
13144
13145 \begin_layout Standard
13146
13147
13148 \backslash
13149 /
13150 \end_layout
13151
13152 \end_inset
13153
13154 -stack-auto
13155 \emph default
13156  or when a function is declared as 
13157 \emph on
13158 reentrant
13159 \emph default
13160  this should only be done for static variables.
13161 \end_layout
13162
13163 \begin_layout Standard
13164 Parameters
13165 \begin_inset LatexCommand \index{function parameter}
13166
13167 \end_inset
13168
13169  however are not allowed any storage class
13170 \begin_inset LatexCommand \index{Storage class}
13171
13172 \end_inset
13173
13174 , (storage classes for parameters will be ignored), their allocation is
13175  governed by the memory model in use, and the reentrancy options.
13176 \end_layout
13177
13178 \begin_layout Standard
13179 It is however allowed to use bit parameters in reentrant functions and also
13180  non-static local bit variables are supported.
13181  Efficient use is limited to 8 semi-bitregisters in bit space.
13182  They are pushed and popped to stack
13183 \begin_inset LatexCommand \index{stack}
13184
13185 \end_inset
13186
13187  as a single byte just like the normal registers.
13188 \end_layout
13189
13190 \begin_layout Section
13191 Overlaying
13192 \begin_inset LatexCommand \label{sub:Overlaying}
13193
13194 \end_inset
13195
13196
13197 \begin_inset LatexCommand \index{Overlaying}
13198
13199 \end_inset
13200
13201
13202 \end_layout
13203
13204 \begin_layout Standard
13205 For non-reentrant
13206 \begin_inset LatexCommand \index{reentrant}
13207
13208 \end_inset
13209
13210  functions SDCC will try to reduce internal ram space usage by overlaying
13211  parameters and local variables of a function (if possible).
13212  Parameters and local variables
13213 \begin_inset LatexCommand \index{local variables}
13214
13215 \end_inset
13216
13217  of a function will be allocated to an overlayable segment if the function
13218  has 
13219 \emph on
13220 no other function calls and the function is non-reentrant and the memory
13221  model
13222 \begin_inset LatexCommand \index{Memory model}
13223
13224 \end_inset
13225
13226  is small.
13227
13228 \emph default
13229  If an explicit storage class
13230 \begin_inset LatexCommand \index{Storage class}
13231
13232 \end_inset
13233
13234  is specified for a local variable, it will NOT be overlayed.
13235 \end_layout
13236
13237 \begin_layout Standard
13238 Note that the compiler (not the linkage editor) makes the decision for overlayin
13239 g the data items.
13240  Functions that are called from an interrupt service routine
13241 \begin_inset Marginal
13242 status collapsed
13243
13244 \begin_layout Standard
13245
13246 \series bold
13247 !
13248 \end_layout
13249
13250 \end_inset
13251
13252  should be preceded by a #pragma\InsetSpace ~
13253 nooverlay
13254 \begin_inset LatexCommand \index{\#pragma nooverlay}
13255
13256 \end_inset
13257
13258  if they are not reentrant.
13259 \end_layout
13260
13261 \begin_layout Standard
13262 Also note that the compiler does not do any processing of inline assembler
13263  code, so the compiler might incorrectly assign local variables and parameters
13264  of a function into the overlay segment if the inline assembler code calls
13265  other c-functions that might use the overlay.
13266  In that case the #pragma\InsetSpace ~
13267 nooverlay should be used.
13268 \end_layout
13269
13270 \begin_layout Standard
13271 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13272 tion
13273 \begin_inset LatexCommand \index{Multiplication}
13274
13275 \end_inset
13276
13277  or division
13278 \begin_inset LatexCommand \index{Division}
13279
13280 \end_inset
13281
13282  will NOT be overlayed since these are implemented using external functions,
13283  e.g.:
13284 \end_layout
13285
13286 \begin_layout Verse
13287
13288 \family typewriter
13289 #pragma save 
13290 \newline
13291 #pragma nooverlay
13292 \begin_inset LatexCommand \index{\#pragma nooverlay}
13293
13294 \end_inset
13295
13296  
13297 \newline
13298 void set_error(unsigned char errcd) 
13299 \newline
13300 {
13301 \newline
13302 \InsetSpace ~
13303 \InsetSpace ~
13304 \InsetSpace ~
13305 \InsetSpace ~
13306 P3 = errcd;
13307 \newline
13308
13309 \newline
13310 #pragma restore 
13311 \newline
13312
13313 \newline
13314 void
13315  some_isr () __interrupt
13316 \begin_inset LatexCommand \index{interrupt}
13317
13318 \end_inset
13319
13320  (2)
13321 \newline
13322 {
13323 \newline
13324 \InsetSpace ~
13325 \InsetSpace ~
13326 \InsetSpace ~
13327 \InsetSpace ~
13328 ...
13329 \newline
13330 \InsetSpace ~
13331 \InsetSpace ~
13332 \InsetSpace ~
13333 \InsetSpace ~
13334 set_error(10);
13335 \newline
13336 \InsetSpace ~
13337 \InsetSpace ~
13338 \InsetSpace ~
13339 \InsetSpace ~
13340 ...
13341  
13342 \newline
13343 }
13344 \end_layout
13345
13346 \begin_layout Standard
13347 In the above example the parameter 
13348 \emph on
13349 errcd
13350 \emph default
13351  for the function 
13352 \emph on
13353 set_error
13354 \emph default
13355  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13356 nooverlay was
13357  not present, this could cause unpredictable runtime behavior when called
13358  from an interrupt service routine.
13359  The #pragma\InsetSpace ~
13360 nooverlay ensures that the parameters and local variables for
13361  the function are NOT overlayed.
13362 \begin_inset VSpace bigskip
13363 \end_inset
13364
13365
13366 \end_layout
13367
13368 \begin_layout Section
13369 Interrupt Service Routines
13370 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13371
13372 \end_inset
13373
13374
13375 \end_layout
13376
13377 \begin_layout Subsection
13378 General Information
13379 \end_layout
13380
13381 \begin_layout Standard
13382 SDCC allows 
13383 \emph on
13384 i
13385 \emph default
13386 nterrupt 
13387 \emph on
13388 s
13389 \emph default
13390 ervice 
13391 \emph on
13392 r
13393 \emph default
13394 outines to be coded in C, with some extended keywords.
13395 \end_layout
13396
13397 \begin_layout Verse
13398
13399 \family typewriter
13400 void timer_isr (void) __interrupt (1) __using (1) 
13401 \newline
13402
13403 \newline
13404 \InsetSpace ~
13405 \InsetSpace ~
13406 \InsetSpace ~
13407 \InsetSpace ~
13408 ...
13409  
13410 \newline
13411 }
13412 \end_layout
13413
13414 \begin_layout Standard
13415 The optional number following the 
13416 \emph on
13417 interrupt
13418 \begin_inset LatexCommand \index{interrupt}
13419
13420 \end_inset
13421
13422
13423 \begin_inset LatexCommand \index{\_\_interrupt}
13424
13425 \end_inset
13426
13427
13428 \emph default
13429  keyword is the interrupt number this routine will service.
13430  When present, the compiler will insert a call to this routine in the interrupt
13431  vector table
13432 \begin_inset LatexCommand \index{interrupt vector table}
13433
13434 \end_inset
13435
13436  for the interrupt number specified.
13437  If you have multiple source files in your project, interrupt service routines
13438  can be present in any of them, but a prototype of the isr MUST be present
13439  or included in the file that contains the function 
13440 \emph on
13441 main
13442 \emph default
13443 .
13444  The optional (8051 specific) keyword 
13445 \emph on
13446 using
13447 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13448
13449 \end_inset
13450
13451
13452 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13453
13454 \end_inset
13455
13456
13457 \emph default
13458  can be used to tell the compiler to use the specified register bank when
13459  generating code for this function.
13460  
13461 \newline
13462 Interrupt service routines open the door for some very interesting bugs:
13463 \end_layout
13464
13465 \begin_layout Subsubsection
13466 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13467
13468 \end_inset
13469
13470 Common interrupt pitfall: variable not declared 
13471 \emph on
13472 volatile
13473 \end_layout
13474
13475 \begin_layout Standard
13476 If an interrupt service routine changes variables which are accessed by
13477  other functions these variables have to be declared 
13478 \emph on
13479 volatile
13480 \emph default
13481
13482 \begin_inset LatexCommand \index{volatile}
13483
13484 \end_inset
13485
13486 .
13487  See 
13488 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13489
13490 \end_inset
13491
13492  .
13493 \end_layout
13494
13495 \begin_layout Subsubsection
13496 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13497
13498 \end_inset
13499
13500 Common interrupt pitfall: 
13501 \emph on
13502 non-atomic access
13503 \end_layout
13504
13505 \begin_layout Standard
13506 If the access to these variables is not 
13507 \emph on
13508 atomic
13509 \begin_inset LatexCommand \index{atomic}
13510
13511 \end_inset
13512
13513
13514 \emph default
13515  (i.e.
13516  the processor needs more than one instruction for the access and could
13517  be interrupted while accessing the variable) the interrupt must be disabled
13518  during the access to avoid inconsistent data.
13519  
13520 \newline
13521 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13522  and should be protected by disabling interrupts.
13523  You're not automatically on the safe side if you use 8 bit variables though.
13524  We need an example here: f.e.
13525  on the 8051 the harmless looking 
13526 \begin_inset Quotes srd
13527 \end_inset
13528
13529
13530 \family typewriter
13531 flags\InsetSpace ~
13532 |=\InsetSpace ~
13533 0x80;
13534 \family default
13535
13536 \begin_inset Quotes sld
13537 \end_inset
13538
13539  is not atomic if 
13540 \family typewriter
13541 flags
13542 \family default
13543  resides in xdata.
13544  Setting 
13545 \begin_inset Quotes srd
13546 \end_inset
13547
13548
13549 \family typewriter
13550 flags\InsetSpace ~
13551 |=\InsetSpace ~
13552 0x40;
13553 \family default
13554
13555 \begin_inset Quotes sld
13556 \end_inset
13557
13558  from within an interrupt routine might get lost if the interrupt occurs
13559  at the wrong time.
13560  
13561 \begin_inset Quotes sld
13562 \end_inset
13563
13564
13565 \family typewriter
13566 counter\InsetSpace ~
13567 +=\InsetSpace ~
13568 8;
13569 \family default
13570
13571 \begin_inset Quotes srd
13572 \end_inset
13573
13574  is not atomic on the 8051 even if 
13575 \family typewriter
13576 counter
13577 \family default
13578  is located in data memory.
13579 \newline
13580 Bugs like these are hard to reproduce and can
13581  cause a lot of trouble.
13582  
13583 \end_layout
13584
13585 \begin_layout Subsubsection
13586 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13587
13588 \end_inset
13589
13590 Common interrupt pitfall: 
13591 \emph on
13592 stack overflow
13593 \end_layout
13594
13595 \begin_layout Standard
13596 The return address and the registers used in the interrupt service routine
13597  are saved on the stack
13598 \begin_inset LatexCommand \index{stack}
13599
13600 \end_inset
13601
13602  so there must be sufficient stack space.
13603  If there isn't variables or registers (or even the return address itself)
13604  will be corrupted.
13605  This 
13606 \emph on
13607 stack overflow
13608 \emph default
13609
13610 \begin_inset LatexCommand \index{stack overflow}
13611
13612 \end_inset
13613
13614  is most likely to happen if the interrupt occurs during the 
13615 \begin_inset Quotes sld
13616 \end_inset
13617
13618 deepest
13619 \begin_inset Quotes srd
13620 \end_inset
13621
13622  subroutine when the stack is already in use for f.e.
13623  many return addresses.
13624 \end_layout
13625
13626 \begin_layout Subsubsection
13627 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13628
13629 \end_inset
13630
13631 Common interrupt pitfall: 
13632 \emph on
13633 use of non-reentrant functions
13634 \end_layout
13635
13636 \begin_layout Standard
13637 A special note here, int (16 bit) and long (32 bit) integer division
13638 \begin_inset LatexCommand \index{Division}
13639
13640 \end_inset
13641
13642 , multiplication
13643 \begin_inset LatexCommand \index{Multiplication}
13644
13645 \end_inset
13646
13647  & modulus
13648 \begin_inset LatexCommand \index{Modulus}
13649
13650 \end_inset
13651
13652  and floating-point
13653 \begin_inset LatexCommand \index{Floating point support}
13654
13655 \end_inset
13656
13657  operations are implemented using external support routines.
13658  If an interrupt service routine needs to do any of these operations then
13659  the support routines (as mentioned in a following section) will have to
13660  be recompiled using the
13661 \emph on
13662  -
13663 \begin_inset ERT
13664 status collapsed
13665
13666 \begin_layout Standard
13667
13668
13669 \backslash
13670 /
13671 \end_layout
13672
13673 \end_inset
13674
13675 -stack-auto
13676 \begin_inset LatexCommand \index{-\/-stack-auto}
13677
13678 \end_inset
13679
13680
13681 \emph default
13682  option and the source file will need to be compiled using the 
13683 \emph on
13684 -
13685 \begin_inset ERT
13686 status collapsed
13687
13688 \begin_layout Standard
13689
13690
13691 \backslash
13692 /
13693 \end_layout
13694
13695 \end_inset
13696
13697 -int-long-reent
13698 \emph default
13699
13700 \begin_inset LatexCommand \index{-\/-int-long-reent}
13701
13702 \end_inset
13703
13704  compiler option.
13705  
13706 \newline
13707 Note, the type promotion
13708 \begin_inset LatexCommand \index{type promotion}
13709
13710 \end_inset
13711
13712  required by ANSI C can cause 16 bit routines to be used
13713 \begin_inset Marginal
13714 status collapsed
13715
13716 \begin_layout Standard
13717
13718 \series bold
13719 \InsetSpace ~
13720 !
13721 \end_layout
13722
13723 \end_inset
13724
13725  without the programmer being aware of it.
13726  See f.e.
13727  the cast 
13728 \family typewriter
13729 (unsigned char)(tail-1)
13730 \family default
13731  within the if clause in section 
13732 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13733
13734 \end_inset
13735
13736 .
13737 \end_layout
13738
13739 \begin_layout Standard
13740 Calling other functions from an interrupt service routine is not recommended,
13741  avoid it if possible.
13742  Note that when some function is called from an interrupt service routine
13743  it should be preceded by a #pragma\InsetSpace ~
13744 nooverlay
13745 \begin_inset LatexCommand \index{\#pragma nooverlay}
13746
13747 \end_inset
13748
13749  if it is not reentrant.
13750  Furthermore nonreentrant functions should not be called from the main program
13751  while the interrupt service routine might be active.
13752  They also must not be called from low priority interrupt service routines
13753  while a high priority interrupt service routine might be active.
13754  You could use semaphores or make the function
13755 \emph on
13756  critical
13757 \emph default
13758  if all parameters are passed in registers.
13759 \newline
13760  Also see section 
13761 \begin_inset LatexCommand \ref{sub:Overlaying}
13762
13763 \end_inset
13764
13765 \InsetSpace ~
13766 about Overlaying and section 
13767 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13768
13769 \end_inset
13770
13771 \InsetSpace ~
13772 about Functions using private register banks.
13773 \begin_inset VSpace bigskip
13774 \end_inset
13775
13776
13777 \end_layout
13778
13779 \begin_layout Subsection
13780 MCS51/DS390 Interrupt Service Routines
13781 \end_layout
13782
13783 \begin_layout Standard
13784 Interrupt
13785 \begin_inset LatexCommand \index{interrupt}
13786
13787 \end_inset
13788
13789  numbers and the corresponding address & descriptions for the Standard 8051/8052
13790  are listed below.
13791  SDCC will automatically adjust the 
13792 \begin_inset LatexCommand \index{interrupt vector table}
13793
13794 \end_inset
13795
13796  to the maximum interrupt number specified.
13797 \newline
13798
13799 \end_layout
13800
13801 \begin_layout Standard
13802 \align center
13803 \begin_inset Tabular
13804 <lyxtabular version="3" rows="9" columns="3">
13805 <features>
13806 <column alignment="center" valignment="top" leftline="true" width="0in">
13807 <column alignment="left" valignment="top" leftline="true" width="0in">
13808 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13809 <row topline="true" bottomline="true">
13810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13811 \begin_inset Text
13812
13813 \begin_layout Standard
13814 Interrupt #
13815 \end_layout
13816
13817 \end_inset
13818 </cell>
13819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13820 \begin_inset Text
13821
13822 \begin_layout Standard
13823 Description
13824 \end_layout
13825
13826 \end_inset
13827 </cell>
13828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13829 \begin_inset Text
13830
13831 \begin_layout Standard
13832 Vector Address
13833 \end_layout
13834
13835 \end_inset
13836 </cell>
13837 </row>
13838 <row topline="true">
13839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13840 \begin_inset Text
13841
13842 \begin_layout Standard
13843 0
13844 \end_layout
13845
13846 \end_inset
13847 </cell>
13848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13849 \begin_inset Text
13850
13851 \begin_layout Standard
13852 External 0
13853 \end_layout
13854
13855 \end_inset
13856 </cell>
13857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13858 \begin_inset Text
13859
13860 \begin_layout Standard
13861 0x0003
13862 \end_layout
13863
13864 \end_inset
13865 </cell>
13866 </row>
13867 <row topline="true">
13868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13869 \begin_inset Text
13870
13871 \begin_layout Standard
13872 1
13873 \end_layout
13874
13875 \end_inset
13876 </cell>
13877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13878 \begin_inset Text
13879
13880 \begin_layout Standard
13881 Timer 0
13882 \end_layout
13883
13884 \end_inset
13885 </cell>
13886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13887 \begin_inset Text
13888
13889 \begin_layout Standard
13890 0x000b
13891 \end_layout
13892
13893 \end_inset
13894 </cell>
13895 </row>
13896 <row topline="true">
13897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13898 \begin_inset Text
13899
13900 \begin_layout Standard
13901 2
13902 \end_layout
13903
13904 \end_inset
13905 </cell>
13906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13907 \begin_inset Text
13908
13909 \begin_layout Standard
13910 External 1
13911 \end_layout
13912
13913 \end_inset
13914 </cell>
13915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13916 \begin_inset Text
13917
13918 \begin_layout Standard
13919 0x0013
13920 \end_layout
13921
13922 \end_inset
13923 </cell>
13924 </row>
13925 <row topline="true">
13926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13927 \begin_inset Text
13928
13929 \begin_layout Standard
13930 3
13931 \end_layout
13932
13933 \end_inset
13934 </cell>
13935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13936 \begin_inset Text
13937
13938 \begin_layout Standard
13939 Timer 1
13940 \end_layout
13941
13942 \end_inset
13943 </cell>
13944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13945 \begin_inset Text
13946
13947 \begin_layout Standard
13948 0x001b
13949 \end_layout
13950
13951 \end_inset
13952 </cell>
13953 </row>
13954 <row topline="true">
13955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13956 \begin_inset Text
13957
13958 \begin_layout Standard
13959 4
13960 \end_layout
13961
13962 \end_inset
13963 </cell>
13964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13965 \begin_inset Text
13966
13967 \begin_layout Standard
13968 Serial
13969 \end_layout
13970
13971 \end_inset
13972 </cell>
13973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13974 \begin_inset Text
13975
13976 \begin_layout Standard
13977 0x0023
13978 \end_layout
13979
13980 \end_inset
13981 </cell>
13982 </row>
13983 <row topline="true">
13984 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13985 \begin_inset Text
13986
13987 \begin_layout Standard
13988 5
13989 \end_layout
13990
13991 \end_inset
13992 </cell>
13993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13994 \begin_inset Text
13995
13996 \begin_layout Standard
13997 Timer 2 (8052)
13998 \end_layout
13999
14000 \end_inset
14001 </cell>
14002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14003 \begin_inset Text
14004
14005 \begin_layout Standard
14006 0x002b
14007 \end_layout
14008
14009 \end_inset
14010 </cell>
14011 </row>
14012 <row topline="true">
14013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14014 \begin_inset Text
14015
14016 \begin_layout Standard
14017 ...
14018 \end_layout
14019
14020 \end_inset
14021 </cell>
14022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14023 \begin_inset Text
14024
14025 \begin_layout Standard
14026
14027 \end_layout
14028
14029 \end_inset
14030 </cell>
14031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14032 \begin_inset Text
14033
14034 \begin_layout Standard
14035 ...
14036 \end_layout
14037
14038 \end_inset
14039 </cell>
14040 </row>
14041 <row topline="true" bottomline="true">
14042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14043 \begin_inset Text
14044
14045 \begin_layout Standard
14046 n
14047 \end_layout
14048
14049 \end_inset
14050 </cell>
14051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14052 \begin_inset Text
14053
14054 \begin_layout Standard
14055
14056 \end_layout
14057
14058 \end_inset
14059 </cell>
14060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14061 \begin_inset Text
14062
14063 \begin_layout Standard
14064 0x0003 + 8*n
14065 \end_layout
14066
14067 \end_inset
14068 </cell>
14069 </row>
14070 </lyxtabular>
14071
14072 \end_inset
14073
14074
14075 \newline
14076
14077 \end_layout
14078
14079 \begin_layout Standard
14080 If the interrupt service routine is defined without 
14081 \emph on
14082 using
14083 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14084
14085 \end_inset
14086
14087
14088 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14089
14090 \end_inset
14091
14092
14093 \emph default
14094  a register bank or with register bank 0 (
14095 \emph on
14096 using
14097 \emph default
14098  0), the compiler will save the registers used by itself on the stack upon
14099  entry and restore them at exit, however if such an interrupt service routine
14100  calls another function then the entire register bank will be saved on the
14101  stack.
14102  This scheme may be advantageous for small interrupt service routines which
14103  have low register usage.
14104 \end_layout
14105
14106 \begin_layout Standard
14107 If the interrupt service routine is defined to be using a specific register
14108  bank then only 
14109 \emph on
14110 a, b, dptr
14111 \emph default
14112  & psw are saved and restored, if such an interrupt service routine calls
14113  another function (using another register bank) then the entire register
14114  bank of the called function will be saved on the stack
14115 \begin_inset LatexCommand \index{stack}
14116
14117 \end_inset
14118
14119 .
14120  This scheme is recommended for larger interrupt service routines.
14121 \begin_inset VSpace bigskip
14122 \end_inset
14123
14124
14125 \end_layout
14126
14127 \begin_layout Subsection
14128 HC08
14129 \begin_inset LatexCommand \index{HC08}
14130
14131 \end_inset
14132
14133  Interrupt Service Routines
14134 \end_layout
14135
14136 \begin_layout Standard
14137 Since the number of interrupts
14138 \begin_inset LatexCommand \index{HC08!interrupt}
14139
14140 \end_inset
14141
14142  available is chip specific and the interrupt vector table always ends at
14143  the last byte of memory, the interrupt numbers corresponds to the interrupt
14144  vectors in reverse order of address.
14145  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14146  2 will use the interrupt vector at 0xfffa, and so on.
14147  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14148  this way; instead see section 
14149 \begin_inset LatexCommand \ref{sub:Startup-Code}
14150
14151 \end_inset
14152
14153  for details on customizing startup.
14154 \begin_inset VSpace bigskip
14155 \end_inset
14156
14157
14158 \end_layout
14159
14160 \begin_layout Subsection
14161 Z80 Interrupt Service Routines
14162 \end_layout
14163
14164 \begin_layout Standard
14165 The Z80
14166 \begin_inset LatexCommand \index{Z80}
14167
14168 \end_inset
14169
14170  uses several different methods for determining the correct interrupt
14171 \begin_inset LatexCommand \index{Z80!interrupt}
14172
14173 \end_inset
14174
14175  vector depending on the hardware implementation.
14176  Therefore, SDCC ignores the optional interrupt number and does not attempt
14177  to generate an interrupt vector table.
14178 \end_layout
14179
14180 \begin_layout Standard
14181 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14182  instruction to return from the interrupt.
14183  To write an interrupt handler for the non-maskable interrupt, which needs
14184  a RETN instruction instead, add the 
14185 \emph on
14186 critical
14187 \emph default
14188  keyword:
14189 \end_layout
14190
14191 \begin_layout Verse
14192
14193 \family typewriter
14194 void nmi_isr (void) critical interrupt
14195 \newline
14196
14197 \newline
14198 \InsetSpace ~
14199 \InsetSpace ~
14200 \InsetSpace ~
14201 \InsetSpace ~
14202 ...
14203  
14204 \newline
14205 }
14206 \end_layout
14207
14208 \begin_layout Standard
14209 However if you need to create a non-interruptable interrupt service routine
14210  you would also require the 
14211 \emph on
14212 critical
14213 \emph default
14214  keyword.
14215  To distinguish between this and an nmi_isr you must provide an interrupt
14216  number.
14217 \begin_inset VSpace bigskip
14218 \end_inset
14219
14220
14221 \end_layout
14222
14223 \begin_layout Section
14224 Enabling and Disabling Interrupts
14225 \end_layout
14226
14227 \begin_layout Subsection
14228 Critical Functions and Critical Statements
14229 \end_layout
14230
14231 \begin_layout Standard
14232 A special keyword may be associated with a block or a function declaring
14233  it as 
14234 \emph on
14235 critical
14236 \emph default
14237 .
14238  SDCC will generate code to disable all interrupts
14239 \begin_inset LatexCommand \index{interrupt}
14240
14241 \end_inset
14242
14243  upon entry to a critical function and restore the interrupt enable to the
14244  previous state before returning.
14245  Nesting critical functions will need one additional byte on the stack
14246 \begin_inset LatexCommand \index{stack}
14247
14248 \end_inset
14249
14250  for each call.
14251 \end_layout
14252
14253 \begin_layout Verse
14254
14255 \family typewriter
14256 int foo () __critical
14257 \begin_inset LatexCommand \index{critical}
14258
14259 \end_inset
14260
14261
14262 \begin_inset LatexCommand \index{\_\_critical}
14263
14264 \end_inset
14265
14266  
14267 \newline
14268
14269 \newline
14270 \InsetSpace ~
14271 \InsetSpace ~
14272 \InsetSpace ~
14273 \InsetSpace ~
14274 ...
14275  
14276 \newline
14277 \InsetSpace ~
14278 \InsetSpace ~
14279 \InsetSpace ~
14280 \InsetSpace ~
14281 ...
14282  
14283 \newline
14284 }
14285 \end_layout
14286
14287 \begin_layout Standard
14288 The critical attribute maybe used with other attributes like 
14289 \emph on
14290 reentrant.
14291 \emph default
14292
14293 \newline
14294 The keyword 
14295 \emph on
14296 critical
14297 \emph default
14298  may also be used to disable interrupts more locally:
14299 \end_layout
14300
14301 \begin_layout Verse
14302
14303 \family typewriter
14304 __critical{ i++; }
14305 \end_layout
14306
14307 \begin_layout Standard
14308 More than one statement could have been included in the block.
14309 \end_layout
14310
14311 \begin_layout Subsection
14312 Enabling and Disabling Interrupts directly
14313 \end_layout
14314
14315 \begin_layout Standard
14316 Interrupts
14317 \begin_inset LatexCommand \index{interrupt}
14318
14319 \end_inset
14320
14321  can also be disabled and enabled directly (8051):
14322 \end_layout
14323
14324 \begin_layout Verse
14325
14326 \family typewriter
14327 EA = 0;\InsetSpace ~
14328 \InsetSpace ~
14329 \InsetSpace ~
14330 \InsetSpace ~
14331 \InsetSpace ~
14332 \InsetSpace ~
14333 \InsetSpace ~
14334 \InsetSpace ~
14335 \InsetSpace ~
14336 \InsetSpace ~
14337 \InsetSpace ~
14338 \InsetSpace ~
14339 or:\InsetSpace ~
14340 \InsetSpace ~
14341 \InsetSpace ~
14342 \InsetSpace ~
14343 \InsetSpace ~
14344 \InsetSpace ~
14345 \InsetSpace ~
14346 \InsetSpace ~
14347 \InsetSpace ~
14348 \InsetSpace ~
14349 \InsetSpace ~
14350 EA_SAVE = EA;
14351 \end_layout
14352
14353 \begin_layout Verse
14354
14355 \family typewriter
14356 ...\InsetSpace ~
14357 \InsetSpace ~
14358 \InsetSpace ~
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 EA = 0;
14387 \end_layout
14388
14389 \begin_layout Verse
14390
14391 \family typewriter
14392 EA = 1;\InsetSpace ~
14393 \InsetSpace ~
14394 \InsetSpace ~
14395 \InsetSpace ~
14396 \InsetSpace ~
14397 \InsetSpace ~
14398 \InsetSpace ~
14399 \InsetSpace ~
14400 \InsetSpace ~
14401 \InsetSpace ~
14402 \InsetSpace ~
14403 \InsetSpace ~
14404 \InsetSpace ~
14405 \InsetSpace ~
14406 \InsetSpace ~
14407 \InsetSpace ~
14408 \InsetSpace ~
14409 \InsetSpace ~
14410 \InsetSpace ~
14411 \InsetSpace ~
14412 \InsetSpace ~
14413 \InsetSpace ~
14414 \InsetSpace ~
14415 \InsetSpace ~
14416 \InsetSpace ~
14417 \InsetSpace ~
14418 ...
14419 \end_layout
14420
14421 \begin_layout Verse
14422
14423 \family typewriter
14424 \InsetSpace ~
14425 \InsetSpace ~
14426 \InsetSpace ~
14427 \InsetSpace ~
14428 \InsetSpace ~
14429 \InsetSpace ~
14430 \InsetSpace ~
14431 \InsetSpace ~
14432 \InsetSpace ~
14433 \InsetSpace ~
14434 \InsetSpace ~
14435 \InsetSpace ~
14436 \InsetSpace ~
14437 \InsetSpace ~
14438 \InsetSpace ~
14439 \InsetSpace ~
14440 \InsetSpace ~
14441 \InsetSpace ~
14442 \InsetSpace ~
14443 \InsetSpace ~
14444 \InsetSpace ~
14445 \InsetSpace ~
14446 \InsetSpace ~
14447 \InsetSpace ~
14448 \InsetSpace ~
14449 \InsetSpace ~
14450 \InsetSpace ~
14451 \InsetSpace ~
14452 \InsetSpace ~
14453 \InsetSpace ~
14454 \InsetSpace ~
14455 \InsetSpace ~
14456 \InsetSpace ~
14457 EA = EA_SAVE;
14458 \end_layout
14459
14460 \begin_layout Standard
14461 On other architectures which have seperate opcodes for enabling and disabling
14462  interrupts you might want to make use of defines with inline assembly
14463 \begin_inset LatexCommand \index{Assembler routines}
14464
14465 \end_inset
14466
14467  (HC08
14468 \begin_inset LatexCommand \index{HC08!interrupt}
14469
14470 \end_inset
14471
14472 ):
14473 \end_layout
14474
14475 \begin_layout Verse
14476
14477 \family typewriter
14478 #define CLI _asm
14479 \begin_inset LatexCommand \index{\_asm}
14480
14481 \end_inset
14482
14483 \InsetSpace ~
14484 \InsetSpace ~
14485 cli\InsetSpace ~
14486 \InsetSpace ~
14487 _endasm
14488 \begin_inset LatexCommand \index{\_endasm}
14489
14490 \end_inset
14491
14492
14493 \end_layout
14494
14495 \begin_layout Verse
14496
14497 \family typewriter
14498 #define SEI _asm\InsetSpace ~
14499 \InsetSpace ~
14500 sei\InsetSpace ~
14501 \InsetSpace ~
14502 _endasm; 
14503 \end_layout
14504
14505 \begin_layout Verse
14506
14507 \family typewriter
14508 ...
14509 \end_layout
14510
14511 \begin_layout Standard
14512 Note: it is sometimes sufficient to disable only a specific interrupt source
14513  like f.e.
14514  a timer or serial interrupt by manipulating an 
14515 \emph on
14516 interrupt mask
14517 \begin_inset LatexCommand \index{interrupt mask}
14518
14519 \end_inset
14520
14521
14522 \emph default
14523  register.
14524  
14525 \end_layout
14526
14527 \begin_layout Standard
14528 Usually the time during which interrupts are disabled should be kept as
14529  short as possible.
14530  This minimizes both 
14531 \emph on
14532 interrupt latency
14533 \emph default
14534
14535 \begin_inset LatexCommand \index{interrupt latency}
14536
14537 \end_inset
14538
14539  (the time between the occurrence of the interrupt and the execution of
14540  the first code in the interrupt routine) and 
14541 \emph on
14542 interrupt jitter
14543 \emph default
14544
14545 \begin_inset LatexCommand \index{interrupt jitter}
14546
14547 \end_inset
14548
14549  (the difference between the shortest and the longest interrupt latency).
14550  These really are something different, f.e.
14551  a serial interrupt has to be served before its buffer overruns so it cares
14552  for the maximum interrupt latency, whereas it does not care about jitter.
14553  On a loudspeaker driven via a digital to analog converter which is fed
14554  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14555  a much smaller jitter will be very audible.
14556 \end_layout
14557
14558 \begin_layout Standard
14559 You can reenable interrupts within an interrupt routine and on some architecture
14560 s you can make use of two (or more) levels of 
14561 \emph on
14562 interrupt priorities
14563 \emph default
14564
14565 \begin_inset LatexCommand \index{interrupt priority}
14566
14567 \end_inset
14568
14569 .
14570  On some architectures which don't support interrupt priorities these can
14571  be implemented by manipulating the interrupt mask and reenabling interrupts
14572  within the interrupt routine.
14573  Check there is sufficient space on the stack
14574 \begin_inset LatexCommand \index{stack}
14575
14576 \end_inset
14577
14578  and don't add complexity unless you have to.
14579  
14580 \end_layout
14581
14582 \begin_layout Subsection
14583 Semaphore
14584 \begin_inset LatexCommand \index{semaphore}
14585
14586 \end_inset
14587
14588  locking (mcs51/ds390)
14589 \end_layout
14590
14591 \begin_layout Standard
14592 Some architectures (mcs51/ds390) have an atomic
14593 \begin_inset LatexCommand \index{atomic}
14594
14595 \end_inset
14596
14597  bit test and
14598 \emph on
14599  
14600 \emph default
14601 clear
14602 \emph on
14603  
14604 \emph default
14605 instruction.
14606  These type of instructions are typically used in preemptive multitasking
14607  systems, where a routine f.e.
14608  claims the use of a data structure ('acquires a lock
14609 \begin_inset LatexCommand \index{lock}
14610
14611 \end_inset
14612
14613  on it'), makes some modifications and then releases the lock when the data
14614  structure is consistent again.
14615  The instruction may also be used if interrupt and non-interrupt code have
14616  to compete for a resource.
14617  With the atomic bit test and clear instruction interrupts
14618 \begin_inset LatexCommand \index{interrupt}
14619
14620 \end_inset
14621
14622  don't have to be disabled for the locking operation.
14623  
14624 \end_layout
14625
14626 \begin_layout Standard
14627 SDCC generates this instruction if the source follows this pattern:
14628 \end_layout
14629
14630 \begin_layout Verse
14631
14632 \family typewriter
14633 volatile
14634 \begin_inset LatexCommand \index{volatile}
14635
14636 \end_inset
14637
14638  bit resource_is_free; 
14639 \newline
14640
14641 \newline
14642 if (resource_is_free) 
14643 \newline
14644 \InsetSpace ~
14645 \InsetSpace ~
14646
14647 \newline
14648 \InsetSpace ~
14649 \InsetSpace ~
14650 \InsetSpace ~
14651 \InsetSpace ~
14652 resource_is_free=0; 
14653 \newline
14654 \InsetSpace ~
14655 \InsetSpace ~
14656 \InsetSpace ~
14657 \InsetSpace ~
14658 ...
14659  
14660 \newline
14661 \InsetSpace ~
14662 \InsetSpace ~
14663 \InsetSpace ~
14664 \InsetSpace ~
14665 resource_is_free=1;
14666 \newline
14667 \InsetSpace ~
14668 \InsetSpace ~
14669
14670 \end_layout
14671
14672 \begin_layout Standard
14673 Note, mcs51 and ds390 support only an atomic
14674 \begin_inset LatexCommand \index{atomic}
14675
14676 \end_inset
14677
14678  bit test and 
14679 \emph on
14680 clear
14681 \emph default
14682  instruction (as opposed to atomic bit test and 
14683 \emph on
14684 set).
14685 \end_layout
14686
14687 \begin_layout Section
14688 Functions using private register banks
14689 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14690
14691 \end_inset
14692
14693  (mcs51/ds390)
14694 \end_layout
14695
14696 \begin_layout Standard
14697 Some architectures have support for quickly changing register sets.
14698  SDCC supports this feature with the 
14699 \emph on
14700 using
14701 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14702
14703 \end_inset
14704
14705
14706 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14707
14708 \end_inset
14709
14710
14711 \emph default
14712  attribute (which tells the compiler to use a register bank
14713 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14714
14715 \end_inset
14716
14717  other than the default bank zero).
14718  It should only be applied to 
14719 \emph on
14720 interrupt
14721 \begin_inset LatexCommand \index{interrupt}
14722
14723 \end_inset
14724
14725
14726 \emph default
14727  functions (see footnote below).
14728  This will in most circumstances make the generated ISR code more efficient
14729  since it will not have to save registers on the stack.
14730 \end_layout
14731
14732 \begin_layout Standard
14733 The 
14734 \emph on
14735 using
14736 \emph default
14737  attribute will have no effect on the generated code for a 
14738 \emph on
14739 non-interrupt
14740 \emph default
14741  function (but may occasionally be useful anyway
14742 \begin_inset Foot
14743 status open
14744
14745 \begin_layout Standard
14746 possible exception: if a function is called ONLY from 'interrupt' functions
14747  using a particular bank, it can be declared with the same 'using' attribute
14748  as the calling 'interrupt' functions.
14749  For instance, if you have several ISRs using bank one, and all of them
14750  call memcpy(), it might make sense to create a specialized version of memcpy()
14751  'using 1', since this would prevent the ISR from having to save bank zero
14752  to the stack on entry and switch to bank zero before calling the function
14753 \end_layout
14754
14755 \end_inset
14756
14757 ).
14758 \newline
14759
14760 \emph on
14761 (pending: Note, nowadays the 
14762 \emph default
14763 using
14764 \emph on
14765  attribute has an effect on
14766 \emph default
14767  
14768 \emph on
14769 the generated code for a 
14770 \emph default
14771 non-interrupt
14772 \emph on
14773  function
14774 \emph default
14775 .
14776 \emph on
14777 )
14778 \end_layout
14779
14780 \begin_layout Standard
14781 An 
14782 \emph on
14783 interrupt
14784 \emph default
14785  function using a non-zero bank will assume that it can trash that register
14786  bank, and will not save it.
14787  Since high-priority interrupts
14788 \begin_inset LatexCommand \index{interrupts}
14789
14790 \end_inset
14791
14792
14793 \begin_inset LatexCommand \index{interrupt priority}
14794
14795 \end_inset
14796
14797  can interrupt low-priority ones on the 8051 and friends, this means that
14798  if a high-priority ISR 
14799 \emph on
14800 using
14801 \emph default
14802  a particular bank occurs while processing a low-priority ISR 
14803 \emph on
14804 using
14805 \emph default
14806  the same bank, terrible and bad things can happen.
14807  To prevent this, no single register bank should be 
14808 \emph on
14809 used
14810 \emph default
14811  by both a high priority and a low priority ISR.
14812  This is probably most easily done by having all high priority ISRs use
14813  one bank and all low priority ISRs use another.
14814  If you have an ISR which can change priority at runtime, you're on your
14815  own: I suggest using the default bank zero and taking the small performance
14816  hit.
14817 \end_layout
14818
14819 \begin_layout Standard
14820 It is most efficient if your ISR calls no other functions.
14821  If your ISR must call other functions, it is most efficient if those functions
14822  use the same bank as the ISR (see note 1 below); the next best is if the
14823  called functions use bank zero.
14824  It is very inefficient to call a function using a different, non-zero bank
14825  from an ISR.
14826  
14827 \begin_inset VSpace bigskip
14828 \end_inset
14829
14830
14831 \end_layout
14832
14833 \begin_layout Section
14834 Startup Code
14835 \begin_inset LatexCommand \label{sub:Startup-Code}
14836
14837 \end_inset
14838
14839
14840 \begin_inset LatexCommand \index{Startup code}
14841
14842 \end_inset
14843
14844
14845 \end_layout
14846
14847 \begin_layout Subsection
14848 MCS51/DS390 Startup Code
14849 \end_layout
14850
14851 \begin_layout Standard
14852 The compiler triggers the linker to link certain initialization modules
14853  from the runtime library
14854 \begin_inset LatexCommand \index{Runtime library}
14855
14856 \end_inset
14857
14858  called crt<something>.
14859  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14860  GSINIT5) is not linked unless the --xstack option is used.
14861  These modules are highly entangled by the use of special segments/areas,
14862  but a common layout is shown below:
14863 \end_layout
14864
14865 \begin_layout Verse
14866
14867 \family typewriter
14868 \series bold
14869 \size footnotesize
14870 (main.asm)
14871 \end_layout
14872
14873 \begin_layout Verse
14874
14875 \family typewriter
14876 \size footnotesize
14877 \InsetSpace ~
14878 \InsetSpace ~
14879 \InsetSpace ~
14880 \InsetSpace ~
14881 \InsetSpace ~
14882 \InsetSpace ~
14883 \InsetSpace ~
14884 \InsetSpace ~
14885 .area HOME (CODE)
14886 \newline
14887 __interrupt_vect:
14888 \newline
14889 \InsetSpace ~
14890 \InsetSpace ~
14891 \InsetSpace ~
14892 \InsetSpace ~
14893 \InsetSpace ~
14894 \InsetSpace ~
14895 \InsetSpace ~
14896 \InsetSpace ~
14897 ljmp __sdcc_gsinit_startup
14898 \end_layout
14899
14900 \begin_layout Verse
14901
14902 \family typewriter
14903 \series bold
14904 \size footnotesize
14905 (crtstart.asm)
14906 \end_layout
14907
14908 \begin_layout Verse
14909
14910 \family typewriter
14911 \size footnotesize
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 \InsetSpace ~
14916 \InsetSpace ~
14917 \InsetSpace ~
14918 \InsetSpace ~
14919 \InsetSpace ~
14920 .area GSINIT0 (CODE)
14921 \newline
14922 __sdcc_gsinit_startup::
14923 \newline
14924 \InsetSpace ~
14925 \InsetSpace ~
14926 \InsetSpace ~
14927 \InsetSpace ~
14928 \InsetSpace ~
14929 \InsetSpace ~
14930 \InsetSpace ~
14931 \InsetSpace ~
14932 mov sp,#__start__stack - 1
14933 \end_layout
14934
14935 \begin_layout Verse
14936
14937 \family typewriter
14938 \series bold
14939 \size footnotesize
14940 (crtxstack.asm)
14941 \end_layout
14942
14943 \begin_layout Verse
14944
14945 \family typewriter
14946 \size footnotesize
14947 \InsetSpace ~
14948 \InsetSpace ~
14949 \InsetSpace ~
14950 \InsetSpace ~
14951 \InsetSpace ~
14952 \InsetSpace ~
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 .area GSINIT1 (CODE)
14956 \newline
14957 __sdcc_init_xstack::
14958 \newline
14959 ; Need to initialize in GSINIT1 in
14960  case the user's __sdcc_external_startup uses the xstack.
14961 \newline
14962 \InsetSpace ~
14963 \InsetSpace ~
14964 \InsetSpace ~
14965 \InsetSpace ~
14966 \InsetSpace ~
14967 \InsetSpace ~
14968 \InsetSpace ~
14969 \InsetSpace ~
14970 mov __XPAGE,#(__start__x
14971 stack >> 8)
14972 \newline
14973 \InsetSpace ~
14974 \InsetSpace ~
14975 \InsetSpace ~
14976 \InsetSpace ~
14977 \InsetSpace ~
14978 \InsetSpace ~
14979 \InsetSpace ~
14980 \InsetSpace ~
14981 mov _spx,#__start__xstack
14982 \end_layout
14983
14984 \begin_layout Verse
14985
14986 \family typewriter
14987 \series bold
14988 \size footnotesize
14989 (crtstart.asm)
14990 \end_layout
14991
14992 \begin_layout Verse
14993
14994 \family typewriter
14995 \size footnotesize
14996 \InsetSpace ~
14997 \InsetSpace ~
14998 \InsetSpace ~
14999 \InsetSpace ~
15000 \InsetSpace ~
15001 \InsetSpace ~
15002 \InsetSpace ~
15003 \InsetSpace ~
15004 .area GSINIT2 (CODE)
15005 \newline
15006 \InsetSpace ~
15007 \InsetSpace ~
15008 \InsetSpace ~
15009 \InsetSpace ~
15010 \InsetSpace ~
15011 \InsetSpace ~
15012 \InsetSpace ~
15013 \InsetSpace ~
15014 lcall __sdcc_external_startup
15015 \newline
15016 \InsetSpace ~
15017 \InsetSpace ~
15018 \InsetSpace ~
15019 \InsetSpace ~
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 mov a,dpl
15025 \newline
15026 \InsetSpace ~
15027 \InsetSpace ~
15028 \InsetSpace ~
15029 \InsetSpace ~
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 \InsetSpace ~
15034 jz __sdcc_init_data
15035 \newline
15036 \InsetSpace ~
15037 \InsetSpace ~
15038 \InsetSpace ~
15039 \InsetSpace ~
15040 \InsetSpace ~
15041 \InsetSpace ~
15042 \InsetSpace ~
15043 \InsetSpace ~
15044 ljmp
15045  __sdcc_program_startup
15046 \newline
15047 __sdcc_init_data:
15048 \end_layout
15049
15050 \begin_layout Verse
15051
15052 \family typewriter
15053 \series bold
15054 \size footnotesize
15055 (crtxinit.asm)
15056 \end_layout
15057
15058 \begin_layout Verse
15059
15060 \family typewriter
15061 \size footnotesize
15062 \InsetSpace ~
15063 \InsetSpace ~
15064 \InsetSpace ~
15065 \InsetSpace ~
15066 \InsetSpace ~
15067 \InsetSpace ~
15068 \InsetSpace ~
15069 \InsetSpace ~
15070 .area GSINIT3 (CODE)
15071 \newline
15072 __mcs51_genXINIT::
15073 \newline
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 \InsetSpace ~
15079 \InsetSpace ~
15080 \InsetSpace ~
15081 \InsetSpace ~
15082 mov r1,#l_XINIT
15083 \newline
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 \InsetSpace ~
15091 \InsetSpace ~
15092 mov a,r1
15093 \newline
15094 \InsetSpace ~
15095 \InsetSpace ~
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 orl a,#(l_XINIT
15103  >> 8)
15104 \newline
15105 \InsetSpace ~
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
15109 \InsetSpace ~
15110 \InsetSpace ~
15111 \InsetSpace ~
15112 \InsetSpace ~
15113 jz 00003$
15114 \newline
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 \InsetSpace ~
15123 mov r2,#((l_XINIT+255) >> 8)
15124 \newline
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 mov dptr,#s_XINIT
15134 \newline
15135 \InsetSpace ~
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 mov r0,#s_XISEG
15144 \newline
15145 \InsetSpace ~
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 mov
15154  __XPAGE,#(s_XISEG >> 8)
15155 \newline
15156 00001$:\InsetSpace ~
15157 clr a
15158 \newline
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 movc a,@a+dptr
15168 \newline
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
15177 movx @r0,a
15178 \newline
15179 \InsetSpace ~
15180 \InsetSpace ~
15181 \InsetSpace ~
15182 \InsetSpace ~
15183 \InsetSpace ~
15184 \InsetSpace ~
15185 \InsetSpace ~
15186 \InsetSpace ~
15187 inc dptr
15188 \newline
15189 \InsetSpace ~
15190 \InsetSpace ~
15191 \InsetSpace ~
15192 \InsetSpace ~
15193 \InsetSpace ~
15194 \InsetSpace ~
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 inc
15198  r0
15199 \newline
15200 \InsetSpace ~
15201 \InsetSpace ~
15202 \InsetSpace ~
15203 \InsetSpace ~
15204 \InsetSpace ~
15205 \InsetSpace ~
15206 \InsetSpace ~
15207 \InsetSpace ~
15208 cjne r0,#0,00002$
15209 \newline
15210 \InsetSpace ~
15211 \InsetSpace ~
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 \InsetSpace ~
15215 \InsetSpace ~
15216 \InsetSpace ~
15217 \InsetSpace ~
15218 inc __XPAGE
15219 \newline
15220 00002$:\InsetSpace ~
15221 djnz r1,00001$
15222 \newline
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 \InsetSpace ~
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 \InsetSpace ~
15229 \InsetSpace ~
15230 \InsetSpace ~
15231 djnz r2,00001$
15232 \newline
15233 \InsetSpace ~
15234 \InsetSpace ~
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 \InsetSpace ~
15239 \InsetSpace ~
15240 \InsetSpace ~
15241 mov __XPAGE,#0
15242 xFF
15243 \newline
15244 00003$:
15245 \end_layout
15246
15247 \begin_layout Verse
15248
15249 \family typewriter
15250 \series bold
15251 \size footnotesize
15252 (crtclear.asm)
15253 \end_layout
15254
15255 \begin_layout Verse
15256
15257 \family typewriter
15258 \size footnotesize
15259 \InsetSpace ~
15260 \InsetSpace ~
15261 \InsetSpace ~
15262 \InsetSpace ~
15263 \InsetSpace ~
15264 \InsetSpace ~
15265 \InsetSpace ~
15266 \InsetSpace ~
15267 .area GSINIT4 (CODE)
15268 \newline
15269 __mcs51_genRAMCLEAR::
15270 \newline
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 \InsetSpace ~
15274 \InsetSpace ~
15275 \InsetSpace ~
15276 \InsetSpace ~
15277 \InsetSpace ~
15278 \InsetSpace ~
15279 clr a
15280 \newline
15281 \InsetSpace ~
15282 \InsetSpace ~
15283 \InsetSpace ~
15284 \InsetSpace ~
15285 \InsetSpace ~
15286 \InsetSpace ~
15287 \InsetSpace ~
15288 \InsetSpace ~
15289 mov r0,#(l_IRAM-1)
15290 \newline
15291 00004$:\InsetSpace ~
15292 mov
15293  @r0,a
15294 \newline
15295 \InsetSpace ~
15296 \InsetSpace ~
15297 \InsetSpace ~
15298 \InsetSpace ~
15299 \InsetSpace ~
15300 \InsetSpace ~
15301 \InsetSpace ~
15302 \InsetSpace ~
15303 djnz r0,00004$
15304 \newline
15305 ; _mcs51_genRAMCLEAR() end
15306 \end_layout
15307
15308 \begin_layout Verse
15309
15310 \family typewriter
15311 \series bold
15312 \size footnotesize
15313 (crtxclear.asm)
15314 \end_layout
15315
15316 \begin_layout Verse
15317
15318 \family typewriter
15319 \size footnotesize
15320 \InsetSpace ~
15321 \InsetSpace ~
15322 \InsetSpace ~
15323 \InsetSpace ~
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 \InsetSpace ~
15327 \InsetSpace ~
15328 .area GSINIT4 (CODE)
15329 \newline
15330 __mcs51_genXRAMCLEAR::
15331 \newline
15332 \InsetSpace ~
15333 \InsetSpace ~
15334 \InsetSpace ~
15335 \InsetSpace ~
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 \InsetSpace ~
15340 mov r0,#l_PSEG
15341 \newline
15342 \InsetSpace ~
15343 \InsetSpace ~
15344 \InsetSpace ~
15345 \InsetSpace ~
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 \InsetSpace ~
15350 mov a,r0
15351 \newline
15352 \InsetSpace ~
15353 \InsetSpace ~
15354 \InsetSpace ~
15355 \InsetSpace ~
15356 \InsetSpace ~
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 \InsetSpace ~
15360 jz 00006$
15361 \newline
15362 \InsetSpace ~
15363 \InsetSpace ~
15364 \InsetSpace ~
15365 \InsetSpace ~
15366 \InsetSpace ~
15367 \InsetSpace ~
15368 \InsetSpace ~
15369 \InsetSpace ~
15370 mov
15371  r1,#s_PSEG
15372 \newline
15373 \InsetSpace ~
15374 \InsetSpace ~
15375 \InsetSpace ~
15376 \InsetSpace ~
15377 \InsetSpace ~
15378 \InsetSpace ~
15379 \InsetSpace ~
15380 \InsetSpace ~
15381 mov __XPAGE,#(s_PSEG >> 8)
15382 \newline
15383 \InsetSpace ~
15384 \InsetSpace ~
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 \InsetSpace ~
15389 \InsetSpace ~
15390 \InsetSpace ~
15391 clr a
15392 \newline
15393 00005$:\InsetSpace ~
15394 movx @r1,a
15395 \newline
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 \InsetSpace ~
15402 \InsetSpace ~
15403 \InsetSpace ~
15404 inc r1
15405 \newline
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 \InsetSpace ~
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 \InsetSpace ~
15412 \InsetSpace ~
15413 \InsetSpace ~
15414 djnz r0,00005$
15415 \newline
15416 0
15417 0006$:
15418 \newline
15419 \InsetSpace ~
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 \InsetSpace ~
15424 \InsetSpace ~
15425 \InsetSpace ~
15426 \InsetSpace ~
15427 mov r0,#l_XSEG
15428 \newline
15429 \InsetSpace ~
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 \InsetSpace ~
15434 \InsetSpace ~
15435 \InsetSpace ~
15436 \InsetSpace ~
15437 mov a,r0
15438 \newline
15439 \InsetSpace ~
15440 \InsetSpace ~
15441 \InsetSpace ~
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 \InsetSpace ~
15445 \InsetSpace ~
15446 \InsetSpace ~
15447 orl a,#(l_XSEG >> 8)
15448 \newline
15449 \InsetSpace ~
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 \InsetSpace ~
15454 \InsetSpace ~
15455 \InsetSpace ~
15456 \InsetSpace ~
15457 jz 00008$
15458 \newline
15459 \InsetSpace ~
15460 \InsetSpace ~
15461 \InsetSpace ~
15462 \InsetSpace ~
15463 \InsetSpace ~
15464 \InsetSpace ~
15465 \InsetSpace ~
15466 \InsetSpace ~
15467 mov r1,#((l_XSEG
15468  + 255) >> 8)
15469 \newline
15470 \InsetSpace ~
15471 \InsetSpace ~
15472 \InsetSpace ~
15473 \InsetSpace ~
15474 \InsetSpace ~
15475 \InsetSpace ~
15476 \InsetSpace ~
15477 \InsetSpace ~
15478 mov dptr,#s_XSEG
15479 \newline
15480 \InsetSpace ~
15481 \InsetSpace ~
15482 \InsetSpace ~
15483 \InsetSpace ~
15484 \InsetSpace ~
15485 \InsetSpace ~
15486 \InsetSpace ~
15487 \InsetSpace ~
15488 clr a
15489 \newline
15490 00007$:\InsetSpace ~
15491 movx @dptr,a
15492 \newline
15493 \InsetSpace ~
15494 \InsetSpace ~
15495 \InsetSpace ~
15496 \InsetSpace ~
15497 \InsetSpace ~
15498 \InsetSpace ~
15499 \InsetSpace ~
15500 \InsetSpace ~
15501 inc dptr
15502 \newline
15503 \InsetSpace ~
15504 \InsetSpace ~
15505 \InsetSpace ~
15506 \InsetSpace ~
15507 \InsetSpace ~
15508 \InsetSpace ~
15509 \InsetSpace ~
15510 \InsetSpace ~
15511 djnz r0,00007$
15512 \newline
15513 \InsetSpace ~
15514 \InsetSpace ~
15515 \InsetSpace ~
15516 \InsetSpace ~
15517 \InsetSpace ~
15518 \InsetSpace ~
15519 \InsetSpace ~
15520 \InsetSpace ~
15521 djnz
15522  r1,00007$
15523 \newline
15524 00008$:
15525 \end_layout
15526
15527 \begin_layout Verse
15528
15529 \family typewriter
15530 \series bold
15531 \size footnotesize
15532 (crtxstack.asm)
15533 \end_layout
15534
15535 \begin_layout Verse
15536
15537 \family typewriter
15538 \size footnotesize
15539 \InsetSpace ~
15540 \InsetSpace ~
15541 \InsetSpace ~
15542 \InsetSpace ~
15543 \InsetSpace ~
15544 \InsetSpace ~
15545 \InsetSpace ~
15546 \InsetSpace ~
15547 .area GSINIT5 (CODE)
15548 \newline
15549 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15550  modifies __XPAGE
15551 \newline
15552 ; and __mcs51_genRAMCLEAR modifies _spx.
15553 \newline
15554 \InsetSpace ~
15555 \InsetSpace ~
15556 \InsetSpace ~
15557 \InsetSpace ~
15558 \InsetSpace ~
15559 \InsetSpace ~
15560 \InsetSpace ~
15561 \InsetSpace ~
15562 mov __XPAGE,#(__start__x
15563 stack >> 8)
15564 \newline
15565 \InsetSpace ~
15566 \InsetSpace ~
15567 \InsetSpace ~
15568 \InsetSpace ~
15569 \InsetSpace ~
15570 \InsetSpace ~
15571 \InsetSpace ~
15572 \InsetSpace ~
15573 mov _spx,#__start__xstack
15574 \end_layout
15575
15576 \begin_layout Verse
15577
15578 \family typewriter
15579 \series bold
15580 \size footnotesize
15581 (application modules)
15582 \end_layout
15583
15584 \begin_layout Verse
15585
15586 \family typewriter
15587 \size footnotesize
15588 \InsetSpace ~
15589 \InsetSpace ~
15590 \InsetSpace ~
15591 \InsetSpace ~
15592 \InsetSpace ~
15593 \InsetSpace ~
15594 \InsetSpace ~
15595 \InsetSpace ~
15596 .area GSINIT (CODE)
15597 \end_layout
15598
15599 \begin_layout Verse
15600
15601 \family typewriter
15602 \series bold
15603 \size footnotesize
15604 (main.asm)
15605 \end_layout
15606
15607 \begin_layout Verse
15608
15609 \family typewriter
15610 \size footnotesize
15611 \InsetSpace ~
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 \InsetSpace ~
15618 \InsetSpace ~
15619 .area GSFINAL (CODE)
15620 \newline
15621 \InsetSpace ~
15622 \InsetSpace ~
15623 \InsetSpace ~
15624 \InsetSpace ~
15625 \InsetSpace ~
15626 \InsetSpace ~
15627 \InsetSpace ~
15628 \InsetSpace ~
15629 ljmp __sdcc_program_startup
15630 \newline
15631 ;---------------------------------
15632 -----------------------
15633 \newline
15634 ; Home
15635 \newline
15636 ;--------------------------------------------------
15637 ------
15638 \newline
15639 \InsetSpace ~
15640 \InsetSpace ~
15641 \InsetSpace ~
15642 \InsetSpace ~
15643 \InsetSpace ~
15644 \InsetSpace ~
15645 \InsetSpace ~
15646 \InsetSpace ~
15647 .area HOME (CODE)
15648 \newline
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 \InsetSpace ~
15654 \InsetSpace ~
15655 \InsetSpace ~
15656 \InsetSpace ~
15657 .area CSEG (CODE)
15658 \newline
15659 __sdcc_program_startup:
15660 \newline
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 \InsetSpace ~
15664 \InsetSpace ~
15665 \InsetSpace ~
15666 \InsetSpace ~
15667 \InsetSpace ~
15668 \InsetSpace ~
15669 lcall _main
15670 \newline
15671 ;
15672  return from main will lock up
15673 \newline
15674 \InsetSpace ~
15675 \InsetSpace ~
15676 \InsetSpace ~
15677 \InsetSpace ~
15678 \InsetSpace ~
15679 \InsetSpace ~
15680 \InsetSpace ~
15681 \InsetSpace ~
15682 sjmp .
15683 \end_layout
15684
15685 \begin_layout Standard
15686 One of these modules (crtstart.asm) contains a call to the C routine 
15687 \emph on
15688 _sdcc_external_startup()
15689 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15690
15691 \end_inset
15692
15693
15694 \series bold
15695 \emph default
15696  
15697 \series default
15698 at the start of the CODE area.
15699  This routine is also in the runtime library
15700 \begin_inset LatexCommand \index{Runtime library}
15701
15702 \end_inset
15703
15704  and returns 0 by default.
15705  If this routine returns a non-zero value, the static & global variable
15706  initialization will be skipped and the function main will be invoked.
15707  Otherwise static & global variables will be initialized before the function
15708  main is invoked.
15709  You could add an 
15710 \emph on
15711 _sdcc_external_startup()
15712 \emph default
15713  routine to your program to override the default if you need to setup hardware
15714  or perform some other critical operation prior to static & global variable
15715  initialization
15716 \begin_inset LatexCommand \index{Variable initialization}
15717
15718 \end_inset
15719
15720 .
15721  On some mcs51 variants xdata
15722 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15723
15724 \end_inset
15725
15726  memory has to be explicitly enabled before it can be accessed or if the
15727  watchdog
15728 \begin_inset LatexCommand \index{watchdog}
15729
15730 \end_inset
15731
15732  needs to be disabled, this is the place to do it.
15733  The startup code clears all internal data memory, 256 bytes by default,
15734  but from 0 to n-1 if 
15735 \emph on
15736 -
15737 \begin_inset ERT
15738 status collapsed
15739
15740 \begin_layout Standard
15741
15742
15743 \backslash
15744 /
15745 \end_layout
15746
15747 \end_inset
15748
15749 -iram-size
15750 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15751
15752 \end_inset
15753
15754 n
15755 \emph default
15756  is used.
15757  (recommended for Chipcon CC1010).
15758 \end_layout
15759
15760 \begin_layout Standard
15761 See also the compiler options 
15762 \emph on
15763 -
15764 \begin_inset ERT
15765 status collapsed
15766
15767 \begin_layout Standard
15768
15769
15770 \backslash
15771 /
15772 \end_layout
15773
15774 \end_inset
15775
15776 -no-xinit
15777 \emph default
15778 -
15779 \emph on
15780 opt
15781 \emph default
15782
15783 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15784
15785 \end_inset
15786
15787
15788 \emph on
15789 -
15790 \begin_inset ERT
15791 status collapsed
15792
15793 \begin_layout Standard
15794
15795
15796 \backslash
15797 /
15798 \end_layout
15799
15800 \end_inset
15801
15802 -main-return
15803 \emph default
15804
15805 \begin_inset LatexCommand \index{-\/-main-return}
15806
15807 \end_inset
15808
15809  and section 
15810 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15811
15812 \end_inset
15813
15814  about MCS51-variants.
15815 \begin_inset VSpace bigskip
15816 \end_inset
15817
15818
15819 \end_layout
15820
15821 \begin_layout Subsection
15822 HC08 Startup Code
15823 \end_layout
15824
15825 \begin_layout Standard
15826 The HC08
15827 \begin_inset LatexCommand \index{HC08}
15828
15829 \end_inset
15830
15831  startup code follows the same scheme as the MCS51 startup code.
15832 \begin_inset VSpace bigskip
15833 \end_inset
15834
15835
15836 \end_layout
15837
15838 \begin_layout Subsection
15839 Z80 Startup Code
15840 \end_layout
15841
15842 \begin_layout Standard
15843 On the Z80
15844 \begin_inset LatexCommand \index{Z80}
15845
15846 \end_inset
15847
15848  the startup code is inserted by linking with crt0.o which is generated from
15849  sdcc/device/lib/z80/crt0.s.
15850  If you need a different startup code you can use the compiler option 
15851 \emph on
15852 -
15853 \series bold
15854 \emph default
15855
15856 \begin_inset ERT
15857 status collapsed
15858
15859 \begin_layout Standard
15860
15861
15862 \backslash
15863 /
15864 \end_layout
15865
15866 \end_inset
15867
15868
15869 \series default
15870 \emph on
15871 -no-std-crt0
15872 \emph default
15873
15874 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15875
15876 \end_inset
15877
15878  and provide your own crt0.o.
15879  
15880 \begin_inset VSpace bigskip
15881 \end_inset
15882
15883
15884 \end_layout
15885
15886 \begin_layout Section
15887 Inline Assembler Code
15888 \begin_inset LatexCommand \index{Assembler routines}
15889
15890 \end_inset
15891
15892
15893 \end_layout
15894
15895 \begin_layout Subsection
15896 A Step by Step Introduction
15897 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15898
15899 \end_inset
15900
15901
15902 \end_layout
15903
15904 \begin_layout Standard
15905 Starting from a small snippet of c-code this example shows for the MCS51
15906  how to use inline assembly, access variables, a function parameter and
15907  an array in xdata memory.
15908  The example uses an MCS51 here but is easily adapted for other architectures.
15909  This is a buffer routine which should be optimized:
15910 \end_layout
15911
15912 \begin_layout Verse
15913
15914 \family typewriter
15915 \size footnotesize
15916 unsigned char __far
15917 \begin_inset LatexCommand \index{far (storage class)}
15918
15919 \end_inset
15920
15921
15922 \begin_inset LatexCommand \index{\_\_far (storage class)}
15923
15924 \end_inset
15925
15926  __at
15927 \begin_inset LatexCommand \index{at}
15928
15929 \end_inset
15930
15931
15932 \begin_inset LatexCommand \index{\_\_at}
15933
15934 \end_inset
15935
15936 (0x7f00) buf[0x100];
15937 \begin_inset LatexCommand \index{Aligned array}
15938
15939 \end_inset
15940
15941
15942 \newline
15943 unsigned char head, tail;\InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 \InsetSpace ~
15958 \InsetSpace ~
15959 \InsetSpace ~
15960 /* if interrupts
15961 \begin_inset LatexCommand \index{interrupt}
15962
15963 \end_inset
15964
15965  are involved see
15966 \newline
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 \InsetSpace ~
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 \InsetSpace ~
15979 \InsetSpace ~
15980 \InsetSpace ~
15981 \InsetSpace ~
15982 \InsetSpace ~
15983 \InsetSpace ~
15984 \InsetSpace ~
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 \InsetSpace ~
15989 \InsetSpace ~
15990 \InsetSpace ~
15991 \InsetSpace ~
15992 \InsetSpace ~
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 section 
16013 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16014
16015 \end_inset
16016
16017  about
16018 \series bold
16019  volatile
16020 \series default
16021  */
16022 \newline
16023
16024 \newline
16025 void to_buffer( unsigned char c ) 
16026 \newline
16027 {
16028 \newline
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 if( head != (unsigned char)(tail-1)
16034  )\InsetSpace ~
16035 /* cast 
16036 \series bold
16037 needed
16038 \series default
16039  to avoid promotion
16040 \begin_inset LatexCommand \index{promotion to signed int}
16041
16042 \end_inset
16043
16044
16045 \begin_inset LatexCommand \index{type promotion}
16046
16047 \end_inset
16048
16049  to integer */
16050 \begin_inset Marginal
16051 status collapsed
16052
16053 \begin_layout Standard
16054
16055 \series bold
16056 \InsetSpace ~
16057 !
16058 \end_layout
16059
16060 \end_inset
16061
16062
16063 \newline
16064 \InsetSpace ~
16065 \InsetSpace ~
16066 \InsetSpace ~
16067 \InsetSpace ~
16068 \InsetSpace ~
16069 \InsetSpace ~
16070 \InsetSpace ~
16071 \InsetSpace ~
16072 buf[ head++ ] = c;\InsetSpace ~
16073 \InsetSpace ~
16074 \InsetSpace ~
16075 \InsetSpace ~
16076 \InsetSpace ~
16077 \InsetSpace ~
16078 \InsetSpace ~
16079 \InsetSpace ~
16080 \InsetSpace ~
16081 \InsetSpace ~
16082 \InsetSpace ~
16083 \InsetSpace ~
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 \InsetSpace ~
16087 \InsetSpace ~
16088 /* access to a 256 byte aligned array */
16089 \newline
16090
16091 \end_layout
16092
16093 \begin_layout Standard
16094 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16095  then a corresponding buffer.asm file is generated.
16096  We define a new function 
16097 \family typewriter
16098 to_buffer_asm()
16099 \family default
16100  in file buffer.c in which we cut and paste the generated code, removing
16101  unwanted comments and some ':'.
16102  Then add 
16103 \begin_inset Quotes sld
16104 \end_inset
16105
16106
16107 \series bold
16108 _asm
16109 \series default
16110
16111 \begin_inset Quotes srd
16112 \end_inset
16113
16114  and 
16115 \begin_inset Quotes sld
16116 \end_inset
16117
16118
16119 \series bold
16120 _endasm;
16121 \series default
16122
16123 \begin_inset Quotes srd
16124 \end_inset
16125
16126
16127 \begin_inset Foot
16128 status open
16129
16130 \begin_layout Standard
16131 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16132  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16133  has to be used.
16134  The latter is also used in the library functions.
16135 \end_layout
16136
16137 \end_inset
16138
16139  to the beginning and the end of the function body:
16140 \end_layout
16141
16142 \begin_layout Verse
16143
16144 \family typewriter
16145 \size footnotesize
16146 /* With a cut and paste from the .asm file, we have something to start with.
16147 \newline
16148 \InsetSpace ~
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 The
16152  function is not yet OK! (registers aren't saved) */ 
16153 \newline
16154 void to_buffer_asm(
16155  unsigned char c ) 
16156 \newline
16157
16158 \newline
16159 \InsetSpace ~
16160 \InsetSpace ~
16161 \InsetSpace ~
16162 \InsetSpace ~
16163 _asm
16164 \begin_inset LatexCommand \index{\_asm}
16165
16166 \end_inset
16167
16168
16169 \begin_inset LatexCommand \index{\_\_asm}
16170
16171 \end_inset
16172
16173
16174 \newline
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 mov\InsetSpace ~
16180 \InsetSpace ~
16181 r2,dpl 
16182 \newline
16183 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16184 /* cast 
16185 \series bold
16186 needed
16187 \series default
16188  to avoid promotion
16189 \begin_inset LatexCommand \index{promotion to signed int}
16190
16191 \end_inset
16192
16193
16194 \begin_inset LatexCommand \index{type promotion}
16195
16196 \end_inset
16197
16198  to integer */
16199 \newline
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 mov\InsetSpace ~
16205 \InsetSpace ~
16206 a,_tail 
16207 \newline
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 \InsetSpace ~
16211 \InsetSpace ~
16212 dec\InsetSpace ~
16213 \InsetSpace ~
16214
16215 \newline
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 \InsetSpace ~
16219 \InsetSpace ~
16220 mov\InsetSpace ~
16221 \InsetSpace ~
16222 r3,a 
16223 \newline
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 \InsetSpace ~
16228 mov\InsetSpace ~
16229 \InsetSpace ~
16230 a,_head 
16231 \newline
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 cjne a,ar3,00106$ 
16237 \newline
16238 \InsetSpace ~
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 ret
16243 \newline
16244 00106$:
16245  
16246 \newline
16247 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16248 \begin_inset LatexCommand \index{Aligned array}
16249
16250 \end_inset
16251
16252
16253 \newline
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 mov\InsetSpace ~
16259 \InsetSpace ~
16260 r3,_head 
16261 \newline
16262 \InsetSpace ~
16263 \InsetSpace ~
16264 \InsetSpace ~
16265 \InsetSpace ~
16266 inc\InsetSpace ~
16267 \InsetSpace ~
16268 _head 
16269 \newline
16270 \InsetSpace ~
16271 \InsetSpace ~
16272 \InsetSpace ~
16273 \InsetSpace ~
16274 mov\InsetSpace ~
16275 \InsetSpace ~
16276 dpl,r3 
16277 \newline
16278 \InsetSpace ~
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 mov\InsetSpace ~
16283 \InsetSpace ~
16284 dph,#(_buf >> 8) 
16285 \newline
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 \InsetSpace ~
16290 mov\InsetSpace ~
16291 \InsetSpace ~
16292 a,r2 
16293 \newline
16294 \InsetSpace ~
16295 \InsetSpace ~
16296 \InsetSpace ~
16297 \InsetSpace ~
16298 movx @dptr,a
16299  
16300 \newline
16301 00103$: 
16302 \newline
16303 \InsetSpace ~
16304 \InsetSpace ~
16305 \InsetSpace ~
16306 \InsetSpace ~
16307 ret
16308 \newline
16309 \InsetSpace ~
16310 \InsetSpace ~
16311 \InsetSpace ~
16312 \InsetSpace ~
16313 _endasm
16314 \begin_inset LatexCommand \index{\_endasm}
16315
16316 \end_inset
16317
16318
16319 \begin_inset LatexCommand \index{\_\_endasm}
16320
16321 \end_inset
16322
16323 ;
16324 \newline
16325
16326 \end_layout
16327
16328 \begin_layout Standard
16329 The new file buffer.c should compile with only one warning about the unreferenced
16330  function argument 'c'.
16331  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16332  (1) and finally have:
16333 \end_layout
16334
16335 \begin_layout Verse
16336
16337 \family typewriter
16338 \size footnotesize
16339 unsigned char __far __at(0x7f00) buf[0x100];
16340 \newline
16341 unsigned char head, tail;
16342 \newline
16343 #define
16344  USE_ASSEMBLY (1)
16345 \newline
16346
16347 \newline
16348 #if !USE_ASSEMBLY
16349 \newline
16350
16351 \newline
16352 void to_buffer( unsigned char c )
16353 \newline
16354 {
16355 \newline
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 if(
16361  head != (unsigned char)(tail-1) )
16362 \newline
16363 \InsetSpace ~
16364 \InsetSpace ~
16365 \InsetSpace ~
16366 \InsetSpace ~
16367 \InsetSpace ~
16368 \InsetSpace ~
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 buf[ head++ ] = c;
16372 \newline
16373 }
16374 \newline
16375
16376 \newline
16377 #else
16378 \newline
16379
16380 \newline
16381 void to_buffer(
16382  unsigned char c )
16383 \newline
16384 {
16385 \newline
16386 \InsetSpace ~
16387 \InsetSpace ~
16388 \InsetSpace ~
16389 \InsetSpace ~
16390 c; // to avoid warning: unreferenced function argument
16391 \newline
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 _asm
16397 \begin_inset LatexCommand \index{\_asm}
16398
16399 \end_inset
16400
16401
16402 \begin_inset LatexCommand \index{\_\_asm}
16403
16404 \end_inset
16405
16406
16407 \newline
16408 \InsetSpace ~
16409 \InsetSpace ~
16410 \InsetSpace ~
16411 \InsetSpace ~
16412 \InsetSpace ~
16413 \InsetSpace ~
16414 \InsetSpace ~
16415 \InsetSpace ~
16416 ; save used registers here.
16417  
16418 \newline
16419 \InsetSpace ~
16420 \InsetSpace ~
16421 \InsetSpace ~
16422 \InsetSpace ~
16423 \InsetSpace ~
16424 \InsetSpace ~
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 ; If we were still using r2,r3 we would have to push them here.
16428  
16429 \newline
16430 ; if( head != (unsigned char)(tail-1) )
16431 \newline
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 \InsetSpace ~
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 \InsetSpace ~
16440 mov\InsetSpace ~
16441  a,_tail
16442 \newline
16443 \InsetSpace ~
16444 \InsetSpace ~
16445 \InsetSpace ~
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 dec\InsetSpace ~
16452  a
16453 \newline
16454 \InsetSpace ~
16455 \InsetSpace ~
16456 \InsetSpace ~
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 xrl\InsetSpace ~
16463  a,_head
16464 \newline
16465 \InsetSpace ~
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 \InsetSpace ~
16470 \InsetSpace ~
16471 \InsetSpace ~
16472 \InsetSpace ~
16473 ; we
16474  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16475 \newline
16476 \InsetSpace ~
16477 \InsetSpace ~
16478 \InsetSpace ~
16479 \InsetSpace ~
16480 \InsetSpace ~
16481 \InsetSpace ~
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 jz\InsetSpace ~
16485 \InsetSpace ~
16486  t_b_end$
16487 \newline
16488 \InsetSpace ~
16489 \InsetSpace ~
16490 \InsetSpace ~
16491 \InsetSpace ~
16492 \InsetSpace ~
16493 \InsetSpace ~
16494 \InsetSpace ~
16495 \InsetSpace ~
16496 ;
16497 \newline
16498 ;
16499  buf[ head++ ] = c;
16500 \newline
16501 \InsetSpace ~
16502 \InsetSpace ~
16503 \InsetSpace ~
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 \InsetSpace ~
16509 mov\InsetSpace ~
16510  a,dpl \InsetSpace ~
16511 \InsetSpace ~
16512 \InsetSpace ~
16513 \InsetSpace ~
16514 \InsetSpace ~
16515 \InsetSpace ~
16516 \InsetSpace ~
16517 ; dpl holds lower byte of function argument
16518 \newline
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 \InsetSpace ~
16524 \InsetSpace ~
16525 \InsetSpace ~
16526 \InsetSpace ~
16527 mov\InsetSpace ~
16528
16529  dpl,_head \InsetSpace ~
16530 \InsetSpace ~
16531 \InsetSpace ~
16532 ; buf is 0x100 byte aligned so head can be used directly
16533 \newline
16534 \InsetSpace ~
16535 \InsetSpace ~
16536 \InsetSpace ~
16537 \InsetSpace ~
16538 \InsetSpace ~
16539 \InsetSpace ~
16540 \InsetSpace ~
16541 \InsetSpace ~
16542 mov\InsetSpace ~
16543  dph,#(_bu
16544 f>>8)
16545 \newline
16546 \InsetSpace ~
16547 \InsetSpace ~
16548 \InsetSpace ~
16549 \InsetSpace ~
16550 \InsetSpace ~
16551 \InsetSpace ~
16552 \InsetSpace ~
16553 \InsetSpace ~
16554 movx @dptr,a
16555 \newline
16556 \InsetSpace ~
16557 \InsetSpace ~
16558 \InsetSpace ~
16559 \InsetSpace ~
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 \InsetSpace ~
16564 inc \InsetSpace ~
16565 _head
16566 \newline
16567 \InsetSpace ~
16568 \InsetSpace ~
16569 \InsetSpace ~
16570 \InsetSpace ~
16571 \InsetSpace ~
16572 \InsetSpace ~
16573 \InsetSpace ~
16574 \InsetSpace ~
16575 ; we could do an ANL _head,#0x0f here to use a
16576  smaller buffer (see above)
16577 \newline
16578 t_b_end$:
16579 \newline
16580 \InsetSpace ~
16581 \InsetSpace ~
16582 \InsetSpace ~
16583 \InsetSpace ~
16584 \InsetSpace ~
16585 \InsetSpace ~
16586 \InsetSpace ~
16587 \InsetSpace ~
16588 ; restore used registers here 
16589 \newline
16590 \InsetSpace ~
16591 \InsetSpace ~
16592 \InsetSpace ~
16593 \InsetSpace ~
16594 _endasm
16595 \begin_inset LatexCommand \index{\_endasm}
16596
16597 \end_inset
16598
16599
16600 \begin_inset LatexCommand \index{\_\_endasm}
16601
16602 \end_inset
16603
16604 ;
16605 \newline
16606 }
16607 \newline
16608 #endif
16609 \end_layout
16610
16611 \begin_layout Standard
16612 The inline assembler code can contain any valid code understood by the assembler
16613 , this includes any assembler directives and comment lines.
16614  The assembler does not like some characters like ':' or ''' in comments.
16615  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16616 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16617
16618 \end_inset
16619
16620
16621 \begin_inset LatexCommand \index{Assembler documentation}
16622
16623 \end_inset
16624
16625  or online at 
16626 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16627
16628 \end_inset
16629
16630 \InsetSpace ~
16631 .
16632 \end_layout
16633
16634 \begin_layout Standard
16635 The compiler does not do any validation of the code within the 
16636 \family typewriter
16637 _asm
16638 \begin_inset LatexCommand \index{\_asm}
16639
16640 \end_inset
16641
16642
16643 \begin_inset LatexCommand \index{\_\_asm}
16644
16645 \end_inset
16646
16647  ...
16648  _endasm
16649 \size footnotesize
16650
16651 \begin_inset LatexCommand \index{\_endasm}
16652
16653 \end_inset
16654
16655
16656 \begin_inset LatexCommand \index{\_\_endasm}
16657
16658 \end_inset
16659
16660
16661 \size default
16662 ;
16663 \family default
16664  keyword pair.
16665  Specifically it will not know which registers are used and thus register
16666  pushing/popping
16667 \begin_inset LatexCommand \index{push/pop}
16668
16669 \end_inset
16670
16671  has to be done manually.
16672  
16673 \end_layout
16674
16675 \begin_layout Standard
16676 It is recommended that each assembly instruction (including labels) be placed
16677  in a separate line (as the example shows).
16678  When the -
16679 \begin_inset ERT
16680 status collapsed
16681
16682 \begin_layout Standard
16683
16684
16685 \backslash
16686 /
16687 \end_layout
16688
16689 \end_inset
16690
16691 -
16692 \emph on
16693 peep-asm
16694 \begin_inset LatexCommand \index{-\/-peep-asm}
16695
16696 \end_inset
16697
16698
16699 \emph default
16700  command line option is used, the inline assembler code will be passed through
16701  the peephole optimizer
16702 \begin_inset LatexCommand \index{Peephole optimizer}
16703
16704 \end_inset
16705
16706 .
16707  There are only a few (if any) cases where this option makes sense, it might
16708  cause some unexpected changes in the inline assembler code.
16709  Please go through the peephole optimizer rules defined in file 
16710 \emph on
16711 SDCCpeeph.def
16712 \emph default
16713  before using this option.
16714 \end_layout
16715
16716 \begin_layout Subsection
16717 Naked Functions
16718 \begin_inset LatexCommand \label{sub:Naked-Functions}
16719
16720 \end_inset
16721
16722
16723 \begin_inset LatexCommand \index{Naked functions}
16724
16725 \end_inset
16726
16727
16728 \end_layout
16729
16730 \begin_layout Standard
16731 A special keyword may be associated with a function declaring it as 
16732 \emph on
16733 _naked
16734 \begin_inset LatexCommand \index{\_naked}
16735
16736 \end_inset
16737
16738
16739 \begin_inset LatexCommand \index{\_\_naked}
16740
16741 \end_inset
16742
16743 .
16744  
16745 \emph default
16746 The 
16747 \emph on
16748 _naked
16749 \emph default
16750  function modifier attribute prevents the compiler from generating prologue
16751 \begin_inset LatexCommand \index{function prologue}
16752
16753 \end_inset
16754
16755  and epilogue
16756 \begin_inset LatexCommand \index{function epilogue}
16757
16758 \end_inset
16759
16760  code for that function.
16761  This means that the user is entirely responsible for such things as saving
16762  any registers that may need to be preserved, selecting the proper register
16763  bank, generating the 
16764 \emph on
16765 return
16766 \emph default
16767  instruction at the end, etc.
16768  Practically, this means that the contents of the function must be written
16769  in inline assembler.
16770  This is particularly useful for interrupt functions, which can have a large
16771  (and often unnecessary) prologue/epilogue.
16772  For example, compare the code generated by these two functions:
16773 \end_layout
16774
16775 \begin_layout Verse
16776
16777 \family typewriter
16778 volatile
16779 \begin_inset LatexCommand \index{volatile}
16780
16781 \end_inset
16782
16783  data unsigned char counter;
16784 \newline
16785
16786 \newline
16787 void simpleInterrupt(void) __interrupt
16788 \begin_inset LatexCommand \index{interrupt}
16789
16790 \end_inset
16791
16792
16793 \begin_inset LatexCommand \index{\_\_interrupt}
16794
16795 \end_inset
16796
16797  (1)
16798 \newline
16799 {
16800 \newline
16801 \InsetSpace ~
16802 \InsetSpace ~
16803 \InsetSpace ~
16804 \InsetSpace ~
16805 counter++;
16806 \newline
16807 }
16808 \newline
16809
16810 \newline
16811 void nakedInterrupt(void) __interrupt (2) __naked
16812 \newline
16813 {
16814 \newline
16815 \InsetSpace ~
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 _asm
16820 \begin_inset LatexCommand \index{\_asm}
16821
16822 \end_inset
16823
16824
16825 \begin_inset LatexCommand \index{\_\_asm}
16826
16827 \end_inset
16828
16829
16830 \newline
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 \InsetSpace ~
16834 \InsetSpace ~
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 inc\InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 _counter ; does not change flags, no need to save psw
16843 \newline
16844 \InsetSpace ~
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 reti\InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 ; MUST explicitly
16855  include ret or reti in _naked function.
16856 \newline
16857 \InsetSpace ~
16858 \InsetSpace ~
16859 \InsetSpace ~
16860 \InsetSpace ~
16861 _endasm
16862 \begin_inset LatexCommand \index{\_endasm}
16863
16864 \end_inset
16865
16866
16867 \begin_inset LatexCommand \index{\_\_endasm}
16868
16869 \end_inset
16870
16871 ;
16872 \newline
16873 }
16874 \end_layout
16875
16876 \begin_layout Standard
16877 For an 8051 target, the generated simpleInterrupt looks like:
16878 \end_layout
16879
16880 \begin_layout Verse
16881
16882 \family typewriter
16883 Note, this is an 
16884 \emph on
16885 outdated
16886 \emph default
16887  example, recent versions of SDCC generate
16888 \newline
16889 the 
16890 \emph on
16891 same
16892 \emph default
16893  code for simpleInterrupt() and nakedInterrupt()!
16894 \newline
16895
16896 \newline
16897 _simpleInterrupt:
16898 \newline
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 \InsetSpace ~
16902 \InsetSpace ~
16903 push\InsetSpace ~
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 acc
16908 \newline
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 \InsetSpace ~
16912 \InsetSpace ~
16913 push\InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 b
16918 \newline
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 pu
16924 sh\InsetSpace ~
16925 \InsetSpace ~
16926 \InsetSpace ~
16927 \InsetSpace ~
16928 dpl
16929 \newline
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 push\InsetSpace ~
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 \InsetSpace ~
16938 dph
16939 \newline
16940 \InsetSpace ~
16941 \InsetSpace ~
16942 \InsetSpace ~
16943 \InsetSpace ~
16944 push\InsetSpace ~
16945 \InsetSpace ~
16946 \InsetSpace ~
16947 \InsetSpace ~
16948 psw
16949 \newline
16950 \InsetSpace ~
16951 \InsetSpace ~
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 mov\InsetSpace ~
16955 \InsetSpace ~
16956 \InsetSpace ~
16957 \InsetSpace ~
16958 \InsetSpace ~
16959 psw,#0x00
16960 \newline
16961 \InsetSpace ~
16962 \InsetSpace ~
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 inc\InsetSpace ~
16966 \InsetSpace ~
16967 \InsetSpace ~
16968 \InsetSpace ~
16969 \InsetSpace ~
16970 _counter
16971 \newline
16972 \InsetSpace ~
16973 \InsetSpace ~
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 pop\InsetSpace ~
16977 \InsetSpace ~
16978 \InsetSpace ~
16979 \InsetSpace ~
16980 \InsetSpace ~
16981 psw
16982 \newline
16983 \InsetSpace ~
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 pop\InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 \InsetSpace ~
16992 dph
16993 \newline
16994 \InsetSpace ~
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 pop\InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 \InsetSpace ~
17003 dpl
17004 \newline
17005 \InsetSpace ~
17006 \InsetSpace ~
17007 \InsetSpace ~
17008 \InsetSpace ~
17009 pop\InsetSpace ~
17010 \InsetSpace ~
17011 \InsetSpace ~
17012 \InsetSpace ~
17013 \InsetSpace ~
17014 b
17015 \newline
17016 \InsetSpace ~
17017 \InsetSpace ~
17018 \InsetSpace ~
17019 \InsetSpace ~
17020 pop\InsetSpace ~
17021 \InsetSpace ~
17022 \InsetSpace ~
17023 \InsetSpace ~
17024 \InsetSpace ~
17025 acc
17026 \newline
17027 \InsetSpace ~
17028 \InsetSpace ~
17029 \InsetSpace ~
17030 \InsetSpace ~
17031 reti
17032 \end_layout
17033
17034 \begin_layout Standard
17035 whereas nakedInterrupt looks like:
17036 \end_layout
17037
17038 \begin_layout Verse
17039
17040 \family typewriter
17041 _nakedInterrupt:
17042 \newline
17043 \InsetSpace ~
17044 \InsetSpace ~
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 inc\InsetSpace ~
17048 \InsetSpace ~
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 _counter ; does not change flags, no need to save psw
17052 \newline
17053 \InsetSpace ~
17054 \InsetSpace ~
17055 \InsetSpace ~
17056 \InsetSpace ~
17057 reti\InsetSpace ~
17058 \InsetSpace ~
17059 \InsetSpace ~
17060 \InsetSpace ~
17061 \InsetSpace ~
17062 \InsetSpace ~
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 \InsetSpace ~
17068 \InsetSpace ~
17069 ;
17070  MUST explicitly include ret or reti in _naked function
17071 \end_layout
17072
17073 \begin_layout Standard
17074 The related directive #pragma exclude
17075 \begin_inset LatexCommand \index{\#pragma exclude}
17076
17077 \end_inset
17078
17079  allows a more fine grained control over pushing & popping
17080 \begin_inset LatexCommand \index{push/pop}
17081
17082 \end_inset
17083
17084  the registers.
17085 \end_layout
17086
17087 \begin_layout Standard
17088 While there is nothing preventing you from writing C code inside a 
17089 \family typewriter
17090 _naked
17091 \family default
17092  function, there are many ways to shoot yourself in the foot doing this,
17093  and it is recommended that you stick to inline assembler.
17094 \end_layout
17095
17096 \begin_layout Subsection
17097 Use of Labels within Inline Assembler
17098 \end_layout
17099
17100 \begin_layout Standard
17101 SDCC allows the use of in-line assembler with a few restrictions regarding
17102  labels.
17103  In older versions of the compiler all labels defined within inline assembler
17104  code had to be of the form 
17105 \emph on
17106 nnnnn$
17107 \emph default
17108  where nnnnn is a number less than 100 (which implies a limit of utmost
17109  100 inline assembler labels 
17110 \emph on
17111 per function
17112 \emph default
17113 \noun on
17114 )
17115 \noun default
17116 .
17117  
17118 \end_layout
17119
17120 \begin_layout Verse
17121
17122 \family typewriter
17123 _asm
17124 \begin_inset LatexCommand \index{\_asm}
17125
17126 \end_inset
17127
17128
17129 \begin_inset LatexCommand \index{\_\_asm}
17130
17131 \end_inset
17132
17133  
17134 \newline
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 mov\InsetSpace ~
17140 \InsetSpace ~
17141 \InsetSpace ~
17142 \InsetSpace ~
17143 \InsetSpace ~
17144 b,#10 
17145 \newline
17146 00001$: 
17147 \newline
17148 \InsetSpace ~
17149 \InsetSpace ~
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 djnz\InsetSpace ~
17153 \InsetSpace ~
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 b,00001$ 
17157 \newline
17158 _endasm
17159 \begin_inset LatexCommand \index{\_endasm}
17160
17161 \end_inset
17162
17163
17164 \begin_inset LatexCommand \index{\_\_endasm}
17165
17166 \end_inset
17167
17168  ;
17169 \end_layout
17170
17171 \begin_layout Standard
17172 Inline assembler code cannot reference any C-labels, however it can reference
17173  labels
17174 \begin_inset LatexCommand \index{Labels}
17175
17176 \end_inset
17177
17178  defined by the inline assembler, e.g.:
17179 \end_layout
17180
17181 \begin_layout Verse
17182
17183 \family typewriter
17184 foo() { 
17185 \newline
17186 \InsetSpace ~
17187 \InsetSpace ~
17188 \InsetSpace ~
17189 \InsetSpace ~
17190 /* some c code */ 
17191 \newline
17192 \InsetSpace ~
17193 \InsetSpace ~
17194 \InsetSpace ~
17195 \InsetSpace ~
17196 _asm 
17197 \newline
17198 \InsetSpace ~
17199 \InsetSpace ~
17200 \InsetSpace ~
17201 \InsetSpace ~
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 ; some assembler code 
17205 \newline
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 \InsetSpace ~
17211 \InsetSpace ~
17212 ljmp $0003 
17213 \newline
17214 \InsetSpace ~
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 _endasm;
17219  
17220 \newline
17221 \InsetSpace ~
17222 \InsetSpace ~
17223 \InsetSpace ~
17224 \InsetSpace ~
17225 /* some more c code */ 
17226 \newline
17227 clabel:\InsetSpace ~
17228 \InsetSpace ~
17229 /* inline assembler cannot reference this
17230  label */ 
17231 \newline
17232 \InsetSpace ~
17233 \InsetSpace ~
17234 \InsetSpace ~
17235 \InsetSpace ~
17236 _asm
17237 \newline
17238 \InsetSpace ~
17239 \InsetSpace ~
17240 \InsetSpace ~
17241 \InsetSpace ~
17242 $0003: ;label (can be referenced by inline assembler only)
17243  
17244 \newline
17245 \InsetSpace ~
17246 \InsetSpace ~
17247 \InsetSpace ~
17248 \InsetSpace ~
17249 _endasm
17250 \begin_inset LatexCommand \index{\_endasm}
17251
17252 \end_inset
17253
17254
17255 \begin_inset LatexCommand \index{\_\_endasm}
17256
17257 \end_inset
17258
17259  ; 
17260 \newline
17261 \InsetSpace ~
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 /* some more c code */
17266 \newline
17267 }
17268 \end_layout
17269
17270 \begin_layout Standard
17271 In other words inline assembly code can access labels defined in inline
17272  assembly within the scope of the function.
17273  The same goes the other way, i.e.
17274  labels defines in inline assembly can not be accessed by C statements.
17275 \end_layout
17276
17277 \begin_layout Section
17278 Interfacing with Assembler Code
17279 \begin_inset LatexCommand \index{Assembler routines}
17280
17281 \end_inset
17282
17283
17284 \end_layout
17285
17286 \begin_layout Subsection
17287 Global Registers used for Parameter Passing
17288 \begin_inset LatexCommand \index{Parameter passing}
17289
17290 \end_inset
17291
17292
17293 \end_layout
17294
17295 \begin_layout Standard
17296 The compiler always uses the global registers 
17297 \emph on
17298 DPL, DPH
17299 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17300
17301 \end_inset
17302
17303
17304 \begin_inset LatexCommand \index{DPTR}
17305
17306 \end_inset
17307
17308 , B
17309 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17310
17311 \end_inset
17312
17313  
17314 \emph default
17315 and
17316 \emph on
17317  ACC
17318 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17319
17320 \end_inset
17321
17322
17323 \emph default
17324  to pass the first parameter to a function, and also to pass the return
17325  value 
17326 \begin_inset LatexCommand \index{return value}
17327
17328 \end_inset
17329
17330 of function; according to the following scheme: one byte return value in
17331  
17332 \emph on
17333 DPL
17334 \emph default
17335 , two byte value in 
17336 \emph on
17337 DPL
17338 \emph default
17339  (LSB) and 
17340 \emph on
17341 DPH
17342 \emph default
17343  (MSB).
17344  three byte values (generic pointers) in 
17345 \emph on
17346 DPH
17347 \emph default
17348
17349 \emph on
17350 DPL
17351 \emph default
17352  and 
17353 \emph on
17354 B
17355 \emph default
17356 , and four byte values in 
17357 \emph on
17358 DPH
17359 \emph default
17360
17361 \emph on
17362 DPL
17363 \emph default
17364 ,
17365 \emph on
17366  B
17367 \emph default
17368  and 
17369 \emph on
17370 ACC
17371 \emph default
17372 .
17373  Generic pointers
17374 \begin_inset LatexCommand \index{generic pointer}
17375
17376 \end_inset
17377
17378  contain type of accessed memory in 
17379 \emph on
17380 B
17381 \emph default
17382
17383 \series bold
17384 0x00
17385 \series default
17386  -- xdata/far, 
17387 \series bold
17388 0x40
17389 \series default
17390  -- idata/near -- , 
17391 \series bold
17392 0x60
17393 \series default
17394  -- pdata, 
17395 \series bold
17396 0x80
17397 \series default
17398  -- code
17399 \begin_inset Note Note
17400 status collapsed
17401
17402 \begin_layout Standard
17403 This might not be the case of certain memory models (medium???)
17404 \end_layout
17405
17406 \end_inset
17407
17408 .
17409 \end_layout
17410
17411 \begin_layout Standard
17412 The second parameter onwards is either allocated on the stack (for reentrant
17413  routines or if -
17414 \begin_inset ERT
17415 status collapsed
17416
17417 \begin_layout Standard
17418
17419
17420 \backslash
17421 /
17422 \end_layout
17423
17424 \end_inset
17425
17426 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17427  
17428 \end_layout
17429
17430 \begin_layout Subsection
17431 Registers usage
17432 \end_layout
17433
17434 \begin_layout Standard
17435 Unless the called function is declared as 
17436 \family typewriter
17437 _naked
17438 \family default
17439
17440 \begin_inset LatexCommand \index{naked}
17441
17442 \end_inset
17443
17444 , or the -
17445 \begin_inset ERT
17446 status collapsed
17447
17448 \begin_layout Standard
17449
17450
17451 \backslash
17452 /
17453 \end_layout
17454
17455 \end_inset
17456
17457 -callee-saves
17458 \begin_inset LatexCommand \index{-\/-callee-saves}
17459
17460 \end_inset
17461
17462 /-
17463 \begin_inset ERT
17464 status collapsed
17465
17466 \begin_layout Standard
17467
17468
17469 \backslash
17470 /
17471 \end_layout
17472
17473 \end_inset
17474
17475 -all-callee-saves command line option or the corresponding callee_saves
17476  pragma are used, the caller will save the registers (
17477 \emph on
17478 R0-R7
17479 \emph default
17480 ) around the call, so the called function can destroy they content freely.
17481 \end_layout
17482
17483 \begin_layout Standard
17484 If the called function is not declared as 
17485 \family typewriter
17486 _naked
17487 \family default
17488 , the caller will swap register banks around the call, if caller and callee
17489  use different register banks (having them defined by the 
17490 \family typewriter
17491 _using
17492 \family default
17493  modifier).
17494  
17495 \end_layout
17496
17497 \begin_layout Standard
17498 The called function can also use 
17499 \emph on
17500 DPL
17501 \emph default
17502
17503 \emph on
17504 DPH
17505 \emph default
17506
17507 \emph on
17508 B
17509 \emph default
17510  and 
17511 \emph on
17512 ACC
17513 \emph default
17514  observing that they are used for parameter/return value passing.
17515 \end_layout
17516
17517 \begin_layout Subsection
17518 Assembler Routine (non-reentrant)
17519 \end_layout
17520
17521 \begin_layout Standard
17522 In the following example
17523 \begin_inset LatexCommand \index{reentrant}
17524
17525 \end_inset
17526
17527
17528 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17529
17530 \end_inset
17531
17532  the function c_func calls an assembler routine asm_func, which takes two
17533  parameters
17534 \begin_inset LatexCommand \index{function parameter}
17535
17536 \end_inset
17537
17538 .
17539 \end_layout
17540
17541 \begin_layout Verse
17542
17543 \family typewriter
17544 extern int asm_func(unsigned char, unsigned char);
17545 \newline
17546
17547 \newline
17548 int c_func (unsigned char
17549  i, unsigned char j)
17550 \newline
17551 {
17552 \newline
17553 \InsetSpace ~
17554 \InsetSpace ~
17555 \InsetSpace ~
17556 \InsetSpace ~
17557 return asm_func(i,j);
17558 \newline
17559 }
17560 \newline
17561
17562 \newline
17563 int main()
17564 \newline
17565 {
17566 \newline
17567 \InsetSpace ~
17568 \InsetSpace ~
17569 \InsetSpace ~
17570 \InsetSpace ~
17571 return c_func(10,9);
17572 \newline
17573 }
17574 \end_layout
17575
17576 \begin_layout Standard
17577 The corresponding assembler function is:
17578 \end_layout
17579
17580 \begin_layout Verse
17581
17582 \family typewriter
17583 .globl _asm_func_PARM_2 
17584 \newline
17585 \InsetSpace ~
17586 \InsetSpace ~
17587 \InsetSpace ~
17588 \InsetSpace ~
17589 \InsetSpace ~
17590 \InsetSpace ~
17591 \InsetSpace ~
17592 \InsetSpace ~
17593 .globl _asm_func 
17594 \newline
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 \InsetSpace ~
17602 \InsetSpace ~
17603 .area OSEG 
17604 \newline
17605 _asm_func_PARM_2:
17606 \newline
17607 \InsetSpace ~
17608 \InsetSpace ~
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 \InsetSpace ~
17612 \InsetSpace ~
17613 \InsetSpace ~
17614 \InsetSpace ~
17615 .ds   
17616  1 
17617 \newline
17618 \InsetSpace ~
17619 \InsetSpace ~
17620 \InsetSpace ~
17621 \InsetSpace ~
17622 \InsetSpace ~
17623 \InsetSpace ~
17624 \InsetSpace ~
17625 \InsetSpace ~
17626 .area CSEG 
17627 \newline
17628 _asm_func: 
17629 \newline
17630 \InsetSpace ~
17631 \InsetSpace ~
17632 \InsetSpace ~
17633 \InsetSpace ~
17634 \InsetSpace ~
17635 \InsetSpace ~
17636 \InsetSpace ~
17637 \InsetSpace ~
17638 mov\InsetSpace ~
17639 \InsetSpace ~
17640 \InsetSpace ~
17641 \InsetSpace ~
17642 a,dpl 
17643 \newline
17644 \InsetSpace ~
17645 \InsetSpace ~
17646 \InsetSpace ~
17647 \InsetSpace ~
17648 \InsetSpace ~
17649 \InsetSpace ~
17650 \InsetSpace ~
17651 \InsetSpace ~
17652 add\InsetSpace ~
17653 \InsetSpace ~
17654 \InsetSpace ~
17655 \InsetSpace ~
17656 a,_asm_func_PARM_2 
17657 \newline
17658 \InsetSpace ~
17659 \InsetSpace ~
17660 \InsetSpace ~
17661 \InsetSpace ~
17662 \InsetSpace ~
17663 \InsetSpace ~
17664 \InsetSpace ~
17665 \InsetSpace ~
17666 mov\InsetSpace ~
17667 \InsetSpace ~
17668 \InsetSpace ~
17669 \InsetSpace ~
17670 dpl,a 
17671 \newline
17672 \InsetSpace ~
17673 \InsetSpace ~
17674 \InsetSpace ~
17675 \InsetSpace ~
17676 \InsetSpace ~
17677 \InsetSpace ~
17678 \InsetSpace ~
17679 \InsetSpace ~
17680 mov\InsetSpace ~
17681 \InsetSpace ~
17682 \InsetSpace ~
17683 \InsetSpace ~
17684 dph
17685 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17686
17687 \end_inset
17688
17689 ,#0x00 
17690 \newline
17691 \InsetSpace ~
17692 \InsetSpace ~
17693 \InsetSpace ~
17694 \InsetSpace ~
17695 \InsetSpace ~
17696 \InsetSpace ~
17697 \InsetSpace ~
17698 \InsetSpace ~
17699 ret
17700 \end_layout
17701
17702 \begin_layout Standard
17703 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17704  the parameter number starting from 1, and counting from the left.
17705  The first parameter is passed in 
17706 \emph on
17707 DPH
17708 \emph default
17709
17710 \emph on
17711 DPL
17712 \emph default
17713
17714 \emph on
17715 B
17716 \emph default
17717  and 
17718 \emph on
17719 ACC
17720 \emph default
17721  according to the description above.
17722  The variable name for the second parameter will be _<function_name>_PARM_2.
17723 \newline
17724
17725 \newline
17726 Assem
17727 ble the assembler routine with the following command:
17728 \newline
17729
17730 \newline
17731
17732 \family sans
17733 \series bold
17734 asx8051 -losg asmfunc.asm
17735 \newline
17736
17737 \newline
17738
17739 \family default
17740 \series default
17741 Then compile and link the assembler routine to the C source file with the
17742  following command:
17743 \newline
17744
17745 \newline
17746
17747 \family sans
17748 \series bold
17749 sdcc cfunc.c asmfunc.rel
17750 \end_layout
17751
17752 \begin_layout Subsection
17753 Assembler Routine (reentrant)
17754 \end_layout
17755
17756 \begin_layout Standard
17757 In this case
17758 \begin_inset LatexCommand \index{reentrant}
17759
17760 \end_inset
17761
17762
17763 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17764
17765 \end_inset
17766
17767  the second parameter
17768 \begin_inset LatexCommand \index{function parameter}
17769
17770 \end_inset
17771
17772  onwards will be passed on the stack, the parameters are pushed from right
17773  to left i.e.
17774  before the call the second leftmost parameter will be on the top of the
17775  stack (the leftmost parameter is passed in registers).
17776  Here is an example:
17777 \end_layout
17778
17779 \begin_layout Verse
17780
17781 \family typewriter
17782 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17783 \newline
17784
17785 \newline
17786 int
17787  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
17788 \newline
17789 {
17790  
17791 \newline
17792 \InsetSpace ~
17793 \InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 return asm_func(i,j,k); 
17797 \newline
17798
17799 \newline
17800
17801 \newline
17802 int main() 
17803 \newline
17804
17805 \newline
17806 \InsetSpace ~
17807 \InsetSpace ~
17808 \InsetSpace ~
17809 \InsetSpace ~
17810 return c_func(10,9,8); 
17811 \newline
17812 }
17813 \end_layout
17814
17815 \begin_layout Standard
17816 The corresponding (unoptimized) assembler routine is:
17817 \end_layout
17818
17819 \begin_layout Verse
17820
17821 \family typewriter
17822 .globl _asm_func 
17823 \newline
17824 _asm_func: 
17825 \newline
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 push\InsetSpace ~
17831 _bp 
17832 \newline
17833 \InsetSpace ~
17834 \InsetSpace ~
17835 \InsetSpace ~
17836 \InsetSpace ~
17837 mov\InsetSpace ~
17838 \InsetSpace ~
17839 _bp,sp\InsetSpace ~
17840 \InsetSpace ~
17841 \InsetSpace ~
17842 \InsetSpace ~
17843 \InsetSpace ~
17844 \InsetSpace ~
17845 ;stack contains: _bp, return
17846  address, second parameter, third parameter
17847 \newline
17848 \InsetSpace ~
17849 \InsetSpace ~
17850 \InsetSpace ~
17851 \InsetSpace ~
17852 mov\InsetSpace ~
17853 \InsetSpace ~
17854 r2,dpl
17855 \newline
17856 \InsetSpace ~
17857 \InsetSpace ~
17858 \InsetSpace ~
17859 \InsetSpace ~
17860 mov\InsetSpace ~
17861 \InsetSpace ~
17862 a,_bp
17863 \newline
17864 \InsetSpace ~
17865 \InsetSpace ~
17866 \InsetSpace ~
17867 \InsetSpace ~
17868 add\InsetSpace ~
17869 \InsetSpace ~
17870 a,#0xfd\InsetSpace ~
17871 \InsetSpace ~
17872 \InsetSpace ~
17873 \InsetSpace ~
17874 \InsetSpace ~
17875 ;calculate
17876  pointer to the second parameter
17877 \newline
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 \InsetSpace ~
17882 mov\InsetSpace ~
17883 \InsetSpace ~
17884 r0,a 
17885 \newline
17886 \InsetSpace ~
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 \InsetSpace ~
17890 mov\InsetSpace ~
17891 \InsetSpace ~
17892 a,_bp 
17893 \newline
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 \InsetSpace ~
17898 add\InsetSpace ~
17899 \InsetSpace ~
17900 a,#0xfc\InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 ;calculate pointer
17906  to the rightmost parameter
17907 \newline
17908 \InsetSpace ~
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 mov\InsetSpace ~
17913 \InsetSpace ~
17914 r1,a 
17915 \newline
17916 \InsetSpace ~
17917 \InsetSpace ~
17918 \InsetSpace ~
17919 \InsetSpace ~
17920 mov\InsetSpace ~
17921 \InsetSpace ~
17922 a,@r0
17923 \newline
17924 \InsetSpace ~
17925 \InsetSpace ~
17926 \InsetSpace ~
17927 \InsetSpace ~
17928 add\InsetSpace ~
17929 \InsetSpace ~
17930 a,@r1
17931 \newline
17932 \InsetSpace ~
17933 \InsetSpace ~
17934 \InsetSpace ~
17935 \InsetSpace ~
17936 add\InsetSpace ~
17937 \InsetSpace ~
17938 a,r2\InsetSpace ~
17939 \InsetSpace ~
17940 \InsetSpace ~
17941 \InsetSpace ~
17942 \InsetSpace ~
17943 \InsetSpace ~
17944 \InsetSpace ~
17945 \InsetSpace ~
17946 ;calculate the
17947  result (= sum of all three parameters)
17948 \newline
17949 \InsetSpace ~
17950 \InsetSpace ~
17951 \InsetSpace ~
17952 \InsetSpace ~
17953 mov\InsetSpace ~
17954 \InsetSpace ~
17955 dpl,a\InsetSpace ~
17956 \InsetSpace ~
17957 \InsetSpace ~
17958 \InsetSpace ~
17959 \InsetSpace ~
17960 \InsetSpace ~
17961 \InsetSpace ~
17962 ;return value goes into dptr
17963  (cast into int)
17964 \newline
17965 \InsetSpace ~
17966 \InsetSpace ~
17967 \InsetSpace ~
17968 \InsetSpace ~
17969 mov\InsetSpace ~
17970 \InsetSpace ~
17971 dph,#0x00 
17972 \newline
17973 \InsetSpace ~
17974 \InsetSpace ~
17975 \InsetSpace ~
17976 \InsetSpace ~
17977 mov\InsetSpace ~
17978 \InsetSpace ~
17979 sp,_bp 
17980 \newline
17981 \InsetSpace ~
17982 \InsetSpace ~
17983 \InsetSpace ~
17984 \InsetSpace ~
17985 pop\InsetSpace ~
17986 \InsetSpace ~
17987 _bp 
17988 \newline
17989 \InsetSpace ~
17990 \InsetSpace ~
17991 \InsetSpace ~
17992 \InsetSpace ~
17993 ret
17994 \end_layout
17995
17996 \begin_layout Standard
17997 The compiling and linking procedure remains the same, however note the extra
17998  entry & exit linkage required for the assembler code, _bp is the stack
17999  frame pointer and is used to compute the offset into the stack for parameters
18000  and local variables.
18001 \begin_inset VSpace bigskip
18002 \end_inset
18003
18004
18005 \end_layout
18006
18007 \begin_layout Section
18008 int (16 bit)
18009 \begin_inset LatexCommand \index{int (16 bit)}
18010
18011 \end_inset
18012
18013  and long (32 bit)
18014 \begin_inset LatexCommand \index{long (32 bit)}
18015
18016 \end_inset
18017
18018  Support
18019 \end_layout
18020
18021 \begin_layout Standard
18022 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18023  multiplication and modulus operations are implemented by support routines.
18024  These support routines are all developed in ANSI-C to facilitate porting
18025  to other MCUs, although some model specific assembler optimizations are
18026  used.
18027  The following files contain the described routines, all of them can be
18028  found in <installdir>/share/sdcc/lib.
18029 \newline
18030
18031 \end_layout
18032
18033 \begin_layout Standard
18034 \align center
18035 \begin_inset Tabular
18036 <lyxtabular version="3" rows="11" columns="2">
18037 <features>
18038 <column alignment="left" valignment="top" leftline="true" width="0">
18039 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18040 <row topline="true" bottomline="true">
18041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18042 \begin_inset Text
18043
18044 \begin_layout Standard
18045
18046 \series bold
18047 Function
18048 \end_layout
18049
18050 \end_inset
18051 </cell>
18052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18053 \begin_inset Text
18054
18055 \begin_layout Standard
18056
18057 \series bold
18058 Description
18059 \end_layout
18060
18061 \end_inset
18062 </cell>
18063 </row>
18064 <row topline="true">
18065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18066 \begin_inset Text
18067
18068 \begin_layout Standard
18069 _mulint.c 
18070 \end_layout
18071
18072 \end_inset
18073 </cell>
18074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18075 \begin_inset Text
18076
18077 \begin_layout Standard
18078 16 bit multiplication
18079 \end_layout
18080
18081 \end_inset
18082 </cell>
18083 </row>
18084 <row topline="true">
18085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18086 \begin_inset Text
18087
18088 \begin_layout Standard
18089 _divsint.c 
18090 \end_layout
18091
18092 \end_inset
18093 </cell>
18094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18095 \begin_inset Text
18096
18097 \begin_layout Standard
18098  signed 16 bit division (calls _divuint)
18099 \end_layout
18100
18101 \end_inset
18102 </cell>
18103 </row>
18104 <row topline="true">
18105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18106 \begin_inset Text
18107
18108 \begin_layout Standard
18109 _divuint.c 
18110 \end_layout
18111
18112 \end_inset
18113 </cell>
18114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18115 \begin_inset Text
18116
18117 \begin_layout Standard
18118  unsigned 16 bit division
18119 \end_layout
18120
18121 \end_inset
18122 </cell>
18123 </row>
18124 <row topline="true">
18125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18126 \begin_inset Text
18127
18128 \begin_layout Standard
18129 _modsint.c
18130 \end_layout
18131
18132 \end_inset
18133 </cell>
18134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18135 \begin_inset Text
18136
18137 \begin_layout Standard
18138 signed 16 bit modulus (calls _moduint)
18139 \end_layout
18140
18141 \end_inset
18142 </cell>
18143 </row>
18144 <row topline="true">
18145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18146 \begin_inset Text
18147
18148 \begin_layout Standard
18149 _moduint.c
18150 \end_layout
18151
18152 \end_inset
18153 </cell>
18154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18155 \begin_inset Text
18156
18157 \begin_layout Standard
18158 unsigned 16 bit modulus
18159 \end_layout
18160
18161 \end_inset
18162 </cell>
18163 </row>
18164 <row topline="true">
18165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18166 \begin_inset Text
18167
18168 \begin_layout Standard
18169 _mullong.c
18170 \end_layout
18171
18172 \end_inset
18173 </cell>
18174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18175 \begin_inset Text
18176
18177 \begin_layout Standard
18178 32 bit multiplication
18179 \end_layout
18180
18181 \end_inset
18182 </cell>
18183 </row>
18184 <row topline="true">
18185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18186 \begin_inset Text
18187
18188 \begin_layout Standard
18189 _divslong.c 
18190 \end_layout
18191
18192 \end_inset
18193 </cell>
18194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18195 \begin_inset Text
18196
18197 \begin_layout Standard
18198  signed 32 division (calls _divulong)
18199 \end_layout
18200
18201 \end_inset
18202 </cell>
18203 </row>
18204 <row topline="true">
18205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18206 \begin_inset Text
18207
18208 \begin_layout Standard
18209 _divulong.c 
18210 \end_layout
18211
18212 \end_inset
18213 </cell>
18214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18215 \begin_inset Text
18216
18217 \begin_layout Standard
18218 unsigned 32 division
18219 \end_layout
18220
18221 \end_inset
18222 </cell>
18223 </row>
18224 <row topline="true">
18225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18226 \begin_inset Text
18227
18228 \begin_layout Standard
18229 _modslong.c
18230 \end_layout
18231
18232 \end_inset
18233 </cell>
18234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18235 \begin_inset Text
18236
18237 \begin_layout Standard
18238  signed 32 bit modulus (calls _modulong)
18239 \end_layout
18240
18241 \end_inset
18242 </cell>
18243 </row>
18244 <row topline="true" bottomline="true">
18245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18246 \begin_inset Text
18247
18248 \begin_layout Standard
18249 _modulong.c
18250 \end_layout
18251
18252 \end_inset
18253 </cell>
18254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18255 \begin_inset Text
18256
18257 \begin_layout Standard
18258 unsigned 32 bit modulus
18259 \end_layout
18260
18261 \end_inset
18262 </cell>
18263 </row>
18264 </lyxtabular>
18265
18266 \end_inset
18267
18268
18269 \newline
18270
18271 \end_layout
18272
18273 \begin_layout Standard
18274 Since they are compiled as 
18275 \emph on
18276 non-reentrant
18277 \emph default
18278
18279 \begin_inset LatexCommand \index{reentrant}
18280
18281 \end_inset
18282
18283 , interrupt
18284 \begin_inset LatexCommand \index{interrupt}
18285
18286 \end_inset
18287
18288  service routines should not do any of the above operations.
18289  If this is unavoidable then the above routines will need to be compiled
18290  with the 
18291 \emph on
18292 -
18293 \begin_inset ERT
18294 status collapsed
18295
18296 \begin_layout Standard
18297
18298
18299 \backslash
18300 /
18301 \end_layout
18302
18303 \end_inset
18304
18305 -stack-auto
18306 \begin_inset LatexCommand \index{-\/-stack-auto}
18307
18308 \end_inset
18309
18310
18311 \emph default
18312  option, after which the source program will have to be compiled with 
18313 \emph on
18314 -
18315 \begin_inset ERT
18316 status collapsed
18317
18318 \begin_layout Standard
18319
18320
18321 \backslash
18322 /
18323 \end_layout
18324
18325 \end_inset
18326
18327 -int-long-reent
18328 \begin_inset LatexCommand \index{-\/-int-long-reent}
18329
18330 \end_inset
18331
18332
18333 \emph default
18334  option.
18335  Notice that you don't have to call these routines directly.
18336  The compiler will use them automatically every time an integer operation
18337  is required.
18338 \end_layout
18339
18340 \begin_layout Section
18341 Floating Point Support
18342 \begin_inset LatexCommand \index{Floating point support}
18343
18344 \end_inset
18345
18346
18347 \end_layout
18348
18349 \begin_layout Standard
18350 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18351  The floating point support routines are derived from gcc's floatlib.c and
18352  consist of the following routines:
18353 \newline
18354
18355 \end_layout
18356
18357 \begin_layout Standard
18358 \align center
18359
18360 \size footnotesize
18361 \begin_inset Tabular
18362 <lyxtabular version="3" rows="17" columns="2">
18363 <features>
18364 <column alignment="left" valignment="top" leftline="true" width="0">
18365 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18366 <row topline="true" bottomline="true">
18367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18368 \begin_inset Text
18369
18370 \begin_layout Standard
18371
18372 \family roman
18373 \series medium
18374 \shape up
18375 \size normal
18376 \emph off
18377 \bar no
18378 \noun off
18379 \color none
18380 Function 
18381 \end_layout
18382
18383 \end_inset
18384 </cell>
18385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18386 \begin_inset Text
18387
18388 \begin_layout Standard
18389 Description
18390 \end_layout
18391
18392 \end_inset
18393 </cell>
18394 </row>
18395 <row topline="true">
18396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18397 \begin_inset Text
18398
18399 \begin_layout Standard
18400
18401 \family roman
18402 \series medium
18403 \shape up
18404 \size normal
18405 \emph off
18406 \bar no
18407 \noun off
18408 \color none
18409 _fsadd.c
18410 \end_layout
18411
18412 \end_inset
18413 </cell>
18414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18415 \begin_inset Text
18416
18417 \begin_layout Standard
18418
18419 \family roman
18420 \series medium
18421 \shape up
18422 \size normal
18423 \emph off
18424 \bar no
18425 \noun off
18426 \color none
18427 add floating point numbers
18428 \end_layout
18429
18430 \end_inset
18431 </cell>
18432 </row>
18433 <row topline="true">
18434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18435 \begin_inset Text
18436
18437 \begin_layout Standard
18438
18439 \family roman
18440 \series medium
18441 \shape up
18442 \size normal
18443 \emph off
18444 \bar no
18445 \noun off
18446 \color none
18447 _fssub.c 
18448 \end_layout
18449
18450 \end_inset
18451 </cell>
18452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18453 \begin_inset Text
18454
18455 \begin_layout Standard
18456
18457 \family roman
18458 \series medium
18459 \shape up
18460 \size normal
18461 \emph off
18462 \bar no
18463 \noun off
18464 \color none
18465 subtract floating point numbers 
18466 \end_layout
18467
18468 \end_inset
18469 </cell>
18470 </row>
18471 <row topline="true">
18472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18473 \begin_inset Text
18474
18475 \begin_layout Standard
18476
18477 \family roman
18478 \series medium
18479 \shape up
18480 \size normal
18481 \emph off
18482 \bar no
18483 \noun off
18484 \color none
18485 _fsdiv.c 
18486 \end_layout
18487
18488 \end_inset
18489 </cell>
18490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18491 \begin_inset Text
18492
18493 \begin_layout Standard
18494
18495 \family roman
18496 \series medium
18497 \shape up
18498 \size normal
18499 \emph off
18500 \bar no
18501 \noun off
18502 \color none
18503 divide floating point numbers 
18504 \end_layout
18505
18506 \end_inset
18507 </cell>
18508 </row>
18509 <row topline="true">
18510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18511 \begin_inset Text
18512
18513 \begin_layout Standard
18514
18515 \family roman
18516 \series medium
18517 \shape up
18518 \size normal
18519 \emph off
18520 \bar no
18521 \noun off
18522 \color none
18523 _fsmul.c 
18524 \end_layout
18525
18526 \end_inset
18527 </cell>
18528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18529 \begin_inset Text
18530
18531 \begin_layout Standard
18532
18533 \family roman
18534 \series medium
18535 \shape up
18536 \size normal
18537 \emph off
18538 \bar no
18539 \noun off
18540 \color none
18541 multiply floating point numbers 
18542 \end_layout
18543
18544 \end_inset
18545 </cell>
18546 </row>
18547 <row topline="true">
18548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18549 \begin_inset Text
18550
18551 \begin_layout Standard
18552
18553 \family roman
18554 \series medium
18555 \shape up
18556 \size normal
18557 \emph off
18558 \bar no
18559 \noun off
18560 \color none
18561 _fs2uchar.c
18562 \end_layout
18563
18564 \end_inset
18565 </cell>
18566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18567 \begin_inset Text
18568
18569 \begin_layout Standard
18570
18571 \family roman
18572 \series medium
18573 \shape up
18574 \size normal
18575 \emph off
18576 \bar no
18577 \noun off
18578 \color none
18579 convert floating point to unsigned char
18580 \end_layout
18581
18582 \end_inset
18583 </cell>
18584 </row>
18585 <row topline="true">
18586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18587 \begin_inset Text
18588
18589 \begin_layout Standard
18590
18591 \family roman
18592 \series medium
18593 \shape up
18594 \size normal
18595 \emph off
18596 \bar no
18597 \noun off
18598 \color none
18599 _fs2char.c
18600 \end_layout
18601
18602 \end_inset
18603 </cell>
18604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18605 \begin_inset Text
18606
18607 \begin_layout Standard
18608
18609 \family roman
18610 \series medium
18611 \shape up
18612 \size normal
18613 \emph off
18614 \bar no
18615 \noun off
18616 \color none
18617 convert floating point to signed char
18618 \end_layout
18619
18620 \end_inset
18621 </cell>
18622 </row>
18623 <row topline="true">
18624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18625 \begin_inset Text
18626
18627 \begin_layout Standard
18628
18629 \family roman
18630 \series medium
18631 \shape up
18632 \size normal
18633 \emph off
18634 \bar no
18635 \noun off
18636 \color none
18637 _fs2uint.c
18638 \end_layout
18639
18640 \end_inset
18641 </cell>
18642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18643 \begin_inset Text
18644
18645 \begin_layout Standard
18646
18647 \family roman
18648 \series medium
18649 \shape up
18650 \size normal
18651 \emph off
18652 \bar no
18653 \noun off
18654 \color none
18655 convert floating point to unsigned int
18656 \end_layout
18657
18658 \end_inset
18659 </cell>
18660 </row>
18661 <row topline="true">
18662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18663 \begin_inset Text
18664
18665 \begin_layout Standard
18666
18667 \family roman
18668 \series medium
18669 \shape up
18670 \size normal
18671 \emph off
18672 \bar no
18673 \noun off
18674 \color none
18675 _fs2int.c
18676 \end_layout
18677
18678 \end_inset
18679 </cell>
18680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18681 \begin_inset Text
18682
18683 \begin_layout Standard
18684
18685 \family roman
18686 \series medium
18687 \shape up
18688 \size normal
18689 \emph off
18690 \bar no
18691 \noun off
18692 \color none
18693 convert floating point to signed int
18694 \end_layout
18695
18696 \end_inset
18697 </cell>
18698 </row>
18699 <row topline="true">
18700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18701 \begin_inset Text
18702
18703 \begin_layout Standard
18704
18705 \family roman
18706 \series medium
18707 \shape up
18708 \size normal
18709 \emph off
18710 \bar no
18711 \noun off
18712 \color none
18713 _fs2ulong.
18714 \family default
18715 \series default
18716 \shape default
18717 \size default
18718 \emph default
18719 \bar default
18720 \noun default
18721 c
18722 \end_layout
18723
18724 \end_inset
18725 </cell>
18726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18727 \begin_inset Text
18728
18729 \begin_layout Standard
18730
18731 \family roman
18732 \series medium
18733 \shape up
18734 \size normal
18735 \emph off
18736 \bar no
18737 \noun off
18738 \color none
18739 convert floating point to unsigned long
18740 \end_layout
18741
18742 \end_inset
18743 </cell>
18744 </row>
18745 <row topline="true">
18746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18747 \begin_inset Text
18748
18749 \begin_layout Standard
18750
18751 \family roman
18752 \series medium
18753 \shape up
18754 \size normal
18755 \emph off
18756 \bar no
18757 \noun off
18758 \color none
18759 _fs2long.c
18760 \end_layout
18761
18762 \end_inset
18763 </cell>
18764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18765 \begin_inset Text
18766
18767 \begin_layout Standard
18768
18769 \family roman
18770 \series medium
18771 \shape up
18772 \size normal
18773 \emph off
18774 \bar no
18775 \noun off
18776 \color none
18777 convert floating point to signed long
18778 \end_layout
18779
18780 \end_inset
18781 </cell>
18782 </row>
18783 <row topline="true">
18784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18785 \begin_inset Text
18786
18787 \begin_layout Standard
18788
18789 \family roman
18790 \series medium
18791 \shape up
18792 \size normal
18793 \emph off
18794 \bar no
18795 \noun off
18796 \color none
18797 _uchar2fs.c
18798 \end_layout
18799
18800 \end_inset
18801 </cell>
18802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18803 \begin_inset Text
18804
18805 \begin_layout Standard
18806
18807 \family roman
18808 \series medium
18809 \shape up
18810 \size normal
18811 \emph off
18812 \bar no
18813 \noun off
18814 \color none
18815 convert unsigned char to floating point
18816 \end_layout
18817
18818 \end_inset
18819 </cell>
18820 </row>
18821 <row topline="true">
18822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18823 \begin_inset Text
18824
18825 \begin_layout Standard
18826
18827 \family roman
18828 \series medium
18829 \shape up
18830 \size normal
18831 \emph off
18832 \bar no
18833 \noun off
18834 \color none
18835 _char2fs.c
18836 \end_layout
18837
18838 \end_inset
18839 </cell>
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18841 \begin_inset Text
18842
18843 \begin_layout Standard
18844
18845 \family roman
18846 \series medium
18847 \shape up
18848 \size normal
18849 \emph off
18850 \bar no
18851 \noun off
18852 \color none
18853 convert char to floating point number
18854 \end_layout
18855
18856 \end_inset
18857 </cell>
18858 </row>
18859 <row topline="true">
18860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18861 \begin_inset Text
18862
18863 \begin_layout Standard
18864
18865 \family roman
18866 \series medium
18867 \shape up
18868 \size normal
18869 \emph off
18870 \bar no
18871 \noun off
18872 \color none
18873 _uint2fs.c
18874 \end_layout
18875
18876 \end_inset
18877 </cell>
18878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18879 \begin_inset Text
18880
18881 \begin_layout Standard
18882
18883 \family roman
18884 \series medium
18885 \shape up
18886 \size normal
18887 \emph off
18888 \bar no
18889 \noun off
18890 \color none
18891 convert unsigned int to floating point
18892 \end_layout
18893
18894 \end_inset
18895 </cell>
18896 </row>
18897 <row topline="true">
18898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18899 \begin_inset Text
18900
18901 \begin_layout Standard
18902
18903 \family roman
18904 \series medium
18905 \shape up
18906 \size normal
18907 \emph off
18908 \bar no
18909 \noun off
18910 \color none
18911 _int2fs.c
18912 \end_layout
18913
18914 \end_inset
18915 </cell>
18916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18917 \begin_inset Text
18918
18919 \begin_layout Standard
18920
18921 \family roman
18922 \series medium
18923 \shape up
18924 \size normal
18925 \emph off
18926 \bar no
18927 \noun off
18928 \color none
18929 convert int to floating point numbers
18930 \end_layout
18931
18932 \end_inset
18933 </cell>
18934 </row>
18935 <row topline="true">
18936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18937 \begin_inset Text
18938
18939 \begin_layout Standard
18940
18941 \family roman
18942 \series medium
18943 \shape up
18944 \size normal
18945 \emph off
18946 \bar no
18947 \noun off
18948 \color none
18949 _ulong2fs.c
18950 \end_layout
18951
18952 \end_inset
18953 </cell>
18954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18955 \begin_inset Text
18956
18957 \begin_layout Standard
18958
18959 \family roman
18960 \series medium
18961 \shape up
18962 \size normal
18963 \emph off
18964 \bar no
18965 \noun off
18966 \color none
18967 convert unsigned long to floating point number
18968 \end_layout
18969
18970 \end_inset
18971 </cell>
18972 </row>
18973 <row topline="true" bottomline="true">
18974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18975 \begin_inset Text
18976
18977 \begin_layout Standard
18978
18979 \family roman
18980 \series medium
18981 \shape up
18982 \size normal
18983 \emph off
18984 \bar no
18985 \noun off
18986 \color none
18987 _long2fs.c
18988 \end_layout
18989
18990 \end_inset
18991 </cell>
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18993 \begin_inset Text
18994
18995 \begin_layout Standard
18996
18997 \family roman
18998 \series medium
18999 \shape up
19000 \size normal
19001 \emph off
19002 \bar no
19003 \noun off
19004 \color none
19005 convert long to floating point number
19006 \end_layout
19007
19008 \end_inset
19009 </cell>
19010 </row>
19011 </lyxtabular>
19012
19013 \end_inset
19014
19015
19016 \newline
19017
19018 \end_layout
19019
19020 \begin_layout Standard
19021 These support routines are developed in ANSI-C so there is room for space
19022  and speed improvement
19023 \begin_inset Foot
19024 status open
19025
19026 \begin_layout Standard
19027 These floating point routines (
19028 \emph on
19029 not
19030 \emph default
19031  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19032  
19033 \end_layout
19034
19035 \end_inset
19036
19037 .
19038  Note if all these routines are used simultaneously the data space might
19039  overflow.
19040  For serious floating point usage the large model might be needed.
19041  Also notice that you don't have to call this routines directly.
19042  The compiler will use them automatically every time a floating point operation
19043  is required.
19044 \begin_inset VSpace bigskip
19045 \end_inset
19046
19047
19048 \end_layout
19049
19050 \begin_layout Section
19051 Library Routines
19052 \begin_inset LatexCommand \index{Libraries}
19053
19054 \end_inset
19055
19056
19057 \end_layout
19058
19059 \begin_layout Standard
19060
19061 \emph on
19062 <pending: this is messy and incomplete - a little more information is in
19063  sdcc/doc/libdoc.txt
19064 \emph default
19065  >
19066 \end_layout
19067
19068 \begin_layout Subsection
19069 Compiler support routines (_gptrget, _mulint etc.)
19070 \end_layout
19071
19072 \begin_layout Subsection
19073 Stdclib functions (puts, printf, strcat etc.)
19074 \end_layout
19075
19076 \begin_layout Subsubsection
19077 <stdio.h>
19078 \end_layout
19079
19080 \begin_layout Paragraph
19081 getchar(), putchar()
19082 \end_layout
19083
19084 \begin_layout Standard
19085 \begin_inset LatexCommand \index{<stdio.h>}
19086
19087 \end_inset
19088
19089 As usual on embedded systems you have to provide your own 
19090 \family typewriter
19091 getchar()
19092 \begin_inset LatexCommand \index{getchar()}
19093
19094 \end_inset
19095
19096  
19097 \family default
19098 and 
19099 \family typewriter
19100 putchar()
19101 \begin_inset LatexCommand \index{putchar()}
19102
19103 \end_inset
19104
19105
19106 \family default
19107  routines.
19108  SDCC does not know whether the system connects to a serial line with or
19109  without handshake, LCD, keyboard or other device.
19110  And whether a 
19111 \family typewriter
19112 lf
19113 \family default
19114  to 
19115 \family typewriter
19116 crlf
19117 \family default
19118  conversion within 
19119 \family typewriter
19120 putchar()
19121 \family default
19122  is intended.
19123  You'll find examples for serial routines f.e.
19124  in sdcc/device/lib.
19125  For the mcs51 this minimalistic polling 
19126 \family typewriter
19127 putchar()
19128 \family default
19129  routine might be a start:
19130 \end_layout
19131
19132 \begin_layout Verse
19133
19134 \family typewriter
19135 void putchar (char c) { 
19136 \newline
19137 \InsetSpace ~
19138 \InsetSpace ~
19139 \InsetSpace ~
19140 \InsetSpace ~
19141 while (!TI)\InsetSpace ~
19142 \InsetSpace ~
19143 \InsetSpace ~
19144  /* assumes UART is initialized */
19145 \newline
19146 \InsetSpace ~
19147 \InsetSpace ~
19148 \InsetSpace ~
19149 \InsetSpace ~
19150 \InsetSpace ~
19151 \InsetSpace ~
19152 \InsetSpace ~
19153 \InsetSpace ~
19154 ;
19155 \newline
19156 \InsetSpace ~
19157 \InsetSpace ~
19158 \InsetSpace ~
19159 \InsetSpace ~
19160 TI
19161  = 0;
19162 \newline
19163 \InsetSpace ~
19164 \InsetSpace ~
19165 \InsetSpace ~
19166 \InsetSpace ~
19167 SBUF = c;
19168 \newline
19169 }
19170 \end_layout
19171
19172 \begin_layout Paragraph
19173 printf()
19174 \end_layout
19175
19176 \begin_layout Standard
19177 The default
19178 \family typewriter
19179  printf()
19180 \begin_inset LatexCommand \index{printf()}
19181
19182 \end_inset
19183
19184
19185 \family default
19186  implementation in
19187 \family typewriter
19188  printf_large.c
19189 \family default
19190  does not support float (except on ds390).
19191  To enable this recompile it with the option 
19192 \emph on
19193 -
19194 \begin_inset ERT
19195 status collapsed
19196
19197 \begin_layout Standard
19198
19199
19200 \backslash
19201 /
19202 \end_layout
19203
19204 \end_inset
19205
19206 DUSE_FLOATS=1
19207 \begin_inset LatexCommand \index{USE\_FLOATS}
19208
19209 \end_inset
19210
19211
19212 \emph default
19213  on the command line.
19214  Use
19215 \emph on
19216  -
19217 \begin_inset ERT
19218 status collapsed
19219
19220 \begin_layout Standard
19221
19222
19223 \backslash
19224 /
19225 \end_layout
19226
19227 \end_inset
19228
19229 -model-large
19230 \begin_inset LatexCommand \index{-\/-model-large}
19231
19232 \end_inset
19233
19234
19235 \emph default
19236  for the mcs51 port, since this uses a lot of memory.
19237 \end_layout
19238
19239 \begin_layout Standard
19240 If you're short on code memory you might want to use 
19241 \family typewriter
19242 printf_small()
19243 \begin_inset LatexCommand \index{printf\_small()}
19244
19245 \end_inset
19246
19247
19248 \family default
19249  
19250 \emph on
19251 instead
19252 \emph default
19253  of
19254 \family typewriter
19255  printf().
19256
19257 \family default
19258  For the mcs51 there additionally are assembly versions 
19259 \family typewriter
19260 printf_tiny()
19261 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19262
19263 \end_inset
19264
19265
19266 \family default
19267  (subset of printf using less than 270 bytes) and 
19268 \family typewriter
19269 printf_fast()
19270 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19271
19272 \end_inset
19273
19274  
19275 \family default
19276 and
19277 \family typewriter
19278  printf_fast_f()
19279 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19280
19281 \end_inset
19282
19283
19284 \family default
19285  (floating-point aware version of printf_fast) which should fit the requirements
19286  of many embedded systems (printf_fast() can be customized by unsetting
19287  #defines to 
19288 \emph on
19289 not
19290 \emph default
19291  support long variables and field widths).
19292  Be sure to use only one of these printf options within a project.
19293 \newline
19294
19295 \end_layout
19296
19297 \begin_layout Standard
19298 Feature matrix of different 
19299 \emph on
19300 printf
19301 \emph default
19302  options on mcs51.
19303 \end_layout
19304
19305 \begin_layout Standard
19306 \begin_inset Tabular
19307 <lyxtabular version="3" rows="14" columns="7">
19308 <features islongtable="true">
19309 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19310 <column alignment="center" valignment="top" leftline="true" width="0">
19311 <column alignment="center" valignment="top" leftline="true" width="12col%">
19312 <column alignment="center" valignment="top" leftline="true" width="10col%">
19313 <column alignment="center" valignment="top" leftline="true" width="0">
19314 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19315 <column alignment="center" valignment="top" rightline="true" width="0">
19316 <row topline="true" bottomline="true" endhead="true">
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19318 \begin_inset Text
19319
19320 \begin_layout Standard
19321
19322 \series bold
19323 \size large
19324 mcs51
19325 \end_layout
19326
19327 \end_inset
19328 </cell>
19329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19330 \begin_inset Text
19331
19332 \begin_layout Standard
19333 printf
19334 \begin_inset LatexCommand \index{printf}
19335
19336 \end_inset
19337
19338
19339 \end_layout
19340
19341 \end_inset
19342 </cell>
19343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19344 \begin_inset Text
19345
19346 \begin_layout Standard
19347 printf 
19348 \size scriptsize
19349 USE_FLOATS=1
19350 \end_layout
19351
19352 \end_inset
19353 </cell>
19354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19355 \begin_inset Text
19356
19357 \begin_layout Standard
19358 printf_small
19359 \end_layout
19360
19361 \end_inset
19362 </cell>
19363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19364 \begin_inset Text
19365
19366 \begin_layout Standard
19367 printf_fast
19368 \end_layout
19369
19370 \end_inset
19371 </cell>
19372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19373 \begin_inset Text
19374
19375 \begin_layout Standard
19376 printf_fast_f
19377 \end_layout
19378
19379 \end_inset
19380 </cell>
19381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19382 \begin_inset Text
19383
19384 \begin_layout Standard
19385 printf_tiny
19386 \end_layout
19387
19388 \end_inset
19389 </cell>
19390 </row>
19391 <row topline="true" endhead="true">
19392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19393 \begin_inset Text
19394
19395 \begin_layout Standard
19396 filename
19397 \end_layout
19398
19399 \end_inset
19400 </cell>
19401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19402 \begin_inset Text
19403
19404 \begin_layout Standard
19405
19406 \size scriptsize
19407 printf_large.c
19408 \end_layout
19409
19410 \end_inset
19411 </cell>
19412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19413 \begin_inset Text
19414
19415 \begin_layout Standard
19416
19417 \size scriptsize
19418 printf_large.c
19419 \end_layout
19420
19421 \end_inset
19422 </cell>
19423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19424 \begin_inset Text
19425
19426 \begin_layout Standard
19427
19428 \size scriptsize
19429 printfl.c
19430 \end_layout
19431
19432 \end_inset
19433 </cell>
19434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19435 \begin_inset Text
19436
19437 \begin_layout Standard
19438
19439 \size scriptsize
19440 printf_fast.c
19441 \end_layout
19442
19443 \end_inset
19444 </cell>
19445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19446 \begin_inset Text
19447
19448 \begin_layout Standard
19449
19450 \size scriptsize
19451 printf_fast_f.c
19452 \end_layout
19453
19454 \end_inset
19455 </cell>
19456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19457 \begin_inset Text
19458
19459 \begin_layout Standard
19460
19461 \size scriptsize
19462 printf_tiny.c
19463 \end_layout
19464
19465 \end_inset
19466 </cell>
19467 </row>
19468 <row topline="true" endhead="true">
19469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19470 \begin_inset Text
19471
19472 \begin_layout Standard
19473 \begin_inset Quotes sld
19474 \end_inset
19475
19476 Hello World
19477 \begin_inset Quotes srd
19478 \end_inset
19479
19480  size
19481 \end_layout
19482
19483 \begin_layout Standard
19484 small / large
19485 \end_layout
19486
19487 \end_inset
19488 </cell>
19489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19490 \begin_inset Text
19491
19492 \begin_layout Standard
19493 1.7k / 2.4k
19494 \end_layout
19495
19496 \end_inset
19497 </cell>
19498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19499 \begin_inset Text
19500
19501 \begin_layout Standard
19502 4.3k / 5.6k
19503 \end_layout
19504
19505 \end_inset
19506 </cell>
19507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19508 \begin_inset Text
19509
19510 \begin_layout Standard
19511 1.2k / 1.8k
19512 \end_layout
19513
19514 \end_inset
19515 </cell>
19516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19517 \begin_inset Text
19518
19519 \begin_layout Standard
19520 1.3k / 1.3k
19521 \end_layout
19522
19523 \end_inset
19524 </cell>
19525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19526 \begin_inset Text
19527
19528 \begin_layout Standard
19529 1.9k / 1.9k
19530 \end_layout
19531
19532 \end_inset
19533 </cell>
19534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19535 \begin_inset Text
19536
19537 \begin_layout Standard
19538 0.44k / 0.44k
19539 \end_layout
19540
19541 \end_inset
19542 </cell>
19543 </row>
19544 <row topline="true" endhead="true">
19545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19546 \begin_inset Text
19547
19548 \begin_layout Standard
19549 code size
19550 \end_layout
19551
19552 \begin_layout Standard
19553 small / large
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 1.4k / 2.0k
19563 \end_layout
19564
19565 \end_inset
19566 </cell>
19567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19568 \begin_inset Text
19569
19570 \begin_layout Standard
19571 2.8k / 3.7k
19572 \end_layout
19573
19574 \end_inset
19575 </cell>
19576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19577 \begin_inset Text
19578
19579 \begin_layout Standard
19580 0.45k / 0.47k (+ _ltoa)
19581 \end_layout
19582
19583 \end_inset
19584 </cell>
19585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19586 \begin_inset Text
19587
19588 \begin_layout Standard
19589 1.2k / 1.2k
19590 \end_layout
19591
19592 \end_inset
19593 </cell>
19594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19595 \begin_inset Text
19596
19597 \begin_layout Standard
19598 1.6k / 1.6k
19599 \end_layout
19600
19601 \end_inset
19602 </cell>
19603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19604 \begin_inset Text
19605
19606 \begin_layout Standard
19607 0.26k / 0.26k
19608 \end_layout
19609
19610 \end_inset
19611 </cell>
19612 </row>
19613 <row topline="true">
19614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19615 \begin_inset Text
19616
19617 \begin_layout Standard
19618 formats
19619 \end_layout
19620
19621 \end_inset
19622 </cell>
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19624 \begin_inset Text
19625
19626 \begin_layout Standard
19627 cdi
19628 \emph on
19629 o
19630 \emph default
19631 psux
19632 \end_layout
19633
19634 \end_inset
19635 </cell>
19636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19637 \begin_inset Text
19638
19639 \begin_layout Standard
19640
19641 \family roman
19642 \series medium
19643 \shape up
19644 \size normal
19645 \emph off
19646 \bar no
19647 \noun off
19648 \color none
19649 cd
19650 \family default
19651 \series default
19652 \shape default
19653 \size default
19654 \emph default
19655 \bar default
19656 \noun default
19657 f
19658 \family roman
19659 \series medium
19660 \shape up
19661 \size normal
19662 \emph off
19663 \bar no
19664 \noun off
19665 i
19666 \family default
19667 \series default
19668 \shape default
19669 \size default
19670 \emph on
19671 \bar default
19672 \noun default
19673 o
19674 \family roman
19675 \series medium
19676 \shape up
19677 \size normal
19678 \emph off
19679 \bar no
19680 \noun off
19681 psux
19682 \end_layout
19683
19684 \end_inset
19685 </cell>
19686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19687 \begin_inset Text
19688
19689 \begin_layout Standard
19690 c
19691 \family roman
19692 \series medium
19693 \shape up
19694 \size normal
19695 \emph off
19696 \bar no
19697 \noun off
19698 \color none
19699 d
19700 \family default
19701 \series default
19702 \shape default
19703 \size default
19704 \emph on
19705 \bar default
19706 \noun default
19707 o
19708 \family roman
19709 \series medium
19710 \shape up
19711 \size normal
19712 \emph off
19713 \bar no
19714 \noun off
19715 s
19716 \family default
19717 \series default
19718 \shape default
19719 \size default
19720 \emph default
19721 \bar default
19722 \noun default
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 cdsux
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 cdfsux
19742 \end_layout
19743
19744 \end_inset
19745 </cell>
19746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19747 \begin_inset Text
19748
19749 \begin_layout Standard
19750 cdsux
19751 \end_layout
19752
19753 \end_inset
19754 </cell>
19755 </row>
19756 <row topline="true">
19757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19758 \begin_inset Text
19759
19760 \begin_layout Standard
19761 long (32 bit) support
19762 \end_layout
19763
19764 \end_inset
19765 </cell>
19766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19767 \begin_inset Text
19768
19769 \begin_layout Standard
19770 x
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 x
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 x
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 x
19798 \end_layout
19799
19800 \end_inset
19801 </cell>
19802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19803 \begin_inset Text
19804
19805 \begin_layout Standard
19806
19807 \family roman
19808 \series medium
19809 \shape up
19810 \size normal
19811 \emph off
19812 \bar no
19813 \noun off
19814 \color none
19815 x
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 byte arguments on stack
19836 \end_layout
19837
19838 \end_inset
19839 </cell>
19840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19841 \begin_inset Text
19842
19843 \begin_layout Standard
19844 b
19845 \end_layout
19846
19847 \end_inset
19848 </cell>
19849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19850 \begin_inset Text
19851
19852 \begin_layout Standard
19853 b
19854 \end_layout
19855
19856 \end_inset
19857 </cell>
19858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19859 \begin_inset Text
19860
19861 \begin_layout Standard
19862 -
19863 \end_layout
19864
19865 \end_inset
19866 </cell>
19867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19868 \begin_inset Text
19869
19870 \begin_layout Standard
19871 -
19872 \end_layout
19873
19874 \end_inset
19875 </cell>
19876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19877 \begin_inset Text
19878
19879 \begin_layout Standard
19880 -
19881 \end_layout
19882
19883 \end_inset
19884 </cell>
19885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19886 \begin_inset Text
19887
19888 \begin_layout Standard
19889 -
19890 \end_layout
19891
19892 \end_inset
19893 </cell>
19894 </row>
19895 <row topline="true">
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19897 \begin_inset Text
19898
19899 \begin_layout Standard
19900 float format
19901 \begin_inset LatexCommand \index{Floating point support}
19902
19903 \end_inset
19904
19905
19906 \end_layout
19907
19908 \end_inset
19909 </cell>
19910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19911 \begin_inset Text
19912
19913 \begin_layout Standard
19914 -
19915 \end_layout
19916
19917 \end_inset
19918 </cell>
19919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19920 \begin_inset Text
19921
19922 \begin_layout Standard
19923 %f
19924 \end_layout
19925
19926 \end_inset
19927 </cell>
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19929 \begin_inset Text
19930
19931 \begin_layout Standard
19932 -
19933 \end_layout
19934
19935 \end_inset
19936 </cell>
19937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19938 \begin_inset Text
19939
19940 \begin_layout Standard
19941 -
19942 \end_layout
19943
19944 \end_inset
19945 </cell>
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19947 \begin_inset Text
19948
19949 \begin_layout Standard
19950 %f
19951 \begin_inset Foot
19952 status collapsed
19953
19954 \begin_layout Standard
19955 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19956 \end_layout
19957
19958 \end_inset
19959
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">
19976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19977 \begin_inset Text
19978
19979 \begin_layout Standard
19980 float formats %e %g
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 -
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 -
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 -
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 -
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 topline="true" bottomline="true">
20041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20042 \begin_inset Text
20043
20044 \begin_layout Standard
20045 field width
20046 \end_layout
20047
20048 \end_inset
20049 </cell>
20050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20051 \begin_inset Text
20052
20053 \begin_layout Standard
20054 x
20055 \end_layout
20056
20057 \end_inset
20058 </cell>
20059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20060 \begin_inset Text
20061
20062 \begin_layout Standard
20063 x
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 -
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 x
20082 \end_layout
20083
20084 \end_inset
20085 </cell>
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20087 \begin_inset Text
20088
20089 \begin_layout Standard
20090 x
20091 \end_layout
20092
20093 \end_inset
20094 </cell>
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20096 \begin_inset Text
20097
20098 \begin_layout Standard
20099 -
20100 \end_layout
20101
20102 \end_inset
20103 </cell>
20104 </row>
20105 <row bottomline="true">
20106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20107 \begin_inset Text
20108
20109 \begin_layout Standard
20110 string speed
20111 \begin_inset Foot
20112 status collapsed
20113
20114 \begin_layout Standard
20115 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20116 \backslash
20117 r', '
20118 \backslash
20119 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20120 \end_layout
20121
20122 \end_inset
20123
20124 ,
20125 \end_layout
20126
20127 \begin_layout Standard
20128 small / large
20129 \end_layout
20130
20131 \end_inset
20132 </cell>
20133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20134 \begin_inset Text
20135
20136 \begin_layout Standard
20137 1.52 / 2.59 ms
20138 \end_layout
20139
20140 \end_inset
20141 </cell>
20142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20143 \begin_inset Text
20144
20145 \begin_layout Standard
20146 1.53 / 2.62 ms
20147 \end_layout
20148
20149 \end_inset
20150 </cell>
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20152 \begin_inset Text
20153
20154 \begin_layout Standard
20155 0.92 / 0.93 ms
20156 \end_layout
20157
20158 \end_inset
20159 </cell>
20160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20161 \begin_inset Text
20162
20163 \begin_layout Standard
20164 0.45 / 0.45 ms
20165 \end_layout
20166
20167 \end_inset
20168 </cell>
20169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20170 \begin_inset Text
20171
20172 \begin_layout Standard
20173 0.46 / 0.46 ms
20174 \end_layout
20175
20176 \end_inset
20177 </cell>
20178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20179 \begin_inset Text
20180
20181 \begin_layout Standard
20182 0.45 / 0.45 ms
20183 \end_layout
20184
20185 \end_inset
20186 </cell>
20187 </row>
20188 <row bottomline="true">
20189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20190 \begin_inset Text
20191
20192 \begin_layout Standard
20193 int speed
20194 \begin_inset Foot
20195 status collapsed
20196
20197 \begin_layout Standard
20198 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20199  putchar()
20200 \end_layout
20201
20202 \end_inset
20203
20204 ,
20205 \end_layout
20206
20207 \begin_layout Standard
20208 small / large
20209 \end_layout
20210
20211 \end_inset
20212 </cell>
20213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20214 \begin_inset Text
20215
20216 \begin_layout Standard
20217 3.01 / 3.61 ms
20218 \end_layout
20219
20220 \end_inset
20221 </cell>
20222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20223 \begin_inset Text
20224
20225 \begin_layout Standard
20226 3.01 / 3.61 ms
20227 \end_layout
20228
20229 \end_inset
20230 </cell>
20231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20232 \begin_inset Text
20233
20234 \begin_layout Standard
20235 3.51 / 18.13 ms
20236 \end_layout
20237
20238 \end_inset
20239 </cell>
20240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20241 \begin_inset Text
20242
20243 \begin_layout Standard
20244 0.22 / 0.22 ms
20245 \end_layout
20246
20247 \end_inset
20248 </cell>
20249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20250 \begin_inset Text
20251
20252 \begin_layout Standard
20253 0.23 / 0.23 ms
20254 \end_layout
20255
20256 \end_inset
20257 </cell>
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20259 \begin_inset Text
20260
20261 \begin_layout Standard
20262 0.25 / 0.25 ms
20263 \begin_inset Foot
20264 status collapsed
20265
20266 \begin_layout Standard
20267 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20268 \end_layout
20269
20270 \end_inset
20271
20272
20273 \end_layout
20274
20275 \end_inset
20276 </cell>
20277 </row>
20278 <row bottomline="true">
20279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20280 \begin_inset Text
20281
20282 \begin_layout Standard
20283 long speed
20284 \begin_inset Foot
20285 status collapsed
20286
20287 \begin_layout Standard
20288 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20289  empty putchar()
20290 \end_layout
20291
20292 \end_inset
20293
20294 ,
20295 \end_layout
20296
20297 \begin_layout Standard
20298 small / large
20299 \end_layout
20300
20301 \end_inset
20302 </cell>
20303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20304 \begin_inset Text
20305
20306 \begin_layout Standard
20307 5.37 / 6.31 ms
20308 \end_layout
20309
20310 \end_inset
20311 </cell>
20312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20313 \begin_inset Text
20314
20315 \begin_layout Standard
20316 5.37 / 6.31 ms
20317 \end_layout
20318
20319 \end_inset
20320 </cell>
20321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20322 \begin_inset Text
20323
20324 \begin_layout Standard
20325 8.71 / 40.65 ms
20326 \end_layout
20327
20328 \end_inset
20329 </cell>
20330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20331 \begin_inset Text
20332
20333 \begin_layout Standard
20334 0.40 / 0.40 ms
20335 \end_layout
20336
20337 \end_inset
20338 </cell>
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20340 \begin_inset Text
20341
20342 \begin_layout Standard
20343 0.40 / 0.40 ms
20344 \end_layout
20345
20346 \end_inset
20347 </cell>
20348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20349 \begin_inset Text
20350
20351 \begin_layout Standard
20352 -
20353 \end_layout
20354
20355 \end_inset
20356 </cell>
20357 </row>
20358 <row bottomline="true">
20359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20360 \begin_inset Text
20361
20362 \begin_layout Standard
20363 float speed
20364 \begin_inset Foot
20365 status collapsed
20366
20367 \begin_layout Standard
20368 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20369  empty putchar()
20370 \end_layout
20371
20372 \end_inset
20373
20374 ,
20375 \end_layout
20376
20377 \begin_layout Standard
20378 small / large
20379 \end_layout
20380
20381 \end_inset
20382 </cell>
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20384 \begin_inset Text
20385
20386 \begin_layout Standard
20387 -
20388 \end_layout
20389
20390 \end_inset
20391 </cell>
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20393 \begin_inset Text
20394
20395 \begin_layout Standard
20396 7.49 / 22.47 ms
20397 \end_layout
20398
20399 \end_inset
20400 </cell>
20401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20402 \begin_inset Text
20403
20404 \begin_layout Standard
20405 -
20406 \end_layout
20407
20408 \end_inset
20409 </cell>
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20411 \begin_inset Text
20412
20413 \begin_layout Standard
20414 -
20415 \end_layout
20416
20417 \end_inset
20418 </cell>
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20420 \begin_inset Text
20421
20422 \begin_layout Standard
20423 1.04 / 1.04 ms
20424 \end_layout
20425
20426 \end_inset
20427 </cell>
20428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20429 \begin_inset Text
20430
20431 \begin_layout Standard
20432 -
20433 \end_layout
20434
20435 \end_inset
20436 </cell>
20437 </row>
20438 </lyxtabular>
20439
20440 \end_inset
20441
20442
20443 \end_layout
20444
20445 \begin_layout Subsubsection
20446 <malloc.h>
20447 \begin_inset LatexCommand \index{malloc.h}
20448
20449 \end_inset
20450
20451
20452 \end_layout
20453
20454 \begin_layout Standard
20455 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20456  using dynamic memory allocation
20457 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20458
20459 \end_inset
20460
20461  and a default heap
20462 \begin_inset LatexCommand \index{heap (malloc)}
20463
20464 \end_inset
20465
20466  space of 1024 bytes is provided for malloc to allocate memory from.
20467  If you need a different heap size you need to recompile _heap.c with the
20468  required size defined in HEAP_SIZE.
20469  It is recommended to make a copy of this file into your project directory
20470  and compile it there with:
20471 \end_layout
20472
20473 \begin_layout Verse
20474
20475 \family typewriter
20476 sdcc -c _heap.c -D HEAD_SIZE=2048
20477 \end_layout
20478
20479 \begin_layout Standard
20480 And then link it with:
20481 \end_layout
20482
20483 \begin_layout Verse
20484
20485 \family typewriter
20486 sdcc main.rel _heap.rel
20487 \end_layout
20488
20489 \begin_layout Subsection
20490 Math functions (sinf, powf, sqrtf etc.)
20491 \end_layout
20492
20493 \begin_layout Subsubsection
20494 <math.h>
20495 \end_layout
20496
20497 \begin_layout Standard
20498 See definitions in file <math.h>.
20499 \end_layout
20500
20501 \begin_layout Subsection
20502 Other libraries
20503 \end_layout
20504
20505 \begin_layout Standard
20506 Libraries
20507 \begin_inset LatexCommand \index{Libraries}
20508
20509 \end_inset
20510
20511  included in SDCC should have a license at least as liberal as the GNU Lesser
20512  General Public License
20513 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20514
20515 \end_inset
20516
20517  
20518 \emph on
20519 LGPL
20520 \emph default
20521 .
20522 \end_layout
20523
20524 \begin_layout Standard
20525 \begin_inset Note Note
20526 status collapsed
20527
20528 \begin_layout Standard
20529 license statements for the libraries are missing.
20530  sdcc/device/lib/ser_ir.c
20531 \end_layout
20532
20533 \begin_layout Standard
20534 or _decdptr f.e.
20535  come with a GPL (as opposed to LGPL) License - this will not be liberal
20536  enough for many embedded programmers.
20537 \end_layout
20538
20539 \end_inset
20540
20541
20542 \end_layout
20543
20544 \begin_layout Standard
20545 If you have ported some library or want to share experience about some code
20546  which f.e.
20547  falls into any of these categories Busses (I
20548 \begin_inset Formula $^{\textrm{2}}$
20549 \end_inset
20550
20551 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20552  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20553  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20554 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20555
20556 \end_inset
20557
20558 \InsetSpace ~
20559 would certainly like to hear about it.
20560 \end_layout
20561
20562 \begin_layout Standard
20563 Programmers coding for embedded systems are not especially famous for being
20564  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20565 e these references are very valuable.
20566  Let's help to create a climate where information is shared.
20567 \begin_inset VSpace bigskip
20568 \end_inset
20569
20570
20571 \end_layout
20572
20573 \begin_layout Section
20574 Memory Models
20575 \end_layout
20576
20577 \begin_layout Subsection
20578 MCS51 Memory Models
20579 \begin_inset LatexCommand \index{Memory model}
20580
20581 \end_inset
20582
20583
20584 \begin_inset LatexCommand \index{MCS51 memory model}
20585
20586 \end_inset
20587
20588
20589 \end_layout
20590
20591 \begin_layout Subsubsection
20592 Small, Medium and Large
20593 \end_layout
20594
20595 \begin_layout Standard
20596 SDCC allows three memory models for MCS51 code, 
20597 \shape slanted
20598 small, medium
20599 \shape default
20600  and 
20601 \shape slanted
20602 large
20603 \shape default
20604 .
20605  Modules compiled with different memory models should 
20606 \emph on
20607 never
20608 \emph default
20609  be combined together or the results would be unpredictable.
20610  The library routines supplied with the compiler are compiled as small,
20611  medium and large.
20612  The compiled library modules are contained in separate directories as small,
20613  medium and large so that you can link to the appropriate set.
20614 \end_layout
20615
20616 \begin_layout Standard
20617 When the medium or large model is used all variables declared without a
20618  storage class will be allocated into the external ram, this includes all
20619  parameters and local variables (for non-reentrant
20620 \begin_inset LatexCommand \index{reentrant}
20621
20622 \end_inset
20623
20624  functions).
20625  When the small model is used variables without storage class are allocated
20626  in the internal ram.
20627 \end_layout
20628
20629 \begin_layout Standard
20630 Judicious usage of the processor specific storage classes
20631 \begin_inset LatexCommand \index{Storage class}
20632
20633 \end_inset
20634
20635  and the 'reentrant' function type will yield much more efficient code,
20636  than using the large model.
20637  Several optimizations are disabled when the program is compiled using the
20638  large model, it is therefore recommended that the small model be used unless
20639  absolutely required.
20640 \end_layout
20641
20642 \begin_layout Subsubsection
20643 External Stack
20644 \begin_inset LatexCommand \label{sub:External-Stack}
20645
20646 \end_inset
20647
20648
20649 \begin_inset LatexCommand \index{stack}
20650
20651 \end_inset
20652
20653
20654 \begin_inset LatexCommand \index{External stack (mcs51)}
20655
20656 \end_inset
20657
20658
20659 \end_layout
20660
20661 \begin_layout Standard
20662 The external stack (-
20663 \begin_inset ERT
20664 status collapsed
20665
20666 \begin_layout Standard
20667
20668
20669 \backslash
20670 /
20671 \end_layout
20672
20673 \end_inset
20674
20675 -xstack option
20676 \begin_inset LatexCommand \index{-\/-xstack}
20677
20678 \end_inset
20679
20680 ) is located in pdata
20681 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20682
20683 \end_inset
20684
20685  memory (usually at the start of the external ram segment) and uses all
20686  unused space in pdata (max.
20687  256 bytes).
20688  When -
20689 \begin_inset ERT
20690 status collapsed
20691
20692 \begin_layout Standard
20693
20694
20695 \backslash
20696 /
20697 \end_layout
20698
20699 \end_inset
20700
20701 -xstack option is used to compile the program, the parameters and local
20702  variables
20703 \begin_inset LatexCommand \index{local variables}
20704
20705 \end_inset
20706
20707  of all reentrant functions are allocated in this area.
20708  This option is provided for programs with large stack space requirements.
20709  When used with the -
20710 \begin_inset ERT
20711 status collapsed
20712
20713 \begin_layout Standard
20714
20715
20716 \backslash
20717 /
20718 \end_layout
20719
20720 \end_inset
20721
20722 -stack-auto
20723 \begin_inset LatexCommand \index{-\/-stack-auto}
20724
20725 \end_inset
20726
20727  option, all parameters and local variables are allocated on the external
20728  stack (note: support libraries will need to be recompiled with the same
20729  options.
20730  There is a predefined target in the library makefile).
20731 \end_layout
20732
20733 \begin_layout Standard
20734 The compiler outputs the higher order address byte of the external ram segment
20735  into port P2
20736 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20737
20738 \end_inset
20739
20740  (see also section 
20741 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20742
20743 \end_inset
20744
20745 ), therefore when using the External Stack option, this port 
20746 \emph on
20747 may not
20748 \emph default
20749  be used by the application program.
20750 \end_layout
20751
20752 \begin_layout Subsection
20753 DS390 Memory Model
20754 \begin_inset LatexCommand \index{Memory model}
20755
20756 \end_inset
20757
20758
20759 \begin_inset LatexCommand \index{DS390 memory model}
20760
20761 \end_inset
20762
20763
20764 \end_layout
20765
20766 \begin_layout Standard
20767 The only model supported is Flat 24
20768 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20769
20770 \end_inset
20771
20772 .
20773  This generates code for the 24 bit contiguous addressing mode of the Dallas
20774  DS80C390 part.
20775  In this mode, up to four meg of external RAM or code space can be directly
20776  addressed.
20777  See the data sheets at www.dalsemi.com for further information on this part.
20778 \newline
20779
20780 \newline
20781 Note
20782  that the compiler does not generate any code to place the processor into
20783  24 bitmode (although 
20784 \emph on
20785 tinibios
20786 \emph default
20787  in the ds390 libraries will do that for you).
20788  If you don't use 
20789 \emph on
20790 tinibios
20791 \emph default
20792
20793 \begin_inset LatexCommand \index{Tinibios (DS390)}
20794
20795 \end_inset
20796
20797 , the boot loader or similar code must ensure that the processor is in 24
20798  bit contiguous addressing mode before calling the SDCC startup code.
20799 \newline
20800
20801 \newline
20802 Like
20803  the 
20804 \emph on
20805 -
20806 \begin_inset ERT
20807 status collapsed
20808
20809 \begin_layout Standard
20810
20811
20812 \backslash
20813 /
20814 \end_layout
20815
20816 \end_inset
20817
20818 -model-large
20819 \emph default
20820  option, variables will by default be placed into the XDATA segment.
20821  
20822 \newline
20823
20824 \newline
20825 Segments may be placed anywhere in the 4 meg address space using the usual
20826  -
20827 \begin_inset ERT
20828 status collapsed
20829
20830 \begin_layout Standard
20831
20832
20833 \backslash
20834 /
20835 \end_layout
20836
20837 \end_inset
20838
20839 -*-loc options.
20840  Note that if any segments are located above 64K, the -r flag must be passed
20841  to the linker to generate the proper segment relocations, and the Intel
20842  HEX output format must be used.
20843  The -r flag can be passed to the linker by using the option 
20844 \emph on
20845 -Wl-r
20846 \emph default
20847  on the SDCC command line.
20848  However, currently the linker can not handle code segments > 64k.
20849 \end_layout
20850
20851 \begin_layout Section
20852 Pragmas
20853 \begin_inset LatexCommand \label{sec:Pragmas}
20854
20855 \end_inset
20856
20857
20858 \begin_inset LatexCommand \index{Pragmas}
20859
20860 \end_inset
20861
20862
20863 \end_layout
20864
20865 \begin_layout Standard
20866 Pragmas are used to turn on and/or off certain compiler options.
20867  Some of them are closely related to corresponding command-line options
20868  (see section 
20869 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20870
20871 \end_inset
20872
20873 ).
20874 \newline
20875 Pragmas should be placed before and/or after a function, placing pragmas
20876  inside a function body could have unpredictable results.
20877 \newline
20878
20879 \newline
20880 SDCC supports the
20881  following #pragma directives:
20882 \end_layout
20883
20884 \begin_layout Itemize
20885
20886 \series bold
20887 save
20888 \series default
20889
20890 \begin_inset LatexCommand \index{\#pragma save}
20891
20892 \end_inset
20893
20894  - this will save most current options to the save/restore stack.
20895  See #pragma\InsetSpace ~
20896 restore.
20897 \end_layout
20898
20899 \begin_layout Itemize
20900
20901 \series bold
20902 restore
20903 \series default
20904
20905 \begin_inset LatexCommand \index{\#pragma restore}
20906
20907 \end_inset
20908
20909  - will restore saved options from the last save.
20910  saves & restores can be nested.
20911  SDCC uses a save/restore stack: save pushes current options to the stack,
20912  restore pulls current options from the stack.
20913  See #pragma\InsetSpace ~
20914 save.
20915 \newline
20916
20917 \end_layout
20918
20919 \begin_layout Itemize
20920
20921 \series bold
20922 callee_saves
20923 \series default
20924
20925 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20926
20927 \end_inset
20928
20929
20930 \begin_inset LatexCommand \index{function prologue}
20931
20932 \end_inset
20933
20934  function1[,function2[,function3...]] 
20935 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20936
20937 \end_inset
20938
20939 - The compiler by default uses a caller saves convention for register saving
20940  across function calls, however this can cause unnecessary register pushing
20941  and popping
20942 \begin_inset LatexCommand \index{push/pop}
20943
20944 \end_inset
20945
20946  when calling small functions from larger functions.
20947  This option can be used to switch off the register saving convention for
20948  the function names specified.
20949  The compiler will not save registers when calling these functions, extra
20950  code need to be manually inserted at the entry and exit for these functions
20951  to save and restore the registers used by these functions, this can SUBSTANTIAL
20952 LY reduce code and improve run time performance of the generated code.
20953  In the future the compiler (with inter procedural analysis) may be able
20954  to determine the appropriate scheme to use for each function call.
20955  If -
20956 \begin_inset ERT
20957 status collapsed
20958
20959 \begin_layout Standard
20960
20961
20962 \backslash
20963 /
20964 \end_layout
20965
20966 \end_inset
20967
20968 -callee-saves command line option is used (see page 
20969 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20970
20971 \end_inset
20972
20973 ), the function names specified in #pragma\InsetSpace ~
20974 callee_saves
20975 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20976
20977 \end_inset
20978
20979  is appended to the list of functions specified in the command line.
20980 \end_layout
20981
20982 \begin_layout Itemize
20983
20984 \series bold
20985 exclude
20986 \series default
20987
20988 \begin_inset LatexCommand \index{\#pragma exclude}
20989
20990 \end_inset
20991
20992  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20993  of pairs of push/pop
20994 \begin_inset LatexCommand \index{push/pop}
20995
20996 \end_inset
20997
20998  instructions in 
20999 \emph on
21000 I
21001 \emph default
21002 nterrupt
21003 \begin_inset LatexCommand \index{interrupt}
21004
21005 \end_inset
21006
21007  
21008 \emph on
21009 S
21010 \emph default
21011 ervice 
21012 \emph on
21013 R
21014 \emph default
21015 outines.
21016  The directive should be placed immediately before the ISR function definition
21017  and it affects ALL ISR functions following it.
21018  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21019 exclude\InsetSpace ~
21020 none
21021 \begin_inset LatexCommand \index{\#pragma exclude}
21022
21023 \end_inset
21024
21025 .
21026  See also the related keyword _naked
21027 \begin_inset LatexCommand \index{\_naked}
21028
21029 \end_inset
21030
21031
21032 \begin_inset LatexCommand \index{\_\_naked}
21033
21034 \end_inset
21035
21036 .
21037 \end_layout
21038
21039 \begin_layout Itemize
21040
21041 \series bold
21042 less_pedantic
21043 \series default
21044
21045 \begin_inset LatexCommand \index{pedantic}
21046
21047 \end_inset
21048
21049
21050 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21051
21052 \end_inset
21053
21054  
21055 \begin_inset LatexCommand \label{ite:less_pedantic}
21056
21057 \end_inset
21058
21059 - the compiler will not warn you anymore for obvious mistakes, you'r on
21060  your own now ;-( .
21061  See also the command line option -
21062 \begin_inset ERT
21063 status collapsed
21064
21065 \begin_layout Standard
21066
21067
21068 \backslash
21069 /
21070 \end_layout
21071
21072 \end_inset
21073
21074 -less-pedantic 
21075 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21076
21077 \end_inset
21078
21079 .
21080  
21081 \newline
21082 More specifically, the following warnings will be disabled: 
21083 \shape italic
21084 comparison is always [true/false] due to limited range of data type
21085 \shape default
21086  (94); 
21087 \shape italic
21088 overflow in implicit constant conversion
21089 \shape default
21090  (158); [the (in)famous] 
21091 \shape italic
21092 conditional flow changed by optimizer: so said EVELYN the modified DOG
21093 \shape default
21094  (110); 
21095 \shape italic
21096 function '[function name]' must return value
21097 \shape default
21098  (59).
21099  
21100 \newline
21101 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21102  level) are disabled, too, namely: 
21103 \shape italic
21104 constant value '[
21105 \begin_inset Note Note
21106 status collapsed
21107
21108 \begin_layout Standard
21109 dunno what comes here - this warning appears to be unused altogether
21110 \end_layout
21111
21112 \end_inset
21113
21114 ]', out of range
21115 \shape default
21116  (81); 
21117 \shape italic
21118 [left/right] shifting more than size of object changed to zero
21119 \shape default
21120  (116); 
21121 \shape italic
21122 unreachable code
21123 \shape default
21124  (126); 
21125 \shape italic
21126 integer overflow in expression
21127 \shape default
21128  (165); 
21129 \shape italic
21130 unmatched #pragma save and #pragma restore
21131 \shape default
21132  (170); 
21133 \shape italic
21134 comparison of 'signed char' with 'unsigned char' requires promotion to int
21135 \shape default
21136  (185); 
21137 \shape italic
21138 ISO C90 does not support flexible array members
21139 \shape default
21140  (187); 
21141 \shape italic
21142 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21143 nam
21144 e]':\InsetSpace ~
21145 [
21146 \begin_inset Note Note
21147 status collapsed
21148
21149 \begin_layout Standard
21150 appears to be always blank - what was supposed to be here?
21151 \end_layout
21152
21153 \end_inset
21154
21155 ]
21156 \shape default
21157  (114); 
21158 \shape italic
21159 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21160  complexity [number]
21161 \shape default
21162  (121).
21163 \end_layout
21164
21165 \begin_layout Itemize
21166
21167 \series bold
21168 disable_warning
21169 \series default
21170  <nnnn>
21171 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21172
21173 \end_inset
21174
21175  - the compiler will not warn you anymore about warning number <nnnn>.
21176 \end_layout
21177
21178 \begin_layout Itemize
21179
21180 \series bold
21181 nogcse
21182 \series default
21183
21184 \begin_inset LatexCommand \index{\#pragma nogcse}
21185
21186 \end_inset
21187
21188  - will stop global common subexpression elimination.
21189 \end_layout
21190
21191 \begin_layout Itemize
21192
21193 \series bold
21194 noinduction
21195 \series default
21196
21197 \begin_inset LatexCommand \index{\#pragma noinduction}
21198
21199 \end_inset
21200
21201  - will stop loop induction optimizations.
21202 \end_layout
21203
21204 \begin_layout Itemize
21205
21206 \series bold
21207 noinvariant
21208 \series default
21209
21210 \begin_inset LatexCommand \index{\#pragma noinvariant}
21211
21212 \end_inset
21213
21214  - will not do loop invariant optimizations.
21215  For more details see Loop Invariants in section
21216 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21217
21218 \end_inset
21219
21220 .
21221 \end_layout
21222
21223 \begin_layout Itemize
21224
21225 \series bold
21226 noiv
21227 \series default
21228
21229 \begin_inset LatexCommand \index{\#pragma noiv}
21230
21231 \end_inset
21232
21233  - Do not generate interrupt
21234 \begin_inset LatexCommand \index{interrupt}
21235
21236 \end_inset
21237
21238  vector table
21239 \begin_inset LatexCommand \index{interrupt vector table}
21240
21241 \end_inset
21242
21243  entries for all ISR functions defined after the pragma.
21244  This is useful in cases where the interrupt vector table must be defined
21245  manually, or when there is a secondary, manually defined interrupt vector
21246  table (e.g.
21247  for the autovector feature of the Cypress EZ-USB FX2).
21248  More elegantly this can be achieved by obmitting the optional interrupt
21249  number after the interrupt keyword, see section 
21250 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21251
21252 \end_inset
21253
21254 \InsetSpace ~
21255 about interrupts.
21256 \end_layout
21257
21258 \begin_layout Itemize
21259
21260 \series bold
21261 nojtbound
21262 \series default
21263
21264 \begin_inset LatexCommand \index{\#pragma nojtbound}
21265
21266 \end_inset
21267
21268  - will not generate code for boundary value checking, when switch statements
21269  are turned into jump-tables (dangerous).
21270  For more details see section 
21271 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21272
21273 \end_inset
21274
21275 .
21276 \end_layout
21277
21278 \begin_layout Itemize
21279
21280 \series bold
21281 noloopreverse
21282 \series default
21283
21284 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21285
21286 \end_inset
21287
21288  - Will not do loop reversal optimization
21289 \end_layout
21290
21291 \begin_layout Itemize
21292
21293 \series bold
21294 nooverlay
21295 \series default
21296
21297 \begin_inset LatexCommand \index{\#pragma nooverlay}
21298
21299 \end_inset
21300
21301  - the compiler will not overlay the parameters and local variables of a
21302  function.
21303 \end_layout
21304
21305 \begin_layout Itemize
21306
21307 \series bold
21308 stackauto
21309 \series default
21310
21311 \begin_inset LatexCommand \index{\#pragma stackauto}
21312
21313 \end_inset
21314
21315 - See option -
21316 \begin_inset ERT
21317 status collapsed
21318
21319 \begin_layout Standard
21320
21321
21322 \backslash
21323 /
21324 \end_layout
21325
21326 \end_inset
21327
21328 -stack-auto
21329 \begin_inset LatexCommand \index{-\/-stack-auto}
21330
21331 \end_inset
21332
21333  and section 
21334 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21335
21336 \end_inset
21337
21338  Parameters and Local Variables.
21339 \end_layout
21340
21341 \begin_layout Itemize
21342
21343 \series bold
21344 opt_code_speed
21345 \series default
21346  
21347 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21348
21349 \end_inset
21350
21351 - The compiler will optimize code generation towards fast code, possibly
21352  at the expense of code size.
21353  Currently this has little effect.
21354 \end_layout
21355
21356 \begin_layout Itemize
21357
21358 \series bold
21359 opt_code_size
21360 \series default
21361  
21362 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21363
21364 \end_inset
21365
21366 - The compiler will optimize code generation towards compact code, possibly
21367  at the expense of code speed.
21368  Currently this has little effect.
21369 \end_layout
21370
21371 \begin_layout Itemize
21372
21373 \series bold
21374 opt_code_balanced
21375 \series default
21376  
21377 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21378
21379 \end_inset
21380
21381 - The compiler will attempt to generate code that is both compact and fast,
21382  as long as meeting one goal is not a detriment to the other (this is the
21383  default).
21384  
21385 \end_layout
21386
21387 \begin_layout Itemize
21388
21389 \series bold
21390 std_sdcc89
21391 \series default
21392  
21393 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21394
21395 \end_inset
21396
21397 - Generally follow the C89 standard, but allow SDCC features that conflict
21398  with the standard (default).
21399 \end_layout
21400
21401 \begin_layout Itemize
21402
21403 \series bold
21404 std_c89
21405 \series default
21406  
21407 \begin_inset LatexCommand \index{\#pragma std\_c89}
21408
21409 \end_inset
21410
21411 - Follow the C89 standard and disable SDCC features that conflict with the
21412  standard.
21413 \end_layout
21414
21415 \begin_layout Itemize
21416
21417 \series bold
21418 std_sdcc99
21419 \series default
21420  
21421 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21422
21423 \end_inset
21424
21425 - Generally follow the C99 standard, but allow SDCC features that conflict
21426  with the standard (incomplete support).
21427 \end_layout
21428
21429 \begin_layout Itemize
21430
21431 \series bold
21432 std_c99
21433 \series default
21434  
21435 \begin_inset LatexCommand \index{\#pragma std\_c99}
21436
21437 \end_inset
21438
21439 - Follow the C99 standard and disable SDCC features that conflict with the
21440  standard (incomplete support).
21441 \end_layout
21442
21443 \begin_layout Itemize
21444
21445 \series bold
21446 codeseg
21447 \series default
21448  <name>
21449 \begin_inset LatexCommand \index{\#pragma codeseg}
21450
21451 \end_inset
21452
21453 - Use this name (max.
21454  8 characters) for the code segment.
21455  See option -
21456 \begin_inset ERT
21457 status collapsed
21458
21459 \begin_layout Standard
21460
21461
21462 \backslash
21463 /
21464 \end_layout
21465
21466 \end_inset
21467
21468 -codeseg.
21469 \end_layout
21470
21471 \begin_layout Itemize
21472
21473 \series bold
21474 constseg
21475 \series default
21476  <name>
21477 \begin_inset LatexCommand \index{\#pragma constseg}
21478
21479 \end_inset
21480
21481 - Use this name (max.
21482  8 characters) for the const segment.
21483  See option -
21484 \begin_inset ERT
21485 status collapsed
21486
21487 \begin_layout Standard
21488
21489
21490 \backslash
21491 /
21492 \end_layout
21493
21494 \end_inset
21495
21496 -constseg.
21497 \end_layout
21498
21499 \begin_layout Standard
21500 The preprocessor SDCPP
21501 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21502
21503 \end_inset
21504
21505  supports the following #pragma directives:
21506 \end_layout
21507
21508 \begin_layout Itemize
21509
21510 \series bold
21511 pedantic_parse_number
21512 \series default
21513
21514 \begin_inset LatexCommand \index{pedantic}
21515
21516 \end_inset
21517
21518
21519 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21520
21521 \end_inset
21522
21523  (+ | -) 
21524 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21525
21526 \end_inset
21527
21528 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21529  properly and the macro LO_B(3) gets expanded.
21530  Default is off.
21531  See also the -
21532 \begin_inset ERT
21533 status collapsed
21534
21535 \begin_layout Standard
21536
21537
21538 \backslash
21539 /
21540 \end_layout
21541
21542 \end_inset
21543
21544 -pedantic-parse-number command line option 
21545 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21546
21547 \end_inset
21548
21549 .
21550  
21551 \newline
21552 Below is an example on how to use this pragma.
21553
21554 \emph on
21555  Note: this functionality is not in conformance with standard!
21556 \end_layout
21557
21558 \begin_layout Verse
21559
21560 \family typewriter
21561 #pragma pedantic_parse_number +
21562 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21563
21564 \end_inset
21565
21566
21567 \newline
21568
21569 \newline
21570 #define LO_B(x) ((x) & 0xff)
21571 \newline
21572
21573 \newline
21574 unsigned char foo(void)
21575 \newline
21576 {
21577 \newline
21578 \InsetSpace ~
21579 \InsetSpace ~
21580 \InsetSpace ~
21581 unsigned char c=0xfe-LO_B(3)
21582 ;
21583 \newline
21584
21585 \newline
21586 \InsetSpace ~
21587 \InsetSpace ~
21588 \InsetSpace ~
21589 return c;
21590 \newline
21591 }
21592 \newline
21593
21594 \end_layout
21595
21596 \begin_layout Itemize
21597
21598 \series bold
21599 preproc_asm
21600 \series default
21601
21602 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21603
21604 \end_inset
21605
21606  (+ | -) - switch _asm _endasm block preprocessing on / off.
21607  Default is on.
21608  You use this prama to define multilines of assembly code.
21609  This will prevent the preprocessor from changing the formating required
21610  by assembly code.
21611  Below is an example on how to use this pragma.
21612 \end_layout
21613
21614 \begin_layout Verse
21615
21616 \family typewriter
21617 #pragma preproc_asm -
21618 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21619
21620 \end_inset
21621
21622
21623 \newline
21624 #define MYDELAY _asm
21625 \newline
21626 \InsetSpace ~
21627 \InsetSpace ~
21628 \InsetSpace ~
21629 nop ;my assembly comment...
21630 \newline
21631 \InsetSpace ~
21632 \InsetSpace ~
21633 \InsetSpace ~
21634 nop
21635 \newline
21636 \InsetSpace ~
21637 \InsetSpace ~
21638 \InsetSpace ~
21639 nop
21640 \newline
21641 _endasm
21642 \newline
21643 #pragma preproc_asm
21644  +
21645 \newline
21646
21647 \newline
21648 void foo (void) 
21649 \newline
21650
21651 \newline
21652 \InsetSpace ~
21653 \InsetSpace ~
21654 \InsetSpace ~
21655  ...
21656  
21657 \newline
21658 \InsetSpace ~
21659 \InsetSpace ~
21660 \InsetSpace ~
21661  MYDELAY;
21662 \newline
21663 \InsetSpace ~
21664 \InsetSpace ~
21665 \InsetSpace ~
21666  ...
21667  
21668 \newline
21669
21670 \newline
21671
21672 \end_layout
21673
21674 \begin_layout Itemize
21675
21676 \series bold
21677 sdcc_hash
21678 \series default
21679
21680 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21681
21682 \end_inset
21683
21684  (+ | -) - Allow "naked" hash in macro definition, for example:
21685 \newline
21686
21687 \family typewriter
21688 #define DIR_LO(x) #(x & 0xff)
21689 \family default
21690
21691 \newline
21692 Default is off.
21693  Below is an example on how to use this pragma.
21694 \end_layout
21695
21696 \begin_layout Verse
21697
21698 \family typewriter
21699 #pragma preproc_asm +
21700 \newline
21701 #pragma sdcc_hash +
21702 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21703
21704 \end_inset
21705
21706
21707 \newline
21708
21709 \newline
21710 #define ROMCALL(x) 
21711 \backslash
21712
21713 \newline
21714 \InsetSpace ~
21715 \InsetSpace ~
21716 \InsetSpace ~
21717 mov R6_B3, #(x & 0xff) 
21718 \backslash
21719
21720 \newline
21721 \InsetSpace ~
21722 \InsetSpace ~
21723 \InsetSpace ~
21724 mov R7_B3, #((x >> 8) & 0xff) 
21725 \backslash
21726
21727 \newline
21728 \InsetSpace ~
21729 \InsetSpace ~
21730 \InsetSpace ~
21731 lcall __romcall
21732 \newline
21733
21734 \newline
21735 ...
21736 \newline
21737 _asm
21738 \newline
21739 ROMCALL(72)
21740 \newline
21741 _endasm;
21742 \newline
21743 ...
21744 \newline
21745
21746 \end_layout
21747
21748 \begin_layout Standard
21749 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21750 ons which might cause the compiler to generate extra stack and/or data space
21751  to store compiler generated temporary variables.
21752  This usually happens in large functions.
21753  Pragma directives should be used as shown in the following example, they
21754  are used to control options and optimizations for a given function.
21755  
21756 \end_layout
21757
21758 \begin_layout Verse
21759
21760 \family typewriter
21761 #pragma save
21762 \begin_inset LatexCommand \index{\#pragma save}
21763
21764 \end_inset
21765
21766  \InsetSpace ~
21767 \InsetSpace ~
21768 \InsetSpace ~
21769 \InsetSpace ~
21770 \InsetSpace ~
21771 \InsetSpace ~
21772 \InsetSpace ~
21773 /* save the current settings */ 
21774 \newline
21775 #pragma nogcse
21776 \begin_inset LatexCommand \index{\#pragma nogcse}
21777
21778 \end_inset
21779
21780  \InsetSpace ~
21781 \InsetSpace ~
21782 \InsetSpace ~
21783 \InsetSpace ~
21784 \InsetSpace ~
21785 /* turnoff global subexpression elimination */ 
21786 \newline
21787 #pragma noinduction
21788 \begin_inset LatexCommand \index{\#pragma noinduction}
21789
21790 \end_inset
21791
21792  /* turn off induction optimizations */ 
21793 \newline
21794 int foo () 
21795 \newline
21796
21797 \newline
21798 \InsetSpace ~
21799  \InsetSpace ~
21800  ...
21801  
21802 \newline
21803 \InsetSpace ~
21804  \InsetSpace ~
21805  /* large code */ 
21806 \newline
21807 \InsetSpace ~
21808  \InsetSpace ~
21809  ...
21810  
21811 \newline
21812
21813 \newline
21814 #pragma restore
21815 \begin_inset LatexCommand \index{\#pragma restore}
21816
21817 \end_inset
21818
21819  /* turn the optimizations back on */
21820 \end_layout
21821
21822 \begin_layout Standard
21823 The compiler will generate a warning message when extra space is allocated.
21824  It is strongly recommended that the save and restore pragma's be used when
21825  changing options for a function.
21826 \newline
21827
21828 \newline
21829
21830 \newline
21831
21832 \end_layout
21833
21834 \begin_layout Section
21835 Defines Created by the Compiler
21836 \end_layout
21837
21838 \begin_layout Standard
21839 The compiler creates the following #defines
21840 \begin_inset LatexCommand \index{\#defines}
21841
21842 \end_inset
21843
21844
21845 \begin_inset LatexCommand \index{Defines created by the compiler}
21846
21847 \end_inset
21848
21849 :
21850 \newline
21851
21852 \end_layout
21853
21854 \begin_layout Standard
21855 \begin_inset Tabular
21856 <lyxtabular version="3" rows="11" columns="2">
21857 <features>
21858 <column alignment="left" valignment="top" leftline="true" width="3in">
21859 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21860 <row topline="true" bottomline="true">
21861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21862 \begin_inset Text
21863
21864 \begin_layout Standard
21865
21866 \series bold
21867 #define
21868 \end_layout
21869
21870 \end_inset
21871 </cell>
21872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21873 \begin_inset Text
21874
21875 \begin_layout Standard
21876
21877 \series bold
21878 Description
21879 \end_layout
21880
21881 \end_inset
21882 </cell>
21883 </row>
21884 <row topline="true">
21885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21886 \begin_inset Text
21887
21888 \begin_layout Standard
21889 SDCC
21890 \begin_inset LatexCommand \index{SDCC}
21891
21892 \end_inset
21893
21894  
21895 \end_layout
21896
21897 \end_inset
21898 </cell>
21899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21900 \begin_inset Text
21901
21902 \begin_layout Standard
21903 Always defined.
21904  Since version 2.5.6 the version number as an int (ex.
21905  256)
21906 \end_layout
21907
21908 \end_inset
21909 </cell>
21910 </row>
21911 <row topline="true">
21912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21913 \begin_inset Text
21914
21915 \begin_layout Standard
21916 SDCC_mcs51
21917 \begin_inset LatexCommand \index{SDCC\_mcs51}
21918
21919 \end_inset
21920
21921  or SDCC_ds390
21922 \begin_inset LatexCommand \index{SDCC\_ds390}
21923
21924 \end_inset
21925
21926  or SDCC_z80
21927 \begin_inset LatexCommand \index{SDCC\_z80}
21928
21929 \end_inset
21930
21931 , etc.
21932 \end_layout
21933
21934 \end_inset
21935 </cell>
21936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21937 \begin_inset Text
21938
21939 \begin_layout Standard
21940 depending on the model used (e.g.: -mds390)
21941 \end_layout
21942
21943 \end_inset
21944 </cell>
21945 </row>
21946 <row topline="true">
21947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21948 \begin_inset Text
21949
21950 \begin_layout Standard
21951 __mcs51
21952 \begin_inset LatexCommand \index{\_\_mcs51}
21953
21954 \end_inset
21955
21956 , __ds390
21957 \begin_inset LatexCommand \index{\_\_ds390}
21958
21959 \end_inset
21960
21961 , __hc08
21962 \begin_inset LatexCommand \index{\_\_hc08}
21963
21964 \end_inset
21965
21966 , __z80
21967 \begin_inset LatexCommand \index{\_\_z80}
21968
21969 \end_inset
21970
21971 , etc
21972 \end_layout
21973
21974 \end_inset
21975 </cell>
21976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21977 \begin_inset Text
21978
21979 \begin_layout Standard
21980 depending on the model used (e.g.
21981  -mz80)
21982 \end_layout
21983
21984 \end_inset
21985 </cell>
21986 </row>
21987 <row topline="true">
21988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21989 \begin_inset Text
21990
21991 \begin_layout Standard
21992 SDCC_STACK_AUTO
21993 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21994
21995 \end_inset
21996
21997
21998 \end_layout
21999
22000 \end_inset
22001 </cell>
22002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22003 \begin_inset Text
22004
22005 \begin_layout Standard
22006 when 
22007 \emph on
22008 -
22009 \begin_inset ERT
22010 status collapsed
22011
22012 \begin_layout Standard
22013
22014
22015 \backslash
22016 /
22017 \end_layout
22018
22019 \end_inset
22020
22021 -stack-auto
22022 \emph default
22023  option is used
22024 \end_layout
22025
22026 \end_inset
22027 </cell>
22028 </row>
22029 <row topline="true">
22030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22031 \begin_inset Text
22032
22033 \begin_layout Standard
22034 SDCC_MODEL_SMALL
22035 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22036
22037 \end_inset
22038
22039
22040 \end_layout
22041
22042 \end_inset
22043 </cell>
22044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22045 \begin_inset Text
22046
22047 \begin_layout Standard
22048 when 
22049 \emph on
22050 -
22051 \begin_inset ERT
22052 status collapsed
22053
22054 \begin_layout Standard
22055
22056
22057 \backslash
22058 /
22059 \end_layout
22060
22061 \end_inset
22062
22063 -model-small
22064 \emph default
22065  is used
22066 \end_layout
22067
22068 \end_inset
22069 </cell>
22070 </row>
22071 <row topline="true">
22072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22073 \begin_inset Text
22074
22075 \begin_layout Standard
22076 SDCC_MODEL_MEDIUM
22077 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22078
22079 \end_inset
22080
22081
22082 \end_layout
22083
22084 \end_inset
22085 </cell>
22086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22087 \begin_inset Text
22088
22089 \begin_layout Standard
22090 when 
22091 \emph on
22092 -
22093 \begin_inset ERT
22094 status collapsed
22095
22096 \begin_layout Standard
22097
22098
22099 \backslash
22100 /
22101 \end_layout
22102
22103 \end_inset
22104
22105 -model-medium
22106 \emph default
22107  is used
22108 \end_layout
22109
22110 \end_inset
22111 </cell>
22112 </row>
22113 <row topline="true">
22114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22115 \begin_inset Text
22116
22117 \begin_layout Standard
22118 SDCC_MODEL_LARGE
22119 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22120
22121 \end_inset
22122
22123
22124 \end_layout
22125
22126 \end_inset
22127 </cell>
22128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22129 \begin_inset Text
22130
22131 \begin_layout Standard
22132 when 
22133 \emph on
22134 -
22135 \begin_inset ERT
22136 status collapsed
22137
22138 \begin_layout Standard
22139
22140
22141 \backslash
22142 /
22143 \end_layout
22144
22145 \end_inset
22146
22147 -model-large
22148 \emph default
22149  is used
22150 \end_layout
22151
22152 \end_inset
22153 </cell>
22154 </row>
22155 <row topline="true">
22156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22157 \begin_inset Text
22158
22159 \begin_layout Standard
22160 SDCC_USE_XSTACK
22161 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22162
22163 \end_inset
22164
22165
22166 \end_layout
22167
22168 \end_inset
22169 </cell>
22170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22171 \begin_inset Text
22172
22173 \begin_layout Standard
22174 when 
22175 \emph on
22176 -
22177 \begin_inset ERT
22178 status collapsed
22179
22180 \begin_layout Standard
22181
22182
22183 \backslash
22184 /
22185 \end_layout
22186
22187 \end_inset
22188
22189 -xstack
22190 \emph default
22191  option is used
22192 \end_layout
22193
22194 \end_inset
22195 </cell>
22196 </row>
22197 <row topline="true">
22198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22199 \begin_inset Text
22200
22201 \begin_layout Standard
22202 SDCC_STACK_TENBIT
22203 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22204
22205 \end_inset
22206
22207  
22208 \end_layout
22209
22210 \end_inset
22211 </cell>
22212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22213 \begin_inset Text
22214
22215 \begin_layout Standard
22216 when 
22217 \emph on
22218 -mds390
22219 \emph default
22220  is used
22221 \end_layout
22222
22223 \end_inset
22224 </cell>
22225 </row>
22226 <row topline="true" bottomline="true">
22227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22228 \begin_inset Text
22229
22230 \begin_layout Standard
22231 SDCC_MODEL_FLAT24
22232 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22233
22234 \end_inset
22235
22236
22237 \end_layout
22238
22239 \end_inset
22240 </cell>
22241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22242 \begin_inset Text
22243
22244 \begin_layout Standard
22245 when 
22246 \emph on
22247 -mds390
22248 \emph default
22249  is used
22250 \end_layout
22251
22252 \end_inset
22253 </cell>
22254 </row>
22255 </lyxtabular>
22256
22257 \end_inset
22258
22259
22260 \end_layout
22261
22262 \begin_layout Chapter
22263 Notes on supported Processors
22264 \end_layout
22265
22266 \begin_layout Section
22267 MCS51 variants
22268 \begin_inset LatexCommand \label{sub:MCS51-variants}
22269
22270 \end_inset
22271
22272
22273 \begin_inset LatexCommand \index{MCS51 variants}
22274
22275 \end_inset
22276
22277
22278 \end_layout
22279
22280 \begin_layout Standard
22281 MCS51 processors are available from many vendors and come in many different
22282  flavours.
22283  While they might differ considerably in respect to Special Function Registers
22284  the core MCS51 is usually not modified or is kept compatible.
22285  
22286 \end_layout
22287
22288 \begin_layout Subsection
22289 pdata access by SFR 
22290 \end_layout
22291
22292 \begin_layout Standard
22293 With the upcome of devices with internal xdata and flash memory devices
22294  using port P2
22295 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22296
22297 \end_inset
22298
22299  as dedicated I/O port is becoming more popular.
22300  Switching the high byte for pdata
22301 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22302
22303 \end_inset
22304
22305  access which was formerly done by port P2 is then achieved by a Special
22306  Function Register
22307 \begin_inset LatexCommand \index{sfr}
22308
22309 \end_inset
22310
22311 .
22312  In well-established MCS51 tradition the address of this 
22313 \emph on
22314 sfr
22315 \emph default
22316  is where the chip designers decided to put it.
22317  Needless to say that they didn't agree on a common name either.
22318  So that the startup code can correctly initialize xdata variables, you
22319  should define an sfr with the name _XPAGE
22320 \family typewriter
22321
22322 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22323
22324 \end_inset
22325
22326
22327 \family default
22328  at the appropriate location if the default, port P2, is not used for this.
22329  Some examples are:
22330 \end_layout
22331
22332 \begin_layout Verse
22333
22334 \family typewriter
22335 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22336  MPAGE */
22337 \end_layout
22338
22339 \begin_layout Verse
22340
22341 \family typewriter
22342 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22343  a.k.a.
22344  MPAGE */
22345 \end_layout
22346
22347 \begin_layout Verse
22348
22349 \family typewriter
22350 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22351  XPAGE */
22352 \end_layout
22353
22354 \begin_layout Verse
22355
22356 \family typewriter
22357 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22358  EMI0CN */
22359 \end_layout
22360
22361 \begin_layout Verse
22362
22363 \family typewriter
22364 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22365  EMI0CN */
22366 \end_layout
22367
22368 \begin_layout Standard
22369 For more exotic implementations further customizations may be needed.
22370  See section 
22371 \begin_inset LatexCommand \ref{sub:Startup-Code}
22372
22373 \end_inset
22374
22375  for other possibilities.
22376 \end_layout
22377
22378 \begin_layout Subsection
22379 Other Features available by SFR
22380 \end_layout
22381
22382 \begin_layout Standard
22383 Some MCS51 variants offer features like Double DPTR
22384 \begin_inset LatexCommand \index{DPTR}
22385
22386 \end_inset
22387
22388 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22389  These are currently not used for the MCS51 port.
22390  If you absolutely need them you can fall back to inline assembly or submit
22391  a patch to SDCC.
22392 \begin_inset VSpace bigskip
22393 \end_inset
22394
22395
22396 \end_layout
22397
22398 \begin_layout Section
22399 DS400 port
22400 \end_layout
22401
22402 \begin_layout Standard
22403 The DS80C400
22404 \begin_inset LatexCommand \index{DS80C400}
22405
22406 \end_inset
22407
22408
22409 \begin_inset LatexCommand \index{DS400}
22410
22411 \end_inset
22412
22413  microcontroller has a rich set of peripherals.
22414  In its built-in ROM library it includes functions to access some of the
22415  features, among them is a TCP stack with IP4 and IP6 support.
22416  Library headers (currently in beta status) and other files are provided
22417  at 
22418 \size footnotesize
22419
22420 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22421
22422 \end_inset
22423
22424 .
22425  
22426 \begin_inset VSpace bigskip
22427 \end_inset
22428
22429
22430 \end_layout
22431
22432 \begin_layout Section
22433 The Z80 and gbz80 port
22434 \end_layout
22435
22436 \begin_layout Standard
22437 SDCC can target both the Zilog Z80
22438 \begin_inset LatexCommand \index{Z80}
22439
22440 \end_inset
22441
22442  and the Nintendo Gameboy's Z80-like gbz80
22443 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22444
22445 \end_inset
22446
22447 .
22448  The Z80 port is passed through the same 
22449 \emph on
22450 regressions tests
22451 \begin_inset LatexCommand \index{Regression test}
22452
22453 \end_inset
22454
22455
22456 \emph default
22457  (see section 
22458 \begin_inset LatexCommand \ref{sec:Quality-control}
22459
22460 \end_inset
22461
22462 ) as the MCS51 and DS390 ports, so floating point support, support for long
22463  variables and bitfield support is fine.
22464  See mailing lists and forums about interrupt routines.
22465 \end_layout
22466
22467 \begin_layout Standard
22468 As always, the code is the authoritative reference - see z80/ralloc.c and
22469  z80/gen.c.
22470  The stack
22471 \begin_inset LatexCommand \index{Z80!stack}
22472
22473 \end_inset
22474
22475  frame is similar to that generated by the IAR Z80 compiler.
22476  IX is used as the base pointer, HL and IY are used as a temporary registers,
22477  and BC and DE are available for holding variables.
22478  Return values
22479 \begin_inset LatexCommand \index{Z80!return value}
22480
22481 \end_inset
22482
22483  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22484  bytes).
22485  The gbz80 port use the same set of registers for the return values, but
22486  in a different order of significance: E (one byte), DE (two bytes), or
22487  HLDE (four bytes).
22488 \begin_inset VSpace bigskip
22489 \end_inset
22490
22491
22492 \end_layout
22493
22494 \begin_layout Section
22495 The HC08 port
22496 \end_layout
22497
22498 \begin_layout Standard
22499 The port to the Freescale/Motorola HC08
22500 \begin_inset LatexCommand \index{HC08}
22501
22502 \end_inset
22503
22504  family has been added in October 2003, and is still undergoing some basic
22505  development.
22506  The code generator is complete, but the register allocation is still quite
22507  unoptimized.
22508  Some of the SDCC's standard C library functions have embedded non-HC08
22509  inline assembly and so are not yet usable.
22510 \end_layout
22511
22512 \begin_layout Standard
22513 The HC08 port passes the regression test suite (see section 
22514 \begin_inset LatexCommand \ref{sec:Quality-control}
22515
22516 \end_inset
22517
22518 ).
22519 \begin_inset VSpace bigskip
22520 \end_inset
22521
22522
22523 \newpage
22524
22525 \end_layout
22526
22527 \begin_layout Section
22528 The PIC14 port
22529 \end_layout
22530
22531 \begin_layout Standard
22532 The 14bit PIC
22533 \begin_inset LatexCommand \index{PIC14}
22534
22535 \end_inset
22536
22537  port still requires a major effort from the development community.
22538  However it can work for simple code.
22539  It passes its (smaller set of) regression tests
22540 \begin_inset LatexCommand \index{Regression test (PIC14)}
22541
22542 \end_inset
22543
22544  in the directory 
22545 \shape italic
22546 sdcc/src/regression
22547 \shape default
22548 .
22549 \end_layout
22550
22551 \begin_layout Subsection
22552 C code and 14bit PIC code page
22553 \begin_inset LatexCommand \index{code page (pic14)}
22554
22555 \end_inset
22556
22557  and RAM banks
22558 \begin_inset LatexCommand \index{RAM bank (pic14)}
22559
22560 \end_inset
22561
22562
22563 \end_layout
22564
22565 \begin_layout Standard
22566 The linker organizes allocation for the code page and RAM banks.
22567  It does not have intimate knowledge of the code flow.
22568  It will put all the code section of a single asm file into a single code
22569  page.
22570  In order to make use of multiple code pages, separate asm files must be
22571  used.
22572  The compiler treats all functions of a single C file as being in the same
22573  code page unless it is non static.
22574 \newline
22575
22576 \newline
22577 To get the best follow these guide lines:
22578 \end_layout
22579
22580 \begin_layout Enumerate
22581 Make local functions static, as non static functions require code page selection
22582  overhead.
22583 \end_layout
22584
22585 \begin_layout Enumerate
22586 For devices that have multiple code pages it is more efficient to use the
22587  same number of files as pages, i.e.
22588  for the 16F877 use 4 separate files and i.e.
22589  for the 16F874 use 2 separate files.
22590  This way the linker can put the code for each file into different code
22591  pages and there's less page selection overhead.
22592 \end_layout
22593
22594 \begin_layout Enumerate
22595 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22596  instruction set), use 'unsigned char' whereever possible instead of 'int'.
22597 \end_layout
22598
22599 \begin_layout Subsection
22600 Creating a device include file 
22601 \end_layout
22602
22603 \begin_layout Standard
22604 For generating a device include file
22605 \begin_inset LatexCommand \index{PIC14!Header files}
22606
22607 \end_inset
22608
22609  use the support perl script inc2h.pl kept in directory support/script.
22610 \end_layout
22611
22612 \begin_layout Subsection
22613 Interrupt code
22614 \end_layout
22615
22616 \begin_layout Standard
22617 For the interrupt function, use the keyword '__interrupt'
22618 \begin_inset LatexCommand \index{PIC14!interrupt}
22619
22620 \end_inset
22621
22622  with level number of 0 (PIC14 only has 1 interrupt so this number is only
22623  there to avoid a syntax error - it ought to be fixed).
22624  E.g.:
22625 \end_layout
22626
22627 \begin_layout Verse
22628
22629 \family typewriter
22630 void Intr(void) __interrupt 0
22631 \newline
22632 {
22633 \newline
22634 \InsetSpace ~
22635 \InsetSpace ~
22636 T0IF = 0; /* Clear timer interrupt */
22637 \newline
22638 }
22639 \end_layout
22640
22641 \begin_layout Subsection
22642 Linking and assembling
22643 \end_layout
22644
22645 \begin_layout Standard
22646 For assembling you can use either GPUTILS'
22647 \begin_inset LatexCommand \index{gputils (pic tools)}
22648
22649 \end_inset
22650
22651  gpasm.exe or MPLAB's mpasmwin.exe.
22652  GPUTILS is available from 
22653 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22654
22655 \end_inset
22656
22657 .
22658  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22659  If you use MPLAB and an interrupt function then the linker script file
22660  vectors section will need to be enlarged to link with mplink.
22661 \newline
22662
22663 \newline
22664 Here is a 
22665 \family typewriter
22666 Makefile
22667 \family default
22668  using GPUTILS:
22669 \end_layout
22670
22671 \begin_layout Verse
22672
22673 \family typewriter
22674 .c.o:
22675 \newline
22676 \InsetSpace ~
22677 \InsetSpace ~
22678 \InsetSpace ~
22679 \InsetSpace ~
22680 \InsetSpace ~
22681 \InsetSpace ~
22682 \InsetSpace ~
22683 \InsetSpace ~
22684 sdcc -S -V -mpic14 -p16F877 $< 
22685 \newline
22686 \InsetSpace ~
22687 \InsetSpace ~
22688 \InsetSpace ~
22689 \InsetSpace ~
22690 \InsetSpace ~
22691 \InsetSpace ~
22692 \InsetSpace ~
22693 \InsetSpace ~
22694 gpasm -c $*.asm
22695 \newline
22696
22697 \newline
22698 $(PRJ).hex: $(OBJS) 
22699 \newline
22700 \InsetSpace ~
22701 \InsetSpace ~
22702 \InsetSpace ~
22703 \InsetSpace ~
22704 \InsetSpace ~
22705 \InsetSpace ~
22706 \InsetSpace ~
22707 \InsetSpace ~
22708 gplink
22709  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22710 \end_layout
22711
22712 \begin_layout Standard
22713 Here is a 
22714 \family typewriter
22715 Makefile
22716 \family default
22717  using MPLAB:
22718 \end_layout
22719
22720 \begin_layout Verse
22721
22722 \family typewriter
22723 .c.o: 
22724 \newline
22725 \InsetSpace ~
22726 \InsetSpace ~
22727 \InsetSpace ~
22728 \InsetSpace ~
22729 \InsetSpace ~
22730 \InsetSpace ~
22731 \InsetSpace ~
22732 \InsetSpace ~
22733 sdcc -S -V -mpic14 -p16F877 $< 
22734 \newline
22735 \InsetSpace ~
22736 \InsetSpace ~
22737 \InsetSpace ~
22738 \InsetSpace ~
22739 \InsetSpace ~
22740 \InsetSpace ~
22741 \InsetSpace ~
22742 \InsetSpace ~
22743 mpasmwin /q /o $*.asm
22744 \newline
22745
22746 \newline
22747 $(PRJ).hex: $(OBJS)
22748  
22749 \newline
22750 \InsetSpace ~
22751 \InsetSpace ~
22752 \InsetSpace ~
22753 \InsetSpace ~
22754 \InsetSpace ~
22755 \InsetSpace ~
22756 \InsetSpace ~
22757 \InsetSpace ~
22758 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22759 \end_layout
22760
22761 \begin_layout Standard
22762 Please note that indentations within a
22763 \family typewriter
22764  Makefile
22765 \family default
22766  have to be done with a tabulator character.
22767 \end_layout
22768
22769 \begin_layout Subsection
22770 Command-line options
22771 \end_layout
22772
22773 \begin_layout Standard
22774 Besides the switches common to all SDCC backends, the PIC14 port accepts
22775  the following options (for an updated list see sdcc -
22776 \begin_inset ERT
22777 status collapsed
22778
22779 \begin_layout Standard
22780
22781
22782 \backslash
22783 /
22784 \end_layout
22785
22786 \end_inset
22787
22788 -help):
22789 \end_layout
22790
22791 \begin_layout List
22792 \labelwidthstring 00.00.0000
22793 -
22794 \begin_inset ERT
22795 status collapsed
22796
22797 \begin_layout Standard
22798
22799
22800 \backslash
22801 /
22802 \end_layout
22803
22804 \end_inset
22805
22806 -debug-xtra
22807 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22808
22809 \end_inset
22810
22811  emit debug info in assembly output
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 -no-pcode-opt
22830 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22831
22832 \end_inset
22833
22834  disable (slightly faulty) optimization on pCode
22835 \end_layout
22836
22837 \begin_layout List
22838 \labelwidthstring 00.00.0000
22839 -
22840 \begin_inset ERT
22841 status collapsed
22842
22843 \begin_layout Standard
22844
22845
22846 \backslash
22847 /
22848 \end_layout
22849
22850 \end_inset
22851
22852 -stack-loc
22853 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22854
22855 \end_inset
22856
22857  sets the lowest address of the argument passing stack (defaults to a suitably
22858  large shared databank to reduce BANKSEL overhead)
22859 \end_layout
22860
22861 \begin_layout List
22862 \labelwidthstring 00.00.0000
22863 -
22864 \begin_inset ERT
22865 status collapsed
22866
22867 \begin_layout Standard
22868
22869
22870 \backslash
22871 /
22872 \end_layout
22873
22874 \end_inset
22875
22876 -stack-size
22877 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22878
22879 \end_inset
22880
22881  sets the size if the argument passing stack (default: 16, minimum: 4)
22882 \end_layout
22883
22884 \begin_layout Subsection
22885 The library
22886 \end_layout
22887
22888 \begin_layout Subsubsection
22889 error: missing definition for symbol 
22890 \begin_inset Quotes sld
22891 \end_inset
22892
22893 __gptrget1
22894 \begin_inset Quotes srd
22895 \end_inset
22896
22897
22898 \end_layout
22899
22900 \begin_layout Standard
22901 The PIC14 port uses library routines to provide more complex operations
22902  like multiplication, division/modulus and (generic) pointer dereferencing.
22903  In order to add these routines to your project, you must link with PIC14's
22904  
22905 \family typewriter
22906 libsdcc.lib
22907 \family default
22908 .
22909  For single source file projects this is done automatically, more complex
22910  projects must add 
22911 \family typewriter
22912 libsdcc.lib
22913 \family default
22914  to the linker's arguments.
22915  Make sure you also add an include path for the library (using the -I switch
22916  to the linker)!
22917 \end_layout
22918
22919 \begin_layout Subsubsection
22920 Processor mismatch in file 
22921 \begin_inset Quotes sld
22922 \end_inset
22923
22924 XXX
22925 \begin_inset Quotes srd
22926 \end_inset
22927
22928 .
22929 \end_layout
22930
22931 \begin_layout Standard
22932 This warning can usually be ignored due to the very good compatibility amongst
22933  14 bit PIC
22934 \begin_inset LatexCommand \index{PIC14}
22935
22936 \end_inset
22937
22938  devices.
22939 \end_layout
22940
22941 \begin_layout Standard
22942 You might also consider recompiling the library for your specific device
22943  by changing the ARCH=p16f877 (default target) entry in 
22944 \family typewriter
22945 device/lib/pic/Makefile.in
22946 \family default
22947  and 
22948 \family typewriter
22949 device/lib/pic/Makefile
22950 \family default
22951  to reflect your device.
22952  This might even improve performance for smaller devices as unneccesary
22953  BANKSELs migth be removed.
22954 \end_layout
22955
22956 \begin_layout Subsection
22957 Known bugs
22958 \end_layout
22959
22960 \begin_layout Subsubsection
22961 initialized data
22962 \end_layout
22963
22964 \begin_layout Standard
22965 Currently, data can only be initialized if it resides in the source file
22966  together with 
22967 \emph on
22968 main()
22969 \emph default
22970 .
22971  Data in other source files will silently 
22972 \series bold
22973 not
22974 \series default
22975  be initialized.
22976 \family typewriter
22977 \size footnotesize
22978
22979 \begin_inset Marginal
22980 status collapsed
22981
22982 \begin_layout Standard
22983
22984 \series bold
22985 \InsetSpace ~
22986 !
22987 \end_layout
22988
22989 \end_inset
22990
22991
22992 \family default
22993
22994 \newpage
22995
22996 \end_layout
22997
22998 \begin_layout Section
22999 The PIC16
23000 \begin_inset LatexCommand \index{PIC16}
23001
23002 \end_inset
23003
23004  port
23005 \end_layout
23006
23007 \begin_layout Standard
23008 The PIC16
23009 \begin_inset LatexCommand \index{PIC16}
23010
23011 \end_inset
23012
23013  port is the portion of SDCC that is responsible to produce code for the
23014  Microchip
23015 \begin_inset LatexCommand \index{Microchip}
23016
23017 \end_inset
23018
23019 (TM) microcontrollers with 16 bit core.
23020  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
23021  Currently supported devices are:
23022 \end_layout
23023
23024 \begin_layout Standard
23025 \align center
23026 \begin_inset Tabular
23027 <lyxtabular version="3" rows="4" columns="6">
23028 <features>
23029 <column alignment="center" valignment="top" leftline="true" width="0">
23030 <column alignment="center" valignment="top" leftline="true" width="0">
23031 <column alignment="center" valignment="top" leftline="true" width="0">
23032 <column alignment="center" valignment="top" leftline="true" width="0">
23033 <column alignment="center" valignment="top" leftline="true" width="0">
23034 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23035 <row topline="true">
23036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23037 \begin_inset Text
23038
23039 \begin_layout Standard
23040 18F242
23041 \end_layout
23042
23043 \end_inset
23044 </cell>
23045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23046 \begin_inset Text
23047
23048 \begin_layout Standard
23049 18F248
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 18F252
23059 \end_layout
23060
23061 \end_inset
23062 </cell>
23063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23064 \begin_inset Text
23065
23066 \begin_layout Standard
23067 18F258
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 18F442
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 18F448
23086 \end_layout
23087
23088 \end_inset
23089 </cell>
23090 </row>
23091 <row topline="true">
23092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23093 \begin_inset Text
23094
23095 \begin_layout Standard
23096 18F452
23097 \end_layout
23098
23099 \end_inset
23100 </cell>
23101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23102 \begin_inset Text
23103
23104 \begin_layout Standard
23105 18F458
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 18F1220
23115 \end_layout
23116
23117 \end_inset
23118 </cell>
23119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23120 \begin_inset Text
23121
23122 \begin_layout Standard
23123 18F2220
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 18F2550
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 18F4331
23142 \end_layout
23143
23144 \end_inset
23145 </cell>
23146 </row>
23147 <row topline="true">
23148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23149 \begin_inset Text
23150
23151 \begin_layout Standard
23152 18F4455
23153 \end_layout
23154
23155 \end_inset
23156 </cell>
23157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23158 \begin_inset Text
23159
23160 \begin_layout Standard
23161 18F6520
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 18F6620
23171 \end_layout
23172
23173 \end_inset
23174 </cell>
23175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23176 \begin_inset Text
23177
23178 \begin_layout Standard
23179 18F6680
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 18F6720
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 18F8520
23198 \end_layout
23199
23200 \end_inset
23201 </cell>
23202 </row>
23203 <row topline="true" bottomline="true">
23204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23205 \begin_inset Text
23206
23207 \begin_layout Standard
23208 18F8620
23209 \end_layout
23210
23211 \end_inset
23212 </cell>
23213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23214 \begin_inset Text
23215
23216 \begin_layout Standard
23217 18F8680
23218 \end_layout
23219
23220 \end_inset
23221 </cell>
23222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23223 \begin_inset Text
23224
23225 \begin_layout Standard
23226 18F8720
23227 \end_layout
23228
23229 \end_inset
23230 </cell>
23231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23232 \begin_inset Text
23233
23234 \begin_layout Standard
23235
23236 \end_layout
23237
23238 \end_inset
23239 </cell>
23240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23241 \begin_inset Text
23242
23243 \begin_layout Standard
23244
23245 \end_layout
23246
23247 \end_inset
23248 </cell>
23249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23250 \begin_inset Text
23251
23252 \begin_layout Standard
23253
23254 \end_layout
23255
23256 \end_inset
23257 </cell>
23258 </row>
23259 </lyxtabular>
23260
23261 \end_inset
23262
23263
23264 \end_layout
23265
23266 \begin_layout Subsection
23267 Global Options
23268 \end_layout
23269
23270 \begin_layout Standard
23271 PIC16 port supports the standard command line arguments as supposed, with
23272  the exception of certain cases that will be mentioned in the following
23273  list:
23274 \end_layout
23275
23276 \begin_layout List
23277 \labelwidthstring 00.00.0000
23278 -
23279 \begin_inset ERT
23280 status collapsed
23281
23282 \begin_layout Standard
23283
23284
23285 \backslash
23286 /
23287 \end_layout
23288
23289 \end_inset
23290
23291 -callee-saves
23292 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23293
23294 \end_inset
23295
23296  See -
23297 \begin_inset ERT
23298 status collapsed
23299
23300 \begin_layout Standard
23301
23302
23303 \backslash
23304 /
23305 \end_layout
23306
23307 \end_inset
23308
23309 -all-callee-saves
23310 \end_layout
23311
23312 \begin_layout List
23313 \labelwidthstring 00.00.0000
23314 -
23315 \begin_inset ERT
23316 status collapsed
23317
23318 \begin_layout Standard
23319
23320
23321 \backslash
23322 /
23323 \end_layout
23324
23325 \end_inset
23326
23327 -fommit-frame-pointer
23328 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23329
23330 \end_inset
23331
23332  Frame pointer will be omitted when the function uses no local variables.
23333 \end_layout
23334
23335 \begin_layout Subsection
23336 Port Specific Options
23337 \begin_inset LatexCommand \index{Options PIC16}
23338
23339 \end_inset
23340
23341
23342 \end_layout
23343
23344 \begin_layout Standard
23345 The port specific options appear after the global options in the sdcc --help
23346  output.
23347 \end_layout
23348
23349 \begin_layout Subsubsection
23350 General Options
23351 \end_layout
23352
23353 \begin_layout Standard
23354 General options enable certain port features and optimizations.
23355 \end_layout
23356
23357 \begin_layout List
23358 \labelwidthstring 00.00.0000
23359 -
23360 \begin_inset ERT
23361 status collapsed
23362
23363 \begin_layout Standard
23364
23365
23366 \backslash
23367 /
23368 \end_layout
23369
23370 \end_inset
23371
23372 -pstack-model=[model] Used in conjuction with the command above.
23373  Defines the stack model to be used, valid stack models are : 
23374 \end_layout
23375
23376 \begin_deeper
23377 \begin_layout List
23378 \labelwidthstring 00.00.0000
23379
23380 \emph on
23381 small
23382 \emph default
23383  Selects small stack model.
23384  8 bit stack and frame pointers.
23385  Supports 256 bytes stack size.
23386 \end_layout
23387
23388 \begin_layout List
23389 \labelwidthstring 00.00.0000
23390
23391 \emph on
23392 large
23393 \emph default
23394  Selects large stack model.
23395  16 bit stack and frame pointers.
23396  Supports 65536 bytes stack size.
23397 \end_layout
23398
23399 \end_deeper
23400 \begin_layout List
23401 \labelwidthstring 00.00.0000
23402 -
23403 \begin_inset ERT
23404 status collapsed
23405
23406 \begin_layout Standard
23407
23408
23409 \backslash
23410 /
23411 \end_layout
23412
23413 \end_inset
23414
23415 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23416  unitialized data variables with [kword].
23417  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23418 \end_layout
23419
23420 \begin_layout List
23421 \labelwidthstring 00.00.0000
23422 -
23423 \begin_inset ERT
23424 status collapsed
23425
23426 \begin_layout Standard
23427
23428
23429 \backslash
23430 /
23431 \end_layout
23432
23433 \end_inset
23434
23435 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23436  Useful for bootloaders.
23437 \end_layout
23438
23439 \begin_layout List
23440 \labelwidthstring 00.00.0000
23441 -
23442 \begin_inset ERT
23443 status collapsed
23444
23445 \begin_layout Standard
23446
23447
23448 \backslash
23449 /
23450 \end_layout
23451
23452 \end_inset
23453
23454 -asm= sets the full path and name of an external assembler to call.
23455 \end_layout
23456
23457 \begin_layout List
23458 \labelwidthstring 00.00.0000
23459 -
23460 \begin_inset ERT
23461 status collapsed
23462
23463 \begin_layout Standard
23464
23465
23466 \backslash
23467 /
23468 \end_layout
23469
23470 \end_inset
23471
23472 -link= sets the full path and name of an external linker to call.
23473 \end_layout
23474
23475 \begin_layout List
23476 \labelwidthstring 00.00.0000
23477 -
23478 \begin_inset ERT
23479 status collapsed
23480
23481 \begin_layout Standard
23482
23483
23484 \backslash
23485 /
23486 \end_layout
23487
23488 \end_inset
23489
23490 -mplab-comp MPLAB
23491 \begin_inset LatexCommand \index{PIC16!MPLAB}
23492
23493 \end_inset
23494
23495  compatibility option.
23496  Currently only suppresses special gpasm directives.
23497 \end_layout
23498
23499 \begin_layout Subsubsection
23500 Optimization Options
23501 \end_layout
23502
23503 \begin_layout List
23504 \labelwidthstring 00.00.0000
23505 -
23506 \begin_inset ERT
23507 status collapsed
23508
23509 \begin_layout Standard
23510
23511
23512 \backslash
23513 /
23514 \end_layout
23515
23516 \end_inset
23517
23518 -optimize-goto Try to use (conditional) BRA instead of GOTO
23519 \end_layout
23520
23521 \begin_layout List
23522 \labelwidthstring 00.00.0000
23523 -
23524 \begin_inset ERT
23525 status collapsed
23526
23527 \begin_layout Standard
23528
23529
23530 \backslash
23531 /
23532 \end_layout
23533
23534 \end_inset
23535
23536 -optimize-cmp Try to optimize some compares.
23537 \end_layout
23538
23539 \begin_layout List
23540 \labelwidthstring 00.00.0000
23541 -
23542 \begin_inset ERT
23543 status collapsed
23544
23545 \begin_layout Standard
23546
23547
23548 \backslash
23549 /
23550 \end_layout
23551
23552 \end_inset
23553
23554 -optimize-df Analyze the dataflow of the generated code and improve it.
23555 \end_layout
23556
23557 \begin_layout List
23558 \labelwidthstring 00.00.0000
23559 -
23560 \begin_inset ERT
23561 status collapsed
23562
23563 \begin_layout Standard
23564
23565
23566 \backslash
23567 /
23568 \end_layout
23569
23570 \end_inset
23571
23572 -obanksel=nn Set optimization level for inserting BANKSELs.
23573 \newline
23574
23575 \end_layout
23576
23577 \begin_deeper
23578 \begin_layout List
23579 \labelwidthstring 00.00.0000
23580 0 no optimization
23581 \end_layout
23582
23583 \begin_layout List
23584 \labelwidthstring 00.00.0000
23585 1 checks previous used register and if it is the same then does not emit
23586  BANKSEL, accounts only for labels.
23587 \end_layout
23588
23589 \begin_layout List
23590 \labelwidthstring 00.00.0000
23591 2 tries to check the location of (even different) symbols and removes BANKSELs
23592  if they are in the same bank.
23593  
23594 \newline
23595
23596 \emph on
23597 Important: There might be problems if the linker script has data sections
23598  across bank borders!
23599 \end_layout
23600
23601 \end_deeper
23602 \begin_layout Subsubsection
23603 Linking Options
23604 \end_layout
23605
23606 \begin_layout List
23607 \labelwidthstring 00.00.0000
23608 -
23609 \begin_inset ERT
23610 status collapsed
23611
23612 \begin_layout Standard
23613
23614
23615 \backslash
23616 /
23617 \end_layout
23618
23619 \end_inset
23620
23621 -nodefaultlibs do not link default libraries when linking
23622 \end_layout
23623
23624 \begin_layout List
23625 \labelwidthstring 00.00.0000
23626 -
23627 \begin_inset ERT
23628 status collapsed
23629
23630 \begin_layout Standard
23631
23632
23633 \backslash
23634 /
23635 \end_layout
23636
23637 \end_inset
23638
23639 -no-crt Don't link the default run-time modules
23640 \end_layout
23641
23642 \begin_layout List
23643 \labelwidthstring 00.00.0000
23644 -
23645 \begin_inset ERT
23646 status collapsed
23647
23648 \begin_layout Standard
23649
23650
23651 \backslash
23652 /
23653 \end_layout
23654
23655 \end_inset
23656
23657 -use-crt= Use a custom run-time module instead of the defaults.
23658 \end_layout
23659
23660 \begin_layout Subsubsection
23661 Debugging Options
23662 \end_layout
23663
23664 \begin_layout Standard
23665 Debugging options enable extra debugging information in the output files.
23666 \end_layout
23667
23668 \begin_layout List
23669 \labelwidthstring 00.00.0000
23670 -
23671 \begin_inset ERT
23672 status collapsed
23673
23674 \begin_layout Standard
23675
23676
23677 \backslash
23678 /
23679 \end_layout
23680
23681 \end_inset
23682
23683 -debug-xtra Similar to -
23684 \begin_inset ERT
23685 status collapsed
23686
23687 \begin_layout Standard
23688
23689
23690 \backslash
23691 /
23692 \end_layout
23693
23694 \end_inset
23695
23696 -debug
23697 \begin_inset LatexCommand \index{-\/-debug}
23698
23699 \end_inset
23700
23701 , but dumps more information.
23702 \end_layout
23703
23704 \begin_layout List
23705 \labelwidthstring 00.00.0000
23706 -
23707 \begin_inset ERT
23708 status collapsed
23709
23710 \begin_layout Standard
23711
23712
23713 \backslash
23714 /
23715 \end_layout
23716
23717 \end_inset
23718
23719 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23720  information.
23721  <source> is the name of the file compiled.
23722 \end_layout
23723
23724 \begin_layout List
23725 \labelwidthstring 00.00.0000
23726 -
23727 \begin_inset ERT
23728 status collapsed
23729
23730 \begin_layout Standard
23731
23732
23733 \backslash
23734 /
23735 \end_layout
23736
23737 \end_inset
23738
23739 -pcode-verbose Enable pcode debugging information in translation.
23740 \end_layout
23741
23742 \begin_layout List
23743 \labelwidthstring 00.00.0000
23744 -
23745 \begin_inset ERT
23746 status collapsed
23747
23748 \begin_layout Standard
23749
23750
23751 \backslash
23752 /
23753 \end_layout
23754
23755 \end_inset
23756
23757 -denable-peeps Force the usage of peepholes.
23758  Use with care.
23759 \end_layout
23760
23761 \begin_layout List
23762 \labelwidthstring 00.00.0000
23763 -
23764 \begin_inset ERT
23765 status collapsed
23766
23767 \begin_layout Standard
23768
23769
23770 \backslash
23771 /
23772 \end_layout
23773
23774 \end_inset
23775
23776 -gstack Trace push/pops for stack pointer overflow
23777 \end_layout
23778
23779 \begin_layout List
23780 \labelwidthstring 00.00.0000
23781 -
23782 \begin_inset ERT
23783 status collapsed
23784
23785 \begin_layout Standard
23786
23787
23788 \backslash
23789 /
23790 \end_layout
23791
23792 \end_inset
23793
23794 -call-tree dump call tree in .calltree file
23795 \end_layout
23796
23797 \begin_layout Subsection
23798 Enviromental Variables
23799 \end_layout
23800
23801 \begin_layout Standard
23802 There is a number of enviromental variables that can be used when running
23803  SDCC to enable certain optimizations or force a specific program behaviour.
23804  these variables are primarily for debugging purposes so they can be enabled/dis
23805 abled at will.
23806 \end_layout
23807
23808 \begin_layout Standard
23809 Currently there is only two such variables available:
23810 \end_layout
23811
23812 \begin_layout List
23813 \labelwidthstring 00.00.0000
23814 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23815  bitfields is optimized by directly loading FSR0 with the address of the
23816  bitfield structure.
23817  Normally SDCC will cast the bitfield structure to a bitfield pointer and
23818  then load FSR0.
23819  This step saves data ram and code space for functions that perform heavy
23820  use of bitfields.
23821  (ie.
23822  80 bytes of code space are saved when compiling malloc.c with this option).
23823  
23824 \end_layout
23825
23826 \begin_layout List
23827 \labelwidthstring 00.00.0000
23828 NO_REG_OPT do not perform pCode registers optimization.
23829  This should be used for debugging purposes.
23830  In some where bugs in the pcode optimizer are found, users can benefit
23831  from temporarily disabling the optimizer until the bug is fixed.
23832 \end_layout
23833
23834 \begin_layout Subsection
23835 Preprocessor Macros
23836 \end_layout
23837
23838 \begin_layout Standard
23839 PIC16
23840 \begin_inset LatexCommand \index{PIC16}
23841
23842 \end_inset
23843
23844  port defines the following preprocessor macros while translating a source.
23845 \end_layout
23846
23847 \begin_layout Standard
23848 \align center
23849 \begin_inset Tabular
23850 <lyxtabular version="3" rows="6" columns="2">
23851 <features>
23852 <column alignment="center" valignment="top" leftline="true" width="0">
23853 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23854 <row topline="true" bottomline="true">
23855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23856 \begin_inset Text
23857
23858 \begin_layout Standard
23859 Macro
23860 \end_layout
23861
23862 \end_inset
23863 </cell>
23864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23865 \begin_inset Text
23866
23867 \begin_layout Standard
23868 Description
23869 \end_layout
23870
23871 \end_inset
23872 </cell>
23873 </row>
23874 <row topline="true">
23875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23876 \begin_inset Text
23877
23878 \begin_layout Standard
23879 SDCC_pic16
23880 \end_layout
23881
23882 \end_inset
23883 </cell>
23884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23885 \begin_inset Text
23886
23887 \begin_layout Standard
23888 Port identification
23889 \end_layout
23890
23891 \end_inset
23892 </cell>
23893 </row>
23894 <row topline="true">
23895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23896 \begin_inset Text
23897
23898 \begin_layout Standard
23899 _
23900 \begin_inset ERT
23901 status collapsed
23902
23903 \begin_layout Standard
23904
23905
23906 \backslash
23907 /
23908 \end_layout
23909
23910 \end_inset
23911
23912 _pic16
23913 \end_layout
23914
23915 \end_inset
23916 </cell>
23917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23918 \begin_inset Text
23919
23920 \begin_layout Standard
23921 Port identification (same as above)
23922 \end_layout
23923
23924 \end_inset
23925 </cell>
23926 </row>
23927 <row topline="true">
23928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23929 \begin_inset Text
23930
23931 \begin_layout Standard
23932 pic18fxxxx
23933 \end_layout
23934
23935 \end_inset
23936 </cell>
23937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23938 \begin_inset Text
23939
23940 \begin_layout Standard
23941 MCU Identification.
23942  
23943 \emph on
23944 xxxx
23945 \emph default
23946  is the microcontrol identification number, i.e.
23947  452, 6620, etc
23948 \end_layout
23949
23950 \end_inset
23951 </cell>
23952 </row>
23953 <row topline="true">
23954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23955 \begin_inset Text
23956
23957 \begin_layout Standard
23958 _
23959 \begin_inset ERT
23960 status collapsed
23961
23962 \begin_layout Standard
23963
23964
23965 \backslash
23966 /
23967 \end_layout
23968
23969 \end_inset
23970
23971 _18Fxxxx
23972 \end_layout
23973
23974 \end_inset
23975 </cell>
23976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23977 \begin_inset Text
23978
23979 \begin_layout Standard
23980 MCU Identification (same as above)
23981 \end_layout
23982
23983 \end_inset
23984 </cell>
23985 </row>
23986 <row topline="true" bottomline="true">
23987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23988 \begin_inset Text
23989
23990 \begin_layout Standard
23991 STACK_MODEL_nnn
23992 \end_layout
23993
23994 \end_inset
23995 </cell>
23996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23997 \begin_inset Text
23998
23999 \begin_layout Standard
24000 nnn = SMALL or LARGE respectively according to the stack model used
24001 \end_layout
24002
24003 \end_inset
24004 </cell>
24005 </row>
24006 </lyxtabular>
24007
24008 \end_inset
24009
24010
24011 \end_layout
24012
24013 \begin_layout Standard
24014 In addition the following macros are defined when calling assembler:
24015 \end_layout
24016
24017 \begin_layout Standard
24018 \align center
24019 \begin_inset Tabular
24020 <lyxtabular version="3" rows="4" columns="2">
24021 <features>
24022 <column alignment="center" valignment="top" leftline="true" width="0">
24023 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24024 <row topline="true" bottomline="true">
24025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24026 \begin_inset Text
24027
24028 \begin_layout Standard
24029 Macro
24030 \end_layout
24031
24032 \end_inset
24033 </cell>
24034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24035 \begin_inset Text
24036
24037 \begin_layout Standard
24038 Description
24039 \end_layout
24040
24041 \end_inset
24042 </cell>
24043 </row>
24044 <row topline="true">
24045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24046 \begin_inset Text
24047
24048 \begin_layout Standard
24049 __18Fxxxx
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 MCU Identification.
24059  
24060 \emph on
24061 xxxx
24062 \emph default
24063  is the microcontrol identification number, i.e.
24064  452, 6620, etc
24065 \end_layout
24066
24067 \end_inset
24068 </cell>
24069 </row>
24070 <row topline="true">
24071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24072 \begin_inset Text
24073
24074 \begin_layout Standard
24075 SDCC_MODEL_nnn
24076 \end_layout
24077
24078 \end_inset
24079 </cell>
24080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24081 \begin_inset Text
24082
24083 \begin_layout Standard
24084 nnn = SMALL or LARGE respectively according to the memory model used for
24085  SDCC
24086 \end_layout
24087
24088 \end_inset
24089 </cell>
24090 </row>
24091 <row topline="true" bottomline="true">
24092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24093 \begin_inset Text
24094
24095 \begin_layout Standard
24096 STACK_MODEL_nnn
24097 \end_layout
24098
24099 \end_inset
24100 </cell>
24101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24102 \begin_inset Text
24103
24104 \begin_layout Standard
24105 nnn = SMALL or LARGE respectively according to the stack model used
24106 \end_layout
24107
24108 \end_inset
24109 </cell>
24110 </row>
24111 </lyxtabular>
24112
24113 \end_inset
24114
24115
24116 \end_layout
24117
24118 \begin_layout Subsection
24119 Directories
24120 \end_layout
24121
24122 \begin_layout Standard
24123 PIC16
24124 \begin_inset LatexCommand \index{PIC16}
24125
24126 \end_inset
24127
24128  port uses the following directories for searching header files and libraries.
24129 \end_layout
24130
24131 \begin_layout Standard
24132 \align center
24133 \begin_inset Tabular
24134 <lyxtabular version="3" rows="3" columns="4">
24135 <features>
24136 <column alignment="center" valignment="top" leftline="true" width="0">
24137 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24138 <column alignment="center" valignment="top" width="0">
24139 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24140 <row topline="true" bottomline="true">
24141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24142 \begin_inset Text
24143
24144 \begin_layout Standard
24145 Directory
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 Description
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 Target
24164 \end_layout
24165
24166 \end_inset
24167 </cell>
24168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24169 \begin_inset Text
24170
24171 \begin_layout Standard
24172 Command prefix
24173 \end_layout
24174
24175 \end_inset
24176 </cell>
24177 </row>
24178 <row topline="true">
24179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24180 \begin_inset Text
24181
24182 \begin_layout Standard
24183 PREFIX/sdcc/include/pic16
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 PIC16 specific headers
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 Compiler
24202 \end_layout
24203
24204 \end_inset
24205 </cell>
24206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24207 \begin_inset Text
24208
24209 \begin_layout Standard
24210 -I
24211 \end_layout
24212
24213 \end_inset
24214 </cell>
24215 </row>
24216 <row topline="true" bottomline="true">
24217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24218 \begin_inset Text
24219
24220 \begin_layout Standard
24221 PREFIX/sdcc/lib/pic16
24222 \end_layout
24223
24224 \end_inset
24225 </cell>
24226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24227 \begin_inset Text
24228
24229 \begin_layout Standard
24230 PIC16 specific libraries
24231 \end_layout
24232
24233 \end_inset
24234 </cell>
24235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24236 \begin_inset Text
24237
24238 \begin_layout Standard
24239 Linker
24240 \end_layout
24241
24242 \end_inset
24243 </cell>
24244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24245 \begin_inset Text
24246
24247 \begin_layout Standard
24248 -L
24249 \end_layout
24250
24251 \end_inset
24252 </cell>
24253 </row>
24254 </lyxtabular>
24255
24256 \end_inset
24257
24258
24259 \end_layout
24260
24261 \begin_layout Subsection
24262 Pragmas
24263 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24264
24265 \end_inset
24266
24267
24268 \end_layout
24269
24270 \begin_layout Standard
24271 PIC16
24272 \begin_inset LatexCommand \index{PIC16}
24273
24274 \end_inset
24275
24276  port currently supports the following pragmas:
24277 \end_layout
24278
24279 \begin_layout List
24280 \labelwidthstring 00.00.0000
24281 stack
24282 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24283
24284 \end_inset
24285
24286  pragma stack
24287 \begin_inset LatexCommand \index{PIC16!stack}
24288
24289 \end_inset
24290
24291  forces the code generator to initialize the stack & frame pointers at a
24292  specific address.
24293  This is an adhoc solution for cases where no STACK directive is available
24294  in the linker script or gplink is not instructed to create a stack section.
24295 \newline
24296 The
24297  stack pragma should be used only once in a project.
24298  Multiple pragmas may result in indeterminate behaviour of the program.
24299 \begin_inset Foot
24300 status open
24301
24302 \begin_layout Standard
24303 The old format (ie.
24304  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24305  cross page boundaries (or even exceed the available data RAM) and crash
24306  the program.
24307  Make sure that stack does not cross page boundaries when using the SMALL
24308  stack model.
24309 \end_layout
24310
24311 \end_inset
24312
24313
24314 \newline
24315 The format is as follows:
24316 \end_layout
24317
24318 \begin_layout LyX-Code
24319 #pragma stack bottom_address [stack_size]
24320 \end_layout
24321
24322 \begin_layout Standard
24323
24324 \emph on
24325 bottom_address
24326 \emph default
24327  is the lower bound of the stack section.
24328  The stack pointer initially will point at address (bottom_address+stack_size-1).
24329 \end_layout
24330
24331 \begin_layout LyX-Code
24332 Example:
24333 \end_layout
24334
24335 \begin_layout LyX-Code
24336
24337 \end_layout
24338
24339 \begin_layout LyX-Code
24340 /* initializes stack of 100 bytes at RAM address 0x200 */
24341 \end_layout
24342
24343 \begin_layout LyX-Code
24344 #pragma stack 0x200 100
24345 \end_layout
24346
24347 \begin_layout Standard
24348 If the stack_size field is omitted then a stack is created with the default
24349  size of 64.
24350  This size might be enough for most programs, but its not enough for operations
24351  with deep function nesting or excessive stack usage.
24352 \end_layout
24353
24354 \begin_layout List
24355 \labelwidthstring 00.00.0000
24356 code
24357 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24358
24359 \end_inset
24360
24361  place a function symbol at static FLASH address
24362 \end_layout
24363
24364 \begin_layout LyX-Code
24365 Example:
24366 \end_layout
24367
24368 \begin_layout LyX-Code
24369
24370 \end_layout
24371
24372 \begin_layout LyX-Code
24373 /* place function test_func at 0x4000 */
24374 \end_layout
24375
24376 \begin_layout LyX-Code
24377 #pragma code test_func 0x4000
24378 \end_layout
24379
24380 \begin_layout LyX-Code
24381
24382 \end_layout
24383
24384 \begin_layout List
24385 \labelwidthstring 00.00.0000
24386 library instructs the linker to use a library module.
24387 \newline
24388 Usage:
24389 \end_layout
24390
24391 \begin_layout LyX-Code
24392 #pragma library module_name
24393 \end_layout
24394
24395 \begin_layout Standard
24396
24397 \emph on
24398 module_name
24399 \emph default
24400  can be any library or object file (including its path).
24401  Note that there are four reserved keywords which have special meaning.
24402  These are:
24403 \end_layout
24404
24405 \begin_layout Standard
24406 \align center
24407 \begin_inset Tabular
24408 <lyxtabular version="3" rows="6" columns="3">
24409 <features>
24410 <column alignment="center" valignment="top" leftline="true" width="0">
24411 <column alignment="block" valignment="top" leftline="true" width="20page%">
24412 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24413 <row topline="true" bottomline="true">
24414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24415 \begin_inset Text
24416
24417 \begin_layout Standard
24418 Keyword
24419 \end_layout
24420
24421 \end_inset
24422 </cell>
24423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24424 \begin_inset Text
24425
24426 \begin_layout Standard
24427 Description
24428 \end_layout
24429
24430 \end_inset
24431 </cell>
24432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24433 \begin_inset Text
24434
24435 \begin_layout Standard
24436 Module to link
24437 \end_layout
24438
24439 \end_inset
24440 </cell>
24441 </row>
24442 <row topline="true">
24443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24444 \begin_inset Text
24445
24446 \begin_layout Standard
24447
24448 \series bold
24449 ignore
24450 \end_layout
24451
24452 \end_inset
24453 </cell>
24454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24455 \begin_inset Text
24456
24457 \begin_layout Standard
24458 ignore all library pragmas
24459 \end_layout
24460
24461 \end_inset
24462 </cell>
24463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24464 \begin_inset Text
24465
24466 \begin_layout Standard
24467
24468 \emph on
24469 (none)
24470 \end_layout
24471
24472 \end_inset
24473 </cell>
24474 </row>
24475 <row topline="true">
24476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24477 \begin_inset Text
24478
24479 \begin_layout Standard
24480
24481 \series bold
24482 c
24483 \end_layout
24484
24485 \end_inset
24486 </cell>
24487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24488 \begin_inset Text
24489
24490 \begin_layout Standard
24491 link the C library
24492 \end_layout
24493
24494 \end_inset
24495 </cell>
24496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24497 \begin_inset Text
24498
24499 \begin_layout Standard
24500
24501 \emph on
24502 libc18f
24503 \emph default
24504 .lib
24505 \end_layout
24506
24507 \end_inset
24508 </cell>
24509 </row>
24510 <row topline="true">
24511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24512 \begin_inset Text
24513
24514 \begin_layout Standard
24515
24516 \series bold
24517 math
24518 \end_layout
24519
24520 \end_inset
24521 </cell>
24522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24523 \begin_inset Text
24524
24525 \begin_layout Standard
24526 link the Math libarary
24527 \end_layout
24528
24529 \end_inset
24530 </cell>
24531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24532 \begin_inset Text
24533
24534 \begin_layout Standard
24535
24536 \emph on
24537 libm18f
24538 \emph default
24539 .lib
24540 \end_layout
24541
24542 \end_inset
24543 </cell>
24544 </row>
24545 <row topline="true">
24546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24547 \begin_inset Text
24548
24549 \begin_layout Standard
24550
24551 \series bold
24552 io
24553 \end_layout
24554
24555 \end_inset
24556 </cell>
24557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24558 \begin_inset Text
24559
24560 \begin_layout Standard
24561 link the I/O library
24562 \end_layout
24563
24564 \end_inset
24565 </cell>
24566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24567 \begin_inset Text
24568
24569 \begin_layout Standard
24570
24571 \emph on
24572 libio18f*
24573 \emph default
24574 .lib
24575 \end_layout
24576
24577 \end_inset
24578 </cell>
24579 </row>
24580 <row topline="true" bottomline="true">
24581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24582 \begin_inset Text
24583
24584 \begin_layout Standard
24585
24586 \series bold
24587 debug
24588 \end_layout
24589
24590 \end_inset
24591 </cell>
24592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24593 \begin_inset Text
24594
24595 \begin_layout Standard
24596 link the debug library
24597 \end_layout
24598
24599 \end_inset
24600 </cell>
24601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24602 \begin_inset Text
24603
24604 \begin_layout Standard
24605
24606 \emph on
24607 libdebug
24608 \emph default
24609 .lib
24610 \end_layout
24611
24612 \end_inset
24613 </cell>
24614 </row>
24615 </lyxtabular>
24616
24617 \end_inset
24618
24619
24620 \newline
24621 * is the device number, i.e.
24622  452 for PIC18F452 MCU.
24623 \end_layout
24624
24625 \begin_layout Standard
24626 This feature allows for linking with specific libraries withoug having to
24627  explicit name them in the command line.
24628  Note that the 
24629 \noun on
24630 ignore
24631 \noun default
24632  keyword will reject all modules specified by the library pragma.
24633 \end_layout
24634
24635 \begin_layout List
24636 \labelwidthstring 00.00.0000
24637 udata pragma udata instructs the compiler to emit code so that linker will
24638  place a variable at a specific memory bank
24639 \end_layout
24640
24641 \begin_layout LyX-Code
24642 Example:
24643 \end_layout
24644
24645 \begin_layout LyX-Code
24646
24647 \end_layout
24648
24649 \begin_layout LyX-Code
24650 /* places variable foo at bank2 */
24651 \end_layout
24652
24653 \begin_layout LyX-Code
24654 #pragma udata bank2 foo
24655 \end_layout
24656
24657 \begin_layout LyX-Code
24658 char foo;
24659 \end_layout
24660
24661 \begin_layout Standard
24662 In order for this pragma to work extra SECTION directives should be added
24663  in the .lkr script.
24664  In the following example a sample .lkr file is shown:
24665 \end_layout
24666
24667 \begin_layout LyX-Code
24668
24669 \end_layout
24670
24671 \begin_layout LyX-Code
24672 // Sample linker script for the PIC18F452 processor
24673 \end_layout
24674
24675 \begin_layout LyX-Code
24676 LIBPATH .
24677 \end_layout
24678
24679 \begin_layout LyX-Code
24680 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24681 \end_layout
24682
24683 \begin_layout LyX-Code
24684 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24685 \end_layout
24686
24687 \begin_layout LyX-Code
24688 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24689 \end_layout
24690
24691 \begin_layout LyX-Code
24692 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24693 \end_layout
24694
24695 \begin_layout LyX-Code
24696 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24697 \end_layout
24698
24699 \begin_layout LyX-Code
24700 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24701 \end_layout
24702
24703 \begin_layout LyX-Code
24704 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24705 \end_layout
24706
24707 \begin_layout LyX-Code
24708
24709 \end_layout
24710
24711 \begin_layout LyX-Code
24712 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24713 \end_layout
24714
24715 \begin_layout LyX-Code
24716 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24717 \end_layout
24718
24719 \begin_layout LyX-Code
24720 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24721 \end_layout
24722
24723 \begin_layout LyX-Code
24724 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24725 \end_layout
24726
24727 \begin_layout LyX-Code
24728 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24729 \end_layout
24730
24731 \begin_layout LyX-Code
24732 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24733 \end_layout
24734
24735 \begin_layout LyX-Code
24736 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24737 \end_layout
24738
24739 \begin_layout LyX-Code
24740
24741 \end_layout
24742
24743 \begin_layout LyX-Code
24744 SECTION    NAME=CONFIG     ROM=config
24745 \end_layout
24746
24747 \begin_layout LyX-Code
24748
24749 \end_layout
24750
24751 \begin_layout LyX-Code
24752 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
24753 \end_layout
24754
24755 \begin_layout LyX-Code
24756 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
24757 \end_layout
24758
24759 \begin_layout LyX-Code
24760 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
24761 \end_layout
24762
24763 \begin_layout LyX-Code
24764 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
24765 \end_layout
24766
24767 \begin_layout LyX-Code
24768 SECTION    NAME=bank4      RAM=gpr4
24769 \end_layout
24770
24771 \begin_layout LyX-Code
24772 SECTION    NAME=bank5      RAM=gpr5
24773 \end_layout
24774
24775 \begin_layout Standard
24776 The linker will recognise the section name set in the pragma statement and
24777  will position the variable at the memory bank set with the RAM field at
24778  the SECTION line in the linker script file.
24779 \end_layout
24780
24781 \begin_layout Subsection
24782 Header Files
24783 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24784
24785 \end_inset
24786
24787
24788 \end_layout
24789
24790 \begin_layout Standard
24791 There is one main header file
24792 \begin_inset LatexCommand \index{PIC16!Header files}
24793
24794 \end_inset
24795
24796  that can be included to the source files using the pic16
24797 \begin_inset LatexCommand \index{PIC16}
24798
24799 \end_inset
24800
24801  port.
24802  That file is the 
24803 \series bold
24804 pic18fregs.h
24805 \series default
24806 .
24807  This header file contains the definitions for the processor special registers,
24808  so it is necessary if the source accesses them.
24809  It can be included by adding the following line in the beginning of the
24810  file:
24811 \end_layout
24812
24813 \begin_layout LyX-Code
24814 #include <pic18fregs.h>
24815 \end_layout
24816
24817 \begin_layout Standard
24818 The specific microcontroller is selected within the pic18fregs.h automatically,
24819  so the same source can be used with a variety of devices.
24820 \end_layout
24821
24822 \begin_layout Subsection
24823 Libraries
24824 \end_layout
24825
24826 \begin_layout Standard
24827 The libraries
24828 \begin_inset LatexCommand \index{PIC16!Libraries}
24829
24830 \end_inset
24831
24832  that PIC16
24833 \begin_inset LatexCommand \index{PIC16}
24834
24835 \end_inset
24836
24837  port depends on are the microcontroller device libraries which contain
24838  the symbol definitions for the microcontroller special function registers.
24839  These libraries have the format pic18fxxxx.lib, where 
24840 \emph on
24841 xxxx
24842 \emph default
24843  is the microcontroller identification number.
24844  The specific library is selected automatically by the compiler at link
24845  stage according to the selected device.
24846 \end_layout
24847
24848 \begin_layout Standard
24849 Libraries are created with gplib which is part of the gputils package 
24850 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24851
24852 \end_inset
24853
24854 .
24855 \end_layout
24856
24857 \begin_layout Subsubsection*
24858 Building the libraries
24859 \end_layout
24860
24861 \begin_layout Standard
24862 Before using SDCC/pic16 there are some libraries that need to be compiled.
24863  This process is not done automatically by SDCC since not all users use
24864  SDCC for pic16 projects.
24865  So each user should compile the libraries separately.
24866 \end_layout
24867
24868 \begin_layout Standard
24869 The steps to compile the pic16 libraries under Linux and Mac OS X are:
24870 \end_layout
24871
24872 \begin_layout LyX-Code
24873 cd device/lib/pic16
24874 \end_layout
24875
24876 \begin_layout LyX-Code
24877 ./configure
24878 \end_layout
24879
24880 \begin_layout LyX-Code
24881 make
24882 \end_layout
24883
24884 \begin_layout LyX-Code
24885 cd ..
24886 \end_layout
24887
24888 \begin_layout LyX-Code
24889 make model-pic16
24890 \end_layout
24891
24892 \begin_layout LyX-Code
24893 su -c 'make install'     # install the libraries, you need the root password
24894 \end_layout
24895
24896 \begin_layout Standard
24897 If you need to install the headers too, do:
24898 \end_layout
24899
24900 \begin_layout LyX-Code
24901 cd device/include
24902 \end_layout
24903
24904 \begin_layout LyX-Code
24905 su -c 'make install'     # install the headers, you need the root password
24906 \end_layout
24907
24908 \begin_layout Standard
24909 There exist a special target to build the I/O libraries.
24910  This target is not automatically build because it will build the I/O library
24911  for 
24912 \emph on
24913 every
24914 \emph default
24915  supported device.
24916  This way building will take quite a lot of time.
24917  Users are advised to edit the 
24918 \series bold
24919 device/lib/pic16/pics.build
24920 \series default
24921  file and then execute:
24922 \end_layout
24923
24924 \begin_layout LyX-Code
24925 make lib-io
24926 \end_layout
24927
24928 \begin_layout Subsection
24929 Memory Models
24930 \end_layout
24931
24932 \begin_layout Standard
24933 The following memory models are supported by the PIC16 port:
24934 \end_layout
24935
24936 \begin_layout Itemize
24937 small model
24938 \end_layout
24939
24940 \begin_layout Itemize
24941 large model
24942 \end_layout
24943
24944 \begin_layout Standard
24945 Memory model affects the default size of pointers within the source.
24946  The sizes are shown in the next table:
24947 \end_layout
24948
24949 \begin_layout Standard
24950 \align center
24951 \begin_inset Tabular
24952 <lyxtabular version="3" rows="3" columns="3">
24953 <features>
24954 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24955 <column alignment="center" valignment="top" leftline="true" width="0">
24956 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24957 <row topline="true" bottomline="true">
24958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24959 \begin_inset Text
24960
24961 \begin_layout Standard
24962 Pointer sizes according to memory model
24963 \end_layout
24964
24965 \end_inset
24966 </cell>
24967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24968 \begin_inset Text
24969
24970 \begin_layout Standard
24971 small model
24972 \end_layout
24973
24974 \end_inset
24975 </cell>
24976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24977 \begin_inset Text
24978
24979 \begin_layout Standard
24980 large model
24981 \end_layout
24982
24983 \end_inset
24984 </cell>
24985 </row>
24986 <row topline="true" bottomline="true">
24987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24988 \begin_inset Text
24989
24990 \begin_layout Standard
24991 code pointers
24992 \end_layout
24993
24994 \end_inset
24995 </cell>
24996 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24997 \begin_inset Text
24998
24999 \begin_layout Standard
25000 16-bits
25001 \end_layout
25002
25003 \end_inset
25004 </cell>
25005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25006 \begin_inset Text
25007
25008 \begin_layout Standard
25009 24-bits
25010 \end_layout
25011
25012 \end_inset
25013 </cell>
25014 </row>
25015 <row topline="true" bottomline="true">
25016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25017 \begin_inset Text
25018
25019 \begin_layout Standard
25020 data pointers
25021 \end_layout
25022
25023 \end_inset
25024 </cell>
25025 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25026 \begin_inset Text
25027
25028 \begin_layout Standard
25029 16-bits
25030 \end_layout
25031
25032 \end_inset
25033 </cell>
25034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25035 \begin_inset Text
25036
25037 \begin_layout Standard
25038 16-bits
25039 \end_layout
25040
25041 \end_inset
25042 </cell>
25043 </row>
25044 </lyxtabular>
25045
25046 \end_inset
25047
25048
25049 \end_layout
25050
25051 \begin_layout Standard
25052 It is advisable that all sources within a project are compiled with the
25053  same memory model.
25054  If one wants to override the default memory model, this can be done by
25055  declaring a pointer as 
25056 \series bold
25057 far
25058 \series default
25059  or 
25060 \series bold
25061 near
25062 \series default
25063 .
25064  Far selects large memory model's pointers, while near selects small memory
25065  model's pointers.
25066 \end_layout
25067
25068 \begin_layout Standard
25069 The standard device libraries (see 
25070 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25071
25072 \end_inset
25073
25074 ) contain no reference to pointers, so they can be used with both memory
25075  models.
25076 \end_layout
25077
25078 \begin_layout Subsection
25079 Stack
25080 \end_layout
25081
25082 \begin_layout Standard
25083 The stack
25084 \begin_inset LatexCommand \index{PIC16!stack}
25085
25086 \end_inset
25087
25088  implementation for the PIC16 port uses two indirect registers, FSR1 and
25089  FSR2.
25090 \end_layout
25091
25092 \begin_layout List
25093 \labelwidthstring 00.00.0000
25094 FSR1 is assigned as stack pointer
25095 \end_layout
25096
25097 \begin_layout List
25098 \labelwidthstring 00.00.0000
25099 FSR2 is assigned as frame pointer
25100 \end_layout
25101
25102 \begin_layout Standard
25103 The following stack models are supported by the PIC16 port
25104 \end_layout
25105
25106 \begin_layout Itemize
25107
25108 \noun on
25109 small
25110 \noun default
25111  model
25112 \end_layout
25113
25114 \begin_layout Itemize
25115
25116 \noun on
25117 large
25118 \noun default
25119  model
25120 \end_layout
25121
25122 \begin_layout Standard
25123
25124 \noun on
25125 Small
25126 \noun default
25127  model means that only the FSRxL byte is used to access stack and frame,
25128  while 
25129 \emph on
25130 \noun on
25131 large
25132 \emph default
25133 \noun default
25134  uses both FSRxL and FSRxH registers.
25135  The following table shows the stack/frame pointers sizes according to stack
25136  model and the maximum space they can address:
25137 \end_layout
25138
25139 \begin_layout Standard
25140 \align center
25141 \begin_inset Tabular
25142 <lyxtabular version="3" rows="3" columns="3">
25143 <features>
25144 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25145 <column alignment="center" valignment="top" leftline="true" width="0">
25146 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25147 <row topline="true" bottomline="true">
25148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25149 \begin_inset Text
25150
25151 \begin_layout Standard
25152 Stack & Frame pointer sizes according to stack model
25153 \end_layout
25154
25155 \end_inset
25156 </cell>
25157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25158 \begin_inset Text
25159
25160 \begin_layout Standard
25161 small
25162 \end_layout
25163
25164 \end_inset
25165 </cell>
25166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25167 \begin_inset Text
25168
25169 \begin_layout Standard
25170 large
25171 \end_layout
25172
25173 \end_inset
25174 </cell>
25175 </row>
25176 <row topline="true">
25177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25178 \begin_inset Text
25179
25180 \begin_layout Standard
25181 Stack pointer FSR1
25182 \end_layout
25183
25184 \end_inset
25185 </cell>
25186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25187 \begin_inset Text
25188
25189 \begin_layout Standard
25190 8-bits
25191 \end_layout
25192
25193 \end_inset
25194 </cell>
25195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25196 \begin_inset Text
25197
25198 \begin_layout Standard
25199 16-bits
25200 \end_layout
25201
25202 \end_inset
25203 </cell>
25204 </row>
25205 <row topline="true" bottomline="true">
25206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25207 \begin_inset Text
25208
25209 \begin_layout Standard
25210 Frame pointer FSR2
25211 \end_layout
25212
25213 \end_inset
25214 </cell>
25215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25216 \begin_inset Text
25217
25218 \begin_layout Standard
25219 8-bits
25220 \end_layout
25221
25222 \end_inset
25223 </cell>
25224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25225 \begin_inset Text
25226
25227 \begin_layout Standard
25228 16-bits
25229 \end_layout
25230
25231 \end_inset
25232 </cell>
25233 </row>
25234 </lyxtabular>
25235
25236 \end_inset
25237
25238
25239 \end_layout
25240
25241 \begin_layout Standard
25242
25243 \noun on
25244 Large 
25245 \noun default
25246 stack model is currently not working properly throughout the code generator.
25247  So its use is not advised.
25248  Also there are some other points that need special care:
25249 \newline
25250
25251 \end_layout
25252
25253 \begin_layout Enumerate
25254 Do not create stack sections with size more than one physical bank (that
25255  is 256 bytes)
25256 \end_layout
25257
25258 \begin_layout Enumerate
25259 Stack sections should no cross physical bank limits (i.e.
25260  #pragma stack 0x50 0x100)
25261 \end_layout
25262
25263 \begin_layout Standard
25264 These limitations are caused by the fact that only FSRxL is modified when
25265  using SMALL stack model, so no more than 256 bytes of stack can be used.
25266  This problem will disappear after LARGE model is fully implemented.
25267 \end_layout
25268
25269 \begin_layout Subsection
25270 Functions
25271 \end_layout
25272
25273 \begin_layout Standard
25274 In addition to the standard SDCC function keywords, PIC16
25275 \begin_inset LatexCommand \index{PIC16}
25276
25277 \end_inset
25278
25279  port makes available two more:
25280 \end_layout
25281
25282 \begin_layout List
25283 \labelwidthstring 00.00.0000
25284 wparam
25285 \begin_inset LatexCommand \index{PIC16!wparam}
25286
25287 \end_inset
25288
25289  Use the WREG to pass one byte of the first function argument.
25290  This improves speed but you may not use this for functions with arguments
25291  that are called via function pointers, otherwise the first byte of the
25292  first parameter will get lost.
25293  Usage:
25294 \end_layout
25295
25296 \begin_layout LyX-Code
25297 void func_wparam(int a) wparam
25298 \end_layout
25299
25300 \begin_layout LyX-Code
25301 {
25302 \end_layout
25303
25304 \begin_layout LyX-Code
25305     /* WREG hold the lower part of a */
25306 \end_layout
25307
25308 \begin_layout LyX-Code
25309     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25310  */
25311 \end_layout
25312
25313 \begin_layout LyX-Code
25314 ...
25315 \end_layout
25316
25317 \begin_layout LyX-Code
25318 }
25319 \end_layout
25320
25321 \begin_layout List
25322 \labelwidthstring 00.00.0000
25323 shadowregs
25324 \begin_inset LatexCommand \index{PIC16!shadowregs}
25325
25326 \end_inset
25327
25328  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25329  hardware shadow registers which hold the values of WREG, STATUS and BSR
25330  registers.
25331  This can be done by adding the keyword 
25332 \emph on
25333 shadowregs
25334 \emph default
25335  before the 
25336 \emph on
25337 interrupt
25338 \emph default
25339  keyword in the function's header.
25340 \end_layout
25341
25342 \begin_layout LyX-Code
25343 void isr_shadow(void) shadowregs interrupt 1
25344 \end_layout
25345
25346 \begin_layout LyX-Code
25347 {
25348 \end_layout
25349
25350 \begin_layout LyX-Code
25351 ...
25352 \end_layout
25353
25354 \begin_layout LyX-Code
25355 }
25356 \end_layout
25357
25358 \begin_layout Standard
25359
25360 \emph on
25361 shadowregs
25362 \emph default
25363  instructs the code generator not to store/restore WREG, STATUS, BSR when
25364  entering/exiting the ISR.
25365 \end_layout
25366
25367 \begin_layout Subsection
25368 Function return values
25369 \end_layout
25370
25371 \begin_layout Standard
25372 Return values from functions are placed to the appropriate registers following
25373  a modified Microchip policy optimized for SDCC.
25374  The following table shows these registers:
25375 \end_layout
25376
25377 \begin_layout Standard
25378 \align center
25379 \begin_inset Tabular
25380 <lyxtabular version="3" rows="6" columns="2">
25381 <features>
25382 <column alignment="center" valignment="top" leftline="true" width="0">
25383 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25384 <row topline="true" bottomline="true">
25385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25386 \begin_inset Text
25387
25388 \begin_layout Standard
25389 size
25390 \end_layout
25391
25392 \end_inset
25393 </cell>
25394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25395 \begin_inset Text
25396
25397 \begin_layout Standard
25398 destination register
25399 \end_layout
25400
25401 \end_inset
25402 </cell>
25403 </row>
25404 <row topline="true">
25405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25406 \begin_inset Text
25407
25408 \begin_layout Standard
25409 8 bits
25410 \end_layout
25411
25412 \end_inset
25413 </cell>
25414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25415 \begin_inset Text
25416
25417 \begin_layout Standard
25418 WREG
25419 \end_layout
25420
25421 \end_inset
25422 </cell>
25423 </row>
25424 <row topline="true">
25425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25426 \begin_inset Text
25427
25428 \begin_layout Standard
25429 16 bits
25430 \end_layout
25431
25432 \end_inset
25433 </cell>
25434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25435 \begin_inset Text
25436
25437 \begin_layout Standard
25438 PRODL:WREG
25439 \end_layout
25440
25441 \end_inset
25442 </cell>
25443 </row>
25444 <row topline="true">
25445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25446 \begin_inset Text
25447
25448 \begin_layout Standard
25449 24 bits
25450 \end_layout
25451
25452 \end_inset
25453 </cell>
25454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25455 \begin_inset Text
25456
25457 \begin_layout Standard
25458 PRODH:PRODL:WREG
25459 \end_layout
25460
25461 \end_inset
25462 </cell>
25463 </row>
25464 <row topline="true">
25465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25466 \begin_inset Text
25467
25468 \begin_layout Standard
25469 32 bits
25470 \end_layout
25471
25472 \end_inset
25473 </cell>
25474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25475 \begin_inset Text
25476
25477 \begin_layout Standard
25478 FSR0L:PRODH:PRODL:WREG
25479 \end_layout
25480
25481 \end_inset
25482 </cell>
25483 </row>
25484 <row topline="true" bottomline="true">
25485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25486 \begin_inset Text
25487
25488 \begin_layout Standard
25489 >32 bits
25490 \end_layout
25491
25492 \end_inset
25493 </cell>
25494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25495 \begin_inset Text
25496
25497 \begin_layout Standard
25498 on stack, FSR0 points to the beginning
25499 \end_layout
25500
25501 \end_inset
25502 </cell>
25503 </row>
25504 </lyxtabular>
25505
25506 \end_inset
25507
25508
25509 \end_layout
25510
25511 \begin_layout Subsection
25512 Interrupts
25513 \end_layout
25514
25515 \begin_layout Standard
25516 An interrupt
25517 \begin_inset LatexCommand \index{PIC16!interrupt}
25518
25519 \end_inset
25520
25521  service routine (ISR) is declared using the 
25522 \emph on
25523 interrupt
25524 \emph default
25525  keyword.
25526 \end_layout
25527
25528 \begin_layout LyX-Code
25529 void isr(void) interrupt 
25530 \emph on
25531 n
25532 \end_layout
25533
25534 \begin_layout LyX-Code
25535 {
25536 \end_layout
25537
25538 \begin_layout LyX-Code
25539 ...
25540 \end_layout
25541
25542 \begin_layout LyX-Code
25543 }
25544 \end_layout
25545
25546 \begin_layout Standard
25547
25548 \emph on
25549 n
25550 \emph default
25551  is the interrupt number, which for PIC18F devices can be:
25552 \end_layout
25553
25554 \begin_layout Standard
25555 \align center
25556 \begin_inset Tabular
25557 <lyxtabular version="3" rows="4" columns="3">
25558 <features>
25559 <column alignment="center" valignment="top" leftline="true" width="0">
25560 <column alignment="center" valignment="top" leftline="true" width="0">
25561 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25562 <row topline="true" bottomline="true">
25563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25564 \begin_inset Text
25565
25566 \begin_layout Standard
25567
25568 \emph on
25569 n
25570 \end_layout
25571
25572 \end_inset
25573 </cell>
25574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25575 \begin_inset Text
25576
25577 \begin_layout Standard
25578 Interrupt Vector
25579 \end_layout
25580
25581 \end_inset
25582 </cell>
25583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25584 \begin_inset Text
25585
25586 \begin_layout Standard
25587 Interrupt Vector Address
25588 \end_layout
25589
25590 \end_inset
25591 </cell>
25592 </row>
25593 <row topline="true">
25594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25595 \begin_inset Text
25596
25597 \begin_layout Standard
25598 0
25599 \end_layout
25600
25601 \end_inset
25602 </cell>
25603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25604 \begin_inset Text
25605
25606 \begin_layout Standard
25607 RESET vector
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 0x000000
25617 \end_layout
25618
25619 \end_inset
25620 </cell>
25621 </row>
25622 <row topline="true">
25623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25624 \begin_inset Text
25625
25626 \begin_layout Standard
25627
25628 \family roman
25629 \series medium
25630 \shape up
25631 \size normal
25632 \emph off
25633 \bar no
25634 \noun off
25635 \color none
25636 1
25637 \end_layout
25638
25639 \end_inset
25640 </cell>
25641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25642 \begin_inset Text
25643
25644 \begin_layout Standard
25645
25646 \family roman
25647 \series medium
25648 \shape up
25649 \size normal
25650 \emph off
25651 \bar no
25652 \noun off
25653 \color none
25654 HIGH priority interrupts
25655 \end_layout
25656
25657 \end_inset
25658 </cell>
25659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25660 \begin_inset Text
25661
25662 \begin_layout Standard
25663 0x000008
25664 \end_layout
25665
25666 \end_inset
25667 </cell>
25668 </row>
25669 <row topline="true" bottomline="true">
25670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25671 \begin_inset Text
25672
25673 \begin_layout Standard
25674 2
25675 \end_layout
25676
25677 \end_inset
25678 </cell>
25679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25680 \begin_inset Text
25681
25682 \begin_layout Standard
25683 LOW priority interrupts
25684 \end_layout
25685
25686 \end_inset
25687 </cell>
25688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25689 \begin_inset Text
25690
25691 \begin_layout Standard
25692 0x000018
25693 \end_layout
25694
25695 \end_inset
25696 </cell>
25697 </row>
25698 </lyxtabular>
25699
25700 \end_inset
25701
25702
25703 \end_layout
25704
25705 \begin_layout Standard
25706 When generating assembly code for ISR the code generator places a 
25707 \noun on
25708 goto 
25709 \noun default
25710 instruction at the 
25711 \emph on
25712 Interrupt Vector Address
25713 \emph default
25714  which points at the genetated ISR.
25715  This single GOTO instruction is part of an automatically generated 
25716 \emph on
25717 interrupt entry point
25718 \emph default
25719  function.
25720  The actuall ISR code is placed as normally would in the code space.
25721  Upon interrupt request, the GOTO instruction is executed which jumps to
25722  the ISR code.
25723  When declaring interrupt functions as _naked this GOTO instruction is 
25724 \series bold
25725 not
25726 \series default
25727  generated.
25728  The whole interrupt functions is therefore placed at the Interrupt Vector
25729  Address of the specific interrupt.
25730  This is not a problem for the LOW priority interrupts, but it is a problem
25731  for the RESET and the HIGH priority interrupts because code may be written
25732  at the next interrupt´s vector address and cause undeterminate program
25733  behaviour if that interrupt is raised.
25734 \begin_inset Foot
25735 status open
25736
25737 \begin_layout Standard
25738 This is not a problem when
25739 \end_layout
25740
25741 \begin_layout Enumerate
25742 this is a HIGH interrupt ISR and LOW interrupts are 
25743 \emph on
25744 disabled
25745 \emph default
25746  or not used.
25747 \end_layout
25748
25749 \begin_layout Enumerate
25750 when the ISR is small enough not to reach the next interrupt´s vector address.
25751 \end_layout
25752
25753 \end_inset
25754
25755
25756 \end_layout
25757
25758 \begin_layout Standard
25759
25760 \emph on
25761 n
25762 \emph default
25763  is possible to be omitted.
25764  This way a function is generated similar to an ISR, but it is not assigned
25765  to any interrupt.
25766 \end_layout
25767
25768 \begin_layout Standard
25769 When entering an interrupt, currently the PIC16
25770 \begin_inset LatexCommand \index{PIC16}
25771
25772 \end_inset
25773
25774  port automatically saves the following registers:
25775 \end_layout
25776
25777 \begin_layout Itemize
25778 WREG
25779 \end_layout
25780
25781 \begin_layout Itemize
25782 STATUS
25783 \end_layout
25784
25785 \begin_layout Itemize
25786 BSR
25787 \end_layout
25788
25789 \begin_layout Itemize
25790 PROD (PRODL and PRODH)
25791 \end_layout
25792
25793 \begin_layout Itemize
25794 FSR0 (FSR0L and FSR0H)
25795 \end_layout
25796
25797 \begin_layout Standard
25798 These registers are restored upon return from the interrupt routine.
25799 \begin_inset Foot
25800 status open
25801
25802 \begin_layout Standard
25803 NOTE that when the _naked attribute is specified for an interrupt routine,
25804  then NO registers are stored or restored.
25805 \end_layout
25806
25807 \end_inset
25808
25809
25810 \end_layout
25811
25812 \begin_layout Subsection
25813 Generic Pointers
25814 \end_layout
25815
25816 \begin_layout Standard
25817 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25818  There are 3 types of generic pointers currently implemented data, code
25819  and eeprom pointers.
25820  They are differentiated by the value of the 7th and 6th bits of the upper
25821  byte:
25822 \end_layout
25823
25824 \begin_layout Standard
25825 \align center
25826 \begin_inset Tabular
25827 <lyxtabular version="3" rows="5" columns="5">
25828 <features>
25829 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25830 <column alignment="center" valignment="top" width="0">
25831 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25832 <column alignment="center" valignment="top" width="0">
25833 <column alignment="left" valignment="top" rightline="true" width="0">
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 pointer type
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 7th bit
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 6th bit
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 rest of the pointer
25867 \end_layout
25868
25869 \end_inset
25870 </cell>
25871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25872 \begin_inset Text
25873
25874 \begin_layout Standard
25875 description
25876 \end_layout
25877
25878 \end_inset
25879 </cell>
25880 </row>
25881 <row topline="true" bottomline="true">
25882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25883 \begin_inset Text
25884
25885 \begin_layout Standard
25886 data 
25887 \end_layout
25888
25889 \end_inset
25890 </cell>
25891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25892 \begin_inset Text
25893
25894 \begin_layout Standard
25895 1
25896 \end_layout
25897
25898 \end_inset
25899 </cell>
25900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25901 \begin_inset Text
25902
25903 \begin_layout Standard
25904 0
25905 \end_layout
25906
25907 \end_inset
25908 </cell>
25909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25910 \begin_inset Text
25911
25912 \begin_layout Standard
25913
25914 \family typewriter
25915 \shape slanted
25916 \emph on
25917 uuuuuu uuuuxxxx xxxxxxxx
25918 \end_layout
25919
25920 \end_inset
25921 </cell>
25922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25923 \begin_inset Text
25924
25925 \begin_layout Standard
25926 a 12-bit data pointer in data RAM memory
25927 \end_layout
25928
25929 \end_inset
25930 </cell>
25931 </row>
25932 <row bottomline="true">
25933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25934 \begin_inset Text
25935
25936 \begin_layout Standard
25937 code
25938 \end_layout
25939
25940 \end_inset
25941 </cell>
25942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25943 \begin_inset Text
25944
25945 \begin_layout Standard
25946 0
25947 \end_layout
25948
25949 \end_inset
25950 </cell>
25951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25952 \begin_inset Text
25953
25954 \begin_layout Standard
25955 0
25956 \end_layout
25957
25958 \end_inset
25959 </cell>
25960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25961 \begin_inset Text
25962
25963 \begin_layout Standard
25964
25965 \family typewriter
25966 \shape slanted
25967 \emph on
25968 uxxxxx xxxxxxxx xxxxxxxx
25969 \end_layout
25970
25971 \end_inset
25972 </cell>
25973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25974 \begin_inset Text
25975
25976 \begin_layout Standard
25977 a 21-bit code pointer in FLASH memory
25978 \end_layout
25979
25980 \end_inset
25981 </cell>
25982 </row>
25983 <row bottomline="true">
25984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25985 \begin_inset Text
25986
25987 \begin_layout Standard
25988 eeprom
25989 \end_layout
25990
25991 \end_inset
25992 </cell>
25993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25994 \begin_inset Text
25995
25996 \begin_layout Standard
25997 0
25998 \end_layout
25999
26000 \end_inset
26001 </cell>
26002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26003 \begin_inset Text
26004
26005 \begin_layout Standard
26006 1
26007 \end_layout
26008
26009 \end_inset
26010 </cell>
26011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26012 \begin_inset Text
26013
26014 \begin_layout Standard
26015
26016 \family typewriter
26017 \shape slanted
26018 \emph on
26019 uuuuuu uuuuuuxx xxxxxxxx
26020 \end_layout
26021
26022 \end_inset
26023 </cell>
26024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26025 \begin_inset Text
26026
26027 \begin_layout Standard
26028 a 10-bit eeprom pointer in EEPROM memory
26029 \end_layout
26030
26031 \end_inset
26032 </cell>
26033 </row>
26034 <row bottomline="true">
26035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26036 \begin_inset Text
26037
26038 \begin_layout Standard
26039 (unimplemented)
26040 \end_layout
26041
26042 \end_inset
26043 </cell>
26044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26045 \begin_inset Text
26046
26047 \begin_layout Standard
26048 1
26049 \end_layout
26050
26051 \end_inset
26052 </cell>
26053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26054 \begin_inset Text
26055
26056 \begin_layout Standard
26057 1
26058 \end_layout
26059
26060 \end_inset
26061 </cell>
26062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26063 \begin_inset Text
26064
26065 \begin_layout Standard
26066
26067 \family typewriter
26068 \shape slanted
26069 \emph on
26070 xxxxxx xxxxxxxx xxxxxxxx
26071 \end_layout
26072
26073 \end_inset
26074 </cell>
26075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26076 \begin_inset Text
26077
26078 \begin_layout Standard
26079 unimplemented pointer type
26080 \end_layout
26081
26082 \end_inset
26083 </cell>
26084 </row>
26085 </lyxtabular>
26086
26087 \end_inset
26088
26089
26090 \end_layout
26091
26092 \begin_layout Standard
26093 Generic pointer are read and written with a set of library functions which
26094  read/write 1, 2, 3, 4 bytes.
26095 \end_layout
26096
26097 \begin_layout Subsection
26098 PIC16 C Libraries
26099 \end_layout
26100
26101 \begin_layout Subsubsection
26102 Standard I/O Streams
26103 \end_layout
26104
26105 \begin_layout Standard
26106 In the 
26107 \emph on
26108 stdio.h
26109 \emph default
26110  the type FILE is defined as:
26111 \end_layout
26112
26113 \begin_layout LyX-Code
26114 typedef char * FILE;
26115 \end_layout
26116
26117 \begin_layout Standard
26118 This type is the stream type implemented I/O in the PIC18F devices.
26119  Also the standard input and output streams are declared in stdio.h:
26120 \end_layout
26121
26122 \begin_layout LyX-Code
26123 extern FILE * stdin;
26124 \end_layout
26125
26126 \begin_layout LyX-Code
26127 extern FILE * stdout;
26128 \end_layout
26129
26130 \begin_layout Standard
26131 The FILE type is actually a generic pointer which defines one more type
26132  of generic pointers, the 
26133 \emph on
26134 stream 
26135 \emph default
26136 pointer.
26137  This new type has the format:
26138 \end_layout
26139
26140 \begin_layout Standard
26141 \align center
26142 \begin_inset Tabular
26143 <lyxtabular version="3" rows="2" columns="7">
26144 <features>
26145 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26146 <column alignment="center" valignment="top" width="0">
26147 <column alignment="center" valignment="top" leftline="true" width="0">
26148 <column alignment="center" valignment="top" leftline="true" width="0">
26149 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26150 <column alignment="center" valignment="top" width="0">
26151 <column alignment="left" valignment="top" rightline="true" width="0">
26152 <row topline="true" bottomline="true">
26153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26154 \begin_inset Text
26155
26156 \begin_layout Standard
26157 pointer type
26158 \end_layout
26159
26160 \end_inset
26161 </cell>
26162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26163 \begin_inset Text
26164
26165 \begin_layout Standard
26166 <7:6>
26167 \end_layout
26168
26169 \end_inset
26170 </cell>
26171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26172 \begin_inset Text
26173
26174 \begin_layout Standard
26175 <5>
26176 \end_layout
26177
26178 \end_inset
26179 </cell>
26180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26181 \begin_inset Text
26182
26183 \begin_layout Standard
26184 <4>
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 <3:0>
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 rest of the pointer
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 descrption
26212 \end_layout
26213
26214 \end_inset
26215 </cell>
26216 </row>
26217 <row topline="true" bottomline="true">
26218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26219 \begin_inset Text
26220
26221 \begin_layout Standard
26222 stream
26223 \end_layout
26224
26225 \end_inset
26226 </cell>
26227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26228 \begin_inset Text
26229
26230 \begin_layout Standard
26231 00
26232 \end_layout
26233
26234 \end_inset
26235 </cell>
26236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26237 \begin_inset Text
26238
26239 \begin_layout Standard
26240 1
26241 \end_layout
26242
26243 \end_inset
26244 </cell>
26245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26246 \begin_inset Text
26247
26248 \begin_layout Standard
26249 0
26250 \end_layout
26251
26252 \end_inset
26253 </cell>
26254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26255 \begin_inset Text
26256
26257 \begin_layout Standard
26258 nnnn
26259 \end_layout
26260
26261 \end_inset
26262 </cell>
26263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26264 \begin_inset Text
26265
26266 \begin_layout Standard
26267
26268 \family typewriter
26269 \shape slanted
26270 \emph on
26271 uuuuuuuu uuuuuuuu
26272 \end_layout
26273
26274 \end_inset
26275 </cell>
26276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26277 \begin_inset Text
26278
26279 \begin_layout Standard
26280 upper byte high nubble is 0x2n, the rest are zeroes
26281 \end_layout
26282
26283 \end_inset
26284 </cell>
26285 </row>
26286 </lyxtabular>
26287
26288 \end_inset
26289
26290
26291 \end_layout
26292
26293 \begin_layout Standard
26294 Currently implemented there are 3 types of streams defined:
26295 \end_layout
26296
26297 \begin_layout Standard
26298 \align center
26299 \begin_inset Tabular
26300 <lyxtabular version="3" rows="4" columns="4">
26301 <features>
26302 <column alignment="center" valignment="top" leftline="true" width="0">
26303 <column alignment="center" valignment="top" leftline="true" width="0">
26304 <column alignment="center" valignment="top" leftline="true" width="0">
26305 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26306 <row topline="true" bottomline="true">
26307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26308 \begin_inset Text
26309
26310 \begin_layout Standard
26311 stream type
26312 \end_layout
26313
26314 \end_inset
26315 </cell>
26316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26317 \begin_inset Text
26318
26319 \begin_layout Standard
26320 value
26321 \end_layout
26322
26323 \end_inset
26324 </cell>
26325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26326 \begin_inset Text
26327
26328 \begin_layout Standard
26329 module
26330 \end_layout
26331
26332 \end_inset
26333 </cell>
26334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26335 \begin_inset Text
26336
26337 \begin_layout Standard
26338 description
26339 \end_layout
26340
26341 \end_inset
26342 </cell>
26343 </row>
26344 <row topline="true">
26345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26346 \begin_inset Text
26347
26348 \begin_layout Standard
26349 STREAM_USART
26350 \end_layout
26351
26352 \end_inset
26353 </cell>
26354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26355 \begin_inset Text
26356
26357 \begin_layout Standard
26358
26359 \family typewriter
26360 0x200000UL
26361 \end_layout
26362
26363 \end_inset
26364 </cell>
26365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26366 \begin_inset Text
26367
26368 \begin_layout Standard
26369 USART
26370 \end_layout
26371
26372 \end_inset
26373 </cell>
26374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26375 \begin_inset Text
26376
26377 \begin_layout Standard
26378 Writes/Reads characters via the USART peripheral
26379 \end_layout
26380
26381 \end_inset
26382 </cell>
26383 </row>
26384 <row topline="true">
26385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26386 \begin_inset Text
26387
26388 \begin_layout Standard
26389 STREAM_MSSP
26390 \end_layout
26391
26392 \end_inset
26393 </cell>
26394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26395 \begin_inset Text
26396
26397 \begin_layout Standard
26398
26399 \family typewriter
26400 0x210000UL
26401 \end_layout
26402
26403 \end_inset
26404 </cell>
26405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26406 \begin_inset Text
26407
26408 \begin_layout Standard
26409 MSSP
26410 \end_layout
26411
26412 \end_inset
26413 </cell>
26414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26415 \begin_inset Text
26416
26417 \begin_layout Standard
26418 Writes/Reads characters via the MSSP peripheral
26419 \end_layout
26420
26421 \end_inset
26422 </cell>
26423 </row>
26424 <row topline="true" bottomline="true">
26425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26426 \begin_inset Text
26427
26428 \begin_layout Standard
26429 STREAM_USER
26430 \end_layout
26431
26432 \end_inset
26433 </cell>
26434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26435 \begin_inset Text
26436
26437 \begin_layout Standard
26438
26439 \family typewriter
26440 0x2f0000UL
26441 \end_layout
26442
26443 \end_inset
26444 </cell>
26445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26446 \begin_inset Text
26447
26448 \begin_layout Standard
26449 (none)
26450 \end_layout
26451
26452 \end_inset
26453 </cell>
26454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26455 \begin_inset Text
26456
26457 \begin_layout Standard
26458 Writes/Reads characters via used defined functions
26459 \end_layout
26460
26461 \end_inset
26462 </cell>
26463 </row>
26464 </lyxtabular>
26465
26466 \end_inset
26467
26468
26469 \end_layout
26470
26471 \begin_layout Standard
26472 The stream identifiers are declared as macros in the stdio.h header.
26473 \end_layout
26474
26475 \begin_layout Standard
26476 In the libc library there exist the functions that are used to write to
26477  each of the above streams.
26478  These are
26479 \end_layout
26480
26481 \begin_layout List
26482 \labelwidthstring 00.00.0000
26483 _
26484 \begin_inset ERT
26485 status collapsed
26486
26487 \begin_layout Standard
26488
26489
26490 \backslash
26491 /
26492 \end_layout
26493
26494 \end_inset
26495
26496 _stream_usart_putchar writes a character at the USART stream
26497 \end_layout
26498
26499 \begin_layout List
26500 \labelwidthstring 00.00.0000
26501 _
26502 \begin_inset ERT
26503 status collapsed
26504
26505 \begin_layout Standard
26506
26507
26508 \backslash
26509 /
26510 \end_layout
26511
26512 \end_inset
26513
26514 _stream_mssp_putchar writes a character at the MSSP stream
26515 \end_layout
26516
26517 \begin_layout List
26518 \labelwidthstring 00.00.0000
26519 putchar dummy function.
26520  This writes a character to a user specified manner.
26521 \end_layout
26522
26523 \begin_layout Standard
26524 In order to increase performance 
26525 \emph on
26526 putchar 
26527 \emph default
26528 is declared in stdio.h as having its parameter in WREG (it has the wparam
26529  keyword).
26530  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26531  in a user-friendly way.
26532  
26533 \emph on
26534 arg
26535 \emph default
26536  is the name of the variable that holds the character to print.
26537  An example follows:
26538 \end_layout
26539
26540 \begin_layout LyX-Code
26541 #include <pic18fregs.h>
26542 \newline
26543 #include <stdio.h>
26544 \newline
26545
26546 \newline
26547 PUTCHAR( c )
26548 \end_layout
26549
26550 \begin_layout LyX-Code
26551 {
26552 \end_layout
26553
26554 \begin_layout LyX-Code
26555     PORTA = c;    /* dump character c to PORTA */
26556 \end_layout
26557
26558 \begin_layout LyX-Code
26559
26560 \newline
26561
26562 \newline
26563 void main(void)
26564 \end_layout
26565
26566 \begin_layout LyX-Code
26567 {
26568 \end_layout
26569
26570 \begin_layout LyX-Code
26571     stdout = STREAM_USER;    /* this is not necessary, since stdout points
26572 \end_layout
26573
26574 \begin_layout LyX-Code
26575                               * by default to STREAM_USER */
26576 \end_layout
26577
26578 \begin_layout LyX-Code
26579     printf (¨This is a printf test
26580 \backslash
26581 n¨);
26582 \end_layout
26583
26584 \begin_layout LyX-Code
26585 }
26586 \end_layout
26587
26588 \begin_layout LyX-Code
26589
26590 \end_layout
26591
26592 \begin_layout Subsubsection
26593 Printing functions
26594 \end_layout
26595
26596 \begin_layout Standard
26597 PIC16 contains an implementation of the printf-family of functions.
26598  There exist the following functions:
26599 \end_layout
26600
26601 \begin_layout LyX-Code
26602 extern unsigned int sprintf(char *buf, char *fmt, ...);
26603 \end_layout
26604
26605 \begin_layout LyX-Code
26606 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26607 \end_layout
26608
26609 \begin_layout LyX-Code
26610
26611 \end_layout
26612
26613 \begin_layout LyX-Code
26614 extern unsigned int printf(char *fmt, ...);
26615 \end_layout
26616
26617 \begin_layout LyX-Code
26618 extern unsigned int vprintf(char *fmt, va_lista ap);
26619 \end_layout
26620
26621 \begin_layout LyX-Code
26622
26623 \end_layout
26624
26625 \begin_layout LyX-Code
26626 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26627 \end_layout
26628
26629 \begin_layout LyX-Code
26630 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26631 \end_layout
26632
26633 \begin_layout Standard
26634 For sprintf and vsprintf 
26635 \emph on
26636 buf 
26637 \emph default
26638 should normally be a data pointer where the resulting string will be placed.
26639  No range checking is done so the user should allocate the necessery buffer.
26640  For fprintf and vfprintf 
26641 \emph on
26642 fp
26643 \emph default
26644  should be a stream pointer (i.e.
26645  stdout, STREAM_MSSP, etc...).
26646 \end_layout
26647
26648 \begin_layout Subsubsection
26649 Signals
26650 \end_layout
26651
26652 \begin_layout Standard
26653 The PIC18F family of microcontrollers supports a number of interrupt sources.
26654  A list of these interrupts is shown in the following table:
26655 \end_layout
26656
26657 \begin_layout Standard
26658 \align center
26659 \begin_inset Tabular
26660 <lyxtabular version="3" rows="11" columns="4">
26661 <features>
26662 <column alignment="left" valignment="top" leftline="true" width="0">
26663 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26664 <column alignment="left" valignment="top" leftline="true" width="0">
26665 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26666 <row topline="true" bottomline="true">
26667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26668 \begin_inset Text
26669
26670 \begin_layout Standard
26671 signal name
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 description
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 signal name
26690 \end_layout
26691
26692 \end_inset
26693 </cell>
26694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26695 \begin_inset Text
26696
26697 \begin_layout Standard
26698 descritpion
26699 \end_layout
26700
26701 \end_inset
26702 </cell>
26703 </row>
26704 <row topline="true">
26705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26706 \begin_inset Text
26707
26708 \begin_layout Standard
26709 SIG_RB
26710 \end_layout
26711
26712 \end_inset
26713 </cell>
26714 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26715 \begin_inset Text
26716
26717 \begin_layout Standard
26718 PORTB change interrupt
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 SIG_EE
26728 \end_layout
26729
26730 \end_inset
26731 </cell>
26732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26733 \begin_inset Text
26734
26735 \begin_layout Standard
26736 EEPROM/FLASH write complete interrupt
26737 \end_layout
26738
26739 \end_inset
26740 </cell>
26741 </row>
26742 <row topline="true">
26743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26744 \begin_inset Text
26745
26746 \begin_layout Standard
26747 SIG_INT0
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 INT0 external interrupt
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 SIG_BCOL
26766 \end_layout
26767
26768 \end_inset
26769 </cell>
26770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26771 \begin_inset Text
26772
26773 \begin_layout Standard
26774 Bus collision interrupt
26775 \end_layout
26776
26777 \end_inset
26778 </cell>
26779 </row>
26780 <row topline="true">
26781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26782 \begin_inset Text
26783
26784 \begin_layout Standard
26785 SIG_INT1
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 INT1 external interrupt
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 SIG_LVD
26804 \end_layout
26805
26806 \end_inset
26807 </cell>
26808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26809 \begin_inset Text
26810
26811 \begin_layout Standard
26812 Low voltage detect interrupt
26813 \end_layout
26814
26815 \end_inset
26816 </cell>
26817 </row>
26818 <row topline="true">
26819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26820 \begin_inset Text
26821
26822 \begin_layout Standard
26823 SIG_INT2
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 INT2 external interrupt
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 SIG_PSP
26842 \end_layout
26843
26844 \end_inset
26845 </cell>
26846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26847 \begin_inset Text
26848
26849 \begin_layout Standard
26850 Parallel slave port interrupt
26851 \end_layout
26852
26853 \end_inset
26854 </cell>
26855 </row>
26856 <row topline="true">
26857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26858 \begin_inset Text
26859
26860 \begin_layout Standard
26861 SIG_CCP1
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 CCP1 module interrupt
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 SIG_AD
26880 \end_layout
26881
26882 \end_inset
26883 </cell>
26884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26885 \begin_inset Text
26886
26887 \begin_layout Standard
26888 AD convertion complete interrupt
26889 \end_layout
26890
26891 \end_inset
26892 </cell>
26893 </row>
26894 <row topline="true">
26895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26896 \begin_inset Text
26897
26898 \begin_layout Standard
26899 SIG_CCP2
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 CCP2 module interrupt
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 SIG_RC
26918 \end_layout
26919
26920 \end_inset
26921 </cell>
26922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26923 \begin_inset Text
26924
26925 \begin_layout Standard
26926 USART receive interrupt
26927 \end_layout
26928
26929 \end_inset
26930 </cell>
26931 </row>
26932 <row topline="true">
26933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26934 \begin_inset Text
26935
26936 \begin_layout Standard
26937 SIG_TMR0
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 TMR0 overflow interrupt
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 SIG_TX
26956 \end_layout
26957
26958 \end_inset
26959 </cell>
26960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26961 \begin_inset Text
26962
26963 \begin_layout Standard
26964 USART transmit interrupt
26965 \end_layout
26966
26967 \end_inset
26968 </cell>
26969 </row>
26970 <row topline="true">
26971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26972 \begin_inset Text
26973
26974 \begin_layout Standard
26975 SIG_TMR1
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 TMR1 overflow interrupt
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 SIG_MSSP
26994 \end_layout
26995
26996 \end_inset
26997 </cell>
26998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26999 \begin_inset Text
27000
27001 \begin_layout Standard
27002 SSP receive/transmit interrupt
27003 \end_layout
27004
27005 \end_inset
27006 </cell>
27007 </row>
27008 <row topline="true">
27009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27010 \begin_inset Text
27011
27012 \begin_layout Standard
27013 SIG_TMR2
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 TMR2 matches PR2 interrupt
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 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27037 \begin_inset Text
27038
27039 \begin_layout Standard
27040
27041 \end_layout
27042
27043 \end_inset
27044 </cell>
27045 </row>
27046 <row topline="true" bottomline="true">
27047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27048 \begin_inset Text
27049
27050 \begin_layout Standard
27051 SIG_TMR3
27052 \end_layout
27053
27054 \end_inset
27055 </cell>
27056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27057 \begin_inset Text
27058
27059 \begin_layout Standard
27060 TMR3 overflow interrupt
27061 \end_layout
27062
27063 \end_inset
27064 </cell>
27065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27066 \begin_inset Text
27067
27068 \begin_layout Standard
27069
27070 \end_layout
27071
27072 \end_inset
27073 </cell>
27074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27075 \begin_inset Text
27076
27077 \begin_layout Standard
27078
27079 \end_layout
27080
27081 \end_inset
27082 </cell>
27083 </row>
27084 </lyxtabular>
27085
27086 \end_inset
27087
27088
27089 \end_layout
27090
27091 \begin_layout Standard
27092 The prototypes for these names are defined in the header file 
27093 \emph on
27094 signal.h
27095 \emph default
27096  .
27097 \end_layout
27098
27099 \begin_layout Standard
27100 In order to simplify signal handling, a number of macros is provided:
27101 \end_layout
27102
27103 \begin_layout List
27104 \labelwidthstring 00.00.0000
27105 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27106  high priority interrupts.
27107  
27108 \emph on
27109 name
27110 \emph default
27111  is the function name to use.
27112 \end_layout
27113
27114 \begin_layout List
27115 \labelwidthstring 00.00.0000
27116 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27117  low priority interrupt.
27118  
27119 \emph on
27120 name
27121 \emph default
27122  is the function name to use.
27123 \end_layout
27124
27125 \begin_layout List
27126 \labelwidthstring 00.00.0000
27127 DEF_HANDLER(sig,handler) define a handler for signal 
27128 \emph on
27129 sig.
27130 \end_layout
27131
27132 \begin_layout List
27133 \labelwidthstring 00.00.0000
27134 END_DEF end the declaration of the dispatch table.
27135 \end_layout
27136
27137 \begin_layout Standard
27138 Additionally there are two more macros to simplify the declaration of the
27139  signal handler:
27140 \end_layout
27141
27142 \begin_layout List
27143 \labelwidthstring 00.00.0000
27144
27145 \series medium
27146 SIGHANDLER(handler) 
27147 \series default
27148 this declares the function prototype for the 
27149 \emph on
27150 handler
27151 \emph default
27152  function.
27153 \end_layout
27154
27155 \begin_layout List
27156 \labelwidthstring 00.00.0000
27157 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27158 \end_layout
27159
27160 \begin_layout Standard
27161 An example of using the macros above is shown below:
27162 \end_layout
27163
27164 \begin_layout LyX-Code
27165 #include <pic18fregs.h>
27166 \end_layout
27167
27168 \begin_layout LyX-Code
27169 #include <signal.h>
27170 \newline
27171
27172 \newline
27173 DEF_INTHIGH(high_int)
27174 \end_layout
27175
27176 \begin_layout LyX-Code
27177 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27178 \end_layout
27179
27180 \begin_layout LyX-Code
27181 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27182 \end_layout
27183
27184 \begin_layout LyX-Code
27185 END_DEF
27186 \newline
27187
27188 \newline
27189 SIGHANDLER(_tmr0_handler)
27190 \end_layout
27191
27192 \begin_layout LyX-Code
27193 {
27194 \end_layout
27195
27196 \begin_layout LyX-Code
27197   /* action to be taken when timer 0 overflows */
27198 \end_layout
27199
27200 \begin_layout LyX-Code
27201 }
27202 \newline
27203
27204 \newline
27205 SIGHANDLERNAKED(_bcol_handler)
27206 \end_layout
27207
27208 \begin_layout LyX-Code
27209 {
27210 \end_layout
27211
27212 \begin_layout LyX-Code
27213   _asm
27214 \end_layout
27215
27216 \begin_layout LyX-Code
27217     /* action to be taken when bus collision occurs */
27218 \end_layout
27219
27220 \begin_layout LyX-Code
27221     retfie
27222 \end_layout
27223
27224 \begin_layout LyX-Code
27225  _endasm;
27226 \end_layout
27227
27228 \begin_layout LyX-Code
27229 }
27230 \end_layout
27231
27232 \begin_layout Standard
27233
27234 \series bold
27235 NOTES:
27236 \series default
27237  Special care should be taken when using the above scheme:
27238 \end_layout
27239
27240 \begin_layout Itemize
27241 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27242 \end_layout
27243
27244 \begin_layout Itemize
27245 when declaring SIGHANDLERNAKED handler never forget to use 
27246 \emph on
27247 retfie
27248 \emph default
27249  for proper returning.
27250 \end_layout
27251
27252 \begin_layout Subsection
27253 PIC16 Port -- Tips
27254 \end_layout
27255
27256 \begin_layout Standard
27257 Here you can find some general tips for compiling programs with SDCC/pic16.
27258 \end_layout
27259
27260 \begin_layout Subsubsection
27261 Stack size
27262 \end_layout
27263
27264 \begin_layout Standard
27265 The default stack
27266 \begin_inset LatexCommand \index{PIC16!stack}
27267
27268 \end_inset
27269
27270  size (that is 64 bytes) probably is enough for many programs.
27271  One must take care that when there are many levels of function nesting,
27272  or there is excessive usage of stack, its size should be extended.
27273  An example of such a case is the printf/sprintf family of functions.
27274  If you encounter problems like not being able to print integers, then you
27275  need to set the stack size around the maximum (256 for small stack model).
27276  The following diagram shows what happens when calling printf to print an
27277  integer:
27278 \end_layout
27279
27280 \begin_layout LyX-Code
27281 printf () --> ltoa () --> ultoa () --> divschar ()
27282 \end_layout
27283
27284 \begin_layout Standard
27285 It is should be understood that stack is easily consumed when calling complicate
27286 d functions.
27287  Using command line arguments like -
27288 \begin_inset ERT
27289 status collapsed
27290
27291 \begin_layout Standard
27292
27293
27294 \backslash
27295 /
27296 \end_layout
27297
27298 \end_inset
27299
27300 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27301  stack frames.
27302  Other ways to reduce stack usage may exist.
27303 \end_layout
27304
27305 \begin_layout Subsection
27306 Known bugs
27307 \end_layout
27308
27309 \begin_layout Standard
27310 The PIC16 Port currently does not pass SDCC's regression test
27311 \begin_inset LatexCommand \index{Regression test (PIC16)}
27312
27313 \end_inset
27314
27315  suite (see section 
27316 \begin_inset LatexCommand \ref{sec:Quality-control}
27317
27318 \end_inset
27319
27320 ) and thus the snapshot build regression tests for the PIC16 target are
27321  currently disabled for all hosts
27322 \emph on
27323 .
27324 \end_layout
27325
27326 \begin_layout Chapter
27327 Debugging
27328 \end_layout
27329
27330 \begin_layout Standard
27331 There are several approaches to debugging your code.
27332  This chapter is meant to show your options and to give detail on some of
27333  them:
27334 \newline
27335
27336 \newline
27337 When writing your code:
27338 \end_layout
27339
27340 \begin_layout Itemize
27341 write your code with debugging in mind (avoid duplicating code, put conceptually
27342  similar variables into structs, use structured code, have strategic points
27343  within your code where all variables are consistent, ...)
27344 \end_layout
27345
27346 \begin_layout Itemize
27347 run a syntax-checking tool like splint
27348 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27349
27350 \end_inset
27351
27352
27353 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27354
27355 \end_inset
27356
27357  (see -
27358 \begin_inset ERT
27359 status collapsed
27360
27361 \begin_layout Standard
27362
27363
27364 \backslash
27365 /
27366 \end_layout
27367
27368 \end_inset
27369
27370 -more-pedantic 
27371 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27372
27373 \end_inset
27374
27375 ) over the code.
27376 \end_layout
27377
27378 \begin_layout Itemize
27379 for the high level code use a C-compiler (like f.e.
27380  GCC) to compile run and debug the code on your host.
27381  See (see -
27382 \begin_inset ERT
27383 status collapsed
27384
27385 \begin_layout Standard
27386
27387
27388 \backslash
27389 /
27390 \end_layout
27391
27392 \end_inset
27393
27394 -more-pedantic 
27395 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27396
27397 \end_inset
27398
27399 ) on how to handle syntax extensions like __xdata, __at(), ...
27400  
27401 \end_layout
27402
27403 \begin_layout Itemize
27404 use another C-compiler to compile code for your target.
27405  Always an option but not recommended:) And not very likely to help you.
27406  If you seriously consider walking this path you should at least occasionally
27407  check portability of your code.
27408  Most commercial compiler vendors will offer an evaluation version so you
27409  can test compile your code or snippets of your code.
27410 \end_layout
27411
27412 \begin_layout Standard
27413 Debugging on a simulator:
27414 \end_layout
27415
27416 \begin_layout Itemize
27417 there is a separate section about SDCDB (section 
27418 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27419
27420 \end_inset
27421
27422 ) below.
27423 \end_layout
27424
27425 \begin_layout Itemize
27426 or (8051 specific) use a freeware/commercial simulator which interfaces
27427  to the AOMF
27428 \begin_inset LatexCommand \index{AOMF, AOMF51}
27429
27430 \end_inset
27431
27432  file (see 
27433 \begin_inset LatexCommand \ref{OMF file}
27434
27435 \end_inset
27436
27437 ) optionally generated by SDCC.
27438 \end_layout
27439
27440 \begin_layout Standard
27441 Debugging On-target: 
27442 \end_layout
27443
27444 \begin_layout Itemize
27445 use a MCU port pin to serially output debug data to the RS232 port of your
27446  host.
27447  You'll probably want some level shifting device typically involving a MAX232
27448  or similar IC.
27449  If the hardware serial port of the MCU is not available search for 'Software
27450  UART' in your favourite search machine.
27451 \end_layout
27452
27453 \begin_layout Itemize
27454 use an on-target monitor.
27455  In this context a monitor is a small program which usually accepts commands
27456  via a serial line and allows to set program counter, to single step through
27457  a program and read/write memory locations.
27458  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27459  
27460 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27461
27462 \end_inset
27463
27464 ).
27465 \end_layout
27466
27467 \begin_layout Itemize
27468 toggle MCU port pins at strategic points within your code and use an oscilloscop
27469 e.
27470  A 
27471 \emph on
27472 digital oscilloscope
27473 \emph default
27474
27475 \begin_inset LatexCommand \index{Oscilloscope}
27476
27477 \end_inset
27478
27479  with deep trace memory is really helpful especially if you have to debug
27480  a realtime application.
27481  If you need to monitor more pins than your oscilloscope provides you can
27482  sometimes get away with a small R-2R network.
27483  On a single channel oscilloscope you could f.e.
27484  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27485 k
27486 \begin_inset Formula $\Omega$
27487 \end_inset
27488
27489  resistor and the other one by a 5\InsetSpace ~
27490 k
27491 \begin_inset Formula $\Omega$
27492 \end_inset
27493
27494  resistor to the oscilloscope probe (check output drive capability of the
27495  pins you want to monitor).
27496  If you need to monitor many more pins a 
27497 \emph on
27498 logic analyzer
27499 \emph default
27500  will be handy.
27501 \end_layout
27502
27503 \begin_layout Itemize
27504 use an ICE (
27505 \emph on
27506 i
27507 \emph default
27508
27509 \emph on
27510 c
27511 \emph default
27512 ircuit 
27513 \emph on
27514 e
27515 \emph default
27516 mulator
27517 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27518
27519 \end_inset
27520
27521 ).
27522  Usually very expensive.
27523  And very nice to have too.
27524  And usually locks you (for years...) to the devices the ICE can emulate.
27525  
27526 \end_layout
27527
27528 \begin_layout Itemize
27529 use a remote debugger.
27530  In most 8-bit systems the symbol information is not available on the target,
27531  and a complete debugger is too bulky for the target system.
27532  Therefore usually a debugger on the host system connects to an on-target
27533  debugging stub which accepts only primitive commands.
27534  
27535 \newline
27536 Terms to enter into your favourite search engine could be 'remote debugging',
27537  'gdb stub' or 'inferior debugger'.
27538  (is there one?)
27539 \end_layout
27540
27541 \begin_layout Itemize
27542 use an on target hardware debugger.
27543  Some of the more modern MCUs include hardware support for setting break
27544  points and monitoring/changing variables by using dedicated hardware pins.
27545  This facility doesn't require additional code to run on the target and
27546  
27547 \emph on
27548 usually
27549 \emph default
27550  doesn't affect runtime behaviour until a breakpoint is hit.
27551  For the mcs51 most hardware debuggers use the AOMF
27552 \begin_inset LatexCommand \index{AOMF, AOMF51}
27553
27554 \end_inset
27555
27556  file (see 
27557 \begin_inset LatexCommand \ref{OMF file}
27558
27559 \end_inset
27560
27561 ) as input file.
27562  
27563 \end_layout
27564
27565 \begin_layout Standard
27566 Last not least:
27567 \end_layout
27568
27569 \begin_layout Itemize
27570 if you are not familiar with any of the following terms you're likely to
27571  run into problems rather sooner than later: 
27572 \emph on
27573 volatile
27574 \emph default
27575
27576 \emph on
27577 atomic
27578 \emph default
27579
27580 \emph on
27581 memory map
27582 \emph default
27583
27584 \emph on
27585 overlay
27586 \emph default
27587 .
27588  As an embedded programmer you 
27589 \emph on
27590 have
27591 \emph default
27592  to know them so why not look them up 
27593 \emph on
27594 before
27595 \emph default
27596  you have problems?)
27597 \end_layout
27598
27599 \begin_layout Itemize
27600 tell someone else about your problem (actually this is a surprisingly effective
27601  means to hunt down the bug even if the listener is not familiar with your
27602  environment).
27603  As 'failure to communicate' is probably one of the job-induced deformations
27604  of an embedded programmer this is highly encouraged.
27605 \end_layout
27606
27607 \begin_layout Section
27608 Debugging with SDCDB
27609 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27610
27611 \end_inset
27612
27613
27614 \begin_inset LatexCommand \index{SDCDB (debugger)}
27615
27616 \end_inset
27617
27618  
27619 \end_layout
27620
27621 \begin_layout Standard
27622 SDCC is distributed with a source level debugger
27623 \begin_inset LatexCommand \index{Debugger}
27624
27625 \end_inset
27626
27627 .
27628  The debugger uses a command line interface, the command repertoire of the
27629  debugger has been kept as close to gdb
27630 \begin_inset LatexCommand \index{gdb}
27631
27632 \end_inset
27633
27634  (the GNU debugger) as possible.
27635  The configuration and build process is part of the standard compiler installati
27636 on, which also builds and installs the debugger in the target directory
27637  specified during configuration.
27638  The debugger allows you debug BOTH at the C source and at the ASM source
27639  level.
27640 \end_layout
27641
27642 \begin_layout Subsection
27643 Compiling for Debugging
27644 \end_layout
27645
27646 \begin_layout Standard
27647 The -
27648 \begin_inset ERT
27649 status collapsed
27650
27651 \begin_layout Standard
27652
27653
27654 \backslash
27655 /
27656 \end_layout
27657
27658 \end_inset
27659
27660 -debug
27661 \begin_inset LatexCommand \index{-\/-debug}
27662
27663 \end_inset
27664
27665  option must be specified for all files for which debug information is to
27666  be generated.
27667  The compiler generates a .adb file for each of these files.
27668  The linker creates the .cdb
27669 \begin_inset LatexCommand \index{<file>.cdb}
27670
27671 \end_inset
27672
27673  file from the .adb
27674 \begin_inset LatexCommand \index{<file>.adb}
27675
27676 \end_inset
27677
27678  files and the address information.
27679  This .cdb is used by the debugger.
27680 \end_layout
27681
27682 \begin_layout Subsection
27683 How the Debugger Works
27684 \end_layout
27685
27686 \begin_layout Standard
27687 When the -
27688 \begin_inset ERT
27689 status collapsed
27690
27691 \begin_layout Standard
27692
27693
27694 \backslash
27695 /
27696 \end_layout
27697
27698 \end_inset
27699
27700 -debug option is specified the compiler generates extra symbol information
27701  some of which are put into the assembler source and some are put into the
27702  .adb file.
27703  Then the linker creates the .cdb file from the individual .adb files with
27704  the address information for the symbols.
27705  The debugger reads the symbolic information generated by the compiler &
27706  the address information generated by the linker.
27707  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27708  execution is controlled by the debugger.
27709  When a command is issued for the debugger, it translates it into appropriate
27710  commands for the simulator.
27711  (Currently SDCDM only connects to the simulator but 
27712 \emph on
27713 newcdb
27714 \emph default
27715  at 
27716 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27717
27718 \end_inset
27719
27720  is an effort to connect directly to the hardware.) 
27721 \end_layout
27722
27723 \begin_layout Subsection
27724 Starting the Debugger SDCDB
27725 \end_layout
27726
27727 \begin_layout Standard
27728 The debugger can be started using the following command line.
27729  (Assume the file you are debugging has the file name foo).
27730 \newline
27731
27732 \newline
27733
27734 \family sans
27735 \series bold
27736 sdcdb foo
27737 \newline
27738
27739 \family default
27740 \series default
27741
27742 \newline
27743 The debugger will look for the following files.
27744 \end_layout
27745
27746 \begin_layout Itemize
27747 foo.c - the source file.
27748 \end_layout
27749
27750 \begin_layout Itemize
27751 foo.cdb - the debugger symbol information file.
27752 \end_layout
27753
27754 \begin_layout Itemize
27755 foo.ihx - the Intel hex format
27756 \begin_inset LatexCommand \index{Intel hex format}
27757
27758 \end_inset
27759
27760  object file.
27761 \end_layout
27762
27763 \begin_layout Subsection
27764 SDCDB Command Line Options
27765 \end_layout
27766
27767 \begin_layout Itemize
27768 -
27769 \begin_inset ERT
27770 status collapsed
27771
27772 \begin_layout Standard
27773
27774
27775 \backslash
27776 /
27777 \end_layout
27778
27779 \end_inset
27780
27781 -directory=<source file directory> this option can used to specify the directory
27782  search list.
27783  The debugger will look into the directory list specified for source, cdb
27784  & ihx files.
27785  The items in the directory list must be separated by ':', e.g.
27786  if the source files can be in the directories /home/src1 and /home/src2,
27787  the -
27788 \begin_inset ERT
27789 status collapsed
27790
27791 \begin_layout Standard
27792
27793
27794 \backslash
27795 /
27796 \end_layout
27797
27798 \end_inset
27799
27800 -directory option should be -
27801 \begin_inset ERT
27802 status collapsed
27803
27804 \begin_layout Standard
27805
27806
27807 \backslash
27808 /
27809 \end_layout
27810
27811 \end_inset
27812
27813 -directory=/home/src1:/home/src2.
27814  Note there can be no spaces in the option.
27815  
27816 \end_layout
27817
27818 \begin_layout Itemize
27819 -cd <directory> - change to the <directory>.
27820 \end_layout
27821
27822 \begin_layout Itemize
27823 -fullname - used by GUI front ends.
27824 \end_layout
27825
27826 \begin_layout Itemize
27827 -cpu <cpu-type> - this argument is passed to the simulator please see the
27828  simulator docs for details.
27829 \end_layout
27830
27831 \begin_layout Itemize
27832 -X <Clock frequency > this options is passed to the simulator please see
27833  the simulator docs for details.
27834 \end_layout
27835
27836 \begin_layout Itemize
27837 -s <serial port file> passed to simulator see the simulator docs for details.
27838 \end_layout
27839
27840 \begin_layout Itemize
27841 -S <serial in,out> passed to simulator see the simulator docs for details.
27842 \end_layout
27843
27844 \begin_layout Itemize
27845 -k <port number> passed to simulator see the simulator docs for details.
27846 \end_layout
27847
27848 \begin_layout Subsection
27849 SDCDB Debugger Commands
27850 \end_layout
27851
27852 \begin_layout Standard
27853 As mentioned earlier the command interface for the debugger has been deliberatel
27854 y kept as close the GNU debugger gdb, as possible.
27855  This will help the integration with existing graphical user interfaces
27856  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27857  If you use a graphical user interface for the debugger you can skip this
27858  section.
27859 \end_layout
27860
27861 \begin_layout Subsubsection*
27862 break [line | file:line | function | file:function]
27863 \end_layout
27864
27865 \begin_layout Standard
27866 Set breakpoint at specified line or function:
27867 \newline
27868
27869 \newline
27870
27871 \family sans
27872 \series bold
27873 sdcdb>break 100 
27874 \newline
27875 sdcdb>break foo.c:100
27876 \newline
27877 sdcdb>break funcfoo
27878 \newline
27879 sdcdb>break foo.c:funcfoo
27880 \end_layout
27881
27882 \begin_layout Subsubsection*
27883 clear [line | file:line | function | file:function ]
27884 \end_layout
27885
27886 \begin_layout Standard
27887 Clear breakpoint at specified line or function:
27888 \newline
27889
27890 \newline
27891
27892 \family sans
27893 \series bold
27894 sdcdb>clear 100
27895 \newline
27896 sdcdb>clear foo.c:100
27897 \newline
27898 sdcdb>clear funcfoo
27899 \newline
27900 sdcdb>clear foo.c:funcfoo
27901 \end_layout
27902
27903 \begin_layout Subsubsection*
27904 continue
27905 \end_layout
27906
27907 \begin_layout Standard
27908 Continue program being debugged, after breakpoint.
27909 \end_layout
27910
27911 \begin_layout Subsubsection*
27912 finish
27913 \end_layout
27914
27915 \begin_layout Standard
27916 Execute till the end of the current function.
27917 \end_layout
27918
27919 \begin_layout Subsubsection*
27920 delete [n]
27921 \end_layout
27922
27923 \begin_layout Standard
27924 Delete breakpoint number 'n'.
27925  If used without any option clear ALL user defined break points.
27926 \end_layout
27927
27928 \begin_layout Subsubsection*
27929 info [break | stack | frame | registers ]
27930 \end_layout
27931
27932 \begin_layout Itemize
27933 info break - list all breakpoints
27934 \end_layout
27935
27936 \begin_layout Itemize
27937 info stack - show the function call stack.
27938 \end_layout
27939
27940 \begin_layout Itemize
27941 info frame - show information about the current execution frame.
27942 \end_layout
27943
27944 \begin_layout Itemize
27945 info registers - show content of all registers.
27946 \end_layout
27947
27948 \begin_layout Subsubsection*
27949 step
27950 \end_layout
27951
27952 \begin_layout Standard
27953 Step program until it reaches a different source line.
27954  Note: pressing <return> repeats the last command.
27955 \end_layout
27956
27957 \begin_layout Subsubsection*
27958 next
27959 \end_layout
27960
27961 \begin_layout Standard
27962 Step program, proceeding through subroutine calls.
27963 \end_layout
27964
27965 \begin_layout Subsubsection*
27966 run
27967 \end_layout
27968
27969 \begin_layout Standard
27970 Start debugged program.
27971 \end_layout
27972
27973 \begin_layout Subsubsection*
27974 ptype variable 
27975 \end_layout
27976
27977 \begin_layout Standard
27978 Print type information of the variable.
27979 \end_layout
27980
27981 \begin_layout Subsubsection*
27982 print variable
27983 \end_layout
27984
27985 \begin_layout Standard
27986 print value of variable.
27987 \end_layout
27988
27989 \begin_layout Subsubsection*
27990 file filename
27991 \end_layout
27992
27993 \begin_layout Standard
27994 load the given file name.
27995  Note this is an alternate method of loading file for debugging.
27996 \end_layout
27997
27998 \begin_layout Subsubsection*
27999 frame
28000 \end_layout
28001
28002 \begin_layout Standard
28003 print information about current frame.
28004 \end_layout
28005
28006 \begin_layout Subsubsection*
28007 set srcmode
28008 \end_layout
28009
28010 \begin_layout Standard
28011 Toggle between C source & assembly source.
28012 \end_layout
28013
28014 \begin_layout Subsubsection*
28015 ! simulator command
28016 \end_layout
28017
28018 \begin_layout Standard
28019 Send the string following '!' to the simulator, the simulator response is
28020  displayed.
28021  Note the debugger does not interpret the command being sent to the simulator,
28022  so if a command like 'go' is sent the debugger can loose its execution
28023  context and may display incorrect values.
28024 \end_layout
28025
28026 \begin_layout Subsubsection*
28027 quit
28028 \end_layout
28029
28030 \begin_layout Standard
28031 "Watch me now.
28032  Iam going Down.
28033  My name is Bobby Brown"
28034 \end_layout
28035
28036 \begin_layout Subsection
28037 Interfacing SDCDB with DDD
28038 \end_layout
28039
28040 \begin_layout Standard
28041 \begin_inset Note Note
28042 status collapsed
28043
28044 \begin_layout Standard
28045 The screenshot was converted from png to eps with: 
28046 \begin_inset Quotes sld
28047 \end_inset
28048
28049 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28050 \begin_inset Quotes srd
28051 \end_inset
28052
28053  which produces a pretty compact eps file which is free from compression
28054  artifacts.
28055 \end_layout
28056
28057 \begin_layout Standard
28058 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28059  as this broke the build system on Sourceforge (pdf-file was broken.
28060  pdflatex does not accept eps files).
28061 \end_layout
28062
28063 \end_inset
28064
28065
28066 \end_layout
28067
28068 \begin_layout Standard
28069 The 
28070 \emph on
28071 p
28072 \emph default
28073 ortable 
28074 \emph on
28075 n
28076 \emph default
28077 etwork 
28078 \emph on
28079 g
28080 \emph default
28081 raphics File 
28082 \size footnotesize
28083
28084 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28085
28086 \end_inset
28087
28088
28089 \size default
28090  shows a screenshot of a debugging session with DDD
28091 \begin_inset LatexCommand \index{DDD (debugger)}
28092
28093 \end_inset
28094
28095  (Unix only) on a simulated 8032.
28096  The debugging session might not run as smoothly as the screenshot suggests.
28097  The debugger allows setting of breakpoints, displaying and changing variables,
28098  single stepping through C and assembler code.
28099  
28100 \newline
28101 The source was compiled with 
28102 \family sans
28103 \series bold
28104
28105 \newline
28106
28107 \newline
28108 sdcc -
28109 \family default
28110 \series default
28111
28112 \begin_inset ERT
28113 status collapsed
28114
28115 \begin_layout Standard
28116
28117
28118 \backslash
28119 /
28120 \end_layout
28121
28122 \end_inset
28123
28124
28125 \family sans
28126 \series bold
28127 -debug ddd_example.c
28128 \family default
28129 \series default
28130  
28131 \family sans
28132 \series bold
28133
28134 \newline
28135
28136 \family default
28137 \series default
28138
28139 \newline
28140 and DDD was invoked with 
28141 \family sans
28142 \series bold
28143
28144 \newline
28145
28146 \newline
28147 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28148 \end_layout
28149
28150 \begin_layout Standard
28151 \begin_inset Note Note
28152 status open
28153
28154 \begin_layout Standard
28155 Check that the double quotes or an apostroph within the command line survive
28156  the LyX tool chain.
28157  Previously the apostrophs got slanted in the PDF output so a cut and paste
28158  did not work.
28159 \end_layout
28160
28161 \end_inset
28162
28163
28164 \end_layout
28165
28166 \begin_layout Subsection
28167 Interfacing SDCDB with XEmacs
28168 \begin_inset LatexCommand \index{XEmacs}
28169
28170 \end_inset
28171
28172
28173 \begin_inset LatexCommand \index{Emacs}
28174
28175 \end_inset
28176
28177
28178 \end_layout
28179
28180 \begin_layout Standard
28181 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28182  sdcdb.el and sdcdbsrc.el.
28183  These two files can be found in the $(prefix)/bin directory after the installat
28184 ion is complete.
28185  These files need to be loaded into XEmacs for the interface to work.
28186  This can be done at XEmacs startup time by inserting the following into
28187  your '.xemacs' file (which can be found in your HOME directory): 
28188 \newline
28189
28190 \newline
28191
28192 \family typewriter
28193 (load-file sdcdbsrc.el) 
28194 \family default
28195
28196 \newline
28197
28198 \newline
28199 .xemacs is a lisp file so the () around the command is REQUIRED.
28200  The files can also be loaded dynamically while XEmacs is running, set the
28201  environment variable 'EMACSLOADPATH' to the installation bin directory
28202  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28203  To start the interface enter the following command: 
28204 \newline
28205
28206 \newline
28207
28208 \family sans
28209 \series bold
28210 ESC-x sdcdbsrc
28211 \family default
28212 \series default
28213
28214 \newline
28215
28216 \newline
28217 You will prompted to enter the file name to be debugged.
28218  
28219 \newline
28220
28221 \newline
28222 The command line options that are passed to the simulator directly are
28223  bound to default values in the file sdcdbsrc.el.
28224  The variables are listed below, these values maybe changed as required.
28225 \end_layout
28226
28227 \begin_layout Itemize
28228 sdcdbsrc-cpu-type '51
28229 \end_layout
28230
28231 \begin_layout Itemize
28232 sdcdbsrc-frequency '11059200
28233 \end_layout
28234
28235 \begin_layout Itemize
28236 sdcdbsrc-serial nil
28237 \end_layout
28238
28239 \begin_layout Standard
28240 The following is a list of key mapping for the debugger interface.
28241 \end_layout
28242
28243 \begin_layout Standard
28244 \InsetSpace ~
28245
28246 \family typewriter
28247
28248 \newline
28249 ;;\InsetSpace ~
28250 Current Listing :: 
28251 \newline
28252 ;;key\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 binding\InsetSpace ~
28267 \InsetSpace ~
28268 \InsetSpace ~
28269 \InsetSpace ~
28270 \InsetSpace ~
28271 \InsetSpace ~
28272 \InsetSpace ~
28273 \InsetSpace ~
28274 \InsetSpace ~
28275 \InsetSpace ~
28276 \InsetSpace ~
28277 \InsetSpace ~
28278 \InsetSpace ~
28279 \InsetSpace ~
28280 \InsetSpace ~
28281 \InsetSpace ~
28282 \InsetSpace ~
28283 \InsetSpace ~
28284 \InsetSpace ~
28285 \InsetSpace ~
28286 \InsetSpace ~
28287 \InsetSpace ~
28288 Comment 
28289 \newline
28290 ;;---\InsetSpace ~
28291 \InsetSpace ~
28292 \InsetSpace ~
28293 \InsetSpace ~
28294 \InsetSpace ~
28295 \InsetSpace ~
28296 \InsetSpace ~
28297 \InsetSpace ~
28298 \InsetSpace ~
28299 \InsetSpace ~
28300 \InsetSpace ~
28301 \InsetSpace ~
28302 \InsetSpace ~
28303 \InsetSpace ~
28304 -------\InsetSpace ~
28305 \InsetSpace ~
28306 \InsetSpace ~
28307 \InsetSpace ~
28308 \InsetSpace ~
28309 \InsetSpace ~
28310 \InsetSpace ~
28311 \InsetSpace ~
28312 \InsetSpace ~
28313 \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 -------
28327 \newline
28328 ;; 
28329 \newline
28330 ;;\InsetSpace ~
28331 n\InsetSpace ~
28332 \InsetSpace ~
28333 \InsetSpace ~
28334 \InsetSpace ~
28335 \InsetSpace ~
28336 \InsetSpace ~
28337 \InsetSpace ~
28338 \InsetSpace ~
28339 \InsetSpace ~
28340 \InsetSpace ~
28341 \InsetSpace ~
28342 \InsetSpace ~
28343 \InsetSpace ~
28344 \InsetSpace ~
28345 \InsetSpace ~
28346 sdcdb-next-fro
28347 m-src\InsetSpace ~
28348 \InsetSpace ~
28349 \InsetSpace ~
28350 \InsetSpace ~
28351 \InsetSpace ~
28352 \InsetSpace ~
28353 \InsetSpace ~
28354 \InsetSpace ~
28355 \InsetSpace ~
28356 \InsetSpace ~
28357 SDCDB next command 
28358 \newline
28359 ;;\InsetSpace ~
28360 b\InsetSpace ~
28361 \InsetSpace ~
28362 \InsetSpace ~
28363 \InsetSpace ~
28364 \InsetSpace ~
28365 \InsetSpace ~
28366 \InsetSpace ~
28367 \InsetSpace ~
28368 \InsetSpace ~
28369 \InsetSpace ~
28370 \InsetSpace ~
28371 \InsetSpace ~
28372 \InsetSpace ~
28373 \InsetSpace ~
28374 \InsetSpace ~
28375 sdcdb-back-from-src\InsetSpace ~
28376 \InsetSpace ~
28377 \InsetSpace ~
28378 \InsetSpace ~
28379 \InsetSpace ~
28380 \InsetSpace ~
28381 \InsetSpace ~
28382 \InsetSpace ~
28383 \InsetSpace ~
28384 \InsetSpace ~
28385 SDCDB back command 
28386 \newline
28387 ;;\InsetSpace ~
28388 c\InsetSpace ~
28389 \InsetSpace ~
28390 \InsetSpace ~
28391 \InsetSpace ~
28392 \InsetSpace ~
28393 \InsetSpace ~
28394 \InsetSpace ~
28395 \InsetSpace ~
28396 \InsetSpace ~
28397 \InsetSpace ~
28398 \InsetSpace ~
28399 \InsetSpace ~
28400 \InsetSpace ~
28401 \InsetSpace ~
28402 \InsetSpace ~
28403 sdcdb-cont-f
28404 rom-src\InsetSpace ~
28405 \InsetSpace ~
28406 \InsetSpace ~
28407 \InsetSpace ~
28408 \InsetSpace ~
28409 \InsetSpace ~
28410 \InsetSpace ~
28411 \InsetSpace ~
28412 \InsetSpace ~
28413 \InsetSpace ~
28414 SDCDB continue command
28415 \newline
28416 ;;\InsetSpace ~
28417 s\InsetSpace ~
28418 \InsetSpace ~
28419 \InsetSpace ~
28420 \InsetSpace ~
28421 \InsetSpace ~
28422 \InsetSpace ~
28423 \InsetSpace ~
28424 \InsetSpace ~
28425 \InsetSpace ~
28426 \InsetSpace ~
28427 \InsetSpace ~
28428 \InsetSpace ~
28429 \InsetSpace ~
28430 \InsetSpace ~
28431 \InsetSpace ~
28432 sdcdb-step-from-src\InsetSpace ~
28433 \InsetSpace ~
28434 \InsetSpace ~
28435 \InsetSpace ~
28436 \InsetSpace ~
28437 \InsetSpace ~
28438 \InsetSpace ~
28439 \InsetSpace ~
28440 \InsetSpace ~
28441 \InsetSpace ~
28442 SDCDB step command 
28443 \newline
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 sdcdb-w
28461 hatis-c-sexp\InsetSpace ~
28462 \InsetSpace ~
28463 \InsetSpace ~
28464 \InsetSpace ~
28465 \InsetSpace ~
28466 \InsetSpace ~
28467 \InsetSpace ~
28468 \InsetSpace ~
28469 \InsetSpace ~
28470 \InsetSpace ~
28471 SDCDB ptypecommand for data at 
28472 \newline
28473 ;;\InsetSpace ~
28474 \InsetSpace ~
28475 \InsetSpace ~
28476 \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 \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 \InsetSpace ~
28506 \InsetSpace ~
28507 \InsetSpace ~
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 buffer point 
28521 \newline
28522 ;;\InsetSpace ~
28523 x\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 sdcdbsrc-delete\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 SDCD
28553 B Delete all breakpoints if no arg 
28554 \newline
28555 ;;\InsetSpace ~
28556 \InsetSpace ~
28557 \InsetSpace ~
28558 \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 \InsetSpace ~
28574 \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 \InsetSpace ~
28590 \InsetSpace ~
28591 \InsetSpace ~
28592 \InsetSpace ~
28593 \InsetSpace ~
28594 \InsetSpace ~
28595 \InsetSpace ~
28596 \InsetSpace ~
28597 \InsetSpace ~
28598 \InsetSpace ~
28599 \InsetSpace ~
28600 \InsetSpace ~
28601 \InsetSpace ~
28602 given or delete arg (C-u arg x) 
28603 \newline
28604 ;;\InsetSpace ~
28605 m\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 sdcdbsrc
28621 -frame\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 SDCDB Display current frame if no arg, 
28637 \newline
28638 ;;\InsetSpace ~
28639 \InsetSpace ~
28640 \InsetSpace ~
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 given or display frame arg
28686  
28687 \newline
28688 ;;\InsetSpace ~
28689 \InsetSpace ~
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 \InsetSpace ~
28707 \InsetSpace ~
28708 \InsetSpace ~
28709 \InsetSpace ~
28710 \InsetSpace ~
28711 \InsetSpace ~
28712 \InsetSpace ~
28713 \InsetSpace ~
28714 \InsetSpace ~
28715 \InsetSpace ~
28716 \InsetSpace ~
28717 \InsetSpace ~
28718 \InsetSpace ~
28719 \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 \InsetSpace ~
28735 buffer point 
28736 \newline
28737 ;;\InsetSpace ~
28738 !\InsetSpace ~
28739 \InsetSpace ~
28740 \InsetSpace ~
28741 \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744 \InsetSpace ~
28745 \InsetSpace ~
28746 \InsetSpace ~
28747 \InsetSpace ~
28748 \InsetSpace ~
28749 \InsetSpace ~
28750 \InsetSpace ~
28751 \InsetSpace ~
28752 \InsetSpace ~
28753 sdcdbsrc-goto-sdcdb\InsetSpace ~
28754 \InsetSpace ~
28755 \InsetSpace ~
28756 \InsetSpace ~
28757 \InsetSpace ~
28758 \InsetSpace ~
28759 \InsetSpace ~
28760 \InsetSpace ~
28761 \InsetSpace ~
28762 \InsetSpace ~
28763 Goto the SDCDB output buffer 
28764 \newline
28765 ;;\InsetSpace ~
28766 p\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 sdcdb-prin
28782 t-c-sexp\InsetSpace ~
28783 \InsetSpace ~
28784 \InsetSpace ~
28785 \InsetSpace ~
28786 \InsetSpace ~
28787 \InsetSpace ~
28788 \InsetSpace ~
28789 \InsetSpace ~
28790 \InsetSpace ~
28791 \InsetSpace ~
28792 \InsetSpace ~
28793 SDCDB print command for data at 
28794 \newline
28795 ;;\InsetSpace ~
28796 \InsetSpace ~
28797 \InsetSpace ~
28798 \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 \InsetSpace ~
28814 \InsetSpace ~
28815 \InsetSpace ~
28816 \InsetSpace ~
28817 \InsetSpace ~
28818 \InsetSpace ~
28819 \InsetSpace ~
28820 \InsetSpace ~
28821 \InsetSpace ~
28822 \InsetSpace ~
28823 \InsetSpace ~
28824 \InsetSpace ~
28825 \InsetSpace ~
28826 \InsetSpace ~
28827 \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 buffer point 
28843 \newline
28844 ;;\InsetSpace ~
28845 g\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 \InsetSpace ~
28859 \InsetSpace ~
28860 sdcdbsrc-goto-sdcdb\InsetSpace ~
28861 \InsetSpace ~
28862 \InsetSpace ~
28863 \InsetSpace ~
28864 \InsetSpace ~
28865 \InsetSpace ~
28866 \InsetSpace ~
28867 \InsetSpace ~
28868 \InsetSpace ~
28869 \InsetSpace ~
28870 Got
28871 o the SDCDB output buffer 
28872 \newline
28873 ;;\InsetSpace ~
28874 t\InsetSpace ~
28875 \InsetSpace ~
28876 \InsetSpace ~
28877 \InsetSpace ~
28878 \InsetSpace ~
28879 \InsetSpace ~
28880 \InsetSpace ~
28881 \InsetSpace ~
28882 \InsetSpace ~
28883 \InsetSpace ~
28884 \InsetSpace ~
28885 \InsetSpace ~
28886 \InsetSpace ~
28887 \InsetSpace ~
28888 \InsetSpace ~
28889 sdcdbsrc-mode\InsetSpace ~
28890 \InsetSpace ~
28891 \InsetSpace ~
28892 \InsetSpace ~
28893 \InsetSpace ~
28894 \InsetSpace ~
28895 \InsetSpace ~
28896 \InsetSpace ~
28897 \InsetSpace ~
28898 \InsetSpace ~
28899 \InsetSpace ~
28900 \InsetSpace ~
28901 \InsetSpace ~
28902 \InsetSpace ~
28903 \InsetSpace ~
28904 \InsetSpace ~
28905 Toggles Sdcdbsrc mode (turns it
28906  off) 
28907 \newline
28908 ;; 
28909 \newline
28910 ;;\InsetSpace ~
28911 C-c\InsetSpace ~
28912 C-f\InsetSpace ~
28913 \InsetSpace ~
28914 \InsetSpace ~
28915 \InsetSpace ~
28916 \InsetSpace ~
28917 \InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 sdcdb-finish-from-src\InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 \InsetSpace ~
28928 \InsetSpace ~
28929 SDCDB finish command 
28930 \newline
28931 ;; 
28932 \newline
28933 ;;\InsetSpace ~
28934 C-x\InsetSpace ~
28935 SPC\InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 \InsetSpace ~
28940 \InsetSpace ~
28941 \InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 sdcdb-brea
28945 k\InsetSpace ~
28946 \InsetSpace ~
28947 \InsetSpace ~
28948 \InsetSpace ~
28949 \InsetSpace ~
28950 \InsetSpace ~
28951 \InsetSpace ~
28952 \InsetSpace ~
28953 \InsetSpace ~
28954 \InsetSpace ~
28955 \InsetSpace ~
28956 \InsetSpace ~
28957 \InsetSpace ~
28958 \InsetSpace ~
28959 \InsetSpace ~
28960 \InsetSpace ~
28961 \InsetSpace ~
28962 \InsetSpace ~
28963 Set break for line with point 
28964 \newline
28965 ;;\InsetSpace ~
28966 ESC\InsetSpace ~
28967 t\InsetSpace ~
28968 \InsetSpace ~
28969 \InsetSpace ~
28970 \InsetSpace ~
28971 \InsetSpace ~
28972 \InsetSpace ~
28973 \InsetSpace ~
28974 \InsetSpace ~
28975 \InsetSpace ~
28976 \InsetSpace ~
28977 \InsetSpace ~
28978 sdcdbsrc-mode\InsetSpace ~
28979 \InsetSpace ~
28980 \InsetSpace ~
28981 \InsetSpace ~
28982 \InsetSpace ~
28983 \InsetSpace ~
28984 \InsetSpace ~
28985 \InsetSpace ~
28986 \InsetSpace ~
28987 \InsetSpace ~
28988 \InsetSpace ~
28989 \InsetSpace ~
28990 \InsetSpace ~
28991 \InsetSpace ~
28992 \InsetSpace ~
28993 \InsetSpace ~
28994 Toggle Sdcdbsrc mode 
28995 \newline
28996 ;;\InsetSpace ~
28997 ESC\InsetSpace ~
28998 m\InsetSpace ~
28999 \InsetSpace ~
29000 \InsetSpace ~
29001 \InsetSpace ~
29002 \InsetSpace ~
29003 \InsetSpace ~
29004 \InsetSpace ~
29005 \InsetSpace ~
29006 \InsetSpace ~
29007 \InsetSpace ~
29008 \InsetSpace ~
29009 sdc
29010 dbsrc-srcmode\InsetSpace ~
29011 \InsetSpace ~
29012 \InsetSpace ~
29013 \InsetSpace ~
29014 \InsetSpace ~
29015 \InsetSpace ~
29016 \InsetSpace ~
29017 \InsetSpace ~
29018 \InsetSpace ~
29019 \InsetSpace ~
29020 \InsetSpace ~
29021 \InsetSpace ~
29022 \InsetSpace ~
29023 Toggle list mode 
29024 \newline
29025 ;; 
29026 \newline
29027
29028 \family default
29029
29030 \newpage
29031
29032 \end_layout
29033
29034 \begin_layout Chapter
29035 TIPS
29036 \end_layout
29037
29038 \begin_layout Standard
29039 Here are a few guidelines that will help the compiler generate more efficient
29040  code, some of the tips are specific to this compiler others are generally
29041  good programming practice.
29042 \end_layout
29043
29044 \begin_layout Itemize
29045 Use the smallest data type to represent your data-value.
29046  If it is known in advance that the value is going to be less than 256 then
29047  use an 'unsigned char' instead of a 'short' or 'int'.
29048  Please note, that ANSI C requires both signed and unsigned chars to be
29049  promoted to 'signed int'
29050 \begin_inset LatexCommand \index{promotion to signed int}
29051
29052 \end_inset
29053
29054
29055 \begin_inset Marginal
29056 status collapsed
29057
29058 \begin_layout Standard
29059
29060 \series bold
29061 \InsetSpace ~
29062 !
29063 \end_layout
29064
29065 \end_inset
29066
29067  before doing any operation.
29068  This promotion
29069 \begin_inset LatexCommand \index{type promotion}
29070
29071 \end_inset
29072
29073
29074 \begin_inset LatexCommand \label{type promotion}
29075
29076 \end_inset
29077
29078  can be omitted, if the result is the same.
29079  The effect of the promotion rules together with the sign-extension is often
29080  surprising:
29081 \end_layout
29082
29083 \begin_deeper
29084 \begin_layout Verse
29085
29086 \family typewriter
29087 unsigned char uc = 0xfe;
29088 \newline
29089 if (uc * uc < 0) /* this is true! */
29090 \newline
29091 {
29092 \newline
29093 \InsetSpace ~
29094 \InsetSpace ~
29095 \InsetSpace ~
29096 \InsetSpace ~
29097 ....
29098 \newline
29099 }
29100 \end_layout
29101
29102 \begin_layout Standard
29103
29104 \family typewriter
29105 uc * uc
29106 \family default
29107  is evaluated as 
29108 \family typewriter
29109 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29110 \family default
29111 .
29112  
29113 \newline
29114 Another one:
29115 \end_layout
29116
29117 \begin_layout Verse
29118
29119 \family typewriter
29120 (unsigned char) -12 / (signed char) -3 = ...
29121 \end_layout
29122
29123 \begin_layout Standard
29124 No, the result is not 4:
29125 \end_layout
29126
29127 \begin_layout Verse
29128
29129 \family typewriter
29130 (int) (unsigned char) -12 / (int) (signed char) -3 =
29131 \newline
29132 (int) (unsigned char)
29133  0xf4 / (int) (signed char) 0xfd =
29134 \newline
29135 (int) 0x00f4 / (int) 0xfffd =
29136 \newline
29137 (int) 0x00f4
29138  / (int) 0xfffd =
29139 \newline
29140 (int) 244 / (int) -3 =
29141 \newline
29142 (int) -81 = (int) 0xffaf;
29143 \end_layout
29144
29145 \begin_layout Standard
29146 Don't complain, that gcc gives you a different result.
29147  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29148  Therefore the results are different.
29149 \newline
29150 From 
29151 \begin_inset Quotes sld
29152 \end_inset
29153
29154 comp.lang.c FAQ
29155 \begin_inset Quotes srd
29156 \end_inset
29157
29158 :
29159 \end_layout
29160
29161 \begin_layout Quote
29162
29163 \emph on
29164 If well-defined overflow characteristics are important and negative values
29165  are not, or if you want to steer clear of sign-extension problems when
29166  manipulating bits or bytes, use one of the corresponding unsigned types.
29167  (Beware when mixing signed and unsigned values in expressions, though.)
29168 \newline
29169 Although
29170  character types (especially unsigned char) can be used as "tiny" integers,
29171  doing so is sometimes more trouble than it's worth, due to unpredictable
29172  sign extension and increased code size.
29173 \end_layout
29174
29175 \end_deeper
29176 \begin_layout Itemize
29177 Use unsigned when it is known in advance that the value is not going to
29178  be negative.
29179  This helps especially if you are doing division or multiplication, bit-shifting
29180  or are using an array index.
29181 \end_layout
29182
29183 \begin_layout Itemize
29184 NEVER jump into a LOOP.
29185 \end_layout
29186
29187 \begin_layout Itemize
29188 Declare the variables to be local
29189 \begin_inset LatexCommand \index{local variables}
29190
29191 \end_inset
29192
29193  whenever possible, especially loop control variables (induction).
29194 \end_layout
29195
29196 \begin_layout Itemize
29197 Have a look at the assembly listing to get a 
29198 \begin_inset Quotes sld
29199 \end_inset
29200
29201 feeling
29202 \begin_inset Quotes srd
29203 \end_inset
29204
29205  for the code generation.
29206 \end_layout
29207
29208 \begin_layout Section
29209 Porting code from or to other compilers
29210 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29211
29212 \end_inset
29213
29214
29215 \end_layout
29216
29217 \begin_layout Itemize
29218 check whether endianness of the compilers differs and adapt where needed.
29219 \end_layout
29220
29221 \begin_layout Itemize
29222 check the device specific header files
29223 \begin_inset LatexCommand \index{Header files}
29224
29225 \end_inset
29226
29227
29228 \begin_inset LatexCommand \index{Include files}
29229
29230 \end_inset
29231
29232  for compiler specific syntax.
29233  Eventually include the file <compiler.h
29234 \begin_inset LatexCommand \index{compiler.h (include file)}
29235
29236 \end_inset
29237
29238
29239 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29240
29241 \end_inset
29242
29243  to allow using common header files.
29244  (see f.e.
29245  cc2510fx.h 
29246 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29247
29248 \end_inset
29249
29250 ).
29251 \end_layout
29252
29253 \begin_layout Itemize
29254 check whether the startup code contains the correct initialization (watchdog,
29255  peripherals).
29256 \end_layout
29257
29258 \begin_layout Itemize
29259 check whether the sizes of short, int, long match.
29260 \end_layout
29261
29262 \begin_layout Itemize
29263 check if some 16 or 32 bit hardware registers require a specific addressing
29264  order (least significant or most significant byte first) and adapt if needed
29265  (
29266 \emph on
29267 first
29268 \emph default
29269  and 
29270 \emph on
29271 last
29272 \emph default
29273  relate to time and not to lower/upper memory location here, so this is
29274  
29275 \emph on
29276 not
29277 \emph default
29278  the same as endianness).
29279 \end_layout
29280
29281 \begin_layout Itemize
29282 check whether the keyword 
29283 \emph on
29284 volatile
29285 \emph default
29286  is used where needed.
29287  The compilers might differ in their optimization characteristics (as different
29288  versions of the same compiler might also use more clever optimizations
29289  this is good idea anyway).
29290  See section 
29291 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29292
29293 \end_inset
29294
29295 .
29296 \end_layout
29297
29298 \begin_layout Itemize
29299 check that the compilers are not told to supress warnings.
29300 \end_layout
29301
29302 \begin_layout Itemize
29303 check and convert compiler specific extensions (interrupts, memory areas,
29304  pragmas etc.).
29305 \end_layout
29306
29307 \begin_layout Itemize
29308 check for differences in type promotion.
29309  Especially check for math operations on 
29310 \family typewriter
29311 char
29312 \family default
29313  or 
29314 \family typewriter
29315 unsigned char
29316 \family default
29317  variables.
29318  For the sake of C99 compatibility SDCC will probably promote these to 
29319 \family typewriter
29320 int
29321 \family default
29322  more often than other compilers.
29323  Eventually insert explicit casts to 
29324 \family typewriter
29325 (char) 
29326 \family default
29327 or
29328 \family typewriter
29329  (unsigned char)
29330 \family default
29331 .
29332  Also check that the ~\InsetSpace ~
29333 operator
29334 \begin_inset LatexCommand \index{\~\/ Operator}
29335
29336 \end_inset
29337
29338  is not used on 
29339 \family typewriter
29340 bit
29341 \begin_inset LatexCommand \index{bit}
29342
29343 \end_inset
29344
29345
29346 \family default
29347  variables, use the !\InsetSpace ~
29348 operator instead.
29349  See sections 
29350 \begin_inset LatexCommand \ref{type promotion}
29351
29352 \end_inset
29353
29354  and 
29355 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29356
29357 \end_inset
29358
29359 .
29360 \end_layout
29361
29362 \begin_layout Itemize
29363 check the assembly code generated for interrupt routines (f.e.
29364  for calls to possibly non-reentrant library functions).
29365 \end_layout
29366
29367 \begin_layout Itemize
29368 check whether timing loops result in proper timing (or preferably consider
29369  a rewrite of the code with timer based delays instead).
29370 \end_layout
29371
29372 \begin_layout Itemize
29373 check for differences in printf parameters (some compilers push (va_arg
29374 \begin_inset LatexCommand \index{vararg, va\_arg}
29375
29376 \end_inset
29377
29378 ) char variables as 
29379 \family typewriter
29380 int
29381 \family default
29382  others push them as 
29383 \family typewriter
29384 char
29385 \family default
29386 .
29387  See section 
29388 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29389
29390 \end_inset
29391
29392 ).
29393 \end_layout
29394
29395 \begin_layout Itemize
29396 check the resulting memory map
29397 \begin_inset LatexCommand \index{Memory map}
29398
29399 \end_inset
29400
29401 .
29402  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29403 ly idata, pdata, xdata).
29404  Eventually check if unexpected library functions are included.
29405 \end_layout
29406
29407 \begin_layout Section
29408 Tools
29409 \begin_inset LatexCommand \index{Tools}
29410
29411 \end_inset
29412
29413  included in the distribution
29414 \end_layout
29415
29416 \begin_layout Standard
29417 \align left
29418 \begin_inset Tabular
29419 <lyxtabular version="3" rows="12" columns="3">
29420 <features>
29421 <column alignment="left" valignment="top" leftline="true" width="0pt">
29422 <column alignment="left" valignment="top" leftline="true" width="0pt">
29423 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29424 <row topline="true" bottomline="true">
29425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29426 \begin_inset Text
29427
29428 \begin_layout Standard
29429
29430 \series bold
29431 Name
29432 \end_layout
29433
29434 \end_inset
29435 </cell>
29436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29437 \begin_inset Text
29438
29439 \begin_layout Standard
29440
29441 \series bold
29442 Purpose
29443 \end_layout
29444
29445 \end_inset
29446 </cell>
29447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29448 \begin_inset Text
29449
29450 \begin_layout Standard
29451
29452 \series bold
29453 Directory
29454 \end_layout
29455
29456 \end_inset
29457 </cell>
29458 </row>
29459 <row topline="true">
29460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29461 \begin_inset Text
29462
29463 \begin_layout Standard
29464 uCsim
29465 \begin_inset LatexCommand \index{uCsim}
29466
29467 \end_inset
29468
29469
29470 \end_layout
29471
29472 \end_inset
29473 </cell>
29474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29475 \begin_inset Text
29476
29477 \begin_layout Standard
29478 Simulator for various architectures
29479 \end_layout
29480
29481 \end_inset
29482 </cell>
29483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29484 \begin_inset Text
29485
29486 \begin_layout Standard
29487 sdcc/sim/ucsim
29488 \end_layout
29489
29490 \end_inset
29491 </cell>
29492 </row>
29493 <row topline="true">
29494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29495 \begin_inset Text
29496
29497 \begin_layout Standard
29498 keil2sdcc.pl
29499 \end_layout
29500
29501 \end_inset
29502 </cell>
29503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29504 \begin_inset Text
29505
29506 \begin_layout Standard
29507 header file
29508 \begin_inset LatexCommand \index{Header files}
29509
29510 \end_inset
29511
29512
29513 \begin_inset LatexCommand \index{Include files}
29514
29515 \end_inset
29516
29517  conversion
29518 \end_layout
29519
29520 \end_inset
29521 </cell>
29522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29523 \begin_inset Text
29524
29525 \begin_layout Standard
29526 sdcc/support/scripts
29527 \end_layout
29528
29529 \end_inset
29530 </cell>
29531 </row>
29532 <row topline="true">
29533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29534 \begin_inset Text
29535
29536 \begin_layout Standard
29537 mh2h.c
29538 \end_layout
29539
29540 \end_inset
29541 </cell>
29542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29543 \begin_inset Text
29544
29545 \begin_layout Standard
29546 header file conversion
29547 \end_layout
29548
29549 \end_inset
29550 </cell>
29551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29552 \begin_inset Text
29553
29554 \begin_layout Standard
29555 sdcc/support/scripts
29556 \end_layout
29557
29558 \end_inset
29559 </cell>
29560 </row>
29561 <row topline="true">
29562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29563 \begin_inset Text
29564
29565 \begin_layout Standard
29566 as-gbz80
29567 \end_layout
29568
29569 \end_inset
29570 </cell>
29571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29572 \begin_inset Text
29573
29574 \begin_layout Standard
29575 Assembler
29576 \end_layout
29577
29578 \end_inset
29579 </cell>
29580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29581 \begin_inset Text
29582
29583 \begin_layout Standard
29584
29585 \family roman
29586 \series medium
29587 \shape up
29588 \size normal
29589 \emph off
29590 \bar no
29591 \noun off
29592 \color none
29593 sdcc/bin
29594 \end_layout
29595
29596 \end_inset
29597 </cell>
29598 </row>
29599 <row topline="true">
29600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29601 \begin_inset Text
29602
29603 \begin_layout Standard
29604 as-z80
29605 \end_layout
29606
29607 \end_inset
29608 </cell>
29609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29610 \begin_inset Text
29611
29612 \begin_layout Standard
29613 Assembler
29614 \end_layout
29615
29616 \end_inset
29617 </cell>
29618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29619 \begin_inset Text
29620
29621 \begin_layout Standard
29622
29623 \family roman
29624 \series medium
29625 \shape up
29626 \size normal
29627 \emph off
29628 \bar no
29629 \noun off
29630 \color none
29631 sdcc/bin
29632 \end_layout
29633
29634 \end_inset
29635 </cell>
29636 </row>
29637 <row topline="true">
29638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29639 \begin_inset Text
29640
29641 \begin_layout Standard
29642 asx8051
29643 \end_layout
29644
29645 \end_inset
29646 </cell>
29647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29648 \begin_inset Text
29649
29650 \begin_layout Standard
29651 Assembler
29652 \end_layout
29653
29654 \end_inset
29655 </cell>
29656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29657 \begin_inset Text
29658
29659 \begin_layout Standard
29660
29661 \family roman
29662 \series medium
29663 \shape up
29664 \size normal
29665 \emph off
29666 \bar no
29667 \noun off
29668 \color none
29669 sdcc/bin
29670 \end_layout
29671
29672 \end_inset
29673 </cell>
29674 </row>
29675 <row topline="true">
29676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29677 \begin_inset Text
29678
29679 \begin_layout Standard
29680 SDCDB
29681 \end_layout
29682
29683 \end_inset
29684 </cell>
29685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29686 \begin_inset Text
29687
29688 \begin_layout Standard
29689 Simulator
29690 \end_layout
29691
29692 \end_inset
29693 </cell>
29694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29695 \begin_inset Text
29696
29697 \begin_layout Standard
29698
29699 \family roman
29700 \series medium
29701 \shape up
29702 \size normal
29703 \emph off
29704 \bar no
29705 \noun off
29706 \color none
29707 sdcc/bin
29708 \end_layout
29709
29710 \end_inset
29711 </cell>
29712 </row>
29713 <row topline="true">
29714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29715 \begin_inset Text
29716
29717 \begin_layout Standard
29718 aslink
29719 \end_layout
29720
29721 \end_inset
29722 </cell>
29723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29724 \begin_inset Text
29725
29726 \begin_layout Standard
29727 Linker
29728 \end_layout
29729
29730 \end_inset
29731 </cell>
29732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29733 \begin_inset Text
29734
29735 \begin_layout Standard
29736
29737 \family roman
29738 \series medium
29739 \shape up
29740 \size normal
29741 \emph off
29742 \bar no
29743 \noun off
29744 \color none
29745 sdcc/bin
29746 \end_layout
29747
29748 \end_inset
29749 </cell>
29750 </row>
29751 <row topline="true">
29752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29753 \begin_inset Text
29754
29755 \begin_layout Standard
29756 link-z80
29757 \end_layout
29758
29759 \end_inset
29760 </cell>
29761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29762 \begin_inset Text
29763
29764 \begin_layout Standard
29765 Linker
29766 \end_layout
29767
29768 \end_inset
29769 </cell>
29770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29771 \begin_inset Text
29772
29773 \begin_layout Standard
29774
29775 \family roman
29776 \series medium
29777 \shape up
29778 \size normal
29779 \emph off
29780 \bar no
29781 \noun off
29782 \color none
29783 sdcc/bin
29784 \end_layout
29785
29786 \end_inset
29787 </cell>
29788 </row>
29789 <row topline="true">
29790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29791 \begin_inset Text
29792
29793 \begin_layout Standard
29794 link-gbz80
29795 \end_layout
29796
29797 \end_inset
29798 </cell>
29799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29800 \begin_inset Text
29801
29802 \begin_layout Standard
29803 Linker
29804 \end_layout
29805
29806 \end_inset
29807 </cell>
29808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29809 \begin_inset Text
29810
29811 \begin_layout Standard
29812
29813 \family roman
29814 \series medium
29815 \shape up
29816 \size normal
29817 \emph off
29818 \bar no
29819 \noun off
29820 \color none
29821 sdcc/bin
29822 \end_layout
29823
29824 \end_inset
29825 </cell>
29826 </row>
29827 <row topline="true" bottomline="true">
29828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29829 \begin_inset Text
29830
29831 \begin_layout Standard
29832 packihx
29833 \end_layout
29834
29835 \end_inset
29836 </cell>
29837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29838 \begin_inset Text
29839
29840 \begin_layout Standard
29841 Intel Hex packer 
29842 \begin_inset LatexCommand \index{packihx (tool)}
29843
29844 \end_inset
29845
29846
29847 \end_layout
29848
29849 \end_inset
29850 </cell>
29851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29852 \begin_inset Text
29853
29854 \begin_layout Standard
29855
29856 \family roman
29857 \series medium
29858 \shape up
29859 \size normal
29860 \emph off
29861 \bar no
29862 \noun off
29863 \color none
29864 sdcc/bin
29865 \end_layout
29866
29867 \end_inset
29868 </cell>
29869 </row>
29870 </lyxtabular>
29871
29872 \end_inset
29873
29874
29875 \newline
29876
29877 \end_layout
29878
29879 \begin_layout Section
29880 Documentation
29881 \begin_inset LatexCommand \index{Documentation}
29882
29883 \end_inset
29884
29885  included in the distribution
29886 \end_layout
29887
29888 \begin_layout Standard
29889 \align left
29890 \begin_inset Tabular
29891 <lyxtabular version="3" rows="10" columns="2">
29892 <features>
29893 <column alignment="block" valignment="top" leftline="true" width="40col%">
29894 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29895 <row topline="true" bottomline="true" endhead="true">
29896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29897 \begin_inset Text
29898
29899 \begin_layout Standard
29900
29901 \series bold
29902 Subject / Title
29903 \end_layout
29904
29905 \end_inset
29906 </cell>
29907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29908 \begin_inset Text
29909
29910 \begin_layout Standard
29911
29912 \series bold
29913 Filename / Where to get
29914 \end_layout
29915
29916 \end_inset
29917 </cell>
29918 </row>
29919 <row topline="true">
29920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29921 \begin_inset Text
29922
29923 \begin_layout Standard
29924 SDCC Compiler User Guide
29925 \end_layout
29926
29927 \end_inset
29928 </cell>
29929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29930 \begin_inset Text
29931
29932 \begin_layout Standard
29933 You're reading it right now
29934 \emph on
29935  \InsetSpace ~
29936 \InsetSpace ~
29937 \InsetSpace ~
29938
29939 \hfill
29940 online at:
29941 \emph default
29942
29943 \newline
29944
29945 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29946
29947 \end_inset
29948
29949
29950 \end_layout
29951
29952 \end_inset
29953 </cell>
29954 </row>
29955 <row topline="true">
29956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29957 \begin_inset Text
29958
29959 \begin_layout Standard
29960 Changelog of SDCC
29961 \end_layout
29962
29963 \end_inset
29964 </cell>
29965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29966 \begin_inset Text
29967
29968 \begin_layout Standard
29969 sdcc/Changelog
29970 \emph on
29971  \InsetSpace ~
29972 \InsetSpace ~
29973 \InsetSpace ~
29974
29975 \hfill
29976 online at:
29977 \emph default
29978
29979 \newline
29980
29981 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29982
29983 \end_inset
29984
29985
29986 \end_layout
29987
29988 \end_inset
29989 </cell>
29990 </row>
29991 <row topline="true">
29992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29993 \begin_inset Text
29994
29995 \begin_layout Standard
29996 ASXXXX
29997 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29998
29999 \end_inset
30000
30001
30002 \begin_inset LatexCommand \index{Assembler documentation}
30003
30004 \end_inset
30005
30006  Assemblers and
30007 \newline
30008 ASLINK
30009 \begin_inset LatexCommand \index{aslink}
30010
30011 \end_inset
30012
30013
30014 \begin_inset LatexCommand \index{Linker documentation}
30015
30016 \end_inset
30017
30018  Relocating Linker
30019 \end_layout
30020
30021 \end_inset
30022 </cell>
30023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30024 \begin_inset Text
30025
30026 \begin_layout Standard
30027 sdcc/as/doc/asxhtm.html 
30028 \emph on
30029 \InsetSpace ~
30030 \InsetSpace ~
30031 \InsetSpace ~
30032
30033 \hfill
30034 online at:
30035 \emph default
30036
30037 \newline
30038
30039 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30040
30041 \end_inset
30042
30043
30044 \end_layout
30045
30046 \end_inset
30047 </cell>
30048 </row>
30049 <row topline="true">
30050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30051 \begin_inset Text
30052
30053 \begin_layout Standard
30054 SDCC regression test
30055 \begin_inset LatexCommand \index{Regression test}
30056
30057 \end_inset
30058
30059
30060 \end_layout
30061
30062 \end_inset
30063 </cell>
30064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30065 \begin_inset Text
30066
30067 \begin_layout Standard
30068 sdcc/doc/test_suite_spec.pdf 
30069 \emph on
30070 \InsetSpace ~
30071 \InsetSpace ~
30072 \InsetSpace ~
30073
30074 \hfill
30075 online at:
30076 \emph default
30077
30078 \newline
30079
30080 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30081
30082 \end_inset
30083
30084
30085 \end_layout
30086
30087 \end_inset
30088 </cell>
30089 </row>
30090 <row topline="true">
30091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30092 \begin_inset Text
30093
30094 \begin_layout Standard
30095 Various notes
30096 \end_layout
30097
30098 \end_inset
30099 </cell>
30100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30101 \begin_inset Text
30102
30103 \begin_layout Standard
30104 sdcc/doc/* 
30105 \emph on
30106 \InsetSpace ~
30107 \InsetSpace ~
30108 \InsetSpace ~
30109
30110 \hfill
30111 online at:
30112 \emph default
30113
30114 \newline
30115
30116 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30117
30118 \end_inset
30119
30120
30121 \end_layout
30122
30123 \end_inset
30124 </cell>
30125 </row>
30126 <row topline="true">
30127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30128 \begin_inset Text
30129
30130 \begin_layout Standard
30131 Notes on debugging with SDCDB
30132 \begin_inset LatexCommand \index{SDCDB (debugger)}
30133
30134 \end_inset
30135
30136
30137 \end_layout
30138
30139 \end_inset
30140 </cell>
30141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30142 \begin_inset Text
30143
30144 \begin_layout Standard
30145 sdcc/debugger/README 
30146 \emph on
30147 \InsetSpace ~
30148 \InsetSpace ~
30149 \InsetSpace ~
30150
30151 \hfill
30152 online at
30153 \emph default
30154 :
30155 \newline
30156
30157 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30158
30159 \end_inset
30160
30161
30162 \end_layout
30163
30164 \end_inset
30165 </cell>
30166 </row>
30167 <row topline="true">
30168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30169 \begin_inset Text
30170
30171 \begin_layout Standard
30172 uCsim
30173 \begin_inset LatexCommand \index{uCsim}
30174
30175 \end_inset
30176
30177  Software simulator for microcontrollers
30178 \end_layout
30179
30180 \end_inset
30181 </cell>
30182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30183 \begin_inset Text
30184
30185 \begin_layout Standard
30186
30187 \family roman
30188 \series medium
30189 \shape up
30190 \size normal
30191 \emph off
30192 \bar no
30193 \noun off
30194 \color none
30195 sdcc/sim/ucsim/doc
30196 \family default
30197 \series default
30198 \shape default
30199 \size default
30200 \emph default
30201 \bar default
30202 \noun default
30203 /index.html 
30204 \emph on
30205 \InsetSpace ~
30206 \InsetSpace ~
30207 \InsetSpace ~
30208
30209 \hfill
30210 online at:
30211 \emph default
30212
30213 \newline
30214
30215 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30216
30217 \end_inset
30218
30219
30220 \end_layout
30221
30222 \end_inset
30223 </cell>
30224 </row>
30225 <row topline="true">
30226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30227 \begin_inset Text
30228
30229 \begin_layout Standard
30230 Temporary notes on the pic16
30231 \begin_inset LatexCommand \index{PIC16}
30232
30233 \end_inset
30234
30235  port
30236 \end_layout
30237
30238 \end_inset
30239 </cell>
30240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30241 \begin_inset Text
30242
30243 \begin_layout Standard
30244 sdcc/src/pic16/NOTES 
30245 \emph on
30246 \InsetSpace ~
30247 \InsetSpace ~
30248 \InsetSpace ~
30249
30250 \hfill
30251 online at:
30252 \newline
30253
30254 \emph default
30255
30256 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30257
30258 \end_inset
30259
30260
30261 \end_layout
30262
30263 \end_inset
30264 </cell>
30265 </row>
30266 <row topline="true" bottomline="true">
30267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30268 \begin_inset Text
30269
30270 \begin_layout Standard
30271 SDCC internal documentation (debugging file format)
30272 \end_layout
30273
30274 \end_inset
30275 </cell>
30276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30277 \begin_inset Text
30278
30279 \begin_layout Standard
30280 sdcc/doc/
30281 \family roman
30282 \series medium
30283 \shape up
30284 \size normal
30285 \emph off
30286 \bar no
30287 \noun off
30288 \color none
30289 cdbfileformat.pd
30290 \family default
30291 \series default
30292 \shape default
30293 \size default
30294 \emph default
30295 \bar default
30296 \noun default
30297 f
30298 \emph on
30299  \InsetSpace ~
30300 \InsetSpace ~
30301 \InsetSpace ~
30302
30303 \hfill
30304 online at:
30305 \emph default
30306
30307 \newline
30308
30309 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30310
30311 \end_inset
30312
30313
30314 \end_layout
30315
30316 \end_inset
30317 </cell>
30318 </row>
30319 </lyxtabular>
30320
30321 \end_inset
30322
30323
30324 \newline
30325
30326 \end_layout
30327
30328 \begin_layout Section
30329 Related open source tools
30330 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30331
30332 \end_inset
30333
30334
30335 \begin_inset LatexCommand \index{Related tools}
30336
30337 \end_inset
30338
30339
30340 \end_layout
30341
30342 \begin_layout Standard
30343 \align left
30344 \begin_inset Tabular
30345 <lyxtabular version="3" rows="14" columns="3">
30346 <features>
30347 <column alignment="left" valignment="top" leftline="true" width="0pt">
30348 <column alignment="block" valignment="top" leftline="true" width="30line%">
30349 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30350 <row topline="true" bottomline="true">
30351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30352 \begin_inset Text
30353
30354 \begin_layout Standard
30355
30356 \series bold
30357 Name
30358 \end_layout
30359
30360 \end_inset
30361 </cell>
30362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30363 \begin_inset Text
30364
30365 \begin_layout Standard
30366
30367 \series bold
30368 Purpose
30369 \end_layout
30370
30371 \end_inset
30372 </cell>
30373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30374 \begin_inset Text
30375
30376 \begin_layout Standard
30377
30378 \series bold
30379 Where to get
30380 \end_layout
30381
30382 \end_inset
30383 </cell>
30384 </row>
30385 <row topline="true">
30386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30387 \begin_inset Text
30388
30389 \begin_layout Standard
30390 gpsim
30391 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30392
30393 \end_inset
30394
30395
30396 \end_layout
30397
30398 \end_inset
30399 </cell>
30400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30401 \begin_inset Text
30402
30403 \begin_layout Standard
30404 PIC simulator
30405 \end_layout
30406
30407 \end_inset
30408 </cell>
30409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30410 \begin_inset Text
30411
30412 \begin_layout Standard
30413 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30414
30415 \end_inset
30416
30417
30418 \end_layout
30419
30420 \end_inset
30421 </cell>
30422 </row>
30423 <row topline="true">
30424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30425 \begin_inset Text
30426
30427 \begin_layout Standard
30428 gputils
30429 \begin_inset LatexCommand \index{gputils (pic tools)}
30430
30431 \end_inset
30432
30433
30434 \end_layout
30435
30436 \end_inset
30437 </cell>
30438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30439 \begin_inset Text
30440
30441 \begin_layout Standard
30442 GNU PIC utilities
30443 \end_layout
30444
30445 \end_inset
30446 </cell>
30447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30448 \begin_inset Text
30449
30450 \begin_layout Standard
30451 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30452
30453 \end_inset
30454
30455
30456 \end_layout
30457
30458 \end_inset
30459 </cell>
30460 </row>
30461 <row topline="true">
30462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30463 \begin_inset Text
30464
30465 \begin_layout Standard
30466 flP5
30467 \end_layout
30468
30469 \end_inset
30470 </cell>
30471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30472 \begin_inset Text
30473
30474 \begin_layout Standard
30475 PIC programmer
30476 \end_layout
30477
30478 \end_inset
30479 </cell>
30480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30481 \begin_inset Text
30482
30483 \begin_layout Standard
30484 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30485
30486 \end_inset
30487
30488
30489 \end_layout
30490
30491 \end_inset
30492 </cell>
30493 </row>
30494 <row topline="true">
30495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30496 \begin_inset Text
30497
30498 \begin_layout Standard
30499 ec2drv/newcdb
30500 \end_layout
30501
30502 \end_inset
30503 </cell>
30504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30505 \begin_inset Text
30506
30507 \begin_layout Standard
30508 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30509  (Unix only)
30510 \end_layout
30511
30512 \end_inset
30513 </cell>
30514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30515 \begin_inset Text
30516
30517 \begin_layout Standard
30518 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30519
30520 \end_inset
30521
30522
30523 \end_layout
30524
30525 \end_inset
30526 </cell>
30527 </row>
30528 <row topline="true">
30529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30530 \begin_inset Text
30531
30532 \begin_layout Standard
30533 indent
30534 \begin_inset LatexCommand \index{indent (source formatting tool)}
30535
30536 \end_inset
30537
30538
30539 \end_layout
30540
30541 \end_inset
30542 </cell>
30543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30544 \begin_inset Text
30545
30546 \begin_layout Standard
30547 Formats C source - Master of the white spaces
30548 \end_layout
30549
30550 \end_inset
30551 </cell>
30552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30553 \begin_inset Text
30554
30555 \begin_layout Standard
30556 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30557
30558 \end_inset
30559
30560
30561 \end_layout
30562
30563 \end_inset
30564 </cell>
30565 </row>
30566 <row topline="true">
30567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30568 \begin_inset Text
30569
30570 \begin_layout Standard
30571 srecord
30572 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30573
30574 \end_inset
30575
30576
30577 \end_layout
30578
30579 \end_inset
30580 </cell>
30581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30582 \begin_inset Text
30583
30584 \begin_layout Standard
30585 Object file conversion, checksumming, ...
30586 \end_layout
30587
30588 \end_inset
30589 </cell>
30590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30591 \begin_inset Text
30592
30593 \begin_layout Standard
30594 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30595
30596 \end_inset
30597
30598
30599 \end_layout
30600
30601 \end_inset
30602 </cell>
30603 </row>
30604 <row topline="true">
30605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30606 \begin_inset Text
30607
30608 \begin_layout Standard
30609 objdump
30610 \begin_inset LatexCommand \index{objdump (tool)}
30611
30612 \end_inset
30613
30614
30615 \end_layout
30616
30617 \end_inset
30618 </cell>
30619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30620 \begin_inset Text
30621
30622 \begin_layout Standard
30623 Object file conversion, ...
30624 \end_layout
30625
30626 \end_inset
30627 </cell>
30628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30629 \begin_inset Text
30630
30631 \begin_layout Standard
30632 Part of binutils (should be there anyway)
30633 \end_layout
30634
30635 \end_inset
30636 </cell>
30637 </row>
30638 <row topline="true">
30639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30640 \begin_inset Text
30641
30642 \begin_layout Standard
30643 cmon51
30644 \end_layout
30645
30646 \end_inset
30647 </cell>
30648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30649 \begin_inset Text
30650
30651 \begin_layout Standard
30652 8051 monitor (hex up-/download, single step, disassemble)
30653 \end_layout
30654
30655 \end_inset
30656 </cell>
30657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30658 \begin_inset Text
30659
30660 \begin_layout Standard
30661 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30662
30663 \end_inset
30664
30665
30666 \end_layout
30667
30668 \end_inset
30669 </cell>
30670 </row>
30671 <row topline="true">
30672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30673 \begin_inset Text
30674
30675 \begin_layout Standard
30676 doxygen
30677 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30678
30679 \end_inset
30680
30681
30682 \end_layout
30683
30684 \end_inset
30685 </cell>
30686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30687 \begin_inset Text
30688
30689 \begin_layout Standard
30690 Source code documentation system
30691 \end_layout
30692
30693 \end_inset
30694 </cell>
30695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30696 \begin_inset Text
30697
30698 \begin_layout Standard
30699 \begin_inset LatexCommand \url{http://www.doxygen.org}
30700
30701 \end_inset
30702
30703
30704 \end_layout
30705
30706 \end_inset
30707 </cell>
30708 </row>
30709 <row topline="true">
30710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30711 \begin_inset Text
30712
30713 \begin_layout Standard
30714 kdevelop
30715 \end_layout
30716
30717 \end_inset
30718 </cell>
30719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30720 \begin_inset Text
30721
30722 \begin_layout Standard
30723 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30724 \end_layout
30725
30726 \end_inset
30727 </cell>
30728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30729 \begin_inset Text
30730
30731 \begin_layout Standard
30732 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30733
30734 \end_inset
30735
30736
30737 \end_layout
30738
30739 \end_inset
30740 </cell>
30741 </row>
30742 <row topline="true">
30743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30744 \begin_inset Text
30745
30746 \begin_layout Standard
30747 paulmon
30748 \end_layout
30749
30750 \end_inset
30751 </cell>
30752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30753 \begin_inset Text
30754
30755 \begin_layout Standard
30756 8051 monitor (hex up-/download, single step, disassemble)
30757 \end_layout
30758
30759 \end_inset
30760 </cell>
30761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30762 \begin_inset Text
30763
30764 \begin_layout Standard
30765 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30766
30767 \end_inset
30768
30769
30770 \end_layout
30771
30772 \end_inset
30773 </cell>
30774 </row>
30775 <row topline="true">
30776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30777 \begin_inset Text
30778
30779 \begin_layout Standard
30780 splint
30781 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30782
30783 \end_inset
30784
30785
30786 \end_layout
30787
30788 \end_inset
30789 </cell>
30790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30791 \begin_inset Text
30792
30793 \begin_layout Standard
30794 Statically checks c sources (see 
30795 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30796
30797 \end_inset
30798
30799 )
30800 \end_layout
30801
30802 \end_inset
30803 </cell>
30804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30805 \begin_inset Text
30806
30807 \begin_layout Standard
30808 \begin_inset LatexCommand \url{http://www.splint.org}
30809
30810 \end_inset
30811
30812
30813 \end_layout
30814
30815 \end_inset
30816 </cell>
30817 </row>
30818 <row topline="true" bottomline="true">
30819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30820 \begin_inset Text
30821
30822 \begin_layout Standard
30823 ddd
30824 \begin_inset LatexCommand \index{DDD (debugger)}
30825
30826 \end_inset
30827
30828
30829 \end_layout
30830
30831 \end_inset
30832 </cell>
30833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30834 \begin_inset Text
30835
30836 \begin_layout Standard
30837 Debugger, serves nicely as GUI to SDCDB
30838 \begin_inset LatexCommand \index{SDCDB (debugger)}
30839
30840 \end_inset
30841
30842  (Unix only)
30843 \end_layout
30844
30845 \end_inset
30846 </cell>
30847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30848 \begin_inset Text
30849
30850 \begin_layout Standard
30851 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30852
30853 \end_inset
30854
30855
30856 \end_layout
30857
30858 \end_inset
30859 </cell>
30860 </row>
30861 </lyxtabular>
30862
30863 \end_inset
30864
30865
30866 \newline
30867
30868 \end_layout
30869
30870 \begin_layout Section
30871 Related documentation / recommended reading
30872 \end_layout
30873
30874 \begin_layout Standard
30875 \align left
30876 \begin_inset Tabular
30877 <lyxtabular version="3" rows="7" columns="3">
30878 <features>
30879 <column alignment="left" valignment="top" leftline="true" width="0pt">
30880 <column alignment="left" valignment="top" leftline="true" width="0">
30881 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30882 <row topline="true" bottomline="true">
30883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30884 \begin_inset Text
30885
30886 \begin_layout Standard
30887
30888 \series bold
30889 Name
30890 \end_layout
30891
30892 \end_inset
30893 </cell>
30894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30895 \begin_inset Text
30896
30897 \begin_layout Standard
30898
30899 \series bold
30900 Subject / Title
30901 \end_layout
30902
30903 \end_inset
30904 </cell>
30905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30906 \begin_inset Text
30907
30908 \begin_layout Standard
30909
30910 \series bold
30911 Where to get
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
30923 \family roman
30924 \series medium
30925 \shape up
30926 \size normal
30927 \emph off
30928 \bar no
30929 \noun off
30930 \color none
30931 c-refcard.pdf
30932 \end_layout
30933
30934 \end_inset
30935 </cell>
30936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30937 \begin_inset Text
30938
30939 \begin_layout Standard
30940 C Reference Card
30941 \begin_inset LatexCommand \index{C Reference card}
30942
30943 \end_inset
30944
30945 , 2 pages
30946 \end_layout
30947
30948 \end_inset
30949 </cell>
30950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30951 \begin_inset Text
30952
30953 \begin_layout Standard
30954 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30955
30956 \end_inset
30957
30958
30959 \end_layout
30960
30961 \end_inset
30962 </cell>
30963 </row>
30964 <row topline="true">
30965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30966 \begin_inset Text
30967
30968 \begin_layout Standard
30969 c-faq
30970 \end_layout
30971
30972 \end_inset
30973 </cell>
30974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30975 \begin_inset Text
30976
30977 \begin_layout Standard
30978 C-FAQ
30979 \begin_inset LatexCommand \index{C FAQ}
30980
30981 \end_inset
30982
30983
30984 \end_layout
30985
30986 \end_inset
30987 </cell>
30988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30989 \begin_inset Text
30990
30991 \begin_layout Standard
30992 \begin_inset LatexCommand \url{http://www.c-faq.com}
30993
30994 \end_inset
30995
30996
30997 \end_layout
30998
30999 \end_inset
31000 </cell>
31001 </row>
31002 <row topline="true">
31003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31004 \begin_inset Text
31005
31006 \begin_layout Standard
31007 ISO/IEC 9899:TC2
31008 \end_layout
31009
31010 \end_inset
31011 </cell>
31012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31013 \begin_inset Text
31014
31015 \begin_layout Standard
31016 \begin_inset Quotes sld
31017 \end_inset
31018
31019 C-Standard
31020 \begin_inset Quotes srd
31021 \end_inset
31022
31023
31024 \end_layout
31025
31026 \end_inset
31027 </cell>
31028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31029 \begin_inset Text
31030
31031 \begin_layout Standard
31032
31033 \size footnotesize
31034 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31035
31036 \end_inset
31037
31038
31039 \end_layout
31040
31041 \end_inset
31042 </cell>
31043 </row>
31044 <row topline="true">
31045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31046 \begin_inset Text
31047
31048 \begin_layout Standard
31049 ISO/IEC DTR 18037
31050 \end_layout
31051
31052 \end_inset
31053 </cell>
31054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31055 \begin_inset Text
31056
31057 \begin_layout Standard
31058 \begin_inset Quotes sld
31059 \end_inset
31060
31061 Extensions for Embedded C
31062 \begin_inset Quotes srd
31063 \end_inset
31064
31065
31066 \end_layout
31067
31068 \end_inset
31069 </cell>
31070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31071 \begin_inset Text
31072
31073 \begin_layout Standard
31074
31075 \size footnotesize
31076 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31077
31078 \end_inset
31079
31080
31081 \end_layout
31082
31083 \end_inset
31084 </cell>
31085 </row>
31086 <row topline="true">
31087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31088 \begin_inset Text
31089
31090 \begin_layout Standard
31091
31092 \end_layout
31093
31094 \end_inset
31095 </cell>
31096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31097 \begin_inset Text
31098
31099 \begin_layout Standard
31100 Latest datasheet of target CPU
31101 \end_layout
31102
31103 \end_inset
31104 </cell>
31105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31106 \begin_inset Text
31107
31108 \begin_layout Standard
31109 vendor
31110 \end_layout
31111
31112 \end_inset
31113 </cell>
31114 </row>
31115 <row topline="true" bottomline="true">
31116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31117 \begin_inset Text
31118
31119 \begin_layout Standard
31120
31121 \end_layout
31122
31123 \end_inset
31124 </cell>
31125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31126 \begin_inset Text
31127
31128 \begin_layout Standard
31129 Revision history of datasheet
31130 \end_layout
31131
31132 \end_inset
31133 </cell>
31134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31135 \begin_inset Text
31136
31137 \begin_layout Standard
31138 vendor
31139 \end_layout
31140
31141 \end_inset
31142 </cell>
31143 </row>
31144 </lyxtabular>
31145
31146 \end_inset
31147
31148
31149 \newline
31150
31151 \end_layout
31152
31153 \begin_layout Section
31154 Application notes specifically for SDCC
31155 \end_layout
31156
31157 \begin_layout Standard
31158 SDCC makes no claims about the completeness of this list and about up-to-datenes
31159 s or correctness of the application notes
31160 \begin_inset LatexCommand \index{Application notes}
31161
31162 \end_inset
31163
31164 .
31165 \end_layout
31166
31167 \begin_layout Standard
31168 \align left
31169
31170 \size footnotesize
31171 \begin_inset Tabular
31172 <lyxtabular version="3" rows="7" columns="3">
31173 <features>
31174 <column alignment="block" valignment="top" leftline="true" width="17col%">
31175 <column alignment="block" valignment="top" leftline="true" width="27col%">
31176 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31177 <row topline="true" bottomline="true">
31178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31179 \begin_inset Text
31180
31181 \begin_layout Standard
31182
31183 \series bold
31184 \size footnotesize
31185 Vendor
31186 \end_layout
31187
31188 \end_inset
31189 </cell>
31190 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31191 \begin_inset Text
31192
31193 \begin_layout Standard
31194
31195 \series bold
31196 \size footnotesize
31197 Subject / Title
31198 \end_layout
31199
31200 \end_inset
31201 </cell>
31202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31203 \begin_inset Text
31204
31205 \begin_layout Standard
31206
31207 \series bold
31208 \size footnotesize
31209 Where to get
31210 \end_layout
31211
31212 \end_inset
31213 </cell>
31214 </row>
31215 <row topline="true">
31216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31217 \begin_inset Text
31218
31219 \begin_layout Standard
31220
31221 \size footnotesize
31222 Maxim / Dallas
31223 \end_layout
31224
31225 \end_inset
31226 </cell>
31227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31228 \begin_inset Text
31229
31230 \begin_layout Standard
31231
31232 \size footnotesize
31233 Using the SDCC Compiler for the DS80C400
31234 \begin_inset LatexCommand \index{DS80C400}
31235
31236 \end_inset
31237
31238
31239 \end_layout
31240
31241 \end_inset
31242 </cell>
31243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31244 \begin_inset Text
31245
31246 \begin_layout Standard
31247
31248 \size footnotesize
31249 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31250
31251 \end_inset
31252
31253
31254 \end_layout
31255
31256 \end_inset
31257 </cell>
31258 </row>
31259 <row topline="true">
31260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31261 \begin_inset Text
31262
31263 \begin_layout Standard
31264
31265 \size footnotesize
31266 Maxim / Dallas
31267 \end_layout
31268
31269 \end_inset
31270 </cell>
31271 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31272 \begin_inset Text
31273
31274 \begin_layout Standard
31275
31276 \size footnotesize
31277 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31278 \begin_inset LatexCommand \index{DS89C4x0}
31279
31280 \end_inset
31281
31282  Family of Microcontrollers
31283 \end_layout
31284
31285 \end_inset
31286 </cell>
31287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31288 \begin_inset Text
31289
31290 \begin_layout Standard
31291
31292 \size footnotesize
31293 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31294
31295 \end_inset
31296
31297
31298 \end_layout
31299
31300 \end_inset
31301 </cell>
31302 </row>
31303 <row topline="true">
31304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31305 \begin_inset Text
31306
31307 \begin_layout Standard
31308
31309 \size footnotesize
31310 Silicon Laboratories / Cygnal
31311 \end_layout
31312
31313 \end_inset
31314 </cell>
31315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31316 \begin_inset Text
31317
31318 \begin_layout Standard
31319
31320 \size footnotesize
31321 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31322 \begin_inset LatexCommand \index{IDE}
31323
31324 \end_inset
31325
31326
31327 \end_layout
31328
31329 \end_inset
31330 </cell>
31331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31332 \begin_inset Text
31333
31334 \begin_layout Standard
31335
31336 \size footnotesize
31337 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31338
31339 \end_inset
31340
31341
31342 \end_layout
31343
31344 \end_inset
31345 </cell>
31346 </row>
31347 <row topline="true">
31348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31349 \begin_inset Text
31350
31351 \begin_layout Standard
31352
31353 \size footnotesize
31354 Ramtron / Goal Semiconductor
31355 \end_layout
31356
31357 \end_inset
31358 </cell>
31359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31360 \begin_inset Text
31361
31362 \begin_layout Standard
31363
31364 \size footnotesize
31365 Interfacing SDCC to Syn and Textpad
31366 \end_layout
31367
31368 \end_inset
31369 </cell>
31370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31371 \begin_inset Text
31372
31373 \begin_layout Standard
31374
31375 \size footnotesize
31376 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31377
31378 \end_inset
31379
31380
31381 \end_layout
31382
31383 \end_inset
31384 </cell>
31385 </row>
31386 <row topline="true">
31387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31388 \begin_inset Text
31389
31390 \begin_layout Standard
31391
31392 \size footnotesize
31393 Ramtron / Goal Semiconductor
31394 \end_layout
31395
31396 \end_inset
31397 </cell>
31398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31399 \begin_inset Text
31400
31401 \begin_layout Standard
31402
31403 \size footnotesize
31404 Installing and Configuring SDCC and Crimson Editor 
31405 \end_layout
31406
31407 \end_inset
31408 </cell>
31409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31410 \begin_inset Text
31411
31412 \begin_layout Standard
31413
31414 \size footnotesize
31415 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31416
31417 \end_inset
31418
31419
31420 \end_layout
31421
31422 \end_inset
31423 </cell>
31424 </row>
31425 <row topline="true" bottomline="true">
31426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31427 \begin_inset Text
31428
31429 \begin_layout Standard
31430
31431 \size footnotesize
31432 Texas Instruments
31433 \end_layout
31434
31435 \end_inset
31436 </cell>
31437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31438 \begin_inset Text
31439
31440 \begin_layout Standard
31441
31442 \size footnotesize
31443 MSC12xx Programming with SDCC
31444 \end_layout
31445
31446 \end_inset
31447 </cell>
31448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31449 \begin_inset Text
31450
31451 \begin_layout Standard
31452
31453 \size footnotesize
31454 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31455
31456 \end_inset
31457
31458
31459 \end_layout
31460
31461 \end_inset
31462 </cell>
31463 </row>
31464 </lyxtabular>
31465
31466 \end_inset
31467
31468
31469 \end_layout
31470
31471 \begin_layout Section
31472 Some Questions
31473 \end_layout
31474
31475 \begin_layout Standard
31476 Some questions answered, some pointers given - it might be time to in turn
31477  ask 
31478 \emph on
31479 you
31480 \emph default
31481  some questions: 
31482 \end_layout
31483
31484 \begin_layout Itemize
31485 can you solve your project with the selected microcontroller? Would you
31486  find out early or rather late that your target is too small/slow/whatever?
31487  Can you switch to a slightly better device if it doesn't fit?
31488 \end_layout
31489
31490 \begin_layout Itemize
31491 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31492  and/or another programming language be more adequate? Would an operating
31493  system on the target device help?
31494 \end_layout
31495
31496 \begin_layout Itemize
31497 if you solved the problem, will the marketing department be happy?
31498 \end_layout
31499
31500 \begin_layout Itemize
31501 if the marketing department is happy, will customers be happy?
31502 \end_layout
31503
31504 \begin_layout Itemize
31505 if you're the project manager, marketing department and maybe even the customer
31506  in one person, have you tried to see the project from the outside?
31507 \end_layout
31508
31509 \begin_layout Itemize
31510 is the project done if you think it is done? Or is just that other interface/pro
31511 tocol/feature/configuration/option missing? How about website, manual(s),
31512  internationali(z|s)ation, packaging, labels, 2nd source for components,
31513  electromagnetic compatability/interference, documentation for production,
31514  production test software, update mechanism, patent issues?
31515 \end_layout
31516
31517 \begin_layout Itemize
31518 is your project adequately positioned in that magic triangle: fame, fortune,
31519  fun?
31520 \end_layout
31521
31522 \begin_layout Standard
31523 Maybe not all answers to these questions are known and some answers may
31524  even be 
31525 \emph on
31526 no
31527 \emph default
31528 , nevertheless knowing these questions may help you to avoid burnout
31529 \begin_inset Foot
31530 status open
31531
31532 \begin_layout Standard
31533 burnout is bad for electronic devices, programmers and motorcycle tyres
31534 \end_layout
31535
31536 \end_inset
31537
31538 .
31539  Chances are you didn't want to hear some of them...
31540 \end_layout
31541
31542 \begin_layout Chapter
31543 Support
31544 \begin_inset LatexCommand \index{Support}
31545
31546 \end_inset
31547
31548
31549 \end_layout
31550
31551 \begin_layout Standard
31552 SDCC has grown to be a large project.
31553  The compiler alone (without the preprocessor, assembler and linker) is
31554  well over 150,000 lines of code (blank stripped).
31555  The open source nature of this project is a key to its continued growth
31556  and support.
31557  You gain the benefit and support of many active software developers and
31558  end users.
31559  Is SDCC perfect? No, that's why we need your help.
31560  The developers take pride in fixing reported bugs.
31561  You can help by reporting the bugs and helping other SDCC users.
31562  There are lots of ways to contribute, and we encourage you to take part
31563  in making SDCC a great software package.
31564  
31565 \end_layout
31566
31567 \begin_layout Standard
31568 The SDCC project is hosted on the SDCC sourceforge site at 
31569 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31570
31571 \end_inset
31572
31573 .
31574  You'll find the complete set of mailing lists
31575 \begin_inset LatexCommand \index{Mailing list(s)}
31576
31577 \end_inset
31578
31579 , forums, bug reporting system, patch submission
31580 \begin_inset LatexCommand \index{Patch submission}
31581
31582 \end_inset
31583
31584  system, download
31585 \begin_inset LatexCommand \index{download}
31586
31587 \end_inset
31588
31589  area and Subversion code repository
31590 \begin_inset LatexCommand \index{Subversion code repository}
31591
31592 \end_inset
31593
31594  there.
31595 \end_layout
31596
31597 \begin_layout Section
31598 Reporting Bugs
31599 \begin_inset LatexCommand \index{Bug reporting}
31600
31601 \end_inset
31602
31603
31604 \begin_inset LatexCommand \index{Reporting bugs}
31605
31606 \end_inset
31607
31608
31609 \end_layout
31610
31611 \begin_layout Standard
31612 The recommended way of reporting bugs is using the infrastructure of the
31613  sourceforge site.
31614  You can follow the status of bug reports there and have an overview about
31615  the known bugs.
31616 \end_layout
31617
31618 \begin_layout Standard
31619 Bug reports are automatically forwarded to the developer mailing list and
31620  will be fixed ASAP.
31621  When reporting a bug, it is very useful to include a small test program
31622  (the smaller the better) which reproduces the problem.
31623  If you can isolate the problem by looking at the generated assembly code,
31624  this can be very helpful.
31625  Compiling your program with the -
31626 \begin_inset ERT
31627 status collapsed
31628
31629 \begin_layout Standard
31630
31631
31632 \backslash
31633 /
31634 \end_layout
31635
31636 \end_inset
31637
31638 -dumpall
31639 \begin_inset LatexCommand \index{-\/-dumpall}
31640
31641 \end_inset
31642
31643  option can sometimes be useful in locating optimization problems.
31644  When reporting a bug please make sure you:
31645 \end_layout
31646
31647 \begin_layout Enumerate
31648 Attach the code you are compiling with SDCC.
31649  
31650 \end_layout
31651
31652 \begin_layout Enumerate
31653 Specify the exact command you use to run SDCC, or attach your Makefile.
31654  
31655 \end_layout
31656
31657 \begin_layout Enumerate
31658 Specify the SDCC version (type "
31659 \family sans
31660 \series bold
31661 sdcc -v
31662 \family default
31663 \series default
31664 "), your platform, and operating system.
31665  
31666 \end_layout
31667
31668 \begin_layout Enumerate
31669 Provide an exact copy of any error message or incorrect output.
31670  
31671 \end_layout
31672
31673 \begin_layout Enumerate
31674 Put something meaningful in the subject of your message.
31675 \end_layout
31676
31677 \begin_layout Standard
31678 Please attempt to include these 5 important parts, as applicable, in all
31679  requests for support or when reporting any problems or bugs with SDCC.
31680  Though this will make your message lengthy, it will greatly improve your
31681  chance that SDCC users and developers will be able to help you.
31682  Some SDCC developers are frustrated by bug reports without code provided
31683  that they can use to reproduce and ultimately fix the problem, so please
31684  be sure to provide sample code if you are reporting a bug! 
31685 \end_layout
31686
31687 \begin_layout Standard
31688 Please have a short check that you are using a recent version of SDCC and
31689  the bug is not yet known.
31690  This is the link for reporting bugs: 
31691 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31692
31693 \end_inset
31694
31695 .
31696  With SDCC on average having more than 200 downloads
31697 \begin_inset LatexCommand \index{download}
31698
31699 \end_inset
31700
31701  on sourceforge per day
31702 \begin_inset Foot
31703 status open
31704
31705 \begin_layout Standard
31706 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31707  between 2002 and 2005.
31708  This does not include other methods of distribution.
31709 \end_layout
31710
31711 \end_inset
31712
31713  there must be some users.
31714  So it's not exactly easy to find a new bug.
31715  If you find one we need it: 
31716 \emph on
31717 reporting bugs is good
31718 \emph default
31719 .
31720 \end_layout
31721
31722 \begin_layout Section
31723 Requesting Features
31724 \begin_inset LatexCommand \label{sub:Requesting-Features}
31725
31726 \end_inset
31727
31728
31729 \begin_inset LatexCommand \index{Feature request}
31730
31731 \end_inset
31732
31733
31734 \begin_inset LatexCommand \index{Requesting features}
31735
31736 \end_inset
31737
31738
31739 \end_layout
31740
31741 \begin_layout Standard
31742 Like bug reports feature requests are forwarded to the developer mailing
31743  list.
31744  This is the link for requesting features: 
31745 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31746
31747 \end_inset
31748
31749 .
31750 \end_layout
31751
31752 \begin_layout Section
31753 Submitting patches
31754 \end_layout
31755
31756 \begin_layout Standard
31757 Like bug reports contributed patches are forwarded to the developer mailing
31758  list.
31759  This is the link for submitting patches
31760 \begin_inset LatexCommand \index{Patch submission}
31761
31762 \end_inset
31763
31764
31765 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31766
31767 \end_inset
31768
31769 .
31770 \end_layout
31771
31772 \begin_layout Standard
31773 You need to specify some parameters to the 
31774 \family typewriter
31775 diff
31776 \family default
31777  command for the patches to be useful.
31778  If you modified more than one file a patch created f.e.
31779  with 
31780 \family sans
31781 \series bold
31782
31783 \begin_inset Quotes sld
31784 \end_inset
31785
31786 diff -Naur unmodified_directory modified_directory >my_changes.patch
31787 \begin_inset Quotes srd
31788 \end_inset
31789
31790
31791 \family default
31792 \series default
31793  will be fine, otherwise 
31794 \family sans
31795 \series bold
31796
31797 \begin_inset Quotes sld
31798 \end_inset
31799
31800 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31801 \begin_inset Quotes srd
31802 \end_inset
31803
31804
31805 \series default
31806  
31807 \family default
31808 will do.
31809 \end_layout
31810
31811 \begin_layout Section
31812 Getting Help
31813 \end_layout
31814
31815 \begin_layout Standard
31816 These links should take you directly to the 
31817 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31818
31819 \end_inset
31820
31821
31822 \begin_inset Foot
31823 status open
31824
31825 \begin_layout Standard
31826 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31827  automated messages (mid 2003)
31828 \end_layout
31829
31830 \end_inset
31831
31832  and the 
31833 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31834
31835 \end_inset
31836
31837 , lists
31838 \begin_inset LatexCommand \index{Mailing list(s)}
31839
31840 \end_inset
31841
31842  and forums are archived and searchable so if you are lucky someone already
31843  had a similar problem.
31844  While mails to the lists themselves are delivered promptly their web front
31845  end on sourceforge sometimes shows a severe time lag (up to several weeks),
31846  if you're seriously using SDCC please consider subscribing to the lists.
31847 \end_layout
31848
31849 \begin_layout Section
31850 ChangeLog
31851 \end_layout
31852
31853 \begin_layout Standard
31854 You can follow the status of the Subversion version
31855 \begin_inset LatexCommand \index{version}
31856
31857 \end_inset
31858
31859  of SDCC by watching the Changelog
31860 \begin_inset LatexCommand \index{Changelog}
31861
31862 \end_inset
31863
31864  in the Subversion repository
31865 \size footnotesize
31866  
31867 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31868
31869 \end_inset
31870
31871 .
31872 \end_layout
31873
31874 \begin_layout Section
31875 Subversion Source Code Repository
31876 \end_layout
31877
31878 \begin_layout Standard
31879 The output of 
31880 \family sans
31881 \series bold
31882 sdcc --version
31883 \family default
31884 \series default
31885  or the filenames of the snapshot versions of SDCC include date and its
31886  Subversion
31887 \begin_inset LatexCommand \index{Subversion code repository}
31888
31889 \end_inset
31890
31891  number.
31892  Subversion allows to download the source of recent or previous versions
31893  
31894 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31895
31896 \end_inset
31897
31898  (by number or by date).
31899  An on-line source code browser and detailled instructions are also available
31900  there.
31901  SDCC versions starting from 1999 up to now are available (currently the
31902  versions prior to the conversion from cvs
31903 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31904
31905 \end_inset
31906
31907  to Subversion (April 2006) are either by accessible by Subversion or by
31908  cvs).
31909 \end_layout
31910
31911 \begin_layout Section
31912 Release policy
31913 \begin_inset LatexCommand \index{Release policy}
31914
31915 \end_inset
31916
31917
31918 \end_layout
31919
31920 \begin_layout Standard
31921 Historically there often were long delays between official releases and
31922  the sourceforge download area tends to get not updated at all.
31923  Excuses in the past might have referred to problems with live range analysis,
31924  but as this was fixed a while ago, the current problem is that another
31925  excuse has to be found.
31926  Kidding aside, we have to get better there! On the other hand there are
31927  daily snapshots available at 
31928 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31929
31930 \end_inset
31931
31932 , and you can always build the very last version (hopefully with many bugs
31933  fixed, and features added) from the source code available at 
31934 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31935
31936 \end_inset
31937
31938 .
31939  A release wiki
31940 \begin_inset LatexCommand \index{wiki}
31941
31942 \end_inset
31943
31944
31945 \begin_inset LatexCommand \index{Release wiki}
31946
31947 \end_inset
31948
31949  at 
31950 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31951
31952 \end_inset
31953
31954  also holds some information about past and future releases.
31955 \end_layout
31956
31957 \begin_layout Section
31958 Examples
31959 \begin_inset LatexCommand \index{Examples}
31960
31961 \end_inset
31962
31963
31964 \end_layout
31965
31966 \begin_layout Standard
31967 You'll find some small examples in the directory 
31968 \emph on
31969 sdcc/device/examples/.
31970  
31971 \emph default
31972 More examples and libraries are available at
31973 \emph on
31974  The SDCC Open Knowledge Resource 
31975 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31976
31977 \end_inset
31978
31979  
31980 \emph default
31981 web site or at 
31982 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31983
31984 \end_inset
31985
31986 .
31987 \end_layout
31988
31989 \begin_layout Standard
31990 \begin_inset Note Note
31991 status collapsed
31992
31993 \begin_layout Standard
31994 I did insert a reference to Paul's web site here although it seems rather
31995  dedicated to a specific 8032 board (I think it's okay because it f.e.
31996  shows LCD/Harddisc interface and has a free 8051 monitor.
31997  Independent 8032 board vendors face hard competition of heavily subsidized
31998  development boards anyway).
31999 \end_layout
32000
32001 \begin_layout Standard
32002 Maybe we should include some links to real world applications.
32003  Preferably pointer to pointers (one for each architecture) so this stays
32004  manageable here?
32005 \end_layout
32006
32007 \end_inset
32008
32009
32010 \end_layout
32011
32012 \begin_layout Section
32013 Quality control
32014 \begin_inset LatexCommand \label{sec:Quality-control}
32015
32016 \end_inset
32017
32018
32019 \begin_inset LatexCommand \index{Quality control}
32020
32021 \end_inset
32022
32023
32024 \end_layout
32025
32026 \begin_layout Standard
32027 The compiler is passed through snaphot build compile and build checks.
32028  The so called 
32029 \shape italic
32030 regression tests
32031 \shape default
32032
32033 \begin_inset LatexCommand \index{Regression test}
32034
32035 \end_inset
32036
32037  check that SDCC itself compiles flawlessly on several host platforms (i386,
32038  Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32039  the quality of the code generated by SDCC by running the code for several
32040  target platforms through simulators.
32041  The regression test suite comprises more than 100 files which expand to
32042  more than 500 test cases which include more than 4500 tests.
32043  The results of these tests are published daily on SDCC's snapshot page
32044  (click on the red or green symbols on the right side of 
32045 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32046
32047 \end_inset
32048
32049 ).
32050 \end_layout
32051
32052 \begin_layout Standard
32053 There is a separate document 
32054 \shape italic
32055 test_suite.pdf 
32056 \begin_inset LatexCommand \index{Test suite}
32057
32058 \end_inset
32059
32060
32061 \shape default
32062  
32063 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32064
32065 \end_inset
32066
32067  about the regression test suite.
32068 \end_layout
32069
32070 \begin_layout Standard
32071 You'll find the test code in the directory 
32072 \shape italic
32073 sdcc/support/regression
32074 \shape default
32075 .
32076  You can run these tests manually by running 
32077 \family sans
32078 make
32079 \family default
32080  in this directory (or f.e.
32081  
32082 \family sans
32083 \series bold
32084
32085 \begin_inset Quotes sld
32086 \end_inset
32087
32088 make test-mcs51
32089 \begin_inset Quotes srd
32090 \end_inset
32091
32092
32093 \family default
32094 \series default
32095  if you don't want to run the complete tests).
32096  The test code might also be interesting if you want to look for examples
32097 \begin_inset LatexCommand \index{Examples}
32098
32099 \end_inset
32100
32101  checking corner cases of SDCC or if you plan to submit patches
32102 \begin_inset LatexCommand \index{Patch submission}
32103
32104 \end_inset
32105
32106 .
32107 \end_layout
32108
32109 \begin_layout Standard
32110 The 14bit pic port uses a different set of regression tests 
32111 \begin_inset LatexCommand \index{Regression test (PIC14)}
32112
32113 \end_inset
32114
32115 , you'll find them in the directory 
32116 \shape italic
32117 sdcc/src/regression
32118 \shape default
32119 .
32120 \end_layout
32121
32122 \begin_layout Section
32123 Use of SDCC in Education
32124 \end_layout
32125
32126 \begin_layout Standard
32127 In short: 
32128 \emph on
32129 highly
32130 \emph default
32131  encouraged
32132 \begin_inset Foot
32133 status open
32134
32135 \begin_layout Standard
32136 the phrase "use in education" might evoke the association "
32137 \emph on
32138 only
32139 \emph default
32140  fit for use in education".
32141  This connotation is not intended but nevertheless risked as the licensing
32142  of SDCC makes it difficult to offer educational discounts
32143 \end_layout
32144
32145 \end_inset
32146
32147 .
32148  If your rationales are to:
32149 \end_layout
32150
32151 \begin_layout Enumerate
32152 give students a chance to understand the 
32153 \emph on
32154 complete
32155 \emph default
32156  steps of code generation
32157 \end_layout
32158
32159 \begin_layout Enumerate
32160 have a curriculum that can be extended for years.
32161  Then you could use an fpga board as target and your curriculum will seamlessly
32162  extend from logic synthesis (
32163 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32164
32165 \end_inset
32166
32167
32168 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32169
32170 \end_inset
32171
32172 ), over assembly programming, to C to FPGA compilers (
32173 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32174
32175 \end_inset
32176
32177 ) and to C.
32178 \end_layout
32179
32180 \begin_layout Enumerate
32181 be able to insert excursions about skills like using a revision control
32182  system, submitting/applying patches, using a type-setting (as opposed to
32183  word-processing) engine LyX/LaTeX, using 
32184 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32185
32186 \end_inset
32187
32188 , following some 
32189 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32190
32191 \end_inset
32192
32193 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32194  Source Software, CPU simulation, compiler regression tests
32195 \begin_inset LatexCommand \index{Regression test}
32196
32197 \end_inset
32198
32199 .
32200  
32201 \newline
32202 And if there should be a shortage of ideas then you can always point students
32203  to the ever-growing feature request list 
32204 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32205
32206 \end_inset
32207
32208 .
32209 \end_layout
32210
32211 \begin_layout Enumerate
32212 not tie students to a specific host platform and instead allow them to use
32213  a host platform of 
32214 \emph on
32215 their
32216 \emph default
32217  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32218  and eventually 
32219 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32220
32221 \end_inset
32222
32223 )
32224 \end_layout
32225
32226 \begin_layout Enumerate
32227 not encourage students to use illegal copies of educational software
32228 \end_layout
32229
32230 \begin_layout Enumerate
32231 be immune to licensing/availability/price changes of the chosen tool chain
32232 \end_layout
32233
32234 \begin_layout Enumerate
32235 be able to change to a new target platform without having to adopt a new
32236  tool chain
32237 \end_layout
32238
32239 \begin_layout Enumerate
32240 have complete control over and insight into the tool chain
32241 \end_layout
32242
32243 \begin_layout Enumerate
32244 make your students aware about the pros and cons of open source software
32245  development
32246 \end_layout
32247
32248 \begin_layout Enumerate
32249 give back to the public as you are probably at least partially publically
32250  funded
32251 \end_layout
32252
32253 \begin_layout Enumerate
32254 give students a chance to publically prove their skills and to possibly
32255  see a world wide impact
32256 \end_layout
32257
32258 \begin_layout Standard
32259 then SDCC is probably among the first choices.
32260  Well, probably SDCC might be the only choice.
32261 \newpage
32262
32263 \end_layout
32264
32265 \begin_layout Chapter
32266 SDCC Technical Data
32267 \end_layout
32268
32269 \begin_layout Section
32270 Optimizations
32271 \begin_inset LatexCommand \index{Optimizations}
32272
32273 \end_inset
32274
32275
32276 \end_layout
32277
32278 \begin_layout Standard
32279 SDCC performs a host of standard optimizations in addition to some MCU specific
32280  optimizations.
32281  
32282 \end_layout
32283
32284 \begin_layout Subsection
32285 Sub-expression Elimination
32286 \begin_inset LatexCommand \index{Subexpression elimination}
32287
32288 \end_inset
32289
32290
32291 \end_layout
32292
32293 \begin_layout Standard
32294 The compiler does local and 
32295 \emph on
32296 g
32297 \emph default
32298 lobal 
32299 \emph on
32300 c
32301 \emph default
32302 ommon 
32303 \emph on
32304 s
32305 \emph default
32306 ubexpression 
32307 \emph on
32308 e
32309 \emph default
32310 limination, e.g.: 
32311 \end_layout
32312
32313 \begin_layout Verse
32314
32315 \family typewriter
32316 i = x + y + 1; 
32317 \newline
32318 j = x + y;
32319 \end_layout
32320
32321 \begin_layout Standard
32322 will be translated to
32323 \end_layout
32324
32325 \begin_layout Verse
32326
32327 \family typewriter
32328 iTemp = x + y; 
32329 \newline
32330 i = iTemp + 1; 
32331 \newline
32332 j = iTemp;
32333 \end_layout
32334
32335 \begin_layout Standard
32336 Some subexpressions are not as obvious as the above example, e.g.:
32337 \end_layout
32338
32339 \begin_layout Verse
32340
32341 \family typewriter
32342 a->b[i].c = 10; 
32343 \newline
32344 a->b[i].d = 11;
32345 \end_layout
32346
32347 \begin_layout Standard
32348 In this case the address arithmetic a->b[i] will be computed only once;
32349  the equivalent code in C would be.
32350 \end_layout
32351
32352 \begin_layout Verse
32353
32354 \family typewriter
32355 iTemp = a->b[i]; 
32356 \newline
32357 iTemp.c = 10; 
32358 \newline
32359 iTemp.d = 11;
32360 \end_layout
32361
32362 \begin_layout Standard
32363 The compiler will try to keep these temporary variables in registers.
32364 \end_layout
32365
32366 \begin_layout Subsection
32367 Dead-Code Elimination
32368 \begin_inset LatexCommand \index{Dead-code elimination}
32369
32370 \end_inset
32371
32372
32373 \end_layout
32374
32375 \begin_layout Verse
32376
32377 \family typewriter
32378 int global;
32379 \newline
32380
32381 \newline
32382 void f () { 
32383 \newline
32384 \InsetSpace ~
32385 \InsetSpace ~
32386 int i; 
32387 \newline
32388 \InsetSpace ~
32389 \InsetSpace ~
32390 i = 1; \InsetSpace ~
32391 \InsetSpace ~
32392 \InsetSpace ~
32393 \InsetSpace ~
32394 \InsetSpace ~
32395 /* dead store */ 
32396 \newline
32397 \InsetSpace ~
32398 \InsetSpace ~
32399 global = 1;\InsetSpace ~
32400 /* dead
32401  store */ 
32402 \newline
32403 \InsetSpace ~
32404 \InsetSpace ~
32405 global = 2; 
32406 \newline
32407 \InsetSpace ~
32408 \InsetSpace ~
32409 return; 
32410 \newline
32411 \InsetSpace ~
32412 \InsetSpace ~
32413 global = 3;\InsetSpace ~
32414 /* unreachable */ 
32415 \newline
32416 }
32417 \end_layout
32418
32419 \begin_layout Standard
32420 will be changed to
32421 \end_layout
32422
32423 \begin_layout Verse
32424
32425 \family typewriter
32426 int global;
32427 \newline
32428
32429 \newline
32430 void f () {
32431 \newline
32432 \InsetSpace ~
32433 \InsetSpace ~
32434 global = 2; 
32435 \newline
32436 }
32437 \end_layout
32438
32439 \begin_layout Subsection
32440 Copy-Propagation
32441 \begin_inset LatexCommand \index{Copy propagation}
32442
32443 \end_inset
32444
32445
32446 \end_layout
32447
32448 \begin_layout Verse
32449
32450 \family typewriter
32451 int f() { 
32452 \newline
32453 \InsetSpace ~
32454 \InsetSpace ~
32455 int i, j; 
32456 \newline
32457 \InsetSpace ~
32458 \InsetSpace ~
32459 i = 10; 
32460 \newline
32461 \InsetSpace ~
32462 \InsetSpace ~
32463 j = i; 
32464 \newline
32465 \InsetSpace ~
32466 \InsetSpace ~
32467 return j; 
32468 \newline
32469 }
32470 \end_layout
32471
32472 \begin_layout Standard
32473 will be changed to 
32474 \end_layout
32475
32476 \begin_layout Verse
32477
32478 \family typewriter
32479 int f() { 
32480 \newline
32481 \InsetSpace ~
32482 \InsetSpace ~
32483 int i, j; 
32484 \newline
32485 \InsetSpace ~
32486 \InsetSpace ~
32487 i = 10; 
32488 \newline
32489 \InsetSpace ~
32490 \InsetSpace ~
32491 j = 10; 
32492 \newline
32493 \InsetSpace ~
32494 \InsetSpace ~
32495 return 10; 
32496 \newline
32497 }
32498 \end_layout
32499
32500 \begin_layout Standard
32501 Note: the dead stores created by this copy propagation will be eliminated
32502  by dead-code elimination.
32503 \end_layout
32504
32505 \begin_layout Subsection
32506 Loop Optimizations
32507 \begin_inset LatexCommand \index{Loop optimization}
32508
32509 \end_inset
32510
32511
32512 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32513
32514 \end_inset
32515
32516
32517 \end_layout
32518
32519 \begin_layout Standard
32520 Two types of loop optimizations are done by SDCC 
32521 \emph on
32522 loop invariant
32523 \emph default
32524  lifting and
32525 \emph on
32526  strength reduction
32527 \emph default
32528  of loop induction variables.
32529  In addition to the strength reduction the optimizer marks the induction
32530  variables and the register allocator tries to keep the induction variables
32531  in registers for the duration of the loop.
32532  Because of this preference of the register allocator
32533 \begin_inset LatexCommand \index{Register allocation}
32534
32535 \end_inset
32536
32537 , loop induction optimization causes an increase in register pressure, which
32538  may cause unwanted spilling of other temporary variables into the stack
32539 \begin_inset LatexCommand \index{stack}
32540
32541 \end_inset
32542
32543  / data space.
32544  The compiler will generate a warning message when it is forced to allocate
32545  extra space either on the stack or data space.
32546  If this extra space allocation is undesirable then induction optimization
32547  can be eliminated either for the entire source file (with -
32548 \begin_inset ERT
32549 status collapsed
32550
32551 \begin_layout Standard
32552
32553
32554 \backslash
32555 /
32556 \end_layout
32557
32558 \end_inset
32559
32560 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32561 noinduction
32562 \begin_inset LatexCommand \index{\#pragma noinduction}
32563
32564 \end_inset
32565
32566 .
32567 \newline
32568
32569 \newline
32570 Loop Invariant:
32571 \end_layout
32572
32573 \begin_layout Verse
32574
32575 \family typewriter
32576 for (i = 0 ; i < 100 ; i ++) 
32577 \newline
32578 \InsetSpace ~
32579 \InsetSpace ~
32580 \InsetSpace ~
32581 \InsetSpace ~
32582 f += k + l;
32583 \end_layout
32584
32585 \begin_layout Standard
32586 changed to
32587 \end_layout
32588
32589 \begin_layout Verse
32590
32591 \family typewriter
32592 itemp = k + l; 
32593 \newline
32594 for (i = 0; i < 100; i++) 
32595 \newline
32596 \InsetSpace ~
32597 \InsetSpace ~
32598 \InsetSpace ~
32599 \InsetSpace ~
32600 f += itemp;
32601 \end_layout
32602
32603 \begin_layout Standard
32604 As mentioned previously some loop invariants are not as apparent, all static
32605  address computations are also moved out of the loop.
32606 \newline
32607
32608 \newline
32609 Strength Reduction
32610 \begin_inset LatexCommand \index{Strength reduction}
32611
32612 \end_inset
32613
32614 , this optimization substitutes an expression by a cheaper expression:
32615 \end_layout
32616
32617 \begin_layout Verse
32618
32619 \family typewriter
32620 for (i=0;i < 100; i++)
32621 \newline
32622 \InsetSpace ~
32623 \InsetSpace ~
32624 \InsetSpace ~
32625 \InsetSpace ~
32626 ar[i*5] = i*3;
32627 \end_layout
32628
32629 \begin_layout Standard
32630 changed to
32631 \end_layout
32632
32633 \begin_layout Verse
32634
32635 \family typewriter
32636 itemp1 = 0; 
32637 \newline
32638 itemp2 = 0; 
32639 \newline
32640 for (i=0;i< 100;i++) { 
32641 \newline
32642 \InsetSpace ~
32643 \InsetSpace ~
32644 \InsetSpace ~
32645 \InsetSpace ~
32646 ar[itemp1] = itemp2; 
32647 \newline
32648 \InsetSpace ~
32649 \InsetSpace ~
32650 \InsetSpace ~
32651 \InsetSpace ~
32652 itemp1
32653  += 5; 
32654 \newline
32655 \InsetSpace ~
32656 \InsetSpace ~
32657 \InsetSpace ~
32658 \InsetSpace ~
32659 itemp2 += 3; 
32660 \newline
32661 }
32662 \end_layout
32663
32664 \begin_layout Standard
32665 The more expensive multiplication
32666 \begin_inset LatexCommand \index{Multiplication}
32667
32668 \end_inset
32669
32670  is changed to a less expensive addition.
32671 \end_layout
32672
32673 \begin_layout Subsection
32674 Loop Reversing
32675 \begin_inset LatexCommand \index{Loop reversing}
32676
32677 \end_inset
32678
32679
32680 \end_layout
32681
32682 \begin_layout Standard
32683 This optimization is done to reduce the overhead of checking loop boundaries
32684  for every iteration.
32685  Some simple loops can be reversed and implemented using a 
32686 \begin_inset Quotes eld
32687 \end_inset
32688
32689 decrement and jump if not zero
32690 \begin_inset Quotes erd
32691 \end_inset
32692
32693  instruction.
32694  SDCC checks for the following criterion to determine if a loop is reversible
32695  (note: more sophisticated compilers use data-dependency analysis to make
32696  this determination, SDCC uses a more simple minded analysis).
32697 \end_layout
32698
32699 \begin_layout Itemize
32700 The 'for' loop is of the form 
32701 \newline
32702
32703 \newline
32704
32705 \family typewriter
32706 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32707  += 1])
32708 \newline
32709 \InsetSpace ~
32710 \InsetSpace ~
32711 \InsetSpace ~
32712 \InsetSpace ~
32713 <for body>
32714 \end_layout
32715
32716 \begin_layout Itemize
32717 The <for body> does not contain 
32718 \begin_inset Quotes eld
32719 \end_inset
32720
32721 continue
32722 \begin_inset Quotes erd
32723 \end_inset
32724
32725  or 'break
32726 \begin_inset Quotes erd
32727 \end_inset
32728
32729 .
32730 \end_layout
32731
32732 \begin_layout Itemize
32733 All goto's are contained within the loop.
32734 \end_layout
32735
32736 \begin_layout Itemize
32737 No function calls within the loop.
32738 \end_layout
32739
32740 \begin_layout Itemize
32741 The loop control variable <sym> is not assigned any value within the loop
32742 \end_layout
32743
32744 \begin_layout Itemize
32745 The loop control variable does NOT participate in any arithmetic operation
32746  within the loop.
32747 \end_layout
32748
32749 \begin_layout Itemize
32750 There are NO switch statements in the loop.
32751 \end_layout
32752
32753 \begin_layout Subsection
32754 Algebraic Simplifications
32755 \end_layout
32756
32757 \begin_layout Standard
32758 SDCC does numerous algebraic simplifications, the following is a small sub-set
32759  of these optimizations.
32760 \end_layout
32761
32762 \begin_layout Verse
32763
32764 \family typewriter
32765 i = j + 0;\InsetSpace ~
32766 \InsetSpace ~
32767 \InsetSpace ~
32768 \InsetSpace ~
32769  /* changed to: */\InsetSpace ~
32770 \InsetSpace ~
32771 \InsetSpace ~
32772 \InsetSpace ~
32773  i = j; 
32774 \newline
32775 i /= 2;\InsetSpace ~
32776 \InsetSpace ~
32777 \InsetSpace ~
32778 \InsetSpace ~
32779 \InsetSpace ~
32780 \InsetSpace ~
32781 \InsetSpace ~
32782  /* changed to: */\InsetSpace ~
32783 \InsetSpace ~
32784 \InsetSpace ~
32785 \InsetSpace ~
32786  i >>= 1; 
32787 \newline
32788 i
32789  = j - j;\InsetSpace ~
32790 \InsetSpace ~
32791 \InsetSpace ~
32792 \InsetSpace ~
32793  /* changed to: */\InsetSpace ~
32794 \InsetSpace ~
32795 \InsetSpace ~
32796 \InsetSpace ~
32797  i = 0; 
32798 \newline
32799 i = j / 1;\InsetSpace ~
32800 \InsetSpace ~
32801 \InsetSpace ~
32802 \InsetSpace ~
32803  /* changed to: */\InsetSpace ~
32804 \InsetSpace ~
32805 \InsetSpace ~
32806 \InsetSpace ~
32807  i = j;
32808 \end_layout
32809
32810 \begin_layout Standard
32811 Note the subexpressions
32812 \begin_inset LatexCommand \index{Subexpression}
32813
32814 \end_inset
32815
32816  given above are generally introduced by macro expansions or as a result
32817  of copy/constant propagation.
32818 \end_layout
32819
32820 \begin_layout Subsection
32821 'switch' Statements
32822 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32823
32824 \end_inset
32825
32826
32827 \begin_inset LatexCommand \index{switch statement}
32828
32829 \end_inset
32830
32831
32832 \end_layout
32833
32834 \begin_layout Standard
32835 SDCC can optimize switch statements to jump tables
32836 \begin_inset LatexCommand \index{jump tables}
32837
32838 \end_inset
32839
32840 .
32841  It makes the decision based on an estimate of the generated code size.
32842  SDCC is quite liberal in the requirements for jump table generation: 
32843 \end_layout
32844
32845 \begin_layout Itemize
32846 The labels need not be in order, and the starting number need not be one
32847  or zero, the case labels are in numerical sequence or not too many case
32848  labels are missing.
32849 \end_layout
32850
32851 \begin_deeper
32852 \begin_layout Verse
32853
32854 \family typewriter
32855 switch(i) {\InsetSpace ~
32856 \InsetSpace ~
32857 \InsetSpace ~
32858 \InsetSpace ~
32859 \InsetSpace ~
32860 \InsetSpace ~
32861 \InsetSpace ~
32862 \InsetSpace ~
32863 \InsetSpace ~
32864 \InsetSpace ~
32865 \InsetSpace ~
32866 \InsetSpace ~
32867 \InsetSpace ~
32868 \InsetSpace ~
32869 \InsetSpace ~
32870 \InsetSpace ~
32871 \InsetSpace ~
32872 \InsetSpace ~
32873 \InsetSpace ~
32874 \InsetSpace ~
32875 \InsetSpace ~
32876 \InsetSpace ~
32877 \InsetSpace ~
32878 \InsetSpace ~
32879 \InsetSpace ~
32880 \InsetSpace ~
32881 switch (i) { 
32882 \newline
32883 \InsetSpace ~
32884 \InsetSpace ~
32885 \InsetSpace ~
32886 case 4: ...\InsetSpace ~
32887 \InsetSpace ~
32888 \InsetSpace ~
32889 \InsetSpace ~
32890 \InsetSpace ~
32891 \InsetSpace ~
32892 \InsetSpace ~
32893 \InsetSpace ~
32894 \InsetSpace ~
32895 \InsetSpace ~
32896 \InsetSpace ~
32897 \InsetSpace ~
32898 \InsetSpace ~
32899 \InsetSpace ~
32900 \InsetSpace ~
32901 \InsetSpace ~
32902 \InsetSpace ~
32903 \InsetSpace ~
32904 \InsetSpace ~
32905 \InsetSpace ~
32906 \InsetSpace ~
32907 \InsetSpace ~
32908 \InsetSpace ~
32909 \InsetSpace ~
32910 \InsetSpace ~
32911 \InsetSpace ~
32912 case 0: ...
32913  
32914 \newline
32915 \InsetSpace ~
32916 \InsetSpace ~
32917 \InsetSpace ~
32918 case 5: ...\InsetSpace ~
32919 \InsetSpace ~
32920 \InsetSpace ~
32921 \InsetSpace ~
32922 \InsetSpace ~
32923 \InsetSpace ~
32924 \InsetSpace ~
32925 \InsetSpace ~
32926 \InsetSpace ~
32927 \InsetSpace ~
32928 \InsetSpace ~
32929 \InsetSpace ~
32930 \InsetSpace ~
32931 \InsetSpace ~
32932 \InsetSpace ~
32933 \InsetSpace ~
32934 \InsetSpace ~
32935 \InsetSpace ~
32936 \InsetSpace ~
32937 \InsetSpace ~
32938 \InsetSpace ~
32939 \InsetSpace ~
32940 \InsetSpace ~
32941 \InsetSpace ~
32942 \InsetSpace ~
32943 \InsetSpace ~
32944 case 1: ...
32945  
32946 \newline
32947 \InsetSpace ~
32948 \InsetSpace ~
32949 \InsetSpace ~
32950 case 3: ...\InsetSpace ~
32951 \InsetSpace ~
32952 \InsetSpace ~
32953 \InsetSpace ~
32954 \InsetSpace ~
32955 \InsetSpace ~
32956 \InsetSpace ~
32957 \InsetSpace ~
32958 \InsetSpace ~
32959 \InsetSpace ~
32960 \InsetSpace ~
32961 \InsetSpace ~
32962 \InsetSpace ~
32963 \InsetSpace ~
32964 \InsetSpace ~
32965 \InsetSpace ~
32966 \InsetSpace ~
32967 \InsetSpace ~
32968 \InsetSpace ~
32969 \InsetSpace ~
32970 \InsetSpace ~
32971 \InsetSpace ~
32972 \InsetSpace ~
32973 \InsetSpace ~
32974 \InsetSpace ~
32975 \InsetSpace ~
32976
32977 \newline
32978 \InsetSpace ~
32979 \InsetSpace ~
32980 \InsetSpace ~
32981 case 6: ...\InsetSpace ~
32982 \InsetSpace ~
32983 \InsetSpace ~
32984 \InsetSpace ~
32985 \InsetSpace ~
32986 \InsetSpace ~
32987 \InsetSpace ~
32988 \InsetSpace ~
32989 \InsetSpace ~
32990 \InsetSpace ~
32991 \InsetSpace ~
32992 \InsetSpace ~
32993 \InsetSpace ~
32994 \InsetSpace ~
32995 \InsetSpace ~
32996 \InsetSpace ~
32997 \InsetSpace ~
32998 \InsetSpace ~
32999 \InsetSpace ~
33000 \InsetSpace ~
33001 \InsetSpace ~
33002 \InsetSpace ~
33003 \InsetSpace ~
33004 \InsetSpace ~
33005 \InsetSpace ~
33006 \InsetSpace ~
33007 case 3: ...
33008  
33009 \newline
33010 \InsetSpace ~
33011 \InsetSpace ~
33012 \InsetSpace ~
33013 case 7: ...\InsetSpace ~
33014 \InsetSpace ~
33015 \InsetSpace ~
33016 \InsetSpace ~
33017 \InsetSpace ~
33018 \InsetSpace ~
33019 \InsetSpace ~
33020 \InsetSpace ~
33021 \InsetSpace ~
33022 \InsetSpace ~
33023 \InsetSpace ~
33024 \InsetSpace ~
33025 \InsetSpace ~
33026 \InsetSpace ~
33027 \InsetSpace ~
33028 \InsetSpace ~
33029 \InsetSpace ~
33030 \InsetSpace ~
33031 \InsetSpace ~
33032 \InsetSpace ~
33033 \InsetSpace ~
33034 \InsetSpace ~
33035 \InsetSpace ~
33036 \InsetSpace ~
33037 \InsetSpace ~
33038 \InsetSpace ~
33039 case 4: ...
33040  
33041 \newline
33042 \InsetSpace ~
33043 \InsetSpace ~
33044 \InsetSpace ~
33045 case 8: ...\InsetSpace ~
33046 \InsetSpace ~
33047 \InsetSpace ~
33048 \InsetSpace ~
33049 \InsetSpace ~
33050 \InsetSpace ~
33051 \InsetSpace ~
33052 \InsetSpace ~
33053 \InsetSpace ~
33054 \InsetSpace ~
33055 \InsetSpace ~
33056 \InsetSpace ~
33057 \InsetSpace ~
33058 \InsetSpace ~
33059 \InsetSpace ~
33060 \InsetSpace ~
33061 \InsetSpace ~
33062 \InsetSpace ~
33063 \InsetSpace ~
33064 \InsetSpace ~
33065 \InsetSpace ~
33066 \InsetSpace ~
33067 \InsetSpace ~
33068 \InsetSpace ~
33069 \InsetSpace ~
33070 \InsetSpace ~
33071 case 5: ...
33072  
33073 \newline
33074 \InsetSpace ~
33075 \InsetSpace ~
33076 \InsetSpace ~
33077 case 9: ...\InsetSpace ~
33078 \InsetSpace ~
33079 \InsetSpace ~
33080 \InsetSpace ~
33081 \InsetSpace ~
33082 \InsetSpace ~
33083 \InsetSpace ~
33084 \InsetSpace ~
33085 \InsetSpace ~
33086 \InsetSpace ~
33087 \InsetSpace ~
33088 \InsetSpace ~
33089 \InsetSpace ~
33090 \InsetSpace ~
33091 \InsetSpace ~
33092 \InsetSpace ~
33093 \InsetSpace ~
33094 \InsetSpace ~
33095 \InsetSpace ~
33096 \InsetSpace ~
33097 \InsetSpace ~
33098 \InsetSpace ~
33099 \InsetSpace ~
33100 \InsetSpace ~
33101 \InsetSpace ~
33102 \InsetSpace ~
33103 case 6: ...
33104  
33105 \newline
33106 \InsetSpace ~
33107 \InsetSpace ~
33108 \InsetSpace ~
33109 case 10: ...\InsetSpace ~
33110 \InsetSpace ~
33111 \InsetSpace ~
33112 \InsetSpace ~
33113 \InsetSpace ~
33114 \InsetSpace ~
33115 \InsetSpace ~
33116 \InsetSpace ~
33117 \InsetSpace ~
33118 \InsetSpace ~
33119 \InsetSpace ~
33120 \InsetSpace ~
33121 \InsetSpace ~
33122 \InsetSpace ~
33123 \InsetSpace ~
33124 \InsetSpace ~
33125 \InsetSpace ~
33126 \InsetSpace ~
33127 \InsetSpace ~
33128 \InsetSpace ~
33129 \InsetSpace ~
33130 \InsetSpace ~
33131 \InsetSpace ~
33132 \InsetSpace ~
33133 \InsetSpace ~
33134 case 7: ...
33135  
33136 \newline
33137 \InsetSpace ~
33138 \InsetSpace ~
33139 \InsetSpace ~
33140 case 11: ...\InsetSpace ~
33141 \InsetSpace ~
33142 \InsetSpace ~
33143 \InsetSpace ~
33144 \InsetSpace ~
33145 \InsetSpace ~
33146 \InsetSpace ~
33147 \InsetSpace ~
33148 \InsetSpace ~
33149 \InsetSpace ~
33150 \InsetSpace ~
33151 \InsetSpace ~
33152 \InsetSpace ~
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 \InsetSpace ~
33156 \InsetSpace ~
33157 \InsetSpace ~
33158 \InsetSpace ~
33159 \InsetSpace ~
33160 \InsetSpace ~
33161 \InsetSpace ~
33162 \InsetSpace ~
33163 \InsetSpace ~
33164 \InsetSpace ~
33165 case 8: ...
33166  
33167 \newline
33168 }\InsetSpace ~
33169 \InsetSpace ~
33170 \InsetSpace ~
33171 \InsetSpace ~
33172 \InsetSpace ~
33173 \InsetSpace ~
33174 \InsetSpace ~
33175 \InsetSpace ~
33176 \InsetSpace ~
33177 \InsetSpace ~
33178 \InsetSpace ~
33179 \InsetSpace ~
33180 \InsetSpace ~
33181 \InsetSpace ~
33182 \InsetSpace ~
33183 \InsetSpace ~
33184 \InsetSpace ~
33185 \InsetSpace ~
33186 \InsetSpace ~
33187 \InsetSpace ~
33188 \InsetSpace ~
33189 \InsetSpace ~
33190 \InsetSpace ~
33191 \InsetSpace ~
33192 \InsetSpace ~
33193 \InsetSpace ~
33194 \InsetSpace ~
33195 \InsetSpace ~
33196 \InsetSpace ~
33197 \InsetSpace ~
33198 \InsetSpace ~
33199 \InsetSpace ~
33200 \InsetSpace ~
33201 \InsetSpace ~
33202 \InsetSpace ~
33203 \InsetSpace ~
33204 }
33205 \end_layout
33206
33207 \begin_layout Standard
33208 Both the above switch statements will be implemented using a jump-table.
33209  The example to the right side is slightly more efficient as the check for
33210  the lower boundary of the jump-table is not needed.
33211 \end_layout
33212
33213 \end_deeper
33214 \begin_layout Itemize
33215 The number of case labels is not larger than supported by the target architectur
33216 e.
33217 \end_layout
33218
33219 \begin_layout Itemize
33220 If the case labels are not in numerical sequence ('gaps' between cases)
33221  SDCC checks whether a jump table with additionally inserted dummy cases
33222  is still attractive.
33223  
33224 \end_layout
33225
33226 \begin_layout Itemize
33227 If the starting number is not zero and a check for the lower boundary of
33228  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33229  ...
33230  .
33231 \end_layout
33232
33233 \begin_layout Standard
33234 Switch statements which have large gaps in the numeric sequence or those
33235  that have too many case labels can be split into more than one switch statement
33236  for efficient code generation, e.g.:
33237 \end_layout
33238
33239 \begin_layout Verse
33240
33241 \family typewriter
33242 switch (i) { 
33243 \newline
33244 \InsetSpace ~
33245 \InsetSpace ~
33246 case 1: ...
33247  
33248 \newline
33249 \InsetSpace ~
33250 \InsetSpace ~
33251 case 2: ...
33252  
33253 \newline
33254 \InsetSpace ~
33255 \InsetSpace ~
33256 case 3: ...
33257  
33258 \newline
33259 \InsetSpace ~
33260 \InsetSpace ~
33261 case 4: ...
33262  
33263 \newline
33264 \InsetSpace ~
33265 \InsetSpace ~
33266 case 5: ...
33267  
33268 \newline
33269 \InsetSpace ~
33270 \InsetSpace ~
33271 case 6: ...
33272  
33273 \newline
33274 \InsetSpace ~
33275 \InsetSpace ~
33276 case 7: ...
33277  
33278 \newline
33279 \InsetSpace ~
33280 \InsetSpace ~
33281 case 101: ...
33282  
33283 \newline
33284 \InsetSpace ~
33285 \InsetSpace ~
33286 case 102: ...
33287  
33288 \newline
33289 \InsetSpace ~
33290 \InsetSpace ~
33291 case 103: ...
33292  
33293 \newline
33294 \InsetSpace ~
33295 \InsetSpace ~
33296 case 104: ...
33297  
33298 \newline
33299 \InsetSpace ~
33300 \InsetSpace ~
33301 case 105: ...
33302  
33303 \newline
33304 \InsetSpace ~
33305 \InsetSpace ~
33306 case 106: ...
33307  
33308 \newline
33309 \InsetSpace ~
33310 \InsetSpace ~
33311 case 107: ...
33312  
33313 \newline
33314 }
33315 \end_layout
33316
33317 \begin_layout Standard
33318 If the above switch statement is broken down into two switch statements
33319 \end_layout
33320
33321 \begin_layout Verse
33322
33323 \family typewriter
33324 switch (i) { 
33325 \newline
33326 \InsetSpace ~
33327 \InsetSpace ~
33328 case 1: ...
33329  
33330 \newline
33331 \InsetSpace ~
33332 \InsetSpace ~
33333 case 2: ...
33334  
33335 \newline
33336 \InsetSpace ~
33337 \InsetSpace ~
33338 case 3: ...
33339  
33340 \newline
33341 \InsetSpace ~
33342 \InsetSpace ~
33343 case 4: ...
33344  
33345 \newline
33346 \InsetSpace ~
33347 \InsetSpace ~
33348 case 5: ...
33349  
33350 \newline
33351 \InsetSpace ~
33352 \InsetSpace ~
33353 case 6: ...
33354  
33355 \newline
33356 \InsetSpace ~
33357 \InsetSpace ~
33358 case 7: ...
33359  
33360 \newline
33361 }
33362 \end_layout
33363
33364 \begin_layout Standard
33365 and
33366 \end_layout
33367
33368 \begin_layout Verse
33369
33370 \family typewriter
33371 switch (i) { 
33372 \newline
33373 \InsetSpace ~
33374 \InsetSpace ~
33375 case 101: ...
33376  
33377 \newline
33378 \InsetSpace ~
33379 \InsetSpace ~
33380 case 102: ...
33381  
33382 \newline
33383 \InsetSpace ~
33384 \InsetSpace ~
33385 case 103: ...
33386  
33387 \newline
33388 \InsetSpace ~
33389 \InsetSpace ~
33390 case 104: ...
33391  
33392 \newline
33393 \InsetSpace ~
33394 \InsetSpace ~
33395 case 105: ...
33396  
33397 \newline
33398 \InsetSpace ~
33399 \InsetSpace ~
33400 case 106: ...
33401  
33402 \newline
33403 \InsetSpace ~
33404 \InsetSpace ~
33405 case 107: ...
33406  
33407 \newline
33408 }
33409 \end_layout
33410
33411 \begin_layout Standard
33412 then both the switch statements will be implemented using jump-tables whereas
33413  the unmodified switch statement will not be.
33414 \end_layout
33415
33416 \begin_layout Standard
33417 \begin_inset Note Note
33418 status collapsed
33419
33420 \begin_layout Standard
33421 There might be reasons which SDCC cannot know about to either favour or
33422  not favour jump tables.
33423  If the target system has to be as quick for the last switch case as for
33424  the first (pro jump table), or if the switch argument is known to be zero
33425  in the majority of the cases (contra jump table).
33426 \end_layout
33427
33428 \end_inset
33429
33430
33431 \end_layout
33432
33433 \begin_layout Standard
33434 The pragma nojtbound
33435 \begin_inset LatexCommand \index{\#pragma nojtbound}
33436
33437 \end_inset
33438
33439  can be used to turn off checking the 
33440 \emph on
33441 j
33442 \emph default
33443 ump 
33444 \emph on
33445 t
33446 \emph default
33447 able 
33448 \emph on
33449 bound
33450 \emph default
33451 aries.
33452  It has no effect if a default label is supplied.
33453  Use of this pragma is dangerous: if the switch
33454 \begin_inset LatexCommand \index{switch statement}
33455
33456 \end_inset
33457
33458  argument is not matched by a case statement the processor will happily
33459  jump into Nirvana.
33460 \end_layout
33461
33462 \begin_layout Subsection
33463 Bit-shifting Operations
33464 \begin_inset LatexCommand \index{Bit shifting}
33465
33466 \end_inset
33467
33468 .
33469 \end_layout
33470
33471 \begin_layout Standard
33472 Bit shifting is one of the most frequently used operation in embedded programmin
33473 g.
33474  SDCC tries to implement bit-shift operations in the most efficient way
33475  possible, e.g.:
33476 \end_layout
33477
33478 \begin_layout Verse
33479
33480 \family typewriter
33481 unsigned char i;
33482 \newline
33483 ...
33484  
33485 \newline
33486 i >>= 4; 
33487 \newline
33488 ...
33489 \end_layout
33490
33491 \begin_layout Standard
33492 generates the following code:
33493 \end_layout
33494
33495 \begin_layout Verse
33496
33497 \family typewriter
33498 mov\InsetSpace ~
33499  a,_i 
33500 \newline
33501 swap a 
33502 \newline
33503 anl\InsetSpace ~
33504  a,#0x0f 
33505 \newline
33506 mov\InsetSpace ~
33507  _i,a
33508 \end_layout
33509
33510 \begin_layout Standard
33511 In general SDCC will never setup a loop if the shift count is known.
33512  Another example:
33513 \end_layout
33514
33515 \begin_layout Verse
33516
33517 \family typewriter
33518 unsigned int i; 
33519 \newline
33520 ...
33521  
33522 \newline
33523 i >>= 9; 
33524 \newline
33525 ...
33526 \end_layout
33527
33528 \begin_layout Standard
33529 will generate:
33530 \end_layout
33531
33532 \begin_layout Verse
33533
33534 \family typewriter
33535 mov\InsetSpace ~
33536 \InsetSpace ~
33537 a,(_i + 1) 
33538 \newline
33539 mov\InsetSpace ~
33540 \InsetSpace ~
33541 (_i + 1),#0x00 
33542 \newline
33543 clr\InsetSpace ~
33544 \InsetSpace ~
33545
33546 \newline
33547 rrc\InsetSpace ~
33548 \InsetSpace ~
33549
33550 \newline
33551 mov\InsetSpace ~
33552 \InsetSpace ~
33553 _i,a
33554 \end_layout
33555
33556 \begin_layout Subsection
33557 Bit-rotation
33558 \begin_inset LatexCommand \index{Bit rotation}
33559
33560 \end_inset
33561
33562
33563 \end_layout
33564
33565 \begin_layout Standard
33566 A special case of the bit-shift operation is bit rotation
33567 \begin_inset LatexCommand \index{rotating bits}
33568
33569 \end_inset
33570
33571 , SDCC recognizes the following expression to be a left bit-rotation:
33572 \end_layout
33573
33574 \begin_layout Verse
33575
33576 \family typewriter
33577 \series bold
33578 unsigned
33579 \series default
33580 \InsetSpace ~
33581 \InsetSpace ~
33582 char i;\InsetSpace ~
33583 \InsetSpace ~
33584 \InsetSpace ~
33585 \InsetSpace ~
33586 \InsetSpace ~
33587 \InsetSpace ~
33588 \InsetSpace ~
33589 \InsetSpace ~
33590 \InsetSpace ~
33591 \InsetSpace ~
33592 \InsetSpace ~
33593 /* unsigned is needed for rotation */ 
33594 \newline
33595 ...
33596  
33597 \newline
33598 i = ((i << 1) | (i >> 7)); 
33599 \family default
33600
33601 \newline
33602
33603 \family typewriter
33604 ...
33605 \end_layout
33606
33607 \begin_layout Standard
33608 will generate the following code:
33609 \end_layout
33610
33611 \begin_layout Verse
33612
33613 \family typewriter
33614 mov\InsetSpace ~
33615 \InsetSpace ~
33616 a,_i 
33617 \newline
33618 rl\InsetSpace ~
33619 \InsetSpace ~
33620 \InsetSpace ~
33621
33622 \newline
33623 mov\InsetSpace ~
33624 \InsetSpace ~
33625 _i,a
33626 \end_layout
33627
33628 \begin_layout Standard
33629 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33630 ns of this case will also be recognized as bit-rotation, i.e.: 
33631 \end_layout
33632
33633 \begin_layout Verse
33634
33635 \family typewriter
33636 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33637 \end_layout
33638
33639 \begin_layout Subsection
33640 Nibble and Byte Swapping
33641 \end_layout
33642
33643 \begin_layout Standard
33644 Other special cases of the bit-shift operations are nibble or byte swapping
33645 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33646
33647 \end_inset
33648
33649 , SDCC recognizes the following expressions:
33650 \end_layout
33651
33652 \begin_layout Verse
33653
33654 \family typewriter
33655 \series bold
33656 unsigned
33657 \series default
33658 \InsetSpace ~
33659 \InsetSpace ~
33660 char i; 
33661 \newline
33662
33663 \series bold
33664 unsigned
33665 \series default
33666 \InsetSpace ~
33667 \InsetSpace ~
33668 int j; 
33669 \newline
33670 ...
33671  
33672 \newline
33673 i = ((i << 4) | (i >> 4)); 
33674 \family default
33675
33676 \newline
33677
33678 \family typewriter
33679 j = ((j << 8) | (j >> 8)); 
33680 \end_layout
33681
33682 \begin_layout Standard
33683 and generates a swap instruction for the nibble swapping
33684 \begin_inset LatexCommand \index{Nibble swapping}
33685
33686 \end_inset
33687
33688  or move instructions for the byte swapping
33689 \begin_inset LatexCommand \index{Byte swapping}
33690
33691 \end_inset
33692
33693 .
33694  The 
33695 \begin_inset Quotes sld
33696 \end_inset
33697
33698 j
33699 \begin_inset Quotes srd
33700 \end_inset
33701
33702  example can be used to convert from little to big-endian or vice versa.
33703  If you want to change the endianness of a 
33704 \emph on
33705 signed
33706 \emph default
33707  integer you have to cast to 
33708 \family typewriter
33709 (unsigned int)
33710 \family default
33711  first.
33712 \end_layout
33713
33714 \begin_layout Standard
33715 Note that SDCC stores numbers in little-endian
33716 \begin_inset Foot
33717 status open
33718
33719 \begin_layout Standard
33720 Usually 8-bit processors don't care much about endianness.
33721  This is not the case for the standard 8051 which only has an instruction
33722  to increment its 
33723 \emph on
33724 dptr
33725 \emph default
33726
33727 \begin_inset LatexCommand \index{DPTR}
33728
33729 \end_inset
33730
33731 -datapointer
33732 \emph on
33733  
33734 \emph default
33735 so little-endian is the more efficient byte order.
33736 \end_layout
33737
33738 \end_inset
33739
33740
33741 \begin_inset LatexCommand \index{little-endian}
33742
33743 \end_inset
33744
33745
33746 \begin_inset LatexCommand \index{Endianness}
33747
33748 \end_inset
33749
33750  format (i.e.
33751  lowest order first).
33752 \end_layout
33753
33754 \begin_layout Subsection
33755 Highest Order Bit
33756 \begin_inset LatexCommand \index{Highest Order Bit}
33757
33758 \end_inset
33759
33760  / Any Order Bit
33761 \begin_inset LatexCommand \index{Any Order Bit}
33762
33763 \end_inset
33764
33765
33766 \end_layout
33767
33768 \begin_layout Standard
33769 It is frequently required to obtain the highest order bit of an integral
33770  type (long, int, short or char types).
33771  Also obtaining any other order bit is not uncommon.
33772  SDCC recognizes the following expressions to yield the highest order bit
33773  and generates optimized code for it, e.g.:
33774 \end_layout
33775
33776 \begin_layout Verse
33777
33778 \family typewriter
33779 unsigned int gint; 
33780 \newline
33781
33782 \newline
33783 foo () { 
33784 \newline
33785 \InsetSpace ~
33786 \InsetSpace ~
33787 unsigned char hob1, aob1; 
33788 \newline
33789 \InsetSpace ~
33790 \InsetSpace ~
33791 bit hob2, hob3, aob2,
33792  aob3; 
33793 \newline
33794 \InsetSpace ~
33795 \InsetSpace ~
33796 ...
33797  
33798 \newline
33799 \InsetSpace ~
33800 \InsetSpace ~
33801 hob1 = (gint >> 15) & 1; 
33802 \newline
33803 \InsetSpace ~
33804 \InsetSpace ~
33805 hob2 = (gint >> 15) & 1; 
33806 \newline
33807 \InsetSpace ~
33808 \InsetSpace ~
33809 hob3 = gint & 0x8000;
33810  
33811 \newline
33812 \InsetSpace ~
33813 \InsetSpace ~
33814 aob1 = (gint >> 9) & 1; 
33815 \newline
33816 \InsetSpace ~
33817 \InsetSpace ~
33818 aob2 = (gint >> 8) & 1; 
33819 \newline
33820 \InsetSpace ~
33821 \InsetSpace ~
33822 aob3 = gint & 0x0800; 
33823 \newline
33824 \InsetSpace ~
33825 \InsetSpace ~
33826 ..
33827  
33828 \newline
33829 }
33830 \end_layout
33831
33832 \begin_layout Standard
33833 will generate the following code:
33834 \end_layout
33835
33836 \begin_layout Verse
33837
33838 \family typewriter
33839 \InsetSpace ~
33840 \InsetSpace ~
33841 \InsetSpace ~
33842 \InsetSpace ~
33843 \InsetSpace ~
33844 \InsetSpace ~
33845 \InsetSpace ~
33846 \InsetSpace ~
33847 \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  61 ;\InsetSpace ~
33865  hob.c 7 
33866 \newline
33867 000A E5*01\InsetSpace ~
33868 \InsetSpace ~
33869 \InsetSpace ~
33870 \InsetSpace ~
33871 \InsetSpace ~
33872 \InsetSpace ~
33873 \InsetSpace ~
33874 \InsetSpace ~
33875 \InsetSpace ~
33876 \InsetSpace ~
33877 \InsetSpace ~
33878 \InsetSpace ~
33879 \InsetSpace ~
33880 \InsetSpace ~
33881 \InsetSpace ~
33882  62\InsetSpace ~
33883 \InsetSpace ~
33884 \InsetSpace ~
33885 \InsetSpace ~
33886 \InsetSpace ~
33887 \InsetSpace ~
33888 \InsetSpace ~
33889 \InsetSpace ~
33890  mov\InsetSpace ~
33891 \InsetSpace ~
33892  a,(_gint + 1) 
33893 \newline
33894 000C 23\InsetSpace ~
33895 \InsetSpace ~
33896 \InsetSpace ~
33897 \InsetSpace ~
33898 \InsetSpace ~
33899 \InsetSpace ~
33900 \InsetSpace ~
33901 \InsetSpace ~
33902 \InsetSpace ~
33903 \InsetSpace ~
33904 \InsetSpace ~
33905 \InsetSpace ~
33906 \InsetSpace ~
33907 \InsetSpace ~
33908 \InsetSpace ~
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 \InsetSpace ~
33912  63\InsetSpace ~
33913 \InsetSpace ~
33914 \InsetSpace ~
33915 \InsetSpace ~
33916 \InsetSpace ~
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 \InsetSpace ~
33920  rl\InsetSpace ~
33921 \InsetSpace ~
33922 \InsetSpace ~
33923  a 
33924 \newline
33925 000D 54 01\InsetSpace ~
33926 \InsetSpace ~
33927 \InsetSpace ~
33928 \InsetSpace ~
33929 \InsetSpace ~
33930 \InsetSpace ~
33931 \InsetSpace ~
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 \InsetSpace ~
33935 \InsetSpace ~
33936 \InsetSpace ~
33937 \InsetSpace ~
33938 \InsetSpace ~
33939 \InsetSpace ~
33940
33941  64\InsetSpace ~
33942 \InsetSpace ~
33943 \InsetSpace ~
33944 \InsetSpace ~
33945 \InsetSpace ~
33946 \InsetSpace ~
33947 \InsetSpace ~
33948 \InsetSpace ~
33949  anl\InsetSpace ~
33950 \InsetSpace ~
33951  a,#0x01 
33952 \newline
33953 000F F5*02\InsetSpace ~
33954 \InsetSpace ~
33955 \InsetSpace ~
33956 \InsetSpace ~
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 \InsetSpace ~
33960 \InsetSpace ~
33961 \InsetSpace ~
33962 \InsetSpace ~
33963 \InsetSpace ~
33964 \InsetSpace ~
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 \InsetSpace ~
33968  65\InsetSpace ~
33969 \InsetSpace ~
33970 \InsetSpace ~
33971 \InsetSpace ~
33972 \InsetSpace ~
33973 \InsetSpace ~
33974 \InsetSpace ~
33975 \InsetSpace ~
33976  mov\InsetSpace ~
33977 \InsetSpace ~
33978  _foo_hob1_1_1,a 
33979 \newline
33980 \InsetSpace ~
33981 \InsetSpace ~
33982 \InsetSpace ~
33983 \InsetSpace ~
33984 \InsetSpace ~
33985 \InsetSpace ~
33986 \InsetSpace ~
33987 \InsetSpace ~
33988 \InsetSpace ~
33989 \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  66 ;\InsetSpace ~
34006  hob.c 8 
34007 \newline
34008 0011 E5*01\InsetSpace ~
34009 \InsetSpace ~
34010 \InsetSpace ~
34011 \InsetSpace ~
34012 \InsetSpace ~
34013 \InsetSpace ~
34014 \InsetSpace ~
34015 \InsetSpace ~
34016 \InsetSpace ~
34017 \InsetSpace ~
34018 \InsetSpace ~
34019 \InsetSpace ~
34020 \InsetSpace ~
34021 \InsetSpace ~
34022 \InsetSpace ~
34023
34024  67\InsetSpace ~
34025 \InsetSpace ~
34026 \InsetSpace ~
34027 \InsetSpace ~
34028 \InsetSpace ~
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 \InsetSpace ~
34032  mov\InsetSpace ~
34033 \InsetSpace ~
34034  a,(_gint + 1) 
34035 \newline
34036 0013 33\InsetSpace ~
34037 \InsetSpace ~
34038 \InsetSpace ~
34039 \InsetSpace ~
34040 \InsetSpace ~
34041 \InsetSpace ~
34042 \InsetSpace ~
34043 \InsetSpace ~
34044 \InsetSpace ~
34045 \InsetSpace ~
34046 \InsetSpace ~
34047 \InsetSpace ~
34048 \InsetSpace ~
34049 \InsetSpace ~
34050 \InsetSpace ~
34051 \InsetSpace ~
34052 \InsetSpace ~
34053 \InsetSpace ~
34054  68\InsetSpace ~
34055 \InsetSpace ~
34056 \InsetSpace ~
34057 \InsetSpace ~
34058 \InsetSpace ~
34059 \InsetSpace ~
34060 \InsetSpace ~
34061 \InsetSpace ~
34062  rlc\InsetSpace ~
34063 \InsetSpace ~
34064  a 
34065 \newline
34066 0014 92*00\InsetSpace ~
34067 \InsetSpace ~
34068 \InsetSpace ~
34069 \InsetSpace ~
34070 \InsetSpace ~
34071 \InsetSpace ~
34072 \InsetSpace ~
34073 \InsetSpace ~
34074 \InsetSpace ~
34075 \InsetSpace ~
34076 \InsetSpace ~
34077 \InsetSpace ~
34078 \InsetSpace ~
34079 \InsetSpace ~
34080 \InsetSpace ~
34081  69\InsetSpace ~
34082 \InsetSpace ~
34083 \InsetSpace ~
34084 \InsetSpace ~
34085 \InsetSpace ~
34086 \InsetSpace ~
34087 \InsetSpace ~
34088 \InsetSpace ~
34089  mov\InsetSpace ~
34090 \InsetSpace ~
34091  _foo_hob2_1_1,c
34092  
34093 \newline
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 \InsetSpace ~
34099 \InsetSpace ~
34100 \InsetSpace ~
34101 \InsetSpace ~
34102 \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  66 ;\InsetSpace ~
34120  hob.c 9 
34121 \newline
34122 0016 E5*01\InsetSpace ~
34123 \InsetSpace ~
34124 \InsetSpace ~
34125 \InsetSpace ~
34126 \InsetSpace ~
34127 \InsetSpace ~
34128 \InsetSpace ~
34129 \InsetSpace ~
34130 \InsetSpace ~
34131 \InsetSpace ~
34132 \InsetSpace ~
34133 \InsetSpace ~
34134 \InsetSpace ~
34135 \InsetSpace ~
34136 \InsetSpace ~
34137  67\InsetSpace ~
34138 \InsetSpace ~
34139 \InsetSpace ~
34140 \InsetSpace ~
34141 \InsetSpace ~
34142 \InsetSpace ~
34143 \InsetSpace ~
34144 \InsetSpace ~
34145  mov\InsetSpace ~
34146 \InsetSpace ~
34147  a,(_gint + 1) 
34148 \newline
34149 0018 33\InsetSpace ~
34150 \InsetSpace ~
34151 \InsetSpace ~
34152 \InsetSpace ~
34153 \InsetSpace ~
34154 \InsetSpace ~
34155 \InsetSpace ~
34156 \InsetSpace ~
34157 \InsetSpace ~
34158 \InsetSpace ~
34159 \InsetSpace ~
34160 \InsetSpace ~
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 \InsetSpace ~
34166 \InsetSpace ~
34167  68\InsetSpace ~
34168 \InsetSpace ~
34169 \InsetSpace ~
34170 \InsetSpace ~
34171 \InsetSpace ~
34172 \InsetSpace ~
34173 \InsetSpace ~
34174 \InsetSpace ~
34175  rlc\InsetSpace ~
34176 \InsetSpace ~
34177  a 
34178 \newline
34179 0019 92*01\InsetSpace ~
34180 \InsetSpace ~
34181 \InsetSpace ~
34182 \InsetSpace ~
34183 \InsetSpace ~
34184 \InsetSpace ~
34185 \InsetSpace ~
34186 \InsetSpace ~
34187 \InsetSpace ~
34188 \InsetSpace ~
34189 \InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194
34195  69\InsetSpace ~
34196 \InsetSpace ~
34197 \InsetSpace ~
34198 \InsetSpace ~
34199 \InsetSpace ~
34200 \InsetSpace ~
34201 \InsetSpace ~
34202 \InsetSpace ~
34203  mov\InsetSpace ~
34204 \InsetSpace ~
34205  _foo_hob3_1_1,c 
34206 \newline
34207 \InsetSpace ~
34208 \InsetSpace ~
34209 \InsetSpace ~
34210 \InsetSpace ~
34211 \InsetSpace ~
34212 \InsetSpace ~
34213 \InsetSpace ~
34214 \InsetSpace ~
34215 \InsetSpace ~
34216 \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  70 ;\InsetSpace ~
34233  hob.c 10 
34234 \newline
34235 001B E5*01\InsetSpace ~
34236 \InsetSpace ~
34237 \InsetSpace ~
34238 \InsetSpace ~
34239 \InsetSpace ~
34240 \InsetSpace ~
34241 \InsetSpace ~
34242 \InsetSpace ~
34243 \InsetSpace ~
34244 \InsetSpace ~
34245 \InsetSpace ~
34246 \InsetSpace ~
34247 \InsetSpace ~
34248 \InsetSpace ~
34249 \InsetSpace ~
34250  71\InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258  mov\InsetSpace ~
34259 \InsetSpace ~
34260  a,(_gint + 1) 
34261 \newline
34262 001D
34263  03\InsetSpace ~
34264 \InsetSpace ~
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 \InsetSpace ~
34268 \InsetSpace ~
34269 \InsetSpace ~
34270 \InsetSpace ~
34271 \InsetSpace ~
34272 \InsetSpace ~
34273 \InsetSpace ~
34274 \InsetSpace ~
34275 \InsetSpace ~
34276 \InsetSpace ~
34277 \InsetSpace ~
34278 \InsetSpace ~
34279 \InsetSpace ~
34280 \InsetSpace ~
34281  72\InsetSpace ~
34282 \InsetSpace ~
34283 \InsetSpace ~
34284 \InsetSpace ~
34285 \InsetSpace ~
34286 \InsetSpace ~
34287 \InsetSpace ~
34288 \InsetSpace ~
34289  rr\InsetSpace ~
34290 \InsetSpace ~
34291 \InsetSpace ~
34292  a 
34293 \newline
34294 001E 54 01\InsetSpace ~
34295 \InsetSpace ~
34296 \InsetSpace ~
34297 \InsetSpace ~
34298 \InsetSpace ~
34299 \InsetSpace ~
34300 \InsetSpace ~
34301 \InsetSpace ~
34302 \InsetSpace ~
34303 \InsetSpace ~
34304 \InsetSpace ~
34305 \InsetSpace ~
34306 \InsetSpace ~
34307 \InsetSpace ~
34308 \InsetSpace ~
34309  73\InsetSpace ~
34310 \InsetSpace ~
34311 \InsetSpace ~
34312 \InsetSpace ~
34313 \InsetSpace ~
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 \InsetSpace ~
34317  anl\InsetSpace ~
34318 \InsetSpace ~
34319  a,#0x01 
34320 \newline
34321 0020 F5*03\InsetSpace ~
34322 \InsetSpace ~
34323 \InsetSpace ~
34324 \InsetSpace ~
34325 \InsetSpace ~
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 \InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336  74\InsetSpace ~
34337 \InsetSpace ~
34338 \InsetSpace ~
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344  mov\InsetSpace ~
34345 \InsetSpace ~
34346  _foo_aob1_1_1,a
34347  
34348 \newline
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355 \InsetSpace ~
34356 \InsetSpace ~
34357 \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  75 ;\InsetSpace ~
34375  hob.c 11 
34376 \newline
34377 0022 E5*01\InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381 \InsetSpace ~
34382 \InsetSpace ~
34383 \InsetSpace ~
34384 \InsetSpace ~
34385 \InsetSpace ~
34386 \InsetSpace ~
34387 \InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392  76\InsetSpace ~
34393 \InsetSpace ~
34394 \InsetSpace ~
34395 \InsetSpace ~
34396 \InsetSpace ~
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400  mov\InsetSpace ~
34401 \InsetSpace ~
34402  a,(_gint + 1) 
34403 \newline
34404 0024 13\InsetSpace ~
34405 \InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411 \InsetSpace ~
34412 \InsetSpace ~
34413 \InsetSpace ~
34414 \InsetSpace ~
34415 \InsetSpace ~
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421 \InsetSpace ~
34422  77\InsetSpace ~
34423 \InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426 \InsetSpace ~
34427 \InsetSpace ~
34428 \InsetSpace ~
34429 \InsetSpace ~
34430  rrc\InsetSpace ~
34431 \InsetSpace ~
34432  a 
34433 \newline
34434 0025 92*02\InsetSpace ~
34435 \InsetSpace ~
34436 \InsetSpace ~
34437 \InsetSpace ~
34438 \InsetSpace ~
34439 \InsetSpace ~
34440 \InsetSpace ~
34441 \InsetSpace ~
34442 \InsetSpace ~
34443 \InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449
34450  78\InsetSpace ~
34451 \InsetSpace ~
34452 \InsetSpace ~
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457 \InsetSpace ~
34458  mov\InsetSpace ~
34459 \InsetSpace ~
34460  _foo_aob2_1_1,c 
34461 \newline
34462 \InsetSpace ~
34463 \InsetSpace ~
34464 \InsetSpace ~
34465 \InsetSpace ~
34466 \InsetSpace ~
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 \InsetSpace ~
34470 \InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 \InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 \InsetSpace ~
34487  79 ;\InsetSpace ~
34488  hob.c 12 
34489 \newline
34490 0027 E5*01\InsetSpace ~
34491 \InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 \InsetSpace ~
34496 \InsetSpace ~
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505  80\InsetSpace ~
34506 \InsetSpace ~
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513  mov\InsetSpace ~
34514 \InsetSpace ~
34515  a,(_gint + 1) 
34516 \newline
34517 0029
34518  A2 E3\InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521 \InsetSpace ~
34522 \InsetSpace ~
34523 \InsetSpace ~
34524 \InsetSpace ~
34525 \InsetSpace ~
34526 \InsetSpace ~
34527 \InsetSpace ~
34528 \InsetSpace ~
34529 \InsetSpace ~
34530 \InsetSpace ~
34531 \InsetSpace ~
34532 \InsetSpace ~
34533  81\InsetSpace ~
34534 \InsetSpace ~
34535 \InsetSpace ~
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539 \InsetSpace ~
34540 \InsetSpace ~
34541  mov\InsetSpace ~
34542 \InsetSpace ~
34543  c,acc[3] 
34544 \newline
34545 002B 92*03\InsetSpace ~
34546 \InsetSpace ~
34547 \InsetSpace ~
34548 \InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 \InsetSpace ~
34554 \InsetSpace ~
34555 \InsetSpace ~
34556 \InsetSpace ~
34557 \InsetSpace ~
34558 \InsetSpace ~
34559 \InsetSpace ~
34560  82\InsetSpace ~
34561 \InsetSpace ~
34562 \InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 \InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568  mov\InsetSpace ~
34569 \InsetSpace ~
34570  _foo_aob3_1_1,c 
34571 \end_layout
34572
34573 \begin_layout Standard
34574 Other variations of these cases however will 
34575 \emph on
34576 not
34577 \emph default
34578  be recognized.
34579  They are standard C expressions, so I heartily recommend these be the only
34580  way to get the highest order bit, (it is portable).
34581  Of course it will be recognized even if it is embedded in other expressions,
34582  e.g.:
34583 \end_layout
34584
34585 \begin_layout Verse
34586
34587 \family typewriter
34588 xyz = gint + ((gint >> 15) & 1);
34589 \end_layout
34590
34591 \begin_layout Standard
34592 will still be recognized.
34593 \end_layout
34594
34595 \begin_layout Subsection
34596 Higher Order Byte
34597 \begin_inset LatexCommand \index{Higher Order Byte}
34598
34599 \end_inset
34600
34601  / Higher Order Word
34602 \begin_inset LatexCommand \index{Higher Order Word}
34603
34604 \end_inset
34605
34606
34607 \end_layout
34608
34609 \begin_layout Standard
34610 It is also frequently required to obtain a higher order byte or word of
34611  a larger integral type (long, int or short types).
34612  SDCC recognizes the following expressions to yield the higher order byte
34613  or word and generates optimized code for it, e.g.:
34614 \end_layout
34615
34616 \begin_layout Verse
34617
34618 \family typewriter
34619 unsigned int gint; 
34620 \newline
34621 unsigned long int glong; 
34622 \newline
34623
34624 \newline
34625 foo () { 
34626 \newline
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 unsigned char hob1,
34630  hob2; 
34631 \newline
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 unsigned int how1, how2; 
34635 \newline
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 ...
34639  
34640 \newline
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 hob1 = (gint >> 8) & 0xFF; 
34644 \newline
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 hob2 = glong >> 24; 
34648 \newline
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 how1 = (glong >> 16) & 0xFFFF;
34652  
34653 \newline
34654 \InsetSpace ~
34655 \InsetSpace ~
34656 how2 = glong >> 8; 
34657 \newline
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 ..
34661  
34662 \newline
34663 }
34664 \end_layout
34665
34666 \begin_layout Standard
34667 will generate the following code:
34668 \end_layout
34669
34670 \begin_layout Verse
34671
34672 \family typewriter
34673 \InsetSpace ~
34674 \InsetSpace ~
34675 \InsetSpace ~
34676 \InsetSpace ~
34677 \InsetSpace ~
34678 \InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686 \InsetSpace ~
34687 \InsetSpace ~
34688 \InsetSpace ~
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698  91 ;\InsetSpace ~
34699  hob.c 15 
34700 \newline
34701 0037 85*01*06\InsetSpace ~
34702 \InsetSpace ~
34703 \InsetSpace ~
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713  92\InsetSpace ~
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721  mov\InsetSpace ~
34722 \InsetSpace ~
34723  _foo_hob1_1_1,(_gint + 1) 
34724 \newline
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729 \InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739 \InsetSpace ~
34740 \InsetSpace ~
34741 \InsetSpace ~
34742 \InsetSpace ~
34743 \InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750  93 ;\InsetSpace ~
34751  hob.c
34752  16 
34753 \newline
34754 003A 85*05*07\InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766  94\InsetSpace ~
34767 \InsetSpace ~
34768 \InsetSpace ~
34769 \InsetSpace ~
34770 \InsetSpace ~
34771 \InsetSpace ~
34772 \InsetSpace ~
34773 \InsetSpace ~
34774  mov\InsetSpace ~
34775 \InsetSpace ~
34776  _foo_hob2_1_1,(_glong + 3) 
34777 \newline
34778 \InsetSpace ~
34779 \InsetSpace ~
34780 \InsetSpace ~
34781 \InsetSpace ~
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788 \InsetSpace ~
34789 \InsetSpace ~
34790 \InsetSpace ~
34791 \InsetSpace ~
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796 \InsetSpace ~
34797 \InsetSpace ~
34798 \InsetSpace ~
34799 \InsetSpace ~
34800 \InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803  95 ;\InsetSpace ~
34804  hob.c 17 
34805 \newline
34806 003D 85*04*08\InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818
34819  96\InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827  mov\InsetSpace ~
34828 \InsetSpace ~
34829  _foo_how1_1_1,(_glong + 2) 
34830 \newline
34831 0040 85*05*09\InsetSpace ~
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843  97\InsetSpace ~
34844 \InsetSpace ~
34845 \InsetSpace ~
34846 \InsetSpace ~
34847 \InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 \InsetSpace ~
34851  mov\InsetSpace ~
34852 \InsetSpace ~
34853  (_foo_how1_1_1 +
34854  1),(_glong + 3) 
34855 \newline
34856 0043 85*03*0A\InsetSpace ~
34857 \InsetSpace ~
34858 \InsetSpace ~
34859 \InsetSpace ~
34860 \InsetSpace ~
34861 \InsetSpace ~
34862 \InsetSpace ~
34863 \InsetSpace ~
34864 \InsetSpace ~
34865 \InsetSpace ~
34866 \InsetSpace ~
34867 \InsetSpace ~
34868  98\InsetSpace ~
34869 \InsetSpace ~
34870 \InsetSpace ~
34871 \InsetSpace ~
34872 \InsetSpace ~
34873 \InsetSpace ~
34874 \InsetSpace ~
34875 \InsetSpace ~
34876  mov\InsetSpace ~
34877 \InsetSpace ~
34878  _foo_how2_1_1,(_glong + 1) 
34879 \newline
34880 0046 85*04*0B\InsetSpace ~
34881 \InsetSpace ~
34882 \InsetSpace ~
34883 \InsetSpace ~
34884 \InsetSpace ~
34885 \InsetSpace ~
34886 \InsetSpace ~
34887 \InsetSpace ~
34888 \InsetSpace ~
34889 \InsetSpace ~
34890 \InsetSpace ~
34891 \InsetSpace ~
34892
34893  99\InsetSpace ~
34894 \InsetSpace ~
34895 \InsetSpace ~
34896 \InsetSpace ~
34897 \InsetSpace ~
34898 \InsetSpace ~
34899 \InsetSpace ~
34900 \InsetSpace ~
34901  mov\InsetSpace ~
34902 \InsetSpace ~
34903  (_foo_how2_1_1 + 1),(_glong + 2) 
34904 \end_layout
34905
34906 \begin_layout Standard
34907 Again, variations of these cases may 
34908 \emph on
34909 not
34910 \emph default
34911  be recognized.
34912  They are standard C expressions, so I heartily recommend these be the only
34913  way to get the higher order byte/word, (it is portable).
34914  Of course it will be recognized even if it is embedded in other expressions,
34915  e.g.:
34916 \end_layout
34917
34918 \begin_layout Verse
34919
34920 \family typewriter
34921 xyz = gint + ((gint >> 8) & 0xFF);
34922 \end_layout
34923
34924 \begin_layout Standard
34925 will still be recognized.
34926 \end_layout
34927
34928 \begin_layout Subsection
34929 Peephole Optimizer
34930 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34931
34932 \end_inset
34933
34934
34935 \begin_inset LatexCommand \index{Peephole optimizer}
34936
34937 \end_inset
34938
34939
34940 \end_layout
34941
34942 \begin_layout Standard
34943 The compiler uses a rule based, pattern matching and re-writing mechanism
34944  for peep-hole optimization.
34945  It is inspired by 
34946 \emph on
34947 copt
34948 \emph default
34949  a peep-hole optimizer by Christopher W.
34950  Fraser (cwfraser\InsetSpace ~
34951 @\InsetSpace ~
34952 microsoft.com).
34953  A default set of rules are compiled into the compiler, additional rules
34954  may be added with the 
34955 \emph on
34956 -
34957 \begin_inset ERT
34958 status collapsed
34959
34960 \begin_layout Standard
34961
34962
34963 \backslash
34964 /
34965 \end_layout
34966
34967 \end_inset
34968
34969 -peep-file
34970 \begin_inset LatexCommand \index{-\/-peep-file}
34971
34972 \end_inset
34973
34974  <filename>
34975 \emph default
34976  option.
34977  The rule language is best illustrated with examples.
34978 \end_layout
34979
34980 \begin_layout Verse
34981
34982 \family typewriter
34983 replace { 
34984 \newline
34985 \InsetSpace ~
34986 \InsetSpace ~
34987 mov %1,a 
34988 \newline
34989 \InsetSpace ~
34990 \InsetSpace ~
34991 mov a,%1
34992 \newline
34993 } by {
34994 \newline
34995 \InsetSpace ~
34996 \InsetSpace ~
34997 mov %1,a
34998 \newline
34999 }
35000 \end_layout
35001
35002 \begin_layout Standard
35003 The above rule will change the following assembly
35004 \begin_inset LatexCommand \index{Assembler routines}
35005
35006 \end_inset
35007
35008  sequence:
35009 \end_layout
35010
35011 \begin_layout Verse
35012
35013 \family typewriter
35014 mov r1,a 
35015 \newline
35016 mov a,r1
35017 \end_layout
35018
35019 \begin_layout Standard
35020 to
35021 \end_layout
35022
35023 \begin_layout Verse
35024
35025 \family typewriter
35026 mov r1,a
35027 \end_layout
35028
35029 \begin_layout Standard
35030 Note: All occurrences of a 
35031 \emph on
35032 %n
35033 \emph default
35034  (pattern variable) must denote the same string.
35035  With the above rule, the assembly sequence:
35036 \end_layout
35037
35038 \begin_layout Verse
35039
35040 \family typewriter
35041 mov r1,a 
35042 \newline
35043 mov a,r2
35044 \end_layout
35045
35046 \begin_layout Standard
35047 will remain unmodified.
35048 \newline
35049
35050 \newline
35051 Other special case optimizations may be added by the
35052  user (via 
35053 \emph on
35054 -
35055 \begin_inset ERT
35056 status collapsed
35057
35058 \begin_layout Standard
35059
35060
35061 \backslash
35062 /
35063 \end_layout
35064
35065 \end_inset
35066
35067 -peep-file option
35068 \emph default
35069 ).
35070  E.g.
35071  some variants of the 8051 MCU
35072 \begin_inset LatexCommand \index{MCS51 variants}
35073
35074 \end_inset
35075
35076  allow only 
35077 \family typewriter
35078 ajmp
35079 \family default
35080  and 
35081 \family typewriter
35082 acall
35083 \family default
35084 .
35085  The following two rules will change all 
35086 \family typewriter
35087 ljmp
35088 \family default
35089  and 
35090 \family typewriter
35091 lcall
35092 \family default
35093  to 
35094 \family typewriter
35095 ajmp
35096 \family default
35097  and 
35098 \family typewriter
35099 acall
35100 \end_layout
35101
35102 \begin_layout Verse
35103
35104 \family typewriter
35105 replace { lcall %1 } by { acall %1 } 
35106 \newline
35107 replace { ljmp %1 } by { ajmp %1 }
35108 \end_layout
35109
35110 \begin_layout Standard
35111 The 
35112 \emph on
35113 inline-assembler code
35114 \emph default
35115  is also passed through the peep hole optimizer, thus the peephole optimizer
35116  can also be used as an assembly level macro expander.
35117  The rules themselves are MCU dependent whereas the rule language infra-structur
35118 e is MCU independent.
35119  Peephole optimization rules for other MCU can be easily programmed using
35120  the rule language.
35121 \newline
35122
35123 \newline
35124 The syntax for a rule is as follows:
35125 \end_layout
35126
35127 \begin_layout Verse
35128
35129 \family typewriter
35130 rule := replace [ restart ] '{' <assembly sequence> '
35131 \backslash
35132 n' 
35133 \newline
35134 \InsetSpace ~
35135  \InsetSpace ~
35136  \InsetSpace ~
35137  \InsetSpace ~
35138  \InsetSpace ~
35139  \InsetSpace ~
35140  \InsetSpace ~
35141  \InsetSpace ~
35142  \InsetSpace ~
35143  \InsetSpace ~
35144  \InsetSpace ~
35145  \InsetSpace ~
35146  \InsetSpace ~
35147  \InsetSpace ~
35148  '}' by '{' '
35149 \backslash
35150 n' 
35151 \newline
35152 \InsetSpace ~
35153  \InsetSpace ~
35154  \InsetSpace ~
35155  \InsetSpace ~
35156  \InsetSpace ~
35157  \InsetSpace ~
35158  \InsetSpace ~
35159  \InsetSpace ~
35160  \InsetSpace ~
35161  \InsetSpace ~
35162  \InsetSpace ~
35163  \InsetSpace ~
35164  \InsetSpace ~
35165  \InsetSpace ~
35166  \InsetSpace ~
35167  \InsetSpace ~
35168  <assembly sequence> '
35169 \backslash
35170 n' 
35171 \newline
35172 \InsetSpace ~
35173  \InsetSpace ~
35174  \InsetSpace ~
35175  \InsetSpace ~
35176  \InsetSpace ~
35177  \InsetSpace ~
35178  \InsetSpace ~
35179  \InsetSpace ~
35180  \InsetSpace ~
35181  \InsetSpace ~
35182  \InsetSpace ~
35183  \InsetSpace ~
35184  \InsetSpace ~
35185  \InsetSpace ~
35186  '}' [if <functionName> ] '
35187 \backslash
35188 n' 
35189 \end_layout
35190
35191 \begin_layout Standard
35192 <assembly sequence> := assembly instruction (each instruction including
35193  labels must be on a separate line).
35194 \newline
35195
35196 \newline
35197 The optimizer will apply to the rules
35198  one by one from the top in the sequence of their appearance, it will terminate
35199  when all rules are exhausted.
35200  If the 'restart' option is specified, then the optimizer will start matching
35201  the rules again from the top, this option for a rule is expensive (performance)
35202 , it is intended to be used in situations where a transformation will trigger
35203  the same rule again.
35204  An example of this (not a good one, it has side effects) is the following
35205  rule:
35206 \end_layout
35207
35208 \begin_layout Verse
35209
35210 \family typewriter
35211 replace restart { 
35212 \newline
35213 \InsetSpace ~
35214 \InsetSpace ~
35215 pop %1 
35216 \newline
35217 \InsetSpace ~
35218 \InsetSpace ~
35219 push %1 } by { 
35220 \newline
35221 \InsetSpace ~
35222 \InsetSpace ~
35223 ; nop 
35224 \newline
35225 }
35226 \end_layout
35227
35228 \begin_layout Standard
35229 Note that the replace pattern cannot be a blank, but can be a comment line.
35230  Without the 'restart' option only the innermost 'pop' 'push' pair would
35231  be eliminated, i.e.:
35232 \end_layout
35233
35234 \begin_layout Verse
35235
35236 \family typewriter
35237 pop ar1 
35238 \newline
35239 pop ar2 
35240 \newline
35241 push ar2 
35242 \newline
35243 push ar1
35244 \end_layout
35245
35246 \begin_layout Standard
35247 would result in:
35248 \end_layout
35249
35250 \begin_layout Verse
35251
35252 \family typewriter
35253 pop ar1 
35254 \newline
35255 ; nop 
35256 \newline
35257 push ar1
35258 \end_layout
35259
35260 \begin_layout Standard
35261
35262 \emph on
35263 with
35264 \emph default
35265  the restart option the rule will be applied again to the resulting code
35266  and then all the pop-push pairs will be eliminated to yield:
35267 \end_layout
35268
35269 \begin_layout Verse
35270
35271 \family typewriter
35272 ; nop 
35273 \newline
35274 ; nop
35275 \end_layout
35276
35277 \begin_layout Standard
35278 A conditional function can be attached to a rule.
35279  Attaching rules are somewhat more involved, let me illustrate this with
35280  an example.
35281 \end_layout
35282
35283 \begin_layout Verse
35284
35285 \family typewriter
35286 replace { 
35287 \newline
35288 \InsetSpace ~
35289  \InsetSpace ~
35290  \InsetSpace ~
35291 ljmp %5 
35292 \newline
35293 %2:
35294 \newline
35295 } by { 
35296 \newline
35297 \InsetSpace ~
35298  \InsetSpace ~
35299  \InsetSpace ~
35300 sjmp %5 
35301 \newline
35302 %2:
35303 \newline
35304 } if labelInRange
35305 \end_layout
35306
35307 \begin_layout Standard
35308 The optimizer does a look-up of a function name table defined in function
35309  
35310 \emph on
35311 callFuncByName
35312 \emph default
35313  in the source file SDCCpeeph.c, with the name 
35314 \emph on
35315 labelInRange
35316 \emph default
35317 .
35318  If it finds a corresponding entry the function is called.
35319  Note there can be no parameters specified for these functions, in this
35320  case the use of 
35321 \emph on
35322 %5
35323 \emph default
35324  is crucial, since the function 
35325 \emph on
35326 labelInRange
35327 \emph default
35328  expects to find the label in that particular variable (the hash table containin
35329 g the variable bindings is passed as a parameter).
35330  If you want to code more such functions, take a close look at the function
35331  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35332  Currently implemented are 
35333 \emph on
35334 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35335  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35336 \emph default
35337 and
35338 \emph on
35339  notVolatile
35340 \emph default
35341 .
35342 \end_layout
35343
35344 \begin_layout Standard
35345 I know this whole thing is a little kludgey, but maybe some day we will
35346  have some better means.
35347  If you are looking at this file, you will see the default rules that are
35348  compiled into the compiler, you can add your own rules in the default set
35349  there if you get tired of specifying the -
35350 \begin_inset ERT
35351 status collapsed
35352
35353 \begin_layout Standard
35354
35355
35356 \backslash
35357 /
35358 \end_layout
35359
35360 \end_inset
35361
35362 -peep-file option.
35363 \end_layout
35364
35365 \begin_layout Section
35366 ANSI-Compliance
35367 \begin_inset LatexCommand \index{ANSI-compliance}
35368
35369 \end_inset
35370
35371
35372 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35373
35374 \end_inset
35375
35376
35377 \end_layout
35378
35379 \begin_layout Standard
35380 The latest publically available version of the standard 
35381 \emph on
35382 ISO/IEC 9899 - Programming languages - C
35383 \emph default
35384  should be available at: 
35385 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35386
35387 \end_inset
35388
35389 .
35390 \newline
35391
35392 \end_layout
35393
35394 \begin_layout Standard
35395 Deviations from the compliance:
35396 \end_layout
35397
35398 \begin_layout Itemize
35399 functions are not reentrant
35400 \begin_inset LatexCommand \index{reentrant}
35401
35402 \end_inset
35403
35404  unless explicitly declared as such or the 
35405 \series bold
35406 -
35407 \begin_inset ERT
35408 status collapsed
35409
35410 \begin_layout Standard
35411
35412
35413 \backslash
35414 /
35415 \end_layout
35416
35417 \end_inset
35418
35419 -stack-auto
35420 \begin_inset LatexCommand \index{-\/-stack-auto}
35421
35422 \end_inset
35423
35424
35425 \series default
35426  command line option is specified.
35427 \end_layout
35428
35429 \begin_layout Itemize
35430 structures
35431 \begin_inset LatexCommand \index{struct}
35432
35433 \end_inset
35434
35435  and unions
35436 \begin_inset LatexCommand \index{union}
35437
35438 \end_inset
35439
35440  cannot be assigned values directly, cannot be passed as function parameters
35441  or assigned to each other and cannot be a return value
35442 \begin_inset LatexCommand \index{return value}
35443
35444 \end_inset
35445
35446  from a function, e.g.:
35447 \end_layout
35448
35449 \begin_deeper
35450 \begin_layout Verse
35451
35452 \family typewriter
35453 struct s { ...
35454  }; 
35455 \newline
35456 struct s s1, s2; 
35457 \newline
35458 foo() 
35459 \newline
35460
35461 \newline
35462 \InsetSpace ~
35463 \InsetSpace ~
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 ...
35467  
35468 \newline
35469 \InsetSpace ~
35470 \InsetSpace ~
35471 \InsetSpace ~
35472 \InsetSpace ~
35473 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35474 \newline
35475 \InsetSpace ~
35476 \InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479 ...
35480  
35481 \newline
35482 }
35483 \newline
35484
35485 \series bold
35486 struct
35487 \series default
35488  s foo1 (
35489 \series bold
35490 struct
35491 \series default
35492  s parms) /* invalid in SDCC although allowed in ANSI */
35493 \newline
35494
35495 \newline
35496 \InsetSpace ~
35497 \InsetSpace ~
35498 \InsetSpace ~
35499 \InsetSpace ~
35500 struct s rets;
35501  
35502 \newline
35503 \InsetSpace ~
35504 \InsetSpace ~
35505 \InsetSpace ~
35506 \InsetSpace ~
35507 ...
35508  
35509 \newline
35510 \InsetSpace ~
35511 \InsetSpace ~
35512 \InsetSpace ~
35513 \InsetSpace ~
35514 return rets; /* is invalid in SDCC although allowed in ANSI */ 
35515 \newline
35516 }
35517 \end_layout
35518
35519 \end_deeper
35520 \begin_layout Itemize
35521 initialization of structure arrays must be fully braced.
35522 \end_layout
35523
35524 \begin_deeper
35525 \begin_layout Verse
35526
35527 \family typewriter
35528 struct s { char x } a[] = {1, 2};\InsetSpace ~
35529 \InsetSpace ~
35530 \InsetSpace ~
35531 \InsetSpace ~
35532 \InsetSpace ~
35533 /* invalid in SDCC */
35534 \newline
35535 struct s { char x
35536  } a[] = {{1}, {2}}; /* OK */
35537 \end_layout
35538
35539 \end_deeper
35540 \begin_layout Itemize
35541 'long long
35542 \begin_inset LatexCommand \index{long long (not supported)}
35543
35544 \end_inset
35545
35546 ' (64 bit integers
35547 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35548
35549 \end_inset
35550
35551 ) not supported.
35552 \end_layout
35553
35554 \begin_layout Itemize
35555 'double
35556 \begin_inset LatexCommand \index{double (not supported)}
35557
35558 \end_inset
35559
35560 ' precision floating point 
35561 \begin_inset LatexCommand \index{Floating point support}
35562
35563 \end_inset
35564
35565 not supported.
35566 \end_layout
35567
35568 \begin_layout Itemize
35569 Old K&R style
35570 \begin_inset LatexCommand \index{K\&R style}
35571
35572 \end_inset
35573
35574  function declarations are NOT allowed.
35575 \end_layout
35576
35577 \begin_deeper
35578 \begin_layout Verse
35579
35580 \family typewriter
35581 foo(i,j) /* this old style of function declarations */ 
35582 \newline
35583 int i,j; /* are valid
35584  in ANSI but not valid in SDCC */ 
35585 \newline
35586
35587 \newline
35588 \InsetSpace ~
35589 \InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 ...
35593  
35594 \newline
35595 }
35596 \end_layout
35597
35598 \end_deeper
35599 \begin_layout Itemize
35600 Most enhancements in C99 are not supported, f.e.:
35601 \end_layout
35602
35603 \begin_deeper
35604 \begin_layout Verse
35605
35606 \family typewriter
35607 \series bold
35608 inline
35609 \begin_inset LatexCommand \index{inline (not supported)}
35610
35611 \end_inset
35612
35613
35614 \series default
35615  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35616  in C99.
35617  An empty define 
35618 \emph on
35619 #define inline
35620 \emph default
35621  can be used as a work around */
35622 \newline
35623
35624 \newline
35625 for (
35626 \series bold
35627 int
35628 \series default
35629  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35630 \end_layout
35631
35632 \end_deeper
35633 \begin_layout Itemize
35634 Certain words that are valid identifiers in the standard may be reserved
35635  words in SDCC unless the 
35636 \series bold
35637 -
35638 \begin_inset ERT
35639 status collapsed
35640
35641 \begin_layout Standard
35642
35643
35644 \backslash
35645 /
35646 \end_layout
35647
35648 \end_inset
35649
35650 -std-c89
35651 \begin_inset LatexCommand \index{-\/-std-c89}
35652
35653 \end_inset
35654
35655  or -
35656 \begin_inset ERT
35657 status collapsed
35658
35659 \begin_layout Standard
35660
35661
35662 \backslash
35663 /
35664 \end_layout
35665
35666 \end_inset
35667
35668 -std-c99
35669 \begin_inset LatexCommand \index{-\/-std-c99}
35670
35671 \end_inset
35672
35673
35674 \series default
35675  command line options are used.
35676  These may include (depending on the selected processor): 'at', 'banked',
35677  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35678 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35679  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35680  '_naked'.
35681  Compliant equivalents of these keywords are always available in a form
35682  that begin with two underscores
35683 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35684
35685 \end_inset
35686
35687 , f.e.
35688  '__data' instead of 'data'.
35689 \end_layout
35690
35691 \begin_layout Section
35692 Cyclomatic Complexity
35693 \begin_inset LatexCommand \index{Cyclomatic complexity}
35694
35695 \end_inset
35696
35697
35698 \end_layout
35699
35700 \begin_layout Standard
35701 Cyclomatic complexity of a function is defined as the number of independent
35702  paths the program can take during execution of the function.
35703  This is an important number since it defines the number test cases you
35704  have to generate to validate the function.
35705  The accepted industry standard for complexity number is 10, if the cyclomatic
35706  complexity reported by SDCC exceeds 10 you should think about simplification
35707  of the function logic.
35708  Note that the complexity level is not related to the number of lines of
35709  code in a function.
35710  Large functions can have low complexity, and small functions can have large
35711  complexity levels.
35712  
35713 \newline
35714
35715 \newline
35716 SDCC uses the following formula to compute the complexity:
35717 \newline
35718
35719 \end_layout
35720
35721 \begin_layout Standard
35722 complexity = (number of edges in control flow graph) - (number of nodes
35723  in control flow graph) + 2;
35724 \newline
35725
35726 \newline
35727 Having said that the industry standard is 10,
35728  you should be aware that in some cases it be may unavoidable to have a
35729  complexity level of less than 10.
35730  For example if you have switch statement with more than 10 case labels,
35731  each case label adds one to the complexity level.
35732  The complexity level is by no means an absolute measure of the algorithmic
35733  complexity of the function, it does however provide a good starting point
35734  for which functions you might look at for further optimization.
35735 \end_layout
35736
35737 \begin_layout Section
35738 Retargetting for other Processors
35739 \end_layout
35740
35741 \begin_layout Standard
35742 The issues for retargetting the compiler are far too numerous to be covered
35743  by this document.
35744  What follows is a brief description of each of the seven phases of the
35745  compiler and its MCU dependency.
35746 \end_layout
35747
35748 \begin_layout Itemize
35749 Parsing the source and building the annotated parse tree.
35750  This phase is largely MCU independent (except for the language extensions).
35751  Syntax & semantic checks are also done in this phase, along with some initial
35752  optimizations like back patching labels and the pattern matching optimizations
35753  like bit-rotation etc.
35754 \end_layout
35755
35756 \begin_layout Itemize
35757 The second phase involves generating an intermediate code which can be easy
35758  manipulated during the later phases.
35759  This phase is entirely MCU independent.
35760  The intermediate code generation assumes the target machine has unlimited
35761  number of registers, and designates them with the name iTemp.
35762  The compiler can be made to dump a human readable form of the code generated
35763  by using the -
35764 \begin_inset ERT
35765 status collapsed
35766
35767 \begin_layout Standard
35768
35769
35770 \backslash
35771 /
35772 \end_layout
35773
35774 \end_inset
35775
35776 -dumpraw option.
35777 \end_layout
35778
35779 \begin_layout Itemize
35780 This phase does the bulk of the standard optimizations and is also MCU independe
35781 nt.
35782  This phase can be broken down into several sub-phases:
35783 \newline
35784
35785 \newline
35786 Break down intermediate
35787  code (iCode) into basic blocks.
35788 \newline
35789 Do control flow & data flow analysis on the
35790  basic blocks.
35791 \newline
35792 Do local common subexpression elimination, then global subexpressio
35793 n elimination
35794 \newline
35795 Dead code elimination
35796 \newline
35797 Loop optimizations
35798 \newline
35799 If loop optimizations
35800  caused any changes then do 'global subexpression elimination' and 'dead
35801  code elimination' again.
35802 \end_layout
35803
35804 \begin_layout Itemize
35805 This phase determines the live-ranges; by live range I mean those iTemp
35806  variables defined by the compiler that still survive after all the optimization
35807 s.
35808  Live range analysis
35809 \begin_inset LatexCommand \index{Live range analysis}
35810
35811 \end_inset
35812
35813  is essential for register allocation, since these computation determines
35814  which of these iTemps will be assigned to registers, and for how long.
35815 \end_layout
35816
35817 \begin_layout Itemize
35818 Phase five is register allocation.
35819  There are two parts to this process.
35820 \newline
35821
35822 \newline
35823 The first part I call 'register packing'
35824  (for lack of a better term).
35825  In this case several MCU specific expression folding is done to reduce
35826  register pressure.
35827 \newline
35828
35829 \newline
35830 The second part is more MCU independent and deals with
35831  allocating registers to the remaining live ranges.
35832  A lot of MCU specific code does creep into this phase because of the limited
35833  number of index registers available in the 8051.
35834 \end_layout
35835
35836 \begin_layout Itemize
35837 The Code generation phase is (unhappily), entirely MCU dependent and very
35838  little (if any at all) of this code can be reused for other MCU.
35839  However the scheme for allocating a homogenized assembler operand for each
35840  iCode operand may be reused.
35841 \end_layout
35842
35843 \begin_layout Itemize
35844 As mentioned in the optimization section the peep-hole optimizer is rule
35845  based system, which can reprogrammed for other MCUs.
35846 \end_layout
35847
35848 \begin_layout Standard
35849 More information is available in a wiki
35850 \begin_inset LatexCommand \index{wiki}
35851
35852 \end_inset
35853
35854  (preliminary link 
35855 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35856
35857 \end_inset
35858
35859 ) and in the thread 
35860 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35861
35862 \end_inset
35863
35864  .
35865 \end_layout
35866
35867 \begin_layout Chapter
35868 Compiler internals
35869 \begin_inset LatexCommand \index{Compiler internals}
35870
35871 \end_inset
35872
35873
35874 \end_layout
35875
35876 \begin_layout Section
35877 The anatomy of the compiler
35878 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35879
35880 \end_inset
35881
35882
35883 \end_layout
35884
35885 \begin_layout Standard
35886
35887 \shape italic
35888 This is an excerpt from an article published in Circuit Cellar Magazine
35889  in 
35890 \series bold
35891 August 2000
35892 \series default
35893 .
35894  It's a little outdated (the compiler is much more efficient now and user/develo
35895 per friendly), but pretty well exposes the guts of it all.
35896 \shape default
35897
35898 \newline
35899
35900 \newline
35901 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35902  It is fairly easy to retarget for other 8-bit MCU.
35903  Here we take a look at some of the internals of the compiler.
35904  
35905 \end_layout
35906
35907 \begin_layout Paragraph*
35908 Parsing
35909 \begin_inset LatexCommand \index{Parsing}
35910
35911 \end_inset
35912
35913  
35914 \end_layout
35915
35916 \begin_layout Standard
35917 Parsing the input source file and creating an AST (Annotated Syntax Tree
35918 \begin_inset LatexCommand \index{Annotated syntax tree}
35919
35920 \end_inset
35921
35922 ).
35923  This phase also involves propagating types (annotating each node of the
35924  parse tree with type information) and semantic analysis.
35925  There are some MCU specific parsing rules.
35926  For example the storage classes, the extended storage classes are MCU specific
35927  while there may be a xdata storage class for 8051 there is no such storage
35928  class for z80 or Atmel AVR.
35929  SDCC allows MCU specific storage class extensions, i.e.
35930  xdata will be treated as a storage class specifier when parsing 8051 C
35931  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35932  C code.
35933 \end_layout
35934
35935 \begin_layout Paragraph*
35936 Generating iCode
35937 \begin_inset LatexCommand \index{iCode}
35938
35939 \end_inset
35940
35941
35942 \end_layout
35943
35944 \begin_layout Standard
35945 Intermediate code generation.
35946  In this phase the AST is broken down into three-operand form (iCode).
35947  These three operand forms are represented as doubly linked lists.
35948  ICode is the term given to the intermediate form generated by the compiler.
35949  ICode example section shows some examples of iCode generated for some simple
35950  C source functions.
35951 \end_layout
35952
35953 \begin_layout Paragraph*
35954 Optimizations
35955 \begin_inset LatexCommand \index{Optimizations}
35956
35957 \end_inset
35958
35959 .
35960 \end_layout
35961
35962 \begin_layout Standard
35963 Bulk of the target independent optimizations is performed in this phase.
35964  The optimizations include constant propagation, common sub-expression eliminati
35965 on, loop invariant code movement, strength reduction of loop induction variables
35966  and dead-code elimination.
35967 \end_layout
35968
35969 \begin_layout Paragraph*
35970 Live range analysis
35971 \begin_inset LatexCommand \index{Live range analysis}
35972
35973 \end_inset
35974
35975
35976 \end_layout
35977
35978 \begin_layout Standard
35979 During intermediate code generation phase, the compiler assumes the target
35980  machine has infinite number of registers and generates a lot of temporary
35981  variables.
35982  The live range computation determines the lifetime of each of these compiler-ge
35983 nerated temporaries.
35984  A picture speaks a thousand words.
35985  ICode example sections show the live range annotations for each of the
35986  operand.
35987  It is important to note here, each iCode is assigned a number in the order
35988  of its execution in the function.
35989  The live ranges are computed in terms of these numbers.
35990  The from number is the number of the iCode which first defines the operand
35991  and the to number signifies the iCode which uses this operand last.
35992 \end_layout
35993
35994 \begin_layout Paragraph*
35995 Register Allocation
35996 \begin_inset LatexCommand \index{Register allocation}
35997
35998 \end_inset
35999
36000
36001 \end_layout
36002
36003 \begin_layout Standard
36004 The register allocation determines the type and number of registers needed
36005  by each operand.
36006  In most MCUs only a few registers can be used for indirect addressing.
36007  In case of 8051 for example the registers R0 & R1 can be used to indirectly
36008  address the internal ram and DPTR to indirectly address the external ram.
36009  The compiler will try to allocate the appropriate register to pointer variables
36010  if it can.
36011  ICode example section shows the operands annotated with the registers assigned
36012  to them.
36013  The compiler will try to keep operands in registers as much as possible;
36014  there are several schemes the compiler uses to do achieve this.
36015  When the compiler runs out of registers the compiler will check to see
36016  if there are any live operands which is not used or defined in the current
36017  basic block being processed, if there are any found then it will push that
36018  operand and use the registers in this block, the operand will then be popped
36019  at the end of the basic block.
36020  
36021 \end_layout
36022
36023 \begin_layout Standard
36024 There are other MCU specific considerations in this phase.
36025  Some MCUs have an accumulator; very short-lived operands could be assigned
36026  to the accumulator instead of a general-purpose register.
36027 \end_layout
36028
36029 \begin_layout Paragraph*
36030 Code generation
36031 \end_layout
36032
36033 \begin_layout Standard
36034 Figure II gives a table of iCode
36035 \begin_inset LatexCommand \index{iCode}
36036
36037 \end_inset
36038
36039  operations supported by the compiler.
36040  The code generation involves translating these operations into corresponding
36041  assembly code for the processor.
36042  This sounds overly simple but that is the essence of code generation.
36043  Some of the iCode operations are generated on a MCU specific manner for
36044  example, the z80 port does not use registers to pass parameters so the
36045  SEND and RECV iCode operations will not be generated, and it also does
36046  not support JUMPTABLES.
36047  
36048 \newline
36049
36050 \end_layout
36051
36052 \begin_layout Standard
36053
36054 \size footnotesize
36055 Figure II 
36056 \begin_inset Tabular
36057 <lyxtabular version="3" rows="39" columns="4">
36058 <features islongtable="true" headBottomDL="true">
36059 <column alignment="block" valignment="top" leftline="true" width="13col%">
36060 <column alignment="left" valignment="top" leftline="true" width="13col%">
36061 <column alignment="block" valignment="top" leftline="true" width="22col%">
36062 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36063 <row topline="true" bottomline="true" endhead="true">
36064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36065 \begin_inset Text
36066
36067 \begin_layout Standard
36068
36069 \series bold
36070 iCode
36071 \series default
36072
36073 \begin_inset LatexCommand \index{iCode}
36074
36075 \end_inset
36076
36077
36078 \end_layout
36079
36080 \end_inset
36081 </cell>
36082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36083 \begin_inset Text
36084
36085 \begin_layout Standard
36086
36087 \series bold
36088 Operands
36089 \end_layout
36090
36091 \end_inset
36092 </cell>
36093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36094 \begin_inset Text
36095
36096 \begin_layout Standard
36097
36098 \series bold
36099 Description
36100 \end_layout
36101
36102 \end_inset
36103 </cell>
36104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36105 \begin_inset Text
36106
36107 \begin_layout Standard
36108
36109 \series bold
36110 C Equivalent
36111 \end_layout
36112
36113 \end_inset
36114 </cell>
36115 </row>
36116 <row topline="true">
36117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36118 \begin_inset Text
36119
36120 \begin_layout Standard
36121
36122 \size footnotesize
36123 '!'
36124 \end_layout
36125
36126 \end_inset
36127 </cell>
36128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36129 \begin_inset Text
36130
36131 \begin_layout Standard
36132
36133 \size footnotesize
36134 IC_LEFT() IC_RESULT()
36135 \end_layout
36136
36137 \end_inset
36138 </cell>
36139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36140 \begin_inset Text
36141
36142 \begin_layout Standard
36143
36144 \size footnotesize
36145 NOT operation 
36146 \end_layout
36147
36148 \end_inset
36149 </cell>
36150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36151 \begin_inset Text
36152
36153 \begin_layout Standard
36154
36155 \size footnotesize
36156 IC_RESULT = ! IC_LEFT;
36157 \end_layout
36158
36159 \end_inset
36160 </cell>
36161 </row>
36162 <row topline="true">
36163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36164 \begin_inset Text
36165
36166 \begin_layout Standard
36167
36168 \size footnotesize
36169 '~'
36170 \end_layout
36171
36172 \end_inset
36173 </cell>
36174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36175 \begin_inset Text
36176
36177 \begin_layout Standard
36178
36179 \size footnotesize
36180 IC_LEFT() IC_RESULT()
36181 \end_layout
36182
36183 \end_inset
36184 </cell>
36185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36186 \begin_inset Text
36187
36188 \begin_layout Standard
36189
36190 \size footnotesize
36191 Bitwise complement of 
36192 \end_layout
36193
36194 \end_inset
36195 </cell>
36196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36197 \begin_inset Text
36198
36199 \begin_layout Standard
36200
36201 \size footnotesize
36202 IC_RESULT = ~IC_LEFT;
36203 \end_layout
36204
36205 \end_inset
36206 </cell>
36207 </row>
36208 <row topline="true">
36209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36210 \begin_inset Text
36211
36212 \begin_layout Standard
36213
36214 \size footnotesize
36215 RRC
36216 \end_layout
36217
36218 \end_inset
36219 </cell>
36220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36221 \begin_inset Text
36222
36223 \begin_layout Standard
36224
36225 \size footnotesize
36226 IC_LEFT() IC_RESULT()
36227 \end_layout
36228
36229 \end_inset
36230 </cell>
36231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36232 \begin_inset Text
36233
36234 \begin_layout Standard
36235
36236 \size footnotesize
36237 Rotate right with carry
36238 \end_layout
36239
36240 \end_inset
36241 </cell>
36242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36243 \begin_inset Text
36244
36245 \begin_layout Standard
36246
36247 \size footnotesize
36248 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36249 \end_layout
36250
36251 \end_inset
36252 </cell>
36253 </row>
36254 <row topline="true">
36255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36256 \begin_inset Text
36257
36258 \begin_layout Standard
36259
36260 \size footnotesize
36261 RLC
36262 \end_layout
36263
36264 \end_inset
36265 </cell>
36266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36267 \begin_inset Text
36268
36269 \begin_layout Standard
36270
36271 \size footnotesize
36272 IC_LEFT() IC_RESULT()
36273 \end_layout
36274
36275 \end_inset
36276 </cell>
36277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36278 \begin_inset Text
36279
36280 \begin_layout Standard
36281
36282 \size footnotesize
36283 Rotate left with carry
36284 \end_layout
36285
36286 \end_inset
36287 </cell>
36288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36289 \begin_inset Text
36290
36291 \begin_layout Standard
36292
36293 \size footnotesize
36294 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36295 \end_layout
36296
36297 \end_inset
36298 </cell>
36299 </row>
36300 <row topline="true">
36301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36302 \begin_inset Text
36303
36304 \begin_layout Standard
36305
36306 \size footnotesize
36307 GETHBIT
36308 \end_layout
36309
36310 \end_inset
36311 </cell>
36312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36313 \begin_inset Text
36314
36315 \begin_layout Standard
36316
36317 \size footnotesize
36318 IC_LEFT() IC_RESULT()
36319 \end_layout
36320
36321 \end_inset
36322 </cell>
36323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36324 \begin_inset Text
36325
36326 \begin_layout Standard
36327
36328 \size footnotesize
36329 Get the highest order bit of IC_LEFT
36330 \end_layout
36331
36332 \end_inset
36333 </cell>
36334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36335 \begin_inset Text
36336
36337 \begin_layout Standard
36338
36339 \size footnotesize
36340 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36341 \end_layout
36342
36343 \end_inset
36344 </cell>
36345 </row>
36346 <row topline="true">
36347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36348 \begin_inset Text
36349
36350 \begin_layout Standard
36351
36352 \size footnotesize
36353 UNARYMINUS
36354 \end_layout
36355
36356 \end_inset
36357 </cell>
36358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36359 \begin_inset Text
36360
36361 \begin_layout Standard
36362
36363 \size footnotesize
36364 IC_LEFT() IC_RESULT()
36365 \end_layout
36366
36367 \end_inset
36368 </cell>
36369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36370 \begin_inset Text
36371
36372 \begin_layout Standard
36373
36374 \size footnotesize
36375 Unary minus
36376 \end_layout
36377
36378 \end_inset
36379 </cell>
36380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36381 \begin_inset Text
36382
36383 \begin_layout Standard
36384
36385 \size footnotesize
36386 IC_RESULT = - IC_LEFT;
36387 \end_layout
36388
36389 \end_inset
36390 </cell>
36391 </row>
36392 <row topline="true">
36393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36394 \begin_inset Text
36395
36396 \begin_layout Standard
36397
36398 \size footnotesize
36399 IPUSH
36400 \end_layout
36401
36402 \end_inset
36403 </cell>
36404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36405 \begin_inset Text
36406
36407 \begin_layout Standard
36408
36409 \size footnotesize
36410 IC_LEFT()
36411 \end_layout
36412
36413 \end_inset
36414 </cell>
36415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36416 \begin_inset Text
36417
36418 \begin_layout Standard
36419
36420 \size footnotesize
36421 Push the operand into stack
36422 \end_layout
36423
36424 \end_inset
36425 </cell>
36426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36427 \begin_inset Text
36428
36429 \begin_layout Standard
36430
36431 \size footnotesize
36432 NONE
36433 \end_layout
36434
36435 \end_inset
36436 </cell>
36437 </row>
36438 <row topline="true">
36439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36440 \begin_inset Text
36441
36442 \begin_layout Standard
36443
36444 \size footnotesize
36445 IPOP
36446 \end_layout
36447
36448 \end_inset
36449 </cell>
36450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36451 \begin_inset Text
36452
36453 \begin_layout Standard
36454
36455 \size footnotesize
36456 IC_LEFT()
36457 \end_layout
36458
36459 \end_inset
36460 </cell>
36461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36462 \begin_inset Text
36463
36464 \begin_layout Standard
36465
36466 \size footnotesize
36467 Pop the operand from the stack 
36468 \end_layout
36469
36470 \end_inset
36471 </cell>
36472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36473 \begin_inset Text
36474
36475 \begin_layout Standard
36476
36477 \size footnotesize
36478 NONE
36479 \end_layout
36480
36481 \end_inset
36482 </cell>
36483 </row>
36484 <row topline="true">
36485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36486 \begin_inset Text
36487
36488 \begin_layout Standard
36489
36490 \size footnotesize
36491 CALL
36492 \end_layout
36493
36494 \end_inset
36495 </cell>
36496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36497 \begin_inset Text
36498
36499 \begin_layout Standard
36500
36501 \size footnotesize
36502 IC_LEFT() IC_RESULT()
36503 \end_layout
36504
36505 \end_inset
36506 </cell>
36507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36508 \begin_inset Text
36509
36510 \begin_layout Standard
36511
36512 \size footnotesize
36513 Call the function represented by IC_LEFT 
36514 \end_layout
36515
36516 \end_inset
36517 </cell>
36518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36519 \begin_inset Text
36520
36521 \begin_layout Standard
36522
36523 \size footnotesize
36524 IC_RESULT = IC_LEFT();
36525 \end_layout
36526
36527 \end_inset
36528 </cell>
36529 </row>
36530 <row topline="true">
36531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36532 \begin_inset Text
36533
36534 \begin_layout Standard
36535
36536 \size footnotesize
36537 PCALL
36538 \end_layout
36539
36540 \end_inset
36541 </cell>
36542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36543 \begin_inset Text
36544
36545 \begin_layout Standard
36546
36547 \size footnotesize
36548 IC_LEFT() IC_RESULT()
36549 \end_layout
36550
36551 \end_inset
36552 </cell>
36553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36554 \begin_inset Text
36555
36556 \begin_layout Standard
36557
36558 \size footnotesize
36559 Call via function pointer
36560 \end_layout
36561
36562 \end_inset
36563 </cell>
36564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36565 \begin_inset Text
36566
36567 \begin_layout Standard
36568
36569 \size footnotesize
36570 IC_RESULT = (*IC_LEFT)();
36571 \end_layout
36572
36573 \end_inset
36574 </cell>
36575 </row>
36576 <row topline="true">
36577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36578 \begin_inset Text
36579
36580 \begin_layout Standard
36581
36582 \size footnotesize
36583 RETURN
36584 \end_layout
36585
36586 \end_inset
36587 </cell>
36588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36589 \begin_inset Text
36590
36591 \begin_layout Standard
36592
36593 \size footnotesize
36594 IC_LEFT()
36595 \end_layout
36596
36597 \end_inset
36598 </cell>
36599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36600 \begin_inset Text
36601
36602 \begin_layout Standard
36603
36604 \size footnotesize
36605 Return the value in operand IC_LEFT 
36606 \end_layout
36607
36608 \end_inset
36609 </cell>
36610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36611 \begin_inset Text
36612
36613 \begin_layout Standard
36614
36615 \size footnotesize
36616 return IC_LEFT;
36617 \end_layout
36618
36619 \end_inset
36620 </cell>
36621 </row>
36622 <row topline="true">
36623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36624 \begin_inset Text
36625
36626 \begin_layout Standard
36627
36628 \size footnotesize
36629 LABEL
36630 \end_layout
36631
36632 \end_inset
36633 </cell>
36634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36635 \begin_inset Text
36636
36637 \begin_layout Standard
36638
36639 \size footnotesize
36640 IC_LABEL() 
36641 \end_layout
36642
36643 \end_inset
36644 </cell>
36645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36646 \begin_inset Text
36647
36648 \begin_layout Standard
36649
36650 \size footnotesize
36651 Label
36652 \end_layout
36653
36654 \end_inset
36655 </cell>
36656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36657 \begin_inset Text
36658
36659 \begin_layout Standard
36660
36661 \size footnotesize
36662 IC_LABEL:
36663 \end_layout
36664
36665 \end_inset
36666 </cell>
36667 </row>
36668 <row topline="true">
36669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36670 \begin_inset Text
36671
36672 \begin_layout Standard
36673
36674 \size footnotesize
36675 GOTO
36676 \end_layout
36677
36678 \end_inset
36679 </cell>
36680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36681 \begin_inset Text
36682
36683 \begin_layout Standard
36684
36685 \size footnotesize
36686 IC_LABEL() 
36687 \end_layout
36688
36689 \end_inset
36690 </cell>
36691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36692 \begin_inset Text
36693
36694 \begin_layout Standard
36695
36696 \size footnotesize
36697 Goto label
36698 \end_layout
36699
36700 \end_inset
36701 </cell>
36702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36703 \begin_inset Text
36704
36705 \begin_layout Standard
36706
36707 \size footnotesize
36708 goto IC_LABEL();
36709 \end_layout
36710
36711 \end_inset
36712 </cell>
36713 </row>
36714 <row topline="true">
36715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36716 \begin_inset Text
36717
36718 \begin_layout Standard
36719
36720 \size footnotesize
36721 '+'
36722 \end_layout
36723
36724 \end_inset
36725 </cell>
36726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36727 \begin_inset Text
36728
36729 \begin_layout Standard
36730
36731 \size footnotesize
36732 IC_LEFT() IC_RIGHT() IC_RESULT()
36733 \end_layout
36734
36735 \end_inset
36736 </cell>
36737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36738 \begin_inset Text
36739
36740 \begin_layout Standard
36741
36742 \size footnotesize
36743 Addition
36744 \end_layout
36745
36746 \end_inset
36747 </cell>
36748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36749 \begin_inset Text
36750
36751 \begin_layout Standard
36752
36753 \size footnotesize
36754 IC_RESULT = IC_LEFT + IC_RIGHT
36755 \end_layout
36756
36757 \end_inset
36758 </cell>
36759 </row>
36760 <row topline="true">
36761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36762 \begin_inset Text
36763
36764 \begin_layout Standard
36765
36766 \size footnotesize
36767 '-'
36768 \end_layout
36769
36770 \end_inset
36771 </cell>
36772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36773 \begin_inset Text
36774
36775 \begin_layout Standard
36776
36777 \size footnotesize
36778 IC_LEFT() IC_RIGHT() IC_RESULT()
36779 \end_layout
36780
36781 \end_inset
36782 </cell>
36783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36784 \begin_inset Text
36785
36786 \begin_layout Standard
36787
36788 \size footnotesize
36789 Subtraction
36790 \end_layout
36791
36792 \end_inset
36793 </cell>
36794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36795 \begin_inset Text
36796
36797 \begin_layout Standard
36798
36799 \size footnotesize
36800 IC_RESULT = IC_LEFT - IC_RIGHT 
36801 \end_layout
36802
36803 \end_inset
36804 </cell>
36805 </row>
36806 <row topline="true">
36807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36808 \begin_inset Text
36809
36810 \begin_layout Standard
36811
36812 \size footnotesize
36813 '*'
36814 \end_layout
36815
36816 \end_inset
36817 </cell>
36818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36819 \begin_inset Text
36820
36821 \begin_layout Standard
36822
36823 \size footnotesize
36824 IC_LEFT() IC_RIGHT() IC_RESULT()
36825 \end_layout
36826
36827 \end_inset
36828 </cell>
36829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36830 \begin_inset Text
36831
36832 \begin_layout Standard
36833
36834 \size footnotesize
36835 Multiplication 
36836 \end_layout
36837
36838 \end_inset
36839 </cell>
36840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36841 \begin_inset Text
36842
36843 \begin_layout Standard
36844
36845 \size footnotesize
36846 IC_RESULT = IC_LEFT * IC_RIGHT;
36847 \end_layout
36848
36849 \end_inset
36850 </cell>
36851 </row>
36852 <row topline="true">
36853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36854 \begin_inset Text
36855
36856 \begin_layout Standard
36857
36858 \size footnotesize
36859 '/'
36860 \end_layout
36861
36862 \end_inset
36863 </cell>
36864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36865 \begin_inset Text
36866
36867 \begin_layout Standard
36868
36869 \size footnotesize
36870 IC_LEFT() IC_RIGHT() IC_RESULT()
36871 \end_layout
36872
36873 \end_inset
36874 </cell>
36875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36876 \begin_inset Text
36877
36878 \begin_layout Standard
36879
36880 \size footnotesize
36881 Division
36882 \end_layout
36883
36884 \end_inset
36885 </cell>
36886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36887 \begin_inset Text
36888
36889 \begin_layout Standard
36890
36891 \size footnotesize
36892 IC_RESULT = IC_LEFT / IC_RIGHT;
36893 \end_layout
36894
36895 \end_inset
36896 </cell>
36897 </row>
36898 <row topline="true">
36899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36900 \begin_inset Text
36901
36902 \begin_layout Standard
36903
36904 \size footnotesize
36905 '%'
36906 \end_layout
36907
36908 \end_inset
36909 </cell>
36910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36911 \begin_inset Text
36912
36913 \begin_layout Standard
36914
36915 \size footnotesize
36916 IC_LEFT() IC_RIGHT() IC_RESULT()
36917 \end_layout
36918
36919 \end_inset
36920 </cell>
36921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36922 \begin_inset Text
36923
36924 \begin_layout Standard
36925
36926 \size footnotesize
36927 Modulus
36928 \end_layout
36929
36930 \end_inset
36931 </cell>
36932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36933 \begin_inset Text
36934
36935 \begin_layout Standard
36936
36937 \size footnotesize
36938 IC_RESULT = IC_LEFT % IC_RIGHT;
36939 \end_layout
36940
36941 \end_inset
36942 </cell>
36943 </row>
36944 <row topline="true">
36945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36946 \begin_inset Text
36947
36948 \begin_layout Standard
36949
36950 \size footnotesize
36951 '<'
36952 \end_layout
36953
36954 \end_inset
36955 </cell>
36956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36957 \begin_inset Text
36958
36959 \begin_layout Standard
36960
36961 \size footnotesize
36962 IC_LEFT() IC_RIGHT() IC_RESULT()
36963 \end_layout
36964
36965 \end_inset
36966 </cell>
36967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36968 \begin_inset Text
36969
36970 \begin_layout Standard
36971
36972 \size footnotesize
36973 Less than
36974 \end_layout
36975
36976 \end_inset
36977 </cell>
36978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36979 \begin_inset Text
36980
36981 \begin_layout Standard
36982
36983 \size footnotesize
36984 IC_RESULT = IC_LEFT < IC_RIGHT;
36985 \end_layout
36986
36987 \end_inset
36988 </cell>
36989 </row>
36990 <row topline="true">
36991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36992 \begin_inset Text
36993
36994 \begin_layout Standard
36995
36996 \size footnotesize
36997 '>'
36998 \end_layout
36999
37000 \end_inset
37001 </cell>
37002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37003 \begin_inset Text
37004
37005 \begin_layout Standard
37006
37007 \size footnotesize
37008 IC_LEFT() IC_RIGHT() IC_RESULT()
37009 \end_layout
37010
37011 \end_inset
37012 </cell>
37013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37014 \begin_inset Text
37015
37016 \begin_layout Standard
37017
37018 \size footnotesize
37019 Greater than 
37020 \end_layout
37021
37022 \end_inset
37023 </cell>
37024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37025 \begin_inset Text
37026
37027 \begin_layout Standard
37028
37029 \size footnotesize
37030 IC_RESULT = IC_LEFT > IC_RIGHT;
37031 \end_layout
37032
37033 \end_inset
37034 </cell>
37035 </row>
37036 <row topline="true">
37037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37038 \begin_inset Text
37039
37040 \begin_layout Standard
37041
37042 \size footnotesize
37043 EQ_OP
37044 \end_layout
37045
37046 \end_inset
37047 </cell>
37048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37049 \begin_inset Text
37050
37051 \begin_layout Standard
37052
37053 \size footnotesize
37054 IC_LEFT() IC_RIGHT() IC_RESULT()
37055 \end_layout
37056
37057 \end_inset
37058 </cell>
37059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37060 \begin_inset Text
37061
37062 \begin_layout Standard
37063
37064 \size footnotesize
37065 Equal to 
37066 \end_layout
37067
37068 \end_inset
37069 </cell>
37070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37071 \begin_inset Text
37072
37073 \begin_layout Standard
37074
37075 \size footnotesize
37076 IC_RESULT = IC_LEFT == IC_RIGHT;
37077 \end_layout
37078
37079 \end_inset
37080 </cell>
37081 </row>
37082 <row topline="true">
37083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37084 \begin_inset Text
37085
37086 \begin_layout Standard
37087
37088 \size footnotesize
37089 AND_OP
37090 \end_layout
37091
37092 \end_inset
37093 </cell>
37094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37095 \begin_inset Text
37096
37097 \begin_layout Standard
37098
37099 \size footnotesize
37100 IC_LEFT() IC_RIGHT() IC_RESULT() 
37101 \end_layout
37102
37103 \end_inset
37104 </cell>
37105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37106 \begin_inset Text
37107
37108 \begin_layout Standard
37109
37110 \size footnotesize
37111 Logical and operation
37112 \end_layout
37113
37114 \end_inset
37115 </cell>
37116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37117 \begin_inset Text
37118
37119 \begin_layout Standard
37120
37121 \size footnotesize
37122 IC_RESULT = IC_LEFT && IC_RIGHT; 
37123 \end_layout
37124
37125 \end_inset
37126 </cell>
37127 </row>
37128 <row topline="true">
37129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37130 \begin_inset Text
37131
37132 \begin_layout Standard
37133
37134 \size footnotesize
37135 OR_OP
37136 \end_layout
37137
37138 \end_inset
37139 </cell>
37140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37141 \begin_inset Text
37142
37143 \begin_layout Standard
37144
37145 \size footnotesize
37146 IC_LEFT() IC_RIGHT() IC_RESULT() 
37147 \end_layout
37148
37149 \end_inset
37150 </cell>
37151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37152 \begin_inset Text
37153
37154 \begin_layout Standard
37155
37156 \size footnotesize
37157 Logical or operation 
37158 \end_layout
37159
37160 \end_inset
37161 </cell>
37162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37163 \begin_inset Text
37164
37165 \begin_layout Standard
37166
37167 \size footnotesize
37168 IC_RESULT = IC_LEFT || IC_RIGHT; 
37169 \end_layout
37170
37171 \end_inset
37172 </cell>
37173 </row>
37174 <row topline="true">
37175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37176 \begin_inset Text
37177
37178 \begin_layout Standard
37179
37180 \size footnotesize
37181 '^'
37182 \end_layout
37183
37184 \end_inset
37185 </cell>
37186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37187 \begin_inset Text
37188
37189 \begin_layout Standard
37190
37191 \size footnotesize
37192 IC_LEFT() IC_RIGHT() IC_RESULT() 
37193 \end_layout
37194
37195 \end_inset
37196 </cell>
37197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37198 \begin_inset Text
37199
37200 \begin_layout Standard
37201
37202 \size footnotesize
37203 Exclusive OR
37204 \end_layout
37205
37206 \end_inset
37207 </cell>
37208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37209 \begin_inset Text
37210
37211 \begin_layout Standard
37212
37213 \size footnotesize
37214 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37215 \end_layout
37216
37217 \end_inset
37218 </cell>
37219 </row>
37220 <row topline="true">
37221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37222 \begin_inset Text
37223
37224 \begin_layout Standard
37225
37226 \size footnotesize
37227 '|'
37228 \end_layout
37229
37230 \end_inset
37231 </cell>
37232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37233 \begin_inset Text
37234
37235 \begin_layout Standard
37236
37237 \size footnotesize
37238 IC_LEFT() IC_RIGHT() IC_RESULT() 
37239 \end_layout
37240
37241 \end_inset
37242 </cell>
37243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37244 \begin_inset Text
37245
37246 \begin_layout Standard
37247
37248 \size footnotesize
37249 Bitwise OR 
37250 \end_layout
37251
37252 \end_inset
37253 </cell>
37254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37255 \begin_inset Text
37256
37257 \begin_layout Standard
37258
37259 \size footnotesize
37260 IC_RESULT = IC_LEFT | IC_RIGHT;
37261 \end_layout
37262
37263 \end_inset
37264 </cell>
37265 </row>
37266 <row topline="true">
37267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37268 \begin_inset Text
37269
37270 \begin_layout Standard
37271
37272 \size footnotesize
37273 BITWISEAND
37274 \end_layout
37275
37276 \end_inset
37277 </cell>
37278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37279 \begin_inset Text
37280
37281 \begin_layout Standard
37282
37283 \size footnotesize
37284 IC_LEFT() IC_RIGHT() IC_RESULT()
37285 \end_layout
37286
37287 \end_inset
37288 </cell>
37289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37290 \begin_inset Text
37291
37292 \begin_layout Standard
37293
37294 \size footnotesize
37295 Bitwise AND 
37296 \end_layout
37297
37298 \end_inset
37299 </cell>
37300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37301 \begin_inset Text
37302
37303 \begin_layout Standard
37304
37305 \size footnotesize
37306 IC_RESULT = IC_LEFT & IC_RIGHT;
37307 \end_layout
37308
37309 \end_inset
37310 </cell>
37311 </row>
37312 <row topline="true">
37313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37314 \begin_inset Text
37315
37316 \begin_layout Standard
37317
37318 \size footnotesize
37319 LEFT_OP
37320 \end_layout
37321
37322 \end_inset
37323 </cell>
37324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37325 \begin_inset Text
37326
37327 \begin_layout Standard
37328
37329 \size footnotesize
37330 IC_LEFT() IC_RIGHT() IC_RESULT()
37331 \end_layout
37332
37333 \end_inset
37334 </cell>
37335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37336 \begin_inset Text
37337
37338 \begin_layout Standard
37339
37340 \size footnotesize
37341 Left shift 
37342 \end_layout
37343
37344 \end_inset
37345 </cell>
37346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37347 \begin_inset Text
37348
37349 \begin_layout Standard
37350
37351 \size footnotesize
37352 IC_RESULT = IC_LEFT << IC_RIGHT 
37353 \end_layout
37354
37355 \end_inset
37356 </cell>
37357 </row>
37358 <row topline="true">
37359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37360 \begin_inset Text
37361
37362 \begin_layout Standard
37363
37364 \size footnotesize
37365 RIGHT_OP
37366 \end_layout
37367
37368 \end_inset
37369 </cell>
37370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37371 \begin_inset Text
37372
37373 \begin_layout Standard
37374
37375 \size footnotesize
37376 IC_LEFT() IC_RIGHT() IC_RESULT()
37377 \end_layout
37378
37379 \end_inset
37380 </cell>
37381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37382 \begin_inset Text
37383
37384 \begin_layout Standard
37385
37386 \size footnotesize
37387 Right shift
37388 \end_layout
37389
37390 \end_inset
37391 </cell>
37392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37393 \begin_inset Text
37394
37395 \begin_layout Standard
37396
37397 \size footnotesize
37398 IC_RESULT = IC_LEFT >> IC_RIGHT 
37399 \end_layout
37400
37401 \end_inset
37402 </cell>
37403 </row>
37404 <row topline="true">
37405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37406 \begin_inset Text
37407
37408 \begin_layout Standard
37409
37410 \size footnotesize
37411 GET_VALUE_
37412 \newline
37413 AT_ ADDRESS
37414 \end_layout
37415
37416 \end_inset
37417 </cell>
37418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37419 \begin_inset Text
37420
37421 \begin_layout Standard
37422
37423 \size footnotesize
37424 IC_LEFT() IC_RESULT()
37425 \end_layout
37426
37427 \end_inset
37428 </cell>
37429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37430 \begin_inset Text
37431
37432 \begin_layout Standard
37433
37434 \size footnotesize
37435 Indirect fetch 
37436 \end_layout
37437
37438 \end_inset
37439 </cell>
37440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37441 \begin_inset Text
37442
37443 \begin_layout Standard
37444
37445 \size footnotesize
37446 IC_RESULT = (*IC_LEFT);
37447 \end_layout
37448
37449 \end_inset
37450 </cell>
37451 </row>
37452 <row topline="true">
37453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37454 \begin_inset Text
37455
37456 \begin_layout Standard
37457
37458 \size footnotesize
37459 POINTER_SET
37460 \end_layout
37461
37462 \end_inset
37463 </cell>
37464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37465 \begin_inset Text
37466
37467 \begin_layout Standard
37468
37469 \size footnotesize
37470 IC_RIGHT() IC_RESULT() 
37471 \end_layout
37472
37473 \end_inset
37474 </cell>
37475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37476 \begin_inset Text
37477
37478 \begin_layout Standard
37479
37480 \size footnotesize
37481 Indirect set
37482 \end_layout
37483
37484 \end_inset
37485 </cell>
37486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37487 \begin_inset Text
37488
37489 \begin_layout Standard
37490
37491 \size footnotesize
37492 (*IC_RESULT) = IC_RIGHT;
37493 \end_layout
37494
37495 \end_inset
37496 </cell>
37497 </row>
37498 <row topline="true">
37499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37500 \begin_inset Text
37501
37502 \begin_layout Standard
37503
37504 \size footnotesize
37505 '='
37506 \end_layout
37507
37508 \end_inset
37509 </cell>
37510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37511 \begin_inset Text
37512
37513 \begin_layout Standard
37514
37515 \size footnotesize
37516 IC_RIGHT() IC_RESULT()
37517 \end_layout
37518
37519 \end_inset
37520 </cell>
37521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37522 \begin_inset Text
37523
37524 \begin_layout Standard
37525
37526 \size footnotesize
37527 Assignment
37528 \end_layout
37529
37530 \end_inset
37531 </cell>
37532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37533 \begin_inset Text
37534
37535 \begin_layout Standard
37536
37537 \size footnotesize
37538 IC_RESULT = IC_RIGHT;
37539 \end_layout
37540
37541 \end_inset
37542 </cell>
37543 </row>
37544 <row topline="true">
37545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37546 \begin_inset Text
37547
37548 \begin_layout Standard
37549
37550 \size footnotesize
37551 IFX
37552 \end_layout
37553
37554 \end_inset
37555 </cell>
37556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37557 \begin_inset Text
37558
37559 \begin_layout Standard
37560
37561 \size footnotesize
37562 IC_COND IC_TRUE IC_LABEL
37563 \end_layout
37564
37565 \end_inset
37566 </cell>
37567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37568 \begin_inset Text
37569
37570 \begin_layout Standard
37571
37572 \size footnotesize
37573 Conditional jump.
37574  If true label is present then jump to true label if condition is true else
37575  jump to false label if condition is false 
37576 \end_layout
37577
37578 \end_inset
37579 </cell>
37580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37581 \begin_inset Text
37582
37583 \begin_layout Standard
37584
37585 \size footnotesize
37586 if (IC_COND) goto IC_TRUE; 
37587 \newline
37588 \InsetSpace ~
37589 \InsetSpace ~
37590 Or 
37591 \newline
37592 If (!IC_COND) goto IC_FALSE;
37593 \end_layout
37594
37595 \end_inset
37596 </cell>
37597 </row>
37598 <row topline="true">
37599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37600 \begin_inset Text
37601
37602 \begin_layout Standard
37603
37604 \size footnotesize
37605 ADDRESS_OF
37606 \end_layout
37607
37608 \end_inset
37609 </cell>
37610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37611 \begin_inset Text
37612
37613 \begin_layout Standard
37614
37615 \size footnotesize
37616 IC_LEFT() IC_RESULT()
37617 \end_layout
37618
37619 \end_inset
37620 </cell>
37621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37622 \begin_inset Text
37623
37624 \begin_layout Standard
37625
37626 \size footnotesize
37627 Address of 
37628 \end_layout
37629
37630 \end_inset
37631 </cell>
37632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37633 \begin_inset Text
37634
37635 \begin_layout Standard
37636
37637 \size footnotesize
37638 IC_RESULT = &IC_LEFT();
37639 \end_layout
37640
37641 \end_inset
37642 </cell>
37643 </row>
37644 <row topline="true">
37645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37646 \begin_inset Text
37647
37648 \begin_layout Standard
37649
37650 \size footnotesize
37651 JUMPTABLE
37652 \end_layout
37653
37654 \end_inset
37655 </cell>
37656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37657 \begin_inset Text
37658
37659 \begin_layout Standard
37660
37661 \size footnotesize
37662 IC_JTCOND IC_JTLABELS
37663 \end_layout
37664
37665 \end_inset
37666 </cell>
37667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37668 \begin_inset Text
37669
37670 \begin_layout Standard
37671
37672 \size footnotesize
37673 Jump to list of labels depending on the value of JTCOND
37674 \end_layout
37675
37676 \end_inset
37677 </cell>
37678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37679 \begin_inset Text
37680
37681 \begin_layout Standard
37682
37683 \size footnotesize
37684 Switch statement
37685 \end_layout
37686
37687 \end_inset
37688 </cell>
37689 </row>
37690 <row topline="true">
37691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37692 \begin_inset Text
37693
37694 \begin_layout Standard
37695
37696 \size footnotesize
37697 CAST
37698 \end_layout
37699
37700 \end_inset
37701 </cell>
37702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37703 \begin_inset Text
37704
37705 \begin_layout Standard
37706
37707 \size footnotesize
37708 IC_RIGHT() IC_LEFT() IC_RESULT()
37709 \end_layout
37710
37711 \end_inset
37712 </cell>
37713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37714 \begin_inset Text
37715
37716 \begin_layout Standard
37717
37718 \size footnotesize
37719 Cast types 
37720 \end_layout
37721
37722 \end_inset
37723 </cell>
37724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37725 \begin_inset Text
37726
37727 \begin_layout Standard
37728
37729 \size footnotesize
37730 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37731 \end_layout
37732
37733 \end_inset
37734 </cell>
37735 </row>
37736 <row topline="true">
37737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37738 \begin_inset Text
37739
37740 \begin_layout Standard
37741
37742 \size footnotesize
37743 SEND
37744 \end_layout
37745
37746 \end_inset
37747 </cell>
37748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37749 \begin_inset Text
37750
37751 \begin_layout Standard
37752
37753 \size footnotesize
37754 IC_LEFT()
37755 \end_layout
37756
37757 \end_inset
37758 </cell>
37759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37760 \begin_inset Text
37761
37762 \begin_layout Standard
37763
37764 \size footnotesize
37765 This is used for passing parameters in registers; 
37766 \newline
37767 move IC_LEFT to the next
37768  available parameter register.
37769 \end_layout
37770
37771 \end_inset
37772 </cell>
37773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37774 \begin_inset Text
37775
37776 \begin_layout Standard
37777
37778 \size footnotesize
37779 None
37780 \end_layout
37781
37782 \end_inset
37783 </cell>
37784 </row>
37785 <row topline="true">
37786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37787 \begin_inset Text
37788
37789 \begin_layout Standard
37790
37791 \size footnotesize
37792 RECV
37793 \end_layout
37794
37795 \end_inset
37796 </cell>
37797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37798 \begin_inset Text
37799
37800 \begin_layout Standard
37801
37802 \size footnotesize
37803 IC_RESULT()
37804 \end_layout
37805
37806 \end_inset
37807 </cell>
37808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37809 \begin_inset Text
37810
37811 \begin_layout Standard
37812
37813 \size footnotesize
37814 This is used for receiving parameters passed in registers;
37815 \newline
37816 Move the values
37817  in the next parameter register to IC_RESULT 
37818 \end_layout
37819
37820 \end_inset
37821 </cell>
37822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37823 \begin_inset Text
37824
37825 \begin_layout Standard
37826
37827 \size footnotesize
37828 None
37829 \end_layout
37830
37831 \end_inset
37832 </cell>
37833 </row>
37834 <row topline="true" bottomline="true">
37835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37836 \begin_inset Text
37837
37838 \begin_layout Standard
37839
37840 \shape slanted
37841 \size footnotesize
37842 (some more have been added)
37843 \end_layout
37844
37845 \end_inset
37846 </cell>
37847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37848 \begin_inset Text
37849
37850 \begin_layout Standard
37851
37852 \end_layout
37853
37854 \end_inset
37855 </cell>
37856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37857 \begin_inset Text
37858
37859 \begin_layout Standard
37860
37861 \end_layout
37862
37863 \end_inset
37864 </cell>
37865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37866 \begin_inset Text
37867
37868 \begin_layout Standard
37869
37870 \shape slanted
37871 \size footnotesize
37872 see f.e.
37873  
37874 \family typewriter
37875 gen51Code()
37876 \family default
37877  in 
37878 \family typewriter
37879 src/mcs51/gen.c
37880 \end_layout
37881
37882 \end_inset
37883 </cell>
37884 </row>
37885 </lyxtabular>
37886
37887 \end_inset
37888
37889
37890 \end_layout
37891
37892 \begin_layout Standard
37893 \begin_inset Note Note
37894 status collapsed
37895
37896 \begin_layout Standard
37897 In the original article Figure II was announced to be downloadable on 
37898 \shape italic
37899 Circuit Cellar
37900 \shape default
37901 's web site.
37902  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37903 \end_layout
37904
37905 \end_inset
37906
37907
37908 \end_layout
37909
37910 \begin_layout Paragraph*
37911 ICode Example
37912 \begin_inset LatexCommand \index{iCode}
37913
37914 \end_inset
37915
37916
37917 \end_layout
37918
37919 \begin_layout Standard
37920 This section shows some details of iCode.
37921  The example C code does not do anything useful; it is used as an example
37922  to illustrate the intermediate code generated by the compiler.
37923 \end_layout
37924
37925 \begin_layout Verse
37926
37927 \family typewriter
37928 1.\InsetSpace ~
37929 xdata int * p;
37930 \newline
37931 2.\InsetSpace ~
37932 int gint;
37933 \newline
37934 3.\InsetSpace ~
37935 /* This function does nothing useful.
37936  It is used
37937 \newline
37938 4.\InsetSpace ~
37939 \InsetSpace ~
37940 \InsetSpace ~
37941 \InsetSpace ~
37942 for the purpose of explaining iCode */
37943 \newline
37944 5.\InsetSpace ~
37945 short function (data
37946  int *x)
37947 \newline
37948 6.\InsetSpace ~
37949 {
37950 \newline
37951 7.\InsetSpace ~
37952 \InsetSpace ~
37953 \InsetSpace ~
37954 short i=10; \InsetSpace ~
37955 \InsetSpace ~
37956 /* dead initialization eliminated */
37957 \newline
37958 8.\InsetSpace ~
37959 \InsetSpace ~
37960 \InsetSpace ~
37961 short sum=10;
37962  /* dead initialization eliminated */
37963 \newline
37964 9.\InsetSpace ~
37965 \InsetSpace ~
37966 \InsetSpace ~
37967 short mul;
37968 \newline
37969 10.\InsetSpace ~
37970 \InsetSpace ~
37971 int j ;
37972 \newline
37973 11.\InsetSpace ~
37974 \InsetSpace ~
37975 while (*x) *x++
37976  = *p++; 
37977 \newline
37978 12.\InsetSpace ~
37979 \InsetSpace ~
37980 \InsetSpace ~
37981 \InsetSpace ~
37982 sum = 0 ; 
37983 \newline
37984 13.\InsetSpace ~
37985 \InsetSpace ~
37986 mul = 0;
37987 \newline
37988 14.\InsetSpace ~
37989 \InsetSpace ~
37990 /* compiler detects i,j to be induction
37991  variables */
37992 \newline
37993 15.\InsetSpace ~
37994 \InsetSpace ~
37995 for (i = 0, j = 10 ; i < 10 ; i++, j
37996 \family default
37997 -
37998 \begin_inset ERT
37999 status collapsed
38000
38001 \begin_layout Standard
38002
38003
38004 \backslash
38005 /
38006 \end_layout
38007
38008 \end_inset
38009
38010 -
38011 \family typewriter
38012 ) {
38013 \newline
38014 16.\InsetSpace ~
38015 \InsetSpace ~
38016 \InsetSpace ~
38017 \InsetSpace ~
38018 sum += i;
38019 \newline
38020 17.\InsetSpace ~
38021 \InsetSpace ~
38022 \InsetSpace ~
38023 \InsetSpace ~
38024 mul += i * 3; \InsetSpace ~
38025 \InsetSpace ~
38026 /* this multiplication remains */
38027 \newline
38028 18.\InsetSpace ~
38029 \InsetSpace ~
38030 \InsetSpace ~
38031 \InsetSpace ~
38032 gint +=
38033  j * 3;\InsetSpace ~
38034 \InsetSpace ~
38035 /* this multiplication changed to addition */
38036 \newline
38037 19.\InsetSpace ~
38038 \InsetSpace ~
38039 }
38040 \newline
38041 20.\InsetSpace ~
38042 \InsetSpace ~
38043 return sum+mul;
38044 \newline
38045 21.\InsetSpace ~
38046 }
38047 \end_layout
38048
38049 \begin_layout Standard
38050 In addition to the operands each iCode contains information about the filename
38051  and line it corresponds to in the source file.
38052  The first field in the listing should be interpreted as follows:
38053 \newline
38054
38055 \shape italic
38056 \size footnotesize
38057 Filename(linenumber: iCode Execution sequence number : ICode hash table
38058  key : loop depth of the iCode).
38059 \shape default
38060 \size default
38061
38062 \newline
38063 Then follows the human readable form of the ICode operation.
38064  Each operand of this triplet form can be of three basic types a) compiler
38065  generated temporary b) user defined variable c) a constant value.
38066  Note that local variables and parameters are replaced by compiler generated
38067  temporaries.
38068  Live ranges
38069 \begin_inset LatexCommand \index{Live range analysis}
38070
38071 \end_inset
38072
38073  are computed only for temporaries (i.e.
38074  live ranges are not computed for global variables).
38075  Registers
38076 \begin_inset LatexCommand \index{Register allocation}
38077
38078 \end_inset
38079
38080  are allocated for temporaries only.
38081  Operands are formatted in the following manner:
38082 \newline
38083
38084 \shape italic
38085 \size footnotesize
38086 Operand Name [lr live-from : live-to ] { type information } [ registers
38087  allocated ].
38088 \shape default
38089 \size default
38090
38091 \newline
38092 As mentioned earlier the live ranges are computed in terms of the execution
38093  sequence number of the iCodes, for example 
38094 \newline
38095 the iTemp0 is live from (i.e.
38096  first defined in iCode with execution sequence number 3, and is last used
38097  in the iCode with sequence number 5).
38098  For induction variables such as iTemp21 the live range computation extends
38099  the lifetime from the start to the end of the loop.
38100 \newline
38101 The register allocator
38102  used the live range information to allocate registers, the same registers
38103  may be used for different temporaries if their live ranges do not overlap,
38104  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38105  ranges do not overlap.
38106  In addition the allocator also takes into consideration the type and usage
38107  of a temporary, for example itemp6 is a pointer to near space and is used
38108  as to fetch data from (i.e.
38109  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38110  Some short lived temporaries are allocated to special registers which have
38111  meaning to the code generator e.g.
38112  iTemp13 is allocated to a pseudo register CC which tells the back end that
38113  the temporary is used only for a conditional jump the code generation makes
38114  use of this information to optimize a compare and jump ICode.
38115 \newline
38116 There are several
38117  loop optimizations
38118 \begin_inset LatexCommand \index{Loop optimization}
38119
38120 \end_inset
38121
38122  performed by the compiler.
38123  It can detect induction variables iTemp21(i) and iTemp23(j).
38124  Also note the compiler does selective strength reduction
38125 \begin_inset LatexCommand \index{Strength reduction}
38126
38127 \end_inset
38128
38129 , i.e.
38130  the multiplication of an induction variable in line 18 (gint = j * 3) is
38131  changed to addition, a new temporary iTemp17 is allocated and assigned
38132  a initial value, a constant 3 is then added for each iteration of the loop.
38133  The compiler does not change the multiplication
38134 \begin_inset LatexCommand \index{Multiplication}
38135
38136 \end_inset
38137
38138  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38139 \newline
38140
38141 Note the dead code elimination
38142 \begin_inset LatexCommand \index{Dead-code elimination}
38143
38144 \end_inset
38145
38146  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38147  respectively.
38148 \newline
38149
38150 \end_layout
38151
38152 \begin_layout Standard
38153
38154 \size footnotesize
38155 Sample.c (5:1:0:0) _entry($9) :
38156 \end_layout
38157
38158 \begin_layout Standard
38159
38160 \size footnotesize
38161 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38162 \end_layout
38163
38164 \begin_layout Standard
38165
38166 \size footnotesize
38167 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38168 \end_layout
38169
38170 \begin_layout Standard
38171
38172 \size footnotesize
38173 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38174 \end_layout
38175
38176 \begin_layout Standard
38177
38178 \size footnotesize
38179 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38180  * int}[r2]
38181 \end_layout
38182
38183 \begin_layout Standard
38184
38185 \size footnotesize
38186 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38187 \end_layout
38188
38189 \begin_layout Standard
38190
38191 \size footnotesize
38192 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38193  int}[r0]]
38194 \end_layout
38195
38196 \begin_layout Standard
38197
38198 \size footnotesize
38199 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38200 \end_layout
38201
38202 \begin_layout Standard
38203
38204 \size footnotesize
38205 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38206  * int}
38207 \end_layout
38208
38209 \begin_layout Standard
38210
38211 \size footnotesize
38212 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38213  {short}
38214 \end_layout
38215
38216 \begin_layout Standard
38217
38218 \size footnotesize
38219 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38220  * int}[DPTR]]
38221 \end_layout
38222
38223 \begin_layout Standard
38224
38225 \size footnotesize
38226 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38227 }[r2 r3]
38228 \end_layout
38229
38230 \begin_layout Standard
38231
38232 \size footnotesize
38233 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38234  * int}[r0] + 0x2 {short}
38235 \end_layout
38236
38237 \begin_layout Standard
38238
38239 \size footnotesize
38240 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38241 \end_layout
38242
38243 \begin_layout Standard
38244
38245 \size footnotesize
38246 Sample.c(11:17:21:0)_whilebreak_0($3) :
38247 \end_layout
38248
38249 \begin_layout Standard
38250
38251 \size footnotesize
38252 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38253 \end_layout
38254
38255 \begin_layout Standard
38256
38257 \size footnotesize
38258 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38259 \end_layout
38260
38261 \begin_layout Standard
38262
38263 \size footnotesize
38264 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38265 \end_layout
38266
38267 \begin_layout Standard
38268
38269 \size footnotesize
38270 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38271 \end_layout
38272
38273 \begin_layout Standard
38274
38275 \size footnotesize
38276 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38277 \end_layout
38278
38279 \begin_layout Standard
38280
38281 \size footnotesize
38282 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38283 \end_layout
38284
38285 \begin_layout Standard
38286
38287 \size footnotesize
38288 Sample.c(15:24:26:1)_forcond_0($4) :
38289 \end_layout
38290
38291 \begin_layout Standard
38292
38293 \size footnotesize
38294 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38295  < 0xa {short}
38296 \end_layout
38297
38298 \begin_layout Standard
38299
38300 \size footnotesize
38301 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38302 \end_layout
38303
38304 \begin_layout Standard
38305
38306 \size footnotesize
38307 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38308  + ITemp21 [lr21:38]{short}[r4]
38309 \end_layout
38310
38311 \begin_layout Standard
38312
38313 \size footnotesize
38314 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38315  * 0x3 {short}
38316 \end_layout
38317
38318 \begin_layout Standard
38319
38320 \size footnotesize
38321 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38322  + iTemp15 [lr29:30]{short}[r1]
38323 \end_layout
38324
38325 \begin_layout Standard
38326
38327 \size footnotesize
38328 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38329  r0]- 0x3 {short}
38330 \end_layout
38331
38332 \begin_layout Standard
38333
38334 \size footnotesize
38335 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38336 int}[r7 r0]
38337 \end_layout
38338
38339 \begin_layout Standard
38340
38341 \size footnotesize
38342 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38343  + 0x1 {short}
38344 \end_layout
38345
38346 \begin_layout Standard
38347
38348 \size footnotesize
38349 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38350  r6]- 0x1 {short}
38351 \end_layout
38352
38353 \begin_layout Standard
38354
38355 \size footnotesize
38356 Sample.c(19:38:47:1) goto _forcond_0($4)
38357 \end_layout
38358
38359 \begin_layout Standard
38360
38361 \size footnotesize
38362 Sample.c(19:39:48:0)_forbreak_0($7) :
38363 \end_layout
38364
38365 \begin_layout Standard
38366
38367 \size footnotesize
38368 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38369  + ITemp11 [lr19:40]{short}[r3]
38370 \end_layout
38371
38372 \begin_layout Standard
38373
38374 \size footnotesize
38375 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38376 \end_layout
38377
38378 \begin_layout Standard
38379
38380 \size footnotesize
38381 Sample.c(20:42:51:0)_return($8) :
38382 \end_layout
38383
38384 \begin_layout Standard
38385
38386 \size footnotesize
38387 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38388 \size default
38389
38390 \newline
38391
38392 \newline
38393 Finally the code generated for this function:
38394 \newline
38395
38396 \end_layout
38397
38398 \begin_layout Standard
38399
38400 \size footnotesize
38401 .area DSEG (DATA)
38402 \end_layout
38403
38404 \begin_layout Standard
38405
38406 \size footnotesize
38407 _p::
38408 \end_layout
38409
38410 \begin_layout Standard
38411
38412 \size footnotesize
38413 \InsetSpace ~
38414 \InsetSpace ~
38415 .ds 2
38416 \end_layout
38417
38418 \begin_layout Standard
38419
38420 \size footnotesize
38421 _gint::
38422 \end_layout
38423
38424 \begin_layout Standard
38425
38426 \size footnotesize
38427 \InsetSpace ~
38428 \InsetSpace ~
38429 .ds 2
38430 \end_layout
38431
38432 \begin_layout Standard
38433
38434 \size footnotesize
38435 ; sample.c 5
38436 \end_layout
38437
38438 \begin_layout Standard
38439
38440 \size footnotesize
38441 ; ----------------------------------------------
38442 \end_layout
38443
38444 \begin_layout Standard
38445
38446 \size footnotesize
38447 ; function function
38448 \end_layout
38449
38450 \begin_layout Standard
38451
38452 \size footnotesize
38453 ; ----------------------------------------------
38454 \end_layout
38455
38456 \begin_layout Standard
38457
38458 \size footnotesize
38459 _function:
38460 \end_layout
38461
38462 \begin_layout Standard
38463
38464 \size footnotesize
38465 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38466 \end_layout
38467
38468 \begin_layout Standard
38469
38470 \size footnotesize
38471 \InsetSpace ~
38472 \InsetSpace ~
38473 mov r2,dpl
38474 \end_layout
38475
38476 \begin_layout Standard
38477
38478 \size footnotesize
38479 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38480 \end_layout
38481
38482 \begin_layout Standard
38483
38484 \size footnotesize
38485 \InsetSpace ~
38486 \InsetSpace ~
38487 mov ar0,r2
38488 \end_layout
38489
38490 \begin_layout Standard
38491
38492 \size footnotesize
38493 ;_whilecontinue_0($1) :
38494 \end_layout
38495
38496 \begin_layout Standard
38497
38498 \size footnotesize
38499 00101$:
38500 \end_layout
38501
38502 \begin_layout Standard
38503
38504 \size footnotesize
38505 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38506 \end_layout
38507
38508 \begin_layout Standard
38509
38510 \size footnotesize
38511 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38512 \end_layout
38513
38514 \begin_layout Standard
38515
38516 \size footnotesize
38517 \InsetSpace ~
38518 \InsetSpace ~
38519 mov ar2,@r0
38520 \end_layout
38521
38522 \begin_layout Standard
38523
38524 \size footnotesize
38525 \InsetSpace ~
38526 \InsetSpace ~
38527 inc r0
38528 \end_layout
38529
38530 \begin_layout Standard
38531
38532 \size footnotesize
38533 \InsetSpace ~
38534 \InsetSpace ~
38535 mov ar3,@r0
38536 \end_layout
38537
38538 \begin_layout Standard
38539
38540 \size footnotesize
38541 \InsetSpace ~
38542 \InsetSpace ~
38543 dec r0
38544 \end_layout
38545
38546 \begin_layout Standard
38547
38548 \size footnotesize
38549 \InsetSpace ~
38550 \InsetSpace ~
38551 mov a,r2
38552 \end_layout
38553
38554 \begin_layout Standard
38555
38556 \size footnotesize
38557 \InsetSpace ~
38558 \InsetSpace ~
38559 orl a,r3
38560 \end_layout
38561
38562 \begin_layout Standard
38563
38564 \size footnotesize
38565 \InsetSpace ~
38566 \InsetSpace ~
38567 jz 00103$
38568 \end_layout
38569
38570 \begin_layout Standard
38571
38572 \size footnotesize
38573 00114$:
38574 \end_layout
38575
38576 \begin_layout Standard
38577
38578 \size footnotesize
38579 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38580 \end_layout
38581
38582 \begin_layout Standard
38583
38584 \size footnotesize
38585 \InsetSpace ~
38586 \InsetSpace ~
38587 mov dpl,_p
38588 \end_layout
38589
38590 \begin_layout Standard
38591
38592 \size footnotesize
38593 \InsetSpace ~
38594 \InsetSpace ~
38595 mov dph,(_p + 1)
38596 \end_layout
38597
38598 \begin_layout Standard
38599
38600 \size footnotesize
38601 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38602 \end_layout
38603
38604 \begin_layout Standard
38605
38606 \size footnotesize
38607 \InsetSpace ~
38608 \InsetSpace ~
38609 mov a,#0x02
38610 \end_layout
38611
38612 \begin_layout Standard
38613
38614 \size footnotesize
38615 \InsetSpace ~
38616 \InsetSpace ~
38617 add a,_p
38618 \end_layout
38619
38620 \begin_layout Standard
38621
38622 \size footnotesize
38623 \InsetSpace ~
38624 \InsetSpace ~
38625 mov _p,a
38626 \end_layout
38627
38628 \begin_layout Standard
38629
38630 \size footnotesize
38631 \InsetSpace ~
38632 \InsetSpace ~
38633 clr a
38634 \end_layout
38635
38636 \begin_layout Standard
38637
38638 \size footnotesize
38639 \InsetSpace ~
38640 \InsetSpace ~
38641 addc a,(_p + 1)
38642 \end_layout
38643
38644 \begin_layout Standard
38645
38646 \size footnotesize
38647 \InsetSpace ~
38648 \InsetSpace ~
38649 mov (_p + 1),a
38650 \end_layout
38651
38652 \begin_layout Standard
38653
38654 \size footnotesize
38655 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38656 \end_layout
38657
38658 \begin_layout Standard
38659
38660 \size footnotesize
38661 \InsetSpace ~
38662 \InsetSpace ~
38663 movx a,@dptr
38664 \end_layout
38665
38666 \begin_layout Standard
38667
38668 \size footnotesize
38669 \InsetSpace ~
38670 \InsetSpace ~
38671 mov r2,a
38672 \end_layout
38673
38674 \begin_layout Standard
38675
38676 \size footnotesize
38677 \InsetSpace ~
38678 \InsetSpace ~
38679 inc dptr
38680 \end_layout
38681
38682 \begin_layout Standard
38683
38684 \size footnotesize
38685 \InsetSpace ~
38686 \InsetSpace ~
38687 movx a,@dptr
38688 \end_layout
38689
38690 \begin_layout Standard
38691
38692 \size footnotesize
38693 \InsetSpace ~
38694 \InsetSpace ~
38695 mov r3,a
38696 \end_layout
38697
38698 \begin_layout Standard
38699
38700 \size footnotesize
38701 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38702 \end_layout
38703
38704 \begin_layout Standard
38705
38706 \size footnotesize
38707 \InsetSpace ~
38708 \InsetSpace ~
38709 mov @r0,ar2
38710 \end_layout
38711
38712 \begin_layout Standard
38713
38714 \size footnotesize
38715 \InsetSpace ~
38716 \InsetSpace ~
38717 inc r0
38718 \end_layout
38719
38720 \begin_layout Standard
38721
38722 \size footnotesize
38723 \InsetSpace ~
38724 \InsetSpace ~
38725 mov @r0,ar3
38726 \end_layout
38727
38728 \begin_layout Standard
38729
38730 \size footnotesize
38731 ; iTemp6 [lr5:16]{_near * int}[r0] = 
38732 \end_layout
38733
38734 \begin_layout Standard
38735
38736 \size footnotesize
38737 ; iTemp6 [lr5:16]{_near * int}[r0] + 
38738 \end_layout
38739
38740 \begin_layout Standard
38741
38742 \size footnotesize
38743 ; 0x2 {short}
38744 \end_layout
38745
38746 \begin_layout Standard
38747
38748 \size footnotesize
38749 \InsetSpace ~
38750 \InsetSpace ~
38751 inc r0
38752 \end_layout
38753
38754 \begin_layout Standard
38755
38756 \size footnotesize
38757 ; goto _whilecontinue_0($1)
38758 \end_layout
38759
38760 \begin_layout Standard
38761
38762 \size footnotesize
38763 \InsetSpace ~
38764 \InsetSpace ~
38765 sjmp 00101$
38766 \end_layout
38767
38768 \begin_layout Standard
38769
38770 \size footnotesize
38771 ; _whilebreak_0($3) :
38772 \end_layout
38773
38774 \begin_layout Standard
38775
38776 \size footnotesize
38777 00103$:
38778 \end_layout
38779
38780 \begin_layout Standard
38781
38782 \size footnotesize
38783 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38784 \end_layout
38785
38786 \begin_layout Standard
38787
38788 \size footnotesize
38789 \InsetSpace ~
38790 \InsetSpace ~
38791 mov r2,#0x00
38792 \end_layout
38793
38794 \begin_layout Standard
38795
38796 \size footnotesize
38797 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38798 \end_layout
38799
38800 \begin_layout Standard
38801
38802 \size footnotesize
38803 \InsetSpace ~
38804 \InsetSpace ~
38805 mov r3,#0x00
38806 \end_layout
38807
38808 \begin_layout Standard
38809
38810 \size footnotesize
38811 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38812 \end_layout
38813
38814 \begin_layout Standard
38815
38816 \size footnotesize
38817 \InsetSpace ~
38818 \InsetSpace ~
38819 mov r4,#0x00
38820 \end_layout
38821
38822 \begin_layout Standard
38823
38824 \size footnotesize
38825 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38826 \end_layout
38827
38828 \begin_layout Standard
38829
38830 \size footnotesize
38831 \InsetSpace ~
38832 \InsetSpace ~
38833 mov r5,#0x0A
38834 \end_layout
38835
38836 \begin_layout Standard
38837
38838 \size footnotesize
38839 \InsetSpace ~
38840 \InsetSpace ~
38841 mov r6,#0x00
38842 \end_layout
38843
38844 \begin_layout Standard
38845
38846 \size footnotesize
38847 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38848 \end_layout
38849
38850 \begin_layout Standard
38851
38852 \size footnotesize
38853 \InsetSpace ~
38854 \InsetSpace ~
38855 mov r7,#0x1E
38856 \end_layout
38857
38858 \begin_layout Standard
38859
38860 \size footnotesize
38861 \InsetSpace ~
38862 \InsetSpace ~
38863 mov r0,#0x00
38864 \end_layout
38865
38866 \begin_layout Standard
38867
38868 \size footnotesize
38869 ; _forcond_0($4) :
38870 \end_layout
38871
38872 \begin_layout Standard
38873
38874 \size footnotesize
38875 00104$:
38876 \end_layout
38877
38878 \begin_layout Standard
38879
38880 \size footnotesize
38881 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38882 \end_layout
38883
38884 \begin_layout Standard
38885
38886 \size footnotesize
38887 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38888 \end_layout
38889
38890 \begin_layout Standard
38891
38892 \size footnotesize
38893 \InsetSpace ~
38894 \InsetSpace ~
38895 clr c
38896 \end_layout
38897
38898 \begin_layout Standard
38899
38900 \size footnotesize
38901 \InsetSpace ~
38902 \InsetSpace ~
38903 mov a,r4
38904 \end_layout
38905
38906 \begin_layout Standard
38907
38908 \size footnotesize
38909 \InsetSpace ~
38910 \InsetSpace ~
38911 xrl a,#0x80
38912 \end_layout
38913
38914 \begin_layout Standard
38915
38916 \size footnotesize
38917 \InsetSpace ~
38918 \InsetSpace ~
38919 subb a,#0x8a
38920 \end_layout
38921
38922 \begin_layout Standard
38923
38924 \size footnotesize
38925 \InsetSpace ~
38926 \InsetSpace ~
38927 jnc 00107$
38928 \end_layout
38929
38930 \begin_layout Standard
38931
38932 \size footnotesize
38933 00115$:
38934 \end_layout
38935
38936 \begin_layout Standard
38937
38938 \size footnotesize
38939 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
38940 \end_layout
38941
38942 \begin_layout Standard
38943
38944 \size footnotesize
38945 ; iTemp21 [lr21:38]{short}[r4]
38946 \end_layout
38947
38948 \begin_layout Standard
38949
38950 \size footnotesize
38951 \InsetSpace ~
38952 \InsetSpace ~
38953 mov a,r4
38954 \end_layout
38955
38956 \begin_layout Standard
38957
38958 \size footnotesize
38959 \InsetSpace ~
38960 \InsetSpace ~
38961 add a,r2
38962 \end_layout
38963
38964 \begin_layout Standard
38965
38966 \size footnotesize
38967 \InsetSpace ~
38968 \InsetSpace ~
38969 mov r2,a
38970 \end_layout
38971
38972 \begin_layout Standard
38973
38974 \size footnotesize
38975 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38976 \end_layout
38977
38978 \begin_layout Standard
38979
38980 \size footnotesize
38981 \InsetSpace ~
38982 \InsetSpace ~
38983 mov b,#0x03
38984 \end_layout
38985
38986 \begin_layout Standard
38987
38988 \size footnotesize
38989 \InsetSpace ~
38990 \InsetSpace ~
38991 mov a,r4
38992 \end_layout
38993
38994 \begin_layout Standard
38995
38996 \size footnotesize
38997 \InsetSpace ~
38998 \InsetSpace ~
38999 mul ab
39000 \end_layout
39001
39002 \begin_layout Standard
39003
39004 \size footnotesize
39005 \InsetSpace ~
39006 \InsetSpace ~
39007 mov r1,a
39008 \end_layout
39009
39010 \begin_layout Standard
39011
39012 \size footnotesize
39013 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
39014 \end_layout
39015
39016 \begin_layout Standard
39017
39018 \size footnotesize
39019 ; iTemp15 [lr29:30]{short}[r1]
39020 \end_layout
39021
39022 \begin_layout Standard
39023
39024 \size footnotesize
39025 \InsetSpace ~
39026 \InsetSpace ~
39027 add a,r3
39028 \end_layout
39029
39030 \begin_layout Standard
39031
39032 \size footnotesize
39033 \InsetSpace ~
39034 \InsetSpace ~
39035 mov r3,a
39036 \end_layout
39037
39038 \begin_layout Standard
39039
39040 \size footnotesize
39041 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39042 \end_layout
39043
39044 \begin_layout Standard
39045
39046 \size footnotesize
39047 \InsetSpace ~
39048 \InsetSpace ~
39049 mov a,r7
39050 \end_layout
39051
39052 \begin_layout Standard
39053
39054 \size footnotesize
39055 \InsetSpace ~
39056 \InsetSpace ~
39057 add a,#0xfd
39058 \end_layout
39059
39060 \begin_layout Standard
39061
39062 \size footnotesize
39063 \InsetSpace ~
39064 \InsetSpace ~
39065 mov r7,a
39066 \end_layout
39067
39068 \begin_layout Standard
39069
39070 \size footnotesize
39071 \InsetSpace ~
39072 \InsetSpace ~
39073 mov a,r0
39074 \end_layout
39075
39076 \begin_layout Standard
39077
39078 \size footnotesize
39079 \InsetSpace ~
39080 \InsetSpace ~
39081 addc a,#0xff
39082 \end_layout
39083
39084 \begin_layout Standard
39085
39086 \size footnotesize
39087 \InsetSpace ~
39088 \InsetSpace ~
39089 mov r0,a
39090 \end_layout
39091
39092 \begin_layout Standard
39093
39094 \size footnotesize
39095 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39096 \end_layout
39097
39098 \begin_layout Standard
39099
39100 \size footnotesize
39101 \InsetSpace ~
39102 \InsetSpace ~
39103 mov a,r7
39104 \end_layout
39105
39106 \begin_layout Standard
39107
39108 \size footnotesize
39109 \InsetSpace ~
39110 \InsetSpace ~
39111 add a,_gint
39112 \end_layout
39113
39114 \begin_layout Standard
39115
39116 \size footnotesize
39117 \InsetSpace ~
39118 \InsetSpace ~
39119 mov _gint,a
39120 \end_layout
39121
39122 \begin_layout Standard
39123
39124 \size footnotesize
39125 \InsetSpace ~
39126 \InsetSpace ~
39127 mov a,r0
39128 \end_layout
39129
39130 \begin_layout Standard
39131
39132 \size footnotesize
39133 \InsetSpace ~
39134 \InsetSpace ~
39135 addc a,(_gint + 1)
39136 \end_layout
39137
39138 \begin_layout Standard
39139
39140 \size footnotesize
39141 \InsetSpace ~
39142 \InsetSpace ~
39143 mov (_gint + 1),a
39144 \end_layout
39145
39146 \begin_layout Standard
39147
39148 \size footnotesize
39149 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39150 \end_layout
39151
39152 \begin_layout Standard
39153
39154 \size footnotesize
39155 \InsetSpace ~
39156 \InsetSpace ~
39157 inc r4
39158 \end_layout
39159
39160 \begin_layout Standard
39161
39162 \size footnotesize
39163 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39164 \end_layout
39165
39166 \begin_layout Standard
39167
39168 \size footnotesize
39169 \InsetSpace ~
39170 \InsetSpace ~
39171 dec r5
39172 \end_layout
39173
39174 \begin_layout Standard
39175
39176 \size footnotesize
39177 \InsetSpace ~
39178 \InsetSpace ~
39179 cjne r5,#0xff,00104$
39180 \end_layout
39181
39182 \begin_layout Standard
39183
39184 \size footnotesize
39185 \InsetSpace ~
39186 \InsetSpace ~
39187 dec r6
39188 \end_layout
39189
39190 \begin_layout Standard
39191
39192 \size footnotesize
39193 ; goto _forcond_0($4)
39194 \end_layout
39195
39196 \begin_layout Standard
39197
39198 \size footnotesize
39199 \InsetSpace ~
39200 \InsetSpace ~
39201 sjmp 00104$
39202 \end_layout
39203
39204 \begin_layout Standard
39205
39206 \size footnotesize
39207 ; _forbreak_0($7) :
39208 \end_layout
39209
39210 \begin_layout Standard
39211
39212 \size footnotesize
39213 00107$:
39214 \end_layout
39215
39216 \begin_layout Standard
39217
39218 \size footnotesize
39219 ; ret iTemp24 [lr40:41]{short}
39220 \end_layout
39221
39222 \begin_layout Standard
39223
39224 \size footnotesize
39225 \InsetSpace ~
39226 \InsetSpace ~
39227 mov a,r3
39228 \end_layout
39229
39230 \begin_layout Standard
39231
39232 \size footnotesize
39233 \InsetSpace ~
39234 \InsetSpace ~
39235 add a,r2
39236 \end_layout
39237
39238 \begin_layout Standard
39239
39240 \size footnotesize
39241 \InsetSpace ~
39242 \InsetSpace ~
39243 mov dpl,a
39244 \end_layout
39245
39246 \begin_layout Standard
39247
39248 \size footnotesize
39249 ; _return($8) :
39250 \end_layout
39251
39252 \begin_layout Standard
39253
39254 \size footnotesize
39255 00108$:
39256 \end_layout
39257
39258 \begin_layout Standard
39259
39260 \size footnotesize
39261 \InsetSpace ~
39262 \InsetSpace ~
39263 ret
39264 \newline
39265
39266 \end_layout
39267
39268 \begin_layout Section
39269 A few words about basic block successors, predecessors and dominators
39270 \end_layout
39271
39272 \begin_layout Standard
39273 Successors are basic blocks
39274 \begin_inset LatexCommand \index{Basic blocks}
39275
39276 \end_inset
39277
39278  that might execute after this basic block.
39279 \newline
39280 Predecessors are basic blocks
39281  that might execute before reaching this basic block.
39282 \newline
39283 Dominators are basic
39284  blocks that WILL execute before reaching this basic block.
39285 \newline
39286
39287 \end_layout
39288
39289 \begin_layout Standard
39290 [basic block 1]
39291 \end_layout
39292
39293 \begin_layout Standard
39294 if (something)
39295 \end_layout
39296
39297 \begin_layout Standard
39298 \InsetSpace ~
39299 \InsetSpace ~
39300 \InsetSpace ~
39301 \InsetSpace ~
39302 [basic block 2]
39303 \end_layout
39304
39305 \begin_layout Standard
39306 else
39307 \end_layout
39308
39309 \begin_layout Standard
39310 \InsetSpace ~
39311 \InsetSpace ~
39312 \InsetSpace ~
39313 \InsetSpace ~
39314 [basic block 3]
39315 \end_layout
39316
39317 \begin_layout Standard
39318 [basic block 4]
39319 \newline
39320
39321 \end_layout
39322
39323 \begin_layout Standard
39324 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39325 \end_layout
39326
39327 \begin_layout Standard
39328 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39329 \end_layout
39330
39331 \begin_layout Standard
39332 c) domVect of [BB4] = BB1 ...
39333  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39334  was executed.
39335 \end_layout
39336
39337 \begin_layout Chapter
39338 Acknowledgments
39339 \end_layout
39340
39341 \begin_layout Standard
39342 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39343
39344 \end_inset
39345
39346
39347 \newline
39348
39349 \newline
39350
39351 \emph on
39352 Thanks to all the other volunteer developers who have helped with coding,
39353  testing, web-page creation, distribution sets, etc.
39354  You know who you are :-)
39355 \emph default
39356
39357 \newline
39358
39359 \newline
39360
39361 \emph on
39362 Also thanks to Sourceforge 
39363 \begin_inset LatexCommand \url{http://www.sf.net}
39364
39365 \end_inset
39366
39367  which has hosted the project since 1999 and donates significant download
39368  bandwidth and probably more than 
39369 \begin_inset ERT
39370 status collapsed
39371
39372 \begin_layout Standard
39373
39374 $10^{13}$
39375 \end_layout
39376
39377 \end_inset
39378
39379 CPU cycles per day.
39380 \newline
39381  
39382 \begin_inset Note Note
39383 status open
39384
39385 \begin_layout Standard
39386 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39387  minutes for (configure+make+regression test), and there is (i386, amd64,
39388  alpha, ppc64, (mingw32), sparc, Mac OS X).
39389  
39390 \end_layout
39391
39392 \end_inset
39393
39394
39395 \end_layout
39396
39397 \begin_layout Standard
39398 This document was initially written by Sandeep Dutta
39399 \end_layout
39400
39401 \begin_layout Standard
39402 All product names mentioned herein may be trademarks
39403 \begin_inset LatexCommand \index{Trademarks}
39404
39405 \end_inset
39406
39407  of their respective companies.
39408  
39409 \end_layout
39410
39411 \begin_layout Section*
39412 Alphabetical index
39413 \end_layout
39414
39415 \begin_layout Standard
39416 To avoid confusion, the installation and building options for SDCC itself
39417  (chapter 2) are not part of the index.
39418 \end_layout
39419
39420 \begin_layout Standard
39421 \begin_inset LatexCommand \printindex{}
39422
39423 \end_inset
39424
39425
39426 \end_layout
39427
39428 \end_body
39429 \end_document