* doc/sdccman.lyx: inserted footnotes about inline assembler labels,
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.4 created this file. For more info see http://www.lyx.org/
2 \lyxformat 245
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \fontscheme pslatex
26 \graphics default
27 \paperfontsize default
28 \spacing single
29 \papersize letterpaper
30 \use_geometry true
31 \use_amsmath 1
32 \cite_engine basic
33 \use_bibtopic false
34 \paperorientation portrait
35 \leftmargin 30mm
36 \topmargin 20mm
37 \rightmargin 25mm
38 \bottommargin 20mm
39 \secnumdepth 3
40 \tocdepth 3
41 \paragraph_separation indent
42 \defskip medskip
43 \quotes_language swedish
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47 \tracking_changes false
48 \output_changes true
49 \end_header
50
51 \begin_body
52
53 \begin_layout Standard
54 \begin_inset Note Note
55 status collapsed
56
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59  --version) are written this way: -
60 \begin_inset ERT
61 status collapsed
62
63 \begin_layout Standard
64
65
66 \backslash
67 /
68 \end_layout
69
70 \end_inset
71
72 -
73 \end_layout
74
75 \begin_layout Standard
76 Two resp.
77  three consecutive dashes would otherwise result in a long resp.
78  extra long dash.
79 \end_layout
80
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
83  later go
84 \end_layout
85
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
88  Z80 in 
89 \end_layout
90
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
93 \end_layout
94
95 \end_inset
96
97
98 \end_layout
99
100 \begin_layout Title
101 SDCC Compiler User Guide
102 \end_layout
103
104 \begin_layout Date
105
106 \size normal
107 SDCC 2.7.0
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 \end_layout
8440
8441 \begin_layout List
8442 \labelwidthstring 00.00.0000
8443
8444 \series bold
8445 -
8446 \begin_inset ERT
8447 status collapsed
8448
8449 \begin_layout Standard
8450
8451
8452 \backslash
8453 /
8454 \end_layout
8455
8456 \end_inset
8457
8458 -portmode=
8459 \series default
8460 <Value>
8461 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8462
8463 \end_inset
8464
8465  Determinate PORT I/O mode (<Value> is z80 or z180).
8466 \end_layout
8467
8468 \begin_layout List
8469 \labelwidthstring 00.00.0000
8470
8471 \series bold
8472 -
8473 \begin_inset ERT
8474 status collapsed
8475
8476 \begin_layout Standard
8477
8478
8479 \backslash
8480 /
8481 \end_layout
8482
8483 \end_inset
8484
8485 -asm=
8486 \series default
8487 <Value>
8488 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8489
8490 \end_inset
8491
8492  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8493 \end_layout
8494
8495 \begin_layout List
8496 \labelwidthstring 00.00.0000
8497
8498 \series bold
8499 -
8500 \begin_inset ERT
8501 status collapsed
8502
8503 \begin_layout Standard
8504
8505
8506 \backslash
8507 /
8508 \end_layout
8509
8510 \end_inset
8511
8512 -codeseg
8513 \series default
8514 \InsetSpace ~
8515 <Value>
8516 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8517
8518 \end_inset
8519
8520  Use <Value> for the code segment name.
8521 \end_layout
8522
8523 \begin_layout List
8524 \labelwidthstring 00.00.0000
8525
8526 \series bold
8527 -
8528 \begin_inset ERT
8529 status collapsed
8530
8531 \begin_layout Standard
8532
8533
8534 \backslash
8535 /
8536 \end_layout
8537
8538 \end_inset
8539
8540 -constseg
8541 \series default
8542 \InsetSpace ~
8543 <Value>
8544 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8545
8546 \end_inset
8547
8548  Use <Value> for the const segment name.
8549 \end_layout
8550
8551 \begin_layout List
8552 \labelwidthstring 00.00.0000
8553 \begin_inset VSpace bigskip
8554 \end_inset
8555
8556
8557 \end_layout
8558
8559 \begin_layout Subsection
8560 GBZ80 Options
8561 \begin_inset LatexCommand \index{Options GBZ80}
8562
8563 \end_inset
8564
8565
8566 \begin_inset LatexCommand \index{GBZ80}
8567
8568 \end_inset
8569
8570
8571 \end_layout
8572
8573 \begin_layout List
8574 \labelwidthstring 00.00.0000
8575
8576 \series bold
8577 -
8578 \begin_inset ERT
8579 status collapsed
8580
8581 \begin_layout Standard
8582
8583
8584 \backslash
8585 /
8586 \end_layout
8587
8588 \end_inset
8589
8590 -callee-saves-bc
8591 \series default
8592
8593 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8594
8595 \end_inset
8596
8597
8598 \size large
8599 \emph on
8600  
8601 \size default
8602 \emph default
8603 Force a called function to always save BC.
8604 \end_layout
8605
8606 \begin_layout List
8607 \labelwidthstring 00.00.0000
8608
8609 \series bold
8610 -bo
8611 \series default
8612 \InsetSpace ~
8613 <Num>
8614 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8615
8616 \end_inset
8617
8618  Use code bank <Num>.
8619 \end_layout
8620
8621 \begin_layout List
8622 \labelwidthstring 00.00.0000
8623
8624 \series bold
8625 -ba
8626 \series default
8627 \InsetSpace ~
8628 <Num>
8629 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8630
8631 \end_inset
8632
8633  Use data bank <Num>.
8634 \end_layout
8635
8636 \begin_layout List
8637 \labelwidthstring 00.00.0000
8638
8639 \series bold
8640 -
8641 \begin_inset ERT
8642 status collapsed
8643
8644 \begin_layout Standard
8645
8646
8647 \backslash
8648 /
8649 \end_layout
8650
8651 \end_inset
8652
8653 -codeseg
8654 \series default
8655 \InsetSpace ~
8656 <Value>
8657 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8658
8659 \end_inset
8660
8661  Use <Value> for the code segment name.
8662 \end_layout
8663
8664 \begin_layout List
8665 \labelwidthstring 00.00.0000
8666
8667 \series bold
8668 -
8669 \begin_inset ERT
8670 status collapsed
8671
8672 \begin_layout Standard
8673
8674
8675 \backslash
8676 /
8677 \end_layout
8678
8679 \end_inset
8680
8681 -constseg
8682 \series default
8683 \InsetSpace ~
8684 <Value>
8685 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8686
8687 \end_inset
8688
8689  Use <Value> for the const segment name.
8690 \end_layout
8691
8692 \begin_layout Standard
8693 \begin_inset VSpace bigskip
8694 \end_inset
8695
8696
8697 \end_layout
8698
8699 \begin_layout Subsection
8700 Optimization Options
8701 \begin_inset LatexCommand \index{Options optimization}
8702
8703 \end_inset
8704
8705
8706 \begin_inset LatexCommand \index{Optimization options}
8707
8708 \end_inset
8709
8710
8711 \end_layout
8712
8713 \begin_layout List
8714 \labelwidthstring 00.00.0000
8715
8716 \series bold
8717 -
8718 \begin_inset ERT
8719 status collapsed
8720
8721 \begin_layout Standard
8722
8723
8724 \backslash
8725 /
8726 \end_layout
8727
8728 \end_inset
8729
8730 -nogcse
8731 \begin_inset LatexCommand \index{-\/-nogcse}
8732
8733 \end_inset
8734
8735
8736 \series default
8737  Will not do global subexpression elimination, this option may be used when
8738  the compiler creates undesirably large stack/data spaces to store compiler
8739  temporaries (
8740 \emph on
8741 s
8742 \emph default
8743 pill 
8744 \emph on
8745 loc
8746 \emph default
8747 ations, sloc
8748 \begin_inset LatexCommand \index{sloc (spill location)}
8749
8750 \end_inset
8751
8752 ).
8753  A warning message will be generated when this happens and the compiler
8754  will indicate the number of extra bytes it allocated.
8755  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8756 nogcse
8757 \begin_inset LatexCommand \index{\#pragma nogcse}
8758
8759 \end_inset
8760
8761  can be used to turn off global subexpression elimination
8762 \begin_inset LatexCommand \index{Subexpression elimination}
8763
8764 \end_inset
8765
8766  for a given function only.
8767 \end_layout
8768
8769 \begin_layout List
8770 \labelwidthstring 00.00.0000
8771
8772 \series bold
8773 -
8774 \begin_inset ERT
8775 status collapsed
8776
8777 \begin_layout Standard
8778
8779
8780 \backslash
8781 /
8782 \end_layout
8783
8784 \end_inset
8785
8786 -noinvariant
8787 \begin_inset LatexCommand \index{-\/-noinvariant}
8788
8789 \end_inset
8790
8791
8792 \series default
8793  Will not do loop invariant optimizations, this may be turned off for reasons
8794  explained for the previous option.
8795  For more details of loop optimizations performed see Loop Invariants in
8796  section 
8797 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8798
8799 \end_inset
8800
8801 .
8802  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8803 noinvariant
8804 \begin_inset LatexCommand \index{\#pragma noinvariant}
8805
8806 \end_inset
8807
8808  can be used to turn off invariant optimizations for a given function only.
8809 \end_layout
8810
8811 \begin_layout List
8812 \labelwidthstring 00.00.0000
8813
8814 \series bold
8815 -
8816 \begin_inset ERT
8817 status collapsed
8818
8819 \begin_layout Standard
8820
8821
8822 \backslash
8823 /
8824 \end_layout
8825
8826 \end_inset
8827
8828 -noinduction
8829 \begin_inset LatexCommand \index{-\/-noinduction}
8830
8831 \end_inset
8832
8833
8834 \series default
8835  Will not do loop induction optimizations, see section strength reduction
8836  for more details.
8837  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8838 noinduction
8839 \begin_inset LatexCommand \index{\#pragma noinduction}
8840
8841 \end_inset
8842
8843  can be used to turn off induction optimizations for a given function only.
8844 \end_layout
8845
8846 \begin_layout List
8847 \labelwidthstring 00.00.0000
8848
8849 \series bold
8850 -
8851 \begin_inset ERT
8852 status collapsed
8853
8854 \begin_layout Standard
8855
8856
8857 \backslash
8858 /
8859 \end_layout
8860
8861 \end_inset
8862
8863 -nojtbound
8864 \begin_inset LatexCommand \index{-\/-nojtbound}
8865
8866 \end_inset
8867
8868
8869 \size large
8870 \bar under
8871  
8872 \series default
8873 \size default
8874 \bar default
8875  Will not generate boundary condition check when switch statements
8876 \begin_inset LatexCommand \index{switch statement}
8877
8878 \end_inset
8879
8880  are implemented using jump-tables.
8881  See section 
8882 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8883
8884 \end_inset
8885
8886 \InsetSpace ~
8887 Switch Statements for more details.
8888  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8889 nojtbound
8890 \begin_inset LatexCommand \index{\#pragma nojtbound}
8891
8892 \end_inset
8893
8894  can be used to turn off boundary checking for jump tables for a given function
8895  only.
8896 \end_layout
8897
8898 \begin_layout List
8899 \labelwidthstring 00.00.0000
8900
8901 \series bold
8902 -
8903 \begin_inset ERT
8904 status collapsed
8905
8906 \begin_layout Standard
8907
8908
8909 \backslash
8910 /
8911 \end_layout
8912
8913 \end_inset
8914
8915 -noloopreverse
8916 \begin_inset LatexCommand \index{-\/-noloopreverse}
8917
8918 \end_inset
8919
8920
8921 \series default
8922 \size large
8923  
8924 \size default
8925 Will not do loop reversal 
8926 \begin_inset LatexCommand \index{Loop reversing}
8927
8928 \end_inset
8929
8930 optimization.
8931 \end_layout
8932
8933 \begin_layout List
8934 \labelwidthstring 00.00.0000
8935 -
8936 \begin_inset ERT
8937 status collapsed
8938
8939 \begin_layout Standard
8940
8941
8942 \backslash
8943 /
8944 \end_layout
8945
8946 \end_inset
8947
8948 -
8949 \series bold
8950 nolabelopt
8951 \series default
8952  
8953 \begin_inset LatexCommand \index{-\/-nolabelopt }
8954
8955 \end_inset
8956
8957 Will not optimize labels (makes the dumpfiles more readable).
8958 \end_layout
8959
8960 \begin_layout List
8961 \labelwidthstring 00.00.0000
8962
8963 \series bold
8964 -
8965 \begin_inset ERT
8966 status collapsed
8967
8968 \begin_layout Standard
8969
8970
8971 \backslash
8972 /
8973 \end_layout
8974
8975 \end_inset
8976
8977 -no-xinit-opt
8978 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8979
8980 \end_inset
8981
8982
8983 \series default
8984  Will not memcpy initialized data from code space into xdata space.
8985  This saves a few bytes in code space if you don't have initialized data
8986 \begin_inset LatexCommand \index{Variable initialization}
8987
8988 \end_inset
8989
8990 .
8991 \end_layout
8992
8993 \begin_layout List
8994 \labelwidthstring 00.00.0000
8995
8996 \series bold
8997 -
8998 \begin_inset ERT
8999 status collapsed
9000
9001 \begin_layout Standard
9002
9003
9004 \backslash
9005 /
9006 \end_layout
9007
9008 \end_inset
9009
9010 -nooverlay
9011 \begin_inset LatexCommand \index{-\/-nooverlay}
9012
9013 \end_inset
9014
9015
9016 \series default
9017   The compiler will not overlay parameters and local variables of any function,
9018  see section Parameters and local variables for more details.
9019 \end_layout
9020
9021 \begin_layout List
9022 \labelwidthstring 00.00.0000
9023
9024 \series bold
9025 -
9026 \begin_inset ERT
9027 status collapsed
9028
9029 \begin_layout Standard
9030
9031
9032 \backslash
9033 /
9034 \end_layout
9035
9036 \end_inset
9037
9038 -no-peep
9039 \begin_inset LatexCommand \index{-\/-no-peep}
9040
9041 \end_inset
9042
9043
9044 \series default
9045  Disable peep-hole optimization with built-in rules.
9046 \end_layout
9047
9048 \begin_layout List
9049 \labelwidthstring 00.00.0000
9050
9051 \series bold
9052 -
9053 \begin_inset ERT
9054 status collapsed
9055
9056 \begin_layout Standard
9057
9058
9059 \backslash
9060 /
9061 \end_layout
9062
9063 \end_inset
9064
9065 -peep-file
9066 \series default
9067
9068 \begin_inset LatexCommand \index{-\/-peep-file}
9069
9070 \end_inset
9071
9072 \InsetSpace ~
9073 <filename> This option can be used to use additional rules to be used by
9074  the peep hole optimizer.
9075  See section 
9076 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9077
9078 \end_inset
9079
9080 \InsetSpace ~
9081 Peep Hole optimizations for details on how to write these rules.
9082 \end_layout
9083
9084 \begin_layout List
9085 \labelwidthstring 00.00.0000
9086
9087 \series bold
9088 -
9089 \begin_inset ERT
9090 status collapsed
9091
9092 \begin_layout Standard
9093
9094
9095 \backslash
9096 /
9097 \end_layout
9098
9099 \end_inset
9100
9101 -peep-asm
9102 \begin_inset LatexCommand \index{-\/-peep-asm}
9103
9104 \end_inset
9105
9106
9107 \series default
9108  Pass the inline assembler code through the peep hole optimizer.
9109  This can cause unexpected changes to inline assembler code, please go through
9110  the peephole optimizer
9111 \begin_inset LatexCommand \index{Peephole optimizer}
9112
9113 \end_inset
9114
9115  rules defined in the source file tree '<target>/peeph.def' before using
9116  this option.
9117 \end_layout
9118
9119 \begin_layout List
9120 \labelwidthstring 00.00.0000
9121
9122 \series bold
9123 -
9124 \begin_inset ERT
9125 status collapsed
9126
9127 \begin_layout Standard
9128
9129
9130 \backslash
9131 /
9132 \end_layout
9133
9134 \end_inset
9135
9136 -opt-code-speed
9137 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9138
9139 \end_inset
9140
9141
9142 \series default
9143  The compiler will optimize code generation towards fast code, possibly
9144  at the expense of code size.
9145 \end_layout
9146
9147 \begin_layout List
9148 \labelwidthstring 00.00.0000
9149
9150 \series bold
9151 -
9152 \begin_inset ERT
9153 status collapsed
9154
9155 \begin_layout Standard
9156
9157
9158 \backslash
9159 /
9160 \end_layout
9161
9162 \end_inset
9163
9164 -opt-code-size
9165 \begin_inset LatexCommand \index{-\/-opt-code-size}
9166
9167 \end_inset
9168
9169
9170 \series default
9171  The compiler will optimize code generation towards compact code, possibly
9172  at the expense of code speed.
9173 \end_layout
9174
9175 \begin_layout Standard
9176 \begin_inset VSpace bigskip
9177 \end_inset
9178
9179
9180 \end_layout
9181
9182 \begin_layout Subsection
9183 Other Options
9184 \begin_inset LatexCommand \index{Options other}
9185
9186 \end_inset
9187
9188
9189 \end_layout
9190
9191 \begin_layout List
9192 \labelwidthstring 00.00.0000
9193
9194 \series bold
9195 -c\InsetSpace ~
9196 -
9197 \begin_inset ERT
9198 status collapsed
9199
9200 \begin_layout Standard
9201
9202
9203 \backslash
9204 /
9205 \end_layout
9206
9207 \end_inset
9208
9209 -compile-only
9210 \begin_inset LatexCommand \index{-\/-compile-only}
9211
9212 \end_inset
9213
9214
9215 \begin_inset LatexCommand \index{-c -\/-compile-only}
9216
9217 \end_inset
9218
9219
9220 \series default
9221  will compile and assemble the source, but will not call the linkage editor.
9222 \end_layout
9223
9224 \begin_layout List
9225 \labelwidthstring 00.00.0000
9226
9227 \series bold
9228 -
9229 \series default
9230
9231 \begin_inset ERT
9232 status collapsed
9233
9234 \begin_layout Standard
9235
9236
9237 \backslash
9238 /
9239 \end_layout
9240
9241 \end_inset
9242
9243
9244 \series bold
9245 -c1mode
9246 \begin_inset LatexCommand \index{-\/-c1mode}
9247
9248 \end_inset
9249
9250
9251 \series default
9252  reads the preprocessed source from standard input and compiles it.
9253  The file name for the assembler output must be specified using the -o option.
9254 \end_layout
9255
9256 \begin_layout List
9257 \labelwidthstring 00.00.0000
9258
9259 \series bold
9260 -E
9261 \begin_inset LatexCommand \index{-E}
9262
9263 \end_inset
9264
9265
9266 \series default
9267  Run only the C preprocessor.
9268  Preprocess all the C source files specified and output the results to standard
9269  output.
9270 \end_layout
9271
9272 \begin_layout List
9273 \labelwidthstring 00.00.0000
9274
9275 \series bold
9276 -o\InsetSpace ~
9277 <path/file>
9278 \begin_inset LatexCommand \index{-o <path/file>}
9279
9280 \end_inset
9281
9282  
9283 \series default
9284 The output path where everything will be placed or the file name used for
9285  all generated output files.
9286  If the parameter is a path, it must have a trailing slash (or backslash
9287  for the Windows binaries) to be recognized as a path.
9288
9289 \emph on
9290  
9291 \emph default
9292 Note for Windows users: if the path contains spaces, it should be surrounded
9293  by quotes.
9294  The trailing backslash should be doubled in order to prevent escaping the
9295  final quote, for example: 
9296 \emph on
9297 -o 
9298 \begin_inset Quotes sld
9299 \end_inset
9300
9301 F:
9302 \backslash
9303 Projects
9304 \backslash
9305 test3
9306 \backslash
9307 output 1
9308 \backslash
9309
9310 \backslash
9311
9312 \begin_inset Quotes srd
9313 \end_inset
9314
9315
9316 \emph default
9317  or put after the final quote, for example: 
9318 \emph on
9319 -o 
9320 \begin_inset Quotes sld
9321 \end_inset
9322
9323 F:
9324 \backslash
9325 Projects
9326 \backslash
9327 test3
9328 \backslash
9329 output 1
9330 \begin_inset Quotes srd
9331 \end_inset
9332
9333
9334 \backslash
9335
9336 \emph default
9337 .
9338  The path using slashes for directory delimiters can be used too, for example:
9339  
9340 \emph on
9341 -o 
9342 \begin_inset Quotes sld
9343 \end_inset
9344
9345 F:/Projects/test3/output 1/
9346 \begin_inset Quotes srd
9347 \end_inset
9348
9349
9350 \emph default
9351 .
9352 \end_layout
9353
9354 \begin_layout List
9355 \labelwidthstring 00.00.0000
9356
9357 \series bold
9358 -
9359 \begin_inset ERT
9360 status collapsed
9361
9362 \begin_layout Standard
9363
9364
9365 \backslash
9366 /
9367 \end_layout
9368
9369 \end_inset
9370
9371 -stack-auto
9372 \begin_inset LatexCommand \index{-\/-stack-auto}
9373
9374 \end_inset
9375
9376
9377 \series default
9378 \size large
9379 \emph on
9380  
9381 \size default
9382 \emph default
9383 All functions in the source file will be compiled as 
9384 \emph on
9385 reentrant
9386 \emph default
9387
9388 \begin_inset LatexCommand \index{reentrant}
9389
9390 \end_inset
9391
9392 , i.e.
9393  the parameters and local variables will be allocated on the stack
9394 \begin_inset LatexCommand \index{stack}
9395
9396 \end_inset
9397
9398 .
9399  See section 
9400 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9401
9402 \end_inset
9403
9404  Parameters and Local Variables for more details.
9405  If this option is used all source files in the project should be compiled
9406  with this option.
9407  It automatically implies --int-long-reent and --float-reent.
9408  
9409 \end_layout
9410
9411 \begin_layout List
9412 \labelwidthstring 00.00.0000
9413
9414 \series bold
9415 -
9416 \begin_inset ERT
9417 status collapsed
9418
9419 \begin_layout Standard
9420
9421
9422 \backslash
9423 /
9424 \end_layout
9425
9426 \end_inset
9427
9428 -callee-saves
9429 \begin_inset LatexCommand \index{-\/-callee-saves}
9430
9431 \end_inset
9432
9433  
9434 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9435
9436 \end_inset
9437
9438 function1[,function2][,function3]....
9439
9440 \series default
9441  The compiler by default uses a caller saves convention for register saving
9442  across function calls, however this can cause unnecessary register pushing
9443  and popping when calling small functions from larger functions.
9444  This option can be used to switch the register saving convention for the
9445  function names specified.
9446  The compiler will not save registers when calling these functions, no extra
9447  code will be generated at the entry and exit (function prologue
9448 \series bold
9449
9450 \begin_inset LatexCommand \index{function prologue}
9451
9452 \end_inset
9453
9454
9455 \series default
9456  and epilogue
9457 \series bold
9458
9459 \begin_inset LatexCommand \index{function epilogue}
9460
9461 \end_inset
9462
9463
9464 \series default
9465 ) for these functions to save and restore the registers used by these functions,
9466  this can SUBSTANTIALLY reduce code and improve run time performance of
9467  the generated code.
9468  In the future the compiler (with inter procedural analysis) will be able
9469  to determine the appropriate scheme to use for each function call.
9470  DO NOT use this option for built-in functions such as _mulint..., if this
9471  option is used for a library function the appropriate library function
9472  needs to be recompiled with the same option.
9473  If the project consists of multiple source files then all the source file
9474  should be compiled with the same -
9475 \begin_inset ERT
9476 status collapsed
9477
9478 \begin_layout Standard
9479
9480
9481 \backslash
9482 /
9483 \end_layout
9484
9485 \end_inset
9486
9487 -callee-saves option string.
9488  Also see #pragma\InsetSpace ~
9489 callee_saves 
9490 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9491
9492 \end_inset
9493
9494  
9495 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9496
9497 \end_inset
9498
9499 .
9500 \end_layout
9501
9502 \begin_layout List
9503 \labelwidthstring 00.00.0000
9504
9505 \series bold
9506 -
9507 \begin_inset ERT
9508 status collapsed
9509
9510 \begin_layout Standard
9511
9512
9513 \backslash
9514 /
9515 \end_layout
9516
9517 \end_inset
9518
9519 -all-callee-saves
9520 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9521
9522 \end_inset
9523
9524  
9525 \series default
9526 Function of
9527 \series bold
9528  
9529 \series default
9530 -
9531 \begin_inset ERT
9532 status collapsed
9533
9534 \begin_layout Standard
9535
9536
9537 \backslash
9538 /
9539 \end_layout
9540
9541 \end_inset
9542
9543 -callee-saves will be applied to all functions by default.
9544 \end_layout
9545
9546 \begin_layout List
9547 \labelwidthstring 00.00.0000
9548
9549 \series bold
9550 -
9551 \begin_inset ERT
9552 status collapsed
9553
9554 \begin_layout Standard
9555
9556
9557 \backslash
9558 /
9559 \end_layout
9560
9561 \end_inset
9562
9563 -debug
9564 \begin_inset LatexCommand \index{-\/-debug}
9565
9566 \end_inset
9567
9568
9569 \bar under
9570  
9571 \series default
9572 \bar default
9573 When this option is used the compiler will generate debug information.
9574  The debug information collected in a file with .cdb extension can be used
9575  with the SDCDB.
9576  For more information see documentation for SDCDB.
9577  Another file with no extension contains debug information in AOMF or AOMF51
9578 \begin_inset LatexCommand \index{AOMF, AOMF51}
9579
9580 \end_inset
9581
9582  format which is commonly used by third party tools.
9583 \end_layout
9584
9585 \begin_layout List
9586 \labelwidthstring 00.00.0000
9587
9588 \series bold
9589 -S
9590 \begin_inset LatexCommand \index{-S}
9591
9592 \end_inset
9593
9594
9595 \size large
9596 \bar under
9597  
9598 \series default
9599 \size default
9600 \bar default
9601 Stop after the stage of compilation proper; do not assemble.
9602  The output is an assembler code file for the input file specified.
9603 \end_layout
9604
9605 \begin_layout List
9606 \labelwidthstring 00.00.0000
9607
9608 \series bold
9609 -
9610 \begin_inset ERT
9611 status collapsed
9612
9613 \begin_layout Standard
9614
9615
9616 \backslash
9617 /
9618 \end_layout
9619
9620 \end_inset
9621
9622 -int-long-reent
9623 \begin_inset LatexCommand \index{-\/-int-long-reent}
9624
9625 \end_inset
9626
9627
9628 \series default
9629  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9630  Note by default these libraries are compiled as non-reentrant.
9631  See section Installation for more details.
9632 \end_layout
9633
9634 \begin_layout List
9635 \labelwidthstring 00.00.0000
9636
9637 \series bold
9638 -
9639 \begin_inset ERT
9640 status collapsed
9641
9642 \begin_layout Standard
9643
9644
9645 \backslash
9646 /
9647 \end_layout
9648
9649 \end_inset
9650
9651 -cyclomatic
9652 \begin_inset LatexCommand \index{-\/-cyclomatic}
9653
9654 \end_inset
9655
9656
9657 \bar under
9658  
9659 \series default
9660 \bar default
9661 This option will cause the compiler to generate an information message for
9662  each function in the source file.
9663  The message contains some 
9664 \emph on
9665 important
9666 \emph default
9667  information about the function.
9668  The number of edges and nodes the compiler detected in the control flow
9669  graph of the function, and most importantly the 
9670 \emph on
9671 cyclomatic complexity
9672 \begin_inset LatexCommand \index{Cyclomatic complexity}
9673
9674 \end_inset
9675
9676
9677 \emph default
9678  see section on Cyclomatic Complexity for more details.
9679 \end_layout
9680
9681 \begin_layout List
9682 \labelwidthstring 00.00.0000
9683
9684 \series bold
9685 -
9686 \begin_inset ERT
9687 status collapsed
9688
9689 \begin_layout Standard
9690
9691
9692 \backslash
9693 /
9694 \end_layout
9695
9696 \end_inset
9697
9698 -float-reent
9699 \begin_inset LatexCommand \index{-\/-float-reent}
9700
9701 \end_inset
9702
9703
9704 \series default
9705  Floating point library is compiled as reentrant
9706 \begin_inset LatexCommand \index{reentrant}
9707
9708 \end_inset
9709
9710 .
9711  See section Installation for more details.
9712 \end_layout
9713
9714 \begin_layout List
9715 \labelwidthstring 00.00.0000
9716
9717 \series bold
9718 -
9719 \begin_inset ERT
9720 status collapsed
9721
9722 \begin_layout Standard
9723
9724
9725 \backslash
9726 /
9727 \end_layout
9728
9729 \end_inset
9730
9731 -funsigned-char
9732 \begin_inset LatexCommand \index{-\/-funsigned-char}
9733
9734 \end_inset
9735
9736
9737 \series default
9738  The default signedness for every type is
9739 \family typewriter
9740  signed
9741 \family default
9742 .
9743  In some embedded environments the default signedness of
9744 \family typewriter
9745  char
9746 \family default
9747  is
9748 \family typewriter
9749  unsigned
9750 \family default
9751 .
9752  To set the signess for characters to unsigned, use the option --funsigned-char.
9753  If this option is set and no signedness keyword (unsigned/signed) is given,
9754  a char will be signed.
9755  All other types are unaffected.
9756 \end_layout
9757
9758 \begin_layout List
9759 \labelwidthstring 00.00.0000
9760
9761 \series bold
9762 -
9763 \begin_inset ERT
9764 status collapsed
9765
9766 \begin_layout Standard
9767
9768
9769 \backslash
9770 /
9771 \end_layout
9772
9773 \end_inset
9774
9775 -main-return
9776 \begin_inset LatexCommand \index{-\/-main-return}
9777
9778 \end_inset
9779
9780
9781 \series default
9782  This option can be used if the code generated is called by a monitor program
9783  or if the main routine includes an endless loop.
9784  This option results in slightly smaller code and saves two bytes of stack
9785  space.
9786  The return from the 'main'
9787 \begin_inset LatexCommand \index{main return}
9788
9789 \end_inset
9790
9791  function will return to the function calling main.
9792  The default setting is to lock up i.e.
9793  generate a '
9794 \family typewriter
9795 sjmp .
9796 \family default
9797 '.
9798 \end_layout
9799
9800 \begin_layout List
9801 \labelwidthstring 00.00.0000
9802
9803 \series bold
9804 -
9805 \begin_inset ERT
9806 status collapsed
9807
9808 \begin_layout Standard
9809
9810
9811 \backslash
9812 /
9813 \end_layout
9814
9815 \end_inset
9816
9817 -nostdinc
9818 \begin_inset LatexCommand \index{-\/-nostdinc}
9819
9820 \end_inset
9821
9822
9823 \series default
9824  This will prevent the compiler from passing on the default include path
9825  to the preprocessor.
9826 \end_layout
9827
9828 \begin_layout List
9829 \labelwidthstring 00.00.0000
9830
9831 \series bold
9832 -
9833 \begin_inset ERT
9834 status collapsed
9835
9836 \begin_layout Standard
9837
9838
9839 \backslash
9840 /
9841 \end_layout
9842
9843 \end_inset
9844
9845 -nostdlib
9846 \begin_inset LatexCommand \index{-\/-nostdlib}
9847
9848 \end_inset
9849
9850
9851 \series default
9852  This will prevent the compiler from passing on the default library
9853 \begin_inset LatexCommand \index{Libraries}
9854
9855 \end_inset
9856
9857  path to the linker.
9858 \end_layout
9859
9860 \begin_layout List
9861 \labelwidthstring 00.00.0000
9862
9863 \series bold
9864 -
9865 \begin_inset ERT
9866 status collapsed
9867
9868 \begin_layout Standard
9869
9870
9871 \backslash
9872 /
9873 \end_layout
9874
9875 \end_inset
9876
9877 -verbose
9878 \begin_inset LatexCommand \index{-\/-verbose}
9879
9880 \end_inset
9881
9882
9883 \series default
9884  Shows the various actions the compiler is performing.
9885 \end_layout
9886
9887 \begin_layout List
9888 \labelwidthstring 00.00.0000
9889
9890 \series bold
9891 -V
9892 \begin_inset LatexCommand \index{-V}
9893
9894 \end_inset
9895
9896
9897 \series default
9898  Shows the actual commands the compiler is executing.
9899 \end_layout
9900
9901 \begin_layout List
9902 \labelwidthstring 00.00.0000
9903
9904 \series bold
9905 -
9906 \begin_inset ERT
9907 status collapsed
9908
9909 \begin_layout Standard
9910
9911
9912 \backslash
9913 /
9914 \end_layout
9915
9916 \end_inset
9917
9918 -no-c-code-in-asm
9919 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9920
9921 \end_inset
9922
9923
9924 \series default
9925  Hides your ugly and inefficient c-code from the asm file, so you can always
9926  blame the compiler :)
9927 \end_layout
9928
9929 \begin_layout List
9930 \labelwidthstring 00.00.0000
9931
9932 \series bold
9933 -
9934 \begin_inset ERT
9935 status collapsed
9936
9937 \begin_layout Standard
9938
9939
9940 \backslash
9941 /
9942 \end_layout
9943
9944 \end_inset
9945
9946 -fverbose-asm
9947 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9948
9949 \end_inset
9950
9951
9952 \series default
9953  Include code generator and peep-hole comments in the generated asm files.
9954 \end_layout
9955
9956 \begin_layout List
9957 \labelwidthstring 00.00.0000
9958
9959 \series bold
9960 -
9961 \begin_inset ERT
9962 status collapsed
9963
9964 \begin_layout Standard
9965
9966
9967 \backslash
9968 /
9969 \end_layout
9970
9971 \end_inset
9972
9973 -no-peep-comments
9974 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9975
9976 \end_inset
9977
9978
9979 \series default
9980  Don't include peep-hole comments in the generated asm files even if --fverbose-
9981 asm option is specified.
9982 \end_layout
9983
9984 \begin_layout List
9985 \labelwidthstring 00.00.0000
9986
9987 \series bold
9988 -
9989 \begin_inset ERT
9990 status collapsed
9991
9992 \begin_layout Standard
9993
9994
9995 \backslash
9996 /
9997 \end_layout
9998
9999 \end_inset
10000
10001 -i-code-in-asm
10002 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10003
10004 \end_inset
10005
10006
10007 \series default
10008  Include i-codes in the asm file.
10009  Sounds like noise but is most helpful for debugging the compiler itself.
10010 \end_layout
10011
10012 \begin_layout List
10013 \labelwidthstring 00.00.0000
10014
10015 \series bold
10016 -
10017 \begin_inset ERT
10018 status collapsed
10019
10020 \begin_layout Standard
10021
10022
10023 \backslash
10024 /
10025 \end_layout
10026
10027 \end_inset
10028
10029 -less-pedantic
10030 \begin_inset LatexCommand \index{pedantic}
10031
10032 \end_inset
10033
10034
10035 \begin_inset LatexCommand \index{-\/-less-pedantic}
10036
10037 \end_inset
10038
10039
10040 \series default
10041
10042 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10043
10044 \end_inset
10045
10046  Disable some of the more pedantic warnings
10047 \begin_inset LatexCommand \index{Warnings}
10048
10049 \end_inset
10050
10051 .
10052  For more details, see the less_pedantic pragma 
10053 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10054
10055 \end_inset
10056
10057 .
10058 \end_layout
10059
10060 \begin_layout List
10061 \labelwidthstring 00.00.0000
10062
10063 \series bold
10064 -
10065 \begin_inset ERT
10066 status collapsed
10067
10068 \begin_layout Standard
10069
10070
10071 \backslash
10072 /
10073 \end_layout
10074
10075 \end_inset
10076
10077 -disable-warning\InsetSpace ~
10078 <nnnn>
10079 \begin_inset LatexCommand \index{-\/-disable-warning}
10080
10081 \end_inset
10082
10083
10084 \series default
10085  Disable specific warning with number <nnnn>.
10086 \end_layout
10087
10088 \begin_layout List
10089 \labelwidthstring 00.00.0000
10090
10091 \series bold
10092 -
10093 \begin_inset ERT
10094 status collapsed
10095
10096 \begin_layout Standard
10097
10098
10099 \backslash
10100 /
10101 \end_layout
10102
10103 \end_inset
10104
10105 -print-search-dirs
10106 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10107
10108 \end_inset
10109
10110
10111 \series default
10112  Display the directories in the compiler's search path
10113 \end_layout
10114
10115 \begin_layout List
10116 \labelwidthstring 00.00.0000
10117
10118 \series bold
10119 -
10120 \begin_inset ERT
10121 status collapsed
10122
10123 \begin_layout Standard
10124
10125
10126 \backslash
10127 /
10128 \end_layout
10129
10130 \end_inset
10131
10132 -vc
10133 \begin_inset LatexCommand \index{-\/-vc}
10134
10135 \end_inset
10136
10137
10138 \series default
10139  Display errors and warnings using MSVC style, so you can use SDCC with
10140  the visual studio IDE
10141 \begin_inset LatexCommand \index{IDE}
10142
10143 \end_inset
10144
10145 .
10146  With SDCC both offering a GCC-like (the default) and a MSVC-like
10147 \begin_inset LatexCommand \index{MSVC output style}
10148
10149 \end_inset
10150
10151  output style, integration into most programming editors should be straightforwa
10152 rd.
10153 \end_layout
10154
10155 \begin_layout List
10156 \labelwidthstring 00.00.0000
10157
10158 \series bold
10159 -
10160 \begin_inset ERT
10161 status collapsed
10162
10163 \begin_layout Standard
10164
10165
10166 \backslash
10167 /
10168 \end_layout
10169
10170 \end_inset
10171
10172 -use-stdout
10173 \begin_inset LatexCommand \index{-\/-use-stdout}
10174
10175 \end_inset
10176
10177
10178 \series default
10179  Send errors and warnings to stdout instead of stderr.
10180 \end_layout
10181
10182 \begin_layout List
10183 \labelwidthstring 00.00.0000
10184
10185 \series bold
10186 -Wa\InsetSpace ~
10187 asmOption[,asmOption]
10188 \series default
10189
10190 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10191
10192 \end_inset
10193
10194 ...
10195  Pass the asmOption to the assembler
10196 \begin_inset LatexCommand \index{Options assembler}
10197
10198 \end_inset
10199
10200
10201 \begin_inset LatexCommand \index{Assembler options}
10202
10203 \end_inset
10204
10205 .
10206  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10207 \end_layout
10208
10209 \begin_layout List
10210 \labelwidthstring 00.00.0000
10211
10212 \series bold
10213 -
10214 \begin_inset ERT
10215 status collapsed
10216
10217 \begin_layout Standard
10218
10219
10220 \backslash
10221 /
10222 \end_layout
10223
10224 \end_inset
10225
10226 -std-sdcc89
10227 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10228
10229 \end_inset
10230
10231
10232 \series default
10233  Generally follow the C89 standard, but allow SDCC features that conflict
10234  with the standard (default).
10235 \end_layout
10236
10237 \begin_layout List
10238 \labelwidthstring 00.00.0000
10239
10240 \series bold
10241 -
10242 \begin_inset ERT
10243 status collapsed
10244
10245 \begin_layout Standard
10246
10247
10248 \backslash
10249 /
10250 \end_layout
10251
10252 \end_inset
10253
10254 -std-c89
10255 \begin_inset LatexCommand \index{-\/-std-c89}
10256
10257 \end_inset
10258
10259
10260 \series default
10261  Follow the C89 standard and disable SDCC features that conflict with the
10262  standard.
10263 \end_layout
10264
10265 \begin_layout List
10266 \labelwidthstring 00.00.0000
10267
10268 \series bold
10269 -
10270 \begin_inset ERT
10271 status collapsed
10272
10273 \begin_layout Standard
10274
10275
10276 \backslash
10277 /
10278 \end_layout
10279
10280 \end_inset
10281
10282 -std-sdcc99
10283 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10284
10285 \end_inset
10286
10287
10288 \series default
10289  Generally follow the C99 standard, but allow SDCC features that conflict
10290  with the standard (incomplete support).
10291 \end_layout
10292
10293 \begin_layout List
10294 \labelwidthstring 00.00.0000
10295
10296 \series bold
10297 -
10298 \begin_inset ERT
10299 status collapsed
10300
10301 \begin_layout Standard
10302
10303
10304 \backslash
10305 /
10306 \end_layout
10307
10308 \end_inset
10309
10310 -std-c99
10311 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10312
10313 \end_inset
10314
10315
10316 \series default
10317  Follow the C99 standard and disable SDCC features that conflict with the
10318  standard (incomplete support).
10319 \end_layout
10320
10321 \begin_layout List
10322 \labelwidthstring 00.00.0000
10323
10324 \series bold
10325 -
10326 \begin_inset ERT
10327 status collapsed
10328
10329 \begin_layout Standard
10330
10331
10332 \backslash
10333 /
10334 \end_layout
10335
10336 \end_inset
10337
10338 -codeseg
10339 \series default
10340
10341 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10342
10343 \end_inset
10344
10345 \InsetSpace ~
10346 <Name> The name to be used for the code
10347 \begin_inset LatexCommand \index{code}
10348
10349 \end_inset
10350
10351  segment, default CSEG.
10352  This is useful if you need to tell the compiler to put the code in a special
10353  segment so you can later on tell the linker to put this segment in a special
10354  place in memory.
10355  Can be used for instance when using bank switching to put the code in a
10356  bank.
10357 \end_layout
10358
10359 \begin_layout List
10360 \labelwidthstring 00.00.0000
10361
10362 \series bold
10363 -
10364 \begin_inset ERT
10365 status collapsed
10366
10367 \begin_layout Standard
10368
10369
10370 \backslash
10371 /
10372 \end_layout
10373
10374 \end_inset
10375
10376 -constseg
10377 \series default
10378
10379 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10380
10381 \end_inset
10382
10383 \InsetSpace ~
10384 <Name> The name to be used for the const
10385 \begin_inset LatexCommand \index{const}
10386
10387 \end_inset
10388
10389  segment, default CONST.
10390  This is useful if you need to tell the compiler to put the const data in
10391  a special segment so you can later on tell the linker to put this segment
10392  in a special place in memory.
10393  Can be used for instance when using bank switching to put the const data
10394  in a bank.
10395 \end_layout
10396
10397 \begin_layout List
10398 \labelwidthstring 00.00.0000
10399
10400 \series bold
10401 -
10402 \begin_inset ERT
10403 status collapsed
10404
10405 \begin_layout Standard
10406
10407
10408 \backslash
10409 /
10410 \end_layout
10411
10412 \end_inset
10413
10414 -fdollars-in-identifiers
10415 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10416
10417 \end_inset
10418
10419
10420 \series default
10421  Permit '$' as an identifier character.
10422 \end_layout
10423
10424 \begin_layout List
10425 \labelwidthstring 00.00.0000
10426
10427 \series bold
10428 -
10429 \begin_inset ERT
10430 status collapsed
10431
10432 \begin_layout Standard
10433
10434
10435 \backslash
10436 /
10437 \end_layout
10438
10439 \end_inset
10440
10441 -more-pedantic
10442 \series default
10443
10444 \begin_inset LatexCommand \index{-\/-more-pedantic}
10445
10446 \end_inset
10447
10448
10449 \begin_inset LatexCommand \index{pedantic}
10450
10451 \end_inset
10452
10453  Actually this is 
10454 \series bold
10455 \emph on
10456 not
10457 \series default
10458 \emph default
10459  a SDCC compiler option but if you want 
10460 \emph on
10461 more
10462 \emph default
10463  warnings you can use a separate tool dedicated to syntax checking like
10464  splint
10465 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10466
10467 \end_inset
10468
10469
10470 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10471
10472 \end_inset
10473
10474  
10475 \begin_inset LatexCommand \url{http://www.splint.org}
10476
10477 \end_inset
10478
10479 .
10480  To make your source files parseable by splint you will have to include
10481  
10482 \family sans
10483 lint.h
10484 \family default
10485
10486 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10487
10488 \end_inset
10489
10490  in your source file and add brackets around extended keywords (like 
10491 \family sans
10492
10493 \begin_inset Quotes sld
10494 \end_inset
10495
10496 __at\InsetSpace ~
10497
10498 \series bold
10499 (
10500 \series default
10501 0xab
10502 \series bold
10503 )
10504 \series default
10505
10506 \begin_inset Quotes srd
10507 \end_inset
10508
10509
10510 \family default
10511  and 
10512 \family sans
10513
10514 \begin_inset Quotes sld
10515 \end_inset
10516
10517 __interrupt\InsetSpace ~
10518 (2)
10519 \begin_inset Quotes srd
10520 \end_inset
10521
10522
10523 \family default
10524 ).
10525  
10526 \newline
10527 Splint has an excellent on line manual at 
10528 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10529
10530 \end_inset
10531
10532  and it's capabilities go beyond pure syntax checking.
10533  You'll need to tell splint the location of SDCC's include files so a typical
10534  command line could look like this: 
10535 \newline
10536
10537 \family sans
10538 splint\InsetSpace ~
10539 -I\InsetSpace ~
10540 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10541 \InsetSpace ~
10542 myprogram.c
10543 \end_layout
10544
10545 \begin_layout List
10546 \labelwidthstring 00.00.0000
10547
10548 \series bold
10549 -
10550 \begin_inset ERT
10551 status collapsed
10552
10553 \begin_layout Standard
10554
10555
10556 \backslash
10557 /
10558 \end_layout
10559
10560 \end_inset
10561
10562 -short-is-8bits
10563 \series default
10564
10565 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10566
10567 \end_inset
10568
10569
10570 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10571
10572 \end_inset
10573
10574  Treat short as 8-bit (for backward compatibility with older versions of
10575  compiler - see section 
10576 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10577
10578 \end_inset
10579
10580 )
10581 \end_layout
10582
10583 \begin_layout Standard
10584 \begin_inset VSpace bigskip
10585 \end_inset
10586
10587
10588 \end_layout
10589
10590 \begin_layout Subsection
10591 Intermediate Dump Options
10592 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10593
10594 \end_inset
10595
10596
10597 \begin_inset LatexCommand \index{Options intermediate dump}
10598
10599 \end_inset
10600
10601
10602 \begin_inset LatexCommand \index{Intermediate dump options}
10603
10604 \end_inset
10605
10606
10607 \end_layout
10608
10609 \begin_layout Standard
10610 The following options are provided for the purpose of retargetting and debugging
10611  the compiler.
10612  They provide a means to dump the intermediate code (iCode
10613 \begin_inset LatexCommand \index{iCode}
10614
10615 \end_inset
10616
10617 ) generated by the compiler in human readable form at various stages of
10618  the compilation process.
10619  More on iCodes see chapter 
10620 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10621
10622 \end_inset
10623
10624  
10625 \begin_inset Quotes srd
10626 \end_inset
10627
10628 The anatomy of the compiler
10629 \begin_inset Quotes srd
10630 \end_inset
10631
10632 .
10633 \end_layout
10634
10635 \begin_layout List
10636 \labelwidthstring 00.00.0000
10637
10638 \series bold
10639 -
10640 \begin_inset ERT
10641 status collapsed
10642
10643 \begin_layout Standard
10644
10645
10646 \backslash
10647 /
10648 \end_layout
10649
10650 \end_inset
10651
10652 -dumpraw
10653 \begin_inset LatexCommand \index{-\/-dumpraw}
10654
10655 \end_inset
10656
10657
10658 \series default
10659  This option will cause the compiler to dump the intermediate code into
10660  a file of named 
10661 \emph on
10662 <source filename>.dumpraw
10663 \emph default
10664  just after the intermediate code has been generated for a function, i.e.
10665  before any optimizations are done.
10666  The basic blocks
10667 \begin_inset LatexCommand \index{Basic blocks}
10668
10669 \end_inset
10670
10671  at this stage ordered in the depth first number, so they may not be in
10672  sequence of execution.
10673 \end_layout
10674
10675 \begin_layout List
10676 \labelwidthstring 00.00.0000
10677
10678 \series bold
10679 -
10680 \begin_inset ERT
10681 status collapsed
10682
10683 \begin_layout Standard
10684
10685
10686 \backslash
10687 /
10688 \end_layout
10689
10690 \end_inset
10691
10692 -dumpgcse
10693 \begin_inset LatexCommand \index{-\/-dumpgcse}
10694
10695 \end_inset
10696
10697
10698 \series default
10699  Will create a dump of iCode's, after global subexpression elimination
10700 \begin_inset LatexCommand \index{Global subexpression elimination}
10701
10702 \end_inset
10703
10704 , into a file named 
10705 \emph on
10706 <source filename>.dumpgcse.
10707 \end_layout
10708
10709 \begin_layout List
10710 \labelwidthstring 00.00.0000
10711
10712 \series bold
10713 -
10714 \begin_inset ERT
10715 status collapsed
10716
10717 \begin_layout Standard
10718
10719
10720 \backslash
10721 /
10722 \end_layout
10723
10724 \end_inset
10725
10726 -dumpdeadcode
10727 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10728
10729 \end_inset
10730
10731
10732 \series default
10733  Will create a dump of iCode's, after deadcode elimination
10734 \begin_inset LatexCommand \index{Dead-code elimination}
10735
10736 \end_inset
10737
10738 , into a file named 
10739 \emph on
10740 <source filename>.dumpdeadcode.
10741 \end_layout
10742
10743 \begin_layout List
10744 \labelwidthstring 00.00.0000
10745
10746 \series bold
10747 -
10748 \begin_inset ERT
10749 status collapsed
10750
10751 \begin_layout Standard
10752
10753
10754 \backslash
10755 /
10756 \end_layout
10757
10758 \end_inset
10759
10760 -dumploop
10761 \begin_inset LatexCommand \index{-\/-dumploop}
10762
10763 \end_inset
10764
10765
10766 \series default
10767 \size large
10768  
10769 \size default
10770 Will create a dump of iCode's, after loop optimizations
10771 \begin_inset LatexCommand \index{Loop optimization}
10772
10773 \end_inset
10774
10775 , into a file named 
10776 \emph on
10777 <source filename>.dumploop.
10778 \end_layout
10779
10780 \begin_layout List
10781 \labelwidthstring 00.00.0000
10782
10783 \series bold
10784 -
10785 \begin_inset ERT
10786 status collapsed
10787
10788 \begin_layout Standard
10789
10790
10791 \backslash
10792 /
10793 \end_layout
10794
10795 \end_inset
10796
10797 -dumprange
10798 \begin_inset LatexCommand \index{-\/-dumprange}
10799
10800 \end_inset
10801
10802
10803 \series default
10804 \size large
10805  
10806 \size default
10807 Will create a dump of iCode's, after live range analysis
10808 \begin_inset LatexCommand \index{Live range analysis}
10809
10810 \end_inset
10811
10812 , into a file named 
10813 \emph on
10814 <source filename>.dumprange.
10815 \end_layout
10816
10817 \begin_layout List
10818 \labelwidthstring 00.00.0000
10819
10820 \series bold
10821 -
10822 \begin_inset ERT
10823 status collapsed
10824
10825 \begin_layout Standard
10826
10827
10828 \backslash
10829 /
10830 \end_layout
10831
10832 \end_inset
10833
10834 -dumlrange
10835 \begin_inset LatexCommand \index{-\/-dumlrange}
10836
10837 \end_inset
10838
10839
10840 \series default
10841  Will dump the life ranges
10842 \begin_inset LatexCommand \index{Live range analysis}
10843
10844 \end_inset
10845
10846  for all symbols.
10847 \end_layout
10848
10849 \begin_layout List
10850 \labelwidthstring 00.00.0000
10851
10852 \series bold
10853 -
10854 \begin_inset ERT
10855 status collapsed
10856
10857 \begin_layout Standard
10858
10859
10860 \backslash
10861 /
10862 \end_layout
10863
10864 \end_inset
10865
10866 -dumpregassign
10867 \begin_inset LatexCommand \index{-\/-dumpregassign}
10868
10869 \end_inset
10870
10871
10872 \bar under
10873  
10874 \series default
10875 \bar default
10876 Will create a dump of iCode's, after register assignment
10877 \begin_inset LatexCommand \index{Register assignment}
10878
10879 \end_inset
10880
10881 , into a file named 
10882 \emph on
10883 <source filename>.dumprassgn.
10884 \end_layout
10885
10886 \begin_layout List
10887 \labelwidthstring 00.00.0000
10888
10889 \series bold
10890 -
10891 \begin_inset ERT
10892 status collapsed
10893
10894 \begin_layout Standard
10895
10896
10897 \backslash
10898 /
10899 \end_layout
10900
10901 \end_inset
10902
10903 -dumplrange
10904 \begin_inset LatexCommand \index{-\/-dumplrange}
10905
10906 \end_inset
10907
10908
10909 \series default
10910  Will create a dump of the live ranges of iTemp's
10911 \end_layout
10912
10913 \begin_layout List
10914 \labelwidthstring 00.00.0000
10915
10916 \series bold
10917 -
10918 \begin_inset ERT
10919 status collapsed
10920
10921 \begin_layout Standard
10922
10923
10924 \backslash
10925 /
10926 \end_layout
10927
10928 \end_inset
10929
10930 -dumpall
10931 \begin_inset LatexCommand \index{-\/-dumpall}
10932
10933 \end_inset
10934
10935
10936 \size large
10937 \bar under
10938  
10939 \series default
10940 \size default
10941 \bar default
10942 Will cause all the above mentioned dumps to be created.
10943 \end_layout
10944
10945 \begin_layout Standard
10946 \begin_inset VSpace bigskip
10947 \end_inset
10948
10949
10950 \end_layout
10951
10952 \begin_layout Subsection
10953 Redirecting output on Windows Shells
10954 \end_layout
10955
10956 \begin_layout Standard
10957 By default SDCC writes it's error messages to 
10958 \begin_inset Quotes sld
10959 \end_inset
10960
10961 standard error
10962 \begin_inset Quotes srd
10963 \end_inset
10964
10965 .
10966  To force all messages to 
10967 \begin_inset Quotes sld
10968 \end_inset
10969
10970 standard output
10971 \begin_inset Quotes srd
10972 \end_inset
10973
10974  use 
10975 \series bold
10976 -
10977 \series default
10978 \emph on
10979
10980 \begin_inset ERT
10981 status collapsed
10982
10983 \begin_layout Standard
10984
10985
10986 \backslash
10987 /
10988 \end_layout
10989
10990 \end_inset
10991
10992
10993 \series bold
10994 \emph default
10995 -
10996 \series default
10997 use-stdout
10998 \begin_inset LatexCommand \index{-\/-use-stdout}
10999
11000 \end_inset
11001
11002 .
11003  Additionally, if you happen to have visual studio installed in your windows
11004  machine, you can use it to compile your sources using a custom build and
11005  the SDCC -
11006 \emph on
11007
11008 \begin_inset ERT
11009 status collapsed
11010
11011 \begin_layout Standard
11012
11013
11014 \backslash
11015 /
11016 \end_layout
11017
11018 \end_inset
11019
11020
11021 \emph default
11022 -vc
11023 \begin_inset LatexCommand \index{-\/-vc}
11024
11025 \end_inset
11026
11027  option.
11028  Something like this should work:
11029 \newline
11030
11031 \newline
11032
11033 \series bold
11034 c:
11035 \backslash
11036 sdcc
11037 \backslash
11038 bin
11039 \backslash
11040 sdcc.exe -
11041 \series default
11042 \emph on
11043
11044 \begin_inset ERT
11045 status collapsed
11046
11047 \begin_layout Standard
11048
11049
11050 \backslash
11051 /
11052 \end_layout
11053
11054 \end_inset
11055
11056
11057 \series bold
11058 \emph default
11059 -vc -
11060 \series default
11061 \emph on
11062
11063 \begin_inset ERT
11064 status collapsed
11065
11066 \begin_layout Standard
11067
11068
11069 \backslash
11070 /
11071 \end_layout
11072
11073 \end_inset
11074
11075
11076 \series bold
11077 \emph default
11078 -model-large -c $(InputPath)
11079 \series default
11080
11081 \begin_inset VSpace bigskip
11082 \end_inset
11083
11084
11085 \end_layout
11086
11087 \begin_layout Section
11088 Environment variables
11089 \begin_inset LatexCommand \index{Environment variables}
11090
11091 \end_inset
11092
11093
11094 \end_layout
11095
11096 \begin_layout Standard
11097 SDCC recognizes the following environment variables:
11098 \end_layout
11099
11100 \begin_layout List
11101 \labelwidthstring 00.00.0000
11102
11103 \series bold
11104 SDCC_LEAVE_SIGNALS
11105 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11106
11107 \end_inset
11108
11109
11110 \series default
11111  SDCC installs a signal handler
11112 \begin_inset LatexCommand \index{signal handler}
11113
11114 \end_inset
11115
11116  to be able to delete temporary files after an user break (^C) or an exception.
11117  If this environment variable is set, SDCC won't install the signal handler
11118  in order to be able to debug SDCC.
11119 \end_layout
11120
11121 \begin_layout List
11122 \labelwidthstring 00.00.0000
11123
11124 \series bold
11125 TMP,\InsetSpace ~
11126 TEMP,\InsetSpace ~
11127 TMPDIR
11128 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11129
11130 \end_inset
11131
11132
11133 \series default
11134  Path, where temporary files will be created.
11135  The order of the variables is the search order.
11136  In a standard *nix environment these variables are not set, and there's
11137  no need to set them.
11138  On Windows it's recommended to set one of them.
11139 \end_layout
11140
11141 \begin_layout List
11142 \labelwidthstring 00.00.0000
11143
11144 \series bold
11145 SDCC_HOME
11146 \begin_inset LatexCommand \index{SDCC\_HOME}
11147
11148 \end_inset
11149
11150
11151 \series default
11152  Path, see section 
11153 \begin_inset LatexCommand \ref{sub:Install-paths}
11154
11155 \end_inset
11156
11157 \InsetSpace ~
11158
11159 \begin_inset Quotes sld
11160 \end_inset
11161
11162  Install Paths
11163 \begin_inset Quotes srd
11164 \end_inset
11165
11166 .
11167 \end_layout
11168
11169 \begin_layout List
11170 \labelwidthstring 00.00.0000
11171
11172 \series bold
11173 SDCC_INCLUDE
11174 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11175
11176 \end_inset
11177
11178
11179 \series default
11180  Path, see section 
11181 \begin_inset LatexCommand \ref{sub:Search-Paths}
11182
11183 \end_inset
11184
11185 \InsetSpace ~
11186
11187 \begin_inset Quotes sld
11188 \end_inset
11189
11190 Search Paths
11191 \begin_inset Quotes srd
11192 \end_inset
11193
11194 .
11195 \end_layout
11196
11197 \begin_layout List
11198 \labelwidthstring 00.00.0000
11199
11200 \series bold
11201 SDCC_LIB
11202 \begin_inset LatexCommand \index{SDCC\_LIB}
11203
11204 \end_inset
11205
11206
11207 \series default
11208  Path, see section 
11209 \begin_inset LatexCommand \ref{sub:Search-Paths}
11210
11211 \end_inset
11212
11213 \InsetSpace ~
11214
11215 \begin_inset Quotes sld
11216 \end_inset
11217
11218 Search Paths
11219 \begin_inset Quotes srd
11220 \end_inset
11221
11222 ..
11223 \end_layout
11224
11225 \begin_layout Standard
11226 There are some more environment variables recognized by SDCC, but these
11227  are solely used for debugging purposes.
11228  They can change or disappear very quickly, and will never be documented.
11229 \begin_inset VSpace bigskip
11230 \end_inset
11231
11232
11233 \end_layout
11234
11235 \begin_layout Section
11236 Storage Class Language Extensions
11237 \end_layout
11238
11239 \begin_layout Subsection
11240 MCS51/DS390 Storage Class
11241 \begin_inset LatexCommand \index{Storage class}
11242
11243 \end_inset
11244
11245  Language Extensions
11246 \end_layout
11247
11248 \begin_layout Standard
11249 In addition to the ANSI storage classes SDCC allows the following MCS51
11250  specific storage classes:
11251 \end_layout
11252
11253 \begin_layout Subsubsection
11254 data
11255 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11256
11257 \end_inset
11258
11259
11260 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11261
11262 \end_inset
11263
11264  / near
11265 \begin_inset LatexCommand \index{near (storage class)}
11266
11267 \end_inset
11268
11269
11270 \begin_inset LatexCommand \index{\_\_near (storage class)}
11271
11272 \end_inset
11273
11274
11275 \end_layout
11276
11277 \begin_layout Standard
11278 This is the 
11279 \series bold
11280 default
11281 \series default
11282  storage class for the Small Memory model (
11283 \emph on
11284 data
11285 \emph default
11286  and 
11287 \emph on
11288 near
11289 \emph default
11290  or the more ANSI-C compliant forms 
11291 \emph on
11292 __data
11293 \emph default
11294  and 
11295 \emph on
11296 __near
11297 \emph default
11298  can be used synonymously).
11299  Variables declared with this storage class will be allocated in the directly
11300  addressable portion of the internal RAM of a 8051, e.g.:
11301 \end_layout
11302
11303 \begin_layout Verse
11304
11305 \family typewriter
11306 __data unsigned char test_data;
11307 \end_layout
11308
11309 \begin_layout Standard
11310 Writing 0x01 to this variable generates the assembly code:
11311 \end_layout
11312
11313 \begin_layout Verse
11314
11315 \family typewriter
11316 75*00 01\InsetSpace ~
11317 \InsetSpace ~
11318 \InsetSpace ~
11319 mov\InsetSpace ~
11320 \InsetSpace ~
11321 _test_data,#0x01
11322 \end_layout
11323
11324 \begin_layout Subsubsection
11325 xdata
11326 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11327
11328 \end_inset
11329
11330
11331 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11332
11333 \end_inset
11334
11335  / far
11336 \begin_inset LatexCommand \index{far (storage class)}
11337
11338 \end_inset
11339
11340
11341 \begin_inset LatexCommand \index{\_\_far (storage class)}
11342
11343 \end_inset
11344
11345
11346 \end_layout
11347
11348 \begin_layout Standard
11349 Variables declared with this storage class will be placed in the external
11350  RAM.
11351  This is the 
11352 \series bold
11353 default
11354 \series default
11355  storage class for the Large Memory model, e.g.:
11356 \end_layout
11357
11358 \begin_layout Verse
11359
11360 \family typewriter
11361 __xdata unsigned char test_xdata;
11362 \end_layout
11363
11364 \begin_layout Standard
11365 Writing 0x01 to this variable generates the assembly code:
11366 \end_layout
11367
11368 \begin_layout Verse
11369
11370 \family typewriter
11371 90s00r00\InsetSpace ~
11372 \InsetSpace ~
11373 \InsetSpace ~
11374 mov\InsetSpace ~
11375 \InsetSpace ~
11376 dptr,#_test_xdata 
11377 \newline
11378 74\InsetSpace ~
11379 01\InsetSpace ~
11380 \InsetSpace ~
11381 \InsetSpace ~
11382 \InsetSpace ~
11383 \InsetSpace ~
11384 \InsetSpace ~
11385 mov\InsetSpace ~
11386 \InsetSpace ~
11387 a,#0x01 
11388 \newline
11389 F0\InsetSpace ~
11390 \InsetSpace ~
11391 \InsetSpace ~
11392 \InsetSpace ~
11393 \InsetSpace ~
11394 \InsetSpace ~
11395 \InsetSpace ~
11396 \InsetSpace ~
11397 \InsetSpace ~
11398 movx\InsetSpace ~
11399 @dptr,a 
11400 \end_layout
11401
11402 \begin_layout Subsubsection
11403 idata
11404 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11405
11406 \end_inset
11407
11408
11409 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11410
11411 \end_inset
11412
11413
11414 \end_layout
11415
11416 \begin_layout Standard
11417 Variables declared with this storage class will be allocated into the indirectly
11418  addressable portion of the internal ram of a 8051, e.g.:
11419 \end_layout
11420
11421 \begin_layout Verse
11422
11423 \family typewriter
11424 __idata unsigned char test_idata;
11425 \end_layout
11426
11427 \begin_layout Standard
11428 Writing 0x01 to this variable generates the assembly code:
11429 \end_layout
11430
11431 \begin_layout Verse
11432
11433 \family typewriter
11434 78r00\InsetSpace ~
11435 \InsetSpace ~
11436 \InsetSpace ~
11437 \InsetSpace ~
11438 \InsetSpace ~
11439 \InsetSpace ~
11440 \InsetSpace ~
11441 mov\InsetSpace ~
11442 \InsetSpace ~
11443 r0,#_test_idata
11444 \newline
11445 76\InsetSpace ~
11446 01\InsetSpace ~
11447 \InsetSpace ~
11448 \InsetSpace ~
11449 \InsetSpace ~
11450 \InsetSpace ~
11451 \InsetSpace ~
11452 \InsetSpace ~
11453 mov\InsetSpace ~
11454 \InsetSpace ~
11455 @r0,#0x01
11456 \end_layout
11457
11458 \begin_layout Standard
11459 Please note, the first 128 byte of idata physically access the same RAM
11460  as the data memory.
11461  The original 8051 had 128 byte idata memory, nowadays most devices have
11462  256 byte idata memory.
11463  The stack
11464 \begin_inset LatexCommand \index{stack}
11465
11466 \end_inset
11467
11468  is located in idata memory.
11469 \end_layout
11470
11471 \begin_layout Subsubsection
11472 pdata
11473 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11474
11475 \end_inset
11476
11477
11478 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11479
11480 \end_inset
11481
11482
11483 \end_layout
11484
11485 \begin_layout Standard
11486 Paged xdata access is just as straightforward as using the other addressing
11487  modes of a 8051.
11488  It is typically located at the start of xdata and has a maximum size of
11489  256 bytes.
11490  The following example writes 0x01 to the pdata variable.
11491  Please note, pdata access physically accesses xdata memory.
11492  The high byte of the address is determined by port P2 
11493 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11494
11495 \end_inset
11496
11497 (or in case of some 8051 variants by a separate Special Function Register,
11498  see section 
11499 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11500
11501 \end_inset
11502
11503 ).
11504  This is the 
11505 \series bold
11506 default
11507 \series default
11508  storage class for the Medium Memory model, e.g.:
11509 \end_layout
11510
11511 \begin_layout Verse
11512
11513 \family typewriter
11514 __pdata unsigned char test_pdata;
11515 \end_layout
11516
11517 \begin_layout Standard
11518 Writing 0x01 to this variable generates the assembly code:
11519 \end_layout
11520
11521 \begin_layout Verse
11522
11523 \family typewriter
11524 78r00\InsetSpace ~
11525 \InsetSpace ~
11526 \InsetSpace ~
11527 \InsetSpace ~
11528 \InsetSpace ~
11529 \InsetSpace ~
11530 mov r0,#_test_pdata
11531 \newline
11532 74 01\InsetSpace ~
11533 \InsetSpace ~
11534 \InsetSpace ~
11535 \InsetSpace ~
11536 \InsetSpace ~
11537 \InsetSpace ~
11538 mov a,#0x01 
11539 \newline
11540 F2\InsetSpace ~
11541 \InsetSpace ~
11542 \InsetSpace ~
11543 \InsetSpace ~
11544 \InsetSpace ~
11545 \InsetSpace ~
11546 \InsetSpace ~
11547 \InsetSpace ~
11548 \InsetSpace ~
11549 movx @r0,a
11550 \end_layout
11551
11552 \begin_layout Standard
11553 If the -
11554 \begin_inset ERT
11555 status collapsed
11556
11557 \begin_layout Standard
11558
11559
11560 \backslash
11561 /
11562 \end_layout
11563
11564 \end_inset
11565
11566 -xstack
11567 \begin_inset LatexCommand \index{-\/-xstack}
11568
11569 \end_inset
11570
11571  option is used the pdata memory area is followed by the xstack memory area
11572  and the sum of their sizes is limited to 256 bytes.
11573 \end_layout
11574
11575 \begin_layout Subsubsection
11576 code
11577 \begin_inset LatexCommand \index{code}
11578
11579 \end_inset
11580
11581
11582 \begin_inset LatexCommand \index{\_\_code}
11583
11584 \end_inset
11585
11586
11587 \end_layout
11588
11589 \begin_layout Standard
11590 'Variables' declared with this storage class will be placed in the code
11591  memory:
11592 \end_layout
11593
11594 \begin_layout Verse
11595
11596 \family typewriter
11597 __code unsigned char test_code;
11598 \end_layout
11599
11600 \begin_layout Standard
11601 Read access to this variable generates the assembly code:
11602 \end_layout
11603
11604 \begin_layout Verse
11605
11606 \family typewriter
11607 90s00r6F\InsetSpace ~
11608 \InsetSpace ~
11609 \InsetSpace ~
11610 mov dptr,#_test_code
11611 \newline
11612 E4\InsetSpace ~
11613 \InsetSpace ~
11614 \InsetSpace ~
11615 \InsetSpace ~
11616 \InsetSpace ~
11617 \InsetSpace ~
11618 \InsetSpace ~
11619 \InsetSpace ~
11620 \InsetSpace ~
11621 clr a
11622 \newline
11623 93\InsetSpace ~
11624 \InsetSpace ~
11625 \InsetSpace ~
11626 \InsetSpace ~
11627 \InsetSpace ~
11628 \InsetSpace ~
11629 \InsetSpace ~
11630 \InsetSpace ~
11631 \InsetSpace ~
11632 movc a,@a+dptr 
11633 \end_layout
11634
11635 \begin_layout Standard
11636
11637 \family typewriter
11638 char
11639 \family default
11640  indexed arrays of characters in code memory can be accessed efficiently:
11641 \end_layout
11642
11643 \begin_layout Verse
11644
11645 \family typewriter
11646 __code char test_array[] = {'c','h','e','a','p'}; 
11647 \end_layout
11648
11649 \begin_layout Standard
11650 Read access to this array using an 8-bit unsigned index generates the assembly
11651  code:
11652 \end_layout
11653
11654 \begin_layout Verse
11655
11656 \family typewriter
11657 E5*00\InsetSpace ~
11658 \InsetSpace ~
11659 \InsetSpace ~
11660 \InsetSpace ~
11661 \InsetSpace ~
11662 \InsetSpace ~
11663 mov a,_index 
11664 \end_layout
11665
11666 \begin_layout Verse
11667
11668 \family typewriter
11669 90s00r41\InsetSpace ~
11670 \InsetSpace ~
11671 \InsetSpace ~
11672 mov dptr,#_test_array
11673 \end_layout
11674
11675 \begin_layout Verse
11676
11677 \family typewriter
11678 93\InsetSpace ~
11679 \InsetSpace ~
11680 \InsetSpace ~
11681 \InsetSpace ~
11682 \InsetSpace ~
11683 \InsetSpace ~
11684 \InsetSpace ~
11685 \InsetSpace ~
11686 \InsetSpace ~
11687 movc a,@a+dptr 
11688 \end_layout
11689
11690 \begin_layout Subsubsection
11691 bit
11692 \begin_inset LatexCommand \index{bit}
11693
11694 \end_inset
11695
11696
11697 \begin_inset LatexCommand \index{\_\_bit}
11698
11699 \end_inset
11700
11701
11702 \end_layout
11703
11704 \begin_layout Standard
11705 This is a data-type and a storage class specifier.
11706  When a variable is declared as a bit, it is allocated into the bit addressable
11707  memory of 8051, e.g.:
11708 \end_layout
11709
11710 \begin_layout Verse
11711
11712 \family typewriter
11713 __bit test_bit;
11714 \end_layout
11715
11716 \begin_layout Standard
11717 Writing 1 to this variable generates the assembly code:
11718 \end_layout
11719
11720 \begin_layout Verse
11721
11722 \family typewriter
11723 D2*00\InsetSpace ~
11724 \InsetSpace ~
11725 \InsetSpace ~
11726 \InsetSpace ~
11727 \InsetSpace ~
11728 \InsetSpace ~
11729 \InsetSpace ~
11730 setb\InsetSpace ~
11731 _test_bit
11732 \end_layout
11733
11734 \begin_layout Standard
11735 The bit addressable memory consists of 128 bits which are located from 0x20
11736  to 0x2f in data memory.
11737  
11738 \newline
11739 Apart from this 8051 specific storage class most architectures support
11740  ANSI-C bitfields
11741 \begin_inset LatexCommand \index{bitfields}
11742
11743 \end_inset
11744
11745
11746 \begin_inset Foot
11747 status open
11748
11749 \begin_layout Standard
11750 Not really meant as examples, but nevertheless showing what bitfields are
11751  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11752 \end_layout
11753
11754 \end_inset
11755
11756 .
11757  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11758  signed modifier are implemented as unsigned.
11759 \end_layout
11760
11761 \begin_layout Subsubsection
11762 sfr
11763 \begin_inset LatexCommand \index{sfr}
11764
11765 \end_inset
11766
11767
11768 \begin_inset LatexCommand \index{\_\_sfr}
11769
11770 \end_inset
11771
11772  / sfr16
11773 \begin_inset LatexCommand \index{sfr16}
11774
11775 \end_inset
11776
11777
11778 \begin_inset LatexCommand \index{\_\_sfr16}
11779
11780 \end_inset
11781
11782  / sfr32
11783 \begin_inset LatexCommand \index{sfr32}
11784
11785 \end_inset
11786
11787
11788 \begin_inset LatexCommand \index{\_\_sfr32}
11789
11790 \end_inset
11791
11792  / sbit
11793 \begin_inset LatexCommand \index{\_\_sbit}
11794
11795 \end_inset
11796
11797
11798 \begin_inset LatexCommand \index{sbit}
11799
11800 \end_inset
11801
11802
11803 \end_layout
11804
11805 \begin_layout Standard
11806 Like the bit keyword, 
11807 \emph on
11808 sfr / sfr16 / sfr32 / sbit 
11809 \emph default
11810 signify both a data-type and storage class, they are used to describe the
11811  
11812 \emph on
11813 s
11814 \emph default
11815 pecial 
11816 \emph on
11817 f
11818 \emph default
11819 unction 
11820 \emph on
11821 r
11822 \emph default
11823 egisters and 
11824 \emph on
11825 s
11826 \emph default
11827 pecial 
11828 \emph on
11829 bit
11830 \emph default
11831  variables of a 8051, eg:
11832 \end_layout
11833
11834 \begin_layout Verse
11835
11836 \family typewriter
11837 __sfr __at
11838 \begin_inset LatexCommand \index{at}
11839
11840 \end_inset
11841
11842
11843 \begin_inset LatexCommand \index{\_\_at}
11844
11845 \end_inset
11846
11847  (0x80) P0;\InsetSpace ~
11848  /* special function register P0 at location 0x80 */
11849 \newline
11850
11851 \newline
11852 /* 16 bit
11853  special function register combination for timer 0
11854 \newline
11855 \InsetSpace ~
11856 \InsetSpace ~
11857  with the high byte at
11858  location 0x8C and the low byte at location 0x8A */
11859 \newline
11860 __sfr16 __at (0x8C8A)
11861  TMR0;
11862 \newline
11863
11864 \newline
11865 __sbit __at
11866 \begin_inset LatexCommand \index{at}
11867
11868 \end_inset
11869
11870
11871 \begin_inset LatexCommand \index{\_\_at}
11872
11873 \end_inset
11874
11875  (0xd7) CY;\InsetSpace ~
11876  /* CY (Carry Flag
11877 \begin_inset LatexCommand \index{Flags}
11878
11879 \end_inset
11880
11881
11882 \begin_inset LatexCommand \index{Carry flag}
11883
11884 \end_inset
11885
11886 ) */
11887 \end_layout
11888
11889 \begin_layout Standard
11890 Special function registers which are located on an address dividable by
11891  8 are bit-addressable, an
11892 \emph on
11893  sbit
11894 \emph default
11895  addresses a specific bit within these sfr.
11896 \newline
11897 16 Bit and 32 bit special function
11898  register combinations which require a certain access order are better not
11899  declared using 
11900 \emph on
11901 sfr16
11902 \emph default
11903  or 
11904 \emph on
11905 sfr32.
11906
11907 \emph default
11908  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11909  this is not guaranteed.
11910 \newline
11911
11912 \end_layout
11913
11914 \begin_layout Standard
11915 Please note, if you use a header file which was written for another compiler
11916  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11917  likely be 
11918 \emph on
11919 not 
11920 \emph default
11921 compatible.
11922  Specifically the syntax 
11923 \family typewriter
11924 \InsetSpace ~
11925 sfr P0 = 0x80;\InsetSpace ~
11926
11927 \family default
11928  is compiled 
11929 \emph on
11930 without warning
11931 \emph default
11932  by SDCC to an assignment of 0x80 to a variable called P0 
11933 \family typewriter
11934
11935 \begin_inset Marginal
11936 status collapsed
11937
11938 \begin_layout Standard
11939
11940 \series bold
11941 \InsetSpace ~
11942 !
11943 \end_layout
11944
11945 \end_inset
11946
11947 .
11948  
11949 \family default
11950 Nevertheless it is possible to write header files
11951 \begin_inset LatexCommand \index{Header files}
11952
11953 \end_inset
11954
11955
11956 \begin_inset LatexCommand \index{Include files}
11957
11958 \end_inset
11959
11960  which can be shared among different compilers (see section 
11961 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11962
11963 \end_inset
11964
11965 ).
11966  
11967 \end_layout
11968
11969 \begin_layout Subsubsection
11970 Pointers
11971 \begin_inset LatexCommand \index{Pointer}
11972
11973 \end_inset
11974
11975  to MCS51/DS390 specific memory spaces
11976 \end_layout
11977
11978 \begin_layout Standard
11979 SDCC allows (via language extensions) pointers to explicitly point to any
11980  of the memory spaces
11981 \begin_inset LatexCommand \index{Memory model}
11982
11983 \end_inset
11984
11985  of the 8051.
11986  In addition to the explicit pointers, the compiler uses (by default) generic
11987  pointers which can be used to point to any of the memory spaces.
11988 \newline
11989
11990 \newline
11991 Pointer
11992  declaration examples:
11993 \end_layout
11994
11995 \begin_layout Verse
11996
11997 \family typewriter
11998 /* pointer physically in internal ram pointing to object in external ram
11999  */ 
12000 \newline
12001 __xdata unsigned char * __data p;
12002 \newline
12003
12004 \newline
12005 /* pointer physically in external ram
12006  pointing to object in internal ram */ 
12007 \newline
12008 __data unsigned char * __xdata p;
12009 \newline
12010
12011 \newline
12012 /*
12013  pointer physically in code rom pointing to data in xdata space */ 
12014 \newline
12015 __xdata
12016  unsigned char * __code p;
12017 \newline
12018
12019 \newline
12020 /* pointer physically in code space pointing to
12021  data in code space */ 
12022 \newline
12023 __code unsigned char * __code p;
12024 \newline
12025
12026 \newline
12027 /* generic pointer
12028  physically located in xdata space */
12029 \newline
12030 unsigned char * __xdata p;
12031 \newline
12032
12033 \newline
12034 /* generic
12035  pointer physically located in default memory space */
12036 \newline
12037 unsigned char * p;
12038 \newline
12039
12040 \newline
12041 /*
12042  the following is a function pointer
12043 \begin_inset LatexCommand \index{function pointer}
12044
12045 \end_inset
12046
12047  physically located in data space */
12048 \newline
12049 char (* __data fp)(void);
12050 \end_layout
12051
12052 \begin_layout Standard
12053 Well you get the idea.
12054  
12055 \newline
12056
12057 \newline
12058 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12059 \emph on
12060 generic
12061 \emph default
12062  pointers.
12063  
12064 \size small
12065
12066 \newline
12067
12068 \newline
12069
12070 \size default
12071 The highest order byte of the 
12072 \emph on
12073 generic
12074 \emph default
12075  pointers contains the data space information.
12076  Assembler support routines are called whenever data is stored or retrieved
12077  using 
12078 \emph on
12079 generic
12080 \emph default
12081  pointers.
12082  These are useful for developing reusable library
12083 \begin_inset LatexCommand \index{Libraries}
12084
12085 \end_inset
12086
12087  routines.
12088  Explicitly specifying the pointer
12089 \begin_inset LatexCommand \index{pointer}
12090
12091 \end_inset
12092
12093  type will generate the most efficient code.
12094 \end_layout
12095
12096 \begin_layout Subsubsection
12097 Notes on MCS51 memory
12098 \begin_inset LatexCommand \index{MCS51 memory}
12099
12100 \end_inset
12101
12102  layout
12103 \end_layout
12104
12105 \begin_layout Standard
12106 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12107  RAM memory which is structured as follows:
12108 \newline
12109
12110 \newline
12111 - Bytes 00-1F - 32 bytes to hold
12112  up to 4 banks of the registers R0 to R7, 
12113 \newline
12114 - Bytes 20-2F - 16 bytes to hold
12115  128 bit
12116 \begin_inset LatexCommand \index{bit}
12117
12118 \end_inset
12119
12120  variables and, 
12121 \newline
12122 - Bytes 30-7F - 80 bytes for general purpose use.
12123 \newline
12124
12125 \end_layout
12126
12127 \begin_layout Standard
12128 Additionally some members of the MCS51 family may have up to 128 bytes of
12129  additional, indirectly addressable, internal RAM memory (
12130 \emph on
12131 idata
12132 \emph default
12133
12134 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12135
12136 \end_inset
12137
12138
12139 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12140
12141 \end_inset
12142
12143 ).
12144  Furthermore, some chips may have some built in external memory (
12145 \emph on
12146 xdata
12147 \emph default
12148
12149 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12150
12151 \end_inset
12152
12153
12154 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12155
12156 \end_inset
12157
12158 ) which should not be confused with the internal, directly addressable RAM
12159  memory (
12160 \emph on
12161 data
12162 \emph default
12163
12164 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12165
12166 \end_inset
12167
12168
12169 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12170
12171 \end_inset
12172
12173 ).
12174  Sometimes this built in 
12175 \emph on
12176 xdata
12177 \emph default
12178  memory has to be activated before using it (you can probably find this
12179  information on the datasheet of the microcontroller your are using, see
12180  also section 
12181 \begin_inset LatexCommand \ref{sub:Startup-Code}
12182
12183 \end_inset
12184
12185 \InsetSpace ~
12186 Startup-Code).
12187 \end_layout
12188
12189 \begin_layout Standard
12190 Normally SDCC will only use the first bank
12191 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12192
12193 \end_inset
12194
12195  of registers (register bank 0), but it is possible to specify that other
12196  banks of registers (keyword 
12197 \emph on
12198 using
12199 \emph default
12200  
12201 \emph on
12202
12203 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12204
12205 \end_inset
12206
12207
12208 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12209
12210 \end_inset
12211
12212
12213 \emph default
12214 ) should be used for example in interrupt
12215 \begin_inset LatexCommand \index{interrupt}
12216
12217 \end_inset
12218
12219
12220 \begin_inset LatexCommand \index{\_\_interrupt}
12221
12222 \end_inset
12223
12224  routines.
12225  By default, the compiler will place the stack after the last byte of allocated
12226  memory for variables.
12227  For example, if the first 2 banks of registers are used, and only four
12228  bytes are used for 
12229 \emph on
12230 data
12231 \emph default
12232  variables, it will position the base of the internal stack at address 20
12233  (0x14).
12234  This implies that as the stack
12235 \begin_inset LatexCommand \index{stack}
12236
12237 \end_inset
12238
12239  grows, it will use up the remaining register banks, and the 16 bytes used
12240  by the 128 bit variables, and 80 bytes for general purpose use.
12241  If any bit variables are used, the data variables will be placed in unused
12242  register banks and after the byte holding the last bit variable.
12243  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12244  (two bytes used), 
12245 \emph on
12246 data
12247 \emph default
12248  variables will be placed starting from address 0x10 to 0x20 and continue
12249  at address 0x22.
12250  You can also use -
12251 \begin_inset ERT
12252 status collapsed
12253
12254 \begin_layout Standard
12255
12256
12257 \backslash
12258 /
12259 \end_layout
12260
12261 \end_inset
12262
12263 -data-loc
12264 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12265
12266 \end_inset
12267
12268  to specify the start address of the 
12269 \emph on
12270 data
12271 \emph default
12272  and -
12273 \begin_inset ERT
12274 status collapsed
12275
12276 \begin_layout Standard
12277
12278
12279 \backslash
12280 /
12281 \end_layout
12282
12283 \end_inset
12284
12285 -iram-size
12286 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12287
12288 \end_inset
12289
12290  to specify the size of the total internal RAM (
12291 \emph on
12292 data
12293 \emph default
12294 +
12295 \emph on
12296 idata
12297 \emph default
12298 ).
12299  
12300 \newline
12301
12302 \end_layout
12303
12304 \begin_layout Standard
12305 By default the 8051 linker will place the stack after the last byte of (i)data
12306  variables.
12307  Option -
12308 \begin_inset ERT
12309 status collapsed
12310
12311 \begin_layout Standard
12312
12313
12314 \backslash
12315 /
12316 \end_layout
12317
12318 \end_inset
12319
12320 -stack-loc
12321 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12322
12323 \end_inset
12324
12325  allows you to specify the start of the stack, i.e.
12326  you could start it after any data in the general purpose area.
12327  If your microcontroller has additional indirectly addressable internal
12328  RAM (
12329 \emph on
12330 idata
12331 \emph default
12332 ) you can place the stack on it.
12333  You may also need to use -
12334 \begin_inset ERT
12335 status collapsed
12336
12337 \begin_layout Standard
12338
12339
12340 \backslash
12341 /
12342 \end_layout
12343
12344 \end_inset
12345
12346 -xdata-loc
12347 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12348
12349 \end_inset
12350
12351  to set the start address of the external RAM (
12352 \emph on
12353 xdata
12354 \emph default
12355 ) and -
12356 \begin_inset ERT
12357 status collapsed
12358
12359 \begin_layout Standard
12360
12361
12362 \backslash
12363 /
12364 \end_layout
12365
12366 \end_inset
12367
12368 -xram-size
12369 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12370
12371 \end_inset
12372
12373  to specify its size.
12374  Same goes for the code memory, using -
12375 \begin_inset ERT
12376 status collapsed
12377
12378 \begin_layout Standard
12379
12380
12381 \backslash
12382 /
12383 \end_layout
12384
12385 \end_inset
12386
12387 -code-loc
12388 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12389
12390 \end_inset
12391
12392  and -
12393 \begin_inset ERT
12394 status collapsed
12395
12396 \begin_layout Standard
12397
12398
12399 \backslash
12400 /
12401 \end_layout
12402
12403 \end_inset
12404
12405 -code-size
12406 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12407
12408 \end_inset
12409
12410 .
12411  If in doubt, don't specify any options and see if the resulting memory
12412  layout is appropriate, then you can adjust it.
12413 \end_layout
12414
12415 \begin_layout Standard
12416 The linker generates two files with memory allocation information.
12417  The first, with extension .map
12418 \begin_inset LatexCommand \index{<file>.map}
12419
12420 \end_inset
12421
12422  shows all the variables and segments.
12423  The second with extension .mem
12424 \begin_inset LatexCommand \index{<file>.mem}
12425
12426 \end_inset
12427
12428  shows the final memory layout.
12429  The linker will complain either if memory segments overlap, there is not
12430  enough memory, or there is not enough space for stack.
12431  If you get any linking warnings and/or errors related to stack or segments
12432  allocation, take a look at either the .map or .mem files to find out what
12433  the problem is.
12434  The .mem file may even suggest a solution to the problem.
12435 \begin_inset VSpace bigskip
12436 \end_inset
12437
12438
12439 \end_layout
12440
12441 \begin_layout Subsection
12442 Z80/Z180 Storage Class
12443 \begin_inset LatexCommand \index{Z80!Storage class}
12444
12445 \end_inset
12446
12447  Language Extensions
12448 \end_layout
12449
12450 \begin_layout Subsubsection
12451 sfr
12452 \begin_inset LatexCommand \index{sfr}
12453
12454 \end_inset
12455
12456
12457 \begin_inset LatexCommand \index{\_\_sfr}
12458
12459 \end_inset
12460
12461  (in/out to 8-bit addresses)
12462 \end_layout
12463
12464 \begin_layout Standard
12465 The Z80
12466 \begin_inset LatexCommand \index{Z80}
12467
12468 \end_inset
12469
12470  family has separate address spaces for memory and 
12471 \emph on
12472 i
12473 \emph default
12474 nput/
12475 \emph on
12476 o
12477 \emph default
12478 utput memory.
12479  I/O memory
12480 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12481
12482 \end_inset
12483
12484
12485 \begin_inset LatexCommand \index{Z80!I/O memory}
12486
12487 \end_inset
12488
12489
12490 \begin_inset LatexCommand \index{Z180!I/O memory}
12491
12492 \end_inset
12493
12494  is accessed with special instructions, e.g.:
12495 \end_layout
12496
12497 \begin_layout Verse
12498
12499 \family typewriter
12500 sfr at 0x78 IoPort;\InsetSpace ~
12501 \InsetSpace ~
12502 /* define a var in I/O space at 78h called IoPort */
12503  
12504 \end_layout
12505
12506 \begin_layout Standard
12507 Writing 0x01 to this variable generates the assembly code:
12508 \end_layout
12509
12510 \begin_layout Verse
12511
12512 \family typewriter
12513 3E 01\InsetSpace ~
12514 \InsetSpace ~
12515 \InsetSpace ~
12516 \InsetSpace ~
12517 \InsetSpace ~
12518 \InsetSpace ~
12519 ld a,#0x01
12520 \newline
12521 D3 78\InsetSpace ~
12522 \InsetSpace ~
12523 \InsetSpace ~
12524 \InsetSpace ~
12525 \InsetSpace ~
12526 \InsetSpace ~
12527 out (_IoPort),a 
12528 \end_layout
12529
12530 \begin_layout Subsubsection
12531 banked sfr
12532 \begin_inset LatexCommand \index{sfr}
12533
12534 \end_inset
12535
12536
12537 \begin_inset LatexCommand \index{\_\_sfr}
12538
12539 \end_inset
12540
12541  (in/out to 16-bit addresses)
12542 \end_layout
12543
12544 \begin_layout Standard
12545 The keyword 
12546 \emph on
12547 banked
12548 \emph default
12549  is used to support 16 bit addresses in I/O memory e.g.:
12550 \end_layout
12551
12552 \begin_layout Verse
12553
12554 \family typewriter
12555 sfr banked at
12556 \begin_inset LatexCommand \index{at}
12557
12558 \end_inset
12559
12560
12561 \begin_inset LatexCommand \index{\_\_at}
12562
12563 \end_inset
12564
12565  0x123 IoPort; 
12566 \end_layout
12567
12568 \begin_layout Standard
12569 Writing 0x01 to this variable generates the assembly code:
12570 \end_layout
12571
12572 \begin_layout Verse
12573
12574 \family typewriter
12575 01 23 01\InsetSpace ~
12576 \InsetSpace ~
12577 \InsetSpace ~
12578 ld bc,#_IoPort
12579 \newline
12580 3E 01\InsetSpace ~
12581 \InsetSpace ~
12582 \InsetSpace ~
12583 \InsetSpace ~
12584 \InsetSpace ~
12585 \InsetSpace ~
12586 ld a,#0x01 
12587 \newline
12588 ED 79\InsetSpace ~
12589 \InsetSpace ~
12590 \InsetSpace ~
12591 \InsetSpace ~
12592 \InsetSpace ~
12593 \InsetSpace ~
12594 out (c),a 
12595 \end_layout
12596
12597 \begin_layout Subsubsection
12598 sfr
12599 \begin_inset LatexCommand \index{sfr}
12600
12601 \end_inset
12602
12603
12604 \begin_inset LatexCommand \index{\_\_sfr}
12605
12606 \end_inset
12607
12608  (in0/out0 to 8 bit addresses on Z180
12609 \begin_inset LatexCommand \index{Z180}
12610
12611 \end_inset
12612
12613 /HD64180
12614 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12615
12616 \end_inset
12617
12618 )
12619 \end_layout
12620
12621 \begin_layout Standard
12622 The compiler option -
12623 \begin_inset ERT
12624 status collapsed
12625
12626 \begin_layout Standard
12627
12628
12629 \backslash
12630 /
12631 \end_layout
12632
12633 \end_inset
12634
12635 -portmode
12636 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12637
12638 \end_inset
12639
12640 =180 (80) and a compiler #pragma\InsetSpace ~
12641 portmode
12642 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12643
12644 \end_inset
12645
12646  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12647 ns 
12648 \family typewriter
12649 in0/out0
12650 \family default
12651  instead of 
12652 \family typewriter
12653 in/out
12654 \family default
12655 .
12656  If you include the file z180.h this will be set automatically.
12657 \begin_inset VSpace bigskip
12658 \end_inset
12659
12660
12661 \end_layout
12662
12663 \begin_layout Subsection
12664 HC08 Storage Class
12665 \begin_inset LatexCommand \index{HC08!Storage class}
12666
12667 \end_inset
12668
12669  Language Extensions
12670 \end_layout
12671
12672 \begin_layout Subsubsection
12673 data
12674 \begin_inset LatexCommand \index{data (hc08 storage class)}
12675
12676 \end_inset
12677
12678
12679 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12680
12681 \end_inset
12682
12683  
12684 \end_layout
12685
12686 \begin_layout Standard
12687 The data storage class declares a variable that resides in the first 256
12688  bytes of memory (the direct page).
12689  The HC08
12690 \begin_inset LatexCommand \index{HC08}
12691
12692 \end_inset
12693
12694  is most efficient at accessing variables (especially pointers) stored here.
12695 \end_layout
12696
12697 \begin_layout Subsubsection
12698 xdata
12699 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12700
12701 \end_inset
12702
12703
12704 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12705
12706 \end_inset
12707
12708  
12709 \end_layout
12710
12711 \begin_layout Standard
12712 The xdata storage class declares a variable that can reside anywhere in
12713  memory.
12714  This is the default if no storage class is specified.
12715  
12716 \begin_inset VSpace bigskip
12717 \end_inset
12718
12719
12720 \end_layout
12721
12722 \begin_layout Section
12723 Absolute Addressing
12724 \begin_inset LatexCommand \index{Absolute addressing}
12725
12726 \end_inset
12727
12728
12729 \end_layout
12730
12731 \begin_layout Standard
12732 Data items can be assigned an absolute address with the 
12733 \emph on
12734 at
12735 \begin_inset LatexCommand \index{at}
12736
12737 \end_inset
12738
12739
12740 \begin_inset LatexCommand \index{\_\_at}
12741
12742 \end_inset
12743
12744  <address>
12745 \emph default
12746  keyword, in addition to a storage class, e.g.:
12747 \end_layout
12748
12749 \begin_layout Verse
12750
12751 \family typewriter
12752 xdata
12753 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12754
12755 \end_inset
12756
12757
12758 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12759
12760 \end_inset
12761
12762  at
12763 \begin_inset LatexCommand \index{at}
12764
12765 \end_inset
12766
12767
12768 \begin_inset LatexCommand \index{\_\_at}
12769
12770 \end_inset
12771
12772  0x7ffe unsigned int chksum;
12773 \end_layout
12774
12775 \begin_layout Standard
12776 or, better conforming to ISO/IEC 9899 C:
12777 \end_layout
12778
12779 \begin_layout Verse
12780
12781 \family typewriter
12782 __xdata __at (0x7ffe) unsigned int chksum;
12783 \end_layout
12784
12785 \begin_layout Standard
12786 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12787  of the external ram.
12788  The compiler does 
12789 \emph on
12790 not
12791 \emph default
12792  reserve any space for variables declared in this way
12793 \begin_inset Marginal
12794 status collapsed
12795
12796 \begin_layout Standard
12797
12798 \series bold
12799 \InsetSpace ~
12800 !
12801 \end_layout
12802
12803 \end_inset
12804
12805  (they are implemented with an equate in the assembler).
12806  Thus it is left to the programmer to make sure there are no overlaps with
12807  other variables that are declared without the absolute address.
12808  The assembler listing file (.lst
12809 \begin_inset LatexCommand \index{<file>.lst}
12810
12811 \end_inset
12812
12813 ) and the linker output files (.rst
12814 \begin_inset LatexCommand \index{<file>.rst}
12815
12816 \end_inset
12817
12818 ) and (.map
12819 \begin_inset LatexCommand \index{<file>.map}
12820
12821 \end_inset
12822
12823 ) are good places to look for such overlaps.
12824  Variables with an absolute address are 
12825 \emph on
12826 not
12827 \begin_inset Marginal
12828 status collapsed
12829
12830 \begin_layout Standard
12831
12832 \series bold
12833 \InsetSpace ~
12834 !
12835 \end_layout
12836
12837 \end_inset
12838
12839
12840 \emph default
12841  initialized
12842 \begin_inset LatexCommand \index{Variable initialization}
12843
12844 \end_inset
12845
12846 .
12847 \end_layout
12848
12849 \begin_layout Standard
12850 In case of memory mapped I/O devices the keyword 
12851 \emph on
12852 volatile
12853 \emph default
12854  has to be used to tell the compiler that accesses might not be removed:
12855 \end_layout
12856
12857 \begin_layout Verse
12858
12859 \family typewriter
12860 volatile
12861 \begin_inset LatexCommand \index{volatile}
12862
12863 \end_inset
12864
12865  __xdata
12866 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12867
12868 \end_inset
12869
12870  __at
12871 \begin_inset LatexCommand \index{at}
12872
12873 \end_inset
12874
12875  (0x8000) unsigned char PORTA_8255;
12876 \end_layout
12877
12878 \begin_layout Standard
12879 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12880 r) array
12881 \family typewriter
12882 \size footnotesize
12883
12884 \begin_inset LatexCommand \index{Aligned array}
12885
12886 \end_inset
12887
12888
12889 \family default
12890 \size default
12891  starts at a block (256 byte) boundary
12892 \begin_inset LatexCommand \index{block boundary}
12893
12894 \end_inset
12895
12896  (section 
12897 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12898
12899 \end_inset
12900
12901  has an example).
12902 \newline
12903 Absolute addresses can be specified for variables in all
12904  storage classes, e.g.:
12905 \end_layout
12906
12907 \begin_layout Verse
12908
12909 \family typewriter
12910 __bit
12911 \begin_inset LatexCommand \index{bit}
12912
12913 \end_inset
12914
12915  __at
12916 \begin_inset LatexCommand \index{at}
12917
12918 \end_inset
12919
12920  (0x02) bvar;
12921 \end_layout
12922
12923 \begin_layout Standard
12924 The above example will allocate the variable at offset 0x02 in the bit-addressab
12925 le space.
12926  There is no real advantage to assigning absolute addresses to variables
12927  in this manner, unless you want strict control over all the variables allocated.
12928  One possible use would be to write hardware portable code.
12929  For example, if you have a routine that uses one or more of the microcontroller
12930  I/O pins, and such pins are different for two different hardwares, you
12931  can declare the I/O pins in your routine using:
12932 \end_layout
12933
12934 \begin_layout Verse
12935
12936 \family typewriter
12937 extern volatile
12938 \begin_inset LatexCommand \index{volatile}
12939
12940 \end_inset
12941
12942  __bit MOSI;\InsetSpace ~
12943 \InsetSpace ~
12944 \InsetSpace ~
12945 \InsetSpace ~
12946 /* master out, slave in */
12947 \newline
12948 extern volatile __bit MISO;\InsetSpace ~
12949 \InsetSpace ~
12950 \InsetSpace ~
12951 \InsetSpace ~
12952 /* master
12953  in, slave out */
12954 \newline
12955 extern volatile __bit MCLK;\InsetSpace ~
12956 \InsetSpace ~
12957 \InsetSpace ~
12958 \InsetSpace ~
12959 /* master clock */
12960 \newline
12961
12962 \newline
12963 /* Input and
12964  Output of a byte on a 3-wire serial bus.
12965 \newline
12966 \InsetSpace ~
12967 \InsetSpace ~
12968 \InsetSpace ~
12969 If needed adapt polarity of clock,
12970  polarity of data and bit order
12971 \newline
12972 \InsetSpace ~
12973 */
12974 \newline
12975 unsigned char spi_io(unsigned char out_byte)
12976  
12977 \newline
12978
12979 \newline
12980 \InsetSpace ~
12981 \InsetSpace ~
12982 \InsetSpace ~
12983 \InsetSpace ~
12984 unsigned char i=8;
12985 \newline
12986 \InsetSpace ~
12987 \InsetSpace ~
12988 \InsetSpace ~
12989 \InsetSpace ~
12990 do { 
12991 \newline
12992 \InsetSpace ~
12993 \InsetSpace ~
12994 \InsetSpace ~
12995 \InsetSpace ~
12996 \InsetSpace ~
12997 \InsetSpace ~
12998 \InsetSpace ~
12999 \InsetSpace ~
13000 MOSI = out_byte & 0x80; 
13001 \newline
13002 \InsetSpace ~
13003 \InsetSpace ~
13004 \InsetSpace ~
13005 \InsetSpace ~
13006 \InsetSpace ~
13007 \InsetSpace ~
13008 \InsetSpace ~
13009 \InsetSpace ~
13010 out_byte <<= 1;
13011 \newline
13012 \InsetSpace ~
13013 \InsetSpace ~
13014 \InsetSpace ~
13015 \InsetSpace ~
13016 \InsetSpace ~
13017 \InsetSpace ~
13018 \InsetSpace ~
13019 \InsetSpace ~
13020 MCLK =
13021  1; 
13022 \newline
13023 \InsetSpace ~
13024 \InsetSpace ~
13025 \InsetSpace ~
13026 \InsetSpace ~
13027 \InsetSpace ~
13028 \InsetSpace ~
13029 \InsetSpace ~
13030 \InsetSpace ~
13031 /* _asm nop _endasm; */\InsetSpace ~
13032 \InsetSpace ~
13033 \InsetSpace ~
13034 \InsetSpace ~
13035 \InsetSpace ~
13036 \InsetSpace ~
13037 \InsetSpace ~
13038 \InsetSpace ~
13039 /* for slow peripherals */
13040 \newline
13041 \InsetSpace ~
13042 \InsetSpace ~
13043 \InsetSpace ~
13044 \InsetSpace ~
13045 \InsetSpace ~
13046 \InsetSpace ~
13047 \InsetSpace ~
13048 \InsetSpace ~
13049 if(MISO) 
13050 \newline
13051 \InsetSpace ~
13052 \InsetSpace ~
13053 \InsetSpace ~
13054 \InsetSpace ~
13055 \InsetSpace ~
13056 \InsetSpace ~
13057 \InsetSpace ~
13058 \InsetSpace ~
13059 \InsetSpace ~
13060 \InsetSpace ~
13061 \InsetSpace ~
13062 \InsetSpace ~
13063 out_byte +=
13064  1; 
13065 \newline
13066 \InsetSpace ~
13067 \InsetSpace ~
13068 \InsetSpace ~
13069 \InsetSpace ~
13070 \InsetSpace ~
13071 \InsetSpace ~
13072 \InsetSpace ~
13073 \InsetSpace ~
13074 MCLK = 0; 
13075 \newline
13076 \InsetSpace ~
13077 \InsetSpace ~
13078 \InsetSpace ~
13079 \InsetSpace ~
13080 } while(--i);
13081 \newline
13082 \InsetSpace ~
13083 \InsetSpace ~
13084 \InsetSpace ~
13085 \InsetSpace ~
13086 return out_byte; 
13087 \newline
13088 }
13089 \end_layout
13090
13091 \begin_layout Standard
13092 Then, someplace in the code for the first hardware you would use
13093 \end_layout
13094
13095 \begin_layout Verse
13096
13097 \family typewriter
13098 __bit __at
13099 \begin_inset LatexCommand \index{at}
13100
13101 \end_inset
13102
13103
13104 \begin_inset LatexCommand \index{\_\_at}
13105
13106 \end_inset
13107
13108  (0x80) MOSI;\InsetSpace ~
13109 \InsetSpace ~
13110 \InsetSpace ~
13111 \InsetSpace ~
13112 /* I/O port 0, bit 0 */
13113 \newline
13114 __bit __at (0x81) MISO;\InsetSpace ~
13115 \InsetSpace ~
13116 \InsetSpace ~
13117 \InsetSpace ~
13118 /* I/O port 0,
13119  bit 1 */
13120 \newline
13121 __bit __at (0x82) MCLK;\InsetSpace ~
13122 \InsetSpace ~
13123 \InsetSpace ~
13124 \InsetSpace ~
13125 /* I/O port 0, bit 2 */
13126 \end_layout
13127
13128 \begin_layout Standard
13129 Similarly, for the second hardware you would use
13130 \end_layout
13131
13132 \begin_layout Verse
13133
13134 \family typewriter
13135 __bit __at (0x83) MOSI;\InsetSpace ~
13136 \InsetSpace ~
13137 \InsetSpace ~
13138 \InsetSpace ~
13139 /* I/O port 0, bit 3 */
13140 \newline
13141 __bit __at (0x91) MISO;\InsetSpace ~
13142 \InsetSpace ~
13143 \InsetSpace ~
13144 \InsetSpace ~
13145 /*
13146  I/O port 1, bit 1 */
13147 \newline
13148 __bit
13149 \begin_inset LatexCommand \index{bit}
13150
13151 \end_inset
13152
13153  __at (0x92) MCLK;\InsetSpace ~
13154 \InsetSpace ~
13155 \InsetSpace ~
13156 \InsetSpace ~
13157 /* I/O port 1, bit 2 */
13158 \end_layout
13159
13160 \begin_layout Standard
13161 and you can use the same hardware dependent routine without changes, as
13162  for example in a library.
13163  This is somehow similar to sbit, but only one absolute address has to be
13164  specified in the whole project.
13165 \begin_inset VSpace bigskip
13166 \end_inset
13167
13168
13169 \end_layout
13170
13171 \begin_layout Section
13172 Parameters
13173 \begin_inset LatexCommand \index{Parameters}
13174
13175 \end_inset
13176
13177
13178 \begin_inset LatexCommand \index{function parameter}
13179
13180 \end_inset
13181
13182  & Local Variables
13183 \begin_inset LatexCommand \index{local variables}
13184
13185 \end_inset
13186
13187
13188 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13189
13190 \end_inset
13191
13192
13193 \end_layout
13194
13195 \begin_layout Standard
13196 Automatic (local) variables and parameters to functions can either be placed
13197  on the stack or in data-space.
13198  The default action of the compiler is to place these variables in the internal
13199  RAM (for small model) or external RAM (for large model).
13200  This in fact makes them similar to 
13201 \emph on
13202 static
13203 \begin_inset LatexCommand \index{static}
13204
13205 \end_inset
13206
13207
13208 \emph default
13209  so by default functions are non-reentrant
13210 \begin_inset LatexCommand \index{reentrant}
13211
13212 \end_inset
13213
13214 .
13215  
13216 \newline
13217
13218 \newline
13219 They can be placed on the stack
13220 \begin_inset LatexCommand \index{stack}
13221
13222 \end_inset
13223
13224  by using the
13225 \emph on
13226  -
13227 \begin_inset ERT
13228 status collapsed
13229
13230 \begin_layout Standard
13231
13232
13233 \backslash
13234 /
13235 \end_layout
13236
13237 \end_inset
13238
13239 -stack-auto
13240 \begin_inset LatexCommand \index{-\/-stack-auto}
13241
13242 \end_inset
13243
13244
13245 \emph default
13246  option, by using 
13247 \emph on
13248 #pragma\InsetSpace ~
13249 stackauto
13250 \emph default
13251
13252 \begin_inset LatexCommand \index{\#pragma stackauto}
13253
13254 \end_inset
13255
13256  or by using the 
13257 \emph on
13258 reentrant
13259 \begin_inset LatexCommand \index{reentrant}
13260
13261 \end_inset
13262
13263
13264 \emph default
13265  keyword in the function declaration, e.g.:
13266 \end_layout
13267
13268 \begin_layout Verse
13269
13270 \family typewriter
13271 unsigned char foo(char i) __reentrant 
13272 \newline
13273
13274 \newline
13275 \InsetSpace ~
13276 \InsetSpace ~
13277 \InsetSpace ~
13278 \InsetSpace ~
13279 ...
13280  
13281 \newline
13282 }
13283 \end_layout
13284
13285 \begin_layout Standard
13286 Since stack space on 8051 is limited, the 
13287 \emph on
13288 reentrant 
13289 \emph default
13290 keyword or the
13291 \emph on
13292  -
13293 \begin_inset ERT
13294 status collapsed
13295
13296 \begin_layout Standard
13297
13298
13299 \backslash
13300 /
13301 \end_layout
13302
13303 \end_inset
13304
13305 -stack-auto
13306 \emph default
13307  option should be used sparingly.
13308  Note that the reentrant keyword just means that the parameters & local
13309  variables will be allocated to the stack, it 
13310 \emph on
13311 does not
13312 \emph default
13313  mean that the function is register bank
13314 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13315
13316 \end_inset
13317
13318  independent.
13319 \newline
13320
13321 \newline
13322 Local variables
13323 \begin_inset LatexCommand \index{local variables}
13324
13325 \end_inset
13326
13327  can be assigned storage classes and absolute
13328 \begin_inset LatexCommand \index{Absolute addressing}
13329
13330 \end_inset
13331
13332  addresses, e.g.: 
13333 \end_layout
13334
13335 \begin_layout Verse
13336
13337 \family typewriter
13338 unsigned char foo() 
13339 \newline
13340 {
13341 \newline
13342 \InsetSpace ~
13343 \InsetSpace ~
13344 \InsetSpace ~
13345 \InsetSpace ~
13346 __xdata unsigned char i;
13347 \newline
13348 \InsetSpace ~
13349 \InsetSpace ~
13350 \InsetSpace ~
13351 \InsetSpace ~
13352 __bit bvar;
13353 \newline
13354 \InsetSpace ~
13355 \InsetSpace ~
13356 \InsetSpace ~
13357 \InsetSpace ~
13358 __data __at
13359 \begin_inset LatexCommand \index{at}
13360
13361 \end_inset
13362
13363  (0x31) unsigned char j;
13364 \newline
13365 \InsetSpace ~
13366 \InsetSpace ~
13367 \InsetSpace ~
13368 \InsetSpace ~
13369 ...
13370  
13371 \newline
13372 }
13373 \end_layout
13374
13375 \begin_layout Standard
13376 In the above example the variable 
13377 \emph on
13378 i
13379 \emph default
13380  will be allocated in the external ram, 
13381 \emph on
13382 bvar
13383 \emph default
13384  in bit addressable space and
13385 \emph on
13386  j
13387 \emph default
13388  in internal ram.
13389  When compiled with 
13390 \emph on
13391 -
13392 \begin_inset ERT
13393 status collapsed
13394
13395 \begin_layout Standard
13396
13397
13398 \backslash
13399 /
13400 \end_layout
13401
13402 \end_inset
13403
13404 -stack-auto
13405 \emph default
13406  or when a function is declared as 
13407 \emph on
13408 reentrant
13409 \emph default
13410  this should only be done for static variables.
13411 \end_layout
13412
13413 \begin_layout Standard
13414 Parameters
13415 \begin_inset LatexCommand \index{function parameter}
13416
13417 \end_inset
13418
13419  however are not allowed any storage class
13420 \begin_inset LatexCommand \index{Storage class}
13421
13422 \end_inset
13423
13424 , (storage classes for parameters will be ignored), their allocation is
13425  governed by the memory model in use, and the reentrancy options.
13426 \end_layout
13427
13428 \begin_layout Standard
13429 It is however allowed to use bit parameters in reentrant functions and also
13430  non-static local bit variables are supported.
13431  Efficient use is limited to 8 semi-bitregisters in bit space.
13432  They are pushed and popped to stack
13433 \begin_inset LatexCommand \index{stack}
13434
13435 \end_inset
13436
13437  as a single byte just like the normal registers.
13438 \end_layout
13439
13440 \begin_layout Section
13441 Overlaying
13442 \begin_inset LatexCommand \label{sub:Overlaying}
13443
13444 \end_inset
13445
13446
13447 \begin_inset LatexCommand \index{Overlaying}
13448
13449 \end_inset
13450
13451
13452 \end_layout
13453
13454 \begin_layout Standard
13455 For non-reentrant
13456 \begin_inset LatexCommand \index{reentrant}
13457
13458 \end_inset
13459
13460  functions SDCC will try to reduce internal ram space usage by overlaying
13461  parameters and local variables of a function (if possible).
13462  Parameters and local variables
13463 \begin_inset LatexCommand \index{local variables}
13464
13465 \end_inset
13466
13467  of a function will be allocated to an overlayable segment if the function
13468  has 
13469 \emph on
13470 no other function calls and the function is non-reentrant and the memory
13471  model
13472 \begin_inset LatexCommand \index{Memory model}
13473
13474 \end_inset
13475
13476  is small.
13477
13478 \emph default
13479  If an explicit storage class
13480 \begin_inset LatexCommand \index{Storage class}
13481
13482 \end_inset
13483
13484  is specified for a local variable, it will NOT be overlayed.
13485 \end_layout
13486
13487 \begin_layout Standard
13488 Note that the compiler (not the linkage editor) makes the decision for overlayin
13489 g the data items.
13490  Functions that are called from an interrupt service routine
13491 \begin_inset Marginal
13492 status collapsed
13493
13494 \begin_layout Standard
13495
13496 \series bold
13497 !
13498 \end_layout
13499
13500 \end_inset
13501
13502  should be preceded by a #pragma\InsetSpace ~
13503 nooverlay
13504 \begin_inset LatexCommand \index{\#pragma nooverlay}
13505
13506 \end_inset
13507
13508  if they are not reentrant.
13509 \end_layout
13510
13511 \begin_layout Standard
13512 Also note that the compiler does not do any processing of inline assembler
13513  code, so the compiler might incorrectly assign local variables and parameters
13514  of a function into the overlay segment if the inline assembler code calls
13515  other c-functions that might use the overlay.
13516  In that case the #pragma\InsetSpace ~
13517 nooverlay should be used.
13518 \end_layout
13519
13520 \begin_layout Standard
13521 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13522 tion
13523 \begin_inset LatexCommand \index{Multiplication}
13524
13525 \end_inset
13526
13527  or division
13528 \begin_inset LatexCommand \index{Division}
13529
13530 \end_inset
13531
13532  will NOT be overlayed since these are implemented using external functions,
13533  e.g.:
13534 \end_layout
13535
13536 \begin_layout Verse
13537
13538 \family typewriter
13539 #pragma save 
13540 \newline
13541 #pragma nooverlay
13542 \begin_inset LatexCommand \index{\#pragma nooverlay}
13543
13544 \end_inset
13545
13546  
13547 \newline
13548 void set_error(unsigned char errcd) 
13549 \newline
13550 {
13551 \newline
13552 \InsetSpace ~
13553 \InsetSpace ~
13554 \InsetSpace ~
13555 \InsetSpace ~
13556 P3 = errcd;
13557 \newline
13558
13559 \newline
13560 #pragma restore 
13561 \newline
13562
13563 \newline
13564 void
13565  some_isr () __interrupt
13566 \begin_inset LatexCommand \index{interrupt}
13567
13568 \end_inset
13569
13570  (2)
13571 \newline
13572 {
13573 \newline
13574 \InsetSpace ~
13575 \InsetSpace ~
13576 \InsetSpace ~
13577 \InsetSpace ~
13578 ...
13579 \newline
13580 \InsetSpace ~
13581 \InsetSpace ~
13582 \InsetSpace ~
13583 \InsetSpace ~
13584 set_error(10);
13585 \newline
13586 \InsetSpace ~
13587 \InsetSpace ~
13588 \InsetSpace ~
13589 \InsetSpace ~
13590 ...
13591  
13592 \newline
13593 }
13594 \end_layout
13595
13596 \begin_layout Standard
13597 In the above example the parameter 
13598 \emph on
13599 errcd
13600 \emph default
13601  for the function 
13602 \emph on
13603 set_error
13604 \emph default
13605  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13606 nooverlay was
13607  not present, this could cause unpredictable runtime behavior when called
13608  from an interrupt service routine.
13609  The #pragma\InsetSpace ~
13610 nooverlay ensures that the parameters and local variables for
13611  the function are NOT overlayed.
13612 \begin_inset VSpace bigskip
13613 \end_inset
13614
13615
13616 \end_layout
13617
13618 \begin_layout Section
13619 Interrupt Service Routines
13620 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13621
13622 \end_inset
13623
13624
13625 \end_layout
13626
13627 \begin_layout Subsection
13628 General Information
13629 \end_layout
13630
13631 \begin_layout Standard
13632 SDCC allows 
13633 \emph on
13634 i
13635 \emph default
13636 nterrupt 
13637 \emph on
13638 s
13639 \emph default
13640 ervice 
13641 \emph on
13642 r
13643 \emph default
13644 outines to be coded in C, with some extended keywords.
13645 \end_layout
13646
13647 \begin_layout Verse
13648
13649 \family typewriter
13650 void timer_isr (void) __interrupt (1) __using (1) 
13651 \newline
13652
13653 \newline
13654 \InsetSpace ~
13655 \InsetSpace ~
13656 \InsetSpace ~
13657 \InsetSpace ~
13658 ...
13659  
13660 \newline
13661 }
13662 \end_layout
13663
13664 \begin_layout Standard
13665 The optional number following the 
13666 \emph on
13667 interrupt
13668 \begin_inset LatexCommand \index{interrupt}
13669
13670 \end_inset
13671
13672
13673 \begin_inset LatexCommand \index{\_\_interrupt}
13674
13675 \end_inset
13676
13677
13678 \emph default
13679  keyword is the interrupt number this routine will service.
13680  When present, the compiler will insert a call to this routine in the interrupt
13681  vector table
13682 \begin_inset LatexCommand \index{interrupt vector table}
13683
13684 \end_inset
13685
13686  for the interrupt number specified.
13687  If you have multiple source files in your project, interrupt service routines
13688  can be present in any of them, but a prototype of the isr MUST be present
13689  or included in the file that contains the function 
13690 \emph on
13691 main
13692 \emph default
13693 .
13694  The optional (8051 specific) keyword 
13695 \emph on
13696 using
13697 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13698
13699 \end_inset
13700
13701
13702 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13703
13704 \end_inset
13705
13706
13707 \emph default
13708  can be used to tell the compiler to use the specified register bank when
13709  generating code for this function.
13710  
13711 \newline
13712 Interrupt service routines open the door for some very interesting bugs:
13713 \end_layout
13714
13715 \begin_layout Subsubsection
13716 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13717
13718 \end_inset
13719
13720 Common interrupt pitfall: variable not declared 
13721 \emph on
13722 volatile
13723 \end_layout
13724
13725 \begin_layout Standard
13726 If an interrupt service routine changes variables which are accessed by
13727  other functions these variables have to be declared 
13728 \emph on
13729 volatile
13730 \emph default
13731
13732 \begin_inset LatexCommand \index{volatile}
13733
13734 \end_inset
13735
13736 .
13737  See 
13738 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13739
13740 \end_inset
13741
13742  .
13743 \end_layout
13744
13745 \begin_layout Subsubsection
13746 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13747
13748 \end_inset
13749
13750 Common interrupt pitfall: 
13751 \emph on
13752 non-atomic access
13753 \end_layout
13754
13755 \begin_layout Standard
13756 If the access to these variables is not 
13757 \emph on
13758 atomic
13759 \begin_inset LatexCommand \index{atomic}
13760
13761 \end_inset
13762
13763
13764 \emph default
13765  (i.e.
13766  the processor needs more than one instruction for the access and could
13767  be interrupted while accessing the variable) the interrupt must be disabled
13768  during the access to avoid inconsistent data.
13769  
13770 \newline
13771 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13772  and should be protected by disabling interrupts.
13773  You're not automatically on the safe side if you use 8 bit variables though.
13774  We need an example here: f.e.
13775  on the 8051 the harmless looking 
13776 \begin_inset Quotes srd
13777 \end_inset
13778
13779
13780 \family typewriter
13781 flags\InsetSpace ~
13782 |=\InsetSpace ~
13783 0x80;
13784 \family default
13785
13786 \begin_inset Quotes sld
13787 \end_inset
13788
13789  is not atomic if 
13790 \family typewriter
13791 flags
13792 \family default
13793  resides in xdata.
13794  Setting 
13795 \begin_inset Quotes srd
13796 \end_inset
13797
13798
13799 \family typewriter
13800 flags\InsetSpace ~
13801 |=\InsetSpace ~
13802 0x40;
13803 \family default
13804
13805 \begin_inset Quotes sld
13806 \end_inset
13807
13808  from within an interrupt routine might get lost if the interrupt occurs
13809  at the wrong time.
13810  
13811 \begin_inset Quotes sld
13812 \end_inset
13813
13814
13815 \family typewriter
13816 counter\InsetSpace ~
13817 +=\InsetSpace ~
13818 8;
13819 \family default
13820
13821 \begin_inset Quotes srd
13822 \end_inset
13823
13824  is not atomic on the 8051 even if 
13825 \family typewriter
13826 counter
13827 \family default
13828  is located in data memory.
13829 \newline
13830 Bugs like these are hard to reproduce and can
13831  cause a lot of trouble.
13832  
13833 \end_layout
13834
13835 \begin_layout Subsubsection
13836 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13837
13838 \end_inset
13839
13840 Common interrupt pitfall: 
13841 \emph on
13842 stack overflow
13843 \end_layout
13844
13845 \begin_layout Standard
13846 The return address and the registers used in the interrupt service routine
13847  are saved on the stack
13848 \begin_inset LatexCommand \index{stack}
13849
13850 \end_inset
13851
13852  so there must be sufficient stack space.
13853  If there isn't variables or registers (or even the return address itself)
13854  will be corrupted.
13855  This 
13856 \emph on
13857 stack overflow
13858 \emph default
13859
13860 \begin_inset LatexCommand \index{stack overflow}
13861
13862 \end_inset
13863
13864  is most likely to happen if the interrupt occurs during the 
13865 \begin_inset Quotes sld
13866 \end_inset
13867
13868 deepest
13869 \begin_inset Quotes srd
13870 \end_inset
13871
13872  subroutine when the stack is already in use for f.e.
13873  many return addresses.
13874 \end_layout
13875
13876 \begin_layout Subsubsection
13877 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13878
13879 \end_inset
13880
13881 Common interrupt pitfall: 
13882 \emph on
13883 use of non-reentrant functions
13884 \end_layout
13885
13886 \begin_layout Standard
13887 A special note here, int (16 bit) and long (32 bit) integer division
13888 \begin_inset LatexCommand \index{Division}
13889
13890 \end_inset
13891
13892 , multiplication
13893 \begin_inset LatexCommand \index{Multiplication}
13894
13895 \end_inset
13896
13897  & modulus
13898 \begin_inset LatexCommand \index{Modulus}
13899
13900 \end_inset
13901
13902  and floating-point
13903 \begin_inset LatexCommand \index{Floating point support}
13904
13905 \end_inset
13906
13907  operations are implemented using external support routines.
13908  If an interrupt service routine needs to do any of these operations then
13909  the support routines (as mentioned in a following section) will have to
13910  be recompiled using the
13911 \emph on
13912  -
13913 \begin_inset ERT
13914 status collapsed
13915
13916 \begin_layout Standard
13917
13918
13919 \backslash
13920 /
13921 \end_layout
13922
13923 \end_inset
13924
13925 -stack-auto
13926 \begin_inset LatexCommand \index{-\/-stack-auto}
13927
13928 \end_inset
13929
13930
13931 \emph default
13932  option and the source file will need to be compiled using the 
13933 \emph on
13934 -
13935 \begin_inset ERT
13936 status collapsed
13937
13938 \begin_layout Standard
13939
13940
13941 \backslash
13942 /
13943 \end_layout
13944
13945 \end_inset
13946
13947 -int-long-reent
13948 \emph default
13949
13950 \begin_inset LatexCommand \index{-\/-int-long-reent}
13951
13952 \end_inset
13953
13954  compiler option.
13955  
13956 \newline
13957 Note, the type promotion
13958 \begin_inset LatexCommand \index{type promotion}
13959
13960 \end_inset
13961
13962  required by ANSI C can cause 16 bit routines to be used
13963 \begin_inset Marginal
13964 status collapsed
13965
13966 \begin_layout Standard
13967
13968 \series bold
13969 \InsetSpace ~
13970 !
13971 \end_layout
13972
13973 \end_inset
13974
13975  without the programmer being aware of it.
13976  See f.e.
13977  the cast 
13978 \family typewriter
13979 (unsigned char)(tail-1)
13980 \family default
13981  within the if clause in section 
13982 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13983
13984 \end_inset
13985
13986 .
13987 \end_layout
13988
13989 \begin_layout Standard
13990 Calling other functions from an interrupt service routine is not recommended,
13991  avoid it if possible.
13992  Note that when some function is called from an interrupt service routine
13993  it should be preceded by a #pragma\InsetSpace ~
13994 nooverlay
13995 \begin_inset LatexCommand \index{\#pragma nooverlay}
13996
13997 \end_inset
13998
13999  if it is not reentrant.
14000  Furthermore nonreentrant functions should not be called from the main program
14001  while the interrupt service routine might be active.
14002  They also must not be called from low priority interrupt service routines
14003  while a high priority interrupt service routine might be active.
14004  You could use semaphores or make the function
14005 \emph on
14006  critical
14007 \emph default
14008  if all parameters are passed in registers.
14009 \newline
14010  Also see section 
14011 \begin_inset LatexCommand \ref{sub:Overlaying}
14012
14013 \end_inset
14014
14015 \InsetSpace ~
14016 about Overlaying and section 
14017 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14018
14019 \end_inset
14020
14021 \InsetSpace ~
14022 about Functions using private register banks.
14023 \begin_inset VSpace bigskip
14024 \end_inset
14025
14026
14027 \end_layout
14028
14029 \begin_layout Subsection
14030 MCS51/DS390 Interrupt Service Routines
14031 \end_layout
14032
14033 \begin_layout Standard
14034 Interrupt
14035 \begin_inset LatexCommand \index{interrupt}
14036
14037 \end_inset
14038
14039  numbers and the corresponding address & descriptions for the Standard 8051/8052
14040  are listed below.
14041  SDCC will automatically adjust the 
14042 \begin_inset LatexCommand \index{interrupt vector table}
14043
14044 \end_inset
14045
14046  to the maximum interrupt number specified.
14047 \newline
14048
14049 \end_layout
14050
14051 \begin_layout Standard
14052 \align center
14053 \begin_inset Tabular
14054 <lyxtabular version="3" rows="9" columns="3">
14055 <features>
14056 <column alignment="center" valignment="top" leftline="true" width="0in">
14057 <column alignment="left" valignment="top" leftline="true" width="0in">
14058 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14059 <row topline="true" bottomline="true">
14060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14061 \begin_inset Text
14062
14063 \begin_layout Standard
14064 Interrupt #
14065 \end_layout
14066
14067 \end_inset
14068 </cell>
14069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14070 \begin_inset Text
14071
14072 \begin_layout Standard
14073 Description
14074 \end_layout
14075
14076 \end_inset
14077 </cell>
14078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14079 \begin_inset Text
14080
14081 \begin_layout Standard
14082 Vector Address
14083 \end_layout
14084
14085 \end_inset
14086 </cell>
14087 </row>
14088 <row topline="true">
14089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14090 \begin_inset Text
14091
14092 \begin_layout Standard
14093 0
14094 \end_layout
14095
14096 \end_inset
14097 </cell>
14098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14099 \begin_inset Text
14100
14101 \begin_layout Standard
14102 External 0
14103 \end_layout
14104
14105 \end_inset
14106 </cell>
14107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14108 \begin_inset Text
14109
14110 \begin_layout Standard
14111 0x0003
14112 \end_layout
14113
14114 \end_inset
14115 </cell>
14116 </row>
14117 <row topline="true">
14118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14119 \begin_inset Text
14120
14121 \begin_layout Standard
14122 1
14123 \end_layout
14124
14125 \end_inset
14126 </cell>
14127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14128 \begin_inset Text
14129
14130 \begin_layout Standard
14131 Timer 0
14132 \end_layout
14133
14134 \end_inset
14135 </cell>
14136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14137 \begin_inset Text
14138
14139 \begin_layout Standard
14140 0x000b
14141 \end_layout
14142
14143 \end_inset
14144 </cell>
14145 </row>
14146 <row topline="true">
14147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14148 \begin_inset Text
14149
14150 \begin_layout Standard
14151 2
14152 \end_layout
14153
14154 \end_inset
14155 </cell>
14156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14157 \begin_inset Text
14158
14159 \begin_layout Standard
14160 External 1
14161 \end_layout
14162
14163 \end_inset
14164 </cell>
14165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14166 \begin_inset Text
14167
14168 \begin_layout Standard
14169 0x0013
14170 \end_layout
14171
14172 \end_inset
14173 </cell>
14174 </row>
14175 <row topline="true">
14176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14177 \begin_inset Text
14178
14179 \begin_layout Standard
14180 3
14181 \end_layout
14182
14183 \end_inset
14184 </cell>
14185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14186 \begin_inset Text
14187
14188 \begin_layout Standard
14189 Timer 1
14190 \end_layout
14191
14192 \end_inset
14193 </cell>
14194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14195 \begin_inset Text
14196
14197 \begin_layout Standard
14198 0x001b
14199 \end_layout
14200
14201 \end_inset
14202 </cell>
14203 </row>
14204 <row topline="true">
14205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14206 \begin_inset Text
14207
14208 \begin_layout Standard
14209 4
14210 \end_layout
14211
14212 \end_inset
14213 </cell>
14214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14215 \begin_inset Text
14216
14217 \begin_layout Standard
14218 Serial
14219 \end_layout
14220
14221 \end_inset
14222 </cell>
14223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14224 \begin_inset Text
14225
14226 \begin_layout Standard
14227 0x0023
14228 \end_layout
14229
14230 \end_inset
14231 </cell>
14232 </row>
14233 <row topline="true">
14234 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14235 \begin_inset Text
14236
14237 \begin_layout Standard
14238 5
14239 \end_layout
14240
14241 \end_inset
14242 </cell>
14243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14244 \begin_inset Text
14245
14246 \begin_layout Standard
14247 Timer 2 (8052)
14248 \end_layout
14249
14250 \end_inset
14251 </cell>
14252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14253 \begin_inset Text
14254
14255 \begin_layout Standard
14256 0x002b
14257 \end_layout
14258
14259 \end_inset
14260 </cell>
14261 </row>
14262 <row topline="true">
14263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14264 \begin_inset Text
14265
14266 \begin_layout Standard
14267 ...
14268 \end_layout
14269
14270 \end_inset
14271 </cell>
14272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14273 \begin_inset Text
14274
14275 \begin_layout Standard
14276
14277 \end_layout
14278
14279 \end_inset
14280 </cell>
14281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14282 \begin_inset Text
14283
14284 \begin_layout Standard
14285 ...
14286 \end_layout
14287
14288 \end_inset
14289 </cell>
14290 </row>
14291 <row topline="true" bottomline="true">
14292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14293 \begin_inset Text
14294
14295 \begin_layout Standard
14296 n
14297 \end_layout
14298
14299 \end_inset
14300 </cell>
14301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14302 \begin_inset Text
14303
14304 \begin_layout Standard
14305
14306 \end_layout
14307
14308 \end_inset
14309 </cell>
14310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14311 \begin_inset Text
14312
14313 \begin_layout Standard
14314 0x0003 + 8*n
14315 \end_layout
14316
14317 \end_inset
14318 </cell>
14319 </row>
14320 </lyxtabular>
14321
14322 \end_inset
14323
14324
14325 \newline
14326
14327 \end_layout
14328
14329 \begin_layout Standard
14330 If the interrupt service routine is defined without 
14331 \emph on
14332 using
14333 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14334
14335 \end_inset
14336
14337
14338 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14339
14340 \end_inset
14341
14342
14343 \emph default
14344  a register bank or with register bank 0 (
14345 \emph on
14346 using
14347 \emph default
14348  0), the compiler will save the registers used by itself on the stack upon
14349  entry and restore them at exit, however if such an interrupt service routine
14350  calls another function then the entire register bank will be saved on the
14351  stack.
14352  This scheme may be advantageous for small interrupt service routines which
14353  have low register usage.
14354 \end_layout
14355
14356 \begin_layout Standard
14357 If the interrupt service routine is defined to be using a specific register
14358  bank then only 
14359 \emph on
14360 a, b, dptr
14361 \emph default
14362  & psw are saved and restored, if such an interrupt service routine calls
14363  another function (using another register bank) then the entire register
14364  bank of the called function will be saved on the stack
14365 \begin_inset LatexCommand \index{stack}
14366
14367 \end_inset
14368
14369 .
14370  This scheme is recommended for larger interrupt service routines.
14371 \begin_inset VSpace bigskip
14372 \end_inset
14373
14374
14375 \end_layout
14376
14377 \begin_layout Subsection
14378 HC08
14379 \begin_inset LatexCommand \index{HC08}
14380
14381 \end_inset
14382
14383  Interrupt Service Routines
14384 \end_layout
14385
14386 \begin_layout Standard
14387 Since the number of interrupts
14388 \begin_inset LatexCommand \index{HC08!interrupt}
14389
14390 \end_inset
14391
14392  available is chip specific and the interrupt vector table always ends at
14393  the last byte of memory, the interrupt numbers corresponds to the interrupt
14394  vectors in reverse order of address.
14395  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14396  2 will use the interrupt vector at 0xfffa, and so on.
14397  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14398  this way; instead see section 
14399 \begin_inset LatexCommand \ref{sub:Startup-Code}
14400
14401 \end_inset
14402
14403  for details on customizing startup.
14404 \begin_inset VSpace bigskip
14405 \end_inset
14406
14407
14408 \end_layout
14409
14410 \begin_layout Subsection
14411 Z80 Interrupt Service Routines
14412 \end_layout
14413
14414 \begin_layout Standard
14415 The Z80
14416 \begin_inset LatexCommand \index{Z80}
14417
14418 \end_inset
14419
14420  uses several different methods for determining the correct interrupt
14421 \begin_inset LatexCommand \index{Z80!interrupt}
14422
14423 \end_inset
14424
14425  vector depending on the hardware implementation.
14426  Therefore, SDCC ignores the optional interrupt number and does not attempt
14427  to generate an interrupt vector table.
14428 \end_layout
14429
14430 \begin_layout Standard
14431 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14432  instruction to return from the interrupt.
14433  To write an interrupt handler for the non-maskable interrupt, which needs
14434  a RETN instruction instead, add the 
14435 \emph on
14436 critical
14437 \emph default
14438  keyword:
14439 \end_layout
14440
14441 \begin_layout Verse
14442
14443 \family typewriter
14444 void nmi_isr (void) critical interrupt
14445 \newline
14446
14447 \newline
14448 \InsetSpace ~
14449 \InsetSpace ~
14450 \InsetSpace ~
14451 \InsetSpace ~
14452 ...
14453  
14454 \newline
14455 }
14456 \end_layout
14457
14458 \begin_layout Standard
14459 However if you need to create a non-interruptable interrupt service routine
14460  you would also require the 
14461 \emph on
14462 critical
14463 \emph default
14464  keyword.
14465  To distinguish between this and an nmi_isr you must provide an interrupt
14466  number.
14467 \begin_inset VSpace bigskip
14468 \end_inset
14469
14470
14471 \end_layout
14472
14473 \begin_layout Section
14474 Enabling and Disabling Interrupts
14475 \end_layout
14476
14477 \begin_layout Subsection
14478 Critical Functions and Critical Statements
14479 \end_layout
14480
14481 \begin_layout Standard
14482 A special keyword may be associated with a block or a function declaring
14483  it as 
14484 \emph on
14485 critical
14486 \emph default
14487 .
14488  SDCC will generate code to disable all interrupts
14489 \begin_inset LatexCommand \index{interrupt}
14490
14491 \end_inset
14492
14493  upon entry to a critical function and restore the interrupt enable to the
14494  previous state before returning.
14495  Nesting critical functions will need one additional byte on the stack
14496 \begin_inset LatexCommand \index{stack}
14497
14498 \end_inset
14499
14500  for each call.
14501 \end_layout
14502
14503 \begin_layout Verse
14504
14505 \family typewriter
14506 int foo () __critical
14507 \begin_inset LatexCommand \index{critical}
14508
14509 \end_inset
14510
14511
14512 \begin_inset LatexCommand \index{\_\_critical}
14513
14514 \end_inset
14515
14516  
14517 \newline
14518
14519 \newline
14520 \InsetSpace ~
14521 \InsetSpace ~
14522 \InsetSpace ~
14523 \InsetSpace ~
14524 ...
14525  
14526 \newline
14527 \InsetSpace ~
14528 \InsetSpace ~
14529 \InsetSpace ~
14530 \InsetSpace ~
14531 ...
14532  
14533 \newline
14534 }
14535 \end_layout
14536
14537 \begin_layout Standard
14538 The critical attribute maybe used with other attributes like 
14539 \emph on
14540 reentrant.
14541 \emph default
14542
14543 \newline
14544 The keyword 
14545 \emph on
14546 critical
14547 \emph default
14548  may also be used to disable interrupts more locally:
14549 \end_layout
14550
14551 \begin_layout Verse
14552
14553 \family typewriter
14554 __critical{ i++; }
14555 \end_layout
14556
14557 \begin_layout Standard
14558 More than one statement could have been included in the block.
14559 \end_layout
14560
14561 \begin_layout Subsection
14562 Enabling and Disabling Interrupts directly
14563 \end_layout
14564
14565 \begin_layout Standard
14566 Interrupts
14567 \begin_inset LatexCommand \index{interrupt}
14568
14569 \end_inset
14570
14571  can also be disabled and enabled directly (8051):
14572 \end_layout
14573
14574 \begin_layout Verse
14575
14576 \family typewriter
14577 EA = 0;\InsetSpace ~
14578 \InsetSpace ~
14579 \InsetSpace ~
14580 \InsetSpace ~
14581 \InsetSpace ~
14582 \InsetSpace ~
14583 \InsetSpace ~
14584 \InsetSpace ~
14585 \InsetSpace ~
14586 \InsetSpace ~
14587 \InsetSpace ~
14588 \InsetSpace ~
14589 or:\InsetSpace ~
14590 \InsetSpace ~
14591 \InsetSpace ~
14592 \InsetSpace ~
14593 \InsetSpace ~
14594 \InsetSpace ~
14595 \InsetSpace ~
14596 \InsetSpace ~
14597 \InsetSpace ~
14598 \InsetSpace ~
14599 \InsetSpace ~
14600 EA_SAVE = EA;
14601 \end_layout
14602
14603 \begin_layout Verse
14604
14605 \family typewriter
14606 ...\InsetSpace ~
14607 \InsetSpace ~
14608 \InsetSpace ~
14609 \InsetSpace ~
14610 \InsetSpace ~
14611 \InsetSpace ~
14612 \InsetSpace ~
14613 \InsetSpace ~
14614 \InsetSpace ~
14615 \InsetSpace ~
14616 \InsetSpace ~
14617 \InsetSpace ~
14618 \InsetSpace ~
14619 \InsetSpace ~
14620 \InsetSpace ~
14621 \InsetSpace ~
14622 \InsetSpace ~
14623 \InsetSpace ~
14624 \InsetSpace ~
14625 \InsetSpace ~
14626 \InsetSpace ~
14627 \InsetSpace ~
14628 \InsetSpace ~
14629 \InsetSpace ~
14630 \InsetSpace ~
14631 \InsetSpace ~
14632 \InsetSpace ~
14633 \InsetSpace ~
14634 \InsetSpace ~
14635 \InsetSpace ~
14636 EA = 0;
14637 \end_layout
14638
14639 \begin_layout Verse
14640
14641 \family typewriter
14642 EA = 1;\InsetSpace ~
14643 \InsetSpace ~
14644 \InsetSpace ~
14645 \InsetSpace ~
14646 \InsetSpace ~
14647 \InsetSpace ~
14648 \InsetSpace ~
14649 \InsetSpace ~
14650 \InsetSpace ~
14651 \InsetSpace ~
14652 \InsetSpace ~
14653 \InsetSpace ~
14654 \InsetSpace ~
14655 \InsetSpace ~
14656 \InsetSpace ~
14657 \InsetSpace ~
14658 \InsetSpace ~
14659 \InsetSpace ~
14660 \InsetSpace ~
14661 \InsetSpace ~
14662 \InsetSpace ~
14663 \InsetSpace ~
14664 \InsetSpace ~
14665 \InsetSpace ~
14666 \InsetSpace ~
14667 \InsetSpace ~
14668 ...
14669 \end_layout
14670
14671 \begin_layout Verse
14672
14673 \family typewriter
14674 \InsetSpace ~
14675 \InsetSpace ~
14676 \InsetSpace ~
14677 \InsetSpace ~
14678 \InsetSpace ~
14679 \InsetSpace ~
14680 \InsetSpace ~
14681 \InsetSpace ~
14682 \InsetSpace ~
14683 \InsetSpace ~
14684 \InsetSpace ~
14685 \InsetSpace ~
14686 \InsetSpace ~
14687 \InsetSpace ~
14688 \InsetSpace ~
14689 \InsetSpace ~
14690 \InsetSpace ~
14691 \InsetSpace ~
14692 \InsetSpace ~
14693 \InsetSpace ~
14694 \InsetSpace ~
14695 \InsetSpace ~
14696 \InsetSpace ~
14697 \InsetSpace ~
14698 \InsetSpace ~
14699 \InsetSpace ~
14700 \InsetSpace ~
14701 \InsetSpace ~
14702 \InsetSpace ~
14703 \InsetSpace ~
14704 \InsetSpace ~
14705 \InsetSpace ~
14706 \InsetSpace ~
14707 EA = EA_SAVE;
14708 \end_layout
14709
14710 \begin_layout Standard
14711 On other architectures which have seperate opcodes for enabling and disabling
14712  interrupts you might want to make use of defines with inline assembly
14713 \begin_inset LatexCommand \index{Assembler routines}
14714
14715 \end_inset
14716
14717  (HC08
14718 \begin_inset LatexCommand \index{HC08!interrupt}
14719
14720 \end_inset
14721
14722 ):
14723 \end_layout
14724
14725 \begin_layout Verse
14726
14727 \family typewriter
14728 #define CLI _asm
14729 \begin_inset LatexCommand \index{\_asm}
14730
14731 \end_inset
14732
14733 \InsetSpace ~
14734 \InsetSpace ~
14735 cli\InsetSpace ~
14736 \InsetSpace ~
14737 _endasm
14738 \begin_inset LatexCommand \index{\_endasm}
14739
14740 \end_inset
14741
14742
14743 \end_layout
14744
14745 \begin_layout Verse
14746
14747 \family typewriter
14748 #define SEI _asm\InsetSpace ~
14749 \InsetSpace ~
14750 sei\InsetSpace ~
14751 \InsetSpace ~
14752 _endasm; 
14753 \end_layout
14754
14755 \begin_layout Verse
14756
14757 \family typewriter
14758 ...
14759 \end_layout
14760
14761 \begin_layout Standard
14762 Note: it is sometimes sufficient to disable only a specific interrupt source
14763  like f.e.
14764  a timer or serial interrupt by manipulating an 
14765 \emph on
14766 interrupt mask
14767 \begin_inset LatexCommand \index{interrupt mask}
14768
14769 \end_inset
14770
14771
14772 \emph default
14773  register.
14774  
14775 \end_layout
14776
14777 \begin_layout Standard
14778 Usually the time during which interrupts are disabled should be kept as
14779  short as possible.
14780  This minimizes both 
14781 \emph on
14782 interrupt latency
14783 \emph default
14784
14785 \begin_inset LatexCommand \index{interrupt latency}
14786
14787 \end_inset
14788
14789  (the time between the occurrence of the interrupt and the execution of
14790  the first code in the interrupt routine) and 
14791 \emph on
14792 interrupt jitter
14793 \emph default
14794
14795 \begin_inset LatexCommand \index{interrupt jitter}
14796
14797 \end_inset
14798
14799  (the difference between the shortest and the longest interrupt latency).
14800  These really are something different, f.e.
14801  a serial interrupt has to be served before its buffer overruns so it cares
14802  for the maximum interrupt latency, whereas it does not care about jitter.
14803  On a loudspeaker driven via a digital to analog converter which is fed
14804  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14805  a much smaller jitter will be very audible.
14806 \end_layout
14807
14808 \begin_layout Standard
14809 You can reenable interrupts within an interrupt routine and on some architecture
14810 s you can make use of two (or more) levels of 
14811 \emph on
14812 interrupt priorities
14813 \emph default
14814
14815 \begin_inset LatexCommand \index{interrupt priority}
14816
14817 \end_inset
14818
14819 .
14820  On some architectures which don't support interrupt priorities these can
14821  be implemented by manipulating the interrupt mask and reenabling interrupts
14822  within the interrupt routine.
14823  Check there is sufficient space on the stack
14824 \begin_inset LatexCommand \index{stack}
14825
14826 \end_inset
14827
14828  and don't add complexity unless you have to.
14829  
14830 \end_layout
14831
14832 \begin_layout Subsection
14833 Semaphore
14834 \begin_inset LatexCommand \index{semaphore}
14835
14836 \end_inset
14837
14838  locking (mcs51/ds390)
14839 \end_layout
14840
14841 \begin_layout Standard
14842 Some architectures (mcs51/ds390) have an atomic
14843 \begin_inset LatexCommand \index{atomic}
14844
14845 \end_inset
14846
14847  bit test and
14848 \emph on
14849  
14850 \emph default
14851 clear
14852 \emph on
14853  
14854 \emph default
14855 instruction.
14856  These type of instructions are typically used in preemptive multitasking
14857  systems, where a routine f.e.
14858  claims the use of a data structure ('acquires a lock
14859 \begin_inset LatexCommand \index{lock}
14860
14861 \end_inset
14862
14863  on it'), makes some modifications and then releases the lock when the data
14864  structure is consistent again.
14865  The instruction may also be used if interrupt and non-interrupt code have
14866  to compete for a resource.
14867  With the atomic bit test and clear instruction interrupts
14868 \begin_inset LatexCommand \index{interrupt}
14869
14870 \end_inset
14871
14872  don't have to be disabled for the locking operation.
14873  
14874 \end_layout
14875
14876 \begin_layout Standard
14877 SDCC generates this instruction if the source follows this pattern:
14878 \end_layout
14879
14880 \begin_layout Verse
14881
14882 \family typewriter
14883 volatile
14884 \begin_inset LatexCommand \index{volatile}
14885
14886 \end_inset
14887
14888  bit resource_is_free; 
14889 \newline
14890
14891 \newline
14892 if (resource_is_free) 
14893 \newline
14894 \InsetSpace ~
14895 \InsetSpace ~
14896
14897 \newline
14898 \InsetSpace ~
14899 \InsetSpace ~
14900 \InsetSpace ~
14901 \InsetSpace ~
14902 resource_is_free=0; 
14903 \newline
14904 \InsetSpace ~
14905 \InsetSpace ~
14906 \InsetSpace ~
14907 \InsetSpace ~
14908 ...
14909  
14910 \newline
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 resource_is_free=1;
14916 \newline
14917 \InsetSpace ~
14918 \InsetSpace ~
14919
14920 \end_layout
14921
14922 \begin_layout Standard
14923 Note, mcs51 and ds390 support only an atomic
14924 \begin_inset LatexCommand \index{atomic}
14925
14926 \end_inset
14927
14928  bit test and 
14929 \emph on
14930 clear
14931 \emph default
14932  instruction (as opposed to atomic bit test and 
14933 \emph on
14934 set).
14935 \end_layout
14936
14937 \begin_layout Section
14938 Functions using private register banks
14939 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14940
14941 \end_inset
14942
14943  (mcs51/ds390)
14944 \end_layout
14945
14946 \begin_layout Standard
14947 Some architectures have support for quickly changing register sets.
14948  SDCC supports this feature with the 
14949 \emph on
14950 using
14951 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14952
14953 \end_inset
14954
14955
14956 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14957
14958 \end_inset
14959
14960
14961 \emph default
14962  attribute (which tells the compiler to use a register bank
14963 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14964
14965 \end_inset
14966
14967  other than the default bank zero).
14968  It should only be applied to 
14969 \emph on
14970 interrupt
14971 \begin_inset LatexCommand \index{interrupt}
14972
14973 \end_inset
14974
14975
14976 \emph default
14977  functions (see footnote below).
14978  This will in most circumstances make the generated ISR code more efficient
14979  since it will not have to save registers on the stack.
14980 \end_layout
14981
14982 \begin_layout Standard
14983 The 
14984 \emph on
14985 using
14986 \emph default
14987  attribute will have no effect on the generated code for a 
14988 \emph on
14989 non-interrupt
14990 \emph default
14991  function (but may occasionally be useful anyway
14992 \begin_inset Foot
14993 status open
14994
14995 \begin_layout Standard
14996 possible exception: if a function is called ONLY from 'interrupt' functions
14997  using a particular bank, it can be declared with the same 'using' attribute
14998  as the calling 'interrupt' functions.
14999  For instance, if you have several ISRs using bank one, and all of them
15000  call memcpy(), it might make sense to create a specialized version of memcpy()
15001  'using 1', since this would prevent the ISR from having to save bank zero
15002  to the stack on entry and switch to bank zero before calling the function
15003 \end_layout
15004
15005 \end_inset
15006
15007 ).
15008 \newline
15009
15010 \emph on
15011 (pending: Note, nowadays the 
15012 \emph default
15013 using
15014 \emph on
15015  attribute has an effect on
15016 \emph default
15017  
15018 \emph on
15019 the generated code for a 
15020 \emph default
15021 non-interrupt
15022 \emph on
15023  function
15024 \emph default
15025 .
15026 \emph on
15027 )
15028 \end_layout
15029
15030 \begin_layout Standard
15031 An 
15032 \emph on
15033 interrupt
15034 \emph default
15035  function using a non-zero bank will assume that it can trash that register
15036  bank, and will not save it.
15037  Since high-priority interrupts
15038 \begin_inset LatexCommand \index{interrupts}
15039
15040 \end_inset
15041
15042
15043 \begin_inset LatexCommand \index{interrupt priority}
15044
15045 \end_inset
15046
15047  can interrupt low-priority ones on the 8051 and friends, this means that
15048  if a high-priority ISR 
15049 \emph on
15050 using
15051 \emph default
15052  a particular bank occurs while processing a low-priority ISR 
15053 \emph on
15054 using
15055 \emph default
15056  the same bank, terrible and bad things can happen.
15057  To prevent this, no single register bank should be 
15058 \emph on
15059 used
15060 \emph default
15061  by both a high priority and a low priority ISR.
15062  This is probably most easily done by having all high priority ISRs use
15063  one bank and all low priority ISRs use another.
15064  If you have an ISR which can change priority at runtime, you're on your
15065  own: I suggest using the default bank zero and taking the small performance
15066  hit.
15067 \end_layout
15068
15069 \begin_layout Standard
15070 It is most efficient if your ISR calls no other functions.
15071  If your ISR must call other functions, it is most efficient if those functions
15072  use the same bank as the ISR (see note 1 below); the next best is if the
15073  called functions use bank zero.
15074  It is very inefficient to call a function using a different, non-zero bank
15075  from an ISR.
15076  
15077 \begin_inset VSpace bigskip
15078 \end_inset
15079
15080
15081 \end_layout
15082
15083 \begin_layout Section
15084 Startup Code
15085 \begin_inset LatexCommand \label{sub:Startup-Code}
15086
15087 \end_inset
15088
15089
15090 \begin_inset LatexCommand \index{Startup code}
15091
15092 \end_inset
15093
15094
15095 \end_layout
15096
15097 \begin_layout Subsection
15098 MCS51/DS390 Startup Code
15099 \end_layout
15100
15101 \begin_layout Standard
15102 The compiler triggers the linker to link certain initialization modules
15103  from the runtime library
15104 \begin_inset LatexCommand \index{Runtime library}
15105
15106 \end_inset
15107
15108  called crt<something>.
15109  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15110  GSINIT5) is not linked unless the --xstack option is used.
15111  These modules are highly entangled by the use of special segments/areas,
15112  but a common layout is shown below:
15113 \end_layout
15114
15115 \begin_layout Verse
15116
15117 \family typewriter
15118 \series bold
15119 \size footnotesize
15120 (main.asm)
15121 \end_layout
15122
15123 \begin_layout Verse
15124
15125 \family typewriter
15126 \size footnotesize
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 \InsetSpace ~
15134 \InsetSpace ~
15135 .area HOME (CODE)
15136 \newline
15137 __interrupt_vect:
15138 \newline
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 \InsetSpace ~
15145 \InsetSpace ~
15146 \InsetSpace ~
15147 ljmp __sdcc_gsinit_startup
15148 \end_layout
15149
15150 \begin_layout Verse
15151
15152 \family typewriter
15153 \series bold
15154 \size footnotesize
15155 (crtstart.asm)
15156 \end_layout
15157
15158 \begin_layout Verse
15159
15160 \family typewriter
15161 \size footnotesize
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 \InsetSpace ~
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 .area GSINIT0 (CODE)
15171 \newline
15172 __sdcc_gsinit_startup::
15173 \newline
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
15177 \InsetSpace ~
15178 \InsetSpace ~
15179 \InsetSpace ~
15180 \InsetSpace ~
15181 \InsetSpace ~
15182 mov sp,#__start__stack - 1
15183 \end_layout
15184
15185 \begin_layout Verse
15186
15187 \family typewriter
15188 \series bold
15189 \size footnotesize
15190 (crtxstack.asm)
15191 \end_layout
15192
15193 \begin_layout Verse
15194
15195 \family typewriter
15196 \size footnotesize
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 \InsetSpace ~
15201 \InsetSpace ~
15202 \InsetSpace ~
15203 \InsetSpace ~
15204 \InsetSpace ~
15205 .area GSINIT1 (CODE)
15206 \newline
15207 __sdcc_init_xstack::
15208 \newline
15209 ; Need to initialize in GSINIT1 in
15210  case the user's __sdcc_external_startup uses the xstack.
15211 \newline
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 \InsetSpace ~
15215 \InsetSpace ~
15216 \InsetSpace ~
15217 \InsetSpace ~
15218 \InsetSpace ~
15219 \InsetSpace ~
15220 mov __XPAGE,#(__start__x
15221 stack >> 8)
15222 \newline
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 \InsetSpace ~
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 \InsetSpace ~
15229 \InsetSpace ~
15230 \InsetSpace ~
15231 mov _spx,#__start__xstack
15232 \end_layout
15233
15234 \begin_layout Verse
15235
15236 \family typewriter
15237 \series bold
15238 \size footnotesize
15239 (crtstart.asm)
15240 \end_layout
15241
15242 \begin_layout Verse
15243
15244 \family typewriter
15245 \size footnotesize
15246 \InsetSpace ~
15247 \InsetSpace ~
15248 \InsetSpace ~
15249 \InsetSpace ~
15250 \InsetSpace ~
15251 \InsetSpace ~
15252 \InsetSpace ~
15253 \InsetSpace ~
15254 .area GSINIT2 (CODE)
15255 \newline
15256 \InsetSpace ~
15257 \InsetSpace ~
15258 \InsetSpace ~
15259 \InsetSpace ~
15260 \InsetSpace ~
15261 \InsetSpace ~
15262 \InsetSpace ~
15263 \InsetSpace ~
15264 lcall __sdcc_external_startup
15265 \newline
15266 \InsetSpace ~
15267 \InsetSpace ~
15268 \InsetSpace ~
15269 \InsetSpace ~
15270 \InsetSpace ~
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 \InsetSpace ~
15274 mov a,dpl
15275 \newline
15276 \InsetSpace ~
15277 \InsetSpace ~
15278 \InsetSpace ~
15279 \InsetSpace ~
15280 \InsetSpace ~
15281 \InsetSpace ~
15282 \InsetSpace ~
15283 \InsetSpace ~
15284 jz __sdcc_init_data
15285 \newline
15286 \InsetSpace ~
15287 \InsetSpace ~
15288 \InsetSpace ~
15289 \InsetSpace ~
15290 \InsetSpace ~
15291 \InsetSpace ~
15292 \InsetSpace ~
15293 \InsetSpace ~
15294 ljmp
15295  __sdcc_program_startup
15296 \newline
15297 __sdcc_init_data:
15298 \end_layout
15299
15300 \begin_layout Verse
15301
15302 \family typewriter
15303 \series bold
15304 \size footnotesize
15305 (crtxinit.asm)
15306 \end_layout
15307
15308 \begin_layout Verse
15309
15310 \family typewriter
15311 \size footnotesize
15312 \InsetSpace ~
15313 \InsetSpace ~
15314 \InsetSpace ~
15315 \InsetSpace ~
15316 \InsetSpace ~
15317 \InsetSpace ~
15318 \InsetSpace ~
15319 \InsetSpace ~
15320 .area GSINIT3 (CODE)
15321 \newline
15322 __mcs51_genXINIT::
15323 \newline
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 \InsetSpace ~
15327 \InsetSpace ~
15328 \InsetSpace ~
15329 \InsetSpace ~
15330 \InsetSpace ~
15331 \InsetSpace ~
15332 mov r1,#l_XINIT
15333 \newline
15334 \InsetSpace ~
15335 \InsetSpace ~
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 \InsetSpace ~
15340 \InsetSpace ~
15341 \InsetSpace ~
15342 mov a,r1
15343 \newline
15344 \InsetSpace ~
15345 \InsetSpace ~
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 \InsetSpace ~
15350 \InsetSpace ~
15351 \InsetSpace ~
15352 orl a,#(l_XINIT
15353  >> 8)
15354 \newline
15355 \InsetSpace ~
15356 \InsetSpace ~
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 \InsetSpace ~
15360 \InsetSpace ~
15361 \InsetSpace ~
15362 \InsetSpace ~
15363 jz 00003$
15364 \newline
15365 \InsetSpace ~
15366 \InsetSpace ~
15367 \InsetSpace ~
15368 \InsetSpace ~
15369 \InsetSpace ~
15370 \InsetSpace ~
15371 \InsetSpace ~
15372 \InsetSpace ~
15373 mov r2,#((l_XINIT+255) >> 8)
15374 \newline
15375 \InsetSpace ~
15376 \InsetSpace ~
15377 \InsetSpace ~
15378 \InsetSpace ~
15379 \InsetSpace ~
15380 \InsetSpace ~
15381 \InsetSpace ~
15382 \InsetSpace ~
15383 mov dptr,#s_XINIT
15384 \newline
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 \InsetSpace ~
15389 \InsetSpace ~
15390 \InsetSpace ~
15391 \InsetSpace ~
15392 \InsetSpace ~
15393 mov r0,#s_XISEG
15394 \newline
15395 \InsetSpace ~
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 \InsetSpace ~
15402 \InsetSpace ~
15403 mov
15404  __XPAGE,#(s_XISEG >> 8)
15405 \newline
15406 00001$:\InsetSpace ~
15407 clr a
15408 \newline
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 \InsetSpace ~
15412 \InsetSpace ~
15413 \InsetSpace ~
15414 \InsetSpace ~
15415 \InsetSpace ~
15416 \InsetSpace ~
15417 movc a,@a+dptr
15418 \newline
15419 \InsetSpace ~
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 \InsetSpace ~
15424 \InsetSpace ~
15425 \InsetSpace ~
15426 \InsetSpace ~
15427 movx @r0,a
15428 \newline
15429 \InsetSpace ~
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 \InsetSpace ~
15434 \InsetSpace ~
15435 \InsetSpace ~
15436 \InsetSpace ~
15437 inc dptr
15438 \newline
15439 \InsetSpace ~
15440 \InsetSpace ~
15441 \InsetSpace ~
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 \InsetSpace ~
15445 \InsetSpace ~
15446 \InsetSpace ~
15447 inc
15448  r0
15449 \newline
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 \InsetSpace ~
15454 \InsetSpace ~
15455 \InsetSpace ~
15456 \InsetSpace ~
15457 \InsetSpace ~
15458 cjne r0,#0,00002$
15459 \newline
15460 \InsetSpace ~
15461 \InsetSpace ~
15462 \InsetSpace ~
15463 \InsetSpace ~
15464 \InsetSpace ~
15465 \InsetSpace ~
15466 \InsetSpace ~
15467 \InsetSpace ~
15468 inc __XPAGE
15469 \newline
15470 00002$:\InsetSpace ~
15471 djnz r1,00001$
15472 \newline
15473 \InsetSpace ~
15474 \InsetSpace ~
15475 \InsetSpace ~
15476 \InsetSpace ~
15477 \InsetSpace ~
15478 \InsetSpace ~
15479 \InsetSpace ~
15480 \InsetSpace ~
15481 djnz r2,00001$
15482 \newline
15483 \InsetSpace ~
15484 \InsetSpace ~
15485 \InsetSpace ~
15486 \InsetSpace ~
15487 \InsetSpace ~
15488 \InsetSpace ~
15489 \InsetSpace ~
15490 \InsetSpace ~
15491 mov __XPAGE,#0
15492 xFF
15493 \newline
15494 00003$:
15495 \end_layout
15496
15497 \begin_layout Verse
15498
15499 \family typewriter
15500 \series bold
15501 \size footnotesize
15502 (crtclear.asm)
15503 \end_layout
15504
15505 \begin_layout Verse
15506
15507 \family typewriter
15508 \size footnotesize
15509 \InsetSpace ~
15510 \InsetSpace ~
15511 \InsetSpace ~
15512 \InsetSpace ~
15513 \InsetSpace ~
15514 \InsetSpace ~
15515 \InsetSpace ~
15516 \InsetSpace ~
15517 .area GSINIT4 (CODE)
15518 \newline
15519 __mcs51_genRAMCLEAR::
15520 \newline
15521 \InsetSpace ~
15522 \InsetSpace ~
15523 \InsetSpace ~
15524 \InsetSpace ~
15525 \InsetSpace ~
15526 \InsetSpace ~
15527 \InsetSpace ~
15528 \InsetSpace ~
15529 clr a
15530 \newline
15531 \InsetSpace ~
15532 \InsetSpace ~
15533 \InsetSpace ~
15534 \InsetSpace ~
15535 \InsetSpace ~
15536 \InsetSpace ~
15537 \InsetSpace ~
15538 \InsetSpace ~
15539 mov r0,#(l_IRAM-1)
15540 \newline
15541 00004$:\InsetSpace ~
15542 mov
15543  @r0,a
15544 \newline
15545 \InsetSpace ~
15546 \InsetSpace ~
15547 \InsetSpace ~
15548 \InsetSpace ~
15549 \InsetSpace ~
15550 \InsetSpace ~
15551 \InsetSpace ~
15552 \InsetSpace ~
15553 djnz r0,00004$
15554 \newline
15555 ; _mcs51_genRAMCLEAR() end
15556 \end_layout
15557
15558 \begin_layout Verse
15559
15560 \family typewriter
15561 \series bold
15562 \size footnotesize
15563 (crtxclear.asm)
15564 \end_layout
15565
15566 \begin_layout Verse
15567
15568 \family typewriter
15569 \size footnotesize
15570 \InsetSpace ~
15571 \InsetSpace ~
15572 \InsetSpace ~
15573 \InsetSpace ~
15574 \InsetSpace ~
15575 \InsetSpace ~
15576 \InsetSpace ~
15577 \InsetSpace ~
15578 .area GSINIT4 (CODE)
15579 \newline
15580 __mcs51_genXRAMCLEAR::
15581 \newline
15582 \InsetSpace ~
15583 \InsetSpace ~
15584 \InsetSpace ~
15585 \InsetSpace ~
15586 \InsetSpace ~
15587 \InsetSpace ~
15588 \InsetSpace ~
15589 \InsetSpace ~
15590 mov r0,#l_PSEG
15591 \newline
15592 \InsetSpace ~
15593 \InsetSpace ~
15594 \InsetSpace ~
15595 \InsetSpace ~
15596 \InsetSpace ~
15597 \InsetSpace ~
15598 \InsetSpace ~
15599 \InsetSpace ~
15600 mov a,r0
15601 \newline
15602 \InsetSpace ~
15603 \InsetSpace ~
15604 \InsetSpace ~
15605 \InsetSpace ~
15606 \InsetSpace ~
15607 \InsetSpace ~
15608 \InsetSpace ~
15609 \InsetSpace ~
15610 jz 00006$
15611 \newline
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 \InsetSpace ~
15618 \InsetSpace ~
15619 \InsetSpace ~
15620 mov
15621  r1,#s_PSEG
15622 \newline
15623 \InsetSpace ~
15624 \InsetSpace ~
15625 \InsetSpace ~
15626 \InsetSpace ~
15627 \InsetSpace ~
15628 \InsetSpace ~
15629 \InsetSpace ~
15630 \InsetSpace ~
15631 mov __XPAGE,#(s_PSEG >> 8)
15632 \newline
15633 \InsetSpace ~
15634 \InsetSpace ~
15635 \InsetSpace ~
15636 \InsetSpace ~
15637 \InsetSpace ~
15638 \InsetSpace ~
15639 \InsetSpace ~
15640 \InsetSpace ~
15641 clr a
15642 \newline
15643 00005$:\InsetSpace ~
15644 movx @r1,a
15645 \newline
15646 \InsetSpace ~
15647 \InsetSpace ~
15648 \InsetSpace ~
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 \InsetSpace ~
15654 inc r1
15655 \newline
15656 \InsetSpace ~
15657 \InsetSpace ~
15658 \InsetSpace ~
15659 \InsetSpace ~
15660 \InsetSpace ~
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 \InsetSpace ~
15664 djnz r0,00005$
15665 \newline
15666 0
15667 0006$:
15668 \newline
15669 \InsetSpace ~
15670 \InsetSpace ~
15671 \InsetSpace ~
15672 \InsetSpace ~
15673 \InsetSpace ~
15674 \InsetSpace ~
15675 \InsetSpace ~
15676 \InsetSpace ~
15677 mov r0,#l_XSEG
15678 \newline
15679 \InsetSpace ~
15680 \InsetSpace ~
15681 \InsetSpace ~
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 mov a,r0
15688 \newline
15689 \InsetSpace ~
15690 \InsetSpace ~
15691 \InsetSpace ~
15692 \InsetSpace ~
15693 \InsetSpace ~
15694 \InsetSpace ~
15695 \InsetSpace ~
15696 \InsetSpace ~
15697 orl a,#(l_XSEG >> 8)
15698 \newline
15699 \InsetSpace ~
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 \InsetSpace ~
15703 \InsetSpace ~
15704 \InsetSpace ~
15705 \InsetSpace ~
15706 \InsetSpace ~
15707 jz 00008$
15708 \newline
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 \InsetSpace ~
15716 \InsetSpace ~
15717 mov r1,#((l_XSEG
15718  + 255) >> 8)
15719 \newline
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 \InsetSpace ~
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 mov dptr,#s_XSEG
15729 \newline
15730 \InsetSpace ~
15731 \InsetSpace ~
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 clr a
15739 \newline
15740 00007$:\InsetSpace ~
15741 movx @dptr,a
15742 \newline
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 \InsetSpace ~
15747 \InsetSpace ~
15748 \InsetSpace ~
15749 \InsetSpace ~
15750 \InsetSpace ~
15751 inc dptr
15752 \newline
15753 \InsetSpace ~
15754 \InsetSpace ~
15755 \InsetSpace ~
15756 \InsetSpace ~
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 \InsetSpace ~
15760 \InsetSpace ~
15761 djnz r0,00007$
15762 \newline
15763 \InsetSpace ~
15764 \InsetSpace ~
15765 \InsetSpace ~
15766 \InsetSpace ~
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 djnz
15772  r1,00007$
15773 \newline
15774 00008$:
15775 \end_layout
15776
15777 \begin_layout Verse
15778
15779 \family typewriter
15780 \series bold
15781 \size footnotesize
15782 (crtxstack.asm)
15783 \end_layout
15784
15785 \begin_layout Verse
15786
15787 \family typewriter
15788 \size footnotesize
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 \InsetSpace ~
15795 \InsetSpace ~
15796 \InsetSpace ~
15797 .area GSINIT5 (CODE)
15798 \newline
15799 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15800  modifies __XPAGE
15801 \newline
15802 ; and __mcs51_genRAMCLEAR modifies _spx.
15803 \newline
15804 \InsetSpace ~
15805 \InsetSpace ~
15806 \InsetSpace ~
15807 \InsetSpace ~
15808 \InsetSpace ~
15809 \InsetSpace ~
15810 \InsetSpace ~
15811 \InsetSpace ~
15812 mov __XPAGE,#(__start__x
15813 stack >> 8)
15814 \newline
15815 \InsetSpace ~
15816 \InsetSpace ~
15817 \InsetSpace ~
15818 \InsetSpace ~
15819 \InsetSpace ~
15820 \InsetSpace ~
15821 \InsetSpace ~
15822 \InsetSpace ~
15823 mov _spx,#__start__xstack
15824 \end_layout
15825
15826 \begin_layout Verse
15827
15828 \family typewriter
15829 \series bold
15830 \size footnotesize
15831 (application modules)
15832 \end_layout
15833
15834 \begin_layout Verse
15835
15836 \family typewriter
15837 \size footnotesize
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 \InsetSpace ~
15841 \InsetSpace ~
15842 \InsetSpace ~
15843 \InsetSpace ~
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 .area GSINIT (CODE)
15847 \end_layout
15848
15849 \begin_layout Verse
15850
15851 \family typewriter
15852 \series bold
15853 \size footnotesize
15854 (main.asm)
15855 \end_layout
15856
15857 \begin_layout Verse
15858
15859 \family typewriter
15860 \size footnotesize
15861 \InsetSpace ~
15862 \InsetSpace ~
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 .area GSFINAL (CODE)
15870 \newline
15871 \InsetSpace ~
15872 \InsetSpace ~
15873 \InsetSpace ~
15874 \InsetSpace ~
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 ljmp __sdcc_program_startup
15880 \newline
15881 ;---------------------------------
15882 -----------------------
15883 \newline
15884 ; Home
15885 \newline
15886 ;--------------------------------------------------
15887 ------
15888 \newline
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 .area HOME (CODE)
15898 \newline
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 .area CSEG (CODE)
15908 \newline
15909 __sdcc_program_startup:
15910 \newline
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 lcall _main
15920 \newline
15921 ;
15922  return from main will lock up
15923 \newline
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 sjmp .
15933 \end_layout
15934
15935 \begin_layout Standard
15936 One of these modules (crtstart.asm) contains a call to the C routine 
15937 \emph on
15938 _sdcc_external_startup()
15939 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15940
15941 \end_inset
15942
15943
15944 \series bold
15945 \emph default
15946  
15947 \series default
15948 at the start of the CODE area.
15949  This routine is also in the runtime library
15950 \begin_inset LatexCommand \index{Runtime library}
15951
15952 \end_inset
15953
15954  and returns 0 by default.
15955  If this routine returns a non-zero value, the static & global variable
15956  initialization will be skipped and the function main will be invoked.
15957  Otherwise static & global variables will be initialized before the function
15958  main is invoked.
15959  You could add an 
15960 \emph on
15961 _sdcc_external_startup()
15962 \emph default
15963  routine to your program to override the default if you need to setup hardware
15964  or perform some other critical operation prior to static & global variable
15965  initialization
15966 \begin_inset LatexCommand \index{Variable initialization}
15967
15968 \end_inset
15969
15970 .
15971  On some mcs51 variants xdata
15972 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15973
15974 \end_inset
15975
15976  memory has to be explicitly enabled before it can be accessed or if the
15977  watchdog
15978 \begin_inset LatexCommand \index{watchdog}
15979
15980 \end_inset
15981
15982  needs to be disabled, this is the place to do it.
15983  The startup code clears all internal data memory, 256 bytes by default,
15984  but from 0 to n-1 if 
15985 \emph on
15986 -
15987 \begin_inset ERT
15988 status collapsed
15989
15990 \begin_layout Standard
15991
15992
15993 \backslash
15994 /
15995 \end_layout
15996
15997 \end_inset
15998
15999 -iram-size
16000 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16001
16002 \end_inset
16003
16004 n
16005 \emph default
16006  is used.
16007  (recommended for Chipcon CC1010).
16008 \end_layout
16009
16010 \begin_layout Standard
16011 See also the compiler options 
16012 \emph on
16013 -
16014 \begin_inset ERT
16015 status collapsed
16016
16017 \begin_layout Standard
16018
16019
16020 \backslash
16021 /
16022 \end_layout
16023
16024 \end_inset
16025
16026 -no-xinit
16027 \emph default
16028 -
16029 \emph on
16030 opt
16031 \emph default
16032
16033 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16034
16035 \end_inset
16036
16037
16038 \emph on
16039 -
16040 \begin_inset ERT
16041 status collapsed
16042
16043 \begin_layout Standard
16044
16045
16046 \backslash
16047 /
16048 \end_layout
16049
16050 \end_inset
16051
16052 -main-return
16053 \emph default
16054
16055 \begin_inset LatexCommand \index{-\/-main-return}
16056
16057 \end_inset
16058
16059  and section 
16060 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16061
16062 \end_inset
16063
16064  about MCS51-variants.
16065 \begin_inset VSpace bigskip
16066 \end_inset
16067
16068
16069 \end_layout
16070
16071 \begin_layout Subsection
16072 HC08 Startup Code
16073 \end_layout
16074
16075 \begin_layout Standard
16076 The HC08
16077 \begin_inset LatexCommand \index{HC08}
16078
16079 \end_inset
16080
16081  startup code follows the same scheme as the MCS51 startup code.
16082 \begin_inset VSpace bigskip
16083 \end_inset
16084
16085
16086 \end_layout
16087
16088 \begin_layout Subsection
16089 Z80 Startup Code
16090 \end_layout
16091
16092 \begin_layout Standard
16093 On the Z80
16094 \begin_inset LatexCommand \index{Z80}
16095
16096 \end_inset
16097
16098  the startup code is inserted by linking with crt0.o which is generated from
16099  sdcc/device/lib/z80/crt0.s.
16100  If you need a different startup code you can use the compiler option 
16101 \emph on
16102 -
16103 \series bold
16104 \emph default
16105
16106 \begin_inset ERT
16107 status collapsed
16108
16109 \begin_layout Standard
16110
16111
16112 \backslash
16113 /
16114 \end_layout
16115
16116 \end_inset
16117
16118
16119 \series default
16120 \emph on
16121 -no-std-crt0
16122 \emph default
16123
16124 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16125
16126 \end_inset
16127
16128  and provide your own crt0.o.
16129  
16130 \begin_inset VSpace bigskip
16131 \end_inset
16132
16133
16134 \end_layout
16135
16136 \begin_layout Section
16137 Inline Assembler Code
16138 \begin_inset LatexCommand \index{Assembler routines}
16139
16140 \end_inset
16141
16142
16143 \end_layout
16144
16145 \begin_layout Subsection
16146 A Step by Step Introduction
16147 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16148
16149 \end_inset
16150
16151
16152 \end_layout
16153
16154 \begin_layout Standard
16155 Starting from a small snippet of c-code this example shows for the MCS51
16156  how to use inline assembly, access variables, a function parameter and
16157  an array in xdata memory.
16158  The example uses an MCS51 here but is easily adapted for other architectures.
16159  This is a buffer routine which should be optimized:
16160 \end_layout
16161
16162 \begin_layout Verse
16163
16164 \family typewriter
16165 \size footnotesize
16166 unsigned char __far
16167 \begin_inset LatexCommand \index{far (storage class)}
16168
16169 \end_inset
16170
16171
16172 \begin_inset LatexCommand \index{\_\_far (storage class)}
16173
16174 \end_inset
16175
16176  __at
16177 \begin_inset LatexCommand \index{at}
16178
16179 \end_inset
16180
16181
16182 \begin_inset LatexCommand \index{\_\_at}
16183
16184 \end_inset
16185
16186 (0x7f00) buf[0x100];
16187 \begin_inset LatexCommand \index{Aligned array}
16188
16189 \end_inset
16190
16191
16192 \newline
16193 unsigned char head, tail;\InsetSpace ~
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 \InsetSpace ~
16197 \InsetSpace ~
16198 \InsetSpace ~
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 \InsetSpace ~
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 /* if interrupts
16211 \begin_inset LatexCommand \index{interrupt}
16212
16213 \end_inset
16214
16215  are involved see
16216 \newline
16217 \InsetSpace ~
16218 \InsetSpace ~
16219 \InsetSpace ~
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 \InsetSpace ~
16228 \InsetSpace ~
16229 \InsetSpace ~
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 \InsetSpace ~
16237 \InsetSpace ~
16238 \InsetSpace ~
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 \InsetSpace ~
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 \InsetSpace ~
16249 \InsetSpace ~
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 \InsetSpace ~
16259 \InsetSpace ~
16260 \InsetSpace ~
16261 \InsetSpace ~
16262 section 
16263 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16264
16265 \end_inset
16266
16267  about
16268 \series bold
16269  volatile
16270 \series default
16271  */
16272 \newline
16273
16274 \newline
16275 void to_buffer( unsigned char c ) 
16276 \newline
16277 {
16278 \newline
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 \InsetSpace ~
16283 if( head != (unsigned char)(tail-1)
16284  )\InsetSpace ~
16285 /* cast 
16286 \series bold
16287 needed
16288 \series default
16289  to avoid promotion
16290 \begin_inset LatexCommand \index{promotion to signed int}
16291
16292 \end_inset
16293
16294
16295 \begin_inset LatexCommand \index{type promotion}
16296
16297 \end_inset
16298
16299  to integer */
16300 \begin_inset Marginal
16301 status collapsed
16302
16303 \begin_layout Standard
16304
16305 \series bold
16306 \InsetSpace ~
16307 !
16308 \end_layout
16309
16310 \end_inset
16311
16312
16313 \newline
16314 \InsetSpace ~
16315 \InsetSpace ~
16316 \InsetSpace ~
16317 \InsetSpace ~
16318 \InsetSpace ~
16319 \InsetSpace ~
16320 \InsetSpace ~
16321 \InsetSpace ~
16322 buf[ head++ ] = c;\InsetSpace ~
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 \InsetSpace ~
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 \InsetSpace ~
16333 \InsetSpace ~
16334 \InsetSpace ~
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 /* access to a 256 byte aligned array */
16339 \newline
16340
16341 \end_layout
16342
16343 \begin_layout Standard
16344 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16345  then a corresponding buffer.asm file is generated.
16346  We define a new function 
16347 \family typewriter
16348 to_buffer_asm()
16349 \family default
16350  in file buffer.c in which we cut and paste the generated code, removing
16351  unwanted comments and some ':'.
16352  Then add 
16353 \begin_inset Quotes sld
16354 \end_inset
16355
16356
16357 \series bold
16358 _asm
16359 \series default
16360
16361 \begin_inset Quotes srd
16362 \end_inset
16363
16364  and 
16365 \begin_inset Quotes sld
16366 \end_inset
16367
16368
16369 \series bold
16370 _endasm;
16371 \series default
16372
16373 \begin_inset Quotes srd
16374 \end_inset
16375
16376
16377 \begin_inset Foot
16378 status open
16379
16380 \begin_layout Standard
16381 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16382  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16383  has to be used.
16384  The latter is also used in the library functions.
16385 \end_layout
16386
16387 \end_inset
16388
16389  to the beginning and the end of the function body:
16390 \end_layout
16391
16392 \begin_layout Verse
16393
16394 \family typewriter
16395 \size footnotesize
16396 /* With a cut and paste from the .asm file, we have something to start with.
16397 \newline
16398 \InsetSpace ~
16399 \InsetSpace ~
16400 \InsetSpace ~
16401 The
16402  function is not yet OK! (registers aren't saved) */ 
16403 \newline
16404 void to_buffer_asm(
16405  unsigned char c ) 
16406 \newline
16407
16408 \newline
16409 \InsetSpace ~
16410 \InsetSpace ~
16411 \InsetSpace ~
16412 \InsetSpace ~
16413 _asm
16414 \begin_inset LatexCommand \index{\_asm}
16415
16416 \end_inset
16417
16418
16419 \begin_inset LatexCommand \index{\_\_asm}
16420
16421 \end_inset
16422
16423
16424 \newline
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 \InsetSpace ~
16428 \InsetSpace ~
16429 mov\InsetSpace ~
16430 \InsetSpace ~
16431 r2,dpl 
16432 \newline
16433 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16434 /* cast 
16435 \series bold
16436 needed
16437 \series default
16438  to avoid promotion
16439 \begin_inset LatexCommand \index{promotion to signed int}
16440
16441 \end_inset
16442
16443
16444 \begin_inset LatexCommand \index{type promotion}
16445
16446 \end_inset
16447
16448  to integer */
16449 \newline
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 \InsetSpace ~
16453 \InsetSpace ~
16454 mov\InsetSpace ~
16455 \InsetSpace ~
16456 a,_tail 
16457 \newline
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 dec\InsetSpace ~
16463 \InsetSpace ~
16464
16465 \newline
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 \InsetSpace ~
16470 mov\InsetSpace ~
16471 \InsetSpace ~
16472 r3,a 
16473 \newline
16474 \InsetSpace ~
16475 \InsetSpace ~
16476 \InsetSpace ~
16477 \InsetSpace ~
16478 mov\InsetSpace ~
16479 \InsetSpace ~
16480 a,_head 
16481 \newline
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 \InsetSpace ~
16486 cjne a,ar3,00106$ 
16487 \newline
16488 \InsetSpace ~
16489 \InsetSpace ~
16490 \InsetSpace ~
16491 \InsetSpace ~
16492 ret
16493 \newline
16494 00106$:
16495  
16496 \newline
16497 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16498 \begin_inset LatexCommand \index{Aligned array}
16499
16500 \end_inset
16501
16502
16503 \newline
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 mov\InsetSpace ~
16509 \InsetSpace ~
16510 r3,_head 
16511 \newline
16512 \InsetSpace ~
16513 \InsetSpace ~
16514 \InsetSpace ~
16515 \InsetSpace ~
16516 inc\InsetSpace ~
16517 \InsetSpace ~
16518 _head 
16519 \newline
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 \InsetSpace ~
16524 mov\InsetSpace ~
16525 \InsetSpace ~
16526 dpl,r3 
16527 \newline
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 \InsetSpace ~
16531 \InsetSpace ~
16532 mov\InsetSpace ~
16533 \InsetSpace ~
16534 dph,#(_buf >> 8) 
16535 \newline
16536 \InsetSpace ~
16537 \InsetSpace ~
16538 \InsetSpace ~
16539 \InsetSpace ~
16540 mov\InsetSpace ~
16541 \InsetSpace ~
16542 a,r2 
16543 \newline
16544 \InsetSpace ~
16545 \InsetSpace ~
16546 \InsetSpace ~
16547 \InsetSpace ~
16548 movx @dptr,a
16549  
16550 \newline
16551 00103$: 
16552 \newline
16553 \InsetSpace ~
16554 \InsetSpace ~
16555 \InsetSpace ~
16556 \InsetSpace ~
16557 ret
16558 \newline
16559 \InsetSpace ~
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 _endasm
16564 \begin_inset LatexCommand \index{\_endasm}
16565
16566 \end_inset
16567
16568
16569 \begin_inset LatexCommand \index{\_\_endasm}
16570
16571 \end_inset
16572
16573 ;
16574 \newline
16575
16576 \end_layout
16577
16578 \begin_layout Standard
16579 The new file buffer.c should compile with only one warning about the unreferenced
16580  function argument 'c'.
16581  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16582  (1) and finally have:
16583 \end_layout
16584
16585 \begin_layout Verse
16586
16587 \family typewriter
16588 \size footnotesize
16589 unsigned char __far __at(0x7f00) buf[0x100];
16590 \newline
16591 unsigned char head, tail;
16592 \newline
16593 #define
16594  USE_ASSEMBLY (1)
16595 \newline
16596
16597 \newline
16598 #if !USE_ASSEMBLY
16599 \newline
16600
16601 \newline
16602 void to_buffer( unsigned char c )
16603 \newline
16604 {
16605 \newline
16606 \InsetSpace ~
16607 \InsetSpace ~
16608 \InsetSpace ~
16609 \InsetSpace ~
16610 if(
16611  head != (unsigned char)(tail-1) )
16612 \newline
16613 \InsetSpace ~
16614 \InsetSpace ~
16615 \InsetSpace ~
16616 \InsetSpace ~
16617 \InsetSpace ~
16618 \InsetSpace ~
16619 \InsetSpace ~
16620 \InsetSpace ~
16621 buf[ head++ ] = c;
16622 \newline
16623 }
16624 \newline
16625
16626 \newline
16627 #else
16628 \newline
16629
16630 \newline
16631 void to_buffer(
16632  unsigned char c )
16633 \newline
16634 {
16635 \newline
16636 \InsetSpace ~
16637 \InsetSpace ~
16638 \InsetSpace ~
16639 \InsetSpace ~
16640 c; // to avoid warning: unreferenced function argument
16641 \newline
16642 \InsetSpace ~
16643 \InsetSpace ~
16644 \InsetSpace ~
16645 \InsetSpace ~
16646 _asm
16647 \begin_inset LatexCommand \index{\_asm}
16648
16649 \end_inset
16650
16651
16652 \begin_inset LatexCommand \index{\_\_asm}
16653
16654 \end_inset
16655
16656
16657 \newline
16658 \InsetSpace ~
16659 \InsetSpace ~
16660 \InsetSpace ~
16661 \InsetSpace ~
16662 \InsetSpace ~
16663 \InsetSpace ~
16664 \InsetSpace ~
16665 \InsetSpace ~
16666 ; save used registers here.
16667  
16668 \newline
16669 \InsetSpace ~
16670 \InsetSpace ~
16671 \InsetSpace ~
16672 \InsetSpace ~
16673 \InsetSpace ~
16674 \InsetSpace ~
16675 \InsetSpace ~
16676 \InsetSpace ~
16677 ; If we were still using r2,r3 we would have to push them here.
16678  
16679 \newline
16680 ; if( head != (unsigned char)(tail-1) )
16681 \newline
16682 \InsetSpace ~
16683 \InsetSpace ~
16684 \InsetSpace ~
16685 \InsetSpace ~
16686 \InsetSpace ~
16687 \InsetSpace ~
16688 \InsetSpace ~
16689 \InsetSpace ~
16690 mov\InsetSpace ~
16691  a,_tail
16692 \newline
16693 \InsetSpace ~
16694 \InsetSpace ~
16695 \InsetSpace ~
16696 \InsetSpace ~
16697 \InsetSpace ~
16698 \InsetSpace ~
16699 \InsetSpace ~
16700 \InsetSpace ~
16701 dec\InsetSpace ~
16702  a
16703 \newline
16704 \InsetSpace ~
16705 \InsetSpace ~
16706 \InsetSpace ~
16707 \InsetSpace ~
16708 \InsetSpace ~
16709 \InsetSpace ~
16710 \InsetSpace ~
16711 \InsetSpace ~
16712 xrl\InsetSpace ~
16713  a,_head
16714 \newline
16715 \InsetSpace ~
16716 \InsetSpace ~
16717 \InsetSpace ~
16718 \InsetSpace ~
16719 \InsetSpace ~
16720 \InsetSpace ~
16721 \InsetSpace ~
16722 \InsetSpace ~
16723 ; we
16724  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16725 \newline
16726 \InsetSpace ~
16727 \InsetSpace ~
16728 \InsetSpace ~
16729 \InsetSpace ~
16730 \InsetSpace ~
16731 \InsetSpace ~
16732 \InsetSpace ~
16733 \InsetSpace ~
16734 jz\InsetSpace ~
16735 \InsetSpace ~
16736  t_b_end$
16737 \newline
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 \InsetSpace ~
16741 \InsetSpace ~
16742 \InsetSpace ~
16743 \InsetSpace ~
16744 \InsetSpace ~
16745 \InsetSpace ~
16746 ;
16747 \newline
16748 ;
16749  buf[ head++ ] = c;
16750 \newline
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 \InsetSpace ~
16756 \InsetSpace ~
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 mov\InsetSpace ~
16760  a,dpl \InsetSpace ~
16761 \InsetSpace ~
16762 \InsetSpace ~
16763 \InsetSpace ~
16764 \InsetSpace ~
16765 \InsetSpace ~
16766 \InsetSpace ~
16767 ; dpl holds lower byte of function argument
16768 \newline
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 \InsetSpace ~
16773 \InsetSpace ~
16774 \InsetSpace ~
16775 \InsetSpace ~
16776 \InsetSpace ~
16777 mov\InsetSpace ~
16778
16779  dpl,_head \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 ; buf is 0x100 byte aligned so head can be used directly
16783 \newline
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 \InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 mov\InsetSpace ~
16793  dph,#(_bu
16794 f>>8)
16795 \newline
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 \InsetSpace ~
16800 \InsetSpace ~
16801 \InsetSpace ~
16802 \InsetSpace ~
16803 \InsetSpace ~
16804 movx @dptr,a
16805 \newline
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 \InsetSpace ~
16810 \InsetSpace ~
16811 \InsetSpace ~
16812 \InsetSpace ~
16813 \InsetSpace ~
16814 inc \InsetSpace ~
16815 _head
16816 \newline
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 \InsetSpace ~
16824 \InsetSpace ~
16825 ; we could do an ANL _head,#0x0f here to use a
16826  smaller buffer (see above)
16827 \newline
16828 t_b_end$:
16829 \newline
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 \InsetSpace ~
16834 \InsetSpace ~
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 ; restore used registers here 
16839 \newline
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 _endasm
16845 \begin_inset LatexCommand \index{\_endasm}
16846
16847 \end_inset
16848
16849
16850 \begin_inset LatexCommand \index{\_\_endasm}
16851
16852 \end_inset
16853
16854 ;
16855 \newline
16856 }
16857 \newline
16858 #endif
16859 \end_layout
16860
16861 \begin_layout Standard
16862 The inline assembler code can contain any valid code understood by the assembler
16863 , this includes any assembler directives and comment lines.
16864  The assembler does not like some characters like ':' or ''' in comments.
16865  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16866 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16867
16868 \end_inset
16869
16870
16871 \begin_inset LatexCommand \index{Assembler documentation}
16872
16873 \end_inset
16874
16875  or online at 
16876 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16877
16878 \end_inset
16879
16880 \InsetSpace ~
16881 .
16882 \end_layout
16883
16884 \begin_layout Standard
16885 The compiler does not do any validation of the code within the 
16886 \family typewriter
16887 _asm
16888 \begin_inset LatexCommand \index{\_asm}
16889
16890 \end_inset
16891
16892
16893 \begin_inset LatexCommand \index{\_\_asm}
16894
16895 \end_inset
16896
16897  ...
16898  _endasm
16899 \size footnotesize
16900
16901 \begin_inset LatexCommand \index{\_endasm}
16902
16903 \end_inset
16904
16905
16906 \begin_inset LatexCommand \index{\_\_endasm}
16907
16908 \end_inset
16909
16910
16911 \size default
16912 ;
16913 \family default
16914  keyword pair.
16915  Specifically it will not know which registers are used and thus register
16916  pushing/popping
16917 \begin_inset LatexCommand \index{push/pop}
16918
16919 \end_inset
16920
16921  has to be done manually.
16922  
16923 \end_layout
16924
16925 \begin_layout Standard
16926 It is recommended that each assembly instruction (including labels) be placed
16927  in a separate line (as the example shows).
16928  When the -
16929 \begin_inset ERT
16930 status collapsed
16931
16932 \begin_layout Standard
16933
16934
16935 \backslash
16936 /
16937 \end_layout
16938
16939 \end_inset
16940
16941 -
16942 \emph on
16943 peep-asm
16944 \begin_inset LatexCommand \index{-\/-peep-asm}
16945
16946 \end_inset
16947
16948
16949 \emph default
16950  command line option is used, the inline assembler code will be passed through
16951  the peephole optimizer
16952 \begin_inset LatexCommand \index{Peephole optimizer}
16953
16954 \end_inset
16955
16956 .
16957  There are only a few (if any) cases where this option makes sense, it might
16958  cause some unexpected changes in the inline assembler code.
16959  Please go through the peephole optimizer rules defined in file 
16960 \emph on
16961 SDCCpeeph.def
16962 \emph default
16963  before using this option.
16964 \end_layout
16965
16966 \begin_layout Subsection
16967 Naked Functions
16968 \begin_inset LatexCommand \label{sub:Naked-Functions}
16969
16970 \end_inset
16971
16972
16973 \begin_inset LatexCommand \index{Naked functions}
16974
16975 \end_inset
16976
16977
16978 \end_layout
16979
16980 \begin_layout Standard
16981 A special keyword may be associated with a function declaring it as 
16982 \emph on
16983 _naked
16984 \begin_inset LatexCommand \index{\_naked}
16985
16986 \end_inset
16987
16988
16989 \begin_inset LatexCommand \index{\_\_naked}
16990
16991 \end_inset
16992
16993 .
16994  
16995 \emph default
16996 The 
16997 \emph on
16998 _naked
16999 \emph default
17000  function modifier attribute prevents the compiler from generating prologue
17001 \begin_inset LatexCommand \index{function prologue}
17002
17003 \end_inset
17004
17005  and epilogue
17006 \begin_inset LatexCommand \index{function epilogue}
17007
17008 \end_inset
17009
17010  code for that function.
17011  This means that the user is entirely responsible for such things as saving
17012  any registers that may need to be preserved, selecting the proper register
17013  bank, generating the 
17014 \emph on
17015 return
17016 \emph default
17017  instruction at the end, etc.
17018  Practically, this means that the contents of the function must be written
17019  in inline assembler.
17020  This is particularly useful for interrupt functions, which can have a large
17021  (and often unnecessary) prologue/epilogue.
17022  For example, compare the code generated by these two functions:
17023 \end_layout
17024
17025 \begin_layout Verse
17026
17027 \family typewriter
17028 volatile
17029 \begin_inset LatexCommand \index{volatile}
17030
17031 \end_inset
17032
17033  data unsigned char counter;
17034 \newline
17035
17036 \newline
17037 void simpleInterrupt(void) __interrupt
17038 \begin_inset LatexCommand \index{interrupt}
17039
17040 \end_inset
17041
17042
17043 \begin_inset LatexCommand \index{\_\_interrupt}
17044
17045 \end_inset
17046
17047  (1)
17048 \newline
17049 {
17050 \newline
17051 \InsetSpace ~
17052 \InsetSpace ~
17053 \InsetSpace ~
17054 \InsetSpace ~
17055 counter++;
17056 \newline
17057 }
17058 \newline
17059
17060 \newline
17061 void nakedInterrupt(void) __interrupt (2) __naked
17062 \newline
17063 {
17064 \newline
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 \InsetSpace ~
17068 \InsetSpace ~
17069 _asm
17070 \begin_inset LatexCommand \index{\_asm}
17071
17072 \end_inset
17073
17074
17075 \begin_inset LatexCommand \index{\_\_asm}
17076
17077 \end_inset
17078
17079
17080 \newline
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 inc\InsetSpace ~
17088 \InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 \InsetSpace ~
17092 _counter ; does not change flags, no need to save psw
17093 \newline
17094 \InsetSpace ~
17095 \InsetSpace ~
17096 \InsetSpace ~
17097 \InsetSpace ~
17098 \InsetSpace ~
17099 \InsetSpace ~
17100 reti\InsetSpace ~
17101 \InsetSpace ~
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 ; MUST explicitly
17105  include ret or reti in _naked function.
17106 \newline
17107 \InsetSpace ~
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 _endasm
17112 \begin_inset LatexCommand \index{\_endasm}
17113
17114 \end_inset
17115
17116
17117 \begin_inset LatexCommand \index{\_\_endasm}
17118
17119 \end_inset
17120
17121 ;
17122 \newline
17123 }
17124 \end_layout
17125
17126 \begin_layout Standard
17127 For an 8051 target, the generated simpleInterrupt looks like:
17128 \end_layout
17129
17130 \begin_layout Verse
17131
17132 \family typewriter
17133 Note, this is an 
17134 \emph on
17135 outdated
17136 \emph default
17137  example, recent versions of SDCC generate
17138 \newline
17139 the 
17140 \emph on
17141 same
17142 \emph default
17143  code for simpleInterrupt() and nakedInterrupt()!
17144 \newline
17145
17146 \newline
17147 _simpleInterrupt:
17148 \newline
17149 \InsetSpace ~
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 push\InsetSpace ~
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 \InsetSpace ~
17157 acc
17158 \newline
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 \InsetSpace ~
17162 \InsetSpace ~
17163 push\InsetSpace ~
17164 \InsetSpace ~
17165 \InsetSpace ~
17166 \InsetSpace ~
17167 b
17168 \newline
17169 \InsetSpace ~
17170 \InsetSpace ~
17171 \InsetSpace ~
17172 \InsetSpace ~
17173 pu
17174 sh\InsetSpace ~
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 dpl
17179 \newline
17180 \InsetSpace ~
17181 \InsetSpace ~
17182 \InsetSpace ~
17183 \InsetSpace ~
17184 push\InsetSpace ~
17185 \InsetSpace ~
17186 \InsetSpace ~
17187 \InsetSpace ~
17188 dph
17189 \newline
17190 \InsetSpace ~
17191 \InsetSpace ~
17192 \InsetSpace ~
17193 \InsetSpace ~
17194 push\InsetSpace ~
17195 \InsetSpace ~
17196 \InsetSpace ~
17197 \InsetSpace ~
17198 psw
17199 \newline
17200 \InsetSpace ~
17201 \InsetSpace ~
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 mov\InsetSpace ~
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 psw,#0x00
17210 \newline
17211 \InsetSpace ~
17212 \InsetSpace ~
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 inc\InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 _counter
17221 \newline
17222 \InsetSpace ~
17223 \InsetSpace ~
17224 \InsetSpace ~
17225 \InsetSpace ~
17226 pop\InsetSpace ~
17227 \InsetSpace ~
17228 \InsetSpace ~
17229 \InsetSpace ~
17230 \InsetSpace ~
17231 psw
17232 \newline
17233 \InsetSpace ~
17234 \InsetSpace ~
17235 \InsetSpace ~
17236 \InsetSpace ~
17237 pop\InsetSpace ~
17238 \InsetSpace ~
17239 \InsetSpace ~
17240 \InsetSpace ~
17241 \InsetSpace ~
17242 dph
17243 \newline
17244 \InsetSpace ~
17245 \InsetSpace ~
17246 \InsetSpace ~
17247 \InsetSpace ~
17248 pop\InsetSpace ~
17249 \InsetSpace ~
17250 \InsetSpace ~
17251 \InsetSpace ~
17252 \InsetSpace ~
17253 dpl
17254 \newline
17255 \InsetSpace ~
17256 \InsetSpace ~
17257 \InsetSpace ~
17258 \InsetSpace ~
17259 pop\InsetSpace ~
17260 \InsetSpace ~
17261 \InsetSpace ~
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 b
17265 \newline
17266 \InsetSpace ~
17267 \InsetSpace ~
17268 \InsetSpace ~
17269 \InsetSpace ~
17270 pop\InsetSpace ~
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 \InsetSpace ~
17274 \InsetSpace ~
17275 acc
17276 \newline
17277 \InsetSpace ~
17278 \InsetSpace ~
17279 \InsetSpace ~
17280 \InsetSpace ~
17281 reti
17282 \end_layout
17283
17284 \begin_layout Standard
17285 whereas nakedInterrupt looks like:
17286 \end_layout
17287
17288 \begin_layout Verse
17289
17290 \family typewriter
17291 _nakedInterrupt:
17292 \newline
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 inc\InsetSpace ~
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 \InsetSpace ~
17301 _counter ; does not change flags, no need to save psw
17302 \newline
17303 \InsetSpace ~
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 reti\InsetSpace ~
17308 \InsetSpace ~
17309 \InsetSpace ~
17310 \InsetSpace ~
17311 \InsetSpace ~
17312 \InsetSpace ~
17313 \InsetSpace ~
17314 \InsetSpace ~
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 ;
17320  MUST explicitly include ret or reti in _naked function
17321 \end_layout
17322
17323 \begin_layout Standard
17324 The related directive #pragma exclude
17325 \begin_inset LatexCommand \index{\#pragma exclude}
17326
17327 \end_inset
17328
17329  allows a more fine grained control over pushing & popping
17330 \begin_inset LatexCommand \index{push/pop}
17331
17332 \end_inset
17333
17334  the registers.
17335 \end_layout
17336
17337 \begin_layout Standard
17338 While there is nothing preventing you from writing C code inside a 
17339 \family typewriter
17340 _naked
17341 \family default
17342  function, there are many ways to shoot yourself in the foot doing this,
17343  and it is recommended that you stick to inline assembler.
17344 \end_layout
17345
17346 \begin_layout Subsection
17347 Use of Labels within Inline Assembler
17348 \end_layout
17349
17350 \begin_layout Standard
17351 SDCC allows the use of in-line assembler with a few restrictions regarding
17352  labels.
17353  All labels defined within inline assembler code have to be of the form
17354  
17355 \emph on
17356 nnnnn$
17357 \emph default
17358  where nnnnn is a number less than 100 (which implies a limit of utmost
17359  100 inline assembler labels 
17360 \emph on
17361 per function
17362 \emph default
17363 \noun on
17364 )
17365 \noun default
17366 .
17367 \begin_inset Foot
17368 status open
17369
17370 \begin_layout Standard
17371 This is a slightly more stringent rule than absolutely necessary, but stays
17372  always on the safe side.
17373  Labels in the form of nnnnn$ are local labels in the assembler, locality
17374  of which is confined within two labels of the standard form.
17375  The compiler uses the same form for labels within a function (but starting
17376  from nnnnn=00100); and places always a standard label at the beginning
17377  of a function, thus limiting the locality of labels within the scope of
17378  the function.
17379  So, if the inline assembler part would be embedded into C-code, an improperly
17380  placed non-local label in the assembler would break up the reference space
17381  for labels created by the compiler for the C-code, leading to an assembling
17382  error.
17383 \end_layout
17384
17385 \begin_layout Standard
17386 The numeric part of local labels does not need to have 5 digits (although
17387  this is the form of labels output by the compiler), any valid integer will
17388  do.
17389  Please refer to the assemblers documentation for further details.
17390 \end_layout
17391
17392 \end_inset
17393
17394  
17395 \end_layout
17396
17397 \begin_layout Verse
17398
17399 \family typewriter
17400 _asm
17401 \begin_inset LatexCommand \index{\_asm}
17402
17403 \end_inset
17404
17405
17406 \begin_inset LatexCommand \index{\_\_asm}
17407
17408 \end_inset
17409
17410  
17411 \newline
17412 \InsetSpace ~
17413 \InsetSpace ~
17414 \InsetSpace ~
17415 \InsetSpace ~
17416 mov\InsetSpace ~
17417 \InsetSpace ~
17418 \InsetSpace ~
17419 \InsetSpace ~
17420 \InsetSpace ~
17421 b,#10 
17422 \newline
17423 00001$: 
17424 \newline
17425 \InsetSpace ~
17426 \InsetSpace ~
17427 \InsetSpace ~
17428 \InsetSpace ~
17429 djnz\InsetSpace ~
17430 \InsetSpace ~
17431 \InsetSpace ~
17432 \InsetSpace ~
17433 b,00001$ 
17434 \newline
17435 _endasm
17436 \begin_inset LatexCommand \index{\_endasm}
17437
17438 \end_inset
17439
17440
17441 \begin_inset LatexCommand \index{\_\_endasm}
17442
17443 \end_inset
17444
17445  ;
17446 \end_layout
17447
17448 \begin_layout Standard
17449 Inline assembler code cannot reference any C-labels, however it can reference
17450  labels
17451 \begin_inset LatexCommand \index{Labels}
17452
17453 \end_inset
17454
17455  defined by the inline assembler, e.g.:
17456 \end_layout
17457
17458 \begin_layout Verse
17459
17460 \family typewriter
17461 foo() { 
17462 \newline
17463 \InsetSpace ~
17464 \InsetSpace ~
17465 \InsetSpace ~
17466 \InsetSpace ~
17467 /* some c code */ 
17468 \newline
17469 \InsetSpace ~
17470 \InsetSpace ~
17471 \InsetSpace ~
17472 \InsetSpace ~
17473 _asm 
17474 \newline
17475 \InsetSpace ~
17476 \InsetSpace ~
17477 \InsetSpace ~
17478 \InsetSpace ~
17479 \InsetSpace ~
17480 \InsetSpace ~
17481 ; some assembler code 
17482 \newline
17483 \InsetSpace ~
17484 \InsetSpace ~
17485 \InsetSpace ~
17486 \InsetSpace ~
17487 \InsetSpace ~
17488 \InsetSpace ~
17489 ljmp 0003$ 
17490 \newline
17491 \InsetSpace ~
17492 \InsetSpace ~
17493 \InsetSpace ~
17494 \InsetSpace ~
17495 _endasm;
17496  
17497 \newline
17498 \InsetSpace ~
17499 \InsetSpace ~
17500 \InsetSpace ~
17501 \InsetSpace ~
17502 /* some more c code */ 
17503 \newline
17504 clabel:\InsetSpace ~
17505 \InsetSpace ~
17506 /* inline assembler cannot reference this
17507  label */ 
17508 \begin_inset Foot
17509 status open
17510
17511 \begin_layout Standard
17512 Here, the C-label 
17513 \family typewriter
17514 clabel
17515 \family default
17516  is translated by the compiler into a local label, so the locality of labels
17517  within the function is not broken.
17518 \end_layout
17519
17520 \end_inset
17521
17522
17523 \newline
17524 \InsetSpace ~
17525 \InsetSpace ~
17526 \InsetSpace ~
17527 \InsetSpace ~
17528 _asm
17529 \newline
17530 \InsetSpace ~
17531 \InsetSpace ~
17532 \InsetSpace ~
17533 \InsetSpace ~
17534 0003$: ;label (can be referenced by inline assembler only)
17535  
17536 \newline
17537 \InsetSpace ~
17538 \InsetSpace ~
17539 \InsetSpace ~
17540 \InsetSpace ~
17541 _endasm
17542 \begin_inset LatexCommand \index{\_endasm}
17543
17544 \end_inset
17545
17546
17547 \begin_inset LatexCommand \index{\_\_endasm}
17548
17549 \end_inset
17550
17551  ; 
17552 \newline
17553 \InsetSpace ~
17554 \InsetSpace ~
17555 \InsetSpace ~
17556 \InsetSpace ~
17557 /* some more c code */
17558 \newline
17559 }
17560 \end_layout
17561
17562 \begin_layout Standard
17563 In other words inline assembly code can access labels defined in inline
17564  assembly within the scope of the function.
17565  The same goes the other way, i.e.
17566  labels defines in inline assembly can not be accessed by C statements.
17567 \end_layout
17568
17569 \begin_layout Section
17570 Interfacing with Assembler Code
17571 \begin_inset LatexCommand \index{Assembler routines}
17572
17573 \end_inset
17574
17575
17576 \end_layout
17577
17578 \begin_layout Subsection
17579 Global Registers used for Parameter Passing
17580 \begin_inset LatexCommand \index{Parameter passing}
17581
17582 \end_inset
17583
17584
17585 \end_layout
17586
17587 \begin_layout Standard
17588 The compiler always uses the global registers 
17589 \emph on
17590 DPL, DPH
17591 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17592
17593 \end_inset
17594
17595
17596 \begin_inset LatexCommand \index{DPTR}
17597
17598 \end_inset
17599
17600 , B
17601 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17602
17603 \end_inset
17604
17605  
17606 \emph default
17607 and
17608 \emph on
17609  ACC
17610 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17611
17612 \end_inset
17613
17614
17615 \emph default
17616  to pass the first parameter to a function, and also to pass the return
17617  value 
17618 \begin_inset LatexCommand \index{return value}
17619
17620 \end_inset
17621
17622 of function; according to the following scheme: one byte return value in
17623  
17624 \emph on
17625 DPL
17626 \emph default
17627 , two byte value in 
17628 \emph on
17629 DPL
17630 \emph default
17631  (LSB) and 
17632 \emph on
17633 DPH
17634 \emph default
17635  (MSB).
17636  three byte values (generic pointers) in 
17637 \emph on
17638 DPH
17639 \emph default
17640
17641 \emph on
17642 DPL
17643 \emph default
17644  and 
17645 \emph on
17646 B
17647 \emph default
17648 , and four byte values in 
17649 \emph on
17650 DPH
17651 \emph default
17652
17653 \emph on
17654 DPL
17655 \emph default
17656 ,
17657 \emph on
17658  B
17659 \emph default
17660  and 
17661 \emph on
17662 ACC
17663 \emph default
17664 .
17665  Generic pointers
17666 \begin_inset LatexCommand \index{generic pointer}
17667
17668 \end_inset
17669
17670  contain type of accessed memory in 
17671 \emph on
17672 B
17673 \emph default
17674
17675 \series bold
17676 0x00
17677 \series default
17678  -- xdata/far, 
17679 \series bold
17680 0x40
17681 \series default
17682  -- idata/near -- , 
17683 \series bold
17684 0x60
17685 \series default
17686  -- pdata, 
17687 \series bold
17688 0x80
17689 \series default
17690  -- code
17691 \begin_inset Note Note
17692 status collapsed
17693
17694 \begin_layout Standard
17695 This might not be the case of certain memory models (medium???)
17696 \end_layout
17697
17698 \end_inset
17699
17700 .
17701 \end_layout
17702
17703 \begin_layout Standard
17704 The second parameter onwards is either allocated on the stack (for reentrant
17705  routines or if -
17706 \begin_inset ERT
17707 status collapsed
17708
17709 \begin_layout Standard
17710
17711
17712 \backslash
17713 /
17714 \end_layout
17715
17716 \end_inset
17717
17718 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17719  
17720 \end_layout
17721
17722 \begin_layout Subsection
17723 Registers usage
17724 \end_layout
17725
17726 \begin_layout Standard
17727 Unless the called function is declared as 
17728 \family typewriter
17729 _naked
17730 \family default
17731
17732 \begin_inset LatexCommand \index{naked}
17733
17734 \end_inset
17735
17736 , or the -
17737 \begin_inset ERT
17738 status collapsed
17739
17740 \begin_layout Standard
17741
17742
17743 \backslash
17744 /
17745 \end_layout
17746
17747 \end_inset
17748
17749 -callee-saves
17750 \begin_inset LatexCommand \index{-\/-callee-saves}
17751
17752 \end_inset
17753
17754 /-
17755 \begin_inset ERT
17756 status collapsed
17757
17758 \begin_layout Standard
17759
17760
17761 \backslash
17762 /
17763 \end_layout
17764
17765 \end_inset
17766
17767 -all-callee-saves command line option or the corresponding callee_saves
17768  pragma are used, the caller will save the registers (
17769 \emph on
17770 R0-R7
17771 \emph default
17772 ) around the call, so the called function can destroy they content freely.
17773 \end_layout
17774
17775 \begin_layout Standard
17776 If the called function is not declared as 
17777 \family typewriter
17778 _naked
17779 \family default
17780 , the caller will swap register banks around the call, if caller and callee
17781  use different register banks (having them defined by the 
17782 \family typewriter
17783 _using
17784 \family default
17785  modifier).
17786  
17787 \end_layout
17788
17789 \begin_layout Standard
17790 The called function can also use 
17791 \emph on
17792 DPL
17793 \emph default
17794
17795 \emph on
17796 DPH
17797 \emph default
17798
17799 \emph on
17800 B
17801 \emph default
17802  and 
17803 \emph on
17804 ACC
17805 \emph default
17806  observing that they are used for parameter/return value passing.
17807 \end_layout
17808
17809 \begin_layout Subsection
17810 Assembler Routine (non-reentrant)
17811 \end_layout
17812
17813 \begin_layout Standard
17814 In the following example
17815 \begin_inset LatexCommand \index{reentrant}
17816
17817 \end_inset
17818
17819
17820 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17821
17822 \end_inset
17823
17824  the function c_func calls an assembler routine asm_func, which takes two
17825  parameters
17826 \begin_inset LatexCommand \index{function parameter}
17827
17828 \end_inset
17829
17830 .
17831 \end_layout
17832
17833 \begin_layout Verse
17834
17835 \family typewriter
17836 extern int asm_func(unsigned char, unsigned char);
17837 \newline
17838
17839 \newline
17840 int c_func (unsigned char
17841  i, unsigned char j)
17842 \newline
17843 {
17844 \newline
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 \InsetSpace ~
17849 return asm_func(i,j);
17850 \newline
17851 }
17852 \newline
17853
17854 \newline
17855 int main()
17856 \newline
17857 {
17858 \newline
17859 \InsetSpace ~
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 return c_func(10,9);
17864 \newline
17865 }
17866 \end_layout
17867
17868 \begin_layout Standard
17869 The corresponding assembler function is:
17870 \end_layout
17871
17872 \begin_layout Verse
17873
17874 \family typewriter
17875 .globl _asm_func_PARM_2 
17876 \newline
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 \InsetSpace ~
17882 \InsetSpace ~
17883 \InsetSpace ~
17884 \InsetSpace ~
17885 .globl _asm_func 
17886 \newline
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 \InsetSpace ~
17890 \InsetSpace ~
17891 \InsetSpace ~
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 .area OSEG 
17896 \newline
17897 _asm_func_PARM_2:
17898 \newline
17899 \InsetSpace ~
17900 \InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 \InsetSpace ~
17907 .ds   
17908  1 
17909 \newline
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 \InsetSpace ~
17914 \InsetSpace ~
17915 \InsetSpace ~
17916 \InsetSpace ~
17917 \InsetSpace ~
17918 .area CSEG 
17919 \newline
17920 _asm_func: 
17921 \newline
17922 \InsetSpace ~
17923 \InsetSpace ~
17924 \InsetSpace ~
17925 \InsetSpace ~
17926 \InsetSpace ~
17927 \InsetSpace ~
17928 \InsetSpace ~
17929 \InsetSpace ~
17930 mov\InsetSpace ~
17931 \InsetSpace ~
17932 \InsetSpace ~
17933 \InsetSpace ~
17934 a,dpl 
17935 \newline
17936 \InsetSpace ~
17937 \InsetSpace ~
17938 \InsetSpace ~
17939 \InsetSpace ~
17940 \InsetSpace ~
17941 \InsetSpace ~
17942 \InsetSpace ~
17943 \InsetSpace ~
17944 add\InsetSpace ~
17945 \InsetSpace ~
17946 \InsetSpace ~
17947 \InsetSpace ~
17948 a,_asm_func_PARM_2 
17949 \newline
17950 \InsetSpace ~
17951 \InsetSpace ~
17952 \InsetSpace ~
17953 \InsetSpace ~
17954 \InsetSpace ~
17955 \InsetSpace ~
17956 \InsetSpace ~
17957 \InsetSpace ~
17958 mov\InsetSpace ~
17959 \InsetSpace ~
17960 \InsetSpace ~
17961 \InsetSpace ~
17962 dpl,a 
17963 \newline
17964 \InsetSpace ~
17965 \InsetSpace ~
17966 \InsetSpace ~
17967 \InsetSpace ~
17968 \InsetSpace ~
17969 \InsetSpace ~
17970 \InsetSpace ~
17971 \InsetSpace ~
17972 mov\InsetSpace ~
17973 \InsetSpace ~
17974 \InsetSpace ~
17975 \InsetSpace ~
17976 dph
17977 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17978
17979 \end_inset
17980
17981 ,#0x00 
17982 \newline
17983 \InsetSpace ~
17984 \InsetSpace ~
17985 \InsetSpace ~
17986 \InsetSpace ~
17987 \InsetSpace ~
17988 \InsetSpace ~
17989 \InsetSpace ~
17990 \InsetSpace ~
17991 ret
17992 \end_layout
17993
17994 \begin_layout Standard
17995 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17996  the parameter number starting from 1, and counting from the left.
17997  The first parameter is passed in 
17998 \emph on
17999 DPH
18000 \emph default
18001
18002 \emph on
18003 DPL
18004 \emph default
18005
18006 \emph on
18007 B
18008 \emph default
18009  and 
18010 \emph on
18011 ACC
18012 \emph default
18013  according to the description above.
18014  The variable name for the second parameter will be _<function_name>_PARM_2.
18015 \newline
18016
18017 \newline
18018 Assem
18019 ble the assembler routine with the following command:
18020 \newline
18021
18022 \newline
18023
18024 \family sans
18025 \series bold
18026 asx8051 -losg asmfunc.asm
18027 \newline
18028
18029 \newline
18030
18031 \family default
18032 \series default
18033 Then compile and link the assembler routine to the C source file with the
18034  following command:
18035 \newline
18036
18037 \newline
18038
18039 \family sans
18040 \series bold
18041 sdcc cfunc.c asmfunc.rel
18042 \end_layout
18043
18044 \begin_layout Subsection
18045 Assembler Routine (reentrant)
18046 \end_layout
18047
18048 \begin_layout Standard
18049 In this case
18050 \begin_inset LatexCommand \index{reentrant}
18051
18052 \end_inset
18053
18054
18055 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18056
18057 \end_inset
18058
18059  the second parameter
18060 \begin_inset LatexCommand \index{function parameter}
18061
18062 \end_inset
18063
18064  onwards will be passed on the stack, the parameters are pushed from right
18065  to left i.e.
18066  before the call the second leftmost parameter will be on the top of the
18067  stack (the leftmost parameter is passed in registers).
18068  Here is an example:
18069 \end_layout
18070
18071 \begin_layout Verse
18072
18073 \family typewriter
18074 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18075 \newline
18076
18077 \newline
18078 int
18079  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18080 \newline
18081 {
18082  
18083 \newline
18084 \InsetSpace ~
18085 \InsetSpace ~
18086 \InsetSpace ~
18087 \InsetSpace ~
18088 return asm_func(i,j,k); 
18089 \newline
18090
18091 \newline
18092
18093 \newline
18094 int main() 
18095 \newline
18096
18097 \newline
18098 \InsetSpace ~
18099 \InsetSpace ~
18100 \InsetSpace ~
18101 \InsetSpace ~
18102 return c_func(10,9,8); 
18103 \newline
18104 }
18105 \end_layout
18106
18107 \begin_layout Standard
18108 The corresponding (unoptimized) assembler routine is:
18109 \end_layout
18110
18111 \begin_layout Verse
18112
18113 \family typewriter
18114 .globl _asm_func 
18115 \newline
18116 _asm_func: 
18117 \newline
18118 \InsetSpace ~
18119 \InsetSpace ~
18120 \InsetSpace ~
18121 \InsetSpace ~
18122 push\InsetSpace ~
18123 _bp 
18124 \newline
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 \InsetSpace ~
18128 \InsetSpace ~
18129 mov\InsetSpace ~
18130 \InsetSpace ~
18131 _bp,sp\InsetSpace ~
18132 \InsetSpace ~
18133 \InsetSpace ~
18134 \InsetSpace ~
18135 \InsetSpace ~
18136 \InsetSpace ~
18137 ;stack contains: _bp, return
18138  address, second parameter, third parameter
18139 \newline
18140 \InsetSpace ~
18141 \InsetSpace ~
18142 \InsetSpace ~
18143 \InsetSpace ~
18144 mov\InsetSpace ~
18145 \InsetSpace ~
18146 r2,dpl
18147 \newline
18148 \InsetSpace ~
18149 \InsetSpace ~
18150 \InsetSpace ~
18151 \InsetSpace ~
18152 mov\InsetSpace ~
18153 \InsetSpace ~
18154 a,_bp
18155 \newline
18156 \InsetSpace ~
18157 \InsetSpace ~
18158 \InsetSpace ~
18159 \InsetSpace ~
18160 add\InsetSpace ~
18161 \InsetSpace ~
18162 a,#0xfd\InsetSpace ~
18163 \InsetSpace ~
18164 \InsetSpace ~
18165 \InsetSpace ~
18166 \InsetSpace ~
18167 ;calculate
18168  pointer to the second parameter
18169 \newline
18170 \InsetSpace ~
18171 \InsetSpace ~
18172 \InsetSpace ~
18173 \InsetSpace ~
18174 mov\InsetSpace ~
18175 \InsetSpace ~
18176 r0,a 
18177 \newline
18178 \InsetSpace ~
18179 \InsetSpace ~
18180 \InsetSpace ~
18181 \InsetSpace ~
18182 mov\InsetSpace ~
18183 \InsetSpace ~
18184 a,_bp 
18185 \newline
18186 \InsetSpace ~
18187 \InsetSpace ~
18188 \InsetSpace ~
18189 \InsetSpace ~
18190 add\InsetSpace ~
18191 \InsetSpace ~
18192 a,#0xfc\InsetSpace ~
18193 \InsetSpace ~
18194 \InsetSpace ~
18195 \InsetSpace ~
18196 \InsetSpace ~
18197 ;calculate pointer
18198  to the rightmost parameter
18199 \newline
18200 \InsetSpace ~
18201 \InsetSpace ~
18202 \InsetSpace ~
18203 \InsetSpace ~
18204 mov\InsetSpace ~
18205 \InsetSpace ~
18206 r1,a 
18207 \newline
18208 \InsetSpace ~
18209 \InsetSpace ~
18210 \InsetSpace ~
18211 \InsetSpace ~
18212 mov\InsetSpace ~
18213 \InsetSpace ~
18214 a,@r0
18215 \newline
18216 \InsetSpace ~
18217 \InsetSpace ~
18218 \InsetSpace ~
18219 \InsetSpace ~
18220 add\InsetSpace ~
18221 \InsetSpace ~
18222 a,@r1
18223 \newline
18224 \InsetSpace ~
18225 \InsetSpace ~
18226 \InsetSpace ~
18227 \InsetSpace ~
18228 add\InsetSpace ~
18229 \InsetSpace ~
18230 a,r2\InsetSpace ~
18231 \InsetSpace ~
18232 \InsetSpace ~
18233 \InsetSpace ~
18234 \InsetSpace ~
18235 \InsetSpace ~
18236 \InsetSpace ~
18237 \InsetSpace ~
18238 ;calculate the
18239  result (= sum of all three parameters)
18240 \newline
18241 \InsetSpace ~
18242 \InsetSpace ~
18243 \InsetSpace ~
18244 \InsetSpace ~
18245 mov\InsetSpace ~
18246 \InsetSpace ~
18247 dpl,a\InsetSpace ~
18248 \InsetSpace ~
18249 \InsetSpace ~
18250 \InsetSpace ~
18251 \InsetSpace ~
18252 \InsetSpace ~
18253 \InsetSpace ~
18254 ;return value goes into dptr
18255  (cast into int)
18256 \newline
18257 \InsetSpace ~
18258 \InsetSpace ~
18259 \InsetSpace ~
18260 \InsetSpace ~
18261 mov\InsetSpace ~
18262 \InsetSpace ~
18263 dph,#0x00 
18264 \newline
18265 \InsetSpace ~
18266 \InsetSpace ~
18267 \InsetSpace ~
18268 \InsetSpace ~
18269 mov\InsetSpace ~
18270 \InsetSpace ~
18271 sp,_bp 
18272 \newline
18273 \InsetSpace ~
18274 \InsetSpace ~
18275 \InsetSpace ~
18276 \InsetSpace ~
18277 pop\InsetSpace ~
18278 \InsetSpace ~
18279 _bp 
18280 \newline
18281 \InsetSpace ~
18282 \InsetSpace ~
18283 \InsetSpace ~
18284 \InsetSpace ~
18285 ret
18286 \end_layout
18287
18288 \begin_layout Standard
18289 The compiling and linking procedure remains the same, however note the extra
18290  entry & exit linkage required for the assembler code, _bp is the stack
18291  frame pointer and is used to compute the offset into the stack for parameters
18292  and local variables.
18293 \begin_inset VSpace bigskip
18294 \end_inset
18295
18296
18297 \end_layout
18298
18299 \begin_layout Section
18300 int (16 bit)
18301 \begin_inset LatexCommand \index{int (16 bit)}
18302
18303 \end_inset
18304
18305  and long (32 bit)
18306 \begin_inset LatexCommand \index{long (32 bit)}
18307
18308 \end_inset
18309
18310  Support
18311 \end_layout
18312
18313 \begin_layout Standard
18314 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18315  multiplication and modulus operations are implemented by support routines.
18316  These support routines are all developed in ANSI-C to facilitate porting
18317  to other MCUs, although some model specific assembler optimizations are
18318  used.
18319  The following files contain the described routines, all of them can be
18320  found in <installdir>/share/sdcc/lib.
18321 \newline
18322
18323 \end_layout
18324
18325 \begin_layout Standard
18326 \align center
18327 \begin_inset Tabular
18328 <lyxtabular version="3" rows="11" columns="2">
18329 <features>
18330 <column alignment="left" valignment="top" leftline="true" width="0">
18331 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18332 <row topline="true" bottomline="true">
18333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18334 \begin_inset Text
18335
18336 \begin_layout Standard
18337
18338 \series bold
18339 Function
18340 \end_layout
18341
18342 \end_inset
18343 </cell>
18344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18345 \begin_inset Text
18346
18347 \begin_layout Standard
18348
18349 \series bold
18350 Description
18351 \end_layout
18352
18353 \end_inset
18354 </cell>
18355 </row>
18356 <row topline="true">
18357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18358 \begin_inset Text
18359
18360 \begin_layout Standard
18361 _mulint.c 
18362 \end_layout
18363
18364 \end_inset
18365 </cell>
18366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18367 \begin_inset Text
18368
18369 \begin_layout Standard
18370 16 bit multiplication
18371 \end_layout
18372
18373 \end_inset
18374 </cell>
18375 </row>
18376 <row topline="true">
18377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18378 \begin_inset Text
18379
18380 \begin_layout Standard
18381 _divsint.c 
18382 \end_layout
18383
18384 \end_inset
18385 </cell>
18386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18387 \begin_inset Text
18388
18389 \begin_layout Standard
18390  signed 16 bit division (calls _divuint)
18391 \end_layout
18392
18393 \end_inset
18394 </cell>
18395 </row>
18396 <row topline="true">
18397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18398 \begin_inset Text
18399
18400 \begin_layout Standard
18401 _divuint.c 
18402 \end_layout
18403
18404 \end_inset
18405 </cell>
18406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18407 \begin_inset Text
18408
18409 \begin_layout Standard
18410  unsigned 16 bit division
18411 \end_layout
18412
18413 \end_inset
18414 </cell>
18415 </row>
18416 <row topline="true">
18417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18418 \begin_inset Text
18419
18420 \begin_layout Standard
18421 _modsint.c
18422 \end_layout
18423
18424 \end_inset
18425 </cell>
18426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18427 \begin_inset Text
18428
18429 \begin_layout Standard
18430 signed 16 bit modulus (calls _moduint)
18431 \end_layout
18432
18433 \end_inset
18434 </cell>
18435 </row>
18436 <row topline="true">
18437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18438 \begin_inset Text
18439
18440 \begin_layout Standard
18441 _moduint.c
18442 \end_layout
18443
18444 \end_inset
18445 </cell>
18446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18447 \begin_inset Text
18448
18449 \begin_layout Standard
18450 unsigned 16 bit modulus
18451 \end_layout
18452
18453 \end_inset
18454 </cell>
18455 </row>
18456 <row topline="true">
18457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18458 \begin_inset Text
18459
18460 \begin_layout Standard
18461 _mullong.c
18462 \end_layout
18463
18464 \end_inset
18465 </cell>
18466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18467 \begin_inset Text
18468
18469 \begin_layout Standard
18470 32 bit multiplication
18471 \end_layout
18472
18473 \end_inset
18474 </cell>
18475 </row>
18476 <row topline="true">
18477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18478 \begin_inset Text
18479
18480 \begin_layout Standard
18481 _divslong.c 
18482 \end_layout
18483
18484 \end_inset
18485 </cell>
18486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18487 \begin_inset Text
18488
18489 \begin_layout Standard
18490  signed 32 division (calls _divulong)
18491 \end_layout
18492
18493 \end_inset
18494 </cell>
18495 </row>
18496 <row topline="true">
18497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18498 \begin_inset Text
18499
18500 \begin_layout Standard
18501 _divulong.c 
18502 \end_layout
18503
18504 \end_inset
18505 </cell>
18506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18507 \begin_inset Text
18508
18509 \begin_layout Standard
18510 unsigned 32 division
18511 \end_layout
18512
18513 \end_inset
18514 </cell>
18515 </row>
18516 <row topline="true">
18517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18518 \begin_inset Text
18519
18520 \begin_layout Standard
18521 _modslong.c
18522 \end_layout
18523
18524 \end_inset
18525 </cell>
18526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18527 \begin_inset Text
18528
18529 \begin_layout Standard
18530  signed 32 bit modulus (calls _modulong)
18531 \end_layout
18532
18533 \end_inset
18534 </cell>
18535 </row>
18536 <row topline="true" bottomline="true">
18537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18538 \begin_inset Text
18539
18540 \begin_layout Standard
18541 _modulong.c
18542 \end_layout
18543
18544 \end_inset
18545 </cell>
18546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18547 \begin_inset Text
18548
18549 \begin_layout Standard
18550 unsigned 32 bit modulus
18551 \end_layout
18552
18553 \end_inset
18554 </cell>
18555 </row>
18556 </lyxtabular>
18557
18558 \end_inset
18559
18560
18561 \newline
18562
18563 \end_layout
18564
18565 \begin_layout Standard
18566 Since they are compiled as 
18567 \emph on
18568 non-reentrant
18569 \emph default
18570
18571 \begin_inset LatexCommand \index{reentrant}
18572
18573 \end_inset
18574
18575 , interrupt
18576 \begin_inset LatexCommand \index{interrupt}
18577
18578 \end_inset
18579
18580  service routines should not do any of the above operations.
18581  If this is unavoidable then the above routines will need to be compiled
18582  with the 
18583 \emph on
18584 -
18585 \begin_inset ERT
18586 status collapsed
18587
18588 \begin_layout Standard
18589
18590
18591 \backslash
18592 /
18593 \end_layout
18594
18595 \end_inset
18596
18597 -stack-auto
18598 \begin_inset LatexCommand \index{-\/-stack-auto}
18599
18600 \end_inset
18601
18602
18603 \emph default
18604  option, after which the source program will have to be compiled with 
18605 \emph on
18606 -
18607 \begin_inset ERT
18608 status collapsed
18609
18610 \begin_layout Standard
18611
18612
18613 \backslash
18614 /
18615 \end_layout
18616
18617 \end_inset
18618
18619 -int-long-reent
18620 \begin_inset LatexCommand \index{-\/-int-long-reent}
18621
18622 \end_inset
18623
18624
18625 \emph default
18626  option.
18627  Notice that you don't have to call these routines directly.
18628  The compiler will use them automatically every time an integer operation
18629  is required.
18630 \end_layout
18631
18632 \begin_layout Section
18633 Floating Point Support
18634 \begin_inset LatexCommand \index{Floating point support}
18635
18636 \end_inset
18637
18638
18639 \end_layout
18640
18641 \begin_layout Standard
18642 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18643  The floating point support routines are derived from gcc's floatlib.c and
18644  consist of the following routines:
18645 \newline
18646
18647 \end_layout
18648
18649 \begin_layout Standard
18650 \align center
18651
18652 \size footnotesize
18653 \begin_inset Tabular
18654 <lyxtabular version="3" rows="17" columns="2">
18655 <features>
18656 <column alignment="left" valignment="top" leftline="true" width="0">
18657 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18658 <row topline="true" bottomline="true">
18659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18660 \begin_inset Text
18661
18662 \begin_layout Standard
18663
18664 \family roman
18665 \series medium
18666 \shape up
18667 \size normal
18668 \emph off
18669 \bar no
18670 \noun off
18671 \color none
18672 Function 
18673 \end_layout
18674
18675 \end_inset
18676 </cell>
18677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18678 \begin_inset Text
18679
18680 \begin_layout Standard
18681 Description
18682 \end_layout
18683
18684 \end_inset
18685 </cell>
18686 </row>
18687 <row topline="true">
18688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18689 \begin_inset Text
18690
18691 \begin_layout Standard
18692
18693 \family roman
18694 \series medium
18695 \shape up
18696 \size normal
18697 \emph off
18698 \bar no
18699 \noun off
18700 \color none
18701 _fsadd.c
18702 \end_layout
18703
18704 \end_inset
18705 </cell>
18706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18707 \begin_inset Text
18708
18709 \begin_layout Standard
18710
18711 \family roman
18712 \series medium
18713 \shape up
18714 \size normal
18715 \emph off
18716 \bar no
18717 \noun off
18718 \color none
18719 add floating point numbers
18720 \end_layout
18721
18722 \end_inset
18723 </cell>
18724 </row>
18725 <row topline="true">
18726 <cell alignment="center" valignment="top" topline="true" leftline="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 _fssub.c 
18740 \end_layout
18741
18742 \end_inset
18743 </cell>
18744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18745 \begin_inset Text
18746
18747 \begin_layout Standard
18748
18749 \family roman
18750 \series medium
18751 \shape up
18752 \size normal
18753 \emph off
18754 \bar no
18755 \noun off
18756 \color none
18757 subtract floating point numbers 
18758 \end_layout
18759
18760 \end_inset
18761 </cell>
18762 </row>
18763 <row topline="true">
18764 <cell alignment="center" valignment="top" topline="true" leftline="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 _fsdiv.c 
18778 \end_layout
18779
18780 \end_inset
18781 </cell>
18782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18783 \begin_inset Text
18784
18785 \begin_layout Standard
18786
18787 \family roman
18788 \series medium
18789 \shape up
18790 \size normal
18791 \emph off
18792 \bar no
18793 \noun off
18794 \color none
18795 divide floating point numbers 
18796 \end_layout
18797
18798 \end_inset
18799 </cell>
18800 </row>
18801 <row topline="true">
18802 <cell alignment="center" valignment="top" topline="true" leftline="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 _fsmul.c 
18816 \end_layout
18817
18818 \end_inset
18819 </cell>
18820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18821 \begin_inset Text
18822
18823 \begin_layout Standard
18824
18825 \family roman
18826 \series medium
18827 \shape up
18828 \size normal
18829 \emph off
18830 \bar no
18831 \noun off
18832 \color none
18833 multiply floating point numbers 
18834 \end_layout
18835
18836 \end_inset
18837 </cell>
18838 </row>
18839 <row topline="true">
18840 <cell alignment="center" valignment="top" topline="true" leftline="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 _fs2uchar.c
18854 \end_layout
18855
18856 \end_inset
18857 </cell>
18858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18859 \begin_inset Text
18860
18861 \begin_layout Standard
18862
18863 \family roman
18864 \series medium
18865 \shape up
18866 \size normal
18867 \emph off
18868 \bar no
18869 \noun off
18870 \color none
18871 convert floating point to unsigned char
18872 \end_layout
18873
18874 \end_inset
18875 </cell>
18876 </row>
18877 <row topline="true">
18878 <cell alignment="center" valignment="top" topline="true" leftline="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 _fs2char.c
18892 \end_layout
18893
18894 \end_inset
18895 </cell>
18896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18897 \begin_inset Text
18898
18899 \begin_layout Standard
18900
18901 \family roman
18902 \series medium
18903 \shape up
18904 \size normal
18905 \emph off
18906 \bar no
18907 \noun off
18908 \color none
18909 convert floating point to signed char
18910 \end_layout
18911
18912 \end_inset
18913 </cell>
18914 </row>
18915 <row topline="true">
18916 <cell alignment="center" valignment="top" topline="true" leftline="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 _fs2uint.c
18930 \end_layout
18931
18932 \end_inset
18933 </cell>
18934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18935 \begin_inset Text
18936
18937 \begin_layout Standard
18938
18939 \family roman
18940 \series medium
18941 \shape up
18942 \size normal
18943 \emph off
18944 \bar no
18945 \noun off
18946 \color none
18947 convert floating point to unsigned int
18948 \end_layout
18949
18950 \end_inset
18951 </cell>
18952 </row>
18953 <row topline="true">
18954 <cell alignment="center" valignment="top" topline="true" leftline="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 _fs2int.c
18968 \end_layout
18969
18970 \end_inset
18971 </cell>
18972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18973 \begin_inset Text
18974
18975 \begin_layout Standard
18976
18977 \family roman
18978 \series medium
18979 \shape up
18980 \size normal
18981 \emph off
18982 \bar no
18983 \noun off
18984 \color none
18985 convert floating point to signed int
18986 \end_layout
18987
18988 \end_inset
18989 </cell>
18990 </row>
18991 <row topline="true">
18992 <cell alignment="center" valignment="top" topline="true" leftline="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 _fs2ulong.
19006 \family default
19007 \series default
19008 \shape default
19009 \size default
19010 \emph default
19011 \bar default
19012 \noun default
19013 c
19014 \end_layout
19015
19016 \end_inset
19017 </cell>
19018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19019 \begin_inset Text
19020
19021 \begin_layout Standard
19022
19023 \family roman
19024 \series medium
19025 \shape up
19026 \size normal
19027 \emph off
19028 \bar no
19029 \noun off
19030 \color none
19031 convert floating point to unsigned long
19032 \end_layout
19033
19034 \end_inset
19035 </cell>
19036 </row>
19037 <row topline="true">
19038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19039 \begin_inset Text
19040
19041 \begin_layout Standard
19042
19043 \family roman
19044 \series medium
19045 \shape up
19046 \size normal
19047 \emph off
19048 \bar no
19049 \noun off
19050 \color none
19051 _fs2long.c
19052 \end_layout
19053
19054 \end_inset
19055 </cell>
19056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19057 \begin_inset Text
19058
19059 \begin_layout Standard
19060
19061 \family roman
19062 \series medium
19063 \shape up
19064 \size normal
19065 \emph off
19066 \bar no
19067 \noun off
19068 \color none
19069 convert floating point to signed long
19070 \end_layout
19071
19072 \end_inset
19073 </cell>
19074 </row>
19075 <row topline="true">
19076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19077 \begin_inset Text
19078
19079 \begin_layout Standard
19080
19081 \family roman
19082 \series medium
19083 \shape up
19084 \size normal
19085 \emph off
19086 \bar no
19087 \noun off
19088 \color none
19089 _uchar2fs.c
19090 \end_layout
19091
19092 \end_inset
19093 </cell>
19094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19095 \begin_inset Text
19096
19097 \begin_layout Standard
19098
19099 \family roman
19100 \series medium
19101 \shape up
19102 \size normal
19103 \emph off
19104 \bar no
19105 \noun off
19106 \color none
19107 convert unsigned char to floating point
19108 \end_layout
19109
19110 \end_inset
19111 </cell>
19112 </row>
19113 <row topline="true">
19114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19115 \begin_inset Text
19116
19117 \begin_layout Standard
19118
19119 \family roman
19120 \series medium
19121 \shape up
19122 \size normal
19123 \emph off
19124 \bar no
19125 \noun off
19126 \color none
19127 _char2fs.c
19128 \end_layout
19129
19130 \end_inset
19131 </cell>
19132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19133 \begin_inset Text
19134
19135 \begin_layout Standard
19136
19137 \family roman
19138 \series medium
19139 \shape up
19140 \size normal
19141 \emph off
19142 \bar no
19143 \noun off
19144 \color none
19145 convert char to floating point number
19146 \end_layout
19147
19148 \end_inset
19149 </cell>
19150 </row>
19151 <row topline="true">
19152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19153 \begin_inset Text
19154
19155 \begin_layout Standard
19156
19157 \family roman
19158 \series medium
19159 \shape up
19160 \size normal
19161 \emph off
19162 \bar no
19163 \noun off
19164 \color none
19165 _uint2fs.c
19166 \end_layout
19167
19168 \end_inset
19169 </cell>
19170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19171 \begin_inset Text
19172
19173 \begin_layout Standard
19174
19175 \family roman
19176 \series medium
19177 \shape up
19178 \size normal
19179 \emph off
19180 \bar no
19181 \noun off
19182 \color none
19183 convert unsigned int to floating point
19184 \end_layout
19185
19186 \end_inset
19187 </cell>
19188 </row>
19189 <row topline="true">
19190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19191 \begin_inset Text
19192
19193 \begin_layout Standard
19194
19195 \family roman
19196 \series medium
19197 \shape up
19198 \size normal
19199 \emph off
19200 \bar no
19201 \noun off
19202 \color none
19203 _int2fs.c
19204 \end_layout
19205
19206 \end_inset
19207 </cell>
19208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19209 \begin_inset Text
19210
19211 \begin_layout Standard
19212
19213 \family roman
19214 \series medium
19215 \shape up
19216 \size normal
19217 \emph off
19218 \bar no
19219 \noun off
19220 \color none
19221 convert int to floating point numbers
19222 \end_layout
19223
19224 \end_inset
19225 </cell>
19226 </row>
19227 <row topline="true">
19228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19229 \begin_inset Text
19230
19231 \begin_layout Standard
19232
19233 \family roman
19234 \series medium
19235 \shape up
19236 \size normal
19237 \emph off
19238 \bar no
19239 \noun off
19240 \color none
19241 _ulong2fs.c
19242 \end_layout
19243
19244 \end_inset
19245 </cell>
19246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19247 \begin_inset Text
19248
19249 \begin_layout Standard
19250
19251 \family roman
19252 \series medium
19253 \shape up
19254 \size normal
19255 \emph off
19256 \bar no
19257 \noun off
19258 \color none
19259 convert unsigned long to floating point number
19260 \end_layout
19261
19262 \end_inset
19263 </cell>
19264 </row>
19265 <row topline="true" bottomline="true">
19266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19267 \begin_inset Text
19268
19269 \begin_layout Standard
19270
19271 \family roman
19272 \series medium
19273 \shape up
19274 \size normal
19275 \emph off
19276 \bar no
19277 \noun off
19278 \color none
19279 _long2fs.c
19280 \end_layout
19281
19282 \end_inset
19283 </cell>
19284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19285 \begin_inset Text
19286
19287 \begin_layout Standard
19288
19289 \family roman
19290 \series medium
19291 \shape up
19292 \size normal
19293 \emph off
19294 \bar no
19295 \noun off
19296 \color none
19297 convert long to floating point number
19298 \end_layout
19299
19300 \end_inset
19301 </cell>
19302 </row>
19303 </lyxtabular>
19304
19305 \end_inset
19306
19307
19308 \newline
19309
19310 \end_layout
19311
19312 \begin_layout Standard
19313 These support routines are developed in ANSI-C so there is room for space
19314  and speed improvement
19315 \begin_inset Foot
19316 status open
19317
19318 \begin_layout Standard
19319 These floating point routines (
19320 \emph on
19321 not
19322 \emph default
19323  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19324  
19325 \end_layout
19326
19327 \end_inset
19328
19329 .
19330  Note if all these routines are used simultaneously the data space might
19331  overflow.
19332  For serious floating point usage the large model might be needed.
19333  Also notice that you don't have to call this routines directly.
19334  The compiler will use them automatically every time a floating point operation
19335  is required.
19336 \begin_inset VSpace bigskip
19337 \end_inset
19338
19339
19340 \end_layout
19341
19342 \begin_layout Section
19343 Library Routines
19344 \begin_inset LatexCommand \index{Libraries}
19345
19346 \end_inset
19347
19348
19349 \end_layout
19350
19351 \begin_layout Standard
19352
19353 \emph on
19354 <pending: this is messy and incomplete - a little more information is in
19355  sdcc/doc/libdoc.txt
19356 \emph default
19357  >
19358 \end_layout
19359
19360 \begin_layout Subsection
19361 Compiler support routines (_gptrget, _mulint etc.)
19362 \end_layout
19363
19364 \begin_layout Subsection
19365 Stdclib functions (puts, printf, strcat etc.)
19366 \end_layout
19367
19368 \begin_layout Subsubsection
19369 <stdio.h>
19370 \end_layout
19371
19372 \begin_layout Paragraph
19373 getchar(), putchar()
19374 \end_layout
19375
19376 \begin_layout Standard
19377 \begin_inset LatexCommand \index{<stdio.h>}
19378
19379 \end_inset
19380
19381 As usual on embedded systems you have to provide your own 
19382 \family typewriter
19383 getchar()
19384 \begin_inset LatexCommand \index{getchar()}
19385
19386 \end_inset
19387
19388  
19389 \family default
19390 and 
19391 \family typewriter
19392 putchar()
19393 \begin_inset LatexCommand \index{putchar()}
19394
19395 \end_inset
19396
19397
19398 \family default
19399  routines.
19400  SDCC does not know whether the system connects to a serial line with or
19401  without handshake, LCD, keyboard or other device.
19402  And whether a 
19403 \family typewriter
19404 lf
19405 \family default
19406  to 
19407 \family typewriter
19408 crlf
19409 \family default
19410  conversion within 
19411 \family typewriter
19412 putchar()
19413 \family default
19414  is intended.
19415  You'll find examples for serial routines f.e.
19416  in sdcc/device/lib.
19417  For the mcs51 this minimalistic polling 
19418 \family typewriter
19419 putchar()
19420 \family default
19421  routine might be a start:
19422 \end_layout
19423
19424 \begin_layout Verse
19425
19426 \family typewriter
19427 void putchar (char c) { 
19428 \newline
19429 \InsetSpace ~
19430 \InsetSpace ~
19431 \InsetSpace ~
19432 \InsetSpace ~
19433 while (!TI)\InsetSpace ~
19434 \InsetSpace ~
19435 \InsetSpace ~
19436  /* assumes UART is initialized */
19437 \newline
19438 \InsetSpace ~
19439 \InsetSpace ~
19440 \InsetSpace ~
19441 \InsetSpace ~
19442 \InsetSpace ~
19443 \InsetSpace ~
19444 \InsetSpace ~
19445 \InsetSpace ~
19446 ;
19447 \newline
19448 \InsetSpace ~
19449 \InsetSpace ~
19450 \InsetSpace ~
19451 \InsetSpace ~
19452 TI
19453  = 0;
19454 \newline
19455 \InsetSpace ~
19456 \InsetSpace ~
19457 \InsetSpace ~
19458 \InsetSpace ~
19459 SBUF = c;
19460 \newline
19461 }
19462 \end_layout
19463
19464 \begin_layout Paragraph
19465 printf()
19466 \end_layout
19467
19468 \begin_layout Standard
19469 The default
19470 \family typewriter
19471  printf()
19472 \begin_inset LatexCommand \index{printf()}
19473
19474 \end_inset
19475
19476
19477 \family default
19478  implementation in
19479 \family typewriter
19480  printf_large.c
19481 \family default
19482  does not support float (except on ds390).
19483  To enable this recompile it with the option 
19484 \emph on
19485 -
19486 \begin_inset ERT
19487 status collapsed
19488
19489 \begin_layout Standard
19490
19491
19492 \backslash
19493 /
19494 \end_layout
19495
19496 \end_inset
19497
19498 DUSE_FLOATS=1
19499 \begin_inset LatexCommand \index{USE\_FLOATS}
19500
19501 \end_inset
19502
19503
19504 \emph default
19505  on the command line.
19506  Use
19507 \emph on
19508  -
19509 \begin_inset ERT
19510 status collapsed
19511
19512 \begin_layout Standard
19513
19514
19515 \backslash
19516 /
19517 \end_layout
19518
19519 \end_inset
19520
19521 -model-large
19522 \begin_inset LatexCommand \index{-\/-model-large}
19523
19524 \end_inset
19525
19526
19527 \emph default
19528  for the mcs51 port, since this uses a lot of memory.
19529 \end_layout
19530
19531 \begin_layout Standard
19532 If you're short on code memory you might want to use 
19533 \family typewriter
19534 printf_small()
19535 \begin_inset LatexCommand \index{printf\_small()}
19536
19537 \end_inset
19538
19539
19540 \family default
19541  
19542 \emph on
19543 instead
19544 \emph default
19545  of
19546 \family typewriter
19547  printf().
19548
19549 \family default
19550  For the mcs51 there additionally are assembly versions 
19551 \family typewriter
19552 printf_tiny()
19553 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19554
19555 \end_inset
19556
19557
19558 \family default
19559  (subset of printf using less than 270 bytes) and 
19560 \family typewriter
19561 printf_fast()
19562 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19563
19564 \end_inset
19565
19566  
19567 \family default
19568 and
19569 \family typewriter
19570  printf_fast_f()
19571 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19572
19573 \end_inset
19574
19575
19576 \family default
19577  (floating-point aware version of printf_fast) which should fit the requirements
19578  of many embedded systems (printf_fast() can be customized by unsetting
19579  #defines to 
19580 \emph on
19581 not
19582 \emph default
19583  support long variables and field widths).
19584  Be sure to use only one of these printf options within a project.
19585 \newline
19586
19587 \end_layout
19588
19589 \begin_layout Standard
19590 Feature matrix of different 
19591 \emph on
19592 printf
19593 \emph default
19594  options on mcs51.
19595 \end_layout
19596
19597 \begin_layout Standard
19598 \begin_inset Tabular
19599 <lyxtabular version="3" rows="14" columns="7">
19600 <features islongtable="true">
19601 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19602 <column alignment="center" valignment="top" leftline="true" width="0">
19603 <column alignment="center" valignment="top" leftline="true" width="12col%">
19604 <column alignment="center" valignment="top" leftline="true" width="10col%">
19605 <column alignment="center" valignment="top" leftline="true" width="0">
19606 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19607 <column alignment="center" valignment="top" rightline="true" width="0">
19608 <row topline="true" bottomline="true" endhead="true">
19609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19610 \begin_inset Text
19611
19612 \begin_layout Standard
19613
19614 \series bold
19615 \size large
19616 mcs51
19617 \end_layout
19618
19619 \end_inset
19620 </cell>
19621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19622 \begin_inset Text
19623
19624 \begin_layout Standard
19625 printf
19626 \begin_inset LatexCommand \index{printf}
19627
19628 \end_inset
19629
19630
19631 \end_layout
19632
19633 \end_inset
19634 </cell>
19635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19636 \begin_inset Text
19637
19638 \begin_layout Standard
19639 printf 
19640 \size scriptsize
19641 USE_FLOATS=1
19642 \end_layout
19643
19644 \end_inset
19645 </cell>
19646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19647 \begin_inset Text
19648
19649 \begin_layout Standard
19650 printf_small
19651 \end_layout
19652
19653 \end_inset
19654 </cell>
19655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19656 \begin_inset Text
19657
19658 \begin_layout Standard
19659 printf_fast
19660 \end_layout
19661
19662 \end_inset
19663 </cell>
19664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19665 \begin_inset Text
19666
19667 \begin_layout Standard
19668 printf_fast_f
19669 \end_layout
19670
19671 \end_inset
19672 </cell>
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19674 \begin_inset Text
19675
19676 \begin_layout Standard
19677 printf_tiny
19678 \end_layout
19679
19680 \end_inset
19681 </cell>
19682 </row>
19683 <row topline="true" endhead="true">
19684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19685 \begin_inset Text
19686
19687 \begin_layout Standard
19688 filename
19689 \end_layout
19690
19691 \end_inset
19692 </cell>
19693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19694 \begin_inset Text
19695
19696 \begin_layout Standard
19697
19698 \size scriptsize
19699 printf_large.c
19700 \end_layout
19701
19702 \end_inset
19703 </cell>
19704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19705 \begin_inset Text
19706
19707 \begin_layout Standard
19708
19709 \size scriptsize
19710 printf_large.c
19711 \end_layout
19712
19713 \end_inset
19714 </cell>
19715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19716 \begin_inset Text
19717
19718 \begin_layout Standard
19719
19720 \size scriptsize
19721 printfl.c
19722 \end_layout
19723
19724 \end_inset
19725 </cell>
19726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19727 \begin_inset Text
19728
19729 \begin_layout Standard
19730
19731 \size scriptsize
19732 printf_fast.c
19733 \end_layout
19734
19735 \end_inset
19736 </cell>
19737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19738 \begin_inset Text
19739
19740 \begin_layout Standard
19741
19742 \size scriptsize
19743 printf_fast_f.c
19744 \end_layout
19745
19746 \end_inset
19747 </cell>
19748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19749 \begin_inset Text
19750
19751 \begin_layout Standard
19752
19753 \size scriptsize
19754 printf_tiny.c
19755 \end_layout
19756
19757 \end_inset
19758 </cell>
19759 </row>
19760 <row topline="true" endhead="true">
19761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19762 \begin_inset Text
19763
19764 \begin_layout Standard
19765 \begin_inset Quotes sld
19766 \end_inset
19767
19768 Hello World
19769 \begin_inset Quotes srd
19770 \end_inset
19771
19772  size
19773 \end_layout
19774
19775 \begin_layout Standard
19776 small / large
19777 \end_layout
19778
19779 \end_inset
19780 </cell>
19781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19782 \begin_inset Text
19783
19784 \begin_layout Standard
19785 1.7k / 2.4k
19786 \end_layout
19787
19788 \end_inset
19789 </cell>
19790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19791 \begin_inset Text
19792
19793 \begin_layout Standard
19794 4.3k / 5.6k
19795 \end_layout
19796
19797 \end_inset
19798 </cell>
19799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19800 \begin_inset Text
19801
19802 \begin_layout Standard
19803 1.2k / 1.8k
19804 \end_layout
19805
19806 \end_inset
19807 </cell>
19808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19809 \begin_inset Text
19810
19811 \begin_layout Standard
19812 1.3k / 1.3k
19813 \end_layout
19814
19815 \end_inset
19816 </cell>
19817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19818 \begin_inset Text
19819
19820 \begin_layout Standard
19821 1.9k / 1.9k
19822 \end_layout
19823
19824 \end_inset
19825 </cell>
19826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19827 \begin_inset Text
19828
19829 \begin_layout Standard
19830 0.44k / 0.44k
19831 \end_layout
19832
19833 \end_inset
19834 </cell>
19835 </row>
19836 <row topline="true" endhead="true">
19837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19838 \begin_inset Text
19839
19840 \begin_layout Standard
19841 code size
19842 \end_layout
19843
19844 \begin_layout Standard
19845 small / large
19846 \end_layout
19847
19848 \end_inset
19849 </cell>
19850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19851 \begin_inset Text
19852
19853 \begin_layout Standard
19854 1.4k / 2.0k
19855 \end_layout
19856
19857 \end_inset
19858 </cell>
19859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19860 \begin_inset Text
19861
19862 \begin_layout Standard
19863 2.8k / 3.7k
19864 \end_layout
19865
19866 \end_inset
19867 </cell>
19868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19869 \begin_inset Text
19870
19871 \begin_layout Standard
19872 0.45k / 0.47k (+ _ltoa)
19873 \end_layout
19874
19875 \end_inset
19876 </cell>
19877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19878 \begin_inset Text
19879
19880 \begin_layout Standard
19881 1.2k / 1.2k
19882 \end_layout
19883
19884 \end_inset
19885 </cell>
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19887 \begin_inset Text
19888
19889 \begin_layout Standard
19890 1.6k / 1.6k
19891 \end_layout
19892
19893 \end_inset
19894 </cell>
19895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19896 \begin_inset Text
19897
19898 \begin_layout Standard
19899 0.26k / 0.26k
19900 \end_layout
19901
19902 \end_inset
19903 </cell>
19904 </row>
19905 <row topline="true">
19906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19907 \begin_inset Text
19908
19909 \begin_layout Standard
19910 formats
19911 \end_layout
19912
19913 \end_inset
19914 </cell>
19915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19916 \begin_inset Text
19917
19918 \begin_layout Standard
19919 cdi
19920 \emph on
19921 o
19922 \emph default
19923 psux
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 \family roman
19934 \series medium
19935 \shape up
19936 \size normal
19937 \emph off
19938 \bar no
19939 \noun off
19940 \color none
19941 cd
19942 \family default
19943 \series default
19944 \shape default
19945 \size default
19946 \emph default
19947 \bar default
19948 \noun default
19949 f
19950 \family roman
19951 \series medium
19952 \shape up
19953 \size normal
19954 \emph off
19955 \bar no
19956 \noun off
19957 i
19958 \family default
19959 \series default
19960 \shape default
19961 \size default
19962 \emph on
19963 \bar default
19964 \noun default
19965 o
19966 \family roman
19967 \series medium
19968 \shape up
19969 \size normal
19970 \emph off
19971 \bar no
19972 \noun off
19973 psux
19974 \end_layout
19975
19976 \end_inset
19977 </cell>
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19979 \begin_inset Text
19980
19981 \begin_layout Standard
19982 c
19983 \family roman
19984 \series medium
19985 \shape up
19986 \size normal
19987 \emph off
19988 \bar no
19989 \noun off
19990 \color none
19991 d
19992 \family default
19993 \series default
19994 \shape default
19995 \size default
19996 \emph on
19997 \bar default
19998 \noun default
19999 o
20000 \family roman
20001 \series medium
20002 \shape up
20003 \size normal
20004 \emph off
20005 \bar no
20006 \noun off
20007 s
20008 \family default
20009 \series default
20010 \shape default
20011 \size default
20012 \emph default
20013 \bar default
20014 \noun default
20015 x
20016 \end_layout
20017
20018 \end_inset
20019 </cell>
20020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20021 \begin_inset Text
20022
20023 \begin_layout Standard
20024 cdsux
20025 \end_layout
20026
20027 \end_inset
20028 </cell>
20029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20030 \begin_inset Text
20031
20032 \begin_layout Standard
20033 cdfsux
20034 \end_layout
20035
20036 \end_inset
20037 </cell>
20038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20039 \begin_inset Text
20040
20041 \begin_layout Standard
20042 cdsux
20043 \end_layout
20044
20045 \end_inset
20046 </cell>
20047 </row>
20048 <row topline="true">
20049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20050 \begin_inset Text
20051
20052 \begin_layout Standard
20053 long (32 bit) support
20054 \end_layout
20055
20056 \end_inset
20057 </cell>
20058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20059 \begin_inset Text
20060
20061 \begin_layout Standard
20062 x
20063 \end_layout
20064
20065 \end_inset
20066 </cell>
20067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20068 \begin_inset Text
20069
20070 \begin_layout Standard
20071 x
20072 \end_layout
20073
20074 \end_inset
20075 </cell>
20076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20077 \begin_inset Text
20078
20079 \begin_layout Standard
20080 x
20081 \end_layout
20082
20083 \end_inset
20084 </cell>
20085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20086 \begin_inset Text
20087
20088 \begin_layout Standard
20089 x
20090 \end_layout
20091
20092 \end_inset
20093 </cell>
20094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20095 \begin_inset Text
20096
20097 \begin_layout Standard
20098
20099 \family roman
20100 \series medium
20101 \shape up
20102 \size normal
20103 \emph off
20104 \bar no
20105 \noun off
20106 \color none
20107 x
20108 \end_layout
20109
20110 \end_inset
20111 </cell>
20112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20113 \begin_inset Text
20114
20115 \begin_layout Standard
20116 -
20117 \end_layout
20118
20119 \end_inset
20120 </cell>
20121 </row>
20122 <row topline="true">
20123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20124 \begin_inset Text
20125
20126 \begin_layout Standard
20127 byte arguments on stack
20128 \end_layout
20129
20130 \end_inset
20131 </cell>
20132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20133 \begin_inset Text
20134
20135 \begin_layout Standard
20136 b
20137 \end_layout
20138
20139 \end_inset
20140 </cell>
20141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20142 \begin_inset Text
20143
20144 \begin_layout Standard
20145 b
20146 \end_layout
20147
20148 \end_inset
20149 </cell>
20150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20151 \begin_inset Text
20152
20153 \begin_layout Standard
20154 -
20155 \end_layout
20156
20157 \end_inset
20158 </cell>
20159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20160 \begin_inset Text
20161
20162 \begin_layout Standard
20163 -
20164 \end_layout
20165
20166 \end_inset
20167 </cell>
20168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20169 \begin_inset Text
20170
20171 \begin_layout Standard
20172 -
20173 \end_layout
20174
20175 \end_inset
20176 </cell>
20177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20178 \begin_inset Text
20179
20180 \begin_layout Standard
20181 -
20182 \end_layout
20183
20184 \end_inset
20185 </cell>
20186 </row>
20187 <row topline="true">
20188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20189 \begin_inset Text
20190
20191 \begin_layout Standard
20192 float format
20193 \begin_inset LatexCommand \index{Floating point support}
20194
20195 \end_inset
20196
20197
20198 \end_layout
20199
20200 \end_inset
20201 </cell>
20202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20203 \begin_inset Text
20204
20205 \begin_layout Standard
20206 -
20207 \end_layout
20208
20209 \end_inset
20210 </cell>
20211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20212 \begin_inset Text
20213
20214 \begin_layout Standard
20215 %f
20216 \end_layout
20217
20218 \end_inset
20219 </cell>
20220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20221 \begin_inset Text
20222
20223 \begin_layout Standard
20224 -
20225 \end_layout
20226
20227 \end_inset
20228 </cell>
20229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20230 \begin_inset Text
20231
20232 \begin_layout Standard
20233 -
20234 \end_layout
20235
20236 \end_inset
20237 </cell>
20238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20239 \begin_inset Text
20240
20241 \begin_layout Standard
20242 %f
20243 \begin_inset Foot
20244 status collapsed
20245
20246 \begin_layout Standard
20247 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20248 \end_layout
20249
20250 \end_inset
20251
20252
20253 \end_layout
20254
20255 \end_inset
20256 </cell>
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20258 \begin_inset Text
20259
20260 \begin_layout Standard
20261 -
20262 \end_layout
20263
20264 \end_inset
20265 </cell>
20266 </row>
20267 <row topline="true">
20268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20269 \begin_inset Text
20270
20271 \begin_layout Standard
20272 float formats %e %g
20273 \end_layout
20274
20275 \end_inset
20276 </cell>
20277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20278 \begin_inset Text
20279
20280 \begin_layout Standard
20281 -
20282 \end_layout
20283
20284 \end_inset
20285 </cell>
20286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20287 \begin_inset Text
20288
20289 \begin_layout Standard
20290 -
20291 \end_layout
20292
20293 \end_inset
20294 </cell>
20295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20296 \begin_inset Text
20297
20298 \begin_layout Standard
20299 -
20300 \end_layout
20301
20302 \end_inset
20303 </cell>
20304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20305 \begin_inset Text
20306
20307 \begin_layout Standard
20308 -
20309 \end_layout
20310
20311 \end_inset
20312 </cell>
20313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20314 \begin_inset Text
20315
20316 \begin_layout Standard
20317 -
20318 \end_layout
20319
20320 \end_inset
20321 </cell>
20322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20323 \begin_inset Text
20324
20325 \begin_layout Standard
20326 -
20327 \end_layout
20328
20329 \end_inset
20330 </cell>
20331 </row>
20332 <row topline="true" bottomline="true">
20333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20334 \begin_inset Text
20335
20336 \begin_layout Standard
20337 field width
20338 \end_layout
20339
20340 \end_inset
20341 </cell>
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20343 \begin_inset Text
20344
20345 \begin_layout Standard
20346 x
20347 \end_layout
20348
20349 \end_inset
20350 </cell>
20351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20352 \begin_inset Text
20353
20354 \begin_layout Standard
20355 x
20356 \end_layout
20357
20358 \end_inset
20359 </cell>
20360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20361 \begin_inset Text
20362
20363 \begin_layout Standard
20364 -
20365 \end_layout
20366
20367 \end_inset
20368 </cell>
20369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20370 \begin_inset Text
20371
20372 \begin_layout Standard
20373 x
20374 \end_layout
20375
20376 \end_inset
20377 </cell>
20378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20379 \begin_inset Text
20380
20381 \begin_layout Standard
20382 x
20383 \end_layout
20384
20385 \end_inset
20386 </cell>
20387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20388 \begin_inset Text
20389
20390 \begin_layout Standard
20391 -
20392 \end_layout
20393
20394 \end_inset
20395 </cell>
20396 </row>
20397 <row bottomline="true">
20398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20399 \begin_inset Text
20400
20401 \begin_layout Standard
20402 string speed
20403 \begin_inset Foot
20404 status collapsed
20405
20406 \begin_layout Standard
20407 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20408 \backslash
20409 r', '
20410 \backslash
20411 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20412 \end_layout
20413
20414 \end_inset
20415
20416 ,
20417 \end_layout
20418
20419 \begin_layout Standard
20420 small / large
20421 \end_layout
20422
20423 \end_inset
20424 </cell>
20425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20426 \begin_inset Text
20427
20428 \begin_layout Standard
20429 1.52 / 2.59 ms
20430 \end_layout
20431
20432 \end_inset
20433 </cell>
20434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20435 \begin_inset Text
20436
20437 \begin_layout Standard
20438 1.53 / 2.62 ms
20439 \end_layout
20440
20441 \end_inset
20442 </cell>
20443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20444 \begin_inset Text
20445
20446 \begin_layout Standard
20447 0.92 / 0.93 ms
20448 \end_layout
20449
20450 \end_inset
20451 </cell>
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20453 \begin_inset Text
20454
20455 \begin_layout Standard
20456 0.45 / 0.45 ms
20457 \end_layout
20458
20459 \end_inset
20460 </cell>
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20462 \begin_inset Text
20463
20464 \begin_layout Standard
20465 0.46 / 0.46 ms
20466 \end_layout
20467
20468 \end_inset
20469 </cell>
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20471 \begin_inset Text
20472
20473 \begin_layout Standard
20474 0.45 / 0.45 ms
20475 \end_layout
20476
20477 \end_inset
20478 </cell>
20479 </row>
20480 <row bottomline="true">
20481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20482 \begin_inset Text
20483
20484 \begin_layout Standard
20485 int speed
20486 \begin_inset Foot
20487 status collapsed
20488
20489 \begin_layout Standard
20490 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20491  putchar()
20492 \end_layout
20493
20494 \end_inset
20495
20496 ,
20497 \end_layout
20498
20499 \begin_layout Standard
20500 small / large
20501 \end_layout
20502
20503 \end_inset
20504 </cell>
20505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20506 \begin_inset Text
20507
20508 \begin_layout Standard
20509 3.01 / 3.61 ms
20510 \end_layout
20511
20512 \end_inset
20513 </cell>
20514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20515 \begin_inset Text
20516
20517 \begin_layout Standard
20518 3.01 / 3.61 ms
20519 \end_layout
20520
20521 \end_inset
20522 </cell>
20523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20524 \begin_inset Text
20525
20526 \begin_layout Standard
20527 3.51 / 18.13 ms
20528 \end_layout
20529
20530 \end_inset
20531 </cell>
20532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20533 \begin_inset Text
20534
20535 \begin_layout Standard
20536 0.22 / 0.22 ms
20537 \end_layout
20538
20539 \end_inset
20540 </cell>
20541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20542 \begin_inset Text
20543
20544 \begin_layout Standard
20545 0.23 / 0.23 ms
20546 \end_layout
20547
20548 \end_inset
20549 </cell>
20550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20551 \begin_inset Text
20552
20553 \begin_layout Standard
20554 0.25 / 0.25 ms
20555 \begin_inset Foot
20556 status collapsed
20557
20558 \begin_layout Standard
20559 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20560 \end_layout
20561
20562 \end_inset
20563
20564
20565 \end_layout
20566
20567 \end_inset
20568 </cell>
20569 </row>
20570 <row bottomline="true">
20571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20572 \begin_inset Text
20573
20574 \begin_layout Standard
20575 long speed
20576 \begin_inset Foot
20577 status collapsed
20578
20579 \begin_layout Standard
20580 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20581  empty putchar()
20582 \end_layout
20583
20584 \end_inset
20585
20586 ,
20587 \end_layout
20588
20589 \begin_layout Standard
20590 small / large
20591 \end_layout
20592
20593 \end_inset
20594 </cell>
20595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20596 \begin_inset Text
20597
20598 \begin_layout Standard
20599 5.37 / 6.31 ms
20600 \end_layout
20601
20602 \end_inset
20603 </cell>
20604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20605 \begin_inset Text
20606
20607 \begin_layout Standard
20608 5.37 / 6.31 ms
20609 \end_layout
20610
20611 \end_inset
20612 </cell>
20613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20614 \begin_inset Text
20615
20616 \begin_layout Standard
20617 8.71 / 40.65 ms
20618 \end_layout
20619
20620 \end_inset
20621 </cell>
20622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20623 \begin_inset Text
20624
20625 \begin_layout Standard
20626 0.40 / 0.40 ms
20627 \end_layout
20628
20629 \end_inset
20630 </cell>
20631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20632 \begin_inset Text
20633
20634 \begin_layout Standard
20635 0.40 / 0.40 ms
20636 \end_layout
20637
20638 \end_inset
20639 </cell>
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20641 \begin_inset Text
20642
20643 \begin_layout Standard
20644 -
20645 \end_layout
20646
20647 \end_inset
20648 </cell>
20649 </row>
20650 <row bottomline="true">
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20652 \begin_inset Text
20653
20654 \begin_layout Standard
20655 float speed
20656 \begin_inset Foot
20657 status collapsed
20658
20659 \begin_layout Standard
20660 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20661  empty putchar()
20662 \end_layout
20663
20664 \end_inset
20665
20666 ,
20667 \end_layout
20668
20669 \begin_layout Standard
20670 small / large
20671 \end_layout
20672
20673 \end_inset
20674 </cell>
20675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20676 \begin_inset Text
20677
20678 \begin_layout Standard
20679 -
20680 \end_layout
20681
20682 \end_inset
20683 </cell>
20684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20685 \begin_inset Text
20686
20687 \begin_layout Standard
20688 7.49 / 22.47 ms
20689 \end_layout
20690
20691 \end_inset
20692 </cell>
20693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20694 \begin_inset Text
20695
20696 \begin_layout Standard
20697 -
20698 \end_layout
20699
20700 \end_inset
20701 </cell>
20702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20703 \begin_inset Text
20704
20705 \begin_layout Standard
20706 -
20707 \end_layout
20708
20709 \end_inset
20710 </cell>
20711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20712 \begin_inset Text
20713
20714 \begin_layout Standard
20715 1.04 / 1.04 ms
20716 \end_layout
20717
20718 \end_inset
20719 </cell>
20720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20721 \begin_inset Text
20722
20723 \begin_layout Standard
20724 -
20725 \end_layout
20726
20727 \end_inset
20728 </cell>
20729 </row>
20730 </lyxtabular>
20731
20732 \end_inset
20733
20734
20735 \end_layout
20736
20737 \begin_layout Subsubsection
20738 <malloc.h>
20739 \begin_inset LatexCommand \index{malloc.h}
20740
20741 \end_inset
20742
20743
20744 \end_layout
20745
20746 \begin_layout Standard
20747 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20748  using dynamic memory allocation
20749 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20750
20751 \end_inset
20752
20753  and a default heap
20754 \begin_inset LatexCommand \index{heap (malloc)}
20755
20756 \end_inset
20757
20758  space of 1024 bytes is provided for malloc to allocate memory from.
20759  If you need a different heap size you need to recompile _heap.c with the
20760  required size defined in HEAP_SIZE.
20761  It is recommended to make a copy of this file into your project directory
20762  and compile it there with:
20763 \end_layout
20764
20765 \begin_layout Verse
20766
20767 \family typewriter
20768 sdcc -c _heap.c -D HEAD_SIZE=2048
20769 \end_layout
20770
20771 \begin_layout Standard
20772 And then link it with:
20773 \end_layout
20774
20775 \begin_layout Verse
20776
20777 \family typewriter
20778 sdcc main.rel _heap.rel
20779 \end_layout
20780
20781 \begin_layout Subsection
20782 Math functions (sinf, powf, sqrtf etc.)
20783 \end_layout
20784
20785 \begin_layout Subsubsection
20786 <math.h>
20787 \end_layout
20788
20789 \begin_layout Standard
20790 See definitions in file <math.h>.
20791 \end_layout
20792
20793 \begin_layout Subsection
20794 Other libraries
20795 \end_layout
20796
20797 \begin_layout Standard
20798 Libraries
20799 \begin_inset LatexCommand \index{Libraries}
20800
20801 \end_inset
20802
20803  included in SDCC should have a license at least as liberal as the GNU Lesser
20804  General Public License
20805 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20806
20807 \end_inset
20808
20809  
20810 \emph on
20811 LGPL
20812 \emph default
20813 .
20814 \end_layout
20815
20816 \begin_layout Standard
20817 \begin_inset Note Note
20818 status collapsed
20819
20820 \begin_layout Standard
20821 license statements for the libraries are missing.
20822  sdcc/device/lib/ser_ir.c
20823 \end_layout
20824
20825 \begin_layout Standard
20826 or _decdptr f.e.
20827  come with a GPL (as opposed to LGPL) License - this will not be liberal
20828  enough for many embedded programmers.
20829 \end_layout
20830
20831 \end_inset
20832
20833
20834 \end_layout
20835
20836 \begin_layout Standard
20837 If you have ported some library or want to share experience about some code
20838  which f.e.
20839  falls into any of these categories Busses (I
20840 \begin_inset Formula $^{\textrm{2}}$
20841 \end_inset
20842
20843 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20844  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20845  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20846 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20847
20848 \end_inset
20849
20850 \InsetSpace ~
20851 would certainly like to hear about it.
20852 \end_layout
20853
20854 \begin_layout Standard
20855 Programmers coding for embedded systems are not especially famous for being
20856  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20857 e these references are very valuable.
20858  Let's help to create a climate where information is shared.
20859 \begin_inset VSpace bigskip
20860 \end_inset
20861
20862
20863 \end_layout
20864
20865 \begin_layout Section
20866 Memory Models
20867 \end_layout
20868
20869 \begin_layout Subsection
20870 MCS51 Memory Models
20871 \begin_inset LatexCommand \index{Memory model}
20872
20873 \end_inset
20874
20875
20876 \begin_inset LatexCommand \index{MCS51 memory model}
20877
20878 \end_inset
20879
20880
20881 \end_layout
20882
20883 \begin_layout Subsubsection
20884 Small, Medium and Large
20885 \end_layout
20886
20887 \begin_layout Standard
20888 SDCC allows three memory models for MCS51 code, 
20889 \shape slanted
20890 small, medium
20891 \shape default
20892  and 
20893 \shape slanted
20894 large
20895 \shape default
20896 .
20897  Modules compiled with different memory models should 
20898 \emph on
20899 never
20900 \emph default
20901  be combined together or the results would be unpredictable.
20902  The library routines supplied with the compiler are compiled as small,
20903  medium and large.
20904  The compiled library modules are contained in separate directories as small,
20905  medium and large so that you can link to the appropriate set.
20906 \end_layout
20907
20908 \begin_layout Standard
20909 When the medium or large model is used all variables declared without a
20910  storage class will be allocated into the external ram, this includes all
20911  parameters and local variables (for non-reentrant
20912 \begin_inset LatexCommand \index{reentrant}
20913
20914 \end_inset
20915
20916  functions).
20917  When the small model is used variables without storage class are allocated
20918  in the internal ram.
20919 \end_layout
20920
20921 \begin_layout Standard
20922 Judicious usage of the processor specific storage classes
20923 \begin_inset LatexCommand \index{Storage class}
20924
20925 \end_inset
20926
20927  and the 'reentrant' function type will yield much more efficient code,
20928  than using the large model.
20929  Several optimizations are disabled when the program is compiled using the
20930  large model, it is therefore recommended that the small model be used unless
20931  absolutely required.
20932 \end_layout
20933
20934 \begin_layout Subsubsection
20935 External Stack
20936 \begin_inset LatexCommand \label{sub:External-Stack}
20937
20938 \end_inset
20939
20940
20941 \begin_inset LatexCommand \index{stack}
20942
20943 \end_inset
20944
20945
20946 \begin_inset LatexCommand \index{External stack (mcs51)}
20947
20948 \end_inset
20949
20950
20951 \end_layout
20952
20953 \begin_layout Standard
20954 The external stack (-
20955 \begin_inset ERT
20956 status collapsed
20957
20958 \begin_layout Standard
20959
20960
20961 \backslash
20962 /
20963 \end_layout
20964
20965 \end_inset
20966
20967 -xstack option
20968 \begin_inset LatexCommand \index{-\/-xstack}
20969
20970 \end_inset
20971
20972 ) is located in pdata
20973 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20974
20975 \end_inset
20976
20977  memory (usually at the start of the external ram segment) and uses all
20978  unused space in pdata (max.
20979  256 bytes).
20980  When -
20981 \begin_inset ERT
20982 status collapsed
20983
20984 \begin_layout Standard
20985
20986
20987 \backslash
20988 /
20989 \end_layout
20990
20991 \end_inset
20992
20993 -xstack option is used to compile the program, the parameters and local
20994  variables
20995 \begin_inset LatexCommand \index{local variables}
20996
20997 \end_inset
20998
20999  of all reentrant functions are allocated in this area.
21000  This option is provided for programs with large stack space requirements.
21001  When used with the -
21002 \begin_inset ERT
21003 status collapsed
21004
21005 \begin_layout Standard
21006
21007
21008 \backslash
21009 /
21010 \end_layout
21011
21012 \end_inset
21013
21014 -stack-auto
21015 \begin_inset LatexCommand \index{-\/-stack-auto}
21016
21017 \end_inset
21018
21019  option, all parameters and local variables are allocated on the external
21020  stack (note: support libraries will need to be recompiled with the same
21021  options.
21022  There is a predefined target in the library makefile).
21023 \end_layout
21024
21025 \begin_layout Standard
21026 The compiler outputs the higher order address byte of the external ram segment
21027  into port P2
21028 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21029
21030 \end_inset
21031
21032  (see also section 
21033 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21034
21035 \end_inset
21036
21037 ), therefore when using the External Stack option, this port 
21038 \emph on
21039 may not
21040 \emph default
21041  be used by the application program.
21042 \end_layout
21043
21044 \begin_layout Subsection
21045 DS390 Memory Model
21046 \begin_inset LatexCommand \index{Memory model}
21047
21048 \end_inset
21049
21050
21051 \begin_inset LatexCommand \index{DS390 memory model}
21052
21053 \end_inset
21054
21055
21056 \end_layout
21057
21058 \begin_layout Standard
21059 The only model supported is Flat 24
21060 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21061
21062 \end_inset
21063
21064 .
21065  This generates code for the 24 bit contiguous addressing mode of the Dallas
21066  DS80C390 part.
21067  In this mode, up to four meg of external RAM or code space can be directly
21068  addressed.
21069  See the data sheets at www.dalsemi.com for further information on this part.
21070 \newline
21071
21072 \newline
21073 Note
21074  that the compiler does not generate any code to place the processor into
21075  24 bitmode (although 
21076 \emph on
21077 tinibios
21078 \emph default
21079  in the ds390 libraries will do that for you).
21080  If you don't use 
21081 \emph on
21082 tinibios
21083 \emph default
21084
21085 \begin_inset LatexCommand \index{Tinibios (DS390)}
21086
21087 \end_inset
21088
21089 , the boot loader or similar code must ensure that the processor is in 24
21090  bit contiguous addressing mode before calling the SDCC startup code.
21091 \newline
21092
21093 \newline
21094 Like
21095  the 
21096 \emph on
21097 -
21098 \begin_inset ERT
21099 status collapsed
21100
21101 \begin_layout Standard
21102
21103
21104 \backslash
21105 /
21106 \end_layout
21107
21108 \end_inset
21109
21110 -model-large
21111 \emph default
21112  option, variables will by default be placed into the XDATA segment.
21113  
21114 \newline
21115
21116 \newline
21117 Segments may be placed anywhere in the 4 meg address space using the usual
21118  -
21119 \begin_inset ERT
21120 status collapsed
21121
21122 \begin_layout Standard
21123
21124
21125 \backslash
21126 /
21127 \end_layout
21128
21129 \end_inset
21130
21131 -*-loc options.
21132  Note that if any segments are located above 64K, the -r flag must be passed
21133  to the linker to generate the proper segment relocations, and the Intel
21134  HEX output format must be used.
21135  The -r flag can be passed to the linker by using the option 
21136 \emph on
21137 -Wl-r
21138 \emph default
21139  on the SDCC command line.
21140  However, currently the linker can not handle code segments > 64k.
21141 \end_layout
21142
21143 \begin_layout Section
21144 Pragmas
21145 \begin_inset LatexCommand \label{sec:Pragmas}
21146
21147 \end_inset
21148
21149
21150 \begin_inset LatexCommand \index{Pragmas}
21151
21152 \end_inset
21153
21154
21155 \end_layout
21156
21157 \begin_layout Standard
21158 Pragmas are used to turn on and/or off certain compiler options.
21159  Some of them are closely related to corresponding command-line options
21160  (see section 
21161 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21162
21163 \end_inset
21164
21165 ).
21166 \newline
21167 Pragmas should be placed before and/or after a function, placing pragmas
21168  inside a function body could have unpredictable results.
21169 \newline
21170
21171 \newline
21172 SDCC supports the
21173  following #pragma directives:
21174 \end_layout
21175
21176 \begin_layout Itemize
21177
21178 \series bold
21179 save
21180 \series default
21181
21182 \begin_inset LatexCommand \index{\#pragma save}
21183
21184 \end_inset
21185
21186  - this will save most current options to the save/restore stack.
21187  See #pragma\InsetSpace ~
21188 restore.
21189 \end_layout
21190
21191 \begin_layout Itemize
21192
21193 \series bold
21194 restore
21195 \series default
21196
21197 \begin_inset LatexCommand \index{\#pragma restore}
21198
21199 \end_inset
21200
21201  - will restore saved options from the last save.
21202  saves & restores can be nested.
21203  SDCC uses a save/restore stack: save pushes current options to the stack,
21204  restore pulls current options from the stack.
21205  See #pragma\InsetSpace ~
21206 save.
21207 \newline
21208
21209 \end_layout
21210
21211 \begin_layout Itemize
21212
21213 \series bold
21214 callee_saves
21215 \series default
21216
21217 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21218
21219 \end_inset
21220
21221
21222 \begin_inset LatexCommand \index{function prologue}
21223
21224 \end_inset
21225
21226  function1[,function2[,function3...]] 
21227 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21228
21229 \end_inset
21230
21231 - The compiler by default uses a caller saves convention for register saving
21232  across function calls, however this can cause unnecessary register pushing
21233  and popping
21234 \begin_inset LatexCommand \index{push/pop}
21235
21236 \end_inset
21237
21238  when calling small functions from larger functions.
21239  This option can be used to switch off the register saving convention for
21240  the function names specified.
21241  The compiler will not save registers when calling these functions, extra
21242  code need to be manually inserted at the entry and exit for these functions
21243  to save and restore the registers used by these functions, this can SUBSTANTIAL
21244 LY reduce code and improve run time performance of the generated code.
21245  In the future the compiler (with inter procedural analysis) may be able
21246  to determine the appropriate scheme to use for each function call.
21247  If -
21248 \begin_inset ERT
21249 status collapsed
21250
21251 \begin_layout Standard
21252
21253
21254 \backslash
21255 /
21256 \end_layout
21257
21258 \end_inset
21259
21260 -callee-saves command line option is used (see page 
21261 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21262
21263 \end_inset
21264
21265 ), the function names specified in #pragma\InsetSpace ~
21266 callee_saves
21267 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21268
21269 \end_inset
21270
21271  is appended to the list of functions specified in the command line.
21272 \end_layout
21273
21274 \begin_layout Itemize
21275
21276 \series bold
21277 exclude
21278 \series default
21279
21280 \begin_inset LatexCommand \index{\#pragma exclude}
21281
21282 \end_inset
21283
21284  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21285  of pairs of push/pop
21286 \begin_inset LatexCommand \index{push/pop}
21287
21288 \end_inset
21289
21290  instructions in 
21291 \emph on
21292 I
21293 \emph default
21294 nterrupt
21295 \begin_inset LatexCommand \index{interrupt}
21296
21297 \end_inset
21298
21299  
21300 \emph on
21301 S
21302 \emph default
21303 ervice 
21304 \emph on
21305 R
21306 \emph default
21307 outines.
21308  The directive should be placed immediately before the ISR function definition
21309  and it affects ALL ISR functions following it.
21310  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21311 exclude\InsetSpace ~
21312 none
21313 \begin_inset LatexCommand \index{\#pragma exclude}
21314
21315 \end_inset
21316
21317 .
21318  See also the related keyword _naked
21319 \begin_inset LatexCommand \index{\_naked}
21320
21321 \end_inset
21322
21323
21324 \begin_inset LatexCommand \index{\_\_naked}
21325
21326 \end_inset
21327
21328 .
21329 \end_layout
21330
21331 \begin_layout Itemize
21332
21333 \series bold
21334 less_pedantic
21335 \series default
21336
21337 \begin_inset LatexCommand \index{pedantic}
21338
21339 \end_inset
21340
21341
21342 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21343
21344 \end_inset
21345
21346  
21347 \begin_inset LatexCommand \label{ite:less_pedantic}
21348
21349 \end_inset
21350
21351 - the compiler will not warn you anymore for obvious mistakes, you'r on
21352  your own now ;-( .
21353  See also the command line option -
21354 \begin_inset ERT
21355 status collapsed
21356
21357 \begin_layout Standard
21358
21359
21360 \backslash
21361 /
21362 \end_layout
21363
21364 \end_inset
21365
21366 -less-pedantic 
21367 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21368
21369 \end_inset
21370
21371 .
21372  
21373 \newline
21374 More specifically, the following warnings will be disabled: 
21375 \shape italic
21376 comparison is always [true/false] due to limited range of data type
21377 \shape default
21378  (94); 
21379 \shape italic
21380 overflow in implicit constant conversion
21381 \shape default
21382  (158); [the (in)famous] 
21383 \shape italic
21384 conditional flow changed by optimizer: so said EVELYN the modified DOG
21385 \shape default
21386  (110); 
21387 \shape italic
21388 function '[function name]' must return value
21389 \shape default
21390  (59).
21391  
21392 \newline
21393 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21394  level) are disabled, too, namely: 
21395 \shape italic
21396 constant value '[
21397 \begin_inset Note Note
21398 status collapsed
21399
21400 \begin_layout Standard
21401 dunno what comes here - this warning appears to be unused altogether
21402 \end_layout
21403
21404 \end_inset
21405
21406 ]', out of range
21407 \shape default
21408  (81); 
21409 \shape italic
21410 [left/right] shifting more than size of object changed to zero
21411 \shape default
21412  (116); 
21413 \shape italic
21414 unreachable code
21415 \shape default
21416  (126); 
21417 \shape italic
21418 integer overflow in expression
21419 \shape default
21420  (165); 
21421 \shape italic
21422 unmatched #pragma save and #pragma restore
21423 \shape default
21424  (170); 
21425 \shape italic
21426 comparison of 'signed char' with 'unsigned char' requires promotion to int
21427 \shape default
21428  (185); 
21429 \shape italic
21430 ISO C90 does not support flexible array members
21431 \shape default
21432  (187); 
21433 \shape italic
21434 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21435 nam
21436 e]':\InsetSpace ~
21437 [
21438 \begin_inset Note Note
21439 status collapsed
21440
21441 \begin_layout Standard
21442 appears to be always blank - what was supposed to be here?
21443 \end_layout
21444
21445 \end_inset
21446
21447 ]
21448 \shape default
21449  (114); 
21450 \shape italic
21451 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21452  complexity [number]
21453 \shape default
21454  (121).
21455 \end_layout
21456
21457 \begin_layout Itemize
21458
21459 \series bold
21460 disable_warning
21461 \series default
21462  <nnnn>
21463 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21464
21465 \end_inset
21466
21467  - the compiler will not warn you anymore about warning number <nnnn>.
21468 \end_layout
21469
21470 \begin_layout Itemize
21471
21472 \series bold
21473 nogcse
21474 \series default
21475
21476 \begin_inset LatexCommand \index{\#pragma nogcse}
21477
21478 \end_inset
21479
21480  - will stop global common subexpression elimination.
21481 \end_layout
21482
21483 \begin_layout Itemize
21484
21485 \series bold
21486 noinduction
21487 \series default
21488
21489 \begin_inset LatexCommand \index{\#pragma noinduction}
21490
21491 \end_inset
21492
21493  - will stop loop induction optimizations.
21494 \end_layout
21495
21496 \begin_layout Itemize
21497
21498 \series bold
21499 noinvariant
21500 \series default
21501
21502 \begin_inset LatexCommand \index{\#pragma noinvariant}
21503
21504 \end_inset
21505
21506  - will not do loop invariant optimizations.
21507  For more details see Loop Invariants in section
21508 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21509
21510 \end_inset
21511
21512 .
21513 \end_layout
21514
21515 \begin_layout Itemize
21516
21517 \series bold
21518 noiv
21519 \series default
21520
21521 \begin_inset LatexCommand \index{\#pragma noiv}
21522
21523 \end_inset
21524
21525  - Do not generate interrupt
21526 \begin_inset LatexCommand \index{interrupt}
21527
21528 \end_inset
21529
21530  vector table
21531 \begin_inset LatexCommand \index{interrupt vector table}
21532
21533 \end_inset
21534
21535  entries for all ISR functions defined after the pragma.
21536  This is useful in cases where the interrupt vector table must be defined
21537  manually, or when there is a secondary, manually defined interrupt vector
21538  table (e.g.
21539  for the autovector feature of the Cypress EZ-USB FX2).
21540  More elegantly this can be achieved by obmitting the optional interrupt
21541  number after the interrupt keyword, see section 
21542 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21543
21544 \end_inset
21545
21546 \InsetSpace ~
21547 about interrupts.
21548 \end_layout
21549
21550 \begin_layout Itemize
21551
21552 \series bold
21553 nojtbound
21554 \series default
21555
21556 \begin_inset LatexCommand \index{\#pragma nojtbound}
21557
21558 \end_inset
21559
21560  - will not generate code for boundary value checking, when switch statements
21561  are turned into jump-tables (dangerous).
21562  For more details see section 
21563 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21564
21565 \end_inset
21566
21567 .
21568 \end_layout
21569
21570 \begin_layout Itemize
21571
21572 \series bold
21573 noloopreverse
21574 \series default
21575
21576 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21577
21578 \end_inset
21579
21580  - Will not do loop reversal optimization
21581 \end_layout
21582
21583 \begin_layout Itemize
21584
21585 \series bold
21586 nooverlay
21587 \series default
21588
21589 \begin_inset LatexCommand \index{\#pragma nooverlay}
21590
21591 \end_inset
21592
21593  - the compiler will not overlay the parameters and local variables of a
21594  function.
21595 \end_layout
21596
21597 \begin_layout Itemize
21598
21599 \series bold
21600 stackauto
21601 \series default
21602
21603 \begin_inset LatexCommand \index{\#pragma stackauto}
21604
21605 \end_inset
21606
21607 - See option -
21608 \begin_inset ERT
21609 status collapsed
21610
21611 \begin_layout Standard
21612
21613
21614 \backslash
21615 /
21616 \end_layout
21617
21618 \end_inset
21619
21620 -stack-auto
21621 \begin_inset LatexCommand \index{-\/-stack-auto}
21622
21623 \end_inset
21624
21625  and section 
21626 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21627
21628 \end_inset
21629
21630  Parameters and Local Variables.
21631 \end_layout
21632
21633 \begin_layout Itemize
21634
21635 \series bold
21636 opt_code_speed
21637 \series default
21638  
21639 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21640
21641 \end_inset
21642
21643 - The compiler will optimize code generation towards fast code, possibly
21644  at the expense of code size.
21645  Currently this has little effect.
21646 \end_layout
21647
21648 \begin_layout Itemize
21649
21650 \series bold
21651 opt_code_size
21652 \series default
21653  
21654 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21655
21656 \end_inset
21657
21658 - The compiler will optimize code generation towards compact code, possibly
21659  at the expense of code speed.
21660  Currently this has little effect.
21661 \end_layout
21662
21663 \begin_layout Itemize
21664
21665 \series bold
21666 opt_code_balanced
21667 \series default
21668  
21669 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21670
21671 \end_inset
21672
21673 - The compiler will attempt to generate code that is both compact and fast,
21674  as long as meeting one goal is not a detriment to the other (this is the
21675  default).
21676  
21677 \end_layout
21678
21679 \begin_layout Itemize
21680
21681 \series bold
21682 std_sdcc89
21683 \series default
21684  
21685 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21686
21687 \end_inset
21688
21689 - Generally follow the C89 standard, but allow SDCC features that conflict
21690  with the standard (default).
21691 \end_layout
21692
21693 \begin_layout Itemize
21694
21695 \series bold
21696 std_c89
21697 \series default
21698  
21699 \begin_inset LatexCommand \index{\#pragma std\_c89}
21700
21701 \end_inset
21702
21703 - Follow the C89 standard and disable SDCC features that conflict with the
21704  standard.
21705 \end_layout
21706
21707 \begin_layout Itemize
21708
21709 \series bold
21710 std_sdcc99
21711 \series default
21712  
21713 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21714
21715 \end_inset
21716
21717 - Generally follow the C99 standard, but allow SDCC features that conflict
21718  with the standard (incomplete support).
21719 \end_layout
21720
21721 \begin_layout Itemize
21722
21723 \series bold
21724 std_c99
21725 \series default
21726  
21727 \begin_inset LatexCommand \index{\#pragma std\_c99}
21728
21729 \end_inset
21730
21731 - Follow the C99 standard and disable SDCC features that conflict with the
21732  standard (incomplete support).
21733 \end_layout
21734
21735 \begin_layout Itemize
21736
21737 \series bold
21738 codeseg
21739 \series default
21740  <name>
21741 \begin_inset LatexCommand \index{\#pragma codeseg}
21742
21743 \end_inset
21744
21745 - Use this name (max.
21746  8 characters) for the code segment.
21747  See option -
21748 \begin_inset ERT
21749 status collapsed
21750
21751 \begin_layout Standard
21752
21753
21754 \backslash
21755 /
21756 \end_layout
21757
21758 \end_inset
21759
21760 -codeseg.
21761 \end_layout
21762
21763 \begin_layout Itemize
21764
21765 \series bold
21766 constseg
21767 \series default
21768  <name>
21769 \begin_inset LatexCommand \index{\#pragma constseg}
21770
21771 \end_inset
21772
21773 - Use this name (max.
21774  8 characters) for the const segment.
21775  See option -
21776 \begin_inset ERT
21777 status collapsed
21778
21779 \begin_layout Standard
21780
21781
21782 \backslash
21783 /
21784 \end_layout
21785
21786 \end_inset
21787
21788 -constseg.
21789 \end_layout
21790
21791 \begin_layout Standard
21792 The preprocessor SDCPP
21793 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21794
21795 \end_inset
21796
21797  supports the following #pragma directives:
21798 \end_layout
21799
21800 \begin_layout Itemize
21801
21802 \series bold
21803 pedantic_parse_number
21804 \series default
21805
21806 \begin_inset LatexCommand \index{pedantic}
21807
21808 \end_inset
21809
21810
21811 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21812
21813 \end_inset
21814
21815  (+ | -) 
21816 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21817
21818 \end_inset
21819
21820 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21821  properly and the macro LO_B(3) gets expanded.
21822  Default is off.
21823  See also the -
21824 \begin_inset ERT
21825 status collapsed
21826
21827 \begin_layout Standard
21828
21829
21830 \backslash
21831 /
21832 \end_layout
21833
21834 \end_inset
21835
21836 -pedantic-parse-number command line option 
21837 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21838
21839 \end_inset
21840
21841 .
21842  
21843 \newline
21844 Below is an example on how to use this pragma.
21845
21846 \emph on
21847  Note: this functionality is not in conformance with standard!
21848 \end_layout
21849
21850 \begin_layout Verse
21851
21852 \family typewriter
21853 #pragma pedantic_parse_number +
21854 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21855
21856 \end_inset
21857
21858
21859 \newline
21860
21861 \newline
21862 #define LO_B(x) ((x) & 0xff)
21863 \newline
21864
21865 \newline
21866 unsigned char foo(void)
21867 \newline
21868 {
21869 \newline
21870 \InsetSpace ~
21871 \InsetSpace ~
21872 \InsetSpace ~
21873 unsigned char c=0xfe-LO_B(3)
21874 ;
21875 \newline
21876
21877 \newline
21878 \InsetSpace ~
21879 \InsetSpace ~
21880 \InsetSpace ~
21881 return c;
21882 \newline
21883 }
21884 \newline
21885
21886 \end_layout
21887
21888 \begin_layout Itemize
21889
21890 \series bold
21891 preproc_asm
21892 \series default
21893
21894 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21895
21896 \end_inset
21897
21898  (+ | -) - switch _asm _endasm block preprocessing on / off.
21899  Default is on.
21900  You use this prama to define multilines of assembly code.
21901  This will prevent the preprocessor from changing the formating required
21902  by assembly code.
21903  Below is an example on how to use this pragma.
21904 \end_layout
21905
21906 \begin_layout Verse
21907
21908 \family typewriter
21909 #pragma preproc_asm -
21910 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21911
21912 \end_inset
21913
21914
21915 \newline
21916 #define MYDELAY _asm
21917 \newline
21918 \InsetSpace ~
21919 \InsetSpace ~
21920 \InsetSpace ~
21921 nop ;my assembly comment...
21922 \newline
21923 \InsetSpace ~
21924 \InsetSpace ~
21925 \InsetSpace ~
21926 nop
21927 \newline
21928 \InsetSpace ~
21929 \InsetSpace ~
21930 \InsetSpace ~
21931 nop
21932 \newline
21933 _endasm
21934 \newline
21935 #pragma preproc_asm
21936  +
21937 \newline
21938
21939 \newline
21940 void foo (void) 
21941 \newline
21942
21943 \newline
21944 \InsetSpace ~
21945 \InsetSpace ~
21946 \InsetSpace ~
21947  ...
21948  
21949 \newline
21950 \InsetSpace ~
21951 \InsetSpace ~
21952 \InsetSpace ~
21953  MYDELAY;
21954 \newline
21955 \InsetSpace ~
21956 \InsetSpace ~
21957 \InsetSpace ~
21958  ...
21959  
21960 \newline
21961
21962 \newline
21963
21964 \end_layout
21965
21966 \begin_layout Itemize
21967
21968 \series bold
21969 sdcc_hash
21970 \series default
21971
21972 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21973
21974 \end_inset
21975
21976  (+ | -) - Allow "naked" hash in macro definition, for example:
21977 \newline
21978
21979 \family typewriter
21980 #define DIR_LO(x) #(x & 0xff)
21981 \family default
21982
21983 \newline
21984 Default is off.
21985  Below is an example on how to use this pragma.
21986 \end_layout
21987
21988 \begin_layout Verse
21989
21990 \family typewriter
21991 #pragma preproc_asm +
21992 \newline
21993 #pragma sdcc_hash +
21994 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21995
21996 \end_inset
21997
21998
21999 \newline
22000
22001 \newline
22002 #define ROMCALL(x) 
22003 \backslash
22004
22005 \newline
22006 \InsetSpace ~
22007 \InsetSpace ~
22008 \InsetSpace ~
22009 mov R6_B3, #(x & 0xff) 
22010 \backslash
22011
22012 \newline
22013 \InsetSpace ~
22014 \InsetSpace ~
22015 \InsetSpace ~
22016 mov R7_B3, #((x >> 8) & 0xff) 
22017 \backslash
22018
22019 \newline
22020 \InsetSpace ~
22021 \InsetSpace ~
22022 \InsetSpace ~
22023 lcall __romcall
22024 \newline
22025
22026 \newline
22027 ...
22028 \newline
22029 _asm
22030 \newline
22031 ROMCALL(72)
22032 \newline
22033 _endasm;
22034 \newline
22035 ...
22036 \newline
22037
22038 \end_layout
22039
22040 \begin_layout Standard
22041 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22042 ons which might cause the compiler to generate extra stack and/or data space
22043  to store compiler generated temporary variables.
22044  This usually happens in large functions.
22045  Pragma directives should be used as shown in the following example, they
22046  are used to control options and optimizations for a given function.
22047  
22048 \end_layout
22049
22050 \begin_layout Verse
22051
22052 \family typewriter
22053 #pragma save
22054 \begin_inset LatexCommand \index{\#pragma save}
22055
22056 \end_inset
22057
22058  \InsetSpace ~
22059 \InsetSpace ~
22060 \InsetSpace ~
22061 \InsetSpace ~
22062 \InsetSpace ~
22063 \InsetSpace ~
22064 \InsetSpace ~
22065 /* save the current settings */ 
22066 \newline
22067 #pragma nogcse
22068 \begin_inset LatexCommand \index{\#pragma nogcse}
22069
22070 \end_inset
22071
22072  \InsetSpace ~
22073 \InsetSpace ~
22074 \InsetSpace ~
22075 \InsetSpace ~
22076 \InsetSpace ~
22077 /* turnoff global subexpression elimination */ 
22078 \newline
22079 #pragma noinduction
22080 \begin_inset LatexCommand \index{\#pragma noinduction}
22081
22082 \end_inset
22083
22084  /* turn off induction optimizations */ 
22085 \newline
22086 int foo () 
22087 \newline
22088
22089 \newline
22090 \InsetSpace ~
22091  \InsetSpace ~
22092  ...
22093  
22094 \newline
22095 \InsetSpace ~
22096  \InsetSpace ~
22097  /* large code */ 
22098 \newline
22099 \InsetSpace ~
22100  \InsetSpace ~
22101  ...
22102  
22103 \newline
22104
22105 \newline
22106 #pragma restore
22107 \begin_inset LatexCommand \index{\#pragma restore}
22108
22109 \end_inset
22110
22111  /* turn the optimizations back on */
22112 \end_layout
22113
22114 \begin_layout Standard
22115 The compiler will generate a warning message when extra space is allocated.
22116  It is strongly recommended that the save and restore pragma's be used when
22117  changing options for a function.
22118 \newline
22119
22120 \newline
22121
22122 \newline
22123
22124 \end_layout
22125
22126 \begin_layout Section
22127 Defines Created by the Compiler
22128 \end_layout
22129
22130 \begin_layout Standard
22131 The compiler creates the following #defines
22132 \begin_inset LatexCommand \index{\#defines}
22133
22134 \end_inset
22135
22136
22137 \begin_inset LatexCommand \index{Defines created by the compiler}
22138
22139 \end_inset
22140
22141 :
22142 \newline
22143
22144 \end_layout
22145
22146 \begin_layout Standard
22147 \begin_inset Tabular
22148 <lyxtabular version="3" rows="11" columns="2">
22149 <features>
22150 <column alignment="left" valignment="top" leftline="true" width="3in">
22151 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22152 <row topline="true" bottomline="true">
22153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22154 \begin_inset Text
22155
22156 \begin_layout Standard
22157
22158 \series bold
22159 #define
22160 \end_layout
22161
22162 \end_inset
22163 </cell>
22164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22165 \begin_inset Text
22166
22167 \begin_layout Standard
22168
22169 \series bold
22170 Description
22171 \end_layout
22172
22173 \end_inset
22174 </cell>
22175 </row>
22176 <row topline="true">
22177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22178 \begin_inset Text
22179
22180 \begin_layout Standard
22181 SDCC
22182 \begin_inset LatexCommand \index{SDCC}
22183
22184 \end_inset
22185
22186  
22187 \end_layout
22188
22189 \end_inset
22190 </cell>
22191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22192 \begin_inset Text
22193
22194 \begin_layout Standard
22195 Always defined.
22196  Since version 2.5.6 the version number as an int (ex.
22197  256)
22198 \end_layout
22199
22200 \end_inset
22201 </cell>
22202 </row>
22203 <row topline="true">
22204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22205 \begin_inset Text
22206
22207 \begin_layout Standard
22208 SDCC_mcs51
22209 \begin_inset LatexCommand \index{SDCC\_mcs51}
22210
22211 \end_inset
22212
22213  or SDCC_ds390
22214 \begin_inset LatexCommand \index{SDCC\_ds390}
22215
22216 \end_inset
22217
22218  or SDCC_z80
22219 \begin_inset LatexCommand \index{SDCC\_z80}
22220
22221 \end_inset
22222
22223 , etc.
22224 \end_layout
22225
22226 \end_inset
22227 </cell>
22228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22229 \begin_inset Text
22230
22231 \begin_layout Standard
22232 depending on the model used (e.g.: -mds390)
22233 \end_layout
22234
22235 \end_inset
22236 </cell>
22237 </row>
22238 <row topline="true">
22239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22240 \begin_inset Text
22241
22242 \begin_layout Standard
22243 __mcs51
22244 \begin_inset LatexCommand \index{\_\_mcs51}
22245
22246 \end_inset
22247
22248 , __ds390
22249 \begin_inset LatexCommand \index{\_\_ds390}
22250
22251 \end_inset
22252
22253 , __hc08
22254 \begin_inset LatexCommand \index{\_\_hc08}
22255
22256 \end_inset
22257
22258 , __z80
22259 \begin_inset LatexCommand \index{\_\_z80}
22260
22261 \end_inset
22262
22263 , etc
22264 \end_layout
22265
22266 \end_inset
22267 </cell>
22268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22269 \begin_inset Text
22270
22271 \begin_layout Standard
22272 depending on the model used (e.g.
22273  -mz80)
22274 \end_layout
22275
22276 \end_inset
22277 </cell>
22278 </row>
22279 <row topline="true">
22280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22281 \begin_inset Text
22282
22283 \begin_layout Standard
22284 SDCC_STACK_AUTO
22285 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22286
22287 \end_inset
22288
22289
22290 \end_layout
22291
22292 \end_inset
22293 </cell>
22294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22295 \begin_inset Text
22296
22297 \begin_layout Standard
22298 when 
22299 \emph on
22300 -
22301 \begin_inset ERT
22302 status collapsed
22303
22304 \begin_layout Standard
22305
22306
22307 \backslash
22308 /
22309 \end_layout
22310
22311 \end_inset
22312
22313 -stack-auto
22314 \emph default
22315  option is used
22316 \end_layout
22317
22318 \end_inset
22319 </cell>
22320 </row>
22321 <row topline="true">
22322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22323 \begin_inset Text
22324
22325 \begin_layout Standard
22326 SDCC_MODEL_SMALL
22327 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22328
22329 \end_inset
22330
22331
22332 \end_layout
22333
22334 \end_inset
22335 </cell>
22336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22337 \begin_inset Text
22338
22339 \begin_layout Standard
22340 when 
22341 \emph on
22342 -
22343 \begin_inset ERT
22344 status collapsed
22345
22346 \begin_layout Standard
22347
22348
22349 \backslash
22350 /
22351 \end_layout
22352
22353 \end_inset
22354
22355 -model-small
22356 \emph default
22357  is used
22358 \end_layout
22359
22360 \end_inset
22361 </cell>
22362 </row>
22363 <row topline="true">
22364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22365 \begin_inset Text
22366
22367 \begin_layout Standard
22368 SDCC_MODEL_MEDIUM
22369 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22370
22371 \end_inset
22372
22373
22374 \end_layout
22375
22376 \end_inset
22377 </cell>
22378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22379 \begin_inset Text
22380
22381 \begin_layout Standard
22382 when 
22383 \emph on
22384 -
22385 \begin_inset ERT
22386 status collapsed
22387
22388 \begin_layout Standard
22389
22390
22391 \backslash
22392 /
22393 \end_layout
22394
22395 \end_inset
22396
22397 -model-medium
22398 \emph default
22399  is used
22400 \end_layout
22401
22402 \end_inset
22403 </cell>
22404 </row>
22405 <row topline="true">
22406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22407 \begin_inset Text
22408
22409 \begin_layout Standard
22410 SDCC_MODEL_LARGE
22411 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22412
22413 \end_inset
22414
22415
22416 \end_layout
22417
22418 \end_inset
22419 </cell>
22420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22421 \begin_inset Text
22422
22423 \begin_layout Standard
22424 when 
22425 \emph on
22426 -
22427 \begin_inset ERT
22428 status collapsed
22429
22430 \begin_layout Standard
22431
22432
22433 \backslash
22434 /
22435 \end_layout
22436
22437 \end_inset
22438
22439 -model-large
22440 \emph default
22441  is used
22442 \end_layout
22443
22444 \end_inset
22445 </cell>
22446 </row>
22447 <row topline="true">
22448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22449 \begin_inset Text
22450
22451 \begin_layout Standard
22452 SDCC_USE_XSTACK
22453 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22454
22455 \end_inset
22456
22457
22458 \end_layout
22459
22460 \end_inset
22461 </cell>
22462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22463 \begin_inset Text
22464
22465 \begin_layout Standard
22466 when 
22467 \emph on
22468 -
22469 \begin_inset ERT
22470 status collapsed
22471
22472 \begin_layout Standard
22473
22474
22475 \backslash
22476 /
22477 \end_layout
22478
22479 \end_inset
22480
22481 -xstack
22482 \emph default
22483  option is used
22484 \end_layout
22485
22486 \end_inset
22487 </cell>
22488 </row>
22489 <row topline="true">
22490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22491 \begin_inset Text
22492
22493 \begin_layout Standard
22494 SDCC_STACK_TENBIT
22495 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22496
22497 \end_inset
22498
22499  
22500 \end_layout
22501
22502 \end_inset
22503 </cell>
22504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22505 \begin_inset Text
22506
22507 \begin_layout Standard
22508 when 
22509 \emph on
22510 -mds390
22511 \emph default
22512  is used
22513 \end_layout
22514
22515 \end_inset
22516 </cell>
22517 </row>
22518 <row topline="true" bottomline="true">
22519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22520 \begin_inset Text
22521
22522 \begin_layout Standard
22523 SDCC_MODEL_FLAT24
22524 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22525
22526 \end_inset
22527
22528
22529 \end_layout
22530
22531 \end_inset
22532 </cell>
22533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22534 \begin_inset Text
22535
22536 \begin_layout Standard
22537 when 
22538 \emph on
22539 -mds390
22540 \emph default
22541  is used
22542 \end_layout
22543
22544 \end_inset
22545 </cell>
22546 </row>
22547 </lyxtabular>
22548
22549 \end_inset
22550
22551
22552 \end_layout
22553
22554 \begin_layout Chapter
22555 Notes on supported Processors
22556 \end_layout
22557
22558 \begin_layout Section
22559 MCS51 variants
22560 \begin_inset LatexCommand \label{sub:MCS51-variants}
22561
22562 \end_inset
22563
22564
22565 \begin_inset LatexCommand \index{MCS51 variants}
22566
22567 \end_inset
22568
22569
22570 \end_layout
22571
22572 \begin_layout Standard
22573 MCS51 processors are available from many vendors and come in many different
22574  flavours.
22575  While they might differ considerably in respect to Special Function Registers
22576  the core MCS51 is usually not modified or is kept compatible.
22577  
22578 \end_layout
22579
22580 \begin_layout Subsection
22581 pdata access by SFR 
22582 \end_layout
22583
22584 \begin_layout Standard
22585 With the upcome of devices with internal xdata and flash memory devices
22586  using port P2
22587 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22588
22589 \end_inset
22590
22591  as dedicated I/O port is becoming more popular.
22592  Switching the high byte for pdata
22593 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22594
22595 \end_inset
22596
22597  access which was formerly done by port P2 is then achieved by a Special
22598  Function Register
22599 \begin_inset LatexCommand \index{sfr}
22600
22601 \end_inset
22602
22603 .
22604  In well-established MCS51 tradition the address of this 
22605 \emph on
22606 sfr
22607 \emph default
22608  is where the chip designers decided to put it.
22609  Needless to say that they didn't agree on a common name either.
22610  So that the startup code can correctly initialize xdata variables, you
22611  should define an sfr with the name _XPAGE
22612 \family typewriter
22613
22614 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22615
22616 \end_inset
22617
22618
22619 \family default
22620  at the appropriate location if the default, port P2, is not used for this.
22621  Some examples are:
22622 \end_layout
22623
22624 \begin_layout Verse
22625
22626 \family typewriter
22627 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22628  MPAGE */
22629 \end_layout
22630
22631 \begin_layout Verse
22632
22633 \family typewriter
22634 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22635  a.k.a.
22636  MPAGE */
22637 \end_layout
22638
22639 \begin_layout Verse
22640
22641 \family typewriter
22642 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22643  XPAGE */
22644 \end_layout
22645
22646 \begin_layout Verse
22647
22648 \family typewriter
22649 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22650  EMI0CN */
22651 \end_layout
22652
22653 \begin_layout Verse
22654
22655 \family typewriter
22656 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22657  EMI0CN */
22658 \end_layout
22659
22660 \begin_layout Standard
22661 For more exotic implementations further customizations may be needed.
22662  See section 
22663 \begin_inset LatexCommand \ref{sub:Startup-Code}
22664
22665 \end_inset
22666
22667  for other possibilities.
22668 \end_layout
22669
22670 \begin_layout Subsection
22671 Other Features available by SFR
22672 \end_layout
22673
22674 \begin_layout Standard
22675 Some MCS51 variants offer features like Double DPTR
22676 \begin_inset LatexCommand \index{DPTR}
22677
22678 \end_inset
22679
22680 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22681  These are currently not used for the MCS51 port.
22682  If you absolutely need them you can fall back to inline assembly or submit
22683  a patch to SDCC.
22684 \begin_inset VSpace bigskip
22685 \end_inset
22686
22687
22688 \end_layout
22689
22690 \begin_layout Section
22691 DS400 port
22692 \end_layout
22693
22694 \begin_layout Standard
22695 The DS80C400
22696 \begin_inset LatexCommand \index{DS80C400}
22697
22698 \end_inset
22699
22700
22701 \begin_inset LatexCommand \index{DS400}
22702
22703 \end_inset
22704
22705  microcontroller has a rich set of peripherals.
22706  In its built-in ROM library it includes functions to access some of the
22707  features, among them is a TCP stack with IP4 and IP6 support.
22708  Library headers (currently in beta status) and other files are provided
22709  at 
22710 \size footnotesize
22711
22712 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22713
22714 \end_inset
22715
22716 .
22717  
22718 \begin_inset VSpace bigskip
22719 \end_inset
22720
22721
22722 \end_layout
22723
22724 \begin_layout Section
22725 The Z80 and gbz80 port
22726 \end_layout
22727
22728 \begin_layout Standard
22729 SDCC can target both the Zilog Z80
22730 \begin_inset LatexCommand \index{Z80}
22731
22732 \end_inset
22733
22734  and the Nintendo Gameboy's Z80-like gbz80
22735 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22736
22737 \end_inset
22738
22739 .
22740  The Z80 port is passed through the same 
22741 \emph on
22742 regressions tests
22743 \begin_inset LatexCommand \index{Regression test}
22744
22745 \end_inset
22746
22747
22748 \emph default
22749  (see section 
22750 \begin_inset LatexCommand \ref{sec:Quality-control}
22751
22752 \end_inset
22753
22754 ) as the MCS51 and DS390 ports, so floating point support, support for long
22755  variables and bitfield support is fine.
22756  See mailing lists and forums about interrupt routines.
22757 \end_layout
22758
22759 \begin_layout Standard
22760 As always, the code is the authoritative reference - see z80/ralloc.c and
22761  z80/gen.c.
22762  The stack
22763 \begin_inset LatexCommand \index{Z80!stack}
22764
22765 \end_inset
22766
22767  frame is similar to that generated by the IAR Z80 compiler.
22768  IX is used as the base pointer, HL and IY are used as a temporary registers,
22769  and BC and DE are available for holding variables.
22770  Return values
22771 \begin_inset LatexCommand \index{Z80!return value}
22772
22773 \end_inset
22774
22775  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22776  bytes).
22777  The gbz80 port use the same set of registers for the return values, but
22778  in a different order of significance: E (one byte), DE (two bytes), or
22779  HLDE (four bytes).
22780 \begin_inset VSpace bigskip
22781 \end_inset
22782
22783
22784 \end_layout
22785
22786 \begin_layout Section
22787 The HC08 port
22788 \end_layout
22789
22790 \begin_layout Standard
22791 The port to the Freescale/Motorola HC08
22792 \begin_inset LatexCommand \index{HC08}
22793
22794 \end_inset
22795
22796  family has been added in October 2003, and is still undergoing some basic
22797  development.
22798  The code generator is complete, but the register allocation is still quite
22799  unoptimized.
22800  Some of the SDCC's standard C library functions have embedded non-HC08
22801  inline assembly and so are not yet usable.
22802 \end_layout
22803
22804 \begin_layout Standard
22805 The HC08 port passes the regression test suite (see section 
22806 \begin_inset LatexCommand \ref{sec:Quality-control}
22807
22808 \end_inset
22809
22810 ).
22811 \begin_inset VSpace bigskip
22812 \end_inset
22813
22814
22815 \newpage
22816
22817 \end_layout
22818
22819 \begin_layout Section
22820 The PIC14 port
22821 \end_layout
22822
22823 \begin_layout Standard
22824 The PIC14 port adds support for Microchip(TM)'s 14
22825 \begin_inset ERT
22826 status open
22827
22828 \begin_layout Standard
22829
22830
22831 \backslash
22832 ,
22833 \end_layout
22834
22835 \end_inset
22836
22837 bit PIC
22838 \begin_inset LatexCommand \index{PIC14}
22839
22840 \end_inset
22841
22842  MCUs.
22843  This port is not yet mature and still lacks many features.
22844  However, it can work for simple code.
22845 \end_layout
22846
22847 \begin_layout Standard
22848 Currently supported devices include:
22849 \end_layout
22850
22851 \begin_layout Standard
22852 12F: 629, 635, 675, 683
22853 \end_layout
22854
22855 \begin_layout Standard
22856 16C: 432, 433
22857 \end_layout
22858
22859 \begin_layout Standard
22860 16C: 554, 557, 558
22861 \end_layout
22862
22863 \begin_layout Standard
22864 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
22865 \end_layout
22866
22867 \begin_layout Standard
22868 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
22869  781, 782
22870 \end_layout
22871
22872 \begin_layout Standard
22873 16C: 925, 926
22874 \end_layout
22875
22876 \begin_layout Standard
22877 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
22878  689, 690
22879 \end_layout
22880
22881 \begin_layout Standard
22882 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
22883 \end_layout
22884
22885 \begin_layout Standard
22886 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
22887  877, 877a, 88
22888 \end_layout
22889
22890 \begin_layout Standard
22891 16F: 913, 914, 916, 917
22892 \end_layout
22893
22894 \begin_layout Standard
22895 An up-to-date list of currently supported devices can be obtained via 
22896 \family typewriter
22897 sdcc -mpic14 -phelp foo.c
22898 \family default
22899  (foo.c must exist...).
22900 \end_layout
22901
22902 \begin_layout Subsection
22903 PIC Code Pages
22904 \begin_inset LatexCommand \index{code page (pic14)}
22905
22906 \end_inset
22907
22908  and Memory Banks
22909 \begin_inset LatexCommand \index{Memory bank (pic14)}
22910
22911 \end_inset
22912
22913
22914 \end_layout
22915
22916 \begin_layout Standard
22917 The linker organizes allocation for the code page and RAM banks.
22918  It does not have intimate knowledge of the code flow.
22919  It will put all the code section of a single .asm file into a single code
22920  page.
22921  In order to make use of multiple code pages, separate asm files must be
22922  used.
22923  The compiler assigns all 
22924 \emph on
22925 static
22926 \emph default
22927  functions of a single .c file into the same code page.
22928 \newline
22929
22930 \newline
22931 To get the best results,
22932  follow these guidelines:
22933 \end_layout
22934
22935 \begin_layout Enumerate
22936 Make local functions static, as non static functions require code page selection
22937  overhead.
22938 \newline
22939 Due to the way sdcc handles functions, place called functions prior
22940  to calling functions in the file wherever possible: Otherwise sdcc will
22941  insert unneccessary pagesel directives around the call, believing that
22942  the called function is externally defined.
22943 \end_layout
22944
22945 \begin_layout Enumerate
22946 For devices that have multiple code pages it is more efficient to use the
22947  same number of files as pages: Use up to 4 separate .c files for the 16F877,
22948  but only 2 files for the 16F874.
22949  This way the linker can put the code for each file into different code
22950  pages and there will be less page selection overhead.
22951 \end_layout
22952
22953 \begin_layout Enumerate
22954 And as for any 8 bit micro (especially for PIC14 as they have a very simple
22955  instruction set), use 'unsigned char' wherever possible instead of 'int'.
22956 \end_layout
22957
22958 \begin_layout Subsection
22959 Adding New Devices to the Port 
22960 \end_layout
22961
22962 \begin_layout Standard
22963 Adding support for a new 14
22964 \begin_inset ERT
22965 status open
22966
22967 \begin_layout Standard
22968
22969
22970 \backslash
22971 ,
22972 \end_layout
22973
22974 \end_inset
22975
22976 bit PIC MCU requires the following steps:
22977 \end_layout
22978
22979 \begin_layout Enumerate
22980 Create a new device description.
22981 \newline
22982 Each device is described in two files: pic16f*.h
22983  and pic16f*.c.
22984  These files primarily define SFRs, structs to access their bits, and symbolic
22985  configuration options.
22986  Both files can be generated from gputils' .inc files using the perl script
22987  
22988 \family typewriter
22989 support/scripts/inc2h.pl
22990 \family default
22991 .
22992  This file also contains further instructions on how to proceed.
22993 \end_layout
22994
22995 \begin_layout Enumerate
22996 Copy the .h file into SDCC's include path and either add the .c file to your
22997  project or copy it to 
22998 \family typewriter
22999 device/lib/pic/libdev
23000 \family default
23001 .
23002  Afterwards, rebuild and install the libraries.
23003 \end_layout
23004
23005 \begin_layout Enumerate
23006 Edit pic14devices.txt in SDCC's include path (
23007 \family typewriter
23008 device/include/pic/
23009 \family default
23010  in the source tree or 
23011 \family typewriter
23012 /usr/local/share/sdcc/include/pic
23013 \family default
23014  after installation).
23015 \newline
23016 You need to add a device specification here to make
23017  the memory layout (code banks, RAM, aliased memory regions, ...) known to
23018  the compiler.
23019  Probably you can copy and modify an existing entry.
23020  The file format is documented at the top of the file.
23021 \end_layout
23022
23023 \begin_layout Subsection
23024 Interrupt Code
23025 \end_layout
23026
23027 \begin_layout Standard
23028 For the interrupt function, use the keyword '__interrupt'
23029 \begin_inset LatexCommand \index{PIC14!interrupt}
23030
23031 \end_inset
23032
23033  with level number of 0 (PIC14 only has 1 interrupt so this number is only
23034  there to avoid a syntax error - it ought to be fixed).
23035  E.g.:
23036 \end_layout
23037
23038 \begin_layout Verse
23039
23040 \family typewriter
23041 void Intr(void) __interrupt 0
23042 \newline
23043 {
23044 \newline
23045 \InsetSpace ~
23046 \InsetSpace ~
23047 T0IF = 0; /* Clear timer interrupt */
23048 \newline
23049 }
23050 \end_layout
23051
23052 \begin_layout Subsection
23053 Linking and Assembling
23054 \end_layout
23055
23056 \begin_layout Standard
23057 For assembling you can use either GPUTILS'
23058 \begin_inset LatexCommand \index{gputils (pic tools)}
23059
23060 \end_inset
23061
23062  gpasm.exe or MPLAB's mpasmwin.exe.
23063  GPUTILS are available from 
23064 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23065
23066 \end_inset
23067
23068 .
23069  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23070  If you use MPLAB and an interrupt function then the linker script file
23071  vectors section will need to be enlarged to link with mplink.
23072 \newline
23073
23074 \newline
23075 Here is a 
23076 \family typewriter
23077 Makefile
23078 \family default
23079  using GPUTILS:
23080 \end_layout
23081
23082 \begin_layout Verse
23083
23084 \family typewriter
23085 .c.o:
23086 \newline
23087 \InsetSpace ~
23088 \InsetSpace ~
23089 \InsetSpace ~
23090 \InsetSpace ~
23091 \InsetSpace ~
23092 \InsetSpace ~
23093 \InsetSpace ~
23094 \InsetSpace ~
23095 sdcc -V -mpic14 -p16f877 -c $< 
23096 \newline
23097
23098 \newline
23099 $(PRJ).hex: $(OBJS) 
23100 \newline
23101 \InsetSpace ~
23102 \InsetSpace ~
23103 \InsetSpace ~
23104 \InsetSpace ~
23105 \InsetSpace ~
23106 \InsetSpace ~
23107 \InsetSpace ~
23108 \InsetSpace ~
23109 gplink -m -s $(PRJ).lkr
23110  -o $(PRJ).hex $(OBJS) libsdcc.lib
23111 \end_layout
23112
23113 \begin_layout Standard
23114 Here is a 
23115 \family typewriter
23116 Makefile
23117 \family default
23118  using MPLAB:
23119 \end_layout
23120
23121 \begin_layout Verse
23122
23123 \family typewriter
23124 .c.o: 
23125 \newline
23126 \InsetSpace ~
23127 \InsetSpace ~
23128 \InsetSpace ~
23129 \InsetSpace ~
23130 \InsetSpace ~
23131 \InsetSpace ~
23132 \InsetSpace ~
23133 \InsetSpace ~
23134 sdcc -S -V -mpic14 -p16f877 $< 
23135 \newline
23136 \InsetSpace ~
23137 \InsetSpace ~
23138 \InsetSpace ~
23139 \InsetSpace ~
23140 \InsetSpace ~
23141 \InsetSpace ~
23142 \InsetSpace ~
23143 \InsetSpace ~
23144 mpasmwin /q /o $*.asm
23145 \newline
23146
23147 \newline
23148 $(PRJ).hex: $(OBJS)
23149  
23150 \newline
23151 \InsetSpace ~
23152 \InsetSpace ~
23153 \InsetSpace ~
23154 \InsetSpace ~
23155 \InsetSpace ~
23156 \InsetSpace ~
23157 \InsetSpace ~
23158 \InsetSpace ~
23159 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23160 \end_layout
23161
23162 \begin_layout Standard
23163 Please note that indentations within a
23164 \family typewriter
23165  Makefile
23166 \family default
23167  have to be done with a tabulator character.
23168 \end_layout
23169
23170 \begin_layout Subsection
23171 Command-Line Options
23172 \end_layout
23173
23174 \begin_layout Standard
23175 Besides the switches common to all SDCC backends, the PIC14 port accepts
23176  the following options (for an updated list see sdcc -
23177 \begin_inset ERT
23178 status collapsed
23179
23180 \begin_layout Standard
23181
23182
23183 \backslash
23184 /
23185 \end_layout
23186
23187 \end_inset
23188
23189 -help):
23190 \end_layout
23191
23192 \begin_layout Description
23193 -
23194 \begin_inset ERT
23195 status collapsed
23196
23197 \begin_layout Standard
23198
23199
23200 \backslash
23201 /
23202 \end_layout
23203
23204 \end_inset
23205
23206 -debug-xtra
23207 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23208
23209 \end_inset
23210
23211  emit debug info in assembly output
23212 \end_layout
23213
23214 \begin_layout Description
23215 -
23216 \begin_inset ERT
23217 status collapsed
23218
23219 \begin_layout Standard
23220
23221
23222 \backslash
23223 /
23224 \end_layout
23225
23226 \end_inset
23227
23228 -no-pcode-opt
23229 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23230
23231 \end_inset
23232
23233  disable (slightly faulty) optimization on pCode
23234 \end_layout
23235
23236 \begin_layout Description
23237 -
23238 \begin_inset ERT
23239 status collapsed
23240
23241 \begin_layout Standard
23242
23243
23244 \backslash
23245 /
23246 \end_layout
23247
23248 \end_inset
23249
23250 -stack-loc
23251 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23252
23253 \end_inset
23254
23255  sets the lowest address of the argument passing stack (defaults to a suitably
23256  large shared databank to reduce BANKSEL overhead)
23257 \end_layout
23258
23259 \begin_layout Description
23260 -
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 -stack-size
23274 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23275
23276 \end_inset
23277
23278  sets the size if the argument passing stack (default: 16, minimum: 4)
23279 \end_layout
23280
23281 \begin_layout Subsection
23282 Environment Variables
23283 \end_layout
23284
23285 \begin_layout Standard
23286 The PIC14 port recognizes the following environment variables:
23287 \end_layout
23288
23289 \begin_layout Description
23290 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23291  register (the ones called r0xNNNN) in a section of its own.
23292  By default (if this variable is unset), sdcc tries to cluster registers
23293  in sections in order to reduce the BANKSEL overhead when accessing them.
23294 \end_layout
23295
23296 \begin_layout Subsection
23297 The Library
23298 \end_layout
23299
23300 \begin_layout Standard
23301 The PIC14 library currently only contains support routines required by the
23302  compiler to implement multiplication, division, and floating point support.
23303  No libc-like replacement is available at the moment, though many of the
23304  common sdcc library sources (in 
23305 \family typewriter
23306 device/lib
23307 \family default
23308 ) should also compile with the PIC14 port.
23309 \end_layout
23310
23311 \begin_layout Subsubsection
23312 error: missing definition for symbol 
23313 \begin_inset Quotes sld
23314 \end_inset
23315
23316 __gptrget1
23317 \begin_inset Quotes srd
23318 \end_inset
23319
23320
23321 \end_layout
23322
23323 \begin_layout Standard
23324 The PIC14 port uses library routines to provide more complex operations
23325  like multiplication, division/modulus and (generic) pointer dereferencing.
23326  In order to add these routines to your project, you must link with PIC14's
23327  
23328 \family typewriter
23329 libsdcc.lib
23330 \family default
23331 .
23332  For single source file projects this is done automatically, more complex
23333  projects must add 
23334 \family typewriter
23335 libsdcc.lib
23336 \family default
23337  to the linker's arguments.
23338  Make sure you also add an include path for the library (using the -I switch
23339  to the linker)!
23340 \end_layout
23341
23342 \begin_layout Subsubsection
23343 Processor mismatch in file 
23344 \begin_inset Quotes sld
23345 \end_inset
23346
23347 XXX
23348 \begin_inset Quotes srd
23349 \end_inset
23350
23351 .
23352 \end_layout
23353
23354 \begin_layout Standard
23355 This warning can usually be ignored due to the very good compatibility amongst
23356  14
23357 \begin_inset ERT
23358 status open
23359
23360 \begin_layout Standard
23361
23362
23363 \backslash
23364 ,
23365 \end_layout
23366
23367 \end_inset
23368
23369 bit PIC
23370 \begin_inset LatexCommand \index{PIC14}
23371
23372 \end_inset
23373
23374  devices.
23375 \end_layout
23376
23377 \begin_layout Standard
23378 You might also consider recompiling the library for your specific device
23379  by changing the ARCH=p16f877 (default target) entry in 
23380 \family typewriter
23381 device/lib/pic/Makefile.in
23382 \family default
23383  and 
23384 \family typewriter
23385 device/lib/pic/Makefile
23386 \family default
23387  to reflect your device.
23388  This might even improve performance for smaller devices as unneccesary
23389  BANKSELs might be removed.
23390 \end_layout
23391
23392 \begin_layout Subsection
23393 Known Bugs
23394 \end_layout
23395
23396 \begin_layout Subsubsection
23397 Function arguments
23398 \end_layout
23399
23400 \begin_layout Standard
23401 Functions with variable argument lists (like printf) are not yet supported.
23402  Similarly, taking the argument of the first argument passed into a function
23403  does not work: It is currently passed in WREG and has no address...
23404 \end_layout
23405
23406 \begin_layout Subsubsection
23407 Regression tests fail
23408 \end_layout
23409
23410 \begin_layout Standard
23411 Though the small subset of regression tests in src/regression passes, SDCC
23412  regression test suite does not, indicating that there are still major bugs
23413  in the port.
23414  However, many smaller projects have successfully used SDCC in the past...
23415 \end_layout
23416
23417 \begin_layout Standard
23418
23419 \size footnotesize
23420
23421 \newpage
23422
23423 \end_layout
23424
23425 \begin_layout Section
23426 The PIC16
23427 \begin_inset LatexCommand \index{PIC16}
23428
23429 \end_inset
23430
23431  port
23432 \end_layout
23433
23434 \begin_layout Standard
23435 The PIC16
23436 \begin_inset LatexCommand \index{PIC16}
23437
23438 \end_inset
23439
23440  port is the portion of SDCC that is responsible to produce code for the
23441  Microchip
23442 \begin_inset LatexCommand \index{Microchip}
23443
23444 \end_inset
23445
23446 (TM) microcontrollers with 16 bit core.
23447  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
23448  Currently supported devices are:
23449 \end_layout
23450
23451 \begin_layout Standard
23452 18F: 242, 248, 252, 258, 442, 448, 452, 458
23453 \end_layout
23454
23455 \begin_layout Standard
23456 18F: 1220, 1320
23457 \end_layout
23458
23459 \begin_layout Standard
23460 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 2525, 2550, 2620
23461 \end_layout
23462
23463 \begin_layout Standard
23464 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 4520, 4525, 4550, 4620
23465 \end_layout
23466
23467 \begin_layout Standard
23468 18F: 6520, 6620, 6680, 6720
23469 \end_layout
23470
23471 \begin_layout Standard
23472 18F: 8520, 8620, 8680, 8720
23473 \end_layout
23474
23475 \begin_layout Subsection
23476 Global Options
23477 \end_layout
23478
23479 \begin_layout Standard
23480 PIC16 port supports the standard command line arguments as supposed, with
23481  the exception of certain cases that will be mentioned in the following
23482  list:
23483 \end_layout
23484
23485 \begin_layout Description
23486 -
23487 \begin_inset ERT
23488 status collapsed
23489
23490 \begin_layout Standard
23491
23492
23493 \backslash
23494 /
23495 \end_layout
23496
23497 \end_inset
23498
23499 -callee-saves
23500 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23501
23502 \end_inset
23503
23504  See -
23505 \begin_inset ERT
23506 status collapsed
23507
23508 \begin_layout Standard
23509
23510
23511 \backslash
23512 /
23513 \end_layout
23514
23515 \end_inset
23516
23517 -all-callee-saves
23518 \end_layout
23519
23520 \begin_layout Description
23521 -
23522 \begin_inset ERT
23523 status collapsed
23524
23525 \begin_layout Standard
23526
23527
23528 \backslash
23529 /
23530 \end_layout
23531
23532 \end_inset
23533
23534 -fommit-frame-pointer
23535 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23536
23537 \end_inset
23538
23539  Frame pointer will be omitted when the function uses no local variables.
23540 \end_layout
23541
23542 \begin_layout Subsection
23543 Port Specific Options
23544 \begin_inset LatexCommand \index{Options PIC16}
23545
23546 \end_inset
23547
23548
23549 \end_layout
23550
23551 \begin_layout Standard
23552 The port specific options appear after the global options in the sdcc -
23553 \begin_inset ERT
23554 status collapsed
23555
23556 \begin_layout Standard
23557
23558
23559 \backslash
23560 /
23561 \end_layout
23562
23563 \end_inset
23564
23565 -help output.
23566 \end_layout
23567
23568 \begin_layout Subsubsection
23569 Code Generation Options
23570 \end_layout
23571
23572 \begin_layout Standard
23573 These options influence the generated assembler code.
23574 \end_layout
23575
23576 \begin_layout Description
23577 -
23578 \begin_inset ERT
23579 status collapsed
23580
23581 \begin_layout Standard
23582
23583
23584 \backslash
23585 /
23586 \end_layout
23587
23588 \end_inset
23589
23590 -pstack-model=[model] Used in conjuction with the command above.
23591  Defines the stack model to be used, valid stack models are:
23592 \end_layout
23593
23594 \begin_deeper
23595 \begin_layout List
23596 \labelwidthstring 00.00.0000
23597
23598 \emph on
23599 small
23600 \emph default
23601  Selects small stack model.
23602  8 bit stack and frame pointers.
23603  Supports 256 bytes stack size.
23604 \end_layout
23605
23606 \begin_layout List
23607 \labelwidthstring 00.00.0000
23608
23609 \emph on
23610 large
23611 \emph default
23612  Selects large stack model.
23613  16 bit stack and frame pointers.
23614  Supports 65536 bytes stack size.
23615 \end_layout
23616
23617 \end_deeper
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 -pno-banksel Do not generate BANKSEL assembler directives.
23633 \end_layout
23634
23635 \begin_layout Description
23636 -
23637 \begin_inset ERT
23638 status collapsed
23639
23640 \begin_layout Standard
23641
23642
23643 \backslash
23644 /
23645 \end_layout
23646
23647 \end_inset
23648
23649 -extended Enable extended instruction set/literal offset addressing mode.
23650  Use with care!
23651 \end_layout
23652
23653 \begin_layout Subsubsection
23654 Optimization Options
23655 \end_layout
23656
23657 \begin_layout Description
23658 -
23659 \begin_inset ERT
23660 status collapsed
23661
23662 \begin_layout Standard
23663
23664
23665 \backslash
23666 /
23667 \end_layout
23668
23669 \end_inset
23670
23671 -obanksel=n Set optimization level for inserting BANKSELs.
23672 \newline
23673
23674 \end_layout
23675
23676 \begin_deeper
23677 \begin_layout List
23678 \labelwidthstring 00.00.0000
23679 0 no optimization
23680 \end_layout
23681
23682 \begin_layout List
23683 \labelwidthstring 00.00.0000
23684 1 checks previous used register and if it is the same then does not emit
23685  BANKSEL, accounts only for labels.
23686 \end_layout
23687
23688 \begin_layout List
23689 \labelwidthstring 00.00.0000
23690 2 tries to check the location of (even different) symbols and removes BANKSELs
23691  if they are in the same bank.
23692  
23693 \newline
23694
23695 \emph on
23696 Important: There might be problems if the linker script has data sections
23697  across bank borders!
23698 \end_layout
23699
23700 \end_deeper
23701 \begin_layout Description
23702 -
23703 \begin_inset ERT
23704 status collapsed
23705
23706 \begin_layout Standard
23707
23708
23709 \backslash
23710 /
23711 \end_layout
23712
23713 \end_inset
23714
23715 -denable-peeps Force the usage of peepholes.
23716  Use with care.
23717 \end_layout
23718
23719 \begin_layout Description
23720 -
23721 \begin_inset ERT
23722 status collapsed
23723
23724 \begin_layout Standard
23725
23726
23727 \backslash
23728 /
23729 \end_layout
23730
23731 \end_inset
23732
23733 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23734 \end_layout
23735
23736 \begin_layout Description
23737 -
23738 \begin_inset ERT
23739 status collapsed
23740
23741 \begin_layout Standard
23742
23743
23744 \backslash
23745 /
23746 \end_layout
23747
23748 \end_inset
23749
23750 -optimize-cmp Try to optimize some compares.
23751 \end_layout
23752
23753 \begin_layout Description
23754 -
23755 \begin_inset ERT
23756 status collapsed
23757
23758 \begin_layout Standard
23759
23760
23761 \backslash
23762 /
23763 \end_layout
23764
23765 \end_inset
23766
23767 -optimize-df Analyze the dataflow of the generated code and improve it.
23768 \end_layout
23769
23770 \begin_layout Subsubsection
23771 Assembling Options
23772 \end_layout
23773
23774 \begin_layout Description
23775 -
23776 \begin_inset ERT
23777 status collapsed
23778
23779 \begin_layout Standard
23780
23781
23782 \backslash
23783 /
23784 \end_layout
23785
23786 \end_inset
23787
23788 -asm= Sets the full path and name of an external assembler to call.
23789 \end_layout
23790
23791 \begin_layout Description
23792 -
23793 \begin_inset ERT
23794 status collapsed
23795
23796 \begin_layout Standard
23797
23798
23799 \backslash
23800 /
23801 \end_layout
23802
23803 \end_inset
23804
23805 -mplab-comp MPLAB
23806 \begin_inset LatexCommand \index{PIC16!MPLAB}
23807
23808 \end_inset
23809
23810  compatibility option.
23811  Currently only suppresses special gpasm directives.
23812 \end_layout
23813
23814 \begin_layout Subsubsection
23815 Linking Options
23816 \end_layout
23817
23818 \begin_layout Description
23819 -
23820 \begin_inset ERT
23821 status collapsed
23822
23823 \begin_layout Standard
23824
23825
23826 \backslash
23827 /
23828 \end_layout
23829
23830 \end_inset
23831
23832 -link= Sets the full path and name of an external linker to call.
23833 \end_layout
23834
23835 \begin_layout Description
23836 -
23837 \begin_inset ERT
23838 status collapsed
23839
23840 \begin_layout Standard
23841
23842
23843 \backslash
23844 /
23845 \end_layout
23846
23847 \end_inset
23848
23849 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23850  unitialized data variables with [kword].
23851  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23852 \end_layout
23853
23854 \begin_layout Description
23855 -
23856 \begin_inset ERT
23857 status collapsed
23858
23859 \begin_layout Standard
23860
23861
23862 \backslash
23863 /
23864 \end_layout
23865
23866 \end_inset
23867
23868 -ivt-loc=n Place the interrupt vector table at address 
23869 \emph on
23870 n
23871 \emph default
23872 .
23873  Useful for bootloaders.
23874 \end_layout
23875
23876 \begin_layout Description
23877 -
23878 \begin_inset ERT
23879 status collapsed
23880
23881 \begin_layout Standard
23882
23883
23884 \backslash
23885 /
23886 \end_layout
23887
23888 \end_inset
23889
23890 -nodefaultlibs Do not link default libraries when linking.
23891 \end_layout
23892
23893 \begin_layout Description
23894 -
23895 \begin_inset ERT
23896 status collapsed
23897
23898 \begin_layout Standard
23899
23900
23901 \backslash
23902 /
23903 \end_layout
23904
23905 \end_inset
23906
23907 -use-crt= Use a custom run-time module instead of the defaults.
23908 \end_layout
23909
23910 \begin_layout Description
23911 -
23912 \begin_inset ERT
23913 status collapsed
23914
23915 \begin_layout Standard
23916
23917
23918 \backslash
23919 /
23920 \end_layout
23921
23922 \end_inset
23923
23924 -no-crt Don't link the default run-time modules
23925 \end_layout
23926
23927 \begin_layout Subsubsection
23928 Debugging Options
23929 \end_layout
23930
23931 \begin_layout Standard
23932 Debugging options enable extra debugging information in the output files.
23933 \end_layout
23934
23935 \begin_layout Description
23936 -
23937 \begin_inset ERT
23938 status collapsed
23939
23940 \begin_layout Standard
23941
23942
23943 \backslash
23944 /
23945 \end_layout
23946
23947 \end_inset
23948
23949 -debug-xtra Similar to -
23950 \begin_inset ERT
23951 status collapsed
23952
23953 \begin_layout Standard
23954
23955
23956 \backslash
23957 /
23958 \end_layout
23959
23960 \end_inset
23961
23962 -debug
23963 \begin_inset LatexCommand \index{-\/-debug}
23964
23965 \end_inset
23966
23967 , but dumps more information.
23968 \end_layout
23969
23970 \begin_layout Description
23971 -
23972 \begin_inset ERT
23973 status collapsed
23974
23975 \begin_layout Standard
23976
23977
23978 \backslash
23979 /
23980 \end_layout
23981
23982 \end_inset
23983
23984 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23985  information.
23986  <source> is the name of the file being compiled.
23987 \end_layout
23988
23989 \begin_layout Description
23990 -
23991 \begin_inset ERT
23992 status collapsed
23993
23994 \begin_layout Standard
23995
23996
23997 \backslash
23998 /
23999 \end_layout
24000
24001 \end_inset
24002
24003 -pcode-verbose Enable pcode debugging information in translation.
24004 \end_layout
24005
24006 \begin_layout Description
24007 -
24008 \begin_inset ERT
24009 status collapsed
24010
24011 \begin_layout Standard
24012
24013
24014 \backslash
24015 /
24016 \end_layout
24017
24018 \end_inset
24019
24020 -calltree Dump call tree in .calltree file.
24021 \end_layout
24022
24023 \begin_layout Description
24024 -
24025 \begin_inset ERT
24026 status collapsed
24027
24028 \begin_layout Standard
24029
24030
24031 \backslash
24032 /
24033 \end_layout
24034
24035 \end_inset
24036
24037 -gstack Trace push/pops for stack pointer overflow.
24038 \end_layout
24039
24040 \begin_layout Subsection
24041 Enviroment Variables
24042 \end_layout
24043
24044 \begin_layout Standard
24045 There is a number of enviromental variables that can be used when running
24046  SDCC to enable certain optimizations or force a specific program behaviour.
24047  these variables are primarily for debugging purposes so they can be enabled/dis
24048 abled at will.
24049 \end_layout
24050
24051 \begin_layout Standard
24052 Currently there is only two such variables available:
24053 \end_layout
24054
24055 \begin_layout Description
24056 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24057  bitfields is optimized by directly loading FSR0 with the address of the
24058  bitfield structure.
24059  Normally SDCC will cast the bitfield structure to a bitfield pointer and
24060  then load FSR0.
24061  This step saves data ram and code space for functions that make heavy use
24062  of bitfields.
24063  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24064  option).
24065  
24066 \end_layout
24067
24068 \begin_layout Description
24069 NO_REG_OPT Do not perform pCode registers optimization.
24070  This should be used for debugging purposes.
24071  If bugs in the pcode optimizer are found, users can benefit from temporarily
24072  disabling the optimizer until the bug is fixed.
24073 \end_layout
24074
24075 \begin_layout Subsection
24076 Preprocessor Macros
24077 \end_layout
24078
24079 \begin_layout Standard
24080 PIC16
24081 \begin_inset LatexCommand \index{PIC16}
24082
24083 \end_inset
24084
24085  port defines the following preprocessor macros while translating a source.
24086 \end_layout
24087
24088 \begin_layout Standard
24089 \align center
24090 \begin_inset Tabular
24091 <lyxtabular version="3" rows="6" columns="2">
24092 <features>
24093 <column alignment="center" valignment="top" leftline="true" width="0">
24094 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24095 <row topline="true" bottomline="true">
24096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24097 \begin_inset Text
24098
24099 \begin_layout Standard
24100 Macro
24101 \end_layout
24102
24103 \end_inset
24104 </cell>
24105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24106 \begin_inset Text
24107
24108 \begin_layout Standard
24109 Description
24110 \end_layout
24111
24112 \end_inset
24113 </cell>
24114 </row>
24115 <row topline="true">
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24117 \begin_inset Text
24118
24119 \begin_layout Standard
24120 SDCC_pic16
24121 \end_layout
24122
24123 \end_inset
24124 </cell>
24125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24126 \begin_inset Text
24127
24128 \begin_layout Standard
24129 Port identification
24130 \end_layout
24131
24132 \end_inset
24133 </cell>
24134 </row>
24135 <row topline="true">
24136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24137 \begin_inset Text
24138
24139 \begin_layout Standard
24140 _
24141 \begin_inset ERT
24142 status collapsed
24143
24144 \begin_layout Standard
24145
24146
24147 \backslash
24148 /
24149 \end_layout
24150
24151 \end_inset
24152
24153 _pic16
24154 \end_layout
24155
24156 \end_inset
24157 </cell>
24158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24159 \begin_inset Text
24160
24161 \begin_layout Standard
24162 Port identification (same as above)
24163 \end_layout
24164
24165 \end_inset
24166 </cell>
24167 </row>
24168 <row topline="true">
24169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24170 \begin_inset Text
24171
24172 \begin_layout Standard
24173 pic18fxxxx
24174 \end_layout
24175
24176 \end_inset
24177 </cell>
24178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24179 \begin_inset Text
24180
24181 \begin_layout Standard
24182 MCU Identification.
24183  
24184 \emph on
24185 xxxx
24186 \emph default
24187  is the microcontrol identification number, i.e.
24188  452, 6620, etc
24189 \end_layout
24190
24191 \end_inset
24192 </cell>
24193 </row>
24194 <row topline="true">
24195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24196 \begin_inset Text
24197
24198 \begin_layout Standard
24199 _
24200 \begin_inset ERT
24201 status collapsed
24202
24203 \begin_layout Standard
24204
24205
24206 \backslash
24207 /
24208 \end_layout
24209
24210 \end_inset
24211
24212 _18Fxxxx
24213 \end_layout
24214
24215 \end_inset
24216 </cell>
24217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24218 \begin_inset Text
24219
24220 \begin_layout Standard
24221 MCU Identification (same as above)
24222 \end_layout
24223
24224 \end_inset
24225 </cell>
24226 </row>
24227 <row topline="true" bottomline="true">
24228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24229 \begin_inset Text
24230
24231 \begin_layout Standard
24232 STACK_MODEL_nnn
24233 \end_layout
24234
24235 \end_inset
24236 </cell>
24237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24238 \begin_inset Text
24239
24240 \begin_layout Standard
24241 nnn = SMALL or LARGE respectively according to the stack model used
24242 \end_layout
24243
24244 \end_inset
24245 </cell>
24246 </row>
24247 </lyxtabular>
24248
24249 \end_inset
24250
24251
24252 \end_layout
24253
24254 \begin_layout Standard
24255 In addition the following macros are defined when calling assembler:
24256 \end_layout
24257
24258 \begin_layout Standard
24259 \align center
24260 \begin_inset Tabular
24261 <lyxtabular version="3" rows="4" columns="2">
24262 <features>
24263 <column alignment="center" valignment="top" leftline="true" width="0">
24264 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24265 <row topline="true" bottomline="true">
24266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24267 \begin_inset Text
24268
24269 \begin_layout Standard
24270 Macro
24271 \end_layout
24272
24273 \end_inset
24274 </cell>
24275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24276 \begin_inset Text
24277
24278 \begin_layout Standard
24279 Description
24280 \end_layout
24281
24282 \end_inset
24283 </cell>
24284 </row>
24285 <row topline="true">
24286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24287 \begin_inset Text
24288
24289 \begin_layout Standard
24290 __18Fxxxx
24291 \end_layout
24292
24293 \end_inset
24294 </cell>
24295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24296 \begin_inset Text
24297
24298 \begin_layout Standard
24299 MCU Identification.
24300  
24301 \emph on
24302 xxxx
24303 \emph default
24304  is the microcontrol identification number, i.e.
24305  452, 6620, etc
24306 \end_layout
24307
24308 \end_inset
24309 </cell>
24310 </row>
24311 <row topline="true">
24312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24313 \begin_inset Text
24314
24315 \begin_layout Standard
24316 SDCC_MODEL_nnn
24317 \end_layout
24318
24319 \end_inset
24320 </cell>
24321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24322 \begin_inset Text
24323
24324 \begin_layout Standard
24325 nnn = SMALL or LARGE respectively according to the memory model used for
24326  SDCC
24327 \end_layout
24328
24329 \end_inset
24330 </cell>
24331 </row>
24332 <row topline="true" bottomline="true">
24333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24334 \begin_inset Text
24335
24336 \begin_layout Standard
24337 STACK_MODEL_nnn
24338 \end_layout
24339
24340 \end_inset
24341 </cell>
24342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24343 \begin_inset Text
24344
24345 \begin_layout Standard
24346 nnn = SMALL or LARGE respectively according to the stack model used
24347 \end_layout
24348
24349 \end_inset
24350 </cell>
24351 </row>
24352 </lyxtabular>
24353
24354 \end_inset
24355
24356
24357 \end_layout
24358
24359 \begin_layout Subsection
24360 Directories
24361 \end_layout
24362
24363 \begin_layout Standard
24364 PIC16
24365 \begin_inset LatexCommand \index{PIC16}
24366
24367 \end_inset
24368
24369  port uses the following directories for searching header files and libraries.
24370 \end_layout
24371
24372 \begin_layout Standard
24373 \align center
24374 \begin_inset Tabular
24375 <lyxtabular version="3" rows="3" columns="4">
24376 <features>
24377 <column alignment="center" valignment="top" leftline="true" width="0">
24378 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24379 <column alignment="center" valignment="top" width="0">
24380 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24381 <row topline="true" bottomline="true">
24382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24383 \begin_inset Text
24384
24385 \begin_layout Standard
24386 Directory
24387 \end_layout
24388
24389 \end_inset
24390 </cell>
24391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24392 \begin_inset Text
24393
24394 \begin_layout Standard
24395 Description
24396 \end_layout
24397
24398 \end_inset
24399 </cell>
24400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24401 \begin_inset Text
24402
24403 \begin_layout Standard
24404 Target
24405 \end_layout
24406
24407 \end_inset
24408 </cell>
24409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24410 \begin_inset Text
24411
24412 \begin_layout Standard
24413 Command prefix
24414 \end_layout
24415
24416 \end_inset
24417 </cell>
24418 </row>
24419 <row topline="true">
24420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24421 \begin_inset Text
24422
24423 \begin_layout Standard
24424 PREFIX/sdcc/include/pic16
24425 \end_layout
24426
24427 \end_inset
24428 </cell>
24429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24430 \begin_inset Text
24431
24432 \begin_layout Standard
24433 PIC16 specific headers
24434 \end_layout
24435
24436 \end_inset
24437 </cell>
24438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24439 \begin_inset Text
24440
24441 \begin_layout Standard
24442 Compiler
24443 \end_layout
24444
24445 \end_inset
24446 </cell>
24447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24448 \begin_inset Text
24449
24450 \begin_layout Standard
24451 -I
24452 \end_layout
24453
24454 \end_inset
24455 </cell>
24456 </row>
24457 <row topline="true" bottomline="true">
24458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24459 \begin_inset Text
24460
24461 \begin_layout Standard
24462 PREFIX/sdcc/lib/pic16
24463 \end_layout
24464
24465 \end_inset
24466 </cell>
24467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24468 \begin_inset Text
24469
24470 \begin_layout Standard
24471 PIC16 specific libraries
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 Linker
24481 \end_layout
24482
24483 \end_inset
24484 </cell>
24485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24486 \begin_inset Text
24487
24488 \begin_layout Standard
24489 -L
24490 \end_layout
24491
24492 \end_inset
24493 </cell>
24494 </row>
24495 </lyxtabular>
24496
24497 \end_inset
24498
24499
24500 \end_layout
24501
24502 \begin_layout Subsection
24503 Pragmas
24504 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24505
24506 \end_inset
24507
24508
24509 \end_layout
24510
24511 \begin_layout Standard
24512 The PIC16
24513 \begin_inset LatexCommand \index{PIC16}
24514
24515 \end_inset
24516
24517  port currently supports the following pragmas:
24518 \end_layout
24519
24520 \begin_layout Description
24521 stack
24522 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24523
24524 \end_inset
24525
24526  This forces the code generator to initialize the stack & frame pointers
24527  at a specific address.
24528  This is an ad hoc solution for cases where no STACK directive is available
24529  in the linker script or gplink is not instructed to create a stack section.
24530 \newline
24531 The
24532  stack pragma should be used only once in a project.
24533  Multiple pragmas may result in indeterminate behaviour of the program.
24534 \begin_inset Foot
24535 status open
24536
24537 \begin_layout Standard
24538 The old format (ie.
24539  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24540  cross page boundaries (or even exceed the available data RAM) and crash
24541  the program.
24542  Make sure that stack does not cross page boundaries when using the SMALL
24543  stack model.
24544 \end_layout
24545
24546 \end_inset
24547
24548
24549 \newline
24550 The format is as follows:
24551 \newline
24552
24553 \end_layout
24554
24555 \begin_layout LyX-Code
24556 #pragma stack bottom_address [stack_size]
24557 \newline
24558
24559 \end_layout
24560
24561 \begin_layout Standard
24562
24563 \emph on
24564 bottom_address
24565 \emph default
24566  is the lower bound of the stack section.
24567  The stack pointer initially will point at address (bottom_address+stack_size-1).
24568 \end_layout
24569
24570 \begin_layout LyX-Code
24571 Example:
24572 \end_layout
24573
24574 \begin_layout LyX-Code
24575
24576 \end_layout
24577
24578 \begin_layout LyX-Code
24579 /* initializes stack of 100 bytes at RAM address 0x200 */
24580 \end_layout
24581
24582 \begin_layout LyX-Code
24583 #pragma stack 0x200 100
24584 \end_layout
24585
24586 \begin_layout Standard
24587 If the stack_size field is omitted then a stack is created with the default
24588  size of 64.
24589  This size might be enough for most programs, but its not enough for operations
24590  with deep function nesting or excessive stack usage.
24591 \end_layout
24592
24593 \begin_layout Description
24594 code
24595 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24596
24597 \end_inset
24598
24599  Force a function to a static FLASH address.
24600 \end_layout
24601
24602 \begin_layout LyX-Code
24603 Example:
24604 \end_layout
24605
24606 \begin_layout LyX-Code
24607
24608 \end_layout
24609
24610 \begin_layout LyX-Code
24611 /* place function test_func at 0x4000 */
24612 \end_layout
24613
24614 \begin_layout LyX-Code
24615 #pragma code test_func 0x4000
24616 \end_layout
24617
24618 \begin_layout LyX-Code
24619
24620 \end_layout
24621
24622 \begin_layout Description
24623 library instructs the linker to use a library module.
24624 \newline
24625 Usage:
24626 \end_layout
24627
24628 \begin_layout LyX-Code
24629 #pragma library module_name
24630 \end_layout
24631
24632 \begin_layout Standard
24633
24634 \emph on
24635 module_name
24636 \emph default
24637  can be any library or object file (including its path).
24638  Note that there are four reserved keywords which have special meaning.
24639  These are:
24640 \end_layout
24641
24642 \begin_layout Standard
24643 \align center
24644 \begin_inset Tabular
24645 <lyxtabular version="3" rows="6" columns="3">
24646 <features>
24647 <column alignment="center" valignment="top" leftline="true" width="0">
24648 <column alignment="block" valignment="top" leftline="true" width="20page%">
24649 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24650 <row topline="true" bottomline="true">
24651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24652 \begin_inset Text
24653
24654 \begin_layout Standard
24655 Keyword
24656 \end_layout
24657
24658 \end_inset
24659 </cell>
24660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24661 \begin_inset Text
24662
24663 \begin_layout Standard
24664 Description
24665 \end_layout
24666
24667 \end_inset
24668 </cell>
24669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24670 \begin_inset Text
24671
24672 \begin_layout Standard
24673 Module to link
24674 \end_layout
24675
24676 \end_inset
24677 </cell>
24678 </row>
24679 <row topline="true">
24680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24681 \begin_inset Text
24682
24683 \begin_layout Standard
24684
24685 \series bold
24686 ignore
24687 \end_layout
24688
24689 \end_inset
24690 </cell>
24691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24692 \begin_inset Text
24693
24694 \begin_layout Standard
24695 ignore all library pragmas
24696 \end_layout
24697
24698 \end_inset
24699 </cell>
24700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24701 \begin_inset Text
24702
24703 \begin_layout Standard
24704
24705 \emph on
24706 (none)
24707 \end_layout
24708
24709 \end_inset
24710 </cell>
24711 </row>
24712 <row topline="true">
24713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24714 \begin_inset Text
24715
24716 \begin_layout Standard
24717
24718 \series bold
24719 c
24720 \end_layout
24721
24722 \end_inset
24723 </cell>
24724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24725 \begin_inset Text
24726
24727 \begin_layout Standard
24728 link the C library
24729 \end_layout
24730
24731 \end_inset
24732 </cell>
24733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24734 \begin_inset Text
24735
24736 \begin_layout Standard
24737
24738 \emph on
24739 libc18f
24740 \emph default
24741 .lib
24742 \end_layout
24743
24744 \end_inset
24745 </cell>
24746 </row>
24747 <row topline="true">
24748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24749 \begin_inset Text
24750
24751 \begin_layout Standard
24752
24753 \series bold
24754 math
24755 \end_layout
24756
24757 \end_inset
24758 </cell>
24759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24760 \begin_inset Text
24761
24762 \begin_layout Standard
24763 link the Math libarary
24764 \end_layout
24765
24766 \end_inset
24767 </cell>
24768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24769 \begin_inset Text
24770
24771 \begin_layout Standard
24772
24773 \emph on
24774 libm18f
24775 \emph default
24776 .lib
24777 \end_layout
24778
24779 \end_inset
24780 </cell>
24781 </row>
24782 <row topline="true">
24783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24784 \begin_inset Text
24785
24786 \begin_layout Standard
24787
24788 \series bold
24789 io
24790 \end_layout
24791
24792 \end_inset
24793 </cell>
24794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24795 \begin_inset Text
24796
24797 \begin_layout Standard
24798 link the I/O library
24799 \end_layout
24800
24801 \end_inset
24802 </cell>
24803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24804 \begin_inset Text
24805
24806 \begin_layout Standard
24807
24808 \emph on
24809 libio18f*
24810 \emph default
24811 .lib
24812 \end_layout
24813
24814 \end_inset
24815 </cell>
24816 </row>
24817 <row topline="true" bottomline="true">
24818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24819 \begin_inset Text
24820
24821 \begin_layout Standard
24822
24823 \series bold
24824 debug
24825 \end_layout
24826
24827 \end_inset
24828 </cell>
24829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24830 \begin_inset Text
24831
24832 \begin_layout Standard
24833 link the debug library
24834 \end_layout
24835
24836 \end_inset
24837 </cell>
24838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24839 \begin_inset Text
24840
24841 \begin_layout Standard
24842
24843 \emph on
24844 libdebug
24845 \emph default
24846 .lib
24847 \end_layout
24848
24849 \end_inset
24850 </cell>
24851 </row>
24852 </lyxtabular>
24853
24854 \end_inset
24855
24856
24857 \newline
24858 * is the device number, i.e.
24859  452 for PIC18F452 MCU.
24860 \end_layout
24861
24862 \begin_layout Standard
24863 This feature allows for linking with specific libraries withoug having to
24864  explicit name them in the command line.
24865  Note that the 
24866 \noun on
24867 ignore
24868 \noun default
24869  keyword will reject all modules specified by the library pragma.
24870 \end_layout
24871
24872 \begin_layout Description
24873 udata The pragma udata instructs the compiler to emit code so that linker
24874  will place a variable at a specific memory bank.
24875 \end_layout
24876
24877 \begin_layout LyX-Code
24878 Example:
24879 \end_layout
24880
24881 \begin_layout LyX-Code
24882
24883 \end_layout
24884
24885 \begin_layout LyX-Code
24886 /* places variable foo at bank2 */
24887 \end_layout
24888
24889 \begin_layout LyX-Code
24890 #pragma udata bank2 foo
24891 \end_layout
24892
24893 \begin_layout LyX-Code
24894 char foo;
24895 \end_layout
24896
24897 \begin_layout Standard
24898 In order for this pragma to work extra SECTION directives should be added
24899  in the .lkr script.
24900  In the following example a sample .lkr file is shown:
24901 \end_layout
24902
24903 \begin_layout LyX-Code
24904
24905 \end_layout
24906
24907 \begin_layout LyX-Code
24908 // Sample linker script for the PIC18F452 processor
24909 \end_layout
24910
24911 \begin_layout LyX-Code
24912 LIBPATH .
24913 \end_layout
24914
24915 \begin_layout LyX-Code
24916 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24917 \end_layout
24918
24919 \begin_layout LyX-Code
24920 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24921 \end_layout
24922
24923 \begin_layout LyX-Code
24924 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24925 \end_layout
24926
24927 \begin_layout LyX-Code
24928 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24929 \end_layout
24930
24931 \begin_layout LyX-Code
24932 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24933 \end_layout
24934
24935 \begin_layout LyX-Code
24936 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24937 \end_layout
24938
24939 \begin_layout LyX-Code
24940 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24941 \end_layout
24942
24943 \begin_layout LyX-Code
24944
24945 \end_layout
24946
24947 \begin_layout LyX-Code
24948 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24949 \end_layout
24950
24951 \begin_layout LyX-Code
24952 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24953 \end_layout
24954
24955 \begin_layout LyX-Code
24956 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24957 \end_layout
24958
24959 \begin_layout LyX-Code
24960 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24961 \end_layout
24962
24963 \begin_layout LyX-Code
24964 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24965 \end_layout
24966
24967 \begin_layout LyX-Code
24968 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24969 \end_layout
24970
24971 \begin_layout LyX-Code
24972 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24973 \end_layout
24974
24975 \begin_layout LyX-Code
24976
24977 \end_layout
24978
24979 \begin_layout LyX-Code
24980 SECTION    NAME=CONFIG     ROM=config
24981 \end_layout
24982
24983 \begin_layout LyX-Code
24984
24985 \end_layout
24986
24987 \begin_layout LyX-Code
24988 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
24989 \end_layout
24990
24991 \begin_layout LyX-Code
24992 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
24993 \end_layout
24994
24995 \begin_layout LyX-Code
24996 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
24997 \end_layout
24998
24999 \begin_layout LyX-Code
25000 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25001 \end_layout
25002
25003 \begin_layout LyX-Code
25004 SECTION    NAME=bank4      RAM=gpr4
25005 \end_layout
25006
25007 \begin_layout LyX-Code
25008 SECTION    NAME=bank5      RAM=gpr5
25009 \end_layout
25010
25011 \begin_layout Standard
25012 The linker will recognise the section name set in the pragma statement and
25013  will position the variable at the memory bank set with the RAM field at
25014  the SECTION line in the linker script file.
25015 \end_layout
25016
25017 \begin_layout Subsection
25018 Header Files
25019 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25020
25021 \end_inset
25022
25023
25024 \end_layout
25025
25026 \begin_layout Standard
25027 There is one main header file
25028 \begin_inset LatexCommand \index{PIC16!Header files}
25029
25030 \end_inset
25031
25032  that can be included to the source files using the pic16
25033 \begin_inset LatexCommand \index{PIC16}
25034
25035 \end_inset
25036
25037  port.
25038  That file is the 
25039 \series bold
25040 pic18fregs.h
25041 \series default
25042 .
25043  This header file contains the definitions for the processor special registers,
25044  so it is necessary if the source accesses them.
25045  It can be included by adding the following line in the beginning of the
25046  file:
25047 \end_layout
25048
25049 \begin_layout LyX-Code
25050 #include <pic18fregs.h>
25051 \end_layout
25052
25053 \begin_layout Standard
25054 The specific microcontroller is selected within the pic18fregs.h automatically,
25055  so the same source can be used with a variety of devices.
25056 \end_layout
25057
25058 \begin_layout Subsection
25059 Libraries
25060 \end_layout
25061
25062 \begin_layout Standard
25063 The libraries
25064 \begin_inset LatexCommand \index{PIC16!Libraries}
25065
25066 \end_inset
25067
25068  that PIC16
25069 \begin_inset LatexCommand \index{PIC16}
25070
25071 \end_inset
25072
25073  port depends on are the microcontroller device libraries which contain
25074  the symbol definitions for the microcontroller special function registers.
25075  These libraries have the format pic18fxxxx.lib, where 
25076 \emph on
25077 xxxx
25078 \emph default
25079  is the microcontroller identification number.
25080  The specific library is selected automatically by the compiler at link
25081  stage according to the selected device.
25082 \end_layout
25083
25084 \begin_layout Standard
25085 Libraries are created with gplib which is part of the gputils package 
25086 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25087
25088 \end_inset
25089
25090 .
25091 \end_layout
25092
25093 \begin_layout Subsubsection*
25094 Building the libraries
25095 \end_layout
25096
25097 \begin_layout Standard
25098 Before using SDCC/pic16 there are some libraries that need to be compiled.
25099  This process is not done automatically by SDCC since not all users use
25100  SDCC for pic16 projects.
25101  So each user should compile the libraries separately.
25102 \end_layout
25103
25104 \begin_layout Standard
25105 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25106 \end_layout
25107
25108 \begin_layout LyX-Code
25109 cd device/lib/pic16
25110 \end_layout
25111
25112 \begin_layout LyX-Code
25113 ./configure
25114 \end_layout
25115
25116 \begin_layout LyX-Code
25117 make
25118 \end_layout
25119
25120 \begin_layout LyX-Code
25121 cd ..
25122 \end_layout
25123
25124 \begin_layout LyX-Code
25125 make model-pic16
25126 \end_layout
25127
25128 \begin_layout LyX-Code
25129 su -c 'make install'     # install the libraries, you need the root password
25130 \end_layout
25131
25132 \begin_layout Standard
25133 If you need to install the headers too, do:
25134 \end_layout
25135
25136 \begin_layout LyX-Code
25137 cd device/include
25138 \end_layout
25139
25140 \begin_layout LyX-Code
25141 su -c 'make install'     # install the headers, you need the root password
25142 \end_layout
25143
25144 \begin_layout Standard
25145 There exist a special target to build the I/O libraries.
25146  This target is not automatically build because it will build the I/O library
25147  for 
25148 \emph on
25149 every
25150 \emph default
25151  supported device.
25152  This way building will take quite a lot of time.
25153  Users are advised to edit the 
25154 \series bold
25155 device/lib/pic16/pics.build
25156 \series default
25157  file and then execute:
25158 \end_layout
25159
25160 \begin_layout LyX-Code
25161 make lib-io
25162 \end_layout
25163
25164 \begin_layout Subsection
25165 Adding New Devices to the Port
25166 \end_layout
25167
25168 \begin_layout Standard
25169 Adding support for a new 16
25170 \begin_inset ERT
25171 status open
25172
25173 \begin_layout Standard
25174
25175
25176 \backslash
25177 ,
25178 \end_layout
25179
25180 \end_inset
25181
25182 bit PIC MCU requires the following steps:
25183 \end_layout
25184
25185 \begin_layout Enumerate
25186 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25187 \newline
25188
25189 \family typewriter
25190 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25191 inc
25192 \end_layout
25193
25194 \begin_layout Enumerate
25195
25196 \family typewriter
25197 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25198 \end_layout
25199
25200 \begin_layout Enumerate
25201
25202 \family typewriter
25203 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25204 \end_layout
25205
25206 \begin_layout Enumerate
25207 Add DEVICE to 
25208 \family typewriter
25209 /path/to/sdcc/device/lib/pics.all
25210 \family default
25211  (and 
25212 \family typewriter
25213 .build
25214 \family default
25215 ).
25216 \newline
25217 Note: No 18f prefix here!
25218 \end_layout
25219
25220 \begin_layout Enumerate
25221 Adjust 
25222 \family typewriter
25223 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25224 \family default
25225
25226 \newline
25227 Add your DEVICE if it does not compile in 
25228 \family typewriter
25229 adc
25230 \family default
25231
25232 \family typewriter
25233 i2c
25234 \family default
25235 , or 
25236 \family typewriter
25237 usart
25238 \family default
25239 .
25240 \end_layout
25241
25242 \begin_layout Enumerate
25243 Edit 
25244 \family typewriter
25245 /path/to/sdcc/device/include/pic16/pic18fregs.h
25246 \family default
25247 .
25248  The file format is self-explanatory, just add
25249 \newline
25250
25251 \family typewriter
25252 #elif defined(picDEVICE)
25253 \newline
25254 # include <picDEVICE.h>
25255 \family default
25256
25257 \newline
25258 at the right place (keep it sorted).
25259 \end_layout
25260
25261 \begin_layout Enumerate
25262 Edit 
25263 \family typewriter
25264 /path/to/sdcc/src/pic16/devices.inc
25265 \family default
25266 .
25267  Copy and modify an existing entry and insert it at the correct place (keep
25268  the file sorted).
25269  The file is hardly documented, look at the entries for the 18f2221...
25270 \end_layout
25271
25272 \begin_layout Enumerate
25273 Recompile SDCC, including the pic16 libraries.
25274 \end_layout
25275
25276 \begin_layout Subsection
25277 Memory Models
25278 \end_layout
25279
25280 \begin_layout Standard
25281 The following memory models are supported by the PIC16 port:
25282 \end_layout
25283
25284 \begin_layout Itemize
25285 small model
25286 \end_layout
25287
25288 \begin_layout Itemize
25289 large model
25290 \end_layout
25291
25292 \begin_layout Standard
25293 Memory model affects the default size of pointers within the source.
25294  The sizes are shown in the next table:
25295 \end_layout
25296
25297 \begin_layout Standard
25298 \align center
25299 \begin_inset Tabular
25300 <lyxtabular version="3" rows="3" columns="3">
25301 <features>
25302 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25303 <column alignment="center" valignment="top" leftline="true" width="0">
25304 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25305 <row topline="true" bottomline="true">
25306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25307 \begin_inset Text
25308
25309 \begin_layout Standard
25310 Pointer sizes according to memory model
25311 \end_layout
25312
25313 \end_inset
25314 </cell>
25315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25316 \begin_inset Text
25317
25318 \begin_layout Standard
25319 small model
25320 \end_layout
25321
25322 \end_inset
25323 </cell>
25324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25325 \begin_inset Text
25326
25327 \begin_layout Standard
25328 large model
25329 \end_layout
25330
25331 \end_inset
25332 </cell>
25333 </row>
25334 <row topline="true" bottomline="true">
25335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25336 \begin_inset Text
25337
25338 \begin_layout Standard
25339 code pointers
25340 \end_layout
25341
25342 \end_inset
25343 </cell>
25344 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25345 \begin_inset Text
25346
25347 \begin_layout Standard
25348 16-bits
25349 \end_layout
25350
25351 \end_inset
25352 </cell>
25353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25354 \begin_inset Text
25355
25356 \begin_layout Standard
25357 24-bits
25358 \end_layout
25359
25360 \end_inset
25361 </cell>
25362 </row>
25363 <row topline="true" bottomline="true">
25364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25365 \begin_inset Text
25366
25367 \begin_layout Standard
25368 data pointers
25369 \end_layout
25370
25371 \end_inset
25372 </cell>
25373 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25374 \begin_inset Text
25375
25376 \begin_layout Standard
25377 16-bits
25378 \end_layout
25379
25380 \end_inset
25381 </cell>
25382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25383 \begin_inset Text
25384
25385 \begin_layout Standard
25386 16-bits
25387 \end_layout
25388
25389 \end_inset
25390 </cell>
25391 </row>
25392 </lyxtabular>
25393
25394 \end_inset
25395
25396
25397 \end_layout
25398
25399 \begin_layout Standard
25400 It is advisable that all sources within a project are compiled with the
25401  same memory model.
25402  If one wants to override the default memory model, this can be done by
25403  declaring a pointer as 
25404 \series bold
25405 far
25406 \series default
25407  or 
25408 \series bold
25409 near
25410 \series default
25411 .
25412  Far selects large memory model's pointers, while near selects small memory
25413  model's pointers.
25414 \end_layout
25415
25416 \begin_layout Standard
25417 The standard device libraries (see 
25418 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25419
25420 \end_inset
25421
25422 ) contain no reference to pointers, so they can be used with both memory
25423  models.
25424 \end_layout
25425
25426 \begin_layout Subsection
25427 Stack
25428 \end_layout
25429
25430 \begin_layout Standard
25431 The stack
25432 \begin_inset LatexCommand \index{PIC16!stack}
25433
25434 \end_inset
25435
25436  implementation for the PIC16 port uses two indirect registers, FSR1 and
25437  FSR2.
25438 \end_layout
25439
25440 \begin_layout Description
25441 FSR1 is assigned as stack pointer
25442 \end_layout
25443
25444 \begin_layout Description
25445 FSR2 is assigned as frame pointer
25446 \end_layout
25447
25448 \begin_layout Standard
25449 The following stack models are supported by the PIC16 port
25450 \end_layout
25451
25452 \begin_layout Itemize
25453
25454 \noun on
25455 small
25456 \noun default
25457  model
25458 \end_layout
25459
25460 \begin_layout Itemize
25461
25462 \noun on
25463 large
25464 \noun default
25465  model
25466 \end_layout
25467
25468 \begin_layout Standard
25469
25470 \noun on
25471 Small
25472 \noun default
25473  model means that only the FSRxL byte is used to access stack and frame,
25474  while 
25475 \emph on
25476 \noun on
25477 large
25478 \emph default
25479 \noun default
25480  uses both FSRxL and FSRxH registers.
25481  The following table shows the stack/frame pointers sizes according to stack
25482  model and the maximum space they can address:
25483 \end_layout
25484
25485 \begin_layout Standard
25486 \align center
25487 \begin_inset Tabular
25488 <lyxtabular version="3" rows="3" columns="3">
25489 <features>
25490 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25491 <column alignment="center" valignment="top" leftline="true" width="0">
25492 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25493 <row topline="true" bottomline="true">
25494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25495 \begin_inset Text
25496
25497 \begin_layout Standard
25498 Stack & Frame pointer sizes according to stack model
25499 \end_layout
25500
25501 \end_inset
25502 </cell>
25503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25504 \begin_inset Text
25505
25506 \begin_layout Standard
25507 small
25508 \end_layout
25509
25510 \end_inset
25511 </cell>
25512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25513 \begin_inset Text
25514
25515 \begin_layout Standard
25516 large
25517 \end_layout
25518
25519 \end_inset
25520 </cell>
25521 </row>
25522 <row topline="true">
25523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25524 \begin_inset Text
25525
25526 \begin_layout Standard
25527 Stack pointer FSR1
25528 \end_layout
25529
25530 \end_inset
25531 </cell>
25532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25533 \begin_inset Text
25534
25535 \begin_layout Standard
25536 8-bits
25537 \end_layout
25538
25539 \end_inset
25540 </cell>
25541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25542 \begin_inset Text
25543
25544 \begin_layout Standard
25545 16-bits
25546 \end_layout
25547
25548 \end_inset
25549 </cell>
25550 </row>
25551 <row topline="true" bottomline="true">
25552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25553 \begin_inset Text
25554
25555 \begin_layout Standard
25556 Frame pointer FSR2
25557 \end_layout
25558
25559 \end_inset
25560 </cell>
25561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25562 \begin_inset Text
25563
25564 \begin_layout Standard
25565 8-bits
25566 \end_layout
25567
25568 \end_inset
25569 </cell>
25570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25571 \begin_inset Text
25572
25573 \begin_layout Standard
25574 16-bits
25575 \end_layout
25576
25577 \end_inset
25578 </cell>
25579 </row>
25580 </lyxtabular>
25581
25582 \end_inset
25583
25584
25585 \end_layout
25586
25587 \begin_layout Standard
25588
25589 \noun on
25590 Large 
25591 \noun default
25592 stack model is currently not working properly throughout the code generator.
25593  So its use is not advised.
25594  Also there are some other points that need special care:
25595 \newline
25596
25597 \end_layout
25598
25599 \begin_layout Enumerate
25600 Do not create stack sections with size more than one physical bank (that
25601  is 256 bytes)
25602 \end_layout
25603
25604 \begin_layout Enumerate
25605 Stack sections should no cross physical bank limits (i.e.
25606  #pragma stack 0x50 0x100)
25607 \end_layout
25608
25609 \begin_layout Standard
25610 These limitations are caused by the fact that only FSRxL is modified when
25611  using SMALL stack model, so no more than 256 bytes of stack can be used.
25612  This problem will disappear after LARGE model is fully implemented.
25613 \end_layout
25614
25615 \begin_layout Subsection
25616 Functions
25617 \end_layout
25618
25619 \begin_layout Standard
25620 In addition to the standard SDCC function keywords, PIC16
25621 \begin_inset LatexCommand \index{PIC16}
25622
25623 \end_inset
25624
25625  port makes available two more:
25626 \end_layout
25627
25628 \begin_layout Description
25629 wparam
25630 \begin_inset LatexCommand \index{PIC16!wparam}
25631
25632 \end_inset
25633
25634  Use the WREG to pass one byte of the first function argument.
25635  This improves speed but you may not use this for functions with arguments
25636  that are called via function pointers, otherwise the first byte of the
25637  first parameter will get lost.
25638  Usage:
25639 \end_layout
25640
25641 \begin_layout LyX-Code
25642 void func_wparam(int a) wparam
25643 \end_layout
25644
25645 \begin_layout LyX-Code
25646 {
25647 \end_layout
25648
25649 \begin_layout LyX-Code
25650     /* WREG hold the lower part of a */
25651 \end_layout
25652
25653 \begin_layout LyX-Code
25654     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25655  */
25656 \end_layout
25657
25658 \begin_layout LyX-Code
25659 ...
25660 \end_layout
25661
25662 \begin_layout LyX-Code
25663 }
25664 \end_layout
25665
25666 \begin_layout Description
25667 shadowregs
25668 \begin_inset LatexCommand \index{PIC16!shadowregs}
25669
25670 \end_inset
25671
25672  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25673  hardware shadow registers which hold the values of WREG, STATUS and BSR
25674  registers.
25675  This can be done by adding the keyword 
25676 \emph on
25677 shadowregs
25678 \emph default
25679  before the 
25680 \emph on
25681 interrupt
25682 \emph default
25683  keyword in the function's header.
25684 \end_layout
25685
25686 \begin_layout LyX-Code
25687 void isr_shadow(void) shadowregs interrupt 1
25688 \end_layout
25689
25690 \begin_layout LyX-Code
25691 {
25692 \end_layout
25693
25694 \begin_layout LyX-Code
25695 ...
25696 \end_layout
25697
25698 \begin_layout LyX-Code
25699 }
25700 \end_layout
25701
25702 \begin_layout Standard
25703
25704 \emph on
25705 shadowregs
25706 \emph default
25707  instructs the code generator not to store/restore WREG, STATUS, BSR when
25708  entering/exiting the ISR.
25709 \end_layout
25710
25711 \begin_layout Subsection
25712 Function return values
25713 \end_layout
25714
25715 \begin_layout Standard
25716 Return values from functions are placed to the appropriate registers following
25717  a modified Microchip policy optimized for SDCC.
25718  The following table shows these registers:
25719 \end_layout
25720
25721 \begin_layout Standard
25722 \align center
25723 \begin_inset Tabular
25724 <lyxtabular version="3" rows="6" columns="2">
25725 <features>
25726 <column alignment="center" valignment="top" leftline="true" width="0">
25727 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25728 <row topline="true" bottomline="true">
25729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25730 \begin_inset Text
25731
25732 \begin_layout Standard
25733 size
25734 \end_layout
25735
25736 \end_inset
25737 </cell>
25738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25739 \begin_inset Text
25740
25741 \begin_layout Standard
25742 destination register
25743 \end_layout
25744
25745 \end_inset
25746 </cell>
25747 </row>
25748 <row topline="true">
25749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25750 \begin_inset Text
25751
25752 \begin_layout Standard
25753 8 bits
25754 \end_layout
25755
25756 \end_inset
25757 </cell>
25758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25759 \begin_inset Text
25760
25761 \begin_layout Standard
25762 WREG
25763 \end_layout
25764
25765 \end_inset
25766 </cell>
25767 </row>
25768 <row topline="true">
25769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25770 \begin_inset Text
25771
25772 \begin_layout Standard
25773 16 bits
25774 \end_layout
25775
25776 \end_inset
25777 </cell>
25778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25779 \begin_inset Text
25780
25781 \begin_layout Standard
25782 PRODL:WREG
25783 \end_layout
25784
25785 \end_inset
25786 </cell>
25787 </row>
25788 <row topline="true">
25789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25790 \begin_inset Text
25791
25792 \begin_layout Standard
25793 24 bits
25794 \end_layout
25795
25796 \end_inset
25797 </cell>
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25799 \begin_inset Text
25800
25801 \begin_layout Standard
25802 PRODH:PRODL:WREG
25803 \end_layout
25804
25805 \end_inset
25806 </cell>
25807 </row>
25808 <row topline="true">
25809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25810 \begin_inset Text
25811
25812 \begin_layout Standard
25813 32 bits
25814 \end_layout
25815
25816 \end_inset
25817 </cell>
25818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25819 \begin_inset Text
25820
25821 \begin_layout Standard
25822 FSR0L:PRODH:PRODL:WREG
25823 \end_layout
25824
25825 \end_inset
25826 </cell>
25827 </row>
25828 <row topline="true" bottomline="true">
25829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25830 \begin_inset Text
25831
25832 \begin_layout Standard
25833 >32 bits
25834 \end_layout
25835
25836 \end_inset
25837 </cell>
25838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25839 \begin_inset Text
25840
25841 \begin_layout Standard
25842 on stack, FSR0 points to the beginning
25843 \end_layout
25844
25845 \end_inset
25846 </cell>
25847 </row>
25848 </lyxtabular>
25849
25850 \end_inset
25851
25852
25853 \end_layout
25854
25855 \begin_layout Subsection
25856 Interrupts
25857 \end_layout
25858
25859 \begin_layout Standard
25860 An interrupt
25861 \begin_inset LatexCommand \index{PIC16!interrupt}
25862
25863 \end_inset
25864
25865  service routine (ISR) is declared using the 
25866 \emph on
25867 interrupt
25868 \emph default
25869  keyword.
25870 \end_layout
25871
25872 \begin_layout LyX-Code
25873 void isr(void) interrupt 
25874 \emph on
25875 n
25876 \end_layout
25877
25878 \begin_layout LyX-Code
25879 {
25880 \end_layout
25881
25882 \begin_layout LyX-Code
25883 ...
25884 \end_layout
25885
25886 \begin_layout LyX-Code
25887 }
25888 \end_layout
25889
25890 \begin_layout Standard
25891
25892 \emph on
25893 n
25894 \emph default
25895  is the interrupt number, which for PIC18F devices can be:
25896 \end_layout
25897
25898 \begin_layout Standard
25899 \align center
25900 \begin_inset Tabular
25901 <lyxtabular version="3" rows="4" columns="3">
25902 <features>
25903 <column alignment="center" valignment="top" leftline="true" width="0">
25904 <column alignment="center" valignment="top" leftline="true" width="0">
25905 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25906 <row topline="true" bottomline="true">
25907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25908 \begin_inset Text
25909
25910 \begin_layout Standard
25911
25912 \emph on
25913 n
25914 \end_layout
25915
25916 \end_inset
25917 </cell>
25918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25919 \begin_inset Text
25920
25921 \begin_layout Standard
25922 Interrupt Vector
25923 \end_layout
25924
25925 \end_inset
25926 </cell>
25927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25928 \begin_inset Text
25929
25930 \begin_layout Standard
25931 Interrupt Vector Address
25932 \end_layout
25933
25934 \end_inset
25935 </cell>
25936 </row>
25937 <row topline="true">
25938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25939 \begin_inset Text
25940
25941 \begin_layout Standard
25942 0
25943 \end_layout
25944
25945 \end_inset
25946 </cell>
25947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25948 \begin_inset Text
25949
25950 \begin_layout Standard
25951 RESET vector
25952 \end_layout
25953
25954 \end_inset
25955 </cell>
25956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25957 \begin_inset Text
25958
25959 \begin_layout Standard
25960 0x000000
25961 \end_layout
25962
25963 \end_inset
25964 </cell>
25965 </row>
25966 <row topline="true">
25967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25968 \begin_inset Text
25969
25970 \begin_layout Standard
25971
25972 \family roman
25973 \series medium
25974 \shape up
25975 \size normal
25976 \emph off
25977 \bar no
25978 \noun off
25979 \color none
25980 1
25981 \end_layout
25982
25983 \end_inset
25984 </cell>
25985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25986 \begin_inset Text
25987
25988 \begin_layout Standard
25989
25990 \family roman
25991 \series medium
25992 \shape up
25993 \size normal
25994 \emph off
25995 \bar no
25996 \noun off
25997 \color none
25998 HIGH priority interrupts
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 0x000008
26008 \end_layout
26009
26010 \end_inset
26011 </cell>
26012 </row>
26013 <row topline="true" bottomline="true">
26014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26015 \begin_inset Text
26016
26017 \begin_layout Standard
26018 2
26019 \end_layout
26020
26021 \end_inset
26022 </cell>
26023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26024 \begin_inset Text
26025
26026 \begin_layout Standard
26027 LOW priority interrupts
26028 \end_layout
26029
26030 \end_inset
26031 </cell>
26032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26033 \begin_inset Text
26034
26035 \begin_layout Standard
26036 0x000018
26037 \end_layout
26038
26039 \end_inset
26040 </cell>
26041 </row>
26042 </lyxtabular>
26043
26044 \end_inset
26045
26046
26047 \end_layout
26048
26049 \begin_layout Standard
26050 When generating assembly code for ISR the code generator places a 
26051 \noun on
26052 goto 
26053 \noun default
26054 instruction at the 
26055 \emph on
26056 Interrupt Vector Address
26057 \emph default
26058  which points at the genetated ISR.
26059  This single GOTO instruction is part of an automatically generated 
26060 \emph on
26061 interrupt entry point
26062 \emph default
26063  function.
26064  The actuall ISR code is placed as normally would in the code space.
26065  Upon interrupt request, the GOTO instruction is executed which jumps to
26066  the ISR code.
26067  When declaring interrupt functions as _naked this GOTO instruction is 
26068 \series bold
26069 not
26070 \series default
26071  generated.
26072  The whole interrupt functions is therefore placed at the Interrupt Vector
26073  Address of the specific interrupt.
26074  This is not a problem for the LOW priority interrupts, but it is a problem
26075  for the RESET and the HIGH priority interrupts because code may be written
26076  at the next interrupt´s vector address and cause undeterminate program
26077  behaviour if that interrupt is raised.
26078 \begin_inset Foot
26079 status open
26080
26081 \begin_layout Standard
26082 This is not a problem when
26083 \end_layout
26084
26085 \begin_layout Enumerate
26086 this is a HIGH interrupt ISR and LOW interrupts are 
26087 \emph on
26088 disabled
26089 \emph default
26090  or not used.
26091 \end_layout
26092
26093 \begin_layout Enumerate
26094 when the ISR is small enough not to reach the next interrupt´s vector address.
26095 \end_layout
26096
26097 \end_inset
26098
26099
26100 \end_layout
26101
26102 \begin_layout Standard
26103
26104 \emph on
26105 n
26106 \emph default
26107  is possible to be omitted.
26108  This way a function is generated similar to an ISR, but it is not assigned
26109  to any interrupt.
26110 \end_layout
26111
26112 \begin_layout Standard
26113 When entering an interrupt, currently the PIC16
26114 \begin_inset LatexCommand \index{PIC16}
26115
26116 \end_inset
26117
26118  port automatically saves the following registers:
26119 \end_layout
26120
26121 \begin_layout Itemize
26122 WREG
26123 \end_layout
26124
26125 \begin_layout Itemize
26126 STATUS
26127 \end_layout
26128
26129 \begin_layout Itemize
26130 BSR
26131 \end_layout
26132
26133 \begin_layout Itemize
26134 PROD (PRODL and PRODH)
26135 \end_layout
26136
26137 \begin_layout Itemize
26138 FSR0 (FSR0L and FSR0H)
26139 \end_layout
26140
26141 \begin_layout Standard
26142 These registers are restored upon return from the interrupt routine.
26143 \begin_inset Foot
26144 status open
26145
26146 \begin_layout Standard
26147 NOTE that when the _naked attribute is specified for an interrupt routine,
26148  then NO registers are stored or restored.
26149 \end_layout
26150
26151 \end_inset
26152
26153
26154 \end_layout
26155
26156 \begin_layout Subsection
26157 Generic Pointers
26158 \end_layout
26159
26160 \begin_layout Standard
26161 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26162  There are 3 types of generic pointers currently implemented data, code
26163  and eeprom pointers.
26164  They are differentiated by the value of the 7th and 6th bits of the upper
26165  byte:
26166 \end_layout
26167
26168 \begin_layout Standard
26169 \align center
26170 \begin_inset Tabular
26171 <lyxtabular version="3" rows="5" columns="5">
26172 <features>
26173 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26174 <column alignment="center" valignment="top" width="0">
26175 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26176 <column alignment="center" valignment="top" width="0">
26177 <column alignment="left" valignment="top" rightline="true" width="0">
26178 <row topline="true" bottomline="true">
26179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26180 \begin_inset Text
26181
26182 \begin_layout Standard
26183 pointer type
26184 \end_layout
26185
26186 \end_inset
26187 </cell>
26188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26189 \begin_inset Text
26190
26191 \begin_layout Standard
26192 7th bit
26193 \end_layout
26194
26195 \end_inset
26196 </cell>
26197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26198 \begin_inset Text
26199
26200 \begin_layout Standard
26201 6th bit
26202 \end_layout
26203
26204 \end_inset
26205 </cell>
26206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26207 \begin_inset Text
26208
26209 \begin_layout Standard
26210 rest of the pointer
26211 \end_layout
26212
26213 \end_inset
26214 </cell>
26215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26216 \begin_inset Text
26217
26218 \begin_layout Standard
26219 description
26220 \end_layout
26221
26222 \end_inset
26223 </cell>
26224 </row>
26225 <row topline="true" bottomline="true">
26226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26227 \begin_inset Text
26228
26229 \begin_layout Standard
26230 data 
26231 \end_layout
26232
26233 \end_inset
26234 </cell>
26235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26236 \begin_inset Text
26237
26238 \begin_layout Standard
26239 1
26240 \end_layout
26241
26242 \end_inset
26243 </cell>
26244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26245 \begin_inset Text
26246
26247 \begin_layout Standard
26248 0
26249 \end_layout
26250
26251 \end_inset
26252 </cell>
26253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26254 \begin_inset Text
26255
26256 \begin_layout Standard
26257
26258 \family typewriter
26259 \shape slanted
26260 \emph on
26261 uuuuuu uuuuxxxx xxxxxxxx
26262 \end_layout
26263
26264 \end_inset
26265 </cell>
26266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26267 \begin_inset Text
26268
26269 \begin_layout Standard
26270 a 12-bit data pointer in data RAM memory
26271 \end_layout
26272
26273 \end_inset
26274 </cell>
26275 </row>
26276 <row bottomline="true">
26277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26278 \begin_inset Text
26279
26280 \begin_layout Standard
26281 code
26282 \end_layout
26283
26284 \end_inset
26285 </cell>
26286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26287 \begin_inset Text
26288
26289 \begin_layout Standard
26290 0
26291 \end_layout
26292
26293 \end_inset
26294 </cell>
26295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26296 \begin_inset Text
26297
26298 \begin_layout Standard
26299 0
26300 \end_layout
26301
26302 \end_inset
26303 </cell>
26304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26305 \begin_inset Text
26306
26307 \begin_layout Standard
26308
26309 \family typewriter
26310 \shape slanted
26311 \emph on
26312 uxxxxx xxxxxxxx xxxxxxxx
26313 \end_layout
26314
26315 \end_inset
26316 </cell>
26317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26318 \begin_inset Text
26319
26320 \begin_layout Standard
26321 a 21-bit code pointer in FLASH memory
26322 \end_layout
26323
26324 \end_inset
26325 </cell>
26326 </row>
26327 <row bottomline="true">
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26329 \begin_inset Text
26330
26331 \begin_layout Standard
26332 eeprom
26333 \end_layout
26334
26335 \end_inset
26336 </cell>
26337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26338 \begin_inset Text
26339
26340 \begin_layout Standard
26341 0
26342 \end_layout
26343
26344 \end_inset
26345 </cell>
26346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26347 \begin_inset Text
26348
26349 \begin_layout Standard
26350 1
26351 \end_layout
26352
26353 \end_inset
26354 </cell>
26355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26356 \begin_inset Text
26357
26358 \begin_layout Standard
26359
26360 \family typewriter
26361 \shape slanted
26362 \emph on
26363 uuuuuu uuuuuuxx xxxxxxxx
26364 \end_layout
26365
26366 \end_inset
26367 </cell>
26368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26369 \begin_inset Text
26370
26371 \begin_layout Standard
26372 a 10-bit eeprom pointer in EEPROM memory
26373 \end_layout
26374
26375 \end_inset
26376 </cell>
26377 </row>
26378 <row bottomline="true">
26379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26380 \begin_inset Text
26381
26382 \begin_layout Standard
26383 (unimplemented)
26384 \end_layout
26385
26386 \end_inset
26387 </cell>
26388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26389 \begin_inset Text
26390
26391 \begin_layout Standard
26392 1
26393 \end_layout
26394
26395 \end_inset
26396 </cell>
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26398 \begin_inset Text
26399
26400 \begin_layout Standard
26401 1
26402 \end_layout
26403
26404 \end_inset
26405 </cell>
26406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26407 \begin_inset Text
26408
26409 \begin_layout Standard
26410
26411 \family typewriter
26412 \shape slanted
26413 \emph on
26414 xxxxxx xxxxxxxx xxxxxxxx
26415 \end_layout
26416
26417 \end_inset
26418 </cell>
26419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26420 \begin_inset Text
26421
26422 \begin_layout Standard
26423 unimplemented pointer type
26424 \end_layout
26425
26426 \end_inset
26427 </cell>
26428 </row>
26429 </lyxtabular>
26430
26431 \end_inset
26432
26433
26434 \end_layout
26435
26436 \begin_layout Standard
26437 Generic pointer are read and written with a set of library functions which
26438  read/write 1, 2, 3, 4 bytes.
26439 \end_layout
26440
26441 \begin_layout Subsection
26442 PIC16 C Libraries
26443 \end_layout
26444
26445 \begin_layout Subsubsection
26446 Standard I/O Streams
26447 \end_layout
26448
26449 \begin_layout Standard
26450 In the 
26451 \emph on
26452 stdio.h
26453 \emph default
26454  the type FILE is defined as:
26455 \end_layout
26456
26457 \begin_layout LyX-Code
26458 typedef char * FILE;
26459 \end_layout
26460
26461 \begin_layout Standard
26462 This type is the stream type implemented I/O in the PIC18F devices.
26463  Also the standard input and output streams are declared in stdio.h:
26464 \end_layout
26465
26466 \begin_layout LyX-Code
26467 extern FILE * stdin;
26468 \end_layout
26469
26470 \begin_layout LyX-Code
26471 extern FILE * stdout;
26472 \end_layout
26473
26474 \begin_layout Standard
26475 The FILE type is actually a generic pointer which defines one more type
26476  of generic pointers, the 
26477 \emph on
26478 stream 
26479 \emph default
26480 pointer.
26481  This new type has the format:
26482 \end_layout
26483
26484 \begin_layout Standard
26485 \align center
26486 \begin_inset Tabular
26487 <lyxtabular version="3" rows="2" columns="7">
26488 <features>
26489 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26490 <column alignment="center" valignment="top" width="0">
26491 <column alignment="center" valignment="top" leftline="true" width="0">
26492 <column alignment="center" valignment="top" leftline="true" width="0">
26493 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26494 <column alignment="center" valignment="top" width="0">
26495 <column alignment="left" valignment="top" rightline="true" width="0">
26496 <row topline="true" bottomline="true">
26497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26498 \begin_inset Text
26499
26500 \begin_layout Standard
26501 pointer type
26502 \end_layout
26503
26504 \end_inset
26505 </cell>
26506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26507 \begin_inset Text
26508
26509 \begin_layout Standard
26510 <7:6>
26511 \end_layout
26512
26513 \end_inset
26514 </cell>
26515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26516 \begin_inset Text
26517
26518 \begin_layout Standard
26519 <5>
26520 \end_layout
26521
26522 \end_inset
26523 </cell>
26524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26525 \begin_inset Text
26526
26527 \begin_layout Standard
26528 <4>
26529 \end_layout
26530
26531 \end_inset
26532 </cell>
26533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26534 \begin_inset Text
26535
26536 \begin_layout Standard
26537 <3:0>
26538 \end_layout
26539
26540 \end_inset
26541 </cell>
26542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26543 \begin_inset Text
26544
26545 \begin_layout Standard
26546 rest of the pointer
26547 \end_layout
26548
26549 \end_inset
26550 </cell>
26551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26552 \begin_inset Text
26553
26554 \begin_layout Standard
26555 descrption
26556 \end_layout
26557
26558 \end_inset
26559 </cell>
26560 </row>
26561 <row topline="true" bottomline="true">
26562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26563 \begin_inset Text
26564
26565 \begin_layout Standard
26566 stream
26567 \end_layout
26568
26569 \end_inset
26570 </cell>
26571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26572 \begin_inset Text
26573
26574 \begin_layout Standard
26575 00
26576 \end_layout
26577
26578 \end_inset
26579 </cell>
26580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26581 \begin_inset Text
26582
26583 \begin_layout Standard
26584 1
26585 \end_layout
26586
26587 \end_inset
26588 </cell>
26589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26590 \begin_inset Text
26591
26592 \begin_layout Standard
26593 0
26594 \end_layout
26595
26596 \end_inset
26597 </cell>
26598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26599 \begin_inset Text
26600
26601 \begin_layout Standard
26602 nnnn
26603 \end_layout
26604
26605 \end_inset
26606 </cell>
26607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26608 \begin_inset Text
26609
26610 \begin_layout Standard
26611
26612 \family typewriter
26613 \shape slanted
26614 \emph on
26615 uuuuuuuu uuuuuuuu
26616 \end_layout
26617
26618 \end_inset
26619 </cell>
26620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26621 \begin_inset Text
26622
26623 \begin_layout Standard
26624 upper byte high nubble is 0x2n, the rest are zeroes
26625 \end_layout
26626
26627 \end_inset
26628 </cell>
26629 </row>
26630 </lyxtabular>
26631
26632 \end_inset
26633
26634
26635 \end_layout
26636
26637 \begin_layout Standard
26638 Currently implemented there are 3 types of streams defined:
26639 \end_layout
26640
26641 \begin_layout Standard
26642 \align center
26643 \begin_inset Tabular
26644 <lyxtabular version="3" rows="4" columns="4">
26645 <features>
26646 <column alignment="center" valignment="top" leftline="true" width="0">
26647 <column alignment="center" valignment="top" leftline="true" width="0">
26648 <column alignment="center" valignment="top" leftline="true" width="0">
26649 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26650 <row topline="true" bottomline="true">
26651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26652 \begin_inset Text
26653
26654 \begin_layout Standard
26655 stream type
26656 \end_layout
26657
26658 \end_inset
26659 </cell>
26660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26661 \begin_inset Text
26662
26663 \begin_layout Standard
26664 value
26665 \end_layout
26666
26667 \end_inset
26668 </cell>
26669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26670 \begin_inset Text
26671
26672 \begin_layout Standard
26673 module
26674 \end_layout
26675
26676 \end_inset
26677 </cell>
26678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26679 \begin_inset Text
26680
26681 \begin_layout Standard
26682 description
26683 \end_layout
26684
26685 \end_inset
26686 </cell>
26687 </row>
26688 <row topline="true">
26689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26690 \begin_inset Text
26691
26692 \begin_layout Standard
26693 STREAM_USART
26694 \end_layout
26695
26696 \end_inset
26697 </cell>
26698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26699 \begin_inset Text
26700
26701 \begin_layout Standard
26702
26703 \family typewriter
26704 0x200000UL
26705 \end_layout
26706
26707 \end_inset
26708 </cell>
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26710 \begin_inset Text
26711
26712 \begin_layout Standard
26713 USART
26714 \end_layout
26715
26716 \end_inset
26717 </cell>
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26719 \begin_inset Text
26720
26721 \begin_layout Standard
26722 Writes/Reads characters via the USART peripheral
26723 \end_layout
26724
26725 \end_inset
26726 </cell>
26727 </row>
26728 <row topline="true">
26729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26730 \begin_inset Text
26731
26732 \begin_layout Standard
26733 STREAM_MSSP
26734 \end_layout
26735
26736 \end_inset
26737 </cell>
26738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26739 \begin_inset Text
26740
26741 \begin_layout Standard
26742
26743 \family typewriter
26744 0x210000UL
26745 \end_layout
26746
26747 \end_inset
26748 </cell>
26749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26750 \begin_inset Text
26751
26752 \begin_layout Standard
26753 MSSP
26754 \end_layout
26755
26756 \end_inset
26757 </cell>
26758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26759 \begin_inset Text
26760
26761 \begin_layout Standard
26762 Writes/Reads characters via the MSSP peripheral
26763 \end_layout
26764
26765 \end_inset
26766 </cell>
26767 </row>
26768 <row topline="true" bottomline="true">
26769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26770 \begin_inset Text
26771
26772 \begin_layout Standard
26773 STREAM_USER
26774 \end_layout
26775
26776 \end_inset
26777 </cell>
26778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26779 \begin_inset Text
26780
26781 \begin_layout Standard
26782
26783 \family typewriter
26784 0x2f0000UL
26785 \end_layout
26786
26787 \end_inset
26788 </cell>
26789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26790 \begin_inset Text
26791
26792 \begin_layout Standard
26793 (none)
26794 \end_layout
26795
26796 \end_inset
26797 </cell>
26798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26799 \begin_inset Text
26800
26801 \begin_layout Standard
26802 Writes/Reads characters via used defined functions
26803 \end_layout
26804
26805 \end_inset
26806 </cell>
26807 </row>
26808 </lyxtabular>
26809
26810 \end_inset
26811
26812
26813 \end_layout
26814
26815 \begin_layout Standard
26816 The stream identifiers are declared as macros in the stdio.h header.
26817 \end_layout
26818
26819 \begin_layout Standard
26820 In the libc library there exist the functions that are used to write to
26821  each of the above streams.
26822  These are
26823 \end_layout
26824
26825 \begin_layout Description
26826 _
26827 \begin_inset ERT
26828 status collapsed
26829
26830 \begin_layout Standard
26831
26832
26833 \backslash
26834 /
26835 \end_layout
26836
26837 \end_inset
26838
26839 _stream_usart_putchar writes a character at the USART stream
26840 \end_layout
26841
26842 \begin_layout Description
26843 _
26844 \begin_inset ERT
26845 status collapsed
26846
26847 \begin_layout Standard
26848
26849
26850 \backslash
26851 /
26852 \end_layout
26853
26854 \end_inset
26855
26856 _stream_mssp_putchar writes a character at the MSSP stream
26857 \end_layout
26858
26859 \begin_layout Description
26860 putchar dummy function.
26861  This writes a character to a user specified manner.
26862 \end_layout
26863
26864 \begin_layout Standard
26865 In order to increase performance 
26866 \emph on
26867 putchar 
26868 \emph default
26869 is declared in stdio.h as having its parameter in WREG (it has the wparam
26870  keyword).
26871  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26872  in a user-friendly way.
26873  
26874 \emph on
26875 arg
26876 \emph default
26877  is the name of the variable that holds the character to print.
26878  An example follows:
26879 \end_layout
26880
26881 \begin_layout LyX-Code
26882 #include <pic18fregs.h>
26883 \newline
26884 #include <stdio.h>
26885 \newline
26886
26887 \newline
26888 PUTCHAR( c )
26889 \end_layout
26890
26891 \begin_layout LyX-Code
26892 {
26893 \end_layout
26894
26895 \begin_layout LyX-Code
26896     PORTA = c;    /* dump character c to PORTA */
26897 \end_layout
26898
26899 \begin_layout LyX-Code
26900
26901 \newline
26902
26903 \newline
26904 void main(void)
26905 \end_layout
26906
26907 \begin_layout LyX-Code
26908 {
26909 \end_layout
26910
26911 \begin_layout LyX-Code
26912     stdout = STREAM_USER;    /* this is not necessary, since stdout points
26913 \end_layout
26914
26915 \begin_layout LyX-Code
26916                               * by default to STREAM_USER */
26917 \end_layout
26918
26919 \begin_layout LyX-Code
26920     printf (
26921 \begin_inset Quotes sld
26922 \end_inset
26923
26924 This is a printf test
26925 \backslash
26926 n
26927 \begin_inset Quotes srd
26928 \end_inset
26929
26930 );
26931 \end_layout
26932
26933 \begin_layout LyX-Code
26934 }
26935 \end_layout
26936
26937 \begin_layout LyX-Code
26938
26939 \end_layout
26940
26941 \begin_layout Subsubsection
26942 Printing functions
26943 \end_layout
26944
26945 \begin_layout Standard
26946 PIC16 contains an implementation of the printf-family of functions.
26947  There exist the following functions:
26948 \end_layout
26949
26950 \begin_layout LyX-Code
26951 extern unsigned int sprintf(char *buf, char *fmt, ...);
26952 \end_layout
26953
26954 \begin_layout LyX-Code
26955 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26956 \end_layout
26957
26958 \begin_layout LyX-Code
26959
26960 \end_layout
26961
26962 \begin_layout LyX-Code
26963 extern unsigned int printf(char *fmt, ...);
26964 \end_layout
26965
26966 \begin_layout LyX-Code
26967 extern unsigned int vprintf(char *fmt, va_lista ap);
26968 \end_layout
26969
26970 \begin_layout LyX-Code
26971
26972 \end_layout
26973
26974 \begin_layout LyX-Code
26975 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26976 \end_layout
26977
26978 \begin_layout LyX-Code
26979 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26980 \end_layout
26981
26982 \begin_layout Standard
26983 For sprintf and vsprintf 
26984 \emph on
26985 buf 
26986 \emph default
26987 should normally be a data pointer where the resulting string will be placed.
26988  No range checking is done so the user should allocate the necessery buffer.
26989  For fprintf and vfprintf 
26990 \emph on
26991 fp
26992 \emph default
26993  should be a stream pointer (i.e.
26994  stdout, STREAM_MSSP, etc...).
26995 \end_layout
26996
26997 \begin_layout Subsubsection
26998 Signals
26999 \end_layout
27000
27001 \begin_layout Standard
27002 The PIC18F family of microcontrollers supports a number of interrupt sources.
27003  A list of these interrupts is shown in the following table:
27004 \end_layout
27005
27006 \begin_layout Standard
27007 \align center
27008 \begin_inset Tabular
27009 <lyxtabular version="3" rows="11" columns="4">
27010 <features>
27011 <column alignment="left" valignment="top" leftline="true" width="0">
27012 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27013 <column alignment="left" valignment="top" leftline="true" width="0">
27014 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27015 <row topline="true" bottomline="true">
27016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27017 \begin_inset Text
27018
27019 \begin_layout Standard
27020 signal name
27021 \end_layout
27022
27023 \end_inset
27024 </cell>
27025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27026 \begin_inset Text
27027
27028 \begin_layout Standard
27029 description
27030 \end_layout
27031
27032 \end_inset
27033 </cell>
27034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27035 \begin_inset Text
27036
27037 \begin_layout Standard
27038 signal name
27039 \end_layout
27040
27041 \end_inset
27042 </cell>
27043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27044 \begin_inset Text
27045
27046 \begin_layout Standard
27047 descritpion
27048 \end_layout
27049
27050 \end_inset
27051 </cell>
27052 </row>
27053 <row topline="true">
27054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27055 \begin_inset Text
27056
27057 \begin_layout Standard
27058 SIG_RB
27059 \end_layout
27060
27061 \end_inset
27062 </cell>
27063 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27064 \begin_inset Text
27065
27066 \begin_layout Standard
27067 PORTB change interrupt
27068 \end_layout
27069
27070 \end_inset
27071 </cell>
27072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27073 \begin_inset Text
27074
27075 \begin_layout Standard
27076 SIG_EE
27077 \end_layout
27078
27079 \end_inset
27080 </cell>
27081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27082 \begin_inset Text
27083
27084 \begin_layout Standard
27085 EEPROM/FLASH write complete interrupt
27086 \end_layout
27087
27088 \end_inset
27089 </cell>
27090 </row>
27091 <row topline="true">
27092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27093 \begin_inset Text
27094
27095 \begin_layout Standard
27096 SIG_INT0
27097 \end_layout
27098
27099 \end_inset
27100 </cell>
27101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27102 \begin_inset Text
27103
27104 \begin_layout Standard
27105 INT0 external interrupt
27106 \end_layout
27107
27108 \end_inset
27109 </cell>
27110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27111 \begin_inset Text
27112
27113 \begin_layout Standard
27114 SIG_BCOL
27115 \end_layout
27116
27117 \end_inset
27118 </cell>
27119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27120 \begin_inset Text
27121
27122 \begin_layout Standard
27123 Bus collision interrupt
27124 \end_layout
27125
27126 \end_inset
27127 </cell>
27128 </row>
27129 <row topline="true">
27130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27131 \begin_inset Text
27132
27133 \begin_layout Standard
27134 SIG_INT1
27135 \end_layout
27136
27137 \end_inset
27138 </cell>
27139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27140 \begin_inset Text
27141
27142 \begin_layout Standard
27143 INT1 external interrupt
27144 \end_layout
27145
27146 \end_inset
27147 </cell>
27148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27149 \begin_inset Text
27150
27151 \begin_layout Standard
27152 SIG_LVD
27153 \end_layout
27154
27155 \end_inset
27156 </cell>
27157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27158 \begin_inset Text
27159
27160 \begin_layout Standard
27161 Low voltage detect interrupt
27162 \end_layout
27163
27164 \end_inset
27165 </cell>
27166 </row>
27167 <row topline="true">
27168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27169 \begin_inset Text
27170
27171 \begin_layout Standard
27172 SIG_INT2
27173 \end_layout
27174
27175 \end_inset
27176 </cell>
27177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27178 \begin_inset Text
27179
27180 \begin_layout Standard
27181 INT2 external interrupt
27182 \end_layout
27183
27184 \end_inset
27185 </cell>
27186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27187 \begin_inset Text
27188
27189 \begin_layout Standard
27190 SIG_PSP
27191 \end_layout
27192
27193 \end_inset
27194 </cell>
27195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27196 \begin_inset Text
27197
27198 \begin_layout Standard
27199 Parallel slave port interrupt
27200 \end_layout
27201
27202 \end_inset
27203 </cell>
27204 </row>
27205 <row topline="true">
27206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27207 \begin_inset Text
27208
27209 \begin_layout Standard
27210 SIG_CCP1
27211 \end_layout
27212
27213 \end_inset
27214 </cell>
27215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27216 \begin_inset Text
27217
27218 \begin_layout Standard
27219 CCP1 module interrupt
27220 \end_layout
27221
27222 \end_inset
27223 </cell>
27224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27225 \begin_inset Text
27226
27227 \begin_layout Standard
27228 SIG_AD
27229 \end_layout
27230
27231 \end_inset
27232 </cell>
27233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27234 \begin_inset Text
27235
27236 \begin_layout Standard
27237 AD convertion complete interrupt
27238 \end_layout
27239
27240 \end_inset
27241 </cell>
27242 </row>
27243 <row topline="true">
27244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27245 \begin_inset Text
27246
27247 \begin_layout Standard
27248 SIG_CCP2
27249 \end_layout
27250
27251 \end_inset
27252 </cell>
27253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27254 \begin_inset Text
27255
27256 \begin_layout Standard
27257 CCP2 module interrupt
27258 \end_layout
27259
27260 \end_inset
27261 </cell>
27262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27263 \begin_inset Text
27264
27265 \begin_layout Standard
27266 SIG_RC
27267 \end_layout
27268
27269 \end_inset
27270 </cell>
27271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27272 \begin_inset Text
27273
27274 \begin_layout Standard
27275 USART receive interrupt
27276 \end_layout
27277
27278 \end_inset
27279 </cell>
27280 </row>
27281 <row topline="true">
27282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27283 \begin_inset Text
27284
27285 \begin_layout Standard
27286 SIG_TMR0
27287 \end_layout
27288
27289 \end_inset
27290 </cell>
27291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27292 \begin_inset Text
27293
27294 \begin_layout Standard
27295 TMR0 overflow interrupt
27296 \end_layout
27297
27298 \end_inset
27299 </cell>
27300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27301 \begin_inset Text
27302
27303 \begin_layout Standard
27304 SIG_TX
27305 \end_layout
27306
27307 \end_inset
27308 </cell>
27309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27310 \begin_inset Text
27311
27312 \begin_layout Standard
27313 USART transmit interrupt
27314 \end_layout
27315
27316 \end_inset
27317 </cell>
27318 </row>
27319 <row topline="true">
27320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27321 \begin_inset Text
27322
27323 \begin_layout Standard
27324 SIG_TMR1
27325 \end_layout
27326
27327 \end_inset
27328 </cell>
27329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27330 \begin_inset Text
27331
27332 \begin_layout Standard
27333 TMR1 overflow interrupt
27334 \end_layout
27335
27336 \end_inset
27337 </cell>
27338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27339 \begin_inset Text
27340
27341 \begin_layout Standard
27342 SIG_MSSP
27343 \end_layout
27344
27345 \end_inset
27346 </cell>
27347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27348 \begin_inset Text
27349
27350 \begin_layout Standard
27351 SSP receive/transmit interrupt
27352 \end_layout
27353
27354 \end_inset
27355 </cell>
27356 </row>
27357 <row topline="true">
27358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27359 \begin_inset Text
27360
27361 \begin_layout Standard
27362 SIG_TMR2
27363 \end_layout
27364
27365 \end_inset
27366 </cell>
27367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27368 \begin_inset Text
27369
27370 \begin_layout Standard
27371 TMR2 matches PR2 interrupt
27372 \end_layout
27373
27374 \end_inset
27375 </cell>
27376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27377 \begin_inset Text
27378
27379 \begin_layout Standard
27380
27381 \end_layout
27382
27383 \end_inset
27384 </cell>
27385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27386 \begin_inset Text
27387
27388 \begin_layout Standard
27389
27390 \end_layout
27391
27392 \end_inset
27393 </cell>
27394 </row>
27395 <row topline="true" bottomline="true">
27396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27397 \begin_inset Text
27398
27399 \begin_layout Standard
27400 SIG_TMR3
27401 \end_layout
27402
27403 \end_inset
27404 </cell>
27405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27406 \begin_inset Text
27407
27408 \begin_layout Standard
27409 TMR3 overflow interrupt
27410 \end_layout
27411
27412 \end_inset
27413 </cell>
27414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27415 \begin_inset Text
27416
27417 \begin_layout Standard
27418
27419 \end_layout
27420
27421 \end_inset
27422 </cell>
27423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27424 \begin_inset Text
27425
27426 \begin_layout Standard
27427
27428 \end_layout
27429
27430 \end_inset
27431 </cell>
27432 </row>
27433 </lyxtabular>
27434
27435 \end_inset
27436
27437
27438 \end_layout
27439
27440 \begin_layout Standard
27441 The prototypes for these names are defined in the header file 
27442 \emph on
27443 signal.h
27444 \emph default
27445  .
27446 \end_layout
27447
27448 \begin_layout Standard
27449 In order to simplify signal handling, a number of macros is provided:
27450 \end_layout
27451
27452 \begin_layout List
27453 \labelwidthstring 00.00.0000
27454 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27455  high priority interrupts.
27456  
27457 \emph on
27458 name
27459 \emph default
27460  is the function name to use.
27461 \end_layout
27462
27463 \begin_layout List
27464 \labelwidthstring 00.00.0000
27465 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27466  low priority interrupt.
27467  
27468 \emph on
27469 name
27470 \emph default
27471  is the function name to use.
27472 \end_layout
27473
27474 \begin_layout List
27475 \labelwidthstring 00.00.0000
27476 DEF_HANDLER(sig,handler) define a handler for signal 
27477 \emph on
27478 sig.
27479 \end_layout
27480
27481 \begin_layout List
27482 \labelwidthstring 00.00.0000
27483 END_DEF end the declaration of the dispatch table.
27484 \end_layout
27485
27486 \begin_layout Standard
27487 Additionally there are two more macros to simplify the declaration of the
27488  signal handler:
27489 \end_layout
27490
27491 \begin_layout List
27492 \labelwidthstring 00.00.0000
27493
27494 \series medium
27495 SIGHANDLER(handler) 
27496 \series default
27497 this declares the function prototype for the 
27498 \emph on
27499 handler
27500 \emph default
27501  function.
27502 \end_layout
27503
27504 \begin_layout List
27505 \labelwidthstring 00.00.0000
27506 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27507 \end_layout
27508
27509 \begin_layout Standard
27510 An example of using the macros above is shown below:
27511 \end_layout
27512
27513 \begin_layout LyX-Code
27514 #include <pic18fregs.h>
27515 \end_layout
27516
27517 \begin_layout LyX-Code
27518 #include <signal.h>
27519 \newline
27520
27521 \newline
27522 DEF_INTHIGH(high_int)
27523 \end_layout
27524
27525 \begin_layout LyX-Code
27526 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27527 \end_layout
27528
27529 \begin_layout LyX-Code
27530 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27531 \end_layout
27532
27533 \begin_layout LyX-Code
27534 END_DEF
27535 \newline
27536
27537 \newline
27538 SIGHANDLER(_tmr0_handler)
27539 \end_layout
27540
27541 \begin_layout LyX-Code
27542 {
27543 \end_layout
27544
27545 \begin_layout LyX-Code
27546   /* action to be taken when timer 0 overflows */
27547 \end_layout
27548
27549 \begin_layout LyX-Code
27550 }
27551 \newline
27552
27553 \newline
27554 SIGHANDLERNAKED(_bcol_handler)
27555 \end_layout
27556
27557 \begin_layout LyX-Code
27558 {
27559 \end_layout
27560
27561 \begin_layout LyX-Code
27562   _asm
27563 \end_layout
27564
27565 \begin_layout LyX-Code
27566     /* action to be taken when bus collision occurs */
27567 \end_layout
27568
27569 \begin_layout LyX-Code
27570     retfie
27571 \end_layout
27572
27573 \begin_layout LyX-Code
27574  _endasm;
27575 \end_layout
27576
27577 \begin_layout LyX-Code
27578 }
27579 \end_layout
27580
27581 \begin_layout Standard
27582
27583 \series bold
27584 NOTES:
27585 \series default
27586  Special care should be taken when using the above scheme:
27587 \end_layout
27588
27589 \begin_layout Itemize
27590 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27591 \end_layout
27592
27593 \begin_layout Itemize
27594 when declaring SIGHANDLERNAKED handler never forget to use 
27595 \emph on
27596 retfie
27597 \emph default
27598  for proper returning.
27599 \end_layout
27600
27601 \begin_layout Subsection
27602 PIC16 Port -- Tips
27603 \end_layout
27604
27605 \begin_layout Standard
27606 Here you can find some general tips for compiling programs with SDCC/pic16.
27607 \end_layout
27608
27609 \begin_layout Subsubsection
27610 Stack size
27611 \end_layout
27612
27613 \begin_layout Standard
27614 The default stack
27615 \begin_inset LatexCommand \index{PIC16!stack}
27616
27617 \end_inset
27618
27619  size (that is 64 bytes) probably is enough for many programs.
27620  One must take care that when there are many levels of function nesting,
27621  or there is excessive usage of stack, its size should be extended.
27622  An example of such a case is the printf/sprintf family of functions.
27623  If you encounter problems like not being able to print integers, then you
27624  need to set the stack size around the maximum (256 for small stack model).
27625  The following diagram shows what happens when calling printf to print an
27626  integer:
27627 \end_layout
27628
27629 \begin_layout LyX-Code
27630 printf () --> ltoa () --> ultoa () --> divschar ()
27631 \end_layout
27632
27633 \begin_layout Standard
27634 It is should be understood that stack is easily consumed when calling complicate
27635 d functions.
27636  Using command line arguments like -
27637 \begin_inset ERT
27638 status collapsed
27639
27640 \begin_layout Standard
27641
27642
27643 \backslash
27644 /
27645 \end_layout
27646
27647 \end_inset
27648
27649 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27650  stack frames.
27651  Other ways to reduce stack usage may exist.
27652 \end_layout
27653
27654 \begin_layout Subsection
27655 Known Bugs
27656 \end_layout
27657
27658 \begin_layout Standard
27659 The PIC16 Port currently does not pass SDCC's regression test
27660 \begin_inset LatexCommand \index{Regression test (PIC16)}
27661
27662 \end_inset
27663
27664  suite (see section 
27665 \begin_inset LatexCommand \ref{sec:Quality-control}
27666
27667 \end_inset
27668
27669 ) and thus the snapshot build regression tests for the PIC16 target are
27670  currently disabled for all hosts
27671 \emph on
27672 .
27673 \end_layout
27674
27675 \begin_layout Chapter
27676 Debugging
27677 \end_layout
27678
27679 \begin_layout Standard
27680 There are several approaches to debugging your code.
27681  This chapter is meant to show your options and to give detail on some of
27682  them:
27683 \newline
27684
27685 \newline
27686 When writing your code:
27687 \end_layout
27688
27689 \begin_layout Itemize
27690 write your code with debugging in mind (avoid duplicating code, put conceptually
27691  similar variables into structs, use structured code, have strategic points
27692  within your code where all variables are consistent, ...)
27693 \end_layout
27694
27695 \begin_layout Itemize
27696 run a syntax-checking tool like splint
27697 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27698
27699 \end_inset
27700
27701
27702 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27703
27704 \end_inset
27705
27706  (see -
27707 \begin_inset ERT
27708 status collapsed
27709
27710 \begin_layout Standard
27711
27712
27713 \backslash
27714 /
27715 \end_layout
27716
27717 \end_inset
27718
27719 -more-pedantic 
27720 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27721
27722 \end_inset
27723
27724 ) over the code.
27725 \end_layout
27726
27727 \begin_layout Itemize
27728 for the high level code use a C-compiler (like f.e.
27729  GCC) to compile run and debug the code on your host.
27730  See (see -
27731 \begin_inset ERT
27732 status collapsed
27733
27734 \begin_layout Standard
27735
27736
27737 \backslash
27738 /
27739 \end_layout
27740
27741 \end_inset
27742
27743 -more-pedantic 
27744 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27745
27746 \end_inset
27747
27748 ) on how to handle syntax extensions like __xdata, __at(), ...
27749  
27750 \end_layout
27751
27752 \begin_layout Itemize
27753 use another C-compiler to compile code for your target.
27754  Always an option but not recommended:) And not very likely to help you.
27755  If you seriously consider walking this path you should at least occasionally
27756  check portability of your code.
27757  Most commercial compiler vendors will offer an evaluation version so you
27758  can test compile your code or snippets of your code.
27759 \end_layout
27760
27761 \begin_layout Standard
27762 Debugging on a simulator:
27763 \end_layout
27764
27765 \begin_layout Itemize
27766 there is a separate section about SDCDB (section 
27767 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27768
27769 \end_inset
27770
27771 ) below.
27772 \end_layout
27773
27774 \begin_layout Itemize
27775 or (8051 specific) use a freeware/commercial simulator which interfaces
27776  to the AOMF
27777 \begin_inset LatexCommand \index{AOMF, AOMF51}
27778
27779 \end_inset
27780
27781  file (see 
27782 \begin_inset LatexCommand \ref{OMF file}
27783
27784 \end_inset
27785
27786 ) optionally generated by SDCC.
27787 \end_layout
27788
27789 \begin_layout Standard
27790 Debugging On-target: 
27791 \end_layout
27792
27793 \begin_layout Itemize
27794 use a MCU port pin to serially output debug data to the RS232 port of your
27795  host.
27796  You'll probably want some level shifting device typically involving a MAX232
27797  or similar IC.
27798  If the hardware serial port of the MCU is not available search for 'Software
27799  UART' in your favourite search machine.
27800 \end_layout
27801
27802 \begin_layout Itemize
27803 use an on-target monitor.
27804  In this context a monitor is a small program which usually accepts commands
27805  via a serial line and allows to set program counter, to single step through
27806  a program and read/write memory locations.
27807  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27808  
27809 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27810
27811 \end_inset
27812
27813 ).
27814 \end_layout
27815
27816 \begin_layout Itemize
27817 toggle MCU port pins at strategic points within your code and use an oscilloscop
27818 e.
27819  A 
27820 \emph on
27821 digital oscilloscope
27822 \emph default
27823
27824 \begin_inset LatexCommand \index{Oscilloscope}
27825
27826 \end_inset
27827
27828  with deep trace memory is really helpful especially if you have to debug
27829  a realtime application.
27830  If you need to monitor more pins than your oscilloscope provides you can
27831  sometimes get away with a small R-2R network.
27832  On a single channel oscilloscope you could f.e.
27833  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27834 k
27835 \begin_inset Formula $\Omega$
27836 \end_inset
27837
27838  resistor and the other one by a 5\InsetSpace ~
27839 k
27840 \begin_inset Formula $\Omega$
27841 \end_inset
27842
27843  resistor to the oscilloscope probe (check output drive capability of the
27844  pins you want to monitor).
27845  If you need to monitor many more pins a 
27846 \emph on
27847 logic analyzer
27848 \emph default
27849  will be handy.
27850 \end_layout
27851
27852 \begin_layout Itemize
27853 use an ICE (
27854 \emph on
27855 i
27856 \emph default
27857
27858 \emph on
27859 c
27860 \emph default
27861 ircuit 
27862 \emph on
27863 e
27864 \emph default
27865 mulator
27866 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27867
27868 \end_inset
27869
27870 ).
27871  Usually very expensive.
27872  And very nice to have too.
27873  And usually locks you (for years...) to the devices the ICE can emulate.
27874  
27875 \end_layout
27876
27877 \begin_layout Itemize
27878 use a remote debugger.
27879  In most 8-bit systems the symbol information is not available on the target,
27880  and a complete debugger is too bulky for the target system.
27881  Therefore usually a debugger on the host system connects to an on-target
27882  debugging stub which accepts only primitive commands.
27883  
27884 \newline
27885 Terms to enter into your favourite search engine could be 'remote debugging',
27886  'gdb stub' or 'inferior debugger'.
27887  (is there one?)
27888 \end_layout
27889
27890 \begin_layout Itemize
27891 use an on target hardware debugger.
27892  Some of the more modern MCUs include hardware support for setting break
27893  points and monitoring/changing variables by using dedicated hardware pins.
27894  This facility doesn't require additional code to run on the target and
27895  
27896 \emph on
27897 usually
27898 \emph default
27899  doesn't affect runtime behaviour until a breakpoint is hit.
27900  For the mcs51 most hardware debuggers use the AOMF
27901 \begin_inset LatexCommand \index{AOMF, AOMF51}
27902
27903 \end_inset
27904
27905  file (see 
27906 \begin_inset LatexCommand \ref{OMF file}
27907
27908 \end_inset
27909
27910 ) as input file.
27911  
27912 \end_layout
27913
27914 \begin_layout Standard
27915 Last not least:
27916 \end_layout
27917
27918 \begin_layout Itemize
27919 if you are not familiar with any of the following terms you're likely to
27920  run into problems rather sooner than later: 
27921 \emph on
27922 volatile
27923 \emph default
27924
27925 \emph on
27926 atomic
27927 \emph default
27928
27929 \emph on
27930 memory map
27931 \emph default
27932
27933 \emph on
27934 overlay
27935 \emph default
27936 .
27937  As an embedded programmer you 
27938 \emph on
27939 have
27940 \emph default
27941  to know them so why not look them up 
27942 \emph on
27943 before
27944 \emph default
27945  you have problems?)
27946 \end_layout
27947
27948 \begin_layout Itemize
27949 tell someone else about your problem (actually this is a surprisingly effective
27950  means to hunt down the bug even if the listener is not familiar with your
27951  environment).
27952  As 'failure to communicate' is probably one of the job-induced deformations
27953  of an embedded programmer this is highly encouraged.
27954 \end_layout
27955
27956 \begin_layout Section
27957 Debugging with SDCDB
27958 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27959
27960 \end_inset
27961
27962
27963 \begin_inset LatexCommand \index{SDCDB (debugger)}
27964
27965 \end_inset
27966
27967  
27968 \end_layout
27969
27970 \begin_layout Standard
27971 SDCC is distributed with a source level debugger
27972 \begin_inset LatexCommand \index{Debugger}
27973
27974 \end_inset
27975
27976 .
27977  The debugger uses a command line interface, the command repertoire of the
27978  debugger has been kept as close to gdb
27979 \begin_inset LatexCommand \index{gdb}
27980
27981 \end_inset
27982
27983  (the GNU debugger) as possible.
27984  The configuration and build process is part of the standard compiler installati
27985 on, which also builds and installs the debugger in the target directory
27986  specified during configuration.
27987  The debugger allows you debug BOTH at the C source and at the ASM source
27988  level.
27989 \end_layout
27990
27991 \begin_layout Subsection
27992 Compiling for Debugging
27993 \end_layout
27994
27995 \begin_layout Standard
27996 The -
27997 \begin_inset ERT
27998 status collapsed
27999
28000 \begin_layout Standard
28001
28002
28003 \backslash
28004 /
28005 \end_layout
28006
28007 \end_inset
28008
28009 -debug
28010 \begin_inset LatexCommand \index{-\/-debug}
28011
28012 \end_inset
28013
28014  option must be specified for all files for which debug information is to
28015  be generated.
28016  The compiler generates a .adb file for each of these files.
28017  The linker creates the .cdb
28018 \begin_inset LatexCommand \index{<file>.cdb}
28019
28020 \end_inset
28021
28022  file from the .adb
28023 \begin_inset LatexCommand \index{<file>.adb}
28024
28025 \end_inset
28026
28027  files and the address information.
28028  This .cdb is used by the debugger.
28029 \end_layout
28030
28031 \begin_layout Subsection
28032 How the Debugger Works
28033 \end_layout
28034
28035 \begin_layout Standard
28036 When the -
28037 \begin_inset ERT
28038 status collapsed
28039
28040 \begin_layout Standard
28041
28042
28043 \backslash
28044 /
28045 \end_layout
28046
28047 \end_inset
28048
28049 -debug option is specified the compiler generates extra symbol information
28050  some of which are put into the assembler source and some are put into the
28051  .adb file.
28052  Then the linker creates the .cdb file from the individual .adb files with
28053  the address information for the symbols.
28054  The debugger reads the symbolic information generated by the compiler &
28055  the address information generated by the linker.
28056  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28057  execution is controlled by the debugger.
28058  When a command is issued for the debugger, it translates it into appropriate
28059  commands for the simulator.
28060  (Currently SDCDM only connects to the simulator but 
28061 \emph on
28062 newcdb
28063 \emph default
28064  at 
28065 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28066
28067 \end_inset
28068
28069  is an effort to connect directly to the hardware.) 
28070 \end_layout
28071
28072 \begin_layout Subsection
28073 Starting the Debugger SDCDB
28074 \end_layout
28075
28076 \begin_layout Standard
28077 The debugger can be started using the following command line.
28078  (Assume the file you are debugging has the file name foo).
28079 \newline
28080
28081 \newline
28082
28083 \family sans
28084 \series bold
28085 sdcdb foo
28086 \newline
28087
28088 \family default
28089 \series default
28090
28091 \newline
28092 The debugger will look for the following files.
28093 \end_layout
28094
28095 \begin_layout Itemize
28096 foo.c - the source file.
28097 \end_layout
28098
28099 \begin_layout Itemize
28100 foo.cdb - the debugger symbol information file.
28101 \end_layout
28102
28103 \begin_layout Itemize
28104 foo.ihx - the Intel hex format
28105 \begin_inset LatexCommand \index{Intel hex format}
28106
28107 \end_inset
28108
28109  object file.
28110 \end_layout
28111
28112 \begin_layout Subsection
28113 SDCDB Command Line Options
28114 \end_layout
28115
28116 \begin_layout Itemize
28117 -
28118 \begin_inset ERT
28119 status collapsed
28120
28121 \begin_layout Standard
28122
28123
28124 \backslash
28125 /
28126 \end_layout
28127
28128 \end_inset
28129
28130 -directory=<source file directory> this option can used to specify the directory
28131  search list.
28132  The debugger will look into the directory list specified for source, cdb
28133  & ihx files.
28134  The items in the directory list must be separated by ':', e.g.
28135  if the source files can be in the directories /home/src1 and /home/src2,
28136  the -
28137 \begin_inset ERT
28138 status collapsed
28139
28140 \begin_layout Standard
28141
28142
28143 \backslash
28144 /
28145 \end_layout
28146
28147 \end_inset
28148
28149 -directory option should be -
28150 \begin_inset ERT
28151 status collapsed
28152
28153 \begin_layout Standard
28154
28155
28156 \backslash
28157 /
28158 \end_layout
28159
28160 \end_inset
28161
28162 -directory=/home/src1:/home/src2.
28163  Note there can be no spaces in the option.
28164  
28165 \end_layout
28166
28167 \begin_layout Itemize
28168 -cd <directory> - change to the <directory>.
28169 \end_layout
28170
28171 \begin_layout Itemize
28172 -fullname - used by GUI front ends.
28173 \end_layout
28174
28175 \begin_layout Itemize
28176 -cpu <cpu-type> - this argument is passed to the simulator please see the
28177  simulator docs for details.
28178 \end_layout
28179
28180 \begin_layout Itemize
28181 -X <Clock frequency > this options is passed to the simulator please see
28182  the simulator docs for details.
28183 \end_layout
28184
28185 \begin_layout Itemize
28186 -s <serial port file> passed to simulator see the simulator docs for details.
28187 \end_layout
28188
28189 \begin_layout Itemize
28190 -S <serial in,out> passed to simulator see the simulator docs for details.
28191 \end_layout
28192
28193 \begin_layout Itemize
28194 -k <port number> passed to simulator see the simulator docs for details.
28195 \end_layout
28196
28197 \begin_layout Subsection
28198 SDCDB Debugger Commands
28199 \end_layout
28200
28201 \begin_layout Standard
28202 As mentioned earlier the command interface for the debugger has been deliberatel
28203 y kept as close the GNU debugger gdb, as possible.
28204  This will help the integration with existing graphical user interfaces
28205  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28206  If you use a graphical user interface for the debugger you can skip this
28207  section.
28208 \end_layout
28209
28210 \begin_layout Subsubsection*
28211 break [line | file:line | function | file:function]
28212 \end_layout
28213
28214 \begin_layout Standard
28215 Set breakpoint at specified line or function:
28216 \newline
28217
28218 \newline
28219
28220 \family sans
28221 \series bold
28222 sdcdb>break 100 
28223 \newline
28224 sdcdb>break foo.c:100
28225 \newline
28226 sdcdb>break funcfoo
28227 \newline
28228 sdcdb>break foo.c:funcfoo
28229 \end_layout
28230
28231 \begin_layout Subsubsection*
28232 clear [line | file:line | function | file:function ]
28233 \end_layout
28234
28235 \begin_layout Standard
28236 Clear breakpoint at specified line or function:
28237 \newline
28238
28239 \newline
28240
28241 \family sans
28242 \series bold
28243 sdcdb>clear 100
28244 \newline
28245 sdcdb>clear foo.c:100
28246 \newline
28247 sdcdb>clear funcfoo
28248 \newline
28249 sdcdb>clear foo.c:funcfoo
28250 \end_layout
28251
28252 \begin_layout Subsubsection*
28253 continue
28254 \end_layout
28255
28256 \begin_layout Standard
28257 Continue program being debugged, after breakpoint.
28258 \end_layout
28259
28260 \begin_layout Subsubsection*
28261 finish
28262 \end_layout
28263
28264 \begin_layout Standard
28265 Execute till the end of the current function.
28266 \end_layout
28267
28268 \begin_layout Subsubsection*
28269 delete [n]
28270 \end_layout
28271
28272 \begin_layout Standard
28273 Delete breakpoint number 'n'.
28274  If used without any option clear ALL user defined break points.
28275 \end_layout
28276
28277 \begin_layout Subsubsection*
28278 info [break | stack | frame | registers ]
28279 \end_layout
28280
28281 \begin_layout Itemize
28282 info break - list all breakpoints
28283 \end_layout
28284
28285 \begin_layout Itemize
28286 info stack - show the function call stack.
28287 \end_layout
28288
28289 \begin_layout Itemize
28290 info frame - show information about the current execution frame.
28291 \end_layout
28292
28293 \begin_layout Itemize
28294 info registers - show content of all registers.
28295 \end_layout
28296
28297 \begin_layout Subsubsection*
28298 step
28299 \end_layout
28300
28301 \begin_layout Standard
28302 Step program until it reaches a different source line.
28303  Note: pressing <return> repeats the last command.
28304 \end_layout
28305
28306 \begin_layout Subsubsection*
28307 next
28308 \end_layout
28309
28310 \begin_layout Standard
28311 Step program, proceeding through subroutine calls.
28312 \end_layout
28313
28314 \begin_layout Subsubsection*
28315 run
28316 \end_layout
28317
28318 \begin_layout Standard
28319 Start debugged program.
28320 \end_layout
28321
28322 \begin_layout Subsubsection*
28323 ptype variable 
28324 \end_layout
28325
28326 \begin_layout Standard
28327 Print type information of the variable.
28328 \end_layout
28329
28330 \begin_layout Subsubsection*
28331 print variable
28332 \end_layout
28333
28334 \begin_layout Standard
28335 print value of variable.
28336 \end_layout
28337
28338 \begin_layout Subsubsection*
28339 file filename
28340 \end_layout
28341
28342 \begin_layout Standard
28343 load the given file name.
28344  Note this is an alternate method of loading file for debugging.
28345 \end_layout
28346
28347 \begin_layout Subsubsection*
28348 frame
28349 \end_layout
28350
28351 \begin_layout Standard
28352 print information about current frame.
28353 \end_layout
28354
28355 \begin_layout Subsubsection*
28356 set srcmode
28357 \end_layout
28358
28359 \begin_layout Standard
28360 Toggle between C source & assembly source.
28361 \end_layout
28362
28363 \begin_layout Subsubsection*
28364 ! simulator command
28365 \end_layout
28366
28367 \begin_layout Standard
28368 Send the string following '!' to the simulator, the simulator response is
28369  displayed.
28370  Note the debugger does not interpret the command being sent to the simulator,
28371  so if a command like 'go' is sent the debugger can loose its execution
28372  context and may display incorrect values.
28373 \end_layout
28374
28375 \begin_layout Subsubsection*
28376 quit
28377 \end_layout
28378
28379 \begin_layout Standard
28380 "Watch me now.
28381  Iam going Down.
28382  My name is Bobby Brown"
28383 \end_layout
28384
28385 \begin_layout Subsection
28386 Interfacing SDCDB with DDD
28387 \end_layout
28388
28389 \begin_layout Standard
28390 \begin_inset Note Note
28391 status collapsed
28392
28393 \begin_layout Standard
28394 The screenshot was converted from png to eps with: 
28395 \begin_inset Quotes sld
28396 \end_inset
28397
28398 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28399 \begin_inset Quotes srd
28400 \end_inset
28401
28402  which produces a pretty compact eps file which is free from compression
28403  artifacts.
28404 \end_layout
28405
28406 \begin_layout Standard
28407 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28408  as this broke the build system on Sourceforge (pdf-file was broken.
28409  pdflatex does not accept eps files).
28410 \end_layout
28411
28412 \end_inset
28413
28414
28415 \end_layout
28416
28417 \begin_layout Standard
28418 The 
28419 \emph on
28420 p
28421 \emph default
28422 ortable 
28423 \emph on
28424 n
28425 \emph default
28426 etwork 
28427 \emph on
28428 g
28429 \emph default
28430 raphics File 
28431 \size footnotesize
28432
28433 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28434
28435 \end_inset
28436
28437
28438 \size default
28439  shows a screenshot of a debugging session with DDD
28440 \begin_inset LatexCommand \index{DDD (debugger)}
28441
28442 \end_inset
28443
28444  (Unix only) on a simulated 8032.
28445  The debugging session might not run as smoothly as the screenshot suggests.
28446  The debugger allows setting of breakpoints, displaying and changing variables,
28447  single stepping through C and assembler code.
28448  
28449 \newline
28450 The source was compiled with 
28451 \family sans
28452 \series bold
28453
28454 \newline
28455
28456 \newline
28457 sdcc -
28458 \family default
28459 \series default
28460
28461 \begin_inset ERT
28462 status collapsed
28463
28464 \begin_layout Standard
28465
28466
28467 \backslash
28468 /
28469 \end_layout
28470
28471 \end_inset
28472
28473
28474 \family sans
28475 \series bold
28476 -debug ddd_example.c
28477 \family default
28478 \series default
28479  
28480 \family sans
28481 \series bold
28482
28483 \newline
28484
28485 \family default
28486 \series default
28487
28488 \newline
28489 and DDD was invoked with 
28490 \family sans
28491 \series bold
28492
28493 \newline
28494
28495 \newline
28496 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28497 \end_layout
28498
28499 \begin_layout Standard
28500 \begin_inset Note Note
28501 status open
28502
28503 \begin_layout Standard
28504 Check that the double quotes or an apostroph within the command line survive
28505  the LyX tool chain.
28506  Previously the apostrophs got slanted in the PDF output so a cut and paste
28507  did not work.
28508 \end_layout
28509
28510 \end_inset
28511
28512
28513 \end_layout
28514
28515 \begin_layout Subsection
28516 Interfacing SDCDB with XEmacs
28517 \begin_inset LatexCommand \index{XEmacs}
28518
28519 \end_inset
28520
28521
28522 \begin_inset LatexCommand \index{Emacs}
28523
28524 \end_inset
28525
28526
28527 \end_layout
28528
28529 \begin_layout Standard
28530 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28531  sdcdb.el and sdcdbsrc.el.
28532  These two files can be found in the $(prefix)/bin directory after the installat
28533 ion is complete.
28534  These files need to be loaded into XEmacs for the interface to work.
28535  This can be done at XEmacs startup time by inserting the following into
28536  your '.xemacs' file (which can be found in your HOME directory): 
28537 \newline
28538
28539 \newline
28540
28541 \family typewriter
28542 (load-file sdcdbsrc.el) 
28543 \family default
28544
28545 \newline
28546
28547 \newline
28548 .xemacs is a lisp file so the () around the command is REQUIRED.
28549  The files can also be loaded dynamically while XEmacs is running, set the
28550  environment variable 'EMACSLOADPATH' to the installation bin directory
28551  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28552  To start the interface enter the following command: 
28553 \newline
28554
28555 \newline
28556
28557 \family sans
28558 \series bold
28559 ESC-x sdcdbsrc
28560 \family default
28561 \series default
28562
28563 \newline
28564
28565 \newline
28566 You will prompted to enter the file name to be debugged.
28567  
28568 \newline
28569
28570 \newline
28571 The command line options that are passed to the simulator directly are
28572  bound to default values in the file sdcdbsrc.el.
28573  The variables are listed below, these values maybe changed as required.
28574 \end_layout
28575
28576 \begin_layout Itemize
28577 sdcdbsrc-cpu-type '51
28578 \end_layout
28579
28580 \begin_layout Itemize
28581 sdcdbsrc-frequency '11059200
28582 \end_layout
28583
28584 \begin_layout Itemize
28585 sdcdbsrc-serial nil
28586 \end_layout
28587
28588 \begin_layout Standard
28589 The following is a list of key mapping for the debugger interface.
28590 \end_layout
28591
28592 \begin_layout Standard
28593 \InsetSpace ~
28594
28595 \family typewriter
28596
28597 \newline
28598 ;;\InsetSpace ~
28599 Current Listing :: 
28600 \newline
28601 ;;key\InsetSpace ~
28602 \InsetSpace ~
28603 \InsetSpace ~
28604 \InsetSpace ~
28605 \InsetSpace ~
28606 \InsetSpace ~
28607 \InsetSpace ~
28608 \InsetSpace ~
28609 \InsetSpace ~
28610 \InsetSpace ~
28611 \InsetSpace ~
28612 \InsetSpace ~
28613 \InsetSpace ~
28614 \InsetSpace ~
28615 binding\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 Comment 
28638 \newline
28639 ;;---\InsetSpace ~
28640 \InsetSpace ~
28641 \InsetSpace ~
28642 \InsetSpace ~
28643 \InsetSpace ~
28644 \InsetSpace ~
28645 \InsetSpace ~
28646 \InsetSpace ~
28647 \InsetSpace ~
28648 \InsetSpace ~
28649 \InsetSpace ~
28650 \InsetSpace ~
28651 \InsetSpace ~
28652 \InsetSpace ~
28653 -------\InsetSpace ~
28654 \InsetSpace ~
28655 \InsetSpace ~
28656 \InsetSpace ~
28657 \InsetSpace ~
28658 \InsetSpace ~
28659 \InsetSpace ~
28660 \InsetSpace ~
28661 \InsetSpace ~
28662 \InsetSpace ~
28663 \InsetSpace ~
28664 \InsetSpace ~
28665 \InsetSpace ~
28666 \InsetSpace ~
28667 \InsetSpace ~
28668 \InsetSpace ~
28669 \InsetSpace ~
28670 \InsetSpace ~
28671 \InsetSpace ~
28672 \InsetSpace ~
28673 \InsetSpace ~
28674 \InsetSpace ~
28675 -------
28676 \newline
28677 ;; 
28678 \newline
28679 ;;\InsetSpace ~
28680 n\InsetSpace ~
28681 \InsetSpace ~
28682 \InsetSpace ~
28683 \InsetSpace ~
28684 \InsetSpace ~
28685 \InsetSpace ~
28686 \InsetSpace ~
28687 \InsetSpace ~
28688 \InsetSpace ~
28689 \InsetSpace ~
28690 \InsetSpace ~
28691 \InsetSpace ~
28692 \InsetSpace ~
28693 \InsetSpace ~
28694 \InsetSpace ~
28695 sdcdb-next-fro
28696 m-src\InsetSpace ~
28697 \InsetSpace ~
28698 \InsetSpace ~
28699 \InsetSpace ~
28700 \InsetSpace ~
28701 \InsetSpace ~
28702 \InsetSpace ~
28703 \InsetSpace ~
28704 \InsetSpace ~
28705 \InsetSpace ~
28706 SDCDB next command 
28707 \newline
28708 ;;\InsetSpace ~
28709 b\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 sdcdb-back-from-src\InsetSpace ~
28725 \InsetSpace ~
28726 \InsetSpace ~
28727 \InsetSpace ~
28728 \InsetSpace ~
28729 \InsetSpace ~
28730 \InsetSpace ~
28731 \InsetSpace ~
28732 \InsetSpace ~
28733 \InsetSpace ~
28734 SDCDB back command 
28735 \newline
28736 ;;\InsetSpace ~
28737 c\InsetSpace ~
28738 \InsetSpace ~
28739 \InsetSpace ~
28740 \InsetSpace ~
28741 \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744 \InsetSpace ~
28745 \InsetSpace ~
28746 \InsetSpace ~
28747 \InsetSpace ~
28748 \InsetSpace ~
28749 \InsetSpace ~
28750 \InsetSpace ~
28751 \InsetSpace ~
28752 sdcdb-cont-f
28753 rom-src\InsetSpace ~
28754 \InsetSpace ~
28755 \InsetSpace ~
28756 \InsetSpace ~
28757 \InsetSpace ~
28758 \InsetSpace ~
28759 \InsetSpace ~
28760 \InsetSpace ~
28761 \InsetSpace ~
28762 \InsetSpace ~
28763 SDCDB continue command
28764 \newline
28765 ;;\InsetSpace ~
28766 s\InsetSpace ~
28767 \InsetSpace ~
28768 \InsetSpace ~
28769 \InsetSpace ~
28770 \InsetSpace ~
28771 \InsetSpace ~
28772 \InsetSpace ~
28773 \InsetSpace ~
28774 \InsetSpace ~
28775 \InsetSpace ~
28776 \InsetSpace ~
28777 \InsetSpace ~
28778 \InsetSpace ~
28779 \InsetSpace ~
28780 \InsetSpace ~
28781 sdcdb-step-from-src\InsetSpace ~
28782 \InsetSpace ~
28783 \InsetSpace ~
28784 \InsetSpace ~
28785 \InsetSpace ~
28786 \InsetSpace ~
28787 \InsetSpace ~
28788 \InsetSpace ~
28789 \InsetSpace ~
28790 \InsetSpace ~
28791 SDCDB step command 
28792 \newline
28793 ;;\InsetSpace ~
28794 ?\InsetSpace ~
28795 \InsetSpace ~
28796 \InsetSpace ~
28797 \InsetSpace ~
28798 \InsetSpace ~
28799 \InsetSpace ~
28800 \InsetSpace ~
28801 \InsetSpace ~
28802 \InsetSpace ~
28803 \InsetSpace ~
28804 \InsetSpace ~
28805 \InsetSpace ~
28806 \InsetSpace ~
28807 \InsetSpace ~
28808 \InsetSpace ~
28809 sdcdb-w
28810 hatis-c-sexp\InsetSpace ~
28811 \InsetSpace ~
28812 \InsetSpace ~
28813 \InsetSpace ~
28814 \InsetSpace ~
28815 \InsetSpace ~
28816 \InsetSpace ~
28817 \InsetSpace ~
28818 \InsetSpace ~
28819 \InsetSpace ~
28820 SDCDB ptypecommand for data at 
28821 \newline
28822 ;;\InsetSpace ~
28823 \InsetSpace ~
28824 \InsetSpace ~
28825 \InsetSpace ~
28826 \InsetSpace ~
28827 \InsetSpace ~
28828 \InsetSpace ~
28829 \InsetSpace ~
28830 \InsetSpace ~
28831 \InsetSpace ~
28832 \InsetSpace ~
28833 \InsetSpace ~
28834 \InsetSpace ~
28835 \InsetSpace ~
28836 \InsetSpace ~
28837 \InsetSpace ~
28838 \InsetSpace ~
28839 \InsetSpace ~
28840 \InsetSpace ~
28841 \InsetSpace ~
28842 \InsetSpace ~
28843 \InsetSpace ~
28844 \InsetSpace ~
28845 \InsetSpace ~
28846 \InsetSpace ~
28847 \InsetSpace ~
28848 \InsetSpace ~
28849 \InsetSpace ~
28850 \InsetSpace ~
28851 \InsetSpace ~
28852 \InsetSpace ~
28853 \InsetSpace ~
28854 \InsetSpace ~
28855 \InsetSpace ~
28856 \InsetSpace ~
28857 \InsetSpace ~
28858 \InsetSpace ~
28859 \InsetSpace ~
28860 \InsetSpace ~
28861 \InsetSpace ~
28862 \InsetSpace ~
28863 \InsetSpace ~
28864 \InsetSpace ~
28865 \InsetSpace ~
28866 \InsetSpace ~
28867 \InsetSpace ~
28868 \InsetSpace ~
28869 buffer point 
28870 \newline
28871 ;;\InsetSpace ~
28872 x\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 sdcdbsrc-delete\InsetSpace ~
28888 \InsetSpace ~
28889 \InsetSpace ~
28890 \InsetSpace ~
28891 \InsetSpace ~
28892 \InsetSpace ~
28893 \InsetSpace ~
28894 \InsetSpace ~
28895 \InsetSpace ~
28896 \InsetSpace ~
28897 \InsetSpace ~
28898 \InsetSpace ~
28899 \InsetSpace ~
28900 \InsetSpace ~
28901 SDCD
28902 B Delete all breakpoints if no arg 
28903 \newline
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 \InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 \InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 \InsetSpace ~
28928 \InsetSpace ~
28929 \InsetSpace ~
28930 \InsetSpace ~
28931 \InsetSpace ~
28932 \InsetSpace ~
28933 \InsetSpace ~
28934 \InsetSpace ~
28935 \InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 \InsetSpace ~
28940 \InsetSpace ~
28941 \InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 \InsetSpace ~
28945 \InsetSpace ~
28946 \InsetSpace ~
28947 \InsetSpace ~
28948 \InsetSpace ~
28949 \InsetSpace ~
28950 \InsetSpace ~
28951 given or delete arg (C-u arg x) 
28952 \newline
28953 ;;\InsetSpace ~
28954 m\InsetSpace ~
28955 \InsetSpace ~
28956 \InsetSpace ~
28957 \InsetSpace ~
28958 \InsetSpace ~
28959 \InsetSpace ~
28960 \InsetSpace ~
28961 \InsetSpace ~
28962 \InsetSpace ~
28963 \InsetSpace ~
28964 \InsetSpace ~
28965 \InsetSpace ~
28966 \InsetSpace ~
28967 \InsetSpace ~
28968 \InsetSpace ~
28969 sdcdbsrc
28970 -frame\InsetSpace ~
28971 \InsetSpace ~
28972 \InsetSpace ~
28973 \InsetSpace ~
28974 \InsetSpace ~
28975 \InsetSpace ~
28976 \InsetSpace ~
28977 \InsetSpace ~
28978 \InsetSpace ~
28979 \InsetSpace ~
28980 \InsetSpace ~
28981 \InsetSpace ~
28982 \InsetSpace ~
28983 \InsetSpace ~
28984 \InsetSpace ~
28985 SDCDB Display current frame if no arg, 
28986 \newline
28987 ;;\InsetSpace ~
28988 \InsetSpace ~
28989 \InsetSpace ~
28990 \InsetSpace ~
28991 \InsetSpace ~
28992 \InsetSpace ~
28993 \InsetSpace ~
28994 \InsetSpace ~
28995 \InsetSpace ~
28996 \InsetSpace ~
28997 \InsetSpace ~
28998 \InsetSpace ~
28999 \InsetSpace ~
29000 \InsetSpace ~
29001 \InsetSpace ~
29002 \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 \InsetSpace ~
29021 \InsetSpace ~
29022 \InsetSpace ~
29023 \InsetSpace ~
29024 \InsetSpace ~
29025 \InsetSpace ~
29026 \InsetSpace ~
29027 \InsetSpace ~
29028 \InsetSpace ~
29029 \InsetSpace ~
29030 \InsetSpace ~
29031 \InsetSpace ~
29032 \InsetSpace ~
29033 \InsetSpace ~
29034 given or display frame arg
29035  
29036 \newline
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 \InsetSpace ~
29052 \InsetSpace ~
29053 \InsetSpace ~
29054 \InsetSpace ~
29055 \InsetSpace ~
29056 \InsetSpace ~
29057 \InsetSpace ~
29058 \InsetSpace ~
29059 \InsetSpace ~
29060 \InsetSpace ~
29061 \InsetSpace ~
29062 \InsetSpace ~
29063 \InsetSpace ~
29064 \InsetSpace ~
29065 \InsetSpace ~
29066 \InsetSpace ~
29067 \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 \InsetSpace ~
29081 \InsetSpace ~
29082 \InsetSpace ~
29083 \InsetSpace ~
29084 buffer point 
29085 \newline
29086 ;;\InsetSpace ~
29087 !\InsetSpace ~
29088 \InsetSpace ~
29089 \InsetSpace ~
29090 \InsetSpace ~
29091 \InsetSpace ~
29092 \InsetSpace ~
29093 \InsetSpace ~
29094 \InsetSpace ~
29095 \InsetSpace ~
29096 \InsetSpace ~
29097 \InsetSpace ~
29098 \InsetSpace ~
29099 \InsetSpace ~
29100 \InsetSpace ~
29101 \InsetSpace ~
29102 sdcdbsrc-goto-sdcdb\InsetSpace ~
29103 \InsetSpace ~
29104 \InsetSpace ~
29105 \InsetSpace ~
29106 \InsetSpace ~
29107 \InsetSpace ~
29108 \InsetSpace ~
29109 \InsetSpace ~
29110 \InsetSpace ~
29111 \InsetSpace ~
29112 Goto the SDCDB output buffer 
29113 \newline
29114 ;;\InsetSpace ~
29115 p\InsetSpace ~
29116 \InsetSpace ~
29117 \InsetSpace ~
29118 \InsetSpace ~
29119 \InsetSpace ~
29120 \InsetSpace ~
29121 \InsetSpace ~
29122 \InsetSpace ~
29123 \InsetSpace ~
29124 \InsetSpace ~
29125 \InsetSpace ~
29126 \InsetSpace ~
29127 \InsetSpace ~
29128 \InsetSpace ~
29129 \InsetSpace ~
29130 sdcdb-prin
29131 t-c-sexp\InsetSpace ~
29132 \InsetSpace ~
29133 \InsetSpace ~
29134 \InsetSpace ~
29135 \InsetSpace ~
29136 \InsetSpace ~
29137 \InsetSpace ~
29138 \InsetSpace ~
29139 \InsetSpace ~
29140 \InsetSpace ~
29141 \InsetSpace ~
29142 SDCDB print command for data at 
29143 \newline
29144 ;;\InsetSpace ~
29145 \InsetSpace ~
29146 \InsetSpace ~
29147 \InsetSpace ~
29148 \InsetSpace ~
29149 \InsetSpace ~
29150 \InsetSpace ~
29151 \InsetSpace ~
29152 \InsetSpace ~
29153 \InsetSpace ~
29154 \InsetSpace ~
29155 \InsetSpace ~
29156 \InsetSpace ~
29157 \InsetSpace ~
29158 \InsetSpace ~
29159 \InsetSpace ~
29160 \InsetSpace ~
29161 \InsetSpace ~
29162 \InsetSpace ~
29163 \InsetSpace ~
29164 \InsetSpace ~
29165 \InsetSpace ~
29166 \InsetSpace ~
29167 \InsetSpace ~
29168 \InsetSpace ~
29169 \InsetSpace ~
29170 \InsetSpace ~
29171 \InsetSpace ~
29172 \InsetSpace ~
29173 \InsetSpace ~
29174 \InsetSpace ~
29175 \InsetSpace ~
29176 \InsetSpace ~
29177 \InsetSpace ~
29178 \InsetSpace ~
29179 \InsetSpace ~
29180 \InsetSpace ~
29181 \InsetSpace ~
29182 \InsetSpace ~
29183 \InsetSpace ~
29184 \InsetSpace ~
29185 \InsetSpace ~
29186 \InsetSpace ~
29187 \InsetSpace ~
29188 \InsetSpace ~
29189 \InsetSpace ~
29190 \InsetSpace ~
29191 buffer point 
29192 \newline
29193 ;;\InsetSpace ~
29194 g\InsetSpace ~
29195 \InsetSpace ~
29196 \InsetSpace ~
29197 \InsetSpace ~
29198 \InsetSpace ~
29199 \InsetSpace ~
29200 \InsetSpace ~
29201 \InsetSpace ~
29202 \InsetSpace ~
29203 \InsetSpace ~
29204 \InsetSpace ~
29205 \InsetSpace ~
29206 \InsetSpace ~
29207 \InsetSpace ~
29208 \InsetSpace ~
29209 sdcdbsrc-goto-sdcdb\InsetSpace ~
29210 \InsetSpace ~
29211 \InsetSpace ~
29212 \InsetSpace ~
29213 \InsetSpace ~
29214 \InsetSpace ~
29215 \InsetSpace ~
29216 \InsetSpace ~
29217 \InsetSpace ~
29218 \InsetSpace ~
29219 Got
29220 o the SDCDB output buffer 
29221 \newline
29222 ;;\InsetSpace ~
29223 t\InsetSpace ~
29224 \InsetSpace ~
29225 \InsetSpace ~
29226 \InsetSpace ~
29227 \InsetSpace ~
29228 \InsetSpace ~
29229 \InsetSpace ~
29230 \InsetSpace ~
29231 \InsetSpace ~
29232 \InsetSpace ~
29233 \InsetSpace ~
29234 \InsetSpace ~
29235 \InsetSpace ~
29236 \InsetSpace ~
29237 \InsetSpace ~
29238 sdcdbsrc-mode\InsetSpace ~
29239 \InsetSpace ~
29240 \InsetSpace ~
29241 \InsetSpace ~
29242 \InsetSpace ~
29243 \InsetSpace ~
29244 \InsetSpace ~
29245 \InsetSpace ~
29246 \InsetSpace ~
29247 \InsetSpace ~
29248 \InsetSpace ~
29249 \InsetSpace ~
29250 \InsetSpace ~
29251 \InsetSpace ~
29252 \InsetSpace ~
29253 \InsetSpace ~
29254 Toggles Sdcdbsrc mode (turns it
29255  off) 
29256 \newline
29257 ;; 
29258 \newline
29259 ;;\InsetSpace ~
29260 C-c\InsetSpace ~
29261 C-f\InsetSpace ~
29262 \InsetSpace ~
29263 \InsetSpace ~
29264 \InsetSpace ~
29265 \InsetSpace ~
29266 \InsetSpace ~
29267 \InsetSpace ~
29268 \InsetSpace ~
29269 \InsetSpace ~
29270 sdcdb-finish-from-src\InsetSpace ~
29271 \InsetSpace ~
29272 \InsetSpace ~
29273 \InsetSpace ~
29274 \InsetSpace ~
29275 \InsetSpace ~
29276 \InsetSpace ~
29277 \InsetSpace ~
29278 SDCDB finish command 
29279 \newline
29280 ;; 
29281 \newline
29282 ;;\InsetSpace ~
29283 C-x\InsetSpace ~
29284 SPC\InsetSpace ~
29285 \InsetSpace ~
29286 \InsetSpace ~
29287 \InsetSpace ~
29288 \InsetSpace ~
29289 \InsetSpace ~
29290 \InsetSpace ~
29291 \InsetSpace ~
29292 \InsetSpace ~
29293 sdcdb-brea
29294 k\InsetSpace ~
29295 \InsetSpace ~
29296 \InsetSpace ~
29297 \InsetSpace ~
29298 \InsetSpace ~
29299 \InsetSpace ~
29300 \InsetSpace ~
29301 \InsetSpace ~
29302 \InsetSpace ~
29303 \InsetSpace ~
29304 \InsetSpace ~
29305 \InsetSpace ~
29306 \InsetSpace ~
29307 \InsetSpace ~
29308 \InsetSpace ~
29309 \InsetSpace ~
29310 \InsetSpace ~
29311 \InsetSpace ~
29312 Set break for line with point 
29313 \newline
29314 ;;\InsetSpace ~
29315 ESC\InsetSpace ~
29316 t\InsetSpace ~
29317 \InsetSpace ~
29318 \InsetSpace ~
29319 \InsetSpace ~
29320 \InsetSpace ~
29321 \InsetSpace ~
29322 \InsetSpace ~
29323 \InsetSpace ~
29324 \InsetSpace ~
29325 \InsetSpace ~
29326 \InsetSpace ~
29327 sdcdbsrc-mode\InsetSpace ~
29328 \InsetSpace ~
29329 \InsetSpace ~
29330 \InsetSpace ~
29331 \InsetSpace ~
29332 \InsetSpace ~
29333 \InsetSpace ~
29334 \InsetSpace ~
29335 \InsetSpace ~
29336 \InsetSpace ~
29337 \InsetSpace ~
29338 \InsetSpace ~
29339 \InsetSpace ~
29340 \InsetSpace ~
29341 \InsetSpace ~
29342 \InsetSpace ~
29343 Toggle Sdcdbsrc mode 
29344 \newline
29345 ;;\InsetSpace ~
29346 ESC\InsetSpace ~
29347 m\InsetSpace ~
29348 \InsetSpace ~
29349 \InsetSpace ~
29350 \InsetSpace ~
29351 \InsetSpace ~
29352 \InsetSpace ~
29353 \InsetSpace ~
29354 \InsetSpace ~
29355 \InsetSpace ~
29356 \InsetSpace ~
29357 \InsetSpace ~
29358 sdc
29359 dbsrc-srcmode\InsetSpace ~
29360 \InsetSpace ~
29361 \InsetSpace ~
29362 \InsetSpace ~
29363 \InsetSpace ~
29364 \InsetSpace ~
29365 \InsetSpace ~
29366 \InsetSpace ~
29367 \InsetSpace ~
29368 \InsetSpace ~
29369 \InsetSpace ~
29370 \InsetSpace ~
29371 \InsetSpace ~
29372 Toggle list mode 
29373 \newline
29374 ;; 
29375 \newline
29376
29377 \family default
29378
29379 \newpage
29380
29381 \end_layout
29382
29383 \begin_layout Chapter
29384 TIPS
29385 \end_layout
29386
29387 \begin_layout Standard
29388 Here are a few guidelines that will help the compiler generate more efficient
29389  code, some of the tips are specific to this compiler others are generally
29390  good programming practice.
29391 \end_layout
29392
29393 \begin_layout Itemize
29394 Use the smallest data type to represent your data-value.
29395  If it is known in advance that the value is going to be less than 256 then
29396  use an 'unsigned char' instead of a 'short' or 'int'.
29397  Please note, that ANSI C requires both signed and unsigned chars to be
29398  promoted to 'signed int'
29399 \begin_inset LatexCommand \index{promotion to signed int}
29400
29401 \end_inset
29402
29403
29404 \begin_inset Marginal
29405 status collapsed
29406
29407 \begin_layout Standard
29408
29409 \series bold
29410 \InsetSpace ~
29411 !
29412 \end_layout
29413
29414 \end_inset
29415
29416  before doing any operation.
29417  This promotion
29418 \begin_inset LatexCommand \index{type promotion}
29419
29420 \end_inset
29421
29422
29423 \begin_inset LatexCommand \label{type promotion}
29424
29425 \end_inset
29426
29427  can be omitted, if the result is the same.
29428  The effect of the promotion rules together with the sign-extension is often
29429  surprising:
29430 \end_layout
29431
29432 \begin_deeper
29433 \begin_layout Verse
29434
29435 \family typewriter
29436 unsigned char uc = 0xfe;
29437 \newline
29438 if (uc * uc < 0) /* this is true! */
29439 \newline
29440 {
29441 \newline
29442 \InsetSpace ~
29443 \InsetSpace ~
29444 \InsetSpace ~
29445 \InsetSpace ~
29446 ....
29447 \newline
29448 }
29449 \end_layout
29450
29451 \begin_layout Standard
29452
29453 \family typewriter
29454 uc * uc
29455 \family default
29456  is evaluated as 
29457 \family typewriter
29458 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29459 \family default
29460 .
29461  
29462 \newline
29463 Another one:
29464 \end_layout
29465
29466 \begin_layout Verse
29467
29468 \family typewriter
29469 (unsigned char) -12 / (signed char) -3 = ...
29470 \end_layout
29471
29472 \begin_layout Standard
29473 No, the result is not 4:
29474 \end_layout
29475
29476 \begin_layout Verse
29477
29478 \family typewriter
29479 (int) (unsigned char) -12 / (int) (signed char) -3 =
29480 \newline
29481 (int) (unsigned char)
29482  0xf4 / (int) (signed char) 0xfd =
29483 \newline
29484 (int) 0x00f4 / (int) 0xfffd =
29485 \newline
29486 (int) 0x00f4
29487  / (int) 0xfffd =
29488 \newline
29489 (int) 244 / (int) -3 =
29490 \newline
29491 (int) -81 = (int) 0xffaf;
29492 \end_layout
29493
29494 \begin_layout Standard
29495 Don't complain, that gcc gives you a different result.
29496  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29497  Therefore the results are different.
29498 \newline
29499 From 
29500 \begin_inset Quotes sld
29501 \end_inset
29502
29503 comp.lang.c FAQ
29504 \begin_inset Quotes srd
29505 \end_inset
29506
29507 :
29508 \end_layout
29509
29510 \begin_layout Quote
29511
29512 \emph on
29513 If well-defined overflow characteristics are important and negative values
29514  are not, or if you want to steer clear of sign-extension problems when
29515  manipulating bits or bytes, use one of the corresponding unsigned types.
29516  (Beware when mixing signed and unsigned values in expressions, though.)
29517 \newline
29518 Although
29519  character types (especially unsigned char) can be used as "tiny" integers,
29520  doing so is sometimes more trouble than it's worth, due to unpredictable
29521  sign extension and increased code size.
29522 \end_layout
29523
29524 \end_deeper
29525 \begin_layout Itemize
29526 Use unsigned when it is known in advance that the value is not going to
29527  be negative.
29528  This helps especially if you are doing division or multiplication, bit-shifting
29529  or are using an array index.
29530 \end_layout
29531
29532 \begin_layout Itemize
29533 NEVER jump into a LOOP.
29534 \end_layout
29535
29536 \begin_layout Itemize
29537 Declare the variables to be local
29538 \begin_inset LatexCommand \index{local variables}
29539
29540 \end_inset
29541
29542  whenever possible, especially loop control variables (induction).
29543 \end_layout
29544
29545 \begin_layout Itemize
29546 Have a look at the assembly listing to get a 
29547 \begin_inset Quotes sld
29548 \end_inset
29549
29550 feeling
29551 \begin_inset Quotes srd
29552 \end_inset
29553
29554  for the code generation.
29555 \end_layout
29556
29557 \begin_layout Section
29558 Porting code from or to other compilers
29559 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29560
29561 \end_inset
29562
29563
29564 \end_layout
29565
29566 \begin_layout Itemize
29567 check whether endianness of the compilers differs and adapt where needed.
29568 \end_layout
29569
29570 \begin_layout Itemize
29571 check the device specific header files
29572 \begin_inset LatexCommand \index{Header files}
29573
29574 \end_inset
29575
29576
29577 \begin_inset LatexCommand \index{Include files}
29578
29579 \end_inset
29580
29581  for compiler specific syntax.
29582  Eventually include the file <compiler.h
29583 \begin_inset LatexCommand \index{compiler.h (include file)}
29584
29585 \end_inset
29586
29587
29588 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29589
29590 \end_inset
29591
29592  to allow using common header files.
29593  (see f.e.
29594  cc2510fx.h 
29595 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29596
29597 \end_inset
29598
29599 ).
29600 \end_layout
29601
29602 \begin_layout Itemize
29603 check whether the startup code contains the correct initialization (watchdog,
29604  peripherals).
29605 \end_layout
29606
29607 \begin_layout Itemize
29608 check whether the sizes of short, int, long match.
29609 \end_layout
29610
29611 \begin_layout Itemize
29612 check if some 16 or 32 bit hardware registers require a specific addressing
29613  order (least significant or most significant byte first) and adapt if needed
29614  (
29615 \emph on
29616 first
29617 \emph default
29618  and 
29619 \emph on
29620 last
29621 \emph default
29622  relate to time and not to lower/upper memory location here, so this is
29623  
29624 \emph on
29625 not
29626 \emph default
29627  the same as endianness).
29628 \end_layout
29629
29630 \begin_layout Itemize
29631 check whether the keyword 
29632 \emph on
29633 volatile
29634 \emph default
29635  is used where needed.
29636  The compilers might differ in their optimization characteristics (as different
29637  versions of the same compiler might also use more clever optimizations
29638  this is good idea anyway).
29639  See section 
29640 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29641
29642 \end_inset
29643
29644 .
29645 \end_layout
29646
29647 \begin_layout Itemize
29648 check that the compilers are not told to supress warnings.
29649 \end_layout
29650
29651 \begin_layout Itemize
29652 check and convert compiler specific extensions (interrupts, memory areas,
29653  pragmas etc.).
29654 \end_layout
29655
29656 \begin_layout Itemize
29657 check for differences in type promotion.
29658  Especially check for math operations on 
29659 \family typewriter
29660 char
29661 \family default
29662  or 
29663 \family typewriter
29664 unsigned char
29665 \family default
29666  variables.
29667  For the sake of C99 compatibility SDCC will probably promote these to 
29668 \family typewriter
29669 int
29670 \family default
29671  more often than other compilers.
29672  Eventually insert explicit casts to 
29673 \family typewriter
29674 (char) 
29675 \family default
29676 or
29677 \family typewriter
29678  (unsigned char)
29679 \family default
29680 .
29681  Also check that the ~\InsetSpace ~
29682 operator
29683 \begin_inset LatexCommand \index{\~\/ Operator}
29684
29685 \end_inset
29686
29687  is not used on 
29688 \family typewriter
29689 bit
29690 \begin_inset LatexCommand \index{bit}
29691
29692 \end_inset
29693
29694
29695 \family default
29696  variables, use the !\InsetSpace ~
29697 operator instead.
29698  See sections 
29699 \begin_inset LatexCommand \ref{type promotion}
29700
29701 \end_inset
29702
29703  and 
29704 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29705
29706 \end_inset
29707
29708 .
29709 \end_layout
29710
29711 \begin_layout Itemize
29712 check the assembly code generated for interrupt routines (f.e.
29713  for calls to possibly non-reentrant library functions).
29714 \end_layout
29715
29716 \begin_layout Itemize
29717 check whether timing loops result in proper timing (or preferably consider
29718  a rewrite of the code with timer based delays instead).
29719 \end_layout
29720
29721 \begin_layout Itemize
29722 check for differences in printf parameters (some compilers push (va_arg
29723 \begin_inset LatexCommand \index{vararg, va\_arg}
29724
29725 \end_inset
29726
29727 ) char variables as 
29728 \family typewriter
29729 int
29730 \family default
29731  others push them as 
29732 \family typewriter
29733 char
29734 \family default
29735 .
29736  See section 
29737 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29738
29739 \end_inset
29740
29741 ).
29742 \end_layout
29743
29744 \begin_layout Itemize
29745 check the resulting memory map
29746 \begin_inset LatexCommand \index{Memory map}
29747
29748 \end_inset
29749
29750 .
29751  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29752 ly idata, pdata, xdata).
29753  Eventually check if unexpected library functions are included.
29754 \end_layout
29755
29756 \begin_layout Section
29757 Tools
29758 \begin_inset LatexCommand \index{Tools}
29759
29760 \end_inset
29761
29762  included in the distribution
29763 \end_layout
29764
29765 \begin_layout Standard
29766 \align left
29767 \begin_inset Tabular
29768 <lyxtabular version="3" rows="12" columns="3">
29769 <features>
29770 <column alignment="left" valignment="top" leftline="true" width="0pt">
29771 <column alignment="left" valignment="top" leftline="true" width="0pt">
29772 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29773 <row topline="true" bottomline="true">
29774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29775 \begin_inset Text
29776
29777 \begin_layout Standard
29778
29779 \series bold
29780 Name
29781 \end_layout
29782
29783 \end_inset
29784 </cell>
29785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29786 \begin_inset Text
29787
29788 \begin_layout Standard
29789
29790 \series bold
29791 Purpose
29792 \end_layout
29793
29794 \end_inset
29795 </cell>
29796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29797 \begin_inset Text
29798
29799 \begin_layout Standard
29800
29801 \series bold
29802 Directory
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 uCsim
29814 \begin_inset LatexCommand \index{uCsim}
29815
29816 \end_inset
29817
29818
29819 \end_layout
29820
29821 \end_inset
29822 </cell>
29823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29824 \begin_inset Text
29825
29826 \begin_layout Standard
29827 Simulator for various architectures
29828 \end_layout
29829
29830 \end_inset
29831 </cell>
29832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29833 \begin_inset Text
29834
29835 \begin_layout Standard
29836 sdcc/sim/ucsim
29837 \end_layout
29838
29839 \end_inset
29840 </cell>
29841 </row>
29842 <row topline="true">
29843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29844 \begin_inset Text
29845
29846 \begin_layout Standard
29847 keil2sdcc.pl
29848 \end_layout
29849
29850 \end_inset
29851 </cell>
29852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29853 \begin_inset Text
29854
29855 \begin_layout Standard
29856 header file
29857 \begin_inset LatexCommand \index{Header files}
29858
29859 \end_inset
29860
29861
29862 \begin_inset LatexCommand \index{Include files}
29863
29864 \end_inset
29865
29866  conversion
29867 \end_layout
29868
29869 \end_inset
29870 </cell>
29871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29872 \begin_inset Text
29873
29874 \begin_layout Standard
29875 sdcc/support/scripts
29876 \end_layout
29877
29878 \end_inset
29879 </cell>
29880 </row>
29881 <row topline="true">
29882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29883 \begin_inset Text
29884
29885 \begin_layout Standard
29886 mh2h.c
29887 \end_layout
29888
29889 \end_inset
29890 </cell>
29891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29892 \begin_inset Text
29893
29894 \begin_layout Standard
29895 header file conversion
29896 \end_layout
29897
29898 \end_inset
29899 </cell>
29900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29901 \begin_inset Text
29902
29903 \begin_layout Standard
29904 sdcc/support/scripts
29905 \end_layout
29906
29907 \end_inset
29908 </cell>
29909 </row>
29910 <row topline="true">
29911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29912 \begin_inset Text
29913
29914 \begin_layout Standard
29915 as-gbz80
29916 \end_layout
29917
29918 \end_inset
29919 </cell>
29920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29921 \begin_inset Text
29922
29923 \begin_layout Standard
29924 Assembler
29925 \end_layout
29926
29927 \end_inset
29928 </cell>
29929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29930 \begin_inset Text
29931
29932 \begin_layout Standard
29933
29934 \family roman
29935 \series medium
29936 \shape up
29937 \size normal
29938 \emph off
29939 \bar no
29940 \noun off
29941 \color none
29942 sdcc/bin
29943 \end_layout
29944
29945 \end_inset
29946 </cell>
29947 </row>
29948 <row topline="true">
29949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29950 \begin_inset Text
29951
29952 \begin_layout Standard
29953 as-z80
29954 \end_layout
29955
29956 \end_inset
29957 </cell>
29958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29959 \begin_inset Text
29960
29961 \begin_layout Standard
29962 Assembler
29963 \end_layout
29964
29965 \end_inset
29966 </cell>
29967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29968 \begin_inset Text
29969
29970 \begin_layout Standard
29971
29972 \family roman
29973 \series medium
29974 \shape up
29975 \size normal
29976 \emph off
29977 \bar no
29978 \noun off
29979 \color none
29980 sdcc/bin
29981 \end_layout
29982
29983 \end_inset
29984 </cell>
29985 </row>
29986 <row topline="true">
29987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29988 \begin_inset Text
29989
29990 \begin_layout Standard
29991 asx8051
29992 \end_layout
29993
29994 \end_inset
29995 </cell>
29996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29997 \begin_inset Text
29998
29999 \begin_layout Standard
30000 Assembler
30001 \end_layout
30002
30003 \end_inset
30004 </cell>
30005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30006 \begin_inset Text
30007
30008 \begin_layout Standard
30009
30010 \family roman
30011 \series medium
30012 \shape up
30013 \size normal
30014 \emph off
30015 \bar no
30016 \noun off
30017 \color none
30018 sdcc/bin
30019 \end_layout
30020
30021 \end_inset
30022 </cell>
30023 </row>
30024 <row topline="true">
30025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30026 \begin_inset Text
30027
30028 \begin_layout Standard
30029 SDCDB
30030 \end_layout
30031
30032 \end_inset
30033 </cell>
30034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30035 \begin_inset Text
30036
30037 \begin_layout Standard
30038 Simulator
30039 \end_layout
30040
30041 \end_inset
30042 </cell>
30043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30044 \begin_inset Text
30045
30046 \begin_layout Standard
30047
30048 \family roman
30049 \series medium
30050 \shape up
30051 \size normal
30052 \emph off
30053 \bar no
30054 \noun off
30055 \color none
30056 sdcc/bin
30057 \end_layout
30058
30059 \end_inset
30060 </cell>
30061 </row>
30062 <row topline="true">
30063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30064 \begin_inset Text
30065
30066 \begin_layout Standard
30067 aslink
30068 \end_layout
30069
30070 \end_inset
30071 </cell>
30072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30073 \begin_inset Text
30074
30075 \begin_layout Standard
30076 Linker
30077 \end_layout
30078
30079 \end_inset
30080 </cell>
30081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30082 \begin_inset Text
30083
30084 \begin_layout Standard
30085
30086 \family roman
30087 \series medium
30088 \shape up
30089 \size normal
30090 \emph off
30091 \bar no
30092 \noun off
30093 \color none
30094 sdcc/bin
30095 \end_layout
30096
30097 \end_inset
30098 </cell>
30099 </row>
30100 <row topline="true">
30101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30102 \begin_inset Text
30103
30104 \begin_layout Standard
30105 link-z80
30106 \end_layout
30107
30108 \end_inset
30109 </cell>
30110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30111 \begin_inset Text
30112
30113 \begin_layout Standard
30114 Linker
30115 \end_layout
30116
30117 \end_inset
30118 </cell>
30119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30120 \begin_inset Text
30121
30122 \begin_layout Standard
30123
30124 \family roman
30125 \series medium
30126 \shape up
30127 \size normal
30128 \emph off
30129 \bar no
30130 \noun off
30131 \color none
30132 sdcc/bin
30133 \end_layout
30134
30135 \end_inset
30136 </cell>
30137 </row>
30138 <row topline="true">
30139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30140 \begin_inset Text
30141
30142 \begin_layout Standard
30143 link-gbz80
30144 \end_layout
30145
30146 \end_inset
30147 </cell>
30148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30149 \begin_inset Text
30150
30151 \begin_layout Standard
30152 Linker
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
30162 \family roman
30163 \series medium
30164 \shape up
30165 \size normal
30166 \emph off
30167 \bar no
30168 \noun off
30169 \color none
30170 sdcc/bin
30171 \end_layout
30172
30173 \end_inset
30174 </cell>
30175 </row>
30176 <row topline="true" bottomline="true">
30177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30178 \begin_inset Text
30179
30180 \begin_layout Standard
30181 packihx
30182 \end_layout
30183
30184 \end_inset
30185 </cell>
30186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30187 \begin_inset Text
30188
30189 \begin_layout Standard
30190 Intel Hex packer 
30191 \begin_inset LatexCommand \index{packihx (tool)}
30192
30193 \end_inset
30194
30195
30196 \end_layout
30197
30198 \end_inset
30199 </cell>
30200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30201 \begin_inset Text
30202
30203 \begin_layout Standard
30204
30205 \family roman
30206 \series medium
30207 \shape up
30208 \size normal
30209 \emph off
30210 \bar no
30211 \noun off
30212 \color none
30213 sdcc/bin
30214 \end_layout
30215
30216 \end_inset
30217 </cell>
30218 </row>
30219 </lyxtabular>
30220
30221 \end_inset
30222
30223
30224 \newline
30225
30226 \end_layout
30227
30228 \begin_layout Section
30229 Documentation
30230 \begin_inset LatexCommand \index{Documentation}
30231
30232 \end_inset
30233
30234  included in the distribution
30235 \end_layout
30236
30237 \begin_layout Standard
30238 \align left
30239 \begin_inset Tabular
30240 <lyxtabular version="3" rows="10" columns="2">
30241 <features>
30242 <column alignment="block" valignment="top" leftline="true" width="40col%">
30243 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30244 <row topline="true" bottomline="true" endhead="true">
30245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30246 \begin_inset Text
30247
30248 \begin_layout Standard
30249
30250 \series bold
30251 Subject / Title
30252 \end_layout
30253
30254 \end_inset
30255 </cell>
30256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30257 \begin_inset Text
30258
30259 \begin_layout Standard
30260
30261 \series bold
30262 Filename / Where to get
30263 \end_layout
30264
30265 \end_inset
30266 </cell>
30267 </row>
30268 <row topline="true">
30269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30270 \begin_inset Text
30271
30272 \begin_layout Standard
30273 SDCC Compiler User Guide
30274 \end_layout
30275
30276 \end_inset
30277 </cell>
30278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30279 \begin_inset Text
30280
30281 \begin_layout Standard
30282 You're reading it right now
30283 \emph on
30284  \InsetSpace ~
30285 \InsetSpace ~
30286 \InsetSpace ~
30287
30288 \hfill
30289 online at:
30290 \emph default
30291
30292 \newline
30293
30294 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30295
30296 \end_inset
30297
30298
30299 \end_layout
30300
30301 \end_inset
30302 </cell>
30303 </row>
30304 <row topline="true">
30305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30306 \begin_inset Text
30307
30308 \begin_layout Standard
30309 Changelog of SDCC
30310 \end_layout
30311
30312 \end_inset
30313 </cell>
30314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30315 \begin_inset Text
30316
30317 \begin_layout Standard
30318 sdcc/Changelog
30319 \emph on
30320  \InsetSpace ~
30321 \InsetSpace ~
30322 \InsetSpace ~
30323
30324 \hfill
30325 online at:
30326 \emph default
30327
30328 \newline
30329
30330 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30331
30332 \end_inset
30333
30334
30335 \end_layout
30336
30337 \end_inset
30338 </cell>
30339 </row>
30340 <row topline="true">
30341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30342 \begin_inset Text
30343
30344 \begin_layout Standard
30345 ASXXXX
30346 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30347
30348 \end_inset
30349
30350
30351 \begin_inset LatexCommand \index{Assembler documentation}
30352
30353 \end_inset
30354
30355  Assemblers and
30356 \newline
30357 ASLINK
30358 \begin_inset LatexCommand \index{aslink}
30359
30360 \end_inset
30361
30362
30363 \begin_inset LatexCommand \index{Linker documentation}
30364
30365 \end_inset
30366
30367  Relocating Linker
30368 \end_layout
30369
30370 \end_inset
30371 </cell>
30372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30373 \begin_inset Text
30374
30375 \begin_layout Standard
30376 sdcc/as/doc/asxhtm.html 
30377 \emph on
30378 \InsetSpace ~
30379 \InsetSpace ~
30380 \InsetSpace ~
30381
30382 \hfill
30383 online at:
30384 \emph default
30385
30386 \newline
30387
30388 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30389
30390 \end_inset
30391
30392
30393 \end_layout
30394
30395 \end_inset
30396 </cell>
30397 </row>
30398 <row topline="true">
30399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30400 \begin_inset Text
30401
30402 \begin_layout Standard
30403 SDCC regression test
30404 \begin_inset LatexCommand \index{Regression test}
30405
30406 \end_inset
30407
30408
30409 \end_layout
30410
30411 \end_inset
30412 </cell>
30413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30414 \begin_inset Text
30415
30416 \begin_layout Standard
30417 sdcc/doc/test_suite_spec.pdf 
30418 \emph on
30419 \InsetSpace ~
30420 \InsetSpace ~
30421 \InsetSpace ~
30422
30423 \hfill
30424 online at:
30425 \emph default
30426
30427 \newline
30428
30429 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30430
30431 \end_inset
30432
30433
30434 \end_layout
30435
30436 \end_inset
30437 </cell>
30438 </row>
30439 <row topline="true">
30440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30441 \begin_inset Text
30442
30443 \begin_layout Standard
30444 Various notes
30445 \end_layout
30446
30447 \end_inset
30448 </cell>
30449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30450 \begin_inset Text
30451
30452 \begin_layout Standard
30453 sdcc/doc/* 
30454 \emph on
30455 \InsetSpace ~
30456 \InsetSpace ~
30457 \InsetSpace ~
30458
30459 \hfill
30460 online at:
30461 \emph default
30462
30463 \newline
30464
30465 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30466
30467 \end_inset
30468
30469
30470 \end_layout
30471
30472 \end_inset
30473 </cell>
30474 </row>
30475 <row topline="true">
30476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30477 \begin_inset Text
30478
30479 \begin_layout Standard
30480 Notes on debugging with SDCDB
30481 \begin_inset LatexCommand \index{SDCDB (debugger)}
30482
30483 \end_inset
30484
30485
30486 \end_layout
30487
30488 \end_inset
30489 </cell>
30490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30491 \begin_inset Text
30492
30493 \begin_layout Standard
30494 sdcc/debugger/README 
30495 \emph on
30496 \InsetSpace ~
30497 \InsetSpace ~
30498 \InsetSpace ~
30499
30500 \hfill
30501 online at
30502 \emph default
30503 :
30504 \newline
30505
30506 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30507
30508 \end_inset
30509
30510
30511 \end_layout
30512
30513 \end_inset
30514 </cell>
30515 </row>
30516 <row topline="true">
30517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30518 \begin_inset Text
30519
30520 \begin_layout Standard
30521 uCsim
30522 \begin_inset LatexCommand \index{uCsim}
30523
30524 \end_inset
30525
30526  Software simulator for microcontrollers
30527 \end_layout
30528
30529 \end_inset
30530 </cell>
30531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30532 \begin_inset Text
30533
30534 \begin_layout Standard
30535
30536 \family roman
30537 \series medium
30538 \shape up
30539 \size normal
30540 \emph off
30541 \bar no
30542 \noun off
30543 \color none
30544 sdcc/sim/ucsim/doc
30545 \family default
30546 \series default
30547 \shape default
30548 \size default
30549 \emph default
30550 \bar default
30551 \noun default
30552 /index.html 
30553 \emph on
30554 \InsetSpace ~
30555 \InsetSpace ~
30556 \InsetSpace ~
30557
30558 \hfill
30559 online at:
30560 \emph default
30561
30562 \newline
30563
30564 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30565
30566 \end_inset
30567
30568
30569 \end_layout
30570
30571 \end_inset
30572 </cell>
30573 </row>
30574 <row topline="true">
30575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30576 \begin_inset Text
30577
30578 \begin_layout Standard
30579 Temporary notes on the pic16
30580 \begin_inset LatexCommand \index{PIC16}
30581
30582 \end_inset
30583
30584  port
30585 \end_layout
30586
30587 \end_inset
30588 </cell>
30589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30590 \begin_inset Text
30591
30592 \begin_layout Standard
30593 sdcc/src/pic16/NOTES 
30594 \emph on
30595 \InsetSpace ~
30596 \InsetSpace ~
30597 \InsetSpace ~
30598
30599 \hfill
30600 online at:
30601 \newline
30602
30603 \emph default
30604
30605 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30606
30607 \end_inset
30608
30609
30610 \end_layout
30611
30612 \end_inset
30613 </cell>
30614 </row>
30615 <row topline="true" bottomline="true">
30616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30617 \begin_inset Text
30618
30619 \begin_layout Standard
30620 SDCC internal documentation (debugging file format)
30621 \end_layout
30622
30623 \end_inset
30624 </cell>
30625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30626 \begin_inset Text
30627
30628 \begin_layout Standard
30629 sdcc/doc/
30630 \family roman
30631 \series medium
30632 \shape up
30633 \size normal
30634 \emph off
30635 \bar no
30636 \noun off
30637 \color none
30638 cdbfileformat.pd
30639 \family default
30640 \series default
30641 \shape default
30642 \size default
30643 \emph default
30644 \bar default
30645 \noun default
30646 f
30647 \emph on
30648  \InsetSpace ~
30649 \InsetSpace ~
30650 \InsetSpace ~
30651
30652 \hfill
30653 online at:
30654 \emph default
30655
30656 \newline
30657
30658 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30659
30660 \end_inset
30661
30662
30663 \end_layout
30664
30665 \end_inset
30666 </cell>
30667 </row>
30668 </lyxtabular>
30669
30670 \end_inset
30671
30672
30673 \newline
30674
30675 \end_layout
30676
30677 \begin_layout Section
30678 Related open source tools
30679 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30680
30681 \end_inset
30682
30683
30684 \begin_inset LatexCommand \index{Related tools}
30685
30686 \end_inset
30687
30688
30689 \end_layout
30690
30691 \begin_layout Standard
30692 \align left
30693 \begin_inset Tabular
30694 <lyxtabular version="3" rows="14" columns="3">
30695 <features>
30696 <column alignment="left" valignment="top" leftline="true" width="0pt">
30697 <column alignment="block" valignment="top" leftline="true" width="30line%">
30698 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30699 <row topline="true" bottomline="true">
30700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30701 \begin_inset Text
30702
30703 \begin_layout Standard
30704
30705 \series bold
30706 Name
30707 \end_layout
30708
30709 \end_inset
30710 </cell>
30711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30712 \begin_inset Text
30713
30714 \begin_layout Standard
30715
30716 \series bold
30717 Purpose
30718 \end_layout
30719
30720 \end_inset
30721 </cell>
30722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30723 \begin_inset Text
30724
30725 \begin_layout Standard
30726
30727 \series bold
30728 Where to get
30729 \end_layout
30730
30731 \end_inset
30732 </cell>
30733 </row>
30734 <row topline="true">
30735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30736 \begin_inset Text
30737
30738 \begin_layout Standard
30739 gpsim
30740 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30741
30742 \end_inset
30743
30744
30745 \end_layout
30746
30747 \end_inset
30748 </cell>
30749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30750 \begin_inset Text
30751
30752 \begin_layout Standard
30753 PIC simulator
30754 \end_layout
30755
30756 \end_inset
30757 </cell>
30758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30759 \begin_inset Text
30760
30761 \begin_layout Standard
30762 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30763
30764 \end_inset
30765
30766
30767 \end_layout
30768
30769 \end_inset
30770 </cell>
30771 </row>
30772 <row topline="true">
30773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30774 \begin_inset Text
30775
30776 \begin_layout Standard
30777 gputils
30778 \begin_inset LatexCommand \index{gputils (pic tools)}
30779
30780 \end_inset
30781
30782
30783 \end_layout
30784
30785 \end_inset
30786 </cell>
30787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30788 \begin_inset Text
30789
30790 \begin_layout Standard
30791 GNU PIC utilities
30792 \end_layout
30793
30794 \end_inset
30795 </cell>
30796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30797 \begin_inset Text
30798
30799 \begin_layout Standard
30800 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30801
30802 \end_inset
30803
30804
30805 \end_layout
30806
30807 \end_inset
30808 </cell>
30809 </row>
30810 <row topline="true">
30811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30812 \begin_inset Text
30813
30814 \begin_layout Standard
30815 flP5
30816 \end_layout
30817
30818 \end_inset
30819 </cell>
30820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30821 \begin_inset Text
30822
30823 \begin_layout Standard
30824 PIC programmer
30825 \end_layout
30826
30827 \end_inset
30828 </cell>
30829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30830 \begin_inset Text
30831
30832 \begin_layout Standard
30833 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30834
30835 \end_inset
30836
30837
30838 \end_layout
30839
30840 \end_inset
30841 </cell>
30842 </row>
30843 <row topline="true">
30844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30845 \begin_inset Text
30846
30847 \begin_layout Standard
30848 ec2drv/newcdb
30849 \end_layout
30850
30851 \end_inset
30852 </cell>
30853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30854 \begin_inset Text
30855
30856 \begin_layout Standard
30857 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30858  (Unix only)
30859 \end_layout
30860
30861 \end_inset
30862 </cell>
30863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30864 \begin_inset Text
30865
30866 \begin_layout Standard
30867 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30868
30869 \end_inset
30870
30871
30872 \end_layout
30873
30874 \end_inset
30875 </cell>
30876 </row>
30877 <row topline="true">
30878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30879 \begin_inset Text
30880
30881 \begin_layout Standard
30882 indent
30883 \begin_inset LatexCommand \index{indent (source formatting tool)}
30884
30885 \end_inset
30886
30887
30888 \end_layout
30889
30890 \end_inset
30891 </cell>
30892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30893 \begin_inset Text
30894
30895 \begin_layout Standard
30896 Formats C source - Master of the white spaces
30897 \end_layout
30898
30899 \end_inset
30900 </cell>
30901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30902 \begin_inset Text
30903
30904 \begin_layout Standard
30905 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30906
30907 \end_inset
30908
30909
30910 \end_layout
30911
30912 \end_inset
30913 </cell>
30914 </row>
30915 <row topline="true">
30916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30917 \begin_inset Text
30918
30919 \begin_layout Standard
30920 srecord
30921 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30922
30923 \end_inset
30924
30925
30926 \end_layout
30927
30928 \end_inset
30929 </cell>
30930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30931 \begin_inset Text
30932
30933 \begin_layout Standard
30934 Object file conversion, checksumming, ...
30935 \end_layout
30936
30937 \end_inset
30938 </cell>
30939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30940 \begin_inset Text
30941
30942 \begin_layout Standard
30943 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30944
30945 \end_inset
30946
30947
30948 \end_layout
30949
30950 \end_inset
30951 </cell>
30952 </row>
30953 <row topline="true">
30954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30955 \begin_inset Text
30956
30957 \begin_layout Standard
30958 objdump
30959 \begin_inset LatexCommand \index{objdump (tool)}
30960
30961 \end_inset
30962
30963
30964 \end_layout
30965
30966 \end_inset
30967 </cell>
30968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30969 \begin_inset Text
30970
30971 \begin_layout Standard
30972 Object file conversion, ...
30973 \end_layout
30974
30975 \end_inset
30976 </cell>
30977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30978 \begin_inset Text
30979
30980 \begin_layout Standard
30981 Part of binutils (should be there anyway)
30982 \end_layout
30983
30984 \end_inset
30985 </cell>
30986 </row>
30987 <row topline="true">
30988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30989 \begin_inset Text
30990
30991 \begin_layout Standard
30992 cmon51
30993 \end_layout
30994
30995 \end_inset
30996 </cell>
30997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30998 \begin_inset Text
30999
31000 \begin_layout Standard
31001 8051 monitor (hex up-/download, single step, disassemble)
31002 \end_layout
31003
31004 \end_inset
31005 </cell>
31006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31007 \begin_inset Text
31008
31009 \begin_layout Standard
31010 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31011
31012 \end_inset
31013
31014
31015 \end_layout
31016
31017 \end_inset
31018 </cell>
31019 </row>
31020 <row topline="true">
31021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31022 \begin_inset Text
31023
31024 \begin_layout Standard
31025 doxygen
31026 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31027
31028 \end_inset
31029
31030
31031 \end_layout
31032
31033 \end_inset
31034 </cell>
31035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31036 \begin_inset Text
31037
31038 \begin_layout Standard
31039 Source code documentation system
31040 \end_layout
31041
31042 \end_inset
31043 </cell>
31044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31045 \begin_inset Text
31046
31047 \begin_layout Standard
31048 \begin_inset LatexCommand \url{http://www.doxygen.org}
31049
31050 \end_inset
31051
31052
31053 \end_layout
31054
31055 \end_inset
31056 </cell>
31057 </row>
31058 <row topline="true">
31059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31060 \begin_inset Text
31061
31062 \begin_layout Standard
31063 kdevelop
31064 \end_layout
31065
31066 \end_inset
31067 </cell>
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31069 \begin_inset Text
31070
31071 \begin_layout Standard
31072 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31073 \end_layout
31074
31075 \end_inset
31076 </cell>
31077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31078 \begin_inset Text
31079
31080 \begin_layout Standard
31081 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31082
31083 \end_inset
31084
31085
31086 \end_layout
31087
31088 \end_inset
31089 </cell>
31090 </row>
31091 <row topline="true">
31092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31093 \begin_inset Text
31094
31095 \begin_layout Standard
31096 paulmon
31097 \end_layout
31098
31099 \end_inset
31100 </cell>
31101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31102 \begin_inset Text
31103
31104 \begin_layout Standard
31105 8051 monitor (hex up-/download, single step, disassemble)
31106 \end_layout
31107
31108 \end_inset
31109 </cell>
31110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31111 \begin_inset Text
31112
31113 \begin_layout Standard
31114 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31115
31116 \end_inset
31117
31118
31119 \end_layout
31120
31121 \end_inset
31122 </cell>
31123 </row>
31124 <row topline="true">
31125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31126 \begin_inset Text
31127
31128 \begin_layout Standard
31129 splint
31130 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31131
31132 \end_inset
31133
31134
31135 \end_layout
31136
31137 \end_inset
31138 </cell>
31139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31140 \begin_inset Text
31141
31142 \begin_layout Standard
31143 Statically checks c sources (see 
31144 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31145
31146 \end_inset
31147
31148 )
31149 \end_layout
31150
31151 \end_inset
31152 </cell>
31153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31154 \begin_inset Text
31155
31156 \begin_layout Standard
31157 \begin_inset LatexCommand \url{http://www.splint.org}
31158
31159 \end_inset
31160
31161
31162 \end_layout
31163
31164 \end_inset
31165 </cell>
31166 </row>
31167 <row topline="true" bottomline="true">
31168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31169 \begin_inset Text
31170
31171 \begin_layout Standard
31172 ddd
31173 \begin_inset LatexCommand \index{DDD (debugger)}
31174
31175 \end_inset
31176
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 Debugger, serves nicely as GUI to SDCDB
31187 \begin_inset LatexCommand \index{SDCDB (debugger)}
31188
31189 \end_inset
31190
31191  (Unix only)
31192 \end_layout
31193
31194 \end_inset
31195 </cell>
31196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31197 \begin_inset Text
31198
31199 \begin_layout Standard
31200 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31201
31202 \end_inset
31203
31204
31205 \end_layout
31206
31207 \end_inset
31208 </cell>
31209 </row>
31210 </lyxtabular>
31211
31212 \end_inset
31213
31214
31215 \newline
31216
31217 \end_layout
31218
31219 \begin_layout Section
31220 Related documentation / recommended reading
31221 \end_layout
31222
31223 \begin_layout Standard
31224 \align left
31225 \begin_inset Tabular
31226 <lyxtabular version="3" rows="7" columns="3">
31227 <features>
31228 <column alignment="left" valignment="top" leftline="true" width="0pt">
31229 <column alignment="left" valignment="top" leftline="true" width="0">
31230 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31231 <row topline="true" bottomline="true">
31232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31233 \begin_inset Text
31234
31235 \begin_layout Standard
31236
31237 \series bold
31238 Name
31239 \end_layout
31240
31241 \end_inset
31242 </cell>
31243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31244 \begin_inset Text
31245
31246 \begin_layout Standard
31247
31248 \series bold
31249 Subject / Title
31250 \end_layout
31251
31252 \end_inset
31253 </cell>
31254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31255 \begin_inset Text
31256
31257 \begin_layout Standard
31258
31259 \series bold
31260 Where to get
31261 \end_layout
31262
31263 \end_inset
31264 </cell>
31265 </row>
31266 <row topline="true">
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31268 \begin_inset Text
31269
31270 \begin_layout Standard
31271
31272 \family roman
31273 \series medium
31274 \shape up
31275 \size normal
31276 \emph off
31277 \bar no
31278 \noun off
31279 \color none
31280 c-refcard.pdf
31281 \end_layout
31282
31283 \end_inset
31284 </cell>
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31286 \begin_inset Text
31287
31288 \begin_layout Standard
31289 C Reference Card
31290 \begin_inset LatexCommand \index{C Reference card}
31291
31292 \end_inset
31293
31294 , 2 pages
31295 \end_layout
31296
31297 \end_inset
31298 </cell>
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31300 \begin_inset Text
31301
31302 \begin_layout Standard
31303 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31304
31305 \end_inset
31306
31307
31308 \end_layout
31309
31310 \end_inset
31311 </cell>
31312 </row>
31313 <row topline="true">
31314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31315 \begin_inset Text
31316
31317 \begin_layout Standard
31318 c-faq
31319 \end_layout
31320
31321 \end_inset
31322 </cell>
31323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31324 \begin_inset Text
31325
31326 \begin_layout Standard
31327 C-FAQ
31328 \begin_inset LatexCommand \index{C FAQ}
31329
31330 \end_inset
31331
31332
31333 \end_layout
31334
31335 \end_inset
31336 </cell>
31337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31338 \begin_inset Text
31339
31340 \begin_layout Standard
31341 \begin_inset LatexCommand \url{http://www.c-faq.com}
31342
31343 \end_inset
31344
31345
31346 \end_layout
31347
31348 \end_inset
31349 </cell>
31350 </row>
31351 <row topline="true">
31352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31353 \begin_inset Text
31354
31355 \begin_layout Standard
31356 ISO/IEC 9899:TC2
31357 \end_layout
31358
31359 \end_inset
31360 </cell>
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31362 \begin_inset Text
31363
31364 \begin_layout Standard
31365 \begin_inset Quotes sld
31366 \end_inset
31367
31368 C-Standard
31369 \begin_inset Quotes srd
31370 \end_inset
31371
31372
31373 \end_layout
31374
31375 \end_inset
31376 </cell>
31377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31378 \begin_inset Text
31379
31380 \begin_layout Standard
31381
31382 \size footnotesize
31383 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31384
31385 \end_inset
31386
31387
31388 \end_layout
31389
31390 \end_inset
31391 </cell>
31392 </row>
31393 <row topline="true">
31394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31395 \begin_inset Text
31396
31397 \begin_layout Standard
31398 ISO/IEC DTR 18037
31399 \end_layout
31400
31401 \end_inset
31402 </cell>
31403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31404 \begin_inset Text
31405
31406 \begin_layout Standard
31407 \begin_inset Quotes sld
31408 \end_inset
31409
31410 Extensions for Embedded C
31411 \begin_inset Quotes srd
31412 \end_inset
31413
31414
31415 \end_layout
31416
31417 \end_inset
31418 </cell>
31419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31420 \begin_inset Text
31421
31422 \begin_layout Standard
31423
31424 \size footnotesize
31425 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31426
31427 \end_inset
31428
31429
31430 \end_layout
31431
31432 \end_inset
31433 </cell>
31434 </row>
31435 <row topline="true">
31436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31437 \begin_inset Text
31438
31439 \begin_layout Standard
31440
31441 \end_layout
31442
31443 \end_inset
31444 </cell>
31445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31446 \begin_inset Text
31447
31448 \begin_layout Standard
31449 Latest datasheet of target CPU
31450 \end_layout
31451
31452 \end_inset
31453 </cell>
31454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31455 \begin_inset Text
31456
31457 \begin_layout Standard
31458 vendor
31459 \end_layout
31460
31461 \end_inset
31462 </cell>
31463 </row>
31464 <row topline="true" bottomline="true">
31465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31466 \begin_inset Text
31467
31468 \begin_layout Standard
31469
31470 \end_layout
31471
31472 \end_inset
31473 </cell>
31474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31475 \begin_inset Text
31476
31477 \begin_layout Standard
31478 Revision history of datasheet
31479 \end_layout
31480
31481 \end_inset
31482 </cell>
31483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31484 \begin_inset Text
31485
31486 \begin_layout Standard
31487 vendor
31488 \end_layout
31489
31490 \end_inset
31491 </cell>
31492 </row>
31493 </lyxtabular>
31494
31495 \end_inset
31496
31497
31498 \newline
31499
31500 \end_layout
31501
31502 \begin_layout Section
31503 Application notes specifically for SDCC
31504 \end_layout
31505
31506 \begin_layout Standard
31507 SDCC makes no claims about the completeness of this list and about up-to-datenes
31508 s or correctness of the application notes
31509 \begin_inset LatexCommand \index{Application notes}
31510
31511 \end_inset
31512
31513 .
31514 \end_layout
31515
31516 \begin_layout Standard
31517 \align left
31518
31519 \size footnotesize
31520 \begin_inset Tabular
31521 <lyxtabular version="3" rows="7" columns="3">
31522 <features>
31523 <column alignment="block" valignment="top" leftline="true" width="17col%">
31524 <column alignment="block" valignment="top" leftline="true" width="27col%">
31525 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31526 <row topline="true" bottomline="true">
31527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31528 \begin_inset Text
31529
31530 \begin_layout Standard
31531
31532 \series bold
31533 \size footnotesize
31534 Vendor
31535 \end_layout
31536
31537 \end_inset
31538 </cell>
31539 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31540 \begin_inset Text
31541
31542 \begin_layout Standard
31543
31544 \series bold
31545 \size footnotesize
31546 Subject / Title
31547 \end_layout
31548
31549 \end_inset
31550 </cell>
31551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31552 \begin_inset Text
31553
31554 \begin_layout Standard
31555
31556 \series bold
31557 \size footnotesize
31558 Where to get
31559 \end_layout
31560
31561 \end_inset
31562 </cell>
31563 </row>
31564 <row topline="true">
31565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31566 \begin_inset Text
31567
31568 \begin_layout Standard
31569
31570 \size footnotesize
31571 Maxim / Dallas
31572 \end_layout
31573
31574 \end_inset
31575 </cell>
31576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31577 \begin_inset Text
31578
31579 \begin_layout Standard
31580
31581 \size footnotesize
31582 Using the SDCC Compiler for the DS80C400
31583 \begin_inset LatexCommand \index{DS80C400}
31584
31585 \end_inset
31586
31587
31588 \end_layout
31589
31590 \end_inset
31591 </cell>
31592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31593 \begin_inset Text
31594
31595 \begin_layout Standard
31596
31597 \size footnotesize
31598 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31599
31600 \end_inset
31601
31602
31603 \end_layout
31604
31605 \end_inset
31606 </cell>
31607 </row>
31608 <row topline="true">
31609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31610 \begin_inset Text
31611
31612 \begin_layout Standard
31613
31614 \size footnotesize
31615 Maxim / Dallas
31616 \end_layout
31617
31618 \end_inset
31619 </cell>
31620 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31621 \begin_inset Text
31622
31623 \begin_layout Standard
31624
31625 \size footnotesize
31626 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31627 \begin_inset LatexCommand \index{DS89C4x0}
31628
31629 \end_inset
31630
31631  Family of Microcontrollers
31632 \end_layout
31633
31634 \end_inset
31635 </cell>
31636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31637 \begin_inset Text
31638
31639 \begin_layout Standard
31640
31641 \size footnotesize
31642 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31643
31644 \end_inset
31645
31646
31647 \end_layout
31648
31649 \end_inset
31650 </cell>
31651 </row>
31652 <row topline="true">
31653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31654 \begin_inset Text
31655
31656 \begin_layout Standard
31657
31658 \size footnotesize
31659 Silicon Laboratories / Cygnal
31660 \end_layout
31661
31662 \end_inset
31663 </cell>
31664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31665 \begin_inset Text
31666
31667 \begin_layout Standard
31668
31669 \size footnotesize
31670 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31671 \begin_inset LatexCommand \index{IDE}
31672
31673 \end_inset
31674
31675
31676 \end_layout
31677
31678 \end_inset
31679 </cell>
31680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31681 \begin_inset Text
31682
31683 \begin_layout Standard
31684
31685 \size footnotesize
31686 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31687
31688 \end_inset
31689
31690
31691 \end_layout
31692
31693 \end_inset
31694 </cell>
31695 </row>
31696 <row topline="true">
31697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31698 \begin_inset Text
31699
31700 \begin_layout Standard
31701
31702 \size footnotesize
31703 Ramtron / Goal Semiconductor
31704 \end_layout
31705
31706 \end_inset
31707 </cell>
31708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31709 \begin_inset Text
31710
31711 \begin_layout Standard
31712
31713 \size footnotesize
31714 Interfacing SDCC to Syn and Textpad
31715 \end_layout
31716
31717 \end_inset
31718 </cell>
31719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31720 \begin_inset Text
31721
31722 \begin_layout Standard
31723
31724 \size footnotesize
31725 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31726
31727 \end_inset
31728
31729
31730 \end_layout
31731
31732 \end_inset
31733 </cell>
31734 </row>
31735 <row topline="true">
31736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31737 \begin_inset Text
31738
31739 \begin_layout Standard
31740
31741 \size footnotesize
31742 Ramtron / Goal Semiconductor
31743 \end_layout
31744
31745 \end_inset
31746 </cell>
31747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31748 \begin_inset Text
31749
31750 \begin_layout Standard
31751
31752 \size footnotesize
31753 Installing and Configuring SDCC and Crimson Editor 
31754 \end_layout
31755
31756 \end_inset
31757 </cell>
31758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31759 \begin_inset Text
31760
31761 \begin_layout Standard
31762
31763 \size footnotesize
31764 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31765
31766 \end_inset
31767
31768
31769 \end_layout
31770
31771 \end_inset
31772 </cell>
31773 </row>
31774 <row topline="true" bottomline="true">
31775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31776 \begin_inset Text
31777
31778 \begin_layout Standard
31779
31780 \size footnotesize
31781 Texas Instruments
31782 \end_layout
31783
31784 \end_inset
31785 </cell>
31786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31787 \begin_inset Text
31788
31789 \begin_layout Standard
31790
31791 \size footnotesize
31792 MSC12xx Programming with SDCC
31793 \end_layout
31794
31795 \end_inset
31796 </cell>
31797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31798 \begin_inset Text
31799
31800 \begin_layout Standard
31801
31802 \size footnotesize
31803 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31804
31805 \end_inset
31806
31807
31808 \end_layout
31809
31810 \end_inset
31811 </cell>
31812 </row>
31813 </lyxtabular>
31814
31815 \end_inset
31816
31817
31818 \end_layout
31819
31820 \begin_layout Section
31821 Some Questions
31822 \end_layout
31823
31824 \begin_layout Standard
31825 Some questions answered, some pointers given - it might be time to in turn
31826  ask 
31827 \emph on
31828 you
31829 \emph default
31830  some questions: 
31831 \end_layout
31832
31833 \begin_layout Itemize
31834 can you solve your project with the selected microcontroller? Would you
31835  find out early or rather late that your target is too small/slow/whatever?
31836  Can you switch to a slightly better device if it doesn't fit?
31837 \end_layout
31838
31839 \begin_layout Itemize
31840 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31841  and/or another programming language be more adequate? Would an operating
31842  system on the target device help?
31843 \end_layout
31844
31845 \begin_layout Itemize
31846 if you solved the problem, will the marketing department be happy?
31847 \end_layout
31848
31849 \begin_layout Itemize
31850 if the marketing department is happy, will customers be happy?
31851 \end_layout
31852
31853 \begin_layout Itemize
31854 if you're the project manager, marketing department and maybe even the customer
31855  in one person, have you tried to see the project from the outside?
31856 \end_layout
31857
31858 \begin_layout Itemize
31859 is the project done if you think it is done? Or is just that other interface/pro
31860 tocol/feature/configuration/option missing? How about website, manual(s),
31861  internationali(z|s)ation, packaging, labels, 2nd source for components,
31862  electromagnetic compatability/interference, documentation for production,
31863  production test software, update mechanism, patent issues?
31864 \end_layout
31865
31866 \begin_layout Itemize
31867 is your project adequately positioned in that magic triangle: fame, fortune,
31868  fun?
31869 \end_layout
31870
31871 \begin_layout Standard
31872 Maybe not all answers to these questions are known and some answers may
31873  even be 
31874 \emph on
31875 no
31876 \emph default
31877 , nevertheless knowing these questions may help you to avoid burnout
31878 \begin_inset Foot
31879 status open
31880
31881 \begin_layout Standard
31882 burnout is bad for electronic devices, programmers and motorcycle tyres
31883 \end_layout
31884
31885 \end_inset
31886
31887 .
31888  Chances are you didn't want to hear some of them...
31889 \end_layout
31890
31891 \begin_layout Chapter
31892 Support
31893 \begin_inset LatexCommand \index{Support}
31894
31895 \end_inset
31896
31897
31898 \end_layout
31899
31900 \begin_layout Standard
31901 SDCC has grown to be a large project.
31902  The compiler alone (without the preprocessor, assembler and linker) is
31903  well over 150,000 lines of code (blank stripped).
31904  The open source nature of this project is a key to its continued growth
31905  and support.
31906  You gain the benefit and support of many active software developers and
31907  end users.
31908  Is SDCC perfect? No, that's why we need your help.
31909  The developers take pride in fixing reported bugs.
31910  You can help by reporting the bugs and helping other SDCC users.
31911  There are lots of ways to contribute, and we encourage you to take part
31912  in making SDCC a great software package.
31913  
31914 \end_layout
31915
31916 \begin_layout Standard
31917 The SDCC project is hosted on the SDCC sourceforge site at 
31918 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31919
31920 \end_inset
31921
31922 .
31923  You'll find the complete set of mailing lists
31924 \begin_inset LatexCommand \index{Mailing list(s)}
31925
31926 \end_inset
31927
31928 , forums, bug reporting system, patch submission
31929 \begin_inset LatexCommand \index{Patch submission}
31930
31931 \end_inset
31932
31933  system, download
31934 \begin_inset LatexCommand \index{download}
31935
31936 \end_inset
31937
31938  area and Subversion code repository
31939 \begin_inset LatexCommand \index{Subversion code repository}
31940
31941 \end_inset
31942
31943  there.
31944 \end_layout
31945
31946 \begin_layout Section
31947 Reporting Bugs
31948 \begin_inset LatexCommand \index{Bug reporting}
31949
31950 \end_inset
31951
31952
31953 \begin_inset LatexCommand \index{Reporting bugs}
31954
31955 \end_inset
31956
31957
31958 \end_layout
31959
31960 \begin_layout Standard
31961 The recommended way of reporting bugs is using the infrastructure of the
31962  sourceforge site.
31963  You can follow the status of bug reports there and have an overview about
31964  the known bugs.
31965 \end_layout
31966
31967 \begin_layout Standard
31968 Bug reports are automatically forwarded to the developer mailing list and
31969  will be fixed ASAP.
31970  When reporting a bug, it is very useful to include a small test program
31971  (the smaller the better) which reproduces the problem.
31972  If you can isolate the problem by looking at the generated assembly code,
31973  this can be very helpful.
31974  Compiling your program with the -
31975 \begin_inset ERT
31976 status collapsed
31977
31978 \begin_layout Standard
31979
31980
31981 \backslash
31982 /
31983 \end_layout
31984
31985 \end_inset
31986
31987 -dumpall
31988 \begin_inset LatexCommand \index{-\/-dumpall}
31989
31990 \end_inset
31991
31992  option can sometimes be useful in locating optimization problems.
31993  When reporting a bug please make sure you:
31994 \end_layout
31995
31996 \begin_layout Enumerate
31997 Attach the code you are compiling with SDCC.
31998  
31999 \end_layout
32000
32001 \begin_layout Enumerate
32002 Specify the exact command you use to run SDCC, or attach your Makefile.
32003  
32004 \end_layout
32005
32006 \begin_layout Enumerate
32007 Specify the SDCC version (type "
32008 \family sans
32009 \series bold
32010 sdcc -v
32011 \family default
32012 \series default
32013 "), your platform, and operating system.
32014  
32015 \end_layout
32016
32017 \begin_layout Enumerate
32018 Provide an exact copy of any error message or incorrect output.
32019  
32020 \end_layout
32021
32022 \begin_layout Enumerate
32023 Put something meaningful in the subject of your message.
32024 \end_layout
32025
32026 \begin_layout Standard
32027 Please attempt to include these 5 important parts, as applicable, in all
32028  requests for support or when reporting any problems or bugs with SDCC.
32029  Though this will make your message lengthy, it will greatly improve your
32030  chance that SDCC users and developers will be able to help you.
32031  Some SDCC developers are frustrated by bug reports without code provided
32032  that they can use to reproduce and ultimately fix the problem, so please
32033  be sure to provide sample code if you are reporting a bug! 
32034 \end_layout
32035
32036 \begin_layout Standard
32037 Please have a short check that you are using a recent version of SDCC and
32038  the bug is not yet known.
32039  This is the link for reporting bugs: 
32040 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32041
32042 \end_inset
32043
32044 .
32045  With SDCC on average having more than 200 downloads
32046 \begin_inset LatexCommand \index{download}
32047
32048 \end_inset
32049
32050  on sourceforge per day
32051 \begin_inset Foot
32052 status open
32053
32054 \begin_layout Standard
32055 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32056  between 2002 and 2005.
32057  This does not include other methods of distribution.
32058 \end_layout
32059
32060 \end_inset
32061
32062  there must be some users.
32063  So it's not exactly easy to find a new bug.
32064  If you find one we need it: 
32065 \emph on
32066 reporting bugs is good
32067 \emph default
32068 .
32069 \end_layout
32070
32071 \begin_layout Section
32072 Requesting Features
32073 \begin_inset LatexCommand \label{sub:Requesting-Features}
32074
32075 \end_inset
32076
32077
32078 \begin_inset LatexCommand \index{Feature request}
32079
32080 \end_inset
32081
32082
32083 \begin_inset LatexCommand \index{Requesting features}
32084
32085 \end_inset
32086
32087
32088 \end_layout
32089
32090 \begin_layout Standard
32091 Like bug reports feature requests are forwarded to the developer mailing
32092  list.
32093  This is the link for requesting features: 
32094 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32095
32096 \end_inset
32097
32098 .
32099 \end_layout
32100
32101 \begin_layout Section
32102 Submitting patches
32103 \end_layout
32104
32105 \begin_layout Standard
32106 Like bug reports contributed patches are forwarded to the developer mailing
32107  list.
32108  This is the link for submitting patches
32109 \begin_inset LatexCommand \index{Patch submission}
32110
32111 \end_inset
32112
32113
32114 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32115
32116 \end_inset
32117
32118 .
32119 \end_layout
32120
32121 \begin_layout Standard
32122 You need to specify some parameters to the 
32123 \family typewriter
32124 diff
32125 \family default
32126  command for the patches to be useful.
32127  If you modified more than one file a patch created f.e.
32128  with 
32129 \family sans
32130 \series bold
32131
32132 \begin_inset Quotes sld
32133 \end_inset
32134
32135 diff -Naur unmodified_directory modified_directory >my_changes.patch
32136 \begin_inset Quotes srd
32137 \end_inset
32138
32139
32140 \family default
32141 \series default
32142  will be fine, otherwise 
32143 \family sans
32144 \series bold
32145
32146 \begin_inset Quotes sld
32147 \end_inset
32148
32149 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32150 \begin_inset Quotes srd
32151 \end_inset
32152
32153
32154 \series default
32155  
32156 \family default
32157 will do.
32158 \end_layout
32159
32160 \begin_layout Section
32161 Getting Help
32162 \end_layout
32163
32164 \begin_layout Standard
32165 These links should take you directly to the 
32166 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32167
32168 \end_inset
32169
32170
32171 \begin_inset Foot
32172 status open
32173
32174 \begin_layout Standard
32175 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32176  automated messages (mid 2003)
32177 \end_layout
32178
32179 \end_inset
32180
32181  and the 
32182 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32183
32184 \end_inset
32185
32186 , lists
32187 \begin_inset LatexCommand \index{Mailing list(s)}
32188
32189 \end_inset
32190
32191  and forums are archived and searchable so if you are lucky someone already
32192  had a similar problem.
32193  While mails to the lists themselves are delivered promptly their web front
32194  end on sourceforge sometimes shows a severe time lag (up to several weeks),
32195  if you're seriously using SDCC please consider subscribing to the lists.
32196 \end_layout
32197
32198 \begin_layout Section
32199 ChangeLog
32200 \end_layout
32201
32202 \begin_layout Standard
32203 You can follow the status of the Subversion version
32204 \begin_inset LatexCommand \index{version}
32205
32206 \end_inset
32207
32208  of SDCC by watching the Changelog
32209 \begin_inset LatexCommand \index{Changelog}
32210
32211 \end_inset
32212
32213  in the Subversion repository
32214 \size footnotesize
32215  
32216 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32217
32218 \end_inset
32219
32220 .
32221 \end_layout
32222
32223 \begin_layout Section
32224 Subversion Source Code Repository
32225 \end_layout
32226
32227 \begin_layout Standard
32228 The output of 
32229 \family sans
32230 \series bold
32231 sdcc --version
32232 \family default
32233 \series default
32234  or the filenames of the snapshot versions of SDCC include date and its
32235  Subversion
32236 \begin_inset LatexCommand \index{Subversion code repository}
32237
32238 \end_inset
32239
32240  number.
32241  Subversion allows to download the source of recent or previous versions
32242  
32243 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32244
32245 \end_inset
32246
32247  (by number or by date).
32248  An on-line source code browser and detailled instructions are also available
32249  there.
32250  SDCC versions starting from 1999 up to now are available (currently the
32251  versions prior to the conversion from cvs
32252 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32253
32254 \end_inset
32255
32256  to Subversion (April 2006) are either by accessible by Subversion or by
32257  cvs).
32258 \end_layout
32259
32260 \begin_layout Section
32261 Release policy
32262 \begin_inset LatexCommand \index{Release policy}
32263
32264 \end_inset
32265
32266
32267 \end_layout
32268
32269 \begin_layout Standard
32270 Historically there often were long delays between official releases and
32271  the sourceforge download area tends to get not updated at all.
32272  Excuses in the past might have referred to problems with live range analysis,
32273  but as this was fixed a while ago, the current problem is that another
32274  excuse has to be found.
32275  Kidding aside, we have to get better there! On the other hand there are
32276  daily snapshots available at 
32277 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32278
32279 \end_inset
32280
32281 , and you can always build the very last version (hopefully with many bugs
32282  fixed, and features added) from the source code available at 
32283 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32284
32285 \end_inset
32286
32287 .
32288  A release wiki
32289 \begin_inset LatexCommand \index{wiki}
32290
32291 \end_inset
32292
32293
32294 \begin_inset LatexCommand \index{Release wiki}
32295
32296 \end_inset
32297
32298  at 
32299 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
32300
32301 \end_inset
32302
32303  also holds some information about past and future releases.
32304 \end_layout
32305
32306 \begin_layout Section
32307 Examples
32308 \begin_inset LatexCommand \index{Examples}
32309
32310 \end_inset
32311
32312
32313 \end_layout
32314
32315 \begin_layout Standard
32316 You'll find some small examples in the directory 
32317 \emph on
32318 sdcc/device/examples/.
32319  
32320 \emph default
32321 More examples and libraries are available at
32322 \emph on
32323  The SDCC Open Knowledge Resource 
32324 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32325
32326 \end_inset
32327
32328  
32329 \emph default
32330 web site or at 
32331 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32332
32333 \end_inset
32334
32335 .
32336 \end_layout
32337
32338 \begin_layout Standard
32339 \begin_inset Note Note
32340 status collapsed
32341
32342 \begin_layout Standard
32343 I did insert a reference to Paul's web site here although it seems rather
32344  dedicated to a specific 8032 board (I think it's okay because it f.e.
32345  shows LCD/Harddisc interface and has a free 8051 monitor.
32346  Independent 8032 board vendors face hard competition of heavily subsidized
32347  development boards anyway).
32348 \end_layout
32349
32350 \begin_layout Standard
32351 Maybe we should include some links to real world applications.
32352  Preferably pointer to pointers (one for each architecture) so this stays
32353  manageable here?
32354 \end_layout
32355
32356 \end_inset
32357
32358
32359 \end_layout
32360
32361 \begin_layout Section
32362 Quality control
32363 \begin_inset LatexCommand \label{sec:Quality-control}
32364
32365 \end_inset
32366
32367
32368 \begin_inset LatexCommand \index{Quality control}
32369
32370 \end_inset
32371
32372
32373 \end_layout
32374
32375 \begin_layout Standard
32376 The compiler is passed through snaphot build compile and build checks.
32377  The so called 
32378 \shape italic
32379 regression tests
32380 \shape default
32381
32382 \begin_inset LatexCommand \index{Regression test}
32383
32384 \end_inset
32385
32386  check that SDCC itself compiles flawlessly on several host platforms (i386,
32387  Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32388  the quality of the code generated by SDCC by running the code for several
32389  target platforms through simulators.
32390  The regression test suite comprises more than 100 files which expand to
32391  more than 500 test cases which include more than 4500 tests.
32392  The results of these tests are published daily on SDCC's snapshot page
32393  (click on the red or green symbols on the right side of 
32394 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32395
32396 \end_inset
32397
32398 ).
32399 \end_layout
32400
32401 \begin_layout Standard
32402 There is a separate document 
32403 \shape italic
32404 test_suite.pdf 
32405 \begin_inset LatexCommand \index{Test suite}
32406
32407 \end_inset
32408
32409
32410 \shape default
32411  
32412 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32413
32414 \end_inset
32415
32416  about the regression test suite.
32417 \end_layout
32418
32419 \begin_layout Standard
32420 You'll find the test code in the directory 
32421 \shape italic
32422 sdcc/support/regression
32423 \shape default
32424 .
32425  You can run these tests manually by running 
32426 \family sans
32427 make
32428 \family default
32429  in this directory (or f.e.
32430  
32431 \family sans
32432 \series bold
32433
32434 \begin_inset Quotes sld
32435 \end_inset
32436
32437 make test-mcs51
32438 \begin_inset Quotes srd
32439 \end_inset
32440
32441
32442 \family default
32443 \series default
32444  if you don't want to run the complete tests).
32445  The test code might also be interesting if you want to look for examples
32446 \begin_inset LatexCommand \index{Examples}
32447
32448 \end_inset
32449
32450  checking corner cases of SDCC or if you plan to submit patches
32451 \begin_inset LatexCommand \index{Patch submission}
32452
32453 \end_inset
32454
32455 .
32456 \end_layout
32457
32458 \begin_layout Standard
32459 The PIC14 port uses a different set of regression tests 
32460 \begin_inset LatexCommand \index{Regression test (PIC14)}
32461
32462 \end_inset
32463
32464 , you'll find them in the directory 
32465 \shape italic
32466 sdcc/src/regression
32467 \shape default
32468 .
32469 \end_layout
32470
32471 \begin_layout Section
32472 Use of SDCC in Education
32473 \end_layout
32474
32475 \begin_layout Standard
32476 In short: 
32477 \emph on
32478 highly
32479 \emph default
32480  encouraged
32481 \begin_inset Foot
32482 status open
32483
32484 \begin_layout Standard
32485 the phrase "use in education" might evoke the association "
32486 \emph on
32487 only
32488 \emph default
32489  fit for use in education".
32490  This connotation is not intended but nevertheless risked as the licensing
32491  of SDCC makes it difficult to offer educational discounts
32492 \end_layout
32493
32494 \end_inset
32495
32496 .
32497  If your rationales are to:
32498 \end_layout
32499
32500 \begin_layout Enumerate
32501 give students a chance to understand the 
32502 \emph on
32503 complete
32504 \emph default
32505  steps of code generation
32506 \end_layout
32507
32508 \begin_layout Enumerate
32509 have a curriculum that can be extended for years.
32510  Then you could use an fpga board as target and your curriculum will seamlessly
32511  extend from logic synthesis (
32512 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32513
32514 \end_inset
32515
32516
32517 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32518
32519 \end_inset
32520
32521 ), over assembly programming, to C to FPGA compilers (
32522 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32523
32524 \end_inset
32525
32526 ) and to C.
32527 \end_layout
32528
32529 \begin_layout Enumerate
32530 be able to insert excursions about skills like using a revision control
32531  system, submitting/applying patches, using a type-setting (as opposed to
32532  word-processing) engine LyX/LaTeX, using 
32533 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32534
32535 \end_inset
32536
32537 , following some 
32538 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32539
32540 \end_inset
32541
32542 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32543  Source Software, CPU simulation, compiler regression tests
32544 \begin_inset LatexCommand \index{Regression test}
32545
32546 \end_inset
32547
32548 .
32549  
32550 \newline
32551 And if there should be a shortage of ideas then you can always point students
32552  to the ever-growing feature request list 
32553 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32554
32555 \end_inset
32556
32557 .
32558 \end_layout
32559
32560 \begin_layout Enumerate
32561 not tie students to a specific host platform and instead allow them to use
32562  a host platform of 
32563 \emph on
32564 their
32565 \emph default
32566  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32567  and eventually 
32568 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32569
32570 \end_inset
32571
32572 )
32573 \end_layout
32574
32575 \begin_layout Enumerate
32576 not encourage students to use illegal copies of educational software
32577 \end_layout
32578
32579 \begin_layout Enumerate
32580 be immune to licensing/availability/price changes of the chosen tool chain
32581 \end_layout
32582
32583 \begin_layout Enumerate
32584 be able to change to a new target platform without having to adopt a new
32585  tool chain
32586 \end_layout
32587
32588 \begin_layout Enumerate
32589 have complete control over and insight into the tool chain
32590 \end_layout
32591
32592 \begin_layout Enumerate
32593 make your students aware about the pros and cons of open source software
32594  development
32595 \end_layout
32596
32597 \begin_layout Enumerate
32598 give back to the public as you are probably at least partially publically
32599  funded
32600 \end_layout
32601
32602 \begin_layout Enumerate
32603 give students a chance to publically prove their skills and to possibly
32604  see a world wide impact
32605 \end_layout
32606
32607 \begin_layout Standard
32608 then SDCC is probably among the first choices.
32609  Well, probably SDCC might be the only choice.
32610 \newpage
32611
32612 \end_layout
32613
32614 \begin_layout Chapter
32615 SDCC Technical Data
32616 \end_layout
32617
32618 \begin_layout Section
32619 Optimizations
32620 \begin_inset LatexCommand \index{Optimizations}
32621
32622 \end_inset
32623
32624
32625 \end_layout
32626
32627 \begin_layout Standard
32628 SDCC performs a host of standard optimizations in addition to some MCU specific
32629  optimizations.
32630  
32631 \end_layout
32632
32633 \begin_layout Subsection
32634 Sub-expression Elimination
32635 \begin_inset LatexCommand \index{Subexpression elimination}
32636
32637 \end_inset
32638
32639
32640 \end_layout
32641
32642 \begin_layout Standard
32643 The compiler does local and 
32644 \emph on
32645 g
32646 \emph default
32647 lobal 
32648 \emph on
32649 c
32650 \emph default
32651 ommon 
32652 \emph on
32653 s
32654 \emph default
32655 ubexpression 
32656 \emph on
32657 e
32658 \emph default
32659 limination, e.g.: 
32660 \end_layout
32661
32662 \begin_layout Verse
32663
32664 \family typewriter
32665 i = x + y + 1; 
32666 \newline
32667 j = x + y;
32668 \end_layout
32669
32670 \begin_layout Standard
32671 will be translated to
32672 \end_layout
32673
32674 \begin_layout Verse
32675
32676 \family typewriter
32677 iTemp = x + y; 
32678 \newline
32679 i = iTemp + 1; 
32680 \newline
32681 j = iTemp;
32682 \end_layout
32683
32684 \begin_layout Standard
32685 Some subexpressions are not as obvious as the above example, e.g.:
32686 \end_layout
32687
32688 \begin_layout Verse
32689
32690 \family typewriter
32691 a->b[i].c = 10; 
32692 \newline
32693 a->b[i].d = 11;
32694 \end_layout
32695
32696 \begin_layout Standard
32697 In this case the address arithmetic a->b[i] will be computed only once;
32698  the equivalent code in C would be.
32699 \end_layout
32700
32701 \begin_layout Verse
32702
32703 \family typewriter
32704 iTemp = a->b[i]; 
32705 \newline
32706 iTemp.c = 10; 
32707 \newline
32708 iTemp.d = 11;
32709 \end_layout
32710
32711 \begin_layout Standard
32712 The compiler will try to keep these temporary variables in registers.
32713 \end_layout
32714
32715 \begin_layout Subsection
32716 Dead-Code Elimination
32717 \begin_inset LatexCommand \index{Dead-code elimination}
32718
32719 \end_inset
32720
32721
32722 \end_layout
32723
32724 \begin_layout Verse
32725
32726 \family typewriter
32727 int global;
32728 \newline
32729
32730 \newline
32731 void f () { 
32732 \newline
32733 \InsetSpace ~
32734 \InsetSpace ~
32735 int i; 
32736 \newline
32737 \InsetSpace ~
32738 \InsetSpace ~
32739 i = 1; \InsetSpace ~
32740 \InsetSpace ~
32741 \InsetSpace ~
32742 \InsetSpace ~
32743 \InsetSpace ~
32744 /* dead store */ 
32745 \newline
32746 \InsetSpace ~
32747 \InsetSpace ~
32748 global = 1;\InsetSpace ~
32749 /* dead
32750  store */ 
32751 \newline
32752 \InsetSpace ~
32753 \InsetSpace ~
32754 global = 2; 
32755 \newline
32756 \InsetSpace ~
32757 \InsetSpace ~
32758 return; 
32759 \newline
32760 \InsetSpace ~
32761 \InsetSpace ~
32762 global = 3;\InsetSpace ~
32763 /* unreachable */ 
32764 \newline
32765 }
32766 \end_layout
32767
32768 \begin_layout Standard
32769 will be changed to
32770 \end_layout
32771
32772 \begin_layout Verse
32773
32774 \family typewriter
32775 int global;
32776 \newline
32777
32778 \newline
32779 void f () {
32780 \newline
32781 \InsetSpace ~
32782 \InsetSpace ~
32783 global = 2; 
32784 \newline
32785 }
32786 \end_layout
32787
32788 \begin_layout Subsection
32789 Copy-Propagation
32790 \begin_inset LatexCommand \index{Copy propagation}
32791
32792 \end_inset
32793
32794
32795 \end_layout
32796
32797 \begin_layout Verse
32798
32799 \family typewriter
32800 int f() { 
32801 \newline
32802 \InsetSpace ~
32803 \InsetSpace ~
32804 int i, j; 
32805 \newline
32806 \InsetSpace ~
32807 \InsetSpace ~
32808 i = 10; 
32809 \newline
32810 \InsetSpace ~
32811 \InsetSpace ~
32812 j = i; 
32813 \newline
32814 \InsetSpace ~
32815 \InsetSpace ~
32816 return j; 
32817 \newline
32818 }
32819 \end_layout
32820
32821 \begin_layout Standard
32822 will be changed to 
32823 \end_layout
32824
32825 \begin_layout Verse
32826
32827 \family typewriter
32828 int f() { 
32829 \newline
32830 \InsetSpace ~
32831 \InsetSpace ~
32832 int i, j; 
32833 \newline
32834 \InsetSpace ~
32835 \InsetSpace ~
32836 i = 10; 
32837 \newline
32838 \InsetSpace ~
32839 \InsetSpace ~
32840 j = 10; 
32841 \newline
32842 \InsetSpace ~
32843 \InsetSpace ~
32844 return 10; 
32845 \newline
32846 }
32847 \end_layout
32848
32849 \begin_layout Standard
32850 Note: the dead stores created by this copy propagation will be eliminated
32851  by dead-code elimination.
32852 \end_layout
32853
32854 \begin_layout Subsection
32855 Loop Optimizations
32856 \begin_inset LatexCommand \index{Loop optimization}
32857
32858 \end_inset
32859
32860
32861 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32862
32863 \end_inset
32864
32865
32866 \end_layout
32867
32868 \begin_layout Standard
32869 Two types of loop optimizations are done by SDCC 
32870 \emph on
32871 loop invariant
32872 \emph default
32873  lifting and
32874 \emph on
32875  strength reduction
32876 \emph default
32877  of loop induction variables.
32878  In addition to the strength reduction the optimizer marks the induction
32879  variables and the register allocator tries to keep the induction variables
32880  in registers for the duration of the loop.
32881  Because of this preference of the register allocator
32882 \begin_inset LatexCommand \index{Register allocation}
32883
32884 \end_inset
32885
32886 , loop induction optimization causes an increase in register pressure, which
32887  may cause unwanted spilling of other temporary variables into the stack
32888 \begin_inset LatexCommand \index{stack}
32889
32890 \end_inset
32891
32892  / data space.
32893  The compiler will generate a warning message when it is forced to allocate
32894  extra space either on the stack or data space.
32895  If this extra space allocation is undesirable then induction optimization
32896  can be eliminated either for the entire source file (with -
32897 \begin_inset ERT
32898 status collapsed
32899
32900 \begin_layout Standard
32901
32902
32903 \backslash
32904 /
32905 \end_layout
32906
32907 \end_inset
32908
32909 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32910 noinduction
32911 \begin_inset LatexCommand \index{\#pragma noinduction}
32912
32913 \end_inset
32914
32915 .
32916 \newline
32917
32918 \newline
32919 Loop Invariant:
32920 \end_layout
32921
32922 \begin_layout Verse
32923
32924 \family typewriter
32925 for (i = 0 ; i < 100 ; i ++) 
32926 \newline
32927 \InsetSpace ~
32928 \InsetSpace ~
32929 \InsetSpace ~
32930 \InsetSpace ~
32931 f += k + l;
32932 \end_layout
32933
32934 \begin_layout Standard
32935 changed to
32936 \end_layout
32937
32938 \begin_layout Verse
32939
32940 \family typewriter
32941 itemp = k + l; 
32942 \newline
32943 for (i = 0; i < 100; i++) 
32944 \newline
32945 \InsetSpace ~
32946 \InsetSpace ~
32947 \InsetSpace ~
32948 \InsetSpace ~
32949 f += itemp;
32950 \end_layout
32951
32952 \begin_layout Standard
32953 As mentioned previously some loop invariants are not as apparent, all static
32954  address computations are also moved out of the loop.
32955 \newline
32956
32957 \newline
32958 Strength Reduction
32959 \begin_inset LatexCommand \index{Strength reduction}
32960
32961 \end_inset
32962
32963 , this optimization substitutes an expression by a cheaper expression:
32964 \end_layout
32965
32966 \begin_layout Verse
32967
32968 \family typewriter
32969 for (i=0;i < 100; i++)
32970 \newline
32971 \InsetSpace ~
32972 \InsetSpace ~
32973 \InsetSpace ~
32974 \InsetSpace ~
32975 ar[i*5] = i*3;
32976 \end_layout
32977
32978 \begin_layout Standard
32979 changed to
32980 \end_layout
32981
32982 \begin_layout Verse
32983
32984 \family typewriter
32985 itemp1 = 0; 
32986 \newline
32987 itemp2 = 0; 
32988 \newline
32989 for (i=0;i< 100;i++) { 
32990 \newline
32991 \InsetSpace ~
32992 \InsetSpace ~
32993 \InsetSpace ~
32994 \InsetSpace ~
32995 ar[itemp1] = itemp2; 
32996 \newline
32997 \InsetSpace ~
32998 \InsetSpace ~
32999 \InsetSpace ~
33000 \InsetSpace ~
33001 itemp1
33002  += 5; 
33003 \newline
33004 \InsetSpace ~
33005 \InsetSpace ~
33006 \InsetSpace ~
33007 \InsetSpace ~
33008 itemp2 += 3; 
33009 \newline
33010 }
33011 \end_layout
33012
33013 \begin_layout Standard
33014 The more expensive multiplication
33015 \begin_inset LatexCommand \index{Multiplication}
33016
33017 \end_inset
33018
33019  is changed to a less expensive addition.
33020 \end_layout
33021
33022 \begin_layout Subsection
33023 Loop Reversing
33024 \begin_inset LatexCommand \index{Loop reversing}
33025
33026 \end_inset
33027
33028
33029 \end_layout
33030
33031 \begin_layout Standard
33032 This optimization is done to reduce the overhead of checking loop boundaries
33033  for every iteration.
33034  Some simple loops can be reversed and implemented using a 
33035 \begin_inset Quotes eld
33036 \end_inset
33037
33038 decrement and jump if not zero
33039 \begin_inset Quotes erd
33040 \end_inset
33041
33042  instruction.
33043  SDCC checks for the following criterion to determine if a loop is reversible
33044  (note: more sophisticated compilers use data-dependency analysis to make
33045  this determination, SDCC uses a more simple minded analysis).
33046 \end_layout
33047
33048 \begin_layout Itemize
33049 The 'for' loop is of the form 
33050 \newline
33051
33052 \newline
33053
33054 \family typewriter
33055 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33056  += 1])
33057 \newline
33058 \InsetSpace ~
33059 \InsetSpace ~
33060 \InsetSpace ~
33061 \InsetSpace ~
33062 <for body>
33063 \end_layout
33064
33065 \begin_layout Itemize
33066 The <for body> does not contain 
33067 \begin_inset Quotes eld
33068 \end_inset
33069
33070 continue
33071 \begin_inset Quotes erd
33072 \end_inset
33073
33074  or 'break
33075 \begin_inset Quotes erd
33076 \end_inset
33077
33078 .
33079 \end_layout
33080
33081 \begin_layout Itemize
33082 All goto's are contained within the loop.
33083 \end_layout
33084
33085 \begin_layout Itemize
33086 No function calls within the loop.
33087 \end_layout
33088
33089 \begin_layout Itemize
33090 The loop control variable <sym> is not assigned any value within the loop
33091 \end_layout
33092
33093 \begin_layout Itemize
33094 The loop control variable does NOT participate in any arithmetic operation
33095  within the loop.
33096 \end_layout
33097
33098 \begin_layout Itemize
33099 There are NO switch statements in the loop.
33100 \end_layout
33101
33102 \begin_layout Subsection
33103 Algebraic Simplifications
33104 \end_layout
33105
33106 \begin_layout Standard
33107 SDCC does numerous algebraic simplifications, the following is a small sub-set
33108  of these optimizations.
33109 \end_layout
33110
33111 \begin_layout Verse
33112
33113 \family typewriter
33114 i = j + 0;\InsetSpace ~
33115 \InsetSpace ~
33116 \InsetSpace ~
33117 \InsetSpace ~
33118  /* changed to: */\InsetSpace ~
33119 \InsetSpace ~
33120 \InsetSpace ~
33121 \InsetSpace ~
33122  i = j; 
33123 \newline
33124 i /= 2;\InsetSpace ~
33125 \InsetSpace ~
33126 \InsetSpace ~
33127 \InsetSpace ~
33128 \InsetSpace ~
33129 \InsetSpace ~
33130 \InsetSpace ~
33131  /* changed to: */\InsetSpace ~
33132 \InsetSpace ~
33133 \InsetSpace ~
33134 \InsetSpace ~
33135  i >>= 1; 
33136 \newline
33137 i
33138  = j - j;\InsetSpace ~
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 \InsetSpace ~
33142  /* changed to: */\InsetSpace ~
33143 \InsetSpace ~
33144 \InsetSpace ~
33145 \InsetSpace ~
33146  i = 0; 
33147 \newline
33148 i = j / 1;\InsetSpace ~
33149 \InsetSpace ~
33150 \InsetSpace ~
33151 \InsetSpace ~
33152  /* changed to: */\InsetSpace ~
33153 \InsetSpace ~
33154 \InsetSpace ~
33155 \InsetSpace ~
33156  i = j;
33157 \end_layout
33158
33159 \begin_layout Standard
33160 Note the subexpressions
33161 \begin_inset LatexCommand \index{Subexpression}
33162
33163 \end_inset
33164
33165  given above are generally introduced by macro expansions or as a result
33166  of copy/constant propagation.
33167 \end_layout
33168
33169 \begin_layout Subsection
33170 'switch' Statements
33171 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33172
33173 \end_inset
33174
33175
33176 \begin_inset LatexCommand \index{switch statement}
33177
33178 \end_inset
33179
33180
33181 \end_layout
33182
33183 \begin_layout Standard
33184 SDCC can optimize switch statements to jump tables
33185 \begin_inset LatexCommand \index{jump tables}
33186
33187 \end_inset
33188
33189 .
33190  It makes the decision based on an estimate of the generated code size.
33191  SDCC is quite liberal in the requirements for jump table generation: 
33192 \end_layout
33193
33194 \begin_layout Itemize
33195 The labels need not be in order, and the starting number need not be one
33196  or zero, the case labels are in numerical sequence or not too many case
33197  labels are missing.
33198 \end_layout
33199
33200 \begin_deeper
33201 \begin_layout Verse
33202
33203 \family typewriter
33204 switch(i) {\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 \InsetSpace ~
33223 \InsetSpace ~
33224 \InsetSpace ~
33225 \InsetSpace ~
33226 \InsetSpace ~
33227 \InsetSpace ~
33228 \InsetSpace ~
33229 \InsetSpace ~
33230 switch (i) { 
33231 \newline
33232 \InsetSpace ~
33233 \InsetSpace ~
33234 \InsetSpace ~
33235 case 4: ...\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 case 0: ...
33262  
33263 \newline
33264 \InsetSpace ~
33265 \InsetSpace ~
33266 \InsetSpace ~
33267 case 5: ...\InsetSpace ~
33268 \InsetSpace ~
33269 \InsetSpace ~
33270 \InsetSpace ~
33271 \InsetSpace ~
33272 \InsetSpace ~
33273 \InsetSpace ~
33274 \InsetSpace ~
33275 \InsetSpace ~
33276 \InsetSpace ~
33277 \InsetSpace ~
33278 \InsetSpace ~
33279 \InsetSpace ~
33280 \InsetSpace ~
33281 \InsetSpace ~
33282 \InsetSpace ~
33283 \InsetSpace ~
33284 \InsetSpace ~
33285 \InsetSpace ~
33286 \InsetSpace ~
33287 \InsetSpace ~
33288 \InsetSpace ~
33289 \InsetSpace ~
33290 \InsetSpace ~
33291 \InsetSpace ~
33292 \InsetSpace ~
33293 case 1: ...
33294  
33295 \newline
33296 \InsetSpace ~
33297 \InsetSpace ~
33298 \InsetSpace ~
33299 case 3: ...\InsetSpace ~
33300 \InsetSpace ~
33301 \InsetSpace ~
33302 \InsetSpace ~
33303 \InsetSpace ~
33304 \InsetSpace ~
33305 \InsetSpace ~
33306 \InsetSpace ~
33307 \InsetSpace ~
33308 \InsetSpace ~
33309 \InsetSpace ~
33310 \InsetSpace ~
33311 \InsetSpace ~
33312 \InsetSpace ~
33313 \InsetSpace ~
33314 \InsetSpace ~
33315 \InsetSpace ~
33316 \InsetSpace ~
33317 \InsetSpace ~
33318 \InsetSpace ~
33319 \InsetSpace ~
33320 \InsetSpace ~
33321 \InsetSpace ~
33322 \InsetSpace ~
33323 \InsetSpace ~
33324 \InsetSpace ~
33325
33326 \newline
33327 \InsetSpace ~
33328 \InsetSpace ~
33329 \InsetSpace ~
33330 case 6: ...\InsetSpace ~
33331 \InsetSpace ~
33332 \InsetSpace ~
33333 \InsetSpace ~
33334 \InsetSpace ~
33335 \InsetSpace ~
33336 \InsetSpace ~
33337 \InsetSpace ~
33338 \InsetSpace ~
33339 \InsetSpace ~
33340 \InsetSpace ~
33341 \InsetSpace ~
33342 \InsetSpace ~
33343 \InsetSpace ~
33344 \InsetSpace ~
33345 \InsetSpace ~
33346 \InsetSpace ~
33347 \InsetSpace ~
33348 \InsetSpace ~
33349 \InsetSpace ~
33350 \InsetSpace ~
33351 \InsetSpace ~
33352 \InsetSpace ~
33353 \InsetSpace ~
33354 \InsetSpace ~
33355 \InsetSpace ~
33356 case 3: ...
33357  
33358 \newline
33359 \InsetSpace ~
33360 \InsetSpace ~
33361 \InsetSpace ~
33362 case 7: ...\InsetSpace ~
33363 \InsetSpace ~
33364 \InsetSpace ~
33365 \InsetSpace ~
33366 \InsetSpace ~
33367 \InsetSpace ~
33368 \InsetSpace ~
33369 \InsetSpace ~
33370 \InsetSpace ~
33371 \InsetSpace ~
33372 \InsetSpace ~
33373 \InsetSpace ~
33374 \InsetSpace ~
33375 \InsetSpace ~
33376 \InsetSpace ~
33377 \InsetSpace ~
33378 \InsetSpace ~
33379 \InsetSpace ~
33380 \InsetSpace ~
33381 \InsetSpace ~
33382 \InsetSpace ~
33383 \InsetSpace ~
33384 \InsetSpace ~
33385 \InsetSpace ~
33386 \InsetSpace ~
33387 \InsetSpace ~
33388 case 4: ...
33389  
33390 \newline
33391 \InsetSpace ~
33392 \InsetSpace ~
33393 \InsetSpace ~
33394 case 8: ...\InsetSpace ~
33395 \InsetSpace ~
33396 \InsetSpace ~
33397 \InsetSpace ~
33398 \InsetSpace ~
33399 \InsetSpace ~
33400 \InsetSpace ~
33401 \InsetSpace ~
33402 \InsetSpace ~
33403 \InsetSpace ~
33404 \InsetSpace ~
33405 \InsetSpace ~
33406 \InsetSpace ~
33407 \InsetSpace ~
33408 \InsetSpace ~
33409 \InsetSpace ~
33410 \InsetSpace ~
33411 \InsetSpace ~
33412 \InsetSpace ~
33413 \InsetSpace ~
33414 \InsetSpace ~
33415 \InsetSpace ~
33416 \InsetSpace ~
33417 \InsetSpace ~
33418 \InsetSpace ~
33419 \InsetSpace ~
33420 case 5: ...
33421  
33422 \newline
33423 \InsetSpace ~
33424 \InsetSpace ~
33425 \InsetSpace ~
33426 case 9: ...\InsetSpace ~
33427 \InsetSpace ~
33428 \InsetSpace ~
33429 \InsetSpace ~
33430 \InsetSpace ~
33431 \InsetSpace ~
33432 \InsetSpace ~
33433 \InsetSpace ~
33434 \InsetSpace ~
33435 \InsetSpace ~
33436 \InsetSpace ~
33437 \InsetSpace ~
33438 \InsetSpace ~
33439 \InsetSpace ~
33440 \InsetSpace ~
33441 \InsetSpace ~
33442 \InsetSpace ~
33443 \InsetSpace ~
33444 \InsetSpace ~
33445 \InsetSpace ~
33446 \InsetSpace ~
33447 \InsetSpace ~
33448 \InsetSpace ~
33449 \InsetSpace ~
33450 \InsetSpace ~
33451 \InsetSpace ~
33452 case 6: ...
33453  
33454 \newline
33455 \InsetSpace ~
33456 \InsetSpace ~
33457 \InsetSpace ~
33458 case 10: ...\InsetSpace ~
33459 \InsetSpace ~
33460 \InsetSpace ~
33461 \InsetSpace ~
33462 \InsetSpace ~
33463 \InsetSpace ~
33464 \InsetSpace ~
33465 \InsetSpace ~
33466 \InsetSpace ~
33467 \InsetSpace ~
33468 \InsetSpace ~
33469 \InsetSpace ~
33470 \InsetSpace ~
33471 \InsetSpace ~
33472 \InsetSpace ~
33473 \InsetSpace ~
33474 \InsetSpace ~
33475 \InsetSpace ~
33476 \InsetSpace ~
33477 \InsetSpace ~
33478 \InsetSpace ~
33479 \InsetSpace ~
33480 \InsetSpace ~
33481 \InsetSpace ~
33482 \InsetSpace ~
33483 case 7: ...
33484  
33485 \newline
33486 \InsetSpace ~
33487 \InsetSpace ~
33488 \InsetSpace ~
33489 case 11: ...\InsetSpace ~
33490 \InsetSpace ~
33491 \InsetSpace ~
33492 \InsetSpace ~
33493 \InsetSpace ~
33494 \InsetSpace ~
33495 \InsetSpace ~
33496 \InsetSpace ~
33497 \InsetSpace ~
33498 \InsetSpace ~
33499 \InsetSpace ~
33500 \InsetSpace ~
33501 \InsetSpace ~
33502 \InsetSpace ~
33503 \InsetSpace ~
33504 \InsetSpace ~
33505 \InsetSpace ~
33506 \InsetSpace ~
33507 \InsetSpace ~
33508 \InsetSpace ~
33509 \InsetSpace ~
33510 \InsetSpace ~
33511 \InsetSpace ~
33512 \InsetSpace ~
33513 \InsetSpace ~
33514 case 8: ...
33515  
33516 \newline
33517 }\InsetSpace ~
33518 \InsetSpace ~
33519 \InsetSpace ~
33520 \InsetSpace ~
33521 \InsetSpace ~
33522 \InsetSpace ~
33523 \InsetSpace ~
33524 \InsetSpace ~
33525 \InsetSpace ~
33526 \InsetSpace ~
33527 \InsetSpace ~
33528 \InsetSpace ~
33529 \InsetSpace ~
33530 \InsetSpace ~
33531 \InsetSpace ~
33532 \InsetSpace ~
33533 \InsetSpace ~
33534 \InsetSpace ~
33535 \InsetSpace ~
33536 \InsetSpace ~
33537 \InsetSpace ~
33538 \InsetSpace ~
33539 \InsetSpace ~
33540 \InsetSpace ~
33541 \InsetSpace ~
33542 \InsetSpace ~
33543 \InsetSpace ~
33544 \InsetSpace ~
33545 \InsetSpace ~
33546 \InsetSpace ~
33547 \InsetSpace ~
33548 \InsetSpace ~
33549 \InsetSpace ~
33550 \InsetSpace ~
33551 \InsetSpace ~
33552 \InsetSpace ~
33553 }
33554 \end_layout
33555
33556 \begin_layout Standard
33557 Both the above switch statements will be implemented using a jump-table.
33558  The example to the right side is slightly more efficient as the check for
33559  the lower boundary of the jump-table is not needed.
33560 \end_layout
33561
33562 \end_deeper
33563 \begin_layout Itemize
33564 The number of case labels is not larger than supported by the target architectur
33565 e.
33566 \end_layout
33567
33568 \begin_layout Itemize
33569 If the case labels are not in numerical sequence ('gaps' between cases)
33570  SDCC checks whether a jump table with additionally inserted dummy cases
33571  is still attractive.
33572  
33573 \end_layout
33574
33575 \begin_layout Itemize
33576 If the starting number is not zero and a check for the lower boundary of
33577  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33578  ...
33579  .
33580 \end_layout
33581
33582 \begin_layout Standard
33583 Switch statements which have large gaps in the numeric sequence or those
33584  that have too many case labels can be split into more than one switch statement
33585  for efficient code generation, e.g.:
33586 \end_layout
33587
33588 \begin_layout Verse
33589
33590 \family typewriter
33591 switch (i) { 
33592 \newline
33593 \InsetSpace ~
33594 \InsetSpace ~
33595 case 1: ...
33596  
33597 \newline
33598 \InsetSpace ~
33599 \InsetSpace ~
33600 case 2: ...
33601  
33602 \newline
33603 \InsetSpace ~
33604 \InsetSpace ~
33605 case 3: ...
33606  
33607 \newline
33608 \InsetSpace ~
33609 \InsetSpace ~
33610 case 4: ...
33611  
33612 \newline
33613 \InsetSpace ~
33614 \InsetSpace ~
33615 case 5: ...
33616  
33617 \newline
33618 \InsetSpace ~
33619 \InsetSpace ~
33620 case 6: ...
33621  
33622 \newline
33623 \InsetSpace ~
33624 \InsetSpace ~
33625 case 7: ...
33626  
33627 \newline
33628 \InsetSpace ~
33629 \InsetSpace ~
33630 case 101: ...
33631  
33632 \newline
33633 \InsetSpace ~
33634 \InsetSpace ~
33635 case 102: ...
33636  
33637 \newline
33638 \InsetSpace ~
33639 \InsetSpace ~
33640 case 103: ...
33641  
33642 \newline
33643 \InsetSpace ~
33644 \InsetSpace ~
33645 case 104: ...
33646  
33647 \newline
33648 \InsetSpace ~
33649 \InsetSpace ~
33650 case 105: ...
33651  
33652 \newline
33653 \InsetSpace ~
33654 \InsetSpace ~
33655 case 106: ...
33656  
33657 \newline
33658 \InsetSpace ~
33659 \InsetSpace ~
33660 case 107: ...
33661  
33662 \newline
33663 }
33664 \end_layout
33665
33666 \begin_layout Standard
33667 If the above switch statement is broken down into two switch statements
33668 \end_layout
33669
33670 \begin_layout Verse
33671
33672 \family typewriter
33673 switch (i) { 
33674 \newline
33675 \InsetSpace ~
33676 \InsetSpace ~
33677 case 1: ...
33678  
33679 \newline
33680 \InsetSpace ~
33681 \InsetSpace ~
33682 case 2: ...
33683  
33684 \newline
33685 \InsetSpace ~
33686 \InsetSpace ~
33687 case 3: ...
33688  
33689 \newline
33690 \InsetSpace ~
33691 \InsetSpace ~
33692 case 4: ...
33693  
33694 \newline
33695 \InsetSpace ~
33696 \InsetSpace ~
33697 case 5: ...
33698  
33699 \newline
33700 \InsetSpace ~
33701 \InsetSpace ~
33702 case 6: ...
33703  
33704 \newline
33705 \InsetSpace ~
33706 \InsetSpace ~
33707 case 7: ...
33708  
33709 \newline
33710 }
33711 \end_layout
33712
33713 \begin_layout Standard
33714 and
33715 \end_layout
33716
33717 \begin_layout Verse
33718
33719 \family typewriter
33720 switch (i) { 
33721 \newline
33722 \InsetSpace ~
33723 \InsetSpace ~
33724 case 101: ...
33725  
33726 \newline
33727 \InsetSpace ~
33728 \InsetSpace ~
33729 case 102: ...
33730  
33731 \newline
33732 \InsetSpace ~
33733 \InsetSpace ~
33734 case 103: ...
33735  
33736 \newline
33737 \InsetSpace ~
33738 \InsetSpace ~
33739 case 104: ...
33740  
33741 \newline
33742 \InsetSpace ~
33743 \InsetSpace ~
33744 case 105: ...
33745  
33746 \newline
33747 \InsetSpace ~
33748 \InsetSpace ~
33749 case 106: ...
33750  
33751 \newline
33752 \InsetSpace ~
33753 \InsetSpace ~
33754 case 107: ...
33755  
33756 \newline
33757 }
33758 \end_layout
33759
33760 \begin_layout Standard
33761 then both the switch statements will be implemented using jump-tables whereas
33762  the unmodified switch statement will not be.
33763 \end_layout
33764
33765 \begin_layout Standard
33766 \begin_inset Note Note
33767 status collapsed
33768
33769 \begin_layout Standard
33770 There might be reasons which SDCC cannot know about to either favour or
33771  not favour jump tables.
33772  If the target system has to be as quick for the last switch case as for
33773  the first (pro jump table), or if the switch argument is known to be zero
33774  in the majority of the cases (contra jump table).
33775 \end_layout
33776
33777 \end_inset
33778
33779
33780 \end_layout
33781
33782 \begin_layout Standard
33783 The pragma nojtbound
33784 \begin_inset LatexCommand \index{\#pragma nojtbound}
33785
33786 \end_inset
33787
33788  can be used to turn off checking the 
33789 \emph on
33790 j
33791 \emph default
33792 ump 
33793 \emph on
33794 t
33795 \emph default
33796 able 
33797 \emph on
33798 bound
33799 \emph default
33800 aries.
33801  It has no effect if a default label is supplied.
33802  Use of this pragma is dangerous: if the switch
33803 \begin_inset LatexCommand \index{switch statement}
33804
33805 \end_inset
33806
33807  argument is not matched by a case statement the processor will happily
33808  jump into Nirvana.
33809 \end_layout
33810
33811 \begin_layout Subsection
33812 Bit-shifting Operations
33813 \begin_inset LatexCommand \index{Bit shifting}
33814
33815 \end_inset
33816
33817 .
33818 \end_layout
33819
33820 \begin_layout Standard
33821 Bit shifting is one of the most frequently used operation in embedded programmin
33822 g.
33823  SDCC tries to implement bit-shift operations in the most efficient way
33824  possible, e.g.:
33825 \end_layout
33826
33827 \begin_layout Verse
33828
33829 \family typewriter
33830 unsigned char i;
33831 \newline
33832 ...
33833  
33834 \newline
33835 i >>= 4; 
33836 \newline
33837 ...
33838 \end_layout
33839
33840 \begin_layout Standard
33841 generates the following code:
33842 \end_layout
33843
33844 \begin_layout Verse
33845
33846 \family typewriter
33847 mov\InsetSpace ~
33848  a,_i 
33849 \newline
33850 swap a 
33851 \newline
33852 anl\InsetSpace ~
33853  a,#0x0f 
33854 \newline
33855 mov\InsetSpace ~
33856  _i,a
33857 \end_layout
33858
33859 \begin_layout Standard
33860 In general SDCC will never setup a loop if the shift count is known.
33861  Another example:
33862 \end_layout
33863
33864 \begin_layout Verse
33865
33866 \family typewriter
33867 unsigned int i; 
33868 \newline
33869 ...
33870  
33871 \newline
33872 i >>= 9; 
33873 \newline
33874 ...
33875 \end_layout
33876
33877 \begin_layout Standard
33878 will generate:
33879 \end_layout
33880
33881 \begin_layout Verse
33882
33883 \family typewriter
33884 mov\InsetSpace ~
33885 \InsetSpace ~
33886 a,(_i + 1) 
33887 \newline
33888 mov\InsetSpace ~
33889 \InsetSpace ~
33890 (_i + 1),#0x00 
33891 \newline
33892 clr\InsetSpace ~
33893 \InsetSpace ~
33894
33895 \newline
33896 rrc\InsetSpace ~
33897 \InsetSpace ~
33898
33899 \newline
33900 mov\InsetSpace ~
33901 \InsetSpace ~
33902 _i,a
33903 \end_layout
33904
33905 \begin_layout Subsection
33906 Bit-rotation
33907 \begin_inset LatexCommand \index{Bit rotation}
33908
33909 \end_inset
33910
33911
33912 \end_layout
33913
33914 \begin_layout Standard
33915 A special case of the bit-shift operation is bit rotation
33916 \begin_inset LatexCommand \index{rotating bits}
33917
33918 \end_inset
33919
33920 , SDCC recognizes the following expression to be a left bit-rotation:
33921 \end_layout
33922
33923 \begin_layout Verse
33924
33925 \family typewriter
33926 \series bold
33927 unsigned
33928 \series default
33929 \InsetSpace ~
33930 \InsetSpace ~
33931 char i;\InsetSpace ~
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 \InsetSpace ~
33935 \InsetSpace ~
33936 \InsetSpace ~
33937 \InsetSpace ~
33938 \InsetSpace ~
33939 \InsetSpace ~
33940 \InsetSpace ~
33941 \InsetSpace ~
33942 /* unsigned is needed for rotation */ 
33943 \newline
33944 ...
33945  
33946 \newline
33947 i = ((i << 1) | (i >> 7)); 
33948 \family default
33949
33950 \newline
33951
33952 \family typewriter
33953 ...
33954 \end_layout
33955
33956 \begin_layout Standard
33957 will generate the following code:
33958 \end_layout
33959
33960 \begin_layout Verse
33961
33962 \family typewriter
33963 mov\InsetSpace ~
33964 \InsetSpace ~
33965 a,_i 
33966 \newline
33967 rl\InsetSpace ~
33968 \InsetSpace ~
33969 \InsetSpace ~
33970
33971 \newline
33972 mov\InsetSpace ~
33973 \InsetSpace ~
33974 _i,a
33975 \end_layout
33976
33977 \begin_layout Standard
33978 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33979 ns of this case will also be recognized as bit-rotation, i.e.: 
33980 \end_layout
33981
33982 \begin_layout Verse
33983
33984 \family typewriter
33985 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33986 \end_layout
33987
33988 \begin_layout Subsection
33989 Nibble and Byte Swapping
33990 \end_layout
33991
33992 \begin_layout Standard
33993 Other special cases of the bit-shift operations are nibble or byte swapping
33994 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33995
33996 \end_inset
33997
33998 , SDCC recognizes the following expressions:
33999 \end_layout
34000
34001 \begin_layout Verse
34002
34003 \family typewriter
34004 \series bold
34005 unsigned
34006 \series default
34007 \InsetSpace ~
34008 \InsetSpace ~
34009 char i; 
34010 \newline
34011
34012 \series bold
34013 unsigned
34014 \series default
34015 \InsetSpace ~
34016 \InsetSpace ~
34017 int j; 
34018 \newline
34019 ...
34020  
34021 \newline
34022 i = ((i << 4) | (i >> 4)); 
34023 \family default
34024
34025 \newline
34026
34027 \family typewriter
34028 j = ((j << 8) | (j >> 8)); 
34029 \end_layout
34030
34031 \begin_layout Standard
34032 and generates a swap instruction for the nibble swapping
34033 \begin_inset LatexCommand \index{Nibble swapping}
34034
34035 \end_inset
34036
34037  or move instructions for the byte swapping
34038 \begin_inset LatexCommand \index{Byte swapping}
34039
34040 \end_inset
34041
34042 .
34043  The 
34044 \begin_inset Quotes sld
34045 \end_inset
34046
34047 j
34048 \begin_inset Quotes srd
34049 \end_inset
34050
34051  example can be used to convert from little to big-endian or vice versa.
34052  If you want to change the endianness of a 
34053 \emph on
34054 signed
34055 \emph default
34056  integer you have to cast to 
34057 \family typewriter
34058 (unsigned int)
34059 \family default
34060  first.
34061 \end_layout
34062
34063 \begin_layout Standard
34064 Note that SDCC stores numbers in little-endian
34065 \begin_inset Foot
34066 status open
34067
34068 \begin_layout Standard
34069 Usually 8-bit processors don't care much about endianness.
34070  This is not the case for the standard 8051 which only has an instruction
34071  to increment its 
34072 \emph on
34073 dptr
34074 \emph default
34075
34076 \begin_inset LatexCommand \index{DPTR}
34077
34078 \end_inset
34079
34080 -datapointer
34081 \emph on
34082  
34083 \emph default
34084 so little-endian is the more efficient byte order.
34085 \end_layout
34086
34087 \end_inset
34088
34089
34090 \begin_inset LatexCommand \index{little-endian}
34091
34092 \end_inset
34093
34094
34095 \begin_inset LatexCommand \index{Endianness}
34096
34097 \end_inset
34098
34099  format (i.e.
34100  lowest order first).
34101 \end_layout
34102
34103 \begin_layout Subsection
34104 Highest Order Bit
34105 \begin_inset LatexCommand \index{Highest Order Bit}
34106
34107 \end_inset
34108
34109  / Any Order Bit
34110 \begin_inset LatexCommand \index{Any Order Bit}
34111
34112 \end_inset
34113
34114
34115 \end_layout
34116
34117 \begin_layout Standard
34118 It is frequently required to obtain the highest order bit of an integral
34119  type (long, int, short or char types).
34120  Also obtaining any other order bit is not uncommon.
34121  SDCC recognizes the following expressions to yield the highest order bit
34122  and generates optimized code for it, e.g.:
34123 \end_layout
34124
34125 \begin_layout Verse
34126
34127 \family typewriter
34128 unsigned int gint; 
34129 \newline
34130
34131 \newline
34132 foo () { 
34133 \newline
34134 \InsetSpace ~
34135 \InsetSpace ~
34136 unsigned char hob1, aob1; 
34137 \newline
34138 \InsetSpace ~
34139 \InsetSpace ~
34140 bit hob2, hob3, aob2,
34141  aob3; 
34142 \newline
34143 \InsetSpace ~
34144 \InsetSpace ~
34145 ...
34146  
34147 \newline
34148 \InsetSpace ~
34149 \InsetSpace ~
34150 hob1 = (gint >> 15) & 1; 
34151 \newline
34152 \InsetSpace ~
34153 \InsetSpace ~
34154 hob2 = (gint >> 15) & 1; 
34155 \newline
34156 \InsetSpace ~
34157 \InsetSpace ~
34158 hob3 = gint & 0x8000;
34159  
34160 \newline
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 aob1 = (gint >> 9) & 1; 
34164 \newline
34165 \InsetSpace ~
34166 \InsetSpace ~
34167 aob2 = (gint >> 8) & 1; 
34168 \newline
34169 \InsetSpace ~
34170 \InsetSpace ~
34171 aob3 = gint & 0x0800; 
34172 \newline
34173 \InsetSpace ~
34174 \InsetSpace ~
34175 ..
34176  
34177 \newline
34178 }
34179 \end_layout
34180
34181 \begin_layout Standard
34182 will generate the following code:
34183 \end_layout
34184
34185 \begin_layout Verse
34186
34187 \family typewriter
34188 \InsetSpace ~
34189 \InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194 \InsetSpace ~
34195 \InsetSpace ~
34196 \InsetSpace ~
34197 \InsetSpace ~
34198 \InsetSpace ~
34199 \InsetSpace ~
34200 \InsetSpace ~
34201 \InsetSpace ~
34202 \InsetSpace ~
34203 \InsetSpace ~
34204 \InsetSpace ~
34205 \InsetSpace ~
34206 \InsetSpace ~
34207 \InsetSpace ~
34208 \InsetSpace ~
34209 \InsetSpace ~
34210 \InsetSpace ~
34211 \InsetSpace ~
34212 \InsetSpace ~
34213  61 ;\InsetSpace ~
34214  hob.c 7 
34215 \newline
34216 000A E5*01\InsetSpace ~
34217 \InsetSpace ~
34218 \InsetSpace ~
34219 \InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225 \InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230 \InsetSpace ~
34231  62\InsetSpace ~
34232 \InsetSpace ~
34233 \InsetSpace ~
34234 \InsetSpace ~
34235 \InsetSpace ~
34236 \InsetSpace ~
34237 \InsetSpace ~
34238 \InsetSpace ~
34239  mov\InsetSpace ~
34240 \InsetSpace ~
34241  a,(_gint + 1) 
34242 \newline
34243 000C 23\InsetSpace ~
34244 \InsetSpace ~
34245 \InsetSpace ~
34246 \InsetSpace ~
34247 \InsetSpace ~
34248 \InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258 \InsetSpace ~
34259 \InsetSpace ~
34260 \InsetSpace ~
34261  63\InsetSpace ~
34262 \InsetSpace ~
34263 \InsetSpace ~
34264 \InsetSpace ~
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 \InsetSpace ~
34268 \InsetSpace ~
34269  rl\InsetSpace ~
34270 \InsetSpace ~
34271 \InsetSpace ~
34272  a 
34273 \newline
34274 000D 54 01\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
34290  64\InsetSpace ~
34291 \InsetSpace ~
34292 \InsetSpace ~
34293 \InsetSpace ~
34294 \InsetSpace ~
34295 \InsetSpace ~
34296 \InsetSpace ~
34297 \InsetSpace ~
34298  anl\InsetSpace ~
34299 \InsetSpace ~
34300  a,#0x01 
34301 \newline
34302 000F F5*02\InsetSpace ~
34303 \InsetSpace ~
34304 \InsetSpace ~
34305 \InsetSpace ~
34306 \InsetSpace ~
34307 \InsetSpace ~
34308 \InsetSpace ~
34309 \InsetSpace ~
34310 \InsetSpace ~
34311 \InsetSpace ~
34312 \InsetSpace ~
34313 \InsetSpace ~
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 \InsetSpace ~
34317  65\InsetSpace ~
34318 \InsetSpace ~
34319 \InsetSpace ~
34320 \InsetSpace ~
34321 \InsetSpace ~
34322 \InsetSpace ~
34323 \InsetSpace ~
34324 \InsetSpace ~
34325  mov\InsetSpace ~
34326 \InsetSpace ~
34327  _foo_hob1_1_1,a 
34328 \newline
34329 \InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 \InsetSpace ~
34337 \InsetSpace ~
34338 \InsetSpace ~
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345 \InsetSpace ~
34346 \InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354  66 ;\InsetSpace ~
34355  hob.c 8 
34356 \newline
34357 0011 E5*01\InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369 \InsetSpace ~
34370 \InsetSpace ~
34371 \InsetSpace ~
34372
34373  67\InsetSpace ~
34374 \InsetSpace ~
34375 \InsetSpace ~
34376 \InsetSpace ~
34377 \InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381  mov\InsetSpace ~
34382 \InsetSpace ~
34383  a,(_gint + 1) 
34384 \newline
34385 0013 33\InsetSpace ~
34386 \InsetSpace ~
34387 \InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392 \InsetSpace ~
34393 \InsetSpace ~
34394 \InsetSpace ~
34395 \InsetSpace ~
34396 \InsetSpace ~
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 \InsetSpace ~
34401 \InsetSpace ~
34402 \InsetSpace ~
34403  68\InsetSpace ~
34404 \InsetSpace ~
34405 \InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411  rlc\InsetSpace ~
34412 \InsetSpace ~
34413  a 
34414 \newline
34415 0014 92*00\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  69\InsetSpace ~
34431 \InsetSpace ~
34432 \InsetSpace ~
34433 \InsetSpace ~
34434 \InsetSpace ~
34435 \InsetSpace ~
34436 \InsetSpace ~
34437 \InsetSpace ~
34438  mov\InsetSpace ~
34439 \InsetSpace ~
34440  _foo_hob2_1_1,c
34441  
34442 \newline
34443 \InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450 \InsetSpace ~
34451 \InsetSpace ~
34452 \InsetSpace ~
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457 \InsetSpace ~
34458 \InsetSpace ~
34459 \InsetSpace ~
34460 \InsetSpace ~
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 \InsetSpace ~
34464 \InsetSpace ~
34465 \InsetSpace ~
34466 \InsetSpace ~
34467 \InsetSpace ~
34468  66 ;\InsetSpace ~
34469  hob.c 9 
34470 \newline
34471 0016 E5*01\InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 \InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486  67\InsetSpace ~
34487 \InsetSpace ~
34488 \InsetSpace ~
34489 \InsetSpace ~
34490 \InsetSpace ~
34491 \InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494  mov\InsetSpace ~
34495 \InsetSpace ~
34496  a,(_gint + 1) 
34497 \newline
34498 0018 33\InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505 \InsetSpace ~
34506 \InsetSpace ~
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513 \InsetSpace ~
34514 \InsetSpace ~
34515 \InsetSpace ~
34516  68\InsetSpace ~
34517 \InsetSpace ~
34518 \InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521 \InsetSpace ~
34522 \InsetSpace ~
34523 \InsetSpace ~
34524  rlc\InsetSpace ~
34525 \InsetSpace ~
34526  a 
34527 \newline
34528 0019 92*01\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
34544  69\InsetSpace ~
34545 \InsetSpace ~
34546 \InsetSpace ~
34547 \InsetSpace ~
34548 \InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552  mov\InsetSpace ~
34553 \InsetSpace ~
34554  _foo_hob3_1_1,c 
34555 \newline
34556 \InsetSpace ~
34557 \InsetSpace ~
34558 \InsetSpace ~
34559 \InsetSpace ~
34560 \InsetSpace ~
34561 \InsetSpace ~
34562 \InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 \InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 \InsetSpace ~
34570 \InsetSpace ~
34571 \InsetSpace ~
34572 \InsetSpace ~
34573 \InsetSpace ~
34574 \InsetSpace ~
34575 \InsetSpace ~
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 \InsetSpace ~
34581  70 ;\InsetSpace ~
34582  hob.c 10 
34583 \newline
34584 001B E5*01\InsetSpace ~
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 \InsetSpace ~
34588 \InsetSpace ~
34589 \InsetSpace ~
34590 \InsetSpace ~
34591 \InsetSpace ~
34592 \InsetSpace ~
34593 \InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 \InsetSpace ~
34598 \InsetSpace ~
34599  71\InsetSpace ~
34600 \InsetSpace ~
34601 \InsetSpace ~
34602 \InsetSpace ~
34603 \InsetSpace ~
34604 \InsetSpace ~
34605 \InsetSpace ~
34606 \InsetSpace ~
34607  mov\InsetSpace ~
34608 \InsetSpace ~
34609  a,(_gint + 1) 
34610 \newline
34611 001D
34612  03\InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617 \InsetSpace ~
34618 \InsetSpace ~
34619 \InsetSpace ~
34620 \InsetSpace ~
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 \InsetSpace ~
34624 \InsetSpace ~
34625 \InsetSpace ~
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 \InsetSpace ~
34630  72\InsetSpace ~
34631 \InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638  rr\InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641  a 
34642 \newline
34643 001E 54 01\InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 \InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657 \InsetSpace ~
34658  73\InsetSpace ~
34659 \InsetSpace ~
34660 \InsetSpace ~
34661 \InsetSpace ~
34662 \InsetSpace ~
34663 \InsetSpace ~
34664 \InsetSpace ~
34665 \InsetSpace ~
34666  anl\InsetSpace ~
34667 \InsetSpace ~
34668  a,#0x01 
34669 \newline
34670 0020 F5*03\InsetSpace ~
34671 \InsetSpace ~
34672 \InsetSpace ~
34673 \InsetSpace ~
34674 \InsetSpace ~
34675 \InsetSpace ~
34676 \InsetSpace ~
34677 \InsetSpace ~
34678 \InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685  74\InsetSpace ~
34686 \InsetSpace ~
34687 \InsetSpace ~
34688 \InsetSpace ~
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693  mov\InsetSpace ~
34694 \InsetSpace ~
34695  _foo_aob1_1_1,a
34696  
34697 \newline
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 \InsetSpace ~
34703 \InsetSpace ~
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713 \InsetSpace ~
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723  75 ;\InsetSpace ~
34724  hob.c 11 
34725 \newline
34726 0022 E5*01\InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729 \InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739 \InsetSpace ~
34740 \InsetSpace ~
34741  76\InsetSpace ~
34742 \InsetSpace ~
34743 \InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749  mov\InsetSpace ~
34750 \InsetSpace ~
34751  a,(_gint + 1) 
34752 \newline
34753 0024 13\InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766 \InsetSpace ~
34767 \InsetSpace ~
34768 \InsetSpace ~
34769 \InsetSpace ~
34770 \InsetSpace ~
34771  77\InsetSpace ~
34772 \InsetSpace ~
34773 \InsetSpace ~
34774 \InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779  rrc\InsetSpace ~
34780 \InsetSpace ~
34781  a 
34782 \newline
34783 0025 92*02\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
34799  78\InsetSpace ~
34800 \InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803 \InsetSpace ~
34804 \InsetSpace ~
34805 \InsetSpace ~
34806 \InsetSpace ~
34807  mov\InsetSpace ~
34808 \InsetSpace ~
34809  _foo_aob2_1_1,c 
34810 \newline
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828 \InsetSpace ~
34829 \InsetSpace ~
34830 \InsetSpace ~
34831 \InsetSpace ~
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836  79 ;\InsetSpace ~
34837  hob.c 12 
34838 \newline
34839 0027 E5*01\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  80\InsetSpace ~
34855 \InsetSpace ~
34856 \InsetSpace ~
34857 \InsetSpace ~
34858 \InsetSpace ~
34859 \InsetSpace ~
34860 \InsetSpace ~
34861 \InsetSpace ~
34862  mov\InsetSpace ~
34863 \InsetSpace ~
34864  a,(_gint + 1) 
34865 \newline
34866 0029
34867  A2 E3\InsetSpace ~
34868 \InsetSpace ~
34869 \InsetSpace ~
34870 \InsetSpace ~
34871 \InsetSpace ~
34872 \InsetSpace ~
34873 \InsetSpace ~
34874 \InsetSpace ~
34875 \InsetSpace ~
34876 \InsetSpace ~
34877 \InsetSpace ~
34878 \InsetSpace ~
34879 \InsetSpace ~
34880 \InsetSpace ~
34881 \InsetSpace ~
34882  81\InsetSpace ~
34883 \InsetSpace ~
34884 \InsetSpace ~
34885 \InsetSpace ~
34886 \InsetSpace ~
34887 \InsetSpace ~
34888 \InsetSpace ~
34889 \InsetSpace ~
34890  mov\InsetSpace ~
34891 \InsetSpace ~
34892  c,acc[3] 
34893 \newline
34894 002B 92*03\InsetSpace ~
34895 \InsetSpace ~
34896 \InsetSpace ~
34897 \InsetSpace ~
34898 \InsetSpace ~
34899 \InsetSpace ~
34900 \InsetSpace ~
34901 \InsetSpace ~
34902 \InsetSpace ~
34903 \InsetSpace ~
34904 \InsetSpace ~
34905 \InsetSpace ~
34906 \InsetSpace ~
34907 \InsetSpace ~
34908 \InsetSpace ~
34909  82\InsetSpace ~
34910 \InsetSpace ~
34911 \InsetSpace ~
34912 \InsetSpace ~
34913 \InsetSpace ~
34914 \InsetSpace ~
34915 \InsetSpace ~
34916 \InsetSpace ~
34917  mov\InsetSpace ~
34918 \InsetSpace ~
34919  _foo_aob3_1_1,c 
34920 \end_layout
34921
34922 \begin_layout Standard
34923 Other variations of these cases however will 
34924 \emph on
34925 not
34926 \emph default
34927  be recognized.
34928  They are standard C expressions, so I heartily recommend these be the only
34929  way to get the highest order bit, (it is portable).
34930  Of course it will be recognized even if it is embedded in other expressions,
34931  e.g.:
34932 \end_layout
34933
34934 \begin_layout Verse
34935
34936 \family typewriter
34937 xyz = gint + ((gint >> 15) & 1);
34938 \end_layout
34939
34940 \begin_layout Standard
34941 will still be recognized.
34942 \end_layout
34943
34944 \begin_layout Subsection
34945 Higher Order Byte
34946 \begin_inset LatexCommand \index{Higher Order Byte}
34947
34948 \end_inset
34949
34950  / Higher Order Word
34951 \begin_inset LatexCommand \index{Higher Order Word}
34952
34953 \end_inset
34954
34955
34956 \end_layout
34957
34958 \begin_layout Standard
34959 It is also frequently required to obtain a higher order byte or word of
34960  a larger integral type (long, int or short types).
34961  SDCC recognizes the following expressions to yield the higher order byte
34962  or word and generates optimized code for it, e.g.:
34963 \end_layout
34964
34965 \begin_layout Verse
34966
34967 \family typewriter
34968 unsigned int gint; 
34969 \newline
34970 unsigned long int glong; 
34971 \newline
34972
34973 \newline
34974 foo () { 
34975 \newline
34976 \InsetSpace ~
34977 \InsetSpace ~
34978 unsigned char hob1,
34979  hob2; 
34980 \newline
34981 \InsetSpace ~
34982 \InsetSpace ~
34983 unsigned int how1, how2; 
34984 \newline
34985 \InsetSpace ~
34986 \InsetSpace ~
34987 ...
34988  
34989 \newline
34990 \InsetSpace ~
34991 \InsetSpace ~
34992 hob1 = (gint >> 8) & 0xFF; 
34993 \newline
34994 \InsetSpace ~
34995 \InsetSpace ~
34996 hob2 = glong >> 24; 
34997 \newline
34998 \InsetSpace ~
34999 \InsetSpace ~
35000 how1 = (glong >> 16) & 0xFFFF;
35001  
35002 \newline
35003 \InsetSpace ~
35004 \InsetSpace ~
35005 how2 = glong >> 8; 
35006 \newline
35007 \InsetSpace ~
35008 \InsetSpace ~
35009 ..
35010  
35011 \newline
35012 }
35013 \end_layout
35014
35015 \begin_layout Standard
35016 will generate the following code:
35017 \end_layout
35018
35019 \begin_layout Verse
35020
35021 \family typewriter
35022 \InsetSpace ~
35023 \InsetSpace ~
35024 \InsetSpace ~
35025 \InsetSpace ~
35026 \InsetSpace ~
35027 \InsetSpace ~
35028 \InsetSpace ~
35029 \InsetSpace ~
35030 \InsetSpace ~
35031 \InsetSpace ~
35032 \InsetSpace ~
35033 \InsetSpace ~
35034 \InsetSpace ~
35035 \InsetSpace ~
35036 \InsetSpace ~
35037 \InsetSpace ~
35038 \InsetSpace ~
35039 \InsetSpace ~
35040 \InsetSpace ~
35041 \InsetSpace ~
35042 \InsetSpace ~
35043 \InsetSpace ~
35044 \InsetSpace ~
35045 \InsetSpace ~
35046 \InsetSpace ~
35047  91 ;\InsetSpace ~
35048  hob.c 15 
35049 \newline
35050 0037 85*01*06\InsetSpace ~
35051 \InsetSpace ~
35052 \InsetSpace ~
35053 \InsetSpace ~
35054 \InsetSpace ~
35055 \InsetSpace ~
35056 \InsetSpace ~
35057 \InsetSpace ~
35058 \InsetSpace ~
35059 \InsetSpace ~
35060 \InsetSpace ~
35061 \InsetSpace ~
35062  92\InsetSpace ~
35063 \InsetSpace ~
35064 \InsetSpace ~
35065 \InsetSpace ~
35066 \InsetSpace ~
35067 \InsetSpace ~
35068 \InsetSpace ~
35069 \InsetSpace ~
35070  mov\InsetSpace ~
35071 \InsetSpace ~
35072  _foo_hob1_1_1,(_gint + 1) 
35073 \newline
35074 \InsetSpace ~
35075 \InsetSpace ~
35076 \InsetSpace ~
35077 \InsetSpace ~
35078 \InsetSpace ~
35079 \InsetSpace ~
35080 \InsetSpace ~
35081 \InsetSpace ~
35082 \InsetSpace ~
35083 \InsetSpace ~
35084 \InsetSpace ~
35085 \InsetSpace ~
35086 \InsetSpace ~
35087 \InsetSpace ~
35088 \InsetSpace ~
35089 \InsetSpace ~
35090 \InsetSpace ~
35091 \InsetSpace ~
35092 \InsetSpace ~
35093 \InsetSpace ~
35094 \InsetSpace ~
35095 \InsetSpace ~
35096 \InsetSpace ~
35097 \InsetSpace ~
35098 \InsetSpace ~
35099  93 ;\InsetSpace ~
35100  hob.c
35101  16 
35102 \newline
35103 003A 85*05*07\InsetSpace ~
35104 \InsetSpace ~
35105 \InsetSpace ~
35106 \InsetSpace ~
35107 \InsetSpace ~
35108 \InsetSpace ~
35109 \InsetSpace ~
35110 \InsetSpace ~
35111 \InsetSpace ~
35112 \InsetSpace ~
35113 \InsetSpace ~
35114 \InsetSpace ~
35115  94\InsetSpace ~
35116 \InsetSpace ~
35117 \InsetSpace ~
35118 \InsetSpace ~
35119 \InsetSpace ~
35120 \InsetSpace ~
35121 \InsetSpace ~
35122 \InsetSpace ~
35123  mov\InsetSpace ~
35124 \InsetSpace ~
35125  _foo_hob2_1_1,(_glong + 3) 
35126 \newline
35127 \InsetSpace ~
35128 \InsetSpace ~
35129 \InsetSpace ~
35130 \InsetSpace ~
35131 \InsetSpace ~
35132 \InsetSpace ~
35133 \InsetSpace ~
35134 \InsetSpace ~
35135 \InsetSpace ~
35136 \InsetSpace ~
35137 \InsetSpace ~
35138 \InsetSpace ~
35139 \InsetSpace ~
35140 \InsetSpace ~
35141 \InsetSpace ~
35142 \InsetSpace ~
35143 \InsetSpace ~
35144 \InsetSpace ~
35145 \InsetSpace ~
35146 \InsetSpace ~
35147 \InsetSpace ~
35148 \InsetSpace ~
35149 \InsetSpace ~
35150 \InsetSpace ~
35151 \InsetSpace ~
35152  95 ;\InsetSpace ~
35153  hob.c 17 
35154 \newline
35155 003D 85*04*08\InsetSpace ~
35156 \InsetSpace ~
35157 \InsetSpace ~
35158 \InsetSpace ~
35159 \InsetSpace ~
35160 \InsetSpace ~
35161 \InsetSpace ~
35162 \InsetSpace ~
35163 \InsetSpace ~
35164 \InsetSpace ~
35165 \InsetSpace ~
35166 \InsetSpace ~
35167
35168  96\InsetSpace ~
35169 \InsetSpace ~
35170 \InsetSpace ~
35171 \InsetSpace ~
35172 \InsetSpace ~
35173 \InsetSpace ~
35174 \InsetSpace ~
35175 \InsetSpace ~
35176  mov\InsetSpace ~
35177 \InsetSpace ~
35178  _foo_how1_1_1,(_glong + 2) 
35179 \newline
35180 0040 85*05*09\InsetSpace ~
35181 \InsetSpace ~
35182 \InsetSpace ~
35183 \InsetSpace ~
35184 \InsetSpace ~
35185 \InsetSpace ~
35186 \InsetSpace ~
35187 \InsetSpace ~
35188 \InsetSpace ~
35189 \InsetSpace ~
35190 \InsetSpace ~
35191 \InsetSpace ~
35192  97\InsetSpace ~
35193 \InsetSpace ~
35194 \InsetSpace ~
35195 \InsetSpace ~
35196 \InsetSpace ~
35197 \InsetSpace ~
35198 \InsetSpace ~
35199 \InsetSpace ~
35200  mov\InsetSpace ~
35201 \InsetSpace ~
35202  (_foo_how1_1_1 +
35203  1),(_glong + 3) 
35204 \newline
35205 0043 85*03*0A\InsetSpace ~
35206 \InsetSpace ~
35207 \InsetSpace ~
35208 \InsetSpace ~
35209 \InsetSpace ~
35210 \InsetSpace ~
35211 \InsetSpace ~
35212 \InsetSpace ~
35213 \InsetSpace ~
35214 \InsetSpace ~
35215 \InsetSpace ~
35216 \InsetSpace ~
35217  98\InsetSpace ~
35218 \InsetSpace ~
35219 \InsetSpace ~
35220 \InsetSpace ~
35221 \InsetSpace ~
35222 \InsetSpace ~
35223 \InsetSpace ~
35224 \InsetSpace ~
35225  mov\InsetSpace ~
35226 \InsetSpace ~
35227  _foo_how2_1_1,(_glong + 1) 
35228 \newline
35229 0046 85*04*0B\InsetSpace ~
35230 \InsetSpace ~
35231 \InsetSpace ~
35232 \InsetSpace ~
35233 \InsetSpace ~
35234 \InsetSpace ~
35235 \InsetSpace ~
35236 \InsetSpace ~
35237 \InsetSpace ~
35238 \InsetSpace ~
35239 \InsetSpace ~
35240 \InsetSpace ~
35241
35242  99\InsetSpace ~
35243 \InsetSpace ~
35244 \InsetSpace ~
35245 \InsetSpace ~
35246 \InsetSpace ~
35247 \InsetSpace ~
35248 \InsetSpace ~
35249 \InsetSpace ~
35250  mov\InsetSpace ~
35251 \InsetSpace ~
35252  (_foo_how2_1_1 + 1),(_glong + 2) 
35253 \end_layout
35254
35255 \begin_layout Standard
35256 Again, variations of these cases may 
35257 \emph on
35258 not
35259 \emph default
35260  be recognized.
35261  They are standard C expressions, so I heartily recommend these be the only
35262  way to get the higher order byte/word, (it is portable).
35263  Of course it will be recognized even if it is embedded in other expressions,
35264  e.g.:
35265 \end_layout
35266
35267 \begin_layout Verse
35268
35269 \family typewriter
35270 xyz = gint + ((gint >> 8) & 0xFF);
35271 \end_layout
35272
35273 \begin_layout Standard
35274 will still be recognized.
35275 \end_layout
35276
35277 \begin_layout Subsection
35278 Peephole Optimizer
35279 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35280
35281 \end_inset
35282
35283
35284 \begin_inset LatexCommand \index{Peephole optimizer}
35285
35286 \end_inset
35287
35288
35289 \end_layout
35290
35291 \begin_layout Standard
35292 The compiler uses a rule based, pattern matching and re-writing mechanism
35293  for peep-hole optimization.
35294  It is inspired by 
35295 \emph on
35296 copt
35297 \emph default
35298  a peep-hole optimizer by Christopher W.
35299  Fraser (cwfraser\InsetSpace ~
35300 @\InsetSpace ~
35301 microsoft.com).
35302  A default set of rules are compiled into the compiler, additional rules
35303  may be added with the 
35304 \emph on
35305 -
35306 \begin_inset ERT
35307 status collapsed
35308
35309 \begin_layout Standard
35310
35311
35312 \backslash
35313 /
35314 \end_layout
35315
35316 \end_inset
35317
35318 -peep-file
35319 \begin_inset LatexCommand \index{-\/-peep-file}
35320
35321 \end_inset
35322
35323  <filename>
35324 \emph default
35325  option.
35326  The rule language is best illustrated with examples.
35327 \end_layout
35328
35329 \begin_layout Verse
35330
35331 \family typewriter
35332 replace { 
35333 \newline
35334 \InsetSpace ~
35335 \InsetSpace ~
35336 mov %1,a 
35337 \newline
35338 \InsetSpace ~
35339 \InsetSpace ~
35340 mov a,%1
35341 \newline
35342 } by {
35343 \newline
35344 \InsetSpace ~
35345 \InsetSpace ~
35346 mov %1,a
35347 \newline
35348 }
35349 \end_layout
35350
35351 \begin_layout Standard
35352 The above rule will change the following assembly
35353 \begin_inset LatexCommand \index{Assembler routines}
35354
35355 \end_inset
35356
35357  sequence:
35358 \end_layout
35359
35360 \begin_layout Verse
35361
35362 \family typewriter
35363 mov r1,a 
35364 \newline
35365 mov a,r1
35366 \end_layout
35367
35368 \begin_layout Standard
35369 to
35370 \end_layout
35371
35372 \begin_layout Verse
35373
35374 \family typewriter
35375 mov r1,a
35376 \end_layout
35377
35378 \begin_layout Standard
35379 Note: All occurrences of a 
35380 \emph on
35381 %n
35382 \emph default
35383  (pattern variable) must denote the same string.
35384  With the above rule, the assembly sequence:
35385 \end_layout
35386
35387 \begin_layout Verse
35388
35389 \family typewriter
35390 mov r1,a 
35391 \newline
35392 mov a,r2
35393 \end_layout
35394
35395 \begin_layout Standard
35396 will remain unmodified.
35397 \newline
35398
35399 \newline
35400 Other special case optimizations may be added by the
35401  user (via 
35402 \emph on
35403 -
35404 \begin_inset ERT
35405 status collapsed
35406
35407 \begin_layout Standard
35408
35409
35410 \backslash
35411 /
35412 \end_layout
35413
35414 \end_inset
35415
35416 -peep-file option
35417 \emph default
35418 ).
35419  E.g.
35420  some variants of the 8051 MCU
35421 \begin_inset LatexCommand \index{MCS51 variants}
35422
35423 \end_inset
35424
35425  allow only 
35426 \family typewriter
35427 ajmp
35428 \family default
35429  and 
35430 \family typewriter
35431 acall
35432 \family default
35433 .
35434  The following two rules will change all 
35435 \family typewriter
35436 ljmp
35437 \family default
35438  and 
35439 \family typewriter
35440 lcall
35441 \family default
35442  to 
35443 \family typewriter
35444 ajmp
35445 \family default
35446  and 
35447 \family typewriter
35448 acall
35449 \end_layout
35450
35451 \begin_layout Verse
35452
35453 \family typewriter
35454 replace { lcall %1 } by { acall %1 } 
35455 \newline
35456 replace { ljmp %1 } by { ajmp %1 }
35457 \end_layout
35458
35459 \begin_layout Standard
35460 The 
35461 \emph on
35462 inline-assembler code
35463 \emph default
35464  is also passed through the peep hole optimizer, thus the peephole optimizer
35465  can also be used as an assembly level macro expander.
35466  The rules themselves are MCU dependent whereas the rule language infra-structur
35467 e is MCU independent.
35468  Peephole optimization rules for other MCU can be easily programmed using
35469  the rule language.
35470 \newline
35471
35472 \newline
35473 The syntax for a rule is as follows:
35474 \end_layout
35475
35476 \begin_layout Verse
35477
35478 \family typewriter
35479 rule := replace [ restart ] '{' <assembly sequence> '
35480 \backslash
35481 n' 
35482 \newline
35483 \InsetSpace ~
35484  \InsetSpace ~
35485  \InsetSpace ~
35486  \InsetSpace ~
35487  \InsetSpace ~
35488  \InsetSpace ~
35489  \InsetSpace ~
35490  \InsetSpace ~
35491  \InsetSpace ~
35492  \InsetSpace ~
35493  \InsetSpace ~
35494  \InsetSpace ~
35495  \InsetSpace ~
35496  \InsetSpace ~
35497  '}' by '{' '
35498 \backslash
35499 n' 
35500 \newline
35501 \InsetSpace ~
35502  \InsetSpace ~
35503  \InsetSpace ~
35504  \InsetSpace ~
35505  \InsetSpace ~
35506  \InsetSpace ~
35507  \InsetSpace ~
35508  \InsetSpace ~
35509  \InsetSpace ~
35510  \InsetSpace ~
35511  \InsetSpace ~
35512  \InsetSpace ~
35513  \InsetSpace ~
35514  \InsetSpace ~
35515  \InsetSpace ~
35516  \InsetSpace ~
35517  <assembly sequence> '
35518 \backslash
35519 n' 
35520 \newline
35521 \InsetSpace ~
35522  \InsetSpace ~
35523  \InsetSpace ~
35524  \InsetSpace ~
35525  \InsetSpace ~
35526  \InsetSpace ~
35527  \InsetSpace ~
35528  \InsetSpace ~
35529  \InsetSpace ~
35530  \InsetSpace ~
35531  \InsetSpace ~
35532  \InsetSpace ~
35533  \InsetSpace ~
35534  \InsetSpace ~
35535  '}' [if <functionName> ] '
35536 \backslash
35537 n' 
35538 \end_layout
35539
35540 \begin_layout Standard
35541 <assembly sequence> := assembly instruction (each instruction including
35542  labels must be on a separate line).
35543 \newline
35544
35545 \newline
35546 The optimizer will apply to the rules
35547  one by one from the top in the sequence of their appearance, it will terminate
35548  when all rules are exhausted.
35549  If the 'restart' option is specified, then the optimizer will start matching
35550  the rules again from the top, this option for a rule is expensive (performance)
35551 , it is intended to be used in situations where a transformation will trigger
35552  the same rule again.
35553  An example of this (not a good one, it has side effects) is the following
35554  rule:
35555 \end_layout
35556
35557 \begin_layout Verse
35558
35559 \family typewriter
35560 replace restart { 
35561 \newline
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 pop %1 
35565 \newline
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 push %1 } by { 
35569 \newline
35570 \InsetSpace ~
35571 \InsetSpace ~
35572 ; nop 
35573 \newline
35574 }
35575 \end_layout
35576
35577 \begin_layout Standard
35578 Note that the replace pattern cannot be a blank, but can be a comment line.
35579  Without the 'restart' option only the innermost 'pop' 'push' pair would
35580  be eliminated, i.e.:
35581 \end_layout
35582
35583 \begin_layout Verse
35584
35585 \family typewriter
35586 pop ar1 
35587 \newline
35588 pop ar2 
35589 \newline
35590 push ar2 
35591 \newline
35592 push ar1
35593 \end_layout
35594
35595 \begin_layout Standard
35596 would result in:
35597 \end_layout
35598
35599 \begin_layout Verse
35600
35601 \family typewriter
35602 pop ar1 
35603 \newline
35604 ; nop 
35605 \newline
35606 push ar1
35607 \end_layout
35608
35609 \begin_layout Standard
35610
35611 \emph on
35612 with
35613 \emph default
35614  the restart option the rule will be applied again to the resulting code
35615  and then all the pop-push pairs will be eliminated to yield:
35616 \end_layout
35617
35618 \begin_layout Verse
35619
35620 \family typewriter
35621 ; nop 
35622 \newline
35623 ; nop
35624 \end_layout
35625
35626 \begin_layout Standard
35627 A conditional function can be attached to a rule.
35628  Attaching rules are somewhat more involved, let me illustrate this with
35629  an example.
35630 \end_layout
35631
35632 \begin_layout Verse
35633
35634 \family typewriter
35635 replace { 
35636 \newline
35637 \InsetSpace ~
35638  \InsetSpace ~
35639  \InsetSpace ~
35640 ljmp %5 
35641 \newline
35642 %2:
35643 \newline
35644 } by { 
35645 \newline
35646 \InsetSpace ~
35647  \InsetSpace ~
35648  \InsetSpace ~
35649 sjmp %5 
35650 \newline
35651 %2:
35652 \newline
35653 } if labelInRange
35654 \end_layout
35655
35656 \begin_layout Standard
35657 The optimizer does a look-up of a function name table defined in function
35658  
35659 \emph on
35660 callFuncByName
35661 \emph default
35662  in the source file SDCCpeeph.c, with the name 
35663 \emph on
35664 labelInRange
35665 \emph default
35666 .
35667  If it finds a corresponding entry the function is called.
35668  Note there can be no parameters specified for these functions, in this
35669  case the use of 
35670 \emph on
35671 %5
35672 \emph default
35673  is crucial, since the function 
35674 \emph on
35675 labelInRange
35676 \emph default
35677  expects to find the label in that particular variable (the hash table containin
35678 g the variable bindings is passed as a parameter).
35679  If you want to code more such functions, take a close look at the function
35680  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35681  Currently implemented are 
35682 \emph on
35683 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35684  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35685 \emph default
35686 and
35687 \emph on
35688  notVolatile
35689 \emph default
35690 .
35691 \end_layout
35692
35693 \begin_layout Standard
35694 I know this whole thing is a little kludgey, but maybe some day we will
35695  have some better means.
35696  If you are looking at this file, you will see the default rules that are
35697  compiled into the compiler, you can add your own rules in the default set
35698  there if you get tired of specifying the -
35699 \begin_inset ERT
35700 status collapsed
35701
35702 \begin_layout Standard
35703
35704
35705 \backslash
35706 /
35707 \end_layout
35708
35709 \end_inset
35710
35711 -peep-file option.
35712 \end_layout
35713
35714 \begin_layout Section
35715 ANSI-Compliance
35716 \begin_inset LatexCommand \index{ANSI-compliance}
35717
35718 \end_inset
35719
35720
35721 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35722
35723 \end_inset
35724
35725
35726 \end_layout
35727
35728 \begin_layout Standard
35729 The latest publically available version of the standard 
35730 \emph on
35731 ISO/IEC 9899 - Programming languages - C
35732 \emph default
35733  should be available at: 
35734 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35735
35736 \end_inset
35737
35738 .
35739 \newline
35740
35741 \end_layout
35742
35743 \begin_layout Standard
35744 Deviations from the compliance:
35745 \end_layout
35746
35747 \begin_layout Itemize
35748 functions are not reentrant
35749 \begin_inset LatexCommand \index{reentrant}
35750
35751 \end_inset
35752
35753  unless explicitly declared as such or the 
35754 \series bold
35755 -
35756 \begin_inset ERT
35757 status collapsed
35758
35759 \begin_layout Standard
35760
35761
35762 \backslash
35763 /
35764 \end_layout
35765
35766 \end_inset
35767
35768 -stack-auto
35769 \begin_inset LatexCommand \index{-\/-stack-auto}
35770
35771 \end_inset
35772
35773
35774 \series default
35775  command line option is specified.
35776 \end_layout
35777
35778 \begin_layout Itemize
35779 structures
35780 \begin_inset LatexCommand \index{struct}
35781
35782 \end_inset
35783
35784  and unions
35785 \begin_inset LatexCommand \index{union}
35786
35787 \end_inset
35788
35789  cannot be assigned values directly, cannot be passed as function parameters
35790  or assigned to each other and cannot be a return value
35791 \begin_inset LatexCommand \index{return value}
35792
35793 \end_inset
35794
35795  from a function, e.g.:
35796 \end_layout
35797
35798 \begin_deeper
35799 \begin_layout Verse
35800
35801 \family typewriter
35802 struct s { ...
35803  }; 
35804 \newline
35805 struct s s1, s2; 
35806 \newline
35807 foo() 
35808 \newline
35809
35810 \newline
35811 \InsetSpace ~
35812 \InsetSpace ~
35813 \InsetSpace ~
35814 \InsetSpace ~
35815 ...
35816  
35817 \newline
35818 \InsetSpace ~
35819 \InsetSpace ~
35820 \InsetSpace ~
35821 \InsetSpace ~
35822 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35823 \newline
35824 \InsetSpace ~
35825 \InsetSpace ~
35826 \InsetSpace ~
35827 \InsetSpace ~
35828 ...
35829  
35830 \newline
35831 }
35832 \newline
35833
35834 \series bold
35835 struct
35836 \series default
35837  s foo1 (
35838 \series bold
35839 struct
35840 \series default
35841  s parms) /* invalid in SDCC although allowed in ANSI */
35842 \newline
35843
35844 \newline
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 struct s rets;
35850  
35851 \newline
35852 \InsetSpace ~
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 \InsetSpace ~
35856 ...
35857  
35858 \newline
35859 \InsetSpace ~
35860 \InsetSpace ~
35861 \InsetSpace ~
35862 \InsetSpace ~
35863 return rets; /* is invalid in SDCC although allowed in ANSI */ 
35864 \newline
35865 }
35866 \end_layout
35867
35868 \end_deeper
35869 \begin_layout Itemize
35870 initialization of structure arrays must be fully braced.
35871 \end_layout
35872
35873 \begin_deeper
35874 \begin_layout Verse
35875
35876 \family typewriter
35877 struct s { char x } a[] = {1, 2};\InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 /* invalid in SDCC */
35883 \newline
35884 struct s { char x
35885  } a[] = {{1}, {2}}; /* OK */
35886 \end_layout
35887
35888 \end_deeper
35889 \begin_layout Itemize
35890 'long long
35891 \begin_inset LatexCommand \index{long long (not supported)}
35892
35893 \end_inset
35894
35895 ' (64 bit integers
35896 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35897
35898 \end_inset
35899
35900 ) not supported.
35901 \end_layout
35902
35903 \begin_layout Itemize
35904 'double
35905 \begin_inset LatexCommand \index{double (not supported)}
35906
35907 \end_inset
35908
35909 ' precision floating point 
35910 \begin_inset LatexCommand \index{Floating point support}
35911
35912 \end_inset
35913
35914 not supported.
35915 \end_layout
35916
35917 \begin_layout Itemize
35918 Old K&R style
35919 \begin_inset LatexCommand \index{K\&R style}
35920
35921 \end_inset
35922
35923  function declarations are NOT allowed.
35924 \end_layout
35925
35926 \begin_deeper
35927 \begin_layout Verse
35928
35929 \family typewriter
35930 foo(i,j) /* this old style of function declarations */ 
35931 \newline
35932 int i,j; /* are valid
35933  in ANSI but not valid in SDCC */ 
35934 \newline
35935
35936 \newline
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941 ...
35942  
35943 \newline
35944 }
35945 \end_layout
35946
35947 \end_deeper
35948 \begin_layout Itemize
35949 Most enhancements in C99 are not supported, f.e.:
35950 \end_layout
35951
35952 \begin_deeper
35953 \begin_layout Verse
35954
35955 \family typewriter
35956 \series bold
35957 inline
35958 \begin_inset LatexCommand \index{inline (not supported)}
35959
35960 \end_inset
35961
35962
35963 \series default
35964  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35965  in C99.
35966  An empty define 
35967 \emph on
35968 #define inline
35969 \emph default
35970  can be used as a work around */
35971 \newline
35972
35973 \newline
35974 for (
35975 \series bold
35976 int
35977 \series default
35978  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35979 \end_layout
35980
35981 \end_deeper
35982 \begin_layout Itemize
35983 Certain words that are valid identifiers in the standard may be reserved
35984  words in SDCC unless the 
35985 \series bold
35986 -
35987 \begin_inset ERT
35988 status collapsed
35989
35990 \begin_layout Standard
35991
35992
35993 \backslash
35994 /
35995 \end_layout
35996
35997 \end_inset
35998
35999 -std-c89
36000 \begin_inset LatexCommand \index{-\/-std-c89}
36001
36002 \end_inset
36003
36004  or -
36005 \begin_inset ERT
36006 status collapsed
36007
36008 \begin_layout Standard
36009
36010
36011 \backslash
36012 /
36013 \end_layout
36014
36015 \end_inset
36016
36017 -std-c99
36018 \begin_inset LatexCommand \index{-\/-std-c99}
36019
36020 \end_inset
36021
36022
36023 \series default
36024  command line options are used.
36025  These may include (depending on the selected processor): 'at', 'banked',
36026  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36027 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36028  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36029  '_naked'.
36030  Compliant equivalents of these keywords are always available in a form
36031  that begin with two underscores
36032 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36033
36034 \end_inset
36035
36036 , f.e.
36037  '__data' instead of 'data'.
36038 \end_layout
36039
36040 \begin_layout Section
36041 Cyclomatic Complexity
36042 \begin_inset LatexCommand \index{Cyclomatic complexity}
36043
36044 \end_inset
36045
36046
36047 \end_layout
36048
36049 \begin_layout Standard
36050 Cyclomatic complexity of a function is defined as the number of independent
36051  paths the program can take during execution of the function.
36052  This is an important number since it defines the number test cases you
36053  have to generate to validate the function.
36054  The accepted industry standard for complexity number is 10, if the cyclomatic
36055  complexity reported by SDCC exceeds 10 you should think about simplification
36056  of the function logic.
36057  Note that the complexity level is not related to the number of lines of
36058  code in a function.
36059  Large functions can have low complexity, and small functions can have large
36060  complexity levels.
36061  
36062 \newline
36063
36064 \newline
36065 SDCC uses the following formula to compute the complexity:
36066 \newline
36067
36068 \end_layout
36069
36070 \begin_layout Standard
36071 complexity = (number of edges in control flow graph) - (number of nodes
36072  in control flow graph) + 2;
36073 \newline
36074
36075 \newline
36076 Having said that the industry standard is 10,
36077  you should be aware that in some cases it be may unavoidable to have a
36078  complexity level of less than 10.
36079  For example if you have switch statement with more than 10 case labels,
36080  each case label adds one to the complexity level.
36081  The complexity level is by no means an absolute measure of the algorithmic
36082  complexity of the function, it does however provide a good starting point
36083  for which functions you might look at for further optimization.
36084 \end_layout
36085
36086 \begin_layout Section
36087 Retargetting for other Processors
36088 \end_layout
36089
36090 \begin_layout Standard
36091 The issues for retargetting the compiler are far too numerous to be covered
36092  by this document.
36093  What follows is a brief description of each of the seven phases of the
36094  compiler and its MCU dependency.
36095 \end_layout
36096
36097 \begin_layout Itemize
36098 Parsing the source and building the annotated parse tree.
36099  This phase is largely MCU independent (except for the language extensions).
36100  Syntax & semantic checks are also done in this phase, along with some initial
36101  optimizations like back patching labels and the pattern matching optimizations
36102  like bit-rotation etc.
36103 \end_layout
36104
36105 \begin_layout Itemize
36106 The second phase involves generating an intermediate code which can be easy
36107  manipulated during the later phases.
36108  This phase is entirely MCU independent.
36109  The intermediate code generation assumes the target machine has unlimited
36110  number of registers, and designates them with the name iTemp.
36111  The compiler can be made to dump a human readable form of the code generated
36112  by using the -
36113 \begin_inset ERT
36114 status collapsed
36115
36116 \begin_layout Standard
36117
36118
36119 \backslash
36120 /
36121 \end_layout
36122
36123 \end_inset
36124
36125 -dumpraw option.
36126 \end_layout
36127
36128 \begin_layout Itemize
36129 This phase does the bulk of the standard optimizations and is also MCU independe
36130 nt.
36131  This phase can be broken down into several sub-phases:
36132 \newline
36133
36134 \newline
36135 Break down intermediate
36136  code (iCode) into basic blocks.
36137 \newline
36138 Do control flow & data flow analysis on the
36139  basic blocks.
36140 \newline
36141 Do local common subexpression elimination, then global subexpressio
36142 n elimination
36143 \newline
36144 Dead code elimination
36145 \newline
36146 Loop optimizations
36147 \newline
36148 If loop optimizations
36149  caused any changes then do 'global subexpression elimination' and 'dead
36150  code elimination' again.
36151 \end_layout
36152
36153 \begin_layout Itemize
36154 This phase determines the live-ranges; by live range I mean those iTemp
36155  variables defined by the compiler that still survive after all the optimization
36156 s.
36157  Live range analysis
36158 \begin_inset LatexCommand \index{Live range analysis}
36159
36160 \end_inset
36161
36162  is essential for register allocation, since these computation determines
36163  which of these iTemps will be assigned to registers, and for how long.
36164 \end_layout
36165
36166 \begin_layout Itemize
36167 Phase five is register allocation.
36168  There are two parts to this process.
36169 \newline
36170
36171 \newline
36172 The first part I call 'register packing'
36173  (for lack of a better term).
36174  In this case several MCU specific expression folding is done to reduce
36175  register pressure.
36176 \newline
36177
36178 \newline
36179 The second part is more MCU independent and deals with
36180  allocating registers to the remaining live ranges.
36181  A lot of MCU specific code does creep into this phase because of the limited
36182  number of index registers available in the 8051.
36183 \end_layout
36184
36185 \begin_layout Itemize
36186 The Code generation phase is (unhappily), entirely MCU dependent and very
36187  little (if any at all) of this code can be reused for other MCU.
36188  However the scheme for allocating a homogenized assembler operand for each
36189  iCode operand may be reused.
36190 \end_layout
36191
36192 \begin_layout Itemize
36193 As mentioned in the optimization section the peep-hole optimizer is rule
36194  based system, which can reprogrammed for other MCUs.
36195 \end_layout
36196
36197 \begin_layout Standard
36198 More information is available in a wiki
36199 \begin_inset LatexCommand \index{wiki}
36200
36201 \end_inset
36202
36203  (preliminary link 
36204 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
36205
36206 \end_inset
36207
36208 ) and in the thread 
36209 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36210
36211 \end_inset
36212
36213  .
36214 \end_layout
36215
36216 \begin_layout Chapter
36217 Compiler internals
36218 \begin_inset LatexCommand \index{Compiler internals}
36219
36220 \end_inset
36221
36222
36223 \end_layout
36224
36225 \begin_layout Section
36226 The anatomy of the compiler
36227 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36228
36229 \end_inset
36230
36231
36232 \end_layout
36233
36234 \begin_layout Standard
36235
36236 \shape italic
36237 This is an excerpt from an article published in Circuit Cellar Magazine
36238  in 
36239 \series bold
36240 August 2000
36241 \series default
36242 .
36243  It's a little outdated (the compiler is much more efficient now and user/develo
36244 per friendly), but pretty well exposes the guts of it all.
36245 \shape default
36246
36247 \newline
36248
36249 \newline
36250 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36251  It is fairly easy to retarget for other 8-bit MCU.
36252  Here we take a look at some of the internals of the compiler.
36253  
36254 \end_layout
36255
36256 \begin_layout Paragraph*
36257 Parsing
36258 \begin_inset LatexCommand \index{Parsing}
36259
36260 \end_inset
36261
36262  
36263 \end_layout
36264
36265 \begin_layout Standard
36266 Parsing the input source file and creating an AST (Annotated Syntax Tree
36267 \begin_inset LatexCommand \index{Annotated syntax tree}
36268
36269 \end_inset
36270
36271 ).
36272  This phase also involves propagating types (annotating each node of the
36273  parse tree with type information) and semantic analysis.
36274  There are some MCU specific parsing rules.
36275  For example the storage classes, the extended storage classes are MCU specific
36276  while there may be a xdata storage class for 8051 there is no such storage
36277  class for z80 or Atmel AVR.
36278  SDCC allows MCU specific storage class extensions, i.e.
36279  xdata will be treated as a storage class specifier when parsing 8051 C
36280  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36281  C code.
36282 \end_layout
36283
36284 \begin_layout Paragraph*
36285 Generating iCode
36286 \begin_inset LatexCommand \index{iCode}
36287
36288 \end_inset
36289
36290
36291 \end_layout
36292
36293 \begin_layout Standard
36294 Intermediate code generation.
36295  In this phase the AST is broken down into three-operand form (iCode).
36296  These three operand forms are represented as doubly linked lists.
36297  ICode is the term given to the intermediate form generated by the compiler.
36298  ICode example section shows some examples of iCode generated for some simple
36299  C source functions.
36300 \end_layout
36301
36302 \begin_layout Paragraph*
36303 Optimizations
36304 \begin_inset LatexCommand \index{Optimizations}
36305
36306 \end_inset
36307
36308 .
36309 \end_layout
36310
36311 \begin_layout Standard
36312 Bulk of the target independent optimizations is performed in this phase.
36313  The optimizations include constant propagation, common sub-expression eliminati
36314 on, loop invariant code movement, strength reduction of loop induction variables
36315  and dead-code elimination.
36316 \end_layout
36317
36318 \begin_layout Paragraph*
36319 Live range analysis
36320 \begin_inset LatexCommand \index{Live range analysis}
36321
36322 \end_inset
36323
36324
36325 \end_layout
36326
36327 \begin_layout Standard
36328 During intermediate code generation phase, the compiler assumes the target
36329  machine has infinite number of registers and generates a lot of temporary
36330  variables.
36331  The live range computation determines the lifetime of each of these compiler-ge
36332 nerated temporaries.
36333  A picture speaks a thousand words.
36334  ICode example sections show the live range annotations for each of the
36335  operand.
36336  It is important to note here, each iCode is assigned a number in the order
36337  of its execution in the function.
36338  The live ranges are computed in terms of these numbers.
36339  The from number is the number of the iCode which first defines the operand
36340  and the to number signifies the iCode which uses this operand last.
36341 \end_layout
36342
36343 \begin_layout Paragraph*
36344 Register Allocation
36345 \begin_inset LatexCommand \index{Register allocation}
36346
36347 \end_inset
36348
36349
36350 \end_layout
36351
36352 \begin_layout Standard
36353 The register allocation determines the type and number of registers needed
36354  by each operand.
36355  In most MCUs only a few registers can be used for indirect addressing.
36356  In case of 8051 for example the registers R0 & R1 can be used to indirectly
36357  address the internal ram and DPTR to indirectly address the external ram.
36358  The compiler will try to allocate the appropriate register to pointer variables
36359  if it can.
36360  ICode example section shows the operands annotated with the registers assigned
36361  to them.
36362  The compiler will try to keep operands in registers as much as possible;
36363  there are several schemes the compiler uses to do achieve this.
36364  When the compiler runs out of registers the compiler will check to see
36365  if there are any live operands which is not used or defined in the current
36366  basic block being processed, if there are any found then it will push that
36367  operand and use the registers in this block, the operand will then be popped
36368  at the end of the basic block.
36369  
36370 \end_layout
36371
36372 \begin_layout Standard
36373 There are other MCU specific considerations in this phase.
36374  Some MCUs have an accumulator; very short-lived operands could be assigned
36375  to the accumulator instead of a general-purpose register.
36376 \end_layout
36377
36378 \begin_layout Paragraph*
36379 Code generation
36380 \end_layout
36381
36382 \begin_layout Standard
36383 Figure II gives a table of iCode
36384 \begin_inset LatexCommand \index{iCode}
36385
36386 \end_inset
36387
36388  operations supported by the compiler.
36389  The code generation involves translating these operations into corresponding
36390  assembly code for the processor.
36391  This sounds overly simple but that is the essence of code generation.
36392  Some of the iCode operations are generated on a MCU specific manner for
36393  example, the z80 port does not use registers to pass parameters so the
36394  SEND and RECV iCode operations will not be generated, and it also does
36395  not support JUMPTABLES.
36396  
36397 \newline
36398
36399 \end_layout
36400
36401 \begin_layout Standard
36402
36403 \size footnotesize
36404 Figure II 
36405 \begin_inset Tabular
36406 <lyxtabular version="3" rows="39" columns="4">
36407 <features islongtable="true" headBottomDL="true">
36408 <column alignment="block" valignment="top" leftline="true" width="13col%">
36409 <column alignment="left" valignment="top" leftline="true" width="13col%">
36410 <column alignment="block" valignment="top" leftline="true" width="22col%">
36411 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36412 <row topline="true" bottomline="true" endhead="true">
36413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36414 \begin_inset Text
36415
36416 \begin_layout Standard
36417
36418 \series bold
36419 iCode
36420 \series default
36421
36422 \begin_inset LatexCommand \index{iCode}
36423
36424 \end_inset
36425
36426
36427 \end_layout
36428
36429 \end_inset
36430 </cell>
36431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36432 \begin_inset Text
36433
36434 \begin_layout Standard
36435
36436 \series bold
36437 Operands
36438 \end_layout
36439
36440 \end_inset
36441 </cell>
36442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36443 \begin_inset Text
36444
36445 \begin_layout Standard
36446
36447 \series bold
36448 Description
36449 \end_layout
36450
36451 \end_inset
36452 </cell>
36453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36454 \begin_inset Text
36455
36456 \begin_layout Standard
36457
36458 \series bold
36459 C Equivalent
36460 \end_layout
36461
36462 \end_inset
36463 </cell>
36464 </row>
36465 <row topline="true">
36466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36467 \begin_inset Text
36468
36469 \begin_layout Standard
36470
36471 \size footnotesize
36472 '!'
36473 \end_layout
36474
36475 \end_inset
36476 </cell>
36477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36478 \begin_inset Text
36479
36480 \begin_layout Standard
36481
36482 \size footnotesize
36483 IC_LEFT() IC_RESULT()
36484 \end_layout
36485
36486 \end_inset
36487 </cell>
36488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36489 \begin_inset Text
36490
36491 \begin_layout Standard
36492
36493 \size footnotesize
36494 NOT operation 
36495 \end_layout
36496
36497 \end_inset
36498 </cell>
36499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36500 \begin_inset Text
36501
36502 \begin_layout Standard
36503
36504 \size footnotesize
36505 IC_RESULT = ! IC_LEFT;
36506 \end_layout
36507
36508 \end_inset
36509 </cell>
36510 </row>
36511 <row topline="true">
36512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36513 \begin_inset Text
36514
36515 \begin_layout Standard
36516
36517 \size footnotesize
36518 '~'
36519 \end_layout
36520
36521 \end_inset
36522 </cell>
36523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36524 \begin_inset Text
36525
36526 \begin_layout Standard
36527
36528 \size footnotesize
36529 IC_LEFT() IC_RESULT()
36530 \end_layout
36531
36532 \end_inset
36533 </cell>
36534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36535 \begin_inset Text
36536
36537 \begin_layout Standard
36538
36539 \size footnotesize
36540 Bitwise complement of 
36541 \end_layout
36542
36543 \end_inset
36544 </cell>
36545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36546 \begin_inset Text
36547
36548 \begin_layout Standard
36549
36550 \size footnotesize
36551 IC_RESULT = ~IC_LEFT;
36552 \end_layout
36553
36554 \end_inset
36555 </cell>
36556 </row>
36557 <row topline="true">
36558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36559 \begin_inset Text
36560
36561 \begin_layout Standard
36562
36563 \size footnotesize
36564 RRC
36565 \end_layout
36566
36567 \end_inset
36568 </cell>
36569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36570 \begin_inset Text
36571
36572 \begin_layout Standard
36573
36574 \size footnotesize
36575 IC_LEFT() IC_RESULT()
36576 \end_layout
36577
36578 \end_inset
36579 </cell>
36580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36581 \begin_inset Text
36582
36583 \begin_layout Standard
36584
36585 \size footnotesize
36586 Rotate right with carry
36587 \end_layout
36588
36589 \end_inset
36590 </cell>
36591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36592 \begin_inset Text
36593
36594 \begin_layout Standard
36595
36596 \size footnotesize
36597 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36598 \end_layout
36599
36600 \end_inset
36601 </cell>
36602 </row>
36603 <row topline="true">
36604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36605 \begin_inset Text
36606
36607 \begin_layout Standard
36608
36609 \size footnotesize
36610 RLC
36611 \end_layout
36612
36613 \end_inset
36614 </cell>
36615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36616 \begin_inset Text
36617
36618 \begin_layout Standard
36619
36620 \size footnotesize
36621 IC_LEFT() IC_RESULT()
36622 \end_layout
36623
36624 \end_inset
36625 </cell>
36626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36627 \begin_inset Text
36628
36629 \begin_layout Standard
36630
36631 \size footnotesize
36632 Rotate left with carry
36633 \end_layout
36634
36635 \end_inset
36636 </cell>
36637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36638 \begin_inset Text
36639
36640 \begin_layout Standard
36641
36642 \size footnotesize
36643 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36644 \end_layout
36645
36646 \end_inset
36647 </cell>
36648 </row>
36649 <row topline="true">
36650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36651 \begin_inset Text
36652
36653 \begin_layout Standard
36654
36655 \size footnotesize
36656 GETHBIT
36657 \end_layout
36658
36659 \end_inset
36660 </cell>
36661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36662 \begin_inset Text
36663
36664 \begin_layout Standard
36665
36666 \size footnotesize
36667 IC_LEFT() IC_RESULT()
36668 \end_layout
36669
36670 \end_inset
36671 </cell>
36672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36673 \begin_inset Text
36674
36675 \begin_layout Standard
36676
36677 \size footnotesize
36678 Get the highest order bit of IC_LEFT
36679 \end_layout
36680
36681 \end_inset
36682 </cell>
36683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36684 \begin_inset Text
36685
36686 \begin_layout Standard
36687
36688 \size footnotesize
36689 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36690 \end_layout
36691
36692 \end_inset
36693 </cell>
36694 </row>
36695 <row topline="true">
36696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36697 \begin_inset Text
36698
36699 \begin_layout Standard
36700
36701 \size footnotesize
36702 UNARYMINUS
36703 \end_layout
36704
36705 \end_inset
36706 </cell>
36707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36708 \begin_inset Text
36709
36710 \begin_layout Standard
36711
36712 \size footnotesize
36713 IC_LEFT() IC_RESULT()
36714 \end_layout
36715
36716 \end_inset
36717 </cell>
36718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36719 \begin_inset Text
36720
36721 \begin_layout Standard
36722
36723 \size footnotesize
36724 Unary minus
36725 \end_layout
36726
36727 \end_inset
36728 </cell>
36729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36730 \begin_inset Text
36731
36732 \begin_layout Standard
36733
36734 \size footnotesize
36735 IC_RESULT = - IC_LEFT;
36736 \end_layout
36737
36738 \end_inset
36739 </cell>
36740 </row>
36741 <row topline="true">
36742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36743 \begin_inset Text
36744
36745 \begin_layout Standard
36746
36747 \size footnotesize
36748 IPUSH
36749 \end_layout
36750
36751 \end_inset
36752 </cell>
36753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36754 \begin_inset Text
36755
36756 \begin_layout Standard
36757
36758 \size footnotesize
36759 IC_LEFT()
36760 \end_layout
36761
36762 \end_inset
36763 </cell>
36764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36765 \begin_inset Text
36766
36767 \begin_layout Standard
36768
36769 \size footnotesize
36770 Push the operand into stack
36771 \end_layout
36772
36773 \end_inset
36774 </cell>
36775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36776 \begin_inset Text
36777
36778 \begin_layout Standard
36779
36780 \size footnotesize
36781 NONE
36782 \end_layout
36783
36784 \end_inset
36785 </cell>
36786 </row>
36787 <row topline="true">
36788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36789 \begin_inset Text
36790
36791 \begin_layout Standard
36792
36793 \size footnotesize
36794 IPOP
36795 \end_layout
36796
36797 \end_inset
36798 </cell>
36799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36800 \begin_inset Text
36801
36802 \begin_layout Standard
36803
36804 \size footnotesize
36805 IC_LEFT()
36806 \end_layout
36807
36808 \end_inset
36809 </cell>
36810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36811 \begin_inset Text
36812
36813 \begin_layout Standard
36814
36815 \size footnotesize
36816 Pop the operand from the stack 
36817 \end_layout
36818
36819 \end_inset
36820 </cell>
36821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36822 \begin_inset Text
36823
36824 \begin_layout Standard
36825
36826 \size footnotesize
36827 NONE
36828 \end_layout
36829
36830 \end_inset
36831 </cell>
36832 </row>
36833 <row topline="true">
36834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36835 \begin_inset Text
36836
36837 \begin_layout Standard
36838
36839 \size footnotesize
36840 CALL
36841 \end_layout
36842
36843 \end_inset
36844 </cell>
36845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36846 \begin_inset Text
36847
36848 \begin_layout Standard
36849
36850 \size footnotesize
36851 IC_LEFT() IC_RESULT()
36852 \end_layout
36853
36854 \end_inset
36855 </cell>
36856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36857 \begin_inset Text
36858
36859 \begin_layout Standard
36860
36861 \size footnotesize
36862 Call the function represented by IC_LEFT 
36863 \end_layout
36864
36865 \end_inset
36866 </cell>
36867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36868 \begin_inset Text
36869
36870 \begin_layout Standard
36871
36872 \size footnotesize
36873 IC_RESULT = IC_LEFT();
36874 \end_layout
36875
36876 \end_inset
36877 </cell>
36878 </row>
36879 <row topline="true">
36880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36881 \begin_inset Text
36882
36883 \begin_layout Standard
36884
36885 \size footnotesize
36886 PCALL
36887 \end_layout
36888
36889 \end_inset
36890 </cell>
36891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36892 \begin_inset Text
36893
36894 \begin_layout Standard
36895
36896 \size footnotesize
36897 IC_LEFT() IC_RESULT()
36898 \end_layout
36899
36900 \end_inset
36901 </cell>
36902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36903 \begin_inset Text
36904
36905 \begin_layout Standard
36906
36907 \size footnotesize
36908 Call via function pointer
36909 \end_layout
36910
36911 \end_inset
36912 </cell>
36913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36914 \begin_inset Text
36915
36916 \begin_layout Standard
36917
36918 \size footnotesize
36919 IC_RESULT = (*IC_LEFT)();
36920 \end_layout
36921
36922 \end_inset
36923 </cell>
36924 </row>
36925 <row topline="true">
36926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36927 \begin_inset Text
36928
36929 \begin_layout Standard
36930
36931 \size footnotesize
36932 RETURN
36933 \end_layout
36934
36935 \end_inset
36936 </cell>
36937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36938 \begin_inset Text
36939
36940 \begin_layout Standard
36941
36942 \size footnotesize
36943 IC_LEFT()
36944 \end_layout
36945
36946 \end_inset
36947 </cell>
36948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36949 \begin_inset Text
36950
36951 \begin_layout Standard
36952
36953 \size footnotesize
36954 Return the value in operand IC_LEFT 
36955 \end_layout
36956
36957 \end_inset
36958 </cell>
36959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36960 \begin_inset Text
36961
36962 \begin_layout Standard
36963
36964 \size footnotesize
36965 return IC_LEFT;
36966 \end_layout
36967
36968 \end_inset
36969 </cell>
36970 </row>
36971 <row topline="true">
36972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36973 \begin_inset Text
36974
36975 \begin_layout Standard
36976
36977 \size footnotesize
36978 LABEL
36979 \end_layout
36980
36981 \end_inset
36982 </cell>
36983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36984 \begin_inset Text
36985
36986 \begin_layout Standard
36987
36988 \size footnotesize
36989 IC_LABEL() 
36990 \end_layout
36991
36992 \end_inset
36993 </cell>
36994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36995 \begin_inset Text
36996
36997 \begin_layout Standard
36998
36999 \size footnotesize
37000 Label
37001 \end_layout
37002
37003 \end_inset
37004 </cell>
37005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37006 \begin_inset Text
37007
37008 \begin_layout Standard
37009
37010 \size footnotesize
37011 IC_LABEL:
37012 \end_layout
37013
37014 \end_inset
37015 </cell>
37016 </row>
37017 <row topline="true">
37018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37019 \begin_inset Text
37020
37021 \begin_layout Standard
37022
37023 \size footnotesize
37024 GOTO
37025 \end_layout
37026
37027 \end_inset
37028 </cell>
37029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37030 \begin_inset Text
37031
37032 \begin_layout Standard
37033
37034 \size footnotesize
37035 IC_LABEL() 
37036 \end_layout
37037
37038 \end_inset
37039 </cell>
37040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37041 \begin_inset Text
37042
37043 \begin_layout Standard
37044
37045 \size footnotesize
37046 Goto label
37047 \end_layout
37048
37049 \end_inset
37050 </cell>
37051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37052 \begin_inset Text
37053
37054 \begin_layout Standard
37055
37056 \size footnotesize
37057 goto IC_LABEL();
37058 \end_layout
37059
37060 \end_inset
37061 </cell>
37062 </row>
37063 <row topline="true">
37064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37065 \begin_inset Text
37066
37067 \begin_layout Standard
37068
37069 \size footnotesize
37070 '+'
37071 \end_layout
37072
37073 \end_inset
37074 </cell>
37075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37076 \begin_inset Text
37077
37078 \begin_layout Standard
37079
37080 \size footnotesize
37081 IC_LEFT() IC_RIGHT() IC_RESULT()
37082 \end_layout
37083
37084 \end_inset
37085 </cell>
37086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37087 \begin_inset Text
37088
37089 \begin_layout Standard
37090
37091 \size footnotesize
37092 Addition
37093 \end_layout
37094
37095 \end_inset
37096 </cell>
37097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37098 \begin_inset Text
37099
37100 \begin_layout Standard
37101
37102 \size footnotesize
37103 IC_RESULT = IC_LEFT + IC_RIGHT
37104 \end_layout
37105
37106 \end_inset
37107 </cell>
37108 </row>
37109 <row topline="true">
37110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37111 \begin_inset Text
37112
37113 \begin_layout Standard
37114
37115 \size footnotesize
37116 '-'
37117 \end_layout
37118
37119 \end_inset
37120 </cell>
37121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37122 \begin_inset Text
37123
37124 \begin_layout Standard
37125
37126 \size footnotesize
37127 IC_LEFT() IC_RIGHT() IC_RESULT()
37128 \end_layout
37129
37130 \end_inset
37131 </cell>
37132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37133 \begin_inset Text
37134
37135 \begin_layout Standard
37136
37137 \size footnotesize
37138 Subtraction
37139 \end_layout
37140
37141 \end_inset
37142 </cell>
37143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37144 \begin_inset Text
37145
37146 \begin_layout Standard
37147
37148 \size footnotesize
37149 IC_RESULT = IC_LEFT - IC_RIGHT 
37150 \end_layout
37151
37152 \end_inset
37153 </cell>
37154 </row>
37155 <row topline="true">
37156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37157 \begin_inset Text
37158
37159 \begin_layout Standard
37160
37161 \size footnotesize
37162 '*'
37163 \end_layout
37164
37165 \end_inset
37166 </cell>
37167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37168 \begin_inset Text
37169
37170 \begin_layout Standard
37171
37172 \size footnotesize
37173 IC_LEFT() IC_RIGHT() IC_RESULT()
37174 \end_layout
37175
37176 \end_inset
37177 </cell>
37178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37179 \begin_inset Text
37180
37181 \begin_layout Standard
37182
37183 \size footnotesize
37184 Multiplication 
37185 \end_layout
37186
37187 \end_inset
37188 </cell>
37189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37190 \begin_inset Text
37191
37192 \begin_layout Standard
37193
37194 \size footnotesize
37195 IC_RESULT = IC_LEFT * IC_RIGHT;
37196 \end_layout
37197
37198 \end_inset
37199 </cell>
37200 </row>
37201 <row topline="true">
37202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37203 \begin_inset Text
37204
37205 \begin_layout Standard
37206
37207 \size footnotesize
37208 '/'
37209 \end_layout
37210
37211 \end_inset
37212 </cell>
37213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37214 \begin_inset Text
37215
37216 \begin_layout Standard
37217
37218 \size footnotesize
37219 IC_LEFT() IC_RIGHT() IC_RESULT()
37220 \end_layout
37221
37222 \end_inset
37223 </cell>
37224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37225 \begin_inset Text
37226
37227 \begin_layout Standard
37228
37229 \size footnotesize
37230 Division
37231 \end_layout
37232
37233 \end_inset
37234 </cell>
37235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37236 \begin_inset Text
37237
37238 \begin_layout Standard
37239
37240 \size footnotesize
37241 IC_RESULT = IC_LEFT / IC_RIGHT;
37242 \end_layout
37243
37244 \end_inset
37245 </cell>
37246 </row>
37247 <row topline="true">
37248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37249 \begin_inset Text
37250
37251 \begin_layout Standard
37252
37253 \size footnotesize
37254 '%'
37255 \end_layout
37256
37257 \end_inset
37258 </cell>
37259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37260 \begin_inset Text
37261
37262 \begin_layout Standard
37263
37264 \size footnotesize
37265 IC_LEFT() IC_RIGHT() IC_RESULT()
37266 \end_layout
37267
37268 \end_inset
37269 </cell>
37270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37271 \begin_inset Text
37272
37273 \begin_layout Standard
37274
37275 \size footnotesize
37276 Modulus
37277 \end_layout
37278
37279 \end_inset
37280 </cell>
37281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37282 \begin_inset Text
37283
37284 \begin_layout Standard
37285
37286 \size footnotesize
37287 IC_RESULT = IC_LEFT % IC_RIGHT;
37288 \end_layout
37289
37290 \end_inset
37291 </cell>
37292 </row>
37293 <row topline="true">
37294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37295 \begin_inset Text
37296
37297 \begin_layout Standard
37298
37299 \size footnotesize
37300 '<'
37301 \end_layout
37302
37303 \end_inset
37304 </cell>
37305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37306 \begin_inset Text
37307
37308 \begin_layout Standard
37309
37310 \size footnotesize
37311 IC_LEFT() IC_RIGHT() IC_RESULT()
37312 \end_layout
37313
37314 \end_inset
37315 </cell>
37316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37317 \begin_inset Text
37318
37319 \begin_layout Standard
37320
37321 \size footnotesize
37322 Less than
37323 \end_layout
37324
37325 \end_inset
37326 </cell>
37327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37328 \begin_inset Text
37329
37330 \begin_layout Standard
37331
37332 \size footnotesize
37333 IC_RESULT = IC_LEFT < IC_RIGHT;
37334 \end_layout
37335
37336 \end_inset
37337 </cell>
37338 </row>
37339 <row topline="true">
37340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37341 \begin_inset Text
37342
37343 \begin_layout Standard
37344
37345 \size footnotesize
37346 '>'
37347 \end_layout
37348
37349 \end_inset
37350 </cell>
37351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37352 \begin_inset Text
37353
37354 \begin_layout Standard
37355
37356 \size footnotesize
37357 IC_LEFT() IC_RIGHT() IC_RESULT()
37358 \end_layout
37359
37360 \end_inset
37361 </cell>
37362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37363 \begin_inset Text
37364
37365 \begin_layout Standard
37366
37367 \size footnotesize
37368 Greater than 
37369 \end_layout
37370
37371 \end_inset
37372 </cell>
37373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37374 \begin_inset Text
37375
37376 \begin_layout Standard
37377
37378 \size footnotesize
37379 IC_RESULT = IC_LEFT > IC_RIGHT;
37380 \end_layout
37381
37382 \end_inset
37383 </cell>
37384 </row>
37385 <row topline="true">
37386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37387 \begin_inset Text
37388
37389 \begin_layout Standard
37390
37391 \size footnotesize
37392 EQ_OP
37393 \end_layout
37394
37395 \end_inset
37396 </cell>
37397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37398 \begin_inset Text
37399
37400 \begin_layout Standard
37401
37402 \size footnotesize
37403 IC_LEFT() IC_RIGHT() IC_RESULT()
37404 \end_layout
37405
37406 \end_inset
37407 </cell>
37408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37409 \begin_inset Text
37410
37411 \begin_layout Standard
37412
37413 \size footnotesize
37414 Equal to 
37415 \end_layout
37416
37417 \end_inset
37418 </cell>
37419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37420 \begin_inset Text
37421
37422 \begin_layout Standard
37423
37424 \size footnotesize
37425 IC_RESULT = IC_LEFT == IC_RIGHT;
37426 \end_layout
37427
37428 \end_inset
37429 </cell>
37430 </row>
37431 <row topline="true">
37432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37433 \begin_inset Text
37434
37435 \begin_layout Standard
37436
37437 \size footnotesize
37438 AND_OP
37439 \end_layout
37440
37441 \end_inset
37442 </cell>
37443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37444 \begin_inset Text
37445
37446 \begin_layout Standard
37447
37448 \size footnotesize
37449 IC_LEFT() IC_RIGHT() IC_RESULT() 
37450 \end_layout
37451
37452 \end_inset
37453 </cell>
37454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37455 \begin_inset Text
37456
37457 \begin_layout Standard
37458
37459 \size footnotesize
37460 Logical and operation
37461 \end_layout
37462
37463 \end_inset
37464 </cell>
37465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37466 \begin_inset Text
37467
37468 \begin_layout Standard
37469
37470 \size footnotesize
37471 IC_RESULT = IC_LEFT && IC_RIGHT; 
37472 \end_layout
37473
37474 \end_inset
37475 </cell>
37476 </row>
37477 <row topline="true">
37478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37479 \begin_inset Text
37480
37481 \begin_layout Standard
37482
37483 \size footnotesize
37484 OR_OP
37485 \end_layout
37486
37487 \end_inset
37488 </cell>
37489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37490 \begin_inset Text
37491
37492 \begin_layout Standard
37493
37494 \size footnotesize
37495 IC_LEFT() IC_RIGHT() IC_RESULT() 
37496 \end_layout
37497
37498 \end_inset
37499 </cell>
37500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37501 \begin_inset Text
37502
37503 \begin_layout Standard
37504
37505 \size footnotesize
37506 Logical or operation 
37507 \end_layout
37508
37509 \end_inset
37510 </cell>
37511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37512 \begin_inset Text
37513
37514 \begin_layout Standard
37515
37516 \size footnotesize
37517 IC_RESULT = IC_LEFT || IC_RIGHT; 
37518 \end_layout
37519
37520 \end_inset
37521 </cell>
37522 </row>
37523 <row topline="true">
37524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37525 \begin_inset Text
37526
37527 \begin_layout Standard
37528
37529 \size footnotesize
37530 '^'
37531 \end_layout
37532
37533 \end_inset
37534 </cell>
37535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37536 \begin_inset Text
37537
37538 \begin_layout Standard
37539
37540 \size footnotesize
37541 IC_LEFT() IC_RIGHT() IC_RESULT() 
37542 \end_layout
37543
37544 \end_inset
37545 </cell>
37546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37547 \begin_inset Text
37548
37549 \begin_layout Standard
37550
37551 \size footnotesize
37552 Exclusive OR
37553 \end_layout
37554
37555 \end_inset
37556 </cell>
37557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37558 \begin_inset Text
37559
37560 \begin_layout Standard
37561
37562 \size footnotesize
37563 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37564 \end_layout
37565
37566 \end_inset
37567 </cell>
37568 </row>
37569 <row topline="true">
37570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37571 \begin_inset Text
37572
37573 \begin_layout Standard
37574
37575 \size footnotesize
37576 '|'
37577 \end_layout
37578
37579 \end_inset
37580 </cell>
37581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37582 \begin_inset Text
37583
37584 \begin_layout Standard
37585
37586 \size footnotesize
37587 IC_LEFT() IC_RIGHT() IC_RESULT() 
37588 \end_layout
37589
37590 \end_inset
37591 </cell>
37592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37593 \begin_inset Text
37594
37595 \begin_layout Standard
37596
37597 \size footnotesize
37598 Bitwise OR 
37599 \end_layout
37600
37601 \end_inset
37602 </cell>
37603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37604 \begin_inset Text
37605
37606 \begin_layout Standard
37607
37608 \size footnotesize
37609 IC_RESULT = IC_LEFT | IC_RIGHT;
37610 \end_layout
37611
37612 \end_inset
37613 </cell>
37614 </row>
37615 <row topline="true">
37616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37617 \begin_inset Text
37618
37619 \begin_layout Standard
37620
37621 \size footnotesize
37622 BITWISEAND
37623 \end_layout
37624
37625 \end_inset
37626 </cell>
37627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37628 \begin_inset Text
37629
37630 \begin_layout Standard
37631
37632 \size footnotesize
37633 IC_LEFT() IC_RIGHT() IC_RESULT()
37634 \end_layout
37635
37636 \end_inset
37637 </cell>
37638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37639 \begin_inset Text
37640
37641 \begin_layout Standard
37642
37643 \size footnotesize
37644 Bitwise AND 
37645 \end_layout
37646
37647 \end_inset
37648 </cell>
37649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37650 \begin_inset Text
37651
37652 \begin_layout Standard
37653
37654 \size footnotesize
37655 IC_RESULT = IC_LEFT & IC_RIGHT;
37656 \end_layout
37657
37658 \end_inset
37659 </cell>
37660 </row>
37661 <row topline="true">
37662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37663 \begin_inset Text
37664
37665 \begin_layout Standard
37666
37667 \size footnotesize
37668 LEFT_OP
37669 \end_layout
37670
37671 \end_inset
37672 </cell>
37673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37674 \begin_inset Text
37675
37676 \begin_layout Standard
37677
37678 \size footnotesize
37679 IC_LEFT() IC_RIGHT() IC_RESULT()
37680 \end_layout
37681
37682 \end_inset
37683 </cell>
37684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37685 \begin_inset Text
37686
37687 \begin_layout Standard
37688
37689 \size footnotesize
37690 Left shift 
37691 \end_layout
37692
37693 \end_inset
37694 </cell>
37695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37696 \begin_inset Text
37697
37698 \begin_layout Standard
37699
37700 \size footnotesize
37701 IC_RESULT = IC_LEFT << IC_RIGHT 
37702 \end_layout
37703
37704 \end_inset
37705 </cell>
37706 </row>
37707 <row topline="true">
37708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37709 \begin_inset Text
37710
37711 \begin_layout Standard
37712
37713 \size footnotesize
37714 RIGHT_OP
37715 \end_layout
37716
37717 \end_inset
37718 </cell>
37719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37720 \begin_inset Text
37721
37722 \begin_layout Standard
37723
37724 \size footnotesize
37725 IC_LEFT() IC_RIGHT() IC_RESULT()
37726 \end_layout
37727
37728 \end_inset
37729 </cell>
37730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37731 \begin_inset Text
37732
37733 \begin_layout Standard
37734
37735 \size footnotesize
37736 Right shift
37737 \end_layout
37738
37739 \end_inset
37740 </cell>
37741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37742 \begin_inset Text
37743
37744 \begin_layout Standard
37745
37746 \size footnotesize
37747 IC_RESULT = IC_LEFT >> IC_RIGHT 
37748 \end_layout
37749
37750 \end_inset
37751 </cell>
37752 </row>
37753 <row topline="true">
37754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37755 \begin_inset Text
37756
37757 \begin_layout Standard
37758
37759 \size footnotesize
37760 GET_VALUE_
37761 \newline
37762 AT_ ADDRESS
37763 \end_layout
37764
37765 \end_inset
37766 </cell>
37767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37768 \begin_inset Text
37769
37770 \begin_layout Standard
37771
37772 \size footnotesize
37773 IC_LEFT() IC_RESULT()
37774 \end_layout
37775
37776 \end_inset
37777 </cell>
37778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37779 \begin_inset Text
37780
37781 \begin_layout Standard
37782
37783 \size footnotesize
37784 Indirect fetch 
37785 \end_layout
37786
37787 \end_inset
37788 </cell>
37789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37790 \begin_inset Text
37791
37792 \begin_layout Standard
37793
37794 \size footnotesize
37795 IC_RESULT = (*IC_LEFT);
37796 \end_layout
37797
37798 \end_inset
37799 </cell>
37800 </row>
37801 <row topline="true">
37802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37803 \begin_inset Text
37804
37805 \begin_layout Standard
37806
37807 \size footnotesize
37808 POINTER_SET
37809 \end_layout
37810
37811 \end_inset
37812 </cell>
37813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37814 \begin_inset Text
37815
37816 \begin_layout Standard
37817
37818 \size footnotesize
37819 IC_RIGHT() IC_RESULT() 
37820 \end_layout
37821
37822 \end_inset
37823 </cell>
37824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37825 \begin_inset Text
37826
37827 \begin_layout Standard
37828
37829 \size footnotesize
37830 Indirect set
37831 \end_layout
37832
37833 \end_inset
37834 </cell>
37835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37836 \begin_inset Text
37837
37838 \begin_layout Standard
37839
37840 \size footnotesize
37841 (*IC_RESULT) = IC_RIGHT;
37842 \end_layout
37843
37844 \end_inset
37845 </cell>
37846 </row>
37847 <row topline="true">
37848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37849 \begin_inset Text
37850
37851 \begin_layout Standard
37852
37853 \size footnotesize
37854 '='
37855 \end_layout
37856
37857 \end_inset
37858 </cell>
37859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37860 \begin_inset Text
37861
37862 \begin_layout Standard
37863
37864 \size footnotesize
37865 IC_RIGHT() IC_RESULT()
37866 \end_layout
37867
37868 \end_inset
37869 </cell>
37870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37871 \begin_inset Text
37872
37873 \begin_layout Standard
37874
37875 \size footnotesize
37876 Assignment
37877 \end_layout
37878
37879 \end_inset
37880 </cell>
37881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37882 \begin_inset Text
37883
37884 \begin_layout Standard
37885
37886 \size footnotesize
37887 IC_RESULT = IC_RIGHT;
37888 \end_layout
37889
37890 \end_inset
37891 </cell>
37892 </row>
37893 <row topline="true">
37894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37895 \begin_inset Text
37896
37897 \begin_layout Standard
37898
37899 \size footnotesize
37900 IFX
37901 \end_layout
37902
37903 \end_inset
37904 </cell>
37905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37906 \begin_inset Text
37907
37908 \begin_layout Standard
37909
37910 \size footnotesize
37911 IC_COND IC_TRUE IC_LABEL
37912 \end_layout
37913
37914 \end_inset
37915 </cell>
37916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37917 \begin_inset Text
37918
37919 \begin_layout Standard
37920
37921 \size footnotesize
37922 Conditional jump.
37923  If true label is present then jump to true label if condition is true else
37924  jump to false label if condition is false 
37925 \end_layout
37926
37927 \end_inset
37928 </cell>
37929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37930 \begin_inset Text
37931
37932 \begin_layout Standard
37933
37934 \size footnotesize
37935 if (IC_COND) goto IC_TRUE; 
37936 \newline
37937 \InsetSpace ~
37938 \InsetSpace ~
37939 Or 
37940 \newline
37941 If (!IC_COND) goto IC_FALSE;
37942 \end_layout
37943
37944 \end_inset
37945 </cell>
37946 </row>
37947 <row topline="true">
37948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37949 \begin_inset Text
37950
37951 \begin_layout Standard
37952
37953 \size footnotesize
37954 ADDRESS_OF
37955 \end_layout
37956
37957 \end_inset
37958 </cell>
37959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37960 \begin_inset Text
37961
37962 \begin_layout Standard
37963
37964 \size footnotesize
37965 IC_LEFT() IC_RESULT()
37966 \end_layout
37967
37968 \end_inset
37969 </cell>
37970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37971 \begin_inset Text
37972
37973 \begin_layout Standard
37974
37975 \size footnotesize
37976 Address of 
37977 \end_layout
37978
37979 \end_inset
37980 </cell>
37981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37982 \begin_inset Text
37983
37984 \begin_layout Standard
37985
37986 \size footnotesize
37987 IC_RESULT = &IC_LEFT();
37988 \end_layout
37989
37990 \end_inset
37991 </cell>
37992 </row>
37993 <row topline="true">
37994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37995 \begin_inset Text
37996
37997 \begin_layout Standard
37998
37999 \size footnotesize
38000 JUMPTABLE
38001 \end_layout
38002
38003 \end_inset
38004 </cell>
38005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38006 \begin_inset Text
38007
38008 \begin_layout Standard
38009
38010 \size footnotesize
38011 IC_JTCOND IC_JTLABELS
38012 \end_layout
38013
38014 \end_inset
38015 </cell>
38016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38017 \begin_inset Text
38018
38019 \begin_layout Standard
38020
38021 \size footnotesize
38022 Jump to list of labels depending on the value of JTCOND
38023 \end_layout
38024
38025 \end_inset
38026 </cell>
38027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38028 \begin_inset Text
38029
38030 \begin_layout Standard
38031
38032 \size footnotesize
38033 Switch statement
38034 \end_layout
38035
38036 \end_inset
38037 </cell>
38038 </row>
38039 <row topline="true">
38040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38041 \begin_inset Text
38042
38043 \begin_layout Standard
38044
38045 \size footnotesize
38046 CAST
38047 \end_layout
38048
38049 \end_inset
38050 </cell>
38051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38052 \begin_inset Text
38053
38054 \begin_layout Standard
38055
38056 \size footnotesize
38057 IC_RIGHT() IC_LEFT() IC_RESULT()
38058 \end_layout
38059
38060 \end_inset
38061 </cell>
38062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38063 \begin_inset Text
38064
38065 \begin_layout Standard
38066
38067 \size footnotesize
38068 Cast types 
38069 \end_layout
38070
38071 \end_inset
38072 </cell>
38073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38074 \begin_inset Text
38075
38076 \begin_layout Standard
38077
38078 \size footnotesize
38079 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38080 \end_layout
38081
38082 \end_inset
38083 </cell>
38084 </row>
38085 <row topline="true">
38086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38087 \begin_inset Text
38088
38089 \begin_layout Standard
38090
38091 \size footnotesize
38092 SEND
38093 \end_layout
38094
38095 \end_inset
38096 </cell>
38097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38098 \begin_inset Text
38099
38100 \begin_layout Standard
38101
38102 \size footnotesize
38103 IC_LEFT()
38104 \end_layout
38105
38106 \end_inset
38107 </cell>
38108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38109 \begin_inset Text
38110
38111 \begin_layout Standard
38112
38113 \size footnotesize
38114 This is used for passing parameters in registers; 
38115 \newline
38116 move IC_LEFT to the next
38117  available parameter register.
38118 \end_layout
38119
38120 \end_inset
38121 </cell>
38122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38123 \begin_inset Text
38124
38125 \begin_layout Standard
38126
38127 \size footnotesize
38128 None
38129 \end_layout
38130
38131 \end_inset
38132 </cell>
38133 </row>
38134 <row topline="true">
38135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38136 \begin_inset Text
38137
38138 \begin_layout Standard
38139
38140 \size footnotesize
38141 RECV
38142 \end_layout
38143
38144 \end_inset
38145 </cell>
38146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38147 \begin_inset Text
38148
38149 \begin_layout Standard
38150
38151 \size footnotesize
38152 IC_RESULT()
38153 \end_layout
38154
38155 \end_inset
38156 </cell>
38157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38158 \begin_inset Text
38159
38160 \begin_layout Standard
38161
38162 \size footnotesize
38163 This is used for receiving parameters passed in registers;
38164 \newline
38165 Move the values
38166  in the next parameter register to IC_RESULT 
38167 \end_layout
38168
38169 \end_inset
38170 </cell>
38171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38172 \begin_inset Text
38173
38174 \begin_layout Standard
38175
38176 \size footnotesize
38177 None
38178 \end_layout
38179
38180 \end_inset
38181 </cell>
38182 </row>
38183 <row topline="true" bottomline="true">
38184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38185 \begin_inset Text
38186
38187 \begin_layout Standard
38188
38189 \shape slanted
38190 \size footnotesize
38191 (some more have been added)
38192 \end_layout
38193
38194 \end_inset
38195 </cell>
38196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38197 \begin_inset Text
38198
38199 \begin_layout Standard
38200
38201 \end_layout
38202
38203 \end_inset
38204 </cell>
38205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38206 \begin_inset Text
38207
38208 \begin_layout Standard
38209
38210 \end_layout
38211
38212 \end_inset
38213 </cell>
38214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38215 \begin_inset Text
38216
38217 \begin_layout Standard
38218
38219 \shape slanted
38220 \size footnotesize
38221 see f.e.
38222  
38223 \family typewriter
38224 gen51Code()
38225 \family default
38226  in 
38227 \family typewriter
38228 src/mcs51/gen.c
38229 \end_layout
38230
38231 \end_inset
38232 </cell>
38233 </row>
38234 </lyxtabular>
38235
38236 \end_inset
38237
38238
38239 \end_layout
38240
38241 \begin_layout Standard
38242 \begin_inset Note Note
38243 status collapsed
38244
38245 \begin_layout Standard
38246 In the original article Figure II was announced to be downloadable on 
38247 \shape italic
38248 Circuit Cellar
38249 \shape default
38250 's web site.
38251  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38252 \end_layout
38253
38254 \end_inset
38255
38256
38257 \end_layout
38258
38259 \begin_layout Paragraph*
38260 ICode Example
38261 \begin_inset LatexCommand \index{iCode}
38262
38263 \end_inset
38264
38265
38266 \end_layout
38267
38268 \begin_layout Standard
38269 This section shows some details of iCode.
38270  The example C code does not do anything useful; it is used as an example
38271  to illustrate the intermediate code generated by the compiler.
38272 \end_layout
38273
38274 \begin_layout Verse
38275
38276 \family typewriter
38277 1.\InsetSpace ~
38278 xdata int * p;
38279 \newline
38280 2.\InsetSpace ~
38281 int gint;
38282 \newline
38283 3.\InsetSpace ~
38284 /* This function does nothing useful.
38285  It is used
38286 \newline
38287 4.\InsetSpace ~
38288 \InsetSpace ~
38289 \InsetSpace ~
38290 \InsetSpace ~
38291 for the purpose of explaining iCode */
38292 \newline
38293 5.\InsetSpace ~
38294 short function (data
38295  int *x)
38296 \newline
38297 6.\InsetSpace ~
38298 {
38299 \newline
38300 7.\InsetSpace ~
38301 \InsetSpace ~
38302 \InsetSpace ~
38303 short i=10; \InsetSpace ~
38304 \InsetSpace ~
38305 /* dead initialization eliminated */
38306 \newline
38307 8.\InsetSpace ~
38308 \InsetSpace ~
38309 \InsetSpace ~
38310 short sum=10;
38311  /* dead initialization eliminated */
38312 \newline
38313 9.\InsetSpace ~
38314 \InsetSpace ~
38315 \InsetSpace ~
38316 short mul;
38317 \newline
38318 10.\InsetSpace ~
38319 \InsetSpace ~
38320 int j ;
38321 \newline
38322 11.\InsetSpace ~
38323 \InsetSpace ~
38324 while (*x) *x++
38325  = *p++; 
38326 \newline
38327 12.\InsetSpace ~
38328 \InsetSpace ~
38329 \InsetSpace ~
38330 \InsetSpace ~
38331 sum = 0 ; 
38332 \newline
38333 13.\InsetSpace ~
38334 \InsetSpace ~
38335 mul = 0;
38336 \newline
38337 14.\InsetSpace ~
38338 \InsetSpace ~
38339 /* compiler detects i,j to be induction
38340  variables */
38341 \newline
38342 15.\InsetSpace ~
38343 \InsetSpace ~
38344 for (i = 0, j = 10 ; i < 10 ; i++, j
38345 \family default
38346 -
38347 \begin_inset ERT
38348 status collapsed
38349
38350 \begin_layout Standard
38351
38352
38353 \backslash
38354 /
38355 \end_layout
38356
38357 \end_inset
38358
38359 -
38360 \family typewriter
38361 ) {
38362 \newline
38363 16.\InsetSpace ~
38364 \InsetSpace ~
38365 \InsetSpace ~
38366 \InsetSpace ~
38367 sum += i;
38368 \newline
38369 17.\InsetSpace ~
38370 \InsetSpace ~
38371 \InsetSpace ~
38372 \InsetSpace ~
38373 mul += i * 3; \InsetSpace ~
38374 \InsetSpace ~
38375 /* this multiplication remains */
38376 \newline
38377 18.\InsetSpace ~
38378 \InsetSpace ~
38379 \InsetSpace ~
38380 \InsetSpace ~
38381 gint +=
38382  j * 3;\InsetSpace ~
38383 \InsetSpace ~
38384 /* this multiplication changed to addition */
38385 \newline
38386 19.\InsetSpace ~
38387 \InsetSpace ~
38388 }
38389 \newline
38390 20.\InsetSpace ~
38391 \InsetSpace ~
38392 return sum+mul;
38393 \newline
38394 21.\InsetSpace ~
38395 }
38396 \end_layout
38397
38398 \begin_layout Standard
38399 In addition to the operands each iCode contains information about the filename
38400  and line it corresponds to in the source file.
38401  The first field in the listing should be interpreted as follows:
38402 \newline
38403
38404 \shape italic
38405 \size footnotesize
38406 Filename(linenumber: iCode Execution sequence number : ICode hash table
38407  key : loop depth of the iCode).
38408 \shape default
38409 \size default
38410
38411 \newline
38412 Then follows the human readable form of the ICode operation.
38413  Each operand of this triplet form can be of three basic types a) compiler
38414  generated temporary b) user defined variable c) a constant value.
38415  Note that local variables and parameters are replaced by compiler generated
38416  temporaries.
38417  Live ranges
38418 \begin_inset LatexCommand \index{Live range analysis}
38419
38420 \end_inset
38421
38422  are computed only for temporaries (i.e.
38423  live ranges are not computed for global variables).
38424  Registers
38425 \begin_inset LatexCommand \index{Register allocation}
38426
38427 \end_inset
38428
38429  are allocated for temporaries only.
38430  Operands are formatted in the following manner:
38431 \newline
38432
38433 \shape italic
38434 \size footnotesize
38435 Operand Name [lr live-from : live-to ] { type information } [ registers
38436  allocated ].
38437 \shape default
38438 \size default
38439
38440 \newline
38441 As mentioned earlier the live ranges are computed in terms of the execution
38442  sequence number of the iCodes, for example 
38443 \newline
38444 the iTemp0 is live from (i.e.
38445  first defined in iCode with execution sequence number 3, and is last used
38446  in the iCode with sequence number 5).
38447  For induction variables such as iTemp21 the live range computation extends
38448  the lifetime from the start to the end of the loop.
38449 \newline
38450 The register allocator
38451  used the live range information to allocate registers, the same registers
38452  may be used for different temporaries if their live ranges do not overlap,
38453  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38454  ranges do not overlap.
38455  In addition the allocator also takes into consideration the type and usage
38456  of a temporary, for example itemp6 is a pointer to near space and is used
38457  as to fetch data from (i.e.
38458  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38459  Some short lived temporaries are allocated to special registers which have
38460  meaning to the code generator e.g.
38461  iTemp13 is allocated to a pseudo register CC which tells the back end that
38462  the temporary is used only for a conditional jump the code generation makes
38463  use of this information to optimize a compare and jump ICode.
38464 \newline
38465 There are several
38466  loop optimizations
38467 \begin_inset LatexCommand \index{Loop optimization}
38468
38469 \end_inset
38470
38471  performed by the compiler.
38472  It can detect induction variables iTemp21(i) and iTemp23(j).
38473  Also note the compiler does selective strength reduction
38474 \begin_inset LatexCommand \index{Strength reduction}
38475
38476 \end_inset
38477
38478 , i.e.
38479  the multiplication of an induction variable in line 18 (gint = j * 3) is
38480  changed to addition, a new temporary iTemp17 is allocated and assigned
38481  a initial value, a constant 3 is then added for each iteration of the loop.
38482  The compiler does not change the multiplication
38483 \begin_inset LatexCommand \index{Multiplication}
38484
38485 \end_inset
38486
38487  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38488 \newline
38489
38490 Note the dead code elimination
38491 \begin_inset LatexCommand \index{Dead-code elimination}
38492
38493 \end_inset
38494
38495  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38496  respectively.
38497 \newline
38498
38499 \end_layout
38500
38501 \begin_layout Standard
38502
38503 \size footnotesize
38504 Sample.c (5:1:0:0) _entry($9) :
38505 \end_layout
38506
38507 \begin_layout Standard
38508
38509 \size footnotesize
38510 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38511 \end_layout
38512
38513 \begin_layout Standard
38514
38515 \size footnotesize
38516 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38517 \end_layout
38518
38519 \begin_layout Standard
38520
38521 \size footnotesize
38522 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38523 \end_layout
38524
38525 \begin_layout Standard
38526
38527 \size footnotesize
38528 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38529  * int}[r2]
38530 \end_layout
38531
38532 \begin_layout Standard
38533
38534 \size footnotesize
38535 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38536 \end_layout
38537
38538 \begin_layout Standard
38539
38540 \size footnotesize
38541 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38542  int}[r0]]
38543 \end_layout
38544
38545 \begin_layout Standard
38546
38547 \size footnotesize
38548 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38549 \end_layout
38550
38551 \begin_layout Standard
38552
38553 \size footnotesize
38554 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38555  * int}
38556 \end_layout
38557
38558 \begin_layout Standard
38559
38560 \size footnotesize
38561 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38562  {short}
38563 \end_layout
38564
38565 \begin_layout Standard
38566
38567 \size footnotesize
38568 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38569  * int}[DPTR]]
38570 \end_layout
38571
38572 \begin_layout Standard
38573
38574 \size footnotesize
38575 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38576 }[r2 r3]
38577 \end_layout
38578
38579 \begin_layout Standard
38580
38581 \size footnotesize
38582 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38583  * int}[r0] + 0x2 {short}
38584 \end_layout
38585
38586 \begin_layout Standard
38587
38588 \size footnotesize
38589 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38590 \end_layout
38591
38592 \begin_layout Standard
38593
38594 \size footnotesize
38595 Sample.c(11:17:21:0)_whilebreak_0($3) :
38596 \end_layout
38597
38598 \begin_layout Standard
38599
38600 \size footnotesize
38601 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38602 \end_layout
38603
38604 \begin_layout Standard
38605
38606 \size footnotesize
38607 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38608 \end_layout
38609
38610 \begin_layout Standard
38611
38612 \size footnotesize
38613 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38614 \end_layout
38615
38616 \begin_layout Standard
38617
38618 \size footnotesize
38619 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38620 \end_layout
38621
38622 \begin_layout Standard
38623
38624 \size footnotesize
38625 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38626 \end_layout
38627
38628 \begin_layout Standard
38629
38630 \size footnotesize
38631 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38632 \end_layout
38633
38634 \begin_layout Standard
38635
38636 \size footnotesize
38637 Sample.c(15:24:26:1)_forcond_0($4) :
38638 \end_layout
38639
38640 \begin_layout Standard
38641
38642 \size footnotesize
38643 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38644  < 0xa {short}
38645 \end_layout
38646
38647 \begin_layout Standard
38648
38649 \size footnotesize
38650 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38651 \end_layout
38652
38653 \begin_layout Standard
38654
38655 \size footnotesize
38656 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38657  + ITemp21 [lr21:38]{short}[r4]
38658 \end_layout
38659
38660 \begin_layout Standard
38661
38662 \size footnotesize
38663 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38664  * 0x3 {short}
38665 \end_layout
38666
38667 \begin_layout Standard
38668
38669 \size footnotesize
38670 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38671  + iTemp15 [lr29:30]{short}[r1]
38672 \end_layout
38673
38674 \begin_layout Standard
38675
38676 \size footnotesize
38677 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38678  r0]- 0x3 {short}
38679 \end_layout
38680
38681 \begin_layout Standard
38682
38683 \size footnotesize
38684 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38685 int}[r7 r0]
38686 \end_layout
38687
38688 \begin_layout Standard
38689
38690 \size footnotesize
38691 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38692  + 0x1 {short}
38693 \end_layout
38694
38695 \begin_layout Standard
38696
38697 \size footnotesize
38698 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38699  r6]- 0x1 {short}
38700 \end_layout
38701
38702 \begin_layout Standard
38703
38704 \size footnotesize
38705 Sample.c(19:38:47:1) goto _forcond_0($4)
38706 \end_layout
38707
38708 \begin_layout Standard
38709
38710 \size footnotesize
38711 Sample.c(19:39:48:0)_forbreak_0($7) :
38712 \end_layout
38713
38714 \begin_layout Standard
38715
38716 \size footnotesize
38717 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38718  + ITemp11 [lr19:40]{short}[r3]
38719 \end_layout
38720
38721 \begin_layout Standard
38722
38723 \size footnotesize
38724 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38725 \end_layout
38726
38727 \begin_layout Standard
38728
38729 \size footnotesize
38730 Sample.c(20:42:51:0)_return($8) :
38731 \end_layout
38732
38733 \begin_layout Standard
38734
38735 \size footnotesize
38736 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38737 \size default
38738
38739 \newline
38740
38741 \newline
38742 Finally the code generated for this function:
38743 \newline
38744
38745 \end_layout
38746
38747 \begin_layout Standard
38748
38749 \size footnotesize
38750 .area DSEG (DATA)
38751 \end_layout
38752
38753 \begin_layout Standard
38754
38755 \size footnotesize
38756 _p::
38757 \end_layout
38758
38759 \begin_layout Standard
38760
38761 \size footnotesize
38762 \InsetSpace ~
38763 \InsetSpace ~
38764 .ds 2
38765 \end_layout
38766
38767 \begin_layout Standard
38768
38769 \size footnotesize
38770 _gint::
38771 \end_layout
38772
38773 \begin_layout Standard
38774
38775 \size footnotesize
38776 \InsetSpace ~
38777 \InsetSpace ~
38778 .ds 2
38779 \end_layout
38780
38781 \begin_layout Standard
38782
38783 \size footnotesize
38784 ; sample.c 5
38785 \end_layout
38786
38787 \begin_layout Standard
38788
38789 \size footnotesize
38790 ; ----------------------------------------------
38791 \end_layout
38792
38793 \begin_layout Standard
38794
38795 \size footnotesize
38796 ; function function
38797 \end_layout
38798
38799 \begin_layout Standard
38800
38801 \size footnotesize
38802 ; ----------------------------------------------
38803 \end_layout
38804
38805 \begin_layout Standard
38806
38807 \size footnotesize
38808 _function:
38809 \end_layout
38810
38811 \begin_layout Standard
38812
38813 \size footnotesize
38814 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38815 \end_layout
38816
38817 \begin_layout Standard
38818
38819 \size footnotesize
38820 \InsetSpace ~
38821 \InsetSpace ~
38822 mov r2,dpl
38823 \end_layout
38824
38825 \begin_layout Standard
38826
38827 \size footnotesize
38828 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38829 \end_layout
38830
38831 \begin_layout Standard
38832
38833 \size footnotesize
38834 \InsetSpace ~
38835 \InsetSpace ~
38836 mov ar0,r2
38837 \end_layout
38838
38839 \begin_layout Standard
38840
38841 \size footnotesize
38842 ;_whilecontinue_0($1) :
38843 \end_layout
38844
38845 \begin_layout Standard
38846
38847 \size footnotesize
38848 00101$:
38849 \end_layout
38850
38851 \begin_layout Standard
38852
38853 \size footnotesize
38854 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38855 \end_layout
38856
38857 \begin_layout Standard
38858
38859 \size footnotesize
38860 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38861 \end_layout
38862
38863 \begin_layout Standard
38864
38865 \size footnotesize
38866 \InsetSpace ~
38867 \InsetSpace ~
38868 mov ar2,@r0
38869 \end_layout
38870
38871 \begin_layout Standard
38872
38873 \size footnotesize
38874 \InsetSpace ~
38875 \InsetSpace ~
38876 inc r0
38877 \end_layout
38878
38879 \begin_layout Standard
38880
38881 \size footnotesize
38882 \InsetSpace ~
38883 \InsetSpace ~
38884 mov ar3,@r0
38885 \end_layout
38886
38887 \begin_layout Standard
38888
38889 \size footnotesize
38890 \InsetSpace ~
38891 \InsetSpace ~
38892 dec r0
38893 \end_layout
38894
38895 \begin_layout Standard
38896
38897 \size footnotesize
38898 \InsetSpace ~
38899 \InsetSpace ~
38900 mov a,r2
38901 \end_layout
38902
38903 \begin_layout Standard
38904
38905 \size footnotesize
38906 \InsetSpace ~
38907 \InsetSpace ~
38908 orl a,r3
38909 \end_layout
38910
38911 \begin_layout Standard
38912
38913 \size footnotesize
38914 \InsetSpace ~
38915 \InsetSpace ~
38916 jz 00103$
38917 \end_layout
38918
38919 \begin_layout Standard
38920
38921 \size footnotesize
38922 00114$:
38923 \end_layout
38924
38925 \begin_layout Standard
38926
38927 \size footnotesize
38928 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38929 \end_layout
38930
38931 \begin_layout Standard
38932
38933 \size footnotesize
38934 \InsetSpace ~
38935 \InsetSpace ~
38936 mov dpl,_p
38937 \end_layout
38938
38939 \begin_layout Standard
38940
38941 \size footnotesize
38942 \InsetSpace ~
38943 \InsetSpace ~
38944 mov dph,(_p + 1)
38945 \end_layout
38946
38947 \begin_layout Standard
38948
38949 \size footnotesize
38950 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38951 \end_layout
38952
38953 \begin_layout Standard
38954
38955 \size footnotesize
38956 \InsetSpace ~
38957 \InsetSpace ~
38958 mov a,#0x02
38959 \end_layout
38960
38961 \begin_layout Standard
38962
38963 \size footnotesize
38964 \InsetSpace ~
38965 \InsetSpace ~
38966 add a,_p
38967 \end_layout
38968
38969 \begin_layout Standard
38970
38971 \size footnotesize
38972 \InsetSpace ~
38973 \InsetSpace ~
38974 mov _p,a
38975 \end_layout
38976
38977 \begin_layout Standard
38978
38979 \size footnotesize
38980 \InsetSpace ~
38981 \InsetSpace ~
38982 clr a
38983 \end_layout
38984
38985 \begin_layout Standard
38986
38987 \size footnotesize
38988 \InsetSpace ~
38989 \InsetSpace ~
38990 addc a,(_p + 1)
38991 \end_layout
38992
38993 \begin_layout Standard
38994
38995 \size footnotesize
38996 \InsetSpace ~
38997 \InsetSpace ~
38998 mov (_p + 1),a
38999 \end_layout
39000
39001 \begin_layout Standard
39002
39003 \size footnotesize
39004 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39005 \end_layout
39006
39007 \begin_layout Standard
39008
39009 \size footnotesize
39010 \InsetSpace ~
39011 \InsetSpace ~
39012 movx a,@dptr
39013 \end_layout
39014
39015 \begin_layout Standard
39016
39017 \size footnotesize
39018 \InsetSpace ~
39019 \InsetSpace ~
39020 mov r2,a
39021 \end_layout
39022
39023 \begin_layout Standard
39024
39025 \size footnotesize
39026 \InsetSpace ~
39027 \InsetSpace ~
39028 inc dptr
39029 \end_layout
39030
39031 \begin_layout Standard
39032
39033 \size footnotesize
39034 \InsetSpace ~
39035 \InsetSpace ~
39036 movx a,@dptr
39037 \end_layout
39038
39039 \begin_layout Standard
39040
39041 \size footnotesize
39042 \InsetSpace ~
39043 \InsetSpace ~
39044 mov r3,a
39045 \end_layout
39046
39047 \begin_layout Standard
39048
39049 \size footnotesize
39050 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39051 \end_layout
39052
39053 \begin_layout Standard
39054
39055 \size footnotesize
39056 \InsetSpace ~
39057 \InsetSpace ~
39058 mov @r0,ar2
39059 \end_layout
39060
39061 \begin_layout Standard
39062
39063 \size footnotesize
39064 \InsetSpace ~
39065 \InsetSpace ~
39066 inc r0
39067 \end_layout
39068
39069 \begin_layout Standard
39070
39071 \size footnotesize
39072 \InsetSpace ~
39073 \InsetSpace ~
39074 mov @r0,ar3
39075 \end_layout
39076
39077 \begin_layout Standard
39078
39079 \size footnotesize
39080 ; iTemp6 [lr5:16]{_near * int}[r0] = 
39081 \end_layout
39082
39083 \begin_layout Standard
39084
39085 \size footnotesize
39086 ; iTemp6 [lr5:16]{_near * int}[r0] + 
39087 \end_layout
39088
39089 \begin_layout Standard
39090
39091 \size footnotesize
39092 ; 0x2 {short}
39093 \end_layout
39094
39095 \begin_layout Standard
39096
39097 \size footnotesize
39098 \InsetSpace ~
39099 \InsetSpace ~
39100 inc r0
39101 \end_layout
39102
39103 \begin_layout Standard
39104
39105 \size footnotesize
39106 ; goto _whilecontinue_0($1)
39107 \end_layout
39108
39109 \begin_layout Standard
39110
39111 \size footnotesize
39112 \InsetSpace ~
39113 \InsetSpace ~
39114 sjmp 00101$
39115 \end_layout
39116
39117 \begin_layout Standard
39118
39119 \size footnotesize
39120 ; _whilebreak_0($3) :
39121 \end_layout
39122
39123 \begin_layout Standard
39124
39125 \size footnotesize
39126 00103$:
39127 \end_layout
39128
39129 \begin_layout Standard
39130
39131 \size footnotesize
39132 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39133 \end_layout
39134
39135 \begin_layout Standard
39136
39137 \size footnotesize
39138 \InsetSpace ~
39139 \InsetSpace ~
39140 mov r2,#0x00
39141 \end_layout
39142
39143 \begin_layout Standard
39144
39145 \size footnotesize
39146 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39147 \end_layout
39148
39149 \begin_layout Standard
39150
39151 \size footnotesize
39152 \InsetSpace ~
39153 \InsetSpace ~
39154 mov r3,#0x00
39155 \end_layout
39156
39157 \begin_layout Standard
39158
39159 \size footnotesize
39160 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39161 \end_layout
39162
39163 \begin_layout Standard
39164
39165 \size footnotesize
39166 \InsetSpace ~
39167 \InsetSpace ~
39168 mov r4,#0x00
39169 \end_layout
39170
39171 \begin_layout Standard
39172
39173 \size footnotesize
39174 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39175 \end_layout
39176
39177 \begin_layout Standard
39178
39179 \size footnotesize
39180 \InsetSpace ~
39181 \InsetSpace ~
39182 mov r5,#0x0A
39183 \end_layout
39184
39185 \begin_layout Standard
39186
39187 \size footnotesize
39188 \InsetSpace ~
39189 \InsetSpace ~
39190 mov r6,#0x00
39191 \end_layout
39192
39193 \begin_layout Standard
39194
39195 \size footnotesize
39196 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39197 \end_layout
39198
39199 \begin_layout Standard
39200
39201 \size footnotesize
39202 \InsetSpace ~
39203 \InsetSpace ~
39204 mov r7,#0x1E
39205 \end_layout
39206
39207 \begin_layout Standard
39208
39209 \size footnotesize
39210 \InsetSpace ~
39211 \InsetSpace ~
39212 mov r0,#0x00
39213 \end_layout
39214
39215 \begin_layout Standard
39216
39217 \size footnotesize
39218 ; _forcond_0($4) :
39219 \end_layout
39220
39221 \begin_layout Standard
39222
39223 \size footnotesize
39224 00104$:
39225 \end_layout
39226
39227 \begin_layout Standard
39228
39229 \size footnotesize
39230 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39231 \end_layout
39232
39233 \begin_layout Standard
39234
39235 \size footnotesize
39236 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39237 \end_layout
39238
39239 \begin_layout Standard
39240
39241 \size footnotesize
39242 \InsetSpace ~
39243 \InsetSpace ~
39244 clr c
39245 \end_layout
39246
39247 \begin_layout Standard
39248
39249 \size footnotesize
39250 \InsetSpace ~
39251 \InsetSpace ~
39252 mov a,r4
39253 \end_layout
39254
39255 \begin_layout Standard
39256
39257 \size footnotesize
39258 \InsetSpace ~
39259 \InsetSpace ~
39260 xrl a,#0x80
39261 \end_layout
39262
39263 \begin_layout Standard
39264
39265 \size footnotesize
39266 \InsetSpace ~
39267 \InsetSpace ~
39268 subb a,#0x8a
39269 \end_layout
39270
39271 \begin_layout Standard
39272
39273 \size footnotesize
39274 \InsetSpace ~
39275 \InsetSpace ~
39276 jnc 00107$
39277 \end_layout
39278
39279 \begin_layout Standard
39280
39281 \size footnotesize
39282 00115$:
39283 \end_layout
39284
39285 \begin_layout Standard
39286
39287 \size footnotesize
39288 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
39289 \end_layout
39290
39291 \begin_layout Standard
39292
39293 \size footnotesize
39294 ; iTemp21 [lr21:38]{short}[r4]
39295 \end_layout
39296
39297 \begin_layout Standard
39298
39299 \size footnotesize
39300 \InsetSpace ~
39301 \InsetSpace ~
39302 mov a,r4
39303 \end_layout
39304
39305 \begin_layout Standard
39306
39307 \size footnotesize
39308 \InsetSpace ~
39309 \InsetSpace ~
39310 add a,r2
39311 \end_layout
39312
39313 \begin_layout Standard
39314
39315 \size footnotesize
39316 \InsetSpace ~
39317 \InsetSpace ~
39318 mov r2,a
39319 \end_layout
39320
39321 \begin_layout Standard
39322
39323 \size footnotesize
39324 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39325 \end_layout
39326
39327 \begin_layout Standard
39328
39329 \size footnotesize
39330 \InsetSpace ~
39331 \InsetSpace ~
39332 mov b,#0x03
39333 \end_layout
39334
39335 \begin_layout Standard
39336
39337 \size footnotesize
39338 \InsetSpace ~
39339 \InsetSpace ~
39340 mov a,r4
39341 \end_layout
39342
39343 \begin_layout Standard
39344
39345 \size footnotesize
39346 \InsetSpace ~
39347 \InsetSpace ~
39348 mul ab
39349 \end_layout
39350
39351 \begin_layout Standard
39352
39353 \size footnotesize
39354 \InsetSpace ~
39355 \InsetSpace ~
39356 mov r1,a
39357 \end_layout
39358
39359 \begin_layout Standard
39360
39361 \size footnotesize
39362 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
39363 \end_layout
39364
39365 \begin_layout Standard
39366
39367 \size footnotesize
39368 ; iTemp15 [lr29:30]{short}[r1]
39369 \end_layout
39370
39371 \begin_layout Standard
39372
39373 \size footnotesize
39374 \InsetSpace ~
39375 \InsetSpace ~
39376 add a,r3
39377 \end_layout
39378
39379 \begin_layout Standard
39380
39381 \size footnotesize
39382 \InsetSpace ~
39383 \InsetSpace ~
39384 mov r3,a
39385 \end_layout
39386
39387 \begin_layout Standard
39388
39389 \size footnotesize
39390 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39391 \end_layout
39392
39393 \begin_layout Standard
39394
39395 \size footnotesize
39396 \InsetSpace ~
39397 \InsetSpace ~
39398 mov a,r7
39399 \end_layout
39400
39401 \begin_layout Standard
39402
39403 \size footnotesize
39404 \InsetSpace ~
39405 \InsetSpace ~
39406 add a,#0xfd
39407 \end_layout
39408
39409 \begin_layout Standard
39410
39411 \size footnotesize
39412 \InsetSpace ~
39413 \InsetSpace ~
39414 mov r7,a
39415 \end_layout
39416
39417 \begin_layout Standard
39418
39419 \size footnotesize
39420 \InsetSpace ~
39421 \InsetSpace ~
39422 mov a,r0
39423 \end_layout
39424
39425 \begin_layout Standard
39426
39427 \size footnotesize
39428 \InsetSpace ~
39429 \InsetSpace ~
39430 addc a,#0xff
39431 \end_layout
39432
39433 \begin_layout Standard
39434
39435 \size footnotesize
39436 \InsetSpace ~
39437 \InsetSpace ~
39438 mov r0,a
39439 \end_layout
39440
39441 \begin_layout Standard
39442
39443 \size footnotesize
39444 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39445 \end_layout
39446
39447 \begin_layout Standard
39448
39449 \size footnotesize
39450 \InsetSpace ~
39451 \InsetSpace ~
39452 mov a,r7
39453 \end_layout
39454
39455 \begin_layout Standard
39456
39457 \size footnotesize
39458 \InsetSpace ~
39459 \InsetSpace ~
39460 add a,_gint
39461 \end_layout
39462
39463 \begin_layout Standard
39464
39465 \size footnotesize
39466 \InsetSpace ~
39467 \InsetSpace ~
39468 mov _gint,a
39469 \end_layout
39470
39471 \begin_layout Standard
39472
39473 \size footnotesize
39474 \InsetSpace ~
39475 \InsetSpace ~
39476 mov a,r0
39477 \end_layout
39478
39479 \begin_layout Standard
39480
39481 \size footnotesize
39482 \InsetSpace ~
39483 \InsetSpace ~
39484 addc a,(_gint + 1)
39485 \end_layout
39486
39487 \begin_layout Standard
39488
39489 \size footnotesize
39490 \InsetSpace ~
39491 \InsetSpace ~
39492 mov (_gint + 1),a
39493 \end_layout
39494
39495 \begin_layout Standard
39496
39497 \size footnotesize
39498 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39499 \end_layout
39500
39501 \begin_layout Standard
39502
39503 \size footnotesize
39504 \InsetSpace ~
39505 \InsetSpace ~
39506 inc r4
39507 \end_layout
39508
39509 \begin_layout Standard
39510
39511 \size footnotesize
39512 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39513 \end_layout
39514
39515 \begin_layout Standard
39516
39517 \size footnotesize
39518 \InsetSpace ~
39519 \InsetSpace ~
39520 dec r5
39521 \end_layout
39522
39523 \begin_layout Standard
39524
39525 \size footnotesize
39526 \InsetSpace ~
39527 \InsetSpace ~
39528 cjne r5,#0xff,00104$
39529 \end_layout
39530
39531 \begin_layout Standard
39532
39533 \size footnotesize
39534 \InsetSpace ~
39535 \InsetSpace ~
39536 dec r6
39537 \end_layout
39538
39539 \begin_layout Standard
39540
39541 \size footnotesize
39542 ; goto _forcond_0($4)
39543 \end_layout
39544
39545 \begin_layout Standard
39546
39547 \size footnotesize
39548 \InsetSpace ~
39549 \InsetSpace ~
39550 sjmp 00104$
39551 \end_layout
39552
39553 \begin_layout Standard
39554
39555 \size footnotesize
39556 ; _forbreak_0($7) :
39557 \end_layout
39558
39559 \begin_layout Standard
39560
39561 \size footnotesize
39562 00107$:
39563 \end_layout
39564
39565 \begin_layout Standard
39566
39567 \size footnotesize
39568 ; ret iTemp24 [lr40:41]{short}
39569 \end_layout
39570
39571 \begin_layout Standard
39572
39573 \size footnotesize
39574 \InsetSpace ~
39575 \InsetSpace ~
39576 mov a,r3
39577 \end_layout
39578
39579 \begin_layout Standard
39580
39581 \size footnotesize
39582 \InsetSpace ~
39583 \InsetSpace ~
39584 add a,r2
39585 \end_layout
39586
39587 \begin_layout Standard
39588
39589 \size footnotesize
39590 \InsetSpace ~
39591 \InsetSpace ~
39592 mov dpl,a
39593 \end_layout
39594
39595 \begin_layout Standard
39596
39597 \size footnotesize
39598 ; _return($8) :
39599 \end_layout
39600
39601 \begin_layout Standard
39602
39603 \size footnotesize
39604 00108$:
39605 \end_layout
39606
39607 \begin_layout Standard
39608
39609 \size footnotesize
39610 \InsetSpace ~
39611 \InsetSpace ~
39612 ret
39613 \newline
39614
39615 \end_layout
39616
39617 \begin_layout Section
39618 A few words about basic block successors, predecessors and dominators
39619 \end_layout
39620
39621 \begin_layout Standard
39622 Successors are basic blocks
39623 \begin_inset LatexCommand \index{Basic blocks}
39624
39625 \end_inset
39626
39627  that might execute after this basic block.
39628 \newline
39629 Predecessors are basic blocks
39630  that might execute before reaching this basic block.
39631 \newline
39632 Dominators are basic
39633  blocks that WILL execute before reaching this basic block.
39634 \newline
39635
39636 \end_layout
39637
39638 \begin_layout Standard
39639 [basic block 1]
39640 \end_layout
39641
39642 \begin_layout Standard
39643 if (something)
39644 \end_layout
39645
39646 \begin_layout Standard
39647 \InsetSpace ~
39648 \InsetSpace ~
39649 \InsetSpace ~
39650 \InsetSpace ~
39651 [basic block 2]
39652 \end_layout
39653
39654 \begin_layout Standard
39655 else
39656 \end_layout
39657
39658 \begin_layout Standard
39659 \InsetSpace ~
39660 \InsetSpace ~
39661 \InsetSpace ~
39662 \InsetSpace ~
39663 [basic block 3]
39664 \end_layout
39665
39666 \begin_layout Standard
39667 [basic block 4]
39668 \newline
39669
39670 \end_layout
39671
39672 \begin_layout Standard
39673 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39674 \end_layout
39675
39676 \begin_layout Standard
39677 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39678 \end_layout
39679
39680 \begin_layout Standard
39681 c) domVect of [BB4] = BB1 ...
39682  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39683  was executed.
39684 \end_layout
39685
39686 \begin_layout Chapter
39687 Acknowledgments
39688 \end_layout
39689
39690 \begin_layout Standard
39691 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39692
39693 \end_inset
39694
39695
39696 \newline
39697
39698 \newline
39699
39700 \emph on
39701 Thanks to all the other volunteer developers who have helped with coding,
39702  testing, web-page creation, distribution sets, etc.
39703  You know who you are :-)
39704 \emph default
39705
39706 \newline
39707
39708 \newline
39709
39710 \emph on
39711 Thanks to Sourceforge 
39712 \begin_inset LatexCommand \url{http://www.sf.net}
39713
39714 \end_inset
39715
39716  which has hosted the project since 1999 and donates significant download
39717  bandwidth.
39718 \emph default
39719
39720 \newline
39721
39722 \newline
39723
39724 \emph on
39725 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
39726  cycles and bandwidth for snapshot builds.
39727 \newline
39728
39729 \end_layout
39730
39731 \begin_layout Standard
39732 This document was initially written by Sandeep Dutta
39733 \end_layout
39734
39735 \begin_layout Standard
39736 All product names mentioned herein may be trademarks
39737 \begin_inset LatexCommand \index{Trademarks}
39738
39739 \end_inset
39740
39741  of their respective companies.
39742  
39743 \end_layout
39744
39745 \begin_layout Section*
39746 Alphabetical index
39747 \end_layout
39748
39749 \begin_layout Standard
39750 To avoid confusion, the installation and building options for SDCC itself
39751  (chapter 2) are not part of the index.
39752 \end_layout
39753
39754 \begin_layout Standard
39755 \begin_inset LatexCommand \printindex{}
39756
39757 \end_inset
39758
39759
39760 \end_layout
39761
39762 \end_body
39763 \end_document