* src/pic16/device.h,
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.2 created this file. For more info see http://www.lyx.org/
2 \lyxformat 245
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \fontscheme pslatex
26 \graphics default
27 \paperfontsize default
28 \spacing single
29 \papersize letterpaper
30 \use_geometry true
31 \use_amsmath 1
32 \cite_engine basic
33 \use_bibtopic false
34 \paperorientation portrait
35 \leftmargin 30mm
36 \topmargin 20mm
37 \rightmargin 25mm
38 \bottommargin 20mm
39 \secnumdepth 3
40 \tocdepth 3
41 \paragraph_separation indent
42 \defskip medskip
43 \quotes_language swedish
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47 \tracking_changes false
48 \output_changes true
49 \end_header
50
51 \begin_body
52
53 \begin_layout Standard
54 \begin_inset Note Note
55 status collapsed
56
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59  --version) are written this way: -
60 \begin_inset ERT
61 status collapsed
62
63 \begin_layout Standard
64
65
66 \backslash
67 /
68 \end_layout
69
70 \end_inset
71
72 -
73 \end_layout
74
75 \begin_layout Standard
76 Two resp.
77  three consecutive dashes would otherwise result in a long resp.
78  extra long dash.
79 \end_layout
80
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
83  later go
84 \end_layout
85
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
88  Z80 in 
89 \end_layout
90
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
93 \end_layout
94
95 \end_inset
96
97
98 \end_layout
99
100 \begin_layout Title
101 SDCC Compiler User Guide
102 \end_layout
103
104 \begin_layout Date
105
106 \size normal
107 SDCC 2.6.5
108 \size footnotesize
109
110 \newline
111 $Date::             $ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Note
118 status collapsed
119
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
122 \end_layout
123
124 \end_inset
125
126
127 \end_layout
128
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
131
132 \end_inset
133
134
135 \end_layout
136
137 \begin_layout Chapter
138 Introduction
139 \end_layout
140
141 \begin_layout Section
142 About SDCC
143 \end_layout
144
145 \begin_layout Standard
146
147 \series bold
148 SDCC
149 \series default
150  (
151 \emph on
152 S
153 \emph default
154 mall 
155 \emph on
156 D
157 \emph default
158 evice 
159 \emph on
160 C
161 \emph default
162  
163 \emph on
164 C
165 \emph default
166 ompiler) is 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 PIC14 port adds support for Microchip(TM)'s 14
22533 \begin_inset ERT
22534 status open
22535
22536 \begin_layout Standard
22537
22538
22539 \backslash
22540 ,
22541 \end_layout
22542
22543 \end_inset
22544
22545 bit PIC
22546 \begin_inset LatexCommand \index{PIC14}
22547
22548 \end_inset
22549
22550  MCUs.
22551  This port is not yet mature and still lacks many features.
22552  However, it can work for simple code.
22553 \end_layout
22554
22555 \begin_layout Standard
22556 Currently supported devices include:
22557 \end_layout
22558
22559 \begin_layout Standard
22560 12F: 629, 635, 675, 683
22561 \end_layout
22562
22563 \begin_layout Standard
22564 16C: 432, 433
22565 \end_layout
22566
22567 \begin_layout Standard
22568 16C: 554, 557, 558
22569 \end_layout
22570
22571 \begin_layout Standard
22572 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
22573 \end_layout
22574
22575 \begin_layout Standard
22576 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
22577  781, 782
22578 \end_layout
22579
22580 \begin_layout Standard
22581 16C: 925, 926
22582 \end_layout
22583
22584 \begin_layout Standard
22585 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
22586  689, 690
22587 \end_layout
22588
22589 \begin_layout Standard
22590 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
22591 \end_layout
22592
22593 \begin_layout Standard
22594 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
22595  877, 877a, 88
22596 \end_layout
22597
22598 \begin_layout Standard
22599 16F: 913, 914, 916, 917
22600 \end_layout
22601
22602 \begin_layout Standard
22603 An up-to-date list of currently supported devices can be obtained via 
22604 \family typewriter
22605 sdcc -mpic14 -phelp foo.c
22606 \family default
22607  (foo.c must exist...).
22608 \end_layout
22609
22610 \begin_layout Subsection
22611 PIC Code Pages
22612 \begin_inset LatexCommand \index{code page (pic14)}
22613
22614 \end_inset
22615
22616  and Memory Banks
22617 \begin_inset LatexCommand \index{Memory bank (pic14)}
22618
22619 \end_inset
22620
22621
22622 \end_layout
22623
22624 \begin_layout Standard
22625 The linker organizes allocation for the code page and RAM banks.
22626  It does not have intimate knowledge of the code flow.
22627  It will put all the code section of a single .asm file into a single code
22628  page.
22629  In order to make use of multiple code pages, separate asm files must be
22630  used.
22631  The compiler assigns all 
22632 \emph on
22633 static
22634 \emph default
22635  functions of a single .c file into the same code page.
22636 \newline
22637
22638 \newline
22639 To get the best results,
22640  follow these guidelines:
22641 \end_layout
22642
22643 \begin_layout Enumerate
22644 Make local functions static, as non static functions require code page selection
22645  overhead.
22646 \newline
22647 Due to the way sdcc handles functions, place called functions prior
22648  to calling functions in the file wherever possible: Otherwise sdcc will
22649  insert unneccessary pagesel directives around the call, believing that
22650  the called function is externally defined.
22651 \end_layout
22652
22653 \begin_layout Enumerate
22654 For devices that have multiple code pages it is more efficient to use the
22655  same number of files as pages: Use up to 4 separate .c files for the 16F877,
22656  but only 2 files for the 16F874.
22657  This way the linker can put the code for each file into different code
22658  pages and there will be less page selection overhead.
22659 \end_layout
22660
22661 \begin_layout Enumerate
22662 And as for any 8 bit micro (especially for PIC14 as they have a very simple
22663  instruction set), use 'unsigned char' wherever possible instead of 'int'.
22664 \end_layout
22665
22666 \begin_layout Subsection
22667 Adding New Devices to the Port 
22668 \end_layout
22669
22670 \begin_layout Standard
22671 Adding support for a new 14
22672 \begin_inset ERT
22673 status open
22674
22675 \begin_layout Standard
22676
22677
22678 \backslash
22679 ,
22680 \end_layout
22681
22682 \end_inset
22683
22684 bit PIC MCU requires the following steps:
22685 \end_layout
22686
22687 \begin_layout Enumerate
22688 Create a new device description.
22689 \newline
22690 Each device is described in two files: pic16f*.h
22691  and pic16f*.c.
22692  These files primarily define SFRs, structs to access their bits, and symbolic
22693  configuration options.
22694  Both files can be generated from gputils' .inc files using the perl script
22695  
22696 \family typewriter
22697 support/scripts/inc2h.pl
22698 \family default
22699 .
22700  This file also contains further instructions on how to proceed.
22701 \end_layout
22702
22703 \begin_layout Enumerate
22704 Copy the .h file into SDCC's include path and either add the .c file to your
22705  project or copy it to 
22706 \family typewriter
22707 device/lib/pic/libdev
22708 \family default
22709 .
22710  Afterwards, rebuild and install the libraries.
22711 \end_layout
22712
22713 \begin_layout Enumerate
22714 Edit pic14devices.txt in SDCC's include path (
22715 \family typewriter
22716 device/include/pic/
22717 \family default
22718  in the source tree or 
22719 \family typewriter
22720 /usr/local/share/sdcc/include/pic
22721 \family default
22722  after installation).
22723 \newline
22724 You need to add a device specification here to make
22725  the memory layout (code banks, RAM, aliased memory regions, ...) known to
22726  the compiler.
22727  Probably you can copy and modify an existing entry.
22728  The file format is documented at the top of the file.
22729 \end_layout
22730
22731 \begin_layout Subsection
22732 Interrupt Code
22733 \end_layout
22734
22735 \begin_layout Standard
22736 For the interrupt function, use the keyword '__interrupt'
22737 \begin_inset LatexCommand \index{PIC14!interrupt}
22738
22739 \end_inset
22740
22741  with level number of 0 (PIC14 only has 1 interrupt so this number is only
22742  there to avoid a syntax error - it ought to be fixed).
22743  E.g.:
22744 \end_layout
22745
22746 \begin_layout Verse
22747
22748 \family typewriter
22749 void Intr(void) __interrupt 0
22750 \newline
22751 {
22752 \newline
22753 \InsetSpace ~
22754 \InsetSpace ~
22755 T0IF = 0; /* Clear timer interrupt */
22756 \newline
22757 }
22758 \end_layout
22759
22760 \begin_layout Subsection
22761 Linking and Assembling
22762 \end_layout
22763
22764 \begin_layout Standard
22765 For assembling you can use either GPUTILS'
22766 \begin_inset LatexCommand \index{gputils (pic tools)}
22767
22768 \end_inset
22769
22770  gpasm.exe or MPLAB's mpasmwin.exe.
22771  GPUTILS are available from 
22772 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22773
22774 \end_inset
22775
22776 .
22777  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
22778  If you use MPLAB and an interrupt function then the linker script file
22779  vectors section will need to be enlarged to link with mplink.
22780 \newline
22781
22782 \newline
22783 Here is a 
22784 \family typewriter
22785 Makefile
22786 \family default
22787  using GPUTILS:
22788 \end_layout
22789
22790 \begin_layout Verse
22791
22792 \family typewriter
22793 .c.o:
22794 \newline
22795 \InsetSpace ~
22796 \InsetSpace ~
22797 \InsetSpace ~
22798 \InsetSpace ~
22799 \InsetSpace ~
22800 \InsetSpace ~
22801 \InsetSpace ~
22802 \InsetSpace ~
22803 sdcc -V -mpic14 -p16f877 -c $< 
22804 \newline
22805
22806 \newline
22807 $(PRJ).hex: $(OBJS) 
22808 \newline
22809 \InsetSpace ~
22810 \InsetSpace ~
22811 \InsetSpace ~
22812 \InsetSpace ~
22813 \InsetSpace ~
22814 \InsetSpace ~
22815 \InsetSpace ~
22816 \InsetSpace ~
22817 gplink -m -s $(PRJ).lkr
22818  -o $(PRJ).hex $(OBJS) libsdcc.lib
22819 \end_layout
22820
22821 \begin_layout Standard
22822 Here is a 
22823 \family typewriter
22824 Makefile
22825 \family default
22826  using MPLAB:
22827 \end_layout
22828
22829 \begin_layout Verse
22830
22831 \family typewriter
22832 .c.o: 
22833 \newline
22834 \InsetSpace ~
22835 \InsetSpace ~
22836 \InsetSpace ~
22837 \InsetSpace ~
22838 \InsetSpace ~
22839 \InsetSpace ~
22840 \InsetSpace ~
22841 \InsetSpace ~
22842 sdcc -S -V -mpic14 -p16f877 $< 
22843 \newline
22844 \InsetSpace ~
22845 \InsetSpace ~
22846 \InsetSpace ~
22847 \InsetSpace ~
22848 \InsetSpace ~
22849 \InsetSpace ~
22850 \InsetSpace ~
22851 \InsetSpace ~
22852 mpasmwin /q /o $*.asm
22853 \newline
22854
22855 \newline
22856 $(PRJ).hex: $(OBJS)
22857  
22858 \newline
22859 \InsetSpace ~
22860 \InsetSpace ~
22861 \InsetSpace ~
22862 \InsetSpace ~
22863 \InsetSpace ~
22864 \InsetSpace ~
22865 \InsetSpace ~
22866 \InsetSpace ~
22867 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22868 \end_layout
22869
22870 \begin_layout Standard
22871 Please note that indentations within a
22872 \family typewriter
22873  Makefile
22874 \family default
22875  have to be done with a tabulator character.
22876 \end_layout
22877
22878 \begin_layout Subsection
22879 Command-Line Options
22880 \end_layout
22881
22882 \begin_layout Standard
22883 Besides the switches common to all SDCC backends, the PIC14 port accepts
22884  the following options (for an updated list see sdcc -
22885 \begin_inset ERT
22886 status collapsed
22887
22888 \begin_layout Standard
22889
22890
22891 \backslash
22892 /
22893 \end_layout
22894
22895 \end_inset
22896
22897 -help):
22898 \end_layout
22899
22900 \begin_layout Description
22901 -
22902 \begin_inset ERT
22903 status collapsed
22904
22905 \begin_layout Standard
22906
22907
22908 \backslash
22909 /
22910 \end_layout
22911
22912 \end_inset
22913
22914 -debug-xtra
22915 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22916
22917 \end_inset
22918
22919  emit debug info in assembly output
22920 \end_layout
22921
22922 \begin_layout Description
22923 -
22924 \begin_inset ERT
22925 status collapsed
22926
22927 \begin_layout Standard
22928
22929
22930 \backslash
22931 /
22932 \end_layout
22933
22934 \end_inset
22935
22936 -no-pcode-opt
22937 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22938
22939 \end_inset
22940
22941  disable (slightly faulty) optimization on pCode
22942 \end_layout
22943
22944 \begin_layout Description
22945 -
22946 \begin_inset ERT
22947 status collapsed
22948
22949 \begin_layout Standard
22950
22951
22952 \backslash
22953 /
22954 \end_layout
22955
22956 \end_inset
22957
22958 -stack-loc
22959 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22960
22961 \end_inset
22962
22963  sets the lowest address of the argument passing stack (defaults to a suitably
22964  large shared databank to reduce BANKSEL overhead)
22965 \end_layout
22966
22967 \begin_layout Description
22968 -
22969 \begin_inset ERT
22970 status collapsed
22971
22972 \begin_layout Standard
22973
22974
22975 \backslash
22976 /
22977 \end_layout
22978
22979 \end_inset
22980
22981 -stack-size
22982 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22983
22984 \end_inset
22985
22986  sets the size if the argument passing stack (default: 16, minimum: 4)
22987 \end_layout
22988
22989 \begin_layout Subsection
22990 Environment Variables
22991 \end_layout
22992
22993 \begin_layout Standard
22994 The PIC14 port recognizes the following environment variables:
22995 \end_layout
22996
22997 \begin_layout Description
22998 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
22999  register (the ones called r0xNNNN) in a section of its own.
23000  By default (if this variable is unset), sdcc tries to cluster registers
23001  in sections in order to reduce the BANKSEL overhead when accessing them.
23002 \end_layout
23003
23004 \begin_layout Subsection
23005 The Library
23006 \end_layout
23007
23008 \begin_layout Standard
23009 The PIC14 library currently only contains support routines required by the
23010  compiler to implement multiplication, division, and floating point support.
23011  No libc-like replacement is available at the moment, though many of the
23012  common sdcc library sources (in 
23013 \family typewriter
23014 device/lib
23015 \family default
23016 ) should also compile with the PIC14 port.
23017 \end_layout
23018
23019 \begin_layout Subsubsection
23020 error: missing definition for symbol 
23021 \begin_inset Quotes sld
23022 \end_inset
23023
23024 __gptrget1
23025 \begin_inset Quotes srd
23026 \end_inset
23027
23028
23029 \end_layout
23030
23031 \begin_layout Standard
23032 The PIC14 port uses library routines to provide more complex operations
23033  like multiplication, division/modulus and (generic) pointer dereferencing.
23034  In order to add these routines to your project, you must link with PIC14's
23035  
23036 \family typewriter
23037 libsdcc.lib
23038 \family default
23039 .
23040  For single source file projects this is done automatically, more complex
23041  projects must add 
23042 \family typewriter
23043 libsdcc.lib
23044 \family default
23045  to the linker's arguments.
23046  Make sure you also add an include path for the library (using the -I switch
23047  to the linker)!
23048 \end_layout
23049
23050 \begin_layout Subsubsection
23051 Processor mismatch in file 
23052 \begin_inset Quotes sld
23053 \end_inset
23054
23055 XXX
23056 \begin_inset Quotes srd
23057 \end_inset
23058
23059 .
23060 \end_layout
23061
23062 \begin_layout Standard
23063 This warning can usually be ignored due to the very good compatibility amongst
23064  14
23065 \begin_inset ERT
23066 status open
23067
23068 \begin_layout Standard
23069
23070
23071 \backslash
23072 ,
23073 \end_layout
23074
23075 \end_inset
23076
23077 bit PIC
23078 \begin_inset LatexCommand \index{PIC14}
23079
23080 \end_inset
23081
23082  devices.
23083 \end_layout
23084
23085 \begin_layout Standard
23086 You might also consider recompiling the library for your specific device
23087  by changing the ARCH=p16f877 (default target) entry in 
23088 \family typewriter
23089 device/lib/pic/Makefile.in
23090 \family default
23091  and 
23092 \family typewriter
23093 device/lib/pic/Makefile
23094 \family default
23095  to reflect your device.
23096  This might even improve performance for smaller devices as unneccesary
23097  BANKSELs might be removed.
23098 \end_layout
23099
23100 \begin_layout Subsection
23101 Known Bugs
23102 \end_layout
23103
23104 \begin_layout Subsubsection
23105 Function arguments
23106 \end_layout
23107
23108 \begin_layout Standard
23109 Functions with variable argument lists (like printf) are not yet supported.
23110  Similarly, taking the argument of the first argument passed into a function
23111  does not work: It is currently passed in WREG and has no address...
23112 \end_layout
23113
23114 \begin_layout Subsubsection
23115 Regression tests fail
23116 \end_layout
23117
23118 \begin_layout Standard
23119 Though the small subset of regression tests in src/regression passes, SDCC
23120  regression test suite does not, indicating that there are still major bugs
23121  in the port.
23122  However, many smaller projects have successfully used SDCC in the past...
23123 \end_layout
23124
23125 \begin_layout Standard
23126
23127 \size footnotesize
23128
23129 \newpage
23130
23131 \end_layout
23132
23133 \begin_layout Section
23134 The PIC16
23135 \begin_inset LatexCommand \index{PIC16}
23136
23137 \end_inset
23138
23139  port
23140 \end_layout
23141
23142 \begin_layout Standard
23143 The PIC16
23144 \begin_inset LatexCommand \index{PIC16}
23145
23146 \end_inset
23147
23148  port is the portion of SDCC that is responsible to produce code for the
23149  Microchip
23150 \begin_inset LatexCommand \index{Microchip}
23151
23152 \end_inset
23153
23154 (TM) microcontrollers with 16 bit core.
23155  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
23156  Currently supported devices are:
23157 \end_layout
23158
23159 \begin_layout Standard
23160 18F: 242, 248, 252, 258, 442, 448, 452, 458
23161 \end_layout
23162
23163 \begin_layout Standard
23164 18F: 1220, 1320
23165 \end_layout
23166
23167 \begin_layout Standard
23168 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 2525, 2550, 2620
23169 \end_layout
23170
23171 \begin_layout Standard
23172 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 4520, 4525, 4550, 4620
23173 \end_layout
23174
23175 \begin_layout Standard
23176 18F: 6520, 6620, 6680, 6720
23177 \end_layout
23178
23179 \begin_layout Standard
23180 18F: 8520, 8620, 8680, 8720
23181 \end_layout
23182
23183 \begin_layout Subsection
23184 Global Options
23185 \end_layout
23186
23187 \begin_layout Standard
23188 PIC16 port supports the standard command line arguments as supposed, with
23189  the exception of certain cases that will be mentioned in the following
23190  list:
23191 \end_layout
23192
23193 \begin_layout Description
23194 -
23195 \begin_inset ERT
23196 status collapsed
23197
23198 \begin_layout Standard
23199
23200
23201 \backslash
23202 /
23203 \end_layout
23204
23205 \end_inset
23206
23207 -callee-saves
23208 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23209
23210 \end_inset
23211
23212  See -
23213 \begin_inset ERT
23214 status collapsed
23215
23216 \begin_layout Standard
23217
23218
23219 \backslash
23220 /
23221 \end_layout
23222
23223 \end_inset
23224
23225 -all-callee-saves
23226 \end_layout
23227
23228 \begin_layout Description
23229 -
23230 \begin_inset ERT
23231 status collapsed
23232
23233 \begin_layout Standard
23234
23235
23236 \backslash
23237 /
23238 \end_layout
23239
23240 \end_inset
23241
23242 -fommit-frame-pointer
23243 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23244
23245 \end_inset
23246
23247  Frame pointer will be omitted when the function uses no local variables.
23248 \end_layout
23249
23250 \begin_layout Subsection
23251 Port Specific Options
23252 \begin_inset LatexCommand \index{Options PIC16}
23253
23254 \end_inset
23255
23256
23257 \end_layout
23258
23259 \begin_layout Standard
23260 The port specific options appear after the global options in the sdcc -
23261 \begin_inset ERT
23262 status collapsed
23263
23264 \begin_layout Standard
23265
23266
23267 \backslash
23268 /
23269 \end_layout
23270
23271 \end_inset
23272
23273 -help output.
23274 \end_layout
23275
23276 \begin_layout Subsubsection
23277 Code Generation Options
23278 \end_layout
23279
23280 \begin_layout Standard
23281 These options influence the generated assembler code.
23282 \end_layout
23283
23284 \begin_layout Description
23285 -
23286 \begin_inset ERT
23287 status collapsed
23288
23289 \begin_layout Standard
23290
23291
23292 \backslash
23293 /
23294 \end_layout
23295
23296 \end_inset
23297
23298 -pstack-model=[model] Used in conjuction with the command above.
23299  Defines the stack model to be used, valid stack models are:
23300 \end_layout
23301
23302 \begin_deeper
23303 \begin_layout List
23304 \labelwidthstring 00.00.0000
23305
23306 \emph on
23307 small
23308 \emph default
23309  Selects small stack model.
23310  8 bit stack and frame pointers.
23311  Supports 256 bytes stack size.
23312 \end_layout
23313
23314 \begin_layout List
23315 \labelwidthstring 00.00.0000
23316
23317 \emph on
23318 large
23319 \emph default
23320  Selects large stack model.
23321  16 bit stack and frame pointers.
23322  Supports 65536 bytes stack size.
23323 \end_layout
23324
23325 \end_deeper
23326 \begin_layout Description
23327 -
23328 \begin_inset ERT
23329 status collapsed
23330
23331 \begin_layout Standard
23332
23333
23334 \backslash
23335 /
23336 \end_layout
23337
23338 \end_inset
23339
23340 -pno-banksel Do not generate BANKSEL assembler directives.
23341 \end_layout
23342
23343 \begin_layout Description
23344 -
23345 \begin_inset ERT
23346 status collapsed
23347
23348 \begin_layout Standard
23349
23350
23351 \backslash
23352 /
23353 \end_layout
23354
23355 \end_inset
23356
23357 -extended Enable extended instruction set/literal offset addressing mode.
23358  Use with care!
23359 \end_layout
23360
23361 \begin_layout Subsubsection
23362 Optimization Options
23363 \end_layout
23364
23365 \begin_layout Description
23366 -
23367 \begin_inset ERT
23368 status collapsed
23369
23370 \begin_layout Standard
23371
23372
23373 \backslash
23374 /
23375 \end_layout
23376
23377 \end_inset
23378
23379 -obanksel=n Set optimization level for inserting BANKSELs.
23380 \newline
23381
23382 \end_layout
23383
23384 \begin_deeper
23385 \begin_layout List
23386 \labelwidthstring 00.00.0000
23387 0 no optimization
23388 \end_layout
23389
23390 \begin_layout List
23391 \labelwidthstring 00.00.0000
23392 1 checks previous used register and if it is the same then does not emit
23393  BANKSEL, accounts only for labels.
23394 \end_layout
23395
23396 \begin_layout List
23397 \labelwidthstring 00.00.0000
23398 2 tries to check the location of (even different) symbols and removes BANKSELs
23399  if they are in the same bank.
23400  
23401 \newline
23402
23403 \emph on
23404 Important: There might be problems if the linker script has data sections
23405  across bank borders!
23406 \end_layout
23407
23408 \end_deeper
23409 \begin_layout Description
23410 -
23411 \begin_inset ERT
23412 status collapsed
23413
23414 \begin_layout Standard
23415
23416
23417 \backslash
23418 /
23419 \end_layout
23420
23421 \end_inset
23422
23423 -denable-peeps Force the usage of peepholes.
23424  Use with care.
23425 \end_layout
23426
23427 \begin_layout Description
23428 -
23429 \begin_inset ERT
23430 status collapsed
23431
23432 \begin_layout Standard
23433
23434
23435 \backslash
23436 /
23437 \end_layout
23438
23439 \end_inset
23440
23441 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23442 \end_layout
23443
23444 \begin_layout Description
23445 -
23446 \begin_inset ERT
23447 status collapsed
23448
23449 \begin_layout Standard
23450
23451
23452 \backslash
23453 /
23454 \end_layout
23455
23456 \end_inset
23457
23458 -optimize-cmp Try to optimize some compares.
23459 \end_layout
23460
23461 \begin_layout Description
23462 -
23463 \begin_inset ERT
23464 status collapsed
23465
23466 \begin_layout Standard
23467
23468
23469 \backslash
23470 /
23471 \end_layout
23472
23473 \end_inset
23474
23475 -optimize-df Analyze the dataflow of the generated code and improve it.
23476 \end_layout
23477
23478 \begin_layout Subsubsection
23479 Assembling Options
23480 \end_layout
23481
23482 \begin_layout Description
23483 -
23484 \begin_inset ERT
23485 status collapsed
23486
23487 \begin_layout Standard
23488
23489
23490 \backslash
23491 /
23492 \end_layout
23493
23494 \end_inset
23495
23496 -asm= Sets the full path and name of an external assembler to call.
23497 \end_layout
23498
23499 \begin_layout Description
23500 -
23501 \begin_inset ERT
23502 status collapsed
23503
23504 \begin_layout Standard
23505
23506
23507 \backslash
23508 /
23509 \end_layout
23510
23511 \end_inset
23512
23513 -mplab-comp MPLAB
23514 \begin_inset LatexCommand \index{PIC16!MPLAB}
23515
23516 \end_inset
23517
23518  compatibility option.
23519  Currently only suppresses special gpasm directives.
23520 \end_layout
23521
23522 \begin_layout Subsubsection
23523 Linking Options
23524 \end_layout
23525
23526 \begin_layout Description
23527 -
23528 \begin_inset ERT
23529 status collapsed
23530
23531 \begin_layout Standard
23532
23533
23534 \backslash
23535 /
23536 \end_layout
23537
23538 \end_inset
23539
23540 -link= Sets the full path and name of an external linker to call.
23541 \end_layout
23542
23543 \begin_layout Description
23544 -
23545 \begin_inset ERT
23546 status collapsed
23547
23548 \begin_layout Standard
23549
23550
23551 \backslash
23552 /
23553 \end_layout
23554
23555 \end_inset
23556
23557 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23558  unitialized data variables with [kword].
23559  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23560 \end_layout
23561
23562 \begin_layout Description
23563 -
23564 \begin_inset ERT
23565 status collapsed
23566
23567 \begin_layout Standard
23568
23569
23570 \backslash
23571 /
23572 \end_layout
23573
23574 \end_inset
23575
23576 -ivt-loc=n Place the interrupt vector table at address 
23577 \emph on
23578 n
23579 \emph default
23580 .
23581  Useful for bootloaders.
23582 \end_layout
23583
23584 \begin_layout Description
23585 -
23586 \begin_inset ERT
23587 status collapsed
23588
23589 \begin_layout Standard
23590
23591
23592 \backslash
23593 /
23594 \end_layout
23595
23596 \end_inset
23597
23598 -nodefaultlibs Do not link default libraries when linking.
23599 \end_layout
23600
23601 \begin_layout Description
23602 -
23603 \begin_inset ERT
23604 status collapsed
23605
23606 \begin_layout Standard
23607
23608
23609 \backslash
23610 /
23611 \end_layout
23612
23613 \end_inset
23614
23615 -use-crt= Use a custom run-time module instead of the defaults.
23616 \end_layout
23617
23618 \begin_layout Description
23619 -
23620 \begin_inset ERT
23621 status collapsed
23622
23623 \begin_layout Standard
23624
23625
23626 \backslash
23627 /
23628 \end_layout
23629
23630 \end_inset
23631
23632 -no-crt Don't link the default run-time modules
23633 \end_layout
23634
23635 \begin_layout Subsubsection
23636 Debugging Options
23637 \end_layout
23638
23639 \begin_layout Standard
23640 Debugging options enable extra debugging information in the output files.
23641 \end_layout
23642
23643 \begin_layout Description
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 -debug-xtra Similar to -
23658 \begin_inset ERT
23659 status collapsed
23660
23661 \begin_layout Standard
23662
23663
23664 \backslash
23665 /
23666 \end_layout
23667
23668 \end_inset
23669
23670 -debug
23671 \begin_inset LatexCommand \index{-\/-debug}
23672
23673 \end_inset
23674
23675 , but dumps more information.
23676 \end_layout
23677
23678 \begin_layout Description
23679 -
23680 \begin_inset ERT
23681 status collapsed
23682
23683 \begin_layout Standard
23684
23685
23686 \backslash
23687 /
23688 \end_layout
23689
23690 \end_inset
23691
23692 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23693  information.
23694  <source> is the name of the file being compiled.
23695 \end_layout
23696
23697 \begin_layout Description
23698 -
23699 \begin_inset ERT
23700 status collapsed
23701
23702 \begin_layout Standard
23703
23704
23705 \backslash
23706 /
23707 \end_layout
23708
23709 \end_inset
23710
23711 -pcode-verbose Enable pcode debugging information in translation.
23712 \end_layout
23713
23714 \begin_layout Description
23715 -
23716 \begin_inset ERT
23717 status collapsed
23718
23719 \begin_layout Standard
23720
23721
23722 \backslash
23723 /
23724 \end_layout
23725
23726 \end_inset
23727
23728 -calltree Dump call tree in .calltree file.
23729 \end_layout
23730
23731 \begin_layout Description
23732 -
23733 \begin_inset ERT
23734 status collapsed
23735
23736 \begin_layout Standard
23737
23738
23739 \backslash
23740 /
23741 \end_layout
23742
23743 \end_inset
23744
23745 -gstack Trace push/pops for stack pointer overflow.
23746 \end_layout
23747
23748 \begin_layout Subsection
23749 Enviroment Variables
23750 \end_layout
23751
23752 \begin_layout Standard
23753 There is a number of enviromental variables that can be used when running
23754  SDCC to enable certain optimizations or force a specific program behaviour.
23755  these variables are primarily for debugging purposes so they can be enabled/dis
23756 abled at will.
23757 \end_layout
23758
23759 \begin_layout Standard
23760 Currently there is only two such variables available:
23761 \end_layout
23762
23763 \begin_layout Description
23764 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
23765  bitfields is optimized by directly loading FSR0 with the address of the
23766  bitfield structure.
23767  Normally SDCC will cast the bitfield structure to a bitfield pointer and
23768  then load FSR0.
23769  This step saves data ram and code space for functions that make heavy use
23770  of bitfields.
23771  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
23772  option).
23773  
23774 \end_layout
23775
23776 \begin_layout Description
23777 NO_REG_OPT Do not perform pCode registers optimization.
23778  This should be used for debugging purposes.
23779  If bugs in the pcode optimizer are found, users can benefit from temporarily
23780  disabling the optimizer until the bug is fixed.
23781 \end_layout
23782
23783 \begin_layout Subsection
23784 Preprocessor Macros
23785 \end_layout
23786
23787 \begin_layout Standard
23788 PIC16
23789 \begin_inset LatexCommand \index{PIC16}
23790
23791 \end_inset
23792
23793  port defines the following preprocessor macros while translating a source.
23794 \end_layout
23795
23796 \begin_layout Standard
23797 \align center
23798 \begin_inset Tabular
23799 <lyxtabular version="3" rows="6" columns="2">
23800 <features>
23801 <column alignment="center" valignment="top" leftline="true" width="0">
23802 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23803 <row topline="true" bottomline="true">
23804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23805 \begin_inset Text
23806
23807 \begin_layout Standard
23808 Macro
23809 \end_layout
23810
23811 \end_inset
23812 </cell>
23813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23814 \begin_inset Text
23815
23816 \begin_layout Standard
23817 Description
23818 \end_layout
23819
23820 \end_inset
23821 </cell>
23822 </row>
23823 <row topline="true">
23824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23825 \begin_inset Text
23826
23827 \begin_layout Standard
23828 SDCC_pic16
23829 \end_layout
23830
23831 \end_inset
23832 </cell>
23833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23834 \begin_inset Text
23835
23836 \begin_layout Standard
23837 Port identification
23838 \end_layout
23839
23840 \end_inset
23841 </cell>
23842 </row>
23843 <row topline="true">
23844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23845 \begin_inset Text
23846
23847 \begin_layout Standard
23848 _
23849 \begin_inset ERT
23850 status collapsed
23851
23852 \begin_layout Standard
23853
23854
23855 \backslash
23856 /
23857 \end_layout
23858
23859 \end_inset
23860
23861 _pic16
23862 \end_layout
23863
23864 \end_inset
23865 </cell>
23866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23867 \begin_inset Text
23868
23869 \begin_layout Standard
23870 Port identification (same as above)
23871 \end_layout
23872
23873 \end_inset
23874 </cell>
23875 </row>
23876 <row topline="true">
23877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23878 \begin_inset Text
23879
23880 \begin_layout Standard
23881 pic18fxxxx
23882 \end_layout
23883
23884 \end_inset
23885 </cell>
23886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23887 \begin_inset Text
23888
23889 \begin_layout Standard
23890 MCU Identification.
23891  
23892 \emph on
23893 xxxx
23894 \emph default
23895  is the microcontrol identification number, i.e.
23896  452, 6620, etc
23897 \end_layout
23898
23899 \end_inset
23900 </cell>
23901 </row>
23902 <row topline="true">
23903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23904 \begin_inset Text
23905
23906 \begin_layout Standard
23907 _
23908 \begin_inset ERT
23909 status collapsed
23910
23911 \begin_layout Standard
23912
23913
23914 \backslash
23915 /
23916 \end_layout
23917
23918 \end_inset
23919
23920 _18Fxxxx
23921 \end_layout
23922
23923 \end_inset
23924 </cell>
23925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23926 \begin_inset Text
23927
23928 \begin_layout Standard
23929 MCU Identification (same as above)
23930 \end_layout
23931
23932 \end_inset
23933 </cell>
23934 </row>
23935 <row topline="true" bottomline="true">
23936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23937 \begin_inset Text
23938
23939 \begin_layout Standard
23940 STACK_MODEL_nnn
23941 \end_layout
23942
23943 \end_inset
23944 </cell>
23945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23946 \begin_inset Text
23947
23948 \begin_layout Standard
23949 nnn = SMALL or LARGE respectively according to the stack model used
23950 \end_layout
23951
23952 \end_inset
23953 </cell>
23954 </row>
23955 </lyxtabular>
23956
23957 \end_inset
23958
23959
23960 \end_layout
23961
23962 \begin_layout Standard
23963 In addition the following macros are defined when calling assembler:
23964 \end_layout
23965
23966 \begin_layout Standard
23967 \align center
23968 \begin_inset Tabular
23969 <lyxtabular version="3" rows="4" columns="2">
23970 <features>
23971 <column alignment="center" valignment="top" leftline="true" width="0">
23972 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23973 <row topline="true" bottomline="true">
23974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23975 \begin_inset Text
23976
23977 \begin_layout Standard
23978 Macro
23979 \end_layout
23980
23981 \end_inset
23982 </cell>
23983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23984 \begin_inset Text
23985
23986 \begin_layout Standard
23987 Description
23988 \end_layout
23989
23990 \end_inset
23991 </cell>
23992 </row>
23993 <row topline="true">
23994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23995 \begin_inset Text
23996
23997 \begin_layout Standard
23998 __18Fxxxx
23999 \end_layout
24000
24001 \end_inset
24002 </cell>
24003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24004 \begin_inset Text
24005
24006 \begin_layout Standard
24007 MCU Identification.
24008  
24009 \emph on
24010 xxxx
24011 \emph default
24012  is the microcontrol identification number, i.e.
24013  452, 6620, etc
24014 \end_layout
24015
24016 \end_inset
24017 </cell>
24018 </row>
24019 <row topline="true">
24020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24021 \begin_inset Text
24022
24023 \begin_layout Standard
24024 SDCC_MODEL_nnn
24025 \end_layout
24026
24027 \end_inset
24028 </cell>
24029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24030 \begin_inset Text
24031
24032 \begin_layout Standard
24033 nnn = SMALL or LARGE respectively according to the memory model used for
24034  SDCC
24035 \end_layout
24036
24037 \end_inset
24038 </cell>
24039 </row>
24040 <row topline="true" bottomline="true">
24041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24042 \begin_inset Text
24043
24044 \begin_layout Standard
24045 STACK_MODEL_nnn
24046 \end_layout
24047
24048 \end_inset
24049 </cell>
24050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24051 \begin_inset Text
24052
24053 \begin_layout Standard
24054 nnn = SMALL or LARGE respectively according to the stack model used
24055 \end_layout
24056
24057 \end_inset
24058 </cell>
24059 </row>
24060 </lyxtabular>
24061
24062 \end_inset
24063
24064
24065 \end_layout
24066
24067 \begin_layout Subsection
24068 Directories
24069 \end_layout
24070
24071 \begin_layout Standard
24072 PIC16
24073 \begin_inset LatexCommand \index{PIC16}
24074
24075 \end_inset
24076
24077  port uses the following directories for searching header files and libraries.
24078 \end_layout
24079
24080 \begin_layout Standard
24081 \align center
24082 \begin_inset Tabular
24083 <lyxtabular version="3" rows="3" columns="4">
24084 <features>
24085 <column alignment="center" valignment="top" leftline="true" width="0">
24086 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24087 <column alignment="center" valignment="top" width="0">
24088 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24089 <row topline="true" bottomline="true">
24090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24091 \begin_inset Text
24092
24093 \begin_layout Standard
24094 Directory
24095 \end_layout
24096
24097 \end_inset
24098 </cell>
24099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24100 \begin_inset Text
24101
24102 \begin_layout Standard
24103 Description
24104 \end_layout
24105
24106 \end_inset
24107 </cell>
24108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24109 \begin_inset Text
24110
24111 \begin_layout Standard
24112 Target
24113 \end_layout
24114
24115 \end_inset
24116 </cell>
24117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24118 \begin_inset Text
24119
24120 \begin_layout Standard
24121 Command prefix
24122 \end_layout
24123
24124 \end_inset
24125 </cell>
24126 </row>
24127 <row topline="true">
24128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24129 \begin_inset Text
24130
24131 \begin_layout Standard
24132 PREFIX/sdcc/include/pic16
24133 \end_layout
24134
24135 \end_inset
24136 </cell>
24137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24138 \begin_inset Text
24139
24140 \begin_layout Standard
24141 PIC16 specific headers
24142 \end_layout
24143
24144 \end_inset
24145 </cell>
24146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24147 \begin_inset Text
24148
24149 \begin_layout Standard
24150 Compiler
24151 \end_layout
24152
24153 \end_inset
24154 </cell>
24155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24156 \begin_inset Text
24157
24158 \begin_layout Standard
24159 -I
24160 \end_layout
24161
24162 \end_inset
24163 </cell>
24164 </row>
24165 <row topline="true" bottomline="true">
24166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24167 \begin_inset Text
24168
24169 \begin_layout Standard
24170 PREFIX/sdcc/lib/pic16
24171 \end_layout
24172
24173 \end_inset
24174 </cell>
24175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24176 \begin_inset Text
24177
24178 \begin_layout Standard
24179 PIC16 specific libraries
24180 \end_layout
24181
24182 \end_inset
24183 </cell>
24184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24185 \begin_inset Text
24186
24187 \begin_layout Standard
24188 Linker
24189 \end_layout
24190
24191 \end_inset
24192 </cell>
24193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24194 \begin_inset Text
24195
24196 \begin_layout Standard
24197 -L
24198 \end_layout
24199
24200 \end_inset
24201 </cell>
24202 </row>
24203 </lyxtabular>
24204
24205 \end_inset
24206
24207
24208 \end_layout
24209
24210 \begin_layout Subsection
24211 Pragmas
24212 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24213
24214 \end_inset
24215
24216
24217 \end_layout
24218
24219 \begin_layout Standard
24220 The PIC16
24221 \begin_inset LatexCommand \index{PIC16}
24222
24223 \end_inset
24224
24225  port currently supports the following pragmas:
24226 \end_layout
24227
24228 \begin_layout Description
24229 stack
24230 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24231
24232 \end_inset
24233
24234  This forces the code generator to initialize the stack & frame pointers
24235  at a specific address.
24236  This is an ad hoc solution for cases where no STACK directive is available
24237  in the linker script or gplink is not instructed to create a stack section.
24238 \newline
24239 The
24240  stack pragma should be used only once in a project.
24241  Multiple pragmas may result in indeterminate behaviour of the program.
24242 \begin_inset Foot
24243 status open
24244
24245 \begin_layout Standard
24246 The old format (ie.
24247  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24248  cross page boundaries (or even exceed the available data RAM) and crash
24249  the program.
24250  Make sure that stack does not cross page boundaries when using the SMALL
24251  stack model.
24252 \end_layout
24253
24254 \end_inset
24255
24256
24257 \newline
24258 The format is as follows:
24259 \newline
24260
24261 \end_layout
24262
24263 \begin_layout LyX-Code
24264 #pragma stack bottom_address [stack_size]
24265 \newline
24266
24267 \end_layout
24268
24269 \begin_layout Standard
24270
24271 \emph on
24272 bottom_address
24273 \emph default
24274  is the lower bound of the stack section.
24275  The stack pointer initially will point at address (bottom_address+stack_size-1).
24276 \end_layout
24277
24278 \begin_layout LyX-Code
24279 Example:
24280 \end_layout
24281
24282 \begin_layout LyX-Code
24283
24284 \end_layout
24285
24286 \begin_layout LyX-Code
24287 /* initializes stack of 100 bytes at RAM address 0x200 */
24288 \end_layout
24289
24290 \begin_layout LyX-Code
24291 #pragma stack 0x200 100
24292 \end_layout
24293
24294 \begin_layout Standard
24295 If the stack_size field is omitted then a stack is created with the default
24296  size of 64.
24297  This size might be enough for most programs, but its not enough for operations
24298  with deep function nesting or excessive stack usage.
24299 \end_layout
24300
24301 \begin_layout Description
24302 code
24303 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24304
24305 \end_inset
24306
24307  Force a function to a static FLASH address.
24308 \end_layout
24309
24310 \begin_layout LyX-Code
24311 Example:
24312 \end_layout
24313
24314 \begin_layout LyX-Code
24315
24316 \end_layout
24317
24318 \begin_layout LyX-Code
24319 /* place function test_func at 0x4000 */
24320 \end_layout
24321
24322 \begin_layout LyX-Code
24323 #pragma code test_func 0x4000
24324 \end_layout
24325
24326 \begin_layout LyX-Code
24327
24328 \end_layout
24329
24330 \begin_layout Description
24331 library instructs the linker to use a library module.
24332 \newline
24333 Usage:
24334 \end_layout
24335
24336 \begin_layout LyX-Code
24337 #pragma library module_name
24338 \end_layout
24339
24340 \begin_layout Standard
24341
24342 \emph on
24343 module_name
24344 \emph default
24345  can be any library or object file (including its path).
24346  Note that there are four reserved keywords which have special meaning.
24347  These are:
24348 \end_layout
24349
24350 \begin_layout Standard
24351 \align center
24352 \begin_inset Tabular
24353 <lyxtabular version="3" rows="6" columns="3">
24354 <features>
24355 <column alignment="center" valignment="top" leftline="true" width="0">
24356 <column alignment="block" valignment="top" leftline="true" width="20page%">
24357 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24358 <row topline="true" bottomline="true">
24359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24360 \begin_inset Text
24361
24362 \begin_layout Standard
24363 Keyword
24364 \end_layout
24365
24366 \end_inset
24367 </cell>
24368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24369 \begin_inset Text
24370
24371 \begin_layout Standard
24372 Description
24373 \end_layout
24374
24375 \end_inset
24376 </cell>
24377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24378 \begin_inset Text
24379
24380 \begin_layout Standard
24381 Module to link
24382 \end_layout
24383
24384 \end_inset
24385 </cell>
24386 </row>
24387 <row topline="true">
24388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24389 \begin_inset Text
24390
24391 \begin_layout Standard
24392
24393 \series bold
24394 ignore
24395 \end_layout
24396
24397 \end_inset
24398 </cell>
24399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24400 \begin_inset Text
24401
24402 \begin_layout Standard
24403 ignore all library pragmas
24404 \end_layout
24405
24406 \end_inset
24407 </cell>
24408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24409 \begin_inset Text
24410
24411 \begin_layout Standard
24412
24413 \emph on
24414 (none)
24415 \end_layout
24416
24417 \end_inset
24418 </cell>
24419 </row>
24420 <row topline="true">
24421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24422 \begin_inset Text
24423
24424 \begin_layout Standard
24425
24426 \series bold
24427 c
24428 \end_layout
24429
24430 \end_inset
24431 </cell>
24432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24433 \begin_inset Text
24434
24435 \begin_layout Standard
24436 link the C library
24437 \end_layout
24438
24439 \end_inset
24440 </cell>
24441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24442 \begin_inset Text
24443
24444 \begin_layout Standard
24445
24446 \emph on
24447 libc18f
24448 \emph default
24449 .lib
24450 \end_layout
24451
24452 \end_inset
24453 </cell>
24454 </row>
24455 <row topline="true">
24456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24457 \begin_inset Text
24458
24459 \begin_layout Standard
24460
24461 \series bold
24462 math
24463 \end_layout
24464
24465 \end_inset
24466 </cell>
24467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24468 \begin_inset Text
24469
24470 \begin_layout Standard
24471 link the Math libarary
24472 \end_layout
24473
24474 \end_inset
24475 </cell>
24476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24477 \begin_inset Text
24478
24479 \begin_layout Standard
24480
24481 \emph on
24482 libm18f
24483 \emph default
24484 .lib
24485 \end_layout
24486
24487 \end_inset
24488 </cell>
24489 </row>
24490 <row topline="true">
24491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24492 \begin_inset Text
24493
24494 \begin_layout Standard
24495
24496 \series bold
24497 io
24498 \end_layout
24499
24500 \end_inset
24501 </cell>
24502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24503 \begin_inset Text
24504
24505 \begin_layout Standard
24506 link the I/O library
24507 \end_layout
24508
24509 \end_inset
24510 </cell>
24511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24512 \begin_inset Text
24513
24514 \begin_layout Standard
24515
24516 \emph on
24517 libio18f*
24518 \emph default
24519 .lib
24520 \end_layout
24521
24522 \end_inset
24523 </cell>
24524 </row>
24525 <row topline="true" bottomline="true">
24526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24527 \begin_inset Text
24528
24529 \begin_layout Standard
24530
24531 \series bold
24532 debug
24533 \end_layout
24534
24535 \end_inset
24536 </cell>
24537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24538 \begin_inset Text
24539
24540 \begin_layout Standard
24541 link the debug library
24542 \end_layout
24543
24544 \end_inset
24545 </cell>
24546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24547 \begin_inset Text
24548
24549 \begin_layout Standard
24550
24551 \emph on
24552 libdebug
24553 \emph default
24554 .lib
24555 \end_layout
24556
24557 \end_inset
24558 </cell>
24559 </row>
24560 </lyxtabular>
24561
24562 \end_inset
24563
24564
24565 \newline
24566 * is the device number, i.e.
24567  452 for PIC18F452 MCU.
24568 \end_layout
24569
24570 \begin_layout Standard
24571 This feature allows for linking with specific libraries withoug having to
24572  explicit name them in the command line.
24573  Note that the 
24574 \noun on
24575 ignore
24576 \noun default
24577  keyword will reject all modules specified by the library pragma.
24578 \end_layout
24579
24580 \begin_layout Description
24581 udata The pragma udata instructs the compiler to emit code so that linker
24582  will place a variable at a specific memory bank.
24583 \end_layout
24584
24585 \begin_layout LyX-Code
24586 Example:
24587 \end_layout
24588
24589 \begin_layout LyX-Code
24590
24591 \end_layout
24592
24593 \begin_layout LyX-Code
24594 /* places variable foo at bank2 */
24595 \end_layout
24596
24597 \begin_layout LyX-Code
24598 #pragma udata bank2 foo
24599 \end_layout
24600
24601 \begin_layout LyX-Code
24602 char foo;
24603 \end_layout
24604
24605 \begin_layout Standard
24606 In order for this pragma to work extra SECTION directives should be added
24607  in the .lkr script.
24608  In the following example a sample .lkr file is shown:
24609 \end_layout
24610
24611 \begin_layout LyX-Code
24612
24613 \end_layout
24614
24615 \begin_layout LyX-Code
24616 // Sample linker script for the PIC18F452 processor
24617 \end_layout
24618
24619 \begin_layout LyX-Code
24620 LIBPATH .
24621 \end_layout
24622
24623 \begin_layout LyX-Code
24624 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24625 \end_layout
24626
24627 \begin_layout LyX-Code
24628 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24629 \end_layout
24630
24631 \begin_layout LyX-Code
24632 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24633 \end_layout
24634
24635 \begin_layout LyX-Code
24636 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24637 \end_layout
24638
24639 \begin_layout LyX-Code
24640 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24641 \end_layout
24642
24643 \begin_layout LyX-Code
24644 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24645 \end_layout
24646
24647 \begin_layout LyX-Code
24648 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24649 \end_layout
24650
24651 \begin_layout LyX-Code
24652
24653 \end_layout
24654
24655 \begin_layout LyX-Code
24656 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24657 \end_layout
24658
24659 \begin_layout LyX-Code
24660 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24661 \end_layout
24662
24663 \begin_layout LyX-Code
24664 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24665 \end_layout
24666
24667 \begin_layout LyX-Code
24668 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24669 \end_layout
24670
24671 \begin_layout LyX-Code
24672 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24673 \end_layout
24674
24675 \begin_layout LyX-Code
24676 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24677 \end_layout
24678
24679 \begin_layout LyX-Code
24680 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24681 \end_layout
24682
24683 \begin_layout LyX-Code
24684
24685 \end_layout
24686
24687 \begin_layout LyX-Code
24688 SECTION    NAME=CONFIG     ROM=config
24689 \end_layout
24690
24691 \begin_layout LyX-Code
24692
24693 \end_layout
24694
24695 \begin_layout LyX-Code
24696 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
24697 \end_layout
24698
24699 \begin_layout LyX-Code
24700 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
24701 \end_layout
24702
24703 \begin_layout LyX-Code
24704 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
24705 \end_layout
24706
24707 \begin_layout LyX-Code
24708 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
24709 \end_layout
24710
24711 \begin_layout LyX-Code
24712 SECTION    NAME=bank4      RAM=gpr4
24713 \end_layout
24714
24715 \begin_layout LyX-Code
24716 SECTION    NAME=bank5      RAM=gpr5
24717 \end_layout
24718
24719 \begin_layout Standard
24720 The linker will recognise the section name set in the pragma statement and
24721  will position the variable at the memory bank set with the RAM field at
24722  the SECTION line in the linker script file.
24723 \end_layout
24724
24725 \begin_layout Subsection
24726 Header Files
24727 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24728
24729 \end_inset
24730
24731
24732 \end_layout
24733
24734 \begin_layout Standard
24735 There is one main header file
24736 \begin_inset LatexCommand \index{PIC16!Header files}
24737
24738 \end_inset
24739
24740  that can be included to the source files using the pic16
24741 \begin_inset LatexCommand \index{PIC16}
24742
24743 \end_inset
24744
24745  port.
24746  That file is the 
24747 \series bold
24748 pic18fregs.h
24749 \series default
24750 .
24751  This header file contains the definitions for the processor special registers,
24752  so it is necessary if the source accesses them.
24753  It can be included by adding the following line in the beginning of the
24754  file:
24755 \end_layout
24756
24757 \begin_layout LyX-Code
24758 #include <pic18fregs.h>
24759 \end_layout
24760
24761 \begin_layout Standard
24762 The specific microcontroller is selected within the pic18fregs.h automatically,
24763  so the same source can be used with a variety of devices.
24764 \end_layout
24765
24766 \begin_layout Subsection
24767 Libraries
24768 \end_layout
24769
24770 \begin_layout Standard
24771 The libraries
24772 \begin_inset LatexCommand \index{PIC16!Libraries}
24773
24774 \end_inset
24775
24776  that PIC16
24777 \begin_inset LatexCommand \index{PIC16}
24778
24779 \end_inset
24780
24781  port depends on are the microcontroller device libraries which contain
24782  the symbol definitions for the microcontroller special function registers.
24783  These libraries have the format pic18fxxxx.lib, where 
24784 \emph on
24785 xxxx
24786 \emph default
24787  is the microcontroller identification number.
24788  The specific library is selected automatically by the compiler at link
24789  stage according to the selected device.
24790 \end_layout
24791
24792 \begin_layout Standard
24793 Libraries are created with gplib which is part of the gputils package 
24794 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24795
24796 \end_inset
24797
24798 .
24799 \end_layout
24800
24801 \begin_layout Subsubsection*
24802 Building the libraries
24803 \end_layout
24804
24805 \begin_layout Standard
24806 Before using SDCC/pic16 there are some libraries that need to be compiled.
24807  This process is not done automatically by SDCC since not all users use
24808  SDCC for pic16 projects.
24809  So each user should compile the libraries separately.
24810 \end_layout
24811
24812 \begin_layout Standard
24813 The steps to compile the pic16 libraries under Linux and Mac OS X are:
24814 \end_layout
24815
24816 \begin_layout LyX-Code
24817 cd device/lib/pic16
24818 \end_layout
24819
24820 \begin_layout LyX-Code
24821 ./configure
24822 \end_layout
24823
24824 \begin_layout LyX-Code
24825 make
24826 \end_layout
24827
24828 \begin_layout LyX-Code
24829 cd ..
24830 \end_layout
24831
24832 \begin_layout LyX-Code
24833 make model-pic16
24834 \end_layout
24835
24836 \begin_layout LyX-Code
24837 su -c 'make install'     # install the libraries, you need the root password
24838 \end_layout
24839
24840 \begin_layout Standard
24841 If you need to install the headers too, do:
24842 \end_layout
24843
24844 \begin_layout LyX-Code
24845 cd device/include
24846 \end_layout
24847
24848 \begin_layout LyX-Code
24849 su -c 'make install'     # install the headers, you need the root password
24850 \end_layout
24851
24852 \begin_layout Standard
24853 There exist a special target to build the I/O libraries.
24854  This target is not automatically build because it will build the I/O library
24855  for 
24856 \emph on
24857 every
24858 \emph default
24859  supported device.
24860  This way building will take quite a lot of time.
24861  Users are advised to edit the 
24862 \series bold
24863 device/lib/pic16/pics.build
24864 \series default
24865  file and then execute:
24866 \end_layout
24867
24868 \begin_layout LyX-Code
24869 make lib-io
24870 \end_layout
24871
24872 \begin_layout Subsection
24873 Adding New Devices to the Port
24874 \end_layout
24875
24876 \begin_layout Standard
24877 Adding support for a new 16
24878 \begin_inset ERT
24879 status open
24880
24881 \begin_layout Standard
24882
24883
24884 \backslash
24885 ,
24886 \end_layout
24887
24888 \end_inset
24889
24890 bit PIC MCU requires the following steps:
24891 \end_layout
24892
24893 \begin_layout Enumerate
24894 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
24895 \newline
24896
24897 \family typewriter
24898 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
24899 inc
24900 \end_layout
24901
24902 \begin_layout Enumerate
24903
24904 \family typewriter
24905 mv picDEVICE.h /path/to/sdcc/device/include/pic16
24906 \end_layout
24907
24908 \begin_layout Enumerate
24909
24910 \family typewriter
24911 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
24912 \end_layout
24913
24914 \begin_layout Enumerate
24915 Add DEVICE to 
24916 \family typewriter
24917 /path/to/sdcc/device/lib/pics.all
24918 \family default
24919  (and 
24920 \family typewriter
24921 .build
24922 \family default
24923 ).
24924 \newline
24925 Note: No 18f prefix here!
24926 \end_layout
24927
24928 \begin_layout Enumerate
24929 Adjust 
24930 \family typewriter
24931 /path/to/sdcc/device/lib/pic16/libio/*.ignore
24932 \family default
24933
24934 \newline
24935 Add your DEVICE if it does not compile in 
24936 \family typewriter
24937 adc
24938 \family default
24939
24940 \family typewriter
24941 i2c
24942 \family default
24943 , or 
24944 \family typewriter
24945 usart
24946 \family default
24947 .
24948 \end_layout
24949
24950 \begin_layout Enumerate
24951 Edit 
24952 \family typewriter
24953 /path/to/sdcc/device/include/pic16/pic18fregs.h
24954 \family default
24955 .
24956  The file format is self-explanatory, just add
24957 \newline
24958
24959 \family typewriter
24960 #elif defined(picDEVICE)
24961 \newline
24962 # include <picDEVICE.h>
24963 \family default
24964
24965 \newline
24966 at the right place (keep it sorted).
24967 \end_layout
24968
24969 \begin_layout Enumerate
24970 Edit 
24971 \family typewriter
24972 /path/to/sdcc/src/pic16/devices.inc
24973 \family default
24974 .
24975  Copy and modify an existing entry and insert it at the correct place (keep
24976  the file sorted).
24977  The file is hardly documented, look at the entries for the 18f2221...
24978 \end_layout
24979
24980 \begin_layout Enumerate
24981 Recompile SDCC, including the pic16 libraries.
24982 \end_layout
24983
24984 \begin_layout Subsection
24985 Memory Models
24986 \end_layout
24987
24988 \begin_layout Standard
24989 The following memory models are supported by the PIC16 port:
24990 \end_layout
24991
24992 \begin_layout Itemize
24993 small model
24994 \end_layout
24995
24996 \begin_layout Itemize
24997 large model
24998 \end_layout
24999
25000 \begin_layout Standard
25001 Memory model affects the default size of pointers within the source.
25002  The sizes are shown in the next table:
25003 \end_layout
25004
25005 \begin_layout Standard
25006 \align center
25007 \begin_inset Tabular
25008 <lyxtabular version="3" rows="3" columns="3">
25009 <features>
25010 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25011 <column alignment="center" valignment="top" leftline="true" width="0">
25012 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25013 <row topline="true" bottomline="true">
25014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25015 \begin_inset Text
25016
25017 \begin_layout Standard
25018 Pointer sizes according to memory model
25019 \end_layout
25020
25021 \end_inset
25022 </cell>
25023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25024 \begin_inset Text
25025
25026 \begin_layout Standard
25027 small model
25028 \end_layout
25029
25030 \end_inset
25031 </cell>
25032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25033 \begin_inset Text
25034
25035 \begin_layout Standard
25036 large model
25037 \end_layout
25038
25039 \end_inset
25040 </cell>
25041 </row>
25042 <row topline="true" bottomline="true">
25043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25044 \begin_inset Text
25045
25046 \begin_layout Standard
25047 code pointers
25048 \end_layout
25049
25050 \end_inset
25051 </cell>
25052 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25053 \begin_inset Text
25054
25055 \begin_layout Standard
25056 16-bits
25057 \end_layout
25058
25059 \end_inset
25060 </cell>
25061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25062 \begin_inset Text
25063
25064 \begin_layout Standard
25065 24-bits
25066 \end_layout
25067
25068 \end_inset
25069 </cell>
25070 </row>
25071 <row topline="true" bottomline="true">
25072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25073 \begin_inset Text
25074
25075 \begin_layout Standard
25076 data pointers
25077 \end_layout
25078
25079 \end_inset
25080 </cell>
25081 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25082 \begin_inset Text
25083
25084 \begin_layout Standard
25085 16-bits
25086 \end_layout
25087
25088 \end_inset
25089 </cell>
25090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25091 \begin_inset Text
25092
25093 \begin_layout Standard
25094 16-bits
25095 \end_layout
25096
25097 \end_inset
25098 </cell>
25099 </row>
25100 </lyxtabular>
25101
25102 \end_inset
25103
25104
25105 \end_layout
25106
25107 \begin_layout Standard
25108 It is advisable that all sources within a project are compiled with the
25109  same memory model.
25110  If one wants to override the default memory model, this can be done by
25111  declaring a pointer as 
25112 \series bold
25113 far
25114 \series default
25115  or 
25116 \series bold
25117 near
25118 \series default
25119 .
25120  Far selects large memory model's pointers, while near selects small memory
25121  model's pointers.
25122 \end_layout
25123
25124 \begin_layout Standard
25125 The standard device libraries (see 
25126 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25127
25128 \end_inset
25129
25130 ) contain no reference to pointers, so they can be used with both memory
25131  models.
25132 \end_layout
25133
25134 \begin_layout Subsection
25135 Stack
25136 \end_layout
25137
25138 \begin_layout Standard
25139 The stack
25140 \begin_inset LatexCommand \index{PIC16!stack}
25141
25142 \end_inset
25143
25144  implementation for the PIC16 port uses two indirect registers, FSR1 and
25145  FSR2.
25146 \end_layout
25147
25148 \begin_layout Description
25149 FSR1 is assigned as stack pointer
25150 \end_layout
25151
25152 \begin_layout Description
25153 FSR2 is assigned as frame pointer
25154 \end_layout
25155
25156 \begin_layout Standard
25157 The following stack models are supported by the PIC16 port
25158 \end_layout
25159
25160 \begin_layout Itemize
25161
25162 \noun on
25163 small
25164 \noun default
25165  model
25166 \end_layout
25167
25168 \begin_layout Itemize
25169
25170 \noun on
25171 large
25172 \noun default
25173  model
25174 \end_layout
25175
25176 \begin_layout Standard
25177
25178 \noun on
25179 Small
25180 \noun default
25181  model means that only the FSRxL byte is used to access stack and frame,
25182  while 
25183 \emph on
25184 \noun on
25185 large
25186 \emph default
25187 \noun default
25188  uses both FSRxL and FSRxH registers.
25189  The following table shows the stack/frame pointers sizes according to stack
25190  model and the maximum space they can address:
25191 \end_layout
25192
25193 \begin_layout Standard
25194 \align center
25195 \begin_inset Tabular
25196 <lyxtabular version="3" rows="3" columns="3">
25197 <features>
25198 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25199 <column alignment="center" valignment="top" leftline="true" width="0">
25200 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25201 <row topline="true" bottomline="true">
25202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25203 \begin_inset Text
25204
25205 \begin_layout Standard
25206 Stack & Frame pointer sizes according to stack model
25207 \end_layout
25208
25209 \end_inset
25210 </cell>
25211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25212 \begin_inset Text
25213
25214 \begin_layout Standard
25215 small
25216 \end_layout
25217
25218 \end_inset
25219 </cell>
25220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25221 \begin_inset Text
25222
25223 \begin_layout Standard
25224 large
25225 \end_layout
25226
25227 \end_inset
25228 </cell>
25229 </row>
25230 <row topline="true">
25231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25232 \begin_inset Text
25233
25234 \begin_layout Standard
25235 Stack pointer FSR1
25236 \end_layout
25237
25238 \end_inset
25239 </cell>
25240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25241 \begin_inset Text
25242
25243 \begin_layout Standard
25244 8-bits
25245 \end_layout
25246
25247 \end_inset
25248 </cell>
25249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25250 \begin_inset Text
25251
25252 \begin_layout Standard
25253 16-bits
25254 \end_layout
25255
25256 \end_inset
25257 </cell>
25258 </row>
25259 <row topline="true" bottomline="true">
25260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25261 \begin_inset Text
25262
25263 \begin_layout Standard
25264 Frame pointer FSR2
25265 \end_layout
25266
25267 \end_inset
25268 </cell>
25269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25270 \begin_inset Text
25271
25272 \begin_layout Standard
25273 8-bits
25274 \end_layout
25275
25276 \end_inset
25277 </cell>
25278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25279 \begin_inset Text
25280
25281 \begin_layout Standard
25282 16-bits
25283 \end_layout
25284
25285 \end_inset
25286 </cell>
25287 </row>
25288 </lyxtabular>
25289
25290 \end_inset
25291
25292
25293 \end_layout
25294
25295 \begin_layout Standard
25296
25297 \noun on
25298 Large 
25299 \noun default
25300 stack model is currently not working properly throughout the code generator.
25301  So its use is not advised.
25302  Also there are some other points that need special care:
25303 \newline
25304
25305 \end_layout
25306
25307 \begin_layout Enumerate
25308 Do not create stack sections with size more than one physical bank (that
25309  is 256 bytes)
25310 \end_layout
25311
25312 \begin_layout Enumerate
25313 Stack sections should no cross physical bank limits (i.e.
25314  #pragma stack 0x50 0x100)
25315 \end_layout
25316
25317 \begin_layout Standard
25318 These limitations are caused by the fact that only FSRxL is modified when
25319  using SMALL stack model, so no more than 256 bytes of stack can be used.
25320  This problem will disappear after LARGE model is fully implemented.
25321 \end_layout
25322
25323 \begin_layout Subsection
25324 Functions
25325 \end_layout
25326
25327 \begin_layout Standard
25328 In addition to the standard SDCC function keywords, PIC16
25329 \begin_inset LatexCommand \index{PIC16}
25330
25331 \end_inset
25332
25333  port makes available two more:
25334 \end_layout
25335
25336 \begin_layout Description
25337 wparam
25338 \begin_inset LatexCommand \index{PIC16!wparam}
25339
25340 \end_inset
25341
25342  Use the WREG to pass one byte of the first function argument.
25343  This improves speed but you may not use this for functions with arguments
25344  that are called via function pointers, otherwise the first byte of the
25345  first parameter will get lost.
25346  Usage:
25347 \end_layout
25348
25349 \begin_layout LyX-Code
25350 void func_wparam(int a) wparam
25351 \end_layout
25352
25353 \begin_layout LyX-Code
25354 {
25355 \end_layout
25356
25357 \begin_layout LyX-Code
25358     /* WREG hold the lower part of a */
25359 \end_layout
25360
25361 \begin_layout LyX-Code
25362     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25363  */
25364 \end_layout
25365
25366 \begin_layout LyX-Code
25367 ...
25368 \end_layout
25369
25370 \begin_layout LyX-Code
25371 }
25372 \end_layout
25373
25374 \begin_layout Description
25375 shadowregs
25376 \begin_inset LatexCommand \index{PIC16!shadowregs}
25377
25378 \end_inset
25379
25380  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25381  hardware shadow registers which hold the values of WREG, STATUS and BSR
25382  registers.
25383  This can be done by adding the keyword 
25384 \emph on
25385 shadowregs
25386 \emph default
25387  before the 
25388 \emph on
25389 interrupt
25390 \emph default
25391  keyword in the function's header.
25392 \end_layout
25393
25394 \begin_layout LyX-Code
25395 void isr_shadow(void) shadowregs interrupt 1
25396 \end_layout
25397
25398 \begin_layout LyX-Code
25399 {
25400 \end_layout
25401
25402 \begin_layout LyX-Code
25403 ...
25404 \end_layout
25405
25406 \begin_layout LyX-Code
25407 }
25408 \end_layout
25409
25410 \begin_layout Standard
25411
25412 \emph on
25413 shadowregs
25414 \emph default
25415  instructs the code generator not to store/restore WREG, STATUS, BSR when
25416  entering/exiting the ISR.
25417 \end_layout
25418
25419 \begin_layout Subsection
25420 Function return values
25421 \end_layout
25422
25423 \begin_layout Standard
25424 Return values from functions are placed to the appropriate registers following
25425  a modified Microchip policy optimized for SDCC.
25426  The following table shows these registers:
25427 \end_layout
25428
25429 \begin_layout Standard
25430 \align center
25431 \begin_inset Tabular
25432 <lyxtabular version="3" rows="6" columns="2">
25433 <features>
25434 <column alignment="center" valignment="top" leftline="true" width="0">
25435 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25436 <row topline="true" bottomline="true">
25437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25438 \begin_inset Text
25439
25440 \begin_layout Standard
25441 size
25442 \end_layout
25443
25444 \end_inset
25445 </cell>
25446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25447 \begin_inset Text
25448
25449 \begin_layout Standard
25450 destination register
25451 \end_layout
25452
25453 \end_inset
25454 </cell>
25455 </row>
25456 <row topline="true">
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25458 \begin_inset Text
25459
25460 \begin_layout Standard
25461 8 bits
25462 \end_layout
25463
25464 \end_inset
25465 </cell>
25466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25467 \begin_inset Text
25468
25469 \begin_layout Standard
25470 WREG
25471 \end_layout
25472
25473 \end_inset
25474 </cell>
25475 </row>
25476 <row topline="true">
25477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25478 \begin_inset Text
25479
25480 \begin_layout Standard
25481 16 bits
25482 \end_layout
25483
25484 \end_inset
25485 </cell>
25486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25487 \begin_inset Text
25488
25489 \begin_layout Standard
25490 PRODL:WREG
25491 \end_layout
25492
25493 \end_inset
25494 </cell>
25495 </row>
25496 <row topline="true">
25497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25498 \begin_inset Text
25499
25500 \begin_layout Standard
25501 24 bits
25502 \end_layout
25503
25504 \end_inset
25505 </cell>
25506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25507 \begin_inset Text
25508
25509 \begin_layout Standard
25510 PRODH:PRODL:WREG
25511 \end_layout
25512
25513 \end_inset
25514 </cell>
25515 </row>
25516 <row topline="true">
25517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25518 \begin_inset Text
25519
25520 \begin_layout Standard
25521 32 bits
25522 \end_layout
25523
25524 \end_inset
25525 </cell>
25526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25527 \begin_inset Text
25528
25529 \begin_layout Standard
25530 FSR0L:PRODH:PRODL:WREG
25531 \end_layout
25532
25533 \end_inset
25534 </cell>
25535 </row>
25536 <row topline="true" bottomline="true">
25537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25538 \begin_inset Text
25539
25540 \begin_layout Standard
25541 >32 bits
25542 \end_layout
25543
25544 \end_inset
25545 </cell>
25546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25547 \begin_inset Text
25548
25549 \begin_layout Standard
25550 on stack, FSR0 points to the beginning
25551 \end_layout
25552
25553 \end_inset
25554 </cell>
25555 </row>
25556 </lyxtabular>
25557
25558 \end_inset
25559
25560
25561 \end_layout
25562
25563 \begin_layout Subsection
25564 Interrupts
25565 \end_layout
25566
25567 \begin_layout Standard
25568 An interrupt
25569 \begin_inset LatexCommand \index{PIC16!interrupt}
25570
25571 \end_inset
25572
25573  service routine (ISR) is declared using the 
25574 \emph on
25575 interrupt
25576 \emph default
25577  keyword.
25578 \end_layout
25579
25580 \begin_layout LyX-Code
25581 void isr(void) interrupt 
25582 \emph on
25583 n
25584 \end_layout
25585
25586 \begin_layout LyX-Code
25587 {
25588 \end_layout
25589
25590 \begin_layout LyX-Code
25591 ...
25592 \end_layout
25593
25594 \begin_layout LyX-Code
25595 }
25596 \end_layout
25597
25598 \begin_layout Standard
25599
25600 \emph on
25601 n
25602 \emph default
25603  is the interrupt number, which for PIC18F devices can be:
25604 \end_layout
25605
25606 \begin_layout Standard
25607 \align center
25608 \begin_inset Tabular
25609 <lyxtabular version="3" rows="4" columns="3">
25610 <features>
25611 <column alignment="center" valignment="top" leftline="true" width="0">
25612 <column alignment="center" valignment="top" leftline="true" width="0">
25613 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25614 <row topline="true" bottomline="true">
25615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25616 \begin_inset Text
25617
25618 \begin_layout Standard
25619
25620 \emph on
25621 n
25622 \end_layout
25623
25624 \end_inset
25625 </cell>
25626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25627 \begin_inset Text
25628
25629 \begin_layout Standard
25630 Interrupt Vector
25631 \end_layout
25632
25633 \end_inset
25634 </cell>
25635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25636 \begin_inset Text
25637
25638 \begin_layout Standard
25639 Interrupt Vector Address
25640 \end_layout
25641
25642 \end_inset
25643 </cell>
25644 </row>
25645 <row topline="true">
25646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25647 \begin_inset Text
25648
25649 \begin_layout Standard
25650 0
25651 \end_layout
25652
25653 \end_inset
25654 </cell>
25655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25656 \begin_inset Text
25657
25658 \begin_layout Standard
25659 RESET vector
25660 \end_layout
25661
25662 \end_inset
25663 </cell>
25664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25665 \begin_inset Text
25666
25667 \begin_layout Standard
25668 0x000000
25669 \end_layout
25670
25671 \end_inset
25672 </cell>
25673 </row>
25674 <row topline="true">
25675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25676 \begin_inset Text
25677
25678 \begin_layout Standard
25679
25680 \family roman
25681 \series medium
25682 \shape up
25683 \size normal
25684 \emph off
25685 \bar no
25686 \noun off
25687 \color none
25688 1
25689 \end_layout
25690
25691 \end_inset
25692 </cell>
25693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25694 \begin_inset Text
25695
25696 \begin_layout Standard
25697
25698 \family roman
25699 \series medium
25700 \shape up
25701 \size normal
25702 \emph off
25703 \bar no
25704 \noun off
25705 \color none
25706 HIGH priority interrupts
25707 \end_layout
25708
25709 \end_inset
25710 </cell>
25711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25712 \begin_inset Text
25713
25714 \begin_layout Standard
25715 0x000008
25716 \end_layout
25717
25718 \end_inset
25719 </cell>
25720 </row>
25721 <row topline="true" bottomline="true">
25722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25723 \begin_inset Text
25724
25725 \begin_layout Standard
25726 2
25727 \end_layout
25728
25729 \end_inset
25730 </cell>
25731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25732 \begin_inset Text
25733
25734 \begin_layout Standard
25735 LOW priority interrupts
25736 \end_layout
25737
25738 \end_inset
25739 </cell>
25740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25741 \begin_inset Text
25742
25743 \begin_layout Standard
25744 0x000018
25745 \end_layout
25746
25747 \end_inset
25748 </cell>
25749 </row>
25750 </lyxtabular>
25751
25752 \end_inset
25753
25754
25755 \end_layout
25756
25757 \begin_layout Standard
25758 When generating assembly code for ISR the code generator places a 
25759 \noun on
25760 goto 
25761 \noun default
25762 instruction at the 
25763 \emph on
25764 Interrupt Vector Address
25765 \emph default
25766  which points at the genetated ISR.
25767  This single GOTO instruction is part of an automatically generated 
25768 \emph on
25769 interrupt entry point
25770 \emph default
25771  function.
25772  The actuall ISR code is placed as normally would in the code space.
25773  Upon interrupt request, the GOTO instruction is executed which jumps to
25774  the ISR code.
25775  When declaring interrupt functions as _naked this GOTO instruction is 
25776 \series bold
25777 not
25778 \series default
25779  generated.
25780  The whole interrupt functions is therefore placed at the Interrupt Vector
25781  Address of the specific interrupt.
25782  This is not a problem for the LOW priority interrupts, but it is a problem
25783  for the RESET and the HIGH priority interrupts because code may be written
25784  at the next interrupt´s vector address and cause undeterminate program
25785  behaviour if that interrupt is raised.
25786 \begin_inset Foot
25787 status open
25788
25789 \begin_layout Standard
25790 This is not a problem when
25791 \end_layout
25792
25793 \begin_layout Enumerate
25794 this is a HIGH interrupt ISR and LOW interrupts are 
25795 \emph on
25796 disabled
25797 \emph default
25798  or not used.
25799 \end_layout
25800
25801 \begin_layout Enumerate
25802 when the ISR is small enough not to reach the next interrupt´s vector address.
25803 \end_layout
25804
25805 \end_inset
25806
25807
25808 \end_layout
25809
25810 \begin_layout Standard
25811
25812 \emph on
25813 n
25814 \emph default
25815  is possible to be omitted.
25816  This way a function is generated similar to an ISR, but it is not assigned
25817  to any interrupt.
25818 \end_layout
25819
25820 \begin_layout Standard
25821 When entering an interrupt, currently the PIC16
25822 \begin_inset LatexCommand \index{PIC16}
25823
25824 \end_inset
25825
25826  port automatically saves the following registers:
25827 \end_layout
25828
25829 \begin_layout Itemize
25830 WREG
25831 \end_layout
25832
25833 \begin_layout Itemize
25834 STATUS
25835 \end_layout
25836
25837 \begin_layout Itemize
25838 BSR
25839 \end_layout
25840
25841 \begin_layout Itemize
25842 PROD (PRODL and PRODH)
25843 \end_layout
25844
25845 \begin_layout Itemize
25846 FSR0 (FSR0L and FSR0H)
25847 \end_layout
25848
25849 \begin_layout Standard
25850 These registers are restored upon return from the interrupt routine.
25851 \begin_inset Foot
25852 status open
25853
25854 \begin_layout Standard
25855 NOTE that when the _naked attribute is specified for an interrupt routine,
25856  then NO registers are stored or restored.
25857 \end_layout
25858
25859 \end_inset
25860
25861
25862 \end_layout
25863
25864 \begin_layout Subsection
25865 Generic Pointers
25866 \end_layout
25867
25868 \begin_layout Standard
25869 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25870  There are 3 types of generic pointers currently implemented data, code
25871  and eeprom pointers.
25872  They are differentiated by the value of the 7th and 6th bits of the upper
25873  byte:
25874 \end_layout
25875
25876 \begin_layout Standard
25877 \align center
25878 \begin_inset Tabular
25879 <lyxtabular version="3" rows="5" columns="5">
25880 <features>
25881 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25882 <column alignment="center" valignment="top" width="0">
25883 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25884 <column alignment="center" valignment="top" width="0">
25885 <column alignment="left" valignment="top" rightline="true" width="0">
25886 <row topline="true" bottomline="true">
25887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25888 \begin_inset Text
25889
25890 \begin_layout Standard
25891 pointer type
25892 \end_layout
25893
25894 \end_inset
25895 </cell>
25896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25897 \begin_inset Text
25898
25899 \begin_layout Standard
25900 7th bit
25901 \end_layout
25902
25903 \end_inset
25904 </cell>
25905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25906 \begin_inset Text
25907
25908 \begin_layout Standard
25909 6th bit
25910 \end_layout
25911
25912 \end_inset
25913 </cell>
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25915 \begin_inset Text
25916
25917 \begin_layout Standard
25918 rest of the pointer
25919 \end_layout
25920
25921 \end_inset
25922 </cell>
25923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25924 \begin_inset Text
25925
25926 \begin_layout Standard
25927 description
25928 \end_layout
25929
25930 \end_inset
25931 </cell>
25932 </row>
25933 <row topline="true" bottomline="true">
25934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25935 \begin_inset Text
25936
25937 \begin_layout Standard
25938 data 
25939 \end_layout
25940
25941 \end_inset
25942 </cell>
25943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25944 \begin_inset Text
25945
25946 \begin_layout Standard
25947 1
25948 \end_layout
25949
25950 \end_inset
25951 </cell>
25952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25953 \begin_inset Text
25954
25955 \begin_layout Standard
25956 0
25957 \end_layout
25958
25959 \end_inset
25960 </cell>
25961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25962 \begin_inset Text
25963
25964 \begin_layout Standard
25965
25966 \family typewriter
25967 \shape slanted
25968 \emph on
25969 uuuuuu uuuuxxxx xxxxxxxx
25970 \end_layout
25971
25972 \end_inset
25973 </cell>
25974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25975 \begin_inset Text
25976
25977 \begin_layout Standard
25978 a 12-bit data pointer in data RAM memory
25979 \end_layout
25980
25981 \end_inset
25982 </cell>
25983 </row>
25984 <row bottomline="true">
25985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25986 \begin_inset Text
25987
25988 \begin_layout Standard
25989 code
25990 \end_layout
25991
25992 \end_inset
25993 </cell>
25994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25995 \begin_inset Text
25996
25997 \begin_layout Standard
25998 0
25999 \end_layout
26000
26001 \end_inset
26002 </cell>
26003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26004 \begin_inset Text
26005
26006 \begin_layout Standard
26007 0
26008 \end_layout
26009
26010 \end_inset
26011 </cell>
26012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26013 \begin_inset Text
26014
26015 \begin_layout Standard
26016
26017 \family typewriter
26018 \shape slanted
26019 \emph on
26020 uxxxxx xxxxxxxx xxxxxxxx
26021 \end_layout
26022
26023 \end_inset
26024 </cell>
26025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26026 \begin_inset Text
26027
26028 \begin_layout Standard
26029 a 21-bit code pointer in FLASH memory
26030 \end_layout
26031
26032 \end_inset
26033 </cell>
26034 </row>
26035 <row bottomline="true">
26036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26037 \begin_inset Text
26038
26039 \begin_layout Standard
26040 eeprom
26041 \end_layout
26042
26043 \end_inset
26044 </cell>
26045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26046 \begin_inset Text
26047
26048 \begin_layout Standard
26049 0
26050 \end_layout
26051
26052 \end_inset
26053 </cell>
26054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26055 \begin_inset Text
26056
26057 \begin_layout Standard
26058 1
26059 \end_layout
26060
26061 \end_inset
26062 </cell>
26063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26064 \begin_inset Text
26065
26066 \begin_layout Standard
26067
26068 \family typewriter
26069 \shape slanted
26070 \emph on
26071 uuuuuu uuuuuuxx xxxxxxxx
26072 \end_layout
26073
26074 \end_inset
26075 </cell>
26076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26077 \begin_inset Text
26078
26079 \begin_layout Standard
26080 a 10-bit eeprom pointer in EEPROM memory
26081 \end_layout
26082
26083 \end_inset
26084 </cell>
26085 </row>
26086 <row bottomline="true">
26087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26088 \begin_inset Text
26089
26090 \begin_layout Standard
26091 (unimplemented)
26092 \end_layout
26093
26094 \end_inset
26095 </cell>
26096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26097 \begin_inset Text
26098
26099 \begin_layout Standard
26100 1
26101 \end_layout
26102
26103 \end_inset
26104 </cell>
26105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26106 \begin_inset Text
26107
26108 \begin_layout Standard
26109 1
26110 \end_layout
26111
26112 \end_inset
26113 </cell>
26114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26115 \begin_inset Text
26116
26117 \begin_layout Standard
26118
26119 \family typewriter
26120 \shape slanted
26121 \emph on
26122 xxxxxx xxxxxxxx xxxxxxxx
26123 \end_layout
26124
26125 \end_inset
26126 </cell>
26127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26128 \begin_inset Text
26129
26130 \begin_layout Standard
26131 unimplemented pointer type
26132 \end_layout
26133
26134 \end_inset
26135 </cell>
26136 </row>
26137 </lyxtabular>
26138
26139 \end_inset
26140
26141
26142 \end_layout
26143
26144 \begin_layout Standard
26145 Generic pointer are read and written with a set of library functions which
26146  read/write 1, 2, 3, 4 bytes.
26147 \end_layout
26148
26149 \begin_layout Subsection
26150 PIC16 C Libraries
26151 \end_layout
26152
26153 \begin_layout Subsubsection
26154 Standard I/O Streams
26155 \end_layout
26156
26157 \begin_layout Standard
26158 In the 
26159 \emph on
26160 stdio.h
26161 \emph default
26162  the type FILE is defined as:
26163 \end_layout
26164
26165 \begin_layout LyX-Code
26166 typedef char * FILE;
26167 \end_layout
26168
26169 \begin_layout Standard
26170 This type is the stream type implemented I/O in the PIC18F devices.
26171  Also the standard input and output streams are declared in stdio.h:
26172 \end_layout
26173
26174 \begin_layout LyX-Code
26175 extern FILE * stdin;
26176 \end_layout
26177
26178 \begin_layout LyX-Code
26179 extern FILE * stdout;
26180 \end_layout
26181
26182 \begin_layout Standard
26183 The FILE type is actually a generic pointer which defines one more type
26184  of generic pointers, the 
26185 \emph on
26186 stream 
26187 \emph default
26188 pointer.
26189  This new type has the format:
26190 \end_layout
26191
26192 \begin_layout Standard
26193 \align center
26194 \begin_inset Tabular
26195 <lyxtabular version="3" rows="2" columns="7">
26196 <features>
26197 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26198 <column alignment="center" valignment="top" width="0">
26199 <column alignment="center" valignment="top" leftline="true" width="0">
26200 <column alignment="center" valignment="top" leftline="true" width="0">
26201 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26202 <column alignment="center" valignment="top" width="0">
26203 <column alignment="left" valignment="top" rightline="true" width="0">
26204 <row topline="true" bottomline="true">
26205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26206 \begin_inset Text
26207
26208 \begin_layout Standard
26209 pointer type
26210 \end_layout
26211
26212 \end_inset
26213 </cell>
26214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26215 \begin_inset Text
26216
26217 \begin_layout Standard
26218 <7:6>
26219 \end_layout
26220
26221 \end_inset
26222 </cell>
26223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26224 \begin_inset Text
26225
26226 \begin_layout Standard
26227 <5>
26228 \end_layout
26229
26230 \end_inset
26231 </cell>
26232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26233 \begin_inset Text
26234
26235 \begin_layout Standard
26236 <4>
26237 \end_layout
26238
26239 \end_inset
26240 </cell>
26241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26242 \begin_inset Text
26243
26244 \begin_layout Standard
26245 <3:0>
26246 \end_layout
26247
26248 \end_inset
26249 </cell>
26250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26251 \begin_inset Text
26252
26253 \begin_layout Standard
26254 rest of the pointer
26255 \end_layout
26256
26257 \end_inset
26258 </cell>
26259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26260 \begin_inset Text
26261
26262 \begin_layout Standard
26263 descrption
26264 \end_layout
26265
26266 \end_inset
26267 </cell>
26268 </row>
26269 <row topline="true" bottomline="true">
26270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26271 \begin_inset Text
26272
26273 \begin_layout Standard
26274 stream
26275 \end_layout
26276
26277 \end_inset
26278 </cell>
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26280 \begin_inset Text
26281
26282 \begin_layout Standard
26283 00
26284 \end_layout
26285
26286 \end_inset
26287 </cell>
26288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26289 \begin_inset Text
26290
26291 \begin_layout Standard
26292 1
26293 \end_layout
26294
26295 \end_inset
26296 </cell>
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26298 \begin_inset Text
26299
26300 \begin_layout Standard
26301 0
26302 \end_layout
26303
26304 \end_inset
26305 </cell>
26306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26307 \begin_inset Text
26308
26309 \begin_layout Standard
26310 nnnn
26311 \end_layout
26312
26313 \end_inset
26314 </cell>
26315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26316 \begin_inset Text
26317
26318 \begin_layout Standard
26319
26320 \family typewriter
26321 \shape slanted
26322 \emph on
26323 uuuuuuuu uuuuuuuu
26324 \end_layout
26325
26326 \end_inset
26327 </cell>
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26329 \begin_inset Text
26330
26331 \begin_layout Standard
26332 upper byte high nubble is 0x2n, the rest are zeroes
26333 \end_layout
26334
26335 \end_inset
26336 </cell>
26337 </row>
26338 </lyxtabular>
26339
26340 \end_inset
26341
26342
26343 \end_layout
26344
26345 \begin_layout Standard
26346 Currently implemented there are 3 types of streams defined:
26347 \end_layout
26348
26349 \begin_layout Standard
26350 \align center
26351 \begin_inset Tabular
26352 <lyxtabular version="3" rows="4" columns="4">
26353 <features>
26354 <column alignment="center" valignment="top" leftline="true" width="0">
26355 <column alignment="center" valignment="top" leftline="true" width="0">
26356 <column alignment="center" valignment="top" leftline="true" width="0">
26357 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26358 <row topline="true" bottomline="true">
26359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26360 \begin_inset Text
26361
26362 \begin_layout Standard
26363 stream type
26364 \end_layout
26365
26366 \end_inset
26367 </cell>
26368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26369 \begin_inset Text
26370
26371 \begin_layout Standard
26372 value
26373 \end_layout
26374
26375 \end_inset
26376 </cell>
26377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26378 \begin_inset Text
26379
26380 \begin_layout Standard
26381 module
26382 \end_layout
26383
26384 \end_inset
26385 </cell>
26386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26387 \begin_inset Text
26388
26389 \begin_layout Standard
26390 description
26391 \end_layout
26392
26393 \end_inset
26394 </cell>
26395 </row>
26396 <row topline="true">
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26398 \begin_inset Text
26399
26400 \begin_layout Standard
26401 STREAM_USART
26402 \end_layout
26403
26404 \end_inset
26405 </cell>
26406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26407 \begin_inset Text
26408
26409 \begin_layout Standard
26410
26411 \family typewriter
26412 0x200000UL
26413 \end_layout
26414
26415 \end_inset
26416 </cell>
26417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26418 \begin_inset Text
26419
26420 \begin_layout Standard
26421 USART
26422 \end_layout
26423
26424 \end_inset
26425 </cell>
26426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26427 \begin_inset Text
26428
26429 \begin_layout Standard
26430 Writes/Reads characters via the USART peripheral
26431 \end_layout
26432
26433 \end_inset
26434 </cell>
26435 </row>
26436 <row topline="true">
26437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26438 \begin_inset Text
26439
26440 \begin_layout Standard
26441 STREAM_MSSP
26442 \end_layout
26443
26444 \end_inset
26445 </cell>
26446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26447 \begin_inset Text
26448
26449 \begin_layout Standard
26450
26451 \family typewriter
26452 0x210000UL
26453 \end_layout
26454
26455 \end_inset
26456 </cell>
26457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26458 \begin_inset Text
26459
26460 \begin_layout Standard
26461 MSSP
26462 \end_layout
26463
26464 \end_inset
26465 </cell>
26466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26467 \begin_inset Text
26468
26469 \begin_layout Standard
26470 Writes/Reads characters via the MSSP peripheral
26471 \end_layout
26472
26473 \end_inset
26474 </cell>
26475 </row>
26476 <row topline="true" bottomline="true">
26477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26478 \begin_inset Text
26479
26480 \begin_layout Standard
26481 STREAM_USER
26482 \end_layout
26483
26484 \end_inset
26485 </cell>
26486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26487 \begin_inset Text
26488
26489 \begin_layout Standard
26490
26491 \family typewriter
26492 0x2f0000UL
26493 \end_layout
26494
26495 \end_inset
26496 </cell>
26497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26498 \begin_inset Text
26499
26500 \begin_layout Standard
26501 (none)
26502 \end_layout
26503
26504 \end_inset
26505 </cell>
26506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26507 \begin_inset Text
26508
26509 \begin_layout Standard
26510 Writes/Reads characters via used defined functions
26511 \end_layout
26512
26513 \end_inset
26514 </cell>
26515 </row>
26516 </lyxtabular>
26517
26518 \end_inset
26519
26520
26521 \end_layout
26522
26523 \begin_layout Standard
26524 The stream identifiers are declared as macros in the stdio.h header.
26525 \end_layout
26526
26527 \begin_layout Standard
26528 In the libc library there exist the functions that are used to write to
26529  each of the above streams.
26530  These are
26531 \end_layout
26532
26533 \begin_layout Description
26534 _
26535 \begin_inset ERT
26536 status collapsed
26537
26538 \begin_layout Standard
26539
26540
26541 \backslash
26542 /
26543 \end_layout
26544
26545 \end_inset
26546
26547 _stream_usart_putchar writes a character at the USART stream
26548 \end_layout
26549
26550 \begin_layout Description
26551 _
26552 \begin_inset ERT
26553 status collapsed
26554
26555 \begin_layout Standard
26556
26557
26558 \backslash
26559 /
26560 \end_layout
26561
26562 \end_inset
26563
26564 _stream_mssp_putchar writes a character at the MSSP stream
26565 \end_layout
26566
26567 \begin_layout Description
26568 putchar dummy function.
26569  This writes a character to a user specified manner.
26570 \end_layout
26571
26572 \begin_layout Standard
26573 In order to increase performance 
26574 \emph on
26575 putchar 
26576 \emph default
26577 is declared in stdio.h as having its parameter in WREG (it has the wparam
26578  keyword).
26579  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26580  in a user-friendly way.
26581  
26582 \emph on
26583 arg
26584 \emph default
26585  is the name of the variable that holds the character to print.
26586  An example follows:
26587 \end_layout
26588
26589 \begin_layout LyX-Code
26590 #include <pic18fregs.h>
26591 \newline
26592 #include <stdio.h>
26593 \newline
26594
26595 \newline
26596 PUTCHAR( c )
26597 \end_layout
26598
26599 \begin_layout LyX-Code
26600 {
26601 \end_layout
26602
26603 \begin_layout LyX-Code
26604     PORTA = c;    /* dump character c to PORTA */
26605 \end_layout
26606
26607 \begin_layout LyX-Code
26608
26609 \newline
26610
26611 \newline
26612 void main(void)
26613 \end_layout
26614
26615 \begin_layout LyX-Code
26616 {
26617 \end_layout
26618
26619 \begin_layout LyX-Code
26620     stdout = STREAM_USER;    /* this is not necessary, since stdout points
26621 \end_layout
26622
26623 \begin_layout LyX-Code
26624                               * by default to STREAM_USER */
26625 \end_layout
26626
26627 \begin_layout LyX-Code
26628     printf (
26629 \begin_inset Quotes sld
26630 \end_inset
26631
26632 This is a printf test
26633 \backslash
26634 n
26635 \begin_inset Quotes srd
26636 \end_inset
26637
26638 );
26639 \end_layout
26640
26641 \begin_layout LyX-Code
26642 }
26643 \end_layout
26644
26645 \begin_layout LyX-Code
26646
26647 \end_layout
26648
26649 \begin_layout Subsubsection
26650 Printing functions
26651 \end_layout
26652
26653 \begin_layout Standard
26654 PIC16 contains an implementation of the printf-family of functions.
26655  There exist the following functions:
26656 \end_layout
26657
26658 \begin_layout LyX-Code
26659 extern unsigned int sprintf(char *buf, char *fmt, ...);
26660 \end_layout
26661
26662 \begin_layout LyX-Code
26663 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26664 \end_layout
26665
26666 \begin_layout LyX-Code
26667
26668 \end_layout
26669
26670 \begin_layout LyX-Code
26671 extern unsigned int printf(char *fmt, ...);
26672 \end_layout
26673
26674 \begin_layout LyX-Code
26675 extern unsigned int vprintf(char *fmt, va_lista ap);
26676 \end_layout
26677
26678 \begin_layout LyX-Code
26679
26680 \end_layout
26681
26682 \begin_layout LyX-Code
26683 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26684 \end_layout
26685
26686 \begin_layout LyX-Code
26687 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26688 \end_layout
26689
26690 \begin_layout Standard
26691 For sprintf and vsprintf 
26692 \emph on
26693 buf 
26694 \emph default
26695 should normally be a data pointer where the resulting string will be placed.
26696  No range checking is done so the user should allocate the necessery buffer.
26697  For fprintf and vfprintf 
26698 \emph on
26699 fp
26700 \emph default
26701  should be a stream pointer (i.e.
26702  stdout, STREAM_MSSP, etc...).
26703 \end_layout
26704
26705 \begin_layout Subsubsection
26706 Signals
26707 \end_layout
26708
26709 \begin_layout Standard
26710 The PIC18F family of microcontrollers supports a number of interrupt sources.
26711  A list of these interrupts is shown in the following table:
26712 \end_layout
26713
26714 \begin_layout Standard
26715 \align center
26716 \begin_inset Tabular
26717 <lyxtabular version="3" rows="11" columns="4">
26718 <features>
26719 <column alignment="left" valignment="top" leftline="true" width="0">
26720 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26721 <column alignment="left" valignment="top" leftline="true" width="0">
26722 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26723 <row topline="true" bottomline="true">
26724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26725 \begin_inset Text
26726
26727 \begin_layout Standard
26728 signal name
26729 \end_layout
26730
26731 \end_inset
26732 </cell>
26733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26734 \begin_inset Text
26735
26736 \begin_layout Standard
26737 description
26738 \end_layout
26739
26740 \end_inset
26741 </cell>
26742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26743 \begin_inset Text
26744
26745 \begin_layout Standard
26746 signal name
26747 \end_layout
26748
26749 \end_inset
26750 </cell>
26751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26752 \begin_inset Text
26753
26754 \begin_layout Standard
26755 descritpion
26756 \end_layout
26757
26758 \end_inset
26759 </cell>
26760 </row>
26761 <row topline="true">
26762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26763 \begin_inset Text
26764
26765 \begin_layout Standard
26766 SIG_RB
26767 \end_layout
26768
26769 \end_inset
26770 </cell>
26771 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26772 \begin_inset Text
26773
26774 \begin_layout Standard
26775 PORTB change interrupt
26776 \end_layout
26777
26778 \end_inset
26779 </cell>
26780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26781 \begin_inset Text
26782
26783 \begin_layout Standard
26784 SIG_EE
26785 \end_layout
26786
26787 \end_inset
26788 </cell>
26789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26790 \begin_inset Text
26791
26792 \begin_layout Standard
26793 EEPROM/FLASH write complete interrupt
26794 \end_layout
26795
26796 \end_inset
26797 </cell>
26798 </row>
26799 <row topline="true">
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26801 \begin_inset Text
26802
26803 \begin_layout Standard
26804 SIG_INT0
26805 \end_layout
26806
26807 \end_inset
26808 </cell>
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26810 \begin_inset Text
26811
26812 \begin_layout Standard
26813 INT0 external interrupt
26814 \end_layout
26815
26816 \end_inset
26817 </cell>
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26819 \begin_inset Text
26820
26821 \begin_layout Standard
26822 SIG_BCOL
26823 \end_layout
26824
26825 \end_inset
26826 </cell>
26827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26828 \begin_inset Text
26829
26830 \begin_layout Standard
26831 Bus collision interrupt
26832 \end_layout
26833
26834 \end_inset
26835 </cell>
26836 </row>
26837 <row topline="true">
26838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26839 \begin_inset Text
26840
26841 \begin_layout Standard
26842 SIG_INT1
26843 \end_layout
26844
26845 \end_inset
26846 </cell>
26847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26848 \begin_inset Text
26849
26850 \begin_layout Standard
26851 INT1 external interrupt
26852 \end_layout
26853
26854 \end_inset
26855 </cell>
26856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26857 \begin_inset Text
26858
26859 \begin_layout Standard
26860 SIG_LVD
26861 \end_layout
26862
26863 \end_inset
26864 </cell>
26865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26866 \begin_inset Text
26867
26868 \begin_layout Standard
26869 Low voltage detect interrupt
26870 \end_layout
26871
26872 \end_inset
26873 </cell>
26874 </row>
26875 <row topline="true">
26876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26877 \begin_inset Text
26878
26879 \begin_layout Standard
26880 SIG_INT2
26881 \end_layout
26882
26883 \end_inset
26884 </cell>
26885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26886 \begin_inset Text
26887
26888 \begin_layout Standard
26889 INT2 external interrupt
26890 \end_layout
26891
26892 \end_inset
26893 </cell>
26894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26895 \begin_inset Text
26896
26897 \begin_layout Standard
26898 SIG_PSP
26899 \end_layout
26900
26901 \end_inset
26902 </cell>
26903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26904 \begin_inset Text
26905
26906 \begin_layout Standard
26907 Parallel slave port interrupt
26908 \end_layout
26909
26910 \end_inset
26911 </cell>
26912 </row>
26913 <row topline="true">
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26915 \begin_inset Text
26916
26917 \begin_layout Standard
26918 SIG_CCP1
26919 \end_layout
26920
26921 \end_inset
26922 </cell>
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26924 \begin_inset Text
26925
26926 \begin_layout Standard
26927 CCP1 module interrupt
26928 \end_layout
26929
26930 \end_inset
26931 </cell>
26932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26933 \begin_inset Text
26934
26935 \begin_layout Standard
26936 SIG_AD
26937 \end_layout
26938
26939 \end_inset
26940 </cell>
26941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26942 \begin_inset Text
26943
26944 \begin_layout Standard
26945 AD convertion complete interrupt
26946 \end_layout
26947
26948 \end_inset
26949 </cell>
26950 </row>
26951 <row topline="true">
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26953 \begin_inset Text
26954
26955 \begin_layout Standard
26956 SIG_CCP2
26957 \end_layout
26958
26959 \end_inset
26960 </cell>
26961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26962 \begin_inset Text
26963
26964 \begin_layout Standard
26965 CCP2 module interrupt
26966 \end_layout
26967
26968 \end_inset
26969 </cell>
26970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26971 \begin_inset Text
26972
26973 \begin_layout Standard
26974 SIG_RC
26975 \end_layout
26976
26977 \end_inset
26978 </cell>
26979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26980 \begin_inset Text
26981
26982 \begin_layout Standard
26983 USART receive interrupt
26984 \end_layout
26985
26986 \end_inset
26987 </cell>
26988 </row>
26989 <row topline="true">
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26991 \begin_inset Text
26992
26993 \begin_layout Standard
26994 SIG_TMR0
26995 \end_layout
26996
26997 \end_inset
26998 </cell>
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27000 \begin_inset Text
27001
27002 \begin_layout Standard
27003 TMR0 overflow interrupt
27004 \end_layout
27005
27006 \end_inset
27007 </cell>
27008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27009 \begin_inset Text
27010
27011 \begin_layout Standard
27012 SIG_TX
27013 \end_layout
27014
27015 \end_inset
27016 </cell>
27017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27018 \begin_inset Text
27019
27020 \begin_layout Standard
27021 USART transmit interrupt
27022 \end_layout
27023
27024 \end_inset
27025 </cell>
27026 </row>
27027 <row topline="true">
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27029 \begin_inset Text
27030
27031 \begin_layout Standard
27032 SIG_TMR1
27033 \end_layout
27034
27035 \end_inset
27036 </cell>
27037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27038 \begin_inset Text
27039
27040 \begin_layout Standard
27041 TMR1 overflow interrupt
27042 \end_layout
27043
27044 \end_inset
27045 </cell>
27046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27047 \begin_inset Text
27048
27049 \begin_layout Standard
27050 SIG_MSSP
27051 \end_layout
27052
27053 \end_inset
27054 </cell>
27055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27056 \begin_inset Text
27057
27058 \begin_layout Standard
27059 SSP receive/transmit interrupt
27060 \end_layout
27061
27062 \end_inset
27063 </cell>
27064 </row>
27065 <row topline="true">
27066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27067 \begin_inset Text
27068
27069 \begin_layout Standard
27070 SIG_TMR2
27071 \end_layout
27072
27073 \end_inset
27074 </cell>
27075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27076 \begin_inset Text
27077
27078 \begin_layout Standard
27079 TMR2 matches PR2 interrupt
27080 \end_layout
27081
27082 \end_inset
27083 </cell>
27084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27085 \begin_inset Text
27086
27087 \begin_layout Standard
27088
27089 \end_layout
27090
27091 \end_inset
27092 </cell>
27093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27094 \begin_inset Text
27095
27096 \begin_layout Standard
27097
27098 \end_layout
27099
27100 \end_inset
27101 </cell>
27102 </row>
27103 <row topline="true" bottomline="true">
27104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27105 \begin_inset Text
27106
27107 \begin_layout Standard
27108 SIG_TMR3
27109 \end_layout
27110
27111 \end_inset
27112 </cell>
27113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27114 \begin_inset Text
27115
27116 \begin_layout Standard
27117 TMR3 overflow interrupt
27118 \end_layout
27119
27120 \end_inset
27121 </cell>
27122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27123 \begin_inset Text
27124
27125 \begin_layout Standard
27126
27127 \end_layout
27128
27129 \end_inset
27130 </cell>
27131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27132 \begin_inset Text
27133
27134 \begin_layout Standard
27135
27136 \end_layout
27137
27138 \end_inset
27139 </cell>
27140 </row>
27141 </lyxtabular>
27142
27143 \end_inset
27144
27145
27146 \end_layout
27147
27148 \begin_layout Standard
27149 The prototypes for these names are defined in the header file 
27150 \emph on
27151 signal.h
27152 \emph default
27153  .
27154 \end_layout
27155
27156 \begin_layout Standard
27157 In order to simplify signal handling, a number of macros is provided:
27158 \end_layout
27159
27160 \begin_layout List
27161 \labelwidthstring 00.00.0000
27162 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27163  high priority interrupts.
27164  
27165 \emph on
27166 name
27167 \emph default
27168  is the function name to use.
27169 \end_layout
27170
27171 \begin_layout List
27172 \labelwidthstring 00.00.0000
27173 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27174  low priority interrupt.
27175  
27176 \emph on
27177 name
27178 \emph default
27179  is the function name to use.
27180 \end_layout
27181
27182 \begin_layout List
27183 \labelwidthstring 00.00.0000
27184 DEF_HANDLER(sig,handler) define a handler for signal 
27185 \emph on
27186 sig.
27187 \end_layout
27188
27189 \begin_layout List
27190 \labelwidthstring 00.00.0000
27191 END_DEF end the declaration of the dispatch table.
27192 \end_layout
27193
27194 \begin_layout Standard
27195 Additionally there are two more macros to simplify the declaration of the
27196  signal handler:
27197 \end_layout
27198
27199 \begin_layout List
27200 \labelwidthstring 00.00.0000
27201
27202 \series medium
27203 SIGHANDLER(handler) 
27204 \series default
27205 this declares the function prototype for the 
27206 \emph on
27207 handler
27208 \emph default
27209  function.
27210 \end_layout
27211
27212 \begin_layout List
27213 \labelwidthstring 00.00.0000
27214 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27215 \end_layout
27216
27217 \begin_layout Standard
27218 An example of using the macros above is shown below:
27219 \end_layout
27220
27221 \begin_layout LyX-Code
27222 #include <pic18fregs.h>
27223 \end_layout
27224
27225 \begin_layout LyX-Code
27226 #include <signal.h>
27227 \newline
27228
27229 \newline
27230 DEF_INTHIGH(high_int)
27231 \end_layout
27232
27233 \begin_layout LyX-Code
27234 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27235 \end_layout
27236
27237 \begin_layout LyX-Code
27238 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27239 \end_layout
27240
27241 \begin_layout LyX-Code
27242 END_DEF
27243 \newline
27244
27245 \newline
27246 SIGHANDLER(_tmr0_handler)
27247 \end_layout
27248
27249 \begin_layout LyX-Code
27250 {
27251 \end_layout
27252
27253 \begin_layout LyX-Code
27254   /* action to be taken when timer 0 overflows */
27255 \end_layout
27256
27257 \begin_layout LyX-Code
27258 }
27259 \newline
27260
27261 \newline
27262 SIGHANDLERNAKED(_bcol_handler)
27263 \end_layout
27264
27265 \begin_layout LyX-Code
27266 {
27267 \end_layout
27268
27269 \begin_layout LyX-Code
27270   _asm
27271 \end_layout
27272
27273 \begin_layout LyX-Code
27274     /* action to be taken when bus collision occurs */
27275 \end_layout
27276
27277 \begin_layout LyX-Code
27278     retfie
27279 \end_layout
27280
27281 \begin_layout LyX-Code
27282  _endasm;
27283 \end_layout
27284
27285 \begin_layout LyX-Code
27286 }
27287 \end_layout
27288
27289 \begin_layout Standard
27290
27291 \series bold
27292 NOTES:
27293 \series default
27294  Special care should be taken when using the above scheme:
27295 \end_layout
27296
27297 \begin_layout Itemize
27298 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27299 \end_layout
27300
27301 \begin_layout Itemize
27302 when declaring SIGHANDLERNAKED handler never forget to use 
27303 \emph on
27304 retfie
27305 \emph default
27306  for proper returning.
27307 \end_layout
27308
27309 \begin_layout Subsection
27310 PIC16 Port -- Tips
27311 \end_layout
27312
27313 \begin_layout Standard
27314 Here you can find some general tips for compiling programs with SDCC/pic16.
27315 \end_layout
27316
27317 \begin_layout Subsubsection
27318 Stack size
27319 \end_layout
27320
27321 \begin_layout Standard
27322 The default stack
27323 \begin_inset LatexCommand \index{PIC16!stack}
27324
27325 \end_inset
27326
27327  size (that is 64 bytes) probably is enough for many programs.
27328  One must take care that when there are many levels of function nesting,
27329  or there is excessive usage of stack, its size should be extended.
27330  An example of such a case is the printf/sprintf family of functions.
27331  If you encounter problems like not being able to print integers, then you
27332  need to set the stack size around the maximum (256 for small stack model).
27333  The following diagram shows what happens when calling printf to print an
27334  integer:
27335 \end_layout
27336
27337 \begin_layout LyX-Code
27338 printf () --> ltoa () --> ultoa () --> divschar ()
27339 \end_layout
27340
27341 \begin_layout Standard
27342 It is should be understood that stack is easily consumed when calling complicate
27343 d functions.
27344  Using command line arguments like -
27345 \begin_inset ERT
27346 status collapsed
27347
27348 \begin_layout Standard
27349
27350
27351 \backslash
27352 /
27353 \end_layout
27354
27355 \end_inset
27356
27357 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27358  stack frames.
27359  Other ways to reduce stack usage may exist.
27360 \end_layout
27361
27362 \begin_layout Subsection
27363 Known Bugs
27364 \end_layout
27365
27366 \begin_layout Standard
27367 The PIC16 Port currently does not pass SDCC's regression test
27368 \begin_inset LatexCommand \index{Regression test (PIC16)}
27369
27370 \end_inset
27371
27372  suite (see section 
27373 \begin_inset LatexCommand \ref{sec:Quality-control}
27374
27375 \end_inset
27376
27377 ) and thus the snapshot build regression tests for the PIC16 target are
27378  currently disabled for all hosts
27379 \emph on
27380 .
27381 \end_layout
27382
27383 \begin_layout Chapter
27384 Debugging
27385 \end_layout
27386
27387 \begin_layout Standard
27388 There are several approaches to debugging your code.
27389  This chapter is meant to show your options and to give detail on some of
27390  them:
27391 \newline
27392
27393 \newline
27394 When writing your code:
27395 \end_layout
27396
27397 \begin_layout Itemize
27398 write your code with debugging in mind (avoid duplicating code, put conceptually
27399  similar variables into structs, use structured code, have strategic points
27400  within your code where all variables are consistent, ...)
27401 \end_layout
27402
27403 \begin_layout Itemize
27404 run a syntax-checking tool like splint
27405 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27406
27407 \end_inset
27408
27409
27410 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27411
27412 \end_inset
27413
27414  (see -
27415 \begin_inset ERT
27416 status collapsed
27417
27418 \begin_layout Standard
27419
27420
27421 \backslash
27422 /
27423 \end_layout
27424
27425 \end_inset
27426
27427 -more-pedantic 
27428 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27429
27430 \end_inset
27431
27432 ) over the code.
27433 \end_layout
27434
27435 \begin_layout Itemize
27436 for the high level code use a C-compiler (like f.e.
27437  GCC) to compile run and debug the code on your host.
27438  See (see -
27439 \begin_inset ERT
27440 status collapsed
27441
27442 \begin_layout Standard
27443
27444
27445 \backslash
27446 /
27447 \end_layout
27448
27449 \end_inset
27450
27451 -more-pedantic 
27452 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27453
27454 \end_inset
27455
27456 ) on how to handle syntax extensions like __xdata, __at(), ...
27457  
27458 \end_layout
27459
27460 \begin_layout Itemize
27461 use another C-compiler to compile code for your target.
27462  Always an option but not recommended:) And not very likely to help you.
27463  If you seriously consider walking this path you should at least occasionally
27464  check portability of your code.
27465  Most commercial compiler vendors will offer an evaluation version so you
27466  can test compile your code or snippets of your code.
27467 \end_layout
27468
27469 \begin_layout Standard
27470 Debugging on a simulator:
27471 \end_layout
27472
27473 \begin_layout Itemize
27474 there is a separate section about SDCDB (section 
27475 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27476
27477 \end_inset
27478
27479 ) below.
27480 \end_layout
27481
27482 \begin_layout Itemize
27483 or (8051 specific) use a freeware/commercial simulator which interfaces
27484  to the AOMF
27485 \begin_inset LatexCommand \index{AOMF, AOMF51}
27486
27487 \end_inset
27488
27489  file (see 
27490 \begin_inset LatexCommand \ref{OMF file}
27491
27492 \end_inset
27493
27494 ) optionally generated by SDCC.
27495 \end_layout
27496
27497 \begin_layout Standard
27498 Debugging On-target: 
27499 \end_layout
27500
27501 \begin_layout Itemize
27502 use a MCU port pin to serially output debug data to the RS232 port of your
27503  host.
27504  You'll probably want some level shifting device typically involving a MAX232
27505  or similar IC.
27506  If the hardware serial port of the MCU is not available search for 'Software
27507  UART' in your favourite search machine.
27508 \end_layout
27509
27510 \begin_layout Itemize
27511 use an on-target monitor.
27512  In this context a monitor is a small program which usually accepts commands
27513  via a serial line and allows to set program counter, to single step through
27514  a program and read/write memory locations.
27515  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27516  
27517 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27518
27519 \end_inset
27520
27521 ).
27522 \end_layout
27523
27524 \begin_layout Itemize
27525 toggle MCU port pins at strategic points within your code and use an oscilloscop
27526 e.
27527  A 
27528 \emph on
27529 digital oscilloscope
27530 \emph default
27531
27532 \begin_inset LatexCommand \index{Oscilloscope}
27533
27534 \end_inset
27535
27536  with deep trace memory is really helpful especially if you have to debug
27537  a realtime application.
27538  If you need to monitor more pins than your oscilloscope provides you can
27539  sometimes get away with a small R-2R network.
27540  On a single channel oscilloscope you could f.e.
27541  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27542 k
27543 \begin_inset Formula $\Omega$
27544 \end_inset
27545
27546  resistor and the other one by a 5\InsetSpace ~
27547 k
27548 \begin_inset Formula $\Omega$
27549 \end_inset
27550
27551  resistor to the oscilloscope probe (check output drive capability of the
27552  pins you want to monitor).
27553  If you need to monitor many more pins a 
27554 \emph on
27555 logic analyzer
27556 \emph default
27557  will be handy.
27558 \end_layout
27559
27560 \begin_layout Itemize
27561 use an ICE (
27562 \emph on
27563 i
27564 \emph default
27565
27566 \emph on
27567 c
27568 \emph default
27569 ircuit 
27570 \emph on
27571 e
27572 \emph default
27573 mulator
27574 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27575
27576 \end_inset
27577
27578 ).
27579  Usually very expensive.
27580  And very nice to have too.
27581  And usually locks you (for years...) to the devices the ICE can emulate.
27582  
27583 \end_layout
27584
27585 \begin_layout Itemize
27586 use a remote debugger.
27587  In most 8-bit systems the symbol information is not available on the target,
27588  and a complete debugger is too bulky for the target system.
27589  Therefore usually a debugger on the host system connects to an on-target
27590  debugging stub which accepts only primitive commands.
27591  
27592 \newline
27593 Terms to enter into your favourite search engine could be 'remote debugging',
27594  'gdb stub' or 'inferior debugger'.
27595  (is there one?)
27596 \end_layout
27597
27598 \begin_layout Itemize
27599 use an on target hardware debugger.
27600  Some of the more modern MCUs include hardware support for setting break
27601  points and monitoring/changing variables by using dedicated hardware pins.
27602  This facility doesn't require additional code to run on the target and
27603  
27604 \emph on
27605 usually
27606 \emph default
27607  doesn't affect runtime behaviour until a breakpoint is hit.
27608  For the mcs51 most hardware debuggers use the AOMF
27609 \begin_inset LatexCommand \index{AOMF, AOMF51}
27610
27611 \end_inset
27612
27613  file (see 
27614 \begin_inset LatexCommand \ref{OMF file}
27615
27616 \end_inset
27617
27618 ) as input file.
27619  
27620 \end_layout
27621
27622 \begin_layout Standard
27623 Last not least:
27624 \end_layout
27625
27626 \begin_layout Itemize
27627 if you are not familiar with any of the following terms you're likely to
27628  run into problems rather sooner than later: 
27629 \emph on
27630 volatile
27631 \emph default
27632
27633 \emph on
27634 atomic
27635 \emph default
27636
27637 \emph on
27638 memory map
27639 \emph default
27640
27641 \emph on
27642 overlay
27643 \emph default
27644 .
27645  As an embedded programmer you 
27646 \emph on
27647 have
27648 \emph default
27649  to know them so why not look them up 
27650 \emph on
27651 before
27652 \emph default
27653  you have problems?)
27654 \end_layout
27655
27656 \begin_layout Itemize
27657 tell someone else about your problem (actually this is a surprisingly effective
27658  means to hunt down the bug even if the listener is not familiar with your
27659  environment).
27660  As 'failure to communicate' is probably one of the job-induced deformations
27661  of an embedded programmer this is highly encouraged.
27662 \end_layout
27663
27664 \begin_layout Section
27665 Debugging with SDCDB
27666 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27667
27668 \end_inset
27669
27670
27671 \begin_inset LatexCommand \index{SDCDB (debugger)}
27672
27673 \end_inset
27674
27675  
27676 \end_layout
27677
27678 \begin_layout Standard
27679 SDCC is distributed with a source level debugger
27680 \begin_inset LatexCommand \index{Debugger}
27681
27682 \end_inset
27683
27684 .
27685  The debugger uses a command line interface, the command repertoire of the
27686  debugger has been kept as close to gdb
27687 \begin_inset LatexCommand \index{gdb}
27688
27689 \end_inset
27690
27691  (the GNU debugger) as possible.
27692  The configuration and build process is part of the standard compiler installati
27693 on, which also builds and installs the debugger in the target directory
27694  specified during configuration.
27695  The debugger allows you debug BOTH at the C source and at the ASM source
27696  level.
27697 \end_layout
27698
27699 \begin_layout Subsection
27700 Compiling for Debugging
27701 \end_layout
27702
27703 \begin_layout Standard
27704 The -
27705 \begin_inset ERT
27706 status collapsed
27707
27708 \begin_layout Standard
27709
27710
27711 \backslash
27712 /
27713 \end_layout
27714
27715 \end_inset
27716
27717 -debug
27718 \begin_inset LatexCommand \index{-\/-debug}
27719
27720 \end_inset
27721
27722  option must be specified for all files for which debug information is to
27723  be generated.
27724  The compiler generates a .adb file for each of these files.
27725  The linker creates the .cdb
27726 \begin_inset LatexCommand \index{<file>.cdb}
27727
27728 \end_inset
27729
27730  file from the .adb
27731 \begin_inset LatexCommand \index{<file>.adb}
27732
27733 \end_inset
27734
27735  files and the address information.
27736  This .cdb is used by the debugger.
27737 \end_layout
27738
27739 \begin_layout Subsection
27740 How the Debugger Works
27741 \end_layout
27742
27743 \begin_layout Standard
27744 When the -
27745 \begin_inset ERT
27746 status collapsed
27747
27748 \begin_layout Standard
27749
27750
27751 \backslash
27752 /
27753 \end_layout
27754
27755 \end_inset
27756
27757 -debug option is specified the compiler generates extra symbol information
27758  some of which are put into the assembler source and some are put into the
27759  .adb file.
27760  Then the linker creates the .cdb file from the individual .adb files with
27761  the address information for the symbols.
27762  The debugger reads the symbolic information generated by the compiler &
27763  the address information generated by the linker.
27764  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27765  execution is controlled by the debugger.
27766  When a command is issued for the debugger, it translates it into appropriate
27767  commands for the simulator.
27768  (Currently SDCDM only connects to the simulator but 
27769 \emph on
27770 newcdb
27771 \emph default
27772  at 
27773 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27774
27775 \end_inset
27776
27777  is an effort to connect directly to the hardware.) 
27778 \end_layout
27779
27780 \begin_layout Subsection
27781 Starting the Debugger SDCDB
27782 \end_layout
27783
27784 \begin_layout Standard
27785 The debugger can be started using the following command line.
27786  (Assume the file you are debugging has the file name foo).
27787 \newline
27788
27789 \newline
27790
27791 \family sans
27792 \series bold
27793 sdcdb foo
27794 \newline
27795
27796 \family default
27797 \series default
27798
27799 \newline
27800 The debugger will look for the following files.
27801 \end_layout
27802
27803 \begin_layout Itemize
27804 foo.c - the source file.
27805 \end_layout
27806
27807 \begin_layout Itemize
27808 foo.cdb - the debugger symbol information file.
27809 \end_layout
27810
27811 \begin_layout Itemize
27812 foo.ihx - the Intel hex format
27813 \begin_inset LatexCommand \index{Intel hex format}
27814
27815 \end_inset
27816
27817  object file.
27818 \end_layout
27819
27820 \begin_layout Subsection
27821 SDCDB Command Line Options
27822 \end_layout
27823
27824 \begin_layout Itemize
27825 -
27826 \begin_inset ERT
27827 status collapsed
27828
27829 \begin_layout Standard
27830
27831
27832 \backslash
27833 /
27834 \end_layout
27835
27836 \end_inset
27837
27838 -directory=<source file directory> this option can used to specify the directory
27839  search list.
27840  The debugger will look into the directory list specified for source, cdb
27841  & ihx files.
27842  The items in the directory list must be separated by ':', e.g.
27843  if the source files can be in the directories /home/src1 and /home/src2,
27844  the -
27845 \begin_inset ERT
27846 status collapsed
27847
27848 \begin_layout Standard
27849
27850
27851 \backslash
27852 /
27853 \end_layout
27854
27855 \end_inset
27856
27857 -directory option should be -
27858 \begin_inset ERT
27859 status collapsed
27860
27861 \begin_layout Standard
27862
27863
27864 \backslash
27865 /
27866 \end_layout
27867
27868 \end_inset
27869
27870 -directory=/home/src1:/home/src2.
27871  Note there can be no spaces in the option.
27872  
27873 \end_layout
27874
27875 \begin_layout Itemize
27876 -cd <directory> - change to the <directory>.
27877 \end_layout
27878
27879 \begin_layout Itemize
27880 -fullname - used by GUI front ends.
27881 \end_layout
27882
27883 \begin_layout Itemize
27884 -cpu <cpu-type> - this argument is passed to the simulator please see the
27885  simulator docs for details.
27886 \end_layout
27887
27888 \begin_layout Itemize
27889 -X <Clock frequency > this options is passed to the simulator please see
27890  the simulator docs for details.
27891 \end_layout
27892
27893 \begin_layout Itemize
27894 -s <serial port file> passed to simulator see the simulator docs for details.
27895 \end_layout
27896
27897 \begin_layout Itemize
27898 -S <serial in,out> passed to simulator see the simulator docs for details.
27899 \end_layout
27900
27901 \begin_layout Itemize
27902 -k <port number> passed to simulator see the simulator docs for details.
27903 \end_layout
27904
27905 \begin_layout Subsection
27906 SDCDB Debugger Commands
27907 \end_layout
27908
27909 \begin_layout Standard
27910 As mentioned earlier the command interface for the debugger has been deliberatel
27911 y kept as close the GNU debugger gdb, as possible.
27912  This will help the integration with existing graphical user interfaces
27913  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27914  If you use a graphical user interface for the debugger you can skip this
27915  section.
27916 \end_layout
27917
27918 \begin_layout Subsubsection*
27919 break [line | file:line | function | file:function]
27920 \end_layout
27921
27922 \begin_layout Standard
27923 Set breakpoint at specified line or function:
27924 \newline
27925
27926 \newline
27927
27928 \family sans
27929 \series bold
27930 sdcdb>break 100 
27931 \newline
27932 sdcdb>break foo.c:100
27933 \newline
27934 sdcdb>break funcfoo
27935 \newline
27936 sdcdb>break foo.c:funcfoo
27937 \end_layout
27938
27939 \begin_layout Subsubsection*
27940 clear [line | file:line | function | file:function ]
27941 \end_layout
27942
27943 \begin_layout Standard
27944 Clear breakpoint at specified line or function:
27945 \newline
27946
27947 \newline
27948
27949 \family sans
27950 \series bold
27951 sdcdb>clear 100
27952 \newline
27953 sdcdb>clear foo.c:100
27954 \newline
27955 sdcdb>clear funcfoo
27956 \newline
27957 sdcdb>clear foo.c:funcfoo
27958 \end_layout
27959
27960 \begin_layout Subsubsection*
27961 continue
27962 \end_layout
27963
27964 \begin_layout Standard
27965 Continue program being debugged, after breakpoint.
27966 \end_layout
27967
27968 \begin_layout Subsubsection*
27969 finish
27970 \end_layout
27971
27972 \begin_layout Standard
27973 Execute till the end of the current function.
27974 \end_layout
27975
27976 \begin_layout Subsubsection*
27977 delete [n]
27978 \end_layout
27979
27980 \begin_layout Standard
27981 Delete breakpoint number 'n'.
27982  If used without any option clear ALL user defined break points.
27983 \end_layout
27984
27985 \begin_layout Subsubsection*
27986 info [break | stack | frame | registers ]
27987 \end_layout
27988
27989 \begin_layout Itemize
27990 info break - list all breakpoints
27991 \end_layout
27992
27993 \begin_layout Itemize
27994 info stack - show the function call stack.
27995 \end_layout
27996
27997 \begin_layout Itemize
27998 info frame - show information about the current execution frame.
27999 \end_layout
28000
28001 \begin_layout Itemize
28002 info registers - show content of all registers.
28003 \end_layout
28004
28005 \begin_layout Subsubsection*
28006 step
28007 \end_layout
28008
28009 \begin_layout Standard
28010 Step program until it reaches a different source line.
28011  Note: pressing <return> repeats the last command.
28012 \end_layout
28013
28014 \begin_layout Subsubsection*
28015 next
28016 \end_layout
28017
28018 \begin_layout Standard
28019 Step program, proceeding through subroutine calls.
28020 \end_layout
28021
28022 \begin_layout Subsubsection*
28023 run
28024 \end_layout
28025
28026 \begin_layout Standard
28027 Start debugged program.
28028 \end_layout
28029
28030 \begin_layout Subsubsection*
28031 ptype variable 
28032 \end_layout
28033
28034 \begin_layout Standard
28035 Print type information of the variable.
28036 \end_layout
28037
28038 \begin_layout Subsubsection*
28039 print variable
28040 \end_layout
28041
28042 \begin_layout Standard
28043 print value of variable.
28044 \end_layout
28045
28046 \begin_layout Subsubsection*
28047 file filename
28048 \end_layout
28049
28050 \begin_layout Standard
28051 load the given file name.
28052  Note this is an alternate method of loading file for debugging.
28053 \end_layout
28054
28055 \begin_layout Subsubsection*
28056 frame
28057 \end_layout
28058
28059 \begin_layout Standard
28060 print information about current frame.
28061 \end_layout
28062
28063 \begin_layout Subsubsection*
28064 set srcmode
28065 \end_layout
28066
28067 \begin_layout Standard
28068 Toggle between C source & assembly source.
28069 \end_layout
28070
28071 \begin_layout Subsubsection*
28072 ! simulator command
28073 \end_layout
28074
28075 \begin_layout Standard
28076 Send the string following '!' to the simulator, the simulator response is
28077  displayed.
28078  Note the debugger does not interpret the command being sent to the simulator,
28079  so if a command like 'go' is sent the debugger can loose its execution
28080  context and may display incorrect values.
28081 \end_layout
28082
28083 \begin_layout Subsubsection*
28084 quit
28085 \end_layout
28086
28087 \begin_layout Standard
28088 "Watch me now.
28089  Iam going Down.
28090  My name is Bobby Brown"
28091 \end_layout
28092
28093 \begin_layout Subsection
28094 Interfacing SDCDB with DDD
28095 \end_layout
28096
28097 \begin_layout Standard
28098 \begin_inset Note Note
28099 status collapsed
28100
28101 \begin_layout Standard
28102 The screenshot was converted from png to eps with: 
28103 \begin_inset Quotes sld
28104 \end_inset
28105
28106 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28107 \begin_inset Quotes srd
28108 \end_inset
28109
28110  which produces a pretty compact eps file which is free from compression
28111  artifacts.
28112 \end_layout
28113
28114 \begin_layout Standard
28115 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28116  as this broke the build system on Sourceforge (pdf-file was broken.
28117  pdflatex does not accept eps files).
28118 \end_layout
28119
28120 \end_inset
28121
28122
28123 \end_layout
28124
28125 \begin_layout Standard
28126 The 
28127 \emph on
28128 p
28129 \emph default
28130 ortable 
28131 \emph on
28132 n
28133 \emph default
28134 etwork 
28135 \emph on
28136 g
28137 \emph default
28138 raphics File 
28139 \size footnotesize
28140
28141 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28142
28143 \end_inset
28144
28145
28146 \size default
28147  shows a screenshot of a debugging session with DDD
28148 \begin_inset LatexCommand \index{DDD (debugger)}
28149
28150 \end_inset
28151
28152  (Unix only) on a simulated 8032.
28153  The debugging session might not run as smoothly as the screenshot suggests.
28154  The debugger allows setting of breakpoints, displaying and changing variables,
28155  single stepping through C and assembler code.
28156  
28157 \newline
28158 The source was compiled with 
28159 \family sans
28160 \series bold
28161
28162 \newline
28163
28164 \newline
28165 sdcc -
28166 \family default
28167 \series default
28168
28169 \begin_inset ERT
28170 status collapsed
28171
28172 \begin_layout Standard
28173
28174
28175 \backslash
28176 /
28177 \end_layout
28178
28179 \end_inset
28180
28181
28182 \family sans
28183 \series bold
28184 -debug ddd_example.c
28185 \family default
28186 \series default
28187  
28188 \family sans
28189 \series bold
28190
28191 \newline
28192
28193 \family default
28194 \series default
28195
28196 \newline
28197 and DDD was invoked with 
28198 \family sans
28199 \series bold
28200
28201 \newline
28202
28203 \newline
28204 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28205 \end_layout
28206
28207 \begin_layout Standard
28208 \begin_inset Note Note
28209 status open
28210
28211 \begin_layout Standard
28212 Check that the double quotes or an apostroph within the command line survive
28213  the LyX tool chain.
28214  Previously the apostrophs got slanted in the PDF output so a cut and paste
28215  did not work.
28216 \end_layout
28217
28218 \end_inset
28219
28220
28221 \end_layout
28222
28223 \begin_layout Subsection
28224 Interfacing SDCDB with XEmacs
28225 \begin_inset LatexCommand \index{XEmacs}
28226
28227 \end_inset
28228
28229
28230 \begin_inset LatexCommand \index{Emacs}
28231
28232 \end_inset
28233
28234
28235 \end_layout
28236
28237 \begin_layout Standard
28238 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28239  sdcdb.el and sdcdbsrc.el.
28240  These two files can be found in the $(prefix)/bin directory after the installat
28241 ion is complete.
28242  These files need to be loaded into XEmacs for the interface to work.
28243  This can be done at XEmacs startup time by inserting the following into
28244  your '.xemacs' file (which can be found in your HOME directory): 
28245 \newline
28246
28247 \newline
28248
28249 \family typewriter
28250 (load-file sdcdbsrc.el) 
28251 \family default
28252
28253 \newline
28254
28255 \newline
28256 .xemacs is a lisp file so the () around the command is REQUIRED.
28257  The files can also be loaded dynamically while XEmacs is running, set the
28258  environment variable 'EMACSLOADPATH' to the installation bin directory
28259  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28260  To start the interface enter the following command: 
28261 \newline
28262
28263 \newline
28264
28265 \family sans
28266 \series bold
28267 ESC-x sdcdbsrc
28268 \family default
28269 \series default
28270
28271 \newline
28272
28273 \newline
28274 You will prompted to enter the file name to be debugged.
28275  
28276 \newline
28277
28278 \newline
28279 The command line options that are passed to the simulator directly are
28280  bound to default values in the file sdcdbsrc.el.
28281  The variables are listed below, these values maybe changed as required.
28282 \end_layout
28283
28284 \begin_layout Itemize
28285 sdcdbsrc-cpu-type '51
28286 \end_layout
28287
28288 \begin_layout Itemize
28289 sdcdbsrc-frequency '11059200
28290 \end_layout
28291
28292 \begin_layout Itemize
28293 sdcdbsrc-serial nil
28294 \end_layout
28295
28296 \begin_layout Standard
28297 The following is a list of key mapping for the debugger interface.
28298 \end_layout
28299
28300 \begin_layout Standard
28301 \InsetSpace ~
28302
28303 \family typewriter
28304
28305 \newline
28306 ;;\InsetSpace ~
28307 Current Listing :: 
28308 \newline
28309 ;;key\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 binding\InsetSpace ~
28324 \InsetSpace ~
28325 \InsetSpace ~
28326 \InsetSpace ~
28327 \InsetSpace ~
28328 \InsetSpace ~
28329 \InsetSpace ~
28330 \InsetSpace ~
28331 \InsetSpace ~
28332 \InsetSpace ~
28333 \InsetSpace ~
28334 \InsetSpace ~
28335 \InsetSpace ~
28336 \InsetSpace ~
28337 \InsetSpace ~
28338 \InsetSpace ~
28339 \InsetSpace ~
28340 \InsetSpace ~
28341 \InsetSpace ~
28342 \InsetSpace ~
28343 \InsetSpace ~
28344 \InsetSpace ~
28345 Comment 
28346 \newline
28347 ;;---\InsetSpace ~
28348 \InsetSpace ~
28349 \InsetSpace ~
28350 \InsetSpace ~
28351 \InsetSpace ~
28352 \InsetSpace ~
28353 \InsetSpace ~
28354 \InsetSpace ~
28355 \InsetSpace ~
28356 \InsetSpace ~
28357 \InsetSpace ~
28358 \InsetSpace ~
28359 \InsetSpace ~
28360 \InsetSpace ~
28361 -------\InsetSpace ~
28362 \InsetSpace ~
28363 \InsetSpace ~
28364 \InsetSpace ~
28365 \InsetSpace ~
28366 \InsetSpace ~
28367 \InsetSpace ~
28368 \InsetSpace ~
28369 \InsetSpace ~
28370 \InsetSpace ~
28371 \InsetSpace ~
28372 \InsetSpace ~
28373 \InsetSpace ~
28374 \InsetSpace ~
28375 \InsetSpace ~
28376 \InsetSpace ~
28377 \InsetSpace ~
28378 \InsetSpace ~
28379 \InsetSpace ~
28380 \InsetSpace ~
28381 \InsetSpace ~
28382 \InsetSpace ~
28383 -------
28384 \newline
28385 ;; 
28386 \newline
28387 ;;\InsetSpace ~
28388 n\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-next-fro
28404 m-src\InsetSpace ~
28405 \InsetSpace ~
28406 \InsetSpace ~
28407 \InsetSpace ~
28408 \InsetSpace ~
28409 \InsetSpace ~
28410 \InsetSpace ~
28411 \InsetSpace ~
28412 \InsetSpace ~
28413 \InsetSpace ~
28414 SDCDB next command 
28415 \newline
28416 ;;\InsetSpace ~
28417 b\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-back-from-src\InsetSpace ~
28433 \InsetSpace ~
28434 \InsetSpace ~
28435 \InsetSpace ~
28436 \InsetSpace ~
28437 \InsetSpace ~
28438 \InsetSpace ~
28439 \InsetSpace ~
28440 \InsetSpace ~
28441 \InsetSpace ~
28442 SDCDB back command 
28443 \newline
28444 ;;\InsetSpace ~
28445 c\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-cont-f
28461 rom-src\InsetSpace ~
28462 \InsetSpace ~
28463 \InsetSpace ~
28464 \InsetSpace ~
28465 \InsetSpace ~
28466 \InsetSpace ~
28467 \InsetSpace ~
28468 \InsetSpace ~
28469 \InsetSpace ~
28470 \InsetSpace ~
28471 SDCDB continue command
28472 \newline
28473 ;;\InsetSpace ~
28474 s\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 sdcdb-step-from-src\InsetSpace ~
28490 \InsetSpace ~
28491 \InsetSpace ~
28492 \InsetSpace ~
28493 \InsetSpace ~
28494 \InsetSpace ~
28495 \InsetSpace ~
28496 \InsetSpace ~
28497 \InsetSpace ~
28498 \InsetSpace ~
28499 SDCDB step command 
28500 \newline
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 sdcdb-w
28518 hatis-c-sexp\InsetSpace ~
28519 \InsetSpace ~
28520 \InsetSpace ~
28521 \InsetSpace ~
28522 \InsetSpace ~
28523 \InsetSpace ~
28524 \InsetSpace ~
28525 \InsetSpace ~
28526 \InsetSpace ~
28527 \InsetSpace ~
28528 SDCDB ptypecommand for data at 
28529 \newline
28530 ;;\InsetSpace ~
28531 \InsetSpace ~
28532 \InsetSpace ~
28533 \InsetSpace ~
28534 \InsetSpace ~
28535 \InsetSpace ~
28536 \InsetSpace ~
28537 \InsetSpace ~
28538 \InsetSpace ~
28539 \InsetSpace ~
28540 \InsetSpace ~
28541 \InsetSpace ~
28542 \InsetSpace ~
28543 \InsetSpace ~
28544 \InsetSpace ~
28545 \InsetSpace ~
28546 \InsetSpace ~
28547 \InsetSpace ~
28548 \InsetSpace ~
28549 \InsetSpace ~
28550 \InsetSpace ~
28551 \InsetSpace ~
28552 \InsetSpace ~
28553 \InsetSpace ~
28554 \InsetSpace ~
28555 \InsetSpace ~
28556 \InsetSpace ~
28557 \InsetSpace ~
28558 \InsetSpace ~
28559 \InsetSpace ~
28560 \InsetSpace ~
28561 \InsetSpace ~
28562 \InsetSpace ~
28563 \InsetSpace ~
28564 \InsetSpace ~
28565 \InsetSpace ~
28566 \InsetSpace ~
28567 \InsetSpace ~
28568 \InsetSpace ~
28569 \InsetSpace ~
28570 \InsetSpace ~
28571 \InsetSpace ~
28572 \InsetSpace ~
28573 \InsetSpace ~
28574 \InsetSpace ~
28575 \InsetSpace ~
28576 \InsetSpace ~
28577 buffer point 
28578 \newline
28579 ;;\InsetSpace ~
28580 x\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 sdcdbsrc-delete\InsetSpace ~
28596 \InsetSpace ~
28597 \InsetSpace ~
28598 \InsetSpace ~
28599 \InsetSpace ~
28600 \InsetSpace ~
28601 \InsetSpace ~
28602 \InsetSpace ~
28603 \InsetSpace ~
28604 \InsetSpace ~
28605 \InsetSpace ~
28606 \InsetSpace ~
28607 \InsetSpace ~
28608 \InsetSpace ~
28609 SDCD
28610 B Delete all breakpoints if no arg 
28611 \newline
28612 ;;\InsetSpace ~
28613 \InsetSpace ~
28614 \InsetSpace ~
28615 \InsetSpace ~
28616 \InsetSpace ~
28617 \InsetSpace ~
28618 \InsetSpace ~
28619 \InsetSpace ~
28620 \InsetSpace ~
28621 \InsetSpace ~
28622 \InsetSpace ~
28623 \InsetSpace ~
28624 \InsetSpace ~
28625 \InsetSpace ~
28626 \InsetSpace ~
28627 \InsetSpace ~
28628 \InsetSpace ~
28629 \InsetSpace ~
28630 \InsetSpace ~
28631 \InsetSpace ~
28632 \InsetSpace ~
28633 \InsetSpace ~
28634 \InsetSpace ~
28635 \InsetSpace ~
28636 \InsetSpace ~
28637 \InsetSpace ~
28638 \InsetSpace ~
28639 \InsetSpace ~
28640 \InsetSpace ~
28641 \InsetSpace ~
28642 \InsetSpace ~
28643 \InsetSpace ~
28644 \InsetSpace ~
28645 \InsetSpace ~
28646 \InsetSpace ~
28647 \InsetSpace ~
28648 \InsetSpace ~
28649 \InsetSpace ~
28650 \InsetSpace ~
28651 \InsetSpace ~
28652 \InsetSpace ~
28653 \InsetSpace ~
28654 \InsetSpace ~
28655 \InsetSpace ~
28656 \InsetSpace ~
28657 \InsetSpace ~
28658 \InsetSpace ~
28659 given or delete arg (C-u arg x) 
28660 \newline
28661 ;;\InsetSpace ~
28662 m\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 sdcdbsrc
28678 -frame\InsetSpace ~
28679 \InsetSpace ~
28680 \InsetSpace ~
28681 \InsetSpace ~
28682 \InsetSpace ~
28683 \InsetSpace ~
28684 \InsetSpace ~
28685 \InsetSpace ~
28686 \InsetSpace ~
28687 \InsetSpace ~
28688 \InsetSpace ~
28689 \InsetSpace ~
28690 \InsetSpace ~
28691 \InsetSpace ~
28692 \InsetSpace ~
28693 SDCDB Display current frame if no arg, 
28694 \newline
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 \InsetSpace ~
28736 \InsetSpace ~
28737 \InsetSpace ~
28738 \InsetSpace ~
28739 \InsetSpace ~
28740 \InsetSpace ~
28741 \InsetSpace ~
28742 given or display frame arg
28743  
28744 \newline
28745 ;;\InsetSpace ~
28746 \InsetSpace ~
28747 \InsetSpace ~
28748 \InsetSpace ~
28749 \InsetSpace ~
28750 \InsetSpace ~
28751 \InsetSpace ~
28752 \InsetSpace ~
28753 \InsetSpace ~
28754 \InsetSpace ~
28755 \InsetSpace ~
28756 \InsetSpace ~
28757 \InsetSpace ~
28758 \InsetSpace ~
28759 \InsetSpace ~
28760 \InsetSpace ~
28761 \InsetSpace ~
28762 \InsetSpace ~
28763 \InsetSpace ~
28764 \InsetSpace ~
28765 \InsetSpace ~
28766 \InsetSpace ~
28767 \InsetSpace ~
28768 \InsetSpace ~
28769 \InsetSpace ~
28770 \InsetSpace ~
28771 \InsetSpace ~
28772 \InsetSpace ~
28773 \InsetSpace ~
28774 \InsetSpace ~
28775 \InsetSpace ~
28776 \InsetSpace ~
28777 \InsetSpace ~
28778 \InsetSpace ~
28779 \InsetSpace ~
28780 \InsetSpace ~
28781 \InsetSpace ~
28782 \InsetSpace ~
28783 \InsetSpace ~
28784 \InsetSpace ~
28785 \InsetSpace ~
28786 \InsetSpace ~
28787 \InsetSpace ~
28788 \InsetSpace ~
28789 \InsetSpace ~
28790 \InsetSpace ~
28791 \InsetSpace ~
28792 buffer point 
28793 \newline
28794 ;;\InsetSpace ~
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 sdcdbsrc-goto-sdcdb\InsetSpace ~
28811 \InsetSpace ~
28812 \InsetSpace ~
28813 \InsetSpace ~
28814 \InsetSpace ~
28815 \InsetSpace ~
28816 \InsetSpace ~
28817 \InsetSpace ~
28818 \InsetSpace ~
28819 \InsetSpace ~
28820 Goto the SDCDB output buffer 
28821 \newline
28822 ;;\InsetSpace ~
28823 p\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 sdcdb-prin
28839 t-c-sexp\InsetSpace ~
28840 \InsetSpace ~
28841 \InsetSpace ~
28842 \InsetSpace ~
28843 \InsetSpace ~
28844 \InsetSpace ~
28845 \InsetSpace ~
28846 \InsetSpace ~
28847 \InsetSpace ~
28848 \InsetSpace ~
28849 \InsetSpace ~
28850 SDCDB print command for data at 
28851 \newline
28852 ;;\InsetSpace ~
28853 \InsetSpace ~
28854 \InsetSpace ~
28855 \InsetSpace ~
28856 \InsetSpace ~
28857 \InsetSpace ~
28858 \InsetSpace ~
28859 \InsetSpace ~
28860 \InsetSpace ~
28861 \InsetSpace ~
28862 \InsetSpace ~
28863 \InsetSpace ~
28864 \InsetSpace ~
28865 \InsetSpace ~
28866 \InsetSpace ~
28867 \InsetSpace ~
28868 \InsetSpace ~
28869 \InsetSpace ~
28870 \InsetSpace ~
28871 \InsetSpace ~
28872 \InsetSpace ~
28873 \InsetSpace ~
28874 \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 \InsetSpace ~
28890 \InsetSpace ~
28891 \InsetSpace ~
28892 \InsetSpace ~
28893 \InsetSpace ~
28894 \InsetSpace ~
28895 \InsetSpace ~
28896 \InsetSpace ~
28897 \InsetSpace ~
28898 \InsetSpace ~
28899 buffer point 
28900 \newline
28901 ;;\InsetSpace ~
28902 g\InsetSpace ~
28903 \InsetSpace ~
28904 \InsetSpace ~
28905 \InsetSpace ~
28906 \InsetSpace ~
28907 \InsetSpace ~
28908 \InsetSpace ~
28909 \InsetSpace ~
28910 \InsetSpace ~
28911 \InsetSpace ~
28912 \InsetSpace ~
28913 \InsetSpace ~
28914 \InsetSpace ~
28915 \InsetSpace ~
28916 \InsetSpace ~
28917 sdcdbsrc-goto-sdcdb\InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 \InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 Got
28928 o the SDCDB output buffer 
28929 \newline
28930 ;;\InsetSpace ~
28931 t\InsetSpace ~
28932 \InsetSpace ~
28933 \InsetSpace ~
28934 \InsetSpace ~
28935 \InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 \InsetSpace ~
28940 \InsetSpace ~
28941 \InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 \InsetSpace ~
28945 \InsetSpace ~
28946 sdcdbsrc-mode\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 Toggles Sdcdbsrc mode (turns it
28963  off) 
28964 \newline
28965 ;; 
28966 \newline
28967 ;;\InsetSpace ~
28968 C-c\InsetSpace ~
28969 C-f\InsetSpace ~
28970 \InsetSpace ~
28971 \InsetSpace ~
28972 \InsetSpace ~
28973 \InsetSpace ~
28974 \InsetSpace ~
28975 \InsetSpace ~
28976 \InsetSpace ~
28977 \InsetSpace ~
28978 sdcdb-finish-from-src\InsetSpace ~
28979 \InsetSpace ~
28980 \InsetSpace ~
28981 \InsetSpace ~
28982 \InsetSpace ~
28983 \InsetSpace ~
28984 \InsetSpace ~
28985 \InsetSpace ~
28986 SDCDB finish command 
28987 \newline
28988 ;; 
28989 \newline
28990 ;;\InsetSpace ~
28991 C-x\InsetSpace ~
28992 SPC\InsetSpace ~
28993 \InsetSpace ~
28994 \InsetSpace ~
28995 \InsetSpace ~
28996 \InsetSpace ~
28997 \InsetSpace ~
28998 \InsetSpace ~
28999 \InsetSpace ~
29000 \InsetSpace ~
29001 sdcdb-brea
29002 k\InsetSpace ~
29003 \InsetSpace ~
29004 \InsetSpace ~
29005 \InsetSpace ~
29006 \InsetSpace ~
29007 \InsetSpace ~
29008 \InsetSpace ~
29009 \InsetSpace ~
29010 \InsetSpace ~
29011 \InsetSpace ~
29012 \InsetSpace ~
29013 \InsetSpace ~
29014 \InsetSpace ~
29015 \InsetSpace ~
29016 \InsetSpace ~
29017 \InsetSpace ~
29018 \InsetSpace ~
29019 \InsetSpace ~
29020 Set break for line with point 
29021 \newline
29022 ;;\InsetSpace ~
29023 ESC\InsetSpace ~
29024 t\InsetSpace ~
29025 \InsetSpace ~
29026 \InsetSpace ~
29027 \InsetSpace ~
29028 \InsetSpace ~
29029 \InsetSpace ~
29030 \InsetSpace ~
29031 \InsetSpace ~
29032 \InsetSpace ~
29033 \InsetSpace ~
29034 \InsetSpace ~
29035 sdcdbsrc-mode\InsetSpace ~
29036 \InsetSpace ~
29037 \InsetSpace ~
29038 \InsetSpace ~
29039 \InsetSpace ~
29040 \InsetSpace ~
29041 \InsetSpace ~
29042 \InsetSpace ~
29043 \InsetSpace ~
29044 \InsetSpace ~
29045 \InsetSpace ~
29046 \InsetSpace ~
29047 \InsetSpace ~
29048 \InsetSpace ~
29049 \InsetSpace ~
29050 \InsetSpace ~
29051 Toggle Sdcdbsrc mode 
29052 \newline
29053 ;;\InsetSpace ~
29054 ESC\InsetSpace ~
29055 m\InsetSpace ~
29056 \InsetSpace ~
29057 \InsetSpace ~
29058 \InsetSpace ~
29059 \InsetSpace ~
29060 \InsetSpace ~
29061 \InsetSpace ~
29062 \InsetSpace ~
29063 \InsetSpace ~
29064 \InsetSpace ~
29065 \InsetSpace ~
29066 sdc
29067 dbsrc-srcmode\InsetSpace ~
29068 \InsetSpace ~
29069 \InsetSpace ~
29070 \InsetSpace ~
29071 \InsetSpace ~
29072 \InsetSpace ~
29073 \InsetSpace ~
29074 \InsetSpace ~
29075 \InsetSpace ~
29076 \InsetSpace ~
29077 \InsetSpace ~
29078 \InsetSpace ~
29079 \InsetSpace ~
29080 Toggle list mode 
29081 \newline
29082 ;; 
29083 \newline
29084
29085 \family default
29086
29087 \newpage
29088
29089 \end_layout
29090
29091 \begin_layout Chapter
29092 TIPS
29093 \end_layout
29094
29095 \begin_layout Standard
29096 Here are a few guidelines that will help the compiler generate more efficient
29097  code, some of the tips are specific to this compiler others are generally
29098  good programming practice.
29099 \end_layout
29100
29101 \begin_layout Itemize
29102 Use the smallest data type to represent your data-value.
29103  If it is known in advance that the value is going to be less than 256 then
29104  use an 'unsigned char' instead of a 'short' or 'int'.
29105  Please note, that ANSI C requires both signed and unsigned chars to be
29106  promoted to 'signed int'
29107 \begin_inset LatexCommand \index{promotion to signed int}
29108
29109 \end_inset
29110
29111
29112 \begin_inset Marginal
29113 status collapsed
29114
29115 \begin_layout Standard
29116
29117 \series bold
29118 \InsetSpace ~
29119 !
29120 \end_layout
29121
29122 \end_inset
29123
29124  before doing any operation.
29125  This promotion
29126 \begin_inset LatexCommand \index{type promotion}
29127
29128 \end_inset
29129
29130
29131 \begin_inset LatexCommand \label{type promotion}
29132
29133 \end_inset
29134
29135  can be omitted, if the result is the same.
29136  The effect of the promotion rules together with the sign-extension is often
29137  surprising:
29138 \end_layout
29139
29140 \begin_deeper
29141 \begin_layout Verse
29142
29143 \family typewriter
29144 unsigned char uc = 0xfe;
29145 \newline
29146 if (uc * uc < 0) /* this is true! */
29147 \newline
29148 {
29149 \newline
29150 \InsetSpace ~
29151 \InsetSpace ~
29152 \InsetSpace ~
29153 \InsetSpace ~
29154 ....
29155 \newline
29156 }
29157 \end_layout
29158
29159 \begin_layout Standard
29160
29161 \family typewriter
29162 uc * uc
29163 \family default
29164  is evaluated as 
29165 \family typewriter
29166 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29167 \family default
29168 .
29169  
29170 \newline
29171 Another one:
29172 \end_layout
29173
29174 \begin_layout Verse
29175
29176 \family typewriter
29177 (unsigned char) -12 / (signed char) -3 = ...
29178 \end_layout
29179
29180 \begin_layout Standard
29181 No, the result is not 4:
29182 \end_layout
29183
29184 \begin_layout Verse
29185
29186 \family typewriter
29187 (int) (unsigned char) -12 / (int) (signed char) -3 =
29188 \newline
29189 (int) (unsigned char)
29190  0xf4 / (int) (signed char) 0xfd =
29191 \newline
29192 (int) 0x00f4 / (int) 0xfffd =
29193 \newline
29194 (int) 0x00f4
29195  / (int) 0xfffd =
29196 \newline
29197 (int) 244 / (int) -3 =
29198 \newline
29199 (int) -81 = (int) 0xffaf;
29200 \end_layout
29201
29202 \begin_layout Standard
29203 Don't complain, that gcc gives you a different result.
29204  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29205  Therefore the results are different.
29206 \newline
29207 From 
29208 \begin_inset Quotes sld
29209 \end_inset
29210
29211 comp.lang.c FAQ
29212 \begin_inset Quotes srd
29213 \end_inset
29214
29215 :
29216 \end_layout
29217
29218 \begin_layout Quote
29219
29220 \emph on
29221 If well-defined overflow characteristics are important and negative values
29222  are not, or if you want to steer clear of sign-extension problems when
29223  manipulating bits or bytes, use one of the corresponding unsigned types.
29224  (Beware when mixing signed and unsigned values in expressions, though.)
29225 \newline
29226 Although
29227  character types (especially unsigned char) can be used as "tiny" integers,
29228  doing so is sometimes more trouble than it's worth, due to unpredictable
29229  sign extension and increased code size.
29230 \end_layout
29231
29232 \end_deeper
29233 \begin_layout Itemize
29234 Use unsigned when it is known in advance that the value is not going to
29235  be negative.
29236  This helps especially if you are doing division or multiplication, bit-shifting
29237  or are using an array index.
29238 \end_layout
29239
29240 \begin_layout Itemize
29241 NEVER jump into a LOOP.
29242 \end_layout
29243
29244 \begin_layout Itemize
29245 Declare the variables to be local
29246 \begin_inset LatexCommand \index{local variables}
29247
29248 \end_inset
29249
29250  whenever possible, especially loop control variables (induction).
29251 \end_layout
29252
29253 \begin_layout Itemize
29254 Have a look at the assembly listing to get a 
29255 \begin_inset Quotes sld
29256 \end_inset
29257
29258 feeling
29259 \begin_inset Quotes srd
29260 \end_inset
29261
29262  for the code generation.
29263 \end_layout
29264
29265 \begin_layout Section
29266 Porting code from or to other compilers
29267 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29268
29269 \end_inset
29270
29271
29272 \end_layout
29273
29274 \begin_layout Itemize
29275 check whether endianness of the compilers differs and adapt where needed.
29276 \end_layout
29277
29278 \begin_layout Itemize
29279 check the device specific header files
29280 \begin_inset LatexCommand \index{Header files}
29281
29282 \end_inset
29283
29284
29285 \begin_inset LatexCommand \index{Include files}
29286
29287 \end_inset
29288
29289  for compiler specific syntax.
29290  Eventually include the file <compiler.h
29291 \begin_inset LatexCommand \index{compiler.h (include file)}
29292
29293 \end_inset
29294
29295
29296 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29297
29298 \end_inset
29299
29300  to allow using common header files.
29301  (see f.e.
29302  cc2510fx.h 
29303 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29304
29305 \end_inset
29306
29307 ).
29308 \end_layout
29309
29310 \begin_layout Itemize
29311 check whether the startup code contains the correct initialization (watchdog,
29312  peripherals).
29313 \end_layout
29314
29315 \begin_layout Itemize
29316 check whether the sizes of short, int, long match.
29317 \end_layout
29318
29319 \begin_layout Itemize
29320 check if some 16 or 32 bit hardware registers require a specific addressing
29321  order (least significant or most significant byte first) and adapt if needed
29322  (
29323 \emph on
29324 first
29325 \emph default
29326  and 
29327 \emph on
29328 last
29329 \emph default
29330  relate to time and not to lower/upper memory location here, so this is
29331  
29332 \emph on
29333 not
29334 \emph default
29335  the same as endianness).
29336 \end_layout
29337
29338 \begin_layout Itemize
29339 check whether the keyword 
29340 \emph on
29341 volatile
29342 \emph default
29343  is used where needed.
29344  The compilers might differ in their optimization characteristics (as different
29345  versions of the same compiler might also use more clever optimizations
29346  this is good idea anyway).
29347  See section 
29348 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29349
29350 \end_inset
29351
29352 .
29353 \end_layout
29354
29355 \begin_layout Itemize
29356 check that the compilers are not told to supress warnings.
29357 \end_layout
29358
29359 \begin_layout Itemize
29360 check and convert compiler specific extensions (interrupts, memory areas,
29361  pragmas etc.).
29362 \end_layout
29363
29364 \begin_layout Itemize
29365 check for differences in type promotion.
29366  Especially check for math operations on 
29367 \family typewriter
29368 char
29369 \family default
29370  or 
29371 \family typewriter
29372 unsigned char
29373 \family default
29374  variables.
29375  For the sake of C99 compatibility SDCC will probably promote these to 
29376 \family typewriter
29377 int
29378 \family default
29379  more often than other compilers.
29380  Eventually insert explicit casts to 
29381 \family typewriter
29382 (char) 
29383 \family default
29384 or
29385 \family typewriter
29386  (unsigned char)
29387 \family default
29388 .
29389  Also check that the ~\InsetSpace ~
29390 operator
29391 \begin_inset LatexCommand \index{\~\/ Operator}
29392
29393 \end_inset
29394
29395  is not used on 
29396 \family typewriter
29397 bit
29398 \begin_inset LatexCommand \index{bit}
29399
29400 \end_inset
29401
29402
29403 \family default
29404  variables, use the !\InsetSpace ~
29405 operator instead.
29406  See sections 
29407 \begin_inset LatexCommand \ref{type promotion}
29408
29409 \end_inset
29410
29411  and 
29412 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29413
29414 \end_inset
29415
29416 .
29417 \end_layout
29418
29419 \begin_layout Itemize
29420 check the assembly code generated for interrupt routines (f.e.
29421  for calls to possibly non-reentrant library functions).
29422 \end_layout
29423
29424 \begin_layout Itemize
29425 check whether timing loops result in proper timing (or preferably consider
29426  a rewrite of the code with timer based delays instead).
29427 \end_layout
29428
29429 \begin_layout Itemize
29430 check for differences in printf parameters (some compilers push (va_arg
29431 \begin_inset LatexCommand \index{vararg, va\_arg}
29432
29433 \end_inset
29434
29435 ) char variables as 
29436 \family typewriter
29437 int
29438 \family default
29439  others push them as 
29440 \family typewriter
29441 char
29442 \family default
29443 .
29444  See section 
29445 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29446
29447 \end_inset
29448
29449 ).
29450 \end_layout
29451
29452 \begin_layout Itemize
29453 check the resulting memory map
29454 \begin_inset LatexCommand \index{Memory map}
29455
29456 \end_inset
29457
29458 .
29459  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29460 ly idata, pdata, xdata).
29461  Eventually check if unexpected library functions are included.
29462 \end_layout
29463
29464 \begin_layout Section
29465 Tools
29466 \begin_inset LatexCommand \index{Tools}
29467
29468 \end_inset
29469
29470  included in the distribution
29471 \end_layout
29472
29473 \begin_layout Standard
29474 \align left
29475 \begin_inset Tabular
29476 <lyxtabular version="3" rows="12" columns="3">
29477 <features>
29478 <column alignment="left" valignment="top" leftline="true" width="0pt">
29479 <column alignment="left" valignment="top" leftline="true" width="0pt">
29480 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29481 <row topline="true" bottomline="true">
29482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29483 \begin_inset Text
29484
29485 \begin_layout Standard
29486
29487 \series bold
29488 Name
29489 \end_layout
29490
29491 \end_inset
29492 </cell>
29493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29494 \begin_inset Text
29495
29496 \begin_layout Standard
29497
29498 \series bold
29499 Purpose
29500 \end_layout
29501
29502 \end_inset
29503 </cell>
29504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29505 \begin_inset Text
29506
29507 \begin_layout Standard
29508
29509 \series bold
29510 Directory
29511 \end_layout
29512
29513 \end_inset
29514 </cell>
29515 </row>
29516 <row topline="true">
29517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29518 \begin_inset Text
29519
29520 \begin_layout Standard
29521 uCsim
29522 \begin_inset LatexCommand \index{uCsim}
29523
29524 \end_inset
29525
29526
29527 \end_layout
29528
29529 \end_inset
29530 </cell>
29531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29532 \begin_inset Text
29533
29534 \begin_layout Standard
29535 Simulator for various architectures
29536 \end_layout
29537
29538 \end_inset
29539 </cell>
29540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29541 \begin_inset Text
29542
29543 \begin_layout Standard
29544 sdcc/sim/ucsim
29545 \end_layout
29546
29547 \end_inset
29548 </cell>
29549 </row>
29550 <row topline="true">
29551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29552 \begin_inset Text
29553
29554 \begin_layout Standard
29555 keil2sdcc.pl
29556 \end_layout
29557
29558 \end_inset
29559 </cell>
29560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29561 \begin_inset Text
29562
29563 \begin_layout Standard
29564 header file
29565 \begin_inset LatexCommand \index{Header files}
29566
29567 \end_inset
29568
29569
29570 \begin_inset LatexCommand \index{Include files}
29571
29572 \end_inset
29573
29574  conversion
29575 \end_layout
29576
29577 \end_inset
29578 </cell>
29579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29580 \begin_inset Text
29581
29582 \begin_layout Standard
29583 sdcc/support/scripts
29584 \end_layout
29585
29586 \end_inset
29587 </cell>
29588 </row>
29589 <row topline="true">
29590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29591 \begin_inset Text
29592
29593 \begin_layout Standard
29594 mh2h.c
29595 \end_layout
29596
29597 \end_inset
29598 </cell>
29599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29600 \begin_inset Text
29601
29602 \begin_layout Standard
29603 header file conversion
29604 \end_layout
29605
29606 \end_inset
29607 </cell>
29608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29609 \begin_inset Text
29610
29611 \begin_layout Standard
29612 sdcc/support/scripts
29613 \end_layout
29614
29615 \end_inset
29616 </cell>
29617 </row>
29618 <row topline="true">
29619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29620 \begin_inset Text
29621
29622 \begin_layout Standard
29623 as-gbz80
29624 \end_layout
29625
29626 \end_inset
29627 </cell>
29628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29629 \begin_inset Text
29630
29631 \begin_layout Standard
29632 Assembler
29633 \end_layout
29634
29635 \end_inset
29636 </cell>
29637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29638 \begin_inset Text
29639
29640 \begin_layout Standard
29641
29642 \family roman
29643 \series medium
29644 \shape up
29645 \size normal
29646 \emph off
29647 \bar no
29648 \noun off
29649 \color none
29650 sdcc/bin
29651 \end_layout
29652
29653 \end_inset
29654 </cell>
29655 </row>
29656 <row topline="true">
29657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29658 \begin_inset Text
29659
29660 \begin_layout Standard
29661 as-z80
29662 \end_layout
29663
29664 \end_inset
29665 </cell>
29666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29667 \begin_inset Text
29668
29669 \begin_layout Standard
29670 Assembler
29671 \end_layout
29672
29673 \end_inset
29674 </cell>
29675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29676 \begin_inset Text
29677
29678 \begin_layout Standard
29679
29680 \family roman
29681 \series medium
29682 \shape up
29683 \size normal
29684 \emph off
29685 \bar no
29686 \noun off
29687 \color none
29688 sdcc/bin
29689 \end_layout
29690
29691 \end_inset
29692 </cell>
29693 </row>
29694 <row topline="true">
29695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29696 \begin_inset Text
29697
29698 \begin_layout Standard
29699 asx8051
29700 \end_layout
29701
29702 \end_inset
29703 </cell>
29704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29705 \begin_inset Text
29706
29707 \begin_layout Standard
29708 Assembler
29709 \end_layout
29710
29711 \end_inset
29712 </cell>
29713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29714 \begin_inset Text
29715
29716 \begin_layout Standard
29717
29718 \family roman
29719 \series medium
29720 \shape up
29721 \size normal
29722 \emph off
29723 \bar no
29724 \noun off
29725 \color none
29726 sdcc/bin
29727 \end_layout
29728
29729 \end_inset
29730 </cell>
29731 </row>
29732 <row topline="true">
29733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29734 \begin_inset Text
29735
29736 \begin_layout Standard
29737 SDCDB
29738 \end_layout
29739
29740 \end_inset
29741 </cell>
29742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29743 \begin_inset Text
29744
29745 \begin_layout Standard
29746 Simulator
29747 \end_layout
29748
29749 \end_inset
29750 </cell>
29751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29752 \begin_inset Text
29753
29754 \begin_layout Standard
29755
29756 \family roman
29757 \series medium
29758 \shape up
29759 \size normal
29760 \emph off
29761 \bar no
29762 \noun off
29763 \color none
29764 sdcc/bin
29765 \end_layout
29766
29767 \end_inset
29768 </cell>
29769 </row>
29770 <row topline="true">
29771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29772 \begin_inset Text
29773
29774 \begin_layout Standard
29775 aslink
29776 \end_layout
29777
29778 \end_inset
29779 </cell>
29780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29781 \begin_inset Text
29782
29783 \begin_layout Standard
29784 Linker
29785 \end_layout
29786
29787 \end_inset
29788 </cell>
29789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29790 \begin_inset Text
29791
29792 \begin_layout Standard
29793
29794 \family roman
29795 \series medium
29796 \shape up
29797 \size normal
29798 \emph off
29799 \bar no
29800 \noun off
29801 \color none
29802 sdcc/bin
29803 \end_layout
29804
29805 \end_inset
29806 </cell>
29807 </row>
29808 <row topline="true">
29809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29810 \begin_inset Text
29811
29812 \begin_layout Standard
29813 link-z80
29814 \end_layout
29815
29816 \end_inset
29817 </cell>
29818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29819 \begin_inset Text
29820
29821 \begin_layout Standard
29822 Linker
29823 \end_layout
29824
29825 \end_inset
29826 </cell>
29827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29828 \begin_inset Text
29829
29830 \begin_layout Standard
29831
29832 \family roman
29833 \series medium
29834 \shape up
29835 \size normal
29836 \emph off
29837 \bar no
29838 \noun off
29839 \color none
29840 sdcc/bin
29841 \end_layout
29842
29843 \end_inset
29844 </cell>
29845 </row>
29846 <row topline="true">
29847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29848 \begin_inset Text
29849
29850 \begin_layout Standard
29851 link-gbz80
29852 \end_layout
29853
29854 \end_inset
29855 </cell>
29856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29857 \begin_inset Text
29858
29859 \begin_layout Standard
29860 Linker
29861 \end_layout
29862
29863 \end_inset
29864 </cell>
29865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29866 \begin_inset Text
29867
29868 \begin_layout Standard
29869
29870 \family roman
29871 \series medium
29872 \shape up
29873 \size normal
29874 \emph off
29875 \bar no
29876 \noun off
29877 \color none
29878 sdcc/bin
29879 \end_layout
29880
29881 \end_inset
29882 </cell>
29883 </row>
29884 <row topline="true" bottomline="true">
29885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29886 \begin_inset Text
29887
29888 \begin_layout Standard
29889 packihx
29890 \end_layout
29891
29892 \end_inset
29893 </cell>
29894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29895 \begin_inset Text
29896
29897 \begin_layout Standard
29898 Intel Hex packer 
29899 \begin_inset LatexCommand \index{packihx (tool)}
29900
29901 \end_inset
29902
29903
29904 \end_layout
29905
29906 \end_inset
29907 </cell>
29908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29909 \begin_inset Text
29910
29911 \begin_layout Standard
29912
29913 \family roman
29914 \series medium
29915 \shape up
29916 \size normal
29917 \emph off
29918 \bar no
29919 \noun off
29920 \color none
29921 sdcc/bin
29922 \end_layout
29923
29924 \end_inset
29925 </cell>
29926 </row>
29927 </lyxtabular>
29928
29929 \end_inset
29930
29931
29932 \newline
29933
29934 \end_layout
29935
29936 \begin_layout Section
29937 Documentation
29938 \begin_inset LatexCommand \index{Documentation}
29939
29940 \end_inset
29941
29942  included in the distribution
29943 \end_layout
29944
29945 \begin_layout Standard
29946 \align left
29947 \begin_inset Tabular
29948 <lyxtabular version="3" rows="10" columns="2">
29949 <features>
29950 <column alignment="block" valignment="top" leftline="true" width="40col%">
29951 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29952 <row topline="true" bottomline="true" endhead="true">
29953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29954 \begin_inset Text
29955
29956 \begin_layout Standard
29957
29958 \series bold
29959 Subject / Title
29960 \end_layout
29961
29962 \end_inset
29963 </cell>
29964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29965 \begin_inset Text
29966
29967 \begin_layout Standard
29968
29969 \series bold
29970 Filename / Where to get
29971 \end_layout
29972
29973 \end_inset
29974 </cell>
29975 </row>
29976 <row topline="true">
29977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29978 \begin_inset Text
29979
29980 \begin_layout Standard
29981 SDCC Compiler User Guide
29982 \end_layout
29983
29984 \end_inset
29985 </cell>
29986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29987 \begin_inset Text
29988
29989 \begin_layout Standard
29990 You're reading it right now
29991 \emph on
29992  \InsetSpace ~
29993 \InsetSpace ~
29994 \InsetSpace ~
29995
29996 \hfill
29997 online at:
29998 \emph default
29999
30000 \newline
30001
30002 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30003
30004 \end_inset
30005
30006
30007 \end_layout
30008
30009 \end_inset
30010 </cell>
30011 </row>
30012 <row topline="true">
30013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30014 \begin_inset Text
30015
30016 \begin_layout Standard
30017 Changelog of SDCC
30018 \end_layout
30019
30020 \end_inset
30021 </cell>
30022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30023 \begin_inset Text
30024
30025 \begin_layout Standard
30026 sdcc/Changelog
30027 \emph on
30028  \InsetSpace ~
30029 \InsetSpace ~
30030 \InsetSpace ~
30031
30032 \hfill
30033 online at:
30034 \emph default
30035
30036 \newline
30037
30038 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30039
30040 \end_inset
30041
30042
30043 \end_layout
30044
30045 \end_inset
30046 </cell>
30047 </row>
30048 <row topline="true">
30049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30050 \begin_inset Text
30051
30052 \begin_layout Standard
30053 ASXXXX
30054 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30055
30056 \end_inset
30057
30058
30059 \begin_inset LatexCommand \index{Assembler documentation}
30060
30061 \end_inset
30062
30063  Assemblers and
30064 \newline
30065 ASLINK
30066 \begin_inset LatexCommand \index{aslink}
30067
30068 \end_inset
30069
30070
30071 \begin_inset LatexCommand \index{Linker documentation}
30072
30073 \end_inset
30074
30075  Relocating Linker
30076 \end_layout
30077
30078 \end_inset
30079 </cell>
30080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30081 \begin_inset Text
30082
30083 \begin_layout Standard
30084 sdcc/as/doc/asxhtm.html 
30085 \emph on
30086 \InsetSpace ~
30087 \InsetSpace ~
30088 \InsetSpace ~
30089
30090 \hfill
30091 online at:
30092 \emph default
30093
30094 \newline
30095
30096 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30097
30098 \end_inset
30099
30100
30101 \end_layout
30102
30103 \end_inset
30104 </cell>
30105 </row>
30106 <row topline="true">
30107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30108 \begin_inset Text
30109
30110 \begin_layout Standard
30111 SDCC regression test
30112 \begin_inset LatexCommand \index{Regression test}
30113
30114 \end_inset
30115
30116
30117 \end_layout
30118
30119 \end_inset
30120 </cell>
30121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30122 \begin_inset Text
30123
30124 \begin_layout Standard
30125 sdcc/doc/test_suite_spec.pdf 
30126 \emph on
30127 \InsetSpace ~
30128 \InsetSpace ~
30129 \InsetSpace ~
30130
30131 \hfill
30132 online at:
30133 \emph default
30134
30135 \newline
30136
30137 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30138
30139 \end_inset
30140
30141
30142 \end_layout
30143
30144 \end_inset
30145 </cell>
30146 </row>
30147 <row topline="true">
30148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30149 \begin_inset Text
30150
30151 \begin_layout Standard
30152 Various notes
30153 \end_layout
30154
30155 \end_inset
30156 </cell>
30157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30158 \begin_inset Text
30159
30160 \begin_layout Standard
30161 sdcc/doc/* 
30162 \emph on
30163 \InsetSpace ~
30164 \InsetSpace ~
30165 \InsetSpace ~
30166
30167 \hfill
30168 online at:
30169 \emph default
30170
30171 \newline
30172
30173 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30174
30175 \end_inset
30176
30177
30178 \end_layout
30179
30180 \end_inset
30181 </cell>
30182 </row>
30183 <row topline="true">
30184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30185 \begin_inset Text
30186
30187 \begin_layout Standard
30188 Notes on debugging with SDCDB
30189 \begin_inset LatexCommand \index{SDCDB (debugger)}
30190
30191 \end_inset
30192
30193
30194 \end_layout
30195
30196 \end_inset
30197 </cell>
30198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30199 \begin_inset Text
30200
30201 \begin_layout Standard
30202 sdcc/debugger/README 
30203 \emph on
30204 \InsetSpace ~
30205 \InsetSpace ~
30206 \InsetSpace ~
30207
30208 \hfill
30209 online at
30210 \emph default
30211 :
30212 \newline
30213
30214 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30215
30216 \end_inset
30217
30218
30219 \end_layout
30220
30221 \end_inset
30222 </cell>
30223 </row>
30224 <row topline="true">
30225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30226 \begin_inset Text
30227
30228 \begin_layout Standard
30229 uCsim
30230 \begin_inset LatexCommand \index{uCsim}
30231
30232 \end_inset
30233
30234  Software simulator for microcontrollers
30235 \end_layout
30236
30237 \end_inset
30238 </cell>
30239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30240 \begin_inset Text
30241
30242 \begin_layout Standard
30243
30244 \family roman
30245 \series medium
30246 \shape up
30247 \size normal
30248 \emph off
30249 \bar no
30250 \noun off
30251 \color none
30252 sdcc/sim/ucsim/doc
30253 \family default
30254 \series default
30255 \shape default
30256 \size default
30257 \emph default
30258 \bar default
30259 \noun default
30260 /index.html 
30261 \emph on
30262 \InsetSpace ~
30263 \InsetSpace ~
30264 \InsetSpace ~
30265
30266 \hfill
30267 online at:
30268 \emph default
30269
30270 \newline
30271
30272 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30273
30274 \end_inset
30275
30276
30277 \end_layout
30278
30279 \end_inset
30280 </cell>
30281 </row>
30282 <row topline="true">
30283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30284 \begin_inset Text
30285
30286 \begin_layout Standard
30287 Temporary notes on the pic16
30288 \begin_inset LatexCommand \index{PIC16}
30289
30290 \end_inset
30291
30292  port
30293 \end_layout
30294
30295 \end_inset
30296 </cell>
30297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30298 \begin_inset Text
30299
30300 \begin_layout Standard
30301 sdcc/src/pic16/NOTES 
30302 \emph on
30303 \InsetSpace ~
30304 \InsetSpace ~
30305 \InsetSpace ~
30306
30307 \hfill
30308 online at:
30309 \newline
30310
30311 \emph default
30312
30313 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30314
30315 \end_inset
30316
30317
30318 \end_layout
30319
30320 \end_inset
30321 </cell>
30322 </row>
30323 <row topline="true" bottomline="true">
30324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30325 \begin_inset Text
30326
30327 \begin_layout Standard
30328 SDCC internal documentation (debugging file format)
30329 \end_layout
30330
30331 \end_inset
30332 </cell>
30333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30334 \begin_inset Text
30335
30336 \begin_layout Standard
30337 sdcc/doc/
30338 \family roman
30339 \series medium
30340 \shape up
30341 \size normal
30342 \emph off
30343 \bar no
30344 \noun off
30345 \color none
30346 cdbfileformat.pd
30347 \family default
30348 \series default
30349 \shape default
30350 \size default
30351 \emph default
30352 \bar default
30353 \noun default
30354 f
30355 \emph on
30356  \InsetSpace ~
30357 \InsetSpace ~
30358 \InsetSpace ~
30359
30360 \hfill
30361 online at:
30362 \emph default
30363
30364 \newline
30365
30366 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30367
30368 \end_inset
30369
30370
30371 \end_layout
30372
30373 \end_inset
30374 </cell>
30375 </row>
30376 </lyxtabular>
30377
30378 \end_inset
30379
30380
30381 \newline
30382
30383 \end_layout
30384
30385 \begin_layout Section
30386 Related open source tools
30387 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30388
30389 \end_inset
30390
30391
30392 \begin_inset LatexCommand \index{Related tools}
30393
30394 \end_inset
30395
30396
30397 \end_layout
30398
30399 \begin_layout Standard
30400 \align left
30401 \begin_inset Tabular
30402 <lyxtabular version="3" rows="14" columns="3">
30403 <features>
30404 <column alignment="left" valignment="top" leftline="true" width="0pt">
30405 <column alignment="block" valignment="top" leftline="true" width="30line%">
30406 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30407 <row topline="true" bottomline="true">
30408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30409 \begin_inset Text
30410
30411 \begin_layout Standard
30412
30413 \series bold
30414 Name
30415 \end_layout
30416
30417 \end_inset
30418 </cell>
30419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30420 \begin_inset Text
30421
30422 \begin_layout Standard
30423
30424 \series bold
30425 Purpose
30426 \end_layout
30427
30428 \end_inset
30429 </cell>
30430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30431 \begin_inset Text
30432
30433 \begin_layout Standard
30434
30435 \series bold
30436 Where to get
30437 \end_layout
30438
30439 \end_inset
30440 </cell>
30441 </row>
30442 <row topline="true">
30443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30444 \begin_inset Text
30445
30446 \begin_layout Standard
30447 gpsim
30448 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30449
30450 \end_inset
30451
30452
30453 \end_layout
30454
30455 \end_inset
30456 </cell>
30457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30458 \begin_inset Text
30459
30460 \begin_layout Standard
30461 PIC simulator
30462 \end_layout
30463
30464 \end_inset
30465 </cell>
30466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30467 \begin_inset Text
30468
30469 \begin_layout Standard
30470 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30471
30472 \end_inset
30473
30474
30475 \end_layout
30476
30477 \end_inset
30478 </cell>
30479 </row>
30480 <row topline="true">
30481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30482 \begin_inset Text
30483
30484 \begin_layout Standard
30485 gputils
30486 \begin_inset LatexCommand \index{gputils (pic tools)}
30487
30488 \end_inset
30489
30490
30491 \end_layout
30492
30493 \end_inset
30494 </cell>
30495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30496 \begin_inset Text
30497
30498 \begin_layout Standard
30499 GNU PIC utilities
30500 \end_layout
30501
30502 \end_inset
30503 </cell>
30504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30505 \begin_inset Text
30506
30507 \begin_layout Standard
30508 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30509
30510 \end_inset
30511
30512
30513 \end_layout
30514
30515 \end_inset
30516 </cell>
30517 </row>
30518 <row topline="true">
30519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30520 \begin_inset Text
30521
30522 \begin_layout Standard
30523 flP5
30524 \end_layout
30525
30526 \end_inset
30527 </cell>
30528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30529 \begin_inset Text
30530
30531 \begin_layout Standard
30532 PIC programmer
30533 \end_layout
30534
30535 \end_inset
30536 </cell>
30537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30538 \begin_inset Text
30539
30540 \begin_layout Standard
30541 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30542
30543 \end_inset
30544
30545
30546 \end_layout
30547
30548 \end_inset
30549 </cell>
30550 </row>
30551 <row topline="true">
30552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30553 \begin_inset Text
30554
30555 \begin_layout Standard
30556 ec2drv/newcdb
30557 \end_layout
30558
30559 \end_inset
30560 </cell>
30561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30562 \begin_inset Text
30563
30564 \begin_layout Standard
30565 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30566  (Unix only)
30567 \end_layout
30568
30569 \end_inset
30570 </cell>
30571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30572 \begin_inset Text
30573
30574 \begin_layout Standard
30575 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30576
30577 \end_inset
30578
30579
30580 \end_layout
30581
30582 \end_inset
30583 </cell>
30584 </row>
30585 <row topline="true">
30586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30587 \begin_inset Text
30588
30589 \begin_layout Standard
30590 indent
30591 \begin_inset LatexCommand \index{indent (source formatting tool)}
30592
30593 \end_inset
30594
30595
30596 \end_layout
30597
30598 \end_inset
30599 </cell>
30600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30601 \begin_inset Text
30602
30603 \begin_layout Standard
30604 Formats C source - Master of the white spaces
30605 \end_layout
30606
30607 \end_inset
30608 </cell>
30609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30610 \begin_inset Text
30611
30612 \begin_layout Standard
30613 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30614
30615 \end_inset
30616
30617
30618 \end_layout
30619
30620 \end_inset
30621 </cell>
30622 </row>
30623 <row topline="true">
30624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30625 \begin_inset Text
30626
30627 \begin_layout Standard
30628 srecord
30629 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30630
30631 \end_inset
30632
30633
30634 \end_layout
30635
30636 \end_inset
30637 </cell>
30638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30639 \begin_inset Text
30640
30641 \begin_layout Standard
30642 Object file conversion, checksumming, ...
30643 \end_layout
30644
30645 \end_inset
30646 </cell>
30647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30648 \begin_inset Text
30649
30650 \begin_layout Standard
30651 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30652
30653 \end_inset
30654
30655
30656 \end_layout
30657
30658 \end_inset
30659 </cell>
30660 </row>
30661 <row topline="true">
30662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30663 \begin_inset Text
30664
30665 \begin_layout Standard
30666 objdump
30667 \begin_inset LatexCommand \index{objdump (tool)}
30668
30669 \end_inset
30670
30671
30672 \end_layout
30673
30674 \end_inset
30675 </cell>
30676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30677 \begin_inset Text
30678
30679 \begin_layout Standard
30680 Object file conversion, ...
30681 \end_layout
30682
30683 \end_inset
30684 </cell>
30685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30686 \begin_inset Text
30687
30688 \begin_layout Standard
30689 Part of binutils (should be there anyway)
30690 \end_layout
30691
30692 \end_inset
30693 </cell>
30694 </row>
30695 <row topline="true">
30696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30697 \begin_inset Text
30698
30699 \begin_layout Standard
30700 cmon51
30701 \end_layout
30702
30703 \end_inset
30704 </cell>
30705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30706 \begin_inset Text
30707
30708 \begin_layout Standard
30709 8051 monitor (hex up-/download, single step, disassemble)
30710 \end_layout
30711
30712 \end_inset
30713 </cell>
30714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30715 \begin_inset Text
30716
30717 \begin_layout Standard
30718 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30719
30720 \end_inset
30721
30722
30723 \end_layout
30724
30725 \end_inset
30726 </cell>
30727 </row>
30728 <row topline="true">
30729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30730 \begin_inset Text
30731
30732 \begin_layout Standard
30733 doxygen
30734 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30735
30736 \end_inset
30737
30738
30739 \end_layout
30740
30741 \end_inset
30742 </cell>
30743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30744 \begin_inset Text
30745
30746 \begin_layout Standard
30747 Source code documentation system
30748 \end_layout
30749
30750 \end_inset
30751 </cell>
30752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30753 \begin_inset Text
30754
30755 \begin_layout Standard
30756 \begin_inset LatexCommand \url{http://www.doxygen.org}
30757
30758 \end_inset
30759
30760
30761 \end_layout
30762
30763 \end_inset
30764 </cell>
30765 </row>
30766 <row topline="true">
30767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30768 \begin_inset Text
30769
30770 \begin_layout Standard
30771 kdevelop
30772 \end_layout
30773
30774 \end_inset
30775 </cell>
30776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30777 \begin_inset Text
30778
30779 \begin_layout Standard
30780 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30781 \end_layout
30782
30783 \end_inset
30784 </cell>
30785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30786 \begin_inset Text
30787
30788 \begin_layout Standard
30789 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30790
30791 \end_inset
30792
30793
30794 \end_layout
30795
30796 \end_inset
30797 </cell>
30798 </row>
30799 <row topline="true">
30800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30801 \begin_inset Text
30802
30803 \begin_layout Standard
30804 paulmon
30805 \end_layout
30806
30807 \end_inset
30808 </cell>
30809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30810 \begin_inset Text
30811
30812 \begin_layout Standard
30813 8051 monitor (hex up-/download, single step, disassemble)
30814 \end_layout
30815
30816 \end_inset
30817 </cell>
30818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30819 \begin_inset Text
30820
30821 \begin_layout Standard
30822 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30823
30824 \end_inset
30825
30826
30827 \end_layout
30828
30829 \end_inset
30830 </cell>
30831 </row>
30832 <row topline="true">
30833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30834 \begin_inset Text
30835
30836 \begin_layout Standard
30837 splint
30838 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30839
30840 \end_inset
30841
30842
30843 \end_layout
30844
30845 \end_inset
30846 </cell>
30847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30848 \begin_inset Text
30849
30850 \begin_layout Standard
30851 Statically checks c sources (see 
30852 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30853
30854 \end_inset
30855
30856 )
30857 \end_layout
30858
30859 \end_inset
30860 </cell>
30861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30862 \begin_inset Text
30863
30864 \begin_layout Standard
30865 \begin_inset LatexCommand \url{http://www.splint.org}
30866
30867 \end_inset
30868
30869
30870 \end_layout
30871
30872 \end_inset
30873 </cell>
30874 </row>
30875 <row topline="true" bottomline="true">
30876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30877 \begin_inset Text
30878
30879 \begin_layout Standard
30880 ddd
30881 \begin_inset LatexCommand \index{DDD (debugger)}
30882
30883 \end_inset
30884
30885
30886 \end_layout
30887
30888 \end_inset
30889 </cell>
30890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30891 \begin_inset Text
30892
30893 \begin_layout Standard
30894 Debugger, serves nicely as GUI to SDCDB
30895 \begin_inset LatexCommand \index{SDCDB (debugger)}
30896
30897 \end_inset
30898
30899  (Unix only)
30900 \end_layout
30901
30902 \end_inset
30903 </cell>
30904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30905 \begin_inset Text
30906
30907 \begin_layout Standard
30908 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30909
30910 \end_inset
30911
30912
30913 \end_layout
30914
30915 \end_inset
30916 </cell>
30917 </row>
30918 </lyxtabular>
30919
30920 \end_inset
30921
30922
30923 \newline
30924
30925 \end_layout
30926
30927 \begin_layout Section
30928 Related documentation / recommended reading
30929 \end_layout
30930
30931 \begin_layout Standard
30932 \align left
30933 \begin_inset Tabular
30934 <lyxtabular version="3" rows="7" columns="3">
30935 <features>
30936 <column alignment="left" valignment="top" leftline="true" width="0pt">
30937 <column alignment="left" valignment="top" leftline="true" width="0">
30938 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30939 <row topline="true" bottomline="true">
30940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30941 \begin_inset Text
30942
30943 \begin_layout Standard
30944
30945 \series bold
30946 Name
30947 \end_layout
30948
30949 \end_inset
30950 </cell>
30951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30952 \begin_inset Text
30953
30954 \begin_layout Standard
30955
30956 \series bold
30957 Subject / Title
30958 \end_layout
30959
30960 \end_inset
30961 </cell>
30962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30963 \begin_inset Text
30964
30965 \begin_layout Standard
30966
30967 \series bold
30968 Where to get
30969 \end_layout
30970
30971 \end_inset
30972 </cell>
30973 </row>
30974 <row topline="true">
30975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30976 \begin_inset Text
30977
30978 \begin_layout Standard
30979
30980 \family roman
30981 \series medium
30982 \shape up
30983 \size normal
30984 \emph off
30985 \bar no
30986 \noun off
30987 \color none
30988 c-refcard.pdf
30989 \end_layout
30990
30991 \end_inset
30992 </cell>
30993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30994 \begin_inset Text
30995
30996 \begin_layout Standard
30997 C Reference Card
30998 \begin_inset LatexCommand \index{C Reference card}
30999
31000 \end_inset
31001
31002 , 2 pages
31003 \end_layout
31004
31005 \end_inset
31006 </cell>
31007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31008 \begin_inset Text
31009
31010 \begin_layout Standard
31011 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31012
31013 \end_inset
31014
31015
31016 \end_layout
31017
31018 \end_inset
31019 </cell>
31020 </row>
31021 <row topline="true">
31022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31023 \begin_inset Text
31024
31025 \begin_layout Standard
31026 c-faq
31027 \end_layout
31028
31029 \end_inset
31030 </cell>
31031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31032 \begin_inset Text
31033
31034 \begin_layout Standard
31035 C-FAQ
31036 \begin_inset LatexCommand \index{C FAQ}
31037
31038 \end_inset
31039
31040
31041 \end_layout
31042
31043 \end_inset
31044 </cell>
31045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31046 \begin_inset Text
31047
31048 \begin_layout Standard
31049 \begin_inset LatexCommand \url{http://www.c-faq.com}
31050
31051 \end_inset
31052
31053
31054 \end_layout
31055
31056 \end_inset
31057 </cell>
31058 </row>
31059 <row topline="true">
31060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31061 \begin_inset Text
31062
31063 \begin_layout Standard
31064 ISO/IEC 9899:TC2
31065 \end_layout
31066
31067 \end_inset
31068 </cell>
31069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31070 \begin_inset Text
31071
31072 \begin_layout Standard
31073 \begin_inset Quotes sld
31074 \end_inset
31075
31076 C-Standard
31077 \begin_inset Quotes srd
31078 \end_inset
31079
31080
31081 \end_layout
31082
31083 \end_inset
31084 </cell>
31085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31086 \begin_inset Text
31087
31088 \begin_layout Standard
31089
31090 \size footnotesize
31091 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31092
31093 \end_inset
31094
31095
31096 \end_layout
31097
31098 \end_inset
31099 </cell>
31100 </row>
31101 <row topline="true">
31102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31103 \begin_inset Text
31104
31105 \begin_layout Standard
31106 ISO/IEC DTR 18037
31107 \end_layout
31108
31109 \end_inset
31110 </cell>
31111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31112 \begin_inset Text
31113
31114 \begin_layout Standard
31115 \begin_inset Quotes sld
31116 \end_inset
31117
31118 Extensions for Embedded C
31119 \begin_inset Quotes srd
31120 \end_inset
31121
31122
31123 \end_layout
31124
31125 \end_inset
31126 </cell>
31127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31128 \begin_inset Text
31129
31130 \begin_layout Standard
31131
31132 \size footnotesize
31133 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31134
31135 \end_inset
31136
31137
31138 \end_layout
31139
31140 \end_inset
31141 </cell>
31142 </row>
31143 <row topline="true">
31144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31145 \begin_inset Text
31146
31147 \begin_layout Standard
31148
31149 \end_layout
31150
31151 \end_inset
31152 </cell>
31153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31154 \begin_inset Text
31155
31156 \begin_layout Standard
31157 Latest datasheet of target CPU
31158 \end_layout
31159
31160 \end_inset
31161 </cell>
31162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31163 \begin_inset Text
31164
31165 \begin_layout Standard
31166 vendor
31167 \end_layout
31168
31169 \end_inset
31170 </cell>
31171 </row>
31172 <row topline="true" bottomline="true">
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31174 \begin_inset Text
31175
31176 \begin_layout Standard
31177
31178 \end_layout
31179
31180 \end_inset
31181 </cell>
31182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31183 \begin_inset Text
31184
31185 \begin_layout Standard
31186 Revision history of datasheet
31187 \end_layout
31188
31189 \end_inset
31190 </cell>
31191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31192 \begin_inset Text
31193
31194 \begin_layout Standard
31195 vendor
31196 \end_layout
31197
31198 \end_inset
31199 </cell>
31200 </row>
31201 </lyxtabular>
31202
31203 \end_inset
31204
31205
31206 \newline
31207
31208 \end_layout
31209
31210 \begin_layout Section
31211 Application notes specifically for SDCC
31212 \end_layout
31213
31214 \begin_layout Standard
31215 SDCC makes no claims about the completeness of this list and about up-to-datenes
31216 s or correctness of the application notes
31217 \begin_inset LatexCommand \index{Application notes}
31218
31219 \end_inset
31220
31221 .
31222 \end_layout
31223
31224 \begin_layout Standard
31225 \align left
31226
31227 \size footnotesize
31228 \begin_inset Tabular
31229 <lyxtabular version="3" rows="7" columns="3">
31230 <features>
31231 <column alignment="block" valignment="top" leftline="true" width="17col%">
31232 <column alignment="block" valignment="top" leftline="true" width="27col%">
31233 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31234 <row topline="true" bottomline="true">
31235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31236 \begin_inset Text
31237
31238 \begin_layout Standard
31239
31240 \series bold
31241 \size footnotesize
31242 Vendor
31243 \end_layout
31244
31245 \end_inset
31246 </cell>
31247 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31248 \begin_inset Text
31249
31250 \begin_layout Standard
31251
31252 \series bold
31253 \size footnotesize
31254 Subject / Title
31255 \end_layout
31256
31257 \end_inset
31258 </cell>
31259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31260 \begin_inset Text
31261
31262 \begin_layout Standard
31263
31264 \series bold
31265 \size footnotesize
31266 Where to get
31267 \end_layout
31268
31269 \end_inset
31270 </cell>
31271 </row>
31272 <row topline="true">
31273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31274 \begin_inset Text
31275
31276 \begin_layout Standard
31277
31278 \size footnotesize
31279 Maxim / Dallas
31280 \end_layout
31281
31282 \end_inset
31283 </cell>
31284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31285 \begin_inset Text
31286
31287 \begin_layout Standard
31288
31289 \size footnotesize
31290 Using the SDCC Compiler for the DS80C400
31291 \begin_inset LatexCommand \index{DS80C400}
31292
31293 \end_inset
31294
31295
31296 \end_layout
31297
31298 \end_inset
31299 </cell>
31300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31301 \begin_inset Text
31302
31303 \begin_layout Standard
31304
31305 \size footnotesize
31306 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31307
31308 \end_inset
31309
31310
31311 \end_layout
31312
31313 \end_inset
31314 </cell>
31315 </row>
31316 <row topline="true">
31317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31318 \begin_inset Text
31319
31320 \begin_layout Standard
31321
31322 \size footnotesize
31323 Maxim / Dallas
31324 \end_layout
31325
31326 \end_inset
31327 </cell>
31328 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31329 \begin_inset Text
31330
31331 \begin_layout Standard
31332
31333 \size footnotesize
31334 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31335 \begin_inset LatexCommand \index{DS89C4x0}
31336
31337 \end_inset
31338
31339  Family of Microcontrollers
31340 \end_layout
31341
31342 \end_inset
31343 </cell>
31344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31345 \begin_inset Text
31346
31347 \begin_layout Standard
31348
31349 \size footnotesize
31350 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31351
31352 \end_inset
31353
31354
31355 \end_layout
31356
31357 \end_inset
31358 </cell>
31359 </row>
31360 <row topline="true">
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31362 \begin_inset Text
31363
31364 \begin_layout Standard
31365
31366 \size footnotesize
31367 Silicon Laboratories / Cygnal
31368 \end_layout
31369
31370 \end_inset
31371 </cell>
31372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31373 \begin_inset Text
31374
31375 \begin_layout Standard
31376
31377 \size footnotesize
31378 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31379 \begin_inset LatexCommand \index{IDE}
31380
31381 \end_inset
31382
31383
31384 \end_layout
31385
31386 \end_inset
31387 </cell>
31388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31389 \begin_inset Text
31390
31391 \begin_layout Standard
31392
31393 \size footnotesize
31394 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31395
31396 \end_inset
31397
31398
31399 \end_layout
31400
31401 \end_inset
31402 </cell>
31403 </row>
31404 <row topline="true">
31405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31406 \begin_inset Text
31407
31408 \begin_layout Standard
31409
31410 \size footnotesize
31411 Ramtron / Goal Semiconductor
31412 \end_layout
31413
31414 \end_inset
31415 </cell>
31416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31417 \begin_inset Text
31418
31419 \begin_layout Standard
31420
31421 \size footnotesize
31422 Interfacing SDCC to Syn and Textpad
31423 \end_layout
31424
31425 \end_inset
31426 </cell>
31427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31428 \begin_inset Text
31429
31430 \begin_layout Standard
31431
31432 \size footnotesize
31433 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31434
31435 \end_inset
31436
31437
31438 \end_layout
31439
31440 \end_inset
31441 </cell>
31442 </row>
31443 <row topline="true">
31444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31445 \begin_inset Text
31446
31447 \begin_layout Standard
31448
31449 \size footnotesize
31450 Ramtron / Goal Semiconductor
31451 \end_layout
31452
31453 \end_inset
31454 </cell>
31455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31456 \begin_inset Text
31457
31458 \begin_layout Standard
31459
31460 \size footnotesize
31461 Installing and Configuring SDCC and Crimson Editor 
31462 \end_layout
31463
31464 \end_inset
31465 </cell>
31466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31467 \begin_inset Text
31468
31469 \begin_layout Standard
31470
31471 \size footnotesize
31472 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31473
31474 \end_inset
31475
31476
31477 \end_layout
31478
31479 \end_inset
31480 </cell>
31481 </row>
31482 <row topline="true" bottomline="true">
31483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31484 \begin_inset Text
31485
31486 \begin_layout Standard
31487
31488 \size footnotesize
31489 Texas Instruments
31490 \end_layout
31491
31492 \end_inset
31493 </cell>
31494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31495 \begin_inset Text
31496
31497 \begin_layout Standard
31498
31499 \size footnotesize
31500 MSC12xx Programming with SDCC
31501 \end_layout
31502
31503 \end_inset
31504 </cell>
31505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31506 \begin_inset Text
31507
31508 \begin_layout Standard
31509
31510 \size footnotesize
31511 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31512
31513 \end_inset
31514
31515
31516 \end_layout
31517
31518 \end_inset
31519 </cell>
31520 </row>
31521 </lyxtabular>
31522
31523 \end_inset
31524
31525
31526 \end_layout
31527
31528 \begin_layout Section
31529 Some Questions
31530 \end_layout
31531
31532 \begin_layout Standard
31533 Some questions answered, some pointers given - it might be time to in turn
31534  ask 
31535 \emph on
31536 you
31537 \emph default
31538  some questions: 
31539 \end_layout
31540
31541 \begin_layout Itemize
31542 can you solve your project with the selected microcontroller? Would you
31543  find out early or rather late that your target is too small/slow/whatever?
31544  Can you switch to a slightly better device if it doesn't fit?
31545 \end_layout
31546
31547 \begin_layout Itemize
31548 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31549  and/or another programming language be more adequate? Would an operating
31550  system on the target device help?
31551 \end_layout
31552
31553 \begin_layout Itemize
31554 if you solved the problem, will the marketing department be happy?
31555 \end_layout
31556
31557 \begin_layout Itemize
31558 if the marketing department is happy, will customers be happy?
31559 \end_layout
31560
31561 \begin_layout Itemize
31562 if you're the project manager, marketing department and maybe even the customer
31563  in one person, have you tried to see the project from the outside?
31564 \end_layout
31565
31566 \begin_layout Itemize
31567 is the project done if you think it is done? Or is just that other interface/pro
31568 tocol/feature/configuration/option missing? How about website, manual(s),
31569  internationali(z|s)ation, packaging, labels, 2nd source for components,
31570  electromagnetic compatability/interference, documentation for production,
31571  production test software, update mechanism, patent issues?
31572 \end_layout
31573
31574 \begin_layout Itemize
31575 is your project adequately positioned in that magic triangle: fame, fortune,
31576  fun?
31577 \end_layout
31578
31579 \begin_layout Standard
31580 Maybe not all answers to these questions are known and some answers may
31581  even be 
31582 \emph on
31583 no
31584 \emph default
31585 , nevertheless knowing these questions may help you to avoid burnout
31586 \begin_inset Foot
31587 status open
31588
31589 \begin_layout Standard
31590 burnout is bad for electronic devices, programmers and motorcycle tyres
31591 \end_layout
31592
31593 \end_inset
31594
31595 .
31596  Chances are you didn't want to hear some of them...
31597 \end_layout
31598
31599 \begin_layout Chapter
31600 Support
31601 \begin_inset LatexCommand \index{Support}
31602
31603 \end_inset
31604
31605
31606 \end_layout
31607
31608 \begin_layout Standard
31609 SDCC has grown to be a large project.
31610  The compiler alone (without the preprocessor, assembler and linker) is
31611  well over 150,000 lines of code (blank stripped).
31612  The open source nature of this project is a key to its continued growth
31613  and support.
31614  You gain the benefit and support of many active software developers and
31615  end users.
31616  Is SDCC perfect? No, that's why we need your help.
31617  The developers take pride in fixing reported bugs.
31618  You can help by reporting the bugs and helping other SDCC users.
31619  There are lots of ways to contribute, and we encourage you to take part
31620  in making SDCC a great software package.
31621  
31622 \end_layout
31623
31624 \begin_layout Standard
31625 The SDCC project is hosted on the SDCC sourceforge site at 
31626 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31627
31628 \end_inset
31629
31630 .
31631  You'll find the complete set of mailing lists
31632 \begin_inset LatexCommand \index{Mailing list(s)}
31633
31634 \end_inset
31635
31636 , forums, bug reporting system, patch submission
31637 \begin_inset LatexCommand \index{Patch submission}
31638
31639 \end_inset
31640
31641  system, download
31642 \begin_inset LatexCommand \index{download}
31643
31644 \end_inset
31645
31646  area and Subversion code repository
31647 \begin_inset LatexCommand \index{Subversion code repository}
31648
31649 \end_inset
31650
31651  there.
31652 \end_layout
31653
31654 \begin_layout Section
31655 Reporting Bugs
31656 \begin_inset LatexCommand \index{Bug reporting}
31657
31658 \end_inset
31659
31660
31661 \begin_inset LatexCommand \index{Reporting bugs}
31662
31663 \end_inset
31664
31665
31666 \end_layout
31667
31668 \begin_layout Standard
31669 The recommended way of reporting bugs is using the infrastructure of the
31670  sourceforge site.
31671  You can follow the status of bug reports there and have an overview about
31672  the known bugs.
31673 \end_layout
31674
31675 \begin_layout Standard
31676 Bug reports are automatically forwarded to the developer mailing list and
31677  will be fixed ASAP.
31678  When reporting a bug, it is very useful to include a small test program
31679  (the smaller the better) which reproduces the problem.
31680  If you can isolate the problem by looking at the generated assembly code,
31681  this can be very helpful.
31682  Compiling your program with the -
31683 \begin_inset ERT
31684 status collapsed
31685
31686 \begin_layout Standard
31687
31688
31689 \backslash
31690 /
31691 \end_layout
31692
31693 \end_inset
31694
31695 -dumpall
31696 \begin_inset LatexCommand \index{-\/-dumpall}
31697
31698 \end_inset
31699
31700  option can sometimes be useful in locating optimization problems.
31701  When reporting a bug please make sure you:
31702 \end_layout
31703
31704 \begin_layout Enumerate
31705 Attach the code you are compiling with SDCC.
31706  
31707 \end_layout
31708
31709 \begin_layout Enumerate
31710 Specify the exact command you use to run SDCC, or attach your Makefile.
31711  
31712 \end_layout
31713
31714 \begin_layout Enumerate
31715 Specify the SDCC version (type "
31716 \family sans
31717 \series bold
31718 sdcc -v
31719 \family default
31720 \series default
31721 "), your platform, and operating system.
31722  
31723 \end_layout
31724
31725 \begin_layout Enumerate
31726 Provide an exact copy of any error message or incorrect output.
31727  
31728 \end_layout
31729
31730 \begin_layout Enumerate
31731 Put something meaningful in the subject of your message.
31732 \end_layout
31733
31734 \begin_layout Standard
31735 Please attempt to include these 5 important parts, as applicable, in all
31736  requests for support or when reporting any problems or bugs with SDCC.
31737  Though this will make your message lengthy, it will greatly improve your
31738  chance that SDCC users and developers will be able to help you.
31739  Some SDCC developers are frustrated by bug reports without code provided
31740  that they can use to reproduce and ultimately fix the problem, so please
31741  be sure to provide sample code if you are reporting a bug! 
31742 \end_layout
31743
31744 \begin_layout Standard
31745 Please have a short check that you are using a recent version of SDCC and
31746  the bug is not yet known.
31747  This is the link for reporting bugs: 
31748 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31749
31750 \end_inset
31751
31752 .
31753  With SDCC on average having more than 200 downloads
31754 \begin_inset LatexCommand \index{download}
31755
31756 \end_inset
31757
31758  on sourceforge per day
31759 \begin_inset Foot
31760 status open
31761
31762 \begin_layout Standard
31763 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31764  between 2002 and 2005.
31765  This does not include other methods of distribution.
31766 \end_layout
31767
31768 \end_inset
31769
31770  there must be some users.
31771  So it's not exactly easy to find a new bug.
31772  If you find one we need it: 
31773 \emph on
31774 reporting bugs is good
31775 \emph default
31776 .
31777 \end_layout
31778
31779 \begin_layout Section
31780 Requesting Features
31781 \begin_inset LatexCommand \label{sub:Requesting-Features}
31782
31783 \end_inset
31784
31785
31786 \begin_inset LatexCommand \index{Feature request}
31787
31788 \end_inset
31789
31790
31791 \begin_inset LatexCommand \index{Requesting features}
31792
31793 \end_inset
31794
31795
31796 \end_layout
31797
31798 \begin_layout Standard
31799 Like bug reports feature requests are forwarded to the developer mailing
31800  list.
31801  This is the link for requesting features: 
31802 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31803
31804 \end_inset
31805
31806 .
31807 \end_layout
31808
31809 \begin_layout Section
31810 Submitting patches
31811 \end_layout
31812
31813 \begin_layout Standard
31814 Like bug reports contributed patches are forwarded to the developer mailing
31815  list.
31816  This is the link for submitting patches
31817 \begin_inset LatexCommand \index{Patch submission}
31818
31819 \end_inset
31820
31821
31822 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31823
31824 \end_inset
31825
31826 .
31827 \end_layout
31828
31829 \begin_layout Standard
31830 You need to specify some parameters to the 
31831 \family typewriter
31832 diff
31833 \family default
31834  command for the patches to be useful.
31835  If you modified more than one file a patch created f.e.
31836  with 
31837 \family sans
31838 \series bold
31839
31840 \begin_inset Quotes sld
31841 \end_inset
31842
31843 diff -Naur unmodified_directory modified_directory >my_changes.patch
31844 \begin_inset Quotes srd
31845 \end_inset
31846
31847
31848 \family default
31849 \series default
31850  will be fine, otherwise 
31851 \family sans
31852 \series bold
31853
31854 \begin_inset Quotes sld
31855 \end_inset
31856
31857 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31858 \begin_inset Quotes srd
31859 \end_inset
31860
31861
31862 \series default
31863  
31864 \family default
31865 will do.
31866 \end_layout
31867
31868 \begin_layout Section
31869 Getting Help
31870 \end_layout
31871
31872 \begin_layout Standard
31873 These links should take you directly to the 
31874 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31875
31876 \end_inset
31877
31878
31879 \begin_inset Foot
31880 status open
31881
31882 \begin_layout Standard
31883 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31884  automated messages (mid 2003)
31885 \end_layout
31886
31887 \end_inset
31888
31889  and the 
31890 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31891
31892 \end_inset
31893
31894 , lists
31895 \begin_inset LatexCommand \index{Mailing list(s)}
31896
31897 \end_inset
31898
31899  and forums are archived and searchable so if you are lucky someone already
31900  had a similar problem.
31901  While mails to the lists themselves are delivered promptly their web front
31902  end on sourceforge sometimes shows a severe time lag (up to several weeks),
31903  if you're seriously using SDCC please consider subscribing to the lists.
31904 \end_layout
31905
31906 \begin_layout Section
31907 ChangeLog
31908 \end_layout
31909
31910 \begin_layout Standard
31911 You can follow the status of the Subversion version
31912 \begin_inset LatexCommand \index{version}
31913
31914 \end_inset
31915
31916  of SDCC by watching the Changelog
31917 \begin_inset LatexCommand \index{Changelog}
31918
31919 \end_inset
31920
31921  in the Subversion repository
31922 \size footnotesize
31923  
31924 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31925
31926 \end_inset
31927
31928 .
31929 \end_layout
31930
31931 \begin_layout Section
31932 Subversion Source Code Repository
31933 \end_layout
31934
31935 \begin_layout Standard
31936 The output of 
31937 \family sans
31938 \series bold
31939 sdcc --version
31940 \family default
31941 \series default
31942  or the filenames of the snapshot versions of SDCC include date and its
31943  Subversion
31944 \begin_inset LatexCommand \index{Subversion code repository}
31945
31946 \end_inset
31947
31948  number.
31949  Subversion allows to download the source of recent or previous versions
31950  
31951 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31952
31953 \end_inset
31954
31955  (by number or by date).
31956  An on-line source code browser and detailled instructions are also available
31957  there.
31958  SDCC versions starting from 1999 up to now are available (currently the
31959  versions prior to the conversion from cvs
31960 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31961
31962 \end_inset
31963
31964  to Subversion (April 2006) are either by accessible by Subversion or by
31965  cvs).
31966 \end_layout
31967
31968 \begin_layout Section
31969 Release policy
31970 \begin_inset LatexCommand \index{Release policy}
31971
31972 \end_inset
31973
31974
31975 \end_layout
31976
31977 \begin_layout Standard
31978 Historically there often were long delays between official releases and
31979  the sourceforge download area tends to get not updated at all.
31980  Excuses in the past might have referred to problems with live range analysis,
31981  but as this was fixed a while ago, the current problem is that another
31982  excuse has to be found.
31983  Kidding aside, we have to get better there! On the other hand there are
31984  daily snapshots available at 
31985 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31986
31987 \end_inset
31988
31989 , and you can always build the very last version (hopefully with many bugs
31990  fixed, and features added) from the source code available at 
31991 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31992
31993 \end_inset
31994
31995 .
31996  A release wiki
31997 \begin_inset LatexCommand \index{wiki}
31998
31999 \end_inset
32000
32001
32002 \begin_inset LatexCommand \index{Release wiki}
32003
32004 \end_inset
32005
32006  at 
32007 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
32008
32009 \end_inset
32010
32011  also holds some information about past and future releases.
32012 \end_layout
32013
32014 \begin_layout Section
32015 Examples
32016 \begin_inset LatexCommand \index{Examples}
32017
32018 \end_inset
32019
32020
32021 \end_layout
32022
32023 \begin_layout Standard
32024 You'll find some small examples in the directory 
32025 \emph on
32026 sdcc/device/examples/.
32027  
32028 \emph default
32029 More examples and libraries are available at
32030 \emph on
32031  The SDCC Open Knowledge Resource 
32032 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32033
32034 \end_inset
32035
32036  
32037 \emph default
32038 web site or at 
32039 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32040
32041 \end_inset
32042
32043 .
32044 \end_layout
32045
32046 \begin_layout Standard
32047 \begin_inset Note Note
32048 status collapsed
32049
32050 \begin_layout Standard
32051 I did insert a reference to Paul's web site here although it seems rather
32052  dedicated to a specific 8032 board (I think it's okay because it f.e.
32053  shows LCD/Harddisc interface and has a free 8051 monitor.
32054  Independent 8032 board vendors face hard competition of heavily subsidized
32055  development boards anyway).
32056 \end_layout
32057
32058 \begin_layout Standard
32059 Maybe we should include some links to real world applications.
32060  Preferably pointer to pointers (one for each architecture) so this stays
32061  manageable here?
32062 \end_layout
32063
32064 \end_inset
32065
32066
32067 \end_layout
32068
32069 \begin_layout Section
32070 Quality control
32071 \begin_inset LatexCommand \label{sec:Quality-control}
32072
32073 \end_inset
32074
32075
32076 \begin_inset LatexCommand \index{Quality control}
32077
32078 \end_inset
32079
32080
32081 \end_layout
32082
32083 \begin_layout Standard
32084 The compiler is passed through snaphot build compile and build checks.
32085  The so called 
32086 \shape italic
32087 regression tests
32088 \shape default
32089
32090 \begin_inset LatexCommand \index{Regression test}
32091
32092 \end_inset
32093
32094  check that SDCC itself compiles flawlessly on several host platforms (i386,
32095  Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32096  the quality of the code generated by SDCC by running the code for several
32097  target platforms through simulators.
32098  The regression test suite comprises more than 100 files which expand to
32099  more than 500 test cases which include more than 4500 tests.
32100  The results of these tests are published daily on SDCC's snapshot page
32101  (click on the red or green symbols on the right side of 
32102 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32103
32104 \end_inset
32105
32106 ).
32107 \end_layout
32108
32109 \begin_layout Standard
32110 There is a separate document 
32111 \shape italic
32112 test_suite.pdf 
32113 \begin_inset LatexCommand \index{Test suite}
32114
32115 \end_inset
32116
32117
32118 \shape default
32119  
32120 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32121
32122 \end_inset
32123
32124  about the regression test suite.
32125 \end_layout
32126
32127 \begin_layout Standard
32128 You'll find the test code in the directory 
32129 \shape italic
32130 sdcc/support/regression
32131 \shape default
32132 .
32133  You can run these tests manually by running 
32134 \family sans
32135 make
32136 \family default
32137  in this directory (or f.e.
32138  
32139 \family sans
32140 \series bold
32141
32142 \begin_inset Quotes sld
32143 \end_inset
32144
32145 make test-mcs51
32146 \begin_inset Quotes srd
32147 \end_inset
32148
32149
32150 \family default
32151 \series default
32152  if you don't want to run the complete tests).
32153  The test code might also be interesting if you want to look for examples
32154 \begin_inset LatexCommand \index{Examples}
32155
32156 \end_inset
32157
32158  checking corner cases of SDCC or if you plan to submit patches
32159 \begin_inset LatexCommand \index{Patch submission}
32160
32161 \end_inset
32162
32163 .
32164 \end_layout
32165
32166 \begin_layout Standard
32167 The PIC14 port uses a different set of regression tests 
32168 \begin_inset LatexCommand \index{Regression test (PIC14)}
32169
32170 \end_inset
32171
32172 , you'll find them in the directory 
32173 \shape italic
32174 sdcc/src/regression
32175 \shape default
32176 .
32177 \end_layout
32178
32179 \begin_layout Section
32180 Use of SDCC in Education
32181 \end_layout
32182
32183 \begin_layout Standard
32184 In short: 
32185 \emph on
32186 highly
32187 \emph default
32188  encouraged
32189 \begin_inset Foot
32190 status open
32191
32192 \begin_layout Standard
32193 the phrase "use in education" might evoke the association "
32194 \emph on
32195 only
32196 \emph default
32197  fit for use in education".
32198  This connotation is not intended but nevertheless risked as the licensing
32199  of SDCC makes it difficult to offer educational discounts
32200 \end_layout
32201
32202 \end_inset
32203
32204 .
32205  If your rationales are to:
32206 \end_layout
32207
32208 \begin_layout Enumerate
32209 give students a chance to understand the 
32210 \emph on
32211 complete
32212 \emph default
32213  steps of code generation
32214 \end_layout
32215
32216 \begin_layout Enumerate
32217 have a curriculum that can be extended for years.
32218  Then you could use an fpga board as target and your curriculum will seamlessly
32219  extend from logic synthesis (
32220 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32221
32222 \end_inset
32223
32224
32225 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32226
32227 \end_inset
32228
32229 ), over assembly programming, to C to FPGA compilers (
32230 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32231
32232 \end_inset
32233
32234 ) and to C.
32235 \end_layout
32236
32237 \begin_layout Enumerate
32238 be able to insert excursions about skills like using a revision control
32239  system, submitting/applying patches, using a type-setting (as opposed to
32240  word-processing) engine LyX/LaTeX, using 
32241 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32242
32243 \end_inset
32244
32245 , following some 
32246 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32247
32248 \end_inset
32249
32250 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32251  Source Software, CPU simulation, compiler regression tests
32252 \begin_inset LatexCommand \index{Regression test}
32253
32254 \end_inset
32255
32256 .
32257  
32258 \newline
32259 And if there should be a shortage of ideas then you can always point students
32260  to the ever-growing feature request list 
32261 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32262
32263 \end_inset
32264
32265 .
32266 \end_layout
32267
32268 \begin_layout Enumerate
32269 not tie students to a specific host platform and instead allow them to use
32270  a host platform of 
32271 \emph on
32272 their
32273 \emph default
32274  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32275  and eventually 
32276 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32277
32278 \end_inset
32279
32280 )
32281 \end_layout
32282
32283 \begin_layout Enumerate
32284 not encourage students to use illegal copies of educational software
32285 \end_layout
32286
32287 \begin_layout Enumerate
32288 be immune to licensing/availability/price changes of the chosen tool chain
32289 \end_layout
32290
32291 \begin_layout Enumerate
32292 be able to change to a new target platform without having to adopt a new
32293  tool chain
32294 \end_layout
32295
32296 \begin_layout Enumerate
32297 have complete control over and insight into the tool chain
32298 \end_layout
32299
32300 \begin_layout Enumerate
32301 make your students aware about the pros and cons of open source software
32302  development
32303 \end_layout
32304
32305 \begin_layout Enumerate
32306 give back to the public as you are probably at least partially publically
32307  funded
32308 \end_layout
32309
32310 \begin_layout Enumerate
32311 give students a chance to publically prove their skills and to possibly
32312  see a world wide impact
32313 \end_layout
32314
32315 \begin_layout Standard
32316 then SDCC is probably among the first choices.
32317  Well, probably SDCC might be the only choice.
32318 \newpage
32319
32320 \end_layout
32321
32322 \begin_layout Chapter
32323 SDCC Technical Data
32324 \end_layout
32325
32326 \begin_layout Section
32327 Optimizations
32328 \begin_inset LatexCommand \index{Optimizations}
32329
32330 \end_inset
32331
32332
32333 \end_layout
32334
32335 \begin_layout Standard
32336 SDCC performs a host of standard optimizations in addition to some MCU specific
32337  optimizations.
32338  
32339 \end_layout
32340
32341 \begin_layout Subsection
32342 Sub-expression Elimination
32343 \begin_inset LatexCommand \index{Subexpression elimination}
32344
32345 \end_inset
32346
32347
32348 \end_layout
32349
32350 \begin_layout Standard
32351 The compiler does local and 
32352 \emph on
32353 g
32354 \emph default
32355 lobal 
32356 \emph on
32357 c
32358 \emph default
32359 ommon 
32360 \emph on
32361 s
32362 \emph default
32363 ubexpression 
32364 \emph on
32365 e
32366 \emph default
32367 limination, e.g.: 
32368 \end_layout
32369
32370 \begin_layout Verse
32371
32372 \family typewriter
32373 i = x + y + 1; 
32374 \newline
32375 j = x + y;
32376 \end_layout
32377
32378 \begin_layout Standard
32379 will be translated to
32380 \end_layout
32381
32382 \begin_layout Verse
32383
32384 \family typewriter
32385 iTemp = x + y; 
32386 \newline
32387 i = iTemp + 1; 
32388 \newline
32389 j = iTemp;
32390 \end_layout
32391
32392 \begin_layout Standard
32393 Some subexpressions are not as obvious as the above example, e.g.:
32394 \end_layout
32395
32396 \begin_layout Verse
32397
32398 \family typewriter
32399 a->b[i].c = 10; 
32400 \newline
32401 a->b[i].d = 11;
32402 \end_layout
32403
32404 \begin_layout Standard
32405 In this case the address arithmetic a->b[i] will be computed only once;
32406  the equivalent code in C would be.
32407 \end_layout
32408
32409 \begin_layout Verse
32410
32411 \family typewriter
32412 iTemp = a->b[i]; 
32413 \newline
32414 iTemp.c = 10; 
32415 \newline
32416 iTemp.d = 11;
32417 \end_layout
32418
32419 \begin_layout Standard
32420 The compiler will try to keep these temporary variables in registers.
32421 \end_layout
32422
32423 \begin_layout Subsection
32424 Dead-Code Elimination
32425 \begin_inset LatexCommand \index{Dead-code elimination}
32426
32427 \end_inset
32428
32429
32430 \end_layout
32431
32432 \begin_layout Verse
32433
32434 \family typewriter
32435 int global;
32436 \newline
32437
32438 \newline
32439 void f () { 
32440 \newline
32441 \InsetSpace ~
32442 \InsetSpace ~
32443 int i; 
32444 \newline
32445 \InsetSpace ~
32446 \InsetSpace ~
32447 i = 1; \InsetSpace ~
32448 \InsetSpace ~
32449 \InsetSpace ~
32450 \InsetSpace ~
32451 \InsetSpace ~
32452 /* dead store */ 
32453 \newline
32454 \InsetSpace ~
32455 \InsetSpace ~
32456 global = 1;\InsetSpace ~
32457 /* dead
32458  store */ 
32459 \newline
32460 \InsetSpace ~
32461 \InsetSpace ~
32462 global = 2; 
32463 \newline
32464 \InsetSpace ~
32465 \InsetSpace ~
32466 return; 
32467 \newline
32468 \InsetSpace ~
32469 \InsetSpace ~
32470 global = 3;\InsetSpace ~
32471 /* unreachable */ 
32472 \newline
32473 }
32474 \end_layout
32475
32476 \begin_layout Standard
32477 will be changed to
32478 \end_layout
32479
32480 \begin_layout Verse
32481
32482 \family typewriter
32483 int global;
32484 \newline
32485
32486 \newline
32487 void f () {
32488 \newline
32489 \InsetSpace ~
32490 \InsetSpace ~
32491 global = 2; 
32492 \newline
32493 }
32494 \end_layout
32495
32496 \begin_layout Subsection
32497 Copy-Propagation
32498 \begin_inset LatexCommand \index{Copy propagation}
32499
32500 \end_inset
32501
32502
32503 \end_layout
32504
32505 \begin_layout Verse
32506
32507 \family typewriter
32508 int f() { 
32509 \newline
32510 \InsetSpace ~
32511 \InsetSpace ~
32512 int i, j; 
32513 \newline
32514 \InsetSpace ~
32515 \InsetSpace ~
32516 i = 10; 
32517 \newline
32518 \InsetSpace ~
32519 \InsetSpace ~
32520 j = i; 
32521 \newline
32522 \InsetSpace ~
32523 \InsetSpace ~
32524 return j; 
32525 \newline
32526 }
32527 \end_layout
32528
32529 \begin_layout Standard
32530 will be changed to 
32531 \end_layout
32532
32533 \begin_layout Verse
32534
32535 \family typewriter
32536 int f() { 
32537 \newline
32538 \InsetSpace ~
32539 \InsetSpace ~
32540 int i, j; 
32541 \newline
32542 \InsetSpace ~
32543 \InsetSpace ~
32544 i = 10; 
32545 \newline
32546 \InsetSpace ~
32547 \InsetSpace ~
32548 j = 10; 
32549 \newline
32550 \InsetSpace ~
32551 \InsetSpace ~
32552 return 10; 
32553 \newline
32554 }
32555 \end_layout
32556
32557 \begin_layout Standard
32558 Note: the dead stores created by this copy propagation will be eliminated
32559  by dead-code elimination.
32560 \end_layout
32561
32562 \begin_layout Subsection
32563 Loop Optimizations
32564 \begin_inset LatexCommand \index{Loop optimization}
32565
32566 \end_inset
32567
32568
32569 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32570
32571 \end_inset
32572
32573
32574 \end_layout
32575
32576 \begin_layout Standard
32577 Two types of loop optimizations are done by SDCC 
32578 \emph on
32579 loop invariant
32580 \emph default
32581  lifting and
32582 \emph on
32583  strength reduction
32584 \emph default
32585  of loop induction variables.
32586  In addition to the strength reduction the optimizer marks the induction
32587  variables and the register allocator tries to keep the induction variables
32588  in registers for the duration of the loop.
32589  Because of this preference of the register allocator
32590 \begin_inset LatexCommand \index{Register allocation}
32591
32592 \end_inset
32593
32594 , loop induction optimization causes an increase in register pressure, which
32595  may cause unwanted spilling of other temporary variables into the stack
32596 \begin_inset LatexCommand \index{stack}
32597
32598 \end_inset
32599
32600  / data space.
32601  The compiler will generate a warning message when it is forced to allocate
32602  extra space either on the stack or data space.
32603  If this extra space allocation is undesirable then induction optimization
32604  can be eliminated either for the entire source file (with -
32605 \begin_inset ERT
32606 status collapsed
32607
32608 \begin_layout Standard
32609
32610
32611 \backslash
32612 /
32613 \end_layout
32614
32615 \end_inset
32616
32617 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32618 noinduction
32619 \begin_inset LatexCommand \index{\#pragma noinduction}
32620
32621 \end_inset
32622
32623 .
32624 \newline
32625
32626 \newline
32627 Loop Invariant:
32628 \end_layout
32629
32630 \begin_layout Verse
32631
32632 \family typewriter
32633 for (i = 0 ; i < 100 ; i ++) 
32634 \newline
32635 \InsetSpace ~
32636 \InsetSpace ~
32637 \InsetSpace ~
32638 \InsetSpace ~
32639 f += k + l;
32640 \end_layout
32641
32642 \begin_layout Standard
32643 changed to
32644 \end_layout
32645
32646 \begin_layout Verse
32647
32648 \family typewriter
32649 itemp = k + l; 
32650 \newline
32651 for (i = 0; i < 100; i++) 
32652 \newline
32653 \InsetSpace ~
32654 \InsetSpace ~
32655 \InsetSpace ~
32656 \InsetSpace ~
32657 f += itemp;
32658 \end_layout
32659
32660 \begin_layout Standard
32661 As mentioned previously some loop invariants are not as apparent, all static
32662  address computations are also moved out of the loop.
32663 \newline
32664
32665 \newline
32666 Strength Reduction
32667 \begin_inset LatexCommand \index{Strength reduction}
32668
32669 \end_inset
32670
32671 , this optimization substitutes an expression by a cheaper expression:
32672 \end_layout
32673
32674 \begin_layout Verse
32675
32676 \family typewriter
32677 for (i=0;i < 100; i++)
32678 \newline
32679 \InsetSpace ~
32680 \InsetSpace ~
32681 \InsetSpace ~
32682 \InsetSpace ~
32683 ar[i*5] = i*3;
32684 \end_layout
32685
32686 \begin_layout Standard
32687 changed to
32688 \end_layout
32689
32690 \begin_layout Verse
32691
32692 \family typewriter
32693 itemp1 = 0; 
32694 \newline
32695 itemp2 = 0; 
32696 \newline
32697 for (i=0;i< 100;i++) { 
32698 \newline
32699 \InsetSpace ~
32700 \InsetSpace ~
32701 \InsetSpace ~
32702 \InsetSpace ~
32703 ar[itemp1] = itemp2; 
32704 \newline
32705 \InsetSpace ~
32706 \InsetSpace ~
32707 \InsetSpace ~
32708 \InsetSpace ~
32709 itemp1
32710  += 5; 
32711 \newline
32712 \InsetSpace ~
32713 \InsetSpace ~
32714 \InsetSpace ~
32715 \InsetSpace ~
32716 itemp2 += 3; 
32717 \newline
32718 }
32719 \end_layout
32720
32721 \begin_layout Standard
32722 The more expensive multiplication
32723 \begin_inset LatexCommand \index{Multiplication}
32724
32725 \end_inset
32726
32727  is changed to a less expensive addition.
32728 \end_layout
32729
32730 \begin_layout Subsection
32731 Loop Reversing
32732 \begin_inset LatexCommand \index{Loop reversing}
32733
32734 \end_inset
32735
32736
32737 \end_layout
32738
32739 \begin_layout Standard
32740 This optimization is done to reduce the overhead of checking loop boundaries
32741  for every iteration.
32742  Some simple loops can be reversed and implemented using a 
32743 \begin_inset Quotes eld
32744 \end_inset
32745
32746 decrement and jump if not zero
32747 \begin_inset Quotes erd
32748 \end_inset
32749
32750  instruction.
32751  SDCC checks for the following criterion to determine if a loop is reversible
32752  (note: more sophisticated compilers use data-dependency analysis to make
32753  this determination, SDCC uses a more simple minded analysis).
32754 \end_layout
32755
32756 \begin_layout Itemize
32757 The 'for' loop is of the form 
32758 \newline
32759
32760 \newline
32761
32762 \family typewriter
32763 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32764  += 1])
32765 \newline
32766 \InsetSpace ~
32767 \InsetSpace ~
32768 \InsetSpace ~
32769 \InsetSpace ~
32770 <for body>
32771 \end_layout
32772
32773 \begin_layout Itemize
32774 The <for body> does not contain 
32775 \begin_inset Quotes eld
32776 \end_inset
32777
32778 continue
32779 \begin_inset Quotes erd
32780 \end_inset
32781
32782  or 'break
32783 \begin_inset Quotes erd
32784 \end_inset
32785
32786 .
32787 \end_layout
32788
32789 \begin_layout Itemize
32790 All goto's are contained within the loop.
32791 \end_layout
32792
32793 \begin_layout Itemize
32794 No function calls within the loop.
32795 \end_layout
32796
32797 \begin_layout Itemize
32798 The loop control variable <sym> is not assigned any value within the loop
32799 \end_layout
32800
32801 \begin_layout Itemize
32802 The loop control variable does NOT participate in any arithmetic operation
32803  within the loop.
32804 \end_layout
32805
32806 \begin_layout Itemize
32807 There are NO switch statements in the loop.
32808 \end_layout
32809
32810 \begin_layout Subsection
32811 Algebraic Simplifications
32812 \end_layout
32813
32814 \begin_layout Standard
32815 SDCC does numerous algebraic simplifications, the following is a small sub-set
32816  of these optimizations.
32817 \end_layout
32818
32819 \begin_layout Verse
32820
32821 \family typewriter
32822 i = j + 0;\InsetSpace ~
32823 \InsetSpace ~
32824 \InsetSpace ~
32825 \InsetSpace ~
32826  /* changed to: */\InsetSpace ~
32827 \InsetSpace ~
32828 \InsetSpace ~
32829 \InsetSpace ~
32830  i = j; 
32831 \newline
32832 i /= 2;\InsetSpace ~
32833 \InsetSpace ~
32834 \InsetSpace ~
32835 \InsetSpace ~
32836 \InsetSpace ~
32837 \InsetSpace ~
32838 \InsetSpace ~
32839  /* changed to: */\InsetSpace ~
32840 \InsetSpace ~
32841 \InsetSpace ~
32842 \InsetSpace ~
32843  i >>= 1; 
32844 \newline
32845 i
32846  = j - j;\InsetSpace ~
32847 \InsetSpace ~
32848 \InsetSpace ~
32849 \InsetSpace ~
32850  /* changed to: */\InsetSpace ~
32851 \InsetSpace ~
32852 \InsetSpace ~
32853 \InsetSpace ~
32854  i = 0; 
32855 \newline
32856 i = j / 1;\InsetSpace ~
32857 \InsetSpace ~
32858 \InsetSpace ~
32859 \InsetSpace ~
32860  /* changed to: */\InsetSpace ~
32861 \InsetSpace ~
32862 \InsetSpace ~
32863 \InsetSpace ~
32864  i = j;
32865 \end_layout
32866
32867 \begin_layout Standard
32868 Note the subexpressions
32869 \begin_inset LatexCommand \index{Subexpression}
32870
32871 \end_inset
32872
32873  given above are generally introduced by macro expansions or as a result
32874  of copy/constant propagation.
32875 \end_layout
32876
32877 \begin_layout Subsection
32878 'switch' Statements
32879 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32880
32881 \end_inset
32882
32883
32884 \begin_inset LatexCommand \index{switch statement}
32885
32886 \end_inset
32887
32888
32889 \end_layout
32890
32891 \begin_layout Standard
32892 SDCC can optimize switch statements to jump tables
32893 \begin_inset LatexCommand \index{jump tables}
32894
32895 \end_inset
32896
32897 .
32898  It makes the decision based on an estimate of the generated code size.
32899  SDCC is quite liberal in the requirements for jump table generation: 
32900 \end_layout
32901
32902 \begin_layout Itemize
32903 The labels need not be in order, and the starting number need not be one
32904  or zero, the case labels are in numerical sequence or not too many case
32905  labels are missing.
32906 \end_layout
32907
32908 \begin_deeper
32909 \begin_layout Verse
32910
32911 \family typewriter
32912 switch(i) {\InsetSpace ~
32913 \InsetSpace ~
32914 \InsetSpace ~
32915 \InsetSpace ~
32916 \InsetSpace ~
32917 \InsetSpace ~
32918 \InsetSpace ~
32919 \InsetSpace ~
32920 \InsetSpace ~
32921 \InsetSpace ~
32922 \InsetSpace ~
32923 \InsetSpace ~
32924 \InsetSpace ~
32925 \InsetSpace ~
32926 \InsetSpace ~
32927 \InsetSpace ~
32928 \InsetSpace ~
32929 \InsetSpace ~
32930 \InsetSpace ~
32931 \InsetSpace ~
32932 \InsetSpace ~
32933 \InsetSpace ~
32934 \InsetSpace ~
32935 \InsetSpace ~
32936 \InsetSpace ~
32937 \InsetSpace ~
32938 switch (i) { 
32939 \newline
32940 \InsetSpace ~
32941 \InsetSpace ~
32942 \InsetSpace ~
32943 case 4: ...\InsetSpace ~
32944 \InsetSpace ~
32945 \InsetSpace ~
32946 \InsetSpace ~
32947 \InsetSpace ~
32948 \InsetSpace ~
32949 \InsetSpace ~
32950 \InsetSpace ~
32951 \InsetSpace ~
32952 \InsetSpace ~
32953 \InsetSpace ~
32954 \InsetSpace ~
32955 \InsetSpace ~
32956 \InsetSpace ~
32957 \InsetSpace ~
32958 \InsetSpace ~
32959 \InsetSpace ~
32960 \InsetSpace ~
32961 \InsetSpace ~
32962 \InsetSpace ~
32963 \InsetSpace ~
32964 \InsetSpace ~
32965 \InsetSpace ~
32966 \InsetSpace ~
32967 \InsetSpace ~
32968 \InsetSpace ~
32969 case 0: ...
32970  
32971 \newline
32972 \InsetSpace ~
32973 \InsetSpace ~
32974 \InsetSpace ~
32975 case 5: ...\InsetSpace ~
32976 \InsetSpace ~
32977 \InsetSpace ~
32978 \InsetSpace ~
32979 \InsetSpace ~
32980 \InsetSpace ~
32981 \InsetSpace ~
32982 \InsetSpace ~
32983 \InsetSpace ~
32984 \InsetSpace ~
32985 \InsetSpace ~
32986 \InsetSpace ~
32987 \InsetSpace ~
32988 \InsetSpace ~
32989 \InsetSpace ~
32990 \InsetSpace ~
32991 \InsetSpace ~
32992 \InsetSpace ~
32993 \InsetSpace ~
32994 \InsetSpace ~
32995 \InsetSpace ~
32996 \InsetSpace ~
32997 \InsetSpace ~
32998 \InsetSpace ~
32999 \InsetSpace ~
33000 \InsetSpace ~
33001 case 1: ...
33002  
33003 \newline
33004 \InsetSpace ~
33005 \InsetSpace ~
33006 \InsetSpace ~
33007 case 3: ...\InsetSpace ~
33008 \InsetSpace ~
33009 \InsetSpace ~
33010 \InsetSpace ~
33011 \InsetSpace ~
33012 \InsetSpace ~
33013 \InsetSpace ~
33014 \InsetSpace ~
33015 \InsetSpace ~
33016 \InsetSpace ~
33017 \InsetSpace ~
33018 \InsetSpace ~
33019 \InsetSpace ~
33020 \InsetSpace ~
33021 \InsetSpace ~
33022 \InsetSpace ~
33023 \InsetSpace ~
33024 \InsetSpace ~
33025 \InsetSpace ~
33026 \InsetSpace ~
33027 \InsetSpace ~
33028 \InsetSpace ~
33029 \InsetSpace ~
33030 \InsetSpace ~
33031 \InsetSpace ~
33032 \InsetSpace ~
33033
33034 \newline
33035 \InsetSpace ~
33036 \InsetSpace ~
33037 \InsetSpace ~
33038 case 6: ...\InsetSpace ~
33039 \InsetSpace ~
33040 \InsetSpace ~
33041 \InsetSpace ~
33042 \InsetSpace ~
33043 \InsetSpace ~
33044 \InsetSpace ~
33045 \InsetSpace ~
33046 \InsetSpace ~
33047 \InsetSpace ~
33048 \InsetSpace ~
33049 \InsetSpace ~
33050 \InsetSpace ~
33051 \InsetSpace ~
33052 \InsetSpace ~
33053 \InsetSpace ~
33054 \InsetSpace ~
33055 \InsetSpace ~
33056 \InsetSpace ~
33057 \InsetSpace ~
33058 \InsetSpace ~
33059 \InsetSpace ~
33060 \InsetSpace ~
33061 \InsetSpace ~
33062 \InsetSpace ~
33063 \InsetSpace ~
33064 case 3: ...
33065  
33066 \newline
33067 \InsetSpace ~
33068 \InsetSpace ~
33069 \InsetSpace ~
33070 case 7: ...\InsetSpace ~
33071 \InsetSpace ~
33072 \InsetSpace ~
33073 \InsetSpace ~
33074 \InsetSpace ~
33075 \InsetSpace ~
33076 \InsetSpace ~
33077 \InsetSpace ~
33078 \InsetSpace ~
33079 \InsetSpace ~
33080 \InsetSpace ~
33081 \InsetSpace ~
33082 \InsetSpace ~
33083 \InsetSpace ~
33084 \InsetSpace ~
33085 \InsetSpace ~
33086 \InsetSpace ~
33087 \InsetSpace ~
33088 \InsetSpace ~
33089 \InsetSpace ~
33090 \InsetSpace ~
33091 \InsetSpace ~
33092 \InsetSpace ~
33093 \InsetSpace ~
33094 \InsetSpace ~
33095 \InsetSpace ~
33096 case 4: ...
33097  
33098 \newline
33099 \InsetSpace ~
33100 \InsetSpace ~
33101 \InsetSpace ~
33102 case 8: ...\InsetSpace ~
33103 \InsetSpace ~
33104 \InsetSpace ~
33105 \InsetSpace ~
33106 \InsetSpace ~
33107 \InsetSpace ~
33108 \InsetSpace ~
33109 \InsetSpace ~
33110 \InsetSpace ~
33111 \InsetSpace ~
33112 \InsetSpace ~
33113 \InsetSpace ~
33114 \InsetSpace ~
33115 \InsetSpace ~
33116 \InsetSpace ~
33117 \InsetSpace ~
33118 \InsetSpace ~
33119 \InsetSpace ~
33120 \InsetSpace ~
33121 \InsetSpace ~
33122 \InsetSpace ~
33123 \InsetSpace ~
33124 \InsetSpace ~
33125 \InsetSpace ~
33126 \InsetSpace ~
33127 \InsetSpace ~
33128 case 5: ...
33129  
33130 \newline
33131 \InsetSpace ~
33132 \InsetSpace ~
33133 \InsetSpace ~
33134 case 9: ...\InsetSpace ~
33135 \InsetSpace ~
33136 \InsetSpace ~
33137 \InsetSpace ~
33138 \InsetSpace ~
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 \InsetSpace ~
33142 \InsetSpace ~
33143 \InsetSpace ~
33144 \InsetSpace ~
33145 \InsetSpace ~
33146 \InsetSpace ~
33147 \InsetSpace ~
33148 \InsetSpace ~
33149 \InsetSpace ~
33150 \InsetSpace ~
33151 \InsetSpace ~
33152 \InsetSpace ~
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 \InsetSpace ~
33156 \InsetSpace ~
33157 \InsetSpace ~
33158 \InsetSpace ~
33159 \InsetSpace ~
33160 case 6: ...
33161  
33162 \newline
33163 \InsetSpace ~
33164 \InsetSpace ~
33165 \InsetSpace ~
33166 case 10: ...\InsetSpace ~
33167 \InsetSpace ~
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 case 7: ...
33192  
33193 \newline
33194 \InsetSpace ~
33195 \InsetSpace ~
33196 \InsetSpace ~
33197 case 11: ...\InsetSpace ~
33198 \InsetSpace ~
33199 \InsetSpace ~
33200 \InsetSpace ~
33201 \InsetSpace ~
33202 \InsetSpace ~
33203 \InsetSpace ~
33204 \InsetSpace ~
33205 \InsetSpace ~
33206 \InsetSpace ~
33207 \InsetSpace ~
33208 \InsetSpace ~
33209 \InsetSpace ~
33210 \InsetSpace ~
33211 \InsetSpace ~
33212 \InsetSpace ~
33213 \InsetSpace ~
33214 \InsetSpace ~
33215 \InsetSpace ~
33216 \InsetSpace ~
33217 \InsetSpace ~
33218 \InsetSpace ~
33219 \InsetSpace ~
33220 \InsetSpace ~
33221 \InsetSpace ~
33222 case 8: ...
33223  
33224 \newline
33225 }\InsetSpace ~
33226 \InsetSpace ~
33227 \InsetSpace ~
33228 \InsetSpace ~
33229 \InsetSpace ~
33230 \InsetSpace ~
33231 \InsetSpace ~
33232 \InsetSpace ~
33233 \InsetSpace ~
33234 \InsetSpace ~
33235 \InsetSpace ~
33236 \InsetSpace ~
33237 \InsetSpace ~
33238 \InsetSpace ~
33239 \InsetSpace ~
33240 \InsetSpace ~
33241 \InsetSpace ~
33242 \InsetSpace ~
33243 \InsetSpace ~
33244 \InsetSpace ~
33245 \InsetSpace ~
33246 \InsetSpace ~
33247 \InsetSpace ~
33248 \InsetSpace ~
33249 \InsetSpace ~
33250 \InsetSpace ~
33251 \InsetSpace ~
33252 \InsetSpace ~
33253 \InsetSpace ~
33254 \InsetSpace ~
33255 \InsetSpace ~
33256 \InsetSpace ~
33257 \InsetSpace ~
33258 \InsetSpace ~
33259 \InsetSpace ~
33260 \InsetSpace ~
33261 }
33262 \end_layout
33263
33264 \begin_layout Standard
33265 Both the above switch statements will be implemented using a jump-table.
33266  The example to the right side is slightly more efficient as the check for
33267  the lower boundary of the jump-table is not needed.
33268 \end_layout
33269
33270 \end_deeper
33271 \begin_layout Itemize
33272 The number of case labels is not larger than supported by the target architectur
33273 e.
33274 \end_layout
33275
33276 \begin_layout Itemize
33277 If the case labels are not in numerical sequence ('gaps' between cases)
33278  SDCC checks whether a jump table with additionally inserted dummy cases
33279  is still attractive.
33280  
33281 \end_layout
33282
33283 \begin_layout Itemize
33284 If the starting number is not zero and a check for the lower boundary of
33285  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33286  ...
33287  .
33288 \end_layout
33289
33290 \begin_layout Standard
33291 Switch statements which have large gaps in the numeric sequence or those
33292  that have too many case labels can be split into more than one switch statement
33293  for efficient code generation, e.g.:
33294 \end_layout
33295
33296 \begin_layout Verse
33297
33298 \family typewriter
33299 switch (i) { 
33300 \newline
33301 \InsetSpace ~
33302 \InsetSpace ~
33303 case 1: ...
33304  
33305 \newline
33306 \InsetSpace ~
33307 \InsetSpace ~
33308 case 2: ...
33309  
33310 \newline
33311 \InsetSpace ~
33312 \InsetSpace ~
33313 case 3: ...
33314  
33315 \newline
33316 \InsetSpace ~
33317 \InsetSpace ~
33318 case 4: ...
33319  
33320 \newline
33321 \InsetSpace ~
33322 \InsetSpace ~
33323 case 5: ...
33324  
33325 \newline
33326 \InsetSpace ~
33327 \InsetSpace ~
33328 case 6: ...
33329  
33330 \newline
33331 \InsetSpace ~
33332 \InsetSpace ~
33333 case 7: ...
33334  
33335 \newline
33336 \InsetSpace ~
33337 \InsetSpace ~
33338 case 101: ...
33339  
33340 \newline
33341 \InsetSpace ~
33342 \InsetSpace ~
33343 case 102: ...
33344  
33345 \newline
33346 \InsetSpace ~
33347 \InsetSpace ~
33348 case 103: ...
33349  
33350 \newline
33351 \InsetSpace ~
33352 \InsetSpace ~
33353 case 104: ...
33354  
33355 \newline
33356 \InsetSpace ~
33357 \InsetSpace ~
33358 case 105: ...
33359  
33360 \newline
33361 \InsetSpace ~
33362 \InsetSpace ~
33363 case 106: ...
33364  
33365 \newline
33366 \InsetSpace ~
33367 \InsetSpace ~
33368 case 107: ...
33369  
33370 \newline
33371 }
33372 \end_layout
33373
33374 \begin_layout Standard
33375 If the above switch statement is broken down into two switch statements
33376 \end_layout
33377
33378 \begin_layout Verse
33379
33380 \family typewriter
33381 switch (i) { 
33382 \newline
33383 \InsetSpace ~
33384 \InsetSpace ~
33385 case 1: ...
33386  
33387 \newline
33388 \InsetSpace ~
33389 \InsetSpace ~
33390 case 2: ...
33391  
33392 \newline
33393 \InsetSpace ~
33394 \InsetSpace ~
33395 case 3: ...
33396  
33397 \newline
33398 \InsetSpace ~
33399 \InsetSpace ~
33400 case 4: ...
33401  
33402 \newline
33403 \InsetSpace ~
33404 \InsetSpace ~
33405 case 5: ...
33406  
33407 \newline
33408 \InsetSpace ~
33409 \InsetSpace ~
33410 case 6: ...
33411  
33412 \newline
33413 \InsetSpace ~
33414 \InsetSpace ~
33415 case 7: ...
33416  
33417 \newline
33418 }
33419 \end_layout
33420
33421 \begin_layout Standard
33422 and
33423 \end_layout
33424
33425 \begin_layout Verse
33426
33427 \family typewriter
33428 switch (i) { 
33429 \newline
33430 \InsetSpace ~
33431 \InsetSpace ~
33432 case 101: ...
33433  
33434 \newline
33435 \InsetSpace ~
33436 \InsetSpace ~
33437 case 102: ...
33438  
33439 \newline
33440 \InsetSpace ~
33441 \InsetSpace ~
33442 case 103: ...
33443  
33444 \newline
33445 \InsetSpace ~
33446 \InsetSpace ~
33447 case 104: ...
33448  
33449 \newline
33450 \InsetSpace ~
33451 \InsetSpace ~
33452 case 105: ...
33453  
33454 \newline
33455 \InsetSpace ~
33456 \InsetSpace ~
33457 case 106: ...
33458  
33459 \newline
33460 \InsetSpace ~
33461 \InsetSpace ~
33462 case 107: ...
33463  
33464 \newline
33465 }
33466 \end_layout
33467
33468 \begin_layout Standard
33469 then both the switch statements will be implemented using jump-tables whereas
33470  the unmodified switch statement will not be.
33471 \end_layout
33472
33473 \begin_layout Standard
33474 \begin_inset Note Note
33475 status collapsed
33476
33477 \begin_layout Standard
33478 There might be reasons which SDCC cannot know about to either favour or
33479  not favour jump tables.
33480  If the target system has to be as quick for the last switch case as for
33481  the first (pro jump table), or if the switch argument is known to be zero
33482  in the majority of the cases (contra jump table).
33483 \end_layout
33484
33485 \end_inset
33486
33487
33488 \end_layout
33489
33490 \begin_layout Standard
33491 The pragma nojtbound
33492 \begin_inset LatexCommand \index{\#pragma nojtbound}
33493
33494 \end_inset
33495
33496  can be used to turn off checking the 
33497 \emph on
33498 j
33499 \emph default
33500 ump 
33501 \emph on
33502 t
33503 \emph default
33504 able 
33505 \emph on
33506 bound
33507 \emph default
33508 aries.
33509  It has no effect if a default label is supplied.
33510  Use of this pragma is dangerous: if the switch
33511 \begin_inset LatexCommand \index{switch statement}
33512
33513 \end_inset
33514
33515  argument is not matched by a case statement the processor will happily
33516  jump into Nirvana.
33517 \end_layout
33518
33519 \begin_layout Subsection
33520 Bit-shifting Operations
33521 \begin_inset LatexCommand \index{Bit shifting}
33522
33523 \end_inset
33524
33525 .
33526 \end_layout
33527
33528 \begin_layout Standard
33529 Bit shifting is one of the most frequently used operation in embedded programmin
33530 g.
33531  SDCC tries to implement bit-shift operations in the most efficient way
33532  possible, e.g.:
33533 \end_layout
33534
33535 \begin_layout Verse
33536
33537 \family typewriter
33538 unsigned char i;
33539 \newline
33540 ...
33541  
33542 \newline
33543 i >>= 4; 
33544 \newline
33545 ...
33546 \end_layout
33547
33548 \begin_layout Standard
33549 generates the following code:
33550 \end_layout
33551
33552 \begin_layout Verse
33553
33554 \family typewriter
33555 mov\InsetSpace ~
33556  a,_i 
33557 \newline
33558 swap a 
33559 \newline
33560 anl\InsetSpace ~
33561  a,#0x0f 
33562 \newline
33563 mov\InsetSpace ~
33564  _i,a
33565 \end_layout
33566
33567 \begin_layout Standard
33568 In general SDCC will never setup a loop if the shift count is known.
33569  Another example:
33570 \end_layout
33571
33572 \begin_layout Verse
33573
33574 \family typewriter
33575 unsigned int i; 
33576 \newline
33577 ...
33578  
33579 \newline
33580 i >>= 9; 
33581 \newline
33582 ...
33583 \end_layout
33584
33585 \begin_layout Standard
33586 will generate:
33587 \end_layout
33588
33589 \begin_layout Verse
33590
33591 \family typewriter
33592 mov\InsetSpace ~
33593 \InsetSpace ~
33594 a,(_i + 1) 
33595 \newline
33596 mov\InsetSpace ~
33597 \InsetSpace ~
33598 (_i + 1),#0x00 
33599 \newline
33600 clr\InsetSpace ~
33601 \InsetSpace ~
33602
33603 \newline
33604 rrc\InsetSpace ~
33605 \InsetSpace ~
33606
33607 \newline
33608 mov\InsetSpace ~
33609 \InsetSpace ~
33610 _i,a
33611 \end_layout
33612
33613 \begin_layout Subsection
33614 Bit-rotation
33615 \begin_inset LatexCommand \index{Bit rotation}
33616
33617 \end_inset
33618
33619
33620 \end_layout
33621
33622 \begin_layout Standard
33623 A special case of the bit-shift operation is bit rotation
33624 \begin_inset LatexCommand \index{rotating bits}
33625
33626 \end_inset
33627
33628 , SDCC recognizes the following expression to be a left bit-rotation:
33629 \end_layout
33630
33631 \begin_layout Verse
33632
33633 \family typewriter
33634 \series bold
33635 unsigned
33636 \series default
33637 \InsetSpace ~
33638 \InsetSpace ~
33639 char i;\InsetSpace ~
33640 \InsetSpace ~
33641 \InsetSpace ~
33642 \InsetSpace ~
33643 \InsetSpace ~
33644 \InsetSpace ~
33645 \InsetSpace ~
33646 \InsetSpace ~
33647 \InsetSpace ~
33648 \InsetSpace ~
33649 \InsetSpace ~
33650 /* unsigned is needed for rotation */ 
33651 \newline
33652 ...
33653  
33654 \newline
33655 i = ((i << 1) | (i >> 7)); 
33656 \family default
33657
33658 \newline
33659
33660 \family typewriter
33661 ...
33662 \end_layout
33663
33664 \begin_layout Standard
33665 will generate the following code:
33666 \end_layout
33667
33668 \begin_layout Verse
33669
33670 \family typewriter
33671 mov\InsetSpace ~
33672 \InsetSpace ~
33673 a,_i 
33674 \newline
33675 rl\InsetSpace ~
33676 \InsetSpace ~
33677 \InsetSpace ~
33678
33679 \newline
33680 mov\InsetSpace ~
33681 \InsetSpace ~
33682 _i,a
33683 \end_layout
33684
33685 \begin_layout Standard
33686 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33687 ns of this case will also be recognized as bit-rotation, i.e.: 
33688 \end_layout
33689
33690 \begin_layout Verse
33691
33692 \family typewriter
33693 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33694 \end_layout
33695
33696 \begin_layout Subsection
33697 Nibble and Byte Swapping
33698 \end_layout
33699
33700 \begin_layout Standard
33701 Other special cases of the bit-shift operations are nibble or byte swapping
33702 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33703
33704 \end_inset
33705
33706 , SDCC recognizes the following expressions:
33707 \end_layout
33708
33709 \begin_layout Verse
33710
33711 \family typewriter
33712 \series bold
33713 unsigned
33714 \series default
33715 \InsetSpace ~
33716 \InsetSpace ~
33717 char i; 
33718 \newline
33719
33720 \series bold
33721 unsigned
33722 \series default
33723 \InsetSpace ~
33724 \InsetSpace ~
33725 int j; 
33726 \newline
33727 ...
33728  
33729 \newline
33730 i = ((i << 4) | (i >> 4)); 
33731 \family default
33732
33733 \newline
33734
33735 \family typewriter
33736 j = ((j << 8) | (j >> 8)); 
33737 \end_layout
33738
33739 \begin_layout Standard
33740 and generates a swap instruction for the nibble swapping
33741 \begin_inset LatexCommand \index{Nibble swapping}
33742
33743 \end_inset
33744
33745  or move instructions for the byte swapping
33746 \begin_inset LatexCommand \index{Byte swapping}
33747
33748 \end_inset
33749
33750 .
33751  The 
33752 \begin_inset Quotes sld
33753 \end_inset
33754
33755 j
33756 \begin_inset Quotes srd
33757 \end_inset
33758
33759  example can be used to convert from little to big-endian or vice versa.
33760  If you want to change the endianness of a 
33761 \emph on
33762 signed
33763 \emph default
33764  integer you have to cast to 
33765 \family typewriter
33766 (unsigned int)
33767 \family default
33768  first.
33769 \end_layout
33770
33771 \begin_layout Standard
33772 Note that SDCC stores numbers in little-endian
33773 \begin_inset Foot
33774 status open
33775
33776 \begin_layout Standard
33777 Usually 8-bit processors don't care much about endianness.
33778  This is not the case for the standard 8051 which only has an instruction
33779  to increment its 
33780 \emph on
33781 dptr
33782 \emph default
33783
33784 \begin_inset LatexCommand \index{DPTR}
33785
33786 \end_inset
33787
33788 -datapointer
33789 \emph on
33790  
33791 \emph default
33792 so little-endian is the more efficient byte order.
33793 \end_layout
33794
33795 \end_inset
33796
33797
33798 \begin_inset LatexCommand \index{little-endian}
33799
33800 \end_inset
33801
33802
33803 \begin_inset LatexCommand \index{Endianness}
33804
33805 \end_inset
33806
33807  format (i.e.
33808  lowest order first).
33809 \end_layout
33810
33811 \begin_layout Subsection
33812 Highest Order Bit
33813 \begin_inset LatexCommand \index{Highest Order Bit}
33814
33815 \end_inset
33816
33817  / Any Order Bit
33818 \begin_inset LatexCommand \index{Any Order Bit}
33819
33820 \end_inset
33821
33822
33823 \end_layout
33824
33825 \begin_layout Standard
33826 It is frequently required to obtain the highest order bit of an integral
33827  type (long, int, short or char types).
33828  Also obtaining any other order bit is not uncommon.
33829  SDCC recognizes the following expressions to yield the highest order bit
33830  and generates optimized code for it, e.g.:
33831 \end_layout
33832
33833 \begin_layout Verse
33834
33835 \family typewriter
33836 unsigned int gint; 
33837 \newline
33838
33839 \newline
33840 foo () { 
33841 \newline
33842 \InsetSpace ~
33843 \InsetSpace ~
33844 unsigned char hob1, aob1; 
33845 \newline
33846 \InsetSpace ~
33847 \InsetSpace ~
33848 bit hob2, hob3, aob2,
33849  aob3; 
33850 \newline
33851 \InsetSpace ~
33852 \InsetSpace ~
33853 ...
33854  
33855 \newline
33856 \InsetSpace ~
33857 \InsetSpace ~
33858 hob1 = (gint >> 15) & 1; 
33859 \newline
33860 \InsetSpace ~
33861 \InsetSpace ~
33862 hob2 = (gint >> 15) & 1; 
33863 \newline
33864 \InsetSpace ~
33865 \InsetSpace ~
33866 hob3 = gint & 0x8000;
33867  
33868 \newline
33869 \InsetSpace ~
33870 \InsetSpace ~
33871 aob1 = (gint >> 9) & 1; 
33872 \newline
33873 \InsetSpace ~
33874 \InsetSpace ~
33875 aob2 = (gint >> 8) & 1; 
33876 \newline
33877 \InsetSpace ~
33878 \InsetSpace ~
33879 aob3 = gint & 0x0800; 
33880 \newline
33881 \InsetSpace ~
33882 \InsetSpace ~
33883 ..
33884  
33885 \newline
33886 }
33887 \end_layout
33888
33889 \begin_layout Standard
33890 will generate the following code:
33891 \end_layout
33892
33893 \begin_layout Verse
33894
33895 \family typewriter
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 \InsetSpace ~
33913 \InsetSpace ~
33914 \InsetSpace ~
33915 \InsetSpace ~
33916 \InsetSpace ~
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 \InsetSpace ~
33920 \InsetSpace ~
33921  61 ;\InsetSpace ~
33922  hob.c 7 
33923 \newline
33924 000A E5*01\InsetSpace ~
33925 \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  62\InsetSpace ~
33940 \InsetSpace ~
33941 \InsetSpace ~
33942 \InsetSpace ~
33943 \InsetSpace ~
33944 \InsetSpace ~
33945 \InsetSpace ~
33946 \InsetSpace ~
33947  mov\InsetSpace ~
33948 \InsetSpace ~
33949  a,(_gint + 1) 
33950 \newline
33951 000C 23\InsetSpace ~
33952 \InsetSpace ~
33953 \InsetSpace ~
33954 \InsetSpace ~
33955 \InsetSpace ~
33956 \InsetSpace ~
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 \InsetSpace ~
33960 \InsetSpace ~
33961 \InsetSpace ~
33962 \InsetSpace ~
33963 \InsetSpace ~
33964 \InsetSpace ~
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 \InsetSpace ~
33968 \InsetSpace ~
33969  63\InsetSpace ~
33970 \InsetSpace ~
33971 \InsetSpace ~
33972 \InsetSpace ~
33973 \InsetSpace ~
33974 \InsetSpace ~
33975 \InsetSpace ~
33976 \InsetSpace ~
33977  rl\InsetSpace ~
33978 \InsetSpace ~
33979 \InsetSpace ~
33980  a 
33981 \newline
33982 000D 54 01\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
33998  64\InsetSpace ~
33999 \InsetSpace ~
34000 \InsetSpace ~
34001 \InsetSpace ~
34002 \InsetSpace ~
34003 \InsetSpace ~
34004 \InsetSpace ~
34005 \InsetSpace ~
34006  anl\InsetSpace ~
34007 \InsetSpace ~
34008  a,#0x01 
34009 \newline
34010 000F F5*02\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 \InsetSpace ~
34024 \InsetSpace ~
34025  65\InsetSpace ~
34026 \InsetSpace ~
34027 \InsetSpace ~
34028 \InsetSpace ~
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 \InsetSpace ~
34032 \InsetSpace ~
34033  mov\InsetSpace ~
34034 \InsetSpace ~
34035  _foo_hob1_1_1,a 
34036 \newline
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 \InsetSpace ~
34055 \InsetSpace ~
34056 \InsetSpace ~
34057 \InsetSpace ~
34058 \InsetSpace ~
34059 \InsetSpace ~
34060 \InsetSpace ~
34061 \InsetSpace ~
34062  66 ;\InsetSpace ~
34063  hob.c 8 
34064 \newline
34065 0011 E5*01\InsetSpace ~
34066 \InsetSpace ~
34067 \InsetSpace ~
34068 \InsetSpace ~
34069 \InsetSpace ~
34070 \InsetSpace ~
34071 \InsetSpace ~
34072 \InsetSpace ~
34073 \InsetSpace ~
34074 \InsetSpace ~
34075 \InsetSpace ~
34076 \InsetSpace ~
34077 \InsetSpace ~
34078 \InsetSpace ~
34079 \InsetSpace ~
34080
34081  67\InsetSpace ~
34082 \InsetSpace ~
34083 \InsetSpace ~
34084 \InsetSpace ~
34085 \InsetSpace ~
34086 \InsetSpace ~
34087 \InsetSpace ~
34088 \InsetSpace ~
34089  mov\InsetSpace ~
34090 \InsetSpace ~
34091  a,(_gint + 1) 
34092 \newline
34093 0013 33\InsetSpace ~
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  68\InsetSpace ~
34112 \InsetSpace ~
34113 \InsetSpace ~
34114 \InsetSpace ~
34115 \InsetSpace ~
34116 \InsetSpace ~
34117 \InsetSpace ~
34118 \InsetSpace ~
34119  rlc\InsetSpace ~
34120 \InsetSpace ~
34121  a 
34122 \newline
34123 0014 92*00\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 \InsetSpace ~
34138  69\InsetSpace ~
34139 \InsetSpace ~
34140 \InsetSpace ~
34141 \InsetSpace ~
34142 \InsetSpace ~
34143 \InsetSpace ~
34144 \InsetSpace ~
34145 \InsetSpace ~
34146  mov\InsetSpace ~
34147 \InsetSpace ~
34148  _foo_hob2_1_1,c
34149  
34150 \newline
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 \InsetSpace ~
34168 \InsetSpace ~
34169 \InsetSpace ~
34170 \InsetSpace ~
34171 \InsetSpace ~
34172 \InsetSpace ~
34173 \InsetSpace ~
34174 \InsetSpace ~
34175 \InsetSpace ~
34176  66 ;\InsetSpace ~
34177  hob.c 9 
34178 \newline
34179 0016 E5*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  67\InsetSpace ~
34195 \InsetSpace ~
34196 \InsetSpace ~
34197 \InsetSpace ~
34198 \InsetSpace ~
34199 \InsetSpace ~
34200 \InsetSpace ~
34201 \InsetSpace ~
34202  mov\InsetSpace ~
34203 \InsetSpace ~
34204  a,(_gint + 1) 
34205 \newline
34206 0018 33\InsetSpace ~
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  68\InsetSpace ~
34225 \InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230 \InsetSpace ~
34231 \InsetSpace ~
34232  rlc\InsetSpace ~
34233 \InsetSpace ~
34234  a 
34235 \newline
34236 0019 92*01\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 \InsetSpace ~
34251
34252  69\InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258 \InsetSpace ~
34259 \InsetSpace ~
34260  mov\InsetSpace ~
34261 \InsetSpace ~
34262  _foo_hob3_1_1,c 
34263 \newline
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 \InsetSpace ~
34282 \InsetSpace ~
34283 \InsetSpace ~
34284 \InsetSpace ~
34285 \InsetSpace ~
34286 \InsetSpace ~
34287 \InsetSpace ~
34288 \InsetSpace ~
34289  70 ;\InsetSpace ~
34290  hob.c 10 
34291 \newline
34292 001B E5*01\InsetSpace ~
34293 \InsetSpace ~
34294 \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  71\InsetSpace ~
34308 \InsetSpace ~
34309 \InsetSpace ~
34310 \InsetSpace ~
34311 \InsetSpace ~
34312 \InsetSpace ~
34313 \InsetSpace ~
34314 \InsetSpace ~
34315  mov\InsetSpace ~
34316 \InsetSpace ~
34317  a,(_gint + 1) 
34318 \newline
34319 001D
34320  03\InsetSpace ~
34321 \InsetSpace ~
34322 \InsetSpace ~
34323 \InsetSpace ~
34324 \InsetSpace ~
34325 \InsetSpace ~
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 \InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 \InsetSpace ~
34337 \InsetSpace ~
34338  72\InsetSpace ~
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345 \InsetSpace ~
34346  rr\InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349  a 
34350 \newline
34351 001E 54 01\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  73\InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369 \InsetSpace ~
34370 \InsetSpace ~
34371 \InsetSpace ~
34372 \InsetSpace ~
34373 \InsetSpace ~
34374  anl\InsetSpace ~
34375 \InsetSpace ~
34376  a,#0x01 
34377 \newline
34378 0020 F5*03\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 \InsetSpace ~
34393  74\InsetSpace ~
34394 \InsetSpace ~
34395 \InsetSpace ~
34396 \InsetSpace ~
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 \InsetSpace ~
34401  mov\InsetSpace ~
34402 \InsetSpace ~
34403  _foo_aob1_1_1,a
34404  
34405 \newline
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 \InsetSpace ~
34423 \InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426 \InsetSpace ~
34427 \InsetSpace ~
34428 \InsetSpace ~
34429 \InsetSpace ~
34430 \InsetSpace ~
34431  75 ;\InsetSpace ~
34432  hob.c 11 
34433 \newline
34434 0022 E5*01\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  76\InsetSpace ~
34450 \InsetSpace ~
34451 \InsetSpace ~
34452 \InsetSpace ~
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457  mov\InsetSpace ~
34458 \InsetSpace ~
34459  a,(_gint + 1) 
34460 \newline
34461 0024 13\InsetSpace ~
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  77\InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 \InsetSpace ~
34487  rrc\InsetSpace ~
34488 \InsetSpace ~
34489  a 
34490 \newline
34491 0025 92*02\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 \InsetSpace ~
34506
34507  78\InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513 \InsetSpace ~
34514 \InsetSpace ~
34515  mov\InsetSpace ~
34516 \InsetSpace ~
34517  _foo_aob2_1_1,c 
34518 \newline
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 \InsetSpace ~
34534 \InsetSpace ~
34535 \InsetSpace ~
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539 \InsetSpace ~
34540 \InsetSpace ~
34541 \InsetSpace ~
34542 \InsetSpace ~
34543 \InsetSpace ~
34544  79 ;\InsetSpace ~
34545  hob.c 12 
34546 \newline
34547 0027 E5*01\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 \InsetSpace ~
34561 \InsetSpace ~
34562  80\InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 \InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 \InsetSpace ~
34570  mov\InsetSpace ~
34571 \InsetSpace ~
34572  a,(_gint + 1) 
34573 \newline
34574 0029
34575  A2 E3\InsetSpace ~
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 \InsetSpace ~
34588 \InsetSpace ~
34589 \InsetSpace ~
34590  81\InsetSpace ~
34591 \InsetSpace ~
34592 \InsetSpace ~
34593 \InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 \InsetSpace ~
34598  mov\InsetSpace ~
34599 \InsetSpace ~
34600  c,acc[3] 
34601 \newline
34602 002B 92*03\InsetSpace ~
34603 \InsetSpace ~
34604 \InsetSpace ~
34605 \InsetSpace ~
34606 \InsetSpace ~
34607 \InsetSpace ~
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 \InsetSpace ~
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617  82\InsetSpace ~
34618 \InsetSpace ~
34619 \InsetSpace ~
34620 \InsetSpace ~
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 \InsetSpace ~
34624 \InsetSpace ~
34625  mov\InsetSpace ~
34626 \InsetSpace ~
34627  _foo_aob3_1_1,c 
34628 \end_layout
34629
34630 \begin_layout Standard
34631 Other variations of these cases however will 
34632 \emph on
34633 not
34634 \emph default
34635  be recognized.
34636  They are standard C expressions, so I heartily recommend these be the only
34637  way to get the highest order bit, (it is portable).
34638  Of course it will be recognized even if it is embedded in other expressions,
34639  e.g.:
34640 \end_layout
34641
34642 \begin_layout Verse
34643
34644 \family typewriter
34645 xyz = gint + ((gint >> 15) & 1);
34646 \end_layout
34647
34648 \begin_layout Standard
34649 will still be recognized.
34650 \end_layout
34651
34652 \begin_layout Subsection
34653 Higher Order Byte
34654 \begin_inset LatexCommand \index{Higher Order Byte}
34655
34656 \end_inset
34657
34658  / Higher Order Word
34659 \begin_inset LatexCommand \index{Higher Order Word}
34660
34661 \end_inset
34662
34663
34664 \end_layout
34665
34666 \begin_layout Standard
34667 It is also frequently required to obtain a higher order byte or word of
34668  a larger integral type (long, int or short types).
34669  SDCC recognizes the following expressions to yield the higher order byte
34670  or word and generates optimized code for it, e.g.:
34671 \end_layout
34672
34673 \begin_layout Verse
34674
34675 \family typewriter
34676 unsigned int gint; 
34677 \newline
34678 unsigned long int glong; 
34679 \newline
34680
34681 \newline
34682 foo () { 
34683 \newline
34684 \InsetSpace ~
34685 \InsetSpace ~
34686 unsigned char hob1,
34687  hob2; 
34688 \newline
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 unsigned int how1, how2; 
34692 \newline
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 ...
34696  
34697 \newline
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 hob1 = (gint >> 8) & 0xFF; 
34701 \newline
34702 \InsetSpace ~
34703 \InsetSpace ~
34704 hob2 = glong >> 24; 
34705 \newline
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 how1 = (glong >> 16) & 0xFFFF;
34709  
34710 \newline
34711 \InsetSpace ~
34712 \InsetSpace ~
34713 how2 = glong >> 8; 
34714 \newline
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 ..
34718  
34719 \newline
34720 }
34721 \end_layout
34722
34723 \begin_layout Standard
34724 will generate the following code:
34725 \end_layout
34726
34727 \begin_layout Verse
34728
34729 \family typewriter
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 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755  91 ;\InsetSpace ~
34756  hob.c 15 
34757 \newline
34758 0037 85*01*06\InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766 \InsetSpace ~
34767 \InsetSpace ~
34768 \InsetSpace ~
34769 \InsetSpace ~
34770  92\InsetSpace ~
34771 \InsetSpace ~
34772 \InsetSpace ~
34773 \InsetSpace ~
34774 \InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778  mov\InsetSpace ~
34779 \InsetSpace ~
34780  _foo_hob1_1_1,(_gint + 1) 
34781 \newline
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 \InsetSpace ~
34804 \InsetSpace ~
34805 \InsetSpace ~
34806 \InsetSpace ~
34807  93 ;\InsetSpace ~
34808  hob.c
34809  16 
34810 \newline
34811 003A 85*05*07\InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823  94\InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828 \InsetSpace ~
34829 \InsetSpace ~
34830 \InsetSpace ~
34831  mov\InsetSpace ~
34832 \InsetSpace ~
34833  _foo_hob2_1_1,(_glong + 3) 
34834 \newline
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 \InsetSpace ~
34845 \InsetSpace ~
34846 \InsetSpace ~
34847 \InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 \InsetSpace ~
34852 \InsetSpace ~
34853 \InsetSpace ~
34854 \InsetSpace ~
34855 \InsetSpace ~
34856 \InsetSpace ~
34857 \InsetSpace ~
34858 \InsetSpace ~
34859 \InsetSpace ~
34860  95 ;\InsetSpace ~
34861  hob.c 17 
34862 \newline
34863 003D 85*04*08\InsetSpace ~
34864 \InsetSpace ~
34865 \InsetSpace ~
34866 \InsetSpace ~
34867 \InsetSpace ~
34868 \InsetSpace ~
34869 \InsetSpace ~
34870 \InsetSpace ~
34871 \InsetSpace ~
34872 \InsetSpace ~
34873 \InsetSpace ~
34874 \InsetSpace ~
34875
34876  96\InsetSpace ~
34877 \InsetSpace ~
34878 \InsetSpace ~
34879 \InsetSpace ~
34880 \InsetSpace ~
34881 \InsetSpace ~
34882 \InsetSpace ~
34883 \InsetSpace ~
34884  mov\InsetSpace ~
34885 \InsetSpace ~
34886  _foo_how1_1_1,(_glong + 2) 
34887 \newline
34888 0040 85*05*09\InsetSpace ~
34889 \InsetSpace ~
34890 \InsetSpace ~
34891 \InsetSpace ~
34892 \InsetSpace ~
34893 \InsetSpace ~
34894 \InsetSpace ~
34895 \InsetSpace ~
34896 \InsetSpace ~
34897 \InsetSpace ~
34898 \InsetSpace ~
34899 \InsetSpace ~
34900  97\InsetSpace ~
34901 \InsetSpace ~
34902 \InsetSpace ~
34903 \InsetSpace ~
34904 \InsetSpace ~
34905 \InsetSpace ~
34906 \InsetSpace ~
34907 \InsetSpace ~
34908  mov\InsetSpace ~
34909 \InsetSpace ~
34910  (_foo_how1_1_1 +
34911  1),(_glong + 3) 
34912 \newline
34913 0043 85*03*0A\InsetSpace ~
34914 \InsetSpace ~
34915 \InsetSpace ~
34916 \InsetSpace ~
34917 \InsetSpace ~
34918 \InsetSpace ~
34919 \InsetSpace ~
34920 \InsetSpace ~
34921 \InsetSpace ~
34922 \InsetSpace ~
34923 \InsetSpace ~
34924 \InsetSpace ~
34925  98\InsetSpace ~
34926 \InsetSpace ~
34927 \InsetSpace ~
34928 \InsetSpace ~
34929 \InsetSpace ~
34930 \InsetSpace ~
34931 \InsetSpace ~
34932 \InsetSpace ~
34933  mov\InsetSpace ~
34934 \InsetSpace ~
34935  _foo_how2_1_1,(_glong + 1) 
34936 \newline
34937 0046 85*04*0B\InsetSpace ~
34938 \InsetSpace ~
34939 \InsetSpace ~
34940 \InsetSpace ~
34941 \InsetSpace ~
34942 \InsetSpace ~
34943 \InsetSpace ~
34944 \InsetSpace ~
34945 \InsetSpace ~
34946 \InsetSpace ~
34947 \InsetSpace ~
34948 \InsetSpace ~
34949
34950  99\InsetSpace ~
34951 \InsetSpace ~
34952 \InsetSpace ~
34953 \InsetSpace ~
34954 \InsetSpace ~
34955 \InsetSpace ~
34956 \InsetSpace ~
34957 \InsetSpace ~
34958  mov\InsetSpace ~
34959 \InsetSpace ~
34960  (_foo_how2_1_1 + 1),(_glong + 2) 
34961 \end_layout
34962
34963 \begin_layout Standard
34964 Again, variations of these cases may 
34965 \emph on
34966 not
34967 \emph default
34968  be recognized.
34969  They are standard C expressions, so I heartily recommend these be the only
34970  way to get the higher order byte/word, (it is portable).
34971  Of course it will be recognized even if it is embedded in other expressions,
34972  e.g.:
34973 \end_layout
34974
34975 \begin_layout Verse
34976
34977 \family typewriter
34978 xyz = gint + ((gint >> 8) & 0xFF);
34979 \end_layout
34980
34981 \begin_layout Standard
34982 will still be recognized.
34983 \end_layout
34984
34985 \begin_layout Subsection
34986 Peephole Optimizer
34987 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34988
34989 \end_inset
34990
34991
34992 \begin_inset LatexCommand \index{Peephole optimizer}
34993
34994 \end_inset
34995
34996
34997 \end_layout
34998
34999 \begin_layout Standard
35000 The compiler uses a rule based, pattern matching and re-writing mechanism
35001  for peep-hole optimization.
35002  It is inspired by 
35003 \emph on
35004 copt
35005 \emph default
35006  a peep-hole optimizer by Christopher W.
35007  Fraser (cwfraser\InsetSpace ~
35008 @\InsetSpace ~
35009 microsoft.com).
35010  A default set of rules are compiled into the compiler, additional rules
35011  may be added with the 
35012 \emph on
35013 -
35014 \begin_inset ERT
35015 status collapsed
35016
35017 \begin_layout Standard
35018
35019
35020 \backslash
35021 /
35022 \end_layout
35023
35024 \end_inset
35025
35026 -peep-file
35027 \begin_inset LatexCommand \index{-\/-peep-file}
35028
35029 \end_inset
35030
35031  <filename>
35032 \emph default
35033  option.
35034  The rule language is best illustrated with examples.
35035 \end_layout
35036
35037 \begin_layout Verse
35038
35039 \family typewriter
35040 replace { 
35041 \newline
35042 \InsetSpace ~
35043 \InsetSpace ~
35044 mov %1,a 
35045 \newline
35046 \InsetSpace ~
35047 \InsetSpace ~
35048 mov a,%1
35049 \newline
35050 } by {
35051 \newline
35052 \InsetSpace ~
35053 \InsetSpace ~
35054 mov %1,a
35055 \newline
35056 }
35057 \end_layout
35058
35059 \begin_layout Standard
35060 The above rule will change the following assembly
35061 \begin_inset LatexCommand \index{Assembler routines}
35062
35063 \end_inset
35064
35065  sequence:
35066 \end_layout
35067
35068 \begin_layout Verse
35069
35070 \family typewriter
35071 mov r1,a 
35072 \newline
35073 mov a,r1
35074 \end_layout
35075
35076 \begin_layout Standard
35077 to
35078 \end_layout
35079
35080 \begin_layout Verse
35081
35082 \family typewriter
35083 mov r1,a
35084 \end_layout
35085
35086 \begin_layout Standard
35087 Note: All occurrences of a 
35088 \emph on
35089 %n
35090 \emph default
35091  (pattern variable) must denote the same string.
35092  With the above rule, the assembly sequence:
35093 \end_layout
35094
35095 \begin_layout Verse
35096
35097 \family typewriter
35098 mov r1,a 
35099 \newline
35100 mov a,r2
35101 \end_layout
35102
35103 \begin_layout Standard
35104 will remain unmodified.
35105 \newline
35106
35107 \newline
35108 Other special case optimizations may be added by the
35109  user (via 
35110 \emph on
35111 -
35112 \begin_inset ERT
35113 status collapsed
35114
35115 \begin_layout Standard
35116
35117
35118 \backslash
35119 /
35120 \end_layout
35121
35122 \end_inset
35123
35124 -peep-file option
35125 \emph default
35126 ).
35127  E.g.
35128  some variants of the 8051 MCU
35129 \begin_inset LatexCommand \index{MCS51 variants}
35130
35131 \end_inset
35132
35133  allow only 
35134 \family typewriter
35135 ajmp
35136 \family default
35137  and 
35138 \family typewriter
35139 acall
35140 \family default
35141 .
35142  The following two rules will change all 
35143 \family typewriter
35144 ljmp
35145 \family default
35146  and 
35147 \family typewriter
35148 lcall
35149 \family default
35150  to 
35151 \family typewriter
35152 ajmp
35153 \family default
35154  and 
35155 \family typewriter
35156 acall
35157 \end_layout
35158
35159 \begin_layout Verse
35160
35161 \family typewriter
35162 replace { lcall %1 } by { acall %1 } 
35163 \newline
35164 replace { ljmp %1 } by { ajmp %1 }
35165 \end_layout
35166
35167 \begin_layout Standard
35168 The 
35169 \emph on
35170 inline-assembler code
35171 \emph default
35172  is also passed through the peep hole optimizer, thus the peephole optimizer
35173  can also be used as an assembly level macro expander.
35174  The rules themselves are MCU dependent whereas the rule language infra-structur
35175 e is MCU independent.
35176  Peephole optimization rules for other MCU can be easily programmed using
35177  the rule language.
35178 \newline
35179
35180 \newline
35181 The syntax for a rule is as follows:
35182 \end_layout
35183
35184 \begin_layout Verse
35185
35186 \family typewriter
35187 rule := replace [ restart ] '{' <assembly sequence> '
35188 \backslash
35189 n' 
35190 \newline
35191 \InsetSpace ~
35192  \InsetSpace ~
35193  \InsetSpace ~
35194  \InsetSpace ~
35195  \InsetSpace ~
35196  \InsetSpace ~
35197  \InsetSpace ~
35198  \InsetSpace ~
35199  \InsetSpace ~
35200  \InsetSpace ~
35201  \InsetSpace ~
35202  \InsetSpace ~
35203  \InsetSpace ~
35204  \InsetSpace ~
35205  '}' by '{' '
35206 \backslash
35207 n' 
35208 \newline
35209 \InsetSpace ~
35210  \InsetSpace ~
35211  \InsetSpace ~
35212  \InsetSpace ~
35213  \InsetSpace ~
35214  \InsetSpace ~
35215  \InsetSpace ~
35216  \InsetSpace ~
35217  \InsetSpace ~
35218  \InsetSpace ~
35219  \InsetSpace ~
35220  \InsetSpace ~
35221  \InsetSpace ~
35222  \InsetSpace ~
35223  \InsetSpace ~
35224  \InsetSpace ~
35225  <assembly sequence> '
35226 \backslash
35227 n' 
35228 \newline
35229 \InsetSpace ~
35230  \InsetSpace ~
35231  \InsetSpace ~
35232  \InsetSpace ~
35233  \InsetSpace ~
35234  \InsetSpace ~
35235  \InsetSpace ~
35236  \InsetSpace ~
35237  \InsetSpace ~
35238  \InsetSpace ~
35239  \InsetSpace ~
35240  \InsetSpace ~
35241  \InsetSpace ~
35242  \InsetSpace ~
35243  '}' [if <functionName> ] '
35244 \backslash
35245 n' 
35246 \end_layout
35247
35248 \begin_layout Standard
35249 <assembly sequence> := assembly instruction (each instruction including
35250  labels must be on a separate line).
35251 \newline
35252
35253 \newline
35254 The optimizer will apply to the rules
35255  one by one from the top in the sequence of their appearance, it will terminate
35256  when all rules are exhausted.
35257  If the 'restart' option is specified, then the optimizer will start matching
35258  the rules again from the top, this option for a rule is expensive (performance)
35259 , it is intended to be used in situations where a transformation will trigger
35260  the same rule again.
35261  An example of this (not a good one, it has side effects) is the following
35262  rule:
35263 \end_layout
35264
35265 \begin_layout Verse
35266
35267 \family typewriter
35268 replace restart { 
35269 \newline
35270 \InsetSpace ~
35271 \InsetSpace ~
35272 pop %1 
35273 \newline
35274 \InsetSpace ~
35275 \InsetSpace ~
35276 push %1 } by { 
35277 \newline
35278 \InsetSpace ~
35279 \InsetSpace ~
35280 ; nop 
35281 \newline
35282 }
35283 \end_layout
35284
35285 \begin_layout Standard
35286 Note that the replace pattern cannot be a blank, but can be a comment line.
35287  Without the 'restart' option only the innermost 'pop' 'push' pair would
35288  be eliminated, i.e.:
35289 \end_layout
35290
35291 \begin_layout Verse
35292
35293 \family typewriter
35294 pop ar1 
35295 \newline
35296 pop ar2 
35297 \newline
35298 push ar2 
35299 \newline
35300 push ar1
35301 \end_layout
35302
35303 \begin_layout Standard
35304 would result in:
35305 \end_layout
35306
35307 \begin_layout Verse
35308
35309 \family typewriter
35310 pop ar1 
35311 \newline
35312 ; nop 
35313 \newline
35314 push ar1
35315 \end_layout
35316
35317 \begin_layout Standard
35318
35319 \emph on
35320 with
35321 \emph default
35322  the restart option the rule will be applied again to the resulting code
35323  and then all the pop-push pairs will be eliminated to yield:
35324 \end_layout
35325
35326 \begin_layout Verse
35327
35328 \family typewriter
35329 ; nop 
35330 \newline
35331 ; nop
35332 \end_layout
35333
35334 \begin_layout Standard
35335 A conditional function can be attached to a rule.
35336  Attaching rules are somewhat more involved, let me illustrate this with
35337  an example.
35338 \end_layout
35339
35340 \begin_layout Verse
35341
35342 \family typewriter
35343 replace { 
35344 \newline
35345 \InsetSpace ~
35346  \InsetSpace ~
35347  \InsetSpace ~
35348 ljmp %5 
35349 \newline
35350 %2:
35351 \newline
35352 } by { 
35353 \newline
35354 \InsetSpace ~
35355  \InsetSpace ~
35356  \InsetSpace ~
35357 sjmp %5 
35358 \newline
35359 %2:
35360 \newline
35361 } if labelInRange
35362 \end_layout
35363
35364 \begin_layout Standard
35365 The optimizer does a look-up of a function name table defined in function
35366  
35367 \emph on
35368 callFuncByName
35369 \emph default
35370  in the source file SDCCpeeph.c, with the name 
35371 \emph on
35372 labelInRange
35373 \emph default
35374 .
35375  If it finds a corresponding entry the function is called.
35376  Note there can be no parameters specified for these functions, in this
35377  case the use of 
35378 \emph on
35379 %5
35380 \emph default
35381  is crucial, since the function 
35382 \emph on
35383 labelInRange
35384 \emph default
35385  expects to find the label in that particular variable (the hash table containin
35386 g the variable bindings is passed as a parameter).
35387  If you want to code more such functions, take a close look at the function
35388  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35389  Currently implemented are 
35390 \emph on
35391 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35392  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35393 \emph default
35394 and
35395 \emph on
35396  notVolatile
35397 \emph default
35398 .
35399 \end_layout
35400
35401 \begin_layout Standard
35402 I know this whole thing is a little kludgey, but maybe some day we will
35403  have some better means.
35404  If you are looking at this file, you will see the default rules that are
35405  compiled into the compiler, you can add your own rules in the default set
35406  there if you get tired of specifying the -
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 -peep-file option.
35420 \end_layout
35421
35422 \begin_layout Section
35423 ANSI-Compliance
35424 \begin_inset LatexCommand \index{ANSI-compliance}
35425
35426 \end_inset
35427
35428
35429 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35430
35431 \end_inset
35432
35433
35434 \end_layout
35435
35436 \begin_layout Standard
35437 The latest publically available version of the standard 
35438 \emph on
35439 ISO/IEC 9899 - Programming languages - C
35440 \emph default
35441  should be available at: 
35442 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35443
35444 \end_inset
35445
35446 .
35447 \newline
35448
35449 \end_layout
35450
35451 \begin_layout Standard
35452 Deviations from the compliance:
35453 \end_layout
35454
35455 \begin_layout Itemize
35456 functions are not reentrant
35457 \begin_inset LatexCommand \index{reentrant}
35458
35459 \end_inset
35460
35461  unless explicitly declared as such or the 
35462 \series bold
35463 -
35464 \begin_inset ERT
35465 status collapsed
35466
35467 \begin_layout Standard
35468
35469
35470 \backslash
35471 /
35472 \end_layout
35473
35474 \end_inset
35475
35476 -stack-auto
35477 \begin_inset LatexCommand \index{-\/-stack-auto}
35478
35479 \end_inset
35480
35481
35482 \series default
35483  command line option is specified.
35484 \end_layout
35485
35486 \begin_layout Itemize
35487 structures
35488 \begin_inset LatexCommand \index{struct}
35489
35490 \end_inset
35491
35492  and unions
35493 \begin_inset LatexCommand \index{union}
35494
35495 \end_inset
35496
35497  cannot be assigned values directly, cannot be passed as function parameters
35498  or assigned to each other and cannot be a return value
35499 \begin_inset LatexCommand \index{return value}
35500
35501 \end_inset
35502
35503  from a function, e.g.:
35504 \end_layout
35505
35506 \begin_deeper
35507 \begin_layout Verse
35508
35509 \family typewriter
35510 struct s { ...
35511  }; 
35512 \newline
35513 struct s s1, s2; 
35514 \newline
35515 foo() 
35516 \newline
35517
35518 \newline
35519 \InsetSpace ~
35520 \InsetSpace ~
35521 \InsetSpace ~
35522 \InsetSpace ~
35523 ...
35524  
35525 \newline
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35531 \newline
35532 \InsetSpace ~
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 ...
35537  
35538 \newline
35539 }
35540 \newline
35541
35542 \series bold
35543 struct
35544 \series default
35545  s foo1 (
35546 \series bold
35547 struct
35548 \series default
35549  s parms) /* invalid in SDCC although allowed in ANSI */
35550 \newline
35551
35552 \newline
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 struct s rets;
35558  
35559 \newline
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 ...
35565  
35566 \newline
35567 \InsetSpace ~
35568 \InsetSpace ~
35569 \InsetSpace ~
35570 \InsetSpace ~
35571 return rets; /* is invalid in SDCC although allowed in ANSI */ 
35572 \newline
35573 }
35574 \end_layout
35575
35576 \end_deeper
35577 \begin_layout Itemize
35578 initialization of structure arrays must be fully braced.
35579 \end_layout
35580
35581 \begin_deeper
35582 \begin_layout Verse
35583
35584 \family typewriter
35585 struct s { char x } a[] = {1, 2};\InsetSpace ~
35586 \InsetSpace ~
35587 \InsetSpace ~
35588 \InsetSpace ~
35589 \InsetSpace ~
35590 /* invalid in SDCC */
35591 \newline
35592 struct s { char x
35593  } a[] = {{1}, {2}}; /* OK */
35594 \end_layout
35595
35596 \end_deeper
35597 \begin_layout Itemize
35598 'long long
35599 \begin_inset LatexCommand \index{long long (not supported)}
35600
35601 \end_inset
35602
35603 ' (64 bit integers
35604 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35605
35606 \end_inset
35607
35608 ) not supported.
35609 \end_layout
35610
35611 \begin_layout Itemize
35612 'double
35613 \begin_inset LatexCommand \index{double (not supported)}
35614
35615 \end_inset
35616
35617 ' precision floating point 
35618 \begin_inset LatexCommand \index{Floating point support}
35619
35620 \end_inset
35621
35622 not supported.
35623 \end_layout
35624
35625 \begin_layout Itemize
35626 Old K&R style
35627 \begin_inset LatexCommand \index{K\&R style}
35628
35629 \end_inset
35630
35631  function declarations are NOT allowed.
35632 \end_layout
35633
35634 \begin_deeper
35635 \begin_layout Verse
35636
35637 \family typewriter
35638 foo(i,j) /* this old style of function declarations */ 
35639 \newline
35640 int i,j; /* are valid
35641  in ANSI but not valid in SDCC */ 
35642 \newline
35643
35644 \newline
35645 \InsetSpace ~
35646 \InsetSpace ~
35647 \InsetSpace ~
35648 \InsetSpace ~
35649 ...
35650  
35651 \newline
35652 }
35653 \end_layout
35654
35655 \end_deeper
35656 \begin_layout Itemize
35657 Most enhancements in C99 are not supported, f.e.:
35658 \end_layout
35659
35660 \begin_deeper
35661 \begin_layout Verse
35662
35663 \family typewriter
35664 \series bold
35665 inline
35666 \begin_inset LatexCommand \index{inline (not supported)}
35667
35668 \end_inset
35669
35670
35671 \series default
35672  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35673  in C99.
35674  An empty define 
35675 \emph on
35676 #define inline
35677 \emph default
35678  can be used as a work around */
35679 \newline
35680
35681 \newline
35682 for (
35683 \series bold
35684 int
35685 \series default
35686  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35687 \end_layout
35688
35689 \end_deeper
35690 \begin_layout Itemize
35691 Certain words that are valid identifiers in the standard may be reserved
35692  words in SDCC unless the 
35693 \series bold
35694 -
35695 \begin_inset ERT
35696 status collapsed
35697
35698 \begin_layout Standard
35699
35700
35701 \backslash
35702 /
35703 \end_layout
35704
35705 \end_inset
35706
35707 -std-c89
35708 \begin_inset LatexCommand \index{-\/-std-c89}
35709
35710 \end_inset
35711
35712  or -
35713 \begin_inset ERT
35714 status collapsed
35715
35716 \begin_layout Standard
35717
35718
35719 \backslash
35720 /
35721 \end_layout
35722
35723 \end_inset
35724
35725 -std-c99
35726 \begin_inset LatexCommand \index{-\/-std-c99}
35727
35728 \end_inset
35729
35730
35731 \series default
35732  command line options are used.
35733  These may include (depending on the selected processor): 'at', 'banked',
35734  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35735 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35736  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35737  '_naked'.
35738  Compliant equivalents of these keywords are always available in a form
35739  that begin with two underscores
35740 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35741
35742 \end_inset
35743
35744 , f.e.
35745  '__data' instead of 'data'.
35746 \end_layout
35747
35748 \begin_layout Section
35749 Cyclomatic Complexity
35750 \begin_inset LatexCommand \index{Cyclomatic complexity}
35751
35752 \end_inset
35753
35754
35755 \end_layout
35756
35757 \begin_layout Standard
35758 Cyclomatic complexity of a function is defined as the number of independent
35759  paths the program can take during execution of the function.
35760  This is an important number since it defines the number test cases you
35761  have to generate to validate the function.
35762  The accepted industry standard for complexity number is 10, if the cyclomatic
35763  complexity reported by SDCC exceeds 10 you should think about simplification
35764  of the function logic.
35765  Note that the complexity level is not related to the number of lines of
35766  code in a function.
35767  Large functions can have low complexity, and small functions can have large
35768  complexity levels.
35769  
35770 \newline
35771
35772 \newline
35773 SDCC uses the following formula to compute the complexity:
35774 \newline
35775
35776 \end_layout
35777
35778 \begin_layout Standard
35779 complexity = (number of edges in control flow graph) - (number of nodes
35780  in control flow graph) + 2;
35781 \newline
35782
35783 \newline
35784 Having said that the industry standard is 10,
35785  you should be aware that in some cases it be may unavoidable to have a
35786  complexity level of less than 10.
35787  For example if you have switch statement with more than 10 case labels,
35788  each case label adds one to the complexity level.
35789  The complexity level is by no means an absolute measure of the algorithmic
35790  complexity of the function, it does however provide a good starting point
35791  for which functions you might look at for further optimization.
35792 \end_layout
35793
35794 \begin_layout Section
35795 Retargetting for other Processors
35796 \end_layout
35797
35798 \begin_layout Standard
35799 The issues for retargetting the compiler are far too numerous to be covered
35800  by this document.
35801  What follows is a brief description of each of the seven phases of the
35802  compiler and its MCU dependency.
35803 \end_layout
35804
35805 \begin_layout Itemize
35806 Parsing the source and building the annotated parse tree.
35807  This phase is largely MCU independent (except for the language extensions).
35808  Syntax & semantic checks are also done in this phase, along with some initial
35809  optimizations like back patching labels and the pattern matching optimizations
35810  like bit-rotation etc.
35811 \end_layout
35812
35813 \begin_layout Itemize
35814 The second phase involves generating an intermediate code which can be easy
35815  manipulated during the later phases.
35816  This phase is entirely MCU independent.
35817  The intermediate code generation assumes the target machine has unlimited
35818  number of registers, and designates them with the name iTemp.
35819  The compiler can be made to dump a human readable form of the code generated
35820  by using the -
35821 \begin_inset ERT
35822 status collapsed
35823
35824 \begin_layout Standard
35825
35826
35827 \backslash
35828 /
35829 \end_layout
35830
35831 \end_inset
35832
35833 -dumpraw option.
35834 \end_layout
35835
35836 \begin_layout Itemize
35837 This phase does the bulk of the standard optimizations and is also MCU independe
35838 nt.
35839  This phase can be broken down into several sub-phases:
35840 \newline
35841
35842 \newline
35843 Break down intermediate
35844  code (iCode) into basic blocks.
35845 \newline
35846 Do control flow & data flow analysis on the
35847  basic blocks.
35848 \newline
35849 Do local common subexpression elimination, then global subexpressio
35850 n elimination
35851 \newline
35852 Dead code elimination
35853 \newline
35854 Loop optimizations
35855 \newline
35856 If loop optimizations
35857  caused any changes then do 'global subexpression elimination' and 'dead
35858  code elimination' again.
35859 \end_layout
35860
35861 \begin_layout Itemize
35862 This phase determines the live-ranges; by live range I mean those iTemp
35863  variables defined by the compiler that still survive after all the optimization
35864 s.
35865  Live range analysis
35866 \begin_inset LatexCommand \index{Live range analysis}
35867
35868 \end_inset
35869
35870  is essential for register allocation, since these computation determines
35871  which of these iTemps will be assigned to registers, and for how long.
35872 \end_layout
35873
35874 \begin_layout Itemize
35875 Phase five is register allocation.
35876  There are two parts to this process.
35877 \newline
35878
35879 \newline
35880 The first part I call 'register packing'
35881  (for lack of a better term).
35882  In this case several MCU specific expression folding is done to reduce
35883  register pressure.
35884 \newline
35885
35886 \newline
35887 The second part is more MCU independent and deals with
35888  allocating registers to the remaining live ranges.
35889  A lot of MCU specific code does creep into this phase because of the limited
35890  number of index registers available in the 8051.
35891 \end_layout
35892
35893 \begin_layout Itemize
35894 The Code generation phase is (unhappily), entirely MCU dependent and very
35895  little (if any at all) of this code can be reused for other MCU.
35896  However the scheme for allocating a homogenized assembler operand for each
35897  iCode operand may be reused.
35898 \end_layout
35899
35900 \begin_layout Itemize
35901 As mentioned in the optimization section the peep-hole optimizer is rule
35902  based system, which can reprogrammed for other MCUs.
35903 \end_layout
35904
35905 \begin_layout Standard
35906 More information is available in a wiki
35907 \begin_inset LatexCommand \index{wiki}
35908
35909 \end_inset
35910
35911  (preliminary link 
35912 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35913
35914 \end_inset
35915
35916 ) and in the thread 
35917 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35918
35919 \end_inset
35920
35921  .
35922 \end_layout
35923
35924 \begin_layout Chapter
35925 Compiler internals
35926 \begin_inset LatexCommand \index{Compiler internals}
35927
35928 \end_inset
35929
35930
35931 \end_layout
35932
35933 \begin_layout Section
35934 The anatomy of the compiler
35935 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35936
35937 \end_inset
35938
35939
35940 \end_layout
35941
35942 \begin_layout Standard
35943
35944 \shape italic
35945 This is an excerpt from an article published in Circuit Cellar Magazine
35946  in 
35947 \series bold
35948 August 2000
35949 \series default
35950 .
35951  It's a little outdated (the compiler is much more efficient now and user/develo
35952 per friendly), but pretty well exposes the guts of it all.
35953 \shape default
35954
35955 \newline
35956
35957 \newline
35958 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35959  It is fairly easy to retarget for other 8-bit MCU.
35960  Here we take a look at some of the internals of the compiler.
35961  
35962 \end_layout
35963
35964 \begin_layout Paragraph*
35965 Parsing
35966 \begin_inset LatexCommand \index{Parsing}
35967
35968 \end_inset
35969
35970  
35971 \end_layout
35972
35973 \begin_layout Standard
35974 Parsing the input source file and creating an AST (Annotated Syntax Tree
35975 \begin_inset LatexCommand \index{Annotated syntax tree}
35976
35977 \end_inset
35978
35979 ).
35980  This phase also involves propagating types (annotating each node of the
35981  parse tree with type information) and semantic analysis.
35982  There are some MCU specific parsing rules.
35983  For example the storage classes, the extended storage classes are MCU specific
35984  while there may be a xdata storage class for 8051 there is no such storage
35985  class for z80 or Atmel AVR.
35986  SDCC allows MCU specific storage class extensions, i.e.
35987  xdata will be treated as a storage class specifier when parsing 8051 C
35988  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35989  C code.
35990 \end_layout
35991
35992 \begin_layout Paragraph*
35993 Generating iCode
35994 \begin_inset LatexCommand \index{iCode}
35995
35996 \end_inset
35997
35998
35999 \end_layout
36000
36001 \begin_layout Standard
36002 Intermediate code generation.
36003  In this phase the AST is broken down into three-operand form (iCode).
36004  These three operand forms are represented as doubly linked lists.
36005  ICode is the term given to the intermediate form generated by the compiler.
36006  ICode example section shows some examples of iCode generated for some simple
36007  C source functions.
36008 \end_layout
36009
36010 \begin_layout Paragraph*
36011 Optimizations
36012 \begin_inset LatexCommand \index{Optimizations}
36013
36014 \end_inset
36015
36016 .
36017 \end_layout
36018
36019 \begin_layout Standard
36020 Bulk of the target independent optimizations is performed in this phase.
36021  The optimizations include constant propagation, common sub-expression eliminati
36022 on, loop invariant code movement, strength reduction of loop induction variables
36023  and dead-code elimination.
36024 \end_layout
36025
36026 \begin_layout Paragraph*
36027 Live range analysis
36028 \begin_inset LatexCommand \index{Live range analysis}
36029
36030 \end_inset
36031
36032
36033 \end_layout
36034
36035 \begin_layout Standard
36036 During intermediate code generation phase, the compiler assumes the target
36037  machine has infinite number of registers and generates a lot of temporary
36038  variables.
36039  The live range computation determines the lifetime of each of these compiler-ge
36040 nerated temporaries.
36041  A picture speaks a thousand words.
36042  ICode example sections show the live range annotations for each of the
36043  operand.
36044  It is important to note here, each iCode is assigned a number in the order
36045  of its execution in the function.
36046  The live ranges are computed in terms of these numbers.
36047  The from number is the number of the iCode which first defines the operand
36048  and the to number signifies the iCode which uses this operand last.
36049 \end_layout
36050
36051 \begin_layout Paragraph*
36052 Register Allocation
36053 \begin_inset LatexCommand \index{Register allocation}
36054
36055 \end_inset
36056
36057
36058 \end_layout
36059
36060 \begin_layout Standard
36061 The register allocation determines the type and number of registers needed
36062  by each operand.
36063  In most MCUs only a few registers can be used for indirect addressing.
36064  In case of 8051 for example the registers R0 & R1 can be used to indirectly
36065  address the internal ram and DPTR to indirectly address the external ram.
36066  The compiler will try to allocate the appropriate register to pointer variables
36067  if it can.
36068  ICode example section shows the operands annotated with the registers assigned
36069  to them.
36070  The compiler will try to keep operands in registers as much as possible;
36071  there are several schemes the compiler uses to do achieve this.
36072  When the compiler runs out of registers the compiler will check to see
36073  if there are any live operands which is not used or defined in the current
36074  basic block being processed, if there are any found then it will push that
36075  operand and use the registers in this block, the operand will then be popped
36076  at the end of the basic block.
36077  
36078 \end_layout
36079
36080 \begin_layout Standard
36081 There are other MCU specific considerations in this phase.
36082  Some MCUs have an accumulator; very short-lived operands could be assigned
36083  to the accumulator instead of a general-purpose register.
36084 \end_layout
36085
36086 \begin_layout Paragraph*
36087 Code generation
36088 \end_layout
36089
36090 \begin_layout Standard
36091 Figure II gives a table of iCode
36092 \begin_inset LatexCommand \index{iCode}
36093
36094 \end_inset
36095
36096  operations supported by the compiler.
36097  The code generation involves translating these operations into corresponding
36098  assembly code for the processor.
36099  This sounds overly simple but that is the essence of code generation.
36100  Some of the iCode operations are generated on a MCU specific manner for
36101  example, the z80 port does not use registers to pass parameters so the
36102  SEND and RECV iCode operations will not be generated, and it also does
36103  not support JUMPTABLES.
36104  
36105 \newline
36106
36107 \end_layout
36108
36109 \begin_layout Standard
36110
36111 \size footnotesize
36112 Figure II 
36113 \begin_inset Tabular
36114 <lyxtabular version="3" rows="39" columns="4">
36115 <features islongtable="true" headBottomDL="true">
36116 <column alignment="block" valignment="top" leftline="true" width="13col%">
36117 <column alignment="left" valignment="top" leftline="true" width="13col%">
36118 <column alignment="block" valignment="top" leftline="true" width="22col%">
36119 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36120 <row topline="true" bottomline="true" endhead="true">
36121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36122 \begin_inset Text
36123
36124 \begin_layout Standard
36125
36126 \series bold
36127 iCode
36128 \series default
36129
36130 \begin_inset LatexCommand \index{iCode}
36131
36132 \end_inset
36133
36134
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 \series bold
36145 Operands
36146 \end_layout
36147
36148 \end_inset
36149 </cell>
36150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36151 \begin_inset Text
36152
36153 \begin_layout Standard
36154
36155 \series bold
36156 Description
36157 \end_layout
36158
36159 \end_inset
36160 </cell>
36161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36162 \begin_inset Text
36163
36164 \begin_layout Standard
36165
36166 \series bold
36167 C Equivalent
36168 \end_layout
36169
36170 \end_inset
36171 </cell>
36172 </row>
36173 <row topline="true">
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 '!'
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 IC_LEFT() IC_RESULT()
36192 \end_layout
36193
36194 \end_inset
36195 </cell>
36196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36197 \begin_inset Text
36198
36199 \begin_layout Standard
36200
36201 \size footnotesize
36202 NOT operation 
36203 \end_layout
36204
36205 \end_inset
36206 </cell>
36207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36208 \begin_inset Text
36209
36210 \begin_layout Standard
36211
36212 \size footnotesize
36213 IC_RESULT = ! IC_LEFT;
36214 \end_layout
36215
36216 \end_inset
36217 </cell>
36218 </row>
36219 <row topline="true">
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 '~'
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 IC_LEFT() IC_RESULT()
36238 \end_layout
36239
36240 \end_inset
36241 </cell>
36242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36243 \begin_inset Text
36244
36245 \begin_layout Standard
36246
36247 \size footnotesize
36248 Bitwise complement of 
36249 \end_layout
36250
36251 \end_inset
36252 </cell>
36253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36254 \begin_inset Text
36255
36256 \begin_layout Standard
36257
36258 \size footnotesize
36259 IC_RESULT = ~IC_LEFT;
36260 \end_layout
36261
36262 \end_inset
36263 </cell>
36264 </row>
36265 <row topline="true">
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 RRC
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 IC_LEFT() IC_RESULT()
36284 \end_layout
36285
36286 \end_inset
36287 </cell>
36288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36289 \begin_inset Text
36290
36291 \begin_layout Standard
36292
36293 \size footnotesize
36294 Rotate right with carry
36295 \end_layout
36296
36297 \end_inset
36298 </cell>
36299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36300 \begin_inset Text
36301
36302 \begin_layout Standard
36303
36304 \size footnotesize
36305 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36306 \end_layout
36307
36308 \end_inset
36309 </cell>
36310 </row>
36311 <row topline="true">
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 RLC
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 IC_LEFT() IC_RESULT()
36330 \end_layout
36331
36332 \end_inset
36333 </cell>
36334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36335 \begin_inset Text
36336
36337 \begin_layout Standard
36338
36339 \size footnotesize
36340 Rotate left with carry
36341 \end_layout
36342
36343 \end_inset
36344 </cell>
36345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36346 \begin_inset Text
36347
36348 \begin_layout Standard
36349
36350 \size footnotesize
36351 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36352 \end_layout
36353
36354 \end_inset
36355 </cell>
36356 </row>
36357 <row topline="true">
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 GETHBIT
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 IC_LEFT() IC_RESULT()
36376 \end_layout
36377
36378 \end_inset
36379 </cell>
36380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36381 \begin_inset Text
36382
36383 \begin_layout Standard
36384
36385 \size footnotesize
36386 Get the highest order bit of IC_LEFT
36387 \end_layout
36388
36389 \end_inset
36390 </cell>
36391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36392 \begin_inset Text
36393
36394 \begin_layout Standard
36395
36396 \size footnotesize
36397 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36398 \end_layout
36399
36400 \end_inset
36401 </cell>
36402 </row>
36403 <row topline="true">
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 UNARYMINUS
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 IC_LEFT() IC_RESULT()
36422 \end_layout
36423
36424 \end_inset
36425 </cell>
36426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36427 \begin_inset Text
36428
36429 \begin_layout Standard
36430
36431 \size footnotesize
36432 Unary minus
36433 \end_layout
36434
36435 \end_inset
36436 </cell>
36437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36438 \begin_inset Text
36439
36440 \begin_layout Standard
36441
36442 \size footnotesize
36443 IC_RESULT = - IC_LEFT;
36444 \end_layout
36445
36446 \end_inset
36447 </cell>
36448 </row>
36449 <row topline="true">
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 IPUSH
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 IC_LEFT()
36468 \end_layout
36469
36470 \end_inset
36471 </cell>
36472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36473 \begin_inset Text
36474
36475 \begin_layout Standard
36476
36477 \size footnotesize
36478 Push the operand into stack
36479 \end_layout
36480
36481 \end_inset
36482 </cell>
36483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36484 \begin_inset Text
36485
36486 \begin_layout Standard
36487
36488 \size footnotesize
36489 NONE
36490 \end_layout
36491
36492 \end_inset
36493 </cell>
36494 </row>
36495 <row topline="true">
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 IPOP
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 IC_LEFT()
36514 \end_layout
36515
36516 \end_inset
36517 </cell>
36518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36519 \begin_inset Text
36520
36521 \begin_layout Standard
36522
36523 \size footnotesize
36524 Pop the operand from the stack 
36525 \end_layout
36526
36527 \end_inset
36528 </cell>
36529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36530 \begin_inset Text
36531
36532 \begin_layout Standard
36533
36534 \size footnotesize
36535 NONE
36536 \end_layout
36537
36538 \end_inset
36539 </cell>
36540 </row>
36541 <row topline="true">
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 CALL
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 IC_LEFT() IC_RESULT()
36560 \end_layout
36561
36562 \end_inset
36563 </cell>
36564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36565 \begin_inset Text
36566
36567 \begin_layout Standard
36568
36569 \size footnotesize
36570 Call the function represented by IC_LEFT 
36571 \end_layout
36572
36573 \end_inset
36574 </cell>
36575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36576 \begin_inset Text
36577
36578 \begin_layout Standard
36579
36580 \size footnotesize
36581 IC_RESULT = IC_LEFT();
36582 \end_layout
36583
36584 \end_inset
36585 </cell>
36586 </row>
36587 <row topline="true">
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 PCALL
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 IC_LEFT() IC_RESULT()
36606 \end_layout
36607
36608 \end_inset
36609 </cell>
36610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36611 \begin_inset Text
36612
36613 \begin_layout Standard
36614
36615 \size footnotesize
36616 Call via function pointer
36617 \end_layout
36618
36619 \end_inset
36620 </cell>
36621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36622 \begin_inset Text
36623
36624 \begin_layout Standard
36625
36626 \size footnotesize
36627 IC_RESULT = (*IC_LEFT)();
36628 \end_layout
36629
36630 \end_inset
36631 </cell>
36632 </row>
36633 <row topline="true">
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 RETURN
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 IC_LEFT()
36652 \end_layout
36653
36654 \end_inset
36655 </cell>
36656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36657 \begin_inset Text
36658
36659 \begin_layout Standard
36660
36661 \size footnotesize
36662 Return the value in operand IC_LEFT 
36663 \end_layout
36664
36665 \end_inset
36666 </cell>
36667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36668 \begin_inset Text
36669
36670 \begin_layout Standard
36671
36672 \size footnotesize
36673 return IC_LEFT;
36674 \end_layout
36675
36676 \end_inset
36677 </cell>
36678 </row>
36679 <row topline="true">
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 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 IC_LABEL() 
36698 \end_layout
36699
36700 \end_inset
36701 </cell>
36702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36703 \begin_inset Text
36704
36705 \begin_layout Standard
36706
36707 \size footnotesize
36708 Label
36709 \end_layout
36710
36711 \end_inset
36712 </cell>
36713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36714 \begin_inset Text
36715
36716 \begin_layout Standard
36717
36718 \size footnotesize
36719 IC_LABEL:
36720 \end_layout
36721
36722 \end_inset
36723 </cell>
36724 </row>
36725 <row topline="true">
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 GOTO
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 IC_LABEL() 
36744 \end_layout
36745
36746 \end_inset
36747 </cell>
36748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36749 \begin_inset Text
36750
36751 \begin_layout Standard
36752
36753 \size footnotesize
36754 Goto label
36755 \end_layout
36756
36757 \end_inset
36758 </cell>
36759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36760 \begin_inset Text
36761
36762 \begin_layout Standard
36763
36764 \size footnotesize
36765 goto IC_LABEL();
36766 \end_layout
36767
36768 \end_inset
36769 </cell>
36770 </row>
36771 <row topline="true">
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 '+'
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 IC_LEFT() IC_RIGHT() IC_RESULT()
36790 \end_layout
36791
36792 \end_inset
36793 </cell>
36794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36795 \begin_inset Text
36796
36797 \begin_layout Standard
36798
36799 \size footnotesize
36800 Addition
36801 \end_layout
36802
36803 \end_inset
36804 </cell>
36805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36806 \begin_inset Text
36807
36808 \begin_layout Standard
36809
36810 \size footnotesize
36811 IC_RESULT = IC_LEFT + IC_RIGHT
36812 \end_layout
36813
36814 \end_inset
36815 </cell>
36816 </row>
36817 <row topline="true">
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 '-'
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 IC_LEFT() IC_RIGHT() IC_RESULT()
36836 \end_layout
36837
36838 \end_inset
36839 </cell>
36840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36841 \begin_inset Text
36842
36843 \begin_layout Standard
36844
36845 \size footnotesize
36846 Subtraction
36847 \end_layout
36848
36849 \end_inset
36850 </cell>
36851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36852 \begin_inset Text
36853
36854 \begin_layout Standard
36855
36856 \size footnotesize
36857 IC_RESULT = IC_LEFT - IC_RIGHT 
36858 \end_layout
36859
36860 \end_inset
36861 </cell>
36862 </row>
36863 <row topline="true">
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 '*'
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 IC_LEFT() IC_RIGHT() IC_RESULT()
36882 \end_layout
36883
36884 \end_inset
36885 </cell>
36886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36887 \begin_inset Text
36888
36889 \begin_layout Standard
36890
36891 \size footnotesize
36892 Multiplication 
36893 \end_layout
36894
36895 \end_inset
36896 </cell>
36897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36898 \begin_inset Text
36899
36900 \begin_layout Standard
36901
36902 \size footnotesize
36903 IC_RESULT = IC_LEFT * IC_RIGHT;
36904 \end_layout
36905
36906 \end_inset
36907 </cell>
36908 </row>
36909 <row topline="true">
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 '/'
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 IC_LEFT() IC_RIGHT() IC_RESULT()
36928 \end_layout
36929
36930 \end_inset
36931 </cell>
36932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36933 \begin_inset Text
36934
36935 \begin_layout Standard
36936
36937 \size footnotesize
36938 Division
36939 \end_layout
36940
36941 \end_inset
36942 </cell>
36943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36944 \begin_inset Text
36945
36946 \begin_layout Standard
36947
36948 \size footnotesize
36949 IC_RESULT = IC_LEFT / IC_RIGHT;
36950 \end_layout
36951
36952 \end_inset
36953 </cell>
36954 </row>
36955 <row topline="true">
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 '%'
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 IC_LEFT() IC_RIGHT() IC_RESULT()
36974 \end_layout
36975
36976 \end_inset
36977 </cell>
36978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36979 \begin_inset Text
36980
36981 \begin_layout Standard
36982
36983 \size footnotesize
36984 Modulus
36985 \end_layout
36986
36987 \end_inset
36988 </cell>
36989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36990 \begin_inset Text
36991
36992 \begin_layout Standard
36993
36994 \size footnotesize
36995 IC_RESULT = IC_LEFT % IC_RIGHT;
36996 \end_layout
36997
36998 \end_inset
36999 </cell>
37000 </row>
37001 <row topline="true">
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 '<'
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 IC_LEFT() IC_RIGHT() IC_RESULT()
37020 \end_layout
37021
37022 \end_inset
37023 </cell>
37024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37025 \begin_inset Text
37026
37027 \begin_layout Standard
37028
37029 \size footnotesize
37030 Less than
37031 \end_layout
37032
37033 \end_inset
37034 </cell>
37035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37036 \begin_inset Text
37037
37038 \begin_layout Standard
37039
37040 \size footnotesize
37041 IC_RESULT = IC_LEFT < IC_RIGHT;
37042 \end_layout
37043
37044 \end_inset
37045 </cell>
37046 </row>
37047 <row topline="true">
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 '>'
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 IC_LEFT() IC_RIGHT() IC_RESULT()
37066 \end_layout
37067
37068 \end_inset
37069 </cell>
37070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37071 \begin_inset Text
37072
37073 \begin_layout Standard
37074
37075 \size footnotesize
37076 Greater than 
37077 \end_layout
37078
37079 \end_inset
37080 </cell>
37081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37082 \begin_inset Text
37083
37084 \begin_layout Standard
37085
37086 \size footnotesize
37087 IC_RESULT = IC_LEFT > IC_RIGHT;
37088 \end_layout
37089
37090 \end_inset
37091 </cell>
37092 </row>
37093 <row topline="true">
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 EQ_OP
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 IC_LEFT() IC_RIGHT() IC_RESULT()
37112 \end_layout
37113
37114 \end_inset
37115 </cell>
37116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37117 \begin_inset Text
37118
37119 \begin_layout Standard
37120
37121 \size footnotesize
37122 Equal to 
37123 \end_layout
37124
37125 \end_inset
37126 </cell>
37127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37128 \begin_inset Text
37129
37130 \begin_layout Standard
37131
37132 \size footnotesize
37133 IC_RESULT = IC_LEFT == IC_RIGHT;
37134 \end_layout
37135
37136 \end_inset
37137 </cell>
37138 </row>
37139 <row topline="true">
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 AND_OP
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 IC_LEFT() IC_RIGHT() IC_RESULT() 
37158 \end_layout
37159
37160 \end_inset
37161 </cell>
37162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37163 \begin_inset Text
37164
37165 \begin_layout Standard
37166
37167 \size footnotesize
37168 Logical and operation
37169 \end_layout
37170
37171 \end_inset
37172 </cell>
37173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37174 \begin_inset Text
37175
37176 \begin_layout Standard
37177
37178 \size footnotesize
37179 IC_RESULT = IC_LEFT && IC_RIGHT; 
37180 \end_layout
37181
37182 \end_inset
37183 </cell>
37184 </row>
37185 <row topline="true">
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 OR_OP
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 IC_LEFT() IC_RIGHT() IC_RESULT() 
37204 \end_layout
37205
37206 \end_inset
37207 </cell>
37208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37209 \begin_inset Text
37210
37211 \begin_layout Standard
37212
37213 \size footnotesize
37214 Logical or operation 
37215 \end_layout
37216
37217 \end_inset
37218 </cell>
37219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37220 \begin_inset Text
37221
37222 \begin_layout Standard
37223
37224 \size footnotesize
37225 IC_RESULT = IC_LEFT || IC_RIGHT; 
37226 \end_layout
37227
37228 \end_inset
37229 </cell>
37230 </row>
37231 <row topline="true">
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 '^'
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 IC_LEFT() IC_RIGHT() IC_RESULT() 
37250 \end_layout
37251
37252 \end_inset
37253 </cell>
37254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37255 \begin_inset Text
37256
37257 \begin_layout Standard
37258
37259 \size footnotesize
37260 Exclusive OR
37261 \end_layout
37262
37263 \end_inset
37264 </cell>
37265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37266 \begin_inset Text
37267
37268 \begin_layout Standard
37269
37270 \size footnotesize
37271 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37272 \end_layout
37273
37274 \end_inset
37275 </cell>
37276 </row>
37277 <row topline="true">
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 '|'
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 IC_LEFT() IC_RIGHT() IC_RESULT() 
37296 \end_layout
37297
37298 \end_inset
37299 </cell>
37300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37301 \begin_inset Text
37302
37303 \begin_layout Standard
37304
37305 \size footnotesize
37306 Bitwise OR 
37307 \end_layout
37308
37309 \end_inset
37310 </cell>
37311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37312 \begin_inset Text
37313
37314 \begin_layout Standard
37315
37316 \size footnotesize
37317 IC_RESULT = IC_LEFT | IC_RIGHT;
37318 \end_layout
37319
37320 \end_inset
37321 </cell>
37322 </row>
37323 <row topline="true">
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 BITWISEAND
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 IC_LEFT() IC_RIGHT() IC_RESULT()
37342 \end_layout
37343
37344 \end_inset
37345 </cell>
37346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37347 \begin_inset Text
37348
37349 \begin_layout Standard
37350
37351 \size footnotesize
37352 Bitwise AND 
37353 \end_layout
37354
37355 \end_inset
37356 </cell>
37357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37358 \begin_inset Text
37359
37360 \begin_layout Standard
37361
37362 \size footnotesize
37363 IC_RESULT = IC_LEFT & IC_RIGHT;
37364 \end_layout
37365
37366 \end_inset
37367 </cell>
37368 </row>
37369 <row topline="true">
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 LEFT_OP
37377 \end_layout
37378
37379 \end_inset
37380 </cell>
37381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37382 \begin_inset Text
37383
37384 \begin_layout Standard
37385
37386 \size footnotesize
37387 IC_LEFT() IC_RIGHT() IC_RESULT()
37388 \end_layout
37389
37390 \end_inset
37391 </cell>
37392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37393 \begin_inset Text
37394
37395 \begin_layout Standard
37396
37397 \size footnotesize
37398 Left shift 
37399 \end_layout
37400
37401 \end_inset
37402 </cell>
37403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37404 \begin_inset Text
37405
37406 \begin_layout Standard
37407
37408 \size footnotesize
37409 IC_RESULT = IC_LEFT << IC_RIGHT 
37410 \end_layout
37411
37412 \end_inset
37413 </cell>
37414 </row>
37415 <row topline="true">
37416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37417 \begin_inset Text
37418
37419 \begin_layout Standard
37420
37421 \size footnotesize
37422 RIGHT_OP
37423 \end_layout
37424
37425 \end_inset
37426 </cell>
37427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37428 \begin_inset Text
37429
37430 \begin_layout Standard
37431
37432 \size footnotesize
37433 IC_LEFT() IC_RIGHT() IC_RESULT()
37434 \end_layout
37435
37436 \end_inset
37437 </cell>
37438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37439 \begin_inset Text
37440
37441 \begin_layout Standard
37442
37443 \size footnotesize
37444 Right shift
37445 \end_layout
37446
37447 \end_inset
37448 </cell>
37449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37450 \begin_inset Text
37451
37452 \begin_layout Standard
37453
37454 \size footnotesize
37455 IC_RESULT = IC_LEFT >> IC_RIGHT 
37456 \end_layout
37457
37458 \end_inset
37459 </cell>
37460 </row>
37461 <row topline="true">
37462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37463 \begin_inset Text
37464
37465 \begin_layout Standard
37466
37467 \size footnotesize
37468 GET_VALUE_
37469 \newline
37470 AT_ ADDRESS
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 IC_LEFT() IC_RESULT()
37482 \end_layout
37483
37484 \end_inset
37485 </cell>
37486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37487 \begin_inset Text
37488
37489 \begin_layout Standard
37490
37491 \size footnotesize
37492 Indirect fetch 
37493 \end_layout
37494
37495 \end_inset
37496 </cell>
37497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37498 \begin_inset Text
37499
37500 \begin_layout Standard
37501
37502 \size footnotesize
37503 IC_RESULT = (*IC_LEFT);
37504 \end_layout
37505
37506 \end_inset
37507 </cell>
37508 </row>
37509 <row topline="true">
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 POINTER_SET
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 IC_RIGHT() IC_RESULT() 
37528 \end_layout
37529
37530 \end_inset
37531 </cell>
37532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37533 \begin_inset Text
37534
37535 \begin_layout Standard
37536
37537 \size footnotesize
37538 Indirect set
37539 \end_layout
37540
37541 \end_inset
37542 </cell>
37543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37544 \begin_inset Text
37545
37546 \begin_layout Standard
37547
37548 \size footnotesize
37549 (*IC_RESULT) = IC_RIGHT;
37550 \end_layout
37551
37552 \end_inset
37553 </cell>
37554 </row>
37555 <row topline="true">
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 '='
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 IC_RIGHT() IC_RESULT()
37574 \end_layout
37575
37576 \end_inset
37577 </cell>
37578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37579 \begin_inset Text
37580
37581 \begin_layout Standard
37582
37583 \size footnotesize
37584 Assignment
37585 \end_layout
37586
37587 \end_inset
37588 </cell>
37589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37590 \begin_inset Text
37591
37592 \begin_layout Standard
37593
37594 \size footnotesize
37595 IC_RESULT = IC_RIGHT;
37596 \end_layout
37597
37598 \end_inset
37599 </cell>
37600 </row>
37601 <row topline="true">
37602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37603 \begin_inset Text
37604
37605 \begin_layout Standard
37606
37607 \size footnotesize
37608 IFX
37609 \end_layout
37610
37611 \end_inset
37612 </cell>
37613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37614 \begin_inset Text
37615
37616 \begin_layout Standard
37617
37618 \size footnotesize
37619 IC_COND IC_TRUE IC_LABEL
37620 \end_layout
37621
37622 \end_inset
37623 </cell>
37624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37625 \begin_inset Text
37626
37627 \begin_layout Standard
37628
37629 \size footnotesize
37630 Conditional jump.
37631  If true label is present then jump to true label if condition is true else
37632  jump to false label if condition is false 
37633 \end_layout
37634
37635 \end_inset
37636 </cell>
37637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37638 \begin_inset Text
37639
37640 \begin_layout Standard
37641
37642 \size footnotesize
37643 if (IC_COND) goto IC_TRUE; 
37644 \newline
37645 \InsetSpace ~
37646 \InsetSpace ~
37647 Or 
37648 \newline
37649 If (!IC_COND) goto IC_FALSE;
37650 \end_layout
37651
37652 \end_inset
37653 </cell>
37654 </row>
37655 <row topline="true">
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 ADDRESS_OF
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 IC_LEFT() IC_RESULT()
37674 \end_layout
37675
37676 \end_inset
37677 </cell>
37678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37679 \begin_inset Text
37680
37681 \begin_layout Standard
37682
37683 \size footnotesize
37684 Address of 
37685 \end_layout
37686
37687 \end_inset
37688 </cell>
37689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37690 \begin_inset Text
37691
37692 \begin_layout Standard
37693
37694 \size footnotesize
37695 IC_RESULT = &IC_LEFT();
37696 \end_layout
37697
37698 \end_inset
37699 </cell>
37700 </row>
37701 <row topline="true">
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 JUMPTABLE
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 IC_JTCOND IC_JTLABELS
37720 \end_layout
37721
37722 \end_inset
37723 </cell>
37724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37725 \begin_inset Text
37726
37727 \begin_layout Standard
37728
37729 \size footnotesize
37730 Jump to list of labels depending on the value of JTCOND
37731 \end_layout
37732
37733 \end_inset
37734 </cell>
37735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37736 \begin_inset Text
37737
37738 \begin_layout Standard
37739
37740 \size footnotesize
37741 Switch statement
37742 \end_layout
37743
37744 \end_inset
37745 </cell>
37746 </row>
37747 <row topline="true">
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 CAST
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 IC_RIGHT() IC_LEFT() IC_RESULT()
37766 \end_layout
37767
37768 \end_inset
37769 </cell>
37770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37771 \begin_inset Text
37772
37773 \begin_layout Standard
37774
37775 \size footnotesize
37776 Cast types 
37777 \end_layout
37778
37779 \end_inset
37780 </cell>
37781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37782 \begin_inset Text
37783
37784 \begin_layout Standard
37785
37786 \size footnotesize
37787 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37788 \end_layout
37789
37790 \end_inset
37791 </cell>
37792 </row>
37793 <row topline="true">
37794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37795 \begin_inset Text
37796
37797 \begin_layout Standard
37798
37799 \size footnotesize
37800 SEND
37801 \end_layout
37802
37803 \end_inset
37804 </cell>
37805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37806 \begin_inset Text
37807
37808 \begin_layout Standard
37809
37810 \size footnotesize
37811 IC_LEFT()
37812 \end_layout
37813
37814 \end_inset
37815 </cell>
37816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37817 \begin_inset Text
37818
37819 \begin_layout Standard
37820
37821 \size footnotesize
37822 This is used for passing parameters in registers; 
37823 \newline
37824 move IC_LEFT to the next
37825  available parameter register.
37826 \end_layout
37827
37828 \end_inset
37829 </cell>
37830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37831 \begin_inset Text
37832
37833 \begin_layout Standard
37834
37835 \size footnotesize
37836 None
37837 \end_layout
37838
37839 \end_inset
37840 </cell>
37841 </row>
37842 <row topline="true">
37843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37844 \begin_inset Text
37845
37846 \begin_layout Standard
37847
37848 \size footnotesize
37849 RECV
37850 \end_layout
37851
37852 \end_inset
37853 </cell>
37854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37855 \begin_inset Text
37856
37857 \begin_layout Standard
37858
37859 \size footnotesize
37860 IC_RESULT()
37861 \end_layout
37862
37863 \end_inset
37864 </cell>
37865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37866 \begin_inset Text
37867
37868 \begin_layout Standard
37869
37870 \size footnotesize
37871 This is used for receiving parameters passed in registers;
37872 \newline
37873 Move the values
37874  in the next parameter register to IC_RESULT 
37875 \end_layout
37876
37877 \end_inset
37878 </cell>
37879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37880 \begin_inset Text
37881
37882 \begin_layout Standard
37883
37884 \size footnotesize
37885 None
37886 \end_layout
37887
37888 \end_inset
37889 </cell>
37890 </row>
37891 <row topline="true" bottomline="true">
37892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37893 \begin_inset Text
37894
37895 \begin_layout Standard
37896
37897 \shape slanted
37898 \size footnotesize
37899 (some more have been added)
37900 \end_layout
37901
37902 \end_inset
37903 </cell>
37904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37905 \begin_inset Text
37906
37907 \begin_layout Standard
37908
37909 \end_layout
37910
37911 \end_inset
37912 </cell>
37913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37914 \begin_inset Text
37915
37916 \begin_layout Standard
37917
37918 \end_layout
37919
37920 \end_inset
37921 </cell>
37922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37923 \begin_inset Text
37924
37925 \begin_layout Standard
37926
37927 \shape slanted
37928 \size footnotesize
37929 see f.e.
37930  
37931 \family typewriter
37932 gen51Code()
37933 \family default
37934  in 
37935 \family typewriter
37936 src/mcs51/gen.c
37937 \end_layout
37938
37939 \end_inset
37940 </cell>
37941 </row>
37942 </lyxtabular>
37943
37944 \end_inset
37945
37946
37947 \end_layout
37948
37949 \begin_layout Standard
37950 \begin_inset Note Note
37951 status collapsed
37952
37953 \begin_layout Standard
37954 In the original article Figure II was announced to be downloadable on 
37955 \shape italic
37956 Circuit Cellar
37957 \shape default
37958 's web site.
37959  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37960 \end_layout
37961
37962 \end_inset
37963
37964
37965 \end_layout
37966
37967 \begin_layout Paragraph*
37968 ICode Example
37969 \begin_inset LatexCommand \index{iCode}
37970
37971 \end_inset
37972
37973
37974 \end_layout
37975
37976 \begin_layout Standard
37977 This section shows some details of iCode.
37978  The example C code does not do anything useful; it is used as an example
37979  to illustrate the intermediate code generated by the compiler.
37980 \end_layout
37981
37982 \begin_layout Verse
37983
37984 \family typewriter
37985 1.\InsetSpace ~
37986 xdata int * p;
37987 \newline
37988 2.\InsetSpace ~
37989 int gint;
37990 \newline
37991 3.\InsetSpace ~
37992 /* This function does nothing useful.
37993  It is used
37994 \newline
37995 4.\InsetSpace ~
37996 \InsetSpace ~
37997 \InsetSpace ~
37998 \InsetSpace ~
37999 for the purpose of explaining iCode */
38000 \newline
38001 5.\InsetSpace ~
38002 short function (data
38003  int *x)
38004 \newline
38005 6.\InsetSpace ~
38006 {
38007 \newline
38008 7.\InsetSpace ~
38009 \InsetSpace ~
38010 \InsetSpace ~
38011 short i=10; \InsetSpace ~
38012 \InsetSpace ~
38013 /* dead initialization eliminated */
38014 \newline
38015 8.\InsetSpace ~
38016 \InsetSpace ~
38017 \InsetSpace ~
38018 short sum=10;
38019  /* dead initialization eliminated */
38020 \newline
38021 9.\InsetSpace ~
38022 \InsetSpace ~
38023 \InsetSpace ~
38024 short mul;
38025 \newline
38026 10.\InsetSpace ~
38027 \InsetSpace ~
38028 int j ;
38029 \newline
38030 11.\InsetSpace ~
38031 \InsetSpace ~
38032 while (*x) *x++
38033  = *p++; 
38034 \newline
38035 12.\InsetSpace ~
38036 \InsetSpace ~
38037 \InsetSpace ~
38038 \InsetSpace ~
38039 sum = 0 ; 
38040 \newline
38041 13.\InsetSpace ~
38042 \InsetSpace ~
38043 mul = 0;
38044 \newline
38045 14.\InsetSpace ~
38046 \InsetSpace ~
38047 /* compiler detects i,j to be induction
38048  variables */
38049 \newline
38050 15.\InsetSpace ~
38051 \InsetSpace ~
38052 for (i = 0, j = 10 ; i < 10 ; i++, j
38053 \family default
38054 -
38055 \begin_inset ERT
38056 status collapsed
38057
38058 \begin_layout Standard
38059
38060
38061 \backslash
38062 /
38063 \end_layout
38064
38065 \end_inset
38066
38067 -
38068 \family typewriter
38069 ) {
38070 \newline
38071 16.\InsetSpace ~
38072 \InsetSpace ~
38073 \InsetSpace ~
38074 \InsetSpace ~
38075 sum += i;
38076 \newline
38077 17.\InsetSpace ~
38078 \InsetSpace ~
38079 \InsetSpace ~
38080 \InsetSpace ~
38081 mul += i * 3; \InsetSpace ~
38082 \InsetSpace ~
38083 /* this multiplication remains */
38084 \newline
38085 18.\InsetSpace ~
38086 \InsetSpace ~
38087 \InsetSpace ~
38088 \InsetSpace ~
38089 gint +=
38090  j * 3;\InsetSpace ~
38091 \InsetSpace ~
38092 /* this multiplication changed to addition */
38093 \newline
38094 19.\InsetSpace ~
38095 \InsetSpace ~
38096 }
38097 \newline
38098 20.\InsetSpace ~
38099 \InsetSpace ~
38100 return sum+mul;
38101 \newline
38102 21.\InsetSpace ~
38103 }
38104 \end_layout
38105
38106 \begin_layout Standard
38107 In addition to the operands each iCode contains information about the filename
38108  and line it corresponds to in the source file.
38109  The first field in the listing should be interpreted as follows:
38110 \newline
38111
38112 \shape italic
38113 \size footnotesize
38114 Filename(linenumber: iCode Execution sequence number : ICode hash table
38115  key : loop depth of the iCode).
38116 \shape default
38117 \size default
38118
38119 \newline
38120 Then follows the human readable form of the ICode operation.
38121  Each operand of this triplet form can be of three basic types a) compiler
38122  generated temporary b) user defined variable c) a constant value.
38123  Note that local variables and parameters are replaced by compiler generated
38124  temporaries.
38125  Live ranges
38126 \begin_inset LatexCommand \index{Live range analysis}
38127
38128 \end_inset
38129
38130  are computed only for temporaries (i.e.
38131  live ranges are not computed for global variables).
38132  Registers
38133 \begin_inset LatexCommand \index{Register allocation}
38134
38135 \end_inset
38136
38137  are allocated for temporaries only.
38138  Operands are formatted in the following manner:
38139 \newline
38140
38141 \shape italic
38142 \size footnotesize
38143 Operand Name [lr live-from : live-to ] { type information } [ registers
38144  allocated ].
38145 \shape default
38146 \size default
38147
38148 \newline
38149 As mentioned earlier the live ranges are computed in terms of the execution
38150  sequence number of the iCodes, for example 
38151 \newline
38152 the iTemp0 is live from (i.e.
38153  first defined in iCode with execution sequence number 3, and is last used
38154  in the iCode with sequence number 5).
38155  For induction variables such as iTemp21 the live range computation extends
38156  the lifetime from the start to the end of the loop.
38157 \newline
38158 The register allocator
38159  used the live range information to allocate registers, the same registers
38160  may be used for different temporaries if their live ranges do not overlap,
38161  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38162  ranges do not overlap.
38163  In addition the allocator also takes into consideration the type and usage
38164  of a temporary, for example itemp6 is a pointer to near space and is used
38165  as to fetch data from (i.e.
38166  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38167  Some short lived temporaries are allocated to special registers which have
38168  meaning to the code generator e.g.
38169  iTemp13 is allocated to a pseudo register CC which tells the back end that
38170  the temporary is used only for a conditional jump the code generation makes
38171  use of this information to optimize a compare and jump ICode.
38172 \newline
38173 There are several
38174  loop optimizations
38175 \begin_inset LatexCommand \index{Loop optimization}
38176
38177 \end_inset
38178
38179  performed by the compiler.
38180  It can detect induction variables iTemp21(i) and iTemp23(j).
38181  Also note the compiler does selective strength reduction
38182 \begin_inset LatexCommand \index{Strength reduction}
38183
38184 \end_inset
38185
38186 , i.e.
38187  the multiplication of an induction variable in line 18 (gint = j * 3) is
38188  changed to addition, a new temporary iTemp17 is allocated and assigned
38189  a initial value, a constant 3 is then added for each iteration of the loop.
38190  The compiler does not change the multiplication
38191 \begin_inset LatexCommand \index{Multiplication}
38192
38193 \end_inset
38194
38195  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38196 \newline
38197
38198 Note the dead code elimination
38199 \begin_inset LatexCommand \index{Dead-code elimination}
38200
38201 \end_inset
38202
38203  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38204  respectively.
38205 \newline
38206
38207 \end_layout
38208
38209 \begin_layout Standard
38210
38211 \size footnotesize
38212 Sample.c (5:1:0:0) _entry($9) :
38213 \end_layout
38214
38215 \begin_layout Standard
38216
38217 \size footnotesize
38218 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38219 \end_layout
38220
38221 \begin_layout Standard
38222
38223 \size footnotesize
38224 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38225 \end_layout
38226
38227 \begin_layout Standard
38228
38229 \size footnotesize
38230 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38231 \end_layout
38232
38233 \begin_layout Standard
38234
38235 \size footnotesize
38236 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38237  * int}[r2]
38238 \end_layout
38239
38240 \begin_layout Standard
38241
38242 \size footnotesize
38243 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38244 \end_layout
38245
38246 \begin_layout Standard
38247
38248 \size footnotesize
38249 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38250  int}[r0]]
38251 \end_layout
38252
38253 \begin_layout Standard
38254
38255 \size footnotesize
38256 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38257 \end_layout
38258
38259 \begin_layout Standard
38260
38261 \size footnotesize
38262 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38263  * int}
38264 \end_layout
38265
38266 \begin_layout Standard
38267
38268 \size footnotesize
38269 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38270  {short}
38271 \end_layout
38272
38273 \begin_layout Standard
38274
38275 \size footnotesize
38276 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38277  * int}[DPTR]]
38278 \end_layout
38279
38280 \begin_layout Standard
38281
38282 \size footnotesize
38283 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38284 }[r2 r3]
38285 \end_layout
38286
38287 \begin_layout Standard
38288
38289 \size footnotesize
38290 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38291  * int}[r0] + 0x2 {short}
38292 \end_layout
38293
38294 \begin_layout Standard
38295
38296 \size footnotesize
38297 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38298 \end_layout
38299
38300 \begin_layout Standard
38301
38302 \size footnotesize
38303 Sample.c(11:17:21:0)_whilebreak_0($3) :
38304 \end_layout
38305
38306 \begin_layout Standard
38307
38308 \size footnotesize
38309 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38310 \end_layout
38311
38312 \begin_layout Standard
38313
38314 \size footnotesize
38315 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38316 \end_layout
38317
38318 \begin_layout Standard
38319
38320 \size footnotesize
38321 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38322 \end_layout
38323
38324 \begin_layout Standard
38325
38326 \size footnotesize
38327 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38328 \end_layout
38329
38330 \begin_layout Standard
38331
38332 \size footnotesize
38333 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38334 \end_layout
38335
38336 \begin_layout Standard
38337
38338 \size footnotesize
38339 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38340 \end_layout
38341
38342 \begin_layout Standard
38343
38344 \size footnotesize
38345 Sample.c(15:24:26:1)_forcond_0($4) :
38346 \end_layout
38347
38348 \begin_layout Standard
38349
38350 \size footnotesize
38351 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38352  < 0xa {short}
38353 \end_layout
38354
38355 \begin_layout Standard
38356
38357 \size footnotesize
38358 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38359 \end_layout
38360
38361 \begin_layout Standard
38362
38363 \size footnotesize
38364 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38365  + ITemp21 [lr21:38]{short}[r4]
38366 \end_layout
38367
38368 \begin_layout Standard
38369
38370 \size footnotesize
38371 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38372  * 0x3 {short}
38373 \end_layout
38374
38375 \begin_layout Standard
38376
38377 \size footnotesize
38378 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38379  + iTemp15 [lr29:30]{short}[r1]
38380 \end_layout
38381
38382 \begin_layout Standard
38383
38384 \size footnotesize
38385 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38386  r0]- 0x3 {short}
38387 \end_layout
38388
38389 \begin_layout Standard
38390
38391 \size footnotesize
38392 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38393 int}[r7 r0]
38394 \end_layout
38395
38396 \begin_layout Standard
38397
38398 \size footnotesize
38399 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38400  + 0x1 {short}
38401 \end_layout
38402
38403 \begin_layout Standard
38404
38405 \size footnotesize
38406 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38407  r6]- 0x1 {short}
38408 \end_layout
38409
38410 \begin_layout Standard
38411
38412 \size footnotesize
38413 Sample.c(19:38:47:1) goto _forcond_0($4)
38414 \end_layout
38415
38416 \begin_layout Standard
38417
38418 \size footnotesize
38419 Sample.c(19:39:48:0)_forbreak_0($7) :
38420 \end_layout
38421
38422 \begin_layout Standard
38423
38424 \size footnotesize
38425 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38426  + ITemp11 [lr19:40]{short}[r3]
38427 \end_layout
38428
38429 \begin_layout Standard
38430
38431 \size footnotesize
38432 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38433 \end_layout
38434
38435 \begin_layout Standard
38436
38437 \size footnotesize
38438 Sample.c(20:42:51:0)_return($8) :
38439 \end_layout
38440
38441 \begin_layout Standard
38442
38443 \size footnotesize
38444 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38445 \size default
38446
38447 \newline
38448
38449 \newline
38450 Finally the code generated for this function:
38451 \newline
38452
38453 \end_layout
38454
38455 \begin_layout Standard
38456
38457 \size footnotesize
38458 .area DSEG (DATA)
38459 \end_layout
38460
38461 \begin_layout Standard
38462
38463 \size footnotesize
38464 _p::
38465 \end_layout
38466
38467 \begin_layout Standard
38468
38469 \size footnotesize
38470 \InsetSpace ~
38471 \InsetSpace ~
38472 .ds 2
38473 \end_layout
38474
38475 \begin_layout Standard
38476
38477 \size footnotesize
38478 _gint::
38479 \end_layout
38480
38481 \begin_layout Standard
38482
38483 \size footnotesize
38484 \InsetSpace ~
38485 \InsetSpace ~
38486 .ds 2
38487 \end_layout
38488
38489 \begin_layout Standard
38490
38491 \size footnotesize
38492 ; sample.c 5
38493 \end_layout
38494
38495 \begin_layout Standard
38496
38497 \size footnotesize
38498 ; ----------------------------------------------
38499 \end_layout
38500
38501 \begin_layout Standard
38502
38503 \size footnotesize
38504 ; function function
38505 \end_layout
38506
38507 \begin_layout Standard
38508
38509 \size footnotesize
38510 ; ----------------------------------------------
38511 \end_layout
38512
38513 \begin_layout Standard
38514
38515 \size footnotesize
38516 _function:
38517 \end_layout
38518
38519 \begin_layout Standard
38520
38521 \size footnotesize
38522 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38523 \end_layout
38524
38525 \begin_layout Standard
38526
38527 \size footnotesize
38528 \InsetSpace ~
38529 \InsetSpace ~
38530 mov r2,dpl
38531 \end_layout
38532
38533 \begin_layout Standard
38534
38535 \size footnotesize
38536 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38537 \end_layout
38538
38539 \begin_layout Standard
38540
38541 \size footnotesize
38542 \InsetSpace ~
38543 \InsetSpace ~
38544 mov ar0,r2
38545 \end_layout
38546
38547 \begin_layout Standard
38548
38549 \size footnotesize
38550 ;_whilecontinue_0($1) :
38551 \end_layout
38552
38553 \begin_layout Standard
38554
38555 \size footnotesize
38556 00101$:
38557 \end_layout
38558
38559 \begin_layout Standard
38560
38561 \size footnotesize
38562 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38563 \end_layout
38564
38565 \begin_layout Standard
38566
38567 \size footnotesize
38568 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38569 \end_layout
38570
38571 \begin_layout Standard
38572
38573 \size footnotesize
38574 \InsetSpace ~
38575 \InsetSpace ~
38576 mov ar2,@r0
38577 \end_layout
38578
38579 \begin_layout Standard
38580
38581 \size footnotesize
38582 \InsetSpace ~
38583 \InsetSpace ~
38584 inc r0
38585 \end_layout
38586
38587 \begin_layout Standard
38588
38589 \size footnotesize
38590 \InsetSpace ~
38591 \InsetSpace ~
38592 mov ar3,@r0
38593 \end_layout
38594
38595 \begin_layout Standard
38596
38597 \size footnotesize
38598 \InsetSpace ~
38599 \InsetSpace ~
38600 dec r0
38601 \end_layout
38602
38603 \begin_layout Standard
38604
38605 \size footnotesize
38606 \InsetSpace ~
38607 \InsetSpace ~
38608 mov a,r2
38609 \end_layout
38610
38611 \begin_layout Standard
38612
38613 \size footnotesize
38614 \InsetSpace ~
38615 \InsetSpace ~
38616 orl a,r3
38617 \end_layout
38618
38619 \begin_layout Standard
38620
38621 \size footnotesize
38622 \InsetSpace ~
38623 \InsetSpace ~
38624 jz 00103$
38625 \end_layout
38626
38627 \begin_layout Standard
38628
38629 \size footnotesize
38630 00114$:
38631 \end_layout
38632
38633 \begin_layout Standard
38634
38635 \size footnotesize
38636 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38637 \end_layout
38638
38639 \begin_layout Standard
38640
38641 \size footnotesize
38642 \InsetSpace ~
38643 \InsetSpace ~
38644 mov dpl,_p
38645 \end_layout
38646
38647 \begin_layout Standard
38648
38649 \size footnotesize
38650 \InsetSpace ~
38651 \InsetSpace ~
38652 mov dph,(_p + 1)
38653 \end_layout
38654
38655 \begin_layout Standard
38656
38657 \size footnotesize
38658 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38659 \end_layout
38660
38661 \begin_layout Standard
38662
38663 \size footnotesize
38664 \InsetSpace ~
38665 \InsetSpace ~
38666 mov a,#0x02
38667 \end_layout
38668
38669 \begin_layout Standard
38670
38671 \size footnotesize
38672 \InsetSpace ~
38673 \InsetSpace ~
38674 add a,_p
38675 \end_layout
38676
38677 \begin_layout Standard
38678
38679 \size footnotesize
38680 \InsetSpace ~
38681 \InsetSpace ~
38682 mov _p,a
38683 \end_layout
38684
38685 \begin_layout Standard
38686
38687 \size footnotesize
38688 \InsetSpace ~
38689 \InsetSpace ~
38690 clr a
38691 \end_layout
38692
38693 \begin_layout Standard
38694
38695 \size footnotesize
38696 \InsetSpace ~
38697 \InsetSpace ~
38698 addc a,(_p + 1)
38699 \end_layout
38700
38701 \begin_layout Standard
38702
38703 \size footnotesize
38704 \InsetSpace ~
38705 \InsetSpace ~
38706 mov (_p + 1),a
38707 \end_layout
38708
38709 \begin_layout Standard
38710
38711 \size footnotesize
38712 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38713 \end_layout
38714
38715 \begin_layout Standard
38716
38717 \size footnotesize
38718 \InsetSpace ~
38719 \InsetSpace ~
38720 movx a,@dptr
38721 \end_layout
38722
38723 \begin_layout Standard
38724
38725 \size footnotesize
38726 \InsetSpace ~
38727 \InsetSpace ~
38728 mov r2,a
38729 \end_layout
38730
38731 \begin_layout Standard
38732
38733 \size footnotesize
38734 \InsetSpace ~
38735 \InsetSpace ~
38736 inc dptr
38737 \end_layout
38738
38739 \begin_layout Standard
38740
38741 \size footnotesize
38742 \InsetSpace ~
38743 \InsetSpace ~
38744 movx a,@dptr
38745 \end_layout
38746
38747 \begin_layout Standard
38748
38749 \size footnotesize
38750 \InsetSpace ~
38751 \InsetSpace ~
38752 mov r3,a
38753 \end_layout
38754
38755 \begin_layout Standard
38756
38757 \size footnotesize
38758 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38759 \end_layout
38760
38761 \begin_layout Standard
38762
38763 \size footnotesize
38764 \InsetSpace ~
38765 \InsetSpace ~
38766 mov @r0,ar2
38767 \end_layout
38768
38769 \begin_layout Standard
38770
38771 \size footnotesize
38772 \InsetSpace ~
38773 \InsetSpace ~
38774 inc r0
38775 \end_layout
38776
38777 \begin_layout Standard
38778
38779 \size footnotesize
38780 \InsetSpace ~
38781 \InsetSpace ~
38782 mov @r0,ar3
38783 \end_layout
38784
38785 \begin_layout Standard
38786
38787 \size footnotesize
38788 ; iTemp6 [lr5:16]{_near * int}[r0] = 
38789 \end_layout
38790
38791 \begin_layout Standard
38792
38793 \size footnotesize
38794 ; iTemp6 [lr5:16]{_near * int}[r0] + 
38795 \end_layout
38796
38797 \begin_layout Standard
38798
38799 \size footnotesize
38800 ; 0x2 {short}
38801 \end_layout
38802
38803 \begin_layout Standard
38804
38805 \size footnotesize
38806 \InsetSpace ~
38807 \InsetSpace ~
38808 inc r0
38809 \end_layout
38810
38811 \begin_layout Standard
38812
38813 \size footnotesize
38814 ; goto _whilecontinue_0($1)
38815 \end_layout
38816
38817 \begin_layout Standard
38818
38819 \size footnotesize
38820 \InsetSpace ~
38821 \InsetSpace ~
38822 sjmp 00101$
38823 \end_layout
38824
38825 \begin_layout Standard
38826
38827 \size footnotesize
38828 ; _whilebreak_0($3) :
38829 \end_layout
38830
38831 \begin_layout Standard
38832
38833 \size footnotesize
38834 00103$:
38835 \end_layout
38836
38837 \begin_layout Standard
38838
38839 \size footnotesize
38840 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38841 \end_layout
38842
38843 \begin_layout Standard
38844
38845 \size footnotesize
38846 \InsetSpace ~
38847 \InsetSpace ~
38848 mov r2,#0x00
38849 \end_layout
38850
38851 \begin_layout Standard
38852
38853 \size footnotesize
38854 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38855 \end_layout
38856
38857 \begin_layout Standard
38858
38859 \size footnotesize
38860 \InsetSpace ~
38861 \InsetSpace ~
38862 mov r3,#0x00
38863 \end_layout
38864
38865 \begin_layout Standard
38866
38867 \size footnotesize
38868 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38869 \end_layout
38870
38871 \begin_layout Standard
38872
38873 \size footnotesize
38874 \InsetSpace ~
38875 \InsetSpace ~
38876 mov r4,#0x00
38877 \end_layout
38878
38879 \begin_layout Standard
38880
38881 \size footnotesize
38882 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38883 \end_layout
38884
38885 \begin_layout Standard
38886
38887 \size footnotesize
38888 \InsetSpace ~
38889 \InsetSpace ~
38890 mov r5,#0x0A
38891 \end_layout
38892
38893 \begin_layout Standard
38894
38895 \size footnotesize
38896 \InsetSpace ~
38897 \InsetSpace ~
38898 mov r6,#0x00
38899 \end_layout
38900
38901 \begin_layout Standard
38902
38903 \size footnotesize
38904 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38905 \end_layout
38906
38907 \begin_layout Standard
38908
38909 \size footnotesize
38910 \InsetSpace ~
38911 \InsetSpace ~
38912 mov r7,#0x1E
38913 \end_layout
38914
38915 \begin_layout Standard
38916
38917 \size footnotesize
38918 \InsetSpace ~
38919 \InsetSpace ~
38920 mov r0,#0x00
38921 \end_layout
38922
38923 \begin_layout Standard
38924
38925 \size footnotesize
38926 ; _forcond_0($4) :
38927 \end_layout
38928
38929 \begin_layout Standard
38930
38931 \size footnotesize
38932 00104$:
38933 \end_layout
38934
38935 \begin_layout Standard
38936
38937 \size footnotesize
38938 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38939 \end_layout
38940
38941 \begin_layout Standard
38942
38943 \size footnotesize
38944 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38945 \end_layout
38946
38947 \begin_layout Standard
38948
38949 \size footnotesize
38950 \InsetSpace ~
38951 \InsetSpace ~
38952 clr c
38953 \end_layout
38954
38955 \begin_layout Standard
38956
38957 \size footnotesize
38958 \InsetSpace ~
38959 \InsetSpace ~
38960 mov a,r4
38961 \end_layout
38962
38963 \begin_layout Standard
38964
38965 \size footnotesize
38966 \InsetSpace ~
38967 \InsetSpace ~
38968 xrl a,#0x80
38969 \end_layout
38970
38971 \begin_layout Standard
38972
38973 \size footnotesize
38974 \InsetSpace ~
38975 \InsetSpace ~
38976 subb a,#0x8a
38977 \end_layout
38978
38979 \begin_layout Standard
38980
38981 \size footnotesize
38982 \InsetSpace ~
38983 \InsetSpace ~
38984 jnc 00107$
38985 \end_layout
38986
38987 \begin_layout Standard
38988
38989 \size footnotesize
38990 00115$:
38991 \end_layout
38992
38993 \begin_layout Standard
38994
38995 \size footnotesize
38996 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
38997 \end_layout
38998
38999 \begin_layout Standard
39000
39001 \size footnotesize
39002 ; iTemp21 [lr21:38]{short}[r4]
39003 \end_layout
39004
39005 \begin_layout Standard
39006
39007 \size footnotesize
39008 \InsetSpace ~
39009 \InsetSpace ~
39010 mov a,r4
39011 \end_layout
39012
39013 \begin_layout Standard
39014
39015 \size footnotesize
39016 \InsetSpace ~
39017 \InsetSpace ~
39018 add a,r2
39019 \end_layout
39020
39021 \begin_layout Standard
39022
39023 \size footnotesize
39024 \InsetSpace ~
39025 \InsetSpace ~
39026 mov r2,a
39027 \end_layout
39028
39029 \begin_layout Standard
39030
39031 \size footnotesize
39032 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39033 \end_layout
39034
39035 \begin_layout Standard
39036
39037 \size footnotesize
39038 \InsetSpace ~
39039 \InsetSpace ~
39040 mov b,#0x03
39041 \end_layout
39042
39043 \begin_layout Standard
39044
39045 \size footnotesize
39046 \InsetSpace ~
39047 \InsetSpace ~
39048 mov a,r4
39049 \end_layout
39050
39051 \begin_layout Standard
39052
39053 \size footnotesize
39054 \InsetSpace ~
39055 \InsetSpace ~
39056 mul ab
39057 \end_layout
39058
39059 \begin_layout Standard
39060
39061 \size footnotesize
39062 \InsetSpace ~
39063 \InsetSpace ~
39064 mov r1,a
39065 \end_layout
39066
39067 \begin_layout Standard
39068
39069 \size footnotesize
39070 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
39071 \end_layout
39072
39073 \begin_layout Standard
39074
39075 \size footnotesize
39076 ; iTemp15 [lr29:30]{short}[r1]
39077 \end_layout
39078
39079 \begin_layout Standard
39080
39081 \size footnotesize
39082 \InsetSpace ~
39083 \InsetSpace ~
39084 add a,r3
39085 \end_layout
39086
39087 \begin_layout Standard
39088
39089 \size footnotesize
39090 \InsetSpace ~
39091 \InsetSpace ~
39092 mov r3,a
39093 \end_layout
39094
39095 \begin_layout Standard
39096
39097 \size footnotesize
39098 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39099 \end_layout
39100
39101 \begin_layout Standard
39102
39103 \size footnotesize
39104 \InsetSpace ~
39105 \InsetSpace ~
39106 mov a,r7
39107 \end_layout
39108
39109 \begin_layout Standard
39110
39111 \size footnotesize
39112 \InsetSpace ~
39113 \InsetSpace ~
39114 add a,#0xfd
39115 \end_layout
39116
39117 \begin_layout Standard
39118
39119 \size footnotesize
39120 \InsetSpace ~
39121 \InsetSpace ~
39122 mov r7,a
39123 \end_layout
39124
39125 \begin_layout Standard
39126
39127 \size footnotesize
39128 \InsetSpace ~
39129 \InsetSpace ~
39130 mov a,r0
39131 \end_layout
39132
39133 \begin_layout Standard
39134
39135 \size footnotesize
39136 \InsetSpace ~
39137 \InsetSpace ~
39138 addc a,#0xff
39139 \end_layout
39140
39141 \begin_layout Standard
39142
39143 \size footnotesize
39144 \InsetSpace ~
39145 \InsetSpace ~
39146 mov r0,a
39147 \end_layout
39148
39149 \begin_layout Standard
39150
39151 \size footnotesize
39152 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39153 \end_layout
39154
39155 \begin_layout Standard
39156
39157 \size footnotesize
39158 \InsetSpace ~
39159 \InsetSpace ~
39160 mov a,r7
39161 \end_layout
39162
39163 \begin_layout Standard
39164
39165 \size footnotesize
39166 \InsetSpace ~
39167 \InsetSpace ~
39168 add a,_gint
39169 \end_layout
39170
39171 \begin_layout Standard
39172
39173 \size footnotesize
39174 \InsetSpace ~
39175 \InsetSpace ~
39176 mov _gint,a
39177 \end_layout
39178
39179 \begin_layout Standard
39180
39181 \size footnotesize
39182 \InsetSpace ~
39183 \InsetSpace ~
39184 mov a,r0
39185 \end_layout
39186
39187 \begin_layout Standard
39188
39189 \size footnotesize
39190 \InsetSpace ~
39191 \InsetSpace ~
39192 addc a,(_gint + 1)
39193 \end_layout
39194
39195 \begin_layout Standard
39196
39197 \size footnotesize
39198 \InsetSpace ~
39199 \InsetSpace ~
39200 mov (_gint + 1),a
39201 \end_layout
39202
39203 \begin_layout Standard
39204
39205 \size footnotesize
39206 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39207 \end_layout
39208
39209 \begin_layout Standard
39210
39211 \size footnotesize
39212 \InsetSpace ~
39213 \InsetSpace ~
39214 inc r4
39215 \end_layout
39216
39217 \begin_layout Standard
39218
39219 \size footnotesize
39220 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39221 \end_layout
39222
39223 \begin_layout Standard
39224
39225 \size footnotesize
39226 \InsetSpace ~
39227 \InsetSpace ~
39228 dec r5
39229 \end_layout
39230
39231 \begin_layout Standard
39232
39233 \size footnotesize
39234 \InsetSpace ~
39235 \InsetSpace ~
39236 cjne r5,#0xff,00104$
39237 \end_layout
39238
39239 \begin_layout Standard
39240
39241 \size footnotesize
39242 \InsetSpace ~
39243 \InsetSpace ~
39244 dec r6
39245 \end_layout
39246
39247 \begin_layout Standard
39248
39249 \size footnotesize
39250 ; goto _forcond_0($4)
39251 \end_layout
39252
39253 \begin_layout Standard
39254
39255 \size footnotesize
39256 \InsetSpace ~
39257 \InsetSpace ~
39258 sjmp 00104$
39259 \end_layout
39260
39261 \begin_layout Standard
39262
39263 \size footnotesize
39264 ; _forbreak_0($7) :
39265 \end_layout
39266
39267 \begin_layout Standard
39268
39269 \size footnotesize
39270 00107$:
39271 \end_layout
39272
39273 \begin_layout Standard
39274
39275 \size footnotesize
39276 ; ret iTemp24 [lr40:41]{short}
39277 \end_layout
39278
39279 \begin_layout Standard
39280
39281 \size footnotesize
39282 \InsetSpace ~
39283 \InsetSpace ~
39284 mov a,r3
39285 \end_layout
39286
39287 \begin_layout Standard
39288
39289 \size footnotesize
39290 \InsetSpace ~
39291 \InsetSpace ~
39292 add a,r2
39293 \end_layout
39294
39295 \begin_layout Standard
39296
39297 \size footnotesize
39298 \InsetSpace ~
39299 \InsetSpace ~
39300 mov dpl,a
39301 \end_layout
39302
39303 \begin_layout Standard
39304
39305 \size footnotesize
39306 ; _return($8) :
39307 \end_layout
39308
39309 \begin_layout Standard
39310
39311 \size footnotesize
39312 00108$:
39313 \end_layout
39314
39315 \begin_layout Standard
39316
39317 \size footnotesize
39318 \InsetSpace ~
39319 \InsetSpace ~
39320 ret
39321 \newline
39322
39323 \end_layout
39324
39325 \begin_layout Section
39326 A few words about basic block successors, predecessors and dominators
39327 \end_layout
39328
39329 \begin_layout Standard
39330 Successors are basic blocks
39331 \begin_inset LatexCommand \index{Basic blocks}
39332
39333 \end_inset
39334
39335  that might execute after this basic block.
39336 \newline
39337 Predecessors are basic blocks
39338  that might execute before reaching this basic block.
39339 \newline
39340 Dominators are basic
39341  blocks that WILL execute before reaching this basic block.
39342 \newline
39343
39344 \end_layout
39345
39346 \begin_layout Standard
39347 [basic block 1]
39348 \end_layout
39349
39350 \begin_layout Standard
39351 if (something)
39352 \end_layout
39353
39354 \begin_layout Standard
39355 \InsetSpace ~
39356 \InsetSpace ~
39357 \InsetSpace ~
39358 \InsetSpace ~
39359 [basic block 2]
39360 \end_layout
39361
39362 \begin_layout Standard
39363 else
39364 \end_layout
39365
39366 \begin_layout Standard
39367 \InsetSpace ~
39368 \InsetSpace ~
39369 \InsetSpace ~
39370 \InsetSpace ~
39371 [basic block 3]
39372 \end_layout
39373
39374 \begin_layout Standard
39375 [basic block 4]
39376 \newline
39377
39378 \end_layout
39379
39380 \begin_layout Standard
39381 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39382 \end_layout
39383
39384 \begin_layout Standard
39385 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39386 \end_layout
39387
39388 \begin_layout Standard
39389 c) domVect of [BB4] = BB1 ...
39390  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39391  was executed.
39392 \end_layout
39393
39394 \begin_layout Chapter
39395 Acknowledgments
39396 \end_layout
39397
39398 \begin_layout Standard
39399 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39400
39401 \end_inset
39402
39403
39404 \newline
39405
39406 \newline
39407
39408 \emph on
39409 Thanks to all the other volunteer developers who have helped with coding,
39410  testing, web-page creation, distribution sets, etc.
39411  You know who you are :-)
39412 \emph default
39413
39414 \newline
39415
39416 \newline
39417
39418 \emph on
39419 Also thanks to Sourceforge 
39420 \begin_inset LatexCommand \url{http://www.sf.net}
39421
39422 \end_inset
39423
39424  which has hosted the project since 1999 and donates significant download
39425  bandwidth and probably more than 
39426 \begin_inset ERT
39427 status collapsed
39428
39429 \begin_layout Standard
39430
39431 $10^{13}$
39432 \end_layout
39433
39434 \end_inset
39435
39436 CPU cycles per day.
39437 \newline
39438  
39439 \begin_inset Note Note
39440 status open
39441
39442 \begin_layout Standard
39443 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39444  minutes for (configure+make+regression test), and there is (i386, amd64,
39445  alpha, ppc64, (mingw32), sparc, Mac OS X).
39446  
39447 \end_layout
39448
39449 \end_inset
39450
39451
39452 \end_layout
39453
39454 \begin_layout Standard
39455 This document was initially written by Sandeep Dutta
39456 \end_layout
39457
39458 \begin_layout Standard
39459 All product names mentioned herein may be trademarks
39460 \begin_inset LatexCommand \index{Trademarks}
39461
39462 \end_inset
39463
39464  of their respective companies.
39465  
39466 \end_layout
39467
39468 \begin_layout Section*
39469 Alphabetical index
39470 \end_layout
39471
39472 \begin_layout Standard
39473 To avoid confusion, the installation and building options for SDCC itself
39474  (chapter 2) are not part of the index.
39475 \end_layout
39476
39477 \begin_layout Standard
39478 \begin_inset LatexCommand \printindex{}
39479
39480 \end_inset
39481
39482
39483 \end_layout
39484
39485 \end_body
39486 \end_document